@lexical/react 0.1.9 → 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 +5 -44
- package/DEPRECATED_useLexical.prod.js +1 -2
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +87 -41
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +20 -18
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +22 -19
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
- package/DEPRECATED_useLexicalEditor.dev.js +1 -25
- package/DEPRECATED_useLexicalEditor.prod.js +1 -1
- package/DEPRECATED_useLexicalHistory.dev.js +1 -1
- package/DEPRECATED_useLexicalHistory.prod.js +2 -2
- package/DEPRECATED_useLexicalList.dev.js +6 -0
- package/DEPRECATED_useLexicalList.prod.js +1 -1
- package/DEPRECATED_useLexicalPlainText.dev.js +81 -89
- package/DEPRECATED_useLexicalPlainText.prod.js +15 -16
- package/DEPRECATED_useLexicalRichText.dev.js +98 -592
- package/DEPRECATED_useLexicalRichText.prod.js +17 -29
- package/LexicalAutoFormatterPlugin.d.ts +9 -0
- package/LexicalAutoFormatterPlugin.dev.js +87 -41
- package/LexicalAutoFormatterPlugin.js.flow +10 -0
- package/LexicalAutoFormatterPlugin.prod.js +21 -19
- package/LexicalAutoLinkPlugin.d.ts +20 -0
- package/LexicalAutoLinkPlugin.js.flow +23 -0
- package/LexicalCharacterLimitPlugin.d.ts +11 -0
- package/LexicalCharacterLimitPlugin.dev.js +22 -19
- package/LexicalCharacterLimitPlugin.js.flow +12 -0
- package/LexicalCharacterLimitPlugin.prod.js +9 -8
- package/LexicalClearEditorPlugin.d.ts +14 -0
- package/LexicalClearEditorPlugin.dev.js +73 -0
- package/LexicalClearEditorPlugin.js +9 -0
- package/LexicalClearEditorPlugin.js.flow +14 -0
- package/LexicalClearEditorPlugin.prod.js +8 -0
- package/LexicalCollaborationPlugin.d.ts +49 -0
- package/LexicalCollaborationPlugin.dev.js +21 -11
- package/LexicalCollaborationPlugin.js.flow +55 -0
- package/LexicalCollaborationPlugin.prod.js +7 -7
- package/LexicalComposer.d.ts +22 -0
- package/LexicalComposer.dev.js +29 -5
- package/LexicalComposer.js.flow +24 -0
- package/LexicalComposer.prod.js +3 -3
- package/LexicalComposerContext.d.ts +24 -0
- package/LexicalComposerContext.js.flow +27 -0
- package/LexicalContentEditable.d.ts +32 -0
- package/LexicalContentEditable.dev.js +35 -8
- package/LexicalContentEditable.js.flow +35 -0
- package/LexicalContentEditable.prod.js +3 -3
- package/LexicalHashtagPlugin.d.ts +9 -0
- package/LexicalHashtagPlugin.js.flow +10 -0
- package/LexicalHistoryPlugin.d.ts +29 -0
- package/LexicalHistoryPlugin.dev.js +1 -1
- package/LexicalHistoryPlugin.js.flow +34 -0
- package/LexicalHistoryPlugin.prod.js +2 -2
- package/LexicalHorizontalRuleNode.d.ts +23 -0
- package/LexicalHorizontalRuleNode.js.flow +25 -0
- package/LexicalLinkPlugin.d.ts +9 -0
- package/LexicalLinkPlugin.js.flow +10 -0
- package/LexicalListPlugin.d.ts +9 -0
- package/LexicalListPlugin.dev.js +6 -0
- package/LexicalListPlugin.js.flow +10 -0
- package/LexicalListPlugin.prod.js +2 -2
- package/LexicalNestedComposer.d.ts +20 -0
- package/LexicalNestedComposer.js.flow +21 -0
- package/LexicalOnChangePlugin.d.ts +12 -0
- package/LexicalOnChangePlugin.js.flow +14 -0
- package/LexicalPlainTextPlugin.d.ts +15 -0
- package/LexicalPlainTextPlugin.dev.js +77 -84
- package/LexicalPlainTextPlugin.js.flow +18 -0
- package/LexicalPlainTextPlugin.prod.js +12 -12
- package/LexicalRichTextPlugin.d.ts +15 -0
- package/LexicalRichTextPlugin.dev.js +93 -586
- package/LexicalRichTextPlugin.js.flow +18 -0
- package/LexicalRichTextPlugin.prod.js +13 -25
- package/LexicalTablePlugin.d.ts +9 -0
- package/LexicalTablePlugin.dev.js +23 -1
- package/LexicalTablePlugin.js.flow +10 -0
- package/LexicalTablePlugin.prod.js +4 -3
- package/LexicalTreeView.d.ts +17 -0
- package/LexicalTreeView.dev.js +10 -2
- package/LexicalTreeView.js.flow +19 -0
- package/LexicalTreeView.prod.js +9 -8
- package/README.md +0 -1
- package/package.json +6 -5
- package/useLexicalDecoratorMap.d.ts +14 -0
- package/useLexicalDecoratorMap.js.flow +16 -0
- package/useLexicalIsTextContentEmpty.d.ts +13 -0
- package/useLexicalIsTextContentEmpty.js.flow +15 -0
- package/useLexicalNodeSelection.d.ts +12 -0
- package/useLexicalNodeSelection.dev.js +70 -0
- package/useLexicalNodeSelection.js +9 -0
- package/useLexicalNodeSelection.js.flow +14 -0
- package/useLexicalNodeSelection.prod.js +8 -0
- package/withSubscriptions.d.ts +12 -0
- package/withSubscriptions.js.flow +13 -0
- package/LexicalBootstrapPlugin.dev.js +0 -122
- package/LexicalBootstrapPlugin.js +0 -9
- package/LexicalBootstrapPlugin.prod.js +0 -8
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare export default function LexicalCharacterLimitPlugin(props: {
|
|
11
|
+
charset: 'UTF-8' | 'UTF-16',
|
|
12
|
+
}): React$Node;
|
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var l=require("@lexical/react/LexicalComposerContext"),
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
var l=require("@lexical/react/LexicalComposerContext"),w=require("react"),x=require("lexical"),B=require("@lexical/react/withSubscriptions"),C=require("lexical/OverflowNode");function D(){return x.$getRoot().getTextContent()}
|
|
8
|
+
function F(b,d,p=Object.freeze({})){const {strlen:h=e=>e.length,remainingCharacters:r=()=>{}}=p;w.useEffect(()=>{if(!b.hasNodes([C.OverflowNode]))throw Error("Minified Lexical error #58; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");},[b]);w.useEffect(()=>{let e=b.getEditorState().read(D),f=0;return B(b.addListener("textcontent",q=>{e=q}),b.addListener("update",({dirtyLeaves:q})=>{var y=b.isComposing();q=0<q.size;if(!y&&
|
|
9
|
+
q){y=h(e);q=y>d||null!==f&&f>d;r(d-y);if(null===f||q){const u=G(e,d,h);b.update(()=>{const z=[];for(var c=x.$getRoot().getLatest(),A=x.$isElementNode(c)?c.getLastDescendant():c;null!==c&&!c.is(A);)if(z.push(c),x.$isElementNode(c)&&0<c.getChildrenSize())c=c.getFirstChild();else for(var t=null;null===t&&null!==c;)t=c.getNextSibling(),c=null===t?c.getParent():t;null!==c&&c.is(A)&&z.push(c);A=z.length;c=0;for(t=0;t<A;t+=1){var a=z[t];if(C.$isOverflowNode(a)){var g=c;if(c+a.getTextContentSize()<=u){var k=
|
|
10
|
+
a.getParent();g=a.getPreviousSibling();var m=a.getNextSibling();H(a);a=x.$getSelection();!x.$isRangeSelection(a)||a.anchor.getNode().isAttached()&&a.focus.getNode().isAttached()||(x.$isTextNode(g)?g.select():x.$isTextNode(m)?m.select():null!==k&&k.select())}else g<u&&(k=a.getFirstDescendant(),m=null!==k?k.getTextContentSize():0,g+=m,k=x.$isTextNode(k)&&k.isSimpleText(),g=g<=u,(k||g)&&H(a))}else if(x.$isLeafNode(a)&&(g=c,c+=a.getTextContentSize(),c>u&&!C.$isOverflowNode(a.getParent())&&(k=x.$getSelection(),
|
|
11
|
+
g<u&&x.$isTextNode(a)&&a.isSimpleText()?([,a]=a.splitText(u-g),a=I(a)):a=I(a),null!==k&&x.$setSelection(k),g=a.getPreviousSibling(),C.$isOverflowNode(g)))){m=a.getFirstChild();var v=g.getChildren();k=v.length;if(null===m)a.append(...v);else for(var n=0;n<k;n++)m.insertBefore(v[n]);n=x.$getSelection();if(x.$isRangeSelection(n)){m=n.anchor;v=m.getNode();n=n.focus;const E=m.getNode();v.is(g)?m.set(a.getKey(),m.offset,"element"):v.is(a)&&m.set(a.getKey(),k+m.offset,"element");E.is(g)?n.set(a.getKey(),
|
|
12
|
+
n.offset,"element"):E.is(a)&&n.set(a.getKey(),k+n.offset,"element")}g.remove()}}},{tag:"history-merge"})}f=y}}))},[b,d,r,h])}function G(b,d,p){var h=Intl.Segmenter;let r=0;var e=0;if("function"===typeof h){b=(new h).segment(b);for(var {segment:f}of b){e+=p(f);if(e>d)break;r+=f.length}}else for(f=Array.from(b),b=f.length,h=0;h<b;h++){const q=f[h];e+=p(q);if(e>d)break;r+=q.length}return r}function I(b){const d=C.$createOverflowNode();b.insertBefore(d);d.append(b);return d}
|
|
13
|
+
function H(b){const d=b.getChildren(),p=d.length;for(let h=0;h<p;h++)b.insertBefore(d[h]);b.remove();return 0<p?d[p-1]:null}let J=null;
|
|
14
|
+
module.exports=function({charset:b="UTF-16"}){const [d]=l.useLexicalComposerContext(),[p,h]=w.useState(0),r=w.useMemo(()=>({remainingCharacters:h,strlen:e=>{if("UTF-8"===b){if(void 0===window.TextEncoder)var f=null;else null===J&&(J=new window.TextEncoder),f=J;null===f?(f=encodeURIComponent(e).match(/%[89ABab]/g),e=e.length+(f?f.length:0)):e=f.encode(e).length;return e}if("UTF-16"===b)return e.length;throw Error("Unrecognized charset");}}),[b]);F(d,5,r);return w.createElement("span",{className:`characters-limit ${0>
|
|
15
|
+
p?"characters-limit-exceeded":""}`},p)};
|
|
@@ -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;
|
|
@@ -0,0 +1,73 @@
|
|
|
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 lexical = require('lexical');
|
|
11
|
+
var react = require('react');
|
|
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
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
36
|
+
*
|
|
37
|
+
* This source code is licensed under the MIT license found in the
|
|
38
|
+
* LICENSE file in the root directory of this source tree.
|
|
39
|
+
*
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
function LexicalClearEditorPlugin({
|
|
43
|
+
onClear
|
|
44
|
+
}) {
|
|
45
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
46
|
+
useLayoutEffect(() => {
|
|
47
|
+
return editor.addListener('command', (type, payload) => {
|
|
48
|
+
if (type === 'clearEditor') {
|
|
49
|
+
editor.update(() => {
|
|
50
|
+
if (onClear == null) {
|
|
51
|
+
const root = lexical.$getRoot();
|
|
52
|
+
const selection = lexical.$getSelection();
|
|
53
|
+
const paragraph = lexical.$createParagraphNode();
|
|
54
|
+
root.clear();
|
|
55
|
+
root.append(paragraph);
|
|
56
|
+
|
|
57
|
+
if (selection !== null) {
|
|
58
|
+
paragraph.select();
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
onClear();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return false;
|
|
68
|
+
}, 0);
|
|
69
|
+
}, [editor, onClear]);
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = LexicalClearEditorPlugin;
|
|
@@ -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
|
+
'use strict'
|
|
8
|
+
const LexicalClearEditorPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalClearEditorPlugin.dev.js') : require('./LexicalClearEditorPlugin.prod.js')
|
|
9
|
+
module.exports = LexicalClearEditorPlugin;
|
|
@@ -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
|
+
type Props = $ReadOnly<{
|
|
11
|
+
onClear?: () => void,
|
|
12
|
+
}>;
|
|
13
|
+
|
|
14
|
+
declare export default function LexicalClearEditorPlugin(Props): React$Node;
|
|
@@ -0,0 +1,8 @@
|
|
|
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 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;
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
10
|
var React = require('react');
|
|
11
11
|
var yjs = require('@lexical/yjs');
|
|
12
|
+
var lexical = require('lexical');
|
|
12
13
|
var reactDom = require('react-dom');
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -20,7 +21,6 @@ var reactDom = require('react-dom');
|
|
|
20
21
|
*
|
|
21
22
|
*/
|
|
22
23
|
const EditorPriority = 0;
|
|
23
|
-
const BootstrapPriority = 1;
|
|
24
24
|
function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBootstrap) {
|
|
25
25
|
const binding = React.useMemo(() => yjs.createBinding(editor, provider, id, docMap), [editor, provider, id, docMap]);
|
|
26
26
|
const connect = React.useCallback(() => {
|
|
@@ -33,15 +33,6 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
33
33
|
}
|
|
34
34
|
}, [provider]);
|
|
35
35
|
const bootstrapPropagationRef = React.useRef(true);
|
|
36
|
-
React.useLayoutEffect(() => {
|
|
37
|
-
return editor.addListener('command', type => {
|
|
38
|
-
if (type === 'bootstrapEditor') {
|
|
39
|
-
return bootstrapPropagationRef.current;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return false;
|
|
43
|
-
}, BootstrapPriority);
|
|
44
|
-
}, [editor]);
|
|
45
36
|
React.useEffect(() => {
|
|
46
37
|
const {
|
|
47
38
|
root
|
|
@@ -59,7 +50,7 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
59
50
|
const onSync = isSynced => {
|
|
60
51
|
if (shouldBootstrap && isSynced && root.isEmpty() && root._xmlText._length === 0) {
|
|
61
52
|
bootstrapPropagationRef.current = false;
|
|
62
|
-
editor
|
|
53
|
+
initializeEditor(editor);
|
|
63
54
|
}
|
|
64
55
|
};
|
|
65
56
|
|
|
@@ -176,6 +167,25 @@ function useYjsHistory(editor, binding) {
|
|
|
176
167
|
return clearHistory;
|
|
177
168
|
}
|
|
178
169
|
|
|
170
|
+
function initializeEditor(editor) {
|
|
171
|
+
editor.update(() => {
|
|
172
|
+
const root = lexical.$getRoot();
|
|
173
|
+
const firstChild = root.getFirstChild();
|
|
174
|
+
|
|
175
|
+
if (firstChild === null) {
|
|
176
|
+
const paragraph = lexical.$createParagraphNode();
|
|
177
|
+
root.append(paragraph);
|
|
178
|
+
const activeElement = document.activeElement;
|
|
179
|
+
|
|
180
|
+
if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
|
|
181
|
+
paragraph.select();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}, {
|
|
185
|
+
tag: 'history-merge'
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
179
189
|
/**
|
|
180
190
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
181
191
|
*
|
|
@@ -0,0 +1,55 @@
|
|
|
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 {Doc, RelativePosition} from 'yjs';
|
|
11
|
+
|
|
12
|
+
export type UserState = {
|
|
13
|
+
anchorPos: null | RelativePosition,
|
|
14
|
+
focusPos: null | RelativePosition,
|
|
15
|
+
name: string,
|
|
16
|
+
color: string,
|
|
17
|
+
focusing: boolean,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type ProviderAwareness = {
|
|
21
|
+
getLocalState: () => UserState,
|
|
22
|
+
setLocalState: (UserState) => void,
|
|
23
|
+
getStates: () => Map<number, UserState>,
|
|
24
|
+
on: (type: 'update', cb: () => void) => void,
|
|
25
|
+
off: (type: 'update', cb: () => void) => void,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export interface Provider {
|
|
29
|
+
connect(): void | Promise<void>;
|
|
30
|
+
disconnect(): void;
|
|
31
|
+
awareness: ProviderAwareness;
|
|
32
|
+
on(type: 'sync', cb: (isSynced: boolean) => void): void;
|
|
33
|
+
on(type: 'status', cb: ({status: string}) => void): void;
|
|
34
|
+
// $FlowFixMe: temp
|
|
35
|
+
on(type: 'update', cb: (any) => void): void;
|
|
36
|
+
off(type: 'sync', cb: (isSynced: boolean) => void): void;
|
|
37
|
+
// $FlowFixMe: temp
|
|
38
|
+
off(type: 'update', cb: (any) => void): void;
|
|
39
|
+
off(type: 'status', cb: ({status: string}) => void): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type CollaborationContextType = {
|
|
43
|
+
clientID: number,
|
|
44
|
+
color: string,
|
|
45
|
+
name: string,
|
|
46
|
+
yjsDocMap: Map<string, Doc>,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
declare export function CollaborationPlugin(arg0: {
|
|
50
|
+
id: string,
|
|
51
|
+
providerFactory: (id: string, yjsDocMap: Map<string, Doc>) => Provider,
|
|
52
|
+
shouldBootstrap: boolean,
|
|
53
|
+
}): React$Node;
|
|
54
|
+
declare export var CollaborationContext: React$Context<CollaborationContextType>;
|
|
55
|
+
declare export function useCollaborationContext(): CollaborationContextType;
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
const
|
|
13
|
-
function
|
|
7
|
+
var d=require("@lexical/react/LexicalComposerContext"),g=require("react"),u=require("@lexical/yjs"),A=require("lexical"),B=require("react-dom");
|
|
8
|
+
function C(b,c,a,h,n,p,q){const e=g.useMemo(()=>u.createBinding(b,a,c,h),[b,a,c,h]),k=g.useCallback(()=>{a.connect()},[a]),l=g.useCallback(()=>{try{a.disconnect()}catch(f){}},[a]),r=g.useRef(!0);g.useEffect(()=>{const {root:f}=e,{awareness:t}=a,w=({status:m})=>{b.execCommand("connected","connected"===m)},x=m=>{q&&m&&f.isEmpty()&&0===f._xmlText._length&&(r.current=!1,D(b))},y=()=>{u.syncCursorPositions(e,a)},z=(m,v)=>{v.origin!==e&&u.syncYjsChangesToLexical(e,a,m)};u.initLocalState(a,n,p,document.activeElement===
|
|
9
|
+
b.getRootElement());a.on("status",w);a.on("sync",x);t.on("update",y);f.getSharedType().observeDeep(z);const M=b.addListener("update",({prevEditorState:m,editorState:v,dirtyLeaves:I,dirtyElements:J,normalizedNodes:K,tags:L})=>{u.syncLexicalUpdateToYjs(e,a,m,v,J,I,K,L)});k();return()=>{l();a.off("sync",x);a.off("status",w);t.off("update",y);f.getSharedType().unobserveDeep(z);M()}},[e,p,k,l,b,n,a,q]);const N=g.useMemo(()=>B.createPortal(g.createElement("div",{ref:f=>{e.cursorsContainer=f}}),document.body),
|
|
10
|
+
[e]);g.useEffect(()=>b.addListener("command",(f,t)=>{"toggleConnect"===f&&void 0!==k&&void 0!==l&&(t?(console.log("Collaboration connected!"),k()):(console.log("Collaboration disconnected!"),l()));return!1},0),[k,l,b]);return[N,e]}function E(b,c){g.useEffect(()=>b.addListener("command",a=>{"focus"===a?u.setLocalStateFocus(c,!0):"blur"===a&&u.setLocalStateFocus(c,!1);return!1},0),[b,c])}
|
|
11
|
+
function F(b,c){const a=g.useMemo(()=>u.createUndoManager(c,c.root.getSharedType()),[c]);g.useEffect(()=>b.addListener("command",h=>"undo"===h?(a.undo(),!0):"redo"===h?(a.redo(),!0):!1,0));return g.useCallback(()=>{a.clear()},[a])}function D(b){b.update(()=>{var c=A.$getRoot();if(null===c.getFirstChild()){const a=A.$createParagraphNode();c.append(a);c=document.activeElement;(null!==A.$getSelection()||null!==c&&c===b.getRootElement())&&a.select()}},{tag:"history-merge"})}
|
|
12
|
+
const G=[["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"]],H=G[Math.floor(Math.random()*(G.length-1+1))],O=g.createContext({clientID:0,color:H[1],name:H[0],yjsDocMap:new Map});
|
|
13
|
+
function P(){return g.useContext(O)}exports.CollaborationContext=O;exports.CollaborationPlugin=function({id:b,providerFactory:c,shouldBootstrap:a}){const h=P(),{yjsDocMap:n,name:p,color:q}=h,[e]=d.useLexicalComposerContext(),k=g.useMemo(()=>c(b,n),[b,c,n]),[l,r]=C(e,b,k,n,p,q,a);h.clientID=r.clientID;F(e,r);E(e,k);return l};exports.useCollaborationContext=P;
|
|
@@ -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
|
@@ -18,11 +18,27 @@ var React = require('react');
|
|
|
18
18
|
*
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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;
|
|
25
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
36
|
+
*
|
|
37
|
+
* This source code is licensed under the MIT license found in the
|
|
38
|
+
* LICENSE file in the root directory of this source tree.
|
|
39
|
+
*
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
26
42
|
function LexicalComposer({
|
|
27
43
|
initialConfig = {},
|
|
28
44
|
children
|
|
@@ -54,20 +70,28 @@ function LexicalComposer({
|
|
|
54
70
|
let editor = initialEditor || null;
|
|
55
71
|
|
|
56
72
|
if (editor === null) {
|
|
57
|
-
|
|
73
|
+
const newEditor = lexical.createEditor({
|
|
58
74
|
context,
|
|
59
75
|
namespace,
|
|
60
76
|
nodes,
|
|
77
|
+
onError: error => onError(error, newEditor),
|
|
61
78
|
parentEditor,
|
|
79
|
+
readOnly: true,
|
|
62
80
|
theme: composerTheme
|
|
63
81
|
});
|
|
64
|
-
editor
|
|
82
|
+
editor = newEditor;
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
return [editor, context];
|
|
68
86
|
}, // We only do this for init
|
|
69
87
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
70
88
|
[]);
|
|
89
|
+
useLayoutEffect(() => {
|
|
90
|
+
const isReadOnly = initialConfig.readOnly;
|
|
91
|
+
const [editor] = composerContext;
|
|
92
|
+
editor.setReadOnly(isReadOnly || false); // We only do this for init
|
|
93
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
+
}, []);
|
|
71
95
|
return /*#__PURE__*/React.createElement(LexicalComposerContext.LexicalComposerContext.Provider, {
|
|
72
96
|
value: composerContext
|
|
73
97
|
}, children);
|
|
@@ -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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {EditorThemeClasses, LexicalEditor, LexicalNode} from 'lexical';
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
initialConfig?: {
|
|
14
|
+
editor?: LexicalEditor | null,
|
|
15
|
+
isReadOnly?: boolean,
|
|
16
|
+
namespace?: string,
|
|
17
|
+
nodes?: Array<Class<LexicalNode>>,
|
|
18
|
+
theme?: EditorThemeClasses,
|
|
19
|
+
onError: (error: Error, editor: LexicalEditor) => void,
|
|
20
|
+
},
|
|
21
|
+
children: React$Node,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
declare export default function LexicalComposer(Props): React$MixedElement;
|
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:
|
|
9
|
-
{value:
|
|
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;
|
|
@@ -0,0 +1,27 @@
|
|
|
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 {EditorThemeClasses, LexicalEditor} from 'lexical';
|
|
11
|
+
|
|
12
|
+
export type LexicalComposerContextType = {
|
|
13
|
+
getTheme: () => ?EditorThemeClasses,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type LexicalComposerContextWithEditor = [
|
|
17
|
+
LexicalEditor,
|
|
18
|
+
LexicalComposerContextType,
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
declare export var LexicalComposerContext: React$Context<?LexicalComposerContextWithEditor>;
|
|
22
|
+
|
|
23
|
+
declare export function createLexicalComposerContext(
|
|
24
|
+
parent: ?LexicalComposerContextWithEditor,
|
|
25
|
+
theme: ?EditorThemeClasses,
|
|
26
|
+
): LexicalComposerContextType;
|
|
27
|
+
declare export function useLexicalComposerContext(): 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;
|