@lexical/react 0.12.5 → 0.12.6
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/LexicalTablePlugin.dev.js +3 -0
- package/LexicalTablePlugin.prod.js +2 -1
- package/LexicalTreeView.dev.js +2 -1
- package/LexicalTreeView.prod.js +16 -16
- package/package.json +19 -19
|
@@ -128,6 +128,9 @@ function TablePlugin({
|
|
|
128
128
|
lastRowCell = cell;
|
|
129
129
|
unmerged.push(cell);
|
|
130
130
|
} else if (cell.getColSpan() > 1 || cell.getRowSpan() > 1) {
|
|
131
|
+
if (!table.$isTableCellNode(cell)) {
|
|
132
|
+
throw Error(`Expected TableNode cell to be a TableCellNode`);
|
|
133
|
+
}
|
|
131
134
|
const newCell = table.$createTableCellNode(cell.__headerState);
|
|
132
135
|
if (lastRowCell !== null) {
|
|
133
136
|
lastRowCell.insertAfter(newCell);
|
|
@@ -8,4 +8,5 @@
|
|
|
8
8
|
exports.TablePlugin=function({hasCellMerge:m=!0,hasCellBackgroundColor:n=!0,hasTabHandler:p=!0}){let [d]=c.useLexicalComposerContext();w.useEffect(()=>{d.hasNodes([k.TableNode,k.TableCellNode,k.TableRowNode])||x(10);return d.registerCommand(k.INSERT_TABLE_COMMAND,({columns:a,rows:e,includeHeaders:h})=>{a=k.$createTableNodeWithDimensions(Number(e),Number(a),h);r.$insertNodeToNearestRoot(a);a=a.getFirstDescendant();v.$isTextNode(a)&&a.select();return!0},v.COMMAND_PRIORITY_EDITOR)},[d]);w.useEffect(()=>
|
|
9
9
|
{let a=new Map,e=b=>{const f=b.getKey(),l=d.getElementByKey(f);l&&!a.has(f)&&(b=k.applyTableHandlers(b,l,d,p),a.set(f,b))};d.getEditorState().read(()=>{let b=v.$nodesOfType(k.TableNode);for(let f of b)k.$isTableNode(f)&&e(f)});let h=d.registerMutationListener(k.TableNode,b=>{for(const [f,l]of b)"created"===l?d.getEditorState().read(()=>{const g=v.$getNodeByKey(f);k.$isTableNode(g)&&e(g)}):"destroyed"===l&&(b=a.get(f),void 0!==b&&(b.removeListeners(),a.delete(f)))});return()=>{h();for(let [,b]of a)b.removeListeners()}},
|
|
10
10
|
[d,p]);w.useEffect(()=>{if(!m)return d.registerNodeTransform(k.TableCellNode,a=>{if(1<a.getColSpan()||1<a.getRowSpan()){var [,,e]=v.DEPRECATED_$getNodeTriplet(a);[a]=v.DEPRECATED_$computeGridMap(e,a,a);let b=a.length,f=a[0].length;e=e.getFirstChild();if(!v.DEPRECATED_$isGridRowNode(e))throw Error("Expected TableNode first child to be a RowNode");let l=[];for(let g=0;g<b;g++){if(0!==g&&(e=e.getNextSibling(),!v.DEPRECATED_$isGridRowNode(e)))throw Error("Expected TableNode first child to be a RowNode");
|
|
11
|
-
let u=null;for(let t=0;t<f;t++){var h=a[g][t];let q=h.cell;if(h.startRow===g&&h.startColumn===t)u=q,l.push(q);else if(1<q.getColSpan()||1<q.getRowSpan())h=k.$createTableCellNode(q.__headerState)
|
|
11
|
+
let u=null;for(let t=0;t<f;t++){var h=a[g][t];let q=h.cell;if(h.startRow===g&&h.startColumn===t)u=q,l.push(q);else if(1<q.getColSpan()||1<q.getRowSpan()){if(!k.$isTableCellNode(q))throw Error("Expected TableNode cell to be a TableCellNode");h=k.$createTableCellNode(q.__headerState);null!==u?u.insertAfter(h):r.$insertFirst(e,h)}}}for(let g of l)g.setColSpan(1),g.setRowSpan(1)}})},[d,m]);w.useEffect(()=>{if(!n)return d.registerNodeTransform(k.TableCellNode,a=>{null!==a.getBackgroundColor()&&a.setBackgroundColor(null)})},
|
|
12
|
+
[d,n,m]);return null}
|
package/LexicalTreeView.dev.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
var html = require('@lexical/html');
|
|
10
10
|
var link = require('@lexical/link');
|
|
11
11
|
var mark = require('@lexical/mark');
|
|
12
|
+
var table = require('@lexical/table');
|
|
12
13
|
var utils = require('@lexical/utils');
|
|
13
14
|
var lexical = require('lexical');
|
|
14
15
|
var React = require('react');
|
|
@@ -287,7 +288,7 @@ function generateContent(editor, commandsLog, exportDOM) {
|
|
|
287
288
|
typeDisplay
|
|
288
289
|
});
|
|
289
290
|
});
|
|
290
|
-
return selection === null ? ': null' : lexical.$isRangeSelection(selection) ? printRangeSelection(selection) :
|
|
291
|
+
return selection === null ? ': null' : lexical.$isRangeSelection(selection) ? printRangeSelection(selection) : table.$isGridSelection(selection) ? printGridSelection(selection) : printNodeSelection(selection);
|
|
291
292
|
});
|
|
292
293
|
res += '\n selection' + selectionString;
|
|
293
294
|
res += '\n\n commands:';
|
package/LexicalTreeView.prod.js
CHANGED
|
@@ -4,20 +4,20 @@
|
|
|
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 g=require("@lexical/html"),
|
|
8
|
-
function
|
|
9
|
-
function
|
|
10
|
-
function W(a,b,c){let l=a.getEditorState(),e=a._config,p=a._compositionKey,d=a._editable;if(c){let m="";l.read(()=>{var k=g.$generateHtmlFromNodes(a);let t=document.createElement("div");t.innerHTML=k.trim();m=X(t,0).innerHTML});return m}let h=" root\n";c=l.read(()=>{const m=
|
|
11
|
-
k.getTextContent();var u=0===n.length?"(empty)":`"${Z(n)}"`;n=[V(k),
|
|
12
|
-
h=A+`${H} ${F} ${y} ${
|
|
13
|
-
h+="\n\n editor:";h+=`\n \u2514 namespace ${e.namespace}`;null!==p&&(h+=`\n \u2514 compositionKey ${p}`);return h+=`\n \u2514 editable ${String(d)}`}function Y(a,b,c=[]){a=a.getChildren();let l=a.length;a.forEach((e,p)=>{b(e,c.concat(p===l-1?
|
|
14
|
-
let
|
|
15
|
-
function
|
|
16
|
-
function
|
|
17
|
-
d.offset]:c===
|
|
7
|
+
'use strict';var g=require("@lexical/html"),w=require("@lexical/link"),x=require("@lexical/mark"),I=require("@lexical/table"),M=require("@lexical/utils"),N=require("lexical"),O=require("react");let P=Object.freeze({"\t":"\\t","\n":"\\n"}),Q=new RegExp(Object.keys(P).join("|"),"g"),R=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
|
|
8
|
+
function U(a){let [b,c]=O.useState([]);O.useEffect(()=>{let l=new Set;for(let [e]of a._commands)l.add(a.registerCommand(e,p=>{c(d=>{d=[...d];d.push({payload:p,type:e.type?e.type:"UNKNOWN"});10<d.length&&d.shift();return d});return!1},N.COMMAND_PRIORITY_HIGH));return()=>l.forEach(e=>e())},[a]);return O.useMemo(()=>b,[b])}
|
|
9
|
+
function aa(a){let b="";var c=V(a);b+=`: range ${""!==c?`{ ${c} }`:""} ${""!==a.style?`{ style: ${a.style} } `:""}`;c=a.anchor;a=a.focus;let l=c.offset,e=a.offset;b+=`\n \u251c anchor { key: ${c.key}, offset: ${null===l?"null":l}, type: ${c.type} }`;return b+=`\n \u2514 focus { key: ${a.key}, offset: ${null===e?"null":e}, type: ${a.type} }`}function ba(a){return N.$isNodeSelection(a)?`: node\n \u2514 [${Array.from(a._nodes).join(", ")}]`:""}
|
|
10
|
+
function W(a,b,c){let l=a.getEditorState(),e=a._config,p=a._compositionKey,d=a._editable;if(c){let m="";l.read(()=>{var k=g.$generateHtmlFromNodes(a);let t=document.createElement("div");t.innerHTML=k.trim();m=X(t,0).innerHTML});return m}let h=" root\n";c=l.read(()=>{const m=N.$getSelection();Y(N.$getRoot(),(k,t)=>{const y=`(${k.getKey()})`,v=k.getType()||"",q=k.isSelected(),J=x.$isMarkNode(k)?` id: [ ${k.getIDs().join(", ")} ] `:"";var A=h,H=q?R.selectedLine:" ",F=t.join(" ");if(N.$isTextNode(k)){var n=
|
|
11
|
+
k.getTextContent();var u=0===n.length?"(empty)":`"${Z(n)}"`;n=[V(k),ca(k),da(k)].filter(Boolean).join(", ");n=[u,0!==n.length?`{ ${n} }`:null].filter(Boolean).join(" ").trim()}else if(w.$isLinkNode(k)){n=k.getURL();n=0===n.length?"(empty)":`"${Z(n)}"`;u=k.getTarget();null!=u&&(u="target: "+u);var B=Boolean;var C=k.getRel();null!=C&&(C="rel: "+C);let r=k.getTitle();null!=r&&(r="title: "+r);u=[u,C,r].filter(B).join(", ");n=[n,0!==u.length?`{ ${u} }`:null].filter(Boolean).join(" ").trim()}else n="";
|
|
12
|
+
h=A+`${H} ${F} ${y} ${v} ${J} ${n}\n`;h+=ea({indent:t,isSelected:q,node:k,nodeKeyDisplay:y,selection:m,typeDisplay:v})});return null===m?": null":N.$isRangeSelection(m)?aa(m):I.$isGridSelection(m)?`: grid\n \u2514 { grid: ${m.gridKey}, anchorCell: ${m.anchor.key}, focusCell: ${m.focus.key} }`:ba(m)});h+="\n selection"+c;h+="\n\n commands:";if(b.length)for(let {type:m,payload:k}of b)h+=`\n \u2514 { type: ${m}, payload: ${k instanceof Event?k.constructor.name:k} }`;else h+="\n \u2514 None dispatched.";
|
|
13
|
+
h+="\n\n editor:";h+=`\n \u2514 namespace ${e.namespace}`;null!==p&&(h+=`\n \u2514 compositionKey ${p}`);return h+=`\n \u2514 editable ${String(d)}`}function Y(a,b,c=[]){a=a.getChildren();let l=a.length;a.forEach((e,p)=>{b(e,c.concat(p===l-1?R.isLastChild:R.hasNextSibling));N.$isElementNode(e)&&Y(e,b,c.concat(p===l-1?R.ancestorIsLastChild:R.ancestorHasNextSibling))})}function Z(a){return Object.entries(P).reduce((b,[c,l])=>b.replace(new RegExp(c,"g"),String(l)),a)}
|
|
14
|
+
let fa=[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"],ha=[a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"],ia=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented"];
|
|
15
|
+
function ca(a){let b=ha.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="detail: "+b);return b}function da(a){let b=ia.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="mode: "+b);return b}function V(a){let b=fa.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="format: "+b);return b}
|
|
16
|
+
function ea({indent:a,isSelected:b,node:c,nodeKeyDisplay:l,selection:e,typeDisplay:p}){if(!N.$isTextNode(c)||!N.$isRangeSelection(e)||!b||N.$isElementNode(c))return"";b=e.anchor;var d=e.focus;if(""===c.getTextContent()||b.getNode()===e.focus.getNode()&&b.offset===d.offset)return"";d=e.anchor;let h=e.focus,m=c.getTextContent(),k=m.length;b=e=-1;if("text"===d.type&&"text"===h.type){let v=d.getNode(),q=h.getNode();v===q&&c===v&&d.offset!==h.offset?[e,b]=d.offset<h.offset?[d.offset,h.offset]:[h.offset,
|
|
17
|
+
d.offset]:c===v?[e,b]=v.isBefore(q)?[d.offset,k]:[0,d.offset]:c===q?[e,b]=q.isBefore(v)?[h.offset,k]:[0,h.offset]:[e,b]=[0,k]}c=(m.slice(0,e).match(Q)||[]).length;d=(m.slice(e,b).match(Q)||[]).length;let [t,y]=[e+c,b+c+d];if(t===y)return"";c=a[a.length-1]===R.hasNextSibling?R.ancestorHasNextSibling:R.ancestorIsLastChild;a=[...a.slice(0,a.length-1),c];c=Array(t+1).fill(" ");e=Array(y-t).fill(R.selectedChar);l=Array(l.length+(p.length+3)).fill(" ");return[R.selectedLine,a.join(" "),[...l,...c,...e].join("")].join(" ")+
|
|
18
18
|
"\n"}function X(a,b){let c=Array(b++ +1).join(" "),l=Array(b-1).join(" "),e;for(let p=0;p<a.children.length;p++)e=document.createTextNode("\n"+c),a.insertBefore(e,a.children[p]),X(a.children[p],b),a.lastElementChild===a.children[p]&&(e=document.createTextNode("\n"+l),a.appendChild(e));return a}
|
|
19
|
-
exports.TreeView=function({treeTypeButtonClassName:a,timeTravelButtonClassName:b,timeTravelPanelSliderClassName:c,timeTravelPanelButtonClassName:l,viewClassName:e,timeTravelPanelClassName:p,editor:d}){let [h,m]=
|
|
20
|
-
d,y,q]);
|
|
21
|
-
z()},h[G+1][0]-h[G][0])};z();return()=>{clearTimeout(f)}}},[h,n,d,E]);
|
|
22
|
-
border:"1px solid white",color:"white",cursor:"pointer",padding:5}},"Show full tree")):null,r?null:
|
|
23
|
-
onClick:()=>{A.current===E-1&&(A.current=1);u(!n)},type:"button"},n?"Pause":"Play"),
|
|
19
|
+
exports.TreeView=function({treeTypeButtonClassName:a,timeTravelButtonClassName:b,timeTravelPanelSliderClassName:c,timeTravelPanelButtonClassName:l,viewClassName:e,timeTravelPanelClassName:p,editor:d}){let [h,m]=O.useState([]),[k,t]=O.useState(""),[y,v]=O.useState(!1),[q,J]=O.useState(!1),A=O.useRef(0),H=O.useRef(null),F=O.useRef(null),[n,u]=O.useState(!1),[B,C]=O.useState(!1),[r,ja]=O.useState(!1),K=O.useRef(null),D=U(d),L=O.useCallback(f=>{const z=W(d,D,q);t(z);y||m(G=>[...G,[Date.now(),f]])},[D,
|
|
20
|
+
d,y,q]);O.useEffect(()=>{let f=d.getEditorState();!r&&1E3>f._nodeMap.size&&t(W(d,D,q))},[D,d,r,q]);O.useEffect(()=>M.mergeRegister(d.registerUpdateListener(({editorState:f})=>{if(!r&&1E3<f._nodeMap.size&&(K.current=f,C(!0),!r))return;L(f)}),d.registerEditableListener(()=>{let f=W(d,D,q);t(f)})),[D,d,q,B,L,r]);let E=h.length;O.useEffect(()=>{if(n){let f,z=()=>{const G=A.current;G===E-1?u(!1):f=setTimeout(()=>{A.current++;const S=A.current,T=F.current;null!==T&&(T.value=String(S));d.setEditorState(h[S][1]);
|
|
21
|
+
z()},h[G+1][0]-h[G][0])};z();return()=>{clearTimeout(f)}}},[h,n,d,E]);O.useEffect(()=>{let f=H.current;if(null!==f)return f.__lexicalEditor=d,()=>{f.__lexicalEditor=null}},[d]);return O.createElement("div",{className:e},!r&&B?O.createElement("div",{style:{padding:20}},O.createElement("span",{style:{marginRight:20}},"Detected large EditorState, this can impact debugging performance."),O.createElement("button",{onClick:()=>{ja(!0);let f=K.current;null!==f&&(K.current=null,L(f))},style:{background:"transparent",
|
|
22
|
+
border:"1px solid white",color:"white",cursor:"pointer",padding:5}},"Show full tree")):null,r?null:O.createElement("button",{onClick:()=>J(!q),className:a,type:"button"},q?"Tree":"Export DOM"),!y&&(r||!B)&&2<E&&O.createElement("button",{onClick:()=>{let f=d.getRootElement();null!==f&&(f.contentEditable="false",A.current=E-1,v(!0))},className:b,type:"button"},"Time Travel"),(r||!B)&&O.createElement("pre",{ref:H},k),y&&(r||!B)&&O.createElement("div",{className:p},O.createElement("button",{className:l,
|
|
23
|
+
onClick:()=>{A.current===E-1&&(A.current=1);u(!n)},type:"button"},n?"Pause":"Play"),O.createElement("input",{className:c,ref:F,onChange:f=>{f=Number(f.target.value);let z=h[f];z&&(A.current=f,d.setEditorState(z[1]))},type:"range",min:"1",max:E-1}),O.createElement("button",{className:l,onClick:()=>{var f=d.getRootElement();if(null!==f){f.contentEditable="true";f=h.length-1;d.setEditorState(h[f][1]);let z=F.current;null!==z&&(z.value=String(f));v(!1);u(!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.12.
|
|
11
|
+
"version": "0.12.6",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.12.
|
|
14
|
-
"@lexical/code": "0.12.
|
|
15
|
-
"@lexical/dragon": "0.12.
|
|
16
|
-
"@lexical/hashtag": "0.12.
|
|
17
|
-
"@lexical/history": "0.12.
|
|
18
|
-
"@lexical/link": "0.12.
|
|
19
|
-
"@lexical/list": "0.12.
|
|
20
|
-
"@lexical/mark": "0.12.
|
|
21
|
-
"@lexical/markdown": "0.12.
|
|
22
|
-
"@lexical/overflow": "0.12.
|
|
23
|
-
"@lexical/plain-text": "0.12.
|
|
24
|
-
"@lexical/rich-text": "0.12.
|
|
25
|
-
"@lexical/selection": "0.12.
|
|
26
|
-
"@lexical/table": "0.12.
|
|
27
|
-
"@lexical/text": "0.12.
|
|
28
|
-
"@lexical/utils": "0.12.
|
|
29
|
-
"@lexical/yjs": "0.12.
|
|
13
|
+
"@lexical/clipboard": "0.12.6",
|
|
14
|
+
"@lexical/code": "0.12.6",
|
|
15
|
+
"@lexical/dragon": "0.12.6",
|
|
16
|
+
"@lexical/hashtag": "0.12.6",
|
|
17
|
+
"@lexical/history": "0.12.6",
|
|
18
|
+
"@lexical/link": "0.12.6",
|
|
19
|
+
"@lexical/list": "0.12.6",
|
|
20
|
+
"@lexical/mark": "0.12.6",
|
|
21
|
+
"@lexical/markdown": "0.12.6",
|
|
22
|
+
"@lexical/overflow": "0.12.6",
|
|
23
|
+
"@lexical/plain-text": "0.12.6",
|
|
24
|
+
"@lexical/rich-text": "0.12.6",
|
|
25
|
+
"@lexical/selection": "0.12.6",
|
|
26
|
+
"@lexical/table": "0.12.6",
|
|
27
|
+
"@lexical/text": "0.12.6",
|
|
28
|
+
"@lexical/utils": "0.12.6",
|
|
29
|
+
"@lexical/yjs": "0.12.6",
|
|
30
30
|
"react-error-boundary": "^3.1.4"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"lexical": "0.12.
|
|
33
|
+
"lexical": "0.12.6",
|
|
34
34
|
"react": ">=17.x",
|
|
35
35
|
"react-dom": ">=17.x"
|
|
36
36
|
},
|