@antcde/vue-utils 0.2.10 → 0.2.12-rc.2d2bba7

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 C, useMagicKeys as I, whenever as f, watchDebounced as E, useAsyncState as L } from "@vueuse/core";
2
- import { computed as i, watch as h, ref as b, onBeforeUnmount as w, 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 v, map as S, distinctUntilChanged as V, debounceTime as W, tap as q, BehaviorSubject as x, 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,138 +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);
33
+ function se(t, o) {
34
+ const n = z(o);
35
35
  return h(
36
- () => {
37
- var e;
38
- return (e = o.context.value.user) == null ? void 0 : e.language;
39
- },
40
- (e) => t.locale.value = e ?? "en",
36
+ () => t.context.value.user?.language,
37
+ (e) => n.locale.value = e ?? "en",
41
38
  { immediate: !0 }
42
- ), t;
39
+ ), n;
43
40
  }
44
- function G(o, s) {
45
- const t = b({}), e = K({ parent: window.parent, connect: o }), a = b(""), r = i({
46
- get: () => a.value,
47
- 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)
48
45
  });
49
- return e.context.subscribe((u) => t.value = u), T(e.appState.get(), e.appState).subscribe((u) => a.value = u), N(e.signal, e, s), w(() => e.unsubscribe()), Object.assign(
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(
50
47
  C(e, ["context", "toolbar", "appState"]),
51
48
  {
52
- context: t,
49
+ context: n,
53
50
  toolbar: J(e),
54
51
  appState: r
55
52
  }
56
53
  );
57
54
  }
58
- function J(o) {
59
- const s = {
60
- title: i({
61
- get: () => o.toolbar.get().title,
62
- 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 }))
63
60
  }),
64
- searchEnabled: i({
65
- get: () => o.toolbar.get().search.enabled,
66
- 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 }))
67
64
  }),
68
- search: b(""),
69
- menu: i({
70
- get: () => o.toolbar.get().menu ?? [],
71
- 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 } }))
72
68
  }),
73
- isLoading: i({
74
- get: () => o.toolbar.get().isLoading,
75
- 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 }))
76
80
  })
77
81
  };
78
- return o.toolbar.pipe(S((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;
79
83
  }
80
- function N(o, s, t) {
81
- const e = I(), { ctrl: a, shift: r } = e, u = new _(), c = u.pipe(
82
- v(t ?? ((m) => Promise.resolve(m))),
83
- v((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))
84
88
  ).subscribe();
85
- return s.add(c), c.add(f(a, () => u.next({ hotkeys: { ctrl: !0 } }))), c.add(f(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;
86
90
  }
87
- function oe(o) {
88
- const { context: s } = o, t = new x({}), e = (n) => t.next(n(t.value)), a = b(), r = new x(void 0);
89
- h(a, (n) => r.next(n), { immediate: !0 });
90
- const u = r.asObservable().pipe(
91
- S((n) => n == null ? void 0 : n.contentWindow),
92
- F((n) => !!n)
93
- ), c = P({ ...o, contextChanges: t, windowChanges: u });
94
- Object.entries(s).map(([n, l]) => h(
95
- l,
96
- (d) => e((p) => ({ ...p, [n]: d })),
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 })),
97
99
  { immediate: !0 }
98
- )).forEach((n) => c.scope.add(n)), c.toolbar.subscribe((n) => {
99
- var d, p;
100
- const l = o.toolbar;
101
- l.title.value = n.title, l.searchEnabled.value = ((d = n.search) == null ? void 0 : d.enabled) ?? !1, l.search.value = (p = n.search) == null ? void 0 : p.input, l.menu.value = n.menu, l.isLoading.value = (n == null ? void 0 : n.isLoading) ?? !1;
102
- }), E(
103
- o.toolbar.search,
104
- (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),
105
107
  { immediate: !0, debounce: 100 }
106
108
  );
107
- const m = b(c.appState.get()), j = i({
108
- get: () => m.value,
109
- 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)
110
113
  });
111
- c.appState.changes.subscribe((n) => m.value = n);
112
- const g = b(!1);
113
- c.isConnectionInitialized.subscribe((n) => g.value = n), w(() => c.unsubscribe());
114
- const { unsubscribe: y, signal: k, closed: M } = 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;
115
118
  return {
116
- ...o,
117
- client: a,
118
- appState: j,
119
- isConnectionInitialized: g,
120
- unsubscribe: y,
121
- signal: k,
122
- closed: M
119
+ ...t,
120
+ client: s,
121
+ appState: l,
122
+ isConnectionInitialized: v,
123
+ unsubscribe: x,
124
+ signal: y,
125
+ closed: _
123
126
  };
124
127
  }
125
- function ne(o = "comms") {
126
- const [s, t] = Q(
127
- o,
128
- () => 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(),
129
148
  (e) => e.unsubscribe()
130
149
  );
131
- return { provideComms: s, injectComms: t };
150
+ return { provideComms: o, injectComms: n };
132
151
  }
133
- function Q(o, s, t) {
152
+ function Q(t, o, n) {
134
153
  let e;
135
- const a = () => (!e && (e = s()), e);
154
+ const s = () => (!e && (e = o()), e);
136
155
  return [
137
- (r) => (r.onUnmount(() => t && e && t(e)), r.provide(o, a)),
138
- () => z(o)()
156
+ (r) => (r.onUnmount(() => n && e && n(e)), r.provide(t, s)),
157
+ () => W(t)()
139
158
  ];
140
159
  }
141
- function se(o, s, t) {
142
- const a = L(o, s, { immediate: !1, ...t });
143
- return Object.assign(C(a, ["execute"]), {
144
- execute: (...r) => a.execute(void 0, ...r),
145
- 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
146
165
  });
147
166
  }
148
- function ae(o) {
149
- let s;
150
- const t = b(void 0);
151
- return U(() => s = o.signal.receive((e) => t.value = e)), D(() => s == null ? void 0 : s()), [H(t), () => s == null ? void 0 : 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?.()];
152
171
  }
153
172
  export {
154
- ee as useAntColorMode,
155
- te as useAntI18n,
156
- se as useApi,
157
- G as useCommsClient,
158
- oe as useCommsHost,
159
- ne as useCommsInjection,
160
- 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,
161
181
  Q as useSingleton
162
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,7 +1,6 @@
1
1
  import { BasicColorSchema, UseColorModeOptions, UseColorModeReturn } from '@vueuse/core';
2
2
  import { UseCommsClient } from './useCommsClient';
3
3
  import { Ref } from 'vue';
4
-
5
4
  export type UseAntColorModeOptions = UseColorModeOptions<BasicColorSchema>;
6
5
  export type UseAntColorModeReturn = UseColorModeReturn<BasicColorSchema> & {
7
6
  host: Ref<boolean | null | undefined>;
@@ -1,6 +1,5 @@
1
1
  import { Composer, UseI18nOptions } from 'vue-i18n';
2
2
  import { UseCommsClient } from './useCommsClient';
3
-
4
3
  export type UseAntI18nReturn = Composer;
5
4
  /**
6
5
  * Listens to the changing locale received from comms and translations will automatically refresh due to internal watcher.
@@ -1,8 +1,7 @@
1
1
  import { AntConnect, Client, Context, Signal } from '@antcde/connect-ts';
2
2
  import { ObservableInput } from 'rxjs';
3
- import { CommsToolbar } from './utils';
4
3
  import { Ref } from 'vue';
5
-
4
+ import { CommsToolbar } from './utils';
6
5
  export interface UseCommsClient extends Omit<Client, 'context' | 'toolbar' | 'appState'> {
7
6
  context: Ref<Context>;
8
7
  toolbar: CommsToolbar;
@@ -1,8 +1,7 @@
1
- import { AntConnect, License, Notepad, Notification, ProjectShort, SignalReceiver, SignalSender, Task, User } from '@antcde/connect-ts';
2
- import { CommsToolbar } from './utils';
1
+ import { AntConnect, LabelFilterState, License, Notepad, Notification, ProjectShort, SignalObserverFactory, SignalReceiver, SignalSender, Task, User } from '@antcde/connect-ts';
3
2
  import { SubscriptionLike } from 'rxjs';
4
3
  import { Ref } from 'vue';
5
-
4
+ import { CommsToolbar } from './utils';
6
5
  type Nullable<T> = NonNullable<T> | null | undefined;
7
6
  export interface CommsHostArgs {
8
7
  connect: AntConnect;
@@ -23,7 +22,9 @@ export interface CommsHostArgs {
23
22
  code: string;
24
23
  }>>;
25
24
  darkMode: Ref<Nullable<boolean>>;
25
+ selectedLabels: Ref<LabelFilterState>;
26
26
  };
27
+ newSignalObserver: SignalObserverFactory;
27
28
  }
28
29
  export interface UseCommsHost extends CommsHostArgs, SubscriptionLike {
29
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;
@@ -2,13 +2,13 @@ import { Signal, ToolbarItem } from '@antcde/connect-ts';
2
2
  import { UseAsyncStateOptions, UseAsyncStateReturn } from '@vueuse/core';
3
3
  import { DeepReadonly, FunctionPlugin, Ref, UnwrapRef, WatchStopHandle } from 'vue';
4
4
  import { UseCommsClient } from './useCommsClient';
5
-
6
5
  type RefObject<T> = {
7
6
  [K in keyof T]: T[K];
8
7
  };
9
8
  export declare function unrefObject<T extends object>(obj: RefObject<T>): UnwrapRef<T>;
10
9
  export interface CommsToolbar {
11
10
  title: Ref<string | undefined>;
11
+ subtitle: Ref<string | undefined>;
12
12
  searchEnabled: Ref<boolean>;
13
13
  search: Ref<string>;
14
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.10",
4
+ "version": "0.2.12-rc.2d2bba7",
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,26 +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
- "@vueuse/core": "^12.0.0",
28
+ "@vueuse/core": "^13.9.0",
29
+ "rxjs": "^7.0.0",
30
30
  "vue": "^3.5.10",
31
- "vue-i18n": "^10.0.1",
32
- "rxjs": "^7.0.0"
31
+ "vue-i18n": "^11.1.12"
33
32
  },
34
33
  "dependencies": {
35
- "@antcde/connect-ts": "0.4.10"
34
+ "@antcde/connect-ts": "workspace:*"
36
35
  },
37
36
  "devDependencies": {
38
- "@vitejs/plugin-vue": "^5.0.3",
39
- "@vue/tsconfig": "^0.5.1",
40
- "typescript": "~5.3.3",
41
- "vite": "^5.0.11",
42
- "vite-plugin-dts": "^3.7.0",
43
- "vue-tsc": "^1.8.27"
44
- },
45
- "scripts": {
46
- "build": "pnpm clean && vite build",
47
- "type-check": "vue-tsc --noEmit",
48
- "clean": "pnpm dlx rimraf dist"
37
+ "@tsconfig/node22": "^22.0.2",
38
+ "@types/node": "^22.0.0",
39
+ "@vitejs/plugin-vue": "^6.0.1",
40
+ "@vue/tsconfig": "^0.8.1",
41
+ "typescript": "~5.9.3",
42
+ "vite": "^7.1.10",
43
+ "vite-plugin-dts": "^4.5.4",
44
+ "vue-tsc": "^3.1.1"
49
45
  }
50
- }
46
+ }