@tiptap/core 3.0.0-next.3 → 3.0.0-next.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +5 -1
  3. package/dist/index.cjs +2627 -2651
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +2423 -2688
  6. package/dist/index.d.ts +2423 -2688
  7. package/dist/index.js +2639 -2684
  8. package/dist/index.js.map +1 -1
  9. package/dist/jsx-runtime/jsx-runtime.cjs +56 -0
  10. package/dist/jsx-runtime/jsx-runtime.cjs.map +1 -0
  11. package/dist/jsx-runtime/jsx-runtime.d.cts +22 -0
  12. package/dist/jsx-runtime/jsx-runtime.d.ts +22 -0
  13. package/dist/jsx-runtime/jsx-runtime.js +26 -0
  14. package/dist/jsx-runtime/jsx-runtime.js.map +1 -0
  15. package/jsx-runtime/index.cjs +1 -0
  16. package/jsx-runtime/index.d.cts +1 -0
  17. package/jsx-runtime/index.d.ts +1 -0
  18. package/jsx-runtime/index.js +1 -0
  19. package/package.json +27 -6
  20. package/src/CommandManager.ts +2 -9
  21. package/src/Editor.ts +191 -94
  22. package/src/EventEmitter.ts +7 -10
  23. package/src/Extendable.ts +483 -0
  24. package/src/Extension.ts +5 -496
  25. package/src/ExtensionManager.ts +81 -135
  26. package/src/InputRule.ts +35 -48
  27. package/src/Mark.ts +135 -623
  28. package/src/MarkView.ts +66 -0
  29. package/src/Node.ts +325 -829
  30. package/src/NodePos.ts +1 -3
  31. package/src/NodeView.ts +10 -20
  32. package/src/PasteRule.ts +43 -55
  33. package/src/Tracker.ts +7 -9
  34. package/src/commands/blur.ts +14 -12
  35. package/src/commands/clearContent.ts +12 -5
  36. package/src/commands/clearNodes.ts +32 -30
  37. package/src/commands/command.ts +1 -1
  38. package/src/commands/createParagraphNear.ts +5 -3
  39. package/src/commands/cut.ts +12 -10
  40. package/src/commands/deleteCurrentNode.ts +23 -21
  41. package/src/commands/deleteNode.ts +18 -16
  42. package/src/commands/deleteRange.ts +10 -8
  43. package/src/commands/deleteSelection.ts +5 -3
  44. package/src/commands/enter.ts +6 -4
  45. package/src/commands/exitCode.ts +5 -3
  46. package/src/commands/extendMarkRange.ts +14 -12
  47. package/src/commands/first.ts +2 -4
  48. package/src/commands/focus.ts +51 -48
  49. package/src/commands/forEach.ts +2 -2
  50. package/src/commands/insertContent.ts +12 -14
  51. package/src/commands/insertContentAt.ts +105 -98
  52. package/src/commands/join.ts +20 -12
  53. package/src/commands/joinItemBackward.ts +16 -18
  54. package/src/commands/joinItemForward.ts +16 -18
  55. package/src/commands/joinTextblockBackward.ts +5 -3
  56. package/src/commands/joinTextblockForward.ts +5 -3
  57. package/src/commands/keyboardShortcut.ts +29 -34
  58. package/src/commands/lift.ts +10 -8
  59. package/src/commands/liftEmptyBlock.ts +6 -4
  60. package/src/commands/liftListItem.ts +6 -4
  61. package/src/commands/newlineInCode.ts +5 -3
  62. package/src/commands/resetAttributes.ts +36 -41
  63. package/src/commands/scrollIntoView.ts +9 -7
  64. package/src/commands/selectAll.ts +10 -8
  65. package/src/commands/selectNodeBackward.ts +5 -3
  66. package/src/commands/selectNodeForward.ts +5 -3
  67. package/src/commands/selectParentNode.ts +5 -3
  68. package/src/commands/selectTextblockEnd.ts +5 -3
  69. package/src/commands/selectTextblockStart.ts +5 -3
  70. package/src/commands/setContent.ts +37 -36
  71. package/src/commands/setMark.ts +55 -57
  72. package/src/commands/setMeta.ts +7 -5
  73. package/src/commands/setNode.ts +32 -30
  74. package/src/commands/setNodeSelection.ts +11 -9
  75. package/src/commands/setTextSelection.ts +15 -13
  76. package/src/commands/sinkListItem.ts +6 -4
  77. package/src/commands/splitBlock.ts +67 -76
  78. package/src/commands/splitListItem.ts +93 -106
  79. package/src/commands/toggleList.ts +73 -71
  80. package/src/commands/toggleMark.ts +11 -9
  81. package/src/commands/toggleNode.ts +18 -16
  82. package/src/commands/toggleWrap.ts +10 -8
  83. package/src/commands/undoInputRule.ts +31 -29
  84. package/src/commands/unsetAllMarks.ts +16 -14
  85. package/src/commands/unsetMark.ts +27 -25
  86. package/src/commands/updateAttributes.ts +92 -100
  87. package/src/commands/wrapIn.ts +6 -4
  88. package/src/commands/wrapInList.ts +6 -4
  89. package/src/extensions/clipboardTextSerializer.ts +2 -4
  90. package/src/extensions/delete.ts +89 -0
  91. package/src/extensions/focusEvents.ts +2 -6
  92. package/src/extensions/index.ts +1 -0
  93. package/src/extensions/keymap.ts +58 -50
  94. package/src/extensions/paste.ts +0 -1
  95. package/src/extensions/tabindex.ts +1 -1
  96. package/src/helpers/combineTransactionSteps.ts +1 -4
  97. package/src/helpers/createChainableState.ts +1 -4
  98. package/src/helpers/createDocument.ts +1 -3
  99. package/src/helpers/createNodeFromContent.ts +4 -10
  100. package/src/helpers/findChildrenInRange.ts +1 -5
  101. package/src/helpers/findParentNode.ts +3 -1
  102. package/src/helpers/flattenExtensions.ts +30 -0
  103. package/src/helpers/getAttributes.ts +1 -4
  104. package/src/helpers/getAttributesFromExtensions.ts +28 -37
  105. package/src/helpers/getChangedRanges.ts +13 -11
  106. package/src/helpers/getExtensionField.ts +11 -11
  107. package/src/helpers/getMarkAttributes.ts +1 -4
  108. package/src/helpers/getMarkRange.ts +5 -15
  109. package/src/helpers/getMarkType.ts +1 -3
  110. package/src/helpers/getNodeAttributes.ts +1 -4
  111. package/src/helpers/getNodeType.ts +1 -3
  112. package/src/helpers/getRenderedAttributes.ts +1 -3
  113. package/src/helpers/getSchema.ts +2 -2
  114. package/src/helpers/getSchemaByResolvedExtensions.ts +45 -77
  115. package/src/helpers/getSplittedAttributes.ts +4 -4
  116. package/src/helpers/getTextContentFromNodes.ts +8 -11
  117. package/src/helpers/index.ts +4 -0
  118. package/src/helpers/injectExtensionAttributesToParseRule.ts +1 -1
  119. package/src/helpers/isActive.ts +1 -5
  120. package/src/helpers/isExtensionRulesEnabled.ts +1 -3
  121. package/src/helpers/isNodeEmpty.ts +2 -2
  122. package/src/helpers/resolveExtensions.ts +25 -0
  123. package/src/helpers/resolveFocusPosition.ts +3 -14
  124. package/src/helpers/rewriteUnknownContent.ts +149 -0
  125. package/src/helpers/sortExtensions.ts +26 -0
  126. package/src/index.ts +3 -7
  127. package/src/inputRules/markInputRule.ts +1 -5
  128. package/src/inputRules/nodeInputRule.ts +2 -9
  129. package/src/inputRules/textInputRule.ts +1 -4
  130. package/src/inputRules/textblockTypeInputRule.ts +2 -8
  131. package/src/inputRules/wrappingInputRule.ts +13 -19
  132. package/src/jsx-runtime.ts +64 -0
  133. package/src/pasteRules/markPasteRule.ts +1 -3
  134. package/src/pasteRules/nodePasteRule.ts +2 -8
  135. package/src/pasteRules/textPasteRule.ts +1 -4
  136. package/src/types.ts +529 -174
  137. package/src/utilities/createStyleTag.ts +3 -1
  138. package/src/utilities/deleteProps.ts +7 -11
  139. package/src/utilities/elementFromString.ts +3 -0
  140. package/src/utilities/findDuplicates.ts +4 -1
  141. package/src/utilities/index.ts +1 -0
  142. package/src/utilities/isFunction.ts +1 -0
  143. package/src/utilities/isMacOS.ts +1 -3
  144. package/src/utilities/isiOS.ts +5 -10
  145. package/src/utilities/mergeAttributes.ts +17 -7
  146. package/src/utilities/removeDuplicates.ts +1 -3
package/src/Mark.ts CHANGED
@@ -1,643 +1,155 @@
1
- import {
2
- DOMOutputSpec, Mark as ProseMirrorMark, MarkSpec, MarkType,
3
- } from '@tiptap/pm/model'
4
- import { Plugin, Transaction } from '@tiptap/pm/state'
5
-
6
- import { Editor } from './Editor.js'
7
- import { getExtensionField } from './helpers/getExtensionField.js'
8
- import { MarkConfig } from './index.js'
9
- import { InputRule } from './InputRule.js'
10
- import { Node } from './Node.js'
11
- import { PasteRule } from './PasteRule.js'
12
- import {
13
- AnyConfig,
14
- Attributes,
15
- Extensions,
16
- GlobalAttributes,
17
- KeyboardShortcutCommand,
18
- ParentConfig,
19
- RawCommands,
20
- } from './types.js'
21
- import { callOrReturn } from './utilities/callOrReturn.js'
22
- import { mergeDeep } from './utilities/mergeDeep.js'
23
-
24
- declare module '@tiptap/core' {
25
- export interface MarkConfig<Options = any, Storage = any> {
26
- // @ts-ignore - this is a dynamic key
27
- [key: string]: any
28
-
29
- /**
30
- * The extension name - this must be unique.
31
- * It will be used to identify the extension.
32
- *
33
- * @example 'myExtension'
34
- */
1
+ import type { DOMOutputSpec, Mark as ProseMirrorMark, MarkSpec, MarkType } from '@tiptap/pm/model'
2
+
3
+ import type { Editor } from './Editor.js'
4
+ import type { ExtendableConfig } from './Extendable.js'
5
+ import { Extendable } from './Extendable.js'
6
+ import type { Attributes, MarkViewRenderer, ParentConfig } from './types.js'
7
+
8
+ export interface MarkConfig<Options = any, Storage = any>
9
+ extends ExtendableConfig<Options, Storage, MarkConfig<Options, Storage>, MarkType> {
10
+ /**
11
+ * Mark View
12
+ */
13
+ addMarkView?:
14
+ | ((this: {
15
+ name: string
16
+ options: Options
17
+ storage: Storage
18
+ editor: Editor
19
+ type: MarkType
20
+ parent: ParentConfig<MarkConfig<Options, Storage>>['addMarkView']
21
+ }) => MarkViewRenderer)
22
+ | null
23
+
24
+ /**
25
+ * Keep mark after split node
26
+ */
27
+ keepOnSplit?: boolean | (() => boolean)
28
+
29
+ /**
30
+ * Inclusive
31
+ */
32
+ inclusive?:
33
+ | MarkSpec['inclusive']
34
+ | ((this: {
35
+ name: string
36
+ options: Options
37
+ storage: Storage
38
+ parent: ParentConfig<MarkConfig<Options, Storage>>['inclusive']
39
+ editor?: Editor
40
+ }) => MarkSpec['inclusive'])
41
+
42
+ /**
43
+ * Excludes
44
+ */
45
+ excludes?:
46
+ | MarkSpec['excludes']
47
+ | ((this: {
48
+ name: string
49
+ options: Options
50
+ storage: Storage
51
+ parent: ParentConfig<MarkConfig<Options, Storage>>['excludes']
52
+ editor?: Editor
53
+ }) => MarkSpec['excludes'])
54
+
55
+ /**
56
+ * Marks this Mark as exitable
57
+ */
58
+ exitable?: boolean | (() => boolean)
59
+
60
+ /**
61
+ * Group
62
+ */
63
+ group?:
64
+ | MarkSpec['group']
65
+ | ((this: {
66
+ name: string
67
+ options: Options
68
+ storage: Storage
69
+ parent: ParentConfig<MarkConfig<Options, Storage>>['group']
70
+ editor?: Editor
71
+ }) => MarkSpec['group'])
72
+
73
+ /**
74
+ * Spanning
75
+ */
76
+ spanning?:
77
+ | MarkSpec['spanning']
78
+ | ((this: {
79
+ name: string
80
+ options: Options
81
+ storage: Storage
82
+ parent: ParentConfig<MarkConfig<Options, Storage>>['spanning']
83
+ editor?: Editor
84
+ }) => MarkSpec['spanning'])
85
+
86
+ /**
87
+ * Code
88
+ */
89
+ code?:
90
+ | boolean
91
+ | ((this: {
92
+ name: string
93
+ options: Options
94
+ storage: Storage
95
+ parent: ParentConfig<MarkConfig<Options, Storage>>['code']
96
+ editor?: Editor
97
+ }) => boolean)
98
+
99
+ /**
100
+ * Parse HTML
101
+ */
102
+ parseHTML?: (this: {
35
103
  name: string
36
-
37
- /**
38
- * The priority of your extension. The higher, the earlier it will be called
39
- * and will take precedence over other extensions with a lower priority.
40
- * @default 100
41
- * @example 101
42
- */
43
- priority?: number
44
-
45
- /**
46
- * The default options for this extension.
47
- * @example
48
- * defaultOptions: {
49
- * myOption: 'foo',
50
- * myOtherOption: 10,
51
- * }
52
- */
53
- defaultOptions?: Options
54
-
55
- /**
56
- * This method will add options to this extension
57
- * @see https://tiptap.dev/guide/custom-extensions#settings
58
- * @example
59
- * addOptions() {
60
- * return {
61
- * myOption: 'foo',
62
- * myOtherOption: 10,
63
- * }
64
- */
65
- addOptions?: (this: {
66
- name: string
67
- parent: Exclude<ParentConfig<MarkConfig<Options, Storage>>['addOptions'], undefined>
68
- }) => Options
69
-
70
- /**
71
- * The default storage this extension can save data to.
72
- * @see https://tiptap.dev/guide/custom-extensions#storage
73
- * @example
74
- * defaultStorage: {
75
- * prefetchedUsers: [],
76
- * loading: false,
77
- * }
78
- */
79
- addStorage?: (this: {
80
- name: string
81
- options: Options
82
- parent: Exclude<ParentConfig<MarkConfig<Options, Storage>>['addStorage'], undefined>
83
- }) => Storage
84
-
85
- /**
86
- * This function adds globalAttributes to specific nodes.
87
- * @see https://tiptap.dev/guide/custom-extensions#global-attributes
88
- * @example
89
- * addGlobalAttributes() {
90
- * return [
91
- * {
92
- // Extend the following extensions
93
- * types: [
94
- * 'heading',
95
- * 'paragraph',
96
- * ],
97
- * // … with those attributes
98
- * attributes: {
99
- * textAlign: {
100
- * default: 'left',
101
- * renderHTML: attributes => ({
102
- * style: `text-align: ${attributes.textAlign}`,
103
- * }),
104
- * parseHTML: element => element.style.textAlign || 'left',
105
- * },
106
- * },
107
- * },
108
- * ]
109
- * }
110
- */
111
- addGlobalAttributes?: (this: {
112
- name: string
113
- options: Options
114
- storage: Storage
115
- extensions: (Node | Mark)[]
116
- parent: ParentConfig<MarkConfig<Options, Storage>>['addGlobalAttributes']
117
- }) => GlobalAttributes
118
-
119
- /**
120
- * This function adds commands to the editor
121
- * @see https://tiptap.dev/guide/custom-extensions#keyboard-shortcuts
122
- * @example
123
- * addCommands() {
124
- * return {
125
- * myCommand: () => ({ chain }) => chain().setMark('type', 'foo').run(),
126
- * }
127
- * }
128
- */
129
- addCommands?: (this: {
130
- name: string
131
- options: Options
132
- storage: Storage
133
- editor: Editor
134
- type: MarkType
135
- parent: ParentConfig<MarkConfig<Options, Storage>>['addCommands']
136
- }) => Partial<RawCommands>
137
-
138
- /**
139
- * This function registers keyboard shortcuts.
140
- * @see https://tiptap.dev/guide/custom-extensions#keyboard-shortcuts
141
- * @example
142
- * addKeyboardShortcuts() {
143
- * return {
144
- * 'Mod-l': () => this.editor.commands.toggleBulletList(),
145
- * }
146
- * },
147
- */
148
- addKeyboardShortcuts?: (this: {
149
- name: string
150
- options: Options
151
- storage: Storage
152
- editor: Editor
153
- type: MarkType
154
- parent: ParentConfig<MarkConfig<Options, Storage>>['addKeyboardShortcuts']
155
- }) => {
156
- [key: string]: KeyboardShortcutCommand
157
- }
158
-
159
- /**
160
- * This function adds input rules to the editor.
161
- * @see https://tiptap.dev/guide/custom-extensions#input-rules
162
- * @example
163
- * addInputRules() {
164
- * return [
165
- * markInputRule({
166
- * find: inputRegex,
167
- * type: this.type,
168
- * }),
169
- * ]
170
- * },
171
- */
172
- addInputRules?: (this: {
173
- name: string
174
- options: Options
175
- storage: Storage
176
- editor: Editor
177
- type: MarkType
178
- parent: ParentConfig<MarkConfig<Options, Storage>>['addInputRules']
179
- }) => InputRule[]
180
-
181
- /**
182
- * This function adds paste rules to the editor.
183
- * @see https://tiptap.dev/guide/custom-extensions#paste-rules
184
- * @example
185
- * addPasteRules() {
186
- * return [
187
- * markPasteRule({
188
- * find: pasteRegex,
189
- * type: this.type,
190
- * }),
191
- * ]
192
- * },
193
- */
194
- addPasteRules?: (this: {
195
- name: string
196
- options: Options
197
- storage: Storage
198
- editor: Editor
199
- type: MarkType
200
- parent: ParentConfig<MarkConfig<Options, Storage>>['addPasteRules']
201
- }) => PasteRule[]
202
-
203
- /**
204
- * This function adds Prosemirror plugins to the editor
205
- * @see https://tiptap.dev/guide/custom-extensions#prosemirror-plugins
206
- * @example
207
- * addProseMirrorPlugins() {
208
- * return [
209
- * customPlugin(),
210
- * ]
211
- * }
212
- */
213
- addProseMirrorPlugins?: (this: {
214
- name: string
215
- options: Options
216
- storage: Storage
217
- editor: Editor
218
- type: MarkType
219
- parent: ParentConfig<MarkConfig<Options, Storage>>['addProseMirrorPlugins']
220
- }) => Plugin[]
221
-
222
- /**
223
- * This function adds additional extensions to the editor. This is useful for
224
- * building extension kits.
225
- * @example
226
- * addExtensions() {
227
- * return [
228
- * BulletList,
229
- * OrderedList,
230
- * ListItem
231
- * ]
232
- * }
233
- */
234
- addExtensions?: (this: {
235
- name: string
236
- options: Options
237
- storage: Storage
238
- parent: ParentConfig<MarkConfig<Options, Storage>>['addExtensions']
239
- }) => Extensions
240
-
241
- /**
242
- * This function extends the schema of the node.
243
- * @example
244
- * extendNodeSchema() {
245
- * return {
246
- * group: 'inline',
247
- * selectable: false,
248
- * }
249
- * }
250
- */
251
- extendNodeSchema?:
252
- | ((
253
- this: {
254
- name: string
255
- options: Options
256
- storage: Storage
257
- parent: ParentConfig<MarkConfig<Options, Storage>>['extendNodeSchema']
258
- },
259
- extension: Node,
260
- ) => Record<string, any>)
261
- | null
262
-
263
- /**
264
- * This function extends the schema of the mark.
265
- * @example
266
- * extendMarkSchema() {
267
- * return {
268
- * group: 'inline',
269
- * selectable: false,
270
- * }
271
- * }
272
- */
273
- extendMarkSchema?:
274
- | ((
275
- this: {
276
- name: string
277
- options: Options
278
- storage: Storage
279
- parent: ParentConfig<MarkConfig<Options, Storage>>['extendMarkSchema']
280
- },
281
- extension: Mark,
282
- ) => Record<string, any>)
283
- | null
284
-
285
- /**
286
- * The editor is not ready yet.
287
- */
288
- onBeforeCreate?:
289
- | ((this: {
290
- name: string
291
- options: Options
292
- storage: Storage
293
- editor: Editor
294
- type: MarkType
295
- parent: ParentConfig<MarkConfig<Options, Storage>>['onBeforeCreate']
296
- }) => void)
297
- | null
298
-
299
- /**
300
- * The editor is ready.
301
- */
302
- onCreate?:
303
- | ((this: {
304
- name: string
305
- options: Options
306
- storage: Storage
307
- editor: Editor
308
- type: MarkType
309
- parent: ParentConfig<MarkConfig<Options, Storage>>['onCreate']
310
- }) => void)
311
- | null
312
-
313
- /**
314
- * The content has changed.
315
- */
316
- onUpdate?:
317
- | ((this: {
104
+ options: Options
105
+ storage: Storage
106
+ parent: ParentConfig<MarkConfig<Options, Storage>>['parseHTML']
107
+ editor?: Editor
108
+ }) => MarkSpec['parseDOM']
109
+
110
+ /**
111
+ * Render HTML
112
+ */
113
+ renderHTML?:
114
+ | ((
115
+ this: {
318
116
  name: string
319
117
  options: Options
320
118
  storage: Storage
321
- editor: Editor
322
- type: MarkType
323
- parent: ParentConfig<MarkConfig<Options, Storage>>['onUpdate']
324
- }) => void)
325
- | null
326
-
327
- /**
328
- * The selection has changed.
329
- */
330
- onSelectionUpdate?:
331
- | ((this: {
332
- name: string
333
- options: Options
334
- storage: Storage
335
- editor: Editor
336
- type: MarkType
337
- parent: ParentConfig<MarkConfig<Options, Storage>>['onSelectionUpdate']
338
- }) => void)
339
- | null
340
-
341
- /**
342
- * The editor state has changed.
343
- */
344
- onTransaction?:
345
- | ((
346
- this: {
347
- name: string
348
- options: Options
349
- storage: Storage
350
- editor: Editor
351
- type: MarkType
352
- parent: ParentConfig<MarkConfig<Options, Storage>>['onTransaction']
353
- },
354
- props: {
355
- editor: Editor
356
- transaction: Transaction
357
- },
358
- ) => void)
359
- | null
360
-
361
- /**
362
- * The editor is focused.
363
- */
364
- onFocus?:
365
- | ((
366
- this: {
367
- name: string
368
- options: Options
369
- storage: Storage
370
- editor: Editor
371
- type: MarkType
372
- parent: ParentConfig<MarkConfig<Options, Storage>>['onFocus']
373
- },
374
- props: {
375
- event: FocusEvent
376
- },
377
- ) => void)
378
- | null
379
-
380
- /**
381
- * The editor isn’t focused anymore.
382
- */
383
- onBlur?:
384
- | ((
385
- this: {
386
- name: string
387
- options: Options
388
- storage: Storage
389
- editor: Editor
390
- type: MarkType
391
- parent: ParentConfig<MarkConfig<Options, Storage>>['onBlur']
392
- },
393
- props: {
394
- event: FocusEvent
395
- },
396
- ) => void)
397
- | null
398
-
399
- /**
400
- * The editor is destroyed.
401
- */
402
- onDestroy?:
403
- | ((this: {
404
- name: string
405
- options: Options
406
- storage: Storage
407
- editor: Editor
408
- type: MarkType
409
- parent: ParentConfig<MarkConfig<Options, Storage>>['onDestroy']
410
- }) => void)
411
- | null
412
-
413
- /**
414
- * Keep mark after split node
415
- */
416
- keepOnSplit?: boolean | (() => boolean)
417
-
418
- /**
419
- * Inclusive
420
- */
421
- inclusive?:
422
- | MarkSpec['inclusive']
423
- | ((this: {
424
- name: string
425
- options: Options
426
- storage: Storage
427
- parent: ParentConfig<MarkConfig<Options, Storage>>['inclusive']
428
- editor?: Editor
429
- }) => MarkSpec['inclusive'])
430
-
431
- /**
432
- * Excludes
433
- */
434
- excludes?:
435
- | MarkSpec['excludes']
436
- | ((this: {
437
- name: string
438
- options: Options
439
- storage: Storage
440
- parent: ParentConfig<MarkConfig<Options, Storage>>['excludes']
119
+ parent: ParentConfig<MarkConfig<Options, Storage>>['renderHTML']
441
120
  editor?: Editor
442
- }) => MarkSpec['excludes'])
443
-
444
- /**
445
- * Marks this Mark as exitable
446
- */
447
- exitable?: boolean | (() => boolean)
448
-
449
- /**
450
- * Group
451
- */
452
- group?:
453
- | MarkSpec['group']
454
- | ((this: {
455
- name: string
456
- options: Options
457
- storage: Storage
458
- parent: ParentConfig<MarkConfig<Options, Storage>>['group']
459
- editor?: Editor
460
- }) => MarkSpec['group'])
461
-
462
- /**
463
- * Spanning
464
- */
465
- spanning?:
466
- | MarkSpec['spanning']
467
- | ((this: {
468
- name: string
469
- options: Options
470
- storage: Storage
471
- parent: ParentConfig<MarkConfig<Options, Storage>>['spanning']
472
- editor?: Editor
473
- }) => MarkSpec['spanning'])
474
-
475
- /**
476
- * Code
477
- */
478
- code?:
479
- | boolean
480
- | ((this: {
481
- name: string
482
- options: Options
483
- storage: Storage
484
- parent: ParentConfig<MarkConfig<Options, Storage>>['code']
485
- editor?: Editor
486
- }) => boolean)
487
-
488
- /**
489
- * Parse HTML
490
- */
491
- parseHTML?: (this: {
492
- name: string
493
- options: Options
494
- storage: Storage
495
- parent: ParentConfig<MarkConfig<Options, Storage>>['parseHTML']
496
- editor?: Editor
497
- }) => MarkSpec['parseDOM']
498
-
499
- /**
500
- * Render HTML
501
- */
502
- renderHTML?:
503
- | ((
504
- this: {
505
- name: string
506
- options: Options
507
- storage: Storage
508
- parent: ParentConfig<MarkConfig<Options, Storage>>['renderHTML']
509
- editor?: Editor
510
- },
511
- props: {
512
- mark: ProseMirrorMark
513
- HTMLAttributes: Record<string, any>
514
- },
515
- ) => DOMOutputSpec)
516
- | null
517
-
518
- /**
519
- * Attributes
520
- */
521
- addAttributes?: (this: {
522
- name: string
523
- options: Options
524
- storage: Storage
525
- parent: ParentConfig<MarkConfig<Options, Storage>>['addAttributes']
526
- editor?: Editor
527
- }) => Attributes | {}
528
- }
121
+ },
122
+ props: {
123
+ mark: ProseMirrorMark
124
+ HTMLAttributes: Record<string, any>
125
+ },
126
+ ) => DOMOutputSpec)
127
+ | null
128
+
129
+ /**
130
+ * Attributes
131
+ */
132
+ addAttributes?: (this: {
133
+ name: string
134
+ options: Options
135
+ storage: Storage
136
+ parent: ParentConfig<MarkConfig<Options, Storage>>['addAttributes']
137
+ editor?: Editor
138
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
139
+ }) => Attributes | {}
529
140
  }
530
141
 
531
142
  /**
532
143
  * The Mark class is used to create custom mark extensions.
533
144
  * @see https://tiptap.dev/api/extensions#create-a-new-extension
534
145
  */
535
- export class Mark<Options = any, Storage = any> {
146
+ export class Mark<Options = any, Storage = any> extends Extendable<Options, Storage> {
536
147
  type = 'mark'
537
148
 
538
- name = 'mark'
539
-
540
- parent: Mark | null = null
541
-
542
- child: Mark | null = null
543
-
544
- options: Options
545
-
546
- storage: Storage
547
-
548
- config: MarkConfig = {
549
- name: this.name,
550
- defaultOptions: {},
551
- }
552
-
553
- constructor(config: Partial<MarkConfig<Options, Storage>> = {}) {
554
- this.config = {
555
- ...this.config,
556
- ...config,
557
- }
558
-
559
- this.name = this.config.name
560
-
561
- if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
562
- console.warn(
563
- `[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`,
564
- )
565
- }
566
-
567
- // TODO: remove `addOptions` fallback
568
- this.options = this.config.defaultOptions
569
-
570
- if (this.config.addOptions) {
571
- this.options = callOrReturn(
572
- getExtensionField<AnyConfig['addOptions']>(this, 'addOptions', {
573
- name: this.name,
574
- }),
575
- )
576
- }
577
-
578
- this.storage = callOrReturn(
579
- getExtensionField<AnyConfig['addStorage']>(this, 'addStorage', {
580
- name: this.name,
581
- options: this.options,
582
- }),
583
- ) || {}
584
- }
585
-
586
149
  static create<O = any, S = any>(config: Partial<MarkConfig<O, S>> = {}) {
587
150
  return new Mark<O, S>(config)
588
151
  }
589
152
 
590
- configure(options: Partial<Options> = {}) {
591
- // return a new instance so we can use the same extension
592
- // with different calls of `configure`
593
- const extension = this.extend<Options, Storage>({
594
- ...this.config,
595
- addOptions: () => {
596
- return mergeDeep(this.options as Record<string, any>, options) as Options
597
- },
598
- })
599
-
600
- // Always preserve the current name
601
- extension.name = this.name
602
- // Set the parent to be our parent
603
- extension.parent = this.parent
604
-
605
- return extension
606
- }
607
-
608
- extend<ExtendedOptions = Options, ExtendedStorage = Storage>(
609
- extendedConfig: Partial<MarkConfig<ExtendedOptions, ExtendedStorage>> = {},
610
- ) {
611
- const extension = new Mark<ExtendedOptions, ExtendedStorage>(extendedConfig)
612
-
613
- extension.parent = this
614
-
615
- this.child = extension
616
-
617
- extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name
618
-
619
- if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
620
- console.warn(
621
- `[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`,
622
- )
623
- }
624
-
625
- extension.options = callOrReturn(
626
- getExtensionField<AnyConfig['addOptions']>(extension, 'addOptions', {
627
- name: extension.name,
628
- }),
629
- )
630
-
631
- extension.storage = callOrReturn(
632
- getExtensionField<AnyConfig['addStorage']>(extension, 'addStorage', {
633
- name: extension.name,
634
- options: extension.options,
635
- }),
636
- )
637
-
638
- return extension
639
- }
640
-
641
153
  static handleExit({ editor, mark }: { editor: Editor; mark: Mark }) {
642
154
  const { tr } = editor.state
643
155
  const currentPos = editor.state.selection.$from