lexical 0.1.7 → 0.1.8

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 (41) hide show
  1. package/AutoLinkNode.js +9 -1
  2. package/CodeHighlightNode.js +9 -3
  3. package/CodeNode.js +9 -5
  4. package/HashtagNode.js +9 -3
  5. package/HeadingNode.js +9 -3
  6. package/Lexical.dev.js +7638 -0
  7. package/Lexical.js +9 -147
  8. package/Lexical.prod.js +153 -0
  9. package/LexicalAutoLinkNode.dev.js +58 -0
  10. package/LexicalAutoLinkNode.prod.js +7 -0
  11. package/LexicalCodeHighlightNode.dev.js +100 -0
  12. package/LexicalCodeHighlightNode.prod.js +9 -0
  13. package/LexicalCodeNode.dev.js +173 -0
  14. package/LexicalCodeNode.prod.js +11 -0
  15. package/LexicalExtendedNode.js +9 -2
  16. package/LexicalExtendedNodes.dev.js +32 -0
  17. package/LexicalExtendedNodes.prod.js +8 -0
  18. package/LexicalHashtagNode.dev.js +111 -0
  19. package/LexicalHashtagNode.prod.js +9 -0
  20. package/LexicalHeadingNode.dev.js +100 -0
  21. package/LexicalHeadingNode.prod.js +9 -0
  22. package/LexicalLinkNode.dev.js +115 -0
  23. package/LexicalLinkNode.prod.js +9 -0
  24. package/LexicalOverflowNode.dev.js +67 -0
  25. package/LexicalOverflowNode.js +9 -2
  26. package/LexicalOverflowNode.prod.js +8 -0
  27. package/LexicalQuoteNode.dev.js +86 -0
  28. package/LexicalQuoteNode.prod.js +9 -0
  29. package/LexicalTableCellNode.dev.js +81 -0
  30. package/LexicalTableCellNode.prod.js +9 -0
  31. package/LexicalTableNode.dev.js +638 -0
  32. package/LexicalTableNode.prod.js +21 -0
  33. package/LexicalTableRowNode.dev.js +76 -0
  34. package/LexicalTableRowNode.prod.js +8 -0
  35. package/LinkNode.js +9 -3
  36. package/QuoteNode.js +9 -3
  37. package/README.md +5 -6
  38. package/TableCellNode.js +9 -3
  39. package/TableNode.js +9 -15
  40. package/TableRowNode.js +9 -2
  41. package/package.json +2 -2
@@ -0,0 +1,76 @@
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 lexical = require('lexical');
10
+
11
+ /**
12
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
13
+ *
14
+ * This source code is licensed under the MIT license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ *
17
+ *
18
+ */
19
+ function addClassNamesToElement(element, ...classNames) {
20
+ classNames.forEach(className => {
21
+ if (className != null && typeof className === 'string') {
22
+ element.classList.add(...className.split(' '));
23
+ }
24
+ });
25
+ }
26
+
27
+ /**
28
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
29
+ *
30
+ * This source code is licensed under the MIT license found in the
31
+ * LICENSE file in the root directory of this source tree.
32
+ *
33
+ *
34
+ */
35
+ class TableRowNode extends lexical.ElementNode {
36
+ static getType() {
37
+ return 'table-row';
38
+ }
39
+
40
+ static clone(node) {
41
+ return new TableRowNode(node.__key);
42
+ }
43
+
44
+ constructor(key) {
45
+ super(key);
46
+ }
47
+
48
+ createDOM(config) {
49
+ const element = document.createElement('tr');
50
+ addClassNamesToElement(element, config.theme.tableRow);
51
+ return element;
52
+ }
53
+
54
+ updateDOM() {
55
+ return false;
56
+ }
57
+
58
+ canBeEmpty() {
59
+ return false;
60
+ }
61
+
62
+ canSelectionRemove() {
63
+ return false;
64
+ }
65
+
66
+ }
67
+ function $createTableRowNode() {
68
+ return new TableRowNode();
69
+ }
70
+ function $isTableRowNode(node) {
71
+ return node instanceof TableRowNode;
72
+ }
73
+
74
+ exports.$createTableRowNode = $createTableRowNode;
75
+ exports.$isTableRowNode = $isTableRowNode;
76
+ exports.TableRowNode = TableRowNode;
@@ -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 c=require("lexical");function e(a,...b){b.forEach(d=>{null!=d&&"string"===typeof d&&a.classList.add(...d.split(" "))})}class f extends c.ElementNode{static getType(){return"table-row"}static clone(a){return new f(a.__key)}constructor(a){super(a)}createDOM(a){const b=document.createElement("tr");e(b,a.theme.tableRow);return b}updateDOM(){return!1}canBeEmpty(){return!1}canSelectionRemove(){return!1}}exports.$createTableRowNode=function(){return new f};
8
+ exports.$isTableRowNode=function(a){return a instanceof f};exports.TableRowNode=f;
package/LinkNode.js CHANGED
@@ -1,3 +1,9 @@
1
- 'use strict';var d=require("lexical");function e(a,...b){b.forEach(c=>{null!=c&&"string"===typeof c&&a.classList.add(...c.split(" "))})}
2
- class f extends d.ElementNode{static getType(){return"link"}static clone(a){return new f(a.__url,a.__key)}constructor(a,b){super(b);this.__url=a}createDOM(a){const b=document.createElement("a");b.href=this.__url;e(b,a.theme.link);return b}updateDOM(a,b){const c=this.__url;c!==a.__url&&(b.href=c);return!1}getURL(){return this.getLatest().__url}setURL(a){this.getWritable().__url=a}insertNewAfter(a){a=this.getParentOrThrow().insertNewAfter(a);if(d.$isElementNode(a)){const b=g(this.__url);a.append(b);
3
- return b}return null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}}function g(a){return new f(a)}exports.$createLinkNode=g;exports.$isLinkNode=function(a){return a instanceof f};exports.LinkNode=f;
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 LexicalLinkNode = process.env.NODE_ENV === 'development' ? require('./LexicalLinkNode.dev.js') : require('./LexicalLinkNode.prod.js')
9
+ module.exports = LexicalLinkNode;
package/QuoteNode.js CHANGED
@@ -1,3 +1,9 @@
1
- 'use strict';var c=require("lexical");function d(a,...b){b.forEach(e=>{null!=e&&"string"===typeof e&&a.classList.add(...e.split(" "))})}
2
- class f extends c.ElementNode{static getType(){return"quote"}static clone(a){return new f(a.__key)}constructor(a){super(a)}createDOM(a){const b=document.createElement("blockquote");d(b,a.theme.quote);return b}updateDOM(){return!1}insertNewAfter(){const a=c.$createParagraphNode(),b=this.getDirection();a.setDirection(b);this.insertAfter(a);return a}collapseAtStart(){const a=c.$createParagraphNode();this.getChildren().forEach(b=>a.append(b));this.replace(a);return!0}}exports.$createQuoteNode=function(){return new f};
3
- exports.$isQuoteNode=function(a){return a instanceof f};exports.QuoteNode=f;
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 LexicalQuoteNode = process.env.NODE_ENV === 'development' ? require('./LexicalQuoteNode.dev.js') : require('./LexicalQuoteNode.prod.js')
9
+ module.exports = LexicalQuoteNode;
package/README.md CHANGED
@@ -4,6 +4,7 @@ Lexical is an extensible JavaScript text-editor that provides reliable, accessib
4
4
 
5
5
  The core of Lexical is a dependency-free text editor engine that allows for powerful, simple and complex,
6
6
  editor implementations to be built on top. Lexical's engine provides three main parts:
7
+
7
8
  - editor instances that each attach to a single content editable element.
8
9
  - a set of editor states that represent the current and pending states of the editor at any given time.
9
10
  - a DOM reconciler that takes a set of editor states, diffs the changes, and updates the DOM according to their state.
@@ -64,9 +65,9 @@ editor state from an editor by calling `editor.getEditorState()`.
64
65
  Editor states have two phases:
65
66
 
66
67
  - During an update they can be thought of as "mutable". See "Updating an editor" below to
67
- mutate an editor state.
68
+ mutate an editor state.
68
69
  - After an update, the editor state is then locked and deemed immutable from there one. This
69
- editor state can therefore be thought of as a "snapshot".
70
+ editor state can therefore be thought of as a "snapshot".
70
71
 
71
72
  Editor states contain two core things:
72
73
 
@@ -77,9 +78,7 @@ Editor states are serializable to JSON, and the editor instance provides a usefu
77
78
  to deserialize stringified editor states.
78
79
 
79
80
  ```js
80
- const stringifiedEditorState = JSON.stringify(
81
- editor.getEditorState().toJSON(),
82
- );
81
+ const stringifiedEditorState = JSON.stringify(editor.getEditorState().toJSON());
83
82
 
84
83
  const newEditorState = editor.parseEditorState(stringifiedEditorState);
85
84
  ```
@@ -150,4 +149,4 @@ editor.addListener('update', ({editorState}) => {
150
149
  // the $ prefixed helper functions.
151
150
  });
152
151
  });
153
- ```
152
+ ```
package/TableCellNode.js CHANGED
@@ -1,3 +1,9 @@
1
- 'use strict';var c=require("lexical");function e(a,...b){b.forEach(d=>{null!=d&&"string"===typeof d&&a.classList.add(...d.split(" "))})}
2
- class f extends c.ElementNode{static getType(){return"table-cell"}static clone(a){return new f(!1,a.__key)}constructor(a=!1,b){super(b);this.__isHeader=a}getTag(){return this.__isHeader?"th":"td"}createDOM(a){const b=document.createElement(this.getTag());e(b,a.theme.tableCell,!0===this.__isHeader&&a.theme.tableCellHeader);return b}updateDOM(){return!1}collapseAtStart(){return!0}canSelectionRemove(){return!1}}exports.$createTableCellNode=function(a){return new f(a)};
3
- exports.$isTableCellNode=function(a){return a instanceof f};exports.TableCellNode=f;
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 LexicalTableCellNode = process.env.NODE_ENV === 'development' ? require('./LexicalTableCellNode.dev.js') : require('./LexicalTableCellNode.prod.js')
9
+ module.exports = LexicalTableCellNode;
package/TableNode.js CHANGED
@@ -1,15 +1,9 @@
1
- 'use strict';var n=require("lexical"),y=require("lexical/TableCellNode");function A(a,...g){g.forEach(d=>{null!=d&&"string"===typeof d&&a.classList.add(...d.split(" "))})}function B(a,g){for(;a!==n.$getRoot()&&null!=a;){if(g(a))return a;a=a.getParent()}return null}const C=document.createElement("style");C.appendChild(document.createTextNode("::selection{background-color: transparent}"));
2
- function D(a){for(;null!=a;){const g=a.nodeName;if("TD"===g||"TH"===g){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
3
- function E(a,g,d){const k=[],l={rows:0,columns:0,cells:k};(new MutationObserver(t=>{d.update(()=>{var h=g.firstChild;let u=0,p=0;var e=!1;for(let q=0;q<t.length;q++){const w=t[q].target.nodeName;if("TABLE"===w||"TR"===w){e=!0;break}}if(e){for(k.length=0;null!=h;){e=h.nodeName;if("TD"===e||"TH"===e)e={elem:h,highlighted:!1,x:u,y:p},h._cell=e,void 0===k[p]&&(k[p]=[]),k[p][u]=e;else if(e=h.firstChild,null!=e){h=e;continue}e=h.nextSibling;if(null!=e)u++,h=e;else if(e=h.parentNode,null!=e){h=e.nextSibling;
4
- if(null==h)break;p++;u=0}}l.columns=u+1;l.rows=p+1;a.setGrid(l)}})})).observe(g,{childList:!0,subtree:!0});a.setGrid(l);return l}
5
- function F(a,g,d,k,l){const t=[];for(let h=0;h<l.length;h++){const u=l[h];for(let p=0;p<u.length;p++){const e=u[p],q=e.elem.style;p>=a&&p<=g&&h>=d&&h<=k?(e.highlighted||(e.highlighted=!0,q.setProperty("background-color","rgb(163, 187, 255)"),q.setProperty("caret-color","transparent")),t.push(e)):e.highlighted&&(e.highlighted=!1,q.removeProperty("background-color"),q.removeProperty("caret-color"))}}return t}
6
- function H(a,g,d){if(null!==d.getRootElement()){E(a,g,d);var k=a.getGrid(),l=!1,t=!1,h=-1,u=-1,p=-1,e=-1,q=[];if(null==k)throw Error("Table grid not found.");g.addEventListener("mousemove",c=>{if(l){var b=D(c.target);if(null!==b){const f=b.x;b=b.y;if(!t&&(h!==f||u!==b))c.preventDefault(),c=window.getSelection(),c.setBaseAndExtent(c.anchorNode,0,c.anchorNode,0),t=!0,document.body&&document.body.appendChild(C),null===x&&(x=d.addListener("command",(m,v)=>{if("deleteCharacter"===m){if(q.length===k.columns*
7
- k.rows)return a.selectPrevious(),a.remove(),w(),!0;q.forEach(({elem:r})=>{r=n.$getNearestNodeFromDOMNode(r);if(n.$isElementNode(r)){r.clear();const z=n.$createParagraphNode(),J=n.$createTextNode();z.append(J);r.append(z)}});a.setSelectionState(null);n.$setSelection(null);return!0}if("formatText"===m)return K(v),!0;"insertText"===m&&w();return!1},1));else if(f===p&&b===e)return;p=f;e=b;if(t){const m=Math.min(h,p),v=Math.max(h,p),r=Math.min(u,e),z=Math.max(u,e);d.update(()=>{q=a.setSelectionState({fromX:m,
8
- toX:v,fromY:r,toY:z})})}}}});var w=()=>{d.update(()=>{l=t=!1;e=p=u=h=-1;d.update(()=>{a.setSelectionState(null)});q=[];null!==x&&(x(),x=null);const c=C.parentNode;null!=c&&c.removeChild(C)})};g.addEventListener("mouseleave",()=>{});var K=c=>{let b=n.$getSelection();null===b&&(b=n.$createRangeSelection());const f=b,m=f.anchor,v=f.focus;q.forEach(r=>{r=n.$getNearestNodeFromDOMNode(r.elem);n.$isElementNode(r)&&(m.set(r.getKey(),0,"element"),v.set(r.getKey(),r.getChildrenSize(),"element"),f.formatText(c))});
9
- b.anchor.set(b.anchor.key,b.anchor.offset,b.anchor.type);b.focus.set(b.anchor.key,b.anchor.offset,b.anchor.type);n.$setSelection(b)},x=null;g.addEventListener("mousedown",c=>{l?t&&w():setTimeout(()=>{t&&w();const b=D(c.target);null!==b&&(l=!0,h=b.x,u=b.y,document.addEventListener("mouseup",()=>{l=!1},{capture:!0,once:!0}))},0)});window.addEventListener("click",c=>{0<q.length&&!g.contains(c.target)&&d.update(()=>{a.setSelectionState(null)})});var G=(c,b,f)=>{let m;switch(f){case "backward":case "forward":f=
10
- "forward"===f;m=b!==(f?k.columns-1:0)?a.getCellNodeFromCords(c,b+(f?1:-1)):c!==(f?k.rows-1:0)?a.getCellNodeFromCords(c+(f?1:-1),f?0:k.columns-1):f?a.getNextSibling():a.getPreviousSibling();break;case "up":m=0!==c?a.getCellNodeFromCords(c-1,b):a.getPreviousSibling();break;case "down":m=c!==k.rows-1?a.getCellNodeFromCords(c+1,b):a.getNextSibling()}return n.$isElementNode(m)||n.$isTextNode(m)?(m.select(),!0):!1};d.addListener("command",(c,b)=>{var f=n.$getSelection();if(null==f)return!1;const m=B(f.anchor.getNode(),
11
- v=>y.$isTableCellNode(v));if(!y.$isTableCellNode(m))return!1;if("deleteCharacter"===c&&0===q.length&&f.isCollapsed()&&0===f.anchor.offset)return!0;if(("indentContent"===c||"outdentContent"===c)&&f.isCollapsed()&&0===q.length)return b=a.getCordsFromCellNode(m),G(b.x,b.y,"indentContent"===c?"forward":"backward"),!0;if(("keyArrowDown"===c||"keyArrowUp"===c)&&f.isCollapsed()&&0===q.length){const v=a.getCordsFromCellNode(m);f=B(f.anchor.getNode(),r=>n.$isElementNode(r));if("keyArrowUp"===c&&f===m.getFirstChild()||
12
- "keyArrowDown"===c&&f===m.getLastChild())return b.preventDefault(),b.stopImmediatePropagation(),G(v.x,v.y,"keyArrowUp"===c?"up":"down"),!0}return!1},4)}}
13
- class I extends n.ElementNode{static getType(){return"table"}static clone(a){return new I(a.__key,a.__selectionShape,a.__grid)}constructor(a,g,d){super(a);this.__selectionShape=g;this.__grid=d}createDOM(a,g){const d=document.createElement("table");A(d,a.theme.table);H(this,d,g);return d}updateDOM(){return!1}canExtractContents(){return!1}canBeEmpty(){return!1}setSelectionState(a){this.getWritable().__selectionShape=a;return null==this.__grid?[]:a?F(a.fromX,a.toX,a.fromY,a.toY,this.__grid.cells):F(-1,
14
- -1,-1,-1,this.__grid.cells)}getSelectionState(){return this.__selectionShape}getCordsFromCellNode(a){if(!this.__grid)throw Error("Grid not found.");const {rows:g,cells:d}=this.__grid;for(let l=0;l<g;l++){var k=d[l];if(null==k)throw Error(`Row not found at x:${l}`);k=k.findIndex(({elem:t})=>n.$getNearestNodeFromDOMNode(t)===a);if(-1!==k)return{x:l,y:k}}throw Error("Cell not found in table.");}getCellNodeFromCords(a,g){if(!this.__grid)throw Error("Grid not found.");var {cells:d}=this.__grid;d=d[a];
15
- if(null==d)throw Error(`Table row x:"${a}" not found.`);d=d[g];if(null==d)throw Error(`Table cell y:"${g}" in row x:"${a}" not found.`);a=n.$getNearestNodeFromDOMNode(d.elem);if(y.$isTableCellNode(a))return a;throw Error("Node at cords not TableCellNode.");}setGrid(a){this.getWritable().__grid=a}getGrid(){return this.__grid}}exports.$createTableNode=function(){return new I};exports.$isTableNode=function(a){return a instanceof I};exports.TableNode=I;exports.trackTableGrid=E;
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 LexicalTableNode = process.env.NODE_ENV === 'development' ? require('./LexicalTableNode.dev.js') : require('./LexicalTableNode.prod.js')
9
+ module.exports = LexicalTableNode;
package/TableRowNode.js CHANGED
@@ -1,2 +1,9 @@
1
- 'use strict';var c=require("lexical");function e(a,...b){b.forEach(d=>{null!=d&&"string"===typeof d&&a.classList.add(...d.split(" "))})}class f extends c.ElementNode{static getType(){return"table-row"}static clone(a){return new f(a.__key)}constructor(a){super(a)}createDOM(a){const b=document.createElement("tr");e(b,a.theme.tableRow);return b}updateDOM(){return!1}canBeEmpty(){return!1}canSelectionRemove(){return!1}}exports.$createTableRowNode=function(){return new f};
2
- exports.$isTableRowNode=function(a){return a instanceof f};exports.TableRowNode=f;
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 LexicalTableRowNode = process.env.NODE_ENV === 'development' ? require('./LexicalTableRowNode.dev.js') : require('./LexicalTableRowNode.prod.js')
9
+ module.exports = LexicalTableRowNode;
package/package.json CHANGED
@@ -13,11 +13,11 @@
13
13
  "rich-text"
14
14
  ],
15
15
  "license": "MIT",
16
- "version": "0.1.7",
16
+ "version": "0.1.8",
17
17
  "main": "Lexical.js",
18
18
  "repository": {
19
19
  "type": "git",
20
20
  "url": "https://github.com/facebook/lexical",
21
21
  "directory": "packages/lexical"
22
22
  }
23
- }
23
+ }