@lexical/react 0.45.1-nightly.20260619.0 → 0.45.1-nightly.20260622.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/dist/LexicalAutoEmbedPlugin.dev.js +1 -2
- package/dist/LexicalAutoEmbedPlugin.dev.mjs +1 -2
- package/dist/LexicalAutoEmbedPlugin.prod.js +1 -1
- package/dist/LexicalAutoEmbedPlugin.prod.mjs +1 -1
- package/dist/LexicalAutoFocusPlugin.dev.js +4 -1
- package/dist/LexicalAutoFocusPlugin.dev.mjs +4 -1
- package/dist/LexicalAutoFocusPlugin.prod.js +1 -1
- package/dist/LexicalAutoFocusPlugin.prod.mjs +1 -1
- package/dist/LexicalBlockWithAlignableContents.dev.js +2 -2
- package/dist/LexicalBlockWithAlignableContents.dev.mjs +3 -3
- package/dist/LexicalBlockWithAlignableContents.prod.js +1 -1
- package/dist/LexicalBlockWithAlignableContents.prod.mjs +1 -1
- package/dist/LexicalCharacterLimitPlugin.dev.js +2 -2
- package/dist/LexicalCharacterLimitPlugin.dev.mjs +2 -2
- package/dist/LexicalCharacterLimitPlugin.prod.js +1 -1
- package/dist/LexicalCharacterLimitPlugin.prod.mjs +1 -1
- package/dist/LexicalCollaborationPlugin.dev.js +8 -5
- package/dist/LexicalCollaborationPlugin.dev.mjs +6 -3
- package/dist/LexicalCollaborationPlugin.prod.js +1 -1
- package/dist/LexicalCollaborationPlugin.prod.mjs +1 -1
- package/dist/LexicalComposer.dev.js +5 -2
- package/dist/LexicalComposer.dev.mjs +6 -3
- package/dist/LexicalComposer.prod.js +1 -1
- package/dist/LexicalComposer.prod.mjs +1 -1
- package/dist/LexicalContentEditable.dev.js +1 -2
- package/dist/LexicalContentEditable.dev.mjs +1 -2
- package/dist/LexicalContentEditable.prod.js +2 -2
- package/dist/LexicalContentEditable.prod.mjs +2 -2
- package/dist/LexicalDraggableBlockPlugin.dev.js +25 -18
- package/dist/LexicalDraggableBlockPlugin.dev.mjs +20 -13
- package/dist/LexicalDraggableBlockPlugin.prod.js +1 -1
- package/dist/LexicalDraggableBlockPlugin.prod.mjs +1 -1
- package/dist/LexicalHorizontalRuleNode.dev.js +4 -5
- package/dist/LexicalHorizontalRuleNode.dev.mjs +2 -3
- package/dist/LexicalHorizontalRuleNode.prod.js +2 -2
- package/dist/LexicalHorizontalRuleNode.prod.mjs +2 -2
- package/dist/LexicalNodeEventPlugin.dev.js +1 -2
- package/dist/LexicalNodeEventPlugin.dev.mjs +1 -2
- package/dist/LexicalNodeEventPlugin.prod.js +1 -1
- package/dist/LexicalNodeEventPlugin.prod.mjs +1 -1
- package/dist/LexicalNodeMenuPlugin.dev.js +86 -30
- package/dist/LexicalNodeMenuPlugin.dev.mjs +85 -29
- package/dist/LexicalNodeMenuPlugin.prod.js +1 -1
- package/dist/LexicalNodeMenuPlugin.prod.mjs +1 -1
- package/dist/LexicalPlainTextPlugin.dev.js +2 -3
- package/dist/LexicalPlainTextPlugin.dev.mjs +1 -2
- package/dist/LexicalPlainTextPlugin.prod.js +1 -1
- package/dist/LexicalPlainTextPlugin.prod.mjs +1 -1
- package/dist/LexicalReactPluginHostExtension.dev.js +1 -2
- package/dist/LexicalReactPluginHostExtension.dev.mjs +1 -2
- package/dist/LexicalReactPluginHostExtension.prod.js +1 -1
- package/dist/LexicalReactPluginHostExtension.prod.mjs +1 -1
- package/dist/LexicalRichTextPlugin.dev.js +2 -3
- package/dist/LexicalRichTextPlugin.dev.mjs +1 -2
- package/dist/LexicalRichTextPlugin.prod.js +1 -1
- package/dist/LexicalRichTextPlugin.prod.mjs +1 -1
- package/dist/LexicalTreeView.dev.js +2 -2
- package/dist/LexicalTreeView.dev.mjs +1 -1
- package/dist/LexicalTreeView.prod.js +1 -1
- package/dist/LexicalTreeView.prod.mjs +1 -1
- package/dist/LexicalTypeaheadMenuPlugin.d.ts +1 -7
- package/dist/LexicalTypeaheadMenuPlugin.dev.js +92 -61
- package/dist/LexicalTypeaheadMenuPlugin.dev.mjs +91 -60
- package/dist/LexicalTypeaheadMenuPlugin.prod.js +1 -1
- package/dist/LexicalTypeaheadMenuPlugin.prod.mjs +1 -1
- package/dist/shared/LexicalMenu.d.ts +1 -2
- package/dist/shared/getScrollParent.d.ts +19 -0
- package/dist/useLexicalTextEntity.dev.js +2 -2
- package/dist/useLexicalTextEntity.dev.mjs +1 -1
- package/dist/useLexicalTextEntity.prod.js +1 -1
- package/dist/useLexicalTextEntity.prod.mjs +1 -1
- package/package.json +19 -19
- package/src/LexicalAutoEmbedPlugin.tsx +1 -1
- package/src/LexicalAutoFocusPlugin.ts +5 -1
- package/src/LexicalBlockWithAlignableContents.tsx +4 -5
- package/src/LexicalComposer.tsx +9 -2
- package/src/LexicalDraggableBlockPlugin.tsx +32 -12
- package/src/LexicalHorizontalRuleNode.tsx +5 -6
- package/src/LexicalNodeEventPlugin.ts +1 -2
- package/src/LexicalTreeView.tsx +1 -1
- package/src/LexicalTypeaheadMenuPlugin.tsx +7 -38
- package/src/ReactPluginHostExtension.tsx +1 -1
- package/src/shared/LexicalMenu.tsx +50 -38
- package/src/shared/getScrollParent.ts +54 -0
- package/src/shared/useCanShowPlaceholder.ts +1 -1
- package/src/shared/useCharacterLimit.ts +2 -5
- package/src/shared/usePlainTextSetup.ts +1 -1
- package/src/shared/useRichTextSetup.ts +1 -1
- package/src/shared/useYjsCollaboration.tsx +6 -2
- package/src/useLexicalTextEntity.ts +1 -1
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
var link = require('@lexical/link');
|
|
12
12
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
13
13
|
var LexicalNodeMenuPlugin = require('@lexical/react/LexicalNodeMenuPlugin');
|
|
14
|
-
var utils = require('@lexical/utils');
|
|
15
14
|
var lexical = require('lexical');
|
|
16
15
|
var react = require('react');
|
|
17
16
|
var jsxRuntime = require('react/jsx-runtime');
|
|
@@ -124,7 +123,7 @@ function LexicalAutoEmbedPlugin({
|
|
|
124
123
|
}
|
|
125
124
|
}
|
|
126
125
|
};
|
|
127
|
-
return
|
|
126
|
+
return lexical.mergeRegister(...[link.LinkNode, link.AutoLinkNode].map(Klass => editor.registerMutationListener(Klass, (...args) => listener(...args), {
|
|
128
127
|
skipInitialization: true
|
|
129
128
|
})));
|
|
130
129
|
}, [checkIfLinkNodeIsEmbeddable, editor, nodeKey, reset]);
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
import { $isLinkNode, LinkNode, AutoLinkNode } from '@lexical/link';
|
|
10
10
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
11
11
|
import { MenuOption, LexicalNodeMenuPlugin } from '@lexical/react/LexicalNodeMenuPlugin';
|
|
12
|
-
import { mergeRegister } from '
|
|
13
|
-
import { createCommand, $getNodeByKey, COMMAND_PRIORITY_EDITOR, $getSelection, COMMAND_PRIORITY_LOW, PASTE_TAG } from 'lexical';
|
|
12
|
+
import { createCommand, $getNodeByKey, mergeRegister, COMMAND_PRIORITY_EDITOR, $getSelection, COMMAND_PRIORITY_LOW, PASTE_TAG } from 'lexical';
|
|
14
13
|
import { useState, useCallback, useEffect, useMemo } from 'react';
|
|
15
14
|
import { jsx } from 'react/jsx-runtime';
|
|
16
15
|
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/link"),t=require("@lexical/react/LexicalComposerContext"),n=require("@lexical/react/LexicalNodeMenuPlugin"),
|
|
9
|
+
"use strict";var e=require("@lexical/link"),t=require("@lexical/react/LexicalComposerContext"),n=require("@lexical/react/LexicalNodeMenuPlugin"),o=require("lexical"),i=require("react"),l=require("react/jsx-runtime");const r=/* @__PURE__ */o.createCommand("INSERT_EMBED_COMMAND");class s extends n.MenuOption{title;onSelect;constructor(e,t){super(e),this.title=e,this.onSelect=t.onSelect.bind(this)}}exports.AutoEmbedOption=s,exports.INSERT_EMBED_COMMAND=r,exports.LexicalAutoEmbedPlugin=function({embedConfigs:s,onOpenEmbedModalForConfig:u,getMenuOptions:a,menuRenderFn:c,menuCommandPriority:d=o.COMMAND_PRIORITY_LOW}){const[m]=t.useLexicalComposerContext(),[p,f]=i.useState(null),[C,x]=i.useState(null),M=i.useCallback(()=>{f(null),x(null)},[]),N=i.useCallback(async t=>{const n=m.read("latest",function(){const n=o.$getNodeByKey(t);if(e.$isLinkNode(n))return n.getURL()});if(void 0!==n)for(const e of s){null!=await Promise.resolve(e.parseUrl(n))&&(x(e),f(t))}},[m,s]);i.useEffect(()=>o.mergeRegister(...[e.LinkNode,e.AutoLinkNode].map(e=>m.registerMutationListener(e,(...e)=>((e,{updateTags:t,dirtyLeaves:n})=>{for(const[i,l]of e)"created"===l&&t.has(o.PASTE_TAG)&&n.size<=3?N(i):i===p&&M()})(...e),{skipInitialization:!0}))),[N,m,p,M]),i.useEffect(()=>{if(u)return m.registerCommand(r,e=>{const t=s.find(({type:t})=>t===e);return!!t&&(u(t),!0)},o.COMMAND_PRIORITY_EDITOR)},[m,s,u]);const g=i.useCallback(async function(){if(null!=C&&null!=p){const t=m.read("latest",()=>{const t=o.$getNodeByKey(p);return e.$isLinkNode(t)?t:null});if(e.$isLinkNode(t)){const e=await Promise.resolve(C.parseUrl(t.__url));null!=e&&m.update(()=>{o.$getSelection()||t.selectEnd(),C.insertNode(m,e),t.isAttached()&&t.remove()})}}},[C,m,p]),E=i.useMemo(()=>null!=C&&null!=p?a(C,g,M):[],[C,g,a,p,M]),L=i.useCallback((e,t,n)=>{m.update(()=>{e.onSelect(t),n()})},[m]);return null!=p?/*#__PURE__*/l.jsx(n.LexicalNodeMenuPlugin,{nodeKey:p,onClose:M,onSelectOption:L,options:E,menuRenderFn:c,commandPriority:d}):null},exports.URL_MATCHER=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$isLinkNode as e,LinkNode as t,AutoLinkNode as n}from"@lexical/link";import{useLexicalComposerContext as o}from"@lexical/react/LexicalComposerContext";import{MenuOption as r,LexicalNodeMenuPlugin as i}from"@lexical/react/LexicalNodeMenuPlugin";import{
|
|
9
|
+
import{$isLinkNode as e,LinkNode as t,AutoLinkNode as n}from"@lexical/link";import{useLexicalComposerContext as o}from"@lexical/react/LexicalComposerContext";import{MenuOption as r,LexicalNodeMenuPlugin as i}from"@lexical/react/LexicalNodeMenuPlugin";import{createCommand as l,$getNodeByKey as s,mergeRegister as a,COMMAND_PRIORITY_EDITOR as c,$getSelection as u,COMMAND_PRIORITY_LOW as m,PASTE_TAG as d}from"lexical";import{useState as p,useCallback as f,useEffect as x,useMemo as g}from"react";import{jsx as w}from"react/jsx-runtime";const C=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/,y=/* @__PURE__ */l("INSERT_EMBED_COMMAND");class M extends r{title;onSelect;constructor(e,t){super(e),this.title=e,this.onSelect=t.onSelect.bind(this)}}function h({embedConfigs:r,onOpenEmbedModalForConfig:l,getMenuOptions:C,menuRenderFn:M,menuCommandPriority:h=m}){const[S]=o(),[_,v]=p(null),[z,A]=p(null),E=f(()=>{v(null),A(null)},[]),L=f(async t=>{const n=S.read("latest",function(){const n=s(t);if(e(n))return n.getURL()});if(void 0!==n)for(const e of r){null!=await Promise.resolve(e.parseUrl(n))&&(A(e),v(t))}},[S,r]);x(()=>a(...[t,n].map(e=>S.registerMutationListener(e,(...e)=>((e,{updateTags:t,dirtyLeaves:n})=>{for(const[o,r]of e)"created"===r&&t.has(d)&&n.size<=3?L(o):o===_&&E()})(...e),{skipInitialization:!0}))),[L,S,_,E]),x(()=>{if(l)return S.registerCommand(y,e=>{const t=r.find(({type:t})=>t===e);return!!t&&(l(t),!0)},c)},[S,r,l]);const P=f(async function(){if(null!=z&&null!=_){const t=S.read("latest",()=>{const t=s(_);return e(t)?t:null});if(e(t)){const e=await Promise.resolve(z.parseUrl(t.__url));null!=e&&S.update(()=>{u()||t.selectEnd(),z.insertNode(S,e),t.isAttached()&&t.remove()})}}},[z,S,_]),b=g(()=>null!=z&&null!=_?C(z,P,E):[],[z,P,C,_,E]),N=f((e,t,n)=>{S.update(()=>{e.onSelect(t),n()})},[S]);return null!=_?/*#__PURE__*/w(i,{nodeKey:_,onClose:E,onSelectOption:N,options:b,menuRenderFn:M,commandPriority:h}):null}export{M as AutoEmbedOption,y as INSERT_EMBED_COMMAND,h as LexicalAutoEmbedPlugin,C as URL_MATCHER};
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
11
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
12
|
+
var lexical = require('lexical');
|
|
12
13
|
var react = require('react');
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -39,8 +40,10 @@ function AutoFocusPlugin({
|
|
|
39
40
|
// trigger a re-focus on the element. So in the case this occurs, we'll need to correct it.
|
|
40
41
|
// Normally this is fine, Selection API !== Focus API, but fore the intents of the naming
|
|
41
42
|
// of this plugin, which should preserve focus too.
|
|
42
|
-
const activeElement = document.activeElement;
|
|
43
43
|
const rootElement = editor.getRootElement();
|
|
44
|
+
// getActiveElement rather than document.activeElement, which reports
|
|
45
|
+
// the shadow host when the editor is in a shadow root.
|
|
46
|
+
const activeElement = rootElement !== null ? lexical.getActiveElement(rootElement) : null;
|
|
44
47
|
if (rootElement !== null && (activeElement === null || !rootElement.contains(activeElement))) {
|
|
45
48
|
// Note: preventScroll won't work in Webkit.
|
|
46
49
|
rootElement.focus({
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
10
|
+
import { getActiveElement } from 'lexical';
|
|
10
11
|
import { useEffect } from 'react';
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -37,8 +38,10 @@ function AutoFocusPlugin({
|
|
|
37
38
|
// trigger a re-focus on the element. So in the case this occurs, we'll need to correct it.
|
|
38
39
|
// Normally this is fine, Selection API !== Focus API, but fore the intents of the naming
|
|
39
40
|
// of this plugin, which should preserve focus too.
|
|
40
|
-
const activeElement = document.activeElement;
|
|
41
41
|
const rootElement = editor.getRootElement();
|
|
42
|
+
// getActiveElement rather than document.activeElement, which reports
|
|
43
|
+
// the shadow host when the editor is in a shadow root.
|
|
44
|
+
const activeElement = rootElement !== null ? getActiveElement(rootElement) : null;
|
|
42
45
|
if (rootElement !== null && (activeElement === null || !rootElement.contains(activeElement))) {
|
|
43
46
|
// Note: preventScroll won't work in Webkit.
|
|
44
47
|
rootElement.focus({
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react");exports.AutoFocusPlugin=function({defaultSelection:
|
|
9
|
+
"use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("lexical"),l=require("react");exports.AutoFocusPlugin=function({defaultSelection:n}){const[o]=e.useLexicalComposerContext();return l.useEffect(()=>{o.focus(()=>{const e=o.getRootElement(),l=null!==e?t.getActiveElement(e):null;null===e||null!==l&&e.contains(l)||e.focus({preventScroll:!0})},{defaultSelection:n})},[n,o]),null};
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{useLexicalComposerContext as
|
|
9
|
+
import{useLexicalComposerContext as l}from"@lexical/react/LexicalComposerContext";import{getActiveElement as o}from"lexical";import{useEffect as t}from"react";function e({defaultSelection:e}){const[n]=l();return t(()=>{n.focus(()=>{const l=n.getRootElement(),t=null!==l?o(l):null;null===l||null!==t&&l.contains(t)||l.focus({preventScroll:!0})},{defaultSelection:e})},[e,n]),null}export{e as AutoFocusPlugin};
|
|
@@ -43,7 +43,7 @@ function BlockWithAlignableContents({
|
|
|
43
43
|
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection.useLexicalNodeSelection(nodeKey);
|
|
44
44
|
const ref = react.useRef(null);
|
|
45
45
|
react.useEffect(() => {
|
|
46
|
-
return
|
|
46
|
+
return lexical.mergeRegister(editor.registerCommand(lexical.FORMAT_ELEMENT_COMMAND, formatType => {
|
|
47
47
|
if (isSelected) {
|
|
48
48
|
const selection = lexical.$getSelection();
|
|
49
49
|
if (lexical.$isNodeSelection(selection)) {
|
|
@@ -66,7 +66,7 @@ function BlockWithAlignableContents({
|
|
|
66
66
|
}
|
|
67
67
|
return false;
|
|
68
68
|
}, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.CLICK_COMMAND, event => {
|
|
69
|
-
if (event
|
|
69
|
+
if (lexical.getComposedEventTarget(event) === ref.current) {
|
|
70
70
|
event.preventDefault();
|
|
71
71
|
if (!event.shiftKey) {
|
|
72
72
|
clearSelection();
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
10
10
|
import { $isDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode';
|
|
11
11
|
import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
|
|
12
|
-
import {
|
|
13
|
-
import { FORMAT_ELEMENT_COMMAND, $getSelection, $isNodeSelection, $getNodeByKey, $isRangeSelection, COMMAND_PRIORITY_LOW, CLICK_COMMAND } from 'lexical';
|
|
12
|
+
import { $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
|
|
13
|
+
import { mergeRegister, FORMAT_ELEMENT_COMMAND, $getSelection, $isNodeSelection, $getNodeByKey, $isRangeSelection, COMMAND_PRIORITY_LOW, CLICK_COMMAND, getComposedEventTarget } from 'lexical';
|
|
14
14
|
import { useRef, useEffect } from 'react';
|
|
15
15
|
import { jsx } from 'react/jsx-runtime';
|
|
16
16
|
|
|
@@ -64,7 +64,7 @@ function BlockWithAlignableContents({
|
|
|
64
64
|
}
|
|
65
65
|
return false;
|
|
66
66
|
}, COMMAND_PRIORITY_LOW), editor.registerCommand(CLICK_COMMAND, event => {
|
|
67
|
-
if (event
|
|
67
|
+
if (getComposedEventTarget(event) === ref.current) {
|
|
68
68
|
event.preventDefault();
|
|
69
69
|
if (!event.shiftKey) {
|
|
70
70
|
clearSelection();
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("@lexical/react/LexicalDecoratorBlockNode"),r=require("@lexical/react/useLexicalNodeSelection"),o=require("@lexical/utils"),i=require("lexical"),l=require("react"),c=require("react/jsx-runtime");exports.BlockWithAlignableContents=function({children:s,format:
|
|
9
|
+
"use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("@lexical/react/LexicalDecoratorBlockNode"),r=require("@lexical/react/useLexicalNodeSelection"),o=require("@lexical/utils"),i=require("lexical"),l=require("react"),c=require("react/jsx-runtime");exports.BlockWithAlignableContents=function({children:s,format:n,nodeKey:a,className:u}){const[d]=e.useLexicalComposerContext(),[f,m,x]=r.useLexicalNodeSelection(a),N=l.useRef(null);return l.useEffect(()=>i.mergeRegister(d.registerCommand(i.FORMAT_ELEMENT_COMMAND,e=>{if(f){const r=i.$getSelection();if(i.$isNodeSelection(r)){const r=i.$getNodeByKey(a);t.$isDecoratorBlockNode(r)&&r.setFormat(e)}else if(i.$isRangeSelection(r)){const i=r.getNodes();for(const r of i)if(t.$isDecoratorBlockNode(r))r.setFormat(e);else{o.$getNearestBlockElementAncestorOrThrow(r).setFormat(e)}}return!0}return!1},i.COMMAND_PRIORITY_LOW),d.registerCommand(i.CLICK_COMMAND,e=>i.getComposedEventTarget(e)===N.current&&(e.preventDefault(),e.shiftKey||x(),m(!f),!0),i.COMMAND_PRIORITY_LOW)),[x,d,f,a,m]),/*#__PURE__*/c.jsx("div",{className:[u.base,f?u.focus:null].filter(Boolean).join(" "),ref:N,style:{textAlign:n||void 0},children:s})};
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{$isDecoratorBlockNode as
|
|
9
|
+
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{$isDecoratorBlockNode as r}from"@lexical/react/LexicalDecoratorBlockNode";import{useLexicalNodeSelection as t}from"@lexical/react/useLexicalNodeSelection";import{$getNearestBlockElementAncestorOrThrow as o}from"@lexical/utils";import{mergeRegister as i,FORMAT_ELEMENT_COMMAND as l,$getSelection as c,$isNodeSelection as a,$getNodeByKey as m,$isRangeSelection as n,COMMAND_PRIORITY_LOW as s,CLICK_COMMAND as f,getComposedEventTarget as u}from"lexical";import{useRef as x,useEffect as d}from"react";import{jsx as p}from"react/jsx-runtime";function N({children:N,format:g,nodeKey:C,className:h}){const[v]=e(),[y,F,L]=t(C),j=x(null);return d(()=>i(v.registerCommand(l,e=>{if(y){const t=c();if(a(t)){const t=m(C);r(t)&&t.setFormat(e)}else if(n(t)){const i=t.getNodes();for(const t of i)if(r(t))t.setFormat(e);else{o(t).setFormat(e)}}return!0}return!1},s),v.registerCommand(f,e=>u(e)===j.current&&(e.preventDefault(),e.shiftKey||L(),F(!y),!0),s)),[L,v,y,C,F]),/*#__PURE__*/p("div",{className:[h.base,y?h.focus:null].filter(Boolean).join(" "),ref:j,style:{textAlign:g||void 0},children:N})}export{N as BlockWithAlignableContents};
|
|
@@ -48,7 +48,7 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
|
|
|
48
48
|
react.useEffect(() => {
|
|
49
49
|
let text$1 = editor.read('latest', text.$rootTextContent);
|
|
50
50
|
let lastComputedTextLength = 0;
|
|
51
|
-
return
|
|
51
|
+
return lexical.mergeRegister(editor.registerTextContentListener(currentText => {
|
|
52
52
|
text$1 = currentText;
|
|
53
53
|
}), editor.registerUpdateListener(({
|
|
54
54
|
dirtyLeaves,
|
|
@@ -143,7 +143,7 @@ function $wrapOverflowedNodes(offset) {
|
|
|
143
143
|
// below. Element slot values need no special case: their interior is
|
|
144
144
|
// counted leaf-by-leaf like any other subtree.
|
|
145
145
|
const isSlotValueLeaf = lexical.$isLeafNode(node) && lexical.$getSlotHost(node) !== null;
|
|
146
|
-
const needsOverflowParent = lexical.$isLeafNode(node) && !isSlotValueLeaf && !
|
|
146
|
+
const needsOverflowParent = lexical.$isLeafNode(node) && !isSlotValueLeaf && !lexical.$findMatchingParent(node, overflow.$isOverflowNode);
|
|
147
147
|
if (overflow.$isOverflowNode(node)) {
|
|
148
148
|
const previousLength = accumulatedLength;
|
|
149
149
|
const nextLength = accumulatedLength + node.getTextContentSize();
|
|
@@ -10,8 +10,8 @@ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext
|
|
|
10
10
|
import { useEffect, useState, useMemo } from 'react';
|
|
11
11
|
import { OverflowNode, $isOverflowNode, $createOverflowNode } from '@lexical/overflow';
|
|
12
12
|
import { $rootTextContent } from '@lexical/text';
|
|
13
|
-
import {
|
|
14
|
-
import { HISTORY_MERGE_TAG, DELETE_CHARACTER_COMMAND, $getSelection, $isRangeSelection, $isElementNode, COMMAND_PRIORITY_LOW, $isLeafNode, $getSlotHost, $isTextNode, $setSelection } from 'lexical';
|
|
13
|
+
import { $dfsWithSlots, $unwrapNode } from '@lexical/utils';
|
|
14
|
+
import { mergeRegister, HISTORY_MERGE_TAG, DELETE_CHARACTER_COMMAND, $getSelection, $isRangeSelection, $isElementNode, COMMAND_PRIORITY_LOW, $isLeafNode, $getSlotHost, $findMatchingParent, $isTextNode, $setSelection } from 'lexical';
|
|
15
15
|
import { jsx } from 'react/jsx-runtime';
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react"),n=require("@lexical/overflow"),r=require("@lexical/text"),i=require("@lexical/utils"),o=require("lexical"),s=require("react/jsx-runtime");function l(e,s,l=Object.freeze({})){const{strlen:f=e=>e.length,remainingCharacters:g=()=>{}}=l;t.useEffect(()=>{e.hasNodes([n.OverflowNode])||function(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(57)},[e]),t.useEffect(()=>{let t=e.read("latest",r.$rootTextContent),l=0;return
|
|
9
|
+
"use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react"),n=require("@lexical/overflow"),r=require("@lexical/text"),i=require("@lexical/utils"),o=require("lexical"),s=require("react/jsx-runtime");function l(e,s,l=Object.freeze({})){const{strlen:f=e=>e.length,remainingCharacters:g=()=>{}}=l;t.useEffect(()=>{e.hasNodes([n.OverflowNode])||function(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(57)},[e]),t.useEffect(()=>{let t=e.read("latest",r.$rootTextContent),l=0;return o.mergeRegister(e.registerTextContentListener(e=>{t=e}),e.registerUpdateListener(({dirtyLeaves:r,dirtyElements:u})=>{const d=e.isComposing(),h=r.size>0||u.size>0;if(d||!h)return;const m=f(t),x=m>s||null!==l&&l>s;if(g(s-m),null===l||x){const r=function(e,t,n){let r=0,i=0;if("function"==typeof Intl.Segmenter){const o=(new Intl.Segmenter).segment(e);for(const{segment:e}of o){const o=i+n(e);if(o>t)break;i=o,r+=e.length}}else{const o=Array.from(e),s=o.length;for(let e=0;e<s;e++){const s=o[e],l=i+n(s);if(l>t)break;i=l,r+=s.length}}return r}(t,s,f);e.update(()=>{!function(e){const t=i.$dfsWithSlots(),r=t.length;let s=0;for(let l=0;l<r;l+=1){const{node:r}=t[l],f=o.$isLeafNode(r)&&null!==o.$getSlotHost(r),g=o.$isLeafNode(r)&&!f&&!o.$findMatchingParent(r,n.$isOverflowNode);if(n.$isOverflowNode(r)){const t=s;if(s+r.getTextContentSize()<=e){const e=r.getParent(),t=r.getPreviousSibling(),n=r.getNextSibling();i.$unwrapNode(r);const s=o.$getSelection();!o.$isRangeSelection(s)||s.anchor.getNode().isAttached()&&s.focus.getNode().isAttached()||(o.$isTextNode(t)?t.select():o.$isTextNode(n)?n.select():null!==e&&e.select())}else if(t<e){const n=r.getFirstDescendant(),s=t+(null!==n?n.getTextContentSize():0);(o.$isTextNode(n)&&n.isSimpleText()||s<=e)&&i.$unwrapNode(r)}}else if(f)s+=r.getTextContentSize();else if(g){const t=s;if(s+=r.getTextContentSize(),s>e&&!n.$isOverflowNode(r.getParent())){const n=o.$getSelection();let i;if(t<e&&o.$isTextNode(r)&&r.isSimpleText()){const[,n]=r.splitText(e-t);i=c(n)}else i=c(r);null!==n&&o.$setSelection(n),a(i)}}}}(r)},{tag:o.HISTORY_MERGE_TAG})}l=m}),e.registerCommand(o.DELETE_CHARACTER_COMMAND,e=>{const t=o.$getSelection();if(!o.$isRangeSelection(t))return!1;const n=t.anchor.getNode().getParent(),r=n?n.getParent():null,i=r?r.getNextSibling():null;return t.deleteCharacter(e),r&&r.isEmpty()?r.remove():o.$isElementNode(i)&&i.isEmpty()&&i.remove(),!0},o.COMMAND_PRIORITY_LOW))},[e,s,g,f])}function c(e){const t=n.$createOverflowNode();return e.replace(t),t.append(e),t}function a(e){const t=e.getPreviousSibling();if(!n.$isOverflowNode(t))return;const r=e.getFirstChild(),i=t.getChildren(),s=i.length;if(null===r)e.append(...i);else for(let e=0;e<s;e++)r.insertBefore(i[e]);const l=o.$getSelection();if(o.$isRangeSelection(l)){const n=l.anchor,r=n.getNode(),i=l.focus,o=n.getNode();r.is(t)?n.set(e.getKey(),n.offset,"element"):r.is(e)&&n.set(e.getKey(),s+n.offset,"element"),o.is(t)?i.set(e.getKey(),i.offset,"element"):o.is(e)&&i.set(e.getKey(),s+i.offset,"element")}t.remove()}let f=null;function g(e){const t=void 0===window.TextEncoder?null:(null===f&&(f=new window.TextEncoder),f);if(null===t){const t=encodeURIComponent(e).match(/%[89ABab]/g);return e.length+(t?t.length:0)}return t.encode(e).length}function u({remainingCharacters:e}){/*#__PURE__*/
|
|
10
10
|
return s.jsx("span",{className:"characters-limit "+(e<0?"characters-limit-exceeded":""),children:e})}exports.CharacterLimitPlugin=function({charset:n="UTF-16",maxLength:r=5,renderer:i=u}){const[o]=e.useLexicalComposerContext(),[s,c]=t.useState(r),a=t.useMemo(()=>({remainingCharacters:c,strlen:e=>{if("UTF-8"===n)return g(e);if("UTF-16"===n)return e.length;throw new Error("Unrecognized charset")}}),[n]);return l(o,r,a),i({remainingCharacters:s})};
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useEffect as t,useState as n,useMemo as r}from"react";import{OverflowNode as o,$isOverflowNode as i,$createOverflowNode as s}from"@lexical/overflow";import{$rootTextContent as l}from"@lexical/text";import{
|
|
9
|
+
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useEffect as t,useState as n,useMemo as r}from"react";import{OverflowNode as o,$isOverflowNode as i,$createOverflowNode as s}from"@lexical/overflow";import{$rootTextContent as l}from"@lexical/text";import{$dfsWithSlots as c,$unwrapNode as a}from"@lexical/utils";import{mergeRegister as f,HISTORY_MERGE_TAG as g,DELETE_CHARACTER_COMMAND as m,$getSelection as u,$isRangeSelection as d,$isElementNode as h,COMMAND_PRIORITY_LOW as p,$isLeafNode as x,$getSlotHost as C,$findMatchingParent as S,$isTextNode as v,$setSelection as w}from"lexical";import{jsx as T}from"react/jsx-runtime";function y(e,n,r=Object.freeze({})){const{strlen:s=e=>e.length,remainingCharacters:T=()=>{}}=r;t(()=>{e.hasNodes([o])||function(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(57)},[e]),t(()=>{let t=e.read("latest",l),r=0;return f(e.registerTextContentListener(e=>{t=e}),e.registerUpdateListener(({dirtyLeaves:o,dirtyElements:l})=>{const f=e.isComposing(),m=o.size>0||l.size>0;if(f||!m)return;const h=s(t),p=h>n||null!==r&&r>n;if(T(n-h),null===r||p){const r=function(e,t,n){let r=0,o=0;if("function"==typeof Intl.Segmenter){const i=(new Intl.Segmenter).segment(e);for(const{segment:e}of i){const i=o+n(e);if(i>t)break;o=i,r+=e.length}}else{const i=Array.from(e),s=i.length;for(let e=0;e<s;e++){const s=i[e],l=o+n(s);if(l>t)break;o=l,r+=s.length}}return r}(t,n,s);e.update(()=>{!function(e){const t=c(),n=t.length;let r=0;for(let o=0;o<n;o+=1){const{node:n}=t[o],s=x(n)&&null!==C(n),l=x(n)&&!s&&!S(n,i);if(i(n)){const t=r;if(r+n.getTextContentSize()<=e){const e=n.getParent(),t=n.getPreviousSibling(),r=n.getNextSibling();a(n);const o=u();!d(o)||o.anchor.getNode().isAttached()&&o.focus.getNode().isAttached()||(v(t)?t.select():v(r)?r.select():null!==e&&e.select())}else if(t<e){const r=n.getFirstDescendant(),o=t+(null!==r?r.getTextContentSize():0);(v(r)&&r.isSimpleText()||o<=e)&&a(n)}}else if(s)r+=n.getTextContentSize();else if(l){const t=r;if(r+=n.getTextContentSize(),r>e&&!i(n.getParent())){const r=u();let o;if(t<e&&v(n)&&n.isSimpleText()){const[,r]=n.splitText(e-t);o=N(r)}else o=N(n);null!==r&&w(r),b(o)}}}}(r)},{tag:g})}r=h}),e.registerCommand(m,e=>{const t=u();if(!d(t))return!1;const n=t.anchor.getNode().getParent(),r=n?n.getParent():null,o=r?r.getNextSibling():null;return t.deleteCharacter(e),r&&r.isEmpty()?r.remove():h(o)&&o.isEmpty()&&o.remove(),!0},p))},[e,n,T,s])}function N(e){const t=s();return e.replace(t),t.append(e),t}function b(e){const t=e.getPreviousSibling();if(!i(t))return;const n=e.getFirstChild(),r=t.getChildren(),o=r.length;if(null===n)e.append(...r);else for(let e=0;e<o;e++)n.insertBefore(r[e]);const s=u();if(d(s)){const n=s.anchor,r=n.getNode(),i=s.focus,l=n.getNode();r.is(t)?n.set(e.getKey(),n.offset,"element"):r.is(e)&&n.set(e.getKey(),o+n.offset,"element"),l.is(t)?i.set(e.getKey(),i.offset,"element"):l.is(e)&&i.set(e.getKey(),o+i.offset,"element")}t.remove()}let z=null;function L(e){const t=void 0===window.TextEncoder?null:(null===z&&(z=new window.TextEncoder),z);if(null===t){const t=encodeURIComponent(e).match(/%[89ABab]/g);return e.length+(t?t.length:0)}return t.encode(e).length}function U({remainingCharacters:e}){/*#__PURE__*/
|
|
10
10
|
return T("span",{className:"characters-limit "+(e<0?"characters-limit-exceeded":""),children:e})}function E({charset:t="UTF-16",maxLength:o=5,renderer:i=U}){const[s]=e(),[l,c]=n(o);return y(s,o,r(()=>({remainingCharacters:c,strlen:e=>{if("UTF-8"===t)return L(e);if("UTF-16"===t)return e.length;throw new Error("Unrecognized charset")}}),[t])),i({remainingCharacters:l})}export{E as CharacterLimitPlugin};
|
|
@@ -12,7 +12,6 @@ var LexicalCollaborationContext = require('@lexical/react/LexicalCollaborationCo
|
|
|
12
12
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
13
13
|
var yjs = require('@lexical/yjs');
|
|
14
14
|
var React = require('react');
|
|
15
|
-
var utils = require('@lexical/utils');
|
|
16
15
|
var lexical = require('lexical');
|
|
17
16
|
var reactDom = require('react-dom');
|
|
18
17
|
var yjs$1 = require('yjs');
|
|
@@ -145,7 +144,7 @@ function useYjsCollaborationV2__EXPERIMENTAL(editor, id, doc, provider, docMap,
|
|
|
145
144
|
}, [binding, editor, shouldBootstrap]);
|
|
146
145
|
const [diffSnapshots, setDiffSnapshots] = React.useState();
|
|
147
146
|
React.useEffect(() => {
|
|
148
|
-
|
|
147
|
+
lexical.mergeRegister(editor.registerCommand(yjs.CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL, () => {
|
|
149
148
|
setDiffSnapshots(null);
|
|
150
149
|
// Ensure that any state already in Yjs is loaded into the editor (eg: after clearing diff view).
|
|
151
150
|
yjs.syncYjsStateToLexicalV2__EXPERIMENTAL(binding, provider);
|
|
@@ -220,7 +219,11 @@ function useProvider(editor, provider, name, color, isReloadingDoc, awarenessDat
|
|
|
220
219
|
onBootstrap();
|
|
221
220
|
}
|
|
222
221
|
};
|
|
223
|
-
|
|
222
|
+
const rootElement = editor.getRootElement();
|
|
223
|
+
yjs.initLocalState(provider, name, color,
|
|
224
|
+
// getActiveElement rather than document.activeElement, which reports the
|
|
225
|
+
// shadow host when the editor is in a shadow root.
|
|
226
|
+
rootElement !== null && lexical.getActiveElement(rootElement) === rootElement, awarenessData || {});
|
|
224
227
|
provider.on('status', onStatus);
|
|
225
228
|
provider.on('sync', onSync);
|
|
226
229
|
const connectionPromise = connect();
|
|
@@ -315,7 +318,7 @@ function useYjsCursors(binding, cursorsContainerRef) {
|
|
|
315
318
|
}
|
|
316
319
|
function useYjsFocusTracking(editor, provider, name, color, awarenessData) {
|
|
317
320
|
React.useEffect(() => {
|
|
318
|
-
return
|
|
321
|
+
return lexical.mergeRegister(editor.registerCommand(lexical.FOCUS_COMMAND, () => {
|
|
319
322
|
yjs.setLocalStateFocus(provider, name, color, true, awarenessData || {});
|
|
320
323
|
return false;
|
|
321
324
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.BLUR_COMMAND, () => {
|
|
@@ -340,7 +343,7 @@ function useYjsUndoManager(editor, undoManager) {
|
|
|
340
343
|
const redo = () => {
|
|
341
344
|
undoManager.redo();
|
|
342
345
|
};
|
|
343
|
-
return
|
|
346
|
+
return lexical.mergeRegister(editor.registerCommand(lexical.UNDO_COMMAND, () => {
|
|
344
347
|
undo();
|
|
345
348
|
return true;
|
|
346
349
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.REDO_COMMAND, () => {
|
|
@@ -11,8 +11,7 @@ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext
|
|
|
11
11
|
import { syncCursorPositions, syncLexicalUpdateToYjs, createUndoManager, setLocalStateFocus, createBindingV2__EXPERIMENTAL, CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL, syncYjsStateToLexicalV2__EXPERIMENTAL, DIFF_VERSIONS_COMMAND__EXPERIMENTAL, renderSnapshot__EXPERIMENTAL, syncLexicalUpdateToYjsV2__EXPERIMENTAL, syncYjsChangesToLexical, initLocalState, TOGGLE_CONNECT_COMMAND, syncYjsChangesToLexicalV2__EXPERIMENTAL, removeCursorHighlightRule, CONNECTED_COMMAND, createBinding } from '@lexical/yjs';
|
|
12
12
|
import * as React from 'react';
|
|
13
13
|
import { useRef, useCallback, useEffect, useMemo, useState } from 'react';
|
|
14
|
-
import { mergeRegister } from '
|
|
15
|
-
import { SKIP_COLLAB_TAG, FOCUS_COMMAND, COMMAND_PRIORITY_EDITOR, BLUR_COMMAND, $getRoot, HISTORY_MERGE_TAG, $createParagraphNode, $getSelection, UNDO_COMMAND, REDO_COMMAND, CAN_UNDO_COMMAND, CAN_REDO_COMMAND } from 'lexical';
|
|
14
|
+
import { SKIP_COLLAB_TAG, mergeRegister, FOCUS_COMMAND, COMMAND_PRIORITY_EDITOR, BLUR_COMMAND, $getRoot, HISTORY_MERGE_TAG, $createParagraphNode, $getSelection, getActiveElement, UNDO_COMMAND, REDO_COMMAND, CAN_UNDO_COMMAND, CAN_REDO_COMMAND } from 'lexical';
|
|
16
15
|
import { createPortal } from 'react-dom';
|
|
17
16
|
import { UndoManager } from 'yjs';
|
|
18
17
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
@@ -206,7 +205,11 @@ function useProvider(editor, provider, name, color, isReloadingDoc, awarenessDat
|
|
|
206
205
|
onBootstrap();
|
|
207
206
|
}
|
|
208
207
|
};
|
|
209
|
-
|
|
208
|
+
const rootElement = editor.getRootElement();
|
|
209
|
+
initLocalState(provider, name, color,
|
|
210
|
+
// getActiveElement rather than document.activeElement, which reports the
|
|
211
|
+
// shadow host when the editor is in a shadow root.
|
|
212
|
+
rootElement !== null && getActiveElement(rootElement) === rootElement, awarenessData || {});
|
|
210
213
|
provider.on('status', onStatus);
|
|
211
214
|
provider.on('sync', onSync);
|
|
212
215
|
const connectionPromise = connect();
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/react/LexicalCollaborationContext"),t=require("@lexical/react/LexicalComposerContext"),o=require("@lexical/yjs"),n=require("react"),r=require("
|
|
9
|
+
"use strict";var e=require("@lexical/react/LexicalCollaborationContext"),t=require("@lexical/react/LexicalComposerContext"),o=require("@lexical/yjs"),n=require("react"),r=require("lexical"),s=require("react-dom"),a=require("yjs"),c=require("react/jsx-runtime");function i(e){var t=Object.create(null);if(e)for(var o in e)t[o]=e[o];return t.default=e,t}var l=/*#__PURE__*/i(n);const u=Symbol.for("@lexical/yjs/UndoManager");function d(e,t,s,c,i,l,u,d,C,p,m,h,M=o.syncCursorPositions,R=!1){const O=n.useRef(!1),D=n.useCallback(()=>{const{root:t}=d;u&&t.isEmpty()&&0===t._xmlText._length&&_(e,m)},[d,e,m,u]);return n.useEffect(()=>{const{root:t}=d,n=(e,t)=>{const n=t.origin;if(n!==d){const t=n instanceof a.UndoManager;o.syncYjsChangesToLexical(d,s,e,t,M)}};t.getSharedType().observeDeep(n);const c=e.registerUpdateListener(({prevEditorState:e,editorState:t,dirtyLeaves:n,dirtyElements:a,normalizedNodes:c,tags:i})=>{i.has(r.SKIP_COLLAB_TAG)||o.syncLexicalUpdateToYjs(d,s,e,t,a,n,c,i)});return()=>{t.getSharedType().unobserveDeep(n),c()}},[d,s,e,C,c,t,M]),n.useEffect(()=>{const n=n=>{!function(e,t){if(e.update(()=>{const e=r.$getRoot();e.clear(),e.select()},{tag:r.SKIP_COLLAB_TAG}),null==t.cursors)return;const n=t.cursors;if(null==n)return;const s=t.cursorsContainer;if(null==s)return;for(const e of n.values()){const n=e.selection;if(null!==n){null!==n.highlight&&(CSS.highlights.delete(n.highlightName),o.removeCursorHighlightRule(t,n.highlightName)),n.caret.parentNode===s&&s.removeChild(n.caret);for(const e of n.selections)e.parentNode===s&&s.removeChild(e);e.selection=null}}}(e,d),C(n),c.set(t,n),O.current=!0},a=()=>{O.current=!1};return s.on("reload",n),s.on("sync",a),()=>{s.off("reload",n),s.off("sync",a)}},[d,s,e,C,c,t]),f(e,s,i,l,O,h,D),E(d,s,R),g(d,p)}function f(e,t,s,a,c,i,l){const u=n.useCallback(()=>t.connect(),[t]),d=n.useCallback(()=>{try{t.disconnect()}catch(e){}},[t]);n.useEffect(()=>{const n=({status:t})=>{e.dispatchCommand(o.CONNECTED_COMMAND,"connected"===t)},f=e=>{e&&!1===c.current&&l&&l()},E=e.getRootElement();o.initLocalState(t,s,a,null!==E&&r.getActiveElement(E)===E,i||{}),t.on("status",n),t.on("sync",f);const g=u();return()=>{!1===c.current&&(g?g.then(d):d()),t.off("sync",f),t.off("status",n)}},[e,t,s,a,c,i,l,u,d]),n.useEffect(()=>e.registerCommand(o.TOGGLE_CONNECT_COMMAND,e=>(e?(console.log("Collaboration connected!"),u()):(console.log("Collaboration disconnected!"),d()),!0),r.COMMAND_PRIORITY_EDITOR),[u,d,e]),n.useEffect(()=>{const e=()=>{try{t.awareness.setLocalState(null)}catch(e){}};return window.addEventListener("beforeunload",e),window.addEventListener("pagehide",e),()=>{window.removeEventListener("beforeunload",e),window.removeEventListener("pagehide",e)}},[t])}function E(e,t,r){n.useEffect(()=>{const{awareness:n}=t,s=()=>{o.syncCursorPositions(e,t,{selectionHighlight:r})};return n.on("update",s),()=>{n.off("update",s)}},[e,t,r])}function g(e,t){return n.useMemo(()=>/*#__PURE__*/s.createPortal(/*#__PURE__*/c.jsx("div",{ref:t=>{e.cursorsContainer=t}}),t&&t.current||document.body),[e,t])}function C(e,t,s,a,c){n.useEffect(()=>r.mergeRegister(e.registerCommand(r.FOCUS_COMMAND,()=>(o.setLocalStateFocus(t,s,a,!0,c||{}),!1),r.COMMAND_PRIORITY_EDITOR),e.registerCommand(r.BLUR_COMMAND,()=>(o.setLocalStateFocus(t,s,a,!1,c||{}),!1),r.COMMAND_PRIORITY_EDITOR)),[a,e,s,t,c])}function p(e,t){n.useEffect(()=>r.mergeRegister(e.registerCommand(r.UNDO_COMMAND,()=>(t.undo(),!0),r.COMMAND_PRIORITY_EDITOR),e.registerCommand(r.REDO_COMMAND,()=>(t.redo(),!0),r.COMMAND_PRIORITY_EDITOR))),n.useEffect(()=>{const o=e;return o[u]=t,()=>{o[u]===t&&delete o[u]}},[e,t]);const o=n.useCallback(()=>{t.clear()},[t]);return l.useEffect(()=>{const o=()=>{e.dispatchCommand(r.CAN_UNDO_COMMAND,t.undoStack.length>0),e.dispatchCommand(r.CAN_REDO_COMMAND,t.redoStack.length>0)};return t.on("stack-item-added",o),t.on("stack-item-popped",o),t.on("stack-cleared",o),()=>{t.off("stack-item-added",o),t.off("stack-item-popped",o),t.off("stack-cleared",o)}},[e,t]),o}function _(e,t){e.update(()=>{const o=r.$getRoot();if(o.isEmpty())if(t)switch(typeof t){case"string":{const o=e.parseEditorState(t);e.setEditorState(o,{tag:r.HISTORY_MERGE_TAG});break}case"object":e.setEditorState(t,{tag:r.HISTORY_MERGE_TAG});break;case"function":e.update(()=>{r.$getRoot().isEmpty()&&t(e)},{tag:r.HISTORY_MERGE_TAG})}else{const t=r.$createParagraphNode();o.append(t);const{activeElement:n}=document;(null!==r.$getSelection()||null!==n&&n===e.getRootElement())&&t.select()}},{tag:r.HISTORY_MERGE_TAG})}function m({editor:e,id:t,provider:r,yjsDocMap:s,name:a,color:c,shouldBootstrap:i,cursorsContainerRef:l,initialEditorState:u,awarenessData:f,collabContext:E,binding:g,setDoc:_,syncCursorPositionsFn:m,selectionHighlight:h}){const M=d(e,t,r,s,a,c,i,g,_,l,u,f,m,h);return function(e,t){p(e,n.useMemo(()=>o.createUndoManager(t,t.root.getSharedType()),[t]))}(e,g),C(e,r,a,c,f),M}const h=(e,t)=>{n.useEffect(()=>(e.isCollabActive=!0,()=>{null==t._parentEditor&&(e.isCollabActive=!1)}),[e,t])};exports.CollaborationPlugin=function({id:r,providerFactory:s,shouldBootstrap:a,username:i,cursorColor:l,cursorsContainerRef:u,initialEditorState:d,excludedProperties:f,awarenessData:E,syncCursorPositionsFn:g,selectionHighlight:C}){const p=n.useRef(!1),_=n.useRef(!1),M=e.useCollaborationContext(i,l),{yjsDocMap:R,name:O,color:D}=M,[T]=t.useLexicalComposerContext();h(M,T);const[N,S]=n.useState(),[A,I]=n.useState();n.useEffect(()=>{if(_.current)return;_.current=!0;const e=s(r,R);return S(e),I(R.get(r)),()=>{e.disconnect()}},[r,s,R]);const[y,L]=n.useState();return n.useEffect(()=>{if(!N)return;if(p.current)return;p.current=!0;const e=o.createBinding(T,N,r,A||R.get(r),R,f);return L(e),()=>{e.root.destroy(e)}},[T,N,r,R,A,f]),N&&y?/*#__PURE__*/c.jsx(m,{awarenessData:E,binding:y,collabContext:M,color:D,cursorsContainerRef:u,editor:T,id:r,initialEditorState:d,name:O,provider:N,setDoc:I,shouldBootstrap:a,yjsDocMap:R,syncCursorPositionsFn:g,selectionHighlight:C}):/*#__PURE__*/c.jsx(c.Fragment,{})},exports.CollaborationPluginV2__EXPERIMENTAL=function({id:s,doc:c,provider:i,__shouldBootstrapUnsafe:l,username:u,cursorColor:d,cursorsContainerRef:m,excludedProperties:M,awarenessData:R,selectionHighlight:O}){const D=e.useCollaborationContext(u,d),{yjsDocMap:T,name:N,color:S}=D,[A]=t.useLexicalComposerContext();h(D,A);const I=function(e,t,s,c,i,l,u,d={}){const{awarenessData:g,excludedProperties:C,rootName:p,selectionHighlight:m=!1,__shouldBootstrapUnsafe:h}=d,M=n.useMemo(()=>({current:!1}),[]),R=n.useMemo(()=>o.createBindingV2__EXPERIMENTAL(e,t,s,i,{excludedProperties:C,rootName:p}),[e,t,s,i,C,p]);n.useEffect(()=>(i.set(t,s),()=>{i.delete(t)}),[s,i,t]);const O=n.useCallback(()=>{const{root:t}=R;h&&0===t._length&&_(e)},[R,e,h]),[D,T]=n.useState();return n.useEffect(()=>{r.mergeRegister(e.registerCommand(o.CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL,()=>(T(null),o.syncYjsStateToLexicalV2__EXPERIMENTAL(R,c),!0),r.COMMAND_PRIORITY_EDITOR),e.registerCommand(o.DIFF_VERSIONS_COMMAND__EXPERIMENTAL,({prevSnapshot:e,snapshot:t})=>(T({prevSnapshot:e,snapshot:t}),!0),r.COMMAND_PRIORITY_EDITOR))},[e,R,c]),n.useEffect(()=>{const{root:t}=R;if(D)return void o.renderSnapshot__EXPERIMENTAL(R,D.snapshot,D.prevSnapshot);const n=(e,t)=>{const n=t.origin;if(n!==R){const r=n instanceof a.UndoManager;o.syncYjsChangesToLexicalV2__EXPERIMENTAL(R,c,e,t,r)}};t.observeDeep(n);const s=e.registerUpdateListener(({prevEditorState:e,editorState:t,dirtyElements:n,dirtyLeaves:s,normalizedNodes:a,tags:i})=>{i.has(r.SKIP_COLLAB_TAG)||o.syncLexicalUpdateToYjsV2__EXPERIMENTAL(R,c,e,t,n,s,a,i)});return()=>{t.unobserveDeep(n),s()}},[R,c,e,D]),f(e,c,l,u,M,g,O),E(R,c,m),R}(A,s,c,i,T,N,S,{__shouldBootstrapUnsafe:l,awarenessData:R,excludedProperties:M,selectionHighlight:O});return function(e,t){p(e,n.useMemo(()=>o.createUndoManager(t,t.root),[t]))}(A,I),C(A,i,N,S,R),g(I,m)};
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{useCollaborationContext as e}from"@lexical/react/LexicalCollaborationContext";import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{syncCursorPositions as o,syncLexicalUpdateToYjs as n,createUndoManager as r,setLocalStateFocus as s,createBindingV2__EXPERIMENTAL as i,CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL as a,syncYjsStateToLexicalV2__EXPERIMENTAL as c,DIFF_VERSIONS_COMMAND__EXPERIMENTAL as l,renderSnapshot__EXPERIMENTAL as d,syncLexicalUpdateToYjsV2__EXPERIMENTAL as u,syncYjsChangesToLexical as
|
|
9
|
+
import{useCollaborationContext as e}from"@lexical/react/LexicalCollaborationContext";import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{syncCursorPositions as o,syncLexicalUpdateToYjs as n,createUndoManager as r,setLocalStateFocus as s,createBindingV2__EXPERIMENTAL as i,CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL as a,syncYjsStateToLexicalV2__EXPERIMENTAL as c,DIFF_VERSIONS_COMMAND__EXPERIMENTAL as l,renderSnapshot__EXPERIMENTAL as d,syncLexicalUpdateToYjsV2__EXPERIMENTAL as u,syncYjsChangesToLexical as p,initLocalState as m,TOGGLE_CONNECT_COMMAND as f,syncYjsChangesToLexicalV2__EXPERIMENTAL as g,removeCursorHighlightRule as h,CONNECTED_COMMAND as C,createBinding as y}from"@lexical/yjs";import*as v from"react";import{useRef as E,useCallback as S,useEffect as b,useMemo as x,useState as w}from"react";import{SKIP_COLLAB_TAG as D,mergeRegister as L,FOCUS_COMMAND as k,COMMAND_PRIORITY_EDITOR as _,BLUR_COMMAND as j,$getRoot as N,HISTORY_MERGE_TAG as P,$createParagraphNode as H,$getSelection as B,getActiveElement as R,UNDO_COMMAND as U,REDO_COMMAND as M,CAN_UNDO_COMMAND as F,CAN_REDO_COMMAND as T}from"lexical";import{createPortal as z}from"react-dom";import{UndoManager as A}from"yjs";import{jsx as q,Fragment as G}from"react/jsx-runtime";const I=Symbol.for("@lexical/yjs/UndoManager");function J(e,t,r,s,i,a,c,l,d,u,m,f,g=o,C=!1){const y=E(!1),v=S(()=>{const{root:t}=l;c&&t.isEmpty()&&0===t._xmlText._length&&X(e,m)},[l,e,m,c]);return b(()=>{const{root:t}=l,o=(e,t)=>{const o=t.origin;if(o!==l){p(l,r,e,o instanceof A,g)}};t.getSharedType().observeDeep(o);const s=e.registerUpdateListener(({prevEditorState:e,editorState:t,dirtyLeaves:o,dirtyElements:s,normalizedNodes:i,tags:a})=>{a.has(D)||n(l,r,e,t,s,o,i,a)});return()=>{t.getSharedType().unobserveDeep(o),s()}},[l,r,e,d,s,t,g]),b(()=>{const o=o=>{!function(e,t){if(e.update(()=>{const e=N();e.clear(),e.select()},{tag:D}),null==t.cursors)return;const o=t.cursors;if(null==o)return;const n=t.cursorsContainer;if(null==n)return;for(const e of o.values()){const o=e.selection;if(null!==o){null!==o.highlight&&(CSS.highlights.delete(o.highlightName),h(t,o.highlightName)),o.caret.parentNode===n&&n.removeChild(o.caret);for(const e of o.selections)e.parentNode===n&&n.removeChild(e);e.selection=null}}}(e,l),d(o),s.set(t,o),y.current=!0},n=()=>{y.current=!1};return r.on("reload",o),r.on("sync",n),()=>{r.off("reload",o),r.off("sync",n)}},[l,r,e,d,s,t]),K(e,r,i,a,y,f,v),O(l,r,C),Q(l,u)}function K(e,t,o,n,r,s,i){const a=S(()=>t.connect(),[t]),c=S(()=>{try{t.disconnect()}catch(e){}},[t]);b(()=>{const l=({status:t})=>{e.dispatchCommand(C,"connected"===t)},d=e=>{e&&!1===r.current&&i&&i()},u=e.getRootElement();m(t,o,n,null!==u&&R(u)===u,s||{}),t.on("status",l),t.on("sync",d);const p=a();return()=>{!1===r.current&&(p?p.then(c):c()),t.off("sync",d),t.off("status",l)}},[e,t,o,n,r,s,i,a,c]),b(()=>e.registerCommand(f,e=>(e?(console.log("Collaboration connected!"),a()):(console.log("Collaboration disconnected!"),c()),!0),_),[a,c,e]),b(()=>{const e=()=>{try{t.awareness.setLocalState(null)}catch(e){}};return window.addEventListener("beforeunload",e),window.addEventListener("pagehide",e),()=>{window.removeEventListener("beforeunload",e),window.removeEventListener("pagehide",e)}},[t])}function O(e,t,n){b(()=>{const{awareness:r}=t,s=()=>{o(e,t,{selectionHighlight:n})};return r.on("update",s),()=>{r.off("update",s)}},[e,t,n])}function Q(e,t){return x(()=>/*#__PURE__*/z(/*#__PURE__*/q("div",{ref:t=>{e.cursorsContainer=t}}),t&&t.current||document.body),[e,t])}function V(e,t,o,n,r){b(()=>L(e.registerCommand(k,()=>(s(t,o,n,!0,r||{}),!1),_),e.registerCommand(j,()=>(s(t,o,n,!1,r||{}),!1),_)),[n,e,o,t,r])}function W(e,t){b(()=>L(e.registerCommand(U,()=>(t.undo(),!0),_),e.registerCommand(M,()=>(t.redo(),!0),_))),b(()=>{const o=e;return o[I]=t,()=>{o[I]===t&&delete o[I]}},[e,t]);const o=S(()=>{t.clear()},[t]);return v.useEffect(()=>{const o=()=>{e.dispatchCommand(F,t.undoStack.length>0),e.dispatchCommand(T,t.redoStack.length>0)};return t.on("stack-item-added",o),t.on("stack-item-popped",o),t.on("stack-cleared",o),()=>{t.off("stack-item-added",o),t.off("stack-item-popped",o),t.off("stack-cleared",o)}},[e,t]),o}function X(e,t){e.update(()=>{const o=N();if(o.isEmpty())if(t)switch(typeof t){case"string":{const o=e.parseEditorState(t);e.setEditorState(o,{tag:P});break}case"object":e.setEditorState(t,{tag:P});break;case"function":e.update(()=>{N().isEmpty()&&t(e)},{tag:P})}else{const t=H();o.append(t);const{activeElement:n}=document;(null!==B()||null!==n&&n===e.getRootElement())&&t.select()}},{tag:P})}function Y({id:o,providerFactory:n,shouldBootstrap:r,username:s,cursorColor:i,cursorsContainerRef:a,initialEditorState:c,excludedProperties:l,awarenessData:d,syncCursorPositionsFn:u,selectionHighlight:p}){const m=E(!1),f=E(!1),g=e(s,i),{yjsDocMap:h,name:C,color:v}=g,[S]=t();ee(g,S);const[x,D]=w(),[L,k]=w();b(()=>{if(f.current)return;f.current=!0;const e=n(o,h);return D(e),k(h.get(o)),()=>{e.disconnect()}},[o,n,h]);const[_,j]=w();return b(()=>{if(!x)return;if(m.current)return;m.current=!0;const e=y(S,x,o,L||h.get(o),h,l);return j(e),()=>{e.root.destroy(e)}},[S,x,o,h,L,l]),x&&_?/*#__PURE__*/q(Z,{awarenessData:d,binding:_,collabContext:g,color:v,cursorsContainerRef:a,editor:S,id:o,initialEditorState:c,name:C,provider:x,setDoc:k,shouldBootstrap:r,yjsDocMap:h,syncCursorPositionsFn:u,selectionHighlight:p}):/*#__PURE__*/q(G,{})}function Z({editor:e,id:t,provider:o,yjsDocMap:n,name:s,color:i,shouldBootstrap:a,cursorsContainerRef:c,initialEditorState:l,awarenessData:d,collabContext:u,binding:p,setDoc:m,syncCursorPositionsFn:f,selectionHighlight:g}){const h=J(e,t,o,n,s,i,a,p,m,c,l,d,f,g);return function(e,t){W(e,x(()=>r(t,t.root.getSharedType()),[t]))}(e,p),V(e,o,s,i,d),h}function $({id:o,doc:n,provider:s,__shouldBootstrapUnsafe:p,username:m,cursorColor:f,cursorsContainerRef:h,excludedProperties:C,awarenessData:y,selectionHighlight:v}){const E=e(m,f),{yjsDocMap:k,name:j,color:N}=E,[P]=t();ee(E,P);const H=function(e,t,o,n,r,s,p,m={}){const{awarenessData:f,excludedProperties:h,rootName:C,selectionHighlight:y=!1,__shouldBootstrapUnsafe:v}=m,E=x(()=>({current:!1}),[]),k=x(()=>i(e,t,o,r,{excludedProperties:h,rootName:C}),[e,t,o,r,h,C]);b(()=>(r.set(t,o),()=>{r.delete(t)}),[o,r,t]);const j=S(()=>{const{root:t}=k;v&&0===t._length&&X(e)},[k,e,v]),[N,P]=w();return b(()=>{L(e.registerCommand(a,()=>(P(null),c(k,n),!0),_),e.registerCommand(l,({prevSnapshot:e,snapshot:t})=>(P({prevSnapshot:e,snapshot:t}),!0),_))},[e,k,n]),b(()=>{const{root:t}=k;if(N)return void d(k,N.snapshot,N.prevSnapshot);const o=(e,t)=>{const o=t.origin;o!==k&&g(k,n,e,t,o instanceof A)};t.observeDeep(o);const r=e.registerUpdateListener(({prevEditorState:e,editorState:t,dirtyElements:o,dirtyLeaves:r,normalizedNodes:s,tags:i})=>{i.has(D)||u(k,n,e,t,o,r,s,i)});return()=>{t.unobserveDeep(o),r()}},[k,n,e,N]),K(e,n,s,p,E,f,j),O(k,n,y),k}(P,o,n,s,k,j,N,{__shouldBootstrapUnsafe:p,awarenessData:y,excludedProperties:C,selectionHighlight:v});return function(e,t){W(e,x(()=>r(t,t.root),[t]))}(P,H),V(P,s,j,N,y),Q(H,h)}const ee=(e,t)=>{b(()=>(e.isCollabActive=!0,()=>{null==t._parentEditor&&(e.isCollabActive=!1)}),[e,t])};export{Y as CollaborationPlugin,$ as CollaborationPluginV2__EXPERIMENTAL};
|
|
@@ -140,8 +140,11 @@ function initializeEditor(editor, initialEditorState) {
|
|
|
140
140
|
if (root.isEmpty()) {
|
|
141
141
|
const paragraph = lexical.$createParagraphNode();
|
|
142
142
|
root.append(paragraph);
|
|
143
|
-
const
|
|
144
|
-
|
|
143
|
+
const rootElement = editor.getRootElement();
|
|
144
|
+
// getActiveElement rather than document.activeElement, which reports
|
|
145
|
+
// the shadow host when the editor is in a shadow root.
|
|
146
|
+
const activeElement = lexical.CAN_USE_DOM && rootElement !== null ? lexical.getActiveElement(rootElement) : null;
|
|
147
|
+
if (lexical.$getSelection() !== null || activeElement !== null && activeElement === rootElement) {
|
|
145
148
|
paragraph.select();
|
|
146
149
|
}
|
|
147
150
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { createLexicalComposerContext, LexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
10
|
-
import { CAN_USE_DOM, createEditor, $getRoot, $createParagraphNode, $getSelection, HISTORY_MERGE_TAG } from 'lexical';
|
|
10
|
+
import { CAN_USE_DOM, createEditor, $getRoot, $createParagraphNode, getActiveElement, $getSelection, HISTORY_MERGE_TAG } from 'lexical';
|
|
11
11
|
import { useLayoutEffect, useEffect, useMemo } from 'react';
|
|
12
12
|
import { jsx } from 'react/jsx-runtime';
|
|
13
13
|
|
|
@@ -138,8 +138,11 @@ function initializeEditor(editor, initialEditorState) {
|
|
|
138
138
|
if (root.isEmpty()) {
|
|
139
139
|
const paragraph = $createParagraphNode();
|
|
140
140
|
root.append(paragraph);
|
|
141
|
-
const
|
|
142
|
-
|
|
141
|
+
const rootElement = editor.getRootElement();
|
|
142
|
+
// getActiveElement rather than document.activeElement, which reports
|
|
143
|
+
// the shadow host when the editor is in a shadow root.
|
|
144
|
+
const activeElement = CAN_USE_DOM && rootElement !== null ? getActiveElement(rootElement) : null;
|
|
145
|
+
if ($getSelection() !== null || activeElement !== null && activeElement === rootElement) {
|
|
143
146
|
paragraph.select();
|
|
144
147
|
}
|
|
145
148
|
}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("lexical"),o=require("react"),r=require("react/jsx-runtime");const n=t.CAN_USE_DOM?o.useLayoutEffect:o.useEffect,a={tag:t.HISTORY_MERGE_TAG};exports.LexicalComposer=function({initialConfig:i,children:c}){const
|
|
9
|
+
"use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("lexical"),o=require("react"),r=require("react/jsx-runtime");const n=t.CAN_USE_DOM?o.useLayoutEffect:o.useEffect,a={tag:t.HISTORY_MERGE_TAG};exports.LexicalComposer=function({initialConfig:i,children:c}){const l=o.useMemo(()=>{const{theme:o,namespace:r,nodes:n,onError:c,onWarn:l,editorState:s,html:u}=i,d=e.createLexicalComposerContext(null,o),E=t.createEditor({editable:i.editable,html:u,namespace:r,nodes:n,onError:e=>c(e,E),...l?{onWarn:e=>l(e,E)}:{},theme:o});return function(e,o){if(null===o)return;if(void 0===o)e.update(()=>{const o=t.$getRoot();if(o.isEmpty()){const r=t.$createParagraphNode();o.append(r);const n=e.getRootElement(),a=t.CAN_USE_DOM&&null!==n?t.getActiveElement(n):null;(null!==t.$getSelection()||null!==a&&a===n)&&r.select()}},a);else if(null!==o)switch(typeof o){case"string":{const t=e.parseEditorState(o);e.setEditorState(t,a);break}case"object":e.setEditorState(o,a);break;case"function":e.update(()=>{t.$getRoot().isEmpty()&&o(e)},a)}}(E,s),[E,d]},[]);return n(()=>{const e=i.editable,[t]=l;t.setEditable(void 0===e||e)},[]),/*#__PURE__*/r.jsx(e.LexicalComposerContext.Provider,{value:l,children:c})};
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{createLexicalComposerContext as t,LexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{CAN_USE_DOM as n,createEditor as o,$getRoot as r,$createParagraphNode as i,$getSelection as
|
|
9
|
+
import{createLexicalComposerContext as t,LexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{CAN_USE_DOM as n,createEditor as o,$getRoot as r,$createParagraphNode as i,getActiveElement as a,$getSelection as l,HISTORY_MERGE_TAG as c}from"lexical";import{useLayoutEffect as s,useEffect as m,useMemo as d}from"react";import{jsx as u}from"react/jsx-runtime";const p=n?s:m,f={tag:c};function E({initialConfig:c,children:s}){const m=d(()=>{const{theme:e,namespace:s,nodes:m,onError:d,onWarn:u,editorState:p,html:E}=c,b=t(null,e),h=o({editable:c.editable,html:E,namespace:s,nodes:m,onError:t=>d(t,h),...u?{onWarn:t=>u(t,h)}:{},theme:e});return function(t,e){if(null===e)return;if(void 0===e)t.update(()=>{const e=r();if(e.isEmpty()){const o=i();e.append(o);const r=t.getRootElement(),c=n&&null!==r?a(r):null;(null!==l()||null!==c&&c===r)&&o.select()}},f);else if(null!==e)switch(typeof e){case"string":{const n=t.parseEditorState(e);t.setEditorState(n,f);break}case"object":t.setEditorState(e,f);break;case"function":t.update(()=>{r().isEmpty()&&e(t)},f)}}(h,p),[h,b]},[]);return p(()=>{const t=c.editable,[e]=m;e.setEditable(void 0===t||t)},[]),/*#__PURE__*/u(e.Provider,{value:m,children:s})}export{E as LexicalComposer};
|
|
@@ -13,7 +13,6 @@ var react = require('react');
|
|
|
13
13
|
var lexical = require('lexical');
|
|
14
14
|
var jsxRuntime = require('react/jsx-runtime');
|
|
15
15
|
var text = require('@lexical/text');
|
|
16
|
-
var utils = require('@lexical/utils');
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -164,7 +163,7 @@ function useCanShowPlaceholder(editor) {
|
|
|
164
163
|
setCanShowPlaceholder(currentCanShowPlaceholder);
|
|
165
164
|
}
|
|
166
165
|
resetCanShowPlaceholder();
|
|
167
|
-
return
|
|
166
|
+
return lexical.mergeRegister(editor.registerUpdateListener(() => {
|
|
168
167
|
resetCanShowPlaceholder();
|
|
169
168
|
}), editor.registerEditableListener(() => {
|
|
170
169
|
resetCanShowPlaceholder();
|
|
@@ -8,10 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
10
10
|
import { useLayoutEffect, useEffect, forwardRef, useState, useCallback, useMemo } from 'react';
|
|
11
|
-
import { CAN_USE_DOM } from 'lexical';
|
|
11
|
+
import { CAN_USE_DOM, mergeRegister } from 'lexical';
|
|
12
12
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
13
13
|
import { $canShowPlaceholderCurry } from '@lexical/text';
|
|
14
|
-
import { mergeRegister } from '@lexical/utils';
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react"),a=require("lexical"),r=require("react/jsx-runtime"),i=require("@lexical/text")
|
|
10
|
-
return r.jsxs(r.Fragment,{children:[/*#__PURE__*/r.jsx(
|
|
9
|
+
"use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react"),a=require("lexical"),r=require("react/jsx-runtime"),i=require("@lexical/text");const n=a.CAN_USE_DOM?t.useLayoutEffect:t.useEffect;function l({editor:e,ariaActiveDescendant:a,ariaAutoComplete:i,ariaControls:l,ariaDescribedBy:o,ariaErrorMessage:s,ariaExpanded:u,ariaInvalid:d,ariaLabel:c,ariaLabelledBy:f,ariaMultiline:b,ariaOwns:x,ariaRequired:m,autoCapitalize:E,className:p,id:C,role:v="textbox",spellCheck:y=!0,style:g,tabIndex:L,"data-testid":h,...w},q){const[j,R]=t.useState(e.isEditable()),D=t.useCallback(t=>{t&&t.ownerDocument&&t.ownerDocument.defaultView?e.setRootElement(t):e.setRootElement(null)},[e]),S=t.useMemo(()=>function(...e){return t=>{for(const a of e)"function"==typeof a?a(t):null!=a&&(a.current=t)}}(q,D),[D,q]);return n(()=>(R(e.isEditable()),e.registerEditableListener(e=>{R(e)})),[e]),/*#__PURE__*/r.jsx("div",{"aria-activedescendant":j?a:void 0,"aria-autocomplete":j?i:"none","aria-controls":j?l:void 0,"aria-describedby":o,...null!=s?{"aria-errormessage":s}:{},"aria-expanded":j&&"combobox"===v?!!u:void 0,...null!=d?{"aria-invalid":d}:{},"aria-label":c,"aria-labelledby":f,"aria-multiline":b,"aria-owns":j?x:void 0,"aria-readonly":!j||void 0,"aria-required":m,autoCapitalize:E,className:p,contentEditable:j,"data-testid":h,id:C,ref:S,role:v,spellCheck:y,style:g,tabIndex:L,...w})}const o=/*#__PURE__*/t.forwardRef(l);function s(e){return e.read("latest",i.$canShowPlaceholderCurry(e.isComposing()))}const u=/*#__PURE__*/t.forwardRef(d);function d(t,a){const{placeholder:i,...n}=t,[l]=e.useLexicalComposerContext();/*#__PURE__*/
|
|
10
|
+
return r.jsxs(r.Fragment,{children:[/*#__PURE__*/r.jsx(o,{editor:l,...n,ref:a}),null!=i&&/*#__PURE__*/r.jsx(c,{editor:l,content:i})]})}function c({content:e,editor:i}){const l=function(e){const[r,i]=t.useState(()=>s(e));return n(()=>{function t(){const t=s(e);i(t)}return t(),a.mergeRegister(e.registerUpdateListener(()=>{t()}),e.registerEditableListener(()=>{t()}))},[e]),r}(i),[o,u]=t.useState(i.isEditable());if(t.useLayoutEffect(()=>(u(i.isEditable()),i.registerEditableListener(e=>{u(e)})),[i]),!l)return null;let d=null;return"function"==typeof e?d=e(o):null!==e&&(d=e),null===d?null:/*#__PURE__*/r.jsx("div",{"aria-hidden":!0,children:d})}exports.ContentEditable=u,exports.ContentEditableElement=o;
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLayoutEffect as t,useEffect as i,forwardRef as a,useState as r,useCallback as n,useMemo as o}from"react";import{CAN_USE_DOM as l}from"lexical";import{jsx as
|
|
10
|
-
return
|
|
9
|
+
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLayoutEffect as t,useEffect as i,forwardRef as a,useState as r,useCallback as n,useMemo as o}from"react";import{CAN_USE_DOM as l,mergeRegister as d}from"lexical";import{jsx as s,jsxs as c,Fragment as u}from"react/jsx-runtime";import{$canShowPlaceholderCurry as m}from"@lexical/text";const f=l?t:i;function b({editor:e,ariaActiveDescendant:t,ariaAutoComplete:i,ariaControls:a,ariaDescribedBy:l,ariaErrorMessage:d,ariaExpanded:c,ariaInvalid:u,ariaLabel:m,ariaLabelledBy:b,ariaMultiline:p,ariaOwns:x,ariaRequired:E,autoCapitalize:v,className:y,id:C,role:g="textbox",spellCheck:L=!0,style:h,tabIndex:w,"data-testid":D,...I},R){const[k,q]=r(e.isEditable()),z=n(t=>{t&&t.ownerDocument&&t.ownerDocument.defaultView?e.setRootElement(t):e.setRootElement(null)},[e]),A=o(()=>function(...e){return t=>{for(const i of e)"function"==typeof i?i(t):null!=i&&(i.current=t)}}(R,z),[z,R]);return f(()=>(q(e.isEditable()),e.registerEditableListener(e=>{q(e)})),[e]),/*#__PURE__*/s("div",{"aria-activedescendant":k?t:void 0,"aria-autocomplete":k?i:"none","aria-controls":k?a:void 0,"aria-describedby":l,...null!=d?{"aria-errormessage":d}:{},"aria-expanded":k&&"combobox"===g?!!c:void 0,...null!=u?{"aria-invalid":u}:{},"aria-label":m,"aria-labelledby":b,"aria-multiline":p,"aria-owns":k?x:void 0,"aria-readonly":!k||void 0,"aria-required":E,autoCapitalize:v,className:y,contentEditable:k,"data-testid":D,id:C,ref:A,role:g,spellCheck:L,style:h,tabIndex:w,...I})}const p=/*#__PURE__*/a(b);function x(e){return e.read("latest",m(e.isComposing()))}const E=/*#__PURE__*/a(v);function v(t,i){const{placeholder:a,...r}=t,[n]=e();/*#__PURE__*/
|
|
10
|
+
return c(u,{children:[/*#__PURE__*/s(p,{editor:n,...r,ref:i}),null!=a&&/*#__PURE__*/s(y,{editor:n,content:a})]})}function y({content:e,editor:i}){const a=function(e){const[t,i]=r(()=>x(e));return f(()=>{function t(){const t=x(e);i(t)}return t(),d(e.registerUpdateListener(()=>{t()}),e.registerEditableListener(()=>{t()}))},[e]),t}(i),[n,o]=r(i.isEditable());if(t(()=>(o(i.isEditable()),i.registerEditableListener(e=>{o(e)})),[i]),!a)return null;let l=null;return"function"==typeof e?l=e(n):null!==e&&(l=e),null===l?null:/*#__PURE__*/s("div",{"aria-hidden":!0,children:l})}export{E as ContentEditable,p as ContentEditableElement};
|