@contentful/field-editor-rich-text 3.4.21 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ContentfulEditorProvider.js +59 -0
- package/dist/cjs/RichTextEditor.js +170 -0
- package/dist/cjs/RichTextEditor.styles.js +66 -0
- package/dist/cjs/SdkProvider.js +69 -0
- package/dist/cjs/Toolbar/_tests_/toolbar.test.js +152 -0
- package/dist/cjs/Toolbar/components/EmbedEntityWidget.js +87 -0
- package/dist/cjs/Toolbar/components/EmbeddedEntityDropdownButton.js +69 -0
- package/dist/cjs/Toolbar/components/StickyToolbarWrapper.js +29 -0
- package/dist/cjs/Toolbar/index.js +222 -0
- package/dist/cjs/__fixtures__/FakeSdk.js +183 -0
- package/dist/cjs/__fixtures__/asset/index.js +37 -0
- package/dist/cjs/__fixtures__/content-type/index.js +16 -0
- package/dist/cjs/__fixtures__/entry/index.js +33 -0
- package/dist/cjs/__fixtures__/fixtures.js +71 -0
- package/dist/cjs/__fixtures__/locale/index.js +40 -0
- package/dist/cjs/__fixtures__/space/index.js +16 -0
- package/dist/cjs/constants/Schema.js +172 -0
- package/dist/cjs/dialogs/HypelinkDialog/HyperlinkDialog.js +348 -0
- package/dist/cjs/dialogs/openRichTextDialog.js +64 -0
- package/dist/cjs/dialogs/renderRichTextDialog.js +63 -0
- package/dist/cjs/helpers/__tests__/extractNodes.test.js +299 -0
- package/dist/cjs/helpers/__tests__/removeInternalMarks.test.js +52 -0
- package/dist/cjs/helpers/__tests__/validations.test.js +49 -0
- package/dist/cjs/helpers/editor.js +276 -0
- package/dist/cjs/helpers/environment.js +20 -0
- package/dist/cjs/helpers/extractNodes.js +27 -0
- package/dist/cjs/helpers/formatDateAndTime.js +45 -0
- package/dist/cjs/helpers/getLinkedContentTypeIdsForNodeType.js +24 -0
- package/dist/cjs/helpers/newEntitySelectorConfigFromRichTextField.js +33 -0
- package/dist/cjs/helpers/nodeFactory.js +51 -0
- package/dist/cjs/helpers/removeInternalMarks.js +26 -0
- package/dist/cjs/helpers/sanitizeIncomingSlateDoc.js +33 -0
- package/dist/cjs/helpers/sdkNavigatorSlideIn.js +57 -0
- package/dist/cjs/helpers/sdkNavigatorSlideIn.spec.js +209 -0
- package/dist/cjs/helpers/transformers.js +61 -0
- package/dist/cjs/helpers/validations.js +56 -0
- package/dist/cjs/index.js +66 -0
- package/dist/cjs/internal/constants.js +51 -0
- package/dist/cjs/internal/hooks.js +65 -0
- package/dist/cjs/internal/index.js +21 -0
- package/dist/cjs/internal/misc.js +103 -0
- package/dist/cjs/internal/queries.js +407 -0
- package/dist/cjs/internal/transforms.js +195 -0
- package/dist/cjs/internal/types/editor.js +4 -0
- package/dist/cjs/internal/types/index.js +19 -0
- package/dist/cjs/internal/types/plugins.js +4 -0
- package/dist/cjs/plugins/Break/createExitBreakPlugin.js +26 -0
- package/dist/cjs/plugins/Break/createExitBreakPlugin.test.js +36 -0
- package/dist/cjs/plugins/Break/createResetNodePlugin.js +32 -0
- package/dist/cjs/plugins/Break/createSoftBreakPlugin.js +23 -0
- package/dist/cjs/plugins/Break/createSoftBreakPlugin.test.js +47 -0
- package/dist/cjs/plugins/Break/index.js +20 -0
- package/dist/cjs/plugins/CommandPalette/components/CommandList.js +167 -0
- package/dist/cjs/plugins/CommandPalette/components/CommandList.styles.js +103 -0
- package/dist/cjs/plugins/CommandPalette/components/CommandPrompt.js +69 -0
- package/dist/cjs/plugins/CommandPalette/constants.js +11 -0
- package/dist/cjs/plugins/CommandPalette/createCommandPalettePlugin.js +24 -0
- package/dist/cjs/plugins/CommandPalette/hooks/useCommandList.js +138 -0
- package/dist/cjs/plugins/CommandPalette/index.js +11 -0
- package/dist/cjs/plugins/CommandPalette/onKeyDown.js +51 -0
- package/dist/cjs/plugins/CommandPalette/onKeyDown.spec.js +83 -0
- package/dist/cjs/plugins/CommandPalette/useCommands.js +222 -0
- package/dist/cjs/plugins/CommandPalette/utils/createInlineEntryNode.js +30 -0
- package/dist/cjs/plugins/CommandPalette/utils/fetchAssets.js +31 -0
- package/dist/cjs/plugins/CommandPalette/utils/fetchEntries.js +39 -0
- package/dist/cjs/plugins/CommandPalette/utils/insertBlock.js +42 -0
- package/dist/cjs/plugins/CommandPalette/utils/trimLeadingSlash.js +16 -0
- package/dist/cjs/plugins/DragAndDrop/index.js +54 -0
- package/dist/cjs/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +128 -0
- package/dist/cjs/plugins/EmbeddedEntityBlock/ToolbarIcon.js +106 -0
- package/dist/cjs/plugins/EmbeddedEntityBlock/Util.js +108 -0
- package/dist/cjs/plugins/EmbeddedEntityBlock/index.js +100 -0
- package/dist/cjs/plugins/EmbeddedEntityInline/FetchingWrappedInlineEntryCard.js +158 -0
- package/dist/cjs/plugins/EmbeddedEntityInline/Util.js +30 -0
- package/dist/cjs/plugins/EmbeddedEntityInline/index.js +221 -0
- package/dist/cjs/plugins/Heading/__tests__/createHeadingPlugin.test.js +117 -0
- package/dist/cjs/plugins/Heading/components/Heading.js +127 -0
- package/dist/cjs/plugins/Heading/components/ToolbarHeadingButton.js +173 -0
- package/dist/cjs/plugins/Heading/createHeadingPlugin.js +102 -0
- package/dist/cjs/plugins/Heading/index.js +19 -0
- package/dist/cjs/plugins/Hr/index.js +193 -0
- package/dist/cjs/plugins/Hyperlink/HyperlinkModal.js +282 -0
- package/dist/cjs/plugins/Hyperlink/__tests__/createHyperlinkPlugin.test.js +25 -0
- package/dist/cjs/plugins/Hyperlink/components/EntityHyperlink.js +93 -0
- package/dist/cjs/plugins/Hyperlink/components/ToolbarHyperlinkButton.js +78 -0
- package/dist/cjs/plugins/Hyperlink/components/UrlHyperlink.js +86 -0
- package/dist/cjs/plugins/Hyperlink/components/styles.js +36 -0
- package/dist/cjs/plugins/Hyperlink/createHyperlinkPlugin.js +179 -0
- package/dist/cjs/plugins/Hyperlink/index.js +20 -0
- package/dist/cjs/plugins/Hyperlink/useEntityInfo.js +95 -0
- package/dist/cjs/plugins/Hyperlink/utils.js +43 -0
- package/dist/cjs/plugins/List/__tests__/createListPlugin.test.js +47 -0
- package/dist/cjs/plugins/List/__tests__/insertListBreak.test.js +77 -0
- package/dist/cjs/plugins/List/__tests__/insertListFragment.test.js +64 -0
- package/dist/cjs/plugins/List/components/List.js +108 -0
- package/dist/cjs/plugins/List/components/ListItem.js +73 -0
- package/dist/cjs/plugins/List/components/ToolbarListButton.js +86 -0
- package/dist/cjs/plugins/List/createListPlugin.js +76 -0
- package/dist/cjs/plugins/List/index.js +19 -0
- package/dist/cjs/plugins/List/insertListBreak.js +60 -0
- package/dist/cjs/plugins/List/insertListFragment.js +98 -0
- package/dist/cjs/plugins/List/onKeyDownList.js +46 -0
- package/dist/cjs/plugins/List/transforms/insertListItem.js +92 -0
- package/dist/cjs/plugins/List/transforms/moveListItemDown.js +47 -0
- package/dist/cjs/plugins/List/transforms/moveListItems.js +56 -0
- package/dist/cjs/plugins/List/transforms/moveListItems.test.js +72 -0
- package/dist/cjs/plugins/List/transforms/toggleList.js +141 -0
- package/dist/cjs/plugins/List/transforms/toggleList.spec.js +139 -0
- package/dist/cjs/plugins/List/transforms/unwrapList.js +38 -0
- package/dist/cjs/plugins/List/utils.js +122 -0
- package/dist/cjs/plugins/List/withList.js +32 -0
- package/dist/cjs/plugins/Marks/Bold.js +119 -0
- package/dist/cjs/plugins/Marks/Code.js +122 -0
- package/dist/cjs/plugins/Marks/Italic.js +114 -0
- package/dist/cjs/plugins/Marks/Subscript.js +109 -0
- package/dist/cjs/plugins/Marks/Superscript.js +107 -0
- package/dist/cjs/plugins/Marks/Underline.js +106 -0
- package/dist/cjs/plugins/Marks/components/MarkToolbarButton.js +105 -0
- package/dist/cjs/plugins/Marks/helpers.js +48 -0
- package/dist/cjs/plugins/Marks/index.js +27 -0
- package/dist/cjs/plugins/Normalizer/baseRules.js +38 -0
- package/dist/cjs/plugins/Normalizer/createNormalizerPlugin.js +15 -0
- package/dist/cjs/plugins/Normalizer/createNormalizerPlugin.test.js +117 -0
- package/dist/cjs/plugins/Normalizer/index.js +19 -0
- package/dist/cjs/plugins/Normalizer/types.js +4 -0
- package/dist/cjs/plugins/Normalizer/utils.js +39 -0
- package/dist/cjs/plugins/Normalizer/withNormalizer.js +88 -0
- package/dist/cjs/plugins/Paragraph/Paragraph.js +70 -0
- package/dist/cjs/plugins/Paragraph/__tests__/createParagraphPlugin.test.js +125 -0
- package/dist/cjs/plugins/Paragraph/createParagraphPlugin.js +73 -0
- package/dist/cjs/plugins/Paragraph/index.js +18 -0
- package/dist/cjs/plugins/Paragraph/utils.js +24 -0
- package/dist/cjs/plugins/PasteHTML/createPasteHTMLPlugin.js +63 -0
- package/dist/cjs/plugins/PasteHTML/index.js +18 -0
- package/dist/cjs/plugins/PasteHTML/utils/__tests__/sanitizeHTML.test.js +54 -0
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeAnchors.js +43 -0
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeHTML.js +50 -0
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeSheets.js +44 -0
- package/dist/cjs/plugins/Quote/__test__/createQuotePlugin.test.js +78 -0
- package/dist/cjs/plugins/Quote/components/Quote.js +69 -0
- package/dist/cjs/plugins/Quote/components/ToolbarQuoteButton.js +72 -0
- package/dist/cjs/plugins/Quote/createQuotePlugin.js +57 -0
- package/dist/cjs/plugins/Quote/index.js +19 -0
- package/dist/cjs/plugins/Quote/shouldResetQuote.js +40 -0
- package/dist/cjs/plugins/Quote/toggleQuote.js +56 -0
- package/dist/cjs/plugins/Quote/withQuote.js +48 -0
- package/dist/cjs/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.js +21 -0
- package/dist/cjs/plugins/SelectOnBackspace/index.js +18 -0
- package/dist/cjs/plugins/Table/__tests__/createTablePlugin.test.js +92 -0
- package/dist/cjs/plugins/Table/__tests__/helpers.test.js +18 -0
- package/dist/cjs/plugins/Table/actions/addColumn.js +63 -0
- package/dist/cjs/plugins/Table/actions/addRow.js +57 -0
- package/dist/cjs/plugins/Table/actions/index.js +20 -0
- package/dist/cjs/plugins/Table/actions/setHeader.js +34 -0
- package/dist/cjs/plugins/Table/components/Cell.js +79 -0
- package/dist/cjs/plugins/Table/components/HeaderCell.js +82 -0
- package/dist/cjs/plugins/Table/components/Row.js +69 -0
- package/dist/cjs/plugins/Table/components/Table.js +76 -0
- package/dist/cjs/plugins/Table/components/TableActions.js +175 -0
- package/dist/cjs/plugins/Table/components/ToolbarButton.js +73 -0
- package/dist/cjs/plugins/Table/createTablePlugin.js +119 -0
- package/dist/cjs/plugins/Table/helpers.js +152 -0
- package/dist/cjs/plugins/Table/index.js +19 -0
- package/dist/cjs/plugins/Table/insertTableFragment.js +50 -0
- package/dist/cjs/plugins/Table/onKeyDownTable.js +62 -0
- package/dist/cjs/plugins/Table/tableTracking.js +64 -0
- package/dist/cjs/plugins/Text/__tests__/createTextPlugin.test.js +79 -0
- package/dist/cjs/plugins/Text/createTextPlugin.js +136 -0
- package/dist/cjs/plugins/Text/index.js +18 -0
- package/dist/cjs/plugins/Tracking/createTrackingPlugin.js +101 -0
- package/dist/cjs/plugins/Tracking/index.js +18 -0
- package/dist/cjs/plugins/Tracking/utils.js +64 -0
- package/dist/cjs/plugins/TrailingParagraph/index.js +20 -0
- package/dist/cjs/plugins/Voids/createVoidsPlugin.js +31 -0
- package/dist/cjs/plugins/Voids/index.js +18 -0
- package/dist/cjs/plugins/Voids/transformVoid.js +29 -0
- package/dist/cjs/plugins/index.js +76 -0
- package/dist/cjs/plugins/links-tracking.js +29 -0
- package/dist/cjs/plugins/shared/FetchingWrappedAssetCard.js +113 -0
- package/dist/cjs/plugins/shared/FetchingWrappedEntryCard.js +116 -0
- package/dist/cjs/plugins/shared/ToolbarButton.js +93 -0
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedAssetCard.test.js +107 -0
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedEntryCard.test.js +110 -0
- package/dist/cjs/prepareDocument.js +86 -0
- package/dist/cjs/test-utils/assertOutput.js +31 -0
- package/dist/cjs/test-utils/createEditor.js +31 -0
- package/dist/cjs/test-utils/hyperscript.d.js +1 -0
- package/dist/cjs/test-utils/index.js +21 -0
- package/dist/cjs/test-utils/jsx.js +159 -0
- package/dist/cjs/test-utils/mockPlugin.js +16 -0
- package/dist/cjs/test-utils/randomId.js +13 -0
- package/dist/cjs/test-utils/setEmptyDataAttribute.js +21 -0
- package/dist/cjs/test-utils/validation.js +127 -0
- package/dist/cjs/useOnValueChanged.js +58 -0
- package/dist/esm/ContentfulEditorProvider.js +29 -0
- package/dist/esm/RichTextEditor.js +108 -0
- package/dist/esm/RichTextEditor.styles.js +51 -0
- package/dist/esm/SdkProvider.js +7 -0
- package/dist/esm/Toolbar/_tests_/toolbar.test.js +104 -0
- package/dist/esm/Toolbar/components/EmbedEntityWidget.js +38 -0
- package/dist/esm/Toolbar/components/EmbeddedEntityDropdownButton.js +20 -0
- package/dist/esm/Toolbar/components/StickyToolbarWrapper.js +14 -0
- package/dist/esm/Toolbar/index.js +168 -0
- package/dist/esm/__fixtures__/FakeSdk.js +173 -0
- package/dist/esm/__fixtures__/asset/index.js +6 -0
- package/dist/esm/__fixtures__/content-type/index.js +2 -0
- package/dist/esm/__fixtures__/entry/index.js +5 -0
- package/dist/esm/__fixtures__/fixtures.js +6 -0
- package/dist/esm/__fixtures__/locale/index.js +15 -0
- package/dist/esm/__fixtures__/space/index.js +2 -0
- package/dist/esm/constants/Schema.js +162 -0
- package/dist/esm/dialogs/HypelinkDialog/HyperlinkDialog.js +283 -0
- package/dist/esm/dialogs/openRichTextDialog.js +15 -0
- package/dist/esm/dialogs/renderRichTextDialog.js +14 -0
- package/dist/esm/helpers/__tests__/extractNodes.test.js +295 -0
- package/dist/esm/helpers/__tests__/removeInternalMarks.test.js +48 -0
- package/dist/esm/helpers/__tests__/validations.test.js +45 -0
- package/dist/esm/helpers/editor.js +198 -0
- package/dist/esm/helpers/environment.js +2 -0
- package/dist/esm/helpers/extractNodes.js +17 -0
- package/dist/esm/helpers/formatDateAndTime.js +19 -0
- package/dist/esm/helpers/getLinkedContentTypeIdsForNodeType.js +9 -0
- package/dist/esm/helpers/newEntitySelectorConfigFromRichTextField.js +18 -0
- package/dist/esm/helpers/nodeFactory.js +24 -0
- package/dist/esm/helpers/removeInternalMarks.js +16 -0
- package/dist/esm/helpers/sanitizeIncomingSlateDoc.js +23 -0
- package/dist/esm/helpers/sdkNavigatorSlideIn.js +42 -0
- package/dist/esm/helpers/sdkNavigatorSlideIn.spec.js +200 -0
- package/dist/esm/helpers/transformers.js +34 -0
- package/dist/esm/helpers/validations.js +24 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/internal/constants.js +2 -0
- package/dist/esm/internal/hooks.js +5 -0
- package/dist/esm/internal/index.js +4 -0
- package/dist/esm/internal/misc.js +28 -0
- package/dist/esm/internal/queries.js +182 -0
- package/dist/esm/internal/transforms.js +75 -0
- package/dist/esm/internal/types/editor.js +1 -0
- package/dist/esm/internal/types/index.js +2 -0
- package/dist/esm/internal/types/plugins.js +1 -0
- package/dist/esm/plugins/Break/createExitBreakPlugin.js +16 -0
- package/dist/esm/plugins/Break/createExitBreakPlugin.test.js +32 -0
- package/dist/esm/plugins/Break/createResetNodePlugin.js +22 -0
- package/dist/esm/plugins/Break/createSoftBreakPlugin.js +13 -0
- package/dist/esm/plugins/Break/createSoftBreakPlugin.test.js +43 -0
- package/dist/esm/plugins/Break/index.js +3 -0
- package/dist/esm/plugins/CommandPalette/components/CommandList.js +113 -0
- package/dist/esm/plugins/CommandPalette/components/CommandList.styles.js +88 -0
- package/dist/esm/plugins/CommandPalette/components/CommandPrompt.js +20 -0
- package/dist/esm/plugins/CommandPalette/constants.js +1 -0
- package/dist/esm/plugins/CommandPalette/createCommandPalettePlugin.js +14 -0
- package/dist/esm/plugins/CommandPalette/hooks/useCommandList.js +84 -0
- package/dist/esm/plugins/CommandPalette/index.js +1 -0
- package/dist/esm/plugins/CommandPalette/onKeyDown.js +36 -0
- package/dist/esm/plugins/CommandPalette/onKeyDown.spec.js +40 -0
- package/dist/esm/plugins/CommandPalette/useCommands.js +204 -0
- package/dist/esm/plugins/CommandPalette/utils/createInlineEntryNode.js +20 -0
- package/dist/esm/plugins/CommandPalette/utils/fetchAssets.js +21 -0
- package/dist/esm/plugins/CommandPalette/utils/fetchEntries.js +29 -0
- package/dist/esm/plugins/CommandPalette/utils/insertBlock.js +32 -0
- package/dist/esm/plugins/CommandPalette/utils/trimLeadingSlash.js +6 -0
- package/dist/esm/plugins/DragAndDrop/index.js +44 -0
- package/dist/esm/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +79 -0
- package/dist/esm/plugins/EmbeddedEntityBlock/ToolbarIcon.js +49 -0
- package/dist/esm/plugins/EmbeddedEntityBlock/Util.js +85 -0
- package/dist/esm/plugins/EmbeddedEntityBlock/index.js +74 -0
- package/dist/esm/plugins/EmbeddedEntityInline/FetchingWrappedInlineEntryCard.js +104 -0
- package/dist/esm/plugins/EmbeddedEntityInline/Util.js +20 -0
- package/dist/esm/plugins/EmbeddedEntityInline/index.js +159 -0
- package/dist/esm/plugins/Heading/__tests__/createHeadingPlugin.test.js +113 -0
- package/dist/esm/plugins/Heading/components/Heading.js +73 -0
- package/dist/esm/plugins/Heading/components/ToolbarHeadingButton.js +119 -0
- package/dist/esm/plugins/Heading/createHeadingPlugin.js +87 -0
- package/dist/esm/plugins/Heading/index.js +2 -0
- package/dist/esm/plugins/Hr/index.js +125 -0
- package/dist/esm/plugins/Hyperlink/HyperlinkModal.js +220 -0
- package/dist/esm/plugins/Hyperlink/__tests__/createHyperlinkPlugin.test.js +21 -0
- package/dist/esm/plugins/Hyperlink/components/EntityHyperlink.js +44 -0
- package/dist/esm/plugins/Hyperlink/components/ToolbarHyperlinkButton.js +29 -0
- package/dist/esm/plugins/Hyperlink/components/UrlHyperlink.js +37 -0
- package/dist/esm/plugins/Hyperlink/components/styles.js +21 -0
- package/dist/esm/plugins/Hyperlink/createHyperlinkPlugin.js +125 -0
- package/dist/esm/plugins/Hyperlink/index.js +2 -0
- package/dist/esm/plugins/Hyperlink/useEntityInfo.js +85 -0
- package/dist/esm/plugins/Hyperlink/utils.js +25 -0
- package/dist/esm/plugins/List/__tests__/createListPlugin.test.js +43 -0
- package/dist/esm/plugins/List/__tests__/insertListBreak.test.js +73 -0
- package/dist/esm/plugins/List/__tests__/insertListFragment.test.js +60 -0
- package/dist/esm/plugins/List/components/List.js +46 -0
- package/dist/esm/plugins/List/components/ListItem.js +19 -0
- package/dist/esm/plugins/List/components/ToolbarListButton.js +37 -0
- package/dist/esm/plugins/List/createListPlugin.js +66 -0
- package/dist/esm/plugins/List/index.js +2 -0
- package/dist/esm/plugins/List/insertListBreak.js +50 -0
- package/dist/esm/plugins/List/insertListFragment.js +88 -0
- package/dist/esm/plugins/List/onKeyDownList.js +31 -0
- package/dist/esm/plugins/List/transforms/insertListItem.js +82 -0
- package/dist/esm/plugins/List/transforms/moveListItemDown.js +37 -0
- package/dist/esm/plugins/List/transforms/moveListItems.js +46 -0
- package/dist/esm/plugins/List/transforms/moveListItems.test.js +68 -0
- package/dist/esm/plugins/List/transforms/toggleList.js +132 -0
- package/dist/esm/plugins/List/transforms/toggleList.spec.js +135 -0
- package/dist/esm/plugins/List/transforms/unwrapList.js +28 -0
- package/dist/esm/plugins/List/utils.js +89 -0
- package/dist/esm/plugins/List/withList.js +22 -0
- package/dist/esm/plugins/Marks/Bold.js +59 -0
- package/dist/esm/plugins/Marks/Code.js +59 -0
- package/dist/esm/plugins/Marks/Italic.js +54 -0
- package/dist/esm/plugins/Marks/Subscript.js +46 -0
- package/dist/esm/plugins/Marks/Superscript.js +44 -0
- package/dist/esm/plugins/Marks/Underline.js +46 -0
- package/dist/esm/plugins/Marks/components/MarkToolbarButton.js +51 -0
- package/dist/esm/plugins/Marks/helpers.js +25 -0
- package/dist/esm/plugins/Marks/index.js +17 -0
- package/dist/esm/plugins/Normalizer/baseRules.js +28 -0
- package/dist/esm/plugins/Normalizer/createNormalizerPlugin.js +5 -0
- package/dist/esm/plugins/Normalizer/createNormalizerPlugin.test.js +113 -0
- package/dist/esm/plugins/Normalizer/index.js +2 -0
- package/dist/esm/plugins/Normalizer/types.js +1 -0
- package/dist/esm/plugins/Normalizer/utils.js +18 -0
- package/dist/esm/plugins/Normalizer/withNormalizer.js +73 -0
- package/dist/esm/plugins/Paragraph/Paragraph.js +16 -0
- package/dist/esm/plugins/Paragraph/__tests__/createParagraphPlugin.test.js +121 -0
- package/dist/esm/plugins/Paragraph/createParagraphPlugin.js +58 -0
- package/dist/esm/plugins/Paragraph/index.js +1 -0
- package/dist/esm/plugins/Paragraph/utils.js +6 -0
- package/dist/esm/plugins/PasteHTML/createPasteHTMLPlugin.js +42 -0
- package/dist/esm/plugins/PasteHTML/index.js +1 -0
- package/dist/esm/plugins/PasteHTML/utils/__tests__/sanitizeHTML.test.js +50 -0
- package/dist/esm/plugins/PasteHTML/utils/sanitizeAnchors.js +33 -0
- package/dist/esm/plugins/PasteHTML/utils/sanitizeHTML.js +40 -0
- package/dist/esm/plugins/PasteHTML/utils/sanitizeSheets.js +34 -0
- package/dist/esm/plugins/Quote/__test__/createQuotePlugin.test.js +74 -0
- package/dist/esm/plugins/Quote/components/Quote.js +15 -0
- package/dist/esm/plugins/Quote/components/ToolbarQuoteButton.js +23 -0
- package/dist/esm/plugins/Quote/createQuotePlugin.js +47 -0
- package/dist/esm/plugins/Quote/index.js +2 -0
- package/dist/esm/plugins/Quote/shouldResetQuote.js +30 -0
- package/dist/esm/plugins/Quote/toggleQuote.js +33 -0
- package/dist/esm/plugins/Quote/withQuote.js +38 -0
- package/dist/esm/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.js +11 -0
- package/dist/esm/plugins/SelectOnBackspace/index.js +1 -0
- package/dist/esm/plugins/Table/__tests__/createTablePlugin.test.js +88 -0
- package/dist/esm/plugins/Table/__tests__/helpers.test.js +14 -0
- package/dist/esm/plugins/Table/actions/addColumn.js +45 -0
- package/dist/esm/plugins/Table/actions/addRow.js +39 -0
- package/dist/esm/plugins/Table/actions/index.js +3 -0
- package/dist/esm/plugins/Table/actions/setHeader.js +24 -0
- package/dist/esm/plugins/Table/components/Cell.js +25 -0
- package/dist/esm/plugins/Table/components/HeaderCell.js +28 -0
- package/dist/esm/plugins/Table/components/Row.js +15 -0
- package/dist/esm/plugins/Table/components/Table.js +22 -0
- package/dist/esm/plugins/Table/components/TableActions.js +118 -0
- package/dist/esm/plugins/Table/components/ToolbarButton.js +24 -0
- package/dist/esm/plugins/Table/createTablePlugin.js +109 -0
- package/dist/esm/plugins/Table/helpers.js +116 -0
- package/dist/esm/plugins/Table/index.js +2 -0
- package/dist/esm/plugins/Table/insertTableFragment.js +40 -0
- package/dist/esm/plugins/Table/onKeyDownTable.js +52 -0
- package/dist/esm/plugins/Table/tableTracking.js +46 -0
- package/dist/esm/plugins/Text/__tests__/createTextPlugin.test.js +75 -0
- package/dist/esm/plugins/Text/createTextPlugin.js +126 -0
- package/dist/esm/plugins/Text/index.js +1 -0
- package/dist/esm/plugins/Tracking/createTrackingPlugin.js +83 -0
- package/dist/esm/plugins/Tracking/index.js +1 -0
- package/dist/esm/plugins/Tracking/utils.js +10 -0
- package/dist/esm/plugins/TrailingParagraph/index.js +10 -0
- package/dist/esm/plugins/Voids/createVoidsPlugin.js +21 -0
- package/dist/esm/plugins/Voids/index.js +1 -0
- package/dist/esm/plugins/Voids/transformVoid.js +19 -0
- package/dist/esm/plugins/index.js +58 -0
- package/dist/esm/plugins/links-tracking.js +14 -0
- package/dist/esm/plugins/shared/FetchingWrappedAssetCard.js +59 -0
- package/dist/esm/plugins/shared/FetchingWrappedEntryCard.js +62 -0
- package/dist/esm/plugins/shared/ToolbarButton.js +39 -0
- package/dist/esm/plugins/shared/__tests__/FetchingWrappedAssetCard.test.js +59 -0
- package/dist/esm/plugins/shared/__tests__/FetchingWrappedEntryCard.test.js +62 -0
- package/dist/esm/prepareDocument.js +57 -0
- package/dist/esm/test-utils/assertOutput.js +21 -0
- package/dist/esm/test-utils/createEditor.js +21 -0
- package/dist/esm/test-utils/hyperscript.d.js +0 -0
- package/dist/esm/test-utils/index.js +4 -0
- package/dist/esm/test-utils/jsx.js +149 -0
- package/dist/esm/test-utils/mockPlugin.js +6 -0
- package/dist/esm/test-utils/randomId.js +3 -0
- package/dist/esm/test-utils/setEmptyDataAttribute.js +11 -0
- package/dist/esm/test-utils/validation.js +112 -0
- package/dist/esm/useOnValueChanged.js +43 -0
- package/dist/{ContentfulEditorProvider.d.ts → types/ContentfulEditorProvider.d.ts} +9 -9
- package/dist/{RichTextEditor.d.ts → types/RichTextEditor.d.ts} +21 -20
- package/dist/{RichTextEditor.styles.d.ts → types/RichTextEditor.styles.d.ts} +7 -7
- package/dist/{SdkProvider.d.ts → types/SdkProvider.d.ts} +7 -7
- package/dist/types/Toolbar/_tests_/toolbar.test.d.ts +1 -0
- package/dist/{Toolbar → types/Toolbar}/components/EmbedEntityWidget.d.ts +6 -5
- package/dist/{Toolbar → types/Toolbar}/components/EmbeddedEntityDropdownButton.d.ts +9 -9
- package/dist/{Toolbar → types/Toolbar}/components/StickyToolbarWrapper.d.ts +7 -7
- package/dist/types/Toolbar/index.d.ts +6 -0
- package/dist/types/__fixtures__/FakeSdk.d.ts +8 -0
- package/dist/types/__fixtures__/asset/index.d.ts +6 -0
- package/dist/types/__fixtures__/content-type/index.d.ts +2 -0
- package/dist/types/__fixtures__/entry/index.d.ts +5 -0
- package/dist/types/__fixtures__/fixtures.d.ts +6 -0
- package/dist/types/__fixtures__/locale/index.d.ts +42 -0
- package/dist/types/__fixtures__/space/index.d.ts +2 -0
- package/dist/{constants → types/constants}/Schema.d.ts +111 -111
- package/dist/{dialogs → types/dialogs}/HypelinkDialog/HyperlinkDialog.d.ts +63 -54
- package/dist/{dialogs → types/dialogs}/openRichTextDialog.d.ts +2 -2
- package/dist/{dialogs → types/dialogs}/renderRichTextDialog.d.ts +3 -2
- package/dist/types/helpers/__tests__/extractNodes.test.d.ts +1 -0
- package/dist/types/helpers/__tests__/removeInternalMarks.test.d.ts +2 -0
- package/dist/types/helpers/__tests__/validations.test.d.ts +1 -0
- package/dist/{helpers → types/helpers}/editor.d.ts +40 -40
- package/dist/{helpers → types/helpers}/environment.d.ts +2 -2
- package/dist/{helpers → types/helpers}/extractNodes.d.ts +5 -5
- package/dist/{helpers → types/helpers}/formatDateAndTime.d.ts +15 -15
- package/dist/{helpers → types/helpers}/getLinkedContentTypeIdsForNodeType.d.ts +26 -26
- package/dist/{helpers → types/helpers}/newEntitySelectorConfigFromRichTextField.d.ts +14 -14
- package/dist/{helpers → types/helpers}/nodeFactory.d.ts +24 -24
- package/dist/{helpers → types/helpers}/removeInternalMarks.d.ts +1 -1
- package/dist/{helpers → types/helpers}/sanitizeIncomingSlateDoc.d.ts +6 -6
- package/dist/{helpers → types/helpers}/sdkNavigatorSlideIn.d.ts +16 -16
- package/dist/types/helpers/sdkNavigatorSlideIn.spec.d.ts +1 -0
- package/dist/{helpers → types/helpers}/transformers.d.ts +7 -7
- package/dist/{helpers → types/helpers}/validations.d.ts +10 -10
- package/dist/{index.d.ts → types/index.d.ts} +4 -4
- package/dist/{internal → types/internal}/constants.d.ts +1 -1
- package/dist/{internal → types/internal}/hooks.d.ts +4 -4
- package/dist/{internal → types/internal}/index.d.ts +4 -4
- package/dist/{internal → types/internal}/misc.d.ts +37 -37
- package/dist/{internal → types/internal}/queries.d.ts +78 -78
- package/dist/{internal → types/internal}/transforms.d.ts +33 -33
- package/dist/types/internal/types/editor.d.ts +51 -0
- package/dist/{internal → types/internal}/types/index.d.ts +2 -2
- package/dist/{internal → types/internal}/types/plugins.d.ts +12 -12
- package/dist/{plugins → types/plugins}/Break/createExitBreakPlugin.d.ts +2 -2
- package/dist/types/plugins/Break/createExitBreakPlugin.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/Break/createResetNodePlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Break/createSoftBreakPlugin.d.ts +2 -2
- package/dist/types/plugins/Break/createSoftBreakPlugin.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/Break/index.d.ts +5 -5
- package/dist/{plugins → types/plugins}/CommandPalette/components/CommandList.d.ts +8 -7
- package/dist/{plugins → types/plugins}/CommandPalette/components/CommandList.styles.d.ts +14 -14
- package/dist/{plugins → types/plugins}/CommandPalette/components/CommandPrompt.d.ts +5 -4
- package/dist/{plugins → types/plugins}/CommandPalette/constants.d.ts +1 -1
- package/dist/{plugins → types/plugins}/CommandPalette/createCommandPalettePlugin.d.ts +13 -13
- package/dist/{plugins → types/plugins}/CommandPalette/hooks/useCommandList.d.ts +4 -4
- package/dist/{plugins → types/plugins}/CommandPalette/index.d.ts +1 -1
- package/dist/{plugins → types/plugins}/CommandPalette/onKeyDown.d.ts +2 -2
- package/dist/types/plugins/CommandPalette/onKeyDown.spec.d.ts +1 -0
- package/dist/{plugins → types/plugins}/CommandPalette/useCommands.d.ts +19 -19
- package/dist/{plugins → types/plugins}/CommandPalette/utils/createInlineEntryNode.d.ts +16 -16
- package/dist/{plugins → types/plugins}/CommandPalette/utils/fetchAssets.d.ts +8 -8
- package/dist/{plugins → types/plugins}/CommandPalette/utils/fetchEntries.d.ts +9 -9
- package/dist/{plugins → types/plugins}/CommandPalette/utils/insertBlock.d.ts +1 -1
- package/dist/{plugins → types/plugins}/CommandPalette/utils/trimLeadingSlash.d.ts +7 -7
- package/dist/{plugins → types/plugins}/DragAndDrop/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/EmbeddedEntityBlock/LinkedEntityBlock.d.ts +20 -19
- package/dist/{plugins → types/plugins}/EmbeddedEntityBlock/ToolbarIcon.d.ts +11 -10
- package/dist/{plugins → types/plugins}/EmbeddedEntityBlock/Util.d.ts +4 -4
- package/dist/{plugins → types/plugins}/EmbeddedEntityBlock/index.d.ts +5 -5
- package/dist/{plugins → types/plugins}/EmbeddedEntityInline/FetchingWrappedInlineEntryCard.d.ts +13 -13
- package/dist/{plugins → types/plugins}/EmbeddedEntityInline/Util.d.ts +16 -16
- package/dist/{plugins → types/plugins}/EmbeddedEntityInline/index.d.ts +10 -9
- package/dist/types/plugins/Heading/__tests__/createHeadingPlugin.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/Heading/components/Heading.d.ts +10 -10
- package/dist/{plugins → types/plugins}/Heading/components/ToolbarHeadingButton.d.ts +5 -4
- package/dist/{plugins → types/plugins}/Heading/createHeadingPlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Heading/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Hr/index.d.ts +11 -11
- package/dist/{plugins → types/plugins}/Hyperlink/HyperlinkModal.d.ts +17 -16
- package/dist/types/plugins/Hyperlink/__tests__/createHyperlinkPlugin.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/Hyperlink/components/EntityHyperlink.d.ts +21 -20
- package/dist/{plugins → types/plugins}/Hyperlink/components/ToolbarHyperlinkButton.d.ts +6 -5
- package/dist/{plugins → types/plugins}/Hyperlink/components/UrlHyperlink.d.ts +22 -21
- package/dist/{plugins → types/plugins}/Hyperlink/components/styles.d.ts +4 -4
- package/dist/{plugins → types/plugins}/Hyperlink/createHyperlinkPlugin.d.ts +3 -3
- package/dist/{plugins → types/plugins}/Hyperlink/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Hyperlink/useEntityInfo.d.ts +16 -16
- package/dist/{plugins → types/plugins}/Hyperlink/utils.d.ts +5 -5
- package/dist/types/plugins/List/__tests__/createListPlugin.test.d.ts +1 -0
- package/dist/types/plugins/List/__tests__/insertListBreak.test.d.ts +1 -0
- package/dist/types/plugins/List/__tests__/insertListFragment.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/List/components/List.d.ts +4 -3
- package/dist/{plugins → types/plugins}/List/components/ListItem.d.ts +3 -2
- package/dist/{plugins → types/plugins}/List/components/ToolbarListButton.d.ts +5 -4
- package/dist/{plugins → types/plugins}/List/createListPlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/List/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/List/insertListBreak.d.ts +2 -2
- package/dist/{plugins → types/plugins}/List/insertListFragment.d.ts +2 -2
- package/dist/{plugins → types/plugins}/List/onKeyDownList.d.ts +7 -7
- package/dist/{plugins → types/plugins}/List/transforms/insertListItem.d.ts +5 -5
- package/dist/{plugins → types/plugins}/List/transforms/moveListItemDown.d.ts +6 -6
- package/dist/{plugins → types/plugins}/List/transforms/moveListItems.d.ts +6 -6
- package/dist/types/plugins/List/transforms/moveListItems.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/List/transforms/toggleList.d.ts +4 -4
- package/dist/types/plugins/List/transforms/toggleList.spec.d.ts +1 -0
- package/dist/{plugins → types/plugins}/List/transforms/unwrapList.d.ts +4 -4
- package/dist/{plugins → types/plugins}/List/utils.d.ts +14 -14
- package/dist/{plugins → types/plugins}/List/withList.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Marks/Bold.d.ts +11 -10
- package/dist/{plugins → types/plugins}/Marks/Code.d.ts +17 -16
- package/dist/{plugins → types/plugins}/Marks/Italic.d.ts +11 -10
- package/dist/{plugins → types/plugins}/Marks/Subscript.d.ts +17 -16
- package/dist/{plugins → types/plugins}/Marks/Superscript.d.ts +17 -16
- package/dist/{plugins → types/plugins}/Marks/Underline.d.ts +11 -10
- package/dist/{plugins → types/plugins}/Marks/components/MarkToolbarButton.d.ts +13 -13
- package/dist/{plugins → types/plugins}/Marks/helpers.d.ts +4 -4
- package/dist/{plugins → types/plugins}/Marks/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Normalizer/baseRules.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Normalizer/createNormalizerPlugin.d.ts +2 -2
- package/dist/types/plugins/Normalizer/createNormalizerPlugin.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/Normalizer/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Normalizer/types.d.ts +38 -38
- package/dist/{plugins → types/plugins}/Normalizer/utils.d.ts +5 -5
- package/dist/{plugins → types/plugins}/Normalizer/withNormalizer.d.ts +2 -2
- package/dist/types/plugins/Paragraph/Paragraph.d.ts +3 -0
- package/dist/types/plugins/Paragraph/__tests__/createParagraphPlugin.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/Paragraph/createParagraphPlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Paragraph/index.d.ts +1 -1
- package/dist/{plugins → types/plugins}/Paragraph/utils.d.ts +2 -2
- package/dist/{plugins → types/plugins}/PasteHTML/createPasteHTMLPlugin.d.ts +8 -8
- package/dist/{plugins → types/plugins}/PasteHTML/index.d.ts +1 -1
- package/dist/types/plugins/PasteHTML/utils/__tests__/sanitizeHTML.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/PasteHTML/utils/sanitizeAnchors.d.ts +19 -19
- package/dist/{plugins → types/plugins}/PasteHTML/utils/sanitizeHTML.d.ts +1 -1
- package/dist/{plugins → types/plugins}/PasteHTML/utils/sanitizeSheets.d.ts +4 -4
- package/dist/types/plugins/Quote/__test__/createQuotePlugin.test.d.ts +1 -0
- package/dist/types/plugins/Quote/components/Quote.d.ts +3 -0
- package/dist/{plugins → types/plugins}/Quote/components/ToolbarQuoteButton.d.ts +5 -4
- package/dist/{plugins → types/plugins}/Quote/createQuotePlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Quote/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Quote/shouldResetQuote.d.ts +8 -8
- package/dist/{plugins → types/plugins}/Quote/toggleQuote.d.ts +4 -4
- package/dist/{plugins → types/plugins}/Quote/withQuote.d.ts +2 -2
- package/dist/{plugins → types/plugins}/SelectOnBackspace/createSelectOnBackspacePlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/SelectOnBackspace/index.d.ts +1 -1
- package/dist/types/plugins/Table/__tests__/createTablePlugin.test.d.ts +1 -0
- package/dist/types/plugins/Table/__tests__/helpers.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/Table/actions/addColumn.d.ts +7 -7
- package/dist/{plugins → types/plugins}/Table/actions/addRow.d.ts +3 -3
- package/dist/{plugins → types/plugins}/Table/actions/index.d.ts +3 -3
- package/dist/{plugins → types/plugins}/Table/actions/setHeader.d.ts +2 -2
- package/dist/types/plugins/Table/components/Cell.d.ts +3 -0
- package/dist/{plugins → types/plugins}/Table/components/HeaderCell.d.ts +3 -2
- package/dist/types/plugins/Table/components/Row.d.ts +3 -0
- package/dist/{plugins → types/plugins}/Table/components/Table.d.ts +3 -2
- package/dist/types/plugins/Table/components/TableActions.d.ts +5 -0
- package/dist/{plugins → types/plugins}/Table/components/ToolbarButton.d.ts +5 -4
- package/dist/{plugins → types/plugins}/Table/createTablePlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Table/helpers.d.ts +15 -15
- package/dist/{plugins → types/plugins}/Table/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Table/insertTableFragment.d.ts +3 -3
- package/dist/{plugins → types/plugins}/Table/onKeyDownTable.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Table/tableTracking.d.ts +4 -4
- package/dist/types/plugins/Text/__tests__/createTextPlugin.test.d.ts +2 -0
- package/dist/{plugins → types/plugins}/Text/createTextPlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Text/index.d.ts +1 -1
- package/dist/{plugins → types/plugins}/Tracking/createTrackingPlugin.d.ts +12 -12
- package/dist/{plugins → types/plugins}/Tracking/index.d.ts +1 -1
- package/dist/{plugins → types/plugins}/Tracking/utils.d.ts +2 -2
- package/dist/{plugins → types/plugins}/TrailingParagraph/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Voids/createVoidsPlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Voids/index.d.ts +1 -1
- package/dist/{plugins → types/plugins}/Voids/transformVoid.d.ts +5 -5
- package/dist/{plugins → types/plugins}/index.d.ts +6 -6
- package/dist/{plugins → types/plugins}/links-tracking.d.ts +3 -3
- package/dist/{plugins → types/plugins}/shared/FetchingWrappedAssetCard.d.ts +14 -13
- package/dist/{plugins → types/plugins}/shared/FetchingWrappedEntryCard.d.ts +14 -13
- package/dist/{plugins → types/plugins}/shared/ToolbarButton.d.ts +12 -11
- package/dist/types/plugins/shared/__tests__/FetchingWrappedAssetCard.test.d.ts +1 -0
- package/dist/types/plugins/shared/__tests__/FetchingWrappedEntryCard.test.d.ts +1 -0
- package/dist/{prepareDocument.d.ts → types/prepareDocument.d.ts} +19 -19
- package/dist/{test-utils → types/test-utils}/assertOutput.d.ts +7 -7
- package/dist/{test-utils → types/test-utils}/createEditor.d.ts +31 -31
- package/dist/{test-utils → types/test-utils}/index.d.ts +4 -4
- package/dist/{test-utils → types/test-utils}/jsx.d.ts +28 -28
- package/dist/{test-utils → types/test-utils}/mockPlugin.d.ts +2 -2
- package/dist/{test-utils → types/test-utils}/randomId.d.ts +4 -4
- package/dist/{test-utils → types/test-utils}/setEmptyDataAttribute.d.ts +6 -6
- package/dist/{test-utils → types/test-utils}/validation.d.ts +1 -1
- package/dist/{useOnValueChanged.d.ts → types/useOnValueChanged.d.ts} +8 -8
- package/package.json +27 -21
- package/CHANGELOG.md +0 -946
- package/dist/Toolbar/index.d.ts +0 -5
- package/dist/field-editor-rich-text.cjs.development.js +0 -7210
- package/dist/field-editor-rich-text.cjs.development.js.map +0 -1
- package/dist/field-editor-rich-text.cjs.production.min.js +0 -163
- package/dist/field-editor-rich-text.cjs.production.min.js.map +0 -1
- package/dist/field-editor-rich-text.esm.js +0 -7200
- package/dist/field-editor-rich-text.esm.js.map +0 -1
- package/dist/index.js +0 -8
- package/dist/internal/types/editor.d.ts +0 -51
- package/dist/plugins/List/transforms/deleteBackwardList.d.ts +0 -2
- package/dist/plugins/Paragraph/Paragraph.d.ts +0 -2
- package/dist/plugins/Quote/components/Quote.d.ts +0 -2
- package/dist/plugins/Table/components/Cell.d.ts +0 -2
- package/dist/plugins/Table/components/Row.d.ts +0 -2
- package/dist/plugins/Table/components/TableActions.d.ts +0 -4
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BLOCKS, TEXT_CONTAINERS } from '@contentful/rich-text-types';
|
|
2
|
+
import { Element, Point } from 'slate';
|
|
3
|
+
import { getAboveNode, getText } from '../../internal/queries';
|
|
4
|
+
import { deleteText, insertNodes } from '../../internal/transforms';
|
|
5
|
+
export const withQuote = (editor)=>{
|
|
6
|
+
const { insertFragment } = editor;
|
|
7
|
+
editor.insertFragment = (fragment)=>{
|
|
8
|
+
const startingNode = fragment.length && fragment[0];
|
|
9
|
+
const startsWithBlockquote = Element.isElement(startingNode) && startingNode.type === BLOCKS.QUOTE;
|
|
10
|
+
const containerEntry = getAboveNode(editor, {
|
|
11
|
+
match: {
|
|
12
|
+
type: TEXT_CONTAINERS
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
const containerIsNotEmpty = containerEntry && getText(editor, containerEntry[1]) !== '';
|
|
16
|
+
if (startsWithBlockquote && containerIsNotEmpty) {
|
|
17
|
+
const { selection } = editor;
|
|
18
|
+
const isContentSelected = (selection)=>!!selection && Point.compare(selection.anchor, selection.focus) !== 0;
|
|
19
|
+
if (isContentSelected(selection)) {
|
|
20
|
+
deleteText(editor, {
|
|
21
|
+
at: selection
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const containerEntry = getAboveNode(editor, {
|
|
25
|
+
match: {
|
|
26
|
+
type: TEXT_CONTAINERS
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const containerIsNotEmpty = containerEntry && getText(editor, containerEntry[1]) !== '';
|
|
30
|
+
if (containerIsNotEmpty) {
|
|
31
|
+
insertNodes(editor, fragment);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
insertFragment(fragment);
|
|
36
|
+
};
|
|
37
|
+
return editor;
|
|
38
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { INLINES } from '@contentful/rich-text-types';
|
|
2
|
+
import { createSelectOnBackspacePlugin as createDefaultSelectPlugin } from '@udecode/plate-select';
|
|
3
|
+
export const createSelectOnBackspacePlugin = ()=>createDefaultSelectPlugin({
|
|
4
|
+
options: {
|
|
5
|
+
query: {
|
|
6
|
+
allow: [
|
|
7
|
+
INLINES.EMBEDDED_ENTRY
|
|
8
|
+
]
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createSelectOnBackspacePlugin';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { assertOutput, jsx } from '../../../test-utils';
|
|
2
|
+
describe('normalization', ()=>{
|
|
3
|
+
describe('Table', ()=>{
|
|
4
|
+
it('removes empty table nodes', ()=>{
|
|
5
|
+
const input = jsx("editor", null, jsx("htable", null));
|
|
6
|
+
const expected = jsx("editor", null, jsx("hp", null, jsx("text", null)));
|
|
7
|
+
assertOutput({
|
|
8
|
+
input,
|
|
9
|
+
expected
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
it('moves tables to the root level except nested tables', ()=>{
|
|
13
|
+
const table = jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "Cell 1")), jsx("htd", null, jsx("hp", null, "Cell 2"))));
|
|
14
|
+
const input = jsx("editor", null, jsx("hp", null, "hello", table), jsx("hquote", null, jsx("hp", null, "quote", table)), jsx("hul", null, jsx("hli", null, jsx("hp", null, "item", table))), jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell with table: ", table)))));
|
|
15
|
+
const expected = jsx("editor", null, jsx("hp", null, "hello"), table, jsx("hquote", null, jsx("hp", null, "quote")), table, jsx("hul", null, jsx("hli", null, jsx("hp", null, "item"))), table, jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell with table: "), jsx("hp", null, "Cell 1"), jsx("hp", null, "Cell 2")))), jsx("hp", null, jsx("htext", null)));
|
|
16
|
+
assertOutput({
|
|
17
|
+
input,
|
|
18
|
+
expected
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
it('removes invalid children', ()=>{
|
|
22
|
+
const input = jsx("editor", null, jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "Cell 1")), jsx("htd", null, jsx("hp", null, "Cell 2"))), jsx("htd", null, "invalid cell"), "invalid text"), jsx("hp", null));
|
|
23
|
+
const expected = jsx("editor", null, jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "Cell 1")), jsx("htd", null, jsx("hp", null, "Cell 2")))), jsx("hp", null, jsx("htext", null)));
|
|
24
|
+
assertOutput({
|
|
25
|
+
input,
|
|
26
|
+
expected
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe('Table cell', ()=>{
|
|
31
|
+
it('converts invalid children to paragraphs', ()=>{
|
|
32
|
+
const input = jsx("editor", null, jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "Cell 1")), jsx("htd", null, jsx("hp", null, "Cell 2"), jsx("hquote", null, jsx("hp", null, jsx("htext", {
|
|
33
|
+
bold: true,
|
|
34
|
+
italic: true,
|
|
35
|
+
underline: true
|
|
36
|
+
}, "quote"), jsx("hinline", {
|
|
37
|
+
type: "Entry",
|
|
38
|
+
id: "entry-id"
|
|
39
|
+
})))))), jsx("hp", null));
|
|
40
|
+
const expected = jsx("editor", null, jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "Cell 1")), jsx("htd", null, jsx("hp", null, "Cell 2"), jsx("hp", null, jsx("htext", {
|
|
41
|
+
bold: true,
|
|
42
|
+
italic: true,
|
|
43
|
+
underline: true
|
|
44
|
+
}, "quote"), jsx("hinline", {
|
|
45
|
+
type: "Entry",
|
|
46
|
+
id: "entry-id"
|
|
47
|
+
}), jsx("htext", null))))), jsx("hp", null, jsx("htext", null)));
|
|
48
|
+
assertOutput({
|
|
49
|
+
input,
|
|
50
|
+
expected
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('Table row', ()=>{
|
|
55
|
+
it('must be wrapped in a table', ()=>{
|
|
56
|
+
const input = jsx("editor", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell"))));
|
|
57
|
+
const expected = jsx("editor", null, jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell")))), jsx("hp", null, jsx("text", null)));
|
|
58
|
+
assertOutput({
|
|
59
|
+
input,
|
|
60
|
+
expected
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
it('removes empty rows', ()=>{
|
|
64
|
+
const input = jsx("editor", null, jsx("htr", null));
|
|
65
|
+
const expected = jsx("editor", null, jsx("hp", null, jsx("text", null)));
|
|
66
|
+
assertOutput({
|
|
67
|
+
input,
|
|
68
|
+
expected
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
it('wraps invalid children in table cells', ()=>{
|
|
72
|
+
const input = jsx("editor", null, jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell 1")), jsx("hp", null, "cell 2"))));
|
|
73
|
+
const expected = jsx("editor", null, jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell 1")), jsx("htd", null, jsx("hp", null, "cell 2")))), jsx("hp", null, jsx("text", null)));
|
|
74
|
+
assertOutput({
|
|
75
|
+
input,
|
|
76
|
+
expected
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
it('ensures all table rows have the same width', ()=>{
|
|
80
|
+
const input = jsx("editor", null, jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell 1"))), jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell 2")), jsx("htd", null, jsx("hp", null, "cell 3")), jsx("htd", null, jsx("hp", null, "cell 4"))), jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell 5")), jsx("htd", null, jsx("hp", null, "cell 6")))));
|
|
81
|
+
const expected = jsx("editor", null, jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell 1")), jsx("htd", null, jsx("hp", null, jsx("text", null))), jsx("htd", null, jsx("hp", null, jsx("text", null)))), jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell 2")), jsx("htd", null, jsx("hp", null, "cell 3")), jsx("htd", null, jsx("hp", null, "cell 4"))), jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell 5")), jsx("htd", null, jsx("hp", null, "cell 6")), jsx("htd", null, jsx("hp", null, jsx("text", null))))), jsx("hp", null, jsx("text", null)));
|
|
82
|
+
assertOutput({
|
|
83
|
+
input,
|
|
84
|
+
expected
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx, assertOutput, createTestEditor } from '../../../test-utils';
|
|
2
|
+
import { insertTableAndFocusFirstCell } from '../helpers';
|
|
3
|
+
test('insertTableAndFocusFirstCell', ()=>{
|
|
4
|
+
const input = jsx("editor", null, jsx("hp", null, jsx("htext", null), jsx("cursor", null)), jsx("hp", null));
|
|
5
|
+
const { editor } = createTestEditor({
|
|
6
|
+
input
|
|
7
|
+
});
|
|
8
|
+
insertTableAndFocusFirstCell(editor);
|
|
9
|
+
const expected = jsx("editor", null, jsx("htable", null, jsx("htr", null, jsx("hth", null, jsx("hp", null, jsx("htext", null), jsx("cursor", null))), jsx("hth", null, jsx("hp", null, jsx("htext", null)))), jsx("htr", null, jsx("htd", null, jsx("hp", null, jsx("htext", null))), jsx("htd", null, jsx("hp", null, jsx("htext", null))))), jsx("hp", null, jsx("htext", null)));
|
|
10
|
+
assertOutput({
|
|
11
|
+
input,
|
|
12
|
+
expected
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BLOCKS } from '@contentful/rich-text-types';
|
|
2
|
+
import { getEmptyCellNode } from '@udecode/plate-table';
|
|
3
|
+
import { getAboveNode, getNextPath, someNode } from '../../../internal/queries';
|
|
4
|
+
import { insertNodes } from '../../../internal/transforms';
|
|
5
|
+
const addColumn = (editor, { header }, getNextCellPath)=>{
|
|
6
|
+
if (someNode(editor, {
|
|
7
|
+
match: {
|
|
8
|
+
type: BLOCKS.TABLE
|
|
9
|
+
}
|
|
10
|
+
})) {
|
|
11
|
+
const currentCellItem = getAboveNode(editor, {
|
|
12
|
+
match: {
|
|
13
|
+
type: [
|
|
14
|
+
BLOCKS.TABLE_HEADER_CELL,
|
|
15
|
+
BLOCKS.TABLE_CELL
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const currentTableItem = getAboveNode(editor, {
|
|
20
|
+
match: {
|
|
21
|
+
type: BLOCKS.TABLE
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
if (currentCellItem && currentTableItem) {
|
|
25
|
+
const nextCellPath = getNextCellPath(currentCellItem[1]);
|
|
26
|
+
const newCellPath = nextCellPath.slice();
|
|
27
|
+
const replacePathPos = newCellPath.length - 2;
|
|
28
|
+
currentTableItem[0].children.forEach((_, rowIdx)=>{
|
|
29
|
+
newCellPath[replacePathPos] = rowIdx;
|
|
30
|
+
insertNodes(editor, getEmptyCellNode(editor, {
|
|
31
|
+
header: header && rowIdx === 0
|
|
32
|
+
}), {
|
|
33
|
+
at: newCellPath,
|
|
34
|
+
select: rowIdx === 0
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const addColumnRight = (editor, options)=>{
|
|
41
|
+
addColumn(editor, options, (currentCellPath)=>getNextPath(currentCellPath));
|
|
42
|
+
};
|
|
43
|
+
export const addColumnLeft = (editor, options)=>{
|
|
44
|
+
addColumn(editor, options, (currentCellPath)=>currentCellPath);
|
|
45
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BLOCKS } from '@contentful/rich-text-types';
|
|
2
|
+
import { getEmptyRowNode } from '@udecode/plate-table';
|
|
3
|
+
import { getAboveNode, someNode, getStartPoint, getNextPath } from '../../../internal/queries';
|
|
4
|
+
import { select, insertNodes } from '../../../internal/transforms';
|
|
5
|
+
const addRow = (editor, getNextRowPath)=>{
|
|
6
|
+
if (someNode(editor, {
|
|
7
|
+
match: {
|
|
8
|
+
type: BLOCKS.TABLE
|
|
9
|
+
}
|
|
10
|
+
})) {
|
|
11
|
+
const currentRowItem = getAboveNode(editor, {
|
|
12
|
+
match: {
|
|
13
|
+
type: BLOCKS.TABLE_ROW
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
if (currentRowItem) {
|
|
17
|
+
const [currentRowElem, currentRowPath] = currentRowItem;
|
|
18
|
+
const nextRowPath = getNextRowPath(currentRowPath);
|
|
19
|
+
insertNodes(editor, getEmptyRowNode(editor, {
|
|
20
|
+
header: false,
|
|
21
|
+
colCount: currentRowElem.children.length
|
|
22
|
+
}), {
|
|
23
|
+
at: nextRowPath,
|
|
24
|
+
select: true
|
|
25
|
+
});
|
|
26
|
+
select(editor, getStartPoint(editor, nextRowPath));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export const addRowBelow = (editor)=>{
|
|
31
|
+
addRow(editor, (currentRowPath)=>{
|
|
32
|
+
return getNextPath(currentRowPath);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export const addRowAbove = (editor)=>{
|
|
36
|
+
addRow(editor, (currentRowPath)=>{
|
|
37
|
+
return currentRowPath;
|
|
38
|
+
});
|
|
39
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BLOCKS } from '@contentful/rich-text-types';
|
|
2
|
+
import { getAboveNode, getChildren } from '../../../internal/queries';
|
|
3
|
+
import { setNodes } from '../../../internal/transforms';
|
|
4
|
+
export const setHeader = (editor, enable)=>{
|
|
5
|
+
const tableItem = getAboveNode(editor, {
|
|
6
|
+
match: {
|
|
7
|
+
type: BLOCKS.TABLE
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
if (!tableItem) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const firstRow = getChildren(tableItem)[0];
|
|
14
|
+
if (!firstRow) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
getChildren(firstRow).forEach(([, path])=>{
|
|
18
|
+
setNodes(editor, {
|
|
19
|
+
type: enable ? BLOCKS.TABLE_HEADER_CELL : BLOCKS.TABLE_CELL
|
|
20
|
+
}, {
|
|
21
|
+
at: path
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import tokens from '@contentful/f36-tokens';
|
|
3
|
+
import { css } from 'emotion';
|
|
4
|
+
import { useSelected } from 'slate-react';
|
|
5
|
+
import { TableActions } from './TableActions';
|
|
6
|
+
const style = css`
|
|
7
|
+
border: 1px solid ${tokens.gray400};
|
|
8
|
+
border-collapse: collapse;
|
|
9
|
+
padding: 10px 12px;
|
|
10
|
+
min-width: 48px;
|
|
11
|
+
position: relative;
|
|
12
|
+
vertical-align: top;
|
|
13
|
+
|
|
14
|
+
div:last-child {
|
|
15
|
+
margin-bottom: 0;
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
export const Cell = (props)=>{
|
|
19
|
+
const isSelected = useSelected();
|
|
20
|
+
return React.createElement("td", {
|
|
21
|
+
...props.attributes,
|
|
22
|
+
...props.element.data,
|
|
23
|
+
className: style
|
|
24
|
+
}, isSelected && React.createElement(TableActions, null), props.children);
|
|
25
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import tokens from '@contentful/f36-tokens';
|
|
3
|
+
import { css } from 'emotion';
|
|
4
|
+
import { useSelected } from 'slate-react';
|
|
5
|
+
import { TableActions } from './TableActions';
|
|
6
|
+
const style = css`
|
|
7
|
+
background-clip: padding-box;
|
|
8
|
+
background-color: ${tokens.gray200};
|
|
9
|
+
border: 1px solid ${tokens.gray400};
|
|
10
|
+
border-collapse: collapse;
|
|
11
|
+
padding: 10px 12px;
|
|
12
|
+
font-weight: ${tokens.fontWeightNormal};
|
|
13
|
+
text-align: left;
|
|
14
|
+
min-width: 48px;
|
|
15
|
+
position: relative;
|
|
16
|
+
|
|
17
|
+
div:last-child {
|
|
18
|
+
margin-bottom: 0;
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
export const HeaderCell = (props)=>{
|
|
22
|
+
const isSelected = useSelected();
|
|
23
|
+
return React.createElement("th", {
|
|
24
|
+
...props.attributes,
|
|
25
|
+
...props.element.data,
|
|
26
|
+
className: style
|
|
27
|
+
}, isSelected && React.createElement(TableActions, null), props.children);
|
|
28
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import tokens from '@contentful/f36-tokens';
|
|
3
|
+
import { css } from 'emotion';
|
|
4
|
+
const style = css`
|
|
5
|
+
border: 1px solid ${tokens.gray400};
|
|
6
|
+
border-collapse: collapse;
|
|
7
|
+
|
|
8
|
+
&:hover td {
|
|
9
|
+
background-color: transparent !important;
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
export const Row = (props)=>React.createElement("tr", {
|
|
13
|
+
...props.attributes,
|
|
14
|
+
className: style
|
|
15
|
+
}, props.children);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import tokens from '@contentful/f36-tokens';
|
|
3
|
+
import { BLOCKS } from '@contentful/rich-text-types';
|
|
4
|
+
import { css } from 'emotion';
|
|
5
|
+
const style = css`
|
|
6
|
+
margin-bottom: 1.5em;
|
|
7
|
+
border-collapse: collapse;
|
|
8
|
+
border-radius: 5px;
|
|
9
|
+
border-style: hidden;
|
|
10
|
+
box-shadow: 0 0 0 1px ${tokens.gray400};
|
|
11
|
+
width: 100%;
|
|
12
|
+
table-layout: fixed;
|
|
13
|
+
overflow: hidden;
|
|
14
|
+
`;
|
|
15
|
+
export const Table = (props)=>{
|
|
16
|
+
return React.createElement("div", {
|
|
17
|
+
"data-block-type": BLOCKS.TABLE
|
|
18
|
+
}, React.createElement("table", {
|
|
19
|
+
className: style,
|
|
20
|
+
...props.attributes
|
|
21
|
+
}, React.createElement("tbody", null, props.children)));
|
|
22
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { IconButton, Menu } from '@contentful/f36-components';
|
|
3
|
+
import { ChevronDownIcon } from '@contentful/f36-icons';
|
|
4
|
+
import { BLOCKS } from '@contentful/rich-text-types';
|
|
5
|
+
import { deleteColumn, deleteRow, deleteTable } from '@udecode/plate-table';
|
|
6
|
+
import { css } from 'emotion';
|
|
7
|
+
import { useContentfulEditor } from '../../../ContentfulEditorProvider';
|
|
8
|
+
import { getNodeEntryFromSelection, getTableSize } from '../../../helpers/editor';
|
|
9
|
+
import { withoutNormalizing } from '../../../internal';
|
|
10
|
+
import { useReadOnly } from '../../../internal/hooks';
|
|
11
|
+
import { getAboveNode } from '../../../internal/queries';
|
|
12
|
+
import { addColumnLeft, addColumnRight, addRowAbove, addRowBelow, setHeader } from '../actions';
|
|
13
|
+
import { isTableHeaderEnabled } from '../helpers';
|
|
14
|
+
export const styles = {
|
|
15
|
+
topRight: css({
|
|
16
|
+
position: 'absolute',
|
|
17
|
+
top: '6px',
|
|
18
|
+
right: '5px'
|
|
19
|
+
})
|
|
20
|
+
};
|
|
21
|
+
const getCurrentTableSize = (editor)=>{
|
|
22
|
+
const [table] = getNodeEntryFromSelection(editor, BLOCKS.TABLE);
|
|
23
|
+
return table ? getTableSize(table) : null;
|
|
24
|
+
};
|
|
25
|
+
export const TableActions = ()=>{
|
|
26
|
+
const editor = useContentfulEditor();
|
|
27
|
+
const isDisabled = useReadOnly();
|
|
28
|
+
const [isOpen, setOpen] = React.useState(false);
|
|
29
|
+
const [isHeaderEnabled, setHeaderEnabled] = React.useState(false);
|
|
30
|
+
const close = React.useCallback(()=>{
|
|
31
|
+
setOpen(false);
|
|
32
|
+
}, []);
|
|
33
|
+
React.useEffect(()=>{
|
|
34
|
+
setHeaderEnabled(Boolean(editor && isTableHeaderEnabled(editor)));
|
|
35
|
+
}, [
|
|
36
|
+
editor
|
|
37
|
+
]);
|
|
38
|
+
const canInsertRowAbove = React.useMemo(()=>{
|
|
39
|
+
if (!editor) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const headerCell = getAboveNode(editor, {
|
|
43
|
+
match: {
|
|
44
|
+
type: BLOCKS.TABLE_HEADER_CELL
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return !headerCell;
|
|
48
|
+
}, [
|
|
49
|
+
editor
|
|
50
|
+
]);
|
|
51
|
+
const toggleHeader = React.useCallback(()=>{
|
|
52
|
+
close();
|
|
53
|
+
if (!editor) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const value = !isHeaderEnabled;
|
|
57
|
+
setHeaderEnabled(value);
|
|
58
|
+
setHeader(editor, value);
|
|
59
|
+
}, [
|
|
60
|
+
editor,
|
|
61
|
+
close,
|
|
62
|
+
isHeaderEnabled
|
|
63
|
+
]);
|
|
64
|
+
const action = React.useCallback((cb, type, element)=>()=>{
|
|
65
|
+
if (!editor?.selection) return;
|
|
66
|
+
close();
|
|
67
|
+
const tableSize = getCurrentTableSize(editor);
|
|
68
|
+
withoutNormalizing(editor, ()=>{
|
|
69
|
+
cb(editor, {
|
|
70
|
+
header: isHeaderEnabled
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
const actionName = `${type}Table${element === 'Table' ? '' : element}`;
|
|
74
|
+
editor.tracking.onViewportAction(actionName, {
|
|
75
|
+
tableSize
|
|
76
|
+
});
|
|
77
|
+
}, [
|
|
78
|
+
editor,
|
|
79
|
+
isHeaderEnabled,
|
|
80
|
+
close
|
|
81
|
+
]);
|
|
82
|
+
if (isDisabled) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return React.createElement(Menu, {
|
|
86
|
+
placement: "left",
|
|
87
|
+
isOpen: isOpen,
|
|
88
|
+
onOpen: ()=>{
|
|
89
|
+
setOpen(true);
|
|
90
|
+
},
|
|
91
|
+
onClose: close
|
|
92
|
+
}, React.createElement(Menu.Trigger, null, React.createElement(IconButton, {
|
|
93
|
+
size: "small",
|
|
94
|
+
variant: "transparent",
|
|
95
|
+
tabIndex: -1,
|
|
96
|
+
className: styles.topRight,
|
|
97
|
+
icon: React.createElement(ChevronDownIcon, null),
|
|
98
|
+
"aria-label": "Open table menu",
|
|
99
|
+
testId: "cf-table-actions-button"
|
|
100
|
+
})), React.createElement(Menu.List, null, React.createElement(Menu.Item, {
|
|
101
|
+
onClick: action(addRowAbove, 'insert', 'Row'),
|
|
102
|
+
disabled: !canInsertRowAbove
|
|
103
|
+
}, "Add row above"), React.createElement(Menu.Item, {
|
|
104
|
+
onClick: action(addRowBelow, 'insert', 'Row')
|
|
105
|
+
}, "Add row below"), React.createElement(Menu.Item, {
|
|
106
|
+
onClick: action(addColumnLeft, 'insert', 'Column')
|
|
107
|
+
}, "Add column left"), React.createElement(Menu.Item, {
|
|
108
|
+
onClick: action(addColumnRight, 'insert', 'Column')
|
|
109
|
+
}, "Add column right"), React.createElement(Menu.Divider, null), React.createElement(Menu.Item, {
|
|
110
|
+
onClick: toggleHeader
|
|
111
|
+
}, isHeaderEnabled ? 'Disable table header' : 'Enable table header'), React.createElement(Menu.Divider, null), React.createElement(Menu.Item, {
|
|
112
|
+
onClick: action(deleteRow, 'remove', 'Row')
|
|
113
|
+
}, "Delete row"), React.createElement(Menu.Item, {
|
|
114
|
+
onClick: action(deleteColumn, 'remove', 'Column')
|
|
115
|
+
}, "Delete column"), React.createElement(Menu.Item, {
|
|
116
|
+
onClick: action(deleteTable, 'remove', 'Table')
|
|
117
|
+
}, "Delete table")));
|
|
118
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { TableIcon } from '@contentful/f36-icons';
|
|
3
|
+
import { useContentfulEditor } from '../../../ContentfulEditorProvider';
|
|
4
|
+
import { focus } from '../../../helpers/editor';
|
|
5
|
+
import { ToolbarButton } from '../../shared/ToolbarButton';
|
|
6
|
+
import { insertTableAndFocusFirstCell, isTableActive } from './../helpers';
|
|
7
|
+
export function ToolbarTableButton(props) {
|
|
8
|
+
const editor = useContentfulEditor();
|
|
9
|
+
const isActive = editor && isTableActive(editor);
|
|
10
|
+
async function handleClick() {
|
|
11
|
+
if (!editor) return;
|
|
12
|
+
editor.tracking.onToolbarAction('insertTable');
|
|
13
|
+
insertTableAndFocusFirstCell(editor);
|
|
14
|
+
focus(editor);
|
|
15
|
+
}
|
|
16
|
+
if (!editor) return null;
|
|
17
|
+
return React.createElement(ToolbarButton, {
|
|
18
|
+
title: "Table",
|
|
19
|
+
testId: "table-toolbar-button",
|
|
20
|
+
onClick: handleClick,
|
|
21
|
+
isActive: !!isActive,
|
|
22
|
+
isDisabled: props.isDisabled
|
|
23
|
+
}, React.createElement(TableIcon, null));
|
|
24
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { BLOCKS, CONTAINERS } from '@contentful/rich-text-types';
|
|
2
|
+
import { createTablePlugin as createDefaultTablePlugin, ELEMENT_TABLE, ELEMENT_TD, ELEMENT_TH, ELEMENT_TR, withTable } from '@udecode/plate-table';
|
|
3
|
+
import { isRootLevel } from '../../helpers/editor';
|
|
4
|
+
import { transformLift, transformParagraphs, transformWrapIn } from '../../helpers/transformers';
|
|
5
|
+
import { getParentNode, getBlockAbove, getLastChildPath, getNextPath } from '../../internal/queries';
|
|
6
|
+
import { insertNodes } from '../../internal/transforms';
|
|
7
|
+
import { Cell } from './components/Cell';
|
|
8
|
+
import { HeaderCell } from './components/HeaderCell';
|
|
9
|
+
import { Row } from './components/Row';
|
|
10
|
+
import { Table } from './components/Table';
|
|
11
|
+
import { createEmptyTableCells, getNoOfMissingTableCellsInRow, isNotEmpty } from './helpers';
|
|
12
|
+
import { insertTableFragment } from './insertTableFragment';
|
|
13
|
+
import { onKeyDownTable } from './onKeyDownTable';
|
|
14
|
+
import { addTableTrackingEvents, withInvalidCellChildrenTracking } from './tableTracking';
|
|
15
|
+
export const createTablePlugin = ()=>createDefaultTablePlugin({
|
|
16
|
+
type: BLOCKS.TABLE,
|
|
17
|
+
handlers: {
|
|
18
|
+
onKeyDown: onKeyDownTable
|
|
19
|
+
},
|
|
20
|
+
withOverrides: (editor, plugin)=>{
|
|
21
|
+
const { normalizeNode } = editor;
|
|
22
|
+
withTable(editor, plugin);
|
|
23
|
+
editor.normalizeNode = normalizeNode;
|
|
24
|
+
addTableTrackingEvents(editor);
|
|
25
|
+
editor.insertFragment = insertTableFragment(editor);
|
|
26
|
+
return editor;
|
|
27
|
+
},
|
|
28
|
+
overrideByKey: {
|
|
29
|
+
[ELEMENT_TABLE]: {
|
|
30
|
+
type: BLOCKS.TABLE,
|
|
31
|
+
component: Table,
|
|
32
|
+
normalizer: [
|
|
33
|
+
{
|
|
34
|
+
validNode: isNotEmpty
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
validNode: (editor, [, path])=>{
|
|
38
|
+
const isNestedTable = !!getBlockAbove(editor, {
|
|
39
|
+
at: path,
|
|
40
|
+
match: {
|
|
41
|
+
type: [
|
|
42
|
+
BLOCKS.TABLE_CELL,
|
|
43
|
+
BLOCKS.TABLE_HEADER_CELL
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return isRootLevel(path) || isNestedTable;
|
|
48
|
+
},
|
|
49
|
+
transform: transformLift
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
validChildren: CONTAINERS[BLOCKS.TABLE]
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
[ELEMENT_TR]: {
|
|
57
|
+
type: BLOCKS.TABLE_ROW,
|
|
58
|
+
component: Row,
|
|
59
|
+
normalizer: [
|
|
60
|
+
{
|
|
61
|
+
validChildren: CONTAINERS[BLOCKS.TABLE_ROW],
|
|
62
|
+
transform: transformWrapIn(BLOCKS.TABLE_CELL)
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
validNode: isNotEmpty
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
validNode: (editor, [, path])=>{
|
|
69
|
+
const parent = getParentNode(editor, path)?.[0];
|
|
70
|
+
return parent && parent.type === BLOCKS.TABLE;
|
|
71
|
+
},
|
|
72
|
+
transform: transformWrapIn(BLOCKS.TABLE)
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
validNode: (editor, entry)=>{
|
|
76
|
+
return getNoOfMissingTableCellsInRow(editor, entry) === 0;
|
|
77
|
+
},
|
|
78
|
+
transform: (editor, entry)=>{
|
|
79
|
+
const howMany = getNoOfMissingTableCellsInRow(editor, entry);
|
|
80
|
+
const at = getNextPath(getLastChildPath(entry));
|
|
81
|
+
insertNodes(editor, createEmptyTableCells(howMany), {
|
|
82
|
+
at
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
[ELEMENT_TH]: {
|
|
89
|
+
type: BLOCKS.TABLE_HEADER_CELL,
|
|
90
|
+
component: HeaderCell,
|
|
91
|
+
normalizer: [
|
|
92
|
+
{
|
|
93
|
+
validChildren: CONTAINERS[BLOCKS.TABLE_HEADER_CELL],
|
|
94
|
+
transform: withInvalidCellChildrenTracking(transformParagraphs)
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
[ELEMENT_TD]: {
|
|
99
|
+
type: BLOCKS.TABLE_CELL,
|
|
100
|
+
component: Cell,
|
|
101
|
+
normalizer: [
|
|
102
|
+
{
|
|
103
|
+
validChildren: CONTAINERS[BLOCKS.TABLE_CELL],
|
|
104
|
+
transform: withInvalidCellChildrenTracking(transformParagraphs)
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|