@tiptap/core 3.0.0-next.0 → 3.0.0-next.2
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/dist/index.cjs +4934 -4574
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3576 -0
- package/dist/index.d.ts +3576 -0
- package/dist/index.js +4839 -4481
- package/dist/index.js.map +1 -1
- package/package.json +6 -8
- package/src/Editor.ts +66 -10
- package/src/EventEmitter.ts +9 -0
- package/src/Extension.ts +4 -3
- package/src/ExtensionManager.ts +18 -12
- package/src/InputRule.ts +45 -30
- package/src/Mark.ts +4 -3
- package/src/Node.ts +23 -3
- package/src/NodePos.ts +9 -4
- package/src/NodeView.ts +43 -12
- package/src/PasteRule.ts +96 -42
- package/src/commands/focus.ts +1 -6
- package/src/commands/insertContent.ts +9 -9
- package/src/commands/insertContentAt.ts +23 -3
- package/src/commands/selectAll.ts +10 -5
- package/src/commands/setContent.ts +10 -14
- package/src/commands/setMeta.ts +3 -1
- package/src/commands/setNode.ts +9 -2
- package/src/commands/splitListItem.ts +27 -17
- package/src/commands/toggleNode.ts +11 -2
- package/src/commands/updateAttributes.ts +72 -12
- package/src/extensions/drop.ts +26 -0
- package/src/extensions/index.ts +2 -0
- package/src/extensions/keymap.ts +5 -2
- package/src/extensions/paste.ts +26 -0
- package/src/helpers/createDocument.ts +4 -2
- package/src/helpers/createNodeFromContent.ts +11 -2
- package/src/helpers/getAttributesFromExtensions.ts +1 -1
- package/src/helpers/getMarkRange.ts +35 -8
- package/src/helpers/getMarksBetween.ts +1 -1
- package/src/helpers/getRenderedAttributes.ts +3 -0
- package/src/helpers/getSchemaByResolvedExtensions.ts +3 -2
- package/src/helpers/isList.ts +1 -1
- package/src/helpers/isNodeEmpty.ts +33 -12
- package/src/inputRules/markInputRule.ts +1 -1
- package/src/inputRules/nodeInputRule.ts +1 -1
- package/src/inputRules/textInputRule.ts +1 -1
- package/src/inputRules/textblockTypeInputRule.ts +1 -1
- package/src/inputRules/wrappingInputRule.ts +1 -1
- package/src/pasteRules/markPasteRule.ts +1 -1
- package/src/pasteRules/nodePasteRule.ts +15 -6
- package/src/pasteRules/textPasteRule.ts +1 -1
- package/src/style.ts +2 -2
- package/src/types.ts +107 -19
- package/src/utilities/mergeAttributes.ts +18 -1
- package/dist/index.umd.js +0 -5130
- package/dist/index.umd.js.map +0 -1
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -159
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -343
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -451
- package/dist/packages/core/src/Node.d.ts +0 -611
- package/dist/packages/core/src/NodePos.d.ts +0 -44
- package/dist/packages/core/src/NodeView.d.ts +0 -31
- package/dist/packages/core/src/PasteRule.d.ts +0 -50
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -13
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
- package/dist/packages/core/src/commands/command.d.ts +0 -18
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
- package/dist/packages/core/src/commands/cut.d.ts +0 -20
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
- package/dist/packages/core/src/commands/enter.d.ts +0 -13
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
- package/dist/packages/core/src/commands/first.d.ts +0 -14
- package/dist/packages/core/src/commands/focus.d.ts +0 -27
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -55
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
- package/dist/packages/core/src/commands/join.d.ts +0 -41
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
- package/dist/packages/core/src/commands/lift.d.ts +0 -17
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
- package/dist/packages/core/src/commands/setContent.d.ts +0 -40
- package/dist/packages/core/src/commands/setMark.d.ts +0 -15
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
- package/dist/packages/core/src/commands/setNode.d.ts +0 -16
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
- package/dist/packages/core/src/extensions/commands.d.ts +0 -3
- 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 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
- package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
- 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/getNodeAtPosition.d.ts +0 -11
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
- 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 -4
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getText.d.ts +0 -15
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
- package/dist/packages/core/src/helpers/index.d.ts +0 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
- package/dist/packages/core/src/helpers/isList.d.ts +0 -2
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -8
- 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/posToDOMRect.d.ts +0 -2
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
- 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 -24
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -253
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
- package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/index.d.ts +0 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
- package/dist/packages/core/src/utilities/isString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
package/src/types.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Mark as ProseMirrorMark,
|
|
3
3
|
Node as ProseMirrorNode,
|
|
4
|
-
NodeType,
|
|
5
4
|
ParseOptions,
|
|
5
|
+
Slice,
|
|
6
6
|
} from '@tiptap/pm/model'
|
|
7
7
|
import { EditorState, Transaction } from '@tiptap/pm/state'
|
|
8
|
+
import { Mappable } from '@tiptap/pm/transform'
|
|
8
9
|
import {
|
|
9
|
-
Decoration,
|
|
10
|
+
Decoration,
|
|
11
|
+
DecorationAttrs,
|
|
12
|
+
EditorProps,
|
|
13
|
+
EditorView,
|
|
14
|
+
NodeView,
|
|
15
|
+
NodeViewConstructor,
|
|
16
|
+
ViewMutationRecord,
|
|
10
17
|
} from '@tiptap/pm/view'
|
|
11
18
|
|
|
12
19
|
import { Editor } from './Editor.js'
|
|
@@ -58,6 +65,8 @@ export interface EditorEvents {
|
|
|
58
65
|
focus: { editor: Editor; event: FocusEvent; transaction: Transaction };
|
|
59
66
|
blur: { editor: Editor; event: FocusEvent; transaction: Transaction };
|
|
60
67
|
destroy: void;
|
|
68
|
+
paste: { editor: Editor; event: ClipboardEvent; slice: Slice };
|
|
69
|
+
drop: { editor: Editor; event: DragEvent; slice: Slice; moved: boolean };
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
export type EnableRules = (AnyExtension | string)[] | boolean;
|
|
@@ -79,7 +88,38 @@ export interface EditorOptions {
|
|
|
79
88
|
};
|
|
80
89
|
enableInputRules: EnableRules;
|
|
81
90
|
enablePasteRules: EnableRules;
|
|
82
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Determines whether core extensions are enabled.
|
|
93
|
+
*
|
|
94
|
+
* If set to `false`, all core extensions will be disabled.
|
|
95
|
+
* To disable specific core extensions, provide an object where the keys are the extension names and the values are `false`.
|
|
96
|
+
* Extensions not listed in the object will remain enabled.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* // Disable all core extensions
|
|
100
|
+
* enabledCoreExtensions: false
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* // Disable only the keymap core extension
|
|
104
|
+
* enabledCoreExtensions: { keymap: false }
|
|
105
|
+
*
|
|
106
|
+
* @default true
|
|
107
|
+
*/
|
|
108
|
+
enableCoreExtensions?:
|
|
109
|
+
| boolean
|
|
110
|
+
| Partial<
|
|
111
|
+
Record<
|
|
112
|
+
| 'editable'
|
|
113
|
+
| 'clipboardTextSerializer'
|
|
114
|
+
| 'commands'
|
|
115
|
+
| 'focusEvents'
|
|
116
|
+
| 'keymap'
|
|
117
|
+
| 'tabindex'
|
|
118
|
+
| 'drop'
|
|
119
|
+
| 'paste',
|
|
120
|
+
false
|
|
121
|
+
>
|
|
122
|
+
>;
|
|
83
123
|
/**
|
|
84
124
|
* If `true`, the editor will check the content for errors on initialization.
|
|
85
125
|
* Emitting the `contentError` event if the content is invalid.
|
|
@@ -100,6 +140,8 @@ export interface EditorOptions {
|
|
|
100
140
|
onFocus: (props: EditorEvents['focus']) => void;
|
|
101
141
|
onBlur: (props: EditorEvents['blur']) => void;
|
|
102
142
|
onDestroy: (props: EditorEvents['destroy']) => void;
|
|
143
|
+
onPaste: (e: ClipboardEvent, slice: Slice) => void;
|
|
144
|
+
onDrop: (e: DragEvent, slice: Slice, moved: boolean) => void;
|
|
103
145
|
}
|
|
104
146
|
|
|
105
147
|
export type HTMLContent = string;
|
|
@@ -184,39 +226,85 @@ export type ValuesOf<T> = T[keyof T];
|
|
|
184
226
|
|
|
185
227
|
export type KeysWithTypeOf<T, Type> = { [P in keyof T]: T[P] extends Type ? P : never }[keyof T];
|
|
186
228
|
|
|
229
|
+
export type DOMNode = InstanceType<typeof window.Node>
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* prosemirror-view does not export the `type` property of `Decoration`.
|
|
233
|
+
* So, this defines the `DecorationType` interface to include the `type` property.
|
|
234
|
+
*/
|
|
235
|
+
export interface DecorationType {
|
|
236
|
+
spec: any
|
|
237
|
+
map(mapping: Mappable, span: Decoration, offset: number, oldOffset: number): Decoration | null
|
|
238
|
+
valid(node: Node, span: Decoration): boolean
|
|
239
|
+
eq(other: DecorationType): boolean
|
|
240
|
+
destroy(dom: DOMNode): void
|
|
241
|
+
readonly attrs: DecorationAttrs
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* prosemirror-view does not export the `type` property of `Decoration`.
|
|
246
|
+
* This adds the `type` property to the `Decoration` type.
|
|
247
|
+
*/
|
|
187
248
|
export type DecorationWithType = Decoration & {
|
|
188
|
-
type:
|
|
249
|
+
type: DecorationType;
|
|
189
250
|
};
|
|
190
251
|
|
|
191
|
-
export
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
decorations: DecorationWithType[];
|
|
252
|
+
export interface NodeViewProps extends NodeViewRendererProps {
|
|
253
|
+
// 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[];
|
|
195
255
|
selected: boolean;
|
|
196
|
-
extension: Node;
|
|
197
|
-
getPos: () => number;
|
|
198
256
|
updateAttributes: (attributes: Record<string, any>) => void;
|
|
199
257
|
deleteNode: () => void;
|
|
200
|
-
}
|
|
258
|
+
}
|
|
201
259
|
|
|
202
260
|
export interface NodeViewRendererOptions {
|
|
203
261
|
stopEvent: ((props: { event: Event }) => boolean) | null;
|
|
204
262
|
ignoreMutation:
|
|
205
|
-
| ((props: { mutation:
|
|
263
|
+
| ((props: { mutation: ViewMutationRecord }) => boolean)
|
|
206
264
|
| null;
|
|
207
265
|
contentDOMElementTag: string;
|
|
208
266
|
}
|
|
209
267
|
|
|
210
|
-
export
|
|
268
|
+
export interface NodeViewRendererProps {
|
|
269
|
+
// pass-through from prosemirror
|
|
270
|
+
/**
|
|
271
|
+
* The node that is being rendered.
|
|
272
|
+
*/
|
|
273
|
+
node: Parameters<NodeViewConstructor>[0];
|
|
274
|
+
/**
|
|
275
|
+
* The editor's view.
|
|
276
|
+
*/
|
|
277
|
+
view: Parameters<NodeViewConstructor>[1];
|
|
278
|
+
/**
|
|
279
|
+
* A function that can be called to get the node's current position in the document.
|
|
280
|
+
*/
|
|
281
|
+
getPos: Parameters<NodeViewConstructor>[2];
|
|
282
|
+
/**
|
|
283
|
+
* is an array of node or inline decorations that are active around the node.
|
|
284
|
+
* 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
|
+
*/
|
|
286
|
+
decorations: Parameters<NodeViewConstructor>[3];
|
|
287
|
+
/**
|
|
288
|
+
* 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
|
+
* 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
|
+
*/
|
|
291
|
+
innerDecorations: Parameters<NodeViewConstructor>[4];
|
|
292
|
+
// tiptap-specific
|
|
293
|
+
/**
|
|
294
|
+
* The editor instance.
|
|
295
|
+
*/
|
|
211
296
|
editor: Editor;
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
decorations: Decoration[];
|
|
297
|
+
/**
|
|
298
|
+
* The extension that is responsible for the node.
|
|
299
|
+
*/
|
|
216
300
|
extension: Node;
|
|
217
|
-
|
|
301
|
+
/**
|
|
302
|
+
* The HTML attributes that should be added to the node's DOM element.
|
|
303
|
+
*/
|
|
304
|
+
HTMLAttributes: Record<string, any>;
|
|
305
|
+
}
|
|
218
306
|
|
|
219
|
-
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView
|
|
307
|
+
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView;
|
|
220
308
|
|
|
221
309
|
export type AnyCommands = Record<string, (...args: any[]) => Command>;
|
|
222
310
|
|
|
@@ -23,7 +23,24 @@ export function mergeAttributes(...objects: Record<string, any>[]): Record<strin
|
|
|
23
23
|
|
|
24
24
|
mergedAttributes[key] = [...existingClasses, ...insertClasses].join(' ')
|
|
25
25
|
} else if (key === 'style') {
|
|
26
|
-
|
|
26
|
+
const newStyles: string[] = value ? value.split(';').map((style: string) => style.trim()).filter(Boolean) : []
|
|
27
|
+
const existingStyles: string[] = mergedAttributes[key] ? mergedAttributes[key].split(';').map((style: string) => style.trim()).filter(Boolean) : []
|
|
28
|
+
|
|
29
|
+
const styleMap = new Map<string, string>()
|
|
30
|
+
|
|
31
|
+
existingStyles.forEach(style => {
|
|
32
|
+
const [property, val] = style.split(':').map(part => part.trim())
|
|
33
|
+
|
|
34
|
+
styleMap.set(property, val)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
newStyles.forEach(style => {
|
|
38
|
+
const [property, val] = style.split(':').map(part => part.trim())
|
|
39
|
+
|
|
40
|
+
styleMap.set(property, val)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
mergedAttributes[key] = Array.from(styleMap.entries()).map(([property, val]) => `${property}: ${val}`).join('; ')
|
|
27
44
|
} else {
|
|
28
45
|
mergedAttributes[key] = value
|
|
29
46
|
}
|