@tiptap/core 2.0.0-beta.21 → 2.0.0-beta.210

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 (289) hide show
  1. package/README.md +2 -2
  2. package/dist/index.cjs +4311 -0
  3. package/dist/index.d.ts +2330 -0
  4. package/dist/index.js +4311 -0
  5. package/package.json +39 -25
  6. package/src/CommandManager.ts +76 -86
  7. package/src/Editor.ts +120 -81
  8. package/src/EventEmitter.ts +14 -4
  9. package/src/Extension.ts +280 -108
  10. package/src/ExtensionManager.ts +254 -108
  11. package/src/InputRule.ts +260 -0
  12. package/src/Mark.ts +398 -147
  13. package/src/Node.ts +437 -171
  14. package/src/NodeView.ts +132 -63
  15. package/src/PasteRule.ts +240 -0
  16. package/src/Tracker.ts +38 -0
  17. package/src/commands/blur.ts +12 -6
  18. package/src/commands/clearContent.ts +3 -3
  19. package/src/commands/clearNodes.ts +31 -19
  20. package/src/commands/command.ts +2 -2
  21. package/src/commands/createParagraphNear.ts +5 -4
  22. package/src/commands/deleteCurrentNode.ts +41 -0
  23. package/src/commands/deleteNode.ts +37 -0
  24. package/src/commands/deleteRange.ts +3 -3
  25. package/src/commands/deleteSelection.ts +5 -4
  26. package/src/commands/enter.ts +3 -3
  27. package/src/commands/exitCode.ts +5 -4
  28. package/src/commands/extendMarkRange.ts +16 -12
  29. package/src/commands/first.ts +3 -3
  30. package/src/commands/focus.ts +47 -44
  31. package/src/commands/forEach.ts +24 -0
  32. package/src/commands/index.ts +50 -0
  33. package/src/commands/insertContent.ts +17 -24
  34. package/src/commands/insertContentAt.ts +94 -0
  35. package/src/commands/join.ts +53 -0
  36. package/src/commands/keyboardShortcut.ts +6 -6
  37. package/src/commands/lift.ts +8 -7
  38. package/src/commands/liftEmptyBlock.ts +5 -4
  39. package/src/commands/liftListItem.ts +7 -6
  40. package/src/commands/newlineInCode.ts +5 -4
  41. package/src/commands/resetAttributes.ts +18 -12
  42. package/src/commands/scrollIntoView.ts +3 -3
  43. package/src/commands/selectAll.ts +8 -6
  44. package/src/commands/selectNodeBackward.ts +5 -4
  45. package/src/commands/selectNodeForward.ts +5 -4
  46. package/src/commands/selectParentNode.ts +5 -4
  47. package/src/commands/selectTextblockEnd.ts +20 -0
  48. package/src/commands/selectTextblockStart.ts +20 -0
  49. package/src/commands/setContent.ts +9 -16
  50. package/src/commands/setMark.ts +90 -14
  51. package/src/commands/setMeta.ts +18 -0
  52. package/src/commands/setNode.ts +32 -8
  53. package/src/commands/setNodeSelection.ts +27 -0
  54. package/src/commands/setTextSelection.ts +31 -0
  55. package/src/commands/sinkListItem.ts +7 -6
  56. package/src/commands/splitBlock.ts +31 -41
  57. package/src/commands/splitListItem.ts +46 -29
  58. package/src/commands/toggleList.ts +88 -20
  59. package/src/commands/toggleMark.ts +19 -8
  60. package/src/commands/toggleNode.ts +11 -6
  61. package/src/commands/toggleWrap.ts +10 -10
  62. package/src/commands/undoInputRule.ts +34 -5
  63. package/src/commands/unsetAllMarks.ts +7 -11
  64. package/src/commands/unsetMark.ts +36 -23
  65. package/src/commands/updateAttributes.ts +27 -15
  66. package/src/commands/wrapIn.ts +7 -12
  67. package/src/commands/wrapInList.ts +7 -6
  68. package/src/extensions/clipboardTextSerializer.ts +15 -36
  69. package/src/extensions/commands.ts +3 -147
  70. package/src/extensions/editable.ts +2 -1
  71. package/src/extensions/focusEvents.ts +4 -6
  72. package/src/extensions/index.ts +1 -0
  73. package/src/extensions/keymap.ts +106 -13
  74. package/src/extensions/tabindex.ts +18 -0
  75. package/src/helpers/combineTransactionSteps.ts +21 -0
  76. package/src/helpers/createChainableState.ts +38 -0
  77. package/src/helpers/createDocument.ts +5 -6
  78. package/src/helpers/createNodeFromContent.ts +20 -28
  79. package/src/helpers/defaultBlockAt.ts +13 -0
  80. package/src/helpers/findChildren.ts +18 -0
  81. package/src/helpers/findChildrenInRange.ts +36 -0
  82. package/src/helpers/findParentNode.ts +4 -3
  83. package/src/helpers/findParentNodeClosestToPos.ts +13 -7
  84. package/src/helpers/generateHTML.ts +7 -6
  85. package/src/helpers/generateJSON.ts +12 -0
  86. package/src/helpers/generateText.ts +27 -0
  87. package/src/helpers/getAttributes.ts +26 -0
  88. package/src/helpers/getAttributesFromExtensions.ts +42 -14
  89. package/src/helpers/getChangedRanges.ts +83 -0
  90. package/src/helpers/getDebugJSON.ts +54 -0
  91. package/src/helpers/getExtensionField.ts +25 -0
  92. package/src/helpers/getHTMLFromFragment.ts +5 -6
  93. package/src/helpers/getMarkAttributes.ts +18 -11
  94. package/src/helpers/getMarkRange.ts +41 -8
  95. package/src/helpers/getMarkType.ts +8 -2
  96. package/src/helpers/getMarksBetween.ts +34 -10
  97. package/src/helpers/getNodeAttributes.ts +14 -13
  98. package/src/helpers/getNodeType.ts +8 -2
  99. package/src/helpers/getRenderedAttributes.ts +9 -7
  100. package/src/helpers/getSchema.ts +7 -133
  101. package/src/helpers/getSchemaByResolvedExtensions.ts +192 -0
  102. package/src/helpers/getSchemaTypeByName.ts +3 -11
  103. package/src/helpers/getSchemaTypeNameByName.ts +2 -2
  104. package/src/helpers/getSplittedAttributes.ts +4 -4
  105. package/src/helpers/getText.ts +19 -0
  106. package/src/helpers/getTextBetween.ts +46 -0
  107. package/src/helpers/getTextContentFromNodes.ts +26 -0
  108. package/src/helpers/getTextSerializersFromSchema.ts +11 -0
  109. package/src/helpers/index.ts +33 -0
  110. package/src/helpers/injectExtensionAttributesToParseRule.ts +22 -23
  111. package/src/helpers/isActive.ts +10 -6
  112. package/src/helpers/isExtensionRulesEnabled.ts +15 -0
  113. package/src/helpers/isList.ts +14 -7
  114. package/src/helpers/isMarkActive.ts +49 -27
  115. package/src/helpers/isNodeActive.ts +29 -39
  116. package/src/helpers/isNodeEmpty.ts +2 -2
  117. package/src/helpers/isNodeSelection.ts +3 -4
  118. package/src/helpers/isTextSelection.ts +3 -4
  119. package/src/helpers/posToDOMRect.ts +35 -0
  120. package/src/helpers/resolveFocusPosition.ts +42 -0
  121. package/src/helpers/selectionToInsertionEnd.ts +3 -3
  122. package/src/helpers/splitExtensions.ts +3 -3
  123. package/src/index.ts +15 -24
  124. package/src/inputRules/index.ts +5 -0
  125. package/src/inputRules/markInputRule.ts +59 -40
  126. package/src/inputRules/nodeInputRule.ts +45 -12
  127. package/src/inputRules/textInputRule.ts +35 -0
  128. package/src/inputRules/textblockTypeInputRule.ts +37 -0
  129. package/src/inputRules/wrappingInputRule.ts +59 -0
  130. package/src/pasteRules/index.ts +3 -0
  131. package/src/pasteRules/markPasteRule.ts +61 -53
  132. package/src/pasteRules/nodePasteRule.ts +37 -0
  133. package/src/pasteRules/textPasteRule.ts +35 -0
  134. package/src/style.ts +16 -3
  135. package/src/types.ts +170 -97
  136. package/src/utilities/callOrReturn.ts +6 -3
  137. package/src/utilities/createStyleTag.ts +12 -1
  138. package/src/utilities/deleteProps.ts +2 -4
  139. package/src/utilities/elementFromString.ts +4 -5
  140. package/src/utilities/escapeForRegEx.ts +4 -0
  141. package/src/utilities/findDuplicates.ts +5 -0
  142. package/src/utilities/fromString.ts +2 -2
  143. package/src/utilities/index.ts +20 -0
  144. package/src/utilities/isEmptyObject.ts +2 -2
  145. package/src/utilities/isFunction.ts +3 -0
  146. package/src/utilities/isMacOS.ts +5 -0
  147. package/src/utilities/isNumber.ts +3 -0
  148. package/src/utilities/isPlainObject.ts +8 -5
  149. package/src/utilities/isRegExp.ts +3 -0
  150. package/src/utilities/isString.ts +3 -0
  151. package/src/utilities/isiOS.ts +12 -0
  152. package/src/utilities/mergeAttributes.ts +2 -3
  153. package/src/utilities/mergeDeep.ts +2 -3
  154. package/src/utilities/minMax.ts +1 -1
  155. package/src/utilities/objectIncludes.ts +17 -5
  156. package/src/utilities/removeDuplicates.ts +15 -0
  157. package/CHANGELOG.md +0 -365
  158. package/LICENSE.md +0 -21
  159. package/dist/packages/core/src/CommandManager.d.ts +0 -13
  160. package/dist/packages/core/src/Editor.d.ts +0 -142
  161. package/dist/packages/core/src/EventEmitter.d.ts +0 -7
  162. package/dist/packages/core/src/Extension.d.ts +0 -148
  163. package/dist/packages/core/src/ExtensionManager.d.ts +0 -24
  164. package/dist/packages/core/src/Mark.d.ts +0 -211
  165. package/dist/packages/core/src/Node.d.ts +0 -265
  166. package/dist/packages/core/src/NodeView.d.ts +0 -31
  167. package/dist/packages/core/src/commands/blur.d.ts +0 -12
  168. package/dist/packages/core/src/commands/clearContent.d.ts +0 -12
  169. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -12
  170. package/dist/packages/core/src/commands/command.d.ts +0 -12
  171. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -12
  172. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -12
  173. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -12
  174. package/dist/packages/core/src/commands/enter.d.ts +0 -12
  175. package/dist/packages/core/src/commands/exitCode.d.ts +0 -12
  176. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -13
  177. package/dist/packages/core/src/commands/first.d.ts +0 -12
  178. package/dist/packages/core/src/commands/focus.d.ts +0 -12
  179. package/dist/packages/core/src/commands/insertContent.d.ts +0 -12
  180. package/dist/packages/core/src/commands/insertHTML.d.ts +0 -12
  181. package/dist/packages/core/src/commands/insertNode.d.ts +0 -13
  182. package/dist/packages/core/src/commands/insertText.d.ts +0 -12
  183. package/dist/packages/core/src/commands/joinBackward.d.ts +0 -12
  184. package/dist/packages/core/src/commands/joinForward.d.ts +0 -12
  185. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -12
  186. package/dist/packages/core/src/commands/lift.d.ts +0 -13
  187. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -12
  188. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -13
  189. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -12
  190. package/dist/packages/core/src/commands/replace.d.ts +0 -13
  191. package/dist/packages/core/src/commands/replaceRange.d.ts +0 -13
  192. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -13
  193. package/dist/packages/core/src/commands/resetNodeAttributes.d.ts +0 -13
  194. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -12
  195. package/dist/packages/core/src/commands/selectAll.d.ts +0 -12
  196. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -12
  197. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -12
  198. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -12
  199. package/dist/packages/core/src/commands/setContent.d.ts +0 -12
  200. package/dist/packages/core/src/commands/setMark.d.ts +0 -13
  201. package/dist/packages/core/src/commands/setNode.d.ts +0 -13
  202. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -13
  203. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -14
  204. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -13
  205. package/dist/packages/core/src/commands/toggleList.d.ts +0 -13
  206. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -13
  207. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -13
  208. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -13
  209. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -12
  210. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -12
  211. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -13
  212. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -13
  213. package/dist/packages/core/src/commands/updateNodeAttributes.d.ts +0 -13
  214. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -13
  215. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -13
  216. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -2
  217. package/dist/packages/core/src/extensions/commands.d.ts +0 -100
  218. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  219. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  220. package/dist/packages/core/src/extensions/index.d.ts +0 -5
  221. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  222. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -4
  223. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -8
  224. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -9
  225. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -8
  226. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -2
  227. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  228. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  229. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -4
  230. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  231. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  232. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  233. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -4
  234. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  235. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  236. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -3
  237. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -2
  238. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -2
  239. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -2
  240. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  241. package/dist/packages/core/src/helpers/isActive.d.ts +0 -3
  242. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  243. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -4
  244. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -4
  245. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
  246. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  247. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  248. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  249. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  250. package/dist/packages/core/src/index.d.ts +0 -30
  251. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -3
  252. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -3
  253. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -3
  254. package/dist/packages/core/src/style.d.ts +0 -2
  255. package/dist/packages/core/src/types.d.ts +0 -154
  256. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -8
  257. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  258. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -7
  259. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  260. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  261. package/dist/packages/core/src/utilities/isClass.d.ts +0 -1
  262. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  263. package/dist/packages/core/src/utilities/isObject.d.ts +0 -1
  264. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  265. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -2
  266. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -2
  267. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  268. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -7
  269. package/dist/packages/core/src/utilities/removeElement.d.ts +0 -1
  270. package/dist/tiptap-core.bundle.umd.min.js +0 -17
  271. package/dist/tiptap-core.bundle.umd.min.js.map +0 -1
  272. package/dist/tiptap-core.cjs.js +0 -3027
  273. package/dist/tiptap-core.cjs.js.map +0 -1
  274. package/dist/tiptap-core.esm.js +0 -3002
  275. package/dist/tiptap-core.esm.js.map +0 -1
  276. package/dist/tiptap-core.umd.js +0 -3024
  277. package/dist/tiptap-core.umd.js.map +0 -1
  278. package/src/commands/insertHTML.ts +0 -30
  279. package/src/commands/insertNode.ts +0 -33
  280. package/src/commands/insertText.ts +0 -22
  281. package/src/commands/joinBackward.ts +0 -17
  282. package/src/commands/joinForward.ts +0 -17
  283. package/src/commands/replace.ts +0 -20
  284. package/src/commands/replaceRange.ts +0 -36
  285. package/src/commands/resetNodeAttributes.ts +0 -33
  286. package/src/commands/updateNodeAttributes.ts +0 -35
  287. package/src/utilities/isClass.ts +0 -7
  288. package/src/utilities/isObject.ts +0 -10
  289. package/src/utilities/removeElement.ts +0 -5
package/src/types.ts CHANGED
@@ -1,167 +1,240 @@
1
+ import { Mark as ProseMirrorMark, Node as ProseMirrorNode, ParseOptions } from '@tiptap/pm/model'
2
+ import { EditorState, Transaction } from '@tiptap/pm/state'
1
3
  import {
2
- Node as ProseMirrorNode,
3
- Mark as ProseMirrorMark,
4
- ParseOptions,
5
- } from 'prosemirror-model'
4
+ Decoration, EditorProps, EditorView, NodeView,
5
+ } from '@tiptap/pm/view'
6
+
6
7
  import {
7
- EditorView,
8
- Decoration,
9
- NodeView,
10
- EditorProps,
11
- } from 'prosemirror-view'
12
- import { EditorState, Transaction } from 'prosemirror-state'
8
+ Commands, ExtensionConfig, MarkConfig, NodeConfig,
9
+ } from '.'
10
+ import { Editor } from './Editor'
13
11
  import { Extension } from './Extension'
14
- import { Node } from './Node'
15
12
  import { Mark } from './Mark'
16
- import { Editor } from './Editor'
17
- import { Commands } from '.'
13
+ import { Node } from './Node'
14
+
15
+ export type AnyConfig = ExtensionConfig | NodeConfig | MarkConfig
16
+ export type AnyExtension = Extension | Node | Mark
17
+ export type Extensions = AnyExtension[]
18
+
19
+ export type ParentConfig<T> = Partial<{
20
+ [P in keyof T]: Required<T>[P] extends (...args: any) => any
21
+ ? (...args: Parameters<Required<T>[P]>) => ReturnType<Required<T>[P]>
22
+ : T[P]
23
+ }>
24
+
25
+ export type Primitive = null | undefined | string | number | boolean | symbol | bigint
26
+
27
+ export type RemoveThis<T> = T extends (...args: any) => any
28
+ ? (...args: Parameters<T>) => ReturnType<T>
29
+ : T
30
+
31
+ export type MaybeReturnType<T> = T extends (...args: any) => any ? ReturnType<T> : T
32
+
33
+ export type MaybeThisParameterType<T> = Exclude<T, Primitive> extends (...args: any) => any
34
+ ? ThisParameterType<Exclude<T, Primitive>>
35
+ : any
36
+
37
+ export interface EditorEvents {
38
+ beforeCreate: { editor: Editor }
39
+ create: { editor: Editor }
40
+ update: { editor: Editor; transaction: Transaction }
41
+ selectionUpdate: { editor: Editor; transaction: Transaction }
42
+ transaction: { editor: Editor; transaction: Transaction }
43
+ focus: { editor: Editor; event: FocusEvent; transaction: Transaction }
44
+ blur: { editor: Editor; event: FocusEvent; transaction: Transaction }
45
+ destroy: void
46
+ }
18
47
 
19
- export type Extensions = (Extension | Node | Mark)[]
48
+ export type EnableRules = (AnyExtension | string)[] | boolean
20
49
 
21
50
  export interface EditorOptions {
22
- element: Element,
23
- content: Content,
24
- extensions: Extensions,
25
- injectCSS: boolean,
26
- autofocus: FocusPosition,
27
- editable: boolean,
28
- editorProps: EditorProps,
29
- parseOptions: ParseOptions,
30
- enableInputRules: boolean,
31
- enablePasteRules: boolean,
32
- onCreate: (props: { editor: Editor }) => void,
33
- onUpdate: (props: { editor: Editor }) => void,
34
- onSelectionUpdate: (props: { editor: Editor }) => void,
35
- onTransaction: (props: { editor: Editor, transaction: Transaction }) => void,
36
- onFocus: (props: { editor: Editor, event: FocusEvent }) => void,
37
- onBlur: (props: { editor: Editor, event: FocusEvent }) => void,
38
- onResize: (props: { editor: Editor }) => void,
39
- onDestroy: () => void,
40
- }
41
-
42
- export type Content = string | JSON | null
51
+ element: Element
52
+ content: Content
53
+ extensions: Extensions
54
+ injectCSS: boolean
55
+ injectNonce: string | undefined
56
+ autofocus: FocusPosition
57
+ editable: boolean
58
+ editorProps: EditorProps
59
+ parseOptions: ParseOptions
60
+ enableInputRules: EnableRules
61
+ enablePasteRules: EnableRules
62
+ enableCoreExtensions: boolean
63
+ onBeforeCreate: (props: EditorEvents['beforeCreate']) => void
64
+ onCreate: (props: EditorEvents['create']) => void
65
+ onUpdate: (props: EditorEvents['update']) => void
66
+ onSelectionUpdate: (props: EditorEvents['selectionUpdate']) => void
67
+ onTransaction: (props: EditorEvents['transaction']) => void
68
+ onFocus: (props: EditorEvents['focus']) => void
69
+ onBlur: (props: EditorEvents['blur']) => void
70
+ onDestroy: (props: EditorEvents['destroy']) => void
71
+ }
72
+
73
+ export type HTMLContent = string
74
+
75
+ export type JSONContent = {
76
+ type?: string
77
+ attrs?: Record<string, any>
78
+ content?: JSONContent[]
79
+ marks?: {
80
+ type: string
81
+ attrs?: Record<string, any>
82
+ [key: string]: any
83
+ }[]
84
+ text?: string
85
+ [key: string]: any
86
+ }
87
+
88
+ export type Content = HTMLContent | JSONContent | JSONContent[] | null
43
89
 
44
90
  export type CommandProps = {
45
- editor: Editor,
46
- tr: Transaction,
47
- commands: SingleCommands,
48
- can: () => CanCommands,
49
- chain: () => ChainedCommands,
50
- state: EditorState,
51
- view: EditorView,
52
- dispatch: ((args?: any) => any) | undefined,
91
+ editor: Editor
92
+ tr: Transaction
93
+ commands: SingleCommands
94
+ can: () => CanCommands
95
+ chain: () => ChainedCommands
96
+ state: EditorState
97
+ view: EditorView
98
+ dispatch: ((args?: any) => any) | undefined
53
99
  }
54
100
 
55
101
  export type Command = (props: CommandProps) => boolean
56
102
 
57
103
  export type CommandSpec = (...args: any[]) => Command
58
104
 
105
+ export type KeyboardShortcutCommand = (props: { editor: Editor }) => boolean
106
+
59
107
  export type Attribute = {
60
- default: any,
61
- rendered?: boolean,
62
- renderHTML?: ((attributes: { [key: string]: any }) => { [key: string]: any } | null) | null,
63
- parseHTML?: ((element: HTMLElement) => { [key: string]: any } | null) | null,
64
- keepOnSplit: boolean,
108
+ default: any
109
+ rendered?: boolean
110
+ renderHTML?: ((attributes: Record<string, any>) => Record<string, any> | null) | null
111
+ parseHTML?: ((element: HTMLElement) => any | null) | null
112
+ keepOnSplit: boolean
113
+ isRequired?: boolean
65
114
  }
66
115
 
67
116
  export type Attributes = {
68
- [key: string]: Attribute,
117
+ [key: string]: Attribute
69
118
  }
70
119
 
71
120
  export type ExtensionAttribute = {
72
- type: string,
73
- name: string,
74
- attribute: Required<Attribute>,
121
+ type: string
122
+ name: string
123
+ attribute: Required<Attribute>
75
124
  }
76
125
 
77
126
  export type GlobalAttributes = {
78
- types: string[],
127
+ types: string[]
79
128
  attributes: {
80
129
  [key: string]: Attribute
81
- },
130
+ }
82
131
  }[]
83
132
 
84
133
  export type PickValue<T, K extends keyof T> = T[K]
85
134
 
86
- export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I)=>void)
135
+ export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
136
+ k: infer I,
137
+ ) => void
87
138
  ? I
88
139
  : never
89
140
 
90
- export type Diff<T extends keyof any, U extends keyof any> =
91
- ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T]
92
-
93
- export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U;
141
+ export type Diff<T extends keyof any, U extends keyof any> = ({ [P in T]: P } & {
142
+ [P in U]: never
143
+ } & { [x: string]: never })[T]
94
144
 
95
- export type AnyObject = {
96
- [key: string]: any
97
- }
145
+ export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U
98
146
 
99
- export type ValuesOf<T> = T[keyof T];
147
+ export type ValuesOf<T> = T[keyof T]
100
148
 
101
- export type KeysWithTypeOf<T, Type> = ({[P in keyof T]: T[P] extends Type ? P : never })[keyof T]
149
+ export type KeysWithTypeOf<T, Type> = { [P in keyof T]: T[P] extends Type ? P : never }[keyof T]
102
150
 
103
151
  export type NodeViewProps = {
104
- editor: Editor,
105
- node: ProseMirrorNode,
106
- decorations: Decoration[],
107
- selected: boolean,
108
- extension: Node,
109
- getPos: () => number,
110
- updateAttributes: (attributes: AnyObject) => void,
152
+ editor: Editor
153
+ node: ProseMirrorNode
154
+ decorations: Decoration[]
155
+ selected: boolean
156
+ extension: Node
157
+ getPos: () => number
158
+ updateAttributes: (attributes: Record<string, any>) => void
159
+ deleteNode: () => void
160
+ }
161
+
162
+ export interface NodeViewRendererOptions {
163
+ stopEvent: ((props: { event: Event }) => boolean) | null
164
+ ignoreMutation:
165
+ | ((props: { mutation: MutationRecord | { type: 'selection'; target: Element } }) => boolean)
166
+ | null
111
167
  }
112
168
 
113
169
  export type NodeViewRendererProps = {
114
- editor: Editor,
115
- node: ProseMirrorNode,
116
- getPos: (() => number) | boolean,
117
- HTMLAttributes: { [key: string]: any },
118
- decorations: Decoration[],
119
- extension: Node,
170
+ editor: Editor
171
+ node: ProseMirrorNode
172
+ getPos: (() => number) | boolean
173
+ HTMLAttributes: Record<string, any>
174
+ decorations: Decoration[]
175
+ extension: Node
120
176
  }
121
177
 
122
- export type NodeViewRenderer = (props: NodeViewRendererProps) => (NodeView | {})
178
+ export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView | {}
123
179
 
124
- export type UnionCommands = UnionToIntersection<ValuesOf<Pick<Commands, KeysWithTypeOf<Commands, {}>>>>
180
+ export type AnyCommands = Record<string, (...args: any[]) => Command>
181
+
182
+ export type UnionCommands<T = Command> = UnionToIntersection<
183
+ ValuesOf<Pick<Commands<T>, KeysWithTypeOf<Commands<T>, {}>>>
184
+ >
125
185
 
126
186
  export type RawCommands = {
127
- [Item in keyof UnionCommands]: UnionCommands[Item] extends (...args: any[]) => any
128
- ? (...args: Parameters<UnionCommands[Item]>) => Command
129
- : never
187
+ [Item in keyof UnionCommands]: UnionCommands<Command>[Item]
130
188
  }
131
189
 
132
190
  export type SingleCommands = {
133
- [Item in keyof RawCommands]: RawCommands[Item] extends (...args: any[]) => any
134
- ? (...args: Parameters<RawCommands[Item]>) => boolean
135
- : never
191
+ [Item in keyof UnionCommands]: UnionCommands<boolean>[Item]
136
192
  }
137
193
 
138
194
  export type ChainedCommands = {
139
- [Item in keyof RawCommands]: RawCommands[Item] extends (...args: any[]) => any
140
- ? (...args: Parameters<RawCommands[Item]>) => ChainedCommands
141
- : never
195
+ [Item in keyof UnionCommands]: UnionCommands<ChainedCommands>[Item]
142
196
  } & {
143
197
  run: () => boolean
144
198
  }
145
199
 
146
200
  export type CanCommands = SingleCommands & { chain: () => ChainedCommands }
147
201
 
148
- export type FocusPosition = 'start' | 'end' | number | boolean | null
202
+ export type FocusPosition = 'start' | 'end' | 'all' | number | boolean | null
149
203
 
150
204
  export type Range = {
151
- from: number,
152
- to: number,
205
+ from: number
206
+ to: number
153
207
  }
154
208
 
155
209
  export type NodeRange = {
156
- node: ProseMirrorNode,
157
- from: number,
158
- to: number,
210
+ node: ProseMirrorNode
211
+ from: number
212
+ to: number
159
213
  }
160
214
 
161
215
  export type MarkRange = {
162
- mark: ProseMirrorMark,
163
- from: number,
164
- to: number,
216
+ mark: ProseMirrorMark
217
+ from: number
218
+ to: number
165
219
  }
166
220
 
167
221
  export type Predicate = (node: ProseMirrorNode) => boolean
222
+
223
+ export type NodeWithPos = {
224
+ node: ProseMirrorNode
225
+ pos: number
226
+ }
227
+
228
+ export type TextSerializer = (props: {
229
+ node: ProseMirrorNode
230
+ pos: number
231
+ parent: ProseMirrorNode
232
+ index: number
233
+ range: Range
234
+ }) => string
235
+
236
+ export type ExtendedRegExpMatchArray = RegExpMatchArray & {
237
+ data?: Record<string, any>
238
+ }
239
+
240
+ export type Dispatch = ((args?: any) => any) | undefined
@@ -1,3 +1,6 @@
1
+ import { MaybeReturnType } from '../types'
2
+ import { isFunction } from './isFunction'
3
+
1
4
  /**
2
5
  * Optionally calls `value` as a function.
3
6
  * Otherwise it is returned directly.
@@ -5,8 +8,8 @@
5
8
  * @param context Optional context to bind to function.
6
9
  * @param props Optional props to pass to function.
7
10
  */
8
- export default function callOrReturn(value: any, context: any = undefined, ...props: any[]): any {
9
- if (typeof value === 'function') {
11
+ export function callOrReturn<T>(value: T, context: any = undefined, ...props: any[]): MaybeReturnType<T> {
12
+ if (isFunction(value)) {
10
13
  if (context) {
11
14
  return value.bind(context)(...props)
12
15
  }
@@ -14,5 +17,5 @@ export default function callOrReturn(value: any, context: any = undefined, ...pr
14
17
  return value(...props)
15
18
  }
16
19
 
17
- return value
20
+ return value as MaybeReturnType<T>
18
21
  }
@@ -1,6 +1,17 @@
1
- export default function createStyleTag(style: string): HTMLStyleElement {
1
+ export function createStyleTag(style: string, nonce?: string): HTMLStyleElement {
2
+ const tipTapStyleTag = (<HTMLStyleElement>document.querySelector('style[data-tiptap-style]'))
3
+
4
+ if (tipTapStyleTag !== null) {
5
+ return tipTapStyleTag
6
+ }
7
+
2
8
  const styleNode = document.createElement('style')
3
9
 
10
+ if (nonce) {
11
+ styleNode.setAttribute('nonce', nonce)
12
+ }
13
+
14
+ styleNode.setAttribute('data-tiptap-style', '')
4
15
  styleNode.innerHTML = style
5
16
  document.getElementsByTagName('head')[0].appendChild(styleNode)
6
17
 
@@ -1,18 +1,16 @@
1
- import { AnyObject } from '../types'
2
-
3
1
  /**
4
2
  * Remove a property or an array of properties from an object
5
3
  * @param obj Object
6
4
  * @param key Key to remove
7
5
  */
8
- export default function deleteProps(obj: AnyObject, propOrProps: string | string[]): AnyObject {
6
+ export function deleteProps(obj: Record<string, any>, propOrProps: string | string[]): Record<string, any> {
9
7
  const props = typeof propOrProps === 'string'
10
8
  ? [propOrProps]
11
9
  : propOrProps
12
10
 
13
11
  return Object
14
12
  .keys(obj)
15
- .reduce((newObj: AnyObject, prop) => {
13
+ .reduce((newObj: Record<string, any>, prop) => {
16
14
  if (!props.includes(prop)) {
17
15
  newObj[prop] = obj[prop]
18
16
  }
@@ -1,7 +1,6 @@
1
- export default function elementFromString(value: string): HTMLElement {
2
- const htmlString = `<div>${value}</div>`
3
- const parser = new window.DOMParser()
4
- const element = parser.parseFromString(htmlString, 'text/html').body
1
+ export function elementFromString(value: string): HTMLElement {
2
+ // add a wrapper to preserve leading and trailing whitespace
3
+ const wrappedValue = `<body>${value}</body>`
5
4
 
6
- return element
5
+ return new window.DOMParser().parseFromString(wrappedValue, 'text/html').body
7
6
  }
@@ -0,0 +1,4 @@
1
+ // source: https://stackoverflow.com/a/6969486
2
+ export function escapeForRegEx(string: string): string {
3
+ return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')
4
+ }
@@ -0,0 +1,5 @@
1
+ export function findDuplicates(items: any[]): any[] {
2
+ const filtered = items.filter((el, index) => items.indexOf(el) !== index)
3
+
4
+ return [...new Set(filtered)]
5
+ }
@@ -1,9 +1,9 @@
1
- export default function fromString(value: any): any {
1
+ export function fromString(value: any): any {
2
2
  if (typeof value !== 'string') {
3
3
  return value
4
4
  }
5
5
 
6
- if (value.match(/^\d*(\.\d+)?$/)) {
6
+ if (value.match(/^[+-]?(?:\d*\.)?\d+$/)) {
7
7
  return Number(value)
8
8
  }
9
9
 
@@ -0,0 +1,20 @@
1
+ export * from './callOrReturn'
2
+ export * from './createStyleTag'
3
+ export * from './deleteProps'
4
+ export * from './elementFromString'
5
+ export * from './escapeForRegEx'
6
+ export * from './findDuplicates'
7
+ export * from './fromString'
8
+ export * from './isEmptyObject'
9
+ export * from './isFunction'
10
+ export * from './isiOS'
11
+ export * from './isMacOS'
12
+ export * from './isNumber'
13
+ export * from './isPlainObject'
14
+ export * from './isRegExp'
15
+ export * from './isString'
16
+ export * from './mergeAttributes'
17
+ export * from './mergeDeep'
18
+ export * from './minMax'
19
+ export * from './objectIncludes'
20
+ export * from './removeDuplicates'
@@ -1,3 +1,3 @@
1
- export default function isEmptyObject(object = {}): boolean {
2
- return Object.keys(object).length === 0 && object.constructor === Object
1
+ export function isEmptyObject(value = {}): boolean {
2
+ return Object.keys(value).length === 0 && value.constructor === Object
3
3
  }
@@ -0,0 +1,3 @@
1
+ export function isFunction(value: any): value is Function {
2
+ return typeof value === 'function'
3
+ }
@@ -0,0 +1,5 @@
1
+ export function isMacOS(): boolean {
2
+ return typeof navigator !== 'undefined'
3
+ ? /Mac/.test(navigator.platform)
4
+ : false
5
+ }
@@ -0,0 +1,3 @@
1
+ export function isNumber(value: any): value is number {
2
+ return typeof value === 'number'
3
+ }
@@ -1,10 +1,13 @@
1
1
  // see: https://github.com/mesqueeb/is-what/blob/88d6e4ca92fb2baab6003c54e02eedf4e729e5ab/src/index.ts
2
2
 
3
- function getType(payload: any): string {
4
- return Object.prototype.toString.call(payload).slice(8, -1)
3
+ function getType(value: any): string {
4
+ return Object.prototype.toString.call(value).slice(8, -1)
5
5
  }
6
6
 
7
- export default function isPlainObject(payload: any): payload is Record<string, any> {
8
- if (getType(payload) !== 'Object') return false
9
- return payload.constructor === Object && Object.getPrototypeOf(payload) === Object.prototype
7
+ export function isPlainObject(value: any): value is Record<string, any> {
8
+ if (getType(value) !== 'Object') {
9
+ return false
10
+ }
11
+
12
+ return value.constructor === Object && Object.getPrototypeOf(value) === Object.prototype
10
13
  }
@@ -0,0 +1,3 @@
1
+ export function isRegExp(value: any): value is RegExp {
2
+ return Object.prototype.toString.call(value) === '[object RegExp]'
3
+ }
@@ -0,0 +1,3 @@
1
+ export function isString(value: any): value is string {
2
+ return typeof value === 'string'
3
+ }
@@ -0,0 +1,12 @@
1
+ export function isiOS(): boolean {
2
+ return [
3
+ 'iPad Simulator',
4
+ 'iPhone Simulator',
5
+ 'iPod Simulator',
6
+ 'iPad',
7
+ 'iPhone',
8
+ 'iPod',
9
+ ].includes(navigator.platform)
10
+ // iPad on iOS 13 detection
11
+ || (navigator.userAgent.includes('Mac') && 'ontouchend' in document)
12
+ }
@@ -1,6 +1,4 @@
1
- import { AnyObject } from '../types'
2
-
3
- export default function mergeAttributes(...objects: AnyObject[]): AnyObject {
1
+ export function mergeAttributes(...objects: Record<string, any>[]): Record<string, any> {
4
2
  return objects
5
3
  .filter(item => !!item)
6
4
  .reduce((items, item) => {
@@ -11,6 +9,7 @@ export default function mergeAttributes(...objects: AnyObject[]): AnyObject {
11
9
 
12
10
  if (!exists) {
13
11
  mergedAttributes[key] = value
12
+
14
13
  return
15
14
  }
16
15
 
@@ -1,7 +1,6 @@
1
- import { AnyObject } from '../types'
2
- import isPlainObject from './isPlainObject'
1
+ import { isPlainObject } from './isPlainObject'
3
2
 
4
- export default function mergeDeep(target: AnyObject, source: AnyObject): AnyObject {
3
+ export function mergeDeep(target: Record<string, any>, source: Record<string, any>): Record<string, any> {
5
4
  const output = { ...target }
6
5
 
7
6
  if (isPlainObject(target) && isPlainObject(source)) {
@@ -1,3 +1,3 @@
1
- export default function minMax(value = 0, min = 0, max = 0): number {
1
+ export function minMax(value = 0, min = 0, max = 0): number {
2
2
  return Math.min(Math.max(value, min), max)
3
3
  }
@@ -1,18 +1,30 @@
1
- import { AnyObject } from '../types'
1
+ import { isRegExp } from './isRegExp'
2
2
 
3
3
  /**
4
4
  * Check if object1 includes object2
5
5
  * @param object1 Object
6
6
  * @param object2 Object
7
7
  */
8
- export default function objectIncludes(object1: AnyObject, object2: AnyObject): boolean {
8
+ export function objectIncludes(
9
+ object1: Record<string, any>,
10
+ object2: Record<string, any>,
11
+ options: { strict: boolean } = { strict: true },
12
+ ): boolean {
9
13
  const keys = Object.keys(object2)
10
14
 
11
15
  if (!keys.length) {
12
16
  return true
13
17
  }
14
18
 
15
- return !!keys
16
- .filter(key => object2[key] === object1[key])
17
- .length
19
+ return keys.every(key => {
20
+ if (options.strict) {
21
+ return object2[key] === object1[key]
22
+ }
23
+
24
+ if (isRegExp(object2[key])) {
25
+ return object2[key].test(object1[key])
26
+ }
27
+
28
+ return object2[key] === object1[key]
29
+ })
18
30
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Removes duplicated values within an array.
3
+ * Supports numbers, strings and objects.
4
+ */
5
+ export function removeDuplicates<T>(array: T[], by = JSON.stringify): T[] {
6
+ const seen: Record<any, any> = {}
7
+
8
+ return array.filter(item => {
9
+ const key = by(item)
10
+
11
+ return Object.prototype.hasOwnProperty.call(seen, key)
12
+ ? false
13
+ : (seen[key] = true)
14
+ })
15
+ }