@stacksjs/defaults 0.75.571 → 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 (61) 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 +3 -1
  5. package/ai/skills/stacks-native/CATALOG.md +2 -2
  6. package/ai/skills/stacks-orm/SKILL.md +5 -1
  7. package/app/Actions/Dashboard/Content/CommentUpdateAction.ts +1 -1
  8. package/app/Actions/Dashboard/Content/PostStoreAction.ts +1 -1
  9. package/app/Actions/Dashboard/Content/PostUpdateAction.ts +1 -1
  10. package/app/Actions/Dashboard/Marketing/marketing-list-records.test.ts +2 -2
  11. package/app/Actions/Dashboard/Marketing/marketing-list-records.ts +4 -4
  12. package/app/Actions/Dashboard/Models/ModelShowAction.ts +42 -43
  13. package/app/Actions/Dashboard/Models/ModelUpdateAction.ts +17 -3
  14. package/app/Actions/Dashboard/Models/model-filters.ts +429 -0
  15. package/app/Actions/Dashboard/Models/model-switches.ts +159 -0
  16. package/app/Actions/Dashboard/Models/model-write.ts +6 -0
  17. package/app/Models/Comment.ts +3 -3
  18. package/app/Models/Content/Post.ts +3 -3
  19. package/app/Models/EmailList.ts +8 -6
  20. package/app/Models/Subscriber.ts +2 -0
  21. package/app/Models/Team.ts +2 -0
  22. package/app/Models/User.ts +3 -0
  23. package/functions/dashboard-model-filters.ts +219 -0
  24. package/functions/dashboard-model-record.ts +42 -8
  25. package/ide/vscode/package.json +1 -1
  26. package/package.json +3 -3
  27. package/resources/components/Dashboard/Commerce/CommerceCategoryDialog.stx +3 -1
  28. package/resources/components/Dashboard/Commerce/CommerceCouponDialog.stx +3 -1
  29. package/resources/components/Dashboard/Commerce/CommerceGiftCardDialog.stx +9 -3
  30. package/resources/components/Dashboard/Commerce/CommerceManufacturerDialog.stx +3 -4
  31. package/resources/components/Dashboard/Commerce/CommerceProductDialog.stx +3 -1
  32. package/resources/components/Dashboard/Commerce/CommerceReviewEditDialog.stx +6 -8
  33. package/resources/components/Dashboard/Commerce/CommerceTaxDialog.stx +6 -14
  34. package/resources/components/Dashboard/Commerce/CommerceUnitDialog.stx +3 -7
  35. package/resources/components/Dashboard/Commerce/Delivery/DigitalDeliveryDialog.stx +6 -2
  36. package/resources/components/Dashboard/Content/BlogPostEditorDialog.stx +2 -8
  37. package/resources/components/Dashboard/Content/PageEditorDialog.stx +3 -7
  38. package/resources/components/Dashboard/Content/PostEditorDialog.stx +3 -4
  39. package/resources/components/Dashboard/Data/DataModelRecords.stx +12 -75
  40. package/resources/components/Dashboard/Data/DataStatCards.stx +110 -0
  41. package/resources/components/Dashboard/Email/InboxSettingsDashboard.stx +20 -36
  42. package/resources/components/Dashboard/Marketing/MarketingListDialog.stx +7 -14
  43. package/resources/components/Dashboard/Marketing/MarketingListsDashboard.stx +3 -2
  44. package/resources/components/Dashboard/Models/ModelFieldInputs.stx +10 -13
  45. package/resources/components/Dashboard/Models/ModelFilterPanel.stx +166 -0
  46. package/resources/components/Dashboard/Models/ModelRecordDetail.stx +18 -0
  47. package/resources/components/Dashboard/Models/ModelRecordEdit.stx +3 -2
  48. package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +96 -29
  49. package/resources/components/Dashboard/Models/ModelRegion.stx +25 -0
  50. package/resources/components/Dashboard/Models/ModelRegionFor.stx +31 -0
  51. package/resources/components/Dashboard/Operations/RecoveryDestinationDialog.stx +2 -2
  52. package/resources/components/Dashboard/Operations/RecoveryPolicyDialog.stx +3 -1
  53. package/resources/components/Dashboard/Operations/RecoveryRestoreDialog.stx +3 -1
  54. package/resources/components/Dashboard/Settings/AppearanceSettingsDashboard.stx +11 -14
  55. package/resources/components/Dashboard/Settings/SettingsDashboard.stx +6 -9
  56. package/resources/components/Dashboard/UI/Toggle.stx +16 -12
  57. package/resources/functions/dashboard/regions.ts +113 -0
  58. package/resources/functions/dashboard/sidebar.ts +2 -0
  59. package/views/dashboard/composables/useModelList.ts +52 -0
  60. package/views/dashboard/composables/useModelRecord.ts +46 -0
  61. package/views/dashboard/stores/model-page.ts +105 -0
@@ -0,0 +1,166 @@
1
+ <script client>
2
+ // What a list can be narrowed by, each asked for in the control its kind
3
+ // calls for: a few allowed values are picked from, a yes-or-no is yes or no,
4
+ // a field that points at another record is that record, a date is a range
5
+ // of days, a number a minimum and a maximum.
6
+ //
7
+ // The list tells this which filters there are (the server derives them from
8
+ // the model's fields) and what each is set to; this says what was changed.
9
+ // It holds nothing of its own, so a filter cleared from its chip is cleared
10
+ // here too.
11
+ //
12
+ // Each loop is on a wrapper and not on the button itself: a loop placed on a
13
+ // component does not hand its item to what the component wraps.
14
+ import type { ModelFilterPreset, ModelListFilter, ModelListFilterValue, ModelListFilterValues } from '../../../../functions/dashboard-model-filters'
15
+ import { MODEL_FILTER_PRESETS, modelFilterChosen, modelFilterDays, modelFilterPresetDays, modelFilterRange, modelFilterToggle } from '../../../../functions/dashboard-model-filters'
16
+
17
+ const filters = useReactiveProp<ModelListFilter[]>('filters', [])
18
+ const values = useReactiveProp<ModelListFilterValues>('values', {})
19
+ const emit = defineEmits(['change'])
20
+
21
+ const YES_NO = [{ value: 'true', label: 'Yes' }, { value: 'false', label: 'No' }]
22
+ const presets = MODEL_FILTER_PRESETS
23
+
24
+ const boxClass = 'block px-2 h-8 w-full min-w-0 text-[13px] 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'
25
+
26
+ function set(filter: ModelListFilter, value: ModelListFilterValue): void {
27
+ emit('change', { name: filter.name, value })
28
+ }
29
+
30
+ function current(filter: ModelListFilter): ModelListFilterValue | undefined {
31
+ return values()[filter.name]
32
+ }
33
+
34
+ function chosen(filter: ModelListFilter, option: string): boolean {
35
+ return modelFilterChosen(current(filter)).includes(option)
36
+ }
37
+
38
+ function toggle(filter: ModelListFilter, option: string): void {
39
+ set(filter, modelFilterToggle(current(filter), option))
40
+ }
41
+
42
+ /** Yes, no, or neither: pressing the one that is on turns the filter off. */
43
+ function isAnswer(filter: ModelListFilter, answer: string): boolean {
44
+ return current(filter) === answer
45
+ }
46
+
47
+ function answer(filter: ModelListFilter, value: string): void {
48
+ set(filter, isAnswer(filter, value) ? '' : value)
49
+ }
50
+
51
+ /** The one record a relation filter is set to. */
52
+ function record(filter: ModelListFilter): string {
53
+ return modelFilterChosen(current(filter))[0] ?? ''
54
+ }
55
+
56
+ function rangeKind(filter: ModelListFilter): 'date' | 'datetime' {
57
+ return filter.kind === 'date' ? 'date' : 'datetime'
58
+ }
59
+
60
+ function day(filter: ModelListFilter, edge: 'from' | 'to'): string {
61
+ return modelFilterDays(rangeKind(filter), current(filter))[edge]
62
+ }
63
+
64
+ function setDay(filter: ModelListFilter, edge: 'from' | 'to', event: Event): void {
65
+ const days = modelFilterDays(rangeKind(filter), current(filter))
66
+ days[edge] = (event.target as HTMLInputElement).value
67
+ set(filter, modelFilterRange(rangeKind(filter), days.from, days.to))
68
+ }
69
+
70
+ function isPreset(filter: ModelListFilter, preset: ModelFilterPreset): boolean {
71
+ const days = modelFilterDays(rangeKind(filter), current(filter))
72
+ const wanted = modelFilterPresetDays(preset)
73
+ return days.from === wanted.from && days.to === wanted.to
74
+ }
75
+
76
+ function usePreset(filter: ModelListFilter, preset: ModelFilterPreset): void {
77
+ if (isPreset(filter, preset)) {
78
+ set(filter, '')
79
+ return
80
+ }
81
+ const days = modelFilterPresetDays(preset)
82
+ set(filter, modelFilterRange(rangeKind(filter), days.from, days.to))
83
+ }
84
+
85
+ function amount(filter: ModelListFilter, edge: 'min' | 'max'): string {
86
+ const value = current(filter)
87
+ const number = value && typeof value !== 'string' && edge in value ? (value as { min?: number, max?: number })[edge] : undefined
88
+ return number === undefined ? '' : String(number)
89
+ }
90
+
91
+ function setAmount(filter: ModelListFilter, edge: 'min' | 'max', event: Event): void {
92
+ const typed = (event.target as HTMLInputElement).value.trim()
93
+ const range = { min: amount(filter, 'min'), max: amount(filter, 'max'), [edge]: typed }
94
+ const next: { min?: number, max?: number } = {}
95
+ if (range.min !== '' && Number.isFinite(Number(range.min)))
96
+ next.min = Number(range.min)
97
+ if (range.max !== '' && Number.isFinite(Number(range.max)))
98
+ next.max = Number(range.max)
99
+ set(filter, next.min === undefined && next.max === undefined ? '' : next)
100
+ }
101
+
102
+ function exact(filter: ModelListFilter): string {
103
+ const value = current(filter)
104
+ return typeof value === 'string' ? value : ''
105
+ }
106
+
107
+ function setExact(filter: ModelListFilter, event: Event): void {
108
+ set(filter, (event.target as HTMLInputElement).value)
109
+ }
110
+ </script>
111
+
112
+ <div role="group" aria-label="Filters" data-filter-panel class="grid gap-x-6 gap-y-4 grid-cols-1 md:grid-cols-2 xl:grid-cols-3 p-4 bg-white dark:bg-neutral-900 border border-black/8 rounded-xl dark:border-white/10">
113
+ <div :for="filter in filters()" class="min-w-0" :data-filter="filter.name" :data-filter-kind="filter.kind">
114
+ <!-- The record picker draws its own label, tied to its search box. -->
115
+ <p :if="filter.kind !== 'relation'" class="mb-1.5 font-medium text-[12px] text-neutral-600 dark:text-neutral-400" :text="filter.label"></p>
116
+
117
+ <div :if="filter.kind === 'choice'" class="flex flex-wrap gap-1.5">
118
+ <span :for="option in filter.options" class="contents">
119
+ <Button variant="secondary" size="xs" interaction="toggle" :pressed="chosen(filter, option.value)" @click="toggle(filter, option.value)">{{ option.label }}</Button>
120
+ </span>
121
+ </div>
122
+
123
+ <div :if="filter.kind === 'boolean'" class="flex flex-wrap gap-1.5">
124
+ <span :for="choice in YES_NO" class="contents">
125
+ <Button variant="secondary" size="xs" interaction="toggle" :pressed="isAnswer(filter, choice.value)" @click="answer(filter, choice.value)">{{ choice.label }}</Button>
126
+ </span>
127
+ </div>
128
+
129
+ <ModelRelationPicker
130
+ :if="filter.kind === 'relation'"
131
+ :slug="filter.relation ? filter.relation.slug : ''"
132
+ :value="record(filter)"
133
+ :label="filter.label"
134
+ @update:value="set(filter, $event)"
135
+ />
136
+
137
+ <div :if="filter.kind === 'date' || filter.kind === 'datetime'" class="flex flex-col gap-1.5">
138
+ <div class="flex gap-1.5 items-center">
139
+ <input type="date" :value="day(filter, 'from')" :aria-label="filter.label + ' from'" :class="boxClass" @change="setDay(filter, 'from', $event)">
140
+ <span class="flex-none text-[12px] text-neutral-500 dark:text-neutral-400">to</span>
141
+ <input type="date" :value="day(filter, 'to')" :aria-label="filter.label + ' to'" :class="boxClass" @change="setDay(filter, 'to', $event)">
142
+ </div>
143
+ <div class="flex flex-wrap gap-1.5">
144
+ <span :for="preset in presets" class="contents">
145
+ <Button variant="secondary" size="xs" interaction="toggle" :pressed="isPreset(filter, preset.name)" @click="usePreset(filter, preset.name)">{{ preset.label }}</Button>
146
+ </span>
147
+ </div>
148
+ </div>
149
+
150
+ <div :if="filter.kind === 'number'" class="flex gap-1.5 items-center">
151
+ <input type="number" inputmode="decimal" placeholder="At least" :value="amount(filter, 'min')" :aria-label="filter.label + ' at least'" :class="boxClass" @input="setAmount(filter, 'min', $event)">
152
+ <span class="flex-none text-[12px] text-neutral-500 dark:text-neutral-400">to</span>
153
+ <input type="number" inputmode="decimal" placeholder="At most" :value="amount(filter, 'max')" :aria-label="filter.label + ' at most'" :class="boxClass" @input="setAmount(filter, 'max', $event)">
154
+ </div>
155
+
156
+ <input
157
+ :if="filter.kind === 'text'"
158
+ type="text"
159
+ placeholder="Exactly"
160
+ :value="exact(filter)"
161
+ :aria-label="filter.label + ' is exactly'"
162
+ :class="boxClass"
163
+ @input="setExact(filter, $event)"
164
+ >
165
+ </div>
166
+ </div>
@@ -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>