From 34326c3001128bdebfe6b9d94c866aa266234f68 Mon Sep 17 00:00:00 2001 From: Aodhagan Murphy Date: Mon, 8 Jul 2024 22:03:22 +0100 Subject: [PATCH] feat: removing unwrap list override [] --- .../src/plugins/List/transforms/toggleList.ts | 3 +- .../src/plugins/List/transforms/unwrapList.ts | 51 ------------------- 2 files changed, 1 insertion(+), 53 deletions(-) delete mode 100644 packages/rich-text/src/plugins/List/transforms/unwrapList.ts diff --git a/packages/rich-text/src/plugins/List/transforms/toggleList.ts b/packages/rich-text/src/plugins/List/transforms/toggleList.ts index 95adbf9d1..3debc2df0 100644 --- a/packages/rich-text/src/plugins/List/transforms/toggleList.ts +++ b/packages/rich-text/src/plugins/List/transforms/toggleList.ts @@ -4,7 +4,7 @@ */ import { BLOCKS } from '@contentful/rich-text-types'; import { ELEMENT_LIC } from '@udecode/plate-list'; -import { getListItemEntry } from '@udecode/plate-list'; +import { getListItemEntry, unwrapList } from '@udecode/plate-list'; import { withoutNormalizing } from '../../../internal'; import { ELEMENT_DEFAULT } from '../../../internal/constants'; @@ -22,7 +22,6 @@ import { } from '../../../internal/queries'; import { setNodes, wrapNodes } from '../../../internal/transforms'; import { PlateEditor, Element, Location, NodeEntry } from '../../../internal/types'; -import { unwrapList } from './unwrapList'; const listTypes = [BLOCKS.UL_LIST, BLOCKS.OL_LIST] as string[]; diff --git a/packages/rich-text/src/plugins/List/transforms/unwrapList.ts b/packages/rich-text/src/plugins/List/transforms/unwrapList.ts deleted file mode 100644 index 04569bacc..000000000 --- a/packages/rich-text/src/plugins/List/transforms/unwrapList.ts +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Credit: Modified version of Plate's list plugin - * See: https://github.com/udecode/plate/blob/main/packages/nodes/list - */ -import { BLOCKS } from '@contentful/rich-text-types'; - -import { withoutNormalizing } from '../../../internal'; -import { getNodeEntries, isElement } from '../../../internal/queries'; -import { unwrapNodes, liftNodes } from '../../../internal/transforms'; -import { PlateEditor, Path } from '../../../internal/types'; - -function hasUnliftedListItems(editor: PlateEditor, stoppingIndex: number, at?: Path) { - return getNodeEntries(editor, { - at, - match: (node, path) => - isElement(node) && node.type === BLOCKS.LIST_ITEM && path.length >= stoppingIndex, - }).next().done; -} - -function getStoppingIndex(editor: PlateEditor, at?: Path) { - const tableCell = getNodeEntries(editor, { - at, - match: (node) => { - return isElement(node) && node.type === BLOCKS.TABLE_CELL; - }, - }).next().value; - const rootStoppingIndex = 2; - return tableCell ? tableCell[1].length + rootStoppingIndex : rootStoppingIndex; -} - -export const unwrapList = (editor: PlateEditor, { at }: { at?: Path } = {}) => { - const stoppingIndex = getStoppingIndex(editor, at); - - withoutNormalizing(editor, () => { - do { - // lift list items to the root level - liftNodes(editor, { - at, - match: (node) => isElement(node) && node.type === BLOCKS.LIST_ITEM, - mode: 'lowest', - }); - } while (!hasUnliftedListItems(editor, stoppingIndex, at)); - - // finally unwrap all lifted items - unwrapNodes(editor, { - at, - match: { type: BLOCKS.LIST_ITEM }, - split: false, - }); - }); -};