@bbl-digital/snorre 4.1.12 → 4.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.js
CHANGED
|
@@ -35458,7 +35458,7 @@ to {top: 100vh;}
|
|
|
35458
35458
|
'formats/ulist': MyListItem
|
|
35459
35459
|
});
|
|
35460
35460
|
Quill__default["default"].register(CustomLinkSanitizer, true);
|
|
35461
|
-
const QuillEditor = ({
|
|
35461
|
+
const QuillEditor = /*#__PURE__*/React.forwardRef(({
|
|
35462
35462
|
height,
|
|
35463
35463
|
width,
|
|
35464
35464
|
maxHeight,
|
|
@@ -35485,12 +35485,15 @@ to {top: 100vh;}
|
|
|
35485
35485
|
disabled,
|
|
35486
35486
|
pasteAsText,
|
|
35487
35487
|
name,
|
|
35488
|
-
id
|
|
35489
|
-
|
|
35490
|
-
}) => {
|
|
35488
|
+
id
|
|
35489
|
+
}, ref) => {
|
|
35491
35490
|
const [quill, setQuill] = React.useState(null);
|
|
35492
35491
|
const isMounted = React.useRef(false);
|
|
35493
35492
|
const containerRef = React.useRef(null);
|
|
35493
|
+
const defaultValueRef = React.useRef(initialValue);
|
|
35494
|
+
const onTextChangeRef = React.useRef(onChange);
|
|
35495
|
+
// const onFocusRef = useRef(onFocus)
|
|
35496
|
+
// const onBlurRef = useRef(onBlur)
|
|
35494
35497
|
const {
|
|
35495
35498
|
alert
|
|
35496
35499
|
} = react.useTheme();
|
|
@@ -35537,20 +35540,17 @@ to {top: 100vh;}
|
|
|
35537
35540
|
}
|
|
35538
35541
|
}
|
|
35539
35542
|
};
|
|
35540
|
-
const handleChange = React.useCallback((delta, _oldDelta, source) => {
|
|
35541
|
-
|
|
35542
|
-
|
|
35543
|
-
|
|
35544
|
-
onChange(html, delta, source, quill);
|
|
35545
|
-
}
|
|
35543
|
+
const handleChange = React.useCallback((delta, _oldDelta, source, instance) => {
|
|
35544
|
+
const html = instance.root.innerHTML;
|
|
35545
|
+
if (onChange) {
|
|
35546
|
+
onChange(html, delta, source, quill);
|
|
35546
35547
|
}
|
|
35547
35548
|
}, [quill, onChange]);
|
|
35548
|
-
const handelFocus = React.useCallback(
|
|
35549
|
-
|
|
35550
|
-
const html = quill.root.innerHTML;
|
|
35549
|
+
const handelFocus = React.useCallback(instance => {
|
|
35550
|
+
const html = instance.root.innerHTML;
|
|
35551
35551
|
onFocus && onFocus(html);
|
|
35552
35552
|
}, [quill, onFocus]);
|
|
35553
|
-
const applySizes =
|
|
35553
|
+
const applySizes = quill => {
|
|
35554
35554
|
if (!quill) return;
|
|
35555
35555
|
minHeight && (quill.root.style.minHeight = `${minHeight}px`);
|
|
35556
35556
|
maxHeight && (quill.root.style.maxHeight = `${maxHeight}px`);
|
|
@@ -35559,55 +35559,67 @@ to {top: 100vh;}
|
|
|
35559
35559
|
height && (quill.root.style.height = `${height}px`);
|
|
35560
35560
|
minWidth && (quill.root.style.minWidth = `${minWidth}px`);
|
|
35561
35561
|
};
|
|
35562
|
+
React.useLayoutEffect(() => {
|
|
35563
|
+
onTextChangeRef.current = onChange;
|
|
35564
|
+
});
|
|
35562
35565
|
React.useEffect(() => {
|
|
35563
|
-
if (
|
|
35564
|
-
|
|
35565
|
-
|
|
35566
|
-
|
|
35567
|
-
|
|
35568
|
-
|
|
35569
|
-
|
|
35570
|
-
|
|
35571
|
-
|
|
35572
|
-
|
|
35573
|
-
|
|
35574
|
-
|
|
35575
|
-
|
|
35576
|
-
|
|
35577
|
-
|
|
35578
|
-
|
|
35579
|
-
|
|
35566
|
+
if (isMounted.current) return;
|
|
35567
|
+
const container = containerRef.current;
|
|
35568
|
+
const editor = container?.appendChild(container.ownerDocument.createElement('div'));
|
|
35569
|
+
if (!editor) return;
|
|
35570
|
+
const quillInstance = new Quill__default["default"](editor, {
|
|
35571
|
+
theme: 'snow',
|
|
35572
|
+
modules: {
|
|
35573
|
+
...modules
|
|
35574
|
+
},
|
|
35575
|
+
formats,
|
|
35576
|
+
placeholder,
|
|
35577
|
+
bounds,
|
|
35578
|
+
readOnly
|
|
35579
|
+
});
|
|
35580
|
+
ref && ref.current && (ref.current = editor);
|
|
35581
|
+
const editorActual = editor.querySelector('.ql-editor');
|
|
35582
|
+
if (editorActual) {
|
|
35583
|
+
editorActual.setAttribute('id', id || 'ql-editor');
|
|
35584
|
+
editorActual.setAttribute('name', name || 'ql-editor');
|
|
35585
|
+
}
|
|
35586
|
+
applySizes(quillInstance);
|
|
35587
|
+
quillInstance.keyboard.addBinding({
|
|
35588
|
+
key: 'Backspace'
|
|
35589
|
+
}, {
|
|
35590
|
+
format: {
|
|
35591
|
+
list: true,
|
|
35592
|
+
indent: true
|
|
35580
35593
|
}
|
|
35581
|
-
|
|
35582
|
-
|
|
35583
|
-
|
|
35584
|
-
|
|
35585
|
-
|
|
35586
|
-
|
|
35587
|
-
|
|
35588
|
-
|
|
35589
|
-
|
|
35590
|
-
|
|
35591
|
-
|
|
35592
|
-
|
|
35593
|
-
quillInstance.
|
|
35594
|
-
|
|
35595
|
-
}, () => {
|
|
35596
|
-
// Remove focus from editor
|
|
35597
|
-
quillInstance.blur();
|
|
35594
|
+
}, (range, context) => {
|
|
35595
|
+
return handleBackspaceWithIndentetList(range, context, quillInstance);
|
|
35596
|
+
});
|
|
35597
|
+
// Move the last binding in the list, to the top. Ensure that the custom binding is called first.
|
|
35598
|
+
quillInstance.keyboard.bindings['Backspace'].unshift(quillInstance.keyboard.bindings['Backspace'].pop());
|
|
35599
|
+
quillInstance.keyboard.addBinding({
|
|
35600
|
+
key: 'Escape'
|
|
35601
|
+
}, () => {
|
|
35602
|
+
// Remove focus from editor
|
|
35603
|
+
quillInstance.blur();
|
|
35604
|
+
});
|
|
35605
|
+
if (defaultValueRef.current) {
|
|
35606
|
+
const delta = quillInstance.clipboard.convert({
|
|
35607
|
+
html: defaultValueRef.current
|
|
35598
35608
|
});
|
|
35599
|
-
|
|
35600
|
-
if (quillInstance.root.innerHTML !== initialValue) {
|
|
35601
|
-
const delta = quillInstance.clipboard.convert({
|
|
35602
|
-
html: initialValue
|
|
35603
|
-
});
|
|
35604
|
-
quillInstance.setContents(delta);
|
|
35605
|
-
}
|
|
35606
|
-
}
|
|
35607
|
-
isMounted.current = true;
|
|
35608
|
-
setQuill(quillInstance);
|
|
35609
|
+
quillInstance.setContents(delta);
|
|
35609
35610
|
}
|
|
35610
|
-
|
|
35611
|
+
quillInstance.on(Quill__default["default"].events.TEXT_CHANGE, (...args) => handleChange(...args, quillInstance));
|
|
35612
|
+
quillInstance.on(Quill__default["default"].events.SELECTION_CHANGE, range => {
|
|
35613
|
+
if (!range) return;
|
|
35614
|
+
handelFocus(quillInstance);
|
|
35615
|
+
});
|
|
35616
|
+
isMounted.current = true;
|
|
35617
|
+
setQuill(quillInstance);
|
|
35618
|
+
return () => {
|
|
35619
|
+
ref && ref.current && (ref.current = null);
|
|
35620
|
+
container.innerHTML = '';
|
|
35621
|
+
};
|
|
35622
|
+
}, [ref]);
|
|
35611
35623
|
React.useEffect(() => {
|
|
35612
35624
|
if (!quill) return;
|
|
35613
35625
|
const handleBlur = () => {
|
|
@@ -35621,26 +35633,6 @@ to {top: 100vh;}
|
|
|
35621
35633
|
quill.root.removeEventListener('blur', handleBlur);
|
|
35622
35634
|
};
|
|
35623
35635
|
}, [quill]);
|
|
35624
|
-
React.useEffect(() => {
|
|
35625
|
-
if (!quill) return;
|
|
35626
|
-
quill.on('selection-change', (range, oldRange, source) => {
|
|
35627
|
-
if (!range) return;
|
|
35628
|
-
handelFocus();
|
|
35629
|
-
});
|
|
35630
|
-
return () => {
|
|
35631
|
-
quill.off('selection-change');
|
|
35632
|
-
};
|
|
35633
|
-
}, [quill]);
|
|
35634
|
-
React.useEffect(() => {
|
|
35635
|
-
if (!quill) return;
|
|
35636
|
-
quill.on('text-change', handleChange);
|
|
35637
|
-
return () => {
|
|
35638
|
-
quill.off('text-change', handleChange);
|
|
35639
|
-
};
|
|
35640
|
-
}, [quill, isMounted]);
|
|
35641
|
-
React.useEffect(() => {
|
|
35642
|
-
applySizes();
|
|
35643
|
-
}, [quill, height, width, maxHeight, maxWidth, minHeight, minWidth]);
|
|
35644
35636
|
React.useEffect(() => {
|
|
35645
35637
|
if (!quill) return;
|
|
35646
35638
|
quill.clipboard.addMatcher(Node.ELEMENT_NODE, (node, delta) => {
|
|
@@ -35701,7 +35693,7 @@ to {top: 100vh;}
|
|
|
35701
35693
|
})
|
|
35702
35694
|
})]
|
|
35703
35695
|
});
|
|
35704
|
-
};
|
|
35696
|
+
});
|
|
35705
35697
|
|
|
35706
35698
|
const getReducedArray = (array, indexesAmount) => {
|
|
35707
35699
|
// copies x amount of indexes from array (in order) to a new array
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @jsxImportSource @emotion/react */
|
|
2
|
-
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
2
|
+
import { useRef, useState, useEffect, useCallback, forwardRef, useLayoutEffect } from 'react';
|
|
3
3
|
import Quill from 'quill';
|
|
4
4
|
import 'quill/dist/quill.snow.css';
|
|
5
5
|
import { basicToolbar, richToolbar } from './config';
|
|
@@ -55,7 +55,7 @@ Quill.register({
|
|
|
55
55
|
'formats/ulist': MyListItem
|
|
56
56
|
});
|
|
57
57
|
Quill.register(CustomLinkSanitizer, true);
|
|
58
|
-
const QuillEditor = ({
|
|
58
|
+
const QuillEditor = /*#__PURE__*/forwardRef(({
|
|
59
59
|
height,
|
|
60
60
|
width,
|
|
61
61
|
maxHeight,
|
|
@@ -82,12 +82,15 @@ const QuillEditor = ({
|
|
|
82
82
|
disabled,
|
|
83
83
|
pasteAsText,
|
|
84
84
|
name,
|
|
85
|
-
id
|
|
86
|
-
|
|
87
|
-
}) => {
|
|
85
|
+
id
|
|
86
|
+
}, ref) => {
|
|
88
87
|
const [quill, setQuill] = useState(null);
|
|
89
88
|
const isMounted = useRef(false);
|
|
90
89
|
const containerRef = useRef(null);
|
|
90
|
+
const defaultValueRef = useRef(initialValue);
|
|
91
|
+
const onTextChangeRef = useRef(onChange);
|
|
92
|
+
// const onFocusRef = useRef(onFocus)
|
|
93
|
+
// const onBlurRef = useRef(onBlur)
|
|
91
94
|
const {
|
|
92
95
|
alert
|
|
93
96
|
} = useTheme();
|
|
@@ -134,20 +137,17 @@ const QuillEditor = ({
|
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
139
|
};
|
|
137
|
-
const handleChange = useCallback((delta, _oldDelta, source) => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
onChange(html, delta, source, quill);
|
|
142
|
-
}
|
|
140
|
+
const handleChange = useCallback((delta, _oldDelta, source, instance) => {
|
|
141
|
+
const html = instance.root.innerHTML;
|
|
142
|
+
if (onChange) {
|
|
143
|
+
onChange(html, delta, source, quill);
|
|
143
144
|
}
|
|
144
145
|
}, [quill, onChange]);
|
|
145
|
-
const handelFocus = useCallback(
|
|
146
|
-
|
|
147
|
-
const html = quill.root.innerHTML;
|
|
146
|
+
const handelFocus = useCallback(instance => {
|
|
147
|
+
const html = instance.root.innerHTML;
|
|
148
148
|
onFocus && onFocus(html);
|
|
149
149
|
}, [quill, onFocus]);
|
|
150
|
-
const applySizes =
|
|
150
|
+
const applySizes = quill => {
|
|
151
151
|
if (!quill) return;
|
|
152
152
|
minHeight && (quill.root.style.minHeight = `${minHeight}px`);
|
|
153
153
|
maxHeight && (quill.root.style.maxHeight = `${maxHeight}px`);
|
|
@@ -156,55 +156,67 @@ const QuillEditor = ({
|
|
|
156
156
|
height && (quill.root.style.height = `${height}px`);
|
|
157
157
|
minWidth && (quill.root.style.minWidth = `${minWidth}px`);
|
|
158
158
|
};
|
|
159
|
+
useLayoutEffect(() => {
|
|
160
|
+
onTextChangeRef.current = onChange;
|
|
161
|
+
});
|
|
159
162
|
useEffect(() => {
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
163
|
+
if (isMounted.current) return;
|
|
164
|
+
const container = containerRef.current;
|
|
165
|
+
const editor = container?.appendChild(container.ownerDocument.createElement('div'));
|
|
166
|
+
if (!editor) return;
|
|
167
|
+
const quillInstance = new Quill(editor, {
|
|
168
|
+
theme: 'snow',
|
|
169
|
+
modules: {
|
|
170
|
+
...modules
|
|
171
|
+
},
|
|
172
|
+
formats,
|
|
173
|
+
placeholder,
|
|
174
|
+
bounds,
|
|
175
|
+
readOnly
|
|
176
|
+
});
|
|
177
|
+
ref && ref.current && (ref.current = editor);
|
|
178
|
+
const editorActual = editor.querySelector('.ql-editor');
|
|
179
|
+
if (editorActual) {
|
|
180
|
+
editorActual.setAttribute('id', id || 'ql-editor');
|
|
181
|
+
editorActual.setAttribute('name', name || 'ql-editor');
|
|
182
|
+
}
|
|
183
|
+
applySizes(quillInstance);
|
|
184
|
+
quillInstance.keyboard.addBinding({
|
|
185
|
+
key: 'Backspace'
|
|
186
|
+
}, {
|
|
187
|
+
format: {
|
|
188
|
+
list: true,
|
|
189
|
+
indent: true
|
|
177
190
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
quillInstance.
|
|
191
|
-
|
|
192
|
-
}, () => {
|
|
193
|
-
// Remove focus from editor
|
|
194
|
-
quillInstance.blur();
|
|
191
|
+
}, (range, context) => {
|
|
192
|
+
return handleBackspaceWithIndentetList(range, context, quillInstance);
|
|
193
|
+
});
|
|
194
|
+
// Move the last binding in the list, to the top. Ensure that the custom binding is called first.
|
|
195
|
+
quillInstance.keyboard.bindings['Backspace'].unshift(quillInstance.keyboard.bindings['Backspace'].pop());
|
|
196
|
+
quillInstance.keyboard.addBinding({
|
|
197
|
+
key: 'Escape'
|
|
198
|
+
}, () => {
|
|
199
|
+
// Remove focus from editor
|
|
200
|
+
quillInstance.blur();
|
|
201
|
+
});
|
|
202
|
+
if (defaultValueRef.current) {
|
|
203
|
+
const delta = quillInstance.clipboard.convert({
|
|
204
|
+
html: defaultValueRef.current
|
|
195
205
|
});
|
|
196
|
-
|
|
197
|
-
if (quillInstance.root.innerHTML !== initialValue) {
|
|
198
|
-
const delta = quillInstance.clipboard.convert({
|
|
199
|
-
html: initialValue
|
|
200
|
-
});
|
|
201
|
-
quillInstance.setContents(delta);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
isMounted.current = true;
|
|
205
|
-
setQuill(quillInstance);
|
|
206
|
+
quillInstance.setContents(delta);
|
|
206
207
|
}
|
|
207
|
-
|
|
208
|
+
quillInstance.on(Quill.events.TEXT_CHANGE, (...args) => handleChange(...args, quillInstance));
|
|
209
|
+
quillInstance.on(Quill.events.SELECTION_CHANGE, range => {
|
|
210
|
+
if (!range) return;
|
|
211
|
+
handelFocus(quillInstance);
|
|
212
|
+
});
|
|
213
|
+
isMounted.current = true;
|
|
214
|
+
setQuill(quillInstance);
|
|
215
|
+
return () => {
|
|
216
|
+
ref && ref.current && (ref.current = null);
|
|
217
|
+
container.innerHTML = '';
|
|
218
|
+
};
|
|
219
|
+
}, [ref]);
|
|
208
220
|
useEffect(() => {
|
|
209
221
|
if (!quill) return;
|
|
210
222
|
const handleBlur = () => {
|
|
@@ -218,26 +230,6 @@ const QuillEditor = ({
|
|
|
218
230
|
quill.root.removeEventListener('blur', handleBlur);
|
|
219
231
|
};
|
|
220
232
|
}, [quill]);
|
|
221
|
-
useEffect(() => {
|
|
222
|
-
if (!quill) return;
|
|
223
|
-
quill.on('selection-change', (range, oldRange, source) => {
|
|
224
|
-
if (!range) return;
|
|
225
|
-
handelFocus();
|
|
226
|
-
});
|
|
227
|
-
return () => {
|
|
228
|
-
quill.off('selection-change');
|
|
229
|
-
};
|
|
230
|
-
}, [quill]);
|
|
231
|
-
useEffect(() => {
|
|
232
|
-
if (!quill) return;
|
|
233
|
-
quill.on('text-change', handleChange);
|
|
234
|
-
return () => {
|
|
235
|
-
quill.off('text-change', handleChange);
|
|
236
|
-
};
|
|
237
|
-
}, [quill, isMounted]);
|
|
238
|
-
useEffect(() => {
|
|
239
|
-
applySizes();
|
|
240
|
-
}, [quill, height, width, maxHeight, maxWidth, minHeight, minWidth]);
|
|
241
233
|
useEffect(() => {
|
|
242
234
|
if (!quill) return;
|
|
243
235
|
quill.clipboard.addMatcher(Node.ELEMENT_NODE, (node, delta) => {
|
|
@@ -298,5 +290,5 @@ const QuillEditor = ({
|
|
|
298
290
|
})
|
|
299
291
|
})]
|
|
300
292
|
});
|
|
301
|
-
};
|
|
293
|
+
});
|
|
302
294
|
export default QuillEditor;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'quill/dist/quill.snow.css';
|
|
2
2
|
import { QuillEditorProps } from './models';
|
|
3
|
-
declare const QuillEditor:
|
|
3
|
+
declare const QuillEditor: import("react").ForwardRefExoticComponent<QuillEditorProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
4
4
|
export default QuillEditor;
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packages/core/QuillEditor/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packages/core/QuillEditor/index.tsx"],"names":[],"mappings":"AAUA,OAAO,2BAA2B,CAAA;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAiE3C,QAAA,MAAM,WAAW,6GA6RhB,CAAA;AAED,eAAe,WAAW,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @jsxImportSource @emotion/react */
|
|
2
|
-
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
2
|
+
import { useRef, useState, useEffect, useCallback, forwardRef, useLayoutEffect } from 'react';
|
|
3
3
|
import Quill from 'quill';
|
|
4
4
|
import 'quill/dist/quill.snow.css';
|
|
5
5
|
import { basicToolbar, richToolbar } from './config';
|
|
@@ -55,7 +55,7 @@ Quill.register({
|
|
|
55
55
|
'formats/ulist': MyListItem
|
|
56
56
|
});
|
|
57
57
|
Quill.register(CustomLinkSanitizer, true);
|
|
58
|
-
const QuillEditor = ({
|
|
58
|
+
const QuillEditor = /*#__PURE__*/forwardRef(({
|
|
59
59
|
height,
|
|
60
60
|
width,
|
|
61
61
|
maxHeight,
|
|
@@ -82,12 +82,15 @@ const QuillEditor = ({
|
|
|
82
82
|
disabled,
|
|
83
83
|
pasteAsText,
|
|
84
84
|
name,
|
|
85
|
-
id
|
|
86
|
-
|
|
87
|
-
}) => {
|
|
85
|
+
id
|
|
86
|
+
}, ref) => {
|
|
88
87
|
const [quill, setQuill] = useState(null);
|
|
89
88
|
const isMounted = useRef(false);
|
|
90
89
|
const containerRef = useRef(null);
|
|
90
|
+
const defaultValueRef = useRef(initialValue);
|
|
91
|
+
const onTextChangeRef = useRef(onChange);
|
|
92
|
+
// const onFocusRef = useRef(onFocus)
|
|
93
|
+
// const onBlurRef = useRef(onBlur)
|
|
91
94
|
const {
|
|
92
95
|
alert
|
|
93
96
|
} = useTheme();
|
|
@@ -134,20 +137,17 @@ const QuillEditor = ({
|
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
139
|
};
|
|
137
|
-
const handleChange = useCallback((delta, _oldDelta, source) => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
onChange(html, delta, source, quill);
|
|
142
|
-
}
|
|
140
|
+
const handleChange = useCallback((delta, _oldDelta, source, instance) => {
|
|
141
|
+
const html = instance.root.innerHTML;
|
|
142
|
+
if (onChange) {
|
|
143
|
+
onChange(html, delta, source, quill);
|
|
143
144
|
}
|
|
144
145
|
}, [quill, onChange]);
|
|
145
|
-
const handelFocus = useCallback(
|
|
146
|
-
|
|
147
|
-
const html = quill.root.innerHTML;
|
|
146
|
+
const handelFocus = useCallback(instance => {
|
|
147
|
+
const html = instance.root.innerHTML;
|
|
148
148
|
onFocus && onFocus(html);
|
|
149
149
|
}, [quill, onFocus]);
|
|
150
|
-
const applySizes =
|
|
150
|
+
const applySizes = quill => {
|
|
151
151
|
if (!quill) return;
|
|
152
152
|
minHeight && (quill.root.style.minHeight = `${minHeight}px`);
|
|
153
153
|
maxHeight && (quill.root.style.maxHeight = `${maxHeight}px`);
|
|
@@ -156,55 +156,67 @@ const QuillEditor = ({
|
|
|
156
156
|
height && (quill.root.style.height = `${height}px`);
|
|
157
157
|
minWidth && (quill.root.style.minWidth = `${minWidth}px`);
|
|
158
158
|
};
|
|
159
|
+
useLayoutEffect(() => {
|
|
160
|
+
onTextChangeRef.current = onChange;
|
|
161
|
+
});
|
|
159
162
|
useEffect(() => {
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
163
|
+
if (isMounted.current) return;
|
|
164
|
+
const container = containerRef.current;
|
|
165
|
+
const editor = container?.appendChild(container.ownerDocument.createElement('div'));
|
|
166
|
+
if (!editor) return;
|
|
167
|
+
const quillInstance = new Quill(editor, {
|
|
168
|
+
theme: 'snow',
|
|
169
|
+
modules: {
|
|
170
|
+
...modules
|
|
171
|
+
},
|
|
172
|
+
formats,
|
|
173
|
+
placeholder,
|
|
174
|
+
bounds,
|
|
175
|
+
readOnly
|
|
176
|
+
});
|
|
177
|
+
ref && ref.current && (ref.current = editor);
|
|
178
|
+
const editorActual = editor.querySelector('.ql-editor');
|
|
179
|
+
if (editorActual) {
|
|
180
|
+
editorActual.setAttribute('id', id || 'ql-editor');
|
|
181
|
+
editorActual.setAttribute('name', name || 'ql-editor');
|
|
182
|
+
}
|
|
183
|
+
applySizes(quillInstance);
|
|
184
|
+
quillInstance.keyboard.addBinding({
|
|
185
|
+
key: 'Backspace'
|
|
186
|
+
}, {
|
|
187
|
+
format: {
|
|
188
|
+
list: true,
|
|
189
|
+
indent: true
|
|
177
190
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
quillInstance.
|
|
191
|
-
|
|
192
|
-
}, () => {
|
|
193
|
-
// Remove focus from editor
|
|
194
|
-
quillInstance.blur();
|
|
191
|
+
}, (range, context) => {
|
|
192
|
+
return handleBackspaceWithIndentetList(range, context, quillInstance);
|
|
193
|
+
});
|
|
194
|
+
// Move the last binding in the list, to the top. Ensure that the custom binding is called first.
|
|
195
|
+
quillInstance.keyboard.bindings['Backspace'].unshift(quillInstance.keyboard.bindings['Backspace'].pop());
|
|
196
|
+
quillInstance.keyboard.addBinding({
|
|
197
|
+
key: 'Escape'
|
|
198
|
+
}, () => {
|
|
199
|
+
// Remove focus from editor
|
|
200
|
+
quillInstance.blur();
|
|
201
|
+
});
|
|
202
|
+
if (defaultValueRef.current) {
|
|
203
|
+
const delta = quillInstance.clipboard.convert({
|
|
204
|
+
html: defaultValueRef.current
|
|
195
205
|
});
|
|
196
|
-
|
|
197
|
-
if (quillInstance.root.innerHTML !== initialValue) {
|
|
198
|
-
const delta = quillInstance.clipboard.convert({
|
|
199
|
-
html: initialValue
|
|
200
|
-
});
|
|
201
|
-
quillInstance.setContents(delta);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
isMounted.current = true;
|
|
205
|
-
setQuill(quillInstance);
|
|
206
|
+
quillInstance.setContents(delta);
|
|
206
207
|
}
|
|
207
|
-
|
|
208
|
+
quillInstance.on(Quill.events.TEXT_CHANGE, (...args) => handleChange(...args, quillInstance));
|
|
209
|
+
quillInstance.on(Quill.events.SELECTION_CHANGE, range => {
|
|
210
|
+
if (!range) return;
|
|
211
|
+
handelFocus(quillInstance);
|
|
212
|
+
});
|
|
213
|
+
isMounted.current = true;
|
|
214
|
+
setQuill(quillInstance);
|
|
215
|
+
return () => {
|
|
216
|
+
ref && ref.current && (ref.current = null);
|
|
217
|
+
container.innerHTML = '';
|
|
218
|
+
};
|
|
219
|
+
}, [ref]);
|
|
208
220
|
useEffect(() => {
|
|
209
221
|
if (!quill) return;
|
|
210
222
|
const handleBlur = () => {
|
|
@@ -218,26 +230,6 @@ const QuillEditor = ({
|
|
|
218
230
|
quill.root.removeEventListener('blur', handleBlur);
|
|
219
231
|
};
|
|
220
232
|
}, [quill]);
|
|
221
|
-
useEffect(() => {
|
|
222
|
-
if (!quill) return;
|
|
223
|
-
quill.on('selection-change', (range, oldRange, source) => {
|
|
224
|
-
if (!range) return;
|
|
225
|
-
handelFocus();
|
|
226
|
-
});
|
|
227
|
-
return () => {
|
|
228
|
-
quill.off('selection-change');
|
|
229
|
-
};
|
|
230
|
-
}, [quill]);
|
|
231
|
-
useEffect(() => {
|
|
232
|
-
if (!quill) return;
|
|
233
|
-
quill.on('text-change', handleChange);
|
|
234
|
-
return () => {
|
|
235
|
-
quill.off('text-change', handleChange);
|
|
236
|
-
};
|
|
237
|
-
}, [quill, isMounted]);
|
|
238
|
-
useEffect(() => {
|
|
239
|
-
applySizes();
|
|
240
|
-
}, [quill, height, width, maxHeight, maxWidth, minHeight, minWidth]);
|
|
241
233
|
useEffect(() => {
|
|
242
234
|
if (!quill) return;
|
|
243
235
|
quill.clipboard.addMatcher(Node.ELEMENT_NODE, (node, delta) => {
|
|
@@ -298,5 +290,5 @@ const QuillEditor = ({
|
|
|
298
290
|
})
|
|
299
291
|
})]
|
|
300
292
|
});
|
|
301
|
-
};
|
|
293
|
+
});
|
|
302
294
|
export default QuillEditor;
|