@lexical/react 0.35.1-nightly.20250924.0 → 0.36.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 (154) hide show
  1. package/ExtensionComponent.d.ts +42 -0
  2. package/LexicalAutoEmbedPlugin.dev.js +2 -0
  3. package/LexicalAutoEmbedPlugin.dev.mjs +2 -0
  4. package/LexicalAutoEmbedPlugin.prod.js +1 -1
  5. package/LexicalAutoEmbedPlugin.prod.mjs +1 -1
  6. package/LexicalAutoLinkPlugin.d.ts +2 -17
  7. package/LexicalAutoLinkPlugin.dev.js +7 -309
  8. package/LexicalAutoLinkPlugin.dev.mjs +9 -310
  9. package/LexicalAutoLinkPlugin.js.flow +4 -18
  10. package/LexicalAutoLinkPlugin.prod.js +1 -1
  11. package/LexicalAutoLinkPlugin.prod.mjs +1 -1
  12. package/LexicalClearEditorPlugin.dev.js +2 -23
  13. package/LexicalClearEditorPlugin.dev.mjs +2 -23
  14. package/LexicalClearEditorPlugin.prod.js +1 -1
  15. package/LexicalClearEditorPlugin.prod.mjs +1 -1
  16. package/LexicalClickableLinkPlugin.dev.js +5 -70
  17. package/LexicalClickableLinkPlugin.dev.mjs +6 -71
  18. package/LexicalClickableLinkPlugin.prod.js +1 -1
  19. package/LexicalClickableLinkPlugin.prod.mjs +1 -1
  20. package/LexicalCollaborationContext.prod.js +1 -1
  21. package/LexicalCollaborationContext.prod.mjs +1 -1
  22. package/LexicalCollaborationPlugin.dev.mjs +2 -2
  23. package/LexicalCollaborationPlugin.prod.mjs +1 -1
  24. package/LexicalContentEditable.dev.js +2 -3
  25. package/LexicalContentEditable.dev.mjs +2 -3
  26. package/LexicalContentEditable.prod.js +1 -1
  27. package/LexicalContentEditable.prod.mjs +1 -1
  28. package/LexicalContextMenuPlugin.dev.js +2 -0
  29. package/LexicalContextMenuPlugin.dev.mjs +4 -2
  30. package/LexicalContextMenuPlugin.prod.js +1 -1
  31. package/LexicalContextMenuPlugin.prod.mjs +1 -1
  32. package/LexicalDecoratorBlockNode.dev.js +1 -0
  33. package/LexicalDecoratorBlockNode.dev.mjs +1 -0
  34. package/LexicalDecoratorBlockNode.js.flow +7 -0
  35. package/LexicalDecoratorBlockNode.prod.js +1 -1
  36. package/LexicalDecoratorBlockNode.prod.mjs +1 -1
  37. package/LexicalDraggableBlockPlugin.dev.js +6 -0
  38. package/LexicalDraggableBlockPlugin.dev.mjs +6 -0
  39. package/LexicalDraggableBlockPlugin.prod.js +1 -1
  40. package/LexicalDraggableBlockPlugin.prod.mjs +1 -1
  41. package/LexicalExtensionComponent.dev.js +53 -0
  42. package/LexicalExtensionComponent.dev.mjs +51 -0
  43. package/LexicalExtensionComponent.js +11 -0
  44. package/LexicalExtensionComponent.js.flow +12 -0
  45. package/LexicalExtensionComponent.mjs +12 -0
  46. package/LexicalExtensionComponent.node.mjs +10 -0
  47. package/LexicalExtensionComponent.prod.js +9 -0
  48. package/LexicalExtensionComponent.prod.mjs +9 -0
  49. package/LexicalExtensionComposer.d.ts +69 -0
  50. package/LexicalExtensionComposer.dev.js +105 -0
  51. package/LexicalExtensionComposer.dev.mjs +103 -0
  52. package/LexicalExtensionComposer.js +11 -0
  53. package/LexicalExtensionComposer.js.flow +20 -0
  54. package/LexicalExtensionComposer.mjs +12 -0
  55. package/LexicalExtensionComposer.node.mjs +10 -0
  56. package/LexicalExtensionComposer.prod.js +9 -0
  57. package/LexicalExtensionComposer.prod.mjs +9 -0
  58. package/LexicalHashtagPlugin.dev.js +1 -136
  59. package/LexicalHashtagPlugin.dev.mjs +3 -138
  60. package/LexicalHashtagPlugin.prod.js +1 -1
  61. package/LexicalHashtagPlugin.prod.mjs +1 -1
  62. package/LexicalHorizontalRuleNode.d.ts +10 -11
  63. package/LexicalHorizontalRuleNode.dev.js +12 -26
  64. package/LexicalHorizontalRuleNode.dev.mjs +14 -27
  65. package/LexicalHorizontalRuleNode.js.flow +2 -3
  66. package/LexicalHorizontalRuleNode.prod.js +1 -1
  67. package/LexicalHorizontalRuleNode.prod.mjs +1 -1
  68. package/LexicalLinkPlugin.d.ts +1 -1
  69. package/LexicalLinkPlugin.dev.js +7 -52
  70. package/LexicalLinkPlugin.dev.mjs +8 -53
  71. package/LexicalLinkPlugin.prod.js +1 -1
  72. package/LexicalLinkPlugin.prod.mjs +1 -1
  73. package/LexicalListPlugin.js.flow +5 -0
  74. package/LexicalMarkdownShortcutPlugin.dev.mjs +1 -1
  75. package/LexicalMarkdownShortcutPlugin.prod.mjs +1 -1
  76. package/LexicalNestedComposer.js.flow +10 -6
  77. package/LexicalNodeContextMenuPlugin.dev.js +10 -0
  78. package/LexicalNodeContextMenuPlugin.dev.mjs +11 -1
  79. package/LexicalNodeContextMenuPlugin.prod.js +1 -1
  80. package/LexicalNodeContextMenuPlugin.prod.mjs +1 -1
  81. package/LexicalNodeMenuPlugin.dev.js +2 -0
  82. package/LexicalNodeMenuPlugin.dev.mjs +4 -2
  83. package/LexicalNodeMenuPlugin.prod.js +1 -1
  84. package/LexicalNodeMenuPlugin.prod.mjs +1 -1
  85. package/LexicalPlainTextPlugin.d.ts +1 -1
  86. package/LexicalPlainTextPlugin.dev.js +85 -30
  87. package/LexicalPlainTextPlugin.dev.mjs +85 -30
  88. package/LexicalPlainTextPlugin.prod.js +1 -1
  89. package/LexicalPlainTextPlugin.prod.mjs +1 -1
  90. package/LexicalReactExtension.dev.js +187 -0
  91. package/LexicalReactExtension.dev.mjs +184 -0
  92. package/LexicalReactExtension.js +11 -0
  93. package/LexicalReactExtension.js.flow +68 -0
  94. package/LexicalReactExtension.mjs +13 -0
  95. package/LexicalReactExtension.node.mjs +11 -0
  96. package/LexicalReactExtension.prod.js +9 -0
  97. package/LexicalReactExtension.prod.mjs +9 -0
  98. package/LexicalReactPluginHostExtension.dev.js +189 -0
  99. package/LexicalReactPluginHostExtension.dev.mjs +181 -0
  100. package/LexicalReactPluginHostExtension.js +11 -0
  101. package/LexicalReactPluginHostExtension.js.flow +84 -0
  102. package/LexicalReactPluginHostExtension.mjs +18 -0
  103. package/LexicalReactPluginHostExtension.node.mjs +16 -0
  104. package/LexicalReactPluginHostExtension.prod.js +9 -0
  105. package/LexicalReactPluginHostExtension.prod.mjs +9 -0
  106. package/LexicalReactProviderExtension.dev.js +33 -0
  107. package/LexicalReactProviderExtension.dev.mjs +31 -0
  108. package/LexicalReactProviderExtension.js +11 -0
  109. package/LexicalReactProviderExtension.js.flow +12 -0
  110. package/LexicalReactProviderExtension.mjs +12 -0
  111. package/LexicalReactProviderExtension.node.mjs +10 -0
  112. package/LexicalReactProviderExtension.prod.js +9 -0
  113. package/LexicalReactProviderExtension.prod.mjs +9 -0
  114. package/LexicalRichTextPlugin.d.ts +1 -1
  115. package/LexicalRichTextPlugin.dev.js +85 -30
  116. package/LexicalRichTextPlugin.dev.mjs +85 -30
  117. package/LexicalRichTextPlugin.prod.js +1 -1
  118. package/LexicalRichTextPlugin.prod.mjs +1 -1
  119. package/LexicalTabIndentationPlugin.d.ts +2 -2
  120. package/LexicalTabIndentationPlugin.dev.js +3 -57
  121. package/LexicalTabIndentationPlugin.dev.mjs +3 -56
  122. package/LexicalTabIndentationPlugin.prod.js +1 -1
  123. package/LexicalTabIndentationPlugin.prod.mjs +1 -1
  124. package/LexicalTreeViewExtension.dev.js +57 -0
  125. package/LexicalTreeViewExtension.dev.mjs +54 -0
  126. package/LexicalTreeViewExtension.js +11 -0
  127. package/LexicalTreeViewExtension.js.flow +12 -0
  128. package/LexicalTreeViewExtension.mjs +13 -0
  129. package/LexicalTreeViewExtension.node.mjs +11 -0
  130. package/LexicalTreeViewExtension.prod.js +9 -0
  131. package/LexicalTreeViewExtension.prod.mjs +9 -0
  132. package/LexicalTypeaheadMenuPlugin.dev.js +2 -0
  133. package/LexicalTypeaheadMenuPlugin.dev.mjs +4 -2
  134. package/LexicalTypeaheadMenuPlugin.prod.js +1 -1
  135. package/LexicalTypeaheadMenuPlugin.prod.mjs +1 -1
  136. package/ReactExtension.d.ts +41 -0
  137. package/ReactPluginHostExtension.d.ts +56 -0
  138. package/ReactProviderExtension.d.ts +9 -0
  139. package/TreeViewExtension.d.ts +18 -0
  140. package/package.json +228 -17
  141. package/shared/LegacyDecorators.d.ts +23 -0
  142. package/shared/buildEditorComponent.d.ts +11 -0
  143. package/shared/mergeRefs.d.ts +2 -1
  144. package/shared/types.d.ts +89 -0
  145. package/shared/useReactDecorators.d.ts +12 -0
  146. package/useExtensionComponent.d.ts +10 -0
  147. package/useLexicalExtensionComponent.dev.js +37 -0
  148. package/useLexicalExtensionComponent.dev.mjs +34 -0
  149. package/useLexicalExtensionComponent.js +11 -0
  150. package/useLexicalExtensionComponent.js.flow +12 -0
  151. package/useLexicalExtensionComponent.mjs +13 -0
  152. package/useLexicalExtensionComponent.node.mjs +11 -0
  153. package/useLexicalExtensionComponent.prod.js +9 -0
  154. package/useLexicalExtensionComponent.prod.mjs +9 -0
@@ -0,0 +1,181 @@
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
+
9
+ import { untracked, signal, getExtensionDependencyFromEditor, effect } from '@lexical/extension';
10
+ import { ReactExtension } from '@lexical/react/ReactExtension';
11
+ import { ReactProviderExtension } from '@lexical/react/ReactProviderExtension';
12
+ import { mergeRegister } from '@lexical/utils';
13
+ import { createCommand, defineExtension, configExtension, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_EDITOR } from 'lexical';
14
+ import { useState, useEffect, Suspense } from 'react';
15
+ import { createPortal } from 'react-dom';
16
+ import { createRoot } from 'react-dom/client';
17
+ import { jsx, Fragment } from 'react/jsx-runtime';
18
+
19
+ /**
20
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
21
+ *
22
+ * This source code is licensed under the MIT license found in the
23
+ * LICENSE file in the root directory of this source tree.
24
+ *
25
+ */
26
+
27
+ // Do not require this module directly! Use normal `invariant` calls.
28
+
29
+ function formatDevErrorMessage(message) {
30
+ throw new Error(message);
31
+ }
32
+
33
+ function mountReactExtensionComponent(editor, opts) {
34
+ const {
35
+ props,
36
+ extension,
37
+ ...rest
38
+ } = opts;
39
+ const {
40
+ Component
41
+ } = getExtensionDependencyFromEditor(editor, extension).output;
42
+ const element = props ? /*#__PURE__*/jsx(Component, {
43
+ ...props
44
+ }) : null;
45
+ mountReactPluginElement(editor, {
46
+ ...rest,
47
+ element
48
+ });
49
+ }
50
+ function mountReactPluginComponent(editor, opts) {
51
+ const {
52
+ Component,
53
+ props,
54
+ ...rest
55
+ } = opts;
56
+ mountReactPluginElement(editor, {
57
+ ...rest,
58
+ element: props ? /*#__PURE__*/jsx(Component, {
59
+ ...props
60
+ }) : null
61
+ });
62
+ }
63
+ function mountReactPluginElement(editor, opts) {
64
+ getExtensionDependencyFromEditor(editor, ReactPluginHostExtension).output.mountReactPlugin(opts);
65
+ }
66
+ function mountReactPluginHost(editor, container) {
67
+ getExtensionDependencyFromEditor(editor, ReactPluginHostExtension).output.mountReactPluginHost(container);
68
+ }
69
+ const REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND = createCommand('REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND');
70
+ const REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND = createCommand('REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND');
71
+ function PluginHostDecorator({
72
+ context: [editor]
73
+ }) {
74
+ const {
75
+ mountedPluginsStore
76
+ } = getExtensionDependencyFromEditor(editor, ReactPluginHostExtension).output;
77
+ const {
78
+ ErrorBoundary
79
+ } = getExtensionDependencyFromEditor(editor, ReactExtension).config;
80
+ const onError = editor._onError.bind(editor);
81
+ const [{
82
+ plugins
83
+ }, setMountedPlugins] = useState(() => mountedPluginsStore.peek());
84
+ useEffect(() => effect(() => setMountedPlugins(mountedPluginsStore.value)), [mountedPluginsStore]);
85
+ const children = [];
86
+ for (const {
87
+ key,
88
+ element,
89
+ domNode
90
+ } of plugins.values()) {
91
+ if (!element) {
92
+ continue;
93
+ }
94
+ const wrapped = /*#__PURE__*/jsx(ErrorBoundary, {
95
+ onError: onError,
96
+ children: /*#__PURE__*/jsx(Suspense, {
97
+ fallback: null,
98
+ children: element
99
+ })
100
+ }, key);
101
+ children.push(domNode ? /*#__PURE__*/createPortal(wrapped, domNode, key) : wrapped);
102
+ }
103
+ return children.length > 0 ? /*#__PURE__*/jsx(Fragment, {
104
+ children: children
105
+ }) : null;
106
+ }
107
+
108
+ /**
109
+ * This extension provides a React host for editors that are not built
110
+ * with LexicalExtensionComposer (e.g. you are using Vanilla JS or some
111
+ * other framework).
112
+ *
113
+ * You must use {@link mountReactPluginHost} for any React content to work.
114
+ * Afterwards, you may use {@link mountReactExtensionComponent} to
115
+ * render UI for a specific React Extension.
116
+ * {@link mountReactPluginComponent} and
117
+ * {@link mountReactPluginElement} can be used to render
118
+ * legacy React plug-ins (or any React content).
119
+ */
120
+ const ReactPluginHostExtension = defineExtension({
121
+ build(editor, config, state) {
122
+ const mountedPluginsStore = signal({
123
+ plugins: new Map()
124
+ });
125
+ return {
126
+ mountReactPlugin: arg => {
127
+ editor.dispatchCommand(REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND, arg);
128
+ },
129
+ // Using outputs to wrap commands will give us better error messages
130
+ // if the mount functions are called on an editor without this extension
131
+ mountReactPluginHost: container => editor.dispatchCommand(REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND, {
132
+ root: createRoot(container)
133
+ }),
134
+ mountedPluginsStore
135
+ };
136
+ },
137
+ dependencies: [ReactProviderExtension, configExtension(ReactExtension, {
138
+ decorators: [PluginHostDecorator]
139
+ })],
140
+ name: '@lexical/react/ReactPluginHost',
141
+ register(editor, _config, state) {
142
+ let root;
143
+ const {
144
+ mountedPluginsStore
145
+ } = state.getOutput();
146
+ const {
147
+ Component
148
+ } = state.getDependency(ReactExtension).output;
149
+ return mergeRegister(() => {
150
+ if (root) {
151
+ root.unmount();
152
+ }
153
+ untracked(() => {
154
+ mountedPluginsStore.value.plugins.clear();
155
+ });
156
+ }, editor.registerCommand(REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND, arg => {
157
+ // This runs before the PluginHost version
158
+ untracked(() => {
159
+ const {
160
+ plugins
161
+ } = mountedPluginsStore.value;
162
+ plugins.set(arg.key, arg);
163
+ mountedPluginsStore.value = {
164
+ plugins
165
+ };
166
+ });
167
+ return false;
168
+ }, COMMAND_PRIORITY_CRITICAL), editor.registerCommand(REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND, arg => {
169
+ if (!(root === undefined)) {
170
+ formatDevErrorMessage(`ReactPluginHostExtension: Root is already mounted`);
171
+ }
172
+ root = arg.root;
173
+ root.render(/*#__PURE__*/jsx(Component, {
174
+ contentEditable: null
175
+ }));
176
+ return true;
177
+ }, COMMAND_PRIORITY_EDITOR));
178
+ }
179
+ });
180
+
181
+ export { REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND, REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND, ReactPluginHostExtension, mountReactExtensionComponent, mountReactPluginComponent, mountReactPluginElement, mountReactPluginHost };
@@ -0,0 +1,11 @@
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
+
9
+ 'use strict'
10
+ const LexicalReactPluginHostExtension = process.env.NODE_ENV !== 'production' ? require('./LexicalReactPluginHostExtension.dev.js') : require('./LexicalReactPluginHostExtension.prod.js');
11
+ module.exports = LexicalReactPluginHostExtension;
@@ -0,0 +1,84 @@
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
+ /**
11
+ * LexicalReactPluginHostExtension
12
+ */
13
+ import type {
14
+ LexicalExtension,
15
+ AnyLexicalExtension,
16
+ LexicalEditor,
17
+ LexicalExtensionOutput,
18
+ LexicalCommand,
19
+ ExtensionConfigBase,
20
+ } from 'lexical';
21
+ import type {Signal} from '@lexical/extension';
22
+ import type {DecoratorComponentProps} from '@lexical/react/ReactExtension';
23
+ export type {DecoratorComponentProps};
24
+
25
+ type Container = DocumentFragment | Element;
26
+ // TODO: Not sure how to import RootType from react-dom/client
27
+ type Root = mixed;
28
+
29
+ export interface HostMountCommandArg {
30
+ root: Root;
31
+ }
32
+
33
+ export interface MountPluginCommandArg {
34
+ key: string;
35
+ element: React.Node | null;
36
+ domNode?: Container | null;
37
+ }
38
+
39
+ declare export function mountReactExtensionComponent<
40
+ Extension: AnyLexicalExtension,
41
+ >(
42
+ editor: LexicalEditor,
43
+ opts: {
44
+ extension: Extension;
45
+ props: [LexicalExtensionOutput<Extension>] extends [
46
+ {
47
+ // $FlowFixMe[unclear-type]: defined by user
48
+ Component: infer OutputComponentType extends React.ComponentType<any>;
49
+ },
50
+ ]
51
+ ? React.PropsOf<OutputComponentType> | null
52
+ : empty;
53
+ } & Omit<MountPluginCommandArg, 'element'>,
54
+ ): void;
55
+
56
+ declare export function mountReactPluginComponent<
57
+ P: {...} = {...},
58
+ >(
59
+ editor: LexicalEditor,
60
+ opts: {
61
+ Component: React.ComponentType<P>;
62
+ props: (P & {key?: null | void | React.Key}) | null;
63
+ } & Omit<MountPluginCommandArg, 'element'>,
64
+ ): void;
65
+
66
+ declare export function mountReactPluginElement(
67
+ editor: LexicalEditor,
68
+ opts: MountPluginCommandArg,
69
+ ): void;
70
+
71
+ declare export function mountReactPluginHost(
72
+ editor: LexicalEditor,
73
+ container: Container,
74
+ ): void;
75
+
76
+ declare export var REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND: LexicalCommand<HostMountCommandArg>;
77
+ declare export var REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND: LexicalCommand<MountPluginCommandArg>;
78
+ declare export var ReactPluginHostExtension: LexicalExtension<ExtensionConfigBase, "@lexical/react/ReactPluginHost", {
79
+ mountReactPlugin: (arg: MountPluginCommandArg) => void;
80
+ mountReactPluginHost: (container: Container) => boolean;
81
+ mountedPluginsStore: Signal<{
82
+ plugins: Map<string, MountPluginCommandArg>;
83
+ }>;
84
+ }, void>;
@@ -0,0 +1,18 @@
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
+
9
+ import * as modDev from './LexicalReactPluginHostExtension.dev.mjs';
10
+ import * as modProd from './LexicalReactPluginHostExtension.prod.mjs';
11
+ const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
12
+ export const REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND = mod.REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND;
13
+ export const REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND = mod.REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND;
14
+ export const ReactPluginHostExtension = mod.ReactPluginHostExtension;
15
+ export const mountReactExtensionComponent = mod.mountReactExtensionComponent;
16
+ export const mountReactPluginComponent = mod.mountReactPluginComponent;
17
+ export const mountReactPluginElement = mod.mountReactPluginElement;
18
+ export const mountReactPluginHost = mod.mountReactPluginHost;
@@ -0,0 +1,16 @@
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
+
9
+ const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalReactPluginHostExtension.dev.mjs') : import('./LexicalReactPluginHostExtension.prod.mjs'));
10
+ export const REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND = mod.REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND;
11
+ export const REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND = mod.REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND;
12
+ export const ReactPluginHostExtension = mod.ReactPluginHostExtension;
13
+ export const mountReactExtensionComponent = mod.mountReactExtensionComponent;
14
+ export const mountReactPluginComponent = mod.mountReactPluginComponent;
15
+ export const mountReactPluginElement = mod.mountReactPluginElement;
16
+ export const mountReactPluginHost = mod.mountReactPluginHost;
@@ -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
+
9
+ "use strict";var e=require("@lexical/extension"),n=require("@lexical/react/ReactExtension"),t=require("@lexical/react/ReactProviderExtension"),o=require("@lexical/utils"),r=require("lexical"),i=require("react"),s=require("react-dom"),u=require("react-dom/client"),c=require("react/jsx-runtime");function a(n,t){e.getExtensionDependencyFromEditor(n,m).output.mountReactPlugin(t)}const l=r.createCommand("REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND"),d=r.createCommand("REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND");const m=r.defineExtension({build:(n,t,o)=>({mountReactPlugin:e=>{n.dispatchCommand(d,e)},mountReactPluginHost:e=>n.dispatchCommand(l,{root:u.createRoot(e)}),mountedPluginsStore:e.signal({plugins:new Map})}),dependencies:[t.ReactProviderExtension,r.configExtension(n.ReactExtension,{decorators:[function({context:[t]}){const{mountedPluginsStore:o}=e.getExtensionDependencyFromEditor(t,m).output,{ErrorBoundary:r}=e.getExtensionDependencyFromEditor(t,n.ReactExtension).config,u=t._onError.bind(t),[{plugins:a},l]=i.useState((()=>o.peek()));i.useEffect((()=>e.effect((()=>l(o.value)))),[o]);const d=[];for(const{key:e,element:n,domNode:t}of a.values()){if(!n)continue;const o=c.jsx(r,{onError:u,children:c.jsx(i.Suspense,{fallback:null,children:n})},e);d.push(t?s.createPortal(o,t,e):o)}return d.length>0?c.jsx(c.Fragment,{children:d}):null}]})],name:"@lexical/react/ReactPluginHost",register(t,i,s){let u;const{mountedPluginsStore:a}=s.getOutput(),{Component:m}=s.getDependency(n.ReactExtension).output;return o.mergeRegister((()=>{u&&u.unmount(),e.untracked((()=>{a.value.plugins.clear()}))}),t.registerCommand(d,(n=>(e.untracked((()=>{const{plugins:e}=a.value;e.set(n.key,n),a.value={plugins:e}})),!1)),r.COMMAND_PRIORITY_CRITICAL),t.registerCommand(l,(e=>(void 0!==u&&function(e,...n){const t=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of n)o.append("v",e);throw t.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(322),u=e.root,u.render(c.jsx(m,{contentEditable:null})),!0)),r.COMMAND_PRIORITY_EDITOR))}});exports.REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND=d,exports.REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND=l,exports.ReactPluginHostExtension=m,exports.mountReactExtensionComponent=function(n,t){const{props:o,extension:r,...i}=t,{Component:s}=e.getExtensionDependencyFromEditor(n,r).output;a(n,{...i,element:o?c.jsx(s,{...o}):null})},exports.mountReactPluginComponent=function(e,n){const{Component:t,props:o,...r}=n;a(e,{...r,element:o?c.jsx(t,{...o}):null})},exports.mountReactPluginElement=a,exports.mountReactPluginHost=function(n,t){e.getExtensionDependencyFromEditor(n,m).output.mountReactPluginHost(t)};
@@ -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
+
9
+ import{untracked as e,signal as n,getExtensionDependencyFromEditor as t,effect as o}from"@lexical/extension";import{ReactExtension as r}from"@lexical/react/ReactExtension";import{ReactProviderExtension as i}from"@lexical/react/ReactProviderExtension";import{mergeRegister as l}from"@lexical/utils";import{createCommand as u,defineExtension as c,configExtension as a,COMMAND_PRIORITY_CRITICAL as s,COMMAND_PRIORITY_EDITOR as m}from"lexical";import{useState as p,useEffect as d,Suspense as f}from"react";import{createPortal as g}from"react-dom";import{createRoot as x}from"react-dom/client";import{jsx as h,Fragment as P}from"react/jsx-runtime";function v(e,n){const{props:o,extension:r,...i}=n,{Component:l}=t(e,r).output;C(e,{...i,element:o?h(l,{...o}):null})}function R(e,n){const{Component:t,props:o,...r}=n;C(e,{...r,element:o?h(t,{...o}):null})}function C(e,n){t(e,M).output.mountReactPlugin(n)}function _(e,n){t(e,M).output.mountReactPluginHost(n)}const E=u("REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND"),O=u("REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND");const M=c({build:(e,t,o)=>({mountReactPlugin:n=>{e.dispatchCommand(O,n)},mountReactPluginHost:n=>e.dispatchCommand(E,{root:x(n)}),mountedPluginsStore:n({plugins:new Map})}),dependencies:[i,a(r,{decorators:[function({context:[e]}){const{mountedPluginsStore:n}=t(e,M).output,{ErrorBoundary:i}=t(e,r).config,l=e._onError.bind(e),[{plugins:u},c]=p((()=>n.peek()));d((()=>o((()=>c(n.value)))),[n]);const a=[];for(const{key:e,element:n,domNode:t}of u.values()){if(!n)continue;const o=h(i,{onError:l,children:h(f,{fallback:null,children:n})},e);a.push(t?g(o,t,e):o)}return a.length>0?h(P,{children:a}):null}]})],name:"@lexical/react/ReactPluginHost",register(n,t,o){let i;const{mountedPluginsStore:u}=o.getOutput(),{Component:c}=o.getDependency(r).output;return l((()=>{i&&i.unmount(),e((()=>{u.value.plugins.clear()}))}),n.registerCommand(O,(n=>(e((()=>{const{plugins:e}=u.value;e.set(n.key,n),u.value={plugins:e}})),!1)),s),n.registerCommand(E,(e=>(void 0!==i&&function(e,...n){const t=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of n)o.append("v",e);throw t.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(322),i=e.root,i.render(h(c,{contentEditable:null})),!0)),m))}});export{O as REACT_PLUGIN_HOST_MOUNT_PLUGIN_COMMAND,E as REACT_PLUGIN_HOST_MOUNT_ROOT_COMMAND,M as ReactPluginHostExtension,v as mountReactExtensionComponent,R as mountReactPluginComponent,C as mountReactPluginElement,_ as mountReactPluginHost};
@@ -0,0 +1,33 @@
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
+
9
+ 'use strict';
10
+
11
+ var lexical = require('lexical');
12
+
13
+ /**
14
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
15
+ *
16
+ * This source code is licensed under the MIT license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ *
19
+ */
20
+
21
+ /**
22
+ * An extension used to declare that there is a LexicalExtensionComposer or
23
+ * ReactPluginHostExtension available so that we can issue runtime warnings
24
+ * when plugins that depend on React are hosted in an environment
25
+ * where it is not ever going to be rendered.
26
+ *
27
+ * It is a separate extension so it can be used as a peer dependency.
28
+ */
29
+ const ReactProviderExtension = lexical.defineExtension({
30
+ name: '@lexical/react/ReactProvider'
31
+ });
32
+
33
+ exports.ReactProviderExtension = ReactProviderExtension;
@@ -0,0 +1,31 @@
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
+
9
+ import { defineExtension } from 'lexical';
10
+
11
+ /**
12
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
13
+ *
14
+ * This source code is licensed under the MIT license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ *
17
+ */
18
+
19
+ /**
20
+ * An extension used to declare that there is a LexicalExtensionComposer or
21
+ * ReactPluginHostExtension available so that we can issue runtime warnings
22
+ * when plugins that depend on React are hosted in an environment
23
+ * where it is not ever going to be rendered.
24
+ *
25
+ * It is a separate extension so it can be used as a peer dependency.
26
+ */
27
+ const ReactProviderExtension = defineExtension({
28
+ name: '@lexical/react/ReactProvider'
29
+ });
30
+
31
+ export { ReactProviderExtension };
@@ -0,0 +1,11 @@
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
+
9
+ 'use strict'
10
+ const LexicalReactProviderExtension = process.env.NODE_ENV !== 'production' ? require('./LexicalReactProviderExtension.dev.js') : require('./LexicalReactProviderExtension.prod.js');
11
+ module.exports = LexicalReactProviderExtension;
@@ -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
+ * @flow strict
8
+ */
9
+
10
+ /**
11
+ * LexicalReactProviderExtension
12
+ */
@@ -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
+
9
+ import * as modDev from './LexicalReactProviderExtension.dev.mjs';
10
+ import * as modProd from './LexicalReactProviderExtension.prod.mjs';
11
+ const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
12
+ export const ReactProviderExtension = mod.ReactProviderExtension;
@@ -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
+
9
+ const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalReactProviderExtension.dev.mjs') : import('./LexicalReactProviderExtension.prod.mjs'));
10
+ export const ReactProviderExtension = mod.ReactProviderExtension;
@@ -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
+
9
+ "use strict";const e=require("lexical").defineExtension({name:"@lexical/react/ReactProvider"});exports.ReactProviderExtension=e;
@@ -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
+
9
+ import{defineExtension as e}from"lexical";const r=e({name:"@lexical/react/ReactProvider"});export{r as ReactProviderExtension};
@@ -6,7 +6,7 @@
6
6
  *
7
7
  */
8
8
  import type { JSX } from 'react';
9
- import { ErrorBoundaryType } from './shared/useDecorators';
9
+ import { type ErrorBoundaryType } from './shared/LegacyDecorators';
10
10
  export declare function RichTextPlugin({ contentEditable, placeholder, ErrorBoundary, }: {
11
11
  contentEditable: JSX.Element;
12
12
  placeholder?: ((isEditable: boolean) => null | JSX.Element) | null | JSX.Element;
@@ -10,11 +10,13 @@
10
10
 
11
11
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
12
12
  var useLexicalEditable = require('@lexical/react/useLexicalEditable');
13
- var text = require('@lexical/text');
14
- var utils = require('@lexical/utils');
13
+ var extension = require('@lexical/extension');
14
+ var ReactProviderExtension = require('@lexical/react/ReactProviderExtension');
15
15
  var react = require('react');
16
16
  var reactDom = require('react-dom');
17
17
  var jsxRuntime = require('react/jsx-runtime');
18
+ var text = require('@lexical/text');
19
+ var utils = require('@lexical/utils');
18
20
  var dragon = require('@lexical/dragon');
19
21
  var richText = require('@lexical/rich-text');
20
22
 
@@ -26,7 +28,11 @@ var richText = require('@lexical/rich-text');
26
28
  *
27
29
  */
28
30
 
29
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
31
+ // Do not require this module directly! Use normal `invariant` calls.
32
+
33
+ function formatDevErrorMessage(message) {
34
+ throw new Error(message);
35
+ }
30
36
 
31
37
  /**
32
38
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -36,11 +42,7 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
36
42
  *
37
43
  */
38
44
 
39
-
40
- // This workaround is no longer necessary in React 19,
41
- // but we currently support React >=17.x
42
- // https://github.com/facebook/react/pull/26395
43
- const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
45
+ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
44
46
 
45
47
  /**
46
48
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -50,26 +52,11 @@ const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffec
50
52
  *
51
53
  */
52
54
 
53
- function canShowPlaceholderFromCurrentEditorState(editor) {
54
- const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
55
- return currentCanShowPlaceholder;
56
- }
57
- function useCanShowPlaceholder(editor) {
58
- const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
59
- useLayoutEffectImpl(() => {
60
- function resetCanShowPlaceholder() {
61
- const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
62
- setCanShowPlaceholder(currentCanShowPlaceholder);
63
- }
64
- resetCanShowPlaceholder();
65
- return utils.mergeRegister(editor.registerUpdateListener(() => {
66
- resetCanShowPlaceholder();
67
- }), editor.registerEditableListener(() => {
68
- resetCanShowPlaceholder();
69
- }));
70
- }, [editor]);
71
- return canShowPlaceholder;
72
- }
55
+
56
+ // This workaround is no longer necessary in React 19,
57
+ // but we currently support React >=17.x
58
+ // https://github.com/facebook/react/pull/26395
59
+ const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
73
60
 
74
61
  /**
75
62
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -119,6 +106,72 @@ function useDecorators(editor, ErrorBoundary) {
119
106
  }, [ErrorBoundary, decorators, editor]);
120
107
  }
121
108
 
109
+ function isUsingReactExtension(editor) {
110
+ const builder = extension.LexicalBuilder.maybeFromEditor(editor);
111
+ if (builder && builder.hasExtensionByName(ReactProviderExtension.ReactProviderExtension.name)) {
112
+ for (const name of ['@lexical/plain-text', '@lexical/rich-text']) {
113
+ if (!!builder.hasExtensionByName(name)) {
114
+ formatDevErrorMessage(`LexicalBuilder: @lexical/react legacy text plugins conflict with the ${name} extension. Remove the legacy <RichTextPlugin/> or <PlainTextPlugin/> component.`);
115
+ }
116
+ }
117
+ return true;
118
+ }
119
+ return false;
120
+ }
121
+ function Decorators({
122
+ editor,
123
+ ErrorBoundary
124
+ }) {
125
+ return useDecorators(editor, ErrorBoundary);
126
+ }
127
+
128
+ /**
129
+ * @internal
130
+ *
131
+ * When using @lexical/extension, the ReactProvider is expected to handle
132
+ * rendering decorators. This component allows RichTextPlugin and
133
+ * PlainTextPlugin to be used in extension projects that have not yet
134
+ * migrated to use RichTextExtension or PlainTextExtension.
135
+ **/
136
+ function LegacyDecorators({
137
+ editor,
138
+ ErrorBoundary
139
+ }) {
140
+ return isUsingReactExtension(editor) ? null : /*#__PURE__*/jsxRuntime.jsx(Decorators, {
141
+ editor: editor,
142
+ ErrorBoundary: ErrorBoundary
143
+ });
144
+ }
145
+
146
+ /**
147
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
148
+ *
149
+ * This source code is licensed under the MIT license found in the
150
+ * LICENSE file in the root directory of this source tree.
151
+ *
152
+ */
153
+
154
+ function canShowPlaceholderFromCurrentEditorState(editor) {
155
+ const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
156
+ return currentCanShowPlaceholder;
157
+ }
158
+ function useCanShowPlaceholder(editor) {
159
+ const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
160
+ useLayoutEffectImpl(() => {
161
+ function resetCanShowPlaceholder() {
162
+ const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
163
+ setCanShowPlaceholder(currentCanShowPlaceholder);
164
+ }
165
+ resetCanShowPlaceholder();
166
+ return utils.mergeRegister(editor.registerUpdateListener(() => {
167
+ resetCanShowPlaceholder();
168
+ }), editor.registerEditableListener(() => {
169
+ resetCanShowPlaceholder();
170
+ }));
171
+ }, [editor]);
172
+ return canShowPlaceholder;
173
+ }
174
+
122
175
  /**
123
176
  * Copyright (c) Meta Platforms, Inc. and affiliates.
124
177
  *
@@ -151,12 +204,14 @@ function RichTextPlugin({
151
204
  ErrorBoundary
152
205
  }) {
153
206
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
154
- const decorators = useDecorators(editor, ErrorBoundary);
155
207
  useRichTextSetup(editor);
156
208
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
157
209
  children: [contentEditable, /*#__PURE__*/jsxRuntime.jsx(Placeholder, {
158
210
  content: placeholder
159
- }), decorators]
211
+ }), /*#__PURE__*/jsxRuntime.jsx(LegacyDecorators, {
212
+ editor: editor,
213
+ ErrorBoundary: ErrorBoundary
214
+ })]
160
215
  });
161
216
  }
162
217