@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,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 link = require('@lexical/link');
|
|
@@ -11,7 +13,8 @@ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
|
11
13
|
var LexicalNodeMenuPlugin = require('@lexical/react/LexicalNodeMenuPlugin');
|
|
12
14
|
var utils = require('@lexical/utils');
|
|
13
15
|
var lexical = require('lexical');
|
|
14
|
-
var
|
|
16
|
+
var react = require('react');
|
|
17
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -20,6 +23,7 @@ var React = require('react');
|
|
|
20
23
|
* LICENSE file in the root directory of this source tree.
|
|
21
24
|
*
|
|
22
25
|
*/
|
|
26
|
+
|
|
23
27
|
const URL_MATCHER = /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
|
|
24
28
|
const INSERT_EMBED_COMMAND = lexical.createCommand('INSERT_EMBED_COMMAND');
|
|
25
29
|
class AutoEmbedOption extends LexicalNodeMenuPlugin.MenuOption {
|
|
@@ -37,13 +41,13 @@ function LexicalAutoEmbedPlugin({
|
|
|
37
41
|
menuCommandPriority = lexical.COMMAND_PRIORITY_LOW
|
|
38
42
|
}) {
|
|
39
43
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
40
|
-
const [nodeKey, setNodeKey] =
|
|
41
|
-
const [activeEmbedConfig, setActiveEmbedConfig] =
|
|
42
|
-
const reset =
|
|
44
|
+
const [nodeKey, setNodeKey] = react.useState(null);
|
|
45
|
+
const [activeEmbedConfig, setActiveEmbedConfig] = react.useState(null);
|
|
46
|
+
const reset = react.useCallback(() => {
|
|
43
47
|
setNodeKey(null);
|
|
44
48
|
setActiveEmbedConfig(null);
|
|
45
49
|
}, []);
|
|
46
|
-
const checkIfLinkNodeIsEmbeddable =
|
|
50
|
+
const checkIfLinkNodeIsEmbeddable = react.useCallback(key => {
|
|
47
51
|
editor.getEditorState().read(async function () {
|
|
48
52
|
const linkNode = lexical.$getNodeByKey(key);
|
|
49
53
|
if (link.$isLinkNode(linkNode)) {
|
|
@@ -58,7 +62,7 @@ function LexicalAutoEmbedPlugin({
|
|
|
58
62
|
}
|
|
59
63
|
});
|
|
60
64
|
}, [editor, embedConfigs]);
|
|
61
|
-
|
|
65
|
+
react.useEffect(() => {
|
|
62
66
|
const listener = (nodeMutations, {
|
|
63
67
|
updateTags,
|
|
64
68
|
dirtyLeaves
|
|
@@ -73,7 +77,7 @@ function LexicalAutoEmbedPlugin({
|
|
|
73
77
|
};
|
|
74
78
|
return utils.mergeRegister(...[link.LinkNode, link.AutoLinkNode].map(Klass => editor.registerMutationListener(Klass, (...args) => listener(...args))));
|
|
75
79
|
}, [checkIfLinkNodeIsEmbeddable, editor, embedConfigs, nodeKey, reset]);
|
|
76
|
-
|
|
80
|
+
react.useEffect(() => {
|
|
77
81
|
return editor.registerCommand(INSERT_EMBED_COMMAND, embedConfigType => {
|
|
78
82
|
const embedConfig = embedConfigs.find(({
|
|
79
83
|
type
|
|
@@ -85,7 +89,7 @@ function LexicalAutoEmbedPlugin({
|
|
|
85
89
|
return false;
|
|
86
90
|
}, lexical.COMMAND_PRIORITY_EDITOR);
|
|
87
91
|
}, [editor, embedConfigs, onOpenEmbedModalForConfig]);
|
|
88
|
-
const embedLinkViaActiveEmbedConfig =
|
|
92
|
+
const embedLinkViaActiveEmbedConfig = react.useCallback(async function () {
|
|
89
93
|
if (activeEmbedConfig != null && nodeKey != null) {
|
|
90
94
|
const linkNode = editor.getEditorState().read(() => {
|
|
91
95
|
const node = lexical.$getNodeByKey(nodeKey);
|
|
@@ -110,16 +114,16 @@ function LexicalAutoEmbedPlugin({
|
|
|
110
114
|
}
|
|
111
115
|
}
|
|
112
116
|
}, [activeEmbedConfig, editor, nodeKey]);
|
|
113
|
-
const options =
|
|
117
|
+
const options = react.useMemo(() => {
|
|
114
118
|
return activeEmbedConfig != null && nodeKey != null ? getMenuOptions(activeEmbedConfig, embedLinkViaActiveEmbedConfig, reset) : [];
|
|
115
119
|
}, [activeEmbedConfig, embedLinkViaActiveEmbedConfig, getMenuOptions, nodeKey, reset]);
|
|
116
|
-
const onSelectOption =
|
|
120
|
+
const onSelectOption = react.useCallback((selectedOption, targetNode, closeMenu) => {
|
|
117
121
|
editor.update(() => {
|
|
118
122
|
selectedOption.onSelect(targetNode);
|
|
119
123
|
closeMenu();
|
|
120
124
|
});
|
|
121
125
|
}, [editor]);
|
|
122
|
-
return nodeKey != null ? /*#__PURE__*/
|
|
126
|
+
return nodeKey != null ? /*#__PURE__*/jsxRuntime.jsx(LexicalNodeMenuPlugin.LexicalNodeMenuPlugin, {
|
|
123
127
|
nodeKey: nodeKey,
|
|
124
128
|
onClose: reset,
|
|
125
129
|
onSelectOption: onSelectOption,
|
|
@@ -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 { $isLinkNode, LinkNode, AutoLinkNode } from '@lexical/link';
|
|
8
10
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
9
11
|
import { MenuOption, LexicalNodeMenuPlugin } from '@lexical/react/LexicalNodeMenuPlugin';
|
|
10
12
|
import { mergeRegister } from '@lexical/utils';
|
|
11
13
|
import { createCommand, $getNodeByKey, COMMAND_PRIORITY_EDITOR, $getSelection, COMMAND_PRIORITY_LOW } from 'lexical';
|
|
12
|
-
import * as React from 'react';
|
|
13
14
|
import { useState, useCallback, useEffect, useMemo } from 'react';
|
|
15
|
+
import { jsx } from 'react/jsx-runtime';
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -19,6 +21,7 @@ import { useState, useCallback, useEffect, useMemo } from 'react';
|
|
|
19
21
|
* LICENSE file in the root directory of this source tree.
|
|
20
22
|
*
|
|
21
23
|
*/
|
|
24
|
+
|
|
22
25
|
const URL_MATCHER = /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
|
|
23
26
|
const INSERT_EMBED_COMMAND = createCommand('INSERT_EMBED_COMMAND');
|
|
24
27
|
class AutoEmbedOption extends MenuOption {
|
|
@@ -118,7 +121,7 @@ function LexicalAutoEmbedPlugin({
|
|
|
118
121
|
closeMenu();
|
|
119
122
|
});
|
|
120
123
|
}, [editor]);
|
|
121
|
-
return nodeKey != null ? /*#__PURE__*/
|
|
124
|
+
return nodeKey != null ? /*#__PURE__*/jsx(LexicalNodeMenuPlugin, {
|
|
122
125
|
nodeKey: nodeKey,
|
|
123
126
|
onClose: reset,
|
|
124
127
|
onSelectOption: onSelectOption,
|
|
@@ -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 LexicalAutoEmbedPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalAutoEmbedPlugin.dev.js') : require('./LexicalAutoEmbedPlugin.prod.js');
|
|
9
11
|
module.exports = LexicalAutoEmbedPlugin;
|
|
@@ -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 './LexicalAutoEmbedPlugin.dev.mjs';
|
|
8
10
|
import * as modProd from './LexicalAutoEmbedPlugin.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('./LexicalAutoEmbedPlugin.dev.mjs') : import('./LexicalAutoEmbedPlugin.prod.mjs'));
|
|
8
10
|
export const AutoEmbedOption = mod.AutoEmbedOption;
|
|
9
11
|
export const INSERT_EMBED_COMMAND = mod.INSERT_EMBED_COMMAND;
|
|
@@ -3,9 +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
|
-
|
|
10
|
-
|
|
11
|
-
exports.URL_MATCHER=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/
|
|
8
|
+
|
|
9
|
+
'use strict';var e=require("@lexical/link"),k=require("@lexical/react/LexicalComposerContext"),l=require("@lexical/react/LexicalNodeMenuPlugin"),q=require("@lexical/utils"),r=require("lexical"),z=require("react"),A=require("react/jsx-runtime");let B=r.createCommand("INSERT_EMBED_COMMAND");class C extends l.MenuOption{constructor(f,n){super(f);this.title=f;this.onSelect=n.onSelect.bind(this)}}exports.AutoEmbedOption=C;exports.INSERT_EMBED_COMMAND=B;
|
|
10
|
+
exports.LexicalAutoEmbedPlugin=function({embedConfigs:f,onOpenEmbedModalForConfig:n,getMenuOptions:t,menuRenderFn:D,menuCommandPriority:E=r.COMMAND_PRIORITY_LOW}){let [c]=k.useLexicalComposerContext(),[g,u]=z.useState(null),[h,v]=z.useState(null),m=z.useCallback(()=>{u(null);v(null)},[]),w=z.useCallback(b=>{c.getEditorState().read(async function(){const a=r.$getNodeByKey(b);if(e.$isLinkNode(a))for(let d=0;d<f.length;d++){const p=f[d];null!=await Promise.resolve(p.parseUrl(a.__url))&&(v(p),u(a.getKey()))}})},
|
|
11
|
+
[c,f]);z.useEffect(()=>{let b=(a,{updateTags:d,dirtyLeaves:p})=>{for(const [x,F]of a)"created"===F&&d.has("paste")&&3>=p.size?w(x):x===g&&m()};return q.mergeRegister(...[e.LinkNode,e.AutoLinkNode].map(a=>c.registerMutationListener(a,(...d)=>b(...d))))},[w,c,f,g,m]);z.useEffect(()=>c.registerCommand(B,b=>{let a=f.find(({type:d})=>d===b);return a?(n(a),!0):!1},r.COMMAND_PRIORITY_EDITOR),[c,f,n]);let y=z.useCallback(async function(){if(null!=h&&null!=g){const b=c.getEditorState().read(()=>{const a=r.$getNodeByKey(g);
|
|
12
|
+
return e.$isLinkNode(a)?a:null});if(e.$isLinkNode(b)){const a=await Promise.resolve(h.parseUrl(b.__url));null!=a&&c.update(()=>{r.$getSelection()||b.selectEnd();h.insertNode(c,a);b.isAttached()&&b.remove()})}}},[h,c,g]),G=z.useMemo(()=>null!=h&&null!=g?t(h,y,m):[],[h,y,t,g,m]),H=z.useCallback((b,a,d)=>{c.update(()=>{b.onSelect(a);d()})},[c]);return null!=g?A.jsx(l.LexicalNodeMenuPlugin,{nodeKey:g,onClose:m,onSelectOption:H,options:G,menuRenderFn:D,commandPriority:E}):null};exports.URL_MATCHER=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/
|
|
@@ -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{$isLinkNode as e,LinkNode as t,AutoLinkNode as n}from"@lexical/link";import{useLexicalComposerContext as o}from"@lexical/react/LexicalComposerContext";import{MenuOption as r,LexicalNodeMenuPlugin as l}from"@lexical/react/LexicalNodeMenuPlugin";import{mergeRegister as i}from"@lexical/utils";import{createCommand as s,$getNodeByKey as a,COMMAND_PRIORITY_EDITOR as c,$getSelection as u,COMMAND_PRIORITY_LOW as m}from"lexical";import{useState as d,useCallback as p,useEffect as f,useMemo as g}from"react";import{jsx as x}from"react/jsx-runtime";const w=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/,y=s("INSERT_EMBED_COMMAND");class C extends r{constructor(e,t){super(e),this.title=e,this.onSelect=t.onSelect.bind(this)}}function _({embedConfigs:r,onOpenEmbedModalForConfig:s,getMenuOptions:w,menuRenderFn:C,menuCommandPriority:_=m}){const[h]=o(),[E,M]=d(null),[S,A]=d(null),P=p((()=>{M(null),A(null)}),[]),b=p((t=>{h.getEditorState().read((async function(){const n=a(t);if(e(n))for(let e=0;e<r.length;e++){const t=r[e];null!=await Promise.resolve(t.parseUrl(n.__url))&&(A(t),M(n.getKey()))}}))}),[h,r]);f((()=>i(...[t,n].map((e=>h.registerMutationListener(e,((...e)=>((e,{updateTags:t,dirtyLeaves:n})=>{for(const[o,r]of e)"created"===r&&t.has("paste")&&n.size<=3?b(o):o===E&&P()})(...e))))))),[b,h,r,E,P]),f((()=>h.registerCommand(y,(e=>{const t=r.find((({type:t})=>t===e));return!!t&&(s(t),!0)}),c)),[h,r,s]);const v=p((async function(){if(null!=S&&null!=E){const t=h.getEditorState().read((()=>{const t=a(E);return e(t)?t:null}));if(e(t)){const e=await Promise.resolve(S.parseUrl(t.__url));null!=e&&h.update((()=>{u()||t.selectEnd(),S.insertNode(h,e),t.isAttached()&&t.remove()}))}}}),[S,h,E]),z=g((()=>null!=S&&null!=E?w(S,v,P):[]),[S,v,w,E,P]),L=p(((e,t,n)=>{h.update((()=>{e.onSelect(t),n()}))}),[h]);return null!=E?x(l,{nodeKey:E,onClose:P,onSelectOption:L,options:z,menuRenderFn:C,commandPriority:_}):null}export{C as AutoEmbedOption,y as INSERT_EMBED_COMMAND,_ as LexicalAutoEmbedPlugin,w as URL_MATCHER};
|
|
@@ -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');
|
|
@@ -16,6 +18,7 @@ var react = require('react');
|
|
|
16
18
|
* LICENSE file in the root directory of this source tree.
|
|
17
19
|
*
|
|
18
20
|
*/
|
|
21
|
+
|
|
19
22
|
function AutoFocusPlugin({
|
|
20
23
|
defaultSelection
|
|
21
24
|
}) {
|
|
@@ -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 { useEffect } from 'react';
|
|
9
11
|
|
|
@@ -14,6 +16,7 @@ import { useEffect } from 'react';
|
|
|
14
16
|
* LICENSE file in the root directory of this source tree.
|
|
15
17
|
*
|
|
16
18
|
*/
|
|
19
|
+
|
|
17
20
|
function AutoFocusPlugin({
|
|
18
21
|
defaultSelection
|
|
19
22
|
}) {
|
|
@@ -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 LexicalAutoFocusPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalAutoFocusPlugin.dev.js') : require('./LexicalAutoFocusPlugin.prod.js');
|
|
9
11
|
module.exports = LexicalAutoFocusPlugin;
|
|
@@ -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 './LexicalAutoFocusPlugin.dev.mjs';
|
|
8
10
|
import * as modProd from './LexicalAutoFocusPlugin.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('./LexicalAutoFocusPlugin.dev.mjs') : import('./LexicalAutoFocusPlugin.prod.mjs'));
|
|
8
10
|
export const AutoFocusPlugin = mod.AutoFocusPlugin;
|
|
@@ -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
|
'use strict';var e=require("@lexical/react/LexicalComposerContext"),f=require("react");exports.AutoFocusPlugin=function({defaultSelection:c}){let [a]=e.useLexicalComposerContext();f.useEffect(()=>{a.focus(()=>{let d=document.activeElement,b=a.getRootElement();null===b||null!==d&&b.contains(d)||b.focus({preventScroll:!0})},{defaultSelection:c})},[c,a]);return null}
|
|
@@ -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{useEffect as t}from"react";function o({defaultSelection:o}){const[l]=e();return t((()=>{l.focus((()=>{const e=document.activeElement,t=l.getRootElement();null===t||null!==e&&t.contains(e)||t.focus({preventScroll:!0})}),{defaultSelection:o})}),[o,l]),null}export{o as AutoFocusPlugin};
|
|
@@ -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 link = require('@lexical/link');
|
|
@@ -19,6 +21,7 @@ var react = require('react');
|
|
|
19
21
|
* LICENSE file in the root directory of this source tree.
|
|
20
22
|
*
|
|
21
23
|
*/
|
|
24
|
+
|
|
22
25
|
function createLinkMatcherWithRegExp(regExp, urlTransformer = text => text) {
|
|
23
26
|
return text => {
|
|
24
27
|
const match = regExp.exec(text);
|
|
@@ -100,7 +103,7 @@ function extractMatchingNodes(nodes, startIndex, endIndex) {
|
|
|
100
103
|
}
|
|
101
104
|
return [matchingOffset, unmodifiedBeforeNodes, matchingNodes, unmodifiedAfterNodes];
|
|
102
105
|
}
|
|
103
|
-
function
|
|
106
|
+
function $createAutoLinkNode_(nodes, startIndex, endIndex, match) {
|
|
104
107
|
const linkNode = link.$createAutoLinkNode(match.url, match.attributes);
|
|
105
108
|
if (nodes.length === 1) {
|
|
106
109
|
let remainingTextNode = nodes[0];
|
|
@@ -113,6 +116,7 @@ function createAutoLinkNode(nodes, startIndex, endIndex, match) {
|
|
|
113
116
|
const textNode = lexical.$createTextNode(match.text);
|
|
114
117
|
textNode.setFormat(linkTextNode.getFormat());
|
|
115
118
|
textNode.setDetail(linkTextNode.getDetail());
|
|
119
|
+
textNode.setStyle(linkTextNode.getStyle());
|
|
116
120
|
linkNode.append(textNode);
|
|
117
121
|
linkTextNode.replace(linkNode);
|
|
118
122
|
return remainingTextNode;
|
|
@@ -149,6 +153,7 @@ function createAutoLinkNode(nodes, startIndex, endIndex, match) {
|
|
|
149
153
|
const textNode = lexical.$createTextNode(firstLinkTextNode.getTextContent());
|
|
150
154
|
textNode.setFormat(firstLinkTextNode.getFormat());
|
|
151
155
|
textNode.setDetail(firstLinkTextNode.getDetail());
|
|
156
|
+
textNode.setStyle(firstLinkTextNode.getStyle());
|
|
152
157
|
linkNode.append(textNode, ...linkNodes);
|
|
153
158
|
// it does not preserve caret position if caret was at the first text node
|
|
154
159
|
// so we need to restore caret position
|
|
@@ -164,7 +169,7 @@ function createAutoLinkNode(nodes, startIndex, endIndex, match) {
|
|
|
164
169
|
}
|
|
165
170
|
return undefined;
|
|
166
171
|
}
|
|
167
|
-
function handleLinkCreation(nodes, matchers, onChange) {
|
|
172
|
+
function $handleLinkCreation(nodes, matchers, onChange) {
|
|
168
173
|
let currentNodes = [...nodes];
|
|
169
174
|
const initialText = currentNodes.map(node => node.getTextContent()).join('');
|
|
170
175
|
let text = initialText;
|
|
@@ -179,7 +184,7 @@ function handleLinkCreation(nodes, matchers, onChange) {
|
|
|
179
184
|
const [matchingOffset,, matchingNodes, unmodifiedAfterNodes] = extractMatchingNodes(currentNodes, invalidMatchEnd + matchStart, invalidMatchEnd + matchEnd);
|
|
180
185
|
const actualMatchStart = invalidMatchEnd + matchStart - matchingOffset;
|
|
181
186
|
const actualMatchEnd = invalidMatchEnd + matchEnd - matchingOffset;
|
|
182
|
-
const remainingTextNode =
|
|
187
|
+
const remainingTextNode = $createAutoLinkNode_(matchingNodes, actualMatchStart, actualMatchEnd, match);
|
|
183
188
|
currentNodes = remainingTextNode ? [remainingTextNode, ...unmodifiedAfterNodes] : unmodifiedAfterNodes;
|
|
184
189
|
onChange(match.url, null);
|
|
185
190
|
invalidMatchEnd = 0;
|
|
@@ -295,7 +300,7 @@ function useAutoLink(editor, matchers, onChange) {
|
|
|
295
300
|
} else if (!link.$isLinkNode(parent)) {
|
|
296
301
|
if (textNode.isSimpleText() && (startsWithSeparator(textNode.getTextContent()) || !link.$isAutoLinkNode(previous))) {
|
|
297
302
|
const textNodesToMatch = getTextNodesToMatch(textNode);
|
|
298
|
-
handleLinkCreation(textNodesToMatch, matchers, onChangeWrapped);
|
|
303
|
+
$handleLinkCreation(textNodesToMatch, matchers, onChangeWrapped);
|
|
299
304
|
}
|
|
300
305
|
handleBadNeighbors(textNode, matchers, onChangeWrapped);
|
|
301
306
|
}
|
|
@@ -3,11 +3,13 @@
|
|
|
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 { AutoLinkNode, $isAutoLinkNode, $isLinkNode, $createAutoLinkNode } from '@lexical/link';
|
|
8
10
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
9
11
|
import { mergeRegister } from '@lexical/utils';
|
|
10
|
-
import { TextNode, $isTextNode, $
|
|
12
|
+
import { TextNode, $isTextNode, $isElementNode, $isLineBreakNode, $createTextNode, $getSelection, $isRangeSelection, $isNodeSelection } from 'lexical';
|
|
11
13
|
import { useEffect } from 'react';
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -17,6 +19,7 @@ import { useEffect } from 'react';
|
|
|
17
19
|
* LICENSE file in the root directory of this source tree.
|
|
18
20
|
*
|
|
19
21
|
*/
|
|
22
|
+
|
|
20
23
|
function createLinkMatcherWithRegExp(regExp, urlTransformer = text => text) {
|
|
21
24
|
return text => {
|
|
22
25
|
const match = regExp.exec(text);
|
|
@@ -98,7 +101,7 @@ function extractMatchingNodes(nodes, startIndex, endIndex) {
|
|
|
98
101
|
}
|
|
99
102
|
return [matchingOffset, unmodifiedBeforeNodes, matchingNodes, unmodifiedAfterNodes];
|
|
100
103
|
}
|
|
101
|
-
function
|
|
104
|
+
function $createAutoLinkNode_(nodes, startIndex, endIndex, match) {
|
|
102
105
|
const linkNode = $createAutoLinkNode(match.url, match.attributes);
|
|
103
106
|
if (nodes.length === 1) {
|
|
104
107
|
let remainingTextNode = nodes[0];
|
|
@@ -111,6 +114,7 @@ function createAutoLinkNode(nodes, startIndex, endIndex, match) {
|
|
|
111
114
|
const textNode = $createTextNode(match.text);
|
|
112
115
|
textNode.setFormat(linkTextNode.getFormat());
|
|
113
116
|
textNode.setDetail(linkTextNode.getDetail());
|
|
117
|
+
textNode.setStyle(linkTextNode.getStyle());
|
|
114
118
|
linkNode.append(textNode);
|
|
115
119
|
linkTextNode.replace(linkNode);
|
|
116
120
|
return remainingTextNode;
|
|
@@ -147,6 +151,7 @@ function createAutoLinkNode(nodes, startIndex, endIndex, match) {
|
|
|
147
151
|
const textNode = $createTextNode(firstLinkTextNode.getTextContent());
|
|
148
152
|
textNode.setFormat(firstLinkTextNode.getFormat());
|
|
149
153
|
textNode.setDetail(firstLinkTextNode.getDetail());
|
|
154
|
+
textNode.setStyle(firstLinkTextNode.getStyle());
|
|
150
155
|
linkNode.append(textNode, ...linkNodes);
|
|
151
156
|
// it does not preserve caret position if caret was at the first text node
|
|
152
157
|
// so we need to restore caret position
|
|
@@ -162,7 +167,7 @@ function createAutoLinkNode(nodes, startIndex, endIndex, match) {
|
|
|
162
167
|
}
|
|
163
168
|
return undefined;
|
|
164
169
|
}
|
|
165
|
-
function handleLinkCreation(nodes, matchers, onChange) {
|
|
170
|
+
function $handleLinkCreation(nodes, matchers, onChange) {
|
|
166
171
|
let currentNodes = [...nodes];
|
|
167
172
|
const initialText = currentNodes.map(node => node.getTextContent()).join('');
|
|
168
173
|
let text = initialText;
|
|
@@ -177,7 +182,7 @@ function handleLinkCreation(nodes, matchers, onChange) {
|
|
|
177
182
|
const [matchingOffset,, matchingNodes, unmodifiedAfterNodes] = extractMatchingNodes(currentNodes, invalidMatchEnd + matchStart, invalidMatchEnd + matchEnd);
|
|
178
183
|
const actualMatchStart = invalidMatchEnd + matchStart - matchingOffset;
|
|
179
184
|
const actualMatchEnd = invalidMatchEnd + matchEnd - matchingOffset;
|
|
180
|
-
const remainingTextNode =
|
|
185
|
+
const remainingTextNode = $createAutoLinkNode_(matchingNodes, actualMatchStart, actualMatchEnd, match);
|
|
181
186
|
currentNodes = remainingTextNode ? [remainingTextNode, ...unmodifiedAfterNodes] : unmodifiedAfterNodes;
|
|
182
187
|
onChange(match.url, null);
|
|
183
188
|
invalidMatchEnd = 0;
|
|
@@ -293,7 +298,7 @@ function useAutoLink(editor, matchers, onChange) {
|
|
|
293
298
|
} else if (!$isLinkNode(parent)) {
|
|
294
299
|
if (textNode.isSimpleText() && (startsWithSeparator(textNode.getTextContent()) || !$isAutoLinkNode(previous))) {
|
|
295
300
|
const textNodesToMatch = getTextNodesToMatch(textNode);
|
|
296
|
-
handleLinkCreation(textNodesToMatch, matchers, onChangeWrapped);
|
|
301
|
+
$handleLinkCreation(textNodesToMatch, matchers, onChangeWrapped);
|
|
297
302
|
}
|
|
298
303
|
handleBadNeighbors(textNode, matchers, onChangeWrapped);
|
|
299
304
|
}
|
package/LexicalAutoLinkPlugin.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 LexicalAutoLinkPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalAutoLinkPlugin.dev.js') : require('./LexicalAutoLinkPlugin.prod.js');
|
|
9
11
|
module.exports = LexicalAutoLinkPlugin;
|
|
@@ -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 './LexicalAutoLinkPlugin.dev.mjs';
|
|
8
10
|
import * as modProd from './LexicalAutoLinkPlugin.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('./LexicalAutoLinkPlugin.dev.mjs') : import('./LexicalAutoLinkPlugin.prod.mjs'));
|
|
8
10
|
export const AutoLinkPlugin = mod.AutoLinkPlugin;
|
|
9
11
|
export const createLinkMatcherWithRegExp = mod.createLinkMatcherWithRegExp;
|
|
@@ -3,15 +3,17 @@
|
|
|
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
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function E(a,c,b){var d=a
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
c,
|
|
8
|
+
|
|
9
|
+
'use strict';var k=require("@lexical/link"),n=require("@lexical/react/LexicalComposerContext"),p=require("@lexical/utils"),r=require("lexical"),u=require("react"),v;function w(a){let c=new URLSearchParams;c.append("code",a);for(let b=1;b<arguments.length;b++)c.append("v",arguments[b]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${c} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
|
|
10
|
+
v=w&&w.__esModule&&Object.prototype.hasOwnProperty.call(w,"default")?w["default"]:w;function x(a,c){for(let b=0;b<c.length;b++){let d=c[b](a);if(d)return d}return null}let y=/[.,;\s]/;function z(a){a=a.getPreviousSibling();r.$isElementNode(a)&&(a=a.getLastDescendant());var c;!(c=null===a||r.$isLineBreakNode(a))&&(c=r.$isTextNode(a))&&(a=a.getTextContent(),c=y.test(a[a.length-1]));return c}
|
|
11
|
+
function A(a){a=a.getNextSibling();r.$isElementNode(a)&&(a=a.getFirstDescendant());return null===a||r.$isLineBreakNode(a)||r.$isTextNode(a)&&y.test(a.getTextContent()[0])}function B(a,c,b,d){return(0<a?y.test(b[a-1]):z(d[0]))?c<b.length?y.test(b[c]):A(d[d.length-1]):!1}function C(a,c,b){let d=[],h=[],e=[],f=0,g=0;for(a=[...a];0<a.length;){let l=a[0],m=l.getTextContent().length,q=g;g+m<=c?(d.push(l),f+=m):q>=b?e.push(l):h.push(l);g+=m;a.shift()}return[f,d,h,e]}
|
|
12
|
+
function D(a,c,b,d){let h=k.$createAutoLinkNode(d.url,d.attributes);if(1===a.length){var e=a[0];0===c?[g,e]=e.splitText(b):[,g,e]=e.splitText(c,b);var f=r.$createTextNode(d.text);f.setFormat(g.getFormat());f.setDetail(g.getDetail());f.setStyle(g.getStyle());h.append(f);g.replace(h);return e}if(1<a.length){d=a[0];var g=d.getTextContent().length;0===c?e=d:[,e]=d.splitText(c);c=[];for(d=1;d<a.length;d++){let l=a[d],m=l.getTextContent().length,q=g,t=g+m;if(q<b)if(t<=b)c.push(l);else{let [G,H]=l.splitText(b-
|
|
13
|
+
q);c.push(G);f=H}g+=m}a=(b=r.$getSelection())?b.getNodes().find(r.$isTextNode):void 0;g=r.$createTextNode(e.getTextContent());g.setFormat(e.getFormat());g.setDetail(e.getDetail());g.setStyle(e.getStyle());h.append(g,...c);a&&a===e&&(r.$isRangeSelection(b)?g.select(b.anchor.offset,b.focus.offset):r.$isNodeSelection(b)&&g.select(0,g.getTextContent().length));e.replace(h);return f}}
|
|
14
|
+
function E(a,c,b){var d=[...a];let h=a=d.map(g=>g.getTextContent()).join(""),e,f=0;for(;(e=x(h,c))&&null!==e;){let g=e.index,l=g+e.length;if(B(f+g,f+l,a,d)){let [m,,q,t]=C(d,f+g,f+l);d=(d=D(q,f+g-m,f+l-m,e))?[d,...t]:t;b(e.url,null);f=0}else f+=l;h=h.substring(l)}}
|
|
15
|
+
function F(a,c,b){var d=a.getChildren();let h=d.length;for(let e=0;e<h;e++){let f=d[e];if(!r.$isTextNode(f)||!f.isSimpleText()){I(a);b(null,a.getURL());return}}d=a.getTextContent();c=x(d,c);null===c||c.text!==d?(I(a),b(null,a.getURL())):z(a)&&A(a)?(d=a.getURL(),d!==c.url&&(a.setURL(c.url),b(c.url,d)),c.attributes&&(d=a.getRel(),d!==c.attributes.rel&&(a.setRel(c.attributes.rel||null),b(c.attributes.rel||null,d)),d=a.getTarget(),d!==c.attributes.target&&(a.setTarget(c.attributes.target||null),b(c.attributes.target||
|
|
16
|
+
null,d)))):(I(a),b(null,a.getURL()))}function I(a){let c=a.getChildren();var b=c.length;for(--b;0<=b;b--)a.insertAfter(c[b]);a.remove();return c.map(d=>d.getLatest())}
|
|
17
|
+
function J(a,c,b){u.useEffect(()=>{a.hasNodes([k.AutoLinkNode])||v(77);let d=(h,e)=>{b&&b(h,e)};return p.mergeRegister(a.registerNodeTransform(r.TextNode,h=>{var e=h.getParentOrThrow(),f=h.getPreviousSibling();if(k.$isAutoLinkNode(e))F(e,c,d);else if(!k.$isLinkNode(e)){if(h.isSimpleText()&&(y.test(h.getTextContent()[0])||!k.$isAutoLinkNode(f))){e=[h];for(f=h.getNextSibling();null!==f&&r.$isTextNode(f)&&f.isSimpleText();){e.push(f);if(/[\s]/.test(f.getTextContent()))break;f=f.getNextSibling()}E(e,
|
|
18
|
+
c,d)}let g=h.getPreviousSibling();e=h.getNextSibling();f=h.getTextContent();k.$isAutoLinkNode(g)&&!y.test(f[0])&&(g.append(h),F(g,c,d),h=g.getURL(),b&&b(null,h));k.$isAutoLinkNode(e)&&!y.test(f[f.length-1])&&(I(e),F(e,c,d),h=e.getURL(),b&&b(null,h))}}))},[a,c,b])}exports.AutoLinkPlugin=function({matchers:a,onChange:c}){let [b]=n.useLexicalComposerContext();J(b,a,c);return null};
|
|
17
19
|
exports.createLinkMatcherWithRegExp=function(a,c=b=>b){return b=>{b=a.exec(b);return null===b?null:{index:b.index,length:b[0].length,text:b[0],url:c(b[0])}}}
|
|
@@ -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{AutoLinkNode as t,$isAutoLinkNode as e,$isLinkNode as n,$createAutoLinkNode as l}from"@lexical/link";import{useLexicalComposerContext as r}from"@lexical/react/LexicalComposerContext";import{mergeRegister as o}from"@lexical/utils";import{TextNode as i,$isTextNode as s,$isElementNode as u,$isLineBreakNode as g,$createTextNode as c,$getSelection as f,$isRangeSelection as a,$isNodeSelection as h}from"lexical";import{useEffect as p}from"react";function x(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var d=x((function(t){const e=new URLSearchParams;e.append("code",t);for(let t=1;t<arguments.length;t++)e.append("v",arguments[t]);throw Error(`Minified Lexical error #${t}; visit https://lexical.dev/docs/error?${e} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));function m(t,e=(t=>t)){return n=>{const l=t.exec(n);return null===l?null:{index:l.index,length:l[0].length,text:l[0],url:e(l[0])}}}function T(t,e){for(let n=0;n<e.length;n++){const l=e[n](t);if(l)return l}return null}const b=/[.,;\s]/;function C(t){return b.test(t)}function S(t){return C(t[t.length-1])}function v(t){return C(t[0])}function L(t){let e=t.getPreviousSibling();return u(e)&&(e=e.getLastDescendant()),null===e||g(e)||s(e)&&S(e.getTextContent())}function R(t){let e=t.getNextSibling();return u(e)&&(e=e.getFirstDescendant()),null===e||g(e)||s(e)&&v(e.getTextContent())}function U(t,e,n,l){if(!(t>0?C(n[t-1]):L(l[0])))return!1;return e<n.length?C(n[e]):R(l[l.length-1])}function N(t,e,n){const l=[],r=[],o=[];let i=0,s=0;const u=[...t];for(;u.length>0;){const t=u[0],g=t.getTextContent().length,c=s;s+g<=e?(l.push(t),i+=g):c>=n?o.push(t):r.push(t),s+=g,u.shift()}return[i,l,r,o]}function y(t,e,n,r){const o=l(r.url,r.attributes);if(1===t.length){let l,i=t[0];0===e?[l,i]=i.splitText(n):[,l,i]=i.splitText(e,n);const s=c(r.text);return s.setFormat(l.getFormat()),s.setDetail(l.getDetail()),s.setStyle(l.getStyle()),o.append(s),l.replace(o),i}if(t.length>1){const l=t[0];let r,i=l.getTextContent().length;0===e?r=l:[,r]=l.splitText(e);const u=[];let g;for(let e=1;e<t.length;e++){const l=t[e],r=l.getTextContent().length,o=i;if(o<n)if(i+r<=n)u.push(l);else{const[t,e]=l.splitText(n-o);u.push(t),g=e}i+=r}const p=f(),x=p?p.getNodes().find(s):void 0,d=c(r.getTextContent());return d.setFormat(r.getFormat()),d.setDetail(r.getDetail()),d.setStyle(r.getStyle()),o.append(d,...u),x&&x===r&&(a(p)?d.select(p.anchor.offset,p.focus.offset):h(p)&&d.select(0,d.getTextContent().length)),r.replace(o),g}}function D(t,e,n){const l=t.getChildren(),r=l.length;for(let e=0;e<r;e++){const r=l[e];if(!s(r)||!r.isSimpleText())return P(t),void n(null,t.getURL())}const o=t.getTextContent(),i=T(o,e);if(null===i||i.text!==o)return P(t),void n(null,t.getURL());if(!L(t)||!R(t))return P(t),void n(null,t.getURL());const u=t.getURL();if(u!==i.url&&(t.setURL(i.url),n(i.url,u)),i.attributes){const e=t.getRel();e!==i.attributes.rel&&(t.setRel(i.attributes.rel||null),n(i.attributes.rel||null,e));const l=t.getTarget();l!==i.attributes.target&&(t.setTarget(i.attributes.target||null),n(i.attributes.target||null,l))}}function P(t){const e=t.getChildren();for(let n=e.length-1;n>=0;n--)t.insertAfter(e[n]);return t.remove(),e.map((t=>t.getLatest()))}function w(l,r,u){p((()=>{l.hasNodes([t])||d(77);const g=(t,e)=>{u&&u(t,e)};return o(l.registerNodeTransform(i,(t=>{const l=t.getParentOrThrow(),o=t.getPreviousSibling();if(e(l))D(l,r,g);else if(!n(l)){if(t.isSimpleText()&&(v(t.getTextContent())||!e(o))){const e=function(t){const e=[t];let n=t.getNextSibling();for(;null!==n&&s(n)&&n.isSimpleText()&&(e.push(n),!/[\s]/.test(n.getTextContent()));)n=n.getNextSibling();return e}(t);!function(t,e,n){let l=[...t];const r=l.map((t=>t.getTextContent())).join("");let o,i=r,s=0;for(;(o=T(i,e))&&null!==o;){const t=o.index,e=t+o.length;if(U(s+t,s+e,r,l)){const[r,,i,u]=N(l,s+t,s+e),g=y(i,s+t-r,s+e-r,o);l=g?[g,...u]:u,n(o.url,null),s=0}else s+=e;i=i.substring(e)}}(e,r,g)}!function(t,n,l){const r=t.getPreviousSibling(),o=t.getNextSibling(),i=t.getTextContent();e(r)&&!v(i)&&(r.append(t),D(r,n,l),l(null,r.getURL())),e(o)&&!S(i)&&(P(o),D(o,n,l),l(null,o.getURL()))}(t,r,g)}})))}),[l,r,u])}function F({matchers:t,onChange:e}){const[n]=r();return w(n,t,e),null}export{F as AutoLinkPlugin,m as createLinkMatcherWithRegExp};
|
|
@@ -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');
|
|
@@ -11,7 +13,8 @@ var LexicalDecoratorBlockNode = require('@lexical/react/LexicalDecoratorBlockNod
|
|
|
11
13
|
var useLexicalNodeSelection = require('@lexical/react/useLexicalNodeSelection');
|
|
12
14
|
var utils = require('@lexical/utils');
|
|
13
15
|
var lexical = require('lexical');
|
|
14
|
-
var
|
|
16
|
+
var react = require('react');
|
|
17
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -20,6 +23,7 @@ var React = require('react');
|
|
|
20
23
|
* LICENSE file in the root directory of this source tree.
|
|
21
24
|
*
|
|
22
25
|
*/
|
|
26
|
+
|
|
23
27
|
function BlockWithAlignableContents({
|
|
24
28
|
children,
|
|
25
29
|
format,
|
|
@@ -28,8 +32,8 @@ function BlockWithAlignableContents({
|
|
|
28
32
|
}) {
|
|
29
33
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
30
34
|
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection.useLexicalNodeSelection(nodeKey);
|
|
31
|
-
const ref =
|
|
32
|
-
const onDelete =
|
|
35
|
+
const ref = react.useRef(null);
|
|
36
|
+
const $onDelete = react.useCallback(event => {
|
|
33
37
|
if (isSelected && lexical.$isNodeSelection(lexical.$getSelection())) {
|
|
34
38
|
event.preventDefault();
|
|
35
39
|
const node = lexical.$getNodeByKey(nodeKey);
|
|
@@ -40,7 +44,7 @@ function BlockWithAlignableContents({
|
|
|
40
44
|
}
|
|
41
45
|
return false;
|
|
42
46
|
}, [isSelected, nodeKey]);
|
|
43
|
-
|
|
47
|
+
react.useEffect(() => {
|
|
44
48
|
return utils.mergeRegister(editor.registerCommand(lexical.FORMAT_ELEMENT_COMMAND, formatType => {
|
|
45
49
|
if (isSelected) {
|
|
46
50
|
const selection = lexical.$getSelection();
|
|
@@ -73,15 +77,16 @@ function BlockWithAlignableContents({
|
|
|
73
77
|
return true;
|
|
74
78
|
}
|
|
75
79
|
return false;
|
|
76
|
-
}, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_DELETE_COMMAND, onDelete, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, onDelete, lexical.COMMAND_PRIORITY_LOW));
|
|
77
|
-
}, [clearSelection, editor, isSelected, nodeKey, onDelete, setSelected]);
|
|
78
|
-
return /*#__PURE__*/
|
|
80
|
+
}, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_DELETE_COMMAND, $onDelete, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, $onDelete, lexical.COMMAND_PRIORITY_LOW));
|
|
81
|
+
}, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected]);
|
|
82
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
79
83
|
className: [className.base, isSelected ? className.focus : null].filter(Boolean).join(' '),
|
|
80
84
|
ref: ref,
|
|
81
85
|
style: {
|
|
82
86
|
textAlign: format ? format : undefined
|
|
83
|
-
}
|
|
84
|
-
|
|
87
|
+
},
|
|
88
|
+
children: children
|
|
89
|
+
});
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
exports.BlockWithAlignableContents = BlockWithAlignableContents;
|