Skip to content

Commit 46189ac

Browse files
committed
Add optional import callback prop to enable module imports on the quill instance
1 parent eedc784 commit 46189ac

File tree

9 files changed

+42
-19
lines changed

9 files changed

+42
-19
lines changed

dist/components/form/Form.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ declare const Form: {
1818
({ type, className, ...rest }: import("./components/FormCheck").FormCheckProps): React.JSX.Element;
1919
Feedback: import("react-bootstrap/esm/helpers").BsPrefixRefForwardingComponent<"div", import("react-bootstrap/esm/Feedback").FeedbackProps>;
2020
};
21-
RichText: ({ modules, value, onChange, theme, ...rest }: import("./components/FormRichText").QuillEditorProps) => React.JSX.Element;
21+
RichText: ({ modules, value, onChange, theme, importCallback, ...rest }: import("./components/FormRichText").QuillEditorProps) => React.JSX.Element;
2222
DateTime: {
2323
({ className, ...rest }: import("./components/FormDateTime").FormDateTimeProps): React.JSX.Element;
2424
Feedback: import("react-bootstrap/esm/helpers").BsPrefixRefForwardingComponent<"div", import("react-bootstrap/esm/Feedback").FeedbackProps>;

dist/components/form/components/FormRichText.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export interface QuillEditorProps {
88
value?: string;
99
theme?: string;
1010
onChange?(value: string): any;
11+
importCallback?(): any;
1112
}
12-
declare const FormRichText: ({ modules, value, onChange, theme, ...rest }: QuillEditorProps) => React.JSX.Element;
13+
declare const FormRichText: ({ modules, value, onChange, theme, importCallback, ...rest }: QuillEditorProps) => React.JSX.Element;
1314
export default FormRichText;
1415
//# sourceMappingURL=FormRichText.d.ts.map

dist/components/form/components/FormRichText.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change

dist/components/form/components/FormRichText.js

+12-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/components/form/components/FormRichText.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.es.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -25532,7 +25532,7 @@ Quill.register({
2553225532
}, true);
2553325533

2553425534
var FormRichText = function (_a) {
25535-
var modules = _a.modules, value = _a.value, onChange = _a.onChange, theme = _a.theme, rest = __rest(_a, ["modules", "value", "onChange", "theme"]);
25535+
var modules = _a.modules, value = _a.value, onChange = _a.onChange, theme = _a.theme, importCallback = _a.importCallback, rest = __rest(_a, ["modules", "value", "onChange", "theme", "importCallback"]);
2553625536
var quillRef = React.useRef(null);
2553725537
var containerRef = React.useRef(null);
2553825538
var quillOptions = __assign(__assign({}, modules), { theme: theme || 'snow' });
@@ -25550,19 +25550,25 @@ var FormRichText = function (_a) {
2555025550
};
2555125551
React.useEffect(function () {
2555225552
if (containerRef.current) {
25553+
if (importCallback) {
25554+
//Callback to import new modules into quill, needs to be done within the same instance as the quill object.
25555+
importCallback();
25556+
}
2555325557
var container_1 = containerRef.current;
2555425558
var editorContainer = container_1.appendChild(container_1.ownerDocument.createElement('div'));
25555-
var quill_1 = new Quill(editorContainer, quillOptions);
25556-
quillRef.current = quill_1; // Store the Quill instance in a ref
25559+
var quill = new Quill(editorContainer, quillOptions);
25560+
quillRef.current = quill; // Store the Quill instance in a ref
2555725561
if (value) {
25558-
setValue(quill_1);
25562+
setValue(quill);
2555925563
}
25560-
configureListeners(quill_1);
25564+
configureListeners(quill);
2556125565
return function () {
2556225566
container_1.innerHTML = '';
25563-
quill_1.off(Quill.events.TEXT_CHANGE);
25567+
quillRef.current.off(Quill.events.TEXT_CHANGE);
2556425568
};
2556525569
}
25570+
// NOTE: Run effect once on component mount, please recheck dependencies if effect is updated.
25571+
// eslint-disable-next-line react-hooks/exhaustive-deps
2556625572
}, []);
2556725573
return React.createElement("div", { ref: containerRef, style: rest.style, id: rest.id, className: rest.className });
2556825574
};

dist/index.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/form/components/FormRichText.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ export interface QuillEditorProps {
1111
theme?: string;
1212

1313
onChange?(value: string): any;
14+
importCallback?(): any;
1415
}
1516

1617
const FormRichText = ({
1718
modules,
1819
value,
1920
onChange,
2021
theme,
22+
importCallback,
2123
...rest
2224
}: QuillEditorProps) => {
2325
const quillRef = useRef<Quill | null>(null);
@@ -43,6 +45,11 @@ const FormRichText = ({
4345

4446
useEffect(() => {
4547
if (containerRef.current) {
48+
if (importCallback) {
49+
// Callback to import new modules into quill, needs to be done within the same instance as the quill object.
50+
importCallback();
51+
}
52+
4653
const container = containerRef.current as HTMLDivElement;
4754
const editorContainer = container.appendChild(
4855
container.ownerDocument.createElement('div')
@@ -58,9 +65,12 @@ const FormRichText = ({
5865

5966
return () => {
6067
container.innerHTML = '';
61-
quill.off(Quill.events.TEXT_CHANGE);
68+
(quillRef.current as Quill).off(Quill.events.TEXT_CHANGE);
6269
};
6370
}
71+
72+
// NOTE: Run effect once on component mount, please recheck dependencies if effect is updated.
73+
// eslint-disable-next-line react-hooks/exhaustive-deps
6474
}, []);
6575

6676
return (

0 commit comments

Comments
 (0)