@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { entityHelpers } from '@contentful/field-editor-shared';
|
|
3
3
|
import { getEntityInfo } from './utils';
|
|
4
|
-
async function fetchAllData({ sdk
|
|
4
|
+
async function fetchAllData({ sdk, entityId, entityType, localeCode, defaultLocaleCode }) {
|
|
5
5
|
let contentType;
|
|
6
6
|
const getEntity = entityType === 'Entry' ? sdk.space.getEntry : sdk.space.getAsset;
|
|
7
7
|
const entity = await getEntity(entityId);
|
|
@@ -10,6 +10,7 @@ async function fetchAllData({ sdk , entityId , entityType , localeCode , default
|
|
|
10
10
|
contentType = sdk.space.getCachedContentTypes().find((ct)=>ct.sys.id === contentTypeId);
|
|
11
11
|
}
|
|
12
12
|
const entityTitle = entityType === 'Entry' ? entityHelpers.getEntryTitle({
|
|
13
|
+
//@ts-expect-error
|
|
13
14
|
entry: entity,
|
|
14
15
|
contentType,
|
|
15
16
|
localeCode,
|
|
@@ -22,12 +23,14 @@ async function fetchAllData({ sdk , entityId , entityType , localeCode , default
|
|
|
22
23
|
defaultTitle: 'Untitled'
|
|
23
24
|
});
|
|
24
25
|
const entityDescription = entityHelpers.getEntityDescription({
|
|
26
|
+
// @ts-expect-error
|
|
25
27
|
entity,
|
|
26
28
|
contentType,
|
|
27
29
|
localeCode,
|
|
28
30
|
defaultLocaleCode
|
|
29
31
|
});
|
|
30
32
|
const jobs = await sdk.space.getEntityScheduledActions(entityType, entityId);
|
|
33
|
+
// @ts-expect-error
|
|
31
34
|
const entityStatus = entityHelpers.getEntryStatus(entity.sys);
|
|
32
35
|
return {
|
|
33
36
|
jobs,
|
|
@@ -38,7 +41,7 @@ async function fetchAllData({ sdk , entityId , entityType , localeCode , default
|
|
|
38
41
|
contentTypeName: contentType ? contentType.name : ''
|
|
39
42
|
};
|
|
40
43
|
}
|
|
41
|
-
function useRequestStatus({ sdk
|
|
44
|
+
function useRequestStatus({ sdk, target, onEntityFetchComplete }) {
|
|
42
45
|
const [requestStatus, setRequestStatus] = useState({
|
|
43
46
|
type: 'loading'
|
|
44
47
|
});
|
|
@@ -74,7 +77,7 @@ function useRequestStatus({ sdk , target , onEntityFetchComplete }) {
|
|
|
74
77
|
}
|
|
75
78
|
export function useEntityInfo(props) {
|
|
76
79
|
const status = useRequestStatus(props);
|
|
77
|
-
const { linkType
|
|
80
|
+
const { linkType } = props.target.sys;
|
|
78
81
|
if (status.type === 'loading') {
|
|
79
82
|
return `Loading ${linkType.toLowerCase()}...`;
|
|
80
83
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useResource } from '@contentful/field-editor-reference';
|
|
3
|
-
import { truncateTitle } from '
|
|
4
|
-
export function useResourceEntityInfo({ onEntityFetchComplete
|
|
5
|
-
const { data
|
|
3
|
+
import { truncateTitle } from '../../plugins/shared/utils';
|
|
4
|
+
export function useResourceEntityInfo({ onEntityFetchComplete, target }) {
|
|
5
|
+
const { data, error, status } = useResource(target.sys.linkType, target.sys.urn);
|
|
6
6
|
React.useEffect(()=>{
|
|
7
7
|
if (status === 'success') {
|
|
8
8
|
onEntityFetchComplete?.();
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import { getScheduleTooltipContent } from '@contentful/field-editor-reference';
|
|
2
2
|
import { isAncestorEmpty } from '@udecode/plate-common';
|
|
3
3
|
import { getText } from '../../internal/queries';
|
|
4
|
+
import { truncateTitle } from '../../plugins/shared/utils';
|
|
4
5
|
export const hasText = (editor, entry)=>{
|
|
5
6
|
const [node, path] = entry;
|
|
6
7
|
return !isAncestorEmpty(editor, node) && getText(editor, path).trim() !== '';
|
|
7
8
|
};
|
|
8
|
-
export function truncateTitle(str, length) {
|
|
9
|
-
if (typeof str === 'string' && str.length > length) {
|
|
10
|
-
return str && str.substr(0, length + 1).replace(/(\s+\S(?=\S)|\s*)\.?.$/, '…');
|
|
11
|
-
}
|
|
12
|
-
return str;
|
|
13
|
-
}
|
|
14
9
|
export function getEntityInfo(data) {
|
|
15
10
|
if (!data) {
|
|
16
11
|
return '';
|
|
17
12
|
}
|
|
18
|
-
const { entityTitle
|
|
13
|
+
const { entityTitle, contentTypeName, entityStatus, jobs } = data;
|
|
19
14
|
const title = truncateTitle(entityTitle, 60) || 'Untitled';
|
|
20
15
|
const scheduledActions = jobs.length > 0 ? getScheduleTooltipContent({
|
|
21
16
|
job: jobs[0],
|
|
@@ -1,40 +1,40 @@
|
|
|
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
|
it('wraps orphaned list items in a list', ()=>{
|
|
4
|
-
const input = jsx("editor", null, jsx("hli", null, jsx("hp", null, "Item")), jsx("hp", null));
|
|
5
|
-
const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item"))), jsx("hp", null, jsx("htext", null)));
|
|
4
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item")), /*#__PURE__*/ jsx("hp", null));
|
|
5
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item"))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
6
6
|
assertOutput({
|
|
7
7
|
input,
|
|
8
8
|
expected
|
|
9
9
|
});
|
|
10
10
|
});
|
|
11
11
|
it('adds empty paragraph to empty list items', ()=>{
|
|
12
|
-
const input = jsx("editor", null, jsx("hul", null, jsx("hli", null)), jsx("hp", null));
|
|
13
|
-
const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, jsx("htext", null)))), jsx("hp", null, jsx("htext", null)));
|
|
12
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null)), /*#__PURE__*/ jsx("hp", null));
|
|
13
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
14
14
|
assertOutput({
|
|
15
15
|
input,
|
|
16
16
|
expected
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
19
|
it('replaces invalid list items with text', ()=>{
|
|
20
|
-
const input = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item"), jsx("htd", null, jsx("hp", null, jsx("htext", {
|
|
20
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item"), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", {
|
|
21
21
|
bold: true
|
|
22
|
-
}, "bold text"))), jsx("htd", null, jsx("hp", null, "Take a look at this ", jsx("hlink", {
|
|
22
|
+
}, "bold text"))), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "Take a look at this ", /*#__PURE__*/ jsx("hlink", {
|
|
23
23
|
uri: "https://google.com"
|
|
24
|
-
}, "link"))))), jsx("hp", null));
|
|
25
|
-
const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item"), jsx("hp", null, jsx("htext", {
|
|
24
|
+
}, "link"))))), /*#__PURE__*/ jsx("hp", null));
|
|
25
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item"), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", {
|
|
26
26
|
bold: true
|
|
27
|
-
}, "bold text")), jsx("hp", null, "Take a look at this ", jsx("hlink", {
|
|
27
|
+
}, "bold text")), /*#__PURE__*/ jsx("hp", null, "Take a look at this ", /*#__PURE__*/ jsx("hlink", {
|
|
28
28
|
uri: "https://google.com"
|
|
29
|
-
}, "link"), jsx("htext", null)))), jsx("hp", null, jsx("htext", null)));
|
|
29
|
+
}, "link"), /*#__PURE__*/ jsx("htext", null)))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
30
30
|
assertOutput({
|
|
31
31
|
input,
|
|
32
32
|
expected
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
it('replaces list items with nested lists as a first child', ()=>{
|
|
36
|
-
const input = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item 1"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item 1.1")))), jsx("hli", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item 2.1"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item 2.1.1")))), jsx("hli", null, jsx("hp", null, "Item 2.2"))))), jsx("hp", null, jsx("htext", null)));
|
|
37
|
-
const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item 1"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item 1.1")))), jsx("hli", null, jsx("hp", null, "Item 2.1"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item 2.1.1")))), jsx("hli", null, jsx("hp", null, "Item 2.2"))), jsx("hp", null, jsx("htext", null)));
|
|
36
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 1"), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 1.1")))), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 2.1"), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 2.1.1")))), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 2.2"))))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
37
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 1"), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 1.1")))), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 2.1"), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 2.1.1")))), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 2.2"))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
38
38
|
assertOutput({
|
|
39
39
|
input,
|
|
40
40
|
expected
|
|
@@ -1,68 +1,72 @@
|
|
|
1
|
-
import { jsx, assertOutput, createTestEditor } from '../../../test-utils';
|
|
1
|
+
/** @jsx jsx */ import { jsx, assertOutput, createTestEditor } from '../../../test-utils';
|
|
2
2
|
describe('insert line break', ()=>{
|
|
3
3
|
const tests = [
|
|
4
|
+
// single p
|
|
4
5
|
{
|
|
5
6
|
title: 'at the start of a li',
|
|
6
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hp", null, jsx("cursor", null), "p1"))),
|
|
7
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, jsx("cursor", null))), jsx("hli", null, jsx("hp", null, "p1")))
|
|
7
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("cursor", null), "p1"))),
|
|
8
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("cursor", null))), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "p1")))
|
|
8
9
|
},
|
|
9
10
|
{
|
|
10
11
|
title: 'at the end of a li',
|
|
11
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hp", null, "p1", jsx("cursor", null)))),
|
|
12
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, "p1")), jsx("hli", null, jsx("hp", null, jsx("cursor", null))))
|
|
12
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "p1", /*#__PURE__*/ jsx("cursor", null)))),
|
|
13
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "p1")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("cursor", null))))
|
|
13
14
|
},
|
|
14
15
|
{
|
|
15
16
|
title: 'at the middle of a li',
|
|
16
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hp", null, "split ", jsx("cursor", null), "me"))),
|
|
17
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, "split ")), jsx("hli", null, jsx("hp", null, jsx("cursor", null), "me")))
|
|
17
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "split ", /*#__PURE__*/ jsx("cursor", null), "me"))),
|
|
18
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "split ")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("cursor", null), "me")))
|
|
18
19
|
},
|
|
20
|
+
// multi p
|
|
19
21
|
{
|
|
20
22
|
title: 'at the start of a li with multiple p',
|
|
21
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hp", null, jsx("cursor", null), "p1"), jsx("hp", null, "p2"))),
|
|
22
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, jsx("cursor", null))), jsx("hli", null, jsx("hp", null, "p1"), jsx("hp", null, "p2")))
|
|
23
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("cursor", null), "p1"), /*#__PURE__*/ jsx("hp", null, "p2"))),
|
|
24
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("cursor", null))), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "p1"), /*#__PURE__*/ jsx("hp", null, "p2")))
|
|
23
25
|
},
|
|
24
26
|
{
|
|
25
27
|
title: 'at the start of the second p of a li',
|
|
26
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hp", null, "p1"), jsx("hp", null, jsx("cursor", null), "p2"))),
|
|
27
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, "p1")), jsx("hli", null, jsx("hp", null, jsx("cursor", null)), jsx("hp", null, "p2")))
|
|
28
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "p1"), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("cursor", null), "p2"))),
|
|
29
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "p1")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("cursor", null)), /*#__PURE__*/ jsx("hp", null, "p2")))
|
|
28
30
|
},
|
|
29
31
|
{
|
|
30
32
|
title: 'at the end of a li with multiple p',
|
|
31
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hp", null, "p1"), jsx("hp", null, "p2", jsx("cursor", null)))),
|
|
32
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, "p1"), jsx("hp", null, "p2")), jsx("hli", null, jsx("hp", null, jsx("cursor", null))))
|
|
33
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "p1"), /*#__PURE__*/ jsx("hp", null, "p2", /*#__PURE__*/ jsx("cursor", null)))),
|
|
34
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "p1"), /*#__PURE__*/ jsx("hp", null, "p2")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("cursor", null))))
|
|
33
35
|
},
|
|
34
36
|
{
|
|
35
37
|
title: 'at the middle of a li with multiple p',
|
|
36
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hp", null, "split ", jsx("cursor", null), "me"), jsx("hp", null, "move me"))),
|
|
37
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, "split ")), jsx("hli", null, jsx("hp", null, jsx("cursor", null), "me"), jsx("hp", null, "move me")))
|
|
38
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "split ", /*#__PURE__*/ jsx("cursor", null), "me"), /*#__PURE__*/ jsx("hp", null, "move me"))),
|
|
39
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "split ")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("cursor", null), "me"), /*#__PURE__*/ jsx("hp", null, "move me")))
|
|
38
40
|
},
|
|
41
|
+
// with headings
|
|
39
42
|
{
|
|
40
43
|
title: 'at the start of a li with heading',
|
|
41
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hh1", null, jsx("cursor", null), "p1"))),
|
|
42
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, jsx("cursor", null))), jsx("hli", null, jsx("hh1", null, "p1")))
|
|
44
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hh1", null, /*#__PURE__*/ jsx("cursor", null), "p1"))),
|
|
45
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("cursor", null))), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hh1", null, "p1")))
|
|
43
46
|
},
|
|
44
47
|
{
|
|
45
48
|
title: 'at the end of a li with heading',
|
|
46
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hh1", null, "p1", jsx("cursor", null)))),
|
|
47
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hh1", null, "p1")), jsx("hli", null, jsx("hp", null, jsx("cursor", null))))
|
|
49
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hh1", null, "p1", /*#__PURE__*/ jsx("cursor", null)))),
|
|
50
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hh1", null, "p1")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("cursor", null))))
|
|
48
51
|
},
|
|
49
52
|
{
|
|
50
53
|
title: 'at the middle of a li with heading',
|
|
51
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hh1", null, "split ", jsx("cursor", null), "me"))),
|
|
52
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hh1", null, "split ")), jsx("hli", null, jsx("hh1", null, jsx("cursor", null), "me")))
|
|
54
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hh1", null, "split ", /*#__PURE__*/ jsx("cursor", null), "me"))),
|
|
55
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hh1", null, "split ")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hh1", null, /*#__PURE__*/ jsx("cursor", null), "me")))
|
|
53
56
|
},
|
|
54
57
|
{
|
|
55
58
|
title: 'at a li with nested list',
|
|
56
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hp", null, "item 1")), jsx("hli", null, jsx("hp", null, "item 2", jsx("cursor", null)), jsx("hul", null, jsx("hli", null, jsx("hp", null, "sub list"))))),
|
|
57
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, "item 1")), jsx("hli", null, jsx("hp", null, "item 2")), jsx("hli", null, jsx("hp", null, jsx("cursor", null)), jsx("hul", null, jsx("hli", null, jsx("hp", null, "sub list")))))
|
|
59
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "item 1")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "item 2", /*#__PURE__*/ jsx("cursor", null)), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "sub list"))))),
|
|
60
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "item 1")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "item 2")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("cursor", null)), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "sub list")))))
|
|
58
61
|
}
|
|
59
62
|
];
|
|
60
|
-
const render = (children)
|
|
63
|
+
const render = (children)=>/*#__PURE__*/ jsx("editor", null, children, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
61
64
|
for (const t of tests){
|
|
62
65
|
test(t.title, ()=>{
|
|
63
|
-
const { editor
|
|
66
|
+
const { editor } = createTestEditor({
|
|
64
67
|
input: render(t.input)
|
|
65
68
|
});
|
|
69
|
+
// Equivalent of pressing ENTER
|
|
66
70
|
editor.insertBreak();
|
|
67
71
|
assertOutput({
|
|
68
72
|
editor,
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { jsx, assertOutput, createTestEditor } from '../../../test-utils';
|
|
1
|
+
/** @jsx jsx */ import { jsx, assertOutput, createTestEditor } from '../../../test-utils';
|
|
2
2
|
describe('insert fragment', ()=>{
|
|
3
3
|
const tests = [
|
|
4
4
|
{
|
|
5
5
|
title: 'text wrapped in li > p',
|
|
6
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hp", null, "hello ", jsx("cursor", null)))),
|
|
7
|
-
fragment: jsx("fragment", null, jsx("hli", null, jsx("hp", null, "world"))),
|
|
8
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, "hello world")))
|
|
6
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "hello ", /*#__PURE__*/ jsx("cursor", null)))),
|
|
7
|
+
fragment: /*#__PURE__*/ jsx("fragment", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "world"))),
|
|
8
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "hello world")))
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
title: 'text wrapped in li > h*',
|
|
12
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hp", null, "hello ", jsx("cursor", null)))),
|
|
13
|
-
fragment: jsx("fragment", null, jsx("hli", null, jsx("hh1", null, "world"))),
|
|
14
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, "hello world")))
|
|
12
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "hello ", /*#__PURE__*/ jsx("cursor", null)))),
|
|
13
|
+
fragment: /*#__PURE__*/ jsx("fragment", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hh1", null, "world"))),
|
|
14
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "hello world")))
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
title: 'single li with only asset card',
|
|
18
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hp", null, "hello", jsx("cursor", null), "world"))),
|
|
19
|
-
fragment: jsx("fragment", null, jsx("hli", null, jsx("hembed", {
|
|
18
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "hello", /*#__PURE__*/ jsx("cursor", null), "world"))),
|
|
19
|
+
fragment: /*#__PURE__*/ jsx("fragment", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hembed", {
|
|
20
20
|
type: "Asset",
|
|
21
21
|
id: "asset-id"
|
|
22
22
|
}))),
|
|
23
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, "hello"), jsx("hembed", {
|
|
23
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "hello"), /*#__PURE__*/ jsx("hembed", {
|
|
24
24
|
type: "Asset",
|
|
25
25
|
id: "asset-id"
|
|
26
|
-
}), jsx("hp", null, "world")))
|
|
26
|
+
}), /*#__PURE__*/ jsx("hp", null, "world")))
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
29
|
title: 'two paragraphs',
|
|
30
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hp", null, "hello ", jsx("cursor", null)))),
|
|
31
|
-
fragment: jsx("fragment", null, jsx("hp", null, "world"), jsx("hp", null, "line 2")),
|
|
32
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, "hello world"), jsx("hp", null, "line 2")))
|
|
30
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "hello ", /*#__PURE__*/ jsx("cursor", null)))),
|
|
31
|
+
fragment: /*#__PURE__*/ jsx("fragment", null, /*#__PURE__*/ jsx("hp", null, "world"), /*#__PURE__*/ jsx("hp", null, "line 2")),
|
|
32
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "hello world"), /*#__PURE__*/ jsx("hp", null, "line 2")))
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
title: 'two headings',
|
|
36
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hp", null, "hello ", jsx("cursor", null)))),
|
|
37
|
-
fragment: jsx("fragment", null, jsx("hh1", null, "world"), jsx("hh1", null, "line 2")),
|
|
38
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, "hello world"), jsx("hh1", null, "line 2")))
|
|
36
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "hello ", /*#__PURE__*/ jsx("cursor", null)))),
|
|
37
|
+
fragment: /*#__PURE__*/ jsx("fragment", null, /*#__PURE__*/ jsx("hh1", null, "world"), /*#__PURE__*/ jsx("hh1", null, "line 2")),
|
|
38
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "hello world"), /*#__PURE__*/ jsx("hh1", null, "line 2")))
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
41
|
title: 'two paragraphs wrapped in a li',
|
|
42
|
-
input: jsx("hul", null, jsx("hli", null, jsx("hp", null, "hello ", jsx("cursor", null)))),
|
|
43
|
-
fragment: jsx("fragment", null, jsx("hli", null, jsx("hp", null, "world"), jsx("hp", null, "line 2"))),
|
|
44
|
-
expected: jsx("hul", null, jsx("hli", null, jsx("hp", null, "hello "), jsx("hul", null, jsx("hli", null, jsx("hp", null, "world"), jsx("hp", null, "line 2")))))
|
|
42
|
+
input: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "hello ", /*#__PURE__*/ jsx("cursor", null)))),
|
|
43
|
+
fragment: /*#__PURE__*/ jsx("fragment", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "world"), /*#__PURE__*/ jsx("hp", null, "line 2"))),
|
|
44
|
+
expected: /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "hello "), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "world"), /*#__PURE__*/ jsx("hp", null, "line 2")))))
|
|
45
45
|
}
|
|
46
46
|
];
|
|
47
|
-
const render = (children)
|
|
47
|
+
const render = (children)=>/*#__PURE__*/ jsx("editor", null, children, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
48
48
|
for (const t of tests){
|
|
49
49
|
test(t.title, ()=>{
|
|
50
|
-
const { editor
|
|
50
|
+
const { editor } = createTestEditor({
|
|
51
51
|
input: render(t.input)
|
|
52
52
|
});
|
|
53
53
|
editor.insertFragment(t.fragment);
|
|
@@ -36,7 +36,7 @@ const styles = {
|
|
|
36
36
|
};
|
|
37
37
|
function createList(Tag, block) {
|
|
38
38
|
return function List(props) {
|
|
39
|
-
return React.createElement(Tag, {
|
|
39
|
+
return /*#__PURE__*/ React.createElement(Tag, {
|
|
40
40
|
...props.attributes,
|
|
41
41
|
className: cx(baseStyle, styles[block])
|
|
42
42
|
}, props.children);
|
|
@@ -21,17 +21,17 @@ export function ToolbarListButton(props) {
|
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
if (!editor) return null;
|
|
24
|
-
return React.createElement(React.Fragment, null, isNodeTypeEnabled(sdk.field, BLOCKS.UL_LIST) && React.createElement(ToolbarButton, {
|
|
24
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, isNodeTypeEnabled(sdk.field, BLOCKS.UL_LIST) && /*#__PURE__*/ React.createElement(ToolbarButton, {
|
|
25
25
|
title: "UL",
|
|
26
26
|
testId: "ul-toolbar-button",
|
|
27
27
|
onClick: handleClick(BLOCKS.UL_LIST),
|
|
28
28
|
isActive: isListTypeActive(editor, BLOCKS.UL_LIST),
|
|
29
29
|
isDisabled: props.isDisabled
|
|
30
|
-
}, React.createElement(ListBulletedIcon, null)), isNodeTypeEnabled(sdk.field, BLOCKS.OL_LIST) && React.createElement(ToolbarButton, {
|
|
30
|
+
}, /*#__PURE__*/ React.createElement(ListBulletedIcon, null)), isNodeTypeEnabled(sdk.field, BLOCKS.OL_LIST) && /*#__PURE__*/ React.createElement(ToolbarButton, {
|
|
31
31
|
title: "OL",
|
|
32
32
|
testId: "ol-toolbar-button",
|
|
33
33
|
onClick: handleClick(BLOCKS.OL_LIST),
|
|
34
34
|
isActive: isListTypeActive(editor, BLOCKS.OL_LIST),
|
|
35
35
|
isDisabled: props.isDisabled
|
|
36
|
-
}, React.createElement(ListNumberedIcon, null)));
|
|
36
|
+
}, /*#__PURE__*/ React.createElement(ListNumberedIcon, null)));
|
|
37
37
|
}
|
|
@@ -28,6 +28,8 @@ export const createListPlugin = ()=>createPlateListPlugin({
|
|
|
28
28
|
handlers: {
|
|
29
29
|
onKeyDown: onKeyDownList
|
|
30
30
|
},
|
|
31
|
+
// The withList is added on ELEMENT_UL plugin in upstream code
|
|
32
|
+
// so we need to override it here
|
|
31
33
|
withOverrides: withList
|
|
32
34
|
},
|
|
33
35
|
[ELEMENT_OL]: {
|
|
@@ -37,12 +39,14 @@ export const createListPlugin = ()=>createPlateListPlugin({
|
|
|
37
39
|
onKeyDown: onKeyDownList
|
|
38
40
|
}
|
|
39
41
|
},
|
|
42
|
+
// ELEMENT_LIC is a child of li, Slate does ul > li > lic + ul
|
|
40
43
|
[ELEMENT_LIC]: {
|
|
41
44
|
type: BLOCKS.PARAGRAPH
|
|
42
45
|
},
|
|
43
46
|
[ELEMENT_LI]: {
|
|
44
47
|
type: BLOCKS.LIST_ITEM,
|
|
45
48
|
component: ListItem,
|
|
49
|
+
// @ts-expect-error
|
|
46
50
|
normalizer: [
|
|
47
51
|
{
|
|
48
52
|
validNode: hasListAsDirectParent,
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Credit: Copied & modified version from Plate's list plugin to support
|
|
3
|
+
* list items with multiple children.
|
|
4
|
+
*
|
|
5
|
+
* See: https://github.com/udecode/plate/blob/main/packages/nodes/list
|
|
6
|
+
*/ import { TEXT_CONTAINERS } from '@contentful/rich-text-types';
|
|
2
7
|
import { ELEMENT_DEFAULT, getPluginType, isBlockAboveEmpty, mockPlugin } from '@udecode/plate-common';
|
|
3
8
|
import { getListItemEntry, moveListItemUp, unwrapList, ELEMENT_LI } from '@udecode/plate-list';
|
|
4
9
|
import { onKeyDownResetNode, SIMULATE_BACKSPACE } from '@udecode/plate-reset-node';
|
|
@@ -7,9 +12,11 @@ const listBreak = (editor)=>{
|
|
|
7
12
|
if (!editor.selection) return false;
|
|
8
13
|
const res = getListItemEntry(editor, {});
|
|
9
14
|
let moved;
|
|
15
|
+
// If selection is in a li
|
|
10
16
|
if (res) {
|
|
11
|
-
const { list
|
|
17
|
+
const { list, listItem } = res;
|
|
12
18
|
const childNode = listItem[0].children[0];
|
|
19
|
+
// If selected li is empty, move it up.
|
|
13
20
|
if (isBlockAboveEmpty(editor) && listItem[0].children.length === 1 && TEXT_CONTAINERS.includes(childNode.type)) {
|
|
14
21
|
moved = moveListItemUp(editor, {
|
|
15
22
|
list,
|
|
@@ -35,14 +42,16 @@ const listBreak = (editor)=>{
|
|
|
35
42
|
if (didReset) {
|
|
36
43
|
return true;
|
|
37
44
|
}
|
|
38
|
-
|
|
45
|
+
/**
|
|
46
|
+
* If selection is in li > p, insert li.
|
|
47
|
+
*/ if (!moved) {
|
|
39
48
|
const inserted = insertListItem(editor);
|
|
40
49
|
if (inserted) return true;
|
|
41
50
|
}
|
|
42
51
|
return false;
|
|
43
52
|
};
|
|
44
53
|
export const insertListBreak = (editor)=>{
|
|
45
|
-
const { insertBreak
|
|
54
|
+
const { insertBreak } = editor;
|
|
46
55
|
return ()=>{
|
|
47
56
|
if (listBreak(editor)) return;
|
|
48
57
|
insertBreak();
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Credit: Modified version of Plate's list plugin
|
|
3
|
+
* See: https://github.com/udecode/plate/blob/main/packages/nodes/list
|
|
4
|
+
*/ import { TEXT_CONTAINERS, BLOCKS } from '@contentful/rich-text-types';
|
|
2
5
|
import { findNode } from '@udecode/plate-common';
|
|
3
6
|
import { isBlockNode, isAncestorPath, getCommonNode, getNodeTexts, getParentPath, getDescendantNodeByPath } from '../../internal/queries';
|
|
4
7
|
import { insertNodes } from '../../internal/transforms';
|
|
@@ -16,19 +19,26 @@ const isListRoot = (node)=>[
|
|
|
16
19
|
BLOCKS.UL_LIST,
|
|
17
20
|
BLOCKS.OL_LIST
|
|
18
21
|
].includes(node.type);
|
|
19
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Removes the "empty" leading lis. Empty in this context means lis only with other lis as children.
|
|
24
|
+
*
|
|
25
|
+
* @returns If argument is not a list root, returns it, otherwise returns ul[] or li[].
|
|
26
|
+
*/ const trimList = (listRoot)=>{
|
|
20
27
|
if (!isListRoot(listRoot)) {
|
|
21
28
|
return [
|
|
22
29
|
listRoot
|
|
23
30
|
];
|
|
24
31
|
}
|
|
25
32
|
const textEntries = Array.from(getNodeTexts(listRoot));
|
|
26
|
-
const commonAncestorEntry = textEntries.reduce((commonAncestor, textEntry)=>isAncestorPath(commonAncestor[1], textEntry[1]) ? commonAncestor : getCommonNode(listRoot, textEntry[1], commonAncestor[1]),
|
|
33
|
+
const commonAncestorEntry = textEntries.reduce((commonAncestor, textEntry)=>isAncestorPath(commonAncestor[1], textEntry[1]) ? commonAncestor : getCommonNode(listRoot, textEntry[1], commonAncestor[1]), // any list item would do, we grab the first one
|
|
34
|
+
getFirstAncestorOfType(listRoot, textEntries[0]));
|
|
27
35
|
return isListRoot(commonAncestorEntry[0]) ? commonAncestorEntry[0].children : [
|
|
28
36
|
commonAncestorEntry[0]
|
|
29
37
|
];
|
|
30
38
|
};
|
|
31
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Removes leading li when pasting a single li with a single child.
|
|
41
|
+
*/ const trimLiWrapper = (nodes)=>{
|
|
32
42
|
if (nodes.length !== 1) {
|
|
33
43
|
return nodes;
|
|
34
44
|
}
|
|
@@ -49,7 +59,7 @@ const unwrapTextContainerAtStart = (nodes)=>{
|
|
|
49
59
|
return nodes;
|
|
50
60
|
};
|
|
51
61
|
export const insertListFragment = (editor)=>{
|
|
52
|
-
const { insertFragment
|
|
62
|
+
const { insertFragment } = editor;
|
|
53
63
|
return (fragment)=>{
|
|
54
64
|
if (!editor.selection) {
|
|
55
65
|
return;
|
|
@@ -68,6 +78,9 @@ export const insertListFragment = (editor)=>{
|
|
|
68
78
|
}
|
|
69
79
|
const inlines = nodes.slice(0, firstBlockIndex);
|
|
70
80
|
const blocks = nodes.slice(firstBlockIndex);
|
|
81
|
+
// Two calls to insertNodes are required here. Otherwise, all blocks
|
|
82
|
+
// after a text or inline element occurrence will be unwrapped for
|
|
83
|
+
// some reason.
|
|
71
84
|
insertNodes(editor, inlines, {
|
|
72
85
|
at: editor.selection,
|
|
73
86
|
select: true
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Credit: Modified version of Plate's list plugin
|
|
3
|
+
* See: https://github.com/udecode/plate/blob/main/packages/nodes/list
|
|
4
|
+
*/ import isHotkey from 'is-hotkey';
|
|
2
5
|
import castArray from 'lodash/castArray';
|
|
3
6
|
import { getAboveNode } from '../../internal/queries';
|
|
4
7
|
import { moveListItems } from './transforms/moveListItems';
|
|
5
8
|
import { toggleList } from './transforms/toggleList';
|
|
6
|
-
export const onKeyDownList = (editor, { type
|
|
9
|
+
export const onKeyDownList = (editor, { type, options: { hotkey } })=>(e)=>{
|
|
7
10
|
if (e.key === 'Tab' && editor.selection) {
|
|
8
11
|
const listSelected = getAboveNode(editor, {
|
|
9
12
|
at: editor.selection,
|
|
@@ -2,7 +2,9 @@ import { BLOCKS, TEXT_CONTAINERS } from '@contentful/rich-text-types';
|
|
|
2
2
|
import { withoutNormalizing } from '../../../internal';
|
|
3
3
|
import { getAboveNode, getParentNode, isFirstChildPath, isSelectionAtBlockEnd, isSelectionAtBlockStart, getMarks, getNextPath } from '../../../internal/queries';
|
|
4
4
|
import { select, insertNodes, moveChildren, splitNodes, collapseSelection } from '../../../internal/transforms';
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Build a new list item node while preserving marks
|
|
7
|
+
*/ const emptyListItemNode = (editor, withChildren = false)=>{
|
|
6
8
|
let children = [];
|
|
7
9
|
if (withChildren) {
|
|
8
10
|
const marks = getMarks(editor) || {};
|
|
@@ -25,10 +27,13 @@ const emptyListItemNode = (editor, withChildren = false)=>{
|
|
|
25
27
|
children
|
|
26
28
|
};
|
|
27
29
|
};
|
|
28
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Insert list item if selection is in li>p.
|
|
32
|
+
*/ export const insertListItem = (editor)=>{
|
|
29
33
|
if (!editor.selection) {
|
|
30
34
|
return false;
|
|
31
35
|
}
|
|
36
|
+
// Naming it paragraph for simplicity but can be a heading as well
|
|
32
37
|
const paragraph = getAboveNode(editor, {
|
|
33
38
|
match: {
|
|
34
39
|
type: TEXT_CONTAINERS
|
|
@@ -46,23 +51,33 @@ export const insertListItem = (editor)=>{
|
|
|
46
51
|
if (listItemNode.type !== BLOCKS.LIST_ITEM) {
|
|
47
52
|
return false;
|
|
48
53
|
}
|
|
54
|
+
// We are in a li>p (or heading)
|
|
49
55
|
withoutNormalizing(editor, ()=>{
|
|
50
56
|
if (!editor.selection) {
|
|
51
57
|
return;
|
|
52
58
|
}
|
|
59
|
+
// Check the cursor position in the current paragraph
|
|
53
60
|
const isAtStart = isSelectionAtBlockStart(editor);
|
|
54
61
|
const isAtEnd = isSelectionAtBlockEnd(editor);
|
|
55
62
|
const isAtStartOfListItem = isAtStart && isFirstChildPath(paragraphPath);
|
|
56
63
|
const shouldSplit = !isAtStart && !isAtEnd;
|
|
64
|
+
// Split the current paragraph content if necessary
|
|
57
65
|
if (shouldSplit) {
|
|
58
66
|
splitNodes(editor);
|
|
59
67
|
}
|
|
68
|
+
// Insert the new li
|
|
60
69
|
const newListItemPath = isAtStartOfListItem ? listItemPath : getNextPath(listItemPath);
|
|
61
|
-
insertNodes(editor,
|
|
70
|
+
insertNodes(editor, // Add an empty paragraph to the new li if We will not move some
|
|
71
|
+
// paragraphs over there.
|
|
72
|
+
emptyListItemNode(editor, !shouldSplit), {
|
|
62
73
|
at: newListItemPath
|
|
63
74
|
});
|
|
75
|
+
// Move children *after* selection to the new li
|
|
64
76
|
const fromPath = isAtStart ? paragraphPath : getNextPath(paragraphPath);
|
|
65
77
|
const fromStartIndex = fromPath[fromPath.length - 1] || 0;
|
|
78
|
+
// On split we don't add paragraph to the new li so we move
|
|
79
|
+
// content to the very beginning. Otherwise, account for the empty
|
|
80
|
+
// paragraph at the beginning by moving the content after
|
|
66
81
|
const toPath = newListItemPath.concat([
|
|
67
82
|
shouldSplit ? 0 : 1
|
|
68
83
|
]);
|
|
@@ -73,10 +88,12 @@ export const insertListItem = (editor)=>{
|
|
|
73
88
|
fromStartIndex
|
|
74
89
|
});
|
|
75
90
|
}
|
|
91
|
+
// Move cursor to the start of the new li
|
|
76
92
|
select(editor, newListItemPath);
|
|
77
93
|
collapseSelection(editor, {
|
|
78
94
|
edge: 'start'
|
|
79
95
|
});
|
|
80
96
|
});
|
|
97
|
+
// Returning True skips processing other editor.insertBreak handlers
|
|
81
98
|
return true;
|
|
82
99
|
};
|