Skip to content

Commit

Permalink
Add optional import callback prop to enable module imports on the qui…
Browse files Browse the repository at this point in the history
…ll instance
  • Loading branch information
Jamie-n committed Jun 19, 2024
1 parent eedc784 commit 46189ac
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 19 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: ({ modules, value, onChange, theme, ...rest }: import("./components/FormRichText").QuillEditorProps) => React.JSX.Element;
RichText: ({ modules, value, onChange, theme, importCallback, ...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
3 changes: 2 additions & 1 deletion dist/components/form/components/FormRichText.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export interface QuillEditorProps {
value?: string;
theme?: string;
onChange?(value: string): any;
importCallback?(): any;
}
declare const FormRichText: ({ modules, value, onChange, theme, ...rest }: QuillEditorProps) => React.JSX.Element;
declare const FormRichText: ({ modules, value, onChange, theme, importCallback, ...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.

18 changes: 12 additions & 6 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.

2 changes: 1 addition & 1 deletion dist/index.es.js

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25532,7 +25532,7 @@ Quill.register({
}, true);

var FormRichText = function (_a) {
var modules = _a.modules, value = _a.value, onChange = _a.onChange, theme = _a.theme, rest = __rest(_a, ["modules", "value", "onChange", "theme"]);
var modules = _a.modules, value = _a.value, onChange = _a.onChange, theme = _a.theme, importCallback = _a.importCallback, rest = __rest(_a, ["modules", "value", "onChange", "theme", "importCallback"]);
var quillRef = React.useRef(null);
var containerRef = React.useRef(null);
var quillOptions = __assign(__assign({}, modules), { theme: theme || 'snow' });
Expand All @@ -25550,19 +25550,25 @@ var FormRichText = function (_a) {
};
React.useEffect(function () {
if (containerRef.current) {
if (importCallback) {
//Callback to import new modules into quill, needs to be done within the same instance as the quill object.
importCallback();
}
var container_1 = containerRef.current;
var editorContainer = container_1.appendChild(container_1.ownerDocument.createElement('div'));
var quill_1 = new Quill(editorContainer, quillOptions);
quillRef.current = quill_1; // Store the Quill instance in a ref
var quill = new Quill(editorContainer, quillOptions);
quillRef.current = quill; // Store the Quill instance in a ref
if (value) {
setValue(quill_1);
setValue(quill);
}
configureListeners(quill_1);
configureListeners(quill);
return function () {
container_1.innerHTML = '';
quill_1.off(Quill.events.TEXT_CHANGE);
quillRef.current.off(Quill.events.TEXT_CHANGE);
};
}
// NOTE: Run effect once on component mount, please recheck dependencies if effect is updated.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return React.createElement("div", { ref: containerRef, style: rest.style, id: rest.id, className: rest.className });
};
Expand Down
2 changes: 1 addition & 1 deletion dist/index.min.js

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion src/components/form/components/FormRichText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ export interface QuillEditorProps {
theme?: string;

onChange?(value: string): any;
importCallback?(): any;
}

const FormRichText = ({
modules,
value,
onChange,
theme,
importCallback,
...rest
}: QuillEditorProps) => {
const quillRef = useRef<Quill | null>(null);
Expand All @@ -43,6 +45,11 @@ const FormRichText = ({

useEffect(() => {
if (containerRef.current) {
if (importCallback) {
// Callback to import new modules into quill, needs to be done within the same instance as the quill object.
importCallback();
}

const container = containerRef.current as HTMLDivElement;
const editorContainer = container.appendChild(
container.ownerDocument.createElement('div')
Expand All @@ -58,9 +65,12 @@ const FormRichText = ({

return () => {
container.innerHTML = '';
quill.off(Quill.events.TEXT_CHANGE);
(quillRef.current as Quill).off(Quill.events.TEXT_CHANGE);
};
}

// NOTE: Run effect once on component mount, please recheck dependencies if effect is updated.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
Expand Down

0 comments on commit 46189ac

Please sign in to comment.