Skip to content

Commit

Permalink
Remove forward referencing for simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie-n committed Jun 18, 2024
1 parent b696f25 commit ec032b4
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 69 deletions.
2 changes: 1 addition & 1 deletion dist/components/form/Form.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ declare const Form: {
({ type, className, ...rest }: import("./components/FormCheck").FormCheckProps): React.JSX.Element;
Feedback: import("react-bootstrap/esm/helpers").BsPrefixRefForwardingComponent<"div", import("react-bootstrap/esm/Feedback").FeedbackProps>;
};
RichText: React.ForwardRefExoticComponent<import("./components/FormRichText").QuillEditorProps & React.RefAttributes<import("quill/core/quill").default>>;
RichText: ({ modules, value, valueChange, ...rest }: import("./components/FormRichText").QuillEditorProps) => React.JSX.Element;
DateTime: {
({ className, ...rest }: import("./components/FormDateTime").FormDateTimeProps): React.JSX.Element;
Feedback: import("react-bootstrap/esm/helpers").BsPrefixRefForwardingComponent<"div", import("react-bootstrap/esm/Feedback").FeedbackProps>;
Expand Down
7 changes: 3 additions & 4 deletions dist/components/form/components/FormRichText.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { CSSProperties } from 'react';
import Quill from 'quill';
export interface QuillEditorProps {
className?: string;
style?: CSSProperties;
id?: string;
modules?: Record<string, unknown>;
valueChange?(value: string): any;
value?: string;
valueChange?(value: string): any;
}
declare const _default: React.ForwardRefExoticComponent<QuillEditorProps & React.RefAttributes<Quill>>;
export default _default;
declare const FormRichText: ({ modules, value, valueChange, ...rest }: QuillEditorProps) => React.JSX.Element;
export default FormRichText;
//# sourceMappingURL=FormRichText.d.ts.map
2 changes: 1 addition & 1 deletion dist/components/form/components/FormRichText.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 6 additions & 13 deletions dist/components/form/components/FormRichText.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/components/form/components/FormRichText.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dist/index.es.js

Large diffs are not rendered by default.

18 changes: 5 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25531,7 +25531,7 @@ Quill.register({
'ui/tooltip': Tooltip
}, true);

var FormRichText = function (_a, ref) {
var FormRichText = function (_a) {
var modules = _a.modules, value = _a.value, valueChange = _a.valueChange, rest = __rest(_a, ["modules", "value", "valueChange"]);
var editorRef = React.useRef(null);
var quillRef = React.useRef(null);
Expand All @@ -25551,22 +25551,14 @@ var FormRichText = function (_a, ref) {
if (editorRef.current) {
var quill = new Quill(editorRef.current, modules);
quillRef.current = quill; // Store the Quill instance in a ref
if (ref) {
// Assign the Quill instance to the forwarded ref
if (typeof ref !== 'function') {
ref.current = quill; // For object refs
}
if (value) {
setValue(quill);
}
configureListeners(quill);
if (value) {
setValue(quill);
}
configureListeners(quill);
}
}, []);
React.useImperativeHandle(ref, function () { return quillRef.current; });
return React.createElement("div", { ref: editorRef, style: rest.style, id: rest.id });
};
var FormRichText$1 = React.forwardRef(FormRichText);

var FormDateTime = function (_a) {
var className = _a.className, rest = __rest(_a, ["className"]);
Expand Down Expand Up @@ -29211,7 +29203,7 @@ Form$1.Label = FormLabel;
Form$1.Control = FormControl;
Form$1.Select = FormSelect;
Form$1.Check = FormCheck;
Form$1.RichText = FormRichText$1;
Form$1.RichText = FormRichText;
Form$1.DateTime = FormDateTime;
Form$1.Feedback = Feedback$1;
Form$1.Text = FormText$1;
Expand Down
10 changes: 5 additions & 5 deletions dist/index.min.js

Large diffs are not rendered by default.

40 changes: 13 additions & 27 deletions src/components/form/components/FormRichText.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import React, {
useEffect,
useRef,
useImperativeHandle,
forwardRef,
ForwardedRef,
CSSProperties,
} from 'react';
import React, { useRef, CSSProperties, useEffect } from 'react';
import Quill from 'quill';

export interface QuillEditorProps {
className?: string;
style?: CSSProperties;
id?: string;
modules?: Record<string, unknown>;
valueChange?(value: string): any;
value?: string;

valueChange?(value: string): any;
}

const FormRichText: React.ForwardRefRenderFunction<Quill, QuillEditorProps> = (
{ modules, value, valueChange, ...rest }: QuillEditorProps,
ref: ForwardedRef<Quill>
) => {
const FormRichText = ({
modules,
value,
valueChange,
...rest
}: QuillEditorProps) => {
const editorRef = useRef<HTMLDivElement | null>(null);
const quillRef = useRef<Quill | null>(null);

Expand All @@ -42,23 +38,13 @@ const FormRichText: React.ForwardRefRenderFunction<Quill, QuillEditorProps> = (
const quill = new Quill(editorRef.current, modules);
quillRef.current = quill; // Store the Quill instance in a ref

if (ref) {
// Assign the Quill instance to the forwarded ref
if (typeof ref !== 'function') {
ref.current = quill; // For object refs
}

if (value) {
setValue(quill);
}
configureListeners(quill);
if (value) {
setValue(quill);
}
configureListeners(quill);
}
}, []);

useImperativeHandle(ref, () => quillRef.current as Quill);

return <div ref={editorRef} style={rest.style} id={rest.id} />;
};

export default forwardRef(FormRichText);
export default FormRichText;

0 comments on commit ec032b4

Please sign in to comment.