@tiptap/core 2.0.0-beta.209 → 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 (259) hide show
  1. package/dist/index.cjs +4311 -0
  2. package/dist/index.d.ts +2330 -0
  3. package/dist/index.js +4311 -0
  4. package/package.json +24 -23
  5. package/src/CommandManager.ts +27 -36
  6. package/src/Editor.ts +27 -37
  7. package/src/Extension.ts +193 -179
  8. package/src/ExtensionManager.ts +82 -98
  9. package/src/InputRule.ts +38 -43
  10. package/src/Mark.ts +277 -264
  11. package/src/Node.ts +349 -314
  12. package/src/NodeView.ts +24 -23
  13. package/src/PasteRule.ts +37 -44
  14. package/src/Tracker.ts +4 -8
  15. package/src/commands/clearNodes.ts +1 -1
  16. package/src/commands/createParagraphNear.ts +2 -2
  17. package/src/commands/deleteNode.ts +1 -1
  18. package/src/commands/deleteSelection.ts +2 -2
  19. package/src/commands/exitCode.ts +2 -2
  20. package/src/commands/extendMarkRange.ts +6 -3
  21. package/src/commands/insertContent.ts +9 -5
  22. package/src/commands/insertContentAt.ts +10 -24
  23. package/src/commands/join.ts +9 -6
  24. package/src/commands/lift.ts +3 -3
  25. package/src/commands/liftEmptyBlock.ts +1 -1
  26. package/src/commands/liftListItem.ts +3 -3
  27. package/src/commands/newlineInCode.ts +2 -2
  28. package/src/commands/resetAttributes.ts +11 -6
  29. package/src/commands/selectNodeBackward.ts +2 -2
  30. package/src/commands/selectNodeForward.ts +2 -2
  31. package/src/commands/selectParentNode.ts +2 -2
  32. package/src/commands/selectTextblockEnd.ts +2 -2
  33. package/src/commands/selectTextblockStart.ts +2 -2
  34. package/src/commands/setContent.ts +3 -4
  35. package/src/commands/setMark.ts +26 -16
  36. package/src/commands/setNode.ts +19 -17
  37. package/src/commands/setNodeSelection.ts +2 -2
  38. package/src/commands/setTextSelection.ts +3 -5
  39. package/src/commands/sinkListItem.ts +3 -3
  40. package/src/commands/splitBlock.ts +20 -25
  41. package/src/commands/splitListItem.ts +15 -25
  42. package/src/commands/toggleList.ts +27 -24
  43. package/src/commands/toggleMark.ts +3 -3
  44. package/src/commands/toggleNode.ts +6 -2
  45. package/src/commands/toggleWrap.ts +2 -2
  46. package/src/commands/unsetMark.ts +3 -3
  47. package/src/commands/updateAttributes.ts +14 -9
  48. package/src/commands/wrapIn.ts +3 -3
  49. package/src/commands/wrapInList.ts +3 -3
  50. package/src/extensions/clipboardTextSerializer.ts +1 -1
  51. package/src/extensions/editable.ts +1 -1
  52. package/src/extensions/focusEvents.ts +1 -1
  53. package/src/extensions/keymap.ts +2 -7
  54. package/src/extensions/tabindex.ts +1 -1
  55. package/src/helpers/combineTransactionSteps.ts +7 -4
  56. package/src/helpers/createChainableState.ts +3 -3
  57. package/src/helpers/createDocument.ts +1 -1
  58. package/src/helpers/createNodeFromContent.ts +4 -10
  59. package/src/helpers/defaultBlockAt.ts +1 -1
  60. package/src/helpers/findChildren.ts +1 -1
  61. package/src/helpers/findChildrenInRange.ts +6 -2
  62. package/src/helpers/findParentNode.ts +1 -1
  63. package/src/helpers/findParentNodeClosestToPos.ts +12 -7
  64. package/src/helpers/generateHTML.ts +1 -1
  65. package/src/helpers/generateJSON.ts +2 -4
  66. package/src/helpers/generateText.ts +4 -7
  67. package/src/helpers/getAttributes.ts +3 -5
  68. package/src/helpers/getChangedRanges.ts +1 -1
  69. package/src/helpers/getDebugJSON.ts +4 -4
  70. package/src/helpers/getHTMLFromFragment.ts +2 -4
  71. package/src/helpers/getMarkAttributes.ts +6 -3
  72. package/src/helpers/getMarkRange.ts +1 -1
  73. package/src/helpers/getMarkType.ts +4 -2
  74. package/src/helpers/getMarksBetween.ts +8 -6
  75. package/src/helpers/getNodeAttributes.ts +7 -6
  76. package/src/helpers/getNodeType.ts +4 -2
  77. package/src/helpers/getRenderedAttributes.ts +5 -2
  78. package/src/helpers/getSchema.ts +1 -1
  79. package/src/helpers/getSchemaByResolvedExtensions.ts +151 -107
  80. package/src/helpers/getSchemaTypeByName.ts +1 -1
  81. package/src/helpers/getSchemaTypeNameByName.ts +1 -1
  82. package/src/helpers/getText.ts +3 -3
  83. package/src/helpers/getTextBetween.ts +4 -7
  84. package/src/helpers/getTextContentFromNodes.ts +8 -3
  85. package/src/helpers/getTextSerializersFromSchema.ts +6 -5
  86. package/src/helpers/injectExtensionAttributesToParseRule.ts +6 -5
  87. package/src/helpers/isActive.ts +6 -2
  88. package/src/helpers/isMarkActive.ts +12 -15
  89. package/src/helpers/isNodeActive.ts +4 -7
  90. package/src/helpers/isNodeEmpty.ts +1 -1
  91. package/src/helpers/isNodeSelection.ts +1 -1
  92. package/src/helpers/isTextSelection.ts +1 -1
  93. package/src/helpers/posToDOMRect.ts +1 -1
  94. package/src/helpers/resolveFocusPosition.ts +2 -3
  95. package/src/helpers/selectionToInsertionEnd.ts +2 -2
  96. package/src/inputRules/markInputRule.ts +3 -4
  97. package/src/inputRules/nodeInputRule.ts +3 -4
  98. package/src/inputRules/textblockTypeInputRule.ts +3 -4
  99. package/src/inputRules/wrappingInputRule.ts +5 -6
  100. package/src/pasteRules/markPasteRule.ts +3 -4
  101. package/src/pasteRules/nodePasteRule.ts +8 -10
  102. package/src/types.ts +109 -125
  103. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  104. package/dist/packages/core/src/Editor.d.ts +0 -147
  105. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  106. package/dist/packages/core/src/Extension.d.ts +0 -227
  107. package/dist/packages/core/src/ExtensionManager.d.ts +0 -18
  108. package/dist/packages/core/src/InputRule.d.ts +0 -42
  109. package/dist/packages/core/src/Mark.d.ts +0 -327
  110. package/dist/packages/core/src/Node.d.ts +0 -397
  111. package/dist/packages/core/src/NodeView.d.ts +0 -27
  112. package/dist/packages/core/src/PasteRule.d.ts +0 -42
  113. package/dist/packages/core/src/Tracker.d.ts +0 -11
  114. package/dist/packages/core/src/commands/blur.d.ts +0 -12
  115. package/dist/packages/core/src/commands/clearContent.d.ts +0 -12
  116. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -12
  117. package/dist/packages/core/src/commands/command.d.ts +0 -12
  118. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -12
  119. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -12
  120. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -13
  121. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -12
  122. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -12
  123. package/dist/packages/core/src/commands/enter.d.ts +0 -12
  124. package/dist/packages/core/src/commands/exitCode.d.ts +0 -12
  125. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -13
  126. package/dist/packages/core/src/commands/first.d.ts +0 -12
  127. package/dist/packages/core/src/commands/focus.d.ts +0 -14
  128. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  129. package/dist/packages/core/src/commands/index.d.ts +0 -50
  130. package/dist/packages/core/src/commands/insertContent.d.ts +0 -16
  131. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -16
  132. package/dist/packages/core/src/commands/join.d.ts +0 -33
  133. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -12
  134. package/dist/packages/core/src/commands/lift.d.ts +0 -13
  135. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -12
  136. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -13
  137. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -12
  138. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -13
  139. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -12
  140. package/dist/packages/core/src/commands/selectAll.d.ts +0 -12
  141. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -12
  142. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -12
  143. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -12
  144. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -12
  145. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -12
  146. package/dist/packages/core/src/commands/setContent.d.ts +0 -13
  147. package/dist/packages/core/src/commands/setMark.d.ts +0 -13
  148. package/dist/packages/core/src/commands/setMeta.d.ts +0 -12
  149. package/dist/packages/core/src/commands/setNode.d.ts +0 -13
  150. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -12
  151. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -12
  152. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -13
  153. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -14
  154. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -13
  155. package/dist/packages/core/src/commands/toggleList.d.ts +0 -13
  156. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -18
  157. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -13
  158. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -13
  159. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -12
  160. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -12
  161. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -18
  162. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -13
  163. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -13
  164. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -13
  165. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -2
  166. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  167. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  168. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  169. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  170. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  171. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  172. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -7
  173. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -5
  174. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -3
  175. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -7
  176. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -2
  177. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -3
  178. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -6
  179. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -8
  180. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -8
  181. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -2
  182. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -2
  183. package/dist/packages/core/src/helpers/generateText.d.ts +0 -5
  184. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -3
  185. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  186. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  187. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  188. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -2
  189. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  190. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  191. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  192. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  193. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  194. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  195. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  196. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  197. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -3
  198. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -3
  199. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -2
  200. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -2
  201. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -2
  202. package/dist/packages/core/src/helpers/getText.d.ts +0 -6
  203. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -6
  204. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -2
  205. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -3
  206. package/dist/packages/core/src/helpers/index.d.ts +0 -33
  207. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  208. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  209. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  210. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  211. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  212. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  213. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
  214. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  215. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  216. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  217. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  218. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  219. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  220. package/dist/packages/core/src/index.d.ts +0 -23
  221. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  222. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -12
  223. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -12
  224. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -9
  225. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -14
  226. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -23
  227. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  228. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -12
  229. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -12
  230. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -9
  231. package/dist/packages/core/src/style.d.ts +0 -1
  232. package/dist/packages/core/src/types.d.ts +0 -214
  233. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  234. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  235. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  236. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  237. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  238. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  239. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  240. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  241. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  242. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  243. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  244. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  245. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  246. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  247. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  248. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  249. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  250. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  251. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  252. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  253. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
  254. package/dist/tiptap-core.cjs +0 -4360
  255. package/dist/tiptap-core.cjs.map +0 -1
  256. package/dist/tiptap-core.esm.js +0 -4284
  257. package/dist/tiptap-core.esm.js.map +0 -1
  258. package/dist/tiptap-core.umd.js +0 -4358
  259. package/dist/tiptap-core.umd.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { Node as ProseMirrorNode, NodeType } from 'prosemirror-model'
2
- import { canJoin, findWrapping } from 'prosemirror-transform'
1
+ import { Node as ProseMirrorNode, NodeType } from '@tiptap/pm/model'
2
+ import { canJoin, findWrapping } from '@tiptap/pm/transform'
3
3
 
4
4
  import { InputRule, InputRuleFinder } from '../InputRule'
5
5
  import { ExtendedRegExpMatchArray } from '../types'
@@ -20,15 +20,14 @@ import { callOrReturn } from '../utilities/callOrReturn'
20
20
  * return a boolean to indicate whether a join should happen.
21
21
  */
22
22
  export function wrappingInputRule(config: {
23
- find: InputRuleFinder,
24
- type: NodeType,
23
+ find: InputRuleFinder
24
+ type: NodeType
25
25
  getAttributes?:
26
26
  | Record<string, any>
27
27
  | ((match: ExtendedRegExpMatchArray) => Record<string, any>)
28
28
  | false
29
29
  | null
30
- ,
31
- joinPredicate?: (match: ExtendedRegExpMatchArray, node: ProseMirrorNode) => boolean,
30
+ joinPredicate?: (match: ExtendedRegExpMatchArray, node: ProseMirrorNode) => boolean
32
31
  }) {
33
32
  return new InputRule({
34
33
  find: config.find,
@@ -1,4 +1,4 @@
1
- import { MarkType } from 'prosemirror-model'
1
+ import { MarkType } from '@tiptap/pm/model'
2
2
 
3
3
  import { getMarksBetween } from '../helpers/getMarksBetween'
4
4
  import { PasteRule, PasteRuleFinder } from '../PasteRule'
@@ -10,14 +10,13 @@ import { callOrReturn } from '../utilities/callOrReturn'
10
10
  * matched text is pasted into it.
11
11
  */
12
12
  export function markPasteRule(config: {
13
- find: PasteRuleFinder,
14
- type: MarkType,
13
+ find: PasteRuleFinder
14
+ type: MarkType
15
15
  getAttributes?:
16
16
  | Record<string, any>
17
17
  | ((match: ExtendedRegExpMatchArray) => Record<string, any>)
18
18
  | false
19
19
  | null
20
- ,
21
20
  }) {
22
21
  return new PasteRule({
23
22
  find: config.find,
@@ -1,4 +1,4 @@
1
- import { NodeType } from 'prosemirror-model'
1
+ import { NodeType } from '@tiptap/pm/model'
2
2
 
3
3
  import { PasteRule } from '../PasteRule'
4
4
  import { ExtendedRegExpMatchArray } from '../types'
@@ -9,13 +9,13 @@ import { callOrReturn } from '../utilities'
9
9
  * matched text is pasted into it.
10
10
  */
11
11
  export function nodePasteRule(config: {
12
- find: RegExp,
13
- type: NodeType,
12
+ find: RegExp
13
+ type: NodeType
14
14
  getAttributes?:
15
15
  | Record<string, any>
16
16
  | ((match: ExtendedRegExpMatchArray) => Record<string, any>)
17
17
  | false
18
- | null,
18
+ | null
19
19
  }) {
20
20
  return new PasteRule({
21
21
  find: config.find,
@@ -27,12 +27,10 @@ export function nodePasteRule(config: {
27
27
  }
28
28
 
29
29
  if (match.input) {
30
- chain()
31
- .deleteRange(range)
32
- .insertContentAt(range.from, {
33
- type: config.type.name,
34
- attrs: attributes,
35
- })
30
+ chain().deleteRange(range).insertContentAt(range.from, {
31
+ type: config.type.name,
32
+ attrs: attributes,
33
+ })
36
34
  }
37
35
  },
38
36
  })
package/src/types.ts CHANGED
@@ -1,21 +1,11 @@
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
- Mark as ProseMirrorMark,
3
- Node as ProseMirrorNode,
4
- ParseOptions,
5
- } from 'prosemirror-model'
6
- import { EditorState, Transaction } from 'prosemirror-state'
7
- import {
8
- Decoration,
9
- EditorProps,
10
- EditorView,
11
- NodeView,
12
- } from 'prosemirror-view'
4
+ Decoration, EditorProps, EditorView, NodeView,
5
+ } from '@tiptap/pm/view'
13
6
 
14
7
  import {
15
- Commands,
16
- ExtensionConfig,
17
- MarkConfig,
18
- NodeConfig,
8
+ Commands, ExtensionConfig, MarkConfig, NodeConfig,
19
9
  } from '.'
20
10
  import { Editor } from './Editor'
21
11
  import { Extension } from './Extension'
@@ -32,89 +22,80 @@ export type ParentConfig<T> = Partial<{
32
22
  : T[P]
33
23
  }>
34
24
 
35
- export type Primitive =
36
- | null
37
- | undefined
38
- | string
39
- | number
40
- | boolean
41
- | symbol
42
- | bigint
25
+ export type Primitive = null | undefined | string | number | boolean | symbol | bigint
43
26
 
44
27
  export type RemoveThis<T> = T extends (...args: any) => any
45
28
  ? (...args: Parameters<T>) => ReturnType<T>
46
29
  : T
47
30
 
48
- export type MaybeReturnType<T> = T extends (...args: any) => any
49
- ? ReturnType<T>
50
- : T
31
+ export type MaybeReturnType<T> = T extends (...args: any) => any ? ReturnType<T> : T
51
32
 
52
33
  export type MaybeThisParameterType<T> = Exclude<T, Primitive> extends (...args: any) => any
53
34
  ? ThisParameterType<Exclude<T, Primitive>>
54
35
  : any
55
36
 
56
37
  export interface EditorEvents {
57
- beforeCreate: { editor: Editor },
58
- create: { editor: Editor },
59
- update: { editor: Editor, transaction: Transaction },
60
- selectionUpdate: { editor: Editor, transaction: Transaction },
61
- transaction: { editor: Editor, transaction: Transaction },
62
- focus: { editor: Editor, event: FocusEvent, transaction: Transaction },
63
- blur: { editor: Editor, event: FocusEvent, transaction: Transaction },
64
- destroy: void,
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
65
46
  }
66
47
 
67
48
  export type EnableRules = (AnyExtension | string)[] | boolean
68
49
 
69
50
  export interface EditorOptions {
70
- element: Element,
71
- content: Content,
72
- extensions: Extensions,
73
- injectCSS: boolean,
74
- injectNonce: string | undefined,
75
- autofocus: FocusPosition,
76
- editable: boolean,
77
- editorProps: EditorProps,
78
- parseOptions: ParseOptions,
79
- enableInputRules: EnableRules,
80
- enablePasteRules: EnableRules,
81
- enableCoreExtensions: boolean,
82
- onBeforeCreate: (props: EditorEvents['beforeCreate']) => void,
83
- onCreate: (props: EditorEvents['create']) => void,
84
- onUpdate: (props: EditorEvents['update']) => void,
85
- onSelectionUpdate: (props: EditorEvents['selectionUpdate']) => void,
86
- onTransaction: (props: EditorEvents['transaction']) => void,
87
- onFocus: (props: EditorEvents['focus']) => void,
88
- onBlur: (props: EditorEvents['blur']) => void,
89
- onDestroy: (props: EditorEvents['destroy']) => void,
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
90
71
  }
91
72
 
92
73
  export type HTMLContent = string
93
74
 
94
75
  export type JSONContent = {
95
- type?: string,
96
- attrs?: Record<string, any>,
97
- content?: JSONContent[],
76
+ type?: string
77
+ attrs?: Record<string, any>
78
+ content?: JSONContent[]
98
79
  marks?: {
99
- type: string,
100
- attrs?: Record<string, any>,
101
- [key: string]: any,
102
- }[],
103
- text?: string,
104
- [key: string]: any,
80
+ type: string
81
+ attrs?: Record<string, any>
82
+ [key: string]: any
83
+ }[]
84
+ text?: string
85
+ [key: string]: any
105
86
  }
106
87
 
107
88
  export type Content = HTMLContent | JSONContent | JSONContent[] | null
108
89
 
109
90
  export type CommandProps = {
110
- editor: Editor,
111
- tr: Transaction,
112
- commands: SingleCommands,
113
- can: () => CanCommands,
114
- chain: () => ChainedCommands,
115
- state: EditorState,
116
- view: EditorView,
117
- 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
118
99
  }
119
100
 
120
101
  export type Command = (props: CommandProps) => boolean
@@ -124,80 +105,83 @@ export type CommandSpec = (...args: any[]) => Command
124
105
  export type KeyboardShortcutCommand = (props: { editor: Editor }) => boolean
125
106
 
126
107
  export type Attribute = {
127
- default: any,
128
- rendered?: boolean,
129
- renderHTML?: ((attributes: Record<string, any>) => Record<string, any> | null) | null,
130
- parseHTML?: ((element: HTMLElement) => any | null) | null,
131
- keepOnSplit: boolean,
132
- isRequired?: 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
133
114
  }
134
115
 
135
116
  export type Attributes = {
136
- [key: string]: Attribute,
117
+ [key: string]: Attribute
137
118
  }
138
119
 
139
120
  export type ExtensionAttribute = {
140
- type: string,
141
- name: string,
142
- attribute: Required<Attribute>,
121
+ type: string
122
+ name: string
123
+ attribute: Required<Attribute>
143
124
  }
144
125
 
145
126
  export type GlobalAttributes = {
146
- types: string[],
127
+ types: string[]
147
128
  attributes: {
148
129
  [key: string]: Attribute
149
- },
130
+ }
150
131
  }[]
151
132
 
152
133
  export type PickValue<T, K extends keyof T> = T[K]
153
134
 
154
- 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
155
138
  ? I
156
139
  : never
157
140
 
158
- export type Diff<T extends keyof any, U extends keyof any> =
159
- ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T]
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]
160
144
 
161
145
  export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U
162
146
 
163
147
  export type ValuesOf<T> = T[keyof T]
164
148
 
165
- 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]
166
150
 
167
151
  export type NodeViewProps = {
168
- editor: Editor,
169
- node: ProseMirrorNode,
170
- decorations: Decoration[],
171
- selected: boolean,
172
- extension: Node,
173
- getPos: () => number,
174
- updateAttributes: (attributes: Record<string, any>) => void,
175
- deleteNode: () => 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
176
160
  }
177
161
 
178
162
  export interface NodeViewRendererOptions {
179
- stopEvent: ((props: {
180
- event: Event
181
- }) => boolean) | null,
182
- ignoreMutation: ((props: {
183
- mutation: MutationRecord | { type: 'selection', target: Element }
184
- }) => boolean) | null,
163
+ stopEvent: ((props: { event: Event }) => boolean) | null
164
+ ignoreMutation:
165
+ | ((props: { mutation: MutationRecord | { type: 'selection'; target: Element } }) => boolean)
166
+ | null
185
167
  }
186
168
 
187
169
  export type NodeViewRendererProps = {
188
- editor: Editor,
189
- node: ProseMirrorNode,
190
- getPos: (() => number) | boolean,
191
- HTMLAttributes: Record<string, any>,
192
- decorations: Decoration[],
193
- extension: Node,
170
+ editor: Editor
171
+ node: ProseMirrorNode
172
+ getPos: (() => number) | boolean
173
+ HTMLAttributes: Record<string, any>
174
+ decorations: Decoration[]
175
+ extension: Node
194
176
  }
195
177
 
196
- export type NodeViewRenderer = (props: NodeViewRendererProps) => (NodeView | {})
178
+ export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView | {}
197
179
 
198
180
  export type AnyCommands = Record<string, (...args: any[]) => Command>
199
181
 
200
- export type UnionCommands<T = Command> = UnionToIntersection<ValuesOf<Pick<Commands<T>, KeysWithTypeOf<Commands<T>, {}>>>>
182
+ export type UnionCommands<T = Command> = UnionToIntersection<
183
+ ValuesOf<Pick<Commands<T>, KeysWithTypeOf<Commands<T>, {}>>>
184
+ >
201
185
 
202
186
  export type RawCommands = {
203
187
  [Item in keyof UnionCommands]: UnionCommands<Command>[Item]
@@ -218,39 +202,39 @@ export type CanCommands = SingleCommands & { chain: () => ChainedCommands }
218
202
  export type FocusPosition = 'start' | 'end' | 'all' | number | boolean | null
219
203
 
220
204
  export type Range = {
221
- from: number,
222
- to: number,
205
+ from: number
206
+ to: number
223
207
  }
224
208
 
225
209
  export type NodeRange = {
226
- node: ProseMirrorNode,
227
- from: number,
228
- to: number,
210
+ node: ProseMirrorNode
211
+ from: number
212
+ to: number
229
213
  }
230
214
 
231
215
  export type MarkRange = {
232
- mark: ProseMirrorMark,
233
- from: number,
234
- to: number,
216
+ mark: ProseMirrorMark
217
+ from: number
218
+ to: number
235
219
  }
236
220
 
237
221
  export type Predicate = (node: ProseMirrorNode) => boolean
238
222
 
239
223
  export type NodeWithPos = {
240
- node: ProseMirrorNode,
241
- pos: number,
224
+ node: ProseMirrorNode
225
+ pos: number
242
226
  }
243
227
 
244
228
  export type TextSerializer = (props: {
245
- node: ProseMirrorNode,
246
- pos: number,
247
- parent: ProseMirrorNode,
248
- index: number,
249
- range: Range,
229
+ node: ProseMirrorNode
230
+ pos: number
231
+ parent: ProseMirrorNode
232
+ index: number
233
+ range: Range
250
234
  }) => string
251
235
 
252
236
  export type ExtendedRegExpMatchArray = RegExpMatchArray & {
253
- data?: Record<string, any>,
237
+ data?: Record<string, any>
254
238
  }
255
239
 
256
240
  export type Dispatch = ((args?: any) => any) | undefined
@@ -1,20 +0,0 @@
1
- import { EditorState, Transaction } from 'prosemirror-state';
2
- import { Editor } from './Editor';
3
- import { AnyCommands, CanCommands, ChainedCommands, CommandProps, SingleCommands } from './types';
4
- export declare class CommandManager {
5
- editor: Editor;
6
- rawCommands: AnyCommands;
7
- customState?: EditorState;
8
- constructor(props: {
9
- editor: Editor;
10
- state?: EditorState;
11
- });
12
- get hasCustomState(): boolean;
13
- get state(): EditorState;
14
- get commands(): SingleCommands;
15
- get chain(): () => ChainedCommands;
16
- get can(): () => CanCommands;
17
- createChain(startTr?: Transaction, shouldDispatch?: boolean): ChainedCommands;
18
- createCan(startTr?: Transaction): CanCommands;
19
- buildProps(tr: Transaction, shouldDispatch?: boolean): CommandProps;
20
- }
@@ -1,147 +0,0 @@
1
- import { MarkType, NodeType, Schema } from 'prosemirror-model';
2
- import { EditorState, Plugin, PluginKey, Transaction } from 'prosemirror-state';
3
- import { EditorView } from 'prosemirror-view';
4
- import { EventEmitter } from './EventEmitter';
5
- import { ExtensionManager } from './ExtensionManager';
6
- import * as extensions from './extensions';
7
- import { CanCommands, ChainedCommands, EditorEvents, EditorOptions, JSONContent, SingleCommands, TextSerializer } from './types';
8
- export { extensions };
9
- export interface HTMLElement {
10
- editor?: Editor;
11
- }
12
- export declare class Editor extends EventEmitter<EditorEvents> {
13
- private commandManager;
14
- extensionManager: ExtensionManager;
15
- private css;
16
- schema: Schema;
17
- view: EditorView;
18
- isFocused: boolean;
19
- extensionStorage: Record<string, any>;
20
- options: EditorOptions;
21
- constructor(options?: Partial<EditorOptions>);
22
- /**
23
- * Returns the editor storage.
24
- */
25
- get storage(): Record<string, any>;
26
- /**
27
- * An object of all registered commands.
28
- */
29
- get commands(): SingleCommands;
30
- /**
31
- * Create a command chain to call multiple commands at once.
32
- */
33
- chain(): ChainedCommands;
34
- /**
35
- * Check if a command or a command chain can be executed. Without executing it.
36
- */
37
- can(): CanCommands;
38
- /**
39
- * Inject CSS styles.
40
- */
41
- private injectCSS;
42
- /**
43
- * Update editor options.
44
- *
45
- * @param options A list of options
46
- */
47
- setOptions(options?: Partial<EditorOptions>): void;
48
- /**
49
- * Update editable state of the editor.
50
- */
51
- setEditable(editable: boolean): void;
52
- /**
53
- * Returns whether the editor is editable.
54
- */
55
- get isEditable(): boolean;
56
- /**
57
- * Returns the editor state.
58
- */
59
- get state(): EditorState;
60
- /**
61
- * Register a ProseMirror plugin.
62
- *
63
- * @param plugin A ProseMirror plugin
64
- * @param handlePlugins Control how to merge the plugin into the existing plugins.
65
- */
66
- registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]): void;
67
- /**
68
- * Unregister a ProseMirror plugin.
69
- *
70
- * @param nameOrPluginKey The plugins name
71
- */
72
- unregisterPlugin(nameOrPluginKey: string | PluginKey): void;
73
- /**
74
- * Creates an extension manager.
75
- */
76
- private createExtensionManager;
77
- /**
78
- * Creates an command manager.
79
- */
80
- private createCommandManager;
81
- /**
82
- * Creates a ProseMirror schema.
83
- */
84
- private createSchema;
85
- /**
86
- * Creates a ProseMirror view.
87
- */
88
- private createView;
89
- /**
90
- * Creates all node views.
91
- */
92
- createNodeViews(): void;
93
- isCapturingTransaction: boolean;
94
- private capturedTransaction;
95
- captureTransaction(fn: Function): Transaction | null;
96
- /**
97
- * The callback over which to send transactions (state updates) produced by the view.
98
- *
99
- * @param transaction An editor state transaction
100
- */
101
- private dispatchTransaction;
102
- /**
103
- * Get attributes of the currently selected node or mark.
104
- */
105
- getAttributes(nameOrType: string | NodeType | MarkType): Record<string, any>;
106
- /**
107
- * Returns if the currently selected node or mark is active.
108
- *
109
- * @param name Name of the node or mark
110
- * @param attributes Attributes of the node or mark
111
- */
112
- isActive(name: string, attributes?: {}): boolean;
113
- isActive(attributes: {}): boolean;
114
- /**
115
- * Get the document as JSON.
116
- */
117
- getJSON(): JSONContent;
118
- /**
119
- * Get the document as HTML.
120
- */
121
- getHTML(): string;
122
- /**
123
- * Get the document as text.
124
- */
125
- getText(options?: {
126
- blockSeparator?: string;
127
- textSerializers?: Record<string, TextSerializer>;
128
- }): string;
129
- /**
130
- * Check if there is no content.
131
- */
132
- get isEmpty(): boolean;
133
- /**
134
- * Get the number of characters for the current document.
135
- *
136
- * @deprecated
137
- */
138
- getCharacterCount(): number;
139
- /**
140
- * Destroy the editor.
141
- */
142
- destroy(): void;
143
- /**
144
- * Check if the editor is already destroyed.
145
- */
146
- get isDestroyed(): boolean;
147
- }
@@ -1,11 +0,0 @@
1
- declare type StringKeyOf<T> = Extract<keyof T, string>;
2
- declare type CallbackType<T extends Record<string, any>, EventName extends StringKeyOf<T>> = T[EventName] extends any[] ? T[EventName] : [T[EventName]];
3
- declare type CallbackFunction<T extends Record<string, any>, EventName extends StringKeyOf<T>> = (...props: CallbackType<T, EventName>) => any;
4
- export declare class EventEmitter<T extends Record<string, any>> {
5
- private callbacks;
6
- on<EventName extends StringKeyOf<T>>(event: EventName, fn: CallbackFunction<T, EventName>): this;
7
- protected emit<EventName extends StringKeyOf<T>>(event: EventName, ...args: CallbackType<T, EventName>): this;
8
- off<EventName extends StringKeyOf<T>>(event: EventName, fn?: CallbackFunction<T, EventName>): this;
9
- protected removeAllListeners(): void;
10
- }
11
- export {};