@jskit-ai/workspaces-web 0.1.13 → 0.1.15

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.
Files changed (48) hide show
  1. package/package.descriptor.mjs +61 -25
  2. package/package.json +13 -3
  3. package/src/client/account-settings/accountSettingsInvitesRuntime.js +88 -0
  4. package/src/client/account-settings/useAccountSettingsInvitesSectionRuntime.js +217 -0
  5. package/src/client/components/AccountSettingsInvitesSection.vue +72 -0
  6. package/src/client/components/MembersAdminClientElement.vue +400 -0
  7. package/src/client/components/UsersProfileSurfaceSwitchMenuItem.vue +39 -0
  8. package/src/client/components/UsersWorkspaceMembersMenuItem.vue +36 -0
  9. package/src/client/components/UsersWorkspacePermissionMenuItem.vue +89 -0
  10. package/src/client/components/UsersWorkspaceSelector.vue +242 -0
  11. package/src/client/components/UsersWorkspaceSettingsMenuItem.vue +39 -0
  12. package/src/client/components/UsersWorkspaceToolsWidget.vue +12 -0
  13. package/src/client/components/WorkspaceMembersClientElement.vue +657 -0
  14. package/src/client/components/WorkspaceProfileClientElement.vue +116 -0
  15. package/src/client/components/WorkspaceSettingsClientElement.vue +102 -0
  16. package/src/client/components/WorkspaceSettingsFieldsClientElement.vue +265 -0
  17. package/src/client/components/WorkspacesClientElement.vue +540 -0
  18. package/src/client/composables/useBootstrapQuery.js +52 -0
  19. package/src/client/composables/useWorkspaceRouteContext.js +28 -0
  20. package/src/client/composables/useWorkspaceSurfaceId.js +43 -0
  21. package/src/client/index.js +1 -0
  22. package/src/client/lib/bootstrap.js +59 -0
  23. package/src/client/lib/httpClient.js +10 -0
  24. package/src/client/lib/permissions.js +27 -0
  25. package/src/client/lib/profileSurfaceMenuLinks.js +163 -0
  26. package/src/client/lib/surfaceAccessPolicy.js +350 -0
  27. package/src/client/lib/theme.js +332 -0
  28. package/src/client/lib/workspaceLinkResolver.js +207 -0
  29. package/src/client/lib/workspaceSurfaceContext.js +82 -0
  30. package/src/client/lib/workspaceSurfacePaths.js +163 -0
  31. package/src/client/providers/WorkspacesWebClientProvider.js +59 -2
  32. package/src/client/runtime/bootstrapPlacementRouteGuards.js +371 -0
  33. package/src/client/runtime/bootstrapPlacementRuntime.js +463 -0
  34. package/src/client/runtime/bootstrapPlacementRuntimeConstants.js +28 -0
  35. package/src/client/runtime/bootstrapPlacementRuntimeHelpers.js +147 -0
  36. package/src/client/support/realtimeWorkspace.js +21 -0
  37. package/src/client/support/runtimeNormalization.js +23 -0
  38. package/src/client/support/workspaceQueryKeys.js +15 -0
  39. package/src/shared/toolsOutletContracts.js +9 -0
  40. package/templates/src/pages/admin/members/index.vue +1 -1
  41. package/test/bootstrapPlacementRuntime.test.js +1095 -0
  42. package/test/exportsContract.test.js +2 -1
  43. package/test/profileSurfaceMenuLinks.test.js +208 -0
  44. package/test/settingsPlacementContract.test.js +19 -1
  45. package/test/surfaceAccessPolicy.test.js +129 -0
  46. package/test/theme.test.js +101 -0
  47. package/test/workspaceLinkResolver.test.js +61 -0
  48. package/test/workspaceSurfacePaths.test.js +39 -0
@@ -0,0 +1,242 @@
1
+ <script setup>
2
+ import { computed, ref } from "vue";
3
+ import { useRoute, useRouter } from "vue-router";
4
+ import {
5
+ useWebPlacementContext,
6
+ resolveSurfaceIdFromPlacementPathname,
7
+ resolveSurfaceNavigationTargetFromPlacementContext
8
+ } from "@jskit-ai/shell-web/client/placement";
9
+ import { TENANCY_MODE_NONE } from "@jskit-ai/workspaces-core/shared/tenancyProfile";
10
+ import { mdiBriefcaseOutline } from "@mdi/js";
11
+ import { findWorkspaceBySlug, normalizeWorkspaceEntry, normalizeWorkspaceList } from "../lib/bootstrap.js";
12
+ import { usePaths } from "@jskit-ai/users-web/client/composables/usePaths";
13
+ import { resolveSurfaceSwitchTargetsFromPlacementContext, surfaceRequiresWorkspaceFromPlacementContext } from "../lib/workspaceSurfaceContext.js";
14
+ import { resolveWorkspaceSurfaceIdFromPlacementPathname, extractWorkspaceSlugFromSurfacePathname } from "../lib/workspaceSurfacePaths.js";
15
+
16
+ const props = defineProps({
17
+ surface: {
18
+ type: String,
19
+ default: "*"
20
+ },
21
+ allowOnNonWorkspaceSurface: {
22
+ type: Boolean,
23
+ default: false
24
+ },
25
+ targetSurfaceId: {
26
+ type: String,
27
+ default: ""
28
+ }
29
+ });
30
+
31
+ const navigatingToWorkspace = ref("");
32
+ const errorMessage = ref("");
33
+ const route = useRoute();
34
+ const router = useRouter();
35
+ const { context: placementContext } = useWebPlacementContext();
36
+ const paths = usePaths();
37
+
38
+ function resolveBrowserPath() {
39
+ if (typeof window !== "object" || !window || !window.location) {
40
+ return "/";
41
+ }
42
+ const pathname = String(window.location.pathname || "").trim();
43
+ return pathname || "/";
44
+ }
45
+
46
+ const currentPath = computed(() => {
47
+ const routePath = String(route?.path || "").trim();
48
+ if (routePath) {
49
+ return routePath;
50
+ }
51
+ return resolveBrowserPath();
52
+ });
53
+
54
+ const currentSurfaceId = computed(() => {
55
+ return (
56
+ resolveWorkspaceSurfaceIdFromPlacementPathname(placementContext.value, currentPath.value) ||
57
+ resolveSurfaceIdFromPlacementPathname(placementContext.value, currentPath.value) ||
58
+ props.surface
59
+ );
60
+ });
61
+
62
+ const targetSurfaceId = computed(() => String(props.targetSurfaceId || "").trim().toLowerCase());
63
+ const workspaceSwitchSurfaceId = computed(() => {
64
+ const normalizedCurrentSurfaceId = String(currentSurfaceId.value || "").trim().toLowerCase();
65
+ if (
66
+ normalizedCurrentSurfaceId &&
67
+ surfaceRequiresWorkspaceFromPlacementContext(placementContext.value, normalizedCurrentSurfaceId)
68
+ ) {
69
+ return normalizedCurrentSurfaceId;
70
+ }
71
+
72
+ if (targetSurfaceId.value) {
73
+ return targetSurfaceId.value;
74
+ }
75
+
76
+ const targets = resolveSurfaceSwitchTargetsFromPlacementContext(placementContext.value, normalizedCurrentSurfaceId);
77
+ return String(targets.workspaceSurfaceId || "").trim().toLowerCase();
78
+ });
79
+
80
+ const routeWorkspaceSlug = computed(() => {
81
+ return String(
82
+ extractWorkspaceSlugFromSurfacePathname(
83
+ placementContext.value,
84
+ currentSurfaceId.value,
85
+ currentPath.value
86
+ ) || ""
87
+ ).trim();
88
+ });
89
+
90
+ const authenticated = computed(() => Boolean(placementContext.value?.auth?.authenticated));
91
+ const workspaces = computed(() => normalizeWorkspaceList(placementContext.value?.workspaces));
92
+ const activeWorkspace = computed(() => {
93
+ const workspaceFromRoute = findWorkspaceBySlug(workspaces.value, routeWorkspaceSlug.value);
94
+ if (workspaceFromRoute) {
95
+ return workspaceFromRoute;
96
+ }
97
+
98
+ return normalizeWorkspaceEntry(placementContext.value?.workspace);
99
+ });
100
+
101
+ async function navigateToWorkspace(slug) {
102
+ const normalizedSlug = String(slug || "").trim();
103
+ if (!normalizedSlug) {
104
+ return;
105
+ }
106
+ if (navigatingToWorkspace.value) {
107
+ return;
108
+ }
109
+ if (!workspaceSwitchSurfaceId.value) {
110
+ errorMessage.value = "Workspace selector target surface is not configured.";
111
+ return;
112
+ }
113
+ if (!workspaceSwitchSurfaceRequiresWorkspace.value) {
114
+ errorMessage.value = "Workspace selector target surface must require a workspace.";
115
+ return;
116
+ }
117
+
118
+ const targetPath = paths.page("/", {
119
+ surface: workspaceSwitchSurfaceId.value,
120
+ workspaceSlug: normalizedSlug,
121
+ mode: "workspace"
122
+ });
123
+ if (!targetPath) {
124
+ errorMessage.value = "Workspace selector target surface is not configured.";
125
+ return;
126
+ }
127
+ const navigationTarget = resolveSurfaceNavigationTargetFromPlacementContext(placementContext.value, {
128
+ path: targetPath,
129
+ surfaceId: workspaceSwitchSurfaceId.value
130
+ });
131
+
132
+ navigatingToWorkspace.value = normalizedSlug;
133
+ errorMessage.value = "";
134
+
135
+ try {
136
+ if (currentPath.value !== targetPath || !navigationTarget.sameOrigin) {
137
+ if (navigationTarget.sameOrigin && router && typeof router.push === "function") {
138
+ await router.push(navigationTarget.href);
139
+ } else if (typeof window === "object" && window && window.location) {
140
+ window.location.assign(navigationTarget.href);
141
+ return;
142
+ } else {
143
+ throw new Error("Router is unavailable.");
144
+ }
145
+ }
146
+ } catch (error) {
147
+ const message = String(error?.message || "Unable to switch workspace.").trim();
148
+ errorMessage.value = message;
149
+ } finally {
150
+ navigatingToWorkspace.value = "";
151
+ }
152
+ }
153
+
154
+ const tenancyMode = computed(() => String(placementContext.value?.surfaceConfig?.tenancyMode || "").trim().toLowerCase());
155
+ const tenancyAllowsWorkspaceRouting = computed(() => tenancyMode.value !== TENANCY_MODE_NONE);
156
+
157
+ const surfaceRequiresWorkspace = computed(() =>
158
+ surfaceRequiresWorkspaceFromPlacementContext(placementContext.value, currentSurfaceId.value)
159
+ );
160
+ const workspaceSwitchSurfaceRequiresWorkspace = computed(() =>
161
+ surfaceRequiresWorkspaceFromPlacementContext(placementContext.value, workspaceSwitchSurfaceId.value)
162
+ );
163
+ const selectorSurfaceAllowed = computed(() => {
164
+ if (surfaceRequiresWorkspace.value) {
165
+ return true;
166
+ }
167
+ return props.allowOnNonWorkspaceSurface === true;
168
+ });
169
+
170
+ const isVisible = computed(
171
+ () =>
172
+ Boolean(workspaceSwitchSurfaceId.value) &&
173
+ workspaceSwitchSurfaceRequiresWorkspace.value &&
174
+ selectorSurfaceAllowed.value &&
175
+ tenancyAllowsWorkspaceRouting.value &&
176
+ authenticated.value &&
177
+ workspaces.value.length > 0
178
+ );
179
+
180
+ const activeWorkspaceLabel = computed(() => {
181
+ const active = activeWorkspace.value || null;
182
+ if (active?.name) {
183
+ return active.name;
184
+ }
185
+ return "Workspace";
186
+ });
187
+
188
+ function workspaceAvatarStyle(workspace) {
189
+ const color = String(workspace?.color || "").trim();
190
+ if (!/^#[0-9a-fA-F]{6}$/.test(color)) {
191
+ return {};
192
+ }
193
+
194
+ return {
195
+ backgroundColor: color
196
+ };
197
+ }
198
+
199
+ </script>
200
+
201
+ <template>
202
+ <v-menu v-if="isVisible" location="bottom start" offset="8">
203
+ <template #activator="{ props: activatorProps }">
204
+ <v-btn
205
+ v-bind="activatorProps"
206
+ variant="text"
207
+ class="text-none"
208
+ :prepend-icon="mdiBriefcaseOutline"
209
+ >
210
+ {{ activeWorkspaceLabel }}
211
+ </v-btn>
212
+ </template>
213
+
214
+ <v-list density="comfortable" min-width="280">
215
+ <v-list-subheader>Workspaces</v-list-subheader>
216
+ <v-list-item
217
+ v-for="workspace in workspaces"
218
+ :key="workspace.id"
219
+ :title="workspace.name"
220
+ :subtitle="`/${workspace.slug}`"
221
+ :active="workspace.slug === activeWorkspace?.slug"
222
+ :disabled="Boolean(navigatingToWorkspace)"
223
+ @click="navigateToWorkspace(workspace.slug)"
224
+ >
225
+ <template #prepend>
226
+ <v-avatar size="24" color="primary" variant="tonal" :style="workspaceAvatarStyle(workspace)">
227
+ <span class="text-caption">{{ String(workspace.name || "W").slice(0, 1).toUpperCase() }}</span>
228
+ </v-avatar>
229
+ </template>
230
+ <template #append>
231
+ <v-progress-circular
232
+ v-if="navigatingToWorkspace === workspace.slug"
233
+ indeterminate
234
+ size="16"
235
+ width="2"
236
+ />
237
+ </template>
238
+ </v-list-item>
239
+ <v-list-item v-if="errorMessage" :subtitle="errorMessage" />
240
+ </v-list>
241
+ </v-menu>
242
+ </template>
@@ -0,0 +1,39 @@
1
+ <script setup>
2
+ import { mdiCogOutline } from "@mdi/js";
3
+ import UsersWorkspacePermissionMenuItem from "./UsersWorkspacePermissionMenuItem.vue";
4
+
5
+ const props = defineProps({
6
+ label: {
7
+ type: String,
8
+ default: "Workspace settings"
9
+ },
10
+ to: {
11
+ type: String,
12
+ default: ""
13
+ },
14
+ icon: {
15
+ type: String,
16
+ default: mdiCogOutline
17
+ },
18
+ surface: {
19
+ type: String,
20
+ default: "*"
21
+ }
22
+ });
23
+
24
+ const WORKSPACE_SETTINGS_MENU_PERMISSIONS = Object.freeze([
25
+ "workspace.settings.view",
26
+ "workspace.settings.update"
27
+ ]);
28
+ </script>
29
+
30
+ <template>
31
+ <UsersWorkspacePermissionMenuItem
32
+ :label="props.label"
33
+ :to="props.to"
34
+ :icon="props.icon"
35
+ :surface="props.surface"
36
+ path="/workspace/settings"
37
+ :permissions="WORKSPACE_SETTINGS_MENU_PERMISSIONS"
38
+ />
39
+ </template>
@@ -0,0 +1,12 @@
1
+ <script setup>
2
+ import ShellOutletMenuWidget from "@jskit-ai/shell-web/client/components/ShellOutletMenuWidget";
3
+ import { WORKSPACE_TOOLS_OUTLET } from "../../shared/toolsOutletContracts.js";
4
+ </script>
5
+
6
+ <template>
7
+ <ShellOutletMenuWidget
8
+ :target="WORKSPACE_TOOLS_OUTLET.target"
9
+ :default-link-component-token="WORKSPACE_TOOLS_OUTLET.defaultLinkComponentToken"
10
+ :aria-label="WORKSPACE_TOOLS_OUTLET.ariaLabel"
11
+ />
12
+ </template>