Skip to content

Commit

Permalink
feat: add name to extension context
Browse files Browse the repository at this point in the history
  • Loading branch information
philippkuehn committed Apr 20, 2021
1 parent 92ced9f commit 12f60ab
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 3 deletions.
18 changes: 17 additions & 1 deletion packages/core/src/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ declare module '@tiptap/core' {
* Global attributes
*/
addGlobalAttributes?: (this: {
name: string,
options: Options,
parent: ParentConfig<ExtensionConfig<Options>>['addGlobalAttributes'],
}) => GlobalAttributes | {},
Expand All @@ -43,6 +44,7 @@ declare module '@tiptap/core' {
* Raw
*/
addCommands?: (this: {
name: string,
options: Options,
editor: Editor,
parent: ParentConfig<ExtensionConfig<Options>>['addCommands'],
Expand All @@ -52,6 +54,7 @@ declare module '@tiptap/core' {
* Keyboard shortcuts
*/
addKeyboardShortcuts?: (this: {
name: string,
options: Options,
editor: Editor,
parent: ParentConfig<ExtensionConfig<Options>>['addKeyboardShortcuts'],
Expand All @@ -63,6 +66,7 @@ declare module '@tiptap/core' {
* Input rules
*/
addInputRules?: (this: {
name: string,
options: Options,
editor: Editor,
parent: ParentConfig<ExtensionConfig<Options>>['addInputRules'],
Expand All @@ -72,6 +76,7 @@ declare module '@tiptap/core' {
* Paste rules
*/
addPasteRules?: (this: {
name: string,
options: Options,
editor: Editor,
parent: ParentConfig<ExtensionConfig<Options>>['addPasteRules'],
Expand All @@ -81,6 +86,7 @@ declare module '@tiptap/core' {
* ProseMirror plugins
*/
addProseMirrorPlugins?: (this: {
name: string,
options: Options,
editor: Editor,
parent: ParentConfig<ExtensionConfig<Options>>['addProseMirrorPlugins'],
Expand All @@ -91,6 +97,7 @@ declare module '@tiptap/core' {
*/
extendNodeSchema?: ((
this: {
name: string,
options: Options,
parent: ParentConfig<ExtensionConfig<Options>>['extendNodeSchema'],
},
Expand All @@ -104,6 +111,7 @@ declare module '@tiptap/core' {
*/
extendMarkSchema?: ((
this: {
name: string,
options: Options,
parent: ParentConfig<ExtensionConfig<Options>>['extendMarkSchema'],
},
Expand All @@ -115,7 +123,8 @@ declare module '@tiptap/core' {
/**
* The editor is not ready yet.
*/
onBeforeCreate?: ((this: {
onBeforeCreate?: ((this: {
name: string,
options: Options,
editor: Editor,
parent: ParentConfig<ExtensionConfig<Options>>['onBeforeCreate'],
Expand All @@ -125,6 +134,7 @@ declare module '@tiptap/core' {
* The editor is ready.
*/
onCreate?: ((this: {
name: string,
options: Options,
editor: Editor,
parent: ParentConfig<ExtensionConfig<Options>>['onCreate'],
Expand All @@ -134,6 +144,7 @@ declare module '@tiptap/core' {
* The content has changed.
*/
onUpdate?: ((this: {
name: string,
options: Options,
editor: Editor,
parent: ParentConfig<ExtensionConfig<Options>>['onUpdate'],
Expand All @@ -143,6 +154,7 @@ declare module '@tiptap/core' {
* The selection has changed.
*/
onSelectionUpdate?: ((this: {
name: string,
options: Options,
editor: Editor,
parent: ParentConfig<ExtensionConfig<Options>>['onSelectionUpdate'],
Expand All @@ -153,6 +165,7 @@ declare module '@tiptap/core' {
*/
onTransaction?: ((
this: {
name: string,
options: Options,
editor: Editor,
parent: ParentConfig<ExtensionConfig<Options>>['onTransaction'],
Expand All @@ -167,6 +180,7 @@ declare module '@tiptap/core' {
*/
onFocus?: ((
this: {
name: string,
options: Options,
editor: Editor,
parent: ParentConfig<ExtensionConfig<Options>>['onFocus'],
Expand All @@ -181,6 +195,7 @@ declare module '@tiptap/core' {
*/
onBlur?: ((
this: {
name: string,
options: Options,
editor: Editor,
parent: ParentConfig<ExtensionConfig<Options>>['onBlur'],
Expand All @@ -194,6 +209,7 @@ declare module '@tiptap/core' {
* The editor is destroyed.
*/
onDestroy?: ((this: {
name: string,
options: Options,
editor: Editor,
parent: ParentConfig<ExtensionConfig<Options>>['onDestroy'],
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/ExtensionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class ExtensionManager {

this.extensions.forEach(extension => {
const context = {
name: extension.name,
options: extension.options,
editor: this.editor,
type: getSchemaTypeByName(extension.name, this.schema),
Expand Down Expand Up @@ -149,6 +150,7 @@ export default class ExtensionManager {
get commands(): RawCommands {
return this.extensions.reduce((commands, extension) => {
const context = {
name: extension.name,
options: extension.options,
editor: this.editor,
type: getSchemaTypeByName(extension.name, this.schema),
Expand Down Expand Up @@ -176,6 +178,7 @@ export default class ExtensionManager {
.reverse()
.map(extension => {
const context = {
name: extension.name,
options: extension.options,
editor: this.editor,
type: getSchemaTypeByName(extension.name, this.schema),
Expand Down Expand Up @@ -260,6 +263,7 @@ export default class ExtensionManager {
.map(extension => {
const extensionAttributes = this.attributes.filter(attribute => attribute.type === extension.name)
const context = {
name: extension.name,
options: extension.options,
editor,
type: getNodeType(extension.name, this.schema),
Expand Down Expand Up @@ -304,6 +308,7 @@ export default class ExtensionManager {
.filter(extension => !!getExtensionField(extension, 'renderText'))
.map(extension => {
const context = {
name: extension.name,
options: extension.options,
editor,
type: getNodeType(extension.name, this.schema),
Expand Down
23 changes: 23 additions & 0 deletions packages/core/src/Mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ declare module '@tiptap/core' {
* Global attributes
*/
addGlobalAttributes?: (this: {
name: string,
options: Options,
parent: ParentConfig<MarkConfig<Options>>['addGlobalAttributes'],
}) => GlobalAttributes | {},
Expand All @@ -49,6 +50,7 @@ declare module '@tiptap/core' {
* Raw
*/
addCommands?: (this: {
name: string,
options: Options,
editor: Editor,
type: MarkType,
Expand All @@ -59,6 +61,7 @@ declare module '@tiptap/core' {
* Keyboard shortcuts
*/
addKeyboardShortcuts?: (this: {
name: string,
options: Options,
editor: Editor,
type: MarkType,
Expand All @@ -71,6 +74,7 @@ declare module '@tiptap/core' {
* Input rules
*/
addInputRules?: (this: {
name: string,
options: Options,
editor: Editor,
type: MarkType,
Expand All @@ -81,6 +85,7 @@ declare module '@tiptap/core' {
* Paste rules
*/
addPasteRules?: (this: {
name: string,
options: Options,
editor: Editor,
type: MarkType,
Expand All @@ -91,6 +96,7 @@ declare module '@tiptap/core' {
* ProseMirror plugins
*/
addProseMirrorPlugins?: (this: {
name: string,
options: Options,
editor: Editor,
type: MarkType,
Expand All @@ -102,6 +108,7 @@ declare module '@tiptap/core' {
*/
extendNodeSchema?: ((
this: {
name: string,
options: Options,
parent: ParentConfig<MarkConfig<Options>>['extendNodeSchema'],
},
Expand All @@ -115,6 +122,7 @@ declare module '@tiptap/core' {
*/
extendMarkSchema?: ((
this: {
name: string,
options: Options,
parent: ParentConfig<MarkConfig<Options>>['extendMarkSchema'],
},
Expand All @@ -127,6 +135,7 @@ declare module '@tiptap/core' {
* The editor is not ready yet.
*/
onBeforeCreate?: ((this: {
name: string,
options: Options,
editor: Editor,
type: MarkType,
Expand All @@ -137,6 +146,7 @@ declare module '@tiptap/core' {
* The editor is ready.
*/
onCreate?: ((this: {
name: string,
options: Options,
editor: Editor,
type: MarkType,
Expand All @@ -147,6 +157,7 @@ declare module '@tiptap/core' {
* The content has changed.
*/
onUpdate?: ((this: {
name: string,
options: Options,
editor: Editor,
type: MarkType,
Expand All @@ -157,6 +168,7 @@ declare module '@tiptap/core' {
* The selection has changed.
*/
onSelectionUpdate?: ((this: {
name: string,
options: Options,
editor: Editor,
type: MarkType,
Expand All @@ -168,6 +180,7 @@ declare module '@tiptap/core' {
*/
onTransaction?: ((
this: {
name: string,
options: Options,
editor: Editor,
type: MarkType,
Expand All @@ -183,6 +196,7 @@ declare module '@tiptap/core' {
*/
onFocus?: ((
this: {
name: string,
options: Options,
editor: Editor,
type: MarkType,
Expand All @@ -198,6 +212,7 @@ declare module '@tiptap/core' {
*/
onBlur?: ((
this: {
name: string,
options: Options,
editor: Editor,
type: MarkType,
Expand All @@ -212,6 +227,7 @@ declare module '@tiptap/core' {
* The editor is destroyed.
*/
onDestroy?: ((this: {
name: string,
options: Options,
editor: Editor,
type: MarkType,
Expand All @@ -227,6 +243,7 @@ declare module '@tiptap/core' {
* Inclusive
*/
inclusive?: MarkSpec['inclusive'] | ((this: {
name: string,
options: Options,
parent: ParentConfig<MarkConfig<Options>>['inclusive'],
}) => MarkSpec['inclusive']),
Expand All @@ -235,6 +252,7 @@ declare module '@tiptap/core' {
* Excludes
*/
excludes?: MarkSpec['excludes'] | ((this: {
name: string,
options: Options,
parent: ParentConfig<MarkConfig<Options>>['excludes'],
}) => MarkSpec['excludes']),
Expand All @@ -243,6 +261,7 @@ declare module '@tiptap/core' {
* Group
*/
group?: MarkSpec['group'] | ((this: {
name: string,
options: Options,
parent: ParentConfig<MarkConfig<Options>>['group'],
}) => MarkSpec['group']),
Expand All @@ -251,6 +270,7 @@ declare module '@tiptap/core' {
* Spanning
*/
spanning?: MarkSpec['spanning'] | ((this: {
name: string,
options: Options,
parent: ParentConfig<MarkConfig<Options>>['spanning'],
}) => MarkSpec['spanning']),
Expand All @@ -260,6 +280,7 @@ declare module '@tiptap/core' {
*/
parseHTML?: (
this: {
name: string,
options: Options,
parent: ParentConfig<MarkConfig<Options>>['parseHTML'],
},
Expand All @@ -270,6 +291,7 @@ declare module '@tiptap/core' {
*/
renderHTML?: ((
this: {
name: string,
options: Options,
parent: ParentConfig<MarkConfig<Options>>['renderHTML'],
},
Expand All @@ -284,6 +306,7 @@ declare module '@tiptap/core' {
*/
addAttributes?: (
this: {
name: string,
options: Options,
parent: ParentConfig<MarkConfig<Options>>['addAttributes'],
},
Expand Down
Loading

0 comments on commit 12f60ab

Please sign in to comment.