@lexical/react 0.15.0 → 0.16.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.
- package/LexicalAutoEmbedPlugin.dev.js +12 -24
- package/LexicalAutoEmbedPlugin.dev.mjs +2 -2
- package/LexicalAutoEmbedPlugin.prod.js +4 -5
- package/LexicalAutoEmbedPlugin.prod.mjs +1 -1
- package/LexicalBlockWithAlignableContents.dev.js +9 -20
- package/LexicalBlockWithAlignableContents.dev.mjs +5 -4
- package/LexicalBlockWithAlignableContents.prod.js +4 -4
- package/LexicalBlockWithAlignableContents.prod.mjs +1 -1
- package/LexicalCharacterLimitPlugin.dev.js +10 -22
- package/LexicalCharacterLimitPlugin.dev.mjs +5 -5
- package/LexicalCharacterLimitPlugin.prod.js +9 -9
- package/LexicalCharacterLimitPlugin.prod.mjs +1 -1
- package/LexicalCheckListPlugin.dev.js +2 -0
- package/LexicalCheckListPlugin.dev.mjs +2 -0
- package/LexicalCheckListPlugin.prod.js +2 -2
- package/LexicalCheckListPlugin.prod.mjs +1 -1
- package/LexicalClearEditorPlugin.dev.js +4 -0
- package/LexicalClearEditorPlugin.dev.mjs +4 -0
- package/LexicalClickableLinkPlugin.d.ts +3 -1
- package/LexicalClickableLinkPlugin.dev.js +3 -2
- package/LexicalClickableLinkPlugin.dev.mjs +2 -2
- package/LexicalClickableLinkPlugin.js.flow +3 -1
- package/LexicalClickableLinkPlugin.mjs +1 -0
- package/LexicalClickableLinkPlugin.node.mjs +1 -0
- package/LexicalClickableLinkPlugin.prod.js +4 -3
- package/LexicalClickableLinkPlugin.prod.mjs +1 -1
- package/LexicalCollaborationPlugin.dev.js +2 -1
- package/LexicalCollaborationPlugin.dev.mjs +2 -1
- package/LexicalCollaborationPlugin.prod.js +9 -9
- package/LexicalCollaborationPlugin.prod.mjs +1 -1
- package/LexicalComposer.dev.js +12 -19
- package/LexicalComposer.dev.mjs +9 -4
- package/LexicalComposer.prod.js +3 -4
- package/LexicalComposer.prod.mjs +1 -1
- package/LexicalContentEditable.dev.js +20 -34
- package/LexicalContentEditable.dev.mjs +16 -18
- package/LexicalContentEditable.prod.js +3 -4
- package/LexicalContentEditable.prod.mjs +1 -1
- package/LexicalContextMenuPlugin.dev.js +6 -1
- package/LexicalContextMenuPlugin.dev.mjs +6 -1
- package/LexicalContextMenuPlugin.prod.js +15 -15
- package/LexicalContextMenuPlugin.prod.mjs +1 -1
- package/LexicalErrorBoundary.d.ts +3 -1
- package/LexicalErrorBoundary.dev.js +11 -7
- package/LexicalErrorBoundary.dev.mjs +10 -7
- package/LexicalErrorBoundary.js.flow +4 -1
- package/LexicalErrorBoundary.mjs +1 -0
- package/LexicalErrorBoundary.node.mjs +1 -0
- package/LexicalErrorBoundary.prod.js +4 -4
- package/LexicalErrorBoundary.prod.mjs +1 -1
- package/LexicalHorizontalRuleNode.d.ts +2 -2
- package/LexicalHorizontalRuleNode.dev.js +16 -21
- package/LexicalHorizontalRuleNode.dev.mjs +13 -6
- package/LexicalHorizontalRuleNode.prod.js +5 -5
- package/LexicalHorizontalRuleNode.prod.mjs +1 -1
- package/LexicalNestedComposer.dev.js +11 -22
- package/LexicalNestedComposer.dev.mjs +5 -4
- package/LexicalNestedComposer.prod.js +5 -5
- package/LexicalNestedComposer.prod.mjs +1 -1
- package/LexicalNodeMenuPlugin.dev.js +6 -1
- package/LexicalNodeMenuPlugin.dev.mjs +6 -1
- package/LexicalNodeMenuPlugin.prod.js +13 -13
- package/LexicalNodeMenuPlugin.prod.mjs +1 -1
- package/LexicalOnChangePlugin.dev.js +4 -0
- package/LexicalOnChangePlugin.dev.mjs +4 -0
- package/LexicalPlainTextPlugin.dev.js +24 -28
- package/LexicalPlainTextPlugin.dev.mjs +19 -11
- package/LexicalPlainTextPlugin.js.flow +1 -1
- package/LexicalPlainTextPlugin.prod.js +4 -4
- package/LexicalPlainTextPlugin.prod.mjs +1 -1
- package/LexicalRichTextPlugin.dev.js +24 -28
- package/LexicalRichTextPlugin.dev.mjs +19 -11
- package/LexicalRichTextPlugin.js.flow +1 -1
- package/LexicalRichTextPlugin.prod.js +4 -4
- package/LexicalRichTextPlugin.prod.mjs +1 -1
- package/LexicalTableOfContents.d.ts +6 -13
- package/LexicalTableOfContents.dev.js +10 -2
- package/LexicalTableOfContents.dev.mjs +10 -2
- package/LexicalTableOfContents.js.flow +3 -7
- package/LexicalTableOfContents.prod.js +1 -1
- package/LexicalTableOfContentsPlugin.d.ts +20 -0
- package/LexicalTableOfContentsPlugin.dev.js +198 -0
- package/LexicalTableOfContentsPlugin.dev.mjs +196 -0
- package/LexicalTableOfContentsPlugin.js +11 -0
- package/LexicalTableOfContentsPlugin.js.flow +18 -0
- package/LexicalTableOfContentsPlugin.mjs +12 -0
- package/LexicalTableOfContentsPlugin.node.mjs +10 -0
- package/LexicalTableOfContentsPlugin.prod.js +12 -0
- package/LexicalTableOfContentsPlugin.prod.mjs +9 -0
- package/LexicalTreeView.d.ts +3 -1
- package/LexicalTreeView.dev.js +5 -3
- package/LexicalTreeView.dev.mjs +5 -3
- package/LexicalTreeView.js.flow +2 -0
- package/LexicalTreeView.prod.js +3 -3
- package/LexicalTreeView.prod.mjs +1 -1
- package/LexicalTypeaheadMenuPlugin.dev.js +6 -1
- package/LexicalTypeaheadMenuPlugin.dev.mjs +6 -1
- package/LexicalTypeaheadMenuPlugin.prod.js +17 -17
- package/LexicalTypeaheadMenuPlugin.prod.mjs +1 -1
- package/package.json +50 -20
- package/useLexicalEditable.d.ts +11 -1
- package/useLexicalEditable.dev.js +16 -1
- package/useLexicalEditable.dev.mjs +15 -1
- package/useLexicalEditable.js.flow +4 -1
- package/useLexicalEditable.mjs +2 -1
- package/useLexicalEditable.node.mjs +2 -1
- package/useLexicalEditable.prod.js +1 -1
- package/useLexicalEditable.prod.mjs +1 -1
- package/useLexicalIsTextContentEmpty.dev.js +4 -0
- package/useLexicalIsTextContentEmpty.dev.mjs +4 -0
- package/useLexicalSubscription.d.ts +4 -1
- package/useLexicalSubscription.dev.js +7 -1
- package/useLexicalSubscription.dev.mjs +6 -1
- package/useLexicalSubscription.js.flow +4 -1
- package/useLexicalSubscription.mjs +2 -1
- package/useLexicalSubscription.node.mjs +2 -1
- package/useLexicalSubscription.prod.js +2 -2
- package/useLexicalSubscription.prod.mjs +1 -1
|
@@ -10,4 +10,6 @@ export type LexicalErrorBoundaryProps = {
|
|
|
10
10
|
children: JSX.Element;
|
|
11
11
|
onError: (error: Error) => void;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export declare function LexicalErrorBoundary({ children, onError, }: LexicalErrorBoundaryProps): JSX.Element;
|
|
14
|
+
/** @deprecated use the named export {@link LexicalErrorBoundary} */
|
|
15
|
+
export default LexicalErrorBoundary;
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
11
|
var React = require('react');
|
|
12
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
12
13
|
|
|
13
14
|
function _interopNamespaceDefault(e) {
|
|
14
15
|
var n = Object.create(null);
|
|
@@ -160,16 +161,19 @@ function LexicalErrorBoundary({
|
|
|
160
161
|
children,
|
|
161
162
|
onError
|
|
162
163
|
}) {
|
|
163
|
-
return /*#__PURE__*/
|
|
164
|
-
fallback: /*#__PURE__*/
|
|
164
|
+
return /*#__PURE__*/jsxRuntime.jsx(ErrorBoundary, {
|
|
165
|
+
fallback: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
165
166
|
style: {
|
|
166
167
|
border: '1px solid #f00',
|
|
167
168
|
color: '#f00',
|
|
168
169
|
padding: '8px'
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
},
|
|
171
|
+
children: "An error was thrown."
|
|
172
|
+
}),
|
|
173
|
+
onError: onError,
|
|
174
|
+
children: children
|
|
175
|
+
});
|
|
173
176
|
}
|
|
174
177
|
|
|
175
|
-
|
|
178
|
+
exports.LexicalErrorBoundary = LexicalErrorBoundary;
|
|
179
|
+
exports.default = LexicalErrorBoundary;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import * as React from 'react';
|
|
10
|
+
import { jsx } from 'react/jsx-runtime';
|
|
10
11
|
|
|
11
12
|
function _setPrototypeOf(o, p) {
|
|
12
13
|
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
@@ -145,16 +146,18 @@ function LexicalErrorBoundary({
|
|
|
145
146
|
children,
|
|
146
147
|
onError
|
|
147
148
|
}) {
|
|
148
|
-
return /*#__PURE__*/
|
|
149
|
-
fallback: /*#__PURE__*/
|
|
149
|
+
return /*#__PURE__*/jsx(ErrorBoundary, {
|
|
150
|
+
fallback: /*#__PURE__*/jsx("div", {
|
|
150
151
|
style: {
|
|
151
152
|
border: '1px solid #f00',
|
|
152
153
|
color: '#f00',
|
|
153
154
|
padding: '8px'
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
},
|
|
156
|
+
children: "An error was thrown."
|
|
157
|
+
}),
|
|
158
|
+
onError: onError,
|
|
159
|
+
children: children
|
|
160
|
+
});
|
|
158
161
|
}
|
|
159
162
|
|
|
160
|
-
export { LexicalErrorBoundary as default };
|
|
163
|
+
export { LexicalErrorBoundary, LexicalErrorBoundary as default };
|
|
@@ -12,6 +12,9 @@ export type LexicalErrorBoundaryProps = $ReadOnly<{
|
|
|
12
12
|
onError: (error: Error) => void,
|
|
13
13
|
}>;
|
|
14
14
|
|
|
15
|
-
declare export
|
|
15
|
+
declare export function LexicalErrorBoundary(
|
|
16
16
|
props: LexicalErrorBoundaryProps,
|
|
17
17
|
): React$Node;
|
|
18
|
+
|
|
19
|
+
/** @deprecated use the named export {@link LexicalErrorBoundary} */
|
|
20
|
+
export default typeof LexicalErrorBoundary;
|
package/LexicalErrorBoundary.mjs
CHANGED
|
@@ -9,4 +9,5 @@
|
|
|
9
9
|
import * as modDev from './LexicalErrorBoundary.dev.mjs';
|
|
10
10
|
import * as modProd from './LexicalErrorBoundary.prod.mjs';
|
|
11
11
|
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
12
|
+
export const LexicalErrorBoundary = mod.LexicalErrorBoundary;
|
|
12
13
|
export default mod.default;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
'use strict';var h=require("react"),l=Object.create(null);if(h)for(var
|
|
10
|
-
var
|
|
11
|
-
e;null==(f=(e=this.props).onError)?void 0:f.call(e,a,d)};g.componentDidUpdate=function(a,d){var f=this.props.resetKeys;if(null!==this.state.error&&null!==d.error&&
|
|
12
|
-
typeof f)return f(a);if(e)return
|
|
9
|
+
'use strict';var h=require("react"),l=require("react/jsx-runtime"),n=Object.create(null);if(h)for(var p in h)n[p]=h[p];n.default=h;function q(b,c){q=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(g,a){g.__proto__=a;return g};return q(b,c)}function r(b,c){b.prototype=Object.create(c.prototype);b.prototype.constructor=b;q(b,c)}function v(b,c){void 0===b&&(b=[]);void 0===c&&(c=[]);return b.length!==c.length||b.some(function(g,a){return!Object.is(g,c[a])})}
|
|
10
|
+
var w={error:null},x=function(b){function c(){for(var a,d=arguments.length,f=Array(d),e=0;e<d;e++)f[e]=arguments[e];a=b.call.apply(b,[this].concat(f))||this;a.state=w;a.resetErrorBoundary=function(){for(var k,t=arguments.length,u=Array(t),m=0;m<t;m++)u[m]=arguments[m];null==a.props.onReset?void 0:(k=a.props).onReset.apply(k,u);a.reset()};return a}r(c,b);c.getDerivedStateFromError=function(a){return{error:a}};var g=c.prototype;g.reset=function(){this.setState(w)};g.componentDidCatch=function(a,d){var f,
|
|
11
|
+
e;null==(f=(e=this.props).onError)?void 0:f.call(e,a,d)};g.componentDidUpdate=function(a,d){var f=this.props.resetKeys;if(null!==this.state.error&&null!==d.error&&v(a.resetKeys,f)){var e,k;null==(e=(k=this.props).onResetKeysChange)?void 0:e.call(k,a.resetKeys,f);this.reset()}};g.render=function(){var a=this.state.error,d=this.props,f=d.fallbackRender,e=d.FallbackComponent;d=d.fallback;if(null!==a){a={error:a,resetErrorBoundary:this.resetErrorBoundary};if(n.isValidElement(d))return d;if("function"===
|
|
12
|
+
typeof f)return f(a);if(e)return n.createElement(e,a);throw Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop");}return this.props.children};return c}(n.Component);function y({children:b,onError:c}){return l.jsx(x,{fallback:l.jsx("div",{style:{border:"1px solid #f00",color:"#f00",padding:"8px"},children:"An error was thrown."}),onError:c,children:b})}exports.LexicalErrorBoundary=y;exports.default=y
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import*as r from"react";function
|
|
9
|
+
import*as r from"react";import{jsx as e}from"react/jsx-runtime";function t(r,e){return t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,e){return r.__proto__=e,r},t(r,e)}var o={error:null},n=function(e){var n,a;function s(){for(var r,t=arguments.length,n=new Array(t),a=0;a<t;a++)n[a]=arguments[a];return(r=e.call.apply(e,[this].concat(n))||this).state=o,r.resetErrorBoundary=function(){for(var e,t=arguments.length,o=new Array(t),n=0;n<t;n++)o[n]=arguments[n];null==r.props.onReset||(e=r.props).onReset.apply(e,o),r.reset()},r}a=e,(n=s).prototype=Object.create(a.prototype),n.prototype.constructor=n,t(n,a),s.getDerivedStateFromError=function(r){return{error:r}};var l=s.prototype;return l.reset=function(){this.setState(o)},l.componentDidCatch=function(r,e){var t,o;null==(t=(o=this.props).onError)||t.call(o,r,e)},l.componentDidUpdate=function(r,e){var t,o,n,a,s=this.state.error,l=this.props.resetKeys;null!==s&&null!==e.error&&(void 0===(n=r.resetKeys)&&(n=[]),void 0===(a=l)&&(a=[]),n.length!==a.length||n.some((function(r,e){return!Object.is(r,a[e])})))&&(null==(t=(o=this.props).onResetKeysChange)||t.call(o,r.resetKeys,l),this.reset())},l.render=function(){var e=this.state.error,t=this.props,o=t.fallbackRender,n=t.FallbackComponent,a=t.fallback;if(null!==e){var s={error:e,resetErrorBoundary:this.resetErrorBoundary};if(r.isValidElement(a))return a;if("function"==typeof o)return o(s);if(n)return r.createElement(n,s);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},s}(r.Component);function a({children:r,onError:t}){return e(n,{fallback:e("div",{style:{border:"1px solid #f00",color:"#f00",padding:"8px"},children:"An error was thrown."}),onError:t,children:r})}export{a as LexicalErrorBoundary,a as default};
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
/// <reference types="react" />
|
|
9
|
-
import type { DOMConversionMap, DOMExportOutput, LexicalCommand, LexicalNode, SerializedLexicalNode } from 'lexical';
|
|
9
|
+
import type { DOMConversionMap, DOMExportOutput, EditorConfig, LexicalCommand, LexicalNode, SerializedLexicalNode } from 'lexical';
|
|
10
10
|
import { DecoratorNode } from 'lexical';
|
|
11
11
|
export type SerializedHorizontalRuleNode = SerializedLexicalNode;
|
|
12
12
|
export declare const INSERT_HORIZONTAL_RULE_COMMAND: LexicalCommand<void>;
|
|
@@ -17,7 +17,7 @@ export declare class HorizontalRuleNode extends DecoratorNode<JSX.Element> {
|
|
|
17
17
|
static importDOM(): DOMConversionMap | null;
|
|
18
18
|
exportJSON(): SerializedLexicalNode;
|
|
19
19
|
exportDOM(): DOMExportOutput;
|
|
20
|
-
createDOM(): HTMLElement;
|
|
20
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
21
21
|
getTextContent(): string;
|
|
22
22
|
isInline(): false;
|
|
23
23
|
updateDOM(): boolean;
|
|
@@ -12,20 +12,8 @@ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
|
12
12
|
var useLexicalNodeSelection = require('@lexical/react/useLexicalNodeSelection');
|
|
13
13
|
var utils = require('@lexical/utils');
|
|
14
14
|
var lexical = require('lexical');
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
function _interopNamespaceDefault(e) {
|
|
18
|
-
var n = Object.create(null);
|
|
19
|
-
if (e) {
|
|
20
|
-
for (var k in e) {
|
|
21
|
-
n[k] = e[k];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
n.default = e;
|
|
25
|
-
return n;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
15
|
+
var react = require('react');
|
|
16
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
29
17
|
|
|
30
18
|
/**
|
|
31
19
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -41,7 +29,7 @@ function HorizontalRuleComponent({
|
|
|
41
29
|
}) {
|
|
42
30
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
43
31
|
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection.useLexicalNodeSelection(nodeKey);
|
|
44
|
-
const $onDelete =
|
|
32
|
+
const $onDelete = react.useCallback(event => {
|
|
45
33
|
if (isSelected && lexical.$isNodeSelection(lexical.$getSelection())) {
|
|
46
34
|
event.preventDefault();
|
|
47
35
|
const node = lexical.$getNodeByKey(nodeKey);
|
|
@@ -52,7 +40,7 @@ function HorizontalRuleComponent({
|
|
|
52
40
|
}
|
|
53
41
|
return false;
|
|
54
42
|
}, [isSelected, nodeKey]);
|
|
55
|
-
|
|
43
|
+
react.useEffect(() => {
|
|
56
44
|
return utils.mergeRegister(editor.registerCommand(lexical.CLICK_COMMAND, event => {
|
|
57
45
|
const hrElem = editor.getElementByKey(nodeKey);
|
|
58
46
|
if (event.target === hrElem) {
|
|
@@ -65,10 +53,15 @@ function HorizontalRuleComponent({
|
|
|
65
53
|
return false;
|
|
66
54
|
}, 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));
|
|
67
55
|
}, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected]);
|
|
68
|
-
|
|
56
|
+
react.useEffect(() => {
|
|
69
57
|
const hrElem = editor.getElementByKey(nodeKey);
|
|
58
|
+
const isSelectedClassName = 'selected';
|
|
70
59
|
if (hrElem !== null) {
|
|
71
|
-
|
|
60
|
+
if (isSelected) {
|
|
61
|
+
utils.addClassNamesToElement(hrElem, isSelectedClassName);
|
|
62
|
+
} else {
|
|
63
|
+
utils.removeClassNamesFromElement(hrElem, isSelectedClassName);
|
|
64
|
+
}
|
|
72
65
|
}
|
|
73
66
|
}, [editor, isSelected, nodeKey]);
|
|
74
67
|
return null;
|
|
@@ -102,8 +95,10 @@ class HorizontalRuleNode extends lexical.DecoratorNode {
|
|
|
102
95
|
element: document.createElement('hr')
|
|
103
96
|
};
|
|
104
97
|
}
|
|
105
|
-
createDOM() {
|
|
106
|
-
|
|
98
|
+
createDOM(config) {
|
|
99
|
+
const element = document.createElement('hr');
|
|
100
|
+
utils.addClassNamesToElement(element, config.theme.hr);
|
|
101
|
+
return element;
|
|
107
102
|
}
|
|
108
103
|
getTextContent() {
|
|
109
104
|
return '\n';
|
|
@@ -115,7 +110,7 @@ class HorizontalRuleNode extends lexical.DecoratorNode {
|
|
|
115
110
|
return false;
|
|
116
111
|
}
|
|
117
112
|
decorate() {
|
|
118
|
-
return /*#__PURE__*/
|
|
113
|
+
return /*#__PURE__*/jsxRuntime.jsx(HorizontalRuleComponent, {
|
|
119
114
|
nodeKey: this.__key
|
|
120
115
|
});
|
|
121
116
|
}
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
|
|
9
9
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
10
10
|
import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
|
|
11
|
-
import { mergeRegister } from '@lexical/utils';
|
|
11
|
+
import { addClassNamesToElement, mergeRegister, removeClassNamesFromElement } from '@lexical/utils';
|
|
12
12
|
import { createCommand, DecoratorNode, $applyNodeReplacement, $isNodeSelection, $getSelection, $getNodeByKey, CLICK_COMMAND, COMMAND_PRIORITY_LOW, KEY_DELETE_COMMAND, KEY_BACKSPACE_COMMAND } from 'lexical';
|
|
13
|
-
import * as React from 'react';
|
|
14
13
|
import { useCallback, useEffect } from 'react';
|
|
14
|
+
import { jsx } from 'react/jsx-runtime';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -53,8 +53,13 @@ function HorizontalRuleComponent({
|
|
|
53
53
|
}, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected]);
|
|
54
54
|
useEffect(() => {
|
|
55
55
|
const hrElem = editor.getElementByKey(nodeKey);
|
|
56
|
+
const isSelectedClassName = 'selected';
|
|
56
57
|
if (hrElem !== null) {
|
|
57
|
-
|
|
58
|
+
if (isSelected) {
|
|
59
|
+
addClassNamesToElement(hrElem, isSelectedClassName);
|
|
60
|
+
} else {
|
|
61
|
+
removeClassNamesFromElement(hrElem, isSelectedClassName);
|
|
62
|
+
}
|
|
58
63
|
}
|
|
59
64
|
}, [editor, isSelected, nodeKey]);
|
|
60
65
|
return null;
|
|
@@ -88,8 +93,10 @@ class HorizontalRuleNode extends DecoratorNode {
|
|
|
88
93
|
element: document.createElement('hr')
|
|
89
94
|
};
|
|
90
95
|
}
|
|
91
|
-
createDOM() {
|
|
92
|
-
|
|
96
|
+
createDOM(config) {
|
|
97
|
+
const element = document.createElement('hr');
|
|
98
|
+
addClassNamesToElement(element, config.theme.hr);
|
|
99
|
+
return element;
|
|
93
100
|
}
|
|
94
101
|
getTextContent() {
|
|
95
102
|
return '\n';
|
|
@@ -101,7 +108,7 @@ class HorizontalRuleNode extends DecoratorNode {
|
|
|
101
108
|
return false;
|
|
102
109
|
}
|
|
103
110
|
decorate() {
|
|
104
|
-
return /*#__PURE__*/
|
|
111
|
+
return /*#__PURE__*/jsx(HorizontalRuleComponent, {
|
|
105
112
|
nodeKey: this.__key
|
|
106
113
|
});
|
|
107
114
|
}
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
'use strict';var
|
|
10
|
-
function
|
|
11
|
-
k,h.COMMAND_PRIORITY_LOW)),[
|
|
12
|
-
class
|
|
13
|
-
function
|
|
9
|
+
'use strict';var b=require("@lexical/react/LexicalComposerContext"),f=require("@lexical/react/useLexicalNodeSelection"),g=require("@lexical/utils"),h=require("lexical"),l=require("react"),p=require("react/jsx-runtime");let q=h.createCommand("INSERT_HORIZONTAL_RULE_COMMAND");
|
|
10
|
+
function r({nodeKey:a}){let [d]=b.useLexicalComposerContext(),[e,m,n]=f.useLexicalNodeSelection(a),k=l.useCallback(c=>e&&h.$isNodeSelection(h.$getSelection())&&(c.preventDefault(),c=h.$getNodeByKey(a),t(c))?(c.remove(),!0):!1,[e,a]);l.useEffect(()=>g.mergeRegister(d.registerCommand(h.CLICK_COMMAND,c=>{let w=d.getElementByKey(a);return c.target===w?(c.shiftKey||n(),m(!e),!0):!1},h.COMMAND_PRIORITY_LOW),d.registerCommand(h.KEY_DELETE_COMMAND,k,h.COMMAND_PRIORITY_LOW),d.registerCommand(h.KEY_BACKSPACE_COMMAND,
|
|
11
|
+
k,h.COMMAND_PRIORITY_LOW)),[n,d,e,a,k,m]);l.useEffect(()=>{let c=d.getElementByKey(a);null!==c&&(e?g.addClassNamesToElement(c,"selected"):g.removeClassNamesFromElement(c,"selected"))},[d,e,a]);return null}
|
|
12
|
+
class u extends h.DecoratorNode{static getType(){return"horizontalrule"}static clone(a){return new u(a.__key)}static importJSON(){return v()}static importDOM(){return{hr:()=>({conversion:x,priority:0})}}exportJSON(){return{type:"horizontalrule",version:1}}exportDOM(){return{element:document.createElement("hr")}}createDOM(a){let d=document.createElement("hr");g.addClassNamesToElement(d,a.theme.hr);return d}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}decorate(){return p.jsx(r,
|
|
13
|
+
{nodeKey:this.__key})}}function x(){return{node:v()}}function v(){return h.$applyNodeReplacement(new u)}function t(a){return a instanceof u}exports.$createHorizontalRuleNode=v;exports.$isHorizontalRuleNode=t;exports.HorizontalRuleNode=u;exports.INSERT_HORIZONTAL_RULE_COMMAND=q
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLexicalNodeSelection as t}from"@lexical/react/useLexicalNodeSelection";import{mergeRegister as
|
|
9
|
+
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLexicalNodeSelection as t}from"@lexical/react/useLexicalNodeSelection";import{addClassNamesToElement as r,mergeRegister as n,removeClassNamesFromElement as o}from"@lexical/utils";import{createCommand as i,DecoratorNode as c,$applyNodeReplacement as u,$isNodeSelection as m,$getSelection as l,$getNodeByKey as a,CLICK_COMMAND as s,COMMAND_PRIORITY_LOW as p,KEY_DELETE_COMMAND as f,KEY_BACKSPACE_COMMAND as d}from"lexical";import{useCallback as x,useEffect as y}from"react";import{jsx as h}from"react/jsx-runtime";const O=i("INSERT_HORIZONTAL_RULE_COMMAND");function g({nodeKey:i}){const[c]=e(),[u,h,O]=t(i),g=x((e=>{if(u&&m(l())){e.preventDefault();const t=a(i);if(E(t))return t.remove(),!0}return!1}),[u,i]);return y((()=>n(c.registerCommand(s,(e=>{const t=c.getElementByKey(i);return e.target===t&&(e.shiftKey||O(),h(!u),!0)}),p),c.registerCommand(f,g,p),c.registerCommand(d,g,p))),[O,c,u,i,g,h]),y((()=>{const e=c.getElementByKey(i),t="selected";null!==e&&(u?r(e,t):o(e,t))}),[c,u,i]),null}class C extends c{static getType(){return"horizontalrule"}static clone(e){return new C(e.__key)}static importJSON(e){return D()}static importDOM(){return{hr:()=>({conversion:_,priority:0})}}exportJSON(){return{type:"horizontalrule",version:1}}exportDOM(){return{element:document.createElement("hr")}}createDOM(e){const t=document.createElement("hr");return r(t,e.theme.hr),t}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}decorate(){return h(g,{nodeKey:this.__key})}}function _(){return{node:D()}}function D(){return u(new C)}function E(e){return e instanceof C}export{D as $createHorizontalRuleNode,E as $isHorizontalRuleNode,C as HorizontalRuleNode,O as INSERT_HORIZONTAL_RULE_COMMAND};
|
|
@@ -10,20 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
var LexicalCollaborationContext = require('@lexical/react/LexicalCollaborationContext');
|
|
12
12
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
function _interopNamespaceDefault(e) {
|
|
16
|
-
var n = Object.create(null);
|
|
17
|
-
if (e) {
|
|
18
|
-
for (var k in e) {
|
|
19
|
-
n[k] = e[k];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
n.default = e;
|
|
23
|
-
return n;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
13
|
+
var react = require('react');
|
|
14
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
27
15
|
|
|
28
16
|
/**
|
|
29
17
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -44,8 +32,8 @@ function LexicalNestedComposer({
|
|
|
44
32
|
initialTheme,
|
|
45
33
|
skipCollabChecks
|
|
46
34
|
}) {
|
|
47
|
-
const wasCollabPreviouslyReadyRef =
|
|
48
|
-
const parentContext =
|
|
35
|
+
const wasCollabPreviouslyReadyRef = react.useRef(false);
|
|
36
|
+
const parentContext = react.useContext(LexicalComposerContext.LexicalComposerContext);
|
|
49
37
|
if (parentContext == null) {
|
|
50
38
|
{
|
|
51
39
|
throw Error(`Unexpected parent context null on a nested composer`);
|
|
@@ -54,7 +42,7 @@ function LexicalNestedComposer({
|
|
|
54
42
|
const [parentEditor, {
|
|
55
43
|
getTheme: getParentTheme
|
|
56
44
|
}] = parentContext;
|
|
57
|
-
const composerContext =
|
|
45
|
+
const composerContext = react.useMemo(() => {
|
|
58
46
|
const composerTheme = initialTheme || getParentTheme() || undefined;
|
|
59
47
|
const context = LexicalComposerContext.createLexicalComposerContext(parentContext, composerTheme);
|
|
60
48
|
if (composerTheme !== undefined) {
|
|
@@ -106,21 +94,22 @@ function LexicalNestedComposer({
|
|
|
106
94
|
yjsDocMap
|
|
107
95
|
} = LexicalCollaborationContext.useCollaborationContext();
|
|
108
96
|
const isCollabReady = skipCollabChecks || wasCollabPreviouslyReadyRef.current || yjsDocMap.has(initialEditor.getKey());
|
|
109
|
-
|
|
97
|
+
react.useEffect(() => {
|
|
110
98
|
if (isCollabReady) {
|
|
111
99
|
wasCollabPreviouslyReadyRef.current = true;
|
|
112
100
|
}
|
|
113
101
|
}, [isCollabReady]);
|
|
114
102
|
|
|
115
103
|
// Update `isEditable` state of nested editor in response to the same change on parent editor.
|
|
116
|
-
|
|
104
|
+
react.useEffect(() => {
|
|
117
105
|
return parentEditor.registerEditableListener(editable => {
|
|
118
106
|
initialEditor.setEditable(editable);
|
|
119
107
|
});
|
|
120
108
|
}, [initialEditor, parentEditor]);
|
|
121
|
-
return /*#__PURE__*/
|
|
122
|
-
value: composerContext
|
|
123
|
-
|
|
109
|
+
return /*#__PURE__*/jsxRuntime.jsx(LexicalComposerContext.LexicalComposerContext.Provider, {
|
|
110
|
+
value: composerContext,
|
|
111
|
+
children: !isCollabActive || isCollabReady ? children : null
|
|
112
|
+
});
|
|
124
113
|
}
|
|
125
114
|
|
|
126
115
|
exports.LexicalNestedComposer = LexicalNestedComposer;
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
import { useCollaborationContext } from '@lexical/react/LexicalCollaborationContext';
|
|
10
10
|
import { LexicalComposerContext, createLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
11
|
-
import * as React from 'react';
|
|
12
11
|
import { useRef, useContext, useMemo, useEffect } from 'react';
|
|
12
|
+
import { jsx } from 'react/jsx-runtime';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -104,9 +104,10 @@ function LexicalNestedComposer({
|
|
|
104
104
|
initialEditor.setEditable(editable);
|
|
105
105
|
});
|
|
106
106
|
}, [initialEditor, parentEditor]);
|
|
107
|
-
return /*#__PURE__*/
|
|
108
|
-
value: composerContext
|
|
109
|
-
|
|
107
|
+
return /*#__PURE__*/jsx(LexicalComposerContext.Provider, {
|
|
108
|
+
value: composerContext,
|
|
109
|
+
children: !isCollabActive || isCollabReady ? children : null
|
|
110
|
+
});
|
|
110
111
|
}
|
|
111
112
|
|
|
112
113
|
export { LexicalNestedComposer };
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
'use strict';var
|
|
10
|
-
|
|
11
|
-
exports.LexicalNestedComposer=function({initialEditor:a,children:k,initialNodes:
|
|
12
|
-
{exportDOM:m?m.exportDOM:void 0,klass:
|
|
13
|
-
|
|
9
|
+
'use strict';var g=require("@lexical/react/LexicalCollaborationContext"),h=require("@lexical/react/LexicalComposerContext"),n=require("react"),r=require("react/jsx-runtime"),t;function v(a){let k=new URLSearchParams;k.append("code",a);for(let d=1;d<arguments.length;d++)k.append("v",arguments[d]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${k} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
|
|
10
|
+
t=v&&v.__esModule&&Object.prototype.hasOwnProperty.call(v,"default")?v["default"]:v;function w(a){a=a.transform();return null!==a?new Set([a]):new Set}
|
|
11
|
+
exports.LexicalNestedComposer=function({initialEditor:a,children:k,initialNodes:d,initialTheme:x,skipCollabChecks:y}){let u=n.useRef(!1),p=n.useContext(h.LexicalComposerContext);null==p&&t(9);let [e,{getTheme:z}]=p,B=n.useMemo(()=>{var c=x||z()||void 0;const A=h.createLexicalComposerContext(p,c);void 0!==c&&(a._config.theme=c);a._parentEditor=e;if(d)for(var b of d){var f=c=null;"function"!==typeof b&&(f=b,b=f.replace,c=f.with,f=f.withKlass||null);const m=a._nodes.get(b.getType());a._nodes.set(b.getType(),
|
|
12
|
+
{exportDOM:m?m.exportDOM:void 0,klass:b,replace:c,replaceWithKlass:f,transforms:w(b)})}else{b=a._nodes=new Map(e._nodes);for(const [m,l]of b)a._nodes.set(m,{exportDOM:l.exportDOM,klass:l.klass,replace:l.replace,replaceWithKlass:l.replaceWithKlass,transforms:w(l.klass)})}a._config.namespace=e._config.namespace;a._editable=e._editable;return[a,A]},[]),{isCollabActive:C,yjsDocMap:D}=g.useCollaborationContext(),q=y||u.current||D.has(a.getKey());n.useEffect(()=>{q&&(u.current=!0)},[q]);n.useEffect(()=>
|
|
13
|
+
e.registerEditableListener(c=>{a.setEditable(c)}),[a,e]);return r.jsx(h.LexicalComposerContext.Provider,{value:B,children:!C||q?k:null})}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{useCollaborationContext as e}from"@lexical/react/LexicalCollaborationContext";import{LexicalComposerContext as t,createLexicalComposerContext as r}from"@lexical/react/LexicalComposerContext";import
|
|
9
|
+
import{useCollaborationContext as e}from"@lexical/react/LexicalCollaborationContext";import{LexicalComposerContext as t,createLexicalComposerContext as r}from"@lexical/react/LexicalComposerContext";import{useRef as o,useContext as n,useMemo as l,useEffect as i}from"react";import{jsx as a}from"react/jsx-runtime";function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var c=s((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));function p(e){const t=e.transform();return null!==t?new Set([t]):new Set}function d({initialEditor:s,children:d,initialNodes:f,initialTheme:u,skipCollabChecks:m}){const h=o(!1),x=n(t);null==x&&c(9);const[_,{getTheme:g}]=x,v=l((()=>{const e=u||g()||void 0,t=r(x,e);if(void 0!==e&&(s._config.theme=e),s._parentEditor=_,f)for(let e of f){let t=null,r=null;if("function"!=typeof e){const o=e;e=o.replace,t=o.with,r=o.withKlass||null}const o=s._nodes.get(e.getType());s._nodes.set(e.getType(),{exportDOM:o?o.exportDOM:void 0,klass:e,replace:t,replaceWithKlass:r,transforms:p(e)})}else{const e=s._nodes=new Map(_._nodes);for(const[t,r]of e)s._nodes.set(t,{exportDOM:r.exportDOM,klass:r.klass,replace:r.replace,replaceWithKlass:r.replaceWithKlass,transforms:p(r.klass)})}return s._config.namespace=_._config.namespace,s._editable=_._editable,[s,t]}),[]),{isCollabActive:w,yjsDocMap:b}=e(),M=m||h.current||b.has(s.getKey());return i((()=>{M&&(h.current=!0)}),[M]),i((()=>_.registerEditableListener((e=>{s.setEditable(e)}))),[s,_]),a(t.Provider,{value:v,children:!w||M?d:null})}export{d as LexicalNestedComposer};
|
|
@@ -12,6 +12,7 @@ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
|
12
12
|
var lexical = require('lexical');
|
|
13
13
|
var React = require('react');
|
|
14
14
|
var utils = require('@lexical/utils');
|
|
15
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
15
16
|
|
|
16
17
|
function _interopNamespaceDefault(e) {
|
|
17
18
|
var n = Object.create(null);
|
|
@@ -44,6 +45,10 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
44
45
|
*
|
|
45
46
|
*/
|
|
46
47
|
|
|
48
|
+
|
|
49
|
+
// This workaround is no longer necessary in React 19,
|
|
50
|
+
// but we currently support React >=17.x
|
|
51
|
+
// https://github.com/facebook/react/pull/26395
|
|
47
52
|
const useLayoutEffectImpl = CAN_USE_DOM ? React.useLayoutEffect : React.useEffect;
|
|
48
53
|
|
|
49
54
|
/**
|
|
@@ -469,7 +474,7 @@ function LexicalNodeMenuPlugin({
|
|
|
469
474
|
});
|
|
470
475
|
}
|
|
471
476
|
}, [editor, positionOrCloseMenu, nodeKey]);
|
|
472
|
-
return resolution === null || editor === null ? null : /*#__PURE__*/
|
|
477
|
+
return resolution === null || editor === null ? null : /*#__PURE__*/jsxRuntime.jsx(LexicalMenu, {
|
|
473
478
|
close: closeNodeMenu,
|
|
474
479
|
resolution: resolution,
|
|
475
480
|
editor: editor,
|
|
@@ -11,6 +11,7 @@ import { createCommand, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ESCAPE
|
|
|
11
11
|
import * as React from 'react';
|
|
12
12
|
import { useLayoutEffect, useEffect, useState, useCallback, useMemo, useRef } from 'react';
|
|
13
13
|
import { mergeRegister } from '@lexical/utils';
|
|
14
|
+
import { jsx } from 'react/jsx-runtime';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -30,6 +31,10 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
30
31
|
*
|
|
31
32
|
*/
|
|
32
33
|
|
|
34
|
+
|
|
35
|
+
// This workaround is no longer necessary in React 19,
|
|
36
|
+
// but we currently support React >=17.x
|
|
37
|
+
// https://github.com/facebook/react/pull/26395
|
|
33
38
|
const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
|
|
34
39
|
|
|
35
40
|
/**
|
|
@@ -455,7 +460,7 @@ function LexicalNodeMenuPlugin({
|
|
|
455
460
|
});
|
|
456
461
|
}
|
|
457
462
|
}, [editor, positionOrCloseMenu, nodeKey]);
|
|
458
|
-
return resolution === null || editor === null ? null : /*#__PURE__*/
|
|
463
|
+
return resolution === null || editor === null ? null : /*#__PURE__*/jsx(LexicalMenu, {
|
|
459
464
|
close: closeNodeMenu,
|
|
460
465
|
resolution: resolution,
|
|
461
466
|
editor: editor,
|
|
@@ -6,18 +6,18 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
'use strict';var k=require("@lexical/react/LexicalComposerContext"),t=require("lexical"),x=require("react"),y=require("@lexical/utils"),z=Object.create(null);if(x)for(var
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
function
|
|
13
|
-
function
|
|
14
|
-
c,!0)}}},[a,e,l,f,b])}let
|
|
15
|
-
function
|
|
16
|
-
"typeahead-item-"+d),g(d))},[a]);x.useEffect(()=>()=>{let d=a.getRootElement();null!==d&&d.removeAttribute("aria-activedescendant")},[a]);
|
|
17
|
-
a.dispatchCommand(
|
|
9
|
+
'use strict';var k=require("@lexical/react/LexicalComposerContext"),t=require("lexical"),x=require("react"),y=require("@lexical/utils"),z=require("react/jsx-runtime"),A=Object.create(null);if(x)for(var B in x)A[B]=x[B];A.default=x;let C="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?x.useLayoutEffect:x.useEffect;
|
|
10
|
+
class D{constructor(b){this.key=b;this.ref={current:null};this.setRefElement=this.setRefElement.bind(this)}setRefElement(b){this.ref={current:b}}}let E=b=>{const a=document.getElementById("typeahead-menu");if(a){var f=a.getBoundingClientRect();f.top+f.height>window.innerHeight&&a.scrollIntoView({block:"center"});0>f.top&&a.scrollIntoView({block:"center"});b.scrollIntoView({block:"nearest"})}};
|
|
11
|
+
function F(b){var a=t.$getSelection();if(!t.$isRangeSelection(a)||!a.isCollapsed())return null;var f=a.anchor;if("text"!==f.type)return null;a=f.getNode();if(!a.isSimpleText())return null;f=f.offset;let l=a.getTextContent().slice(0,f);var e=b.matchingString;b=b.replaceableString.length;for(let n=b;n<=e.length;n++)l.substr(-n)===e.substr(0,n)&&(b=n);b=f-b;if(0>b)return null;let p;0===b?[p]=a.splitText(f):[,p]=a.splitText(b,f);return p}
|
|
12
|
+
function G(b){let a=getComputedStyle(b),f="absolute"===a.position,l=/(auto|scroll)/;if("fixed"===a.position)return document.body;for(;b=b.parentElement;)if(a=getComputedStyle(b),(!f||"static"!==a.position)&&l.test(a.overflow+a.overflowY+a.overflowX))return b;return document.body}function H(b,a){b=b.getBoundingClientRect();a=a.getBoundingClientRect();return b.top>a.top&&b.top<a.bottom}
|
|
13
|
+
function I(b,a,f,l){let [e]=k.useLexicalComposerContext();x.useEffect(()=>{if(null!=a&&null!=b){let p=e.getRootElement(),n=null!=p?G(p):document.body,w=!1,m=H(a,n),c=function(){w||(window.requestAnimationFrame(function(){f();w=!1}),w=!0);const q=H(a,n);q!==m&&(m=q,null!=l&&l(q))},g=new ResizeObserver(f);window.addEventListener("resize",f);document.addEventListener("scroll",c,{capture:!0,passive:!0});g.observe(a);return()=>{g.unobserve(a);window.removeEventListener("resize",f);document.removeEventListener("scroll",
|
|
14
|
+
c,!0)}}},[a,e,l,f,b])}let J=t.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
|
|
15
|
+
function K({close:b,editor:a,anchorElementRef:f,resolution:l,options:e,menuRenderFn:p,onSelectOption:n,shouldSplitNodeWithQuery:w=!1,commandPriority:m=t.COMMAND_PRIORITY_LOW}){let [c,g]=x.useState(null);x.useEffect(()=>{g(0)},[l.match&&l.match.matchingString]);let q=x.useCallback(d=>{a.update(()=>{const h=null!=l.match&&w?F(l.match):null;n(d,h,b,l.match?l.match.matchingString:"")})},[a,w,l.match,n,b]),r=x.useCallback(d=>{const h=a.getRootElement();null!==h&&(h.setAttribute("aria-activedescendant",
|
|
16
|
+
"typeahead-item-"+d),g(d))},[a]);x.useEffect(()=>()=>{let d=a.getRootElement();null!==d&&d.removeAttribute("aria-activedescendant")},[a]);C(()=>{null===e?g(null):null===c&&r(0)},[e,c,r]);x.useEffect(()=>y.mergeRegister(a.registerCommand(J,({option:d})=>d.ref&&null!=d.ref.current?(E(d.ref.current),!0):!1,m)),[a,r,m]);x.useEffect(()=>y.mergeRegister(a.registerCommand(t.KEY_ARROW_DOWN_COMMAND,d=>{if(null!==e&&e.length&&null!==c){let h=c!==e.length-1?c+1:0;r(h);let u=e[h];null!=u.ref&&u.ref.current&&
|
|
17
|
+
a.dispatchCommand(J,{index:h,option:u});d.preventDefault();d.stopImmediatePropagation()}return!0},m),a.registerCommand(t.KEY_ARROW_UP_COMMAND,d=>{if(null!==e&&e.length&&null!==c){var h=0!==c?c-1:e.length-1;r(h);h=e[h];null!=h.ref&&h.ref.current&&E(h.ref.current);d.preventDefault();d.stopImmediatePropagation()}return!0},m),a.registerCommand(t.KEY_ESCAPE_COMMAND,d=>{d.preventDefault();d.stopImmediatePropagation();b();return!0},m),a.registerCommand(t.KEY_TAB_COMMAND,d=>{if(null===e||null===c||null==
|
|
18
18
|
e[c])return!1;d.preventDefault();d.stopImmediatePropagation();q(e[c]);return!0},m),a.registerCommand(t.KEY_ENTER_COMMAND,d=>{if(null===e||null===c||null==e[c])return!1;null!==d&&(d.preventDefault(),d.stopImmediatePropagation());q(e[c]);return!0},m)),[q,b,a,e,c,r,m]);let v=x.useMemo(()=>({options:e,selectOptionAndCleanUp:q,selectedIndex:c,setHighlightedIndex:g}),[q,c,e]);return p(f,v,l.match?l.match.matchingString:"")}
|
|
19
|
-
function
|
|
19
|
+
function L(b,a,f,l=document.body){let [e]=k.useLexicalComposerContext(),p=x.useRef(document.createElement("div")),n=x.useCallback(()=>{p.current.style.top=p.current.style.bottom;const m=e.getRootElement(),c=p.current;var g=c.firstChild;if(null!==m&&null!==b){const {left:r,top:v,width:d,height:h}=b.getRect();c.style.top=`${v+window.pageYOffset+p.current.offsetHeight+3}px`;c.style.left=`${r+window.pageXOffset}px`;c.style.height=`${h}px`;c.style.width=`${d}px`;if(null!==g){g.style.top=`${v}`;var q=g.getBoundingClientRect();
|
|
20
20
|
g=q.height;q=q.width;const u=m.getBoundingClientRect();r+q>u.right&&(c.style.left=`${u.right-q+window.pageXOffset}px`);(v+g>window.innerHeight||v+g>u.bottom)&&v-u.top>g+h&&(c.style.top=`${v-g+window.pageYOffset-h}px`)}c.isConnected||(null!=f&&(c.className=f),c.setAttribute("aria-label","Typeahead menu"),c.setAttribute("id","typeahead-menu"),c.setAttribute("role","listbox"),c.style.display="block",c.style.position="absolute",l.append(c));p.current=c;m.setAttribute("aria-controls","typeahead-menu")}},
|
|
21
|
-
[e,b,f,l]);x.useEffect(()=>{let m=e.getRootElement();if(null!==b)return n(),()=>{null!==m&&m.removeAttribute("aria-controls");let c=p.current;null!==c&&c.isConnected&&c.remove()}},[e,n,b]);let w=x.useCallback(m=>{null!==b&&(m||a(null))},[b,a]);
|
|
22
|
-
exports.LexicalNodeMenuPlugin=function({options:b,nodeKey:a,onClose:f,onOpen:l,onSelectOption:e,menuRenderFn:p,anchorClassName:n,commandPriority:w=t.COMMAND_PRIORITY_LOW,parent:m}){let [c]=k.useLexicalComposerContext(),[g,q]=x.useState(null);n=
|
|
23
|
-
u.getBoundingClientRect()}))}):null==a&&null!=g&&r()},[r,c,a,v,g]);x.useEffect(()=>{d()},[d,a]);x.useEffect(()=>{if(null!=a)return c.registerUpdateListener(({dirtyElements:h})=>{h.get(a)&&d()})},[c,d,a]);return null===g||null===c?null:z.
|
|
21
|
+
[e,b,f,l]);x.useEffect(()=>{let m=e.getRootElement();if(null!==b)return n(),()=>{null!==m&&m.removeAttribute("aria-controls");let c=p.current;null!==c&&c.isConnected&&c.remove()}},[e,n,b]);let w=x.useCallback(m=>{null!==b&&(m||a(null))},[b,a]);I(b,p.current,n,w);return p}function M(b){A.startTransition?A.startTransition(b):b()}
|
|
22
|
+
exports.LexicalNodeMenuPlugin=function({options:b,nodeKey:a,onClose:f,onOpen:l,onSelectOption:e,menuRenderFn:p,anchorClassName:n,commandPriority:w=t.COMMAND_PRIORITY_LOW,parent:m}){let [c]=k.useLexicalComposerContext(),[g,q]=x.useState(null);n=L(g,q,n,m);let r=x.useCallback(()=>{q(null);null!=f&&null!==g&&f()},[f,g]),v=x.useCallback(h=>{q(h);null!=l&&null===g&&l(h)},[l,g]),d=x.useCallback(()=>{a?c.update(()=>{const h=t.$getNodeByKey(a),u=c.getElementByKey(a);null!=h&&null!=u&&null==g&&M(()=>v({getRect:()=>
|
|
23
|
+
u.getBoundingClientRect()}))}):null==a&&null!=g&&r()},[r,c,a,v,g]);x.useEffect(()=>{d()},[d,a]);x.useEffect(()=>{if(null!=a)return c.registerUpdateListener(({dirtyElements:h})=>{h.get(a)&&d()})},[c,d,a]);return null===g||null===c?null:z.jsx(K,{close:r,resolution:g,editor:c,anchorElementRef:n,options:b,menuRenderFn:p,onSelectOption:e,commandPriority:w})};exports.MenuOption=D
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{createCommand as e,KEY_ARROW_DOWN_COMMAND as n,KEY_ARROW_UP_COMMAND as o,KEY_ESCAPE_COMMAND as l,KEY_TAB_COMMAND as r,KEY_ENTER_COMMAND as i,COMMAND_PRIORITY_LOW as s,$getSelection as u,$isRangeSelection as c,$getNodeByKey as a}from"lexical";import*as m from"react";import{useLayoutEffect as d,useEffect as p,useState as f,useCallback as g,useMemo as h,useRef as y}from"react";import{mergeRegister as w}from"@lexical/utils";const
|
|
9
|
+
import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{createCommand as e,KEY_ARROW_DOWN_COMMAND as n,KEY_ARROW_UP_COMMAND as o,KEY_ESCAPE_COMMAND as l,KEY_TAB_COMMAND as r,KEY_ENTER_COMMAND as i,COMMAND_PRIORITY_LOW as s,$getSelection as u,$isRangeSelection as c,$getNodeByKey as a}from"lexical";import*as m from"react";import{useLayoutEffect as d,useEffect as p,useState as f,useCallback as g,useMemo as h,useRef as y}from"react";import{mergeRegister as w}from"@lexical/utils";import{jsx as b}from"react/jsx-runtime";const v="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?d:p;class C{constructor(t){this.key=t,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(t){this.ref={current:t}}}const x=t=>{const e=document.getElementById("typeahead-menu");if(!e)return;const n=e.getBoundingClientRect();n.top+n.height>window.innerHeight&&e.scrollIntoView({block:"center"}),n.top<0&&e.scrollIntoView({block:"center"}),t.scrollIntoView({block:"nearest"})};function E(t,e){const n=t.getBoundingClientRect(),o=e.getBoundingClientRect();return n.top>o.top&&n.top<o.bottom}function R(e,n,o,l){const[r]=t();p((()=>{if(null!=n&&null!=e){const t=r.getRootElement(),e=null!=t?function(t,e){let n=getComputedStyle(t);const o="absolute"===n.position,l=/(auto|scroll)/;if("fixed"===n.position)return document.body;for(let e=t;e=e.parentElement;)if(n=getComputedStyle(e),(!o||"static"!==n.position)&&l.test(n.overflow+n.overflowY+n.overflowX))return e;return document.body}(t):document.body;let i=!1,s=E(n,e);const u=function(){i||(window.requestAnimationFrame((function(){o(),i=!1})),i=!0);const t=E(n,e);t!==s&&(s=t,null!=l&&l(t))},c=new ResizeObserver(o);return window.addEventListener("resize",o),document.addEventListener("scroll",u,{capture:!0,passive:!0}),c.observe(n),()=>{c.unobserve(n),window.removeEventListener("resize",o),document.removeEventListener("scroll",u,!0)}}}),[n,r,l,o,e])}const O=e("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function I({close:t,editor:e,anchorElementRef:a,resolution:m,options:d,menuRenderFn:y,onSelectOption:b,shouldSplitNodeWithQuery:C=!1,commandPriority:E=s}){const[R,I]=f(null),S=m.match&&m.match.matchingString;p((()=>{I(0)}),[S]);const A=g((n=>{e.update((()=>{const e=null!=m.match&&C?function(t){const e=u();if(!c(e)||!e.isCollapsed())return null;const n=e.anchor;if("text"!==n.type)return null;const o=n.getNode();if(!o.isSimpleText())return null;const l=n.offset,r=o.getTextContent().slice(0,l),i=t.replaceableString.length,s=l-function(t,e,n){let o=n;for(let n=o;n<=e.length;n++)t.substr(-n)===e.substr(0,n)&&(o=n);return o}(r,t.matchingString,i);if(s<0)return null;let a;return 0===s?[a]=o.splitText(l):[,a]=o.splitText(s,l),a}(m.match):null;b(n,e,t,m.match?m.match.matchingString:"")}))}),[e,C,m.match,b,t]),P=g((t=>{const n=e.getRootElement();null!==n&&(n.setAttribute("aria-activedescendant","typeahead-item-"+t),I(t))}),[e]);p((()=>()=>{const t=e.getRootElement();null!==t&&t.removeAttribute("aria-activedescendant")}),[e]),v((()=>{null===d?I(null):null===R&&P(0)}),[d,R,P]),p((()=>w(e.registerCommand(O,(({option:t})=>!(!t.ref||null==t.ref.current)&&(x(t.ref.current),!0)),E))),[e,P,E]),p((()=>w(e.registerCommand(n,(t=>{const n=t;if(null!==d&&d.length&&null!==R){const t=R!==d.length-1?R+1:0;P(t);const o=d[t];null!=o.ref&&o.ref.current&&e.dispatchCommand(O,{index:t,option:o}),n.preventDefault(),n.stopImmediatePropagation()}return!0}),E),e.registerCommand(o,(t=>{const e=t;if(null!==d&&d.length&&null!==R){const t=0!==R?R-1:d.length-1;P(t);const n=d[t];null!=n.ref&&n.ref.current&&x(n.ref.current),e.preventDefault(),e.stopImmediatePropagation()}return!0}),E),e.registerCommand(l,(e=>{const n=e;return n.preventDefault(),n.stopImmediatePropagation(),t(),!0}),E),e.registerCommand(r,(t=>{const e=t;return null!==d&&null!==R&&null!=d[R]&&(e.preventDefault(),e.stopImmediatePropagation(),A(d[R]),!0)}),E),e.registerCommand(i,(t=>null!==d&&null!==R&&null!=d[R]&&(null!==t&&(t.preventDefault(),t.stopImmediatePropagation()),A(d[R]),!0)),E))),[A,t,e,d,R,P,E]);return y(a,h((()=>({options:d,selectOptionAndCleanUp:A,selectedIndex:R,setHighlightedIndex:I})),[A,R,d]),m.match?m.match.matchingString:"")}function S({options:e,nodeKey:n,onClose:o,onOpen:l,onSelectOption:r,menuRenderFn:i,anchorClassName:u,commandPriority:c=s,parent:d}){const[h]=t(),[w,v]=f(null),C=function(e,n,o,l=document.body){const[r]=t(),i=y(document.createElement("div")),s=g((()=>{i.current.style.top=i.current.style.bottom;const t=r.getRootElement(),n=i.current,s=n.firstChild;if(null!==t&&null!==e){const{left:r,top:u,width:c,height:a}=e.getRect(),m=i.current.offsetHeight;if(n.style.top=`${u+window.pageYOffset+m+3}px`,n.style.left=`${r+window.pageXOffset}px`,n.style.height=`${a}px`,n.style.width=`${c}px`,null!==s){s.style.top=`${u}`;const e=s.getBoundingClientRect(),o=e.height,l=e.width,i=t.getBoundingClientRect();r+l>i.right&&(n.style.left=`${i.right-l+window.pageXOffset}px`),(u+o>window.innerHeight||u+o>i.bottom)&&u-i.top>o+a&&(n.style.top=u-o+window.pageYOffset-a+"px")}n.isConnected||(null!=o&&(n.className=o),n.setAttribute("aria-label","Typeahead menu"),n.setAttribute("id","typeahead-menu"),n.setAttribute("role","listbox"),n.style.display="block",n.style.position="absolute",l.append(n)),i.current=n,t.setAttribute("aria-controls","typeahead-menu")}}),[r,e,o,l]);p((()=>{const t=r.getRootElement();if(null!==e)return s(),()=>{null!==t&&t.removeAttribute("aria-controls");const e=i.current;null!==e&&e.isConnected&&e.remove()}}),[r,s,e]);const u=g((t=>{null!==e&&(t||n(null))}),[e,n]);return R(e,i.current,s,u),i}(w,v,u,d),x=g((()=>{v(null),null!=o&&null!==w&&o()}),[o,w]),E=g((t=>{v(t),null!=l&&null===w&&l(t)}),[l,w]),O=g((()=>{n?h.update((()=>{const t=a(n),e=h.getElementByKey(n);var o;null!=t&&null!=e&&null==w&&(o=()=>E({getRect:()=>e.getBoundingClientRect()}),m.startTransition?m.startTransition(o):o())})):null==n&&null!=w&&x()}),[x,h,n,E,w]);return p((()=>{O()}),[O,n]),p((()=>{if(null!=n)return h.registerUpdateListener((({dirtyElements:t})=>{t.get(n)&&O()}))}),[h,O,n]),null===w||null===h?null:b(I,{close:x,resolution:w,editor:h,anchorElementRef:C,options:e,menuRenderFn:i,onSelectOption:r,commandPriority:c})}export{S as LexicalNodeMenuPlugin,C as MenuOption};
|