@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 +125 -101
- package/dist/types/index.d.ts +1 -0
- package/dist/types/useCommsHost.d.ts +2 -2
- package/dist/types/usePermissions.d.ts +12 -0
- package/dist/types/utils.d.ts +1 -0
- package/package.json +15 -22
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { useColorMode as
|
|
2
|
-
import { computed as
|
|
3
|
-
import { useI18n as
|
|
4
|
-
import { newCommsClient as
|
|
5
|
-
import { concat as
|
|
6
|
-
function
|
|
7
|
-
const
|
|
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
|
|
16
|
+
return n.value;
|
|
17
17
|
}
|
|
18
|
-
}), r =
|
|
19
|
-
switch (
|
|
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
|
-
|
|
28
|
+
s,
|
|
29
29
|
{ host: e, isDark: r },
|
|
30
|
-
|
|
30
|
+
L(n, ["state", "system", "store"])
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
const
|
|
35
|
-
return
|
|
36
|
-
() =>
|
|
37
|
-
(e) =>
|
|
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
|
-
),
|
|
39
|
+
), n;
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
const
|
|
43
|
-
get: () =>
|
|
44
|
-
set: (
|
|
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((
|
|
47
|
-
|
|
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:
|
|
49
|
+
context: n,
|
|
50
50
|
toolbar: J(e),
|
|
51
51
|
appState: r
|
|
52
52
|
}
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
|
-
function J(
|
|
56
|
-
const
|
|
57
|
-
title:
|
|
58
|
-
get: () =>
|
|
59
|
-
set: (
|
|
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
|
-
|
|
62
|
-
get: () =>
|
|
63
|
-
set: (
|
|
61
|
+
subtitle: u({
|
|
62
|
+
get: () => t.toolbar.get().subtitle,
|
|
63
|
+
set: (e) => t.toolbar.set((s) => ({ ...s, subtitle: e }))
|
|
64
64
|
}),
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
71
|
-
get: () => o.
|
|
72
|
-
set: (
|
|
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
|
|
82
|
+
return t.toolbar.pipe(w((e) => e.search.input ?? ""), G(), V(300)).forEach((e) => o.value = e), n;
|
|
76
83
|
}
|
|
77
|
-
function N(
|
|
78
|
-
const e =
|
|
79
|
-
|
|
80
|
-
|
|
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
|
|
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
|
|
85
|
-
const { context:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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((
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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((
|
|
108
|
-
const
|
|
109
|
-
c.isConnectionInitialized.subscribe((
|
|
110
|
-
const { unsubscribe:
|
|
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
|
-
...
|
|
113
|
-
client:
|
|
114
|
-
appState:
|
|
115
|
-
isConnectionInitialized:
|
|
116
|
-
unsubscribe:
|
|
117
|
-
signal:
|
|
118
|
-
closed:
|
|
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
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
() =>
|
|
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:
|
|
150
|
+
return { provideComms: o, injectComms: n };
|
|
128
151
|
}
|
|
129
|
-
function Q(
|
|
152
|
+
function Q(t, o, n) {
|
|
130
153
|
let e;
|
|
131
|
-
const
|
|
154
|
+
const s = () => (!e && (e = o()), e);
|
|
132
155
|
return [
|
|
133
|
-
(r) => (r.onUnmount(() =>
|
|
134
|
-
() =>
|
|
156
|
+
(r) => (r.onUnmount(() => n && e && n(e)), r.provide(t, s)),
|
|
157
|
+
() => W(t)()
|
|
135
158
|
];
|
|
136
159
|
}
|
|
137
|
-
function
|
|
138
|
-
const
|
|
139
|
-
return Object.assign(
|
|
140
|
-
execute: (...r) =>
|
|
141
|
-
executeDelayed:
|
|
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
|
|
145
|
-
let
|
|
146
|
-
const
|
|
147
|
-
return U(() =>
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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,
|
|
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:
|
|
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;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -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.
|
|
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": "
|
|
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.
|
|
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
|
+
}
|