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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +5 -1
  3. package/dist/index.cjs +2627 -2651
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +2423 -2688
  6. package/dist/index.d.ts +2423 -2688
  7. package/dist/index.js +2639 -2684
  8. package/dist/index.js.map +1 -1
  9. package/dist/jsx-runtime/jsx-runtime.cjs +56 -0
  10. package/dist/jsx-runtime/jsx-runtime.cjs.map +1 -0
  11. package/dist/jsx-runtime/jsx-runtime.d.cts +22 -0
  12. package/dist/jsx-runtime/jsx-runtime.d.ts +22 -0
  13. package/dist/jsx-runtime/jsx-runtime.js +26 -0
  14. package/dist/jsx-runtime/jsx-runtime.js.map +1 -0
  15. package/jsx-runtime/index.cjs +1 -0
  16. package/jsx-runtime/index.d.cts +1 -0
  17. package/jsx-runtime/index.d.ts +1 -0
  18. package/jsx-runtime/index.js +1 -0
  19. package/package.json +27 -6
  20. package/src/CommandManager.ts +2 -9
  21. package/src/Editor.ts +191 -94
  22. package/src/EventEmitter.ts +7 -10
  23. package/src/Extendable.ts +483 -0
  24. package/src/Extension.ts +5 -496
  25. package/src/ExtensionManager.ts +81 -135
  26. package/src/InputRule.ts +35 -48
  27. package/src/Mark.ts +135 -623
  28. package/src/MarkView.ts +66 -0
  29. package/src/Node.ts +325 -829
  30. package/src/NodePos.ts +1 -3
  31. package/src/NodeView.ts +10 -20
  32. package/src/PasteRule.ts +43 -55
  33. package/src/Tracker.ts +7 -9
  34. package/src/commands/blur.ts +14 -12
  35. package/src/commands/clearContent.ts +12 -5
  36. package/src/commands/clearNodes.ts +32 -30
  37. package/src/commands/command.ts +1 -1
  38. package/src/commands/createParagraphNear.ts +5 -3
  39. package/src/commands/cut.ts +12 -10
  40. package/src/commands/deleteCurrentNode.ts +23 -21
  41. package/src/commands/deleteNode.ts +18 -16
  42. package/src/commands/deleteRange.ts +10 -8
  43. package/src/commands/deleteSelection.ts +5 -3
  44. package/src/commands/enter.ts +6 -4
  45. package/src/commands/exitCode.ts +5 -3
  46. package/src/commands/extendMarkRange.ts +14 -12
  47. package/src/commands/first.ts +2 -4
  48. package/src/commands/focus.ts +51 -48
  49. package/src/commands/forEach.ts +2 -2
  50. package/src/commands/insertContent.ts +12 -14
  51. package/src/commands/insertContentAt.ts +105 -98
  52. package/src/commands/join.ts +20 -12
  53. package/src/commands/joinItemBackward.ts +16 -18
  54. package/src/commands/joinItemForward.ts +16 -18
  55. package/src/commands/joinTextblockBackward.ts +5 -3
  56. package/src/commands/joinTextblockForward.ts +5 -3
  57. package/src/commands/keyboardShortcut.ts +29 -34
  58. package/src/commands/lift.ts +10 -8
  59. package/src/commands/liftEmptyBlock.ts +6 -4
  60. package/src/commands/liftListItem.ts +6 -4
  61. package/src/commands/newlineInCode.ts +5 -3
  62. package/src/commands/resetAttributes.ts +36 -41
  63. package/src/commands/scrollIntoView.ts +9 -7
  64. package/src/commands/selectAll.ts +10 -8
  65. package/src/commands/selectNodeBackward.ts +5 -3
  66. package/src/commands/selectNodeForward.ts +5 -3
  67. package/src/commands/selectParentNode.ts +5 -3
  68. package/src/commands/selectTextblockEnd.ts +5 -3
  69. package/src/commands/selectTextblockStart.ts +5 -3
  70. package/src/commands/setContent.ts +37 -36
  71. package/src/commands/setMark.ts +55 -57
  72. package/src/commands/setMeta.ts +7 -5
  73. package/src/commands/setNode.ts +32 -30
  74. package/src/commands/setNodeSelection.ts +11 -9
  75. package/src/commands/setTextSelection.ts +15 -13
  76. package/src/commands/sinkListItem.ts +6 -4
  77. package/src/commands/splitBlock.ts +67 -76
  78. package/src/commands/splitListItem.ts +93 -106
  79. package/src/commands/toggleList.ts +73 -71
  80. package/src/commands/toggleMark.ts +11 -9
  81. package/src/commands/toggleNode.ts +18 -16
  82. package/src/commands/toggleWrap.ts +10 -8
  83. package/src/commands/undoInputRule.ts +31 -29
  84. package/src/commands/unsetAllMarks.ts +16 -14
  85. package/src/commands/unsetMark.ts +27 -25
  86. package/src/commands/updateAttributes.ts +92 -100
  87. package/src/commands/wrapIn.ts +6 -4
  88. package/src/commands/wrapInList.ts +6 -4
  89. package/src/extensions/clipboardTextSerializer.ts +2 -4
  90. package/src/extensions/delete.ts +89 -0
  91. package/src/extensions/focusEvents.ts +2 -6
  92. package/src/extensions/index.ts +1 -0
  93. package/src/extensions/keymap.ts +58 -50
  94. package/src/extensions/paste.ts +0 -1
  95. package/src/extensions/tabindex.ts +1 -1
  96. package/src/helpers/combineTransactionSteps.ts +1 -4
  97. package/src/helpers/createChainableState.ts +1 -4
  98. package/src/helpers/createDocument.ts +1 -3
  99. package/src/helpers/createNodeFromContent.ts +4 -10
  100. package/src/helpers/findChildrenInRange.ts +1 -5
  101. package/src/helpers/findParentNode.ts +3 -1
  102. package/src/helpers/flattenExtensions.ts +30 -0
  103. package/src/helpers/getAttributes.ts +1 -4
  104. package/src/helpers/getAttributesFromExtensions.ts +28 -37
  105. package/src/helpers/getChangedRanges.ts +13 -11
  106. package/src/helpers/getExtensionField.ts +11 -11
  107. package/src/helpers/getMarkAttributes.ts +1 -4
  108. package/src/helpers/getMarkRange.ts +5 -15
  109. package/src/helpers/getMarkType.ts +1 -3
  110. package/src/helpers/getNodeAttributes.ts +1 -4
  111. package/src/helpers/getNodeType.ts +1 -3
  112. package/src/helpers/getRenderedAttributes.ts +1 -3
  113. package/src/helpers/getSchema.ts +2 -2
  114. package/src/helpers/getSchemaByResolvedExtensions.ts +45 -77
  115. package/src/helpers/getSplittedAttributes.ts +4 -4
  116. package/src/helpers/getTextContentFromNodes.ts +8 -11
  117. package/src/helpers/index.ts +4 -0
  118. package/src/helpers/injectExtensionAttributesToParseRule.ts +1 -1
  119. package/src/helpers/isActive.ts +1 -5
  120. package/src/helpers/isExtensionRulesEnabled.ts +1 -3
  121. package/src/helpers/isNodeEmpty.ts +2 -2
  122. package/src/helpers/resolveExtensions.ts +25 -0
  123. package/src/helpers/resolveFocusPosition.ts +3 -14
  124. package/src/helpers/rewriteUnknownContent.ts +149 -0
  125. package/src/helpers/sortExtensions.ts +26 -0
  126. package/src/index.ts +3 -7
  127. package/src/inputRules/markInputRule.ts +1 -5
  128. package/src/inputRules/nodeInputRule.ts +2 -9
  129. package/src/inputRules/textInputRule.ts +1 -4
  130. package/src/inputRules/textblockTypeInputRule.ts +2 -8
  131. package/src/inputRules/wrappingInputRule.ts +13 -19
  132. package/src/jsx-runtime.ts +64 -0
  133. package/src/pasteRules/markPasteRule.ts +1 -3
  134. package/src/pasteRules/nodePasteRule.ts +2 -8
  135. package/src/pasteRules/textPasteRule.ts +1 -4
  136. package/src/types.ts +529 -174
  137. package/src/utilities/createStyleTag.ts +3 -1
  138. package/src/utilities/deleteProps.ts +7 -11
  139. package/src/utilities/elementFromString.ts +3 -0
  140. package/src/utilities/findDuplicates.ts +4 -1
  141. package/src/utilities/index.ts +1 -0
  142. package/src/utilities/isFunction.ts +1 -0
  143. package/src/utilities/isMacOS.ts +1 -3
  144. package/src/utilities/isiOS.ts +5 -10
  145. package/src/utilities/mergeAttributes.ts +17 -7
  146. package/src/utilities/removeDuplicates.ts +1 -3
package/src/index.ts CHANGED
@@ -5,7 +5,9 @@ export * as extensions from './extensions/index.js'
5
5
  export * from './helpers/index.js'
6
6
  export * from './InputRule.js'
7
7
  export * from './inputRules/index.js'
8
+ export { createElement, Fragment, createElement as h } from './jsx-runtime.js'
8
9
  export * from './Mark.js'
10
+ export * from './MarkView.js'
9
11
  export * from './Node.js'
10
12
  export * from './NodePos.js'
11
13
  export * from './NodeView.js'
@@ -19,10 +21,4 @@ export * from './utilities/index.js'
19
21
  export interface Commands<ReturnType = any> {}
20
22
 
21
23
  // eslint-disable-next-line
22
- export interface ExtensionConfig<Options = any, Storage = any> {}
23
-
24
- // eslint-disable-next-line
25
- export interface NodeConfig<Options = any, Storage = any> {}
26
-
27
- // eslint-disable-next-line
28
- export interface MarkConfig<Options = any, Storage = any> {}
24
+ export interface Storage {}
@@ -13,11 +13,7 @@ import { callOrReturn } from '../utilities/callOrReturn.js'
13
13
  export function markInputRule(config: {
14
14
  find: InputRuleFinder
15
15
  type: MarkType
16
- getAttributes?:
17
- | Record<string, any>
18
- | ((match: ExtendedRegExpMatchArray) => Record<string, any>)
19
- | false
20
- | null
16
+ getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null
21
17
  }) {
22
18
  return new InputRule({
23
19
  find: config.find,
@@ -24,11 +24,7 @@ export function nodeInputRule(config: {
24
24
  * A function that returns the attributes for the node
25
25
  * can also be an object of attributes
26
26
  */
27
- getAttributes?:
28
- | Record<string, any>
29
- | ((match: ExtendedRegExpMatchArray) => Record<string, any>)
30
- | false
31
- | null
27
+ getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null
32
28
  }) {
33
29
  return new InputRule({
34
30
  find: config.find,
@@ -60,10 +56,7 @@ export function nodeInputRule(config: {
60
56
  } else if (match[0]) {
61
57
  const insertionStart = config.type.isInline ? start : start - 1
62
58
 
63
- tr.insert(insertionStart, config.type.create(attributes)).delete(
64
- tr.mapping.map(start),
65
- tr.mapping.map(end),
66
- )
59
+ tr.insert(insertionStart, config.type.create(attributes)).delete(tr.mapping.map(start), tr.mapping.map(end))
67
60
  }
68
61
 
69
62
  tr.scrollIntoView()
@@ -5,10 +5,7 @@ import { InputRule, InputRuleFinder } from '../InputRule.js'
5
5
  * matched text is typed into it.
6
6
  * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules
7
7
  */
8
- export function textInputRule(config: {
9
- find: InputRuleFinder,
10
- replace: string,
11
- }) {
8
+ export function textInputRule(config: { find: InputRuleFinder; replace: string }) {
12
9
  return new InputRule({
13
10
  find: config.find,
14
11
  handler: ({ state, range, match }) => {
@@ -14,11 +14,7 @@ import { callOrReturn } from '../utilities/callOrReturn.js'
14
14
  export function textblockTypeInputRule(config: {
15
15
  find: InputRuleFinder
16
16
  type: NodeType
17
- getAttributes?:
18
- | Record<string, any>
19
- | ((match: ExtendedRegExpMatchArray) => Record<string, any>)
20
- | false
21
- | null
17
+ getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null
22
18
  }) {
23
19
  return new InputRule({
24
20
  find: config.find,
@@ -30,9 +26,7 @@ export function textblockTypeInputRule(config: {
30
26
  return null
31
27
  }
32
28
 
33
- state.tr
34
- .delete(range.from, range.to)
35
- .setBlockType(range.from, range.from, config.type, attributes)
29
+ state.tr.delete(range.from, range.to).setBlockType(range.from, range.from, config.type, attributes)
36
30
  },
37
31
  })
38
32
  }
@@ -22,24 +22,17 @@ import { callOrReturn } from '../utilities/callOrReturn.js'
22
22
  * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules
23
23
  */
24
24
  export function wrappingInputRule(config: {
25
- find: InputRuleFinder,
26
- type: NodeType,
27
- keepMarks?: boolean,
28
- keepAttributes?: boolean,
25
+ find: InputRuleFinder
26
+ type: NodeType
27
+ keepMarks?: boolean
28
+ keepAttributes?: boolean
29
29
  editor?: Editor
30
- getAttributes?:
31
- | Record<string, any>
32
- | ((match: ExtendedRegExpMatchArray) => Record<string, any>)
33
- | false
34
- | null
35
- ,
36
- joinPredicate?: (match: ExtendedRegExpMatchArray, node: ProseMirrorNode) => boolean,
30
+ getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null
31
+ joinPredicate?: (match: ExtendedRegExpMatchArray, node: ProseMirrorNode) => boolean
37
32
  }) {
38
33
  return new InputRule({
39
34
  find: config.find,
40
- handler: ({
41
- state, range, match, chain,
42
- }) => {
35
+ handler: ({ state, range, match, chain }) => {
43
36
  const attributes = callOrReturn(config.getAttributes, undefined, match) || {}
44
37
  const tr = state.tr.delete(range.from, range.to)
45
38
  const $start = tr.doc.resolve(range.from)
@@ -65,7 +58,8 @@ export function wrappingInputRule(config: {
65
58
  }
66
59
  if (config.keepAttributes) {
67
60
  /** If the nodeType is `bulletList` or `orderedList` set the `nodeType` as `listItem` */
68
- const nodeType = config.type.name === 'bulletList' || config.type.name === 'orderedList' ? 'listItem' : 'taskList'
61
+ const nodeType =
62
+ config.type.name === 'bulletList' || config.type.name === 'orderedList' ? 'listItem' : 'taskList'
69
63
 
70
64
  chain().updateAttributes(nodeType, attributes).run()
71
65
  }
@@ -73,10 +67,10 @@ export function wrappingInputRule(config: {
73
67
  const before = tr.doc.resolve(range.from - 1).nodeBefore
74
68
 
75
69
  if (
76
- before
77
- && before.type === config.type
78
- && canJoin(tr.doc, range.from - 1)
79
- && (!config.joinPredicate || config.joinPredicate(match, before))
70
+ before &&
71
+ before.type === config.type &&
72
+ canJoin(tr.doc, range.from - 1) &&
73
+ (!config.joinPredicate || config.joinPredicate(match, before))
80
74
  ) {
81
75
  tr.join(range.from - 1)
82
76
  }
@@ -0,0 +1,64 @@
1
+ export type Attributes = Record<string, any>
2
+
3
+ export type DOMOutputSpecElement = 0 | Attributes | DOMOutputSpecArray
4
+ /**
5
+ * Better describes the output of a `renderHTML` function in prosemirror
6
+ * @see https://prosemirror.net/docs/ref/#model.DOMOutputSpec
7
+ */
8
+ export type DOMOutputSpecArray =
9
+ | [string]
10
+ | [string, Attributes]
11
+ | [string, 0]
12
+ | [string, Attributes, 0]
13
+ | [string, Attributes, DOMOutputSpecArray | 0]
14
+ | [string, DOMOutputSpecArray]
15
+
16
+ declare global {
17
+ // eslint-disable-next-line @typescript-eslint/no-namespace
18
+ namespace JSX {
19
+ // @ts-ignore - conflict with React typings
20
+ type Element = [string, ...any[]]
21
+ // @ts-ignore - conflict with React typings
22
+ interface IntrinsicElements {
23
+ // @ts-ignore - conflict with React typings
24
+ [key: string]: any
25
+ }
26
+ }
27
+ }
28
+
29
+ export type JSXRenderer = (
30
+ tag: 'slot' | string | ((props?: Attributes) => DOMOutputSpecArray | DOMOutputSpecElement),
31
+ props?: Attributes,
32
+ ...children: JSXRenderer[]
33
+ ) => DOMOutputSpecArray | DOMOutputSpecElement
34
+
35
+ export function Fragment(props: { children: JSXRenderer[] }) {
36
+ return props.children
37
+ }
38
+
39
+ export const h: JSXRenderer = (tag, attributes) => {
40
+ // Treat the slot tag as the Prosemirror hole to render content into
41
+ if (tag === 'slot') {
42
+ return 0
43
+ }
44
+
45
+ // If the tag is a function, call it with the props
46
+ if (tag instanceof Function) {
47
+ return tag(attributes)
48
+ }
49
+
50
+ const { children, ...rest } = attributes ?? {}
51
+
52
+ if (tag === 'svg') {
53
+ throw new Error('SVG elements are not supported in the JSX syntax, use the array syntax instead')
54
+ }
55
+
56
+ // Otherwise, return the tag, attributes, and children
57
+ return [tag, rest, children]
58
+ }
59
+
60
+ // See
61
+ // https://esbuild.github.io/api/#jsx-import-source
62
+ // https://www.typescriptlang.org/tsconfig/#jsxImportSource
63
+
64
+ export { h as createElement, h as jsx, h as jsxDEV, h as jsxs }
@@ -21,9 +21,7 @@ export function markPasteRule(config: {
21
21
  }) {
22
22
  return new PasteRule({
23
23
  find: config.find,
24
- handler: ({
25
- state, range, match, pasteEvent,
26
- }) => {
24
+ handler: ({ state, range, match, pasteEvent }) => {
27
25
  const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent)
28
26
 
29
27
  if (attributes === false || attributes === null) {
@@ -17,17 +17,11 @@ export function nodePasteRule(config: {
17
17
  | ((match: ExtendedRegExpMatchArray, event: ClipboardEvent) => Record<string, any>)
18
18
  | false
19
19
  | null
20
- getContent?:
21
- | JSONContent[]
22
- | ((attrs: Record<string, any>) => JSONContent[])
23
- | false
24
- | null
20
+ getContent?: JSONContent[] | ((attrs: Record<string, any>) => JSONContent[]) | false | null
25
21
  }) {
26
22
  return new PasteRule({
27
23
  find: config.find,
28
- handler({
29
- match, chain, range, pasteEvent,
30
- }) {
24
+ handler({ match, chain, range, pasteEvent }) {
31
25
  const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent)
32
26
  const content = callOrReturn(config.getContent, undefined, attributes)
33
27
 
@@ -5,10 +5,7 @@ import { PasteRule, PasteRuleFinder } from '../PasteRule.js'
5
5
  * matched text is pasted into it.
6
6
  * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#paste-rules
7
7
  */
8
- export function textPasteRule(config: {
9
- find: PasteRuleFinder,
10
- replace: string,
11
- }) {
8
+ export function textPasteRule(config: { find: PasteRuleFinder; replace: string }) {
12
9
  return new PasteRule({
13
10
  find: config.find,
14
11
  handler: ({ state, range, match }) => {