@lexical/react 0.2.3 → 0.2.4
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/LexicalBlockWithAlignableContents.dev.js +102 -0
- package/LexicalBlockWithAlignableContents.js +9 -0
- package/LexicalBlockWithAlignableContents.js.flow +24 -0
- package/LexicalBlockWithAlignableContents.prod.js +10 -0
- package/LexicalDecoratorBlockNode.dev.js +43 -0
- package/LexicalDecoratorBlockNode.js +9 -0
- package/LexicalDecoratorBlockNode.js.flow +23 -0
- package/LexicalDecoratorBlockNode.prod.js +7 -0
- package/LexicalHorizontalRuleNode.d.ts +1 -1
- package/package.json +18 -18
|
@@ -0,0 +1,102 @@
|
|
|
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 LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
|
+
var LexicalDecoratorBlockNode = require('@lexical/react/LexicalDecoratorBlockNode');
|
|
11
|
+
var useLexicalNodeSelection = require('@lexical/react/useLexicalNodeSelection');
|
|
12
|
+
var utils = require('@lexical/utils');
|
|
13
|
+
var lexical = require('lexical');
|
|
14
|
+
var React = require('react');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the MIT license found in the
|
|
20
|
+
* LICENSE file in the root directory of this source tree.
|
|
21
|
+
*
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
function BlockWithAlignableContents({
|
|
25
|
+
children,
|
|
26
|
+
format,
|
|
27
|
+
nodeKey
|
|
28
|
+
}) {
|
|
29
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
30
|
+
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
|
|
31
|
+
const ref = React.useRef();
|
|
32
|
+
const onDelete = React.useCallback(payload => {
|
|
33
|
+
if (isSelected && lexical.$isNodeSelection(lexical.$getSelection())) {
|
|
34
|
+
const event = payload;
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
editor.update(() => {
|
|
37
|
+
const node = lexical.$getNodeByKey(nodeKey);
|
|
38
|
+
|
|
39
|
+
if (lexical.$isDecoratorNode(node) && node.isTopLevel()) {
|
|
40
|
+
node.remove();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setSelected(false);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return false;
|
|
48
|
+
}, [editor, isSelected, nodeKey, setSelected]);
|
|
49
|
+
React.useEffect(() => {
|
|
50
|
+
return utils.mergeRegister(editor.registerCommand(lexical.FORMAT_ELEMENT_COMMAND, payload => {
|
|
51
|
+
if (isSelected) {
|
|
52
|
+
const selection = lexical.$getSelection();
|
|
53
|
+
|
|
54
|
+
if (lexical.$isNodeSelection(selection)) {
|
|
55
|
+
const node = lexical.$getNodeByKey(nodeKey);
|
|
56
|
+
|
|
57
|
+
if (LexicalDecoratorBlockNode.$isDecoratorBlockNode(node)) {
|
|
58
|
+
node.setFormat(payload);
|
|
59
|
+
}
|
|
60
|
+
} else if (lexical.$isRangeSelection(selection)) {
|
|
61
|
+
const nodes = selection.getNodes();
|
|
62
|
+
|
|
63
|
+
for (const node of nodes) {
|
|
64
|
+
if (LexicalDecoratorBlockNode.$isDecoratorBlockNode(node)) {
|
|
65
|
+
node.setFormat(payload);
|
|
66
|
+
} else {
|
|
67
|
+
const element = utils.$getNearestBlockElementAncestorOrThrow(node);
|
|
68
|
+
element.setFormat(payload);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return false;
|
|
77
|
+
}, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.CLICK_COMMAND, payload => {
|
|
78
|
+
const event = payload;
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
|
|
81
|
+
if (event.target === ref.current) {
|
|
82
|
+
if (!event.shiftKey) {
|
|
83
|
+
clearSelection();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
setSelected(!isSelected);
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return false;
|
|
91
|
+
}, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_DELETE_COMMAND, onDelete, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, onDelete, lexical.COMMAND_PRIORITY_LOW));
|
|
92
|
+
}, [clearSelection, editor, isSelected, nodeKey, onDelete, setSelected]);
|
|
93
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
94
|
+
className: `embed-block${isSelected ? ' focused' : ''}`,
|
|
95
|
+
ref: ref,
|
|
96
|
+
style: {
|
|
97
|
+
textAlign: format
|
|
98
|
+
}
|
|
99
|
+
}, children);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
exports.BlockWithAlignableContents = BlockWithAlignableContents;
|
|
@@ -0,0 +1,9 @@
|
|
|
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 LexicalBlockWithAlignableContents = process.env.NODE_ENV === 'development' ? require('./LexicalBlockWithAlignableContents.dev.js') : require('./LexicalBlockWithAlignableContents.prod.js')
|
|
9
|
+
module.exports = LexicalBlockWithAlignableContents;
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
ElementFormatType,
|
|
12
|
+
LexicalEditor,
|
|
13
|
+
EditorThemeClasses,
|
|
14
|
+
LexicalNode,
|
|
15
|
+
NodeKey,
|
|
16
|
+
} from 'lexical';
|
|
17
|
+
|
|
18
|
+
type Props = $ReadOnly<{
|
|
19
|
+
children: React$Node,
|
|
20
|
+
format: ?ElementFormatType,
|
|
21
|
+
nodeKey: NodeKey,
|
|
22
|
+
}>;
|
|
23
|
+
|
|
24
|
+
declare export function BlockWithAlignableContents(Props): React$Node;
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
var a=require("@lexical/react/LexicalComposerContext"),h=require("@lexical/react/LexicalDecoratorBlockNode"),m=require("@lexical/react/useLexicalNodeSelection"),n=require("@lexical/utils"),r=require("lexical"),t=require("react");
|
|
8
|
+
exports.BlockWithAlignableContents=function({children:u,format:v,nodeKey:g}){const [d]=a.useLexicalComposerContext(),[e,k,p]=m(g),q=t.useRef(),l=t.useCallback(b=>{e&&r.$isNodeSelection(r.$getSelection())&&(b.preventDefault(),d.update(()=>{const c=r.$getNodeByKey(g);r.$isDecoratorNode(c)&&c.isTopLevel()&&c.remove();k(!1)}));return!1},[d,e,g,k]);t.useEffect(()=>n.mergeRegister(d.registerCommand(r.FORMAT_ELEMENT_COMMAND,b=>{if(e){var c=r.$getSelection();if(r.$isNodeSelection(c)){var f=r.$getNodeByKey(g);
|
|
9
|
+
h.$isDecoratorBlockNode(f)&&f.setFormat(b)}else if(r.$isRangeSelection(c)){c=c.getNodes();for(f of c)h.$isDecoratorBlockNode(f)?f.setFormat(b):n.$getNearestBlockElementAncestorOrThrow(f).setFormat(b)}return!0}return!1},r.COMMAND_PRIORITY_LOW),d.registerCommand(r.CLICK_COMMAND,b=>{b.preventDefault();return b.target===q.current?(b.shiftKey||p(),k(!e),!0):!1},r.COMMAND_PRIORITY_LOW),d.registerCommand(r.KEY_DELETE_COMMAND,l,r.COMMAND_PRIORITY_LOW),d.registerCommand(r.KEY_BACKSPACE_COMMAND,l,r.COMMAND_PRIORITY_LOW)),
|
|
10
|
+
[p,d,e,g,l,k]);return t.createElement("div",{className:`embed-block${e?" focused":""}`,ref:q,style:{textAlign:v}},u)};
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
class DecoratorBlockNode extends lexical.DecoratorNode {
|
|
20
|
+
createDOM() {
|
|
21
|
+
return document.createElement('div');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
updateDOM() {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
setFormat(format) {
|
|
29
|
+
const self = this.getWritable();
|
|
30
|
+
self.__format = format;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
function $createDecoratorBlockNode() {
|
|
35
|
+
return new DecoratorBlockNode();
|
|
36
|
+
}
|
|
37
|
+
function $isDecoratorBlockNode(node) {
|
|
38
|
+
return node instanceof DecoratorBlockNode;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.$createDecoratorBlockNode = $createDecoratorBlockNode;
|
|
42
|
+
exports.$isDecoratorBlockNode = $isDecoratorBlockNode;
|
|
43
|
+
exports.DecoratorBlockNode = DecoratorBlockNode;
|
|
@@ -0,0 +1,9 @@
|
|
|
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 LexicalDecoratorBlockNode = process.env.NODE_ENV === 'development' ? require('./LexicalDecoratorBlockNode.dev.js') : require('./LexicalDecoratorBlockNode.prod.js')
|
|
9
|
+
module.exports = LexicalDecoratorBlockNode;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {ElementFormatType, LexicalNode, LexicalCommand} from 'lexical';
|
|
11
|
+
|
|
12
|
+
import {DecoratorNode} from 'lexical';
|
|
13
|
+
|
|
14
|
+
declare export class DecoratorBlockNode<T> extends DecoratorNode<T> {
|
|
15
|
+
__format: ?ElementFormatType;
|
|
16
|
+
createDOM(): HTMLElement;
|
|
17
|
+
setFormat(format: ElementFormatType): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare export function $createDecoratorBlockNode<T>(): DecoratorBlockNode<T>;
|
|
21
|
+
declare export function $isDecoratorBlockNode(
|
|
22
|
+
node: ?LexicalNode,
|
|
23
|
+
): boolean %checks(node instanceof DecoratorBlockNode);
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
var a=require("lexical");class c extends a.DecoratorNode{createDOM(){return document.createElement("div")}updateDOM(){return!1}setFormat(b){this.getWritable().__format=b}}exports.$createDecoratorBlockNode=function(){return new c};exports.$isDecoratorBlockNode=function(b){return b instanceof c};exports.DecoratorBlockNode=c;
|
|
@@ -20,6 +20,6 @@ export declare class HorizontalRuleNode extends DecoratorNode<JSX.Element | null
|
|
|
20
20
|
export function $createHorizontalRuleNode(): HorizontalRuleNode;
|
|
21
21
|
export function $isHorizontalRuleNode(
|
|
22
22
|
node: LexicalNode | null | undefined,
|
|
23
|
-
):
|
|
23
|
+
): node is HorizontalRuleNode;
|
|
24
24
|
|
|
25
25
|
export var INSERT_HORIZONTAL_RULE_COMMAND: LexicalCommand<void>;
|
package/package.json
CHANGED
|
@@ -8,27 +8,27 @@
|
|
|
8
8
|
"rich-text"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.2.
|
|
11
|
+
"version": "0.2.4",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.2.
|
|
14
|
-
"@lexical/list": "0.2.
|
|
15
|
-
"@lexical/table": "0.2.
|
|
16
|
-
"@lexical/yjs": "0.2.
|
|
17
|
-
"@lexical/hashtag": "0.2.
|
|
18
|
-
"@lexical/selection": "0.2.
|
|
19
|
-
"@lexical/utils": "0.2.
|
|
20
|
-
"@lexical/dragon": "0.2.
|
|
21
|
-
"@lexical/plain-text": "0.2.
|
|
22
|
-
"@lexical/rich-text": "0.2.
|
|
23
|
-
"@lexical/code": "0.2.
|
|
24
|
-
"@lexical/text": "0.2.
|
|
25
|
-
"@lexical/link": "0.2.
|
|
26
|
-
"@lexical/overflow": "0.2.
|
|
27
|
-
"@lexical/history": "0.2.
|
|
28
|
-
"@lexical/markdown": "0.2.
|
|
13
|
+
"@lexical/clipboard": "0.2.4",
|
|
14
|
+
"@lexical/list": "0.2.4",
|
|
15
|
+
"@lexical/table": "0.2.4",
|
|
16
|
+
"@lexical/yjs": "0.2.4",
|
|
17
|
+
"@lexical/hashtag": "0.2.4",
|
|
18
|
+
"@lexical/selection": "0.2.4",
|
|
19
|
+
"@lexical/utils": "0.2.4",
|
|
20
|
+
"@lexical/dragon": "0.2.4",
|
|
21
|
+
"@lexical/plain-text": "0.2.4",
|
|
22
|
+
"@lexical/rich-text": "0.2.4",
|
|
23
|
+
"@lexical/code": "0.2.4",
|
|
24
|
+
"@lexical/text": "0.2.4",
|
|
25
|
+
"@lexical/link": "0.2.4",
|
|
26
|
+
"@lexical/overflow": "0.2.4",
|
|
27
|
+
"@lexical/history": "0.2.4",
|
|
28
|
+
"@lexical/markdown": "0.2.4"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"lexical": "0.2.
|
|
31
|
+
"lexical": "0.2.4",
|
|
32
32
|
"react": ">=17.x",
|
|
33
33
|
"react-dom": ">=17.x"
|
|
34
34
|
},
|