@antcde/vue-utils 0.2.21-rc.1 → 0.2.21-rc.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.
package/dist/index.js CHANGED
@@ -56,9 +56,20 @@ function F(e, t = {}) {
56
56
  let o = M.has(n) && /^en\b/i.test(r) ? A : r;
57
57
  return new Intl.DateTimeFormat(o, j[n]).format(a);
58
58
  }
59
+ function I(e, t, n = {}) {
60
+ let { preset: r = "medium", locale: i = A, fallback: a = "" } = n, o = e == null || e === "" ? null : N(e), s = t == null || t === "" ? null : N(t), c = o && !Number.isNaN(o.getTime()) ? o : null, l = s && !Number.isNaN(s.getTime()) ? s : null;
61
+ if (!c && !l) return a;
62
+ if (!c || !l || P(c) === P(l)) return F(c ?? l, {
63
+ preset: r === "iso" ? "medium" : r,
64
+ locale: i,
65
+ fallback: a
66
+ });
67
+ let u = r === "iso" ? "medium" : r;
68
+ return new Intl.DateTimeFormat(i, j[u]).formatRange(c, l);
69
+ }
59
70
  //#endregion
60
71
  //#region src/useAntColorMode.ts
61
- function I(e, n) {
72
+ function L(e, n) {
62
73
  let i = r(n), a = s(() => e.context.value.darkMode), o = s(() => {
63
74
  switch (a.value) {
64
75
  case null: return "auto";
@@ -84,28 +95,28 @@ function I(e, n) {
84
95
  }
85
96
  //#endregion
86
97
  //#region src/useAntI18n.ts
87
- function L(e, t) {
98
+ function R(e, t) {
88
99
  let n = _(t);
89
100
  return g(() => e.context.value.user?.language, (e) => n.locale.value = e ?? "en", { immediate: !0 }), n;
90
101
  }
91
102
  //#endregion
92
103
  //#region src/useAppTourMode.ts
93
- var R = m(!1), z = m(null);
94
- function B() {
104
+ var z = m(!1), B = m(null);
105
+ function V() {
95
106
  function e(e) {
96
107
  g(() => e.value.tourMode, (e) => {
97
- R.value = !!e, e || (z.value = null);
108
+ z.value = !!e, e || (B.value = null);
98
109
  }, { immediate: !0 });
99
110
  }
100
111
  function t(e) {
101
- R.value && (z.value = e);
112
+ z.value && (B.value = e);
102
113
  }
103
114
  function n() {
104
- R.value = !1, z.value = null;
115
+ z.value = !1, B.value = null;
105
116
  }
106
117
  return {
107
- isActive: p(R),
108
- activeZoneId: p(z),
118
+ isActive: p(z),
119
+ activeZoneId: p(B),
109
120
  connectContext: e,
110
121
  setActiveZone: t,
111
122
  exit: n
@@ -113,7 +124,7 @@ function B() {
113
124
  }
114
125
  //#endregion
115
126
  //#region src/useCommsClient.ts
116
- function V(t, n, r) {
127
+ function H(t, n, r) {
117
128
  let i = m({}), a = b({
118
129
  parent: window.parent,
119
130
  connect: t,
@@ -122,17 +133,17 @@ function V(t, n, r) {
122
133
  get: () => o.value,
123
134
  set: (e) => a.appState.set(e)
124
135
  });
125
- return a.context.subscribe((e) => i.value = e), w(a.appState.get(), a.appState).subscribe((e) => o.value = e), U(a.signal, a, n), l(() => a.unsubscribe()), Object.assign(e(a, [
136
+ return a.context.subscribe((e) => i.value = e), w(a.appState.get(), a.appState).subscribe((e) => o.value = e), W(a.signal, a, n), l(() => a.unsubscribe()), Object.assign(e(a, [
126
137
  "context",
127
138
  "toolbar",
128
139
  "appState"
129
140
  ]), {
130
141
  context: i,
131
- toolbar: H(a),
142
+ toolbar: U(a),
132
143
  appState: c
133
144
  });
134
145
  }
135
- function H(e) {
146
+ function U(e) {
136
147
  let t = m(""), n = {
137
148
  title: s({
138
149
  get: () => e.toolbar.get().title,
@@ -185,13 +196,13 @@ function H(e) {
185
196
  };
186
197
  return e.toolbar.pipe(k((e) => e.search.input ?? ""), D(), E(300)).forEach((e) => t.value = e), n;
187
198
  }
188
- function U(e, t, n) {
199
+ function W(e, t, n) {
189
200
  let r = i(), a = r.ctrl ?? s(() => !1), c = r.shift ?? s(() => !1), l = new C(), u = l.pipe(T(n ?? ((e) => Promise.resolve(e))), T((t) => e(t))).subscribe();
190
201
  return t.add(u), u.add(o(a, () => l.next({ hotkeys: { ctrl: !0 } }))), u.add(o(c, () => l.next({ hotkeys: { shift: !0 } }))), u;
191
202
  }
192
203
  //#endregion
193
204
  //#region src/useCommsHost.ts
194
- function W(e) {
205
+ function G(e) {
195
206
  let { context: t } = e, n = new S({}), r = (e) => n.next(e(n.value)), i = m(), o = new S(void 0), c = g(i, (e) => o.next(e), { immediate: !0 }), l = o.asObservable().pipe(k((e) => e?.contentWindow), O((e) => !!e)), u = x({
196
207
  ...e,
197
208
  contextChanges: n,
@@ -232,7 +243,7 @@ function W(e) {
232
243
  }
233
244
  //#endregion
234
245
  //#region src/usePermissions.ts
235
- function G(e) {
246
+ function K(e) {
236
247
  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);
237
248
  function c(e) {
238
249
  return !t.value || !n.value ? !1 : i.value || a.value ? !0 : (n.value.user_roles ?? []).some((t) => t.name === e);
@@ -258,7 +269,7 @@ function G(e) {
258
269
  }
259
270
  //#endregion
260
271
  //#region src/useTemplateVersioning.ts
261
- function K(e) {
272
+ function q(e) {
262
273
  let t = h(null), n = h(null), r = h(null), i = h(null), a = h([]), o = h(null), c = m(!1), l = m(!1), u = m(!1), d = m(!1), f = m(!1), p = m(!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);
263
274
  async function b(n) {
264
275
  c.value = !0;
@@ -407,8 +418,8 @@ function K(e) {
407
418
  }
408
419
  //#endregion
409
420
  //#region src/useTriggerDispatch.ts
410
- function q(e, t = {}) {
411
- let n = t.authorizationTimeoutMs ?? 3e5, r = /* @__PURE__ */ new Set();
421
+ function J(e, t = {}) {
422
+ let n = t.authorizationTimeoutMs ?? 5 * 6e4, r = /* @__PURE__ */ new Set();
412
423
  d(() => {
413
424
  for (let e of r) e();
414
425
  });
@@ -434,18 +445,18 @@ function q(e, t = {}) {
434
445
  }
435
446
  //#endregion
436
447
  //#region src/utils.ts
437
- function J(e = "comms") {
438
- let [t, n] = Y(e, () => V(), (e) => e.unsubscribe());
448
+ function Y(e = "comms") {
449
+ let [t, n] = X(e, () => H(), (e) => e.unsubscribe());
439
450
  return {
440
451
  provideComms: t,
441
452
  injectComms: n
442
453
  };
443
454
  }
444
- function Y(e, t, n) {
455
+ function X(e, t, n) {
445
456
  let r, i = () => (!r && (r = t()), r);
446
457
  return [(t) => (t.onUnmount(() => n && r && n(r)), t.provide(e, i)), () => c(e)()];
447
458
  }
448
- function X(t, r, i) {
459
+ function Z(t, r, i) {
449
460
  let a = n(t, r, {
450
461
  immediate: !1,
451
462
  ...i
@@ -455,9 +466,9 @@ function X(t, r, i) {
455
466
  executeDelayed: a.execute
456
467
  });
457
468
  }
458
- function Z(e) {
469
+ function Q(e) {
459
470
  let t, n = m(void 0);
460
471
  return u(() => t = e.signal.receive((e) => n.value = e)), f(() => t?.()), [p(n), () => t?.()];
461
472
  }
462
473
  //#endregion
463
- export { F as formatDate, I as useAntColorMode, L as useAntI18n, X as useApi, B as useAppTourMode, V as useCommsClient, W as useCommsHost, J as useCommsInjection, G as usePermissions, Z as useSignal, Y as useSingleton, K as useTemplateVersioning, q as useTriggerDispatch };
474
+ export { F as formatDate, I as formatDateRange, L as useAntColorMode, R as useAntI18n, Z as useApi, V as useAppTourMode, H as useCommsClient, G as useCommsHost, Y as useCommsInjection, K as usePermissions, Q as useSignal, X as useSingleton, q as useTemplateVersioning, J as useTriggerDispatch };
@@ -7,6 +7,14 @@ export interface FormatDateOptions {
7
7
  /** Returned when value is null/undefined/empty/invalid. Default: ''. */
8
8
  fallback?: string;
9
9
  }
10
+ export interface FormatDateRangeOptions {
11
+ /** Display preset. Default: 'medium' (e.g. 6 Aug 2025). */
12
+ preset?: DateFormatPreset;
13
+ /** BCP-47 locale tag. Default: 'nl'. */
14
+ locale?: string;
15
+ /** Returned when both ends are null/undefined/empty/invalid. Default: ''. */
16
+ fallback?: string;
17
+ }
10
18
  /**
11
19
  * Format a date for display across the ANT environment.
12
20
  *
@@ -20,3 +28,15 @@ export interface FormatDateOptions {
20
28
  * serialisation, never for display.
21
29
  */
22
30
  export declare function formatDate(value: Date | string | number | null | undefined, options?: FormatDateOptions): string;
31
+ /**
32
+ * Format a date range with a smart, non-redundant year.
33
+ *
34
+ * Uses native `Intl…formatRange`, so the year collapses when both ends share
35
+ * it and stays on both ends when the range spans years:
36
+ * same month : 6–20 Aug 2025
37
+ * same year : 6 Aug – 20 Sep 2025
38
+ * multi-year : 6 Dec 2025 – 20 Jan 2026
39
+ *
40
+ * One-sided or same-day ranges fall back to a single `formatDate`.
41
+ */
42
+ export declare function formatDateRange(start: Date | string | number | null | undefined, end: Date | string | number | null | undefined, options?: FormatDateRangeOptions): string;
@@ -1,4 +1,4 @@
1
- export { type DateFormatPreset, formatDate, type FormatDateOptions } from './formatDate';
1
+ export { type DateFormatPreset, formatDate, type FormatDateOptions, formatDateRange, type FormatDateRangeOptions } from './formatDate';
2
2
  export { useAntColorMode, type UseAntColorModeOptions, type UseAntColorModeReturn } from './useAntColorMode';
3
3
  export { useAntI18n, type UseAntI18nReturn } from './useAntI18n';
4
4
  export { useAppTourMode } from './useAppTourMode';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@antcde/vue-utils",
3
3
  "type": "module",
4
- "version": "0.2.21-rc.1",
4
+ "version": "0.2.21-rc.2",
5
5
  "description": "Helper to use ANT Comms in Vue 3",
6
6
  "author": "CollaborAll",
7
7
  "exports": {
@@ -31,7 +31,7 @@
31
31
  "vue-i18n": "^11.1.12"
32
32
  },
33
33
  "dependencies": {
34
- "@antcde/connect-ts": "0.4.26-rc.1"
34
+ "@antcde/connect-ts": "0.4.26-rc.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@tsconfig/node22": "^22.0.5",