@templatical/media-library 0.2.0 → 0.2.1
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { API_ROUTES as e, ApiClient as t, buildUrl as n, createSdkAuthManager as r } from "@templatical/core/cloud";
|
|
2
2
|
import { Fragment as i, Teleport as a, Transition as o, computed as s, createApp as c, createBlock as l, createCommentVNode as u, createElementBlock as d, createElementVNode as f, createTextVNode as p, createVNode as m, defineComponent as h, h as g, inject as _, isRef as v, normalizeClass as y, normalizeStyle as b, onMounted as x, openBlock as S, provide as C, ref as w, renderList as T, resolveComponent as E, toDisplayString as D, unref as O, vModelText as k, watch as A, withCtx as j, withDirectives as M, withKeys as N, withModifiers as P } from "vue";
|
|
3
|
-
import { Check as F, ChevronRight as I, Copy as L, File as R, Folder as z, Grid2x2 as B, Link as V, List as H, LoaderCircle as U, PanelLeft as W, Pencil as G, Plus as K, RefreshCw as q, Search as J, Star as
|
|
3
|
+
import { Check as F, ChevronRight as I, Copy as L, File as R, Folder as z, Grid2x2 as B, Link as V, List as H, LoaderCircle as U, PanelLeft as W, Pencil as G, Plus as K, RefreshCw as q, Search as J, Star as Y, Trash2 as ee, Upload as X, X as te } from "@lucide/vue";
|
|
4
4
|
import { Cropper as ne } from "vue-advanced-cropper";
|
|
5
5
|
import { onClickOutside as re, useClipboard as ie, useDebounceFn as ae, useDropZone as oe, useEventListener as se, useFileDialog as ce, useIntersectionObserver as le } from "@vueuse/core";
|
|
6
6
|
//#region src/api-client.ts
|
|
@@ -162,8 +162,9 @@ var ue = class {
|
|
|
162
162
|
//#region src/composable.ts
|
|
163
163
|
function de(e) {
|
|
164
164
|
if (!e.projectId) throw Error("projectId is required for useMediaLibrary");
|
|
165
|
-
let t = new ue(e.authManager), n = w([]), r = w([]), i = w(null), a = w("files"), o = w(""), s = w(null), c = w("newest"), l = w(!1), u = w(!1), d = w(!1), f = w(null), p = w(null), m = w(/* @__PURE__ */ new Set()), h = w(null), g = w([]), _ = w({}), v = w(!1), y = w([]), b = w(!1), x = w(null), S = w(!1), C = w(null), T = w(!1), E = w(null), D = w(null);
|
|
166
|
-
async function
|
|
165
|
+
let t = new ue(e.authManager), n = w([]), r = w([]), i = w(null), a = w("files"), o = w(""), s = w(null), c = w("newest"), l = w(!1), u = w(!1), d = w(!1), f = w(null), p = w(null), m = w(/* @__PURE__ */ new Set()), h = w(null), g = w([]), _ = w({}), v = w(!1), y = w([]), b = w(!1), x = w(null), S = w(!1), C = w(null), T = w(!1), E = w(null), D = w(null), O = 0;
|
|
166
|
+
async function k() {
|
|
167
|
+
let r = ++O;
|
|
167
168
|
l.value = !0;
|
|
168
169
|
try {
|
|
169
170
|
let e = await t.browseMedia({
|
|
@@ -172,48 +173,52 @@ function de(e) {
|
|
|
172
173
|
category: s.value || void 0,
|
|
173
174
|
sort: c.value === "newest" ? void 0 : c.value
|
|
174
175
|
});
|
|
176
|
+
if (r !== O) return;
|
|
175
177
|
n.value = e.data, f.value = e.meta.next_cursor, d.value = !!e.meta.next_cursor;
|
|
176
178
|
} catch (t) {
|
|
179
|
+
if (r !== O) return;
|
|
177
180
|
e.onError?.(t);
|
|
178
181
|
} finally {
|
|
179
|
-
l.value = !1;
|
|
182
|
+
r === O && (l.value = !1);
|
|
180
183
|
}
|
|
181
184
|
}
|
|
182
|
-
async function
|
|
183
|
-
if (!
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
185
|
+
async function A() {
|
|
186
|
+
if (!d.value || !f.value || l.value) return;
|
|
187
|
+
let r = ++O;
|
|
188
|
+
l.value = !0;
|
|
189
|
+
try {
|
|
190
|
+
let e = await t.browseMedia({
|
|
191
|
+
folder_id: o.value ? void 0 : i.value,
|
|
192
|
+
search: o.value || void 0,
|
|
193
|
+
category: s.value || void 0,
|
|
194
|
+
sort: c.value === "newest" ? void 0 : c.value,
|
|
195
|
+
cursor: f.value
|
|
196
|
+
});
|
|
197
|
+
if (r !== O) return;
|
|
198
|
+
n.value = [...n.value, ...e.data], f.value = e.meta.next_cursor, d.value = !!e.meta.next_cursor;
|
|
199
|
+
} catch (t) {
|
|
200
|
+
if (r !== O) return;
|
|
201
|
+
e.onError?.(t);
|
|
202
|
+
} finally {
|
|
203
|
+
r === O && (l.value = !1);
|
|
199
204
|
}
|
|
200
205
|
}
|
|
201
|
-
async function A(e) {
|
|
202
|
-
o.value = e, await O();
|
|
203
|
-
}
|
|
204
206
|
async function j(e) {
|
|
205
|
-
|
|
207
|
+
o.value = e, await k();
|
|
206
208
|
}
|
|
207
209
|
async function M(e) {
|
|
208
|
-
|
|
210
|
+
s.value = e, await k();
|
|
209
211
|
}
|
|
210
212
|
async function N(e) {
|
|
211
|
-
|
|
213
|
+
c.value = e, await k();
|
|
212
214
|
}
|
|
213
|
-
async function P() {
|
|
214
|
-
a.value = "
|
|
215
|
+
async function P(e) {
|
|
216
|
+
a.value = "files", i.value = e, o.value = "", m.value = /* @__PURE__ */ new Set(), h.value = null, await k();
|
|
217
|
+
}
|
|
218
|
+
async function F() {
|
|
219
|
+
a.value = "frequently-used", i.value = null, o.value = "", m.value = /* @__PURE__ */ new Set(), h.value = null, await V();
|
|
215
220
|
}
|
|
216
|
-
async function
|
|
221
|
+
async function I(r) {
|
|
217
222
|
u.value = !0;
|
|
218
223
|
try {
|
|
219
224
|
let e = await t.uploadMedia(r, i.value);
|
|
@@ -224,7 +229,7 @@ function de(e) {
|
|
|
224
229
|
u.value = !1;
|
|
225
230
|
}
|
|
226
231
|
}
|
|
227
|
-
async function
|
|
232
|
+
async function L(r) {
|
|
228
233
|
u.value = !0, p.value = {
|
|
229
234
|
current: 0,
|
|
230
235
|
total: r.length
|
|
@@ -245,7 +250,7 @@ function de(e) {
|
|
|
245
250
|
u.value = !1, p.value = null;
|
|
246
251
|
}
|
|
247
252
|
}
|
|
248
|
-
async function
|
|
253
|
+
async function R(r) {
|
|
249
254
|
if (m.value.size !== 0) try {
|
|
250
255
|
let e = await t.moveMedia([...m.value], r);
|
|
251
256
|
if (i.value === null) {
|
|
@@ -257,7 +262,7 @@ function de(e) {
|
|
|
257
262
|
e.onError?.(t);
|
|
258
263
|
}
|
|
259
264
|
}
|
|
260
|
-
async function
|
|
265
|
+
async function z(r, i, a) {
|
|
261
266
|
try {
|
|
262
267
|
let e = await t.updateMedia(r, i, a);
|
|
263
268
|
n.value = n.value.map((t) => t.id === r ? e : t), h.value?.id === r && (h.value = e);
|
|
@@ -265,21 +270,21 @@ function de(e) {
|
|
|
265
270
|
e.onError?.(t);
|
|
266
271
|
}
|
|
267
272
|
}
|
|
268
|
-
async function
|
|
273
|
+
async function B() {
|
|
269
274
|
if (m.value.size !== 0) try {
|
|
270
275
|
await t.deleteMedia([...m.value]), n.value = n.value.filter((e) => !m.value.has(e.id)), g.value = g.value.filter((e) => !m.value.has(e.id)), m.value = /* @__PURE__ */ new Set(), h.value = null;
|
|
271
276
|
} catch (t) {
|
|
272
277
|
e.onError?.(t);
|
|
273
278
|
}
|
|
274
279
|
}
|
|
275
|
-
async function
|
|
280
|
+
async function V() {
|
|
276
281
|
try {
|
|
277
282
|
g.value = await t.getFrequentlyUsed();
|
|
278
283
|
} catch (t) {
|
|
279
284
|
e.onError?.(t);
|
|
280
285
|
}
|
|
281
286
|
}
|
|
282
|
-
async function
|
|
287
|
+
async function H() {
|
|
283
288
|
if (m.value.size === 0) return !1;
|
|
284
289
|
y.value = [...m.value];
|
|
285
290
|
try {
|
|
@@ -291,17 +296,17 @@ function de(e) {
|
|
|
291
296
|
return e.onError?.(t), !1;
|
|
292
297
|
}
|
|
293
298
|
}
|
|
294
|
-
async function
|
|
299
|
+
async function U() {
|
|
295
300
|
if (v.value = !1, y.value.length !== 0) try {
|
|
296
301
|
await t.deleteMedia(y.value), n.value = n.value.filter((e) => !y.value.includes(e.id)), g.value = g.value.filter((e) => !y.value.includes(e.id)), m.value = /* @__PURE__ */ new Set(), h.value = null, y.value = [], _.value = {};
|
|
297
302
|
} catch (t) {
|
|
298
303
|
e.onError?.(t);
|
|
299
304
|
}
|
|
300
305
|
}
|
|
301
|
-
function
|
|
306
|
+
function W() {
|
|
302
307
|
v.value = !1, y.value = [], _.value = {};
|
|
303
308
|
}
|
|
304
|
-
async function
|
|
309
|
+
async function G(r) {
|
|
305
310
|
b.value = !0, x.value = null;
|
|
306
311
|
try {
|
|
307
312
|
let e = await t.importFromUrl(r, i.value);
|
|
@@ -312,17 +317,17 @@ function de(e) {
|
|
|
312
317
|
b.value = !1;
|
|
313
318
|
}
|
|
314
319
|
}
|
|
315
|
-
function
|
|
320
|
+
function K(e) {
|
|
316
321
|
let t = new Set(m.value);
|
|
317
322
|
t.has(e) ? t.delete(e) : t.add(e), m.value = t;
|
|
318
323
|
}
|
|
319
|
-
function
|
|
324
|
+
function q() {
|
|
320
325
|
m.value = /* @__PURE__ */ new Set(), h.value = null;
|
|
321
326
|
}
|
|
322
|
-
function
|
|
327
|
+
function J(e) {
|
|
323
328
|
h.value = e, m.value = new Set([e.id]);
|
|
324
329
|
}
|
|
325
|
-
async function
|
|
330
|
+
async function Y() {
|
|
326
331
|
try {
|
|
327
332
|
r.value = await t.getMediaFolders();
|
|
328
333
|
} catch (t) {
|
|
@@ -332,37 +337,37 @@ function de(e) {
|
|
|
332
337
|
async function ee(n, r) {
|
|
333
338
|
try {
|
|
334
339
|
let e = await t.createMediaFolder(n, r);
|
|
335
|
-
return await
|
|
340
|
+
return await Y(), e;
|
|
336
341
|
} catch (t) {
|
|
337
342
|
return e.onError?.(t), null;
|
|
338
343
|
}
|
|
339
344
|
}
|
|
340
|
-
function
|
|
345
|
+
function X(e, t) {
|
|
341
346
|
for (let n of e) {
|
|
342
347
|
if (n.id === t) return n;
|
|
343
348
|
if (n.children) {
|
|
344
|
-
let e =
|
|
349
|
+
let e = X(n.children, t);
|
|
345
350
|
if (e) return e;
|
|
346
351
|
}
|
|
347
352
|
}
|
|
348
353
|
return null;
|
|
349
354
|
}
|
|
350
|
-
async function
|
|
355
|
+
async function te(n, r) {
|
|
351
356
|
try {
|
|
352
|
-
await t.renameMediaFolder(n, r), await
|
|
357
|
+
await t.renameMediaFolder(n, r), await Y();
|
|
353
358
|
} catch (t) {
|
|
354
359
|
e.onError?.(t);
|
|
355
360
|
}
|
|
356
361
|
}
|
|
357
|
-
async function
|
|
362
|
+
async function ne(n) {
|
|
358
363
|
try {
|
|
359
|
-
let e =
|
|
360
|
-
await t.deleteMediaFolder(n), i.value === n && (i.value = e), await
|
|
364
|
+
let e = X(r.value, n)?.parent_id ?? null;
|
|
365
|
+
await t.deleteMediaFolder(n), i.value === n && (i.value = e), await Y(), await k();
|
|
361
366
|
} catch (t) {
|
|
362
367
|
e.onError?.(t);
|
|
363
368
|
}
|
|
364
369
|
}
|
|
365
|
-
async function
|
|
370
|
+
async function re(n) {
|
|
366
371
|
E.value = n, C.value = null;
|
|
367
372
|
try {
|
|
368
373
|
D.value = (await t.checkMediaUsage([n.id])).data[n.id] ?? null, T.value = !0;
|
|
@@ -370,10 +375,10 @@ function de(e) {
|
|
|
370
375
|
e.onError?.(t);
|
|
371
376
|
}
|
|
372
377
|
}
|
|
373
|
-
function
|
|
378
|
+
function ie() {
|
|
374
379
|
T.value = !1, E.value = null, D.value = null, C.value = null;
|
|
375
380
|
}
|
|
376
|
-
async function
|
|
381
|
+
async function ae(r) {
|
|
377
382
|
if (!E.value) return null;
|
|
378
383
|
S.value = !0, C.value = null;
|
|
379
384
|
try {
|
|
@@ -385,7 +390,7 @@ function de(e) {
|
|
|
385
390
|
S.value = !1;
|
|
386
391
|
}
|
|
387
392
|
}
|
|
388
|
-
async function
|
|
393
|
+
async function oe(r, i) {
|
|
389
394
|
try {
|
|
390
395
|
let e = await t.replaceMedia(r, i);
|
|
391
396
|
return n.value = n.value.map((t) => t.id === e.id ? e : t), g.value = g.value.map((t) => t.id === e.id ? e : t), h.value?.id === e.id && (h.value = e), e;
|
|
@@ -410,42 +415,42 @@ function de(e) {
|
|
|
410
415
|
frequentlyUsedItems: g,
|
|
411
416
|
deleteUsageInfo: _,
|
|
412
417
|
showDeleteWarning: v,
|
|
413
|
-
loadItems:
|
|
414
|
-
loadMore:
|
|
415
|
-
search:
|
|
416
|
-
filterByCategory:
|
|
417
|
-
sortBy:
|
|
418
|
-
navigateToFolder:
|
|
419
|
-
showFrequentlyUsed:
|
|
420
|
-
uploadFile:
|
|
421
|
-
uploadFiles:
|
|
422
|
-
moveSelected:
|
|
423
|
-
updateFile:
|
|
424
|
-
deleteSelected:
|
|
418
|
+
loadItems: k,
|
|
419
|
+
loadMore: A,
|
|
420
|
+
search: j,
|
|
421
|
+
filterByCategory: M,
|
|
422
|
+
sortBy: N,
|
|
423
|
+
navigateToFolder: P,
|
|
424
|
+
showFrequentlyUsed: F,
|
|
425
|
+
uploadFile: I,
|
|
426
|
+
uploadFiles: L,
|
|
427
|
+
moveSelected: R,
|
|
428
|
+
updateFile: z,
|
|
429
|
+
deleteSelected: B,
|
|
425
430
|
isImportingFromUrl: b,
|
|
426
431
|
importFromUrlError: x,
|
|
427
|
-
importFromUrl:
|
|
428
|
-
toggleSelection:
|
|
429
|
-
clearSelection:
|
|
430
|
-
selectItem:
|
|
431
|
-
loadFolders:
|
|
432
|
+
importFromUrl: G,
|
|
433
|
+
toggleSelection: K,
|
|
434
|
+
clearSelection: q,
|
|
435
|
+
selectItem: J,
|
|
436
|
+
loadFolders: Y,
|
|
432
437
|
createFolder: ee,
|
|
433
|
-
renameFolder:
|
|
434
|
-
deleteFolder:
|
|
435
|
-
findFolderInTree:
|
|
436
|
-
loadFrequentlyUsed:
|
|
437
|
-
checkUsageBeforeDelete:
|
|
438
|
-
confirmDelete:
|
|
439
|
-
cancelDelete:
|
|
438
|
+
renameFolder: te,
|
|
439
|
+
deleteFolder: ne,
|
|
440
|
+
findFolderInTree: X,
|
|
441
|
+
loadFrequentlyUsed: V,
|
|
442
|
+
checkUsageBeforeDelete: H,
|
|
443
|
+
confirmDelete: U,
|
|
444
|
+
cancelDelete: W,
|
|
440
445
|
isReplacing: S,
|
|
441
446
|
replaceError: C,
|
|
442
447
|
showReplaceWarning: T,
|
|
443
448
|
pendingReplaceItem: E,
|
|
444
449
|
replaceUsageInfo: D,
|
|
445
|
-
checkUsageBeforeReplace:
|
|
446
|
-
cancelReplace:
|
|
447
|
-
replaceFile:
|
|
448
|
-
replaceMediaDirectly:
|
|
450
|
+
checkUsageBeforeReplace: re,
|
|
451
|
+
cancelReplace: ie,
|
|
452
|
+
replaceFile: ae,
|
|
453
|
+
replaceMediaDirectly: oe
|
|
449
454
|
};
|
|
450
455
|
}
|
|
451
456
|
//#endregion
|
|
@@ -666,11 +671,11 @@ var xe = ["data-tpl-theme"], Se = { class: "tpl:shrink-0 tpl:p-5 tpl:pb-4" }, Ce
|
|
|
666
671
|
function J() {
|
|
667
672
|
V.value = !0, !z.value && n.item?.width && n.item?.height && (z.value = n.item.width / n.item.height);
|
|
668
673
|
}
|
|
669
|
-
function
|
|
674
|
+
function Y(e) {
|
|
670
675
|
let t = e.target.value;
|
|
671
676
|
L.value = t, F.value = t && parseInt(t, 10) || void 0;
|
|
672
677
|
}
|
|
673
|
-
function
|
|
678
|
+
function ee(e) {
|
|
674
679
|
let t = e.target.value;
|
|
675
680
|
R.value = t, I.value = t && parseInt(t, 10) || void 0;
|
|
676
681
|
}
|
|
@@ -756,7 +761,7 @@ var xe = ["data-tpl-theme"], Se = { class: "tpl:shrink-0 tpl:p-5 tpl:pb-4" }, Ce
|
|
|
756
761
|
color: "var(--tpl-text)"
|
|
757
762
|
},
|
|
758
763
|
placeholder: B.value?.width?.toString() || "",
|
|
759
|
-
onInput:
|
|
764
|
+
onInput: Y
|
|
760
765
|
}, null, 40, Ie), f("span", Le, D(O(c).mediaLibrary.cropPixels), 1)])]), f("div", Re, [f("label", ze, [p(D(O(c).mediaLibrary.cropMaxHeight) + " ", 1), f("span", Be, D(O(c).mediaLibrary.cropOptional), 1)]), f("div", Ve, [f("input", {
|
|
761
766
|
value: R.value,
|
|
762
767
|
type: "number",
|
|
@@ -768,7 +773,7 @@ var xe = ["data-tpl-theme"], Se = { class: "tpl:shrink-0 tpl:p-5 tpl:pb-4" }, Ce
|
|
|
768
773
|
color: "var(--tpl-text)"
|
|
769
774
|
},
|
|
770
775
|
placeholder: B.value?.height?.toString() || "",
|
|
771
|
-
onInput:
|
|
776
|
+
onInput: ee
|
|
772
777
|
}, null, 40, He), f("span", Ue, D(O(c).mediaLibrary.cropPixels), 1)])])]),
|
|
773
778
|
K.value ? (S(), d("div", We, [f("span", null, D(O(c).mediaLibrary.cropOutputSize) + ": ", 1), f("span", Ge, D(K.value.width) + " x " + D(K.value.height) + " " + D(O(c).mediaLibrary.cropPixels), 1)])) : u("", !0)
|
|
774
779
|
])])) : u("", !0),
|
|
@@ -930,7 +935,7 @@ var xe = ["data-tpl-theme"], Se = { class: "tpl:shrink-0 tpl:p-5 tpl:pb-4" }, Ce
|
|
|
930
935
|
f("button", {
|
|
931
936
|
class: "tpl:flex tpl:size-6 tpl:items-center tpl:justify-center tpl:rounded tpl:transition-colors",
|
|
932
937
|
onClick: n[3] ||= P((t) => r("deleteFolder", e.folder.id), ["stop"])
|
|
933
|
-
}, [m(O(
|
|
938
|
+
}, [m(O(ee), {
|
|
934
939
|
size: 12,
|
|
935
940
|
"stroke-width": 2,
|
|
936
941
|
style: { color: "var(--tpl-danger)" }
|
|
@@ -1053,7 +1058,7 @@ var xe = ["data-tpl-theme"], Se = { class: "tpl:shrink-0 tpl:p-5 tpl:pb-4" }, Ce
|
|
|
1053
1058
|
color: e.viewMode === "frequently-used" ? "var(--tpl-primary)" : "var(--tpl-text)"
|
|
1054
1059
|
}),
|
|
1055
1060
|
onClick: g[6] ||= (e) => n("showFrequentlyUsed")
|
|
1056
|
-
}, [m(O(
|
|
1061
|
+
}, [m(O(Y), {
|
|
1057
1062
|
size: 14,
|
|
1058
1063
|
"stroke-width": 1.5
|
|
1059
1064
|
}), p(" " + D(O(r).mediaLibrary.frequentlyUsed), 1)], 4)) : u("", !0)
|
|
@@ -3001,11 +3006,10 @@ var $ = null, Pi = w(null);
|
|
|
3001
3006
|
async function Fi(e) {
|
|
3002
3007
|
let n = typeof e.container == "string" ? document.querySelector(e.container) : e.container;
|
|
3003
3008
|
if (!n) throw Error(`Container element not found: ${e.container}`);
|
|
3004
|
-
$ && Ii();
|
|
3005
3009
|
let i = r(e.auth, e.onError);
|
|
3006
3010
|
await i.initialize();
|
|
3007
3011
|
let a = await new t(i).fetchConfig(), o = await Ni(e.locale ?? "en");
|
|
3008
|
-
return Li(n, e.theme), new Promise((t, r) => {
|
|
3012
|
+
return Li(n, e.theme), $ && Ii(), new Promise((t, r) => {
|
|
3009
3013
|
try {
|
|
3010
3014
|
$ = c({ setup() {
|
|
3011
3015
|
let r = () => {
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@templatical/media-library",
|
|
3
3
|
"description": "Media library management for Templatical email editor",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"bugs": "https://github.com/templatical/sdk/issues",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@lucide/vue": "^1.11.0",
|
|
8
8
|
"@vueuse/core": "^14.2.1",
|
|
9
9
|
"vue-advanced-cropper": "^2.8.9",
|
|
10
|
-
"@templatical/core": "0.2.
|
|
11
|
-
"@templatical/types": "0.2.
|
|
10
|
+
"@templatical/core": "0.2.1",
|
|
11
|
+
"@templatical/types": "0.2.1"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@vitejs/plugin-vue": "^6.0.6",
|