rename attributes to HTMLAttributes

This commit is contained in:
Philipp Kühn 2020-11-13 16:07:20 +01:00
parent 5bccbacf32
commit c840a562de
25 changed files with 55 additions and 51 deletions

View File

@ -122,14 +122,14 @@ export default class ExtensionManager {
getPos: (() => number) | boolean,
decorations: Decoration[],
) => {
const attributes = getRenderedAttributes(node, extensionAttributes)
const HTMLAttributes = getRenderedAttributes(node, extensionAttributes)
return renderer({
editor,
node,
getPos,
decorations,
attributes,
HTMLAttributes,
})
}

View File

@ -45,7 +45,7 @@ export interface MarkExtensionSpec<Options = {}, Commands = {}> extends Overwrit
},
props: {
mark: Mark,
attributes: { [key: string]: any },
HTMLAttributes: { [key: string]: any },
}
) => DOMOutputSpec) | null,

View File

@ -80,7 +80,7 @@ export interface NodeExtensionSpec<Options = {}, Commands = {}> extends Overwrit
},
props: {
node: Node,
attributes: { [key: string]: any },
HTMLAttributes: { [key: string]: any },
}
) => DOMOutputSpec) | null,

View File

@ -49,7 +49,7 @@ export type NodeViewRendererProps = {
node: Node,
getPos: (() => number) | boolean,
decorations: Decoration[],
attributes: AnyObject,
HTMLAttributes: { [key: string]: any },
}
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView

View File

@ -50,7 +50,7 @@ export default function getSchema(extensions: Extensions): Schema {
if (extension.renderHTML) {
schema.toDOM = node => (extension.renderHTML as Function)?.bind(context)({
node,
attributes: getRenderedAttributes(node, extensionAttributes),
HTMLAttributes: getRenderedAttributes(node, extensionAttributes),
})
}
@ -79,7 +79,7 @@ export default function getSchema(extensions: Extensions): Schema {
if (extension.renderHTML) {
schema.toDOM = mark => (extension.renderHTML as Function)?.bind(context)({
mark,
attributes: getRenderedAttributes(mark, extensionAttributes),
HTMLAttributes: getRenderedAttributes(mark, extensionAttributes),
})
}

View File

@ -18,8 +18,8 @@ const Blockquote = createNode({
]
},
renderHTML({ attributes }) {
return ['blockquote', attributes, 0]
renderHTML({ HTMLAttributes }) {
return ['blockquote', HTMLAttributes, 0]
},
addCommands() {

View File

@ -26,8 +26,8 @@ const Bold = createMark({
]
},
renderHTML({ attributes }) {
return ['strong', attributes, 0]
renderHTML({ HTMLAttributes }) {
return ['strong', HTMLAttributes, 0]
},
addCommands() {

View File

@ -16,8 +16,8 @@ const BulletList = createNode({
]
},
renderHTML({ attributes }) {
return ['ul', attributes, 0]
renderHTML({ HTMLAttributes }) {
return ['ul', HTMLAttributes, 0]
},
addCommands() {

View File

@ -64,8 +64,8 @@ const CodeBlock = createNode({
]
},
renderHTML({ attributes }) {
return ['pre', ['code', attributes, 0]]
renderHTML({ HTMLAttributes }) {
return ['pre', ['code', HTMLAttributes, 0]]
},
addCommands() {

View File

@ -16,8 +16,8 @@ const Code = createMark({
]
},
renderHTML({ attributes }) {
return ['code', attributes, 0]
renderHTML({ HTMLAttributes }) {
return ['code', HTMLAttributes, 0]
},
addCommands() {

View File

@ -16,8 +16,8 @@ const HardBreak = createNode({
]
},
renderHTML({ attributes }) {
return ['br', attributes]
renderHTML({ HTMLAttributes }) {
return ['br', HTMLAttributes]
},
addCommands() {

View File

@ -5,6 +5,9 @@ type Level = 1 | 2 | 3 | 4 | 5 | 6
export interface HeadingOptions {
levels: Level[],
HTMLAttributes: {
[key: string]: any
},
}
const Heading = createNode({
@ -12,6 +15,7 @@ const Heading = createNode({
defaultOptions: <HeadingOptions>{
levels: [1, 2, 3, 4, 5, 6],
HTMLAttributes: {},
},
content: 'inline*',
@ -37,13 +41,13 @@ const Heading = createNode({
}))
},
renderHTML({ node, attributes }) {
renderHTML({ node, HTMLAttributes }) {
const hasLevel = this.options.levels.includes(node.attrs.level)
const level = hasLevel
? node.attrs.level
: this.options.levels[0]
return [`h${level}`, attributes, 0]
return [`h${level}`, HTMLAttributes, 0]
},
addCommands() {

View File

@ -42,8 +42,8 @@ const Highlight = createMark({
]
},
renderHTML({ attributes }) {
return ['mark', attributes, 0]
renderHTML({ HTMLAttributes }) {
return ['mark', HTMLAttributes, 0]
},
addCommands() {

View File

@ -11,8 +11,8 @@ const HorizontalRule = createNode({
]
},
renderHTML({ attributes }) {
return ['hr', attributes]
renderHTML({ HTMLAttributes }) {
return ['hr', HTMLAttributes]
},
addCommands() {

View File

@ -45,8 +45,8 @@ const Image = createNode({
]
},
renderHTML({ attributes }) {
return ['img', attributes]
renderHTML({ HTMLAttributes }) {
return ['img', HTMLAttributes]
},
addCommands() {

View File

@ -25,8 +25,8 @@ const Italic = createMark({
]
},
renderHTML({ attributes }) {
return ['em', attributes, 0]
renderHTML({ HTMLAttributes }) {
return ['em', HTMLAttributes, 0]
},
addCommands() {

View File

@ -39,8 +39,8 @@ const Link = createMark({
]
},
renderHTML({ attributes }) {
return ['a', mergeAttributes(attributes, { rel: this.options.rel }), 0]
renderHTML({ HTMLAttributes }) {
return ['a', mergeAttributes(HTMLAttributes, { rel: this.options.rel }), 0]
},
addCommands() {

View File

@ -15,8 +15,8 @@ const ListItem = createNode({
]
},
renderHTML({ attributes }) {
return ['li', attributes, 0]
renderHTML({ HTMLAttributes }) {
return ['li', HTMLAttributes, 0]
},
addKeyboardShortcuts() {

View File

@ -31,12 +31,12 @@ const OrderedList = createNode({
]
},
renderHTML({ attributes }) {
const { start, ...attributesWithoutStart } = attributes
renderHTML({ HTMLAttributes }) {
const { start, ...attributesWithoutStart } = HTMLAttributes
return start === 1
? ['ol', attributesWithoutStart, 0]
: ['ol', attributes, 0]
: ['ol', HTMLAttributes, 0]
},
addCommands() {

View File

@ -14,8 +14,8 @@ const Paragraph = createNode({
]
},
renderHTML({ attributes }) {
return ['p', attributes, 0]
renderHTML({ HTMLAttributes }) {
return ['p', HTMLAttributes, 0]
},
addCommands() {

View File

@ -25,8 +25,8 @@ const Strike = createMark({
]
},
renderHTML({ attributes }) {
return ['s', attributes, 0]
renderHTML({ HTMLAttributes }) {
return ['s', HTMLAttributes, 0]
},
addCommands() {

View File

@ -43,8 +43,8 @@ const TaskItem = createNode({
]
},
renderHTML({ attributes }) {
return ['li', mergeAttributes(attributes, { 'data-type': 'taskItem' }), 0]
renderHTML({ HTMLAttributes }) {
return ['li', mergeAttributes(HTMLAttributes, { 'data-type': 'taskItem' }), 0]
},
addKeyboardShortcuts() {
@ -64,7 +64,7 @@ const TaskItem = createNode({
},
addNodeView() {
return ({ attributes, getPos, editor }) => {
return ({ HTMLAttributes, getPos, editor }) => {
const { view } = editor
const listItem = document.createElement('li')
const checkbox = document.createElement('input')
@ -82,13 +82,13 @@ const TaskItem = createNode({
}
})
if (attributes['data-checked'] === true) {
if (HTMLAttributes['data-checked'] === true) {
checkbox.setAttribute('checked', 'checked')
}
listItem.append(checkbox, content)
Object.entries(attributes).forEach(([key, value]) => {
Object.entries(HTMLAttributes).forEach(([key, value]) => {
listItem.setAttribute(key, value)
})

View File

@ -16,8 +16,8 @@ const TaskList = createNode({
]
},
renderHTML({ attributes }) {
return ['ul', mergeAttributes(attributes, { 'data-type': 'taskList' }), 0]
renderHTML({ HTMLAttributes }) {
return ['ul', mergeAttributes(HTMLAttributes, { 'data-type': 'taskList' }), 0]
},
addCommands() {

View File

@ -20,8 +20,8 @@ const TextStyle = createMark({
]
},
renderHTML({ attributes }) {
return ['span', attributes, 0]
renderHTML({ HTMLAttributes }) {
return ['span', HTMLAttributes, 0]
},
addCommands() {

View File

@ -14,8 +14,8 @@ const Underline = createMark({
]
},
renderHTML({ attributes }) {
return ['u', attributes, 0]
renderHTML({ HTMLAttributes }) {
return ['u', HTMLAttributes, 0]
},
addCommands() {