@lexical/react 0.1.14 → 0.1.17
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_useLexicalAutoFormatter.dev.js +5 -741
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +1 -21
- package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +4 -73
- package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -2
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +19 -72
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +7 -8
- package/DEPRECATED_useLexicalDecorators.dev.js +1 -1
- package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
- package/DEPRECATED_useLexicalEditorEvents.dev.js +1 -1
- package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
- package/DEPRECATED_useLexicalHistory.dev.js +5 -307
- package/DEPRECATED_useLexicalHistory.prod.js +1 -7
- package/DEPRECATED_useLexicalList.dev.js +29 -25
- package/DEPRECATED_useLexicalList.prod.js +3 -1
- package/DEPRECATED_useLexicalPlainText.dev.js +8 -687
- package/DEPRECATED_useLexicalPlainText.prod.js +2 -15
- package/DEPRECATED_useLexicalRichText.dev.js +8 -772
- package/DEPRECATED_useLexicalRichText.prod.js +2 -17
- package/LICENSE +1 -1
- package/{withSubscriptions.prod.js → LexicalAutoFocusPlugin.d.ts} +3 -1
- package/{withSubscriptions.dev.js → LexicalAutoFocusPlugin.dev.js} +10 -5
- package/LexicalAutoFocusPlugin.js +9 -0
- package/{LexicalAutoFormatterPlugin.js.flow → LexicalAutoFocusPlugin.js.flow} +1 -1
- package/LexicalAutoFocusPlugin.prod.js +7 -0
- package/LexicalAutoLinkPlugin.dev.js +12 -15
- package/LexicalAutoLinkPlugin.prod.js +6 -6
- package/LexicalAutoScrollPlugin.d.ts +13 -0
- package/LexicalAutoScrollPlugin.dev.js +82 -0
- package/LexicalAutoScrollPlugin.js +9 -0
- package/{withSubscriptions.d.ts → LexicalAutoScrollPlugin.js.flow} +5 -5
- package/LexicalAutoScrollPlugin.prod.js +8 -0
- package/LexicalCharacterLimitPlugin.dev.js +19 -72
- package/LexicalCharacterLimitPlugin.prod.js +8 -9
- package/LexicalClearEditorPlugin.dev.js +15 -19
- package/LexicalClearEditorPlugin.prod.js +1 -1
- package/LexicalCollaborationPlugin.d.ts +8 -3
- package/LexicalCollaborationPlugin.dev.js +70 -47
- package/LexicalCollaborationPlugin.js.flow +9 -3
- package/LexicalCollaborationPlugin.prod.js +10 -8
- package/LexicalComposer.d.ts +2 -2
- package/LexicalComposer.dev.js +3 -19
- package/LexicalComposer.js.flow +2 -2
- package/LexicalComposer.prod.js +2 -3
- package/LexicalContentEditable.dev.js +3 -1
- package/LexicalContentEditable.prod.js +2 -2
- package/LexicalHashtagPlugin.dev.js +21 -92
- package/LexicalHashtagPlugin.prod.js +4 -7
- package/LexicalHistoryPlugin.dev.js +5 -307
- package/LexicalHistoryPlugin.prod.js +1 -7
- package/LexicalHorizontalRuleNode.d.ts +3 -1
- package/LexicalHorizontalRuleNode.dev.js +2 -0
- package/LexicalHorizontalRuleNode.js.flow +6 -2
- package/LexicalHorizontalRuleNode.prod.js +2 -2
- package/LexicalLinkPlugin.dev.js +19 -20
- package/LexicalLinkPlugin.prod.js +4 -3
- package/LexicalListPlugin.dev.js +29 -25
- package/LexicalListPlugin.prod.js +3 -2
- package/{LexicalAutoFormatterPlugin.d.ts → LexicalMarkdownShortcutPlugin.d.ts} +1 -1
- package/LexicalMarkdownShortcutPlugin.dev.js +42 -0
- package/LexicalMarkdownShortcutPlugin.js +9 -0
- package/{withSubscriptions.js.flow → LexicalMarkdownShortcutPlugin.js.flow} +1 -4
- package/LexicalMarkdownShortcutPlugin.prod.js +7 -0
- package/LexicalNestedComposer.dev.js +20 -15
- package/LexicalNestedComposer.prod.js +3 -3
- package/LexicalOnChangePlugin.dev.js +16 -3
- package/LexicalOnChangePlugin.prod.js +2 -1
- package/LexicalPlainTextPlugin.dev.js +9 -455
- package/LexicalPlainTextPlugin.prod.js +4 -12
- package/LexicalRichTextPlugin.dev.js +9 -540
- package/LexicalRichTextPlugin.prod.js +4 -13
- package/LexicalTablePlugin.dev.js +36 -35
- package/LexicalTablePlugin.prod.js +3 -3
- package/LexicalTreeView.dev.js +1 -1
- package/LexicalTreeView.prod.js +1 -1
- package/package.json +17 -11
- package/useLexicalIsTextContentEmpty.dev.js +4 -33
- package/useLexicalIsTextContentEmpty.prod.js +1 -2
- package/useLexicalNodeSelection.dev.js +1 -1
- package/useLexicalNodeSelection.prod.js +1 -1
- package/useLexicalTextEntity.d.ts +19 -0
- package/useLexicalTextEntity.dev.js +29 -0
- package/{withSubscriptions.js → useLexicalTextEntity.js} +2 -2
- package/useLexicalTextEntity.js.flow +18 -0
- package/useLexicalTextEntity.prod.js +7 -0
- package/LexicalAutoFormatterPlugin.dev.js +0 -778
- package/LexicalAutoFormatterPlugin.js +0 -9
- package/LexicalAutoFormatterPlugin.prod.js +0 -27
|
@@ -29,52 +29,49 @@ function TablePlugin() {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
return editor.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const selection = lexical.$getSelection();
|
|
32
|
+
return editor.registerCommand(table.INSERT_TABLE_COMMAND, payload => {
|
|
33
|
+
const {
|
|
34
|
+
columns,
|
|
35
|
+
rows
|
|
36
|
+
} = payload;
|
|
37
|
+
const selection = lexical.$getSelection();
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
const focus = selection.focus;
|
|
44
|
+
const focusNode = focus.getNode();
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
if (focusNode !== null) {
|
|
47
|
+
const tableNode = table.$createTableNodeWithDimensions(Number(rows), Number(columns));
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
if (lexical.$isRootNode(focusNode)) {
|
|
50
|
+
const target = focusNode.getChildAtIndex(focus.offset);
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
} else {
|
|
56
|
-
focusNode.append(tableNode);
|
|
57
|
-
}
|
|
52
|
+
if (target !== null) {
|
|
53
|
+
target.insertBefore(tableNode);
|
|
58
54
|
} else {
|
|
59
|
-
|
|
60
|
-
topLevelNode.insertAfter(tableNode);
|
|
55
|
+
focusNode.append(tableNode);
|
|
61
56
|
}
|
|
62
57
|
|
|
63
|
-
tableNode.
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
tableNode.insertBefore(lexical.$createParagraphNode());
|
|
59
|
+
} else {
|
|
60
|
+
const topLevelNode = focusNode.getTopLevelElementOrThrow();
|
|
61
|
+
topLevelNode.insertAfter(tableNode);
|
|
66
62
|
}
|
|
67
63
|
|
|
68
|
-
|
|
64
|
+
tableNode.insertAfter(lexical.$createParagraphNode());
|
|
65
|
+
const firstCell = tableNode.getFirstChildOrThrow().getFirstChildOrThrow();
|
|
66
|
+
firstCell.select();
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
return
|
|
69
|
+
return true;
|
|
72
70
|
}, EditorPriority);
|
|
73
71
|
}, [editor]);
|
|
74
72
|
react.useEffect(() => {
|
|
75
|
-
const
|
|
76
|
-
return editor.
|
|
77
|
-
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
|
|
73
|
+
const tableSelections = new Map();
|
|
74
|
+
return editor.registerMutationListener(table.TableNode, nodeMutations => {
|
|
78
75
|
for (const [nodeKey, mutation] of nodeMutations) {
|
|
79
76
|
if (mutation === 'created') {
|
|
80
77
|
editor.update(() => {
|
|
@@ -82,13 +79,17 @@ function TablePlugin() {
|
|
|
82
79
|
const tableNode = lexical.$getNodeByKey(nodeKey);
|
|
83
80
|
|
|
84
81
|
if (tableElement && tableNode) {
|
|
85
|
-
const
|
|
86
|
-
|
|
82
|
+
const tableSelection = table.applyTableHandlers(tableNode, tableElement, editor);
|
|
83
|
+
tableSelections.set(nodeKey, tableSelection);
|
|
87
84
|
}
|
|
88
85
|
});
|
|
89
86
|
} else if (mutation === 'destroyed') {
|
|
90
|
-
const
|
|
91
|
-
|
|
87
|
+
const tableSelection = tableSelections.get(nodeKey);
|
|
88
|
+
|
|
89
|
+
if (tableSelection) {
|
|
90
|
+
tableSelection.removeListeners();
|
|
91
|
+
tableSelections.delete(nodeKey);
|
|
92
|
+
}
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
});
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
var e=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/table"),k=require("lexical"),m=require("react");
|
|
8
|
-
module.exports=function(){const [
|
|
9
|
-
h)
|
|
10
|
-
"destroyed"===
|
|
8
|
+
module.exports=function(){const [c]=e.useLexicalComposerContext();m.useEffect(()=>{if(!c.hasNodes([g.TableNode,g.TableCellNode,g.TableRowNode]))throw Error("Minified Lexical error #54; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return c.registerCommand(g.INSERT_TABLE_COMMAND,a=>{const {columns:h,rows:f}=a;a=k.$getSelection();if(!k.$isRangeSelection(a))return!0;var d=a.focus;a=d.getNode();if(null!==a){const b=g.$createTableNodeWithDimensions(Number(f),
|
|
9
|
+
Number(h));k.$isRootNode(a)?(d=a.getChildAtIndex(d.offset),null!==d?d.insertBefore(b):a.append(b),b.insertBefore(k.$createParagraphNode())):a.getTopLevelElementOrThrow().insertAfter(b);b.insertAfter(k.$createParagraphNode());b.getFirstChildOrThrow().getFirstChildOrThrow().select()}return!0},0)},[c]);m.useEffect(()=>{const a=new Map;return c.registerMutationListener(g.TableNode,h=>{for(const [f,d]of h)"created"===d?c.update(()=>{var b=c.getElementByKey(f);const l=k.$getNodeByKey(f);b&&l&&(b=g.applyTableHandlers(l,
|
|
10
|
+
b,c),a.set(f,b))}):"destroyed"===d&&(h=a.get(f))&&(h.removeListeners(),a.delete(f))})},[c]);return null};
|
package/LexicalTreeView.dev.js
CHANGED
|
@@ -47,7 +47,7 @@ function TreeView({
|
|
|
47
47
|
const [isPlaying, setIsPlaying] = React.useState(false);
|
|
48
48
|
React.useEffect(() => {
|
|
49
49
|
setContent(generateContent(editor.getEditorState()));
|
|
50
|
-
return editor.
|
|
50
|
+
return editor.registerUpdateListener(({
|
|
51
51
|
editorState
|
|
52
52
|
}) => {
|
|
53
53
|
const compositionKey = editor._compositionKey;
|
package/LexicalTreeView.prod.js
CHANGED
|
@@ -14,7 +14,7 @@ function M(a){let b=Q.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase(
|
|
|
14
14
|
function N({indent:a,isSelected:b,node:c,nodeKeyDisplay:e,selection:d,typeDisplay:f}){if(!k.$isTextNode(c)||!k.$isRangeSelection(d)||!b||k.$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;const m=d.focus,v=c.getTextContent(!0),u=v.length;b=d=-1;if("text"===g.type&&"text"===m.type){const n=g.getNode(),w=m.getNode();n===w&&c===n&&g.offset!==m.offset?[d,b]=g.offset<m.offset?[g.offset,m.offset]:[m.offset,
|
|
15
15
|
g.offset]:c===n?[d,b]=n.isBefore(w)?[g.offset,u]:[0,g.offset]:c===w?[d,b]=w.isBefore(n)?[m.offset,u]:[0,m.offset]:[d,b]=[0,u]}c=(v.slice(0,d).match(D)||[]).length;g=(v.slice(d,b).match(D)||[]).length;const [r,l]=[d+c,b+c+g];if(r===l)return"";c=a[a.length-1]===E.hasNextSibling?E.ancestorHasNextSibling:E.ancestorIsLastChild;a=[...a.slice(0,a.length-1),c];c=Array(r).fill(" ");d=Array(l-r).fill(E.selectedChar);e=Array(e.length+(f.length+3)).fill(" ");return[E.selectedLine,a.join(" "),[...e,...c,...d].join("")].join(" ")+
|
|
16
16
|
"\n"}
|
|
17
|
-
module.exports=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:e,timeTravelPanelClassName:d,editor:f}){const [g,m]=q.useState([]),[v,u]=q.useState(""),[r,l]=q.useState(!1),n=q.useRef(0),w=q.useRef(null),B=q.useRef(null),[z,C]=q.useState(!1);q.useEffect(()=>{u(H(f.getEditorState()));return f.
|
|
17
|
+
module.exports=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:e,timeTravelPanelClassName:d,editor:f}){const [g,m]=q.useState([]),[v,u]=q.useState(""),[r,l]=q.useState(!1),n=q.useRef(0),w=q.useRef(null),B=q.useRef(null),[z,C]=q.useState(!1);q.useEffect(()=>{u(H(f.getEditorState()));return f.registerUpdateListener(({editorState:h})=>{const p=f._compositionKey,x=H(f.getEditorState());u([x,null!==p&&`Composition key: ${p}`].filter(Boolean).join("\n\n"));r||
|
|
18
18
|
m(A=>[...A,[Date.now(),h]])})},[r,f]);const y=g.length;q.useEffect(()=>{if(z){let h;const p=()=>{const x=n.current;x===y-1?C(!1):h=setTimeout(()=>{n.current++;const A=n.current,I=B.current;null!==I&&(I.value=String(A));f.setEditorState(g[A][1]);p()},g[x+1][0]-g[x][0])};p();return()=>{window.clearTimeout(h)}}},[g,z,f,y]);q.useEffect(()=>{const h=w.current;if(null!==h)return h.__lexicalEditor=f,()=>{h.__lexicalEditor=null}},[f]);return q.createElement("div",{className:e},!r&&2<y&&q.createElement("button",
|
|
19
19
|
{onClick:()=>{const h=f.getRootElement();null!==h&&(h.contentEditable="false",n.current=y-1,l(!0))},className:a},"Time Travel"),q.createElement("pre",{ref:w},v),r&&q.createElement("div",{className:d},q.createElement("button",{className:c,onClick:()=>{C(!z)}},z?"Pause":"Play"),q.createElement("input",{className:b,ref:B,onChange:h=>{h=Number(h.target.value);const p=g[h];p&&(n.current=h,f.setEditorState(p[1]))},type:"range",min:"1",max:y-1}),q.createElement("button",{className:c,onClick:()=>{var h=f.getRootElement();
|
|
20
20
|
if(null!==h){h.contentEditable="true";h=g.length-1;f.setEditorState(g[h][1]);const p=B.current;null!==p&&(p.value=String(h));l(!1);C(!1)}}},"Exit")))};
|
package/package.json
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lexical/react",
|
|
3
|
-
"author": {
|
|
4
|
-
"name": "Dominic Gannaway",
|
|
5
|
-
"email": "dg@domgan.com"
|
|
6
|
-
},
|
|
7
3
|
"description": "This package provides Lexical components and hooks for React applications.",
|
|
8
4
|
"keywords": [
|
|
9
5
|
"react",
|
|
@@ -12,16 +8,26 @@
|
|
|
12
8
|
"rich-text"
|
|
13
9
|
],
|
|
14
10
|
"license": "MIT",
|
|
15
|
-
"version": "0.1.
|
|
11
|
+
"version": "0.1.17",
|
|
16
12
|
"dependencies": {
|
|
17
|
-
"@lexical/
|
|
18
|
-
"@lexical/
|
|
19
|
-
"@lexical/
|
|
20
|
-
"@lexical/
|
|
21
|
-
"@lexical/
|
|
13
|
+
"@lexical/clipboard": "0.1.17",
|
|
14
|
+
"@lexical/list": "0.1.17",
|
|
15
|
+
"@lexical/table": "0.1.17",
|
|
16
|
+
"@lexical/yjs": "0.1.17",
|
|
17
|
+
"@lexical/hashtag": "0.1.17",
|
|
18
|
+
"@lexical/selection": "0.1.17",
|
|
19
|
+
"@lexical/utils": "0.1.17",
|
|
20
|
+
"@lexical/dragon": "0.1.17",
|
|
21
|
+
"@lexical/plain-text": "0.1.17",
|
|
22
|
+
"@lexical/rich-text": "0.1.17",
|
|
23
|
+
"@lexical/code": "0.1.17",
|
|
24
|
+
"@lexical/text": "0.1.17",
|
|
25
|
+
"@lexical/link": "0.1.17",
|
|
26
|
+
"@lexical/overflow": "0.1.17",
|
|
27
|
+
"@lexical/history": "0.1.17"
|
|
22
28
|
},
|
|
23
29
|
"peerDependencies": {
|
|
24
|
-
"lexical": "0.1.
|
|
30
|
+
"lexical": "0.1.17",
|
|
25
31
|
"react": ">=17.x",
|
|
26
32
|
"react-dom": ">=17.x"
|
|
27
33
|
},
|
|
@@ -6,38 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var text = require('@lexical/text');
|
|
10
10
|
var react = require('react');
|
|
11
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
|
-
function $textContent() {
|
|
21
|
-
const root = lexical.$getRoot();
|
|
22
|
-
return root.getTextContent();
|
|
23
|
-
}
|
|
24
|
-
function $isTextContentEmpty(isEditorComposing, trim = true) {
|
|
25
|
-
if (isEditorComposing) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let text = $textContent();
|
|
30
|
-
|
|
31
|
-
if (trim) {
|
|
32
|
-
text = text.trim();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return text === '';
|
|
36
|
-
}
|
|
37
|
-
function $isTextContentEmptyCurry(isEditorComposing, trim) {
|
|
38
|
-
return () => $isTextContentEmpty(isEditorComposing, trim);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
12
|
/**
|
|
42
13
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
43
14
|
*
|
|
@@ -68,13 +39,13 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
68
39
|
*
|
|
69
40
|
*/
|
|
70
41
|
function useLexicalIsTextContentEmpty(editor, trim) {
|
|
71
|
-
const [isEmpty, setIsEmpty] = react.useState(editor.getEditorState().read(
|
|
42
|
+
const [isEmpty, setIsEmpty] = react.useState(editor.getEditorState().read(text.$isRootTextContentEmptyCurry(editor.isComposing(), trim)));
|
|
72
43
|
useLayoutEffect(() => {
|
|
73
|
-
return editor.
|
|
44
|
+
return editor.registerUpdateListener(({
|
|
74
45
|
editorState
|
|
75
46
|
}) => {
|
|
76
47
|
const isComposing = editor.isComposing();
|
|
77
|
-
const currentIsEmpty = editorState.read(
|
|
48
|
+
const currentIsEmpty = editorState.read(text.$isRootTextContentEmptyCurry(isComposing, trim));
|
|
78
49
|
setIsEmpty(currentIsEmpty);
|
|
79
50
|
});
|
|
80
51
|
}, [editor, trim]);
|
|
@@ -4,5 +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
|
|
8
|
-
module.exports=function(a,b){const [k,l]=e.useState(a.getEditorState().read(g(a.isComposing(),b)));h(()=>a.addListener("update",({editorState:d})=>{const m=a.isComposing();d=d.read(g(m,b));l(d)}),[a,b]);return k};
|
|
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;module.exports=function(a,c){const [g,h]=e.useState(a.getEditorState().read(b.$isRootTextContentEmptyCurry(a.isComposing(),c)));f(()=>a.registerUpdateListener(({editorState:d})=>{const k=a.isComposing();d=d.read(b.$isRootTextContentEmptyCurry(k,c));h(d)}),[a,c]);return g};
|
|
@@ -35,7 +35,7 @@ function useLexicalNodeSelection(key) {
|
|
|
35
35
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
36
36
|
const [isSelected, setIsSelected] = react.useState(() => isNodeSelected(editor, key));
|
|
37
37
|
react.useEffect(() => {
|
|
38
|
-
return editor.
|
|
38
|
+
return editor.registerUpdateListener(() => {
|
|
39
39
|
setIsSelected(isNodeSelected(editor, key));
|
|
40
40
|
});
|
|
41
41
|
}, [editor, key]);
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
var c=require("@lexical/react/LexicalComposerContext"),e=require("lexical"),h=require("react");function k(b,a){return b.getEditorState().read(()=>{const f=e.$getNodeByKey(a);return null===f?!1:f.isSelected()})}
|
|
8
|
-
module.exports=function(b){const [a]=c.useLexicalComposerContext(),[f,l]=h.useState(()=>k(a,b));h.useEffect(()=>a.
|
|
8
|
+
module.exports=function(b){const [a]=c.useLexicalComposerContext(),[f,l]=h.useState(()=>k(a,b));h.useEffect(()=>a.registerUpdateListener(()=>{l(k(a,b))}),[a,b]);const 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]};
|
|
@@ -0,0 +1,19 @@
|
|
|
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 {Class} from 'utility-types';
|
|
10
|
+
import type {TextNode} from 'lexical';
|
|
11
|
+
export type EntityMatch = {
|
|
12
|
+
end: number;
|
|
13
|
+
start: number;
|
|
14
|
+
};
|
|
15
|
+
export default function useLexicalTextEntity<N extends TextNode>(
|
|
16
|
+
getMatch: (text: string) => null | EntityMatch,
|
|
17
|
+
targetNode: Class<N>,
|
|
18
|
+
createNode: (textNode: TextNode) => N,
|
|
19
|
+
): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
|
+
var text = require('@lexical/text');
|
|
11
|
+
var utils = require('@lexical/utils');
|
|
12
|
+
var react = require('react');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
16
|
+
*
|
|
17
|
+
* This source code is licensed under the MIT license found in the
|
|
18
|
+
* LICENSE file in the root directory of this source tree.
|
|
19
|
+
*
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
function useLexicalTextEntity(getMatch, targetNode, createNode) {
|
|
23
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
24
|
+
react.useEffect(() => {
|
|
25
|
+
return utils.mergeRegister(...text.registerLexicalTextEntity(editor, getMatch, targetNode, createNode));
|
|
26
|
+
}, [createNode, editor, getMatch, targetNode]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = useLexicalTextEntity;
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const
|
|
9
|
-
module.exports =
|
|
8
|
+
const useLexicalTextEntity = process.env.NODE_ENV === 'development' ? require('./useLexicalTextEntity.dev.js') : require('./useLexicalTextEntity.prod.js')
|
|
9
|
+
module.exports = useLexicalTextEntity;
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
import type {TextNode} from 'lexical';
|
|
11
|
+
|
|
12
|
+
export type EntityMatch = {end: number, start: number};
|
|
13
|
+
|
|
14
|
+
declare export default function useLexicalTextEntity<N: TextNode>(
|
|
15
|
+
getMatch: (text: string) => null | EntityMatch,
|
|
16
|
+
targetNode: Class<N>,
|
|
17
|
+
createNode: (textNode: TextNode) => N,
|
|
18
|
+
): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
var e=require("@lexical/react/LexicalComposerContext"),f=require("@lexical/text"),g=require("@lexical/utils"),h=require("react");module.exports=function(a,b,c){const [d]=e.useLexicalComposerContext();h.useEffect(()=>g.mergeRegister(...f.registerLexicalTextEntity(d,a,b,c)),[c,d,a,b])};
|