@lexical/react 0.2.7 → 0.3.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/DEPRECATED_useLexical.dev.js +55 -4
- package/DEPRECATED_useLexical.js.flow +23 -0
- package/DEPRECATED_useLexical.prod.js +3 -1
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +1 -2
- package/DEPRECATED_useLexicalAutoFormatter.js.flow +12 -0
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +1 -1
- package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +6 -8
- package/DEPRECATED_useLexicalCanShowPlaceholder.js.flow +12 -0
- package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +2 -1
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +5 -3
- package/DEPRECATED_useLexicalCharacterLimit.js.flow +28 -0
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +6 -6
- package/DEPRECATED_useLexicalDecorators.dev.js +7 -5
- package/DEPRECATED_useLexicalDecorators.js.flow +14 -0
- package/DEPRECATED_useLexicalDecorators.prod.js +2 -2
- package/DEPRECATED_useLexicalEditor.dev.js +55 -3
- package/DEPRECATED_useLexicalEditor.prod.js +2 -1
- package/DEPRECATED_useLexicalEditorEvents.dev.js +1 -5
- package/DEPRECATED_useLexicalEditorEvents.js.flow +19 -0
- package/DEPRECATED_useLexicalEditorEvents.prod.js +2 -2
- package/DEPRECATED_useLexicalHistory.dev.js +0 -2
- package/DEPRECATED_useLexicalHistory.js.flow +31 -0
- package/DEPRECATED_useLexicalHistory.prod.js +1 -1
- package/DEPRECATED_useLexicalList.dev.js +3 -5
- package/DEPRECATED_useLexicalList.js.flow +10 -0
- package/DEPRECATED_useLexicalList.prod.js +2 -2
- package/DEPRECATED_useLexicalPlainText.dev.js +1 -7
- package/DEPRECATED_useLexicalPlainText.js.flow +15 -0
- package/DEPRECATED_useLexicalPlainText.prod.js +2 -2
- package/DEPRECATED_useLexicalRichText.dev.js +1 -7
- package/DEPRECATED_useLexicalRichText.js.flow +15 -0
- package/DEPRECATED_useLexicalRichText.prod.js +2 -2
- package/LexicalAutoFocusPlugin.d.ts +1 -1
- package/LexicalAutoFocusPlugin.dev.js +17 -4
- package/LexicalAutoFocusPlugin.js.flow +1 -1
- package/LexicalAutoFocusPlugin.prod.js +1 -1
- package/LexicalAutoLinkPlugin.d.ts +1 -1
- package/LexicalAutoLinkPlugin.dev.js +4 -5
- package/LexicalAutoLinkPlugin.js.flow +2 -1
- package/LexicalAutoLinkPlugin.prod.js +5 -5
- package/LexicalAutoScrollPlugin.d.ts +2 -3
- package/LexicalAutoScrollPlugin.dev.js +2 -5
- package/LexicalAutoScrollPlugin.js.flow +1 -3
- package/LexicalAutoScrollPlugin.prod.js +2 -2
- package/LexicalBlockWithAlignableContents.d.ts +16 -0
- package/LexicalBlockWithAlignableContents.dev.js +7 -9
- package/LexicalBlockWithAlignableContents.prod.js +4 -4
- package/LexicalCharacterLimitPlugin.d.ts +1 -1
- package/LexicalCharacterLimitPlugin.dev.js +6 -5
- package/LexicalCharacterLimitPlugin.js.flow +1 -1
- package/LexicalCharacterLimitPlugin.prod.js +8 -8
- package/LexicalCheckListPlugin.d.ts +9 -0
- package/LexicalCheckListPlugin.dev.js +7 -15
- package/LexicalCheckListPlugin.js.flow +1 -1
- package/LexicalCheckListPlugin.prod.js +7 -7
- package/LexicalClearEditorPlugin.d.ts +2 -6
- package/LexicalClearEditorPlugin.dev.js +2 -5
- package/LexicalClearEditorPlugin.js.flow +1 -1
- package/LexicalClearEditorPlugin.prod.js +2 -2
- package/LexicalCollaborationPlugin.d.ts +3 -20
- package/LexicalCollaborationPlugin.dev.js +9 -5
- package/LexicalCollaborationPlugin.prod.js +9 -9
- package/LexicalComposer.d.ts +2 -2
- package/LexicalComposer.dev.js +1 -6
- package/LexicalComposer.js.flow +1 -1
- package/LexicalComposer.prod.js +2 -2
- package/LexicalComposerContext.dev.js +0 -1
- package/LexicalComposerContext.prod.js +1 -1
- package/LexicalContentEditable.d.ts +2 -5
- package/LexicalContentEditable.dev.js +5 -7
- package/LexicalContentEditable.js.flow +1 -3
- package/LexicalContentEditable.prod.js +3 -3
- package/LexicalDecoratorBlockNode.d.ts +32 -0
- package/LexicalDecoratorBlockNode.dev.js +8 -1
- package/LexicalDecoratorBlockNode.prod.js +1 -1
- package/LexicalHashtagPlugin.d.ts +1 -1
- package/LexicalHashtagPlugin.dev.js +2 -3
- package/LexicalHashtagPlugin.js.flow +1 -1
- package/LexicalHashtagPlugin.prod.js +3 -3
- package/LexicalHistoryPlugin.d.ts +1 -0
- package/LexicalHistoryPlugin.dev.js +0 -2
- package/LexicalHistoryPlugin.prod.js +1 -1
- package/LexicalHorizontalRuleNode.d.ts +1 -1
- package/LexicalHorizontalRuleNode.dev.js +11 -1
- package/LexicalHorizontalRuleNode.prod.js +3 -3
- package/LexicalLinkPlugin.d.ts +1 -1
- package/LexicalLinkPlugin.dev.js +3 -107
- package/LexicalLinkPlugin.js.flow +1 -1
- package/LexicalLinkPlugin.prod.js +1 -4
- package/LexicalListPlugin.d.ts +1 -1
- package/LexicalListPlugin.dev.js +9 -6
- package/LexicalListPlugin.js.flow +1 -1
- package/LexicalListPlugin.prod.js +3 -3
- package/LexicalMarkdownShortcutPlugin.d.ts +4 -2
- package/LexicalMarkdownShortcutPlugin.dev.js +7 -83
- package/LexicalMarkdownShortcutPlugin.js.flow +2 -2
- package/LexicalMarkdownShortcutPlugin.prod.js +2 -3
- package/LexicalNestedComposer.d.ts +2 -2
- package/LexicalNestedComposer.dev.js +1 -2
- package/LexicalNestedComposer.js.flow +1 -1
- package/LexicalNestedComposer.prod.js +3 -3
- package/LexicalOnChangePlugin.d.ts +2 -1
- package/LexicalOnChangePlugin.dev.js +1 -4
- package/LexicalOnChangePlugin.js.flow +1 -1
- package/LexicalOnChangePlugin.prod.js +2 -2
- package/LexicalPlainTextPlugin.d.ts +3 -2
- package/LexicalPlainTextPlugin.dev.js +12 -10
- package/LexicalPlainTextPlugin.js.flow +1 -1
- package/LexicalPlainTextPlugin.prod.js +4 -4
- package/LexicalRichTextPlugin.d.ts +3 -2
- package/LexicalRichTextPlugin.dev.js +12 -10
- package/LexicalRichTextPlugin.js.flow +1 -1
- package/LexicalRichTextPlugin.prod.js +4 -4
- package/LexicalTablePlugin.d.ts +1 -1
- package/LexicalTablePlugin.dev.js +7 -8
- package/LexicalTablePlugin.js.flow +1 -1
- package/LexicalTablePlugin.prod.js +4 -4
- package/LexicalTreeView.d.ts +2 -1
- package/LexicalTreeView.dev.js +4 -5
- package/LexicalTreeView.js.flow +1 -1
- package/LexicalTreeView.prod.js +11 -11
- package/README.md +10 -6
- package/package.json +19 -19
- package/useLexicalIsTextContentEmpty.d.ts +2 -1
- package/useLexicalIsTextContentEmpty.dev.js +2 -5
- package/useLexicalIsTextContentEmpty.js.flow +1 -1
- package/useLexicalIsTextContentEmpty.prod.js +1 -1
- package/useLexicalNodeSelection.d.ts +2 -1
- package/useLexicalNodeSelection.dev.js +1 -2
- package/useLexicalNodeSelection.js.flow +1 -1
- package/useLexicalNodeSelection.prod.js +2 -2
- package/useLexicalTextEntity.d.ts +2 -1
- package/useLexicalTextEntity.dev.js +1 -2
- package/useLexicalTextEntity.js.flow +1 -1
- package/useLexicalTextEntity.prod.js +1 -1
|
@@ -20,7 +20,6 @@ var utils = require('@lexical/utils');
|
|
|
20
20
|
* This source code is licensed under the MIT license found in the
|
|
21
21
|
* LICENSE file in the root directory of this source tree.
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
23
|
*/
|
|
25
24
|
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
26
25
|
|
|
@@ -30,7 +29,6 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
30
29
|
* This source code is licensed under the MIT license found in the
|
|
31
30
|
* LICENSE file in the root directory of this source tree.
|
|
32
31
|
*
|
|
33
|
-
*
|
|
34
32
|
*/
|
|
35
33
|
const useLayoutEffectImpl = CAN_USE_DOM ? React.useLayoutEffect : React.useEffect;
|
|
36
34
|
var useLayoutEffect = useLayoutEffectImpl;
|
|
@@ -41,16 +39,17 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
41
39
|
* This source code is licensed under the MIT license found in the
|
|
42
40
|
* LICENSE file in the root directory of this source tree.
|
|
43
41
|
*
|
|
44
|
-
*
|
|
45
42
|
*/
|
|
46
|
-
function
|
|
43
|
+
function useCanShowPlaceholder(editor) {
|
|
47
44
|
const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
|
|
48
45
|
useLayoutEffect(() => {
|
|
46
|
+
let currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
|
|
47
|
+
setCanShowPlaceholder(currentCanShowPlaceholder);
|
|
49
48
|
return editor.registerUpdateListener(({
|
|
50
49
|
editorState
|
|
51
50
|
}) => {
|
|
52
51
|
const isComposing = editor.isComposing();
|
|
53
|
-
|
|
52
|
+
currentCanShowPlaceholder = editorState.read(text.$canShowPlaceholderCurry(isComposing));
|
|
54
53
|
setCanShowPlaceholder(currentCanShowPlaceholder);
|
|
55
54
|
});
|
|
56
55
|
}, [editor]);
|
|
@@ -63,7 +62,6 @@ function useLexicalCanShowPlaceholder(editor) {
|
|
|
63
62
|
* This source code is licensed under the MIT license found in the
|
|
64
63
|
* LICENSE file in the root directory of this source tree.
|
|
65
64
|
*
|
|
66
|
-
*
|
|
67
65
|
*/
|
|
68
66
|
function useDecorators(editor) {
|
|
69
67
|
const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
|
|
@@ -74,6 +72,12 @@ function useDecorators(editor) {
|
|
|
74
72
|
setDecorators(nextDecorators);
|
|
75
73
|
});
|
|
76
74
|
});
|
|
75
|
+
}, [editor]);
|
|
76
|
+
React.useEffect(() => {
|
|
77
|
+
// If the content editable mounts before the subscription is added, then
|
|
78
|
+
// nothing will be rendered on initial pass. We can get around that by
|
|
79
|
+
// ensuring that we set the value.
|
|
80
|
+
setDecorators(editor.getDecorators());
|
|
77
81
|
}, [editor]); // Return decorators defined as React Portals
|
|
78
82
|
|
|
79
83
|
return React.useMemo(() => {
|
|
@@ -100,7 +104,6 @@ function useDecorators(editor) {
|
|
|
100
104
|
* This source code is licensed under the MIT license found in the
|
|
101
105
|
* LICENSE file in the root directory of this source tree.
|
|
102
106
|
*
|
|
103
|
-
*
|
|
104
107
|
*/
|
|
105
108
|
function usePlainTextSetup(editor, initialEditorState) {
|
|
106
109
|
useLayoutEffect(() => {
|
|
@@ -115,7 +118,6 @@ function usePlainTextSetup(editor, initialEditorState) {
|
|
|
115
118
|
* This source code is licensed under the MIT license found in the
|
|
116
119
|
* LICENSE file in the root directory of this source tree.
|
|
117
120
|
*
|
|
118
|
-
*
|
|
119
121
|
*/
|
|
120
122
|
function PlainTextPlugin({
|
|
121
123
|
contentEditable,
|
|
@@ -123,10 +125,10 @@ function PlainTextPlugin({
|
|
|
123
125
|
initialEditorState
|
|
124
126
|
}) {
|
|
125
127
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
126
|
-
const showPlaceholder =
|
|
128
|
+
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
127
129
|
usePlainTextSetup(editor, initialEditorState);
|
|
128
130
|
const decorators = useDecorators(editor);
|
|
129
131
|
return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, showPlaceholder && placeholder, decorators);
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
|
|
134
|
+
exports.PlainTextPlugin = PlainTextPlugin;
|
|
@@ -11,7 +11,7 @@ import type {EditorState} from 'lexical';
|
|
|
11
11
|
|
|
12
12
|
type InitialEditorStateType = null | string | EditorState | (() => void);
|
|
13
13
|
|
|
14
|
-
declare export
|
|
14
|
+
declare export function PlainTextPlugin({
|
|
15
15
|
contentEditable: React$Node,
|
|
16
16
|
initialEditorState?: InitialEditorStateType,
|
|
17
17
|
placeholder: React$Node,
|
|
@@ -4,7 +4,7 @@
|
|
|
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
|
-
var
|
|
8
|
-
function t(a){
|
|
9
|
-
function u(a){
|
|
10
|
-
|
|
7
|
+
'use strict';var e=require("@lexical/react/LexicalComposerContext"),h=require("react"),k=require("@lexical/text"),m=require("react-dom"),n=require("@lexical/dragon"),p=require("@lexical/plain-text"),q=require("@lexical/utils"),r="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
|
|
8
|
+
function t(a){let [c,d]=h.useState(a.getEditorState().read(k.$canShowPlaceholderCurry(a.isComposing())));r(()=>{let b=a.getEditorState().read(k.$canShowPlaceholderCurry(a.isComposing()));d(b);return a.registerUpdateListener(({editorState:g})=>{let f=a.isComposing();b=g.read(k.$canShowPlaceholderCurry(f));d(b)})},[a]);return c}
|
|
9
|
+
function u(a){let [c,d]=h.useState(()=>a.getDecorators());r(()=>a.registerDecoratorListener(b=>{m.flushSync(()=>{d(b)})}),[a]);h.useEffect(()=>{d(a.getDecorators())},[a]);return h.useMemo(()=>{let b=[],g=Object.keys(c);for(let l=0;l<g.length;l++){var f=g[l];let v=c[f];f=a.getElementByKey(f);null!==f&&b.push(m.createPortal(v,f))}return b},[c,a])}function w(a,c){r(()=>q.mergeRegister(p.registerPlainText(a,c),n.registerDragonSupport(a)),[a])}
|
|
10
|
+
exports.PlainTextPlugin=function({contentEditable:a,placeholder:c,initialEditorState:d}){let [b]=e.useLexicalComposerContext(),g=t(b);w(b,d);d=u(b);return h.createElement(h.Fragment,null,a,g&&c,d)}
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type {EditorState} from 'lexical';
|
|
10
|
+
|
|
10
11
|
type InitialEditorStateType = null | string | EditorState | (() => void);
|
|
11
|
-
export
|
|
12
|
+
export function RichTextPlugin(arg0: {
|
|
12
13
|
contentEditable: JSX.Element | null;
|
|
13
14
|
initialEditorState?: InitialEditorStateType;
|
|
14
|
-
placeholder: JSX.Element | null;
|
|
15
|
+
placeholder: JSX.Element | string | null;
|
|
15
16
|
}): JSX.Element | null;
|
|
@@ -20,7 +20,6 @@ var utils = require('@lexical/utils');
|
|
|
20
20
|
* This source code is licensed under the MIT license found in the
|
|
21
21
|
* LICENSE file in the root directory of this source tree.
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
23
|
*/
|
|
25
24
|
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
26
25
|
|
|
@@ -30,7 +29,6 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
30
29
|
* This source code is licensed under the MIT license found in the
|
|
31
30
|
* LICENSE file in the root directory of this source tree.
|
|
32
31
|
*
|
|
33
|
-
*
|
|
34
32
|
*/
|
|
35
33
|
const useLayoutEffectImpl = CAN_USE_DOM ? React.useLayoutEffect : React.useEffect;
|
|
36
34
|
var useLayoutEffect = useLayoutEffectImpl;
|
|
@@ -41,16 +39,17 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
41
39
|
* This source code is licensed under the MIT license found in the
|
|
42
40
|
* LICENSE file in the root directory of this source tree.
|
|
43
41
|
*
|
|
44
|
-
*
|
|
45
42
|
*/
|
|
46
|
-
function
|
|
43
|
+
function useCanShowPlaceholder(editor) {
|
|
47
44
|
const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
|
|
48
45
|
useLayoutEffect(() => {
|
|
46
|
+
let currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
|
|
47
|
+
setCanShowPlaceholder(currentCanShowPlaceholder);
|
|
49
48
|
return editor.registerUpdateListener(({
|
|
50
49
|
editorState
|
|
51
50
|
}) => {
|
|
52
51
|
const isComposing = editor.isComposing();
|
|
53
|
-
|
|
52
|
+
currentCanShowPlaceholder = editorState.read(text.$canShowPlaceholderCurry(isComposing));
|
|
54
53
|
setCanShowPlaceholder(currentCanShowPlaceholder);
|
|
55
54
|
});
|
|
56
55
|
}, [editor]);
|
|
@@ -63,7 +62,6 @@ function useLexicalCanShowPlaceholder(editor) {
|
|
|
63
62
|
* This source code is licensed under the MIT license found in the
|
|
64
63
|
* LICENSE file in the root directory of this source tree.
|
|
65
64
|
*
|
|
66
|
-
*
|
|
67
65
|
*/
|
|
68
66
|
function useDecorators(editor) {
|
|
69
67
|
const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
|
|
@@ -74,6 +72,12 @@ function useDecorators(editor) {
|
|
|
74
72
|
setDecorators(nextDecorators);
|
|
75
73
|
});
|
|
76
74
|
});
|
|
75
|
+
}, [editor]);
|
|
76
|
+
React.useEffect(() => {
|
|
77
|
+
// If the content editable mounts before the subscription is added, then
|
|
78
|
+
// nothing will be rendered on initial pass. We can get around that by
|
|
79
|
+
// ensuring that we set the value.
|
|
80
|
+
setDecorators(editor.getDecorators());
|
|
77
81
|
}, [editor]); // Return decorators defined as React Portals
|
|
78
82
|
|
|
79
83
|
return React.useMemo(() => {
|
|
@@ -100,7 +104,6 @@ function useDecorators(editor) {
|
|
|
100
104
|
* This source code is licensed under the MIT license found in the
|
|
101
105
|
* LICENSE file in the root directory of this source tree.
|
|
102
106
|
*
|
|
103
|
-
*
|
|
104
107
|
*/
|
|
105
108
|
function useRichTextSetup(editor, initialEditorState) {
|
|
106
109
|
useLayoutEffect(() => {
|
|
@@ -115,7 +118,6 @@ function useRichTextSetup(editor, initialEditorState) {
|
|
|
115
118
|
* This source code is licensed under the MIT license found in the
|
|
116
119
|
* LICENSE file in the root directory of this source tree.
|
|
117
120
|
*
|
|
118
|
-
*
|
|
119
121
|
*/
|
|
120
122
|
function RichTextPlugin({
|
|
121
123
|
contentEditable,
|
|
@@ -123,10 +125,10 @@ function RichTextPlugin({
|
|
|
123
125
|
initialEditorState
|
|
124
126
|
}) {
|
|
125
127
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
126
|
-
const showPlaceholder =
|
|
128
|
+
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
127
129
|
useRichTextSetup(editor, initialEditorState);
|
|
128
130
|
const decorators = useDecorators(editor);
|
|
129
131
|
return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, showPlaceholder && placeholder, decorators);
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
|
|
134
|
+
exports.RichTextPlugin = RichTextPlugin;
|
|
@@ -11,7 +11,7 @@ import type {EditorState} from 'lexical';
|
|
|
11
11
|
|
|
12
12
|
type InitialEditorStateType = null | string | EditorState | (() => void);
|
|
13
13
|
|
|
14
|
-
declare export
|
|
14
|
+
declare export function RichTextPlugin({
|
|
15
15
|
contentEditable: React$Node,
|
|
16
16
|
initialEditorState?: InitialEditorStateType,
|
|
17
17
|
placeholder: React$Node,
|
|
@@ -4,7 +4,7 @@
|
|
|
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
|
-
var
|
|
8
|
-
function t(a){
|
|
9
|
-
function u(a){
|
|
10
|
-
|
|
7
|
+
'use strict';var e=require("@lexical/react/LexicalComposerContext"),h=require("react"),k=require("@lexical/text"),m=require("react-dom"),n=require("@lexical/dragon"),p=require("@lexical/rich-text"),q=require("@lexical/utils"),r="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
|
|
8
|
+
function t(a){let [c,d]=h.useState(a.getEditorState().read(k.$canShowPlaceholderCurry(a.isComposing())));r(()=>{let b=a.getEditorState().read(k.$canShowPlaceholderCurry(a.isComposing()));d(b);return a.registerUpdateListener(({editorState:g})=>{let f=a.isComposing();b=g.read(k.$canShowPlaceholderCurry(f));d(b)})},[a]);return c}
|
|
9
|
+
function u(a){let [c,d]=h.useState(()=>a.getDecorators());r(()=>a.registerDecoratorListener(b=>{m.flushSync(()=>{d(b)})}),[a]);h.useEffect(()=>{d(a.getDecorators())},[a]);return h.useMemo(()=>{let b=[],g=Object.keys(c);for(let l=0;l<g.length;l++){var f=g[l];let v=c[f];f=a.getElementByKey(f);null!==f&&b.push(m.createPortal(v,f))}return b},[c,a])}function w(a,c){r(()=>q.mergeRegister(p.registerRichText(a,c),n.registerDragonSupport(a)),[a])}
|
|
10
|
+
exports.RichTextPlugin=function({contentEditable:a,placeholder:c,initialEditorState:d}){let [b]=e.useLexicalComposerContext(),g=t(b);w(b,d);d=u(b);return h.createElement(h.Fragment,null,a,g&&c,d)}
|
package/LexicalTablePlugin.d.ts
CHANGED
|
@@ -17,7 +17,6 @@ var react = require('react');
|
|
|
17
17
|
* This source code is licensed under the MIT license found in the
|
|
18
18
|
* LICENSE file in the root directory of this source tree.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
20
|
*/
|
|
22
21
|
function TablePlugin() {
|
|
23
22
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
@@ -28,11 +27,11 @@ function TablePlugin() {
|
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
return editor.registerCommand(table.INSERT_TABLE_COMMAND,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
return editor.registerCommand(table.INSERT_TABLE_COMMAND, ({
|
|
31
|
+
columns,
|
|
32
|
+
rows,
|
|
33
|
+
includeHeaders
|
|
34
|
+
}) => {
|
|
36
35
|
const selection = lexical.$getSelection();
|
|
37
36
|
|
|
38
37
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -43,7 +42,7 @@ function TablePlugin() {
|
|
|
43
42
|
const focusNode = focus.getNode();
|
|
44
43
|
|
|
45
44
|
if (focusNode !== null) {
|
|
46
|
-
const tableNode = table.$createTableNodeWithDimensions(Number(rows), Number(columns));
|
|
45
|
+
const tableNode = table.$createTableNodeWithDimensions(Number(rows), Number(columns), includeHeaders);
|
|
47
46
|
|
|
48
47
|
if (lexical.$isRootNode(focusNode)) {
|
|
49
48
|
const target = focusNode.getChildAtIndex(focus.offset);
|
|
@@ -96,4 +95,4 @@ function TablePlugin() {
|
|
|
96
95
|
return null;
|
|
97
96
|
}
|
|
98
97
|
|
|
99
|
-
|
|
98
|
+
exports.TablePlugin = TablePlugin;
|
|
@@ -4,7 +4,7 @@
|
|
|
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
|
-
var e=require("@lexical/react/LexicalComposerContext"),f=require("@lexical/table"),k=require("lexical"),m=require("react");
|
|
8
|
-
|
|
9
|
-
Number(
|
|
10
|
-
|
|
7
|
+
'use strict';var e=require("@lexical/react/LexicalComposerContext"),f=require("@lexical/table"),k=require("lexical"),m=require("react");
|
|
8
|
+
exports.TablePlugin=function(){let [c]=e.useLexicalComposerContext();m.useEffect(()=>{if(!c.hasNodes([f.TableNode,f.TableCellNode,f.TableRowNode]))throw Error("Minified Lexical error #10; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return c.registerCommand(f.INSERT_TABLE_COMMAND,({columns:a,rows:d,includeHeaders:g})=>{var b=k.$getSelection();if(!k.$isRangeSelection(b))return!0;let h=b.focus;b=h.getNode();null!==b&&
|
|
9
|
+
(a=f.$createTableNodeWithDimensions(Number(d),Number(a),g),k.$isRootNode(b)?(d=b.getChildAtIndex(h.offset),null!==d?d.insertBefore(a):b.append(a),a.insertBefore(k.$createParagraphNode())):b.getTopLevelElementOrThrow().insertAfter(a),a.insertAfter(k.$createParagraphNode()),a.getFirstChildOrThrow().getFirstChildOrThrow().select());return!0},k.COMMAND_PRIORITY_EDITOR)},[c]);m.useEffect(()=>{let a=new Map;return c.registerMutationListener(f.TableNode,d=>{for(let [g,b]of d)"created"===b?c.update(()=>{var h=
|
|
10
|
+
c.getElementByKey(g);let l=k.$getNodeByKey(g);h&&l&&(h=f.applyTableHandlers(l,h,c),a.set(g,h))}):"destroyed"===b&&(d=a.get(g))&&(d.removeListeners(),a.delete(g))})},[c]);return null}
|
package/LexicalTreeView.d.ts
CHANGED
package/LexicalTreeView.dev.js
CHANGED
|
@@ -16,7 +16,6 @@ var React = require('react');
|
|
|
16
16
|
* This source code is licensed under the MIT license found in the
|
|
17
17
|
* LICENSE file in the root directory of this source tree.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
19
|
*/
|
|
21
20
|
const NON_SINGLE_WIDTH_CHARS_REPLACEMENT = Object.freeze({
|
|
22
21
|
'\t': '\\t',
|
|
@@ -101,10 +100,10 @@ function TreeView({
|
|
|
101
100
|
const element = treeElementRef.current;
|
|
102
101
|
|
|
103
102
|
if (element !== null) {
|
|
104
|
-
//
|
|
103
|
+
// @ts-ignore Internal field
|
|
105
104
|
element.__lexicalEditor = editor;
|
|
106
105
|
return () => {
|
|
107
|
-
//
|
|
106
|
+
// @ts-ignore Internal field
|
|
108
107
|
element.__lexicalEditor = null;
|
|
109
108
|
};
|
|
110
109
|
}
|
|
@@ -309,7 +308,7 @@ function printSelectedCharsLine({
|
|
|
309
308
|
|
|
310
309
|
const selectionLastIndent = indent[indent.length - 1] === SYMBOLS.hasNextSibling ? SYMBOLS.ancestorHasNextSibling : SYMBOLS.ancestorIsLastChild;
|
|
311
310
|
const indentionChars = [...indent.slice(0, indent.length - 1), selectionLastIndent];
|
|
312
|
-
const unselectedChars = Array(start).fill(' ');
|
|
311
|
+
const unselectedChars = Array(start + 1).fill(' ');
|
|
313
312
|
const selectedChars = Array(end - start).fill(SYMBOLS.selectedChar);
|
|
314
313
|
const paddingLength = typeDisplay.length + 3; // 2 for the spaces around + 1 for the double quote.
|
|
315
314
|
|
|
@@ -347,4 +346,4 @@ function $getSelectionStartEnd(node, selection) {
|
|
|
347
346
|
return [start + numNonSingleWidthCharBeforeSelection, end + numNonSingleWidthCharBeforeSelection + numNonSingleWidthCharInSelection];
|
|
348
347
|
}
|
|
349
348
|
|
|
350
|
-
|
|
349
|
+
exports.TreeView = TreeView;
|
package/LexicalTreeView.js.flow
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import type {LexicalEditor} from 'lexical';
|
|
11
11
|
|
|
12
|
-
declare export
|
|
12
|
+
declare export function TreeView(props: {
|
|
13
13
|
timeTravelPanelClassName: string,
|
|
14
14
|
timeTravelPanelSliderClassName: string,
|
|
15
15
|
timeTravelPanelButtonClassName: string,
|
package/LexicalTreeView.prod.js
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
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
|
-
var l=require("@lexical/mark"),p=require("lexical"),r=require("react");
|
|
8
|
-
function G(a){let b=""
|
|
9
|
-
function J(a){let b=" root\n";a=a.read(()=>{const c=p.$getSelection();K(p.$getRoot(),(e,d)=>{const f=`(${e.getKey()})`,g=e.getType()||"",m=e.isSelected(),v=l.$isMarkNode(e)?` id: [ ${e.getIDs().join(", ")} ] `:"";var u=b,q=m?F.selectedLine:" ",w=d.join(" ");if(p.$isTextNode(e)){var k=e.getTextContent(!0);
|
|
7
|
+
'use strict';var l=require("@lexical/mark"),p=require("lexical"),r=require("react");let D=Object.freeze({"\t":"\\t","\n":"\\n"}),E=new RegExp(Object.keys(D).join("|"),"g"),F=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
|
|
8
|
+
function G(a){let b="",c=H(a),e=a.anchor;a=a.focus;let d=e.offset,f=a.offset;b=b+`: range ${""!==c?`{ ${c} }`:""}`+`\n \u251c anchor { key: ${e.key}, offset: ${null===d?"null":d}, type: ${e.type} }`;return b+=`\n \u2514 focus { key: ${a.key}, offset: ${null===f?"null":f}, type: ${a.type} }`}
|
|
9
|
+
function J(a){let b=" root\n";a=a.read(()=>{const c=p.$getSelection();K(p.$getRoot(),(e,d)=>{const f=`(${e.getKey()})`,g=e.getType()||"",m=e.isSelected(),v=l.$isMarkNode(e)?` id: [ ${e.getIDs().join(", ")} ] `:"";var u=b,q=m?F.selectedLine:" ",w=d.join(" ");if(p.$isTextNode(e)){var k=e.getTextContent(!0);let t=0===k.length?"(empty)":`"${L(k)}"`;k=[H(e),M(e),N(e)].filter(Boolean).join(", ");k=[t,0!==k.length?`{ ${k} }`:null].filter(Boolean).join(" ").trim()}else k="";b=u+`${q} ${w} ${f} ${g} ${v} ${k}\n`;
|
|
10
10
|
b+=O({indent:d,isSelected:m,node:e,nodeKeyDisplay:f,selection:c,typeDisplay:g})});return null===c?": null":p.$isRangeSelection(c)?G(c):p.$isGridSelection(c)?`: grid\n \u2514 { grid: ${c.gridKey}, anchorCell: ${c.anchor.key}, focusCell: ${c.focus.key} }`:`: node\n \u2514 [${Array.from(c._nodes).join(", ")}]`});return b+"\n selection"+a}
|
|
11
|
-
function K(a,b,c=[]){a=a.getChildren();
|
|
12
|
-
|
|
11
|
+
function K(a,b,c=[]){a=a.getChildren();let e=a.length;a.forEach((d,f)=>{b(d,c.concat(f===e-1?F.isLastChild:F.hasNextSibling));p.$isElementNode(d)&&K(d,b,c.concat(f===e-1?F.ancestorIsLastChild:F.ancestorHasNextSibling))})}function L(a){return Object.entries(D).reduce((b,[c,e])=>b.replace(new RegExp(c,"g"),String(e)),a)}
|
|
12
|
+
let P=[a=>a.hasFormat("bold")&&"Bold",a=>a.hasFormat("code")&&"Code",a=>a.hasFormat("italic")&&"Italic",a=>a.hasFormat("strikethrough")&&"Strikethrough",a=>a.hasFormat("subscript")&&"Subscript",a=>a.hasFormat("superscript")&&"Superscript",a=>a.hasFormat("underline")&&"Underline"],Q=[a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"],R=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented",a=>a.isInert()&&"Inert"];
|
|
13
13
|
function M(a){let b=Q.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="detail: "+b);return b}function N(a){let b=R.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="mode: "+b);return b}function H(a){let b=P.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="format: "+b);return b}
|
|
14
|
-
function O({indent:a,isSelected:b,node:c,nodeKeyDisplay:e,selection:d,typeDisplay:f}){if(!p.$isTextNode(c)||!p.$isRangeSelection(d)||!b||p.$isElementNode(c))return"";b=d.anchor;var g=d.focus;if(""===c.getTextContent()||b.getNode()===d.focus.getNode()&&b.offset===g.offset)return"";g=d.anchor;
|
|
15
|
-
g.offset]:c===k?[d,b]=k.isBefore(t)?[g.offset,u]:[0,g.offset]:c===t?[d,b]=t.isBefore(k)?[m.offset,u]:[0,m.offset]:[d,b]=[0,u]}c=(v.slice(0,d).match(E)||[]).length;g=(v.slice(d,b).match(E)||[]).length;
|
|
14
|
+
function O({indent:a,isSelected:b,node:c,nodeKeyDisplay:e,selection:d,typeDisplay:f}){if(!p.$isTextNode(c)||!p.$isRangeSelection(d)||!b||p.$isElementNode(c))return"";b=d.anchor;var g=d.focus;if(""===c.getTextContent()||b.getNode()===d.focus.getNode()&&b.offset===g.offset)return"";g=d.anchor;let m=d.focus,v=c.getTextContent(!0),u=v.length;b=d=-1;if("text"===g.type&&"text"===m.type){let k=g.getNode(),t=m.getNode();k===t&&c===k&&g.offset!==m.offset?[d,b]=g.offset<m.offset?[g.offset,m.offset]:[m.offset,
|
|
15
|
+
g.offset]:c===k?[d,b]=k.isBefore(t)?[g.offset,u]:[0,g.offset]:c===t?[d,b]=t.isBefore(k)?[m.offset,u]:[0,m.offset]:[d,b]=[0,u]}c=(v.slice(0,d).match(E)||[]).length;g=(v.slice(d,b).match(E)||[]).length;let [q,w]=[d+c,b+c+g];if(q===w)return"";c=a[a.length-1]===F.hasNextSibling?F.ancestorHasNextSibling:F.ancestorIsLastChild;a=[...a.slice(0,a.length-1),c];c=Array(q+1).fill(" ");d=Array(w-q).fill(F.selectedChar);e=Array(e.length+(f.length+3)).fill(" ");return[F.selectedLine,a.join(" "),[...e,...c,...d].join("")].join(" ")+
|
|
16
16
|
"\n"}
|
|
17
|
-
|
|
18
|
-
m(A=>[...A,[Date.now(),h]])})},[q,f]);
|
|
19
|
-
{
|
|
20
|
-
if(null!==h){h.contentEditable="true";h=g.length-1;f.setEditorState(g[h][1]);
|
|
17
|
+
exports.TreeView=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:e,timeTravelPanelClassName:d,editor:f}){let [g,m]=r.useState([]),[v,u]=r.useState(""),[q,w]=r.useState(!1),k=r.useRef(0),t=r.useRef(null),B=r.useRef(null),[z,C]=r.useState(!1);r.useEffect(()=>{u(J(f.getEditorState()));return f.registerUpdateListener(({editorState:h})=>{let n=f._compositionKey,x=J(f.getEditorState());u([x,null!==n&&`Composition key: ${n}`].filter(Boolean).join("\n\n"));q||
|
|
18
|
+
m(A=>[...A,[Date.now(),h]])})},[q,f]);let y=g.length;r.useEffect(()=>{if(z){let h,n=()=>{const x=k.current;x===y-1?C(!1):h=setTimeout(()=>{k.current++;const A=k.current,I=B.current;null!==I&&(I.value=String(A));f.setEditorState(g[A][1]);n()},g[x+1][0]-g[x][0])};n();return()=>{window.clearTimeout(h)}}},[g,z,f,y]);r.useEffect(()=>{let h=t.current;if(null!==h)return h.__lexicalEditor=f,()=>{h.__lexicalEditor=null}},[f]);return r.createElement("div",{className:e},!q&&2<y&&r.createElement("button",{onClick:()=>
|
|
19
|
+
{let h=f.getRootElement();null!==h&&(h.contentEditable="false",k.current=y-1,w(!0))},className:a},"Time Travel"),r.createElement("pre",{ref:t},v),q&&r.createElement("div",{className:d},r.createElement("button",{className:c,onClick:()=>{C(!z)}},z?"Pause":"Play"),r.createElement("input",{className:b,ref:B,onChange:h=>{h=Number(h.target.value);let n=g[h];n&&(k.current=h,f.setEditorState(n[1]))},type:"range",min:"1",max:y-1}),r.createElement("button",{className:c,onClick:()=>{var h=f.getRootElement();
|
|
20
|
+
if(null!==h){h.contentEditable="true";h=g.length-1;f.setEditorState(g[h][1]);let n=B.current;null!==n&&(n.value=String(h));w(!1);C(!1)}}},"Exit")))}
|
package/README.md
CHANGED
|
@@ -16,11 +16,11 @@ Below is an example of a basic plain text editor using `lexical` and `@lexical/r
|
|
|
16
16
|
import {$getRoot, $getSelection} from 'lexical';
|
|
17
17
|
import {useEffect} from 'react';
|
|
18
18
|
|
|
19
|
-
import LexicalComposer from '@lexical/react/LexicalComposer';
|
|
20
|
-
import LexicalPlainTextPlugin from '@lexical/react/LexicalPlainTextPlugin';
|
|
21
|
-
import LexicalContentEditable from '@lexical/react/LexicalContentEditable';
|
|
19
|
+
import {LexicalComposer} from '@lexical/react/LexicalComposer';
|
|
20
|
+
import {LexicalPlainTextPlugin} from '@lexical/react/LexicalPlainTextPlugin';
|
|
21
|
+
import {LexicalContentEditable} from '@lexical/react/LexicalContentEditable';
|
|
22
22
|
import {HistoryPlugin} from '@lexical/react/LexicalHistoryPlugin';
|
|
23
|
-
import LexicalOnChangePlugin from '@lexical/react/LexicalOnChangePlugin';
|
|
23
|
+
import {LexicalOnChangePlugin} from '@lexical/react/LexicalOnChangePlugin';
|
|
24
24
|
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
|
25
25
|
|
|
26
26
|
const theme = {
|
|
@@ -47,7 +47,9 @@ function onChange(editorState) {
|
|
|
47
47
|
function MyCustomAutoFocusPlugin() {
|
|
48
48
|
const [editor] = useLexicalComposerContext();
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
51
53
|
// Focus the editor when the effect fires!
|
|
52
54
|
editor.focus();
|
|
53
55
|
}, [editor]);
|
|
@@ -68,7 +70,9 @@ function Editor() {
|
|
|
68
70
|
onError,
|
|
69
71
|
};
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
return (
|
|
72
76
|
<LexicalComposer initialConfig={initialConfig}>
|
|
73
77
|
<LexicalPlainTextPlugin
|
|
74
78
|
contentEditable={<LexicalContentEditable />}
|
package/package.json
CHANGED
|
@@ -8,28 +8,28 @@
|
|
|
8
8
|
"rich-text"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.3.0",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.
|
|
14
|
-
"@lexical/list": "0.
|
|
15
|
-
"@lexical/table": "0.
|
|
16
|
-
"@lexical/yjs": "0.
|
|
17
|
-
"@lexical/hashtag": "0.
|
|
18
|
-
"@lexical/selection": "0.
|
|
19
|
-
"@lexical/utils": "0.
|
|
20
|
-
"@lexical/dragon": "0.
|
|
21
|
-
"@lexical/plain-text": "0.
|
|
22
|
-
"@lexical/rich-text": "0.
|
|
23
|
-
"@lexical/code": "0.
|
|
24
|
-
"@lexical/text": "0.
|
|
25
|
-
"@lexical/link": "0.
|
|
26
|
-
"@lexical/overflow": "0.
|
|
27
|
-
"@lexical/history": "0.
|
|
28
|
-
"@lexical/markdown": "0.
|
|
29
|
-
"@lexical/mark": "0.
|
|
13
|
+
"@lexical/clipboard": "0.3.0",
|
|
14
|
+
"@lexical/list": "0.3.0",
|
|
15
|
+
"@lexical/table": "0.3.0",
|
|
16
|
+
"@lexical/yjs": "0.3.0",
|
|
17
|
+
"@lexical/hashtag": "0.3.0",
|
|
18
|
+
"@lexical/selection": "0.3.0",
|
|
19
|
+
"@lexical/utils": "0.3.0",
|
|
20
|
+
"@lexical/dragon": "0.3.0",
|
|
21
|
+
"@lexical/plain-text": "0.3.0",
|
|
22
|
+
"@lexical/rich-text": "0.3.0",
|
|
23
|
+
"@lexical/code": "0.3.0",
|
|
24
|
+
"@lexical/text": "0.3.0",
|
|
25
|
+
"@lexical/link": "0.3.0",
|
|
26
|
+
"@lexical/overflow": "0.3.0",
|
|
27
|
+
"@lexical/history": "0.3.0",
|
|
28
|
+
"@lexical/markdown": "0.3.0",
|
|
29
|
+
"@lexical/mark": "0.3.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"lexical": "0.
|
|
32
|
+
"lexical": "0.3.0",
|
|
33
33
|
"react": ">=17.x",
|
|
34
34
|
"react-dom": ">=17.x"
|
|
35
35
|
},
|
|
@@ -15,7 +15,6 @@ var react = require('react');
|
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
18
|
*/
|
|
20
19
|
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
21
20
|
|
|
@@ -25,18 +24,16 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
25
24
|
* This source code is licensed under the MIT license found in the
|
|
26
25
|
* LICENSE file in the root directory of this source tree.
|
|
27
26
|
*
|
|
28
|
-
*
|
|
29
27
|
*/
|
|
30
28
|
const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
|
|
31
29
|
var useLayoutEffect = useLayoutEffectImpl;
|
|
32
30
|
|
|
33
31
|
/**
|
|
34
|
-
* Copyright (c)
|
|
32
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
35
33
|
*
|
|
36
34
|
* This source code is licensed under the MIT license found in the
|
|
37
35
|
* LICENSE file in the root directory of this source tree.
|
|
38
36
|
*
|
|
39
|
-
*
|
|
40
37
|
*/
|
|
41
38
|
function useLexicalIsTextContentEmpty(editor, trim) {
|
|
42
39
|
const [isEmpty, setIsEmpty] = react.useState(editor.getEditorState().read(text.$isRootTextContentEmptyCurry(editor.isComposing(), trim)));
|
|
@@ -52,4 +49,4 @@ function useLexicalIsTextContentEmpty(editor, trim) {
|
|
|
52
49
|
return isEmpty;
|
|
53
50
|
}
|
|
54
51
|
|
|
55
|
-
|
|
52
|
+
exports.useLexicalIsTextContentEmpty = useLexicalIsTextContentEmpty;
|
|
@@ -4,4 +4,4 @@
|
|
|
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
|
-
var b=require("@lexical/text"),e=require("react"),f="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?e.useLayoutEffect:e.useEffect;
|
|
7
|
+
'use strict';var b=require("@lexical/text"),e=require("react"),f="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?e.useLayoutEffect:e.useEffect;exports.useLexicalIsTextContentEmpty=function(a,c){let [g,h]=e.useState(a.getEditorState().read(b.$isRootTextContentEmptyCurry(a.isComposing(),c)));f(()=>a.registerUpdateListener(({editorState:d})=>{let k=a.isComposing();d=d.read(b.$isRootTextContentEmptyCurry(k,c));h(d)}),[a,c]);return g}
|
|
@@ -16,7 +16,6 @@ var react = require('react');
|
|
|
16
16
|
* This source code is licensed under the MIT license found in the
|
|
17
17
|
* LICENSE file in the root directory of this source tree.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
19
|
*/
|
|
21
20
|
|
|
22
21
|
function isNodeSelected(editor, key) {
|
|
@@ -67,4 +66,4 @@ function useLexicalNodeSelection(key) {
|
|
|
67
66
|
return [isSelected, setSelected, clearSelected];
|
|
68
67
|
}
|
|
69
68
|
|
|
70
|
-
|
|
69
|
+
exports.useLexicalNodeSelection = useLexicalNodeSelection;
|
|
@@ -4,5 +4,5 @@
|
|
|
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
|
-
var c=require("@lexical/react/LexicalComposerContext"),e=require("lexical"),h=require("react");function k(b,a){return b.getEditorState().read(()=>{
|
|
8
|
-
|
|
7
|
+
'use strict';var c=require("@lexical/react/LexicalComposerContext"),e=require("lexical"),h=require("react");function k(b,a){return b.getEditorState().read(()=>{let f=e.$getNodeByKey(a);return null===f?!1:f.isSelected()})}
|
|
8
|
+
exports.useLexicalNodeSelection=function(b){let [a]=c.useLexicalComposerContext(),[f,l]=h.useState(()=>k(a,b));h.useEffect(()=>a.registerUpdateListener(()=>{l(k(a,b))}),[a,b]);let m=h.useCallback(g=>{a.update(()=>{let d=e.$getSelection();e.$isNodeSelection(d)||(d=e.$createNodeSelection(),e.$setSelection(d));g?d.add(b):d.delete(b)})},[a,b]),n=h.useCallback(()=>{a.update(()=>{const g=e.$getSelection();e.$isNodeSelection(g)&&g.clear()})},[a]);return[f,m,n]}
|
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
|
|
9
9
|
import {Class} from 'utility-types';
|
|
10
10
|
import type {TextNode} from 'lexical';
|
|
11
|
+
|
|
11
12
|
export type EntityMatch = {
|
|
12
13
|
end: number;
|
|
13
14
|
start: number;
|
|
14
15
|
};
|
|
15
|
-
export
|
|
16
|
+
export function useLexicalTextEntity<N extends TextNode>(
|
|
16
17
|
getMatch: (text: string) => null | EntityMatch,
|
|
17
18
|
targetNode: Class<N>,
|
|
18
19
|
createNode: (textNode: TextNode) => N,
|