@antcde/vue-utils 0.2.14-rc.00a441c → 0.2.14-rc.1d0df62
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/index.js +107 -30
- package/dist/types/formatDate.d.ts +22 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/useAppTourMode.d.ts +26 -0
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,10 +1,64 @@
|
|
|
1
1
|
import { objectOmit as e, objectPick as t, useAsyncState as n, useColorMode as r, useMagicKeys as i, watchDebounced as a, whenever as o } from "@vueuse/core";
|
|
2
2
|
import { computed as s, inject as c, onBeforeUnmount as l, onMounted as u, onUnmounted as d, readonly as f, ref as p, shallowRef as m, watch as h } from "vue";
|
|
3
3
|
import { useI18n as g } from "vue-i18n";
|
|
4
|
-
import {
|
|
5
|
-
import { BehaviorSubject as
|
|
4
|
+
import { clone as _, newCommsClient as v, newCommsHost as y } from "@antcde/connect-ts";
|
|
5
|
+
import { BehaviorSubject as b, Subject as x, concat as S, concatMap as C, debounceTime as w, distinctUntilChanged as T, filter as E, map as D } from "rxjs";
|
|
6
|
+
//#region src/formatDate.ts
|
|
7
|
+
var O = "nl", k = {
|
|
8
|
+
short: {
|
|
9
|
+
day: "2-digit",
|
|
10
|
+
month: "2-digit",
|
|
11
|
+
year: "numeric"
|
|
12
|
+
},
|
|
13
|
+
medium: {
|
|
14
|
+
day: "numeric",
|
|
15
|
+
month: "short",
|
|
16
|
+
year: "numeric"
|
|
17
|
+
},
|
|
18
|
+
long: {
|
|
19
|
+
day: "numeric",
|
|
20
|
+
month: "long",
|
|
21
|
+
year: "numeric"
|
|
22
|
+
},
|
|
23
|
+
monthDay: {
|
|
24
|
+
day: "numeric",
|
|
25
|
+
month: "short"
|
|
26
|
+
},
|
|
27
|
+
shortDateTime: {
|
|
28
|
+
day: "2-digit",
|
|
29
|
+
month: "2-digit",
|
|
30
|
+
year: "numeric",
|
|
31
|
+
hour: "2-digit",
|
|
32
|
+
minute: "2-digit",
|
|
33
|
+
hour12: !1
|
|
34
|
+
},
|
|
35
|
+
mediumDateTime: {
|
|
36
|
+
day: "numeric",
|
|
37
|
+
month: "short",
|
|
38
|
+
year: "numeric",
|
|
39
|
+
hour: "2-digit",
|
|
40
|
+
minute: "2-digit",
|
|
41
|
+
hour12: !1
|
|
42
|
+
}
|
|
43
|
+
}, A = new Set(["short", "shortDateTime"]);
|
|
44
|
+
function j(e) {
|
|
45
|
+
return e instanceof Date ? e : new Date(e);
|
|
46
|
+
}
|
|
47
|
+
function M(e) {
|
|
48
|
+
return `${e.getFullYear()}-${String(e.getMonth() + 1).padStart(2, "0")}-${String(e.getDate()).padStart(2, "0")}`;
|
|
49
|
+
}
|
|
50
|
+
function N(e, t = {}) {
|
|
51
|
+
let { preset: n = "short", locale: r = O, fallback: i = "" } = t;
|
|
52
|
+
if (e == null || e === "") return i;
|
|
53
|
+
let a = j(e);
|
|
54
|
+
if (Number.isNaN(a.getTime())) return i;
|
|
55
|
+
if (n === "iso") return M(a);
|
|
56
|
+
let o = A.has(n) && /^en\b/i.test(r) ? O : r;
|
|
57
|
+
return new Intl.DateTimeFormat(o, k[n]).format(a);
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
6
60
|
//#region src/useAntColorMode.ts
|
|
7
|
-
function
|
|
61
|
+
function P(e, n) {
|
|
8
62
|
let i = r(n), a = s(() => e.context.value.darkMode), o = s(() => {
|
|
9
63
|
switch (a.value) {
|
|
10
64
|
case null: return "auto";
|
|
@@ -30,14 +84,37 @@ function D(e, n) {
|
|
|
30
84
|
}
|
|
31
85
|
//#endregion
|
|
32
86
|
//#region src/useAntI18n.ts
|
|
33
|
-
function
|
|
87
|
+
function F(e, t) {
|
|
34
88
|
let n = g(t);
|
|
35
89
|
return h(() => e.context.value.user?.language, (e) => n.locale.value = e ?? "en", { immediate: !0 }), n;
|
|
36
90
|
}
|
|
37
91
|
//#endregion
|
|
92
|
+
//#region src/useAppTourMode.ts
|
|
93
|
+
var I = p(!1), L = p(null);
|
|
94
|
+
function R() {
|
|
95
|
+
function e(e) {
|
|
96
|
+
h(() => e.value.tourMode, (e) => {
|
|
97
|
+
I.value = !!e, e || (L.value = null);
|
|
98
|
+
}, { immediate: !0 });
|
|
99
|
+
}
|
|
100
|
+
function t(e) {
|
|
101
|
+
I.value && (L.value = e);
|
|
102
|
+
}
|
|
103
|
+
function n() {
|
|
104
|
+
I.value = !1, L.value = null;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
isActive: f(I),
|
|
108
|
+
activeZoneId: f(L),
|
|
109
|
+
connectContext: e,
|
|
110
|
+
setActiveZone: t,
|
|
111
|
+
exit: n
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
38
115
|
//#region src/useCommsClient.ts
|
|
39
|
-
function
|
|
40
|
-
let i = p({}), a =
|
|
116
|
+
function z(t, n, r) {
|
|
117
|
+
let i = p({}), a = v({
|
|
41
118
|
parent: window.parent,
|
|
42
119
|
connect: t,
|
|
43
120
|
manifest: r
|
|
@@ -45,17 +122,17 @@ function k(t, n, r) {
|
|
|
45
122
|
get: () => o.value,
|
|
46
123
|
set: (e) => a.appState.set(e)
|
|
47
124
|
});
|
|
48
|
-
return a.context.subscribe((e) => i.value = e),
|
|
125
|
+
return a.context.subscribe((e) => i.value = e), S(a.appState.get(), a.appState).subscribe((e) => o.value = e), V(a.signal, a, n), l(() => a.unsubscribe()), Object.assign(e(a, [
|
|
49
126
|
"context",
|
|
50
127
|
"toolbar",
|
|
51
128
|
"appState"
|
|
52
129
|
]), {
|
|
53
130
|
context: i,
|
|
54
|
-
toolbar:
|
|
131
|
+
toolbar: B(a),
|
|
55
132
|
appState: c
|
|
56
133
|
});
|
|
57
134
|
}
|
|
58
|
-
function
|
|
135
|
+
function B(e) {
|
|
59
136
|
let t = p(""), n = {
|
|
60
137
|
title: s({
|
|
61
138
|
get: () => e.toolbar.get().title,
|
|
@@ -106,23 +183,23 @@ function A(e) {
|
|
|
106
183
|
}))
|
|
107
184
|
})
|
|
108
185
|
};
|
|
109
|
-
return e.toolbar.pipe(
|
|
186
|
+
return e.toolbar.pipe(D((e) => e.search.input ?? ""), T(), w(300)).forEach((e) => t.value = e), n;
|
|
110
187
|
}
|
|
111
|
-
function
|
|
112
|
-
let r = i(), a = r.ctrl ?? s(() => !1), c = r.shift ?? s(() => !1), l = new
|
|
188
|
+
function V(e, t, n) {
|
|
189
|
+
let r = i(), a = r.ctrl ?? s(() => !1), c = r.shift ?? s(() => !1), l = new x(), u = l.pipe(C(n ?? ((e) => Promise.resolve(e))), C((t) => e(t))).subscribe();
|
|
113
190
|
return t.add(u), u.add(o(a, () => l.next({ hotkeys: { ctrl: !0 } }))), u.add(o(c, () => l.next({ hotkeys: { shift: !0 } }))), u;
|
|
114
191
|
}
|
|
115
192
|
//#endregion
|
|
116
193
|
//#region src/useCommsHost.ts
|
|
117
|
-
function
|
|
118
|
-
let { context: t } = e, n = new
|
|
194
|
+
function H(e) {
|
|
195
|
+
let { context: t } = e, n = new b({}), r = (e) => n.next(e(n.value)), i = p(), o = new b(void 0), c = h(i, (e) => o.next(e), { immediate: !0 }), l = o.asObservable().pipe(D((e) => e?.contentWindow), E((e) => !!e)), u = y({
|
|
119
196
|
...e,
|
|
120
197
|
contextChanges: n,
|
|
121
198
|
windowChanges: l
|
|
122
199
|
});
|
|
123
200
|
Object.entries(t).map(([e, t]) => h(t, (t) => r((n) => ({
|
|
124
201
|
...n,
|
|
125
|
-
[e]: t
|
|
202
|
+
[e]: _(t)
|
|
126
203
|
})), { immediate: !0 })).forEach((e) => u.scope.add(e)), u.toolbar.subscribe((t) => {
|
|
127
204
|
let n = e.toolbar;
|
|
128
205
|
n.title.value = t.title, n.subtitle.value = t.subtitle, n.searchEnabled.value = t.search?.enabled ?? !1, n.search.value = t.search?.input, n.menu.value = t.menu, n.isLoading.value = t?.isLoading ?? !1;
|
|
@@ -139,23 +216,23 @@ function M(e) {
|
|
|
139
216
|
u.appState.changes.subscribe((e) => f.value = e);
|
|
140
217
|
let g = p(!1);
|
|
141
218
|
u.isConnectionInitialized.subscribe((e) => g.value = e);
|
|
142
|
-
let
|
|
143
|
-
u.manifest?.subscribe((e) =>
|
|
144
|
-
let { unsubscribe:
|
|
219
|
+
let v = p(null);
|
|
220
|
+
u.manifest?.subscribe((e) => v.value = e);
|
|
221
|
+
let { unsubscribe: x, signal: S, closed: C } = u;
|
|
145
222
|
return {
|
|
146
223
|
...e,
|
|
147
224
|
client: i,
|
|
148
225
|
appState: m,
|
|
149
226
|
isConnectionInitialized: g,
|
|
150
|
-
manifest:
|
|
151
|
-
unsubscribe:
|
|
152
|
-
signal:
|
|
153
|
-
closed:
|
|
227
|
+
manifest: v,
|
|
228
|
+
unsubscribe: x,
|
|
229
|
+
signal: S,
|
|
230
|
+
closed: C
|
|
154
231
|
};
|
|
155
232
|
}
|
|
156
233
|
//#endregion
|
|
157
234
|
//#region src/usePermissions.ts
|
|
158
|
-
function
|
|
235
|
+
function U(e) {
|
|
159
236
|
let t = s(() => e.value?.user), n = s(() => e.value?.license), r = s(() => e.value?.project), i = s(() => !!t.value?.is_admin), a = s(() => !!n.value?.user_is_admin), o = s(() => !!r.value?.user_is_admin || a.value);
|
|
160
237
|
function c(e) {
|
|
161
238
|
return !t.value || !n.value ? !1 : i.value || a.value ? !0 : (n.value.user_roles ?? []).some((t) => t.name === e);
|
|
@@ -181,7 +258,7 @@ function N(e) {
|
|
|
181
258
|
}
|
|
182
259
|
//#endregion
|
|
183
260
|
//#region src/useTemplateVersioning.ts
|
|
184
|
-
function
|
|
261
|
+
function W(e) {
|
|
185
262
|
let t = m(null), n = m(null), r = m(null), i = m(null), a = m([]), o = m(null), c = p(!1), l = p(!1), u = p(!1), d = p(!1), f = p(!1), h = p(!1), g = s(() => t.value?.has_update ?? !1), _ = s(() => t.value?.current_version ?? null), v = s(() => t.value?.latest_version ?? null), y = s(() => n.value ? n.value.added.length + n.value.removed.length + n.value.modified.length + n.value.relations_added.length + n.value.relations_removed.length : 0);
|
|
186
263
|
async function b(n) {
|
|
187
264
|
c.value = !0;
|
|
@@ -321,18 +398,18 @@ function P(e) {
|
|
|
321
398
|
}
|
|
322
399
|
//#endregion
|
|
323
400
|
//#region src/utils.ts
|
|
324
|
-
function
|
|
325
|
-
let [t, n] =
|
|
401
|
+
function G(e = "comms") {
|
|
402
|
+
let [t, n] = K(e, () => z(), (e) => e.unsubscribe());
|
|
326
403
|
return {
|
|
327
404
|
provideComms: t,
|
|
328
405
|
injectComms: n
|
|
329
406
|
};
|
|
330
407
|
}
|
|
331
|
-
function
|
|
408
|
+
function K(e, t, n) {
|
|
332
409
|
let r, i = () => (!r && (r = t()), r);
|
|
333
410
|
return [(t) => (t.onUnmount(() => n && r && n(r)), t.provide(e, i)), () => c(e)()];
|
|
334
411
|
}
|
|
335
|
-
function
|
|
412
|
+
function q(t, r, i) {
|
|
336
413
|
let a = n(t, r, {
|
|
337
414
|
immediate: !1,
|
|
338
415
|
...i
|
|
@@ -342,9 +419,9 @@ function L(t, r, i) {
|
|
|
342
419
|
executeDelayed: a.execute
|
|
343
420
|
});
|
|
344
421
|
}
|
|
345
|
-
function
|
|
422
|
+
function J(e) {
|
|
346
423
|
let t, n = p(void 0);
|
|
347
424
|
return u(() => t = e.signal.receive((e) => n.value = e)), d(() => t?.()), [f(n), () => t?.()];
|
|
348
425
|
}
|
|
349
426
|
//#endregion
|
|
350
|
-
export {
|
|
427
|
+
export { N as formatDate, P as useAntColorMode, F as useAntI18n, q as useApi, R as useAppTourMode, z as useCommsClient, H as useCommsHost, G as useCommsInjection, U as usePermissions, J as useSignal, K as useSingleton, W as useTemplateVersioning };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type DateFormatPreset = 'short' | 'medium' | 'long' | 'monthDay' | 'shortDateTime' | 'mediumDateTime' | 'iso';
|
|
2
|
+
export interface FormatDateOptions {
|
|
3
|
+
/** Display preset. Default: 'short' (DD-MM-YYYY numeric). */
|
|
4
|
+
preset?: DateFormatPreset;
|
|
5
|
+
/** BCP-47 locale tag. Default: 'nl' (Dutch DD-MM-YYYY notation). */
|
|
6
|
+
locale?: string;
|
|
7
|
+
/** Returned when value is null/undefined/empty/invalid. Default: ''. */
|
|
8
|
+
fallback?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Format a date for display across the ANT environment.
|
|
12
|
+
*
|
|
13
|
+
* Default is the Dutch DD-MM-YYYY notation. German callers get DD.MM.YYYY
|
|
14
|
+
* via native Intl. English (`en`, `en-US`, `en-GB`, ...) is intentionally
|
|
15
|
+
* mapped to the Dutch numeric pattern for the `short`/`shortDateTime`
|
|
16
|
+
* presets to keep the project-wide DD-MM-YYYY default even when the host
|
|
17
|
+
* runs in English.
|
|
18
|
+
*
|
|
19
|
+
* Storage stays ISO everywhere — use the `iso` preset only for payload
|
|
20
|
+
* serialisation, never for display.
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatDate(value: Date | string | number | null | undefined, options?: FormatDateOptions): string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
export { type DateFormatPreset, formatDate, type FormatDateOptions } from './formatDate';
|
|
1
2
|
export { useAntColorMode, type UseAntColorModeOptions, type UseAntColorModeReturn } from './useAntColorMode';
|
|
2
3
|
export { useAntI18n, type UseAntI18nReturn } from './useAntI18n';
|
|
4
|
+
export { useAppTourMode } from './useAppTourMode';
|
|
3
5
|
export { type UseCommsClient, useCommsClient } from './useCommsClient';
|
|
4
6
|
export { type CommsHostArgs, type UseCommsHost, useCommsHost } from './useCommsHost';
|
|
5
7
|
export { type UsePermissions, usePermissions } from './usePermissions';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Iframe-side tour mode — mirrors the OS `useTourMode` API.
|
|
4
|
+
*
|
|
5
|
+
* Call `connectContext(context)` once in App.vue to wire the OS context stream.
|
|
6
|
+
* Then call `useAppTourMode()` anywhere to read state and set the active zone.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // App.vue — one-time wiring
|
|
11
|
+
* const { comms } = injectContext()
|
|
12
|
+
* useAppTourMode().connectContext(comms.context)
|
|
13
|
+
*
|
|
14
|
+
* // Any component
|
|
15
|
+
* const { isActive, activeZoneId, setActiveZone } = useAppTourMode()
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function useAppTourMode(): {
|
|
19
|
+
isActive: Readonly<Ref<boolean, boolean>>;
|
|
20
|
+
activeZoneId: Readonly<Ref<string | null, string | null>>;
|
|
21
|
+
connectContext: (context: Ref<{
|
|
22
|
+
tourMode?: boolean | null;
|
|
23
|
+
}>) => void;
|
|
24
|
+
setActiveZone: (id: string | null) => void;
|
|
25
|
+
exit: () => void;
|
|
26
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antcde/vue-utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.14-rc.
|
|
4
|
+
"version": "0.2.14-rc.1d0df62",
|
|
5
5
|
"description": "Helper to use ANT Comms in Vue 3",
|
|
6
6
|
"author": "CollaborAll",
|
|
7
7
|
"exports": {
|
|
@@ -31,16 +31,16 @@
|
|
|
31
31
|
"vue-i18n": "^11.1.12"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@antcde/connect-ts": "0.4.18-rc.
|
|
34
|
+
"@antcde/connect-ts": "0.4.18-rc.1d0df62"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@tsconfig/node22": "^22.0.5",
|
|
38
|
-
"@types/node": "^22.19.
|
|
38
|
+
"@types/node": "^22.19.21",
|
|
39
39
|
"@vitejs/plugin-vue": "^6.0.7",
|
|
40
40
|
"@vue/tsconfig": "^0.9.1",
|
|
41
41
|
"typescript": "~6.0.3",
|
|
42
|
-
"vite": "^8.0.
|
|
42
|
+
"vite": "^8.0.16",
|
|
43
43
|
"vite-plugin-dts": "^4.5.4",
|
|
44
|
-
"vue-tsc": "^3.3.
|
|
44
|
+
"vue-tsc": "^3.3.5"
|
|
45
45
|
}
|
|
46
46
|
}
|