@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
|
@@ -13,20 +13,8 @@ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
|
13
13
|
var LexicalNodeMenuPlugin = require('@lexical/react/LexicalNodeMenuPlugin');
|
|
14
14
|
var utils = require('@lexical/utils');
|
|
15
15
|
var lexical = require('lexical');
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
function _interopNamespaceDefault(e) {
|
|
19
|
-
var n = Object.create(null);
|
|
20
|
-
if (e) {
|
|
21
|
-
for (var k in e) {
|
|
22
|
-
n[k] = e[k];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
n.default = e;
|
|
26
|
-
return n;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
16
|
+
var react = require('react');
|
|
17
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
30
18
|
|
|
31
19
|
/**
|
|
32
20
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -53,13 +41,13 @@ function LexicalAutoEmbedPlugin({
|
|
|
53
41
|
menuCommandPriority = lexical.COMMAND_PRIORITY_LOW
|
|
54
42
|
}) {
|
|
55
43
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
56
|
-
const [nodeKey, setNodeKey] =
|
|
57
|
-
const [activeEmbedConfig, setActiveEmbedConfig] =
|
|
58
|
-
const reset =
|
|
44
|
+
const [nodeKey, setNodeKey] = react.useState(null);
|
|
45
|
+
const [activeEmbedConfig, setActiveEmbedConfig] = react.useState(null);
|
|
46
|
+
const reset = react.useCallback(() => {
|
|
59
47
|
setNodeKey(null);
|
|
60
48
|
setActiveEmbedConfig(null);
|
|
61
49
|
}, []);
|
|
62
|
-
const checkIfLinkNodeIsEmbeddable =
|
|
50
|
+
const checkIfLinkNodeIsEmbeddable = react.useCallback(key => {
|
|
63
51
|
editor.getEditorState().read(async function () {
|
|
64
52
|
const linkNode = lexical.$getNodeByKey(key);
|
|
65
53
|
if (link.$isLinkNode(linkNode)) {
|
|
@@ -74,7 +62,7 @@ function LexicalAutoEmbedPlugin({
|
|
|
74
62
|
}
|
|
75
63
|
});
|
|
76
64
|
}, [editor, embedConfigs]);
|
|
77
|
-
|
|
65
|
+
react.useEffect(() => {
|
|
78
66
|
const listener = (nodeMutations, {
|
|
79
67
|
updateTags,
|
|
80
68
|
dirtyLeaves
|
|
@@ -89,7 +77,7 @@ function LexicalAutoEmbedPlugin({
|
|
|
89
77
|
};
|
|
90
78
|
return utils.mergeRegister(...[link.LinkNode, link.AutoLinkNode].map(Klass => editor.registerMutationListener(Klass, (...args) => listener(...args))));
|
|
91
79
|
}, [checkIfLinkNodeIsEmbeddable, editor, embedConfigs, nodeKey, reset]);
|
|
92
|
-
|
|
80
|
+
react.useEffect(() => {
|
|
93
81
|
return editor.registerCommand(INSERT_EMBED_COMMAND, embedConfigType => {
|
|
94
82
|
const embedConfig = embedConfigs.find(({
|
|
95
83
|
type
|
|
@@ -101,7 +89,7 @@ function LexicalAutoEmbedPlugin({
|
|
|
101
89
|
return false;
|
|
102
90
|
}, lexical.COMMAND_PRIORITY_EDITOR);
|
|
103
91
|
}, [editor, embedConfigs, onOpenEmbedModalForConfig]);
|
|
104
|
-
const embedLinkViaActiveEmbedConfig =
|
|
92
|
+
const embedLinkViaActiveEmbedConfig = react.useCallback(async function () {
|
|
105
93
|
if (activeEmbedConfig != null && nodeKey != null) {
|
|
106
94
|
const linkNode = editor.getEditorState().read(() => {
|
|
107
95
|
const node = lexical.$getNodeByKey(nodeKey);
|
|
@@ -126,16 +114,16 @@ function LexicalAutoEmbedPlugin({
|
|
|
126
114
|
}
|
|
127
115
|
}
|
|
128
116
|
}, [activeEmbedConfig, editor, nodeKey]);
|
|
129
|
-
const options =
|
|
117
|
+
const options = react.useMemo(() => {
|
|
130
118
|
return activeEmbedConfig != null && nodeKey != null ? getMenuOptions(activeEmbedConfig, embedLinkViaActiveEmbedConfig, reset) : [];
|
|
131
119
|
}, [activeEmbedConfig, embedLinkViaActiveEmbedConfig, getMenuOptions, nodeKey, reset]);
|
|
132
|
-
const onSelectOption =
|
|
120
|
+
const onSelectOption = react.useCallback((selectedOption, targetNode, closeMenu) => {
|
|
133
121
|
editor.update(() => {
|
|
134
122
|
selectedOption.onSelect(targetNode);
|
|
135
123
|
closeMenu();
|
|
136
124
|
});
|
|
137
125
|
}, [editor]);
|
|
138
|
-
return nodeKey != null ? /*#__PURE__*/
|
|
126
|
+
return nodeKey != null ? /*#__PURE__*/jsxRuntime.jsx(LexicalNodeMenuPlugin.LexicalNodeMenuPlugin, {
|
|
139
127
|
nodeKey: nodeKey,
|
|
140
128
|
onClose: reset,
|
|
141
129
|
onSelectOption: onSelectOption,
|
|
@@ -11,8 +11,8 @@ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext
|
|
|
11
11
|
import { MenuOption, LexicalNodeMenuPlugin } from '@lexical/react/LexicalNodeMenuPlugin';
|
|
12
12
|
import { mergeRegister } from '@lexical/utils';
|
|
13
13
|
import { createCommand, $getNodeByKey, COMMAND_PRIORITY_EDITOR, $getSelection, COMMAND_PRIORITY_LOW } from 'lexical';
|
|
14
|
-
import * as React from 'react';
|
|
15
14
|
import { useState, useCallback, useEffect, useMemo } from 'react';
|
|
15
|
+
import { jsx } from 'react/jsx-runtime';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -121,7 +121,7 @@ function LexicalAutoEmbedPlugin({
|
|
|
121
121
|
closeMenu();
|
|
122
122
|
});
|
|
123
123
|
}, [editor]);
|
|
124
|
-
return nodeKey != null ? /*#__PURE__*/
|
|
124
|
+
return nodeKey != null ? /*#__PURE__*/jsx(LexicalNodeMenuPlugin, {
|
|
125
125
|
nodeKey: nodeKey,
|
|
126
126
|
onClose: reset,
|
|
127
127
|
onSelectOption: onSelectOption,
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
'use strict';var
|
|
10
|
-
exports.LexicalAutoEmbedPlugin=function({embedConfigs:f,onOpenEmbedModalForConfig:n,getMenuOptions:
|
|
11
|
-
[
|
|
12
|
-
return
|
|
13
|
-
exports.URL_MATCHER=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/
|
|
9
|
+
'use strict';var e=require("@lexical/link"),k=require("@lexical/react/LexicalComposerContext"),l=require("@lexical/react/LexicalNodeMenuPlugin"),q=require("@lexical/utils"),r=require("lexical"),z=require("react"),A=require("react/jsx-runtime");let B=r.createCommand("INSERT_EMBED_COMMAND");class C extends l.MenuOption{constructor(f,n){super(f);this.title=f;this.onSelect=n.onSelect.bind(this)}}exports.AutoEmbedOption=C;exports.INSERT_EMBED_COMMAND=B;
|
|
10
|
+
exports.LexicalAutoEmbedPlugin=function({embedConfigs:f,onOpenEmbedModalForConfig:n,getMenuOptions:t,menuRenderFn:D,menuCommandPriority:E=r.COMMAND_PRIORITY_LOW}){let [c]=k.useLexicalComposerContext(),[g,u]=z.useState(null),[h,v]=z.useState(null),m=z.useCallback(()=>{u(null);v(null)},[]),w=z.useCallback(b=>{c.getEditorState().read(async function(){const a=r.$getNodeByKey(b);if(e.$isLinkNode(a))for(let d=0;d<f.length;d++){const p=f[d];null!=await Promise.resolve(p.parseUrl(a.__url))&&(v(p),u(a.getKey()))}})},
|
|
11
|
+
[c,f]);z.useEffect(()=>{let b=(a,{updateTags:d,dirtyLeaves:p})=>{for(const [x,F]of a)"created"===F&&d.has("paste")&&3>=p.size?w(x):x===g&&m()};return q.mergeRegister(...[e.LinkNode,e.AutoLinkNode].map(a=>c.registerMutationListener(a,(...d)=>b(...d))))},[w,c,f,g,m]);z.useEffect(()=>c.registerCommand(B,b=>{let a=f.find(({type:d})=>d===b);return a?(n(a),!0):!1},r.COMMAND_PRIORITY_EDITOR),[c,f,n]);let y=z.useCallback(async function(){if(null!=h&&null!=g){const b=c.getEditorState().read(()=>{const a=r.$getNodeByKey(g);
|
|
12
|
+
return e.$isLinkNode(a)?a:null});if(e.$isLinkNode(b)){const a=await Promise.resolve(h.parseUrl(b.__url));null!=a&&c.update(()=>{r.$getSelection()||b.selectEnd();h.insertNode(c,a);b.isAttached()&&b.remove()})}}},[h,c,g]),G=z.useMemo(()=>null!=h&&null!=g?t(h,y,m):[],[h,y,t,g,m]),H=z.useCallback((b,a,d)=>{c.update(()=>{b.onSelect(a);d()})},[c]);return null!=g?A.jsx(l.LexicalNodeMenuPlugin,{nodeKey:g,onClose:m,onSelectOption:H,options:G,menuRenderFn:D,commandPriority:E}):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 l}from"@lexical/react/LexicalNodeMenuPlugin";import{mergeRegister as i}from"@lexical/utils";import{createCommand as s,$getNodeByKey as a,COMMAND_PRIORITY_EDITOR as c,$getSelection as u,COMMAND_PRIORITY_LOW as m}from"lexical";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 l}from"@lexical/react/LexicalNodeMenuPlugin";import{mergeRegister as i}from"@lexical/utils";import{createCommand as s,$getNodeByKey as a,COMMAND_PRIORITY_EDITOR as c,$getSelection as u,COMMAND_PRIORITY_LOW as m}from"lexical";import{useState as d,useCallback as p,useEffect as f,useMemo as g}from"react";import{jsx as x}from"react/jsx-runtime";const w=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/,y=s("INSERT_EMBED_COMMAND");class C extends r{constructor(e,t){super(e),this.title=e,this.onSelect=t.onSelect.bind(this)}}function _({embedConfigs:r,onOpenEmbedModalForConfig:s,getMenuOptions:w,menuRenderFn:C,menuCommandPriority:_=m}){const[h]=o(),[E,M]=d(null),[S,A]=d(null),P=p((()=>{M(null),A(null)}),[]),b=p((t=>{h.getEditorState().read((async function(){const n=a(t);if(e(n))for(let e=0;e<r.length;e++){const t=r[e];null!=await Promise.resolve(t.parseUrl(n.__url))&&(A(t),M(n.getKey()))}}))}),[h,r]);f((()=>i(...[t,n].map((e=>h.registerMutationListener(e,((...e)=>((e,{updateTags:t,dirtyLeaves:n})=>{for(const[o,r]of e)"created"===r&&t.has("paste")&&n.size<=3?b(o):o===E&&P()})(...e))))))),[b,h,r,E,P]),f((()=>h.registerCommand(y,(e=>{const t=r.find((({type:t})=>t===e));return!!t&&(s(t),!0)}),c)),[h,r,s]);const v=p((async function(){if(null!=S&&null!=E){const t=h.getEditorState().read((()=>{const t=a(E);return e(t)?t:null}));if(e(t)){const e=await Promise.resolve(S.parseUrl(t.__url));null!=e&&h.update((()=>{u()||t.selectEnd(),S.insertNode(h,e),t.isAttached()&&t.remove()}))}}}),[S,h,E]),z=g((()=>null!=S&&null!=E?w(S,v,P):[]),[S,v,w,E,P]),L=p(((e,t,n)=>{h.update((()=>{e.onSelect(t),n()}))}),[h]);return null!=E?x(l,{nodeKey:E,onClose:P,onSelectOption:L,options:z,menuRenderFn:C,commandPriority:_}):null}export{C as AutoEmbedOption,y as INSERT_EMBED_COMMAND,_ as LexicalAutoEmbedPlugin,w as URL_MATCHER};
|
|
@@ -13,20 +13,8 @@ var LexicalDecoratorBlockNode = require('@lexical/react/LexicalDecoratorBlockNod
|
|
|
13
13
|
var useLexicalNodeSelection = require('@lexical/react/useLexicalNodeSelection');
|
|
14
14
|
var utils = require('@lexical/utils');
|
|
15
15
|
var lexical = require('lexical');
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
function _interopNamespaceDefault(e) {
|
|
19
|
-
var n = Object.create(null);
|
|
20
|
-
if (e) {
|
|
21
|
-
for (var k in e) {
|
|
22
|
-
n[k] = e[k];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
n.default = e;
|
|
26
|
-
return n;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
16
|
+
var react = require('react');
|
|
17
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
30
18
|
|
|
31
19
|
/**
|
|
32
20
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -44,8 +32,8 @@ function BlockWithAlignableContents({
|
|
|
44
32
|
}) {
|
|
45
33
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
46
34
|
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection.useLexicalNodeSelection(nodeKey);
|
|
47
|
-
const ref =
|
|
48
|
-
const $onDelete =
|
|
35
|
+
const ref = react.useRef(null);
|
|
36
|
+
const $onDelete = react.useCallback(event => {
|
|
49
37
|
if (isSelected && lexical.$isNodeSelection(lexical.$getSelection())) {
|
|
50
38
|
event.preventDefault();
|
|
51
39
|
const node = lexical.$getNodeByKey(nodeKey);
|
|
@@ -56,7 +44,7 @@ function BlockWithAlignableContents({
|
|
|
56
44
|
}
|
|
57
45
|
return false;
|
|
58
46
|
}, [isSelected, nodeKey]);
|
|
59
|
-
|
|
47
|
+
react.useEffect(() => {
|
|
60
48
|
return utils.mergeRegister(editor.registerCommand(lexical.FORMAT_ELEMENT_COMMAND, formatType => {
|
|
61
49
|
if (isSelected) {
|
|
62
50
|
const selection = lexical.$getSelection();
|
|
@@ -91,13 +79,14 @@ function BlockWithAlignableContents({
|
|
|
91
79
|
return false;
|
|
92
80
|
}, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_DELETE_COMMAND, $onDelete, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, $onDelete, lexical.COMMAND_PRIORITY_LOW));
|
|
93
81
|
}, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected]);
|
|
94
|
-
return /*#__PURE__*/
|
|
82
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
95
83
|
className: [className.base, isSelected ? className.focus : null].filter(Boolean).join(' '),
|
|
96
84
|
ref: ref,
|
|
97
85
|
style: {
|
|
98
86
|
textAlign: format ? format : undefined
|
|
99
|
-
}
|
|
100
|
-
|
|
87
|
+
},
|
|
88
|
+
children: children
|
|
89
|
+
});
|
|
101
90
|
}
|
|
102
91
|
|
|
103
92
|
exports.BlockWithAlignableContents = BlockWithAlignableContents;
|
|
@@ -11,8 +11,8 @@ import { $isDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode'
|
|
|
11
11
|
import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
|
|
12
12
|
import { mergeRegister, $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
|
|
13
13
|
import { $isNodeSelection, $getSelection, $getNodeByKey, $isDecoratorNode, FORMAT_ELEMENT_COMMAND, $isRangeSelection, COMMAND_PRIORITY_LOW, CLICK_COMMAND, KEY_DELETE_COMMAND, KEY_BACKSPACE_COMMAND } from 'lexical';
|
|
14
|
-
import * as React from 'react';
|
|
15
14
|
import { useRef, useCallback, useEffect } from 'react';
|
|
15
|
+
import { jsx } from 'react/jsx-runtime';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -77,13 +77,14 @@ function BlockWithAlignableContents({
|
|
|
77
77
|
return false;
|
|
78
78
|
}, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_DELETE_COMMAND, $onDelete, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_BACKSPACE_COMMAND, $onDelete, COMMAND_PRIORITY_LOW));
|
|
79
79
|
}, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected]);
|
|
80
|
-
return /*#__PURE__*/
|
|
80
|
+
return /*#__PURE__*/jsx("div", {
|
|
81
81
|
className: [className.base, isSelected ? className.focus : null].filter(Boolean).join(' '),
|
|
82
82
|
ref: ref,
|
|
83
83
|
style: {
|
|
84
84
|
textAlign: format ? format : undefined
|
|
85
|
-
}
|
|
86
|
-
|
|
85
|
+
},
|
|
86
|
+
children: children
|
|
87
|
+
});
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
export { BlockWithAlignableContents };
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
'use strict';var a=require("@lexical/react/LexicalComposerContext"),
|
|
10
|
-
exports.BlockWithAlignableContents=function({children:
|
|
11
|
-
|
|
12
|
-
{className:[
|
|
9
|
+
'use strict';var a=require("@lexical/react/LexicalComposerContext"),h=require("@lexical/react/LexicalDecoratorBlockNode"),l=require("@lexical/react/useLexicalNodeSelection"),m=require("@lexical/utils"),u=require("lexical"),v=require("react"),w=require("react/jsx-runtime");
|
|
10
|
+
exports.BlockWithAlignableContents=function({children:x,format:n,nodeKey:e,className:p}){let [f]=a.useLexicalComposerContext(),[c,q,r]=l.useLexicalNodeSelection(e),t=v.useRef(null),k=v.useCallback(b=>c&&u.$isNodeSelection(u.$getSelection())&&(b.preventDefault(),b=u.$getNodeByKey(e),u.$isDecoratorNode(b))?(b.remove(),!0):!1,[c,e]);v.useEffect(()=>m.mergeRegister(f.registerCommand(u.FORMAT_ELEMENT_COMMAND,b=>{if(c){var g=u.$getSelection();if(u.$isNodeSelection(g)){var d=u.$getNodeByKey(e);h.$isDecoratorBlockNode(d)&&
|
|
11
|
+
d.setFormat(b)}else if(u.$isRangeSelection(g)){g=g.getNodes();for(d of g)h.$isDecoratorBlockNode(d)?d.setFormat(b):m.$getNearestBlockElementAncestorOrThrow(d).setFormat(b)}return!0}return!1},u.COMMAND_PRIORITY_LOW),f.registerCommand(u.CLICK_COMMAND,b=>b.target===t.current?(b.preventDefault(),b.shiftKey||r(),q(!c),!0):!1,u.COMMAND_PRIORITY_LOW),f.registerCommand(u.KEY_DELETE_COMMAND,k,u.COMMAND_PRIORITY_LOW),f.registerCommand(u.KEY_BACKSPACE_COMMAND,k,u.COMMAND_PRIORITY_LOW)),[r,f,c,e,k,q]);return w.jsx("div",
|
|
12
|
+
{className:[p.base,c?p.focus:null].filter(Boolean).join(" "),ref:t,style:{textAlign:n?n:void 0},children:x})}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
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{mergeRegister as o,$getNearestBlockElementAncestorOrThrow as i}from"@lexical/utils";import{$isNodeSelection 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{mergeRegister as o,$getNearestBlockElementAncestorOrThrow as i}from"@lexical/utils";import{$isNodeSelection as l,$getSelection as a,$getNodeByKey as m,$isDecoratorNode as n,FORMAT_ELEMENT_COMMAND as c,$isRangeSelection as s,COMMAND_PRIORITY_LOW as f,CLICK_COMMAND as u,KEY_DELETE_COMMAND as d,KEY_BACKSPACE_COMMAND as x}from"lexical";import{useRef as p,useCallback as g,useEffect as C}from"react";import{jsx as v}from"react/jsx-runtime";function N({children:N,format:h,nodeKey:y,className:D}){const[F]=e(),[L,j,B]=t(y),K=p(null),b=g((e=>{if(L&&l(a())){e.preventDefault();const r=m(y);if(n(r))return r.remove(),!0}return!1}),[L,y]);return C((()=>o(F.registerCommand(c,(e=>{if(L){const t=a();if(l(t)){const t=m(y);r(t)&&t.setFormat(e)}else if(s(t)){const o=t.getNodes();for(const t of o)if(r(t))t.setFormat(e);else{i(t).setFormat(e)}}return!0}return!1}),f),F.registerCommand(u,(e=>e.target===K.current&&(e.preventDefault(),e.shiftKey||B(),j(!L),!0)),f),F.registerCommand(d,b,f),F.registerCommand(x,b,f))),[B,F,L,y,b,j]),v("div",{className:[D.base,L?D.focus:null].filter(Boolean).join(" "),ref:K,style:{textAlign:h||void 0},children:N})}export{N as BlockWithAlignableContents};
|
|
@@ -9,24 +9,12 @@
|
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
11
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
12
|
-
var
|
|
12
|
+
var react = require('react');
|
|
13
13
|
var overflow = require('@lexical/overflow');
|
|
14
14
|
var text = require('@lexical/text');
|
|
15
15
|
var utils = require('@lexical/utils');
|
|
16
16
|
var lexical = require('lexical');
|
|
17
|
-
|
|
18
|
-
function _interopNamespaceDefault(e) {
|
|
19
|
-
var n = Object.create(null);
|
|
20
|
-
if (e) {
|
|
21
|
-
for (var k in e) {
|
|
22
|
-
n[k] = e[k];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
n.default = e;
|
|
26
|
-
return n;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
17
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
30
18
|
|
|
31
19
|
/**
|
|
32
20
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -44,14 +32,14 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
|
|
|
44
32
|
return;
|
|
45
33
|
}
|
|
46
34
|
} = optional;
|
|
47
|
-
|
|
35
|
+
react.useEffect(() => {
|
|
48
36
|
if (!editor.hasNodes([overflow.OverflowNode])) {
|
|
49
37
|
{
|
|
50
38
|
throw Error(`useCharacterLimit: OverflowNode not registered on editor`);
|
|
51
39
|
}
|
|
52
40
|
}
|
|
53
41
|
}, [editor]);
|
|
54
|
-
|
|
42
|
+
react.useEffect(() => {
|
|
55
43
|
let text$1 = editor.getEditorState().read(text.$rootTextContent);
|
|
56
44
|
let lastComputedTextLength = 0;
|
|
57
45
|
return utils.mergeRegister(editor.registerTextContentListener(currentText => {
|
|
@@ -82,7 +70,6 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
|
|
|
82
70
|
}, [editor, maxCharacters, remainingCharacters, strlen]);
|
|
83
71
|
}
|
|
84
72
|
function findOffset(text, maxCharacters, strlen) {
|
|
85
|
-
// @ts-ignore This is due to be added in a later version of TS
|
|
86
73
|
const Segmenter = Intl.Segmenter;
|
|
87
74
|
let offsetUtf16 = 0;
|
|
88
75
|
let offset = 0;
|
|
@@ -258,9 +245,10 @@ function utf8Length(text) {
|
|
|
258
245
|
function DefaultRenderer({
|
|
259
246
|
remainingCharacters
|
|
260
247
|
}) {
|
|
261
|
-
return /*#__PURE__*/
|
|
262
|
-
className: `characters-limit ${remainingCharacters < 0 ? 'characters-limit-exceeded' : ''}
|
|
263
|
-
|
|
248
|
+
return /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
249
|
+
className: `characters-limit ${remainingCharacters < 0 ? 'characters-limit-exceeded' : ''}`,
|
|
250
|
+
children: remainingCharacters
|
|
251
|
+
});
|
|
264
252
|
}
|
|
265
253
|
function CharacterLimitPlugin({
|
|
266
254
|
charset = 'UTF-16',
|
|
@@ -268,8 +256,8 @@ function CharacterLimitPlugin({
|
|
|
268
256
|
renderer = DefaultRenderer
|
|
269
257
|
}) {
|
|
270
258
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
271
|
-
const [remainingCharacters, setRemainingCharacters] =
|
|
272
|
-
const characterLimitProps =
|
|
259
|
+
const [remainingCharacters, setRemainingCharacters] = react.useState(maxLength);
|
|
260
|
+
const characterLimitProps = react.useMemo(() => ({
|
|
273
261
|
remainingCharacters: setRemainingCharacters,
|
|
274
262
|
strlen: text => {
|
|
275
263
|
if (charset === 'UTF-8') {
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
10
|
-
import * as React from 'react';
|
|
11
10
|
import { useEffect, useState, useMemo } from 'react';
|
|
12
11
|
import { OverflowNode, $isOverflowNode, $createOverflowNode } from '@lexical/overflow';
|
|
13
12
|
import { $rootTextContent } from '@lexical/text';
|
|
14
13
|
import { mergeRegister, $dfs } from '@lexical/utils';
|
|
15
14
|
import { $getSelection, $isRangeSelection, $isTextNode, $isLeafNode, $setSelection } from 'lexical';
|
|
15
|
+
import { jsx } from 'react/jsx-runtime';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -68,7 +68,6 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
|
|
|
68
68
|
}, [editor, maxCharacters, remainingCharacters, strlen]);
|
|
69
69
|
}
|
|
70
70
|
function findOffset(text, maxCharacters, strlen) {
|
|
71
|
-
// @ts-ignore This is due to be added in a later version of TS
|
|
72
71
|
const Segmenter = Intl.Segmenter;
|
|
73
72
|
let offsetUtf16 = 0;
|
|
74
73
|
let offset = 0;
|
|
@@ -244,9 +243,10 @@ function utf8Length(text) {
|
|
|
244
243
|
function DefaultRenderer({
|
|
245
244
|
remainingCharacters
|
|
246
245
|
}) {
|
|
247
|
-
return /*#__PURE__*/
|
|
248
|
-
className: `characters-limit ${remainingCharacters < 0 ? 'characters-limit-exceeded' : ''}
|
|
249
|
-
|
|
246
|
+
return /*#__PURE__*/jsx("span", {
|
|
247
|
+
className: `characters-limit ${remainingCharacters < 0 ? 'characters-limit-exceeded' : ''}`,
|
|
248
|
+
children: remainingCharacters
|
|
249
|
+
});
|
|
250
250
|
}
|
|
251
251
|
function CharacterLimitPlugin({
|
|
252
252
|
charset = 'UTF-16',
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
'use strict';var p=require("@lexical/react/LexicalComposerContext"),
|
|
10
|
-
function
|
|
11
|
-
function I(a,c,h=Object.freeze({})){let {strlen:f=l=>l.length,remainingCharacters:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function
|
|
16
|
-
function
|
|
17
|
-
exports.CharacterLimitPlugin=function({charset:a="UTF-16",maxLength:c=5,renderer:h=
|
|
9
|
+
'use strict';var p=require("@lexical/react/LexicalComposerContext"),v=require("react"),w=require("@lexical/overflow"),z=require("@lexical/text"),B=require("@lexical/utils"),C=require("lexical"),D=require("react/jsx-runtime"),F;
|
|
10
|
+
function G(a){let c=new URLSearchParams;c.append("code",a);for(let h=1;h<arguments.length;h++)c.append("v",arguments[h]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${c} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}F=G&&G.__esModule&&Object.prototype.hasOwnProperty.call(G,"default")?G["default"]:G;
|
|
11
|
+
function I(a,c,h=Object.freeze({})){let {strlen:f=l=>l.length,remainingCharacters:q=()=>{}}=h;v.useEffect(()=>{a.hasNodes([w.OverflowNode])||F(57)},[a]);v.useEffect(()=>{let l=a.getEditorState().read(z.$rootTextContent),m=0;return B.mergeRegister(a.registerTextContentListener(d=>{l=d}),a.registerUpdateListener(({dirtyLeaves:d,dirtyElements:r})=>{var x=a.isComposing();d=0<d.size||0<r.size;if(!x&&d){x=f(l);d=x>c||null!==m&&m>c;q(c-x);if(null===m||d){let t=J(l,c,f);a.update(()=>{let E=B.$dfs(),N=E.length,
|
|
12
|
+
y=0;for(let A=0;A<N;A+=1){var {node:b}=E[A];if(w.$isOverflowNode(b)){var e=y;if(y+b.getTextContentSize()<=t){var g=b.getParent();e=b.getPreviousSibling();var k=b.getNextSibling();K(b);b=C.$getSelection();!C.$isRangeSelection(b)||b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()||(C.$isTextNode(e)?e.select():C.$isTextNode(k)?k.select():null!==g&&g.select())}else e<t&&(g=b.getFirstDescendant(),k=null!==g?g.getTextContentSize():0,e+=k,g=C.$isTextNode(g)&&g.isSimpleText(),e=e<=t,(g||e)&&
|
|
13
|
+
K(b))}else if(C.$isLeafNode(b)&&(e=y,y+=b.getTextContentSize(),y>t&&!w.$isOverflowNode(b.getParent())&&(g=C.$getSelection(),e<t&&C.$isTextNode(b)&&b.isSimpleText()?([,b]=b.splitText(t-e),b=L(b)):b=L(b),null!==g&&C.$setSelection(g),e=b.getPreviousSibling(),w.$isOverflowNode(e)))){k=b.getFirstChild();var u=e.getChildren();g=u.length;if(null===k)b.append(...u);else for(var n=0;n<g;n++)k.insertBefore(u[n]);n=C.$getSelection();if(C.$isRangeSelection(n)){k=n.anchor;u=k.getNode();n=n.focus;let H=k.getNode();
|
|
14
|
+
u.is(e)?k.set(b.getKey(),k.offset,"element"):u.is(b)&&k.set(b.getKey(),g+k.offset,"element");H.is(e)?n.set(b.getKey(),n.offset,"element"):H.is(b)&&n.set(b.getKey(),g+n.offset,"element")}e.remove()}}},{tag:"history-merge"})}m=x}}))},[a,c,q,f])}
|
|
15
|
+
function J(a,c,h){var f=Intl.Segmenter;let q=0;var l=0;if("function"===typeof f){a=(new f).segment(a);for(var {segment:m}of a){l+=h(m);if(l>c)break;q+=m.length}}else for(m=Array.from(a),a=m.length,f=0;f<a;f++){let d=m[f];l+=h(d);if(l>c)break;q+=d.length}return q}function L(a){let c=w.$createOverflowNode();a.replace(c);c.append(a);return c}function K(a){let c=a.getChildren(),h=c.length;for(let f=0;f<h;f++)a.insertBefore(c[f]);a.remove();return 0<h?c[h-1]:null}let M=null;
|
|
16
|
+
function O({remainingCharacters:a}){return D.jsx("span",{className:`characters-limit ${0>a?"characters-limit-exceeded":""}`,children:a})}
|
|
17
|
+
exports.CharacterLimitPlugin=function({charset:a="UTF-16",maxLength:c=5,renderer:h=O}){let [f]=p.useLexicalComposerContext(),[q,l]=v.useState(c),m=v.useMemo(()=>({remainingCharacters:l,strlen:d=>{if("UTF-8"===a){if(void 0===window.TextEncoder)var r=null;else null===M&&(M=new window.TextEncoder),r=M;null===r?(r=encodeURIComponent(d).match(/%[89ABab]/g),d=d.length+(r?r.length:0)):d=r.encode(d).length;return d}if("UTF-16"===a)return d.length;throw Error("Unrecognized charset");}}),[a]);I(f,c,m);return h({remainingCharacters:q})}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";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{mergeRegister as c,$dfs as a}from"@lexical/utils";import{$getSelection as f,$isRangeSelection as g,$isTextNode as u,$isLeafNode as d,$setSelection as m}from"lexical";import{jsx as h}from"react/jsx-runtime";function p(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var x=p((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));function C(e,n,r=Object.freeze({})){const{strlen:s=(e=>e.length),remainingCharacters:h=(()=>{})}=r;t((()=>{e.hasNodes([o])||x(57)}),[e]),t((()=>{let t=e.getEditorState().read(l),r=0;return c(e.registerTextContentListener((e=>{t=e})),e.registerUpdateListener((({dirtyLeaves:o,dirtyElements:l})=>{const c=e.isComposing(),p=o.size>0||l.size>0;if(c||!p)return;const x=s(t),C=x>n||null!==r&&r>n;if(h(n-x),null===r||C){const r=function(e,t,n){const r=Intl.Segmenter;let o=0,i=0;if("function"==typeof r){const s=(new r).segment(e);for(const{segment:e}of s){const r=i+n(e);if(r>t)break;i=r,o+=e.length}}else{const r=Array.from(e),s=r.length;for(let e=0;e<s;e++){const s=r[e],l=i+n(s);if(l>t)break;i=l,o+=s.length}}return o}(t,n,s);e.update((()=>{!function(e){const t=a(),n=t.length;let r=0;for(let o=0;o<n;o+=1){const{node:n}=t[o];if(i(n)){const t=r;if(r+n.getTextContentSize()<=e){const e=n.getParent(),t=n.getPreviousSibling(),r=n.getNextSibling();w(n);const o=f();!g(o)||o.anchor.getNode().isAttached()&&o.focus.getNode().isAttached()||(u(t)?t.select():u(r)?r.select():null!==e&&e.select())}else if(t<e){const r=n.getFirstDescendant(),o=t+(null!==r?r.getTextContentSize():0);(u(r)&&r.isSimpleText()||o<=e)&&w(n)}}else if(d(n)){const t=r;if(r+=n.getTextContentSize(),r>e&&!i(n.getParent())){const r=f();let o;if(t<e&&u(n)&&n.isSimpleText()){const[,r]=n.splitText(e-t);o=v(r)}else o=v(n);null!==r&&m(r),T(o)}}}}(r)}),{tag:"history-merge"})}r=x})))}),[e,n,h,s])}function v(e){const t=s();return e.replace(t),t.append(e),t}function w(e){const t=e.getChildren(),n=t.length;for(let r=0;r<n;r++)e.insertBefore(t[r]);return e.remove(),n>0?t[n-1]:null}function T(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=f();if(g(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 y=null;function S(e){const t=void 0===window.TextEncoder?null:(null===y&&(y=new window.TextEncoder),y);if(null===t){const t=encodeURIComponent(e).match(/%[89ABab]/g);return e.length+(t?t.length:0)}return t.encode(e).length}function b({remainingCharacters:e}){return h("span",{className:"characters-limit "+(e<0?"characters-limit-exceeded":""),children:e})}function z({charset:t="UTF-16",maxLength:o=5,renderer:i=b}){const[s]=e(),[l,c]=n(o);return C(s,o,r((()=>({remainingCharacters:c,strlen:e=>{if("UTF-8"===t)return S(e);if("UTF-16"===t)return e.length;throw new Error("Unrecognized charset")}})),[t])),i({remainingCharacters:l})}export{z as CharacterLimitPlugin};
|
|
@@ -133,12 +133,14 @@ function handleClick(event) {
|
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
});
|
|
136
|
+
event.stopPropagation(); // Prevents potential parent-editor listeners from firing, causing the checkbox toggle to be undone
|
|
136
137
|
}
|
|
137
138
|
function handlePointerDown(event) {
|
|
138
139
|
handleCheckItemEvent(event, () => {
|
|
139
140
|
// Prevents caret moving when clicking on check mark
|
|
140
141
|
event.preventDefault();
|
|
141
142
|
});
|
|
143
|
+
event.stopPropagation();
|
|
142
144
|
}
|
|
143
145
|
function findEditor(target) {
|
|
144
146
|
let node = target;
|
|
@@ -131,12 +131,14 @@ function handleClick(event) {
|
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
});
|
|
134
|
+
event.stopPropagation(); // Prevents potential parent-editor listeners from firing, causing the checkbox toggle to be undone
|
|
134
135
|
}
|
|
135
136
|
function handlePointerDown(event) {
|
|
136
137
|
handleCheckItemEvent(event, () => {
|
|
137
138
|
// Prevents caret moving when clicking on check mark
|
|
138
139
|
event.preventDefault();
|
|
139
140
|
});
|
|
141
|
+
event.stopPropagation();
|
|
140
142
|
}
|
|
141
143
|
function findEditor(target) {
|
|
142
144
|
let node = target;
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';var e=require("@lexical/list"),g=require("@lexical/react/LexicalComposerContext"),k=require("@lexical/utils"),l=require("lexical"),m=require("react");function n(a,c){let b=a.target;if(null!==b&&k.isHTMLElement(b)){var d=b.firstChild;(null==d||!k.isHTMLElement(d)||"UL"!==d.tagName&&"OL"!==d.tagName)&&(d=b.parentNode)&&"check"===d.__lexicalListType&&(d=b.getBoundingClientRect(),a=a.pageX/k.calculateZoomLevel(b),("rtl"===b.dir?a<d.right&&a>d.right-20:a>d.left&&a<d.left+20)&&c())}}
|
|
10
|
-
function p(a){n(a,()=>{let c=a.target,b=q(c);null!=b&&b.isEditable()&&b.update(()=>{if(a.target){let d=l.$getNearestNodeFromDOMNode(c);e.$isListItemNode(d)&&(c.focus(),d.toggleChecked())}})})}function r(a){n(a,()=>{a.preventDefault()})}function q(a){for(;a;){if(a.__lexicalEditor)return a.__lexicalEditor;a=a.parentNode}return null}
|
|
11
|
-
function u(a,c){let b=c?a.getPreviousSibling():a.getNextSibling();for(;null==b&&e.$isListItemNode(a);)a=a.getParentOrThrow().getParent(),null!=a&&(b=c?a.getPreviousSibling():a.getNextSibling());for(;e.$isListItemNode(b);){a=c?b.getLastChild():b.getFirstChild();if(!e.$isListNode(a))return b;b=c?a.getLastChild():a.getFirstChild()}return null}
|
|
10
|
+
function p(a){n(a,()=>{let c=a.target,b=q(c);null!=b&&b.isEditable()&&b.update(()=>{if(a.target){let d=l.$getNearestNodeFromDOMNode(c);e.$isListItemNode(d)&&(c.focus(),d.toggleChecked())}})});a.stopPropagation()}function r(a){n(a,()=>{a.preventDefault()});a.stopPropagation()}function q(a){for(;a;){if(a.__lexicalEditor)return a.__lexicalEditor;a=a.parentNode}return null}
|
|
11
|
+
function t(){let a=document.activeElement;return null!=a&&"LI"===a.tagName&&null!=a.parentNode&&"check"===a.parentNode.__lexicalListType?a:null}function u(a,c){let b=c?a.getPreviousSibling():a.getNextSibling();for(;null==b&&e.$isListItemNode(a);)a=a.getParentOrThrow().getParent(),null!=a&&(b=c?a.getPreviousSibling():a.getNextSibling());for(;e.$isListItemNode(b);){a=c?b.getLastChild():b.getFirstChild();if(!e.$isListNode(a))return b;b=c?a.getLastChild():a.getFirstChild()}return null}
|
|
12
12
|
function v(a,c,b){let d=t();null!=d&&c.update(()=>{var f=l.$getNearestNodeFromDOMNode(d);if(e.$isListItemNode(f)&&(f=u(f,b),null!=f)){f.selectStart();let h=c.getElementByKey(f.__key);null!=h&&(a.preventDefault(),setTimeout(()=>{h.focus()},0))}});return!1}
|
|
13
13
|
exports.CheckListPlugin=function(){let [a]=g.useLexicalComposerContext();m.useEffect(()=>k.mergeRegister(a.registerCommand(e.INSERT_CHECK_LIST_COMMAND,()=>{e.insertList(a,"check");return!0},l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_DOWN_COMMAND,c=>v(c,a,!1),l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_UP_COMMAND,c=>v(c,a,!0),l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ESCAPE_COMMAND,()=>{if(null!=t()){let c=a.getRootElement();null!=c&&c.focus();return!0}return!1},l.COMMAND_PRIORITY_LOW),
|
|
14
14
|
a.registerCommand(l.KEY_SPACE_COMMAND,c=>{let b=t();return null!=b&&a.isEditable()?(a.update(()=>{let d=l.$getNearestNodeFromDOMNode(b);e.$isListItemNode(d)&&(c.preventDefault(),d.toggleChecked())}),!0):!1},l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_LEFT_COMMAND,c=>a.getEditorState().read(()=>{var b=l.$getSelection();if(l.$isRangeSelection(b)&&b.isCollapsed()){var {anchor:d}=b;if((b="element"===d.type)||0===d.offset){d=d.getNode();let f=k.$findMatchingParent(d,h=>l.$isElementNode(h)&&!h.isInline());
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{INSERT_CHECK_LIST_COMMAND as e,insertList as t,$isListItemNode as n,$isListNode as r}from"@lexical/list";import{useLexicalComposerContext as i}from"@lexical/react/LexicalComposerContext";import{mergeRegister as l,$findMatchingParent as o,isHTMLElement as c,calculateZoomLevel as
|
|
9
|
+
import{INSERT_CHECK_LIST_COMMAND as e,insertList as t,$isListItemNode as n,$isListNode as r}from"@lexical/list";import{useLexicalComposerContext as i}from"@lexical/react/LexicalComposerContext";import{mergeRegister as l,$findMatchingParent as o,isHTMLElement as c,calculateZoomLevel as s}from"@lexical/utils";import{COMMAND_PRIORITY_LOW as u,KEY_ARROW_DOWN_COMMAND as a,KEY_ARROW_UP_COMMAND as g,KEY_ESCAPE_COMMAND as f,KEY_SPACE_COMMAND as d,$getNearestNodeFromDOMNode as m,KEY_ARROW_LEFT_COMMAND as p,$getSelection as C,$isRangeSelection as h,$isElementNode as v}from"lexical";import{useEffect as E}from"react";function L(){const[c]=i();return E((()=>l(c.registerCommand(e,(()=>(t(c,"check"),!0)),u),c.registerCommand(a,(e=>N(e,c,!1)),u),c.registerCommand(g,(e=>N(e,c,!0)),u),c.registerCommand(f,(e=>{if(null!=y()){const e=c.getRootElement();return null!=e&&e.focus(),!0}return!1}),u),c.registerCommand(d,(e=>{const t=y();return!(null==t||!c.isEditable())&&(c.update((()=>{const r=m(t);n(r)&&(e.preventDefault(),r.toggleChecked())})),!0)}),u),c.registerCommand(p,(e=>c.getEditorState().read((()=>{const t=C();if(h(t)&&t.isCollapsed()){const{anchor:i}=t,l="element"===i.type;if(l||0===i.offset){const t=i.getNode(),s=o(t,(e=>v(e)&&!e.isInline()));if(n(s)){const n=s.getParent();if(r(n)&&"check"===n.getListType()&&(l||s.getFirstDescendant()===t)){const t=c.getElementByKey(s.__key);if(null!=t&&document.activeElement!==t)return t.focus(),e.preventDefault(),!0}}}}return!1}))),u),c.registerRootListener(((e,t)=>{null!==e&&(e.addEventListener("click",_),e.addEventListener("pointerdown",k)),null!==t&&(t.removeEventListener("click",_),t.removeEventListener("pointerdown",k))}))))),null}function x(e,t){const n=e.target;if(null===n||!c(n))return;const r=n.firstChild;if(null!=r&&c(r)&&("UL"===r.tagName||"OL"===r.tagName))return;const i=n.parentNode;if(!i||"check"!==i.__lexicalListType)return;const l=n.getBoundingClientRect(),o=e.pageX/s(n);("rtl"===n.dir?o<l.right&&o>l.right-20:o>l.left&&o<l.left+20)&&t()}function _(e){x(e,(()=>{const t=e.target,r=function(e){let t=e;for(;t;){if(t.__lexicalEditor)return t.__lexicalEditor;t=t.parentNode}return null}(t);null!=r&&r.isEditable()&&r.update((()=>{if(e.target){const e=m(t);n(e)&&(t.focus(),e.toggleChecked())}}))})),e.stopPropagation()}function k(e){x(e,(()=>{e.preventDefault()})),e.stopPropagation()}function y(){const e=document.activeElement;return null!=e&&"LI"===e.tagName&&null!=e.parentNode&&"check"===e.parentNode.__lexicalListType?e:null}function N(e,t,i){const l=y();return null!=l&&t.update((()=>{const o=m(l);if(!n(o))return;const c=function(e,t){let i=t?e.getPreviousSibling():e.getNextSibling(),l=e;for(;null==i&&n(l);)l=l.getParentOrThrow().getParent(),null!=l&&(i=t?l.getPreviousSibling():l.getNextSibling());for(;n(i);){const e=t?i.getLastChild():i.getFirstChild();if(!r(e))return i;i=t?e.getLastChild():e.getFirstChild()}return null}(o,i);if(null!=c){c.selectStart();const n=t.getElementByKey(c.__key);null!=n&&(e.preventDefault(),setTimeout((()=>{n.focus()}),0))}})),!1}export{L as CheckListPlugin};
|
|
@@ -30,6 +30,10 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
30
30
|
*
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
+
|
|
34
|
+
// This workaround is no longer necessary in React 19,
|
|
35
|
+
// but we currently support React >=17.x
|
|
36
|
+
// https://github.com/facebook/react/pull/26395
|
|
33
37
|
const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
|
|
34
38
|
|
|
35
39
|
/**
|
|
@@ -28,6 +28,10 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
28
28
|
*
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
+
|
|
32
|
+
// This workaround is no longer necessary in React 19,
|
|
33
|
+
// but we currently support React >=17.x
|
|
34
|
+
// https://github.com/facebook/react/pull/26395
|
|
31
35
|
const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
|
|
32
36
|
|
|
33
37
|
/**
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
8
|
+
export declare function ClickableLinkPlugin({ newTab, disabled, }: {
|
|
9
9
|
newTab?: boolean;
|
|
10
10
|
disabled?: boolean;
|
|
11
11
|
}): null;
|
|
12
|
+
/** @deprecated use the named export {@link ClickableLinkPlugin} */
|
|
13
|
+
export default ClickableLinkPlugin;
|
|
@@ -32,7 +32,7 @@ function findMatchingDOM(startNode, predicate) {
|
|
|
32
32
|
}
|
|
33
33
|
return null;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function ClickableLinkPlugin({
|
|
36
36
|
newTab = true,
|
|
37
37
|
disabled = false
|
|
38
38
|
}) {
|
|
@@ -100,4 +100,5 @@ function LexicalClickableLinkPlugin({
|
|
|
100
100
|
return null;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
exports.ClickableLinkPlugin = ClickableLinkPlugin;
|
|
104
|
+
exports.default = ClickableLinkPlugin;
|
|
@@ -30,7 +30,7 @@ function findMatchingDOM(startNode, predicate) {
|
|
|
30
30
|
}
|
|
31
31
|
return null;
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function ClickableLinkPlugin({
|
|
34
34
|
newTab = true,
|
|
35
35
|
disabled = false
|
|
36
36
|
}) {
|
|
@@ -98,4 +98,4 @@ function LexicalClickableLinkPlugin({
|
|
|
98
98
|
return null;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
export {
|
|
101
|
+
export { ClickableLinkPlugin, ClickableLinkPlugin as default };
|
|
@@ -9,4 +9,5 @@
|
|
|
9
9
|
import * as modDev from './LexicalClickableLinkPlugin.dev.mjs';
|
|
10
10
|
import * as modProd from './LexicalClickableLinkPlugin.prod.mjs';
|
|
11
11
|
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
12
|
+
export const ClickableLinkPlugin = mod.ClickableLinkPlugin;
|
|
12
13
|
export default mod.default;
|