@contentful/field-editor-rich-text 3.14.3 → 3.15.1
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 +8 -8
- package/dist/cjs/RichTextEditor.js +22 -20
- package/dist/cjs/RichTextEditor.styles.js +2 -1
- package/dist/cjs/SdkProvider.js +7 -5
- package/dist/cjs/SyncEditorChanges.js +15 -6
- package/dist/cjs/Toolbar/_tests_/toolbar.test.js +17 -15
- package/dist/cjs/Toolbar/components/EmbedEntityWidget.js +14 -10
- package/dist/cjs/Toolbar/components/EmbeddedEntityDropdownButton.js +10 -8
- package/dist/cjs/Toolbar/components/StickyToolbarWrapper.js +2 -2
- package/dist/cjs/Toolbar/index.js +33 -30
- package/dist/cjs/__fixtures__/FakeSdk.js +3 -3
- package/dist/cjs/__fixtures__/asset/index.js +10 -10
- package/dist/cjs/__fixtures__/content-type/index.js +1 -1
- package/dist/cjs/__fixtures__/entry/index.js +7 -7
- package/dist/cjs/__fixtures__/fixtures.js +8 -6
- package/dist/cjs/__fixtures__/locale/index.js +2 -2
- package/dist/cjs/__fixtures__/space/index.js +1 -1
- package/dist/cjs/constants/Schema.js +1 -0
- package/dist/cjs/dialogs/HypelinkDialog/HyperlinkDialog.js +43 -38
- package/dist/cjs/dialogs/openRichTextDialog.js +6 -4
- package/dist/cjs/dialogs/renderRichTextDialog.js +6 -4
- package/dist/cjs/helpers/__tests__/removeInternalMarks.test.js +10 -10
- package/dist/cjs/helpers/callbacks.js +3 -3
- package/dist/cjs/helpers/config.js +2 -2
- package/dist/cjs/helpers/editor.js +53 -44
- package/dist/cjs/helpers/environment.js +3 -3
- package/dist/cjs/helpers/formatDateAndTime.js +5 -4
- package/dist/cjs/helpers/getAllowedResourcesForNodeType.js +22 -5
- package/dist/cjs/helpers/getLinkedContentTypeIdsForNodeType.js +29 -5
- package/dist/cjs/helpers/nodeFactory.js +6 -6
- package/dist/cjs/helpers/sdkNavigatorSlideIn.js +14 -6
- package/dist/cjs/helpers/sdkNavigatorSlideIn.spec.js +3 -2
- package/dist/cjs/helpers/toSlateValue.js +14 -3
- package/dist/cjs/helpers/transformers.js +5 -5
- package/dist/cjs/helpers/validations.js +12 -9
- package/dist/cjs/index.js +7 -5
- package/dist/cjs/internal/constants.js +4 -2
- package/dist/cjs/internal/hooks.js +8 -6
- package/dist/cjs/internal/misc.js +15 -12
- package/dist/cjs/internal/queries.js +115 -108
- package/dist/cjs/internal/transforms.js +51 -48
- package/dist/cjs/internal/types/editor.js +3 -1
- package/dist/cjs/plugins/Break/createExitBreakPlugin.test.js +4 -3
- package/dist/cjs/plugins/Break/createResetNodePlugin.js +1 -0
- package/dist/cjs/plugins/Break/createSoftBreakPlugin.test.js +3 -3
- package/dist/cjs/plugins/CommandPalette/components/CommandList.js +35 -33
- package/dist/cjs/plugins/CommandPalette/components/CommandList.styles.js +1 -1
- package/dist/cjs/plugins/CommandPalette/components/CommandPrompt.js +7 -5
- package/dist/cjs/plugins/CommandPalette/hooks/useCommandList.js +7 -3
- package/dist/cjs/plugins/CommandPalette/onKeyDown.js +6 -1
- package/dist/cjs/plugins/CommandPalette/onKeyDown.spec.js +6 -4
- package/dist/cjs/plugins/CommandPalette/useCommands.js +3 -3
- package/dist/cjs/plugins/CommandPalette/utils/fetchEntries.js +2 -0
- package/dist/cjs/plugins/CommandPalette/utils/trimLeadingSlash.js +6 -1
- package/dist/cjs/plugins/DragAndDrop/index.js +9 -1
- package/dist/cjs/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +10 -8
- package/dist/cjs/plugins/EmbeddedEntityBlock/index.js +3 -3
- package/dist/cjs/plugins/EmbeddedEntityInline/FetchingWrappedInlineEntryCard.js +19 -17
- package/dist/cjs/plugins/EmbeddedEntityInline/LinkedEntityInline.js +9 -7
- package/dist/cjs/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +5 -5
- package/dist/cjs/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.js +17 -13
- package/dist/cjs/plugins/EmbeddedResourceInline/LinkedResourceInline.js +5 -5
- package/dist/cjs/plugins/Heading/__tests__/createHeadingPlugin.test.js +32 -32
- package/dist/cjs/plugins/Heading/components/Heading.js +13 -10
- package/dist/cjs/plugins/Heading/components/ToolbarHeadingButton.js +19 -11
- package/dist/cjs/plugins/Heading/createHeadingPlugin.js +7 -2
- package/dist/cjs/plugins/Hr/index.js +19 -14
- package/dist/cjs/plugins/Hyperlink/HyperlinkModal.js +32 -28
- package/dist/cjs/plugins/Hyperlink/__tests__/createHyperlinkPlugin.test.js +8 -8
- package/dist/cjs/plugins/Hyperlink/components/EntityHyperlink.js +8 -6
- package/dist/cjs/plugins/Hyperlink/components/ResourceHyperlink.js +8 -6
- package/dist/cjs/plugins/Hyperlink/components/ToolbarHyperlinkButton.js +6 -4
- package/dist/cjs/plugins/Hyperlink/components/UrlHyperlink.js +7 -5
- package/dist/cjs/plugins/Hyperlink/components/styles.js +1 -1
- package/dist/cjs/plugins/Hyperlink/createHyperlinkPlugin.js +10 -4
- package/dist/cjs/plugins/Hyperlink/useEntityInfo.js +6 -3
- package/dist/cjs/plugins/Hyperlink/useResourceEntityInfo.js +7 -5
- package/dist/cjs/plugins/Hyperlink/utils.js +6 -14
- package/dist/cjs/plugins/List/__tests__/createListPlugin.test.js +13 -13
- package/dist/cjs/plugins/List/__tests__/insertListBreak.test.js +29 -25
- package/dist/cjs/plugins/List/__tests__/insertListFragment.test.js +22 -22
- package/dist/cjs/plugins/List/components/List.js +9 -7
- package/dist/cjs/plugins/List/components/ListItem.js +6 -4
- package/dist/cjs/plugins/List/components/ToolbarListButton.js +7 -5
- package/dist/cjs/plugins/List/createListPlugin.js +4 -0
- package/dist/cjs/plugins/List/insertListBreak.js +13 -4
- package/dist/cjs/plugins/List/insertListFragment.js +18 -5
- package/dist/cjs/plugins/List/onKeyDownList.js +7 -4
- package/dist/cjs/plugins/List/transforms/insertListItem.js +17 -2
- package/dist/cjs/plugins/List/transforms/moveListItemDown.js +8 -2
- package/dist/cjs/plugins/List/transforms/moveListItems.js +7 -2
- package/dist/cjs/plugins/List/transforms/moveListItems.test.js +15 -14
- package/dist/cjs/plugins/List/transforms/toggleList.js +8 -3
- package/dist/cjs/plugins/List/transforms/toggleList.spec.js +28 -28
- package/dist/cjs/plugins/List/transforms/unwrapList.js +7 -2
- package/dist/cjs/plugins/List/utils.js +12 -11
- package/dist/cjs/plugins/List/withList.js +6 -2
- package/dist/cjs/plugins/Marks/Bold.js +9 -7
- package/dist/cjs/plugins/Marks/Code.js +15 -7
- package/dist/cjs/plugins/Marks/Italic.js +9 -7
- package/dist/cjs/plugins/Marks/Subscript.js +10 -8
- package/dist/cjs/plugins/Marks/Superscript.js +10 -8
- package/dist/cjs/plugins/Marks/Underline.js +6 -4
- package/dist/cjs/plugins/Marks/components/MarkToolbarButton.js +9 -7
- package/dist/cjs/plugins/Marks/helpers.js +5 -5
- package/dist/cjs/plugins/Normalizer/baseRules.js +2 -0
- package/dist/cjs/plugins/Normalizer/createNormalizerPlugin.test.js +12 -12
- package/dist/cjs/plugins/Normalizer/utils.js +4 -3
- package/dist/cjs/plugins/Normalizer/withNormalizer.js +23 -3
- package/dist/cjs/plugins/Paragraph/Paragraph.js +6 -4
- package/dist/cjs/plugins/Paragraph/__tests__/createParagraphPlugin.test.js +32 -32
- package/dist/cjs/plugins/Paragraph/createParagraphPlugin.js +3 -2
- package/dist/cjs/plugins/PasteHTML/createPasteHTMLPlugin.js +9 -6
- package/dist/cjs/plugins/PasteHTML/utils/__tests__/sanitizeHTML.test.js +2 -0
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeAnchors.js +9 -0
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeHTML.js +17 -2
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeSheets.js +13 -1
- package/dist/cjs/plugins/Quote/__test__/createQuotePlugin.test.js +21 -21
- package/dist/cjs/plugins/Quote/components/Quote.js +6 -4
- package/dist/cjs/plugins/Quote/components/ToolbarQuoteButton.js +6 -4
- package/dist/cjs/plugins/Quote/createQuotePlugin.js +1 -0
- package/dist/cjs/plugins/Quote/toggleQuote.js +5 -5
- package/dist/cjs/plugins/Quote/withQuote.js +4 -2
- package/dist/cjs/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.js +1 -0
- package/dist/cjs/plugins/Table/__tests__/createTablePlugin.test.js +22 -22
- package/dist/cjs/plugins/Table/__tests__/helpers.test.js +4 -4
- package/dist/cjs/plugins/Table/actions/addColumn.js +5 -4
- package/dist/cjs/plugins/Table/actions/addRow.js +6 -3
- package/dist/cjs/plugins/Table/components/Cell.js +7 -5
- package/dist/cjs/plugins/Table/components/HeaderCell.js +7 -5
- package/dist/cjs/plugins/Table/components/Row.js +6 -4
- package/dist/cjs/plugins/Table/components/Table.js +8 -6
- package/dist/cjs/plugins/Table/components/TableActions.js +19 -16
- package/dist/cjs/plugins/Table/components/ToolbarButton.js +7 -4
- package/dist/cjs/plugins/Table/createTablePlugin.js +11 -1
- package/dist/cjs/plugins/Table/helpers.js +16 -12
- package/dist/cjs/plugins/Table/insertTableFragment.js +15 -2
- package/dist/cjs/plugins/Table/onKeyDownTable.js +10 -2
- package/dist/cjs/plugins/Table/tableTracking.js +6 -6
- package/dist/cjs/plugins/Text/__tests__/createTextPlugin.test.js +19 -17
- package/dist/cjs/plugins/Text/createTextPlugin.js +22 -5
- package/dist/cjs/plugins/Tracking/createTrackingPlugin.js +5 -4
- package/dist/cjs/plugins/Tracking/utils.js +6 -3
- package/dist/cjs/plugins/Voids/createVoidsPlugin.js +5 -0
- package/dist/cjs/plugins/Voids/transformVoid.js +1 -0
- package/dist/cjs/plugins/index.js +15 -3
- package/dist/cjs/plugins/shared/EmbeddedBlockToolbarIcon.js +12 -10
- package/dist/cjs/plugins/shared/EmbeddedBlockUtil.js +16 -6
- package/dist/cjs/plugins/shared/EmbeddedInlineToolbarIcon.js +10 -8
- package/dist/cjs/plugins/shared/EmbeddedInlineUtil.js +9 -5
- package/dist/cjs/plugins/shared/FetchingWrappedAssetCard.js +13 -11
- package/dist/cjs/plugins/shared/FetchingWrappedEntryCard.js +14 -12
- package/dist/cjs/plugins/shared/FetchingWrappedResourceCard.js +14 -11
- package/dist/cjs/plugins/shared/LinkedBlockWrapper.js +8 -4
- package/dist/cjs/plugins/shared/LinkedInlineWrapper.js +10 -6
- package/dist/cjs/plugins/shared/ResourceNewBadge.js +5 -3
- package/dist/cjs/plugins/shared/ToolbarButton.js +8 -6
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedAssetCard.test.js +10 -5
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedEntryCard.test.js +11 -6
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedResourceCard.test.js +15 -13
- package/dist/cjs/plugins/shared/utils.js +20 -3
- package/dist/cjs/test-utils/assertOutput.js +1 -0
- package/dist/cjs/test-utils/hyperscript.d.js +1 -0
- package/dist/cjs/test-utils/randomId.js +3 -1
- package/dist/cjs/test-utils/validation.js +8 -5
- package/dist/esm/ContentfulEditorProvider.js +4 -1
- package/dist/esm/RichTextEditor.js +13 -13
- package/dist/esm/RichTextEditor.styles.js +1 -0
- package/dist/esm/SdkProvider.js +2 -2
- package/dist/esm/SyncEditorChanges.js +18 -3
- package/dist/esm/Toolbar/_tests_/toolbar.test.js +12 -12
- package/dist/esm/Toolbar/components/EmbedEntityWidget.js +10 -8
- package/dist/esm/Toolbar/components/EmbeddedEntityDropdownButton.js +6 -6
- package/dist/esm/Toolbar/components/StickyToolbarWrapper.js +1 -1
- package/dist/esm/Toolbar/index.js +28 -27
- package/dist/esm/__fixtures__/FakeSdk.js +3 -3
- package/dist/esm/constants/Schema.js +1 -0
- package/dist/esm/dialogs/HypelinkDialog/HyperlinkDialog.js +34 -31
- package/dist/esm/dialogs/openRichTextDialog.js +2 -2
- package/dist/esm/dialogs/renderRichTextDialog.js +2 -2
- package/dist/esm/helpers/__tests__/removeInternalMarks.test.js +10 -10
- package/dist/esm/helpers/callbacks.js +1 -1
- package/dist/esm/helpers/config.js +9 -1
- package/dist/esm/helpers/editor.js +22 -6
- package/dist/esm/helpers/extractNodes.js +3 -1
- package/dist/esm/helpers/formatDateAndTime.js +11 -2
- package/dist/esm/helpers/getAllowedResourcesForNodeType.js +19 -2
- package/dist/esm/helpers/getLinkedContentTypeIdsForNodeType.js +26 -2
- package/dist/esm/helpers/sdkNavigatorSlideIn.js +20 -6
- package/dist/esm/helpers/sdkNavigatorSlideIn.spec.js +1 -0
- package/dist/esm/helpers/toSlateValue.js +17 -3
- package/dist/esm/helpers/validations.js +5 -1
- package/dist/esm/internal/misc.js +23 -2
- package/dist/esm/internal/queries.js +11 -2
- package/dist/esm/internal/transforms.js +14 -3
- package/dist/esm/internal/types/editor.js +3 -1
- package/dist/esm/plugins/Break/createExitBreakPlugin.test.js +4 -3
- package/dist/esm/plugins/Break/createResetNodePlugin.js +1 -0
- package/dist/esm/plugins/Break/createSoftBreakPlugin.test.js +3 -3
- package/dist/esm/plugins/CommandPalette/components/CommandList.js +30 -30
- package/dist/esm/plugins/CommandPalette/components/CommandPrompt.js +2 -2
- package/dist/esm/plugins/CommandPalette/createCommandPalettePlugin.js +11 -1
- package/dist/esm/plugins/CommandPalette/hooks/useCommandList.js +2 -0
- package/dist/esm/plugins/CommandPalette/onKeyDown.js +5 -0
- package/dist/esm/plugins/CommandPalette/onKeyDown.spec.js +2 -2
- package/dist/esm/plugins/CommandPalette/useCommands.js +3 -3
- package/dist/esm/plugins/CommandPalette/utils/fetchEntries.js +2 -0
- package/dist/esm/plugins/CommandPalette/utils/trimLeadingSlash.js +6 -1
- package/dist/esm/plugins/DragAndDrop/index.js +9 -1
- package/dist/esm/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +6 -6
- package/dist/esm/plugins/EmbeddedEntityInline/FetchingWrappedInlineEntryCard.js +14 -14
- package/dist/esm/plugins/EmbeddedEntityInline/LinkedEntityInline.js +5 -5
- package/dist/esm/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +4 -4
- package/dist/esm/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.js +13 -11
- package/dist/esm/plugins/EmbeddedResourceInline/LinkedResourceInline.js +4 -4
- package/dist/esm/plugins/Heading/__tests__/createHeadingPlugin.test.js +32 -32
- package/dist/esm/plugins/Heading/components/Heading.js +8 -7
- package/dist/esm/plugins/Heading/components/ToolbarHeadingButton.js +14 -8
- package/dist/esm/plugins/Heading/createHeadingPlugin.js +6 -1
- package/dist/esm/plugins/Hr/index.js +8 -5
- package/dist/esm/plugins/Hyperlink/HyperlinkModal.js +25 -23
- package/dist/esm/plugins/Hyperlink/__tests__/createHyperlinkPlugin.test.js +8 -8
- package/dist/esm/plugins/Hyperlink/components/EntityHyperlink.js +4 -4
- package/dist/esm/plugins/Hyperlink/components/ResourceHyperlink.js +4 -4
- package/dist/esm/plugins/Hyperlink/components/ToolbarHyperlinkButton.js +2 -2
- package/dist/esm/plugins/Hyperlink/components/UrlHyperlink.js +3 -3
- package/dist/esm/plugins/Hyperlink/createHyperlinkPlugin.js +5 -1
- package/dist/esm/plugins/Hyperlink/useEntityInfo.js +6 -3
- package/dist/esm/plugins/Hyperlink/useResourceEntityInfo.js +3 -3
- package/dist/esm/plugins/Hyperlink/utils.js +2 -7
- package/dist/esm/plugins/List/__tests__/createListPlugin.test.js +13 -13
- package/dist/esm/plugins/List/__tests__/insertListBreak.test.js +29 -25
- package/dist/esm/plugins/List/__tests__/insertListFragment.test.js +22 -22
- package/dist/esm/plugins/List/components/List.js +1 -1
- package/dist/esm/plugins/List/components/ListItem.js +1 -1
- package/dist/esm/plugins/List/components/ToolbarListButton.js +3 -3
- package/dist/esm/plugins/List/createListPlugin.js +4 -0
- package/dist/esm/plugins/List/insertListBreak.js +13 -4
- package/dist/esm/plugins/List/insertListFragment.js +18 -5
- package/dist/esm/plugins/List/onKeyDownList.js +5 -2
- package/dist/esm/plugins/List/transforms/insertListItem.js +20 -3
- package/dist/esm/plugins/List/transforms/moveListItemDown.js +8 -2
- package/dist/esm/plugins/List/transforms/moveListItems.js +7 -2
- package/dist/esm/plugins/List/transforms/moveListItems.test.js +15 -14
- package/dist/esm/plugins/List/transforms/toggleList.js +8 -3
- package/dist/esm/plugins/List/transforms/toggleList.spec.js +28 -28
- package/dist/esm/plugins/List/transforms/unwrapList.js +7 -2
- package/dist/esm/plugins/List/utils.js +7 -2
- package/dist/esm/plugins/List/withList.js +6 -2
- package/dist/esm/plugins/Marks/Bold.js +2 -2
- package/dist/esm/plugins/Marks/Code.js +8 -2
- package/dist/esm/plugins/Marks/Italic.js +2 -2
- package/dist/esm/plugins/Marks/Subscript.js +2 -2
- package/dist/esm/plugins/Marks/Superscript.js +2 -2
- package/dist/esm/plugins/Marks/Underline.js +2 -2
- package/dist/esm/plugins/Marks/components/MarkToolbarButton.js +4 -4
- package/dist/esm/plugins/Marks/helpers.js +1 -1
- package/dist/esm/plugins/Normalizer/baseRules.js +4 -0
- package/dist/esm/plugins/Normalizer/createNormalizerPlugin.test.js +12 -12
- package/dist/esm/plugins/Normalizer/utils.js +1 -0
- package/dist/esm/plugins/Normalizer/withNormalizer.js +22 -2
- package/dist/esm/plugins/Paragraph/Paragraph.js +1 -1
- package/dist/esm/plugins/Paragraph/__tests__/createParagraphPlugin.test.js +32 -32
- package/dist/esm/plugins/Paragraph/createParagraphPlugin.js +2 -1
- package/dist/esm/plugins/PasteHTML/createPasteHTMLPlugin.js +9 -3
- package/dist/esm/plugins/PasteHTML/utils/__tests__/sanitizeHTML.test.js +2 -0
- package/dist/esm/plugins/PasteHTML/utils/sanitizeAnchors.js +27 -1
- package/dist/esm/plugins/PasteHTML/utils/sanitizeHTML.js +17 -2
- package/dist/esm/plugins/PasteHTML/utils/sanitizeSheets.js +13 -1
- package/dist/esm/plugins/Quote/__test__/createQuotePlugin.test.js +21 -21
- package/dist/esm/plugins/Quote/components/Quote.js +1 -1
- package/dist/esm/plugins/Quote/components/ToolbarQuoteButton.js +2 -2
- package/dist/esm/plugins/Quote/createQuotePlugin.js +1 -0
- package/dist/esm/plugins/Quote/shouldResetQuote.js +6 -1
- package/dist/esm/plugins/Quote/toggleQuote.js +1 -1
- package/dist/esm/plugins/Quote/withQuote.js +4 -2
- package/dist/esm/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.js +1 -0
- package/dist/esm/plugins/Table/__tests__/createTablePlugin.test.js +22 -22
- package/dist/esm/plugins/Table/__tests__/helpers.test.js +4 -4
- package/dist/esm/plugins/Table/actions/addColumn.js +2 -1
- package/dist/esm/plugins/Table/actions/addRow.js +3 -0
- package/dist/esm/plugins/Table/components/Cell.js +2 -2
- package/dist/esm/plugins/Table/components/HeaderCell.js +2 -2
- package/dist/esm/plugins/Table/components/Row.js +1 -1
- package/dist/esm/plugins/Table/components/Table.js +3 -3
- package/dist/esm/plugins/Table/components/TableActions.js +12 -11
- package/dist/esm/plugins/Table/components/ToolbarButton.js +3 -2
- package/dist/esm/plugins/Table/createTablePlugin.js +11 -1
- package/dist/esm/plugins/Table/helpers.js +10 -1
- package/dist/esm/plugins/Table/insertTableFragment.js +15 -2
- package/dist/esm/plugins/Table/onKeyDownTable.js +10 -2
- package/dist/esm/plugins/Table/tableTracking.js +6 -6
- package/dist/esm/plugins/Text/__tests__/createTextPlugin.test.js +19 -17
- package/dist/esm/plugins/Text/createTextPlugin.js +22 -5
- package/dist/esm/plugins/Tracking/createTrackingPlugin.js +2 -1
- package/dist/esm/plugins/Tracking/utils.js +1 -0
- package/dist/esm/plugins/Voids/createVoidsPlugin.js +5 -0
- package/dist/esm/plugins/Voids/transformVoid.js +4 -1
- package/dist/esm/plugins/index.js +12 -0
- package/dist/esm/plugins/shared/EmbeddedBlockToolbarIcon.js +5 -5
- package/dist/esm/plugins/shared/EmbeddedBlockUtil.js +15 -5
- package/dist/esm/plugins/shared/EmbeddedInlineToolbarIcon.js +5 -5
- package/dist/esm/plugins/shared/EmbeddedInlineUtil.js +8 -4
- package/dist/esm/plugins/shared/FetchingWrappedAssetCard.js +8 -8
- package/dist/esm/plugins/shared/FetchingWrappedEntryCard.js +9 -9
- package/dist/esm/plugins/shared/FetchingWrappedResourceCard.js +9 -8
- package/dist/esm/plugins/shared/LinkedBlockWrapper.js +7 -3
- package/dist/esm/plugins/shared/LinkedInlineWrapper.js +5 -3
- package/dist/esm/plugins/shared/ResourceNewBadge.js +1 -1
- package/dist/esm/plugins/shared/ToolbarButton.js +3 -3
- package/dist/esm/plugins/shared/__tests__/FetchingWrappedAssetCard.test.js +5 -2
- package/dist/esm/plugins/shared/__tests__/FetchingWrappedEntryCard.test.js +5 -2
- package/dist/esm/plugins/shared/__tests__/FetchingWrappedResourceCard.test.js +8 -8
- package/dist/esm/plugins/shared/utils.js +9 -0
- package/dist/esm/test-utils/assertOutput.js +1 -0
- package/dist/esm/test-utils/hyperscript.d.js +1 -0
- package/dist/esm/test-utils/jsx.js +5 -1
- package/dist/esm/test-utils/randomId.js +3 -1
- package/dist/esm/test-utils/setEmptyDataAttribute.js +4 -1
- package/dist/esm/test-utils/validation.js +7 -4
- package/dist/types/plugins/Hyperlink/utils.d.ts +0 -1
- package/dist/types/plugins/shared/utils.d.ts +1 -0
- package/package.json +2 -2
|
@@ -13,11 +13,11 @@ export function ToolbarQuoteButton(props) {
|
|
|
13
13
|
focus(editor);
|
|
14
14
|
}
|
|
15
15
|
if (!editor) return null;
|
|
16
|
-
return React.createElement(ToolbarButton, {
|
|
16
|
+
return /*#__PURE__*/ React.createElement(ToolbarButton, {
|
|
17
17
|
title: "Blockquote",
|
|
18
18
|
onClick: handleOnClick,
|
|
19
19
|
testId: "quote-toolbar-button",
|
|
20
20
|
isDisabled: props.isDisabled,
|
|
21
21
|
isActive: isBlockSelected(editor, BLOCKS.QUOTE)
|
|
22
|
-
}, React.createElement(QuoteIcon, null));
|
|
22
|
+
}, /*#__PURE__*/ React.createElement(QuoteIcon, null));
|
|
23
23
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { BLOCKS, TEXT_CONTAINERS } from '@contentful/rich-text-types';
|
|
2
2
|
import { isLastChild, hasSingleChild } from '@udecode/plate-common';
|
|
3
3
|
import { getAboveNode, getBlockAbove, isAncestorEmpty } from '../../internal/queries';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Returns true if we are:
|
|
6
|
+
* 1) Inside a blockquote
|
|
7
|
+
* 2) With no only one child paragraph/heading and
|
|
8
|
+
* 3) that child is empty
|
|
9
|
+
*/ export const shouldResetQuoteOnBackspace = (editor)=>{
|
|
5
10
|
const container = getAboveNode(editor, {
|
|
6
11
|
match: {
|
|
7
12
|
type: TEXT_CONTAINERS
|
|
@@ -25,7 +25,7 @@ export function toggleQuote(editor, logAction) {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
export const onKeyDownToggleQuote = (editor, plugin)=>(event)=>{
|
|
28
|
-
const { hotkey
|
|
28
|
+
const { hotkey } = plugin.options;
|
|
29
29
|
if (hotkey && isHotkey(hotkey, event)) {
|
|
30
30
|
event.preventDefault();
|
|
31
31
|
toggleQuote(editor, editor.tracking.onShortcutAction);
|
|
@@ -3,7 +3,7 @@ import { Element, Point } from 'slate';
|
|
|
3
3
|
import { getAboveNode, getText } from '../../internal/queries';
|
|
4
4
|
import { deleteText, insertNodes } from '../../internal/transforms';
|
|
5
5
|
export const withQuote = (editor)=>{
|
|
6
|
-
const { insertFragment
|
|
6
|
+
const { insertFragment } = editor;
|
|
7
7
|
editor.insertFragment = (fragment)=>{
|
|
8
8
|
const startingNode = fragment.length && fragment[0];
|
|
9
9
|
const startsWithBlockquote = Element.isElement(startingNode) && startingNode.type === BLOCKS.QUOTE;
|
|
@@ -14,13 +14,15 @@ export const withQuote = (editor)=>{
|
|
|
14
14
|
});
|
|
15
15
|
const containerIsNotEmpty = containerEntry && getText(editor, containerEntry[1]) !== '';
|
|
16
16
|
if (startsWithBlockquote && containerIsNotEmpty) {
|
|
17
|
-
const { selection
|
|
17
|
+
const { selection } = editor;
|
|
18
18
|
const isContentSelected = (selection)=>!!selection && Point.compare(selection.anchor, selection.focus) !== 0;
|
|
19
|
+
// if something is selected (highlighted) we replace the selection
|
|
19
20
|
if (isContentSelected(selection)) {
|
|
20
21
|
deleteText(editor, {
|
|
21
22
|
at: selection
|
|
22
23
|
});
|
|
23
24
|
}
|
|
25
|
+
// get the cursor entry again, it may be different after deletion
|
|
24
26
|
const containerEntry = getAboveNode(editor, {
|
|
25
27
|
match: {
|
|
26
28
|
type: TEXT_CONTAINERS
|
|
@@ -3,6 +3,7 @@ import { createSelectOnBackspacePlugin as createDefaultSelectPlugin } from '@ude
|
|
|
3
3
|
export const createSelectOnBackspacePlugin = ()=>createDefaultSelectPlugin({
|
|
4
4
|
options: {
|
|
5
5
|
query: {
|
|
6
|
+
// `createTextPlugin` is taking care of block elements
|
|
6
7
|
allow: [
|
|
7
8
|
INLINES.EMBEDDED_ENTRY
|
|
8
9
|
]
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { assertOutput, jsx } from '../../../test-utils';
|
|
1
|
+
/* eslint-disable react/no-unknown-property */ /** @jsx jsx */ import { assertOutput, jsx } from '../../../test-utils';
|
|
2
2
|
describe('normalization', ()=>{
|
|
3
3
|
describe('Table', ()=>{
|
|
4
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)));
|
|
5
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("htable", null));
|
|
6
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("text", null)));
|
|
7
7
|
assertOutput({
|
|
8
8
|
input,
|
|
9
9
|
expected
|
|
10
10
|
});
|
|
11
11
|
});
|
|
12
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)));
|
|
13
|
+
const table = /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "Cell 1")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "Cell 2"))));
|
|
14
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hp", null, "hello", table), /*#__PURE__*/ jsx("hquote", null, /*#__PURE__*/ jsx("hp", null, "quote", table)), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "item", table))), /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell with table: ", table)))));
|
|
15
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hp", null, "hello"), table, /*#__PURE__*/ jsx("hquote", null, /*#__PURE__*/ jsx("hp", null, "quote")), table, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "item"))), table, /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell with table: "), /*#__PURE__*/ jsx("hp", null, "Cell 1"), /*#__PURE__*/ jsx("hp", null, "Cell 2")))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
16
16
|
assertOutput({
|
|
17
17
|
input,
|
|
18
18
|
expected
|
|
19
19
|
});
|
|
20
20
|
});
|
|
21
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)));
|
|
22
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "Cell 1")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "Cell 2"))), /*#__PURE__*/ jsx("htd", null, "invalid cell"), "invalid text"), /*#__PURE__*/ jsx("hp", null));
|
|
23
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "Cell 1")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "Cell 2")))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
24
24
|
assertOutput({
|
|
25
25
|
input,
|
|
26
26
|
expected
|
|
@@ -29,22 +29,22 @@ describe('normalization', ()=>{
|
|
|
29
29
|
});
|
|
30
30
|
describe('Table cell', ()=>{
|
|
31
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", {
|
|
32
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "Cell 1")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "Cell 2"), /*#__PURE__*/ jsx("hquote", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", {
|
|
33
33
|
bold: true,
|
|
34
34
|
italic: true,
|
|
35
35
|
underline: true
|
|
36
|
-
}, "quote"), jsx("hinline", {
|
|
36
|
+
}, "quote"), /*#__PURE__*/ jsx("hinline", {
|
|
37
37
|
type: "Entry",
|
|
38
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", {
|
|
39
|
+
})))))), /*#__PURE__*/ jsx("hp", null));
|
|
40
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "Cell 1")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "Cell 2"), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", {
|
|
41
41
|
bold: true,
|
|
42
42
|
italic: true,
|
|
43
43
|
underline: true
|
|
44
|
-
}, "quote"), jsx("hinline", {
|
|
44
|
+
}, "quote"), /*#__PURE__*/ jsx("hinline", {
|
|
45
45
|
type: "Entry",
|
|
46
46
|
id: "entry-id"
|
|
47
|
-
}), jsx("htext", null))))), jsx("hp", null, jsx("htext", null)));
|
|
47
|
+
}), /*#__PURE__*/ jsx("htext", null))))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
48
48
|
assertOutput({
|
|
49
49
|
input,
|
|
50
50
|
expected
|
|
@@ -53,32 +53,32 @@ describe('normalization', ()=>{
|
|
|
53
53
|
});
|
|
54
54
|
describe('Table row', ()=>{
|
|
55
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)));
|
|
56
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell"))));
|
|
57
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell")))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("text", null)));
|
|
58
58
|
assertOutput({
|
|
59
59
|
input,
|
|
60
60
|
expected
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
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)));
|
|
64
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("htr", null));
|
|
65
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("text", null)));
|
|
66
66
|
assertOutput({
|
|
67
67
|
input,
|
|
68
68
|
expected
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
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)));
|
|
72
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 1")), /*#__PURE__*/ jsx("hp", null, "cell 2"))));
|
|
73
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 1")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 2")))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("text", null)));
|
|
74
74
|
assertOutput({
|
|
75
75
|
input,
|
|
76
76
|
expected
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
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)));
|
|
80
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 1"))), /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 2")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 3")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 4"))), /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 5")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 6")))));
|
|
81
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 1")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("text", null))), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("text", null)))), /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 2")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 3")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 4"))), /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 5")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 6")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("text", null))))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("text", null)));
|
|
82
82
|
assertOutput({
|
|
83
83
|
input,
|
|
84
84
|
expected
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { jsx, assertOutput, createTestEditor } from '../../../test-utils';
|
|
1
|
+
/** @jsx jsx */ import { jsx, assertOutput, createTestEditor } from '../../../test-utils';
|
|
2
2
|
import { insertTableAndFocusFirstCell } from '../helpers';
|
|
3
3
|
test('insertTableAndFocusFirstCell', ()=>{
|
|
4
|
-
const input = jsx("editor", null, jsx("hp", null, jsx("htext", null), jsx("cursor", null)), jsx("hp", null));
|
|
5
|
-
const { editor
|
|
4
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null), /*#__PURE__*/ jsx("cursor", null)), /*#__PURE__*/ jsx("hp", null));
|
|
5
|
+
const { editor } = createTestEditor({
|
|
6
6
|
input
|
|
7
7
|
});
|
|
8
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)));
|
|
9
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("hth", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null), /*#__PURE__*/ jsx("cursor", null))), /*#__PURE__*/ jsx("hth", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)))), /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null))), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null))))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
10
10
|
assertOutput({
|
|
11
11
|
input,
|
|
12
12
|
expected
|
|
@@ -2,7 +2,7 @@ import { BLOCKS } from '@contentful/rich-text-types';
|
|
|
2
2
|
import { getEmptyCellNode } from '@udecode/plate-table';
|
|
3
3
|
import { getAboveNode, getNextPath, someNode } from '../../../internal/queries';
|
|
4
4
|
import { insertNodes } from '../../../internal/transforms';
|
|
5
|
-
const addColumn = (editor, { header
|
|
5
|
+
const addColumn = (editor, { header }, getNextCellPath)=>{
|
|
6
6
|
if (someNode(editor, {
|
|
7
7
|
match: {
|
|
8
8
|
type: BLOCKS.TABLE
|
|
@@ -31,6 +31,7 @@ const addColumn = (editor, { header }, getNextCellPath)=>{
|
|
|
31
31
|
header: header && rowIdx === 0
|
|
32
32
|
}), {
|
|
33
33
|
at: newCellPath,
|
|
34
|
+
// Select the first cell of the new column
|
|
34
35
|
select: rowIdx === 0
|
|
35
36
|
});
|
|
36
37
|
});
|
|
@@ -21,8 +21,10 @@ const addRow = (editor, getNextRowPath)=>{
|
|
|
21
21
|
colCount: currentRowElem.children.length
|
|
22
22
|
}), {
|
|
23
23
|
at: nextRowPath,
|
|
24
|
+
// Note: this selects the last cell of the new row
|
|
24
25
|
select: true
|
|
25
26
|
});
|
|
27
|
+
// Select the first cell in the current row
|
|
26
28
|
select(editor, getStartPoint(editor, nextRowPath));
|
|
27
29
|
}
|
|
28
30
|
}
|
|
@@ -34,6 +36,7 @@ export const addRowBelow = (editor)=>{
|
|
|
34
36
|
};
|
|
35
37
|
export const addRowAbove = (editor)=>{
|
|
36
38
|
addRow(editor, (currentRowPath)=>{
|
|
39
|
+
// The new row will be in in-place of the old row
|
|
37
40
|
return currentRowPath;
|
|
38
41
|
});
|
|
39
42
|
};
|
|
@@ -17,9 +17,9 @@ const style = css`
|
|
|
17
17
|
`;
|
|
18
18
|
export const Cell = (props)=>{
|
|
19
19
|
const isSelected = useSelected();
|
|
20
|
-
return React.createElement("td", {
|
|
20
|
+
return /*#__PURE__*/ React.createElement("td", {
|
|
21
21
|
...props.attributes,
|
|
22
22
|
...props.element.data,
|
|
23
23
|
className: style
|
|
24
|
-
}, isSelected && React.createElement(TableActions, null), props.children);
|
|
24
|
+
}, isSelected && /*#__PURE__*/ React.createElement(TableActions, null), props.children);
|
|
25
25
|
};
|
|
@@ -20,9 +20,9 @@ const style = css`
|
|
|
20
20
|
`;
|
|
21
21
|
export const HeaderCell = (props)=>{
|
|
22
22
|
const isSelected = useSelected();
|
|
23
|
-
return React.createElement("th", {
|
|
23
|
+
return /*#__PURE__*/ React.createElement("th", {
|
|
24
24
|
...props.attributes,
|
|
25
25
|
...props.element.data,
|
|
26
26
|
className: style
|
|
27
|
-
}, isSelected && React.createElement(TableActions, null), props.children);
|
|
27
|
+
}, isSelected && /*#__PURE__*/ React.createElement(TableActions, null), props.children);
|
|
28
28
|
};
|
|
@@ -9,7 +9,7 @@ const style = css`
|
|
|
9
9
|
background-color: transparent !important;
|
|
10
10
|
}
|
|
11
11
|
`;
|
|
12
|
-
export const Row = (props)
|
|
12
|
+
export const Row = (props)=>/*#__PURE__*/ React.createElement("tr", {
|
|
13
13
|
...props.attributes,
|
|
14
14
|
className: style
|
|
15
15
|
}, props.children);
|
|
@@ -13,10 +13,10 @@ const style = css`
|
|
|
13
13
|
overflow: hidden;
|
|
14
14
|
`;
|
|
15
15
|
export const Table = (props)=>{
|
|
16
|
-
return React.createElement("div", {
|
|
16
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
17
17
|
"data-block-type": BLOCKS.TABLE
|
|
18
|
-
}, React.createElement("table", {
|
|
18
|
+
}, /*#__PURE__*/ React.createElement("table", {
|
|
19
19
|
className: style,
|
|
20
20
|
...props.attributes
|
|
21
|
-
}, React.createElement("tbody", null, props.children)));
|
|
21
|
+
}, /*#__PURE__*/ React.createElement("tbody", null, props.children)));
|
|
22
22
|
};
|
|
@@ -70,6 +70,7 @@ export const TableActions = ()=>{
|
|
|
70
70
|
header: isHeaderEnabled
|
|
71
71
|
});
|
|
72
72
|
});
|
|
73
|
+
// Tracking
|
|
73
74
|
const actionName = `${type}Table${element === 'Table' ? '' : element}`;
|
|
74
75
|
editor.tracking.onViewportAction(actionName, {
|
|
75
76
|
tableSize
|
|
@@ -82,37 +83,37 @@ export const TableActions = ()=>{
|
|
|
82
83
|
if (isDisabled) {
|
|
83
84
|
return null;
|
|
84
85
|
}
|
|
85
|
-
return React.createElement(Menu, {
|
|
86
|
+
return /*#__PURE__*/ React.createElement(Menu, {
|
|
86
87
|
placement: "left",
|
|
87
88
|
isOpen: isOpen,
|
|
88
89
|
onOpen: ()=>{
|
|
89
90
|
setOpen(true);
|
|
90
91
|
},
|
|
91
92
|
onClose: close
|
|
92
|
-
}, React.createElement(Menu.Trigger, null, React.createElement(IconButton, {
|
|
93
|
+
}, /*#__PURE__*/ React.createElement(Menu.Trigger, null, /*#__PURE__*/ React.createElement(IconButton, {
|
|
93
94
|
size: "small",
|
|
94
95
|
variant: "transparent",
|
|
95
96
|
tabIndex: -1,
|
|
96
97
|
className: styles.topRight,
|
|
97
|
-
icon: React.createElement(ChevronDownIcon, null),
|
|
98
|
+
icon: /*#__PURE__*/ React.createElement(ChevronDownIcon, null),
|
|
98
99
|
"aria-label": "Open table menu",
|
|
99
100
|
testId: "cf-table-actions-button"
|
|
100
|
-
})), React.createElement(Menu.List, null, React.createElement(Menu.Item, {
|
|
101
|
+
})), /*#__PURE__*/ React.createElement(Menu.List, null, /*#__PURE__*/ React.createElement(Menu.Item, {
|
|
101
102
|
onClick: action(addRowAbove, 'insert', 'Row'),
|
|
102
103
|
disabled: !canInsertRowAbove
|
|
103
|
-
}, "Add row above"), React.createElement(Menu.Item, {
|
|
104
|
+
}, "Add row above"), /*#__PURE__*/ React.createElement(Menu.Item, {
|
|
104
105
|
onClick: action(addRowBelow, 'insert', 'Row')
|
|
105
|
-
}, "Add row below"), React.createElement(Menu.Item, {
|
|
106
|
+
}, "Add row below"), /*#__PURE__*/ React.createElement(Menu.Item, {
|
|
106
107
|
onClick: action(addColumnLeft, 'insert', 'Column')
|
|
107
|
-
}, "Add column left"), React.createElement(Menu.Item, {
|
|
108
|
+
}, "Add column left"), /*#__PURE__*/ React.createElement(Menu.Item, {
|
|
108
109
|
onClick: action(addColumnRight, 'insert', 'Column')
|
|
109
|
-
}, "Add column right"), React.createElement(Menu.Divider, null), React.createElement(Menu.Item, {
|
|
110
|
+
}, "Add column right"), /*#__PURE__*/ React.createElement(Menu.Divider, null), /*#__PURE__*/ React.createElement(Menu.Item, {
|
|
110
111
|
onClick: toggleHeader
|
|
111
|
-
}, isHeaderEnabled ? 'Disable table header' : 'Enable table header'), React.createElement(Menu.Divider, null), React.createElement(Menu.Item, {
|
|
112
|
+
}, isHeaderEnabled ? 'Disable table header' : 'Enable table header'), /*#__PURE__*/ React.createElement(Menu.Divider, null), /*#__PURE__*/ React.createElement(Menu.Item, {
|
|
112
113
|
onClick: action(deleteRow, 'remove', 'Row')
|
|
113
|
-
}, "Delete row"), React.createElement(Menu.Item, {
|
|
114
|
+
}, "Delete row"), /*#__PURE__*/ React.createElement(Menu.Item, {
|
|
114
115
|
onClick: action(deleteColumn, 'remove', 'Column')
|
|
115
|
-
}, "Delete column"), React.createElement(Menu.Item, {
|
|
116
|
+
}, "Delete column"), /*#__PURE__*/ React.createElement(Menu.Item, {
|
|
116
117
|
onClick: action(deleteTable, 'remove', 'Table')
|
|
117
118
|
}, "Delete table")));
|
|
118
119
|
};
|
|
@@ -14,11 +14,12 @@ export function ToolbarTableButton(props) {
|
|
|
14
14
|
focus(editor);
|
|
15
15
|
}
|
|
16
16
|
if (!editor) return null;
|
|
17
|
-
return React.createElement(ToolbarButton, {
|
|
17
|
+
return /*#__PURE__*/ React.createElement(ToolbarButton, {
|
|
18
18
|
title: "Table",
|
|
19
19
|
testId: "table-toolbar-button",
|
|
20
20
|
onClick: handleClick,
|
|
21
|
+
// TODO: active state looks off since the button will be disabled. Do we still need it?
|
|
21
22
|
isActive: !!isActive,
|
|
22
23
|
isDisabled: props.isDisabled
|
|
23
|
-
}, React.createElement(TableIcon, null));
|
|
24
|
+
}, /*#__PURE__*/ React.createElement(TableIcon, null));
|
|
24
25
|
}
|
|
@@ -15,11 +15,15 @@ import { addTableTrackingEvents, withInvalidCellChildrenTracking } from './table
|
|
|
15
15
|
export const createTablePlugin = ()=>createDefaultTablePlugin({
|
|
16
16
|
type: BLOCKS.TABLE,
|
|
17
17
|
handlers: {
|
|
18
|
+
// @ts-expect-error
|
|
18
19
|
onKeyDown: onKeyDownTable
|
|
19
20
|
},
|
|
20
21
|
withOverrides: (editor, plugin)=>{
|
|
21
|
-
const { normalizeNode
|
|
22
|
+
const { normalizeNode } = editor;
|
|
23
|
+
// injects important fixes from plate's original table plugin
|
|
22
24
|
withTable(editor, plugin);
|
|
25
|
+
// Resets all normalization rules added by @udecode/plate-table as
|
|
26
|
+
// they conflict with our own
|
|
23
27
|
editor.normalizeNode = normalizeNode;
|
|
24
28
|
addTableTrackingEvents(editor);
|
|
25
29
|
editor.insertFragment = insertTableFragment(editor);
|
|
@@ -34,7 +38,10 @@ export const createTablePlugin = ()=>createDefaultTablePlugin({
|
|
|
34
38
|
validNode: isNotEmpty
|
|
35
39
|
},
|
|
36
40
|
{
|
|
41
|
+
// Move to root level unless nested
|
|
37
42
|
validNode: (editor, [, path])=>{
|
|
43
|
+
// Nested tables are handled by another normalization
|
|
44
|
+
// rule in a the table cell level
|
|
38
45
|
const isNestedTable = !!getBlockAbove(editor, {
|
|
39
46
|
at: path,
|
|
40
47
|
match: {
|
|
@@ -62,9 +69,11 @@ export const createTablePlugin = ()=>createDefaultTablePlugin({
|
|
|
62
69
|
transform: transformWrapIn(BLOCKS.TABLE_CELL)
|
|
63
70
|
},
|
|
64
71
|
{
|
|
72
|
+
// Remove empty rows
|
|
65
73
|
validNode: isNotEmpty
|
|
66
74
|
},
|
|
67
75
|
{
|
|
76
|
+
// Parent must be a table
|
|
68
77
|
validNode: (editor, [, path])=>{
|
|
69
78
|
const parent = getParentNode(editor, path)?.[0];
|
|
70
79
|
return parent && parent.type === BLOCKS.TABLE;
|
|
@@ -72,6 +81,7 @@ export const createTablePlugin = ()=>createDefaultTablePlugin({
|
|
|
72
81
|
transform: transformWrapIn(BLOCKS.TABLE)
|
|
73
82
|
},
|
|
74
83
|
{
|
|
84
|
+
// ensure consistent number of cells in each row
|
|
75
85
|
validNode: (editor, entry)=>{
|
|
76
86
|
return getNoOfMissingTableCellsInRow(editor, entry) === 0;
|
|
77
87
|
},
|
|
@@ -71,21 +71,30 @@ export function replaceEmptyParagraphWithTable(editor) {
|
|
|
71
71
|
const [previousNode] = nodes;
|
|
72
72
|
const isPreviousNodeTextEmpty = isAncestorEmpty(editor, previousNode);
|
|
73
73
|
if (isPreviousNodeTextEmpty) {
|
|
74
|
+
// Switch table with previous empty paragraph
|
|
74
75
|
moveNodes(editor, {
|
|
75
76
|
at: tablePath,
|
|
76
77
|
to: previousPath
|
|
77
78
|
});
|
|
79
|
+
// Remove previous paragraph that now is under the table
|
|
78
80
|
removeNodes(editor, {
|
|
79
81
|
at: tablePath
|
|
80
82
|
});
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Returns the number of cells in a given row vs the table width
|
|
87
|
+
*
|
|
88
|
+
* Note: We should only get different table rows cell counts in between
|
|
89
|
+
* normalization cycles.
|
|
90
|
+
*/ export const getNoOfMissingTableCellsInRow = (editor, rowEntry)=>{
|
|
84
91
|
const [, rowPath] = rowEntry;
|
|
85
92
|
const parent = getParentNode(editor, rowPath);
|
|
93
|
+
// This is ensured by normalization. The error is here just in case
|
|
86
94
|
if (!parent) {
|
|
87
95
|
throw new Error('table rows must be wrapped in a table node');
|
|
88
96
|
}
|
|
97
|
+
// The longest table row determines its width
|
|
89
98
|
const tableWidth = Math.max(...getChildren(parent).map((entry)=>getChildren(entry).length));
|
|
90
99
|
const rowWidth = getChildren(rowEntry).length;
|
|
91
100
|
return tableWidth - rowWidth;
|
|
@@ -2,18 +2,29 @@ import { BLOCKS } from '@contentful/rich-text-types';
|
|
|
2
2
|
import { insertEmptyParagraph } from '../../helpers/editor';
|
|
3
3
|
import { getText, isElement } from '../../internal/queries';
|
|
4
4
|
import { isTable } from './helpers';
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Removes table wrappers when pasting a single table cell
|
|
7
|
+
*
|
|
8
|
+
* In Plate/Slate, copying the content of a table cell wraps
|
|
9
|
+
* it in a <table><tr><td>{content}</td></tr></table> even
|
|
10
|
+
* when copying partial cell content.
|
|
11
|
+
*
|
|
12
|
+
* That's really annoying as there is no way to remove the table
|
|
13
|
+
* wrappers in that case.
|
|
14
|
+
*/ const trimUnnecessaryTableWrapper = (node)=>{
|
|
6
15
|
if (!isElement(node)) {
|
|
7
16
|
return [
|
|
8
17
|
node
|
|
9
18
|
];
|
|
10
19
|
}
|
|
20
|
+
// must be a table with a single row
|
|
11
21
|
if (node.type !== BLOCKS.TABLE || node.children?.length !== 1) {
|
|
12
22
|
return [
|
|
13
23
|
node
|
|
14
24
|
];
|
|
15
25
|
}
|
|
16
26
|
const row = node.children[0];
|
|
27
|
+
// the row must contain a single cell
|
|
17
28
|
if (row?.children?.length !== 1) {
|
|
18
29
|
return [
|
|
19
30
|
node
|
|
@@ -23,12 +34,14 @@ const trimUnnecessaryTableWrapper = (node)=>{
|
|
|
23
34
|
return cell.children;
|
|
24
35
|
};
|
|
25
36
|
export const insertTableFragment = (editor)=>{
|
|
26
|
-
const { insertFragment
|
|
37
|
+
const { insertFragment } = editor;
|
|
27
38
|
return (fragments)=>{
|
|
28
39
|
if (!editor.selection) {
|
|
29
40
|
return;
|
|
30
41
|
}
|
|
31
42
|
fragments = fragments.flatMap(trimUnnecessaryTableWrapper);
|
|
43
|
+
// We need to make sure we have a new, empty and clean paragraph in order to paste tables as-is due to how Slate behaves
|
|
44
|
+
// More info: https://github.com/ianstormtaylor/slate/pull/4489 and https://github.com/ianstormtaylor/slate/issues/4542
|
|
32
45
|
const isInsertingTable = fragments.some((fragment)=>isTable(fragment));
|
|
33
46
|
const isTableFirstFragment = fragments.findIndex((fragment)=>isTable(fragment)) === 0;
|
|
34
47
|
const currentLineHasText = getText(editor, editor.selection?.focus.path) !== '';
|
|
@@ -7,8 +7,12 @@ import { addRowBelow } from './actions';
|
|
|
7
7
|
export const onKeyDownTable = (editor, plugin)=>{
|
|
8
8
|
const defaultHandler = defaultKeyDownTable(editor, plugin);
|
|
9
9
|
return (event)=>{
|
|
10
|
+
// This fixes `Cannot resolve a Slate point from DOM point:
|
|
11
|
+
// [object HTMLDivElement]` when typing while the cursor is before table
|
|
10
12
|
const windowSelection = window.getSelection();
|
|
11
13
|
if (windowSelection) {
|
|
14
|
+
// @ts-expect-error
|
|
15
|
+
// this attribute comes from `plugins/Table/components/Table.tsx`
|
|
12
16
|
const blockType = windowSelection.anchorNode.attributes?.['data-block-type']?.value;
|
|
13
17
|
const isBeforeTable = blockType === BLOCKS.TABLE;
|
|
14
18
|
if (isBeforeTable) {
|
|
@@ -30,10 +34,11 @@ export const onKeyDownTable = (editor, plugin)=>{
|
|
|
30
34
|
return;
|
|
31
35
|
}
|
|
32
36
|
}
|
|
37
|
+
// TODO clean this up
|
|
33
38
|
if (event.key === 'Backspace') {
|
|
34
39
|
const entry = getTableEntries(editor, {});
|
|
35
40
|
if (entry) {
|
|
36
|
-
const { table
|
|
41
|
+
const { table, row, cell } = entry;
|
|
37
42
|
const cellText = getText(editor, cell[1]);
|
|
38
43
|
const isFirstCell = isFirstChild(row[1]);
|
|
39
44
|
const isFirstRow = isFirstChild(table[1]);
|
|
@@ -44,15 +49,18 @@ export const onKeyDownTable = (editor, plugin)=>{
|
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
51
|
}
|
|
52
|
+
// Pressing Tab on the last cell creates a new row
|
|
53
|
+
// Otherwise, jumping between cells is handled in the defaultKeyDownTable
|
|
47
54
|
if (event.key === 'Tab' && !event.shiftKey) {
|
|
48
55
|
event.preventDefault();
|
|
49
56
|
const entry = getTableEntries(editor, {});
|
|
50
57
|
if (entry) {
|
|
51
|
-
const { table
|
|
58
|
+
const { table, row, cell } = entry;
|
|
52
59
|
const isLastCell = isLastChildPath(row, cell[1]);
|
|
53
60
|
const isLastRow = isLastChildPath(table, row[1]);
|
|
54
61
|
if (isLastRow && isLastCell) {
|
|
55
62
|
addRowBelow(editor);
|
|
63
|
+
// skip default handler
|
|
56
64
|
return;
|
|
57
65
|
} else {
|
|
58
66
|
defaultHandler(event);
|
|
@@ -2,22 +2,22 @@ import { BLOCKS } from '@contentful/rich-text-types';
|
|
|
2
2
|
import { isElement } from '../../internal/queries';
|
|
3
3
|
import { getPastingSource } from '../../plugins/Tracking';
|
|
4
4
|
function hasTables(nodes) {
|
|
5
|
-
return nodes.some(({ type
|
|
5
|
+
return nodes.some(({ type })=>{
|
|
6
6
|
return type === BLOCKS.TABLE;
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
|
-
const isTableHeaderCell = ({ type
|
|
9
|
+
const isTableHeaderCell = ({ type })=>type === BLOCKS.TABLE_HEADER_CELL;
|
|
10
10
|
function hasHeadersOutsideFirstRow(nodes) {
|
|
11
|
-
return nodes.filter(({ type
|
|
11
|
+
return nodes.filter(({ type })=>type === BLOCKS.TABLE).flatMap(({ children })=>children.slice(1)).some(({ children })=>children.some(isTableHeaderCell));
|
|
12
12
|
}
|
|
13
13
|
export function addTableTrackingEvents(editor) {
|
|
14
|
-
const { insertData
|
|
14
|
+
const { insertData } = editor;
|
|
15
15
|
editor.insertData = (data)=>{
|
|
16
16
|
const html = data.getData('text/html');
|
|
17
17
|
if (html) {
|
|
18
|
-
const { children: markupBefore
|
|
18
|
+
const { children: markupBefore } = editor;
|
|
19
19
|
insertData(data);
|
|
20
|
-
const { children: markupAfter
|
|
20
|
+
const { children: markupAfter } = editor;
|
|
21
21
|
setTimeout(()=>{
|
|
22
22
|
if (hasTables(markupBefore)) return;
|
|
23
23
|
if (hasTables(markupAfter)) {
|