@lexical/react 0.14.5 → 0.16.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.
- package/LexicalAutoEmbedPlugin.dev.js +15 -11
- package/LexicalAutoEmbedPlugin.dev.mjs +5 -2
- package/LexicalAutoEmbedPlugin.js +2 -0
- package/LexicalAutoEmbedPlugin.mjs +2 -0
- package/LexicalAutoEmbedPlugin.node.mjs +2 -0
- package/LexicalAutoEmbedPlugin.prod.js +6 -5
- package/LexicalAutoEmbedPlugin.prod.mjs +3 -1
- package/LexicalAutoFocusPlugin.dev.js +3 -0
- package/LexicalAutoFocusPlugin.dev.mjs +3 -0
- package/LexicalAutoFocusPlugin.js +2 -0
- package/LexicalAutoFocusPlugin.mjs +2 -0
- package/LexicalAutoFocusPlugin.node.mjs +2 -0
- package/LexicalAutoFocusPlugin.prod.js +2 -0
- package/LexicalAutoFocusPlugin.prod.mjs +2 -0
- package/LexicalAutoLinkPlugin.dev.js +9 -4
- package/LexicalAutoLinkPlugin.dev.mjs +10 -5
- package/LexicalAutoLinkPlugin.js +2 -0
- package/LexicalAutoLinkPlugin.mjs +2 -0
- package/LexicalAutoLinkPlugin.node.mjs +2 -0
- package/LexicalAutoLinkPlugin.prod.js +12 -10
- package/LexicalAutoLinkPlugin.prod.mjs +3 -1
- package/LexicalBlockWithAlignableContents.dev.js +14 -9
- package/LexicalBlockWithAlignableContents.dev.mjs +11 -7
- package/LexicalBlockWithAlignableContents.js +2 -0
- package/LexicalBlockWithAlignableContents.mjs +2 -0
- package/LexicalBlockWithAlignableContents.node.mjs +2 -0
- package/LexicalBlockWithAlignableContents.prod.js +6 -4
- package/LexicalBlockWithAlignableContents.prod.mjs +3 -1
- package/LexicalCharacterLimitPlugin.dev.js +17 -12
- package/LexicalCharacterLimitPlugin.dev.mjs +12 -8
- package/LexicalCharacterLimitPlugin.js +2 -0
- package/LexicalCharacterLimitPlugin.mjs +2 -0
- package/LexicalCharacterLimitPlugin.node.mjs +2 -0
- package/LexicalCharacterLimitPlugin.prod.js +11 -9
- package/LexicalCharacterLimitPlugin.prod.mjs +3 -1
- package/LexicalCheckListPlugin.dev.js +5 -0
- package/LexicalCheckListPlugin.dev.mjs +5 -0
- package/LexicalCheckListPlugin.js +2 -0
- package/LexicalCheckListPlugin.mjs +2 -0
- package/LexicalCheckListPlugin.node.mjs +2 -0
- package/LexicalCheckListPlugin.prod.js +4 -2
- package/LexicalCheckListPlugin.prod.mjs +3 -1
- package/LexicalClearEditorPlugin.dev.js +9 -2
- package/LexicalClearEditorPlugin.dev.mjs +11 -4
- package/LexicalClearEditorPlugin.js +2 -0
- package/LexicalClearEditorPlugin.mjs +2 -0
- package/LexicalClearEditorPlugin.node.mjs +2 -0
- package/LexicalClearEditorPlugin.prod.js +3 -1
- package/LexicalClearEditorPlugin.prod.mjs +3 -1
- package/LexicalClickableLinkPlugin.d.ts +3 -1
- package/LexicalClickableLinkPlugin.dev.js +17 -15
- package/LexicalClickableLinkPlugin.dev.mjs +16 -15
- package/LexicalClickableLinkPlugin.js +2 -0
- package/LexicalClickableLinkPlugin.js.flow +3 -1
- package/LexicalClickableLinkPlugin.mjs +3 -0
- package/LexicalClickableLinkPlugin.node.mjs +3 -0
- package/LexicalClickableLinkPlugin.prod.js +6 -4
- package/LexicalClickableLinkPlugin.prod.mjs +3 -1
- package/LexicalCollaborationContext.dev.js +3 -0
- package/LexicalCollaborationContext.dev.mjs +3 -0
- package/LexicalCollaborationContext.js +2 -0
- package/LexicalCollaborationContext.mjs +2 -0
- package/LexicalCollaborationContext.node.mjs +2 -0
- package/LexicalCollaborationContext.prod.js +2 -0
- package/LexicalCollaborationContext.prod.mjs +2 -0
- package/LexicalCollaborationPlugin.dev.js +20 -2
- package/LexicalCollaborationPlugin.dev.mjs +6 -1
- package/LexicalCollaborationPlugin.js +2 -0
- package/LexicalCollaborationPlugin.mjs +2 -0
- package/LexicalCollaborationPlugin.node.mjs +2 -0
- package/LexicalCollaborationPlugin.prod.js +12 -10
- package/LexicalCollaborationPlugin.prod.mjs +3 -1
- package/LexicalComposer.dev.js +17 -8
- package/LexicalComposer.dev.mjs +16 -8
- package/LexicalComposer.js +2 -0
- package/LexicalComposer.mjs +2 -0
- package/LexicalComposer.node.mjs +2 -0
- package/LexicalComposer.prod.js +5 -4
- package/LexicalComposer.prod.mjs +3 -1
- package/LexicalComposerContext.dev.js +3 -0
- package/LexicalComposerContext.dev.mjs +3 -0
- package/LexicalComposerContext.js +2 -0
- package/LexicalComposerContext.mjs +2 -0
- package/LexicalComposerContext.node.mjs +2 -0
- package/LexicalComposerContext.prod.js +4 -2
- package/LexicalComposerContext.prod.mjs +3 -1
- package/LexicalContentEditable.dev.js +24 -23
- package/LexicalContentEditable.dev.mjs +22 -22
- package/LexicalContentEditable.js +2 -0
- package/LexicalContentEditable.mjs +2 -0
- package/LexicalContentEditable.node.mjs +2 -0
- package/LexicalContentEditable.prod.js +5 -3
- package/LexicalContentEditable.prod.mjs +3 -1
- package/LexicalContextMenuPlugin.dev.js +29 -7
- package/LexicalContextMenuPlugin.dev.mjs +17 -8
- package/LexicalContextMenuPlugin.js +2 -0
- package/LexicalContextMenuPlugin.js.flow +12 -0
- package/LexicalContextMenuPlugin.mjs +2 -0
- package/LexicalContextMenuPlugin.node.mjs +2 -0
- package/LexicalContextMenuPlugin.prod.js +18 -16
- package/LexicalContextMenuPlugin.prod.mjs +3 -1
- package/LexicalDecoratorBlockNode.d.ts +1 -0
- package/LexicalDecoratorBlockNode.dev.js +6 -0
- package/LexicalDecoratorBlockNode.dev.mjs +6 -0
- package/LexicalDecoratorBlockNode.js +2 -0
- package/LexicalDecoratorBlockNode.mjs +2 -0
- package/LexicalDecoratorBlockNode.node.mjs +2 -0
- package/LexicalDecoratorBlockNode.prod.js +3 -1
- package/LexicalDecoratorBlockNode.prod.mjs +3 -1
- package/LexicalEditorRefPlugin.dev.js +17 -1
- package/LexicalEditorRefPlugin.dev.mjs +3 -0
- package/LexicalEditorRefPlugin.js +2 -0
- package/LexicalEditorRefPlugin.js.flow +19 -0
- package/LexicalEditorRefPlugin.mjs +2 -0
- package/LexicalEditorRefPlugin.node.mjs +2 -0
- package/LexicalEditorRefPlugin.prod.js +3 -1
- package/LexicalEditorRefPlugin.prod.mjs +2 -0
- package/LexicalErrorBoundary.d.ts +3 -1
- package/LexicalErrorBoundary.dev.js +30 -10
- package/LexicalErrorBoundary.dev.mjs +13 -7
- package/LexicalErrorBoundary.js +2 -0
- package/LexicalErrorBoundary.js.flow +4 -1
- package/LexicalErrorBoundary.mjs +3 -0
- package/LexicalErrorBoundary.node.mjs +3 -0
- package/LexicalErrorBoundary.prod.js +6 -4
- package/LexicalErrorBoundary.prod.mjs +3 -1
- package/LexicalHashtagPlugin.dev.js +5 -2
- package/LexicalHashtagPlugin.dev.mjs +5 -2
- package/LexicalHashtagPlugin.js +2 -0
- package/LexicalHashtagPlugin.mjs +2 -0
- package/LexicalHashtagPlugin.node.mjs +2 -0
- package/LexicalHashtagPlugin.prod.js +2 -0
- package/LexicalHashtagPlugin.prod.mjs +2 -0
- package/LexicalHistoryPlugin.dev.js +4 -0
- package/LexicalHistoryPlugin.dev.mjs +4 -0
- package/LexicalHistoryPlugin.js +2 -0
- package/LexicalHistoryPlugin.mjs +2 -0
- package/LexicalHistoryPlugin.node.mjs +2 -0
- package/LexicalHistoryPlugin.prod.js +2 -0
- package/LexicalHistoryPlugin.prod.mjs +2 -0
- package/LexicalHorizontalRuleNode.d.ts +2 -2
- package/LexicalHorizontalRuleNode.dev.js +23 -12
- package/LexicalHorizontalRuleNode.dev.mjs +21 -11
- package/LexicalHorizontalRuleNode.js +2 -0
- package/LexicalHorizontalRuleNode.mjs +2 -0
- package/LexicalHorizontalRuleNode.node.mjs +2 -0
- package/LexicalHorizontalRuleNode.prod.js +7 -5
- package/LexicalHorizontalRuleNode.prod.mjs +3 -1
- package/LexicalHorizontalRulePlugin.dev.js +3 -0
- package/LexicalHorizontalRulePlugin.dev.mjs +3 -0
- package/LexicalHorizontalRulePlugin.js +2 -0
- package/LexicalHorizontalRulePlugin.mjs +2 -0
- package/LexicalHorizontalRulePlugin.node.mjs +2 -0
- package/LexicalHorizontalRulePlugin.prod.js +2 -0
- package/LexicalHorizontalRulePlugin.prod.mjs +2 -0
- package/LexicalLinkPlugin.dev.js +6 -3
- package/LexicalLinkPlugin.dev.mjs +7 -4
- package/LexicalLinkPlugin.js +2 -0
- package/LexicalLinkPlugin.mjs +2 -0
- package/LexicalLinkPlugin.node.mjs +2 -0
- package/LexicalLinkPlugin.prod.js +3 -1
- package/LexicalLinkPlugin.prod.mjs +3 -1
- package/LexicalListPlugin.dev.js +4 -0
- package/LexicalListPlugin.dev.mjs +4 -0
- package/LexicalListPlugin.js +2 -0
- package/LexicalListPlugin.mjs +2 -0
- package/LexicalListPlugin.node.mjs +2 -0
- package/LexicalListPlugin.prod.js +2 -0
- package/LexicalListPlugin.prod.mjs +2 -0
- package/LexicalMarkdownShortcutPlugin.dev.js +3 -0
- package/LexicalMarkdownShortcutPlugin.dev.mjs +3 -0
- package/LexicalMarkdownShortcutPlugin.js +2 -0
- package/LexicalMarkdownShortcutPlugin.mjs +2 -0
- package/LexicalMarkdownShortcutPlugin.node.mjs +2 -0
- package/LexicalMarkdownShortcutPlugin.prod.js +2 -0
- package/LexicalMarkdownShortcutPlugin.prod.mjs +2 -0
- package/LexicalNestedComposer.dev.js +14 -9
- package/LexicalNestedComposer.dev.mjs +8 -4
- package/LexicalNestedComposer.js +2 -0
- package/LexicalNestedComposer.mjs +2 -0
- package/LexicalNestedComposer.node.mjs +2 -0
- package/LexicalNestedComposer.prod.js +7 -5
- package/LexicalNestedComposer.prod.mjs +3 -1
- package/LexicalNodeEventPlugin.dev.js +3 -0
- package/LexicalNodeEventPlugin.dev.mjs +3 -0
- package/LexicalNodeEventPlugin.js +2 -0
- package/LexicalNodeEventPlugin.js.flow +12 -0
- package/LexicalNodeEventPlugin.mjs +2 -0
- package/LexicalNodeEventPlugin.node.mjs +2 -0
- package/LexicalNodeEventPlugin.prod.js +2 -0
- package/LexicalNodeEventPlugin.prod.mjs +2 -0
- package/LexicalNodeMenuPlugin.dev.js +30 -8
- package/LexicalNodeMenuPlugin.dev.mjs +17 -8
- package/LexicalNodeMenuPlugin.js +2 -0
- package/LexicalNodeMenuPlugin.mjs +2 -0
- package/LexicalNodeMenuPlugin.node.mjs +2 -0
- package/LexicalNodeMenuPlugin.prod.js +17 -15
- package/LexicalNodeMenuPlugin.prod.mjs +3 -1
- package/LexicalOnChangePlugin.dev.js +9 -2
- package/LexicalOnChangePlugin.dev.mjs +11 -4
- package/LexicalOnChangePlugin.js +2 -0
- package/LexicalOnChangePlugin.mjs +2 -0
- package/LexicalOnChangePlugin.node.mjs +2 -0
- package/LexicalOnChangePlugin.prod.js +3 -1
- package/LexicalOnChangePlugin.prod.mjs +3 -1
- package/LexicalPlainTextPlugin.dev.js +34 -19
- package/LexicalPlainTextPlugin.dev.mjs +31 -17
- package/LexicalPlainTextPlugin.js +2 -0
- package/LexicalPlainTextPlugin.js.flow +1 -1
- package/LexicalPlainTextPlugin.mjs +2 -0
- package/LexicalPlainTextPlugin.node.mjs +2 -0
- package/LexicalPlainTextPlugin.prod.js +6 -4
- package/LexicalPlainTextPlugin.prod.mjs +3 -1
- package/LexicalRichTextPlugin.dev.js +34 -19
- package/LexicalRichTextPlugin.dev.mjs +31 -17
- package/LexicalRichTextPlugin.js +2 -0
- package/LexicalRichTextPlugin.js.flow +1 -1
- package/LexicalRichTextPlugin.mjs +2 -0
- package/LexicalRichTextPlugin.node.mjs +2 -0
- package/LexicalRichTextPlugin.prod.js +6 -4
- package/LexicalRichTextPlugin.prod.mjs +3 -1
- package/LexicalTabIndentationPlugin.dev.js +5 -2
- package/LexicalTabIndentationPlugin.dev.mjs +5 -2
- package/LexicalTabIndentationPlugin.js +2 -0
- package/LexicalTabIndentationPlugin.mjs +2 -0
- package/LexicalTabIndentationPlugin.node.mjs +2 -0
- package/LexicalTabIndentationPlugin.prod.js +2 -0
- package/LexicalTabIndentationPlugin.prod.mjs +2 -0
- package/LexicalTableOfContents.d.ts +6 -13
- package/LexicalTableOfContents.dev.js +57 -10
- package/LexicalTableOfContents.dev.mjs +58 -11
- package/LexicalTableOfContents.js +2 -0
- package/LexicalTableOfContents.js.flow +3 -7
- package/LexicalTableOfContents.mjs +2 -0
- package/LexicalTableOfContents.node.mjs +2 -0
- package/LexicalTableOfContents.prod.js +6 -4
- package/LexicalTableOfContents.prod.mjs +3 -1
- package/LexicalTableOfContentsPlugin.d.ts +20 -0
- package/LexicalTableOfContentsPlugin.dev.js +198 -0
- package/LexicalTableOfContentsPlugin.dev.mjs +196 -0
- package/LexicalTableOfContentsPlugin.js +11 -0
- package/LexicalTableOfContentsPlugin.js.flow +18 -0
- package/LexicalTableOfContentsPlugin.mjs +12 -0
- package/LexicalTableOfContentsPlugin.node.mjs +10 -0
- package/LexicalTableOfContentsPlugin.prod.js +12 -0
- package/LexicalTableOfContentsPlugin.prod.mjs +9 -0
- package/LexicalTablePlugin.dev.js +28 -2
- package/LexicalTablePlugin.dev.mjs +31 -5
- package/LexicalTablePlugin.js +2 -0
- package/LexicalTablePlugin.mjs +2 -0
- package/LexicalTablePlugin.node.mjs +2 -0
- package/LexicalTablePlugin.prod.js +9 -5
- package/LexicalTablePlugin.prod.mjs +3 -1
- package/LexicalTreeView.d.ts +3 -1
- package/LexicalTreeView.dev.js +22 -4
- package/LexicalTreeView.dev.mjs +8 -3
- package/LexicalTreeView.js +2 -0
- package/LexicalTreeView.js.flow +2 -0
- package/LexicalTreeView.mjs +2 -0
- package/LexicalTreeView.node.mjs +2 -0
- package/LexicalTreeView.prod.js +5 -3
- package/LexicalTreeView.prod.mjs +3 -1
- package/LexicalTypeaheadMenuPlugin.dev.js +30 -8
- package/LexicalTypeaheadMenuPlugin.dev.mjs +17 -8
- package/LexicalTypeaheadMenuPlugin.js +2 -0
- package/LexicalTypeaheadMenuPlugin.mjs +2 -0
- package/LexicalTypeaheadMenuPlugin.node.mjs +2 -0
- package/LexicalTypeaheadMenuPlugin.prod.js +21 -19
- package/LexicalTypeaheadMenuPlugin.prod.mjs +3 -1
- package/package.json +50 -20
- package/shared/useCharacterLimit.d.ts +1 -1
- package/useLexicalEditable.d.ts +11 -1
- package/useLexicalEditable.dev.js +22 -3
- package/useLexicalEditable.dev.mjs +23 -5
- package/useLexicalEditable.js +2 -0
- package/useLexicalEditable.js.flow +4 -1
- package/useLexicalEditable.mjs +4 -1
- package/useLexicalEditable.node.mjs +4 -1
- package/useLexicalEditable.prod.js +4 -2
- package/useLexicalEditable.prod.mjs +3 -1
- package/useLexicalIsTextContentEmpty.dev.js +9 -2
- package/useLexicalIsTextContentEmpty.dev.mjs +11 -4
- package/useLexicalIsTextContentEmpty.js +2 -0
- package/useLexicalIsTextContentEmpty.mjs +2 -0
- package/useLexicalIsTextContentEmpty.node.mjs +2 -0
- package/useLexicalIsTextContentEmpty.prod.js +3 -1
- package/useLexicalIsTextContentEmpty.prod.mjs +3 -1
- package/useLexicalNodeSelection.dev.js +3 -0
- package/useLexicalNodeSelection.dev.mjs +4 -1
- package/useLexicalNodeSelection.js +2 -0
- package/useLexicalNodeSelection.mjs +2 -0
- package/useLexicalNodeSelection.node.mjs +2 -0
- package/useLexicalNodeSelection.prod.js +2 -0
- package/useLexicalNodeSelection.prod.mjs +3 -1
- package/useLexicalSubscription.d.ts +4 -1
- package/useLexicalSubscription.dev.js +12 -3
- package/useLexicalSubscription.dev.mjs +13 -5
- package/useLexicalSubscription.js +2 -0
- package/useLexicalSubscription.js.flow +4 -1
- package/useLexicalSubscription.mjs +4 -1
- package/useLexicalSubscription.node.mjs +4 -1
- package/useLexicalSubscription.prod.js +4 -2
- package/useLexicalSubscription.prod.mjs +3 -1
- package/useLexicalTextEntity.dev.js +3 -0
- package/useLexicalTextEntity.dev.mjs +3 -0
- package/useLexicalTextEntity.js +2 -0
- package/useLexicalTextEntity.mjs +2 -0
- package/useLexicalTextEntity.node.mjs +2 -0
- package/useLexicalTextEntity.prod.js +2 -0
- package/useLexicalTextEntity.prod.mjs +2 -0
|
@@ -3,15 +3,18 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict';
|
|
8
10
|
|
|
9
11
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
12
|
var useLexicalEditable = require('@lexical/react/useLexicalEditable');
|
|
11
|
-
var React = require('react');
|
|
12
13
|
var text = require('@lexical/text');
|
|
13
14
|
var utils = require('@lexical/utils');
|
|
15
|
+
var react = require('react');
|
|
14
16
|
var reactDom = require('react-dom');
|
|
17
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
15
18
|
var dragon = require('@lexical/dragon');
|
|
16
19
|
var richText = require('@lexical/rich-text');
|
|
17
20
|
|
|
@@ -32,8 +35,12 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
32
35
|
* LICENSE file in the root directory of this source tree.
|
|
33
36
|
*
|
|
34
37
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
|
|
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;
|
|
37
44
|
|
|
38
45
|
/**
|
|
39
46
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -42,13 +49,14 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
42
49
|
* LICENSE file in the root directory of this source tree.
|
|
43
50
|
*
|
|
44
51
|
*/
|
|
52
|
+
|
|
45
53
|
function canShowPlaceholderFromCurrentEditorState(editor) {
|
|
46
54
|
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
|
|
47
55
|
return currentCanShowPlaceholder;
|
|
48
56
|
}
|
|
49
57
|
function useCanShowPlaceholder(editor) {
|
|
50
|
-
const [canShowPlaceholder, setCanShowPlaceholder] =
|
|
51
|
-
|
|
58
|
+
const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
|
|
59
|
+
useLayoutEffectImpl(() => {
|
|
52
60
|
function resetCanShowPlaceholder() {
|
|
53
61
|
const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
|
|
54
62
|
setCanShowPlaceholder(currentCanShowPlaceholder);
|
|
@@ -70,18 +78,19 @@ function useCanShowPlaceholder(editor) {
|
|
|
70
78
|
* LICENSE file in the root directory of this source tree.
|
|
71
79
|
*
|
|
72
80
|
*/
|
|
81
|
+
|
|
73
82
|
function useDecorators(editor, ErrorBoundary) {
|
|
74
|
-
const [decorators, setDecorators] =
|
|
83
|
+
const [decorators, setDecorators] = react.useState(() => editor.getDecorators());
|
|
75
84
|
|
|
76
85
|
// Subscribe to changes
|
|
77
|
-
|
|
86
|
+
useLayoutEffectImpl(() => {
|
|
78
87
|
return editor.registerDecoratorListener(nextDecorators => {
|
|
79
88
|
reactDom.flushSync(() => {
|
|
80
89
|
setDecorators(nextDecorators);
|
|
81
90
|
});
|
|
82
91
|
});
|
|
83
92
|
}, [editor]);
|
|
84
|
-
|
|
93
|
+
react.useEffect(() => {
|
|
85
94
|
// If the content editable mounts before the subscription is added, then
|
|
86
95
|
// nothing will be rendered on initial pass. We can get around that by
|
|
87
96
|
// ensuring that we set the value.
|
|
@@ -89,16 +98,18 @@ function useDecorators(editor, ErrorBoundary) {
|
|
|
89
98
|
}, [editor]);
|
|
90
99
|
|
|
91
100
|
// Return decorators defined as React Portals
|
|
92
|
-
return
|
|
101
|
+
return react.useMemo(() => {
|
|
93
102
|
const decoratedPortals = [];
|
|
94
103
|
const decoratorKeys = Object.keys(decorators);
|
|
95
104
|
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
96
105
|
const nodeKey = decoratorKeys[i];
|
|
97
|
-
const reactDecorator = /*#__PURE__*/
|
|
98
|
-
onError: e => editor._onError(e)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
const reactDecorator = /*#__PURE__*/jsxRuntime.jsx(ErrorBoundary, {
|
|
107
|
+
onError: e => editor._onError(e),
|
|
108
|
+
children: /*#__PURE__*/jsxRuntime.jsx(react.Suspense, {
|
|
109
|
+
fallback: null,
|
|
110
|
+
children: decorators[nodeKey]
|
|
111
|
+
})
|
|
112
|
+
});
|
|
102
113
|
const element = editor.getElementByKey(nodeKey);
|
|
103
114
|
if (element !== null) {
|
|
104
115
|
decoratedPortals.push( /*#__PURE__*/reactDom.createPortal(reactDecorator, element, nodeKey));
|
|
@@ -115,8 +126,9 @@ function useDecorators(editor, ErrorBoundary) {
|
|
|
115
126
|
* LICENSE file in the root directory of this source tree.
|
|
116
127
|
*
|
|
117
128
|
*/
|
|
129
|
+
|
|
118
130
|
function useRichTextSetup(editor) {
|
|
119
|
-
|
|
131
|
+
useLayoutEffectImpl(() => {
|
|
120
132
|
return utils.mergeRegister(richText.registerRichText(editor), dragon.registerDragonSupport(editor));
|
|
121
133
|
|
|
122
134
|
// We only do this for init
|
|
@@ -131,6 +143,7 @@ function useRichTextSetup(editor) {
|
|
|
131
143
|
* LICENSE file in the root directory of this source tree.
|
|
132
144
|
*
|
|
133
145
|
*/
|
|
146
|
+
|
|
134
147
|
function RichTextPlugin({
|
|
135
148
|
contentEditable,
|
|
136
149
|
placeholder,
|
|
@@ -139,16 +152,18 @@ function RichTextPlugin({
|
|
|
139
152
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
140
153
|
const decorators = useDecorators(editor, ErrorBoundary);
|
|
141
154
|
useRichTextSetup(editor);
|
|
142
|
-
return /*#__PURE__*/
|
|
143
|
-
|
|
144
|
-
|
|
155
|
+
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
156
|
+
children: [contentEditable, /*#__PURE__*/jsxRuntime.jsx(Placeholder, {
|
|
157
|
+
content: placeholder
|
|
158
|
+
}), decorators]
|
|
159
|
+
});
|
|
145
160
|
}
|
|
146
161
|
function Placeholder({
|
|
147
162
|
content
|
|
148
163
|
}) {
|
|
149
164
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
150
165
|
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
151
|
-
const editable = useLexicalEditable();
|
|
166
|
+
const editable = useLexicalEditable.useLexicalEditable();
|
|
152
167
|
if (!showPlaceholder) {
|
|
153
168
|
return null;
|
|
154
169
|
}
|
|
@@ -3,14 +3,16 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
8
|
-
import useLexicalEditable from '@lexical/react/useLexicalEditable';
|
|
9
|
-
import * as React from 'react';
|
|
10
|
-
import { useLayoutEffect as useLayoutEffect$1, useEffect, useState, useMemo, Suspense } from 'react';
|
|
10
|
+
import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
|
|
11
11
|
import { $canShowPlaceholderCurry } from '@lexical/text';
|
|
12
12
|
import { mergeRegister } from '@lexical/utils';
|
|
13
|
-
import {
|
|
13
|
+
import { useLayoutEffect, useEffect, useState, useMemo, Suspense } from 'react';
|
|
14
|
+
import { flushSync, createPortal } from 'react-dom';
|
|
15
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
14
16
|
import { registerDragonSupport } from '@lexical/dragon';
|
|
15
17
|
import { registerRichText } from '@lexical/rich-text';
|
|
16
18
|
|
|
@@ -31,8 +33,12 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
31
33
|
* LICENSE file in the root directory of this source tree.
|
|
32
34
|
*
|
|
33
35
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// This workaround is no longer necessary in React 19,
|
|
39
|
+
// but we currently support React >=17.x
|
|
40
|
+
// https://github.com/facebook/react/pull/26395
|
|
41
|
+
const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
|
|
36
42
|
|
|
37
43
|
/**
|
|
38
44
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -41,13 +47,14 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
41
47
|
* LICENSE file in the root directory of this source tree.
|
|
42
48
|
*
|
|
43
49
|
*/
|
|
50
|
+
|
|
44
51
|
function canShowPlaceholderFromCurrentEditorState(editor) {
|
|
45
52
|
const currentCanShowPlaceholder = editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing()));
|
|
46
53
|
return currentCanShowPlaceholder;
|
|
47
54
|
}
|
|
48
55
|
function useCanShowPlaceholder(editor) {
|
|
49
56
|
const [canShowPlaceholder, setCanShowPlaceholder] = useState(() => canShowPlaceholderFromCurrentEditorState(editor));
|
|
50
|
-
|
|
57
|
+
useLayoutEffectImpl(() => {
|
|
51
58
|
function resetCanShowPlaceholder() {
|
|
52
59
|
const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
|
|
53
60
|
setCanShowPlaceholder(currentCanShowPlaceholder);
|
|
@@ -69,11 +76,12 @@ function useCanShowPlaceholder(editor) {
|
|
|
69
76
|
* LICENSE file in the root directory of this source tree.
|
|
70
77
|
*
|
|
71
78
|
*/
|
|
79
|
+
|
|
72
80
|
function useDecorators(editor, ErrorBoundary) {
|
|
73
81
|
const [decorators, setDecorators] = useState(() => editor.getDecorators());
|
|
74
82
|
|
|
75
83
|
// Subscribe to changes
|
|
76
|
-
|
|
84
|
+
useLayoutEffectImpl(() => {
|
|
77
85
|
return editor.registerDecoratorListener(nextDecorators => {
|
|
78
86
|
flushSync(() => {
|
|
79
87
|
setDecorators(nextDecorators);
|
|
@@ -93,11 +101,13 @@ function useDecorators(editor, ErrorBoundary) {
|
|
|
93
101
|
const decoratorKeys = Object.keys(decorators);
|
|
94
102
|
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
95
103
|
const nodeKey = decoratorKeys[i];
|
|
96
|
-
const reactDecorator = /*#__PURE__*/
|
|
97
|
-
onError: e => editor._onError(e)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
const reactDecorator = /*#__PURE__*/jsx(ErrorBoundary, {
|
|
105
|
+
onError: e => editor._onError(e),
|
|
106
|
+
children: /*#__PURE__*/jsx(Suspense, {
|
|
107
|
+
fallback: null,
|
|
108
|
+
children: decorators[nodeKey]
|
|
109
|
+
})
|
|
110
|
+
});
|
|
101
111
|
const element = editor.getElementByKey(nodeKey);
|
|
102
112
|
if (element !== null) {
|
|
103
113
|
decoratedPortals.push( /*#__PURE__*/createPortal(reactDecorator, element, nodeKey));
|
|
@@ -114,8 +124,9 @@ function useDecorators(editor, ErrorBoundary) {
|
|
|
114
124
|
* LICENSE file in the root directory of this source tree.
|
|
115
125
|
*
|
|
116
126
|
*/
|
|
127
|
+
|
|
117
128
|
function useRichTextSetup(editor) {
|
|
118
|
-
|
|
129
|
+
useLayoutEffectImpl(() => {
|
|
119
130
|
return mergeRegister(registerRichText(editor), registerDragonSupport(editor));
|
|
120
131
|
|
|
121
132
|
// We only do this for init
|
|
@@ -130,6 +141,7 @@ function useRichTextSetup(editor) {
|
|
|
130
141
|
* LICENSE file in the root directory of this source tree.
|
|
131
142
|
*
|
|
132
143
|
*/
|
|
144
|
+
|
|
133
145
|
function RichTextPlugin({
|
|
134
146
|
contentEditable,
|
|
135
147
|
placeholder,
|
|
@@ -138,9 +150,11 @@ function RichTextPlugin({
|
|
|
138
150
|
const [editor] = useLexicalComposerContext();
|
|
139
151
|
const decorators = useDecorators(editor, ErrorBoundary);
|
|
140
152
|
useRichTextSetup(editor);
|
|
141
|
-
return /*#__PURE__*/
|
|
142
|
-
|
|
143
|
-
|
|
153
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
154
|
+
children: [contentEditable, /*#__PURE__*/jsx(Placeholder, {
|
|
155
|
+
content: placeholder
|
|
156
|
+
}), decorators]
|
|
157
|
+
});
|
|
144
158
|
}
|
|
145
159
|
function Placeholder({
|
|
146
160
|
content
|
package/LexicalRichTextPlugin.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict'
|
|
8
10
|
const LexicalRichTextPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalRichTextPlugin.dev.js') : require('./LexicalRichTextPlugin.prod.js');
|
|
9
11
|
module.exports = LexicalRichTextPlugin;
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import type {EditorState, LexicalEditor} from 'lexical';
|
|
11
11
|
|
|
12
|
-
import typeof LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
|
|
12
|
+
import {typeof LexicalErrorBoundary} from '@lexical/react/LexicalErrorBoundary';
|
|
13
13
|
|
|
14
14
|
import * as React from 'react';
|
|
15
15
|
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
import * as modDev from './LexicalRichTextPlugin.dev.mjs';
|
|
8
10
|
import * as modProd from './LexicalRichTextPlugin.prod.mjs';
|
|
9
11
|
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalRichTextPlugin.dev.mjs') : import('./LexicalRichTextPlugin.prod.mjs'));
|
|
8
10
|
export const RichTextPlugin = mod.RichTextPlugin;
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
function
|
|
8
|
+
|
|
9
|
+
'use strict';var e=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/react/useLexicalEditable"),h=require("@lexical/text"),m=require("@lexical/utils"),n=require("react"),p=require("react-dom"),q=require("react/jsx-runtime"),u=require("@lexical/dragon"),v=require("@lexical/rich-text");let w="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?n.useLayoutEffect:n.useEffect;
|
|
10
|
+
function x(a){return a.getEditorState().read(h.$canShowPlaceholderCurry(a.isComposing()))}function y(a){let [c,b]=n.useState(()=>x(a));w(()=>{function d(){let f=x(a);b(f)}d();return m.mergeRegister(a.registerUpdateListener(()=>{d()}),a.registerEditableListener(()=>{d()}))},[a]);return c}
|
|
11
|
+
function z(a,c){let [b,d]=n.useState(()=>a.getDecorators());w(()=>a.registerDecoratorListener(f=>{p.flushSync(()=>{d(f)})}),[a]);n.useEffect(()=>{d(a.getDecorators())},[a]);return n.useMemo(()=>{let f=[],r=Object.keys(b);for(let k=0;k<r.length;k++){let l=r[k],B=q.jsx(c,{onError:A=>a._onError(A),children:q.jsx(n.Suspense,{fallback:null,children:b[l]})}),t=a.getElementByKey(l);null!==t&&f.push(p.createPortal(B,t,l))}return f},[c,b,a])}
|
|
12
|
+
function C(a){w(()=>m.mergeRegister(v.registerRichText(a),u.registerDragonSupport(a)),[a])}function D({content:a}){var [c]=e.useLexicalComposerContext();c=y(c);let b=g.useLexicalEditable();return c?"function"===typeof a?a(b):a:null}exports.RichTextPlugin=function({contentEditable:a,placeholder:c,ErrorBoundary:b}){let [d]=e.useLexicalComposerContext();b=z(d,b);C(d);return q.jsxs(q.Fragment,{children:[a,q.jsx(D,{content:c}),b]})}
|
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as e}from"@lexical/react/useLexicalEditable";import{$canShowPlaceholderCurry as r}from"@lexical/text";import{mergeRegister as o}from"@lexical/utils";import{useLayoutEffect as n,useEffect as i,useState as c,useMemo as l,Suspense as a}from"react";import{flushSync as m,createPortal as u}from"react-dom";import{jsx as s,jsxs as d,Fragment as f}from"react/jsx-runtime";import{registerDragonSupport as p}from"@lexical/dragon";import{registerRichText as x}from"@lexical/rich-text";const g="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?n:i;function E(t){return t.getEditorState().read(r(t.isComposing()))}function h({contentEditable:e,placeholder:r,ErrorBoundary:n}){const[E]=t(),h=function(t,e){const[r,o]=c((()=>t.getDecorators()));return g((()=>t.registerDecoratorListener((t=>{m((()=>{o(t)}))}))),[t]),i((()=>{o(t.getDecorators())}),[t]),l((()=>{const o=[],n=Object.keys(r);for(let i=0;i<n.length;i++){const c=n[i],l=s(e,{onError:e=>t._onError(e),children:s(a,{fallback:null,children:r[c]})}),m=t.getElementByKey(c);null!==m&&o.push(u(l,m,c))}return o}),[e,r,t])}(E,n);return function(t){g((()=>o(x(t),p(t))),[t])}(E),d(f,{children:[e,s(w,{content:r}),h]})}function w({content:r}){const[n]=t(),i=function(t){const[e,r]=c((()=>E(t)));return g((()=>{function e(){const e=E(t);r(e)}return e(),o(t.registerUpdateListener((()=>{e()})),t.registerEditableListener((()=>{e()})))}),[t]),e}(n),l=e();return i?"function"==typeof r?r(l):r:null}export{h as RichTextPlugin};
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict';
|
|
8
10
|
|
|
9
11
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
@@ -18,7 +20,8 @@ var react = require('react');
|
|
|
18
20
|
* LICENSE file in the root directory of this source tree.
|
|
19
21
|
*
|
|
20
22
|
*/
|
|
21
|
-
|
|
23
|
+
|
|
24
|
+
function $indentOverTab(selection) {
|
|
22
25
|
// const handled = new Set();
|
|
23
26
|
const nodes = selection.getNodes();
|
|
24
27
|
const canIndentBlockNodes = utils.$filter(nodes, node => {
|
|
@@ -57,7 +60,7 @@ function registerTabIndentation(editor) {
|
|
|
57
60
|
return false;
|
|
58
61
|
}
|
|
59
62
|
event.preventDefault();
|
|
60
|
-
const command = indentOverTab(selection) ? event.shiftKey ? lexical.OUTDENT_CONTENT_COMMAND : lexical.INDENT_CONTENT_COMMAND : lexical.INSERT_TAB_COMMAND;
|
|
63
|
+
const command = $indentOverTab(selection) ? event.shiftKey ? lexical.OUTDENT_CONTENT_COMMAND : lexical.INDENT_CONTENT_COMMAND : lexical.INSERT_TAB_COMMAND;
|
|
61
64
|
return editor.dispatchCommand(command, undefined);
|
|
62
65
|
}, lexical.COMMAND_PRIORITY_EDITOR);
|
|
63
66
|
}
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
8
10
|
import { $filter, $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
|
|
9
11
|
import { KEY_TAB_COMMAND, $getSelection, $isRangeSelection, OUTDENT_CONTENT_COMMAND, INDENT_CONTENT_COMMAND, INSERT_TAB_COMMAND, COMMAND_PRIORITY_EDITOR, $isBlockElementNode, $createRangeSelection, $normalizeSelection__EXPERIMENTAL } from 'lexical';
|
|
@@ -16,7 +18,8 @@ import { useEffect } from 'react';
|
|
|
16
18
|
* LICENSE file in the root directory of this source tree.
|
|
17
19
|
*
|
|
18
20
|
*/
|
|
19
|
-
|
|
21
|
+
|
|
22
|
+
function $indentOverTab(selection) {
|
|
20
23
|
// const handled = new Set();
|
|
21
24
|
const nodes = selection.getNodes();
|
|
22
25
|
const canIndentBlockNodes = $filter(nodes, node => {
|
|
@@ -55,7 +58,7 @@ function registerTabIndentation(editor) {
|
|
|
55
58
|
return false;
|
|
56
59
|
}
|
|
57
60
|
event.preventDefault();
|
|
58
|
-
const command = indentOverTab(selection) ? event.shiftKey ? OUTDENT_CONTENT_COMMAND : INDENT_CONTENT_COMMAND : INSERT_TAB_COMMAND;
|
|
61
|
+
const command = $indentOverTab(selection) ? event.shiftKey ? OUTDENT_CONTENT_COMMAND : INDENT_CONTENT_COMMAND : INSERT_TAB_COMMAND;
|
|
59
62
|
return editor.dispatchCommand(command, undefined);
|
|
60
63
|
}, COMMAND_PRIORITY_EDITOR);
|
|
61
64
|
}
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict'
|
|
8
10
|
const LexicalTabIndentationPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalTabIndentationPlugin.dev.js') : require('./LexicalTabIndentationPlugin.prod.js');
|
|
9
11
|
module.exports = LexicalTabIndentationPlugin;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
import * as modDev from './LexicalTabIndentationPlugin.dev.mjs';
|
|
8
10
|
import * as modProd from './LexicalTabIndentationPlugin.prod.mjs';
|
|
9
11
|
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalTabIndentationPlugin.dev.mjs') : import('./LexicalTabIndentationPlugin.prod.mjs'));
|
|
8
10
|
export const TabIndentationPlugin = mod.TabIndentationPlugin;
|
|
9
11
|
export const registerTabIndentation = mod.registerTabIndentation;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict';var d=require("@lexical/react/LexicalComposerContext"),e=require("@lexical/utils"),f=require("lexical"),g=require("react");
|
|
8
10
|
function h(b){var a=b.getNodes();if(0<e.$filter(a,c=>f.$isBlockElementNode(c)&&c.canIndent()?c:null).length)return!0;a=b.anchor;b=b.focus;b=b.isBefore(a)?b:a;a=b.getNode();a=e.$getNearestBlockElementAncestorOrThrow(a);if(a.canIndent()){a=a.getKey();let c=f.$createRangeSelection();c.anchor.set(a,0,"element");c.focus.set(a,0,"element");c=f.$normalizeSelection__EXPERIMENTAL(c);if(c.anchor.is(b))return!0}return!1}
|
|
9
11
|
function k(b){return b.registerCommand(f.KEY_TAB_COMMAND,a=>{let c=f.$getSelection();if(!f.$isRangeSelection(c))return!1;a.preventDefault();a=h(c)?a.shiftKey?f.OUTDENT_CONTENT_COMMAND:f.INDENT_CONTENT_COMMAND:f.INSERT_TAB_COMMAND;return b.dispatchCommand(a,void 0)},f.COMMAND_PRIORITY_EDITOR)}exports.TabIndentationPlugin=function(){let [b]=d.useLexicalComposerContext();g.useEffect(()=>k(b));return null};exports.registerTabIndentation=k
|
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{$filter as t,$getNearestBlockElementAncestorOrThrow as n}from"@lexical/utils";import{KEY_TAB_COMMAND as r,$getSelection as o,$isRangeSelection as c,OUTDENT_CONTENT_COMMAND as i,INDENT_CONTENT_COMMAND as s,INSERT_TAB_COMMAND as l,COMMAND_PRIORITY_EDITOR as f,$isBlockElementNode as u,$createRangeSelection as a,$normalizeSelection__EXPERIMENTAL as m}from"lexical";import{useEffect as d}from"react";function p(e){return e.registerCommand(r,(r=>{const f=o();if(!c(f))return!1;r.preventDefault();const d=function(e){const r=e.getNodes();if(t(r,(e=>u(e)&&e.canIndent()?e:null)).length>0)return!0;const o=e.anchor,c=e.focus,i=c.isBefore(o)?c:o,s=i.getNode(),l=n(s);if(l.canIndent()){const e=l.getKey();let t=a();if(t.anchor.set(e,0,"element"),t.focus.set(e,0,"element"),t=m(t),t.anchor.is(i))return!0}return!1}(f)?r.shiftKey?i:s:l;return e.dispatchCommand(d,void 0)}),f)}function h(){const[t]=e();return d((()=>p(t))),null}export{h as TabIndentationPlugin,p as registerTabIndentation};
|
|
@@ -5,16 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
import type
|
|
10
|
-
|
|
11
|
-
export type TableOfContentsEntry
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
tag: HeadingTagType
|
|
15
|
-
];
|
|
16
|
-
type Props = {
|
|
17
|
-
children: (values: Array<TableOfContentsEntry>, editor: LexicalEditor) => JSX.Element;
|
|
18
|
-
};
|
|
19
|
-
export default function LexicalTableOfContentsPlugin({ children, }: Props): JSX.Element;
|
|
20
|
-
export {};
|
|
8
|
+
/** @deprecated moved to @lexical/react/LexicalTableOfContentsPlugin */
|
|
9
|
+
import { type TableOfContentsEntry, TableOfContentsPlugin } from './LexicalTableOfContentsPlugin';
|
|
10
|
+
/** @deprecated use the module @lexical/react/LexicalTableOfContentsPlugin */
|
|
11
|
+
export { type TableOfContentsEntry };
|
|
12
|
+
/** @deprecated use module @lexical/react/LexicalTableOfContentsPlugin */
|
|
13
|
+
export default TableOfContentsPlugin;
|
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict';
|
|
8
10
|
|
|
9
11
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
12
|
var richText = require('@lexical/rich-text');
|
|
13
|
+
var utils = require('@lexical/utils');
|
|
11
14
|
var lexical = require('lexical');
|
|
12
15
|
var react = require('react');
|
|
13
16
|
|
|
@@ -18,6 +21,7 @@ var react = require('react');
|
|
|
18
21
|
* LICENSE file in the root directory of this source tree.
|
|
19
22
|
*
|
|
20
23
|
*/
|
|
24
|
+
|
|
21
25
|
function toEntry(heading) {
|
|
22
26
|
return [heading.getKey(), heading.getTextContent(), heading.getTag()];
|
|
23
27
|
}
|
|
@@ -28,12 +32,20 @@ function $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTable
|
|
|
28
32
|
const newEntry = toEntry(newHeading);
|
|
29
33
|
let newTableOfContents = [];
|
|
30
34
|
if (prevHeading === null) {
|
|
35
|
+
// check if key already exists
|
|
36
|
+
if (currentTableOfContents.length > 0 && currentTableOfContents[0][0] === newHeading.__key) {
|
|
37
|
+
return currentTableOfContents;
|
|
38
|
+
}
|
|
31
39
|
newTableOfContents = [newEntry, ...currentTableOfContents];
|
|
32
40
|
} else {
|
|
33
41
|
for (let i = 0; i < currentTableOfContents.length; i++) {
|
|
34
42
|
const key = currentTableOfContents[i][0];
|
|
35
43
|
newTableOfContents.push(currentTableOfContents[i]);
|
|
36
44
|
if (key === prevHeading.getKey() && key !== newHeading.getKey()) {
|
|
45
|
+
// check if key already exists
|
|
46
|
+
if (i + 1 < currentTableOfContents.length && currentTableOfContents[i + 1][0] === newHeading.__key) {
|
|
47
|
+
return currentTableOfContents;
|
|
48
|
+
}
|
|
37
49
|
newTableOfContents.push(newEntry);
|
|
38
50
|
}
|
|
39
51
|
}
|
|
@@ -82,7 +94,14 @@ function $updateHeadingPosition(prevHeading, heading, currentTableOfContents) {
|
|
|
82
94
|
}
|
|
83
95
|
return newTableOfContents;
|
|
84
96
|
}
|
|
85
|
-
function
|
|
97
|
+
function $getPreviousHeading(node) {
|
|
98
|
+
let prevHeading = utils.$getNextRightPreorderNode(node);
|
|
99
|
+
while (prevHeading !== null && !richText.$isHeadingNode(prevHeading)) {
|
|
100
|
+
prevHeading = utils.$getNextRightPreorderNode(prevHeading);
|
|
101
|
+
}
|
|
102
|
+
return prevHeading;
|
|
103
|
+
}
|
|
104
|
+
function TableOfContentsPlugin({
|
|
86
105
|
children
|
|
87
106
|
}) {
|
|
88
107
|
const [tableOfContents, setTableOfContents] = react.useState([]);
|
|
@@ -100,6 +119,31 @@ function LexicalTableOfContentsPlugin({
|
|
|
100
119
|
}
|
|
101
120
|
setTableOfContents(currentTableOfContents);
|
|
102
121
|
});
|
|
122
|
+
const removeRootUpdateListener = editor.registerUpdateListener(({
|
|
123
|
+
editorState,
|
|
124
|
+
dirtyElements
|
|
125
|
+
}) => {
|
|
126
|
+
editorState.read(() => {
|
|
127
|
+
const updateChildHeadings = node => {
|
|
128
|
+
for (const child of node.getChildren()) {
|
|
129
|
+
if (richText.$isHeadingNode(child)) {
|
|
130
|
+
const prevHeading = $getPreviousHeading(child);
|
|
131
|
+
currentTableOfContents = $updateHeadingPosition(prevHeading, child, currentTableOfContents);
|
|
132
|
+
setTableOfContents(currentTableOfContents);
|
|
133
|
+
} else if (lexical.$isElementNode(child)) {
|
|
134
|
+
updateChildHeadings(child);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// If a node is changes, all child heading positions need to be updated
|
|
140
|
+
lexical.$getRoot().getChildren().forEach(node => {
|
|
141
|
+
if (lexical.$isElementNode(node) && dirtyElements.get(node.__key)) {
|
|
142
|
+
updateChildHeadings(node);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
103
147
|
|
|
104
148
|
// Listen to updates to heading mutations and update state
|
|
105
149
|
const removeHeaderMutationListener = editor.registerMutationListener(richText.HeadingNode, mutatedNodes => {
|
|
@@ -108,10 +152,7 @@ function LexicalTableOfContentsPlugin({
|
|
|
108
152
|
if (mutation === 'created') {
|
|
109
153
|
const newHeading = lexical.$getNodeByKey(nodeKey);
|
|
110
154
|
if (newHeading !== null) {
|
|
111
|
-
|
|
112
|
-
while (prevHeading !== null && !richText.$isHeadingNode(prevHeading)) {
|
|
113
|
-
prevHeading = prevHeading.getPreviousSibling();
|
|
114
|
-
}
|
|
155
|
+
const prevHeading = $getPreviousHeading(newHeading);
|
|
115
156
|
currentTableOfContents = $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents);
|
|
116
157
|
}
|
|
117
158
|
} else if (mutation === 'destroyed') {
|
|
@@ -119,10 +160,7 @@ function LexicalTableOfContentsPlugin({
|
|
|
119
160
|
} else if (mutation === 'updated') {
|
|
120
161
|
const newHeading = lexical.$getNodeByKey(nodeKey);
|
|
121
162
|
if (newHeading !== null) {
|
|
122
|
-
|
|
123
|
-
while (prevHeading !== null && !richText.$isHeadingNode(prevHeading)) {
|
|
124
|
-
prevHeading = prevHeading.getPreviousSibling();
|
|
125
|
-
}
|
|
163
|
+
const prevHeading = $getPreviousHeading(newHeading);
|
|
126
164
|
currentTableOfContents = $updateHeadingPosition(prevHeading, newHeading, currentTableOfContents);
|
|
127
165
|
}
|
|
128
166
|
}
|
|
@@ -151,9 +189,18 @@ function LexicalTableOfContentsPlugin({
|
|
|
151
189
|
return () => {
|
|
152
190
|
removeHeaderMutationListener();
|
|
153
191
|
removeTextNodeMutationListener();
|
|
192
|
+
removeRootUpdateListener();
|
|
154
193
|
};
|
|
155
194
|
}, [editor]);
|
|
156
195
|
return children(tableOfContents, editor);
|
|
157
196
|
}
|
|
158
197
|
|
|
159
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
200
|
+
*
|
|
201
|
+
* This source code is licensed under the MIT license found in the
|
|
202
|
+
* LICENSE file in the root directory of this source tree.
|
|
203
|
+
*
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
exports.default = TableOfContentsPlugin;
|