@choosemycompany/lib 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/dist/analytics/useGtagConversion.d.ts +36 -0
- package/dist/analytics/useHubspotContactUrl.d.ts +25 -0
- package/dist/errors/useErrorHandling.d.ts +36 -0
- package/dist/http/types.d.ts +113 -0
- package/dist/http/useHttp.d.ts +23 -0
- package/dist/i18n/types.d.ts +37 -0
- package/dist/i18n/useCountriesTranslation.d.ts +46 -0
- package/dist/{useLocaleHelpers.d.ts → i18n/useLocaleHelpers.d.ts} +5 -0
- package/dist/i18n/useParseTranslation.d.ts +45 -0
- package/dist/i18n/usePrimaryTypeTranslation.d.ts +34 -0
- package/dist/i18n/useTranslate.d.ts +32 -0
- package/dist/index.d.ts +35 -15
- package/dist/index.js +225 -191
- package/dist/store/types.d.ts +94 -0
- package/dist/store/useStore.d.ts +94 -0
- package/dist/ui/useClickOutside.d.ts +39 -0
- package/dist/ui/useImageCacheWatcherCallback.d.ts +34 -0
- package/dist/ui/useResponsiveSize.d.ts +33 -0
- package/package.json +13 -11
- package/dist/types/errors.d.ts +0 -15
- package/dist/types/index.d.ts +0 -8
- package/dist/types/language.d.ts +0 -2
- package/dist/types/pagination.d.ts +0 -12
- package/dist/types/request.d.ts +0 -7
- package/dist/types/response.d.ts +0 -8
- package/dist/types/routes.d.ts +0 -6
- package/dist/types/store.d.ts +0 -15
- package/dist/types/view.d.ts +0 -12
- package/dist/useClickOutside.d.ts +0 -2
- package/dist/useCountriesTranslation.d.ts +0 -6
- package/dist/useErrorHandling.d.ts +0 -5
- package/dist/useGtagConversion.d.ts +0 -8
- package/dist/useHttp.d.ts +0 -6
- package/dist/useHubspotContactUrl.d.ts +0 -3
- package/dist/useImageCacheWatcherCallback.d.ts +0 -2
- package/dist/useParseTranslation.d.ts +0 -6
- package/dist/usePrimaryTypeTranslation.d.ts +0 -3
- package/dist/useResponsiveSize.d.ts +0 -4
- package/dist/useStore.d.ts +0 -20
- package/dist/useTranslate.d.ts +0 -4
- package/dist/useUrlHelpers.d.ts +0 -8
package/dist/index.js
CHANGED
|
@@ -1,113 +1,175 @@
|
|
|
1
|
-
import { mande as
|
|
2
|
-
import { useRuntimeConfig as
|
|
3
|
-
import { ref as
|
|
4
|
-
import { useI18n as
|
|
5
|
-
import { createError as
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function N() {
|
|
10
|
-
return A || (A = S().public.cmcApiUrl, A);
|
|
1
|
+
import { mande as H } from "mande";
|
|
2
|
+
import { useRuntimeConfig as G, showError as F, useState as O } from "nuxt/app";
|
|
3
|
+
import { ref as A, onMounted as z, onBeforeUnmount as q, computed as N, onUnmounted as Z } from "vue";
|
|
4
|
+
import { useI18n as M } from "vue-i18n";
|
|
5
|
+
import { createError as x } from "h3";
|
|
6
|
+
let w;
|
|
7
|
+
function V() {
|
|
8
|
+
return w || (w = G().public.cmcApiUrl, w);
|
|
11
9
|
}
|
|
12
|
-
function
|
|
13
|
-
const a =
|
|
10
|
+
function na() {
|
|
11
|
+
const a = V(), n = H(a, {
|
|
14
12
|
headers: {}
|
|
15
13
|
});
|
|
16
|
-
function t(
|
|
17
|
-
|
|
18
|
-
...
|
|
19
|
-
Authorization: `Bearer ${
|
|
14
|
+
function t(e) {
|
|
15
|
+
n.options.headers = {
|
|
16
|
+
...n.options.headers ?? {},
|
|
17
|
+
Authorization: `Bearer ${e}`
|
|
20
18
|
};
|
|
21
19
|
}
|
|
22
20
|
function i() {
|
|
23
|
-
|
|
21
|
+
n.options.headers && delete n.options.headers.Authorization;
|
|
24
22
|
}
|
|
25
|
-
return { http:
|
|
23
|
+
return { http: n, setToken: t, clearToken: i };
|
|
26
24
|
}
|
|
27
|
-
function
|
|
28
|
-
return Object.entries(a).sort(([
|
|
25
|
+
function P(a) {
|
|
26
|
+
return Object.entries(a).sort(([n], [t]) => n.localeCompare(t)).map(([n, t]) => `${n}=${t}`).join("|");
|
|
29
27
|
}
|
|
30
|
-
function
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
function ia(a) {
|
|
29
|
+
const n = A({}), t = A({}), i = A({}), e = A({}), o = A(""), d = A([]), l = a.getItemId ?? ((r) => {
|
|
30
|
+
const u = r.id;
|
|
31
|
+
if (u === void 0)
|
|
32
|
+
throw new Error(
|
|
33
|
+
"useStore: no `getItemId` option provided and item has no `id` property. Either pass `getItemId` in the store options, or expose an `id` field on your items."
|
|
34
|
+
);
|
|
35
|
+
return u;
|
|
36
|
+
});
|
|
37
|
+
function f(r) {
|
|
38
|
+
return !!e.value[r];
|
|
34
39
|
}
|
|
35
|
-
async function
|
|
36
|
-
|
|
37
|
-
if (e.value[u] && !b)
|
|
38
|
-
return e.value[u];
|
|
39
|
-
if (!a.fetchOne || s(u))
|
|
40
|
-
return e.value[u] ?? void 0;
|
|
41
|
-
n.value[u] = !0;
|
|
40
|
+
async function p(r, u) {
|
|
41
|
+
e.value[r] = u;
|
|
42
42
|
try {
|
|
43
|
-
const
|
|
44
|
-
return
|
|
45
|
-
} catch (
|
|
46
|
-
i.value
|
|
47
|
-
return;
|
|
43
|
+
const s = await u;
|
|
44
|
+
return delete i.value[r], s;
|
|
45
|
+
} catch (s) {
|
|
46
|
+
throw i.value[r] = s, s;
|
|
48
47
|
} finally {
|
|
49
|
-
|
|
48
|
+
delete e.value[r];
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
|
-
async function
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
async function b(r, u = {}) {
|
|
52
|
+
if (!a.fetchOne)
|
|
53
|
+
throw new Error("useStore.retrieve called but fetchOne is not defined in store options");
|
|
54
|
+
const { force: s = !1 } = u;
|
|
55
|
+
if (n.value[r] && !s)
|
|
56
|
+
return n.value[r];
|
|
57
|
+
const c = e.value[r];
|
|
58
|
+
if (c)
|
|
59
|
+
return c;
|
|
60
|
+
const B = a.fetchOne, k = (async () => {
|
|
56
61
|
try {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
const C = await B(r), h = a.enrichItem ? a.enrichItem(C) : C;
|
|
63
|
+
return n.value[r] = h, delete i.value[r], n.value[r];
|
|
64
|
+
} catch (C) {
|
|
65
|
+
i.value[r] = C;
|
|
66
|
+
return;
|
|
67
|
+
} finally {
|
|
68
|
+
delete e.value[r];
|
|
69
|
+
}
|
|
70
|
+
})();
|
|
71
|
+
return e.value[r] = k, k;
|
|
72
|
+
}
|
|
73
|
+
function g(r) {
|
|
74
|
+
const u = P(r), s = t.value[u];
|
|
75
|
+
if (s)
|
|
76
|
+
return {
|
|
77
|
+
items: s.itemIds.map((c) => n.value[c]).filter((c) => c !== void 0),
|
|
78
|
+
total: s.total,
|
|
79
|
+
hasMore: s.hasMore,
|
|
80
|
+
page: s.page,
|
|
81
|
+
limit: s.limit
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
async function m(r, u = {}) {
|
|
85
|
+
if (!a.fetchPage)
|
|
86
|
+
throw new Error("useStore.list called but fetchPage is not defined in store options");
|
|
87
|
+
const s = P(r), { force: c = !1 } = u;
|
|
88
|
+
if (t.value[s] && !c)
|
|
89
|
+
return g(r);
|
|
90
|
+
const B = e.value[s];
|
|
91
|
+
if (B)
|
|
92
|
+
return await B, g(r);
|
|
93
|
+
const k = a.fetchPage, C = (async () => {
|
|
94
|
+
try {
|
|
95
|
+
const h = await k(r), R = [];
|
|
96
|
+
for (const E of h.items) {
|
|
97
|
+
const y = a.enrichItem ? a.enrichItem(E) : E, T = l(y);
|
|
98
|
+
n.value[T] = y, R.push(T);
|
|
63
99
|
}
|
|
64
|
-
t.value[
|
|
65
|
-
|
|
66
|
-
total:
|
|
67
|
-
hasMore:
|
|
68
|
-
page:
|
|
69
|
-
limit:
|
|
70
|
-
};
|
|
71
|
-
} catch (
|
|
72
|
-
i.value
|
|
100
|
+
t.value[s] = {
|
|
101
|
+
itemIds: R,
|
|
102
|
+
total: h.total,
|
|
103
|
+
hasMore: h.hasMore,
|
|
104
|
+
page: h.page,
|
|
105
|
+
limit: h.limit
|
|
106
|
+
}, delete i.value[s];
|
|
107
|
+
} catch (h) {
|
|
108
|
+
i.value[s] = h;
|
|
73
109
|
} finally {
|
|
74
|
-
|
|
110
|
+
delete e.value[s];
|
|
75
111
|
}
|
|
112
|
+
})();
|
|
113
|
+
return e.value[s] = C, await C, g(r);
|
|
114
|
+
}
|
|
115
|
+
async function v(r) {
|
|
116
|
+
if (!a.createMutation)
|
|
117
|
+
throw new Error("useStore.create called but createMutation is not defined in store options");
|
|
118
|
+
const u = await a.createMutation(r), s = a.enrichItem ? a.enrichItem(u) : u, c = l(s);
|
|
119
|
+
return n.value[c] = s, t.value = {}, s;
|
|
120
|
+
}
|
|
121
|
+
async function I(r, u) {
|
|
122
|
+
if (!a.updateMutation)
|
|
123
|
+
throw new Error("useStore.update called but updateMutation is not defined in store options");
|
|
124
|
+
const s = a.updateMutation, c = await p(r, (async () => s(r, u))()), B = a.enrichItem ? a.enrichItem(c) : c;
|
|
125
|
+
return n.value[r] = B, B;
|
|
126
|
+
}
|
|
127
|
+
async function S(r) {
|
|
128
|
+
if (!a.removeMutation)
|
|
129
|
+
throw new Error("useStore.remove called but removeMutation is not defined in store options");
|
|
130
|
+
const u = a.removeMutation;
|
|
131
|
+
await p(r, (async () => u(r))()), delete n.value[r];
|
|
132
|
+
for (const s of Object.values(t.value)) {
|
|
133
|
+
const c = s.itemIds.indexOf(r);
|
|
134
|
+
c !== -1 && (s.itemIds.splice(c, 1), s.total = Math.max(0, s.total - 1));
|
|
76
135
|
}
|
|
77
136
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
137
|
+
function D() {
|
|
138
|
+
i.value = {};
|
|
139
|
+
}
|
|
140
|
+
function K() {
|
|
141
|
+
n.value = {}, t.value = {}, i.value = {}, e.value = {}, o.value = "", d.value = [];
|
|
80
142
|
}
|
|
81
|
-
return { items:
|
|
143
|
+
return { items: n, views: t, errors: i, search: o, filters: d, isPending: f, list: m, reset: K, retrieve: b, getView: g, track: p, create: v, update: I, remove: S, clearErrors: D };
|
|
82
144
|
}
|
|
83
|
-
function
|
|
145
|
+
function ta(a, n) {
|
|
84
146
|
const t = (i) => {
|
|
85
|
-
const
|
|
86
|
-
!
|
|
147
|
+
const e = a.value, o = i.target;
|
|
148
|
+
!e || !o || e.contains(o) || n();
|
|
87
149
|
};
|
|
88
|
-
|
|
150
|
+
z(() => {
|
|
89
151
|
document.addEventListener("click", t);
|
|
90
|
-
}),
|
|
152
|
+
}), q(() => {
|
|
91
153
|
document.removeEventListener("click", t);
|
|
92
154
|
});
|
|
93
155
|
}
|
|
94
|
-
function
|
|
95
|
-
const { locale: a } =
|
|
96
|
-
function
|
|
97
|
-
const
|
|
98
|
-
if (!
|
|
156
|
+
function ra() {
|
|
157
|
+
const { locale: a } = M();
|
|
158
|
+
function n(t, i = null) {
|
|
159
|
+
const e = J[t.trim().toUpperCase()];
|
|
160
|
+
if (!e)
|
|
99
161
|
throw new Error(`Unknown country code: ${t}`);
|
|
100
|
-
if (i &&
|
|
101
|
-
return
|
|
102
|
-
if (
|
|
103
|
-
return
|
|
104
|
-
if (a.value !== "en" &&
|
|
105
|
-
return
|
|
162
|
+
if (i && e[i])
|
|
163
|
+
return e[i];
|
|
164
|
+
if (e[a.value])
|
|
165
|
+
return e[a.value];
|
|
166
|
+
if (a.value !== "en" && e.en)
|
|
167
|
+
return e.en;
|
|
106
168
|
throw new Error(`Unknown country code: ${t}`);
|
|
107
169
|
}
|
|
108
|
-
return
|
|
170
|
+
return n;
|
|
109
171
|
}
|
|
110
|
-
const
|
|
172
|
+
const J = {
|
|
111
173
|
AD: { en: "Andorra", fr: "Andorre", es: "Andorra", de: "Andorra", it: "Andorra", pt: "Andorra", da: "Andorra" },
|
|
112
174
|
AE: { en: "United Arab Emirates", fr: "Émirats arabes unis", es: "Emiratos Árabes Unidos", de: "Vereinigte Arabische Emirate", it: "Emirati Arabi Uniti", pt: "Emirados Árabes Unidos", da: "De Forenede Arabiske Emirater" },
|
|
113
175
|
AF: { en: "Afghanistan", fr: "Afghanistan", es: "Afganistán", de: "Afghanistan", it: "Afghanistan", pt: "Afeganistão", da: "Afghanistan" },
|
|
@@ -245,188 +307,160 @@ const H = {
|
|
|
245
307
|
ZA: { en: "South Africa", fr: "Afrique Du Sud", es: "Sudáfrica", de: "Südafrika", it: "Sudafrica", pt: "África Do Sul", da: "Sydafrika" },
|
|
246
308
|
ZM: { en: "Zambia", fr: "Zambie", es: "Zambia", de: "Sambia", it: "Zambia", pt: "Zâmbia", da: "Zambia" },
|
|
247
309
|
ZW: { en: "Zimbabwe", fr: "Zimbabwe", es: "Zimbabue", de: "Simbabwe", it: "Zimbabwe", pt: "Zimbábue", da: "Zimbabwe" }
|
|
248
|
-
},
|
|
249
|
-
const i =
|
|
310
|
+
}, oa = ({ code: a, message: n, data: t }) => {
|
|
311
|
+
const i = n || "An unexpected error occurred", e = x({
|
|
250
312
|
statusCode: a,
|
|
251
313
|
statusMessage: i,
|
|
252
314
|
message: i,
|
|
253
315
|
data: t
|
|
254
316
|
});
|
|
255
|
-
throw
|
|
256
|
-
},
|
|
257
|
-
function
|
|
258
|
-
const { gtagId: a } =
|
|
317
|
+
throw F(e), e;
|
|
318
|
+
}, $ = "ilcJCL_lmpwcEJfSkKND";
|
|
319
|
+
function sa() {
|
|
320
|
+
const { gtagId: a } = G().public;
|
|
259
321
|
return { reportConversion: () => {
|
|
260
322
|
if (typeof window > "u" || typeof window.gtag > "u" || !a)
|
|
261
323
|
return;
|
|
262
|
-
const t = `${a}/${
|
|
324
|
+
const t = `${a}/${$}`;
|
|
263
325
|
window.gtag("event", "conversion", {
|
|
264
326
|
send_to: t
|
|
265
327
|
});
|
|
266
328
|
} };
|
|
267
329
|
}
|
|
268
|
-
const
|
|
269
|
-
function
|
|
270
|
-
const { locale: a } =
|
|
271
|
-
return { contactUrl:
|
|
330
|
+
const U = "https://5509641.hs-sites-eu1.com";
|
|
331
|
+
function da() {
|
|
332
|
+
const { locale: a } = M();
|
|
333
|
+
return { contactUrl: N(() => a.value === "fr" ? `${U}/contact` : `${U}/${a.value}/contact`) };
|
|
272
334
|
}
|
|
273
|
-
function
|
|
335
|
+
function ua() {
|
|
274
336
|
async function a(i) {
|
|
275
337
|
await Promise.all(
|
|
276
338
|
i.map(
|
|
277
|
-
(
|
|
278
|
-
if (!
|
|
339
|
+
(e) => new Promise((o) => {
|
|
340
|
+
if (!e) return o(null);
|
|
279
341
|
const d = new Image();
|
|
280
|
-
d.onload = () =>
|
|
342
|
+
d.onload = () => o(null), d.onerror = () => o(null), d.src = e;
|
|
281
343
|
})
|
|
282
344
|
)
|
|
283
345
|
);
|
|
284
346
|
}
|
|
285
|
-
function
|
|
286
|
-
return
|
|
347
|
+
function n(i, e) {
|
|
348
|
+
return e.split(".").reduce((o, d) => o && typeof o == "object" && d in o ? o[d] : "", i) ?? "";
|
|
287
349
|
}
|
|
288
|
-
function t(i,
|
|
350
|
+
function t(i, e, o) {
|
|
289
351
|
if (import.meta.server)
|
|
290
|
-
return async (
|
|
352
|
+
return async (l) => {
|
|
291
353
|
i.value = !0;
|
|
292
354
|
};
|
|
293
|
-
const d =
|
|
294
|
-
`${
|
|
355
|
+
const d = O(
|
|
356
|
+
`${e}LoadedImageCache`,
|
|
295
357
|
() => ({})
|
|
296
358
|
);
|
|
297
|
-
return async (
|
|
298
|
-
if (!
|
|
359
|
+
return async (l) => {
|
|
360
|
+
if (!l) {
|
|
299
361
|
i.value = !1;
|
|
300
362
|
return;
|
|
301
363
|
}
|
|
302
|
-
const
|
|
364
|
+
const f = o.map((g) => n(l, g)), p = `${e}|${f.join("|")}`;
|
|
303
365
|
if (d.value[p]) {
|
|
304
366
|
i.value = !0;
|
|
305
367
|
return;
|
|
306
368
|
}
|
|
307
369
|
i.value = !1;
|
|
308
|
-
const
|
|
309
|
-
await a(
|
|
370
|
+
const b = f.filter(Boolean).map(String);
|
|
371
|
+
await a(b), d.value[p] = !0, i.value = !0;
|
|
310
372
|
};
|
|
311
373
|
}
|
|
312
374
|
return t;
|
|
313
375
|
}
|
|
314
|
-
const
|
|
376
|
+
const j = {
|
|
315
377
|
en: ["US", "UK"]
|
|
316
|
-
},
|
|
317
|
-
function
|
|
318
|
-
const
|
|
378
|
+
}, _ = "FR";
|
|
379
|
+
function W(a) {
|
|
380
|
+
const n = a.trim().replace("_", "-"), [t, i] = n.split("-");
|
|
319
381
|
return {
|
|
320
382
|
language: t?.toLowerCase() ?? "",
|
|
321
383
|
region: i?.toUpperCase() ?? ""
|
|
322
384
|
};
|
|
323
385
|
}
|
|
324
|
-
function
|
|
386
|
+
function L(a) {
|
|
325
387
|
return a.toString().trim().toUpperCase();
|
|
326
388
|
}
|
|
327
|
-
function
|
|
328
|
-
function a(
|
|
389
|
+
function la() {
|
|
390
|
+
function a(n, t) {
|
|
329
391
|
if (!t.length) return;
|
|
330
|
-
const i = t.map(
|
|
331
|
-
d &&
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
for (const p of
|
|
335
|
-
if (
|
|
392
|
+
const i = t.map(L), e = new Set(i), { language: o, region: d } = W(n), l = [];
|
|
393
|
+
d && l.push(d);
|
|
394
|
+
const f = j[o];
|
|
395
|
+
f?.length && l.push(...f.map(L)), o && l.push(o.toUpperCase()), l.push(_);
|
|
396
|
+
for (const p of l)
|
|
397
|
+
if (e.has(p))
|
|
336
398
|
return p;
|
|
337
399
|
return i[0];
|
|
338
400
|
}
|
|
339
401
|
return { getRegionFromLocale: a };
|
|
340
402
|
}
|
|
341
|
-
function
|
|
342
|
-
const { t: a } =
|
|
343
|
-
function
|
|
344
|
-
const
|
|
345
|
-
let
|
|
346
|
-
for (;
|
|
347
|
-
const { index:
|
|
348
|
-
|
|
403
|
+
function ca() {
|
|
404
|
+
const { t: a } = M();
|
|
405
|
+
function n(t, i) {
|
|
406
|
+
const e = a(t), o = [], l = i.map((m) => m.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), f = new RegExp(`\\[(${l})\\]([\\s\\S]*?)\\[\\/\\1\\]`, "g"), p = i.reduce((m, v) => (m[v] = !1, m), {});
|
|
407
|
+
let b = 0, g = f.exec(e);
|
|
408
|
+
for (; g; ) {
|
|
409
|
+
const { index: m, 0: v, 1: I, 2: S } = g;
|
|
410
|
+
m > b && o.push({ text: e.slice(b, m), ...p }), S && I && o.push({ text: S, ...p, [I]: !0 }), b = m + v.length, g = f.exec(e);
|
|
349
411
|
}
|
|
350
|
-
return
|
|
412
|
+
return b < e.length && o.push({ text: e.slice(b), ...p }), o;
|
|
351
413
|
}
|
|
352
|
-
return { parse:
|
|
414
|
+
return { parse: n };
|
|
353
415
|
}
|
|
354
|
-
function
|
|
355
|
-
const { t:
|
|
356
|
-
function
|
|
357
|
-
const
|
|
358
|
-
return t(
|
|
359
|
-
primaryType:
|
|
416
|
+
function pa(a) {
|
|
417
|
+
const { t: n, te: t, tm: i } = M();
|
|
418
|
+
function e(o, d) {
|
|
419
|
+
const l = `${o}.${d}`, f = `${o}.${a[0]}`;
|
|
420
|
+
return t(l) ? n(l) : t(f) ? n(f) : typeof i(o) == "string" ? n(o, {
|
|
421
|
+
primaryType: n(`common.primary-type.${d}`).toLowerCase()
|
|
360
422
|
}) : "";
|
|
361
423
|
}
|
|
362
|
-
return { getPrimaryTypeTranslation:
|
|
424
|
+
return { getPrimaryTypeTranslation: e };
|
|
363
425
|
}
|
|
364
|
-
function
|
|
365
|
-
const i =
|
|
366
|
-
() => i.value >= t ?
|
|
426
|
+
function fa(a, n, t = 768) {
|
|
427
|
+
const i = A(t - 1), e = N(
|
|
428
|
+
() => i.value >= t ? n : a
|
|
367
429
|
);
|
|
368
430
|
if (import.meta.client) {
|
|
369
|
-
const
|
|
431
|
+
const o = () => {
|
|
370
432
|
i.value = window.innerWidth;
|
|
371
433
|
};
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}),
|
|
375
|
-
window.removeEventListener("resize",
|
|
434
|
+
z(() => {
|
|
435
|
+
o(), window.addEventListener("resize", o);
|
|
436
|
+
}), Z(() => {
|
|
437
|
+
window.removeEventListener("resize", o);
|
|
376
438
|
});
|
|
377
439
|
}
|
|
378
|
-
return { size:
|
|
440
|
+
return { size: e, windowWidth: i };
|
|
379
441
|
}
|
|
380
|
-
function
|
|
381
|
-
const { locale: a } =
|
|
382
|
-
function
|
|
442
|
+
function ga() {
|
|
443
|
+
const { locale: a } = M();
|
|
444
|
+
function n(t, i = "fr") {
|
|
383
445
|
if (!t) return "";
|
|
384
|
-
const
|
|
385
|
-
return t[
|
|
386
|
-
}
|
|
387
|
-
return e;
|
|
388
|
-
}
|
|
389
|
-
function la() {
|
|
390
|
-
const a = S(), { locale: e } = C(), t = G(), i = E(), n = a.public.cmcAssetsUrl, r = a.public.cmcCorporateWebsiteUrl, d = a.public.siteUrl;
|
|
391
|
-
function s(o) {
|
|
392
|
-
return `${n}${o}`;
|
|
393
|
-
}
|
|
394
|
-
const l = s("/img/public-site/default-banner.png"), p = s("/img/public-site/default-logo.png");
|
|
395
|
-
function g(o) {
|
|
396
|
-
return o || l;
|
|
397
|
-
}
|
|
398
|
-
function c(o) {
|
|
399
|
-
return o || p;
|
|
400
|
-
}
|
|
401
|
-
function f(o) {
|
|
402
|
-
return `${r}${o}`;
|
|
403
|
-
}
|
|
404
|
-
function u(o) {
|
|
405
|
-
return `${d}/${e.value}/${o}`;
|
|
406
|
-
}
|
|
407
|
-
function b(o = "home") {
|
|
408
|
-
const B = String(t.name || "");
|
|
409
|
-
if (B === o || B.startsWith(`${o}__`) || B.startsWith(`${o}___`))
|
|
410
|
-
return;
|
|
411
|
-
const m = i(o), M = `/${e.value}`, U = !m || m === "/" || m.startsWith("/_") ? M : m;
|
|
412
|
-
return D(U, a.app.baseURL);
|
|
446
|
+
const e = a.value;
|
|
447
|
+
return t[e] ?? t[i] ?? "";
|
|
413
448
|
}
|
|
414
|
-
return
|
|
449
|
+
return n;
|
|
415
450
|
}
|
|
416
451
|
export {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
la as useUrlHelpers
|
|
452
|
+
P as getViewKey,
|
|
453
|
+
oa as showAndThrowError,
|
|
454
|
+
ta as useClickOutside,
|
|
455
|
+
ra as useCountriesTranslation,
|
|
456
|
+
sa as useGtagConversion,
|
|
457
|
+
na as useHttp,
|
|
458
|
+
da as useHubspotContactUrl,
|
|
459
|
+
ua as useImageCacheWatcherCallback,
|
|
460
|
+
la as useLocaleHelpers,
|
|
461
|
+
ca as useParseTranslation,
|
|
462
|
+
pa as usePrimaryTypeTranslation,
|
|
463
|
+
fa as useResponsiveSize,
|
|
464
|
+
ia as useStore,
|
|
465
|
+
ga as useTranslate
|
|
432
466
|
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for {@link useStore}. Kept in their own module so consumers can
|
|
3
|
+
* `import type` without dragging in the runtime composable.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Required shape every paginated query must satisfy. Acts as a constraint on
|
|
7
|
+
* the `Params` generic of {@link useStore} so the store can deterministically
|
|
8
|
+
* key a view from arbitrary user-defined query objects.
|
|
9
|
+
*/
|
|
10
|
+
export type ViewKeyParams = {
|
|
11
|
+
page: number;
|
|
12
|
+
limit: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Resolved view exposed by `list()` and `getView()`. Combines the original
|
|
16
|
+
* `{ page, limit }` query with the materialized items and pagination meta.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam Item - Shape of an individual list item.
|
|
19
|
+
*/
|
|
20
|
+
export type View<Item> = ViewKeyParams & {
|
|
21
|
+
/** Items belonging to this page, in API-returned order. */
|
|
22
|
+
items: Item[];
|
|
23
|
+
/** Total number of items across all pages. */
|
|
24
|
+
total: number;
|
|
25
|
+
/** `true` if more pages exist after the current one. */
|
|
26
|
+
hasMore: boolean;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Reserved for future "infinite scroll vs. paginated" switching. Currently
|
|
30
|
+
* unused by the implementation — declared here to lock the public surface.
|
|
31
|
+
*/
|
|
32
|
+
export type ViewOptions = {
|
|
33
|
+
infinite?: boolean;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Permitted shape for an item identifier. Restricting to `string | number`
|
|
37
|
+
* keeps `Record<Id, Item>` indexing tractable on TypeScript ≥ 5 strict mode.
|
|
38
|
+
*/
|
|
39
|
+
export type IdKey = string | number;
|
|
40
|
+
/**
|
|
41
|
+
* Configuration passed to {@link useStore}. Every field is optional — fetchers
|
|
42
|
+
* and mutations only need to be supplied for the corresponding `retrieve` /
|
|
43
|
+
* `list` / `create` / `update` / `remove` methods to work.
|
|
44
|
+
*
|
|
45
|
+
* @typeParam Id - Item identifier type (string or number).
|
|
46
|
+
* @typeParam Item - Item shape stored in the cache.
|
|
47
|
+
* @typeParam Params - User-defined paginated query shape (must extend {@link ViewKeyParams}).
|
|
48
|
+
* @typeParam CreatePayload - Shape passed to `createMutation` (defaults to `Item`).
|
|
49
|
+
* @typeParam UpdatePatch - Shape passed to `updateMutation` (defaults to `Partial<Item>`).
|
|
50
|
+
*/
|
|
51
|
+
export type StoreOptions<Id extends IdKey, Item, Params extends ViewKeyParams, CreatePayload = Item, UpdatePatch = Partial<Item>> = {
|
|
52
|
+
/** Default query parameters. Held for reference, never read by the store itself. */
|
|
53
|
+
params?: Params;
|
|
54
|
+
/**
|
|
55
|
+
* Computes the cache key for an item. Defaults to `(item) => item.id` and
|
|
56
|
+
* throws if `id` is missing on an item, so always provide this when items
|
|
57
|
+
* use a non-standard identifier (`uuid`, `slug`, composite key, …).
|
|
58
|
+
*/
|
|
59
|
+
getItemId?: (item: Item) => Id;
|
|
60
|
+
/** Fetches a single item by id. Required to call `retrieve()`. */
|
|
61
|
+
fetchOne?: (id: Id) => Promise<Item>;
|
|
62
|
+
/** Fetches one page. Required to call `list()`. */
|
|
63
|
+
fetchPage?: (params: Params) => Promise<View<Item>>;
|
|
64
|
+
/**
|
|
65
|
+
* Transformation applied to every item before it lands in `items`. Also runs
|
|
66
|
+
* on items returned by `createMutation` and `updateMutation`. Identity by default.
|
|
67
|
+
*/
|
|
68
|
+
enrichItem?: (item: Item) => Item;
|
|
69
|
+
/** Persists a new item server-side. Required to call `create()`. */
|
|
70
|
+
createMutation?: (payload: CreatePayload) => Promise<Item>;
|
|
71
|
+
/** Patches an existing item server-side. Required to call `update()`. */
|
|
72
|
+
updateMutation?: (id: Id, patch: UpdatePatch) => Promise<Item>;
|
|
73
|
+
/** Deletes an item server-side. Required to call `remove()`. */
|
|
74
|
+
removeMutation?: (id: Id) => Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Cache time-to-live in milliseconds. Reserved for future use — currently
|
|
77
|
+
* **not implemented**; cached entries live until `reset()` is called.
|
|
78
|
+
*/
|
|
79
|
+
ttlMs?: number;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Options accepted by `retrieve()`.
|
|
83
|
+
*/
|
|
84
|
+
export type RetrieveOptions = {
|
|
85
|
+
/** When `true`, bypass the cache and fetch even if the item is already known. */
|
|
86
|
+
force?: boolean;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Options accepted by `list()`.
|
|
90
|
+
*/
|
|
91
|
+
export type ListOptions = {
|
|
92
|
+
/** When `true`, bypass the cache and fetch even if the view is already known. */
|
|
93
|
+
force?: boolean;
|
|
94
|
+
};
|