@antcde/vue-utils 0.2.11 → 0.2.12-rc.64ce643

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
- import { useColorMode as A, objectPick as O, objectOmit as v, useMagicKeys as I, whenever as h, watchDebounced as E, useAsyncState as L } from "@vueuse/core";
2
- import { computed as i, watch as d, ref as b, onBeforeUnmount as x, onMounted as U, onUnmounted as D, readonly as H, inject as z } from "vue";
3
- import { useI18n as B } from "vue-i18n";
4
- import { newCommsClient as K, newCommsHost as P } from "@antcde/connect-ts";
5
- import { concat as T, Subject as _, concatMap as g, map as C, distinctUntilChanged as V, debounceTime as W, tap as q, BehaviorSubject as f, filter as F } from "rxjs";
6
- function ee(o, s) {
7
- const t = A(s), e = i(() => o.context.value.darkMode), a = i(() => {
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
8
  switch (e.value) {
9
9
  case null:
10
10
  return "auto";
@@ -13,10 +13,10 @@ function ee(o, s) {
13
13
  case !1:
14
14
  return "light";
15
15
  default:
16
- return t.value;
16
+ return n.value;
17
17
  }
18
- }), r = i(() => {
19
- switch (a.value) {
18
+ }), r = u(() => {
19
+ switch (s.value) {
20
20
  case "light":
21
21
  case "auto":
22
22
  return !1;
@@ -25,134 +25,158 @@ function ee(o, s) {
25
25
  }
26
26
  });
27
27
  return Object.assign(
28
- a,
28
+ s,
29
29
  { host: e, isDark: r },
30
- O(t, ["state", "system", "store"])
30
+ L(n, ["state", "system", "store"])
31
31
  );
32
32
  }
33
- function te(o, s) {
34
- const t = B(s);
35
- return d(
36
- () => o.context.value.user?.language,
37
- (e) => t.locale.value = e ?? "en",
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
38
  { immediate: !0 }
39
- ), t;
39
+ ), n;
40
40
  }
41
- function G(o, s) {
42
- const t = b({}), e = K({ parent: window.parent, connect: o }), a = b(""), r = i({
43
- get: () => a.value,
44
- set: (u) => e.appState.set(u)
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
45
  });
46
- return e.context.subscribe((u) => t.value = u), T(e.appState.get(), e.appState).subscribe((u) => a.value = u), N(e.signal, e, s), x(() => e.unsubscribe()), Object.assign(
47
- v(e, ["context", "toolbar", "appState"]),
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
48
  {
49
- context: t,
49
+ context: n,
50
50
  toolbar: J(e),
51
51
  appState: r
52
52
  }
53
53
  );
54
54
  }
55
- function J(o) {
56
- const s = {
57
- title: i({
58
- get: () => o.toolbar.get().title,
59
- set: (t) => o.toolbar.set((e) => ({ ...e, title: t }))
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
60
  }),
61
- searchEnabled: i({
62
- get: () => o.toolbar.get().search.enabled,
63
- set: (t) => o.toolbar.set((e) => ({ ...e, search: { ...e.search, enabled: t } }))
61
+ subtitle: u({
62
+ get: () => t.toolbar.get().subtitle,
63
+ set: (e) => t.toolbar.set((s) => ({ ...s, subtitle: e }))
64
64
  }),
65
- search: b(""),
66
- menu: i({
67
- get: () => o.toolbar.get().menu ?? [],
68
- set: (t) => o.toolbar.set((e) => ({ ...e, menu: t }))
65
+ searchEnabled: u({
66
+ get: () => t.toolbar.get().search.enabled,
67
+ set: (e) => t.toolbar.set((s) => ({ ...s, search: { ...s.search, enabled: e } }))
69
68
  }),
70
- isLoading: i({
71
- get: () => o.toolbar.get().isLoading,
72
- set: (t) => o.toolbar.set((e) => ({ ...e, isLoading: t }))
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 }))
73
80
  })
74
81
  };
75
- return o.toolbar.pipe(C((t) => t.search.input ?? ""), V(), W(300), q(console.log)).forEach((t) => s.search.value = t), s;
82
+ return t.toolbar.pipe(w((e) => e.search.input ?? ""), G(), V(300)).forEach((e) => o.value = e), n;
76
83
  }
77
- function N(o, s, t) {
78
- const e = I(), { ctrl: a, shift: r } = e, u = new _(), c = u.pipe(
79
- g(t ?? ((m) => Promise.resolve(m))),
80
- g((m) => o(m))
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))
81
88
  ).subscribe();
82
- return s.add(c), c.add(h(a, () => u.next({ hotkeys: { ctrl: !0 } }))), c.add(h(r, () => u.next({ hotkeys: { shift: !0 } }))), c;
89
+ return o.add(m), m.add(g(s, () => i.next({ hotkeys: { ctrl: !0 } }))), m.add(g(r, () => i.next({ hotkeys: { shift: !0 } }))), m;
83
90
  }
84
- function oe(o) {
85
- const { context: s } = o, t = new f({}), e = (n) => t.next(n(t.value)), a = b(), r = new f(void 0);
86
- d(a, (n) => r.next(n), { immediate: !0 });
87
- const u = r.asObservable().pipe(
88
- C((n) => n?.contentWindow),
89
- F((n) => !!n)
90
- ), c = P({ ...o, contextChanges: t, windowChanges: u });
91
- Object.entries(s).map(([n, l]) => d(
92
- l,
93
- (k) => e((M) => ({ ...M, [n]: k })),
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 })),
94
99
  { immediate: !0 }
95
- )).forEach((n) => c.scope.add(n)), c.toolbar.subscribe((n) => {
96
- const l = o.toolbar;
97
- l.title.value = n.title, l.searchEnabled.value = n.search?.enabled ?? !1, l.search.value = n.search?.input, l.menu.value = n.menu, l.isLoading.value = n?.isLoading ?? !1;
98
- }), E(
99
- o.toolbar.search,
100
- (n) => c.toolbar.set.search(n),
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),
101
107
  { immediate: !0, debounce: 100 }
102
108
  );
103
- const m = b(c.appState.get()), w = i({
104
- get: () => m.value,
105
- set: (n) => c.appState.set(n)
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)
106
113
  });
107
- c.appState.changes.subscribe((n) => m.value = n);
108
- const p = b(!1);
109
- c.isConnectionInitialized.subscribe((n) => p.value = n), x(() => c.unsubscribe());
110
- const { unsubscribe: S, signal: j, closed: y } = c;
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;
111
118
  return {
112
- ...o,
113
- client: a,
114
- appState: w,
115
- isConnectionInitialized: p,
116
- unsubscribe: S,
117
- signal: j,
118
- closed: y
119
+ ...t,
120
+ client: s,
121
+ appState: l,
122
+ isConnectionInitialized: v,
123
+ unsubscribe: x,
124
+ signal: y,
125
+ closed: _
119
126
  };
120
127
  }
121
- function ne(o = "comms") {
122
- const [s, t] = Q(
123
- o,
124
- () => G(),
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 };
143
+ }
144
+ function ae(t = "comms") {
145
+ const [o, n] = Q(
146
+ t,
147
+ () => F(),
125
148
  (e) => e.unsubscribe()
126
149
  );
127
- return { provideComms: s, injectComms: t };
150
+ return { provideComms: o, injectComms: n };
128
151
  }
129
- function Q(o, s, t) {
152
+ function Q(t, o, n) {
130
153
  let e;
131
- const a = () => (!e && (e = s()), e);
154
+ const s = () => (!e && (e = o()), e);
132
155
  return [
133
- (r) => (r.onUnmount(() => t && e && t(e)), r.provide(o, a)),
134
- () => z(o)()
156
+ (r) => (r.onUnmount(() => n && e && n(e)), r.provide(t, s)),
157
+ () => W(t)()
135
158
  ];
136
159
  }
137
- function se(o, s, t) {
138
- const a = L(o, s, { immediate: !1, ...t });
139
- return Object.assign(v(a, ["execute"]), {
140
- execute: (...r) => a.execute(void 0, ...r),
141
- executeDelayed: a.execute
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
142
165
  });
143
166
  }
144
- function ae(o) {
145
- let s;
146
- const t = b(void 0);
147
- return U(() => s = o.signal.receive((e) => t.value = e)), D(() => s?.()), [H(t), () => s?.()];
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?.()];
148
171
  }
149
172
  export {
150
- ee as useAntColorMode,
151
- te as useAntI18n,
152
- se as useApi,
153
- G as useCommsClient,
154
- oe as useCommsHost,
155
- ne as useCommsInjection,
156
- ae as useSignal,
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,
157
181
  Q as useSingleton
158
182
  };
@@ -2,4 +2,5 @@ export { useAntColorMode, type UseAntColorModeOptions, type UseAntColorModeRetur
2
2
  export { useAntI18n, type UseAntI18nReturn } from './useAntI18n';
3
3
  export { type UseCommsClient, useCommsClient } from './useCommsClient';
4
4
  export { type CommsHostArgs, type UseCommsHost, useCommsHost } from './useCommsHost';
5
+ export { type UsePermissions, usePermissions } from './usePermissions';
5
6
  export { type AnyUseApiReturn, type CommsToolbar, useApi, type UseApiReturn, useCommsInjection, useSignal, useSingleton, } from './utils';
@@ -1,4 +1,4 @@
1
- import { AntConnect, Change, ChangeSignal, LabelFilterState, License, Notepad, Notification, ProjectShort, SignalReceiver, SignalSender, Task, User } from '@antcde/connect-ts';
1
+ import { AntConnect, 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';
@@ -24,7 +24,7 @@ export interface CommsHostArgs {
24
24
  darkMode: Ref<Nullable<boolean>>;
25
25
  selectedLabels: Ref<LabelFilterState>;
26
26
  };
27
- newSignalObserver: <T extends keyof ChangeSignal>(type: T, id: string, actions: Change[], callback: (signal: ChangeSignal) => void) => () => void;
27
+ newSignalObserver: SignalObserverFactory;
28
28
  }
29
29
  export interface UseCommsHost extends CommsHostArgs, SubscriptionLike {
30
30
  client: Ref<HTMLIFrameElement | null | undefined>;
@@ -0,0 +1,12 @@
1
+ import { Context, LicensePermissionMap, ProjectPermissionMap, Role } from '@antcde/connect-ts';
2
+ import { ComputedRef, Ref } from 'vue';
3
+ export interface UsePermissions {
4
+ isGlobalAdmin: ComputedRef<boolean>;
5
+ isLicenseAdmin: ComputedRef<boolean>;
6
+ isProjectAdmin: ComputedRef<boolean>;
7
+ hasLicenseRole: (roleName: Role['name']) => boolean;
8
+ hasLicensePermission: (permission: keyof LicensePermissionMap) => boolean;
9
+ hasProjectRole: (roleName: Role['name']) => boolean;
10
+ hasProjectPermission: (permission: keyof ProjectPermissionMap) => boolean;
11
+ }
12
+ export declare function usePermissions(context: Ref<Context>): UsePermissions;
@@ -8,6 +8,7 @@ type RefObject<T> = {
8
8
  export declare function unrefObject<T extends object>(obj: RefObject<T>): UnwrapRef<T>;
9
9
  export interface CommsToolbar {
10
10
  title: Ref<string | undefined>;
11
+ subtitle: Ref<string | undefined>;
11
12
  searchEnabled: Ref<boolean>;
12
13
  search: Ref<string>;
13
14
  menu: Ref<ToolbarItem[]>;
package/package.json CHANGED
@@ -1,16 +1,9 @@
1
1
  {
2
2
  "name": "@antcde/vue-utils",
3
3
  "type": "module",
4
- "version": "0.2.11",
4
+ "version": "0.2.12-rc.64ce643",
5
5
  "description": "Helper to use ANT Comms in Vue 3",
6
6
  "author": "CollaborAll",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://npm.antcde.io"
10
- },
11
- "publishConfig": {
12
- "registry": "https://npm.antcde.io"
13
- },
14
7
  "exports": {
15
8
  ".": {
16
9
  "types": "./dist/types/index.d.ts",
@@ -25,29 +18,29 @@
25
18
  "README.md",
26
19
  "dist"
27
20
  ],
21
+ "scripts": {
22
+ "build": "pnpm clean && vite build",
23
+ "build:watch": "vite build --watch",
24
+ "type-check": "vue-tsc --noEmit",
25
+ "clean": "pnpm dlx rimraf dist"
26
+ },
28
27
  "peerDependencies": {
29
28
  "@vueuse/core": "^13.9.0",
29
+ "rxjs": "^7.0.0",
30
30
  "vue": "^3.5.10",
31
- "vue-i18n": "^11.1.12",
32
- "rxjs": "^7.0.0"
31
+ "vue-i18n": "^11.1.12"
33
32
  },
34
33
  "dependencies": {
35
- "@antcde/connect-ts": "0.4.14"
34
+ "@antcde/connect-ts": "workspace:*"
36
35
  },
37
36
  "devDependencies": {
37
+ "@tsconfig/node22": "^22.0.2",
38
+ "@types/node": "^22.0.0",
38
39
  "@vitejs/plugin-vue": "^6.0.1",
39
40
  "@vue/tsconfig": "^0.8.1",
40
- "typescript": "~5.3.3",
41
+ "typescript": "~5.9.3",
41
42
  "vite": "^7.1.10",
42
43
  "vite-plugin-dts": "^4.5.4",
43
- "vue-tsc": "^3.1.1",
44
- "@tsconfig/node22": "^22.0.2",
45
- "@types/node": "^22.0.0"
46
- },
47
- "scripts": {
48
- "build": "pnpm clean && vite build",
49
- "build:watch": "vite build --watch",
50
- "type-check": "vue-tsc --noEmit",
51
- "clean": "pnpm dlx rimraf dist"
44
+ "vue-tsc": "^3.1.1"
52
45
  }
53
- }
46
+ }