@plumile/backoffice-react 0.1.116 → 0.1.117

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 (59) hide show
  1. package/lib/esm/components/backoffice/billing/BackofficeBillingUsageChart.js +60 -0
  2. package/lib/esm/components/backoffice/billing/BackofficeBillingUsageChart.js.map +1 -0
  3. package/lib/esm/components/backoffice/billing/backofficeBillingUsageChart.css.js +7 -0
  4. package/lib/esm/components/backoffice/billing/backofficeBillingUsageChart.css.js.map +1 -0
  5. package/lib/esm/components/backoffice/columns/buildDataTableColumns.js +6 -6
  6. package/lib/esm/components/backoffice/layout/buildSidebarSections.js +154 -135
  7. package/lib/esm/components/backoffice/layout/buildSidebarSections.js.map +1 -1
  8. package/lib/esm/components/backoffice/layout/sidebarUtils.js +24 -21
  9. package/lib/esm/components/backoffice/layout/sidebarUtils.js.map +1 -1
  10. package/lib/esm/components/backoffice/links/resolveBackofficeLink.js +62 -54
  11. package/lib/esm/components/backoffice/links/resolveBackofficeLink.js.map +1 -1
  12. package/lib/esm/components/backoffice/links/resolveBackofficeTargetIcon.js +1 -1
  13. package/lib/esm/components/backoffice/links/resolveBackofficeTargetIcon.js.map +1 -1
  14. package/lib/esm/index.js +75 -74
  15. package/lib/esm/pages/BackofficeDashboardPage.helpers.js +1 -0
  16. package/lib/esm/pages/BackofficeDashboardPage.helpers.js.map +1 -1
  17. package/lib/esm/pages/BackofficeDashboardPage.js +181 -154
  18. package/lib/esm/pages/BackofficeDashboardPage.js.map +1 -1
  19. package/lib/esm/pages/BackofficeEntityDetailPage.js +12 -12
  20. package/lib/esm/pages/BackofficeLayoutPage.js +133 -129
  21. package/lib/esm/pages/BackofficeLayoutPage.js.map +1 -1
  22. package/lib/esm/provider/BackofficeConfigContext.js.map +1 -1
  23. package/lib/esm/provider/BackofficeProvider.js +126 -121
  24. package/lib/esm/provider/BackofficeProvider.js.map +1 -1
  25. package/lib/esm/provider/dashboardRegistrations.js +17 -0
  26. package/lib/esm/provider/dashboardRegistrations.js.map +1 -0
  27. package/lib/esm/router/createBackofficeRoutes.js +148 -131
  28. package/lib/esm/router/createBackofficeRoutes.js.map +1 -1
  29. package/lib/types/components/backoffice/billing/BackofficeBillingUsageChart.d.ts +25 -0
  30. package/lib/types/components/backoffice/billing/BackofficeBillingUsageChart.d.ts.map +1 -0
  31. package/lib/types/components/backoffice/billing/BackofficeBillingUsageChart.stories.d.ts +41 -0
  32. package/lib/types/components/backoffice/billing/BackofficeBillingUsageChart.stories.d.ts.map +1 -0
  33. package/lib/types/components/backoffice/billing/backofficeBillingUsageChart.css.d.ts +4 -0
  34. package/lib/types/components/backoffice/billing/backofficeBillingUsageChart.css.d.ts.map +1 -0
  35. package/lib/types/components/backoffice/layout/buildSidebarSections.d.ts +2 -1
  36. package/lib/types/components/backoffice/layout/buildSidebarSections.d.ts.map +1 -1
  37. package/lib/types/components/backoffice/layout/sidebarUtils.d.ts +1 -0
  38. package/lib/types/components/backoffice/layout/sidebarUtils.d.ts.map +1 -1
  39. package/lib/types/components/backoffice/links/resolveBackofficeLink.d.ts.map +1 -1
  40. package/lib/types/components/backoffice/links/types.d.ts +1 -0
  41. package/lib/types/components/backoffice/links/types.d.ts.map +1 -1
  42. package/lib/types/index.d.ts +2 -1
  43. package/lib/types/index.d.ts.map +1 -1
  44. package/lib/types/pages/BackofficeDashboardPage.d.ts +5 -1
  45. package/lib/types/pages/BackofficeDashboardPage.d.ts.map +1 -1
  46. package/lib/types/pages/BackofficeDashboardPage.helpers.d.ts.map +1 -1
  47. package/lib/types/pages/BackofficeDashboardPage.stories.d.ts +9 -0
  48. package/lib/types/pages/BackofficeDashboardPage.stories.d.ts.map +1 -0
  49. package/lib/types/pages/BackofficeLayoutPage.d.ts.map +1 -1
  50. package/lib/types/provider/BackofficeConfigContext.d.ts +2 -1
  51. package/lib/types/provider/BackofficeConfigContext.d.ts.map +1 -1
  52. package/lib/types/provider/BackofficeProvider.d.ts.map +1 -1
  53. package/lib/types/provider/dashboardRegistrations.d.ts +4 -0
  54. package/lib/types/provider/dashboardRegistrations.d.ts.map +1 -0
  55. package/lib/types/provider/types.d.ts +8 -1
  56. package/lib/types/provider/types.d.ts.map +1 -1
  57. package/lib/types/router/createBackofficeRoutes.d.ts +8 -2
  58. package/lib/types/router/createBackofficeRoutes.d.ts.map +1 -1
  59. package/package.json +13 -13
@@ -1 +1 @@
1
- {"version":3,"file":"buildSidebarSections.js","names":[],"sources":["../../../../../src/components/backoffice/layout/buildSidebarSections.tsx"],"sourcesContent":["import { type DragEvent, type ReactNode } from 'react';\nimport type { TFunction } from 'i18next';\n\nimport type { BackofficeEntityManifestMap } from '@plumile/backoffice-core/types.js';\nimport type {\n BackofficeSidebarConfig,\n BackofficeSidebarItemDescriptor,\n BackofficeIconComponent,\n BackofficeSidebarRecentItem,\n} from '../../../provider/types.js';\nimport { type AdminSidebarSection } from '@plumile/ui/admin/organisms/admin_sidebar/AdminSidebar.js';\nimport { type SidebarNavSectionItem } from '@plumile/ui/backoffice/molecules/sidebar_nav_section/SidebarNavSection.js';\nimport { BackofficeSidebarHistorySvg } from '@plumile/ui/icons/backoffice/BackofficeSidebarHistorySvg.js';\nimport { GripDotsSvg } from '@plumile/ui/icons/GripDotsSvg.js';\nimport { PinFilledSvg } from '@plumile/ui/icons/PinFilledSvg.js';\nimport { PinSvg } from '@plumile/ui/icons/PinSvg.js';\nimport { SidebarHomeSvg } from '@plumile/ui/icons/SidebarHomeSvg.js';\nimport { SidebarTasksSvg } from '@plumile/ui/icons/SidebarTasksSvg.js';\nimport type { SidebarGroupCollapseState } from '../../../hooks/useSidebarGroupCollapse.js';\nimport * as styles from './backofficeSidebarActions.css.js';\nimport {\n buildEntityGroupLookup,\n isActivePath,\n resolveLabel,\n resolveGroupItems,\n resolveHubEntityIds,\n resolveSidebarHub,\n resolveSidebarGroups,\n} from './sidebarUtils.js';\n\nconst renderIcon = (\n Icon?: BackofficeIconComponent,\n fallback?: ReactNode,\n size = 18,\n): ReactNode => {\n if (Icon != null) {\n return <Icon width={size} height={size} aria-hidden=\"true\" />;\n }\n return fallback ?? null;\n};\n\nexport type BuildSidebarSectionsInput = {\n basePath: string;\n pathname: string;\n entities: BackofficeEntityManifestMap;\n sidebar?: BackofficeSidebarConfig;\n permissions: unknown;\n searchQuery?: string;\n tApp: TFunction;\n t: TFunction;\n pinnedEntityIds?: readonly string[];\n recentItems?: readonly BackofficeSidebarRecentItem[];\n onTogglePin?: (entityId: string) => void;\n onReorderPin?: (fromId: string, toId: string) => void;\n collapsedByGroupId?: SidebarGroupCollapseState;\n onGroupCollapsedChange?: (groupId: string, collapsed: boolean) => void;\n sidebarCollapsed?: boolean;\n};\n\n/**\n * Builds the sidebar sections for the backoffice layout.\n */\nexport function buildSidebarSections(\n input: BuildSidebarSectionsInput,\n): readonly AdminSidebarSection[] {\n const {\n basePath,\n pathname,\n entities,\n sidebar,\n permissions,\n searchQuery,\n tApp,\n t,\n pinnedEntityIds = [],\n recentItems = [],\n onTogglePin,\n onReorderPin,\n collapsedByGroupId,\n onGroupCollapsedChange,\n sidebarCollapsed = false,\n } = input;\n\n const groups = resolveSidebarGroups(entities, sidebar);\n const entries = Object.entries(groups);\n const pinnedSet = new Set(pinnedEntityIds);\n const pinLabel = t('sidebar.actions.pin');\n const unpinLabel = t('sidebar.actions.unpin');\n const reorderLabel = t('sidebar.actions.reorder');\n const entityGroupLookup = buildEntityGroupLookup(groups, sidebar);\n const normalizedQuery = searchQuery?.trim().toLowerCase() ?? '';\n\n const labelMatchesQuery = (label: string): boolean => {\n return (\n normalizedQuery === '' || label.toLowerCase().includes(normalizedQuery)\n );\n };\n\n const renderPinAction = (entityId: string): ReactNode | null => {\n if (onTogglePin == null) {\n return null;\n }\n const isPinned = pinnedSet.has(entityId);\n let label = pinLabel;\n let Icon = PinSvg;\n if (isPinned) {\n label = unpinLabel;\n Icon = PinFilledSvg;\n }\n\n return (\n <button\n type=\"button\"\n className={styles.actionButton}\n aria-pressed={isPinned}\n aria-label={label}\n title={label}\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n onTogglePin(entityId);\n }}\n >\n <Icon width={14} height={14} aria-hidden=\"true\" />\n </button>\n );\n };\n\n const buildDashboardItem = (\n groupId?: string,\n ): SidebarNavSectionItem | null => {\n const dashboardDescriptor: BackofficeSidebarItemDescriptor = {\n kind: 'dashboard',\n id: 'dashboard',\n };\n const isDashboardVisible = sidebar?.isItemVisible?.(\n dashboardDescriptor,\n permissions,\n );\n if (isDashboardVisible === false) {\n return null;\n }\n\n const label = t('sidebar.items.dashboard');\n if (!labelMatchesQuery(label)) {\n return null;\n }\n\n return {\n id: 'dashboard',\n data: {\n kind: 'dashboard',\n id: 'dashboard',\n groupId,\n },\n label,\n href: basePath,\n icon: renderIcon(\n undefined,\n <SidebarHomeSvg width={18} height={18} aria-hidden=\"true\" />,\n ),\n isActive: isActivePath(pathname, basePath),\n ariaLabel: label,\n };\n };\n\n const buildEntityItem = (inputItem: {\n entityId: string;\n groupId?: string;\n groupIcon?: BackofficeIconComponent;\n itemIcon?: BackofficeIconComponent;\n itemLabel?: string;\n enableReorder?: boolean;\n }): SidebarNavSectionItem | null => {\n const { entityId, groupId, groupIcon, itemIcon, itemLabel, enableReorder } =\n inputItem;\n const config = entities[entityId];\n if (config == null) {\n return null;\n }\n\n let descriptor: BackofficeSidebarItemDescriptor = {\n kind: 'entity',\n id: entityId,\n };\n if (config.kind === 'tool') {\n descriptor = { kind: 'tool', id: entityId };\n }\n const isEntityVisible = sidebar?.isItemVisible?.(descriptor, permissions);\n if (isEntityVisible === false) {\n return null;\n }\n\n if (config.kind === 'tool') {\n const label = itemLabel ?? resolveLabel(config.label, tApp);\n if (\n normalizedQuery !== '' &&\n !label.toLowerCase().includes(normalizedQuery)\n ) {\n return null;\n }\n return {\n id: `tool-${entityId}`,\n data: {\n kind: 'tool',\n id: entityId,\n groupId,\n },\n label,\n href: config.routes.list,\n icon: renderIcon(\n itemIcon ?? groupIcon,\n <SidebarTasksSvg width={18} height={18} aria-hidden=\"true\" />,\n ),\n isActive: isActivePath(pathname, config.routes.list),\n ariaLabel: label,\n actionSlot: renderPinAction(entityId),\n };\n }\n\n if (!config.hasList) {\n return null;\n }\n\n const label = itemLabel ?? resolveLabel(config.label, tApp);\n if (\n normalizedQuery !== '' &&\n !label.toLowerCase().includes(normalizedQuery)\n ) {\n return null;\n }\n\n let dragHandleSlot: ReactNode | undefined;\n let onDragStart: ((event: DragEvent) => void) | undefined;\n let onDragOver: ((event: DragEvent) => void) | undefined;\n let onDrop: ((event: DragEvent) => void) | undefined;\n let draggable = false;\n\n if (enableReorder === true && onReorderPin != null) {\n draggable = true;\n dragHandleSlot = (\n <GripDotsSvg width={14} height={14} aria-hidden=\"true\" />\n );\n onDragStart = (event) => {\n const { dataTransfer } = event;\n dataTransfer.effectAllowed = 'move';\n dataTransfer.setData('text/plain', entityId);\n };\n onDragOver = (event) => {\n event.preventDefault();\n const { dataTransfer } = event;\n dataTransfer.dropEffect = 'move';\n };\n onDrop = (event) => {\n event.preventDefault();\n const fromId = event.dataTransfer.getData('text/plain');\n if (fromId === '' || fromId === entityId) {\n return;\n }\n onReorderPin(fromId, entityId);\n };\n }\n\n let dragHandleLabel: string | undefined;\n if (dragHandleSlot != null) {\n dragHandleLabel = reorderLabel;\n }\n\n return {\n id: entityId,\n data: {\n kind: 'entity',\n id: entityId,\n groupId,\n },\n label,\n href: config.routes.list,\n icon: renderIcon(\n itemIcon ?? groupIcon,\n <SidebarTasksSvg width={18} height={18} aria-hidden=\"true\" />,\n ),\n isActive: isActivePath(pathname, config.routes.list),\n ariaLabel: label,\n actionSlot: renderPinAction(entityId),\n dragHandleSlot,\n dragHandleLabel,\n draggable,\n onDragStart,\n onDragOver,\n onDrop,\n };\n };\n\n const buildHubItem = (inputItem: {\n hub: ReturnType<typeof resolveSidebarHub>;\n groupId?: string;\n icon?: BackofficeIconComponent;\n }): SidebarNavSectionItem | null => {\n const { hub, groupId, icon } = inputItem;\n const descriptor: BackofficeSidebarItemDescriptor = {\n kind: 'hub',\n id: hub.id,\n };\n const isVisible = sidebar?.isItemVisible?.(descriptor, permissions);\n if (isVisible === false) {\n return null;\n }\n const childEntityIds = resolveHubEntityIds(hub);\n const visibleChildConfigs = childEntityIds\n .map((entityId) => {\n return entities[entityId] ?? null;\n })\n .filter((config): config is BackofficeEntityManifestMap[string] => {\n if (config == null) {\n return false;\n }\n let childKind: BackofficeSidebarItemDescriptor['kind'] = 'entity';\n if (config.kind === 'tool') {\n childKind = 'tool';\n }\n const childDescriptor: BackofficeSidebarItemDescriptor = {\n kind: childKind,\n id: config.id,\n };\n const isChildVisible = sidebar?.isItemVisible?.(\n childDescriptor,\n permissions,\n );\n if (isChildVisible === false) {\n return false;\n }\n if (config.kind !== 'tool' && !config.hasList) {\n return false;\n }\n return true;\n });\n if (childEntityIds.length > 0 && visibleChildConfigs.length === 0) {\n return null;\n }\n const label = resolveLabel(hub.title, tApp);\n const matchesHub = labelMatchesQuery(label);\n const matchesChild = visibleChildConfigs.some((config) => {\n return labelMatchesQuery(resolveLabel(config.label, tApp));\n });\n if (!matchesHub && !matchesChild) {\n return null;\n }\n const isActive =\n isActivePath(pathname, hub.href) ||\n visibleChildConfigs.some((config) => {\n return isActivePath(pathname, config.routes.list);\n });\n return {\n id: `hub-${hub.id}`,\n data: {\n kind: 'hub',\n id: hub.id,\n groupId,\n },\n label,\n href: hub.href,\n icon: renderIcon(\n icon,\n <SidebarTasksSvg width={18} height={18} aria-hidden=\"true\" />,\n ),\n isActive,\n ariaLabel: label,\n };\n };\n\n const sections: AdminSidebarSection[] = [];\n\n const primaryItems = sidebar?.primaryItems ?? [];\n if (primaryItems.length > 0) {\n const primarySectionItems = primaryItems\n .map((primaryItem): SidebarNavSectionItem | null => {\n if (primaryItem.kind === 'dashboard') {\n return buildDashboardItem();\n }\n if (primaryItem.kind === 'hub') {\n const hub = resolveSidebarHub(primaryItem, sidebar);\n return buildHubItem({\n hub,\n icon: primaryItem.icon,\n });\n }\n let itemLabel: string | undefined;\n if (primaryItem.label != null) {\n itemLabel = resolveLabel(primaryItem.label, tApp);\n }\n return buildEntityItem({\n entityId: primaryItem.id,\n itemIcon: primaryItem.icon,\n itemLabel,\n });\n })\n .filter((item): item is SidebarNavSectionItem => {\n return item != null;\n });\n\n if (primarySectionItems.length > 0) {\n sections.push({\n id: 'primary',\n items: primarySectionItems,\n collapsible: false,\n });\n }\n }\n\n if (pinnedEntityIds.length > 0) {\n const pinnedItems = pinnedEntityIds\n .map((entityId) => {\n const groupMeta = entityGroupLookup.get(entityId);\n return buildEntityItem({\n entityId,\n groupId: groupMeta?.groupId,\n groupIcon: groupMeta?.groupIcon,\n itemIcon: groupMeta?.itemIcon,\n enableReorder: true,\n });\n })\n .filter((item): item is SidebarNavSectionItem => {\n return item != null;\n });\n\n if (pinnedItems.length > 0) {\n sections.push({\n id: 'pinned',\n title: t('sidebar.sections.pinned'),\n icon: renderIcon(\n undefined,\n <PinSvg width={16} height={16} aria-hidden=\"true\" />,\n ),\n items: pinnedItems,\n collapsible: false,\n });\n }\n }\n\n if (recentItems.length > 0) {\n const recentSectionItems = recentItems\n .map((recentItem): SidebarNavSectionItem | null => {\n const config = entities[recentItem.id];\n if (config == null) {\n return null;\n }\n const descriptor: BackofficeSidebarItemDescriptor = {\n kind: recentItem.kind,\n id: recentItem.id,\n };\n const isVisible = sidebar?.isItemVisible?.(descriptor, permissions);\n if (isVisible === false) {\n return null;\n }\n if (\n normalizedQuery !== '' &&\n !recentItem.label.toLowerCase().includes(normalizedQuery)\n ) {\n return null;\n }\n const groupMeta = entityGroupLookup.get(recentItem.id);\n return {\n id: `recent-${recentItem.kind}-${recentItem.id}`,\n data: {\n kind: recentItem.kind,\n id: recentItem.id,\n groupId: groupMeta?.groupId,\n },\n label: recentItem.label,\n href: recentItem.href,\n icon: renderIcon(\n groupMeta?.itemIcon ?? groupMeta?.groupIcon,\n <SidebarTasksSvg width={18} height={18} aria-hidden=\"true\" />,\n ),\n isActive: isActivePath(pathname, recentItem.href),\n ariaLabel: recentItem.label,\n } satisfies SidebarNavSectionItem;\n })\n .filter((item): item is SidebarNavSectionItem => {\n return item != null;\n });\n\n if (recentSectionItems.length > 0) {\n sections.push({\n id: 'recent',\n title: t('sidebar.sections.recent'),\n icon: renderIcon(\n undefined,\n <BackofficeSidebarHistorySvg\n width={16}\n height={16}\n aria-hidden=\"true\"\n />,\n ),\n items: recentSectionItems,\n collapsible: false,\n });\n }\n }\n\n entries.forEach(([groupId, group]) => {\n if (group.isVisible != null && !group.isVisible(permissions)) {\n return;\n }\n\n const items: SidebarNavSectionItem[] = [];\n\n const groupItems = resolveGroupItems(group);\n if (groupItems.length > 0) {\n groupItems.forEach((groupItem) => {\n if (groupItem.kind === 'dashboard') {\n const item = buildDashboardItem(groupId);\n if (item != null) {\n items.push(item);\n }\n return;\n }\n if (groupItem.kind === 'hub') {\n const hub = resolveSidebarHub(groupItem, sidebar);\n const item = buildHubItem({\n hub,\n groupId,\n icon: groupItem.icon ?? group.icon,\n });\n if (item != null) {\n items.push(item);\n }\n return;\n }\n let itemLabel: string | undefined;\n if (groupItem.label != null) {\n itemLabel = resolveLabel(groupItem.label, tApp);\n }\n const item = buildEntityItem({\n entityId: groupItem.id,\n groupId,\n groupIcon: group.icon,\n itemIcon: groupItem.icon,\n itemLabel,\n });\n if (item != null) {\n items.push(item);\n }\n });\n }\n\n let sectionItems: SidebarNavSectionItem[] = items;\n if (sidebarCollapsed && group.behavior?.showInCollapsedRail !== true) {\n sectionItems = items.filter((item) => {\n return item.id === 'dashboard' || item.isActive === true;\n });\n }\n\n if (sectionItems.length === 0) {\n return;\n }\n\n let title: string | undefined;\n if (group.title != null) {\n title = resolveLabel(group.title, tApp);\n }\n\n const isCollapsed = collapsedByGroupId?.[groupId];\n let onCollapsedChange: ((collapsed: boolean) => void) | undefined;\n if (onGroupCollapsedChange != null) {\n onCollapsedChange = (collapsed: boolean) => {\n onGroupCollapsedChange(groupId, collapsed);\n };\n }\n\n sections.push({\n id: groupId,\n title,\n icon: renderIcon(group.icon, undefined, 16),\n items: sectionItems,\n collapsible: group.behavior?.collapsible ?? true,\n defaultCollapsed: group.behavior?.defaultCollapsed ?? true,\n isCollapsed,\n onCollapsedChange,\n });\n });\n\n return sections;\n}\n"],"mappings":";;;;;;;;;;AA8BA,IAAM,KACJ,GACA,GACA,IAAO,OAEH,KAAQ,OAGL,KAAY,OAFV,kBAAC,GAAD;CAAM,OAAO;CAAM,QAAQ;CAAM,eAAY;CAAS,CAAA;AA0BjE,SAAgB,EACd,GACgC;CAChC,IAAM,EACJ,aACA,aACA,aACA,YACA,gBACA,gBACA,SACA,MACA,qBAAkB,EAAE,EACpB,iBAAc,EAAE,EAChB,gBACA,iBACA,uBACA,2BACA,sBAAmB,OACjB,GAEE,IAAS,EAAqB,GAAU,EAAQ,EAChD,IAAU,OAAO,QAAQ,EAAO,EAChC,IAAY,IAAI,IAAI,EAAgB,EACpC,IAAW,EAAE,sBAAsB,EACnC,IAAa,EAAE,wBAAwB,EACvC,IAAe,EAAE,0BAA0B,EAC3C,IAAoB,EAAuB,GAAQ,EAAQ,EAC3D,IAAkB,GAAa,MAAM,CAAC,aAAa,IAAI,IAEvD,KAAqB,MAEvB,MAAoB,MAAM,EAAM,aAAa,CAAC,SAAS,EAAgB,EAIrE,KAAmB,MAAuC;EAC9D,IAAI,KAAe,MACjB,OAAO;EAET,IAAM,IAAW,EAAU,IAAI,EAAS,EACpC,IAAQ,GACR,IAAO;EAMX,OALI,MACF,IAAQ,GACR,IAAO,IAIP,kBAAC,UAAD;GACE,MAAK;GACL,WAAW;GACX,gBAAc;GACd,cAAY;GACZ,OAAO;GACP,UAAU,MAAU;IAGlB,AAFA,EAAM,gBAAgB,EACtB,EAAM,iBAAiB,EACvB,EAAY,EAAS;;aAGvB,kBAAC,GAAD;IAAM,OAAO;IAAI,QAAQ;IAAI,eAAY;IAAS,CAAA;GAC3C,CAAA;IAIP,KACJ,MACiC;EASjC,IAJ2B,GA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KAAA,GAAW,GAAG;GAC3C,OAAO;GACP,aAAa,EAAM,UAAU,eAAe;GAC5C,kBAAkB,EAAM,UAAU,oBAAoB;GACtD;GACA;GACD,CAAC;GACF,EAEK"}
1
+ {"version":3,"file":"buildSidebarSections.js","names":[],"sources":["../../../../../src/components/backoffice/layout/buildSidebarSections.tsx"],"sourcesContent":["import { type DragEvent, type ReactNode } from 'react';\nimport type { TFunction } from 'i18next';\n\nimport type { BackofficeEntityManifestMap } from '@plumile/backoffice-core/types.js';\nimport type {\n BackofficeSidebarConfig,\n BackofficeDashboardRegistration,\n BackofficeSidebarItemDescriptor,\n BackofficeIconComponent,\n BackofficeSidebarRecentItem,\n} from '../../../provider/types.js';\nimport { type AdminSidebarSection } from '@plumile/ui/admin/organisms/admin_sidebar/AdminSidebar.js';\nimport { type SidebarNavSectionItem } from '@plumile/ui/backoffice/molecules/sidebar_nav_section/SidebarNavSection.js';\nimport { BackofficeSidebarHistorySvg } from '@plumile/ui/icons/backoffice/BackofficeSidebarHistorySvg.js';\nimport { GripDotsSvg } from '@plumile/ui/icons/GripDotsSvg.js';\nimport { PinFilledSvg } from '@plumile/ui/icons/PinFilledSvg.js';\nimport { PinSvg } from '@plumile/ui/icons/PinSvg.js';\nimport { SidebarHomeSvg } from '@plumile/ui/icons/SidebarHomeSvg.js';\nimport { SidebarTasksSvg } from '@plumile/ui/icons/SidebarTasksSvg.js';\nimport type { SidebarGroupCollapseState } from '../../../hooks/useSidebarGroupCollapse.js';\nimport { findBackofficeDashboardRegistration } from '../../../provider/dashboardRegistrations.js';\nimport * as styles from './backofficeSidebarActions.css.js';\nimport {\n buildEntityGroupLookup,\n isActivePath,\n joinBackofficePath,\n resolveLabel,\n resolveGroupItems,\n resolveHubEntityIds,\n resolveSidebarHub,\n resolveSidebarGroups,\n} from './sidebarUtils.js';\n\nconst renderIcon = (\n Icon?: BackofficeIconComponent,\n fallback?: ReactNode,\n size = 18,\n): ReactNode => {\n if (Icon != null) {\n return <Icon width={size} height={size} aria-hidden=\"true\" />;\n }\n return fallback ?? null;\n};\n\nexport type BuildSidebarSectionsInput = {\n basePath: string;\n pathname: string;\n entities: BackofficeEntityManifestMap;\n dashboards?: readonly BackofficeDashboardRegistration[];\n sidebar?: BackofficeSidebarConfig;\n permissions: unknown;\n searchQuery?: string;\n tApp: TFunction;\n t: TFunction;\n pinnedEntityIds?: readonly string[];\n recentItems?: readonly BackofficeSidebarRecentItem[];\n onTogglePin?: (entityId: string) => void;\n onReorderPin?: (fromId: string, toId: string) => void;\n collapsedByGroupId?: SidebarGroupCollapseState;\n onGroupCollapsedChange?: (groupId: string, collapsed: boolean) => void;\n sidebarCollapsed?: boolean;\n};\n\n/**\n * Builds the sidebar sections for the backoffice layout.\n */\nexport function buildSidebarSections(\n input: BuildSidebarSectionsInput,\n): readonly AdminSidebarSection[] {\n const {\n basePath,\n pathname,\n entities,\n dashboards = [],\n sidebar,\n permissions,\n searchQuery,\n tApp,\n t,\n pinnedEntityIds = [],\n recentItems = [],\n onTogglePin,\n onReorderPin,\n collapsedByGroupId,\n onGroupCollapsedChange,\n sidebarCollapsed = false,\n } = input;\n\n const groups = resolveSidebarGroups(entities, sidebar);\n const entries = Object.entries(groups);\n const pinnedSet = new Set(pinnedEntityIds);\n const pinLabel = t('sidebar.actions.pin');\n const unpinLabel = t('sidebar.actions.unpin');\n const reorderLabel = t('sidebar.actions.reorder');\n const entityGroupLookup = buildEntityGroupLookup(groups, sidebar);\n const normalizedQuery = searchQuery?.trim().toLowerCase() ?? '';\n\n const labelMatchesQuery = (label: string): boolean => {\n return (\n normalizedQuery === '' || label.toLowerCase().includes(normalizedQuery)\n );\n };\n\n const renderPinAction = (entityId: string): ReactNode | null => {\n if (onTogglePin == null) {\n return null;\n }\n const isPinned = pinnedSet.has(entityId);\n let label = pinLabel;\n let Icon = PinSvg;\n if (isPinned) {\n label = unpinLabel;\n Icon = PinFilledSvg;\n }\n\n return (\n <button\n type=\"button\"\n className={styles.actionButton}\n aria-pressed={isPinned}\n aria-label={label}\n title={label}\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n onTogglePin(entityId);\n }}\n >\n <Icon width={14} height={14} aria-hidden=\"true\" />\n </button>\n );\n };\n\n const buildDashboardItem = (\n inputItem?: {\n id?: string;\n icon?: BackofficeIconComponent;\n label?: string;\n },\n groupId?: string,\n ): SidebarNavSectionItem | null => {\n const dashboardId = inputItem?.id ?? 'dashboard';\n const dashboardDescriptor: BackofficeSidebarItemDescriptor = {\n kind: 'dashboard',\n id: dashboardId,\n };\n const isDashboardVisible = sidebar?.isItemVisible?.(\n dashboardDescriptor,\n permissions,\n );\n if (isDashboardVisible === false) {\n return null;\n }\n\n const registration = findBackofficeDashboardRegistration(\n dashboards,\n dashboardId,\n );\n let label = inputItem?.label;\n if (label == null && registration != null) {\n label = resolveLabel(registration.label, tApp);\n }\n label ??= t('sidebar.items.dashboard');\n if (!labelMatchesQuery(label)) {\n return null;\n }\n\n let href = basePath;\n let id = 'dashboard';\n if (dashboardId !== 'dashboard') {\n href = joinBackofficePath(basePath, `dashboard/${dashboardId}`);\n id = `dashboard-${dashboardId}`;\n }\n\n let isActive = isActivePath(pathname, href);\n if (dashboardId === 'dashboard') {\n isActive = pathname === basePath || pathname === `${basePath}/dashboard`;\n }\n\n return {\n id,\n data: {\n kind: 'dashboard',\n id: dashboardId,\n groupId,\n },\n label,\n href,\n icon: renderIcon(\n inputItem?.icon ?? registration?.icon,\n <SidebarHomeSvg width={18} height={18} aria-hidden=\"true\" />,\n ),\n isActive,\n ariaLabel: label,\n };\n };\n\n const buildEntityItem = (inputItem: {\n entityId: string;\n groupId?: string;\n groupIcon?: BackofficeIconComponent;\n itemIcon?: BackofficeIconComponent;\n itemLabel?: string;\n enableReorder?: boolean;\n }): SidebarNavSectionItem | null => {\n const { entityId, groupId, groupIcon, itemIcon, itemLabel, enableReorder } =\n inputItem;\n const config = entities[entityId];\n if (config == null) {\n return null;\n }\n\n let descriptor: BackofficeSidebarItemDescriptor = {\n kind: 'entity',\n id: entityId,\n };\n if (config.kind === 'tool') {\n descriptor = { kind: 'tool', id: entityId };\n }\n const isEntityVisible = sidebar?.isItemVisible?.(descriptor, permissions);\n if (isEntityVisible === false) {\n return null;\n }\n\n if (config.kind === 'tool') {\n const label = itemLabel ?? resolveLabel(config.label, tApp);\n if (\n normalizedQuery !== '' &&\n !label.toLowerCase().includes(normalizedQuery)\n ) {\n return null;\n }\n return {\n id: `tool-${entityId}`,\n data: {\n kind: 'tool',\n id: entityId,\n groupId,\n },\n label,\n href: config.routes.list,\n icon: renderIcon(\n itemIcon ?? groupIcon,\n <SidebarTasksSvg width={18} height={18} aria-hidden=\"true\" />,\n ),\n isActive: isActivePath(pathname, config.routes.list),\n ariaLabel: label,\n actionSlot: renderPinAction(entityId),\n };\n }\n\n if (!config.hasList) {\n return null;\n }\n\n const label = itemLabel ?? resolveLabel(config.label, tApp);\n if (\n normalizedQuery !== '' &&\n !label.toLowerCase().includes(normalizedQuery)\n ) {\n return null;\n }\n\n let dragHandleSlot: ReactNode | undefined;\n let onDragStart: ((event: DragEvent) => void) | undefined;\n let onDragOver: ((event: DragEvent) => void) | undefined;\n let onDrop: ((event: DragEvent) => void) | undefined;\n let draggable = false;\n\n if (enableReorder === true && onReorderPin != null) {\n draggable = true;\n dragHandleSlot = (\n <GripDotsSvg width={14} height={14} aria-hidden=\"true\" />\n );\n onDragStart = (event) => {\n const { dataTransfer } = event;\n dataTransfer.effectAllowed = 'move';\n dataTransfer.setData('text/plain', entityId);\n };\n onDragOver = (event) => {\n event.preventDefault();\n const { dataTransfer } = event;\n dataTransfer.dropEffect = 'move';\n };\n onDrop = (event) => {\n event.preventDefault();\n const fromId = event.dataTransfer.getData('text/plain');\n if (fromId === '' || fromId === entityId) {\n return;\n }\n onReorderPin(fromId, entityId);\n };\n }\n\n let dragHandleLabel: string | undefined;\n if (dragHandleSlot != null) {\n dragHandleLabel = reorderLabel;\n }\n\n return {\n id: entityId,\n data: {\n kind: 'entity',\n id: entityId,\n groupId,\n },\n label,\n href: config.routes.list,\n icon: renderIcon(\n itemIcon ?? groupIcon,\n <SidebarTasksSvg width={18} height={18} aria-hidden=\"true\" />,\n ),\n isActive: isActivePath(pathname, config.routes.list),\n ariaLabel: label,\n actionSlot: renderPinAction(entityId),\n dragHandleSlot,\n dragHandleLabel,\n draggable,\n onDragStart,\n onDragOver,\n onDrop,\n };\n };\n\n const buildHubItem = (inputItem: {\n hub: ReturnType<typeof resolveSidebarHub>;\n groupId?: string;\n icon?: BackofficeIconComponent;\n }): SidebarNavSectionItem | null => {\n const { hub, groupId, icon } = inputItem;\n const descriptor: BackofficeSidebarItemDescriptor = {\n kind: 'hub',\n id: hub.id,\n };\n const isVisible = sidebar?.isItemVisible?.(descriptor, permissions);\n if (isVisible === false) {\n return null;\n }\n const childEntityIds = resolveHubEntityIds(hub);\n const visibleChildConfigs = childEntityIds\n .map((entityId) => {\n return entities[entityId] ?? null;\n })\n .filter((config): config is BackofficeEntityManifestMap[string] => {\n if (config == null) {\n return false;\n }\n let childKind: BackofficeSidebarItemDescriptor['kind'] = 'entity';\n if (config.kind === 'tool') {\n childKind = 'tool';\n }\n const childDescriptor: BackofficeSidebarItemDescriptor = {\n kind: childKind,\n id: config.id,\n };\n const isChildVisible = sidebar?.isItemVisible?.(\n childDescriptor,\n permissions,\n );\n if (isChildVisible === false) {\n return false;\n }\n if (config.kind !== 'tool' && !config.hasList) {\n return false;\n }\n return true;\n });\n if (childEntityIds.length > 0 && visibleChildConfigs.length === 0) {\n return null;\n }\n const label = resolveLabel(hub.title, tApp);\n const matchesHub = labelMatchesQuery(label);\n const matchesChild = visibleChildConfigs.some((config) => {\n return labelMatchesQuery(resolveLabel(config.label, tApp));\n });\n if (!matchesHub && !matchesChild) {\n return null;\n }\n const isActive =\n isActivePath(pathname, hub.href) ||\n visibleChildConfigs.some((config) => {\n return isActivePath(pathname, config.routes.list);\n });\n return {\n id: `hub-${hub.id}`,\n data: {\n kind: 'hub',\n id: hub.id,\n groupId,\n },\n label,\n href: hub.href,\n icon: renderIcon(\n icon,\n <SidebarTasksSvg width={18} height={18} aria-hidden=\"true\" />,\n ),\n isActive,\n ariaLabel: label,\n };\n };\n\n const sections: AdminSidebarSection[] = [];\n\n const primaryItems = sidebar?.primaryItems ?? [];\n if (primaryItems.length > 0) {\n const primarySectionItems = primaryItems\n .map((primaryItem): SidebarNavSectionItem | null => {\n if (primaryItem.kind === 'dashboard') {\n let itemLabel: string | undefined;\n if (primaryItem.label != null) {\n itemLabel = resolveLabel(primaryItem.label, tApp);\n }\n return buildDashboardItem({\n id: primaryItem.id,\n icon: primaryItem.icon,\n label: itemLabel,\n });\n }\n if (primaryItem.kind === 'hub') {\n const hub = resolveSidebarHub(primaryItem, sidebar);\n return buildHubItem({\n hub,\n icon: primaryItem.icon,\n });\n }\n let itemLabel: string | undefined;\n if (primaryItem.label != null) {\n itemLabel = resolveLabel(primaryItem.label, tApp);\n }\n return buildEntityItem({\n entityId: primaryItem.id,\n itemIcon: primaryItem.icon,\n itemLabel,\n });\n })\n .filter((item): item is SidebarNavSectionItem => {\n return item != null;\n });\n\n if (primarySectionItems.length > 0) {\n sections.push({\n id: 'primary',\n items: primarySectionItems,\n collapsible: false,\n });\n }\n }\n\n if (pinnedEntityIds.length > 0) {\n const pinnedItems = pinnedEntityIds\n .map((entityId) => {\n const groupMeta = entityGroupLookup.get(entityId);\n return buildEntityItem({\n entityId,\n groupId: groupMeta?.groupId,\n groupIcon: groupMeta?.groupIcon,\n itemIcon: groupMeta?.itemIcon,\n enableReorder: true,\n });\n })\n .filter((item): item is SidebarNavSectionItem => {\n return item != null;\n });\n\n if (pinnedItems.length > 0) {\n sections.push({\n id: 'pinned',\n title: t('sidebar.sections.pinned'),\n icon: renderIcon(\n undefined,\n <PinSvg width={16} height={16} aria-hidden=\"true\" />,\n ),\n items: pinnedItems,\n collapsible: false,\n });\n }\n }\n\n if (recentItems.length > 0) {\n const recentSectionItems = recentItems\n .map((recentItem): SidebarNavSectionItem | null => {\n const config = entities[recentItem.id];\n if (config == null) {\n return null;\n }\n const descriptor: BackofficeSidebarItemDescriptor = {\n kind: recentItem.kind,\n id: recentItem.id,\n };\n const isVisible = sidebar?.isItemVisible?.(descriptor, permissions);\n if (isVisible === false) {\n return null;\n }\n if (\n normalizedQuery !== '' &&\n !recentItem.label.toLowerCase().includes(normalizedQuery)\n ) {\n return null;\n }\n const groupMeta = entityGroupLookup.get(recentItem.id);\n return {\n id: `recent-${recentItem.kind}-${recentItem.id}`,\n data: {\n kind: recentItem.kind,\n id: recentItem.id,\n groupId: groupMeta?.groupId,\n },\n label: recentItem.label,\n href: recentItem.href,\n icon: renderIcon(\n groupMeta?.itemIcon ?? groupMeta?.groupIcon,\n <SidebarTasksSvg width={18} height={18} aria-hidden=\"true\" />,\n ),\n isActive: isActivePath(pathname, recentItem.href),\n ariaLabel: recentItem.label,\n } satisfies SidebarNavSectionItem;\n })\n .filter((item): item is SidebarNavSectionItem => {\n return item != null;\n });\n\n if (recentSectionItems.length > 0) {\n sections.push({\n id: 'recent',\n title: t('sidebar.sections.recent'),\n icon: renderIcon(\n undefined,\n <BackofficeSidebarHistorySvg\n width={16}\n height={16}\n aria-hidden=\"true\"\n />,\n ),\n items: recentSectionItems,\n collapsible: false,\n });\n }\n }\n\n entries.forEach(([groupId, group]) => {\n if (group.isVisible != null && !group.isVisible(permissions)) {\n return;\n }\n\n const items: SidebarNavSectionItem[] = [];\n\n const groupItems = resolveGroupItems(group);\n if (groupItems.length > 0) {\n groupItems.forEach((groupItem) => {\n if (groupItem.kind === 'dashboard') {\n let itemLabel: string | undefined;\n if (groupItem.label != null) {\n itemLabel = resolveLabel(groupItem.label, tApp);\n }\n const item = buildDashboardItem(\n {\n id: groupItem.id,\n icon: groupItem.icon ?? group.icon,\n label: itemLabel,\n },\n groupId,\n );\n if (item != null) {\n items.push(item);\n }\n return;\n }\n if (groupItem.kind === 'hub') {\n const hub = resolveSidebarHub(groupItem, sidebar);\n const item = buildHubItem({\n hub,\n groupId,\n icon: groupItem.icon ?? group.icon,\n });\n if (item != null) {\n items.push(item);\n }\n return;\n }\n let itemLabel: string | undefined;\n if (groupItem.label != null) {\n itemLabel = resolveLabel(groupItem.label, tApp);\n }\n const item = buildEntityItem({\n entityId: groupItem.id,\n groupId,\n groupIcon: group.icon,\n itemIcon: groupItem.icon,\n itemLabel,\n });\n if (item != null) {\n items.push(item);\n }\n });\n }\n\n let sectionItems: SidebarNavSectionItem[] = items;\n if (sidebarCollapsed && group.behavior?.showInCollapsedRail !== true) {\n sectionItems = items.filter((item) => {\n return item.data?.kind === 'dashboard' || item.isActive === true;\n });\n }\n\n if (sectionItems.length === 0) {\n return;\n }\n\n let title: string | undefined;\n if (group.title != null) {\n title = resolveLabel(group.title, tApp);\n }\n\n const isCollapsed = collapsedByGroupId?.[groupId];\n let onCollapsedChange: ((collapsed: boolean) => void) | undefined;\n if (onGroupCollapsedChange != null) {\n onCollapsedChange = (collapsed: boolean) => {\n onGroupCollapsedChange(groupId, collapsed);\n };\n }\n\n sections.push({\n id: groupId,\n title,\n icon: renderIcon(group.icon, undefined, 16),\n items: sectionItems,\n collapsible: group.behavior?.collapsible ?? true,\n defaultCollapsed: group.behavior?.defaultCollapsed ?? true,\n isCollapsed,\n onCollapsedChange,\n });\n });\n\n return sections;\n}\n"],"mappings":";;;;;;;;;;;AAiCA,IAAM,KACJ,GACA,GACA,IAAO,OAEH,KAAQ,OAGL,KAAY,OAFV,kBAAC,GAAD;CAAM,OAAO;CAAM,QAAQ;CAAM,eAAY;CAAS,CAAA;AA2BjE,SAAgB,EACd,GACgC;CAChC,IAAM,EACJ,aACA,aACA,aACA,gBAAa,EAAE,EACf,YACA,gBACA,gBACA,SACA,MACA,qBAAkB,EAAE,EACpB,iBAAc,EAAE,EAChB,gBACA,iBACA,uBACA,2BACA,sBAAmB,OACjB,GAEE,IAAS,EAAqB,GAAU,EAAQ,EAChD,IAAU,OAAO,QAAQ,EAAO,EAChC,IAAY,IAAI,IAAI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S,KAAK;GACZ,IAAI;GACJ;GACA,MAAM,EAAW,EAAM,MAAM,KAAA,GAAW,GAAG;GAC3C,OAAO;GACP,aAAa,EAAM,UAAU,eAAe;GAC5C,kBAAkB,EAAM,UAAU,oBAAoB;GACtD;GACA;GACD,CAAC;GACF,EAEK"}
@@ -1,52 +1,55 @@
1
1
  //#region src/components/backoffice/layout/sidebarUtils.ts
2
- var e = (e, t) => e(t), t = (e, t) => !!(e === t || t !== "/" && e.startsWith(`${t}/`)), n = (e) => ({ main: { entities: Object.keys(e) } }), r = (e, t) => t?.groups ?? n(e), i = (e) => e.kind === "dashboard" ? {
2
+ var e = (e, t) => e(t), t = (e, t) => !!(e === t || t !== "/" && e.startsWith(`${t}/`)), n = (e, t) => {
3
+ let n = e.replace(/\/+$/g, ""), r = t.replace(/^\/+/g, "");
4
+ return n === "" ? `/${r}` : `${n}/${r}`;
5
+ }, r = (e) => ({ main: { entities: Object.keys(e) } }), i = (e, t) => t?.groups ?? r(e), a = (e) => e.kind === "dashboard" ? {
3
6
  kind: "dashboard",
4
7
  id: e.id ?? "dashboard"
5
8
  } : {
6
9
  kind: e.kind,
7
10
  id: e.id
8
- }, a = (e) => e.items == null ? e.entities?.map((e) => ({
11
+ }, o = (e) => e.items == null ? e.entities?.map((e) => ({
9
12
  kind: "entity",
10
13
  id: e
11
- })) ?? [] : e.items, o = (e, t) => {
14
+ })) ?? [] : e.items, s = (e, t) => {
12
15
  let n = t?.hubs?.[e.id];
13
16
  return {
14
17
  ...n,
15
18
  ...e,
16
19
  groups: e.groups ?? n?.groups ?? []
17
20
  };
18
- }, s = (e, t) => o(e, t), c = (e) => {
21
+ }, c = (e, t) => s(e, t), l = (e) => {
19
22
  let t = [], n = /* @__PURE__ */ new Set();
20
23
  return e.groups.forEach((e) => {
21
24
  e.items.forEach((e) => {
22
25
  n.has(e.id) || (n.add(e.id), t.push(e.id));
23
26
  });
24
27
  }), t;
25
- }, l = (e, t) => {
28
+ }, u = (e, t) => {
26
29
  let n = [], r = /* @__PURE__ */ new Set();
27
30
  return Object.entries(e).forEach(([e, i]) => {
28
- a(i).forEach((a) => {
31
+ o(i).forEach((a) => {
29
32
  a.kind !== "hub" || r.has(a.id) || (r.add(a.id), n.push({
30
33
  groupId: e,
31
- hub: s(a, t),
34
+ hub: c(a, t),
32
35
  icon: a.icon ?? i.icon
33
36
  }));
34
37
  });
35
38
  }), Object.values(t?.hubs ?? {}).forEach((e) => {
36
39
  r.has(e.id) || (r.add(e.id), n.push({
37
40
  groupId: null,
38
- hub: s(e, t),
41
+ hub: c(e, t),
39
42
  icon: e.icon
40
43
  }));
41
44
  }), n;
42
- }, u = (e, t) => a(e).flatMap((e) => e.kind === "entity" || e.kind === "tool" ? [e.id] : e.kind === "hub" ? c(s(e, t)) : []), d = (e, t) => {
45
+ }, d = (e, t) => o(e).flatMap((e) => e.kind === "entity" || e.kind === "tool" ? [e.id] : e.kind === "hub" ? l(c(e, t)) : []), f = (e, t) => {
43
46
  let n = /* @__PURE__ */ new Map();
44
47
  return Object.entries(e).forEach(([e, r]) => {
45
- a(r).forEach((i) => {
48
+ o(r).forEach((i) => {
46
49
  if (i.kind !== "dashboard") {
47
50
  if (i.kind === "hub") {
48
- let a = s(i, t);
49
- c(a).forEach((t) => {
51
+ let a = c(i, t);
52
+ l(a).forEach((t) => {
50
53
  n.has(t) || n.set(t, {
51
54
  groupId: e,
52
55
  groupIcon: r.icon,
@@ -63,7 +66,7 @@ var e = (e, t) => e(t), t = (e, t) => !!(e === t || t !== "/" && e.startsWith(`$
63
66
  }
64
67
  });
65
68
  }), n;
66
- }, f = (e, t, n, r) => {
69
+ }, p = (e, t, n, r) => {
67
70
  let i = t[e];
68
71
  if (i == null) return !1;
69
72
  let a = {
@@ -74,25 +77,25 @@ var e = (e, t) => e(t), t = (e, t) => !!(e === t || t !== "/" && e.startsWith(`$
74
77
  kind: "tool",
75
78
  id: e
76
79
  }), n?.isItemVisible == null ? i.kind === "tool" ? !0 : i.hasList : n.isItemVisible(a, r);
77
- }, p = (e, t, n, r) => {
80
+ }, m = (e, t, n, r) => {
78
81
  let i = [], a = /* @__PURE__ */ new Set();
79
82
  return Object.entries(e).forEach(([, e]) => {
80
- e.isVisible != null && !e.isVisible(r) || u(e, n).forEach((e) => {
81
- a.has(e) || f(e, t, n, r) && (a.add(e), i.push(e));
83
+ e.isVisible != null && !e.isVisible(r) || d(e, n).forEach((e) => {
84
+ a.has(e) || p(e, t, n, r) && (a.add(e), i.push(e));
82
85
  });
83
86
  }), i;
84
- }, m = (e, n) => {
87
+ }, h = (e, n) => {
85
88
  let r = Object.entries(n);
86
89
  for (let [n, i] of r) if (i.kind === "tool") {
87
90
  if (t(e, i.routes.list)) return n;
88
91
  } else if (i.hasList && t(e, i.routes.list)) return n;
89
92
  return null;
90
- }, h = (e, t, n, r, i) => {
91
- if (t == null || !f(t, n, r, i)) return null;
92
- for (let [n, a] of Object.entries(e)) if ((a.isVisible == null || a.isVisible(i)) && u(a, r).includes(t)) return n;
93
+ }, g = (e, t, n, r, i) => {
94
+ if (t == null || !p(t, n, r, i)) return null;
95
+ for (let [n, a] of Object.entries(e)) if ((a.isVisible == null || a.isVisible(i)) && d(a, r).includes(t)) return n;
93
96
  return null;
94
97
  };
95
98
  //#endregion
96
- export { n as buildDefaultGroups, d as buildEntityGroupLookup, t as isActivePath, m as resolveActiveEntityId, h as resolveActiveGroupId, u as resolveGroupEntityIds, a as resolveGroupItems, c as resolveHubEntityIds, i as resolveItemDescriptor, e as resolveLabel, r as resolveSidebarGroups, s as resolveSidebarHub, l as resolveSidebarHubEntries, o as resolveSidebarHubFor, p as resolveVisibleEntityIds };
99
+ export { r as buildDefaultGroups, f as buildEntityGroupLookup, t as isActivePath, n as joinBackofficePath, h as resolveActiveEntityId, g as resolveActiveGroupId, d as resolveGroupEntityIds, o as resolveGroupItems, l as resolveHubEntityIds, a as resolveItemDescriptor, e as resolveLabel, i as resolveSidebarGroups, c as resolveSidebarHub, u as resolveSidebarHubEntries, s as resolveSidebarHubFor, m as resolveVisibleEntityIds };
97
100
 
98
101
  //# sourceMappingURL=sidebarUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sidebarUtils.js","names":[],"sources":["../../../../../src/components/backoffice/layout/sidebarUtils.ts"],"sourcesContent":["import type { TFunction } from 'i18next';\n\nimport type {\n BackofficeEntityManifestMap,\n I18nLabel,\n} from '@plumile/backoffice-core/types.js';\nimport type {\n BackofficeSidebarConfig,\n BackofficeIconComponent,\n BackofficeSidebarGroupConfig,\n BackofficeSidebarItemDescriptor,\n BackofficeSidebarItemConfig,\n BackofficeSidebarHubConfig,\n BackofficeSidebarHubGroupConfig,\n BackofficeResolvedSidebarHubConfig,\n} from '../../../provider/types.js';\n\nexport const resolveLabel = (label: I18nLabel, tApp: TFunction): string => {\n return label(tApp);\n};\n\nexport const isActivePath = (pathname: string, href: string): boolean => {\n if (pathname === href) {\n return true;\n }\n if (href !== '/' && pathname.startsWith(`${href}/`)) {\n return true;\n }\n return false;\n};\n\nexport const buildDefaultGroups = (\n entities: BackofficeEntityManifestMap,\n): Record<string, BackofficeSidebarGroupConfig> => {\n const entityIds = Object.keys(entities);\n\n return {\n main: {\n entities: entityIds,\n },\n };\n};\n\nexport const resolveSidebarGroups = (\n entities: BackofficeEntityManifestMap,\n sidebar: BackofficeSidebarConfig | undefined,\n): Record<string, BackofficeSidebarGroupConfig> => {\n return sidebar?.groups ?? buildDefaultGroups(entities);\n};\n\nexport type EntityGroupLookup = Map<\n string,\n {\n groupId: string;\n groupIcon?: BackofficeIconComponent;\n itemIcon?: BackofficeIconComponent;\n }\n>;\n\nexport const resolveItemDescriptor = (\n item: BackofficeSidebarItemConfig,\n): BackofficeSidebarItemDescriptor => {\n if (item.kind === 'dashboard') {\n return { kind: 'dashboard', id: item.id ?? 'dashboard' };\n }\n return { kind: item.kind, id: item.id };\n};\n\nexport const resolveGroupItems = <\n TManifest extends BackofficeEntityManifestMap = BackofficeEntityManifestMap,\n>(\n group: BackofficeSidebarGroupConfig<TManifest>,\n): readonly BackofficeSidebarItemConfig<TManifest>[] => {\n if (group.items != null) {\n return group.items;\n }\n return (group.entities?.map((entityId) => {\n return { kind: 'entity', id: entityId } as const;\n }) ?? []) as unknown as readonly BackofficeSidebarItemConfig<TManifest>[];\n};\n\nexport type BackofficeResolvedSidebarHubConfigFor<\n TManifest extends BackofficeEntityManifestMap = BackofficeEntityManifestMap,\n> = BackofficeSidebarHubConfig<TManifest> & {\n groups: readonly BackofficeSidebarHubGroupConfig<TManifest>[];\n};\n\nexport const resolveSidebarHubFor = <\n TManifest extends BackofficeEntityManifestMap = BackofficeEntityManifestMap,\n>(\n item: BackofficeSidebarHubConfig<TManifest>,\n sidebar: BackofficeSidebarConfig<TManifest> | undefined,\n): BackofficeResolvedSidebarHubConfigFor<TManifest> => {\n const registeredHub = sidebar?.hubs?.[item.id];\n return {\n ...registeredHub,\n ...item,\n groups: item.groups ?? registeredHub?.groups ?? [],\n };\n};\n\nexport const resolveSidebarHub = (\n item: BackofficeSidebarHubConfig,\n sidebar: BackofficeSidebarConfig | undefined,\n): BackofficeResolvedSidebarHubConfig => {\n return resolveSidebarHubFor(item, sidebar);\n};\n\nexport const resolveHubEntityIds = (\n hub: BackofficeResolvedSidebarHubConfig,\n): readonly string[] => {\n const output: string[] = [];\n const seen = new Set<string>();\n hub.groups.forEach((group) => {\n group.items.forEach((item) => {\n if (seen.has(item.id)) {\n return;\n }\n seen.add(item.id);\n output.push(item.id);\n });\n });\n return output;\n};\n\nexport type ResolvedSidebarHubEntry = {\n groupId: string | null;\n hub: BackofficeResolvedSidebarHubConfig;\n icon?: BackofficeIconComponent;\n};\n\nexport const resolveSidebarHubEntries = (\n groups: Record<string, BackofficeSidebarGroupConfig>,\n sidebar: BackofficeSidebarConfig | undefined,\n): readonly ResolvedSidebarHubEntry[] => {\n const output: ResolvedSidebarHubEntry[] = [];\n const seen = new Set<string>();\n\n Object.entries(groups).forEach(([groupId, group]) => {\n resolveGroupItems(group).forEach((item) => {\n if (item.kind !== 'hub' || seen.has(item.id)) {\n return;\n }\n seen.add(item.id);\n output.push({\n groupId,\n hub: resolveSidebarHub(item, sidebar),\n icon: item.icon ?? group.icon,\n });\n });\n });\n\n Object.values(sidebar?.hubs ?? {}).forEach((hub) => {\n if (seen.has(hub.id)) {\n return;\n }\n seen.add(hub.id);\n output.push({\n groupId: null,\n hub: resolveSidebarHub(hub, sidebar),\n icon: hub.icon,\n });\n });\n\n return output;\n};\n\nexport const resolveGroupEntityIds = (\n group: BackofficeSidebarGroupConfig,\n sidebar?: BackofficeSidebarConfig,\n): readonly string[] => {\n return resolveGroupItems(group).flatMap((item) => {\n if (item.kind === 'entity' || item.kind === 'tool') {\n return [item.id];\n }\n if (item.kind === 'hub') {\n return resolveHubEntityIds(resolveSidebarHub(item, sidebar));\n }\n return [];\n });\n};\n\nexport const buildEntityGroupLookup = (\n groups: Record<string, BackofficeSidebarGroupConfig>,\n sidebar?: BackofficeSidebarConfig,\n): EntityGroupLookup => {\n const lookup: EntityGroupLookup = new Map();\n\n Object.entries(groups).forEach(([groupId, group]) => {\n resolveGroupItems(group).forEach((item) => {\n if (item.kind === 'dashboard') {\n return;\n }\n\n if (item.kind === 'hub') {\n const hub = resolveSidebarHub(item, sidebar);\n resolveHubEntityIds(hub).forEach((entityId) => {\n if (!lookup.has(entityId)) {\n lookup.set(entityId, {\n groupId,\n groupIcon: group.icon,\n itemIcon: item.icon ?? hub.icon,\n });\n }\n });\n return;\n }\n\n if (!lookup.has(item.id)) {\n lookup.set(item.id, {\n groupId,\n groupIcon: group.icon,\n itemIcon: item.icon,\n });\n }\n });\n });\n\n return lookup;\n};\n\nconst isEntityVisible = (\n entityId: string,\n entities: BackofficeEntityManifestMap,\n sidebar: BackofficeSidebarConfig | undefined,\n permissions: unknown,\n): boolean => {\n const config = entities[entityId];\n if (config == null) {\n return false;\n }\n\n let descriptor: BackofficeSidebarItemDescriptor = {\n kind: 'entity',\n id: entityId,\n };\n if (config.kind === 'tool') {\n descriptor = { kind: 'tool', id: entityId };\n }\n\n if (sidebar?.isItemVisible != null) {\n return sidebar.isItemVisible(descriptor, permissions);\n }\n\n if (config.kind === 'tool') {\n return true;\n }\n return config.hasList;\n};\n\nexport const resolveVisibleEntityIds = (\n groups: Record<string, BackofficeSidebarGroupConfig>,\n entities: BackofficeEntityManifestMap,\n sidebar: BackofficeSidebarConfig | undefined,\n permissions: unknown,\n): string[] => {\n const output: string[] = [];\n const seen = new Set<string>();\n\n Object.entries(groups).forEach(([, group]) => {\n if (group.isVisible != null && !group.isVisible(permissions)) {\n return;\n }\n resolveGroupEntityIds(group, sidebar).forEach((entityId) => {\n if (seen.has(entityId)) {\n return;\n }\n if (!isEntityVisible(entityId, entities, sidebar, permissions)) {\n return;\n }\n seen.add(entityId);\n output.push(entityId);\n });\n });\n\n return output;\n};\n\nexport const resolveActiveEntityId = (\n pathname: string,\n entities: BackofficeEntityManifestMap,\n): string | null => {\n const entries = Object.entries(entities);\n for (const [entityId, config] of entries) {\n if (config.kind === 'tool') {\n if (isActivePath(pathname, config.routes.list)) {\n return entityId;\n }\n } else if (config.hasList && isActivePath(pathname, config.routes.list)) {\n return entityId;\n }\n }\n return null;\n};\n\nexport const resolveActiveGroupId = (\n groups: Record<string, BackofficeSidebarGroupConfig>,\n activeEntityId: string | null,\n entities: BackofficeEntityManifestMap,\n sidebar: BackofficeSidebarConfig | undefined,\n permissions: unknown,\n): string | null => {\n if (activeEntityId == null) {\n return null;\n }\n\n if (!isEntityVisible(activeEntityId, entities, sidebar, permissions)) {\n return null;\n }\n\n for (const [groupId, group] of Object.entries(groups)) {\n const isVisible = group.isVisible == null || group.isVisible(permissions);\n if (\n isVisible &&\n resolveGroupEntityIds(group, sidebar).includes(activeEntityId)\n ) {\n return groupId;\n }\n }\n\n return null;\n};\n"],"mappings":";AAiBA,IAAa,KAAgB,GAAkB,MACtC,EAAM,EAAK,EAGP,KAAgB,GAAkB,MAI7C,GAHI,MAAa,KAGb,MAAS,OAAO,EAAS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ACb,IAAM,IAAmB,EAAE,EACrB,oBAAO,IAAI,KAAa;CAkB9B,OAhBA,OAAO,QAAQ,EAAO,CAAC,SAAS,GAAG,OAAW;EACxC,EAAM,aAAa,QAAQ,CAAC,EAAM,UAAU,EAAY,IAG5D,EAAsB,GAAO,EAAQ,CAAC,SAAS,MAAa;GACtD,EAAK,IAAI,EAAS,IAGjB,EAAgB,GAAU,GAAU,GAAS,EAAY,KAG9D,EAAK,IAAI,EAAS,EAClB,EAAO,KAAK,EAAS;IACrB;GACF,EAEK;GAGI,KACX,GACA,MACkB;CAClB,IAAM,IAAU,OAAO,QAAQ,EAAS;CACxC,KAAK,IAAM,CAAC,GAAU,MAAW,GAC/B,IAAI,EAAO,SAAS;MACd,EAAa,GAAU,EAAO,OAAO,KAAK,EAC5C,OAAO;QAEJ,IAAI,EAAO,WAAW,EAAa,GAAU,EAAO,OAAO,KAAK,EACrE,OAAO;CAGX,OAAO;GAGI,KACX,GACA,GACA,GACA,GACA,MACkB;CAKlB,IAJI,KAAkB,QAIlB,CAAC,EAAgB,GAAgB,GAAU,GAAS,EAAY,EAClE,OAAO;CAGT,KAAK,IAAM,CAAC,GAAS,MAAU,OAAO,QAAQ,EAAO,EAEnD,KADkB,EAAM,aAAa,QAAQ,EAAM,UAAU,EAAY,KAGvE,EAAsB,GAAO,EAAQ,CAAC,SAAS,EAAe,EAE9D,OAAO;CAIX,OAAO"}
1
+ {"version":3,"file":"sidebarUtils.js","names":[],"sources":["../../../../../src/components/backoffice/layout/sidebarUtils.ts"],"sourcesContent":["import type { TFunction } from 'i18next';\n\nimport type {\n BackofficeEntityManifestMap,\n I18nLabel,\n} from '@plumile/backoffice-core/types.js';\nimport type {\n BackofficeSidebarConfig,\n BackofficeIconComponent,\n BackofficeSidebarGroupConfig,\n BackofficeSidebarItemDescriptor,\n BackofficeSidebarItemConfig,\n BackofficeSidebarHubConfig,\n BackofficeSidebarHubGroupConfig,\n BackofficeResolvedSidebarHubConfig,\n} from '../../../provider/types.js';\n\nexport const resolveLabel = (label: I18nLabel, tApp: TFunction): string => {\n return label(tApp);\n};\n\nexport const isActivePath = (pathname: string, href: string): boolean => {\n if (pathname === href) {\n return true;\n }\n if (href !== '/' && pathname.startsWith(`${href}/`)) {\n return true;\n }\n return false;\n};\n\nexport const joinBackofficePath = (\n basePath: string,\n pathSegment: string,\n): string => {\n const normalizedBasePath = basePath.replace(/\\/+$/g, '');\n const normalizedPathSegment = pathSegment.replace(/^\\/+/g, '');\n if (normalizedBasePath === '') {\n return `/${normalizedPathSegment}`;\n }\n return `${normalizedBasePath}/${normalizedPathSegment}`;\n};\n\nexport const buildDefaultGroups = (\n entities: BackofficeEntityManifestMap,\n): Record<string, BackofficeSidebarGroupConfig> => {\n const entityIds = Object.keys(entities);\n\n return {\n main: {\n entities: entityIds,\n },\n };\n};\n\nexport const resolveSidebarGroups = (\n entities: BackofficeEntityManifestMap,\n sidebar: BackofficeSidebarConfig | undefined,\n): Record<string, BackofficeSidebarGroupConfig> => {\n return sidebar?.groups ?? buildDefaultGroups(entities);\n};\n\nexport type EntityGroupLookup = Map<\n string,\n {\n groupId: string;\n groupIcon?: BackofficeIconComponent;\n itemIcon?: BackofficeIconComponent;\n }\n>;\n\nexport const resolveItemDescriptor = (\n item: BackofficeSidebarItemConfig,\n): BackofficeSidebarItemDescriptor => {\n if (item.kind === 'dashboard') {\n return { kind: 'dashboard', id: item.id ?? 'dashboard' };\n }\n return { kind: item.kind, id: item.id };\n};\n\nexport const resolveGroupItems = <\n TManifest extends BackofficeEntityManifestMap = BackofficeEntityManifestMap,\n>(\n group: BackofficeSidebarGroupConfig<TManifest>,\n): readonly BackofficeSidebarItemConfig<TManifest>[] => {\n if (group.items != null) {\n return group.items;\n }\n return (group.entities?.map((entityId) => {\n return { kind: 'entity', id: entityId } as const;\n }) ?? []) as unknown as readonly BackofficeSidebarItemConfig<TManifest>[];\n};\n\nexport type BackofficeResolvedSidebarHubConfigFor<\n TManifest extends BackofficeEntityManifestMap = BackofficeEntityManifestMap,\n> = BackofficeSidebarHubConfig<TManifest> & {\n groups: readonly BackofficeSidebarHubGroupConfig<TManifest>[];\n};\n\nexport const resolveSidebarHubFor = <\n TManifest extends BackofficeEntityManifestMap = BackofficeEntityManifestMap,\n>(\n item: BackofficeSidebarHubConfig<TManifest>,\n sidebar: BackofficeSidebarConfig<TManifest> | undefined,\n): BackofficeResolvedSidebarHubConfigFor<TManifest> => {\n const registeredHub = sidebar?.hubs?.[item.id];\n return {\n ...registeredHub,\n ...item,\n groups: item.groups ?? registeredHub?.groups ?? [],\n };\n};\n\nexport const resolveSidebarHub = (\n item: BackofficeSidebarHubConfig,\n sidebar: BackofficeSidebarConfig | undefined,\n): BackofficeResolvedSidebarHubConfig => {\n return resolveSidebarHubFor(item, sidebar);\n};\n\nexport const resolveHubEntityIds = (\n hub: BackofficeResolvedSidebarHubConfig,\n): readonly string[] => {\n const output: string[] = [];\n const seen = new Set<string>();\n hub.groups.forEach((group) => {\n group.items.forEach((item) => {\n if (seen.has(item.id)) {\n return;\n }\n seen.add(item.id);\n output.push(item.id);\n });\n });\n return output;\n};\n\nexport type ResolvedSidebarHubEntry = {\n groupId: string | null;\n hub: BackofficeResolvedSidebarHubConfig;\n icon?: BackofficeIconComponent;\n};\n\nexport const resolveSidebarHubEntries = (\n groups: Record<string, BackofficeSidebarGroupConfig>,\n sidebar: BackofficeSidebarConfig | undefined,\n): readonly ResolvedSidebarHubEntry[] => {\n const output: ResolvedSidebarHubEntry[] = [];\n const seen = new Set<string>();\n\n Object.entries(groups).forEach(([groupId, group]) => {\n resolveGroupItems(group).forEach((item) => {\n if (item.kind !== 'hub' || seen.has(item.id)) {\n return;\n }\n seen.add(item.id);\n output.push({\n groupId,\n hub: resolveSidebarHub(item, sidebar),\n icon: item.icon ?? group.icon,\n });\n });\n });\n\n Object.values(sidebar?.hubs ?? {}).forEach((hub) => {\n if (seen.has(hub.id)) {\n return;\n }\n seen.add(hub.id);\n output.push({\n groupId: null,\n hub: resolveSidebarHub(hub, sidebar),\n icon: hub.icon,\n });\n });\n\n return output;\n};\n\nexport const resolveGroupEntityIds = (\n group: BackofficeSidebarGroupConfig,\n sidebar?: BackofficeSidebarConfig,\n): readonly string[] => {\n return resolveGroupItems(group).flatMap((item) => {\n if (item.kind === 'entity' || item.kind === 'tool') {\n return [item.id];\n }\n if (item.kind === 'hub') {\n return resolveHubEntityIds(resolveSidebarHub(item, sidebar));\n }\n return [];\n });\n};\n\nexport const buildEntityGroupLookup = (\n groups: Record<string, BackofficeSidebarGroupConfig>,\n sidebar?: BackofficeSidebarConfig,\n): EntityGroupLookup => {\n const lookup: EntityGroupLookup = new Map();\n\n Object.entries(groups).forEach(([groupId, group]) => {\n resolveGroupItems(group).forEach((item) => {\n if (item.kind === 'dashboard') {\n return;\n }\n\n if (item.kind === 'hub') {\n const hub = resolveSidebarHub(item, sidebar);\n resolveHubEntityIds(hub).forEach((entityId) => {\n if (!lookup.has(entityId)) {\n lookup.set(entityId, {\n groupId,\n groupIcon: group.icon,\n itemIcon: item.icon ?? hub.icon,\n });\n }\n });\n return;\n }\n\n if (!lookup.has(item.id)) {\n lookup.set(item.id, {\n groupId,\n groupIcon: group.icon,\n itemIcon: item.icon,\n });\n }\n });\n });\n\n return lookup;\n};\n\nconst isEntityVisible = (\n entityId: string,\n entities: BackofficeEntityManifestMap,\n sidebar: BackofficeSidebarConfig | undefined,\n permissions: unknown,\n): boolean => {\n const config = entities[entityId];\n if (config == null) {\n return false;\n }\n\n let descriptor: BackofficeSidebarItemDescriptor = {\n kind: 'entity',\n id: entityId,\n };\n if (config.kind === 'tool') {\n descriptor = { kind: 'tool', id: entityId };\n }\n\n if (sidebar?.isItemVisible != null) {\n return sidebar.isItemVisible(descriptor, permissions);\n }\n\n if (config.kind === 'tool') {\n return true;\n }\n return config.hasList;\n};\n\nexport const resolveVisibleEntityIds = (\n groups: Record<string, BackofficeSidebarGroupConfig>,\n entities: BackofficeEntityManifestMap,\n sidebar: BackofficeSidebarConfig | undefined,\n permissions: unknown,\n): string[] => {\n const output: string[] = [];\n const seen = new Set<string>();\n\n Object.entries(groups).forEach(([, group]) => {\n if (group.isVisible != null && !group.isVisible(permissions)) {\n return;\n }\n resolveGroupEntityIds(group, sidebar).forEach((entityId) => {\n if (seen.has(entityId)) {\n return;\n }\n if (!isEntityVisible(entityId, entities, sidebar, permissions)) {\n return;\n }\n seen.add(entityId);\n output.push(entityId);\n });\n });\n\n return output;\n};\n\nexport const resolveActiveEntityId = (\n pathname: string,\n entities: BackofficeEntityManifestMap,\n): string | null => {\n const entries = Object.entries(entities);\n for (const [entityId, config] of entries) {\n if (config.kind === 'tool') {\n if (isActivePath(pathname, config.routes.list)) {\n return entityId;\n }\n } else if (config.hasList && isActivePath(pathname, config.routes.list)) {\n return entityId;\n }\n }\n return null;\n};\n\nexport const resolveActiveGroupId = (\n groups: Record<string, BackofficeSidebarGroupConfig>,\n activeEntityId: string | null,\n entities: BackofficeEntityManifestMap,\n sidebar: BackofficeSidebarConfig | undefined,\n permissions: unknown,\n): string | null => {\n if (activeEntityId == null) {\n return null;\n }\n\n if (!isEntityVisible(activeEntityId, entities, sidebar, permissions)) {\n return null;\n }\n\n for (const [groupId, group] of Object.entries(groups)) {\n const isVisible = group.isVisible == null || group.isVisible(permissions);\n if (\n isVisible &&\n resolveGroupEntityIds(group, sidebar).includes(activeEntityId)\n ) {\n return groupId;\n }\n }\n\n return null;\n};\n"],"mappings":";AAiBA,IAAa,KAAgB,GAAkB,MACtC,EAAM,EAAK,EAGP,KAAgB,GAAkB,MAI7C,GAHI,MAAa,KAGb,MAAS,OAAO,EAAS,WAAW,GAAG,EAAK,GAAG,GAMxC,KACX,GACA,MACW;CACX,IAAM,IAAqB,EAAS,QAAQ,SAAS,GAAG,EAClD,IAAwB,EAAY,QAAQ,SAAS,GAAG;CAI9D,OAHI,MAAuB,KAClB,IAAI,MAEN,GAAG,EAAmB,GAAG;GAGrB,KACX,OAIO,EACL,MAAM,EACJ,UAJc,OAAO,KAA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,EAAO,CAAC,SAAS,GAAG,OAAW;EACxC,EAAM,aAAa,QAAQ,CAAC,EAAM,UAAU,EAAY,IAG5D,EAAsB,GAAO,EAAQ,CAAC,SAAS,MAAa;GACtD,EAAK,IAAI,EAAS,IAGjB,EAAgB,GAAU,GAAU,GAAS,EAAY,KAG9D,EAAK,IAAI,EAAS,EAClB,EAAO,KAAK,EAAS;IACrB;GACF,EAEK;GAGI,KACX,GACA,MACkB;CAClB,IAAM,IAAU,OAAO,QAAQ,EAAS;CACxC,KAAK,IAAM,CAAC,GAAU,MAAW,GAC/B,IAAI,EAAO,SAAS;MACd,EAAa,GAAU,EAAO,OAAO,KAAK,EAC5C,OAAO;QAEJ,IAAI,EAAO,WAAW,EAAa,GAAU,EAAO,OAAO,KAAK,EACrE,OAAO;CAGX,OAAO;GAGI,KACX,GACA,GACA,GACA,GACA,MACkB;CAKlB,IAJI,KAAkB,QAIlB,CAAC,EAAgB,GAAgB,GAAU,GAAS,EAAY,EAClE,OAAO;CAGT,KAAK,IAAM,CAAC,GAAS,MAAU,OAAO,QAAQ,EAAO,EAEnD,KADkB,EAAM,aAAa,QAAQ,EAAM,UAAU,EAAY,KAGvE,EAAsB,GAAO,EAAQ,CAAC,SAAS,EAAe,EAE9D,OAAO;CAIX,OAAO"}
@@ -1,81 +1,89 @@
1
- import { resolveSidebarHub as e } from "../layout/sidebarUtils.js";
2
- import { resolveBackofficeTargetIcon as t } from "./resolveBackofficeTargetIcon.js";
3
- import { buildBackofficeFallbackListHref as n } from "@plumile/backoffice-core/state/buildListHref.js";
1
+ import { joinBackofficePath as e, resolveSidebarHub as t } from "../layout/sidebarUtils.js";
2
+ import { resolveBackofficeTargetIcon as n } from "./resolveBackofficeTargetIcon.js";
3
+ import { buildBackofficeFallbackListHref as r } from "@plumile/backoffice-core/state/buildListHref.js";
4
4
  //#region src/components/backoffice/links/resolveBackofficeLink.ts
5
- var r = (e, t) => {
5
+ var i = (e, t) => {
6
6
  let n = e[t];
7
7
  if (n == null) throw Error(`Unknown backoffice entity: ${t}`);
8
8
  return n;
9
- }, i = (t, n) => {
10
- let r = t?.hubs?.[n];
9
+ }, a = (e, n) => {
10
+ let r = e?.hubs?.[n];
11
11
  if (r != null) return r.href;
12
- for (let r of Object.values(t?.groups ?? {})) for (let i of r.items ?? []) if (i.kind === "hub" && i.id === n) return e(i, t).href;
12
+ for (let r of Object.values(e?.groups ?? {})) for (let i of r.items ?? []) if (i.kind === "hub" && i.id === n) return t(i, e).href;
13
13
  throw Error(`Unknown backoffice hub: ${n}`);
14
- }, a = (t, n, r) => {
15
- let i = t?.hubs?.[n];
14
+ }, o = (e, n, r) => {
15
+ let i = e?.hubs?.[n];
16
16
  if (i != null) return i.title(r);
17
- for (let i of Object.values(t?.groups ?? {})) for (let a of i.items ?? []) if (a.kind === "hub" && a.id === n) return e(a, t).title(r);
17
+ for (let i of Object.values(e?.groups ?? {})) for (let a of i.items ?? []) if (a.kind === "hub" && a.id === n) return t(a, e).title(r);
18
18
  return n;
19
- }, o = (e) => {
20
- let o = e.manifest, s = e.sidebar, c = e.target, l = t({
21
- target: e.target,
22
- sidebar: e.sidebar
19
+ }, s = (t) => {
20
+ let s = t.manifest, c = t.sidebar, l = t.target, u = n({
21
+ target: t.target,
22
+ sidebar: t.sidebar
23
23
  });
24
- if (c.kind === "dashboard") return {
25
- id: "dashboard",
26
- href: e.dashboardHref ?? "/",
27
- label: e.label ?? e.dashboardLabel ?? "Dashboard",
28
- icon: l
29
- };
30
- if (c.kind === "entity-list") {
31
- let t = r(o, c.entityId), { state: i } = c, a = t.routes.list;
32
- return i != null && (a = n(t.routes.list, i.where ?? null, i.filters)), {
33
- id: `${c.entityId}-list`,
24
+ if (l.kind === "dashboard") {
25
+ let n = l.id ?? "dashboard", r = t.dashboardHref ?? "/";
26
+ return n === "dashboard" ? {
27
+ id: "dashboard",
28
+ href: r,
29
+ label: t.label ?? t.dashboardLabel ?? "Dashboard",
30
+ icon: u
31
+ } : {
32
+ id: `dashboard-${n}`,
33
+ href: e(r, `dashboard/${n}`),
34
+ label: t.label ?? n,
35
+ icon: u
36
+ };
37
+ }
38
+ if (l.kind === "entity-list") {
39
+ let e = i(s, l.entityId), { state: n } = l, a = e.routes.list;
40
+ return n != null && (a = r(e.routes.list, n.where ?? null, n.filters)), {
41
+ id: `${l.entityId}-list`,
34
42
  href: a,
35
- label: e.label ?? t.label(e.tApp),
36
- icon: l
43
+ label: t.label ?? e.label(t.tApp),
44
+ icon: u
37
45
  };
38
46
  }
39
- if (c.kind === "entity-detail") {
40
- let t = r(o, c.entityId);
47
+ if (l.kind === "entity-detail") {
48
+ let e = i(s, l.entityId);
41
49
  return {
42
- id: `${c.entityId}-entity-${c.id}`,
43
- href: t.routes.detail(c.id),
44
- label: e.label ?? c.id,
45
- icon: l
50
+ id: `${l.entityId}-entity-${l.id}`,
51
+ href: e.routes.detail(l.id),
52
+ label: t.label ?? l.id,
53
+ icon: u
46
54
  };
47
55
  }
48
- if (c.kind === "entity-detail-page") {
49
- let t = r(o, c.entityId);
56
+ if (l.kind === "entity-detail-page") {
57
+ let e = i(s, l.entityId);
50
58
  return {
51
- id: `${c.entityId}-page-${c.id}-${c.pageId}`,
52
- href: t.routes.detailPage(c.id, c.pageId),
53
- label: e.label ?? c.pageId,
54
- icon: l
59
+ id: `${l.entityId}-page-${l.id}-${l.pageId}`,
60
+ href: e.routes.detailPage(l.id, l.pageId),
61
+ label: t.label ?? l.pageId,
62
+ icon: u
55
63
  };
56
64
  }
57
- if (c.kind === "tool") {
58
- let t = r(o, c.toolId);
65
+ if (l.kind === "tool") {
66
+ let e = i(s, l.toolId);
59
67
  return {
60
- id: `tool-${c.toolId}`,
61
- href: t.routes.list,
62
- label: e.label ?? t.label(e.tApp),
63
- icon: l
68
+ id: `tool-${l.toolId}`,
69
+ href: e.routes.list,
70
+ label: t.label ?? e.label(t.tApp),
71
+ icon: u
64
72
  };
65
73
  }
66
- return c.kind === "hub" ? {
67
- id: `hub-${c.hubId}`,
68
- href: i(s, c.hubId),
69
- label: e.label ?? a(s, c.hubId, e.tApp),
70
- icon: l
74
+ return l.kind === "hub" ? {
75
+ id: `hub-${l.hubId}`,
76
+ href: a(c, l.hubId),
77
+ label: t.label ?? o(c, l.hubId, t.tApp),
78
+ icon: u
71
79
  } : {
72
- id: `href-${c.href}`,
73
- href: c.href,
74
- label: e.label ?? c.href,
75
- icon: l
80
+ id: `href-${l.href}`,
81
+ href: l.href,
82
+ label: t.label ?? l.href,
83
+ icon: u
76
84
  };
77
85
  };
78
86
  //#endregion
79
- export { o as resolveBackofficeLink };
87
+ export { s as resolveBackofficeLink };
80
88
 
81
89
  //# sourceMappingURL=resolveBackofficeLink.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveBackofficeLink.js","names":[],"sources":["../../../../../src/components/backoffice/links/resolveBackofficeLink.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport type { TFunction } from 'i18next';\nimport { buildBackofficeFallbackListHref } from '@plumile/backoffice-core/state/buildListHref.js';\nimport type { BackofficeEntityManifestMap } from '@plumile/backoffice-core/types.js';\n\nimport type { BackofficeSidebarConfig } from '../../../provider/types.js';\nimport { resolveSidebarHub } from '../layout/sidebarUtils.js';\nimport { resolveBackofficeTargetIcon } from './resolveBackofficeTargetIcon.js';\nimport type { BackofficeLinkTarget, BackofficeResolvedLink } from './types.js';\n\nconst requireEntity = (\n manifest: BackofficeEntityManifestMap,\n entityId: string,\n) => {\n const entity = manifest[entityId];\n if (entity == null) {\n throw new Error(`Unknown backoffice entity: ${entityId}`);\n }\n return entity;\n};\n\nconst resolveHubHref = (\n sidebar: BackofficeSidebarConfig | undefined,\n hubId: string,\n): string => {\n const registeredHub = sidebar?.hubs?.[hubId];\n if (registeredHub != null) {\n return registeredHub.href;\n }\n\n for (const group of Object.values(sidebar?.groups ?? {})) {\n for (const item of group.items ?? []) {\n if (item.kind === 'hub' && item.id === hubId) {\n return resolveSidebarHub(item, sidebar).href;\n }\n }\n }\n\n throw new Error(`Unknown backoffice hub: ${hubId}`);\n};\n\nconst resolveHubLabel = (\n sidebar: BackofficeSidebarConfig | undefined,\n hubId: string,\n tApp: TFunction,\n): string => {\n const registeredHub = sidebar?.hubs?.[hubId];\n if (registeredHub != null) {\n return registeredHub.title(tApp);\n }\n\n for (const group of Object.values(sidebar?.groups ?? {})) {\n for (const item of group.items ?? []) {\n if (item.kind === 'hub' && item.id === hubId) {\n return resolveSidebarHub(item, sidebar).title(tApp);\n }\n }\n }\n\n return hubId;\n};\n\nexport const resolveBackofficeLink = <\n TManifest extends BackofficeEntityManifestMap,\n>(input: {\n target: BackofficeLinkTarget<TManifest>;\n label?: ReactNode;\n manifest: TManifest;\n sidebar?: BackofficeSidebarConfig<TManifest>;\n tApp: TFunction;\n dashboardHref?: string;\n dashboardLabel?: string;\n}): BackofficeResolvedLink => {\n const manifest = input.manifest as BackofficeEntityManifestMap;\n const sidebar = input.sidebar as BackofficeSidebarConfig | undefined;\n const target = input.target as BackofficeLinkTarget;\n const icon = resolveBackofficeTargetIcon({\n target: input.target,\n sidebar: input.sidebar,\n });\n\n if (target.kind === 'dashboard') {\n const href = input.dashboardHref ?? '/';\n return {\n id: 'dashboard',\n href,\n label: input.label ?? input.dashboardLabel ?? 'Dashboard',\n icon,\n };\n }\n\n if (target.kind === 'entity-list') {\n const entity = requireEntity(manifest, target.entityId);\n const { state } = target;\n let href = entity.routes.list;\n if (state != null) {\n href = buildBackofficeFallbackListHref(\n entity.routes.list,\n state.where ?? null,\n state.filters,\n );\n }\n return {\n id: `${target.entityId}-list`,\n href,\n label: input.label ?? entity.label(input.tApp),\n icon,\n };\n }\n\n if (target.kind === 'entity-detail') {\n const entity = requireEntity(manifest, target.entityId);\n return {\n id: `${target.entityId}-entity-${target.id}`,\n href: entity.routes.detail(target.id),\n label: input.label ?? target.id,\n icon,\n };\n }\n\n if (target.kind === 'entity-detail-page') {\n const entity = requireEntity(manifest, target.entityId);\n return {\n id: `${target.entityId}-page-${target.id}-${target.pageId}`,\n href: entity.routes.detailPage(target.id, target.pageId),\n label: input.label ?? target.pageId,\n icon,\n };\n }\n\n if (target.kind === 'tool') {\n const entity = requireEntity(manifest, target.toolId);\n return {\n id: `tool-${target.toolId}`,\n href: entity.routes.list,\n label: input.label ?? entity.label(input.tApp),\n icon,\n };\n }\n\n if (target.kind === 'hub') {\n return {\n id: `hub-${target.hubId}`,\n href: resolveHubHref(sidebar, target.hubId),\n label: input.label ?? resolveHubLabel(sidebar, target.hubId, input.tApp),\n icon,\n };\n }\n\n return {\n id: `href-${target.href}`,\n href: target.href,\n label: input.label ?? target.href,\n icon,\n };\n};\n"],"mappings":";;;;AAUA,IAAM,KACJ,GACA,MACG;CACH,IAAM,IAAS,EAAS;CACxB,IAAI,KAAU,MACZ,MAAU,MAAM,8BAA8B,IAAW;CAE3D,OAAO;GAGH,KACJ,GACA,MACW;CACX,IAAM,IAAgB,GAAS,OAAO;CACtC,IAAI,KAAiB,MACnB,OAAO,EAAc;CAGvB,KAAK,IAAM,KAAS,OAAO,OAAO,GAAS,UAAU,EAAE,CAAC,EACtD,KAAK,IAAM,KAAQ,EAAM,SAAS,EAAE,EAClC,IAAI,EAAK,SAAS,SAAS,EAAK,OAAO,GACrC,OAAO,EAAkB,GAAM,EAAQ,CAAC;CAK9C,MAAU,MAAM,2BAA2B,IAAQ;GAG/C,KACJ,GACA,GACA,MACW;CACX,IAAM,IAAgB,GAAS,OAAO;CACtC,IAAI,KAAiB,MACnB,OAAO,EAAc,MAAM,EAAK;CAGlC,KAAK,IAAM,KAAS,OAAO,OAAO,GAAS,UAAU,EAAE,CAAC,EACtD,KAAK,IAAM,KAAQ,EAAM,SAAS,EAAE,EAClC,IAAI,EAAK,SAAS,SAAS,EAAK,OAAO,GACrC,OAAO,EAAkB,GAAM,EAAQ,CAAC,MAAM,EAAK;CAKzD,OAAO;GAGI,KAEX,MAQ4B;CAC5B,IAAM,IAAW,EAAM,UACjB,IAAU,EAAM,SAChB,IAAS,EAAM,QACf,IAAO,EAA4B;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EAAgB,GAAS,EAAO,OAAO,EAAM,KAAK;EACxE;EACD,GAGI;EACL,IAAI,QAAQ,EAAO;EACnB,MAAM,EAAO;EACb,OAAO,EAAM,SAAS,EAAO;EAC7B;EACD"}
1
+ {"version":3,"file":"resolveBackofficeLink.js","names":[],"sources":["../../../../../src/components/backoffice/links/resolveBackofficeLink.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport type { TFunction } from 'i18next';\nimport { buildBackofficeFallbackListHref } from '@plumile/backoffice-core/state/buildListHref.js';\nimport type { BackofficeEntityManifestMap } from '@plumile/backoffice-core/types.js';\n\nimport type { BackofficeSidebarConfig } from '../../../provider/types.js';\nimport {\n joinBackofficePath,\n resolveSidebarHub,\n} from '../layout/sidebarUtils.js';\nimport { resolveBackofficeTargetIcon } from './resolveBackofficeTargetIcon.js';\nimport type { BackofficeLinkTarget, BackofficeResolvedLink } from './types.js';\n\nconst requireEntity = (\n manifest: BackofficeEntityManifestMap,\n entityId: string,\n) => {\n const entity = manifest[entityId];\n if (entity == null) {\n throw new Error(`Unknown backoffice entity: ${entityId}`);\n }\n return entity;\n};\n\nconst resolveHubHref = (\n sidebar: BackofficeSidebarConfig | undefined,\n hubId: string,\n): string => {\n const registeredHub = sidebar?.hubs?.[hubId];\n if (registeredHub != null) {\n return registeredHub.href;\n }\n\n for (const group of Object.values(sidebar?.groups ?? {})) {\n for (const item of group.items ?? []) {\n if (item.kind === 'hub' && item.id === hubId) {\n return resolveSidebarHub(item, sidebar).href;\n }\n }\n }\n\n throw new Error(`Unknown backoffice hub: ${hubId}`);\n};\n\nconst resolveHubLabel = (\n sidebar: BackofficeSidebarConfig | undefined,\n hubId: string,\n tApp: TFunction,\n): string => {\n const registeredHub = sidebar?.hubs?.[hubId];\n if (registeredHub != null) {\n return registeredHub.title(tApp);\n }\n\n for (const group of Object.values(sidebar?.groups ?? {})) {\n for (const item of group.items ?? []) {\n if (item.kind === 'hub' && item.id === hubId) {\n return resolveSidebarHub(item, sidebar).title(tApp);\n }\n }\n }\n\n return hubId;\n};\n\nexport const resolveBackofficeLink = <\n TManifest extends BackofficeEntityManifestMap,\n>(input: {\n target: BackofficeLinkTarget<TManifest>;\n label?: ReactNode;\n manifest: TManifest;\n sidebar?: BackofficeSidebarConfig<TManifest>;\n tApp: TFunction;\n dashboardHref?: string;\n dashboardLabel?: string;\n}): BackofficeResolvedLink => {\n const manifest = input.manifest as BackofficeEntityManifestMap;\n const sidebar = input.sidebar as BackofficeSidebarConfig | undefined;\n const target = input.target as BackofficeLinkTarget;\n const icon = resolveBackofficeTargetIcon({\n target: input.target,\n sidebar: input.sidebar,\n });\n\n if (target.kind === 'dashboard') {\n const dashboardId = target.id ?? 'dashboard';\n const href = input.dashboardHref ?? '/';\n if (dashboardId !== 'dashboard') {\n return {\n id: `dashboard-${dashboardId}`,\n href: joinBackofficePath(href, `dashboard/${dashboardId}`),\n label: input.label ?? dashboardId,\n icon,\n };\n }\n return {\n id: 'dashboard',\n href,\n label: input.label ?? input.dashboardLabel ?? 'Dashboard',\n icon,\n };\n }\n\n if (target.kind === 'entity-list') {\n const entity = requireEntity(manifest, target.entityId);\n const { state } = target;\n let href = entity.routes.list;\n if (state != null) {\n href = buildBackofficeFallbackListHref(\n entity.routes.list,\n state.where ?? null,\n state.filters,\n );\n }\n return {\n id: `${target.entityId}-list`,\n href,\n label: input.label ?? entity.label(input.tApp),\n icon,\n };\n }\n\n if (target.kind === 'entity-detail') {\n const entity = requireEntity(manifest, target.entityId);\n return {\n id: `${target.entityId}-entity-${target.id}`,\n href: entity.routes.detail(target.id),\n label: input.label ?? target.id,\n icon,\n };\n }\n\n if (target.kind === 'entity-detail-page') {\n const entity = requireEntity(manifest, target.entityId);\n return {\n id: `${target.entityId}-page-${target.id}-${target.pageId}`,\n href: entity.routes.detailPage(target.id, target.pageId),\n label: input.label ?? target.pageId,\n icon,\n };\n }\n\n if (target.kind === 'tool') {\n const entity = requireEntity(manifest, target.toolId);\n return {\n id: `tool-${target.toolId}`,\n href: entity.routes.list,\n label: input.label ?? entity.label(input.tApp),\n icon,\n };\n }\n\n if (target.kind === 'hub') {\n return {\n id: `hub-${target.hubId}`,\n href: resolveHubHref(sidebar, target.hubId),\n label: input.label ?? resolveHubLabel(sidebar, target.hubId, input.tApp),\n icon,\n };\n }\n\n return {\n id: `href-${target.href}`,\n href: target.href,\n label: input.label ?? target.href,\n icon,\n };\n};\n"],"mappings":";;;;AAaA,IAAM,KACJ,GACA,MACG;CACH,IAAM,IAAS,EAAS;CACxB,IAAI,KAAU,MACZ,MAAU,MAAM,8BAA8B,IAAW;CAE3D,OAAO;GAGH,KACJ,GACA,MACW;CACX,IAAM,IAAgB,GAAS,OAAO;CACtC,IAAI,KAAiB,MACnB,OAAO,EAAc;CAGvB,KAAK,IAAM,KAAS,OAAO,OAAO,GAAS,UAAU,EAAE,CAAC,EACtD,KAAK,IAAM,KAAQ,EAAM,SAAS,EAAE,EAClC,IAAI,EAAK,SAAS,SAAS,EAAK,OAAO,GACrC,OAAO,EAAkB,GAAM,EAAQ,CAAC;CAK9C,MAAU,MAAM,2BAA2B,IAAQ;GAG/C,KACJ,GACA,GACA,MACW;CACX,IAAM,IAAgB,GAAS,OAAO;CACtC,IAAI,KAAiB,MACnB,OAAO,EAAc,MAAM,EAAK;CAGlC,KAAK,IAAM,KAAS,OAAO,OAAO,GAAS,UAAU,EAAE,CAAC,EACtD,KAAK,IAAM,KAAQ,EAAM,SAAS,EAAE,EAClC,IAAI,EAAK,SAAS,SAAS,EAAK,OAAO,GACrC,OAAO,EAAkB,GAAM,EAAQ,CAAC,MAAM,EAAK;CAKzD,OAAO;GAGI,KAEX,MAQ4B;CAC5B,IAAM,IAAW,EAAM,UACjB,IAAU,EAAM,SAChB,IAAS,EAAM,QACf,IAAO,EAA4B;EACvC,QAAQ,EAAM;EACd,SAAS,EAAM;EAChB,CAAC;CAEF,IAAI,EAAO,SAAS,aAAa;EAC/B,IAAM,IAAc,EAAO,MAAM,aAC3B,IAAO,EAAM,iBAA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,OAAO,EAAM,SAAS,EAAgB,GAAS,EAAO,OAAO,EAAM,KAAK;EACxE;EACD,GAGI;EACL,IAAI,QAAQ,EAAO;EACnB,MAAM,EAAO;EACb,OAAO,EAAM,SAAS,EAAO;EAC7B;EACD"}
@@ -2,7 +2,7 @@ import { resolveGroupItems as e, resolveSidebarHubFor as t } from "../layout/sid
2
2
  //#region src/components/backoffice/links/resolveBackofficeTargetIcon.ts
3
3
  var n = (e) => e.kind === "dashboard" ? {
4
4
  kind: "dashboard",
5
- id: "dashboard"
5
+ id: e.id ?? "dashboard"
6
6
  } : e.kind === "entity-list" || e.kind === "entity-detail" || e.kind === "entity-detail-page" ? {
7
7
  kind: "entity",
8
8
  id: e.entityId
@@ -1 +1 @@
1
- {"version":3,"file":"resolveBackofficeTargetIcon.js","names":[],"sources":["../../../../../src/components/backoffice/links/resolveBackofficeTargetIcon.ts"],"sourcesContent":["import type { BackofficeEntityManifestMap } from '@plumile/backoffice-core/types.js';\n\nimport type {\n BackofficeIconComponent,\n BackofficeSidebarConfig,\n BackofficeSidebarGroupConfig,\n BackofficeSidebarItemConfig,\n} from '../../../provider/types.js';\nimport {\n resolveGroupItems,\n resolveSidebarHubFor,\n} from '../layout/sidebarUtils.js';\nimport type { BackofficeLinkTarget } from './types.js';\n\nconst getTargetId = (\n target: BackofficeLinkTarget,\n): { kind: 'dashboard' | 'entity' | 'tool' | 'hub' | 'href'; id: string } => {\n if (target.kind === 'dashboard') {\n return { kind: 'dashboard', id: 'dashboard' };\n }\n if (target.kind === 'entity-list') {\n return { kind: 'entity', id: target.entityId };\n }\n if (target.kind === 'entity-detail') {\n return { kind: 'entity', id: target.entityId };\n }\n if (target.kind === 'entity-detail-page') {\n return { kind: 'entity', id: target.entityId };\n }\n if (target.kind === 'tool') {\n return { kind: 'tool', id: target.toolId };\n }\n if (target.kind === 'hub') {\n return { kind: 'hub', id: target.hubId };\n }\n return { kind: 'href', id: target.href };\n};\n\nconst resolveItemIcon = <TManifest extends BackofficeEntityManifestMap>(\n item: BackofficeSidebarItemConfig<TManifest>,\n target: ReturnType<typeof getTargetId>,\n group: BackofficeSidebarGroupConfig<TManifest>,\n sidebar: BackofficeSidebarConfig<TManifest> | undefined,\n): BackofficeIconComponent | undefined => {\n if (target.kind === 'dashboard') {\n if (item.kind === 'dashboard' && (item.id ?? 'dashboard') === target.id) {\n return item.icon ?? group.icon;\n }\n return undefined;\n }\n\n if (target.kind === 'hub') {\n if (item.kind === 'hub' && item.id === target.id) {\n const hub = resolveSidebarHubFor(item, sidebar);\n return item.icon ?? hub.icon ?? group.icon;\n }\n return undefined;\n }\n\n if (target.kind === 'entity' || target.kind === 'tool') {\n if (item.kind === target.kind && item.id === target.id) {\n return item.icon ?? group.icon;\n }\n\n if (item.kind === 'hub') {\n const hub = resolveSidebarHubFor(item, sidebar);\n for (const hubGroup of hub.groups) {\n const hubItem = hubGroup.items.find((candidate) => {\n return candidate.kind === target.kind && candidate.id === target.id;\n });\n if (hubItem != null) {\n return (\n hubItem.icon ?? hubGroup.icon ?? item.icon ?? hub.icon ?? group.icon\n );\n }\n }\n }\n }\n\n return undefined;\n};\n\nexport const resolveBackofficeTargetIcon = <\n TManifest extends BackofficeEntityManifestMap,\n>(input: {\n target: BackofficeLinkTarget<TManifest>;\n sidebar?: BackofficeSidebarConfig<TManifest>;\n}): BackofficeIconComponent | undefined => {\n const target = getTargetId(input.target);\n if (target.kind === 'href') {\n return undefined;\n }\n\n for (const group of Object.values(input.sidebar?.groups ?? {})) {\n for (const item of resolveGroupItems(group)) {\n const icon = resolveItemIcon(item, target, group, input.sidebar);\n if (icon != null) {\n return icon;\n }\n }\n }\n\n if (target.kind === 'hub') {\n return input.sidebar?.hubs?.[target.id]?.icon;\n }\n\n return undefined;\n};\n"],"mappings":";;AAcA,IAAM,KACJ,MAEI,EAAO,SAAS,cACX;CAAE,MAAM;CAAa,IAAI;CAAa,GAE3C,EAAO,SAAS,iBAGhB,EAAO,SAAS,mBAGhB,EAAO,SAAS,uBAC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AAO;;EAKb,IAAI,EAAO,SAAS,OAClB,OAAO,EAAM,SAAS,OAAO,EAAO,KAAK"}
1
+ {"version":3,"file":"resolveBackofficeTargetIcon.js","names":[],"sources":["../../../../../src/components/backoffice/links/resolveBackofficeTargetIcon.ts"],"sourcesContent":["import type { BackofficeEntityManifestMap } from '@plumile/backoffice-core/types.js';\n\nimport type {\n BackofficeIconComponent,\n BackofficeSidebarConfig,\n BackofficeSidebarGroupConfig,\n BackofficeSidebarItemConfig,\n} from '../../../provider/types.js';\nimport {\n resolveGroupItems,\n resolveSidebarHubFor,\n} from '../layout/sidebarUtils.js';\nimport type { BackofficeLinkTarget } from './types.js';\n\nconst getTargetId = (\n target: BackofficeLinkTarget,\n): { kind: 'dashboard' | 'entity' | 'tool' | 'hub' | 'href'; id: string } => {\n if (target.kind === 'dashboard') {\n return { kind: 'dashboard', id: target.id ?? 'dashboard' };\n }\n if (target.kind === 'entity-list') {\n return { kind: 'entity', id: target.entityId };\n }\n if (target.kind === 'entity-detail') {\n return { kind: 'entity', id: target.entityId };\n }\n if (target.kind === 'entity-detail-page') {\n return { kind: 'entity', id: target.entityId };\n }\n if (target.kind === 'tool') {\n return { kind: 'tool', id: target.toolId };\n }\n if (target.kind === 'hub') {\n return { kind: 'hub', id: target.hubId };\n }\n return { kind: 'href', id: target.href };\n};\n\nconst resolveItemIcon = <TManifest extends BackofficeEntityManifestMap>(\n item: BackofficeSidebarItemConfig<TManifest>,\n target: ReturnType<typeof getTargetId>,\n group: BackofficeSidebarGroupConfig<TManifest>,\n sidebar: BackofficeSidebarConfig<TManifest> | undefined,\n): BackofficeIconComponent | undefined => {\n if (target.kind === 'dashboard') {\n if (item.kind === 'dashboard' && (item.id ?? 'dashboard') === target.id) {\n return item.icon ?? group.icon;\n }\n return undefined;\n }\n\n if (target.kind === 'hub') {\n if (item.kind === 'hub' && item.id === target.id) {\n const hub = resolveSidebarHubFor(item, sidebar);\n return item.icon ?? hub.icon ?? group.icon;\n }\n return undefined;\n }\n\n if (target.kind === 'entity' || target.kind === 'tool') {\n if (item.kind === target.kind && item.id === target.id) {\n return item.icon ?? group.icon;\n }\n\n if (item.kind === 'hub') {\n const hub = resolveSidebarHubFor(item, sidebar);\n for (const hubGroup of hub.groups) {\n const hubItem = hubGroup.items.find((candidate) => {\n return candidate.kind === target.kind && candidate.id === target.id;\n });\n if (hubItem != null) {\n return (\n hubItem.icon ?? hubGroup.icon ?? item.icon ?? hub.icon ?? group.icon\n );\n }\n }\n }\n }\n\n return undefined;\n};\n\nexport const resolveBackofficeTargetIcon = <\n TManifest extends BackofficeEntityManifestMap,\n>(input: {\n target: BackofficeLinkTarget<TManifest>;\n sidebar?: BackofficeSidebarConfig<TManifest>;\n}): BackofficeIconComponent | undefined => {\n const target = getTargetId(input.target);\n if (target.kind === 'href') {\n return undefined;\n }\n\n for (const group of Object.values(input.sidebar?.groups ?? {})) {\n for (const item of resolveGroupItems(group)) {\n const icon = resolveItemIcon(item, target, group, input.sidebar);\n if (icon != null) {\n return icon;\n }\n }\n }\n\n if (target.kind === 'hub') {\n return input.sidebar?.hubs?.[target.id]?.icon;\n }\n\n return undefined;\n};\n"],"mappings":";;AAcA,IAAM,KACJ,MAEI,EAAO,SAAS,cACX;CAAE,MAAM;CAAa,IAAI,EAAO,MAAM;CAAa,GAExD,EAAO,SAAS,iBAGhB,EAAO,SAAS,mBAGhB,EAAO,SAAS,uBACX;CAAE,MAAM;CAAU,IAAI,EAAO;CAAU,GAE5C,EAAO,SAAS,SACX;CAAE,MAAM;CAAQ,IAAI,EAAO;CAAQ,GAExC,EAAO,SAAS,QACX;CAAE,MAAM;CAAO,IAAI,EAAO;CAAO,GAEnC;CAAE,MAAM;CAAQ,IAAI,EAAO;CAAM,EAGpC,KACJ,GACA,GACA,GACA,MACwC;CACxC,IAAI,EAAO,SAAS,aAIlB,OAHI,EAAK,SAAS,gBAAgB,EAAK,MAAM,iBAAiB,EAAO,KAC5D,EAAK,QAAQ,EAAM,OAE5B;CAGF,IAA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