@lexical/react 0.1.8 → 0.1.9
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/DEPRECATED_useLexical.prod.js +1 -1
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +142 -55
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -16
- package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -1
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +1 -2
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +3 -3
- package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
- package/DEPRECATED_useLexicalEditor.prod.js +1 -1
- package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
- package/DEPRECATED_useLexicalHistory.dev.js +17 -14
- package/DEPRECATED_useLexicalHistory.prod.js +7 -7
- package/DEPRECATED_useLexicalList.prod.js +1 -1
- package/DEPRECATED_useLexicalPlainText.dev.js +46 -23
- package/DEPRECATED_useLexicalPlainText.prod.js +16 -16
- package/DEPRECATED_useLexicalRichText.dev.js +47 -24
- package/DEPRECATED_useLexicalRichText.prod.js +27 -27
- package/LexicalAutoFormatterPlugin.dev.js +142 -55
- package/LexicalAutoFormatterPlugin.prod.js +19 -17
- package/LexicalAutoLinkPlugin.prod.js +4 -4
- package/LexicalBootstrapPlugin.dev.js +0 -2
- package/LexicalBootstrapPlugin.prod.js +2 -2
- package/LexicalCharacterLimitPlugin.dev.js +1 -2
- package/LexicalCharacterLimitPlugin.prod.js +3 -3
- package/LexicalCollaborationPlugin.dev.js +11 -26
- package/LexicalCollaborationPlugin.prod.js +7 -8
- package/LexicalComposer.prod.js +1 -1
- package/LexicalComposerContext.prod.js +1 -1
- package/LexicalContentEditable.prod.js +1 -1
- package/LexicalHashtagPlugin.prod.js +1 -1
- package/LexicalHistoryPlugin.dev.js +17 -14
- package/LexicalHistoryPlugin.prod.js +6 -6
- package/LexicalHorizontalRuleNode.dev.js +66 -0
- package/LexicalHorizontalRuleNode.js +9 -0
- package/LexicalHorizontalRuleNode.prod.js +8 -0
- package/LexicalLinkPlugin.dev.js +0 -1
- package/LexicalLinkPlugin.prod.js +3 -3
- package/LexicalListPlugin.prod.js +1 -1
- package/LexicalNestedComposer.prod.js +1 -1
- package/LexicalOnChangePlugin.prod.js +1 -1
- package/LexicalPlainTextPlugin.dev.js +29 -9
- package/LexicalPlainTextPlugin.prod.js +12 -11
- package/LexicalRichTextPlugin.dev.js +30 -10
- package/LexicalRichTextPlugin.prod.js +16 -16
- package/LexicalTablePlugin.dev.js +20 -38
- package/LexicalTablePlugin.prod.js +3 -3
- package/LexicalTreeView.prod.js +1 -1
- package/package.json +5 -4
- package/useLexicalDecoratorMap.prod.js +1 -1
- package/useLexicalIsTextContentEmpty.prod.js +1 -1
- package/withSubscriptions.prod.js +1 -1
- package/LexicalHorizontalRulePlugin.dev.js +0 -51
- package/LexicalHorizontalRulePlugin.js +0 -9
- package/LexicalHorizontalRulePlugin.prod.js +0 -7
|
@@ -18,9 +18,9 @@ var react = require('react');
|
|
|
18
18
|
*
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
21
|
+
const HISTORY_MERGE = 0;
|
|
22
|
+
const HISTORY_PUSH = 1;
|
|
23
|
+
const DISCARD_HISTORY_CANDIDATE = 2;
|
|
24
24
|
const OTHER = 0;
|
|
25
25
|
const COMPOSING_CHARACTER = 1;
|
|
26
26
|
const INSERT_CHARACTER_AFTER_SELECTION = 2;
|
|
@@ -148,18 +148,21 @@ function createMergeActionGetter(editor, delay) {
|
|
|
148
148
|
if (tags.has('historic')) {
|
|
149
149
|
prevChangeType = OTHER;
|
|
150
150
|
prevChangeTime = changeTime;
|
|
151
|
-
return
|
|
151
|
+
return DISCARD_HISTORY_CANDIDATE;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
const changeType = getChangeType(prevEditorState, nextEditorState, dirtyLeaves, dirtyElements, editor.isComposing());
|
|
155
155
|
|
|
156
156
|
const mergeAction = (() => {
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
const shouldPushHistory = tags.has('history-push');
|
|
158
|
+
const shouldMergeHistory = !shouldPushHistory && tags.has('history-merge');
|
|
159
|
+
|
|
160
|
+
if (shouldMergeHistory) {
|
|
161
|
+
return HISTORY_MERGE;
|
|
159
162
|
}
|
|
160
163
|
|
|
161
164
|
if (prevEditorState === null) {
|
|
162
|
-
return
|
|
165
|
+
return HISTORY_PUSH;
|
|
163
166
|
}
|
|
164
167
|
|
|
165
168
|
const selection = nextEditorState._selection;
|
|
@@ -168,19 +171,19 @@ function createMergeActionGetter(editor, delay) {
|
|
|
168
171
|
|
|
169
172
|
if (!hasDirtyNodes) {
|
|
170
173
|
if (prevSelection === null && selection !== null) {
|
|
171
|
-
return
|
|
174
|
+
return HISTORY_MERGE;
|
|
172
175
|
}
|
|
173
176
|
|
|
174
|
-
return
|
|
177
|
+
return DISCARD_HISTORY_CANDIDATE;
|
|
175
178
|
}
|
|
176
179
|
|
|
177
180
|
const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
|
|
178
181
|
|
|
179
|
-
if (changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
|
|
180
|
-
return
|
|
182
|
+
if (shouldPushHistory === false && changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
|
|
183
|
+
return HISTORY_MERGE;
|
|
181
184
|
}
|
|
182
185
|
|
|
183
|
-
return
|
|
186
|
+
return HISTORY_PUSH;
|
|
184
187
|
})();
|
|
185
188
|
|
|
186
189
|
prevChangeTime = changeTime;
|
|
@@ -217,7 +220,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
|
|
|
217
220
|
|
|
218
221
|
const mergeAction = getMergeAction(prevEditorState, editorState, current, dirtyLeaves, dirtyElements, tags);
|
|
219
222
|
|
|
220
|
-
if (mergeAction ===
|
|
223
|
+
if (mergeAction === HISTORY_PUSH) {
|
|
221
224
|
if (redoStack.length !== 0) {
|
|
222
225
|
historyState.redoStack = [];
|
|
223
226
|
}
|
|
@@ -228,7 +231,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
|
|
|
228
231
|
});
|
|
229
232
|
editor.execCommand('canUndo', true);
|
|
230
233
|
}
|
|
231
|
-
} else if (mergeAction ===
|
|
234
|
+
} else if (mergeAction === DISCARD_HISTORY_CANDIDATE) {
|
|
232
235
|
return;
|
|
233
236
|
} // Else we merge
|
|
234
237
|
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
function w(b,d,k,a,h){if(null===b||0===k.size&&0===a.size)return 0;var g=d._selection,c=b._selection;if(h)return 1;if(null===g||null===c||!c.isCollapsed()||!g.isCollapsed())return 0;var e=Array.from(k);a=Array.from(a);k=d._nodeMap;h=[];for(var f=0;f<e.length;f++){const l=k.get(e[f]);void 0!==l&&h.push(l)}for(e=0;e<a.length;e++)a[e][1]&&(f=k.get(a[e][0]),void 0===f||
|
|
9
|
-
c&&!b._nodeMap.has(d.__key)&&
|
|
10
|
-
function x(b,d){let k=Date.now(),a=0;return(h,g,c,e,f,l)=>{const p=Date.now();if(l.has("historic"))return a=0,k=p,2;const m=w(h,g,e,f,b.isComposing()),u=(()=>{if(l.has("
|
|
11
|
-
function y(b,d,k=1E3){const a=v.useMemo(()=>d||
|
|
12
|
-
a.redoStack,e=a.undoStack,0!==c.length&&(f=a.current,null!==f&&(e.push(f),b.execCommand("canUndo",!0)),e=c.pop(),0===c.length&&b.execCommand("canRedo",!1),a.current=e,e.editor.setEditorState(e.editorState,{tag:"historic"})),!0;case "clearEditor":return h(),!1;case "clearHistory":return h(),!0;default:return!1}},0),b.addListener("update",({editorState:c,prevEditorState:e,dirtyLeaves:f,dirtyElements:l,tags:p})=>{const m=a.current,u=a.redoStack,
|
|
13
|
-
c!==
|
|
7
|
+
var n=require("@lexical/react/withSubscriptions"),t=require("lexical"),v=require("react");
|
|
8
|
+
function w(b,d,k,a,h){if(null===b||0===k.size&&0===a.size)return 0;var g=d._selection,c=b._selection;if(h)return 1;if(null===g||null===c||!c.isCollapsed()||!g.isCollapsed())return 0;var e=Array.from(k);a=Array.from(a);k=d._nodeMap;h=[];for(var f=0;f<e.length;f++){const l=k.get(e[f]);void 0!==l&&h.push(l)}for(e=0;e<a.length;e++)a[e][1]&&(f=k.get(a[e][0]),void 0===f||t.$isRootNode(f)||h.push(f));if(0===h.length)return 0;if(1<h.length)return a=d._nodeMap,d=a.get(g.anchor.key),c=a.get(c.anchor.key),d&&
|
|
9
|
+
c&&!b._nodeMap.has(d.__key)&&t.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=h[0];b=b._nodeMap.get(d.__key);if(!t.$isTextNode(b)||!t.$isTextNode(d)||b.__mode!==d.__mode)return 0;b=b.__text;d=d.__text;if(b===d)return 0;g=g.anchor;c=c.anchor;if(g.key!==c.key||"text"!==g.type)return 0;g=g.offset;c=c.offset;b=d.length-b.length;return 1===b&&c===g-1?2:-1===b&&c===g+1?3:-1===b&&c===g?4:0}
|
|
10
|
+
function x(b,d){let k=Date.now(),a=0;return(h,g,c,e,f,l)=>{const p=Date.now();if(l.has("historic"))return a=0,k=p,2;const m=w(h,g,e,f,b.isComposing()),u=(()=>{const r=l.has("history-push");if(!r&&l.has("history-merge"))return 0;if(null===h)return 1;var q=g._selection;const z=h._selection;if(!(0<e.size||0<f.size))return null===z&&null!==q?0:2;q=null===c||c.editor===b;return!1===r&&0!==m&&m===a&&p<k+d&&q?0:1})();k=p;a=m;return u}}
|
|
11
|
+
function y(b,d,k=1E3){const a=v.useMemo(()=>d||A(),[d]),h=v.useCallback(()=>{a.undoStack=[];a.redoStack=[];a.current=null},[a]);v.useEffect(()=>{const g=x(b,k);return n(b.addListener("command",c=>{switch(c){case "undo":c=a.redoStack;var e=a.undoStack;if(0!==e.length){var f=a.current;const l=e.pop();null!==f&&(c.push(f),b.execCommand("canRedo",!0));0===e.length&&b.execCommand("canUndo",!1);a.current=l;l.editor.setEditorState(l.editorState.clone(l.undoSelection),{tag:"historic"})}return!0;case "redo":return c=
|
|
12
|
+
a.redoStack,e=a.undoStack,0!==c.length&&(f=a.current,null!==f&&(e.push(f),b.execCommand("canUndo",!0)),e=c.pop(),0===c.length&&b.execCommand("canRedo",!1),a.current=e,e.editor.setEditorState(e.editorState,{tag:"historic"})),!0;case "clearEditor":return h(),!1;case "clearHistory":return h(),!0;default:return!1}},0),b.addListener("update",({editorState:c,prevEditorState:e,dirtyLeaves:f,dirtyElements:l,tags:p})=>{const m=a.current,u=a.redoStack,r=a.undoStack,q=null===m?null:m.editorState;if(null===m||
|
|
13
|
+
c!==q){f=g(e,c,m,f,l,p);if(1===f)0!==u.length&&(a.redoStack=[]),null!==m&&(r.push({...m,undoSelection:e.read(t.$getSelection)}),b.execCommand("canUndo",!0));else if(2===f)return;a.current={editor:b,editorState:c}}}))},[h,k,b,a])}function A(){return{current:null,redoStack:[],undoStack:[]}}exports.createEmptyHistoryState=A;exports.useLexicalHistory=function(b,d,k=1E3){return y(b,d,k)};
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
var b=require("@lexical/list"),d=require("react");function e(a){d.useEffect(()=>a.addListener("command",c=>{if("indentContent"===c){if(b.indentList())return!0}else if("outdentContent"===c){if(b.outdentList())return!0}else{if("insertOrderedList"===c)return b.insertList(a,"ol"),!0;if("insertUnorderedList"===c)return b.insertList(a,"ul"),!0;if("removeList"===c)return b.removeList(a),!0}return!1},1),[a])}module.exports=function(a){e(a)};
|
|
@@ -18,9 +18,9 @@ var react = require('react');
|
|
|
18
18
|
*
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
21
|
+
const HISTORY_MERGE = 0;
|
|
22
|
+
const HISTORY_PUSH = 1;
|
|
23
|
+
const DISCARD_HISTORY_CANDIDATE = 2;
|
|
24
24
|
const OTHER = 0;
|
|
25
25
|
const COMPOSING_CHARACTER = 1;
|
|
26
26
|
const INSERT_CHARACTER_AFTER_SELECTION = 2;
|
|
@@ -148,18 +148,21 @@ function createMergeActionGetter(editor, delay) {
|
|
|
148
148
|
if (tags.has('historic')) {
|
|
149
149
|
prevChangeType = OTHER;
|
|
150
150
|
prevChangeTime = changeTime;
|
|
151
|
-
return
|
|
151
|
+
return DISCARD_HISTORY_CANDIDATE;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
const changeType = getChangeType(prevEditorState, nextEditorState, dirtyLeaves, dirtyElements, editor.isComposing());
|
|
155
155
|
|
|
156
156
|
const mergeAction = (() => {
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
const shouldPushHistory = tags.has('history-push');
|
|
158
|
+
const shouldMergeHistory = !shouldPushHistory && tags.has('history-merge');
|
|
159
|
+
|
|
160
|
+
if (shouldMergeHistory) {
|
|
161
|
+
return HISTORY_MERGE;
|
|
159
162
|
}
|
|
160
163
|
|
|
161
164
|
if (prevEditorState === null) {
|
|
162
|
-
return
|
|
165
|
+
return HISTORY_PUSH;
|
|
163
166
|
}
|
|
164
167
|
|
|
165
168
|
const selection = nextEditorState._selection;
|
|
@@ -168,19 +171,19 @@ function createMergeActionGetter(editor, delay) {
|
|
|
168
171
|
|
|
169
172
|
if (!hasDirtyNodes) {
|
|
170
173
|
if (prevSelection === null && selection !== null) {
|
|
171
|
-
return
|
|
174
|
+
return HISTORY_MERGE;
|
|
172
175
|
}
|
|
173
176
|
|
|
174
|
-
return
|
|
177
|
+
return DISCARD_HISTORY_CANDIDATE;
|
|
175
178
|
}
|
|
176
179
|
|
|
177
180
|
const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
|
|
178
181
|
|
|
179
|
-
if (changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
|
|
180
|
-
return
|
|
182
|
+
if (shouldPushHistory === false && changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
|
|
183
|
+
return HISTORY_MERGE;
|
|
181
184
|
}
|
|
182
185
|
|
|
183
|
-
return
|
|
186
|
+
return HISTORY_PUSH;
|
|
184
187
|
})();
|
|
185
188
|
|
|
186
189
|
prevChangeTime = changeTime;
|
|
@@ -217,7 +220,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
|
|
|
217
220
|
|
|
218
221
|
const mergeAction = getMergeAction(prevEditorState, editorState, current, dirtyLeaves, dirtyElements, tags);
|
|
219
222
|
|
|
220
|
-
if (mergeAction ===
|
|
223
|
+
if (mergeAction === HISTORY_PUSH) {
|
|
221
224
|
if (redoStack.length !== 0) {
|
|
222
225
|
historyState.redoStack = [];
|
|
223
226
|
}
|
|
@@ -228,7 +231,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
|
|
|
228
231
|
});
|
|
229
232
|
editor.execCommand('canUndo', true);
|
|
230
233
|
}
|
|
231
|
-
} else if (mergeAction ===
|
|
234
|
+
} else if (mergeAction === DISCARD_HISTORY_CANDIDATE) {
|
|
232
235
|
return;
|
|
233
236
|
} // Else we merge
|
|
234
237
|
|
|
@@ -349,7 +352,7 @@ function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity)
|
|
|
349
352
|
}
|
|
350
353
|
function $isParentElementRTL(selection) {
|
|
351
354
|
const anchorNode = selection.anchor.getNode();
|
|
352
|
-
const parent = anchorNode.getParentOrThrow();
|
|
355
|
+
const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
|
|
353
356
|
return parent.getDirection() === 'rtl';
|
|
354
357
|
}
|
|
355
358
|
function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
@@ -365,17 +368,41 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
365
368
|
*
|
|
366
369
|
*
|
|
367
370
|
*/
|
|
371
|
+
function resolveElement(element, isBackward, focusOffset) {
|
|
372
|
+
const parent = element.getParent();
|
|
373
|
+
let offset = focusOffset;
|
|
374
|
+
let block = element;
|
|
375
|
+
|
|
376
|
+
if (parent !== null) {
|
|
377
|
+
if (isBackward && focusOffset === 0) {
|
|
378
|
+
offset = block.getIndexWithinParent();
|
|
379
|
+
block = parent;
|
|
380
|
+
} else if (!isBackward && focusOffset === block.getChildrenSize()) {
|
|
381
|
+
offset = block.getIndexWithinParent() + 1;
|
|
382
|
+
block = parent;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return block.getChildAtIndex(isBackward ? offset - 1 : offset);
|
|
387
|
+
}
|
|
388
|
+
|
|
368
389
|
function getPossibleDecoratorNode(focus, isBackward) {
|
|
369
390
|
const focusOffset = focus.offset;
|
|
370
391
|
|
|
371
392
|
if (focus.type === 'element') {
|
|
372
393
|
const block = focus.getNode();
|
|
373
|
-
return block
|
|
394
|
+
return resolveElement(block, isBackward, focusOffset);
|
|
374
395
|
} else {
|
|
375
396
|
const focusNode = focus.getNode();
|
|
376
397
|
|
|
377
398
|
if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
|
|
378
|
-
|
|
399
|
+
const possibleNode = isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
|
|
400
|
+
|
|
401
|
+
if (possibleNode === null) {
|
|
402
|
+
return resolveElement(focusNode.getParentOrThrow(), isBackward, focusNode.getIndexWithinParent() + (isBackward ? 0 : 1));
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return possibleNode;
|
|
379
406
|
}
|
|
380
407
|
}
|
|
381
408
|
|
|
@@ -398,13 +425,12 @@ function $insertDataTransferForPlainText(dataTransfer, selection) {
|
|
|
398
425
|
}
|
|
399
426
|
}
|
|
400
427
|
function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
401
|
-
const
|
|
402
|
-
return lexical.$isDecoratorNode(
|
|
428
|
+
const possibleNode = getPossibleDecoratorNode(selection.focus, isBackward);
|
|
429
|
+
return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
|
|
403
430
|
}
|
|
404
431
|
function onPasteForPlainText(event, editor) {
|
|
405
432
|
event.preventDefault();
|
|
406
433
|
editor.update(() => {
|
|
407
|
-
lexical.$log('onPasteForPlainText');
|
|
408
434
|
const selection = lexical.$getSelection();
|
|
409
435
|
const clipboardData = event.clipboardData;
|
|
410
436
|
|
|
@@ -416,7 +442,6 @@ function onPasteForPlainText(event, editor) {
|
|
|
416
442
|
function onCutForPlainText(event, editor) {
|
|
417
443
|
onCopyForPlainText(event, editor);
|
|
418
444
|
editor.update(() => {
|
|
419
|
-
lexical.$log('onCutForPlainText');
|
|
420
445
|
const selection = lexical.$getSelection();
|
|
421
446
|
|
|
422
447
|
if (selection !== null) {
|
|
@@ -427,7 +452,6 @@ function onCutForPlainText(event, editor) {
|
|
|
427
452
|
function onCopyForPlainText(event, editor) {
|
|
428
453
|
event.preventDefault();
|
|
429
454
|
editor.update(() => {
|
|
430
|
-
lexical.$log('onCopyForPlainText');
|
|
431
455
|
const clipboardData = event.clipboardData;
|
|
432
456
|
const selection = lexical.$getSelection();
|
|
433
457
|
|
|
@@ -512,7 +536,6 @@ function useLexicalDragonSupport(editor) {
|
|
|
512
536
|
if (args) {
|
|
513
537
|
const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; // TODO: we should probably handle formatCommand somehow?
|
|
514
538
|
editor.update(() => {
|
|
515
|
-
lexical.$log('useLexicalDragonSupport');
|
|
516
539
|
const selection = lexical.$getSelection();
|
|
517
540
|
|
|
518
541
|
if (selection !== null) {
|
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
function w(a,
|
|
9
|
-
f&&!a._nodeMap.has(
|
|
10
|
-
function x(a,
|
|
11
|
-
function y(a,
|
|
12
|
-
{tag:"historic"})}return!0;case "redo":return f=b.redoStack,h=b.undoStack,0!==f.length&&(k=b.current,null!==k&&(h.push(k),a.execCommand("canUndo",!0)),h=f.pop(),0===f.length&&a.execCommand("canRedo",!1),b.current=h,h.editor.setEditorState(h.editorState,{tag:"historic"})),!0;case "clearEditor":return
|
|
13
|
-
|
|
14
|
-
function B(a,
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
module.exports=function(a,
|
|
7
|
+
var n=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react");
|
|
8
|
+
function w(a,d,c,b,e){if(null===a||0===c.size&&0===b.size)return 0;var g=d._selection,f=a._selection;if(e)return 1;if(null===g||null===f||!f.isCollapsed()||!g.isCollapsed())return 0;var h=Array.from(c);b=Array.from(b);c=d._nodeMap;e=[];for(var k=0;k<h.length;k++){const m=c.get(h[k]);void 0!==m&&e.push(m)}for(h=0;h<b.length;h++)b[h][1]&&(k=c.get(b[h][0]),void 0===k||u.$isRootNode(k)||e.push(k));if(0===e.length)return 0;if(1<e.length)return b=d._nodeMap,d=b.get(g.anchor.key),f=b.get(f.anchor.key),d&&
|
|
9
|
+
f&&!a._nodeMap.has(d.__key)&&u.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=e[0];a=a._nodeMap.get(d.__key);if(!u.$isTextNode(a)||!u.$isTextNode(d)||a.__mode!==d.__mode)return 0;a=a.__text;d=d.__text;if(a===d)return 0;g=g.anchor;f=f.anchor;if(g.key!==f.key||"text"!==g.type)return 0;g=g.offset;f=f.offset;a=d.length-a.length;return 1===a&&f===g-1?2:-1===a&&f===g+1?3:-1===a&&f===g?4:0}
|
|
10
|
+
function x(a,d){let c=Date.now(),b=0;return(e,g,f,h,k,m)=>{const t=Date.now();if(m.has("historic"))return b=0,c=t,2;const l=w(e,g,h,k,a.isComposing()),r=(()=>{const q=m.has("history-push");if(!q&&m.has("history-merge"))return 0;if(null===e)return 1;var p=g._selection;const D=e._selection;if(!(0<h.size||0<k.size))return null===D&&null!==p?0:2;p=null===f||f.editor===a;return!1===q&&0!==l&&l===b&&t<c+d&&p?0:1})();c=t;b=l;return r}}
|
|
11
|
+
function y(a,d,c=1E3){const b=v.useMemo(()=>d||{current:null,redoStack:[],undoStack:[]},[d]),e=v.useCallback(()=>{b.undoStack=[];b.redoStack=[];b.current=null},[b]);v.useEffect(()=>{const g=x(a,c);return n(a.addListener("command",f=>{switch(f){case "undo":f=b.redoStack;var h=b.undoStack;if(0!==h.length){var k=b.current;const m=h.pop();null!==k&&(f.push(k),a.execCommand("canRedo",!0));0===h.length&&a.execCommand("canUndo",!1);b.current=m;m.editor.setEditorState(m.editorState.clone(m.undoSelection),
|
|
12
|
+
{tag:"historic"})}return!0;case "redo":return f=b.redoStack,h=b.undoStack,0!==f.length&&(k=b.current,null!==k&&(h.push(k),a.execCommand("canUndo",!0)),h=f.pop(),0===f.length&&a.execCommand("canRedo",!1),b.current=h,h.editor.setEditorState(h.editorState,{tag:"historic"})),!0;case "clearEditor":return e(),!1;case "clearHistory":return e(),!0;default:return!1}},0),a.addListener("update",({editorState:f,prevEditorState:h,dirtyLeaves:k,dirtyElements:m,tags:t})=>{const l=b.current,r=b.redoStack,q=b.undoStack,
|
|
13
|
+
p=null===l?null:l.editorState;if(null===l||f!==p){k=g(h,f,l,k,m,t);if(1===k)0!==r.length&&(b.redoStack=[]),null!==l&&(q.push({...l,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===k)return;b.current={editor:a,editorState:f}}}))},[e,c,a,b])}function z(a,d,c=1E3){return y(a,d,c)}function A(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}
|
|
14
|
+
function B(a,d,c){const b=a.getParent();let e=c;null!==b&&(d&&0===c?(e=a.getIndexWithinParent(),a=b):d||c!==a.getChildrenSize()||(e=a.getIndexWithinParent()+1,a=b));return a.getChildAtIndex(d?e-1:e)}function C(a,d){a=a.getData("text/plain");null!=a&&d.insertRawText(a)}
|
|
15
|
+
function E(a,d){var c=a.focus;a=c.offset;"element"===c.type?(c=c.getNode(),d=B(c,d,a)):(c=c.getNode(),d&&0===a||!d&&a===c.getTextContentSize()?(a=d?c.getPreviousSibling():c.getNextSibling(),d=null===a?B(c.getParentOrThrow(),d,c.getIndexWithinParent()+(d?0:1)):a):d=null);return u.$isDecoratorNode(d)&&!d.isIsolated()}function F(a,d){a.preventDefault();d.update(()=>{const c=u.$getSelection(),b=a.clipboardData;null!=b&&null!==c&&C(b,c)})}
|
|
16
|
+
function G(a,d){H(a,d);d.update(()=>{const c=u.$getSelection();null!==c&&c.removeText()})}function H(a,d){a.preventDefault();d.update(()=>{const c=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=c){var e=window.getSelection();if(!e.isCollapsed){var g=e.getRangeAt(0);g&&(e=document.createElement("div"),g=g.cloneContents(),e.appendChild(g),c.setData("text/html",e.innerHTML));c.setData("text/plain",b.getTextContent())}}})}
|
|
17
|
+
var I="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?v.useLayoutEffect:v.useEffect;
|
|
18
|
+
function J(a){v.useEffect(()=>{const d=c=>{var b=a.getRootElement();if(document.activeElement===b&&(b=c.data,"string"===typeof b)){try{var e=JSON.parse(b)}catch(g){return}if(e&&"nuanria_messaging"===e.protocol&&"request"===e.type&&(e=e.payload)&&"makeChanges"===e.functionId&&(e=e.args)){const [g,f,h,k,m]=e;a.update(()=>{const t=u.$getSelection();if(null!==t){var l=t.anchor;let r=l.getNode(),q=0,p=0;u.$isTextNode(r)&&0<=g&&0<=f&&(q=g,p=g+f,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==h)t.insertRawText(h),
|
|
19
|
+
r=l.getNode();u.$isTextNode(r)&&(q=k,p=k+m,l=r.getTextContentSize(),q=q>l?l:q,p=p>l?l:p,t.setTextNodeRange(r,q,r,p));c.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
|
|
20
|
+
function K(a){I(()=>{const d=a.addListener("command",(c,b)=>{const e=u.$getSelection();if(null===e)return!1;switch(c){case "deleteCharacter":return e.deleteCharacter(b),!0;case "deleteWord":return e.deleteWord(b),!0;case "deleteLine":return e.deleteLine(b),!0;case "insertText":return"string"===typeof b?e.insertText(b):(c=b.dataTransfer,null!=c?C(c,e):(b=b.data)&&e.insertText(b)),!0;case "removeText":return e.removeText(),!0;case "insertLineBreak":return e.insertLineBreak(b),!0;case "insertParagraph":return e.insertLineBreak(),
|
|
21
|
+
!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":c=b.shiftKey;if(E(e,!0))return b.preventDefault(),b=c,c=A(e),e.modify(b?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=b.shiftKey;if(E(e,!1))return b.preventDefault(),b=c,c=A(e),e.modify(b?"extend":"move",c,"character"),!0;break;case "keyBackspace":return b.preventDefault(),a.execCommand("deleteCharacter",
|
|
22
|
+
!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),a.execCommand("insertLineBreak");case "copy":return H(b,a),!0;case "cut":return G(b,a),!0;case "paste":return F(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return d},[a]);J(a)}module.exports=function(a,d){K(a);z(a,d)};
|
|
@@ -22,9 +22,9 @@ var LinkNode = require('lexical/LinkNode');
|
|
|
22
22
|
*
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
25
|
+
const HISTORY_MERGE = 0;
|
|
26
|
+
const HISTORY_PUSH = 1;
|
|
27
|
+
const DISCARD_HISTORY_CANDIDATE = 2;
|
|
28
28
|
const OTHER = 0;
|
|
29
29
|
const COMPOSING_CHARACTER = 1;
|
|
30
30
|
const INSERT_CHARACTER_AFTER_SELECTION = 2;
|
|
@@ -152,18 +152,21 @@ function createMergeActionGetter(editor, delay) {
|
|
|
152
152
|
if (tags.has('historic')) {
|
|
153
153
|
prevChangeType = OTHER;
|
|
154
154
|
prevChangeTime = changeTime;
|
|
155
|
-
return
|
|
155
|
+
return DISCARD_HISTORY_CANDIDATE;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
const changeType = getChangeType(prevEditorState, nextEditorState, dirtyLeaves, dirtyElements, editor.isComposing());
|
|
159
159
|
|
|
160
160
|
const mergeAction = (() => {
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
const shouldPushHistory = tags.has('history-push');
|
|
162
|
+
const shouldMergeHistory = !shouldPushHistory && tags.has('history-merge');
|
|
163
|
+
|
|
164
|
+
if (shouldMergeHistory) {
|
|
165
|
+
return HISTORY_MERGE;
|
|
163
166
|
}
|
|
164
167
|
|
|
165
168
|
if (prevEditorState === null) {
|
|
166
|
-
return
|
|
169
|
+
return HISTORY_PUSH;
|
|
167
170
|
}
|
|
168
171
|
|
|
169
172
|
const selection = nextEditorState._selection;
|
|
@@ -172,19 +175,19 @@ function createMergeActionGetter(editor, delay) {
|
|
|
172
175
|
|
|
173
176
|
if (!hasDirtyNodes) {
|
|
174
177
|
if (prevSelection === null && selection !== null) {
|
|
175
|
-
return
|
|
178
|
+
return HISTORY_MERGE;
|
|
176
179
|
}
|
|
177
180
|
|
|
178
|
-
return
|
|
181
|
+
return DISCARD_HISTORY_CANDIDATE;
|
|
179
182
|
}
|
|
180
183
|
|
|
181
184
|
const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
|
|
182
185
|
|
|
183
|
-
if (changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
|
|
184
|
-
return
|
|
186
|
+
if (shouldPushHistory === false && changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
|
|
187
|
+
return HISTORY_MERGE;
|
|
185
188
|
}
|
|
186
189
|
|
|
187
|
-
return
|
|
190
|
+
return HISTORY_PUSH;
|
|
188
191
|
})();
|
|
189
192
|
|
|
190
193
|
prevChangeTime = changeTime;
|
|
@@ -221,7 +224,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
|
|
|
221
224
|
|
|
222
225
|
const mergeAction = getMergeAction(prevEditorState, editorState, current, dirtyLeaves, dirtyElements, tags);
|
|
223
226
|
|
|
224
|
-
if (mergeAction ===
|
|
227
|
+
if (mergeAction === HISTORY_PUSH) {
|
|
225
228
|
if (redoStack.length !== 0) {
|
|
226
229
|
historyState.redoStack = [];
|
|
227
230
|
}
|
|
@@ -232,7 +235,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
|
|
|
232
235
|
});
|
|
233
236
|
editor.execCommand('canUndo', true);
|
|
234
237
|
}
|
|
235
|
-
} else if (mergeAction ===
|
|
238
|
+
} else if (mergeAction === DISCARD_HISTORY_CANDIDATE) {
|
|
236
239
|
return;
|
|
237
240
|
} // Else we merge
|
|
238
241
|
|
|
@@ -473,7 +476,7 @@ function $cloneContents(selection) {
|
|
|
473
476
|
const firstNode = nodes[0];
|
|
474
477
|
const firstNodeParent = firstNode.getParent();
|
|
475
478
|
|
|
476
|
-
if (firstNodeParent !== null && !firstNodeParent.canBeEmpty()) {
|
|
479
|
+
if (firstNodeParent !== null && (!firstNodeParent.canBeEmpty() || lexical.$isRootNode(firstNodeParent))) {
|
|
477
480
|
const parentChildren = firstNodeParent.__children;
|
|
478
481
|
const parentChildrenLength = parentChildren.length;
|
|
479
482
|
|
|
@@ -529,7 +532,7 @@ function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity)
|
|
|
529
532
|
}
|
|
530
533
|
function $isParentElementRTL(selection) {
|
|
531
534
|
const anchorNode = selection.anchor.getNode();
|
|
532
|
-
const parent = anchorNode.getParentOrThrow();
|
|
535
|
+
const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
|
|
533
536
|
return parent.getDirection() === 'rtl';
|
|
534
537
|
}
|
|
535
538
|
function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
@@ -545,17 +548,41 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
545
548
|
*
|
|
546
549
|
*
|
|
547
550
|
*/
|
|
551
|
+
function resolveElement(element, isBackward, focusOffset) {
|
|
552
|
+
const parent = element.getParent();
|
|
553
|
+
let offset = focusOffset;
|
|
554
|
+
let block = element;
|
|
555
|
+
|
|
556
|
+
if (parent !== null) {
|
|
557
|
+
if (isBackward && focusOffset === 0) {
|
|
558
|
+
offset = block.getIndexWithinParent();
|
|
559
|
+
block = parent;
|
|
560
|
+
} else if (!isBackward && focusOffset === block.getChildrenSize()) {
|
|
561
|
+
offset = block.getIndexWithinParent() + 1;
|
|
562
|
+
block = parent;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
return block.getChildAtIndex(isBackward ? offset - 1 : offset);
|
|
567
|
+
}
|
|
568
|
+
|
|
548
569
|
function getPossibleDecoratorNode(focus, isBackward) {
|
|
549
570
|
const focusOffset = focus.offset;
|
|
550
571
|
|
|
551
572
|
if (focus.type === 'element') {
|
|
552
573
|
const block = focus.getNode();
|
|
553
|
-
return block
|
|
574
|
+
return resolveElement(block, isBackward, focusOffset);
|
|
554
575
|
} else {
|
|
555
576
|
const focusNode = focus.getNode();
|
|
556
577
|
|
|
557
578
|
if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
|
|
558
|
-
|
|
579
|
+
const possibleNode = isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
|
|
580
|
+
|
|
581
|
+
if (possibleNode === null) {
|
|
582
|
+
return resolveElement(focusNode.getParentOrThrow(), isBackward, focusNode.getIndexWithinParent() + (isBackward ? 0 : 1));
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
return possibleNode;
|
|
559
586
|
}
|
|
560
587
|
}
|
|
561
588
|
|
|
@@ -889,13 +916,12 @@ function $insertDataTransferForPlainText(dataTransfer, selection) {
|
|
|
889
916
|
}
|
|
890
917
|
}
|
|
891
918
|
function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
892
|
-
const
|
|
893
|
-
return lexical.$isDecoratorNode(
|
|
919
|
+
const possibleNode = getPossibleDecoratorNode(selection.focus, isBackward);
|
|
920
|
+
return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
|
|
894
921
|
}
|
|
895
922
|
function onPasteForRichText(event, editor) {
|
|
896
923
|
event.preventDefault();
|
|
897
924
|
editor.update(() => {
|
|
898
|
-
lexical.$log('onPasteForRichText');
|
|
899
925
|
const selection = lexical.$getSelection();
|
|
900
926
|
const clipboardData = event.clipboardData;
|
|
901
927
|
|
|
@@ -907,7 +933,6 @@ function onPasteForRichText(event, editor) {
|
|
|
907
933
|
function onCutForRichText(event, editor) {
|
|
908
934
|
onCopyForRichText(event, editor);
|
|
909
935
|
editor.update(() => {
|
|
910
|
-
lexical.$log('onCutForRichText');
|
|
911
936
|
const selection = lexical.$getSelection();
|
|
912
937
|
|
|
913
938
|
if (selection !== null) {
|
|
@@ -918,7 +943,6 @@ function onCutForRichText(event, editor) {
|
|
|
918
943
|
function onCopyForRichText(event, editor) {
|
|
919
944
|
event.preventDefault();
|
|
920
945
|
editor.update(() => {
|
|
921
|
-
lexical.$log('onCopyForRichText');
|
|
922
946
|
const clipboardData = event.clipboardData;
|
|
923
947
|
const selection = lexical.$getSelection();
|
|
924
948
|
|
|
@@ -1008,7 +1032,6 @@ function useLexicalDragonSupport(editor) {
|
|
|
1008
1032
|
if (args) {
|
|
1009
1033
|
const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; // TODO: we should probably handle formatCommand somehow?
|
|
1010
1034
|
editor.update(() => {
|
|
1011
|
-
lexical.$log('useLexicalDragonSupport');
|
|
1012
1035
|
const selection = lexical.$getSelection();
|
|
1013
1036
|
|
|
1014
1037
|
if (selection !== null) {
|