@thomasjahoda-forks/tiptap-extension-list 3.0.7

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.
Files changed (76) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +18 -0
  3. package/dist/bullet-list/index.cjs +93 -0
  4. package/dist/bullet-list/index.cjs.map +1 -0
  5. package/dist/bullet-list/index.d.cts +51 -0
  6. package/dist/bullet-list/index.d.ts +51 -0
  7. package/dist/bullet-list/index.js +65 -0
  8. package/dist/bullet-list/index.js.map +1 -0
  9. package/dist/index.cjs +736 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.cts +300 -0
  12. package/dist/index.d.ts +300 -0
  13. package/dist/index.js +705 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/item/index.cjs +62 -0
  16. package/dist/item/index.cjs.map +1 -0
  17. package/dist/item/index.d.cts +29 -0
  18. package/dist/item/index.d.ts +29 -0
  19. package/dist/item/index.js +35 -0
  20. package/dist/item/index.js.map +1 -0
  21. package/dist/keymap/index.cjs +308 -0
  22. package/dist/keymap/index.cjs.map +1 -0
  23. package/dist/keymap/index.d.cts +63 -0
  24. package/dist/keymap/index.d.ts +63 -0
  25. package/dist/keymap/index.js +286 -0
  26. package/dist/keymap/index.js.map +1 -0
  27. package/dist/kit/index.cjs +714 -0
  28. package/dist/kit/index.cjs.map +1 -0
  29. package/dist/kit/index.d.cts +212 -0
  30. package/dist/kit/index.d.ts +212 -0
  31. package/dist/kit/index.js +695 -0
  32. package/dist/kit/index.js.map +1 -0
  33. package/dist/ordered-list/index.cjs +113 -0
  34. package/dist/ordered-list/index.cjs.map +1 -0
  35. package/dist/ordered-list/index.d.cts +52 -0
  36. package/dist/ordered-list/index.d.ts +52 -0
  37. package/dist/ordered-list/index.js +85 -0
  38. package/dist/ordered-list/index.js.map +1 -0
  39. package/dist/task-item/index.cjs +199 -0
  40. package/dist/task-item/index.cjs.map +1 -0
  41. package/dist/task-item/index.d.cts +53 -0
  42. package/dist/task-item/index.d.ts +53 -0
  43. package/dist/task-item/index.js +171 -0
  44. package/dist/task-item/index.js.map +1 -0
  45. package/dist/task-list/index.cjs +69 -0
  46. package/dist/task-list/index.cjs.map +1 -0
  47. package/dist/task-list/index.d.cts +34 -0
  48. package/dist/task-list/index.d.ts +34 -0
  49. package/dist/task-list/index.js +42 -0
  50. package/dist/task-list/index.js.map +1 -0
  51. package/package.json +106 -0
  52. package/src/bullet-list/bullet-list.ts +126 -0
  53. package/src/bullet-list/index.ts +1 -0
  54. package/src/index.ts +7 -0
  55. package/src/item/index.ts +1 -0
  56. package/src/item/list-item.ts +64 -0
  57. package/src/keymap/index.ts +2 -0
  58. package/src/keymap/list-keymap.ts +106 -0
  59. package/src/keymap/listHelpers/findListItemPos.ts +30 -0
  60. package/src/keymap/listHelpers/getNextListDepth.ts +16 -0
  61. package/src/keymap/listHelpers/handleBackspace.ts +85 -0
  62. package/src/keymap/listHelpers/handleDelete.ts +44 -0
  63. package/src/keymap/listHelpers/hasListBefore.ts +15 -0
  64. package/src/keymap/listHelpers/hasListItemAfter.ts +17 -0
  65. package/src/keymap/listHelpers/hasListItemBefore.ts +17 -0
  66. package/src/keymap/listHelpers/index.ts +10 -0
  67. package/src/keymap/listHelpers/listItemHasSubList.ts +21 -0
  68. package/src/keymap/listHelpers/nextListIsDeeper.ts +19 -0
  69. package/src/keymap/listHelpers/nextListIsHigher.ts +19 -0
  70. package/src/kit/index.ts +81 -0
  71. package/src/ordered-list/index.ts +1 -0
  72. package/src/ordered-list/ordered-list.ts +151 -0
  73. package/src/task-item/index.ts +1 -0
  74. package/src/task-item/task-item.ts +266 -0
  75. package/src/task-list/index.ts +1 -0
  76. package/src/task-list/task-list.ts +79 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/task-item/index.ts","../../src/task-item/task-item.ts"],"sourcesContent":["export * from './task-item.js'\n","import type { KeyboardShortcutCommand } from '@tiptap/core'\nimport { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\nimport type { 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 whether the change to the checkbox state should be accepted or reverted - or whether the editor content should be updated\n */\n onReadOnlyChecked?: (node: ProseMirrorNode, checked: boolean) => boolean | 'updateEditorContent'\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 * Accessibility options for the task item.\n * @default {}\n * @example\n * ```js\n * {\n * checkboxLabel: (node) => `Task item: ${node.textContent || 'empty task item'}`\n * }\n */\n a11y?: {\n checkboxLabel?: (node: ProseMirrorNode, checked: boolean) => string\n }\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 a11y: undefined,\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 ({ node, HTMLAttributes, getPos, editor }) => {\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 const updateA11Y = () => {\n checkbox.ariaLabel =\n this.options.a11y?.checkboxLabel?.(node, checkbox.checked) ||\n `Task item checkbox for ${node.textContent || 'empty task item'}`\n }\n\n updateA11Y()\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 const result = this.options.onReadOnlyChecked(node, checked)\n if (result === false) {\n checkbox.checked = !checkbox.checked\n } else if (result === true) {\n // simply accept the change and do nothing\n } else if (result === 'updateEditorContent') {\n // update the editor content to reflect the change\n editor\n .chain()\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 }\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 updateA11Y()\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAAyD;AAkDlD,IAAM,aAAa;AAMnB,IAAM,WAAW,iBAAK,OAAwB;AAAA,EACnD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,gBAAgB,CAAC;AAAA,MACjB,kBAAkB;AAAA,MAClB,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,UAAU;AACR,WAAO,KAAK,QAAQ,SAAS,qBAAqB;AAAA,EACpD;AAAA,EAEA,UAAU;AAAA,EAEV,gBAAgB;AACd,WAAO;AAAA,MACL,SAAS;AAAA,QACP,SAAS;AAAA,QACT,aAAa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m/model';
3
+
4
+ interface TaskItemOptions {
5
+ /**
6
+ * A callback function that is called when the checkbox is clicked while the editor is in readonly mode.
7
+ * @param node The prosemirror node of the task item
8
+ * @param checked The new checked state
9
+ * @returns boolean whether the change to the checkbox state should be accepted or reverted - or whether the editor content should be updated
10
+ */
11
+ onReadOnlyChecked?: (node: Node, checked: boolean) => boolean | 'updateEditorContent';
12
+ /**
13
+ * Controls whether the task items can be nested or not.
14
+ * @default false
15
+ * @example true
16
+ */
17
+ nested: boolean;
18
+ /**
19
+ * HTML attributes to add to the task item element.
20
+ * @default {}
21
+ * @example { class: 'foo' }
22
+ */
23
+ HTMLAttributes: Record<string, any>;
24
+ /**
25
+ * The node type for taskList nodes
26
+ * @default 'taskList'
27
+ * @example 'myCustomTaskList'
28
+ */
29
+ taskListTypeName: string;
30
+ /**
31
+ * Accessibility options for the task item.
32
+ * @default {}
33
+ * @example
34
+ * ```js
35
+ * {
36
+ * checkboxLabel: (node) => `Task item: ${node.textContent || 'empty task item'}`
37
+ * }
38
+ */
39
+ a11y?: {
40
+ checkboxLabel?: (node: Node, checked: boolean) => string;
41
+ };
42
+ }
43
+ /**
44
+ * Matches a task item to a - [ ] on input.
45
+ */
46
+ declare const inputRegex: RegExp;
47
+ /**
48
+ * This extension allows you to create task items.
49
+ * @see https://www.tiptap.dev/api/nodes/task-item
50
+ */
51
+ declare const TaskItem: Node$1<TaskItemOptions, any>;
52
+
53
+ export { TaskItem, type TaskItemOptions, inputRegex };
@@ -0,0 +1,53 @@
1
+ import { Node as Node$1 } from '@tiptap/core';
2
+ import { Node } from '@tiptap/pm/model';
3
+
4
+ interface TaskItemOptions {
5
+ /**
6
+ * A callback function that is called when the checkbox is clicked while the editor is in readonly mode.
7
+ * @param node The prosemirror node of the task item
8
+ * @param checked The new checked state
9
+ * @returns boolean whether the change to the checkbox state should be accepted or reverted - or whether the editor content should be updated
10
+ */
11
+ onReadOnlyChecked?: (node: Node, checked: boolean) => boolean | 'updateEditorContent';
12
+ /**
13
+ * Controls whether the task items can be nested or not.
14
+ * @default false
15
+ * @example true
16
+ */
17
+ nested: boolean;
18
+ /**
19
+ * HTML attributes to add to the task item element.
20
+ * @default {}
21
+ * @example { class: 'foo' }
22
+ */
23
+ HTMLAttributes: Record<string, any>;
24
+ /**
25
+ * The node type for taskList nodes
26
+ * @default 'taskList'
27
+ * @example 'myCustomTaskList'
28
+ */
29
+ taskListTypeName: string;
30
+ /**
31
+ * Accessibility options for the task item.
32
+ * @default {}
33
+ * @example
34
+ * ```js
35
+ * {
36
+ * checkboxLabel: (node) => `Task item: ${node.textContent || 'empty task item'}`
37
+ * }
38
+ */
39
+ a11y?: {
40
+ checkboxLabel?: (node: Node, checked: boolean) => string;
41
+ };
42
+ }
43
+ /**
44
+ * Matches a task item to a - [ ] on input.
45
+ */
46
+ declare const inputRegex: RegExp;
47
+ /**
48
+ * This extension allows you to create task items.
49
+ * @see https://www.tiptap.dev/api/nodes/task-item
50
+ */
51
+ declare const TaskItem: Node$1<TaskItemOptions, any>;
52
+
53
+ export { TaskItem, type TaskItemOptions, inputRegex };
@@ -0,0 +1,171 @@
1
+ // src/task-item/task-item.ts
2
+ import { mergeAttributes, Node, wrappingInputRule } from "@tiptap/core";
3
+ var inputRegex = /^\s*(\[([( |x])?\])\s$/;
4
+ var TaskItem = Node.create({
5
+ name: "taskItem",
6
+ addOptions() {
7
+ return {
8
+ nested: false,
9
+ HTMLAttributes: {},
10
+ taskListTypeName: "taskList",
11
+ a11y: void 0
12
+ };
13
+ },
14
+ content() {
15
+ return this.options.nested ? "paragraph block*" : "paragraph+";
16
+ },
17
+ defining: true,
18
+ addAttributes() {
19
+ return {
20
+ checked: {
21
+ default: false,
22
+ keepOnSplit: false,
23
+ parseHTML: (element) => {
24
+ const dataChecked = element.getAttribute("data-checked");
25
+ return dataChecked === "" || dataChecked === "true";
26
+ },
27
+ renderHTML: (attributes) => ({
28
+ "data-checked": attributes.checked
29
+ })
30
+ }
31
+ };
32
+ },
33
+ parseHTML() {
34
+ return [
35
+ {
36
+ tag: `li[data-type="${this.name}"]`,
37
+ priority: 51
38
+ }
39
+ ];
40
+ },
41
+ renderHTML({ node, HTMLAttributes }) {
42
+ return [
43
+ "li",
44
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
45
+ "data-type": this.name
46
+ }),
47
+ [
48
+ "label",
49
+ [
50
+ "input",
51
+ {
52
+ type: "checkbox",
53
+ checked: node.attrs.checked ? "checked" : null
54
+ }
55
+ ],
56
+ ["span"]
57
+ ],
58
+ ["div", 0]
59
+ ];
60
+ },
61
+ addKeyboardShortcuts() {
62
+ const shortcuts = {
63
+ Enter: () => this.editor.commands.splitListItem(this.name),
64
+ "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
65
+ };
66
+ if (!this.options.nested) {
67
+ return shortcuts;
68
+ }
69
+ return {
70
+ ...shortcuts,
71
+ Tab: () => this.editor.commands.sinkListItem(this.name)
72
+ };
73
+ },
74
+ addNodeView() {
75
+ return ({ node, HTMLAttributes, getPos, editor }) => {
76
+ const listItem = document.createElement("li");
77
+ const checkboxWrapper = document.createElement("label");
78
+ const checkboxStyler = document.createElement("span");
79
+ const checkbox = document.createElement("input");
80
+ const content = document.createElement("div");
81
+ const updateA11Y = () => {
82
+ var _a, _b;
83
+ checkbox.ariaLabel = ((_b = (_a = this.options.a11y) == null ? void 0 : _a.checkboxLabel) == null ? void 0 : _b.call(_a, node, checkbox.checked)) || `Task item checkbox for ${node.textContent || "empty task item"}`;
84
+ };
85
+ updateA11Y();
86
+ checkboxWrapper.contentEditable = "false";
87
+ checkbox.type = "checkbox";
88
+ checkbox.addEventListener("mousedown", (event) => event.preventDefault());
89
+ checkbox.addEventListener("change", (event) => {
90
+ if (!editor.isEditable && !this.options.onReadOnlyChecked) {
91
+ checkbox.checked = !checkbox.checked;
92
+ return;
93
+ }
94
+ const { checked } = event.target;
95
+ if (editor.isEditable && typeof getPos === "function") {
96
+ editor.chain().focus(void 0, { scrollIntoView: false }).command(({ tr }) => {
97
+ const position = getPos();
98
+ if (typeof position !== "number") {
99
+ return false;
100
+ }
101
+ const currentNode = tr.doc.nodeAt(position);
102
+ tr.setNodeMarkup(position, void 0, {
103
+ ...currentNode == null ? void 0 : currentNode.attrs,
104
+ checked
105
+ });
106
+ return true;
107
+ }).run();
108
+ }
109
+ if (!editor.isEditable && this.options.onReadOnlyChecked) {
110
+ const result = this.options.onReadOnlyChecked(node, checked);
111
+ if (result === false) {
112
+ checkbox.checked = !checkbox.checked;
113
+ } else if (result === true) {
114
+ } else if (result === "updateEditorContent") {
115
+ editor.chain().command(({ tr }) => {
116
+ const position = getPos();
117
+ if (typeof position !== "number") {
118
+ return false;
119
+ }
120
+ const currentNode = tr.doc.nodeAt(position);
121
+ tr.setNodeMarkup(position, void 0, {
122
+ ...currentNode == null ? void 0 : currentNode.attrs,
123
+ checked
124
+ });
125
+ return true;
126
+ }).run();
127
+ }
128
+ }
129
+ });
130
+ Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {
131
+ listItem.setAttribute(key, value);
132
+ });
133
+ listItem.dataset.checked = node.attrs.checked;
134
+ checkbox.checked = node.attrs.checked;
135
+ checkboxWrapper.append(checkbox, checkboxStyler);
136
+ listItem.append(checkboxWrapper, content);
137
+ Object.entries(HTMLAttributes).forEach(([key, value]) => {
138
+ listItem.setAttribute(key, value);
139
+ });
140
+ return {
141
+ dom: listItem,
142
+ contentDOM: content,
143
+ update: (updatedNode) => {
144
+ if (updatedNode.type !== this.type) {
145
+ return false;
146
+ }
147
+ listItem.dataset.checked = updatedNode.attrs.checked;
148
+ checkbox.checked = updatedNode.attrs.checked;
149
+ updateA11Y();
150
+ return true;
151
+ }
152
+ };
153
+ };
154
+ },
155
+ addInputRules() {
156
+ return [
157
+ wrappingInputRule({
158
+ find: inputRegex,
159
+ type: this.type,
160
+ getAttributes: (match) => ({
161
+ checked: match[match.length - 1] === "x"
162
+ })
163
+ })
164
+ ];
165
+ }
166
+ });
167
+ export {
168
+ TaskItem,
169
+ inputRegex
170
+ };
171
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/task-item/task-item.ts"],"sourcesContent":["import type { KeyboardShortcutCommand } from '@tiptap/core'\nimport { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\nimport type { 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 whether the change to the checkbox state should be accepted or reverted - or whether the editor content should be updated\n */\n onReadOnlyChecked?: (node: ProseMirrorNode, checked: boolean) => boolean | 'updateEditorContent'\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 * Accessibility options for the task item.\n * @default {}\n * @example\n * ```js\n * {\n * checkboxLabel: (node) => `Task item: ${node.textContent || 'empty task item'}`\n * }\n */\n a11y?: {\n checkboxLabel?: (node: ProseMirrorNode, checked: boolean) => string\n }\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 a11y: undefined,\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 ({ node, HTMLAttributes, getPos, editor }) => {\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 const updateA11Y = () => {\n checkbox.ariaLabel =\n this.options.a11y?.checkboxLabel?.(node, checkbox.checked) ||\n `Task item checkbox for ${node.textContent || 'empty task item'}`\n }\n\n updateA11Y()\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 const result = this.options.onReadOnlyChecked(node, checked)\n if (result === false) {\n checkbox.checked = !checkbox.checked\n } else if (result === true) {\n // simply accept the change and do nothing\n } else if (result === 'updateEditorContent') {\n // update the editor content to reflect the change\n editor\n .chain()\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 }\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 updateA11Y()\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"],"mappings":";AACA,SAAS,iBAAiB,MAAM,yBAAyB;AAkDlD,IAAM,aAAa;AAMnB,IAAM,WAAW,KAAK,OAAwB;AAAA,EACnD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,gBAAgB,CAAC;AAAA,MACjB,kBAAkB;AAAA,MAClB,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,UAAU;AACR,WAAO,KAAK,QAAQ,SAAS,qBA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C;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,69 @@
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);
19
+
20
+ // src/task-list/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ TaskList: () => TaskList
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/task-list/task-list.ts
28
+ var import_core = require("@tiptap/core");
29
+ var TaskList = import_core.Node.create({
30
+ name: "taskList",
31
+ addOptions() {
32
+ return {
33
+ itemTypeName: "taskItem",
34
+ HTMLAttributes: {}
35
+ };
36
+ },
37
+ group: "block list",
38
+ content() {
39
+ return `${this.options.itemTypeName}+`;
40
+ },
41
+ parseHTML() {
42
+ return [
43
+ {
44
+ tag: `ul[data-type="${this.name}"]`,
45
+ priority: 51
46
+ }
47
+ ];
48
+ },
49
+ renderHTML({ HTMLAttributes }) {
50
+ return ["ul", (0, import_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, { "data-type": this.name }), 0];
51
+ },
52
+ addCommands() {
53
+ return {
54
+ toggleTaskList: () => ({ commands }) => {
55
+ return commands.toggleList(this.name, this.options.itemTypeName);
56
+ }
57
+ };
58
+ },
59
+ addKeyboardShortcuts() {
60
+ return {
61
+ "Mod-Shift-9": () => this.editor.commands.toggleTaskList()
62
+ };
63
+ }
64
+ });
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ TaskList
68
+ });
69
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/task-list/index.ts","../../src/task-list/task-list.ts"],"sourcesContent":["export * from './task-list.js'\n","import { mergeAttributes, Node } from '@tiptap/core'\n\nexport interface TaskListOptions {\n /**\n * The node type name for a task item.\n * @default 'taskItem'\n * @example 'myCustomTaskItem'\n */\n itemTypeName: string\n\n /**\n * The HTML attributes for a task list node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n taskList: {\n /**\n * Toggle a task list\n * @example editor.commands.toggleTaskList()\n */\n toggleTaskList: () => ReturnType\n }\n }\n}\n\n/**\n * This extension allows you to create task lists.\n * @see https://www.tiptap.dev/api/nodes/task-list\n */\nexport const TaskList = Node.create<TaskListOptions>({\n name: 'taskList',\n\n addOptions() {\n return {\n itemTypeName: 'taskItem',\n HTMLAttributes: {},\n }\n },\n\n group: 'block list',\n\n content() {\n return `${this.options.itemTypeName}+`\n },\n\n parseHTML() {\n return [\n {\n tag: `ul[data-type=\"${this.name}\"]`,\n priority: 51,\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { 'data-type': this.name }), 0]\n },\n\n addCommands() {\n return {\n toggleTaskList:\n () =>\n ({ commands }) => {\n return commands.toggleList(this.name, this.options.itemTypeName)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-9': () => this.editor.commands.toggleTaskList(),\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAsC;AAkC/B,IAAM,WAAW,iBAAK,OAAwB;AAAA,EACnD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,cAAc;AAAA,MACd,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,EAEP,UAAU;AACR,WAAO,GAAG,KAAK,QAAQ,YAAY;AAAA,EACrC;AAAA,EAEA,YAAY;AACV,WAAO;AAAA,MACL;AAAA,QACE,KAAK,iBAAiB,KAAK,IAAI;AAAA,QAC/B,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,UAAM,6BAAgB,KAAK,QAAQ,gBAAgB,gBAAgB,EAAE,aAAa,KAAK,KAAK,CAAC,GAAG,CAAC;AAAA,EAC3G;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,gBACE,MACA,CAAC,EAAE,SAAS,MAAM;AAChB,eAAO,SAAS,WAAW,KAAK,MAAM,KAAK,QAAQ,YAAY;AAAA,MACjE;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,eAAe,MAAM,KAAK,OAAO,SAAS,eAAe;AAAA,IAC3D;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,34 @@
1
+ import { Node } from '@tiptap/core';
2
+
3
+ interface TaskListOptions {
4
+ /**
5
+ * The node type name for a task item.
6
+ * @default 'taskItem'
7
+ * @example 'myCustomTaskItem'
8
+ */
9
+ itemTypeName: string;
10
+ /**
11
+ * The HTML attributes for a task list node.
12
+ * @default {}
13
+ * @example { class: 'foo' }
14
+ */
15
+ HTMLAttributes: Record<string, any>;
16
+ }
17
+ declare module '@tiptap/core' {
18
+ interface Commands<ReturnType> {
19
+ taskList: {
20
+ /**
21
+ * Toggle a task list
22
+ * @example editor.commands.toggleTaskList()
23
+ */
24
+ toggleTaskList: () => ReturnType;
25
+ };
26
+ }
27
+ }
28
+ /**
29
+ * This extension allows you to create task lists.
30
+ * @see https://www.tiptap.dev/api/nodes/task-list
31
+ */
32
+ declare const TaskList: Node<TaskListOptions, any>;
33
+
34
+ export { TaskList, type TaskListOptions };
@@ -0,0 +1,34 @@
1
+ import { Node } from '@tiptap/core';
2
+
3
+ interface TaskListOptions {
4
+ /**
5
+ * The node type name for a task item.
6
+ * @default 'taskItem'
7
+ * @example 'myCustomTaskItem'
8
+ */
9
+ itemTypeName: string;
10
+ /**
11
+ * The HTML attributes for a task list node.
12
+ * @default {}
13
+ * @example { class: 'foo' }
14
+ */
15
+ HTMLAttributes: Record<string, any>;
16
+ }
17
+ declare module '@tiptap/core' {
18
+ interface Commands<ReturnType> {
19
+ taskList: {
20
+ /**
21
+ * Toggle a task list
22
+ * @example editor.commands.toggleTaskList()
23
+ */
24
+ toggleTaskList: () => ReturnType;
25
+ };
26
+ }
27
+ }
28
+ /**
29
+ * This extension allows you to create task lists.
30
+ * @see https://www.tiptap.dev/api/nodes/task-list
31
+ */
32
+ declare const TaskList: Node<TaskListOptions, any>;
33
+
34
+ export { TaskList, type TaskListOptions };
@@ -0,0 +1,42 @@
1
+ // src/task-list/task-list.ts
2
+ import { mergeAttributes, Node } from "@tiptap/core";
3
+ var TaskList = Node.create({
4
+ name: "taskList",
5
+ addOptions() {
6
+ return {
7
+ itemTypeName: "taskItem",
8
+ HTMLAttributes: {}
9
+ };
10
+ },
11
+ group: "block list",
12
+ content() {
13
+ return `${this.options.itemTypeName}+`;
14
+ },
15
+ parseHTML() {
16
+ return [
17
+ {
18
+ tag: `ul[data-type="${this.name}"]`,
19
+ priority: 51
20
+ }
21
+ ];
22
+ },
23
+ renderHTML({ HTMLAttributes }) {
24
+ return ["ul", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { "data-type": this.name }), 0];
25
+ },
26
+ addCommands() {
27
+ return {
28
+ toggleTaskList: () => ({ commands }) => {
29
+ return commands.toggleList(this.name, this.options.itemTypeName);
30
+ }
31
+ };
32
+ },
33
+ addKeyboardShortcuts() {
34
+ return {
35
+ "Mod-Shift-9": () => this.editor.commands.toggleTaskList()
36
+ };
37
+ }
38
+ });
39
+ export {
40
+ TaskList
41
+ };
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/task-list/task-list.ts"],"sourcesContent":["import { mergeAttributes, Node } from '@tiptap/core'\n\nexport interface TaskListOptions {\n /**\n * The node type name for a task item.\n * @default 'taskItem'\n * @example 'myCustomTaskItem'\n */\n itemTypeName: string\n\n /**\n * The HTML attributes for a task list node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n taskList: {\n /**\n * Toggle a task list\n * @example editor.commands.toggleTaskList()\n */\n toggleTaskList: () => ReturnType\n }\n }\n}\n\n/**\n * This extension allows you to create task lists.\n * @see https://www.tiptap.dev/api/nodes/task-list\n */\nexport const TaskList = Node.create<TaskListOptions>({\n name: 'taskList',\n\n addOptions() {\n return {\n itemTypeName: 'taskItem',\n HTMLAttributes: {},\n }\n },\n\n group: 'block list',\n\n content() {\n return `${this.options.itemTypeName}+`\n },\n\n parseHTML() {\n return [\n {\n tag: `ul[data-type=\"${this.name}\"]`,\n priority: 51,\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { 'data-type': this.name }), 0]\n },\n\n addCommands() {\n return {\n toggleTaskList:\n () =>\n ({ commands }) => {\n return commands.toggleList(this.name, this.options.itemTypeName)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-9': () => this.editor.commands.toggleTaskList(),\n }\n },\n})\n"],"mappings":";AAAA,SAAS,iBAAiB,YAAY;AAkC/B,IAAM,WAAW,KAAK,OAAwB;AAAA,EACnD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,cAAc;AAAA,MACd,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,EAEP,UAAU;AACR,WAAO,GAAG,KAAK,QAAQ,YAAY;AAAA,EACrC;AAAA,EAEA,YAAY;AACV,WAAO;AAAA,MACL;AAAA,QACE,KAAK,iBAAiB,KAAK,IAAI;AAAA,QAC/B,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,MAAM,gBAAgB,KAAK,QAAQ,gBAAgB,gBAAgB,EAAE,aAAa,KAAK,KAAK,CAAC,GAAG,CAAC;AAAA,EAC3G;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,gBACE,MACA,CAAC,EAAE,SAAS,MAAM;AAChB,eAAO,SAAS,WAAW,KAAK,MAAM,KAAK,QAAQ,YAAY;AAAA,MACjE;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,eAAe,MAAM,KAAK,OAAO,SAAS,eAAe;AAAA,IAC3D;AAAA,EACF;AACF,CAAC;","names":[]}
package/package.json ADDED
@@ -0,0 +1,106 @@
1
+ {
2
+ "name": "@thomasjahoda-forks/tiptap-extension-list",
3
+ "description": "List extension for tiptap",
4
+ "version": "3.0.7",
5
+ "homepage": "https://tiptap.dev",
6
+ "keywords": [
7
+ "tiptap",
8
+ "tiptap extension"
9
+ ],
10
+ "license": "MIT",
11
+ "funding": {
12
+ "type": "github",
13
+ "url": "https://github.com/sponsors/ueberdosis"
14
+ },
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "types": {
19
+ "import": "./dist/index.d.ts",
20
+ "require": "./dist/index.d.cts"
21
+ },
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.cjs"
24
+ },
25
+ "./bullet-list": {
26
+ "types": {
27
+ "import": "./dist/bullet-list/index.d.ts",
28
+ "require": "./dist/bullet-list/index.d.cts"
29
+ },
30
+ "import": "./dist/bullet-list/index.js",
31
+ "require": "./dist/bullet-list/index.cjs"
32
+ },
33
+ "./item": {
34
+ "types": {
35
+ "import": "./dist/item/index.d.ts",
36
+ "require": "./dist/item/index.d.cts"
37
+ },
38
+ "import": "./dist/item/index.js",
39
+ "require": "./dist/item/index.cjs"
40
+ },
41
+ "./keymap": {
42
+ "types": {
43
+ "import": "./dist/keymap/index.d.ts",
44
+ "require": "./dist/keymap/index.d.cts"
45
+ },
46
+ "import": "./dist/keymap/index.js",
47
+ "require": "./dist/keymap/index.cjs"
48
+ },
49
+ "./kit": {
50
+ "types": {
51
+ "import": "./dist/kit/index.d.ts",
52
+ "require": "./dist/kit/index.d.cts"
53
+ },
54
+ "import": "./dist/kit/index.js",
55
+ "require": "./dist/kit/index.cjs"
56
+ },
57
+ "./ordered-list": {
58
+ "types": {
59
+ "import": "./dist/ordered-list/index.d.ts",
60
+ "require": "./dist/ordered-list/index.d.cts"
61
+ },
62
+ "import": "./dist/ordered-list/index.js",
63
+ "require": "./dist/ordered-list/index.cjs"
64
+ },
65
+ "./task-item": {
66
+ "types": {
67
+ "import": "./dist/task-item/index.d.ts",
68
+ "require": "./dist/task-item/index.d.cts"
69
+ },
70
+ "import": "./dist/task-item/index.js",
71
+ "require": "./dist/task-item/index.cjs"
72
+ },
73
+ "./task-list": {
74
+ "types": {
75
+ "import": "./dist/task-list/index.d.ts",
76
+ "require": "./dist/task-list/index.d.cts"
77
+ },
78
+ "import": "./dist/task-list/index.js",
79
+ "require": "./dist/task-list/index.cjs"
80
+ }
81
+ },
82
+ "main": "dist/index.cjs",
83
+ "module": "dist/index.js",
84
+ "types": "dist/index.d.ts",
85
+ "files": [
86
+ "src",
87
+ "dist"
88
+ ],
89
+ "devDependencies": {
90
+ "@tiptap/core": "^3.0.7",
91
+ "@tiptap/pm": "^3.0.7"
92
+ },
93
+ "peerDependencies": {
94
+ "@tiptap/core": "^3.0.7",
95
+ "@tiptap/pm": "^3.0.7"
96
+ },
97
+ "repository": {
98
+ "type": "git",
99
+ "url": "https://github.com/ueberdosis/tiptap",
100
+ "directory": "packages/extension-list"
101
+ },
102
+ "scripts": {
103
+ "build": "tsup",
104
+ "lint": "prettier ./src/ --check && eslint --cache --quiet --no-error-on-unmatched-pattern ./src/"
105
+ }
106
+ }