@antcde/vue-utils 0.2.14-rc.6346d95 → 0.2.14-rc.6a3e1ae

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 CHANGED
@@ -3,8 +3,62 @@ import { computed as s, inject as c, onBeforeUnmount as l, onMounted as u, onUnm
3
3
  import { useI18n as g } from "vue-i18n";
4
4
  import { newCommsClient as _, newCommsHost as v } from "@antcde/connect-ts";
5
5
  import { BehaviorSubject as y, Subject as b, concat as x, concatMap as S, debounceTime as C, distinctUntilChanged as w, filter as T, map as E } from "rxjs";
6
+ //#region src/formatDate.ts
7
+ var D = "nl", O = {
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
+ }, k = new Set(["short", "shortDateTime"]);
44
+ function A(e) {
45
+ return e instanceof Date ? e : new Date(e);
46
+ }
47
+ function j(e) {
48
+ return `${e.getFullYear()}-${String(e.getMonth() + 1).padStart(2, "0")}-${String(e.getDate()).padStart(2, "0")}`;
49
+ }
50
+ function M(e, t = {}) {
51
+ let { preset: n = "short", locale: r = D, fallback: i = "" } = t;
52
+ if (e == null || e === "") return i;
53
+ let a = A(e);
54
+ if (Number.isNaN(a.getTime())) return i;
55
+ if (n === "iso") return j(a);
56
+ let o = k.has(n) && /^en\b/i.test(r) ? D : r;
57
+ return new Intl.DateTimeFormat(o, O[n]).format(a);
58
+ }
59
+ //#endregion
6
60
  //#region src/useAntColorMode.ts
7
- function D(e, n) {
61
+ function N(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,13 +84,36 @@ function D(e, n) {
30
84
  }
31
85
  //#endregion
32
86
  //#region src/useAntI18n.ts
33
- function O(e, t) {
87
+ function P(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 F = p(!1), I = p(null);
94
+ function L() {
95
+ function e(e) {
96
+ h(() => e.value.tourMode, (e) => {
97
+ F.value = !!e, e || (I.value = null);
98
+ }, { immediate: !0 });
99
+ }
100
+ function t(e) {
101
+ F.value && (I.value = e);
102
+ }
103
+ function n() {
104
+ F.value = !1, I.value = null;
105
+ }
106
+ return {
107
+ isActive: f(F),
108
+ activeZoneId: f(I),
109
+ connectContext: e,
110
+ setActiveZone: t,
111
+ exit: n
112
+ };
113
+ }
114
+ //#endregion
38
115
  //#region src/useCommsClient.ts
39
- function k(t, n, r) {
116
+ function R(t, n, r) {
40
117
  let i = p({}), a = _({
41
118
  parent: window.parent,
42
119
  connect: t,
@@ -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), x(a.appState.get(), a.appState).subscribe((e) => o.value = e), j(a.signal, a, n), l(() => a.unsubscribe()), Object.assign(e(a, [
125
+ return a.context.subscribe((e) => i.value = e), x(a.appState.get(), a.appState).subscribe((e) => o.value = e), B(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: A(a),
131
+ toolbar: z(a),
55
132
  appState: c
56
133
  });
57
134
  }
58
- function A(e) {
135
+ function z(e) {
59
136
  let t = p(""), n = {
60
137
  title: s({
61
138
  get: () => e.toolbar.get().title,
@@ -108,13 +185,13 @@ function A(e) {
108
185
  };
109
186
  return e.toolbar.pipe(E((e) => e.search.input ?? ""), w(), C(300)).forEach((e) => t.value = e), n;
110
187
  }
111
- function j(e, t, n) {
188
+ function B(e, t, n) {
112
189
  let r = i(), a = r.ctrl ?? s(() => !1), c = r.shift ?? s(() => !1), l = new b(), u = l.pipe(S(n ?? ((e) => Promise.resolve(e))), S((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 M(e) {
194
+ function V(e) {
118
195
  let { context: t } = e, n = new y({}), r = (e) => n.next(e(n.value)), i = p(), o = new y(void 0), c = h(i, (e) => o.next(e), { immediate: !0 }), l = o.asObservable().pipe(E((e) => e?.contentWindow), T((e) => !!e)), u = v({
119
196
  ...e,
120
197
  contextChanges: n,
@@ -155,7 +232,7 @@ function M(e) {
155
232
  }
156
233
  //#endregion
157
234
  //#region src/usePermissions.ts
158
- function N(e) {
235
+ function H(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 P(e) {
261
+ function U(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 F(e = "comms") {
325
- let [t, n] = I(e, () => k(), (e) => e.unsubscribe());
401
+ function W(e = "comms") {
402
+ let [t, n] = G(e, () => R(), (e) => e.unsubscribe());
326
403
  return {
327
404
  provideComms: t,
328
405
  injectComms: n
329
406
  };
330
407
  }
331
- function I(e, t, n) {
408
+ function G(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 L(t, r, i) {
412
+ function K(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 R(e) {
422
+ function q(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 { D as useAntColorMode, O as useAntI18n, L as useApi, k as useCommsClient, M as useCommsHost, F as useCommsInjection, N as usePermissions, R as useSignal, I as useSingleton, P as useTemplateVersioning };
427
+ export { M as formatDate, N as useAntColorMode, P as useAntI18n, K as useApi, L as useAppTourMode, R as useCommsClient, V as useCommsHost, W as useCommsInjection, H as usePermissions, q as useSignal, G as useSingleton, U 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;
@@ -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.6346d95",
4
+ "version": "0.2.14-rc.6a3e1ae",
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.6346d95"
34
+ "@antcde/connect-ts": "0.4.18-rc.6a3e1ae"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@tsconfig/node22": "^22.0.5",
38
- "@types/node": "^22.19.20",
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
42
  "vite": "^8.0.16",
43
43
  "vite-plugin-dts": "^4.5.4",
44
- "vue-tsc": "^3.3.4"
44
+ "vue-tsc": "^3.3.5"
45
45
  }
46
46
  }