@lexical/react 0.6.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEPRECATED_useLexical.dev.js +1 -1
- package/DEPRECATED_useLexical.prod.js +1 -1
- package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +1 -1
- package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -1
- package/DEPRECATED_useLexicalEditor.dev.js +1 -1
- package/DEPRECATED_useLexicalEditor.prod.js +1 -1
- package/LexicalAutoEmbedPlugin.d.ts +5 -4
- package/LexicalAutoEmbedPlugin.dev.js +13 -12
- package/LexicalAutoEmbedPlugin.prod.js +4 -4
- package/LexicalAutoFocusPlugin.dev.js +1 -1
- package/LexicalAutoFocusPlugin.prod.js +1 -1
- package/LexicalNodeEventPlugin.dev.js +5 -1
- package/LexicalNodeEventPlugin.prod.js +2 -2
- package/LexicalPlainTextPlugin.d.ts +1 -1
- package/LexicalPlainTextPlugin.dev.js +23 -3
- package/LexicalPlainTextPlugin.js.flow +1 -1
- package/LexicalPlainTextPlugin.prod.js +4 -4
- package/LexicalRichTextPlugin.d.ts +3 -3
- package/LexicalRichTextPlugin.dev.js +23 -3
- package/LexicalRichTextPlugin.js.flow +1 -1
- package/LexicalRichTextPlugin.prod.js +4 -4
- package/LexicalTabIndentationPlugin.d.ts +13 -0
- package/LexicalTabIndentationPlugin.dev.js +43 -0
- package/LexicalTabIndentationPlugin.js +9 -0
- package/LexicalTabIndentationPlugin.prod.js +7 -0
- package/LexicalTreeView.dev.js +52 -9
- package/LexicalTreeView.prod.js +15 -14
- package/package.json +19 -19
- package/useLexicalEditable.d.ts +8 -0
- package/useLexicalEditable.dev.js +88 -0
- package/useLexicalEditable.js +9 -0
- package/useLexicalEditable.js.flow +12 -0
- package/useLexicalEditable.prod.js +8 -0
- package/useLexicalSubscription.d.ts +16 -0
- package/useLexicalSubscription.dev.js +67 -0
- package/useLexicalSubscription.js +9 -0
- package/useLexicalSubscription.js.flow +19 -0
- package/useLexicalSubscription.prod.js +8 -0
|
@@ -39,7 +39,7 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
39
39
|
*/
|
|
40
40
|
|
|
41
41
|
function canShowPlaceholderFromCurrentEditorState(editor) {
|
|
42
|
-
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()
|
|
42
|
+
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
|
|
43
43
|
return currentCanShowPlaceholder;
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var c=require("lexical"),f=require("react"),g=require("@lexical/text"),h=require("@lexical/utils"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;function l(a){return a.getEditorState().read(g.$canShowPlaceholderCurry(a.isComposing()
|
|
7
|
+
'use strict';var c=require("lexical"),f=require("react"),g=require("@lexical/text"),h=require("@lexical/utils"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;function l(a){return a.getEditorState().read(g.$canShowPlaceholderCurry(a.isComposing()))}
|
|
8
8
|
function m(a){let [b,d]=f.useState(()=>l(a));k(()=>{function e(){let n=l(a);d(n)}e();return h.mergeRegister(a.registerUpdateListener(()=>{e()}),a.registerEditableListener(()=>{e()}))},[a]);return b}function p(a){let b=m(a);return[f.useCallback(d=>{a.setRootElement(d)},[a]),b]}exports.useLexical=function(a){let b=f.useMemo(()=>c.createEditor(a),[]),[d,e]=p(b);return[b,d,e]}
|
|
@@ -38,7 +38,7 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
40
|
function canShowPlaceholderFromCurrentEditorState(editor) {
|
|
41
|
-
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()
|
|
41
|
+
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
|
|
42
42
|
return currentCanShowPlaceholder;
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var b=require("@lexical/text"),d=require("@lexical/utils"),e=require("react"),f="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?e.useLayoutEffect:e.useEffect;function g(a){return a.getEditorState().read(b.$canShowPlaceholderCurry(a.isComposing()
|
|
7
|
+
'use strict';var b=require("@lexical/text"),d=require("@lexical/utils"),e=require("react"),f="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?e.useLayoutEffect:e.useEffect;function g(a){return a.getEditorState().read(b.$canShowPlaceholderCurry(a.isComposing()))}
|
|
8
8
|
function h(a){let [k,l]=e.useState(()=>g(a));f(()=>{function c(){let m=g(a);l(m)}c();return d.mergeRegister(a.registerUpdateListener(()=>{c()}),a.registerEditableListener(()=>{c()}))},[a]);return k}exports.useLexicalCanShowPlaceholder=function(a){return h(a)}
|
|
@@ -38,7 +38,7 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
40
|
function canShowPlaceholderFromCurrentEditorState(editor) {
|
|
41
|
-
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()
|
|
41
|
+
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
|
|
42
42
|
return currentCanShowPlaceholder;
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var b=require("react"),f=require("@lexical/text"),g=require("@lexical/utils"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?b.useLayoutEffect:b.useEffect;function k(a){return a.getEditorState().read(f.$canShowPlaceholderCurry(a.isComposing()
|
|
7
|
+
'use strict';var b=require("react"),f=require("@lexical/text"),g=require("@lexical/utils"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?b.useLayoutEffect:b.useEffect;function k(a){return a.getEditorState().read(f.$canShowPlaceholderCurry(a.isComposing()))}
|
|
8
8
|
function l(a){let [c,d]=b.useState(()=>k(a));h(()=>{function e(){let m=k(a);d(m)}e();return g.mergeRegister(a.registerUpdateListener(()=>{e()}),a.registerEditableListener(()=>{e()}))},[a]);return c}exports.useLexicalEditor=function(a){let c=l(a);return[b.useCallback(d=>{a.setRootElement(d)},[a]),c]}
|
|
@@ -8,14 +8,15 @@
|
|
|
8
8
|
import type { LexicalNode } from 'lexical';
|
|
9
9
|
import { MenuRenderFn, TypeaheadOption } from '@lexical/react/LexicalTypeaheadMenuPlugin';
|
|
10
10
|
import { LexicalCommand, LexicalEditor } from 'lexical';
|
|
11
|
-
export declare type EmbedMatchResult = {
|
|
11
|
+
export declare type EmbedMatchResult<TEmbedMatchResult = unknown> = {
|
|
12
12
|
url: string;
|
|
13
13
|
id: string;
|
|
14
|
+
data?: TEmbedMatchResult;
|
|
14
15
|
};
|
|
15
|
-
export interface EmbedConfig {
|
|
16
|
+
export interface EmbedConfig<TEmbedMatchResultData = unknown, TEmbedMatchResult = EmbedMatchResult<TEmbedMatchResultData>> {
|
|
16
17
|
type: string;
|
|
17
|
-
parseUrl: (text: string) =>
|
|
18
|
-
insertNode: (editor: LexicalEditor, result:
|
|
18
|
+
parseUrl: (text: string) => Promise<TEmbedMatchResult | null> | TEmbedMatchResult | null;
|
|
19
|
+
insertNode: (editor: LexicalEditor, result: TEmbedMatchResult) => void;
|
|
19
20
|
}
|
|
20
21
|
export declare const URL_MATCHER: RegExp;
|
|
21
22
|
export declare const INSERT_EMBED_COMMAND: LexicalCommand<EmbedConfig['type']>;
|
|
@@ -44,15 +44,18 @@ function LexicalAutoEmbedPlugin({
|
|
|
44
44
|
setActiveEmbedConfig(null);
|
|
45
45
|
}, []);
|
|
46
46
|
const checkIfLinkNodeIsEmbeddable = React.useCallback(key => {
|
|
47
|
-
editor.getEditorState().read(() => {
|
|
47
|
+
editor.getEditorState().read(async () => {
|
|
48
48
|
const linkNode = lexical.$getNodeByKey(key);
|
|
49
49
|
|
|
50
50
|
if (link.$isLinkNode(linkNode)) {
|
|
51
|
-
|
|
51
|
+
for (let i = 0; i < embedConfigs.length; i++) {
|
|
52
|
+
const embedConfig = embedConfigs[i];
|
|
53
|
+
const urlMatch = await Promise.resolve(embedConfig.parseUrl(linkNode.__url));
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
if (urlMatch != null) {
|
|
56
|
+
setActiveEmbedConfig(embedConfig);
|
|
57
|
+
setNodeKey(linkNode.getKey());
|
|
58
|
+
}
|
|
56
59
|
}
|
|
57
60
|
}
|
|
58
61
|
});
|
|
@@ -87,7 +90,7 @@ function LexicalAutoEmbedPlugin({
|
|
|
87
90
|
return false;
|
|
88
91
|
}, lexical.COMMAND_PRIORITY_EDITOR);
|
|
89
92
|
}, [editor, embedConfigs, onOpenEmbedModalForConfig]);
|
|
90
|
-
const embedLinkViaActiveEmbedConfig = React.useCallback(() => {
|
|
93
|
+
const embedLinkViaActiveEmbedConfig = React.useCallback(async () => {
|
|
91
94
|
if (activeEmbedConfig != null && nodeKey != null) {
|
|
92
95
|
const linkNode = editor.getEditorState().read(() => {
|
|
93
96
|
const node = lexical.$getNodeByKey(nodeKey);
|
|
@@ -100,18 +103,16 @@ function LexicalAutoEmbedPlugin({
|
|
|
100
103
|
});
|
|
101
104
|
|
|
102
105
|
if (link.$isLinkNode(linkNode)) {
|
|
103
|
-
const result = activeEmbedConfig.parseUrl(linkNode.__url);
|
|
106
|
+
const result = await Promise.resolve(activeEmbedConfig.parseUrl(linkNode.__url));
|
|
104
107
|
|
|
105
108
|
if (result != null) {
|
|
106
109
|
editor.update(() => {
|
|
107
110
|
activeEmbedConfig.insertNode(editor, result);
|
|
108
|
-
});
|
|
109
111
|
|
|
110
|
-
|
|
111
|
-
editor.update(() => {
|
|
112
|
+
if (linkNode.isAttached()) {
|
|
112
113
|
linkNode.remove();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var
|
|
8
|
-
exports.LexicalAutoEmbedPlugin=function({embedConfigs:
|
|
9
|
-
D&&
|
|
10
|
-
(b.update(()=>{h.insertNode(b,a)
|
|
7
|
+
'use strict';var e=require("@lexical/link"),k=require("@lexical/react/LexicalComposerContext"),m=require("@lexical/react/LexicalTypeaheadMenuPlugin"),q=require("@lexical/utils"),r=require("lexical"),z=require("react");let A=r.createCommand("INSERT_EMBED_COMMAND");class B extends m.TypeaheadOption{constructor(f,n){super(f);this.title=f;this.onSelect=n.onSelect.bind(this)}}exports.AutoEmbedOption=B;exports.INSERT_EMBED_COMMAND=A;
|
|
8
|
+
exports.LexicalAutoEmbedPlugin=function({embedConfigs:f,onOpenEmbedModalForConfig:n,getMenuOptions:t,menuRenderFn:C}){let [b]=k.useLexicalComposerContext(),[g,u]=z.useState(null),[h,v]=z.useState(null),l=z.useCallback(()=>{u(null);v(null)},[]),w=z.useCallback(c=>{b.getEditorState().read(async()=>{const a=r.$getNodeByKey(c);if(e.$isLinkNode(a))for(let d=0;d<f.length;d++){const p=f[d];null!=await Promise.resolve(p.parseUrl(a.__url))&&(v(p),u(a.getKey()))}})},[b,f]);z.useEffect(()=>{let c=(a,{updateTags:d,
|
|
9
|
+
dirtyLeaves:p})=>{for(const [x,D]of a)"created"===D&&d.has("paste")&&1===p.size?w(x):x===g&&l()};return q.mergeRegister(...[e.LinkNode,e.AutoLinkNode].map(a=>b.registerMutationListener(a,(...d)=>c(...d))))},[w,b,f,g,l]);z.useEffect(()=>b.registerCommand(A,c=>{let a=f.find(({type:d})=>d===c);return a?(n(a),!0):!1},r.COMMAND_PRIORITY_EDITOR),[b,f,n]);let y=z.useCallback(async()=>{if(null!=h&&null!=g){const c=b.getEditorState().read(()=>{const a=r.$getNodeByKey(g);return e.$isLinkNode(a)?a:null});if(e.$isLinkNode(c)){const a=
|
|
10
|
+
await Promise.resolve(h.parseUrl(c.__url));null!=a&&b.update(()=>{h.insertNode(b,a);c.isAttached()&&c.remove()})}}},[h,b,g]),E=z.useMemo(()=>null!=h&&null!=g?t(h,y,l):[],[h,y,t,g,l]),F=z.useCallback((c,a,d)=>{b.update(()=>{c.onSelect(a);d()})},[b]);return null!=g?z.createElement(m.LexicalNodeMenuPlugin,{nodeKey:g,onClose:l,onSelectOption:F,options:E,menuRenderFn:C}):null};exports.URL_MATCHER=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/
|
|
@@ -29,7 +29,7 @@ function AutoFocusPlugin({
|
|
|
29
29
|
const activeElement = document.activeElement;
|
|
30
30
|
const rootElement = editor.getRootElement();
|
|
31
31
|
|
|
32
|
-
if (
|
|
32
|
+
if (rootElement !== null && (activeElement === null || !rootElement.contains(activeElement))) {
|
|
33
33
|
// Note: preventScroll won't work in Webkit.
|
|
34
34
|
rootElement.focus({
|
|
35
35
|
preventScroll: true
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var e=require("@lexical/react/LexicalComposerContext"),f=require("react");exports.AutoFocusPlugin=function({defaultSelection:c}){let [a]=e.useLexicalComposerContext();f.useEffect(()=>{a.focus(()=>{let d=document.activeElement,b=a.getRootElement();b.contains(d)
|
|
7
|
+
'use strict';var e=require("@lexical/react/LexicalComposerContext"),f=require("react");exports.AutoFocusPlugin=function({defaultSelection:c}){let [a]=e.useLexicalComposerContext();f.useEffect(()=>{a.focus(()=>{let d=document.activeElement,b=a.getRootElement();null===b||null!==d&&b.contains(d)||b.focus({preventScroll:!0})},{defaultSelection:c})},[c,a]);return null}
|
|
@@ -45,11 +45,15 @@ function NodeEventPlugin({
|
|
|
45
45
|
listenerRef.current = eventListener;
|
|
46
46
|
useLayoutEffect(() => {
|
|
47
47
|
return editor.registerMutationListener(nodeType, mutations => {
|
|
48
|
+
const registedElements = new WeakSet();
|
|
48
49
|
editor.getEditorState().read(() => {
|
|
49
50
|
for (const [key, mutation] of mutations) {
|
|
50
51
|
const element = editor.getElementByKey(key);
|
|
51
52
|
|
|
52
|
-
if (
|
|
53
|
+
if ( // Updated might be a move, so that might mean a new DOM element
|
|
54
|
+
// is created. In this case, we need to add and event listener too.
|
|
55
|
+
(mutation === 'created' || mutation === 'updated') && element !== null && !registedElements.has(element)) {
|
|
56
|
+
registedElements.add(element);
|
|
53
57
|
element.addEventListener(eventType, event => {
|
|
54
58
|
listenerRef.current(event, editor, key);
|
|
55
59
|
});
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var
|
|
8
|
-
exports.NodeEventPlugin=function({nodeType:
|
|
7
|
+
'use strict';var c=require("@lexical/react/LexicalComposerContext"),l=require("react"),m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?l.useLayoutEffect:l.useEffect;
|
|
8
|
+
exports.NodeEventPlugin=function({nodeType:d,eventType:n,eventListener:e}){let [a]=c.useLexicalComposerContext(),f=l.useRef(e);f.current=e;m(()=>a.registerMutationListener(d,p=>{let g=new WeakSet;a.getEditorState().read(()=>{for(let [h,k]of p){let b=a.getElementByKey(h);"created"!==k&&"updated"!==k||null===b||g.has(b)||(g.add(b),b.addEventListener(n,q=>{f.current(q,a,h)}))}})}),[a,d]);return null}
|
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
import { ErrorBoundaryType } from './shared/useDecorators';
|
|
9
9
|
export declare function PlainTextPlugin({ contentEditable, placeholder, ErrorBoundary, }: {
|
|
10
10
|
contentEditable: JSX.Element;
|
|
11
|
-
placeholder: JSX.Element |
|
|
11
|
+
placeholder: ((isEditable: boolean) => null | JSX.Element) | null | JSX.Element;
|
|
12
12
|
ErrorBoundary: ErrorBoundaryType;
|
|
13
13
|
}): JSX.Element;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
|
+
var useLexicalEditable = require('@lexical/react/useLexicalEditable');
|
|
10
11
|
var React = require('react');
|
|
11
12
|
var text = require('@lexical/text');
|
|
12
13
|
var utils = require('@lexical/utils');
|
|
@@ -42,7 +43,7 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
42
43
|
*/
|
|
43
44
|
|
|
44
45
|
function canShowPlaceholderFromCurrentEditorState(editor) {
|
|
45
|
-
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()
|
|
46
|
+
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
|
|
46
47
|
return currentCanShowPlaceholder;
|
|
47
48
|
}
|
|
48
49
|
|
|
@@ -137,10 +138,29 @@ function PlainTextPlugin({
|
|
|
137
138
|
ErrorBoundary
|
|
138
139
|
}) {
|
|
139
140
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
140
|
-
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
141
141
|
const decorators = useDecorators(editor, ErrorBoundary);
|
|
142
142
|
usePlainTextSetup(editor);
|
|
143
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable,
|
|
143
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, /*#__PURE__*/React.createElement(Placeholder, {
|
|
144
|
+
content: placeholder
|
|
145
|
+
}), decorators);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function Placeholder({
|
|
149
|
+
content
|
|
150
|
+
}) {
|
|
151
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
152
|
+
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
153
|
+
const editable = useLexicalEditable();
|
|
154
|
+
|
|
155
|
+
if (!showPlaceholder) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (typeof content === 'function') {
|
|
160
|
+
return content(editable);
|
|
161
|
+
} else {
|
|
162
|
+
return content;
|
|
163
|
+
}
|
|
144
164
|
}
|
|
145
165
|
|
|
146
166
|
exports.PlainTextPlugin = PlainTextPlugin;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var b=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),
|
|
8
|
-
function v(a){let [
|
|
9
|
-
function
|
|
10
|
-
function
|
|
7
|
+
'use strict';var b=require("@lexical/react/LexicalComposerContext"),h=require("@lexical/react/useLexicalEditable"),l=require("react"),m=require("@lexical/text"),n=require("@lexical/utils"),p=require("react-dom"),r=require("@lexical/dragon"),t=require("@lexical/plain-text"),u="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?l.useLayoutEffect:l.useEffect;
|
|
8
|
+
function v(a){return a.getEditorState().read(m.$canShowPlaceholderCurry(a.isComposing()))}function w(a){let [d,c]=l.useState(()=>v(a));u(()=>{function e(){let f=v(a);c(f)}e();return n.mergeRegister(a.registerUpdateListener(()=>{e()}),a.registerEditableListener(()=>{e()}))},[a]);return d}
|
|
9
|
+
function x(a,d){let [c,e]=l.useState(()=>a.getDecorators());u(()=>a.registerDecoratorListener(f=>{p.flushSync(()=>{e(f)})}),[a]);l.useEffect(()=>{e(a.getDecorators())},[a]);return l.useMemo(()=>{let f=[],q=Object.keys(c);for(let k=0;k<q.length;k++){var g=q[k];let z=l.createElement(d,{onError:y=>a._onError(y)},l.createElement(l.Suspense,{fallback:null},c[g]));g=a.getElementByKey(g);null!==g&&f.push(p.createPortal(z,g))}return f},[d,c,a])}
|
|
10
|
+
function A(a){u(()=>n.mergeRegister(t.registerPlainText(a),r.registerDragonSupport(a)),[a])}function B({content:a}){var [d]=b.useLexicalComposerContext();d=w(d);let c=h();return d?"function"===typeof a?a(c):a:null}exports.PlainTextPlugin=function({contentEditable:a,placeholder:d,ErrorBoundary:c}){let [e]=b.useLexicalComposerContext();c=x(e,c);A(e);return l.createElement(l.Fragment,null,a,l.createElement(B,{content:d}),c)}
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
import { ErrorBoundaryType } from './shared/useDecorators';
|
|
9
|
-
export declare function RichTextPlugin({ contentEditable, placeholder, ErrorBoundary, }:
|
|
9
|
+
export declare function RichTextPlugin({ contentEditable, placeholder, ErrorBoundary, }: {
|
|
10
10
|
contentEditable: JSX.Element;
|
|
11
|
-
placeholder: JSX.Element |
|
|
11
|
+
placeholder: ((isEditable: boolean) => null | JSX.Element) | null | JSX.Element;
|
|
12
12
|
ErrorBoundary: ErrorBoundaryType;
|
|
13
|
-
}
|
|
13
|
+
}): JSX.Element;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
|
+
var useLexicalEditable = require('@lexical/react/useLexicalEditable');
|
|
10
11
|
var React = require('react');
|
|
11
12
|
var text = require('@lexical/text');
|
|
12
13
|
var utils = require('@lexical/utils');
|
|
@@ -42,7 +43,7 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
42
43
|
*/
|
|
43
44
|
|
|
44
45
|
function canShowPlaceholderFromCurrentEditorState(editor) {
|
|
45
|
-
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()
|
|
46
|
+
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
|
|
46
47
|
return currentCanShowPlaceholder;
|
|
47
48
|
}
|
|
48
49
|
|
|
@@ -137,10 +138,29 @@ function RichTextPlugin({
|
|
|
137
138
|
ErrorBoundary
|
|
138
139
|
}) {
|
|
139
140
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
140
|
-
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
141
141
|
const decorators = useDecorators(editor, ErrorBoundary);
|
|
142
142
|
useRichTextSetup(editor);
|
|
143
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable,
|
|
143
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, /*#__PURE__*/React.createElement(Placeholder, {
|
|
144
|
+
content: placeholder
|
|
145
|
+
}), decorators);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function Placeholder({
|
|
149
|
+
content
|
|
150
|
+
}) {
|
|
151
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
152
|
+
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
153
|
+
const editable = useLexicalEditable();
|
|
154
|
+
|
|
155
|
+
if (!showPlaceholder) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (typeof content === 'function') {
|
|
160
|
+
return content(editable);
|
|
161
|
+
} else {
|
|
162
|
+
return content;
|
|
163
|
+
}
|
|
144
164
|
}
|
|
145
165
|
|
|
146
166
|
exports.RichTextPlugin = RichTextPlugin;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var b=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),
|
|
8
|
-
function v(a){let [
|
|
9
|
-
function
|
|
10
|
-
function
|
|
7
|
+
'use strict';var b=require("@lexical/react/LexicalComposerContext"),h=require("@lexical/react/useLexicalEditable"),l=require("react"),m=require("@lexical/text"),n=require("@lexical/utils"),p=require("react-dom"),r=require("@lexical/dragon"),t=require("@lexical/rich-text"),u="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?l.useLayoutEffect:l.useEffect;
|
|
8
|
+
function v(a){return a.getEditorState().read(m.$canShowPlaceholderCurry(a.isComposing()))}function w(a){let [d,c]=l.useState(()=>v(a));u(()=>{function e(){let f=v(a);c(f)}e();return n.mergeRegister(a.registerUpdateListener(()=>{e()}),a.registerEditableListener(()=>{e()}))},[a]);return d}
|
|
9
|
+
function x(a,d){let [c,e]=l.useState(()=>a.getDecorators());u(()=>a.registerDecoratorListener(f=>{p.flushSync(()=>{e(f)})}),[a]);l.useEffect(()=>{e(a.getDecorators())},[a]);return l.useMemo(()=>{let f=[],q=Object.keys(c);for(let k=0;k<q.length;k++){var g=q[k];let z=l.createElement(d,{onError:y=>a._onError(y)},l.createElement(l.Suspense,{fallback:null},c[g]));g=a.getElementByKey(g);null!==g&&f.push(p.createPortal(z,g))}return f},[d,c,a])}
|
|
10
|
+
function A(a){u(()=>n.mergeRegister(t.registerRichText(a),r.registerDragonSupport(a)),[a])}function B({content:a}){var [d]=b.useLexicalComposerContext();d=w(d);let c=h();return d?"function"===typeof a?a(c):a:null}exports.RichTextPlugin=function({contentEditable:a,placeholder:d,ErrorBoundary:c}){let [e]=b.useLexicalComposerContext();c=x(e,c);A(e);return l.createElement(l.Fragment,null,a,l.createElement(B,{content:d}),c)}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
* This plugin adds the ability to indent content using the tab key. Generally, we don't
|
|
10
|
+
* recommend using this plugin as it could negatively affect acessibility for keyboard
|
|
11
|
+
* users, causing focus to become trapped within the editor.
|
|
12
|
+
*/
|
|
13
|
+
export declare function TabIndentationPlugin(): null;
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
* This plugin adds the ability to indent content using the tab key. Generally, we don't
|
|
22
|
+
* recommend using this plugin as it could negatively affect acessibility for keyboard
|
|
23
|
+
* users, causing focus to become trapped within the editor.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
function TabIndentationPlugin() {
|
|
27
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
28
|
+
react.useEffect(() => {
|
|
29
|
+
return editor.registerCommand(lexical.KEY_TAB_COMMAND, event => {
|
|
30
|
+
const selection = lexical.$getSelection();
|
|
31
|
+
|
|
32
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
return editor.dispatchCommand(event.shiftKey ? lexical.OUTDENT_CONTENT_COMMAND : lexical.INDENT_CONTENT_COMMAND, undefined);
|
|
38
|
+
}, lexical.COMMAND_PRIORITY_EDITOR);
|
|
39
|
+
});
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.TabIndentationPlugin = TabIndentationPlugin;
|
|
@@ -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 LexicalTabIndentationPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalTabIndentationPlugin.dev.js') : require('./LexicalTabIndentationPlugin.prod.js')
|
|
9
|
+
module.exports = LexicalTabIndentationPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
'use strict';var a=require("@lexical/react/LexicalComposerContext"),d=require("lexical"),e=require("react");exports.TabIndentationPlugin=function(){let [b]=a.useLexicalComposerContext();e.useEffect(()=>b.registerCommand(d.KEY_TAB_COMMAND,c=>{let f=d.$getSelection();if(!d.$isRangeSelection(f))return!1;c.preventDefault();return b.dispatchCommand(c.shiftKey?d.OUTDENT_CONTENT_COMMAND:d.INDENT_CONTENT_COMMAND,void 0)},d.COMMAND_PRIORITY_EDITOR));return null}
|
package/LexicalTreeView.dev.js
CHANGED
|
@@ -47,22 +47,40 @@ function TreeView({
|
|
|
47
47
|
const treeElementRef = React.useRef(null);
|
|
48
48
|
const inputRef = React.useRef(null);
|
|
49
49
|
const [isPlaying, setIsPlaying] = React.useState(false);
|
|
50
|
+
const [isLimited, setIsLimited] = React.useState(false);
|
|
51
|
+
const [showLimited, setShowLimited] = React.useState(false);
|
|
52
|
+
const lastEditorStateRef = React.useRef(null);
|
|
53
|
+
const generateTree = React.useCallback(editorState => {
|
|
54
|
+
const treeText = generateContent(editor.getEditorState(), editor._config, editor._compositionKey, editor._editable);
|
|
55
|
+
setContent(treeText);
|
|
56
|
+
|
|
57
|
+
if (!timeTravelEnabled) {
|
|
58
|
+
setTimeStampedEditorStates(currentEditorStates => [...currentEditorStates, [Date.now(), editorState]]);
|
|
59
|
+
}
|
|
60
|
+
}, [editor, timeTravelEnabled]);
|
|
50
61
|
React.useEffect(() => {
|
|
51
62
|
setContent(generateContent(editor.getEditorState(), editor._config, editor._compositionKey, editor._editable));
|
|
63
|
+
}, [editor]);
|
|
64
|
+
React.useEffect(() => {
|
|
52
65
|
return utils.mergeRegister(editor.registerUpdateListener(({
|
|
53
|
-
editorState
|
|
66
|
+
editorState,
|
|
67
|
+
dirtyLeaves
|
|
54
68
|
}) => {
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
if (!showLimited && dirtyLeaves.size > 1000) {
|
|
70
|
+
lastEditorStateRef.current = editorState;
|
|
71
|
+
setIsLimited(true);
|
|
57
72
|
|
|
58
|
-
|
|
59
|
-
|
|
73
|
+
if (!showLimited) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
60
76
|
}
|
|
77
|
+
|
|
78
|
+
generateTree(editorState);
|
|
61
79
|
}), editor.registerEditableListener(() => {
|
|
62
80
|
const treeText = generateContent(editor.getEditorState(), editor._config, editor._compositionKey, editor._editable);
|
|
63
81
|
setContent(treeText);
|
|
64
82
|
}));
|
|
65
|
-
}, [
|
|
83
|
+
}, [editor, isLimited, generateTree, showLimited]);
|
|
66
84
|
const totalEditorStates = timeStampedEditorStates.length;
|
|
67
85
|
React.useEffect(() => {
|
|
68
86
|
if (isPlaying) {
|
|
@@ -113,7 +131,32 @@ function TreeView({
|
|
|
113
131
|
}, [editor]);
|
|
114
132
|
return /*#__PURE__*/React.createElement("div", {
|
|
115
133
|
className: viewClassName
|
|
116
|
-
}, !
|
|
134
|
+
}, !showLimited && isLimited ? /*#__PURE__*/React.createElement("div", {
|
|
135
|
+
style: {
|
|
136
|
+
padding: 20
|
|
137
|
+
}
|
|
138
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
139
|
+
style: {
|
|
140
|
+
marginRight: 20
|
|
141
|
+
}
|
|
142
|
+
}, "Detected large EditorState, this can impact debugging performance."), /*#__PURE__*/React.createElement("button", {
|
|
143
|
+
onClick: () => {
|
|
144
|
+
setShowLimited(true);
|
|
145
|
+
const editorState = lastEditorStateRef.current;
|
|
146
|
+
|
|
147
|
+
if (editorState !== null) {
|
|
148
|
+
lastEditorStateRef.current = null;
|
|
149
|
+
generateTree(editorState);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
style: {
|
|
153
|
+
background: 'transparent',
|
|
154
|
+
border: '1px solid white',
|
|
155
|
+
color: 'white',
|
|
156
|
+
cursor: 'pointer',
|
|
157
|
+
padding: 5
|
|
158
|
+
}
|
|
159
|
+
}, "Show full tree")) : null, !timeTravelEnabled && (showLimited || !isLimited) && totalEditorStates > 2 && /*#__PURE__*/React.createElement("button", {
|
|
117
160
|
onClick: () => {
|
|
118
161
|
const rootElement = editor.getRootElement();
|
|
119
162
|
|
|
@@ -125,9 +168,9 @@ function TreeView({
|
|
|
125
168
|
},
|
|
126
169
|
className: timeTravelButtonClassName,
|
|
127
170
|
type: "button"
|
|
128
|
-
}, "Time Travel"), /*#__PURE__*/React.createElement("pre", {
|
|
171
|
+
}, "Time Travel"), (showLimited || !isLimited) && /*#__PURE__*/React.createElement("pre", {
|
|
129
172
|
ref: treeElementRef
|
|
130
|
-
}, content), timeTravelEnabled && /*#__PURE__*/React.createElement("div", {
|
|
173
|
+
}, content), timeTravelEnabled && (showLimited || !isLimited) && /*#__PURE__*/React.createElement("div", {
|
|
131
174
|
className: timeTravelPanelClassName
|
|
132
175
|
}, /*#__PURE__*/React.createElement("button", {
|
|
133
176
|
className: timeTravelPanelButtonClassName,
|
package/LexicalTreeView.prod.js
CHANGED
|
@@ -4,18 +4,19 @@
|
|
|
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
|
-
'use strict';var
|
|
8
|
-
function
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
`: node\n \u2514 [${Array.from(b._nodes).join(", ")}]`});f+="\n selection"+a;f+="\n\n editor:";f+=`\n \u2514 namespace ${c.namespace}`;null!==e&&(f+=`\n \u2514 compositionKey ${e}`);return f+=`\n \u2514 editable ${String(l)}`}function
|
|
12
|
-
function
|
|
13
|
-
let
|
|
14
|
-
function
|
|
15
|
-
function
|
|
16
|
-
d.offset]:e===m?[f,c]=m.isBefore(w)?[d.offset,
|
|
7
|
+
'use strict';var h=require("@lexical/link"),t=require("@lexical/mark"),v=require("@lexical/utils"),F=require("lexical"),I=require("react");let J=Object.freeze({"\t":"\\t","\n":"\\n"}),K=new RegExp(Object.keys(J).join("|"),"g"),L=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
|
|
8
|
+
function M(a){let c="",e=P(a),l=a.anchor;a=a.focus;let f=l.offset,b=a.offset;c=c+`: range ${""!==e?`{ ${e} }`:""}`+`\n \u251c anchor { key: ${l.key}, offset: ${null===f?"null":f}, type: ${l.type} }`;return c+=`\n \u2514 focus { key: ${a.key}, offset: ${null===b?"null":b}, type: ${a.type} }`}
|
|
9
|
+
function Q(a,c,e,l){let f=" root\n";a=a.read(()=>{const b=F.$getSelection();R(F.$getRoot(),(d,n)=>{const x=`(${d.getKey()})`,u=d.getType()||"",r=d.isSelected(),y=t.$isMarkNode(d)?` id: [ ${d.getIDs().join(", ")} ] `:"";var m=f,w=r?L.selectedLine:" ",D=n.join(" ");if(F.$isTextNode(d)){var k=d.getTextContent();var p=0===k.length?"(empty)":`"${S(k)}"`;k=[P(d),T(d),U(d)].filter(Boolean).join(", ");k=[p,0!==k.length?`{ ${k} }`:null].filter(Boolean).join(" ").trim()}else if(h.$isLinkNode(d)){k=d.getURL();
|
|
10
|
+
k=0===k.length?"(empty)":`"${S(k)}"`;p=d.getTarget();null!=p&&(p="target: "+p);var z=Boolean;let B=d.getRel();null!=B&&(B="rel: "+B);p=[p,B].filter(z).join(", ");k=[k,0!==p.length?`{ ${p} }`:null].filter(Boolean).join(" ").trim()}else k="";f=m+`${w} ${D} ${x} ${u} ${y} ${k}\n`;f+=V({indent:n,isSelected:r,node:d,nodeKeyDisplay:x,selection:b,typeDisplay:u})});return null===b?": null":F.$isRangeSelection(b)?M(b):F.DEPRECATED_$isGridSelection(b)?`: grid\n \u2514 { grid: ${b.gridKey}, anchorCell: ${b.anchor.key}, focusCell: ${b.focus.key} }`:
|
|
11
|
+
`: node\n \u2514 [${Array.from(b._nodes).join(", ")}]`});f+="\n selection"+a;f+="\n\n editor:";f+=`\n \u2514 namespace ${c.namespace}`;null!==e&&(f+=`\n \u2514 compositionKey ${e}`);return f+=`\n \u2514 editable ${String(l)}`}function R(a,c,e=[]){a=a.getChildren();let l=a.length;a.forEach((f,b)=>{c(f,e.concat(b===l-1?L.isLastChild:L.hasNextSibling));F.$isElementNode(f)&&R(f,c,e.concat(b===l-1?L.ancestorIsLastChild:L.ancestorHasNextSibling))})}
|
|
12
|
+
function S(a){return Object.entries(J).reduce((c,[e,l])=>c.replace(new RegExp(e,"g"),String(l)),a)}
|
|
13
|
+
let W=[a=>a.hasFormat("bold")&&"Bold",a=>a.hasFormat("code")&&"Code",a=>a.hasFormat("italic")&&"Italic",a=>a.hasFormat("strikethrough")&&"Strikethrough",a=>a.hasFormat("subscript")&&"Subscript",a=>a.hasFormat("superscript")&&"Superscript",a=>a.hasFormat("underline")&&"Underline"],X=[a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"],Y=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented"];
|
|
14
|
+
function T(a){let c=X.map(e=>e(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="detail: "+c);return c}function U(a){let c=Y.map(e=>e(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="mode: "+c);return c}function P(a){let c=W.map(e=>e(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="format: "+c);return c}
|
|
15
|
+
function V({indent:a,isSelected:c,node:e,nodeKeyDisplay:l,selection:f,typeDisplay:b}){if(!F.$isTextNode(e)||!F.$isRangeSelection(f)||!c||F.$isElementNode(e))return"";c=f.anchor;var d=f.focus;if(""===e.getTextContent()||c.getNode()===f.focus.getNode()&&c.offset===d.offset)return"";d=f.anchor;let n=f.focus,x=e.getTextContent(),u=x.length;c=f=-1;if("text"===d.type&&"text"===n.type){let m=d.getNode(),w=n.getNode();m===w&&e===m&&d.offset!==n.offset?[f,c]=d.offset<n.offset?[d.offset,n.offset]:[n.offset,
|
|
16
|
+
d.offset]:e===m?[f,c]=m.isBefore(w)?[d.offset,u]:[0,d.offset]:e===w?[f,c]=w.isBefore(m)?[n.offset,u]:[0,n.offset]:[f,c]=[0,u]}e=(x.slice(0,f).match(K)||[]).length;d=(x.slice(f,c).match(K)||[]).length;let [r,y]=[f+e,c+e+d];if(r===y)return"";e=a[a.length-1]===L.hasNextSibling?L.ancestorHasNextSibling:L.ancestorIsLastChild;a=[...a.slice(0,a.length-1),e];e=Array(r+1).fill(" ");f=Array(y-r).fill(L.selectedChar);l=Array(l.length+(b.length+3)).fill(" ");return[L.selectedLine,a.join(" "),[...l,...e,...f].join("")].join(" ")+
|
|
17
17
|
"\n"}
|
|
18
|
-
exports.TreeView=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:c,timeTravelPanelButtonClassName:e,viewClassName:l,timeTravelPanelClassName:f,editor:b}){let [d,n]=
|
|
19
|
-
b._editable);
|
|
20
|
-
b,()=>{g
|
|
21
|
-
|
|
18
|
+
exports.TreeView=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:c,timeTravelPanelButtonClassName:e,viewClassName:l,timeTravelPanelClassName:f,editor:b}){let [d,n]=I.useState([]),[x,u]=I.useState(""),[r,y]=I.useState(!1),m=I.useRef(0),w=I.useRef(null),D=I.useRef(null),[k,p]=I.useState(!1),[z,B]=I.useState(!1),[A,Z]=I.useState(!1),G=I.useRef(null),H=I.useCallback(g=>{const q=Q(b.getEditorState(),b._config,b._compositionKey,b._editable);u(q);r||n(E=>[...E,[Date.now(),g]])},[b,r]);
|
|
19
|
+
I.useEffect(()=>{u(Q(b.getEditorState(),b._config,b._compositionKey,b._editable))},[b]);I.useEffect(()=>v.mergeRegister(b.registerUpdateListener(({editorState:g,dirtyLeaves:q})=>{if(!A&&1E3<q.size&&(G.current=g,B(!0),!A))return;H(g)}),b.registerEditableListener(()=>{let g=Q(b.getEditorState(),b._config,b._compositionKey,b._editable);u(g)})),[b,z,H,A]);let C=d.length;I.useEffect(()=>{if(k){let g,q=()=>{const E=m.current;E===C-1?p(!1):g=setTimeout(()=>{m.current++;const N=m.current,O=D.current;null!==
|
|
20
|
+
O&&(O.value=String(N));b.setEditorState(d[N][1]);q()},d[E+1][0]-d[E][0])};q();return()=>{clearTimeout(g)}}},[d,k,b,C]);I.useEffect(()=>{let g=w.current;if(null!==g)return g.__lexicalEditor=b,()=>{g.__lexicalEditor=null}},[b]);return I.createElement("div",{className:l},!A&&z?I.createElement("div",{style:{padding:20}},I.createElement("span",{style:{marginRight:20}},"Detected large EditorState, this can impact debugging performance."),I.createElement("button",{onClick:()=>{Z(!0);let g=G.current;null!==
|
|
21
|
+
g&&(G.current=null,H(g))},style:{background:"transparent",border:"1px solid white",color:"white",cursor:"pointer",padding:5}},"Show full tree")):null,!r&&(A||!z)&&2<C&&I.createElement("button",{onClick:()=>{let g=b.getRootElement();null!==g&&(g.contentEditable="false",m.current=C-1,y(!0))},className:a,type:"button"},"Time Travel"),(A||!z)&&I.createElement("pre",{ref:w},x),r&&(A||!z)&&I.createElement("div",{className:f},I.createElement("button",{className:e,onClick:()=>{m.current===C-1&&(m.current=
|
|
22
|
+
1);p(!k)},type:"button"},k?"Pause":"Play"),I.createElement("input",{className:c,ref:D,onChange:g=>{g=Number(g.target.value);let q=d[g];q&&(m.current=g,b.setEditorState(q[1]))},type:"range",min:"1",max:C-1}),I.createElement("button",{className:e,onClick:()=>{var g=b.getRootElement();if(null!==g){g.contentEditable="true";g=d.length-1;b.setEditorState(d[g][1]);let q=D.current;null!==q&&(q.value=String(g));y(!1);p(!1)}},type:"button"},"Exit")))}
|
package/package.json
CHANGED
|
@@ -8,29 +8,29 @@
|
|
|
8
8
|
"rich-text"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.7.0",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.
|
|
14
|
-
"@lexical/code": "0.
|
|
15
|
-
"@lexical/dragon": "0.
|
|
16
|
-
"@lexical/hashtag": "0.
|
|
17
|
-
"@lexical/history": "0.
|
|
18
|
-
"@lexical/link": "0.
|
|
19
|
-
"@lexical/list": "0.
|
|
20
|
-
"@lexical/mark": "0.
|
|
21
|
-
"@lexical/markdown": "0.
|
|
22
|
-
"@lexical/overflow": "0.
|
|
23
|
-
"@lexical/plain-text": "0.
|
|
24
|
-
"@lexical/rich-text": "0.
|
|
25
|
-
"@lexical/selection": "0.
|
|
26
|
-
"@lexical/table": "0.
|
|
27
|
-
"@lexical/text": "0.
|
|
28
|
-
"@lexical/utils": "0.
|
|
29
|
-
"@lexical/yjs": "0.
|
|
13
|
+
"@lexical/clipboard": "0.7.0",
|
|
14
|
+
"@lexical/code": "0.7.0",
|
|
15
|
+
"@lexical/dragon": "0.7.0",
|
|
16
|
+
"@lexical/hashtag": "0.7.0",
|
|
17
|
+
"@lexical/history": "0.7.0",
|
|
18
|
+
"@lexical/link": "0.7.0",
|
|
19
|
+
"@lexical/list": "0.7.0",
|
|
20
|
+
"@lexical/mark": "0.7.0",
|
|
21
|
+
"@lexical/markdown": "0.7.0",
|
|
22
|
+
"@lexical/overflow": "0.7.0",
|
|
23
|
+
"@lexical/plain-text": "0.7.0",
|
|
24
|
+
"@lexical/rich-text": "0.7.0",
|
|
25
|
+
"@lexical/selection": "0.7.0",
|
|
26
|
+
"@lexical/table": "0.7.0",
|
|
27
|
+
"@lexical/text": "0.7.0",
|
|
28
|
+
"@lexical/utils": "0.7.0",
|
|
29
|
+
"@lexical/yjs": "0.7.0",
|
|
30
30
|
"react-error-boundary": "^3.1.4"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"lexical": "0.
|
|
33
|
+
"lexical": "0.7.0",
|
|
34
34
|
"react": ">=17.x",
|
|
35
35
|
"react-dom": ">=17.x"
|
|
36
36
|
},
|
|
@@ -0,0 +1,88 @@
|
|
|
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 react = require('react');
|
|
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
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the MIT license found in the
|
|
25
|
+
* LICENSE file in the root directory of this source tree.
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
|
|
29
|
+
var useLayoutEffect = useLayoutEffectImpl;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
33
|
+
*
|
|
34
|
+
* This source code is licensed under the MIT license found in the
|
|
35
|
+
* LICENSE file in the root directory of this source tree.
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Shortcut to Lexical subscriptions when values are used for render.
|
|
41
|
+
*/
|
|
42
|
+
function useLexicalSubscription(subscription) {
|
|
43
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
44
|
+
const initializedSubscription = react.useMemo(() => subscription(editor), [editor, subscription]);
|
|
45
|
+
const valueRef = react.useRef(initializedSubscription.initialValueFn());
|
|
46
|
+
const [value, setValue] = react.useState(valueRef.current);
|
|
47
|
+
useLayoutEffect(() => {
|
|
48
|
+
const {
|
|
49
|
+
initialValueFn,
|
|
50
|
+
subscribe
|
|
51
|
+
} = initializedSubscription;
|
|
52
|
+
const currentValue = initialValueFn();
|
|
53
|
+
|
|
54
|
+
if (valueRef.current !== currentValue) {
|
|
55
|
+
valueRef.current = currentValue;
|
|
56
|
+
setValue(currentValue);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return subscribe(newValue => {
|
|
60
|
+
valueRef.current = newValue;
|
|
61
|
+
setValue(newValue);
|
|
62
|
+
});
|
|
63
|
+
}, [initializedSubscription, subscription]);
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
69
|
+
*
|
|
70
|
+
* This source code is licensed under the MIT license found in the
|
|
71
|
+
* LICENSE file in the root directory of this source tree.
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
function subscription(editor) {
|
|
76
|
+
return {
|
|
77
|
+
initialValueFn: () => editor.isEditable(),
|
|
78
|
+
subscribe: callback => {
|
|
79
|
+
return editor.registerEditableListener(callback);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function useLexicalEditable() {
|
|
85
|
+
return useLexicalSubscription(subscription);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = useLexicalEditable;
|
|
@@ -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 useLexicalEditable = process.env.NODE_ENV === 'development' ? require('./useLexicalEditable.dev.js') : require('./useLexicalEditable.prod.js')
|
|
9
|
+
module.exports = useLexicalEditable;
|
|
@@ -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
|
+
import type {LexicalEditor} from 'lexical';
|
|
11
|
+
|
|
12
|
+
declare export default function useLexicalEditable(): boolean;
|
|
@@ -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
|
+
'use strict';var b=require("@lexical/react/LexicalComposerContext"),k=require("react"),l="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?k.useLayoutEffect:k.useEffect;
|
|
8
|
+
function m(a){let [c]=b.useLexicalComposerContext(),e=k.useMemo(()=>a(c),[c,a]),d=k.useRef(e.initialValueFn()),[n,g]=k.useState(d.current);l(()=>{let {initialValueFn:p,subscribe:q}=e,f=p();d.current!==f&&(d.current=f,g(f));return q(h=>{d.current=h;g(h)})},[e,a]);return n}function r(a){return{initialValueFn:()=>a.isEditable(),subscribe:c=>a.registerEditableListener(c)}}module.exports=function(){return m(r)}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
import type { LexicalEditor } from 'lexical';
|
|
9
|
+
export declare type LexicalSubscription<T> = {
|
|
10
|
+
initialValueFn: () => T;
|
|
11
|
+
subscribe: (callback: (value: T) => void) => () => void;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Shortcut to Lexical subscriptions when values are used for render.
|
|
15
|
+
*/
|
|
16
|
+
export default function useLexicalSubscription<T>(subscription: (editor: LexicalEditor) => LexicalSubscription<T>): T;
|
|
@@ -0,0 +1,67 @@
|
|
|
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 react = require('react');
|
|
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
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the MIT license found in the
|
|
25
|
+
* LICENSE file in the root directory of this source tree.
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
|
|
29
|
+
var useLayoutEffect = useLayoutEffectImpl;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
33
|
+
*
|
|
34
|
+
* This source code is licensed under the MIT license found in the
|
|
35
|
+
* LICENSE file in the root directory of this source tree.
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Shortcut to Lexical subscriptions when values are used for render.
|
|
41
|
+
*/
|
|
42
|
+
function useLexicalSubscription(subscription) {
|
|
43
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
44
|
+
const initializedSubscription = react.useMemo(() => subscription(editor), [editor, subscription]);
|
|
45
|
+
const valueRef = react.useRef(initializedSubscription.initialValueFn());
|
|
46
|
+
const [value, setValue] = react.useState(valueRef.current);
|
|
47
|
+
useLayoutEffect(() => {
|
|
48
|
+
const {
|
|
49
|
+
initialValueFn,
|
|
50
|
+
subscribe
|
|
51
|
+
} = initializedSubscription;
|
|
52
|
+
const currentValue = initialValueFn();
|
|
53
|
+
|
|
54
|
+
if (valueRef.current !== currentValue) {
|
|
55
|
+
valueRef.current = currentValue;
|
|
56
|
+
setValue(currentValue);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return subscribe(newValue => {
|
|
60
|
+
valueRef.current = newValue;
|
|
61
|
+
setValue(newValue);
|
|
62
|
+
});
|
|
63
|
+
}, [initializedSubscription, subscription]);
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = useLexicalSubscription;
|
|
@@ -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 useLexicalSubscription = process.env.NODE_ENV === 'development' ? require('./useLexicalSubscription.dev.js') : require('./useLexicalSubscription.prod.js')
|
|
9
|
+
module.exports = useLexicalSubscription;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {LexicalEditor} from 'lexical';
|
|
11
|
+
|
|
12
|
+
export type LexicalSubscription<T> = {
|
|
13
|
+
initialValueFn: () => T,
|
|
14
|
+
subscribe: (callback: (value: T) => void) => () => void,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
declare export default function useLexicalSubscription<T>(
|
|
18
|
+
subscription: (editor: LexicalEditor) => LexicalSubscription<T>,
|
|
19
|
+
): T;
|
|
@@ -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
|
+
'use strict';var a=require("@lexical/react/LexicalComposerContext"),k=require("react"),l="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?k.useLayoutEffect:k.useEffect;
|
|
8
|
+
module.exports=function(c){let [f]=a.useLexicalComposerContext(),d=k.useMemo(()=>c(f),[f,c]),b=k.useRef(d.initialValueFn()),[m,g]=k.useState(b.current);l(()=>{let {initialValueFn:n,subscribe:p}=d,e=n();b.current!==e&&(b.current=e,g(e));return p(h=>{b.current=h;g(h)})},[d,c]);return m}
|