@lexical/react 0.3.3 → 0.3.4

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 (68) hide show
  1. package/DEPRECATED_useLexical.d.ts +19 -0
  2. package/DEPRECATED_useLexical.js.flow +4 -1
  3. package/DEPRECATED_useLexicalAutoFormatter.d.ts +9 -0
  4. package/DEPRECATED_useLexicalAutoFormatter.js.flow +4 -1
  5. package/DEPRECATED_useLexicalCanShowPlaceholder.d.ts +9 -0
  6. package/DEPRECATED_useLexicalCanShowPlaceholder.js.flow +4 -1
  7. package/DEPRECATED_useLexicalCharacterLimit.d.ts +8 -0
  8. package/DEPRECATED_useLexicalCharacterLimit.js.flow +4 -1
  9. package/DEPRECATED_useLexicalDecorators.d.ts +9 -0
  10. package/DEPRECATED_useLexicalDecorators.js.flow +4 -1
  11. package/DEPRECATED_useLexicalEditor.d.ts +9 -0
  12. package/DEPRECATED_useLexicalEditorEvents.d.ts +10 -0
  13. package/DEPRECATED_useLexicalEditorEvents.js.flow +4 -1
  14. package/DEPRECATED_useLexicalHistory.d.ts +12 -0
  15. package/DEPRECATED_useLexicalHistory.js.flow +4 -1
  16. package/DEPRECATED_useLexicalList.d.ts +9 -0
  17. package/DEPRECATED_useLexicalList.js.flow +4 -1
  18. package/DEPRECATED_useLexicalPlainText.d.ts +10 -0
  19. package/DEPRECATED_useLexicalPlainText.js.flow +4 -1
  20. package/DEPRECATED_useLexicalRichText.d.ts +10 -0
  21. package/DEPRECATED_useLexicalRichText.js.flow +4 -1
  22. package/LexicalAutoFocusPlugin.d.ts +1 -2
  23. package/LexicalAutoLinkPlugin.d.ts +12 -12
  24. package/LexicalAutoScrollPlugin.d.ts +6 -4
  25. package/LexicalBlockWithAlignableContents.d.ts +11 -8
  26. package/LexicalBlockWithAlignableContents.dev.js +3 -2
  27. package/LexicalBlockWithAlignableContents.js.flow +4 -0
  28. package/LexicalBlockWithAlignableContents.prod.js +4 -4
  29. package/LexicalCharacterLimitPlugin.d.ts +3 -4
  30. package/LexicalCheckListPlugin.d.ts +1 -2
  31. package/LexicalClearEditorPlugin.d.ts +4 -4
  32. package/LexicalCollaborationPlugin.d.ts +17 -31
  33. package/LexicalComposer.d.ts +16 -15
  34. package/LexicalComposer.dev.js +39 -1
  35. package/LexicalComposer.prod.js +3 -2
  36. package/LexicalComposerContext.d.ts +10 -15
  37. package/LexicalContentEditable.d.ts +24 -23
  38. package/LexicalDecoratorBlockNode.d.ts +13 -24
  39. package/LexicalHashtagPlugin.d.ts +1 -2
  40. package/LexicalHistoryPlugin.d.ts +6 -23
  41. package/LexicalHorizontalRuleNode.d.ts +19 -17
  42. package/LexicalLinkPlugin.d.ts +1 -2
  43. package/LexicalLinkPlugin.dev.js +1 -0
  44. package/LexicalListPlugin.d.ts +1 -2
  45. package/LexicalMarkdownShortcutPlugin.d.ts +4 -6
  46. package/LexicalNestedComposer.d.ts +6 -8
  47. package/LexicalOnChangePlugin.d.ts +5 -7
  48. package/LexicalPlainTextPlugin.d.ts +6 -9
  49. package/LexicalPlainTextPlugin.dev.js +25 -1
  50. package/LexicalPlainTextPlugin.prod.js +3 -3
  51. package/LexicalRichTextPlugin.d.ts +6 -9
  52. package/LexicalRichTextPlugin.dev.js +25 -1
  53. package/LexicalRichTextPlugin.prod.js +3 -3
  54. package/LexicalTablePlugin.d.ts +1 -2
  55. package/LexicalTreeView.d.ts +9 -11
  56. package/package.json +19 -19
  57. package/shared/useCanShowPlaceholder.d.ts +9 -0
  58. package/shared/useCharacterLimit.d.ts +16 -0
  59. package/shared/useDecorators.d.ts +9 -0
  60. package/shared/useEditorEvents.d.ts +10 -0
  61. package/shared/useHistory.d.ts +10 -0
  62. package/shared/useList.d.ts +9 -0
  63. package/shared/usePlainTextSetup.d.ts +10 -0
  64. package/shared/useRichTextSetup.d.ts +10 -0
  65. package/shared/useYjsCollaboration.d.ts +14 -0
  66. package/useLexicalIsTextContentEmpty.d.ts +2 -7
  67. package/useLexicalNodeSelection.d.ts +2 -6
  68. package/useLexicalTextEntity.d.ts +4 -13
@@ -0,0 +1,19 @@
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
+ */
8
+ import type { EditorState, EditorThemeClasses, LexicalEditor, LexicalNode } from 'lexical';
9
+ import type { Klass } from 'shared/types';
10
+ export declare function useLexical(editorConfig: {
11
+ disableEvents?: boolean;
12
+ editorState?: EditorState;
13
+ namespace: string;
14
+ nodes?: ReadonlyArray<Klass<LexicalNode>>;
15
+ onError: (error: Error) => void;
16
+ parentEditor?: LexicalEditor;
17
+ readOnly?: boolean;
18
+ theme?: EditorThemeClasses;
19
+ }): [LexicalEditor, (arg0: null | HTMLElement) => void, boolean];
@@ -1,5 +1,8 @@
1
1
  /**
2
- * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
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.
3
6
  *
4
7
  * @flow strict
5
8
  * @format
@@ -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
+ */
8
+ import type { LexicalEditor } from 'lexical';
9
+ export declare function useLexicalAutoFormatter(editor: LexicalEditor): void;
@@ -1,5 +1,8 @@
1
1
  /**
2
- * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
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.
3
6
  *
4
7
  * @flow strict
5
8
  * @format
@@ -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
+ */
8
+ import type { LexicalEditor } from 'lexical';
9
+ export declare function useLexicalCanShowPlaceholder(editor: LexicalEditor): boolean;
@@ -1,5 +1,8 @@
1
1
  /**
2
- * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
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.
3
6
  *
4
7
  * @flow strict
5
8
  * @format
@@ -0,0 +1,8 @@
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
+ */
8
+ export { mergePrevious, useCharacterLimit } from './shared/useCharacterLimit';
@@ -1,5 +1,8 @@
1
1
  /**
2
- * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
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.
3
6
  *
4
7
  * @flow strict
5
8
  * @format
@@ -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
+ */
8
+ import type { LexicalEditor } from 'lexical';
9
+ export declare function useLexicalDecorators(editor: LexicalEditor): Array<JSX.Element>;
@@ -1,5 +1,8 @@
1
1
  /**
2
- * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
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.
3
6
  *
4
7
  * @flow strict
5
8
  * @format
@@ -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
+ */
8
+ import type { LexicalEditor } from 'lexical';
9
+ export declare function useLexicalEditor(editor: LexicalEditor): [(rootElement: null | HTMLElement) => void, boolean];
@@ -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
+ */
8
+ import type { InputEvents } from './shared/useEditorEvents';
9
+ import type { LexicalEditor } from 'lexical';
10
+ export declare function useLexicalEditorEvents(events: InputEvents, editor: LexicalEditor): void;
@@ -1,5 +1,8 @@
1
1
  /**
2
- * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
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.
3
6
  *
4
7
  * @flow strict
5
8
  * @format
@@ -0,0 +1,12 @@
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
+ */
8
+ import type { HistoryState } from '@lexical/history';
9
+ import type { LexicalEditor } from 'lexical';
10
+ export { createEmptyHistoryState } from '@lexical/history';
11
+ export type { HistoryState };
12
+ export declare function useLexicalHistory(editor: LexicalEditor, externalHistoryState?: HistoryState, delay?: number): void;
@@ -1,5 +1,8 @@
1
1
  /**
2
- * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
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.
3
6
  *
4
7
  * @flow strict
5
8
  * @format
@@ -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
+ */
8
+ import type { LexicalEditor } from 'lexical';
9
+ export declare function useLexicalList(editor: LexicalEditor): void;
@@ -1,5 +1,8 @@
1
1
  /**
2
- * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
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.
3
6
  *
4
7
  * @flow strict
5
8
  * @format
@@ -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
+ */
8
+ import type { HistoryState } from './DEPRECATED_useLexicalHistory';
9
+ import type { EditorState, LexicalEditor } from 'lexical';
10
+ export declare function useLexicalPlainText(editor: LexicalEditor, externalHistoryState?: HistoryState, initialEditorState?: null | string | EditorState | (() => void)): void;
@@ -1,5 +1,8 @@
1
1
  /**
2
- * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
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.
3
6
  *
4
7
  * @flow strict
5
8
  * @format
@@ -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
+ */
8
+ import type { HistoryState } from './DEPRECATED_useLexicalHistory';
9
+ import type { EditorState, LexicalEditor } from 'lexical';
10
+ export declare function useLexicalRichText(editor: LexicalEditor, externalHistoryState?: HistoryState, initialEditorState?: null | string | EditorState | (() => void)): void;
@@ -1,5 +1,8 @@
1
1
  /**
2
- * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
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.
3
6
  *
4
7
  * @flow strict
5
8
  * @format
@@ -5,5 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
-
9
- export function AutoFocusPlugin(): null;
8
+ export declare function AutoFocusPlugin(): null;
@@ -5,16 +5,16 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
-
9
- type ChangeHandler = (url: string | null, prevUrl: string | null) => void;
10
- type LinkMatcherResult = {
11
- text: string;
12
- url: string;
13
- length: number;
14
- index: number;
8
+ declare type ChangeHandler = (url: string | null, prevUrl: string | null) => void;
9
+ declare type LinkMatcherResult = {
10
+ index: number;
11
+ length: number;
12
+ text: string;
13
+ url: string;
15
14
  };
16
- export type LinkMatcher = (text: string) => LinkMatcherResult | null;
17
- export function AutoLinkPlugin(props: {
18
- matchers: Array<LinkMatcher>;
19
- onChange?: ChangeHandler;
20
- }): JSX.Element | null;
15
+ export declare type LinkMatcher = (text: string) => LinkMatcherResult | null;
16
+ export declare function AutoLinkPlugin({ matchers, onChange, }: {
17
+ matchers: Array<LinkMatcher>;
18
+ onChange?: ChangeHandler;
19
+ }): JSX.Element;
20
+ export {};
@@ -5,8 +5,10 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
-
9
- type Props = Readonly<{
10
- scrollRef: {current: HTMLElement | null};
8
+ declare type Props = Readonly<{
9
+ scrollRef: {
10
+ current: HTMLElement | null;
11
+ };
11
12
  }>;
12
- export function AutoScrollPlugin(props: Props): null;
13
+ export declare function AutoScrollPlugin({ scrollRef }: Props): JSX.Element;
14
+ export {};
@@ -5,12 +5,15 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
-
9
- import type {ElementFormatType, NodeKey} from 'lexical';
10
-
11
- type Props = Readonly<{
12
- children: JSX.Element | string | (JSX.Element | string)[];
13
- format: ElementFormatType | null;
14
- nodeKey: NodeKey;
8
+ import type { ElementFormatType, NodeKey } from 'lexical';
9
+ declare type Props = Readonly<{
10
+ children: JSX.Element | string | (JSX.Element | string)[];
11
+ format: ElementFormatType | null | undefined;
12
+ nodeKey: NodeKey;
13
+ className: Readonly<{
14
+ base: string;
15
+ focus: string;
16
+ }>;
15
17
  }>;
16
- declare function BlockWithAlignableContents(arg0: Props): JSX.Element;
18
+ export declare function BlockWithAlignableContents({ children, format, nodeKey, className, }: Props): JSX.Element;
19
+ export {};
@@ -23,7 +23,8 @@ var React = require('react');
23
23
  function BlockWithAlignableContents({
24
24
  children,
25
25
  format,
26
- nodeKey
26
+ nodeKey,
27
+ className
27
28
  }) {
28
29
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
29
30
  const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection.useLexicalNodeSelection(nodeKey);
@@ -89,7 +90,7 @@ function BlockWithAlignableContents({
89
90
  }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_DELETE_COMMAND, onDelete, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, onDelete, lexical.COMMAND_PRIORITY_LOW));
90
91
  }, [clearSelection, editor, isSelected, nodeKey, onDelete, setSelected]);
91
92
  return /*#__PURE__*/React.createElement("div", {
92
- className: `embed-block${isSelected ? ' focused' : ''}`,
93
+ className: [className.base, isSelected ? className.focus : null].filter(Boolean).join(' '),
93
94
  ref: ref,
94
95
  style: {
95
96
  textAlign: format ? format : null
@@ -19,6 +19,10 @@ type Props = $ReadOnly<{
19
19
  children: React$Node,
20
20
  format: ?ElementFormatType,
21
21
  nodeKey: NodeKey,
22
+ className: $ReadOnly<{
23
+ base: string,
24
+ focus: string,
25
+ }>,
22
26
  }>;
23
27
 
24
28
  declare export function BlockWithAlignableContents(Props): React$Node;
@@ -4,7 +4,7 @@
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 a=require("@lexical/react/LexicalComposerContext"),h=require("@lexical/react/LexicalDecoratorBlockNode"),m=require("@lexical/react/useLexicalNodeSelection"),n=require("@lexical/utils"),t=require("lexical"),u=require("react");
8
- exports.BlockWithAlignableContents=function({children:v,format:p,nodeKey:g}){let [d]=a.useLexicalComposerContext(),[e,k,q]=m.useLexicalNodeSelection(g),r=u.useRef(),l=u.useCallback(b=>{e&&t.$isNodeSelection(t.$getSelection())&&(b.preventDefault(),d.update(()=>{const c=t.$getNodeByKey(g);t.$isDecoratorNode(c)&&c.isTopLevel()&&c.remove();k(!1)}));return!1},[d,e,g,k]);u.useEffect(()=>n.mergeRegister(d.registerCommand(t.FORMAT_ELEMENT_COMMAND,b=>{if(e){var c=t.$getSelection();if(t.$isNodeSelection(c)){var f=
9
- t.$getNodeByKey(g);h.$isDecoratorBlockNode(f)&&f.setFormat(b)}else if(t.$isRangeSelection(c)){c=c.getNodes();for(f of c)h.$isDecoratorBlockNode(f)?f.setFormat(b):n.$getNearestBlockElementAncestorOrThrow(f).setFormat(b)}return!0}return!1},t.COMMAND_PRIORITY_LOW),d.registerCommand(t.CLICK_COMMAND,b=>{b.preventDefault();return b.target===r.current?(b.shiftKey||q(),k(!e),!0):!1},t.COMMAND_PRIORITY_LOW),d.registerCommand(t.KEY_DELETE_COMMAND,l,t.COMMAND_PRIORITY_LOW),d.registerCommand(t.KEY_BACKSPACE_COMMAND,
10
- l,t.COMMAND_PRIORITY_LOW)),[q,d,e,g,l,k]);return u.createElement("div",{className:`embed-block${e?" focused":""}`,ref:r,style:{textAlign:p?p:null}},v)}
7
+ 'use strict';var a=require("@lexical/react/LexicalComposerContext"),h=require("@lexical/react/LexicalDecoratorBlockNode"),m=require("@lexical/react/useLexicalNodeSelection"),n=require("@lexical/utils"),u=require("lexical"),v=require("react");
8
+ exports.BlockWithAlignableContents=function({children:w,format:p,nodeKey:g,className:q}){let [d]=a.useLexicalComposerContext(),[e,k,r]=m.useLexicalNodeSelection(g),t=v.useRef(),l=v.useCallback(b=>{e&&u.$isNodeSelection(u.$getSelection())&&(b.preventDefault(),d.update(()=>{const c=u.$getNodeByKey(g);u.$isDecoratorNode(c)&&c.isTopLevel()&&c.remove();k(!1)}));return!1},[d,e,g,k]);v.useEffect(()=>n.mergeRegister(d.registerCommand(u.FORMAT_ELEMENT_COMMAND,b=>{if(e){var c=u.$getSelection();if(u.$isNodeSelection(c)){var f=
9
+ u.$getNodeByKey(g);h.$isDecoratorBlockNode(f)&&f.setFormat(b)}else if(u.$isRangeSelection(c)){c=c.getNodes();for(f of c)h.$isDecoratorBlockNode(f)?f.setFormat(b):n.$getNearestBlockElementAncestorOrThrow(f).setFormat(b)}return!0}return!1},u.COMMAND_PRIORITY_LOW),d.registerCommand(u.CLICK_COMMAND,b=>{b.preventDefault();return b.target===t.current?(b.shiftKey||r(),k(!e),!0):!1},u.COMMAND_PRIORITY_LOW),d.registerCommand(u.KEY_DELETE_COMMAND,l,u.COMMAND_PRIORITY_LOW),d.registerCommand(u.KEY_BACKSPACE_COMMAND,
10
+ l,u.COMMAND_PRIORITY_LOW)),[r,d,e,g,l,k]);return v.createElement("div",{className:[q.base,e?q.focus:null].filter(Boolean).join(" "),ref:t,style:{textAlign:p?p:null}},w)}
@@ -5,7 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
-
9
- export function CharacterLimitPlugin(props: {
10
- charset: 'UTF-8' | 'UTF-16';
11
- }): JSX.Element | null;
8
+ export declare function CharacterLimitPlugin({ charset, }: {
9
+ charset: 'UTF-8' | 'UTF-16';
10
+ }): JSX.Element;
@@ -5,5 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
-
9
- export function CheckListPlugin(): null;
8
+ export declare function CheckListPlugin(): null;
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
-
9
- type Props = Readonly<{
10
- onClear?: () => void;
8
+ declare type Props = Readonly<{
9
+ onClear?: () => void;
11
10
  }>;
12
- export function ClearEditorPlugin(arg0: Props): JSX.Element | null;
11
+ export declare function ClearEditorPlugin({ onClear }: Props): JSX.Element;
12
+ export {};
@@ -5,35 +5,21 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
-
9
- import type {Provider} from '@lexical/yjs';
10
- import type {Doc, RelativePosition} from 'yjs';
11
-
12
- export type UserState = {
13
- anchorPos: null | RelativePosition;
14
- focusPos: null | RelativePosition;
15
- name: string;
16
- color: string;
17
- focusing: boolean;
8
+ /// <reference types="react" />
9
+ import type { Doc } from 'yjs';
10
+ import { WebsocketProvider } from 'y-websocket';
11
+ declare type CollaborationContextType = {
12
+ clientID: number;
13
+ color: string;
14
+ name: string;
15
+ yjsDocMap: Map<string, Doc>;
18
16
  };
19
- export type ProviderAwareness = {
20
- getLocalState: () => UserState;
21
- setLocalState: (arg0: UserState) => void;
22
- getStates: () => Array<UserState>;
23
- on: (type: 'update', cb: () => void) => void;
24
- off: (type: 'update', cb: () => void) => void;
25
- };
26
- type CollaborationContextType = {
27
- clientID: number;
28
- color: string;
29
- name: string;
30
- yjsDocMap: Map<string, Doc>;
31
- };
32
- export function CollaborationPlugin(arg0: {
33
- id: string;
34
- providerFactory(id: string, yjsDocMap: Map<string, Doc>): Provider;
35
- shouldBootstrap: boolean;
36
- username?: string;
37
- }): JSX.Element | null;
38
- export declare var CollaborationContext: React.Context<CollaborationContextType>;
39
- export function useCollaborationContext(): CollaborationContextType;
17
+ export declare function CollaborationPlugin({ id, providerFactory, shouldBootstrap, username, }: {
18
+ id: string;
19
+ providerFactory: (id: string, yjsDocMap: Map<string, Doc>) => WebsocketProvider;
20
+ shouldBootstrap: boolean;
21
+ username?: string;
22
+ }): JSX.Element;
23
+ export declare const CollaborationContext: React.Context<CollaborationContextType>;
24
+ export declare function useCollaborationContext(username?: string): CollaborationContextType;
25
+ export {};
@@ -5,19 +5,20 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
-
9
- import {Class} from 'utility-types';
10
- import type {EditorThemeClasses, LexicalEditor, LexicalNode} from 'lexical';
11
-
12
- type Props = {
13
- initialConfig: {
14
- namespace: string;
15
- editor__DEPRECATED?: LexicalEditor | null;
16
- readOnly?: boolean;
17
- nodes?: Array<Class<LexicalNode>>;
18
- theme?: EditorThemeClasses;
19
- onError: (error: Error, editor: LexicalEditor) => void;
20
- };
21
- children: JSX.Element | JSX.Element[] | null;
8
+ import { EditorState, EditorThemeClasses, LexicalEditor, LexicalNode } from 'lexical';
9
+ import { Class } from 'utility-types';
10
+ export declare type InitialEditorStateType = null | string | EditorState | ((editor: LexicalEditor) => void);
11
+ declare type Props = {
12
+ children: JSX.Element | string | (JSX.Element | string)[];
13
+ initialConfig: Readonly<{
14
+ editor__DEPRECATED?: LexicalEditor | null;
15
+ namespace: string;
16
+ nodes?: ReadonlyArray<Class<LexicalNode>>;
17
+ onError: (error: Error, editor: LexicalEditor) => void;
18
+ readOnly?: boolean;
19
+ theme?: EditorThemeClasses;
20
+ editorState?: InitialEditorStateType;
21
+ }>;
22
22
  };
23
- export function LexicalComposer(arg0: Props): JSX.Element | null;
23
+ export declare function LexicalComposer({ initialConfig, children }: Props): JSX.Element;
24
+ export {};
@@ -36,6 +36,9 @@ var useLayoutEffect = useLayoutEffectImpl;
36
36
  * LICENSE file in the root directory of this source tree.
37
37
  *
38
38
  */
39
+ const HISTORY_MERGE_OPTIONS = {
40
+ tag: 'history-merge'
41
+ };
39
42
  function LexicalComposer({
40
43
  initialConfig,
41
44
  children
@@ -46,7 +49,8 @@ function LexicalComposer({
46
49
  namespace,
47
50
  editor__DEPRECATED: initialEditor,
48
51
  nodes,
49
- onError
52
+ onError,
53
+ editorState: initialEditorState
50
54
  } = initialConfig;
51
55
  const context = LexicalComposerContext.createLexicalComposerContext(null, theme);
52
56
  let editor = initialEditor || null;
@@ -59,6 +63,7 @@ function LexicalComposer({
59
63
  readOnly: true,
60
64
  theme
61
65
  });
66
+ initializeEditor(newEditor, initialEditorState);
62
67
  editor = newEditor;
63
68
  }
64
69
 
@@ -77,4 +82,37 @@ function LexicalComposer({
77
82
  }, children);
78
83
  }
79
84
 
85
+ function initializeEditor(editor, initialEditorState) {
86
+ if (initialEditorState === null) {
87
+ return;
88
+ } else if (initialEditorState === undefined) ; else if (initialEditorState !== null) {
89
+ switch (typeof initialEditorState) {
90
+ case 'string':
91
+ {
92
+ const parsedEditorState = editor.parseEditorState(initialEditorState);
93
+ editor.setEditorState(parsedEditorState, HISTORY_MERGE_OPTIONS);
94
+ break;
95
+ }
96
+
97
+ case 'object':
98
+ {
99
+ editor.setEditorState(initialEditorState, HISTORY_MERGE_OPTIONS);
100
+ break;
101
+ }
102
+
103
+ case 'function':
104
+ {
105
+ editor.update(() => {
106
+ const root = lexical.$getRoot();
107
+
108
+ if (root.isEmpty()) {
109
+ initialEditorState(editor);
110
+ }
111
+ }, HISTORY_MERGE_OPTIONS);
112
+ break;
113
+ }
114
+ }
115
+ }
116
+ }
117
+
80
118
  exports.LexicalComposer = LexicalComposer;
@@ -4,5 +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 a=require("@lexical/react/LexicalComposerContext"),e=require("lexical"),k=require("react"),l="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?k.useLayoutEffect:k.useEffect;
8
- exports.LexicalComposer=function({initialConfig:f,children:m}){let h=k.useMemo(()=>{const {theme:b,namespace:c,editor__DEPRECATED:n,nodes:p,onError:q}=f,r=a.createLexicalComposerContext(null,b);let d=n||null;if(null===d){const g=e.createEditor({namespace:c,nodes:p,onError:t=>q(t,g),readOnly:!0,theme:b});d=g}return[d,r]},[]);l(()=>{let b=f.readOnly,[c]=h;c.setReadOnly(b||!1)},[]);return k.createElement(a.LexicalComposerContext.Provider,{value:h},m)}
7
+ 'use strict';var c=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),l=require("react"),m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?l.useLayoutEffect:l.useEffect;let n={tag:"history-merge"};
8
+ function p(b,a){if(null!==a&&void 0!==a&&null!==a)switch(typeof a){case "string":let d=b.parseEditorState(a);b.setEditorState(d,n);break;case "object":b.setEditorState(a,n);break;case "function":b.update(()=>{f.$getRoot().isEmpty()&&a(b)},n)}}
9
+ exports.LexicalComposer=function({initialConfig:b,children:a}){let d=l.useMemo(()=>{const {theme:e,namespace:g,editor__DEPRECATED:q,nodes:r,onError:t,editorState:u}=b,v=c.createLexicalComposerContext(null,e);let h=q||null;if(null===h){const k=f.createEditor({namespace:g,nodes:r,onError:w=>t(w,k),readOnly:!0,theme:e});p(k,u);h=k}return[h,v]},[]);m(()=>{let e=b.readOnly,[g]=d;g.setReadOnly(e||!1)},[]);return l.createElement(c.LexicalComposerContext.Provider,{value:d},a)}
@@ -5,20 +5,15 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
-
9
- import type {EditorThemeClasses, LexicalEditor} from 'lexical';
10
- export type LexicalComposerContextType = {
11
- getTheme: () => EditorThemeClasses | null | undefined;
8
+ /// <reference types="react" />
9
+ import type { EditorThemeClasses, LexicalEditor } from 'lexical';
10
+ export declare type LexicalComposerContextType = {
11
+ getTheme: () => EditorThemeClasses | null | undefined;
12
12
  };
13
- export type LexicalComposerContextWithEditor = [
14
- LexicalEditor,
15
- LexicalComposerContextType,
13
+ export declare type LexicalComposerContextWithEditor = [
14
+ LexicalEditor,
15
+ LexicalComposerContextType
16
16
  ];
17
- export declare var LexicalComposerContext: React.Context<
18
- LexicalComposerContextWithEditor | null | undefined
19
- >;
20
- export function createLexicalComposerContext(
21
- parent: LexicalComposerContextWithEditor | null | undefined,
22
- theme: EditorThemeClasses | null | undefined,
23
- ): LexicalComposerContextType;
24
- export function useLexicalComposerContext(): LexicalComposerContextWithEditor;
17
+ export declare const LexicalComposerContext: React.Context<LexicalComposerContextWithEditor | null | undefined>;
18
+ export declare function createLexicalComposerContext(parent: LexicalComposerContextWithEditor | null | undefined, theme: EditorThemeClasses | null | undefined): LexicalComposerContextType;
19
+ export declare function useLexicalComposerContext(): LexicalComposerContextWithEditor;