mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-28 23:59:25 +08:00
wip: add extension.name
This commit is contained in:
parent
016bda4010
commit
05434afc47
@ -70,7 +70,7 @@ export default {
|
||||
|
||||
this.editor = new Editor({
|
||||
extensions: [
|
||||
...defaultExtensions().filter(extension => extension.config.name !== 'history'),
|
||||
...defaultExtensions().filter(extension => extension.name !== 'history'),
|
||||
Highlight,
|
||||
TaskList,
|
||||
TaskItem,
|
||||
|
@ -127,7 +127,7 @@ import { Editor, defaultExtensions } from '@tiptap/starter-kit'
|
||||
|
||||
new Editor({
|
||||
extensions: [
|
||||
...defaultExtensions().filter(extension => extension.config.name !== 'history'),
|
||||
...defaultExtensions().filter(extension => extension.name !== 'history'),
|
||||
],
|
||||
})
|
||||
```
|
||||
|
@ -200,24 +200,27 @@ declare module '@tiptap/core' {
|
||||
export class Extension<Options = any> {
|
||||
type = 'extension'
|
||||
|
||||
config: ExtensionConfig = {
|
||||
name: 'extension',
|
||||
priority: 100,
|
||||
defaultOptions: {},
|
||||
}
|
||||
|
||||
options: Options
|
||||
name = 'extension'
|
||||
|
||||
parent: Extension | null = null
|
||||
|
||||
child: Extension | null = null
|
||||
|
||||
options: Options
|
||||
|
||||
config: ExtensionConfig = {
|
||||
name: this.name,
|
||||
priority: 100,
|
||||
defaultOptions: {},
|
||||
}
|
||||
|
||||
constructor(config: Partial<ExtensionConfig<Options>> = {}) {
|
||||
this.config = {
|
||||
...this.config,
|
||||
...config,
|
||||
}
|
||||
|
||||
this.name = this.config.name
|
||||
this.options = this.config.defaultOptions
|
||||
}
|
||||
|
||||
@ -238,6 +241,10 @@ export class Extension<Options = any> {
|
||||
|
||||
this.child = extension
|
||||
|
||||
extension.name = extendedConfig.name
|
||||
? extendedConfig.name
|
||||
: this.name
|
||||
|
||||
extension.options = {
|
||||
...extension.parent.options,
|
||||
...extension.options,
|
||||
|
@ -34,14 +34,14 @@ export default class ExtensionManager {
|
||||
const context = {
|
||||
options: extension.options,
|
||||
editor: this.editor,
|
||||
type: getSchemaTypeByName(extension.config.name, this.schema),
|
||||
type: getSchemaTypeByName(extension.name, this.schema),
|
||||
}
|
||||
|
||||
if (extension.type === 'mark') {
|
||||
const keepOnSplit = callOrReturn(getExtensionField(extension, 'keepOnSplit', context)) ?? true
|
||||
|
||||
if (keepOnSplit) {
|
||||
this.splittableMarks.push(extension.config.name)
|
||||
this.splittableMarks.push(extension.name)
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ export default class ExtensionManager {
|
||||
const context = {
|
||||
options: extension.options,
|
||||
editor: this.editor,
|
||||
type: getSchemaTypeByName(extension.config.name, this.schema),
|
||||
type: getSchemaTypeByName(extension.name, this.schema),
|
||||
}
|
||||
|
||||
if (!extension.config.addCommands) {
|
||||
@ -121,7 +121,7 @@ export default class ExtensionManager {
|
||||
const context = {
|
||||
options: extension.options,
|
||||
editor: this.editor,
|
||||
type: getSchemaTypeByName(extension.config.name, this.schema),
|
||||
type: getSchemaTypeByName(extension.name, this.schema),
|
||||
}
|
||||
|
||||
const plugins: Plugin[] = []
|
||||
@ -198,7 +198,7 @@ export default class ExtensionManager {
|
||||
const context = {
|
||||
options: extension.options,
|
||||
editor,
|
||||
type: getNodeType(extension.config.name, this.schema),
|
||||
type: getNodeType(extension.name, this.schema),
|
||||
}
|
||||
const addNodeView = getExtensionField<NodeConfig['addNodeView']>(
|
||||
extension,
|
||||
@ -228,7 +228,7 @@ export default class ExtensionManager {
|
||||
})
|
||||
}
|
||||
|
||||
return [extension.config.name, nodeview]
|
||||
return [extension.name, nodeview]
|
||||
}))
|
||||
}
|
||||
|
||||
@ -242,7 +242,7 @@ export default class ExtensionManager {
|
||||
const context = {
|
||||
options: extension.options,
|
||||
editor,
|
||||
type: getNodeType(extension.config.name, this.schema),
|
||||
type: getNodeType(extension.name, this.schema),
|
||||
}
|
||||
|
||||
const renderText = getExtensionField<NodeConfig['renderText']>(extension, 'renderText', context)
|
||||
@ -253,7 +253,7 @@ export default class ExtensionManager {
|
||||
|
||||
const textSerializer = (props: { node: ProsemirrorNode }) => renderText(props)
|
||||
|
||||
return [extension.config.name, textSerializer]
|
||||
return [extension.name, textSerializer]
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -292,26 +292,29 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
|
||||
export class Mark<Options = any> {
|
||||
type = 'node'
|
||||
type = 'mark'
|
||||
|
||||
config: MarkConfig = {
|
||||
name: 'node',
|
||||
priority: 100,
|
||||
defaultOptions: {},
|
||||
}
|
||||
|
||||
options: Options
|
||||
name = 'mark'
|
||||
|
||||
parent: Mark | null = null
|
||||
|
||||
child: Mark | null = null
|
||||
|
||||
options: Options
|
||||
|
||||
config: MarkConfig = {
|
||||
name: this.name,
|
||||
priority: 100,
|
||||
defaultOptions: {},
|
||||
}
|
||||
|
||||
constructor(config: Partial<MarkConfig<Options>> = {}) {
|
||||
this.config = {
|
||||
...this.config,
|
||||
...config,
|
||||
}
|
||||
|
||||
this.name = this.config.name
|
||||
this.options = this.config.defaultOptions
|
||||
}
|
||||
|
||||
@ -332,6 +335,10 @@ export class Mark<Options = any> {
|
||||
|
||||
this.child = extension
|
||||
|
||||
extension.name = extendedConfig.name
|
||||
? extendedConfig.name
|
||||
: this.name
|
||||
|
||||
extension.options = {
|
||||
...extension.parent.options,
|
||||
...extension.options,
|
||||
|
@ -367,24 +367,27 @@ declare module '@tiptap/core' {
|
||||
export class Node<Options = any> {
|
||||
type = 'node'
|
||||
|
||||
config: NodeConfig = {
|
||||
name: 'node',
|
||||
priority: 100,
|
||||
defaultOptions: {},
|
||||
}
|
||||
|
||||
options: Options
|
||||
name = 'node'
|
||||
|
||||
parent: Node | null = null
|
||||
|
||||
child: Node | null = null
|
||||
|
||||
options: Options
|
||||
|
||||
config: NodeConfig = {
|
||||
name: this.name,
|
||||
priority: 100,
|
||||
defaultOptions: {},
|
||||
}
|
||||
|
||||
constructor(config: Partial<NodeConfig<Options>> = {}) {
|
||||
this.config = {
|
||||
...this.config,
|
||||
...config,
|
||||
}
|
||||
|
||||
this.name = this.config.name
|
||||
this.options = this.config.defaultOptions
|
||||
}
|
||||
|
||||
@ -405,6 +408,10 @@ export class Node<Options = any> {
|
||||
|
||||
this.child = extension
|
||||
|
||||
extension.name = extendedConfig.name
|
||||
? extendedConfig.name
|
||||
: this.name
|
||||
|
||||
extension.options = {
|
||||
...extension.parent.options,
|
||||
...extension.options,
|
||||
|
@ -22,13 +22,10 @@ function cleanUpSchemaItem<T>(data: T) {
|
||||
export default function getSchema(extensions: Extensions): Schema {
|
||||
const allAttributes = getAttributesFromExtensions(extensions)
|
||||
const { nodeExtensions, markExtensions } = splitExtensions(extensions)
|
||||
const topNodeExtension = nodeExtensions.find(extension => getExtensionField(extension, 'topNode'))
|
||||
const topNode = topNodeExtension
|
||||
? getExtensionField<NodeConfig['name']>(topNodeExtension, 'name')
|
||||
: null
|
||||
const topNode = nodeExtensions.find(extension => getExtensionField(extension, 'topNode'))?.name
|
||||
|
||||
const nodes = Object.fromEntries(nodeExtensions.map(extension => {
|
||||
const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.config.name)
|
||||
const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.name)
|
||||
const context = {
|
||||
options: extension.options,
|
||||
}
|
||||
@ -79,11 +76,11 @@ export default function getSchema(extensions: Extensions): Schema {
|
||||
})
|
||||
}
|
||||
|
||||
return [extension.config.name, schema]
|
||||
return [extension.name, schema]
|
||||
}))
|
||||
|
||||
const marks = Object.fromEntries(markExtensions.map(extension => {
|
||||
const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.config.name)
|
||||
const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.name)
|
||||
const context = {
|
||||
options: extension.options,
|
||||
}
|
||||
@ -128,7 +125,7 @@ export default function getSchema(extensions: Extensions): Schema {
|
||||
})
|
||||
}
|
||||
|
||||
return [extension.config.name, schema]
|
||||
return [extension.name, schema]
|
||||
}))
|
||||
|
||||
return new Schema({
|
||||
|
@ -4,7 +4,7 @@ import callOrReturn from '../utilities/callOrReturn'
|
||||
|
||||
export default function isList(name: string, extensions: Extensions): boolean {
|
||||
const { nodeExtensions } = splitExtensions(extensions)
|
||||
const extension = nodeExtensions.find(item => item.config.name === name)
|
||||
const extension = nodeExtensions.find(item => item.name === name)
|
||||
|
||||
if (!extension) {
|
||||
return false
|
||||
|
@ -38,7 +38,7 @@ class ReactNodeView extends NodeView<React.FunctionComponent, Editor> {
|
||||
return string.charAt(0).toUpperCase() + string.substring(1)
|
||||
}
|
||||
|
||||
this.component.displayName = capitalizeFirstChar(this.extension.config.name)
|
||||
this.component.displayName = capitalizeFirstChar(this.extension.name)
|
||||
}
|
||||
|
||||
const ReactNodeViewProvider: React.FunctionComponent = componentProps => {
|
||||
|
Loading…
Reference in New Issue
Block a user