@jskit-ai/users-web 0.1.4

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 (97) hide show
  1. package/package.descriptor.mjs +507 -0
  2. package/package.json +31 -0
  3. package/src/client/components/ConsoleSettingsClientElement.vue +24 -0
  4. package/src/client/components/MembersAdminClientElement.vue +404 -0
  5. package/src/client/components/ProfileClientElement.vue +242 -0
  6. package/src/client/components/UsersProfileSurfaceSwitchMenuItem.vue +39 -0
  7. package/src/client/components/UsersShellMenuLinkItem.vue +140 -0
  8. package/src/client/components/UsersSurfaceAwareMenuLinkItem.vue +87 -0
  9. package/src/client/components/UsersWorkspaceMembersMenuItem.vue +36 -0
  10. package/src/client/components/UsersWorkspacePermissionMenuItem.vue +90 -0
  11. package/src/client/components/UsersWorkspaceSelector.vue +237 -0
  12. package/src/client/components/UsersWorkspaceSettingsMenuItem.vue +39 -0
  13. package/src/client/components/UsersWorkspaceToolsWidget.vue +23 -0
  14. package/src/client/components/WorkspaceMembersClientElement.vue +663 -0
  15. package/src/client/components/WorkspaceSettingsClientElement.vue +230 -0
  16. package/src/client/components/WorkspacesClientElement.vue +514 -0
  17. package/src/client/composables/accountSettingsAvatarUploadRuntime.js +241 -0
  18. package/src/client/composables/accountSettingsInvitesRuntime.js +88 -0
  19. package/src/client/composables/accountSettingsRuntimeConstants.js +77 -0
  20. package/src/client/composables/accountSettingsRuntimeHelpers.js +75 -0
  21. package/src/client/composables/errorMessageHelpers.js +66 -0
  22. package/src/client/composables/internal/useOperationScope.js +144 -0
  23. package/src/client/composables/modelStateHelpers.js +49 -0
  24. package/src/client/composables/operationUiHelpers.js +121 -0
  25. package/src/client/composables/operationValidationHelpers.js +52 -0
  26. package/src/client/composables/refValueHelpers.js +19 -0
  27. package/src/client/composables/scopeHelpers.js +145 -0
  28. package/src/client/composables/useAccess.js +109 -0
  29. package/src/client/composables/useAccountSettingsRuntime.js +533 -0
  30. package/src/client/composables/useAddEdit.js +135 -0
  31. package/src/client/composables/useAddEditCore.js +137 -0
  32. package/src/client/composables/useBootstrapQuery.js +52 -0
  33. package/src/client/composables/useCommand.js +112 -0
  34. package/src/client/composables/useCommandCore.js +130 -0
  35. package/src/client/composables/useEndpointResource.js +104 -0
  36. package/src/client/composables/useFieldErrorBag.js +61 -0
  37. package/src/client/composables/useList.js +85 -0
  38. package/src/client/composables/useListCore.js +65 -0
  39. package/src/client/composables/usePagedCollection.js +125 -0
  40. package/src/client/composables/usePaths.js +108 -0
  41. package/src/client/composables/useRealtimeQueryInvalidation.js +105 -0
  42. package/src/client/composables/useScopeRuntime.js +107 -0
  43. package/src/client/composables/useSurfaceRouteContext.js +31 -0
  44. package/src/client/composables/useUiFeedback.js +96 -0
  45. package/src/client/composables/useView.js +89 -0
  46. package/src/client/composables/useViewCore.js +104 -0
  47. package/src/client/composables/useWorkspaceRouteContext.js +28 -0
  48. package/src/client/composables/useWorkspaceSurfaceId.js +43 -0
  49. package/src/client/index.js +7 -0
  50. package/src/client/lib/bootstrap.js +95 -0
  51. package/src/client/lib/httpClient.js +67 -0
  52. package/src/client/lib/menuIcons.js +192 -0
  53. package/src/client/lib/permissions.js +34 -0
  54. package/src/client/lib/profileSurfaceMenuLinks.js +142 -0
  55. package/src/client/lib/surfaceAccessPolicy.js +350 -0
  56. package/src/client/lib/theme.js +99 -0
  57. package/src/client/lib/workspaceLinkResolver.js +207 -0
  58. package/src/client/lib/workspaceSurfaceContext.js +82 -0
  59. package/src/client/lib/workspaceSurfacePaths.js +163 -0
  60. package/src/client/providers/UsersWebClientProvider.js +85 -0
  61. package/src/client/runtime/bootstrapPlacementRouteGuards.js +371 -0
  62. package/src/client/runtime/bootstrapPlacementRuntime.js +413 -0
  63. package/src/client/runtime/bootstrapPlacementRuntimeConstants.js +32 -0
  64. package/src/client/runtime/bootstrapPlacementRuntimeHelpers.js +157 -0
  65. package/src/client/support/contractGuards.js +34 -0
  66. package/src/client/support/realtimeWorkspace.js +12 -0
  67. package/src/client/support/runtimeNormalization.js +27 -0
  68. package/src/client/support/workspaceQueryKeys.js +15 -0
  69. package/templates/packages/main/src/client/components/AccountPendingInvitesCue.vue +162 -0
  70. package/templates/src/components/WorkspaceNotFoundCard.vue +33 -0
  71. package/templates/src/components/account/settings/AccountSettingsClientElement.vue +153 -0
  72. package/templates/src/components/account/settings/AccountSettingsInvitesSection.vue +77 -0
  73. package/templates/src/components/account/settings/AccountSettingsNotificationsSection.vue +55 -0
  74. package/templates/src/components/account/settings/AccountSettingsPreferencesSection.vue +125 -0
  75. package/templates/src/components/account/settings/AccountSettingsProfileSection.vue +94 -0
  76. package/templates/src/composables/useWorkspaceNotFoundState.js +48 -0
  77. package/templates/src/pages/account/index.vue +17 -0
  78. package/templates/src/pages/admin/members/index.vue +7 -0
  79. package/templates/src/pages/admin/workspace/settings/index.vue +16 -0
  80. package/templates/src/pages/console/settings/index.vue +16 -0
  81. package/templates/src/surfaces/admin/index.vue +29 -0
  82. package/templates/src/surfaces/admin/root.vue +20 -0
  83. package/templates/src/surfaces/app/index.vue +27 -0
  84. package/templates/src/surfaces/app/root.vue +20 -0
  85. package/test/bootstrap.test.js +38 -0
  86. package/test/bootstrapPlacementRuntime.test.js +991 -0
  87. package/test/errorMessageHelpers.test.js +28 -0
  88. package/test/exportsContract.test.js +39 -0
  89. package/test/menuIcons.test.js +33 -0
  90. package/test/permissions.test.js +35 -0
  91. package/test/profileSurfaceMenuLinks.test.js +207 -0
  92. package/test/refValueHelpers.test.js +14 -0
  93. package/test/scopeHelpers.test.js +57 -0
  94. package/test/surfaceAccessPolicy.test.js +129 -0
  95. package/test/theme.test.js +95 -0
  96. package/test/workspaceLinkResolver.test.js +61 -0
  97. package/test/workspaceSurfacePaths.test.js +39 -0
@@ -0,0 +1,140 @@
1
+ <script setup>
2
+ import { computed } from "vue";
3
+ import { useRoute } from "vue-router";
4
+ import { appendQueryString } from "@jskit-ai/kernel/shared/support";
5
+ import { isExternalLinkTarget, splitPathQueryHash } from "@jskit-ai/kernel/shared/support/linkPath";
6
+ import {
7
+ useWebPlacementContext,
8
+ resolveSurfaceNavigationTargetFromPlacementContext
9
+ } from "@jskit-ai/shell-web/client/placement";
10
+ import { resolveAccountSettingsPathFromPlacementContext } from "../lib/workspaceSurfacePaths.js";
11
+ import { resolveMenuLinkIcon } from "../lib/menuIcons.js";
12
+
13
+ const props = defineProps({
14
+ label: {
15
+ type: String,
16
+ default: ""
17
+ },
18
+ to: {
19
+ type: String,
20
+ default: ""
21
+ },
22
+ icon: {
23
+ type: String,
24
+ default: ""
25
+ },
26
+ disabled: {
27
+ type: Boolean,
28
+ default: false
29
+ }
30
+ });
31
+
32
+ const route = useRoute();
33
+ const { context: placementContext } = useWebPlacementContext();
34
+
35
+ function resolveFallbackReturnTo() {
36
+ if (typeof window !== "object" || !window || !window.location) {
37
+ return "/";
38
+ }
39
+ const pathname = String(window.location.pathname || "").trim() || "/";
40
+ const search = String(window.location.search || "").trim();
41
+ const hash = String(window.location.hash || "").trim();
42
+ return `${pathname}${search}${hash}`;
43
+ }
44
+
45
+ function resolveFallbackReturnToHref() {
46
+ if (typeof window !== "object" || !window || !window.location) {
47
+ return "/";
48
+ }
49
+ return String(window.location.href || "").trim() || resolveFallbackReturnTo();
50
+ }
51
+
52
+ function resolvePathnameFromLinkTarget(target = "") {
53
+ const normalizedTarget = String(target || "").trim();
54
+ if (!normalizedTarget) {
55
+ return "";
56
+ }
57
+
58
+ if (isExternalLinkTarget(normalizedTarget)) {
59
+ try {
60
+ const parsed = new URL(normalizedTarget);
61
+ return String(parsed.pathname || "").trim();
62
+ } catch {
63
+ return "";
64
+ }
65
+ }
66
+
67
+ return splitPathQueryHash(normalizedTarget).pathname;
68
+ }
69
+
70
+ const accountSettingsPathname = computed(() => {
71
+ const settingsPath = resolveAccountSettingsPathFromPlacementContext(placementContext.value);
72
+ return resolvePathnameFromLinkTarget(settingsPath);
73
+ });
74
+
75
+ const resolvedTo = computed(() => {
76
+ const target = String(props.to || "").trim();
77
+ if (!target) {
78
+ return "";
79
+ }
80
+
81
+ const targetPathname = resolvePathnameFromLinkTarget(target);
82
+ if (!targetPathname || targetPathname !== accountSettingsPathname.value) {
83
+ return target;
84
+ }
85
+ if (target.includes("returnTo=")) {
86
+ return target;
87
+ }
88
+
89
+ const accountSettingsTarget = resolveSurfaceNavigationTargetFromPlacementContext(placementContext.value, {
90
+ path: target,
91
+ surfaceId: "account"
92
+ });
93
+ const routeFullPath = String(route?.fullPath || "").trim();
94
+ const routePath = String(route?.path || "").trim();
95
+ const returnTo = accountSettingsTarget.sameOrigin
96
+ ? routeFullPath || routePath || resolveFallbackReturnTo()
97
+ : resolveFallbackReturnToHref();
98
+ const queryParams = new URLSearchParams({
99
+ returnTo
100
+ });
101
+
102
+ return appendQueryString(target, queryParams.toString());
103
+ });
104
+
105
+ const resolvedNavigationTarget = computed(() => {
106
+ const target = String(resolvedTo.value || "").trim();
107
+ if (!target) {
108
+ return {
109
+ href: "",
110
+ sameOrigin: true
111
+ };
112
+ }
113
+
114
+ const navigationTarget = resolveSurfaceNavigationTargetFromPlacementContext(placementContext.value, {
115
+ path: target
116
+ });
117
+ return {
118
+ href: navigationTarget.href,
119
+ sameOrigin: navigationTarget.sameOrigin
120
+ };
121
+ });
122
+
123
+ const resolvedIcon = computed(() =>
124
+ resolveMenuLinkIcon({
125
+ icon: props.icon,
126
+ label: props.label,
127
+ to: resolvedTo.value
128
+ })
129
+ );
130
+ </script>
131
+
132
+ <template>
133
+ <v-list-item
134
+ :title="props.label"
135
+ :to="resolvedNavigationTarget.sameOrigin ? resolvedNavigationTarget.href : undefined"
136
+ :href="resolvedNavigationTarget.sameOrigin ? undefined : resolvedNavigationTarget.href"
137
+ :prepend-icon="resolvedIcon || undefined"
138
+ :disabled="props.disabled"
139
+ />
140
+ </template>
@@ -0,0 +1,87 @@
1
+ <script setup>
2
+ import { computed } from "vue";
3
+ import { useWebPlacementContext } from "@jskit-ai/shell-web/client/placement";
4
+ import { usePaths } from "../composables/usePaths.js";
5
+ import { surfaceRequiresWorkspaceFromPlacementContext } from "../lib/workspaceSurfaceContext.js";
6
+ import { resolveMenuLinkIcon } from "../lib/menuIcons.js";
7
+
8
+ const props = defineProps({
9
+ label: {
10
+ type: String,
11
+ default: ""
12
+ },
13
+ to: {
14
+ type: String,
15
+ default: ""
16
+ },
17
+ icon: {
18
+ type: String,
19
+ default: ""
20
+ },
21
+ surface: {
22
+ type: String,
23
+ default: ""
24
+ },
25
+ workspaceSuffix: {
26
+ type: String,
27
+ default: "/"
28
+ },
29
+ nonWorkspaceSuffix: {
30
+ type: String,
31
+ default: "/"
32
+ },
33
+ disabled: {
34
+ type: Boolean,
35
+ default: false
36
+ }
37
+ });
38
+
39
+ const paths = usePaths();
40
+ const { context: placementContext } = useWebPlacementContext();
41
+
42
+ const targetSurfaceId = computed(() => {
43
+ const explicitSurface = String(props.surface || "").trim().toLowerCase();
44
+ if (explicitSurface && explicitSurface !== "*") {
45
+ return explicitSurface;
46
+ }
47
+
48
+ return String(paths.currentSurfaceId.value || "").trim().toLowerCase();
49
+ });
50
+
51
+ const resolvedTo = computed(() => {
52
+ const explicitTo = String(props.to || "").trim();
53
+ if (explicitTo) {
54
+ return explicitTo;
55
+ }
56
+
57
+ const workspaceRequired = surfaceRequiresWorkspaceFromPlacementContext(
58
+ placementContext.value,
59
+ targetSurfaceId.value
60
+ );
61
+ const suffix = workspaceRequired ? props.workspaceSuffix : props.nonWorkspaceSuffix;
62
+ const normalizedSuffix = String(suffix || "/").trim() || "/";
63
+
64
+ return paths.page(normalizedSuffix, {
65
+ surface: targetSurfaceId.value,
66
+ mode: "auto"
67
+ });
68
+ });
69
+
70
+ const resolvedIcon = computed(() =>
71
+ resolveMenuLinkIcon({
72
+ icon: props.icon,
73
+ label: props.label,
74
+ to: resolvedTo.value
75
+ })
76
+ );
77
+ </script>
78
+
79
+ <template>
80
+ <v-list-item
81
+ v-if="resolvedTo"
82
+ :title="props.label"
83
+ :to="resolvedTo"
84
+ :prepend-icon="resolvedIcon || undefined"
85
+ :disabled="props.disabled"
86
+ />
87
+ </template>
@@ -0,0 +1,36 @@
1
+ <script setup>
2
+ import { mdiAccountGroupOutline } from "@mdi/js";
3
+ import UsersWorkspacePermissionMenuItem from "./UsersWorkspacePermissionMenuItem.vue";
4
+
5
+ const props = defineProps({
6
+ label: {
7
+ type: String,
8
+ default: "Members"
9
+ },
10
+ to: {
11
+ type: String,
12
+ default: ""
13
+ },
14
+ icon: {
15
+ type: String,
16
+ default: mdiAccountGroupOutline
17
+ },
18
+ surface: {
19
+ type: String,
20
+ default: "*"
21
+ }
22
+ });
23
+
24
+ const MEMBERS_MENU_PERMISSIONS = Object.freeze(["workspace.members.view", "workspace.members.manage"]);
25
+ </script>
26
+
27
+ <template>
28
+ <UsersWorkspacePermissionMenuItem
29
+ :label="props.label"
30
+ :to="props.to"
31
+ :icon="props.icon"
32
+ :surface="props.surface"
33
+ path="/members"
34
+ :permissions="MEMBERS_MENU_PERMISSIONS"
35
+ />
36
+ </template>
@@ -0,0 +1,90 @@
1
+ <script setup>
2
+ import { computed } from "vue";
3
+ import { useSurfaceRouteContext } from "../composables/useSurfaceRouteContext.js";
4
+ import { hasPermission, normalizePermissionList } from "../lib/permissions.js";
5
+ import { usePaths } from "../composables/usePaths.js";
6
+
7
+ const props = defineProps({
8
+ label: {
9
+ type: String,
10
+ default: ""
11
+ },
12
+ to: {
13
+ type: String,
14
+ default: ""
15
+ },
16
+ icon: {
17
+ type: String,
18
+ default: ""
19
+ },
20
+ surface: {
21
+ type: String,
22
+ default: "*"
23
+ },
24
+ path: {
25
+ type: String,
26
+ default: "/"
27
+ },
28
+ permissions: {
29
+ type: [Array, String],
30
+ default: () => []
31
+ }
32
+ });
33
+
34
+ const { placementContext, currentSurfaceId } = useSurfaceRouteContext();
35
+ const paths = usePaths();
36
+
37
+ function normalizeRequiredPermissions(value) {
38
+ if (Array.isArray(value)) {
39
+ return value
40
+ .map((entry) => String(entry || "").trim())
41
+ .filter(Boolean);
42
+ }
43
+
44
+ const normalized = String(value || "").trim();
45
+ if (!normalized) {
46
+ return [];
47
+ }
48
+
49
+ return [normalized];
50
+ }
51
+
52
+ const requiredPermissions = computed(() => normalizeRequiredPermissions(props.permissions));
53
+
54
+ const canView = computed(() => {
55
+ if (requiredPermissions.value.length < 1) {
56
+ return true;
57
+ }
58
+
59
+ const permissions = normalizePermissionList(placementContext.value?.permissions);
60
+ return requiredPermissions.value.some((permission) => hasPermission(permissions, permission));
61
+ });
62
+
63
+ const resolvedTo = computed(() => {
64
+ const explicitTo = String(props.to || "").trim();
65
+ if (explicitTo) {
66
+ return explicitTo;
67
+ }
68
+
69
+ const explicitSurface = String(props.surface || "").trim().toLowerCase();
70
+ const targetSurfaceId =
71
+ explicitSurface && explicitSurface !== "*"
72
+ ? explicitSurface
73
+ : String(currentSurfaceId.value || "").trim().toLowerCase();
74
+ const targetPath = String(props.path || "/").trim() || "/";
75
+
76
+ return paths.page(targetPath, {
77
+ surface: targetSurfaceId,
78
+ mode: "auto"
79
+ });
80
+ });
81
+ </script>
82
+
83
+ <template>
84
+ <v-list-item
85
+ v-if="canView && resolvedTo"
86
+ :title="props.label"
87
+ :to="resolvedTo"
88
+ :prepend-icon="props.icon || undefined"
89
+ />
90
+ </template>
@@ -0,0 +1,237 @@
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/users-core/shared/tenancyProfile";
10
+ import { mdiBriefcaseOutline } from "@mdi/js";
11
+ import { findWorkspaceBySlug, normalizeWorkspaceEntry, normalizeWorkspaceList } from "../lib/bootstrap.js";
12
+ import { usePaths } from "../composables/usePaths.js";
13
+ import {
14
+ resolveSurfaceSwitchTargetsFromPlacementContext,
15
+ surfaceRequiresWorkspaceFromPlacementContext
16
+ } from "../lib/workspaceSurfaceContext.js";
17
+ import {
18
+ resolveWorkspaceSurfaceIdFromPlacementPathname,
19
+ extractWorkspaceSlugFromSurfacePathname
20
+ } from "../lib/workspaceSurfacePaths.js";
21
+
22
+ const props = defineProps({
23
+ surface: {
24
+ type: String,
25
+ default: "*"
26
+ },
27
+ allowOnNonWorkspaceSurface: {
28
+ type: Boolean,
29
+ default: false
30
+ },
31
+ targetSurfaceId: {
32
+ type: String,
33
+ default: ""
34
+ }
35
+ });
36
+
37
+ const navigatingToWorkspace = ref("");
38
+ const errorMessage = ref("");
39
+ const route = useRoute();
40
+ const router = useRouter();
41
+ const { context: placementContext } = useWebPlacementContext();
42
+ const paths = usePaths();
43
+
44
+ function resolveBrowserPath() {
45
+ if (typeof window !== "object" || !window || !window.location) {
46
+ return "/";
47
+ }
48
+ const pathname = String(window.location.pathname || "").trim();
49
+ return pathname || "/";
50
+ }
51
+
52
+ const currentPath = computed(() => {
53
+ const routePath = String(route?.path || "").trim();
54
+ if (routePath) {
55
+ return routePath;
56
+ }
57
+ return resolveBrowserPath();
58
+ });
59
+
60
+ const currentSurfaceId = computed(() => {
61
+ return (
62
+ resolveWorkspaceSurfaceIdFromPlacementPathname(placementContext.value, currentPath.value) ||
63
+ resolveSurfaceIdFromPlacementPathname(placementContext.value, currentPath.value) ||
64
+ props.surface
65
+ );
66
+ });
67
+
68
+ const targetSurfaceId = computed(() => String(props.targetSurfaceId || "").trim().toLowerCase());
69
+ const workspaceSwitchSurfaceId = computed(() => {
70
+ const normalizedCurrentSurfaceId = String(currentSurfaceId.value || "").trim().toLowerCase();
71
+ if (
72
+ normalizedCurrentSurfaceId &&
73
+ surfaceRequiresWorkspaceFromPlacementContext(placementContext.value, normalizedCurrentSurfaceId)
74
+ ) {
75
+ return normalizedCurrentSurfaceId;
76
+ }
77
+
78
+ if (targetSurfaceId.value) {
79
+ return targetSurfaceId.value;
80
+ }
81
+
82
+ const targets = resolveSurfaceSwitchTargetsFromPlacementContext(placementContext.value, normalizedCurrentSurfaceId);
83
+ return String(targets.workspaceSurfaceId || "").trim().toLowerCase();
84
+ });
85
+
86
+ const routeWorkspaceSlug = computed(() => {
87
+ return String(
88
+ extractWorkspaceSlugFromSurfacePathname(
89
+ placementContext.value,
90
+ currentSurfaceId.value,
91
+ currentPath.value
92
+ ) || ""
93
+ ).trim();
94
+ });
95
+
96
+ const authenticated = computed(() => Boolean(placementContext.value?.auth?.authenticated));
97
+ const workspaces = computed(() => normalizeWorkspaceList(placementContext.value?.workspaces));
98
+ const activeWorkspace = computed(() => {
99
+ const workspaceFromRoute = findWorkspaceBySlug(workspaces.value, routeWorkspaceSlug.value);
100
+ if (workspaceFromRoute) {
101
+ return workspaceFromRoute;
102
+ }
103
+
104
+ return normalizeWorkspaceEntry(placementContext.value?.workspace);
105
+ });
106
+
107
+ async function navigateToWorkspace(slug) {
108
+ const normalizedSlug = String(slug || "").trim();
109
+ if (!normalizedSlug) {
110
+ return;
111
+ }
112
+ if (navigatingToWorkspace.value) {
113
+ return;
114
+ }
115
+ if (!workspaceSwitchSurfaceId.value) {
116
+ errorMessage.value = "Workspace selector target surface is not configured.";
117
+ return;
118
+ }
119
+ if (!workspaceSwitchSurfaceRequiresWorkspace.value) {
120
+ errorMessage.value = "Workspace selector target surface must require a workspace.";
121
+ return;
122
+ }
123
+
124
+ const targetPath = paths.page("/", {
125
+ surface: workspaceSwitchSurfaceId.value,
126
+ workspaceSlug: normalizedSlug,
127
+ mode: "workspace"
128
+ });
129
+ if (!targetPath) {
130
+ errorMessage.value = "Workspace selector target surface is not configured.";
131
+ return;
132
+ }
133
+ const navigationTarget = resolveSurfaceNavigationTargetFromPlacementContext(placementContext.value, {
134
+ path: targetPath,
135
+ surfaceId: workspaceSwitchSurfaceId.value
136
+ });
137
+
138
+ navigatingToWorkspace.value = normalizedSlug;
139
+ errorMessage.value = "";
140
+
141
+ try {
142
+ if (currentPath.value !== targetPath || !navigationTarget.sameOrigin) {
143
+ if (navigationTarget.sameOrigin && router && typeof router.push === "function") {
144
+ await router.push(navigationTarget.href);
145
+ } else if (typeof window === "object" && window && window.location) {
146
+ window.location.assign(navigationTarget.href);
147
+ return;
148
+ } else {
149
+ throw new Error("Router is unavailable.");
150
+ }
151
+ }
152
+ } catch (error) {
153
+ const message = String(error?.message || "Unable to switch workspace.").trim();
154
+ errorMessage.value = message;
155
+ } finally {
156
+ navigatingToWorkspace.value = "";
157
+ }
158
+ }
159
+
160
+ const tenancyMode = computed(() => String(placementContext.value?.surfaceConfig?.tenancyMode || "").trim().toLowerCase());
161
+ const tenancyAllowsWorkspaceRouting = computed(() => tenancyMode.value !== TENANCY_MODE_NONE);
162
+
163
+ const surfaceRequiresWorkspace = computed(() =>
164
+ surfaceRequiresWorkspaceFromPlacementContext(placementContext.value, currentSurfaceId.value)
165
+ );
166
+ const workspaceSwitchSurfaceRequiresWorkspace = computed(() =>
167
+ surfaceRequiresWorkspaceFromPlacementContext(placementContext.value, workspaceSwitchSurfaceId.value)
168
+ );
169
+ const selectorSurfaceAllowed = computed(() => {
170
+ if (surfaceRequiresWorkspace.value) {
171
+ return true;
172
+ }
173
+ return props.allowOnNonWorkspaceSurface === true;
174
+ });
175
+
176
+ const isVisible = computed(
177
+ () =>
178
+ Boolean(workspaceSwitchSurfaceId.value) &&
179
+ workspaceSwitchSurfaceRequiresWorkspace.value &&
180
+ selectorSurfaceAllowed.value &&
181
+ tenancyAllowsWorkspaceRouting.value &&
182
+ authenticated.value &&
183
+ workspaces.value.length > 0
184
+ );
185
+
186
+ const activeWorkspaceLabel = computed(() => {
187
+ const active = activeWorkspace.value || null;
188
+ if (active?.name) {
189
+ return active.name;
190
+ }
191
+ return "Workspace";
192
+ });
193
+
194
+ </script>
195
+
196
+ <template>
197
+ <v-menu v-if="isVisible" location="bottom start" offset="8">
198
+ <template #activator="{ props: activatorProps }">
199
+ <v-btn
200
+ v-bind="activatorProps"
201
+ variant="text"
202
+ class="text-none"
203
+ :prepend-icon="mdiBriefcaseOutline"
204
+ >
205
+ {{ activeWorkspaceLabel }}
206
+ </v-btn>
207
+ </template>
208
+
209
+ <v-list density="comfortable" min-width="280">
210
+ <v-list-subheader>Workspaces</v-list-subheader>
211
+ <v-list-item
212
+ v-for="workspace in workspaces"
213
+ :key="workspace.id"
214
+ :title="workspace.name"
215
+ :subtitle="`/${workspace.slug}`"
216
+ :active="workspace.slug === activeWorkspace?.slug"
217
+ :disabled="Boolean(navigatingToWorkspace)"
218
+ @click="navigateToWorkspace(workspace.slug)"
219
+ >
220
+ <template #prepend>
221
+ <v-avatar size="24" color="primary" variant="tonal">
222
+ <span class="text-caption">{{ String(workspace.name || "W").slice(0, 1).toUpperCase() }}</span>
223
+ </v-avatar>
224
+ </template>
225
+ <template #append>
226
+ <v-progress-circular
227
+ v-if="navigatingToWorkspace === workspace.slug"
228
+ indeterminate
229
+ size="16"
230
+ width="2"
231
+ />
232
+ </template>
233
+ </v-list-item>
234
+ <v-list-item v-if="errorMessage" :subtitle="errorMessage" />
235
+ </v-list>
236
+ </v-menu>
237
+ </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,23 @@
1
+ <script setup>
2
+ import ShellOutlet from "@jskit-ai/shell-web/client/components/ShellOutlet";
3
+ import { mdiCogOutline } from "@mdi/js";
4
+ </script>
5
+
6
+ <template>
7
+ <v-menu location="bottom end" offset="10" eager>
8
+ <template #activator="{ props: activatorProps }">
9
+ <v-btn
10
+ v-bind="activatorProps"
11
+ icon
12
+ variant="text"
13
+ aria-label="Workspace tools"
14
+ >
15
+ <v-icon :icon="mdiCogOutline" />
16
+ </v-btn>
17
+ </template>
18
+
19
+ <v-list min-width="220" density="comfortable" class="py-1">
20
+ <ShellOutlet host="workspace-tools" position="primary-menu" />
21
+ </v-list>
22
+ </v-menu>
23
+ </template>