@tiptap/core 3.0.0-next.2 → 3.0.0-next.4
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 +2402 -2540
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1355 -1273
- package/dist/index.d.ts +1355 -1273
- package/dist/index.js +2408 -2562
- package/dist/index.js.map +1 -1
- package/package.json +9 -5
- package/src/CommandManager.ts +2 -9
- package/src/Editor.ts +87 -72
- package/src/EventEmitter.ts +7 -10
- package/src/Extension.ts +8 -14
- package/src/ExtensionManager.ts +26 -125
- package/src/InputRule.ts +35 -48
- package/src/Mark.ts +9 -9
- package/src/Node.ts +9 -9
- 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 +6 -4
- 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 +45 -48
- package/src/commands/forEach.ts +2 -2
- package/src/commands/insertContent.ts +12 -14
- package/src/commands/insertContentAt.ts +101 -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 +25 -25
- 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/focusEvents.ts +2 -6
- package/src/extensions/keymap.ts +54 -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 +1 -4
- 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/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/pasteRules/markPasteRule.ts +1 -3
- package/src/pasteRules/nodePasteRule.ts +2 -8
- package/src/pasteRules/textPasteRule.ts +1 -4
- package/src/types.ts +212 -172
- package/src/utilities/createStyleTag.ts +3 -1
- package/src/utilities/deleteProps.ts +7 -11
- package/src/utilities/findDuplicates.ts +4 -1
- 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 +16 -6
- package/src/utilities/removeDuplicates.ts +1 -3
package/src/types.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Mark as ProseMirrorMark,
|
|
3
|
-
Node as ProseMirrorNode,
|
|
4
|
-
ParseOptions,
|
|
5
|
-
Slice,
|
|
6
|
-
} from '@tiptap/pm/model'
|
|
1
|
+
import { Mark as ProseMirrorMark, Node as ProseMirrorNode, ParseOptions, Slice } from '@tiptap/pm/model'
|
|
7
2
|
import { EditorState, Transaction } from '@tiptap/pm/state'
|
|
8
3
|
import { Mappable } from '@tiptap/pm/transform'
|
|
9
4
|
import {
|
|
@@ -18,76 +13,71 @@ import {
|
|
|
18
13
|
|
|
19
14
|
import { Editor } from './Editor.js'
|
|
20
15
|
import { Extension } from './Extension.js'
|
|
21
|
-
import {
|
|
22
|
-
Commands, ExtensionConfig, MarkConfig, NodeConfig,
|
|
23
|
-
} from './index.js'
|
|
16
|
+
import { Commands, ExtensionConfig, MarkConfig, NodeConfig } from './index.js'
|
|
24
17
|
import { Mark } from './Mark.js'
|
|
25
18
|
import { Node } from './Node.js'
|
|
26
19
|
|
|
27
|
-
export type AnyConfig = ExtensionConfig | NodeConfig | MarkConfig
|
|
28
|
-
export type AnyExtension = Extension | Node | Mark
|
|
29
|
-
export type Extensions = AnyExtension[]
|
|
20
|
+
export type AnyConfig = ExtensionConfig | NodeConfig | MarkConfig
|
|
21
|
+
export type AnyExtension = Extension | Node | Mark
|
|
22
|
+
export type Extensions = AnyExtension[]
|
|
30
23
|
|
|
31
24
|
export type ParentConfig<T> = Partial<{
|
|
32
25
|
[P in keyof T]: Required<T>[P] extends (...args: any) => any
|
|
33
26
|
? (...args: Parameters<Required<T>[P]>) => ReturnType<Required<T>[P]>
|
|
34
|
-
: T[P]
|
|
35
|
-
}
|
|
27
|
+
: T[P]
|
|
28
|
+
}>
|
|
36
29
|
|
|
37
|
-
export type Primitive = null | undefined | string | number | boolean | symbol | bigint
|
|
30
|
+
export type Primitive = null | undefined | string | number | boolean | symbol | bigint
|
|
38
31
|
|
|
39
|
-
export type RemoveThis<T> = T extends (...args: any) => any
|
|
40
|
-
? (...args: Parameters<T>) => ReturnType<T>
|
|
41
|
-
: T;
|
|
32
|
+
export type RemoveThis<T> = T extends (...args: any) => any ? (...args: Parameters<T>) => ReturnType<T> : T
|
|
42
33
|
|
|
43
|
-
export type MaybeReturnType<T> = T extends (...args: any) => any ? ReturnType<T> : T
|
|
34
|
+
export type MaybeReturnType<T> = T extends (...args: any) => any ? ReturnType<T> : T
|
|
44
35
|
|
|
45
|
-
export type MaybeThisParameterType<T> =
|
|
46
|
-
? ThisParameterType<Exclude<T, Primitive>>
|
|
47
|
-
: any;
|
|
36
|
+
export type MaybeThisParameterType<T> =
|
|
37
|
+
Exclude<T, Primitive> extends (...args: any) => any ? ThisParameterType<Exclude<T, Primitive>> : any
|
|
48
38
|
|
|
49
39
|
export interface EditorEvents {
|
|
50
|
-
beforeCreate: { editor: Editor }
|
|
51
|
-
create: { editor: Editor }
|
|
40
|
+
beforeCreate: { editor: Editor }
|
|
41
|
+
create: { editor: Editor }
|
|
52
42
|
contentError: {
|
|
53
|
-
editor: Editor
|
|
54
|
-
error: Error
|
|
43
|
+
editor: Editor
|
|
44
|
+
error: Error
|
|
55
45
|
/**
|
|
56
46
|
* If called, will re-initialize the editor with the collaboration extension removed.
|
|
57
47
|
* This will prevent syncing back deletions of content not present in the current schema.
|
|
58
48
|
*/
|
|
59
|
-
disableCollaboration: () => void
|
|
60
|
-
}
|
|
61
|
-
update: { editor: Editor; transaction: Transaction }
|
|
62
|
-
selectionUpdate: { editor: Editor; transaction: Transaction }
|
|
63
|
-
beforeTransaction: { editor: Editor; transaction: Transaction; nextState: EditorState }
|
|
64
|
-
transaction: { editor: Editor; transaction: Transaction }
|
|
65
|
-
focus: { editor: Editor; event: FocusEvent; transaction: Transaction }
|
|
66
|
-
blur: { editor: Editor; event: FocusEvent; transaction: Transaction }
|
|
67
|
-
destroy: void
|
|
68
|
-
paste: { editor: Editor; event: ClipboardEvent; slice: Slice }
|
|
69
|
-
drop: { editor: Editor; event: DragEvent; slice: Slice; moved: boolean }
|
|
49
|
+
disableCollaboration: () => void
|
|
50
|
+
}
|
|
51
|
+
update: { editor: Editor; transaction: Transaction; appendedTransactions: Transaction[] }
|
|
52
|
+
selectionUpdate: { editor: Editor; transaction: Transaction }
|
|
53
|
+
beforeTransaction: { editor: Editor; transaction: Transaction; nextState: EditorState }
|
|
54
|
+
transaction: { editor: Editor; transaction: Transaction; appendedTransactions: Transaction[] }
|
|
55
|
+
focus: { editor: Editor; event: FocusEvent; transaction: Transaction }
|
|
56
|
+
blur: { editor: Editor; event: FocusEvent; transaction: Transaction }
|
|
57
|
+
destroy: void
|
|
58
|
+
paste: { editor: Editor; event: ClipboardEvent; slice: Slice }
|
|
59
|
+
drop: { editor: Editor; event: DragEvent; slice: Slice; moved: boolean }
|
|
70
60
|
}
|
|
71
61
|
|
|
72
|
-
export type EnableRules = (AnyExtension | string)[] | boolean
|
|
62
|
+
export type EnableRules = (AnyExtension | string)[] | boolean
|
|
73
63
|
|
|
74
64
|
export interface EditorOptions {
|
|
75
|
-
element: Element
|
|
76
|
-
content: Content
|
|
77
|
-
extensions: Extensions
|
|
78
|
-
injectCSS: boolean
|
|
79
|
-
injectNonce: string | undefined
|
|
80
|
-
autofocus: FocusPosition
|
|
81
|
-
editable: boolean
|
|
82
|
-
editorProps: EditorProps
|
|
83
|
-
parseOptions: ParseOptions
|
|
65
|
+
element: Element
|
|
66
|
+
content: Content
|
|
67
|
+
extensions: Extensions
|
|
68
|
+
injectCSS: boolean
|
|
69
|
+
injectNonce: string | undefined
|
|
70
|
+
autofocus: FocusPosition
|
|
71
|
+
editable: boolean
|
|
72
|
+
editorProps: EditorProps
|
|
73
|
+
parseOptions: ParseOptions
|
|
84
74
|
coreExtensionOptions?: {
|
|
85
75
|
clipboardTextSerializer?: {
|
|
86
|
-
blockSeparator?: string
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
enableInputRules: EnableRules
|
|
90
|
-
enablePasteRules: EnableRules
|
|
76
|
+
blockSeparator?: string
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
enableInputRules: EnableRules
|
|
80
|
+
enablePasteRules: EnableRules
|
|
91
81
|
/**
|
|
92
82
|
* Determines whether core extensions are enabled.
|
|
93
83
|
*
|
|
@@ -119,112 +109,164 @@ export interface EditorOptions {
|
|
|
119
109
|
| 'paste',
|
|
120
110
|
false
|
|
121
111
|
>
|
|
122
|
-
|
|
112
|
+
>
|
|
123
113
|
/**
|
|
124
114
|
* If `true`, the editor will check the content for errors on initialization.
|
|
125
115
|
* Emitting the `contentError` event if the content is invalid.
|
|
126
116
|
* Which can be used to show a warning or error message to the user.
|
|
127
117
|
* @default false
|
|
128
118
|
*/
|
|
129
|
-
enableContentCheck: boolean
|
|
130
|
-
onBeforeCreate: (props: EditorEvents['beforeCreate']) => void
|
|
131
|
-
onCreate: (props: EditorEvents['create']) => void
|
|
119
|
+
enableContentCheck: boolean
|
|
120
|
+
onBeforeCreate: (props: EditorEvents['beforeCreate']) => void
|
|
121
|
+
onCreate: (props: EditorEvents['create']) => void
|
|
132
122
|
/**
|
|
133
123
|
* Called when the editor encounters an error while parsing the content.
|
|
134
124
|
* Only enabled if `enableContentCheck` is `true`.
|
|
135
125
|
*/
|
|
136
|
-
onContentError: (props: EditorEvents['contentError']) => void
|
|
137
|
-
onUpdate: (props: EditorEvents['update']) => void
|
|
138
|
-
onSelectionUpdate: (props: EditorEvents['selectionUpdate']) => void
|
|
139
|
-
onTransaction: (props: EditorEvents['transaction']) => void
|
|
140
|
-
onFocus: (props: EditorEvents['focus']) => void
|
|
141
|
-
onBlur: (props: EditorEvents['blur']) => void
|
|
142
|
-
onDestroy: (props: EditorEvents['destroy']) => void
|
|
143
|
-
onPaste: (e: ClipboardEvent, slice: Slice) => void
|
|
144
|
-
onDrop: (e: DragEvent, slice: Slice, moved: boolean) => void
|
|
126
|
+
onContentError: (props: EditorEvents['contentError']) => void
|
|
127
|
+
onUpdate: (props: EditorEvents['update']) => void
|
|
128
|
+
onSelectionUpdate: (props: EditorEvents['selectionUpdate']) => void
|
|
129
|
+
onTransaction: (props: EditorEvents['transaction']) => void
|
|
130
|
+
onFocus: (props: EditorEvents['focus']) => void
|
|
131
|
+
onBlur: (props: EditorEvents['blur']) => void
|
|
132
|
+
onDestroy: (props: EditorEvents['destroy']) => void
|
|
133
|
+
onPaste: (e: ClipboardEvent, slice: Slice) => void
|
|
134
|
+
onDrop: (e: DragEvent, slice: Slice, moved: boolean) => void
|
|
145
135
|
}
|
|
146
136
|
|
|
147
|
-
export type HTMLContent = string
|
|
137
|
+
export type HTMLContent = string
|
|
148
138
|
|
|
149
139
|
export type JSONContent = {
|
|
150
|
-
type?: string
|
|
151
|
-
attrs?: Record<string, any
|
|
152
|
-
content?: JSONContent[]
|
|
140
|
+
type?: string
|
|
141
|
+
attrs?: Record<string, any>
|
|
142
|
+
content?: JSONContent[]
|
|
153
143
|
marks?: {
|
|
154
|
-
type: string
|
|
155
|
-
attrs?: Record<string, any
|
|
156
|
-
[key: string]: any
|
|
157
|
-
}[]
|
|
158
|
-
text?: string
|
|
159
|
-
[key: string]: any
|
|
160
|
-
}
|
|
144
|
+
type: string
|
|
145
|
+
attrs?: Record<string, any>
|
|
146
|
+
[key: string]: any
|
|
147
|
+
}[]
|
|
148
|
+
text?: string
|
|
149
|
+
[key: string]: any
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* A mark type is either a JSON representation of a mark or a Prosemirror mark instance
|
|
154
|
+
*/
|
|
155
|
+
export type MarkType<
|
|
156
|
+
Type extends string | { name: string } = any,
|
|
157
|
+
Attributes extends undefined | Record<string, any> = any,
|
|
158
|
+
> = {
|
|
159
|
+
type: Type
|
|
160
|
+
attrs: Attributes
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* A node type is either a JSON representation of a node or a Prosemirror node instance
|
|
165
|
+
*/
|
|
166
|
+
export type NodeType<
|
|
167
|
+
Type extends string | { name: string } = any,
|
|
168
|
+
Attributes extends undefined | Record<string, any> = any,
|
|
169
|
+
NodeMarkType extends MarkType = any,
|
|
170
|
+
Content extends (NodeType | TextType)[] = any,
|
|
171
|
+
> = {
|
|
172
|
+
type: Type
|
|
173
|
+
attrs: Attributes
|
|
174
|
+
content?: Content
|
|
175
|
+
marks?: NodeMarkType[]
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* A node type is either a JSON representation of a doc node or a Prosemirror doc node instance
|
|
180
|
+
*/
|
|
181
|
+
export type DocumentType<
|
|
182
|
+
TDocAttributes extends Record<string, any> | undefined = Record<string, any>,
|
|
183
|
+
TContentType extends NodeType[] = NodeType[],
|
|
184
|
+
> = Omit<NodeType<'doc', TDocAttributes, never, TContentType>, 'marks' | 'content'> & { content: TContentType }
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* A node type is either a JSON representation of a text node or a Prosemirror text node instance
|
|
188
|
+
*/
|
|
189
|
+
export type TextType<TMarkType extends MarkType = MarkType> = {
|
|
190
|
+
type: 'text'
|
|
191
|
+
text: string
|
|
192
|
+
marks: TMarkType[]
|
|
193
|
+
}
|
|
161
194
|
|
|
162
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Describes the output of a `renderHTML` function in prosemirror
|
|
197
|
+
* @see https://prosemirror.net/docs/ref/#model.DOMOutputSpec
|
|
198
|
+
*/
|
|
199
|
+
export type DOMOutputSpecArray =
|
|
200
|
+
| [string]
|
|
201
|
+
| [string, Record<string, any>]
|
|
202
|
+
| [string, 0]
|
|
203
|
+
| [string, Record<string, any>, 0]
|
|
204
|
+
| [string, Record<string, any>, DOMOutputSpecArray | 0]
|
|
205
|
+
| [string, DOMOutputSpecArray]
|
|
206
|
+
|
|
207
|
+
export type Content = HTMLContent | JSONContent | JSONContent[] | null
|
|
163
208
|
|
|
164
209
|
export type CommandProps = {
|
|
165
|
-
editor: Editor
|
|
166
|
-
tr: Transaction
|
|
167
|
-
commands: SingleCommands
|
|
168
|
-
can: () => CanCommands
|
|
169
|
-
chain: () => ChainedCommands
|
|
170
|
-
state: EditorState
|
|
171
|
-
view: EditorView
|
|
172
|
-
dispatch: ((args?: any) => any) | undefined
|
|
173
|
-
}
|
|
210
|
+
editor: Editor
|
|
211
|
+
tr: Transaction
|
|
212
|
+
commands: SingleCommands
|
|
213
|
+
can: () => CanCommands
|
|
214
|
+
chain: () => ChainedCommands
|
|
215
|
+
state: EditorState
|
|
216
|
+
view: EditorView
|
|
217
|
+
dispatch: ((args?: any) => any) | undefined
|
|
218
|
+
}
|
|
174
219
|
|
|
175
|
-
export type Command = (props: CommandProps) => boolean
|
|
220
|
+
export type Command = (props: CommandProps) => boolean
|
|
176
221
|
|
|
177
|
-
export type CommandSpec = (...args: any[]) => Command
|
|
222
|
+
export type CommandSpec = (...args: any[]) => Command
|
|
178
223
|
|
|
179
|
-
export type KeyboardShortcutCommand = (props: { editor: Editor }) => boolean
|
|
224
|
+
export type KeyboardShortcutCommand = (props: { editor: Editor }) => boolean
|
|
180
225
|
|
|
181
226
|
export type Attribute = {
|
|
182
|
-
default?: any
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
227
|
+
default?: any
|
|
228
|
+
validate?: string | ((value: any) => void)
|
|
229
|
+
rendered?: boolean
|
|
230
|
+
renderHTML?: ((attributes: Record<string, any>) => Record<string, any> | null) | null
|
|
231
|
+
parseHTML?: ((element: HTMLElement) => any | null) | null
|
|
232
|
+
keepOnSplit?: boolean
|
|
233
|
+
isRequired?: boolean
|
|
234
|
+
}
|
|
189
235
|
|
|
190
236
|
export type Attributes = {
|
|
191
|
-
[key: string]: Attribute
|
|
192
|
-
}
|
|
237
|
+
[key: string]: Attribute
|
|
238
|
+
}
|
|
193
239
|
|
|
194
240
|
export type ExtensionAttribute = {
|
|
195
|
-
type: string
|
|
196
|
-
name: string
|
|
197
|
-
attribute: Required<Attribute
|
|
198
|
-
}
|
|
241
|
+
type: string
|
|
242
|
+
name: string
|
|
243
|
+
attribute: Required<Omit<Attribute, 'validate'>> & Pick<Attribute, 'validate'>
|
|
244
|
+
}
|
|
199
245
|
|
|
200
246
|
export type GlobalAttributes = {
|
|
201
247
|
/**
|
|
202
248
|
* The node & mark types this attribute should be applied to.
|
|
203
249
|
*/
|
|
204
|
-
types: string[]
|
|
250
|
+
types: string[]
|
|
205
251
|
/**
|
|
206
252
|
* The attributes to add to the node or mark types.
|
|
207
253
|
*/
|
|
208
|
-
attributes: Record<string, Attribute | undefined
|
|
209
|
-
}[]
|
|
254
|
+
attributes: Record<string, Attribute | undefined>
|
|
255
|
+
}[]
|
|
210
256
|
|
|
211
|
-
export type PickValue<T, K extends keyof T> = T[K]
|
|
257
|
+
export type PickValue<T, K extends keyof T> = T[K]
|
|
212
258
|
|
|
213
|
-
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
214
|
-
k: infer I
|
|
215
|
-
) => void
|
|
216
|
-
? I
|
|
217
|
-
: never;
|
|
259
|
+
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
|
|
218
260
|
|
|
219
261
|
export type Diff<T extends keyof any, U extends keyof any> = ({ [P in T]: P } & {
|
|
220
|
-
[P in U]: never
|
|
221
|
-
} & { [x: string]: never })[T]
|
|
262
|
+
[P in U]: never
|
|
263
|
+
} & { [x: string]: never })[T]
|
|
222
264
|
|
|
223
|
-
export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U
|
|
265
|
+
export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U
|
|
224
266
|
|
|
225
|
-
export type ValuesOf<T> = T[keyof T]
|
|
267
|
+
export type ValuesOf<T> = T[keyof T]
|
|
226
268
|
|
|
227
|
-
export type KeysWithTypeOf<T, Type> = { [P in keyof T]: T[P] extends Type ? P : never }[keyof T]
|
|
269
|
+
export type KeysWithTypeOf<T, Type> = { [P in keyof T]: T[P] extends Type ? P : never }[keyof T]
|
|
228
270
|
|
|
229
271
|
export type DOMNode = InstanceType<typeof window.Node>
|
|
230
272
|
|
|
@@ -246,23 +288,21 @@ export interface DecorationType {
|
|
|
246
288
|
* This adds the `type` property to the `Decoration` type.
|
|
247
289
|
*/
|
|
248
290
|
export type DecorationWithType = Decoration & {
|
|
249
|
-
type: DecorationType
|
|
250
|
-
}
|
|
291
|
+
type: DecorationType
|
|
292
|
+
}
|
|
251
293
|
|
|
252
294
|
export interface NodeViewProps extends NodeViewRendererProps {
|
|
253
295
|
// TODO this type is not technically correct, but it's the best we can do for now since prosemirror doesn't expose the type of decorations
|
|
254
|
-
decorations: readonly DecorationWithType[]
|
|
255
|
-
selected: boolean
|
|
256
|
-
updateAttributes: (attributes: Record<string, any>) => void
|
|
257
|
-
deleteNode: () => void
|
|
296
|
+
decorations: readonly DecorationWithType[]
|
|
297
|
+
selected: boolean
|
|
298
|
+
updateAttributes: (attributes: Record<string, any>) => void
|
|
299
|
+
deleteNode: () => void
|
|
258
300
|
}
|
|
259
301
|
|
|
260
302
|
export interface NodeViewRendererOptions {
|
|
261
|
-
stopEvent: ((props: { event: Event }) => boolean) | null
|
|
262
|
-
ignoreMutation:
|
|
263
|
-
|
|
264
|
-
| null;
|
|
265
|
-
contentDOMElementTag: string;
|
|
303
|
+
stopEvent: ((props: { event: Event }) => boolean) | null
|
|
304
|
+
ignoreMutation: ((props: { mutation: ViewMutationRecord }) => boolean) | null
|
|
305
|
+
contentDOMElementTag: string
|
|
266
306
|
}
|
|
267
307
|
|
|
268
308
|
export interface NodeViewRendererProps {
|
|
@@ -270,100 +310,100 @@ export interface NodeViewRendererProps {
|
|
|
270
310
|
/**
|
|
271
311
|
* The node that is being rendered.
|
|
272
312
|
*/
|
|
273
|
-
node: Parameters<NodeViewConstructor>[0]
|
|
313
|
+
node: Parameters<NodeViewConstructor>[0]
|
|
274
314
|
/**
|
|
275
315
|
* The editor's view.
|
|
276
316
|
*/
|
|
277
|
-
view: Parameters<NodeViewConstructor>[1]
|
|
317
|
+
view: Parameters<NodeViewConstructor>[1]
|
|
278
318
|
/**
|
|
279
319
|
* A function that can be called to get the node's current position in the document.
|
|
280
320
|
*/
|
|
281
|
-
getPos: Parameters<NodeViewConstructor>[2]
|
|
321
|
+
getPos: Parameters<NodeViewConstructor>[2]
|
|
282
322
|
/**
|
|
283
323
|
* is an array of node or inline decorations that are active around the node.
|
|
284
324
|
* They are automatically drawn in the normal way, and you will usually just want to ignore this, but they can also be used as a way to provide context information to the node view without adding it to the document itself.
|
|
285
325
|
*/
|
|
286
|
-
decorations: Parameters<NodeViewConstructor>[3]
|
|
326
|
+
decorations: Parameters<NodeViewConstructor>[3]
|
|
287
327
|
/**
|
|
288
328
|
* holds the decorations for the node's content. You can safely ignore this if your view has no content or a contentDOM property, since the editor will draw the decorations on the content.
|
|
289
329
|
* But if you, for example, want to create a nested editor with the content, it may make sense to provide it with the inner decorations.
|
|
290
330
|
*/
|
|
291
|
-
innerDecorations: Parameters<NodeViewConstructor>[4]
|
|
331
|
+
innerDecorations: Parameters<NodeViewConstructor>[4]
|
|
292
332
|
// tiptap-specific
|
|
293
333
|
/**
|
|
294
334
|
* The editor instance.
|
|
295
335
|
*/
|
|
296
|
-
editor: Editor
|
|
336
|
+
editor: Editor
|
|
297
337
|
/**
|
|
298
338
|
* The extension that is responsible for the node.
|
|
299
339
|
*/
|
|
300
|
-
extension: Node
|
|
340
|
+
extension: Node
|
|
301
341
|
/**
|
|
302
342
|
* The HTML attributes that should be added to the node's DOM element.
|
|
303
343
|
*/
|
|
304
|
-
HTMLAttributes: Record<string, any
|
|
344
|
+
HTMLAttributes: Record<string, any>
|
|
305
345
|
}
|
|
306
346
|
|
|
307
|
-
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView
|
|
347
|
+
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView
|
|
308
348
|
|
|
309
|
-
export type AnyCommands = Record<string, (...args: any[]) => Command
|
|
349
|
+
export type AnyCommands = Record<string, (...args: any[]) => Command>
|
|
310
350
|
|
|
311
351
|
export type UnionCommands<T = Command> = UnionToIntersection<
|
|
312
|
-
ValuesOf<Pick<Commands<T>, KeysWithTypeOf<Commands<T>,
|
|
313
|
-
|
|
352
|
+
ValuesOf<Pick<Commands<T>, KeysWithTypeOf<Commands<T>, object>>>
|
|
353
|
+
>
|
|
314
354
|
|
|
315
355
|
export type RawCommands = {
|
|
316
|
-
[Item in keyof UnionCommands]: UnionCommands<Command>[Item]
|
|
317
|
-
}
|
|
356
|
+
[Item in keyof UnionCommands]: UnionCommands<Command>[Item]
|
|
357
|
+
}
|
|
318
358
|
|
|
319
359
|
export type SingleCommands = {
|
|
320
|
-
[Item in keyof UnionCommands]: UnionCommands<boolean>[Item]
|
|
321
|
-
}
|
|
360
|
+
[Item in keyof UnionCommands]: UnionCommands<boolean>[Item]
|
|
361
|
+
}
|
|
322
362
|
|
|
323
363
|
export type ChainedCommands = {
|
|
324
|
-
[Item in keyof UnionCommands]: UnionCommands<ChainedCommands>[Item]
|
|
364
|
+
[Item in keyof UnionCommands]: UnionCommands<ChainedCommands>[Item]
|
|
325
365
|
} & {
|
|
326
|
-
run: () => boolean
|
|
327
|
-
}
|
|
366
|
+
run: () => boolean
|
|
367
|
+
}
|
|
328
368
|
|
|
329
|
-
export type CanCommands = SingleCommands & { chain: () => ChainedCommands }
|
|
369
|
+
export type CanCommands = SingleCommands & { chain: () => ChainedCommands }
|
|
330
370
|
|
|
331
|
-
export type FocusPosition = 'start' | 'end' | 'all' | number | boolean | null
|
|
371
|
+
export type FocusPosition = 'start' | 'end' | 'all' | number | boolean | null
|
|
332
372
|
|
|
333
373
|
export type Range = {
|
|
334
|
-
from: number
|
|
335
|
-
to: number
|
|
336
|
-
}
|
|
374
|
+
from: number
|
|
375
|
+
to: number
|
|
376
|
+
}
|
|
337
377
|
|
|
338
378
|
export type NodeRange = {
|
|
339
|
-
node: ProseMirrorNode
|
|
340
|
-
from: number
|
|
341
|
-
to: number
|
|
342
|
-
}
|
|
379
|
+
node: ProseMirrorNode
|
|
380
|
+
from: number
|
|
381
|
+
to: number
|
|
382
|
+
}
|
|
343
383
|
|
|
344
384
|
export type MarkRange = {
|
|
345
|
-
mark: ProseMirrorMark
|
|
346
|
-
from: number
|
|
347
|
-
to: number
|
|
348
|
-
}
|
|
385
|
+
mark: ProseMirrorMark
|
|
386
|
+
from: number
|
|
387
|
+
to: number
|
|
388
|
+
}
|
|
349
389
|
|
|
350
|
-
export type Predicate = (node: ProseMirrorNode) => boolean
|
|
390
|
+
export type Predicate = (node: ProseMirrorNode) => boolean
|
|
351
391
|
|
|
352
392
|
export type NodeWithPos = {
|
|
353
|
-
node: ProseMirrorNode
|
|
354
|
-
pos: number
|
|
355
|
-
}
|
|
393
|
+
node: ProseMirrorNode
|
|
394
|
+
pos: number
|
|
395
|
+
}
|
|
356
396
|
|
|
357
397
|
export type TextSerializer = (props: {
|
|
358
|
-
node: ProseMirrorNode
|
|
359
|
-
pos: number
|
|
360
|
-
parent: ProseMirrorNode
|
|
361
|
-
index: number
|
|
362
|
-
range: Range
|
|
363
|
-
}) => string
|
|
398
|
+
node: ProseMirrorNode
|
|
399
|
+
pos: number
|
|
400
|
+
parent: ProseMirrorNode
|
|
401
|
+
index: number
|
|
402
|
+
range: Range
|
|
403
|
+
}) => string
|
|
364
404
|
|
|
365
405
|
export type ExtendedRegExpMatchArray = RegExpMatchArray & {
|
|
366
|
-
data?: Record<string, any
|
|
367
|
-
}
|
|
406
|
+
data?: Record<string, any>
|
|
407
|
+
}
|
|
368
408
|
|
|
369
|
-
export type Dispatch = ((args?: any) => any) | undefined
|
|
409
|
+
export type Dispatch = ((args?: any) => any) | undefined
|
|
@@ -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
|
}
|
|
@@ -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/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
|
}
|
|
@@ -17,14 +17,22 @@ export function mergeAttributes(...objects: Record<string, any>[]): Record<strin
|
|
|
17
17
|
const valueClasses: string[] = value ? 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
|
}
|