@tiptap/extension-task-item
Advanced tools
Comparing version 3.0.0-next.4 to 3.0.0-next.5
@@ -1,41 +0,2 @@ | ||
import { Node as Node$1 } from '@tiptap/core'; | ||
import { Node } from '@tiptap/pm/model'; | ||
interface TaskItemOptions { | ||
/** | ||
* A callback function that is called when the checkbox is clicked while the editor is in readonly mode. | ||
* @param node The prosemirror node of the task item | ||
* @param checked The new checked state | ||
* @returns boolean | ||
*/ | ||
onReadOnlyChecked?: (node: Node, checked: boolean) => boolean; | ||
/** | ||
* Controls whether the task items can be nested or not. | ||
* @default false | ||
* @example true | ||
*/ | ||
nested: boolean; | ||
/** | ||
* HTML attributes to add to the task item element. | ||
* @default {} | ||
* @example { class: 'foo' } | ||
*/ | ||
HTMLAttributes: Record<string, any>; | ||
/** | ||
* The node type for taskList nodes | ||
* @default 'taskList' | ||
* @example 'myCustomTaskList' | ||
*/ | ||
taskListTypeName: string; | ||
} | ||
/** | ||
* Matches a task item to a - [ ] on input. | ||
*/ | ||
declare const inputRegex: RegExp; | ||
/** | ||
* This extension allows you to create task items. | ||
* @see https://www.tiptap.dev/api/nodes/task-item | ||
*/ | ||
declare const TaskItem: Node$1<TaskItemOptions, any>; | ||
export { TaskItem, type TaskItemOptions, TaskItem as default, inputRegex }; | ||
import { TaskItem } from '@tiptap/extension-list'; | ||
export { TaskItem, TaskItemOptions, TaskItem as default } from '@tiptap/extension-list'; |
@@ -1,153 +0,10 @@ | ||
// src/task-item.ts | ||
import { mergeAttributes, Node, wrappingInputRule } from "@tiptap/core"; | ||
var inputRegex = /^\s*(\[([( |x])?\])\s$/; | ||
var TaskItem = Node.create({ | ||
name: "taskItem", | ||
addOptions() { | ||
return { | ||
nested: false, | ||
HTMLAttributes: {}, | ||
taskListTypeName: "taskList" | ||
}; | ||
}, | ||
content() { | ||
return this.options.nested ? "paragraph block*" : "paragraph+"; | ||
}, | ||
defining: true, | ||
addAttributes() { | ||
return { | ||
checked: { | ||
default: false, | ||
keepOnSplit: false, | ||
parseHTML: (element) => { | ||
const dataChecked = element.getAttribute("data-checked"); | ||
return dataChecked === "" || dataChecked === "true"; | ||
}, | ||
renderHTML: (attributes) => ({ | ||
"data-checked": attributes.checked | ||
}) | ||
} | ||
}; | ||
}, | ||
parseHTML() { | ||
return [ | ||
{ | ||
tag: `li[data-type="${this.name}"]`, | ||
priority: 51 | ||
} | ||
]; | ||
}, | ||
renderHTML({ node, HTMLAttributes }) { | ||
return [ | ||
"li", | ||
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { | ||
"data-type": this.name | ||
}), | ||
[ | ||
"label", | ||
[ | ||
"input", | ||
{ | ||
type: "checkbox", | ||
checked: node.attrs.checked ? "checked" : null | ||
} | ||
], | ||
["span"] | ||
], | ||
["div", 0] | ||
]; | ||
}, | ||
addKeyboardShortcuts() { | ||
const shortcuts = { | ||
Enter: () => this.editor.commands.splitListItem(this.name), | ||
"Shift-Tab": () => this.editor.commands.liftListItem(this.name) | ||
}; | ||
if (!this.options.nested) { | ||
return shortcuts; | ||
} | ||
return { | ||
...shortcuts, | ||
Tab: () => this.editor.commands.sinkListItem(this.name) | ||
}; | ||
}, | ||
addNodeView() { | ||
return ({ node, HTMLAttributes, getPos, editor }) => { | ||
const listItem = document.createElement("li"); | ||
const checkboxWrapper = document.createElement("label"); | ||
const checkboxStyler = document.createElement("span"); | ||
const checkbox = document.createElement("input"); | ||
const content = document.createElement("div"); | ||
checkboxWrapper.contentEditable = "false"; | ||
checkbox.type = "checkbox"; | ||
checkbox.addEventListener("mousedown", (event) => event.preventDefault()); | ||
checkbox.addEventListener("change", (event) => { | ||
if (!editor.isEditable && !this.options.onReadOnlyChecked) { | ||
checkbox.checked = !checkbox.checked; | ||
return; | ||
} | ||
const { checked } = event.target; | ||
if (editor.isEditable && typeof getPos === "function") { | ||
editor.chain().focus(void 0, { scrollIntoView: false }).command(({ tr }) => { | ||
const position = getPos(); | ||
if (typeof position !== "number") { | ||
return false; | ||
} | ||
const currentNode = tr.doc.nodeAt(position); | ||
tr.setNodeMarkup(position, void 0, { | ||
...currentNode == null ? void 0 : currentNode.attrs, | ||
checked | ||
}); | ||
return true; | ||
}).run(); | ||
} | ||
if (!editor.isEditable && this.options.onReadOnlyChecked) { | ||
if (!this.options.onReadOnlyChecked(node, checked)) { | ||
checkbox.checked = !checkbox.checked; | ||
} | ||
} | ||
}); | ||
Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => { | ||
listItem.setAttribute(key, value); | ||
}); | ||
listItem.dataset.checked = node.attrs.checked; | ||
checkbox.checked = node.attrs.checked; | ||
checkboxWrapper.append(checkbox, checkboxStyler); | ||
listItem.append(checkboxWrapper, content); | ||
Object.entries(HTMLAttributes).forEach(([key, value]) => { | ||
listItem.setAttribute(key, value); | ||
}); | ||
return { | ||
dom: listItem, | ||
contentDOM: content, | ||
update: (updatedNode) => { | ||
if (updatedNode.type !== this.type) { | ||
return false; | ||
} | ||
listItem.dataset.checked = updatedNode.attrs.checked; | ||
checkbox.checked = updatedNode.attrs.checked; | ||
return true; | ||
} | ||
}; | ||
}; | ||
}, | ||
addInputRules() { | ||
return [ | ||
wrappingInputRule({ | ||
find: inputRegex, | ||
type: this.type, | ||
getAttributes: (match) => ({ | ||
checked: match[match.length - 1] === "x" | ||
}) | ||
}) | ||
]; | ||
} | ||
}); | ||
// src/index.ts | ||
import { TaskItem } from "@tiptap/extension-list"; | ||
import { TaskItem as TaskItem2, TaskItemOptions } from "@tiptap/extension-list"; | ||
var index_default = TaskItem; | ||
export { | ||
TaskItem, | ||
index_default as default, | ||
inputRegex | ||
TaskItem2 as TaskItem, | ||
TaskItemOptions, | ||
index_default as default | ||
}; | ||
//# sourceMappingURL=index.js.map |
MIT License | ||
Copyright (c) 2024, Tiptap GmbH | ||
Copyright (c) 2025, Tiptap GmbH | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
{ | ||
"name": "@tiptap/extension-task-item", | ||
"description": "task item extension for tiptap", | ||
"version": "3.0.0-next.4", | ||
"version": "3.0.0-next.5", | ||
"homepage": "https://tiptap.dev", | ||
@@ -34,8 +34,6 @@ "keywords": [ | ||
"devDependencies": { | ||
"@tiptap/core": "^3.0.0-next.4", | ||
"@tiptap/pm": "^3.0.0-next.4" | ||
"@tiptap/extension-list": "^3.0.0-next.5" | ||
}, | ||
"peerDependencies": { | ||
"@tiptap/core": "^3.0.0-next.1", | ||
"@tiptap/pm": "^3.0.0-next.1" | ||
"@tiptap/extension-list": "^3.0.0-next.4" | ||
}, | ||
@@ -42,0 +40,0 @@ "repository": { |
@@ -1,5 +0,5 @@ | ||
import { TaskItem } from './task-item.js' | ||
import { TaskItem } from '@tiptap/extension-list' | ||
export * from './task-item.js' | ||
export { TaskItem, TaskItemOptions } from '@tiptap/extension-list' | ||
export default TaskItem |
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
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
1
6052
10
48
1