@lexical/react 0.1.11 → 0.1.14
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 +3 -7
- package/DEPRECATED_useLexical.prod.js +1 -1
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +14 -9
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +18 -18
- package/DEPRECATED_useLexicalPlainText.dev.js +33 -27
- package/DEPRECATED_useLexicalPlainText.prod.js +12 -12
- package/DEPRECATED_useLexicalRichText.dev.js +43 -388
- package/DEPRECATED_useLexicalRichText.prod.js +17 -25
- package/LexicalAutoFormatterPlugin.d.ts +9 -0
- package/LexicalAutoFormatterPlugin.dev.js +14 -9
- package/LexicalAutoFormatterPlugin.prod.js +18 -18
- package/LexicalAutoLinkPlugin.d.ts +20 -0
- package/LexicalCharacterLimitPlugin.d.ts +11 -0
- package/LexicalClearEditorPlugin.d.ts +14 -0
- package/LexicalClearEditorPlugin.dev.js +22 -1
- package/LexicalClearEditorPlugin.prod.js +2 -1
- package/LexicalCollaborationPlugin.d.ts +51 -0
- package/LexicalCollaborationPlugin.dev.js +39 -12
- package/LexicalCollaborationPlugin.js.flow +4 -2
- package/LexicalCollaborationPlugin.prod.js +8 -7
- package/LexicalComposer.d.ts +22 -0
- package/LexicalComposer.dev.js +28 -6
- package/LexicalComposer.js.flow +5 -4
- package/LexicalComposer.prod.js +3 -3
- package/LexicalComposerContext.d.ts +24 -0
- package/LexicalComposerContext.js.flow +1 -1
- package/LexicalContentEditable.d.ts +32 -0
- package/LexicalContentEditable.dev.js +22 -1
- package/LexicalContentEditable.prod.js +3 -3
- package/LexicalHashtagPlugin.d.ts +9 -0
- package/LexicalHashtagPlugin.dev.js +56 -1
- package/LexicalHashtagPlugin.js.flow +0 -10
- package/LexicalHashtagPlugin.prod.js +7 -4
- package/LexicalHistoryPlugin.d.ts +29 -0
- package/LexicalHorizontalRuleNode.d.ts +23 -0
- package/LexicalLinkPlugin.d.ts +9 -0
- package/LexicalListPlugin.d.ts +9 -0
- package/LexicalNestedComposer.d.ts +17 -0
- package/LexicalNestedComposer.dev.js +21 -11
- package/LexicalNestedComposer.js.flow +3 -6
- package/LexicalNestedComposer.prod.js +3 -2
- package/LexicalOnChangePlugin.d.ts +12 -0
- package/LexicalPlainTextPlugin.d.ts +15 -0
- package/LexicalPlainTextPlugin.dev.js +11 -26
- package/LexicalPlainTextPlugin.prod.js +8 -8
- package/LexicalRichTextPlugin.d.ts +15 -0
- package/LexicalRichTextPlugin.dev.js +24 -390
- package/LexicalRichTextPlugin.prod.js +13 -21
- package/LexicalTablePlugin.d.ts +9 -0
- package/LexicalTreeView.d.ts +17 -0
- package/package.json +9 -5
- package/useLexicalDecoratorMap.d.ts +14 -0
- package/useLexicalIsTextContentEmpty.d.ts +13 -0
- package/useLexicalNodeSelection.d.ts +12 -0
- package/withSubscriptions.d.ts +12 -0
|
@@ -5,23 +5,23 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
var k=require("@lexical/react/LexicalComposerContext"),q=require("@lexical/list"),r=require("lexical"),t=require("lexical/CodeNode"),u=require("react"),x=require("@lexical/react/LexicalHorizontalRuleNode"),y=require("lexical/HeadingNode"),C=require("lexical/QuoteNode");function D(g){throw Error(`Minified Lexical error #${g}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
|
|
8
|
-
function E(g,f,a,
|
|
8
|
+
function E(g,f,a,c){g=g.getChildren();const b=g.length;let d=0,e=!1;for(let p=0;p<b&&!(d>f);++p){const m=g[p],n=r.$isTextNode(m);var h=n?m.getTextContent().length:c;h=d+h;if((!1===e&&d===a||0===d&&d===a||d<a&&a<=h)&&r.$isTextNode(m))return{node:m,offset:a-d};d=h;e=n}return null}
|
|
9
9
|
const F={nodeTransformationKind:null,regEx:/(?:)/,requiresParagraphStart:!1},H={...F,requiresParagraphStart:!0},I=[{...F,nodeTransformationKind:"bold_italic",regEx:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*\s)$/},{...F,nodeTransformationKind:"italic",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/},{...F,nodeTransformationKind:"bold",regEx:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*\s)$/},{...F,nodeTransformationKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__\s)$/},{...F,nodeTransformationKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>\s)$/},
|
|
10
|
-
{...F,nodeTransformationKind:"strikethrough",regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~\s)$/}],J=[{...H,nodeTransformationKind:"paragraphH1",regEx
|
|
11
|
-
regEx:/^(\d+)\.\s/},{...H,nodeTransformationKind:"paragraphCodeBlock",regEx
|
|
12
|
-
function K(g,f,a,
|
|
13
|
-
function L(g,f,a,b
|
|
14
|
-
function M(g,f){g.update(()=>{if(f.autoFormatCriteria.requiresParagraphStart){var a=f.textNodeWithOffset,
|
|
15
|
-
y.$createHeadingNode("h2");a.append(...d);break;case "paragraphH3":a=y.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=C.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=q.$createListNode("ul");
|
|
16
|
-
a.append(
|
|
17
|
-
["bold","italic"];break a}a=null}if(null!=a){d=[1,5];
|
|
18
|
-
h=d.length-1;0<=h;h--)h<e&&(p=d[h],l=
|
|
19
|
-
e=d[3];
|
|
20
|
-
|
|
21
|
-
function N(g,f){let a=null;g.read(()=>{var
|
|
22
|
-
l=
|
|
23
|
-
h.getChildren();const O=h.length;for(let B=0;B<O;++B){const v=h[B];if(r.$isTextNode(v)){const G=v.getTextContent();if(v.is(m.node)){m.offset>G.length&&D(50,v.__key);w+=v.getTextContent().substr(0,m.offset);break}else w+=G}else w+="\u0004"}p.joinedText=w}}else D(52,h.__key)}d=K(e.joinedText,!1,!0,d.regEx)}if(null!=d){
|
|
24
|
-
|
|
25
|
-
function P(g){let f=null;g.read(()=>{const a=r.$getSelection();if(r.$isRangeSelection(a)&&a.isCollapsed()){var
|
|
26
|
-
function Q(g){u.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var
|
|
10
|
+
{...F,nodeTransformationKind:"strikethrough",regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~\s)$/}],J=[{...H,nodeTransformationKind:"paragraphH1",regEx:/^(?:# )/},{...H,nodeTransformationKind:"paragraphH2",regEx:/^(?:## )/},{...H,nodeTransformationKind:"paragraphH2",regEx:/^(?:### )/},{...H,nodeTransformationKind:"paragraphBlockQuote",regEx:/^(?:> )/},{...H,nodeTransformationKind:"paragraphUnorderedList",regEx:/^(?:- )/},{...H,nodeTransformationKind:"paragraphUnorderedList",regEx:/^(?:\* )/},{...H,nodeTransformationKind:"paragraphOrderedList",
|
|
11
|
+
regEx:/^(\d+)\.\s/},{...H,nodeTransformationKind:"paragraphCodeBlock",regEx:/^(```)([a-z]*)( )/},{...H,nodeTransformationKind:"horizontalRule",regEx:/^(?:\*\*\* )/},{...H,nodeTransformationKind:"horizontalRule",regEx:/^(?:--- )/},...I];
|
|
12
|
+
function K(g,f,a,c){const b={offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]};c=g.match(c);if(null!==c&&0<c.length&&(!1===f||0===c.index)&&(!1===a||c.index+c[0].length===g.length)){b.offsetInJoinedTextForCollapsedSelection=g.length;g=c.length;f=c.index;for(a=0;a<g;a++){const d=c[a];b.regExCaptureGroups.push({anchorTextNodeWithOffset:null,focusTextNodeWithOffset:null,offsetInParent:f,text:d,textLength:d.length-(a+1===g?1:0)});0<a&&(f+=d.length)}return b}return null}
|
|
13
|
+
function L(g,f,a,c,b){b.offsetInJoinedTextForCollapsedSelection+=g;0<b.offsetInJoinedTextForCollapsedSelection||D(67);b=b.regExCaptureGroups;const d=b.length;for(c+=1;c<d;c++){const e=b[c];null!=e.anchorTextNodeWithOffset&&e.anchorTextNodeWithOffset.offset>=f&&e.anchorTextNodeWithOffset.node.is(a)&&(e.anchorTextNodeWithOffset.offset+=g);null!=e.focusTextNodeWithOffset&&e.focusTextNodeWithOffset.offset>=f&&e.focusTextNodeWithOffset.node.is(a)&&(e.focusTextNodeWithOffset.offset+=g)}}
|
|
14
|
+
function M(g,f){g.update(()=>{if(f.autoFormatCriteria.requiresParagraphStart){var a=f.textNodeWithOffset,c=a.node.getParentOrThrow();a=a.node.spliceText(0,f.matchResultContext.regExCaptureGroups[0].text.length,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove());var b=c;a=null;var d=b.getChildren(),e=f.autoFormatCriteria,h=f.matchResultContext;if(null!=e.nodeTransformationKind)switch(e.nodeTransformationKind){case "paragraphH1":a=y.$createHeadingNode("h1");a.append(...d);break;case "paragraphH2":a=
|
|
15
|
+
y.$createHeadingNode("h2");a.append(...d);break;case "paragraphH3":a=y.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=C.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=q.$createListNode("ul");b=q.$createListItemNode();b.append(...d);a.append(b);break;case "paragraphOrderedList":a=parseInt(1<h.regExCaptureGroups.length?h.regExCaptureGroups[h.regExCaptureGroups.length-1].text:"1",10);a=q.$createListNode("ol",a);b=q.$createListItemNode();b.append(...d);
|
|
16
|
+
a.append(b);break;case "paragraphCodeBlock":null!=f.triggerState&&f.triggerState.isCodeBlock?a=r.$createParagraphNode():(a=t.$createCodeNode(),b=3<=h.regExCaptureGroups.length?h.regExCaptureGroups[2].text:null,null!=b&&0<b.length&&a.setLanguage(b));a.append(...d);break;case "horizontalRule":d=x.$createHorizontalRuleNode(),b.insertBefore(d)}null!==a&&c.replace(a)}else if(a=f.autoFormatCriteria,c=f.matchResultContext,null!=a.nodeTransformationKind&&6===c.regExCaptureGroups.length){a:{a=a.nodeTransformationKind;
|
|
17
|
+
switch(a){case "italic":case "bold":case "underline":case "strikethrough":a=[a];break a;case "bold_italic":a=["bold","italic"];break a}a=null}if(null!=a){d=[1,5];b=f.autoFormatCriteria;e=f.matchResultContext.regExCaptureGroups;h=e.length;var p=f.textNodeWithOffset.node.getParentOrThrow();null==f.joinedText&&D(62);var m=f.joinedText.length;for(var n=1;n<h;n++){var l=e[n];l.anchorTextNodeWithOffset=E(p,m,l.offsetInParent,1);l.focusTextNodeWithOffset=E(p,m,l.offsetInParent+l.textLength,1);0>l.textLength&&
|
|
18
|
+
D(63,b.nodeTransformationKind)}c.regExCaptureGroups=e;if(0<d.length)for(b=c.regExCaptureGroups,e=b.length,h=d.length-1;0<=h;h--)h<e&&(p=d[h],l=b[p],n=l.anchorTextNodeWithOffset,m=l.focusTextNodeWithOffset,null!=n&&null!=m&&0<l.textLength&&(l=r.$createRangeSelection(),l.anchor.set(n.node.getKey(),n.offset,"text"),l.focus.set(m.node.getKey(),m.offset,"text"),r.$setSelection(l),l=r.$getSelection(),r.$isRangeSelection(l)&&(l.removeText(),n.node.getKey()===m.node.getKey()?(l=m.offset-n.offset,0<l||D(64),
|
|
19
|
+
L(-l,m.offset,n.node,p,c)):(n=m.offset,0<n&&L(-n,n,m.node,p,c)))));d=c.regExCaptureGroups;3<d.length||D(65);e=d[3];b=e.anchorTextNodeWithOffset;d=e.focusTextNodeWithOffset;if(null!=b&&null!=d&&0<e.textLength&&(e=r.$createRangeSelection(),e.anchor.set(b.node.getKey(),b.offset,"text"),e.focus.set(d.node.getKey(),d.offset,"text"),r.$setSelection(e),b=r.$getSelection(),r.$isRangeSelection(b))){for(e=0;e<a.length;e++)b.formatText(a[e]);a=r.$createRangeSelection();a.anchor.set(d.node.getKey(),d.offset+
|
|
20
|
+
1,"text");a.focus.set(d.node.getKey(),d.offset+1,"text");r.$setSelection(a)}a=f.textNodeWithOffset.node.getParentOrThrow();c=E(a,c.offsetInJoinedTextForCollapsedSelection+1,c.offsetInJoinedTextForCollapsedSelection,1);null!=c&&(a=r.$createRangeSelection(),a.anchor.set(c.node.getKey(),c.offset,"text"),a.focus.set(c.node.getKey(),c.offset,"text"),r.$setSelection(a))}}},{tag:"history-push"})}
|
|
21
|
+
function N(g,f){let a=null;g.read(()=>{var c=r.$getSelection();if(r.$isRangeSelection(c)){var b=c.anchor.getNode();c=r.$isTextNode(b)?{node:b,offset:c.anchor.offset}:null}else c=null;if(null!==c){c={autoFormatCriteria:{nodeTransformationKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},joinedText:null,matchResultContext:{offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]},textNodeWithOffset:c,triggerState:f};a:{b=!1===f.isParentAListItemNode?J:I;const n=c.triggerState,
|
|
22
|
+
l=b.length;for(let z=0;z<l;z++){const A=b[z];if(null!=n&&!1===n.isCodeBlock||"paragraphCodeBlock"===A.nodeTransformationKind){var d=A,e=c;if(null!==d.requiresParagraphStart&&!0===d.requiresParagraphStart)null===e.textNodeWithOffset.node.getPreviousSibling()?(e=e.textNodeWithOffset.node.getTextContent(),d=K(e,!0,!1,d.regEx)):d=null;else{if(null==e.joinedText){var h=e.textNodeWithOffset.node.getParentOrThrow();if(r.$isElementNode(h)){if(null==e.joinedText){var p=e,m=e.textNodeWithOffset;let w="";h=
|
|
23
|
+
h.getChildren();const O=h.length;for(let B=0;B<O;++B){const v=h[B];if(r.$isTextNode(v)){const G=v.getTextContent();if(v.is(m.node)){m.offset>G.length&&D(50,v.__key);w+=v.getTextContent().substr(0,m.offset);break}else w+=G}else w+="\u0004"}p.joinedText=w}}else D(52,h.__key)}d=K(e.joinedText,!1,!0,d.regEx)}if(null!=d){b={autoFormatCriteria:A,matchResultContext:d};break a}}}b={autoFormatCriteria:null,matchResultContext:null}}null!==b.autoFormatCriteria&&null!==b.matchResultContext&&(a=c,a.autoFormatCriteria=
|
|
24
|
+
b.autoFormatCriteria,a.matchResultContext=b.matchResultContext)}});return a}
|
|
25
|
+
function P(g){let f=null;g.read(()=>{const a=r.$getSelection();if(r.$isRangeSelection(a)&&a.isCollapsed()){var c=a.anchor.getNode(),b=c.getParent(),d=null!==b&&q.$isListItemNode(b);f={anchorOffset:a.anchor.offset,hasParentNode:null!==b,isCodeBlock:t.$isCodeNode(c),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:r.$isTextNode(c)&&c.isSimpleText(),nodeKey:c.getKey(),textContent:c.getTextContent()}}});return f}
|
|
26
|
+
function Q(g){u.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var c=g.getEditorState();a=P(c);if(null==a)c=null;else{var b=a,d=f;if(null==b||null==d)c=null;else{var e=b.textContent.length,h=b.anchorOffset-1;c=!1===(!0===b.hasParentNode&&b.isSimpleText&&b.isSelectionCollapsed&&b.nodeKey===d.nodeKey&&b.anchorOffset!==d.anchorOffset&&0<=h&&h+1<=e&&" "===b.textContent.substr(h,1)&&b.textContent!==d.textContent)?null:N(c,b)}}null!=c&&M(g,c);f=a}else f=
|
|
27
27
|
null})},[g])}module.exports=function(){const [g]=k.useLexicalComposerContext();Q(g);return null};
|
|
@@ -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
|
+
*/
|
|
8
|
+
|
|
9
|
+
type ChangeHandler = (url: string | null, prevUrl: string | null) => void;
|
|
10
|
+
type LinkMatcherResult = {
|
|
11
|
+
text: string;
|
|
12
|
+
url: string;
|
|
13
|
+
length: number;
|
|
14
|
+
index: number;
|
|
15
|
+
};
|
|
16
|
+
export type LinkMatcher = (text: string) => LinkMatcherResult | null;
|
|
17
|
+
export default function LexicalAutoLinkPlugin(props: {
|
|
18
|
+
matchers: Array<LinkMatcher>;
|
|
19
|
+
onChange?: ChangeHandler;
|
|
20
|
+
}): React.ReactNode;
|
|
@@ -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
|
+
export default function LexicalCharacterLimitPlugin(props: {
|
|
10
|
+
charset: 'UTF-8' | 'UTF-16';
|
|
11
|
+
}): React.ReactNode;
|
|
@@ -0,0 +1,14 @@
|
|
|
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 {$ReadOnly} from 'utility-types';
|
|
11
|
+
type Props = $ReadOnly<{
|
|
12
|
+
onClear?: () => void;
|
|
13
|
+
}>;
|
|
14
|
+
export default function LexicalClearEditorPlugin(arg0: Props): React.ReactNode;
|
|
@@ -10,6 +10,27 @@ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
|
10
10
|
var lexical = require('lexical');
|
|
11
11
|
var react = require('react');
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
|
+
*
|
|
16
|
+
* This source code is licensed under the MIT license found in the
|
|
17
|
+
* LICENSE file in the root directory of this source tree.
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
25
|
+
*
|
|
26
|
+
* This source code is licensed under the MIT license found in the
|
|
27
|
+
* LICENSE file in the root directory of this source tree.
|
|
28
|
+
*
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
|
|
32
|
+
var useLayoutEffect = useLayoutEffectImpl;
|
|
33
|
+
|
|
13
34
|
/**
|
|
14
35
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
36
|
*
|
|
@@ -22,7 +43,7 @@ function LexicalClearEditorPlugin({
|
|
|
22
43
|
onClear
|
|
23
44
|
}) {
|
|
24
45
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
25
|
-
|
|
46
|
+
useLayoutEffect(() => {
|
|
26
47
|
return editor.addListener('command', (type, payload) => {
|
|
27
48
|
if (type === 'clearEditor') {
|
|
28
49
|
editor.update(() => {
|
|
@@ -4,4 +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 a=require("@lexical/react/LexicalComposerContext"),
|
|
7
|
+
var a=require("@lexical/react/LexicalComposerContext"),d=require("lexical"),g=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;
|
|
8
|
+
module.exports=function({onClear:b}){const [c]=a.useLexicalComposerContext();h(()=>c.addListener("command",k=>"clearEditor"===k?(c.update(()=>{if(null==b){const e=d.$getRoot(),l=d.$getSelection(),f=d.$createParagraphNode();e.clear();e.append(f);null!==l&&f.select()}else b()}),!0):!1,0),[c,b]);return null};
|
|
@@ -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 type {Doc, RelativePosition} from 'yjs';
|
|
10
|
+
export type UserState = {
|
|
11
|
+
anchorPos: null | RelativePosition;
|
|
12
|
+
focusPos: null | RelativePosition;
|
|
13
|
+
name: string;
|
|
14
|
+
color: string;
|
|
15
|
+
focusing: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type ProviderAwareness = {
|
|
18
|
+
getLocalState: () => UserState;
|
|
19
|
+
setLocalState: (arg0: UserState) => void;
|
|
20
|
+
getStates: () => Array<UserState>;
|
|
21
|
+
on: (type: 'update', cb: () => void) => void;
|
|
22
|
+
off: (type: 'update', cb: () => void) => void;
|
|
23
|
+
};
|
|
24
|
+
export interface Provider {
|
|
25
|
+
connect(): void | Promise<void>;
|
|
26
|
+
disconnect(): void;
|
|
27
|
+
awareness: ProviderAwareness;
|
|
28
|
+
on(type: 'sync', cb: (isSynced: boolean) => void): void;
|
|
29
|
+
on(type: 'status', cb: (arg0: {status: string}) => void): void;
|
|
30
|
+
// $FlowFixMe: temp
|
|
31
|
+
on(type: 'update', cb: (arg0: any) => void): void;
|
|
32
|
+
on(type: 'reload', cb: (doc: Doc) => boolean): void;
|
|
33
|
+
off(type: 'sync', cb: (isSynced: boolean) => void): void;
|
|
34
|
+
// $FlowFixMe: temp
|
|
35
|
+
off(type: 'update', cb: (arg0: any) => void): void;
|
|
36
|
+
off(type: 'status', cb: (arg0: {status: string}) => void): void;
|
|
37
|
+
off(type: 'reload', cb: (doc: Doc) => boolean): void;
|
|
38
|
+
}
|
|
39
|
+
type CollaborationContextType = {
|
|
40
|
+
clientID: number;
|
|
41
|
+
color: string;
|
|
42
|
+
name: string;
|
|
43
|
+
yjsDocMap: Map<string, Doc>;
|
|
44
|
+
};
|
|
45
|
+
export function CollaborationPlugin(arg0: {
|
|
46
|
+
id: string;
|
|
47
|
+
providerFactory: (id: string, yjsDocMap: Map<string, Doc>) => Provider;
|
|
48
|
+
shouldBootstrap: boolean;
|
|
49
|
+
}): React.ReactNode;
|
|
50
|
+
export declare var CollaborationContext: React.Context<CollaborationContextType>;
|
|
51
|
+
export function useCollaborationContext(): CollaborationContextType;
|
|
@@ -22,7 +22,9 @@ var reactDom = require('react-dom');
|
|
|
22
22
|
*/
|
|
23
23
|
const EditorPriority = 0;
|
|
24
24
|
function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBootstrap) {
|
|
25
|
-
const
|
|
25
|
+
const isReloadingDoc = React.useRef(false);
|
|
26
|
+
const [doc, setDoc] = React.useState(docMap.get(id));
|
|
27
|
+
const binding = React.useMemo(() => yjs.createBinding(editor, provider, id, doc, docMap), [editor, provider, id, docMap, doc]);
|
|
26
28
|
const connect = React.useCallback(() => {
|
|
27
29
|
provider.connect();
|
|
28
30
|
}, [provider]);
|
|
@@ -32,7 +34,6 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
32
34
|
} catch (e) {// Do nothing
|
|
33
35
|
}
|
|
34
36
|
}, [provider]);
|
|
35
|
-
const bootstrapPropagationRef = React.useRef(true);
|
|
36
37
|
React.useEffect(() => {
|
|
37
38
|
const {
|
|
38
39
|
root
|
|
@@ -48,10 +49,11 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
48
49
|
};
|
|
49
50
|
|
|
50
51
|
const onSync = isSynced => {
|
|
51
|
-
if (shouldBootstrap && isSynced && root.isEmpty() && root._xmlText._length === 0) {
|
|
52
|
-
bootstrapPropagationRef.current = false;
|
|
52
|
+
if (shouldBootstrap && isSynced && root.isEmpty() && root._xmlText._length === 0 && isReloadingDoc.current === false) {
|
|
53
53
|
initializeEditor(editor);
|
|
54
54
|
}
|
|
55
|
+
|
|
56
|
+
isReloadingDoc.current = false;
|
|
55
57
|
};
|
|
56
58
|
|
|
57
59
|
const onAwarenessUpdate = () => {
|
|
@@ -65,6 +67,15 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
65
67
|
};
|
|
66
68
|
|
|
67
69
|
yjs.initLocalState(provider, name, color, document.activeElement === editor.getRootElement());
|
|
70
|
+
|
|
71
|
+
const onProviderDocReload = ydoc => {
|
|
72
|
+
clearEditorSkipCollab(editor);
|
|
73
|
+
setDoc(ydoc);
|
|
74
|
+
docMap.set(id, ydoc);
|
|
75
|
+
isReloadingDoc.current = true;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
provider.on('reload', onProviderDocReload);
|
|
68
79
|
provider.on('status', onStatus);
|
|
69
80
|
provider.on('sync', onSync);
|
|
70
81
|
awareness.on('update', onAwarenessUpdate);
|
|
@@ -77,18 +88,24 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
77
88
|
normalizedNodes,
|
|
78
89
|
tags
|
|
79
90
|
}) => {
|
|
80
|
-
|
|
91
|
+
if (tags.has('skip-collab') === false) {
|
|
92
|
+
yjs.syncLexicalUpdateToYjs(binding, provider, prevEditorState, editorState, dirtyElements, dirtyLeaves, normalizedNodes, tags);
|
|
93
|
+
}
|
|
81
94
|
});
|
|
82
95
|
connect();
|
|
83
96
|
return () => {
|
|
84
|
-
|
|
97
|
+
if (isReloadingDoc.current === false) {
|
|
98
|
+
disconnect();
|
|
99
|
+
}
|
|
100
|
+
|
|
85
101
|
provider.off('sync', onSync);
|
|
86
102
|
provider.off('status', onStatus);
|
|
103
|
+
provider.off('reload', onProviderDocReload);
|
|
87
104
|
awareness.off('update', onAwarenessUpdate);
|
|
88
105
|
root.getSharedType().unobserveDeep(onYjsTreeChanges);
|
|
89
106
|
removeListener();
|
|
90
107
|
};
|
|
91
|
-
}, [binding, color, connect, disconnect, editor, name, provider, shouldBootstrap]);
|
|
108
|
+
}, [binding, color, connect, disconnect, docMap, editor, id, name, provider, shouldBootstrap]);
|
|
92
109
|
const cursorsContainer = React.useMemo(() => {
|
|
93
110
|
const ref = element => {
|
|
94
111
|
binding.cursorsContainer = element;
|
|
@@ -121,18 +138,18 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
121
138
|
}, [connect, disconnect, editor]);
|
|
122
139
|
return [cursorsContainer, binding];
|
|
123
140
|
}
|
|
124
|
-
function useYjsFocusTracking(editor, provider) {
|
|
141
|
+
function useYjsFocusTracking(editor, provider, name, color) {
|
|
125
142
|
React.useEffect(() => {
|
|
126
143
|
return editor.addListener('command', (type, payload) => {
|
|
127
144
|
if (type === 'focus') {
|
|
128
|
-
yjs.setLocalStateFocus(provider, true);
|
|
145
|
+
yjs.setLocalStateFocus(provider, name, color, true);
|
|
129
146
|
} else if (type === 'blur') {
|
|
130
|
-
yjs.setLocalStateFocus(provider, false);
|
|
147
|
+
yjs.setLocalStateFocus(provider, name, color, false);
|
|
131
148
|
}
|
|
132
149
|
|
|
133
150
|
return false;
|
|
134
151
|
}, EditorPriority);
|
|
135
|
-
}, [editor, provider]);
|
|
152
|
+
}, [color, editor, name, provider]);
|
|
136
153
|
}
|
|
137
154
|
function useYjsHistory(editor, binding) {
|
|
138
155
|
const undoManager = React.useMemo(() => yjs.createUndoManager(binding, binding.root.getSharedType()), [binding]);
|
|
@@ -186,6 +203,16 @@ function initializeEditor(editor) {
|
|
|
186
203
|
});
|
|
187
204
|
}
|
|
188
205
|
|
|
206
|
+
function clearEditorSkipCollab(editor) {
|
|
207
|
+
editor.update(() => {
|
|
208
|
+
const root = lexical.$getRoot();
|
|
209
|
+
root.clear();
|
|
210
|
+
root.select();
|
|
211
|
+
}, {
|
|
212
|
+
tag: 'skip-collab'
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
189
216
|
/**
|
|
190
217
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
191
218
|
*
|
|
@@ -212,7 +239,7 @@ function CollaborationPlugin({
|
|
|
212
239
|
const [cursors, binding] = useYjsCollaboration(editor, id, provider, yjsDocMap, name, color, shouldBootstrap);
|
|
213
240
|
collabContext.clientID = binding.clientID;
|
|
214
241
|
useYjsHistory(editor, binding);
|
|
215
|
-
useYjsFocusTracking(editor, provider);
|
|
242
|
+
useYjsFocusTracking(editor, provider, name, color);
|
|
216
243
|
return cursors;
|
|
217
244
|
}
|
|
218
245
|
const CollaborationContext = /*#__PURE__*/React.createContext({
|
|
@@ -18,9 +18,9 @@ export type UserState = {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export type ProviderAwareness = {
|
|
21
|
-
getLocalState: () => UserState,
|
|
21
|
+
getLocalState: () => UserState | null,
|
|
22
22
|
setLocalState: (UserState) => void,
|
|
23
|
-
getStates: () =>
|
|
23
|
+
getStates: () => Map<number, UserState>,
|
|
24
24
|
on: (type: 'update', cb: () => void) => void,
|
|
25
25
|
off: (type: 'update', cb: () => void) => void,
|
|
26
26
|
};
|
|
@@ -33,10 +33,12 @@ export interface Provider {
|
|
|
33
33
|
on(type: 'status', cb: ({status: string}) => void): void;
|
|
34
34
|
// $FlowFixMe: temp
|
|
35
35
|
on(type: 'update', cb: (any) => void): void;
|
|
36
|
+
on(type: 'reload', cb: (doc: Doc) => void): void;
|
|
36
37
|
off(type: 'sync', cb: (isSynced: boolean) => void): void;
|
|
37
38
|
// $FlowFixMe: temp
|
|
38
39
|
off(type: 'update', cb: (any) => void): void;
|
|
39
40
|
off(type: 'status', cb: ({status: string}) => void): void;
|
|
41
|
+
off(type: 'reload', cb: (doc: Doc) => void): void;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
type CollaborationContextType = {
|
|
@@ -4,10 +4,11 @@
|
|
|
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 d=require("@lexical/react/LexicalComposerContext"),
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
[e]);
|
|
11
|
-
function
|
|
12
|
-
const
|
|
13
|
-
|
|
7
|
+
var d=require("@lexical/react/LexicalComposerContext"),l=require("react"),u=require("@lexical/yjs"),E=require("lexical"),F=require("react-dom");
|
|
8
|
+
function G(c,b,a,e,h,n,p){const m=l.useRef(!1),[q,w]=l.useState(e.get(b)),f=l.useMemo(()=>u.createBinding(c,a,b,q,e),[c,a,b,e,q]),r=l.useCallback(()=>{a.connect()},[a]),t=l.useCallback(()=>{try{a.disconnect()}catch(k){}},[a]);l.useEffect(()=>{const {root:k}=f,{awareness:v}=a,y=({status:g})=>{c.execCommand("connected","connected"===g)},z=g=>{p&&g&&k.isEmpty()&&0===k._xmlText._length&&!1===m.current&&H(c);m.current=!1},A=()=>{u.syncCursorPositions(f,a)},B=(g,x)=>{x.origin!==f&&u.syncYjsChangesToLexical(f,
|
|
9
|
+
a,g)};u.initLocalState(a,h,n,document.activeElement===c.getRootElement());const C=g=>{I(c);w(g);e.set(b,g);m.current=!0};a.on("reload",C);a.on("status",y);a.on("sync",z);v.on("update",A);k.getSharedType().observeDeep(B);const Q=c.addListener("update",({prevEditorState:g,editorState:x,dirtyLeaves:N,dirtyElements:O,normalizedNodes:P,tags:D})=>{!1===D.has("skip-collab")&&u.syncLexicalUpdateToYjs(f,a,g,x,O,N,P,D)});r();return()=>{!1===m.current&&t();a.off("sync",z);a.off("status",y);a.off("reload",C);
|
|
10
|
+
v.off("update",A);k.getSharedType().unobserveDeep(B);Q()}},[f,n,r,t,e,c,b,h,a,p]);const R=l.useMemo(()=>F.createPortal(l.createElement("div",{ref:k=>{f.cursorsContainer=k}}),document.body),[f]);l.useEffect(()=>c.addListener("command",(k,v)=>{"toggleConnect"===k&&void 0!==r&&void 0!==t&&(v?(console.log("Collaboration connected!"),r()):(console.log("Collaboration disconnected!"),t()));return!1},0),[r,t,c]);return[R,f]}
|
|
11
|
+
function J(c,b,a,e){l.useEffect(()=>c.addListener("command",h=>{"focus"===h?u.setLocalStateFocus(b,a,e,!0):"blur"===h&&u.setLocalStateFocus(b,a,e,!1);return!1},0),[e,c,a,b])}function K(c,b){const a=l.useMemo(()=>u.createUndoManager(b,b.root.getSharedType()),[b]);l.useEffect(()=>c.addListener("command",e=>"undo"===e?(a.undo(),!0):"redo"===e?(a.redo(),!0):!1,0));return l.useCallback(()=>{a.clear()},[a])}
|
|
12
|
+
function H(c){c.update(()=>{var b=E.$getRoot();if(null===b.getFirstChild()){const a=E.$createParagraphNode();b.append(a);b=document.activeElement;(null!==E.$getSelection()||null!==b&&b===c.getRootElement())&&a.select()}},{tag:"history-merge"})}function I(c){c.update(()=>{const b=E.$getRoot();b.clear();b.select()},{tag:"skip-collab"})}
|
|
13
|
+
const L=[["Cat","255,165,0"],["Dog","0,200,55"],["Rabbit","160,0,200"],["Frog","0,172,200"],["Fox","197,200,0"],["Hedgehog","31,200,0"],["Pigeon","200,0,0"],["Squirrel","200,0,148"],["Bear","255,235,0"],["Tiger","86,255,0"],["Leopard","0,255,208"],["Zebra","0,243,255"],["Wolf","0,102,255"],["Owl","147,0,255"],["Gull","255,0,153"],["Squid","0,220,255"]],M=L[Math.floor(Math.random()*(L.length-1+1))],S=l.createContext({clientID:0,color:M[1],name:M[0],yjsDocMap:new Map});
|
|
14
|
+
function T(){return l.useContext(S)}exports.CollaborationContext=S;exports.CollaborationPlugin=function({id:c,providerFactory:b,shouldBootstrap:a}){const e=T(),{yjsDocMap:h,name:n,color:p}=e,[m]=d.useLexicalComposerContext(),q=l.useMemo(()=>b(c,h),[c,b,h]),[w,f]=G(m,c,q,h,n,p,a);e.clientID=f.clientID;K(m,f);J(m,q,n,p);return w};exports.useCollaborationContext=T;
|
|
@@ -0,0 +1,22 @@
|
|
|
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 {EditorThemeClasses, LexicalEditor, LexicalNode} from 'lexical';
|
|
11
|
+
type Props = {
|
|
12
|
+
initialConfig: {
|
|
13
|
+
editor?: LexicalEditor | null;
|
|
14
|
+
isReadOnly?: boolean;
|
|
15
|
+
namespace?: string;
|
|
16
|
+
nodes?: Array<Class<LexicalNode>>;
|
|
17
|
+
theme?: EditorThemeClasses;
|
|
18
|
+
onError: (error: Error, editor: LexicalEditor) => void;
|
|
19
|
+
};
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
};
|
|
22
|
+
export default function LexicalComposer(arg0: Props): React.ReactNode;
|
package/LexicalComposer.dev.js
CHANGED
|
@@ -10,6 +10,27 @@ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
|
10
10
|
var lexical = require('lexical');
|
|
11
11
|
var React = require('react');
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
|
+
*
|
|
16
|
+
* This source code is licensed under the MIT license found in the
|
|
17
|
+
* LICENSE file in the root directory of this source tree.
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
25
|
+
*
|
|
26
|
+
* This source code is licensed under the MIT license found in the
|
|
27
|
+
* LICENSE file in the root directory of this source tree.
|
|
28
|
+
*
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
const useLayoutEffectImpl = CAN_USE_DOM ? React.useLayoutEffect : React.useEffect;
|
|
32
|
+
var useLayoutEffect = useLayoutEffectImpl;
|
|
33
|
+
|
|
13
34
|
/**
|
|
14
35
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
36
|
*
|
|
@@ -19,7 +40,7 @@ var React = require('react');
|
|
|
19
40
|
*
|
|
20
41
|
*/
|
|
21
42
|
function LexicalComposer({
|
|
22
|
-
initialConfig
|
|
43
|
+
initialConfig,
|
|
23
44
|
children
|
|
24
45
|
}) {
|
|
25
46
|
const parentContext = React.useContext(LexicalComposerContext.LexicalComposerContext);
|
|
@@ -49,23 +70,24 @@ function LexicalComposer({
|
|
|
49
70
|
let editor = initialEditor || null;
|
|
50
71
|
|
|
51
72
|
if (editor === null) {
|
|
52
|
-
|
|
73
|
+
const newEditor = lexical.createEditor({
|
|
53
74
|
context,
|
|
54
75
|
namespace,
|
|
55
76
|
nodes,
|
|
56
|
-
onError,
|
|
77
|
+
onError: error => onError(error, newEditor),
|
|
57
78
|
parentEditor,
|
|
79
|
+
readOnly: true,
|
|
58
80
|
theme: composerTheme
|
|
59
81
|
});
|
|
60
|
-
editor
|
|
82
|
+
editor = newEditor;
|
|
61
83
|
}
|
|
62
84
|
|
|
63
85
|
return [editor, context];
|
|
64
86
|
}, // We only do this for init
|
|
65
87
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
88
|
[]);
|
|
67
|
-
|
|
68
|
-
const isReadOnly = initialConfig.
|
|
89
|
+
useLayoutEffect(() => {
|
|
90
|
+
const isReadOnly = initialConfig.readOnly;
|
|
69
91
|
const [editor] = composerContext;
|
|
70
92
|
editor.setReadOnly(isReadOnly || false); // We only do this for init
|
|
71
93
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
package/LexicalComposer.js.flow
CHANGED
|
@@ -10,13 +10,14 @@
|
|
|
10
10
|
import type {EditorThemeClasses, LexicalEditor, LexicalNode} from 'lexical';
|
|
11
11
|
|
|
12
12
|
type Props = {
|
|
13
|
-
initialConfig
|
|
13
|
+
initialConfig: $ReadOnly<{
|
|
14
14
|
editor?: LexicalEditor | null,
|
|
15
|
+
isReadOnly?: boolean,
|
|
15
16
|
namespace?: string,
|
|
16
|
-
nodes?:
|
|
17
|
+
nodes?: $ReadOnlyArray<Class<LexicalNode>>,
|
|
17
18
|
theme?: EditorThemeClasses,
|
|
18
|
-
onError
|
|
19
|
-
}
|
|
19
|
+
onError: (error: Error, editor: LexicalEditor) => void,
|
|
20
|
+
}>,
|
|
20
21
|
children: React$Node,
|
|
21
22
|
};
|
|
22
23
|
|
package/LexicalComposer.prod.js
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
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({initialConfig:h
|
|
9
|
-
!1)},[]);return
|
|
7
|
+
var b=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),n=require("react"),p="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?n.useLayoutEffect:n.useEffect;
|
|
8
|
+
module.exports=function({initialConfig:h,children:q}){const d=n.useContext(b.LexicalComposerContext),m=n.useMemo(()=>{let a,e;const {theme:k,namespace:r,editor:t,nodes:u,onError:v}=h;if(null!=k)a=k;else if(null!=d){e=d[0];var c=d[1].getTheme();null!=c&&(a=c)}c=b.createLexicalComposerContext(d,a);let g=t||null;if(null===g){const l=f.createEditor({context:c,namespace:r,nodes:u,onError:w=>v(w,l),parentEditor:e,readOnly:!0,theme:a});g=l}return[g,c]},[]);p(()=>{const a=h.readOnly,[e]=m;e.setReadOnly(a||
|
|
9
|
+
!1)},[]);return n.createElement(b.LexicalComposerContext.Provider,{value:m},q)};
|
|
@@ -0,0 +1,24 @@
|
|
|
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 type {EditorThemeClasses, LexicalEditor} from 'lexical';
|
|
10
|
+
export type LexicalComposerContextType = {
|
|
11
|
+
getTheme: () => EditorThemeClasses | null | undefined;
|
|
12
|
+
};
|
|
13
|
+
export type LexicalComposerContextWithEditor = [
|
|
14
|
+
LexicalEditor,
|
|
15
|
+
LexicalComposerContextType,
|
|
16
|
+
];
|
|
17
|
+
export declare var LexicalComposerContext: React.Context<
|
|
18
|
+
LexicalComposerContextWithEditor | null | undefined
|
|
19
|
+
>;
|
|
20
|
+
export function createLexicalComposerContext(
|
|
21
|
+
parent: LexicalComposerContextWithEditor | null | undefined,
|
|
22
|
+
theme: EditorThemeClasses | null | undefined,
|
|
23
|
+
): LexicalComposerContextType;
|
|
24
|
+
export function useLexicalComposerContext(): LexicalComposerContextWithEditor;
|
|
@@ -18,7 +18,7 @@ export type LexicalComposerContextWithEditor = [
|
|
|
18
18
|
LexicalComposerContextType,
|
|
19
19
|
];
|
|
20
20
|
|
|
21
|
-
export
|
|
21
|
+
declare export var LexicalComposerContext: React$Context<?LexicalComposerContextWithEditor>;
|
|
22
22
|
|
|
23
23
|
declare export function createLexicalComposerContext(
|
|
24
24
|
parent: ?LexicalComposerContextWithEditor,
|
|
@@ -0,0 +1,32 @@
|
|
|
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 {$ReadOnly} from 'utility-types';
|
|
10
|
+
export type Props = $ReadOnly<{
|
|
11
|
+
ariaActiveDescendantID?: string;
|
|
12
|
+
ariaAutoComplete?: string;
|
|
13
|
+
ariaControls?: string;
|
|
14
|
+
ariaDescribedBy?: string;
|
|
15
|
+
ariaExpanded?: boolean;
|
|
16
|
+
ariaLabel?: string;
|
|
17
|
+
ariaLabelledBy?: string;
|
|
18
|
+
ariaMultiline?: boolean;
|
|
19
|
+
ariaOwneeID?: string;
|
|
20
|
+
ariaRequired?: string;
|
|
21
|
+
autoCapitalize?: boolean;
|
|
22
|
+
autoComplete?: boolean;
|
|
23
|
+
autoCorrect?: boolean;
|
|
24
|
+
className?: string;
|
|
25
|
+
readOnly?: boolean;
|
|
26
|
+
role?: string;
|
|
27
|
+
style?: StyleSheetList;
|
|
28
|
+
spellCheck?: boolean;
|
|
29
|
+
tabIndex?: number;
|
|
30
|
+
testid?: string;
|
|
31
|
+
}>;
|
|
32
|
+
export default function LexicalContentEditable(props: Props): React.ReactNode;
|
|
@@ -9,6 +9,27 @@
|
|
|
9
9
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
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
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
24
|
+
*
|
|
25
|
+
* This source code is licensed under the MIT license found in the
|
|
26
|
+
* LICENSE file in the root directory of this source tree.
|
|
27
|
+
*
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
const useLayoutEffectImpl = CAN_USE_DOM ? React.useLayoutEffect : React.useEffect;
|
|
31
|
+
var useLayoutEffect = useLayoutEffectImpl;
|
|
32
|
+
|
|
12
33
|
/**
|
|
13
34
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
35
|
*
|
|
@@ -43,7 +64,7 @@ function LexicalContentEditable({
|
|
|
43
64
|
const ref = React.useCallback(rootElement => {
|
|
44
65
|
editor.setRootElement(rootElement);
|
|
45
66
|
}, [editor]);
|
|
46
|
-
|
|
67
|
+
useLayoutEffect(() => {
|
|
47
68
|
setReadOnly(editor.isReadOnly());
|
|
48
69
|
return editor.addListener('readonly', currentIsReadOnly => {
|
|
49
70
|
setReadOnly(currentIsReadOnly);
|