@lexical/react 0.5.1-next.2 → 0.6.1-next.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.
@@ -7,4 +7,4 @@
7
7
  */
8
8
  import type { LexicalEditor } from 'lexical';
9
9
  import { ErrorBoundaryType } from './shared/useDecorators';
10
- export declare function useLexicalDecorators(editor: LexicalEditor, ErrorBoundary?: ErrorBoundaryType): Array<JSX.Element>;
10
+ export declare function useLexicalDecorators(editor: LexicalEditor, ErrorBoundary: ErrorBoundaryType): Array<JSX.Element>;
@@ -9,103 +9,6 @@
9
9
  var React = require('react');
10
10
  var reactDom = require('react-dom');
11
11
 
12
- /**
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- *
18
- */
19
-
20
- const changedArray = (a = [], b = []) => a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
21
-
22
- const initialState = {
23
- error: null
24
- };
25
-
26
- class ErrorBoundary extends React.Component {
27
- constructor(props) {
28
- super(props);
29
- this.state = initialState;
30
- this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
31
- }
32
-
33
- static getDerivedStateFromError(error) {
34
- return {
35
- error
36
- };
37
- }
38
-
39
- resetErrorBoundary(...args) {
40
- // @ts-ignore
41
- // eslint-disable-next-line no-unused-expressions
42
- this.props.onReset && this.props.onReset(...args);
43
- this.reset();
44
- }
45
-
46
- reset() {
47
- this.setState(initialState);
48
- }
49
-
50
- componentDidCatch(error, info) {
51
- // @ts-ignore
52
- // eslint-disable-next-line no-unused-expressions
53
- this.props.onError && this.props.onError(error, info);
54
- }
55
-
56
- componentDidUpdate(prevProps, prevState) {
57
- const {
58
- error
59
- } = this.state;
60
- const {
61
- resetKeys
62
- } = this.props; // There's an edge case where if the thing that triggered the error
63
- // happens to *also* be in the resetKeys array, we'd end up resetting
64
- // the error boundary immediately. This would likely trigger a second
65
- // error to be thrown.
66
- // So we make sure that we don't check the resetKeys on the first call
67
- // of cDU after the error is set
68
-
69
- if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
70
- // @ts-ignore
71
- // eslint-disable-next-line no-unused-expressions
72
- this.props.onResetKeysChange && this.props.onResetKeysChange(prevProps.resetKeys, resetKeys);
73
- this.reset();
74
- }
75
- }
76
-
77
- render() {
78
- const {
79
- error
80
- } = this.state;
81
- const {
82
- fallbackRender,
83
- FallbackComponent,
84
- fallback
85
- } = this.props;
86
-
87
- if (error !== null) {
88
- const props = {
89
- error,
90
- resetErrorBoundary: this.resetErrorBoundary
91
- };
92
-
93
- if ( /*#__PURE__*/React.isValidElement(fallback)) {
94
- return fallback;
95
- } else if (typeof fallbackRender === 'function') {
96
- return fallbackRender(props);
97
- } else if (FallbackComponent) {
98
- return /*#__PURE__*/React.createElement(FallbackComponent, props);
99
- } else {
100
- throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
101
- }
102
- }
103
-
104
- return this.props.children;
105
- }
106
-
107
- }
108
-
109
12
  /**
110
13
  * Copyright (c) Meta Platforms, Inc. and affiliates.
111
14
  *
@@ -132,19 +35,7 @@ var useLayoutEffect = useLayoutEffectImpl;
132
35
  * LICENSE file in the root directory of this source tree.
133
36
  *
134
37
  */
135
-
136
- const fallbackRenderer$1 = () => null;
137
-
138
- const DefaultErrorBoundary$1 = ({
139
- children,
140
- onError
141
- }) => /*#__PURE__*/React.createElement(ErrorBoundary, {
142
- fallbackRender: fallbackRenderer$1,
143
- onError: onError
144
- }, children);
145
-
146
- function useDecorators(editor, // TODO 0.6 Make non-optional non-default
147
- ErrorBoundary = DefaultErrorBoundary$1) {
38
+ function useDecorators(editor, ErrorBoundary) {
148
39
  const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
149
40
 
150
41
  useLayoutEffect(() => {
@@ -190,19 +81,7 @@ ErrorBoundary = DefaultErrorBoundary$1) {
190
81
  * LICENSE file in the root directory of this source tree.
191
82
  *
192
83
  */
193
-
194
- const fallbackRenderer = () => null;
195
-
196
- const DefaultErrorBoundary = ({
197
- children,
198
- onError
199
- }) => /*#__PURE__*/React.createElement(ErrorBoundary, {
200
- fallbackRender: fallbackRenderer,
201
- onError: onError
202
- }, children);
203
-
204
- function useLexicalDecorators(editor, // TODO 0.6 Make non-optional non-default
205
- ErrorBoundary = DefaultErrorBoundary) {
84
+ function useLexicalDecorators(editor, ErrorBoundary) {
206
85
  return useDecorators(editor, ErrorBoundary);
207
86
  }
208
87
 
@@ -13,13 +13,12 @@ import type {LexicalEditor} from 'lexical';
13
13
  import * as React from 'react';
14
14
 
15
15
  type ErrorBoundaryProps = $ReadOnly<{
16
- children: React.Node,
17
- onError?: (error: Error) => void,
16
+ children: React$Node,
17
+ onError: (error: Error) => void,
18
18
  }>;
19
19
  export type ErrorBoundaryType = React.AbstractComponent<ErrorBoundaryProps>;
20
20
 
21
21
  declare export function useLexicalDecorators(
22
22
  editor: LexicalEditor,
23
- // TODO 0.6 Make non-optional non-default
24
- ErrorBoundary?: ErrorBoundaryType,
23
+ ErrorBoundary: ErrorBoundaryType,
25
24
  ): Array<React.Node>;
@@ -4,9 +4,5 @@
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 c=require("react"),k=require("react-dom");let l=(a=[],b=[])=>a.length!==b.length||a.some((d,e)=>!Object.is(d,b[e])),m={error:null};
8
- class p extends c.Component{constructor(a){super(a);this.state=m;this.resetErrorBoundary=this.resetErrorBoundary.bind(this)}static getDerivedStateFromError(a){return{error:a}}resetErrorBoundary(...a){this.props.onReset&&this.props.onReset(...a);this.reset()}reset(){this.setState(m)}componentDidCatch(a,b){this.props.onError&&this.props.onError(a,b)}componentDidUpdate(a,b){let {error:d}=this.state,{resetKeys:e}=this.props;null!==d&&null!==b.error&&l(a.resetKeys,e)&&(this.props.onResetKeysChange&&this.props.onResetKeysChange(a.resetKeys,
9
- e),this.reset())}render(){var {error:a}=this.state;let {fallbackRender:b,FallbackComponent:d,fallback:e}=this.props;if(null!==a){a={error:a,resetErrorBoundary:this.resetErrorBoundary};if(c.isValidElement(e))return e;if("function"===typeof b)return b(a);if(d)return c.createElement(d,a);throw Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop");}return this.props.children}}
10
- var q="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?c.useLayoutEffect:c.useEffect;let r=()=>null,t=({children:a,onError:b})=>c.createElement(p,{fallbackRender:r,onError:b},a);
11
- function u(a,b=t){let [d,e]=c.useState(()=>a.getDecorators());q(()=>a.registerDecoratorListener(g=>{k.flushSync(()=>{e(g)})}),[a]);c.useEffect(()=>{e(a.getDecorators())},[a]);return c.useMemo(()=>{let g=[],n=Object.keys(d);for(let h=0;h<n.length;h++){var f=n[h];let w=c.createElement(b,{onError:v=>a._onError(v)},c.createElement(c.Suspense,{fallback:null},d[f]));f=a.getElementByKey(f);null!==f&&g.push(k.createPortal(w,f))}return g},[b,d,a])}
12
- let x=()=>null,y=({children:a,onError:b})=>c.createElement(p,{fallbackRender:x,onError:b},a);exports.useLexicalDecorators=function(a,b=y){return u(a,b)}
7
+ 'use strict';var b=require("react"),h=require("react-dom"),m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?b.useLayoutEffect:b.useEffect;
8
+ function n(a,d){let [f,k]=b.useState(()=>a.getDecorators());m(()=>a.registerDecoratorListener(e=>{h.flushSync(()=>{k(e)})}),[a]);b.useEffect(()=>{k(a.getDecorators())},[a]);return b.useMemo(()=>{let e=[],l=Object.keys(f);for(let g=0;g<l.length;g++){var c=l[g];let q=b.createElement(d,{onError:p=>a._onError(p)},b.createElement(b.Suspense,{fallback:null},f[c]));c=a.getElementByKey(c);null!==c&&e.push(h.createPortal(q,c))}return e},[d,f,a])}exports.useLexicalDecorators=function(a,d){return n(a,d)}
@@ -0,0 +1,12 @@
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
+ export declare type LexicalErrorBoundaryProps = {
9
+ children: JSX.Element;
10
+ onError: (error: Error) => void;
11
+ };
12
+ export default function LexicalErrorBoundary({ children, onError, }: LexicalErrorBoundaryProps): JSX.Element;
@@ -0,0 +1,159 @@
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 React = require('react');
10
+
11
+ function _setPrototypeOf(o, p) {
12
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
13
+ o.__proto__ = p;
14
+ return o;
15
+ };
16
+ return _setPrototypeOf(o, p);
17
+ }
18
+
19
+ function _inheritsLoose(subClass, superClass) {
20
+ subClass.prototype = Object.create(superClass.prototype);
21
+ subClass.prototype.constructor = subClass;
22
+ _setPrototypeOf(subClass, superClass);
23
+ }
24
+
25
+ var changedArray = function changedArray(a, b) {
26
+ if (a === void 0) {
27
+ a = [];
28
+ }
29
+
30
+ if (b === void 0) {
31
+ b = [];
32
+ }
33
+
34
+ return a.length !== b.length || a.some(function (item, index) {
35
+ return !Object.is(item, b[index]);
36
+ });
37
+ };
38
+
39
+ var initialState = {
40
+ error: null
41
+ };
42
+
43
+ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
44
+ _inheritsLoose(ErrorBoundary, _React$Component);
45
+
46
+ function ErrorBoundary() {
47
+ var _this;
48
+
49
+ for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
50
+ _args[_key] = arguments[_key];
51
+ }
52
+
53
+ _this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
54
+ _this.state = initialState;
55
+
56
+ _this.resetErrorBoundary = function () {
57
+ var _this$props;
58
+
59
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
60
+ args[_key2] = arguments[_key2];
61
+ }
62
+
63
+ _this.props.onReset == null ? void 0 : (_this$props = _this.props).onReset.apply(_this$props, args);
64
+
65
+ _this.reset();
66
+ };
67
+
68
+ return _this;
69
+ }
70
+
71
+ ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
72
+ return {
73
+ error: error
74
+ };
75
+ };
76
+
77
+ var _proto = ErrorBoundary.prototype;
78
+
79
+ _proto.reset = function reset() {
80
+ this.setState(initialState);
81
+ };
82
+
83
+ _proto.componentDidCatch = function componentDidCatch(error, info) {
84
+ var _this$props$onError, _this$props2;
85
+
86
+ (_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
87
+ };
88
+
89
+ _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
90
+ var error = this.state.error;
91
+ var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
92
+ // happens to *also* be in the resetKeys array, we'd end up resetting
93
+ // the error boundary immediately. This would likely trigger a second
94
+ // error to be thrown.
95
+ // So we make sure that we don't check the resetKeys on the first call
96
+ // of cDU after the error is set
97
+
98
+ if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
99
+ var _this$props$onResetKe, _this$props3;
100
+
101
+ (_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
102
+ this.reset();
103
+ }
104
+ };
105
+
106
+ _proto.render = function render() {
107
+ var error = this.state.error;
108
+ var _this$props4 = this.props,
109
+ fallbackRender = _this$props4.fallbackRender,
110
+ FallbackComponent = _this$props4.FallbackComponent,
111
+ fallback = _this$props4.fallback;
112
+
113
+ if (error !== null) {
114
+ var _props = {
115
+ error: error,
116
+ resetErrorBoundary: this.resetErrorBoundary
117
+ };
118
+
119
+ if ( /*#__PURE__*/React.isValidElement(fallback)) {
120
+ return fallback;
121
+ } else if (typeof fallbackRender === 'function') {
122
+ return fallbackRender(_props);
123
+ } else if (FallbackComponent) {
124
+ return /*#__PURE__*/React.createElement(FallbackComponent, _props);
125
+ } else {
126
+ throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
127
+ }
128
+ }
129
+
130
+ return this.props.children;
131
+ };
132
+
133
+ return ErrorBoundary;
134
+ }(React.Component);
135
+
136
+ /**
137
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
138
+ *
139
+ * This source code is licensed under the MIT license found in the
140
+ * LICENSE file in the root directory of this source tree.
141
+ *
142
+ */
143
+ function LexicalErrorBoundary({
144
+ children,
145
+ onError
146
+ }) {
147
+ return /*#__PURE__*/React.createElement(ErrorBoundary, {
148
+ fallback: /*#__PURE__*/React.createElement("div", {
149
+ style: {
150
+ border: '1px solid #f00',
151
+ color: '#f00',
152
+ padding: '8px'
153
+ }
154
+ }, "An error was thrown."),
155
+ onError: onError
156
+ }, children);
157
+ }
158
+
159
+ module.exports = LexicalErrorBoundary;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ 'use strict'
8
+ const LexicalErrorBoundary = process.env.NODE_ENV === 'development' ? require('./LexicalErrorBoundary.dev.js') : require('./LexicalErrorBoundary.prod.js')
9
+ module.exports = LexicalErrorBoundary;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ export type LexicalErrorBoundaryProps = $ReadOnly<{
11
+ children: React$Node,
12
+ onError: (error: Error) => void,
13
+ }>;
14
+
15
+ declare export default function LexicalErrorBoundary(
16
+ props: LexicalErrorBoundaryProps,
17
+ ): React$Node;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ 'use strict';var h=require("react");function m(b,c){m=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(g,a){g.__proto__=a;return g};return m(b,c)}function n(b,c){b.prototype=Object.create(c.prototype);b.prototype.constructor=b;m(b,c)}function r(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])})}
8
+ var t={error:null},u=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=t;a.resetErrorBoundary=function(){for(var k,p=arguments.length,q=Array(p),l=0;l<p;l++)q[l]=arguments[l];null==a.props.onReset?void 0:(k=a.props).onReset.apply(k,q);a.reset()};return a}n(c,b);c.getDerivedStateFromError=function(a){return{error:a}};var g=c.prototype;g.reset=function(){this.setState(t)};g.componentDidCatch=function(a,d){var f,
9
+ 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&&r(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(h.isValidElement(d))return d;if("function"===
10
+ typeof f)return f(a);if(e)return h.createElement(e,a);throw Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop");}return this.props.children};return c}(h.Component);module.exports=function({children:b,onError:c}){return h.createElement(u,{fallback:h.createElement("div",{style:{border:"1px solid #f00",color:"#f00",padding:"8px"}},"An error was thrown."),onError:c},b)}
@@ -9,5 +9,5 @@ import { ErrorBoundaryType } from './shared/useDecorators';
9
9
  export declare function PlainTextPlugin({ contentEditable, placeholder, ErrorBoundary, }: {
10
10
  contentEditable: JSX.Element;
11
11
  placeholder: JSX.Element | string;
12
- ErrorBoundary?: ErrorBoundaryType;
12
+ ErrorBoundary: ErrorBoundaryType;
13
13
  }): JSX.Element;
@@ -14,103 +14,6 @@ var reactDom = require('react-dom');
14
14
  var dragon = require('@lexical/dragon');
15
15
  var plainText = require('@lexical/plain-text');
16
16
 
17
- /**
18
- * Copyright (c) Meta Platforms, Inc. and affiliates.
19
- *
20
- * This source code is licensed under the MIT license found in the
21
- * LICENSE file in the root directory of this source tree.
22
- *
23
- */
24
-
25
- const changedArray = (a = [], b = []) => a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
26
-
27
- const initialState = {
28
- error: null
29
- };
30
-
31
- class ErrorBoundary extends React.Component {
32
- constructor(props) {
33
- super(props);
34
- this.state = initialState;
35
- this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
36
- }
37
-
38
- static getDerivedStateFromError(error) {
39
- return {
40
- error
41
- };
42
- }
43
-
44
- resetErrorBoundary(...args) {
45
- // @ts-ignore
46
- // eslint-disable-next-line no-unused-expressions
47
- this.props.onReset && this.props.onReset(...args);
48
- this.reset();
49
- }
50
-
51
- reset() {
52
- this.setState(initialState);
53
- }
54
-
55
- componentDidCatch(error, info) {
56
- // @ts-ignore
57
- // eslint-disable-next-line no-unused-expressions
58
- this.props.onError && this.props.onError(error, info);
59
- }
60
-
61
- componentDidUpdate(prevProps, prevState) {
62
- const {
63
- error
64
- } = this.state;
65
- const {
66
- resetKeys
67
- } = this.props; // There's an edge case where if the thing that triggered the error
68
- // happens to *also* be in the resetKeys array, we'd end up resetting
69
- // the error boundary immediately. This would likely trigger a second
70
- // error to be thrown.
71
- // So we make sure that we don't check the resetKeys on the first call
72
- // of cDU after the error is set
73
-
74
- if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
75
- // @ts-ignore
76
- // eslint-disable-next-line no-unused-expressions
77
- this.props.onResetKeysChange && this.props.onResetKeysChange(prevProps.resetKeys, resetKeys);
78
- this.reset();
79
- }
80
- }
81
-
82
- render() {
83
- const {
84
- error
85
- } = this.state;
86
- const {
87
- fallbackRender,
88
- FallbackComponent,
89
- fallback
90
- } = this.props;
91
-
92
- if (error !== null) {
93
- const props = {
94
- error,
95
- resetErrorBoundary: this.resetErrorBoundary
96
- };
97
-
98
- if ( /*#__PURE__*/React.isValidElement(fallback)) {
99
- return fallback;
100
- } else if (typeof fallbackRender === 'function') {
101
- return fallbackRender(props);
102
- } else if (FallbackComponent) {
103
- return /*#__PURE__*/React.createElement(FallbackComponent, props);
104
- } else {
105
- throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
106
- }
107
- }
108
-
109
- return this.props.children;
110
- }
111
-
112
- }
113
-
114
17
  /**
115
18
  * Copyright (c) Meta Platforms, Inc. and affiliates.
116
19
  *
@@ -168,19 +71,7 @@ function useCanShowPlaceholder(editor) {
168
71
  * LICENSE file in the root directory of this source tree.
169
72
  *
170
73
  */
171
-
172
- const fallbackRenderer$1 = () => null;
173
-
174
- const DefaultErrorBoundary$1 = ({
175
- children,
176
- onError
177
- }) => /*#__PURE__*/React.createElement(ErrorBoundary, {
178
- fallbackRender: fallbackRenderer$1,
179
- onError: onError
180
- }, children);
181
-
182
- function useDecorators(editor, // TODO 0.6 Make non-optional non-default
183
- ErrorBoundary = DefaultErrorBoundary$1) {
74
+ function useDecorators(editor, ErrorBoundary) {
184
75
  const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
185
76
 
186
77
  useLayoutEffect(() => {
@@ -240,22 +131,10 @@ function usePlainTextSetup(editor) {
240
131
  * LICENSE file in the root directory of this source tree.
241
132
  *
242
133
  */
243
-
244
- const fallbackRenderer = () => null;
245
-
246
- const DefaultErrorBoundary = ({
247
- children,
248
- onError
249
- }) => /*#__PURE__*/React.createElement(ErrorBoundary, {
250
- fallbackRender: fallbackRenderer,
251
- onError: onError
252
- }, children);
253
-
254
134
  function PlainTextPlugin({
255
135
  contentEditable,
256
136
  placeholder,
257
- // TODO 0.6 Make non-optional non-default
258
- ErrorBoundary = DefaultErrorBoundary
137
+ ErrorBoundary
259
138
  }) {
260
139
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
261
140
  const showPlaceholder = useCanShowPlaceholder(editor);
@@ -19,6 +19,5 @@ type InitialEditorStateType =
19
19
  declare export function PlainTextPlugin({
20
20
  contentEditable: React$Node,
21
21
  placeholder: React$Node,
22
- // TODO 0.6 Make non-optional non-default
23
- ErrorBoundary?: ErrorBoundaryType,
22
+ ErrorBoundary: ErrorBoundaryType,
24
23
  }): React$Node;
@@ -4,10 +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 d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),p=require("@lexical/dragon"),q=require("@lexical/plain-text");let t=(a=[],b=[])=>a.length!==b.length||a.some((e,c)=>!Object.is(e,b[c])),u={error:null};
8
- class v extends h.Component{constructor(a){super(a);this.state=u;this.resetErrorBoundary=this.resetErrorBoundary.bind(this)}static getDerivedStateFromError(a){return{error:a}}resetErrorBoundary(...a){this.props.onReset&&this.props.onReset(...a);this.reset()}reset(){this.setState(u)}componentDidCatch(a,b){this.props.onError&&this.props.onError(a,b)}componentDidUpdate(a,b){let {error:e}=this.state,{resetKeys:c}=this.props;null!==e&&null!==b.error&&t(a.resetKeys,c)&&(this.props.onResetKeysChange&&this.props.onResetKeysChange(a.resetKeys,
9
- c),this.reset())}render(){var {error:a}=this.state;let {fallbackRender:b,FallbackComponent:e,fallback:c}=this.props;if(null!==a){a={error:a,resetErrorBoundary:this.resetErrorBoundary};if(h.isValidElement(c))return c;if("function"===typeof b)return b(a);if(e)return h.createElement(e,a);throw Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop");}return this.props.children}}
10
- var w="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function x(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.isEditable()))}function y(a){let [b,e]=h.useState(()=>x(a));w(()=>{function c(){let f=x(a);e(f)}c();return m.mergeRegister(a.registerUpdateListener(()=>{c()}),a.registerEditableListener(()=>{c()}))},[a]);return b}
11
- let z=()=>null,A=({children:a,onError:b})=>h.createElement(v,{fallbackRender:z,onError:b},a);
12
- function B(a,b=A){let [e,c]=h.useState(()=>a.getDecorators());w(()=>a.registerDecoratorListener(f=>{n.flushSync(()=>{c(f)})}),[a]);h.useEffect(()=>{c(a.getDecorators())},[a]);return h.useMemo(()=>{let f=[],r=Object.keys(e);for(let k=0;k<r.length;k++){var g=r[k];let D=h.createElement(b,{onError:C=>a._onError(C)},h.createElement(h.Suspense,{fallback:null},e[g]));g=a.getElementByKey(g);null!==g&&f.push(n.createPortal(D,g))}return f},[b,e,a])}
13
- function E(a){w(()=>m.mergeRegister(q.registerPlainText(a),p.registerDragonSupport(a)),[a])}let F=()=>null,G=({children:a,onError:b})=>h.createElement(v,{fallbackRender:F,onError:b},a);exports.PlainTextPlugin=function({contentEditable:a,placeholder:b,ErrorBoundary:e=G}){let [c]=d.useLexicalComposerContext(),f=y(c);e=B(c,e);E(c);return h.createElement(h.Fragment,null,a,f&&b,e)}
7
+ 'use strict';var b=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),q=require("@lexical/dragon"),r=require("@lexical/plain-text"),t="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function u(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.isEditable()))}
8
+ function v(a){let [f,d]=h.useState(()=>u(a));t(()=>{function c(){let e=u(a);d(e)}c();return m.mergeRegister(a.registerUpdateListener(()=>{c()}),a.registerEditableListener(()=>{c()}))},[a]);return f}
9
+ function w(a,f){let [d,c]=h.useState(()=>a.getDecorators());t(()=>a.registerDecoratorListener(e=>{n.flushSync(()=>{c(e)})}),[a]);h.useEffect(()=>{c(a.getDecorators())},[a]);return h.useMemo(()=>{let e=[],p=Object.keys(d);for(let k=0;k<p.length;k++){var g=p[k];let y=h.createElement(f,{onError:x=>a._onError(x)},h.createElement(h.Suspense,{fallback:null},d[g]));g=a.getElementByKey(g);null!==g&&e.push(n.createPortal(y,g))}return e},[f,d,a])}
10
+ function z(a){t(()=>m.mergeRegister(r.registerPlainText(a),q.registerDragonSupport(a)),[a])}exports.PlainTextPlugin=function({contentEditable:a,placeholder:f,ErrorBoundary:d}){let [c]=b.useLexicalComposerContext(),e=v(c);d=w(c,d);z(c);return h.createElement(h.Fragment,null,a,e&&f,d)}
@@ -9,5 +9,5 @@ import { ErrorBoundaryType } from './shared/useDecorators';
9
9
  export declare function RichTextPlugin({ contentEditable, placeholder, ErrorBoundary, }: Readonly<{
10
10
  contentEditable: JSX.Element;
11
11
  placeholder: JSX.Element | string;
12
- ErrorBoundary?: ErrorBoundaryType;
12
+ ErrorBoundary: ErrorBoundaryType;
13
13
  }>): JSX.Element;
@@ -14,103 +14,6 @@ var reactDom = require('react-dom');
14
14
  var dragon = require('@lexical/dragon');
15
15
  var richText = require('@lexical/rich-text');
16
16
 
17
- /**
18
- * Copyright (c) Meta Platforms, Inc. and affiliates.
19
- *
20
- * This source code is licensed under the MIT license found in the
21
- * LICENSE file in the root directory of this source tree.
22
- *
23
- */
24
-
25
- const changedArray = (a = [], b = []) => a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
26
-
27
- const initialState = {
28
- error: null
29
- };
30
-
31
- class ErrorBoundary extends React.Component {
32
- constructor(props) {
33
- super(props);
34
- this.state = initialState;
35
- this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
36
- }
37
-
38
- static getDerivedStateFromError(error) {
39
- return {
40
- error
41
- };
42
- }
43
-
44
- resetErrorBoundary(...args) {
45
- // @ts-ignore
46
- // eslint-disable-next-line no-unused-expressions
47
- this.props.onReset && this.props.onReset(...args);
48
- this.reset();
49
- }
50
-
51
- reset() {
52
- this.setState(initialState);
53
- }
54
-
55
- componentDidCatch(error, info) {
56
- // @ts-ignore
57
- // eslint-disable-next-line no-unused-expressions
58
- this.props.onError && this.props.onError(error, info);
59
- }
60
-
61
- componentDidUpdate(prevProps, prevState) {
62
- const {
63
- error
64
- } = this.state;
65
- const {
66
- resetKeys
67
- } = this.props; // There's an edge case where if the thing that triggered the error
68
- // happens to *also* be in the resetKeys array, we'd end up resetting
69
- // the error boundary immediately. This would likely trigger a second
70
- // error to be thrown.
71
- // So we make sure that we don't check the resetKeys on the first call
72
- // of cDU after the error is set
73
-
74
- if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
75
- // @ts-ignore
76
- // eslint-disable-next-line no-unused-expressions
77
- this.props.onResetKeysChange && this.props.onResetKeysChange(prevProps.resetKeys, resetKeys);
78
- this.reset();
79
- }
80
- }
81
-
82
- render() {
83
- const {
84
- error
85
- } = this.state;
86
- const {
87
- fallbackRender,
88
- FallbackComponent,
89
- fallback
90
- } = this.props;
91
-
92
- if (error !== null) {
93
- const props = {
94
- error,
95
- resetErrorBoundary: this.resetErrorBoundary
96
- };
97
-
98
- if ( /*#__PURE__*/React.isValidElement(fallback)) {
99
- return fallback;
100
- } else if (typeof fallbackRender === 'function') {
101
- return fallbackRender(props);
102
- } else if (FallbackComponent) {
103
- return /*#__PURE__*/React.createElement(FallbackComponent, props);
104
- } else {
105
- throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
106
- }
107
- }
108
-
109
- return this.props.children;
110
- }
111
-
112
- }
113
-
114
17
  /**
115
18
  * Copyright (c) Meta Platforms, Inc. and affiliates.
116
19
  *
@@ -168,19 +71,7 @@ function useCanShowPlaceholder(editor) {
168
71
  * LICENSE file in the root directory of this source tree.
169
72
  *
170
73
  */
171
-
172
- const fallbackRenderer$1 = () => null;
173
-
174
- const DefaultErrorBoundary$1 = ({
175
- children,
176
- onError
177
- }) => /*#__PURE__*/React.createElement(ErrorBoundary, {
178
- fallbackRender: fallbackRenderer$1,
179
- onError: onError
180
- }, children);
181
-
182
- function useDecorators(editor, // TODO 0.6 Make non-optional non-default
183
- ErrorBoundary = DefaultErrorBoundary$1) {
74
+ function useDecorators(editor, ErrorBoundary) {
184
75
  const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
185
76
 
186
77
  useLayoutEffect(() => {
@@ -240,22 +131,10 @@ function useRichTextSetup(editor) {
240
131
  * LICENSE file in the root directory of this source tree.
241
132
  *
242
133
  */
243
-
244
- const fallbackRenderer = () => null;
245
-
246
- const DefaultErrorBoundary = ({
247
- children,
248
- onError
249
- }) => /*#__PURE__*/React.createElement(ErrorBoundary, {
250
- fallbackRender: fallbackRenderer,
251
- onError: onError
252
- }, children);
253
-
254
134
  function RichTextPlugin({
255
135
  contentEditable,
256
136
  placeholder,
257
- // TODO 0.6 Make non-optional non-default
258
- ErrorBoundary = DefaultErrorBoundary
137
+ ErrorBoundary
259
138
  }) {
260
139
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
261
140
  const showPlaceholder = useCanShowPlaceholder(editor);
@@ -19,6 +19,5 @@ type InitialEditorStateType =
19
19
  declare export function RichTextPlugin({
20
20
  contentEditable: React$Node,
21
21
  placeholder: React$Node,
22
- // TODO 0.6 Make non-optional non-default
23
- ErrorBoundary?: ErrorBoundaryType,
22
+ ErrorBoundary: ErrorBoundaryType,
24
23
  }): React$Node;
@@ -4,10 +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 d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),p=require("@lexical/dragon"),q=require("@lexical/rich-text");let t=(a=[],b=[])=>a.length!==b.length||a.some((e,c)=>!Object.is(e,b[c])),u={error:null};
8
- class v extends h.Component{constructor(a){super(a);this.state=u;this.resetErrorBoundary=this.resetErrorBoundary.bind(this)}static getDerivedStateFromError(a){return{error:a}}resetErrorBoundary(...a){this.props.onReset&&this.props.onReset(...a);this.reset()}reset(){this.setState(u)}componentDidCatch(a,b){this.props.onError&&this.props.onError(a,b)}componentDidUpdate(a,b){let {error:e}=this.state,{resetKeys:c}=this.props;null!==e&&null!==b.error&&t(a.resetKeys,c)&&(this.props.onResetKeysChange&&this.props.onResetKeysChange(a.resetKeys,
9
- c),this.reset())}render(){var {error:a}=this.state;let {fallbackRender:b,FallbackComponent:e,fallback:c}=this.props;if(null!==a){a={error:a,resetErrorBoundary:this.resetErrorBoundary};if(h.isValidElement(c))return c;if("function"===typeof b)return b(a);if(e)return h.createElement(e,a);throw Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop");}return this.props.children}}
10
- var w="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function x(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.isEditable()))}function y(a){let [b,e]=h.useState(()=>x(a));w(()=>{function c(){let f=x(a);e(f)}c();return m.mergeRegister(a.registerUpdateListener(()=>{c()}),a.registerEditableListener(()=>{c()}))},[a]);return b}
11
- let z=()=>null,A=({children:a,onError:b})=>h.createElement(v,{fallbackRender:z,onError:b},a);
12
- function B(a,b=A){let [e,c]=h.useState(()=>a.getDecorators());w(()=>a.registerDecoratorListener(f=>{n.flushSync(()=>{c(f)})}),[a]);h.useEffect(()=>{c(a.getDecorators())},[a]);return h.useMemo(()=>{let f=[],r=Object.keys(e);for(let k=0;k<r.length;k++){var g=r[k];let D=h.createElement(b,{onError:C=>a._onError(C)},h.createElement(h.Suspense,{fallback:null},e[g]));g=a.getElementByKey(g);null!==g&&f.push(n.createPortal(D,g))}return f},[b,e,a])}
13
- function E(a){w(()=>m.mergeRegister(q.registerRichText(a),p.registerDragonSupport(a)),[a])}let F=()=>null,G=({children:a,onError:b})=>h.createElement(v,{fallbackRender:F,onError:b},a);exports.RichTextPlugin=function({contentEditable:a,placeholder:b,ErrorBoundary:e=G}){let [c]=d.useLexicalComposerContext(),f=y(c);e=B(c,e);E(c);return h.createElement(h.Fragment,null,a,f&&b,e)}
7
+ 'use strict';var b=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),q=require("@lexical/dragon"),r=require("@lexical/rich-text"),t="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function u(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.isEditable()))}
8
+ function v(a){let [f,d]=h.useState(()=>u(a));t(()=>{function c(){let e=u(a);d(e)}c();return m.mergeRegister(a.registerUpdateListener(()=>{c()}),a.registerEditableListener(()=>{c()}))},[a]);return f}
9
+ function w(a,f){let [d,c]=h.useState(()=>a.getDecorators());t(()=>a.registerDecoratorListener(e=>{n.flushSync(()=>{c(e)})}),[a]);h.useEffect(()=>{c(a.getDecorators())},[a]);return h.useMemo(()=>{let e=[],p=Object.keys(d);for(let k=0;k<p.length;k++){var g=p[k];let y=h.createElement(f,{onError:x=>a._onError(x)},h.createElement(h.Suspense,{fallback:null},d[g]));g=a.getElementByKey(g);null!==g&&e.push(n.createPortal(y,g))}return e},[f,d,a])}
10
+ function z(a){t(()=>m.mergeRegister(r.registerRichText(a),q.registerDragonSupport(a)),[a])}exports.RichTextPlugin=function({contentEditable:a,placeholder:f,ErrorBoundary:d}){let [c]=b.useLexicalComposerContext(),e=v(c);d=w(c,d);z(c);return h.createElement(h.Fragment,null,a,e&&f,d)}
@@ -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 = activeRange;
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"),z="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?x.useLayoutEffect:x.useEffect;class A{constructor(b){this.key=b;this.ref={current:null};this.setRefElement=this.setRefElement.bind(this)}setRefElement(b){this.ref={current:b}}}
8
- let B=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 C(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 D(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 E(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 F(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 G(b){x.startTransition?x.startTransition(b):b()}
12
- function J(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 K(b,a){b=b.getBoundingClientRect();a=a.getBoundingClientRect();return b.top>a.top&&b.top<a.bottom}
13
- function L(b,a,c,e){let [f]=k.useLexicalComposerContext();x.useEffect(()=>{if(null!=a&&null!=b){let q=f.getRootElement(),p=null!=q?J(q,!1):document.body,g=!1,d=K(a,p),m=function(){g||(window.requestAnimationFrame(function(){c();g=!1}),g=!0);const t=K(a,p);t!==d&&(d=t,null!=e&&e(t))},r=new ResizeObserver(c);window.addEventListener("resize",c);document.addEventListener("scroll",m,{capture:!0,passive:!0});r.observe(a);return()=>{r.unobserve(a);window.removeEventListener("resize",c);document.removeEventListener("scroll",
14
- m)}}},[a,f,e,c,b])}let M=w.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
15
- function N({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 m=x.useCallback(h=>{a.update(()=>{const l=E(a,e.match);p(h,l,b,e.match.matchingString)})},[b,a,e.match,p]),r=x.useCallback(h=>{const l=a.getRootElement();null!==l&&(l.setAttribute("aria-activedescendant","typeahead-item-"+h),d(h))},[a]);x.useEffect(()=>()=>{let h=a.getRootElement();null!==h&&h.removeAttribute("aria-activedescendant")},
16
- [a]);z(()=>{null===f?d(null):null===g&&r(0)},[f,g,r]);x.useEffect(()=>n.mergeRegister(a.registerCommand(M,({option:h})=>h.ref&&null!=h.ref.current?(B(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 l=g!==f.length-1?g+1:0;r(l);let u=f[l];null!=u.ref&&u.ref.current&&a.dispatchCommand(M,{index:l,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 l=0!==g?g-1:f.length-1;r(l);l=f[l];null!=l.ref&&l.ref.current&&B(l.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
- m(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());m(f[g]);return!0},w.COMMAND_PRIORITY_CRITICAL)),[m,b,a,f,g,r]);let t=x.useMemo(()=>({options:f,selectOptionAndCleanUp:m,selectedIndex:g,setHighlightedIndex:d}),[m,g,f]);return q(c,t,e.match.matchingString)}
19
- function O(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:m,top:r,width:t,height:h}=b.getRect();d.style.top=`${r+window.pageYOffset}px`;d.style.left=`${m+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]);L(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,m]=x.useState(null);p=O(d,m,p);let r=x.useCallback(()=>{m(null);null!=c&&null!==d&&c()},[c,d]),t=x.useCallback(h=>{m(h);null!=e&&null===d&&e(h)},[e,d]);x.useEffect(()=>{a&&null==d?g.update(()=>{let h=w.$getNodeByKey(a),l=g.getElementByKey(a);if(null!=h&&null!=l){let u=h.getTextContent();G(()=>t({getRect:()=>l.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(N,{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(),[m,r]=x.useState(null);g=O(m,r,g);let t=x.useCallback(()=>{r(null);null!=f&&null!==m&&f()},[f,m]),h=x.useCallback(l=>{r(l);null!=e&&null===m&&e(l)},[e,m]);x.useEffect(()=>{let l=document.createRange(),u=d.registerUpdateListener(()=>{d.getEditorState().read(()=>{const y=l,H=w.$getSelection(),I=D(d);if(w.$isRangeSelection(H)&&
24
- H.isCollapsed()&&null!==I&&null!==y){var v=p(I,d);a(v?v.matchingString:null);null===v||F(d,v.leadOffset)||null===C(v.leadOffset,y)?t():G(()=>h({getRect:()=>y.getBoundingClientRect(),match:v}))}else t()})});return()=>{l=null;u()}},[d,p,a,m,t,h]);return null===m||null===d?null:x.createElement(N,{close:t,resolution:m,editor:d,anchorElementRef:g,options:b,menuRenderFn:q,onSelectOption:c})};exports.PUNCTUATION="\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";
25
- exports.SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND=M;exports.TypeaheadOption=A;exports.getScrollParent=J;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=L
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,28 +8,29 @@
8
8
  "rich-text"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.5.1-next.2",
11
+ "version": "0.6.1-next.0",
12
12
  "dependencies": {
13
- "@lexical/clipboard": "0.5.1-next.2",
14
- "@lexical/code": "0.5.1-next.2",
15
- "@lexical/dragon": "0.5.1-next.2",
16
- "@lexical/hashtag": "0.5.1-next.2",
17
- "@lexical/history": "0.5.1-next.2",
18
- "@lexical/link": "0.5.1-next.2",
19
- "@lexical/list": "0.5.1-next.2",
20
- "@lexical/mark": "0.5.1-next.2",
21
- "@lexical/markdown": "0.5.1-next.2",
22
- "@lexical/overflow": "0.5.1-next.2",
23
- "@lexical/plain-text": "0.5.1-next.2",
24
- "@lexical/rich-text": "0.5.1-next.2",
25
- "@lexical/selection": "0.5.1-next.2",
26
- "@lexical/table": "0.5.1-next.2",
27
- "@lexical/text": "0.5.1-next.2",
28
- "@lexical/utils": "0.5.1-next.2",
29
- "@lexical/yjs": "0.5.1-next.2"
13
+ "@lexical/clipboard": "0.6.1-next.0",
14
+ "@lexical/code": "0.6.1-next.0",
15
+ "@lexical/dragon": "0.6.1-next.0",
16
+ "@lexical/hashtag": "0.6.1-next.0",
17
+ "@lexical/history": "0.6.1-next.0",
18
+ "@lexical/link": "0.6.1-next.0",
19
+ "@lexical/list": "0.6.1-next.0",
20
+ "@lexical/mark": "0.6.1-next.0",
21
+ "@lexical/markdown": "0.6.1-next.0",
22
+ "@lexical/overflow": "0.6.1-next.0",
23
+ "@lexical/plain-text": "0.6.1-next.0",
24
+ "@lexical/rich-text": "0.6.1-next.0",
25
+ "@lexical/selection": "0.6.1-next.0",
26
+ "@lexical/table": "0.6.1-next.0",
27
+ "@lexical/text": "0.6.1-next.0",
28
+ "@lexical/utils": "0.6.1-next.0",
29
+ "@lexical/yjs": "0.6.1-next.0",
30
+ "react-error-boundary": "^3.1.4"
30
31
  },
31
32
  "peerDependencies": {
32
- "lexical": "0.5.1-next.2",
33
+ "lexical": "0.6.1-next.0",
33
34
  "react": ">=17.x",
34
35
  "react-dom": ">=17.x"
35
36
  },
@@ -12,5 +12,5 @@ declare type ErrorBoundaryProps = {
12
12
  onError: (error: Error) => void;
13
13
  };
14
14
  export declare type ErrorBoundaryType = React.ComponentClass<ErrorBoundaryProps> | React.FC<ErrorBoundaryProps>;
15
- export declare function useDecorators(editor: LexicalEditor, ErrorBoundary?: ErrorBoundaryType): Array<JSX.Element>;
15
+ export declare function useDecorators(editor: LexicalEditor, ErrorBoundary: ErrorBoundaryType): Array<JSX.Element>;
16
16
  export {};
@@ -1,63 +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
- import * as React from 'react';
9
- interface FallbackProps {
10
- error: Error;
11
- resetErrorBoundary: (...args: Array<unknown>) => void;
12
- }
13
- interface ErrorBoundaryPropsWithComponent {
14
- onResetKeysChange?: (prevResetKeys: Array<unknown> | undefined, resetKeys: Array<unknown> | undefined) => void;
15
- onReset?: (...args: Array<unknown>) => void;
16
- onError?: (error: Error, info: {
17
- componentStack: string;
18
- }) => void;
19
- resetKeys?: Array<unknown>;
20
- fallback?: never;
21
- FallbackComponent: React.ComponentType<FallbackProps>;
22
- fallbackRender?: never;
23
- }
24
- declare function FallbackRender(props: FallbackProps): React.ReactElement<unknown, string | React.FunctionComponent | typeof React.Component> | null;
25
- interface ErrorBoundaryPropsWithRender {
26
- onResetKeysChange?: (prevResetKeys: Array<unknown> | undefined, resetKeys: Array<unknown> | undefined) => void;
27
- onReset?: (...args: Array<unknown>) => void;
28
- onError?: (error: Error, info: {
29
- componentStack: string;
30
- }) => void;
31
- resetKeys?: Array<unknown>;
32
- fallback?: never;
33
- FallbackComponent?: never;
34
- fallbackRender: typeof FallbackRender;
35
- }
36
- interface ErrorBoundaryPropsWithFallback {
37
- onResetKeysChange?: (prevResetKeys: Array<unknown> | undefined, resetKeys: Array<unknown> | undefined) => void;
38
- onReset?: (...args: Array<unknown>) => void;
39
- onError?: (error: Error, info: {
40
- componentStack: string;
41
- }) => void;
42
- resetKeys?: Array<unknown>;
43
- fallback: React.ReactElement<unknown, string | React.FunctionComponent | typeof React.Component> | null;
44
- FallbackComponent?: never;
45
- fallbackRender?: never;
46
- }
47
- declare type ErrorBoundaryProps = ErrorBoundaryPropsWithFallback | ErrorBoundaryPropsWithComponent | ErrorBoundaryPropsWithRender;
48
- declare type ErrorBoundaryState = {
49
- error: Error | null;
50
- };
51
- declare class ErrorBoundary extends React.Component<React.PropsWithRef<React.PropsWithChildren<ErrorBoundaryProps>>, ErrorBoundaryState> {
52
- state: ErrorBoundaryState;
53
- constructor(props: ErrorBoundaryProps);
54
- static getDerivedStateFromError(error: Error): {
55
- error: Error;
56
- };
57
- resetErrorBoundary(...args: Array<unknown>): void;
58
- reset(): void;
59
- componentDidCatch(error: Error, info: React.ErrorInfo): void;
60
- componentDidUpdate(prevProps: ErrorBoundaryProps, prevState: ErrorBoundaryState): void;
61
- render(): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
62
- }
63
- export { ErrorBoundary };