@liveblocks/react-ui 2.7.2 → 2.8.0-beta2
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/_private/index.d.mts +5 -3
- package/dist/_private/index.d.ts +5 -3
- package/dist/_private/index.js +4 -2
- package/dist/_private/index.js.map +1 -1
- package/dist/_private/index.mjs +2 -1
- package/dist/_private/index.mjs.map +1 -1
- package/dist/components/Comment.js +106 -3
- package/dist/components/Comment.js.map +1 -1
- package/dist/components/Comment.mjs +107 -5
- package/dist/components/Comment.mjs.map +1 -1
- package/dist/components/Composer.js +216 -103
- package/dist/components/Composer.js.map +1 -1
- package/dist/components/Composer.mjs +220 -107
- package/dist/components/Composer.mjs.map +1 -1
- package/dist/components/HistoryVersionSummary.js +5 -0
- package/dist/components/HistoryVersionSummary.js.map +1 -1
- package/dist/components/HistoryVersionSummary.mjs +5 -0
- package/dist/components/HistoryVersionSummary.mjs.map +1 -1
- package/dist/components/InboxNotification.js +20 -4
- package/dist/components/InboxNotification.js.map +1 -1
- package/dist/components/InboxNotification.mjs +20 -4
- package/dist/components/InboxNotification.mjs.map +1 -1
- package/dist/components/Thread.js +5 -0
- package/dist/components/Thread.js.map +1 -1
- package/dist/components/Thread.mjs +5 -0
- package/dist/components/Thread.mjs.map +1 -1
- package/dist/components/internal/Attachment.js +314 -0
- package/dist/components/internal/Attachment.js.map +1 -0
- package/dist/components/internal/Attachment.mjs +310 -0
- package/dist/components/internal/Attachment.mjs.map +1 -0
- package/dist/components/internal/InboxNotificationThread.js +12 -2
- package/dist/components/internal/InboxNotificationThread.js.map +1 -1
- package/dist/components/internal/InboxNotificationThread.mjs +13 -3
- package/dist/components/internal/InboxNotificationThread.mjs.map +1 -1
- package/dist/icons/Attachment.js +15 -0
- package/dist/icons/Attachment.js.map +1 -0
- package/dist/icons/Attachment.mjs +13 -0
- package/dist/icons/Attachment.mjs.map +1 -0
- package/dist/icons/Spinner.js +3 -9
- package/dist/icons/Spinner.js.map +1 -1
- package/dist/icons/Spinner.mjs +4 -10
- package/dist/icons/Spinner.mjs.map +1 -1
- package/dist/icons/{Missing.js → Warning.js} +3 -3
- package/dist/icons/{Missing.js.map → Warning.js.map} +1 -1
- package/dist/icons/{Missing.mjs → Warning.mjs} +3 -3
- package/dist/icons/{Missing.mjs.map → Warning.mjs.map} +1 -1
- package/dist/index.d.mts +73 -4
- package/dist/index.d.ts +73 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/overrides.js +5 -0
- package/dist/overrides.js.map +1 -1
- package/dist/overrides.mjs +5 -0
- package/dist/overrides.mjs.map +1 -1
- package/dist/primitives/Composer/contexts.js +17 -3
- package/dist/primitives/Composer/contexts.js.map +1 -1
- package/dist/primitives/Composer/contexts.mjs +15 -4
- package/dist/primitives/Composer/contexts.mjs.map +1 -1
- package/dist/primitives/Composer/index.js +207 -30
- package/dist/primitives/Composer/index.js.map +1 -1
- package/dist/primitives/Composer/index.mjs +210 -35
- package/dist/primitives/Composer/index.mjs.map +1 -1
- package/dist/primitives/Composer/utils.js +231 -0
- package/dist/primitives/Composer/utils.js.map +1 -1
- package/dist/primitives/Composer/utils.mjs +229 -1
- package/dist/primitives/Composer/utils.mjs.map +1 -1
- package/dist/primitives/EmojiPicker/utils.js +2 -2
- package/dist/primitives/EmojiPicker/utils.js.map +1 -1
- package/dist/primitives/EmojiPicker/utils.mjs +1 -1
- package/dist/primitives/EmojiPicker/utils.mjs.map +1 -1
- package/dist/primitives/FileSize.js +33 -0
- package/dist/primitives/FileSize.js.map +1 -0
- package/dist/primitives/FileSize.mjs +31 -0
- package/dist/primitives/FileSize.mjs.map +1 -0
- package/dist/primitives/index.d.mts +87 -3
- package/dist/primitives/index.d.ts +87 -3
- package/dist/primitives/index.js +4 -0
- package/dist/primitives/index.js.map +1 -1
- package/dist/primitives/index.mjs +2 -0
- package/dist/primitives/index.mjs.map +1 -1
- package/dist/slate/plugins/{paste-html.js → paste.js} +16 -5
- package/dist/slate/plugins/paste.js.map +1 -0
- package/dist/slate/plugins/{paste-html.mjs → paste.mjs} +16 -5
- package/dist/slate/plugins/paste.mjs.map +1 -0
- package/dist/utils/data-transfer.js +20 -0
- package/dist/utils/data-transfer.js.map +1 -0
- package/dist/utils/data-transfer.mjs +18 -0
- package/dist/utils/data-transfer.mjs.map +1 -0
- package/dist/utils/download.js +14 -0
- package/dist/utils/download.js.map +1 -0
- package/dist/utils/download.mjs +12 -0
- package/dist/utils/download.mjs.map +1 -0
- package/dist/utils/format-file-size.js +45 -0
- package/dist/utils/format-file-size.js.map +1 -0
- package/dist/utils/format-file-size.mjs +43 -0
- package/dist/utils/format-file-size.mjs.map +1 -0
- package/dist/utils/intl.js +6 -0
- package/dist/utils/intl.js.map +1 -1
- package/dist/utils/intl.mjs +6 -1
- package/dist/utils/intl.mjs.map +1 -1
- package/dist/utils/use-initial.js +2 -1
- package/dist/utils/use-initial.js.map +1 -1
- package/dist/utils/use-initial.mjs +3 -2
- package/dist/utils/use-initial.mjs.map +1 -1
- package/dist/utils/use-latest.js.map +1 -1
- package/dist/utils/use-latest.mjs.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/package.json +4 -4
- package/src/styles/dark/index.css +1 -0
- package/src/styles/index.css +343 -62
- package/src/styles/utils.css +44 -0
- package/styles/dark/attributes.css +1 -1
- package/styles/dark/attributes.css.map +1 -1
- package/styles/dark/media-query.css +1 -1
- package/styles/dark/media-query.css.map +1 -1
- package/styles.css +1 -1
- package/styles.css.map +1 -1
- package/dist/slate/plugins/paste-html.js.map +0 -1
- package/dist/slate/plugins/paste-html.mjs.map +0 -1
- package/dist/utils/chunk.js +0 -12
- package/dist/utils/chunk.js.map +0 -1
- package/dist/utils/chunk.mjs +0 -10
- package/dist/utils/chunk.mjs.map +0 -1
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var core = require('@liveblocks/core');
|
|
4
|
+
var react = require('@liveblocks/react');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var index_js = require('use-sync-external-store/shim/index.js');
|
|
3
7
|
var autoLinks = require('../../slate/plugins/auto-links.js');
|
|
4
8
|
var customLinks = require('../../slate/plugins/custom-links.js');
|
|
5
9
|
var mentions = require('../../slate/plugins/mentions.js');
|
|
6
10
|
var isText = require('../../slate/utils/is-text.js');
|
|
11
|
+
var dataTransfer = require('../../utils/data-transfer.js');
|
|
7
12
|
var exists = require('../../utils/exists.js');
|
|
13
|
+
var useInitial = require('../../utils/use-initial.js');
|
|
14
|
+
var useLatest = require('../../utils/use-latest.js');
|
|
8
15
|
var utils = require('../Comment/utils.js');
|
|
16
|
+
var contexts = require('./contexts.js');
|
|
9
17
|
|
|
10
18
|
function composerBodyMentionToCommentBodyMention(mention) {
|
|
11
19
|
return {
|
|
@@ -111,7 +119,228 @@ function getSideAndAlignFromPlacement(placement) {
|
|
|
111
119
|
const [side, align = "center"] = placement.split("-");
|
|
112
120
|
return [side, align];
|
|
113
121
|
}
|
|
122
|
+
function useComposerAttachmentsDropArea({
|
|
123
|
+
onDragEnter,
|
|
124
|
+
onDragLeave,
|
|
125
|
+
onDragOver,
|
|
126
|
+
onDrop,
|
|
127
|
+
disabled
|
|
128
|
+
}) {
|
|
129
|
+
const { isDisabled: isComposerDisabled } = contexts.useComposer();
|
|
130
|
+
const isDisabled = isComposerDisabled || disabled;
|
|
131
|
+
const { createAttachments } = contexts.useComposerAttachmentsContext();
|
|
132
|
+
const [isDraggingOver, setDraggingOver] = React.useState(false);
|
|
133
|
+
const latestIsDraggingOver = useLatest.useLatest(isDraggingOver);
|
|
134
|
+
const handleDragEnter = React.useCallback(
|
|
135
|
+
(event) => {
|
|
136
|
+
onDragEnter?.(event);
|
|
137
|
+
if (latestIsDraggingOver.current || isDisabled || event.isDefaultPrevented()) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const dataTransfer = event.dataTransfer;
|
|
141
|
+
if (!dataTransfer.types.includes("Files")) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
event.stopPropagation();
|
|
146
|
+
setDraggingOver(true);
|
|
147
|
+
},
|
|
148
|
+
[onDragEnter, isDisabled]
|
|
149
|
+
);
|
|
150
|
+
const handleDragLeave = React.useCallback(
|
|
151
|
+
(event) => {
|
|
152
|
+
onDragLeave?.(event);
|
|
153
|
+
if (!latestIsDraggingOver.current || isDisabled || event.isDefaultPrevented()) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (event.relatedTarget ? event.relatedTarget === event.currentTarget || event.currentTarget.contains(event.relatedTarget) : event.currentTarget !== event.target) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
event.stopPropagation();
|
|
161
|
+
setDraggingOver(false);
|
|
162
|
+
},
|
|
163
|
+
[onDragLeave, isDisabled]
|
|
164
|
+
);
|
|
165
|
+
const handleDragOver = React.useCallback(
|
|
166
|
+
(event) => {
|
|
167
|
+
onDragOver?.(event);
|
|
168
|
+
if (isDisabled || event.isDefaultPrevented()) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
event.preventDefault();
|
|
172
|
+
event.stopPropagation();
|
|
173
|
+
},
|
|
174
|
+
[onDragOver, isDisabled]
|
|
175
|
+
);
|
|
176
|
+
const handleDrop = React.useCallback(
|
|
177
|
+
(event) => {
|
|
178
|
+
onDrop?.(event);
|
|
179
|
+
if (!latestIsDraggingOver.current || isDisabled || event.isDefaultPrevented()) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
event.stopPropagation();
|
|
184
|
+
setDraggingOver(false);
|
|
185
|
+
const files = dataTransfer.getFiles(event.dataTransfer);
|
|
186
|
+
createAttachments(files);
|
|
187
|
+
},
|
|
188
|
+
[onDrop, isDisabled, createAttachments]
|
|
189
|
+
);
|
|
190
|
+
return [
|
|
191
|
+
isDraggingOver,
|
|
192
|
+
{
|
|
193
|
+
onDragEnter: handleDragEnter,
|
|
194
|
+
onDragLeave: handleDragLeave,
|
|
195
|
+
onDragOver: handleDragOver,
|
|
196
|
+
onDrop: handleDrop,
|
|
197
|
+
"data-drop": isDraggingOver ? "" : void 0,
|
|
198
|
+
"data-disabled": isDisabled ? "" : void 0
|
|
199
|
+
}
|
|
200
|
+
];
|
|
201
|
+
}
|
|
202
|
+
class AttachmentTooLargeError extends Error {
|
|
203
|
+
constructor() {
|
|
204
|
+
super(...arguments);
|
|
205
|
+
this.name = "AttachmentTooLargeError";
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function createComposerAttachmentsManager(room, options) {
|
|
209
|
+
const attachments = /* @__PURE__ */ new Map();
|
|
210
|
+
const abortControllers = /* @__PURE__ */ new Map();
|
|
211
|
+
const eventSource = core.makeEventSource();
|
|
212
|
+
let cachedSnapshot = null;
|
|
213
|
+
function notifySubscribers() {
|
|
214
|
+
cachedSnapshot = null;
|
|
215
|
+
eventSource.notify();
|
|
216
|
+
}
|
|
217
|
+
function uploadAttachment(attachment) {
|
|
218
|
+
const abortController = new AbortController();
|
|
219
|
+
abortControllers.set(attachment.id, abortController);
|
|
220
|
+
room.uploadAttachment(attachment, {
|
|
221
|
+
signal: abortController.signal
|
|
222
|
+
}).then(() => {
|
|
223
|
+
attachments.set(attachment.id, {
|
|
224
|
+
...attachment,
|
|
225
|
+
status: "uploaded"
|
|
226
|
+
});
|
|
227
|
+
notifySubscribers();
|
|
228
|
+
}).catch((error) => {
|
|
229
|
+
if (error instanceof Error && error.name !== "AbortError" && error.name !== "TimeoutError") {
|
|
230
|
+
attachments.set(attachment.id, {
|
|
231
|
+
...attachment,
|
|
232
|
+
status: "error",
|
|
233
|
+
error: error instanceof core.CommentsApiError && error.status === 413 ? new AttachmentTooLargeError("File is too large.") : error
|
|
234
|
+
});
|
|
235
|
+
notifySubscribers();
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function addAttachments(addedAttachments) {
|
|
240
|
+
const newAttachments = addedAttachments.filter(
|
|
241
|
+
(attachment) => !attachments.has(attachment.id)
|
|
242
|
+
);
|
|
243
|
+
const attachmentsToUpload = [];
|
|
244
|
+
for (const attachment of newAttachments) {
|
|
245
|
+
if (attachment.type === "localAttachment") {
|
|
246
|
+
if (attachment.file.size > options.maxFileSize) {
|
|
247
|
+
attachments.set(attachment.id, {
|
|
248
|
+
...attachment,
|
|
249
|
+
status: "error",
|
|
250
|
+
error: new AttachmentTooLargeError("File is too large.")
|
|
251
|
+
});
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
attachments.set(attachment.id, {
|
|
255
|
+
...attachment,
|
|
256
|
+
status: "uploading"
|
|
257
|
+
});
|
|
258
|
+
attachmentsToUpload.push(attachment);
|
|
259
|
+
} else {
|
|
260
|
+
attachments.set(attachment.id, attachment);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (newAttachments.length > 0) {
|
|
264
|
+
notifySubscribers();
|
|
265
|
+
}
|
|
266
|
+
for (const attachment of attachmentsToUpload) {
|
|
267
|
+
uploadAttachment(attachment);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function removeAttachment(attachmentId) {
|
|
271
|
+
const abortController = abortControllers.get(attachmentId);
|
|
272
|
+
abortController?.abort();
|
|
273
|
+
attachments.delete(attachmentId);
|
|
274
|
+
abortControllers.delete(attachmentId);
|
|
275
|
+
notifySubscribers();
|
|
276
|
+
}
|
|
277
|
+
function getSnapshot() {
|
|
278
|
+
if (!cachedSnapshot) {
|
|
279
|
+
cachedSnapshot = Array.from(attachments.values());
|
|
280
|
+
}
|
|
281
|
+
return cachedSnapshot;
|
|
282
|
+
}
|
|
283
|
+
function clear() {
|
|
284
|
+
abortControllers.forEach((controller) => controller.abort());
|
|
285
|
+
abortControllers.clear();
|
|
286
|
+
eventSource.clear();
|
|
287
|
+
attachments.clear();
|
|
288
|
+
notifySubscribers();
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
addAttachments,
|
|
292
|
+
removeAttachment,
|
|
293
|
+
getSnapshot,
|
|
294
|
+
subscribe: eventSource.subscribe,
|
|
295
|
+
clear
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function preventBeforeUnloadDefault(event) {
|
|
299
|
+
event.preventDefault();
|
|
300
|
+
}
|
|
301
|
+
function useComposerAttachmentsManager(defaultAttachments, options) {
|
|
302
|
+
const room = react.useRoom();
|
|
303
|
+
const frozenDefaultAttachments = useInitial.useInitial(defaultAttachments);
|
|
304
|
+
const frozenAttachmentsManager = useInitial.useInitial(
|
|
305
|
+
() => createComposerAttachmentsManager(room, options)
|
|
306
|
+
);
|
|
307
|
+
React.useEffect(() => {
|
|
308
|
+
frozenAttachmentsManager.addAttachments(frozenDefaultAttachments);
|
|
309
|
+
}, [frozenDefaultAttachments, frozenAttachmentsManager]);
|
|
310
|
+
React.useEffect(() => {
|
|
311
|
+
return () => {
|
|
312
|
+
frozenAttachmentsManager.clear();
|
|
313
|
+
};
|
|
314
|
+
}, [frozenAttachmentsManager]);
|
|
315
|
+
const attachments = index_js.useSyncExternalStore(
|
|
316
|
+
frozenAttachmentsManager.subscribe,
|
|
317
|
+
frozenAttachmentsManager.getSnapshot,
|
|
318
|
+
frozenAttachmentsManager.getSnapshot
|
|
319
|
+
);
|
|
320
|
+
const isUploadingAttachments = React.useMemo(() => {
|
|
321
|
+
return attachments.some(
|
|
322
|
+
(attachment) => attachment.type === "localAttachment" && attachment.status === "uploading"
|
|
323
|
+
);
|
|
324
|
+
}, [attachments]);
|
|
325
|
+
React.useEffect(() => {
|
|
326
|
+
if (!isUploadingAttachments) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
window.addEventListener("beforeunload", preventBeforeUnloadDefault);
|
|
330
|
+
return () => {
|
|
331
|
+
window.removeEventListener("beforeunload", preventBeforeUnloadDefault);
|
|
332
|
+
};
|
|
333
|
+
}, [isUploadingAttachments]);
|
|
334
|
+
return {
|
|
335
|
+
attachments,
|
|
336
|
+
isUploadingAttachments,
|
|
337
|
+
addAttachments: frozenAttachmentsManager.addAttachments,
|
|
338
|
+
removeAttachment: frozenAttachmentsManager.removeAttachment,
|
|
339
|
+
clearAttachments: frozenAttachmentsManager.clear
|
|
340
|
+
};
|
|
341
|
+
}
|
|
114
342
|
|
|
343
|
+
exports.AttachmentTooLargeError = AttachmentTooLargeError;
|
|
115
344
|
exports.commentBodyLinkToComposerBodyLink = commentBodyLinkToComposerBodyLink;
|
|
116
345
|
exports.commentBodyMentionToComposerBodyMention = commentBodyMentionToComposerBodyMention;
|
|
117
346
|
exports.commentBodyToComposerBody = commentBodyToComposerBody;
|
|
@@ -121,4 +350,6 @@ exports.composerBodyMentionToCommentBodyMention = composerBodyMentionToCommentBo
|
|
|
121
350
|
exports.composerBodyToCommentBody = composerBodyToCommentBody;
|
|
122
351
|
exports.getPlacementFromPosition = getPlacementFromPosition;
|
|
123
352
|
exports.getSideAndAlignFromPlacement = getSideAndAlignFromPlacement;
|
|
353
|
+
exports.useComposerAttachmentsDropArea = useComposerAttachmentsDropArea;
|
|
354
|
+
exports.useComposerAttachmentsManager = useComposerAttachmentsManager;
|
|
124
355
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/primitives/Composer/utils.ts"],"sourcesContent":["import type { Placement } from \"@floating-ui/react-dom\";\nimport type {\n CommentBody,\n CommentBodyLink,\n CommentBodyMention,\n} from \"@liveblocks/core\";\n\nimport { isComposerBodyAutoLink } from \"../../slate/plugins/auto-links\";\nimport { isComposerBodyCustomLink } from \"../../slate/plugins/custom-links\";\nimport { isComposerBodyMention } from \"../../slate/plugins/mentions\";\nimport { isText } from \"../../slate/utils/is-text\";\nimport type {\n ComposerBody,\n ComposerBodyAutoLink,\n ComposerBodyCustomLink,\n ComposerBodyMention,\n ComposerBodyText,\n Direction,\n} from \"../../types\";\nimport { exists } from \"../../utils/exists\";\nimport {\n isCommentBodyLink,\n isCommentBodyMention,\n isCommentBodyText,\n} from \"../Comment/utils\";\nimport type { SuggestionsPosition } from \"./types\";\n\nexport function composerBodyMentionToCommentBodyMention(\n mention: ComposerBodyMention\n): CommentBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n };\n}\n\nexport function composerBodyAutoLinkToCommentBodyLink(\n link: ComposerBodyAutoLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n };\n}\n\nexport function composerBodyCustomLinkToCommentBodyLink(\n link: ComposerBodyCustomLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n text: link.children.map((child) => child.text).join(\"\"),\n };\n}\n\nexport function commentBodyMentionToComposerBodyMention(\n mention: CommentBodyMention\n): ComposerBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n children: [{ text: \"\" }],\n };\n}\n\nexport function commentBodyLinkToComposerBodyLink(\n link: CommentBodyLink\n): ComposerBodyAutoLink | ComposerBodyCustomLink {\n if (link.text) {\n return {\n type: \"custom-link\",\n url: link.url,\n children: [{ text: link.text }],\n };\n } else {\n return {\n type: \"auto-link\",\n url: link.url,\n children: [{ text: link.url }],\n };\n }\n}\n\nexport function composerBodyToCommentBody(body: ComposerBody): CommentBody {\n return {\n version: 1,\n content: body\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isComposerBodyMention(inline)) {\n return composerBodyMentionToCommentBodyMention(inline);\n }\n\n if (isComposerBodyAutoLink(inline)) {\n return composerBodyAutoLinkToCommentBodyLink(inline);\n }\n\n if (isComposerBodyCustomLink(inline)) {\n return composerBodyCustomLinkToCommentBodyLink(inline);\n }\n\n if (isText(inline)) {\n return inline;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists),\n };\n}\n\nconst emptyComposerBody: ComposerBody = [];\n\nexport function commentBodyToComposerBody(body: CommentBody): ComposerBody {\n if (!body || !body?.content) {\n return emptyComposerBody;\n }\n\n return body.content\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isCommentBodyMention(inline)) {\n return commentBodyMentionToComposerBodyMention(inline);\n }\n\n if (isCommentBodyLink(inline)) {\n return commentBodyLinkToComposerBodyLink(inline);\n }\n\n if (isCommentBodyText(inline)) {\n return inline as ComposerBodyText;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists);\n}\n\nexport function getPlacementFromPosition(\n position: SuggestionsPosition,\n direction: Direction = \"ltr\"\n): Placement {\n return `${position}-${direction === \"rtl\" ? \"end\" : \"start\"}`;\n}\n\nexport function getSideAndAlignFromPlacement(placement: Placement) {\n const [side, align = \"center\"] = placement.split(\"-\");\n\n return [side, align] as const;\n}\n"],"names":["isComposerBodyMention","isComposerBodyAutoLink","isComposerBodyCustomLink","isText","exists","isCommentBodyMention","isCommentBodyLink","isCommentBodyText"],"mappings":";;;;;;;;;AA2BO,SAAS,wCACd,OACoB,EAAA;AACpB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,SAAA;AAAA,IACN,IAAI,OAAQ,CAAA,EAAA;AAAA,GACd,CAAA;AACF,CAAA;AAEO,SAAS,sCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,GACZ,CAAA;AACF,CAAA;AAEO,SAAS,wCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,IACV,IAAA,EAAM,IAAK,CAAA,QAAA,CAAS,GAAI,CAAA,CAAC,UAAU,KAAM,CAAA,IAAI,CAAE,CAAA,I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A,CAAA;AAEhB,IAAO,OAAA;AAAA,MACL,GAAG,KAAA;AAAA,MACH,QAAA;AAAA,KACF,CAAA;AAAA,GACD,CACA,CAAA,MAAA,CAAOA,aAAM,CAAA,CAAA;AAClB,CAAA;AAEgB,SAAA,wBAAA,CACd,QACA,EAAA,SAAA,GAAuB,KACZ,EAAA;AACX,EAAA,OAAO,CAAG,EAAA,QAAA,CAAA,CAAA,EAAY,SAAc,KAAA,KAAA,GAAQ,KAAQ,GAAA,OAAA,CAAA,CAAA,CAAA;AACtD,CAAA;AAEO,SAAS,6BAA6B,SAAsB,EAAA;AACjE,EAAA,MAAM,CAAC,IAAM,EAAA,KAAA,GAAQ,QAAQ,CAAI,GAAA,SAAA,CAAU,MAAM,GAAG,CAAA,CAAA;AAEpD,EAAO,OAAA,CAAC,MAAM,KAAK,CAAA,CAAA;AACrB;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/primitives/Composer/utils.ts"],"sourcesContent":["import type { Placement } from \"@floating-ui/react-dom\";\nimport {\n type CommentAttachment,\n type CommentBody,\n type CommentBodyLink,\n type CommentBodyMention,\n type CommentLocalAttachment,\n type CommentMixedAttachment,\n CommentsApiError,\n makeEventSource,\n type OpaqueRoom,\n} from \"@liveblocks/core\";\nimport { useRoom } from \"@liveblocks/react\";\nimport type { DragEvent } from \"react\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\n\nimport { isComposerBodyAutoLink } from \"../../slate/plugins/auto-links\";\nimport { isComposerBodyCustomLink } from \"../../slate/plugins/custom-links\";\nimport { isComposerBodyMention } from \"../../slate/plugins/mentions\";\nimport { isText } from \"../../slate/utils/is-text\";\nimport type {\n ComposerBody,\n ComposerBodyAutoLink,\n ComposerBodyCustomLink,\n ComposerBodyMention,\n ComposerBodyText,\n Direction,\n} from \"../../types\";\nimport { getFiles } from \"../../utils/data-transfer\";\nimport { exists } from \"../../utils/exists\";\nimport { useInitial } from \"../../utils/use-initial\";\nimport { useLatest } from \"../../utils/use-latest\";\nimport {\n isCommentBodyLink,\n isCommentBodyMention,\n isCommentBodyText,\n} from \"../Comment/utils\";\nimport { useComposer, useComposerAttachmentsContext } from \"./contexts\";\nimport type { SuggestionsPosition } from \"./types\";\n\nexport function composerBodyMentionToCommentBodyMention(\n mention: ComposerBodyMention\n): CommentBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n };\n}\n\nexport function composerBodyAutoLinkToCommentBodyLink(\n link: ComposerBodyAutoLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n };\n}\n\nexport function composerBodyCustomLinkToCommentBodyLink(\n link: ComposerBodyCustomLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n text: link.children.map((child) => child.text).join(\"\"),\n };\n}\n\nexport function commentBodyMentionToComposerBodyMention(\n mention: CommentBodyMention\n): ComposerBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n children: [{ text: \"\" }],\n };\n}\n\nexport function commentBodyLinkToComposerBodyLink(\n link: CommentBodyLink\n): ComposerBodyAutoLink | ComposerBodyCustomLink {\n if (link.text) {\n return {\n type: \"custom-link\",\n url: link.url,\n children: [{ text: link.text }],\n };\n } else {\n return {\n type: \"auto-link\",\n url: link.url,\n children: [{ text: link.url }],\n };\n }\n}\n\nexport function composerBodyToCommentBody(body: ComposerBody): CommentBody {\n return {\n version: 1,\n content: body\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isComposerBodyMention(inline)) {\n return composerBodyMentionToCommentBodyMention(inline);\n }\n\n if (isComposerBodyAutoLink(inline)) {\n return composerBodyAutoLinkToCommentBodyLink(inline);\n }\n\n if (isComposerBodyCustomLink(inline)) {\n return composerBodyCustomLinkToCommentBodyLink(inline);\n }\n\n if (isText(inline)) {\n return inline;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists),\n };\n}\n\nconst emptyComposerBody: ComposerBody = [];\n\nexport function commentBodyToComposerBody(body: CommentBody): ComposerBody {\n if (!body || !body?.content) {\n return emptyComposerBody;\n }\n\n return body.content\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isCommentBodyMention(inline)) {\n return commentBodyMentionToComposerBodyMention(inline);\n }\n\n if (isCommentBodyLink(inline)) {\n return commentBodyLinkToComposerBodyLink(inline);\n }\n\n if (isCommentBodyText(inline)) {\n return inline as ComposerBodyText;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists);\n}\n\nexport function getPlacementFromPosition(\n position: SuggestionsPosition,\n direction: Direction = \"ltr\"\n): Placement {\n return `${position}-${direction === \"rtl\" ? \"end\" : \"start\"}`;\n}\n\nexport function getSideAndAlignFromPlacement(placement: Placement) {\n const [side, align = \"center\"] = placement.split(\"-\");\n\n return [side, align] as const;\n}\n\nexport function useComposerAttachmentsDropArea<\n T extends HTMLElement = HTMLElement,\n>({\n onDragEnter,\n onDragLeave,\n onDragOver,\n onDrop,\n disabled,\n}: {\n onDragEnter?: (event: DragEvent<T>) => void;\n onDragLeave?: (event: DragEvent<T>) => void;\n onDragOver?: (event: DragEvent<T>) => void;\n onDrop?: (event: DragEvent<T>) => void;\n disabled?: boolean;\n}) {\n const { isDisabled: isComposerDisabled } = useComposer();\n const isDisabled = isComposerDisabled || disabled;\n const { createAttachments } = useComposerAttachmentsContext();\n const [isDraggingOver, setDraggingOver] = useState(false);\n const latestIsDraggingOver = useLatest(isDraggingOver);\n\n const handleDragEnter = useCallback(\n (event: DragEvent<T>) => {\n onDragEnter?.(event);\n\n if (\n latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n const dataTransfer = event.dataTransfer;\n\n if (!dataTransfer.types.includes(\"Files\")) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(true);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDragEnter, isDisabled]\n );\n\n const handleDragLeave = useCallback(\n (event: DragEvent<T>) => {\n onDragLeave?.(event);\n\n if (\n !latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n // Ignore drag leave events that are not actually leaving the drop area\n if (\n event.relatedTarget\n ? event.relatedTarget === event.currentTarget ||\n event.currentTarget.contains(event.relatedTarget as HTMLElement)\n : event.currentTarget !== event.target\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(false);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDragLeave, isDisabled]\n );\n\n const handleDragOver = useCallback(\n (event: DragEvent<T>) => {\n onDragOver?.(event);\n\n if (isDisabled || event.isDefaultPrevented()) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n },\n [onDragOver, isDisabled]\n );\n\n const handleDrop = useCallback(\n (event: DragEvent<T>) => {\n onDrop?.(event);\n\n if (\n !latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(false);\n\n const files = getFiles(event.dataTransfer);\n\n createAttachments(files);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDrop, isDisabled, createAttachments]\n );\n\n return [\n isDraggingOver,\n {\n onDragEnter: handleDragEnter,\n onDragLeave: handleDragLeave,\n onDragOver: handleDragOver,\n onDrop: handleDrop,\n \"data-drop\": isDraggingOver ? \"\" : undefined,\n \"data-disabled\": isDisabled ? \"\" : undefined,\n } as const,\n ] as const;\n}\n\ninterface ComposerAttachmentsManagerOptions {\n maxFileSize: number;\n}\n\nexport class AttachmentTooLargeError extends Error {\n name = \"AttachmentTooLargeError\";\n}\n\nfunction createComposerAttachmentsManager(\n room: OpaqueRoom,\n options: ComposerAttachmentsManagerOptions\n) {\n const attachments: Map<string, CommentMixedAttachment> = new Map();\n const abortControllers: Map<string, AbortController> = new Map();\n const eventSource = makeEventSource<void>();\n let cachedSnapshot: CommentMixedAttachment[] | null = null;\n\n function notifySubscribers() {\n // Invalidate the cached snapshot\n cachedSnapshot = null;\n eventSource.notify();\n }\n\n function uploadAttachment(attachment: CommentLocalAttachment) {\n const abortController = new AbortController();\n abortControllers.set(attachment.id, abortController);\n\n room\n .uploadAttachment(attachment, {\n signal: abortController.signal,\n })\n .then(() => {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"uploaded\",\n });\n notifySubscribers();\n })\n .catch((error) => {\n if (\n error instanceof Error &&\n error.name !== \"AbortError\" &&\n error.name !== \"TimeoutError\"\n ) {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"error\",\n error:\n error instanceof CommentsApiError && error.status === 413\n ? new AttachmentTooLargeError(\"File is too large.\")\n : error,\n });\n notifySubscribers();\n }\n });\n }\n\n function addAttachments(addedAttachments: CommentMixedAttachment[]) {\n // Ignore attachments that are already in the manager\n const newAttachments = addedAttachments.filter(\n (attachment) => !attachments.has(attachment.id)\n );\n\n const attachmentsToUpload: CommentLocalAttachment[] = [];\n\n // Add all the new attachments to the manager\n for (const attachment of newAttachments) {\n if (attachment.type === \"localAttachment\") {\n // The file is too large to be uploaded\n if (attachment.file.size > options.maxFileSize) {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"error\",\n error: new AttachmentTooLargeError(\"File is too large.\"),\n });\n\n continue;\n }\n\n // Otherwise, mark the attachment to be uploaded\n attachments.set(attachment.id, {\n ...attachment,\n status: \"uploading\",\n });\n attachmentsToUpload.push(attachment);\n } else {\n attachments.set(attachment.id, attachment);\n }\n }\n\n // Notify subscribers about the new attachments that were added\n if (newAttachments.length > 0) {\n notifySubscribers();\n }\n\n // Upload all the new local attachments\n for (const attachment of attachmentsToUpload) {\n uploadAttachment(attachment);\n }\n }\n\n function removeAttachment(attachmentId: string) {\n const abortController = abortControllers.get(attachmentId);\n\n abortController?.abort();\n\n attachments.delete(attachmentId);\n abortControllers.delete(attachmentId);\n\n notifySubscribers();\n }\n\n function getSnapshot() {\n if (!cachedSnapshot) {\n cachedSnapshot = Array.from(attachments.values());\n }\n\n return cachedSnapshot;\n }\n\n function clear() {\n abortControllers.forEach((controller) => controller.abort());\n abortControllers.clear();\n eventSource.clear();\n attachments.clear();\n\n notifySubscribers();\n }\n\n return {\n addAttachments,\n removeAttachment,\n getSnapshot,\n subscribe: eventSource.subscribe,\n clear,\n };\n}\n\nfunction preventBeforeUnloadDefault(event: BeforeUnloadEvent) {\n event.preventDefault();\n}\n\nexport function useComposerAttachmentsManager(\n defaultAttachments: CommentAttachment[],\n options: ComposerAttachmentsManagerOptions\n) {\n const room = useRoom();\n const frozenDefaultAttachments = useInitial(defaultAttachments);\n const frozenAttachmentsManager = useInitial(() =>\n createComposerAttachmentsManager(room, options)\n );\n\n // Initialize default attachments on mount\n useEffect(() => {\n frozenAttachmentsManager.addAttachments(frozenDefaultAttachments);\n }, [frozenDefaultAttachments, frozenAttachmentsManager]);\n\n // Clear attachments on unmount\n useEffect(() => {\n return () => {\n frozenAttachmentsManager.clear();\n };\n }, [frozenAttachmentsManager]);\n\n const attachments = useSyncExternalStore(\n frozenAttachmentsManager.subscribe,\n frozenAttachmentsManager.getSnapshot,\n frozenAttachmentsManager.getSnapshot\n );\n\n const isUploadingAttachments = useMemo(() => {\n return attachments.some(\n (attachment) =>\n attachment.type === \"localAttachment\" &&\n attachment.status === \"uploading\"\n );\n }, [attachments]);\n\n useEffect(() => {\n if (!isUploadingAttachments) {\n return;\n }\n\n window.addEventListener(\"beforeunload\", preventBeforeUnloadDefault);\n\n return () => {\n window.removeEventListener(\"beforeunload\", preventBeforeUnloadDefault);\n };\n }, [isUploadingAttachments]);\n\n return {\n attachments,\n isUploadingAttachments,\n addAttachments: frozenAttachmentsManager.addAttachments,\n removeAttachment: frozenAttachmentsManager.removeAttachment,\n clearAttachments: frozenAttachmentsManager.clear,\n };\n}\n"],"names":["isComposerBodyMention","isComposerBodyAutoLink","isComposerBodyCustomLink","isText","exists","isCommentBodyMention","isCommentBodyLink","isCommentBodyText","useComposer","useComposerAttachmentsContext","useState","useLatest","useCallback","getFiles","makeEventSource","CommentsApiError","useRoom","useInitial","useEffect","useSyncExternalStore","useMemo"],"mappings":";;;;;;;;;;;;;;;;;AAyCO,SAAS,wCACd,OACoB,EAAA;AACpB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,SAAA;AAAA,IACN,IAAI,OAAQ,CAAA,EAAA;AAAA,GACd,CAAA;AACF,CAAA;AAEO,SAAS,sCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,GACZ,CAAA;AACF,CAAA;AAEO,SAAS,wCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,IACV,IAAA,EAAM,IAAK,CAAA,QAAA,CAAS,GAAI,CAAA,CAAC,UAAU,KAAM,CAAA,IAAI,CAAE,CAAA,IAAA,CAAK,EAAE,CAAA;AAAA,GACxD,CAAA;AACF,CAAA;AAEO,SAAS,wCACd,OACqB,EAAA;AACrB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,SAAA;AAAA,IACN,IAAI,OAAQ,CAAA,EAAA;AAAA,IACZ,QAAU,EAAA,CAAC,EAAE,IAAA,EAAM,IAAI,CAAA;AAAA,GACzB,CAAA;AACF,CAAA;AAEO,SAAS,kCACd,IAC+C,EAAA;AAC/C,EAAA,IAAI,KAAK,IAAM,EAAA;AACb,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,aAAA;AAAA,MACN,KAAK,IAAK,CAAA,GAAA;AAAA,MACV,UAAU,CAAC,EAAE,IAAM,EAAA,IAAA,CAAK,MAAM,CAAA;AAAA,KAChC,CAAA;AAAA,GACK,M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AA,OAAO,WAAY,CAAA,IAAA;AAAA,MACjB,CAAC,UACC,KAAA,UAAA,CAAW,IAAS,KAAA,iBAAA,IACpB,WAAW,MAAW,KAAA,WAAA;AAAA,KAC1B,CAAA;AAAA,GACF,EAAG,CAAC,WAAW,CAAC,CAAA,CAAA;AAEhB,EAAAF,eAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,sBAAwB,EAAA;AAC3B,MAAA,OAAA;AAAA,KACF;AAEA,IAAO,MAAA,CAAA,gBAAA,CAAiB,gBAAgB,0BAA0B,CAAA,CAAA;AAElE,IAAA,OAAO,MAAM;AACX,MAAO,MAAA,CAAA,mBAAA,CAAoB,gBAAgB,0BAA0B,CAAA,CAAA;AAAA,KACvE,CAAA;AAAA,GACF,EAAG,CAAC,sBAAsB,CAAC,CAAA,CAAA;AAE3B,EAAO,OAAA;AAAA,IACL,WAAA;AAAA,IACA,sBAAA;AAAA,IACA,gBAAgB,wBAAyB,CAAA,cAAA;AAAA,IACzC,kBAAkB,wBAAyB,CAAA,gBAAA;AAAA,IAC3C,kBAAkB,wBAAyB,CAAA,KAAA;AAAA,GAC7C,CAAA;AACF;;;;;;;;;;;;;;;"}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
import { makeEventSource, CommentsApiError } from '@liveblocks/core';
|
|
2
|
+
import { useRoom } from '@liveblocks/react';
|
|
3
|
+
import { useState, useCallback, useEffect, useMemo } from 'react';
|
|
4
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
1
5
|
import { isComposerBodyAutoLink } from '../../slate/plugins/auto-links.mjs';
|
|
2
6
|
import { isComposerBodyCustomLink } from '../../slate/plugins/custom-links.mjs';
|
|
3
7
|
import { isComposerBodyMention } from '../../slate/plugins/mentions.mjs';
|
|
4
8
|
import { isText } from '../../slate/utils/is-text.mjs';
|
|
9
|
+
import { getFiles } from '../../utils/data-transfer.mjs';
|
|
5
10
|
import { exists } from '../../utils/exists.mjs';
|
|
11
|
+
import { useInitial } from '../../utils/use-initial.mjs';
|
|
12
|
+
import { useLatest } from '../../utils/use-latest.mjs';
|
|
6
13
|
import { isCommentBodyMention, isCommentBodyLink, isCommentBodyText } from '../Comment/utils.mjs';
|
|
14
|
+
import { useComposer, useComposerAttachmentsContext } from './contexts.mjs';
|
|
7
15
|
|
|
8
16
|
function composerBodyMentionToCommentBodyMention(mention) {
|
|
9
17
|
return {
|
|
@@ -109,6 +117,226 @@ function getSideAndAlignFromPlacement(placement) {
|
|
|
109
117
|
const [side, align = "center"] = placement.split("-");
|
|
110
118
|
return [side, align];
|
|
111
119
|
}
|
|
120
|
+
function useComposerAttachmentsDropArea({
|
|
121
|
+
onDragEnter,
|
|
122
|
+
onDragLeave,
|
|
123
|
+
onDragOver,
|
|
124
|
+
onDrop,
|
|
125
|
+
disabled
|
|
126
|
+
}) {
|
|
127
|
+
const { isDisabled: isComposerDisabled } = useComposer();
|
|
128
|
+
const isDisabled = isComposerDisabled || disabled;
|
|
129
|
+
const { createAttachments } = useComposerAttachmentsContext();
|
|
130
|
+
const [isDraggingOver, setDraggingOver] = useState(false);
|
|
131
|
+
const latestIsDraggingOver = useLatest(isDraggingOver);
|
|
132
|
+
const handleDragEnter = useCallback(
|
|
133
|
+
(event) => {
|
|
134
|
+
onDragEnter?.(event);
|
|
135
|
+
if (latestIsDraggingOver.current || isDisabled || event.isDefaultPrevented()) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const dataTransfer = event.dataTransfer;
|
|
139
|
+
if (!dataTransfer.types.includes("Files")) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
event.stopPropagation();
|
|
144
|
+
setDraggingOver(true);
|
|
145
|
+
},
|
|
146
|
+
[onDragEnter, isDisabled]
|
|
147
|
+
);
|
|
148
|
+
const handleDragLeave = useCallback(
|
|
149
|
+
(event) => {
|
|
150
|
+
onDragLeave?.(event);
|
|
151
|
+
if (!latestIsDraggingOver.current || isDisabled || event.isDefaultPrevented()) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (event.relatedTarget ? event.relatedTarget === event.currentTarget || event.currentTarget.contains(event.relatedTarget) : event.currentTarget !== event.target) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
event.stopPropagation();
|
|
159
|
+
setDraggingOver(false);
|
|
160
|
+
},
|
|
161
|
+
[onDragLeave, isDisabled]
|
|
162
|
+
);
|
|
163
|
+
const handleDragOver = useCallback(
|
|
164
|
+
(event) => {
|
|
165
|
+
onDragOver?.(event);
|
|
166
|
+
if (isDisabled || event.isDefaultPrevented()) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
event.stopPropagation();
|
|
171
|
+
},
|
|
172
|
+
[onDragOver, isDisabled]
|
|
173
|
+
);
|
|
174
|
+
const handleDrop = useCallback(
|
|
175
|
+
(event) => {
|
|
176
|
+
onDrop?.(event);
|
|
177
|
+
if (!latestIsDraggingOver.current || isDisabled || event.isDefaultPrevented()) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
event.preventDefault();
|
|
181
|
+
event.stopPropagation();
|
|
182
|
+
setDraggingOver(false);
|
|
183
|
+
const files = getFiles(event.dataTransfer);
|
|
184
|
+
createAttachments(files);
|
|
185
|
+
},
|
|
186
|
+
[onDrop, isDisabled, createAttachments]
|
|
187
|
+
);
|
|
188
|
+
return [
|
|
189
|
+
isDraggingOver,
|
|
190
|
+
{
|
|
191
|
+
onDragEnter: handleDragEnter,
|
|
192
|
+
onDragLeave: handleDragLeave,
|
|
193
|
+
onDragOver: handleDragOver,
|
|
194
|
+
onDrop: handleDrop,
|
|
195
|
+
"data-drop": isDraggingOver ? "" : void 0,
|
|
196
|
+
"data-disabled": isDisabled ? "" : void 0
|
|
197
|
+
}
|
|
198
|
+
];
|
|
199
|
+
}
|
|
200
|
+
class AttachmentTooLargeError extends Error {
|
|
201
|
+
constructor() {
|
|
202
|
+
super(...arguments);
|
|
203
|
+
this.name = "AttachmentTooLargeError";
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function createComposerAttachmentsManager(room, options) {
|
|
207
|
+
const attachments = /* @__PURE__ */ new Map();
|
|
208
|
+
const abortControllers = /* @__PURE__ */ new Map();
|
|
209
|
+
const eventSource = makeEventSource();
|
|
210
|
+
let cachedSnapshot = null;
|
|
211
|
+
function notifySubscribers() {
|
|
212
|
+
cachedSnapshot = null;
|
|
213
|
+
eventSource.notify();
|
|
214
|
+
}
|
|
215
|
+
function uploadAttachment(attachment) {
|
|
216
|
+
const abortController = new AbortController();
|
|
217
|
+
abortControllers.set(attachment.id, abortController);
|
|
218
|
+
room.uploadAttachment(attachment, {
|
|
219
|
+
signal: abortController.signal
|
|
220
|
+
}).then(() => {
|
|
221
|
+
attachments.set(attachment.id, {
|
|
222
|
+
...attachment,
|
|
223
|
+
status: "uploaded"
|
|
224
|
+
});
|
|
225
|
+
notifySubscribers();
|
|
226
|
+
}).catch((error) => {
|
|
227
|
+
if (error instanceof Error && error.name !== "AbortError" && error.name !== "TimeoutError") {
|
|
228
|
+
attachments.set(attachment.id, {
|
|
229
|
+
...attachment,
|
|
230
|
+
status: "error",
|
|
231
|
+
error: error instanceof CommentsApiError && error.status === 413 ? new AttachmentTooLargeError("File is too large.") : error
|
|
232
|
+
});
|
|
233
|
+
notifySubscribers();
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function addAttachments(addedAttachments) {
|
|
238
|
+
const newAttachments = addedAttachments.filter(
|
|
239
|
+
(attachment) => !attachments.has(attachment.id)
|
|
240
|
+
);
|
|
241
|
+
const attachmentsToUpload = [];
|
|
242
|
+
for (const attachment of newAttachments) {
|
|
243
|
+
if (attachment.type === "localAttachment") {
|
|
244
|
+
if (attachment.file.size > options.maxFileSize) {
|
|
245
|
+
attachments.set(attachment.id, {
|
|
246
|
+
...attachment,
|
|
247
|
+
status: "error",
|
|
248
|
+
error: new AttachmentTooLargeError("File is too large.")
|
|
249
|
+
});
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
attachments.set(attachment.id, {
|
|
253
|
+
...attachment,
|
|
254
|
+
status: "uploading"
|
|
255
|
+
});
|
|
256
|
+
attachmentsToUpload.push(attachment);
|
|
257
|
+
} else {
|
|
258
|
+
attachments.set(attachment.id, attachment);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (newAttachments.length > 0) {
|
|
262
|
+
notifySubscribers();
|
|
263
|
+
}
|
|
264
|
+
for (const attachment of attachmentsToUpload) {
|
|
265
|
+
uploadAttachment(attachment);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function removeAttachment(attachmentId) {
|
|
269
|
+
const abortController = abortControllers.get(attachmentId);
|
|
270
|
+
abortController?.abort();
|
|
271
|
+
attachments.delete(attachmentId);
|
|
272
|
+
abortControllers.delete(attachmentId);
|
|
273
|
+
notifySubscribers();
|
|
274
|
+
}
|
|
275
|
+
function getSnapshot() {
|
|
276
|
+
if (!cachedSnapshot) {
|
|
277
|
+
cachedSnapshot = Array.from(attachments.values());
|
|
278
|
+
}
|
|
279
|
+
return cachedSnapshot;
|
|
280
|
+
}
|
|
281
|
+
function clear() {
|
|
282
|
+
abortControllers.forEach((controller) => controller.abort());
|
|
283
|
+
abortControllers.clear();
|
|
284
|
+
eventSource.clear();
|
|
285
|
+
attachments.clear();
|
|
286
|
+
notifySubscribers();
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
addAttachments,
|
|
290
|
+
removeAttachment,
|
|
291
|
+
getSnapshot,
|
|
292
|
+
subscribe: eventSource.subscribe,
|
|
293
|
+
clear
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function preventBeforeUnloadDefault(event) {
|
|
297
|
+
event.preventDefault();
|
|
298
|
+
}
|
|
299
|
+
function useComposerAttachmentsManager(defaultAttachments, options) {
|
|
300
|
+
const room = useRoom();
|
|
301
|
+
const frozenDefaultAttachments = useInitial(defaultAttachments);
|
|
302
|
+
const frozenAttachmentsManager = useInitial(
|
|
303
|
+
() => createComposerAttachmentsManager(room, options)
|
|
304
|
+
);
|
|
305
|
+
useEffect(() => {
|
|
306
|
+
frozenAttachmentsManager.addAttachments(frozenDefaultAttachments);
|
|
307
|
+
}, [frozenDefaultAttachments, frozenAttachmentsManager]);
|
|
308
|
+
useEffect(() => {
|
|
309
|
+
return () => {
|
|
310
|
+
frozenAttachmentsManager.clear();
|
|
311
|
+
};
|
|
312
|
+
}, [frozenAttachmentsManager]);
|
|
313
|
+
const attachments = useSyncExternalStore(
|
|
314
|
+
frozenAttachmentsManager.subscribe,
|
|
315
|
+
frozenAttachmentsManager.getSnapshot,
|
|
316
|
+
frozenAttachmentsManager.getSnapshot
|
|
317
|
+
);
|
|
318
|
+
const isUploadingAttachments = useMemo(() => {
|
|
319
|
+
return attachments.some(
|
|
320
|
+
(attachment) => attachment.type === "localAttachment" && attachment.status === "uploading"
|
|
321
|
+
);
|
|
322
|
+
}, [attachments]);
|
|
323
|
+
useEffect(() => {
|
|
324
|
+
if (!isUploadingAttachments) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
window.addEventListener("beforeunload", preventBeforeUnloadDefault);
|
|
328
|
+
return () => {
|
|
329
|
+
window.removeEventListener("beforeunload", preventBeforeUnloadDefault);
|
|
330
|
+
};
|
|
331
|
+
}, [isUploadingAttachments]);
|
|
332
|
+
return {
|
|
333
|
+
attachments,
|
|
334
|
+
isUploadingAttachments,
|
|
335
|
+
addAttachments: frozenAttachmentsManager.addAttachments,
|
|
336
|
+
removeAttachment: frozenAttachmentsManager.removeAttachment,
|
|
337
|
+
clearAttachments: frozenAttachmentsManager.clear
|
|
338
|
+
};
|
|
339
|
+
}
|
|
112
340
|
|
|
113
|
-
export { commentBodyLinkToComposerBodyLink, commentBodyMentionToComposerBodyMention, commentBodyToComposerBody, composerBodyAutoLinkToCommentBodyLink, composerBodyCustomLinkToCommentBodyLink, composerBodyMentionToCommentBodyMention, composerBodyToCommentBody, getPlacementFromPosition, getSideAndAlignFromPlacement };
|
|
341
|
+
export { AttachmentTooLargeError, commentBodyLinkToComposerBodyLink, commentBodyMentionToComposerBodyMention, commentBodyToComposerBody, composerBodyAutoLinkToCommentBodyLink, composerBodyCustomLinkToCommentBodyLink, composerBodyMentionToCommentBodyMention, composerBodyToCommentBody, getPlacementFromPosition, getSideAndAlignFromPlacement, useComposerAttachmentsDropArea, useComposerAttachmentsManager };
|
|
114
342
|
//# sourceMappingURL=utils.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../../src/primitives/Composer/utils.ts"],"sourcesContent":["import type { Placement } from \"@floating-ui/react-dom\";\nimport type {\n CommentBody,\n CommentBodyLink,\n CommentBodyMention,\n} from \"@liveblocks/core\";\n\nimport { isComposerBodyAutoLink } from \"../../slate/plugins/auto-links\";\nimport { isComposerBodyCustomLink } from \"../../slate/plugins/custom-links\";\nimport { isComposerBodyMention } from \"../../slate/plugins/mentions\";\nimport { isText } from \"../../slate/utils/is-text\";\nimport type {\n ComposerBody,\n ComposerBodyAutoLink,\n ComposerBodyCustomLink,\n ComposerBodyMention,\n ComposerBodyText,\n Direction,\n} from \"../../types\";\nimport { exists } from \"../../utils/exists\";\nimport {\n isCommentBodyLink,\n isCommentBodyMention,\n isCommentBodyText,\n} from \"../Comment/utils\";\nimport type { SuggestionsPosition } from \"./types\";\n\nexport function composerBodyMentionToCommentBodyMention(\n mention: ComposerBodyMention\n): CommentBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n };\n}\n\nexport function composerBodyAutoLinkToCommentBodyLink(\n link: ComposerBodyAutoLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n };\n}\n\nexport function composerBodyCustomLinkToCommentBodyLink(\n link: ComposerBodyCustomLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n text: link.children.map((child) => child.text).join(\"\"),\n };\n}\n\nexport function commentBodyMentionToComposerBodyMention(\n mention: CommentBodyMention\n): ComposerBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n children: [{ text: \"\" }],\n };\n}\n\nexport function commentBodyLinkToComposerBodyLink(\n link: CommentBodyLink\n): ComposerBodyAutoLink | ComposerBodyCustomLink {\n if (link.text) {\n return {\n type: \"custom-link\",\n url: link.url,\n children: [{ text: link.text }],\n };\n } else {\n return {\n type: \"auto-link\",\n url: link.url,\n children: [{ text: link.url }],\n };\n }\n}\n\nexport function composerBodyToCommentBody(body: ComposerBody): CommentBody {\n return {\n version: 1,\n content: body\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isComposerBodyMention(inline)) {\n return composerBodyMentionToCommentBodyMention(inline);\n }\n\n if (isComposerBodyAutoLink(inline)) {\n return composerBodyAutoLinkToCommentBodyLink(inline);\n }\n\n if (isComposerBodyCustomLink(inline)) {\n return composerBodyCustomLinkToCommentBodyLink(inline);\n }\n\n if (isText(inline)) {\n return inline;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists),\n };\n}\n\nconst emptyComposerBody: ComposerBody = [];\n\nexport function commentBodyToComposerBody(body: CommentBody): ComposerBody {\n if (!body || !body?.content) {\n return emptyComposerBody;\n }\n\n return body.content\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isCommentBodyMention(inline)) {\n return commentBodyMentionToComposerBodyMention(inline);\n }\n\n if (isCommentBodyLink(inline)) {\n return commentBodyLinkToComposerBodyLink(inline);\n }\n\n if (isCommentBodyText(inline)) {\n return inline as ComposerBodyText;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists);\n}\n\nexport function getPlacementFromPosition(\n position: SuggestionsPosition,\n direction: Direction = \"ltr\"\n): Placement {\n return `${position}-${direction === \"rtl\" ? \"end\" : \"start\"}`;\n}\n\nexport function getSideAndAlignFromPlacement(placement: Placement) {\n const [side, align = \"center\"] = placement.split(\"-\");\n\n return [side, align] as const;\n}\n"],"names":[],"mappings":";;;;;;;AA2BO,SAAS,wCACd,OACoB,EAAA;AACpB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,SAAA;AAAA,IACN,IAAI,OAAQ,CAAA,EAAA;AAAA,GACd,CAAA;AACF,CAAA;AAEO,SAAS,sCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,GACZ,CAAA;AACF,CAAA;AAEO,SAAS,wCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,IACV,IAAA,EAAM,IAAK,CAAA,QAAA,CAAS,GAAI,CAAA,CAAC,UAAU,KAAM,CAAA,IAAI,CAAE,CAAA,IAAA,CAAK,EAAE,CAAA;AAAA,GACxD,CAAA;AACF,CAAA;AAEO,SAAS,wCACd,OACqB,EAAA;AACrB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,SAAA;AAAA,IACN,IAAI,OAAQ,CAAA,EAAA;AAAA,IACZ,QAAU,EAAA,CAAC,EAAE,IAAA,EAAM,IAAI,CAAA;AAAA,GACzB,CAAA;AACF,CAAA;AAEO,SAAS,kCACd,IAC+C,EAAA;AAC/C,EAAA,IAAI,KAAK,IAAM,EAAA;AACb,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,aAAA;AAAA,MACN,KAAK,IAAK,CAAA,GAAA;AAAA,MACV,UAAU,CAAC,EAAE,IAAM,EAAA,IAAA,CAAK,MAAM,CAAA;AAAA,KAChC,CAAA;AAAA,GACK,MAAA;AACL,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,WAAA;AAAA,MACN,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ources":["../../../src/primitives/Composer/utils.ts"],"sourcesContent":["import type { Placement } from \"@floating-ui/react-dom\";\nimport {\n type CommentAttachment,\n type CommentBody,\n type CommentBodyLink,\n type CommentBodyMention,\n type CommentLocalAttachment,\n type CommentMixedAttachment,\n CommentsApiError,\n makeEventSource,\n type OpaqueRoom,\n} from \"@liveblocks/core\";\nimport { useRoom } from \"@liveblocks/react\";\nimport type { DragEvent } from \"react\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\n\nimport { isComposerBodyAutoLink } from \"../../slate/plugins/auto-links\";\nimport { isComposerBodyCustomLink } from \"../../slate/plugins/custom-links\";\nimport { isComposerBodyMention } from \"../../slate/plugins/mentions\";\nimport { isText } from \"../../slate/utils/is-text\";\nimport type {\n ComposerBody,\n ComposerBodyAutoLink,\n ComposerBodyCustomLink,\n ComposerBodyMention,\n ComposerBodyText,\n Direction,\n} from \"../../types\";\nimport { getFiles } from \"../../utils/data-transfer\";\nimport { exists } from \"../../utils/exists\";\nimport { useInitial } from \"../../utils/use-initial\";\nimport { useLatest } from \"../../utils/use-latest\";\nimport {\n isCommentBodyLink,\n isCommentBodyMention,\n isCommentBodyText,\n} from \"../Comment/utils\";\nimport { useComposer, useComposerAttachmentsContext } from \"./contexts\";\nimport type { SuggestionsPosition } from \"./types\";\n\nexport function composerBodyMentionToCommentBodyMention(\n mention: ComposerBodyMention\n): CommentBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n };\n}\n\nexport function composerBodyAutoLinkToCommentBodyLink(\n link: ComposerBodyAutoLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n };\n}\n\nexport function composerBodyCustomLinkToCommentBodyLink(\n link: ComposerBodyCustomLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n text: link.children.map((child) => child.text).join(\"\"),\n };\n}\n\nexport function commentBodyMentionToComposerBodyMention(\n mention: CommentBodyMention\n): ComposerBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n children: [{ text: \"\" }],\n };\n}\n\nexport function commentBodyLinkToComposerBodyLink(\n link: CommentBodyLink\n): ComposerBodyAutoLink | ComposerBodyCustomLink {\n if (link.text) {\n return {\n type: \"custom-link\",\n url: link.url,\n children: [{ text: link.text }],\n };\n } else {\n return {\n type: \"auto-link\",\n url: link.url,\n children: [{ text: link.url }],\n };\n }\n}\n\nexport function composerBodyToCommentBody(body: ComposerBody): CommentBody {\n return {\n version: 1,\n content: body\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isComposerBodyMention(inline)) {\n return composerBodyMentionToCommentBodyMention(inline);\n }\n\n if (isComposerBodyAutoLink(inline)) {\n return composerBodyAutoLinkToCommentBodyLink(inline);\n }\n\n if (isComposerBodyCustomLink(inline)) {\n return composerBodyCustomLinkToCommentBodyLink(inline);\n }\n\n if (isText(inline)) {\n return inline;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists),\n };\n}\n\nconst emptyComposerBody: ComposerBody = [];\n\nexport function commentBodyToComposerBody(body: CommentBody): ComposerBody {\n if (!body || !body?.content) {\n return emptyComposerBody;\n }\n\n return body.content\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isCommentBodyMention(inline)) {\n return commentBodyMentionToComposerBodyMention(inline);\n }\n\n if (isCommentBodyLink(inline)) {\n return commentBodyLinkToComposerBodyLink(inline);\n }\n\n if (isCommentBodyText(inline)) {\n return inline as ComposerBodyText;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists);\n}\n\nexport function getPlacementFromPosition(\n position: SuggestionsPosition,\n direction: Direction = \"ltr\"\n): Placement {\n return `${position}-${direction === \"rtl\" ? \"end\" : \"start\"}`;\n}\n\nexport function getSideAndAlignFromPlacement(placement: Placement) {\n const [side, align = \"center\"] = placement.split(\"-\");\n\n return [side, align] as const;\n}\n\nexport function useComposerAttachmentsDropArea<\n T extends HTMLElement = HTMLElement,\n>({\n onDragEnter,\n onDragLeave,\n onDragOver,\n onDrop,\n disabled,\n}: {\n onDragEnter?: (event: DragEvent<T>) => void;\n onDragLeave?: (event: DragEvent<T>) => void;\n onDragOver?: (event: DragEvent<T>) => void;\n onDrop?: (event: DragEvent<T>) => void;\n disabled?: boolean;\n}) {\n const { isDisabled: isComposerDisabled } = useComposer();\n const isDisabled = isComposerDisabled || disabled;\n const { createAttachments } = useComposerAttachmentsContext();\n const [isDraggingOver, setDraggingOver] = useState(false);\n const latestIsDraggingOver = useLatest(isDraggingOver);\n\n const handleDragEnter = useCallback(\n (event: DragEvent<T>) => {\n onDragEnter?.(event);\n\n if (\n latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n const dataTransfer = event.dataTransfer;\n\n if (!dataTransfer.types.includes(\"Files\")) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(true);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDragEnter, isDisabled]\n );\n\n const handleDragLeave = useCallback(\n (event: DragEvent<T>) => {\n onDragLeave?.(event);\n\n if (\n !latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n // Ignore drag leave events that are not actually leaving the drop area\n if (\n event.relatedTarget\n ? event.relatedTarget === event.currentTarget ||\n event.currentTarget.contains(event.relatedTarget as HTMLElement)\n : event.currentTarget !== event.target\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(false);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDragLeave, isDisabled]\n );\n\n const handleDragOver = useCallback(\n (event: DragEvent<T>) => {\n onDragOver?.(event);\n\n if (isDisabled || event.isDefaultPrevented()) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n },\n [onDragOver, isDisabled]\n );\n\n const handleDrop = useCallback(\n (event: DragEvent<T>) => {\n onDrop?.(event);\n\n if (\n !latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(false);\n\n const files = getFiles(event.dataTransfer);\n\n createAttachments(files);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDrop, isDisabled, createAttachments]\n );\n\n return [\n isDraggingOver,\n {\n onDragEnter: handleDragEnter,\n onDragLeave: handleDragLeave,\n onDragOver: handleDragOver,\n onDrop: handleDrop,\n \"data-drop\": isDraggingOver ? \"\" : undefined,\n \"data-disabled\": isDisabled ? \"\" : undefined,\n } as const,\n ] as const;\n}\n\ninterface ComposerAttachmentsManagerOptions {\n maxFileSize: number;\n}\n\nexport class AttachmentTooLargeError extends Error {\n name = \"AttachmentTooLargeError\";\n}\n\nfunction createComposerAttachmentsManager(\n room: OpaqueRoom,\n options: ComposerAttachmentsManagerOptions\n) {\n const attachments: Map<string, CommentMixedAttachment> = new Map();\n const abortControllers: Map<string, AbortController> = new Map();\n const eventSource = makeEventSource<void>();\n let cachedSnapshot: CommentMixedAttachment[] | null = null;\n\n function notifySubscribers() {\n // Invalidate the cached snapshot\n cachedSnapshot = null;\n eventSource.notify();\n }\n\n function uploadAttachment(attachment: CommentLocalAttachment) {\n const abortController = new AbortController();\n abortControllers.set(attachment.id, abortController);\n\n room\n .uploadAttachment(attachment, {\n signal: abortController.signal,\n })\n .then(() => {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"uploaded\",\n });\n notifySubscribers();\n })\n .catch((error) => {\n if (\n error instanceof Error &&\n error.name !== \"AbortError\" &&\n error.name !== \"TimeoutError\"\n ) {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"error\",\n error:\n error instanceof CommentsApiError && error.status === 413\n ? new AttachmentTooLargeError(\"File is too large.\")\n : error,\n });\n notifySubscribers();\n }\n });\n }\n\n function addAttachments(addedAttachments: CommentMixedAttachment[]) {\n // Ignore attachments that are already in the manager\n const newAttachments = addedAttachments.filter(\n (attachment) => !attachments.has(attachment.id)\n );\n\n const attachmentsToUpload: CommentLocalAttachment[] = [];\n\n // Add all the new attachments to the manager\n for (const attachment of newAttachments) {\n if (attachment.type === \"localAttachment\") {\n // The file is too large to be uploaded\n if (attachment.file.size > options.maxFileSize) {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"error\",\n error: new AttachmentTooLargeError(\"File is too large.\"),\n });\n\n continue;\n }\n\n // Otherwise, mark the attachment to be uploaded\n attachments.set(attachment.id, {\n ...attachment,\n status: \"uploading\",\n });\n attachmentsToUpload.push(attachment);\n } else {\n attachments.set(attachment.id, attachment);\n }\n }\n\n // Notify subscribers about the new attachments that were added\n if (newAttachments.length > 0) {\n notifySubscribers();\n }\n\n // Upload all the new local attachments\n for (const attachment of attachmentsToUpload) {\n uploadAttachment(attachment);\n }\n }\n\n function removeAttachment(attachmentId: string) {\n const abortController = abortControllers.get(attachmentId);\n\n abortController?.abort();\n\n attachments.delete(attachmentId);\n abortControllers.delete(attachmentId);\n\n notifySubscribers();\n }\n\n function getSnapshot() {\n if (!cachedSnapshot) {\n cachedSnapshot = Array.from(attachments.values());\n }\n\n return cachedSnapshot;\n }\n\n function clear() {\n abortControllers.forEach((controller) => controller.abort());\n abortControllers.clear();\n eventSource.clear();\n attachments.clear();\n\n notifySubscribers();\n }\n\n return {\n addAttachments,\n removeAttachment,\n getSnapshot,\n subscribe: eventSource.subscribe,\n clear,\n };\n}\n\nfunction preventBeforeUnloadDefault(event: BeforeUnloadEvent) {\n event.preventDefault();\n}\n\nexport function useComposerAttachmentsManager(\n defaultAttachments: CommentAttachment[],\n options: ComposerAttachmentsManagerOptions\n) {\n const room = useRoom();\n const frozenDefaultAttachments = useInitial(defaultAttachments);\n const frozenAttachmentsManager = useInitial(() =>\n createComposerAttachmentsManager(room, options)\n );\n\n // Initialize default attachments on mount\n useEffect(() => {\n frozenAttachmentsManager.addAttachments(frozenDefaultAttachments);\n }, [frozenDefaultAttachments, frozenAttachmentsManager]);\n\n // Clear attachments on unmount\n useEffect(() => {\n return () => {\n frozenAttachmentsManager.clear();\n };\n }, [frozenAttachmentsManager]);\n\n const attachments = useSyncExternalStore(\n frozenAttachmentsManager.subscribe,\n frozenAttachmentsManager.getSnapshot,\n frozenAttachmentsManager.getSnapshot\n );\n\n const isUploadingAttachments = useMemo(() => {\n return attachments.some(\n (attachment) =>\n attachment.type === \"localAttachment\" &&\n attachment.status === \"uploading\"\n );\n }, [attachments]);\n\n useEffect(() => {\n if (!isUploadingAttachments) {\n return;\n }\n\n window.addEventListener(\"beforeunload\", preventBeforeUnloadDefault);\n\n return () => {\n window.removeEventListener(\"beforeunload\", preventBeforeUnloadDefault);\n };\n }, [isUploadingAttachments]);\n\n return {\n attachments,\n isUploadingAttachments,\n addAttachments: frozenAttachmentsManager.addAttachments,\n removeAttachment: frozenAttachmentsManager.removeAttachment,\n clearAttachments: frozenAttachmentsManager.clear,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAyCO,SAAS,wCACd,OACoB,EAAA;AACpB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,SAAA;AAAA,IACN,IAAI,OAAQ,CAAA,EAAA;AAAA,GACd,CAAA;AACF,CAAA;AAEO,SAAS,sCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,GACZ,CAAA;AACF,CAAA;AAEO,SAAS,wCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,IACV,IAAA,EAAM,IAAK,CAAA,QAAA,CAAS,GAAI,CAAA,CAAC,UAAU,KAAM,CAAA,IAAI,CAAE,CAAA,IAAA,CAAK,EAAE,CAAA;AAAA,GAC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