@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
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export function createStyleTag(style: string, nonce?: string, suffix?: string): HTMLStyleElement {
|
|
2
|
-
const tiptapStyleTag =
|
|
2
|
+
const tiptapStyleTag = <HTMLStyleElement>(
|
|
3
|
+
document.querySelector(`style[data-tiptap-style${suffix ? `-${suffix}` : ''}]`)
|
|
4
|
+
)
|
|
3
5
|
|
|
4
6
|
if (tiptapStyleTag !== null) {
|
|
5
7
|
return tiptapStyleTag
|
|
@@ -4,17 +4,13 @@
|
|
|
4
4
|
* @param key Key to remove
|
|
5
5
|
*/
|
|
6
6
|
export function deleteProps(obj: Record<string, any>, propOrProps: string | string[]): Record<string, any> {
|
|
7
|
-
const props = typeof propOrProps === 'string'
|
|
8
|
-
? [propOrProps]
|
|
9
|
-
: propOrProps
|
|
7
|
+
const props = typeof propOrProps === 'string' ? [propOrProps] : propOrProps
|
|
10
8
|
|
|
11
|
-
return Object
|
|
12
|
-
.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
newObj[prop] = obj[prop]
|
|
16
|
-
}
|
|
9
|
+
return Object.keys(obj).reduce((newObj: Record<string, any>, prop) => {
|
|
10
|
+
if (!props.includes(prop)) {
|
|
11
|
+
newObj[prop] = obj[prop]
|
|
12
|
+
}
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
return newObj
|
|
15
|
+
}, {})
|
|
20
16
|
}
|
|
@@ -15,6 +15,9 @@ const removeWhitespaces = (node: HTMLElement) => {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function elementFromString(value: string): HTMLElement {
|
|
18
|
+
if (typeof window === 'undefined') {
|
|
19
|
+
throw new Error('[tiptap error]: there is no window object available, so this function cannot be used')
|
|
20
|
+
}
|
|
18
21
|
// add a wrapper to preserve leading and trailing whitespace
|
|
19
22
|
const wrappedValue = `<body>${value}</body>`
|
|
20
23
|
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Find duplicates in an array.
|
|
3
|
+
*/
|
|
4
|
+
export function findDuplicates<T>(items: T[]): T[] {
|
|
2
5
|
const filtered = items.filter((el, index) => items.indexOf(el) !== index)
|
|
3
6
|
|
|
4
7
|
return Array.from(new Set(filtered))
|
package/src/utilities/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './elementFromString.js'
|
|
|
5
5
|
export * from './escapeForRegEx.js'
|
|
6
6
|
export * from './findDuplicates.js'
|
|
7
7
|
export * from './fromString.js'
|
|
8
|
+
export * from './isAndroid.js'
|
|
8
9
|
export * from './isEmptyObject.js'
|
|
9
10
|
export * from './isFunction.js'
|
|
10
11
|
export * from './isiOS.js'
|
package/src/utilities/isMacOS.ts
CHANGED
package/src/utilities/isiOS.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
export function isiOS(): boolean {
|
|
2
|
-
return
|
|
3
|
-
'iPad Simulator',
|
|
4
|
-
|
|
5
|
-
'
|
|
6
|
-
|
|
7
|
-
'iPhone',
|
|
8
|
-
'iPod',
|
|
9
|
-
].includes(navigator.platform)
|
|
10
|
-
// iPad on iOS 13 detection
|
|
11
|
-
|| (navigator.userAgent.includes('Mac') && 'ontouchend' in document)
|
|
2
|
+
return (
|
|
3
|
+
['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator.platform) ||
|
|
4
|
+
// iPad on iOS 13 detection
|
|
5
|
+
(navigator.userAgent.includes('Mac') && 'ontouchend' in document)
|
|
6
|
+
)
|
|
12
7
|
}
|
|
@@ -14,17 +14,25 @@ export function mergeAttributes(...objects: Record<string, any>[]): Record<strin
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
if (key === 'class') {
|
|
17
|
-
const valueClasses: string[] = value ? value.split(' ') : []
|
|
17
|
+
const valueClasses: string[] = value ? String(value).split(' ') : []
|
|
18
18
|
const existingClasses: string[] = mergedAttributes[key] ? mergedAttributes[key].split(' ') : []
|
|
19
19
|
|
|
20
|
-
const insertClasses = valueClasses.filter(
|
|
21
|
-
valueClass => !existingClasses.includes(valueClass),
|
|
22
|
-
)
|
|
20
|
+
const insertClasses = valueClasses.filter(valueClass => !existingClasses.includes(valueClass))
|
|
23
21
|
|
|
24
22
|
mergedAttributes[key] = [...existingClasses, ...insertClasses].join(' ')
|
|
25
23
|
} else if (key === 'style') {
|
|
26
|
-
const newStyles: string[] = value
|
|
27
|
-
|
|
24
|
+
const newStyles: string[] = value
|
|
25
|
+
? value
|
|
26
|
+
.split(';')
|
|
27
|
+
.map((style: string) => style.trim())
|
|
28
|
+
.filter(Boolean)
|
|
29
|
+
: []
|
|
30
|
+
const existingStyles: string[] = mergedAttributes[key]
|
|
31
|
+
? mergedAttributes[key]
|
|
32
|
+
.split(';')
|
|
33
|
+
.map((style: string) => style.trim())
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
: []
|
|
28
36
|
|
|
29
37
|
const styleMap = new Map<string, string>()
|
|
30
38
|
|
|
@@ -40,7 +48,9 @@ export function mergeAttributes(...objects: Record<string, any>[]): Record<strin
|
|
|
40
48
|
styleMap.set(property, val)
|
|
41
49
|
})
|
|
42
50
|
|
|
43
|
-
mergedAttributes[key] = Array.from(styleMap.entries())
|
|
51
|
+
mergedAttributes[key] = Array.from(styleMap.entries())
|
|
52
|
+
.map(([property, val]) => `${property}: ${val}`)
|
|
53
|
+
.join('; ')
|
|
44
54
|
} else {
|
|
45
55
|
mergedAttributes[key] = value
|
|
46
56
|
}
|
|
@@ -8,8 +8,6 @@ export function removeDuplicates<T>(array: T[], by = JSON.stringify): T[] {
|
|
|
8
8
|
return array.filter(item => {
|
|
9
9
|
const key = by(item)
|
|
10
10
|
|
|
11
|
-
return Object.prototype.hasOwnProperty.call(seen, key)
|
|
12
|
-
? false
|
|
13
|
-
: (seen[key] = true)
|
|
11
|
+
return Object.prototype.hasOwnProperty.call(seen, key) ? false : (seen[key] = true)
|
|
14
12
|
})
|
|
15
13
|
}
|