@stacksjs/defaults 0.75.569 → 0.75.572

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 (77) hide show
  1. package/ai/skills/stacks-actions/SKILL.md +1 -1
  2. package/ai/skills/stacks-cms/SKILL.md +1 -1
  3. package/ai/skills/stacks-dashboard/SKILL.md +283 -12
  4. package/ai/skills/stacks-database/SKILL.md +50 -0
  5. package/ai/skills/stacks-http/SKILL.md +33 -2
  6. package/ai/skills/stacks-native/CATALOG.md +8 -8
  7. package/ai/skills/stacks-orm/SKILL.md +20 -10
  8. package/ai/skills/stacks-query-builder/SKILL.md +7 -0
  9. package/app/Actions/Dashboard/Commerce/commerce-sql.ts +1 -1
  10. package/app/Actions/Dashboard/Content/CommentUpdateAction.ts +1 -1
  11. package/app/Actions/Dashboard/Content/PostStoreAction.ts +1 -1
  12. package/app/Actions/Dashboard/Content/PostUpdateAction.ts +1 -1
  13. package/app/Actions/Dashboard/Content/comment-list.ts +2 -2
  14. package/app/Actions/Dashboard/Content/page-list.ts +2 -2
  15. package/app/Actions/Dashboard/Content/post-list.ts +2 -2
  16. package/app/Actions/Dashboard/Infrastructure/InsightsAction.ts +24 -19
  17. package/app/Actions/Dashboard/Infrastructure/log-provider.ts +4 -4
  18. package/app/Actions/Dashboard/Jobs/job-list.ts +1 -1
  19. package/app/Actions/Dashboard/Kanban/BoardShowAction.ts +2 -2
  20. package/app/Actions/Dashboard/Kanban/CardShowAction.ts +3 -3
  21. package/app/Actions/Dashboard/Kanban/card-attachments.ts +1 -1
  22. package/app/Actions/Dashboard/Marketing/marketing-list-records.test.ts +2 -2
  23. package/app/Actions/Dashboard/Marketing/marketing-list-records.ts +4 -4
  24. package/app/Actions/Dashboard/Models/ModelShowAction.ts +42 -43
  25. package/app/Actions/Dashboard/Models/ModelUpdateAction.ts +17 -3
  26. package/app/Actions/Dashboard/Models/model-filters.ts +429 -0
  27. package/app/Actions/Dashboard/Models/model-switches.ts +159 -0
  28. package/app/Actions/Dashboard/Models/model-write.ts +6 -0
  29. package/app/Actions/Dashboard/Notifications/NotificationDeliveryOverviewAction.ts +1 -1
  30. package/app/Actions/Dashboard/Queries/query-list.ts +1 -1
  31. package/app/Actions/Dashboard/Queue/queue-stats.ts +2 -2
  32. package/app/Actions/Dashboard/named-search.ts +1 -1
  33. package/app/Models/Comment.ts +3 -3
  34. package/app/Models/Content/Post.ts +3 -3
  35. package/app/Models/EmailList.ts +8 -6
  36. package/app/Models/Subscriber.ts +2 -0
  37. package/app/Models/Team.ts +2 -0
  38. package/app/Models/User.ts +3 -0
  39. package/functions/dashboard-model-filters.ts +219 -0
  40. package/functions/dashboard-model-record.ts +42 -8
  41. package/ide/vscode/package.json +1 -1
  42. package/package.json +3 -3
  43. package/resources/components/Dashboard/Commerce/CommerceCategoryDialog.stx +3 -1
  44. package/resources/components/Dashboard/Commerce/CommerceCouponDialog.stx +3 -1
  45. package/resources/components/Dashboard/Commerce/CommerceGiftCardDialog.stx +9 -3
  46. package/resources/components/Dashboard/Commerce/CommerceManufacturerDialog.stx +3 -4
  47. package/resources/components/Dashboard/Commerce/CommerceProductDialog.stx +3 -1
  48. package/resources/components/Dashboard/Commerce/CommerceReviewEditDialog.stx +6 -8
  49. package/resources/components/Dashboard/Commerce/CommerceTaxDialog.stx +6 -14
  50. package/resources/components/Dashboard/Commerce/CommerceUnitDialog.stx +3 -7
  51. package/resources/components/Dashboard/Commerce/Delivery/DigitalDeliveryDialog.stx +6 -2
  52. package/resources/components/Dashboard/Content/BlogPostEditorDialog.stx +2 -8
  53. package/resources/components/Dashboard/Content/PageEditorDialog.stx +3 -7
  54. package/resources/components/Dashboard/Content/PostEditorDialog.stx +3 -4
  55. package/resources/components/Dashboard/Data/DataModelRecords.stx +12 -75
  56. package/resources/components/Dashboard/Data/DataStatCards.stx +110 -0
  57. package/resources/components/Dashboard/Email/InboxSettingsDashboard.stx +20 -36
  58. package/resources/components/Dashboard/Marketing/MarketingListDialog.stx +7 -14
  59. package/resources/components/Dashboard/Marketing/MarketingListsDashboard.stx +3 -2
  60. package/resources/components/Dashboard/Models/ModelFieldInputs.stx +10 -13
  61. package/resources/components/Dashboard/Models/ModelFilterPanel.stx +166 -0
  62. package/resources/components/Dashboard/Models/ModelRecordDetail.stx +18 -0
  63. package/resources/components/Dashboard/Models/ModelRecordEdit.stx +3 -2
  64. package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +96 -29
  65. package/resources/components/Dashboard/Models/ModelRegion.stx +25 -0
  66. package/resources/components/Dashboard/Models/ModelRegionFor.stx +31 -0
  67. package/resources/components/Dashboard/Operations/RecoveryDestinationDialog.stx +2 -2
  68. package/resources/components/Dashboard/Operations/RecoveryPolicyDialog.stx +3 -1
  69. package/resources/components/Dashboard/Operations/RecoveryRestoreDialog.stx +3 -1
  70. package/resources/components/Dashboard/Settings/AppearanceSettingsDashboard.stx +11 -14
  71. package/resources/components/Dashboard/Settings/SettingsDashboard.stx +6 -9
  72. package/resources/components/Dashboard/UI/Toggle.stx +16 -12
  73. package/resources/functions/dashboard/regions.ts +113 -0
  74. package/resources/functions/dashboard/sidebar.ts +2 -0
  75. package/views/dashboard/composables/useModelList.ts +52 -0
  76. package/views/dashboard/composables/useModelRecord.ts +46 -0
  77. package/views/dashboard/stores/model-page.ts +105 -0
@@ -12,6 +12,7 @@ import type { ModelCustomAction, ModelRecord, ModelRelatedPanel } from '../../..
12
12
  import { deleteModelRecord, fetchModelRecord, fetchModelRelated, modelActionAsks, modelActionIconClass, modelActionNotice, modelDeleteNotice, modelDeleteWarning, modelNameFromSlug, modelRecordBackHref, modelRecordEditHref, modelRecordHref, modelRecordListLabel, modelRecordSections, modelRecordTitle, runModelAction } from '../../../../functions/dashboard-model-record'
13
13
  import { dashboardLoaderTimer, dashboardReloadingClass } from '../../../../functions/dashboard-loading'
14
14
  import { pushToast } from '../../../../functions/toasts'
15
+ import { modelPageStore } from '@stacksjs/defaults/views/dashboard/stores/model-page'
15
16
 
16
17
  const navigation = useNavigation()
17
18
  const record = state<ModelRecord | null>(null)
@@ -72,11 +73,14 @@ async function loadRecord(): Promise<void> {
72
73
  try {
73
74
  const loaded = await fetchModelRecord(slug(), recordId())
74
75
  record.set(loaded)
76
+ // For a component the app placed on this page: it follows the record.
77
+ modelPageStore.showRecord(slug(), recordId(), loaded)
75
78
  // Not awaited, and a page whose panels cannot be read is still the record's page.
76
79
  void fetchModelRelated(slug(), recordId()).then(panels => related.set(panels)).catch(() => related.set([]))
77
80
  }
78
81
  catch (error) {
79
82
  record.set(null)
83
+ modelPageStore.showRecord(slug(), recordId(), null)
80
84
  related.set([])
81
85
  loadError.set(error instanceof Error ? error.message : 'This record could not be loaded.')
82
86
  }
@@ -172,9 +176,17 @@ function submitAction(input: Record<string, unknown>): void {
172
176
  void runAction(action, input)
173
177
  }
174
178
 
179
+ // Said before anything is loaded: which record this page is for, so a
180
+ // component the app placed here never shows the record of the page before.
181
+ modelPageStore.openRecord(slug(), recordId(), () => { void loadRecord() })
182
+
175
183
  onMount(() => {
176
184
  void loadRecord()
177
185
  })
186
+
187
+ onDestroy(() => {
188
+ modelPageStore.closeRecord(slug(), recordId())
189
+ })
178
190
  </script>
179
191
 
180
192
  <div class="flex flex-col gap-6">
@@ -200,6 +212,9 @@ onMount(() => {
200
212
  </div>
201
213
  </header>
202
214
 
215
+ <!-- What the model places above its record: `dashboard.regions.recordTop`. -->
216
+ <ModelRegion place="recordTop" />
217
+
203
218
  <QuietLoader :if="loading() && !record()" :slow="slow()" label="Loading record" />
204
219
 
205
220
  <div :if="!loading() && loadError()" role="alert" class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between px-4 py-3 text-red-700 text-sm dark:text-red-300 bg-red-50 dark:bg-red-950/40 border border-red-200 rounded-lg dark:border-red-900">
@@ -254,6 +269,9 @@ onMount(() => {
254
269
  @changed="reloadRelated"
255
270
  />
256
271
 
272
+ <!-- What the model places under its record: `dashboard.regions.recordBottom`. -->
273
+ <ModelRegion place="recordBottom" />
274
+
257
275
  <ConfirmDialog
258
276
  :isOpen="confirmingDelete()"
259
277
  :title="'Delete this ' + modelName().toLowerCase() + '?'"
@@ -6,7 +6,7 @@
6
6
  // to where the visitor came from: the record's page, or the list.
7
7
  import { useNavigation } from '@stacksjs/defaults/views/dashboard/composables/useNavigation'
8
8
  import type { ModelFormValues, ModelRecord } from '../../../../functions/dashboard-model-record'
9
- import { fetchModelRecord, modelNameFromSlug, modelFormPayload, modelFormValues, modelRecordBackHref, modelRecordHref, modelRecordListLabel, modelRecordSections, updateModelRecord } from '../../../../functions/dashboard-model-record'
9
+ import { fetchModelRecord, modelNameFromSlug, modelFormFieldsFor, modelFormPayload, modelFormValues, modelRecordBackHref, modelRecordHref, modelRecordListLabel, modelRecordSections, updateModelRecord } from '../../../../functions/dashboard-model-record'
10
10
  import { dashboardLoaderTimer } from '../../../../functions/dashboard-loading'
11
11
  import { pushToast } from '../../../../functions/toasts'
12
12
 
@@ -42,7 +42,8 @@ const listLabel = derived(() => modelRecordListLabel(record(), listHref()))
42
42
  // Known from the address before the record comes, so the heading does not change.
43
43
  const modelName = derived(() => record()?.modelName || modelNameFromSlug(slug()))
44
44
 
45
- const writable = derived(() => record()?.fields ?? [])
45
+ // As the record is stored: a switch that cannot be turned from where it is stays shown, not offered.
46
+ const writable = derived(() => modelFormFieldsFor(record()?.fields ?? [], initial()))
46
47
  /** What cannot be changed here, formatted as the record's page shows it. */
47
48
  const context = derived(() => {
48
49
  const current = record()
@@ -19,7 +19,10 @@ import { deleteModelRecords, modelBulkActionConfirm, modelBulkActionScope, model
19
19
  import type { ModelFieldDisplay, ModelFormattedValue } from '@stacksjs/defaults/functions/dashboard-model-format'
20
20
  import { modelCellDisplay, modelColumnIsNumeric } from '@stacksjs/defaults/functions/dashboard-model-format'
21
21
  import { dashboardLoaderTimer, dashboardReloadingClass } from '@stacksjs/defaults/functions/dashboard-loading'
22
+ import type { ModelListFilter, ModelListFilterValue, ModelListFilterValues } from '@stacksjs/defaults/functions/dashboard-model-filters'
23
+ import { modelFilterSummary, modelFiltersSet, modelListAddress } from '@stacksjs/defaults/functions/dashboard-model-filters'
22
24
  import { pushToast } from '@stacksjs/defaults/functions/toasts'
25
+ import { modelPageStore } from '@stacksjs/defaults/views/dashboard/stores/model-page'
23
26
 
24
27
  interface ColumnMeta {
25
28
  name: string
@@ -42,6 +45,9 @@ interface ResponseShape {
42
45
  lastPage: number
43
46
  sort: string
44
47
  dir: 'asc' | 'desc'
48
+ /** What the list can be narrowed by, and the columns it can be ordered by. */
49
+ filterable?: ModelListFilter[]
50
+ sortable?: string[]
45
51
  writable: boolean
46
52
  writeCapabilities: ModelWriteCapabilities
47
53
  /** Rows erased under the app's data-subject rules (users only). */
@@ -71,7 +77,6 @@ const heading = useReactiveProp('heading', '')
71
77
  const description = useReactiveProp('description', '')
72
78
  const home = useReactiveProp('home', '')
73
79
  // Told when a record was deleted or acted on, so a host can read its summary again.
74
- const emit = defineEmits(['changed'])
75
80
 
76
81
  const modelName = state('')
77
82
  // The class name, for the one message that tells a developer what was looked for.
@@ -91,7 +96,11 @@ const sort = state('')
91
96
  const dir = state<'asc' | 'desc'>('desc')
92
97
  const search = state(navigation.urlQuery('q') || '')
93
98
  // A list opened from a record's panel arrives narrowed to that record.
94
- const filters = state<Record<string, string>>(modelListFilters(navigation.urlQuery('filters')))
99
+ const filters = state<ModelListFilterValues>(modelListFilters(navigation.urlQuery('filters')))
100
+ // What the list can be narrowed and ordered by. The server derives both from
101
+ // the model's fields; nothing declares a filter.
102
+ const filterable = state<ModelListFilter[]>([])
103
+ const sortable = state<string[]>([])
95
104
  const writeCapabilities = state<ModelWriteCapabilities>(NO_WRITES)
96
105
  const error = state<string | null>(null)
97
106
  // False when the model's table has not been created yet: the server checked the
@@ -163,7 +172,20 @@ const rangeLabel = derived(() => {
163
172
  return `${from.toLocaleString()} to ${to.toLocaleString()} of ${totalCount().toLocaleString()}`
164
173
  })
165
174
 
166
- const activeFilterCount = derived(() => Object.values(filters()).filter(v => v !== '').length)
175
+ const activeFilters = derived(() => modelFiltersSet(filters()))
176
+ const activeFilterCount = derived(() => Object.keys(activeFilters()).length)
177
+
178
+ /**
179
+ * The filters that are narrowing the list, each as a chip that says what it
180
+ * is set to and clears it. One the list does not offer still gets a chip (a
181
+ * list opened from a record's panel is narrowed by that record), so nothing
182
+ * narrows the list out of sight.
183
+ */
184
+ const filterChips = derived(() => Object.entries(activeFilters()).map(([column, value]) => {
185
+ const filter = filterable().find(candidate => candidate.name === column)
186
+ const label = filter?.label ?? columnMeta().find(candidate => candidate.name === column)?.label ?? column
187
+ return { column, label, text: modelFilterSummary(filter, value, relationNames()[column] ?? {}) }
188
+ }))
167
189
 
168
190
  const filterLabel = derived(() => {
169
191
  const n = activeFilterCount()
@@ -288,6 +310,12 @@ function headerClass(column: ColumnMeta): string {
288
310
  return `flex items-center gap-1 w-full ${align} font-medium text-[11px] uppercase tracking-wide text-neutral-500 dark:text-neutral-400 hover:text-neutral-800 dark:hover:text-neutral-200 transition-colors`
289
311
  }
290
312
 
313
+ /** A heading that is not pressed: the same line of text, without the button's hover. */
314
+ function plainHeaderClass(column: ColumnMeta): string {
315
+ const align = modelColumnIsNumeric(column) ? 'justify-end' : 'justify-start'
316
+ return `flex items-center w-full ${align} font-medium text-[11px] uppercase tracking-wide text-neutral-500 dark:text-neutral-400`
317
+ }
318
+
291
319
  function sortIconClass(column: ColumnMeta): string {
292
320
  if (sort() !== column.name) return 'h-3 w-3 opacity-0 group-hover:opacity-40 i-hugeicons-arrow-up-down'
293
321
  return dir() === 'asc' ? 'h-3 w-3 i-hugeicons-arrow-up-01' : 'h-3 w-3 i-hugeicons-arrow-down-01'
@@ -312,8 +340,11 @@ async function load() {
312
340
  })
313
341
  if (sort()) params.set('sort', sort())
314
342
  if (search()) params.set('q', search())
315
- const active = Object.fromEntries(Object.entries(filters()).filter(([, v]) => v !== ''))
343
+ const active = activeFilters()
316
344
  if (Object.keys(active).length > 0) params.set('filters', JSON.stringify(active))
345
+ // The address says what the list is narrowed by, so it can be sent to
346
+ // someone or come back to.
347
+ navigation.replacePath(modelListAddress(navigation.path(), search(), active))
317
348
 
318
349
  const data = await dashboardApi<ResponseShape>(`/api/dashboard/models/${encodeURIComponent(slug())}?${params}`)
319
350
 
@@ -331,6 +362,8 @@ async function load() {
331
362
  relationNames.set(data.relationNames ?? {})
332
363
  actions.set(data.actions ?? [])
333
364
  rowActions.set(data.rowActions ?? {})
365
+ filterable.set(data.filterable ?? [])
366
+ sortable.set(data.sortable ?? [])
334
367
  // The columns the model chose for its list, and any the list is filtered on.
335
368
  const every = data.columnMeta ?? []
336
369
  const shown = modelListColumnNames(every.map(column => column.name), data.listColumns, active)
@@ -340,6 +373,8 @@ async function load() {
340
373
  if (!sameColumns) columnMeta.set(nextColumns)
341
374
  totalCount.set(data.totalCount ?? 0)
342
375
  lastPage.set(data.lastPage ?? 1)
376
+ // For a component the app placed on this page: it follows the list.
377
+ modelPageStore.showList({ slug: slug(), rows: data.rows ?? [], total: data.totalCount ?? 0, search: search(), filters: active })
343
378
  sort.set(data.sort ?? '')
344
379
  writeCapabilities.set({ ...NO_WRITES, ...data.writeCapabilities })
345
380
  migrated.set(data.migrated !== false)
@@ -356,6 +391,7 @@ async function load() {
356
391
  }
357
392
 
358
393
  function toggleSort(column: ColumnMeta) {
394
+ if (!canSort(column)) return
359
395
  if (sort() === column.name) dir.set(dir() === 'asc' ? 'desc' : 'asc')
360
396
  else { sort.set(column.name); dir.set('asc') }
361
397
  page.set(1)
@@ -370,11 +406,24 @@ const onSearchInput = useDebounce(() => {
370
406
  void load()
371
407
  }, 250)
372
408
 
373
- function onFilterInput(column: string, event: Event) {
374
- filters.set({ ...filters(), [column]: (event.target as HTMLInputElement).value })
409
+ function setFilter(change: { name: string, value: ModelListFilterValue }) {
410
+ filters.set({ ...filters(), [change.name]: change.value })
411
+ // Typing a number or a value is not a query per keystroke.
375
412
  onSearchInput()
376
413
  }
377
414
 
415
+ function clearFilter(column: string) {
416
+ const { [column]: _cleared, ...rest } = filters()
417
+ filters.set(rest)
418
+ page.set(1)
419
+ void load()
420
+ }
421
+
422
+ /** Whether pressing a column's heading orders the list by it. */
423
+ function canSort(column: ColumnMeta): boolean {
424
+ return sortable().includes(column.name)
425
+ }
426
+
378
427
  function clearFilters() {
379
428
  filters.set({})
380
429
  search.set('')
@@ -466,7 +515,7 @@ async function runAction(action: ModelCustomAction, row: Record<string, unknown>
466
515
  pushToast(notice.tone, notice.title, { detail: notice.detail })
467
516
  if (!result.ok)
468
517
  return
469
- emit('changed')
518
+ modelPageStore.listChanged(slug())
470
519
  if (result.redirect)
471
520
  navigate(result.redirect)
472
521
  else
@@ -563,7 +612,7 @@ async function runBulk(pending = confirmingBulk(), input: Record<string, unknown
563
612
  if (pending.kind === 'delete' && result.done >= rows().length && page() > 1)
564
613
  page.set(page() - 1)
565
614
  if (result.done > 0)
566
- emit('changed')
615
+ modelPageStore.listChanged(slug())
567
616
  await load()
568
617
  }
569
618
 
@@ -579,7 +628,7 @@ async function confirmDelete() {
579
628
  // Deleting the last row of the final page would strand the viewer on an
580
629
  // empty page, so step back one.
581
630
  if (rows().length === 1 && page() > 1) page.set(page() - 1)
582
- emit('changed')
631
+ modelPageStore.listChanged(slug())
583
632
  await load()
584
633
  }
585
634
  catch (e) {
@@ -594,8 +643,16 @@ async function confirmDelete() {
594
643
  // model through a prop, and a prop is not bound until then. Loading sooner
595
644
  // asked for the model named by the last part of the host's own address.
596
645
  onMount(() => {
646
+ // Which list this is, before it has loaded: a component the app placed
647
+ // here never shows the list of the page before. Here and not sooner,
648
+ // because a hosting page's `model` is not bound until now.
649
+ modelPageStore.openList(slug(), () => { void load() })
597
650
  void load()
598
651
  })
652
+
653
+ onDestroy(() => {
654
+ modelPageStore.closeList(slug())
655
+ })
599
656
  </script>
600
657
 
601
658
  <template>
@@ -626,7 +683,7 @@ onMount(() => {
626
683
  <span :text="'Invite ' + oneRecord()"></span>
627
684
  </Button>
628
685
  <Button
629
- :if="migrated()"
686
+ :if="migrated() && (filterable().length > 0 || activeFilterCount() > 0)"
630
687
  variant="secondary"
631
688
  size="sm"
632
689
  interaction="toggle"
@@ -639,8 +696,9 @@ onMount(() => {
639
696
  </div>
640
697
  </div>
641
698
 
642
- <!-- What the page hosting this list puts above it: its row of stats. -->
643
- <slot name="summary" />
699
+ <!-- What the model places above its list (`dashboard.regions.listTop`):
700
+ the row of stats over Users, Teams and Subscribers is one. -->
701
+ <ModelRegion place="listTop" />
644
702
 
645
703
  <!-- Search + page size -->
646
704
  <div :if="migrated()" class="flex flex-wrap gap-3 items-center">
@@ -675,6 +733,25 @@ onMount(() => {
675
733
  </div>
676
734
  </div>
677
735
 
736
+ <!-- What the list can be narrowed by. -->
737
+ <ModelFilterPanel
738
+ :if="migrated() && showFilters() && filterable().length > 0"
739
+ :filters="filterable()"
740
+ :values="filters()"
741
+ @change="setFilter"
742
+ />
743
+
744
+ <!-- What is narrowing it now. Always in view, so a filtered list never looks like the whole of it. -->
745
+ <div :if="filterChips().length > 0" data-filter-chips class="flex flex-wrap gap-2 items-center">
746
+ <span :for="chip in filterChips()" class="inline-flex gap-1.5 items-center pl-2.5 pr-1 h-7 text-[12px] text-neutral-700 dark:text-neutral-200 bg-neutral-100 dark:bg-white/10 rounded-full" :data-filter-chip="chip.column">
747
+ <span class="font-medium" :text="chip.label + ':'"></span>
748
+ <span class="max-w-[16rem] truncate" :text="chip.text"></span>
749
+ <Button variant="ghost" size="xs" iconOnly :ariaLabel="'Clear ' + chip.label + ' filter'" @click="clearFilter(chip.column)">
750
+ <span aria-hidden="true" class="h-3 w-3 i-hugeicons-cancel-01"></span>
751
+ </Button>
752
+ </span>
753
+ </div>
754
+
678
755
  <!-- What can be done to the ticked rows. Only there when some are ticked. -->
679
756
  <div :if="selected().length > 0" role="region" aria-label="Selected rows" data-bulk-bar class="flex flex-wrap gap-3 items-center justify-between px-3 py-2 bg-blue-50 dark:bg-blue-500/10 border border-blue-200 rounded-lg dark:border-blue-500/30">
680
757
  <p class="font-medium text-[13px] text-neutral-800 dark:text-neutral-100" aria-live="polite">
@@ -763,29 +840,16 @@ onMount(() => {
763
840
  @change="toggleAllSelected()"
764
841
  />
765
842
  </th>
766
- <th :for="column in columnMeta()" scope="col" class="px-3 py-2 whitespace-nowrap group">
767
- <button type="button" @click="toggleSort(column)" :class="headerClass(column)">
843
+ <th :for="column in columnMeta()" scope="col" class="px-3 py-2 whitespace-nowrap group" :aria-sort="sort() === column.name ? (dir() === 'asc' ? 'ascending' : 'descending') : null">
844
+ <button :if="canSort(column)" type="button" @click="toggleSort(column)" :class="headerClass(column)">
768
845
  <span>{{ column.label }}</span>
769
846
  <span :class="sortIconClass(column)"></span>
770
847
  </button>
848
+ <!-- Prose, a structure, or another record's name: nothing a list is ordered by. -->
849
+ <span :if="!canSort(column)" :class="plainHeaderClass(column)">{{ column.label }}</span>
771
850
  </th>
772
851
  <th scope="col" class="right-0 sticky z-20 px-3 py-2 w-28 font-medium text-[11px] text-neutral-500 text-right tracking-wide uppercase dark:text-neutral-400 bg-neutral-50 dark:bg-neutral-800 border-black/5 border-l dark:border-white/10">Actions</th>
773
852
  </tr>
774
-
775
- <!-- Per-column filter row -->
776
- <tr :if="showFilters()" class="bg-white dark:bg-neutral-900">
777
- <th :if="selectable()"></th>
778
- <th :for="column in columnMeta()" scope="col" class="pb-2 px-2">
779
- <input
780
- type="text"
781
- :value="filters()[column.name] || ''"
782
- @input="onFilterInput(column.name, $event)"
783
- :placeholder="column.label"
784
- class="block px-2 py-1 w-full font-normal text-[12px] text-neutral-900 dark:text-neutral-100 placeholder:text-neutral-400 dark:placeholder:text-neutral-500 bg-white dark:bg-white/10 border border-black/10 rounded-md dark:border-white/15 focus:border-blue-400 focus:outline-none"
785
- >
786
- </th>
787
- <th class="right-0 sticky z-20 bg-white dark:bg-neutral-900 border-black/5 border-l dark:border-white/10"></th>
788
- </tr>
789
853
  </thead>
790
854
 
791
855
  <tbody :class="bodyClass()" :aria-busy="loading() ? 'true' : null">
@@ -843,6 +907,9 @@ onMount(() => {
843
907
  </div>
844
908
  </div>
845
909
 
910
+ <!-- What the model places under its list: `dashboard.regions.listBottom`. -->
911
+ <ModelRegion place="listBottom" />
912
+
846
913
  <ConfirmDialog
847
914
  :isOpen="Boolean(confirmingDelete())"
848
915
  :title="'Delete this ' + modelName() + '?'"
@@ -0,0 +1,25 @@
1
+ <script server>
2
+ // A place on a model's page where the app may put a component of its own
3
+ // (`dashboard.regions`): the model names the component, and it is drawn here.
4
+ //
5
+ // A dashboard page is the same document at every address. It is drawn once
6
+ // and reads its address in the browser, so the server does not know which
7
+ // model the page will be showing. It draws the component of every model that
8
+ // places one here, each inside a ModelRegionFor, and that mounts the one for
9
+ // the model in front of the viewer. The others are never mounted. That holds
10
+ // on a page that hosts the list too (the Users page): the list says which
11
+ // model it is showing, wherever it is.
12
+ import { dashboardRegionEntries } from '@stacksjs/defaults/resources/functions/dashboard/regions'
13
+
14
+ interface ModelRegionProps {
15
+ /** `listTop`, `listBottom`, `recordTop` or `recordBottom`. */
16
+ place?: string
17
+ }
18
+
19
+ const { place = '' } = defineProps<ModelRegionProps>()
20
+ const placed = dashboardRegionEntries(place)
21
+ </script>
22
+
23
+ @foreach(placed as entry)
24
+ <ModelRegionFor model="{{ entry.model }}" component="{{ entry.component }}" place="{{ place }}" />
25
+ @endforeach
@@ -0,0 +1,31 @@
1
+ <script server>
2
+ // One model's component for a place on a page (see ModelRegion). Drawn on
3
+ // the server, where a component can be chosen by name.
4
+ interface ModelRegionForProps {
5
+ /** The model that placed it, as an address has it: `social-post`. */
6
+ model?: string
7
+ /** The component's name, as its file is called: `OrderTimeline`. */
8
+ component?: string
9
+ place?: string
10
+ }
11
+
12
+ const { model = '', component = '', place = '' } = defineProps<ModelRegionForProps>()
13
+ </script>
14
+
15
+ <script client>
16
+ // Mounted only while the page is showing its model, so a component written
17
+ // for orders never runs on a team's page. The page says which model it is
18
+ // showing before it loads anything (`modelPageStore`), on a record's page
19
+ // and on a list alike.
20
+ import { modelPageStore } from '@stacksjs/defaults/views/dashboard/stores/model-page'
21
+
22
+ const forModel = useReactiveProp('model', '')
23
+ const atPlace = useReactiveProp('place', '')
24
+
25
+ const showing = derived(() => atPlace().startsWith('record') ? modelPageStore.record()?.slug ?? '' : modelPageStore.list()?.slug ?? '')
26
+ const mounted = derived(() => forModel() !== '' && showing() === forModel())
27
+ </script>
28
+
29
+ <div :if="mounted()" data-model-region :data-region="atPlace()" :data-region-model="forModel()">
30
+ <component :is="component" :model="model" :region="place"></component>
31
+ </div>
@@ -113,8 +113,8 @@ function submit(): void {
113
113
  <p class="mt-1 text-gray-500 text-xs dark:text-neutral-400">At least 32 characters. Keep an independent recovery copy outside this control plane.</p>
114
114
  </div>
115
115
  <div :if="provider() === 's3_compatible'" class="flex flex-wrap gap-4">
116
- <label class="inline-flex gap-2 items-center text-gray-700 text-sm dark:text-neutral-200"><input x-model="forcePathStyle" type="checkbox" /> Force path-style URLs</label>
117
- <label class="inline-flex gap-2 items-center text-gray-700 text-sm dark:text-neutral-200"><input x-model="allowPrivate" type="checkbox" /> Allow private endpoint</label>
116
+ <Toggle v-model:checked="forcePathStyle" label="Force path-style URLs" />
117
+ <Toggle v-model:checked="allowPrivate" label="Allow private endpoint" />
118
118
  </div>
119
119
  </form>
120
120
  <template #footer>
@@ -144,7 +144,9 @@ function submit(): void {
144
144
  </select>
145
145
  </div>
146
146
  </div>
147
- <label class="inline-flex gap-2 items-center text-gray-700 text-sm dark:text-neutral-200"><input x-model="enabled" type="checkbox" /> Enable scheduled runs</label>
147
+ <div>
148
+ <Toggle v-model:checked="enabled" label="Enable scheduled runs" />
149
+ </div>
148
150
  </form>
149
151
  <template #footer>
150
152
  <div class="flex gap-2 justify-end w-full">
@@ -58,7 +58,9 @@ function execute(): void { emit('execute', input(true)) }
58
58
  <input id="restore-target" x-model.trim="targetName" required placeholder="recovery-check-2026-08" class="px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-lg dark:border-neutral-700" />
59
59
  </div>
60
60
  </div>
61
- <label :if="mode() === 'isolated'" class="inline-flex gap-2 items-center text-gray-700 text-sm dark:text-neutral-200"><input x-model="drill" type="checkbox" /> Run as a recovery drill and clean the isolated target after health validation</label>
61
+ <div :if="mode() === 'isolated'">
62
+ <Toggle v-model:checked="drill" label="Run as a recovery drill and clean the isolated target after health validation" />
63
+ </div>
62
64
  <div :if="mode() === 'in_place'" class="p-4 space-y-4 text-amber-900 dark:text-amber-100 bg-amber-50 dark:bg-amber-950/30 border border-amber-200 rounded-lg dark:border-amber-900">
63
65
  <p class="font-medium text-sm">In-place restore replaces live data and requires a distinct verified safety point.</p>
64
66
  <div>
@@ -54,8 +54,8 @@ function isVisible(id: string) {
54
54
  return !hiddenSections().includes(id)
55
55
  }
56
56
 
57
- function toggleSection(id: string, event: Event) {
58
- appearance.toggleSection(id, (event.target as HTMLInputElement).checked)
57
+ function toggleSection(id: string, visible: boolean) {
58
+ appearance.toggleSection(id, visible)
59
59
  }
60
60
 
61
61
  function resetAll() {
@@ -302,19 +302,16 @@ const selected = (a: unknown, b: unknown) => String(a === b)
302
302
  </div>
303
303
 
304
304
  <div class="divide-neutral-200/60 divide-y dark:divide-white/5">
305
- <label :for="section in sections" class="flex gap-4 items-center justify-between px-6 py-4 hover:bg-stone-50/60 dark:hover:bg-white/[0.02] cursor-pointer">
306
- <span class="min-w-0">
307
- <span class="block font-medium text-neutral-900 text-sm dark:text-white">{{ section.label }}</span>
308
- <span class="block mt-0.5 text-neutral-500 text-xs dark:text-neutral-400">{{ section.count }} items</span>
309
- </span>
310
- <input
311
- type="checkbox"
305
+ <div :for="section in sections" class="px-6 py-4 hover:bg-stone-50/60 dark:hover:bg-white/[0.02]">
306
+ <Toggle
312
307
  :checked="isVisible(section.id)"
313
- @change="toggleSection(section.id, $event)"
314
- class="flex-none h-4 w-4 text-blue-600 border-neutral-300 rounded focus:ring-blue-500"
315
- :aria-label="'Show ' + section.label + ' section'"
316
- >
317
- </label>
308
+ :label="section.label"
309
+ :description="section.count + ' items'"
310
+ :ariaLabel="'Show ' + section.label + ' section'"
311
+ labelPosition="left"
312
+ @update:checked="toggleSection(section.id, $event)"
313
+ />
314
+ </div>
318
315
  </div>
319
316
  </Card>
320
317
 
@@ -277,15 +277,12 @@ void loadFiles()
277
277
 
278
278
  <div>
279
279
  @if(field.type === 'boolean' && field.editable)
280
- <label class="inline-flex gap-3 items-center cursor-pointer">
281
- <input
282
- :id="'config-' + field.key"
283
- type="checkbox"
284
- x-model="drafts[field.key]"
285
- class="h-4 w-4 text-blue-600 border-neutral-300 rounded focus:ring-blue-500"
286
- >
287
- <span class="text-neutral-700 text-sm dark:text-neutral-300">{{ drafts[field.key] ? 'Enabled' : 'Disabled' }}</span>
288
- </label>
280
+ <Toggle
281
+ :id="'config-' + field.key"
282
+ v-model:checked="drafts[field.key]"
283
+ :label="drafts[field.key] ? 'Enabled' : 'Disabled'"
284
+ :ariaLabel="field.key"
285
+ />
289
286
  @elseif(field.editable && field.type === 'number')
290
287
  <input
291
288
  :id="'config-' + field.key"
@@ -11,6 +11,8 @@ const liveLabelPosition = useReactiveProp('labelPosition', 'right' as ToggleLabe
11
11
  const liveName = useReactiveProp('name', '')
12
12
  const liveId = useReactiveProp('id', '')
13
13
  const liveAriaLabel = useReactiveProp('ariaLabel', '')
14
+ // What a refused save said about this switch. Shown in place of the description.
15
+ const liveError = useReactiveProp('error', '')
14
16
  const emit = defineEmits(['update:checked', 'change'])
15
17
  const generatedId = useId('toggle')
16
18
 
@@ -31,31 +33,31 @@ const checkedTranslations: Record<ToggleSize, string> = {
31
33
  }
32
34
 
33
35
  const toggleId = derived(() => liveId() || generatedId)
34
- const hasCopy = derived(() => Boolean(liveLabel() || liveDescription()))
36
+ const hasCopy = derived(() => Boolean(liveLabel() || liveDescription() || liveError()))
35
37
  const wrapperClass = derived(() => [
36
38
  'flex items-center gap-3',
37
39
  liveLabelPosition() === 'left' ? 'flex-row-reverse justify-end' : '',
38
- liveDisabled() ? 'cursor-not-allowed opacity-60' : 'cursor-pointer',
40
+ // Only the track dims: what a switch that cannot be turned says under it still has to be read.
41
+ liveDisabled() ? 'cursor-not-allowed' : 'cursor-pointer',
39
42
  ].join(' '))
40
43
  const trackClass = derived(() => [
41
44
  trackSizes[liveSize()] || trackSizes.md,
42
45
  'relative inline-flex shrink-0 rounded-full transition-colors duration-150',
43
- 'focus-within:ring-2 focus-within:ring-blue-500/40',
46
+ 'peer-focus-visible:ring-2 peer-focus-visible:ring-blue-500/40',
44
47
  liveChecked() ? 'bg-green-500' : 'bg-black/15 dark:bg-white/20',
45
48
  liveDisabled() ? 'opacity-40' : '',
46
49
  ].join(' '))
47
50
  const thumbClass = derived(() => [
48
51
  thumbSizes[liveSize()] || thumbSizes.md,
49
- 'pointer-events-none inline-block translate-x-0.5 rounded-full bg-white shadow-sm transition-transform duration-150 ease-in-out',
50
- liveChecked() ? checkedTranslations[liveSize()] || checkedTranslations.md : '',
52
+ 'pointer-events-none inline-block rounded-full bg-white shadow-sm transition-transform duration-150 ease-in-out',
53
+ // One position or the other, never both: with both on the thumb, which won
54
+ // was the order the page's stylesheet happened to list them in, and on
55
+ // some pages a switch that was on kept its thumb on the left.
56
+ liveChecked() ? checkedTranslations[liveSize()] || checkedTranslations.md : 'translate-x-0.5',
51
57
  ].join(' '))
52
58
  const labelClass = derived(() => [
53
59
  'text-[13px] font-medium tracking-tight',
54
- liveDisabled() ? 'text-neutral-500 dark:text-neutral-600' : 'text-neutral-700 dark:text-neutral-200',
55
- ].join(' '))
56
- const descriptionClass = derived(() => [
57
- 'mt-0.5 text-[12px]',
58
- liveDisabled() ? 'text-neutral-300 dark:text-neutral-600' : 'text-neutral-500 dark:text-neutral-400',
60
+ liveDisabled() ? 'text-neutral-500 dark:text-neutral-400' : 'text-neutral-700 dark:text-neutral-200',
59
61
  ].join(' '))
60
62
 
61
63
  function handleChange(event: Event): void {
@@ -72,7 +74,8 @@ function handleChange(event: Event): void {
72
74
  role="switch"
73
75
  :name="liveName() || null"
74
76
  :aria-label="liveAriaLabel() || liveLabel() || 'Toggle'"
75
- class="sr-only"
77
+ :aria-invalid="liveError() ? 'true' : null"
78
+ class="sr-only peer"
76
79
  x-model="liveChecked"
77
80
  :disabled="liveDisabled()"
78
81
  @change="handleChange"
@@ -84,6 +87,7 @@ function handleChange(event: Event): void {
84
87
 
85
88
  <span :if="hasCopy()" class="flex-1 min-w-0">
86
89
  <span :if="liveLabel()" class="block" :class="labelClass()" :text="liveLabel()"></span>
87
- <span :if="liveDescription()" class="block" :class="descriptionClass()" :text="liveDescription()"></span>
90
+ <span :if="liveDescription() && !liveError()" class="block mt-0.5 text-[12px] text-neutral-500 dark:text-neutral-400" :text="liveDescription()"></span>
91
+ <span :if="liveError()" role="alert" class="block mt-0.5 text-[12px] text-red-600 dark:text-red-400" :text="liveError()"></span>
88
92
  </span>
89
93
  </label>