@lexical/react 0.12.1 → 0.12.3

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 (54) hide show
  1. package/LexicalAutoEmbedPlugin.d.ts +3 -2
  2. package/LexicalAutoEmbedPlugin.dev.js +4 -14
  3. package/LexicalAutoEmbedPlugin.prod.js +4 -3
  4. package/LexicalAutoFocusPlugin.dev.js +0 -1
  5. package/LexicalAutoLinkPlugin.dev.js +126 -73
  6. package/LexicalAutoLinkPlugin.prod.js +11 -7
  7. package/LexicalBlockWithAlignableContents.dev.js +0 -10
  8. package/LexicalCharacterLimitPlugin.dev.js +7 -46
  9. package/LexicalCheckListPlugin.dev.js +10 -48
  10. package/LexicalClearEditorPlugin.dev.js +1 -1
  11. package/LexicalClickableLinkPlugin.dev.js +2 -20
  12. package/LexicalCollaborationContext.dev.js +0 -3
  13. package/LexicalCollaborationPlugin.dev.js +8 -37
  14. package/LexicalComposer.d.ts +3 -7
  15. package/LexicalComposer.dev.js +9 -11
  16. package/LexicalComposer.js.flow +4 -4
  17. package/LexicalComposer.prod.js +2 -1
  18. package/LexicalComposerContext.dev.js +0 -6
  19. package/LexicalContentEditable.dev.js +1 -2
  20. package/LexicalContextMenuPlugin.d.ts +3 -2
  21. package/LexicalContextMenuPlugin.dev.js +28 -82
  22. package/LexicalContextMenuPlugin.prod.js +16 -15
  23. package/LexicalDecoratorBlockNode.dev.js +0 -6
  24. package/LexicalEditorRefPlugin.dev.js +0 -3
  25. package/LexicalHashtagPlugin.dev.js +73 -43
  26. package/LexicalHorizontalRuleNode.dev.js +0 -21
  27. package/LexicalHorizontalRulePlugin.dev.js +0 -4
  28. package/LexicalLinkPlugin.dev.js +4 -10
  29. package/LexicalListPlugin.dev.js +0 -2
  30. package/LexicalMarkdownShortcutPlugin.dev.js +2 -2
  31. package/LexicalNestedComposer.d.ts +2 -2
  32. package/LexicalNestedComposer.dev.js +18 -16
  33. package/LexicalNestedComposer.js.flow +7 -2
  34. package/LexicalNestedComposer.prod.js +4 -3
  35. package/LexicalNodeEventPlugin.dev.js +2 -6
  36. package/LexicalNodeMenuPlugin.d.ts +3 -2
  37. package/LexicalNodeMenuPlugin.dev.js +27 -83
  38. package/LexicalNodeMenuPlugin.prod.js +15 -15
  39. package/LexicalOnChangePlugin.dev.js +1 -1
  40. package/LexicalPlainTextPlugin.dev.js +8 -12
  41. package/LexicalRichTextPlugin.dev.js +8 -12
  42. package/LexicalTabIndentationPlugin.dev.js +7 -16
  43. package/LexicalTableOfContents.dev.js +5 -33
  44. package/LexicalTablePlugin.dev.js +11 -28
  45. package/LexicalTreeView.dev.js +14 -79
  46. package/LexicalTypeaheadMenuPlugin.d.ts +4 -3
  47. package/LexicalTypeaheadMenuPlugin.dev.js +39 -176
  48. package/LexicalTypeaheadMenuPlugin.prod.js +19 -20
  49. package/package.json +19 -19
  50. package/shared/LexicalMenu.d.ts +3 -2
  51. package/useLexicalEditable.dev.js +1 -5
  52. package/useLexicalIsTextContentEmpty.dev.js +1 -0
  53. package/useLexicalNodeSelection.dev.js +0 -7
  54. package/useLexicalSubscription.dev.js +1 -3
@@ -32,7 +32,8 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
32
32
  const disconnect = React.useCallback(() => {
33
33
  try {
34
34
  provider.disconnect();
35
- } catch (e) {// Do nothing
35
+ } catch (e) {
36
+ // Do nothing
36
37
  }
37
38
  }, [provider]);
38
39
  React.useEffect(() => {
@@ -42,48 +43,39 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
42
43
  const {
43
44
  awareness
44
45
  } = provider;
45
-
46
46
  const onStatus = ({
47
47
  status
48
48
  }) => {
49
49
  editor.dispatchCommand(yjs.CONNECTED_COMMAND, status === 'connected');
50
50
  };
51
-
52
51
  const onSync = isSynced => {
53
52
  if (shouldBootstrap && isSynced && root.isEmpty() && root._xmlText._length === 0 && isReloadingDoc.current === false) {
54
53
  initializeEditor(editor, initialEditorState);
55
54
  }
56
-
57
55
  isReloadingDoc.current = false;
58
56
  };
59
-
60
57
  const onAwarenessUpdate = () => {
61
58
  yjs.syncCursorPositions(binding, provider);
62
59
  };
63
-
64
60
  const onYjsTreeChanges = (events, transaction) => {
65
61
  const origin = transaction.origin;
66
-
67
62
  if (origin !== binding) {
68
63
  const isFromUndoManger = origin instanceof yjs$1.UndoManager;
69
64
  yjs.syncYjsChangesToLexical(binding, provider, events, isFromUndoManger);
70
65
  }
71
66
  };
72
-
73
67
  yjs.initLocalState(provider, name, color, document.activeElement === editor.getRootElement(), awarenessData || {});
74
-
75
68
  const onProviderDocReload = ydoc => {
76
69
  clearEditorSkipCollab(editor, binding);
77
70
  setDoc(ydoc);
78
71
  docMap.set(id, ydoc);
79
72
  isReloadingDoc.current = true;
80
73
  };
81
-
82
74
  provider.on('reload', onProviderDocReload);
83
75
  provider.on('status', onStatus);
84
76
  provider.on('sync', onSync);
85
- awareness.on('update', onAwarenessUpdate); // This updates the local editor state when we recieve updates from other clients
86
-
77
+ awareness.on('update', onAwarenessUpdate);
78
+ // This updates the local editor state when we recieve updates from other clients
87
79
  root.getSharedType().observeDeep(onYjsTreeChanges);
88
80
  const removeListener = editor.registerUpdateListener(({
89
81
  prevEditorState,
@@ -102,7 +94,6 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
102
94
  if (isReloadingDoc.current === false) {
103
95
  disconnect();
104
96
  }
105
-
106
97
  provider.off('sync', onSync);
107
98
  provider.off('status', onStatus);
108
99
  provider.off('reload', onProviderDocReload);
@@ -116,7 +107,6 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
116
107
  const ref = element => {
117
108
  binding.cursorsContainer = element;
118
109
  };
119
-
120
110
  return /*#__PURE__*/reactDom.createPortal( /*#__PURE__*/React.createElement("div", {
121
111
  ref: ref
122
112
  }), cursorsContainerRef && cursorsContainerRef.current || document.body);
@@ -125,7 +115,6 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
125
115
  return editor.registerCommand(yjs.TOGGLE_CONNECT_COMMAND, payload => {
126
116
  if (connect !== undefined && disconnect !== undefined) {
127
117
  const shouldConnect = payload;
128
-
129
118
  if (shouldConnect) {
130
119
  // eslint-disable-next-line no-console
131
120
  console.log('Collaboration connected!');
@@ -136,7 +125,6 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
136
125
  disconnect();
137
126
  }
138
127
  }
139
-
140
128
  return true;
141
129
  }, lexical.COMMAND_PRIORITY_EDITOR);
142
130
  }, [connect, disconnect, editor]);
@@ -159,11 +147,9 @@ function useYjsHistory(editor, binding) {
159
147
  const undo = () => {
160
148
  undoManager.undo();
161
149
  };
162
-
163
150
  const redo = () => {
164
151
  undoManager.redo();
165
152
  };
166
-
167
153
  return utils.mergeRegister(editor.registerCommand(lexical.UNDO_COMMAND, () => {
168
154
  undo();
169
155
  return true;
@@ -174,14 +160,14 @@ function useYjsHistory(editor, binding) {
174
160
  });
175
161
  const clearHistory = React.useCallback(() => {
176
162
  undoManager.clear();
177
- }, [undoManager]); // Exposing undo and redo states
163
+ }, [undoManager]);
178
164
 
165
+ // Exposing undo and redo states
179
166
  React.useEffect(() => {
180
167
  const updateUndoRedoStates = () => {
181
168
  editor.dispatchCommand(lexical.CAN_UNDO_COMMAND, undoManager.undoStack.length > 0);
182
169
  editor.dispatchCommand(lexical.CAN_REDO_COMMAND, undoManager.redoStack.length > 0);
183
170
  };
184
-
185
171
  undoManager.on('stack-item-added', updateUndoRedoStates);
186
172
  undoManager.on('stack-item-popped', updateUndoRedoStates);
187
173
  undoManager.on('stack-cleared', updateUndoRedoStates);
@@ -193,11 +179,9 @@ function useYjsHistory(editor, binding) {
193
179
  }, [editor, undoManager]);
194
180
  return clearHistory;
195
181
  }
196
-
197
182
  function initializeEditor(editor, initialEditorState) {
198
183
  editor.update(() => {
199
184
  const root = lexical.$getRoot();
200
-
201
185
  if (root.isEmpty()) {
202
186
  if (initialEditorState) {
203
187
  switch (typeof initialEditorState) {
@@ -209,7 +193,6 @@ function initializeEditor(editor, initialEditorState) {
209
193
  });
210
194
  break;
211
195
  }
212
-
213
196
  case 'object':
214
197
  {
215
198
  editor.setEditorState(initialEditorState, {
@@ -217,12 +200,10 @@ function initializeEditor(editor, initialEditorState) {
217
200
  });
218
201
  break;
219
202
  }
220
-
221
203
  case 'function':
222
204
  {
223
205
  editor.update(() => {
224
206
  const root1 = lexical.$getRoot();
225
-
226
207
  if (root1.isEmpty()) {
227
208
  initialEditorState(editor);
228
209
  }
@@ -238,7 +219,6 @@ function initializeEditor(editor, initialEditorState) {
238
219
  const {
239
220
  activeElement
240
221
  } = document;
241
-
242
222
  if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
243
223
  paragraph.select();
244
224
  }
@@ -248,7 +228,6 @@ function initializeEditor(editor, initialEditorState) {
248
228
  tag: 'history-merge'
249
229
  });
250
230
  }
251
-
252
231
  function clearEditorSkipCollab(editor, binding) {
253
232
  // reset editor state
254
233
  editor.update(() => {
@@ -258,33 +237,25 @@ function clearEditorSkipCollab(editor, binding) {
258
237
  }, {
259
238
  tag: 'skip-collab'
260
239
  });
261
-
262
240
  if (binding.cursors == null) {
263
241
  return;
264
242
  }
265
-
266
243
  const cursors = binding.cursors;
267
-
268
244
  if (cursors == null) {
269
245
  return;
270
246
  }
271
-
272
247
  const cursorsContainer = binding.cursorsContainer;
273
-
274
248
  if (cursorsContainer == null) {
275
249
  return;
276
- } // reset cursors in dom
277
-
250
+ }
278
251
 
252
+ // reset cursors in dom
279
253
  const cursorsArr = Array.from(cursors.values());
280
-
281
254
  for (let i = 0; i < cursorsArr.length; i++) {
282
255
  const cursor = cursorsArr[i];
283
256
  const selection = cursor.selection;
284
-
285
257
  if (selection && selection.selections != null) {
286
258
  const selections = selection.selections;
287
-
288
259
  for (let j = 0; j < selections.length; j++) {
289
260
  cursorsContainer.removeChild(selections[i]);
290
261
  }
@@ -6,21 +6,17 @@
6
6
  *
7
7
  */
8
8
  /// <reference types="react" />
9
- import { EditorState, EditorThemeClasses, Klass, LexicalEditor, LexicalNode } from 'lexical';
9
+ import { EditorState, EditorThemeClasses, HTMLConfig, Klass, LexicalEditor, LexicalNode, LexicalNodeReplacement } from 'lexical';
10
10
  export type InitialEditorStateType = null | string | EditorState | ((editor: LexicalEditor) => void);
11
11
  export type InitialConfigType = Readonly<{
12
12
  editor__DEPRECATED?: LexicalEditor | null;
13
13
  namespace: string;
14
- nodes?: ReadonlyArray<Klass<LexicalNode> | {
15
- replace: Klass<LexicalNode>;
16
- with: <T extends {
17
- new (...args: any): any;
18
- }>(node: InstanceType<T>) => LexicalNode;
19
- }>;
14
+ nodes?: ReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement>;
20
15
  onError: (error: Error, editor: LexicalEditor) => void;
21
16
  editable?: boolean;
22
17
  theme?: EditorThemeClasses;
23
18
  editorState?: InitialEditorStateType;
19
+ html?: HTMLConfig;
24
20
  }>;
25
21
  type Props = {
26
22
  children: JSX.Element | string | (JSX.Element | string)[];
@@ -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
  /**
@@ -50,14 +51,15 @@ function LexicalComposer({
50
51
  editor__DEPRECATED: initialEditor,
51
52
  nodes,
52
53
  onError,
53
- editorState: initialEditorState
54
+ editorState: initialEditorState,
55
+ html
54
56
  } = initialConfig;
55
57
  const context = LexicalComposerContext.createLexicalComposerContext(null, theme);
56
58
  let editor = initialEditor || null;
57
-
58
59
  if (editor === null) {
59
60
  const newEditor = lexical.createEditor({
60
61
  editable: initialConfig.editable,
62
+ html,
61
63
  namespace,
62
64
  nodes,
63
65
  onError: error => onError(error, newEditor),
@@ -66,34 +68,33 @@ function LexicalComposer({
66
68
  initializeEditor(newEditor, initialEditorState);
67
69
  editor = newEditor;
68
70
  }
69
-
70
71
  return [editor, context];
71
- }, // We only do this for init
72
+ },
73
+ // We only do this for init
72
74
  // eslint-disable-next-line react-hooks/exhaustive-deps
73
75
  []);
74
76
  useLayoutEffect(() => {
75
77
  const isEditable = initialConfig.editable;
76
78
  const [editor] = composerContext;
77
- editor.setEditable(isEditable !== undefined ? isEditable : true); // We only do this for init
79
+ editor.setEditable(isEditable !== undefined ? isEditable : true);
80
+
81
+ // We only do this for init
78
82
  // eslint-disable-next-line react-hooks/exhaustive-deps
79
83
  }, []);
80
84
  return /*#__PURE__*/React.createElement(LexicalComposerContext.LexicalComposerContext.Provider, {
81
85
  value: composerContext
82
86
  }, children);
83
87
  }
84
-
85
88
  function initializeEditor(editor, initialEditorState) {
86
89
  if (initialEditorState === null) {
87
90
  return;
88
91
  } else if (initialEditorState === undefined) {
89
92
  editor.update(() => {
90
93
  const root = lexical.$getRoot();
91
-
92
94
  if (root.isEmpty()) {
93
95
  const paragraph = lexical.$createParagraphNode();
94
96
  root.append(paragraph);
95
97
  const activeElement = CAN_USE_DOM ? document.activeElement : null;
96
-
97
98
  if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
98
99
  paragraph.select();
99
100
  }
@@ -107,18 +108,15 @@ function initializeEditor(editor, initialEditorState) {
107
108
  editor.setEditorState(parsedEditorState, HISTORY_MERGE_OPTIONS);
108
109
  break;
109
110
  }
110
-
111
111
  case 'object':
112
112
  {
113
113
  editor.setEditorState(initialEditorState, HISTORY_MERGE_OPTIONS);
114
114
  break;
115
115
  }
116
-
117
116
  case 'function':
118
117
  {
119
118
  editor.update(() => {
120
119
  const root = lexical.$getRoot();
121
-
122
120
  if (root.isEmpty()) {
123
121
  initialEditorState(editor);
124
122
  }
@@ -12,6 +12,8 @@ import type {
12
12
  LexicalEditor,
13
13
  LexicalNode,
14
14
  EditorState,
15
+ LexicalNodeReplacement,
16
+ HTMLConfig,
15
17
  } from 'lexical';
16
18
 
17
19
  export type InitialEditorStateType =
@@ -24,13 +26,11 @@ export type InitialConfigType = $ReadOnly<{
24
26
  editor__DEPRECATED?: LexicalEditor | null,
25
27
  editable?: boolean,
26
28
  namespace: string,
27
- nodes?: $ReadOnlyArray<
28
- | Class<LexicalNode>
29
- | {replace: Class<LexicalNode>, with: (node: LexicalNode) => LexicalNode},
30
- >,
29
+ nodes?: $ReadOnlyArray<Class<LexicalNode> | LexicalNodeReplacement>,
31
30
  theme?: EditorThemeClasses,
32
31
  editorState?: InitialEditorStateType,
33
32
  onError: (error: Error, editor: LexicalEditor) => void,
33
+ html?: HTMLConfig,
34
34
  }>;
35
35
 
36
36
  type Props = {
@@ -6,4 +6,5 @@
6
6
  */
7
7
  'use strict';var e=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),g=require("react");let m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;var n=m?g.useLayoutEffect:g.useEffect;let p={tag:"history-merge"};
8
8
  function q(a,c){if(null!==c)if(void 0===c)a.update(()=>{var b=f.$getRoot();if(b.isEmpty()){let d=f.$createParagraphNode();b.append(d);b=m?document.activeElement:null;(null!==f.$getSelection()||null!==b&&b===a.getRootElement())&&d.select()}},p);else if(null!==c)switch(typeof c){case "string":let b=a.parseEditorState(c);a.setEditorState(b,p);break;case "object":a.setEditorState(c,p);break;case "function":a.update(()=>{f.$getRoot().isEmpty()&&c(a)},p)}}
9
- exports.LexicalComposer=function({initialConfig:a,children:c}){let b=g.useMemo(()=>{const {theme:d,namespace:h,editor__DEPRECATED:r,nodes:t,onError:u,editorState:v}=a,w=e.createLexicalComposerContext(null,d);let k=r||null;if(null===k){const l=f.createEditor({editable:a.editable,namespace:h,nodes:t,onError:x=>u(x,l),theme:d});q(l,v);k=l}return[k,w]},[]);n(()=>{let d=a.editable,[h]=b;h.setEditable(void 0!==d?d:!0)},[]);return g.createElement(e.LexicalComposerContext.Provider,{value:b},c)}
9
+ exports.LexicalComposer=function({initialConfig:a,children:c}){let b=g.useMemo(()=>{const {theme:d,namespace:h,editor__DEPRECATED:r,nodes:t,onError:u,editorState:v,html:w}=a,x=e.createLexicalComposerContext(null,d);let k=r||null;if(null===k){const l=f.createEditor({editable:a.editable,html:w,namespace:h,nodes:t,onError:y=>u(y,l),theme:d});q(l,v);k=l}return[k,x]},[]);n(()=>{let d=a.editable,[h]=b;h.setEditable(void 0!==d?d:!0)},[]);return g.createElement(e.LexicalComposerContext.Provider,{value:b},
10
+ c)}
@@ -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
 
@@ -13,14 +13,12 @@ function _extends() {
13
13
  _extends = Object.assign ? Object.assign.bind() : function (target) {
14
14
  for (var i = 1; i < arguments.length; i++) {
15
15
  var source = arguments[i];
16
-
17
16
  for (var key in source) {
18
17
  if (Object.prototype.hasOwnProperty.call(source, key)) {
19
18
  target[key] = source[key];
20
19
  }
21
20
  }
22
21
  }
23
-
24
22
  return target;
25
23
  };
26
24
  return _extends.apply(this, arguments);
@@ -33,6 +31,7 @@ function _extends() {
33
31
  * LICENSE file in the root directory of this source tree.
34
32
  *
35
33
  */
34
+
36
35
  const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
37
36
 
38
37
  /**
@@ -6,7 +6,7 @@
6
6
  *
7
7
  */
8
8
  import type { MenuRenderFn, MenuResolution } from './shared/LexicalMenu';
9
- import { LexicalNode } from 'lexical';
9
+ import { CommandListenerPriority, LexicalNode } from 'lexical';
10
10
  import { MutableRefObject, ReactPortal } from 'react';
11
11
  import { MenuOption } from './shared/LexicalMenu';
12
12
  export type ContextMenuRenderFn<TOption extends MenuOption> = (anchorElementRef: MutableRefObject<HTMLElement | null>, itemProps: {
@@ -24,6 +24,7 @@ export type LexicalContextMenuPluginProps<TOption extends MenuOption> = {
24
24
  onOpen?: (resolution: MenuResolution) => void;
25
25
  menuRenderFn: ContextMenuRenderFn<TOption>;
26
26
  anchorClassName?: string;
27
+ commandPriority?: CommandListenerPriority;
27
28
  };
28
- export declare function LexicalContextMenuPlugin<TOption extends MenuOption>({ options, onClose, onOpen, onSelectOption, menuRenderFn: contextMenuRenderFn, anchorClassName, }: LexicalContextMenuPluginProps<TOption>): JSX.Element | null;
29
+ export declare function LexicalContextMenuPlugin<TOption extends MenuOption>({ options, onClose, onOpen, onSelectOption, menuRenderFn: contextMenuRenderFn, anchorClassName, commandPriority, }: LexicalContextMenuPluginProps<TOption>): JSX.Element | null;
29
30
  export { MenuOption, MenuRenderFn, MenuResolution };