fix: remove some magic strings

This commit is contained in:
Philipp Kühn
2021-12-02 14:56:57 +01:00
parent dedcf17d53
commit 6c34dec33a
25 changed files with 61 additions and 60 deletions

View File

@@ -28,7 +28,7 @@ export default () => {
], ],
content: ` content: `
<p> <p>
What do you all think about the new <span data-mention data-id="Winona Ryder"></span> movie? What do you all think about the new <span data-type="mention" data-id="Winona Ryder"></span> movie?
</p> </p>
`, `,
}) })

View File

@@ -79,7 +79,7 @@ export default {
], ],
content: ` content: `
<p> <p>
What do you all think about the new <span data-mention data-id="Winona Ryder"></span> movie? What do you all think about the new <span data-type="mention" data-id="Winona Ryder"></span> movie?
</p> </p>
`, `,
}) })

View File

@@ -22,9 +22,9 @@ export default () => {
], ],
content: ` content: `
<p>Hi everyone! Dont forget the daily stand up at 8 AM.</p> <p>Hi everyone! Dont forget the daily stand up at 8 AM.</p>
<p><span data-mention data-id="Jennifer Grey"></span> Would you mind to share what youve been working on lately? We fear not much happened since Dirty Dancing. <p><span data-type="mention" data-id="Jennifer Grey"></span> Would you mind to share what youve been working on lately? We fear not much happened since Dirty Dancing.
<p><span data-mention data-id="Winona Ryder"></span> <span data-mention data-id="Axl Rose"></span> Lets go through your most important points quickly.</p> <p><span data-type="mention" data-id="Winona Ryder"></span> <span data-type="mention" data-id="Axl Rose"></span> Lets go through your most important points quickly.</p>
<p>I have a meeting with <span data-mention data-id="Christina Applegate"></span> and dont want to come late.</p> <p>I have a meeting with <span data-type="mention" data-id="Christina Applegate"></span> and dont want to come late.</p>
<p> Thanks, your big boss</p> <p> Thanks, your big boss</p>
`, `,
}) })

View File

@@ -38,9 +38,9 @@ export default {
], ],
content: ` content: `
<p>Hi everyone! Dont forget the daily stand up at 8 AM.</p> <p>Hi everyone! Dont forget the daily stand up at 8 AM.</p>
<p><span data-mention data-id="Jennifer Grey"></span> Would you mind to share what youve been working on lately? We fear not much happened since Dirty Dancing. <p><span data-type="mention" data-id="Jennifer Grey"></span> Would you mind to share what youve been working on lately? We fear not much happened since Dirty Dancing.
<p><span data-mention data-id="Winona Ryder"></span> <span data-mention data-id="Axl Rose"></span> Lets go through your most important points quickly.</p> <p><span data-type="mention" data-id="Winona Ryder"></span> <span data-type="mention" data-id="Axl Rose"></span> Lets go through your most important points quickly.</p>
<p>I have a meeting with <span data-mention data-id="Christina Applegate"></span> and dont want to come late.</p> <p>I have a meeting with <span data-type="mention" data-id="Christina Applegate"></span> and dont want to come late.</p>
<p> Thanks, your big boss</p> <p> Thanks, your big boss</p>
`, `,
}) })

View File

@@ -54,13 +54,13 @@ export const Blockquote = Node.create<BlockquoteOptions>({
addCommands() { addCommands() {
return { return {
setBlockquote: () => ({ commands }) => { setBlockquote: () => ({ commands }) => {
return commands.wrapIn('blockquote') return commands.wrapIn(this.name)
}, },
toggleBlockquote: () => ({ commands }) => { toggleBlockquote: () => ({ commands }) => {
return commands.toggleWrap('blockquote') return commands.toggleWrap(this.name)
}, },
unsetBlockquote: () => ({ commands }) => { unsetBlockquote: () => ({ commands }) => {
return commands.lift('blockquote') return commands.lift(this.name)
}, },
} }
}, },

View File

@@ -65,13 +65,13 @@ export const Bold = Mark.create<BoldOptions>({
addCommands() { addCommands() {
return { return {
setBold: () => ({ commands }) => { setBold: () => ({ commands }) => {
return commands.setMark('bold') return commands.setMark(this.name)
}, },
toggleBold: () => ({ commands }) => { toggleBold: () => ({ commands }) => {
return commands.toggleMark('bold') return commands.toggleMark(this.name)
}, },
unsetBold: () => ({ commands }) => { unsetBold: () => ({ commands }) => {
return commands.unsetMark('bold') return commands.unsetMark(this.name)
}, },
} }
}, },

View File

@@ -43,7 +43,7 @@ export const BulletList = Node.create<BulletListOptions>({
addCommands() { addCommands() {
return { return {
toggleBulletList: () => ({ commands }) => { toggleBulletList: () => ({ commands }) => {
return commands.toggleList('bulletList', 'listItem') return commands.toggleList(this.name, 'listItem')
}, },
} }
}, },

View File

@@ -91,10 +91,10 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
addCommands() { addCommands() {
return { return {
setCodeBlock: attributes => ({ commands }) => { setCodeBlock: attributes => ({ commands }) => {
return commands.setNode('codeBlock', attributes) return commands.setNode(this.name, attributes)
}, },
toggleCodeBlock: attributes => ({ commands }) => { toggleCodeBlock: attributes => ({ commands }) => {
return commands.toggleNode('codeBlock', 'paragraph', attributes) return commands.toggleNode(this.name, 'paragraph', attributes)
}, },
} }
}, },

View File

@@ -57,13 +57,13 @@ export const Code = Mark.create<CodeOptions>({
addCommands() { addCommands() {
return { return {
setCode: () => ({ commands }) => { setCode: () => ({ commands }) => {
return commands.setMark('code') return commands.setMark(this.name)
}, },
toggleCode: () => ({ commands }) => { toggleCode: () => ({ commands }) => {
return commands.toggleMark('code') return commands.toggleMark(this.name)
}, },
unsetCode: () => ({ commands }) => { unsetCode: () => ({ commands }) => {
return commands.unsetMark('code') return commands.unsetMark(this.name)
}, },
} }
}, },

View File

@@ -71,14 +71,14 @@ export const Heading = Node.create<HeadingOptions>({
return false return false
} }
return commands.setNode('heading', attributes) return commands.setNode(this.name, attributes)
}, },
toggleHeading: attributes => ({ commands }) => { toggleHeading: attributes => ({ commands }) => {
if (!this.options.levels.includes(attributes.level)) { if (!this.options.levels.includes(attributes.level)) {
return false return false
} }
return commands.toggleNode('heading', 'paragraph', attributes) return commands.toggleNode(this.name, 'paragraph', attributes)
}, },
} }
}, },

View File

@@ -80,13 +80,13 @@ export const Highlight = Mark.create<HighlightOptions>({
addCommands() { addCommands() {
return { return {
setHighlight: attributes => ({ commands }) => { setHighlight: attributes => ({ commands }) => {
return commands.setMark('highlight', attributes) return commands.setMark(this.name, attributes)
}, },
toggleHighlight: attributes => ({ commands }) => { toggleHighlight: attributes => ({ commands }) => {
return commands.toggleMark('highlight', attributes) return commands.toggleMark(this.name, attributes)
}, },
unsetHighlight: () => ({ commands }) => { unsetHighlight: () => ({ commands }) => {
return commands.unsetMark('highlight') return commands.unsetMark(this.name)
}, },
} }
}, },

View File

@@ -64,13 +64,13 @@ export const Italic = Mark.create<ItalicOptions>({
addCommands() { addCommands() {
return { return {
setItalic: () => ({ commands }) => { setItalic: () => ({ commands }) => {
return commands.setMark('italic') return commands.setMark(this.name)
}, },
toggleItalic: () => ({ commands }) => { toggleItalic: () => ({ commands }) => {
return commands.toggleMark('italic') return commands.toggleMark(this.name)
}, },
unsetItalic: () => ({ commands }) => { unsetItalic: () => ({ commands }) => {
return commands.unsetMark('italic') return commands.unsetMark(this.name)
}, },
} }
}, },

View File

@@ -82,13 +82,13 @@ export const Link = Mark.create<LinkOptions>({
addCommands() { addCommands() {
return { return {
setLink: attributes => ({ commands }) => { setLink: attributes => ({ commands }) => {
return commands.setMark('link', attributes) return commands.setMark(this.name, attributes)
}, },
toggleLink: attributes => ({ commands }) => { toggleLink: attributes => ({ commands }) => {
return commands.toggleMark('link', attributes, { extendEmptyMarkRange: true }) return commands.toggleMark(this.name, attributes, { extendEmptyMarkRange: true })
}, },
unsetLink: () => ({ commands }) => { unsetLink: () => ({ commands }) => {
return commands.unsetMark('link', { extendEmptyMarkRange: true }) return commands.unsetMark(this.name, { extendEmptyMarkRange: true })
}, },
} }
}, },
@@ -120,7 +120,7 @@ export const Link = Mark.create<LinkOptions>({
key: new PluginKey('handleClickLink'), key: new PluginKey('handleClickLink'),
props: { props: {
handleClick: (view, pos, event) => { 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') const link = (event.target as HTMLElement)?.closest('a')
if (link && attrs.href) { if (link && attrs.href) {

View File

@@ -31,9 +31,9 @@ export const ListItem = Node.create<ListItemOptions>({
addKeyboardShortcuts() { addKeyboardShortcuts() {
return { return {
Enter: () => this.editor.commands.splitListItem('listItem'), Enter: () => this.editor.commands.splitListItem(this.name),
Tab: () => this.editor.commands.sinkListItem('listItem'), Tab: () => this.editor.commands.sinkListItem(this.name),
'Shift-Tab': () => this.editor.commands.liftListItem('listItem'), 'Shift-Tab': () => this.editor.commands.liftListItem(this.name),
} }
}, },
}) })

View File

@@ -105,7 +105,7 @@ export const Mention = Node.create<MentionOptions>({
parseHTML() { parseHTML() {
return [ return [
{ {
tag: 'span[data-mention]', tag: `span[data-type="${this.name}"]`,
}, },
] ]
}, },
@@ -113,7 +113,7 @@ export const Mention = Node.create<MentionOptions>({
renderHTML({ node, HTMLAttributes }) { renderHTML({ node, HTMLAttributes }) {
return [ return [
'span', 'span',
mergeAttributes({ 'data-mention': '' }, this.options.HTMLAttributes, HTMLAttributes), mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),
this.options.renderLabel({ this.options.renderLabel({
options: this.options, options: this.options,
node, node,

View File

@@ -62,7 +62,7 @@ export const OrderedList = Node.create<OrderedListOptions>({
addCommands() { addCommands() {
return { return {
toggleOrderedList: () => ({ commands }) => { toggleOrderedList: () => ({ commands }) => {
return commands.toggleList('orderedList', 'listItem') return commands.toggleList(this.name, 'listItem')
}, },
} }
}, },

View File

@@ -43,7 +43,7 @@ export const Paragraph = Node.create<ParagraphOptions>({
addCommands() { addCommands() {
return { return {
setParagraph: () => ({ commands }) => { setParagraph: () => ({ commands }) => {
return commands.setNode('paragraph') return commands.setNode(this.name)
}, },
} }
}, },

View File

@@ -66,13 +66,13 @@ export const Strike = Mark.create<StrikeOptions>({
addCommands() { addCommands() {
return { return {
setStrike: () => ({ commands }) => { setStrike: () => ({ commands }) => {
return commands.setMark('strike') return commands.setMark(this.name)
}, },
toggleStrike: () => ({ commands }) => { toggleStrike: () => ({ commands }) => {
return commands.toggleMark('strike') return commands.toggleMark(this.name)
}, },
unsetStrike: () => ({ commands }) => { unsetStrike: () => ({ commands }) => {
return commands.unsetMark('strike') return commands.unsetMark(this.name)
}, },
} }
}, },

View File

@@ -58,13 +58,13 @@ export const Subscript = Mark.create<SubscriptExtensionOptions>({
addCommands() { addCommands() {
return { return {
setSubscript: () => ({ commands }) => { setSubscript: () => ({ commands }) => {
return commands.setMark('subscript') return commands.setMark(this.name)
}, },
toggleSubscript: () => ({ commands }) => { toggleSubscript: () => ({ commands }) => {
return commands.toggleMark('subscript') return commands.toggleMark(this.name)
}, },
unsetSubscript: () => ({ commands }) => { unsetSubscript: () => ({ commands }) => {
return commands.unsetMark('subscript') return commands.unsetMark(this.name)
}, },
} }
}, },

View File

@@ -58,13 +58,13 @@ export const Superscript = Mark.create<SuperscriptExtensionOptions>({
addCommands() { addCommands() {
return { return {
setSuperscript: () => ({ commands }) => { setSuperscript: () => ({ commands }) => {
return commands.setMark('superscript') return commands.setMark(this.name)
}, },
toggleSuperscript: () => ({ commands }) => { toggleSuperscript: () => ({ commands }) => {
return commands.toggleMark('superscript') return commands.toggleMark(this.name)
}, },
unsetSuperscript: () => ({ commands }) => { unsetSuperscript: () => ({ commands }) => {
return commands.unsetMark('superscript') return commands.unsetMark(this.name)
}, },
} }
}, },

View File

@@ -39,7 +39,7 @@ export const TaskItem = Node.create<TaskItemOptions>({
parseHTML() { parseHTML() {
return [ return [
{ {
tag: 'li[data-type="taskItem"]', tag: `li[data-type="${this.name}"]`,
priority: 51, priority: 51,
}, },
] ]
@@ -51,7 +51,7 @@ export const TaskItem = Node.create<TaskItemOptions>({
mergeAttributes( mergeAttributes(
this.options.HTMLAttributes, this.options.HTMLAttributes,
HTMLAttributes, HTMLAttributes,
{ 'data-type': 'taskItem' }, { 'data-type': this.name },
), ),
[ [
'label', 'label',
@@ -75,8 +75,8 @@ export const TaskItem = Node.create<TaskItemOptions>({
addKeyboardShortcuts() { addKeyboardShortcuts() {
const shortcuts = { const shortcuts = {
Enter: () => this.editor.commands.splitListItem('taskItem'), Enter: () => this.editor.commands.splitListItem(this.name),
'Shift-Tab': () => this.editor.commands.liftListItem('taskItem'), 'Shift-Tab': () => this.editor.commands.liftListItem(this.name),
} }
if (!this.options.nested) { if (!this.options.nested) {
@@ -85,7 +85,7 @@ export const TaskItem = Node.create<TaskItemOptions>({
return { return {
...shortcuts, ...shortcuts,
Tab: () => this.editor.commands.sinkListItem('taskItem'), Tab: () => this.editor.commands.sinkListItem(this.name),
} }
}, },

View File

@@ -31,20 +31,20 @@ export const TaskList = Node.create<TaskListOptions>({
parseHTML() { parseHTML() {
return [ return [
{ {
tag: 'ul[data-type="taskList"]', tag: `ul[data-type="${this.name}"]`,
priority: 51, priority: 51,
}, },
] ]
}, },
renderHTML({ HTMLAttributes }) { 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() { addCommands() {
return { return {
toggleTaskList: () => ({ commands }) => { toggleTaskList: () => ({ commands }) => {
return commands.toggleList('taskList', 'taskItem') return commands.toggleList(this.name, 'taskItem')
}, },
} }
}, },

View File

@@ -62,6 +62,7 @@ export const TextAlign = Extension.create<TextAlignOptions>({
return this.options.types.every(type => commands.updateAttributes(type, { textAlign: alignment })) return this.options.types.every(type => commands.updateAttributes(type, { textAlign: alignment }))
}, },
unsetTextAlign: () => ({ commands }) => { unsetTextAlign: () => ({ commands }) => {
return this.options.types.every(type => commands.resetAttributes(type, 'textAlign')) return this.options.types.every(type => commands.resetAttributes(type, 'textAlign'))
}, },

View File

@@ -59,7 +59,7 @@ export const TextStyle = Mark.create<TextStyleOptions>({
return true return true
} }
return commands.unsetMark('textStyle') return commands.unsetMark(this.name)
}, },
} }
}, },

View File

@@ -52,13 +52,13 @@ export const Underline = Mark.create<UnderlineOptions>({
addCommands() { addCommands() {
return { return {
setUnderline: () => ({ commands }) => { setUnderline: () => ({ commands }) => {
return commands.setMark('underline') return commands.setMark(this.name)
}, },
toggleUnderline: () => ({ commands }) => { toggleUnderline: () => ({ commands }) => {
return commands.toggleMark('underline') return commands.toggleMark(this.name)
}, },
unsetUnderline: () => ({ commands }) => { unsetUnderline: () => ({ commands }) => {
return commands.unsetMark('underline') return commands.unsetMark(this.name)
}, },
} }
}, },