@ekz/lexical-react 0.40.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/@ekz/lexicalExtensionComponent.dev.js +53 -0
- package/@ekz/lexicalExtensionComponent.dev.mjs +51 -0
- package/@ekz/lexicalExtensionComponent.js +11 -0
- package/@ekz/lexicalExtensionComponent.mjs +12 -0
- package/@ekz/lexicalExtensionComponent.node.mjs +10 -0
- package/@ekz/lexicalExtensionComponent.prod.js +9 -0
- package/@ekz/lexicalExtensionComponent.prod.mjs +9 -0
- package/@ekz/lexicalReactExtension.dev.js +187 -0
- package/@ekz/lexicalReactExtension.dev.mjs +184 -0
- package/@ekz/lexicalReactExtension.js +11 -0
- package/@ekz/lexicalReactExtension.mjs +13 -0
- package/@ekz/lexicalReactExtension.node.mjs +11 -0
- package/@ekz/lexicalReactExtension.prod.js +9 -0
- package/@ekz/lexicalReactExtension.prod.mjs +9 -0
- package/@ekz/lexicalReactPluginHostExtension.dev.js +189 -0
- package/@ekz/lexicalReactPluginHostExtension.dev.mjs +181 -0
- package/@ekz/lexicalReactPluginHostExtension.js +11 -0
- package/@ekz/lexicalReactPluginHostExtension.mjs +18 -0
- package/@ekz/lexicalReactPluginHostExtension.node.mjs +16 -0
- package/@ekz/lexicalReactPluginHostExtension.prod.js +9 -0
- package/@ekz/lexicalReactPluginHostExtension.prod.mjs +9 -0
- package/@ekz/lexicalReactProviderExtension.dev.js +33 -0
- package/@ekz/lexicalReactProviderExtension.dev.mjs +31 -0
- package/@ekz/lexicalReactProviderExtension.js +11 -0
- package/@ekz/lexicalReactProviderExtension.mjs +12 -0
- package/@ekz/lexicalReactProviderExtension.node.mjs +10 -0
- package/@ekz/lexicalReactProviderExtension.prod.js +9 -0
- package/@ekz/lexicalReactProviderExtension.prod.mjs +9 -0
- package/@ekz/lexicalTreeViewExtension.dev.js +57 -0
- package/@ekz/lexicalTreeViewExtension.dev.mjs +54 -0
- package/@ekz/lexicalTreeViewExtension.js +11 -0
- package/@ekz/lexicalTreeViewExtension.mjs +13 -0
- package/@ekz/lexicalTreeViewExtension.node.mjs +11 -0
- package/@ekz/lexicalTreeViewExtension.prod.js +9 -0
- package/@ekz/lexicalTreeViewExtension.prod.mjs +9 -0
- package/ExtensionComponent.d.ts +42 -0
- package/LICENSE +21 -0
- package/LexicalAutoEmbedPlugin.d.ts +39 -0
- package/LexicalAutoEmbedPlugin.dev.js +146 -0
- package/LexicalAutoEmbedPlugin.dev.mjs +141 -0
- package/LexicalAutoEmbedPlugin.js +11 -0
- package/LexicalAutoEmbedPlugin.js.flow +64 -0
- package/LexicalAutoEmbedPlugin.mjs +15 -0
- package/LexicalAutoEmbedPlugin.node.mjs +13 -0
- package/LexicalAutoEmbedPlugin.prod.js +9 -0
- package/LexicalAutoEmbedPlugin.prod.mjs +9 -0
- package/LexicalAutoFocusPlugin.d.ts +12 -0
- package/LexicalAutoFocusPlugin.dev.js +47 -0
- package/LexicalAutoFocusPlugin.dev.mjs +45 -0
- package/LexicalAutoFocusPlugin.js +11 -0
- package/LexicalAutoFocusPlugin.js.flow +14 -0
- package/LexicalAutoFocusPlugin.mjs +12 -0
- package/LexicalAutoFocusPlugin.node.mjs +10 -0
- package/LexicalAutoFocusPlugin.prod.js +9 -0
- package/LexicalAutoFocusPlugin.prod.mjs +9 -0
- package/LexicalAutoLinkPlugin.d.ts +14 -0
- package/LexicalAutoLinkPlugin.dev.js +54 -0
- package/LexicalAutoLinkPlugin.dev.mjs +52 -0
- package/LexicalAutoLinkPlugin.js +11 -0
- package/LexicalAutoLinkPlugin.js.flow +18 -0
- package/LexicalAutoLinkPlugin.mjs +13 -0
- package/LexicalAutoLinkPlugin.node.mjs +11 -0
- package/LexicalAutoLinkPlugin.prod.js +9 -0
- package/LexicalAutoLinkPlugin.prod.mjs +9 -0
- package/LexicalBlockWithAlignableContents.d.ts +21 -0
- package/LexicalBlockWithAlignableContents.dev.js +81 -0
- package/LexicalBlockWithAlignableContents.dev.mjs +79 -0
- package/LexicalBlockWithAlignableContents.js +11 -0
- package/LexicalBlockWithAlignableContents.js.flow +28 -0
- package/LexicalBlockWithAlignableContents.mjs +12 -0
- package/LexicalBlockWithAlignableContents.node.mjs +10 -0
- package/LexicalBlockWithAlignableContents.prod.js +9 -0
- package/LexicalBlockWithAlignableContents.prod.mjs +9 -0
- package/LexicalCharacterLimitPlugin.d.ts +15 -0
- package/LexicalCharacterLimitPlugin.dev.js +292 -0
- package/LexicalCharacterLimitPlugin.dev.mjs +290 -0
- package/LexicalCharacterLimitPlugin.js +11 -0
- package/LexicalCharacterLimitPlugin.js.flow +12 -0
- package/LexicalCharacterLimitPlugin.mjs +12 -0
- package/LexicalCharacterLimitPlugin.node.mjs +10 -0
- package/LexicalCharacterLimitPlugin.prod.js +9 -0
- package/LexicalCharacterLimitPlugin.prod.mjs +9 -0
- package/LexicalCheckListPlugin.d.ts +8 -0
- package/LexicalCheckListPlugin.dev.js +31 -0
- package/LexicalCheckListPlugin.dev.mjs +29 -0
- package/LexicalCheckListPlugin.js +11 -0
- package/LexicalCheckListPlugin.js.flow +10 -0
- package/LexicalCheckListPlugin.mjs +12 -0
- package/LexicalCheckListPlugin.node.mjs +10 -0
- package/LexicalCheckListPlugin.prod.js +9 -0
- package/LexicalCheckListPlugin.prod.mjs +9 -0
- package/LexicalClearEditorPlugin.d.ts +13 -0
- package/LexicalClearEditorPlugin.dev.js +55 -0
- package/LexicalClearEditorPlugin.dev.mjs +53 -0
- package/LexicalClearEditorPlugin.js +11 -0
- package/LexicalClearEditorPlugin.js.flow +14 -0
- package/LexicalClearEditorPlugin.mjs +12 -0
- package/LexicalClearEditorPlugin.node.mjs +10 -0
- package/LexicalClearEditorPlugin.prod.js +9 -0
- package/LexicalClearEditorPlugin.prod.mjs +9 -0
- package/LexicalClickableLinkPlugin.d.ts +11 -0
- package/LexicalClickableLinkPlugin.dev.js +38 -0
- package/LexicalClickableLinkPlugin.dev.mjs +36 -0
- package/LexicalClickableLinkPlugin.js +11 -0
- package/LexicalClickableLinkPlugin.js.flow +12 -0
- package/LexicalClickableLinkPlugin.mjs +12 -0
- package/LexicalClickableLinkPlugin.node.mjs +10 -0
- package/LexicalClickableLinkPlugin.prod.js +9 -0
- package/LexicalClickableLinkPlugin.prod.mjs +9 -0
- package/LexicalCollaborationContext.d.ts +19 -0
- package/LexicalCollaborationContext.dev.js +69 -0
- package/LexicalCollaborationContext.dev.mjs +65 -0
- package/LexicalCollaborationContext.js +11 -0
- package/LexicalCollaborationContext.js.flow +22 -0
- package/LexicalCollaborationContext.mjs +14 -0
- package/LexicalCollaborationContext.node.mjs +12 -0
- package/LexicalCollaborationContext.prod.js +9 -0
- package/LexicalCollaborationContext.prod.mjs +9 -0
- package/LexicalCollaborationPlugin.d.ts +39 -0
- package/LexicalCollaborationPlugin.dev.js +584 -0
- package/LexicalCollaborationPlugin.dev.mjs +569 -0
- package/LexicalCollaborationPlugin.js +11 -0
- package/LexicalCollaborationPlugin.js.flow +50 -0
- package/LexicalCollaborationPlugin.mjs +13 -0
- package/LexicalCollaborationPlugin.node.mjs +11 -0
- package/LexicalCollaborationPlugin.prod.js +9 -0
- package/LexicalCollaborationPlugin.prod.mjs +9 -0
- package/LexicalComposer.d.ts +25 -0
- package/LexicalComposer.dev.js +134 -0
- package/LexicalComposer.dev.mjs +132 -0
- package/LexicalComposer.js +11 -0
- package/LexicalComposer.js.flow +40 -0
- package/LexicalComposer.mjs +12 -0
- package/LexicalComposer.node.mjs +10 -0
- package/LexicalComposer.prod.js +9 -0
- package/LexicalComposer.prod.mjs +9 -0
- package/LexicalComposerContext.d.ts +18 -0
- package/LexicalComposerContext.dev.js +55 -0
- package/LexicalComposerContext.dev.mjs +51 -0
- package/LexicalComposerContext.js +11 -0
- package/LexicalComposerContext.js.flow +27 -0
- package/LexicalComposerContext.mjs +14 -0
- package/LexicalComposerContext.node.mjs +12 -0
- package/LexicalComposerContext.prod.js +9 -0
- package/LexicalComposerContext.prod.mjs +9 -0
- package/LexicalContentEditable.d.ts +26 -0
- package/LexicalContentEditable.dev.js +242 -0
- package/LexicalContentEditable.dev.mjs +239 -0
- package/LexicalContentEditable.js +11 -0
- package/LexicalContentEditable.js.flow +80 -0
- package/LexicalContentEditable.mjs +13 -0
- package/LexicalContentEditable.node.mjs +11 -0
- package/LexicalContentEditable.prod.js +9 -0
- package/LexicalContentEditable.prod.mjs +9 -0
- package/LexicalContextMenuPlugin.d.ts +36 -0
- package/LexicalContextMenuPlugin.dev.js +524 -0
- package/LexicalContextMenuPlugin.dev.mjs +509 -0
- package/LexicalContextMenuPlugin.js +11 -0
- package/LexicalContextMenuPlugin.js.flow +13 -0
- package/LexicalContextMenuPlugin.mjs +13 -0
- package/LexicalContextMenuPlugin.node.mjs +11 -0
- package/LexicalContextMenuPlugin.prod.js +9 -0
- package/LexicalContextMenuPlugin.prod.mjs +9 -0
- package/LexicalDecoratorBlockNode.d.ts +25 -0
- package/LexicalDecoratorBlockNode.dev.js +59 -0
- package/LexicalDecoratorBlockNode.dev.mjs +56 -0
- package/LexicalDecoratorBlockNode.js +11 -0
- package/LexicalDecoratorBlockNode.js.flow +35 -0
- package/LexicalDecoratorBlockNode.mjs +13 -0
- package/LexicalDecoratorBlockNode.node.mjs +11 -0
- package/LexicalDecoratorBlockNode.prod.js +9 -0
- package/LexicalDecoratorBlockNode.prod.mjs +9 -0
- package/LexicalDraggableBlockPlugin.d.ts +18 -0
- package/LexicalDraggableBlockPlugin.dev.js +655 -0
- package/LexicalDraggableBlockPlugin.dev.mjs +653 -0
- package/LexicalDraggableBlockPlugin.js +11 -0
- package/LexicalDraggableBlockPlugin.js.flow +24 -0
- package/LexicalDraggableBlockPlugin.mjs +12 -0
- package/LexicalDraggableBlockPlugin.node.mjs +10 -0
- package/LexicalDraggableBlockPlugin.prod.js +9 -0
- package/LexicalDraggableBlockPlugin.prod.mjs +9 -0
- package/LexicalEditorRefPlugin.d.ts +20 -0
- package/LexicalEditorRefPlugin.dev.js +58 -0
- package/LexicalEditorRefPlugin.dev.mjs +43 -0
- package/LexicalEditorRefPlugin.js +11 -0
- package/LexicalEditorRefPlugin.js.flow +19 -0
- package/LexicalEditorRefPlugin.mjs +12 -0
- package/LexicalEditorRefPlugin.node.mjs +10 -0
- package/LexicalEditorRefPlugin.prod.js +9 -0
- package/LexicalEditorRefPlugin.prod.mjs +9 -0
- package/LexicalErrorBoundary.d.ts +13 -0
- package/LexicalErrorBoundary.dev.js +40 -0
- package/LexicalErrorBoundary.dev.mjs +38 -0
- package/LexicalErrorBoundary.js +11 -0
- package/LexicalErrorBoundary.js.flow +17 -0
- package/LexicalErrorBoundary.mjs +12 -0
- package/LexicalErrorBoundary.node.mjs +10 -0
- package/LexicalErrorBoundary.prod.js +9 -0
- package/LexicalErrorBoundary.prod.mjs +9 -0
- package/LexicalExtensionComponent.js.flow +12 -0
- package/LexicalExtensionComposer.d.ts +69 -0
- package/LexicalExtensionComposer.dev.js +105 -0
- package/LexicalExtensionComposer.dev.mjs +103 -0
- package/LexicalExtensionComposer.js +11 -0
- package/LexicalExtensionComposer.js.flow +20 -0
- package/LexicalExtensionComposer.mjs +12 -0
- package/LexicalExtensionComposer.node.mjs +10 -0
- package/LexicalExtensionComposer.prod.js +9 -0
- package/LexicalExtensionComposer.prod.mjs +9 -0
- package/LexicalHashtagPlugin.d.ts +9 -0
- package/LexicalHashtagPlugin.dev.js +34 -0
- package/LexicalHashtagPlugin.dev.mjs +32 -0
- package/LexicalHashtagPlugin.js +11 -0
- package/LexicalHashtagPlugin.js.flow +10 -0
- package/LexicalHashtagPlugin.mjs +12 -0
- package/LexicalHashtagPlugin.node.mjs +10 -0
- package/LexicalHashtagPlugin.prod.js +9 -0
- package/LexicalHashtagPlugin.prod.mjs +9 -0
- package/LexicalHistoryPlugin.d.ts +14 -0
- package/LexicalHistoryPlugin.dev.js +48 -0
- package/LexicalHistoryPlugin.dev.mjs +46 -0
- package/LexicalHistoryPlugin.js +11 -0
- package/LexicalHistoryPlugin.js.flow +28 -0
- package/LexicalHistoryPlugin.mjs +13 -0
- package/LexicalHistoryPlugin.node.mjs +11 -0
- package/LexicalHistoryPlugin.prod.js +9 -0
- package/LexicalHistoryPlugin.prod.mjs +9 -0
- package/LexicalHorizontalRuleNode.d.ts +25 -0
- package/LexicalHorizontalRuleNode.dev.js +102 -0
- package/LexicalHorizontalRuleNode.dev.mjs +98 -0
- package/LexicalHorizontalRuleNode.js +11 -0
- package/LexicalHorizontalRuleNode.js.flow +27 -0
- package/LexicalHorizontalRuleNode.mjs +15 -0
- package/LexicalHorizontalRuleNode.node.mjs +13 -0
- package/LexicalHorizontalRuleNode.prod.js +9 -0
- package/LexicalHorizontalRuleNode.prod.mjs +9 -0
- package/LexicalHorizontalRulePlugin.d.ts +8 -0
- package/LexicalHorizontalRulePlugin.dev.js +44 -0
- package/LexicalHorizontalRulePlugin.dev.mjs +42 -0
- package/LexicalHorizontalRulePlugin.js +11 -0
- package/LexicalHorizontalRulePlugin.js.flow +12 -0
- package/LexicalHorizontalRulePlugin.mjs +12 -0
- package/LexicalHorizontalRulePlugin.node.mjs +10 -0
- package/LexicalHorizontalRulePlugin.prod.js +9 -0
- package/LexicalHorizontalRulePlugin.prod.mjs +9 -0
- package/LexicalLinkPlugin.d.ts +14 -0
- package/LexicalLinkPlugin.dev.js +43 -0
- package/LexicalLinkPlugin.dev.mjs +41 -0
- package/LexicalLinkPlugin.js +11 -0
- package/LexicalLinkPlugin.js.flow +21 -0
- package/LexicalLinkPlugin.mjs +12 -0
- package/LexicalLinkPlugin.node.mjs +10 -0
- package/LexicalLinkPlugin.prod.js +9 -0
- package/LexicalLinkPlugin.prod.mjs +9 -0
- package/LexicalListPlugin.d.ts +20 -0
- package/LexicalListPlugin.dev.js +55 -0
- package/LexicalListPlugin.dev.mjs +53 -0
- package/LexicalListPlugin.js +11 -0
- package/LexicalListPlugin.js.flow +15 -0
- package/LexicalListPlugin.mjs +12 -0
- package/LexicalListPlugin.node.mjs +10 -0
- package/LexicalListPlugin.prod.js +9 -0
- package/LexicalListPlugin.prod.mjs +9 -0
- package/LexicalMarkdownShortcutPlugin.d.ts +12 -0
- package/LexicalMarkdownShortcutPlugin.dev.js +55 -0
- package/LexicalMarkdownShortcutPlugin.dev.mjs +52 -0
- package/LexicalMarkdownShortcutPlugin.js +11 -0
- package/LexicalMarkdownShortcutPlugin.js.flow +16 -0
- package/LexicalMarkdownShortcutPlugin.mjs +13 -0
- package/LexicalMarkdownShortcutPlugin.node.mjs +11 -0
- package/LexicalMarkdownShortcutPlugin.prod.js +9 -0
- package/LexicalMarkdownShortcutPlugin.prod.mjs +9 -0
- package/LexicalNestedComposer.d.ts +57 -0
- package/LexicalNestedComposer.dev.js +161 -0
- package/LexicalNestedComposer.dev.mjs +159 -0
- package/LexicalNestedComposer.js +11 -0
- package/LexicalNestedComposer.js.flow +26 -0
- package/LexicalNestedComposer.mjs +12 -0
- package/LexicalNestedComposer.node.mjs +10 -0
- package/LexicalNestedComposer.prod.js +9 -0
- package/LexicalNestedComposer.prod.mjs +9 -0
- package/LexicalNodeContextMenuPlugin.d.ts +46 -0
- package/LexicalNodeContextMenuPlugin.dev.js +257 -0
- package/LexicalNodeContextMenuPlugin.dev.mjs +253 -0
- package/LexicalNodeContextMenuPlugin.js +11 -0
- package/LexicalNodeContextMenuPlugin.js.flow +12 -0
- package/LexicalNodeContextMenuPlugin.mjs +14 -0
- package/LexicalNodeContextMenuPlugin.node.mjs +12 -0
- package/LexicalNodeContextMenuPlugin.prod.js +9 -0
- package/LexicalNodeContextMenuPlugin.prod.mjs +9 -0
- package/LexicalNodeEventPlugin.d.ts +13 -0
- package/LexicalNodeEventPlugin.dev.js +61 -0
- package/LexicalNodeEventPlugin.dev.mjs +59 -0
- package/LexicalNodeEventPlugin.js +11 -0
- package/LexicalNodeEventPlugin.js.flow +20 -0
- package/LexicalNodeEventPlugin.mjs +12 -0
- package/LexicalNodeEventPlugin.node.mjs +10 -0
- package/LexicalNodeEventPlugin.prod.js +9 -0
- package/LexicalNodeEventPlugin.prod.mjs +9 -0
- package/LexicalNodeMenuPlugin.d.ts +24 -0
- package/LexicalNodeMenuPlugin.dev.js +527 -0
- package/LexicalNodeMenuPlugin.dev.mjs +524 -0
- package/LexicalNodeMenuPlugin.js +11 -0
- package/LexicalNodeMenuPlugin.js.flow +64 -0
- package/LexicalNodeMenuPlugin.mjs +13 -0
- package/LexicalNodeMenuPlugin.node.mjs +11 -0
- package/LexicalNodeMenuPlugin.prod.js +9 -0
- package/LexicalNodeMenuPlugin.prod.mjs +9 -0
- package/LexicalOnChangePlugin.d.ts +13 -0
- package/LexicalOnChangePlugin.dev.js +72 -0
- package/LexicalOnChangePlugin.dev.mjs +70 -0
- package/LexicalOnChangePlugin.js +11 -0
- package/LexicalOnChangePlugin.js.flow +16 -0
- package/LexicalOnChangePlugin.mjs +12 -0
- package/LexicalOnChangePlugin.node.mjs +10 -0
- package/LexicalOnChangePlugin.prod.js +9 -0
- package/LexicalOnChangePlugin.prod.mjs +9 -0
- package/LexicalPlainTextPlugin.d.ts +14 -0
- package/LexicalPlainTextPlugin.dev.js +235 -0
- package/LexicalPlainTextPlugin.dev.mjs +233 -0
- package/LexicalPlainTextPlugin.js +11 -0
- package/LexicalPlainTextPlugin.js.flow +29 -0
- package/LexicalPlainTextPlugin.mjs +12 -0
- package/LexicalPlainTextPlugin.node.mjs +10 -0
- package/LexicalPlainTextPlugin.prod.js +9 -0
- package/LexicalPlainTextPlugin.prod.mjs +9 -0
- package/LexicalReactExtension.js.flow +68 -0
- package/LexicalReactPluginHostExtension.js.flow +84 -0
- package/LexicalReactProviderExtension.js.flow +12 -0
- package/LexicalRichTextPlugin.d.ts +14 -0
- package/LexicalRichTextPlugin.dev.js +235 -0
- package/LexicalRichTextPlugin.dev.mjs +233 -0
- package/LexicalRichTextPlugin.js +11 -0
- package/LexicalRichTextPlugin.js.flow +29 -0
- package/LexicalRichTextPlugin.mjs +12 -0
- package/LexicalRichTextPlugin.node.mjs +10 -0
- package/LexicalRichTextPlugin.prod.js +9 -0
- package/LexicalRichTextPlugin.prod.mjs +9 -0
- package/LexicalSelectionAlwaysOnDisplay.d.ts +12 -0
- package/LexicalSelectionAlwaysOnDisplay.dev.js +33 -0
- package/LexicalSelectionAlwaysOnDisplay.dev.mjs +31 -0
- package/LexicalSelectionAlwaysOnDisplay.js +11 -0
- package/LexicalSelectionAlwaysOnDisplay.js.flow +15 -0
- package/LexicalSelectionAlwaysOnDisplay.mjs +12 -0
- package/LexicalSelectionAlwaysOnDisplay.node.mjs +10 -0
- package/LexicalSelectionAlwaysOnDisplay.prod.js +9 -0
- package/LexicalSelectionAlwaysOnDisplay.prod.mjs +9 -0
- package/LexicalTabIndentationPlugin.d.ts +17 -0
- package/LexicalTabIndentationPlugin.dev.js +40 -0
- package/LexicalTabIndentationPlugin.dev.mjs +38 -0
- package/LexicalTabIndentationPlugin.js +11 -0
- package/LexicalTabIndentationPlugin.js.flow +21 -0
- package/LexicalTabIndentationPlugin.mjs +13 -0
- package/LexicalTabIndentationPlugin.node.mjs +11 -0
- package/LexicalTabIndentationPlugin.prod.js +9 -0
- package/LexicalTabIndentationPlugin.prod.mjs +9 -0
- package/LexicalTableOfContentsPlugin.d.ts +20 -0
- package/LexicalTableOfContentsPlugin.dev.js +209 -0
- package/LexicalTableOfContentsPlugin.dev.mjs +207 -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 +9 -0
- package/LexicalTableOfContentsPlugin.prod.mjs +9 -0
- package/LexicalTablePlugin.d.ts +46 -0
- package/LexicalTablePlugin.dev.js +81 -0
- package/LexicalTablePlugin.dev.mjs +79 -0
- package/LexicalTablePlugin.js +11 -0
- package/LexicalTablePlugin.js.flow +15 -0
- package/LexicalTablePlugin.mjs +12 -0
- package/LexicalTablePlugin.node.mjs +10 -0
- package/LexicalTablePlugin.prod.js +9 -0
- package/LexicalTablePlugin.prod.mjs +9 -0
- package/LexicalTreeView.d.ts +37 -0
- package/LexicalTreeView.dev.js +105 -0
- package/LexicalTreeView.dev.mjs +91 -0
- package/LexicalTreeView.js +11 -0
- package/LexicalTreeView.js.flow +21 -0
- package/LexicalTreeView.mjs +12 -0
- package/LexicalTreeView.node.mjs +10 -0
- package/LexicalTreeView.prod.js +9 -0
- package/LexicalTreeView.prod.mjs +9 -0
- package/LexicalTreeViewExtension.js.flow +12 -0
- package/LexicalTypeaheadMenuPlugin.d.ts +40 -0
- package/LexicalTypeaheadMenuPlugin.dev.js +654 -0
- package/LexicalTypeaheadMenuPlugin.dev.mjs +646 -0
- package/LexicalTypeaheadMenuPlugin.js +11 -0
- package/LexicalTypeaheadMenuPlugin.js.flow +83 -0
- package/LexicalTypeaheadMenuPlugin.mjs +18 -0
- package/LexicalTypeaheadMenuPlugin.node.mjs +16 -0
- package/LexicalTypeaheadMenuPlugin.prod.js +9 -0
- package/LexicalTypeaheadMenuPlugin.prod.mjs +9 -0
- package/README.md +90 -0
- package/ReactExtension.d.ts +41 -0
- package/ReactPluginHostExtension.d.ts +56 -0
- package/ReactProviderExtension.d.ts +9 -0
- package/TreeViewExtension.d.ts +18 -0
- package/package.json +1549 -0
- package/shared/LegacyDecorators.d.ts +23 -0
- package/shared/LexicalContentEditableElement.d.ts +43 -0
- package/shared/LexicalMenu.d.ts +52 -0
- package/shared/buildEditorComponent.d.ts +11 -0
- package/shared/mergeRefs.d.ts +9 -0
- package/shared/point.d.ts +21 -0
- package/shared/rect.d.ts +45 -0
- package/shared/types.d.ts +89 -0
- package/shared/useCanShowPlaceholder.d.ts +9 -0
- package/shared/useCharacterLimit.d.ts +16 -0
- package/shared/useDecorators.d.ts +17 -0
- package/shared/useHistory.d.ts +10 -0
- package/shared/useList.d.ts +9 -0
- package/shared/usePlainTextSetup.d.ts +9 -0
- package/shared/useReactDecorators.d.ts +12 -0
- package/shared/useRichTextSetup.d.ts +9 -0
- package/shared/useYjsCollaboration.d.ts +25 -0
- package/useExtensionComponent.d.ts +10 -0
- package/useLexicalEditable.d.ts +16 -0
- package/useLexicalEditable.dev.js +102 -0
- package/useLexicalEditable.dev.mjs +100 -0
- package/useLexicalEditable.js +11 -0
- package/useLexicalEditable.js.flow +12 -0
- package/useLexicalEditable.mjs +12 -0
- package/useLexicalEditable.node.mjs +10 -0
- package/useLexicalEditable.prod.js +9 -0
- package/useLexicalEditable.prod.mjs +9 -0
- package/useLexicalExtensionComponent.dev.js +37 -0
- package/useLexicalExtensionComponent.dev.mjs +34 -0
- package/useLexicalExtensionComponent.js +11 -0
- package/useLexicalExtensionComponent.js.flow +12 -0
- package/useLexicalExtensionComponent.mjs +13 -0
- package/useLexicalExtensionComponent.node.mjs +11 -0
- package/useLexicalExtensionComponent.prod.js +9 -0
- package/useLexicalExtensionComponent.prod.mjs +9 -0
- package/useLexicalIsTextContentEmpty.d.ts +9 -0
- package/useLexicalIsTextContentEmpty.dev.js +60 -0
- package/useLexicalIsTextContentEmpty.dev.mjs +58 -0
- package/useLexicalIsTextContentEmpty.js +11 -0
- package/useLexicalIsTextContentEmpty.js.flow +15 -0
- package/useLexicalIsTextContentEmpty.mjs +12 -0
- package/useLexicalIsTextContentEmpty.node.mjs +10 -0
- package/useLexicalIsTextContentEmpty.prod.js +9 -0
- package/useLexicalIsTextContentEmpty.prod.mjs +9 -0
- package/useLexicalNodeSelection.d.ts +24 -0
- package/useLexicalNodeSelection.dev.js +102 -0
- package/useLexicalNodeSelection.dev.mjs +100 -0
- package/useLexicalNodeSelection.js +11 -0
- package/useLexicalNodeSelection.js.flow +14 -0
- package/useLexicalNodeSelection.mjs +12 -0
- package/useLexicalNodeSelection.node.mjs +10 -0
- package/useLexicalNodeSelection.prod.js +9 -0
- package/useLexicalNodeSelection.prod.mjs +9 -0
- package/useLexicalSubscription.d.ts +17 -0
- package/useLexicalSubscription.dev.js +73 -0
- package/useLexicalSubscription.dev.mjs +71 -0
- package/useLexicalSubscription.js +11 -0
- package/useLexicalSubscription.js.flow +19 -0
- package/useLexicalSubscription.mjs +12 -0
- package/useLexicalSubscription.node.mjs +10 -0
- package/useLexicalSubscription.prod.js +9 -0
- package/useLexicalSubscription.prod.mjs +9 -0
- package/useLexicalTextEntity.d.ts +10 -0
- package/useLexicalTextEntity.dev.js +31 -0
- package/useLexicalTextEntity.dev.mjs +29 -0
- package/useLexicalTextEntity.js +11 -0
- package/useLexicalTextEntity.js.flow +18 -0
- package/useLexicalTextEntity.mjs +12 -0
- package/useLexicalTextEntity.node.mjs +10 -0
- package/useLexicalTextEntity.prod.js +9 -0
- package/useLexicalTextEntity.prod.mjs +9 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
var LexicalComposerContext = require('@ekz/lexical-react/LexicalComposerContext');
|
|
12
|
+
var react = require('react');
|
|
13
|
+
var lexicalOverflow = require('@ekz/lexical-overflow');
|
|
14
|
+
var lexicalText = require('@ekz/lexical-text');
|
|
15
|
+
var lexicalUtils = require('@ekz/lexical-utils');
|
|
16
|
+
var lexical = require('@ekz/lexical');
|
|
17
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
21
|
+
*
|
|
22
|
+
* This source code is licensed under the MIT license found in the
|
|
23
|
+
* LICENSE file in the root directory of this source tree.
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
// Do not require this module directly! Use normal `invariant` calls.
|
|
28
|
+
|
|
29
|
+
function formatDevErrorMessage(message) {
|
|
30
|
+
throw new Error(message);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({})) {
|
|
34
|
+
const {
|
|
35
|
+
strlen = input => input.length,
|
|
36
|
+
// UTF-16
|
|
37
|
+
remainingCharacters = () => {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
} = optional;
|
|
41
|
+
react.useEffect(() => {
|
|
42
|
+
if (!editor.hasNodes([lexicalOverflow.OverflowNode])) {
|
|
43
|
+
{
|
|
44
|
+
formatDevErrorMessage(`useCharacterLimit: OverflowNode not registered on editor`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}, [editor]);
|
|
48
|
+
react.useEffect(() => {
|
|
49
|
+
let text = editor.getEditorState().read(lexicalText.$rootTextContent);
|
|
50
|
+
let lastComputedTextLength = 0;
|
|
51
|
+
return lexicalUtils.mergeRegister(editor.registerTextContentListener(currentText => {
|
|
52
|
+
text = currentText;
|
|
53
|
+
}), editor.registerUpdateListener(({
|
|
54
|
+
dirtyLeaves,
|
|
55
|
+
dirtyElements
|
|
56
|
+
}) => {
|
|
57
|
+
const isComposing = editor.isComposing();
|
|
58
|
+
const hasContentChanges = dirtyLeaves.size > 0 || dirtyElements.size > 0;
|
|
59
|
+
if (isComposing || !hasContentChanges) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const textLength = strlen(text);
|
|
63
|
+
const textLengthAboveThreshold = textLength > maxCharacters || lastComputedTextLength !== null && lastComputedTextLength > maxCharacters;
|
|
64
|
+
const diff = maxCharacters - textLength;
|
|
65
|
+
remainingCharacters(diff);
|
|
66
|
+
if (lastComputedTextLength === null || textLengthAboveThreshold) {
|
|
67
|
+
const offset = findOffset(text, maxCharacters, strlen);
|
|
68
|
+
editor.update(() => {
|
|
69
|
+
$wrapOverflowedNodes(offset);
|
|
70
|
+
}, {
|
|
71
|
+
tag: lexical.HISTORY_MERGE_TAG
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
lastComputedTextLength = textLength;
|
|
75
|
+
}), editor.registerCommand(lexical.DELETE_CHARACTER_COMMAND, isBackward => {
|
|
76
|
+
const selection = lexical.$getSelection();
|
|
77
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
const anchorNode = selection.anchor.getNode();
|
|
81
|
+
const overflow = anchorNode.getParent();
|
|
82
|
+
const overflowParent = overflow ? overflow.getParent() : null;
|
|
83
|
+
const parentNext = overflowParent ? overflowParent.getNextSibling() : null;
|
|
84
|
+
selection.deleteCharacter(isBackward);
|
|
85
|
+
if (overflowParent && overflowParent.isEmpty()) {
|
|
86
|
+
overflowParent.remove();
|
|
87
|
+
} else if (lexical.$isElementNode(parentNext) && parentNext.isEmpty()) {
|
|
88
|
+
parentNext.remove();
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}, lexical.COMMAND_PRIORITY_LOW));
|
|
92
|
+
}, [editor, maxCharacters, remainingCharacters, strlen]);
|
|
93
|
+
}
|
|
94
|
+
function findOffset(text, maxCharacters, strlen) {
|
|
95
|
+
const Segmenter = Intl.Segmenter;
|
|
96
|
+
let offsetUtf16 = 0;
|
|
97
|
+
let offset = 0;
|
|
98
|
+
if (typeof Segmenter === 'function') {
|
|
99
|
+
const segmenter = new Segmenter();
|
|
100
|
+
const graphemes = segmenter.segment(text);
|
|
101
|
+
for (const {
|
|
102
|
+
segment: grapheme
|
|
103
|
+
} of graphemes) {
|
|
104
|
+
const nextOffset = offset + strlen(grapheme);
|
|
105
|
+
if (nextOffset > maxCharacters) {
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
offset = nextOffset;
|
|
109
|
+
offsetUtf16 += grapheme.length;
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
const codepoints = Array.from(text);
|
|
113
|
+
const codepointsLength = codepoints.length;
|
|
114
|
+
for (let i = 0; i < codepointsLength; i++) {
|
|
115
|
+
const codepoint = codepoints[i];
|
|
116
|
+
const nextOffset = offset + strlen(codepoint);
|
|
117
|
+
if (nextOffset > maxCharacters) {
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
offset = nextOffset;
|
|
121
|
+
offsetUtf16 += codepoint.length;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return offsetUtf16;
|
|
125
|
+
}
|
|
126
|
+
function $wrapOverflowedNodes(offset) {
|
|
127
|
+
const dfsNodes = lexicalUtils.$dfs();
|
|
128
|
+
const dfsNodesLength = dfsNodes.length;
|
|
129
|
+
let accumulatedLength = 0;
|
|
130
|
+
for (let i = 0; i < dfsNodesLength; i += 1) {
|
|
131
|
+
const {
|
|
132
|
+
node
|
|
133
|
+
} = dfsNodes[i];
|
|
134
|
+
const needsOverflowParent = lexical.$isLeafNode(node) && !lexicalUtils.$findMatchingParent(node, lexicalOverflow.$isOverflowNode);
|
|
135
|
+
if (lexicalOverflow.$isOverflowNode(node)) {
|
|
136
|
+
const previousLength = accumulatedLength;
|
|
137
|
+
const nextLength = accumulatedLength + node.getTextContentSize();
|
|
138
|
+
if (nextLength <= offset) {
|
|
139
|
+
const parent = node.getParent();
|
|
140
|
+
const previousSibling = node.getPreviousSibling();
|
|
141
|
+
const nextSibling = node.getNextSibling();
|
|
142
|
+
lexicalUtils.$unwrapNode(node);
|
|
143
|
+
const selection = lexical.$getSelection();
|
|
144
|
+
|
|
145
|
+
// Restore selection when the overflow children are removed
|
|
146
|
+
if (lexical.$isRangeSelection(selection) && (!selection.anchor.getNode().isAttached() || !selection.focus.getNode().isAttached())) {
|
|
147
|
+
if (lexical.$isTextNode(previousSibling)) {
|
|
148
|
+
previousSibling.select();
|
|
149
|
+
} else if (lexical.$isTextNode(nextSibling)) {
|
|
150
|
+
nextSibling.select();
|
|
151
|
+
} else if (parent !== null) {
|
|
152
|
+
parent.select();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} else if (previousLength < offset) {
|
|
156
|
+
const descendant = node.getFirstDescendant();
|
|
157
|
+
const descendantLength = descendant !== null ? descendant.getTextContentSize() : 0;
|
|
158
|
+
const previousPlusDescendantLength = previousLength + descendantLength;
|
|
159
|
+
// For simple text we can redimension the overflow into a smaller and more accurate
|
|
160
|
+
// container
|
|
161
|
+
const firstDescendantIsSimpleText = lexical.$isTextNode(descendant) && descendant.isSimpleText();
|
|
162
|
+
const firstDescendantDoesNotOverflow = previousPlusDescendantLength <= offset;
|
|
163
|
+
if (firstDescendantIsSimpleText || firstDescendantDoesNotOverflow) {
|
|
164
|
+
lexicalUtils.$unwrapNode(node);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
} else if (needsOverflowParent) {
|
|
168
|
+
const previousAccumulatedLength = accumulatedLength;
|
|
169
|
+
accumulatedLength += node.getTextContentSize();
|
|
170
|
+
if (accumulatedLength > offset && !lexicalOverflow.$isOverflowNode(node.getParent())) {
|
|
171
|
+
const previousSelection = lexical.$getSelection();
|
|
172
|
+
let overflowNode;
|
|
173
|
+
|
|
174
|
+
// For simple text we can improve the limit accuracy by splitting the TextNode
|
|
175
|
+
// on the split point
|
|
176
|
+
if (previousAccumulatedLength < offset && lexical.$isTextNode(node) && node.isSimpleText()) {
|
|
177
|
+
const [, overflowedText] = node.splitText(offset - previousAccumulatedLength);
|
|
178
|
+
overflowNode = $wrapNode(overflowedText);
|
|
179
|
+
} else {
|
|
180
|
+
overflowNode = $wrapNode(node);
|
|
181
|
+
}
|
|
182
|
+
if (previousSelection !== null) {
|
|
183
|
+
lexical.$setSelection(previousSelection);
|
|
184
|
+
}
|
|
185
|
+
$mergePrevious(overflowNode);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function $wrapNode(node) {
|
|
191
|
+
const overflowNode = lexicalOverflow.$createOverflowNode();
|
|
192
|
+
node.replace(overflowNode);
|
|
193
|
+
overflowNode.append(node);
|
|
194
|
+
return overflowNode;
|
|
195
|
+
}
|
|
196
|
+
function $mergePrevious(overflowNode) {
|
|
197
|
+
const previousNode = overflowNode.getPreviousSibling();
|
|
198
|
+
if (!lexicalOverflow.$isOverflowNode(previousNode)) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const firstChild = overflowNode.getFirstChild();
|
|
202
|
+
const previousNodeChildren = previousNode.getChildren();
|
|
203
|
+
const previousNodeChildrenLength = previousNodeChildren.length;
|
|
204
|
+
if (firstChild === null) {
|
|
205
|
+
overflowNode.append(...previousNodeChildren);
|
|
206
|
+
} else {
|
|
207
|
+
for (let i = 0; i < previousNodeChildrenLength; i++) {
|
|
208
|
+
firstChild.insertBefore(previousNodeChildren[i]);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const selection = lexical.$getSelection();
|
|
212
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
213
|
+
const anchor = selection.anchor;
|
|
214
|
+
const anchorNode = anchor.getNode();
|
|
215
|
+
const focus = selection.focus;
|
|
216
|
+
const focusNode = anchor.getNode();
|
|
217
|
+
if (anchorNode.is(previousNode)) {
|
|
218
|
+
anchor.set(overflowNode.getKey(), anchor.offset, 'element');
|
|
219
|
+
} else if (anchorNode.is(overflowNode)) {
|
|
220
|
+
anchor.set(overflowNode.getKey(), previousNodeChildrenLength + anchor.offset, 'element');
|
|
221
|
+
}
|
|
222
|
+
if (focusNode.is(previousNode)) {
|
|
223
|
+
focus.set(overflowNode.getKey(), focus.offset, 'element');
|
|
224
|
+
} else if (focusNode.is(overflowNode)) {
|
|
225
|
+
focus.set(overflowNode.getKey(), previousNodeChildrenLength + focus.offset, 'element');
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
previousNode.remove();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
233
|
+
*
|
|
234
|
+
* This source code is licensed under the MIT license found in the
|
|
235
|
+
* LICENSE file in the root directory of this source tree.
|
|
236
|
+
*
|
|
237
|
+
*/
|
|
238
|
+
|
|
239
|
+
const CHARACTER_LIMIT = 5;
|
|
240
|
+
let textEncoderInstance = null;
|
|
241
|
+
function textEncoder() {
|
|
242
|
+
if (window.TextEncoder === undefined) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
if (textEncoderInstance === null) {
|
|
246
|
+
textEncoderInstance = new window.TextEncoder();
|
|
247
|
+
}
|
|
248
|
+
return textEncoderInstance;
|
|
249
|
+
}
|
|
250
|
+
function utf8Length(text) {
|
|
251
|
+
const currentTextEncoder = textEncoder();
|
|
252
|
+
if (currentTextEncoder === null) {
|
|
253
|
+
// http://stackoverflow.com/a/5515960/210370
|
|
254
|
+
const m = encodeURIComponent(text).match(/%[89ABab]/g);
|
|
255
|
+
return text.length + (m ? m.length : 0);
|
|
256
|
+
}
|
|
257
|
+
return currentTextEncoder.encode(text).length;
|
|
258
|
+
}
|
|
259
|
+
function DefaultRenderer({
|
|
260
|
+
remainingCharacters
|
|
261
|
+
}) {
|
|
262
|
+
return /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
263
|
+
className: `characters-limit ${remainingCharacters < 0 ? 'characters-limit-exceeded' : ''}`,
|
|
264
|
+
children: remainingCharacters
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function CharacterLimitPlugin({
|
|
268
|
+
charset = 'UTF-16',
|
|
269
|
+
maxLength = CHARACTER_LIMIT,
|
|
270
|
+
renderer = DefaultRenderer
|
|
271
|
+
}) {
|
|
272
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
273
|
+
const [remainingCharacters, setRemainingCharacters] = react.useState(maxLength);
|
|
274
|
+
const characterLimitProps = react.useMemo(() => ({
|
|
275
|
+
remainingCharacters: setRemainingCharacters,
|
|
276
|
+
strlen: text => {
|
|
277
|
+
if (charset === 'UTF-8') {
|
|
278
|
+
return utf8Length(text);
|
|
279
|
+
} else if (charset === 'UTF-16') {
|
|
280
|
+
return text.length;
|
|
281
|
+
} else {
|
|
282
|
+
throw new Error('Unrecognized charset');
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}), [charset]);
|
|
286
|
+
useCharacterLimit(editor, maxLength, characterLimitProps);
|
|
287
|
+
return renderer({
|
|
288
|
+
remainingCharacters
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
exports.CharacterLimitPlugin = CharacterLimitPlugin;
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { useLexicalComposerContext } from '@ekz/lexical-react/LexicalComposerContext';
|
|
10
|
+
import { useEffect, useState, useMemo } from 'react';
|
|
11
|
+
import { OverflowNode, $isOverflowNode, $createOverflowNode } from '@ekz/lexical-overflow';
|
|
12
|
+
import { $rootTextContent } from '@ekz/lexical-text';
|
|
13
|
+
import { mergeRegister, $dfs, $findMatchingParent, $unwrapNode } from '@ekz/lexical-utils';
|
|
14
|
+
import { HISTORY_MERGE_TAG, DELETE_CHARACTER_COMMAND, $getSelection, $isRangeSelection, $isElementNode, COMMAND_PRIORITY_LOW, $isLeafNode, $isTextNode, $setSelection } from '@ekz/lexical';
|
|
15
|
+
import { jsx } from 'react/jsx-runtime';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
19
|
+
*
|
|
20
|
+
* This source code is licensed under the MIT license found in the
|
|
21
|
+
* LICENSE file in the root directory of this source tree.
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// Do not require this module directly! Use normal `invariant` calls.
|
|
26
|
+
|
|
27
|
+
function formatDevErrorMessage(message) {
|
|
28
|
+
throw new Error(message);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({})) {
|
|
32
|
+
const {
|
|
33
|
+
strlen = input => input.length,
|
|
34
|
+
// UTF-16
|
|
35
|
+
remainingCharacters = () => {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
} = optional;
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!editor.hasNodes([OverflowNode])) {
|
|
41
|
+
{
|
|
42
|
+
formatDevErrorMessage(`useCharacterLimit: OverflowNode not registered on editor`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}, [editor]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
let text = editor.getEditorState().read($rootTextContent);
|
|
48
|
+
let lastComputedTextLength = 0;
|
|
49
|
+
return mergeRegister(editor.registerTextContentListener(currentText => {
|
|
50
|
+
text = currentText;
|
|
51
|
+
}), editor.registerUpdateListener(({
|
|
52
|
+
dirtyLeaves,
|
|
53
|
+
dirtyElements
|
|
54
|
+
}) => {
|
|
55
|
+
const isComposing = editor.isComposing();
|
|
56
|
+
const hasContentChanges = dirtyLeaves.size > 0 || dirtyElements.size > 0;
|
|
57
|
+
if (isComposing || !hasContentChanges) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const textLength = strlen(text);
|
|
61
|
+
const textLengthAboveThreshold = textLength > maxCharacters || lastComputedTextLength !== null && lastComputedTextLength > maxCharacters;
|
|
62
|
+
const diff = maxCharacters - textLength;
|
|
63
|
+
remainingCharacters(diff);
|
|
64
|
+
if (lastComputedTextLength === null || textLengthAboveThreshold) {
|
|
65
|
+
const offset = findOffset(text, maxCharacters, strlen);
|
|
66
|
+
editor.update(() => {
|
|
67
|
+
$wrapOverflowedNodes(offset);
|
|
68
|
+
}, {
|
|
69
|
+
tag: HISTORY_MERGE_TAG
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
lastComputedTextLength = textLength;
|
|
73
|
+
}), editor.registerCommand(DELETE_CHARACTER_COMMAND, isBackward => {
|
|
74
|
+
const selection = $getSelection();
|
|
75
|
+
if (!$isRangeSelection(selection)) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const anchorNode = selection.anchor.getNode();
|
|
79
|
+
const overflow = anchorNode.getParent();
|
|
80
|
+
const overflowParent = overflow ? overflow.getParent() : null;
|
|
81
|
+
const parentNext = overflowParent ? overflowParent.getNextSibling() : null;
|
|
82
|
+
selection.deleteCharacter(isBackward);
|
|
83
|
+
if (overflowParent && overflowParent.isEmpty()) {
|
|
84
|
+
overflowParent.remove();
|
|
85
|
+
} else if ($isElementNode(parentNext) && parentNext.isEmpty()) {
|
|
86
|
+
parentNext.remove();
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}, COMMAND_PRIORITY_LOW));
|
|
90
|
+
}, [editor, maxCharacters, remainingCharacters, strlen]);
|
|
91
|
+
}
|
|
92
|
+
function findOffset(text, maxCharacters, strlen) {
|
|
93
|
+
const Segmenter = Intl.Segmenter;
|
|
94
|
+
let offsetUtf16 = 0;
|
|
95
|
+
let offset = 0;
|
|
96
|
+
if (typeof Segmenter === 'function') {
|
|
97
|
+
const segmenter = new Segmenter();
|
|
98
|
+
const graphemes = segmenter.segment(text);
|
|
99
|
+
for (const {
|
|
100
|
+
segment: grapheme
|
|
101
|
+
} of graphemes) {
|
|
102
|
+
const nextOffset = offset + strlen(grapheme);
|
|
103
|
+
if (nextOffset > maxCharacters) {
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
offset = nextOffset;
|
|
107
|
+
offsetUtf16 += grapheme.length;
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
const codepoints = Array.from(text);
|
|
111
|
+
const codepointsLength = codepoints.length;
|
|
112
|
+
for (let i = 0; i < codepointsLength; i++) {
|
|
113
|
+
const codepoint = codepoints[i];
|
|
114
|
+
const nextOffset = offset + strlen(codepoint);
|
|
115
|
+
if (nextOffset > maxCharacters) {
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
offset = nextOffset;
|
|
119
|
+
offsetUtf16 += codepoint.length;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return offsetUtf16;
|
|
123
|
+
}
|
|
124
|
+
function $wrapOverflowedNodes(offset) {
|
|
125
|
+
const dfsNodes = $dfs();
|
|
126
|
+
const dfsNodesLength = dfsNodes.length;
|
|
127
|
+
let accumulatedLength = 0;
|
|
128
|
+
for (let i = 0; i < dfsNodesLength; i += 1) {
|
|
129
|
+
const {
|
|
130
|
+
node
|
|
131
|
+
} = dfsNodes[i];
|
|
132
|
+
const needsOverflowParent = $isLeafNode(node) && !$findMatchingParent(node, $isOverflowNode);
|
|
133
|
+
if ($isOverflowNode(node)) {
|
|
134
|
+
const previousLength = accumulatedLength;
|
|
135
|
+
const nextLength = accumulatedLength + node.getTextContentSize();
|
|
136
|
+
if (nextLength <= offset) {
|
|
137
|
+
const parent = node.getParent();
|
|
138
|
+
const previousSibling = node.getPreviousSibling();
|
|
139
|
+
const nextSibling = node.getNextSibling();
|
|
140
|
+
$unwrapNode(node);
|
|
141
|
+
const selection = $getSelection();
|
|
142
|
+
|
|
143
|
+
// Restore selection when the overflow children are removed
|
|
144
|
+
if ($isRangeSelection(selection) && (!selection.anchor.getNode().isAttached() || !selection.focus.getNode().isAttached())) {
|
|
145
|
+
if ($isTextNode(previousSibling)) {
|
|
146
|
+
previousSibling.select();
|
|
147
|
+
} else if ($isTextNode(nextSibling)) {
|
|
148
|
+
nextSibling.select();
|
|
149
|
+
} else if (parent !== null) {
|
|
150
|
+
parent.select();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
} else if (previousLength < offset) {
|
|
154
|
+
const descendant = node.getFirstDescendant();
|
|
155
|
+
const descendantLength = descendant !== null ? descendant.getTextContentSize() : 0;
|
|
156
|
+
const previousPlusDescendantLength = previousLength + descendantLength;
|
|
157
|
+
// For simple text we can redimension the overflow into a smaller and more accurate
|
|
158
|
+
// container
|
|
159
|
+
const firstDescendantIsSimpleText = $isTextNode(descendant) && descendant.isSimpleText();
|
|
160
|
+
const firstDescendantDoesNotOverflow = previousPlusDescendantLength <= offset;
|
|
161
|
+
if (firstDescendantIsSimpleText || firstDescendantDoesNotOverflow) {
|
|
162
|
+
$unwrapNode(node);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
} else if (needsOverflowParent) {
|
|
166
|
+
const previousAccumulatedLength = accumulatedLength;
|
|
167
|
+
accumulatedLength += node.getTextContentSize();
|
|
168
|
+
if (accumulatedLength > offset && !$isOverflowNode(node.getParent())) {
|
|
169
|
+
const previousSelection = $getSelection();
|
|
170
|
+
let overflowNode;
|
|
171
|
+
|
|
172
|
+
// For simple text we can improve the limit accuracy by splitting the TextNode
|
|
173
|
+
// on the split point
|
|
174
|
+
if (previousAccumulatedLength < offset && $isTextNode(node) && node.isSimpleText()) {
|
|
175
|
+
const [, overflowedText] = node.splitText(offset - previousAccumulatedLength);
|
|
176
|
+
overflowNode = $wrapNode(overflowedText);
|
|
177
|
+
} else {
|
|
178
|
+
overflowNode = $wrapNode(node);
|
|
179
|
+
}
|
|
180
|
+
if (previousSelection !== null) {
|
|
181
|
+
$setSelection(previousSelection);
|
|
182
|
+
}
|
|
183
|
+
$mergePrevious(overflowNode);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function $wrapNode(node) {
|
|
189
|
+
const overflowNode = $createOverflowNode();
|
|
190
|
+
node.replace(overflowNode);
|
|
191
|
+
overflowNode.append(node);
|
|
192
|
+
return overflowNode;
|
|
193
|
+
}
|
|
194
|
+
function $mergePrevious(overflowNode) {
|
|
195
|
+
const previousNode = overflowNode.getPreviousSibling();
|
|
196
|
+
if (!$isOverflowNode(previousNode)) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const firstChild = overflowNode.getFirstChild();
|
|
200
|
+
const previousNodeChildren = previousNode.getChildren();
|
|
201
|
+
const previousNodeChildrenLength = previousNodeChildren.length;
|
|
202
|
+
if (firstChild === null) {
|
|
203
|
+
overflowNode.append(...previousNodeChildren);
|
|
204
|
+
} else {
|
|
205
|
+
for (let i = 0; i < previousNodeChildrenLength; i++) {
|
|
206
|
+
firstChild.insertBefore(previousNodeChildren[i]);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const selection = $getSelection();
|
|
210
|
+
if ($isRangeSelection(selection)) {
|
|
211
|
+
const anchor = selection.anchor;
|
|
212
|
+
const anchorNode = anchor.getNode();
|
|
213
|
+
const focus = selection.focus;
|
|
214
|
+
const focusNode = anchor.getNode();
|
|
215
|
+
if (anchorNode.is(previousNode)) {
|
|
216
|
+
anchor.set(overflowNode.getKey(), anchor.offset, 'element');
|
|
217
|
+
} else if (anchorNode.is(overflowNode)) {
|
|
218
|
+
anchor.set(overflowNode.getKey(), previousNodeChildrenLength + anchor.offset, 'element');
|
|
219
|
+
}
|
|
220
|
+
if (focusNode.is(previousNode)) {
|
|
221
|
+
focus.set(overflowNode.getKey(), focus.offset, 'element');
|
|
222
|
+
} else if (focusNode.is(overflowNode)) {
|
|
223
|
+
focus.set(overflowNode.getKey(), previousNodeChildrenLength + focus.offset, 'element');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
previousNode.remove();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
231
|
+
*
|
|
232
|
+
* This source code is licensed under the MIT license found in the
|
|
233
|
+
* LICENSE file in the root directory of this source tree.
|
|
234
|
+
*
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
const CHARACTER_LIMIT = 5;
|
|
238
|
+
let textEncoderInstance = null;
|
|
239
|
+
function textEncoder() {
|
|
240
|
+
if (window.TextEncoder === undefined) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
if (textEncoderInstance === null) {
|
|
244
|
+
textEncoderInstance = new window.TextEncoder();
|
|
245
|
+
}
|
|
246
|
+
return textEncoderInstance;
|
|
247
|
+
}
|
|
248
|
+
function utf8Length(text) {
|
|
249
|
+
const currentTextEncoder = textEncoder();
|
|
250
|
+
if (currentTextEncoder === null) {
|
|
251
|
+
// http://stackoverflow.com/a/5515960/210370
|
|
252
|
+
const m = encodeURIComponent(text).match(/%[89ABab]/g);
|
|
253
|
+
return text.length + (m ? m.length : 0);
|
|
254
|
+
}
|
|
255
|
+
return currentTextEncoder.encode(text).length;
|
|
256
|
+
}
|
|
257
|
+
function DefaultRenderer({
|
|
258
|
+
remainingCharacters
|
|
259
|
+
}) {
|
|
260
|
+
return /*#__PURE__*/jsx("span", {
|
|
261
|
+
className: `characters-limit ${remainingCharacters < 0 ? 'characters-limit-exceeded' : ''}`,
|
|
262
|
+
children: remainingCharacters
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
function CharacterLimitPlugin({
|
|
266
|
+
charset = 'UTF-16',
|
|
267
|
+
maxLength = CHARACTER_LIMIT,
|
|
268
|
+
renderer = DefaultRenderer
|
|
269
|
+
}) {
|
|
270
|
+
const [editor] = useLexicalComposerContext();
|
|
271
|
+
const [remainingCharacters, setRemainingCharacters] = useState(maxLength);
|
|
272
|
+
const characterLimitProps = useMemo(() => ({
|
|
273
|
+
remainingCharacters: setRemainingCharacters,
|
|
274
|
+
strlen: text => {
|
|
275
|
+
if (charset === 'UTF-8') {
|
|
276
|
+
return utf8Length(text);
|
|
277
|
+
} else if (charset === 'UTF-16') {
|
|
278
|
+
return text.length;
|
|
279
|
+
} else {
|
|
280
|
+
throw new Error('Unrecognized charset');
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}), [charset]);
|
|
284
|
+
useCharacterLimit(editor, maxLength, characterLimitProps);
|
|
285
|
+
return renderer({
|
|
286
|
+
remainingCharacters
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export { CharacterLimitPlugin };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict'
|
|
10
|
+
const LexicalCharacterLimitPlugin = process.env.NODE_ENV !== 'production' ? require('./LexicalCharacterLimitPlugin.dev.js') : require('./LexicalCharacterLimitPlugin.prod.js');
|
|
11
|
+
module.exports = LexicalCharacterLimitPlugin;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare export function CharacterLimitPlugin(props: {
|
|
11
|
+
charset: 'UTF-8' | 'UTF-16',
|
|
12
|
+
}): React.Node;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as modDev from './LexicalCharacterLimitPlugin.dev.mjs';
|
|
10
|
+
import * as modProd from './LexicalCharacterLimitPlugin.prod.mjs';
|
|
11
|
+
const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
|
|
12
|
+
export const CharacterLimitPlugin = mod.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
|
+
*/
|
|
8
|
+
|
|
9
|
+
const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalCharacterLimitPlugin.dev.mjs') : import('./LexicalCharacterLimitPlugin.prod.mjs'));
|
|
10
|
+
export const CharacterLimitPlugin = mod.CharacterLimitPlugin;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
"use strict";var e=require("@ekz/lexical-react/LexicalComposerContext"),t=require("react"),n=require("@ekz/lexical-overflow"),r=require("@ekz/lexical-text"),i=require("@ekz/lexical-utils"),o=require("@ekz/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.getEditorState().read(r.$rootTextContent),l=0;return i.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){const r=Intl.Segmenter;let i=0,o=0;if("function"==typeof r){const s=(new r).segment(e);for(const{segment:e}of s){const r=o+n(e);if(r>t)break;o=r,i+=e.length}}else{const r=Array.from(e),s=r.length;for(let e=0;e<s;e++){const s=r[e],l=o+n(s);if(l>t)break;o=l,i+=s.length}}return i}(t,s,f);e.update(()=>{!function(e){const t=i.$dfs(),r=t.length;let s=0;for(let l=0;l<r;l+=1){const{node:r}=t[l],f=o.$isLeafNode(r)&&!i.$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){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}){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);return l(o,r,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])),i({remainingCharacters:s})};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import{useLexicalComposerContext as e}from"@ekz/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"@ekz/lexical-overflow";import{$rootTextContent as l}from"@ekz/lexical-text";import{mergeRegister as c,$dfs as a,$findMatchingParent as f,$unwrapNode as g}from"@ekz/lexical-utils";import{HISTORY_MERGE_TAG as m,DELETE_CHARACTER_COMMAND as u,$getSelection as d,$isRangeSelection as h,$isElementNode as p,COMMAND_PRIORITY_LOW as x,$isLeafNode as C,$isTextNode as S,$setSelection as v}from"@ekz/lexical";import{jsx as w}from"react/jsx-runtime";function z(e,n,r=Object.freeze({})){const{strlen:s=e=>e.length,remainingCharacters:w=()=>{}}=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.getEditorState().read(l),r=0;return c(e.registerTextContentListener(e=>{t=e}),e.registerUpdateListener(({dirtyLeaves:o,dirtyElements:l})=>{const c=e.isComposing(),u=o.size>0||l.size>0;if(c||!u)return;const p=s(t),x=p>n||null!==r&&r>n;if(w(n-p),null===r||x){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],s=C(n)&&!f(n,i);if(i(n)){const t=r;if(r+n.getTextContentSize()<=e){const e=n.getParent(),t=n.getPreviousSibling(),r=n.getNextSibling();g(n);const o=d();!h(o)||o.anchor.getNode().isAttached()&&o.focus.getNode().isAttached()||(S(t)?t.select():S(r)?r.select():null!==e&&e.select())}else if(t<e){const r=n.getFirstDescendant(),o=t+(null!==r?r.getTextContentSize():0);(S(r)&&r.isSimpleText()||o<=e)&&g(n)}}else if(s){const t=r;if(r+=n.getTextContentSize(),r>e&&!i(n.getParent())){const r=d();let o;if(t<e&&S(n)&&n.isSimpleText()){const[,r]=n.splitText(e-t);o=T(r)}else o=T(n);null!==r&&v(r),y(o)}}}}(r)},{tag:m})}r=p}),e.registerCommand(u,e=>{const t=d();if(!h(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():p(o)&&o.isEmpty()&&o.remove(),!0},x))},[e,n,w,s])}function T(e){const t=s();return e.replace(t),t.append(e),t}function y(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=d();if(h(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 N=null;function b(e){const t=void 0===window.TextEncoder?null:(null===N&&(N=new window.TextEncoder),N);if(null===t){const t=encodeURIComponent(e).match(/%[89ABab]/g);return e.length+(t?t.length:0)}return t.encode(e).length}function E({remainingCharacters:e}){return w("span",{className:"characters-limit "+(e<0?"characters-limit-exceeded":""),children:e})}function L({charset:t="UTF-16",maxLength:o=5,renderer:i=E}){const[s]=e(),[l,c]=n(o);return z(s,o,r(()=>({remainingCharacters:c,strlen:e=>{if("UTF-8"===t)return b(e);if("UTF-16"===t)return e.length;throw new Error("Unrecognized charset")}}),[t])),i({remainingCharacters:l})}export{L as CharacterLimitPlugin};
|