@antcde/vue-utils 0.2.19 → 0.2.21-rc.1

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
@@ -1,10 +1,10 @@
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
- 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
- import { useI18n as g } from "vue-i18n";
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";
2
+ import { computed as s, inject as c, onBeforeUnmount as l, onMounted as u, onScopeDispose as d, onUnmounted as f, readonly as p, ref as m, shallowRef as h, watch as g } from "vue";
3
+ import { useI18n as _ } from "vue-i18n";
4
+ import { clone as v, isAuthorizationRequired as y, newCommsClient as b, newCommsHost as x } from "@antcde/connect-ts";
5
+ import { BehaviorSubject as S, Subject as C, concat as w, concatMap as T, debounceTime as E, distinctUntilChanged as D, filter as O, map as k } from "rxjs";
6
6
  //#region src/formatDate.ts
7
- var O = "nl", k = {
7
+ var A = "nl", j = {
8
8
  short: {
9
9
  day: "2-digit",
10
10
  month: "2-digit",
@@ -40,25 +40,25 @@ var O = "nl", k = {
40
40
  minute: "2-digit",
41
41
  hour12: !1
42
42
  }
43
- }, A = new Set(["short", "shortDateTime"]);
44
- function j(e) {
43
+ }, M = /* @__PURE__ */ new Set(["short", "shortDateTime"]);
44
+ function N(e) {
45
45
  return e instanceof Date ? e : new Date(e);
46
46
  }
47
- function M(e) {
47
+ function P(e) {
48
48
  return `${e.getFullYear()}-${String(e.getMonth() + 1).padStart(2, "0")}-${String(e.getDate()).padStart(2, "0")}`;
49
49
  }
50
- function N(e, t = {}) {
51
- let { preset: n = "short", locale: r = O, fallback: i = "" } = t;
50
+ function F(e, t = {}) {
51
+ let { preset: n = "short", locale: r = A, fallback: i = "" } = t;
52
52
  if (e == null || e === "") return i;
53
- let a = j(e);
53
+ let a = N(e);
54
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);
55
+ if (n === "iso") return P(a);
56
+ let o = M.has(n) && /^en\b/i.test(r) ? A : r;
57
+ return new Intl.DateTimeFormat(o, j[n]).format(a);
58
58
  }
59
59
  //#endregion
60
60
  //#region src/useAntColorMode.ts
61
- function P(e, n) {
61
+ function I(e, n) {
62
62
  let i = r(n), a = s(() => e.context.value.darkMode), o = s(() => {
63
63
  switch (a.value) {
64
64
  case null: return "auto";
@@ -84,28 +84,28 @@ function P(e, n) {
84
84
  }
85
85
  //#endregion
86
86
  //#region src/useAntI18n.ts
87
- function F(e, t) {
88
- let n = g(t);
89
- return h(() => e.context.value.user?.language, (e) => n.locale.value = e ?? "en", { immediate: !0 }), n;
87
+ function L(e, t) {
88
+ let n = _(t);
89
+ return g(() => e.context.value.user?.language, (e) => n.locale.value = e ?? "en", { immediate: !0 }), n;
90
90
  }
91
91
  //#endregion
92
92
  //#region src/useAppTourMode.ts
93
- var I = p(!1), L = p(null);
94
- function R() {
93
+ var R = m(!1), z = m(null);
94
+ function B() {
95
95
  function e(e) {
96
- h(() => e.value.tourMode, (e) => {
97
- I.value = !!e, e || (L.value = null);
96
+ g(() => e.value.tourMode, (e) => {
97
+ R.value = !!e, e || (z.value = null);
98
98
  }, { immediate: !0 });
99
99
  }
100
100
  function t(e) {
101
- I.value && (L.value = e);
101
+ R.value && (z.value = e);
102
102
  }
103
103
  function n() {
104
- I.value = !1, L.value = null;
104
+ R.value = !1, z.value = null;
105
105
  }
106
106
  return {
107
- isActive: f(I),
108
- activeZoneId: f(L),
107
+ isActive: p(R),
108
+ activeZoneId: p(z),
109
109
  connectContext: e,
110
110
  setActiveZone: t,
111
111
  exit: n
@@ -113,27 +113,27 @@ function R() {
113
113
  }
114
114
  //#endregion
115
115
  //#region src/useCommsClient.ts
116
- function z(t, n, r) {
117
- let i = p({}), a = v({
116
+ function V(t, n, r) {
117
+ let i = m({}), a = b({
118
118
  parent: window.parent,
119
119
  connect: t,
120
120
  manifest: r
121
- }), o = p(""), c = s({
121
+ }), o = m(""), c = s({
122
122
  get: () => o.value,
123
123
  set: (e) => a.appState.set(e)
124
124
  });
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, [
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, [
126
126
  "context",
127
127
  "toolbar",
128
128
  "appState"
129
129
  ]), {
130
130
  context: i,
131
- toolbar: B(a),
131
+ toolbar: H(a),
132
132
  appState: c
133
133
  });
134
134
  }
135
- function B(e) {
136
- let t = p(""), n = {
135
+ function H(e) {
136
+ let t = m(""), n = {
137
137
  title: s({
138
138
  get: () => e.toolbar.get().title,
139
139
  set: (t) => e.toolbar.set((e) => ({
@@ -183,23 +183,23 @@ function B(e) {
183
183
  }))
184
184
  })
185
185
  };
186
- return e.toolbar.pipe(D((e) => e.search.input ?? ""), T(), w(300)).forEach((e) => t.value = e), n;
186
+ return e.toolbar.pipe(k((e) => e.search.input ?? ""), D(), E(300)).forEach((e) => t.value = e), n;
187
187
  }
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();
188
+ function U(e, t, n) {
189
+ 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
190
  return t.add(u), u.add(o(a, () => l.next({ hotkeys: { ctrl: !0 } }))), u.add(o(c, () => l.next({ hotkeys: { shift: !0 } }))), u;
191
191
  }
192
192
  //#endregion
193
193
  //#region src/useCommsHost.ts
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({
194
+ function W(e) {
195
+ 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
196
  ...e,
197
197
  contextChanges: n,
198
198
  windowChanges: l
199
199
  });
200
- Object.entries(t).map(([e, t]) => h(t, (t) => r((n) => ({
200
+ Object.entries(t).map(([e, t]) => g(t, (t) => r((n) => ({
201
201
  ...n,
202
- [e]: _(t)
202
+ [e]: v(t)
203
203
  })), { immediate: !0 })).forEach((e) => u.scope.add(e)), u.toolbar.subscribe((t) => {
204
204
  let n = e.toolbar;
205
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;
@@ -209,30 +209,30 @@ function H(e) {
209
209
  debounce: 100
210
210
  });
211
211
  u.scope.add(c), u.scope.add(d);
212
- let f = p(u.appState.get()), m = s({
212
+ let f = m(u.appState.get()), p = s({
213
213
  get: () => f.value,
214
214
  set: (e) => u.appState.set(e)
215
215
  });
216
216
  u.appState.changes.subscribe((e) => f.value = e);
217
- let g = p(!1);
218
- u.isConnectionInitialized.subscribe((e) => g.value = e);
219
- let v = p(null);
220
- u.manifest?.subscribe((e) => v.value = e);
221
- let { unsubscribe: x, signal: S, closed: C } = u;
217
+ let h = m(!1);
218
+ u.isConnectionInitialized.subscribe((e) => h.value = e);
219
+ let _ = m(null);
220
+ u.manifest?.subscribe((e) => _.value = e);
221
+ let { unsubscribe: y, signal: b, closed: C } = u;
222
222
  return {
223
223
  ...e,
224
224
  client: i,
225
- appState: m,
226
- isConnectionInitialized: g,
227
- manifest: v,
228
- unsubscribe: x,
229
- signal: S,
225
+ appState: p,
226
+ isConnectionInitialized: h,
227
+ manifest: _,
228
+ unsubscribe: y,
229
+ signal: b,
230
230
  closed: C
231
231
  };
232
232
  }
233
233
  //#endregion
234
234
  //#region src/usePermissions.ts
235
- function U(e) {
235
+ function G(e) {
236
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);
237
237
  function c(e) {
238
238
  return !t.value || !n.value ? !1 : i.value || a.value ? !0 : (n.value.user_roles ?? []).some((t) => t.name === e);
@@ -258,12 +258,13 @@ function U(e) {
258
258
  }
259
259
  //#endregion
260
260
  //#region src/useTemplateVersioning.ts
261
- function W(e) {
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);
261
+ function K(e) {
262
+ 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
263
  async function b(n) {
264
264
  c.value = !0;
265
265
  try {
266
- return t.value = (await e.tasks.checkForUpdates(n))?.data ?? null, t.value;
266
+ let r = await e.tasks.checkForUpdates(n);
267
+ return t.value = r?.data ?? null, t.value;
267
268
  } catch {
268
269
  return t.value = null, null;
269
270
  } finally {
@@ -273,7 +274,8 @@ function W(e) {
273
274
  async function x(t, r) {
274
275
  l.value = !0;
275
276
  try {
276
- return n.value = (await e.tasks.versionDiff(t, r))?.data ?? null, n.value;
277
+ let i = await e.tasks.versionDiff(t, r);
278
+ return n.value = i?.data ?? null, n.value;
277
279
  } catch {
278
280
  return n.value = null, null;
279
281
  } finally {
@@ -283,7 +285,8 @@ function W(e) {
283
285
  async function S(t, r, i) {
284
286
  l.value = !0;
285
287
  try {
286
- return n.value = (await e.tasks.versionCompare(t, r, i))?.data ?? null, n.value;
288
+ let a = await e.tasks.versionCompare(t, r, i);
289
+ return n.value = a?.data ?? null, n.value;
287
290
  } catch {
288
291
  return n.value = null, null;
289
292
  } finally {
@@ -293,7 +296,8 @@ function W(e) {
293
296
  async function C(t) {
294
297
  u.value = !0;
295
298
  try {
296
- return r.value = (await e.tasks.versionDiffOriginal(t))?.data ?? null, r.value;
299
+ let n = await e.tasks.versionDiffOriginal(t);
300
+ return r.value = n?.data ?? null, r.value;
297
301
  } catch {
298
302
  return r.value = null, null;
299
303
  } finally {
@@ -303,7 +307,8 @@ function W(e) {
303
307
  async function w(r, a) {
304
308
  d.value = !0;
305
309
  try {
306
- return i.value = (await e.tasks.syncToLatestVersion(r, a))?.data ?? null, t.value = null, n.value = null, i.value;
310
+ let o = await e.tasks.syncToLatestVersion(r, a);
311
+ return i.value = o?.data ?? null, t.value = null, n.value = null, i.value;
307
312
  } catch {
308
313
  return i.value = null, null;
309
314
  } finally {
@@ -322,27 +327,30 @@ function W(e) {
322
327
  }
323
328
  }
324
329
  async function E(t) {
325
- h.value = !0;
330
+ p.value = !0;
326
331
  try {
327
- return a.value = (await e.tasks.listVersions(t))?.data ?? [], a.value;
332
+ let n = await e.tasks.listVersions(t);
333
+ return a.value = n?.data ?? [], a.value;
328
334
  } catch {
329
335
  return a.value = [], [];
330
336
  } finally {
331
- h.value = !1;
337
+ p.value = !1;
332
338
  }
333
339
  }
334
340
  async function D(t) {
335
341
  try {
336
- return o.value = (await e.tasks.latestVersion(t))?.data ?? null, o.value;
342
+ let n = await e.tasks.latestVersion(t);
343
+ return o.value = n?.data ?? null, o.value;
337
344
  } catch {
338
345
  return o.value = null, null;
339
346
  }
340
347
  }
341
- let O = m([]), k = p(!1), A = p(!1), j = m([]);
348
+ let O = h([]), k = m(!1), A = m(!1), j = h([]);
342
349
  async function M(t) {
343
350
  k.value = !0;
344
351
  try {
345
- return O.value = (await e.tasks.getInstances(t))?.data ?? [], O.value;
352
+ let n = await e.tasks.getInstances(t);
353
+ return O.value = n?.data ?? [], O.value;
346
354
  } catch {
347
355
  return O.value = [], [];
348
356
  } finally {
@@ -352,7 +360,8 @@ function W(e) {
352
360
  async function N(t, n) {
353
361
  A.value = !0, j.value = [];
354
362
  try {
355
- return j.value = (await e.tasks.pushSync(t, n))?.data ?? [], j.value;
363
+ let r = await e.tasks.pushSync(t, n);
364
+ return j.value = r?.data ?? [], j.value;
356
365
  } catch {
357
366
  return j.value = [], [];
358
367
  } finally {
@@ -376,7 +385,7 @@ function W(e) {
376
385
  isFetchingCustomizations: u,
377
386
  isSyncing: d,
378
387
  isPublishing: f,
379
- isFetchingVersions: h,
388
+ isFetchingVersions: p,
380
389
  isFetchingInstances: k,
381
390
  isPushSyncing: A,
382
391
  hasUpdate: g,
@@ -397,19 +406,46 @@ function W(e) {
397
406
  };
398
407
  }
399
408
  //#endregion
409
+ //#region src/useTriggerDispatch.ts
410
+ function q(e, t = {}) {
411
+ let n = t.authorizationTimeoutMs ?? 3e5, r = /* @__PURE__ */ new Set();
412
+ d(() => {
413
+ for (let e of r) e();
414
+ });
415
+ function i(t) {
416
+ return new Promise((i) => {
417
+ let a = !1, o, s, c, l = (e) => {
418
+ a || (a = !0, o?.(), s && clearTimeout(s), c && r.delete(c), i(e));
419
+ };
420
+ c = () => l(!1), r.add(c), o = e.signal.receive((e) => {
421
+ let n = e.oauthAuthorizeResult;
422
+ n && n.secretId === t.secret_id && l(n.ok);
423
+ }), s = setTimeout(l, n, !1), e.signal({ oauthAuthorize: {
424
+ authorizeUrl: t.authorize_url,
425
+ secretId: t.secret_id
426
+ } });
427
+ });
428
+ }
429
+ async function a(e) {
430
+ let t = await e();
431
+ return !y(t) || !await i(t) ? t : e();
432
+ }
433
+ return { dispatch: a };
434
+ }
435
+ //#endregion
400
436
  //#region src/utils.ts
401
- function G(e = "comms") {
402
- let [t, n] = K(e, () => z(), (e) => e.unsubscribe());
437
+ function J(e = "comms") {
438
+ let [t, n] = Y(e, () => V(), (e) => e.unsubscribe());
403
439
  return {
404
440
  provideComms: t,
405
441
  injectComms: n
406
442
  };
407
443
  }
408
- function K(e, t, n) {
444
+ function Y(e, t, n) {
409
445
  let r, i = () => (!r && (r = t()), r);
410
446
  return [(t) => (t.onUnmount(() => n && r && n(r)), t.provide(e, i)), () => c(e)()];
411
447
  }
412
- function q(t, r, i) {
448
+ function X(t, r, i) {
413
449
  let a = n(t, r, {
414
450
  immediate: !1,
415
451
  ...i
@@ -419,9 +455,9 @@ function q(t, r, i) {
419
455
  executeDelayed: a.execute
420
456
  });
421
457
  }
422
- function J(e) {
423
- let t, n = p(void 0);
424
- return u(() => t = e.signal.receive((e) => n.value = e)), d(() => t?.()), [f(n), () => t?.()];
458
+ function Z(e) {
459
+ let t, n = m(void 0);
460
+ return u(() => t = e.signal.receive((e) => n.value = e)), f(() => t?.()), [p(n), () => t?.()];
425
461
  }
426
462
  //#endregion
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 };
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 };
@@ -6,4 +6,5 @@ export { type UseCommsClient, useCommsClient } from './useCommsClient';
6
6
  export { type CommsHostArgs, type UseCommsHost, useCommsHost } from './useCommsHost';
7
7
  export { type UsePermissions, usePermissions } from './usePermissions';
8
8
  export { useTemplateVersioning, type UseTemplateVersioningReturn } from './useTemplateVersioning';
9
+ export { useTriggerDispatch, type UseTriggerDispatchOptions, type UseTriggerDispatchReturn } from './useTriggerDispatch';
9
10
  export { type AnyUseApiReturn, type CommsToolbar, useApi, type UseApiReturn, useCommsInjection, useSignal, useSingleton, } from './utils';
@@ -0,0 +1,28 @@
1
+ import { TriggerDispatchResult } from '@antcde/connect-ts';
2
+ import { UseCommsClient } from './useCommsClient';
3
+ export interface UseTriggerDispatchOptions {
4
+ authorizationTimeoutMs?: number;
5
+ }
6
+ export interface UseTriggerDispatchReturn {
7
+ dispatch: (run: () => Promise<TriggerDispatchResult>) => Promise<TriggerDispatchResult>;
8
+ }
9
+ /**
10
+ * Wrap a trigger dispatch so a per-user OAuth2 "authorization required" outcome is
11
+ * handled transparently for iframe apps: on that outcome the helper asks the HOST
12
+ * (via the `oauthAuthorize` signal) to open the provider consent popup, awaits the
13
+ * host's `oauthAuthorizeResult`, and — when the user authorized — re-runs the
14
+ * dispatch exactly once. Any other outcome is returned unchanged.
15
+ *
16
+ * `run` is the caller's own dispatch invocation (e.g. a `useApi(...).execute`
17
+ * wrapper that resolves to the response body), so this composable stays decoupled
18
+ * from how the request is made and re-runs the identical call after consent.
19
+ *
20
+ * @example
21
+ * const { dispatch } = useTriggerDispatch(comms)
22
+ * const call = useApi(connect.triggers.dispatch, null)
23
+ * const result = await dispatch(async () => {
24
+ * await call.execute(triggerableType, triggerableId, triggerId)
25
+ * return call.state.value
26
+ * })
27
+ */
28
+ export declare function useTriggerDispatch(comms: UseCommsClient, options?: UseTriggerDispatchOptions): UseTriggerDispatchReturn;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@antcde/vue-utils",
3
3
  "type": "module",
4
- "version": "0.2.19",
4
+ "version": "0.2.21-rc.1",
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.24"
34
+ "@antcde/connect-ts": "0.4.26-rc.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@tsconfig/node22": "^22.0.5",
38
- "@types/node": "^22.19.21",
39
- "@vitejs/plugin-vue": "^6.0.7",
38
+ "@types/node": "^22.20.1",
39
+ "@vitejs/plugin-vue": "^6.0.8",
40
40
  "@vue/tsconfig": "^0.9.1",
41
41
  "typescript": "~6.0.3",
42
- "vite": "^8.0.16",
42
+ "vite": "^8.1.5",
43
43
  "vite-plugin-dts": "^4.5.4",
44
- "vue-tsc": "^3.3.5"
44
+ "vue-tsc": "^3.3.7"
45
45
  }
46
46
  }