@lexical/react 0.7.8 → 0.8.0

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.
Files changed (49) hide show
  1. package/DEPRECATED_useLexical.dev.js +3 -4
  2. package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +1 -3
  3. package/DEPRECATED_useLexicalCharacterLimit.dev.js +7 -39
  4. package/DEPRECATED_useLexicalEditor.dev.js +1 -3
  5. package/DEPRECATED_useLexicalPlainText.dev.js +4 -1
  6. package/DEPRECATED_useLexicalRichText.dev.js +4 -1
  7. package/LexicalAutoEmbedPlugin.dev.js +0 -11
  8. package/LexicalAutoFocusPlugin.dev.js +0 -1
  9. package/LexicalAutoLinkPlugin.dev.js +7 -50
  10. package/LexicalBlockWithAlignableContents.d.ts +1 -1
  11. package/LexicalBlockWithAlignableContents.dev.js +0 -11
  12. package/LexicalCharacterLimitPlugin.dev.js +7 -46
  13. package/LexicalCheckListPlugin.dev.js +10 -48
  14. package/LexicalClearEditorPlugin.dev.js +1 -1
  15. package/LexicalCollaborationContext.dev.js +0 -3
  16. package/LexicalCollaborationPlugin.dev.js +11 -36
  17. package/LexicalCollaborationPlugin.prod.js +9 -9
  18. package/LexicalComposer.dev.js +6 -10
  19. package/LexicalComposerContext.dev.js +0 -6
  20. package/LexicalContentEditable.d.ts +16 -25
  21. package/LexicalContentEditable.dev.js +10 -14
  22. package/LexicalContentEditable.js.flow +15 -20
  23. package/LexicalContentEditable.prod.js +3 -3
  24. package/LexicalDecoratorBlockNode.dev.js +0 -5
  25. package/LexicalHashtagPlugin.dev.js +73 -43
  26. package/LexicalHorizontalRuleNode.dev.js +0 -22
  27. package/LexicalHorizontalRulePlugin.dev.js +0 -4
  28. package/LexicalLinkPlugin.dev.js +4 -10
  29. package/LexicalListPlugin.dev.js +1 -9
  30. package/LexicalListPlugin.prod.js +2 -2
  31. package/LexicalMarkdownShortcutPlugin.dev.js +2 -2
  32. package/LexicalNestedComposer.dev.js +8 -11
  33. package/LexicalNestedComposer.prod.js +3 -3
  34. package/LexicalNodeEventPlugin.dev.js +5 -3
  35. package/LexicalOnChangePlugin.dev.js +1 -1
  36. package/LexicalPlainTextPlugin.dev.js +8 -12
  37. package/LexicalRichTextPlugin.dev.js +8 -12
  38. package/LexicalTabIndentationPlugin.dev.js +1 -3
  39. package/LexicalTableOfContents__EXPERIMENTAL.dev.js +5 -33
  40. package/LexicalTablePlugin.dev.js +5 -19
  41. package/LexicalTreeView.dev.js +13 -62
  42. package/LexicalTreeView.prod.js +13 -13
  43. package/LexicalTypeaheadMenuPlugin.dev.js +7 -96
  44. package/package.json +19 -19
  45. package/shared/useYjsCollaboration.d.ts +1 -1
  46. package/useLexicalEditable.dev.js +1 -5
  47. package/useLexicalIsTextContentEmpty.dev.js +1 -0
  48. package/useLexicalNodeSelection.dev.js +0 -7
  49. package/useLexicalSubscription.dev.js +1 -3
@@ -13,6 +13,7 @@ var utils = require('@lexical/utils');
13
13
  var yjs = require('@lexical/yjs');
14
14
  var lexical = require('lexical');
15
15
  var reactDom = require('react-dom');
16
+ var yjs$1 = require('yjs');
16
17
 
17
18
  /**
18
19
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -31,7 +32,8 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
31
32
  const disconnect = React.useCallback(() => {
32
33
  try {
33
34
  provider.disconnect();
34
- } catch (e) {// Do nothing
35
+ } catch (e) {
36
+ // Do nothing
35
37
  }
36
38
  }, [provider]);
37
39
  React.useEffect(() => {
@@ -41,45 +43,39 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
41
43
  const {
42
44
  awareness
43
45
  } = provider;
44
-
45
46
  const onStatus = ({
46
47
  status
47
48
  }) => {
48
49
  editor.dispatchCommand(yjs.CONNECTED_COMMAND, status === 'connected');
49
50
  };
50
-
51
51
  const onSync = isSynced => {
52
52
  if (shouldBootstrap && isSynced && root.isEmpty() && root._xmlText._length === 0 && isReloadingDoc.current === false) {
53
53
  initializeEditor(editor, initialEditorState);
54
54
  }
55
-
56
55
  isReloadingDoc.current = false;
57
56
  };
58
-
59
57
  const onAwarenessUpdate = () => {
60
58
  yjs.syncCursorPositions(binding, provider);
61
59
  };
62
-
63
60
  const onYjsTreeChanges = (events, transaction) => {
64
- if (transaction.origin !== binding) {
65
- yjs.syncYjsChangesToLexical(binding, provider, events);
61
+ const origin = transaction.origin;
62
+ if (origin !== binding) {
63
+ const isFromUndoManger = origin instanceof yjs$1.UndoManager;
64
+ yjs.syncYjsChangesToLexical(binding, provider, events, isFromUndoManger);
66
65
  }
67
66
  };
68
-
69
67
  yjs.initLocalState(provider, name, color, document.activeElement === editor.getRootElement());
70
-
71
68
  const onProviderDocReload = ydoc => {
72
69
  clearEditorSkipCollab(editor, binding);
73
70
  setDoc(ydoc);
74
71
  docMap.set(id, ydoc);
75
72
  isReloadingDoc.current = true;
76
73
  };
77
-
78
74
  provider.on('reload', onProviderDocReload);
79
75
  provider.on('status', onStatus);
80
76
  provider.on('sync', onSync);
81
- awareness.on('update', onAwarenessUpdate); // This updates the local editor state when we recieve updates from other clients
82
-
77
+ awareness.on('update', onAwarenessUpdate);
78
+ // This updates the local editor state when we recieve updates from other clients
83
79
  root.getSharedType().observeDeep(onYjsTreeChanges);
84
80
  const removeListener = editor.registerUpdateListener(({
85
81
  prevEditorState,
@@ -98,7 +94,6 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
98
94
  if (isReloadingDoc.current === false) {
99
95
  disconnect();
100
96
  }
101
-
102
97
  provider.off('sync', onSync);
103
98
  provider.off('status', onStatus);
104
99
  provider.off('reload', onProviderDocReload);
@@ -112,7 +107,6 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
112
107
  const ref = element => {
113
108
  binding.cursorsContainer = element;
114
109
  };
115
-
116
110
  return /*#__PURE__*/reactDom.createPortal( /*#__PURE__*/React.createElement("div", {
117
111
  ref: ref
118
112
  }), cursorsContainerRef && cursorsContainerRef.current || document.body);
@@ -121,7 +115,6 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
121
115
  return editor.registerCommand(yjs.TOGGLE_CONNECT_COMMAND, payload => {
122
116
  if (connect !== undefined && disconnect !== undefined) {
123
117
  const shouldConnect = payload;
124
-
125
118
  if (shouldConnect) {
126
119
  // eslint-disable-next-line no-console
127
120
  console.log('Collaboration connected!');
@@ -132,7 +125,6 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
132
125
  disconnect();
133
126
  }
134
127
  }
135
-
136
128
  return true;
137
129
  }, lexical.COMMAND_PRIORITY_EDITOR);
138
130
  }, [connect, disconnect, editor]);
@@ -155,11 +147,9 @@ function useYjsHistory(editor, binding) {
155
147
  const undo = () => {
156
148
  undoManager.undo();
157
149
  };
158
-
159
150
  const redo = () => {
160
151
  undoManager.redo();
161
152
  };
162
-
163
153
  return utils.mergeRegister(editor.registerCommand(lexical.UNDO_COMMAND, () => {
164
154
  undo();
165
155
  return true;
@@ -173,11 +163,9 @@ function useYjsHistory(editor, binding) {
173
163
  }, [undoManager]);
174
164
  return clearHistory;
175
165
  }
176
-
177
166
  function initializeEditor(editor, initialEditorState) {
178
167
  editor.update(() => {
179
168
  const root = lexical.$getRoot();
180
-
181
169
  if (root.isEmpty()) {
182
170
  if (initialEditorState) {
183
171
  switch (typeof initialEditorState) {
@@ -189,7 +177,6 @@ function initializeEditor(editor, initialEditorState) {
189
177
  });
190
178
  break;
191
179
  }
192
-
193
180
  case 'object':
194
181
  {
195
182
  editor.setEditorState(initialEditorState, {
@@ -197,12 +184,10 @@ function initializeEditor(editor, initialEditorState) {
197
184
  });
198
185
  break;
199
186
  }
200
-
201
187
  case 'function':
202
188
  {
203
189
  editor.update(() => {
204
190
  const root1 = lexical.$getRoot();
205
-
206
191
  if (root1.isEmpty()) {
207
192
  initialEditorState(editor);
208
193
  }
@@ -218,7 +203,6 @@ function initializeEditor(editor, initialEditorState) {
218
203
  const {
219
204
  activeElement
220
205
  } = document;
221
-
222
206
  if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
223
207
  paragraph.select();
224
208
  }
@@ -228,7 +212,6 @@ function initializeEditor(editor, initialEditorState) {
228
212
  tag: 'history-merge'
229
213
  });
230
214
  }
231
-
232
215
  function clearEditorSkipCollab(editor, binding) {
233
216
  // reset editor state
234
217
  editor.update(() => {
@@ -238,33 +221,25 @@ function clearEditorSkipCollab(editor, binding) {
238
221
  }, {
239
222
  tag: 'skip-collab'
240
223
  });
241
-
242
224
  if (binding.cursors == null) {
243
225
  return;
244
226
  }
245
-
246
227
  const cursors = binding.cursors;
247
-
248
228
  if (cursors == null) {
249
229
  return;
250
230
  }
251
-
252
231
  const cursorsContainer = binding.cursorsContainer;
253
-
254
232
  if (cursorsContainer == null) {
255
233
  return;
256
- } // reset cursors in dom
257
-
234
+ }
258
235
 
236
+ // reset cursors in dom
259
237
  const cursorsArr = Array.from(cursors.values());
260
-
261
238
  for (let i = 0; i < cursorsArr.length; i++) {
262
239
  const cursor = cursorsArr[i];
263
240
  const selection = cursor.selection;
264
-
265
241
  if (selection && selection.selections != null) {
266
242
  const selections = selection.selections;
267
-
268
243
  for (let j = 0; j < selections.length; j++) {
269
244
  cursorsContainer.removeChild(selections[i]);
270
245
  }
@@ -4,12 +4,12 @@
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
- 'use strict';var e=require("@lexical/react/LexicalCollaborationContext"),f=require("@lexical/react/LexicalComposerContext"),h=require("react"),z=require("@lexical/utils"),H=require("@lexical/yjs"),I=require("lexical"),J=require("react-dom");
8
- function K(b,c,a,d,p,w,x,l,t){let q=h.useRef(!1),[u,r]=h.useState(d.get(c)),g=h.useMemo(()=>H.createBinding(b,a,c,u,d),[b,a,c,d,u]),n=h.useCallback(()=>{a.connect()},[a]),v=h.useCallback(()=>{try{a.disconnect()}catch(m){}},[a]);h.useEffect(()=>{let {root:m}=g,{awareness:A}=a,B=({status:k})=>{b.dispatchCommand(H.CONNECTED_COMMAND,"connected"===k)},C=k=>{x&&k&&m.isEmpty()&&0===m._xmlText._length&&!1===q.current&&L(b,t);q.current=!1},D=()=>{H.syncCursorPositions(g,a)},E=(k,y)=>{y.origin!==g&&H.syncYjsChangesToLexical(g,
9
- a,k)};H.initLocalState(a,p,w,document.activeElement===b.getRootElement());let F=k=>{M(b,g);r(k);d.set(c,k);q.current=!0};a.on("reload",F);a.on("status",B);a.on("sync",C);A.on("update",D);m.getSharedType().observeDeep(E);let Q=b.registerUpdateListener(({prevEditorState:k,editorState:y,dirtyLeaves:N,dirtyElements:O,normalizedNodes:P,tags:G})=>{!1===G.has("skip-collab")&&H.syncLexicalUpdateToYjs(g,a,k,y,O,N,P,G)});n();return()=>{!1===q.current&&v();a.off("sync",C);a.off("status",B);a.off("reload",F);
10
- A.off("update",D);m.getSharedType().unobserveDeep(E);d.delete(c);Q()}},[g,w,n,v,d,b,c,t,p,a,x]);let R=h.useMemo(()=>J.createPortal(h.createElement("div",{ref:m=>{g.cursorsContainer=m}}),l&&l.current||document.body),[g,l]);h.useEffect(()=>b.registerCommand(H.TOGGLE_CONNECT_COMMAND,m=>{void 0!==n&&void 0!==v&&(m?(console.log("Collaboration connected!"),n()):(console.log("Collaboration disconnected!"),v()));return!0},I.COMMAND_PRIORITY_EDITOR),[n,v,b]);return[R,g]}
11
- function S(b,c,a,d){h.useEffect(()=>z.mergeRegister(b.registerCommand(I.FOCUS_COMMAND,()=>{H.setLocalStateFocus(c,a,d,!0);return!1},I.COMMAND_PRIORITY_EDITOR),b.registerCommand(I.BLUR_COMMAND,()=>{H.setLocalStateFocus(c,a,d,!1);return!1},I.COMMAND_PRIORITY_EDITOR)),[d,b,a,c])}
12
- function T(b,c){let a=h.useMemo(()=>H.createUndoManager(c,c.root.getSharedType()),[c]);h.useEffect(()=>z.mergeRegister(b.registerCommand(I.UNDO_COMMAND,()=>{a.undo();return!0},I.COMMAND_PRIORITY_EDITOR),b.registerCommand(I.REDO_COMMAND,()=>{a.redo();return!0},I.COMMAND_PRIORITY_EDITOR)));return h.useCallback(()=>{a.clear()},[a])}
13
- function L(b,c){b.update(()=>{var a=I.$getRoot();if(a.isEmpty())if(c)switch(typeof c){case "string":var d=b.parseEditorState(c);b.setEditorState(d,{tag:"history-merge"});break;case "object":b.setEditorState(c,{tag:"history-merge"});break;case "function":b.update(()=>{I.$getRoot().isEmpty()&&c(b)},{tag:"history-merge"})}else d=I.$createParagraphNode(),a.append(d),{activeElement:a}=document,(null!==I.$getSelection()||null!==a&&a===b.getRootElement())&&d.select()},{tag:"history-merge"})}
14
- function M(b,c){b.update(()=>{let d=I.$getRoot();d.clear();d.select()},{tag:"skip-collab"});if(null!=c.cursors&&(b=c.cursors,null!=b&&(c=c.cursorsContainer,null!=c))){b=Array.from(b.values());for(let d=0;d<b.length;d++){var a=b[d].selection;if(a&&null!=a.selections){a=a.selections;for(let p=0;p<a.length;p++)c.removeChild(a[d])}}}}
15
- exports.CollaborationPlugin=function({id:b,providerFactory:c,shouldBootstrap:a,username:d,cursorColor:p,cursorsContainerRef:w,initialEditorState:x}){let l=e.useCollaborationContext(d,p),{yjsDocMap:t,name:q,color:u}=l,[r]=f.useLexicalComposerContext();h.useEffect(()=>{l.isCollabActive=!0;return()=>{null==r._parentEditor&&(l.isCollabActive=!1)}},[l,r]);d=h.useMemo(()=>c(b,t),[b,c,t]);let [g,n]=K(r,b,d,t,q,u,a,w,x);l.clientID=n.clientID;T(r,n);S(r,d,q,u);return g}
7
+ 'use strict';var e=require("@lexical/react/LexicalCollaborationContext"),f=require("@lexical/react/LexicalComposerContext"),h=require("react"),z=require("@lexical/utils"),H=require("@lexical/yjs"),I=require("lexical"),J=require("react-dom"),K=require("yjs");
8
+ function L(b,c,a,d,p,x,y,l,t){let q=h.useRef(!1),[v,r]=h.useState(d.get(c)),g=h.useMemo(()=>H.createBinding(b,a,c,v,d),[b,a,c,d,v]),n=h.useCallback(()=>{a.connect()},[a]),w=h.useCallback(()=>{try{a.disconnect()}catch(m){}},[a]);h.useEffect(()=>{let {root:m}=g,{awareness:A}=a,B=({status:k})=>{b.dispatchCommand(H.CONNECTED_COMMAND,"connected"===k)},C=k=>{y&&k&&m.isEmpty()&&0===m._xmlText._length&&!1===q.current&&M(b,t);q.current=!1},D=()=>{H.syncCursorPositions(g,a)},E=(k,u)=>{u=u.origin;u!==g&&H.syncYjsChangesToLexical(g,
9
+ a,k,u instanceof K.UndoManager)};H.initLocalState(a,p,x,document.activeElement===b.getRootElement());let F=k=>{N(b,g);r(k);d.set(c,k);q.current=!0};a.on("reload",F);a.on("status",B);a.on("sync",C);A.on("update",D);m.getSharedType().observeDeep(E);let R=b.registerUpdateListener(({prevEditorState:k,editorState:u,dirtyLeaves:O,dirtyElements:P,normalizedNodes:Q,tags:G})=>{!1===G.has("skip-collab")&&H.syncLexicalUpdateToYjs(g,a,k,u,P,O,Q,G)});n();return()=>{!1===q.current&&w();a.off("sync",C);a.off("status",
10
+ B);a.off("reload",F);A.off("update",D);m.getSharedType().unobserveDeep(E);d.delete(c);R()}},[g,x,n,w,d,b,c,t,p,a,y]);let S=h.useMemo(()=>J.createPortal(h.createElement("div",{ref:m=>{g.cursorsContainer=m}}),l&&l.current||document.body),[g,l]);h.useEffect(()=>b.registerCommand(H.TOGGLE_CONNECT_COMMAND,m=>{void 0!==n&&void 0!==w&&(m?(console.log("Collaboration connected!"),n()):(console.log("Collaboration disconnected!"),w()));return!0},I.COMMAND_PRIORITY_EDITOR),[n,w,b]);return[S,g]}
11
+ function T(b,c,a,d){h.useEffect(()=>z.mergeRegister(b.registerCommand(I.FOCUS_COMMAND,()=>{H.setLocalStateFocus(c,a,d,!0);return!1},I.COMMAND_PRIORITY_EDITOR),b.registerCommand(I.BLUR_COMMAND,()=>{H.setLocalStateFocus(c,a,d,!1);return!1},I.COMMAND_PRIORITY_EDITOR)),[d,b,a,c])}
12
+ function U(b,c){let a=h.useMemo(()=>H.createUndoManager(c,c.root.getSharedType()),[c]);h.useEffect(()=>z.mergeRegister(b.registerCommand(I.UNDO_COMMAND,()=>{a.undo();return!0},I.COMMAND_PRIORITY_EDITOR),b.registerCommand(I.REDO_COMMAND,()=>{a.redo();return!0},I.COMMAND_PRIORITY_EDITOR)));return h.useCallback(()=>{a.clear()},[a])}
13
+ function M(b,c){b.update(()=>{var a=I.$getRoot();if(a.isEmpty())if(c)switch(typeof c){case "string":var d=b.parseEditorState(c);b.setEditorState(d,{tag:"history-merge"});break;case "object":b.setEditorState(c,{tag:"history-merge"});break;case "function":b.update(()=>{I.$getRoot().isEmpty()&&c(b)},{tag:"history-merge"})}else d=I.$createParagraphNode(),a.append(d),{activeElement:a}=document,(null!==I.$getSelection()||null!==a&&a===b.getRootElement())&&d.select()},{tag:"history-merge"})}
14
+ function N(b,c){b.update(()=>{let d=I.$getRoot();d.clear();d.select()},{tag:"skip-collab"});if(null!=c.cursors&&(b=c.cursors,null!=b&&(c=c.cursorsContainer,null!=c))){b=Array.from(b.values());for(let d=0;d<b.length;d++){var a=b[d].selection;if(a&&null!=a.selections){a=a.selections;for(let p=0;p<a.length;p++)c.removeChild(a[d])}}}}
15
+ exports.CollaborationPlugin=function({id:b,providerFactory:c,shouldBootstrap:a,username:d,cursorColor:p,cursorsContainerRef:x,initialEditorState:y}){let l=e.useCollaborationContext(d,p),{yjsDocMap:t,name:q,color:v}=l,[r]=f.useLexicalComposerContext();h.useEffect(()=>{l.isCollabActive=!0;return()=>{null==r._parentEditor&&(l.isCollabActive=!1)}},[l,r]);d=h.useMemo(()=>c(b,t),[b,c,t]);let [g,n]=L(r,b,d,t,q,v,a,x,y);l.clientID=n.clientID;U(r,n);T(r,d,q,v);return g}
@@ -17,6 +17,7 @@ var React = require('react');
17
17
  * LICENSE file in the root directory of this source tree.
18
18
  *
19
19
  */
20
+
20
21
  const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
21
22
 
22
23
  /**
@@ -54,7 +55,6 @@ function LexicalComposer({
54
55
  } = initialConfig;
55
56
  const context = LexicalComposerContext.createLexicalComposerContext(null, theme);
56
57
  let editor = initialEditor || null;
57
-
58
58
  if (editor === null) {
59
59
  const newEditor = lexical.createEditor({
60
60
  editable: false,
@@ -66,34 +66,33 @@ function LexicalComposer({
66
66
  initializeEditor(newEditor, initialEditorState);
67
67
  editor = newEditor;
68
68
  }
69
-
70
69
  return [editor, context];
71
- }, // We only do this for init
70
+ },
71
+ // We only do this for init
72
72
  // eslint-disable-next-line react-hooks/exhaustive-deps
73
73
  []);
74
74
  useLayoutEffect(() => {
75
75
  const isEditable = initialConfig.editable;
76
76
  const [editor] = composerContext;
77
- editor.setEditable(isEditable !== undefined ? isEditable : true); // We only do this for init
77
+ editor.setEditable(isEditable !== undefined ? isEditable : true);
78
+
79
+ // We only do this for init
78
80
  // eslint-disable-next-line react-hooks/exhaustive-deps
79
81
  }, []);
80
82
  return /*#__PURE__*/React.createElement(LexicalComposerContext.LexicalComposerContext.Provider, {
81
83
  value: composerContext
82
84
  }, children);
83
85
  }
84
-
85
86
  function initializeEditor(editor, initialEditorState) {
86
87
  if (initialEditorState === null) {
87
88
  return;
88
89
  } else if (initialEditorState === undefined) {
89
90
  editor.update(() => {
90
91
  const root = lexical.$getRoot();
91
-
92
92
  if (root.isEmpty()) {
93
93
  const paragraph = lexical.$createParagraphNode();
94
94
  root.append(paragraph);
95
95
  const activeElement = CAN_USE_DOM ? document.activeElement : null;
96
-
97
96
  if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
98
97
  paragraph.select();
99
98
  }
@@ -107,18 +106,15 @@ function initializeEditor(editor, initialEditorState) {
107
106
  editor.setEditorState(parsedEditorState, HISTORY_MERGE_OPTIONS);
108
107
  break;
109
108
  }
110
-
111
109
  case 'object':
112
110
  {
113
111
  editor.setEditorState(initialEditorState, HISTORY_MERGE_OPTIONS);
114
112
  break;
115
113
  }
116
-
117
114
  case 'function':
118
115
  {
119
116
  editor.update(() => {
120
117
  const root = lexical.$getRoot();
121
-
122
118
  if (root.isEmpty()) {
123
119
  initialEditorState(editor);
124
120
  }
@@ -18,32 +18,26 @@ var react = require('react');
18
18
  const LexicalComposerContext = /*#__PURE__*/react.createContext(null);
19
19
  function createLexicalComposerContext(parent, theme) {
20
20
  let parentContext = null;
21
-
22
21
  if (parent != null) {
23
22
  parentContext = parent[1];
24
23
  }
25
-
26
24
  function getTheme() {
27
25
  if (theme != null) {
28
26
  return theme;
29
27
  }
30
-
31
28
  return parentContext != null ? parentContext.getTheme() : null;
32
29
  }
33
-
34
30
  return {
35
31
  getTheme
36
32
  };
37
33
  }
38
34
  function useLexicalComposerContext() {
39
35
  const composerContext = react.useContext(LexicalComposerContext);
40
-
41
36
  if (composerContext == null) {
42
37
  {
43
38
  throw Error(`LexicalComposerContext.useLexicalComposerContext: cannot find a LexicalComposerContext`);
44
39
  }
45
40
  }
46
-
47
41
  return composerContext;
48
42
  }
49
43
 
@@ -5,28 +5,19 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import { CSSProperties } from 'react';
9
- export declare type Props = Readonly<{
10
- ariaActiveDescendantID?: string;
11
- ariaAutoComplete?: string;
12
- ariaControls?: string;
13
- ariaDescribedBy?: string;
14
- ariaExpanded?: boolean;
15
- ariaLabel?: string;
16
- ariaLabelledBy?: string;
17
- ariaMultiline?: boolean;
18
- ariaOwneeID?: string;
19
- ariaRequired?: string;
20
- autoCapitalize?: boolean;
21
- autoComplete?: boolean;
22
- autoCorrect?: boolean;
23
- className?: string;
24
- id?: string;
25
- readOnly?: boolean;
26
- role?: string;
27
- spellCheck?: boolean;
28
- style?: CSSProperties;
29
- tabIndex?: number;
30
- testid?: string;
31
- }>;
32
- export declare function ContentEditable({ ariaActiveDescendantID, ariaAutoComplete, ariaControls, ariaDescribedBy, ariaExpanded, ariaLabel, ariaLabelledBy, ariaMultiline, ariaOwneeID, ariaRequired, autoCapitalize, autoComplete, autoCorrect, className, id, role, spellCheck, style, tabIndex, testid, }: Props): JSX.Element;
8
+ import * as React from 'react';
9
+ export declare type Props = {
10
+ ariaActiveDescendant?: React.AriaAttributes['aria-activedescendant'];
11
+ ariaAutoComplete?: React.AriaAttributes['aria-autocomplete'];
12
+ ariaControls?: React.AriaAttributes['aria-controls'];
13
+ ariaDescribedBy?: React.AriaAttributes['aria-describedby'];
14
+ ariaExpanded?: React.AriaAttributes['aria-expanded'];
15
+ ariaLabel?: React.AriaAttributes['aria-label'];
16
+ ariaLabelledBy?: React.AriaAttributes['aria-labelledby'];
17
+ ariaMultiline?: React.AriaAttributes['aria-multiline'];
18
+ ariaOwns?: React.AriaAttributes['aria-owns'];
19
+ ariaRequired?: React.AriaAttributes['aria-required'];
20
+ autoCapitalize?: HTMLDivElement['autocapitalize'];
21
+ 'data-testid'?: string | null | undefined;
22
+ } & React.AllHTMLAttributes<HTMLDivElement>;
23
+ export declare function ContentEditable({ ariaActiveDescendant, ariaAutoComplete, ariaControls, ariaDescribedBy, ariaExpanded, ariaLabel, ariaLabelledBy, ariaMultiline, ariaOwns, ariaRequired, autoCapitalize, className, id, role, spellCheck, style, tabIndex, 'data-testid': testid, }: Props): JSX.Element;
@@ -16,6 +16,7 @@ var React = require('react');
16
16
  * LICENSE file in the root directory of this source tree.
17
17
  *
18
18
  */
19
+
19
20
  const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
20
21
 
21
22
  /**
@@ -36,7 +37,7 @@ var useLayoutEffect = useLayoutEffectImpl;
36
37
  *
37
38
  */
38
39
  function ContentEditable({
39
- ariaActiveDescendantID,
40
+ ariaActiveDescendant,
40
41
  ariaAutoComplete,
41
42
  ariaControls,
42
43
  ariaDescribedBy,
@@ -44,18 +45,16 @@ function ContentEditable({
44
45
  ariaLabel,
45
46
  ariaLabelledBy,
46
47
  ariaMultiline,
47
- ariaOwneeID,
48
+ ariaOwns,
48
49
  ariaRequired,
49
50
  autoCapitalize,
50
- autoComplete,
51
- autoCorrect,
52
51
  className,
53
52
  id,
54
53
  role = 'textbox',
55
54
  spellCheck = true,
56
55
  style,
57
56
  tabIndex,
58
- testid
57
+ 'data-testid': testid
59
58
  }) {
60
59
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
61
60
  const [isEditable, setEditable] = React.useState(false);
@@ -69,20 +68,17 @@ function ContentEditable({
69
68
  });
70
69
  }, [editor]);
71
70
  return /*#__PURE__*/React.createElement("div", {
72
- "aria-activedescendant": !isEditable ? null : ariaActiveDescendantID,
73
- "aria-autocomplete": !isEditable ? null : ariaAutoComplete,
74
- "aria-controls": !isEditable ? null : ariaControls,
71
+ "aria-activedescendant": !isEditable ? undefined : ariaActiveDescendant,
72
+ "aria-autocomplete": !isEditable ? 'none' : ariaAutoComplete,
73
+ "aria-controls": !isEditable ? undefined : ariaControls,
75
74
  "aria-describedby": ariaDescribedBy,
76
- "aria-expanded": !isEditable ? null : role === 'combobox' ? !!ariaExpanded : null,
75
+ "aria-expanded": !isEditable ? undefined : role === 'combobox' ? !!ariaExpanded : undefined,
77
76
  "aria-label": ariaLabel,
78
77
  "aria-labelledby": ariaLabelledBy,
79
78
  "aria-multiline": ariaMultiline,
80
- "aria-owns": !isEditable ? null : ariaOwneeID,
79
+ "aria-owns": !isEditable ? undefined : ariaOwns,
81
80
  "aria-required": ariaRequired,
82
- autoCapitalize: autoCapitalize !== undefined ? String(autoCapitalize) : undefined // @ts-ignore This is a valid attribute
83
- ,
84
- autoComplete: autoComplete,
85
- autoCorrect: autoCorrect !== undefined ? String(autoCorrect) : undefined,
81
+ autoCapitalize: autoCapitalize,
86
82
  className: className,
87
83
  contentEditable: isEditable,
88
84
  "data-testid": testid,
@@ -7,27 +7,22 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
+ import * as React from 'react';
11
+
10
12
  export type Props = $ReadOnly<{
11
- ariaActiveDescendantID?: string,
12
- ariaAutoComplete?: string,
13
- ariaControls?: string,
14
- ariaDescribedBy?: string,
15
- ariaExpanded?: boolean,
16
- ariaLabel?: string,
17
- ariaLabelledBy?: string,
18
- ariaMultiline?: boolean,
19
- ariaOwneeID?: string,
20
- ariaRequired?: string,
21
- autoCapitalize?: boolean,
22
- autoComplete?: boolean,
23
- autoCorrect?: boolean,
24
- className?: string,
25
- readOnly?: boolean,
26
- role?: string,
27
- style?: $Shape<{[string]: string | number}>,
28
- spellCheck?: boolean,
29
- tabIndex?: number,
30
- testid?: string,
13
+ ...$Partial<HTMLDivElement>,
14
+ ariaActiveDescendant?: HTMLDivElement['aria-activedescendant'],
15
+ ariaAutoComplete?: HTMLDivElement['aria-autocomplete'],
16
+ ariaControls?: HTMLDivElement['aria-controls'],
17
+ ariaDescribedBy?: HTMLDivElement['aria-describedby'],
18
+ ariaExpanded?: HTMLDivElement['aria-expanded'],
19
+ ariaLabel?: HTMLDivElement['aria-label'],
20
+ ariaLabelledBy?: HTMLDivElement['aria-labelledby'],
21
+ ariaMultiline?: HTMLDivElement['aria-multiline'],
22
+ ariaOwns?: HTMLDivElement['aria-owns'],
23
+ ariaRequired?: HTMLDivElement['aria-required'],
24
+ autoCapitalize?: HTMLDivElement['autocapitalize'],
25
+ 'data-testid'?: string | null,
31
26
  }>;
32
27
 
33
28
  declare export function ContentEditable(props: Props): React$Node;
@@ -4,6 +4,6 @@
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
- 'use strict';var b=require("@lexical/react/LexicalComposerContext"),k=require("react"),l="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?k.useLayoutEffect:k.useEffect;
8
- exports.ContentEditable=function({ariaActiveDescendantID:m,ariaAutoComplete:n,ariaControls:p,ariaDescribedBy:q,ariaExpanded:r,ariaLabel:t,ariaLabelledBy:u,ariaMultiline:v,ariaOwneeID:w,ariaRequired:x,autoCapitalize:e,autoComplete:y,autoCorrect:f,className:z,id:A,role:g="textbox",spellCheck:B=!0,style:C,tabIndex:D,testid:E}){let [c]=b.useLexicalComposerContext(),[a,h]=k.useState(!1),F=k.useCallback(d=>{c.setRootElement(d)},[c]);l(()=>{h(c.isEditable());return c.registerEditableListener(d=>{h(d)})},
9
- [c]);return k.createElement("div",{"aria-activedescendant":a?m:null,"aria-autocomplete":a?n:null,"aria-controls":a?p:null,"aria-describedby":q,"aria-expanded":a?"combobox"===g?!!r:null:null,"aria-label":t,"aria-labelledby":u,"aria-multiline":v,"aria-owns":a?w:null,"aria-required":x,autoCapitalize:void 0!==e?String(e):void 0,autoComplete:y,autoCorrect:void 0!==f?String(f):void 0,className:z,contentEditable:a,"data-testid":E,id:A,ref:F,role:a?g:void 0,spellCheck:B,style:C,tabIndex:D})}
7
+ 'use strict';var b=require("@lexical/react/LexicalComposerContext"),g=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;
8
+ exports.ContentEditable=function({ariaActiveDescendant:k,ariaAutoComplete:l,ariaControls:m,ariaDescribedBy:n,ariaExpanded:p,ariaLabel:q,ariaLabelledBy:r,ariaMultiline:t,ariaOwns:u,ariaRequired:v,autoCapitalize:w,className:x,id:y,role:e="textbox",spellCheck:z=!0,style:A,tabIndex:B,"data-testid":C}){let [c]=b.useLexicalComposerContext(),[a,f]=g.useState(!1),D=g.useCallback(d=>{c.setRootElement(d)},[c]);h(()=>{f(c.isEditable());return c.registerEditableListener(d=>{f(d)})},[c]);return g.createElement("div",
9
+ {"aria-activedescendant":a?k:void 0,"aria-autocomplete":a?l:"none","aria-controls":a?m:void 0,"aria-describedby":n,"aria-expanded":a?"combobox"===e?!!p:void 0:void 0,"aria-label":q,"aria-labelledby":r,"aria-multiline":t,"aria-owns":a?u:void 0,"aria-required":v,autoCapitalize:w,className:x,contentEditable:a,"data-testid":C,id:y,ref:D,role:a?e:void 0,spellCheck:z,style:A,tabIndex:B})}
@@ -20,7 +20,6 @@ class DecoratorBlockNode extends lexical.DecoratorNode {
20
20
  super(key);
21
21
  this.__format = format || '';
22
22
  }
23
-
24
23
  exportJSON() {
25
24
  return {
26
25
  format: this.__format || '',
@@ -28,20 +27,16 @@ class DecoratorBlockNode extends lexical.DecoratorNode {
28
27
  version: 1
29
28
  };
30
29
  }
31
-
32
30
  createDOM() {
33
31
  return document.createElement('div');
34
32
  }
35
-
36
33
  updateDOM() {
37
34
  return false;
38
35
  }
39
-
40
36
  setFormat(format) {
41
37
  const self = this.getWritable();
42
38
  self.__format = format;
43
39
  }
44
-
45
40
  }
46
41
  function $isDecoratorBlockNode(node) {
47
42
  return node instanceof DecoratorBlockNode;