@tiptap/core 2.0.0-beta.99 → 2.0.0-rc.1

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 (297) hide show
  1. package/README.md +3 -3
  2. package/dist/index.cjs +4360 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/{tiptap-core.esm.js → index.js} +2349 -1447
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.umd.js +4358 -0
  7. package/dist/index.umd.js.map +1 -0
  8. package/dist/packages/core/src/CommandManager.d.ts +14 -7
  9. package/dist/packages/core/src/Editor.d.ts +25 -11
  10. package/dist/packages/core/src/EventEmitter.d.ts +8 -4
  11. package/dist/packages/core/src/Extension.d.ts +63 -29
  12. package/dist/packages/core/src/ExtensionManager.d.ts +3 -4
  13. package/dist/packages/core/src/InputRule.d.ts +42 -0
  14. package/dist/packages/core/src/Mark.d.ts +94 -36
  15. package/dist/packages/core/src/Node.d.ts +104 -45
  16. package/dist/packages/core/src/NodeView.d.ts +8 -8
  17. package/dist/packages/core/src/PasteRule.d.ts +42 -0
  18. package/dist/packages/core/src/Tracker.d.ts +1 -1
  19. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +12 -0
  20. package/dist/packages/core/src/commands/deleteNode.d.ts +1 -1
  21. package/dist/packages/core/src/commands/deleteRange.d.ts +1 -1
  22. package/dist/packages/core/src/commands/extendMarkRange.d.ts +1 -1
  23. package/dist/packages/core/src/commands/focus.d.ts +4 -2
  24. package/dist/packages/core/src/commands/index.d.ts +50 -0
  25. package/dist/packages/core/src/commands/insertContent.d.ts +6 -3
  26. package/dist/packages/core/src/commands/insertContentAt.d.ts +6 -3
  27. package/dist/packages/core/src/commands/join.d.ts +33 -0
  28. package/dist/packages/core/src/commands/lift.d.ts +1 -1
  29. package/dist/packages/core/src/commands/liftListItem.d.ts +1 -1
  30. package/dist/packages/core/src/commands/resetAttributes.d.ts +1 -1
  31. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +12 -0
  32. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +12 -0
  33. package/dist/packages/core/src/commands/setContent.d.ts +2 -2
  34. package/dist/packages/core/src/commands/setMark.d.ts +1 -1
  35. package/dist/packages/core/src/commands/setNode.d.ts +1 -1
  36. package/dist/packages/core/src/commands/setTextSelection.d.ts +1 -1
  37. package/dist/packages/core/src/commands/sinkListItem.d.ts +1 -1
  38. package/dist/packages/core/src/commands/splitListItem.d.ts +1 -1
  39. package/dist/packages/core/src/commands/toggleList.d.ts +2 -2
  40. package/dist/packages/core/src/commands/toggleMark.d.ts +7 -2
  41. package/dist/packages/core/src/commands/toggleNode.d.ts +1 -1
  42. package/dist/packages/core/src/commands/toggleWrap.d.ts +1 -1
  43. package/dist/packages/core/src/commands/unsetMark.d.ts +7 -2
  44. package/dist/packages/core/src/commands/updateAttributes.d.ts +1 -1
  45. package/dist/packages/core/src/commands/wrapIn.d.ts +1 -1
  46. package/dist/packages/core/src/commands/wrapInList.d.ts +1 -1
  47. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +1 -1
  48. package/dist/packages/core/src/extensions/commands.d.ts +2 -97
  49. package/dist/packages/core/src/extensions/editable.d.ts +1 -1
  50. package/dist/packages/core/src/extensions/focusEvents.d.ts +1 -1
  51. package/dist/packages/core/src/extensions/index.d.ts +1 -0
  52. package/dist/packages/core/src/extensions/keymap.d.ts +1 -1
  53. package/dist/packages/core/src/extensions/tabindex.d.ts +2 -0
  54. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +7 -0
  55. package/dist/packages/core/src/helpers/createChainableState.d.ts +5 -0
  56. package/dist/packages/core/src/helpers/createDocument.d.ts +2 -2
  57. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +2 -2
  58. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +2 -0
  59. package/dist/packages/core/src/helpers/findChildren.d.ts +3 -3
  60. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +3 -3
  61. package/dist/packages/core/src/helpers/findParentNode.d.ts +3 -4
  62. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +3 -3
  63. package/dist/packages/core/src/helpers/generateHTML.d.ts +1 -1
  64. package/dist/packages/core/src/helpers/generateJSON.d.ts +1 -1
  65. package/dist/packages/core/src/helpers/generateText.d.ts +5 -0
  66. package/dist/packages/core/src/helpers/getAttributes.d.ts +3 -3
  67. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +2 -2
  68. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +11 -0
  69. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +2 -5
  70. package/dist/packages/core/src/helpers/getExtensionField.d.ts +2 -2
  71. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +2 -2
  72. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +3 -3
  73. package/dist/packages/core/src/helpers/getMarkRange.d.ts +2 -2
  74. package/dist/packages/core/src/helpers/getMarkType.d.ts +2 -2
  75. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +2 -2
  76. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +3 -3
  77. package/dist/packages/core/src/helpers/getNodeType.d.ts +2 -2
  78. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +2 -2
  79. package/dist/packages/core/src/helpers/getSchema.d.ts +2 -2
  80. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +2 -2
  81. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +2 -2
  82. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +2 -2
  83. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +1 -1
  84. package/dist/packages/core/src/helpers/getText.d.ts +6 -0
  85. package/dist/packages/core/src/helpers/getTextBetween.d.ts +6 -0
  86. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +2 -0
  87. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +3 -0
  88. package/dist/packages/core/src/helpers/index.d.ts +47 -0
  89. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +2 -2
  90. package/dist/packages/core/src/helpers/isActive.d.ts +2 -2
  91. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +2 -0
  92. package/dist/packages/core/src/helpers/isList.d.ts +1 -1
  93. package/dist/packages/core/src/helpers/isMarkActive.d.ts +3 -3
  94. package/dist/packages/core/src/helpers/isNodeActive.d.ts +3 -3
  95. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +2 -2
  96. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +2 -2
  97. package/dist/packages/core/src/helpers/isTextSelection.d.ts +2 -2
  98. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +2 -2
  99. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +4 -0
  100. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +2 -2
  101. package/dist/packages/core/src/helpers/splitExtensions.d.ts +6 -6
  102. package/dist/packages/core/src/index.d.ts +12 -34
  103. package/dist/packages/core/src/inputRules/index.d.ts +5 -0
  104. package/dist/packages/core/src/inputRules/markInputRule.d.ts +12 -3
  105. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +12 -3
  106. package/dist/packages/core/src/inputRules/textInputRule.d.ts +9 -0
  107. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +14 -0
  108. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +27 -0
  109. package/dist/packages/core/src/pasteRules/index.d.ts +3 -0
  110. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +12 -3
  111. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +12 -0
  112. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +9 -0
  113. package/dist/packages/core/src/style.d.ts +1 -2
  114. package/dist/packages/core/src/types.d.ts +70 -40
  115. package/dist/packages/core/src/utilities/callOrReturn.d.ts +1 -1
  116. package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -1
  117. package/dist/packages/core/src/utilities/deleteProps.d.ts +1 -1
  118. package/dist/packages/core/src/utilities/elementFromString.d.ts +1 -1
  119. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +1 -0
  120. package/dist/packages/core/src/utilities/findDuplicates.d.ts +1 -0
  121. package/dist/packages/core/src/utilities/fromString.d.ts +1 -1
  122. package/dist/packages/core/src/utilities/index.d.ts +20 -0
  123. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +1 -1
  124. package/dist/packages/core/src/utilities/isFunction.d.ts +1 -0
  125. package/dist/packages/core/src/utilities/isMacOS.d.ts +1 -0
  126. package/dist/packages/core/src/utilities/isNumber.d.ts +1 -0
  127. package/dist/packages/core/src/utilities/isPlainObject.d.ts +1 -1
  128. package/dist/packages/core/src/utilities/isRegExp.d.ts +1 -0
  129. package/dist/packages/core/src/utilities/isString.d.ts +1 -0
  130. package/dist/packages/core/src/utilities/isiOS.d.ts +1 -1
  131. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +1 -1
  132. package/dist/packages/core/src/utilities/mergeDeep.d.ts +1 -1
  133. package/dist/packages/core/src/utilities/minMax.d.ts +1 -1
  134. package/dist/packages/core/src/utilities/objectIncludes.d.ts +3 -1
  135. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +8 -0
  136. package/package.json +25 -24
  137. package/src/CommandManager.ts +73 -83
  138. package/src/Editor.ts +101 -53
  139. package/src/EventEmitter.ts +14 -4
  140. package/src/Extension.ts +244 -138
  141. package/src/ExtensionManager.ts +153 -152
  142. package/src/InputRule.ts +260 -0
  143. package/src/Mark.ts +365 -204
  144. package/src/Node.ts +406 -253
  145. package/src/NodeView.ts +59 -38
  146. package/src/PasteRule.ts +240 -0
  147. package/src/Tracker.ts +4 -8
  148. package/src/commands/blur.ts +4 -0
  149. package/src/commands/clearNodes.ts +15 -9
  150. package/src/commands/createParagraphNear.ts +3 -2
  151. package/src/commands/deleteCurrentNode.ts +41 -0
  152. package/src/commands/deleteNode.ts +3 -2
  153. package/src/commands/deleteRange.ts +1 -1
  154. package/src/commands/deleteSelection.ts +3 -2
  155. package/src/commands/exitCode.ts +3 -2
  156. package/src/commands/extendMarkRange.ts +9 -5
  157. package/src/commands/focus.ts +31 -42
  158. package/src/commands/index.ts +50 -0
  159. package/src/commands/insertContent.ts +15 -4
  160. package/src/commands/insertContentAt.ts +71 -14
  161. package/src/commands/join.ts +53 -0
  162. package/src/commands/keyboardShortcut.ts +3 -3
  163. package/src/commands/lift.ts +6 -5
  164. package/src/commands/liftEmptyBlock.ts +2 -1
  165. package/src/commands/liftListItem.ts +5 -4
  166. package/src/commands/newlineInCode.ts +3 -2
  167. package/src/commands/resetAttributes.ts +16 -10
  168. package/src/commands/selectAll.ts +5 -3
  169. package/src/commands/selectNodeBackward.ts +3 -2
  170. package/src/commands/selectNodeForward.ts +3 -2
  171. package/src/commands/selectParentNode.ts +3 -2
  172. package/src/commands/selectTextblockEnd.ts +20 -0
  173. package/src/commands/selectTextblockStart.ts +20 -0
  174. package/src/commands/setContent.ts +6 -9
  175. package/src/commands/setMark.ts +66 -13
  176. package/src/commands/setNode.ts +30 -6
  177. package/src/commands/setNodeSelection.ts +6 -7
  178. package/src/commands/setTextSelection.ts +8 -9
  179. package/src/commands/sinkListItem.ts +5 -4
  180. package/src/commands/splitBlock.ts +23 -38
  181. package/src/commands/splitListItem.ts +30 -27
  182. package/src/commands/toggleList.ts +108 -19
  183. package/src/commands/toggleMark.ts +17 -6
  184. package/src/commands/toggleNode.ts +9 -4
  185. package/src/commands/toggleWrap.ts +8 -8
  186. package/src/commands/undoInputRule.ts +31 -2
  187. package/src/commands/unsetAllMarks.ts +4 -8
  188. package/src/commands/unsetMark.ts +34 -21
  189. package/src/commands/updateAttributes.ts +18 -12
  190. package/src/commands/wrapIn.ts +5 -10
  191. package/src/commands/wrapInList.ts +5 -4
  192. package/src/extensions/clipboardTextSerializer.ts +15 -36
  193. package/src/extensions/commands.ts +3 -144
  194. package/src/extensions/editable.ts +2 -1
  195. package/src/extensions/focusEvents.ts +4 -6
  196. package/src/extensions/index.ts +1 -0
  197. package/src/extensions/keymap.ts +111 -13
  198. package/src/extensions/tabindex.ts +18 -0
  199. package/src/helpers/combineTransactionSteps.ts +21 -0
  200. package/src/helpers/createChainableState.ts +38 -0
  201. package/src/helpers/createDocument.ts +4 -3
  202. package/src/helpers/createNodeFromContent.ts +10 -15
  203. package/src/helpers/defaultBlockAt.ts +13 -0
  204. package/src/helpers/findChildren.ts +4 -3
  205. package/src/helpers/findChildrenInRange.ts +8 -3
  206. package/src/helpers/findParentNode.ts +4 -3
  207. package/src/helpers/findParentNodeClosestToPos.ts +13 -7
  208. package/src/helpers/generateHTML.ts +6 -5
  209. package/src/helpers/generateJSON.ts +6 -7
  210. package/src/helpers/generateText.ts +27 -0
  211. package/src/helpers/getAttributes.ts +8 -9
  212. package/src/helpers/getAttributesFromExtensions.ts +25 -12
  213. package/src/helpers/getChangedRanges.ts +83 -0
  214. package/src/helpers/getDebugJSON.ts +42 -38
  215. package/src/helpers/getExtensionField.ts +3 -3
  216. package/src/helpers/getHTMLFromFragment.ts +5 -6
  217. package/src/helpers/getMarkAttributes.ts +18 -10
  218. package/src/helpers/getMarkRange.ts +13 -8
  219. package/src/helpers/getMarkType.ts +5 -3
  220. package/src/helpers/getMarksBetween.ts +34 -10
  221. package/src/helpers/getNodeAttributes.ts +14 -12
  222. package/src/helpers/getNodeType.ts +5 -3
  223. package/src/helpers/getRenderedAttributes.ts +8 -6
  224. package/src/helpers/getSchema.ts +5 -4
  225. package/src/helpers/getSchemaByResolvedExtensions.ts +165 -111
  226. package/src/helpers/getSchemaTypeByName.ts +3 -11
  227. package/src/helpers/getSchemaTypeNameByName.ts +2 -2
  228. package/src/helpers/getSplittedAttributes.ts +1 -1
  229. package/src/helpers/getText.ts +19 -0
  230. package/src/helpers/getTextBetween.ts +46 -0
  231. package/src/helpers/getTextContentFromNodes.ts +26 -0
  232. package/src/helpers/getTextSerializersFromSchema.ts +11 -0
  233. package/src/helpers/index.ts +47 -0
  234. package/src/helpers/injectExtensionAttributesToParseRule.ts +22 -23
  235. package/src/helpers/isActive.ts +10 -5
  236. package/src/helpers/isExtensionRulesEnabled.ts +15 -0
  237. package/src/helpers/isList.ts +6 -5
  238. package/src/helpers/isMarkActive.ts +32 -35
  239. package/src/helpers/isNodeActive.ts +27 -37
  240. package/src/helpers/isNodeEmpty.ts +2 -2
  241. package/src/helpers/isNodeSelection.ts +3 -4
  242. package/src/helpers/isTextSelection.ts +3 -4
  243. package/src/helpers/posToDOMRect.ts +10 -4
  244. package/src/helpers/resolveFocusPosition.ts +42 -0
  245. package/src/helpers/selectionToInsertionEnd.ts +3 -3
  246. package/src/helpers/splitExtensions.ts +3 -3
  247. package/src/index.ts +12 -37
  248. package/src/inputRules/index.ts +5 -0
  249. package/src/inputRules/markInputRule.ts +59 -40
  250. package/src/inputRules/nodeInputRule.ts +45 -12
  251. package/src/inputRules/textInputRule.ts +35 -0
  252. package/src/inputRules/textblockTypeInputRule.ts +37 -0
  253. package/src/inputRules/wrappingInputRule.ts +84 -0
  254. package/src/pasteRules/index.ts +3 -0
  255. package/src/pasteRules/markPasteRule.ts +49 -56
  256. package/src/pasteRules/nodePasteRule.ts +37 -0
  257. package/src/pasteRules/textPasteRule.ts +35 -0
  258. package/src/style.ts +12 -3
  259. package/src/types.ts +140 -106
  260. package/src/utilities/callOrReturn.ts +3 -2
  261. package/src/utilities/createStyleTag.ts +8 -4
  262. package/src/utilities/deleteProps.ts +1 -1
  263. package/src/utilities/elementFromString.ts +1 -1
  264. package/src/utilities/escapeForRegEx.ts +4 -0
  265. package/src/utilities/findDuplicates.ts +5 -0
  266. package/src/utilities/fromString.ts +2 -2
  267. package/src/utilities/index.ts +20 -0
  268. package/src/utilities/isEmptyObject.ts +2 -2
  269. package/src/utilities/isFunction.ts +3 -0
  270. package/src/utilities/isMacOS.ts +5 -0
  271. package/src/utilities/isNumber.ts +3 -0
  272. package/src/utilities/isPlainObject.ts +8 -5
  273. package/src/utilities/isRegExp.ts +3 -0
  274. package/src/utilities/isString.ts +3 -0
  275. package/src/utilities/isiOS.ts +1 -1
  276. package/src/utilities/mergeAttributes.ts +2 -1
  277. package/src/utilities/mergeDeep.ts +2 -2
  278. package/src/utilities/minMax.ts +1 -1
  279. package/src/utilities/objectIncludes.ts +18 -4
  280. package/src/utilities/removeDuplicates.ts +15 -0
  281. package/CHANGELOG.md +0 -1190
  282. package/LICENSE.md +0 -21
  283. package/dist/packages/core/src/commands/joinBackward.d.ts +0 -12
  284. package/dist/packages/core/src/commands/joinForward.d.ts +0 -12
  285. package/dist/packages/core/src/utilities/isClass.d.ts +0 -1
  286. package/dist/packages/core/src/utilities/isObject.d.ts +0 -1
  287. package/dist/packages/core/src/utilities/removeElement.d.ts +0 -1
  288. package/dist/tiptap-core.cjs.js +0 -3408
  289. package/dist/tiptap-core.cjs.js.map +0 -1
  290. package/dist/tiptap-core.esm.js.map +0 -1
  291. package/dist/tiptap-core.umd.js +0 -3405
  292. package/dist/tiptap-core.umd.js.map +0 -1
  293. package/src/commands/joinBackward.ts +0 -17
  294. package/src/commands/joinForward.ts +0 -17
  295. package/src/utilities/isClass.ts +0 -7
  296. package/src/utilities/isObject.ts +0 -10
  297. package/src/utilities/removeElement.ts +0 -5
@@ -1,8 +1,18 @@
1
- export default class EventEmitter {
1
+ type StringKeyOf<T> = Extract<keyof T, string>
2
+ type CallbackType<
3
+ T extends Record<string, any>,
4
+ EventName extends StringKeyOf<T>,
5
+ > = T[EventName] extends any[] ? T[EventName] : [T[EventName]]
6
+ type CallbackFunction<
7
+ T extends Record<string, any>,
8
+ EventName extends StringKeyOf<T>,
9
+ > = (...props: CallbackType<T, EventName>) => any
10
+
11
+ export class EventEmitter<T extends Record<string, any>> {
2
12
 
3
13
  private callbacks: { [key: string]: Function[] } = {}
4
14
 
5
- public on(event: string, fn: Function): this {
15
+ public on<EventName extends StringKeyOf<T>>(event: EventName, fn: CallbackFunction<T, EventName>): this {
6
16
  if (!this.callbacks[event]) {
7
17
  this.callbacks[event] = []
8
18
  }
@@ -12,7 +22,7 @@ export default class EventEmitter {
12
22
  return this
13
23
  }
14
24
 
15
- protected emit(event: string, ...args: any): this {
25
+ protected emit<EventName extends StringKeyOf<T>>(event: EventName, ...args: CallbackType<T, EventName>): this {
16
26
  const callbacks = this.callbacks[event]
17
27
 
18
28
  if (callbacks) {
@@ -22,7 +32,7 @@ export default class EventEmitter {
22
32
  return this
23
33
  }
24
34
 
25
- public off(event: string, fn?: Function): this {
35
+ public off<EventName extends StringKeyOf<T>>(event: EventName, fn?: CallbackFunction<T, EventName>): this {
26
36
  const callbacks = this.callbacks[event]
27
37
 
28
38
  if (callbacks) {
package/src/Extension.ts CHANGED
@@ -1,229 +1,288 @@
1
- import { Plugin, Transaction } from 'prosemirror-state'
2
- import { InputRule } from 'prosemirror-inputrules'
1
+ import { Plugin, Transaction } from '@tiptap/pm/state'
2
+
3
+ import { ExtensionConfig } from '.'
3
4
  import { Editor } from './Editor'
4
- import { Node } from './Node'
5
+ import { getExtensionField } from './helpers/getExtensionField'
6
+ import { InputRule } from './InputRule'
5
7
  import { Mark } from './Mark'
6
- import mergeDeep from './utilities/mergeDeep'
8
+ import { Node } from './Node'
9
+ import { PasteRule } from './PasteRule'
7
10
  import {
11
+ AnyConfig,
8
12
  Extensions,
9
13
  GlobalAttributes,
10
- RawCommands,
11
- ParentConfig,
12
14
  KeyboardShortcutCommand,
15
+ ParentConfig,
16
+ RawCommands,
13
17
  } from './types'
14
- import { ExtensionConfig } from '.'
18
+ import { callOrReturn } from './utilities/callOrReturn'
19
+ import { mergeDeep } from './utilities/mergeDeep'
15
20
 
16
21
  declare module '@tiptap/core' {
17
- interface ExtensionConfig<Options = any> {
18
- [key: string]: any;
22
+ interface ExtensionConfig<Options = any, Storage = any> {
23
+ [key: string]: any
19
24
 
20
25
  /**
21
26
  * Name
22
27
  */
23
- name: string,
28
+ name: string
24
29
 
25
30
  /**
26
31
  * Priority
27
32
  */
28
- priority?: number,
33
+ priority?: number
29
34
 
30
35
  /**
31
36
  * Default options
32
37
  */
33
- defaultOptions?: Options,
38
+ defaultOptions?: Options
39
+
40
+ /**
41
+ * Default Options
42
+ */
43
+ addOptions?: (this: {
44
+ name: string
45
+ parent: Exclude<ParentConfig<ExtensionConfig<Options, Storage>>['addOptions'], undefined>
46
+ }) => Options
47
+
48
+ /**
49
+ * Default Storage
50
+ */
51
+ addStorage?: (this: {
52
+ name: string
53
+ options: Options
54
+ parent: Exclude<ParentConfig<ExtensionConfig<Options, Storage>>['addStorage'], undefined>
55
+ }) => Storage
34
56
 
35
57
  /**
36
58
  * Global attributes
37
59
  */
38
60
  addGlobalAttributes?: (this: {
39
- name: string,
40
- options: Options,
41
- parent: ParentConfig<ExtensionConfig<Options>>['addGlobalAttributes'],
42
- }) => GlobalAttributes | {},
61
+ name: string
62
+ options: Options
63
+ storage: Storage
64
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['addGlobalAttributes']
65
+ }) => GlobalAttributes | {}
43
66
 
44
67
  /**
45
68
  * Raw
46
69
  */
47
70
  addCommands?: (this: {
48
- name: string,
49
- options: Options,
50
- editor: Editor,
51
- parent: ParentConfig<ExtensionConfig<Options>>['addCommands'],
52
- }) => Partial<RawCommands>,
71
+ name: string
72
+ options: Options
73
+ storage: Storage
74
+ editor: Editor
75
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['addCommands']
76
+ }) => Partial<RawCommands>
53
77
 
54
78
  /**
55
79
  * Keyboard shortcuts
56
80
  */
57
81
  addKeyboardShortcuts?: (this: {
58
- name: string,
59
- options: Options,
60
- editor: Editor,
61
- parent: ParentConfig<ExtensionConfig<Options>>['addKeyboardShortcuts'],
82
+ name: string
83
+ options: Options
84
+ storage: Storage
85
+ editor: Editor
86
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['addKeyboardShortcuts']
62
87
  }) => {
63
- [key: string]: KeyboardShortcutCommand,
64
- },
88
+ [key: string]: KeyboardShortcutCommand
89
+ }
65
90
 
66
91
  /**
67
92
  * Input rules
68
93
  */
69
94
  addInputRules?: (this: {
70
- name: string,
71
- options: Options,
72
- editor: Editor,
73
- parent: ParentConfig<ExtensionConfig<Options>>['addInputRules'],
74
- }) => InputRule[],
95
+ name: string
96
+ options: Options
97
+ storage: Storage
98
+ editor: Editor
99
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['addInputRules']
100
+ }) => InputRule[]
75
101
 
76
102
  /**
77
103
  * Paste rules
78
104
  */
79
105
  addPasteRules?: (this: {
80
- name: string,
81
- options: Options,
82
- editor: Editor,
83
- parent: ParentConfig<ExtensionConfig<Options>>['addPasteRules'],
84
- }) => Plugin[],
106
+ name: string
107
+ options: Options
108
+ storage: Storage
109
+ editor: Editor
110
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['addPasteRules']
111
+ }) => PasteRule[]
85
112
 
86
113
  /**
87
114
  * ProseMirror plugins
88
115
  */
89
116
  addProseMirrorPlugins?: (this: {
90
- name: string,
91
- options: Options,
92
- editor: Editor,
93
- parent: ParentConfig<ExtensionConfig<Options>>['addProseMirrorPlugins'],
94
- }) => Plugin[],
117
+ name: string
118
+ options: Options
119
+ storage: Storage
120
+ editor: Editor
121
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['addProseMirrorPlugins']
122
+ }) => Plugin[]
95
123
 
96
124
  /**
97
125
  * Extensions
98
126
  */
99
127
  addExtensions?: (this: {
100
- name: string,
101
- options: Options,
102
- parent: ParentConfig<ExtensionConfig<Options>>['addExtensions'],
103
- }) => Extensions,
128
+ name: string
129
+ options: Options
130
+ storage: Storage
131
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['addExtensions']
132
+ }) => Extensions
104
133
 
105
134
  /**
106
135
  * Extend Node Schema
107
136
  */
108
- extendNodeSchema?: ((
109
- this: {
110
- name: string,
111
- options: Options,
112
- parent: ParentConfig<ExtensionConfig<Options>>['extendNodeSchema'],
113
- },
114
- extension: Node,
115
- ) => Record<string, any>) | null,
137
+ extendNodeSchema?:
138
+ | ((
139
+ this: {
140
+ name: string
141
+ options: Options
142
+ storage: Storage
143
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['extendNodeSchema']
144
+ },
145
+ extension: Node,
146
+ ) => Record<string, any>)
147
+ | null
116
148
 
117
149
  /**
118
150
  * Extend Mark Schema
119
151
  */
120
- extendMarkSchema?: ((
121
- this: {
122
- name: string,
123
- options: Options,
124
- parent: ParentConfig<ExtensionConfig<Options>>['extendMarkSchema'],
125
- },
126
- extension: Mark,
127
- ) => Record<string, any>) | null,
152
+ extendMarkSchema?:
153
+ | ((
154
+ this: {
155
+ name: string
156
+ options: Options
157
+ storage: Storage
158
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['extendMarkSchema']
159
+ },
160
+ extension: Mark,
161
+ ) => Record<string, any>)
162
+ | null
128
163
 
129
164
  /**
130
165
  * The editor is not ready yet.
131
166
  */
132
- onBeforeCreate?: ((this: {
133
- name: string,
134
- options: Options,
135
- editor: Editor,
136
- parent: ParentConfig<ExtensionConfig<Options>>['onBeforeCreate'],
137
- }) => void) | null,
167
+ onBeforeCreate?:
168
+ | ((this: {
169
+ name: string
170
+ options: Options
171
+ storage: Storage
172
+ editor: Editor
173
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['onBeforeCreate']
174
+ }) => void)
175
+ | null
138
176
 
139
177
  /**
140
178
  * The editor is ready.
141
179
  */
142
- onCreate?: ((this: {
143
- name: string,
144
- options: Options,
145
- editor: Editor,
146
- parent: ParentConfig<ExtensionConfig<Options>>['onCreate'],
147
- }) => void) | null,
180
+ onCreate?:
181
+ | ((this: {
182
+ name: string
183
+ options: Options
184
+ storage: Storage
185
+ editor: Editor
186
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['onCreate']
187
+ }) => void)
188
+ | null
148
189
 
149
190
  /**
150
191
  * The content has changed.
151
192
  */
152
- onUpdate?: ((this: {
153
- name: string,
154
- options: Options,
155
- editor: Editor,
156
- parent: ParentConfig<ExtensionConfig<Options>>['onUpdate'],
157
- }) => void) | null,
193
+ onUpdate?:
194
+ | ((this: {
195
+ name: string
196
+ options: Options
197
+ storage: Storage
198
+ editor: Editor
199
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['onUpdate']
200
+ }) => void)
201
+ | null
158
202
 
159
203
  /**
160
204
  * The selection has changed.
161
205
  */
162
- onSelectionUpdate?: ((this: {
163
- name: string,
164
- options: Options,
165
- editor: Editor,
166
- parent: ParentConfig<ExtensionConfig<Options>>['onSelectionUpdate'],
167
- }) => void) | null,
206
+ onSelectionUpdate?:
207
+ | ((this: {
208
+ name: string
209
+ options: Options
210
+ storage: Storage
211
+ editor: Editor
212
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['onSelectionUpdate']
213
+ }) => void)
214
+ | null
168
215
 
169
216
  /**
170
217
  * The editor state has changed.
171
218
  */
172
- onTransaction?: ((
173
- this: {
174
- name: string,
175
- options: Options,
176
- editor: Editor,
177
- parent: ParentConfig<ExtensionConfig<Options>>['onTransaction'],
178
- },
179
- props: {
180
- transaction: Transaction,
181
- },
182
- ) => void) | null,
219
+ onTransaction?:
220
+ | ((
221
+ this: {
222
+ name: string
223
+ options: Options
224
+ storage: Storage
225
+ editor: Editor
226
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['onTransaction']
227
+ },
228
+ props: {
229
+ transaction: Transaction
230
+ },
231
+ ) => void)
232
+ | null
183
233
 
184
234
  /**
185
235
  * The editor is focused.
186
236
  */
187
- onFocus?: ((
188
- this: {
189
- name: string,
190
- options: Options,
191
- editor: Editor,
192
- parent: ParentConfig<ExtensionConfig<Options>>['onFocus'],
193
- },
194
- props: {
195
- event: FocusEvent,
196
- },
197
- ) => void) | null,
237
+ onFocus?:
238
+ | ((
239
+ this: {
240
+ name: string
241
+ options: Options
242
+ storage: Storage
243
+ editor: Editor
244
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['onFocus']
245
+ },
246
+ props: {
247
+ event: FocusEvent
248
+ },
249
+ ) => void)
250
+ | null
198
251
 
199
252
  /**
200
253
  * The editor isn’t focused anymore.
201
254
  */
202
- onBlur?: ((
203
- this: {
204
- name: string,
205
- options: Options,
206
- editor: Editor,
207
- parent: ParentConfig<ExtensionConfig<Options>>['onBlur'],
208
- },
209
- props: {
210
- event: FocusEvent,
211
- },
212
- ) => void) | null,
255
+ onBlur?:
256
+ | ((
257
+ this: {
258
+ name: string
259
+ options: Options
260
+ storage: Storage
261
+ editor: Editor
262
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['onBlur']
263
+ },
264
+ props: {
265
+ event: FocusEvent
266
+ },
267
+ ) => void)
268
+ | null
213
269
 
214
270
  /**
215
271
  * The editor is destroyed.
216
272
  */
217
- onDestroy?: ((this: {
218
- name: string,
219
- options: Options,
220
- editor: Editor,
221
- parent: ParentConfig<ExtensionConfig<Options>>['onDestroy'],
222
- }) => void) | null,
273
+ onDestroy?:
274
+ | ((this: {
275
+ name: string
276
+ options: Options
277
+ storage: Storage
278
+ editor: Editor
279
+ parent: ParentConfig<ExtensionConfig<Options, Storage>>['onDestroy']
280
+ }) => void)
281
+ | null
223
282
  }
224
283
  }
225
284
 
226
- export class Extension<Options = any> {
285
+ export class Extension<Options = any, Storage = any> {
227
286
  type = 'extension'
228
287
 
229
288
  name = 'extension'
@@ -234,23 +293,48 @@ export class Extension<Options = any> {
234
293
 
235
294
  options: Options
236
295
 
296
+ storage: Storage
297
+
237
298
  config: ExtensionConfig = {
238
299
  name: this.name,
239
300
  defaultOptions: {},
240
301
  }
241
302
 
242
- constructor(config: Partial<ExtensionConfig<Options>> = {}) {
303
+ constructor(config: Partial<ExtensionConfig<Options, Storage>> = {}) {
243
304
  this.config = {
244
305
  ...this.config,
245
306
  ...config,
246
307
  }
247
308
 
248
309
  this.name = this.config.name
310
+
311
+ if (config.defaultOptions) {
312
+ console.warn(
313
+ `[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`,
314
+ )
315
+ }
316
+
317
+ // TODO: remove `addOptions` fallback
249
318
  this.options = this.config.defaultOptions
319
+
320
+ if (this.config.addOptions) {
321
+ this.options = callOrReturn(
322
+ getExtensionField<AnyConfig['addOptions']>(this, 'addOptions', {
323
+ name: this.name,
324
+ }),
325
+ )
326
+ }
327
+
328
+ this.storage = callOrReturn(
329
+ getExtensionField<AnyConfig['addStorage']>(this, 'addStorage', {
330
+ name: this.name,
331
+ options: this.options,
332
+ }),
333
+ ) || {}
250
334
  }
251
335
 
252
- static create<O>(config: Partial<ExtensionConfig<O>> = {}) {
253
- return new Extension<O>(config)
336
+ static create<O = any, S = any>(config: Partial<ExtensionConfig<O, S>> = {}) {
337
+ return new Extension<O, S>(config)
254
338
  }
255
339
 
256
340
  configure(options: Partial<Options> = {}) {
@@ -258,25 +342,47 @@ export class Extension<Options = any> {
258
342
  // with different calls of `configure`
259
343
  const extension = this.extend()
260
344
 
261
- extension.options = mergeDeep(this.options, options) as Options
345
+ extension.options = mergeDeep(this.options as Record<string, any>, options) as Options
346
+
347
+ extension.storage = callOrReturn(
348
+ getExtensionField<AnyConfig['addStorage']>(extension, 'addStorage', {
349
+ name: extension.name,
350
+ options: extension.options,
351
+ }),
352
+ )
262
353
 
263
354
  return extension
264
355
  }
265
356
 
266
- extend<ExtendedOptions = Options>(extendedConfig: Partial<ExtensionConfig<ExtendedOptions>> = {}) {
267
- const extension = new Extension<ExtendedOptions>(extendedConfig)
357
+ extend<ExtendedOptions = Options, ExtendedStorage = Storage>(
358
+ extendedConfig: Partial<ExtensionConfig<ExtendedOptions, ExtendedStorage>> = {},
359
+ ) {
360
+ const extension = new Extension<ExtendedOptions, ExtendedStorage>(extendedConfig)
268
361
 
269
362
  extension.parent = this
270
363
 
271
364
  this.child = extension
272
365
 
273
- extension.name = extendedConfig.name
274
- ? extendedConfig.name
275
- : extension.parent.name
366
+ extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name
367
+
368
+ if (extendedConfig.defaultOptions) {
369
+ console.warn(
370
+ `[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`,
371
+ )
372
+ }
276
373
 
277
- extension.options = extendedConfig.defaultOptions
278
- ? extendedConfig.defaultOptions
279
- : extension.parent.options
374
+ extension.options = callOrReturn(
375
+ getExtensionField<AnyConfig['addOptions']>(extension, 'addOptions', {
376
+ name: extension.name,
377
+ }),
378
+ )
379
+
380
+ extension.storage = callOrReturn(
381
+ getExtensionField<AnyConfig['addStorage']>(extension, 'addStorage', {
382
+ name: extension.name,
383
+ options: extension.options,
384
+ }),
385
+ )
280
386
 
281
387
  return extension
282
388
  }