From 6c34dec33ac39c9f037a0a72e4525f3fc6d422bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20K=C3=BChn?= Date: Thu, 2 Dec 2021 14:56:57 +0100 Subject: [PATCH] fix: remove some magic strings --- demos/src/Examples/Community/React/index.jsx | 2 +- demos/src/Examples/Community/Vue/index.vue | 2 +- demos/src/Nodes/Mention/React/index.jsx | 6 +++--- demos/src/Nodes/Mention/Vue/index.vue | 6 +++--- packages/extension-blockquote/src/blockquote.ts | 6 +++--- packages/extension-bold/src/bold.ts | 6 +++--- packages/extension-bullet-list/src/bullet-list.ts | 2 +- packages/extension-code-block/src/code-block.ts | 4 ++-- packages/extension-code/src/code.ts | 6 +++--- packages/extension-heading/src/heading.ts | 4 ++-- packages/extension-highlight/src/highlight.ts | 6 +++--- packages/extension-italic/src/italic.ts | 6 +++--- packages/extension-link/src/link.ts | 8 ++++---- packages/extension-list-item/src/list-item.ts | 6 +++--- packages/extension-mention/src/mention.ts | 4 ++-- packages/extension-ordered-list/src/ordered-list.ts | 2 +- packages/extension-paragraph/src/paragraph.ts | 2 +- packages/extension-strike/src/strike.ts | 6 +++--- packages/extension-subscript/src/subscript.ts | 6 +++--- packages/extension-superscript/src/superscript.ts | 6 +++--- packages/extension-task-item/src/task-item.ts | 10 +++++----- packages/extension-task-list/src/task-list.ts | 6 +++--- packages/extension-text-align/src/text-align.ts | 1 + packages/extension-text-style/src/text-style.ts | 2 +- packages/extension-underline/src/underline.ts | 6 +++--- 25 files changed, 61 insertions(+), 60 deletions(-) diff --git a/demos/src/Examples/Community/React/index.jsx b/demos/src/Examples/Community/React/index.jsx index fdb6bf26c..51bd1e33d 100644 --- a/demos/src/Examples/Community/React/index.jsx +++ b/demos/src/Examples/Community/React/index.jsx @@ -28,7 +28,7 @@ export default () => { ], content: `

- What do you all think about the new movie? + What do you all think about the new movie?

`, }) diff --git a/demos/src/Examples/Community/Vue/index.vue b/demos/src/Examples/Community/Vue/index.vue index 7c2647dea..95d60eb87 100644 --- a/demos/src/Examples/Community/Vue/index.vue +++ b/demos/src/Examples/Community/Vue/index.vue @@ -79,7 +79,7 @@ export default { ], content: `

- What do you all think about the new movie? + What do you all think about the new movie?

`, }) diff --git a/demos/src/Nodes/Mention/React/index.jsx b/demos/src/Nodes/Mention/React/index.jsx index 38c2bef9e..adbd62a95 100644 --- a/demos/src/Nodes/Mention/React/index.jsx +++ b/demos/src/Nodes/Mention/React/index.jsx @@ -22,9 +22,9 @@ export default () => { ], content: `

Hi everyone! Don’t forget the daily stand up at 8 AM.

-

Would you mind to share what you’ve been working on lately? We fear not much happened since Dirty Dancing. -

Let’s go through your most important points quickly.

-

I have a meeting with and don’t want to come late.

+

Would you mind to share what you’ve been working on lately? We fear not much happened since Dirty Dancing. +

Let’s go through your most important points quickly.

+

I have a meeting with and don’t want to come late.

– Thanks, your big boss

`, }) diff --git a/demos/src/Nodes/Mention/Vue/index.vue b/demos/src/Nodes/Mention/Vue/index.vue index f14a03dee..2862e5177 100644 --- a/demos/src/Nodes/Mention/Vue/index.vue +++ b/demos/src/Nodes/Mention/Vue/index.vue @@ -38,9 +38,9 @@ export default { ], content: `

Hi everyone! Don’t forget the daily stand up at 8 AM.

-

Would you mind to share what you’ve been working on lately? We fear not much happened since Dirty Dancing. -

Let’s go through your most important points quickly.

-

I have a meeting with and don’t want to come late.

+

Would you mind to share what you’ve been working on lately? We fear not much happened since Dirty Dancing. +

Let’s go through your most important points quickly.

+

I have a meeting with and don’t want to come late.

– Thanks, your big boss

`, }) diff --git a/packages/extension-blockquote/src/blockquote.ts b/packages/extension-blockquote/src/blockquote.ts index 554ec1d45..734ab881d 100644 --- a/packages/extension-blockquote/src/blockquote.ts +++ b/packages/extension-blockquote/src/blockquote.ts @@ -54,13 +54,13 @@ export const Blockquote = Node.create({ addCommands() { return { setBlockquote: () => ({ commands }) => { - return commands.wrapIn('blockquote') + return commands.wrapIn(this.name) }, toggleBlockquote: () => ({ commands }) => { - return commands.toggleWrap('blockquote') + return commands.toggleWrap(this.name) }, unsetBlockquote: () => ({ commands }) => { - return commands.lift('blockquote') + return commands.lift(this.name) }, } }, diff --git a/packages/extension-bold/src/bold.ts b/packages/extension-bold/src/bold.ts index 71c26e179..2593ad1fb 100644 --- a/packages/extension-bold/src/bold.ts +++ b/packages/extension-bold/src/bold.ts @@ -65,13 +65,13 @@ export const Bold = Mark.create({ addCommands() { return { setBold: () => ({ commands }) => { - return commands.setMark('bold') + return commands.setMark(this.name) }, toggleBold: () => ({ commands }) => { - return commands.toggleMark('bold') + return commands.toggleMark(this.name) }, unsetBold: () => ({ commands }) => { - return commands.unsetMark('bold') + return commands.unsetMark(this.name) }, } }, diff --git a/packages/extension-bullet-list/src/bullet-list.ts b/packages/extension-bullet-list/src/bullet-list.ts index 08b05b662..4679cebba 100644 --- a/packages/extension-bullet-list/src/bullet-list.ts +++ b/packages/extension-bullet-list/src/bullet-list.ts @@ -43,7 +43,7 @@ export const BulletList = Node.create({ addCommands() { return { toggleBulletList: () => ({ commands }) => { - return commands.toggleList('bulletList', 'listItem') + return commands.toggleList(this.name, 'listItem') }, } }, diff --git a/packages/extension-code-block/src/code-block.ts b/packages/extension-code-block/src/code-block.ts index b19085a55..bf4568f65 100644 --- a/packages/extension-code-block/src/code-block.ts +++ b/packages/extension-code-block/src/code-block.ts @@ -91,10 +91,10 @@ export const CodeBlock = Node.create({ addCommands() { return { setCodeBlock: attributes => ({ commands }) => { - return commands.setNode('codeBlock', attributes) + return commands.setNode(this.name, attributes) }, toggleCodeBlock: attributes => ({ commands }) => { - return commands.toggleNode('codeBlock', 'paragraph', attributes) + return commands.toggleNode(this.name, 'paragraph', attributes) }, } }, diff --git a/packages/extension-code/src/code.ts b/packages/extension-code/src/code.ts index ea99ca673..a8b78b8ec 100644 --- a/packages/extension-code/src/code.ts +++ b/packages/extension-code/src/code.ts @@ -57,13 +57,13 @@ export const Code = Mark.create({ addCommands() { return { setCode: () => ({ commands }) => { - return commands.setMark('code') + return commands.setMark(this.name) }, toggleCode: () => ({ commands }) => { - return commands.toggleMark('code') + return commands.toggleMark(this.name) }, unsetCode: () => ({ commands }) => { - return commands.unsetMark('code') + return commands.unsetMark(this.name) }, } }, diff --git a/packages/extension-heading/src/heading.ts b/packages/extension-heading/src/heading.ts index 346bcb9fe..53625d58a 100644 --- a/packages/extension-heading/src/heading.ts +++ b/packages/extension-heading/src/heading.ts @@ -71,14 +71,14 @@ export const Heading = Node.create({ return false } - return commands.setNode('heading', attributes) + return commands.setNode(this.name, attributes) }, toggleHeading: attributes => ({ commands }) => { if (!this.options.levels.includes(attributes.level)) { return false } - return commands.toggleNode('heading', 'paragraph', attributes) + return commands.toggleNode(this.name, 'paragraph', attributes) }, } }, diff --git a/packages/extension-highlight/src/highlight.ts b/packages/extension-highlight/src/highlight.ts index 8f8a83741..3d3b8af73 100644 --- a/packages/extension-highlight/src/highlight.ts +++ b/packages/extension-highlight/src/highlight.ts @@ -80,13 +80,13 @@ export const Highlight = Mark.create({ addCommands() { return { setHighlight: attributes => ({ commands }) => { - return commands.setMark('highlight', attributes) + return commands.setMark(this.name, attributes) }, toggleHighlight: attributes => ({ commands }) => { - return commands.toggleMark('highlight', attributes) + return commands.toggleMark(this.name, attributes) }, unsetHighlight: () => ({ commands }) => { - return commands.unsetMark('highlight') + return commands.unsetMark(this.name) }, } }, diff --git a/packages/extension-italic/src/italic.ts b/packages/extension-italic/src/italic.ts index 705f5b19a..5aeae3a02 100644 --- a/packages/extension-italic/src/italic.ts +++ b/packages/extension-italic/src/italic.ts @@ -64,13 +64,13 @@ export const Italic = Mark.create({ addCommands() { return { setItalic: () => ({ commands }) => { - return commands.setMark('italic') + return commands.setMark(this.name) }, toggleItalic: () => ({ commands }) => { - return commands.toggleMark('italic') + return commands.toggleMark(this.name) }, unsetItalic: () => ({ commands }) => { - return commands.unsetMark('italic') + return commands.unsetMark(this.name) }, } }, diff --git a/packages/extension-link/src/link.ts b/packages/extension-link/src/link.ts index 108806c93..9caa99437 100644 --- a/packages/extension-link/src/link.ts +++ b/packages/extension-link/src/link.ts @@ -82,13 +82,13 @@ export const Link = Mark.create({ addCommands() { return { setLink: attributes => ({ commands }) => { - return commands.setMark('link', attributes) + return commands.setMark(this.name, attributes) }, toggleLink: attributes => ({ commands }) => { - return commands.toggleMark('link', attributes, { extendEmptyMarkRange: true }) + return commands.toggleMark(this.name, attributes, { extendEmptyMarkRange: true }) }, unsetLink: () => ({ commands }) => { - return commands.unsetMark('link', { extendEmptyMarkRange: true }) + return commands.unsetMark(this.name, { extendEmptyMarkRange: true }) }, } }, @@ -120,7 +120,7 @@ export const Link = Mark.create({ key: new PluginKey('handleClickLink'), props: { handleClick: (view, pos, event) => { - const attrs = this.editor.getAttributes('link') + const attrs = this.editor.getAttributes(this.name) const link = (event.target as HTMLElement)?.closest('a') if (link && attrs.href) { diff --git a/packages/extension-list-item/src/list-item.ts b/packages/extension-list-item/src/list-item.ts index 4845a623b..cf3ea4510 100644 --- a/packages/extension-list-item/src/list-item.ts +++ b/packages/extension-list-item/src/list-item.ts @@ -31,9 +31,9 @@ export const ListItem = Node.create({ addKeyboardShortcuts() { return { - Enter: () => this.editor.commands.splitListItem('listItem'), - Tab: () => this.editor.commands.sinkListItem('listItem'), - 'Shift-Tab': () => this.editor.commands.liftListItem('listItem'), + Enter: () => this.editor.commands.splitListItem(this.name), + Tab: () => this.editor.commands.sinkListItem(this.name), + 'Shift-Tab': () => this.editor.commands.liftListItem(this.name), } }, }) diff --git a/packages/extension-mention/src/mention.ts b/packages/extension-mention/src/mention.ts index a50249cb5..69ed1011b 100644 --- a/packages/extension-mention/src/mention.ts +++ b/packages/extension-mention/src/mention.ts @@ -105,7 +105,7 @@ export const Mention = Node.create({ parseHTML() { return [ { - tag: 'span[data-mention]', + tag: `span[data-type="${this.name}"]`, }, ] }, @@ -113,7 +113,7 @@ export const Mention = Node.create({ renderHTML({ node, HTMLAttributes }) { return [ 'span', - mergeAttributes({ 'data-mention': '' }, this.options.HTMLAttributes, HTMLAttributes), + mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes), this.options.renderLabel({ options: this.options, node, diff --git a/packages/extension-ordered-list/src/ordered-list.ts b/packages/extension-ordered-list/src/ordered-list.ts index a57dae69d..b6f64cb87 100644 --- a/packages/extension-ordered-list/src/ordered-list.ts +++ b/packages/extension-ordered-list/src/ordered-list.ts @@ -62,7 +62,7 @@ export const OrderedList = Node.create({ addCommands() { return { toggleOrderedList: () => ({ commands }) => { - return commands.toggleList('orderedList', 'listItem') + return commands.toggleList(this.name, 'listItem') }, } }, diff --git a/packages/extension-paragraph/src/paragraph.ts b/packages/extension-paragraph/src/paragraph.ts index bf146932b..d442fd53b 100644 --- a/packages/extension-paragraph/src/paragraph.ts +++ b/packages/extension-paragraph/src/paragraph.ts @@ -43,7 +43,7 @@ export const Paragraph = Node.create({ addCommands() { return { setParagraph: () => ({ commands }) => { - return commands.setNode('paragraph') + return commands.setNode(this.name) }, } }, diff --git a/packages/extension-strike/src/strike.ts b/packages/extension-strike/src/strike.ts index 5d8711b26..a232a39d0 100644 --- a/packages/extension-strike/src/strike.ts +++ b/packages/extension-strike/src/strike.ts @@ -66,13 +66,13 @@ export const Strike = Mark.create({ addCommands() { return { setStrike: () => ({ commands }) => { - return commands.setMark('strike') + return commands.setMark(this.name) }, toggleStrike: () => ({ commands }) => { - return commands.toggleMark('strike') + return commands.toggleMark(this.name) }, unsetStrike: () => ({ commands }) => { - return commands.unsetMark('strike') + return commands.unsetMark(this.name) }, } }, diff --git a/packages/extension-subscript/src/subscript.ts b/packages/extension-subscript/src/subscript.ts index e99ff2229..2861eeb63 100644 --- a/packages/extension-subscript/src/subscript.ts +++ b/packages/extension-subscript/src/subscript.ts @@ -58,13 +58,13 @@ export const Subscript = Mark.create({ addCommands() { return { setSubscript: () => ({ commands }) => { - return commands.setMark('subscript') + return commands.setMark(this.name) }, toggleSubscript: () => ({ commands }) => { - return commands.toggleMark('subscript') + return commands.toggleMark(this.name) }, unsetSubscript: () => ({ commands }) => { - return commands.unsetMark('subscript') + return commands.unsetMark(this.name) }, } }, diff --git a/packages/extension-superscript/src/superscript.ts b/packages/extension-superscript/src/superscript.ts index 6d3a1cba0..f0b888e72 100644 --- a/packages/extension-superscript/src/superscript.ts +++ b/packages/extension-superscript/src/superscript.ts @@ -58,13 +58,13 @@ export const Superscript = Mark.create({ addCommands() { return { setSuperscript: () => ({ commands }) => { - return commands.setMark('superscript') + return commands.setMark(this.name) }, toggleSuperscript: () => ({ commands }) => { - return commands.toggleMark('superscript') + return commands.toggleMark(this.name) }, unsetSuperscript: () => ({ commands }) => { - return commands.unsetMark('superscript') + return commands.unsetMark(this.name) }, } }, diff --git a/packages/extension-task-item/src/task-item.ts b/packages/extension-task-item/src/task-item.ts index c11dc1e78..f0b309cb0 100644 --- a/packages/extension-task-item/src/task-item.ts +++ b/packages/extension-task-item/src/task-item.ts @@ -39,7 +39,7 @@ export const TaskItem = Node.create({ parseHTML() { return [ { - tag: 'li[data-type="taskItem"]', + tag: `li[data-type="${this.name}"]`, priority: 51, }, ] @@ -51,7 +51,7 @@ export const TaskItem = Node.create({ mergeAttributes( this.options.HTMLAttributes, HTMLAttributes, - { 'data-type': 'taskItem' }, + { 'data-type': this.name }, ), [ 'label', @@ -75,8 +75,8 @@ export const TaskItem = Node.create({ addKeyboardShortcuts() { const shortcuts = { - Enter: () => this.editor.commands.splitListItem('taskItem'), - 'Shift-Tab': () => this.editor.commands.liftListItem('taskItem'), + Enter: () => this.editor.commands.splitListItem(this.name), + 'Shift-Tab': () => this.editor.commands.liftListItem(this.name), } if (!this.options.nested) { @@ -85,7 +85,7 @@ export const TaskItem = Node.create({ return { ...shortcuts, - Tab: () => this.editor.commands.sinkListItem('taskItem'), + Tab: () => this.editor.commands.sinkListItem(this.name), } }, diff --git a/packages/extension-task-list/src/task-list.ts b/packages/extension-task-list/src/task-list.ts index 2dfc0521b..b317d76a6 100644 --- a/packages/extension-task-list/src/task-list.ts +++ b/packages/extension-task-list/src/task-list.ts @@ -31,20 +31,20 @@ export const TaskList = Node.create({ parseHTML() { return [ { - tag: 'ul[data-type="taskList"]', + tag: `ul[data-type="${this.name}"]`, priority: 51, }, ] }, renderHTML({ HTMLAttributes }) { - return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { 'data-type': 'taskList' }), 0] + return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { 'data-type': this.name }), 0] }, addCommands() { return { toggleTaskList: () => ({ commands }) => { - return commands.toggleList('taskList', 'taskItem') + return commands.toggleList(this.name, 'taskItem') }, } }, diff --git a/packages/extension-text-align/src/text-align.ts b/packages/extension-text-align/src/text-align.ts index ce3109d9d..40d52ae09 100644 --- a/packages/extension-text-align/src/text-align.ts +++ b/packages/extension-text-align/src/text-align.ts @@ -62,6 +62,7 @@ export const TextAlign = Extension.create({ return this.options.types.every(type => commands.updateAttributes(type, { textAlign: alignment })) }, + unsetTextAlign: () => ({ commands }) => { return this.options.types.every(type => commands.resetAttributes(type, 'textAlign')) }, diff --git a/packages/extension-text-style/src/text-style.ts b/packages/extension-text-style/src/text-style.ts index 0fc9daf30..dc9454a25 100644 --- a/packages/extension-text-style/src/text-style.ts +++ b/packages/extension-text-style/src/text-style.ts @@ -59,7 +59,7 @@ export const TextStyle = Mark.create({ return true } - return commands.unsetMark('textStyle') + return commands.unsetMark(this.name) }, } }, diff --git a/packages/extension-underline/src/underline.ts b/packages/extension-underline/src/underline.ts index 05344ac34..5403eb012 100644 --- a/packages/extension-underline/src/underline.ts +++ b/packages/extension-underline/src/underline.ts @@ -52,13 +52,13 @@ export const Underline = Mark.create({ addCommands() { return { setUnderline: () => ({ commands }) => { - return commands.setMark('underline') + return commands.setMark(this.name) }, toggleUnderline: () => ({ commands }) => { - return commands.toggleMark('underline') + return commands.toggleMark(this.name) }, unsetUnderline: () => ({ commands }) => { - return commands.unsetMark('underline') + return commands.unsetMark(this.name) }, } },