@lexical/react 0.1.11 → 0.1.12
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 +49 -0
- package/LexicalCollaborationPlugin.js.flow +1 -1
- package/LexicalComposer.d.ts +22 -0
- package/LexicalComposer.dev.js +27 -5
- package/LexicalComposer.js.flow +2 -1
- 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.js.flow +0 -10
- 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 +20 -0
- 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 +6 -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,49 @@
|
|
|
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
|
+
off(type: 'sync', cb: (isSynced: boolean) => void): void;
|
|
33
|
+
// $FlowFixMe: temp
|
|
34
|
+
off(type: 'update', cb: (arg0: any) => void): void;
|
|
35
|
+
off(type: 'status', cb: (arg0: {status: string}) => void): void;
|
|
36
|
+
}
|
|
37
|
+
type CollaborationContextType = {
|
|
38
|
+
clientID: number;
|
|
39
|
+
color: string;
|
|
40
|
+
name: string;
|
|
41
|
+
yjsDocMap: Map<string, Doc>;
|
|
42
|
+
};
|
|
43
|
+
export function CollaborationPlugin(arg0: {
|
|
44
|
+
id: string;
|
|
45
|
+
providerFactory: (id: string, yjsDocMap: Map<string, Doc>) => Provider;
|
|
46
|
+
shouldBootstrap: boolean;
|
|
47
|
+
}): React.ReactNode;
|
|
48
|
+
export declare var CollaborationContext: React.Context<CollaborationContextType>;
|
|
49
|
+
export function useCollaborationContext(): CollaborationContextType;
|
|
@@ -20,7 +20,7 @@ export type UserState = {
|
|
|
20
20
|
export type ProviderAwareness = {
|
|
21
21
|
getLocalState: () => UserState,
|
|
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
|
};
|
|
@@ -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
|
*
|
|
@@ -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
|
@@ -12,10 +12,11 @@ import type {EditorThemeClasses, LexicalEditor, LexicalNode} from 'lexical';
|
|
|
12
12
|
type Props = {
|
|
13
13
|
initialConfig?: {
|
|
14
14
|
editor?: LexicalEditor | null,
|
|
15
|
+
isReadOnly?: boolean,
|
|
15
16
|
namespace?: string,
|
|
16
17
|
nodes?: Array<Class<LexicalNode>>,
|
|
17
18
|
theme?: EditorThemeClasses,
|
|
18
|
-
onError
|
|
19
|
+
onError: (error: Error, editor: LexicalEditor) => void,
|
|
19
20
|
},
|
|
20
21
|
children: React$Node,
|
|
21
22
|
};
|
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={},children:
|
|
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);
|
|
@@ -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({ariaActiveDescendantID:
|
|
9
|
-
|
|
7
|
+
var b=require("@lexical/react/LexicalComposerContext"),g=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;
|
|
8
|
+
module.exports=function({ariaActiveDescendantID:k,ariaAutoComplete:l,ariaControls:m,ariaDescribedBy:n,ariaExpanded:p,ariaLabel:q,ariaLabelledBy:r,ariaMultiline:t,ariaOwneeID:u,ariaRequired:v,autoCapitalize:w,autoComplete:x,autoCorrect:y,className:z,role:e="textbox",spellCheck:A=!0,style:B,tabIndex:C,testid:D}){const [c]=b.useLexicalComposerContext(),[a,f]=g.useState(!0),E=g.useCallback(d=>{c.setRootElement(d)},[c]);h(()=>{f(c.isReadOnly());return c.addListener("readonly",d=>{f(d)})},[c]);return g.createElement("div",
|
|
9
|
+
{"aria-activedescendant":a?null:k,"aria-autocomplete":a?null:l,"aria-controls":a?null:m,"aria-describedby":n,"aria-expanded":a?null:"combobox"===e?!!p:null,"aria-label":q,"aria-labelledby":r,"aria-multiline":t,"aria-owns":a?null:u,"aria-required":v,autoCapitalize:w,autoComplete:x,autoCorrect:y,className:z,contentEditable:!a,"data-testid":D,ref:E,role:a?null:e,spellCheck:A,style:B,tabIndex:C})};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export default function LexicalHashtagPlugin(): React.ReactNode;
|
|
@@ -6,15 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
|
-
import type {LexicalEditor, TextNode} from 'lexical';
|
|
10
9
|
|
|
11
|
-
declare function getHashtagRegexStringChars(): $ReadOnly<{
|
|
12
|
-
alpha: string,
|
|
13
|
-
alphanumeric: string,
|
|
14
|
-
hashChars: string,
|
|
15
|
-
}>;
|
|
16
|
-
|
|
17
|
-
declare function getHashtagRegexString(): string;
|
|
18
|
-
declare function textNodeTransform(node: TextNode): void;
|
|
19
|
-
declare function useHashtags(editor: LexicalEditor): void;
|
|
20
10
|
declare export default function LexicalHashtagPlugin(): React$Node;
|
|
@@ -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
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
EditorState,
|
|
11
|
+
GridSelection,
|
|
12
|
+
LexicalEditor,
|
|
13
|
+
NodeSelection,
|
|
14
|
+
RangeSelection,
|
|
15
|
+
} from 'lexical';
|
|
16
|
+
export type HistoryStateEntry = {
|
|
17
|
+
editor: LexicalEditor;
|
|
18
|
+
editorState: EditorState;
|
|
19
|
+
undoSelection?: RangeSelection | NodeSelection | GridSelection | null;
|
|
20
|
+
};
|
|
21
|
+
export type HistoryState = {
|
|
22
|
+
current: null | HistoryStateEntry;
|
|
23
|
+
redoStack: Array<HistoryStateEntry>;
|
|
24
|
+
undoStack: Array<HistoryStateEntry>;
|
|
25
|
+
};
|
|
26
|
+
export function HistoryPlugin(arg0: {
|
|
27
|
+
externalHistoryState?: HistoryState;
|
|
28
|
+
}): React.ReactNode;
|
|
29
|
+
export function createEmptyHistoryState(): HistoryState;
|
|
@@ -0,0 +1,23 @@
|
|
|
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 {LexicalNode} from 'lexical';
|
|
10
|
+
import {DecoratorNode} from 'lexical';
|
|
11
|
+
export declare class HorizontalRuleNode extends DecoratorNode<React.ReactNode> {
|
|
12
|
+
getType(): string;
|
|
13
|
+
clone(node: HorizontalRuleNode): HorizontalRuleNode;
|
|
14
|
+
createDOM(): HTMLElement;
|
|
15
|
+
getTextContent(): '\n';
|
|
16
|
+
isTopLevel(): true;
|
|
17
|
+
updateDOM(): false;
|
|
18
|
+
decorate(): React.ReactNode;
|
|
19
|
+
}
|
|
20
|
+
export function $createHorizontalRuleNode(): HorizontalRuleNode;
|
|
21
|
+
export function $isHorizontalRuleNode(
|
|
22
|
+
node: LexicalNode | null | undefined,
|
|
23
|
+
): boolean;
|
|
@@ -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
|
+
import {Class} from 'utility-types';
|
|
10
|
+
import type {DecoratorEditor, EditorThemeClasses, LexicalNode} from 'lexical';
|
|
11
|
+
export default function LexicalNestedComposer(arg0: {
|
|
12
|
+
initialConfig?: {
|
|
13
|
+
namespace?: string;
|
|
14
|
+
decoratorEditor: DecoratorEditor;
|
|
15
|
+
nodes?: Array<Class<LexicalNode>>;
|
|
16
|
+
theme?: EditorThemeClasses;
|
|
17
|
+
onError?: (arg0: Error) => void;
|
|
18
|
+
};
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
}): React.ReactNode;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {EditorState, LexicalEditor} from 'lexical';
|
|
10
|
+
export default function OnChangePlugin(arg0: {
|
|
11
|
+
onChange: (editorState: EditorState, editor: LexicalEditor) => void;
|
|
12
|
+
}): null;
|
|
@@ -0,0 +1,15 @@
|
|
|
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 {EditorState} from 'lexical';
|
|
10
|
+
type InitialEditorStateType = null | string | EditorState | (() => void);
|
|
11
|
+
export default function PlainTextPlugin(arg0: {
|
|
12
|
+
contentEditable: React.ReactNode;
|
|
13
|
+
initialEditorState?: InitialEditorStateType;
|
|
14
|
+
placeholder: React.ReactNode;
|
|
15
|
+
}): React.ReactNode;
|