@tiptap/extension-task-item
Advanced tools
Comparing version 2.0.0-beta.32 to 2.0.0-beta.35
import { Node } from '@tiptap/core'; | ||
import { Node as ProseMirrorNode } from 'prosemirror-model'; | ||
export interface TaskItemOptions { | ||
onReadOnlyChecked?: (node: ProseMirrorNode, checked: boolean) => boolean; | ||
nested: boolean; | ||
@@ -4,0 +6,0 @@ HTMLAttributes: Record<string, any>; |
@@ -43,3 +43,5 @@ 'use strict'; | ||
'li', | ||
core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { 'data-type': this.name }), | ||
core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { | ||
'data-type': this.name, | ||
}), | ||
[ | ||
@@ -51,5 +53,3 @@ 'label', | ||
type: 'checkbox', | ||
checked: node.attrs.checked | ||
? 'checked' | ||
: null, | ||
checked: node.attrs.checked ? 'checked' : null, | ||
}, | ||
@@ -59,6 +59,3 @@ ], | ||
], | ||
[ | ||
'div', | ||
0, | ||
], | ||
['div', 0], | ||
]; | ||
@@ -89,5 +86,5 @@ }, | ||
checkbox.addEventListener('change', event => { | ||
// if the editor isn’t editable | ||
// we have to undo the latest change | ||
if (!editor.isEditable) { | ||
// if the editor isn’t editable and we don't have a handler for | ||
// readonly checks we have to undo the latest change | ||
if (!editor.isEditable && !this.options.onReadOnlyChecked) { | ||
checkbox.checked = !checkbox.checked; | ||
@@ -112,2 +109,8 @@ return; | ||
} | ||
if (!editor.isEditable && this.options.onReadOnlyChecked) { | ||
// Reset state if onReadOnlyChecked returns false | ||
if (!this.options.onReadOnlyChecked(node, checked)) { | ||
checkbox.checked = !checkbox.checked; | ||
} | ||
} | ||
}); | ||
@@ -123,5 +126,3 @@ Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => { | ||
listItem.append(checkboxWrapper, content); | ||
Object | ||
.entries(HTMLAttributes) | ||
.forEach(([key, value]) => { | ||
Object.entries(HTMLAttributes).forEach(([key, value]) => { | ||
listItem.setAttribute(key, value); | ||
@@ -128,0 +129,0 @@ }); |
@@ -39,3 +39,5 @@ import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core'; | ||
'li', | ||
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { 'data-type': this.name }), | ||
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { | ||
'data-type': this.name, | ||
}), | ||
[ | ||
@@ -47,5 +49,3 @@ 'label', | ||
type: 'checkbox', | ||
checked: node.attrs.checked | ||
? 'checked' | ||
: null, | ||
checked: node.attrs.checked ? 'checked' : null, | ||
}, | ||
@@ -55,6 +55,3 @@ ], | ||
], | ||
[ | ||
'div', | ||
0, | ||
], | ||
['div', 0], | ||
]; | ||
@@ -85,5 +82,5 @@ }, | ||
checkbox.addEventListener('change', event => { | ||
// if the editor isn’t editable | ||
// we have to undo the latest change | ||
if (!editor.isEditable) { | ||
// if the editor isn’t editable and we don't have a handler for | ||
// readonly checks we have to undo the latest change | ||
if (!editor.isEditable && !this.options.onReadOnlyChecked) { | ||
checkbox.checked = !checkbox.checked; | ||
@@ -108,2 +105,8 @@ return; | ||
} | ||
if (!editor.isEditable && this.options.onReadOnlyChecked) { | ||
// Reset state if onReadOnlyChecked returns false | ||
if (!this.options.onReadOnlyChecked(node, checked)) { | ||
checkbox.checked = !checkbox.checked; | ||
} | ||
} | ||
}); | ||
@@ -119,5 +122,3 @@ Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => { | ||
listItem.append(checkboxWrapper, content); | ||
Object | ||
.entries(HTMLAttributes) | ||
.forEach(([key, value]) => { | ||
Object.entries(HTMLAttributes).forEach(([key, value]) => { | ||
listItem.setAttribute(key, value); | ||
@@ -124,0 +125,0 @@ }); |
@@ -43,3 +43,5 @@ (function (global, factory) { | ||
'li', | ||
core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { 'data-type': this.name }), | ||
core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { | ||
'data-type': this.name, | ||
}), | ||
[ | ||
@@ -51,5 +53,3 @@ 'label', | ||
type: 'checkbox', | ||
checked: node.attrs.checked | ||
? 'checked' | ||
: null, | ||
checked: node.attrs.checked ? 'checked' : null, | ||
}, | ||
@@ -59,6 +59,3 @@ ], | ||
], | ||
[ | ||
'div', | ||
0, | ||
], | ||
['div', 0], | ||
]; | ||
@@ -89,5 +86,5 @@ }, | ||
checkbox.addEventListener('change', event => { | ||
// if the editor isn’t editable | ||
// we have to undo the latest change | ||
if (!editor.isEditable) { | ||
// if the editor isn’t editable and we don't have a handler for | ||
// readonly checks we have to undo the latest change | ||
if (!editor.isEditable && !this.options.onReadOnlyChecked) { | ||
checkbox.checked = !checkbox.checked; | ||
@@ -112,2 +109,8 @@ return; | ||
} | ||
if (!editor.isEditable && this.options.onReadOnlyChecked) { | ||
// Reset state if onReadOnlyChecked returns false | ||
if (!this.options.onReadOnlyChecked(node, checked)) { | ||
checkbox.checked = !checkbox.checked; | ||
} | ||
} | ||
}); | ||
@@ -123,5 +126,3 @@ Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => { | ||
listItem.append(checkboxWrapper, content); | ||
Object | ||
.entries(HTMLAttributes) | ||
.forEach(([key, value]) => { | ||
Object.entries(HTMLAttributes).forEach(([key, value]) => { | ||
listItem.setAttribute(key, value); | ||
@@ -128,0 +129,0 @@ }); |
{ | ||
"name": "@tiptap/extension-task-item", | ||
"description": "task item extension for tiptap", | ||
"version": "2.0.0-beta.32", | ||
"version": "2.0.0-beta.35", | ||
"homepage": "https://tiptap.dev", | ||
@@ -24,3 +24,4 @@ "keywords": [ | ||
"peerDependencies": { | ||
"@tiptap/core": "^2.0.0-beta.1" | ||
"@tiptap/core": "^2.0.0-beta.1", | ||
"prosemirror-model": "^1.16.1" | ||
}, | ||
@@ -32,3 +33,3 @@ "repository": { | ||
}, | ||
"gitHead": "90e719c711dbccae6a7333956d543fb93789f3d3" | ||
"gitHead": "591c0807a2ab5c34b4b7fe12c12511fe4f493ebd" | ||
} |
@@ -1,6 +0,8 @@ | ||
import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core' | ||
import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core' | ||
import { Node as ProseMirrorNode } from 'prosemirror-model' | ||
export interface TaskItemOptions { | ||
nested: boolean, | ||
HTMLAttributes: Record<string, any>, | ||
onReadOnlyChecked?: (node: ProseMirrorNode, checked: boolean) => boolean | ||
nested: boolean | ||
HTMLAttributes: Record<string, any> | ||
} | ||
@@ -51,7 +53,5 @@ | ||
'li', | ||
mergeAttributes( | ||
this.options.HTMLAttributes, | ||
HTMLAttributes, | ||
{ 'data-type': this.name }, | ||
), | ||
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { | ||
'data-type': this.name, | ||
}), | ||
[ | ||
@@ -63,5 +63,3 @@ 'label', | ||
type: 'checkbox', | ||
checked: node.attrs.checked | ||
? 'checked' | ||
: null, | ||
checked: node.attrs.checked ? 'checked' : null, | ||
}, | ||
@@ -71,6 +69,3 @@ ], | ||
], | ||
[ | ||
'div', | ||
0, | ||
], | ||
['div', 0], | ||
] | ||
@@ -97,6 +92,3 @@ }, | ||
return ({ | ||
node, | ||
HTMLAttributes, | ||
getPos, | ||
editor, | ||
node, HTMLAttributes, getPos, editor, | ||
}) => { | ||
@@ -112,5 +104,5 @@ const listItem = document.createElement('li') | ||
checkbox.addEventListener('change', event => { | ||
// if the editor isn’t editable | ||
// we have to undo the latest change | ||
if (!editor.isEditable) { | ||
// if the editor isn’t editable and we don't have a handler for | ||
// readonly checks we have to undo the latest change | ||
if (!editor.isEditable && !this.options.onReadOnlyChecked) { | ||
checkbox.checked = !checkbox.checked | ||
@@ -140,2 +132,8 @@ | ||
} | ||
if (!editor.isEditable && this.options.onReadOnlyChecked) { | ||
// Reset state if onReadOnlyChecked returns false | ||
if (!this.options.onReadOnlyChecked(node, checked)) { | ||
checkbox.checked = !checkbox.checked | ||
} | ||
} | ||
}) | ||
@@ -155,7 +153,5 @@ | ||
Object | ||
.entries(HTMLAttributes) | ||
.forEach(([key, value]) => { | ||
listItem.setAttribute(key, value) | ||
}) | ||
Object.entries(HTMLAttributes).forEach(([key, value]) => { | ||
listItem.setAttribute(key, value) | ||
}) | ||
@@ -162,0 +158,0 @@ return { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54747
636
2