@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
|
@@ -29,6 +29,10 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
29
29
|
*
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
|
+
|
|
33
|
+
// This workaround is no longer necessary in React 19,
|
|
34
|
+
// but we currently support React >=17.x
|
|
35
|
+
// https://github.com/facebook/react/pull/26395
|
|
32
36
|
const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
|
|
33
37
|
|
|
34
38
|
/**
|
|
@@ -27,6 +27,10 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
27
27
|
*
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
+
|
|
31
|
+
// This workaround is no longer necessary in React 19,
|
|
32
|
+
// but we currently support React >=17.x
|
|
33
|
+
// https://github.com/facebook/react/pull/26395
|
|
30
34
|
const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
|
|
31
35
|
|
|
32
36
|
/**
|
|
@@ -10,26 +10,14 @@
|
|
|
10
10
|
|
|
11
11
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
12
12
|
var useLexicalEditable = require('@lexical/react/useLexicalEditable');
|
|
13
|
-
var React = require('react');
|
|
14
13
|
var text = require('@lexical/text');
|
|
15
14
|
var utils = require('@lexical/utils');
|
|
15
|
+
var react = require('react');
|
|
16
16
|
var reactDom = require('react-dom');
|
|
17
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
17
18
|
var dragon = require('@lexical/dragon');
|
|
18
19
|
var plainText = require('@lexical/plain-text');
|
|
19
20
|
|
|
20
|
-
function _interopNamespaceDefault(e) {
|
|
21
|
-
var n = Object.create(null);
|
|
22
|
-
if (e) {
|
|
23
|
-
for (var k in e) {
|
|
24
|
-
n[k] = e[k];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
n.default = e;
|
|
28
|
-
return n;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
32
|
-
|
|
33
21
|
/**
|
|
34
22
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
35
23
|
*
|
|
@@ -48,7 +36,11 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
48
36
|
*
|
|
49
37
|
*/
|
|
50
38
|
|
|
51
|
-
|
|
39
|
+
|
|
40
|
+
// This workaround is no longer necessary in React 19,
|
|
41
|
+
// but we currently support React >=17.x
|
|
42
|
+
// https://github.com/facebook/react/pull/26395
|
|
43
|
+
const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
|
|
52
44
|
|
|
53
45
|
/**
|
|
54
46
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -63,7 +55,7 @@ function canShowPlaceholderFromCurrentEditorState(editor) {
|
|
|
63
55
|
return currentCanShowPlaceholder;
|
|
64
56
|
}
|
|
65
57
|
function useCanShowPlaceholder(editor) {
|
|
66
|
-
const [canShowPlaceholder, setCanShowPlaceholder] =
|
|
58
|
+
const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
|
|
67
59
|
useLayoutEffectImpl(() => {
|
|
68
60
|
function resetCanShowPlaceholder() {
|
|
69
61
|
const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
|
|
@@ -88,7 +80,7 @@ function useCanShowPlaceholder(editor) {
|
|
|
88
80
|
*/
|
|
89
81
|
|
|
90
82
|
function useDecorators(editor, ErrorBoundary) {
|
|
91
|
-
const [decorators, setDecorators] =
|
|
83
|
+
const [decorators, setDecorators] = react.useState(() => editor.getDecorators());
|
|
92
84
|
|
|
93
85
|
// Subscribe to changes
|
|
94
86
|
useLayoutEffectImpl(() => {
|
|
@@ -98,7 +90,7 @@ function useDecorators(editor, ErrorBoundary) {
|
|
|
98
90
|
});
|
|
99
91
|
});
|
|
100
92
|
}, [editor]);
|
|
101
|
-
|
|
93
|
+
react.useEffect(() => {
|
|
102
94
|
// If the content editable mounts before the subscription is added, then
|
|
103
95
|
// nothing will be rendered on initial pass. We can get around that by
|
|
104
96
|
// ensuring that we set the value.
|
|
@@ -106,16 +98,18 @@ function useDecorators(editor, ErrorBoundary) {
|
|
|
106
98
|
}, [editor]);
|
|
107
99
|
|
|
108
100
|
// Return decorators defined as React Portals
|
|
109
|
-
return
|
|
101
|
+
return react.useMemo(() => {
|
|
110
102
|
const decoratedPortals = [];
|
|
111
103
|
const decoratorKeys = Object.keys(decorators);
|
|
112
104
|
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
113
105
|
const nodeKey = decoratorKeys[i];
|
|
114
|
-
const reactDecorator = /*#__PURE__*/
|
|
115
|
-
onError: e => editor._onError(e)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
106
|
+
const reactDecorator = /*#__PURE__*/jsxRuntime.jsx(ErrorBoundary, {
|
|
107
|
+
onError: e => editor._onError(e),
|
|
108
|
+
children: /*#__PURE__*/jsxRuntime.jsx(react.Suspense, {
|
|
109
|
+
fallback: null,
|
|
110
|
+
children: decorators[nodeKey]
|
|
111
|
+
})
|
|
112
|
+
});
|
|
119
113
|
const element = editor.getElementByKey(nodeKey);
|
|
120
114
|
if (element !== null) {
|
|
121
115
|
decoratedPortals.push( /*#__PURE__*/reactDom.createPortal(reactDecorator, element, nodeKey));
|
|
@@ -158,16 +152,18 @@ function PlainTextPlugin({
|
|
|
158
152
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
159
153
|
const decorators = useDecorators(editor, ErrorBoundary);
|
|
160
154
|
usePlainTextSetup(editor);
|
|
161
|
-
return /*#__PURE__*/
|
|
162
|
-
|
|
163
|
-
|
|
155
|
+
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
156
|
+
children: [contentEditable, /*#__PURE__*/jsxRuntime.jsx(Placeholder, {
|
|
157
|
+
content: placeholder
|
|
158
|
+
}), decorators]
|
|
159
|
+
});
|
|
164
160
|
}
|
|
165
161
|
function Placeholder({
|
|
166
162
|
content
|
|
167
163
|
}) {
|
|
168
164
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
169
165
|
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
170
|
-
const editable = useLexicalEditable();
|
|
166
|
+
const editable = useLexicalEditable.useLexicalEditable();
|
|
171
167
|
if (!showPlaceholder) {
|
|
172
168
|
return null;
|
|
173
169
|
}
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
10
|
-
import useLexicalEditable from '@lexical/react/useLexicalEditable';
|
|
11
|
-
import * as React from 'react';
|
|
12
|
-
import { useLayoutEffect, useEffect, useState, useMemo, Suspense } from 'react';
|
|
10
|
+
import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
|
|
13
11
|
import { $canShowPlaceholderCurry } from '@lexical/text';
|
|
14
12
|
import { mergeRegister } from '@lexical/utils';
|
|
13
|
+
import { useLayoutEffect, useEffect, useState, useMemo, Suspense } from 'react';
|
|
15
14
|
import { flushSync, createPortal } from 'react-dom';
|
|
15
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
16
16
|
import { registerDragonSupport } from '@lexical/dragon';
|
|
17
17
|
import { registerPlainText } from '@lexical/plain-text';
|
|
18
18
|
|
|
@@ -34,6 +34,10 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
34
34
|
*
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
|
+
|
|
38
|
+
// This workaround is no longer necessary in React 19,
|
|
39
|
+
// but we currently support React >=17.x
|
|
40
|
+
// https://github.com/facebook/react/pull/26395
|
|
37
41
|
const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
|
|
38
42
|
|
|
39
43
|
/**
|
|
@@ -97,11 +101,13 @@ function useDecorators(editor, ErrorBoundary) {
|
|
|
97
101
|
const decoratorKeys = Object.keys(decorators);
|
|
98
102
|
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
99
103
|
const nodeKey = decoratorKeys[i];
|
|
100
|
-
const reactDecorator = /*#__PURE__*/
|
|
101
|
-
onError: e => editor._onError(e)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
const reactDecorator = /*#__PURE__*/jsx(ErrorBoundary, {
|
|
105
|
+
onError: e => editor._onError(e),
|
|
106
|
+
children: /*#__PURE__*/jsx(Suspense, {
|
|
107
|
+
fallback: null,
|
|
108
|
+
children: decorators[nodeKey]
|
|
109
|
+
})
|
|
110
|
+
});
|
|
105
111
|
const element = editor.getElementByKey(nodeKey);
|
|
106
112
|
if (element !== null) {
|
|
107
113
|
decoratedPortals.push( /*#__PURE__*/createPortal(reactDecorator, element, nodeKey));
|
|
@@ -144,9 +150,11 @@ function PlainTextPlugin({
|
|
|
144
150
|
const [editor] = useLexicalComposerContext();
|
|
145
151
|
const decorators = useDecorators(editor, ErrorBoundary);
|
|
146
152
|
usePlainTextSetup(editor);
|
|
147
|
-
return /*#__PURE__*/
|
|
148
|
-
|
|
149
|
-
|
|
153
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
154
|
+
children: [contentEditable, /*#__PURE__*/jsx(Placeholder, {
|
|
155
|
+
content: placeholder
|
|
156
|
+
}), decorators]
|
|
157
|
+
});
|
|
150
158
|
}
|
|
151
159
|
function Placeholder({
|
|
152
160
|
content
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import type {EditorState, LexicalEditor} from 'lexical';
|
|
11
11
|
|
|
12
|
-
import typeof LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
|
|
12
|
+
import {typeof LexicalErrorBoundary} from '@lexical/react/LexicalErrorBoundary';
|
|
13
13
|
|
|
14
14
|
import * as React from 'react';
|
|
15
15
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
'use strict';var
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
function
|
|
9
|
+
'use strict';var e=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/react/useLexicalEditable"),h=require("@lexical/text"),m=require("@lexical/utils"),n=require("react"),p=require("react-dom"),q=require("react/jsx-runtime"),u=require("@lexical/dragon"),v=require("@lexical/plain-text");let w="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?n.useLayoutEffect:n.useEffect;
|
|
10
|
+
function x(a){return a.getEditorState().read(h.$canShowPlaceholderCurry(a.isComposing()))}function y(a){let [c,b]=n.useState(()=>x(a));w(()=>{function d(){let f=x(a);b(f)}d();return m.mergeRegister(a.registerUpdateListener(()=>{d()}),a.registerEditableListener(()=>{d()}))},[a]);return c}
|
|
11
|
+
function z(a,c){let [b,d]=n.useState(()=>a.getDecorators());w(()=>a.registerDecoratorListener(f=>{p.flushSync(()=>{d(f)})}),[a]);n.useEffect(()=>{d(a.getDecorators())},[a]);return n.useMemo(()=>{let f=[],r=Object.keys(b);for(let k=0;k<r.length;k++){let l=r[k],B=q.jsx(c,{onError:A=>a._onError(A),children:q.jsx(n.Suspense,{fallback:null,children:b[l]})}),t=a.getElementByKey(l);null!==t&&f.push(p.createPortal(B,t,l))}return f},[c,b,a])}
|
|
12
|
+
function C(a){w(()=>m.mergeRegister(v.registerPlainText(a),u.registerDragonSupport(a)),[a])}function D({content:a}){var [c]=e.useLexicalComposerContext();c=y(c);let b=g.useLexicalEditable();return c?"function"===typeof a?a(b):a:null}exports.PlainTextPlugin=function({contentEditable:a,placeholder:c,ErrorBoundary:b}){let [d]=e.useLexicalComposerContext();b=z(d,b);C(d);return q.jsxs(q.Fragment,{children:[a,q.jsx(D,{content:c}),b]})}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{useLexicalComposerContext as
|
|
9
|
+
import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as e}from"@lexical/react/useLexicalEditable";import{$canShowPlaceholderCurry as r}from"@lexical/text";import{mergeRegister as o}from"@lexical/utils";import{useLayoutEffect as n,useEffect as i,useState as c,useMemo as l,Suspense as a}from"react";import{flushSync as m,createPortal as u}from"react-dom";import{jsx as s,jsxs as d,Fragment as f}from"react/jsx-runtime";import{registerDragonSupport as p}from"@lexical/dragon";import{registerPlainText as x}from"@lexical/plain-text";const g="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?n:i;function E(t){return t.getEditorState().read(r(t.isComposing()))}function h({contentEditable:e,placeholder:r,ErrorBoundary:n}){const[E]=t(),h=function(t,e){const[r,o]=c((()=>t.getDecorators()));return g((()=>t.registerDecoratorListener((t=>{m((()=>{o(t)}))}))),[t]),i((()=>{o(t.getDecorators())}),[t]),l((()=>{const o=[],n=Object.keys(r);for(let i=0;i<n.length;i++){const c=n[i],l=s(e,{onError:e=>t._onError(e),children:s(a,{fallback:null,children:r[c]})}),m=t.getElementByKey(c);null!==m&&o.push(u(l,m,c))}return o}),[e,r,t])}(E,n);return function(t){g((()=>o(x(t),p(t))),[t])}(E),d(f,{children:[e,s(w,{content:r}),h]})}function w({content:r}){const[n]=t(),i=function(t){const[e,r]=c((()=>E(t)));return g((()=>{function e(){const e=E(t);r(e)}return e(),o(t.registerUpdateListener((()=>{e()})),t.registerEditableListener((()=>{e()})))}),[t]),e}(n),l=e();return i?"function"==typeof r?r(l):r:null}export{h as PlainTextPlugin};
|
|
@@ -10,26 +10,14 @@
|
|
|
10
10
|
|
|
11
11
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
12
12
|
var useLexicalEditable = require('@lexical/react/useLexicalEditable');
|
|
13
|
-
var React = require('react');
|
|
14
13
|
var text = require('@lexical/text');
|
|
15
14
|
var utils = require('@lexical/utils');
|
|
15
|
+
var react = require('react');
|
|
16
16
|
var reactDom = require('react-dom');
|
|
17
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
17
18
|
var dragon = require('@lexical/dragon');
|
|
18
19
|
var richText = require('@lexical/rich-text');
|
|
19
20
|
|
|
20
|
-
function _interopNamespaceDefault(e) {
|
|
21
|
-
var n = Object.create(null);
|
|
22
|
-
if (e) {
|
|
23
|
-
for (var k in e) {
|
|
24
|
-
n[k] = e[k];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
n.default = e;
|
|
28
|
-
return n;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
32
|
-
|
|
33
21
|
/**
|
|
34
22
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
35
23
|
*
|
|
@@ -48,7 +36,11 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
48
36
|
*
|
|
49
37
|
*/
|
|
50
38
|
|
|
51
|
-
|
|
39
|
+
|
|
40
|
+
// This workaround is no longer necessary in React 19,
|
|
41
|
+
// but we currently support React >=17.x
|
|
42
|
+
// https://github.com/facebook/react/pull/26395
|
|
43
|
+
const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
|
|
52
44
|
|
|
53
45
|
/**
|
|
54
46
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -63,7 +55,7 @@ function canShowPlaceholderFromCurrentEditorState(editor) {
|
|
|
63
55
|
return currentCanShowPlaceholder;
|
|
64
56
|
}
|
|
65
57
|
function useCanShowPlaceholder(editor) {
|
|
66
|
-
const [canShowPlaceholder, setCanShowPlaceholder] =
|
|
58
|
+
const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
|
|
67
59
|
useLayoutEffectImpl(() => {
|
|
68
60
|
function resetCanShowPlaceholder() {
|
|
69
61
|
const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
|
|
@@ -88,7 +80,7 @@ function useCanShowPlaceholder(editor) {
|
|
|
88
80
|
*/
|
|
89
81
|
|
|
90
82
|
function useDecorators(editor, ErrorBoundary) {
|
|
91
|
-
const [decorators, setDecorators] =
|
|
83
|
+
const [decorators, setDecorators] = react.useState(() => editor.getDecorators());
|
|
92
84
|
|
|
93
85
|
// Subscribe to changes
|
|
94
86
|
useLayoutEffectImpl(() => {
|
|
@@ -98,7 +90,7 @@ function useDecorators(editor, ErrorBoundary) {
|
|
|
98
90
|
});
|
|
99
91
|
});
|
|
100
92
|
}, [editor]);
|
|
101
|
-
|
|
93
|
+
react.useEffect(() => {
|
|
102
94
|
// If the content editable mounts before the subscription is added, then
|
|
103
95
|
// nothing will be rendered on initial pass. We can get around that by
|
|
104
96
|
// ensuring that we set the value.
|
|
@@ -106,16 +98,18 @@ function useDecorators(editor, ErrorBoundary) {
|
|
|
106
98
|
}, [editor]);
|
|
107
99
|
|
|
108
100
|
// Return decorators defined as React Portals
|
|
109
|
-
return
|
|
101
|
+
return react.useMemo(() => {
|
|
110
102
|
const decoratedPortals = [];
|
|
111
103
|
const decoratorKeys = Object.keys(decorators);
|
|
112
104
|
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
113
105
|
const nodeKey = decoratorKeys[i];
|
|
114
|
-
const reactDecorator = /*#__PURE__*/
|
|
115
|
-
onError: e => editor._onError(e)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
106
|
+
const reactDecorator = /*#__PURE__*/jsxRuntime.jsx(ErrorBoundary, {
|
|
107
|
+
onError: e => editor._onError(e),
|
|
108
|
+
children: /*#__PURE__*/jsxRuntime.jsx(react.Suspense, {
|
|
109
|
+
fallback: null,
|
|
110
|
+
children: decorators[nodeKey]
|
|
111
|
+
})
|
|
112
|
+
});
|
|
119
113
|
const element = editor.getElementByKey(nodeKey);
|
|
120
114
|
if (element !== null) {
|
|
121
115
|
decoratedPortals.push( /*#__PURE__*/reactDom.createPortal(reactDecorator, element, nodeKey));
|
|
@@ -158,16 +152,18 @@ function RichTextPlugin({
|
|
|
158
152
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
159
153
|
const decorators = useDecorators(editor, ErrorBoundary);
|
|
160
154
|
useRichTextSetup(editor);
|
|
161
|
-
return /*#__PURE__*/
|
|
162
|
-
|
|
163
|
-
|
|
155
|
+
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
156
|
+
children: [contentEditable, /*#__PURE__*/jsxRuntime.jsx(Placeholder, {
|
|
157
|
+
content: placeholder
|
|
158
|
+
}), decorators]
|
|
159
|
+
});
|
|
164
160
|
}
|
|
165
161
|
function Placeholder({
|
|
166
162
|
content
|
|
167
163
|
}) {
|
|
168
164
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
169
165
|
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
170
|
-
const editable = useLexicalEditable();
|
|
166
|
+
const editable = useLexicalEditable.useLexicalEditable();
|
|
171
167
|
if (!showPlaceholder) {
|
|
172
168
|
return null;
|
|
173
169
|
}
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
10
|
-
import useLexicalEditable from '@lexical/react/useLexicalEditable';
|
|
11
|
-
import * as React from 'react';
|
|
12
|
-
import { useLayoutEffect, useEffect, useState, useMemo, Suspense } from 'react';
|
|
10
|
+
import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
|
|
13
11
|
import { $canShowPlaceholderCurry } from '@lexical/text';
|
|
14
12
|
import { mergeRegister } from '@lexical/utils';
|
|
13
|
+
import { useLayoutEffect, useEffect, useState, useMemo, Suspense } from 'react';
|
|
15
14
|
import { flushSync, createPortal } from 'react-dom';
|
|
15
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
16
16
|
import { registerDragonSupport } from '@lexical/dragon';
|
|
17
17
|
import { registerRichText } from '@lexical/rich-text';
|
|
18
18
|
|
|
@@ -34,6 +34,10 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
34
34
|
*
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
|
+
|
|
38
|
+
// This workaround is no longer necessary in React 19,
|
|
39
|
+
// but we currently support React >=17.x
|
|
40
|
+
// https://github.com/facebook/react/pull/26395
|
|
37
41
|
const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
|
|
38
42
|
|
|
39
43
|
/**
|
|
@@ -97,11 +101,13 @@ function useDecorators(editor, ErrorBoundary) {
|
|
|
97
101
|
const decoratorKeys = Object.keys(decorators);
|
|
98
102
|
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
99
103
|
const nodeKey = decoratorKeys[i];
|
|
100
|
-
const reactDecorator = /*#__PURE__*/
|
|
101
|
-
onError: e => editor._onError(e)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
const reactDecorator = /*#__PURE__*/jsx(ErrorBoundary, {
|
|
105
|
+
onError: e => editor._onError(e),
|
|
106
|
+
children: /*#__PURE__*/jsx(Suspense, {
|
|
107
|
+
fallback: null,
|
|
108
|
+
children: decorators[nodeKey]
|
|
109
|
+
})
|
|
110
|
+
});
|
|
105
111
|
const element = editor.getElementByKey(nodeKey);
|
|
106
112
|
if (element !== null) {
|
|
107
113
|
decoratedPortals.push( /*#__PURE__*/createPortal(reactDecorator, element, nodeKey));
|
|
@@ -144,9 +150,11 @@ function RichTextPlugin({
|
|
|
144
150
|
const [editor] = useLexicalComposerContext();
|
|
145
151
|
const decorators = useDecorators(editor, ErrorBoundary);
|
|
146
152
|
useRichTextSetup(editor);
|
|
147
|
-
return /*#__PURE__*/
|
|
148
|
-
|
|
149
|
-
|
|
153
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
154
|
+
children: [contentEditable, /*#__PURE__*/jsx(Placeholder, {
|
|
155
|
+
content: placeholder
|
|
156
|
+
}), decorators]
|
|
157
|
+
});
|
|
150
158
|
}
|
|
151
159
|
function Placeholder({
|
|
152
160
|
content
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import type {EditorState, LexicalEditor} from 'lexical';
|
|
11
11
|
|
|
12
|
-
import typeof LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
|
|
12
|
+
import {typeof LexicalErrorBoundary} from '@lexical/react/LexicalErrorBoundary';
|
|
13
13
|
|
|
14
14
|
import * as React from 'react';
|
|
15
15
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
'use strict';var
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
function
|
|
9
|
+
'use strict';var e=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/react/useLexicalEditable"),h=require("@lexical/text"),m=require("@lexical/utils"),n=require("react"),p=require("react-dom"),q=require("react/jsx-runtime"),u=require("@lexical/dragon"),v=require("@lexical/rich-text");let w="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?n.useLayoutEffect:n.useEffect;
|
|
10
|
+
function x(a){return a.getEditorState().read(h.$canShowPlaceholderCurry(a.isComposing()))}function y(a){let [c,b]=n.useState(()=>x(a));w(()=>{function d(){let f=x(a);b(f)}d();return m.mergeRegister(a.registerUpdateListener(()=>{d()}),a.registerEditableListener(()=>{d()}))},[a]);return c}
|
|
11
|
+
function z(a,c){let [b,d]=n.useState(()=>a.getDecorators());w(()=>a.registerDecoratorListener(f=>{p.flushSync(()=>{d(f)})}),[a]);n.useEffect(()=>{d(a.getDecorators())},[a]);return n.useMemo(()=>{let f=[],r=Object.keys(b);for(let k=0;k<r.length;k++){let l=r[k],B=q.jsx(c,{onError:A=>a._onError(A),children:q.jsx(n.Suspense,{fallback:null,children:b[l]})}),t=a.getElementByKey(l);null!==t&&f.push(p.createPortal(B,t,l))}return f},[c,b,a])}
|
|
12
|
+
function C(a){w(()=>m.mergeRegister(v.registerRichText(a),u.registerDragonSupport(a)),[a])}function D({content:a}){var [c]=e.useLexicalComposerContext();c=y(c);let b=g.useLexicalEditable();return c?"function"===typeof a?a(b):a:null}exports.RichTextPlugin=function({contentEditable:a,placeholder:c,ErrorBoundary:b}){let [d]=e.useLexicalComposerContext();b=z(d,b);C(d);return q.jsxs(q.Fragment,{children:[a,q.jsx(D,{content:c}),b]})}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{useLexicalComposerContext as
|
|
9
|
+
import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as e}from"@lexical/react/useLexicalEditable";import{$canShowPlaceholderCurry as r}from"@lexical/text";import{mergeRegister as o}from"@lexical/utils";import{useLayoutEffect as n,useEffect as i,useState as c,useMemo as l,Suspense as a}from"react";import{flushSync as m,createPortal as u}from"react-dom";import{jsx as s,jsxs as d,Fragment as f}from"react/jsx-runtime";import{registerDragonSupport as p}from"@lexical/dragon";import{registerRichText as x}from"@lexical/rich-text";const g="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?n:i;function E(t){return t.getEditorState().read(r(t.isComposing()))}function h({contentEditable:e,placeholder:r,ErrorBoundary:n}){const[E]=t(),h=function(t,e){const[r,o]=c((()=>t.getDecorators()));return g((()=>t.registerDecoratorListener((t=>{m((()=>{o(t)}))}))),[t]),i((()=>{o(t.getDecorators())}),[t]),l((()=>{const o=[],n=Object.keys(r);for(let i=0;i<n.length;i++){const c=n[i],l=s(e,{onError:e=>t._onError(e),children:s(a,{fallback:null,children:r[c]})}),m=t.getElementByKey(c);null!==m&&o.push(u(l,m,c))}return o}),[e,r,t])}(E,n);return function(t){g((()=>o(x(t),p(t))),[t])}(E),d(f,{children:[e,s(w,{content:r}),h]})}function w({content:r}){const[n]=t(),i=function(t){const[e,r]=c((()=>E(t)));return g((()=>{function e(){const e=E(t);r(e)}return e(),o(t.registerUpdateListener((()=>{e()})),t.registerEditableListener((()=>{e()})))}),[t]),e}(n),l=e();return i?"function"==typeof r?r(l):r:null}export{h as RichTextPlugin};
|
|
@@ -5,16 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
export type TableOfContentsEntry
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
tag: HeadingTagType
|
|
15
|
-
];
|
|
16
|
-
type Props = {
|
|
17
|
-
children: (values: Array<TableOfContentsEntry>, editor: LexicalEditor) => JSX.Element;
|
|
18
|
-
};
|
|
19
|
-
export default function LexicalTableOfContentsPlugin({ children, }: Props): JSX.Element;
|
|
20
|
-
export {};
|
|
8
|
+
/** @deprecated moved to @lexical/react/LexicalTableOfContentsPlugin */
|
|
9
|
+
import { type TableOfContentsEntry, TableOfContentsPlugin } from './LexicalTableOfContentsPlugin';
|
|
10
|
+
/** @deprecated use the module @lexical/react/LexicalTableOfContentsPlugin */
|
|
11
|
+
export { type TableOfContentsEntry };
|
|
12
|
+
/** @deprecated use module @lexical/react/LexicalTableOfContentsPlugin */
|
|
13
|
+
export default TableOfContentsPlugin;
|
|
@@ -101,7 +101,7 @@ function $getPreviousHeading(node) {
|
|
|
101
101
|
}
|
|
102
102
|
return prevHeading;
|
|
103
103
|
}
|
|
104
|
-
function
|
|
104
|
+
function TableOfContentsPlugin({
|
|
105
105
|
children
|
|
106
106
|
}) {
|
|
107
107
|
const [tableOfContents, setTableOfContents] = react.useState([]);
|
|
@@ -195,4 +195,12 @@ function LexicalTableOfContentsPlugin({
|
|
|
195
195
|
return children(tableOfContents, editor);
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
200
|
+
*
|
|
201
|
+
* This source code is licensed under the MIT license found in the
|
|
202
|
+
* LICENSE file in the root directory of this source tree.
|
|
203
|
+
*
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
exports.default = TableOfContentsPlugin;
|
|
@@ -99,7 +99,7 @@ function $getPreviousHeading(node) {
|
|
|
99
99
|
}
|
|
100
100
|
return prevHeading;
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function TableOfContentsPlugin({
|
|
103
103
|
children
|
|
104
104
|
}) {
|
|
105
105
|
const [tableOfContents, setTableOfContents] = useState([]);
|
|
@@ -193,4 +193,12 @@ function LexicalTableOfContentsPlugin({
|
|
|
193
193
|
return children(tableOfContents, editor);
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
|
|
196
|
+
/**
|
|
197
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
198
|
+
*
|
|
199
|
+
* This source code is licensed under the MIT license found in the
|
|
200
|
+
* LICENSE file in the root directory of this source tree.
|
|
201
|
+
*
|
|
202
|
+
*/
|
|
203
|
+
|
|
204
|
+
export { TableOfContentsPlugin as default };
|
|
@@ -7,11 +7,7 @@
|
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import
|
|
11
|
-
import type {NodeKey} from 'lexical';
|
|
10
|
+
import {TableOfContentsPlugin} from '@lexical/react/LexicalTableOfContentsPlugin';
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
tableOfContents: Array<[NodeKey, string, HeadingTagType]>,
|
|
16
|
-
) => React$Node,
|
|
17
|
-
}): React$Node;
|
|
12
|
+
/** @deprecated use the named export {@link LexicalTableOfContentsPlugin} */
|
|
13
|
+
declare export default typeof TableOfContentsPlugin;
|
|
@@ -7,6 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';var h=require("@lexical/react/LexicalComposerContext"),q=require("@lexical/rich-text"),v=require("@lexical/utils"),w=require("lexical"),x=require("react");function y(d){return[d.getKey(),d.getTextContent(),d.getTag()]}function z(d,t,n){let e=[],c=y(t);d||e.push(c);for(let r of n)r[0]!==t.getKey()&&(e.push(r),d&&r[0]===d.getKey()&&e.push(c));return e}function B(d){for(d=v.$getNextRightPreorderNode(d);null!==d&&!q.$isHeadingNode(d);)d=v.$getNextRightPreorderNode(d);return d}
|
|
10
|
-
|
|
10
|
+
exports.default=function({children:d}){let [t,n]=x.useState([]),[e]=h.useLexicalComposerContext();x.useEffect(()=>{let c=[];e.getEditorState().read(()=>{let l=w.$getRoot().getChildren();for(let a of l)q.$isHeadingNode(a)&&c.push([a.getKey(),a.getTextContent(),a.getTag()]);n(c)});let r=e.registerUpdateListener(({editorState:l,dirtyElements:a})=>{l.read(()=>{const f=b=>{for(const g of b.getChildren())q.$isHeadingNode(g)?(b=B(g),c=z(b,g,c),n(c)):w.$isElementNode(g)&&f(g)};w.$getRoot().getChildren().forEach(b=>
|
|
11
11
|
{w.$isElementNode(b)&&a.get(b.__key)&&f(b)})})}),C=e.registerMutationListener(q.HeadingNode,l=>{e.getEditorState().read(()=>{for(const [g,m]of l)if("created"===m){var a=w.$getNodeByKey(g);if(null!==a)a:{var f=B(a),b=c;if(null===a){c=b;break a}let k=y(a),u=[];if(null===f){if(0<b.length&&b[0][0]===a.__key){c=b;break a}u=[k,...b]}else for(let p=0;p<b.length;p++){let A=b[p][0];u.push(b[p]);if(A===f.getKey()&&A!==a.getKey()){if(p+1<b.length&&b[p+1][0]===a.__key){c=b;break a}u.push(k)}}c=u}}else if("destroyed"===
|
|
12
12
|
m){f=g;a=c;b=[];for(let k of a)k[0]!==f&&b.push(k);c=b}else"updated"===m&&(f=w.$getNodeByKey(g),null!==f&&(a=B(f),c=z(a,f,c)));n(c)})}),D=e.registerMutationListener(w.TextNode,l=>{e.getEditorState().read(()=>{for(const [b,g]of l)if("updated"===g){var a=w.$getNodeByKey(b);if(null!==a&&(a=a.getParentOrThrow(),q.$isHeadingNode(a))){var f=c;let m=[];for(let k of f)k[0]===a.getKey()?m.push(y(a)):m.push(k);c=m;n(c)}}})});return()=>{C();D();r()}},[e]);return d(t,e)}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
/// <reference types="react" />
|
|
9
|
+
import { HeadingTagType } from '@lexical/rich-text';
|
|
10
|
+
import { LexicalEditor, NodeKey } from 'lexical';
|
|
11
|
+
export type TableOfContentsEntry = [
|
|
12
|
+
key: NodeKey,
|
|
13
|
+
text: string,
|
|
14
|
+
tag: HeadingTagType
|
|
15
|
+
];
|
|
16
|
+
type Props = {
|
|
17
|
+
children: (values: Array<TableOfContentsEntry>, editor: LexicalEditor) => JSX.Element;
|
|
18
|
+
};
|
|
19
|
+
export declare function TableOfContentsPlugin({ children }: Props): JSX.Element;
|
|
20
|
+
export {};
|