@lexical/react 0.6.0 → 0.6.2
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/DEPRECATED_useLexicalDecorators.js.flow +2 -2
- package/LexicalAutoLinkPlugin.d.ts +2 -0
- package/LexicalAutoLinkPlugin.dev.js +18 -2
- package/LexicalAutoLinkPlugin.js.flow +5 -2
- package/LexicalAutoLinkPlugin.prod.js +6 -6
- package/LexicalCollaborationContext.dev.js +1 -1
- package/LexicalCollaborationContext.prod.js +1 -1
- package/LexicalComposer.d.ts +6 -1
- package/LexicalComposer.js.flow +4 -1
- package/LexicalErrorBoundary.d.ts +2 -3
- package/LexicalErrorBoundary.js.flow +6 -3
- package/LexicalHorizontalRuleNode.dev.js +1 -1
- package/LexicalHorizontalRuleNode.prod.js +1 -1
- package/LexicalLinkPlugin.d.ts +5 -1
- package/LexicalLinkPlugin.dev.js +33 -7
- package/LexicalLinkPlugin.js.flow +5 -1
- package/LexicalLinkPlugin.prod.js +3 -2
- package/LexicalNestedComposer.dev.js +2 -0
- package/LexicalNestedComposer.prod.js +4 -3
- package/LexicalTypeaheadMenuPlugin.dev.js +1 -4
- package/LexicalTypeaheadMenuPlugin.prod.js +20 -20
- package/package.json +19 -19
- package/LexicalAutoScrollPlugin.d.ts +0 -14
- package/LexicalAutoScrollPlugin.dev.js +0 -79
- package/LexicalAutoScrollPlugin.js +0 -9
- package/LexicalAutoScrollPlugin.js.flow +0 -12
- package/LexicalAutoScrollPlugin.prod.js +0 -8
|
@@ -13,8 +13,8 @@ import type {LexicalEditor} from 'lexical';
|
|
|
13
13
|
import * as React from 'react';
|
|
14
14
|
|
|
15
15
|
type ErrorBoundaryProps = $ReadOnly<{
|
|
16
|
-
children: React
|
|
17
|
-
onError
|
|
16
|
+
children: React$Node,
|
|
17
|
+
onError: (error: Error) => void,
|
|
18
18
|
}>;
|
|
19
19
|
export type ErrorBoundaryType = React.AbstractComponent<ErrorBoundaryProps>;
|
|
20
20
|
|
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
+
import type { LinkAttributes } from '@lexical/link';
|
|
8
9
|
declare type ChangeHandler = (url: string | null, prevUrl: string | null) => void;
|
|
9
10
|
declare type LinkMatcherResult = {
|
|
11
|
+
attributes?: LinkAttributes;
|
|
10
12
|
index: number;
|
|
11
13
|
length: number;
|
|
12
14
|
text: string;
|
|
@@ -99,7 +99,7 @@ function handleLinkCreation(node, matchers, onChange) {
|
|
|
99
99
|
[, linkTextNode, remainingTextNode] = remainingTextNode.splitText(invalidMatchEnd + matchStart, invalidMatchEnd + matchStart + matchLength);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
const linkNode = link.$createAutoLinkNode(match.url);
|
|
102
|
+
const linkNode = link.$createAutoLinkNode(match.url, match.attributes);
|
|
103
103
|
const textNode = lexical.$createTextNode(match.text);
|
|
104
104
|
textNode.setFormat(linkTextNode.getFormat());
|
|
105
105
|
textNode.setDetail(linkTextNode.getDetail());
|
|
@@ -149,10 +149,26 @@ function handleLinkEdit(linkNode, matchers, onChange) {
|
|
|
149
149
|
|
|
150
150
|
const url = linkNode.getURL();
|
|
151
151
|
|
|
152
|
-
if (
|
|
152
|
+
if (url !== match.url) {
|
|
153
153
|
linkNode.setURL(match.url);
|
|
154
154
|
onChange(match.url, url);
|
|
155
155
|
}
|
|
156
|
+
|
|
157
|
+
if (match.attributes) {
|
|
158
|
+
const rel = linkNode.getRel();
|
|
159
|
+
|
|
160
|
+
if (rel !== match.attributes.rel) {
|
|
161
|
+
linkNode.setRel(match.attributes.rel || null);
|
|
162
|
+
onChange(match.attributes.rel || null, rel);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const target = linkNode.getTarget();
|
|
166
|
+
|
|
167
|
+
if (target !== match.attributes.target) {
|
|
168
|
+
linkNode.setTarget(match.attributes.target || null);
|
|
169
|
+
onChange(match.attributes.target || null, target);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
156
172
|
} // Bad neighbours are edits in neighbor nodes that make AutoLinks incompatible.
|
|
157
173
|
// Given the creation preconditions, these can only be simple text nodes.
|
|
158
174
|
|
|
@@ -7,13 +7,16 @@
|
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import type {LinkAttributes} from '@lexical/link';
|
|
11
|
+
|
|
10
12
|
type ChangeHandler = (url: string | null, prevUrl: string | null) => void;
|
|
11
13
|
|
|
12
14
|
type LinkMatcherResult = {
|
|
15
|
+
attributes?: LinkAttributes,
|
|
16
|
+
index: number,
|
|
17
|
+
length: number,
|
|
13
18
|
text: string,
|
|
14
19
|
url: string,
|
|
15
|
-
length: number,
|
|
16
|
-
index: number,
|
|
17
20
|
};
|
|
18
21
|
|
|
19
22
|
export type LinkMatcher = (text: string) => LinkMatcherResult | null;
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var h=require("@lexical/link"),l=require("@lexical/react/LexicalComposerContext"),m=require("@lexical/utils"),q=require("lexical"),y=require("react");function z(b,
|
|
8
|
-
function D(b){b=b.getNextSibling();q.$isElementNode(b)&&(b=b.getFirstDescendant());return null===b||q.$isLineBreakNode(b)||q.$isTextNode(b)&&A.test(b.getTextContent()[0])}function E(b){let
|
|
9
|
-
function F(b,
|
|
10
|
-
c&&c(null,a);break a}}d=
|
|
11
|
-
v),t=h.$createAutoLinkNode(d.url),p=q.$createTextNode(d.text),p.setFormat(g.getFormat()),p.setDetail(g.getDetail()),t.append(p),g.replace(t),c&&c(d.url,null),k=0):k+=w;n=n.substring(w)}}g=a.getPreviousSibling();d=a.getNextSibling();a=a.getTextContent();h.$isAutoLinkNode(g)&&!A.test(a[0])&&
|
|
12
|
-
exports.AutoLinkPlugin=function({matchers:b,onChange:
|
|
7
|
+
'use strict';var h=require("@lexical/link"),l=require("@lexical/react/LexicalComposerContext"),m=require("@lexical/utils"),q=require("lexical"),y=require("react");function z(b,f){for(let c=0;c<f.length;c++){let a=f[c](b);if(a)return a}return null}let A=/[.,;\s]/;function C(b){b=b.getPreviousSibling();q.$isElementNode(b)&&(b=b.getLastDescendant());var f;!(f=null===b||q.$isLineBreakNode(b))&&(f=q.$isTextNode(b))&&(b=b.getTextContent(),f=A.test(b[b.length-1]));return f}
|
|
8
|
+
function D(b){b=b.getNextSibling();q.$isElementNode(b)&&(b=b.getFirstDescendant());return null===b||q.$isLineBreakNode(b)||q.$isTextNode(b)&&A.test(b.getTextContent()[0])}function E(b){let f=b.getChildren();var c=f.length;for(--c;0<=c;c--)b.insertAfter(f[c]);b.remove();return f.map(a=>a.getLatest())}
|
|
9
|
+
function F(b,f,c){y.useEffect(()=>{if(!b.hasNodes([h.AutoLinkNode]))throw Error("Minified Lexical error #77; visit https://lexical.dev/docs/error?code=77 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return m.mergeRegister(b.registerNodeTransform(q.TextNode,a=>{var e=a.getParentOrThrow();if(h.$isAutoLinkNode(e))a:{a=e.getChildren();var d=a.length;for(var g=0;g<d;g++){var n=a[g];if(!q.$isTextNode(n)||!n.isSimpleText()){E(e);a=e.getURL();
|
|
10
|
+
c&&c(null,a);break a}}d=e.getTextContent();a=z(d,f);null===a||a.text!==d?(E(e),a=e.getURL(),c&&c(null,a)):C(e)&&D(e)?(d=e.getURL(),d!==a.url&&(e.setURL(a.url),c&&c(a.url,d)),a.attributes&&(d=e.getRel(),d!==a.attributes.rel&&(e.setRel(a.attributes.rel||null),c&&c(a.attributes.rel||null,d)),d=e.getTarget(),d!==a.attributes.target&&(e.setTarget(a.attributes.target||null),c&&c(a.attributes.target||null,d)))):(E(e),a=e.getURL(),c&&c(null,a))}else if(!h.$isLinkNode(e)){if(a.isSimpleText()){n=e=a.getTextContent();
|
|
11
|
+
let k=0,u=a;for(;(d=z(n,f))&&null!==d;){let r=d.index,v=d.length,w=r+v;var t=k+r,p=k+w,x=e,B=a;(0<t?A.test(x[t-1]):C(B))&&(p<x.length?A.test(x[p]):D(B))?(0===k+r?[g,u]=u.splitText(k+v):[,g,u]=u.splitText(k+r,k+r+v),t=h.$createAutoLinkNode(d.url,d.attributes),p=q.$createTextNode(d.text),p.setFormat(g.getFormat()),p.setDetail(g.getDetail()),t.append(p),g.replace(t),c&&c(d.url,null),k=0):k+=w;n=n.substring(w)}}g=a.getPreviousSibling();d=a.getNextSibling();a=a.getTextContent();h.$isAutoLinkNode(g)&&!A.test(a[0])&&
|
|
12
|
+
(E(g),g=g.getURL(),c&&c(null,g));h.$isAutoLinkNode(d)&&!A.test(a[a.length-1])&&(E(d),a=d.getURL(),c&&c(null,a))}}))},[b,f,c])}exports.AutoLinkPlugin=function({matchers:b,onChange:f}){let [c]=l.useLexicalComposerContext();F(c,b,f);return null}
|
|
@@ -15,7 +15,7 @@ var react = require('react');
|
|
|
15
15
|
* LICENSE file in the root directory of this source tree.
|
|
16
16
|
*
|
|
17
17
|
*/
|
|
18
|
-
const entries = [['Cat', 'rgb(
|
|
18
|
+
const entries = [['Cat', 'rgb(125, 50, 0)'], ['Dog', 'rgb(100, 0, 0)'], ['Rabbit', 'rgb(150, 0, 0)'], ['Frog', 'rgb(200, 0, 0)'], ['Fox', 'rgb(200, 75, 0)'], ['Hedgehog', 'rgb(0, 75, 0)'], ['Pigeon', 'rgb(0, 125, 0)'], ['Squirrel', 'rgb(75, 100, 0)'], ['Bear', 'rgb(125, 100, 0)'], ['Tiger', 'rgb(0, 0, 150)'], ['Leopard', 'rgb(0, 0, 200)'], ['Zebra', 'rgb(0, 0, 250)'], ['Wolf', 'rgb(0, 100, 150)'], ['Owl', 'rgb(0, 100, 100)'], ['Gull', 'rgb(100, 0, 100)'], ['Squid', 'rgb(150, 0, 150)']];
|
|
19
19
|
const randomEntry = entries[Math.floor(Math.random() * entries.length)];
|
|
20
20
|
const CollaborationContext = /*#__PURE__*/react.createContext({
|
|
21
21
|
clientID: 0,
|
|
@@ -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("react");
|
|
8
|
-
let c=[["Cat","rgb(
|
|
8
|
+
let c=[["Cat","rgb(125, 50, 0)"],["Dog","rgb(100, 0, 0)"],["Rabbit","rgb(150, 0, 0)"],["Frog","rgb(200, 0, 0)"],["Fox","rgb(200, 75, 0)"],["Hedgehog","rgb(0, 75, 0)"],["Pigeon","rgb(0, 125, 0)"],["Squirrel","rgb(75, 100, 0)"],["Bear","rgb(125, 100, 0)"],["Tiger","rgb(0, 0, 150)"],["Leopard","rgb(0, 0, 200)"],["Zebra","rgb(0, 0, 250)"],["Wolf","rgb(0, 100, 150)"],["Owl","rgb(0, 100, 100)"],["Gull","rgb(100, 0, 100)"],["Squid","rgb(150, 0, 150)"]],d=c[Math.floor(Math.random()*c.length)],e=b.createContext({clientID:0,
|
|
9
9
|
color:d[1],isCollabActive:!1,name:d[0],yjsDocMap:new Map});exports.CollaborationContext=e;exports.useCollaborationContext=function(f,g){let a=b.useContext(e);null!=f&&(a.name=f);null!=g&&(a.color=g);return a}
|
package/LexicalComposer.d.ts
CHANGED
|
@@ -12,7 +12,12 @@ declare type Props = {
|
|
|
12
12
|
initialConfig: Readonly<{
|
|
13
13
|
editor__DEPRECATED?: LexicalEditor | null;
|
|
14
14
|
namespace: string;
|
|
15
|
-
nodes?: ReadonlyArray<Klass<LexicalNode
|
|
15
|
+
nodes?: ReadonlyArray<Klass<LexicalNode> | {
|
|
16
|
+
replace: Klass<LexicalNode>;
|
|
17
|
+
with: <T extends {
|
|
18
|
+
new (...args: any): any;
|
|
19
|
+
}>(node: InstanceType<T>) => LexicalNode;
|
|
20
|
+
}>;
|
|
16
21
|
onError: (error: Error, editor: LexicalEditor) => void;
|
|
17
22
|
editable?: boolean;
|
|
18
23
|
theme?: EditorThemeClasses;
|
package/LexicalComposer.js.flow
CHANGED
|
@@ -25,7 +25,10 @@ type Props = {
|
|
|
25
25
|
editor__DEPRECATED?: LexicalEditor | null,
|
|
26
26
|
editable?: boolean,
|
|
27
27
|
namespace: string,
|
|
28
|
-
nodes?: $ReadOnlyArray<
|
|
28
|
+
nodes?: $ReadOnlyArray<
|
|
29
|
+
| Class<LexicalNode>
|
|
30
|
+
| {replace: Class<LexicalNode>, with: (node: LexicalNode) => LexicalNode},
|
|
31
|
+
>,
|
|
29
32
|
theme?: EditorThemeClasses,
|
|
30
33
|
editorState?: InitialEditorStateType,
|
|
31
34
|
onError: (error: Error, editor: LexicalEditor) => void,
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
declare type
|
|
8
|
+
export declare type LexicalErrorBoundaryProps = {
|
|
9
9
|
children: JSX.Element;
|
|
10
10
|
onError: (error: Error) => void;
|
|
11
11
|
};
|
|
12
|
-
export default function LexicalErrorBoundary({ children, onError, }:
|
|
13
|
-
export {};
|
|
12
|
+
export default function LexicalErrorBoundary({ children, onError, }: LexicalErrorBoundaryProps): JSX.Element;
|
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
+
* @flow strict
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
|
-
type
|
|
10
|
-
children:
|
|
10
|
+
export type LexicalErrorBoundaryProps = $ReadOnly<{
|
|
11
|
+
children: React$Node,
|
|
11
12
|
onError: (error: Error) => void,
|
|
12
13
|
}>;
|
|
13
14
|
|
|
14
|
-
declare export default function LexicalErrorBoundary(
|
|
15
|
+
declare export default function LexicalErrorBoundary(
|
|
16
|
+
props: LexicalErrorBoundaryProps,
|
|
17
|
+
): React$Node;
|
|
@@ -132,7 +132,7 @@ function convertHorizontalRuleElement() {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
function $createHorizontalRuleNode() {
|
|
135
|
-
return new HorizontalRuleNode();
|
|
135
|
+
return lexical.$applyNodeReplacement(new HorizontalRuleNode());
|
|
136
136
|
}
|
|
137
137
|
function $isHorizontalRuleNode(node) {
|
|
138
138
|
return node instanceof HorizontalRuleNode;
|
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
function r({nodeKey:b}){let [f]=a.useLexicalComposerContext(),m=p.useRef(null),[e,g,n]=d.useLexicalNodeSelection(b),k=p.useCallback(c=>{e&&l.$isNodeSelection(l.$getSelection())&&(c.preventDefault(),c=l.$getNodeByKey(b),t(c)&&c.remove(),g(!1));return!1},[e,b,g]);p.useEffect(()=>h.mergeRegister(f.registerCommand(l.CLICK_COMMAND,c=>c.target===m.current?(c.shiftKey||n(),g(!e),!0):!1,l.COMMAND_PRIORITY_LOW),f.registerCommand(l.KEY_DELETE_COMMAND,k,l.COMMAND_PRIORITY_LOW),f.registerCommand(l.KEY_BACKSPACE_COMMAND,
|
|
9
9
|
k,l.COMMAND_PRIORITY_LOW)),[n,f,e,k,g]);return p.createElement("hr",{ref:m,className:e?"selected":void 0})}
|
|
10
10
|
class u extends l.DecoratorNode{static getType(){return"horizontalrule"}static clone(b){return new u(b.__key)}static importJSON(){return v()}static importDOM(){return{hr:()=>({conversion:w,priority:0})}}exportJSON(){return{type:"horizontalrule",version:1}}exportDOM(){return{element:document.createElement("hr")}}createDOM(){let b=document.createElement("div");b.style.display="contents";return b}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}decorate(){return p.createElement(r,{nodeKey:this.__key})}}
|
|
11
|
-
function w(){return{node:v()}}function v(){return new u}function t(b){return b instanceof u}exports.$createHorizontalRuleNode=v;exports.$isHorizontalRuleNode=t;exports.HorizontalRuleNode=u;exports.INSERT_HORIZONTAL_RULE_COMMAND=q
|
|
11
|
+
function w(){return{node:v()}}function v(){return l.$applyNodeReplacement(new u)}function t(b){return b instanceof u}exports.$createHorizontalRuleNode=v;exports.$isHorizontalRuleNode=t;exports.HorizontalRuleNode=u;exports.INSERT_HORIZONTAL_RULE_COMMAND=q
|
package/LexicalLinkPlugin.d.ts
CHANGED
|
@@ -5,4 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
declare type Props = {
|
|
9
|
+
validateUrl?: (url: string) => boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function LinkPlugin({ validateUrl }: Props): null;
|
|
12
|
+
export {};
|
package/LexicalLinkPlugin.dev.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
var link = require('@lexical/link');
|
|
10
10
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
11
|
+
var utils = require('@lexical/utils');
|
|
11
12
|
var lexical = require('lexical');
|
|
12
13
|
var react = require('react');
|
|
13
14
|
|
|
@@ -18,17 +19,26 @@ var react = require('react');
|
|
|
18
19
|
* LICENSE file in the root directory of this source tree.
|
|
19
20
|
*
|
|
20
21
|
*/
|
|
21
|
-
function LinkPlugin(
|
|
22
|
+
function LinkPlugin({
|
|
23
|
+
validateUrl
|
|
24
|
+
}) {
|
|
22
25
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
23
26
|
react.useEffect(() => {
|
|
24
27
|
if (!editor.hasNodes([link.LinkNode])) {
|
|
25
28
|
throw new Error('LinkPlugin: LinkNode not registered on editor');
|
|
26
29
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (typeof payload === 'string' || payload === null) {
|
|
30
|
+
|
|
31
|
+
return utils.mergeRegister(editor.registerCommand(link.TOGGLE_LINK_COMMAND, payload => {
|
|
32
|
+
if (payload === null) {
|
|
31
33
|
link.toggleLink(payload);
|
|
34
|
+
return true;
|
|
35
|
+
} else if (typeof payload === 'string') {
|
|
36
|
+
if (validateUrl === undefined || validateUrl(payload)) {
|
|
37
|
+
link.toggleLink(payload);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return false;
|
|
32
42
|
} else {
|
|
33
43
|
const {
|
|
34
44
|
url,
|
|
@@ -39,11 +49,27 @@ function LinkPlugin() {
|
|
|
39
49
|
rel,
|
|
40
50
|
target
|
|
41
51
|
});
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}, lexical.COMMAND_PRIORITY_LOW), validateUrl !== undefined ? editor.registerCommand(lexical.PASTE_COMMAND, event => {
|
|
55
|
+
const selection = lexical.$getSelection();
|
|
56
|
+
|
|
57
|
+
if (!lexical.$isRangeSelection(selection) || selection.isCollapsed() || !(event instanceof ClipboardEvent) || event.clipboardData == null) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const clipboardText = event.clipboardData.getData('text');
|
|
62
|
+
|
|
63
|
+
if (!validateUrl(clipboardText)) {
|
|
64
|
+
return false;
|
|
42
65
|
}
|
|
43
66
|
|
|
67
|
+
editor.dispatchCommand(link.TOGGLE_LINK_COMMAND, clipboardText);
|
|
68
|
+
event.preventDefault();
|
|
44
69
|
return true;
|
|
45
|
-
}, lexical.
|
|
46
|
-
|
|
70
|
+
}, lexical.COMMAND_PRIORITY_LOW) : () => {// Don't paste arbritrary text as a link when there's no validate function
|
|
71
|
+
});
|
|
72
|
+
}, [editor, validateUrl]);
|
|
47
73
|
return null;
|
|
48
74
|
}
|
|
49
75
|
|
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var
|
|
8
|
-
exports.LinkPlugin=function(){let [
|
|
7
|
+
'use strict';var c=require("@lexical/link"),d=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/utils"),h=require("lexical"),k=require("react");
|
|
8
|
+
exports.LinkPlugin=function({validateUrl:e}){let [f]=d.useLexicalComposerContext();k.useEffect(()=>{if(!f.hasNodes([c.LinkNode]))throw Error("LinkPlugin: LinkNode not registered on editor");return g.mergeRegister(f.registerCommand(c.TOGGLE_LINK_COMMAND,a=>{if(null===a)return c.toggleLink(a),!0;if("string"===typeof a)return void 0===e||e(a)?(c.toggleLink(a),!0):!1;let {url:b,target:l,rel:m}=a;c.toggleLink(b,{rel:m,target:l});return!0},h.COMMAND_PRIORITY_LOW),void 0!==e?f.registerCommand(h.PASTE_COMMAND,
|
|
9
|
+
a=>{var b=h.$getSelection();if(!h.$isRangeSelection(b)||b.isCollapsed()||!(a instanceof ClipboardEvent)||null==a.clipboardData)return!1;b=a.clipboardData.getData("text");if(!e(b))return!1;f.dispatchCommand(c.TOGGLE_LINK_COMMAND,b);a.preventDefault();return!0},h.COMMAND_PRIORITY_LOW):()=>{})},[f,e]);return null}
|
|
@@ -50,6 +50,7 @@ function LexicalNestedComposer({
|
|
|
50
50
|
for (const [type, entry] of parentNodes) {
|
|
51
51
|
initialEditor._nodes.set(type, {
|
|
52
52
|
klass: entry.klass,
|
|
53
|
+
replace: entry.replace,
|
|
53
54
|
transforms: new Set()
|
|
54
55
|
});
|
|
55
56
|
}
|
|
@@ -59,6 +60,7 @@ function LexicalNestedComposer({
|
|
|
59
60
|
|
|
60
61
|
initialEditor._nodes.set(type, {
|
|
61
62
|
klass,
|
|
63
|
+
replace: null,
|
|
62
64
|
transforms: new Set()
|
|
63
65
|
});
|
|
64
66
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var b=require("@lexical/react/LexicalCollaborationContext"),e=require("@lexical/react/LexicalComposerContext"),
|
|
8
|
-
exports.LexicalNestedComposer=function({initialEditor:a,children:
|
|
9
|
-
c&&(a._config.theme=c);a._parentEditor=g;if(k)for(var d of k)c=d.getType(),a._nodes.set(c,{klass:d,transforms:new Set});else{d=a._nodes=new Map(g._nodes);for(const [
|
|
7
|
+
'use strict';var b=require("@lexical/react/LexicalCollaborationContext"),e=require("@lexical/react/LexicalComposerContext"),n=require("react");
|
|
8
|
+
exports.LexicalNestedComposer=function({initialEditor:a,children:p,initialNodes:k,initialTheme:q,skipCollabChecks:r}){let l=n.useRef(!1),f=n.useContext(e.LexicalComposerContext);if(null==f)throw Error("Minified Lexical error #9; visit https://lexical.dev/docs/error?code=9 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");let w=n.useMemo(()=>{const [g,t]=f;var c=q||t.getTheme()||void 0;const u=e.createLexicalComposerContext(f,c);void 0!==
|
|
9
|
+
c&&(a._config.theme=c);a._parentEditor=g;if(k)for(var d of k)c=d.getType(),a._nodes.set(c,{klass:d,replace:null,transforms:new Set});else{d=a._nodes=new Map(g._nodes);for(const [v,m]of d)a._nodes.set(v,{klass:m.klass,replace:m.replace,transforms:new Set})}a._config.namespace=g._config.namespace;return[a,u]},[]),{isCollabActive:x,yjsDocMap:y}=b.useCollaborationContext(),h=r||l.current||y.has(a.getKey());n.useEffect(()=>{h&&(l.current=!0)},[h]);return n.createElement(e.LexicalComposerContext.Provider,
|
|
10
|
+
{value:w},!x||h?p:null)}
|
|
@@ -545,11 +545,9 @@ function LexicalTypeaheadMenuPlugin({
|
|
|
545
545
|
}
|
|
546
546
|
}, [onOpen, resolution]);
|
|
547
547
|
React.useEffect(() => {
|
|
548
|
-
let activeRange = document.createRange();
|
|
549
|
-
|
|
550
548
|
const updateListener = () => {
|
|
551
549
|
editor.getEditorState().read(() => {
|
|
552
|
-
const range =
|
|
550
|
+
const range = document.createRange();
|
|
553
551
|
const selection = lexical.$getSelection();
|
|
554
552
|
const text = getQueryTextForSearch(editor);
|
|
555
553
|
|
|
@@ -579,7 +577,6 @@ function LexicalTypeaheadMenuPlugin({
|
|
|
579
577
|
|
|
580
578
|
const removeUpdateListener = editor.registerUpdateListener(updateListener);
|
|
581
579
|
return () => {
|
|
582
|
-
activeRange = null;
|
|
583
580
|
removeUpdateListener();
|
|
584
581
|
};
|
|
585
582
|
}, [editor, triggerFn, onQueryChange, resolution, closeTypeahead, openTypeahead]);
|
|
@@ -4,23 +4,23 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var k=require("@lexical/react/LexicalComposerContext"),n=require("@lexical/utils"),w=require("lexical"),x=require("react"),
|
|
8
|
-
let
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
function
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
function
|
|
16
|
-
[a]);
|
|
17
|
-
a.registerCommand(w.KEY_ARROW_UP_COMMAND,h=>{if(null!==f&&f.length&&null!==g){var
|
|
18
|
-
|
|
19
|
-
function
|
|
20
|
-
"listbox"),d.style.display="block",d.style.position="absolute",document.body.append(d));f.current=d;g.setAttribute("aria-controls","typeahead-menu")}},[e,b,c]);x.useEffect(()=>{let g=e.getRootElement();if(null!==b)return q(),()=>{null!==g&&g.removeAttribute("aria-controls");let d=f.current;null!==d&&d.isConnected&&d.remove()}},[e,q,b]);let p=x.useCallback(g=>{null!==b&&(g||a(null))},[b,a]);
|
|
21
|
-
exports.LexicalNodeMenuPlugin=function({options:b,nodeKey:a,onClose:c,onOpen:e,onSelectOption:f,menuRenderFn:q,anchorClassName:p}){let [g]=k.useLexicalComposerContext(),[d,
|
|
22
|
-
match:{leadOffset:u.length,matchingString:u,replaceableString:u}}))}}):null==a&&null!=d&&r()},[r,g,a,t,d]);return null===d||null===g?null:x.createElement(
|
|
23
|
-
exports.LexicalTypeaheadMenuPlugin=function({options:b,onQueryChange:a,onSelectOption:c,onOpen:e,onClose:f,menuRenderFn:q,triggerFn:p,anchorClassName:g}){let [d]=k.useLexicalComposerContext(),[
|
|
24
|
-
|
|
25
|
-
exports.SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND=
|
|
26
|
-
exports.useDynamicPositioning=
|
|
7
|
+
'use strict';var k=require("@lexical/react/LexicalComposerContext"),n=require("@lexical/utils"),w=require("lexical"),x=require("react"),y="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?x.useLayoutEffect:x.useEffect;class z{constructor(b){this.key=b;this.ref={current:null};this.setRefElement=this.setRefElement.bind(this)}setRefElement(b){this.ref={current:b}}}
|
|
8
|
+
let A=b=>{var a=document.getElementById("typeahead-menu");if(a){a=a.getBoundingClientRect();const c=b.getBoundingClientRect();c.bottom>a.bottom?b.scrollIntoView(!1):c.top<a.top&&b.scrollIntoView()}};function B(b,a){var c=window.getSelection();if(null===c||!c.isCollapsed)return!1;let e=c.anchorNode;c=c.anchorOffset;if(null==e||null==c)return!1;try{a.setStart(e,b),a.setEnd(e,c)}catch(f){return!1}return!0}
|
|
9
|
+
function C(b){let a=null;b.getEditorState().read(()=>{var c=w.$getSelection();if(w.$isRangeSelection(c)){var e=c.anchor;"text"!==e.type?a=null:(c=e.getNode(),c.isSimpleText()?(e=e.offset,a=c.getTextContent().slice(0,e)):a=null)}});return a}
|
|
10
|
+
function D(b,a){b=w.$getSelection();if(!w.$isRangeSelection(b)||!b.isCollapsed())return null;var c=b.anchor;if("text"!==c.type)return null;b=c.getNode();if(!b.isSimpleText())return null;c=c.offset;let e=b.getTextContent().slice(0,c);var f=a.matchingString;a=a.replaceableString.length;for(let p=a;p<=f.length;p++)e.substr(-p)===f.substr(0,p)&&(a=p);a=c-a;if(0>a)return null;let q;0===a?[q]=b.splitText(c):[,q]=b.splitText(a,c);return q}
|
|
11
|
+
function E(b,a){return 0!==a?!1:b.getEditorState().read(()=>{var c=w.$getSelection();return w.$isRangeSelection(c)?(c=c.anchor.getNode().getPreviousSibling(),w.$isTextNode(c)&&c.isTextEntity()):!1})}function F(b){x.startTransition?x.startTransition(b):b()}
|
|
12
|
+
function I(b,a){let c=getComputedStyle(b),e="absolute"===c.position;a=a?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===c.position)return document.body;for(;b=b.parentElement;)if(c=getComputedStyle(b),(!e||"static"!==c.position)&&a.test(c.overflow+c.overflowY+c.overflowX))return b;return document.body}function J(b,a){b=b.getBoundingClientRect();a=a.getBoundingClientRect();return b.top>a.top&&b.top<a.bottom}
|
|
13
|
+
function K(b,a,c,e){let [f]=k.useLexicalComposerContext();x.useEffect(()=>{if(null!=a&&null!=b){let q=f.getRootElement(),p=null!=q?I(q,!1):document.body,g=!1,d=J(a,p),l=function(){g||(window.requestAnimationFrame(function(){c();g=!1}),g=!0);const t=J(a,p);t!==d&&(d=t,null!=e&&e(t))},r=new ResizeObserver(c);window.addEventListener("resize",c);document.addEventListener("scroll",l,{capture:!0,passive:!0});r.observe(a);return()=>{r.unobserve(a);window.removeEventListener("resize",c);document.removeEventListener("scroll",
|
|
14
|
+
l)}}},[a,f,e,c,b])}let L=w.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
|
|
15
|
+
function M({close:b,editor:a,anchorElementRef:c,resolution:e,options:f,menuRenderFn:q,onSelectOption:p}){let [g,d]=x.useState(null);x.useEffect(()=>{d(0)},[e.match.matchingString]);let l=x.useCallback(h=>{a.update(()=>{const m=D(a,e.match);p(h,m,b,e.match.matchingString)})},[b,a,e.match,p]),r=x.useCallback(h=>{const m=a.getRootElement();null!==m&&(m.setAttribute("aria-activedescendant","typeahead-item-"+h),d(h))},[a]);x.useEffect(()=>()=>{let h=a.getRootElement();null!==h&&h.removeAttribute("aria-activedescendant")},
|
|
16
|
+
[a]);y(()=>{null===f?d(null):null===g&&r(0)},[f,g,r]);x.useEffect(()=>n.mergeRegister(a.registerCommand(L,({option:h})=>h.ref&&null!=h.ref.current?(A(h.ref.current),!0):!1,w.COMMAND_PRIORITY_LOW)),[a,r]);x.useEffect(()=>n.mergeRegister(a.registerCommand(w.KEY_ARROW_DOWN_COMMAND,h=>{if(null!==f&&f.length&&null!==g){let m=g!==f.length-1?g+1:0;r(m);let u=f[m];null!=u.ref&&u.ref.current&&a.dispatchCommand(L,{index:m,option:u});h.preventDefault();h.stopImmediatePropagation()}return!0},w.COMMAND_PRIORITY_CRITICAL),
|
|
17
|
+
a.registerCommand(w.KEY_ARROW_UP_COMMAND,h=>{if(null!==f&&f.length&&null!==g){var m=0!==g?g-1:f.length-1;r(m);m=f[m];null!=m.ref&&m.ref.current&&A(m.ref.current);h.preventDefault();h.stopImmediatePropagation()}return!0},w.COMMAND_PRIORITY_CRITICAL),a.registerCommand(w.KEY_ESCAPE_COMMAND,h=>{h.preventDefault();h.stopImmediatePropagation();b();return!0},w.COMMAND_PRIORITY_CRITICAL),a.registerCommand(w.KEY_TAB_COMMAND,h=>{if(null===f||null===g||null==f[g])return!1;h.preventDefault();h.stopImmediatePropagation();
|
|
18
|
+
l(f[g]);return!0},w.COMMAND_PRIORITY_CRITICAL),a.registerCommand(w.KEY_ENTER_COMMAND,h=>{if(null===f||null===g||null==f[g])return!1;null!==h&&(h.preventDefault(),h.stopImmediatePropagation());l(f[g]);return!0},w.COMMAND_PRIORITY_CRITICAL)),[l,b,a,f,g,r]);let t=x.useMemo(()=>({options:f,selectOptionAndCleanUp:l,selectedIndex:g,setHighlightedIndex:d}),[l,g,f]);return q(c,t,e.match.matchingString)}
|
|
19
|
+
function N(b,a,c){let [e]=k.useLexicalComposerContext(),f=x.useRef(document.createElement("div")),q=x.useCallback(()=>{const g=e.getRootElement(),d=f.current;if(null!==g&&null!==b){const {left:l,top:r,width:t,height:h}=b.getRect();d.style.top=`${r+window.pageYOffset}px`;d.style.left=`${l+window.pageXOffset}px`;d.style.height=`${h}px`;d.style.width=`${t}px`;d.isConnected||(null!=c&&(d.className=c),d.setAttribute("aria-label","Typeahead menu"),d.setAttribute("id","typeahead-menu"),d.setAttribute("role",
|
|
20
|
+
"listbox"),d.style.display="block",d.style.position="absolute",document.body.append(d));f.current=d;g.setAttribute("aria-controls","typeahead-menu")}},[e,b,c]);x.useEffect(()=>{let g=e.getRootElement();if(null!==b)return q(),()=>{null!==g&&g.removeAttribute("aria-controls");let d=f.current;null!==d&&d.isConnected&&d.remove()}},[e,q,b]);let p=x.useCallback(g=>{null!==b&&(g||a(null))},[b,a]);K(b,f.current,q,p);return f}
|
|
21
|
+
exports.LexicalNodeMenuPlugin=function({options:b,nodeKey:a,onClose:c,onOpen:e,onSelectOption:f,menuRenderFn:q,anchorClassName:p}){let [g]=k.useLexicalComposerContext(),[d,l]=x.useState(null);p=N(d,l,p);let r=x.useCallback(()=>{l(null);null!=c&&null!==d&&c()},[c,d]),t=x.useCallback(h=>{l(h);null!=e&&null===d&&e(h)},[e,d]);x.useEffect(()=>{a&&null==d?g.update(()=>{let h=w.$getNodeByKey(a),m=g.getElementByKey(a);if(null!=h&&null!=m){let u=h.getTextContent();F(()=>t({getRect:()=>m.getBoundingClientRect(),
|
|
22
|
+
match:{leadOffset:u.length,matchingString:u,replaceableString:u}}))}}):null==a&&null!=d&&r()},[r,g,a,t,d]);return null===d||null===g?null:x.createElement(M,{close:r,resolution:d,editor:g,anchorElementRef:p,options:b,menuRenderFn:q,onSelectOption:f})};
|
|
23
|
+
exports.LexicalTypeaheadMenuPlugin=function({options:b,onQueryChange:a,onSelectOption:c,onOpen:e,onClose:f,menuRenderFn:q,triggerFn:p,anchorClassName:g}){let [d]=k.useLexicalComposerContext(),[l,r]=x.useState(null);g=N(l,r,g);let t=x.useCallback(()=>{r(null);null!=f&&null!==l&&f()},[f,l]),h=x.useCallback(m=>{r(m);null!=e&&null===l&&e(m)},[e,l]);x.useEffect(()=>{let m=d.registerUpdateListener(()=>{d.getEditorState().read(()=>{const u=document.createRange(),G=w.$getSelection(),H=C(d);if(w.$isRangeSelection(G)&&
|
|
24
|
+
G.isCollapsed()&&null!==H&&null!==u){var v=p(H,d);a(v?v.matchingString:null);null===v||E(d,v.leadOffset)||null===B(v.leadOffset,u)?t():F(()=>h({getRect:()=>u.getBoundingClientRect(),match:v}))}else t()})});return()=>{m()}},[d,p,a,l,t,h]);return null===l||null===d?null:x.createElement(M,{close:t,resolution:l,editor:d,anchorElementRef:g,options:b,menuRenderFn:q,onSelectOption:c})};exports.PUNCTUATION="\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";
|
|
25
|
+
exports.SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND=L;exports.TypeaheadOption=z;exports.getScrollParent=I;exports.useBasicTypeaheadTriggerMatch=function(b,{minLength:a=1,maxLength:c=75}){return x.useCallback(e=>{e=(new RegExp("(^|\\s|\\()(["+b+"]((?:[^"+(b+"\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;\\s]){0,")+c+"}))$")).exec(e);if(null!==e){let f=e[1],q=e[3];if(q.length>=a)return{leadOffset:e.index+f.length,matchingString:q,replaceableString:e[2]}}return null},[c,a,b])};
|
|
26
|
+
exports.useDynamicPositioning=K
|
package/package.json
CHANGED
|
@@ -8,29 +8,29 @@
|
|
|
8
8
|
"rich-text"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.6.
|
|
11
|
+
"version": "0.6.2",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.6.
|
|
14
|
-
"@lexical/code": "0.6.
|
|
15
|
-
"@lexical/dragon": "0.6.
|
|
16
|
-
"@lexical/hashtag": "0.6.
|
|
17
|
-
"@lexical/history": "0.6.
|
|
18
|
-
"@lexical/link": "0.6.
|
|
19
|
-
"@lexical/list": "0.6.
|
|
20
|
-
"@lexical/mark": "0.6.
|
|
21
|
-
"@lexical/markdown": "0.6.
|
|
22
|
-
"@lexical/overflow": "0.6.
|
|
23
|
-
"@lexical/plain-text": "0.6.
|
|
24
|
-
"@lexical/rich-text": "0.6.
|
|
25
|
-
"@lexical/selection": "0.6.
|
|
26
|
-
"@lexical/table": "0.6.
|
|
27
|
-
"@lexical/text": "0.6.
|
|
28
|
-
"@lexical/utils": "0.6.
|
|
29
|
-
"@lexical/yjs": "0.6.
|
|
13
|
+
"@lexical/clipboard": "0.6.2",
|
|
14
|
+
"@lexical/code": "0.6.2",
|
|
15
|
+
"@lexical/dragon": "0.6.2",
|
|
16
|
+
"@lexical/hashtag": "0.6.2",
|
|
17
|
+
"@lexical/history": "0.6.2",
|
|
18
|
+
"@lexical/link": "0.6.2",
|
|
19
|
+
"@lexical/list": "0.6.2",
|
|
20
|
+
"@lexical/mark": "0.6.2",
|
|
21
|
+
"@lexical/markdown": "0.6.2",
|
|
22
|
+
"@lexical/overflow": "0.6.2",
|
|
23
|
+
"@lexical/plain-text": "0.6.2",
|
|
24
|
+
"@lexical/rich-text": "0.6.2",
|
|
25
|
+
"@lexical/selection": "0.6.2",
|
|
26
|
+
"@lexical/table": "0.6.2",
|
|
27
|
+
"@lexical/text": "0.6.2",
|
|
28
|
+
"@lexical/utils": "0.6.2",
|
|
29
|
+
"@lexical/yjs": "0.6.2",
|
|
30
30
|
"react-error-boundary": "^3.1.4"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"lexical": "0.6.
|
|
33
|
+
"lexical": "0.6.2",
|
|
34
34
|
"react": ">=17.x",
|
|
35
35
|
"react-dom": ">=17.x"
|
|
36
36
|
},
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
*/
|
|
8
|
-
declare type Props = Readonly<{
|
|
9
|
-
scrollRef: {
|
|
10
|
-
current: HTMLElement | null;
|
|
11
|
-
};
|
|
12
|
-
}>;
|
|
13
|
-
export declare function AutoScrollPlugin({ scrollRef }: Props): JSX.Element | null;
|
|
14
|
-
export {};
|
|
@@ -1,79 +0,0 @@
|
|
|
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 lexical = require('lexical');
|
|
11
|
-
var react = require('react');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
|
-
*
|
|
16
|
-
* This source code is licensed under the MIT license found in the
|
|
17
|
-
* LICENSE file in the root directory of this source tree.
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
24
|
-
*
|
|
25
|
-
* This source code is licensed under the MIT license found in the
|
|
26
|
-
* LICENSE file in the root directory of this source tree.
|
|
27
|
-
*
|
|
28
|
-
*/
|
|
29
|
-
const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
|
|
30
|
-
var useLayoutEffect = useLayoutEffectImpl;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
34
|
-
*
|
|
35
|
-
* This source code is licensed under the MIT license found in the
|
|
36
|
-
* LICENSE file in the root directory of this source tree.
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
|
-
function AutoScrollPlugin({
|
|
40
|
-
scrollRef
|
|
41
|
-
}) {
|
|
42
|
-
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
43
|
-
useLayoutEffect(() => {
|
|
44
|
-
return editor.registerUpdateListener(({
|
|
45
|
-
tags,
|
|
46
|
-
editorState
|
|
47
|
-
}) => {
|
|
48
|
-
const scrollElement = scrollRef.current;
|
|
49
|
-
|
|
50
|
-
if (scrollElement === null || !tags.has('scroll-into-view')) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const selection = editorState.read(() => lexical.$getSelection());
|
|
55
|
-
|
|
56
|
-
if (!lexical.$isRangeSelection(selection) || !selection.isCollapsed()) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const anchorElement = editor.getElementByKey(selection.anchor.key);
|
|
61
|
-
|
|
62
|
-
if (anchorElement === null) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const scrollRect = scrollElement.getBoundingClientRect();
|
|
67
|
-
const rect = anchorElement.getBoundingClientRect();
|
|
68
|
-
|
|
69
|
-
if (rect.bottom > scrollRect.bottom) {
|
|
70
|
-
anchorElement.scrollIntoView(false);
|
|
71
|
-
} else if (rect.top < scrollRect.top) {
|
|
72
|
-
anchorElement.scrollIntoView();
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}, [editor, scrollRef]);
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
exports.AutoScrollPlugin = AutoScrollPlugin;
|
|
@@ -1,9 +0,0 @@
|
|
|
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 LexicalAutoScrollPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalAutoScrollPlugin.dev.js') : require('./LexicalAutoScrollPlugin.prod.js')
|
|
9
|
-
module.exports = LexicalAutoScrollPlugin;
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
type Props = $ReadOnly<{
|
|
10
|
-
scrollRef: {current: HTMLElement | null},
|
|
11
|
-
}>;
|
|
12
|
-
declare export function AutoScrollPlugin(props: Props): React$Node;
|
|
@@ -1,8 +0,0 @@
|
|
|
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 e=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),h=require("react"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
|
|
8
|
-
exports.AutoScrollPlugin=function({scrollRef:g}){let [d]=e.useLexicalComposerContext();k(()=>d.registerUpdateListener(({tags:a,editorState:c})=>{var b=g.current;null!==b&&a.has("scroll-into-view")&&(a=c.read(()=>f.$getSelection()),f.$isRangeSelection(a)&&a.isCollapsed()&&(a=d.getElementByKey(a.anchor.key),null!==a&&(b=b.getBoundingClientRect(),c=a.getBoundingClientRect(),c.bottom>b.bottom?a.scrollIntoView(!1):c.top<b.top&&a.scrollIntoView())))}),[d,g]);return null}
|