@bbl-digital/snorre 4.1.11 → 4.1.13
Sign up to get free protection for your applications and to get access to all the features.
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,86 +35559,80 @@ 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 = () => {
|
35614
|
-
|
35615
|
-
|
35626
|
+
setTimeout(() => {
|
35627
|
+
const html = quill.root.innerHTML;
|
35628
|
+
onBlur && onBlur(html);
|
35629
|
+
}, 50);
|
35616
35630
|
};
|
35617
35631
|
quill.root.addEventListener('blur', handleBlur);
|
35618
35632
|
return () => {
|
35619
35633
|
quill.root.removeEventListener('blur', handleBlur);
|
35620
35634
|
};
|
35621
35635
|
}, [quill]);
|
35622
|
-
React.useEffect(() => {
|
35623
|
-
if (!quill) return;
|
35624
|
-
quill.on('selection-change', (range, oldRange, source) => {
|
35625
|
-
if (!range) return;
|
35626
|
-
handelFocus();
|
35627
|
-
});
|
35628
|
-
return () => {
|
35629
|
-
quill.off('selection-change');
|
35630
|
-
};
|
35631
|
-
}, [quill]);
|
35632
|
-
React.useEffect(() => {
|
35633
|
-
if (!quill) return;
|
35634
|
-
quill.on('text-change', handleChange);
|
35635
|
-
return () => {
|
35636
|
-
quill.off('text-change', handleChange);
|
35637
|
-
};
|
35638
|
-
}, [quill, isMounted]);
|
35639
|
-
React.useEffect(() => {
|
35640
|
-
applySizes();
|
35641
|
-
}, [quill, height, width, maxHeight, maxWidth, minHeight, minWidth]);
|
35642
35636
|
React.useEffect(() => {
|
35643
35637
|
if (!quill) return;
|
35644
35638
|
quill.clipboard.addMatcher(Node.ELEMENT_NODE, (node, delta) => {
|
@@ -35699,7 +35693,7 @@ to {top: 100vh;}
|
|
35699
35693
|
})
|
35700
35694
|
})]
|
35701
35695
|
});
|
35702
|
-
};
|
35696
|
+
});
|
35703
35697
|
|
35704
35698
|
const getReducedArray = (array, indexesAmount) => {
|
35705
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,86 +156,80 @@ 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 = () => {
|
211
|
-
|
212
|
-
|
223
|
+
setTimeout(() => {
|
224
|
+
const html = quill.root.innerHTML;
|
225
|
+
onBlur && onBlur(html);
|
226
|
+
}, 50);
|
213
227
|
};
|
214
228
|
quill.root.addEventListener('blur', handleBlur);
|
215
229
|
return () => {
|
216
230
|
quill.root.removeEventListener('blur', handleBlur);
|
217
231
|
};
|
218
232
|
}, [quill]);
|
219
|
-
useEffect(() => {
|
220
|
-
if (!quill) return;
|
221
|
-
quill.on('selection-change', (range, oldRange, source) => {
|
222
|
-
if (!range) return;
|
223
|
-
handelFocus();
|
224
|
-
});
|
225
|
-
return () => {
|
226
|
-
quill.off('selection-change');
|
227
|
-
};
|
228
|
-
}, [quill]);
|
229
|
-
useEffect(() => {
|
230
|
-
if (!quill) return;
|
231
|
-
quill.on('text-change', handleChange);
|
232
|
-
return () => {
|
233
|
-
quill.off('text-change', handleChange);
|
234
|
-
};
|
235
|
-
}, [quill, isMounted]);
|
236
|
-
useEffect(() => {
|
237
|
-
applySizes();
|
238
|
-
}, [quill, height, width, maxHeight, maxWidth, minHeight, minWidth]);
|
239
233
|
useEffect(() => {
|
240
234
|
if (!quill) return;
|
241
235
|
quill.clipboard.addMatcher(Node.ELEMENT_NODE, (node, delta) => {
|
@@ -296,5 +290,5 @@ const QuillEditor = ({
|
|
296
290
|
})
|
297
291
|
})]
|
298
292
|
});
|
299
|
-
};
|
293
|
+
});
|
300
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,86 +156,80 @@ 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 = () => {
|
211
|
-
|
212
|
-
|
223
|
+
setTimeout(() => {
|
224
|
+
const html = quill.root.innerHTML;
|
225
|
+
onBlur && onBlur(html);
|
226
|
+
}, 50);
|
213
227
|
};
|
214
228
|
quill.root.addEventListener('blur', handleBlur);
|
215
229
|
return () => {
|
216
230
|
quill.root.removeEventListener('blur', handleBlur);
|
217
231
|
};
|
218
232
|
}, [quill]);
|
219
|
-
useEffect(() => {
|
220
|
-
if (!quill) return;
|
221
|
-
quill.on('selection-change', (range, oldRange, source) => {
|
222
|
-
if (!range) return;
|
223
|
-
handelFocus();
|
224
|
-
});
|
225
|
-
return () => {
|
226
|
-
quill.off('selection-change');
|
227
|
-
};
|
228
|
-
}, [quill]);
|
229
|
-
useEffect(() => {
|
230
|
-
if (!quill) return;
|
231
|
-
quill.on('text-change', handleChange);
|
232
|
-
return () => {
|
233
|
-
quill.off('text-change', handleChange);
|
234
|
-
};
|
235
|
-
}, [quill, isMounted]);
|
236
|
-
useEffect(() => {
|
237
|
-
applySizes();
|
238
|
-
}, [quill, height, width, maxHeight, maxWidth, minHeight, minWidth]);
|
239
233
|
useEffect(() => {
|
240
234
|
if (!quill) return;
|
241
235
|
quill.clipboard.addMatcher(Node.ELEMENT_NODE, (node, delta) => {
|
@@ -296,5 +290,5 @@ const QuillEditor = ({
|
|
296
290
|
})
|
297
291
|
})]
|
298
292
|
});
|
299
|
-
};
|
293
|
+
});
|
300
294
|
export default QuillEditor;
|