@lexical/react 0.3.7 → 0.3.10
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/LexicalAutoEmbedPlugin.d.ts +46 -0
- package/LexicalAutoEmbedPlugin.dev.js +490 -0
- package/LexicalAutoEmbedPlugin.js +9 -0
- package/LexicalAutoEmbedPlugin.prod.js +21 -0
- package/LexicalAutoLinkPlugin.dev.js +1 -1
- package/LexicalAutoLinkPlugin.prod.js +2 -2
- package/LexicalCollaborationContext.d.ts +19 -0
- package/LexicalCollaborationContext.dev.js +38 -0
- package/LexicalCollaborationContext.js +9 -0
- package/LexicalCollaborationContext.js.flow +21 -0
- package/LexicalCollaborationContext.prod.js +8 -0
- package/LexicalCollaborationPlugin.d.ts +0 -10
- package/LexicalCollaborationPlugin.dev.js +13 -20
- package/LexicalCollaborationPlugin.js.flow +0 -9
- package/LexicalCollaborationPlugin.prod.js +9 -10
- package/LexicalLinkPlugin.dev.js +15 -2
- package/LexicalLinkPlugin.prod.js +2 -1
- package/LexicalNestedComposer.dev.js +11 -5
- package/LexicalNestedComposer.prod.js +3 -3
- package/LexicalOnChangePlugin.d.ts +2 -1
- package/LexicalOnChangePlugin.dev.js +6 -3
- package/LexicalOnChangePlugin.js.flow +2 -0
- package/LexicalOnChangePlugin.prod.js +2 -2
- package/LexicalTableOfContents__EXPERIMENTAL.d.ts +14 -0
- package/LexicalTableOfContents__EXPERIMENTAL.dev.js +144 -0
- package/LexicalTableOfContents__EXPERIMENTAL.js +9 -0
- package/LexicalTableOfContents__EXPERIMENTAL.js.flow +17 -0
- package/LexicalTableOfContents__EXPERIMENTAL.prod.js +10 -0
- package/LexicalTreeView.dev.js +43 -9
- package/LexicalTreeView.prod.js +13 -13
- package/LexicalTypeaheadMenuPlugin.d.ts +52 -0
- package/LexicalTypeaheadMenuPlugin.dev.js +520 -0
- package/LexicalTypeaheadMenuPlugin.js +9 -0
- package/LexicalTypeaheadMenuPlugin.prod.js +22 -0
- package/package.json +19 -19
package/LexicalTreeView.dev.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var link = require('@lexical/link');
|
|
9
10
|
var mark = require('@lexical/mark');
|
|
10
11
|
var lexical = require('lexical');
|
|
11
12
|
var React = require('react');
|
|
@@ -92,7 +93,7 @@ function TreeView({
|
|
|
92
93
|
|
|
93
94
|
play();
|
|
94
95
|
return () => {
|
|
95
|
-
|
|
96
|
+
clearTimeout(timeoutId);
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
99
|
}, [timeStampedEditorStates, isPlaying, editor, totalEditorStates]);
|
|
@@ -120,7 +121,8 @@ function TreeView({
|
|
|
120
121
|
setTimeTravelEnabled(true);
|
|
121
122
|
}
|
|
122
123
|
},
|
|
123
|
-
className: timeTravelButtonClassName
|
|
124
|
+
className: timeTravelButtonClassName,
|
|
125
|
+
type: "button"
|
|
124
126
|
}, "Time Travel"), /*#__PURE__*/React.createElement("pre", {
|
|
125
127
|
ref: treeElementRef
|
|
126
128
|
}, content), timeTravelEnabled && /*#__PURE__*/React.createElement("div", {
|
|
@@ -129,7 +131,8 @@ function TreeView({
|
|
|
129
131
|
className: timeTravelPanelButtonClassName,
|
|
130
132
|
onClick: () => {
|
|
131
133
|
setIsPlaying(!isPlaying);
|
|
132
|
-
}
|
|
134
|
+
},
|
|
135
|
+
type: "button"
|
|
133
136
|
}, isPlaying ? 'Pause' : 'Play'), /*#__PURE__*/React.createElement("input", {
|
|
134
137
|
className: timeTravelPanelSliderClassName,
|
|
135
138
|
ref: inputRef,
|
|
@@ -164,7 +167,8 @@ function TreeView({
|
|
|
164
167
|
setTimeTravelEnabled(false);
|
|
165
168
|
setIsPlaying(false);
|
|
166
169
|
}
|
|
167
|
-
}
|
|
170
|
+
},
|
|
171
|
+
type: "button"
|
|
168
172
|
}, "Exit")));
|
|
169
173
|
}
|
|
170
174
|
|
|
@@ -228,27 +232,37 @@ function visitTree(currentNode, visitor, indent = []) {
|
|
|
228
232
|
|
|
229
233
|
function normalize(text) {
|
|
230
234
|
return Object.entries(NON_SINGLE_WIDTH_CHARS_REPLACEMENT).reduce((acc, [key, value]) => acc.replace(new RegExp(key, 'g'), String(value)), text);
|
|
231
|
-
}
|
|
235
|
+
} // TODO Pass via props to allow customizability
|
|
236
|
+
|
|
232
237
|
|
|
233
238
|
function printNode(node) {
|
|
234
239
|
if (lexical.$isTextNode(node)) {
|
|
235
240
|
const text = node.getTextContent(true);
|
|
236
241
|
const title = text.length === 0 ? '(empty)' : `"${normalize(text)}"`;
|
|
237
|
-
const properties =
|
|
242
|
+
const properties = printAllTextNodeProperties(node);
|
|
238
243
|
return [title, properties.length !== 0 ? `{ ${properties} }` : null].filter(Boolean).join(' ').trim();
|
|
244
|
+
} else if (link.$isLinkNode(node)) {
|
|
245
|
+
const link = node.getURL();
|
|
246
|
+
const title = link.length === 0 ? '(empty)' : `"${normalize(link)}"`;
|
|
247
|
+
const properties = printAllLinkNodeProperties(node);
|
|
248
|
+
return [title, properties.length !== 0 ? `{ ${properties} }` : null].filter(Boolean).join(' ').trim();
|
|
249
|
+
} else {
|
|
250
|
+
return '';
|
|
239
251
|
}
|
|
240
|
-
|
|
241
|
-
return '';
|
|
242
252
|
}
|
|
243
253
|
|
|
244
254
|
const FORMAT_PREDICATES = [node => node.hasFormat('bold') && 'Bold', node => node.hasFormat('code') && 'Code', node => node.hasFormat('italic') && 'Italic', node => node.hasFormat('strikethrough') && 'Strikethrough', node => node.hasFormat('subscript') && 'Subscript', node => node.hasFormat('superscript') && 'Superscript', node => node.hasFormat('underline') && 'Underline'];
|
|
245
255
|
const DETAIL_PREDICATES = [node => node.isDirectionless() && 'Directionless', node => node.isUnmergeable() && 'Unmergeable'];
|
|
246
256
|
const MODE_PREDICATES = [node => node.isToken() && 'Token', node => node.isSegmented() && 'Segmented', node => node.isInert() && 'Inert'];
|
|
247
257
|
|
|
248
|
-
function
|
|
258
|
+
function printAllTextNodeProperties(node) {
|
|
249
259
|
return [printFormatProperties(node), printDetailProperties(node), printModeProperties(node)].filter(Boolean).join(', ');
|
|
250
260
|
}
|
|
251
261
|
|
|
262
|
+
function printAllLinkNodeProperties(node) {
|
|
263
|
+
return [printTargetProperties(node), printRelProperties(node)].filter(Boolean).join(', ');
|
|
264
|
+
}
|
|
265
|
+
|
|
252
266
|
function printDetailProperties(nodeOrSelection) {
|
|
253
267
|
let str = DETAIL_PREDICATES.map(predicate => predicate(nodeOrSelection)).filter(Boolean).join(', ').toLocaleLowerCase();
|
|
254
268
|
|
|
@@ -279,6 +293,26 @@ function printFormatProperties(nodeOrSelection) {
|
|
|
279
293
|
return str;
|
|
280
294
|
}
|
|
281
295
|
|
|
296
|
+
function printTargetProperties(node) {
|
|
297
|
+
let str = node.getTarget(); // TODO Fix nullish on LinkNode
|
|
298
|
+
|
|
299
|
+
if (str != null) {
|
|
300
|
+
str = 'target: ' + str;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return str;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function printRelProperties(node) {
|
|
307
|
+
let str = node.getRel(); // TODO Fix nullish on LinkNode
|
|
308
|
+
|
|
309
|
+
if (str != null) {
|
|
310
|
+
str = 'rel: ' + str;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return str;
|
|
314
|
+
}
|
|
315
|
+
|
|
282
316
|
function printSelectedCharsLine({
|
|
283
317
|
indent,
|
|
284
318
|
isSelected,
|
package/LexicalTreeView.prod.js
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
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 l=require("@lexical/mark"),
|
|
8
|
-
function
|
|
9
|
-
function
|
|
10
|
-
b+=
|
|
11
|
-
function
|
|
12
|
-
let
|
|
13
|
-
function
|
|
14
|
-
function
|
|
15
|
-
|
|
7
|
+
'use strict';var l=require("@lexical/link"),q=require("@lexical/mark"),t=require("lexical"),D=require("react");let E=Object.freeze({"\t":"\\t","\n":"\\n"}),F=new RegExp(Object.keys(E).join("|"),"g"),G=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
|
|
8
|
+
function H(a){let b="",c=I(a),d=a.anchor;a=a.focus;let e=d.offset,g=a.offset;b=b+`: range ${""!==c?`{ ${c} }`:""}`+`\n \u251c anchor { key: ${d.key}, offset: ${null===e?"null":e}, type: ${d.type} }`;return b+=`\n \u2514 focus { key: ${a.key}, offset: ${null===g?"null":g}, type: ${a.type} }`}
|
|
9
|
+
function K(a){let b=" root\n";a=a.read(()=>{const c=t.$getSelection();L(t.$getRoot(),(d,e)=>{const g=`(${d.getKey()})`,h=d.getType()||"",n=d.isSelected(),w=q.$isMarkNode(d)?` id: [ ${d.getIDs().join(", ")} ] `:"";var v=b,r=n?G.selectedLine:" ",x=e.join(" ");if(t.$isTextNode(d)){var f=d.getTextContent(!0);var m=0===f.length?"(empty)":`"${M(f)}"`;f=[I(d),N(d),O(d)].filter(Boolean).join(", ");f=[m,0!==f.length?`{ ${f} }`:null].filter(Boolean).join(" ").trim()}else if(l.$isLinkNode(d)){f=d.getURL();f=
|
|
10
|
+
0===f.length?"(empty)":`"${M(f)}"`;m=d.getTarget();null!=m&&(m="target: "+m);var y=Boolean;let u=d.getRel();null!=u&&(u="rel: "+u);m=[m,u].filter(y).join(", ");f=[f,0!==m.length?`{ ${m} }`:null].filter(Boolean).join(" ").trim()}else f="";b=v+`${r} ${x} ${g} ${h} ${w} ${f}\n`;b+=P({indent:e,isSelected:n,node:d,nodeKeyDisplay:g,selection:c,typeDisplay:h})});return null===c?": null":t.$isRangeSelection(c)?H(c):t.$isGridSelection(c)?`: grid\n \u2514 { grid: ${c.gridKey}, anchorCell: ${c.anchor.key}, focusCell: ${c.focus.key} }`:
|
|
11
|
+
`: node\n \u2514 [${Array.from(c._nodes).join(", ")}]`});return b+"\n selection"+a}function L(a,b,c=[]){a=a.getChildren();let d=a.length;a.forEach((e,g)=>{b(e,c.concat(g===d-1?G.isLastChild:G.hasNextSibling));t.$isElementNode(e)&&L(e,b,c.concat(g===d-1?G.ancestorIsLastChild:G.ancestorHasNextSibling))})}function M(a){return Object.entries(E).reduce((b,[c,d])=>b.replace(new RegExp(c,"g"),String(d)),a)}
|
|
12
|
+
let Q=[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"],R=[a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"],S=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented",a=>a.isInert()&&"Inert"];
|
|
13
|
+
function N(a){let b=R.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="detail: "+b);return b}function O(a){let b=S.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="mode: "+b);return b}function I(a){let b=Q.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="format: "+b);return b}
|
|
14
|
+
function P({indent:a,isSelected:b,node:c,nodeKeyDisplay:d,selection:e,typeDisplay:g}){if(!t.$isTextNode(c)||!t.$isRangeSelection(e)||!b||t.$isElementNode(c))return"";b=e.anchor;var h=e.focus;if(""===c.getTextContent()||b.getNode()===e.focus.getNode()&&b.offset===h.offset)return"";h=e.anchor;let n=e.focus,w=c.getTextContent(!0),v=w.length;b=e=-1;if("text"===h.type&&"text"===n.type){let f=h.getNode(),m=n.getNode();f===m&&c===f&&h.offset!==n.offset?[e,b]=h.offset<n.offset?[h.offset,n.offset]:[n.offset,
|
|
15
|
+
h.offset]:c===f?[e,b]=f.isBefore(m)?[h.offset,v]:[0,h.offset]:c===m?[e,b]=m.isBefore(f)?[n.offset,v]:[0,n.offset]:[e,b]=[0,v]}c=(w.slice(0,e).match(F)||[]).length;h=(w.slice(e,b).match(F)||[]).length;let [r,x]=[e+c,b+c+h];if(r===x)return"";c=a[a.length-1]===G.hasNextSibling?G.ancestorHasNextSibling:G.ancestorIsLastChild;a=[...a.slice(0,a.length-1),c];c=Array(r+1).fill(" ");e=Array(x-r).fill(G.selectedChar);d=Array(d.length+(g.length+3)).fill(" ");return[G.selectedLine,a.join(" "),[...d,...c,...e].join("")].join(" ")+
|
|
16
16
|
"\n"}
|
|
17
|
-
exports.TreeView=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:
|
|
18
|
-
|
|
19
|
-
{let
|
|
20
|
-
if(null!==
|
|
17
|
+
exports.TreeView=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:d,timeTravelPanelClassName:e,editor:g}){let [h,n]=D.useState([]),[w,v]=D.useState(""),[r,x]=D.useState(!1),f=D.useRef(0),m=D.useRef(null),y=D.useRef(null),[u,C]=D.useState(!1);D.useEffect(()=>{v(K(g.getEditorState()));return g.registerUpdateListener(({editorState:k})=>{let p=g._compositionKey,z=K(g.getEditorState());v([z,null!==p&&`Composition key: ${p}`].filter(Boolean).join("\n\n"));r||
|
|
18
|
+
n(B=>[...B,[Date.now(),k]])})},[r,g]);let A=h.length;D.useEffect(()=>{if(u){let k,p=()=>{const z=f.current;z===A-1?C(!1):k=setTimeout(()=>{f.current++;const B=f.current,J=y.current;null!==J&&(J.value=String(B));g.setEditorState(h[B][1]);p()},h[z+1][0]-h[z][0])};p();return()=>{clearTimeout(k)}}},[h,u,g,A]);D.useEffect(()=>{let k=m.current;if(null!==k)return k.__lexicalEditor=g,()=>{k.__lexicalEditor=null}},[g]);return D.createElement("div",{className:d},!r&&2<A&&D.createElement("button",{onClick:()=>
|
|
19
|
+
{let k=g.getRootElement();null!==k&&(k.contentEditable="false",f.current=A-1,x(!0))},className:a,type:"button"},"Time Travel"),D.createElement("pre",{ref:m},w),r&&D.createElement("div",{className:e},D.createElement("button",{className:c,onClick:()=>{C(!u)},type:"button"},u?"Pause":"Play"),D.createElement("input",{className:b,ref:y,onChange:k=>{k=Number(k.target.value);let p=h[k];p&&(f.current=k,g.setEditorState(p[1]))},type:"range",min:"1",max:A-1}),D.createElement("button",{className:c,onClick:()=>
|
|
20
|
+
{var k=g.getRootElement();if(null!==k){k.contentEditable="true";k=h.length-1;g.setEditorState(h[k][1]);let p=y.current;null!==p&&(p.value=String(k));x(!1);C(!1)}},type:"button"},"Exit")))}
|
|
@@ -0,0 +1,52 @@
|
|
|
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 { LexicalEditor, NodeKey, TextNode } from 'lexical';
|
|
9
|
+
import { MutableRefObject, ReactPortal } from 'react';
|
|
10
|
+
export declare type QueryMatch = {
|
|
11
|
+
leadOffset: number;
|
|
12
|
+
matchingString: string;
|
|
13
|
+
replaceableString: string;
|
|
14
|
+
};
|
|
15
|
+
export declare type Resolution = {
|
|
16
|
+
match: QueryMatch;
|
|
17
|
+
getRect: () => ClientRect;
|
|
18
|
+
};
|
|
19
|
+
export declare const PUNCTUATION = "\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";
|
|
20
|
+
export declare class TypeaheadOption {
|
|
21
|
+
key: string;
|
|
22
|
+
ref?: MutableRefObject<HTMLElement | null>;
|
|
23
|
+
constructor(key: string);
|
|
24
|
+
setRefElement(element: HTMLElement | null): void;
|
|
25
|
+
}
|
|
26
|
+
declare type MenuRenderFn<TOption extends TypeaheadOption> = (anchorElement: HTMLElement | null, itemProps: {
|
|
27
|
+
selectedIndex: number | null;
|
|
28
|
+
selectOptionAndCleanUp: (option: TOption) => void;
|
|
29
|
+
setHighlightedIndex: (index: number) => void;
|
|
30
|
+
}, matchingString: string) => ReactPortal | JSX.Element | null;
|
|
31
|
+
export declare function useBasicTypeaheadTriggerMatch(trigger: string, { minLength, maxLength }: {
|
|
32
|
+
minLength?: number;
|
|
33
|
+
maxLength?: number;
|
|
34
|
+
}): TriggerFn;
|
|
35
|
+
declare type TypeaheadMenuPluginArgs<TOption extends TypeaheadOption> = {
|
|
36
|
+
onQueryChange: (matchingString: string | null) => void;
|
|
37
|
+
onSelectOption: (option: TOption, textNodeContainingQuery: TextNode | null, closeMenu: () => void, matchingString: string) => void;
|
|
38
|
+
options: Array<TOption>;
|
|
39
|
+
menuRenderFn: MenuRenderFn<TOption>;
|
|
40
|
+
triggerFn: TriggerFn;
|
|
41
|
+
};
|
|
42
|
+
declare type TriggerFn = (text: string, editor: LexicalEditor) => QueryMatch | null;
|
|
43
|
+
export declare function LexicalTypeaheadMenuPlugin<TOption extends TypeaheadOption>({ options, onQueryChange, onSelectOption, menuRenderFn, triggerFn, }: TypeaheadMenuPluginArgs<TOption>): JSX.Element | null;
|
|
44
|
+
declare type NodeMenuPluginArgs<TOption extends TypeaheadOption> = {
|
|
45
|
+
onSelectOption: (option: TOption, textNodeContainingQuery: TextNode | null, closeMenu: () => void, matchingString: string) => void;
|
|
46
|
+
options: Array<TOption>;
|
|
47
|
+
nodeKey: NodeKey | null;
|
|
48
|
+
onClose: () => void;
|
|
49
|
+
menuRenderFn: MenuRenderFn<TOption>;
|
|
50
|
+
};
|
|
51
|
+
export declare function LexicalNodeMenuPlugin<TOption extends TypeaheadOption>({ options, nodeKey, onClose, onSelectOption, menuRenderFn, }: NodeMenuPluginArgs<TOption>): JSX.Element | null;
|
|
52
|
+
export {};
|