@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.
- package/README.md +2 -2
- package/dist/index.cjs +4311 -0
- package/dist/index.d.ts +2330 -0
- package/dist/index.js +4311 -0
- package/package.json +39 -25
- package/src/CommandManager.ts +76 -86
- package/src/Editor.ts +120 -81
- package/src/EventEmitter.ts +14 -4
- package/src/Extension.ts +280 -108
- package/src/ExtensionManager.ts +254 -108
- package/src/InputRule.ts +260 -0
- package/src/Mark.ts +398 -147
- package/src/Node.ts +437 -171
- package/src/NodeView.ts +132 -63
- package/src/PasteRule.ts +240 -0
- package/src/Tracker.ts +38 -0
- package/src/commands/blur.ts +12 -6
- package/src/commands/clearContent.ts +3 -3
- package/src/commands/clearNodes.ts +31 -19
- package/src/commands/command.ts +2 -2
- package/src/commands/createParagraphNear.ts +5 -4
- package/src/commands/deleteCurrentNode.ts +41 -0
- package/src/commands/deleteNode.ts +37 -0
- package/src/commands/deleteRange.ts +3 -3
- package/src/commands/deleteSelection.ts +5 -4
- package/src/commands/enter.ts +3 -3
- package/src/commands/exitCode.ts +5 -4
- package/src/commands/extendMarkRange.ts +16 -12
- package/src/commands/first.ts +3 -3
- package/src/commands/focus.ts +47 -44
- package/src/commands/forEach.ts +24 -0
- package/src/commands/index.ts +50 -0
- package/src/commands/insertContent.ts +17 -24
- package/src/commands/insertContentAt.ts +94 -0
- package/src/commands/join.ts +53 -0
- package/src/commands/keyboardShortcut.ts +6 -6
- package/src/commands/lift.ts +8 -7
- package/src/commands/liftEmptyBlock.ts +5 -4
- package/src/commands/liftListItem.ts +7 -6
- package/src/commands/newlineInCode.ts +5 -4
- package/src/commands/resetAttributes.ts +18 -12
- package/src/commands/scrollIntoView.ts +3 -3
- package/src/commands/selectAll.ts +8 -6
- package/src/commands/selectNodeBackward.ts +5 -4
- package/src/commands/selectNodeForward.ts +5 -4
- package/src/commands/selectParentNode.ts +5 -4
- package/src/commands/selectTextblockEnd.ts +20 -0
- package/src/commands/selectTextblockStart.ts +20 -0
- package/src/commands/setContent.ts +9 -16
- package/src/commands/setMark.ts +90 -14
- package/src/commands/setMeta.ts +18 -0
- package/src/commands/setNode.ts +32 -8
- package/src/commands/setNodeSelection.ts +27 -0
- package/src/commands/setTextSelection.ts +31 -0
- package/src/commands/sinkListItem.ts +7 -6
- package/src/commands/splitBlock.ts +31 -41
- package/src/commands/splitListItem.ts +46 -29
- package/src/commands/toggleList.ts +88 -20
- package/src/commands/toggleMark.ts +19 -8
- package/src/commands/toggleNode.ts +11 -6
- package/src/commands/toggleWrap.ts +10 -10
- package/src/commands/undoInputRule.ts +34 -5
- package/src/commands/unsetAllMarks.ts +7 -11
- package/src/commands/unsetMark.ts +36 -23
- package/src/commands/updateAttributes.ts +27 -15
- package/src/commands/wrapIn.ts +7 -12
- package/src/commands/wrapInList.ts +7 -6
- package/src/extensions/clipboardTextSerializer.ts +15 -36
- package/src/extensions/commands.ts +3 -147
- package/src/extensions/editable.ts +2 -1
- package/src/extensions/focusEvents.ts +4 -6
- package/src/extensions/index.ts +1 -0
- package/src/extensions/keymap.ts +106 -13
- package/src/extensions/tabindex.ts +18 -0
- package/src/helpers/combineTransactionSteps.ts +21 -0
- package/src/helpers/createChainableState.ts +38 -0
- package/src/helpers/createDocument.ts +5 -6
- package/src/helpers/createNodeFromContent.ts +20 -28
- package/src/helpers/defaultBlockAt.ts +13 -0
- package/src/helpers/findChildren.ts +18 -0
- package/src/helpers/findChildrenInRange.ts +36 -0
- package/src/helpers/findParentNode.ts +4 -3
- package/src/helpers/findParentNodeClosestToPos.ts +13 -7
- package/src/helpers/generateHTML.ts +7 -6
- package/src/helpers/generateJSON.ts +12 -0
- package/src/helpers/generateText.ts +27 -0
- package/src/helpers/getAttributes.ts +26 -0
- package/src/helpers/getAttributesFromExtensions.ts +42 -14
- package/src/helpers/getChangedRanges.ts +83 -0
- package/src/helpers/getDebugJSON.ts +54 -0
- package/src/helpers/getExtensionField.ts +25 -0
- package/src/helpers/getHTMLFromFragment.ts +5 -6
- package/src/helpers/getMarkAttributes.ts +18 -11
- package/src/helpers/getMarkRange.ts +41 -8
- package/src/helpers/getMarkType.ts +8 -2
- package/src/helpers/getMarksBetween.ts +34 -10
- package/src/helpers/getNodeAttributes.ts +14 -13
- package/src/helpers/getNodeType.ts +8 -2
- package/src/helpers/getRenderedAttributes.ts +9 -7
- package/src/helpers/getSchema.ts +7 -133
- package/src/helpers/getSchemaByResolvedExtensions.ts +192 -0
- package/src/helpers/getSchemaTypeByName.ts +3 -11
- package/src/helpers/getSchemaTypeNameByName.ts +2 -2
- package/src/helpers/getSplittedAttributes.ts +4 -4
- package/src/helpers/getText.ts +19 -0
- package/src/helpers/getTextBetween.ts +46 -0
- package/src/helpers/getTextContentFromNodes.ts +26 -0
- package/src/helpers/getTextSerializersFromSchema.ts +11 -0
- package/src/helpers/index.ts +33 -0
- package/src/helpers/injectExtensionAttributesToParseRule.ts +22 -23
- package/src/helpers/isActive.ts +10 -6
- package/src/helpers/isExtensionRulesEnabled.ts +15 -0
- package/src/helpers/isList.ts +14 -7
- package/src/helpers/isMarkActive.ts +49 -27
- package/src/helpers/isNodeActive.ts +29 -39
- package/src/helpers/isNodeEmpty.ts +2 -2
- package/src/helpers/isNodeSelection.ts +3 -4
- package/src/helpers/isTextSelection.ts +3 -4
- package/src/helpers/posToDOMRect.ts +35 -0
- package/src/helpers/resolveFocusPosition.ts +42 -0
- package/src/helpers/selectionToInsertionEnd.ts +3 -3
- package/src/helpers/splitExtensions.ts +3 -3
- package/src/index.ts +15 -24
- package/src/inputRules/index.ts +5 -0
- package/src/inputRules/markInputRule.ts +59 -40
- package/src/inputRules/nodeInputRule.ts +45 -12
- package/src/inputRules/textInputRule.ts +35 -0
- package/src/inputRules/textblockTypeInputRule.ts +37 -0
- package/src/inputRules/wrappingInputRule.ts +59 -0
- package/src/pasteRules/index.ts +3 -0
- package/src/pasteRules/markPasteRule.ts +61 -53
- package/src/pasteRules/nodePasteRule.ts +37 -0
- package/src/pasteRules/textPasteRule.ts +35 -0
- package/src/style.ts +16 -3
- package/src/types.ts +170 -97
- package/src/utilities/callOrReturn.ts +6 -3
- package/src/utilities/createStyleTag.ts +12 -1
- package/src/utilities/deleteProps.ts +2 -4
- package/src/utilities/elementFromString.ts +4 -5
- package/src/utilities/escapeForRegEx.ts +4 -0
- package/src/utilities/findDuplicates.ts +5 -0
- package/src/utilities/fromString.ts +2 -2
- package/src/utilities/index.ts +20 -0
- package/src/utilities/isEmptyObject.ts +2 -2
- package/src/utilities/isFunction.ts +3 -0
- package/src/utilities/isMacOS.ts +5 -0
- package/src/utilities/isNumber.ts +3 -0
- package/src/utilities/isPlainObject.ts +8 -5
- package/src/utilities/isRegExp.ts +3 -0
- package/src/utilities/isString.ts +3 -0
- package/src/utilities/isiOS.ts +12 -0
- package/src/utilities/mergeAttributes.ts +2 -3
- package/src/utilities/mergeDeep.ts +2 -3
- package/src/utilities/minMax.ts +1 -1
- package/src/utilities/objectIncludes.ts +17 -5
- package/src/utilities/removeDuplicates.ts +15 -0
- package/CHANGELOG.md +0 -365
- package/LICENSE.md +0 -21
- package/dist/packages/core/src/CommandManager.d.ts +0 -13
- package/dist/packages/core/src/Editor.d.ts +0 -142
- package/dist/packages/core/src/EventEmitter.d.ts +0 -7
- package/dist/packages/core/src/Extension.d.ts +0 -148
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -24
- package/dist/packages/core/src/Mark.d.ts +0 -211
- package/dist/packages/core/src/Node.d.ts +0 -265
- package/dist/packages/core/src/NodeView.d.ts +0 -31
- package/dist/packages/core/src/commands/blur.d.ts +0 -12
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -12
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -12
- package/dist/packages/core/src/commands/command.d.ts +0 -12
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -12
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -12
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -12
- package/dist/packages/core/src/commands/enter.d.ts +0 -12
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -12
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -13
- package/dist/packages/core/src/commands/first.d.ts +0 -12
- package/dist/packages/core/src/commands/focus.d.ts +0 -12
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -12
- package/dist/packages/core/src/commands/insertHTML.d.ts +0 -12
- package/dist/packages/core/src/commands/insertNode.d.ts +0 -13
- package/dist/packages/core/src/commands/insertText.d.ts +0 -12
- package/dist/packages/core/src/commands/joinBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinForward.d.ts +0 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -12
- package/dist/packages/core/src/commands/lift.d.ts +0 -13
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -12
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -13
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -12
- package/dist/packages/core/src/commands/replace.d.ts +0 -13
- package/dist/packages/core/src/commands/replaceRange.d.ts +0 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -13
- package/dist/packages/core/src/commands/resetNodeAttributes.d.ts +0 -13
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -12
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -12
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -12
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -12
- package/dist/packages/core/src/commands/setContent.d.ts +0 -12
- package/dist/packages/core/src/commands/setMark.d.ts +0 -13
- package/dist/packages/core/src/commands/setNode.d.ts +0 -13
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -13
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -14
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -13
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -13
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -13
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -13
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -13
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -12
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -12
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -13
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -13
- package/dist/packages/core/src/commands/updateNodeAttributes.d.ts +0 -13
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -13
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -13
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -2
- package/dist/packages/core/src/extensions/commands.d.ts +0 -100
- package/dist/packages/core/src/extensions/editable.d.ts +0 -2
- package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
- package/dist/packages/core/src/extensions/index.d.ts +0 -5
- package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -4
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -8
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -9
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -2
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -4
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -4
- package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchema.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -2
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -2
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -2
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isList.d.ts +0 -2
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -4
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -4
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
- package/dist/packages/core/src/index.d.ts +0 -30
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -3
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -3
- package/dist/packages/core/src/style.d.ts +0 -2
- package/dist/packages/core/src/types.d.ts +0 -154
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -8
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -7
- package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isClass.d.ts +0 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -2
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -2
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -7
- package/dist/packages/core/src/utilities/removeElement.d.ts +0 -1
- package/dist/tiptap-core.bundle.umd.min.js +0 -17
- package/dist/tiptap-core.bundle.umd.min.js.map +0 -1
- package/dist/tiptap-core.cjs.js +0 -3027
- package/dist/tiptap-core.cjs.js.map +0 -1
- package/dist/tiptap-core.esm.js +0 -3002
- package/dist/tiptap-core.esm.js.map +0 -1
- package/dist/tiptap-core.umd.js +0 -3024
- package/dist/tiptap-core.umd.js.map +0 -1
- package/src/commands/insertHTML.ts +0 -30
- package/src/commands/insertNode.ts +0 -33
- package/src/commands/insertText.ts +0 -22
- package/src/commands/joinBackward.ts +0 -17
- package/src/commands/joinForward.ts +0 -17
- package/src/commands/replace.ts +0 -20
- package/src/commands/replaceRange.ts +0 -36
- package/src/commands/resetNodeAttributes.ts +0 -33
- package/src/commands/updateNodeAttributes.ts +0 -35
- package/src/utilities/isClass.ts +0 -7
- package/src/utilities/isObject.ts +0 -10
- 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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from 'prosemirror-model'
|
|
4
|
+
Decoration, EditorProps, EditorView, NodeView,
|
|
5
|
+
} from '@tiptap/pm/view'
|
|
6
|
+
|
|
6
7
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 {
|
|
17
|
-
|
|
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
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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:
|
|
63
|
-
parseHTML?: ((element: HTMLElement) =>
|
|
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 (
|
|
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
|
-
|
|
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
|
|
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> =
|
|
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:
|
|
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:
|
|
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) =>
|
|
178
|
+
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView | {}
|
|
123
179
|
|
|
124
|
-
export type
|
|
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]
|
|
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
|
|
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
|
|
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
|
|
9
|
-
if (
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
2
|
-
|
|
3
|
-
const
|
|
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
|
|
5
|
+
return new window.DOMParser().parseFromString(wrappedValue, 'text/html').body
|
|
7
6
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export
|
|
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(
|
|
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
|
|
2
|
-
return Object.keys(
|
|
1
|
+
export function isEmptyObject(value = {}): boolean {
|
|
2
|
+
return Object.keys(value).length === 0 && value.constructor === Object
|
|
3
3
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
// see: https://github.com/mesqueeb/is-what/blob/88d6e4ca92fb2baab6003c54e02eedf4e729e5ab/src/index.ts
|
|
2
2
|
|
|
3
|
-
function getType(
|
|
4
|
-
return Object.prototype.toString.call(
|
|
3
|
+
function getType(value: any): string {
|
|
4
|
+
return Object.prototype.toString.call(value).slice(8, -1)
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
if (getType(
|
|
9
|
-
|
|
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,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
|
-
|
|
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 {
|
|
2
|
-
import isPlainObject from './isPlainObject'
|
|
1
|
+
import { isPlainObject } from './isPlainObject'
|
|
3
2
|
|
|
4
|
-
export
|
|
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)) {
|
package/src/utilities/minMax.ts
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
|
16
|
-
.
|
|
17
|
-
|
|
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
|
+
}
|