@react-fabric/lexical 1.0.0-beta.57 → 1.0.0-beta.58

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.
Files changed (48) hide show
  1. package/css/_lexical.css +4 -0
  2. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +33 -1
  3. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +11 -11
  4. package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +525 -194
  5. package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +26 -23
  6. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +3 -3
  7. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  8. package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +95 -38
  9. package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +11 -10
  10. package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +387 -124
  11. package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +22 -18
  12. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +54 -29
  13. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
  14. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +107 -8
  15. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +4 -0
  16. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +23 -20
  17. package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +420 -137
  18. package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +50 -45
  19. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +61 -65
  20. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +2 -0
  21. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +47 -46
  22. package/dist/cjs/packages/lexical/src/hooks/useFormatWatcher.js +3 -1
  23. package/dist/cjs/packages/lexical/src/plugins/ToolbarPlugin.js +20 -10
  24. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +34 -2
  25. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
  26. package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +524 -196
  27. package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +3 -3
  28. package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +4 -4
  29. package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  30. package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +96 -40
  31. package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +3 -3
  32. package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +387 -127
  33. package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +5 -4
  34. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +56 -31
  35. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +4 -4
  36. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +106 -10
  37. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +3 -1
  38. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +3 -3
  39. package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +417 -139
  40. package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +3 -3
  41. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +62 -67
  42. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +2 -1
  43. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
  44. package/dist/esm/packages/lexical/src/hooks/useFormatWatcher.js +3 -1
  45. package/dist/esm/packages/lexical/src/plugins/ToolbarPlugin.js +20 -10
  46. package/package.json +12 -12
  47. package/src/hooks/useFormatWatcher.ts +3 -1
  48. package/src/plugins/ToolbarPlugin.tsx +5 -10
package/css/_lexical.css CHANGED
@@ -28,6 +28,10 @@
28
28
  .fabric-lexicalToolbar {
29
29
  width: 21cm;
30
30
  margin: 0 auto;
31
+
32
+ .fabric-inputWrapper {
33
+ outline: none;
34
+ }
31
35
  }
32
36
 
33
37
  .fabric-lexicalEditor {
@@ -184,9 +184,41 @@ function $insertGeneratedNodes(editor, nodes, selection) {
184
184
  selection
185
185
  })) {
186
186
  selection.insertNodes(nodes);
187
+ $updateSelectionOnInsert(selection);
187
188
  }
188
189
  return;
189
190
  }
191
+ function $updateSelectionOnInsert(selection) {
192
+ if (lexical.$isRangeSelection(selection) && selection.isCollapsed()) {
193
+ const anchor = selection.anchor;
194
+ let nodeToInspect = null;
195
+ const anchorCaret = lexical.$caretFromPoint(anchor, 'previous');
196
+ if (anchorCaret) {
197
+ if (lexical.$isTextPointCaret(anchorCaret)) {
198
+ nodeToInspect = anchorCaret.origin;
199
+ } else {
200
+ const range = lexical.$getCaretRange(anchorCaret, lexical.$getChildCaret(lexical.$getRoot(), 'next').getFlipped());
201
+ for (const caret of range) {
202
+ if (lexical.$isTextNode(caret.origin)) {
203
+ nodeToInspect = caret.origin;
204
+ break;
205
+ } else if (lexical.$isElementNode(caret.origin) && !caret.origin.isInline()) {
206
+ break;
207
+ }
208
+ }
209
+ }
210
+ }
211
+ if (nodeToInspect && lexical.$isTextNode(nodeToInspect)) {
212
+ const newFormat = nodeToInspect.getFormat();
213
+ const newStyle = nodeToInspect.getStyle();
214
+ if (selection.format !== newFormat || selection.style !== newStyle) {
215
+ selection.format = newFormat;
216
+ selection.style = newStyle;
217
+ selection.dirty = true;
218
+ }
219
+ }
220
+ }
221
+ }
190
222
  function exportNodeToJSON(node) {
191
223
  const serializedNode = node.exportJSON();
192
224
  const nodeClass = node.constructor;
@@ -275,7 +307,7 @@ function $generateJSONFromSelectedNodes(editor, selection) {
275
307
  }
276
308
 
277
309
  /**
278
- * This method takes an array of objects conforming to the BaseSeralizedNode interface and returns
310
+ * This method takes an array of objects conforming to the BaseSerializedNode interface and returns
279
311
  * an Array containing instances of the corresponding LexicalNode classes registered on the editor.
280
312
  * Normally, you'd get an Array of BaseSerialized nodes from {@link $generateJSONFromSelectedNodes}
281
313
  *
@@ -13,15 +13,15 @@ var lexical = require('lexical');
13
13
  *
14
14
  */
15
15
 
16
- function y(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function T(e,n=lexical.$getSelection()){return null==n&&y(166),lexical.$isRangeSelection(n)&&n.isCollapsed()||0===n.getNodes().length?"":LexicalHtml.$generateHtmlFromNodes(e,n)}function v(t,e=lexical.$getSelection()){return null==e&&y(166),lexical.$isRangeSelection(e)&&e.isCollapsed()||0===e.getNodes().length?null:JSON.stringify(R(t,e))}function C(t,e){const n=t.getData("text/plain")||t.getData("text/uri-list");null!=n&&e.insertRawText(n);}function D(t,n,o){const r=t.getData("application/x-lexical-editor");if(r)try{const t=JSON.parse(r);if(t.namespace===o._config.namespace&&Array.isArray(t.nodes)){return N(o,A(t.nodes),n)}}catch(t){}const c=t.getData("text/html"),a=t.getData("text/plain");if(c&&a!==c)try{const t=(new DOMParser).parseFromString(function(t){if(window.trustedTypes&&window.trustedTypes.createPolicy){return window.trustedTypes.createPolicy("lexical",{createHTML:t=>t}).createHTML(t)}return t}(c),"text/html");return N(o,LexicalHtml.$generateNodesFromDOM(o,t),n)}catch(t){}const u=a||t.getData("text/uri-list");if(null!=u)if(lexical.$isRangeSelection(n)){const t=u.split(/(\r?\n|\t)/);""===t[t.length-1]&&t.pop();for(let e=0;e<t.length;e++){const n=lexical.$getSelection();if(lexical.$isRangeSelection(n)){const o=t[e];"\n"===o||"\r\n"===o?n.insertParagraph():"\t"===o?n.insertNodes([lexical.$createTabNode()]):n.insertText(o);}}}else n.insertRawText(u);}function N(t,e,n){t.dispatchCommand(lexical.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,{nodes:e,selection:n})||n.insertNodes(e);}function S(t,e,n,r=[]){let i=null===e||n.isSelected(e);const l=lexical.$isElementNode(n)&&n.excludeFromCopy("html");let s=n;if(null!==e){let t=lexical.$cloneWithProperties(n);t=lexical.$isTextNode(t)&&null!==e?LexicalSelection.$sliceSelectedTextNodeContent(e,t):t,s=t;}const c=lexical.$isElementNode(s)?s.getChildren():[],a=function(t){const e=t.exportJSON(),n=t.constructor;if(e.type!==n.getType()&&y(58,n.name),lexical.$isElementNode(t)){const t=e.children;Array.isArray(t)||y(59,n.name);}return e}(s);if(lexical.$isTextNode(s)){const t=s.__text;t.length>0?a.text=t:i=!1;}for(let o=0;o<c.length;o++){const r=c[o],l=S(t,e,r,a.children);!i&&lexical.$isElementNode(n)&&l&&n.extractWithChild(r,e,"clone")&&(i=!0);}if(i&&!l)r.push(a);else if(Array.isArray(a.children))for(let t=0;t<a.children.length;t++){const e=a.children[t];r.push(e);}return i}function R(t,e){const n=[],o=lexical.$getRoot().getChildren();for(let r=0;r<o.length;r++){S(t,e,o[r],n);}return {namespace:t._config.namespace,nodes:n}}function A(t){const e=[];for(let o=0;o<t.length;o++){const r=t[o],i=lexical.$parseSerializedNode(r);lexical.$isTextNode(i)&&LexicalSelection.$addNodeStyle(i),e.push(i);}return e}let P=null;async function _(t,e,n){if(null!==P)return !1;if(null!==e)return new Promise(((o,r)=>{t.update((()=>{o(E(t,e,n));}));}));const o=t.getRootElement(),i=t._window||window,l=window.document,s=lexical.getDOMSelection(i);if(null===o||null===s)return !1;const c=l.createElement("span");c.style.cssText="position: fixed; top: -1000px;",c.append(l.createTextNode("#")),o.append(c);const a=new Range;return a.setStart(c,0),a.setEnd(c,1),s.removeAllRanges(),s.addRange(a),new Promise(((e,o)=>{const i=t.registerCommand(lexical.COPY_COMMAND,(o=>(LexicalUtils.objectKlassEquals(o,ClipboardEvent)&&(i(),null!==P&&(window.clearTimeout(P),P=null),e(E(t,o,n))),!0)),lexical.COMMAND_PRIORITY_CRITICAL);P=window.setTimeout((()=>{i(),P=null,e(!1);}),50),l.execCommand("copy"),c.remove();}))}function E(t,e,n){if(void 0===n){const e=lexical.getDOMSelection(t._window);if(!e)return !1;const o=e.anchorNode,r=e.focusNode;if(null!==o&&null!==r&&!lexical.isSelectionWithinEditor(t,o,r))return !1;const i=lexical.$getSelection();if(null===i)return !1;n=M(i);}e.preventDefault();const o=e.clipboardData;return null!==o&&(O(o,n),!0)}const L=[["text/html",T],["application/x-lexical-editor",v]];function M(t=lexical.$getSelection()){const e={"text/plain":t?t.getTextContent():""};if(t){const n=lexical.$getEditor();for(const[o,r]of L){const i=r(n,t);null!==i&&(e[o]=i);}}return e}function O(t,e){for(const n in e){const o=e[n];void 0!==o&&t.setData(n,o);}}
16
+ function D(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function N(e,n=lexical.$getSelection()){return null==n&&D(166),lexical.$isRangeSelection(n)&&n.isCollapsed()||0===n.getNodes().length?"":LexicalHtml.$generateHtmlFromNodes(e,n)}function S(t,e=lexical.$getSelection()){return null==e&&D(166),lexical.$isRangeSelection(e)&&e.isCollapsed()||0===e.getNodes().length?null:JSON.stringify(E(t,e))}function R(t,e){const n=t.getData("text/plain")||t.getData("text/uri-list");null!=n&&e.insertRawText(n);}function A(t,n,o){const r=t.getData("application/x-lexical-editor");if(r)try{const t=JSON.parse(r);if(t.namespace===o._config.namespace&&Array.isArray(t.nodes)){return P(o,L(t.nodes),n)}}catch(t){}const c=t.getData("text/html"),a=t.getData("text/plain");if(c&&a!==c)try{const t=(new DOMParser).parseFromString(function(t){if(window.trustedTypes&&window.trustedTypes.createPolicy){return window.trustedTypes.createPolicy("lexical",{createHTML:t=>t}).createHTML(t)}return t}(c),"text/html");return P(o,LexicalHtml.$generateNodesFromDOM(o,t),n)}catch(t){}const u=a||t.getData("text/uri-list");if(null!=u)if(lexical.$isRangeSelection(n)){const t=u.split(/(\r?\n|\t)/);""===t[t.length-1]&&t.pop();for(let e=0;e<t.length;e++){const n=lexical.$getSelection();if(lexical.$isRangeSelection(n)){const o=t[e];"\n"===o||"\r\n"===o?n.insertParagraph():"\t"===o?n.insertNodes([lexical.$createTabNode()]):n.insertText(o);}}}else n.insertRawText(u);}function P(t,e,n){t.dispatchCommand(lexical.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,{nodes:e,selection:n})||(n.insertNodes(e),function(t){if(lexical.$isRangeSelection(t)&&t.isCollapsed()){const e=t.anchor;let n=null;const o=lexical.$caretFromPoint(e,"previous");if(o)if(lexical.$isTextPointCaret(o))n=o.origin;else {const t=lexical.$getCaretRange(o,lexical.$getChildCaret(lexical.$getRoot(),"next").getFlipped());for(const e of t){if(lexical.$isTextNode(e.origin)){n=e.origin;break}if(lexical.$isElementNode(e.origin)&&!e.origin.isInline())break}}if(n&&lexical.$isTextNode(n)){const e=n.getFormat(),o=n.getStyle();t.format===e&&t.style===o||(t.format=e,t.style=o,t.dirty=!0);}}}(n));}function _(t,e,n,r=[]){let i=null===e||n.isSelected(e);const l=lexical.$isElementNode(n)&&n.excludeFromCopy("html");let s=n;if(null!==e){let t=lexical.$cloneWithProperties(n);t=lexical.$isTextNode(t)&&null!==e?LexicalSelection.$sliceSelectedTextNodeContent(e,t):t,s=t;}const c=lexical.$isElementNode(s)?s.getChildren():[],a=function(t){const e=t.exportJSON(),n=t.constructor;if(e.type!==n.getType()&&D(58,n.name),lexical.$isElementNode(t)){const t=e.children;Array.isArray(t)||D(59,n.name);}return e}(s);if(lexical.$isTextNode(s)){const t=s.__text;t.length>0?a.text=t:i=!1;}for(let o=0;o<c.length;o++){const r=c[o],l=_(t,e,r,a.children);!i&&lexical.$isElementNode(n)&&l&&n.extractWithChild(r,e,"clone")&&(i=!0);}if(i&&!l)r.push(a);else if(Array.isArray(a.children))for(let t=0;t<a.children.length;t++){const e=a.children[t];r.push(e);}return i}function E(t,e){const n=[],o=lexical.$getRoot().getChildren();for(let r=0;r<o.length;r++){_(t,e,o[r],n);}return {namespace:t._config.namespace,nodes:n}}function L(t){const e=[];for(let o=0;o<t.length;o++){const r=t[o],i=lexical.$parseSerializedNode(r);lexical.$isTextNode(i)&&LexicalSelection.$addNodeStyle(i),e.push(i);}return e}let b=null;async function F(t,e,n){if(null!==b)return !1;if(null!==e)return new Promise(((o,r)=>{t.update((()=>{o(M(t,e,n));}));}));const o=t.getRootElement(),i=t._window||window,l=window.document,s=lexical.getDOMSelection(i);if(null===o||null===s)return !1;const c=l.createElement("span");c.style.cssText="position: fixed; top: -1000px;",c.append(l.createTextNode("#")),o.append(c);const a=new Range;return a.setStart(c,0),a.setEnd(c,1),s.removeAllRanges(),s.addRange(a),new Promise(((e,o)=>{const i=t.registerCommand(lexical.COPY_COMMAND,(o=>(LexicalUtils.objectKlassEquals(o,ClipboardEvent)&&(i(),null!==b&&(window.clearTimeout(b),b=null),e(M(t,o,n))),!0)),lexical.COMMAND_PRIORITY_CRITICAL);b=window.setTimeout((()=>{i(),b=null,e(!1);}),50),l.execCommand("copy"),c.remove();}))}function M(t,e,n){if(void 0===n){const e=lexical.getDOMSelection(t._window);if(!e)return !1;const o=e.anchorNode,r=e.focusNode;if(null!==o&&null!==r&&!lexical.isSelectionWithinEditor(t,o,r))return !1;const i=lexical.$getSelection();if(null===i)return !1;n=J(i);}e.preventDefault();const o=e.clipboardData;return null!==o&&(k(o,n),!0)}const O=[["text/html",N],["application/x-lexical-editor",S]];function J(t=lexical.$getSelection()){const e={"text/plain":t?t.getTextContent():""};if(t){const n=lexical.$getEditor();for(const[o,r]of O){const i=r(n,t);null!==i&&(e[o]=i);}}return e}function k(t,e){for(const n in e){const o=e[n];void 0!==o&&t.setData(n,o);}}
17
17
 
18
- exports.$generateJSONFromSelectedNodes = R;
19
- exports.$generateNodesFromSerializedNodes = A;
20
- exports.$getClipboardDataFromSelection = M;
21
- exports.$getHtmlContent = T;
22
- exports.$getLexicalContent = v;
23
- exports.$insertDataTransferForPlainText = C;
24
- exports.$insertDataTransferForRichText = D;
25
- exports.$insertGeneratedNodes = N;
26
- exports.copyToClipboard = _;
27
- exports.setLexicalClipboardDataTransfer = O;
18
+ exports.$generateJSONFromSelectedNodes = E;
19
+ exports.$generateNodesFromSerializedNodes = L;
20
+ exports.$getClipboardDataFromSelection = J;
21
+ exports.$getHtmlContent = N;
22
+ exports.$getLexicalContent = S;
23
+ exports.$insertDataTransferForPlainText = R;
24
+ exports.$insertDataTransferForRichText = A;
25
+ exports.$insertGeneratedNodes = P;
26
+ exports.copyToClipboard = F;
27
+ exports.setLexicalClipboardDataTransfer = k;