feat!: Replace defaultOptions with addOptions (#2088)

* add new addOptions option

* replace defaultOptions with addOptions for all extensions

* replace defaultOptions with addOptions for all demos

* replace defaultOptions with addOptions in docs

* refactoring

* refactoring

* drop object support for addOptions

* fix optional options

* fix tests
This commit is contained in:
Philipp Kühn
2021-10-26 18:31:13 +02:00
committed by GitHub
parent 2fff9c264b
commit 9afadeb7fe
57 changed files with 622 additions and 233 deletions

View File

@@ -59,20 +59,22 @@ declare module '@tiptap/core' {
}
}
export const CollaborationAnnotation = Extension.create({
export const CollaborationAnnotation = Extension.create<AnnotationOptions>({
name: 'annotation',
priority: 1000,
defaultOptions: <AnnotationOptions>{
HTMLAttributes: {
class: 'annotation',
},
onUpdate: decorations => decorations,
document: null,
field: 'annotations',
map: null,
instance: '',
addOptions() {
return {
HTMLAttributes: {
class: 'annotation',
},
onUpdate: decorations => decorations,
document: null,
field: 'annotations',
map: null,
instance: '',
}
},
onCreate() {

View File

@@ -2,16 +2,17 @@ import { Extension } from '@tiptap/core'
import Suggestion from '@tiptap/suggestion'
export default Extension.create({
name: 'mention',
name: 'commands',
defaultOptions: {
suggestion: {
char: '/',
startOfLine: false,
command: ({ editor, range, props }) => {
props.command({ editor, range })
addOptions() {
return {
suggestion: {
char: '/',
command: ({ editor, range, props }) => {
props.command({ editor, range })
},
},
},
}
},
addProseMirrorPlugins() {

View File

@@ -17,8 +17,10 @@ export default Node.create<DetailsSummaryOptions>({
isolating: true,
defaultOptions: {
HTMLAttributes: {},
addOptions() {
return {
HTMLAttributes: {},
}
},
parseHTML() {

View File

@@ -34,8 +34,10 @@ export default Node.create<DetailsOptions>({
// defining: true,
defaultOptions: {
HTMLAttributes: {},
addOptions() {
return {
HTMLAttributes: {},
}
},
parseHTML() {

View File

@@ -18,18 +18,20 @@ declare module '@tiptap/core' {
}
}
export default Node.create({
export default Node.create<IframeOptions>({
name: 'iframe',
group: 'block',
atom: true,
defaultOptions: <IframeOptions>{
allowFullscreen: true,
HTMLAttributes: {
class: 'iframe-wrapper',
},
addOptions() {
return {
allowFullscreen: true,
HTMLAttributes: {
class: 'iframe-wrapper',
},
}
},
addAttributes() {

View File

@@ -41,8 +41,10 @@ export const inputRegex = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/
export const Figure = Node.create<FigureOptions>({
name: 'figure',
defaultOptions: {
HTMLAttributes: {},
addOptions() {
return {
HTMLAttributes: {},
}
},
group: 'block',

View File

@@ -3,8 +3,10 @@ import { Node, mergeAttributes } from '@tiptap/core'
export const Figcaption = Node.create({
name: 'figcaption',
defaultOptions: {
HTMLAttributes: {},
addOptions() {
return {
HTMLAttributes: {},
}
},
content: 'inline*',

View File

@@ -4,8 +4,10 @@ import { Plugin } from 'prosemirror-state'
export const Figure = Node.create({
name: 'figure',
defaultOptions: {
HTMLAttributes: {},
addOptions() {
return {
HTMLAttributes: {},
}
},
group: 'block',

View File

@@ -39,11 +39,13 @@ export interface LinterOptions {
plugins: Array<typeof LinterPlugin>,
}
export const Linter = Extension.create({
export const Linter = Extension.create<LinterOptions>({
name: 'linter',
defaultOptions: <LinterOptions>{
plugins: [],
addOptions() {
return {
plugins: [],
}
},
addProseMirrorPlugins() {

View File

@@ -20,11 +20,13 @@ export interface TrailingNodeOptions {
export const TrailingNode = Extension.create<TrailingNodeOptions>({
name: 'trailingNode',
defaultOptions: {
node: 'paragraph',
notAfter: [
'paragraph',
],
addOptions() {
return {
node: 'paragraph',
notAfter: [
'paragraph',
],
}
},
addProseMirrorPlugins() {