From ad70224515d3b780c90a045f56b78cf037fc9ac8 Mon Sep 17 00:00:00 2001 From: HariHaran Subramanian Date: Wed, 14 Dec 2022 12:49:18 +0530 Subject: [PATCH 1/5] feat: #3540 Ability to preserve marks on lists --- demos/src/Examples/Default/React/index.jsx | 9 +++++- docs/api/nodes/bullet-list.md | 10 ++++++ docs/api/nodes/ordered-list.md | 11 +++++++ package-lock.json | 1 + packages/core/src/commands/splitListItem.ts | 12 +++++++ packages/core/src/commands/toggleList.ts | 31 ++++++++++++++++--- .../core/src/inputRules/wrappingInputRule.ts | 23 +++++++++++--- .../extension-bullet-list/src/bullet-list.ts | 18 +++++++++-- .../src/ordered-list.ts | 20 +++++++++--- 9 files changed, 118 insertions(+), 17 deletions(-) diff --git a/demos/src/Examples/Default/React/index.jsx b/demos/src/Examples/Default/React/index.jsx index 42c168adb72..4f68efc4df8 100644 --- a/demos/src/Examples/Default/React/index.jsx +++ b/demos/src/Examples/Default/React/index.jsx @@ -172,7 +172,14 @@ const MenuBar = ({ editor }) => { export default () => { const editor = useEditor({ extensions: [ - StarterKit, + StarterKit.configure({ + bulletList: { + keepMarks: true, + }, + orderedList: { + keepMarks: true, + }, + }), ], content: `

diff --git a/docs/api/nodes/bullet-list.md b/docs/api/nodes/bullet-list.md index 652bd27c917..b5afd4972c0 100644 --- a/docs/api/nodes/bullet-list.md +++ b/docs/api/nodes/bullet-list.md @@ -41,6 +41,16 @@ BulletList.configure({ itemTypeName: 'listItem', }) ``` +### keepMarks +Decides whether to keep marks after a line break. Based on the `keepOnSplit` option for marks. + +Default: `false` + +```js +BulletList.configure({ + keepMarks: true, +}) +``` ## Commands diff --git a/docs/api/nodes/ordered-list.md b/docs/api/nodes/ordered-list.md index 7fab529f152..9b5243a5e2c 100644 --- a/docs/api/nodes/ordered-list.md +++ b/docs/api/nodes/ordered-list.md @@ -42,6 +42,17 @@ OrderedList.configure({ }) ``` +### keepMarks +Decides whether to keep marks after a line break. Based on the `keepOnSplit` option for marks. + +Default: `false` + +```js +BulletList.configure({ + keepMarks: true, +}) +``` + ## Commands ### toggleOrderedList() diff --git a/package-lock.json b/package-lock.json index 95effd5d857..246e1619624 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19932,6 +19932,7 @@ }, "peerDependencies": { "@tiptap/core": "^2.0.0-beta.193", + "@tiptap/prosemirror-tables": "^1.1.3", "prosemirror-model": "^1.18.1", "prosemirror-state": "^1.4.1", "prosemirror-view": "^1.28.2" diff --git a/packages/core/src/commands/splitListItem.ts b/packages/core/src/commands/splitListItem.ts index 25ee314273f..acad21b6da7 100644 --- a/packages/core/src/commands/splitListItem.ts +++ b/packages/core/src/commands/splitListItem.ts @@ -140,7 +140,19 @@ export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({ } if (dispatch) { + const { selection, storedMarks } = state + const { splittableMarks } = editor.extensionManager + const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks()) + tr.split($from.pos, 2, types).scrollIntoView() + + if (!marks || !dispatch) { + return true + } + + const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name)) + + tr.ensureMarks(filteredMarks) } return true diff --git a/packages/core/src/commands/toggleList.ts b/packages/core/src/commands/toggleList.ts index 27de705ee09..d03ce45eff8 100644 --- a/packages/core/src/commands/toggleList.ts +++ b/packages/core/src/commands/toggleList.ts @@ -65,21 +65,23 @@ declare module '@tiptap/core' { /** * Toggle between different list types. */ - toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType) => ReturnType, + toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType, keepMarks?: boolean) => ReturnType; } } } -export const toggleList: RawCommands['toggleList'] = (listTypeOrName, itemTypeOrName) => ({ +export const toggleList: RawCommands['toggleList'] = (listTypeOrName, itemTypeOrName, keepMarks = false) => ({ editor, tr, state, dispatch, chain, commands, can, }) => { - const { extensions } = editor.extensionManager + const { extensions, splittableMarks } = editor.extensionManager const listType = getNodeType(listTypeOrName, state.schema) const itemType = getNodeType(itemTypeOrName, state.schema) - const { selection } = state + const { selection, storedMarks } = state const { $from, $to } = selection const range = $from.blockRange($to) + const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks()) + if (!range) { return false } @@ -109,6 +111,24 @@ export const toggleList: RawCommands['toggleList'] = (listTypeOrName, itemTypeOr .run() } } + if (!keepMarks || !marks || !dispatch) { + + return chain() + // try to convert node to default node if needed + .command(() => { + const canWrapInList = can().wrapInList(listType) + + if (canWrapInList) { + return true + } + + return commands.clearNodes() + }) + .wrapInList(listType) + .command(() => joinListBackwards(tr, listType)) + .command(() => joinListForwards(tr, listType)) + .run() + } return chain() // try to convert node to default node if needed @@ -118,6 +138,9 @@ export const toggleList: RawCommands['toggleList'] = (listTypeOrName, itemTypeOr if (canWrapInList) { return true } + const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name)) + + tr.ensureMarks(filteredMarks) return commands.clearNodes() }) diff --git a/packages/core/src/inputRules/wrappingInputRule.ts b/packages/core/src/inputRules/wrappingInputRule.ts index 380a824f112..03ae402c18a 100644 --- a/packages/core/src/inputRules/wrappingInputRule.ts +++ b/packages/core/src/inputRules/wrappingInputRule.ts @@ -1,6 +1,7 @@ import { Node as ProseMirrorNode, NodeType } from 'prosemirror-model' import { canJoin, findWrapping } from 'prosemirror-transform' +import { Editor } from '../Editor' import { InputRule, InputRuleFinder } from '../InputRule' import { ExtendedRegExpMatchArray } from '../types' import { callOrReturn } from '../utilities/callOrReturn' @@ -22,11 +23,13 @@ import { callOrReturn } from '../utilities/callOrReturn' export function wrappingInputRule(config: { find: InputRuleFinder, type: NodeType, + keepMarks?: boolean, + editor?: Editor getAttributes?: - | Record - | ((match: ExtendedRegExpMatchArray) => Record) - | false - | null + | Record + | ((match: ExtendedRegExpMatchArray) => Record) + | false + | null , joinPredicate?: (match: ExtendedRegExpMatchArray, node: ProseMirrorNode) => boolean, }) { @@ -45,6 +48,18 @@ export function wrappingInputRule(config: { tr.wrap(blockRange, wrapping) + if (config.keepMarks && config.editor) { + const { selection, storedMarks } = state + const { splittableMarks } = config.editor.extensionManager + const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks()) + + if (marks) { + const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name)) + + tr.ensureMarks(filteredMarks) + } + } + const before = tr.doc.resolve(range.from - 1).nodeBefore if ( diff --git a/packages/extension-bullet-list/src/bullet-list.ts b/packages/extension-bullet-list/src/bullet-list.ts index 7c6ab14a988..63f0cba727d 100644 --- a/packages/extension-bullet-list/src/bullet-list.ts +++ b/packages/extension-bullet-list/src/bullet-list.ts @@ -3,6 +3,7 @@ import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core' export interface BulletListOptions { itemTypeName: string, HTMLAttributes: Record, + keepMarks: boolean, } declare module '@tiptap/core' { @@ -25,6 +26,7 @@ export const BulletList = Node.create({ return { itemTypeName: 'listItem', HTMLAttributes: {}, + keepMarks: false, } }, @@ -59,11 +61,21 @@ export const BulletList = Node.create({ }, addInputRules() { - return [ - wrappingInputRule({ + let inputRule = wrappingInputRule({ + find: inputRegex, + type: this.type, + }) + + if (this.options.keepMarks) { + inputRule = wrappingInputRule({ find: inputRegex, type: this.type, - }), + keepMarks: true, + editor: this.editor, + }) + } + return [ + inputRule, ] }, }) diff --git a/packages/extension-ordered-list/src/ordered-list.ts b/packages/extension-ordered-list/src/ordered-list.ts index 6dd181fa2a1..2fc61515055 100644 --- a/packages/extension-ordered-list/src/ordered-list.ts +++ b/packages/extension-ordered-list/src/ordered-list.ts @@ -3,6 +3,7 @@ import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core' export interface OrderedListOptions { itemTypeName: string, HTMLAttributes: Record, + keepMarks: boolean, } declare module '@tiptap/core' { @@ -25,6 +26,7 @@ export const OrderedList = Node.create({ return { itemTypeName: 'listItem', HTMLAttributes: {}, + keepMarks: false, } }, @@ -78,13 +80,21 @@ export const OrderedList = Node.create({ }, addInputRules() { - return [ - wrappingInputRule({ + let inputRule = wrappingInputRule({ + find: inputRegex, + type: this.type, + }) + + if (this.options.keepMarks) { + inputRule = wrappingInputRule({ find: inputRegex, type: this.type, - getAttributes: match => ({ start: +match[1] }), - joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1], - }), + keepMarks: true, + editor: this.editor, + }) + } + return [ + inputRule, ] }, }) From 73c96f5efe5b1118c8aa92f2ea60ec02b3849a4f Mon Sep 17 00:00:00 2001 From: HariHaran Subramanian Date: Wed, 14 Dec 2022 15:45:53 +0530 Subject: [PATCH 2/5] feat: preserveAttrs in list items --- demos/src/Examples/Default/React/index.jsx | 13 +++++++++++++ docs/api/nodes/bullet-list.md | 13 ++++++++++++- docs/api/nodes/ordered-list.md | 14 ++++++++++++-- .../core/src/inputRules/wrappingInputRule.ts | 11 ++++++++++- .../extension-bullet-list/src/bullet-list.ts | 16 +++++++++++++--- .../extension-ordered-list/src/ordered-list.ts | 16 +++++++++++++--- 6 files changed, 73 insertions(+), 10 deletions(-) diff --git a/demos/src/Examples/Default/React/index.jsx b/demos/src/Examples/Default/React/index.jsx index 4f68efc4df8..6ab57e26451 100644 --- a/demos/src/Examples/Default/React/index.jsx +++ b/demos/src/Examples/Default/React/index.jsx @@ -1,5 +1,8 @@ import './styles.scss' +import { Color } from '@tiptap/extension-color' +import ListItem from '@tiptap/extension-list-item' +import TextStyle from '@tiptap/extension-text-style' import { EditorContent, useEditor } from '@tiptap/react' import StarterKit from '@tiptap/starter-kit' import React from 'react' @@ -165,6 +168,12 @@ const MenuBar = ({ editor }) => { > redo + ) } @@ -172,12 +181,16 @@ const MenuBar = ({ editor }) => { export default () => { const editor = useEditor({ extensions: [ + Color.configure({ types: [TextStyle.name, ListItem.name] }), + TextStyle.configure({ types: [ListItem.name] }), StarterKit.configure({ bulletList: { keepMarks: true, + keepAttributes: true, }, orderedList: { keepMarks: true, + keepAttributes: true, }, }), ], diff --git a/docs/api/nodes/bullet-list.md b/docs/api/nodes/bullet-list.md index b5afd4972c0..b829f3dc1d0 100644 --- a/docs/api/nodes/bullet-list.md +++ b/docs/api/nodes/bullet-list.md @@ -42,7 +42,7 @@ BulletList.configure({ }) ``` ### keepMarks -Decides whether to keep marks after a line break. Based on the `keepOnSplit` option for marks. +Decides whether to keep the marks from a previous line after toggling the list either using `inputRule` or using the button Default: `false` @@ -52,6 +52,17 @@ BulletList.configure({ }) ``` +### keepAttributes +Decides whether to keep the attributes from a previous line after toggling the list either using `inputRule` or using the button + +Default: `false` + +```js +BulletList.configure({ + keepAttributes: true, +}) +``` + ## Commands ### toggleBulletList() diff --git a/docs/api/nodes/ordered-list.md b/docs/api/nodes/ordered-list.md index 9b5243a5e2c..b665813f4b0 100644 --- a/docs/api/nodes/ordered-list.md +++ b/docs/api/nodes/ordered-list.md @@ -43,15 +43,25 @@ OrderedList.configure({ ``` ### keepMarks -Decides whether to keep marks after a line break. Based on the `keepOnSplit` option for marks. +Decides whether to keep the marks from a previous line after toggling the list either using `inputRule` or using the button Default: `false` ```js -BulletList.configure({ +OrderedList.configure({ keepMarks: true, }) ``` +### keepAttributes +Decides whether to keep the attributes from a previous line after toggling the list either using `inputRule` or using the button + +Default: `false` + +```js +OrderedList.configure({ + keepAttributes: true, +}) +``` ## Commands diff --git a/packages/core/src/inputRules/wrappingInputRule.ts b/packages/core/src/inputRules/wrappingInputRule.ts index 03ae402c18a..f09027b5607 100644 --- a/packages/core/src/inputRules/wrappingInputRule.ts +++ b/packages/core/src/inputRules/wrappingInputRule.ts @@ -24,6 +24,7 @@ export function wrappingInputRule(config: { find: InputRuleFinder, type: NodeType, keepMarks?: boolean, + keepAttributes?: boolean, editor?: Editor getAttributes?: | Record @@ -35,7 +36,9 @@ export function wrappingInputRule(config: { }) { return new InputRule({ find: config.find, - handler: ({ state, range, match }) => { + handler: ({ + state, range, match, chain, + }) => { const attributes = callOrReturn(config.getAttributes, undefined, match) || {} const tr = state.tr.delete(range.from, range.to) const $start = tr.doc.resolve(range.from) @@ -59,6 +62,12 @@ export function wrappingInputRule(config: { tr.ensureMarks(filteredMarks) } } + if (config.keepAttributes) { + /** If the nodeType is `bulletList` or `orderedList` set the `nodeType` as `listItem` */ + const nodeType = config.type.name === 'bulletList' || config.type.name === 'orderedList' ? 'listItem' : 'taskList' + + chain().updateAttributes(nodeType, attributes).run() + } const before = tr.doc.resolve(range.from - 1).nodeBefore diff --git a/packages/extension-bullet-list/src/bullet-list.ts b/packages/extension-bullet-list/src/bullet-list.ts index 63f0cba727d..a55cf345bef 100644 --- a/packages/extension-bullet-list/src/bullet-list.ts +++ b/packages/extension-bullet-list/src/bullet-list.ts @@ -1,9 +1,13 @@ import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core' +import ListItem from '../../extension-list-item/src' +import TextStyle from '../../extension-text-style/src' + export interface BulletListOptions { itemTypeName: string, HTMLAttributes: Record, keepMarks: boolean, + keepAttributes: boolean, } declare module '@tiptap/core' { @@ -27,6 +31,7 @@ export const BulletList = Node.create({ itemTypeName: 'listItem', HTMLAttributes: {}, keepMarks: false, + keepAttributes: false, } }, @@ -48,7 +53,10 @@ export const BulletList = Node.create({ addCommands() { return { - toggleBulletList: () => ({ commands }) => { + toggleBulletList: () => ({ commands, chain }) => { + if (this.options.keepAttributes) { + return chain().toggleList(this.name, this.options.itemTypeName).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run() + } return commands.toggleList(this.name, this.options.itemTypeName) }, } @@ -66,11 +74,13 @@ export const BulletList = Node.create({ type: this.type, }) - if (this.options.keepMarks) { + if (this.options.keepMarks || this.options.keepAttributes) { inputRule = wrappingInputRule({ find: inputRegex, type: this.type, - keepMarks: true, + keepMarks: this.options.keepMarks, + keepAttributes: this.options.keepAttributes, + getAttributes: () => { return this.editor.getAttributes(TextStyle.name) }, editor: this.editor, }) } diff --git a/packages/extension-ordered-list/src/ordered-list.ts b/packages/extension-ordered-list/src/ordered-list.ts index 2fc61515055..6b1e0ea9251 100644 --- a/packages/extension-ordered-list/src/ordered-list.ts +++ b/packages/extension-ordered-list/src/ordered-list.ts @@ -1,9 +1,13 @@ import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core' +import ListItem from '../../extension-list-item/src' +import TextStyle from '../../extension-text-style/src' + export interface OrderedListOptions { itemTypeName: string, HTMLAttributes: Record, keepMarks: boolean, + keepAttributes: boolean, } declare module '@tiptap/core' { @@ -27,6 +31,7 @@ export const OrderedList = Node.create({ itemTypeName: 'listItem', HTMLAttributes: {}, keepMarks: false, + keepAttributes: false, } }, @@ -67,7 +72,10 @@ export const OrderedList = Node.create({ addCommands() { return { - toggleOrderedList: () => ({ commands }) => { + toggleOrderedList: () => ({ commands, chain }) => { + if (this.options.keepAttributes) { + return chain().toggleList(this.name, this.options.itemTypeName).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run() + } return commands.toggleList(this.name, this.options.itemTypeName) }, } @@ -85,11 +93,13 @@ export const OrderedList = Node.create({ type: this.type, }) - if (this.options.keepMarks) { + if (this.options.keepMarks || this.options.keepAttributes) { inputRule = wrappingInputRule({ find: inputRegex, type: this.type, - keepMarks: true, + keepMarks: this.options.keepMarks, + keepAttributes: this.options.keepAttributes, + getAttributes: () => { return this.editor.getAttributes(TextStyle.name) }, editor: this.editor, }) } From 9161e1e58634ce8ef3b65b1e9923d38d720d5702 Mon Sep 17 00:00:00 2001 From: HariHaran Subramanian Date: Wed, 14 Dec 2022 17:08:34 +0530 Subject: [PATCH 3/5] `keepMarks` is working, but need help with `keepAttrs` --- demos/src/Examples/Default/React/index.jsx | 4 ++-- packages/core/src/commands/toggleList.ts | 9 +++++---- packages/extension-bullet-list/src/bullet-list.ts | 4 ++-- packages/extension-ordered-list/src/ordered-list.ts | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/demos/src/Examples/Default/React/index.jsx b/demos/src/Examples/Default/React/index.jsx index 6ab57e26451..ef74b7b0d69 100644 --- a/demos/src/Examples/Default/React/index.jsx +++ b/demos/src/Examples/Default/React/index.jsx @@ -186,11 +186,11 @@ export default () => { StarterKit.configure({ bulletList: { keepMarks: true, - keepAttributes: true, + keepAttributes: false, // TODO : Making this as `false` becase marks are not preserved when I try to preserve attrs, awaiting a bit of help }, orderedList: { keepMarks: true, - keepAttributes: true, + keepAttributes: false, // TODO : Making this as `false` becase marks are not preserved when I try to preserve attrs, awaiting a bit of help }, }), ], diff --git a/packages/core/src/commands/toggleList.ts b/packages/core/src/commands/toggleList.ts index d03ce45eff8..0c15bc3d225 100644 --- a/packages/core/src/commands/toggleList.ts +++ b/packages/core/src/commands/toggleList.ts @@ -70,7 +70,7 @@ declare module '@tiptap/core' { } } -export const toggleList: RawCommands['toggleList'] = (listTypeOrName, itemTypeOrName, keepMarks = false) => ({ +export const toggleList: RawCommands['toggleList'] = (listTypeOrName, itemTypeOrName, keepMarks) => ({ editor, tr, state, dispatch, chain, commands, can, }) => { const { extensions, splittableMarks } = editor.extensionManager @@ -135,13 +135,14 @@ export const toggleList: RawCommands['toggleList'] = (listTypeOrName, itemTypeOr .command(() => { const canWrapInList = can().wrapInList(listType) - if (canWrapInList) { - return true - } const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name)) tr.ensureMarks(filteredMarks) + if (canWrapInList) { + return true + } + return commands.clearNodes() }) .wrapInList(listType) diff --git a/packages/extension-bullet-list/src/bullet-list.ts b/packages/extension-bullet-list/src/bullet-list.ts index a55cf345bef..77c0fa6a371 100644 --- a/packages/extension-bullet-list/src/bullet-list.ts +++ b/packages/extension-bullet-list/src/bullet-list.ts @@ -55,9 +55,9 @@ export const BulletList = Node.create({ return { toggleBulletList: () => ({ commands, chain }) => { if (this.options.keepAttributes) { - return chain().toggleList(this.name, this.options.itemTypeName).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run() + return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run() } - return commands.toggleList(this.name, this.options.itemTypeName) + return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks) }, } }, diff --git a/packages/extension-ordered-list/src/ordered-list.ts b/packages/extension-ordered-list/src/ordered-list.ts index 6b1e0ea9251..52533bee3fc 100644 --- a/packages/extension-ordered-list/src/ordered-list.ts +++ b/packages/extension-ordered-list/src/ordered-list.ts @@ -74,9 +74,9 @@ export const OrderedList = Node.create({ return { toggleOrderedList: () => ({ commands, chain }) => { if (this.options.keepAttributes) { - return chain().toggleList(this.name, this.options.itemTypeName).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run() + return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run() } - return commands.toggleList(this.name, this.options.itemTypeName) + return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks) }, } }, From f82c85c4415c39c60802d77687dd49829d4a52f5 Mon Sep 17 00:00:00 2001 From: Hari Haran Date: Mon, 13 Feb 2023 20:02:03 +0530 Subject: [PATCH 4/5] fix: conflict --- packages/core/src/commands/toggleList.ts | 27 ++++++++++++------------ 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/core/src/commands/toggleList.ts b/packages/core/src/commands/toggleList.ts index c7e88ff34cc..4842ab6f3a5 100644 --- a/packages/core/src/commands/toggleList.ts +++ b/packages/core/src/commands/toggleList.ts @@ -132,21 +132,22 @@ export const toggleList: RawCommands['toggleList'] = (listTypeOrName, itemTypeOr return ( chain() // try to convert node to default node if needed - .command(() => { - const canWrapInList = can().wrapInList(listType) + .command(() => { + const canWrapInList = can().wrapInList(listType) - const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name)) + const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name)) - tr.ensureMarks(filteredMarks) + tr.ensureMarks(filteredMarks) - if (canWrapInList) { - return true - } + if (canWrapInList) { + return true + } - return commands.clearNodes() - }) - .wrapInList(listType) - .command(() => joinListBackwards(tr, listType)) - .command(() => joinListForwards(tr, listType)) - .run() + return commands.clearNodes() + }) + .wrapInList(listType) + .command(() => joinListBackwards(tr, listType)) + .command(() => joinListForwards(tr, listType)) + .run() + ) } From 50b95b938ff0c6d496414f7b08713bc4fe95e5bc Mon Sep 17 00:00:00 2001 From: Hari Haran Date: Mon, 13 Feb 2023 20:04:09 +0530 Subject: [PATCH 5/5] avoid casting --- packages/core/src/commands/toggleList.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/core/src/commands/toggleList.ts b/packages/core/src/commands/toggleList.ts index 4842ab6f3a5..4aad12c081e 100644 --- a/packages/core/src/commands/toggleList.ts +++ b/packages/core/src/commands/toggleList.ts @@ -5,7 +5,6 @@ import { canJoin } from '@tiptap/pm/transform' import { findParentNode } from '../helpers/findParentNode' import { getNodeType } from '../helpers/getNodeType' import { isList } from '../helpers/isList' -import { Mark } from '../Mark' import { RawCommands } from '../types' const joinListBackwards = (tr: Transaction, listType: NodeType): boolean => { @@ -79,7 +78,7 @@ export const toggleList: RawCommands['toggleList'] = (listTypeOrName, itemTypeOr const { $from, $to } = selection const range = $from.blockRange($to) - const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks()) as Mark[] + const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks()) if (!range) { return false