@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.
- package/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +2627 -2651
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2423 -2688
- package/dist/index.d.ts +2423 -2688
- package/dist/index.js +2639 -2684
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime/jsx-runtime.cjs +56 -0
- package/dist/jsx-runtime/jsx-runtime.cjs.map +1 -0
- package/dist/jsx-runtime/jsx-runtime.d.cts +22 -0
- package/dist/jsx-runtime/jsx-runtime.d.ts +22 -0
- package/dist/jsx-runtime/jsx-runtime.js +26 -0
- package/dist/jsx-runtime/jsx-runtime.js.map +1 -0
- package/jsx-runtime/index.cjs +1 -0
- package/jsx-runtime/index.d.cts +1 -0
- package/jsx-runtime/index.d.ts +1 -0
- package/jsx-runtime/index.js +1 -0
- package/package.json +27 -6
- package/src/CommandManager.ts +2 -9
- package/src/Editor.ts +191 -94
- package/src/EventEmitter.ts +7 -10
- package/src/Extendable.ts +483 -0
- package/src/Extension.ts +5 -496
- package/src/ExtensionManager.ts +81 -135
- package/src/InputRule.ts +35 -48
- package/src/Mark.ts +135 -623
- package/src/MarkView.ts +66 -0
- package/src/Node.ts +325 -829
- package/src/NodePos.ts +1 -3
- package/src/NodeView.ts +10 -20
- package/src/PasteRule.ts +43 -55
- package/src/Tracker.ts +7 -9
- package/src/commands/blur.ts +14 -12
- package/src/commands/clearContent.ts +12 -5
- package/src/commands/clearNodes.ts +32 -30
- package/src/commands/command.ts +1 -1
- package/src/commands/createParagraphNear.ts +5 -3
- package/src/commands/cut.ts +12 -10
- package/src/commands/deleteCurrentNode.ts +23 -21
- package/src/commands/deleteNode.ts +18 -16
- package/src/commands/deleteRange.ts +10 -8
- package/src/commands/deleteSelection.ts +5 -3
- package/src/commands/enter.ts +6 -4
- package/src/commands/exitCode.ts +5 -3
- package/src/commands/extendMarkRange.ts +14 -12
- package/src/commands/first.ts +2 -4
- package/src/commands/focus.ts +51 -48
- package/src/commands/forEach.ts +2 -2
- package/src/commands/insertContent.ts +12 -14
- package/src/commands/insertContentAt.ts +105 -98
- package/src/commands/join.ts +20 -12
- package/src/commands/joinItemBackward.ts +16 -18
- package/src/commands/joinItemForward.ts +16 -18
- package/src/commands/joinTextblockBackward.ts +5 -3
- package/src/commands/joinTextblockForward.ts +5 -3
- package/src/commands/keyboardShortcut.ts +29 -34
- package/src/commands/lift.ts +10 -8
- package/src/commands/liftEmptyBlock.ts +6 -4
- package/src/commands/liftListItem.ts +6 -4
- package/src/commands/newlineInCode.ts +5 -3
- package/src/commands/resetAttributes.ts +36 -41
- package/src/commands/scrollIntoView.ts +9 -7
- package/src/commands/selectAll.ts +10 -8
- package/src/commands/selectNodeBackward.ts +5 -3
- package/src/commands/selectNodeForward.ts +5 -3
- package/src/commands/selectParentNode.ts +5 -3
- package/src/commands/selectTextblockEnd.ts +5 -3
- package/src/commands/selectTextblockStart.ts +5 -3
- package/src/commands/setContent.ts +37 -36
- package/src/commands/setMark.ts +55 -57
- package/src/commands/setMeta.ts +7 -5
- package/src/commands/setNode.ts +32 -30
- package/src/commands/setNodeSelection.ts +11 -9
- package/src/commands/setTextSelection.ts +15 -13
- package/src/commands/sinkListItem.ts +6 -4
- package/src/commands/splitBlock.ts +67 -76
- package/src/commands/splitListItem.ts +93 -106
- package/src/commands/toggleList.ts +73 -71
- package/src/commands/toggleMark.ts +11 -9
- package/src/commands/toggleNode.ts +18 -16
- package/src/commands/toggleWrap.ts +10 -8
- package/src/commands/undoInputRule.ts +31 -29
- package/src/commands/unsetAllMarks.ts +16 -14
- package/src/commands/unsetMark.ts +27 -25
- package/src/commands/updateAttributes.ts +92 -100
- package/src/commands/wrapIn.ts +6 -4
- package/src/commands/wrapInList.ts +6 -4
- package/src/extensions/clipboardTextSerializer.ts +2 -4
- package/src/extensions/delete.ts +89 -0
- package/src/extensions/focusEvents.ts +2 -6
- package/src/extensions/index.ts +1 -0
- package/src/extensions/keymap.ts +58 -50
- package/src/extensions/paste.ts +0 -1
- package/src/extensions/tabindex.ts +1 -1
- package/src/helpers/combineTransactionSteps.ts +1 -4
- package/src/helpers/createChainableState.ts +1 -4
- package/src/helpers/createDocument.ts +1 -3
- package/src/helpers/createNodeFromContent.ts +4 -10
- package/src/helpers/findChildrenInRange.ts +1 -5
- package/src/helpers/findParentNode.ts +3 -1
- package/src/helpers/flattenExtensions.ts +30 -0
- package/src/helpers/getAttributes.ts +1 -4
- package/src/helpers/getAttributesFromExtensions.ts +28 -37
- package/src/helpers/getChangedRanges.ts +13 -11
- package/src/helpers/getExtensionField.ts +11 -11
- package/src/helpers/getMarkAttributes.ts +1 -4
- package/src/helpers/getMarkRange.ts +5 -15
- package/src/helpers/getMarkType.ts +1 -3
- package/src/helpers/getNodeAttributes.ts +1 -4
- package/src/helpers/getNodeType.ts +1 -3
- package/src/helpers/getRenderedAttributes.ts +1 -3
- package/src/helpers/getSchema.ts +2 -2
- package/src/helpers/getSchemaByResolvedExtensions.ts +45 -77
- package/src/helpers/getSplittedAttributes.ts +4 -4
- package/src/helpers/getTextContentFromNodes.ts +8 -11
- package/src/helpers/index.ts +4 -0
- package/src/helpers/injectExtensionAttributesToParseRule.ts +1 -1
- package/src/helpers/isActive.ts +1 -5
- package/src/helpers/isExtensionRulesEnabled.ts +1 -3
- package/src/helpers/isNodeEmpty.ts +2 -2
- package/src/helpers/resolveExtensions.ts +25 -0
- package/src/helpers/resolveFocusPosition.ts +3 -14
- package/src/helpers/rewriteUnknownContent.ts +149 -0
- package/src/helpers/sortExtensions.ts +26 -0
- package/src/index.ts +3 -7
- package/src/inputRules/markInputRule.ts +1 -5
- package/src/inputRules/nodeInputRule.ts +2 -9
- package/src/inputRules/textInputRule.ts +1 -4
- package/src/inputRules/textblockTypeInputRule.ts +2 -8
- package/src/inputRules/wrappingInputRule.ts +13 -19
- package/src/jsx-runtime.ts +64 -0
- package/src/pasteRules/markPasteRule.ts +1 -3
- package/src/pasteRules/nodePasteRule.ts +2 -8
- package/src/pasteRules/textPasteRule.ts +1 -4
- package/src/types.ts +529 -174
- package/src/utilities/createStyleTag.ts +3 -1
- package/src/utilities/deleteProps.ts +7 -11
- package/src/utilities/elementFromString.ts +3 -0
- package/src/utilities/findDuplicates.ts +4 -1
- package/src/utilities/index.ts +1 -0
- package/src/utilities/isFunction.ts +1 -0
- package/src/utilities/isMacOS.ts +1 -3
- package/src/utilities/isiOS.ts +5 -10
- package/src/utilities/mergeAttributes.ts +17 -7
- 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
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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 }) => {
|