@tiptap/extension-list 3.0.0-beta.0

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 +714 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.cts +288 -0
  12. package/dist/index.d.ts +288 -0
  13. package/dist/index.js +683 -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 +692 -0
  28. package/dist/kit/index.cjs.map +1 -0
  29. package/dist/kit/index.d.cts +200 -0
  30. package/dist/kit/index.d.ts +200 -0
  31. package/dist/kit/index.js +673 -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 +177 -0
  40. package/dist/task-item/index.cjs.map +1 -0
  41. package/dist/task-item/index.d.cts +41 -0
  42. package/dist/task-item/index.d.ts +41 -0
  43. package/dist/task-item/index.js +149 -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 +220 -0
  75. package/src/task-list/index.ts +1 -0
  76. package/src/task-list/task-list.ts +79 -0
@@ -0,0 +1,41 @@
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
10
+ */
11
+ onReadOnlyChecked?: (node: Node, checked: boolean) => boolean;
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
+ /**
32
+ * Matches a task item to a - [ ] on input.
33
+ */
34
+ declare const inputRegex: RegExp;
35
+ /**
36
+ * This extension allows you to create task items.
37
+ * @see https://www.tiptap.dev/api/nodes/task-item
38
+ */
39
+ declare const TaskItem: Node$1<TaskItemOptions, any>;
40
+
41
+ export { TaskItem, type TaskItemOptions, inputRegex };
@@ -0,0 +1,41 @@
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
10
+ */
11
+ onReadOnlyChecked?: (node: Node, checked: boolean) => boolean;
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
+ /**
32
+ * Matches a task item to a - [ ] on input.
33
+ */
34
+ declare const inputRegex: RegExp;
35
+ /**
36
+ * This extension allows you to create task items.
37
+ * @see https://www.tiptap.dev/api/nodes/task-item
38
+ */
39
+ declare const TaskItem: Node$1<TaskItemOptions, any>;
40
+
41
+ export { TaskItem, type TaskItemOptions, inputRegex };
@@ -0,0 +1,149 @@
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
+ };
12
+ },
13
+ content() {
14
+ return this.options.nested ? "paragraph block*" : "paragraph+";
15
+ },
16
+ defining: true,
17
+ addAttributes() {
18
+ return {
19
+ checked: {
20
+ default: false,
21
+ keepOnSplit: false,
22
+ parseHTML: (element) => {
23
+ const dataChecked = element.getAttribute("data-checked");
24
+ return dataChecked === "" || dataChecked === "true";
25
+ },
26
+ renderHTML: (attributes) => ({
27
+ "data-checked": attributes.checked
28
+ })
29
+ }
30
+ };
31
+ },
32
+ parseHTML() {
33
+ return [
34
+ {
35
+ tag: `li[data-type="${this.name}"]`,
36
+ priority: 51
37
+ }
38
+ ];
39
+ },
40
+ renderHTML({ node, HTMLAttributes }) {
41
+ return [
42
+ "li",
43
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
44
+ "data-type": this.name
45
+ }),
46
+ [
47
+ "label",
48
+ [
49
+ "input",
50
+ {
51
+ type: "checkbox",
52
+ checked: node.attrs.checked ? "checked" : null
53
+ }
54
+ ],
55
+ ["span"]
56
+ ],
57
+ ["div", 0]
58
+ ];
59
+ },
60
+ addKeyboardShortcuts() {
61
+ const shortcuts = {
62
+ Enter: () => this.editor.commands.splitListItem(this.name),
63
+ "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
64
+ };
65
+ if (!this.options.nested) {
66
+ return shortcuts;
67
+ }
68
+ return {
69
+ ...shortcuts,
70
+ Tab: () => this.editor.commands.sinkListItem(this.name)
71
+ };
72
+ },
73
+ addNodeView() {
74
+ return ({ node, HTMLAttributes, getPos, editor }) => {
75
+ const listItem = document.createElement("li");
76
+ const checkboxWrapper = document.createElement("label");
77
+ const checkboxStyler = document.createElement("span");
78
+ const checkbox = document.createElement("input");
79
+ const content = document.createElement("div");
80
+ checkboxWrapper.contentEditable = "false";
81
+ checkbox.type = "checkbox";
82
+ checkbox.addEventListener("mousedown", (event) => event.preventDefault());
83
+ checkbox.addEventListener("change", (event) => {
84
+ if (!editor.isEditable && !this.options.onReadOnlyChecked) {
85
+ checkbox.checked = !checkbox.checked;
86
+ return;
87
+ }
88
+ const { checked } = event.target;
89
+ if (editor.isEditable && typeof getPos === "function") {
90
+ editor.chain().focus(void 0, { scrollIntoView: false }).command(({ tr }) => {
91
+ const position = getPos();
92
+ if (typeof position !== "number") {
93
+ return false;
94
+ }
95
+ const currentNode = tr.doc.nodeAt(position);
96
+ tr.setNodeMarkup(position, void 0, {
97
+ ...currentNode == null ? void 0 : currentNode.attrs,
98
+ checked
99
+ });
100
+ return true;
101
+ }).run();
102
+ }
103
+ if (!editor.isEditable && this.options.onReadOnlyChecked) {
104
+ if (!this.options.onReadOnlyChecked(node, checked)) {
105
+ checkbox.checked = !checkbox.checked;
106
+ }
107
+ }
108
+ });
109
+ Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {
110
+ listItem.setAttribute(key, value);
111
+ });
112
+ listItem.dataset.checked = node.attrs.checked;
113
+ checkbox.checked = node.attrs.checked;
114
+ checkboxWrapper.append(checkbox, checkboxStyler);
115
+ listItem.append(checkboxWrapper, content);
116
+ Object.entries(HTMLAttributes).forEach(([key, value]) => {
117
+ listItem.setAttribute(key, value);
118
+ });
119
+ return {
120
+ dom: listItem,
121
+ contentDOM: content,
122
+ update: (updatedNode) => {
123
+ if (updatedNode.type !== this.type) {
124
+ return false;
125
+ }
126
+ listItem.dataset.checked = updatedNode.attrs.checked;
127
+ checkbox.checked = updatedNode.attrs.checked;
128
+ return true;
129
+ }
130
+ };
131
+ };
132
+ },
133
+ addInputRules() {
134
+ return [
135
+ wrappingInputRule({
136
+ find: inputRegex,
137
+ type: this.type,
138
+ getAttributes: (match) => ({
139
+ checked: match[match.length - 1] === "x"
140
+ })
141
+ })
142
+ ];
143
+ }
144
+ });
145
+ export {
146
+ TaskItem,
147
+ inputRegex
148
+ };
149
+ //# 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\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 ({ 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 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"],"mappings":";AACA,SAAS,iBAAiB,MAAM,yBAAyB;AAqClD,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,IACpB;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;AAAA,QACb,WAAW,aAAW;AACpB,gBAAM,cAAc,QAAQ,aAAa,cAAc;AAEvD,iBAAO,gBAAgB,MAAM,gBAAgB;AAAA,QAC/C;AAAA,QACA,YAAY,iBAAe;AAAA,UACzB,gBAAgB,WAAW;AAAA,QAC7B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,YAAY;AACV,WAAO;AAAA,MACL;AAAA,QACE,KAAK,iBAAiB,KAAK,IAAI;AAAA,QAC/B,UAAU;AAAA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AAA,QACT;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,gBAAgB;AACd,WAAO;AAAA,MACL,kBAAkB;AAAA,QAChB,MAAM;AAAA,QACN,MAAM,KAAK;AAAA,QACX,eAAe,YAAU;AAAA,UACvB,SAAS,MAAM,MAAM,SAAS,CAAC,MAAM;AAAA,QACvC;AAAA,MACF,CAAC;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": "@tiptap/extension-list",
3
+ "description": "List extension for tiptap",
4
+ "version": "3.0.0-beta.0",
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.0-beta.0",
91
+ "@tiptap/pm": "^3.0.0-beta.0"
92
+ },
93
+ "peerDependencies": {
94
+ "@tiptap/core": "^3.0.0-beta.0",
95
+ "@tiptap/pm": "^3.0.0-beta.0"
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
+ }
@@ -0,0 +1,126 @@
1
+ import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'
2
+
3
+ const ListItemName = 'listItem'
4
+ const TextStyleName = 'textStyle'
5
+
6
+ export interface BulletListOptions {
7
+ /**
8
+ * The node name for the list items
9
+ * @default 'listItem'
10
+ * @example 'paragraph'
11
+ */
12
+ itemTypeName: string
13
+
14
+ /**
15
+ * HTML attributes to add to the bullet list element
16
+ * @default {}
17
+ * @example { class: 'foo' }
18
+ */
19
+ HTMLAttributes: Record<string, any>
20
+
21
+ /**
22
+ * Keep the marks when splitting the list
23
+ * @default false
24
+ * @example true
25
+ */
26
+ keepMarks: boolean
27
+
28
+ /**
29
+ * Keep the attributes when splitting the list
30
+ * @default false
31
+ * @example true
32
+ */
33
+ keepAttributes: boolean
34
+ }
35
+
36
+ declare module '@tiptap/core' {
37
+ interface Commands<ReturnType> {
38
+ bulletList: {
39
+ /**
40
+ * Toggle a bullet list
41
+ */
42
+ toggleBulletList: () => ReturnType
43
+ }
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Matches a bullet list to a dash or asterisk.
49
+ */
50
+ export const bulletListInputRegex = /^\s*([-+*])\s$/
51
+
52
+ /**
53
+ * This extension allows you to create bullet lists.
54
+ * This requires the ListItem extension
55
+ * @see https://tiptap.dev/api/nodes/bullet-list
56
+ * @see https://tiptap.dev/api/nodes/list-item.
57
+ */
58
+ export const BulletList = Node.create<BulletListOptions>({
59
+ name: 'bulletList',
60
+
61
+ addOptions() {
62
+ return {
63
+ itemTypeName: 'listItem',
64
+ HTMLAttributes: {},
65
+ keepMarks: false,
66
+ keepAttributes: false,
67
+ }
68
+ },
69
+
70
+ group: 'block list',
71
+
72
+ content() {
73
+ return `${this.options.itemTypeName}+`
74
+ },
75
+
76
+ parseHTML() {
77
+ return [{ tag: 'ul' }]
78
+ },
79
+
80
+ renderHTML({ HTMLAttributes }) {
81
+ return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
82
+ },
83
+
84
+ addCommands() {
85
+ return {
86
+ toggleBulletList:
87
+ () =>
88
+ ({ commands, chain }) => {
89
+ if (this.options.keepAttributes) {
90
+ return chain()
91
+ .toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)
92
+ .updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName))
93
+ .run()
94
+ }
95
+ return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)
96
+ },
97
+ }
98
+ },
99
+
100
+ addKeyboardShortcuts() {
101
+ return {
102
+ 'Mod-Shift-8': () => this.editor.commands.toggleBulletList(),
103
+ }
104
+ },
105
+
106
+ addInputRules() {
107
+ let inputRule = wrappingInputRule({
108
+ find: bulletListInputRegex,
109
+ type: this.type,
110
+ })
111
+
112
+ if (this.options.keepMarks || this.options.keepAttributes) {
113
+ inputRule = wrappingInputRule({
114
+ find: bulletListInputRegex,
115
+ type: this.type,
116
+ keepMarks: this.options.keepMarks,
117
+ keepAttributes: this.options.keepAttributes,
118
+ getAttributes: () => {
119
+ return this.editor.getAttributes(TextStyleName)
120
+ },
121
+ editor: this.editor,
122
+ })
123
+ }
124
+ return [inputRule]
125
+ },
126
+ })
@@ -0,0 +1 @@
1
+ export * from './bullet-list.js'