@stacksjs/defaults 0.75.490 → 0.75.493

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 (26) hide show
  1. package/ai/skills/stacks-actions/SKILL.md +1 -1
  2. package/ai/skills/stacks-dashboard/SKILL.md +8 -0
  3. package/ai/skills/stacks-models/SKILL.md +11 -0
  4. package/ai/skills/stacks-native/CATALOG.md +2 -2
  5. package/app/Actions/Dashboard/Commerce/ProductUnitIndexAction.ts +23 -19
  6. package/app/Actions/Dashboard/Commerce/ProductVariantIndexAction.ts +25 -18
  7. package/app/Actions/Dashboard/Commerce/commerce-product-unit-list.test.ts +146 -0
  8. package/app/Actions/Dashboard/Commerce/commerce-product-unit-list.ts +178 -0
  9. package/app/Actions/Dashboard/Commerce/commerce-product-variant-list.test.ts +165 -0
  10. package/app/Actions/Dashboard/Commerce/commerce-product-variant-list.ts +209 -0
  11. package/app/Actions/Dashboard/Commerce/product-unit-records.test.ts +0 -13
  12. package/app/Actions/Dashboard/Commerce/product-unit-records.ts +0 -17
  13. package/app/Actions/Dashboard/Commerce/product-variant-records.test.ts +0 -13
  14. package/app/Actions/Dashboard/Commerce/product-variant-records.ts +0 -17
  15. package/functions/dashboard-list.test.ts +14 -0
  16. package/functions/dashboard-list.ts +21 -3
  17. package/ide/vscode/package.json +1 -1
  18. package/package.json +2 -2
  19. package/resources/components/Dashboard/Commerce/CommerceUnitDialog.stx +63 -8
  20. package/resources/components/Dashboard/Commerce/CommerceUnitsDashboard.stx +48 -60
  21. package/resources/components/Dashboard/Commerce/CommerceUnitsTable.stx +29 -3
  22. package/resources/components/Dashboard/Commerce/CommerceVariantDialog.stx +57 -3
  23. package/resources/components/Dashboard/Commerce/CommerceVariantsDashboard.stx +59 -61
  24. package/resources/components/Dashboard/Commerce/CommerceVariantsTable.stx +28 -2
  25. package/resources/functions/dashboard/sidebar.ts +50 -16
  26. package/views/dashboard/layouts/default.stx +2 -10
@@ -18,6 +18,7 @@ type ModelCategory = 'userland' | 'data' | 'commerce' | 'content' | 'marketing'
18
18
  * full type imports aren't available. Keep in sync with the source.
19
19
  */
20
20
  interface DashboardModelOptionsLite {
21
+ highlight?: boolean | number
21
22
  access?: boolean
22
23
  enabled?: boolean
23
24
  label?: string
@@ -102,6 +103,9 @@ export const DEFAULT_TOGGLES: DashboardSectionToggles = {
102
103
  }
103
104
 
104
105
  interface NavItem {
106
+ id?: string
107
+ children?: NavItem[]
108
+ expanded?: boolean
105
109
  to: string
106
110
  icon: string
107
111
  text: string
@@ -413,13 +417,13 @@ export function buildNavSections(
413
417
  ...categoryNavItems(discoveredModels, 'system', new Set()),
414
418
  ]])
415
419
 
416
- // Data section: configurable basic rows + ALL userland models + any
417
- // root-level framework `data` models. Per-row toggles let projects hide
418
- // the basic rows they don't need; userland models always appear.
420
+ // Data pins model-declared highlights. Other visible models stay accessible
421
+ // through a collapsed disclosure using the shared Sidebar component.
419
422
  // Per-model rows link to `/models/<id>` (dynamic ORM viewer); the
420
423
  // built-in dashboard / activity / users / teams / subscribers rows keep
421
424
  // their bespoke pages under `/data/<row>`.
422
425
  const dataRows = toggles.data ?? DEFAULT_DATA_TOGGLES
426
+ const dedicatedDataRows: Record<string, keyof DataRowToggles> = { user: 'users', team: 'teams', subscriber: 'subscribers', activity: 'activity' }
423
427
  const dataNav: NavItem[] = []
424
428
  if (dataRows.dashboard) dataNav.push({ to: '/data/dashboard', icon: 'dashboard', text: 'Dashboard' })
425
429
  if (dataRows.activity) dataNav.push({ to: '/data/activity', icon: 'activity', text: 'Activity' })
@@ -427,23 +431,36 @@ export function buildNavSections(
427
431
  if (dataRows.teams) dataNav.push({ to: '/data/teams', icon: 'group', text: 'Teams' })
428
432
  if (dataRows.subscribers) dataNav.push({ to: '/data/subscribers', icon: 'mail', text: 'Subscribers' })
429
433
  if (dataRows.allModels) dataNav.push({ to: '/models', icon: 'table', text: 'All Models' })
430
- for (const m of discoveredModels) {
434
+ const moreModels: NavItem[] = []
435
+ const highlighted = (model: DiscoveredModel) => model.dashboard?.highlight === true
436
+ || (typeof model.dashboard?.highlight === 'number' && Number.isFinite(model.dashboard.highlight))
437
+ const rank = (model: DiscoveredModel) => typeof model.dashboard?.highlight === 'number' ? model.dashboard.highlight : Number.POSITIVE_INFINITY
438
+ const dataModels = [...discoveredModels].sort((a, b) => {
439
+ if (highlighted(a) !== highlighted(b)) return highlighted(a) ? -1 : 1
440
+ if (highlighted(a)) return rank(a) - rank(b) || a.name.localeCompare(b.name)
441
+ return a.name.localeCompare(b.name)
442
+ })
443
+ for (const m of dataModels) {
431
444
  // Skip when:
432
445
  // - explicit `dashboard.enabled === false` (effectiveCategory returns undefined)
433
446
  // - pinned to a different section via `dashboard.section`
434
447
  // - already has a dedicated dashboard page
435
448
  const eff = effectiveCategory(m)
436
449
  if (eff !== 'userland' && eff !== 'data') continue
437
- if (m.hasDedicatedPage) continue
438
- dataNav.push({
450
+ const dedicatedRow = dedicatedDataRows[m.id]
451
+ if (m.hasDedicatedPage && (!dedicatedRow || dataRows[dedicatedRow])) continue
452
+ const item: NavItem = {
439
453
  to: `/models/${m.id}`,
440
454
  icon: m.dashboard?.icon ?? m.icon ?? 'table',
441
455
  text: m.dashboard?.label ?? m.name,
442
456
  ...(m.dashboard?.roles && m.dashboard.roles.length > 0
443
457
  ? { roles: m.dashboard.roles }
444
458
  : {}),
445
- })
459
+ }
460
+ if (highlighted(m)) dataNav.push(item)
461
+ else moreModels.push(item)
446
462
  }
463
+ if (moreModels.length) dataNav.push({ id: 'models-more', to: '', text: 'More models', icon: 'table', expanded: false, children: moreModels })
447
464
  sections.push(['data', 'data', dataNav])
448
465
 
449
466
  if (toggles.commerce) {
@@ -650,7 +667,9 @@ export interface WebSidebarItem {
650
667
  icon: string
651
668
  /** macOS system color name or CSS color for the icon tint. */
652
669
  iconColor: string
653
- href: string
670
+ href?: string
671
+ children?: WebSidebarItem[]
672
+ expanded?: boolean
654
673
  roles?: string[]
655
674
  }
656
675
 
@@ -726,6 +745,15 @@ export function buildWebSidebarSections(): WebSidebarSection[] {
726
745
  const appNav = manifest.nav.length > 0 ? manifest.nav : loadAppNavFromConfig()
727
746
  const sections = filterSchemaNavSections(buildNavSections(manifest.models, manifest.sections, appNav), manifest.schemaModels)
728
747
 
748
+ const webItem = (item: NavItem): WebSidebarItem => ({
749
+ id: item.id ?? navItemId(item.to),
750
+ label: item.text,
751
+ icon: resolveNavIcon(item.icon),
752
+ iconColor: 'blue',
753
+ ...(item.to ? { href: item.to } : {}),
754
+ ...(item.roles?.length ? { roles: item.roles } : {}),
755
+ ...(item.children ? { children: item.children.map(webItem), expanded: item.expanded ?? false } : {}),
756
+ })
729
757
  return [
730
758
  {
731
759
  id: 'top',
@@ -735,14 +763,20 @@ export function buildWebSidebarSections(): WebSidebarSection[] {
735
763
  ...sections.map(([key, label, items]) => ({
736
764
  id: key,
737
765
  label: titleCase(label),
738
- items: items.map(item => ({
739
- id: navItemId(item.to),
740
- label: item.text,
741
- icon: resolveNavIcon(item.icon),
742
- iconColor: 'blue',
743
- href: item.to,
744
- ...(item.roles && item.roles.length > 0 ? { roles: item.roles } : {}),
745
- })),
766
+ items: items.map(webItem),
746
767
  })),
747
768
  ]
748
769
  }
770
+
771
+ /** Role metadata follows nested model rows as well as pinned rows. */
772
+ export function webSidebarRoleMap(sections: WebSidebarSection[]): Record<string, string[]> {
773
+ const roles: Record<string, string[]> = Object.create(null)
774
+ const visit = (items: WebSidebarItem[]) => {
775
+ for (const item of items) {
776
+ if (item.roles?.length) roles[item.id] = item.roles
777
+ if (item.children) visit(item.children)
778
+ }
779
+ }
780
+ for (const section of sections) visit(section.items)
781
+ return roles
782
+ }
@@ -16,7 +16,7 @@
16
16
  // vendored or linked. `@stacksjs/defaults/*` is mapped onto the vendored tree in
17
17
  // `storage/framework/tsconfig.app.json` and falls back to the installed
18
18
  // package when there is none, so it resolves in both layouts.
19
- import { buildWebSidebarSections } from '@stacksjs/defaults/resources/functions/dashboard/sidebar'
19
+ import { buildWebSidebarSections, webSidebarRoleMap } from '@stacksjs/defaults/resources/functions/dashboard/sidebar'
20
20
 
21
21
  export const sidebarSections = buildWebSidebarSections()
22
22
 
@@ -31,15 +31,7 @@ export const sidebarSections = buildWebSidebarSections()
31
31
  // then ran `Object.entries` over that string, which yields index/character
32
32
  // pairs, and called `.some()` on a single character. Every dashboard load
33
33
  // threw inside applyRoleFilter before it could filter anything.
34
- export const sidebarRoleMap: Record<string, string[]> = Object.fromEntries(
35
- sidebarSections.flatMap(section =>
36
- section.items.flatMap(item =>
37
- item.roles && item.roles.length > 0
38
- ? [[item.id, item.roles] as const]
39
- : [],
40
- ),
41
- ),
42
- )
34
+ export const sidebarRoleMap: Record<string, string[]> = webSidebarRoleMap(sidebarSections)
43
35
 
44
36
  // Declared, so the client block below gets the map typed rather than inferred
45
37
  // off the implicit bridge - which is what let the mismatch above go unseen.