@tiptap/extension-task-item 2.0.0-beta.21 → 2.0.0-beta.211

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/dist/index.cjs ADDED
@@ -0,0 +1,155 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/task-item.ts
2
+ var _core = require('@tiptap/core');
3
+ var inputRegex = /^\s*(\[([( |x])?\])\s$/;
4
+ var TaskItem = _core.Node.create({
5
+ name: "taskItem",
6
+ addOptions() {
7
+ return {
8
+ nested: false,
9
+ HTMLAttributes: {}
10
+ };
11
+ },
12
+ content() {
13
+ return this.options.nested ? "paragraph block*" : "paragraph+";
14
+ },
15
+ defining: true,
16
+ addAttributes() {
17
+ return {
18
+ checked: {
19
+ default: false,
20
+ keepOnSplit: false,
21
+ parseHTML: (element) => element.getAttribute("data-checked") === "true",
22
+ renderHTML: (attributes) => ({
23
+ "data-checked": attributes.checked
24
+ })
25
+ }
26
+ };
27
+ },
28
+ parseHTML() {
29
+ return [
30
+ {
31
+ tag: `li[data-type="${this.name}"]`,
32
+ priority: 51
33
+ }
34
+ ];
35
+ },
36
+ renderHTML({ node, HTMLAttributes }) {
37
+ return [
38
+ "li",
39
+ _core.mergeAttributes.call(void 0, this.options.HTMLAttributes, HTMLAttributes, {
40
+ "data-type": this.name
41
+ }),
42
+ [
43
+ "label",
44
+ [
45
+ "input",
46
+ {
47
+ type: "checkbox",
48
+ checked: node.attrs.checked ? "checked" : null
49
+ }
50
+ ],
51
+ ["span"]
52
+ ],
53
+ ["div", 0]
54
+ ];
55
+ },
56
+ addKeyboardShortcuts() {
57
+ const shortcuts = {
58
+ Enter: () => this.editor.commands.splitListItem(this.name),
59
+ "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
60
+ };
61
+ if (!this.options.nested) {
62
+ return shortcuts;
63
+ }
64
+ return {
65
+ ...shortcuts,
66
+ Tab: () => this.editor.commands.sinkListItem(this.name)
67
+ };
68
+ },
69
+ addNodeView() {
70
+ return ({
71
+ node,
72
+ HTMLAttributes,
73
+ getPos,
74
+ editor
75
+ }) => {
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
+ checkboxWrapper.contentEditable = "false";
82
+ checkbox.type = "checkbox";
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
+ const currentNode = tr.doc.nodeAt(position);
93
+ tr.setNodeMarkup(position, void 0, {
94
+ ...currentNode == null ? void 0 : currentNode.attrs,
95
+ checked
96
+ });
97
+ return true;
98
+ }).run();
99
+ }
100
+ if (!editor.isEditable && this.options.onReadOnlyChecked) {
101
+ if (!this.options.onReadOnlyChecked(node, checked)) {
102
+ checkbox.checked = !checkbox.checked;
103
+ }
104
+ }
105
+ });
106
+ Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {
107
+ listItem.setAttribute(key, value);
108
+ });
109
+ listItem.dataset.checked = node.attrs.checked;
110
+ if (node.attrs.checked) {
111
+ checkbox.setAttribute("checked", "checked");
112
+ }
113
+ checkboxWrapper.append(checkbox, checkboxStyler);
114
+ listItem.append(checkboxWrapper, content);
115
+ Object.entries(HTMLAttributes).forEach(([key, value]) => {
116
+ listItem.setAttribute(key, value);
117
+ });
118
+ return {
119
+ dom: listItem,
120
+ contentDOM: content,
121
+ update: (updatedNode) => {
122
+ if (updatedNode.type !== this.type) {
123
+ return false;
124
+ }
125
+ listItem.dataset.checked = updatedNode.attrs.checked;
126
+ if (updatedNode.attrs.checked) {
127
+ checkbox.setAttribute("checked", "checked");
128
+ } else {
129
+ checkbox.removeAttribute("checked");
130
+ }
131
+ return true;
132
+ }
133
+ };
134
+ };
135
+ },
136
+ addInputRules() {
137
+ return [
138
+ _core.wrappingInputRule.call(void 0, {
139
+ find: inputRegex,
140
+ type: this.type,
141
+ getAttributes: (match) => ({
142
+ checked: match[match.length - 1] === "x"
143
+ })
144
+ })
145
+ ];
146
+ }
147
+ });
148
+
149
+ // src/index.ts
150
+ var src_default = TaskItem;
151
+
152
+
153
+
154
+
155
+ exports.TaskItem = TaskItem; exports.default = src_default; exports.inputRegex = inputRegex;
@@ -0,0 +1,12 @@
1
+ import { Node as Node$1 } from '@tiptap/core';
2
+ import { Node } from '@tiptap/pm/model';
3
+
4
+ interface TaskItemOptions {
5
+ onReadOnlyChecked?: (node: Node, checked: boolean) => boolean;
6
+ nested: boolean;
7
+ HTMLAttributes: Record<string, any>;
8
+ }
9
+ declare const inputRegex: RegExp;
10
+ declare const TaskItem: Node$1<TaskItemOptions, any>;
11
+
12
+ export { TaskItem, TaskItemOptions, TaskItem as default, inputRegex };
package/dist/index.js ADDED
@@ -0,0 +1,155 @@
1
+ // src/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
+ };
11
+ },
12
+ content() {
13
+ return this.options.nested ? "paragraph block*" : "paragraph+";
14
+ },
15
+ defining: true,
16
+ addAttributes() {
17
+ return {
18
+ checked: {
19
+ default: false,
20
+ keepOnSplit: false,
21
+ parseHTML: (element) => element.getAttribute("data-checked") === "true",
22
+ renderHTML: (attributes) => ({
23
+ "data-checked": attributes.checked
24
+ })
25
+ }
26
+ };
27
+ },
28
+ parseHTML() {
29
+ return [
30
+ {
31
+ tag: `li[data-type="${this.name}"]`,
32
+ priority: 51
33
+ }
34
+ ];
35
+ },
36
+ renderHTML({ node, HTMLAttributes }) {
37
+ return [
38
+ "li",
39
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
40
+ "data-type": this.name
41
+ }),
42
+ [
43
+ "label",
44
+ [
45
+ "input",
46
+ {
47
+ type: "checkbox",
48
+ checked: node.attrs.checked ? "checked" : null
49
+ }
50
+ ],
51
+ ["span"]
52
+ ],
53
+ ["div", 0]
54
+ ];
55
+ },
56
+ addKeyboardShortcuts() {
57
+ const shortcuts = {
58
+ Enter: () => this.editor.commands.splitListItem(this.name),
59
+ "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
60
+ };
61
+ if (!this.options.nested) {
62
+ return shortcuts;
63
+ }
64
+ return {
65
+ ...shortcuts,
66
+ Tab: () => this.editor.commands.sinkListItem(this.name)
67
+ };
68
+ },
69
+ addNodeView() {
70
+ return ({
71
+ node,
72
+ HTMLAttributes,
73
+ getPos,
74
+ editor
75
+ }) => {
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
+ checkboxWrapper.contentEditable = "false";
82
+ checkbox.type = "checkbox";
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
+ const currentNode = tr.doc.nodeAt(position);
93
+ tr.setNodeMarkup(position, void 0, {
94
+ ...currentNode == null ? void 0 : currentNode.attrs,
95
+ checked
96
+ });
97
+ return true;
98
+ }).run();
99
+ }
100
+ if (!editor.isEditable && this.options.onReadOnlyChecked) {
101
+ if (!this.options.onReadOnlyChecked(node, checked)) {
102
+ checkbox.checked = !checkbox.checked;
103
+ }
104
+ }
105
+ });
106
+ Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {
107
+ listItem.setAttribute(key, value);
108
+ });
109
+ listItem.dataset.checked = node.attrs.checked;
110
+ if (node.attrs.checked) {
111
+ checkbox.setAttribute("checked", "checked");
112
+ }
113
+ checkboxWrapper.append(checkbox, checkboxStyler);
114
+ listItem.append(checkboxWrapper, content);
115
+ Object.entries(HTMLAttributes).forEach(([key, value]) => {
116
+ listItem.setAttribute(key, value);
117
+ });
118
+ return {
119
+ dom: listItem,
120
+ contentDOM: content,
121
+ update: (updatedNode) => {
122
+ if (updatedNode.type !== this.type) {
123
+ return false;
124
+ }
125
+ listItem.dataset.checked = updatedNode.attrs.checked;
126
+ if (updatedNode.attrs.checked) {
127
+ checkbox.setAttribute("checked", "checked");
128
+ } else {
129
+ checkbox.removeAttribute("checked");
130
+ }
131
+ return true;
132
+ }
133
+ };
134
+ };
135
+ },
136
+ addInputRules() {
137
+ return [
138
+ wrappingInputRule({
139
+ find: inputRegex,
140
+ type: this.type,
141
+ getAttributes: (match) => ({
142
+ checked: match[match.length - 1] === "x"
143
+ })
144
+ })
145
+ ];
146
+ }
147
+ });
148
+
149
+ // src/index.ts
150
+ var src_default = TaskItem;
151
+ export {
152
+ TaskItem,
153
+ src_default as default,
154
+ inputRegex
155
+ };
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.0.0-beta.21",
4
+ "version": "2.0.0-beta.211",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -12,21 +12,46 @@
12
12
  "type": "github",
13
13
  "url": "https://github.com/sponsors/ueberdosis"
14
14
  },
15
- "main": "dist/tiptap-extension-task-item.cjs.js",
16
- "umd": "dist/tiptap-extension-task-item.umd.js",
17
- "module": "dist/tiptap-extension-task-item.esm.js",
18
- "types": "dist/packages/extension-task-item/src/index.d.ts",
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.cjs"
21
+ }
22
+ },
23
+ "main": "dist/index.cjs",
24
+ "module": "dist/index.js",
25
+ "types": "dist/index.d.ts",
19
26
  "files": [
20
27
  "src",
21
28
  "dist"
22
29
  ],
23
30
  "peerDependencies": {
24
- "@tiptap/core": "^2.0.0-beta.1"
31
+ "@tiptap/core": "^2.0.0-beta.209",
32
+ "@tiptap/pm": "^2.0.0-beta.209"
33
+ },
34
+ "devDependencies": {
35
+ "@tiptap/core": "^2.0.0-beta.211",
36
+ "@tiptap/pm": "^2.0.0-beta.211"
25
37
  },
26
38
  "repository": {
27
39
  "type": "git",
28
40
  "url": "https://github.com/ueberdosis/tiptap",
29
41
  "directory": "packages/extension-task-item"
30
42
  },
31
- "gitHead": "9948e2499a3aa6ca72b677ef2ca96de1db1cb6b5"
43
+ "scripts": {
44
+ "build": "tsup"
45
+ },
46
+ "tsup": {
47
+ "entry": [
48
+ "src/index.ts"
49
+ ],
50
+ "dts": true,
51
+ "splitting": true,
52
+ "format": [
53
+ "esm",
54
+ "cjs"
55
+ ]
56
+ }
32
57
  }
package/src/task-item.ts CHANGED
@@ -1,18 +1,22 @@
1
- import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core'
1
+ import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'
2
+ import { Node as ProseMirrorNode } from '@tiptap/pm/model'
2
3
 
3
4
  export interface TaskItemOptions {
4
- nested: boolean,
5
- HTMLAttributes: Record<string, any>,
5
+ onReadOnlyChecked?: (node: ProseMirrorNode, checked: boolean) => boolean
6
+ nested: boolean
7
+ HTMLAttributes: Record<string, any>
6
8
  }
7
9
 
8
- export const inputRegex = /^\s*(\[([ |x])\])\s$/
10
+ export const inputRegex = /^\s*(\[([( |x])?\])\s$/
9
11
 
10
12
  export const TaskItem = Node.create<TaskItemOptions>({
11
13
  name: 'taskItem',
12
14
 
13
- defaultOptions: {
14
- nested: false,
15
- HTMLAttributes: {},
15
+ addOptions() {
16
+ return {
17
+ nested: false,
18
+ HTMLAttributes: {},
19
+ }
16
20
  },
17
21
 
18
22
  content() {
@@ -37,24 +41,37 @@ export const TaskItem = Node.create<TaskItemOptions>({
37
41
  parseHTML() {
38
42
  return [
39
43
  {
40
- tag: 'li[data-type="taskItem"]',
44
+ tag: `li[data-type="${this.name}"]`,
41
45
  priority: 51,
42
46
  },
43
47
  ]
44
48
  },
45
49
 
46
- renderHTML({ HTMLAttributes }) {
47
- return ['li', mergeAttributes(
48
- this.options.HTMLAttributes,
49
- HTMLAttributes,
50
- { 'data-type': 'taskItem' },
51
- ), 0]
50
+ renderHTML({ node, HTMLAttributes }) {
51
+ return [
52
+ 'li',
53
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
54
+ 'data-type': this.name,
55
+ }),
56
+ [
57
+ 'label',
58
+ [
59
+ 'input',
60
+ {
61
+ type: 'checkbox',
62
+ checked: node.attrs.checked ? 'checked' : null,
63
+ },
64
+ ],
65
+ ['span'],
66
+ ],
67
+ ['div', 0],
68
+ ]
52
69
  },
53
70
 
54
71
  addKeyboardShortcuts() {
55
72
  const shortcuts = {
56
- Enter: () => this.editor.commands.splitListItem('taskItem'),
57
- 'Shift-Tab': () => this.editor.commands.liftListItem('taskItem'),
73
+ Enter: () => this.editor.commands.splitListItem(this.name),
74
+ 'Shift-Tab': () => this.editor.commands.liftListItem(this.name),
58
75
  }
59
76
 
60
77
  if (!this.options.nested) {
@@ -63,16 +80,13 @@ export const TaskItem = Node.create<TaskItemOptions>({
63
80
 
64
81
  return {
65
82
  ...shortcuts,
66
- Tab: () => this.editor.commands.sinkListItem('taskItem'),
83
+ Tab: () => this.editor.commands.sinkListItem(this.name),
67
84
  }
68
85
  },
69
86
 
70
87
  addNodeView() {
71
88
  return ({
72
- node,
73
- HTMLAttributes,
74
- getPos,
75
- editor,
89
+ node, HTMLAttributes, getPos, editor,
76
90
  }) => {
77
91
  const listItem = document.createElement('li')
78
92
  const checkboxWrapper = document.createElement('label')
@@ -83,9 +97,9 @@ export const TaskItem = Node.create<TaskItemOptions>({
83
97
  checkboxWrapper.contentEditable = 'false'
84
98
  checkbox.type = 'checkbox'
85
99
  checkbox.addEventListener('change', event => {
86
- // if the editor isn’t editable
87
- // we have to undo the latest change
88
- if (!editor.isEditable) {
100
+ // if the editor isn’t editable and we don't have a handler for
101
+ // readonly checks we have to undo the latest change
102
+ if (!editor.isEditable && !this.options.onReadOnlyChecked) {
89
103
  checkbox.checked = !checkbox.checked
90
104
 
91
105
  return
@@ -96,9 +110,13 @@ export const TaskItem = Node.create<TaskItemOptions>({
96
110
  if (editor.isEditable && typeof getPos === 'function') {
97
111
  editor
98
112
  .chain()
99
- .focus()
113
+ .focus(undefined, { scrollIntoView: false })
100
114
  .command(({ tr }) => {
101
- tr.setNodeMarkup(getPos(), undefined, {
115
+ const position = getPos()
116
+ const currentNode = tr.doc.nodeAt(position)
117
+
118
+ tr.setNodeMarkup(position, undefined, {
119
+ ...currentNode?.attrs,
102
120
  checked,
103
121
  })
104
122
 
@@ -106,6 +124,16 @@ export const TaskItem = Node.create<TaskItemOptions>({
106
124
  })
107
125
  .run()
108
126
  }
127
+ if (!editor.isEditable && this.options.onReadOnlyChecked) {
128
+ // Reset state if onReadOnlyChecked returns false
129
+ if (!this.options.onReadOnlyChecked(node, checked)) {
130
+ checkbox.checked = !checkbox.checked
131
+ }
132
+ }
133
+ })
134
+
135
+ Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {
136
+ listItem.setAttribute(key, value)
109
137
  })
110
138
 
111
139
  listItem.dataset.checked = node.attrs.checked
@@ -116,11 +144,9 @@ export const TaskItem = Node.create<TaskItemOptions>({
116
144
  checkboxWrapper.append(checkbox, checkboxStyler)
117
145
  listItem.append(checkboxWrapper, content)
118
146
 
119
- Object
120
- .entries(HTMLAttributes)
121
- .forEach(([key, value]) => {
122
- listItem.setAttribute(key, value)
123
- })
147
+ Object.entries(HTMLAttributes).forEach(([key, value]) => {
148
+ listItem.setAttribute(key, value)
149
+ })
124
150
 
125
151
  return {
126
152
  dom: listItem,
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021, überdosis GbR
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.
@@ -1,3 +0,0 @@
1
- import { TaskItem } from './task-item';
2
- export * from './task-item';
3
- export default TaskItem;
@@ -1,7 +0,0 @@
1
- import { Node } from '@tiptap/core';
2
- export interface TaskItemOptions {
3
- nested: boolean;
4
- HTMLAttributes: Record<string, any>;
5
- }
6
- export declare const inputRegex: RegExp;
7
- export declare const TaskItem: Node<TaskItemOptions>;
@@ -1,130 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var core = require('@tiptap/core');
6
-
7
- const inputRegex = /^\s*(\[([ |x])\])\s$/;
8
- const TaskItem = core.Node.create({
9
- name: 'taskItem',
10
- defaultOptions: {
11
- nested: false,
12
- HTMLAttributes: {},
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 => element.getAttribute('data-checked') === 'true',
24
- renderHTML: attributes => ({
25
- 'data-checked': attributes.checked,
26
- }),
27
- },
28
- };
29
- },
30
- parseHTML() {
31
- return [
32
- {
33
- tag: 'li[data-type="taskItem"]',
34
- priority: 51,
35
- },
36
- ];
37
- },
38
- renderHTML({ HTMLAttributes }) {
39
- return ['li', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { 'data-type': 'taskItem' }), 0];
40
- },
41
- addKeyboardShortcuts() {
42
- const shortcuts = {
43
- Enter: () => this.editor.commands.splitListItem('taskItem'),
44
- 'Shift-Tab': () => this.editor.commands.liftListItem('taskItem'),
45
- };
46
- if (!this.options.nested) {
47
- return shortcuts;
48
- }
49
- return {
50
- ...shortcuts,
51
- Tab: () => this.editor.commands.sinkListItem('taskItem'),
52
- };
53
- },
54
- addNodeView() {
55
- return ({ node, HTMLAttributes, getPos, editor, }) => {
56
- const listItem = document.createElement('li');
57
- const checkboxWrapper = document.createElement('label');
58
- const checkboxStyler = document.createElement('span');
59
- const checkbox = document.createElement('input');
60
- const content = document.createElement('div');
61
- checkboxWrapper.contentEditable = 'false';
62
- checkbox.type = 'checkbox';
63
- checkbox.addEventListener('change', event => {
64
- // if the editor isn’t editable
65
- // we have to undo the latest change
66
- if (!editor.isEditable) {
67
- checkbox.checked = !checkbox.checked;
68
- return;
69
- }
70
- const { checked } = event.target;
71
- if (editor.isEditable && typeof getPos === 'function') {
72
- editor
73
- .chain()
74
- .focus()
75
- .command(({ tr }) => {
76
- tr.setNodeMarkup(getPos(), undefined, {
77
- checked,
78
- });
79
- return true;
80
- })
81
- .run();
82
- }
83
- });
84
- listItem.dataset.checked = node.attrs.checked;
85
- if (node.attrs.checked) {
86
- checkbox.setAttribute('checked', 'checked');
87
- }
88
- checkboxWrapper.append(checkbox, checkboxStyler);
89
- listItem.append(checkboxWrapper, content);
90
- Object
91
- .entries(HTMLAttributes)
92
- .forEach(([key, value]) => {
93
- listItem.setAttribute(key, value);
94
- });
95
- return {
96
- dom: listItem,
97
- contentDOM: content,
98
- update: updatedNode => {
99
- if (updatedNode.type !== this.type) {
100
- return false;
101
- }
102
- listItem.dataset.checked = updatedNode.attrs.checked;
103
- if (updatedNode.attrs.checked) {
104
- checkbox.setAttribute('checked', 'checked');
105
- }
106
- else {
107
- checkbox.removeAttribute('checked');
108
- }
109
- return true;
110
- },
111
- };
112
- };
113
- },
114
- addInputRules() {
115
- return [
116
- core.wrappingInputRule({
117
- find: inputRegex,
118
- type: this.type,
119
- getAttributes: match => ({
120
- checked: match[match.length - 1] === 'x',
121
- }),
122
- }),
123
- ];
124
- },
125
- });
126
-
127
- exports.TaskItem = TaskItem;
128
- exports["default"] = TaskItem;
129
- exports.inputRegex = inputRegex;
130
- //# sourceMappingURL=tiptap-extension-task-item.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tiptap-extension-task-item.cjs.js","sources":["../src/task-item.ts"],"sourcesContent":["import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core'\n\nexport interface TaskItemOptions {\n nested: boolean,\n HTMLAttributes: Record<string, any>,\n}\n\nexport const inputRegex = /^\\s*(\\[([ |x])\\])\\s$/\n\nexport const TaskItem = Node.create<TaskItemOptions>({\n name: 'taskItem',\n\n defaultOptions: {\n nested: false,\n HTMLAttributes: {},\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 => element.getAttribute('data-checked') === 'true',\n renderHTML: attributes => ({\n 'data-checked': attributes.checked,\n }),\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'li[data-type=\"taskItem\"]',\n priority: 51,\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['li', mergeAttributes(\n this.options.HTMLAttributes,\n HTMLAttributes,\n { 'data-type': 'taskItem' },\n ), 0]\n },\n\n addKeyboardShortcuts() {\n const shortcuts = {\n Enter: () => this.editor.commands.splitListItem('taskItem'),\n 'Shift-Tab': () => this.editor.commands.liftListItem('taskItem'),\n }\n\n if (!this.options.nested) {\n return shortcuts\n }\n\n return {\n ...shortcuts,\n Tab: () => this.editor.commands.sinkListItem('taskItem'),\n }\n },\n\n addNodeView() {\n return ({\n node,\n HTMLAttributes,\n getPos,\n 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('change', event => {\n // if the editor isn’t editable\n // we have to undo the latest change\n if (!editor.isEditable) {\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()\n .command(({ tr }) => {\n tr.setNodeMarkup(getPos(), undefined, {\n checked,\n })\n\n return true\n })\n .run()\n }\n })\n\n listItem.dataset.checked = node.attrs.checked\n if (node.attrs.checked) {\n checkbox.setAttribute('checked', 'checked')\n }\n\n checkboxWrapper.append(checkbox, checkboxStyler)\n listItem.append(checkboxWrapper, content)\n\n Object\n .entries(HTMLAttributes)\n .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 if (updatedNode.attrs.checked) {\n checkbox.setAttribute('checked', 'checked')\n } else {\n checkbox.removeAttribute('checked')\n }\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 ]\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@ -1,124 +0,0 @@
1
- import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core';
2
-
3
- const inputRegex = /^\s*(\[([ |x])\])\s$/;
4
- const TaskItem = Node.create({
5
- name: 'taskItem',
6
- defaultOptions: {
7
- nested: false,
8
- HTMLAttributes: {},
9
- },
10
- content() {
11
- return this.options.nested ? 'paragraph block*' : 'paragraph+';
12
- },
13
- defining: true,
14
- addAttributes() {
15
- return {
16
- checked: {
17
- default: false,
18
- keepOnSplit: false,
19
- parseHTML: element => element.getAttribute('data-checked') === 'true',
20
- renderHTML: attributes => ({
21
- 'data-checked': attributes.checked,
22
- }),
23
- },
24
- };
25
- },
26
- parseHTML() {
27
- return [
28
- {
29
- tag: 'li[data-type="taskItem"]',
30
- priority: 51,
31
- },
32
- ];
33
- },
34
- renderHTML({ HTMLAttributes }) {
35
- return ['li', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { 'data-type': 'taskItem' }), 0];
36
- },
37
- addKeyboardShortcuts() {
38
- const shortcuts = {
39
- Enter: () => this.editor.commands.splitListItem('taskItem'),
40
- 'Shift-Tab': () => this.editor.commands.liftListItem('taskItem'),
41
- };
42
- if (!this.options.nested) {
43
- return shortcuts;
44
- }
45
- return {
46
- ...shortcuts,
47
- Tab: () => this.editor.commands.sinkListItem('taskItem'),
48
- };
49
- },
50
- addNodeView() {
51
- return ({ node, HTMLAttributes, getPos, editor, }) => {
52
- const listItem = document.createElement('li');
53
- const checkboxWrapper = document.createElement('label');
54
- const checkboxStyler = document.createElement('span');
55
- const checkbox = document.createElement('input');
56
- const content = document.createElement('div');
57
- checkboxWrapper.contentEditable = 'false';
58
- checkbox.type = 'checkbox';
59
- checkbox.addEventListener('change', event => {
60
- // if the editor isn’t editable
61
- // we have to undo the latest change
62
- if (!editor.isEditable) {
63
- checkbox.checked = !checkbox.checked;
64
- return;
65
- }
66
- const { checked } = event.target;
67
- if (editor.isEditable && typeof getPos === 'function') {
68
- editor
69
- .chain()
70
- .focus()
71
- .command(({ tr }) => {
72
- tr.setNodeMarkup(getPos(), undefined, {
73
- checked,
74
- });
75
- return true;
76
- })
77
- .run();
78
- }
79
- });
80
- listItem.dataset.checked = node.attrs.checked;
81
- if (node.attrs.checked) {
82
- checkbox.setAttribute('checked', 'checked');
83
- }
84
- checkboxWrapper.append(checkbox, checkboxStyler);
85
- listItem.append(checkboxWrapper, content);
86
- Object
87
- .entries(HTMLAttributes)
88
- .forEach(([key, value]) => {
89
- listItem.setAttribute(key, value);
90
- });
91
- return {
92
- dom: listItem,
93
- contentDOM: content,
94
- update: updatedNode => {
95
- if (updatedNode.type !== this.type) {
96
- return false;
97
- }
98
- listItem.dataset.checked = updatedNode.attrs.checked;
99
- if (updatedNode.attrs.checked) {
100
- checkbox.setAttribute('checked', 'checked');
101
- }
102
- else {
103
- checkbox.removeAttribute('checked');
104
- }
105
- return true;
106
- },
107
- };
108
- };
109
- },
110
- addInputRules() {
111
- return [
112
- wrappingInputRule({
113
- find: inputRegex,
114
- type: this.type,
115
- getAttributes: match => ({
116
- checked: match[match.length - 1] === 'x',
117
- }),
118
- }),
119
- ];
120
- },
121
- });
122
-
123
- export { TaskItem, TaskItem as default, inputRegex };
124
- //# sourceMappingURL=tiptap-extension-task-item.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tiptap-extension-task-item.esm.js","sources":["../src/task-item.ts"],"sourcesContent":["import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core'\n\nexport interface TaskItemOptions {\n nested: boolean,\n HTMLAttributes: Record<string, any>,\n}\n\nexport const inputRegex = /^\\s*(\\[([ |x])\\])\\s$/\n\nexport const TaskItem = Node.create<TaskItemOptions>({\n name: 'taskItem',\n\n defaultOptions: {\n nested: false,\n HTMLAttributes: {},\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 => element.getAttribute('data-checked') === 'true',\n renderHTML: attributes => ({\n 'data-checked': attributes.checked,\n }),\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'li[data-type=\"taskItem\"]',\n priority: 51,\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['li', mergeAttributes(\n this.options.HTMLAttributes,\n HTMLAttributes,\n { 'data-type': 'taskItem' },\n ), 0]\n },\n\n addKeyboardShortcuts() {\n const shortcuts = {\n Enter: () => this.editor.commands.splitListItem('taskItem'),\n 'Shift-Tab': () => this.editor.commands.liftListItem('taskItem'),\n }\n\n if (!this.options.nested) {\n return shortcuts\n }\n\n return {\n ...shortcuts,\n Tab: () => this.editor.commands.sinkListItem('taskItem'),\n }\n },\n\n addNodeView() {\n return ({\n node,\n HTMLAttributes,\n getPos,\n 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('change', event => {\n // if the editor isn’t editable\n // we have to undo the latest change\n if (!editor.isEditable) {\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()\n .command(({ tr }) => {\n tr.setNodeMarkup(getPos(), undefined, {\n checked,\n })\n\n return true\n })\n .run()\n }\n })\n\n listItem.dataset.checked = node.attrs.checked\n if (node.attrs.checked) {\n checkbox.setAttribute('checked', 'checked')\n }\n\n checkboxWrapper.append(checkbox, checkboxStyler)\n listItem.append(checkboxWrapper, content)\n\n Object\n .entries(HTMLAttributes)\n .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 if (updatedNode.attrs.checked) {\n checkbox.setAttribute('checked', 'checked')\n } else {\n checkbox.removeAttribute('checked')\n }\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":";;MAOa,UAAU,GAAG,uBAAsB;MAEnC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAkB;IACnD,IAAI,EAAE,UAAU;IAEhB,cAAc,EAAE;QACd,MAAM,EAAE,KAAK;QACb,cAAc,EAAE,EAAE;KACnB;IAED,OAAO;QACL,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,kBAAkB,GAAG,YAAY,CAAA;KAC/D;IAED,QAAQ,EAAE,IAAI;IAEd,aAAa;QACX,OAAO;YACL,OAAO,EAAE;gBACP,OAAO,EAAE,KAAK;gBACd,WAAW,EAAE,KAAK;gBAClB,SAAS,EAAE,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,KAAK,MAAM;gBACrE,UAAU,EAAE,UAAU,KAAK;oBACzB,cAAc,EAAE,UAAU,CAAC,OAAO;iBACnC,CAAC;aACH;SACF,CAAA;KACF;IAED,SAAS;QACP,OAAO;YACL;gBACE,GAAG,EAAE,0BAA0B;gBAC/B,QAAQ,EAAE,EAAE;aACb;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE;QAC3B,OAAO,CAAC,IAAI,EAAE,eAAe,CAC3B,IAAI,CAAC,OAAO,CAAC,cAAc,EAC3B,cAAc,EACd,EAAE,WAAW,EAAE,UAAU,EAAE,CAC5B,EAAE,CAAC,CAAC,CAAA;KACN;IAED,oBAAoB;QAClB,MAAM,SAAS,GAAG;YAChB,KAAK,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC;YAC3D,WAAW,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,UAAU,CAAC;S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KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG;iBACzC,CAAC;aACH,CAAC;SACH,CAAA;KACF;CACF;;;;"}
@@ -1,134 +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
- const inputRegex = /^\s*(\[([ |x])\])\s$/;
8
- const TaskItem = core.Node.create({
9
- name: 'taskItem',
10
- defaultOptions: {
11
- nested: false,
12
- HTMLAttributes: {},
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 => element.getAttribute('data-checked') === 'true',
24
- renderHTML: attributes => ({
25
- 'data-checked': attributes.checked,
26
- }),
27
- },
28
- };
29
- },
30
- parseHTML() {
31
- return [
32
- {
33
- tag: 'li[data-type="taskItem"]',
34
- priority: 51,
35
- },
36
- ];
37
- },
38
- renderHTML({ HTMLAttributes }) {
39
- return ['li', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { 'data-type': 'taskItem' }), 0];
40
- },
41
- addKeyboardShortcuts() {
42
- const shortcuts = {
43
- Enter: () => this.editor.commands.splitListItem('taskItem'),
44
- 'Shift-Tab': () => this.editor.commands.liftListItem('taskItem'),
45
- };
46
- if (!this.options.nested) {
47
- return shortcuts;
48
- }
49
- return {
50
- ...shortcuts,
51
- Tab: () => this.editor.commands.sinkListItem('taskItem'),
52
- };
53
- },
54
- addNodeView() {
55
- return ({ node, HTMLAttributes, getPos, editor, }) => {
56
- const listItem = document.createElement('li');
57
- const checkboxWrapper = document.createElement('label');
58
- const checkboxStyler = document.createElement('span');
59
- const checkbox = document.createElement('input');
60
- const content = document.createElement('div');
61
- checkboxWrapper.contentEditable = 'false';
62
- checkbox.type = 'checkbox';
63
- checkbox.addEventListener('change', event => {
64
- // if the editor isn’t editable
65
- // we have to undo the latest change
66
- if (!editor.isEditable) {
67
- checkbox.checked = !checkbox.checked;
68
- return;
69
- }
70
- const { checked } = event.target;
71
- if (editor.isEditable && typeof getPos === 'function') {
72
- editor
73
- .chain()
74
- .focus()
75
- .command(({ tr }) => {
76
- tr.setNodeMarkup(getPos(), undefined, {
77
- checked,
78
- });
79
- return true;
80
- })
81
- .run();
82
- }
83
- });
84
- listItem.dataset.checked = node.attrs.checked;
85
- if (node.attrs.checked) {
86
- checkbox.setAttribute('checked', 'checked');
87
- }
88
- checkboxWrapper.append(checkbox, checkboxStyler);
89
- listItem.append(checkboxWrapper, content);
90
- Object
91
- .entries(HTMLAttributes)
92
- .forEach(([key, value]) => {
93
- listItem.setAttribute(key, value);
94
- });
95
- return {
96
- dom: listItem,
97
- contentDOM: content,
98
- update: updatedNode => {
99
- if (updatedNode.type !== this.type) {
100
- return false;
101
- }
102
- listItem.dataset.checked = updatedNode.attrs.checked;
103
- if (updatedNode.attrs.checked) {
104
- checkbox.setAttribute('checked', 'checked');
105
- }
106
- else {
107
- checkbox.removeAttribute('checked');
108
- }
109
- return true;
110
- },
111
- };
112
- };
113
- },
114
- addInputRules() {
115
- return [
116
- core.wrappingInputRule({
117
- find: inputRegex,
118
- type: this.type,
119
- getAttributes: match => ({
120
- checked: match[match.length - 1] === 'x',
121
- }),
122
- }),
123
- ];
124
- },
125
- });
126
-
127
- exports.TaskItem = TaskItem;
128
- exports["default"] = TaskItem;
129
- exports.inputRegex = inputRegex;
130
-
131
- Object.defineProperty(exports, '__esModule', { value: true });
132
-
133
- }));
134
- //# sourceMappingURL=tiptap-extension-task-item.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tiptap-extension-task-item.umd.js","sources":["../src/task-item.ts"],"sourcesContent":["import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core'\n\nexport interface TaskItemOptions {\n nested: boolean,\n HTMLAttributes: Record<string, any>,\n}\n\nexport const inputRegex = /^\\s*(\\[([ |x])\\])\\s$/\n\nexport const TaskItem = Node.create<TaskItemOptions>({\n name: 'taskItem',\n\n defaultOptions: {\n nested: false,\n HTMLAttributes: {},\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 => element.getAttribute('data-checked') === 'true',\n renderHTML: attributes => ({\n 'data-checked': attributes.checked,\n }),\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'li[data-type=\"taskItem\"]',\n priority: 51,\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['li', mergeAttributes(\n this.options.HTMLAttributes,\n HTMLAttributes,\n { 'data-type': 'taskItem' },\n ), 0]\n },\n\n addKeyboardShortcuts() {\n const shortcuts = {\n Enter: () => this.editor.commands.splitListItem('taskItem'),\n 'Shift-Tab': () => this.editor.commands.liftListItem('taskItem'),\n }\n\n if (!this.options.nested) {\n return shortcuts\n }\n\n return {\n ...shortcuts,\n Tab: () => this.editor.commands.sinkListItem('taskItem'),\n }\n },\n\n addNodeView() {\n return ({\n node,\n HTMLAttributes,\n getPos,\n 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('change', event => {\n // if the editor isn’t editable\n // we have to undo the latest change\n if (!editor.isEditable) {\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()\n .command(({ tr }) => {\n tr.setNodeMarkup(getPos(), undefined, {\n checked,\n })\n\n return true\n })\n .run()\n }\n })\n\n listItem.dataset.checked = node.attrs.checked\n if (node.attrs.checked) {\n checkbox.setAttribute('checked', 'checked')\n }\n\n checkboxWrapper.append(checkbox, checkboxStyler)\n listItem.append(checkboxWrapper, content)\n\n Object\n .entries(HTMLAttributes)\n .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 if (updatedNode.attrs.checked) {\n checkbox.setAttribute('checked', 'checked')\n } else {\n checkbox.removeAttribute('checked')\n }\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":";;;;;;QAOa,UAAU,GAAG,uBAAsB;QAEnC,QAAQ,GAAGA,SAAI,CAAC,MAAM,CAAkB;MACnD,IAAI,EAAE,UAAU;MAEhB,cAAc,EAAE;UACd,MAAM,EAAE,KAAK;UACb,cAAc,EAAE,EAAE;OACnB;MAED,OAAO;UACL,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,kBAAkB,GAAG,YAAY,CAAA;OAC/D;MAED,QAAQ,EAAE,IAAI;MAEd,aAAa;UACX,OAAO;cACL,OAAO,EAAE;kBACP,OAAO,EAAE,KAAK;kBACd,WAAW,EAAE,KAAK;kBAClB,SAAS,EAAE,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,KAAK,MAAM;kBACrE,UAAU,EAAE,UAAU,KAAK;sBACzB,cAAc,EAAE,UAAU,CAAC,OAAO;mBACnC,CAAC;eACH;WACF,CAAA;OACF;MAED,SAAS;UACP,OAAO;cACL;kBACE,GAAG,EAAE,0BAA0B;kBAC/B,QAAQ,EAAE,EAAE;eACb;WACF,CAA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