@lexical/react 0.2.5 → 0.2.6

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.
@@ -7,7 +7,6 @@
7
7
  'use strict';
8
8
 
9
9
  var markdown = require('@lexical/markdown');
10
- var LexicalHorizontalRuleNode = require('@lexical/react/LexicalHorizontalRuleNode');
11
10
  var react = require('react');
12
11
 
13
12
  /**
@@ -18,22 +17,10 @@ var react = require('react');
18
17
  *
19
18
  *
20
19
  */
21
- function useMarkdownShortcuts(editor) {
20
+ function useLexicalAutoFormatter(editor) {
22
21
  react.useEffect(() => {
23
- return markdown.registerMarkdownShortcuts(editor, LexicalHorizontalRuleNode.$createHorizontalRuleNode);
22
+ return markdown.registerMarkdownShortcuts(editor, markdown.TRANSFORMERS);
24
23
  }, [editor]);
25
24
  }
26
25
 
27
- /**
28
- * Copyright (c) Meta Platforms, Inc. and affiliates.
29
- *
30
- * This source code is licensed under the MIT license found in the
31
- * LICENSE file in the root directory of this source tree.
32
- *
33
- *
34
- */
35
- function useLexicalAutoFormatter(editor) {
36
- useMarkdownShortcuts(editor);
37
- }
38
-
39
26
  module.exports = useLexicalAutoFormatter;
@@ -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
- var b=require("@lexical/markdown"),c=require("@lexical/react/LexicalHorizontalRuleNode"),d=require("react");function e(a){d.useEffect(()=>b.registerMarkdownShortcuts(a,c.$createHorizontalRuleNode),[a])}module.exports=function(a){e(a)};
7
+ var a=require("@lexical/markdown"),c=require("react");module.exports=function(b){c.useEffect(()=>a.registerMarkdownShortcuts(b,a.TRANSFORMERS),[b])};
@@ -8,6 +8,6 @@ var k=require("@lexical/overflow"),q=require("@lexical/text"),w=require("@lexica
8
8
  function C(a){const d=a.getChildren(),f=d.length;for(let e=0;e<f;e++)a.insertBefore(d[e]);a.remove();return 0<f?d[f-1]:null}
9
9
  function D(a){const d=a.getPreviousSibling();if(k.$isOverflowNode(d)){var f=a.getFirstChild(),e=d.getChildren(),m=e.length;if(null===f)a.append(...e);else for(var c=0;c<m;c++)f.insertBefore(e[c]);c=x.$getSelection();if(x.$isRangeSelection(c)){f=c.anchor;e=f.getNode();c=c.focus;const g=f.getNode();e.is(d)?f.set(a.getKey(),f.offset,"element"):e.is(a)&&f.set(a.getKey(),m+f.offset,"element");g.is(d)?c.set(a.getKey(),c.offset,"element"):g.is(a)&&c.set(a.getKey(),m+c.offset,"element")}d.remove()}}
10
10
  exports.mergePrevious=D;
11
- exports.useCharacterLimit=function(a,d,f=Object.freeze({})){const {strlen:e=c=>c.length,remainingCharacters:m=()=>{}}=f;y.useEffect(()=>{if(!a.hasNodes([k.OverflowNode]))throw Error("Minified Lexical error #58; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");},[a]);y.useEffect(()=>{let c=a.getEditorState().read(q.$rootTextContentCurry),g=0;return w.mergeRegister(a.registerTextContentListener(n=>{c=n}),a.registerUpdateListener(({dirtyLeaves:n})=>
11
+ exports.useCharacterLimit=function(a,d,f=Object.freeze({})){const {strlen:e=c=>c.length,remainingCharacters:m=()=>{}}=f;y.useEffect(()=>{if(!a.hasNodes([k.OverflowNode]))throw Error("Minified Lexical error #49; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");},[a]);y.useEffect(()=>{let c=a.getEditorState().read(q.$rootTextContentCurry),g=0;return w.mergeRegister(a.registerTextContentListener(n=>{c=n}),a.registerUpdateListener(({dirtyLeaves:n})=>
12
12
  {var r=a.isComposing();n=0<n.size;if(!r&&n){r=e(c);n=r>d||null!==g&&g>d;m(d-r);if(null===g||n){const p=z(c,d,e);a.update(()=>{const B=w.$dfs(),E=B.length;let t=0;for(let v=0;v<E;v+=1){var {node:b}=B[v];if(k.$isOverflowNode(b)){var l=t;if(t+b.getTextContentSize()<=p){var h=b.getParent();l=b.getPreviousSibling();var u=b.getNextSibling();C(b);b=x.$getSelection();!x.$isRangeSelection(b)||b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()||(x.$isTextNode(l)?l.select():x.$isTextNode(u)?u.select():
13
13
  null!==h&&h.select())}else l<p&&(h=b.getFirstDescendant(),u=null!==h?h.getTextContentSize():0,l+=u,h=x.$isTextNode(h)&&h.isSimpleText(),l=l<=p,(h||l)&&C(b))}else x.$isLeafNode(b)&&(l=t,t+=b.getTextContentSize(),t>p&&!k.$isOverflowNode(b.getParent())&&(h=x.$getSelection(),l<p&&x.$isTextNode(b)&&b.isSimpleText()?([,b]=b.splitText(p-l),b=A(b)):b=A(b),null!==h&&x.$setSelection(h),D(b)))}},{tag:"history-merge"})}g=r}}))},[a,d,m,e])};
@@ -28,10 +28,10 @@ function useList(editor) {
28
28
  list.outdentList();
29
29
  return false;
30
30
  }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.INSERT_ORDERED_LIST_COMMAND, () => {
31
- list.insertList(editor, 'ol');
31
+ list.insertList(editor, 'number');
32
32
  return true;
33
33
  }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.INSERT_UNORDERED_LIST_COMMAND, () => {
34
- list.insertList(editor, 'ul');
34
+ list.insertList(editor, 'bullet');
35
35
  return true;
36
36
  }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.REMOVE_LIST_COMMAND, () => {
37
37
  list.removeList(editor);
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var b=require("@lexical/list"),c=require("@lexical/utils"),d=require("lexical"),e=require("react");
8
- function f(a){e.useEffect(()=>c.mergeRegister(a.registerCommand(d.INDENT_CONTENT_COMMAND,()=>{b.indentList();return!1},d.COMMAND_PRIORITY_LOW),a.registerCommand(d.OUTDENT_CONTENT_COMMAND,()=>{b.outdentList();return!1},d.COMMAND_PRIORITY_LOW),a.registerCommand(b.INSERT_ORDERED_LIST_COMMAND,()=>{b.insertList(a,"ol");return!0},d.COMMAND_PRIORITY_LOW),a.registerCommand(b.INSERT_UNORDERED_LIST_COMMAND,()=>{b.insertList(a,"ul");return!0},d.COMMAND_PRIORITY_LOW),a.registerCommand(b.REMOVE_LIST_COMMAND,()=>
9
- {b.removeList(a);return!0},d.COMMAND_PRIORITY_LOW),a.registerCommand(d.INSERT_PARAGRAPH_COMMAND,()=>b.$handleListInsertParagraph()?!0:!1,d.COMMAND_PRIORITY_LOW)),[a])}module.exports=function(a){f(a)};
8
+ function f(a){e.useEffect(()=>c.mergeRegister(a.registerCommand(d.INDENT_CONTENT_COMMAND,()=>{b.indentList();return!1},d.COMMAND_PRIORITY_LOW),a.registerCommand(d.OUTDENT_CONTENT_COMMAND,()=>{b.outdentList();return!1},d.COMMAND_PRIORITY_LOW),a.registerCommand(b.INSERT_ORDERED_LIST_COMMAND,()=>{b.insertList(a,"number");return!0},d.COMMAND_PRIORITY_LOW),a.registerCommand(b.INSERT_UNORDERED_LIST_COMMAND,()=>{b.insertList(a,"bullet");return!0},d.COMMAND_PRIORITY_LOW),a.registerCommand(b.REMOVE_LIST_COMMAND,
9
+ ()=>{b.removeList(a);return!0},d.COMMAND_PRIORITY_LOW),a.registerCommand(d.INSERT_PARAGRAPH_COMMAND,()=>b.$handleListInsertParagraph()?!0:!1,d.COMMAND_PRIORITY_LOW)),[a])}module.exports=function(a){f(a)};
@@ -7,6 +7,6 @@
7
7
  var h=require("@lexical/link"),k=require("@lexical/react/LexicalComposerContext"),p=require("@lexical/utils"),v=require("lexical"),w=require("react");function x(a,b){for(let c=0;c<b.length;c++){const d=b[c](a);if(d)return d}return null}function y(a){a=a.getPreviousSibling();v.$isElementNode(a)&&(a=a.getLastDescendant());return null===a||v.$isLineBreakNode(a)||v.$isTextNode(a)&&a.getTextContent().endsWith(" ")}
8
8
  function A(a){a=a.getNextSibling();v.$isElementNode(a)&&(a=a.getFirstDescendant());return null===a||v.$isLineBreakNode(a)||v.$isTextNode(a)&&a.getTextContent().startsWith(" ")}
9
9
  function B(a,b,c){var d=a.getChildren();const e=d.length;for(let g=0;g<e;g++){const f=d[g];if(!v.$isTextNode(f)||!f.isSimpleText()){C(a);c(null,a.getURL());return}}d=a.getTextContent();b=x(d,b);null===b||b.text!==d?(C(a),c(null,a.getURL())):y(a)&&A(a)?(d=a.getURL(),null!==b&&d!==b.url&&(a.setURL(b.url),c(b.url,d))):(C(a),c(null,a.getURL()))}function C(a){const b=a.getChildren();var c=b.length;for(--c;0<=c;c--)a.insertAfter(b[c]);a.remove();return b.map(d=>d.getLatest())}
10
- function D(a,b,c){w.useEffect(()=>{if(!a.hasNodes([h.AutoLinkNode]))throw Error("Minified Lexical error #53; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");const d=(...e)=>{c&&c(...e)};return p.mergeRegister(a.registerNodeTransform(v.TextNode,e=>{var g=e.getParentOrThrow();if(h.$isAutoLinkNode(g))B(g,b,d);else if(!h.$isLinkNode(g)){if(e.isSimpleText()){g=e.getTextContent();const E=g.length;let u=g,z=0,t=e;for(var f;(f=
10
+ function D(a,b,c){w.useEffect(()=>{if(!a.hasNodes([h.AutoLinkNode]))throw Error("Minified Lexical error #5; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");const d=(...e)=>{c&&c(...e)};return p.mergeRegister(a.registerNodeTransform(v.TextNode,e=>{var g=e.getParentOrThrow();if(h.$isAutoLinkNode(g))B(g,b,d);else if(!h.$isLinkNode(g)){if(e.isSimpleText()){g=e.getTextContent();const E=g.length;let u=g,z=0,t=e;for(var f;(f=
11
11
  x(u,b))&&null!==f;){var l=f.index,n=z+l;const q=f.length;var r=void 0;r=0<n?" "===g[n-1]:y(e);n=n+q<E?" "===g[n+q]:A(e);if(r&&n){var m=void 0;0===l?[m,t]=t.splitText(q):[,m,t]=t.splitText(l,l+q);r=h.$createAutoLinkNode(f.url);r.append(v.$createTextNode(f.text));m.replace(r);d(f.url,null)}l+=q;u=u.substring(l);z+=l}}f=e.getPreviousSibling();m=e.getNextSibling();e=e.getTextContent();h.$isAutoLinkNode(f)&&!e.startsWith(" ")&&(C(f),d(null,f.getURL()));h.$isAutoLinkNode(m)&&!e.endsWith(" ")&&(C(m),d(null,
12
12
  m.getURL()))}}),a.registerNodeTransform(h.AutoLinkNode,e=>{B(e,b,d)}))},[a,b,c])}module.exports=function({matchers:a,onChange:b}){const [c]=k.useLexicalComposerContext();D(c,a,b);return null};
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var m=require("@lexical/react/LexicalComposerContext"),u=require("react"),v=require("@lexical/overflow"),z=require("@lexical/text"),A=require("@lexical/utils"),C=require("lexical");
8
- function D(b,c,n=Object.freeze({})){const {strlen:g=d=>d.length,remainingCharacters:q=()=>{}}=n;u.useEffect(()=>{if(!b.hasNodes([v.OverflowNode]))throw Error("Minified Lexical error #58; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");},[b]);u.useEffect(()=>{let d=b.getEditorState().read(z.$rootTextContentCurry),e=0;return A.mergeRegister(b.registerTextContentListener(p=>{d=p}),b.registerUpdateListener(({dirtyLeaves:p})=>
8
+ function D(b,c,n=Object.freeze({})){const {strlen:g=d=>d.length,remainingCharacters:q=()=>{}}=n;u.useEffect(()=>{if(!b.hasNodes([v.OverflowNode]))throw Error("Minified Lexical error #49; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");},[b]);u.useEffect(()=>{let d=b.getEditorState().read(z.$rootTextContentCurry),e=0;return A.mergeRegister(b.registerTextContentListener(p=>{d=p}),b.registerUpdateListener(({dirtyLeaves:p})=>
9
9
  {var w=b.isComposing();p=0<p.size;if(!w&&p){w=g(d);p=w>c||null!==e&&e>c;q(c-w);if(null===e||p){const r=F(d,c,g);b.update(()=>{const B=A.$dfs(),J=B.length;let x=0;for(let y=0;y<J;y+=1){var {node:a}=B[y];if(v.$isOverflowNode(a)){var f=x;if(x+a.getTextContentSize()<=r){var h=a.getParent();f=a.getPreviousSibling();var k=a.getNextSibling();G(a);a=C.$getSelection();!C.$isRangeSelection(a)||a.anchor.getNode().isAttached()&&a.focus.getNode().isAttached()||(C.$isTextNode(f)?f.select():C.$isTextNode(k)?k.select():
10
10
  null!==h&&h.select())}else f<r&&(h=a.getFirstDescendant(),k=null!==h?h.getTextContentSize():0,f+=k,h=C.$isTextNode(h)&&h.isSimpleText(),f=f<=r,(h||f)&&G(a))}else if(C.$isLeafNode(a)&&(f=x,x+=a.getTextContentSize(),x>r&&!v.$isOverflowNode(a.getParent())&&(h=C.$getSelection(),f<r&&C.$isTextNode(a)&&a.isSimpleText()?([,a]=a.splitText(r-f),a=H(a)):a=H(a),null!==h&&C.$setSelection(h),f=a.getPreviousSibling(),v.$isOverflowNode(f)))){k=a.getFirstChild();var t=f.getChildren();h=t.length;if(null===k)a.append(...t);
11
11
  else for(var l=0;l<h;l++)k.insertBefore(t[l]);l=C.$getSelection();if(C.$isRangeSelection(l)){k=l.anchor;t=k.getNode();l=l.focus;const E=k.getNode();t.is(f)?k.set(a.getKey(),k.offset,"element"):t.is(a)&&k.set(a.getKey(),h+k.offset,"element");E.is(f)?l.set(a.getKey(),l.offset,"element"):E.is(a)&&l.set(a.getKey(),h+l.offset,"element")}f.remove()}}},{tag:"history-merge"})}e=w}}))},[b,c,q,g])}
@@ -0,0 +1,247 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ 'use strict';
8
+
9
+ var list = require('@lexical/list');
10
+ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
11
+ var utils = require('@lexical/utils');
12
+ var lexical = require('lexical');
13
+ var react = require('react');
14
+
15
+ /**
16
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
17
+ *
18
+ * This source code is licensed under the MIT license found in the
19
+ * LICENSE file in the root directory of this source tree.
20
+ *
21
+ *
22
+ */
23
+ function ListPlugin() {
24
+ const [editor] = LexicalComposerContext.useLexicalComposerContext();
25
+ react.useEffect(() => {
26
+ return utils.mergeRegister(editor.registerCommand(list.INSERT_CHECK_LIST_COMMAND, () => {
27
+ list.insertList(editor, 'check');
28
+ return true;
29
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND, event => {
30
+ return handleArrownUpOrDown(event, editor, false);
31
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ARROW_UP_COMMAND, event => {
32
+ return handleArrownUpOrDown(event, editor, true);
33
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ESCAPE_COMMAND, event => {
34
+ const activeItem = getActiveCheckListItem();
35
+
36
+ if (activeItem != null) {
37
+ const rootElement = editor.getRootElement();
38
+
39
+ if (rootElement != null) {
40
+ rootElement.focus();
41
+ }
42
+
43
+ return true;
44
+ }
45
+
46
+ return false;
47
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_SPACE_COMMAND, event => {
48
+ const activeItem = getActiveCheckListItem();
49
+
50
+ if (activeItem != null) {
51
+ editor.update(() => {
52
+ const listItemNode = lexical.$getNearestNodeFromDOMNode(activeItem);
53
+
54
+ if (list.$isListItemNode(listItemNode)) {
55
+ event.preventDefault();
56
+ listItemNode.toggleChecked();
57
+ }
58
+ });
59
+ return true;
60
+ }
61
+
62
+ return false;
63
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, event => {
64
+ return editor.getEditorState().read(() => {
65
+ const selection = lexical.$getSelection();
66
+
67
+ if (lexical.$isRangeSelection(selection) && selection.isCollapsed()) {
68
+ const {
69
+ anchor
70
+ } = selection;
71
+ const isElement = anchor.type === 'element';
72
+
73
+ if (isElement || anchor.offset === 0) {
74
+ const anchorNode = anchor.getNode();
75
+ const elementNode = utils.$findMatchingParent(anchorNode, node => lexical.$isElementNode(node) && !node.isInline());
76
+
77
+ if (list.$isListItemNode(elementNode) && (isElement || elementNode.getFirstDescendant() === anchorNode)) {
78
+ const domNode = editor.getElementByKey(elementNode.__key);
79
+
80
+ if (domNode != null && document.activeElement !== domNode) {
81
+ domNode.focus();
82
+ event.preventDefault();
83
+ return true;
84
+ }
85
+ }
86
+ }
87
+ }
88
+
89
+ return false;
90
+ });
91
+ }, lexical.COMMAND_PRIORITY_LOW), listenPointerDown());
92
+ });
93
+ return null;
94
+ }
95
+ let listenersCount = 0;
96
+
97
+ function listenPointerDown() {
98
+ if (listenersCount++ === 0) {
99
+ // $FlowFixMe[speculation-ambiguous]
100
+ document.addEventListener('click', handleClick); // $FlowFixMe[speculation-ambiguous]
101
+
102
+ document.addEventListener('pointerdown', handlePointerDown);
103
+ }
104
+
105
+ return () => {
106
+ if (--listenersCount === 0) {
107
+ // $FlowFixMe[speculation-ambiguous]
108
+ document.removeEventListener('click', handleClick); // $FlowFixMe[speculation-ambiguous]
109
+
110
+ document.removeEventListener('pointerdown', handlePointerDown);
111
+ }
112
+ };
113
+ }
114
+
115
+ function handleCheckItemEvent(event, callback) {
116
+ const target = event.target;
117
+
118
+ if (!(target instanceof HTMLElement)) {
119
+ return;
120
+ } // Ignore clicks on LI that have nested lists
121
+ // $FlowFixMe
122
+
123
+
124
+ const firstChild = target.firstChild;
125
+
126
+ if (firstChild != null && (firstChild.tagName === 'UL' || firstChild.tagName === 'OL')) {
127
+ return;
128
+ }
129
+
130
+ const parentNode = target.parentNode; // $FlowFixMe[prop-missing] internal field
131
+
132
+ if (!parentNode || parentNode.__lexicalListType !== 'check') {
133
+ return;
134
+ }
135
+
136
+ const pageX = event.pageX;
137
+ const rect = target.getBoundingClientRect();
138
+
139
+ if (target.dir === 'rtl' ? pageX < rect.right && pageX > rect.right - 20 : pageX > rect.left && pageX < rect.left + 20) {
140
+ callback();
141
+ }
142
+ }
143
+
144
+ function handleClick(event) {
145
+ handleCheckItemEvent(event, () => {
146
+ const editor = findEditor(event.target);
147
+
148
+ if (editor != null) {
149
+ editor.update(() => {
150
+ const node = lexical.$getNearestNodeFromDOMNode(event.target);
151
+
152
+ if (list.$isListItemNode(node)) {
153
+ event.target.focus();
154
+ node.toggleChecked();
155
+ }
156
+ });
157
+ }
158
+ });
159
+ }
160
+
161
+ function handlePointerDown(event) {
162
+ handleCheckItemEvent(event, () => {
163
+ // Prevents caret moving when clicking on check mark
164
+ event.preventDefault();
165
+ });
166
+ }
167
+
168
+ function findEditor(target) {
169
+ let node = target;
170
+
171
+ while (node) {
172
+ if (node.__lexicalEditor) {
173
+ return node.__lexicalEditor;
174
+ }
175
+
176
+ node = node.parentNode;
177
+ }
178
+
179
+ return null;
180
+ }
181
+
182
+ function getActiveCheckListItem() {
183
+ const {
184
+ activeElement
185
+ } = document;
186
+ return activeElement != null && activeElement.tagName === 'LI' && activeElement.parentNode != null && // $FlowFixMe[prop-missing] internal field
187
+ activeElement.parentNode.__lexicalListType === 'check' ? activeElement : null;
188
+ }
189
+
190
+ function findCheckListItemSibling(node, backward) {
191
+ let sibling = backward ? node.getPreviousSibling() : node.getNextSibling();
192
+ let parent = node; // Going up in a tree to get non-null sibling
193
+
194
+ while (sibling == null && list.$isListItemNode(parent)) {
195
+ // Get li -> parent ul/ol -> parent li
196
+ parent = parent.getParentOrThrow().getParent();
197
+
198
+ if (parent != null) {
199
+ sibling = backward ? parent.getPreviousSibling() : parent.getNextSibling();
200
+ }
201
+ } // Going down in a tree to get first non-nested list item
202
+
203
+
204
+ while (list.$isListItemNode(sibling)) {
205
+ const firstChild = backward ? sibling.getLastChild() : sibling.getFirstChild();
206
+
207
+ if (!list.$isListNode(firstChild)) {
208
+ return sibling;
209
+ }
210
+
211
+ sibling = backward ? firstChild.getLastChild() : firstChild.getFirstChild();
212
+ }
213
+
214
+ return null;
215
+ }
216
+
217
+ function handleArrownUpOrDown(event, editor, backward) {
218
+ const activeItem = getActiveCheckListItem();
219
+
220
+ if (activeItem != null) {
221
+ editor.update(() => {
222
+ const listItem = lexical.$getNearestNodeFromDOMNode(activeItem);
223
+
224
+ if (!list.$isListItemNode(listItem)) {
225
+ return;
226
+ }
227
+
228
+ const nextListItem = findCheckListItemSibling(listItem, backward);
229
+
230
+ if (nextListItem != null) {
231
+ nextListItem.selectStart();
232
+ const dom = editor.getElementByKey(nextListItem.__key);
233
+
234
+ if (dom != null) {
235
+ event.preventDefault();
236
+ setTimeout(() => {
237
+ dom.focus();
238
+ }, 0);
239
+ }
240
+ }
241
+ });
242
+ }
243
+
244
+ return false;
245
+ }
246
+
247
+ module.exports = ListPlugin;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ 'use strict'
8
+ const LexicalCheckListPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalCheckListPlugin.dev.js') : require('./LexicalCheckListPlugin.prod.js')
9
+ module.exports = LexicalCheckListPlugin;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ declare export default function LexicalCheckListPlugin(): null;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ var e=require("@lexical/list"),g=require("@lexical/react/LexicalComposerContext"),k=require("@lexical/utils"),l=require("lexical"),m=require("react");let n=0;function p(){0===n++&&(document.addEventListener("click",q),document.addEventListener("pointerdown",r));return()=>{0===--n&&(document.removeEventListener("click",q),document.removeEventListener("pointerdown",r))}}
8
+ function t(a,c){const b=a.target;if(b instanceof HTMLElement){var d=b.firstChild;(null==d||"UL"!==d.tagName&&"OL"!==d.tagName)&&(d=b.parentNode)&&"check"===d.__lexicalListType&&(a=a.pageX,d=b.getBoundingClientRect(),("rtl"===b.dir?a<d.right&&a>d.right-20:a>d.left&&a<d.left+20)&&c())}}function q(a){t(a,()=>{const c=u(a.target);null!=c&&c.update(()=>{const b=l.$getNearestNodeFromDOMNode(a.target);e.$isListItemNode(b)&&(a.target.focus(),b.toggleChecked())})})}
9
+ function r(a){t(a,()=>{a.preventDefault()})}function u(a){for(;a;){if(a.__lexicalEditor)return a.__lexicalEditor;a=a.parentNode}return null}function v(){const {activeElement:a}=document;return null!=a&&"LI"===a.tagName&&null!=a.parentNode&&"check"===a.parentNode.__lexicalListType?a:null}
10
+ function w(a,c){let b=c?a.getPreviousSibling():a.getNextSibling();for(;null==b&&e.$isListItemNode(a);)a=a.getParentOrThrow().getParent(),null!=a&&(b=c?a.getPreviousSibling():a.getNextSibling());for(;e.$isListItemNode(b);){a=c?b.getLastChild():b.getFirstChild();if(!e.$isListNode(a))return b;b=c?a.getLastChild():a.getFirstChild()}return null}
11
+ function x(a,c,b){const d=v();null!=d&&c.update(()=>{var f=l.$getNearestNodeFromDOMNode(d);if(e.$isListItemNode(f)&&(f=w(f,b),null!=f)){f.selectStart();const h=c.getElementByKey(f.__key);null!=h&&(a.preventDefault(),setTimeout(()=>{h.focus()},0))}});return!1}
12
+ module.exports=function(){const [a]=g.useLexicalComposerContext();m.useEffect(()=>k.mergeRegister(a.registerCommand(e.INSERT_CHECK_LIST_COMMAND,()=>{e.insertList(a,"check");return!0},l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_DOWN_COMMAND,c=>x(c,a,!1),l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_UP_COMMAND,c=>x(c,a,!0),l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ESCAPE_COMMAND,()=>{if(null!=v()){const c=a.getRootElement();null!=c&&c.focus();return!0}return!1},l.COMMAND_PRIORITY_LOW),
13
+ a.registerCommand(l.KEY_SPACE_COMMAND,c=>{const b=v();return null!=b?(a.update(()=>{const d=l.$getNearestNodeFromDOMNode(b);e.$isListItemNode(d)&&(c.preventDefault(),d.toggleChecked())}),!0):!1},l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_LEFT_COMMAND,c=>a.getEditorState().read(()=>{var b=l.$getSelection();if(l.$isRangeSelection(b)&&b.isCollapsed()){var {anchor:d}=b;if((b="element"===d.type)||0===d.offset){d=d.getNode();const f=k.$findMatchingParent(d,h=>l.$isElementNode(h)&&!h.isInline());
14
+ if(e.$isListItemNode(f)&&(b||f.getFirstDescendant()===d)&&(b=a.getElementByKey(f.__key),null!=b&&document.activeElement!==b))return b.focus(),c.preventDefault(),!0}}return!1}),l.COMMAND_PRIORITY_LOW),p()));return null};
@@ -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
- var c=require("react");const d=c.createContext(null);exports.LexicalComposerContext=d;exports.createLexicalComposerContext=function(a,e){let b=null;null!=a&&(b=a[1]);return{getTheme:function(){return null!=e?e:null!=b?b.getTheme():null}}};exports.useLexicalComposerContext=function(){const a=c.useContext(d);if(null==a)throw Error("Minified Lexical error #0; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return a};
7
+ var c=require("react");const d=c.createContext(null);exports.LexicalComposerContext=d;exports.createLexicalComposerContext=function(a,e){let b=null;null!=a&&(b=a[1]);return{getTheme:function(){return null!=e?e:null!=b?b.getTheme():null}}};exports.useLexicalComposerContext=function(){const a=c.useContext(d);if(null==a)throw Error("Minified Lexical error #6; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return a};
@@ -29,10 +29,10 @@ function useList(editor) {
29
29
  list.outdentList();
30
30
  return false;
31
31
  }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.INSERT_ORDERED_LIST_COMMAND, () => {
32
- list.insertList(editor, 'ol');
32
+ list.insertList(editor, 'number');
33
33
  return true;
34
34
  }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.INSERT_UNORDERED_LIST_COMMAND, () => {
35
- list.insertList(editor, 'ul');
35
+ list.insertList(editor, 'bullet');
36
36
  return true;
37
37
  }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.REMOVE_LIST_COMMAND, () => {
38
38
  list.removeList(editor);
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var b=require("@lexical/react/LexicalComposerContext"),c=require("@lexical/list"),d=require("@lexical/utils"),e=require("lexical"),f=require("react");
8
- function g(a){f.useEffect(()=>d.mergeRegister(a.registerCommand(e.INDENT_CONTENT_COMMAND,()=>{c.indentList();return!1},e.COMMAND_PRIORITY_LOW),a.registerCommand(e.OUTDENT_CONTENT_COMMAND,()=>{c.outdentList();return!1},e.COMMAND_PRIORITY_LOW),a.registerCommand(c.INSERT_ORDERED_LIST_COMMAND,()=>{c.insertList(a,"ol");return!0},e.COMMAND_PRIORITY_LOW),a.registerCommand(c.INSERT_UNORDERED_LIST_COMMAND,()=>{c.insertList(a,"ul");return!0},e.COMMAND_PRIORITY_LOW),a.registerCommand(c.REMOVE_LIST_COMMAND,()=>
9
- {c.removeList(a);return!0},e.COMMAND_PRIORITY_LOW),a.registerCommand(e.INSERT_PARAGRAPH_COMMAND,()=>c.$handleListInsertParagraph()?!0:!1,e.COMMAND_PRIORITY_LOW)),[a])}module.exports=function(){const [a]=b.useLexicalComposerContext();g(a);return null};
8
+ function g(a){f.useEffect(()=>d.mergeRegister(a.registerCommand(e.INDENT_CONTENT_COMMAND,()=>{c.indentList();return!1},e.COMMAND_PRIORITY_LOW),a.registerCommand(e.OUTDENT_CONTENT_COMMAND,()=>{c.outdentList();return!1},e.COMMAND_PRIORITY_LOW),a.registerCommand(c.INSERT_ORDERED_LIST_COMMAND,()=>{c.insertList(a,"number");return!0},e.COMMAND_PRIORITY_LOW),a.registerCommand(c.INSERT_UNORDERED_LIST_COMMAND,()=>{c.insertList(a,"bullet");return!0},e.COMMAND_PRIORITY_LOW),a.registerCommand(c.REMOVE_LIST_COMMAND,
9
+ ()=>{c.removeList(a);return!0},e.COMMAND_PRIORITY_LOW),a.registerCommand(e.INSERT_PARAGRAPH_COMMAND,()=>c.$handleListInsertParagraph()?!0:!1,e.COMMAND_PRIORITY_LOW)),[a])}module.exports=function(){const [a]=b.useLexicalComposerContext();g(a);return null};
@@ -6,9 +6,8 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
- var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
9
  var markdown = require('@lexical/markdown');
11
- var LexicalHorizontalRuleNode = require('@lexical/react/LexicalHorizontalRuleNode');
10
+ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
12
11
  var react = require('react');
13
12
 
14
13
  /**
@@ -19,23 +18,13 @@ var react = require('react');
19
18
  *
20
19
  *
21
20
  */
22
- function useMarkdownShortcuts(editor) {
23
- react.useEffect(() => {
24
- return markdown.registerMarkdownShortcuts(editor, LexicalHorizontalRuleNode.$createHorizontalRuleNode);
25
- }, [editor]);
26
- }
27
-
28
- /**
29
- * Copyright (c) Meta Platforms, Inc. and affiliates.
30
- *
31
- * This source code is licensed under the MIT license found in the
32
- * LICENSE file in the root directory of this source tree.
33
- *
34
- *
35
- */
36
- function LexicalMarkdownShortcutPlugin() {
21
+ function LexicalMarkdownShortcutPlugin({
22
+ transformers
23
+ }) {
37
24
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
38
- useMarkdownShortcuts(editor);
25
+ react.useEffect(() => {
26
+ return markdown.registerMarkdownShortcuts(editor, transformers);
27
+ }, [editor, transformers]);
39
28
  return null;
40
29
  }
41
30
 
@@ -7,4 +7,8 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- declare export default function LexicalMarkdownShortcutPlugin(): React$Node;
10
+ import type {Transformer} from '@lexical/markdown';
11
+
12
+ declare export default function LexicalMarkdownShortcutPlugin({
13
+ transformers: Array<Transformer>,
14
+ }): React$Node;
@@ -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
- var b=require("@lexical/react/LexicalComposerContext"),c=require("@lexical/markdown"),d=require("@lexical/react/LexicalHorizontalRuleNode"),e=require("react");function f(a){e.useEffect(()=>c.registerMarkdownShortcuts(a,d.$createHorizontalRuleNode),[a])}module.exports=function(){const [a]=b.useLexicalComposerContext();f(a);return null};
7
+ var c=require("@lexical/markdown"),d=require("@lexical/react/LexicalComposerContext"),e=require("react");module.exports=function({transformers:a}){const [b]=d.useLexicalComposerContext();e.useEffect(()=>c.registerMarkdownShortcuts(b,a),[b,a]);return null};
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var c=require("@lexical/react/LexicalCollaborationPlugin"),d=require("@lexical/react/LexicalComposerContext"),h=require("react");
8
- module.exports=function({initialEditor:a,children:k,initialTheme:l}){const e=h.useContext(d.LexicalComposerContext);if(null==e)throw Error("Minified Lexical error #72; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");const p=h.useMemo(()=>{const [g,m]=e,f=l||m.getTheme()||void 0,n=d.createLexicalComposerContext(e,f);void 0!==f&&(a._config.theme=f);a._parentEditor=g;a._nodes=g._nodes;return[a,n]},[]);var {yjsDocMap:b}=c.useCollaborationContext();
8
+ module.exports=function({initialEditor:a,children:k,initialTheme:l}){const e=h.useContext(d.LexicalComposerContext);if(null==e)throw Error("Minified Lexical error #8; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");const p=h.useMemo(()=>{const [g,m]=e,f=l||m.getTheme()||void 0,n=d.createLexicalComposerContext(e,f);void 0!==f&&(a._config.theme=f);a._parentEditor=g;a._nodes=g._nodes;return[a,n]},[]);var {yjsDocMap:b}=c.useCollaborationContext();
9
9
  const q=void 0!==b.get("main");b=b.has(a.getKey());return h.createElement(d.LexicalComposerContext.Provider,{value:p},!q||b?k:null)};
@@ -5,6 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var e=require("@lexical/react/LexicalComposerContext"),f=require("@lexical/table"),k=require("lexical"),m=require("react");
8
- module.exports=function(){const [c]=e.useLexicalComposerContext();m.useEffect(()=>{if(!c.hasNodes([f.TableNode,f.TableCellNode,f.TableRowNode]))throw Error("Minified Lexical error #54; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return c.registerCommand(f.INSERT_TABLE_COMMAND,a=>{const {columns:h,rows:g}=a;a=k.$getSelection();if(!k.$isRangeSelection(a))return!0;var d=a.focus;a=d.getNode();if(null!==a){const b=f.$createTableNodeWithDimensions(Number(g),
8
+ module.exports=function(){const [c]=e.useLexicalComposerContext();m.useEffect(()=>{if(!c.hasNodes([f.TableNode,f.TableCellNode,f.TableRowNode]))throw Error("Minified Lexical error #7; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return c.registerCommand(f.INSERT_TABLE_COMMAND,a=>{const {columns:h,rows:g}=a;a=k.$getSelection();if(!k.$isRangeSelection(a))return!0;var d=a.focus;a=d.getNode();if(null!==a){const b=f.$createTableNodeWithDimensions(Number(g),
9
9
  Number(h));k.$isRootNode(a)?(d=a.getChildAtIndex(d.offset),null!==d?d.insertBefore(b):a.append(b),b.insertBefore(k.$createParagraphNode())):a.getTopLevelElementOrThrow().insertAfter(b);b.insertAfter(k.$createParagraphNode());b.getFirstChildOrThrow().getFirstChildOrThrow().select()}return!0},k.COMMAND_PRIORITY_EDITOR)},[c]);m.useEffect(()=>{const a=new Map;return c.registerMutationListener(f.TableNode,h=>{for(const [g,d]of h)"created"===d?c.update(()=>{var b=c.getElementByKey(g);const l=k.$getNodeByKey(g);
10
10
  b&&l&&(b=f.applyTableHandlers(l,b,c),a.set(g,b))}):"destroyed"===d&&(h=a.get(g))&&(h.removeListeners(),a.delete(g))})},[c]);return null};
@@ -6,6 +6,7 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
+ var mark = require('@lexical/mark');
9
10
  var lexical = require('lexical');
10
11
  var React = require('react');
11
12
 
@@ -198,7 +199,8 @@ function generateContent(editorState) {
198
199
  const nodeKeyDisplay = `(${nodeKey})`;
199
200
  const typeDisplay = node.getType() || '';
200
201
  const isSelected = node.isSelected();
201
- res += `${isSelected ? SYMBOLS.selectedLine : ' '} ${indent.join(' ')} ${nodeKeyDisplay} ${typeDisplay} ${printNode(node)}\n`;
202
+ const idsDisplay = mark.$isMarkNode(node) ? ` id: [ ${node.getIDs().join(', ')} ] ` : '';
203
+ res += `${isSelected ? SYMBOLS.selectedLine : ' '} ${indent.join(' ')} ${nodeKeyDisplay} ${typeDisplay} ${idsDisplay} ${printNode(node)}\n`;
202
204
  res += printSelectedCharsLine({
203
205
  indent,
204
206
  isSelected,
@@ -4,17 +4,17 @@
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
- var k=require("lexical"),q=require("react");const t=Object.freeze({"\t":"\\t","\n":"\\n"}),D=new RegExp(Object.keys(t).join("|"),"g"),E=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
8
- function F(a){let b="";const c=G(a),e=a.anchor;a=a.focus;const d=e.offset,f=a.offset;b=b+`: range ${""!==c?`{ ${c} }`:""}`+`\n \u251c anchor { key: ${e.key}, offset: ${null===d?"null":d}, type: ${e.type} }`;return b+=`\n \u2514 focus { key: ${a.key}, offset: ${null===f?"null":f}, type: ${a.type} }`}
9
- function H(a){let b=" root\n";a=a.read(()=>{const c=k.$getSelection();J(k.$getRoot(),(e,d)=>{const f=`(${e.getKey()})`,g=e.getType()||"",m=e.isSelected();var v=b,u=m?E.selectedLine:" ",r=d.join(" ");if(k.$isTextNode(e)){var l=e.getTextContent(!0);const n=0===l.length?"(empty)":`"${K(l)}"`;l=[G(e),L(e),M(e)].filter(Boolean).join(", ");l=[n,0!==l.length?`{ ${l} }`:null].filter(Boolean).join(" ").trim()}else l="";b=v+`${u} ${r} ${f} ${g} ${l}\n`;b+=N({indent:d,isSelected:m,node:e,nodeKeyDisplay:f,selection:c,
10
- typeDisplay:g})});return null===c?": null":k.$isRangeSelection(c)?F(c):k.$isGridSelection(c)?`: grid\n \u2514 { grid: ${c.gridKey}, anchorCell: ${c.anchor.key}, focusCell: ${c.focus.key} }`:`: node\n \u2514 [${Array.from(c._nodes).join(", ")}]`});return b+"\n selection"+a}function J(a,b,c=[]){a=a.getChildren();const e=a.length;a.forEach((d,f)=>{b(d,c.concat(f===e-1?E.isLastChild:E.hasNextSibling));k.$isElementNode(d)&&J(d,b,c.concat(f===e-1?E.ancestorIsLastChild:E.ancestorHasNextSibling))})}
11
- function K(a){return Object.entries(t).reduce((b,[c,e])=>b.replace(new RegExp(c,"g"),String(e)),a)}
12
- const O=[a=>a.hasFormat("bold")&&"Bold",a=>a.hasFormat("code")&&"Code",a=>a.hasFormat("italic")&&"Italic",a=>a.hasFormat("strikethrough")&&"Strikethrough",a=>a.hasFormat("subscript")&&"Subscript",a=>a.hasFormat("superscript")&&"Superscript",a=>a.hasFormat("underline")&&"Underline"],P=[a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"],Q=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented",a=>a.isInert()&&"Inert"];
13
- function L(a){let b=P.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="detail: "+b);return b}function M(a){let b=Q.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="mode: "+b);return b}function G(a){let b=O.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="format: "+b);return b}
14
- function N({indent:a,isSelected:b,node:c,nodeKeyDisplay:e,selection:d,typeDisplay:f}){if(!k.$isTextNode(c)||!k.$isRangeSelection(d)||!b||k.$isElementNode(c))return"";b=d.anchor;var g=d.focus;if(""===c.getTextContent()||b.getNode()===d.focus.getNode()&&b.offset===g.offset)return"";g=d.anchor;const m=d.focus,v=c.getTextContent(!0),u=v.length;b=d=-1;if("text"===g.type&&"text"===m.type){const n=g.getNode(),w=m.getNode();n===w&&c===n&&g.offset!==m.offset?[d,b]=g.offset<m.offset?[g.offset,m.offset]:[m.offset,
15
- g.offset]:c===n?[d,b]=n.isBefore(w)?[g.offset,u]:[0,g.offset]:c===w?[d,b]=w.isBefore(n)?[m.offset,u]:[0,m.offset]:[d,b]=[0,u]}c=(v.slice(0,d).match(D)||[]).length;g=(v.slice(d,b).match(D)||[]).length;const [r,l]=[d+c,b+c+g];if(r===l)return"";c=a[a.length-1]===E.hasNextSibling?E.ancestorHasNextSibling:E.ancestorIsLastChild;a=[...a.slice(0,a.length-1),c];c=Array(r).fill(" ");d=Array(l-r).fill(E.selectedChar);e=Array(e.length+(f.length+3)).fill(" ");return[E.selectedLine,a.join(" "),[...e,...c,...d].join("")].join(" ")+
7
+ var l=require("@lexical/mark"),p=require("lexical"),r=require("react");const D=Object.freeze({"\t":"\\t","\n":"\\n"}),E=new RegExp(Object.keys(D).join("|"),"g"),F=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
8
+ function G(a){let b="";const c=H(a),e=a.anchor;a=a.focus;const d=e.offset,f=a.offset;b=b+`: range ${""!==c?`{ ${c} }`:""}`+`\n \u251c anchor { key: ${e.key}, offset: ${null===d?"null":d}, type: ${e.type} }`;return b+=`\n \u2514 focus { key: ${a.key}, offset: ${null===f?"null":f}, type: ${a.type} }`}
9
+ function J(a){let b=" root\n";a=a.read(()=>{const c=p.$getSelection();K(p.$getRoot(),(e,d)=>{const f=`(${e.getKey()})`,g=e.getType()||"",m=e.isSelected(),v=l.$isMarkNode(e)?` id: [ ${e.getIDs().join(", ")} ] `:"";var u=b,q=m?F.selectedLine:" ",w=d.join(" ");if(p.$isTextNode(e)){var k=e.getTextContent(!0);const t=0===k.length?"(empty)":`"${L(k)}"`;k=[H(e),M(e),N(e)].filter(Boolean).join(", ");k=[t,0!==k.length?`{ ${k} }`:null].filter(Boolean).join(" ").trim()}else k="";b=u+`${q} ${w} ${f} ${g} ${v} ${k}\n`;
10
+ b+=O({indent:d,isSelected:m,node:e,nodeKeyDisplay:f,selection:c,typeDisplay:g})});return null===c?": null":p.$isRangeSelection(c)?G(c):p.$isGridSelection(c)?`: grid\n \u2514 { grid: ${c.gridKey}, anchorCell: ${c.anchor.key}, focusCell: ${c.focus.key} }`:`: node\n \u2514 [${Array.from(c._nodes).join(", ")}]`});return b+"\n selection"+a}
11
+ function K(a,b,c=[]){a=a.getChildren();const e=a.length;a.forEach((d,f)=>{b(d,c.concat(f===e-1?F.isLastChild:F.hasNextSibling));p.$isElementNode(d)&&K(d,b,c.concat(f===e-1?F.ancestorIsLastChild:F.ancestorHasNextSibling))})}function L(a){return Object.entries(D).reduce((b,[c,e])=>b.replace(new RegExp(c,"g"),String(e)),a)}
12
+ const P=[a=>a.hasFormat("bold")&&"Bold",a=>a.hasFormat("code")&&"Code",a=>a.hasFormat("italic")&&"Italic",a=>a.hasFormat("strikethrough")&&"Strikethrough",a=>a.hasFormat("subscript")&&"Subscript",a=>a.hasFormat("superscript")&&"Superscript",a=>a.hasFormat("underline")&&"Underline"],Q=[a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"],R=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented",a=>a.isInert()&&"Inert"];
13
+ function M(a){let b=Q.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="detail: "+b);return b}function N(a){let b=R.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="mode: "+b);return b}function H(a){let b=P.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="format: "+b);return b}
14
+ function O({indent:a,isSelected:b,node:c,nodeKeyDisplay:e,selection:d,typeDisplay:f}){if(!p.$isTextNode(c)||!p.$isRangeSelection(d)||!b||p.$isElementNode(c))return"";b=d.anchor;var g=d.focus;if(""===c.getTextContent()||b.getNode()===d.focus.getNode()&&b.offset===g.offset)return"";g=d.anchor;const m=d.focus,v=c.getTextContent(!0),u=v.length;b=d=-1;if("text"===g.type&&"text"===m.type){const k=g.getNode(),t=m.getNode();k===t&&c===k&&g.offset!==m.offset?[d,b]=g.offset<m.offset?[g.offset,m.offset]:[m.offset,
15
+ g.offset]:c===k?[d,b]=k.isBefore(t)?[g.offset,u]:[0,g.offset]:c===t?[d,b]=t.isBefore(k)?[m.offset,u]:[0,m.offset]:[d,b]=[0,u]}c=(v.slice(0,d).match(E)||[]).length;g=(v.slice(d,b).match(E)||[]).length;const [q,w]=[d+c,b+c+g];if(q===w)return"";c=a[a.length-1]===F.hasNextSibling?F.ancestorHasNextSibling:F.ancestorIsLastChild;a=[...a.slice(0,a.length-1),c];c=Array(q).fill(" ");d=Array(w-q).fill(F.selectedChar);e=Array(e.length+(f.length+3)).fill(" ");return[F.selectedLine,a.join(" "),[...e,...c,...d].join("")].join(" ")+
16
16
  "\n"}
17
- module.exports=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:e,timeTravelPanelClassName:d,editor:f}){const [g,m]=q.useState([]),[v,u]=q.useState(""),[r,l]=q.useState(!1),n=q.useRef(0),w=q.useRef(null),B=q.useRef(null),[z,C]=q.useState(!1);q.useEffect(()=>{u(H(f.getEditorState()));return f.registerUpdateListener(({editorState:h})=>{const p=f._compositionKey,x=H(f.getEditorState());u([x,null!==p&&`Composition key: ${p}`].filter(Boolean).join("\n\n"));r||
18
- m(A=>[...A,[Date.now(),h]])})},[r,f]);const y=g.length;q.useEffect(()=>{if(z){let h;const p=()=>{const x=n.current;x===y-1?C(!1):h=setTimeout(()=>{n.current++;const A=n.current,I=B.current;null!==I&&(I.value=String(A));f.setEditorState(g[A][1]);p()},g[x+1][0]-g[x][0])};p();return()=>{window.clearTimeout(h)}}},[g,z,f,y]);q.useEffect(()=>{const h=w.current;if(null!==h)return h.__lexicalEditor=f,()=>{h.__lexicalEditor=null}},[f]);return q.createElement("div",{className:e},!r&&2<y&&q.createElement("button",
19
- {onClick:()=>{const h=f.getRootElement();null!==h&&(h.contentEditable="false",n.current=y-1,l(!0))},className:a},"Time Travel"),q.createElement("pre",{ref:w},v),r&&q.createElement("div",{className:d},q.createElement("button",{className:c,onClick:()=>{C(!z)}},z?"Pause":"Play"),q.createElement("input",{className:b,ref:B,onChange:h=>{h=Number(h.target.value);const p=g[h];p&&(n.current=h,f.setEditorState(p[1]))},type:"range",min:"1",max:y-1}),q.createElement("button",{className:c,onClick:()=>{var h=f.getRootElement();
20
- if(null!==h){h.contentEditable="true";h=g.length-1;f.setEditorState(g[h][1]);const p=B.current;null!==p&&(p.value=String(h));l(!1);C(!1)}}},"Exit")))};
17
+ module.exports=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:e,timeTravelPanelClassName:d,editor:f}){const [g,m]=r.useState([]),[v,u]=r.useState(""),[q,w]=r.useState(!1),k=r.useRef(0),t=r.useRef(null),B=r.useRef(null),[z,C]=r.useState(!1);r.useEffect(()=>{u(J(f.getEditorState()));return f.registerUpdateListener(({editorState:h})=>{const n=f._compositionKey,x=J(f.getEditorState());u([x,null!==n&&`Composition key: ${n}`].filter(Boolean).join("\n\n"));q||
18
+ m(A=>[...A,[Date.now(),h]])})},[q,f]);const y=g.length;r.useEffect(()=>{if(z){let h;const n=()=>{const x=k.current;x===y-1?C(!1):h=setTimeout(()=>{k.current++;const A=k.current,I=B.current;null!==I&&(I.value=String(A));f.setEditorState(g[A][1]);n()},g[x+1][0]-g[x][0])};n();return()=>{window.clearTimeout(h)}}},[g,z,f,y]);r.useEffect(()=>{const h=t.current;if(null!==h)return h.__lexicalEditor=f,()=>{h.__lexicalEditor=null}},[f]);return r.createElement("div",{className:e},!q&&2<y&&r.createElement("button",
19
+ {onClick:()=>{const h=f.getRootElement();null!==h&&(h.contentEditable="false",k.current=y-1,w(!0))},className:a},"Time Travel"),r.createElement("pre",{ref:t},v),q&&r.createElement("div",{className:d},r.createElement("button",{className:c,onClick:()=>{C(!z)}},z?"Pause":"Play"),r.createElement("input",{className:b,ref:B,onChange:h=>{h=Number(h.target.value);const n=g[h];n&&(k.current=h,f.setEditorState(n[1]))},type:"range",min:"1",max:y-1}),r.createElement("button",{className:c,onClick:()=>{var h=f.getRootElement();
20
+ if(null!==h){h.contentEditable="true";h=g.length-1;f.setEditorState(g[h][1]);const n=B.current;null!==n&&(n.value=String(h));w(!1);C(!1)}}},"Exit")))};
package/package.json CHANGED
@@ -8,27 +8,28 @@
8
8
  "rich-text"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.2.5",
11
+ "version": "0.2.6",
12
12
  "dependencies": {
13
- "@lexical/clipboard": "0.2.5",
14
- "@lexical/list": "0.2.5",
15
- "@lexical/table": "0.2.5",
16
- "@lexical/yjs": "0.2.5",
17
- "@lexical/hashtag": "0.2.5",
18
- "@lexical/selection": "0.2.5",
19
- "@lexical/utils": "0.2.5",
20
- "@lexical/dragon": "0.2.5",
21
- "@lexical/plain-text": "0.2.5",
22
- "@lexical/rich-text": "0.2.5",
23
- "@lexical/code": "0.2.5",
24
- "@lexical/text": "0.2.5",
25
- "@lexical/link": "0.2.5",
26
- "@lexical/overflow": "0.2.5",
27
- "@lexical/history": "0.2.5",
28
- "@lexical/markdown": "0.2.5"
13
+ "@lexical/clipboard": "0.2.6",
14
+ "@lexical/list": "0.2.6",
15
+ "@lexical/table": "0.2.6",
16
+ "@lexical/yjs": "0.2.6",
17
+ "@lexical/hashtag": "0.2.6",
18
+ "@lexical/selection": "0.2.6",
19
+ "@lexical/utils": "0.2.6",
20
+ "@lexical/dragon": "0.2.6",
21
+ "@lexical/plain-text": "0.2.6",
22
+ "@lexical/rich-text": "0.2.6",
23
+ "@lexical/code": "0.2.6",
24
+ "@lexical/text": "0.2.6",
25
+ "@lexical/link": "0.2.6",
26
+ "@lexical/overflow": "0.2.6",
27
+ "@lexical/history": "0.2.6",
28
+ "@lexical/markdown": "0.2.6",
29
+ "@lexical/mark": "0.2.6"
29
30
  },
30
31
  "peerDependencies": {
31
- "lexical": "0.2.5",
32
+ "lexical": "0.2.6",
32
33
  "react": ">=17.x",
33
34
  "react-dom": ">=17.x"
34
35
  },