ablok-components 0.3.68 → 0.3.70

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.
@@ -0,0 +1,542 @@
1
+ import { defineComponent as _, computed as ee, ref as te, watch as P, nextTick as ae, reactive as y, openBlock as c, createElementBlock as f, unref as oe, createCommentVNode as O, createElementVNode as m, createVNode as d, withCtx as p, createBlock as h, normalizeStyle as v, withModifiers as N, Fragment as j, createTextVNode as L, renderList as le } from "vue";
2
+ import { uniqueId as H } from "../../../utilities/helpers.js";
3
+ import { sanitizeHtml as ne } from "../../../composables/useSanitize.js";
4
+ import se from "../../templates/sortable-list/sortable-list.vue.js";
5
+ /* empty css */
6
+ import A from "../../molecules/file-upload/file-upload.vue.js";
7
+ /* empty css */
8
+ import R from "../../molecules/image-upload/image-upload.vue.js";
9
+ /* empty css */
10
+ import I from "../../molecules/input-dropdown/input-dropdown.vue.js";
11
+ /* empty css */
12
+ import r from "../../atoms/svg-icon/svg-icon.vue.js";
13
+ /* empty css */
14
+ import C from "../../templates/popover-dialog/popover-dialog.vue.js";
15
+ /* empty css */
16
+ const ie = { class: "preset-uploader" }, me = ["innerHTML"], de = { class: "preset-uploader__list" }, ce = ["src"], ue = ["onClick"], pe = ["popovertarget"], re = { class: "preset-uploader__popover p-2 d-flex flex-column gap-2" }, be = {
17
+ role: "button",
18
+ class: "btn btn-sm w-100 d-inline-flex align-items-center"
19
+ }, fe = {
20
+ role: "button",
21
+ class: "btn btn-sm w-100 d-inline-flex align-items-center"
22
+ }, he = {
23
+ key: 1,
24
+ class: "preset-group border border-2 rounded d-flex gap-1 p-1"
25
+ }, ye = ["src"], ge = ["onClick"], ve = ["popovertarget"], Ve = { class: "preset-uploader__popover p-2" }, $e = {
26
+ role: "button",
27
+ class: "btn img-thumbnail d-flex justify-content-center align-items-center"
28
+ }, ke = {
29
+ role: "button",
30
+ class: "btn img-thumbnail d-flex justify-content-center align-items-center"
31
+ }, we = { class: "preset-uploader__popover p-2" }, Te = ["onClick"], Ue = {
32
+ role: "button",
33
+ class: "img-thumbnail d-flex justify-content-center align-items-center"
34
+ }, Se = {
35
+ role: "button",
36
+ class: "img-thumbnail d-flex justify-content-center align-items-center"
37
+ }, He = /* @__PURE__ */ _({
38
+ __name: "preset-uploader",
39
+ props: {
40
+ modelValue: {
41
+ type: Array,
42
+ default: () => []
43
+ },
44
+ name: {
45
+ type: String,
46
+ default: () => H()
47
+ },
48
+ id: {
49
+ type: String,
50
+ default: () => H()
51
+ },
52
+ type: {
53
+ type: String,
54
+ default: ""
55
+ },
56
+ label: {
57
+ type: String,
58
+ default: ""
59
+ },
60
+ variant: {
61
+ type: String,
62
+ default: ""
63
+ },
64
+ disabled: {
65
+ type: Boolean,
66
+ default: !1
67
+ },
68
+ required: {
69
+ type: Boolean,
70
+ default: !1
71
+ },
72
+ accept: {
73
+ type: String
74
+ },
75
+ maxFileSize: {
76
+ type: Number,
77
+ default: 0
78
+ },
79
+ endpoint: {
80
+ type: String,
81
+ default: ""
82
+ },
83
+ authToken: {
84
+ type: String,
85
+ default: ""
86
+ },
87
+ customFetch: null,
88
+ mediaTypeMap: {
89
+ type: Object,
90
+ default: () => ({
91
+ svg: "Svg",
92
+ png: "Image",
93
+ jpg: "Image",
94
+ jpeg: "Image",
95
+ webp: "Image",
96
+ mp4: "Video",
97
+ webm: "Video"
98
+ })
99
+ },
100
+ baseResponsePath: {
101
+ type: String,
102
+ default: "/api/v1/assets"
103
+ },
104
+ previewWidth: {
105
+ type: Number,
106
+ default: 0
107
+ },
108
+ useImageUpload: {
109
+ type: Boolean,
110
+ default: !1
111
+ },
112
+ maxImageWidth: {
113
+ type: Number,
114
+ default: 0
115
+ },
116
+ aspectRatio: Number,
117
+ showTypeDropdown: {
118
+ type: Boolean,
119
+ default: !1
120
+ },
121
+ typeOptions: {
122
+ type: Array,
123
+ default: () => ["background", "overlay", "object"]
124
+ }
125
+ },
126
+ emits: ["update:modelValue"],
127
+ setup(e, { emit: q }) {
128
+ const i = e, b = q;
129
+ function E(t) {
130
+ return t?.type === "preset";
131
+ }
132
+ function T(t) {
133
+ if (t.includes("data:image"))
134
+ return t.includes("data:image/svg") ? "Svg" : "Image";
135
+ const o = t.split(".").pop()?.split("?")[0]?.toLowerCase() ?? "";
136
+ return i.mediaTypeMap[o] ?? "";
137
+ }
138
+ const B = ee({
139
+ get() {
140
+ return i.modelValue;
141
+ },
142
+ set(t) {
143
+ b("update:modelValue", t);
144
+ }
145
+ }), g = te("");
146
+ P(g, async (t, o) => {
147
+ if (t && o !== t) {
148
+ const n = {
149
+ src: t,
150
+ name: `${i.name}-${i.modelValue.length}`,
151
+ mediaType: T(t)
152
+ };
153
+ i.type && (n.type = i.type), b("update:modelValue", [...i.modelValue, n]), await ae(), g.value = "";
154
+ }
155
+ });
156
+ const V = y({}), $ = y({}), U = y({}), k = y({}), S = y({}), w = y({}), M = y({});
157
+ P(S, (t) => {
158
+ for (const [o, n] of Object.entries(t))
159
+ if (!n) {
160
+ const a = Number(o);
161
+ delete V[a], delete $[a];
162
+ }
163
+ }, { deep: !0 }), P(w, (t) => {
164
+ for (const [o, n] of Object.entries(t))
165
+ if (!n) {
166
+ const a = Number(o);
167
+ delete U[a], delete k[a];
168
+ }
169
+ }, { deep: !0 });
170
+ function W(t, o) {
171
+ o && (V[t] = o);
172
+ }
173
+ function D(t, o) {
174
+ o && (U[t] = o, w[t] = !0);
175
+ }
176
+ function z(t) {
177
+ const o = [...i.modelValue];
178
+ o.splice(t, 1), b("update:modelValue", o);
179
+ }
180
+ function K(t, o) {
181
+ b("update:modelValue", i.modelValue.map(
182
+ (n, a) => a === t ? { ...n, type: o } : n
183
+ ));
184
+ }
185
+ function G(t, o, n) {
186
+ const a = i.modelValue[t];
187
+ b("update:modelValue", i.modelValue.map(
188
+ (l, s) => s === t ? { ...l, items: { ...l.items, [o]: { ...a.items[o], type: n } } } : l
189
+ ));
190
+ }
191
+ function J(t, o) {
192
+ $[t] = o, Q(t);
193
+ }
194
+ function Q(t) {
195
+ const o = i.modelValue[t], n = o.type || i.type || "item", a = V[t], l = $[t], s = {
196
+ type: "preset",
197
+ items: {
198
+ [n]: {
199
+ src: o.src,
200
+ thumbnail: o.src,
201
+ type: n,
202
+ mediaType: o.mediaType || T(o.src)
203
+ },
204
+ [l]: {
205
+ src: a,
206
+ thumbnail: a,
207
+ type: l,
208
+ mediaType: T(a)
209
+ }
210
+ }
211
+ };
212
+ delete V[t], delete $[t], S[t] = !1, b("update:modelValue", i.modelValue.map(
213
+ (u, F) => F === t ? s : u
214
+ ));
215
+ }
216
+ function X(t, o) {
217
+ k[t] = o, Y(t);
218
+ }
219
+ function Y(t) {
220
+ const o = U[t], n = k[t], a = i.modelValue[t], l = {
221
+ ...a,
222
+ items: {
223
+ ...a.items,
224
+ [n]: {
225
+ src: o,
226
+ thumbnail: o,
227
+ type: n,
228
+ mediaType: T(o)
229
+ }
230
+ }
231
+ };
232
+ delete U[t], delete k[t], w[t] = !1, b("update:modelValue", i.modelValue.map(
233
+ (s, u) => u === t ? l : s
234
+ ));
235
+ }
236
+ function Z(t, o) {
237
+ const n = i.modelValue[t], a = Object.keys(n.items).filter((l) => l !== o);
238
+ if (a.length <= 1) {
239
+ const l = a[0], s = l ? n.items[l] : null;
240
+ if (s) {
241
+ const u = {
242
+ src: s.src,
243
+ name: `${i.name}-${t}`,
244
+ type: s.type,
245
+ mediaType: s.mediaType
246
+ };
247
+ b("update:modelValue", i.modelValue.map(
248
+ (F, x) => x === t ? u : F
249
+ ));
250
+ } else
251
+ z(t);
252
+ } else {
253
+ const l = { ...n.items };
254
+ delete l[o], b("update:modelValue", i.modelValue.map(
255
+ (s, u) => u === t ? { ...n, items: l } : s
256
+ ));
257
+ }
258
+ }
259
+ return (t, o) => (c(), f("div", ie, [
260
+ e.label ? (c(), f("label", {
261
+ key: 0,
262
+ innerHTML: oe(ne)(e.label)
263
+ }, null, 8, me)) : O("", !0),
264
+ m("div", de, [
265
+ d(se, {
266
+ modelValue: B.value,
267
+ "onUpdate:modelValue": o[2] || (o[2] = (n) => B.value = n),
268
+ vertical: !1,
269
+ class: "mb-3"
270
+ }, {
271
+ "list-item": p(({ item: n, index: a }) => [
272
+ E(n) ? (c(), f("div", he, [
273
+ (c(!0), f(j, null, le(n.items, (l, s) => (c(), f("div", {
274
+ key: s,
275
+ class: "img-container",
276
+ style: v(e.showTypeDropdown ? { anchorName: `--${e.name}-si-${a}-${s}` } : {})
277
+ }, [
278
+ m("img", {
279
+ src: l.thumbnail || l.src,
280
+ class: "img-thumbnail border-0 p-0"
281
+ }, null, 8, ye),
282
+ m("button", {
283
+ onClick: N((u) => Z(a, String(s)), ["prevent"]),
284
+ class: "btn btn--close"
285
+ }, [
286
+ d(r, { symbol: "x" })
287
+ ], 8, ge),
288
+ e.showTypeDropdown ? (c(), f(j, { key: 0 }, [
289
+ m("button", {
290
+ class: "btn btn--action",
291
+ popovertarget: `${e.name}-si-${a}-${s}`
292
+ }, [
293
+ d(r, { symbol: "settings" })
294
+ ], 8, ve),
295
+ d(C, {
296
+ id: `${e.name}-si-${a}-${s}`,
297
+ modelValue: M[`${a}-${s}`],
298
+ "onUpdate:modelValue": (u) => M[`${a}-${s}`] = u,
299
+ class: "preset-uploader__anchor-popover",
300
+ style: v({ positionAnchor: `--${e.name}-si-${a}-${s}` })
301
+ }, {
302
+ default: p(() => [
303
+ m("div", Ve, [
304
+ d(I, {
305
+ name: `${e.name}-si-type-${a}-${s}`,
306
+ options: e.typeOptions,
307
+ "model-value": l.type || null,
308
+ placeholder: "layer type",
309
+ "onUpdate:modelValue": (u) => G(a, String(s), u)
310
+ }, null, 8, ["name", "options", "model-value", "onUpdate:modelValue"])
311
+ ])
312
+ ]),
313
+ _: 2
314
+ }, 1032, ["id", "modelValue", "onUpdate:modelValue", "style"])
315
+ ], 64)) : O("", !0)
316
+ ], 4))), 128)),
317
+ m("div", {
318
+ class: "img-container img-container--add",
319
+ style: v({ anchorName: `--${e.name}-ap-${a}` })
320
+ }, [
321
+ e.useImageUpload ? (c(), h(R, {
322
+ key: 0,
323
+ src: "",
324
+ endpoint: e.endpoint,
325
+ "custom-fetch": e.customFetch,
326
+ "to-data-url": !e.endpoint,
327
+ "auth-token": e.authToken,
328
+ disabled: e.disabled,
329
+ "base-response-path": e.baseResponsePath,
330
+ accept: e.accept,
331
+ "max-file-size": e.maxFileSize,
332
+ "max-image-width": e.maxImageWidth,
333
+ "enable-preview": !1,
334
+ "aspect-ratio": e.aspectRatio,
335
+ "onUpdate:src": (l) => D(a, l)
336
+ }, {
337
+ button: p(() => [
338
+ m("span", $e, [
339
+ d(r, { symbol: "plus" })
340
+ ])
341
+ ]),
342
+ _: 1
343
+ }, 8, ["endpoint", "custom-fetch", "to-data-url", "auth-token", "disabled", "base-response-path", "accept", "max-file-size", "max-image-width", "aspect-ratio", "onUpdate:src"])) : (c(), h(A, {
344
+ key: 1,
345
+ src: "",
346
+ multiple: !1,
347
+ endpoint: e.endpoint,
348
+ "custom-fetch": e.customFetch,
349
+ "to-data-url": !e.endpoint,
350
+ "auth-token": e.authToken,
351
+ disabled: e.disabled,
352
+ "base-response-path": e.baseResponsePath,
353
+ accept: e.accept,
354
+ "max-file-size": e.maxFileSize,
355
+ "onUpdate:src": (l) => D(a, l)
356
+ }, {
357
+ button: p(() => [
358
+ m("span", ke, [
359
+ d(r, { symbol: "plus" })
360
+ ])
361
+ ]),
362
+ _: 1
363
+ }, 8, ["endpoint", "custom-fetch", "to-data-url", "auth-token", "disabled", "base-response-path", "accept", "max-file-size", "onUpdate:src"])),
364
+ d(C, {
365
+ id: `${e.name}-ap-${a}`,
366
+ modelValue: w[a],
367
+ "onUpdate:modelValue": (l) => w[a] = l,
368
+ class: "preset-uploader__anchor-popover",
369
+ style: v({ positionAnchor: `--${e.name}-ap-${a}` })
370
+ }, {
371
+ default: p(() => [
372
+ m("div", we, [
373
+ d(I, {
374
+ name: `${e.name}-add-type-${a}`,
375
+ options: e.typeOptions,
376
+ "model-value": k[a] || null,
377
+ placeholder: "layer type",
378
+ "onUpdate:modelValue": (l) => X(a, l)
379
+ }, null, 8, ["name", "options", "model-value", "onUpdate:modelValue"])
380
+ ])
381
+ ]),
382
+ _: 2
383
+ }, 1032, ["id", "modelValue", "onUpdate:modelValue", "style"])
384
+ ], 4),
385
+ m("button", {
386
+ onClick: N((l) => z(a), ["prevent"]),
387
+ class: "btn btn--close btn--close-preset"
388
+ }, [
389
+ d(r, { symbol: "x" })
390
+ ], 8, Te)
391
+ ])) : (c(), f("div", {
392
+ key: 0,
393
+ class: "img-container",
394
+ style: v({ anchorName: `--${e.name}-pp-${a}` })
395
+ }, [
396
+ m("img", {
397
+ src: n.thumbnail || n.src,
398
+ class: "img-thumbnail"
399
+ }, null, 8, ce),
400
+ m("button", {
401
+ onClick: N((l) => z(a), ["prevent"]),
402
+ class: "btn btn--close"
403
+ }, [
404
+ d(r, { symbol: "x" })
405
+ ], 8, ue),
406
+ m("button", {
407
+ class: "btn btn--action",
408
+ popovertarget: `${e.name}-pp-${a}`
409
+ }, [
410
+ d(r, { symbol: "settings" })
411
+ ], 8, pe),
412
+ d(C, {
413
+ id: `${e.name}-pp-${a}`,
414
+ modelValue: S[a],
415
+ "onUpdate:modelValue": (l) => S[a] = l,
416
+ class: "preset-uploader__anchor-popover",
417
+ style: v({ positionAnchor: `--${e.name}-pp-${a}` })
418
+ }, {
419
+ default: p(() => [
420
+ m("div", re, [
421
+ e.showTypeDropdown ? (c(), h(I, {
422
+ key: 0,
423
+ name: `${e.name}-type-${a}`,
424
+ options: e.typeOptions,
425
+ "model-value": n.type || null,
426
+ placeholder: "item type",
427
+ "onUpdate:modelValue": (l) => K(a, l)
428
+ }, null, 8, ["name", "options", "model-value", "onUpdate:modelValue"])) : O("", !0),
429
+ V[a] ? (c(), h(I, {
430
+ key: 2,
431
+ name: `${e.name}-promote-type-${a}`,
432
+ options: e.typeOptions,
433
+ "model-value": $[a] || null,
434
+ placeholder: "new layer type",
435
+ "onUpdate:modelValue": (l) => J(a, l)
436
+ }, null, 8, ["name", "options", "model-value", "onUpdate:modelValue"])) : (c(), f(j, { key: 1 }, [
437
+ e.useImageUpload ? (c(), h(R, {
438
+ key: 0,
439
+ src: "",
440
+ endpoint: e.endpoint,
441
+ "custom-fetch": e.customFetch,
442
+ "to-data-url": !e.endpoint,
443
+ "auth-token": e.authToken,
444
+ disabled: e.disabled,
445
+ "base-response-path": e.baseResponsePath,
446
+ accept: e.accept,
447
+ "max-file-size": e.maxFileSize,
448
+ "max-image-width": e.maxImageWidth,
449
+ "enable-preview": !1,
450
+ "aspect-ratio": e.aspectRatio,
451
+ "onUpdate:src": (l) => W(a, l)
452
+ }, {
453
+ button: p(() => [
454
+ m("span", be, [
455
+ d(r, { symbol: "plus" }),
456
+ o[3] || (o[3] = L(" Add layer", -1))
457
+ ])
458
+ ]),
459
+ _: 1
460
+ }, 8, ["endpoint", "custom-fetch", "to-data-url", "auth-token", "disabled", "base-response-path", "accept", "max-file-size", "max-image-width", "aspect-ratio", "onUpdate:src"])) : (c(), h(A, {
461
+ key: 1,
462
+ src: "",
463
+ multiple: !1,
464
+ endpoint: e.endpoint,
465
+ "custom-fetch": e.customFetch,
466
+ "to-data-url": !e.endpoint,
467
+ "auth-token": e.authToken,
468
+ disabled: e.disabled,
469
+ "base-response-path": e.baseResponsePath,
470
+ accept: e.accept,
471
+ "max-file-size": e.maxFileSize,
472
+ "onUpdate:src": (l) => W(a, l)
473
+ }, {
474
+ button: p(() => [
475
+ m("span", fe, [
476
+ d(r, { symbol: "plus" }),
477
+ o[4] || (o[4] = L(" Add layer", -1))
478
+ ])
479
+ ]),
480
+ _: 1
481
+ }, 8, ["endpoint", "custom-fetch", "to-data-url", "auth-token", "disabled", "base-response-path", "accept", "max-file-size", "onUpdate:src"]))
482
+ ], 64))
483
+ ])
484
+ ]),
485
+ _: 2
486
+ }, 1032, ["id", "modelValue", "onUpdate:modelValue", "style"])
487
+ ], 4))
488
+ ]),
489
+ "list-append": p(() => [
490
+ e.useImageUpload ? (c(), h(R, {
491
+ key: 0,
492
+ src: g.value,
493
+ "onUpdate:src": o[0] || (o[0] = (n) => g.value = n),
494
+ endpoint: e.endpoint,
495
+ "custom-fetch": e.customFetch,
496
+ "to-data-url": !e.endpoint,
497
+ "auth-token": e.authToken,
498
+ disabled: e.disabled,
499
+ "base-response-path": e.baseResponsePath,
500
+ accept: e.accept,
501
+ "max-file-size": e.maxFileSize,
502
+ "max-image-width": e.maxImageWidth,
503
+ "enable-preview": !1,
504
+ "aspect-ratio": e.aspectRatio
505
+ }, {
506
+ button: p(() => [
507
+ m("span", Ue, [
508
+ d(r, { symbol: "plus" })
509
+ ])
510
+ ]),
511
+ _: 1
512
+ }, 8, ["src", "endpoint", "custom-fetch", "to-data-url", "auth-token", "disabled", "base-response-path", "accept", "max-file-size", "max-image-width", "aspect-ratio"])) : (c(), h(A, {
513
+ key: 1,
514
+ src: g.value,
515
+ "onUpdate:src": o[1] || (o[1] = (n) => g.value = n),
516
+ multiple: !1,
517
+ endpoint: e.endpoint,
518
+ "custom-fetch": e.customFetch,
519
+ "to-data-url": !e.endpoint,
520
+ "auth-token": e.authToken,
521
+ disabled: e.disabled,
522
+ "base-response-path": e.baseResponsePath,
523
+ accept: e.accept,
524
+ "max-file-size": e.maxFileSize
525
+ }, {
526
+ button: p(() => [
527
+ m("span", Se, [
528
+ d(r, { symbol: "plus" })
529
+ ])
530
+ ]),
531
+ _: 1
532
+ }, 8, ["src", "endpoint", "custom-fetch", "to-data-url", "auth-token", "disabled", "base-response-path", "accept", "max-file-size"]))
533
+ ]),
534
+ _: 1
535
+ }, 8, ["modelValue"])
536
+ ])
537
+ ]));
538
+ }
539
+ });
540
+ export {
541
+ He as default
542
+ };
@@ -0,0 +1,5 @@
1
+ import o from "./preset-uploader.vue.js";
2
+ /* empty css */
3
+ export {
4
+ o as default
5
+ };
package/dist/index.d.ts CHANGED
@@ -30,6 +30,7 @@ export { default as LocationList } from './components/molecules/location-list/lo
30
30
  export { default as FileUpload } from './components/molecules/file-upload/file-upload.vue';
31
31
  export { default as UploadGroup } from './components/molecules/upload-group/upload-group.vue';
32
32
  export { default as AssetUploader } from './components/organisms/asset-uploader/asset-uploader.vue';
33
+ export { default as PresetUploader } from './components/organisms/preset-uploader/preset-uploader.vue';
33
34
  export { default as LocationFinder } from './components/organisms/location-finder/location-finder.vue';
34
35
  export { default as BaseCarousel } from './components/templates/base-carousel/base-carousel.vue';
35
36
  export { default as MediaThumbnails } from './components/molecules/media-thumbnails/media-thumbnails.vue';