@plexusone/shell 0.2.4 → 0.3.1

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.d.mts CHANGED
@@ -1,6 +1,6 @@
1
+ import * as react from 'react';
1
2
  import { ReactNode } from 'react';
2
3
  import { CatalogApp, SessionMembership } from '@plexusone/auth';
3
- import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
 
5
5
  /**
6
6
  * Navigation item
@@ -419,7 +419,7 @@ interface ShellProviderProps extends Partial<AppShellConfig> {
419
419
  /**
420
420
  * ShellProvider - Provides shell state to components
421
421
  */
422
- declare function ShellProvider({ children, defaultCollapsed, onNavigate, onCollapseChange, }: ShellProviderProps): react_jsx_runtime.JSX.Element;
422
+ declare function ShellProvider({ children, defaultCollapsed, onNavigate, onCollapseChange, }: ShellProviderProps): react.JSX.Element;
423
423
  /**
424
424
  * Hook to access shell context
425
425
  *
@@ -663,4 +663,5 @@ declare function carryPreferences(url: string, prefs?: CarriedPreferences): stri
663
663
  */
664
664
  declare function adoptCarriedPreferences(): void;
665
665
 
666
- export { AppShell, type AppShellConfig, type AppShellProps, type BreadcrumbItem, Breadcrumbs, type BreadcrumbsProps, COLLAPSED_KEY, type CarriedPreferences, type NavItem, type NavSection, Navbar, type NavbarProps, OrgSwitcher, type OrgSwitcherProps, OrganizationSwitcher, type OrganizationSwitcherProps, ProductSwitcher, type ProductSwitcherProps, ProfileMenu, type ProfileMenuProps, type ShellContextValue, ShellProvider, Sidebar, type SidebarProps, THEME_CHANGE_EVENT, THEME_STORAGE_KEY, type Theme, ThemeToggle, type UserAction, UserMenu, type UserMenuProps, adoptCarriedPreferences, applyStoredTheme, applyTheme, carryPreferences, initials, nextTheme, readStoredTheme, resolveTheme, switcherApps, useShell, useShellOptional, useTheme };
666
+ export { AppShell, Breadcrumbs, COLLAPSED_KEY, Navbar, OrgSwitcher, OrganizationSwitcher, ProductSwitcher, ProfileMenu, ShellProvider, Sidebar, THEME_CHANGE_EVENT, THEME_STORAGE_KEY, ThemeToggle, UserMenu, adoptCarriedPreferences, applyStoredTheme, applyTheme, carryPreferences, initials, nextTheme, readStoredTheme, resolveTheme, switcherApps, useShell, useShellOptional, useTheme };
667
+ export type { AppShellConfig, AppShellProps, BreadcrumbItem, BreadcrumbsProps, CarriedPreferences, NavItem, NavSection, NavbarProps, OrgSwitcherProps, OrganizationSwitcherProps, ProductSwitcherProps, ProfileMenuProps, ShellContextValue, SidebarProps, Theme, UserAction, UserMenuProps };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import * as react from 'react';
1
2
  import { ReactNode } from 'react';
2
3
  import { CatalogApp, SessionMembership } from '@plexusone/auth';
3
- import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
 
5
5
  /**
6
6
  * Navigation item
@@ -419,7 +419,7 @@ interface ShellProviderProps extends Partial<AppShellConfig> {
419
419
  /**
420
420
  * ShellProvider - Provides shell state to components
421
421
  */
422
- declare function ShellProvider({ children, defaultCollapsed, onNavigate, onCollapseChange, }: ShellProviderProps): react_jsx_runtime.JSX.Element;
422
+ declare function ShellProvider({ children, defaultCollapsed, onNavigate, onCollapseChange, }: ShellProviderProps): react.JSX.Element;
423
423
  /**
424
424
  * Hook to access shell context
425
425
  *
@@ -663,4 +663,5 @@ declare function carryPreferences(url: string, prefs?: CarriedPreferences): stri
663
663
  */
664
664
  declare function adoptCarriedPreferences(): void;
665
665
 
666
- export { AppShell, type AppShellConfig, type AppShellProps, type BreadcrumbItem, Breadcrumbs, type BreadcrumbsProps, COLLAPSED_KEY, type CarriedPreferences, type NavItem, type NavSection, Navbar, type NavbarProps, OrgSwitcher, type OrgSwitcherProps, OrganizationSwitcher, type OrganizationSwitcherProps, ProductSwitcher, type ProductSwitcherProps, ProfileMenu, type ProfileMenuProps, type ShellContextValue, ShellProvider, Sidebar, type SidebarProps, THEME_CHANGE_EVENT, THEME_STORAGE_KEY, type Theme, ThemeToggle, type UserAction, UserMenu, type UserMenuProps, adoptCarriedPreferences, applyStoredTheme, applyTheme, carryPreferences, initials, nextTheme, readStoredTheme, resolveTheme, switcherApps, useShell, useShellOptional, useTheme };
666
+ export { AppShell, Breadcrumbs, COLLAPSED_KEY, Navbar, OrgSwitcher, OrganizationSwitcher, ProductSwitcher, ProfileMenu, ShellProvider, Sidebar, THEME_CHANGE_EVENT, THEME_STORAGE_KEY, ThemeToggle, UserMenu, adoptCarriedPreferences, applyStoredTheme, applyTheme, carryPreferences, initials, nextTheme, readStoredTheme, resolveTheme, switcherApps, useShell, useShellOptional, useTheme };
667
+ export type { AppShellConfig, AppShellProps, BreadcrumbItem, BreadcrumbsProps, CarriedPreferences, NavItem, NavSection, NavbarProps, OrgSwitcherProps, OrganizationSwitcherProps, ProductSwitcherProps, ProfileMenuProps, ShellContextValue, SidebarProps, Theme, UserAction, UserMenuProps };
package/dist/index.js CHANGED
@@ -166,6 +166,7 @@ function adoptCarriedPreferences() {
166
166
 
167
167
  // src/ShellContext.tsx
168
168
  var import_react2 = require("react");
169
+ var import_auth = require("@plexusone/auth");
169
170
  var import_jsx_runtime = require("react/jsx-runtime");
170
171
  var ShellContext = (0, import_react2.createContext)(null);
171
172
  function ShellProvider({
@@ -217,7 +218,7 @@ function ShellProvider({
217
218
  if (onNavigate) {
218
219
  onNavigate(href);
219
220
  } else {
220
- window.location.assign(href);
221
+ (0, import_auth.navigateTo)(href);
221
222
  }
222
223
  setCurrentPath(href);
223
224
  setSidebarVisible(false);
@@ -266,7 +267,7 @@ function useShellOptional() {
266
267
  }
267
268
 
268
269
  // src/Sidebar.tsx
269
- var import_auth = require("@plexusone/auth");
270
+ var import_auth2 = require("@plexusone/auth");
270
271
  var import_tenant = require("@plexusone/tenant");
271
272
  var import_ui = require("@plexusone/ui");
272
273
  var import_jsx_runtime2 = require("react/jsx-runtime");
@@ -274,8 +275,8 @@ function mayView(tenant, roles) {
274
275
  if (!tenant) return false;
275
276
  if (tenant.isPlatformAdmin) return true;
276
277
  if (!tenant.membership) return false;
277
- const required = Math.min(...roles.map((r) => import_auth.ROLE_LEVELS[r]));
278
- return import_auth.ROLE_LEVELS[tenant.membership.role] >= required;
278
+ const required = Math.min(...roles.map((r) => import_auth2.ROLE_LEVELS[r]));
279
+ return import_auth2.ROLE_LEVELS[tenant.membership.role] >= required;
279
280
  }
280
281
  function NavItemComponent({
281
282
  item,
@@ -294,13 +295,13 @@ function NavItemComponent({
294
295
  if (onNavigate) {
295
296
  onNavigate(item.href);
296
297
  } else {
297
- window.location.assign(item.href);
298
+ (0, import_auth2.navigateTo)(item.href);
298
299
  }
299
300
  };
300
301
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
301
302
  "a",
302
303
  {
303
- href: item.href,
304
+ href: (0, import_auth2.safeHref)(item.href),
304
305
  onClick: handleClick,
305
306
  target: item.external ? "_blank" : void 0,
306
307
  rel: item.external ? "noopener noreferrer" : void 0,
@@ -459,7 +460,7 @@ function OrgSwitcher({ compact = false }) {
459
460
  }
460
461
 
461
462
  // src/OrganizationSwitcher.tsx
462
- var import_auth2 = require("@plexusone/auth");
463
+ var import_auth3 = require("@plexusone/auth");
463
464
  var import_ui3 = require("@plexusone/ui");
464
465
  var import_jsx_runtime4 = require("react/jsx-runtime");
465
466
  function OrganizationSwitcher({
@@ -469,7 +470,7 @@ function OrganizationSwitcher({
469
470
  alwaysShow = false,
470
471
  className
471
472
  }) {
472
- const ctx = (0, import_auth2.useSessionOptional)();
473
+ const ctx = (0, import_auth3.useSessionOptional)();
473
474
  const list = memberships ?? ctx?.session.user?.memberships ?? [];
474
475
  if (list.length === 0 || list.length === 1 && !alwaysShow) {
475
476
  return null;
@@ -487,7 +488,7 @@ function OrganizationSwitcher({
487
488
  ),
488
489
  children: [
489
490
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui3.BuildingIcon, { className: "h-4 w-4 text-muted-foreground" }),
490
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "flex-1 truncate font-medium text-foreground", children: current ? (0, import_auth2.organizationLabel)(current) : "Choose organization" }),
491
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "flex-1 truncate font-medium text-foreground", children: current ? (0, import_auth3.organizationLabel)(current) : "Choose organization" }),
491
492
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui3.ChevronDownIcon, { className: "h-4 w-4 text-muted-foreground" })
492
493
  ]
493
494
  }
@@ -503,7 +504,7 @@ function OrganizationSwitcher({
503
504
  "aria-current": selected ? "true" : void 0,
504
505
  className: (0, import_ui3.cn)("cursor-pointer", selected && "bg-accent"),
505
506
  children: [
506
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "flex-1 truncate text-sm", children: (0, import_auth2.organizationLabel)(m) }),
507
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "flex-1 truncate text-sm", children: (0, import_auth3.organizationLabel)(m) }),
507
508
  selected && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui3.CheckIcon, { className: "h-4 w-4 ml-2 text-primary" })
508
509
  ]
509
510
  },
@@ -514,7 +515,7 @@ function OrganizationSwitcher({
514
515
  }
515
516
 
516
517
  // src/ProductSwitcher.tsx
517
- var import_auth3 = require("@plexusone/auth");
518
+ var import_auth4 = require("@plexusone/auth");
518
519
  var import_ui4 = require("@plexusone/ui");
519
520
 
520
521
  // src/switcher.ts
@@ -532,13 +533,22 @@ function ProductSwitcher({
532
533
  onNavigate,
533
534
  className
534
535
  }) {
535
- const ctx = (0, import_auth3.useSessionOptional)();
536
+ const ctx = (0, import_auth4.useSessionOptional)();
536
537
  const session = ctx?.session;
537
538
  const catalog = apps ?? session?.apps ?? [];
538
- const membership = session ? (0, import_auth3.membershipFor)(session, organizationId) : void 0;
539
- const entries = switcherApps(catalog, self, membership);
539
+ const membership = session ? (0, import_auth4.membershipFor)(session, organizationId) : void 0;
540
+ const entries = switcherApps(catalog, self, membership).filter(
541
+ (app) => app.id === self.id || (0, import_auth4.safeHref)(app.url) !== void 0
542
+ );
540
543
  const follow = (url) => (e) => {
541
- if (!onNavigate) e.currentTarget.href = carryPreferences(url);
544
+ if (!onNavigate) {
545
+ const href = (0, import_auth4.safeHref)(carryPreferences(url));
546
+ if (href === void 0) {
547
+ e.preventDefault();
548
+ return;
549
+ }
550
+ e.currentTarget.href = href;
551
+ }
542
552
  if (!onNavigate || e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey) {
543
553
  return;
544
554
  }
@@ -569,10 +579,10 @@ function ProductSwitcher({
569
579
  }
570
580
 
571
581
  // src/Navbar.tsx
572
- var import_auth6 = require("@plexusone/auth");
582
+ var import_auth8 = require("@plexusone/auth");
573
583
 
574
584
  // src/ProfileMenu.tsx
575
- var import_auth4 = require("@plexusone/auth");
585
+ var import_auth5 = require("@plexusone/auth");
576
586
  var import_ui5 = require("@plexusone/ui");
577
587
  var import_jsx_runtime6 = require("react/jsx-runtime");
578
588
  function initials(nameOrEmail) {
@@ -589,20 +599,22 @@ function ProfileMenu({
589
599
  onNavigate,
590
600
  onSignOutError = (err) => console.error("signing out failed", err)
591
601
  }) {
592
- const ctx = (0, import_auth4.useSessionOptional)();
602
+ const ctx = (0, import_auth5.useSessionOptional)();
593
603
  const user = ctx?.session.user;
594
604
  if (!ctx || ctx.status !== "authenticated" || !user) {
595
605
  return null;
596
606
  }
597
- const who = user.name || user.email || "Signed in";
598
- const membership = (0, import_auth4.membershipFor)(ctx.session, organizationId);
607
+ const name = (0, import_auth5.safeName)(user.name);
608
+ const heading = name ?? "Signed in";
609
+ const who = name || user.email || "Signed in";
610
+ const membership = (0, import_auth5.membershipFor)(ctx.session, organizationId);
599
611
  const role = membership ? appId && membership.applications[appId] || membership.role : void 0;
600
612
  const run = (item) => {
601
613
  if (item.onClick) {
602
614
  item.onClick();
603
615
  } else if (item.href) {
604
616
  if (onNavigate) onNavigate(item.href);
605
- else window.location.assign(item.href);
617
+ else (0, import_auth5.navigateTo)(item.href);
606
618
  }
607
619
  };
608
620
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui5.DropdownMenu, { children: [
@@ -615,20 +627,20 @@ function ProfileMenu({
615
627
  className: "flex items-center p-1 bg-transparent border-none rounded-full cursor-pointer hover:bg-accent",
616
628
  children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui5.Avatar, { className: "h-8 w-8", children: [
617
629
  user.avatarUrl ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui5.AvatarImage, { src: user.avatarUrl, alt: "" }) : null,
618
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui5.AvatarFallback, { className: "bg-primary/10 text-primary text-xs font-medium", children: initials(user.name || user.email) })
630
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui5.AvatarFallback, { className: "bg-primary/10 text-primary text-xs font-medium", children: initials(name || user.email) })
619
631
  ] })
620
632
  }
621
633
  ) }),
622
634
  /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui5.DropdownMenuContent, { align: "end", className: "w-64", children: [
623
635
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui5.DropdownMenuLabel, { className: "font-normal", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex flex-col gap-1", children: [
624
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "text-sm font-medium leading-none", children: who }),
625
- user.email && user.email !== who && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "text-xs leading-none text-muted-foreground", children: user.email })
636
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "text-sm font-medium leading-none", children: heading }),
637
+ user.email && user.email !== heading && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "text-xs leading-none text-muted-foreground", children: user.email })
626
638
  ] }) }),
627
639
  membership && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
628
640
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui5.DropdownMenuSeparator, {}),
629
641
  /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("dl", { className: "px-2 py-1.5 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs", children: [
630
642
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("dt", { className: "text-muted-foreground", children: "Organization" }),
631
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("dd", { className: "truncate", children: (0, import_auth4.organizationLabel)(membership) }),
643
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("dd", { className: "truncate", children: (0, import_auth5.organizationLabel)(membership) }),
632
644
  role && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
633
645
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("dt", { className: "text-muted-foreground", children: "Role" }),
634
646
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("dd", { children: role })
@@ -694,12 +706,12 @@ function ThemeToggle() {
694
706
  }
695
707
 
696
708
  // src/UserMenu.tsx
697
- var import_auth5 = require("@plexusone/auth");
709
+ var import_auth6 = require("@plexusone/auth");
698
710
  var import_ui7 = require("@plexusone/ui");
699
711
  var import_jsx_runtime8 = require("react/jsx-runtime");
700
712
  var defaultActions = [];
701
713
  function UserMenu({ actions = defaultActions, onNavigate }) {
702
- const auth = (0, import_auth5.useAuthOptional)();
714
+ const auth = (0, import_auth6.useAuthOptional)();
703
715
  if (!auth || auth.isLoading || !auth.user) {
704
716
  return null;
705
717
  }
@@ -711,7 +723,7 @@ function UserMenu({ actions = defaultActions, onNavigate }) {
711
723
  if (onNavigate) {
712
724
  onNavigate(action.href);
713
725
  } else {
714
- window.location.assign(action.href);
726
+ (0, import_auth6.navigateTo)(action.href);
715
727
  }
716
728
  }
717
729
  };
@@ -729,14 +741,14 @@ function UserMenu({ actions = defaultActions, onNavigate }) {
729
741
  type: "button",
730
742
  className: "flex items-center gap-2 p-1 bg-transparent border-none rounded-full cursor-pointer hover:bg-accent",
731
743
  children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui7.Avatar, { className: "h-8 w-8", children: [
732
- user.avatar_url ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui7.AvatarImage, { src: user.avatar_url, alt: user.name }) : null,
744
+ user.avatar_url ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui7.AvatarImage, { src: user.avatar_url, alt: (0, import_auth6.displayName)(user, "Signed in") }) : null,
733
745
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui7.AvatarFallback, { className: "bg-primary/10 text-primary", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui7.UserIcon, { className: "h-4 w-4" }) })
734
746
  ] })
735
747
  }
736
748
  ) }),
737
749
  /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui7.DropdownMenuContent, { align: "end", className: "w-56", children: [
738
750
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui7.DropdownMenuLabel, { className: "font-normal", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex flex-col space-y-1", children: [
739
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "text-sm font-medium leading-none", children: user.name }),
751
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "text-sm font-medium leading-none", children: (0, import_auth6.displayName)(user, "Signed in") }),
740
752
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "text-xs leading-none text-muted-foreground", children: user.email })
741
753
  ] }) }),
742
754
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui7.DropdownMenuSeparator, {}),
@@ -776,6 +788,7 @@ function UserMenu({ actions = defaultActions, onNavigate }) {
776
788
 
777
789
  // src/Breadcrumbs.tsx
778
790
  var import_ui8 = require("@plexusone/ui");
791
+ var import_auth7 = require("@plexusone/auth");
779
792
  var import_jsx_runtime9 = require("react/jsx-runtime");
780
793
  function Breadcrumbs({
781
794
  items,
@@ -792,7 +805,7 @@ function Breadcrumbs({
792
805
  if (onNavigate) {
793
806
  onNavigate(href);
794
807
  } else {
795
- window.location.assign(href);
808
+ (0, import_auth7.navigateTo)(href);
796
809
  }
797
810
  };
798
811
  let displayItems = items;
@@ -811,7 +824,7 @@ function Breadcrumbs({
811
824
  isCollapsed ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "text-muted-foreground px-1 py-0.5", children: item.label }) : item.href && !isLast ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
812
825
  "a",
813
826
  {
814
- href: item.href,
827
+ href: (0, import_auth7.safeHref)(item.href),
815
828
  onClick: (e) => handleClick(item.href, e),
816
829
  className: "flex items-center gap-1 text-muted-foreground no-underline px-1 py-0.5 rounded hover:text-foreground hover:bg-accent",
817
830
  children: [
@@ -857,7 +870,7 @@ function Navbar({
857
870
  profileItems,
858
871
  showThemeToggle = false
859
872
  }) {
860
- const hasSession = (0, import_auth6.useSessionOptional)() !== void 0;
873
+ const hasSession = (0, import_auth8.useSessionOptional)() !== void 0;
861
874
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("header", { className: "h-16 bg-background border-b border-border flex items-center px-4 gap-4", children: [
862
875
  onToggleSidebar && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
863
876
  import_ui9.Button,