@examplary/ui 1.55.0 → 1.58.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.
- package/dist/components/ai/ai-icon.js +2 -25
- package/dist/components/ai/ai-prompt-suggestion.js +3 -26
- package/dist/components/brand/tick-icon.js +2 -25
- package/dist/components/chat/chat-input.js +8 -31
- package/dist/components/chat/chat-typing-indicator.js +2 -2
- package/dist/components/chat/chat-view.js +6 -34
- package/dist/components/loading/ai-spinner.js +2 -13
- package/dist/components/loading/tick-loader.js +39 -104
- package/dist/components/print/answer-box.js +2 -25
- package/dist/components/question-types/fetch-component.js +65 -106
- package/dist/components/question-types/format-question-type.d.ts +41 -41
- package/dist/components/question-types/format-question-type.js +36 -37
- package/dist/components/rich-text/minimal-rich-text-field.d.ts +2 -2
- package/dist/components/rich-text/minimal-rich-text-field.js +47 -85
- package/dist/components/rich-text/rich-text-display.js +15 -33
- package/dist/components/rich-text/rich-text-field.js +2 -25
- package/dist/components/rich-text/rich-text-toolbar.d.ts +3 -2
- package/dist/components/rich-text/rich-text-toolbar.js +5 -6
- package/dist/components/rich-text/tiptap/collaboration-caret.js +24 -34
- package/dist/components/rich-text/tiptap/comments/comment-bubble.d.ts +1 -1
- package/dist/components/rich-text/tiptap/comments/comment-bubble.js +36 -41
- package/dist/components/rich-text/tiptap/content-reference.js +6 -7
- package/dist/components/rich-text/tiptap/crop-page-clipping-modal.d.ts +3 -3
- package/dist/components/rich-text/tiptap/crop-page-clipping-modal.js +20 -25
- package/dist/components/rich-text/tiptap/extensions.d.ts +2 -2
- package/dist/components/rich-text/tiptap/extensions.js +6 -16
- package/dist/components/rich-text/tiptap/file-attachment.js +9 -11
- package/dist/components/rich-text/tiptap/file-handler.d.ts +2 -2
- package/dist/components/rich-text/tiptap/file-handler.js +110 -185
- package/dist/components/rich-text/tiptap/image.js +18 -23
- package/dist/components/rich-text/tiptap/mathematics-component.js +25 -30
- package/dist/components/rich-text/tiptap/mathematics.js +56 -82
- package/dist/components/rich-text/tiptap/page-clipping.js +3 -4
- package/dist/components/rich-text/tiptap/png-scanner.js +63 -108
- package/dist/components/rich-text/tiptap/rich-text-formatting-menu.d.ts +1 -1
- package/dist/components/rich-text/tiptap/rich-text-formatting-menu.js +31 -46
- package/dist/components/ui/alert.d.ts +3 -3
- package/dist/components/ui/alert.js +7 -32
- package/dist/components/ui/avatar.js +18 -14
- package/dist/components/ui/badge.d.ts +3 -3
- package/dist/components/ui/badge.js +4 -27
- package/dist/components/ui/button.d.ts +4 -4
- package/dist/components/ui/button.js +4 -27
- package/dist/components/ui/card.js +6 -46
- package/dist/components/ui/checkbox.js +1 -26
- package/dist/components/ui/color-picker.js +11 -22
- package/dist/components/ui/command-palette.d.ts +2 -2
- package/dist/components/ui/command-palette.js +38 -72
- package/dist/components/ui/command.js +18 -49
- package/dist/components/ui/comments.js +37 -107
- package/dist/components/ui/context-menu.js +30 -67
- package/dist/components/ui/dialog.js +15 -61
- package/dist/components/ui/dropdown.js +17 -64
- package/dist/components/ui/floating-menu.js +2 -25
- package/dist/components/ui/floating-resizable.d.ts +5 -0
- package/dist/components/ui/floating-resizable.js +24 -0
- package/dist/components/ui/help-icon.js +1 -2
- package/dist/components/ui/icon-picker.js +50 -130
- package/dist/components/ui/index.d.ts +1 -0
- package/dist/components/ui/index.js +1 -0
- package/dist/components/ui/input.js +2 -25
- package/dist/components/ui/label.d.ts +1 -1
- package/dist/components/ui/label.js +2 -27
- package/dist/components/ui/popover.d.ts +2 -2
- package/dist/components/ui/popover.js +4 -32
- package/dist/components/ui/progress-bar.js +2 -3
- package/dist/components/ui/radio-group.js +4 -28
- package/dist/components/ui/resizable.d.ts +6 -9
- package/dist/components/ui/resizable.js +13 -60
- package/dist/components/ui/select.js +12 -55
- package/dist/components/ui/separator.js +1 -26
- package/dist/components/ui/sheet.d.ts +3 -3
- package/dist/components/ui/sheet.js +11 -51
- package/dist/components/ui/skeleton.js +2 -25
- package/dist/components/ui/slider.js +7 -32
- package/dist/components/ui/sortable.d.ts +1 -1
- package/dist/components/ui/sortable.js +131 -155
- package/dist/components/ui/switch.d.ts +3 -3
- package/dist/components/ui/switch.js +3 -28
- package/dist/components/ui/table.js +8 -54
- package/dist/components/ui/tabs.js +8 -34
- package/dist/components/ui/text-selection-menu.d.ts +1 -1
- package/dist/components/ui/text-selection-menu.js +19 -25
- package/dist/components/ui/textarea.js +7 -30
- package/dist/components/ui/tooltip.js +4 -29
- package/dist/components/web-components/content-reference.js +81 -106
- package/dist/components/web-components/file-attachment.js +9 -30
- package/dist/components/web-components/index.js +1 -1
- package/dist/components/web-components/inline-comment-reply.js +3 -24
- package/dist/components/web-components/inline-comment.js +3 -24
- package/dist/components/web-components/inline-math.js +14 -36
- package/dist/components/web-components/page-clipping.js +13 -34
- package/dist/lib/compose-refs.js +10 -18
- package/dist/lib/use-spin-loop.js +19 -69
- package/dist/src/global.css +2 -2
- package/dist/utils.js +1 -5
- package/package.json +7 -6
- package/src/global.css +6 -1
- package/dist/components/rich-text/tiptap/comments/comment-reply.d.ts +0 -21
- package/dist/components/rich-text/tiptap/comments/comment-reply.js +0 -230
- package/dist/components/rich-text/tiptap/comments/comment.d.ts +0 -22
- package/dist/components/rich-text/tiptap/comments/comment.js +0 -199
- package/dist/components/rich-text/tiptap/comments/helpers.d.ts +0 -19
- package/dist/components/rich-text/tiptap/comments/helpers.js +0 -95
- package/dist/components/rich-text/tiptap/comments/types.d.ts +0 -29
- package/dist/components/rich-text/tiptap/comments/types.js +0 -1
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Node } from "@tiptap/core";
|
|
2
|
-
import { CommentReplyOptions } from "./types";
|
|
3
|
-
export declare const SKIP_RESCUE_META = "comment-reply:intentional-delete";
|
|
4
|
-
declare module "@tiptap/core" {
|
|
5
|
-
interface Commands<ReturnType> {
|
|
6
|
-
"inline-comment-reply": {
|
|
7
|
-
addCommentReply: (params: {
|
|
8
|
-
commentId: string;
|
|
9
|
-
value?: string;
|
|
10
|
-
}) => ReturnType;
|
|
11
|
-
updateCommentReply: (params: {
|
|
12
|
-
id: string;
|
|
13
|
-
value: string;
|
|
14
|
-
}) => ReturnType;
|
|
15
|
-
removeCommentReply: (params: {
|
|
16
|
-
id: string;
|
|
17
|
-
}) => ReturnType;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export declare const CommentReply: Node<CommentReplyOptions, any>;
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import { Node } from "@tiptap/core";
|
|
13
|
-
import { Plugin, PluginKey, TextSelection } from "@tiptap/pm/state";
|
|
14
|
-
import { createId, findReplies, locateCommentRanges, locateReplyById, } from "./helpers";
|
|
15
|
-
export var SKIP_RESCUE_META = "comment-reply:intentional-delete";
|
|
16
|
-
export var CommentReply = Node.create({
|
|
17
|
-
name: "inline-comment-reply",
|
|
18
|
-
inline: true,
|
|
19
|
-
group: "inline",
|
|
20
|
-
atom: true,
|
|
21
|
-
selectable: false,
|
|
22
|
-
draggable: false,
|
|
23
|
-
addOptions: function () {
|
|
24
|
-
return { createdBy: undefined };
|
|
25
|
-
},
|
|
26
|
-
addAttributes: function () {
|
|
27
|
-
return {
|
|
28
|
-
id: {
|
|
29
|
-
default: null,
|
|
30
|
-
parseHTML: function (el) { return el.getAttribute("id"); },
|
|
31
|
-
renderHTML: function (attrs) {
|
|
32
|
-
var _a;
|
|
33
|
-
return ({
|
|
34
|
-
id: (_a = attrs.id) !== null && _a !== void 0 ? _a : createId(),
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
commentId: {
|
|
39
|
-
default: null,
|
|
40
|
-
parseHTML: function (el) { return el.getAttribute("data-comment-id"); },
|
|
41
|
-
renderHTML: function (attrs) { return ({
|
|
42
|
-
"data-comment-id": attrs.commentId,
|
|
43
|
-
}); },
|
|
44
|
-
},
|
|
45
|
-
createdAt: {
|
|
46
|
-
default: null,
|
|
47
|
-
parseHTML: function (el) { return el.getAttribute("data-created-at"); },
|
|
48
|
-
renderHTML: function (attrs) { return ({
|
|
49
|
-
"data-created-at": attrs.createdAt,
|
|
50
|
-
}); },
|
|
51
|
-
},
|
|
52
|
-
createdBy: {
|
|
53
|
-
default: null,
|
|
54
|
-
parseHTML: function (el) { return ({
|
|
55
|
-
id: el.getAttribute("data-user-id"),
|
|
56
|
-
name: el.getAttribute("data-user-name"),
|
|
57
|
-
color: el.getAttribute("data-user-color"),
|
|
58
|
-
}); },
|
|
59
|
-
renderHTML: function (attrs) {
|
|
60
|
-
var _a, _b, _c;
|
|
61
|
-
return ({
|
|
62
|
-
"data-user-id": (_a = attrs.createdBy) === null || _a === void 0 ? void 0 : _a.id,
|
|
63
|
-
"data-user-name": (_b = attrs.createdBy) === null || _b === void 0 ? void 0 : _b.name,
|
|
64
|
-
"data-user-color": (_c = attrs.createdBy) === null || _c === void 0 ? void 0 : _c.color,
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
value: {
|
|
69
|
-
default: "",
|
|
70
|
-
parseHTML: function (el) { var _a; return (_a = el.getAttribute("value")) !== null && _a !== void 0 ? _a : ""; },
|
|
71
|
-
renderHTML: function (attrs) {
|
|
72
|
-
var _a;
|
|
73
|
-
return ({
|
|
74
|
-
value: (_a = attrs.value) !== null && _a !== void 0 ? _a : "",
|
|
75
|
-
});
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
parseHTML: function () {
|
|
81
|
-
return [{ tag: "inline-comment-reply" }];
|
|
82
|
-
},
|
|
83
|
-
renderHTML: function (_a) {
|
|
84
|
-
var HTMLAttributes = _a.HTMLAttributes;
|
|
85
|
-
return ["inline-comment-reply", HTMLAttributes];
|
|
86
|
-
},
|
|
87
|
-
addCommands: function () {
|
|
88
|
-
var _this = this;
|
|
89
|
-
return {
|
|
90
|
-
addCommentReply: function (_a) {
|
|
91
|
-
var commentId = _a.commentId, value = _a.value;
|
|
92
|
-
return function (_a) {
|
|
93
|
-
var state = _a.state, tr = _a.tr, dispatch = _a.dispatch;
|
|
94
|
-
var nodeType = state.schema.nodes["inline-comment-reply"];
|
|
95
|
-
if (!nodeType)
|
|
96
|
-
return false;
|
|
97
|
-
var ranges = locateCommentRanges(state.doc, commentId);
|
|
98
|
-
if (ranges.length === 0)
|
|
99
|
-
return false;
|
|
100
|
-
if (!dispatch)
|
|
101
|
-
return true;
|
|
102
|
-
var existing = findReplies(state.doc, commentId);
|
|
103
|
-
var last = existing[existing.length - 1];
|
|
104
|
-
var insertAt = last ? last.pos + last.nodeSize : ranges[0].from;
|
|
105
|
-
var node = nodeType.create({
|
|
106
|
-
id: createId(),
|
|
107
|
-
commentId: commentId,
|
|
108
|
-
createdBy: _this.options.createdBy,
|
|
109
|
-
createdAt: new Date().toISOString(),
|
|
110
|
-
value: value !== null && value !== void 0 ? value : "",
|
|
111
|
-
});
|
|
112
|
-
tr.insert(insertAt, node);
|
|
113
|
-
dispatch(tr);
|
|
114
|
-
return true;
|
|
115
|
-
};
|
|
116
|
-
},
|
|
117
|
-
updateCommentReply: function (_a) {
|
|
118
|
-
var id = _a.id, value = _a.value;
|
|
119
|
-
return function (_a) {
|
|
120
|
-
var state = _a.state, tr = _a.tr, dispatch = _a.dispatch;
|
|
121
|
-
var nodeType = state.schema.nodes["inline-comment-reply"];
|
|
122
|
-
if (!nodeType)
|
|
123
|
-
return false;
|
|
124
|
-
var located = locateReplyById(state.doc, id);
|
|
125
|
-
if (!located)
|
|
126
|
-
return false;
|
|
127
|
-
if (!dispatch)
|
|
128
|
-
return true;
|
|
129
|
-
var existing = state.doc.nodeAt(located.pos);
|
|
130
|
-
if (!existing)
|
|
131
|
-
return false;
|
|
132
|
-
tr.setNodeMarkup(located.pos, undefined, __assign(__assign({}, existing.attrs), { value: value }));
|
|
133
|
-
dispatch(tr);
|
|
134
|
-
return true;
|
|
135
|
-
};
|
|
136
|
-
},
|
|
137
|
-
removeCommentReply: function (_a) {
|
|
138
|
-
var id = _a.id;
|
|
139
|
-
return function (_a) {
|
|
140
|
-
var state = _a.state, tr = _a.tr, dispatch = _a.dispatch;
|
|
141
|
-
var located = locateReplyById(state.doc, id);
|
|
142
|
-
if (!located)
|
|
143
|
-
return false;
|
|
144
|
-
if (!dispatch)
|
|
145
|
-
return true;
|
|
146
|
-
tr.setMeta(SKIP_RESCUE_META, true);
|
|
147
|
-
tr.delete(located.pos, located.pos + located.nodeSize);
|
|
148
|
-
dispatch(tr);
|
|
149
|
-
return true;
|
|
150
|
-
};
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
},
|
|
154
|
-
addProseMirrorPlugins: function () {
|
|
155
|
-
return [
|
|
156
|
-
new Plugin({
|
|
157
|
-
key: new PluginKey("rescueCommentReplies"),
|
|
158
|
-
props: {
|
|
159
|
-
handleKeyDown: function (view, event) {
|
|
160
|
-
if (event.key !== "Backspace" && event.key !== "Delete") {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
var selection = view.state.selection;
|
|
164
|
-
if (!selection.empty)
|
|
165
|
-
return false;
|
|
166
|
-
var $pos = view.state.doc.resolve(selection.from);
|
|
167
|
-
var node = event.key === "Backspace" ? $pos.nodeBefore : $pos.nodeAfter;
|
|
168
|
-
if ((node === null || node === void 0 ? void 0 : node.type.name) !== "inline-comment-reply")
|
|
169
|
-
return false;
|
|
170
|
-
var newPos = event.key === "Backspace"
|
|
171
|
-
? selection.from - node.nodeSize
|
|
172
|
-
: selection.from + node.nodeSize;
|
|
173
|
-
view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, newPos)));
|
|
174
|
-
return true;
|
|
175
|
-
},
|
|
176
|
-
},
|
|
177
|
-
appendTransaction: function (transactions, oldState, newState) {
|
|
178
|
-
if (!transactions.some(function (t) { return t.docChanged; }))
|
|
179
|
-
return null;
|
|
180
|
-
if (transactions.some(function (t) { return t.getMeta(SKIP_RESCUE_META); })) {
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
if (transactions.some(function (t) { return t.getMeta("addToHistory") === false; })) {
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
var nodeType = newState.schema.nodes["inline-comment-reply"];
|
|
187
|
-
if (!nodeType)
|
|
188
|
-
return null;
|
|
189
|
-
var oldReplies = [];
|
|
190
|
-
oldState.doc.descendants(function (node) {
|
|
191
|
-
if (node.type === nodeType) {
|
|
192
|
-
oldReplies.push({
|
|
193
|
-
id: node.attrs.id,
|
|
194
|
-
attrs: node.attrs,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
if (oldReplies.length === 0)
|
|
199
|
-
return null;
|
|
200
|
-
var surviving = new Set();
|
|
201
|
-
newState.doc.descendants(function (node) {
|
|
202
|
-
if (node.type === nodeType)
|
|
203
|
-
surviving.add(node.attrs.id);
|
|
204
|
-
});
|
|
205
|
-
var missing = oldReplies.filter(function (r) { return !surviving.has(r.id); });
|
|
206
|
-
if (missing.length === 0)
|
|
207
|
-
return null;
|
|
208
|
-
var tr = newState.tr;
|
|
209
|
-
tr.setMeta("addToHistory", false);
|
|
210
|
-
var didChange = false;
|
|
211
|
-
for (var _i = 0, missing_1 = missing; _i < missing_1.length; _i++) {
|
|
212
|
-
var reply = missing_1[_i];
|
|
213
|
-
var commentId = reply.attrs.commentId;
|
|
214
|
-
if (!commentId)
|
|
215
|
-
continue;
|
|
216
|
-
var ranges = locateCommentRanges(tr.doc, commentId);
|
|
217
|
-
if (ranges.length === 0)
|
|
218
|
-
continue;
|
|
219
|
-
var existing = findReplies(tr.doc, commentId);
|
|
220
|
-
var last = existing[existing.length - 1];
|
|
221
|
-
var insertAt = last ? last.pos + last.nodeSize : ranges[0].from;
|
|
222
|
-
tr.insert(insertAt, nodeType.create(reply.attrs));
|
|
223
|
-
didChange = true;
|
|
224
|
-
}
|
|
225
|
-
return didChange ? tr : null;
|
|
226
|
-
},
|
|
227
|
-
}),
|
|
228
|
-
];
|
|
229
|
-
},
|
|
230
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Mark } from "@tiptap/core";
|
|
2
|
-
import { CommentOptions } from "./types";
|
|
3
|
-
declare module "@tiptap/core" {
|
|
4
|
-
interface Commands<ReturnType> {
|
|
5
|
-
comment: {
|
|
6
|
-
toggleComment: () => ReturnType;
|
|
7
|
-
addComment: (params: {
|
|
8
|
-
from: number;
|
|
9
|
-
to: number;
|
|
10
|
-
value?: string;
|
|
11
|
-
}) => ReturnType;
|
|
12
|
-
updateComment: (params: {
|
|
13
|
-
id: string;
|
|
14
|
-
value: string;
|
|
15
|
-
}) => ReturnType;
|
|
16
|
-
removeComment: (params: {
|
|
17
|
-
id: string;
|
|
18
|
-
}) => ReturnType;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export declare const Comment: Mark<CommentOptions, any>;
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
-
if (ar || !(i in from)) {
|
|
15
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
-
ar[i] = from[i];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
-
};
|
|
21
|
-
import { Mark } from "@tiptap/core";
|
|
22
|
-
import { SKIP_RESCUE_META } from "./comment-reply";
|
|
23
|
-
import { createId, findReplies, locateCommentRanges } from "./helpers";
|
|
24
|
-
export var Comment = Mark.create({
|
|
25
|
-
name: "comment",
|
|
26
|
-
inclusive: false,
|
|
27
|
-
spanning: true,
|
|
28
|
-
keepOnSplit: true,
|
|
29
|
-
excludes: "",
|
|
30
|
-
addOptions: function () {
|
|
31
|
-
return { createdBy: undefined };
|
|
32
|
-
},
|
|
33
|
-
addAttributes: function () {
|
|
34
|
-
return {
|
|
35
|
-
id: {
|
|
36
|
-
default: null,
|
|
37
|
-
parseHTML: function (el) { return el.getAttribute("id"); },
|
|
38
|
-
renderHTML: function (attrs) {
|
|
39
|
-
var _a;
|
|
40
|
-
return ({
|
|
41
|
-
id: (_a = attrs.id) !== null && _a !== void 0 ? _a : createId(),
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
createdAt: {
|
|
46
|
-
default: null,
|
|
47
|
-
parseHTML: function (el) { return el.getAttribute("data-created-at"); },
|
|
48
|
-
renderHTML: function (attrs) { return ({
|
|
49
|
-
"data-created-at": attrs.createdAt,
|
|
50
|
-
}); },
|
|
51
|
-
},
|
|
52
|
-
createdBy: {
|
|
53
|
-
default: null,
|
|
54
|
-
parseHTML: function (el) {
|
|
55
|
-
return {
|
|
56
|
-
id: el.getAttribute("data-user-id"),
|
|
57
|
-
name: el.getAttribute("data-user-name"),
|
|
58
|
-
color: el.getAttribute("data-user-color"),
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
renderHTML: function (attrs) {
|
|
62
|
-
var _a, _b, _c;
|
|
63
|
-
return ({
|
|
64
|
-
"data-user-id": (_a = attrs.createdBy) === null || _a === void 0 ? void 0 : _a.id,
|
|
65
|
-
"data-user-name": (_b = attrs.createdBy) === null || _b === void 0 ? void 0 : _b.name,
|
|
66
|
-
"data-user-color": (_c = attrs.createdBy) === null || _c === void 0 ? void 0 : _c.color,
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
value: {
|
|
71
|
-
default: "",
|
|
72
|
-
parseHTML: function (el) { var _a; return (_a = el.getAttribute("value")) !== null && _a !== void 0 ? _a : ""; },
|
|
73
|
-
renderHTML: function (attrs) {
|
|
74
|
-
var _a;
|
|
75
|
-
return ({
|
|
76
|
-
value: (_a = attrs.value) !== null && _a !== void 0 ? _a : "",
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
},
|
|
82
|
-
parseHTML: function () {
|
|
83
|
-
return [{ tag: "inline-comment" }];
|
|
84
|
-
},
|
|
85
|
-
renderHTML: function (_a) {
|
|
86
|
-
var _b;
|
|
87
|
-
var HTMLAttributes = _a.HTMLAttributes;
|
|
88
|
-
return [
|
|
89
|
-
"inline-comment",
|
|
90
|
-
__assign(__assign({}, HTMLAttributes), { style: "--comment-color: ".concat((_b = HTMLAttributes["data-user-color"]) !== null && _b !== void 0 ? _b : "var(--color-blue-400)") }),
|
|
91
|
-
0,
|
|
92
|
-
];
|
|
93
|
-
},
|
|
94
|
-
addCommands: function () {
|
|
95
|
-
var _this = this;
|
|
96
|
-
return {
|
|
97
|
-
addComment: function (_a) {
|
|
98
|
-
var from = _a.from, to = _a.to, value = _a.value;
|
|
99
|
-
return function (_a) {
|
|
100
|
-
var state = _a.state, tr = _a.tr, dispatch = _a.dispatch;
|
|
101
|
-
if (to <= from)
|
|
102
|
-
return false;
|
|
103
|
-
var markType = state.schema.marks.comment;
|
|
104
|
-
if (!markType)
|
|
105
|
-
return false;
|
|
106
|
-
if (!dispatch)
|
|
107
|
-
return true;
|
|
108
|
-
var attrs = {
|
|
109
|
-
id: createId(),
|
|
110
|
-
createdBy: _this.options.createdBy,
|
|
111
|
-
value: value !== null && value !== void 0 ? value : "",
|
|
112
|
-
createdAt: new Date().toISOString(),
|
|
113
|
-
};
|
|
114
|
-
tr.addMark(from, to, markType.create(attrs));
|
|
115
|
-
dispatch(tr);
|
|
116
|
-
return true;
|
|
117
|
-
};
|
|
118
|
-
},
|
|
119
|
-
toggleComment: function () {
|
|
120
|
-
return function (_a) {
|
|
121
|
-
var state = _a.state, tr = _a.tr, dispatch = _a.dispatch;
|
|
122
|
-
var markType = state.schema.marks.comment;
|
|
123
|
-
if (!markType || !dispatch)
|
|
124
|
-
return false;
|
|
125
|
-
// Find if there's a comment mark at the current selection
|
|
126
|
-
var _b = state.selection, from = _b.from, to = _b.to;
|
|
127
|
-
var commentMarks = state.doc.rangeHasMark(from, to, markType);
|
|
128
|
-
if (commentMarks) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
// Otherwise, add a new comment mark with empty body at the current selection
|
|
132
|
-
var attrs = {
|
|
133
|
-
id: createId(),
|
|
134
|
-
createdBy: _this.options.createdBy,
|
|
135
|
-
value: "",
|
|
136
|
-
createdAt: new Date().toISOString(),
|
|
137
|
-
};
|
|
138
|
-
tr.addMark(from, to, markType.create(attrs));
|
|
139
|
-
dispatch(tr);
|
|
140
|
-
return true;
|
|
141
|
-
};
|
|
142
|
-
},
|
|
143
|
-
updateComment: function (_a) {
|
|
144
|
-
var id = _a.id, value = _a.value;
|
|
145
|
-
return function (_a) {
|
|
146
|
-
var state = _a.state, tr = _a.tr, dispatch = _a.dispatch;
|
|
147
|
-
var markType = state.schema.marks.comment;
|
|
148
|
-
if (!markType)
|
|
149
|
-
return false;
|
|
150
|
-
var ranges = locateCommentRanges(state.doc, id);
|
|
151
|
-
if (ranges.length === 0)
|
|
152
|
-
return false;
|
|
153
|
-
if (!dispatch)
|
|
154
|
-
return true;
|
|
155
|
-
var existing = state.doc
|
|
156
|
-
.resolve(ranges[0].from + 1)
|
|
157
|
-
.marks()
|
|
158
|
-
.find(function (m) { return m.type === markType && m.attrs.id === id; });
|
|
159
|
-
if (!existing)
|
|
160
|
-
return false;
|
|
161
|
-
var next = markType.create(__assign(__assign({}, existing.attrs), { value: value }));
|
|
162
|
-
for (var _i = 0, _b = __spreadArray([], ranges, true).sort(function (a, b) { return b.from - a.from; }); _i < _b.length; _i++) {
|
|
163
|
-
var r = _b[_i];
|
|
164
|
-
tr.removeMark(r.from, r.to, markType);
|
|
165
|
-
tr.addMark(r.from, r.to, next);
|
|
166
|
-
}
|
|
167
|
-
dispatch(tr);
|
|
168
|
-
return true;
|
|
169
|
-
};
|
|
170
|
-
},
|
|
171
|
-
removeComment: function (_a) {
|
|
172
|
-
var id = _a.id;
|
|
173
|
-
return function (_a) {
|
|
174
|
-
var state = _a.state, tr = _a.tr, dispatch = _a.dispatch;
|
|
175
|
-
var markType = state.schema.marks.comment;
|
|
176
|
-
if (!markType)
|
|
177
|
-
return false;
|
|
178
|
-
var ranges = locateCommentRanges(state.doc, id);
|
|
179
|
-
if (ranges.length === 0)
|
|
180
|
-
return false;
|
|
181
|
-
if (!dispatch)
|
|
182
|
-
return true;
|
|
183
|
-
for (var _i = 0, _b = __spreadArray([], ranges, true).sort(function (a, b) { return b.from - a.from; }); _i < _b.length; _i++) {
|
|
184
|
-
var r = _b[_i];
|
|
185
|
-
tr.removeMark(r.from, r.to, markType);
|
|
186
|
-
}
|
|
187
|
-
var replies = __spreadArray([], findReplies(state.doc, id), true).sort(function (a, b) { return b.pos - a.pos; });
|
|
188
|
-
for (var _c = 0, replies_1 = replies; _c < replies_1.length; _c++) {
|
|
189
|
-
var r = replies_1[_c];
|
|
190
|
-
tr.delete(r.pos, r.pos + r.nodeSize);
|
|
191
|
-
}
|
|
192
|
-
tr.setMeta(SKIP_RESCUE_META, true);
|
|
193
|
-
dispatch(tr);
|
|
194
|
-
return true;
|
|
195
|
-
};
|
|
196
|
-
},
|
|
197
|
-
};
|
|
198
|
-
},
|
|
199
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Editor } from "@tiptap/core";
|
|
2
|
-
import type { Node as PMNode } from "@tiptap/pm/model";
|
|
3
|
-
import { CommentInfo, CommentReplyAttrs } from "./types";
|
|
4
|
-
export declare function createId(): string;
|
|
5
|
-
export declare function findComments(source: Editor | PMNode): CommentInfo[];
|
|
6
|
-
export interface CommentReplyLocation {
|
|
7
|
-
attrs: CommentReplyAttrs;
|
|
8
|
-
pos: number;
|
|
9
|
-
nodeSize: number;
|
|
10
|
-
}
|
|
11
|
-
export declare function findReplies(source: Editor | PMNode, commentId: string): CommentReplyLocation[];
|
|
12
|
-
export declare function locateReplyById(doc: PMNode, id: string): {
|
|
13
|
-
pos: number;
|
|
14
|
-
nodeSize: number;
|
|
15
|
-
} | null;
|
|
16
|
-
export declare function locateCommentRanges(doc: PMNode, id: string): {
|
|
17
|
-
from: number;
|
|
18
|
-
to: number;
|
|
19
|
-
}[];
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import { nanoid } from "nanoid";
|
|
13
|
-
export function createId() {
|
|
14
|
-
return "cm_".concat(nanoid());
|
|
15
|
-
}
|
|
16
|
-
export function findComments(source) {
|
|
17
|
-
var doc = "state" in source ? source.state.doc : source;
|
|
18
|
-
var rangesById = new Map();
|
|
19
|
-
doc.descendants(function (node, pos) {
|
|
20
|
-
var _a;
|
|
21
|
-
var mark = node.marks.find(function (m) { return m.type.name === "comment"; });
|
|
22
|
-
if (!mark)
|
|
23
|
-
return;
|
|
24
|
-
var attrs = mark.attrs;
|
|
25
|
-
var text = node.isText ? ((_a = node.text) !== null && _a !== void 0 ? _a : "") : "";
|
|
26
|
-
var existing = rangesById.get(attrs.id);
|
|
27
|
-
if (existing) {
|
|
28
|
-
existing.to = Math.max(existing.to, pos + node.nodeSize);
|
|
29
|
-
existing.text += text;
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
rangesById.set(attrs.id, {
|
|
33
|
-
id: attrs.id,
|
|
34
|
-
from: pos,
|
|
35
|
-
to: pos + node.nodeSize,
|
|
36
|
-
text: text,
|
|
37
|
-
attrs: __assign({}, attrs),
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
return Array.from(rangesById.values()).map(function (range) { return (__assign(__assign({}, range.attrs), { from: range.from, to: range.to, text: range.text })); });
|
|
41
|
-
}
|
|
42
|
-
export function findReplies(source, commentId) {
|
|
43
|
-
var doc = "state" in source ? source.state.doc : source;
|
|
44
|
-
var replies = [];
|
|
45
|
-
doc.descendants(function (node, pos) {
|
|
46
|
-
if (node.type.name !== "inline-comment-reply" ||
|
|
47
|
-
node.attrs.commentId !== commentId) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
replies.push({
|
|
51
|
-
attrs: node.attrs,
|
|
52
|
-
pos: pos,
|
|
53
|
-
nodeSize: node.nodeSize,
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
replies.sort(function (a, b) {
|
|
57
|
-
var _a, _b;
|
|
58
|
-
return new Date(((_a = a.attrs) === null || _a === void 0 ? void 0 : _a.createdAt) || 0).getTime() -
|
|
59
|
-
new Date(((_b = b.attrs) === null || _b === void 0 ? void 0 : _b.createdAt) || 0).getTime();
|
|
60
|
-
});
|
|
61
|
-
return replies;
|
|
62
|
-
}
|
|
63
|
-
export function locateReplyById(doc, id) {
|
|
64
|
-
var found = null;
|
|
65
|
-
doc.descendants(function (node, pos) {
|
|
66
|
-
if (found)
|
|
67
|
-
return false;
|
|
68
|
-
if (node.type.name === "inline-comment-reply" && node.attrs.id === id) {
|
|
69
|
-
found = { pos: pos, nodeSize: node.nodeSize };
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
return undefined;
|
|
73
|
-
});
|
|
74
|
-
return found;
|
|
75
|
-
}
|
|
76
|
-
export function locateCommentRanges(doc, id) {
|
|
77
|
-
var ranges = [];
|
|
78
|
-
doc.descendants(function (node, pos) {
|
|
79
|
-
var mark = node.marks.find(function (m) { return m.type.name === "comment" && m.attrs.id === id; });
|
|
80
|
-
if (!mark)
|
|
81
|
-
return;
|
|
82
|
-
ranges.push({ from: pos, to: pos + node.nodeSize });
|
|
83
|
-
});
|
|
84
|
-
ranges.sort(function (a, b) { return a.from - b.from; });
|
|
85
|
-
var merged = [];
|
|
86
|
-
for (var _i = 0, ranges_1 = ranges; _i < ranges_1.length; _i++) {
|
|
87
|
-
var r = ranges_1[_i];
|
|
88
|
-
var last = merged[merged.length - 1];
|
|
89
|
-
if (last && last.to === r.from)
|
|
90
|
-
last.to = r.to;
|
|
91
|
-
else
|
|
92
|
-
merged.push(__assign({}, r));
|
|
93
|
-
}
|
|
94
|
-
return merged;
|
|
95
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export type CommentAuthor = {
|
|
2
|
-
id: string;
|
|
3
|
-
name: string;
|
|
4
|
-
color?: string;
|
|
5
|
-
};
|
|
6
|
-
export interface CommentAttrs {
|
|
7
|
-
id: string;
|
|
8
|
-
createdBy?: CommentAuthor;
|
|
9
|
-
createdAt: string;
|
|
10
|
-
value: string;
|
|
11
|
-
}
|
|
12
|
-
export interface CommentInfo extends CommentAttrs {
|
|
13
|
-
from: number;
|
|
14
|
-
to: number;
|
|
15
|
-
text: string;
|
|
16
|
-
}
|
|
17
|
-
export interface CommentOptions {
|
|
18
|
-
createdBy?: CommentAuthor;
|
|
19
|
-
}
|
|
20
|
-
export interface CommentReplyAttrs {
|
|
21
|
-
id: string;
|
|
22
|
-
commentId: string;
|
|
23
|
-
createdBy?: CommentAuthor;
|
|
24
|
-
createdAt: string;
|
|
25
|
-
value: string;
|
|
26
|
-
}
|
|
27
|
-
export interface CommentReplyOptions {
|
|
28
|
-
createdBy?: CommentAuthor;
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|