* refactor: upgrade prosemirror packages to new typescript versions * refactor: migrate to new typings from prosemirror * style: fix linting issues * style: fix linting issues * style: fix linting issues * fix(ci): fix build process by reimplement filterTransaction * fix(extension-test): fix broken build because of wrong output file names * fix: fix prosemirror-tables not being bundled correctly for ES6 * fix: move to prosemirror-tables-contently until es6 build is working * fix: fix tests for youtube * fix: fix youtube test * fix(demos): fix demos build
79 lines
1.6 KiB
TypeScript
79 lines
1.6 KiB
TypeScript
import { Mark, mergeAttributes } from '@tiptap/core'
|
||
|
||
export interface SuperscriptExtensionOptions {
|
||
HTMLAttributes: Object,
|
||
}
|
||
|
||
declare module '@tiptap/core' {
|
||
interface Commands<ReturnType> {
|
||
superscript: {
|
||
/**
|
||
* Set a superscript mark
|
||
*/
|
||
setSuperscript: () => ReturnType,
|
||
/**
|
||
* Toggle a superscript mark
|
||
*/
|
||
toggleSuperscript: () => ReturnType,
|
||
/**
|
||
* Unset a superscript mark
|
||
*/
|
||
unsetSuperscript: () => ReturnType,
|
||
}
|
||
}
|
||
}
|
||
|
||
export const Superscript = Mark.create<SuperscriptExtensionOptions>({
|
||
name: 'superscript',
|
||
|
||
addOptions() {
|
||
return {
|
||
HTMLAttributes: {},
|
||
}
|
||
},
|
||
|
||
parseHTML() {
|
||
return [
|
||
{
|
||
tag: 'sup',
|
||
},
|
||
{
|
||
style: 'vertical-align',
|
||
getAttrs(value) {
|
||
// Don’t match this rule if the vertical align isn’t super.
|
||
if (value !== 'super') {
|
||
return false
|
||
}
|
||
|
||
// If it falls through we’ll match, and this mark will be applied.
|
||
return null
|
||
},
|
||
},
|
||
]
|
||
},
|
||
|
||
renderHTML({ HTMLAttributes }) {
|
||
return ['sup', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||
},
|
||
|
||
addCommands() {
|
||
return {
|
||
setSuperscript: () => ({ commands }) => {
|
||
return commands.setMark(this.name)
|
||
},
|
||
toggleSuperscript: () => ({ commands }) => {
|
||
return commands.toggleMark(this.name)
|
||
},
|
||
unsetSuperscript: () => ({ commands }) => {
|
||
return commands.unsetMark(this.name)
|
||
},
|
||
}
|
||
},
|
||
|
||
addKeyboardShortcuts() {
|
||
return {
|
||
'Mod-.': () => this.editor.commands.toggleSuperscript(),
|
||
}
|
||
},
|
||
})
|