@tiptap/extension-list 3.15.1 → 3.15.3

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.
@@ -1,5 +1,11 @@
1
1
  import type { KeyboardShortcutCommand } from '@tiptap/core'
2
- import { mergeAttributes, Node, renderNestedMarkdownContent, wrappingInputRule } from '@tiptap/core'
2
+ import {
3
+ getRenderedAttributes,
4
+ mergeAttributes,
5
+ Node,
6
+ renderNestedMarkdownContent,
7
+ wrappingInputRule,
8
+ } from '@tiptap/core'
3
9
  import type { Node as ProseMirrorNode } from '@tiptap/pm/model'
4
10
 
5
11
  export interface TaskItemOptions {
@@ -243,6 +249,9 @@ export const TaskItem = Node.create<TaskItemOptions>({
243
249
  listItem.setAttribute(key, value)
244
250
  })
245
251
 
252
+ // Track the keys of previously rendered HTML attributes for proper removal
253
+ let prevRenderedAttributeKeys = new Set(Object.keys(HTMLAttributes))
254
+
246
255
  return {
247
256
  dom: listItem,
248
257
  contentDOM: content,
@@ -255,6 +264,42 @@ export const TaskItem = Node.create<TaskItemOptions>({
255
264
  checkbox.checked = updatedNode.attrs.checked
256
265
  updateA11Y(updatedNode)
257
266
 
267
+ // Sync all HTML attributes from the updated node
268
+ const extensionAttributes = editor.extensionManager.attributes
269
+ const newHTMLAttributes = getRenderedAttributes(updatedNode, extensionAttributes)
270
+ const newKeys = new Set(Object.keys(newHTMLAttributes))
271
+
272
+ // Remove attributes that were previously rendered but are no longer present
273
+ // If the attribute exists in static options, restore it instead of removing
274
+ const staticAttrs = this.options.HTMLAttributes
275
+
276
+ prevRenderedAttributeKeys.forEach(key => {
277
+ if (!newKeys.has(key)) {
278
+ if (key in staticAttrs) {
279
+ listItem.setAttribute(key, staticAttrs[key])
280
+ } else {
281
+ listItem.removeAttribute(key)
282
+ }
283
+ }
284
+ })
285
+
286
+ // Update or add new attributes
287
+ Object.entries(newHTMLAttributes).forEach(([key, value]) => {
288
+ if (value === null || value === undefined) {
289
+ // If the attribute exists in static options, restore it instead of removing
290
+ if (key in staticAttrs) {
291
+ listItem.setAttribute(key, staticAttrs[key])
292
+ } else {
293
+ listItem.removeAttribute(key)
294
+ }
295
+ } else {
296
+ listItem.setAttribute(key, value)
297
+ }
298
+ })
299
+
300
+ // Update the tracked keys for next update
301
+ prevRenderedAttributeKeys = newKeys
302
+
258
303
  return true
259
304
  },
260
305
  }