@tiptap/extension-task-item 2.11.7 → 3.0.0-beta.1

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025, Tiptap GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,14 +1,18 @@
1
1
  # @tiptap/extension-task-item
2
+
2
3
  [![Version](https://img.shields.io/npm/v/@tiptap/extension-task-item.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-task-item)
3
4
  [![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-task-item.svg)](https://npmcharts.com/compare/tiptap?minimal=true)
4
5
  [![License](https://img.shields.io/npm/l/@tiptap/extension-task-item.svg)](https://www.npmjs.com/package/@tiptap/extension-task-item)
5
6
  [![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/ueberdosis)
6
7
 
7
8
  ## Introduction
8
- Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
9
+
10
+ Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as _New York Times_, _The Guardian_ or _Atlassian_.
9
11
 
10
12
  ## Official Documentation
13
+
11
14
  Documentation can be found on the [Tiptap website](https://tiptap.dev).
12
15
 
13
16
  ## License
17
+
14
18
  Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
package/dist/index.cjs CHANGED
@@ -1,167 +1,34 @@
1
- 'use strict';
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
19
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var core = require('@tiptap/core');
6
-
7
- /**
8
- * Matches a task item to a - [ ] on input.
9
- */
10
- const inputRegex = /^\s*(\[([( |x])?\])\s$/;
11
- /**
12
- * This extension allows you to create task items.
13
- * @see https://www.tiptap.dev/api/nodes/task-item
14
- */
15
- const TaskItem = core.Node.create({
16
- name: 'taskItem',
17
- addOptions() {
18
- return {
19
- nested: false,
20
- HTMLAttributes: {},
21
- taskListTypeName: 'taskList',
22
- };
23
- },
24
- content() {
25
- return this.options.nested ? 'paragraph block*' : 'paragraph+';
26
- },
27
- defining: true,
28
- addAttributes() {
29
- return {
30
- checked: {
31
- default: false,
32
- keepOnSplit: false,
33
- parseHTML: element => {
34
- const dataChecked = element.getAttribute('data-checked');
35
- return dataChecked === '' || dataChecked === 'true';
36
- },
37
- renderHTML: attributes => ({
38
- 'data-checked': attributes.checked,
39
- }),
40
- },
41
- };
42
- },
43
- parseHTML() {
44
- return [
45
- {
46
- tag: `li[data-type="${this.name}"]`,
47
- priority: 51,
48
- },
49
- ];
50
- },
51
- renderHTML({ node, HTMLAttributes }) {
52
- return [
53
- 'li',
54
- core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
55
- 'data-type': this.name,
56
- }),
57
- [
58
- 'label',
59
- [
60
- 'input',
61
- {
62
- type: 'checkbox',
63
- checked: node.attrs.checked ? 'checked' : null,
64
- },
65
- ],
66
- ['span'],
67
- ],
68
- ['div', 0],
69
- ];
70
- },
71
- addKeyboardShortcuts() {
72
- const shortcuts = {
73
- Enter: () => this.editor.commands.splitListItem(this.name),
74
- 'Shift-Tab': () => this.editor.commands.liftListItem(this.name),
75
- };
76
- if (!this.options.nested) {
77
- return shortcuts;
78
- }
79
- return {
80
- ...shortcuts,
81
- Tab: () => this.editor.commands.sinkListItem(this.name),
82
- };
83
- },
84
- addNodeView() {
85
- return ({ node, HTMLAttributes, getPos, editor, }) => {
86
- const listItem = document.createElement('li');
87
- const checkboxWrapper = document.createElement('label');
88
- const checkboxStyler = document.createElement('span');
89
- const checkbox = document.createElement('input');
90
- const content = document.createElement('div');
91
- checkboxWrapper.contentEditable = 'false';
92
- checkbox.type = 'checkbox';
93
- checkbox.addEventListener('mousedown', event => event.preventDefault());
94
- checkbox.addEventListener('change', event => {
95
- // if the editor isn’t editable and we don't have a handler for
96
- // readonly checks we have to undo the latest change
97
- if (!editor.isEditable && !this.options.onReadOnlyChecked) {
98
- checkbox.checked = !checkbox.checked;
99
- return;
100
- }
101
- const { checked } = event.target;
102
- if (editor.isEditable && typeof getPos === 'function') {
103
- editor
104
- .chain()
105
- .focus(undefined, { scrollIntoView: false })
106
- .command(({ tr }) => {
107
- const position = getPos();
108
- if (typeof position !== 'number') {
109
- return false;
110
- }
111
- const currentNode = tr.doc.nodeAt(position);
112
- tr.setNodeMarkup(position, undefined, {
113
- ...currentNode === null || currentNode === void 0 ? void 0 : currentNode.attrs,
114
- checked,
115
- });
116
- return true;
117
- })
118
- .run();
119
- }
120
- if (!editor.isEditable && this.options.onReadOnlyChecked) {
121
- // Reset state if onReadOnlyChecked returns false
122
- if (!this.options.onReadOnlyChecked(node, checked)) {
123
- checkbox.checked = !checkbox.checked;
124
- }
125
- }
126
- });
127
- Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {
128
- listItem.setAttribute(key, value);
129
- });
130
- listItem.dataset.checked = node.attrs.checked;
131
- checkbox.checked = node.attrs.checked;
132
- checkboxWrapper.append(checkbox, checkboxStyler);
133
- listItem.append(checkboxWrapper, content);
134
- Object.entries(HTMLAttributes).forEach(([key, value]) => {
135
- listItem.setAttribute(key, value);
136
- });
137
- return {
138
- dom: listItem,
139
- contentDOM: content,
140
- update: updatedNode => {
141
- if (updatedNode.type !== this.type) {
142
- return false;
143
- }
144
- listItem.dataset.checked = updatedNode.attrs.checked;
145
- checkbox.checked = updatedNode.attrs.checked;
146
- return true;
147
- },
148
- };
149
- };
150
- },
151
- addInputRules() {
152
- return [
153
- core.wrappingInputRule({
154
- find: inputRegex,
155
- type: this.type,
156
- getAttributes: match => ({
157
- checked: match[match.length - 1] === 'x',
158
- }),
159
- }),
160
- ];
161
- },
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ TaskItem: () => import_extension_list2.TaskItem,
24
+ default: () => index_default
162
25
  });
163
-
164
- exports.TaskItem = TaskItem;
165
- exports.default = TaskItem;
166
- exports.inputRegex = inputRegex;
167
- //# sourceMappingURL=index.cjs.map
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_extension_list = require("@tiptap/extension-list");
28
+ var import_extension_list2 = require("@tiptap/extension-list");
29
+ var index_default = import_extension_list.TaskItem;
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ TaskItem
33
+ });
34
+ //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/task-item.ts"],"sourcesContent":["import {\n KeyboardShortcutCommand, mergeAttributes, Node, wrappingInputRule,\n} from '@tiptap/core'\nimport { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nexport interface TaskItemOptions {\n /**\n * A callback function that is called when the checkbox is clicked while the editor is in readonly mode.\n * @param node The prosemirror node of the task item\n * @param checked The new checked state\n * @returns boolean\n */\n onReadOnlyChecked?: (node: ProseMirrorNode, checked: boolean) => boolean\n\n /**\n * Controls whether the task items can be nested or not.\n * @default false\n * @example true\n */\n nested: boolean\n\n /**\n * HTML attributes to add to the task item element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * The node type for taskList nodes\n * @default 'taskList'\n * @example 'myCustomTaskList'\n */\n taskListTypeName: string\n}\n\n/**\n * Matches a task item to a - [ ] on input.\n */\nexport const inputRegex = /^\\s*(\\[([( |x])?\\])\\s$/\n\n/**\n * This extension allows you to create task items.\n * @see https://www.tiptap.dev/api/nodes/task-item\n */\nexport const TaskItem = Node.create<TaskItemOptions>({\n name: 'taskItem',\n\n addOptions() {\n return {\n nested: false,\n HTMLAttributes: {},\n taskListTypeName: 'taskList',\n }\n },\n\n content() {\n return this.options.nested ? 'paragraph block*' : 'paragraph+'\n },\n\n defining: true,\n\n addAttributes() {\n return {\n checked: {\n default: false,\n keepOnSplit: false,\n parseHTML: element => {\n const dataChecked = element.getAttribute('data-checked')\n\n return dataChecked === '' || dataChecked === 'true'\n },\n renderHTML: attributes => ({\n 'data-checked': attributes.checked,\n }),\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: `li[data-type=\"${this.name}\"]`,\n priority: 51,\n },\n ]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n return [\n 'li',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {\n 'data-type': this.name,\n }),\n [\n 'label',\n [\n 'input',\n {\n type: 'checkbox',\n checked: node.attrs.checked ? 'checked' : null,\n },\n ],\n ['span'],\n ],\n ['div', 0],\n ]\n },\n\n addKeyboardShortcuts() {\n const shortcuts: {\n [key: string]: KeyboardShortcutCommand\n } = {\n Enter: () => this.editor.commands.splitListItem(this.name),\n 'Shift-Tab': () => this.editor.commands.liftListItem(this.name),\n }\n\n if (!this.options.nested) {\n return shortcuts\n }\n\n return {\n ...shortcuts,\n Tab: () => this.editor.commands.sinkListItem(this.name),\n }\n },\n\n addNodeView() {\n return ({\n node, HTMLAttributes, getPos, editor,\n }) => {\n const listItem = document.createElement('li')\n const checkboxWrapper = document.createElement('label')\n const checkboxStyler = document.createElement('span')\n const checkbox = document.createElement('input')\n const content = document.createElement('div')\n\n checkboxWrapper.contentEditable = 'false'\n checkbox.type = 'checkbox'\n checkbox.addEventListener('mousedown', event => event.preventDefault())\n checkbox.addEventListener('change', event => {\n // if the editor isn’t editable and we don't have a handler for\n // readonly checks we have to undo the latest change\n if (!editor.isEditable && !this.options.onReadOnlyChecked) {\n checkbox.checked = !checkbox.checked\n\n return\n }\n\n const { checked } = event.target as any\n\n if (editor.isEditable && typeof getPos === 'function') {\n editor\n .chain()\n .focus(undefined, { scrollIntoView: false })\n .command(({ tr }) => {\n const position = getPos()\n\n if (typeof position !== 'number') {\n return false\n }\n const currentNode = tr.doc.nodeAt(position)\n\n tr.setNodeMarkup(position, undefined, {\n ...currentNode?.attrs,\n checked,\n })\n\n return true\n })\n .run()\n }\n if (!editor.isEditable && this.options.onReadOnlyChecked) {\n // Reset state if onReadOnlyChecked returns false\n if (!this.options.onReadOnlyChecked(node, checked)) {\n checkbox.checked = !checkbox.checked\n }\n }\n })\n\n Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {\n listItem.setAttribute(key, value)\n })\n\n listItem.dataset.checked = node.attrs.checked\n checkbox.checked = node.attrs.checked\n\n checkboxWrapper.append(checkbox, checkboxStyler)\n listItem.append(checkboxWrapper, content)\n\n Object.entries(HTMLAttributes).forEach(([key, value]) => {\n listItem.setAttribute(key, value)\n })\n\n return {\n dom: listItem,\n contentDOM: content,\n update: updatedNode => {\n if (updatedNode.type !== this.type) {\n return false\n }\n\n listItem.dataset.checked = updatedNode.attrs.checked\n checkbox.checked = updatedNode.attrs.checked\n\n return true\n },\n }\n }\n },\n\n addInputRules() {\n return [\n wrappingInputRule({\n find: inputRegex,\n type: this.type,\n getAttributes: match => ({\n checked: match[match.length - 1] === 'x',\n }),\n }),\n ]\n },\n})\n"],"names":["Node","mergeAttributes","wrappingInputRule"],"mappings":";;;;;;AAoCA;;AAEG;AACI,MAAM,UAAU,GAAG;AAE1B;;;AAGG;AACU,MAAA,QAAQ,GAAGA,SAAI,CAAC,MAAM,CAAkB;AACnD,IAAA,IAAI,EAAE,UAAU;IAEhB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,MAAM,EAAE,KAAK;AACb,YAAA,cAAc,EAAE,EAAE;AAClB,YAAA,gBAAgB,EAAE,UAAU;SAC7B;KACF;IAED,OAAO,GAAA;AACL,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,kBAAkB,GAAG,YAAY;KAC/D;AAED,IAAA,QAAQ,EAAE,IAAI;IAEd,aAAa,GAAA;QACX,OAAO;AACL,YAAA,OAAO,EAAE;AACP,gBAAA,OAAO,EAAE,KAAK;AACd,gBAAA,WAAW,EAAE,KAAK;gBAClB,SAAS,EAAE,OAAO,IAAG;oBACnB,MAAM,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC;AA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,EAAE,KAAK,CAAC,KAAI;AACtD,gBAAA,QAAQ,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC;AACnC,aAAC,CAAC;YAEF,OAAO;AACL,gBAAA,GAAG,EAAE,QAAQ;AACb,gBAAA,UAAU,EAAE,OAAO;gBACnB,MAAM,EAAE,WAAW,IAAG;oBACpB,IAAI,WAAW,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;AAClC,wBAAA,OAAO,KAAK;;oBAGd,QAAQ,CAAC,OAAO,CAAC,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,OAAO;oBACpD,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,OAAO;AAE5C,oBAAA,OAAO,IAAI;iBACZ;aACF;AACH,SAAC;KACF;IAED,aAAa,GAAA;QACX,OAAO;AACL,YAAAC,sBAAiB,CAAC;AAChB,gBAAA,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;AACf,gBAAA,aAAa,EAAE,KAAK,KAAK;oBACvB,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG;iBACzC,CAAC;aACH,CAAC;SACH;KACF;AACF,CAAA;;;;;;"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { TaskItem } from '@tiptap/extension-list'\n\nexport type { TaskItemOptions } from '@tiptap/extension-list'\nexport { TaskItem } from '@tiptap/extension-list'\n\nexport default TaskItem\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAyB;AAGzB,IAAAA,yBAAyB;AAEzB,IAAO,gBAAQ;","names":["import_extension_list"]}
@@ -0,0 +1,2 @@
1
+ import { TaskItem } from '@tiptap/extension-list';
2
+ export { TaskItem, TaskItemOptions, TaskItem as default } from '@tiptap/extension-list';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- import { TaskItem } from './task-item.js';
2
- export * from './task-item.js';
3
- export default TaskItem;
4
- //# sourceMappingURL=index.d.ts.map
1
+ import { TaskItem } from '@tiptap/extension-list';
2
+ export { TaskItem, TaskItemOptions, TaskItem as default } from '@tiptap/extension-list';
package/dist/index.js CHANGED
@@ -1,161 +1,9 @@
1
- import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core';
2
-
3
- /**
4
- * Matches a task item to a - [ ] on input.
5
- */
6
- const inputRegex = /^\s*(\[([( |x])?\])\s$/;
7
- /**
8
- * This extension allows you to create task items.
9
- * @see https://www.tiptap.dev/api/nodes/task-item
10
- */
11
- const TaskItem = Node.create({
12
- name: 'taskItem',
13
- addOptions() {
14
- return {
15
- nested: false,
16
- HTMLAttributes: {},
17
- taskListTypeName: 'taskList',
18
- };
19
- },
20
- content() {
21
- return this.options.nested ? 'paragraph block*' : 'paragraph+';
22
- },
23
- defining: true,
24
- addAttributes() {
25
- return {
26
- checked: {
27
- default: false,
28
- keepOnSplit: false,
29
- parseHTML: element => {
30
- const dataChecked = element.getAttribute('data-checked');
31
- return dataChecked === '' || dataChecked === 'true';
32
- },
33
- renderHTML: attributes => ({
34
- 'data-checked': attributes.checked,
35
- }),
36
- },
37
- };
38
- },
39
- parseHTML() {
40
- return [
41
- {
42
- tag: `li[data-type="${this.name}"]`,
43
- priority: 51,
44
- },
45
- ];
46
- },
47
- renderHTML({ node, HTMLAttributes }) {
48
- return [
49
- 'li',
50
- mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
51
- 'data-type': this.name,
52
- }),
53
- [
54
- 'label',
55
- [
56
- 'input',
57
- {
58
- type: 'checkbox',
59
- checked: node.attrs.checked ? 'checked' : null,
60
- },
61
- ],
62
- ['span'],
63
- ],
64
- ['div', 0],
65
- ];
66
- },
67
- addKeyboardShortcuts() {
68
- const shortcuts = {
69
- Enter: () => this.editor.commands.splitListItem(this.name),
70
- 'Shift-Tab': () => this.editor.commands.liftListItem(this.name),
71
- };
72
- if (!this.options.nested) {
73
- return shortcuts;
74
- }
75
- return {
76
- ...shortcuts,
77
- Tab: () => this.editor.commands.sinkListItem(this.name),
78
- };
79
- },
80
- addNodeView() {
81
- return ({ node, HTMLAttributes, getPos, editor, }) => {
82
- const listItem = document.createElement('li');
83
- const checkboxWrapper = document.createElement('label');
84
- const checkboxStyler = document.createElement('span');
85
- const checkbox = document.createElement('input');
86
- const content = document.createElement('div');
87
- checkboxWrapper.contentEditable = 'false';
88
- checkbox.type = 'checkbox';
89
- checkbox.addEventListener('mousedown', event => event.preventDefault());
90
- checkbox.addEventListener('change', event => {
91
- // if the editor isn’t editable and we don't have a handler for
92
- // readonly checks we have to undo the latest change
93
- if (!editor.isEditable && !this.options.onReadOnlyChecked) {
94
- checkbox.checked = !checkbox.checked;
95
- return;
96
- }
97
- const { checked } = event.target;
98
- if (editor.isEditable && typeof getPos === 'function') {
99
- editor
100
- .chain()
101
- .focus(undefined, { scrollIntoView: false })
102
- .command(({ tr }) => {
103
- const position = getPos();
104
- if (typeof position !== 'number') {
105
- return false;
106
- }
107
- const currentNode = tr.doc.nodeAt(position);
108
- tr.setNodeMarkup(position, undefined, {
109
- ...currentNode === null || currentNode === void 0 ? void 0 : currentNode.attrs,
110
- checked,
111
- });
112
- return true;
113
- })
114
- .run();
115
- }
116
- if (!editor.isEditable && this.options.onReadOnlyChecked) {
117
- // Reset state if onReadOnlyChecked returns false
118
- if (!this.options.onReadOnlyChecked(node, checked)) {
119
- checkbox.checked = !checkbox.checked;
120
- }
121
- }
122
- });
123
- Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {
124
- listItem.setAttribute(key, value);
125
- });
126
- listItem.dataset.checked = node.attrs.checked;
127
- checkbox.checked = node.attrs.checked;
128
- checkboxWrapper.append(checkbox, checkboxStyler);
129
- listItem.append(checkboxWrapper, content);
130
- Object.entries(HTMLAttributes).forEach(([key, value]) => {
131
- listItem.setAttribute(key, value);
132
- });
133
- return {
134
- dom: listItem,
135
- contentDOM: content,
136
- update: updatedNode => {
137
- if (updatedNode.type !== this.type) {
138
- return false;
139
- }
140
- listItem.dataset.checked = updatedNode.attrs.checked;
141
- checkbox.checked = updatedNode.attrs.checked;
142
- return true;
143
- },
144
- };
145
- };
146
- },
147
- addInputRules() {
148
- return [
149
- wrappingInputRule({
150
- find: inputRegex,
151
- type: this.type,
152
- getAttributes: match => ({
153
- checked: match[match.length - 1] === 'x',
154
- }),
155
- }),
156
- ];
157
- },
158
- });
159
-
160
- export { TaskItem, TaskItem as default, inputRegex };
161
- //# sourceMappingURL=index.js.map
1
+ // src/index.ts
2
+ import { TaskItem } from "@tiptap/extension-list";
3
+ import { TaskItem as TaskItem2 } from "@tiptap/extension-list";
4
+ var index_default = TaskItem;
5
+ export {
6
+ TaskItem2 as TaskItem,
7
+ index_default as default
8
+ };
9
+ //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/task-item.ts"],"sourcesContent":["import {\n KeyboardShortcutCommand, mergeAttributes, Node, wrappingInputRule,\n} from '@tiptap/core'\nimport { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nexport interface TaskItemOptions {\n /**\n * A callback function that is called when the checkbox is clicked while the editor is in readonly mode.\n * @param node The prosemirror node of the task item\n * @param checked The new checked state\n * @returns boolean\n */\n onReadOnlyChecked?: (node: ProseMirrorNode, checked: boolean) => boolean\n\n /**\n * Controls whether the task items can be nested or not.\n * @default false\n * @example true\n */\n nested: boolean\n\n /**\n * HTML attributes to add to the task item element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * The node type for taskList nodes\n * @default 'taskList'\n * @example 'myCustomTaskList'\n */\n taskListTypeName: string\n}\n\n/**\n * Matches a task item to a - [ ] on input.\n */\nexport const inputRegex = /^\\s*(\\[([( |x])?\\])\\s$/\n\n/**\n * This extension allows you to create task items.\n * @see https://www.tiptap.dev/api/nodes/task-item\n */\nexport const TaskItem = Node.create<TaskItemOptions>({\n name: 'taskItem',\n\n addOptions() {\n return {\n nested: false,\n HTMLAttributes: {},\n taskListTypeName: 'taskList',\n }\n },\n\n content() {\n return this.options.nested ? 'paragraph block*' : 'paragraph+'\n },\n\n defining: true,\n\n addAttributes() {\n return {\n checked: {\n default: false,\n keepOnSplit: false,\n parseHTML: element => {\n const dataChecked = element.getAttribute('data-checked')\n\n return dataChecked === '' || dataChecked === 'true'\n },\n renderHTML: attributes => ({\n 'data-checked': attributes.checked,\n }),\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: `li[data-type=\"${this.name}\"]`,\n priority: 51,\n },\n ]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n return [\n 'li',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {\n 'data-type': this.name,\n }),\n [\n 'label',\n [\n 'input',\n {\n type: 'checkbox',\n checked: node.attrs.checked ? 'checked' : null,\n },\n ],\n ['span'],\n ],\n ['div', 0],\n ]\n },\n\n addKeyboardShortcuts() {\n const shortcuts: {\n [key: string]: KeyboardShortcutCommand\n } = {\n Enter: () => this.editor.commands.splitListItem(this.name),\n 'Shift-Tab': () => this.editor.commands.liftListItem(this.name),\n }\n\n if (!this.options.nested) {\n return shortcuts\n }\n\n return {\n ...shortcuts,\n Tab: () => this.editor.commands.sinkListItem(this.name),\n }\n },\n\n addNodeView() {\n return ({\n node, HTMLAttributes, getPos, editor,\n }) => {\n const listItem = document.createElement('li')\n const checkboxWrapper = document.createElement('label')\n const checkboxStyler = document.createElement('span')\n const checkbox = document.createElement('input')\n const content = document.createElement('div')\n\n checkboxWrapper.contentEditable = 'false'\n checkbox.type = 'checkbox'\n checkbox.addEventListener('mousedown', event => event.preventDefault())\n checkbox.addEventListener('change', event => {\n // if the editor isn’t editable and we don't have a handler for\n // readonly checks we have to undo the latest change\n if (!editor.isEditable && !this.options.onReadOnlyChecked) {\n checkbox.checked = !checkbox.checked\n\n return\n }\n\n const { checked } = event.target as any\n\n if (editor.isEditable && typeof getPos === 'function') {\n editor\n .chain()\n .focus(undefined, { scrollIntoView: false })\n .command(({ tr }) => {\n const position = getPos()\n\n if (typeof position !== 'number') {\n return false\n }\n const currentNode = tr.doc.nodeAt(position)\n\n tr.setNodeMarkup(position, undefined, {\n ...currentNode?.attrs,\n checked,\n })\n\n return true\n })\n .run()\n }\n if (!editor.isEditable && this.options.onReadOnlyChecked) {\n // Reset state if onReadOnlyChecked returns false\n if (!this.options.onReadOnlyChecked(node, checked)) {\n checkbox.checked = !checkbox.checked\n }\n }\n })\n\n Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {\n listItem.setAttribute(key, value)\n })\n\n listItem.dataset.checked = node.attrs.checked\n checkbox.checked = node.attrs.checked\n\n checkboxWrapper.append(checkbox, checkboxStyler)\n listItem.append(checkboxWrapper, content)\n\n Object.entries(HTMLAttributes).forEach(([key, value]) => {\n listItem.setAttribute(key, value)\n })\n\n return {\n dom: listItem,\n contentDOM: content,\n update: updatedNode => {\n if (updatedNode.type !== this.type) {\n return false\n }\n\n listItem.dataset.checked = updatedNode.attrs.checked\n checkbox.checked = updatedNode.attrs.checked\n\n return true\n },\n }\n }\n },\n\n addInputRules() {\n return [\n wrappingInputRule({\n find: inputRegex,\n type: this.type,\n getAttributes: match => ({\n checked: match[match.length - 1] === 'x',\n }),\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;AAoCA;;AAEG;AACI,MAAM,UAAU,GAAG;AAE1B;;;AAGG;AACU,MAAA,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAkB;AACnD,IAAA,IAAI,EAAE,UAAU;IAEhB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,MAAM,EAAE,KAAK;AACb,YAAA,cAAc,EAAE,EAAE;AAClB,YAAA,gBAAgB,EAAE,UAAU;SAC7B;KACF;IAED,OAAO,GAAA;AACL,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,kBAAkB,GAAG,YAAY;KAC/D;AAED,IAAA,QAAQ,EAAE,IAAI;IAEd,aA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A,eAAe,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC;AAChD,YAAA,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC;AAEzC,YAAA,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAI;AACtD,gBAAA,QAAQ,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC;AACnC,aAAC,CAAC;YAEF,OAAO;AACL,gBAAA,GAAG,EAAE,QAAQ;AACb,gBAAA,UAAU,EAAE,OAAO;gBACnB,MAAM,EAAE,WAAW,IAAG;oBACpB,IAAI,WAAW,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;AAClC,wBAAA,OAAO,KAAK;;oBAGd,QAAQ,CAAC,OAAO,CAAC,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,OAAO;oBACpD,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,OAAO;AAE5C,oBAAA,OAAO,IAAI;iBACZ;aACF;AACH,SAAC;KACF;IAED,aAAa,GAAA;QACX,OAAO;AACL,YAAA,iBAAiB,CAAC;AAChB,gBAAA,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;AACf,gBAAA,aAAa,EAAE,KAAK,KAAK;oBACvB,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG;iBACzC,CAAC;aACH,CAAC;SACH;KACF;AACF,CAAA;;;;"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { TaskItem } from '@tiptap/extension-list'\n\nexport type { TaskItemOptions } from '@tiptap/extension-list'\nexport { TaskItem } from '@tiptap/extension-list'\n\nexport default TaskItem\n"],"mappings":";AAAA,SAAS,gBAAgB;AAGzB,SAAS,YAAAA,iBAAgB;AAEzB,IAAO,gBAAQ;","names":["TaskItem"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/extension-task-item",
3
3
  "description": "task item extension for tiptap",
4
- "version": "2.11.7",
4
+ "version": "3.0.0-beta.1",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -15,26 +15,26 @@
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/index.d.ts",
18
+ "types": {
19
+ "import": "./dist/index.d.ts",
20
+ "require": "./dist/index.d.cts"
21
+ },
19
22
  "import": "./dist/index.js",
20
23
  "require": "./dist/index.cjs"
21
24
  }
22
25
  },
23
26
  "main": "dist/index.cjs",
24
27
  "module": "dist/index.js",
25
- "umd": "dist/index.umd.js",
26
28
  "types": "dist/index.d.ts",
27
29
  "files": [
28
30
  "src",
29
31
  "dist"
30
32
  ],
31
33
  "devDependencies": {
32
- "@tiptap/core": "^2.11.7",
33
- "@tiptap/pm": "^2.11.7"
34
+ "@tiptap/extension-list": "^3.0.0-beta.1"
34
35
  },
35
36
  "peerDependencies": {
36
- "@tiptap/core": "^2.7.0",
37
- "@tiptap/pm": "^2.7.0"
37
+ "@tiptap/extension-list": "^3.0.0-beta.0"
38
38
  },
39
39
  "repository": {
40
40
  "type": "git",
@@ -42,7 +42,7 @@
42
42
  "directory": "packages/extension-task-item"
43
43
  },
44
44
  "scripts": {
45
- "clean": "rm -rf dist",
46
- "build": "npm run clean && rollup -c"
45
+ "build": "tsup",
46
+ "lint": "prettier ./src/ --check && eslint --cache --quiet --no-error-on-unmatched-pattern ./src/"
47
47
  }
48
- }
48
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { TaskItem } from './task-item.js'
1
+ import { TaskItem } from '@tiptap/extension-list'
2
2
 
3
- export * from './task-item.js'
3
+ export type { TaskItemOptions } from '@tiptap/extension-list'
4
+ export { TaskItem } from '@tiptap/extension-list'
4
5
 
5
6
  export default TaskItem
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,cAAc,gBAAgB,CAAA;AAE9B,eAAe,QAAQ,CAAA"}
package/dist/index.umd.js DELETED
@@ -1,171 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-task-item"] = {}, global.core));
5
- })(this, (function (exports, core) { 'use strict';
6
-
7
- /**
8
- * Matches a task item to a - [ ] on input.
9
- */
10
- const inputRegex = /^\s*(\[([( |x])?\])\s$/;
11
- /**
12
- * This extension allows you to create task items.
13
- * @see https://www.tiptap.dev/api/nodes/task-item
14
- */
15
- const TaskItem = core.Node.create({
16
- name: 'taskItem',
17
- addOptions() {
18
- return {
19
- nested: false,
20
- HTMLAttributes: {},
21
- taskListTypeName: 'taskList',
22
- };
23
- },
24
- content() {
25
- return this.options.nested ? 'paragraph block*' : 'paragraph+';
26
- },
27
- defining: true,
28
- addAttributes() {
29
- return {
30
- checked: {
31
- default: false,
32
- keepOnSplit: false,
33
- parseHTML: element => {
34
- const dataChecked = element.getAttribute('data-checked');
35
- return dataChecked === '' || dataChecked === 'true';
36
- },
37
- renderHTML: attributes => ({
38
- 'data-checked': attributes.checked,
39
- }),
40
- },
41
- };
42
- },
43
- parseHTML() {
44
- return [
45
- {
46
- tag: `li[data-type="${this.name}"]`,
47
- priority: 51,
48
- },
49
- ];
50
- },
51
- renderHTML({ node, HTMLAttributes }) {
52
- return [
53
- 'li',
54
- core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
55
- 'data-type': this.name,
56
- }),
57
- [
58
- 'label',
59
- [
60
- 'input',
61
- {
62
- type: 'checkbox',
63
- checked: node.attrs.checked ? 'checked' : null,
64
- },
65
- ],
66
- ['span'],
67
- ],
68
- ['div', 0],
69
- ];
70
- },
71
- addKeyboardShortcuts() {
72
- const shortcuts = {
73
- Enter: () => this.editor.commands.splitListItem(this.name),
74
- 'Shift-Tab': () => this.editor.commands.liftListItem(this.name),
75
- };
76
- if (!this.options.nested) {
77
- return shortcuts;
78
- }
79
- return {
80
- ...shortcuts,
81
- Tab: () => this.editor.commands.sinkListItem(this.name),
82
- };
83
- },
84
- addNodeView() {
85
- return ({ node, HTMLAttributes, getPos, editor, }) => {
86
- const listItem = document.createElement('li');
87
- const checkboxWrapper = document.createElement('label');
88
- const checkboxStyler = document.createElement('span');
89
- const checkbox = document.createElement('input');
90
- const content = document.createElement('div');
91
- checkboxWrapper.contentEditable = 'false';
92
- checkbox.type = 'checkbox';
93
- checkbox.addEventListener('mousedown', event => event.preventDefault());
94
- checkbox.addEventListener('change', event => {
95
- // if the editor isn’t editable and we don't have a handler for
96
- // readonly checks we have to undo the latest change
97
- if (!editor.isEditable && !this.options.onReadOnlyChecked) {
98
- checkbox.checked = !checkbox.checked;
99
- return;
100
- }
101
- const { checked } = event.target;
102
- if (editor.isEditable && typeof getPos === 'function') {
103
- editor
104
- .chain()
105
- .focus(undefined, { scrollIntoView: false })
106
- .command(({ tr }) => {
107
- const position = getPos();
108
- if (typeof position !== 'number') {
109
- return false;
110
- }
111
- const currentNode = tr.doc.nodeAt(position);
112
- tr.setNodeMarkup(position, undefined, {
113
- ...currentNode === null || currentNode === void 0 ? void 0 : currentNode.attrs,
114
- checked,
115
- });
116
- return true;
117
- })
118
- .run();
119
- }
120
- if (!editor.isEditable && this.options.onReadOnlyChecked) {
121
- // Reset state if onReadOnlyChecked returns false
122
- if (!this.options.onReadOnlyChecked(node, checked)) {
123
- checkbox.checked = !checkbox.checked;
124
- }
125
- }
126
- });
127
- Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {
128
- listItem.setAttribute(key, value);
129
- });
130
- listItem.dataset.checked = node.attrs.checked;
131
- checkbox.checked = node.attrs.checked;
132
- checkboxWrapper.append(checkbox, checkboxStyler);
133
- listItem.append(checkboxWrapper, content);
134
- Object.entries(HTMLAttributes).forEach(([key, value]) => {
135
- listItem.setAttribute(key, value);
136
- });
137
- return {
138
- dom: listItem,
139
- contentDOM: content,
140
- update: updatedNode => {
141
- if (updatedNode.type !== this.type) {
142
- return false;
143
- }
144
- listItem.dataset.checked = updatedNode.attrs.checked;
145
- checkbox.checked = updatedNode.attrs.checked;
146
- return true;
147
- },
148
- };
149
- };
150
- },
151
- addInputRules() {
152
- return [
153
- core.wrappingInputRule({
154
- find: inputRegex,
155
- type: this.type,
156
- getAttributes: match => ({
157
- checked: match[match.length - 1] === 'x',
158
- }),
159
- }),
160
- ];
161
- },
162
- });
163
-
164
- exports.TaskItem = TaskItem;
165
- exports.default = TaskItem;
166
- exports.inputRegex = inputRegex;
167
-
168
- Object.defineProperty(exports, '__esModule', { value: true });
169
-
170
- }));
171
- //# sourceMappingURL=index.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/task-item.ts"],"sourcesContent":["import {\n KeyboardShortcutCommand, mergeAttributes, Node, wrappingInputRule,\n} from '@tiptap/core'\nimport { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nexport interface TaskItemOptions {\n /**\n * A callback function that is called when the checkbox is clicked while the editor is in readonly mode.\n * @param node The prosemirror node of the task item\n * @param checked The new checked state\n * @returns boolean\n */\n onReadOnlyChecked?: (node: ProseMirrorNode, checked: boolean) => boolean\n\n /**\n * Controls whether the task items can be nested or not.\n * @default false\n * @example true\n */\n nested: boolean\n\n /**\n * HTML attributes to add to the task item element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * The node type for taskList nodes\n * @default 'taskList'\n * @example 'myCustomTaskList'\n */\n taskListTypeName: string\n}\n\n/**\n * Matches a task item to a - [ ] on input.\n */\nexport const inputRegex = /^\\s*(\\[([( |x])?\\])\\s$/\n\n/**\n * This extension allows you to create task items.\n * @see https://www.tiptap.dev/api/nodes/task-item\n */\nexport const TaskItem = Node.create<TaskItemOptions>({\n name: 'taskItem',\n\n addOptions() {\n return {\n nested: false,\n HTMLAttributes: {},\n taskListTypeName: 'taskList',\n }\n },\n\n content() {\n return this.options.nested ? 'paragraph block*' : 'paragraph+'\n },\n\n defining: true,\n\n addAttributes() {\n return {\n checked: {\n default: false,\n keepOnSplit: false,\n parseHTML: element => {\n const dataChecked = element.getAttribute('data-checked')\n\n return dataChecked === '' || dataChecked === 'true'\n },\n renderHTML: attributes => ({\n 'data-checked': attributes.checked,\n }),\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: `li[data-type=\"${this.name}\"]`,\n priority: 51,\n },\n ]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n return [\n 'li',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {\n 'data-type': this.name,\n }),\n [\n 'label',\n [\n 'input',\n {\n type: 'checkbox',\n checked: node.attrs.checked ? 'checked' : null,\n },\n ],\n ['span'],\n ],\n ['div', 0],\n ]\n },\n\n addKeyboardShortcuts() {\n const shortcuts: {\n [key: string]: KeyboardShortcutCommand\n } = {\n Enter: () => this.editor.commands.splitListItem(this.name),\n 'Shift-Tab': () => this.editor.commands.liftListItem(this.name),\n }\n\n if (!this.options.nested) {\n return shortcuts\n }\n\n return {\n ...shortcuts,\n Tab: () => this.editor.commands.sinkListItem(this.name),\n }\n },\n\n addNodeView() {\n return ({\n node, HTMLAttributes, getPos, editor,\n }) => {\n const listItem = document.createElement('li')\n const checkboxWrapper = document.createElement('label')\n const checkboxStyler = document.createElement('span')\n const checkbox = document.createElement('input')\n const content = document.createElement('div')\n\n checkboxWrapper.contentEditable = 'false'\n checkbox.type = 'checkbox'\n checkbox.addEventListener('mousedown', event => event.preventDefault())\n checkbox.addEventListener('change', event => {\n // if the editor isn’t editable and we don't have a handler for\n // readonly checks we have to undo the latest change\n if (!editor.isEditable && !this.options.onReadOnlyChecked) {\n checkbox.checked = !checkbox.checked\n\n return\n }\n\n const { checked } = event.target as any\n\n if (editor.isEditable && typeof getPos === 'function') {\n editor\n .chain()\n .focus(undefined, { scrollIntoView: false })\n .command(({ tr }) => {\n const position = getPos()\n\n if (typeof position !== 'number') {\n return false\n }\n const currentNode = tr.doc.nodeAt(position)\n\n tr.setNodeMarkup(position, undefined, {\n ...currentNode?.attrs,\n checked,\n })\n\n return true\n })\n .run()\n }\n if (!editor.isEditable && this.options.onReadOnlyChecked) {\n // Reset state if onReadOnlyChecked returns false\n if (!this.options.onReadOnlyChecked(node, checked)) {\n checkbox.checked = !checkbox.checked\n }\n }\n })\n\n Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {\n listItem.setAttribute(key, value)\n })\n\n listItem.dataset.checked = node.attrs.checked\n checkbox.checked = node.attrs.checked\n\n checkboxWrapper.append(checkbox, checkboxStyler)\n listItem.append(checkboxWrapper, content)\n\n Object.entries(HTMLAttributes).forEach(([key, value]) => {\n listItem.setAttribute(key, value)\n })\n\n return {\n dom: listItem,\n contentDOM: content,\n update: updatedNode => {\n if (updatedNode.type !== this.type) {\n return false\n }\n\n listItem.dataset.checked = updatedNode.attrs.checked\n checkbox.checked = updatedNode.attrs.checked\n\n return true\n },\n }\n }\n },\n\n addInputRules() {\n return [\n wrappingInputRule({\n find: inputRegex,\n type: this.type,\n getAttributes: match => ({\n checked: match[match.length - 1] === 'x',\n }),\n }),\n ]\n },\n})\n"],"names":["Node","mergeAttributes","wrappingInputRule"],"mappings":";;;;;;EAoCA;;EAEG;AACI,QAAM,UAAU,GAAG;EAE1B;;;EAGG;AACU,QAAA,QAAQ,GAAGA,SAAI,CAAC,MAAM,CAAkB;EACnD,IAAA,IAAI,EAAE,UAAU;MAEhB,UAAU,GAAA;UACR,OAAO;EACL,YAAA,MAAM,EAAE,KAAK;EACb,YAAA,cAAc,EAAE,EAAE;EAClB,YAAA,gBAAgB,EAAE,UAAU;WAC7B;OACF;MAED,OAAO,GAAA;EACL,QAAA,O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GAAG,IAAI,CAAC,KAAK,CAAC,OAAO;cAC7C,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO;EAErC,YAAA,eAAe,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC;EAChD,YAAA,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC;EAEzC,YAAA,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAI;EACtD,gBAAA,QAAQ,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC;EACnC,aAAC,CAAC;cAEF,OAAO;EACL,gBAAA,GAAG,EAAE,QAAQ;EACb,gBAAA,UAAU,EAAE,OAAO;kBACnB,MAAM,EAAE,WAAW,IAAG;sBACpB,IAAI,WAAW,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;EAClC,wBAAA,OAAO,KAAK;;sBAGd,QAAQ,CAAC,OAAO,CAAC,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,OAAO;sBACpD,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,OAAO;EAE5C,oBAAA,OAAO,IAAI;mBACZ;eACF;EACH,SAAC;OACF;MAED,aAAa,GAAA;UACX,OAAO;EACL,YAAAC,sBAAiB,CAAC;EAChB,gBAAA,IAAI,EAAE,UAAU;kBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;EACf,gBAAA,aAAa,EAAE,KAAK,KAAK;sBACvB,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG;mBACzC,CAAC;eACH,CAAC;WACH;OACF;EACF,CAAA;;;;;;;;;;;;"}
@@ -1,39 +0,0 @@
1
- import { Node } from '@tiptap/core';
2
- import { Node as ProseMirrorNode } from '@tiptap/pm/model';
3
- export interface TaskItemOptions {
4
- /**
5
- * A callback function that is called when the checkbox is clicked while the editor is in readonly mode.
6
- * @param node The prosemirror node of the task item
7
- * @param checked The new checked state
8
- * @returns boolean
9
- */
10
- onReadOnlyChecked?: (node: ProseMirrorNode, checked: boolean) => boolean;
11
- /**
12
- * Controls whether the task items can be nested or not.
13
- * @default false
14
- * @example true
15
- */
16
- nested: boolean;
17
- /**
18
- * HTML attributes to add to the task item element.
19
- * @default {}
20
- * @example { class: 'foo' }
21
- */
22
- HTMLAttributes: Record<string, any>;
23
- /**
24
- * The node type for taskList nodes
25
- * @default 'taskList'
26
- * @example 'myCustomTaskList'
27
- */
28
- taskListTypeName: string;
29
- }
30
- /**
31
- * Matches a task item to a - [ ] on input.
32
- */
33
- export declare const inputRegex: RegExp;
34
- /**
35
- * This extension allows you to create task items.
36
- * @see https://www.tiptap.dev/api/nodes/task-item
37
- */
38
- export declare const TaskItem: Node<TaskItemOptions, any>;
39
- //# sourceMappingURL=task-item.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"task-item.d.ts","sourceRoot":"","sources":["../src/task-item.ts"],"names":[],"mappings":"AAAA,OAAO,EACqC,IAAI,EAC/C,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,IAAI,IAAI,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAE1D,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAA;IAExE;;;;OAIG;IACH,MAAM,EAAE,OAAO,CAAA;IAEf;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAEnC;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,QAA2B,CAAA;AAElD;;;GAGG;AACH,eAAO,MAAM,QAAQ,4BAiLnB,CAAA"}
package/src/task-item.ts DELETED
@@ -1,223 +0,0 @@
1
- import {
2
- KeyboardShortcutCommand, mergeAttributes, Node, wrappingInputRule,
3
- } from '@tiptap/core'
4
- import { Node as ProseMirrorNode } from '@tiptap/pm/model'
5
-
6
- export interface TaskItemOptions {
7
- /**
8
- * A callback function that is called when the checkbox is clicked while the editor is in readonly mode.
9
- * @param node The prosemirror node of the task item
10
- * @param checked The new checked state
11
- * @returns boolean
12
- */
13
- onReadOnlyChecked?: (node: ProseMirrorNode, checked: boolean) => boolean
14
-
15
- /**
16
- * Controls whether the task items can be nested or not.
17
- * @default false
18
- * @example true
19
- */
20
- nested: boolean
21
-
22
- /**
23
- * HTML attributes to add to the task item element.
24
- * @default {}
25
- * @example { class: 'foo' }
26
- */
27
- HTMLAttributes: Record<string, any>
28
-
29
- /**
30
- * The node type for taskList nodes
31
- * @default 'taskList'
32
- * @example 'myCustomTaskList'
33
- */
34
- taskListTypeName: string
35
- }
36
-
37
- /**
38
- * Matches a task item to a - [ ] on input.
39
- */
40
- export const inputRegex = /^\s*(\[([( |x])?\])\s$/
41
-
42
- /**
43
- * This extension allows you to create task items.
44
- * @see https://www.tiptap.dev/api/nodes/task-item
45
- */
46
- export const TaskItem = Node.create<TaskItemOptions>({
47
- name: 'taskItem',
48
-
49
- addOptions() {
50
- return {
51
- nested: false,
52
- HTMLAttributes: {},
53
- taskListTypeName: 'taskList',
54
- }
55
- },
56
-
57
- content() {
58
- return this.options.nested ? 'paragraph block*' : 'paragraph+'
59
- },
60
-
61
- defining: true,
62
-
63
- addAttributes() {
64
- return {
65
- checked: {
66
- default: false,
67
- keepOnSplit: false,
68
- parseHTML: element => {
69
- const dataChecked = element.getAttribute('data-checked')
70
-
71
- return dataChecked === '' || dataChecked === 'true'
72
- },
73
- renderHTML: attributes => ({
74
- 'data-checked': attributes.checked,
75
- }),
76
- },
77
- }
78
- },
79
-
80
- parseHTML() {
81
- return [
82
- {
83
- tag: `li[data-type="${this.name}"]`,
84
- priority: 51,
85
- },
86
- ]
87
- },
88
-
89
- renderHTML({ node, HTMLAttributes }) {
90
- return [
91
- 'li',
92
- mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
93
- 'data-type': this.name,
94
- }),
95
- [
96
- 'label',
97
- [
98
- 'input',
99
- {
100
- type: 'checkbox',
101
- checked: node.attrs.checked ? 'checked' : null,
102
- },
103
- ],
104
- ['span'],
105
- ],
106
- ['div', 0],
107
- ]
108
- },
109
-
110
- addKeyboardShortcuts() {
111
- const shortcuts: {
112
- [key: string]: KeyboardShortcutCommand
113
- } = {
114
- Enter: () => this.editor.commands.splitListItem(this.name),
115
- 'Shift-Tab': () => this.editor.commands.liftListItem(this.name),
116
- }
117
-
118
- if (!this.options.nested) {
119
- return shortcuts
120
- }
121
-
122
- return {
123
- ...shortcuts,
124
- Tab: () => this.editor.commands.sinkListItem(this.name),
125
- }
126
- },
127
-
128
- addNodeView() {
129
- return ({
130
- node, HTMLAttributes, getPos, editor,
131
- }) => {
132
- const listItem = document.createElement('li')
133
- const checkboxWrapper = document.createElement('label')
134
- const checkboxStyler = document.createElement('span')
135
- const checkbox = document.createElement('input')
136
- const content = document.createElement('div')
137
-
138
- checkboxWrapper.contentEditable = 'false'
139
- checkbox.type = 'checkbox'
140
- checkbox.addEventListener('mousedown', event => event.preventDefault())
141
- checkbox.addEventListener('change', event => {
142
- // if the editor isn’t editable and we don't have a handler for
143
- // readonly checks we have to undo the latest change
144
- if (!editor.isEditable && !this.options.onReadOnlyChecked) {
145
- checkbox.checked = !checkbox.checked
146
-
147
- return
148
- }
149
-
150
- const { checked } = event.target as any
151
-
152
- if (editor.isEditable && typeof getPos === 'function') {
153
- editor
154
- .chain()
155
- .focus(undefined, { scrollIntoView: false })
156
- .command(({ tr }) => {
157
- const position = getPos()
158
-
159
- if (typeof position !== 'number') {
160
- return false
161
- }
162
- const currentNode = tr.doc.nodeAt(position)
163
-
164
- tr.setNodeMarkup(position, undefined, {
165
- ...currentNode?.attrs,
166
- checked,
167
- })
168
-
169
- return true
170
- })
171
- .run()
172
- }
173
- if (!editor.isEditable && this.options.onReadOnlyChecked) {
174
- // Reset state if onReadOnlyChecked returns false
175
- if (!this.options.onReadOnlyChecked(node, checked)) {
176
- checkbox.checked = !checkbox.checked
177
- }
178
- }
179
- })
180
-
181
- Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {
182
- listItem.setAttribute(key, value)
183
- })
184
-
185
- listItem.dataset.checked = node.attrs.checked
186
- checkbox.checked = node.attrs.checked
187
-
188
- checkboxWrapper.append(checkbox, checkboxStyler)
189
- listItem.append(checkboxWrapper, content)
190
-
191
- Object.entries(HTMLAttributes).forEach(([key, value]) => {
192
- listItem.setAttribute(key, value)
193
- })
194
-
195
- return {
196
- dom: listItem,
197
- contentDOM: content,
198
- update: updatedNode => {
199
- if (updatedNode.type !== this.type) {
200
- return false
201
- }
202
-
203
- listItem.dataset.checked = updatedNode.attrs.checked
204
- checkbox.checked = updatedNode.attrs.checked
205
-
206
- return true
207
- },
208
- }
209
- }
210
- },
211
-
212
- addInputRules() {
213
- return [
214
- wrappingInputRule({
215
- find: inputRegex,
216
- type: this.type,
217
- getAttributes: match => ({
218
- checked: match[match.length - 1] === 'x',
219
- }),
220
- }),
221
- ]
222
- },
223
- })