@tiptap/core 2.5.0-beta.1 → 2.5.0-beta.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.
@@ -126,11 +126,11 @@ export declare type KeyboardShortcutCommand = (props: {
126
126
  editor: Editor;
127
127
  }) => boolean;
128
128
  export declare type Attribute = {
129
- default: any;
129
+ default?: any;
130
130
  rendered?: boolean;
131
131
  renderHTML?: ((attributes: Record<string, any>) => Record<string, any> | null) | null;
132
132
  parseHTML?: ((element: HTMLElement) => any | null) | null;
133
- keepOnSplit: boolean;
133
+ keepOnSplit?: boolean;
134
134
  isRequired?: boolean;
135
135
  };
136
136
  export declare type Attributes = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/core",
3
3
  "description": "headless rich text editor",
4
- "version": "2.5.0-beta.1",
4
+ "version": "2.5.0-beta.2",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -32,7 +32,7 @@
32
32
  "dist"
33
33
  ],
34
34
  "devDependencies": {
35
- "@tiptap/pm": "^2.5.0-beta.1"
35
+ "@tiptap/pm": "^2.5.0-beta.2"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@tiptap/pm": "^2.0.0"
@@ -1,4 +1,7 @@
1
- import { MarkType, NodeType } from '@tiptap/pm/model'
1
+ import {
2
+ Mark, MarkType, Node, NodeType,
3
+ } from '@tiptap/pm/model'
4
+ import { SelectionRange } from '@tiptap/pm/state'
2
5
 
3
6
  import { getMarkType } from '../helpers/getMarkType.js'
4
7
  import { getNodeType } from '../helpers/getNodeType.js'
@@ -51,37 +54,49 @@ export const updateAttributes: RawCommands['updateAttributes'] = (typeOrName, at
51
54
  }
52
55
 
53
56
  if (dispatch) {
54
- tr.selection.ranges.forEach(range => {
57
+ let lastPos: number | undefined
58
+ let lastNode: Node | undefined
59
+ let trimmedFrom: number
60
+ let trimmedTo: number
61
+
62
+ tr.selection.ranges.forEach((range: SelectionRange) => {
55
63
  const from = range.$from.pos
56
64
  const to = range.$to.pos
57
65
 
58
- state.doc.nodesBetween(from, to, (node, pos) => {
66
+ state.doc.nodesBetween(from, to, (node: Node, pos: number) => {
59
67
  if (nodeType && nodeType === node.type) {
60
- tr.setNodeMarkup(pos, undefined, {
61
- ...node.attrs,
62
- ...attributes,
63
- })
64
- }
65
-
66
- if (markType && node.marks.length) {
67
- node.marks.forEach(mark => {
68
- if (markType === mark.type) {
69
- const trimmedFrom = Math.max(pos, from)
70
- const trimmedTo = Math.min(pos + node.nodeSize, to)
71
-
72
- tr.addMark(
73
- trimmedFrom,
74
- trimmedTo,
75
- markType.create({
76
- ...mark.attrs,
77
- ...attributes,
78
- }),
79
- )
80
- }
81
- })
68
+ trimmedFrom = Math.max(pos, from)
69
+ trimmedTo = Math.min(pos + node.nodeSize, to)
70
+ lastPos = pos
71
+ lastNode = node
82
72
  }
83
73
  })
84
74
  })
75
+
76
+ if (lastNode) {
77
+
78
+ if (lastPos !== undefined) {
79
+ tr.setNodeMarkup(lastPos, undefined, {
80
+ ...lastNode.attrs,
81
+ ...attributes,
82
+ })
83
+ }
84
+
85
+ if (markType && lastNode.marks.length) {
86
+ lastNode.marks.forEach((mark: Mark) => {
87
+ if (markType === mark.type) {
88
+ tr.addMark(
89
+ trimmedFrom,
90
+ trimmedTo,
91
+ markType.create({
92
+ ...mark.attrs,
93
+ ...attributes,
94
+ }),
95
+ )
96
+ }
97
+ })
98
+ }
99
+ }
85
100
  }
86
101
 
87
102
  return true
package/src/types.ts CHANGED
@@ -133,11 +133,11 @@ export type CommandSpec = (...args: any[]) => Command
133
133
  export type KeyboardShortcutCommand = (props: { editor: Editor }) => boolean
134
134
 
135
135
  export type Attribute = {
136
- default: any
136
+ default?: any
137
137
  rendered?: boolean
138
138
  renderHTML?: ((attributes: Record<string, any>) => Record<string, any> | null) | null
139
139
  parseHTML?: ((element: HTMLElement) => any | null) | null
140
- keepOnSplit: boolean
140
+ keepOnSplit?: boolean
141
141
  isRequired?: boolean
142
142
  }
143
143