@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 +199 -171
- package/dist/types/useCommsClient.d.ts +2 -2
- package/dist/types/useCommsHost.d.ts +2 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,182 +1,210 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { computed as
|
|
3
|
-
import { useI18n as
|
|
4
|
-
import { newCommsClient as
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
|
153
|
-
|
|
154
|
-
|
|
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
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
173
|
-
|
|
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.
|
|
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": "^
|
|
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.
|
|
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.
|
|
40
|
-
"@vue/tsconfig": "^0.
|
|
41
|
-
"typescript": "~
|
|
42
|
-
"vite": "^
|
|
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.
|
|
44
|
+
"vue-tsc": "^3.2.7"
|
|
45
45
|
}
|
|
46
46
|
}
|