@lexical/react 0.35.1-nightly.20250924.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ExtensionComponent.d.ts +42 -0
- package/LexicalAutoEmbedPlugin.dev.js +2 -0
- package/LexicalAutoEmbedPlugin.dev.mjs +2 -0
- package/LexicalAutoEmbedPlugin.prod.js +1 -1
- package/LexicalAutoEmbedPlugin.prod.mjs +1 -1
- package/LexicalAutoLinkPlugin.d.ts +2 -17
- package/LexicalAutoLinkPlugin.dev.js +7 -309
- package/LexicalAutoLinkPlugin.dev.mjs +9 -310
- package/LexicalAutoLinkPlugin.js.flow +4 -18
- package/LexicalAutoLinkPlugin.prod.js +1 -1
- package/LexicalAutoLinkPlugin.prod.mjs +1 -1
- package/LexicalClearEditorPlugin.dev.js +2 -23
- package/LexicalClearEditorPlugin.dev.mjs +2 -23
- package/LexicalClearEditorPlugin.prod.js +1 -1
- package/LexicalClearEditorPlugin.prod.mjs +1 -1
- package/LexicalClickableLinkPlugin.dev.js +5 -70
- package/LexicalClickableLinkPlugin.dev.mjs +6 -71
- package/LexicalClickableLinkPlugin.prod.js +1 -1
- package/LexicalClickableLinkPlugin.prod.mjs +1 -1
- package/LexicalCollaborationContext.prod.js +1 -1
- package/LexicalCollaborationContext.prod.mjs +1 -1
- package/LexicalCollaborationPlugin.dev.mjs +2 -2
- package/LexicalCollaborationPlugin.prod.mjs +1 -1
- package/LexicalContentEditable.dev.js +2 -3
- package/LexicalContentEditable.dev.mjs +2 -3
- package/LexicalContentEditable.prod.js +1 -1
- package/LexicalContentEditable.prod.mjs +1 -1
- package/LexicalContextMenuPlugin.dev.js +2 -0
- package/LexicalContextMenuPlugin.dev.mjs +4 -2
- package/LexicalContextMenuPlugin.prod.js +1 -1
- package/LexicalContextMenuPlugin.prod.mjs +1 -1
- package/LexicalDecoratorBlockNode.dev.js +1 -0
- package/LexicalDecoratorBlockNode.dev.mjs +1 -0
- package/LexicalDecoratorBlockNode.js.flow +7 -0
- package/LexicalDecoratorBlockNode.prod.js +1 -1
- package/LexicalDecoratorBlockNode.prod.mjs +1 -1
- package/LexicalDraggableBlockPlugin.dev.js +6 -0
- package/LexicalDraggableBlockPlugin.dev.mjs +6 -0
- package/LexicalDraggableBlockPlugin.prod.js +1 -1
- package/LexicalDraggableBlockPlugin.prod.mjs +1 -1
- package/LexicalExtensionComponent.dev.js +53 -0
- package/LexicalExtensionComponent.dev.mjs +51 -0
- package/LexicalExtensionComponent.js +11 -0
- package/LexicalExtensionComponent.js.flow +12 -0
- package/LexicalExtensionComponent.mjs +12 -0
- package/LexicalExtensionComponent.node.mjs +10 -0
- package/LexicalExtensionComponent.prod.js +9 -0
- package/LexicalExtensionComponent.prod.mjs +9 -0
- package/LexicalExtensionComposer.d.ts +69 -0
- package/LexicalExtensionComposer.dev.js +105 -0
- package/LexicalExtensionComposer.dev.mjs +103 -0
- package/LexicalExtensionComposer.js +11 -0
- package/LexicalExtensionComposer.js.flow +20 -0
- package/LexicalExtensionComposer.mjs +12 -0
- package/LexicalExtensionComposer.node.mjs +10 -0
- package/LexicalExtensionComposer.prod.js +9 -0
- package/LexicalExtensionComposer.prod.mjs +9 -0
- package/LexicalHashtagPlugin.dev.js +1 -136
- package/LexicalHashtagPlugin.dev.mjs +3 -138
- package/LexicalHashtagPlugin.prod.js +1 -1
- package/LexicalHashtagPlugin.prod.mjs +1 -1
- package/LexicalHorizontalRuleNode.d.ts +10 -11
- package/LexicalHorizontalRuleNode.dev.js +12 -26
- package/LexicalHorizontalRuleNode.dev.mjs +14 -27
- package/LexicalHorizontalRuleNode.js.flow +2 -3
- package/LexicalHorizontalRuleNode.prod.js +1 -1
- package/LexicalHorizontalRuleNode.prod.mjs +1 -1
- package/LexicalLinkPlugin.d.ts +1 -1
- package/LexicalLinkPlugin.dev.js +7 -52
- package/LexicalLinkPlugin.dev.mjs +8 -53
- package/LexicalLinkPlugin.prod.js +1 -1
- package/LexicalLinkPlugin.prod.mjs +1 -1
- package/LexicalListPlugin.js.flow +5 -0
- package/LexicalMarkdownShortcutPlugin.dev.mjs +1 -1
- package/LexicalMarkdownShortcutPlugin.prod.mjs +1 -1
- package/LexicalNestedComposer.js.flow +10 -6
- package/LexicalNodeContextMenuPlugin.dev.js +10 -0
- package/LexicalNodeContextMenuPlugin.dev.mjs +11 -1
- package/LexicalNodeContextMenuPlugin.prod.js +1 -1
- package/LexicalNodeContextMenuPlugin.prod.mjs +1 -1
- package/LexicalNodeMenuPlugin.dev.js +2 -0
- package/LexicalNodeMenuPlugin.dev.mjs +4 -2
- package/LexicalNodeMenuPlugin.prod.js +1 -1
- package/LexicalNodeMenuPlugin.prod.mjs +1 -1
- package/LexicalPlainTextPlugin.d.ts +1 -1
- package/LexicalPlainTextPlugin.dev.js +85 -30
- package/LexicalPlainTextPlugin.dev.mjs +85 -30
- package/LexicalPlainTextPlugin.prod.js +1 -1
- package/LexicalPlainTextPlugin.prod.mjs +1 -1
- package/LexicalReactExtension.dev.js +187 -0
- package/LexicalReactExtension.dev.mjs +184 -0
- package/LexicalReactExtension.js +11 -0
- package/LexicalReactExtension.js.flow +68 -0
- package/LexicalReactExtension.mjs +13 -0
- package/LexicalReactExtension.node.mjs +11 -0
- package/LexicalReactExtension.prod.js +9 -0
- package/LexicalReactExtension.prod.mjs +9 -0
- package/LexicalReactPluginHostExtension.dev.js +189 -0
- package/LexicalReactPluginHostExtension.dev.mjs +181 -0
- package/LexicalReactPluginHostExtension.js +11 -0
- package/LexicalReactPluginHostExtension.js.flow +84 -0
- package/LexicalReactPluginHostExtension.mjs +18 -0
- package/LexicalReactPluginHostExtension.node.mjs +16 -0
- package/LexicalReactPluginHostExtension.prod.js +9 -0
- package/LexicalReactPluginHostExtension.prod.mjs +9 -0
- package/LexicalReactProviderExtension.dev.js +33 -0
- package/LexicalReactProviderExtension.dev.mjs +31 -0
- package/LexicalReactProviderExtension.js +11 -0
- package/LexicalReactProviderExtension.js.flow +12 -0
- package/LexicalReactProviderExtension.mjs +12 -0
- package/LexicalReactProviderExtension.node.mjs +10 -0
- package/LexicalReactProviderExtension.prod.js +9 -0
- package/LexicalReactProviderExtension.prod.mjs +9 -0
- package/LexicalRichTextPlugin.d.ts +1 -1
- package/LexicalRichTextPlugin.dev.js +85 -30
- package/LexicalRichTextPlugin.dev.mjs +85 -30
- package/LexicalRichTextPlugin.prod.js +1 -1
- package/LexicalRichTextPlugin.prod.mjs +1 -1
- package/LexicalTabIndentationPlugin.d.ts +2 -2
- package/LexicalTabIndentationPlugin.dev.js +3 -57
- package/LexicalTabIndentationPlugin.dev.mjs +3 -56
- package/LexicalTabIndentationPlugin.prod.js +1 -1
- package/LexicalTabIndentationPlugin.prod.mjs +1 -1
- package/LexicalTreeViewExtension.dev.js +57 -0
- package/LexicalTreeViewExtension.dev.mjs +54 -0
- package/LexicalTreeViewExtension.js +11 -0
- package/LexicalTreeViewExtension.js.flow +12 -0
- package/LexicalTreeViewExtension.mjs +13 -0
- package/LexicalTreeViewExtension.node.mjs +11 -0
- package/LexicalTreeViewExtension.prod.js +9 -0
- package/LexicalTreeViewExtension.prod.mjs +9 -0
- package/LexicalTypeaheadMenuPlugin.dev.js +2 -0
- package/LexicalTypeaheadMenuPlugin.dev.mjs +4 -2
- package/LexicalTypeaheadMenuPlugin.prod.js +1 -1
- package/LexicalTypeaheadMenuPlugin.prod.mjs +1 -1
- package/ReactExtension.d.ts +41 -0
- package/ReactPluginHostExtension.d.ts +56 -0
- package/ReactProviderExtension.d.ts +9 -0
- package/TreeViewExtension.d.ts +18 -0
- package/package.json +228 -17
- package/shared/LegacyDecorators.d.ts +23 -0
- package/shared/buildEditorComponent.d.ts +11 -0
- package/shared/mergeRefs.d.ts +2 -1
- package/shared/types.d.ts +89 -0
- package/shared/useReactDecorators.d.ts +12 -0
- package/useExtensionComponent.d.ts +10 -0
- package/useLexicalExtensionComponent.dev.js +37 -0
- package/useLexicalExtensionComponent.dev.mjs +34 -0
- package/useLexicalExtensionComponent.js +11 -0
- package/useLexicalExtensionComponent.js.flow +12 -0
- package/useLexicalExtensionComponent.mjs +13 -0
- package/useLexicalExtensionComponent.node.mjs +11 -0
- package/useLexicalExtensionComponent.prod.js +9 -0
- package/useLexicalExtensionComponent.prod.mjs +9 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { useExtensionComponent } from '@lexical/react/useExtensionComponent';
|
|
10
|
+
import { jsx } from 'react/jsx-runtime';
|
|
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
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A convenient way to get an Extension's output Component with {@link useExtensionComponent}
|
|
22
|
+
* and construct it in one step.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* Usage
|
|
26
|
+
* ```tsx
|
|
27
|
+
* return (
|
|
28
|
+
* <ExtensionComponent
|
|
29
|
+
* lexical:extension={TreeViewExtension}
|
|
30
|
+
* viewClassName="tree-view-output" />
|
|
31
|
+
* );
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* Alternative without ExtensionComponent
|
|
36
|
+
* ```tsx
|
|
37
|
+
* const TreeViewComponent = useExtensionComponent(TreeViewExtension);
|
|
38
|
+
* return (<TreeViewComponent viewClassName="tree-view-output" />);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
function ExtensionComponent({
|
|
42
|
+
'lexical:extension': extension,
|
|
43
|
+
...props
|
|
44
|
+
}) {
|
|
45
|
+
const Component = useExtensionComponent(extension);
|
|
46
|
+
return /*#__PURE__*/jsx(Component, {
|
|
47
|
+
...props
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { ExtensionComponent };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict'
|
|
10
|
+
const LexicalExtensionComponent = process.env.NODE_ENV !== 'production' ? require('./LexicalExtensionComponent.dev.js') : require('./LexicalExtensionComponent.prod.js');
|
|
11
|
+
module.exports = LexicalExtensionComponent;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* LexicalExtensionComponent
|
|
12
|
+
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as modDev from './LexicalExtensionComponent.dev.mjs';
|
|
10
|
+
import * as modProd from './LexicalExtensionComponent.prod.mjs';
|
|
11
|
+
const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
|
|
12
|
+
export const ExtensionComponent = mod.ExtensionComponent;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalExtensionComponent.dev.mjs') : import('./LexicalExtensionComponent.prod.mjs'));
|
|
10
|
+
export const ExtensionComponent = mod.ExtensionComponent;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
"use strict";var e=require("@lexical/react/useExtensionComponent"),n=require("react/jsx-runtime");exports.ExtensionComponent=function({"lexical:extension":t,...o}){const r=e.useExtensionComponent(t);return n.jsx(r,{...o})};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import{useExtensionComponent as e}from"@lexical/react/useExtensionComponent";import{jsx as t}from"react/jsx-runtime";function n({"lexical:extension":n,...o}){const r=e(n);return t(r,{...o})}export{n as ExtensionComponent};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ReactConfig } from '@lexical/react/ReactExtension';
|
|
2
|
+
import { type AnyLexicalExtensionArgument } from 'lexical';
|
|
3
|
+
export interface LexicalExtensionComposerProps {
|
|
4
|
+
/**
|
|
5
|
+
* Your root extension, typically defined with {@link defineExtension}
|
|
6
|
+
*/
|
|
7
|
+
extension: AnyLexicalExtensionArgument;
|
|
8
|
+
/**
|
|
9
|
+
* Any children will have access to useLexicalComposerContext (e.g. for React plug-ins or UX)
|
|
10
|
+
*/
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* Override the default ContentEditable that is rendered as the first child of the
|
|
14
|
+
* composer. If this is null, then it is your responsibility to render a ContentEditable
|
|
15
|
+
* elsewhere in the tree. This is equivalent to
|
|
16
|
+
* `configExtension(ReactExtension, {contentEditable})` in your extension dependencies.
|
|
17
|
+
*/
|
|
18
|
+
contentEditable?: ReactConfig['contentEditable'];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The equivalent of LexicalComposer for an extension. Make sure that your extension
|
|
22
|
+
* argument is stable (e.g. using module scope or useMemo) so
|
|
23
|
+
* that you are not re-creating the editor on every render!
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* Module scoped extension
|
|
27
|
+
* ```tsx
|
|
28
|
+
* const extension = defineExtension({
|
|
29
|
+
* name: "[root]",
|
|
30
|
+
* dependencies: [RichTextExtension, HistoryExtension, EmojiExtension]
|
|
31
|
+
* });
|
|
32
|
+
* function MyEditor({ children }) {
|
|
33
|
+
* return (<LexicalExtensionComposer extension={extension}>{children}</LexicalExtensionComposer>);
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* useMemo extension
|
|
39
|
+
* ```tsx
|
|
40
|
+
* function MyEditor({ emojiBaseUrl, children }) {
|
|
41
|
+
* const extension = useMemo(() => {
|
|
42
|
+
* return defineExtension({
|
|
43
|
+
* name: "[root]",
|
|
44
|
+
* dependencies: [
|
|
45
|
+
* RichTextExtension,
|
|
46
|
+
* HistoryExtension,
|
|
47
|
+
* configExtension(EmojiExtension, { emojiBaseUrl }),
|
|
48
|
+
* ],
|
|
49
|
+
* });
|
|
50
|
+
* }, [emojiBaseUrl]);
|
|
51
|
+
* return (<LexicalExtensionComposer extension={extension}>{children}</LexicalExtensionComposer>);
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* Incorrect usage with unstable extension
|
|
57
|
+
* ```tsx
|
|
58
|
+
* function MyBrokenEditor({ emojiBaseUrl }) {
|
|
59
|
+
* // This argument is not stable, the editor is re-created every render and
|
|
60
|
+
* // all state is lost!
|
|
61
|
+
* const extension = defineExtension({
|
|
62
|
+
* name: "[root]",
|
|
63
|
+
* dependencies: [RichTextExtension, HistoryExtension, EmojiExtension]
|
|
64
|
+
* });
|
|
65
|
+
* return (<LexicalExtensionComposer extension={extension}>{children}</LexicalExtensionComposer>);
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function LexicalExtensionComposer({ extension, children, contentEditable, }: LexicalExtensionComposerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
var extension = require('@lexical/extension');
|
|
12
|
+
var ReactExtension = require('@lexical/react/ReactExtension');
|
|
13
|
+
var ReactProviderExtension = require('@lexical/react/ReactProviderExtension');
|
|
14
|
+
var lexical = require('lexical');
|
|
15
|
+
var react = require('react');
|
|
16
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
20
|
+
*
|
|
21
|
+
* This source code is licensed under the MIT license found in the
|
|
22
|
+
* LICENSE file in the root directory of this source tree.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* The equivalent of LexicalComposer for an extension. Make sure that your extension
|
|
27
|
+
* argument is stable (e.g. using module scope or useMemo) so
|
|
28
|
+
* that you are not re-creating the editor on every render!
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* Module scoped extension
|
|
32
|
+
* ```tsx
|
|
33
|
+
* const extension = defineExtension({
|
|
34
|
+
* name: "[root]",
|
|
35
|
+
* dependencies: [RichTextExtension, HistoryExtension, EmojiExtension]
|
|
36
|
+
* });
|
|
37
|
+
* function MyEditor({ children }) {
|
|
38
|
+
* return (<LexicalExtensionComposer extension={extension}>{children}</LexicalExtensionComposer>);
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* useMemo extension
|
|
44
|
+
* ```tsx
|
|
45
|
+
* function MyEditor({ emojiBaseUrl, children }) {
|
|
46
|
+
* const extension = useMemo(() => {
|
|
47
|
+
* return defineExtension({
|
|
48
|
+
* name: "[root]",
|
|
49
|
+
* dependencies: [
|
|
50
|
+
* RichTextExtension,
|
|
51
|
+
* HistoryExtension,
|
|
52
|
+
* configExtension(EmojiExtension, { emojiBaseUrl }),
|
|
53
|
+
* ],
|
|
54
|
+
* });
|
|
55
|
+
* }, [emojiBaseUrl]);
|
|
56
|
+
* return (<LexicalExtensionComposer extension={extension}>{children}</LexicalExtensionComposer>);
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* Incorrect usage with unstable extension
|
|
62
|
+
* ```tsx
|
|
63
|
+
* function MyBrokenEditor({ emojiBaseUrl }) {
|
|
64
|
+
* // This argument is not stable, the editor is re-created every render and
|
|
65
|
+
* // all state is lost!
|
|
66
|
+
* const extension = defineExtension({
|
|
67
|
+
* name: "[root]",
|
|
68
|
+
* dependencies: [RichTextExtension, HistoryExtension, EmojiExtension]
|
|
69
|
+
* });
|
|
70
|
+
* return (<LexicalExtensionComposer extension={extension}>{children}</LexicalExtensionComposer>);
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
function LexicalExtensionComposer({
|
|
75
|
+
extension: extension$1,
|
|
76
|
+
children,
|
|
77
|
+
contentEditable
|
|
78
|
+
}) {
|
|
79
|
+
const editor = react.useMemo(() => {
|
|
80
|
+
const builder = extension.LexicalBuilder.fromExtensions([ReactProviderExtension.ReactProviderExtension, lexical.configExtension(ReactExtension.ReactExtension, contentEditable === undefined ? {} : {
|
|
81
|
+
contentEditable
|
|
82
|
+
}), extension$1]);
|
|
83
|
+
return builder.buildEditor();
|
|
84
|
+
}, [contentEditable, extension$1]);
|
|
85
|
+
react.useEffect(() => {
|
|
86
|
+
// Strict mode workaround
|
|
87
|
+
let didMount = false;
|
|
88
|
+
queueMicrotask(() => {
|
|
89
|
+
didMount = true;
|
|
90
|
+
});
|
|
91
|
+
return () => {
|
|
92
|
+
if (didMount) {
|
|
93
|
+
editor.dispose();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}, [editor]);
|
|
97
|
+
const {
|
|
98
|
+
Component
|
|
99
|
+
} = extension.getExtensionDependencyFromEditor(editor, ReactExtension.ReactExtension).output;
|
|
100
|
+
return /*#__PURE__*/jsxRuntime.jsx(Component, {
|
|
101
|
+
children: children
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
exports.LexicalExtensionComposer = LexicalExtensionComposer;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { LexicalBuilder, getExtensionDependencyFromEditor } from '@lexical/extension';
|
|
10
|
+
import { ReactExtension } from '@lexical/react/ReactExtension';
|
|
11
|
+
import { ReactProviderExtension } from '@lexical/react/ReactProviderExtension';
|
|
12
|
+
import { configExtension } from 'lexical';
|
|
13
|
+
import { useMemo, useEffect } from 'react';
|
|
14
|
+
import { jsx } from 'react/jsx-runtime';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the MIT license found in the
|
|
20
|
+
* LICENSE file in the root directory of this source tree.
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* The equivalent of LexicalComposer for an extension. Make sure that your extension
|
|
25
|
+
* argument is stable (e.g. using module scope or useMemo) so
|
|
26
|
+
* that you are not re-creating the editor on every render!
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* Module scoped extension
|
|
30
|
+
* ```tsx
|
|
31
|
+
* const extension = defineExtension({
|
|
32
|
+
* name: "[root]",
|
|
33
|
+
* dependencies: [RichTextExtension, HistoryExtension, EmojiExtension]
|
|
34
|
+
* });
|
|
35
|
+
* function MyEditor({ children }) {
|
|
36
|
+
* return (<LexicalExtensionComposer extension={extension}>{children}</LexicalExtensionComposer>);
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* useMemo extension
|
|
42
|
+
* ```tsx
|
|
43
|
+
* function MyEditor({ emojiBaseUrl, children }) {
|
|
44
|
+
* const extension = useMemo(() => {
|
|
45
|
+
* return defineExtension({
|
|
46
|
+
* name: "[root]",
|
|
47
|
+
* dependencies: [
|
|
48
|
+
* RichTextExtension,
|
|
49
|
+
* HistoryExtension,
|
|
50
|
+
* configExtension(EmojiExtension, { emojiBaseUrl }),
|
|
51
|
+
* ],
|
|
52
|
+
* });
|
|
53
|
+
* }, [emojiBaseUrl]);
|
|
54
|
+
* return (<LexicalExtensionComposer extension={extension}>{children}</LexicalExtensionComposer>);
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* Incorrect usage with unstable extension
|
|
60
|
+
* ```tsx
|
|
61
|
+
* function MyBrokenEditor({ emojiBaseUrl }) {
|
|
62
|
+
* // This argument is not stable, the editor is re-created every render and
|
|
63
|
+
* // all state is lost!
|
|
64
|
+
* const extension = defineExtension({
|
|
65
|
+
* name: "[root]",
|
|
66
|
+
* dependencies: [RichTextExtension, HistoryExtension, EmojiExtension]
|
|
67
|
+
* });
|
|
68
|
+
* return (<LexicalExtensionComposer extension={extension}>{children}</LexicalExtensionComposer>);
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
function LexicalExtensionComposer({
|
|
73
|
+
extension,
|
|
74
|
+
children,
|
|
75
|
+
contentEditable
|
|
76
|
+
}) {
|
|
77
|
+
const editor = useMemo(() => {
|
|
78
|
+
const builder = LexicalBuilder.fromExtensions([ReactProviderExtension, configExtension(ReactExtension, contentEditable === undefined ? {} : {
|
|
79
|
+
contentEditable
|
|
80
|
+
}), extension]);
|
|
81
|
+
return builder.buildEditor();
|
|
82
|
+
}, [contentEditable, extension]);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
// Strict mode workaround
|
|
85
|
+
let didMount = false;
|
|
86
|
+
queueMicrotask(() => {
|
|
87
|
+
didMount = true;
|
|
88
|
+
});
|
|
89
|
+
return () => {
|
|
90
|
+
if (didMount) {
|
|
91
|
+
editor.dispose();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}, [editor]);
|
|
95
|
+
const {
|
|
96
|
+
Component
|
|
97
|
+
} = getExtensionDependencyFromEditor(editor, ReactExtension).output;
|
|
98
|
+
return /*#__PURE__*/jsx(Component, {
|
|
99
|
+
children: children
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { LexicalExtensionComposer };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict'
|
|
10
|
+
const LexicalExtensionComposer = process.env.NODE_ENV !== 'production' ? require('./LexicalExtensionComposer.dev.js') : require('./LexicalExtensionComposer.prod.js');
|
|
11
|
+
module.exports = LexicalExtensionComposer;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* LexicalExtensionComposer
|
|
12
|
+
*/
|
|
13
|
+
import type {AnyLexicalExtensionArgument} from 'lexical';
|
|
14
|
+
import type {ReactConfig} from '@lexical/react/ReactExtension';
|
|
15
|
+
export type LexicalExtensionComposerProps = {
|
|
16
|
+
extension: AnyLexicalExtensionArgument;
|
|
17
|
+
children: React.Node;
|
|
18
|
+
contentEditable?: ReactConfig['contentEditable'];
|
|
19
|
+
}
|
|
20
|
+
declare export function LexicalExtensionComposer(props: LexicalExtensionComposerProps): React.Node;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as modDev from './LexicalExtensionComposer.dev.mjs';
|
|
10
|
+
import * as modProd from './LexicalExtensionComposer.prod.mjs';
|
|
11
|
+
const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
|
|
12
|
+
export const LexicalExtensionComposer = mod.LexicalExtensionComposer;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalExtensionComposer.dev.mjs') : import('./LexicalExtensionComposer.prod.mjs'));
|
|
10
|
+
export const LexicalExtensionComposer = mod.LexicalExtensionComposer;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
"use strict";var e=require("@lexical/extension"),t=require("@lexical/react/ReactExtension"),i=require("@lexical/react/ReactProviderExtension"),n=require("lexical"),r=require("react"),o=require("react/jsx-runtime");exports.LexicalExtensionComposer=function({extension:c,children:s,contentEditable:x}){const a=r.useMemo((()=>e.LexicalBuilder.fromExtensions([i.ReactProviderExtension,n.configExtension(t.ReactExtension,void 0===x?{}:{contentEditable:x}),c]).buildEditor()),[x,c]);r.useEffect((()=>{let e=!1;return queueMicrotask((()=>{e=!0})),()=>{e&&a.dispose()}}),[a]);const{Component:u}=e.getExtensionDependencyFromEditor(a,t.ReactExtension).output;return o.jsx(u,{children:s})};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import{LexicalBuilder as t,getExtensionDependencyFromEditor as e}from"@lexical/extension";import{ReactExtension as o}from"@lexical/react/ReactExtension";import{ReactProviderExtension as r}from"@lexical/react/ReactProviderExtension";import{configExtension as i}from"lexical";import{useMemo as n,useEffect as c}from"react";import{jsx as m}from"react/jsx-runtime";function l({extension:l,children:a,contentEditable:s}){const x=n((()=>t.fromExtensions([r,i(o,void 0===s?{}:{contentEditable:s}),l]).buildEditor()),[s,l]);c((()=>{let t=!1;return queueMicrotask((()=>{t=!0})),()=>{t&&x.dispose()}}),[x]);const{Component:p}=e(x,o).output;return m(p,{children:a})}export{l as LexicalExtensionComposer};
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
var hashtag = require('@lexical/hashtag');
|
|
12
12
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
13
|
-
var useLexicalTextEntity = require('@lexical/react/useLexicalTextEntity');
|
|
14
13
|
var react = require('react');
|
|
15
14
|
|
|
16
15
|
/**
|
|
@@ -21,148 +20,14 @@ var react = require('react');
|
|
|
21
20
|
*
|
|
22
21
|
*/
|
|
23
22
|
|
|
24
|
-
function getHashtagRegexStringChars() {
|
|
25
|
-
// Latin accented characters
|
|
26
|
-
// Excludes 0xd7 from the range
|
|
27
|
-
// (the multiplication sign, confusable with "x").
|
|
28
|
-
// Also excludes 0xf7, the division sign
|
|
29
|
-
const latinAccents = '\xc0-\xd6' + '\xd8-\xf6' + '\xf8-\xff' + '\u0100-\u024f' + '\u0253-\u0254' + '\u0256-\u0257' + '\u0259' + '\u025b' + '\u0263' + '\u0268' + '\u026f' + '\u0272' + '\u0289' + '\u028b' + '\u02bb' + '\u0300-\u036f' + '\u1e00-\u1eff';
|
|
30
|
-
|
|
31
|
-
// Cyrillic (Russian, Ukrainian, etc.)
|
|
32
|
-
const nonLatinChars = '\u0400-\u04ff' +
|
|
33
|
-
// Cyrillic
|
|
34
|
-
'\u0500-\u0527' +
|
|
35
|
-
// Cyrillic Supplement
|
|
36
|
-
'\u2de0-\u2dff' +
|
|
37
|
-
// Cyrillic Extended A
|
|
38
|
-
'\ua640-\ua69f' +
|
|
39
|
-
// Cyrillic Extended B
|
|
40
|
-
'\u0591-\u05bf' +
|
|
41
|
-
// Hebrew
|
|
42
|
-
'\u05c1-\u05c2' + '\u05c4-\u05c5' + '\u05c7' + '\u05d0-\u05ea' + '\u05f0-\u05f4' + '\ufb12-\ufb28' +
|
|
43
|
-
// Hebrew Presentation Forms
|
|
44
|
-
'\ufb2a-\ufb36' + '\ufb38-\ufb3c' + '\ufb3e' + '\ufb40-\ufb41' + '\ufb43-\ufb44' + '\ufb46-\ufb4f' + '\u0610-\u061a' +
|
|
45
|
-
// Arabic
|
|
46
|
-
'\u0620-\u065f' + '\u066e-\u06d3' + '\u06d5-\u06dc' + '\u06de-\u06e8' + '\u06ea-\u06ef' + '\u06fa-\u06fc' + '\u06ff' + '\u0750-\u077f' +
|
|
47
|
-
// Arabic Supplement
|
|
48
|
-
'\u08a0' +
|
|
49
|
-
// Arabic Extended A
|
|
50
|
-
'\u08a2-\u08ac' + '\u08e4-\u08fe' + '\ufb50-\ufbb1' +
|
|
51
|
-
// Arabic Pres. Forms A
|
|
52
|
-
'\ufbd3-\ufd3d' + '\ufd50-\ufd8f' + '\ufd92-\ufdc7' + '\ufdf0-\ufdfb' + '\ufe70-\ufe74' +
|
|
53
|
-
// Arabic Pres. Forms B
|
|
54
|
-
'\ufe76-\ufefc' + '\u200c-\u200c' +
|
|
55
|
-
// Zero-Width Non-Joiner
|
|
56
|
-
'\u0e01-\u0e3a' +
|
|
57
|
-
// Thai
|
|
58
|
-
'\u0e40-\u0e4e' +
|
|
59
|
-
// Hangul (Korean)
|
|
60
|
-
'\u1100-\u11ff' +
|
|
61
|
-
// Hangul Jamo
|
|
62
|
-
'\u3130-\u3185' +
|
|
63
|
-
// Hangul Compatibility Jamo
|
|
64
|
-
'\uA960-\uA97F' +
|
|
65
|
-
// Hangul Jamo Extended-A
|
|
66
|
-
'\uAC00-\uD7AF' +
|
|
67
|
-
// Hangul Syllables
|
|
68
|
-
'\uD7B0-\uD7FF' +
|
|
69
|
-
// Hangul Jamo Extended-B
|
|
70
|
-
'\uFFA1-\uFFDC'; // Half-width Hangul
|
|
71
|
-
|
|
72
|
-
const charCode = String.fromCharCode;
|
|
73
|
-
const cjkChars = '\u30A1-\u30FA\u30FC-\u30FE' +
|
|
74
|
-
// Katakana (full-width)
|
|
75
|
-
'\uFF66-\uFF9F' +
|
|
76
|
-
// Katakana (half-width)
|
|
77
|
-
'\uFF10-\uFF19\uFF21-\uFF3A' + '\uFF41-\uFF5A' +
|
|
78
|
-
// Latin (full-width)
|
|
79
|
-
'\u3041-\u3096\u3099-\u309E' +
|
|
80
|
-
// Hiragana
|
|
81
|
-
'\u3400-\u4DBF' +
|
|
82
|
-
// Kanji (CJK Extension A)
|
|
83
|
-
'\u4E00-\u9FFF' +
|
|
84
|
-
// Kanji (Unified)
|
|
85
|
-
// Disabled as it breaks the Regex.
|
|
86
|
-
// charCode(0x20000) + '-' + charCode(0x2A6DF) + // Kanji (CJK Extension B)
|
|
87
|
-
charCode(0x2a700) + '-' + charCode(0x2b73f) +
|
|
88
|
-
// Kanji (CJK Extension C)
|
|
89
|
-
charCode(0x2b740) + '-' + charCode(0x2b81f) +
|
|
90
|
-
// Kanji (CJK Extension D)
|
|
91
|
-
charCode(0x2f800) + '-' + charCode(0x2fa1f) + '\u3003\u3005\u303B'; // Kanji (CJK supplement)
|
|
92
|
-
|
|
93
|
-
const otherChars = latinAccents + nonLatinChars + cjkChars;
|
|
94
|
-
// equivalent of \p{L}
|
|
95
|
-
|
|
96
|
-
const unicodeLetters = '\u0041-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6' + '\u00F8-\u0241\u0250-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EE\u037A\u0386' + '\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03CE\u03D0-\u03F5\u03F7-\u0481' + '\u048A-\u04CE\u04D0-\u04F9\u0500-\u050F\u0531-\u0556\u0559\u0561-\u0587' + '\u05D0-\u05EA\u05F0-\u05F2\u0621-\u063A\u0640-\u064A\u066E-\u066F' + '\u0671-\u06D3\u06D5\u06E5-\u06E6\u06EE-\u06EF\u06FA-\u06FC\u06FF\u0710' + '\u0712-\u072F\u074D-\u076D\u0780-\u07A5\u07B1\u0904-\u0939\u093D\u0950' + '\u0958-\u0961\u097D\u0985-\u098C\u098F-\u0990\u0993-\u09A8\u09AA-\u09B0' + '\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC-\u09DD\u09DF-\u09E1\u09F0-\u09F1' + '\u0A05-\u0A0A\u0A0F-\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32-\u0A33' + '\u0A35-\u0A36\u0A38-\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D' + '\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2-\u0AB3\u0AB5-\u0AB9\u0ABD' + '\u0AD0\u0AE0-\u0AE1\u0B05-\u0B0C\u0B0F-\u0B10\u0B13-\u0B28\u0B2A-\u0B30' + '\u0B32-\u0B33\u0B35-\u0B39\u0B3D\u0B5C-\u0B5D\u0B5F-\u0B61\u0B71\u0B83' + '\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99-\u0B9A\u0B9C\u0B9E-\u0B9F' + '\u0BA3-\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0C05-\u0C0C\u0C0E-\u0C10' + '\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C60-\u0C61\u0C85-\u0C8C' + '\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE' + '\u0CE0-\u0CE1\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D28\u0D2A-\u0D39' + '\u0D60-\u0D61\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6' + '\u0E01-\u0E30\u0E32-\u0E33\u0E40-\u0E46\u0E81-\u0E82\u0E84\u0E87-\u0E88' + '\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7' + '\u0EAA-\u0EAB\u0EAD-\u0EB0\u0EB2-\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6' + '\u0EDC-\u0EDD\u0F00\u0F40-\u0F47\u0F49-\u0F6A\u0F88-\u0F8B\u1000-\u1021' + '\u1023-\u1027\u1029-\u102A\u1050-\u1055\u10A0-\u10C5\u10D0-\u10FA\u10FC' + '\u1100-\u1159\u115F-\u11A2\u11A8-\u11F9\u1200-\u1248\u124A-\u124D' + '\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0' + '\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310' + '\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C' + '\u166F-\u1676\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711' + '\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7' + '\u17DC\u1820-\u1877\u1880-\u18A8\u1900-\u191C\u1950-\u196D\u1970-\u1974' + '\u1980-\u19A9\u19C1-\u19C7\u1A00-\u1A16\u1D00-\u1DBF\u1E00-\u1E9B' + '\u1EA0-\u1EF9\u1F00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D' + '\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC' + '\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC' + '\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u2094\u2102\u2107' + '\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D' + '\u212F-\u2131\u2133-\u2139\u213C-\u213F\u2145-\u2149\u2C00-\u2C2E' + '\u2C30-\u2C5E\u2C80-\u2CE4\u2D00-\u2D25\u2D30-\u2D65\u2D6F\u2D80-\u2D96' + '\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6' + '\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3006\u3031-\u3035' + '\u303B-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF' + '\u3105-\u312C\u3131-\u318E\u31A0-\u31B7\u31F0-\u31FF\u3400-\u4DB5' + '\u4E00-\u9FBB\uA000-\uA48C\uA800-\uA801\uA803-\uA805\uA807-\uA80A' + '\uA80C-\uA822\uAC00-\uD7A3\uF900-\uFA2D\uFA30-\uFA6A\uFA70-\uFAD9' + '\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C' + '\uFB3E\uFB40-\uFB41\uFB43-\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F' + '\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A' + '\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7' + '\uFFDA-\uFFDC';
|
|
97
|
-
|
|
98
|
-
// equivalent of \p{Mn}\p{Mc}
|
|
99
|
-
const unicodeAccents = '\u0300-\u036F\u0483-\u0486\u0591-\u05B9\u05BB-\u05BD\u05BF' + '\u05C1-\u05C2\u05C4-\u05C5\u05C7\u0610-\u0615\u064B-\u065E\u0670' + '\u06D6-\u06DC\u06DF-\u06E4\u06E7-\u06E8\u06EA-\u06ED\u0711\u0730-\u074A' + '\u07A6-\u07B0\u0901-\u0903\u093C\u093E-\u094D\u0951-\u0954\u0962-\u0963' + '\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7-\u09C8\u09CB-\u09CD\u09D7' + '\u09E2-\u09E3\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47-\u0A48\u0A4B-\u0A4D' + '\u0A70-\u0A71\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD' + '\u0AE2-\u0AE3\u0B01-\u0B03\u0B3C\u0B3E-\u0B43\u0B47-\u0B48\u0B4B-\u0B4D' + '\u0B56-\u0B57\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7' + '\u0C01-\u0C03\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55-\u0C56' + '\u0C82-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5-\u0CD6' + '\u0D02-\u0D03\u0D3E-\u0D43\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D82-\u0D83' + '\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2-\u0DF3\u0E31\u0E34-\u0E3A' + '\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB-\u0EBC\u0EC8-\u0ECD\u0F18-\u0F19' + '\u0F35\u0F37\u0F39\u0F3E-\u0F3F\u0F71-\u0F84\u0F86-\u0F87\u0F90-\u0F97' + '\u0F99-\u0FBC\u0FC6\u102C-\u1032\u1036-\u1039\u1056-\u1059\u135F' + '\u1712-\u1714\u1732-\u1734\u1752-\u1753\u1772-\u1773\u17B6-\u17D3\u17DD' + '\u180B-\u180D\u18A9\u1920-\u192B\u1930-\u193B\u19B0-\u19C0\u19C8-\u19C9' + '\u1A17-\u1A1B\u1DC0-\u1DC3\u20D0-\u20DC\u20E1\u20E5-\u20EB\u302A-\u302F' + '\u3099-\u309A\uA802\uA806\uA80B\uA823-\uA827\uFB1E\uFE00-\uFE0F' + '\uFE20-\uFE23';
|
|
100
|
-
|
|
101
|
-
// equivalent of \p{Dn}
|
|
102
|
-
const unicodeDigits = '\u0030-\u0039\u0660-\u0669\u06F0-\u06F9\u0966-\u096F\u09E6-\u09EF' + '\u0A66-\u0A6F\u0AE6-\u0AEF\u0B66-\u0B6F\u0BE6-\u0BEF\u0C66-\u0C6F' + '\u0CE6-\u0CEF\u0D66-\u0D6F\u0E50-\u0E59\u0ED0-\u0ED9\u0F20-\u0F29' + '\u1040-\u1049\u17E0-\u17E9\u1810-\u1819\u1946-\u194F\u19D0-\u19D9' + '\uFF10-\uFF19';
|
|
103
|
-
|
|
104
|
-
// An alpha char is a unicode chars excluding unicode combining marks
|
|
105
|
-
// but including other chars, a hashtag must start with one of these,
|
|
106
|
-
// it does not make sense to have a combining mark before a base character.
|
|
107
|
-
const alpha = unicodeLetters + otherChars;
|
|
108
|
-
|
|
109
|
-
// A numeric character is any with the number digit property, or
|
|
110
|
-
// underscore. These characters can be included in hashtags, but a hashtag
|
|
111
|
-
// cannot have only these characters.
|
|
112
|
-
const numeric = unicodeDigits + '_';
|
|
113
|
-
|
|
114
|
-
// Alphanumeric char is any alpha char or a unicode char with decimal
|
|
115
|
-
// number property \p{Nd}
|
|
116
|
-
const alphanumeric = alpha + unicodeAccents + numeric;
|
|
117
|
-
const hashChars = '#\\uFF03'; // normal '#' or full-width '#'
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
alpha,
|
|
121
|
-
alphanumeric,
|
|
122
|
-
hashChars
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
function getHashtagRegexString() {
|
|
126
|
-
const {
|
|
127
|
-
alpha,
|
|
128
|
-
alphanumeric,
|
|
129
|
-
hashChars
|
|
130
|
-
} = getHashtagRegexStringChars();
|
|
131
|
-
const hashtagAlpha = '[' + alpha + ']';
|
|
132
|
-
const hashtagAlphanumeric = '[' + alphanumeric + ']';
|
|
133
|
-
const hashtagBoundary = '^|$|[^&/' + alphanumeric + ']';
|
|
134
|
-
const hashCharList = '[' + hashChars + ']';
|
|
135
|
-
|
|
136
|
-
// A hashtag contains characters, numbers and underscores,
|
|
137
|
-
// but not all numbers.
|
|
138
|
-
const hashtag = '(' + hashtagBoundary + ')(' + hashCharList + ')(' + hashtagAlphanumeric + '*' + hashtagAlpha + hashtagAlphanumeric + '*)';
|
|
139
|
-
return hashtag;
|
|
140
|
-
}
|
|
141
|
-
const REGEX = new RegExp(getHashtagRegexString(), 'i');
|
|
142
23
|
function HashtagPlugin() {
|
|
143
24
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
144
25
|
react.useEffect(() => {
|
|
145
26
|
if (!editor.hasNodes([hashtag.HashtagNode])) {
|
|
146
27
|
throw new Error('HashtagPlugin: HashtagNode not registered on editor');
|
|
147
28
|
}
|
|
29
|
+
return hashtag.registerLexicalHashtag(editor);
|
|
148
30
|
}, [editor]);
|
|
149
|
-
const $createHashtagNode_ = react.useCallback(textNode => {
|
|
150
|
-
return hashtag.$createHashtagNode(textNode.getTextContent());
|
|
151
|
-
}, []);
|
|
152
|
-
const getHashtagMatch = react.useCallback(text => {
|
|
153
|
-
const matchArr = REGEX.exec(text);
|
|
154
|
-
if (matchArr === null) {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
const hashtagLength = matchArr[3].length + 1;
|
|
158
|
-
const startOffset = matchArr.index + matchArr[1].length;
|
|
159
|
-
const endOffset = startOffset + hashtagLength;
|
|
160
|
-
return {
|
|
161
|
-
end: endOffset,
|
|
162
|
-
start: startOffset
|
|
163
|
-
};
|
|
164
|
-
}, []);
|
|
165
|
-
useLexicalTextEntity.useLexicalTextEntity(getHashtagMatch, hashtag.HashtagNode, $createHashtagNode_);
|
|
166
31
|
return null;
|
|
167
32
|
}
|
|
168
33
|
|