@lexical/react 0.13.0 → 0.14.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.
Files changed (181) hide show
  1. package/LexicalAutoEmbedPlugin.dev.esm.js +131 -0
  2. package/LexicalAutoEmbedPlugin.esm.js +13 -0
  3. package/LexicalAutoEmbedPlugin.js +1 -1
  4. package/LexicalAutoEmbedPlugin.prod.esm.js +7 -0
  5. package/LexicalAutoFocusPlugin.dev.esm.js +42 -0
  6. package/LexicalAutoFocusPlugin.dev.js +0 -5
  7. package/LexicalAutoFocusPlugin.esm.js +10 -0
  8. package/LexicalAutoFocusPlugin.js +1 -1
  9. package/LexicalAutoFocusPlugin.prod.esm.js +7 -0
  10. package/LexicalAutoFocusPlugin.prod.js +1 -1
  11. package/LexicalAutoLinkPlugin.dev.esm.js +312 -0
  12. package/LexicalAutoLinkPlugin.dev.js +3 -1
  13. package/LexicalAutoLinkPlugin.esm.js +11 -0
  14. package/LexicalAutoLinkPlugin.js +1 -1
  15. package/LexicalAutoLinkPlugin.prod.esm.js +7 -0
  16. package/LexicalBlockWithAlignableContents.dev.esm.js +86 -0
  17. package/LexicalBlockWithAlignableContents.dev.js +1 -0
  18. package/LexicalBlockWithAlignableContents.esm.js +10 -0
  19. package/LexicalBlockWithAlignableContents.js +1 -1
  20. package/LexicalBlockWithAlignableContents.prod.esm.js +7 -0
  21. package/LexicalBlockWithAlignableContents.prod.js +1 -1
  22. package/LexicalCharacterLimitPlugin.d.ts +4 -1
  23. package/LexicalCharacterLimitPlugin.dev.esm.js +272 -0
  24. package/LexicalCharacterLimitPlugin.dev.js +12 -4
  25. package/LexicalCharacterLimitPlugin.esm.js +10 -0
  26. package/LexicalCharacterLimitPlugin.js +1 -1
  27. package/LexicalCharacterLimitPlugin.prod.esm.js +7 -0
  28. package/LexicalCharacterLimitPlugin.prod.js +9 -9
  29. package/LexicalCheckListPlugin.dev.esm.js +203 -0
  30. package/LexicalCheckListPlugin.esm.js +10 -0
  31. package/LexicalCheckListPlugin.js +1 -1
  32. package/LexicalCheckListPlugin.prod.esm.js +7 -0
  33. package/LexicalClearEditorPlugin.dev.esm.js +64 -0
  34. package/LexicalClearEditorPlugin.esm.js +10 -0
  35. package/LexicalClearEditorPlugin.js +1 -1
  36. package/LexicalClearEditorPlugin.prod.esm.js +7 -0
  37. package/LexicalClickableLinkPlugin.dev.esm.js +95 -0
  38. package/LexicalClickableLinkPlugin.esm.js +10 -0
  39. package/LexicalClickableLinkPlugin.js +1 -1
  40. package/LexicalClickableLinkPlugin.prod.esm.js +7 -0
  41. package/LexicalCollaborationContext.dev.esm.js +36 -0
  42. package/LexicalCollaborationContext.esm.js +11 -0
  43. package/LexicalCollaborationContext.js +1 -1
  44. package/LexicalCollaborationContext.prod.esm.js +7 -0
  45. package/LexicalCollaborationPlugin.dev.esm.js +308 -0
  46. package/LexicalCollaborationPlugin.esm.js +10 -0
  47. package/LexicalCollaborationPlugin.js +1 -1
  48. package/LexicalCollaborationPlugin.prod.esm.js +7 -0
  49. package/LexicalComposer.dev.esm.js +129 -0
  50. package/LexicalComposer.esm.js +10 -0
  51. package/LexicalComposer.js +1 -1
  52. package/LexicalComposer.prod.esm.js +7 -0
  53. package/LexicalComposerContext.dev.esm.js +42 -0
  54. package/LexicalComposerContext.esm.js +12 -0
  55. package/LexicalComposerContext.js +1 -1
  56. package/LexicalComposerContext.prod.esm.js +7 -0
  57. package/LexicalContentEditable.dev.esm.js +107 -0
  58. package/LexicalContentEditable.dev.js +5 -1
  59. package/LexicalContentEditable.esm.js +10 -0
  60. package/LexicalContentEditable.js +1 -1
  61. package/LexicalContentEditable.prod.esm.js +7 -0
  62. package/LexicalContentEditable.prod.js +3 -3
  63. package/LexicalContextMenuPlugin.dev.esm.js +455 -0
  64. package/LexicalContextMenuPlugin.dev.js +3 -1
  65. package/LexicalContextMenuPlugin.esm.js +11 -0
  66. package/LexicalContextMenuPlugin.js +1 -1
  67. package/LexicalContextMenuPlugin.prod.esm.js +7 -0
  68. package/LexicalDecoratorBlockNode.dev.esm.js +46 -0
  69. package/LexicalDecoratorBlockNode.esm.js +11 -0
  70. package/LexicalDecoratorBlockNode.js +1 -1
  71. package/LexicalDecoratorBlockNode.prod.esm.js +7 -0
  72. package/LexicalEditorRefPlugin.dev.esm.js +40 -0
  73. package/LexicalEditorRefPlugin.dev.js +10 -5
  74. package/LexicalEditorRefPlugin.esm.js +10 -0
  75. package/LexicalEditorRefPlugin.js +1 -1
  76. package/LexicalEditorRefPlugin.prod.esm.js +7 -0
  77. package/LexicalEditorRefPlugin.prod.js +1 -1
  78. package/LexicalErrorBoundary.dev.esm.js +157 -0
  79. package/LexicalErrorBoundary.esm.js +10 -0
  80. package/LexicalErrorBoundary.js +1 -1
  81. package/LexicalErrorBoundary.prod.esm.js +7 -0
  82. package/LexicalHashtagPlugin.dev.esm.js +163 -0
  83. package/LexicalHashtagPlugin.esm.js +10 -0
  84. package/LexicalHashtagPlugin.js +1 -1
  85. package/LexicalHashtagPlugin.prod.esm.js +7 -0
  86. package/LexicalHistoryPlugin.dev.esm.js +41 -0
  87. package/LexicalHistoryPlugin.esm.js +11 -0
  88. package/LexicalHistoryPlugin.js +1 -1
  89. package/LexicalHistoryPlugin.prod.esm.js +7 -0
  90. package/LexicalHorizontalRuleNode.dev.esm.js +118 -0
  91. package/LexicalHorizontalRuleNode.dev.js +1 -0
  92. package/LexicalHorizontalRuleNode.esm.js +13 -0
  93. package/LexicalHorizontalRuleNode.js +1 -1
  94. package/LexicalHorizontalRuleNode.prod.esm.js +7 -0
  95. package/LexicalHorizontalRuleNode.prod.js +1 -1
  96. package/LexicalHorizontalRulePlugin.dev.esm.js +39 -0
  97. package/LexicalHorizontalRulePlugin.esm.js +10 -0
  98. package/LexicalHorizontalRulePlugin.js +1 -1
  99. package/LexicalHorizontalRulePlugin.prod.esm.js +7 -0
  100. package/LexicalLinkPlugin.dev.esm.js +79 -0
  101. package/LexicalLinkPlugin.dev.js +6 -2
  102. package/LexicalLinkPlugin.esm.js +10 -0
  103. package/LexicalLinkPlugin.js +1 -1
  104. package/LexicalLinkPlugin.prod.esm.js +7 -0
  105. package/LexicalLinkPlugin.prod.js +1 -1
  106. package/LexicalListPlugin.dev.esm.js +59 -0
  107. package/LexicalListPlugin.esm.js +10 -0
  108. package/LexicalListPlugin.js +1 -1
  109. package/LexicalListPlugin.prod.esm.js +7 -0
  110. package/LexicalMarkdownShortcutPlugin.dev.esm.js +49 -0
  111. package/LexicalMarkdownShortcutPlugin.esm.js +11 -0
  112. package/LexicalMarkdownShortcutPlugin.js +1 -1
  113. package/LexicalMarkdownShortcutPlugin.prod.esm.js +7 -0
  114. package/LexicalNestedComposer.dev.esm.js +105 -0
  115. package/LexicalNestedComposer.esm.js +10 -0
  116. package/LexicalNestedComposer.js +1 -1
  117. package/LexicalNestedComposer.prod.esm.js +7 -0
  118. package/LexicalNodeEventPlugin.dev.esm.js +56 -0
  119. package/LexicalNodeEventPlugin.esm.js +10 -0
  120. package/LexicalNodeEventPlugin.js +1 -1
  121. package/LexicalNodeEventPlugin.prod.esm.js +7 -0
  122. package/LexicalNodeMenuPlugin.dev.esm.js +466 -0
  123. package/LexicalNodeMenuPlugin.dev.js +3 -1
  124. package/LexicalNodeMenuPlugin.esm.js +11 -0
  125. package/LexicalNodeMenuPlugin.js +1 -1
  126. package/LexicalNodeMenuPlugin.prod.esm.js +7 -0
  127. package/LexicalOnChangePlugin.dev.esm.js +62 -0
  128. package/LexicalOnChangePlugin.esm.js +10 -0
  129. package/LexicalOnChangePlugin.js +1 -1
  130. package/LexicalOnChangePlugin.prod.esm.js +7 -0
  131. package/LexicalPlainTextPlugin.dev.esm.js +161 -0
  132. package/LexicalPlainTextPlugin.esm.js +10 -0
  133. package/LexicalPlainTextPlugin.js +1 -1
  134. package/LexicalPlainTextPlugin.prod.esm.js +7 -0
  135. package/LexicalRichTextPlugin.dev.esm.js +161 -0
  136. package/LexicalRichTextPlugin.esm.js +10 -0
  137. package/LexicalRichTextPlugin.js +1 -1
  138. package/LexicalRichTextPlugin.prod.esm.js +7 -0
  139. package/LexicalTabIndentationPlugin.dev.esm.js +76 -0
  140. package/LexicalTabIndentationPlugin.esm.js +11 -0
  141. package/LexicalTabIndentationPlugin.js +1 -1
  142. package/LexicalTabIndentationPlugin.prod.esm.js +7 -0
  143. package/LexicalTableOfContents.dev.esm.js +157 -0
  144. package/LexicalTableOfContents.esm.js +10 -0
  145. package/LexicalTableOfContents.js +1 -1
  146. package/LexicalTableOfContents.prod.esm.js +7 -0
  147. package/LexicalTablePlugin.dev.esm.js +163 -0
  148. package/LexicalTablePlugin.esm.js +10 -0
  149. package/LexicalTablePlugin.js +1 -1
  150. package/LexicalTablePlugin.prod.esm.js +7 -0
  151. package/LexicalTreeView.dev.esm.js +483 -0
  152. package/LexicalTreeView.dev.js +3 -1
  153. package/LexicalTreeView.esm.js +10 -0
  154. package/LexicalTreeView.js +1 -1
  155. package/LexicalTreeView.prod.esm.js +7 -0
  156. package/LexicalTypeaheadMenuPlugin.dev.esm.js +569 -0
  157. package/LexicalTypeaheadMenuPlugin.dev.js +3 -1
  158. package/LexicalTypeaheadMenuPlugin.esm.js +16 -0
  159. package/LexicalTypeaheadMenuPlugin.js +1 -1
  160. package/LexicalTypeaheadMenuPlugin.prod.esm.js +7 -0
  161. package/package.json +583 -20
  162. package/useLexicalEditable.dev.esm.js +82 -0
  163. package/useLexicalEditable.esm.js +10 -0
  164. package/useLexicalEditable.js +1 -1
  165. package/useLexicalEditable.prod.esm.js +7 -0
  166. package/useLexicalIsTextContentEmpty.dev.esm.js +51 -0
  167. package/useLexicalIsTextContentEmpty.esm.js +10 -0
  168. package/useLexicalIsTextContentEmpty.js +1 -1
  169. package/useLexicalIsTextContentEmpty.prod.esm.js +7 -0
  170. package/useLexicalNodeSelection.dev.esm.js +69 -0
  171. package/useLexicalNodeSelection.esm.js +10 -0
  172. package/useLexicalNodeSelection.js +1 -1
  173. package/useLexicalNodeSelection.prod.esm.js +7 -0
  174. package/useLexicalSubscription.dev.esm.js +63 -0
  175. package/useLexicalSubscription.esm.js +10 -0
  176. package/useLexicalSubscription.js +1 -1
  177. package/useLexicalSubscription.prod.esm.js +7 -0
  178. package/useLexicalTextEntity.dev.esm.js +26 -0
  179. package/useLexicalTextEntity.esm.js +10 -0
  180. package/useLexicalTextEntity.js +1 -1
  181. package/useLexicalTextEntity.prod.esm.js +7 -0
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
8
+ import { $isDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode';
9
+ import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
10
+ import { mergeRegister, $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
11
+ import { $isNodeSelection, $getSelection, $getNodeByKey, $isDecoratorNode, FORMAT_ELEMENT_COMMAND, $isRangeSelection, COMMAND_PRIORITY_LOW, CLICK_COMMAND, KEY_DELETE_COMMAND, KEY_BACKSPACE_COMMAND } from 'lexical';
12
+ import * as React from 'react';
13
+ import { useRef, useCallback, useEffect } from 'react';
14
+
15
+ /**
16
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
17
+ *
18
+ * This source code is licensed under the MIT license found in the
19
+ * LICENSE file in the root directory of this source tree.
20
+ *
21
+ */
22
+ function BlockWithAlignableContents({
23
+ children,
24
+ format,
25
+ nodeKey,
26
+ className
27
+ }) {
28
+ const [editor] = useLexicalComposerContext();
29
+ const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
30
+ const ref = useRef(null);
31
+ const onDelete = useCallback(event => {
32
+ if (isSelected && $isNodeSelection($getSelection())) {
33
+ event.preventDefault();
34
+ const node = $getNodeByKey(nodeKey);
35
+ if ($isDecoratorNode(node)) {
36
+ node.remove();
37
+ return true;
38
+ }
39
+ }
40
+ return false;
41
+ }, [isSelected, nodeKey]);
42
+ useEffect(() => {
43
+ return mergeRegister(editor.registerCommand(FORMAT_ELEMENT_COMMAND, formatType => {
44
+ if (isSelected) {
45
+ const selection = $getSelection();
46
+ if ($isNodeSelection(selection)) {
47
+ const node = $getNodeByKey(nodeKey);
48
+ if ($isDecoratorBlockNode(node)) {
49
+ node.setFormat(formatType);
50
+ }
51
+ } else if ($isRangeSelection(selection)) {
52
+ const nodes = selection.getNodes();
53
+ for (const node of nodes) {
54
+ if ($isDecoratorBlockNode(node)) {
55
+ node.setFormat(formatType);
56
+ } else {
57
+ const element = $getNearestBlockElementAncestorOrThrow(node);
58
+ element.setFormat(formatType);
59
+ }
60
+ }
61
+ }
62
+ return true;
63
+ }
64
+ return false;
65
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(CLICK_COMMAND, event => {
66
+ if (event.target === ref.current) {
67
+ event.preventDefault();
68
+ if (!event.shiftKey) {
69
+ clearSelection();
70
+ }
71
+ setSelected(!isSelected);
72
+ return true;
73
+ }
74
+ return false;
75
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_DELETE_COMMAND, onDelete, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_BACKSPACE_COMMAND, onDelete, COMMAND_PRIORITY_LOW));
76
+ }, [clearSelection, editor, isSelected, nodeKey, onDelete, setSelected]);
77
+ return /*#__PURE__*/React.createElement("div", {
78
+ className: [className.base, isSelected ? className.focus : null].filter(Boolean).join(' '),
79
+ ref: ref,
80
+ style: {
81
+ textAlign: format ? format : undefined
82
+ }
83
+ }, children);
84
+ }
85
+
86
+ export { BlockWithAlignableContents };
@@ -35,6 +35,7 @@ function BlockWithAlignableContents({
35
35
  const node = lexical.$getNodeByKey(nodeKey);
36
36
  if (lexical.$isDecoratorNode(node)) {
37
37
  node.remove();
38
+ return true;
38
39
  }
39
40
  }
40
41
  return false;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import * as modDev from './LexicalBlockWithAlignableContents.dev.esm.js';
8
+ import * as modProd from './LexicalBlockWithAlignableContents.prod.esm.js';
9
+ const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
10
+ export const BlockWithAlignableContents = mod.BlockWithAlignableContents;
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict'
8
- const LexicalBlockWithAlignableContents = process.env.NODE_ENV === 'development' ? require('./LexicalBlockWithAlignableContents.dev.js') : require('./LexicalBlockWithAlignableContents.prod.js')
8
+ const LexicalBlockWithAlignableContents = process.env.NODE_ENV === 'development' ? require('./LexicalBlockWithAlignableContents.dev.js') : require('./LexicalBlockWithAlignableContents.prod.js');
9
9
  module.exports = LexicalBlockWithAlignableContents;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ 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 a,$getSelection as l,$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 p}from"lexical";import*as x from"react";import{useRef as g,useCallback as C,useEffect as v}from"react";function N({children:N,format:y,nodeKey:D,className:F}){const[L]=e(),[h,B,K]=t(D),b=g(null),j=C((e=>{if(h&&a(l())){e.preventDefault();const r=m(D);if(n(r))return r.remove(),!0}return!1}),[h,D]);return v((()=>o(L.registerCommand(c,(e=>{if(h){const t=l();if(a(t)){const t=m(D);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),L.registerCommand(u,(e=>e.target===b.current&&(e.preventDefault(),e.shiftKey||K(),B(!h),!0)),f),L.registerCommand(d,j,f),L.registerCommand(p,j,f))),[K,L,h,D,j,B]),x.createElement("div",{className:[F.base,h?F.focus:null].filter(Boolean).join(" "),ref:b,style:{textAlign:y||void 0}},N)}export{N as BlockWithAlignableContents};
@@ -5,6 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  '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");
8
- exports.BlockWithAlignableContents=function({children:w,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());return!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)&&
8
+ exports.BlockWithAlignableContents=function({children:w,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)&&
9
9
  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 v.createElement("div",
10
10
  {className:[p.base,c?p.focus:null].filter(Boolean).join(" "),ref:t,style:{textAlign:n?n:void 0}},w)}
@@ -6,7 +6,10 @@
6
6
  *
7
7
  */
8
8
  /// <reference types="react" />
9
- export declare function CharacterLimitPlugin({ charset, maxLength, }: {
9
+ export declare function CharacterLimitPlugin({ charset, maxLength, renderer, }: {
10
10
  charset: 'UTF-8' | 'UTF-16';
11
11
  maxLength: number;
12
+ renderer?: ({ remainingCharacters, }: {
13
+ remainingCharacters: number;
14
+ }) => JSX.Element;
12
15
  }): JSX.Element;
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
8
+ import * as React from 'react';
9
+ import { useEffect, useState, useMemo } from 'react';
10
+ import { OverflowNode, $isOverflowNode, $createOverflowNode } from '@lexical/overflow';
11
+ import { $rootTextContent } from '@lexical/text';
12
+ import { mergeRegister, $dfs } from '@lexical/utils';
13
+ import { $getSelection, $isRangeSelection, $isTextNode, $isLeafNode, $setSelection } from 'lexical';
14
+
15
+ /**
16
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
17
+ *
18
+ * This source code is licensed under the MIT license found in the
19
+ * LICENSE file in the root directory of this source tree.
20
+ *
21
+ */
22
+ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({})) {
23
+ const {
24
+ strlen = input => input.length,
25
+ // UTF-16
26
+ remainingCharacters = () => {
27
+ return;
28
+ }
29
+ } = optional;
30
+ useEffect(() => {
31
+ if (!editor.hasNodes([OverflowNode])) {
32
+ {
33
+ throw Error(`useCharacterLimit: OverflowNode not registered on editor`);
34
+ }
35
+ }
36
+ }, [editor]);
37
+ useEffect(() => {
38
+ let text = editor.getEditorState().read($rootTextContent);
39
+ let lastComputedTextLength = 0;
40
+ return mergeRegister(editor.registerTextContentListener(currentText => {
41
+ text = currentText;
42
+ }), editor.registerUpdateListener(({
43
+ dirtyLeaves,
44
+ dirtyElements
45
+ }) => {
46
+ const isComposing = editor.isComposing();
47
+ const hasContentChanges = dirtyLeaves.size > 0 || dirtyElements.size > 0;
48
+ if (isComposing || !hasContentChanges) {
49
+ return;
50
+ }
51
+ const textLength = strlen(text);
52
+ const textLengthAboveThreshold = textLength > maxCharacters || lastComputedTextLength !== null && lastComputedTextLength > maxCharacters;
53
+ const diff = maxCharacters - textLength;
54
+ remainingCharacters(diff);
55
+ if (lastComputedTextLength === null || textLengthAboveThreshold) {
56
+ const offset = findOffset(text, maxCharacters, strlen);
57
+ editor.update(() => {
58
+ $wrapOverflowedNodes(offset);
59
+ }, {
60
+ tag: 'history-merge'
61
+ });
62
+ }
63
+ lastComputedTextLength = textLength;
64
+ }));
65
+ }, [editor, maxCharacters, remainingCharacters, strlen]);
66
+ }
67
+ function findOffset(text, maxCharacters, strlen) {
68
+ // @ts-ignore This is due to be added in a later version of TS
69
+ const Segmenter = Intl.Segmenter;
70
+ let offsetUtf16 = 0;
71
+ let offset = 0;
72
+ if (typeof Segmenter === 'function') {
73
+ const segmenter = new Segmenter();
74
+ const graphemes = segmenter.segment(text);
75
+ for (const {
76
+ segment: grapheme
77
+ } of graphemes) {
78
+ const nextOffset = offset + strlen(grapheme);
79
+ if (nextOffset > maxCharacters) {
80
+ break;
81
+ }
82
+ offset = nextOffset;
83
+ offsetUtf16 += grapheme.length;
84
+ }
85
+ } else {
86
+ const codepoints = Array.from(text);
87
+ const codepointsLength = codepoints.length;
88
+ for (let i = 0; i < codepointsLength; i++) {
89
+ const codepoint = codepoints[i];
90
+ const nextOffset = offset + strlen(codepoint);
91
+ if (nextOffset > maxCharacters) {
92
+ break;
93
+ }
94
+ offset = nextOffset;
95
+ offsetUtf16 += codepoint.length;
96
+ }
97
+ }
98
+ return offsetUtf16;
99
+ }
100
+ function $wrapOverflowedNodes(offset) {
101
+ const dfsNodes = $dfs();
102
+ const dfsNodesLength = dfsNodes.length;
103
+ let accumulatedLength = 0;
104
+ for (let i = 0; i < dfsNodesLength; i += 1) {
105
+ const {
106
+ node
107
+ } = dfsNodes[i];
108
+ if ($isOverflowNode(node)) {
109
+ const previousLength = accumulatedLength;
110
+ const nextLength = accumulatedLength + node.getTextContentSize();
111
+ if (nextLength <= offset) {
112
+ const parent = node.getParent();
113
+ const previousSibling = node.getPreviousSibling();
114
+ const nextSibling = node.getNextSibling();
115
+ $unwrapNode(node);
116
+ const selection = $getSelection();
117
+
118
+ // Restore selection when the overflow children are removed
119
+ if ($isRangeSelection(selection) && (!selection.anchor.getNode().isAttached() || !selection.focus.getNode().isAttached())) {
120
+ if ($isTextNode(previousSibling)) {
121
+ previousSibling.select();
122
+ } else if ($isTextNode(nextSibling)) {
123
+ nextSibling.select();
124
+ } else if (parent !== null) {
125
+ parent.select();
126
+ }
127
+ }
128
+ } else if (previousLength < offset) {
129
+ const descendant = node.getFirstDescendant();
130
+ const descendantLength = descendant !== null ? descendant.getTextContentSize() : 0;
131
+ const previousPlusDescendantLength = previousLength + descendantLength;
132
+ // For simple text we can redimension the overflow into a smaller and more accurate
133
+ // container
134
+ const firstDescendantIsSimpleText = $isTextNode(descendant) && descendant.isSimpleText();
135
+ const firstDescendantDoesNotOverflow = previousPlusDescendantLength <= offset;
136
+ if (firstDescendantIsSimpleText || firstDescendantDoesNotOverflow) {
137
+ $unwrapNode(node);
138
+ }
139
+ }
140
+ } else if ($isLeafNode(node)) {
141
+ const previousAccumulatedLength = accumulatedLength;
142
+ accumulatedLength += node.getTextContentSize();
143
+ if (accumulatedLength > offset && !$isOverflowNode(node.getParent())) {
144
+ const previousSelection = $getSelection();
145
+ let overflowNode;
146
+
147
+ // For simple text we can improve the limit accuracy by splitting the TextNode
148
+ // on the split point
149
+ if (previousAccumulatedLength < offset && $isTextNode(node) && node.isSimpleText()) {
150
+ const [, overflowedText] = node.splitText(offset - previousAccumulatedLength);
151
+ overflowNode = $wrapNode(overflowedText);
152
+ } else {
153
+ overflowNode = $wrapNode(node);
154
+ }
155
+ if (previousSelection !== null) {
156
+ $setSelection(previousSelection);
157
+ }
158
+ mergePrevious(overflowNode);
159
+ }
160
+ }
161
+ }
162
+ }
163
+ function $wrapNode(node) {
164
+ const overflowNode = $createOverflowNode();
165
+ node.insertBefore(overflowNode);
166
+ overflowNode.append(node);
167
+ return overflowNode;
168
+ }
169
+ function $unwrapNode(node) {
170
+ const children = node.getChildren();
171
+ const childrenLength = children.length;
172
+ for (let i = 0; i < childrenLength; i++) {
173
+ node.insertBefore(children[i]);
174
+ }
175
+ node.remove();
176
+ return childrenLength > 0 ? children[childrenLength - 1] : null;
177
+ }
178
+ function mergePrevious(overflowNode) {
179
+ const previousNode = overflowNode.getPreviousSibling();
180
+ if (!$isOverflowNode(previousNode)) {
181
+ return;
182
+ }
183
+ const firstChild = overflowNode.getFirstChild();
184
+ const previousNodeChildren = previousNode.getChildren();
185
+ const previousNodeChildrenLength = previousNodeChildren.length;
186
+ if (firstChild === null) {
187
+ overflowNode.append(...previousNodeChildren);
188
+ } else {
189
+ for (let i = 0; i < previousNodeChildrenLength; i++) {
190
+ firstChild.insertBefore(previousNodeChildren[i]);
191
+ }
192
+ }
193
+ const selection = $getSelection();
194
+ if ($isRangeSelection(selection)) {
195
+ const anchor = selection.anchor;
196
+ const anchorNode = anchor.getNode();
197
+ const focus = selection.focus;
198
+ const focusNode = anchor.getNode();
199
+ if (anchorNode.is(previousNode)) {
200
+ anchor.set(overflowNode.getKey(), anchor.offset, 'element');
201
+ } else if (anchorNode.is(overflowNode)) {
202
+ anchor.set(overflowNode.getKey(), previousNodeChildrenLength + anchor.offset, 'element');
203
+ }
204
+ if (focusNode.is(previousNode)) {
205
+ focus.set(overflowNode.getKey(), focus.offset, 'element');
206
+ } else if (focusNode.is(overflowNode)) {
207
+ focus.set(overflowNode.getKey(), previousNodeChildrenLength + focus.offset, 'element');
208
+ }
209
+ }
210
+ previousNode.remove();
211
+ }
212
+
213
+ /**
214
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
215
+ *
216
+ * This source code is licensed under the MIT license found in the
217
+ * LICENSE file in the root directory of this source tree.
218
+ *
219
+ */
220
+ const CHARACTER_LIMIT = 5;
221
+ let textEncoderInstance = null;
222
+ function textEncoder() {
223
+ if (window.TextEncoder === undefined) {
224
+ return null;
225
+ }
226
+ if (textEncoderInstance === null) {
227
+ textEncoderInstance = new window.TextEncoder();
228
+ }
229
+ return textEncoderInstance;
230
+ }
231
+ function utf8Length(text) {
232
+ const currentTextEncoder = textEncoder();
233
+ if (currentTextEncoder === null) {
234
+ // http://stackoverflow.com/a/5515960/210370
235
+ const m = encodeURIComponent(text).match(/%[89ABab]/g);
236
+ return text.length + (m ? m.length : 0);
237
+ }
238
+ return currentTextEncoder.encode(text).length;
239
+ }
240
+ function DefaultRenderer({
241
+ remainingCharacters
242
+ }) {
243
+ return /*#__PURE__*/React.createElement("span", {
244
+ className: `characters-limit ${remainingCharacters < 0 ? 'characters-limit-exceeded' : ''}`
245
+ }, remainingCharacters);
246
+ }
247
+ function CharacterLimitPlugin({
248
+ charset = 'UTF-16',
249
+ maxLength = CHARACTER_LIMIT,
250
+ renderer = DefaultRenderer
251
+ }) {
252
+ const [editor] = useLexicalComposerContext();
253
+ const [remainingCharacters, setRemainingCharacters] = useState(maxLength);
254
+ const characterLimitProps = useMemo(() => ({
255
+ remainingCharacters: setRemainingCharacters,
256
+ strlen: text => {
257
+ if (charset === 'UTF-8') {
258
+ return utf8Length(text);
259
+ } else if (charset === 'UTF-16') {
260
+ return text.length;
261
+ } else {
262
+ throw new Error('Unrecognized charset');
263
+ }
264
+ }
265
+ }), [charset]);
266
+ useCharacterLimit(editor, maxLength, characterLimitProps);
267
+ return renderer({
268
+ remainingCharacters
269
+ });
270
+ }
271
+
272
+ export { CharacterLimitPlugin };
@@ -238,9 +238,17 @@ function utf8Length(text) {
238
238
  }
239
239
  return currentTextEncoder.encode(text).length;
240
240
  }
241
+ function DefaultRenderer({
242
+ remainingCharacters
243
+ }) {
244
+ return /*#__PURE__*/React.createElement("span", {
245
+ className: `characters-limit ${remainingCharacters < 0 ? 'characters-limit-exceeded' : ''}`
246
+ }, remainingCharacters);
247
+ }
241
248
  function CharacterLimitPlugin({
242
249
  charset = 'UTF-16',
243
- maxLength = CHARACTER_LIMIT
250
+ maxLength = CHARACTER_LIMIT,
251
+ renderer = DefaultRenderer
244
252
  }) {
245
253
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
246
254
  const [remainingCharacters, setRemainingCharacters] = React.useState(maxLength);
@@ -257,9 +265,9 @@ function CharacterLimitPlugin({
257
265
  }
258
266
  }), [charset]);
259
267
  useCharacterLimit(editor, maxLength, characterLimitProps);
260
- return /*#__PURE__*/React.createElement("span", {
261
- className: `characters-limit ${remainingCharacters < 0 ? 'characters-limit-exceeded' : ''}`
262
- }, remainingCharacters);
268
+ return renderer({
269
+ remainingCharacters
270
+ });
263
271
  }
264
272
 
265
273
  exports.CharacterLimitPlugin = CharacterLimitPlugin;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import * as modDev from './LexicalCharacterLimitPlugin.dev.esm.js';
8
+ import * as modProd from './LexicalCharacterLimitPlugin.prod.esm.js';
9
+ const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
10
+ export const CharacterLimitPlugin = mod.CharacterLimitPlugin;
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict'
8
- const LexicalCharacterLimitPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalCharacterLimitPlugin.dev.js') : require('./LexicalCharacterLimitPlugin.prod.js')
8
+ const LexicalCharacterLimitPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalCharacterLimitPlugin.dev.js') : require('./LexicalCharacterLimitPlugin.prod.js');
9
9
  module.exports = LexicalCharacterLimitPlugin;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import*as t from"react";import{useEffect as n,useState as r,useMemo as o}from"react";import{OverflowNode as i,$isOverflowNode as s,$createOverflowNode as l}from"@lexical/overflow";import{$rootTextContent as c}from"@lexical/text";import{mergeRegister as a,$dfs as f}from"@lexical/utils";import{$getSelection as g,$isRangeSelection as m,$isTextNode as u,$isLeafNode as d,$setSelection as h}from"lexical";var 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 x(e,t,r=Object.freeze({})){const{strlen:o=(e=>e.length),remainingCharacters:l=(()=>{})}=r;n((()=>{e.hasNodes([i])||p(57)}),[e]),n((()=>{let n=e.getEditorState().read(c),r=0;return a(e.registerTextContentListener((e=>{n=e})),e.registerUpdateListener((({dirtyLeaves:i,dirtyElements:c})=>{const a=e.isComposing(),p=i.size>0||c.size>0;if(a||!p)return;const x=o(n),T=x>t||null!==r&&r>t;if(l(t-x),null===r||T){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}(n,t,o);e.update((()=>{!function(e){const t=f(),n=t.length;let r=0;for(let o=0;o<n;o+=1){const{node:n}=t[o];if(s(n)){const t=r;if(r+n.getTextContentSize()<=e){const e=n.getParent(),t=n.getPreviousSibling(),r=n.getNextSibling();v(n);const o=g();!m(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)&&v(n)}}else if(d(n)){const t=r;if(r+=n.getTextContentSize(),r>e&&!s(n.getParent())){const r=g();let o;if(t<e&&u(n)&&n.isSimpleText()){const[,r]=n.splitText(e-t);o=C(r)}else o=C(n);null!==r&&h(r),w(o)}}}}(r)}),{tag:"history-merge"})}r=x})))}),[e,t,l,o])}function C(e){const t=l();return e.insertBefore(t),t.append(e),t}function v(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 w(e){const t=e.getPreviousSibling();if(!s(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 i=g();if(m(i)){const n=i.anchor,r=n.getNode(),s=i.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)?s.set(e.getKey(),s.offset,"element"):l.is(e)&&s.set(e.getKey(),o+s.offset,"element")}t.remove()}let T=null;function S(e){const t=void 0===window.TextEncoder?null:(null===T&&(T=new window.TextEncoder),T);if(null===t){const t=encodeURIComponent(e).match(/%[89ABab]/g);return e.length+(t?t.length:0)}return t.encode(e).length}function y({remainingCharacters:e}){return t.createElement("span",{className:"characters-limit "+(e<0?"characters-limit-exceeded":"")},e)}function b({charset:t="UTF-16",maxLength:n=5,renderer:i=y}){const[s]=e(),[l,c]=r(n);return x(s,n,o((()=>({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{b as CharacterLimitPlugin};
@@ -4,12 +4,12 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- 'use strict';var p=require("@lexical/react/LexicalComposerContext"),u=require("react"),v=require("@lexical/overflow"),z=require("@lexical/text"),A=require("@lexical/utils"),C=require("lexical");
8
- function D(b){let c=new URLSearchParams;c.append("code",b);for(let k=1;k<arguments.length;k++)c.append("v",arguments[k]);throw Error(`Minified Lexical error #${b}; 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.");}
9
- function F(b,c,k=Object.freeze({})){let {strlen:e=m=>m.length,remainingCharacters:q=()=>{}}=k;u.useEffect(()=>{b.hasNodes([v.OverflowNode])||D(57)},[b]);u.useEffect(()=>{let m=b.getEditorState().read(z.$rootTextContent),d=0;return A.mergeRegister(b.registerTextContentListener(f=>{m=f}),b.registerUpdateListener(({dirtyLeaves:f,dirtyElements:J})=>{var w=b.isComposing();f=0<f.size||0<J.size;if(!w&&f){w=e(m);f=w>c||null!==d&&d>c;q(c-w);if(null===d||f){let r=G(m,c,e);b.update(()=>{let B=A.$dfs(),L=B.length,
10
- x=0;for(let y=0;y<L;y+=1){var {node:a}=B[y];if(v.$isOverflowNode(a)){var g=x;if(x+a.getTextContentSize()<=r){var h=a.getParent();g=a.getPreviousSibling();var l=a.getNextSibling();H(a);a=C.$getSelection();!C.$isRangeSelection(a)||a.anchor.getNode().isAttached()&&a.focus.getNode().isAttached()||(C.$isTextNode(g)?g.select():C.$isTextNode(l)?l.select():null!==h&&h.select())}else g<r&&(h=a.getFirstDescendant(),l=null!==h?h.getTextContentSize():0,g+=l,h=C.$isTextNode(h)&&h.isSimpleText(),g=g<=r,(h||g)&&
11
- H(a))}else if(C.$isLeafNode(a)&&(g=x,x+=a.getTextContentSize(),x>r&&!v.$isOverflowNode(a.getParent())&&(h=C.$getSelection(),g<r&&C.$isTextNode(a)&&a.isSimpleText()?([,a]=a.splitText(r-g),a=I(a)):a=I(a),null!==h&&C.$setSelection(h),g=a.getPreviousSibling(),v.$isOverflowNode(g)))){l=a.getFirstChild();var t=g.getChildren();h=t.length;if(null===l)a.append(...t);else for(var n=0;n<h;n++)l.insertBefore(t[n]);n=C.$getSelection();if(C.$isRangeSelection(n)){l=n.anchor;t=l.getNode();n=n.focus;let E=l.getNode();
12
- t.is(g)?l.set(a.getKey(),l.offset,"element"):t.is(a)&&l.set(a.getKey(),h+l.offset,"element");E.is(g)?n.set(a.getKey(),n.offset,"element"):E.is(a)&&n.set(a.getKey(),h+n.offset,"element")}g.remove()}}},{tag:"history-merge"})}d=w}}))},[b,c,q,e])}
13
- function G(b,c,k){var e=Intl.Segmenter;let q=0;var m=0;if("function"===typeof e){b=(new e).segment(b);for(var {segment:d}of b){m+=k(d);if(m>c)break;q+=d.length}}else for(d=Array.from(b),b=d.length,e=0;e<b;e++){let f=d[e];m+=k(f);if(m>c)break;q+=f.length}return q}function I(b){let c=v.$createOverflowNode();b.insertBefore(c);c.append(b);return c}function H(b){let c=b.getChildren(),k=c.length;for(let e=0;e<k;e++)b.insertBefore(c[e]);b.remove();return 0<k?c[k-1]:null}let K=null;
14
- exports.CharacterLimitPlugin=function({charset:b="UTF-16",maxLength:c=5}){let [k]=p.useLexicalComposerContext(),[e,q]=u.useState(c),m=u.useMemo(()=>({remainingCharacters:q,strlen:d=>{if("UTF-8"===b){if(void 0===window.TextEncoder)var f=null;else null===K&&(K=new window.TextEncoder),f=K;null===f?(f=encodeURIComponent(d).match(/%[89ABab]/g),d=d.length+(f?f.length:0)):d=f.encode(d).length;return d}if("UTF-16"===b)return d.length;throw Error("Unrecognized charset");}}),[b]);F(k,c,m);return u.createElement("span",
15
- {className:`characters-limit ${0>e?"characters-limit-exceeded":""}`},e)}
7
+ 'use strict';var p=require("@lexical/react/LexicalComposerContext"),v=require("react"),w=require("@lexical/overflow"),A=require("@lexical/text"),B=require("@lexical/utils"),D=require("lexical");
8
+ function E(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.");}
9
+ function G(a,c,h=Object.freeze({})){let {strlen:f=l=>l.length,remainingCharacters:q=()=>{}}=h;v.useEffect(()=>{a.hasNodes([w.OverflowNode])||E(57)},[a]);v.useEffect(()=>{let l=a.getEditorState().read(A.$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=H(l,c,f);a.update(()=>{let C=B.$dfs(),L=C.length,
10
+ y=0;for(let z=0;z<L;z+=1){var {node:b}=C[z];if(w.$isOverflowNode(b)){var e=y;if(y+b.getTextContentSize()<=t){var g=b.getParent();e=b.getPreviousSibling();var k=b.getNextSibling();I(b);b=D.$getSelection();!D.$isRangeSelection(b)||b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()||(D.$isTextNode(e)?e.select():D.$isTextNode(k)?k.select():null!==g&&g.select())}else e<t&&(g=b.getFirstDescendant(),k=null!==g?g.getTextContentSize():0,e+=k,g=D.$isTextNode(g)&&g.isSimpleText(),e=e<=t,(g||e)&&
11
+ I(b))}else if(D.$isLeafNode(b)&&(e=y,y+=b.getTextContentSize(),y>t&&!w.$isOverflowNode(b.getParent())&&(g=D.$getSelection(),e<t&&D.$isTextNode(b)&&b.isSimpleText()?([,b]=b.splitText(t-e),b=J(b)):b=J(b),null!==g&&D.$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=D.$getSelection();if(D.$isRangeSelection(n)){k=n.anchor;u=k.getNode();n=n.focus;let F=k.getNode();
12
+ u.is(e)?k.set(b.getKey(),k.offset,"element"):u.is(b)&&k.set(b.getKey(),g+k.offset,"element");F.is(e)?n.set(b.getKey(),n.offset,"element"):F.is(b)&&n.set(b.getKey(),g+n.offset,"element")}e.remove()}}},{tag:"history-merge"})}m=x}}))},[a,c,q,f])}
13
+ function H(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 J(a){let c=w.$createOverflowNode();a.insertBefore(c);c.append(a);return c}function I(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 K=null;
14
+ function M({remainingCharacters:a}){return v.createElement("span",{className:`characters-limit ${0>a?"characters-limit-exceeded":""}`},a)}
15
+ exports.CharacterLimitPlugin=function({charset:a="UTF-16",maxLength:c=5,renderer:h=M}){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===K&&(K=new window.TextEncoder),r=K;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]);G(f,c,m);return h({remainingCharacters:q})}