From a8e478abecb23b8b3e31ea45efc352b5d267cde1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Thu, 5 Nov 2020 14:44:14 +0100 Subject: [PATCH 1/4] reuse attrs for setNodeAttributes and resetNodeAttributes, fix #37 --- packages/core/src/commands/resetNodeAttributes.ts | 1 + packages/core/src/commands/setNodeAttributes.ts | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/src/commands/resetNodeAttributes.ts b/packages/core/src/commands/resetNodeAttributes.ts index dbf1fc65..c7988d18 100644 --- a/packages/core/src/commands/resetNodeAttributes.ts +++ b/packages/core/src/commands/resetNodeAttributes.ts @@ -12,6 +12,7 @@ export default (attributeNames: string[] = []): Command => ({ tr, state, dispatc if (attribute && defaultValue !== undefined && dispatch) { tr.setNodeMarkup(pos, undefined, { + ...node.attrs, [name]: defaultValue, }) } diff --git a/packages/core/src/commands/setNodeAttributes.ts b/packages/core/src/commands/setNodeAttributes.ts index 37b6fc5d..97c9d9c4 100644 --- a/packages/core/src/commands/setNodeAttributes.ts +++ b/packages/core/src/commands/setNodeAttributes.ts @@ -6,7 +6,10 @@ export default (attributes: {}): Command => ({ tr, state, dispatch }) => { state.doc.nodesBetween(from, to, (node, pos) => { if (!node.type.isText && dispatch) { - tr.setNodeMarkup(pos, undefined, attributes) + tr.setNodeMarkup(pos, undefined, { + ...node.attrs, + ...attributes, + }) } }) From d081e81991604ec0c3d53f39492d8f01a41e230c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Thu, 5 Nov 2020 14:51:34 +0100 Subject: [PATCH 2/4] fix task list name --- packages/extension-task-item/index.ts | 2 +- packages/extension-task-list/index.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/extension-task-item/index.ts b/packages/extension-task-item/index.ts index 7652cd10..248164c4 100644 --- a/packages/extension-task-item/index.ts +++ b/packages/extension-task-item/index.ts @@ -11,7 +11,7 @@ const TaskItem = createNode({ name: 'taskItem', content() { - return this.options.nested ? '(paragraph|task_list)+' : 'paragraph+' + return this.options.nested ? '(paragraph|taskList)+' : 'paragraph+' }, defining: true, diff --git a/packages/extension-task-list/index.ts b/packages/extension-task-list/index.ts index adc9b63b..21fc7545 100644 --- a/packages/extension-task-list/index.ts +++ b/packages/extension-task-list/index.ts @@ -1,7 +1,7 @@ import { Command, createNode, mergeAttributes } from '@tiptap/core' const TaskList = createNode({ - name: 'task_list', + name: 'taskList', group: 'block list', @@ -10,20 +10,20 @@ const TaskList = createNode({ parseHTML() { return [ { - tag: 'ul[data-type="task_list"]', + tag: 'ul[data-type="taskList"]', priority: 51, }, ] }, renderHTML({ attributes }) { - return ['ul', mergeAttributes(attributes, { 'data-type': 'task_list' }), 0] + return ['ul', mergeAttributes(attributes, { 'data-type': 'taskList' }), 0] }, addCommands() { return { taskList: (): Command => ({ commands }) => { - return commands.toggleList('task_list', 'taskItem') + return commands.toggleList('taskList', 'taskItem') }, } }, From 5a9e8ce522e5b4424be6ccf829bcdc60cb7c4852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Thu, 5 Nov 2020 14:52:11 +0100 Subject: [PATCH 3/4] fixx task list style --- docs/src/demos/Nodes/TaskList/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/demos/Nodes/TaskList/index.vue b/docs/src/demos/Nodes/TaskList/index.vue index edc67a69..6baf52e5 100644 --- a/docs/src/demos/Nodes/TaskList/index.vue +++ b/docs/src/demos/Nodes/TaskList/index.vue @@ -53,7 +53,7 @@ export default {