@antcde/vue-utils 0.2.13-rc.a84bbf9 → 0.2.13-rc.c0e281b

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,182 +1,210 @@
1
- import { useColorMode as P, objectPick as L, objectOmit as C, useMagicKeys as M, whenever as g, watchDebounced as O, useAsyncState as I } from "@vueuse/core";
2
- import { computed as u, watch as h, ref as d, onBeforeUnmount as E, onMounted as U, onUnmounted as D, readonly as H, inject as W } from "vue";
3
- import { useI18n as z } from "vue-i18n";
4
- import { newCommsClient as B, newCommsHost as K } from "@antcde/connect-ts";
5
- import { concat as R, Subject as T, concatMap as S, map as w, distinctUntilChanged as G, debounceTime as V, BehaviorSubject as j, filter as q } from "rxjs";
6
- function te(t, o) {
7
- const n = P(o), e = u(() => t.context.value.darkMode), s = u(() => {
8
- switch (e.value) {
9
- case null:
10
- return "auto";
11
- case !0:
12
- return "dark";
13
- case !1:
14
- return "light";
15
- default:
16
- return n.value;
17
- }
18
- }), r = u(() => {
19
- switch (s.value) {
20
- case "light":
21
- case "auto":
22
- return !1;
23
- case "dark":
24
- return !0;
25
- }
26
- });
27
- return Object.assign(
28
- s,
29
- { host: e, isDark: r },
30
- L(n, ["state", "system", "store"])
31
- );
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, watch as m } from "vue";
3
+ import { useI18n as h } from "vue-i18n";
4
+ import { newCommsClient as g, newCommsHost as _ } from "@antcde/connect-ts";
5
+ import { BehaviorSubject as v, Subject as y, concat as b, concatMap as x, debounceTime as S, distinctUntilChanged as C, filter as w, map as T } from "rxjs";
6
+ //#region src/useAntColorMode.ts
7
+ function E(e, n) {
8
+ let i = r(n), a = s(() => e.context.value.darkMode), o = s(() => {
9
+ switch (a.value) {
10
+ case null: return "auto";
11
+ case !0: return "dark";
12
+ case !1: return "light";
13
+ default: return i.value;
14
+ }
15
+ }), c = s(() => {
16
+ switch (o.value) {
17
+ case "light":
18
+ case "auto": return !1;
19
+ case "dark": return !0;
20
+ }
21
+ });
22
+ return Object.assign(o, {
23
+ host: a,
24
+ isDark: c
25
+ }, t(i, [
26
+ "state",
27
+ "system",
28
+ "store"
29
+ ]));
32
30
  }
33
- function se(t, o) {
34
- const n = z(o);
35
- return h(
36
- () => t.context.value.user?.language,
37
- (e) => n.locale.value = e ?? "en",
38
- { immediate: !0 }
39
- ), n;
31
+ //#endregion
32
+ //#region src/useAntI18n.ts
33
+ function D(e, t) {
34
+ let n = h(t);
35
+ return m(() => e.context.value.user?.language, (e) => n.locale.value = e ?? "en", { immediate: !0 }), n;
40
36
  }
41
- function F(t, o) {
42
- const n = d({}), e = B({ parent: window.parent, connect: t }), s = d(""), r = u({
43
- get: () => s.value,
44
- set: (i) => e.appState.set(i)
45
- });
46
- return e.context.subscribe((i) => n.value = i), R(e.appState.get(), e.appState).subscribe((i) => s.value = i), N(e.signal, e, o), E(() => e.unsubscribe()), Object.assign(
47
- C(e, ["context", "toolbar", "appState"]),
48
- {
49
- context: n,
50
- toolbar: J(e),
51
- appState: r
52
- }
53
- );
37
+ //#endregion
38
+ //#region src/useCommsClient.ts
39
+ function O(t, n, r) {
40
+ let i = p({}), a = g({
41
+ parent: window.parent,
42
+ connect: t,
43
+ manifest: r
44
+ }), o = p(""), c = s({
45
+ get: () => o.value,
46
+ set: (e) => a.appState.set(e)
47
+ });
48
+ return a.context.subscribe((e) => i.value = e), b(a.appState.get(), a.appState).subscribe((e) => o.value = e), A(a.signal, a, n), l(() => a.unsubscribe()), Object.assign(e(a, [
49
+ "context",
50
+ "toolbar",
51
+ "appState"
52
+ ]), {
53
+ context: i,
54
+ toolbar: k(a),
55
+ appState: c
56
+ });
54
57
  }
55
- function J(t) {
56
- const o = d(""), n = {
57
- title: u({
58
- get: () => t.toolbar.get().title,
59
- set: (e) => t.toolbar.set((s) => ({ ...s, title: e }))
60
- }),
61
- subtitle: u({
62
- get: () => t.toolbar.get().subtitle,
63
- set: (e) => t.toolbar.set((s) => ({ ...s, subtitle: e }))
64
- }),
65
- searchEnabled: u({
66
- get: () => t.toolbar.get().search.enabled,
67
- set: (e) => t.toolbar.set((s) => ({ ...s, search: { ...s.search, enabled: e } }))
68
- }),
69
- search: u({
70
- get: () => o.value,
71
- set: (e) => t.toolbar.set((s) => ({ ...s, search: { ...s.search, input: e } }))
72
- }),
73
- menu: u({
74
- get: () => t.toolbar.get().menu ?? [],
75
- set: (e) => t.toolbar.set((s) => ({ ...s, menu: e }))
76
- }),
77
- isLoading: u({
78
- get: () => t.toolbar.get().isLoading,
79
- set: (e) => t.toolbar.set((s) => ({ ...s, isLoading: e }))
80
- })
81
- };
82
- return t.toolbar.pipe(w((e) => e.search.input ?? ""), G(), V(300)).forEach((e) => o.value = e), n;
58
+ function k(e) {
59
+ let t = p(""), n = {
60
+ title: s({
61
+ get: () => e.toolbar.get().title,
62
+ set: (t) => e.toolbar.set((e) => ({
63
+ ...e,
64
+ title: t
65
+ }))
66
+ }),
67
+ subtitle: s({
68
+ get: () => e.toolbar.get().subtitle,
69
+ set: (t) => e.toolbar.set((e) => ({
70
+ ...e,
71
+ subtitle: t
72
+ }))
73
+ }),
74
+ searchEnabled: s({
75
+ get: () => e.toolbar.get().search.enabled,
76
+ set: (t) => e.toolbar.set((e) => ({
77
+ ...e,
78
+ search: {
79
+ ...e.search,
80
+ enabled: t
81
+ }
82
+ }))
83
+ }),
84
+ search: s({
85
+ get: () => t.value,
86
+ set: (t) => e.toolbar.set((e) => ({
87
+ ...e,
88
+ search: {
89
+ ...e.search,
90
+ input: t
91
+ }
92
+ }))
93
+ }),
94
+ menu: s({
95
+ get: () => e.toolbar.get().menu ?? [],
96
+ set: (t) => e.toolbar.set((e) => ({
97
+ ...e,
98
+ menu: t
99
+ }))
100
+ }),
101
+ isLoading: s({
102
+ get: () => e.toolbar.get().isLoading,
103
+ set: (t) => e.toolbar.set((e) => ({
104
+ ...e,
105
+ isLoading: t
106
+ }))
107
+ })
108
+ };
109
+ return e.toolbar.pipe(T((e) => e.search.input ?? ""), C(), S(300)).forEach((e) => t.value = e), n;
83
110
  }
84
- function N(t, o, n) {
85
- const e = M(), s = e.ctrl ?? u(() => !1), r = e.shift ?? u(() => !1), i = new T(), m = i.pipe(
86
- S(n ?? ((c) => Promise.resolve(c))),
87
- S((c) => t(c))
88
- ).subscribe();
89
- return o.add(m), m.add(g(s, () => i.next({ hotkeys: { ctrl: !0 } }))), m.add(g(r, () => i.next({ hotkeys: { shift: !0 } }))), m;
111
+ function A(e, t, n) {
112
+ let r = i(), a = r.ctrl ?? s(() => !1), c = r.shift ?? s(() => !1), l = new y(), u = l.pipe(x(n ?? ((e) => Promise.resolve(e))), x((t) => e(t))).subscribe();
113
+ return t.add(u), u.add(o(a, () => l.next({ hotkeys: { ctrl: !0 } }))), u.add(o(c, () => l.next({ hotkeys: { shift: !0 } }))), u;
90
114
  }
91
- function ne(t) {
92
- const { context: o } = t, n = new j({}), e = (a) => n.next(a(n.value)), s = d(), r = new j(void 0), i = h(s, (a) => r.next(a), { immediate: !0 }), m = r.asObservable().pipe(
93
- w((a) => a?.contentWindow),
94
- q((a) => !!a)
95
- ), c = K({ ...t, contextChanges: n, windowChanges: m });
96
- Object.entries(o).map(([a, b]) => h(
97
- b,
98
- (A) => e((k) => ({ ...k, [a]: A })),
99
- { immediate: !0 }
100
- )).forEach((a) => c.scope.add(a)), c.toolbar.subscribe((a) => {
101
- const b = t.toolbar;
102
- b.title.value = a.title, b.subtitle.value = a.subtitle, b.searchEnabled.value = a.search?.enabled ?? !1, b.search.value = a.search?.input, b.menu.value = a.menu, b.isLoading.value = a?.isLoading ?? !1;
103
- });
104
- const f = O(
105
- t.toolbar.search,
106
- (a) => c.toolbar.set.search(a),
107
- { immediate: !0, debounce: 100 }
108
- );
109
- c.scope.add(i), c.scope.add(f);
110
- const p = d(c.appState.get()), l = u({
111
- get: () => p.value,
112
- set: (a) => c.appState.set(a)
113
- });
114
- c.appState.changes.subscribe((a) => p.value = a);
115
- const v = d(!1);
116
- c.isConnectionInitialized.subscribe((a) => v.value = a);
117
- const { unsubscribe: x, signal: y, closed: _ } = c;
118
- return {
119
- ...t,
120
- client: s,
121
- appState: l,
122
- isConnectionInitialized: v,
123
- unsubscribe: x,
124
- signal: y,
125
- closed: _
126
- };
115
+ //#endregion
116
+ //#region src/useCommsHost.ts
117
+ function j(e) {
118
+ let { context: t } = e, n = new v({}), r = (e) => n.next(e(n.value)), i = p(), o = new v(void 0), c = m(i, (e) => o.next(e), { immediate: !0 }), l = o.asObservable().pipe(T((e) => e?.contentWindow), w((e) => !!e)), u = _({
119
+ ...e,
120
+ contextChanges: n,
121
+ windowChanges: l
122
+ });
123
+ Object.entries(t).map(([e, t]) => m(t, (t) => r((n) => ({
124
+ ...n,
125
+ [e]: t
126
+ })), { immediate: !0 })).forEach((e) => u.scope.add(e)), u.toolbar.subscribe((t) => {
127
+ let n = e.toolbar;
128
+ 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;
129
+ });
130
+ let d = a(e.toolbar.search, (e) => u.toolbar.set.search(e), {
131
+ immediate: !0,
132
+ debounce: 100
133
+ });
134
+ u.scope.add(c), u.scope.add(d);
135
+ let f = p(u.appState.get()), h = s({
136
+ get: () => f.value,
137
+ set: (e) => u.appState.set(e)
138
+ });
139
+ u.appState.changes.subscribe((e) => f.value = e);
140
+ let g = p(!1);
141
+ u.isConnectionInitialized.subscribe((e) => g.value = e);
142
+ let y = p(null);
143
+ u.manifest?.subscribe((e) => y.value = e);
144
+ let { unsubscribe: b, signal: x, closed: S } = u;
145
+ return {
146
+ ...e,
147
+ client: i,
148
+ appState: h,
149
+ isConnectionInitialized: g,
150
+ manifest: y,
151
+ unsubscribe: b,
152
+ signal: x,
153
+ closed: S
154
+ };
127
155
  }
128
- function oe(t) {
129
- const o = u(() => t.value?.user), n = u(() => t.value?.license), e = u(() => t.value?.project), s = u(() => !!o.value?.is_admin), r = u(() => !!n.value?.user_is_admin), i = u(() => !!e.value?.user_is_admin);
130
- function m(l) {
131
- return !o.value || !n.value ? !1 : s.value || r.value ? !0 : (n.value.user_roles ?? []).some((v) => v.name === l);
132
- }
133
- function c(l) {
134
- return !o.value || !n.value ? !1 : s.value || r.value ? !0 : !!n.value.user_permissions?.[String(l)];
135
- }
136
- function f(l) {
137
- return !o.value || !e.value ? !1 : s.value || r.value || i.value ? !0 : (e.value.user_roles ?? []).some((v) => v.name === l);
138
- }
139
- function p(l) {
140
- return !o.value || !e.value ? !1 : s.value || r.value ? !0 : !!e.value.user_permissions?.[String(l)];
141
- }
142
- return { isGlobalAdmin: s, isLicenseAdmin: r, isProjectAdmin: i, hasLicenseRole: m, hasLicensePermission: c, hasProjectRole: f, hasProjectPermission: p };
156
+ //#endregion
157
+ //#region src/usePermissions.ts
158
+ function M(e) {
159
+ 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);
160
+ function c(e) {
161
+ return !t.value || !n.value ? !1 : i.value || a.value ? !0 : (n.value.user_roles ?? []).some((t) => t.name === e);
162
+ }
163
+ function l(e) {
164
+ return !t.value || !n.value ? !1 : i.value || a.value ? !0 : !!n.value.user_permissions?.[String(e)];
165
+ }
166
+ function u(e) {
167
+ return !t.value || !r.value ? !1 : i.value || a.value || o.value ? !0 : (r.value.user_roles ?? []).some((t) => t.name === e);
168
+ }
169
+ function d(e) {
170
+ return !t.value || !r.value ? !1 : i.value || a.value ? !0 : !!r.value.user_permissions?.[String(e)];
171
+ }
172
+ return {
173
+ isGlobalAdmin: i,
174
+ isLicenseAdmin: a,
175
+ isProjectAdmin: o,
176
+ hasLicenseRole: c,
177
+ hasLicensePermission: l,
178
+ hasProjectRole: u,
179
+ hasProjectPermission: d
180
+ };
143
181
  }
144
- function ae(t = "comms") {
145
- const [o, n] = Q(
146
- t,
147
- () => F(),
148
- (e) => e.unsubscribe()
149
- );
150
- return { provideComms: o, injectComms: n };
182
+ //#endregion
183
+ //#region src/utils.ts
184
+ function N(e = "comms") {
185
+ let [t, n] = P(e, () => O(), (e) => e.unsubscribe());
186
+ return {
187
+ provideComms: t,
188
+ injectComms: n
189
+ };
151
190
  }
152
- function Q(t, o, n) {
153
- let e;
154
- const s = () => (!e && (e = o()), e);
155
- return [
156
- (r) => (r.onUnmount(() => n && e && n(e)), r.provide(t, s)),
157
- () => W(t)()
158
- ];
191
+ function P(e, t, n) {
192
+ let r, i = () => (!r && (r = t()), r);
193
+ return [(t) => (t.onUnmount(() => n && r && n(r)), t.provide(e, i)), () => c(e)()];
159
194
  }
160
- function re(t, o, n) {
161
- const s = I(t, o, { immediate: !1, ...n });
162
- return Object.assign(C(s, ["execute"]), {
163
- execute: (...r) => s.execute(void 0, ...r),
164
- executeDelayed: s.execute
165
- });
195
+ function F(t, r, i) {
196
+ let a = n(t, r, {
197
+ immediate: !1,
198
+ ...i
199
+ });
200
+ return Object.assign(e(a, ["execute"]), {
201
+ execute: (...e) => a.execute(void 0, ...e),
202
+ executeDelayed: a.execute
203
+ });
166
204
  }
167
- function ue(t) {
168
- let o;
169
- const n = d(void 0);
170
- return U(() => o = t.signal.receive((e) => n.value = e)), D(() => o?.()), [H(n), () => o?.()];
205
+ function I(e) {
206
+ let t, n = p(void 0);
207
+ return u(() => t = e.signal.receive((e) => n.value = e)), d(() => t?.()), [f(n), () => t?.()];
171
208
  }
172
- export {
173
- te as useAntColorMode,
174
- se as useAntI18n,
175
- re as useApi,
176
- F as useCommsClient,
177
- ne as useCommsHost,
178
- ae as useCommsInjection,
179
- oe as usePermissions,
180
- ue as useSignal,
181
- Q as useSingleton
182
- };
209
+ //#endregion
210
+ export { E as useAntColorMode, D as useAntI18n, F as useApi, O as useCommsClient, j as useCommsHost, N as useCommsInjection, M as usePermissions, I as useSignal, P as useSingleton };
@@ -1,4 +1,4 @@
1
- import { AntConnect, Client, Context, Signal } from '@antcde/connect-ts';
1
+ import { AntConnect, AppManifest, Client, Context, Signal } from '@antcde/connect-ts';
2
2
  import { ObservableInput } from 'rxjs';
3
3
  import { Ref } from 'vue';
4
4
  import { CommsToolbar } from './utils';
@@ -20,5 +20,5 @@ type KeyboardShortcutsHook = (signal: Signal) => ObservableInput<Signal>;
20
20
  * @param keyboardsShortcuts By default it will process keyboards from the client and send them to the host.
21
21
  *
22
22
  */
23
- export declare function useCommsClient(connect?: AntConnect, keyboardsShortcuts?: KeyboardShortcutsHook): UseCommsClient;
23
+ export declare function useCommsClient(connect?: AntConnect, keyboardsShortcuts?: KeyboardShortcutsHook, manifest?: AppManifest): UseCommsClient;
24
24
  export {};
@@ -1,4 +1,4 @@
1
- import { AntConnect, LabelFilterState, License, Notepad, Notification, ProjectShort, SignalObserverFactory, SignalReceiver, SignalSender, Task, User } from '@antcde/connect-ts';
1
+ import { AntConnect, AppManifest, LabelFilterState, License, Notepad, Notification, ProjectShort, SignalObserverFactory, SignalReceiver, SignalSender, Task, User } from '@antcde/connect-ts';
2
2
  import { SubscriptionLike } from 'rxjs';
3
3
  import { Ref } from 'vue';
4
4
  import { CommsToolbar } from './utils';
@@ -30,6 +30,7 @@ export interface UseCommsHost extends CommsHostArgs, SubscriptionLike {
30
30
  client: Ref<HTMLIFrameElement | null | undefined>;
31
31
  appState: Ref<string>;
32
32
  isConnectionInitialized: Ref<boolean>;
33
+ manifest: Ref<AppManifest | null>;
33
34
  signal: SignalReceiver & SignalSender;
34
35
  }
35
36
  export declare function useCommsHost(args: CommsHostArgs): UseCommsHost;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@antcde/vue-utils",
3
3
  "type": "module",
4
- "version": "0.2.13-rc.a84bbf9",
4
+ "version": "0.2.13-rc.c0e281b",
5
5
  "description": "Helper to use ANT Comms in Vue 3",
6
6
  "author": "CollaborAll",
7
7
  "exports": {
@@ -25,22 +25,22 @@
25
25
  "clean": "pnpm dlx rimraf dist"
26
26
  },
27
27
  "peerDependencies": {
28
- "@vueuse/core": "^13.9.0",
28
+ "@vueuse/core": "^14.0.0",
29
29
  "rxjs": "^7.0.0",
30
30
  "vue": "^3.5.10",
31
31
  "vue-i18n": "^11.1.12"
32
32
  },
33
33
  "dependencies": {
34
- "@antcde/connect-ts": "0.4.17-rc.a84bbf9"
34
+ "@antcde/connect-ts": "0.4.17-rc.c0e281b"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@tsconfig/node22": "^22.0.5",
38
38
  "@types/node": "^22.19.17",
39
- "@vitejs/plugin-vue": "^6.0.5",
40
- "@vue/tsconfig": "^0.8.1",
41
- "typescript": "~5.9.3",
42
- "vite": "^7.3.2",
39
+ "@vitejs/plugin-vue": "^6.0.6",
40
+ "@vue/tsconfig": "^0.9.1",
41
+ "typescript": "~6.0.3",
42
+ "vite": "^8.0.9",
43
43
  "vite-plugin-dts": "^4.5.4",
44
- "vue-tsc": "^3.2.6"
44
+ "vue-tsc": "^3.2.7"
45
45
  }
46
46
  }