@lexical/react 0.3.0 → 0.3.3
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/LexicalCheckListPlugin.dev.js +2 -2
- package/LexicalCheckListPlugin.prod.js +4 -4
- package/LexicalCollaborationPlugin.d.ts +2 -2
- package/LexicalComposer.d.ts +1 -0
- package/LexicalComposer.dev.js +2 -0
- package/LexicalComposer.js.flow +1 -1
- package/LexicalComposer.prod.js +1 -1
- package/LexicalContentEditable.js.flow +1 -1
- package/LexicalHorizontalRuleNode.dev.js +0 -22
- package/LexicalHorizontalRuleNode.prod.js +2 -2
- package/LexicalNestedComposer.dev.js +1 -0
- package/LexicalNestedComposer.prod.js +2 -2
- package/LexicalPlainTextPlugin.d.ts +2 -2
- package/LexicalPlainTextPlugin.js.flow +6 -2
- package/LexicalRichTextPlugin.d.ts +2 -2
- package/LexicalRichTextPlugin.js.flow +6 -2
- package/README.md +4 -5
- package/package.json +22 -19
|
@@ -46,7 +46,7 @@ function CheckListPlugin() {
|
|
|
46
46
|
}, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_SPACE_COMMAND, event => {
|
|
47
47
|
const activeItem = getActiveCheckListItem();
|
|
48
48
|
|
|
49
|
-
if (activeItem != null) {
|
|
49
|
+
if (activeItem != null && !editor.isReadOnly()) {
|
|
50
50
|
editor.update(() => {
|
|
51
51
|
const listItemNode = lexical.$getNearestNodeFromDOMNode(activeItem);
|
|
52
52
|
|
|
@@ -139,7 +139,7 @@ function handleClick(event) {
|
|
|
139
139
|
handleCheckItemEvent(event, () => {
|
|
140
140
|
const editor = findEditor(event.target);
|
|
141
141
|
|
|
142
|
-
if (editor != null) {
|
|
142
|
+
if (editor != null && !editor.isReadOnly()) {
|
|
143
143
|
editor.update(() => {
|
|
144
144
|
const node = lexical.$getNearestNodeFromDOMNode(event.target);
|
|
145
145
|
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var e=require("@lexical/list"),g=require("@lexical/react/LexicalComposerContext"),k=require("@lexical/utils"),l=require("lexical"),m=require("react");let n=0;function p(){0===n++&&(document.addEventListener("click",q),document.addEventListener("pointerdown",r));return()=>{0===--n&&(document.removeEventListener("click",q),document.removeEventListener("pointerdown",r))}}
|
|
8
|
-
function t(a,c){let b=a.target;if(b instanceof HTMLElement){var d=b.firstChild;(null==d||"UL"!==d.tagName&&"OL"!==d.tagName)&&(d=b.parentNode)&&"check"===d.__lexicalListType&&(a=a.pageX,d=b.getBoundingClientRect(),("rtl"===b.dir?a<d.right&&a>d.right-20:a>d.left&&a<d.left+20)&&c())}}function q(a){t(a,()=>{let c=u(a.target);null
|
|
9
|
-
function u(a){for(;a;){if(a.__lexicalEditor)return a.__lexicalEditor;a=a.parentNode}return null}function v(){let a=document.activeElement;return null!=a&&"LI"===a.tagName&&null!=a.parentNode&&"check"===a.parentNode.__lexicalListType?a:null}
|
|
8
|
+
function t(a,c){let b=a.target;if(b instanceof HTMLElement){var d=b.firstChild;(null==d||"UL"!==d.tagName&&"OL"!==d.tagName)&&(d=b.parentNode)&&"check"===d.__lexicalListType&&(a=a.pageX,d=b.getBoundingClientRect(),("rtl"===b.dir?a<d.right&&a>d.right-20:a>d.left&&a<d.left+20)&&c())}}function q(a){t(a,()=>{let c=u(a.target);null==c||c.isReadOnly()||c.update(()=>{let b=l.$getNearestNodeFromDOMNode(a.target);e.$isListItemNode(b)&&(a.target.focus(),b.toggleChecked())})})}
|
|
9
|
+
function r(a){t(a,()=>{a.preventDefault()})}function u(a){for(;a;){if(a.__lexicalEditor)return a.__lexicalEditor;a=a.parentNode}return null}function v(){let a=document.activeElement;return null!=a&&"LI"===a.tagName&&null!=a.parentNode&&"check"===a.parentNode.__lexicalListType?a:null}
|
|
10
10
|
function w(a,c){let b=c?a.getPreviousSibling():a.getNextSibling();for(;null==b&&e.$isListItemNode(a);)a=a.getParentOrThrow().getParent(),null!=a&&(b=c?a.getPreviousSibling():a.getNextSibling());for(;e.$isListItemNode(b);){a=c?b.getLastChild():b.getFirstChild();if(!e.$isListNode(a))return b;b=c?a.getLastChild():a.getFirstChild()}return null}
|
|
11
11
|
function x(a,c,b){let d=v();null!=d&&c.update(()=>{var f=l.$getNearestNodeFromDOMNode(d);if(e.$isListItemNode(f)&&(f=w(f,b),null!=f)){f.selectStart();let h=c.getElementByKey(f.__key);null!=h&&(a.preventDefault(),setTimeout(()=>{h.focus()},0))}});return!1}
|
|
12
12
|
exports.CheckListPlugin=function(){let [a]=g.useLexicalComposerContext();m.useEffect(()=>k.mergeRegister(a.registerCommand(e.INSERT_CHECK_LIST_COMMAND,()=>{e.insertList(a,"check");return!0},l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_DOWN_COMMAND,c=>x(c,a,!1),l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_UP_COMMAND,c=>x(c,a,!0),l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ESCAPE_COMMAND,()=>{if(null!=v()){let c=a.getRootElement();null!=c&&c.focus();return!0}return!1},l.COMMAND_PRIORITY_LOW),
|
|
13
|
-
a.registerCommand(l.KEY_SPACE_COMMAND,c=>{let b=v();return null
|
|
14
|
-
(b||f.getFirstDescendant()===d)&&(b=a.getElementByKey(f.__key),null!=b&&document.activeElement!==b))return b.focus(),c.preventDefault(),!0}}return!1}),l.COMMAND_PRIORITY_LOW),p()));return null}
|
|
13
|
+
a.registerCommand(l.KEY_SPACE_COMMAND,c=>{let b=v();return null==b||a.isReadOnly()?!1:(a.update(()=>{let d=l.$getNearestNodeFromDOMNode(b);e.$isListItemNode(d)&&(c.preventDefault(),d.toggleChecked())}),!0)},l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_LEFT_COMMAND,c=>a.getEditorState().read(()=>{var b=l.$getSelection();if(l.$isRangeSelection(b)&&b.isCollapsed()){var {anchor:d}=b;if((b="element"===d.type)||0===d.offset){d=d.getNode();let f=k.$findMatchingParent(d,h=>l.$isElementNode(h)&&!h.isInline());
|
|
14
|
+
if(e.$isListItemNode(f)&&(b||f.getFirstDescendant()===d)&&(b=a.getElementByKey(f.__key),null!=b&&document.activeElement!==b))return b.focus(),c.preventDefault(),!0}}return!1}),l.COMMAND_PRIORITY_LOW),p()));return null}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import type {Provider} from '@lexical/yjs';
|
|
10
10
|
import type {Doc, RelativePosition} from 'yjs';
|
|
11
11
|
|
|
12
12
|
export type UserState = {
|
|
@@ -31,7 +31,7 @@ type CollaborationContextType = {
|
|
|
31
31
|
};
|
|
32
32
|
export function CollaborationPlugin(arg0: {
|
|
33
33
|
id: string;
|
|
34
|
-
providerFactory(id: string, yjsDocMap: Map<string, Doc>):
|
|
34
|
+
providerFactory(id: string, yjsDocMap: Map<string, Doc>): Provider;
|
|
35
35
|
shouldBootstrap: boolean;
|
|
36
36
|
username?: string;
|
|
37
37
|
}): JSX.Element | null;
|
package/LexicalComposer.d.ts
CHANGED
package/LexicalComposer.dev.js
CHANGED
|
@@ -43,6 +43,7 @@ function LexicalComposer({
|
|
|
43
43
|
const composerContext = React.useMemo(() => {
|
|
44
44
|
const {
|
|
45
45
|
theme,
|
|
46
|
+
namespace,
|
|
46
47
|
editor__DEPRECATED: initialEditor,
|
|
47
48
|
nodes,
|
|
48
49
|
onError
|
|
@@ -52,6 +53,7 @@ function LexicalComposer({
|
|
|
52
53
|
|
|
53
54
|
if (editor === null) {
|
|
54
55
|
const newEditor = lexical.createEditor({
|
|
56
|
+
namespace,
|
|
55
57
|
nodes,
|
|
56
58
|
onError: error => onError(error, newEditor),
|
|
57
59
|
readOnly: true,
|
package/LexicalComposer.js.flow
CHANGED
|
@@ -13,7 +13,7 @@ type Props = {
|
|
|
13
13
|
initialConfig: $ReadOnly<{
|
|
14
14
|
editor__DEPRECATED?: LexicalEditor | null,
|
|
15
15
|
readOnly?: boolean,
|
|
16
|
-
namespace
|
|
16
|
+
namespace: string,
|
|
17
17
|
nodes?: $ReadOnlyArray<Class<LexicalNode>>,
|
|
18
18
|
theme?: EditorThemeClasses,
|
|
19
19
|
onError: (error: Error, editor: LexicalEditor) => void,
|
package/LexicalComposer.prod.js
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var a=require("@lexical/react/LexicalComposerContext"),e=require("lexical"),k=require("react"),l="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?k.useLayoutEffect:k.useEffect;
|
|
8
|
-
exports.LexicalComposer=function({initialConfig:f,children:m}){let h=k.useMemo(()=>{const {theme:b,
|
|
8
|
+
exports.LexicalComposer=function({initialConfig:f,children:m}){let h=k.useMemo(()=>{const {theme:b,namespace:c,editor__DEPRECATED:n,nodes:p,onError:q}=f,r=a.createLexicalComposerContext(null,b);let d=n||null;if(null===d){const g=e.createEditor({namespace:c,nodes:p,onError:t=>q(t,g),readOnly:!0,theme:b});d=g}return[d,r]},[]);l(()=>{let b=f.readOnly,[c]=h;c.setReadOnly(b||!1)},[]);return k.createElement(a.LexicalComposerContext.Provider,{value:h},m)}
|
|
@@ -31,21 +31,6 @@ class HorizontalRuleNode extends lexical.DecoratorNode {
|
|
|
31
31
|
return new HorizontalRuleNode(node.__key);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
static importDOM() {
|
|
35
|
-
return {
|
|
36
|
-
hr: node => ({
|
|
37
|
-
conversion: convertHorizontalRuleElement,
|
|
38
|
-
priority: 0
|
|
39
|
-
})
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
exportDOM() {
|
|
44
|
-
return {
|
|
45
|
-
element: document.createElement('hr')
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
34
|
static importJSON(serializedNode) {
|
|
50
35
|
return $createHorizontalRuleNode();
|
|
51
36
|
}
|
|
@@ -80,13 +65,6 @@ class HorizontalRuleNode extends lexical.DecoratorNode {
|
|
|
80
65
|
}
|
|
81
66
|
|
|
82
67
|
}
|
|
83
|
-
|
|
84
|
-
function convertHorizontalRuleElement() {
|
|
85
|
-
return {
|
|
86
|
-
node: $createHorizontalRuleNode()
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
68
|
function $createHorizontalRuleNode() {
|
|
91
69
|
return new HorizontalRuleNode();
|
|
92
70
|
}
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var b=require("lexical"),c=require("react");let d=b.createCommand();function e(){return c.createElement("hr",null)}
|
|
8
|
-
class f extends b.DecoratorNode{static getType(){return"horizontalrule"}static clone(a){return new f(a.__key)}static
|
|
9
|
-
|
|
8
|
+
class f extends b.DecoratorNode{static getType(){return"horizontalrule"}static clone(a){return new f(a.__key)}static importJSON(){return g()}exportJSON(){return{type:"horizontalrule",version:1}}createDOM(){let a=document.createElement("div");a.style.display="contents";return a}getTextContent(){return"\n"}isTopLevel(){return!0}updateDOM(){return!1}decorate(){return c.createElement(e,null)}}function g(){return new f}exports.$createHorizontalRuleNode=g;
|
|
9
|
+
exports.$isHorizontalRuleNode=function(a){return a instanceof f};exports.HorizontalRuleNode=f;exports.INSERT_HORIZONTAL_RULE_COMMAND=d
|
|
@@ -41,6 +41,7 @@ function LexicalNestedComposer({
|
|
|
41
41
|
|
|
42
42
|
initialEditor._parentEditor = parentEditor;
|
|
43
43
|
initialEditor._nodes = parentEditor._nodes;
|
|
44
|
+
initialEditor._config.namespace = parentEditor._config.namespace;
|
|
44
45
|
return [initialEditor, context];
|
|
45
46
|
}, // We only do this for init
|
|
46
47
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var c=require("@lexical/react/LexicalCollaborationPlugin"),d=require("@lexical/react/LexicalComposerContext"),h=require("react");
|
|
8
|
-
exports.LexicalNestedComposer=function({initialEditor:a,children:k,initialTheme:l}){let e=h.useContext(d.LexicalComposerContext);if(null==e)throw Error("Minified Lexical error #9; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");let p=h.useMemo(()=>{const [
|
|
9
|
-
c.useCollaborationContext();let q=void 0!==b.get("main");b=b.has(a.getKey());return h.createElement(d.LexicalComposerContext.Provider,{value:p},!q||b?k:null)}
|
|
8
|
+
exports.LexicalNestedComposer=function({initialEditor:a,children:k,initialTheme:l}){let e=h.useContext(d.LexicalComposerContext);if(null==e)throw Error("Minified Lexical error #9; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");let p=h.useMemo(()=>{const [f,m]=e,g=l||m.getTheme()||void 0,n=d.createLexicalComposerContext(e,g);void 0!==g&&(a._config.theme=g);a._parentEditor=f;a._nodes=f._nodes;a._config.namespace=f._config.namespace;
|
|
9
|
+
return[a,n]},[]);var {yjsDocMap:b}=c.useCollaborationContext();let q=void 0!==b.get("main");b=b.has(a.getKey());return h.createElement(d.LexicalComposerContext.Provider,{value:p},!q||b?k:null)}
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import {InitialEditorStateType} from '@lexical/plain-text';
|
|
10
|
+
import type {EditorState, LexicalEditor} from 'lexical';
|
|
10
11
|
|
|
11
|
-
type InitialEditorStateType = null | string | EditorState | (() => void);
|
|
12
12
|
export function PlainTextPlugin(arg0: {
|
|
13
13
|
contentEditable: JSX.Element | null;
|
|
14
14
|
initialEditorState?: InitialEditorStateType;
|
|
@@ -7,9 +7,13 @@
|
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type {EditorState} from 'lexical';
|
|
10
|
+
import type {EditorState, LexicalEditor} from 'lexical';
|
|
11
11
|
|
|
12
|
-
type InitialEditorStateType =
|
|
12
|
+
type InitialEditorStateType =
|
|
13
|
+
| null
|
|
14
|
+
| string
|
|
15
|
+
| EditorState
|
|
16
|
+
| ((editor: LexicalEditor) => void);
|
|
13
17
|
|
|
14
18
|
declare export function PlainTextPlugin({
|
|
15
19
|
contentEditable: React$Node,
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import {InitialEditorStateType} from '@lexical/rich-text';
|
|
10
|
+
import type {EditorState, LexicalEditor} from 'lexical';
|
|
10
11
|
|
|
11
|
-
type InitialEditorStateType = null | string | EditorState | (() => void);
|
|
12
12
|
export function RichTextPlugin(arg0: {
|
|
13
13
|
contentEditable: JSX.Element | null;
|
|
14
14
|
initialEditorState?: InitialEditorStateType;
|
|
@@ -7,9 +7,13 @@
|
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type {EditorState} from 'lexical';
|
|
10
|
+
import type {EditorState, LexicalEditor} from 'lexical';
|
|
11
11
|
|
|
12
|
-
type InitialEditorStateType =
|
|
12
|
+
type InitialEditorStateType =
|
|
13
|
+
| null
|
|
14
|
+
| string
|
|
15
|
+
| EditorState
|
|
16
|
+
| ((editor: LexicalEditor) => void);
|
|
13
17
|
|
|
14
18
|
declare export function RichTextPlugin({
|
|
15
19
|
contentEditable: React$Node,
|
package/README.md
CHANGED
|
@@ -17,10 +17,10 @@ import {$getRoot, $getSelection} from 'lexical';
|
|
|
17
17
|
import {useEffect} from 'react';
|
|
18
18
|
|
|
19
19
|
import {LexicalComposer} from '@lexical/react/LexicalComposer';
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
20
|
+
import {PlainTextPlugin} from '@lexical/react/LexicalPlainTextPlugin';
|
|
21
|
+
import {ContentEditable} from '@lexical/react/LexicalContentEditable';
|
|
22
22
|
import {HistoryPlugin} from '@lexical/react/LexicalHistoryPlugin';
|
|
23
|
-
import {
|
|
23
|
+
import {OnChangePlugin} from '@lexical/react/LexicalOnChangePlugin';
|
|
24
24
|
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
|
25
25
|
|
|
26
26
|
const theme = {
|
|
@@ -66,12 +66,11 @@ function onError(error) {
|
|
|
66
66
|
|
|
67
67
|
function Editor() {
|
|
68
68
|
const initialConfig = {
|
|
69
|
+
namespace: 'MyEditor',
|
|
69
70
|
theme,
|
|
70
71
|
onError,
|
|
71
72
|
};
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
74
|
return (
|
|
76
75
|
<LexicalComposer initialConfig={initialConfig}>
|
|
77
76
|
<LexicalPlainTextPlugin
|
package/package.json
CHANGED
|
@@ -8,28 +8,28 @@
|
|
|
8
8
|
"rich-text"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.3.
|
|
11
|
+
"version": "0.3.3",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.3.
|
|
14
|
-
"@lexical/
|
|
15
|
-
"@lexical/
|
|
16
|
-
"@lexical/
|
|
17
|
-
"@lexical/
|
|
18
|
-
"@lexical/
|
|
19
|
-
"@lexical/
|
|
20
|
-
"@lexical/
|
|
21
|
-
"@lexical/
|
|
22
|
-
"@lexical/
|
|
23
|
-
"@lexical/
|
|
24
|
-
"@lexical/text": "0.3.
|
|
25
|
-
"@lexical/
|
|
26
|
-
"@lexical/
|
|
27
|
-
"@lexical/
|
|
28
|
-
"@lexical/
|
|
29
|
-
"@lexical/
|
|
13
|
+
"@lexical/clipboard": "0.3.3",
|
|
14
|
+
"@lexical/code": "0.3.3",
|
|
15
|
+
"@lexical/dragon": "0.3.3",
|
|
16
|
+
"@lexical/hashtag": "0.3.3",
|
|
17
|
+
"@lexical/history": "0.3.3",
|
|
18
|
+
"@lexical/link": "0.3.3",
|
|
19
|
+
"@lexical/list": "0.3.3",
|
|
20
|
+
"@lexical/mark": "0.3.3",
|
|
21
|
+
"@lexical/markdown": "0.3.3",
|
|
22
|
+
"@lexical/overflow": "0.3.3",
|
|
23
|
+
"@lexical/plain-text": "0.3.3",
|
|
24
|
+
"@lexical/rich-text": "0.3.3",
|
|
25
|
+
"@lexical/selection": "0.3.3",
|
|
26
|
+
"@lexical/table": "0.3.3",
|
|
27
|
+
"@lexical/text": "0.3.3",
|
|
28
|
+
"@lexical/utils": "0.3.3",
|
|
29
|
+
"@lexical/yjs": "0.3.3"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"lexical": "0.3.
|
|
32
|
+
"lexical": "0.3.3",
|
|
33
33
|
"react": ">=17.x",
|
|
34
34
|
"react-dom": ">=17.x"
|
|
35
35
|
},
|
|
@@ -37,5 +37,8 @@
|
|
|
37
37
|
"type": "git",
|
|
38
38
|
"url": "https://github.com/facebook/lexical",
|
|
39
39
|
"directory": "packages/lexical-react"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"utility-types": "^3.10.0"
|
|
40
43
|
}
|
|
41
44
|
}
|