@feedmepos/mf-media 0.0.9 → 0.0.10-dev.2

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,285 +0,0 @@
1
- import { defineComponent as ve, computed as C, ref as i, onMounted as me, watch as M, resolveComponent as h, openBlock as w, createElementBlock as S, createElementVNode as c, toDisplayString as x, unref as t, createVNode as s, createBlock as fe, createCommentVNode as J, withCtx as N } from "vue";
2
- import { useCoreStore as pe, useI18n as ge } from "@feedmepos/mf-common";
3
- import { useDialog as be } from "@feedmepos/ui-library";
4
- import { k as ye, a as we, $ as xe, b as _e, v as $, P as ke, x as Be, c as Ce, V as he, d as Se, O as Pe, q as Ve, Q as K, _ as De } from "./media-picker-e86c4195.js";
5
- const Ie = { class: "p-24 relative min-h-full" }, ze = { class: "flex items-center justify-between mb-16" }, Ae = { class: "fm-typo-en-title-md-600 fm-step-title line-clamp-2" }, Te = { class: "flex gap-8" }, Fe = { class: "flex flex-col gap-12 mb-16" }, Re = { class: "flex items-center gap-12" }, Oe = { class: "flex-1 text-xs text-fm-color-typo-secondary" }, Ue = {
6
- key: 0,
7
- class: "text-fm-color-typo-primary font-semibold"
8
- }, Me = { key: 1 }, Ne = {
9
- key: 0,
10
- class: "fixed bottom-24 left-1/2 -translate-x-1/2 flex items-center gap-12 bg-white border rounded-lg shadow-lg px-16 py-8 z-30"
11
- }, $e = { class: "text-sm font-semibold" }, je = { class: "flex justify-end gap-8 w-full" }, He = /* @__PURE__ */ ve({
12
- __name: "AssetLibrary",
13
- setup(qe) {
14
- const j = pe(), { t: l } = ge(), r = C(() => {
15
- var e;
16
- return ((e = j.currentBusiness.value) == null ? void 0 : e.id) ?? "";
17
- }), P = C(() => {
18
- var e;
19
- return (e = j.currentRestaurant.value) == null ? void 0 : e._id;
20
- }), _ = be(), V = i(!1);
21
- function W(e) {
22
- console.log("[media-debug] MediaPickerModal selected", e.ratio ?? "original", e.url), m();
23
- }
24
- const k = i(""), g = i([]), p = i([]), b = i([]), D = i(!1), v = i(1), I = i(0), z = i(0), A = i(!1), q = i("recent"), X = {
25
- recent: { sortBy: "createdAt", descending: !0 },
26
- name: { sortBy: "fileName", descending: !1 },
27
- size: { sortBy: "fileSizeBytes", descending: !0 }
28
- }, E = [{ icon: "grid_view" }, { icon: "view_list" }], T = i(E[0]), Y = C(() => T.value.icon === "grid_view" ? "grid" : "list"), F = ye(() => r.value);
29
- async function m() {
30
- if (r.value) {
31
- p.value.length === 0 && (D.value = !0), A.value = !0;
32
- try {
33
- const [e, a] = await Promise.all([
34
- he({
35
- businessId: r.value,
36
- restaurantId: P.value,
37
- search: k.value || void 0,
38
- tags: g.value.length ? g.value : void 0,
39
- // AI-composed images are assets from the moment their bytes land — they have to be, or
40
- // their URL could not render — so the library hides them until "save to the asset
41
- // centre" removes this tag.
42
- excludeTags: [Se],
43
- skip: Pe(v.value, $),
44
- limit: $,
45
- ...X[q.value]
46
- }),
47
- Ve(r.value)
48
- ]);
49
- p.value = e.resources, I.value = e.meta.totalResources, z.value = e.meta.totalPages, b.value = a, await F.load(e.resources.map((o) => o.refId).filter((o) => !!o));
50
- } finally {
51
- D.value = !1, A.value = !1;
52
- }
53
- }
54
- }
55
- async function R() {
56
- v.value = 1, B(), await m();
57
- }
58
- async function O() {
59
- await m();
60
- const e = De(v.value, z.value);
61
- e !== v.value && (v.value = e, await m());
62
- }
63
- async function Z(e) {
64
- e !== v.value && (v.value = e, B(), await m());
65
- }
66
- me(m), M(r, R), M([g, q], R);
67
- let G;
68
- M(k, () => {
69
- clearTimeout(G), G = setTimeout(R, 250);
70
- });
71
- const u = i(/* @__PURE__ */ new Set());
72
- function ee(e) {
73
- const a = new Set(u.value);
74
- a.has(e.id) ? a.delete(e.id) : a.add(e.id), u.value = a;
75
- }
76
- function B() {
77
- u.value = /* @__PURE__ */ new Set();
78
- }
79
- function ae() {
80
- u.value = new Set(p.value.map((e) => e.id));
81
- }
82
- function le() {
83
- const e = u.value.size;
84
- _.open({
85
- title: l("media.library.deleteBulkTitle"),
86
- message: l("media.library.deleteBulkMessage", { count: e, disclaimer: l("media.library.deleteDisclaimer") }),
87
- primaryActions: { text: l("media.library.deleteConfirmButton"), close: !1, variant: "destructive" },
88
- secondaryActions: { text: l("media.library.cancelButton"), close: !0 }
89
- }).onPrimary(async () => {
90
- await Promise.all(
91
- [...u.value].map((a) => {
92
- const o = p.value.find((U) => U.id === a);
93
- return o ? K(r.value, o) : Promise.resolve();
94
- })
95
- ), B(), await O(), _.close();
96
- });
97
- }
98
- function te(e) {
99
- _.open({
100
- title: l("media.library.deleteOneTitle"),
101
- message: l("media.library.deleteOneMessage", { fileName: e.fileName, disclaimer: l("media.library.deleteDisclaimer") }),
102
- primaryActions: { text: l("media.library.deleteConfirmButton"), close: !1, variant: "destructive" },
103
- secondaryActions: { text: l("media.library.cancelButton"), close: !0 }
104
- }).onPrimary(async () => {
105
- await K(r.value, e);
106
- const a = new Set(u.value);
107
- a.delete(e.id), u.value = a, await O(), _.close();
108
- });
109
- }
110
- const d = i(null), ne = C(
111
- () => {
112
- var e;
113
- return (e = d.value) != null && e.refId ? F.byRefId.value.get(d.value.refId) ?? null : null;
114
- }
115
- );
116
- function ie(e) {
117
- d.value = e;
118
- }
119
- async function Q() {
120
- await m(), d.value && (d.value = p.value.find((e) => {
121
- var a;
122
- return e.id === ((a = d.value) == null ? void 0 : a.id);
123
- }) ?? null);
124
- }
125
- async function se() {
126
- d.value = null, await O();
127
- }
128
- const y = i(!1), f = i(null);
129
- function oe() {
130
- var e;
131
- (e = f.value) == null || e.reset(), y.value = !0;
132
- }
133
- async function ue() {
134
- var e;
135
- (e = f.value) != null && e.stagedCount || (y.value = !1), await m();
136
- }
137
- return (e, a) => {
138
- const o = h("FmButton"), U = h("FmSearch"), re = h("FmButtonGroup"), de = h("FmDialog");
139
- return w(), S("div", Ie, [
140
- c("div", ze, [
141
- c("h1", Ae, x(t(l)("media.title")), 1),
142
- c("div", Te, [
143
- s(o, {
144
- label: t(l)("media.library.testPickerButton"),
145
- variant: "tertiary",
146
- onClick: a[0] || (a[0] = (n) => V.value = !0)
147
- }, null, 8, ["label"]),
148
- s(o, {
149
- label: t(l)("media.library.uploadButton"),
150
- "prepend-icon": "add",
151
- variant: "primary",
152
- onClick: oe
153
- }, null, 8, ["label"])
154
- ])
155
- ]),
156
- c("div", Fe, [
157
- s(U, {
158
- modelValue: k.value,
159
- "onUpdate:modelValue": a[1] || (a[1] = (n) => k.value = n),
160
- placeholder: t(l)("media.library.searchPlaceholder"),
161
- class: "max-w-[280px]"
162
- }, null, 8, ["modelValue", "placeholder"]),
163
- b.value.length ? (w(), fe(t(we), {
164
- key: 0,
165
- modelValue: g.value,
166
- "onUpdate:modelValue": a[2] || (a[2] = (n) => g.value = n),
167
- tags: b.value
168
- }, null, 8, ["modelValue", "tags"])) : J("", !0),
169
- c("div", Re, [
170
- c("div", Oe, [
171
- u.value.size > 0 ? (w(), S("span", Ue, x(t(l)("media.library.selectedCount", { count: u.value.size })), 1)) : (w(), S("span", Me, x(t(l)("media.library.totalSummary", { count: I.value })), 1))
172
- ]),
173
- s(o, {
174
- label: t(l)("media.library.selectAllButton"),
175
- variant: "tertiary",
176
- size: "md",
177
- onClick: ae
178
- }, null, 8, ["label"]),
179
- s(re, {
180
- modelValue: T.value,
181
- "onUpdate:modelValue": a[3] || (a[3] = (n) => T.value = n),
182
- items: E
183
- }, null, 8, ["modelValue"])
184
- ])
185
- ]),
186
- s(t(xe), {
187
- assets: p.value,
188
- loading: D.value,
189
- view: Y.value,
190
- selectable: "",
191
- "selected-ids": u.value,
192
- "variants-by-ref-id": t(F).byRefId.value,
193
- onOpen: ie,
194
- onToggle: ee,
195
- onDelete: te
196
- }, null, 8, ["assets", "loading", "view", "selected-ids", "variants-by-ref-id"]),
197
- s(t(_e), {
198
- page: v.value,
199
- "page-size": t($),
200
- "total-resources": I.value,
201
- "total-pages": z.value,
202
- disabled: A.value,
203
- "onUpdate:page": Z
204
- }, null, 8, ["page", "page-size", "total-resources", "total-pages", "disabled"]),
205
- u.value.size > 0 ? (w(), S("div", Ne, [
206
- c("span", $e, x(t(l)("media.library.selectedCount", { count: u.value.size })), 1),
207
- s(o, {
208
- label: t(l)("media.library.cancelButton"),
209
- variant: "tertiary",
210
- size: "md",
211
- onClick: B
212
- }, null, 8, ["label"]),
213
- s(o, {
214
- label: t(l)("media.library.deleteSelectedButton"),
215
- variant: "destructive",
216
- size: "md",
217
- "prepend-icon": "delete",
218
- onClick: le
219
- }, null, 8, ["label"])
220
- ])) : J("", !0),
221
- s(t(ke), {
222
- asset: d.value,
223
- image: ne.value,
224
- "business-id": r.value,
225
- onClose: a[4] || (a[4] = (n) => d.value = null),
226
- onRenamed: Q,
227
- onDeleted: se,
228
- onChanged: Q
229
- }, null, 8, ["asset", "image", "business-id"]),
230
- s(t(Be), {
231
- open: V.value,
232
- "onUpdate:open": a[5] || (a[5] = (n) => V.value = n),
233
- "business-id": r.value,
234
- "restaurant-id": P.value,
235
- onSelect: W
236
- }, null, 8, ["open", "business-id", "restaurant-id"]),
237
- s(de, {
238
- modelValue: y.value,
239
- "onUpdate:modelValue": a[9] || (a[9] = (n) => y.value = n),
240
- "max-width": 480
241
- }, {
242
- "dialog-header": N(() => [
243
- c("div", null, x(t(l)("media.library.uploadDialogTitle")), 1)
244
- ]),
245
- "dialog-footer": N(() => {
246
- var n, L;
247
- return [
248
- c("div", je, [
249
- s(o, {
250
- label: t(l)("media.library.cancelButton"),
251
- variant: "tertiary",
252
- onClick: a[7] || (a[7] = (ce) => y.value = !1)
253
- }, null, 8, ["label"]),
254
- s(o, {
255
- label: t(l)("media.library.uploadSubmitButton", { count: ((n = f.value) == null ? void 0 : n.stagedCount) ?? 0 }),
256
- variant: "primary",
257
- disabled: !((L = f.value) != null && L.stagedCount) || f.value.uploading,
258
- onClick: a[8] || (a[8] = (ce) => {
259
- var H;
260
- return (H = f.value) == null ? void 0 : H.upload();
261
- })
262
- }, null, 8, ["label", "disabled"])
263
- ])
264
- ];
265
- }),
266
- default: N(() => [
267
- s(t(Ce), {
268
- ref_key: "uploadPanelRef",
269
- ref: f,
270
- "business-id": r.value,
271
- "restaurant-id": P.value,
272
- "available-tags": b.value,
273
- onTagCreated: a[6] || (a[6] = (n) => b.value.push(n)),
274
- onUploaded: ue
275
- }, null, 8, ["business-id", "restaurant-id", "available-tags"])
276
- ]),
277
- _: 1
278
- }, 8, ["modelValue"])
279
- ]);
280
- };
281
- }
282
- });
283
- export {
284
- He as default
285
- };