@lexical/react 0.16.0 → 0.16.1-nightly.20240610.0
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.
|
@@ -133,14 +133,12 @@ function handleClick(event) {
|
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
});
|
|
136
|
-
event.stopPropagation(); // Prevents potential parent-editor listeners from firing, causing the checkbox toggle to be undone
|
|
137
136
|
}
|
|
138
137
|
function handlePointerDown(event) {
|
|
139
138
|
handleCheckItemEvent(event, () => {
|
|
140
139
|
// Prevents caret moving when clicking on check mark
|
|
141
140
|
event.preventDefault();
|
|
142
141
|
});
|
|
143
|
-
event.stopPropagation();
|
|
144
142
|
}
|
|
145
143
|
function findEditor(target) {
|
|
146
144
|
let node = target;
|
|
@@ -131,14 +131,12 @@ function handleClick(event) {
|
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
});
|
|
134
|
-
event.stopPropagation(); // Prevents potential parent-editor listeners from firing, causing the checkbox toggle to be undone
|
|
135
134
|
}
|
|
136
135
|
function handlePointerDown(event) {
|
|
137
136
|
handleCheckItemEvent(event, () => {
|
|
138
137
|
// Prevents caret moving when clicking on check mark
|
|
139
138
|
event.preventDefault();
|
|
140
139
|
});
|
|
141
|
-
event.stopPropagation();
|
|
142
140
|
}
|
|
143
141
|
function findEditor(target) {
|
|
144
142
|
let node = target;
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';var e=require("@lexical/list"),g=require("@lexical/react/LexicalComposerContext"),k=require("@lexical/utils"),l=require("lexical"),m=require("react");function n(a,c){let b=a.target;if(null!==b&&k.isHTMLElement(b)){var d=b.firstChild;(null==d||!k.isHTMLElement(d)||"UL"!==d.tagName&&"OL"!==d.tagName)&&(d=b.parentNode)&&"check"===d.__lexicalListType&&(d=b.getBoundingClientRect(),a=a.pageX/k.calculateZoomLevel(b),("rtl"===b.dir?a<d.right&&a>d.right-20:a>d.left&&a<d.left+20)&&c())}}
|
|
10
|
-
function p(a){n(a,()=>{let c=a.target,b=q(c);null!=b&&b.isEditable()&&b.update(()=>{if(a.target){let d=l.$getNearestNodeFromDOMNode(c);e.$isListItemNode(d)&&(c.focus(),d.toggleChecked())}})})
|
|
11
|
-
function
|
|
10
|
+
function p(a){n(a,()=>{let c=a.target,b=q(c);null!=b&&b.isEditable()&&b.update(()=>{if(a.target){let d=l.$getNearestNodeFromDOMNode(c);e.$isListItemNode(d)&&(c.focus(),d.toggleChecked())}})})}function r(a){n(a,()=>{a.preventDefault()})}function q(a){for(;a;){if(a.__lexicalEditor)return a.__lexicalEditor;a=a.parentNode}return null}function t(){let a=document.activeElement;return null!=a&&"LI"===a.tagName&&null!=a.parentNode&&"check"===a.parentNode.__lexicalListType?a:null}
|
|
11
|
+
function u(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}
|
|
12
12
|
function v(a,c,b){let d=t();null!=d&&c.update(()=>{var f=l.$getNearestNodeFromDOMNode(d);if(e.$isListItemNode(f)&&(f=u(f,b),null!=f)){f.selectStart();let h=c.getElementByKey(f.__key);null!=h&&(a.preventDefault(),setTimeout(()=>{h.focus()},0))}});return!1}
|
|
13
13
|
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=>v(c,a,!1),l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_UP_COMMAND,c=>v(c,a,!0),l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ESCAPE_COMMAND,()=>{if(null!=t()){let c=a.getRootElement();null!=c&&c.focus();return!0}return!1},l.COMMAND_PRIORITY_LOW),
|
|
14
14
|
a.registerCommand(l.KEY_SPACE_COMMAND,c=>{let b=t();return null!=b&&a.isEditable()?(a.update(()=>{let d=l.$getNearestNodeFromDOMNode(b);e.$isListItemNode(d)&&(c.preventDefault(),d.toggleChecked())}),!0):!1},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());
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{INSERT_CHECK_LIST_COMMAND as e,insertList as t,$isListItemNode as n,$isListNode as r}from"@lexical/list";import{useLexicalComposerContext as i}from"@lexical/react/LexicalComposerContext";import{mergeRegister as l,$findMatchingParent as o,isHTMLElement as c,calculateZoomLevel as
|
|
9
|
+
import{INSERT_CHECK_LIST_COMMAND as e,insertList as t,$isListItemNode as n,$isListNode as r}from"@lexical/list";import{useLexicalComposerContext as i}from"@lexical/react/LexicalComposerContext";import{mergeRegister as l,$findMatchingParent as o,isHTMLElement as c,calculateZoomLevel as u}from"@lexical/utils";import{COMMAND_PRIORITY_LOW as s,KEY_ARROW_DOWN_COMMAND as a,KEY_ARROW_UP_COMMAND as g,KEY_ESCAPE_COMMAND as f,KEY_SPACE_COMMAND as d,$getNearestNodeFromDOMNode as m,KEY_ARROW_LEFT_COMMAND as p,$getSelection as C,$isRangeSelection as h,$isElementNode as v}from"lexical";import{useEffect as E}from"react";function L(){const[c]=i();return E((()=>l(c.registerCommand(e,(()=>(t(c,"check"),!0)),s),c.registerCommand(a,(e=>N(e,c,!1)),s),c.registerCommand(g,(e=>N(e,c,!0)),s),c.registerCommand(f,(e=>{if(null!=y()){const e=c.getRootElement();return null!=e&&e.focus(),!0}return!1}),s),c.registerCommand(d,(e=>{const t=y();return!(null==t||!c.isEditable())&&(c.update((()=>{const r=m(t);n(r)&&(e.preventDefault(),r.toggleChecked())})),!0)}),s),c.registerCommand(p,(e=>c.getEditorState().read((()=>{const t=C();if(h(t)&&t.isCollapsed()){const{anchor:i}=t,l="element"===i.type;if(l||0===i.offset){const t=i.getNode(),u=o(t,(e=>v(e)&&!e.isInline()));if(n(u)){const n=u.getParent();if(r(n)&&"check"===n.getListType()&&(l||u.getFirstDescendant()===t)){const t=c.getElementByKey(u.__key);if(null!=t&&document.activeElement!==t)return t.focus(),e.preventDefault(),!0}}}}return!1}))),s),c.registerRootListener(((e,t)=>{null!==e&&(e.addEventListener("click",_),e.addEventListener("pointerdown",k)),null!==t&&(t.removeEventListener("click",_),t.removeEventListener("pointerdown",k))}))))),null}function x(e,t){const n=e.target;if(null===n||!c(n))return;const r=n.firstChild;if(null!=r&&c(r)&&("UL"===r.tagName||"OL"===r.tagName))return;const i=n.parentNode;if(!i||"check"!==i.__lexicalListType)return;const l=n.getBoundingClientRect(),o=e.pageX/u(n);("rtl"===n.dir?o<l.right&&o>l.right-20:o>l.left&&o<l.left+20)&&t()}function _(e){x(e,(()=>{const t=e.target,r=function(e){let t=e;for(;t;){if(t.__lexicalEditor)return t.__lexicalEditor;t=t.parentNode}return null}(t);null!=r&&r.isEditable()&&r.update((()=>{if(e.target){const e=m(t);n(e)&&(t.focus(),e.toggleChecked())}}))}))}function k(e){x(e,(()=>{e.preventDefault()}))}function y(){const e=document.activeElement;return null!=e&&"LI"===e.tagName&&null!=e.parentNode&&"check"===e.parentNode.__lexicalListType?e:null}function N(e,t,i){const l=y();return null!=l&&t.update((()=>{const o=m(l);if(!n(o))return;const c=function(e,t){let i=t?e.getPreviousSibling():e.getNextSibling(),l=e;for(;null==i&&n(l);)l=l.getParentOrThrow().getParent(),null!=l&&(i=t?l.getPreviousSibling():l.getNextSibling());for(;n(i);){const e=t?i.getLastChild():i.getFirstChild();if(!r(e))return i;i=t?e.getLastChild():e.getFirstChild()}return null}(o,i);if(null!=c){c.selectStart();const n=t.getElementByKey(c.__key);null!=n&&(e.preventDefault(),setTimeout((()=>{n.focus()}),0))}})),!1}export{L as CheckListPlugin};
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Install `lexical` and `@lexical/react`:
|
|
|
10
10
|
npm install --save lexical @lexical/react
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Below is an example of a basic plain text editor using `lexical` and `@lexical/react` ([try it yourself](https://
|
|
13
|
+
Below is an example of a basic plain text editor using `lexical` and `@lexical/react` ([try it yourself](https://stackblitz.com/github/facebook/lexical/tree/main/examples/react-plain-text?embed=1&file=src%2FApp.tsx&terminalHeight=0&ctl=1&showSidebar=0&devtoolsheight=0&view=preview)).
|
|
14
14
|
|
|
15
15
|
```jsx
|
|
16
16
|
import {$getRoot, $getSelection} from 'lexical';
|
package/package.json
CHANGED
|
@@ -8,27 +8,27 @@
|
|
|
8
8
|
"rich-text"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.16.0",
|
|
11
|
+
"version": "0.16.1-nightly.20240610.0",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.16.0",
|
|
14
|
-
"@lexical/code": "0.16.0",
|
|
15
|
-
"@lexical/devtools-core": "0.16.0",
|
|
16
|
-
"@lexical/dragon": "0.16.0",
|
|
17
|
-
"@lexical/hashtag": "0.16.0",
|
|
18
|
-
"@lexical/history": "0.16.0",
|
|
19
|
-
"@lexical/link": "0.16.0",
|
|
20
|
-
"@lexical/list": "0.16.0",
|
|
21
|
-
"@lexical/mark": "0.16.0",
|
|
22
|
-
"@lexical/markdown": "0.16.0",
|
|
23
|
-
"@lexical/overflow": "0.16.0",
|
|
24
|
-
"@lexical/plain-text": "0.16.0",
|
|
25
|
-
"@lexical/rich-text": "0.16.0",
|
|
26
|
-
"@lexical/selection": "0.16.0",
|
|
27
|
-
"@lexical/table": "0.16.0",
|
|
28
|
-
"@lexical/text": "0.16.0",
|
|
29
|
-
"@lexical/utils": "0.16.0",
|
|
30
|
-
"@lexical/yjs": "0.16.0",
|
|
31
|
-
"lexical": "0.16.0",
|
|
13
|
+
"@lexical/clipboard": "0.16.1-nightly.20240610.0",
|
|
14
|
+
"@lexical/code": "0.16.1-nightly.20240610.0",
|
|
15
|
+
"@lexical/devtools-core": "0.16.1-nightly.20240610.0",
|
|
16
|
+
"@lexical/dragon": "0.16.1-nightly.20240610.0",
|
|
17
|
+
"@lexical/hashtag": "0.16.1-nightly.20240610.0",
|
|
18
|
+
"@lexical/history": "0.16.1-nightly.20240610.0",
|
|
19
|
+
"@lexical/link": "0.16.1-nightly.20240610.0",
|
|
20
|
+
"@lexical/list": "0.16.1-nightly.20240610.0",
|
|
21
|
+
"@lexical/mark": "0.16.1-nightly.20240610.0",
|
|
22
|
+
"@lexical/markdown": "0.16.1-nightly.20240610.0",
|
|
23
|
+
"@lexical/overflow": "0.16.1-nightly.20240610.0",
|
|
24
|
+
"@lexical/plain-text": "0.16.1-nightly.20240610.0",
|
|
25
|
+
"@lexical/rich-text": "0.16.1-nightly.20240610.0",
|
|
26
|
+
"@lexical/selection": "0.16.1-nightly.20240610.0",
|
|
27
|
+
"@lexical/table": "0.16.1-nightly.20240610.0",
|
|
28
|
+
"@lexical/text": "0.16.1-nightly.20240610.0",
|
|
29
|
+
"@lexical/utils": "0.16.1-nightly.20240610.0",
|
|
30
|
+
"@lexical/yjs": "0.16.1-nightly.20240610.0",
|
|
31
|
+
"lexical": "0.16.1-nightly.20240610.0",
|
|
32
32
|
"react-error-boundary": "^3.1.4"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|