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.
- package/AutoLinkNode.js +9 -1
- package/CodeHighlightNode.js +9 -3
- package/CodeNode.js +9 -5
- package/HashtagNode.js +9 -3
- package/HeadingNode.js +9 -3
- package/Lexical.dev.js +7638 -0
- package/Lexical.js +9 -147
- package/Lexical.prod.js +153 -0
- package/LexicalAutoLinkNode.dev.js +58 -0
- package/LexicalAutoLinkNode.prod.js +7 -0
- package/LexicalCodeHighlightNode.dev.js +100 -0
- package/LexicalCodeHighlightNode.prod.js +9 -0
- package/LexicalCodeNode.dev.js +173 -0
- package/LexicalCodeNode.prod.js +11 -0
- package/LexicalExtendedNode.js +9 -2
- package/LexicalExtendedNodes.dev.js +32 -0
- package/LexicalExtendedNodes.prod.js +8 -0
- package/LexicalHashtagNode.dev.js +111 -0
- package/LexicalHashtagNode.prod.js +9 -0
- package/LexicalHeadingNode.dev.js +100 -0
- package/LexicalHeadingNode.prod.js +9 -0
- package/LexicalLinkNode.dev.js +115 -0
- package/LexicalLinkNode.prod.js +9 -0
- package/LexicalOverflowNode.dev.js +67 -0
- package/LexicalOverflowNode.js +9 -2
- package/LexicalOverflowNode.prod.js +8 -0
- package/LexicalQuoteNode.dev.js +86 -0
- package/LexicalQuoteNode.prod.js +9 -0
- package/LexicalTableCellNode.dev.js +81 -0
- package/LexicalTableCellNode.prod.js +9 -0
- package/LexicalTableNode.dev.js +638 -0
- package/LexicalTableNode.prod.js +21 -0
- package/LexicalTableRowNode.dev.js +76 -0
- package/LexicalTableRowNode.prod.js +8 -0
- package/LinkNode.js +9 -3
- package/QuoteNode.js +9 -3
- package/README.md +5 -6
- package/TableCellNode.js +9 -3
- package/TableNode.js +9 -15
- package/TableRowNode.js +9 -2
- 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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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.
|
|
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
|
+
}
|