mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
feat: pass node & mark extensions as a contextual variable to addGlobalAttributes
This commit is contained in:
parent
4a01716408
commit
3d3263911f
@ -108,8 +108,9 @@ declare module '@tiptap/core' {
|
||||
name: string
|
||||
options: Options
|
||||
storage: Storage
|
||||
extensions: (Node | Mark)[]
|
||||
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addGlobalAttributes']
|
||||
}) => GlobalAttributes | {}
|
||||
}) => GlobalAttributes
|
||||
|
||||
/**
|
||||
* This function adds commands to the editor
|
||||
|
@ -111,8 +111,9 @@ declare module '@tiptap/core' {
|
||||
name: string
|
||||
options: Options
|
||||
storage: Storage
|
||||
extensions: (Node | Mark)[]
|
||||
parent: ParentConfig<MarkConfig<Options, Storage>>['addGlobalAttributes']
|
||||
}) => GlobalAttributes | {}
|
||||
}) => GlobalAttributes
|
||||
|
||||
/**
|
||||
* This function adds commands to the editor
|
||||
|
@ -7,6 +7,7 @@ import { Editor } from './Editor.js'
|
||||
import { getExtensionField } from './helpers/getExtensionField.js'
|
||||
import { NodeConfig } from './index.js'
|
||||
import { InputRule } from './InputRule.js'
|
||||
import { Mark } from './Mark.js'
|
||||
import { PasteRule } from './PasteRule.js'
|
||||
import {
|
||||
AnyConfig,
|
||||
@ -111,8 +112,9 @@ declare module '@tiptap/core' {
|
||||
name: string
|
||||
options: Options
|
||||
storage: Storage
|
||||
extensions: (Node | Mark)[]
|
||||
parent: ParentConfig<NodeConfig<Options, Storage>>['addGlobalAttributes']
|
||||
}) => GlobalAttributes | {}
|
||||
}) => GlobalAttributes
|
||||
|
||||
/**
|
||||
* This function adds commands to the editor
|
||||
|
@ -5,7 +5,6 @@ import {
|
||||
Attributes,
|
||||
ExtensionAttribute,
|
||||
Extensions,
|
||||
GlobalAttributes,
|
||||
} from '../types.js'
|
||||
import { getExtensionField } from './getExtensionField.js'
|
||||
import { splitExtensions } from './splitExtensions.js'
|
||||
@ -32,6 +31,7 @@ export function getAttributesFromExtensions(extensions: Extensions): ExtensionAt
|
||||
name: extension.name,
|
||||
options: extension.options,
|
||||
storage: extension.storage,
|
||||
extensions: nodeAndMarkExtensions,
|
||||
}
|
||||
|
||||
const addGlobalAttributes = getExtensionField<AnyConfig['addGlobalAttributes']>(
|
||||
@ -44,8 +44,7 @@ export function getAttributesFromExtensions(extensions: Extensions): ExtensionAt
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: remove `as GlobalAttributes`
|
||||
const globalAttributes = addGlobalAttributes() as GlobalAttributes
|
||||
const globalAttributes = addGlobalAttributes()
|
||||
|
||||
globalAttributes.forEach(globalAttribute => {
|
||||
globalAttribute.types.forEach(type => {
|
||||
|
@ -152,7 +152,13 @@ export type ExtensionAttribute = {
|
||||
}
|
||||
|
||||
export type GlobalAttributes = {
|
||||
/**
|
||||
* The node & mark types this attribute should be applied to.
|
||||
*/
|
||||
types: string[]
|
||||
/**
|
||||
* The attributes to add to the node or mark types.
|
||||
*/
|
||||
attributes: {
|
||||
[key: string]: Attribute
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user