@lexical/react 0.13.1 → 0.14.1
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.esm.js +131 -0
- package/LexicalAutoEmbedPlugin.esm.js +13 -0
- package/LexicalAutoEmbedPlugin.js +1 -1
- package/LexicalAutoEmbedPlugin.prod.esm.js +7 -0
- package/LexicalAutoFocusPlugin.dev.esm.js +42 -0
- package/LexicalAutoFocusPlugin.esm.js +10 -0
- package/LexicalAutoFocusPlugin.js +1 -1
- package/LexicalAutoFocusPlugin.prod.esm.js +7 -0
- package/LexicalAutoLinkPlugin.dev.esm.js +312 -0
- package/LexicalAutoLinkPlugin.dev.js +3 -1
- package/LexicalAutoLinkPlugin.esm.js +11 -0
- package/LexicalAutoLinkPlugin.js +1 -1
- package/LexicalAutoLinkPlugin.prod.esm.js +7 -0
- package/LexicalBlockWithAlignableContents.dev.esm.js +86 -0
- package/LexicalBlockWithAlignableContents.dev.js +1 -0
- package/LexicalBlockWithAlignableContents.esm.js +10 -0
- package/LexicalBlockWithAlignableContents.js +1 -1
- package/LexicalBlockWithAlignableContents.prod.esm.js +7 -0
- package/LexicalBlockWithAlignableContents.prod.js +1 -1
- package/LexicalCharacterLimitPlugin.d.ts +4 -1
- package/LexicalCharacterLimitPlugin.dev.esm.js +272 -0
- package/LexicalCharacterLimitPlugin.dev.js +12 -4
- package/LexicalCharacterLimitPlugin.esm.js +10 -0
- package/LexicalCharacterLimitPlugin.js +1 -1
- package/LexicalCharacterLimitPlugin.prod.esm.js +7 -0
- package/LexicalCharacterLimitPlugin.prod.js +9 -9
- package/LexicalCheckListPlugin.dev.esm.js +203 -0
- package/LexicalCheckListPlugin.esm.js +10 -0
- package/LexicalCheckListPlugin.js +1 -1
- package/LexicalCheckListPlugin.prod.esm.js +7 -0
- package/LexicalClearEditorPlugin.dev.esm.js +64 -0
- package/LexicalClearEditorPlugin.esm.js +10 -0
- package/LexicalClearEditorPlugin.js +1 -1
- package/LexicalClearEditorPlugin.prod.esm.js +7 -0
- package/LexicalClickableLinkPlugin.dev.esm.js +95 -0
- package/LexicalClickableLinkPlugin.esm.js +10 -0
- package/LexicalClickableLinkPlugin.js +1 -1
- package/LexicalClickableLinkPlugin.prod.esm.js +7 -0
- package/LexicalCollaborationContext.dev.esm.js +36 -0
- package/LexicalCollaborationContext.esm.js +11 -0
- package/LexicalCollaborationContext.js +1 -1
- package/LexicalCollaborationContext.prod.esm.js +7 -0
- package/LexicalCollaborationPlugin.dev.esm.js +308 -0
- package/LexicalCollaborationPlugin.esm.js +10 -0
- package/LexicalCollaborationPlugin.js +1 -1
- package/LexicalCollaborationPlugin.prod.esm.js +7 -0
- package/LexicalComposer.dev.esm.js +129 -0
- package/LexicalComposer.esm.js +10 -0
- package/LexicalComposer.js +1 -1
- package/LexicalComposer.prod.esm.js +7 -0
- package/LexicalComposerContext.dev.esm.js +42 -0
- package/LexicalComposerContext.esm.js +12 -0
- package/LexicalComposerContext.js +1 -1
- package/LexicalComposerContext.prod.esm.js +7 -0
- package/LexicalContentEditable.dev.esm.js +107 -0
- package/LexicalContentEditable.dev.js +5 -1
- package/LexicalContentEditable.esm.js +10 -0
- package/LexicalContentEditable.js +1 -1
- package/LexicalContentEditable.prod.esm.js +7 -0
- package/LexicalContentEditable.prod.js +3 -3
- package/LexicalContextMenuPlugin.dev.esm.js +455 -0
- package/LexicalContextMenuPlugin.dev.js +3 -1
- package/LexicalContextMenuPlugin.esm.js +11 -0
- package/LexicalContextMenuPlugin.js +1 -1
- package/LexicalContextMenuPlugin.prod.esm.js +7 -0
- package/LexicalDecoratorBlockNode.dev.esm.js +46 -0
- package/LexicalDecoratorBlockNode.esm.js +11 -0
- package/LexicalDecoratorBlockNode.js +1 -1
- package/LexicalDecoratorBlockNode.prod.esm.js +7 -0
- package/LexicalEditorRefPlugin.dev.esm.js +40 -0
- package/LexicalEditorRefPlugin.dev.js +10 -5
- package/LexicalEditorRefPlugin.esm.js +10 -0
- package/LexicalEditorRefPlugin.js +1 -1
- package/LexicalEditorRefPlugin.prod.esm.js +7 -0
- package/LexicalEditorRefPlugin.prod.js +1 -1
- package/LexicalErrorBoundary.dev.esm.js +157 -0
- package/LexicalErrorBoundary.esm.js +10 -0
- package/LexicalErrorBoundary.js +1 -1
- package/LexicalErrorBoundary.prod.esm.js +7 -0
- package/LexicalHashtagPlugin.dev.esm.js +163 -0
- package/LexicalHashtagPlugin.esm.js +10 -0
- package/LexicalHashtagPlugin.js +1 -1
- package/LexicalHashtagPlugin.prod.esm.js +7 -0
- package/LexicalHistoryPlugin.dev.esm.js +41 -0
- package/LexicalHistoryPlugin.esm.js +11 -0
- package/LexicalHistoryPlugin.js +1 -1
- package/LexicalHistoryPlugin.prod.esm.js +7 -0
- package/LexicalHorizontalRuleNode.dev.esm.js +118 -0
- package/LexicalHorizontalRuleNode.dev.js +1 -0
- package/LexicalHorizontalRuleNode.esm.js +13 -0
- package/LexicalHorizontalRuleNode.js +1 -1
- package/LexicalHorizontalRuleNode.prod.esm.js +7 -0
- package/LexicalHorizontalRuleNode.prod.js +1 -1
- package/LexicalHorizontalRulePlugin.dev.esm.js +39 -0
- package/LexicalHorizontalRulePlugin.esm.js +10 -0
- package/LexicalHorizontalRulePlugin.js +1 -1
- package/LexicalHorizontalRulePlugin.prod.esm.js +7 -0
- package/LexicalLinkPlugin.dev.esm.js +79 -0
- package/LexicalLinkPlugin.dev.js +6 -2
- package/LexicalLinkPlugin.esm.js +10 -0
- package/LexicalLinkPlugin.js +1 -1
- package/LexicalLinkPlugin.prod.esm.js +7 -0
- package/LexicalLinkPlugin.prod.js +1 -1
- package/LexicalListPlugin.dev.esm.js +59 -0
- package/LexicalListPlugin.esm.js +10 -0
- package/LexicalListPlugin.js +1 -1
- package/LexicalListPlugin.prod.esm.js +7 -0
- package/LexicalMarkdownShortcutPlugin.dev.esm.js +49 -0
- package/LexicalMarkdownShortcutPlugin.esm.js +11 -0
- package/LexicalMarkdownShortcutPlugin.js +1 -1
- package/LexicalMarkdownShortcutPlugin.prod.esm.js +7 -0
- package/LexicalNestedComposer.dev.esm.js +105 -0
- package/LexicalNestedComposer.esm.js +10 -0
- package/LexicalNestedComposer.js +1 -1
- package/LexicalNestedComposer.prod.esm.js +7 -0
- package/LexicalNodeEventPlugin.dev.esm.js +56 -0
- package/LexicalNodeEventPlugin.esm.js +10 -0
- package/LexicalNodeEventPlugin.js +1 -1
- package/LexicalNodeEventPlugin.prod.esm.js +7 -0
- package/LexicalNodeMenuPlugin.dev.esm.js +466 -0
- package/LexicalNodeMenuPlugin.dev.js +3 -1
- package/LexicalNodeMenuPlugin.esm.js +11 -0
- package/LexicalNodeMenuPlugin.js +1 -1
- package/LexicalNodeMenuPlugin.prod.esm.js +7 -0
- package/LexicalOnChangePlugin.dev.esm.js +62 -0
- package/LexicalOnChangePlugin.esm.js +10 -0
- package/LexicalOnChangePlugin.js +1 -1
- package/LexicalOnChangePlugin.prod.esm.js +7 -0
- package/LexicalPlainTextPlugin.dev.esm.js +161 -0
- package/LexicalPlainTextPlugin.esm.js +10 -0
- package/LexicalPlainTextPlugin.js +1 -1
- package/LexicalPlainTextPlugin.prod.esm.js +7 -0
- package/LexicalRichTextPlugin.dev.esm.js +161 -0
- package/LexicalRichTextPlugin.esm.js +10 -0
- package/LexicalRichTextPlugin.js +1 -1
- package/LexicalRichTextPlugin.prod.esm.js +7 -0
- package/LexicalTabIndentationPlugin.dev.esm.js +76 -0
- package/LexicalTabIndentationPlugin.esm.js +11 -0
- package/LexicalTabIndentationPlugin.js +1 -1
- package/LexicalTabIndentationPlugin.prod.esm.js +7 -0
- package/LexicalTableOfContents.dev.esm.js +157 -0
- package/LexicalTableOfContents.esm.js +10 -0
- package/LexicalTableOfContents.js +1 -1
- package/LexicalTableOfContents.prod.esm.js +7 -0
- package/LexicalTablePlugin.dev.esm.js +163 -0
- package/LexicalTablePlugin.esm.js +10 -0
- package/LexicalTablePlugin.js +1 -1
- package/LexicalTablePlugin.prod.esm.js +7 -0
- package/LexicalTreeView.dev.esm.js +483 -0
- package/LexicalTreeView.dev.js +3 -1
- package/LexicalTreeView.esm.js +10 -0
- package/LexicalTreeView.js +1 -1
- package/LexicalTreeView.prod.esm.js +7 -0
- package/LexicalTypeaheadMenuPlugin.dev.esm.js +569 -0
- package/LexicalTypeaheadMenuPlugin.dev.js +3 -1
- package/LexicalTypeaheadMenuPlugin.esm.js +16 -0
- package/LexicalTypeaheadMenuPlugin.js +1 -1
- package/LexicalTypeaheadMenuPlugin.prod.esm.js +7 -0
- package/package.json +583 -20
- package/useLexicalEditable.dev.esm.js +82 -0
- package/useLexicalEditable.esm.js +10 -0
- package/useLexicalEditable.js +1 -1
- package/useLexicalEditable.prod.esm.js +7 -0
- package/useLexicalIsTextContentEmpty.dev.esm.js +51 -0
- package/useLexicalIsTextContentEmpty.esm.js +10 -0
- package/useLexicalIsTextContentEmpty.js +1 -1
- package/useLexicalIsTextContentEmpty.prod.esm.js +7 -0
- package/useLexicalNodeSelection.dev.esm.js +69 -0
- package/useLexicalNodeSelection.esm.js +10 -0
- package/useLexicalNodeSelection.js +1 -1
- package/useLexicalNodeSelection.prod.esm.js +7 -0
- package/useLexicalSubscription.dev.esm.js +63 -0
- package/useLexicalSubscription.esm.js +10 -0
- package/useLexicalSubscription.js +1 -1
- package/useLexicalSubscription.prod.esm.js +7 -0
- package/useLexicalTextEntity.dev.esm.js +26 -0
- package/useLexicalTextEntity.esm.js +10 -0
- package/useLexicalTextEntity.js +1 -1
- package/useLexicalTextEntity.prod.esm.js +7 -0
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
8
|
+
import { useLayoutEffect as useLayoutEffect$1, useEffect } from 'react';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
12
|
+
*
|
|
13
|
+
* This source code is licensed under the MIT license found in the
|
|
14
|
+
* LICENSE file in the root directory of this source tree.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
22
|
+
*
|
|
23
|
+
* This source code is licensed under the MIT license found in the
|
|
24
|
+
* LICENSE file in the root directory of this source tree.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect$1 : useEffect;
|
|
28
|
+
var useLayoutEffect = useLayoutEffectImpl;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
32
|
+
*
|
|
33
|
+
* This source code is licensed under the MIT license found in the
|
|
34
|
+
* LICENSE file in the root directory of this source tree.
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
function OnChangePlugin({
|
|
38
|
+
ignoreHistoryMergeTagChange = true,
|
|
39
|
+
ignoreSelectionChange = false,
|
|
40
|
+
onChange
|
|
41
|
+
}) {
|
|
42
|
+
const [editor] = useLexicalComposerContext();
|
|
43
|
+
useLayoutEffect(() => {
|
|
44
|
+
if (onChange) {
|
|
45
|
+
return editor.registerUpdateListener(({
|
|
46
|
+
editorState,
|
|
47
|
+
dirtyElements,
|
|
48
|
+
dirtyLeaves,
|
|
49
|
+
prevEditorState,
|
|
50
|
+
tags
|
|
51
|
+
}) => {
|
|
52
|
+
if (ignoreSelectionChange && dirtyElements.size === 0 && dirtyLeaves.size === 0 || ignoreHistoryMergeTagChange && tags.has('history-merge') || prevEditorState.isEmpty()) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
onChange(editorState, editor, tags);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}, [editor, ignoreHistoryMergeTagChange, ignoreSelectionChange, onChange]);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { OnChangePlugin };
|
|
@@ -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
|
+
import * as modDev from './LexicalOnChangePlugin.dev.esm.js';
|
|
8
|
+
import * as modProd from './LexicalOnChangePlugin.prod.esm.js';
|
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
|
+
export const OnChangePlugin = mod.OnChangePlugin;
|
package/LexicalOnChangePlugin.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const LexicalOnChangePlugin = process.env.NODE_ENV === 'development' ? require('./LexicalOnChangePlugin.dev.js') : require('./LexicalOnChangePlugin.prod.js')
|
|
8
|
+
const LexicalOnChangePlugin = process.env.NODE_ENV === 'development' ? require('./LexicalOnChangePlugin.dev.js') : require('./LexicalOnChangePlugin.prod.js');
|
|
9
9
|
module.exports = LexicalOnChangePlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLayoutEffect as t,useEffect as r}from"react";var o="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t:r;function i({ignoreHistoryMergeTagChange:t=!0,ignoreSelectionChange:r=!1,onChange:i}){const[n]=e();return o((()=>{if(i)return n.registerUpdateListener((({editorState:e,dirtyElements:o,dirtyLeaves:a,prevEditorState:s,tags:d})=>{r&&0===o.size&&0===a.size||t&&d.has("history-merge")||s.isEmpty()||i(e,n,d)}))}),[n,t,r,i]),null}export{i as OnChangePlugin};
|
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
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';
|
|
11
|
+
import { $canShowPlaceholderCurry } from '@lexical/text';
|
|
12
|
+
import { mergeRegister } from '@lexical/utils';
|
|
13
|
+
import { createPortal, flushSync } from 'react-dom';
|
|
14
|
+
import { registerDragonSupport } from '@lexical/dragon';
|
|
15
|
+
import { registerPlainText } from '@lexical/plain-text';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
19
|
+
*
|
|
20
|
+
* This source code is licensed under the MIT license found in the
|
|
21
|
+
* LICENSE file in the root directory of this source tree.
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
29
|
+
*
|
|
30
|
+
* This source code is licensed under the MIT license found in the
|
|
31
|
+
* LICENSE file in the root directory of this source tree.
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect$1 : useEffect;
|
|
35
|
+
var useLayoutEffect = useLayoutEffectImpl;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
39
|
+
*
|
|
40
|
+
* This source code is licensed under the MIT license found in the
|
|
41
|
+
* LICENSE file in the root directory of this source tree.
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
function canShowPlaceholderFromCurrentEditorState(editor) {
|
|
45
|
+
const currentCanShowPlaceholder = editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing()));
|
|
46
|
+
return currentCanShowPlaceholder;
|
|
47
|
+
}
|
|
48
|
+
function useCanShowPlaceholder(editor) {
|
|
49
|
+
const [canShowPlaceholder, setCanShowPlaceholder] = useState(() => canShowPlaceholderFromCurrentEditorState(editor));
|
|
50
|
+
useLayoutEffect(() => {
|
|
51
|
+
function resetCanShowPlaceholder() {
|
|
52
|
+
const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
|
|
53
|
+
setCanShowPlaceholder(currentCanShowPlaceholder);
|
|
54
|
+
}
|
|
55
|
+
resetCanShowPlaceholder();
|
|
56
|
+
return mergeRegister(editor.registerUpdateListener(() => {
|
|
57
|
+
resetCanShowPlaceholder();
|
|
58
|
+
}), editor.registerEditableListener(() => {
|
|
59
|
+
resetCanShowPlaceholder();
|
|
60
|
+
}));
|
|
61
|
+
}, [editor]);
|
|
62
|
+
return canShowPlaceholder;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
67
|
+
*
|
|
68
|
+
* This source code is licensed under the MIT license found in the
|
|
69
|
+
* LICENSE file in the root directory of this source tree.
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
function useDecorators(editor, ErrorBoundary) {
|
|
73
|
+
const [decorators, setDecorators] = useState(() => editor.getDecorators());
|
|
74
|
+
|
|
75
|
+
// Subscribe to changes
|
|
76
|
+
useLayoutEffect(() => {
|
|
77
|
+
return editor.registerDecoratorListener(nextDecorators => {
|
|
78
|
+
flushSync(() => {
|
|
79
|
+
setDecorators(nextDecorators);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}, [editor]);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
// If the content editable mounts before the subscription is added, then
|
|
85
|
+
// nothing will be rendered on initial pass. We can get around that by
|
|
86
|
+
// ensuring that we set the value.
|
|
87
|
+
setDecorators(editor.getDecorators());
|
|
88
|
+
}, [editor]);
|
|
89
|
+
|
|
90
|
+
// Return decorators defined as React Portals
|
|
91
|
+
return useMemo(() => {
|
|
92
|
+
const decoratedPortals = [];
|
|
93
|
+
const decoratorKeys = Object.keys(decorators);
|
|
94
|
+
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
95
|
+
const nodeKey = decoratorKeys[i];
|
|
96
|
+
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
97
|
+
onError: e => editor._onError(e)
|
|
98
|
+
}, /*#__PURE__*/React.createElement(Suspense, {
|
|
99
|
+
fallback: null
|
|
100
|
+
}, decorators[nodeKey]));
|
|
101
|
+
const element = editor.getElementByKey(nodeKey);
|
|
102
|
+
if (element !== null) {
|
|
103
|
+
decoratedPortals.push( /*#__PURE__*/createPortal(reactDecorator, element, nodeKey));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return decoratedPortals;
|
|
107
|
+
}, [ErrorBoundary, decorators, editor]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
112
|
+
*
|
|
113
|
+
* This source code is licensed under the MIT license found in the
|
|
114
|
+
* LICENSE file in the root directory of this source tree.
|
|
115
|
+
*
|
|
116
|
+
*/
|
|
117
|
+
function usePlainTextSetup(editor) {
|
|
118
|
+
useLayoutEffect(() => {
|
|
119
|
+
return mergeRegister(registerPlainText(editor), registerDragonSupport(editor));
|
|
120
|
+
|
|
121
|
+
// We only do this for init
|
|
122
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
123
|
+
}, [editor]);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
128
|
+
*
|
|
129
|
+
* This source code is licensed under the MIT license found in the
|
|
130
|
+
* LICENSE file in the root directory of this source tree.
|
|
131
|
+
*
|
|
132
|
+
*/
|
|
133
|
+
function PlainTextPlugin({
|
|
134
|
+
contentEditable,
|
|
135
|
+
placeholder,
|
|
136
|
+
ErrorBoundary
|
|
137
|
+
}) {
|
|
138
|
+
const [editor] = useLexicalComposerContext();
|
|
139
|
+
const decorators = useDecorators(editor, ErrorBoundary);
|
|
140
|
+
usePlainTextSetup(editor);
|
|
141
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, /*#__PURE__*/React.createElement(Placeholder, {
|
|
142
|
+
content: placeholder
|
|
143
|
+
}), decorators);
|
|
144
|
+
}
|
|
145
|
+
function Placeholder({
|
|
146
|
+
content
|
|
147
|
+
}) {
|
|
148
|
+
const [editor] = useLexicalComposerContext();
|
|
149
|
+
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
150
|
+
const editable = useLexicalEditable();
|
|
151
|
+
if (!showPlaceholder) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
if (typeof content === 'function') {
|
|
155
|
+
return content(editable);
|
|
156
|
+
} else {
|
|
157
|
+
return content;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { PlainTextPlugin };
|
|
@@ -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
|
+
import * as modDev from './LexicalPlainTextPlugin.dev.esm.js';
|
|
8
|
+
import * as modProd from './LexicalPlainTextPlugin.prod.esm.js';
|
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
|
+
export const PlainTextPlugin = mod.PlainTextPlugin;
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const LexicalPlainTextPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalPlainTextPlugin.dev.js') : require('./LexicalPlainTextPlugin.prod.js')
|
|
8
|
+
const LexicalPlainTextPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalPlainTextPlugin.dev.js') : require('./LexicalPlainTextPlugin.prod.js');
|
|
9
9
|
module.exports = LexicalPlainTextPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import t from"@lexical/react/useLexicalEditable";import*as r from"react";import{useLayoutEffect as o,useEffect as n,useState as c,useMemo as i,Suspense as l}from"react";import{$canShowPlaceholderCurry as a}from"@lexical/text";import{mergeRegister as m}from"@lexical/utils";import{createPortal as u,flushSync as s}from"react-dom";import{registerDragonSupport as f}from"@lexical/dragon";import{registerPlainText as d}from"@lexical/plain-text";var p="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?o:n;function E(e){return e.getEditorState().read(a(e.isComposing()))}function x({contentEditable:t,placeholder:o,ErrorBoundary:a}){const[E]=e(),x=function(e,t){const[o,a]=c((()=>e.getDecorators()));return p((()=>e.registerDecoratorListener((e=>{s((()=>{a(e)}))}))),[e]),n((()=>{a(e.getDecorators())}),[e]),i((()=>{const n=[],c=Object.keys(o);for(let i=0;i<c.length;i++){const a=c[i],m=r.createElement(t,{onError:t=>e._onError(t)},r.createElement(l,{fallback:null},o[a])),s=e.getElementByKey(a);null!==s&&n.push(u(m,s,a))}return n}),[t,o,e])}(E,a);return function(e){p((()=>m(d(e),f(e))),[e])}(E),r.createElement(r.Fragment,null,t,r.createElement(g,{content:o}),x)}function g({content:r}){const[o]=e(),n=function(e){const[t,r]=c((()=>E(e)));return p((()=>{function t(){const t=E(e);r(t)}return t(),m(e.registerUpdateListener((()=>{t()})),e.registerEditableListener((()=>{t()})))}),[e]),t}(o),i=t();return n?"function"==typeof r?r(i):r:null}export{x as PlainTextPlugin};
|
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
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';
|
|
11
|
+
import { $canShowPlaceholderCurry } from '@lexical/text';
|
|
12
|
+
import { mergeRegister } from '@lexical/utils';
|
|
13
|
+
import { createPortal, flushSync } from 'react-dom';
|
|
14
|
+
import { registerDragonSupport } from '@lexical/dragon';
|
|
15
|
+
import { registerRichText } from '@lexical/rich-text';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
19
|
+
*
|
|
20
|
+
* This source code is licensed under the MIT license found in the
|
|
21
|
+
* LICENSE file in the root directory of this source tree.
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
29
|
+
*
|
|
30
|
+
* This source code is licensed under the MIT license found in the
|
|
31
|
+
* LICENSE file in the root directory of this source tree.
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect$1 : useEffect;
|
|
35
|
+
var useLayoutEffect = useLayoutEffectImpl;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
39
|
+
*
|
|
40
|
+
* This source code is licensed under the MIT license found in the
|
|
41
|
+
* LICENSE file in the root directory of this source tree.
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
function canShowPlaceholderFromCurrentEditorState(editor) {
|
|
45
|
+
const currentCanShowPlaceholder = editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing()));
|
|
46
|
+
return currentCanShowPlaceholder;
|
|
47
|
+
}
|
|
48
|
+
function useCanShowPlaceholder(editor) {
|
|
49
|
+
const [canShowPlaceholder, setCanShowPlaceholder] = useState(() => canShowPlaceholderFromCurrentEditorState(editor));
|
|
50
|
+
useLayoutEffect(() => {
|
|
51
|
+
function resetCanShowPlaceholder() {
|
|
52
|
+
const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
|
|
53
|
+
setCanShowPlaceholder(currentCanShowPlaceholder);
|
|
54
|
+
}
|
|
55
|
+
resetCanShowPlaceholder();
|
|
56
|
+
return mergeRegister(editor.registerUpdateListener(() => {
|
|
57
|
+
resetCanShowPlaceholder();
|
|
58
|
+
}), editor.registerEditableListener(() => {
|
|
59
|
+
resetCanShowPlaceholder();
|
|
60
|
+
}));
|
|
61
|
+
}, [editor]);
|
|
62
|
+
return canShowPlaceholder;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
67
|
+
*
|
|
68
|
+
* This source code is licensed under the MIT license found in the
|
|
69
|
+
* LICENSE file in the root directory of this source tree.
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
function useDecorators(editor, ErrorBoundary) {
|
|
73
|
+
const [decorators, setDecorators] = useState(() => editor.getDecorators());
|
|
74
|
+
|
|
75
|
+
// Subscribe to changes
|
|
76
|
+
useLayoutEffect(() => {
|
|
77
|
+
return editor.registerDecoratorListener(nextDecorators => {
|
|
78
|
+
flushSync(() => {
|
|
79
|
+
setDecorators(nextDecorators);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}, [editor]);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
// If the content editable mounts before the subscription is added, then
|
|
85
|
+
// nothing will be rendered on initial pass. We can get around that by
|
|
86
|
+
// ensuring that we set the value.
|
|
87
|
+
setDecorators(editor.getDecorators());
|
|
88
|
+
}, [editor]);
|
|
89
|
+
|
|
90
|
+
// Return decorators defined as React Portals
|
|
91
|
+
return useMemo(() => {
|
|
92
|
+
const decoratedPortals = [];
|
|
93
|
+
const decoratorKeys = Object.keys(decorators);
|
|
94
|
+
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
95
|
+
const nodeKey = decoratorKeys[i];
|
|
96
|
+
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
97
|
+
onError: e => editor._onError(e)
|
|
98
|
+
}, /*#__PURE__*/React.createElement(Suspense, {
|
|
99
|
+
fallback: null
|
|
100
|
+
}, decorators[nodeKey]));
|
|
101
|
+
const element = editor.getElementByKey(nodeKey);
|
|
102
|
+
if (element !== null) {
|
|
103
|
+
decoratedPortals.push( /*#__PURE__*/createPortal(reactDecorator, element, nodeKey));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return decoratedPortals;
|
|
107
|
+
}, [ErrorBoundary, decorators, editor]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
112
|
+
*
|
|
113
|
+
* This source code is licensed under the MIT license found in the
|
|
114
|
+
* LICENSE file in the root directory of this source tree.
|
|
115
|
+
*
|
|
116
|
+
*/
|
|
117
|
+
function useRichTextSetup(editor) {
|
|
118
|
+
useLayoutEffect(() => {
|
|
119
|
+
return mergeRegister(registerRichText(editor), registerDragonSupport(editor));
|
|
120
|
+
|
|
121
|
+
// We only do this for init
|
|
122
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
123
|
+
}, [editor]);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
128
|
+
*
|
|
129
|
+
* This source code is licensed under the MIT license found in the
|
|
130
|
+
* LICENSE file in the root directory of this source tree.
|
|
131
|
+
*
|
|
132
|
+
*/
|
|
133
|
+
function RichTextPlugin({
|
|
134
|
+
contentEditable,
|
|
135
|
+
placeholder,
|
|
136
|
+
ErrorBoundary
|
|
137
|
+
}) {
|
|
138
|
+
const [editor] = useLexicalComposerContext();
|
|
139
|
+
const decorators = useDecorators(editor, ErrorBoundary);
|
|
140
|
+
useRichTextSetup(editor);
|
|
141
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, /*#__PURE__*/React.createElement(Placeholder, {
|
|
142
|
+
content: placeholder
|
|
143
|
+
}), decorators);
|
|
144
|
+
}
|
|
145
|
+
function Placeholder({
|
|
146
|
+
content
|
|
147
|
+
}) {
|
|
148
|
+
const [editor] = useLexicalComposerContext();
|
|
149
|
+
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
150
|
+
const editable = useLexicalEditable();
|
|
151
|
+
if (!showPlaceholder) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
if (typeof content === 'function') {
|
|
155
|
+
return content(editable);
|
|
156
|
+
} else {
|
|
157
|
+
return content;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { RichTextPlugin };
|
|
@@ -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
|
+
import * as modDev from './LexicalRichTextPlugin.dev.esm.js';
|
|
8
|
+
import * as modProd from './LexicalRichTextPlugin.prod.esm.js';
|
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
|
+
export const RichTextPlugin = mod.RichTextPlugin;
|
package/LexicalRichTextPlugin.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const LexicalRichTextPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalRichTextPlugin.dev.js') : require('./LexicalRichTextPlugin.prod.js')
|
|
8
|
+
const LexicalRichTextPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalRichTextPlugin.dev.js') : require('./LexicalRichTextPlugin.prod.js');
|
|
9
9
|
module.exports = LexicalRichTextPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import t from"@lexical/react/useLexicalEditable";import*as r from"react";import{useLayoutEffect as o,useEffect as n,useState as c,useMemo as i,Suspense as l}from"react";import{$canShowPlaceholderCurry as a}from"@lexical/text";import{mergeRegister as m}from"@lexical/utils";import{createPortal as u,flushSync as s}from"react-dom";import{registerDragonSupport as f}from"@lexical/dragon";import{registerRichText as d}from"@lexical/rich-text";var p="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?o:n;function E(e){return e.getEditorState().read(a(e.isComposing()))}function x({contentEditable:t,placeholder:o,ErrorBoundary:a}){const[E]=e(),x=function(e,t){const[o,a]=c((()=>e.getDecorators()));return p((()=>e.registerDecoratorListener((e=>{s((()=>{a(e)}))}))),[e]),n((()=>{a(e.getDecorators())}),[e]),i((()=>{const n=[],c=Object.keys(o);for(let i=0;i<c.length;i++){const a=c[i],m=r.createElement(t,{onError:t=>e._onError(t)},r.createElement(l,{fallback:null},o[a])),s=e.getElementByKey(a);null!==s&&n.push(u(m,s,a))}return n}),[t,o,e])}(E,a);return function(e){p((()=>m(d(e),f(e))),[e])}(E),r.createElement(r.Fragment,null,t,r.createElement(g,{content:o}),x)}function g({content:r}){const[o]=e(),n=function(e){const[t,r]=c((()=>E(e)));return p((()=>{function t(){const t=E(e);r(t)}return t(),m(e.registerUpdateListener((()=>{t()})),e.registerEditableListener((()=>{t()})))}),[e]),t}(o),i=t();return n?"function"==typeof r?r(i):r:null}export{x as RichTextPlugin};
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
8
|
+
import { $filter, $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
|
|
9
|
+
import { KEY_TAB_COMMAND, $getSelection, $isRangeSelection, OUTDENT_CONTENT_COMMAND, INDENT_CONTENT_COMMAND, INSERT_TAB_COMMAND, COMMAND_PRIORITY_EDITOR, $isBlockElementNode, $createRangeSelection, $normalizeSelection__EXPERIMENTAL } from 'lexical';
|
|
10
|
+
import { useEffect } from 'react';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
function indentOverTab(selection) {
|
|
20
|
+
// const handled = new Set();
|
|
21
|
+
const nodes = selection.getNodes();
|
|
22
|
+
const canIndentBlockNodes = $filter(nodes, node => {
|
|
23
|
+
if ($isBlockElementNode(node) && node.canIndent()) {
|
|
24
|
+
return node;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
});
|
|
28
|
+
// 1. If selection spans across canIndent block nodes: indent
|
|
29
|
+
if (canIndentBlockNodes.length > 0) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
// 2. If first (anchor/focus) is at block start: indent
|
|
33
|
+
const anchor = selection.anchor;
|
|
34
|
+
const focus = selection.focus;
|
|
35
|
+
const first = focus.isBefore(anchor) ? focus : anchor;
|
|
36
|
+
const firstNode = first.getNode();
|
|
37
|
+
const firstBlock = $getNearestBlockElementAncestorOrThrow(firstNode);
|
|
38
|
+
if (firstBlock.canIndent()) {
|
|
39
|
+
const firstBlockKey = firstBlock.getKey();
|
|
40
|
+
let selectionAtStart = $createRangeSelection();
|
|
41
|
+
selectionAtStart.anchor.set(firstBlockKey, 0, 'element');
|
|
42
|
+
selectionAtStart.focus.set(firstBlockKey, 0, 'element');
|
|
43
|
+
selectionAtStart = $normalizeSelection__EXPERIMENTAL(selectionAtStart);
|
|
44
|
+
if (selectionAtStart.anchor.is(first)) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// 3. Else: tab
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
function registerTabIndentation(editor) {
|
|
52
|
+
return editor.registerCommand(KEY_TAB_COMMAND, event => {
|
|
53
|
+
const selection = $getSelection();
|
|
54
|
+
if (!$isRangeSelection(selection)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
const command = indentOverTab(selection) ? event.shiftKey ? OUTDENT_CONTENT_COMMAND : INDENT_CONTENT_COMMAND : INSERT_TAB_COMMAND;
|
|
59
|
+
return editor.dispatchCommand(command, undefined);
|
|
60
|
+
}, COMMAND_PRIORITY_EDITOR);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* This plugin adds the ability to indent content using the tab key. Generally, we don't
|
|
65
|
+
* recommend using this plugin as it could negatively affect acessibility for keyboard
|
|
66
|
+
* users, causing focus to become trapped within the editor.
|
|
67
|
+
*/
|
|
68
|
+
function TabIndentationPlugin() {
|
|
69
|
+
const [editor] = useLexicalComposerContext();
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
return registerTabIndentation(editor);
|
|
72
|
+
});
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { TabIndentationPlugin, registerTabIndentation };
|
|
@@ -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
|
+
import * as modDev from './LexicalTabIndentationPlugin.dev.esm.js';
|
|
8
|
+
import * as modProd from './LexicalTabIndentationPlugin.prod.esm.js';
|
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
|
+
export const TabIndentationPlugin = mod.TabIndentationPlugin;
|
|
11
|
+
export const registerTabIndentation = mod.registerTabIndentation;
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const LexicalTabIndentationPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalTabIndentationPlugin.dev.js') : require('./LexicalTabIndentationPlugin.prod.js')
|
|
8
|
+
const LexicalTabIndentationPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalTabIndentationPlugin.dev.js') : require('./LexicalTabIndentationPlugin.prod.js');
|
|
9
9
|
module.exports = LexicalTabIndentationPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
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};
|