@stacksjs/defaults 0.75.552 → 0.75.555

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 (57) hide show
  1. package/ai/skills/stacks-actions/SKILL.md +1 -1
  2. package/ai/skills/stacks-dashboard/SKILL.md +347 -14
  3. package/ai/skills/stacks-desktop/SKILL.md +19 -0
  4. package/ai/skills/stacks-models/SKILL.md +19 -0
  5. package/ai/skills/stacks-native/CATALOG.md +5 -5
  6. package/app/Actions/Dashboard/Content/file-manager.ts +9 -3
  7. package/app/Actions/Dashboard/Data/SubscriberIndexAction.ts +6 -3
  8. package/app/Actions/Dashboard/Data/TeamIndexAction.ts +6 -3
  9. package/app/Actions/Dashboard/Data/UserIndexAction.ts +6 -3
  10. package/app/Actions/Dashboard/Data/data-records.ts +12 -0
  11. package/app/Actions/Dashboard/Models/ModelActionRunAction.ts +77 -0
  12. package/app/Actions/Dashboard/Models/ModelMarkdownAction.ts +42 -0
  13. package/app/Actions/Dashboard/Models/ModelShowAction.ts +63 -21
  14. package/app/Actions/Dashboard/Models/ModelUploadAction.ts +83 -0
  15. package/app/Actions/Dashboard/Models/model-actions.ts +393 -0
  16. package/app/Actions/Dashboard/Models/model-fields.ts +198 -0
  17. package/app/Actions/Dashboard/Models/model-forms.ts +36 -0
  18. package/app/Actions/Dashboard/Models/model-related.ts +62 -11
  19. package/app/Actions/Dashboard/Models/model-upload.ts +81 -0
  20. package/app/Actions/Dashboard/Models/model-write.ts +92 -5
  21. package/app/Actions/Dashboard/Users/UserPasswordResetAction.ts +50 -0
  22. package/app/Actions/Desktop/UpdateArtifactAction.ts +37 -0
  23. package/app/Models/CardAttachment.ts +5 -0
  24. package/app/Models/Deployment.ts +5 -0
  25. package/app/Models/QueryLog.ts +5 -0
  26. package/app/Models/Request.ts +4 -0
  27. package/app/Models/Team.ts +4 -0
  28. package/app/Models/User.ts +18 -0
  29. package/functions/dashboard-markdown.ts +132 -0
  30. package/functions/dashboard-model-bulk.ts +224 -0
  31. package/functions/dashboard-model-format.ts +201 -0
  32. package/functions/dashboard-model-record.test.ts +53 -30
  33. package/functions/dashboard-model-record.ts +267 -19
  34. package/functions/data.ts +9 -0
  35. package/ide/vscode/package.json +1 -1
  36. package/package.json +3 -3
  37. package/resources/components/Dashboard/Data/ActivityLog.stx +212 -0
  38. package/resources/components/Dashboard/Data/DataModelRecords.stx +89 -0
  39. package/resources/components/Dashboard/Models/ModelActionForm.stx +85 -0
  40. package/resources/components/Dashboard/Models/ModelBadge.stx +22 -0
  41. package/resources/components/Dashboard/Models/ModelFieldInputs.stx +43 -9
  42. package/resources/components/Dashboard/Models/ModelMarkdownInput.stx +139 -0
  43. package/resources/components/Dashboard/Models/ModelRecordActions.stx +32 -1
  44. package/resources/components/Dashboard/Models/ModelRecordCreate.stx +1 -1
  45. package/resources/components/Dashboard/Models/ModelRecordDetail.stx +114 -7
  46. package/resources/components/Dashboard/Models/ModelRecordEdit.stx +1 -1
  47. package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +387 -20
  48. package/resources/components/Dashboard/Models/ModelRelatedPanels.stx +197 -27
  49. package/resources/components/Dashboard/Models/ModelRelationPicker.stx +3 -0
  50. package/resources/components/Dashboard/Models/ModelUploadInput.stx +97 -0
  51. package/routes/dashboard-api.ts +9 -0
  52. package/routes/desktop-updates.ts +7 -0
  53. package/views/dashboard/data/activity/index.stx +1 -1
  54. package/views/dashboard/data/subscribers.stx +1 -3
  55. package/views/dashboard/data/teams.stx +1 -3
  56. package/views/dashboard/data/users.stx +1 -3
  57. package/resources/components/Dashboard/Data/DataRecords.stx +0 -427
@@ -6,16 +6,26 @@
6
6
  // All querying is server-side (`GET /api/dashboard/models/{slug}`), so this
7
7
  // works the same on a table with 10 rows and one with a million. Rows and
8
8
  // writes go through the model, so scopes, casts and observers apply.
9
+ //
10
+ // It is the one list of a model's records. A page with a place of its own
11
+ // (Users, Teams, Subscribers) hosts it: it says which model, what the page is
12
+ // called and where it lives, and puts its own summary above the table.
9
13
  import { useNavigation } from '@stacksjs/defaults/views/dashboard/composables/useNavigation'
10
14
  import { dashboardApi } from '@stacksjs/defaults/functions/dashboard-api'
11
- import type { ModelRelationTarget, ModelWriteCapabilities } from '@stacksjs/defaults/functions/dashboard-model-record'
12
- import { deleteModelRecord, modelDeleteNotice, modelDeleteWarning, modelListColumnNames, modelListFilters, modelRecordCreateHref, modelRecordEditHref, modelRecordHref, modelRelationCell, NO_WRITES, userInviteHref } from '@stacksjs/defaults/functions/dashboard-model-record'
15
+ import type { ModelCustomAction, ModelRelationTarget, ModelWriteCapabilities } from '@stacksjs/defaults/functions/dashboard-model-record'
16
+ import { deleteModelRecord, modelActionAsks, modelActionIconClass, modelActionNotice, modelActionsFor, modelDeleteNotice, modelDeleteWarning, modelListColumnNames, modelListFilters, modelRecordCreateHref, modelRecordEditHref, modelRecordHref, modelRelationCell, NO_WRITES, runModelAction, userInviteHref } from '@stacksjs/defaults/functions/dashboard-model-record'
17
+ import type { ModelBulkResult } from '@stacksjs/defaults/functions/dashboard-model-bulk'
18
+ import { deleteModelRecords, modelBulkActionConfirm, modelBulkActionScope, modelBulkActions, modelBulkDeleteConfirm, modelBulkDeleteTargets, modelBulkNotice, modelBulkTargets, runModelActionOnEach } from '@stacksjs/defaults/functions/dashboard-model-bulk'
19
+ import type { ModelFieldDisplay, ModelFormattedValue } from '@stacksjs/defaults/functions/dashboard-model-format'
20
+ import { modelCellDisplay, modelColumnIsNumeric } from '@stacksjs/defaults/functions/dashboard-model-format'
13
21
  import { pushToast } from '@stacksjs/defaults/functions/toasts'
14
22
 
15
23
  interface ColumnMeta {
16
24
  name: string
17
25
  label: string
18
26
  type: 'number' | 'boolean' | 'date' | 'json' | 'text'
27
+ /** How the model says the value reads (`dashboard.fields`): money, a size, a link. */
28
+ format?: ModelFieldDisplay
19
29
  }
20
30
 
21
31
  interface ResponseShape {
@@ -35,10 +45,15 @@ interface ResponseShape {
35
45
  writeCapabilities: ModelWriteCapabilities
36
46
  /** Rows erased under the app's data-subject rules (users only). */
37
47
  anonymizedIds?: Array<number | string>
48
+ /** The columns erasure empties: placeholders in an anonymized row. */
49
+ anonymizedColumns?: string[]
38
50
  /** The columns the list draws: the model's own choice, or all of them. */
39
51
  listColumns?: string[]
40
52
  relations?: Record<string, ModelRelationTarget>
41
53
  relationNames?: Record<string, Record<string, string>>
54
+ /** The model's own actions (`dashboard.actions`), and which each row is offered. */
55
+ actions?: ModelCustomAction[]
56
+ rowActions?: Record<string, string[]>
42
57
  updateColumns: string[]
43
58
  migrated?: boolean
44
59
  error: string | null
@@ -47,6 +62,16 @@ interface ResponseShape {
47
62
  const PER_PAGE_OPTIONS = [25, 50, 100, 200]
48
63
  const navigation = useNavigation()
49
64
 
65
+ // For a page that hosts this list. The model to list, when it is not the last
66
+ // part of the address; what the page calls itself; and the page's own path,
67
+ // so a record opened from here comes back here.
68
+ const hostedModel = useReactiveProp('model', '')
69
+ const heading = useReactiveProp('heading', '')
70
+ const description = useReactiveProp('description', '')
71
+ const home = useReactiveProp('home', '')
72
+ // Told when a record was deleted or acted on, so a host can read its summary again.
73
+ const emit = defineEmits(['changed'])
74
+
50
75
  const modelName = state('')
51
76
  // The class name, for the one message that tells a developer what was looked for.
52
77
  const modelClass = state('')
@@ -77,8 +102,46 @@ const showFilters = state(Object.keys(filters()).length > 0)
77
102
 
78
103
  const saving = state(false)
79
104
  const confirmingDelete = state<Record<string, unknown> | null>(null)
105
+ // The model's own actions, and the rows the server says each is for.
106
+ const actions = state<ModelCustomAction[]>([])
107
+ const rowActions = state<Record<string, string[]>>({})
108
+ // One of them waiting on its confirmation, and the one that is running.
109
+ const confirmingAction = state<{ action: ModelCustomAction, row: Record<string, unknown> } | null>(null)
110
+ const runningAction = state<{ name: string, id: string } | null>(null)
111
+
112
+ // The rows ticked on this page, by id. A selection is what is on screen: it
113
+ // is dropped whenever the rows are read again.
114
+ const selected = state<string[]>([])
115
+ // What the selection is about to have done to it, waiting on its confirmation.
116
+ const confirmingBulk = state<{ kind: 'action', action: ModelCustomAction } | { kind: 'delete' } | null>(null)
117
+ // How far a run over the selection has got. Null when none is running.
118
+ const bulkProgress = state<{ done: number, total: number } | null>(null)
119
+ // An action that takes input, with its form open: for one row, or (no row)
120
+ // for the selection. And what its last try was refused for.
121
+ const askingAction = state<{ action: ModelCustomAction, row: Record<string, unknown> | null } | null>(null)
122
+ const actionError = state('')
123
+ const actionErrors = state<Record<string, string[]>>({})
124
+
125
+ /** The model's own actions that may be run on a selection: `on: ['bulk']`. */
126
+ const bulkActions = derived(() => modelBulkActions(actions()))
127
+ // A tick box is only drawn when there is something to do with a tick.
128
+ const selectable = derived(() => migrated() && (bulkActions().length > 0 || writeCapabilities().destroy))
129
+ const allSelected = derived(() => rows().length > 0 && rows().every(row => selected().includes(String(row.id))))
130
+ const selectionLabel = derived(() => `${selected().length} selected`)
131
+ const bulkBusy = derived(() => bulkProgress() !== null)
132
+ const bulkProgressLabel = derived(() => {
133
+ const progress = bulkProgress()
134
+ return progress ? `Working: ${Math.min(progress.done + 1, progress.total)} of ${progress.total}` : ''
135
+ })
80
136
 
81
- const slug = derived(() => navigation.urlSegment(-1) || '')
137
+ const slug = derived(() => hostedModel() || navigation.urlSegment(-1) || '')
138
+ /** Where this list lives, for the pages it opens to come back to. */
139
+ const listHref = derived(() => home() || `/models/${slug()}`)
140
+ const title = derived(() => heading() || modelName())
141
+ /** "user", "social post": the model in a sentence or on a button. */
142
+ const oneRecord = derived(() => (modelName() || 'record').toLowerCase())
143
+ // The columns erasure empties, for a row that has been anonymized.
144
+ const anonymizedColumns = state<string[]>([])
82
145
 
83
146
  const recordLabel = derived(() => {
84
147
  const n = totalCount()
@@ -101,9 +164,11 @@ const filterLabel = derived(() => {
101
164
 
102
165
  const isEmpty = derived(() => !loading() && !error() && migrated() && rows().length === 0)
103
166
 
104
- const subtitle = derived(() => migrated()
105
- ? `${recordLabel()} in the ${tableName()} table`
106
- : `The ${tableName()} table has not been created yet`)
167
+ const subtitle = derived(() => {
168
+ if (!migrated())
169
+ return `The ${tableName()} table has not been created yet`
170
+ return description() || `${recordLabel()} in the ${tableName()} table`
171
+ })
107
172
 
108
173
  const deleteDescription = derived(() => {
109
174
  const row = confirmingDelete()
@@ -144,20 +209,64 @@ function relationHref(row: Record<string, unknown>, column: ColumnMeta): string
144
209
  return relationCell(row, column)?.href ?? ''
145
210
  }
146
211
 
212
+ /**
213
+ * A cell as the model says it reads: "$12.00", "1.5 KB", a link, a picture.
214
+ * Null when the model does not say, or nothing is stored.
215
+ */
216
+ function formatted(row: Record<string, unknown>, column: ColumnMeta): ModelFormattedValue | null {
217
+ return modelCellDisplay(column, row[column.name], row)
218
+ }
219
+
220
+ /**
221
+ * What an anonymized row says in a column erasure emptied. The row stores
222
+ * placeholders there ("[erased]", "erased-13"), which read as corrupt data:
223
+ * the first such column names the row for what it is, the rest say removed.
224
+ * Null for every other cell.
225
+ */
226
+ function removed(row: Record<string, unknown>, column: ColumnMeta): string | null {
227
+ if (!isAnonymized(row) || !anonymizedColumns().includes(column.name))
228
+ return null
229
+ const first = columnMeta().find(candidate => anonymizedColumns().includes(candidate.name))
230
+ return first?.name === column.name ? `Anonymized ${oneRecord()}` : 'Removed'
231
+ }
232
+
233
+ /** How a cell is drawn: a link to a record, or what its format calls for, or words. */
234
+ function cellKind(row: Record<string, unknown>, column: ColumnMeta): 'relation' | 'removed' | ModelFormattedValue['kind'] {
235
+ if (removed(row, column))
236
+ return 'removed'
237
+ if (relationHref(row, column))
238
+ return 'relation'
239
+ return formatted(row, column)?.kind ?? 'text'
240
+ }
241
+
242
+ function cellHref(row: Record<string, unknown>, column: ColumnMeta): string {
243
+ return formatted(row, column)?.href ?? ''
244
+ }
245
+
246
+ function cellTone(row: Record<string, unknown>, column: ColumnMeta): string {
247
+ return formatted(row, column)?.tone ?? 'neutral'
248
+ }
249
+
147
250
  function cellValue(row: Record<string, unknown>, column: ColumnMeta): string {
148
- return relationCell(row, column)?.text ?? formatCell(row[column.name], column.type)
251
+ const gone = removed(row, column)
252
+ if (gone)
253
+ return gone
254
+ if (relationCell(row, column))
255
+ return relationCell(row, column)!.text
256
+ // Words for what is stored: as the model says, as a status reads, or as it is.
257
+ return formatted(row, column)?.text ?? (column.format ? '-' : formatCell(row[column.name], column.type))
149
258
  }
150
259
 
151
260
  // Returned as COMPLETE class strings and applied with `:class`, because a
152
261
  // `{{ }}` placeholder inside a class attribute is not reactively bound.
153
262
  function cellClass(column: ColumnMeta): string {
154
- const align = column.type === 'number' ? 'text-right tabular-nums' : 'text-left'
155
- const mono = column.type === 'json' ? ' font-mono text-[12px]' : ''
263
+ const align = modelColumnIsNumeric(column) ? 'text-right tabular-nums' : 'text-left'
264
+ const mono = column.type === 'json' && !column.format ? ' font-mono text-[12px]' : ''
156
265
  return `px-3 py-2 max-w-xs truncate whitespace-nowrap text-[13px] text-neutral-800 dark:text-neutral-200 ${align}${mono}`
157
266
  }
158
267
 
159
268
  function headerClass(column: ColumnMeta): string {
160
- const align = column.type === 'number' ? 'justify-end' : 'justify-start'
269
+ const align = modelColumnIsNumeric(column) ? 'justify-end' : 'justify-start'
161
270
  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`
162
271
  }
163
272
 
@@ -174,6 +283,8 @@ async function load() {
174
283
  }
175
284
  loading.set(true)
176
285
  error.set(null)
286
+ // The rows about to arrive may not be the ones that were ticked.
287
+ selected.set([])
177
288
  try {
178
289
  const params = new URLSearchParams({
179
290
  page: String(page()),
@@ -192,12 +303,15 @@ async function load() {
192
303
  tableName.set(data.tableName ?? '')
193
304
  rows.set(data.rows ?? [])
194
305
  anonymizedIds.set((data.anonymizedIds ?? []).map(String))
306
+ anonymizedColumns.set(data.anonymizedColumns ?? [])
195
307
  // Only reassign when the column set actually changes. It is the same for
196
308
  // every page and every sort of a given model, and re-rendering the
197
309
  // header `:for` on each query both wastes work and trips a reconciler
198
310
  // bug that leaves the columns rotated out of order.
199
311
  relations.set(data.relations ?? {})
200
312
  relationNames.set(data.relationNames ?? {})
313
+ actions.set(data.actions ?? [])
314
+ rowActions.set(data.rowActions ?? {})
201
315
  // The columns the model chose for its list, and any the list is filtered on.
202
316
  const every = data.columnMeta ?? []
203
317
  const shown = modelListColumnNames(every.map(column => column.name), data.listColumns, active)
@@ -265,23 +379,171 @@ function isAnonymized(row: Record<string, unknown>): boolean {
265
379
  return anonymizedIds().includes(String(row.id))
266
380
  }
267
381
 
268
- // The eye and the pencil each open a page of the record's own.
382
+ // The eye and the pencil each open a page of the record's own, which comes
383
+ // back to this list wherever it is hosted.
269
384
  function startEdit(row: Record<string, unknown>) {
270
- navigate(modelRecordEditHref(slug(), String(row.id)))
385
+ navigate(modelRecordEditHref(slug(), String(row.id), { from: home() || undefined }))
271
386
  }
272
387
 
273
388
  function startView(row: Record<string, unknown>) {
274
- navigate(modelRecordHref(slug(), String(row.id)))
389
+ navigate(modelRecordHref(slug(), String(row.id), home() || undefined))
275
390
  }
276
391
 
277
392
  // Creating has a page of its own too.
278
393
  function openCreate(): void {
279
- navigate(modelRecordCreateHref(slug()))
394
+ navigate(modelRecordCreateHref(slug(), home() || undefined))
280
395
  }
281
396
 
282
397
  // A user is invited, not typed in: the account's holder chooses the password.
283
398
  function openInvite(): void {
284
- navigate(userInviteHref(`/models/${slug()}`))
399
+ navigate(userInviteHref(listHref()))
400
+ }
401
+
402
+ /** The model's own actions this row is offered in a list. */
403
+ function actionsFor(row: Record<string, unknown>): ModelCustomAction[] {
404
+ return modelActionsFor(actions(), rowActions(), String(row.id), 'row')
405
+ }
406
+
407
+ /** The name of the action running on this row, if one is. */
408
+ function runningOn(row: Record<string, unknown>): string {
409
+ const current = runningAction()
410
+ return current && current.id === String(row.id) ? current.name : ''
411
+ }
412
+
413
+ function openActionForm(action: ModelCustomAction, row: Record<string, unknown> | null): void {
414
+ actionError.set('')
415
+ actionErrors.set({})
416
+ askingAction.set({ action, row })
417
+ }
418
+
419
+ // An action that takes input opens its form, one that asks first its
420
+ // confirmation, and any other runs.
421
+ function startAction(payload: { action: ModelCustomAction, record: Record<string, unknown> }): void {
422
+ if (modelActionAsks(payload.action))
423
+ openActionForm(payload.action, payload.record)
424
+ else if (payload.action.confirm)
425
+ confirmingAction.set({ action: payload.action, row: payload.record })
426
+ else
427
+ void runAction(payload.action, payload.record)
428
+ }
429
+
430
+ async function runAction(action: ModelCustomAction, row: Record<string, unknown>, input: Record<string, unknown> = {}): Promise<void> {
431
+ if (runningAction())
432
+ return
433
+ runningAction.set({ name: action.name, id: String(row.id) })
434
+ const result = await runModelAction(slug(), String(row.id), action.name, input)
435
+ runningAction.set(null)
436
+ confirmingAction.set(null)
437
+ // A refusal of what was typed is answered where it was typed.
438
+ if (!result.ok && askingAction()) {
439
+ actionError.set(result.error)
440
+ actionErrors.set(result.errors ?? {})
441
+ return
442
+ }
443
+ askingAction.set(null)
444
+ const notice = modelActionNotice(action, result)
445
+ pushToast(notice.tone, notice.title, { detail: notice.detail })
446
+ if (!result.ok)
447
+ return
448
+ emit('changed')
449
+ if (result.redirect)
450
+ navigate(result.redirect)
451
+ else
452
+ // The row may read differently now, and be offered different actions.
453
+ await load()
454
+ }
455
+
456
+ function confirmAction(): void {
457
+ const pending = confirmingAction()
458
+ if (pending)
459
+ void runAction(pending.action, pending.row)
460
+ }
461
+
462
+ function isSelected(row: Record<string, unknown>): boolean {
463
+ return selected().includes(String(row.id))
464
+ }
465
+
466
+ function toggleSelected(row: Record<string, unknown>): void {
467
+ const id = String(row.id)
468
+ selected.set(isSelected(row) ? selected().filter(candidate => candidate !== id) : [...selected(), id])
469
+ }
470
+
471
+ function toggleAllSelected(): void {
472
+ selected.set(allSelected() ? [] : rows().map(row => String(row.id)))
473
+ }
474
+
475
+ /** The selected rows an action is for: the server has said which rows it applies to. */
476
+ function bulkTargets(action: ModelCustomAction): string[] {
477
+ return modelBulkTargets(action, rowActions(), selected())
478
+ }
479
+
480
+ /** The selected rows a delete is for: an anonymized account is left alone. */
481
+ function bulkDeleteTargets(): string[] {
482
+ return modelBulkDeleteTargets(selected(), anonymizedIds())
483
+ }
484
+
485
+ // Acting on many records always asks first, whatever a single press does.
486
+ const bulkConfirm = derived(() => {
487
+ const pending = confirmingBulk()
488
+ if (!pending)
489
+ return { title: '', description: '', label: 'Run', destructive: false }
490
+ if (pending.kind === 'delete')
491
+ return { ...modelBulkDeleteConfirm(bulkDeleteTargets().length, selected().length, writeCapabilities().anonymize), label: 'Delete', destructive: true }
492
+ return { ...modelBulkActionConfirm(pending.action, bulkTargets(pending.action).length, selected().length), label: pending.action.label, destructive: pending.action.destructive }
493
+ })
494
+
495
+ // Acting on a selection always asks first: in the action's form when it
496
+ // takes input, in a confirmation when it does not.
497
+ function startBulkAction(action: ModelCustomAction): void {
498
+ if (modelActionAsks(action))
499
+ openActionForm(action, null)
500
+ else
501
+ confirmingBulk.set({ kind: 'action', action })
502
+ }
503
+
504
+ /** What the form is told beside the model's own sentence: how far the action reaches. */
505
+ const actionFormNote = derived(() => {
506
+ const asking = askingAction()
507
+ return asking && !asking.row ? modelBulkActionScope(bulkTargets(asking.action).length, selected().length) : ''
508
+ })
509
+
510
+ function submitAction(input: Record<string, unknown>): void {
511
+ const asking = askingAction()
512
+ if (!asking)
513
+ return
514
+ if (asking.row)
515
+ void runAction(asking.action, asking.row, input)
516
+ else
517
+ void runBulk({ kind: 'action', action: asking.action }, input)
518
+ }
519
+
520
+ async function runBulk(pending = confirmingBulk(), input: Record<string, unknown> = {}): Promise<void> {
521
+ if (!pending || bulkBusy())
522
+ return
523
+ const track = (done: number, total: number) => bulkProgress.set({ done, total })
524
+ let result: ModelBulkResult
525
+ if (pending.kind === 'delete')
526
+ result = await deleteModelRecords(slug(), bulkDeleteTargets(), track)
527
+ else
528
+ result = await runModelActionOnEach(slug(), bulkTargets(pending.action), pending.action.name, { input, progress: track })
529
+ bulkProgress.set(null)
530
+ // What was typed was refused by the first record: nothing ran, and the
531
+ // form says which field and why.
532
+ if (Object.keys(result.invalid).length > 0) {
533
+ actionError.set(Object.keys(result.invalid).length === 1 ? 'Check the field marked below.' : `Check the ${Object.keys(result.invalid).length} fields marked below.`)
534
+ actionErrors.set(result.invalid)
535
+ return
536
+ }
537
+ askingAction.set(null)
538
+ confirmingBulk.set(null)
539
+ const notice = modelBulkNotice(pending.kind === 'delete' ? { kind: 'delete' } : { kind: 'action', label: pending.action.label }, modelName(), result)
540
+ pushToast(notice.tone, notice.title, { detail: notice.detail })
541
+ // Deleting every row of the final page would strand the viewer on an empty one.
542
+ if (pending.kind === 'delete' && result.done >= rows().length && page() > 1)
543
+ page.set(page() - 1)
544
+ if (result.done > 0)
545
+ emit('changed')
546
+ await load()
285
547
  }
286
548
 
287
549
  async function confirmDelete() {
@@ -296,6 +558,7 @@ async function confirmDelete() {
296
558
  // Deleting the last row of the final page would strand the viewer on an
297
559
  // empty page, so step back one.
298
560
  if (rows().length === 1 && page() > 1) page.set(page() - 1)
561
+ emit('changed')
299
562
  await load()
300
563
  }
301
564
  catch (e) {
@@ -306,7 +569,12 @@ async function confirmDelete() {
306
569
  }
307
570
  }
308
571
 
309
- void load()
572
+ // On mount, not while setting up: a page that hosts this list says which
573
+ // model through a prop, and a prop is not bound until then. Loading sooner
574
+ // asked for the model named by the last part of the host's own address.
575
+ onMount(() => {
576
+ void load()
577
+ })
310
578
  </script>
311
579
 
312
580
  <template>
@@ -318,7 +586,7 @@ void load()
318
586
  `:text` bindings here stay reactive. -->
319
587
  <div class="flex flex-wrap gap-4 items-start justify-between">
320
588
  <div class="min-w-0">
321
- <h1 class="font-bold text-2xl text-neutral-900 truncate dark:text-white" :text="modelName()"></h1>
589
+ <h1 class="font-bold text-2xl text-neutral-900 truncate dark:text-white" :text="title()"></h1>
322
590
  <p class="mt-1 text-[13px] text-neutral-500 dark:text-neutral-400" :text="subtitle()"></p>
323
591
  </div>
324
592
  <div class="flex gap-2 items-center">
@@ -327,14 +595,14 @@ void load()
327
595
  @click="openCreate"
328
596
  >
329
597
  <span aria-hidden="true" class="h-4 w-4 i-hugeicons-add-01"></span>
330
- Create
598
+ <span :text="'Create ' + oneRecord()"></span>
331
599
  </Button>
332
600
  <Button
333
601
  :if="writeCapabilities().invite"
334
602
  @click="openInvite"
335
603
  >
336
604
  <span aria-hidden="true" class="h-4 w-4 i-hugeicons-mail-send-01"></span>
337
- Invite
605
+ <span :text="'Invite ' + oneRecord()"></span>
338
606
  </Button>
339
607
  <Button
340
608
  :if="migrated()"
@@ -350,6 +618,9 @@ void load()
350
618
  </div>
351
619
  </div>
352
620
 
621
+ <!-- What the page hosting this list puts above it: its row of stats. -->
622
+ <slot name="summary" />
623
+
353
624
  <!-- Search + page size -->
354
625
  <div :if="migrated()" class="flex flex-wrap gap-3 items-center">
355
626
  <div class="relative flex-1 max-w-sm">
@@ -383,6 +654,39 @@ void load()
383
654
  </div>
384
655
  </div>
385
656
 
657
+ <!-- What can be done to the ticked rows. Only there when some are ticked. -->
658
+ <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">
659
+ <p class="font-medium text-[13px] text-neutral-800 dark:text-neutral-100" aria-live="polite">
660
+ <span :if="!bulkBusy()" :text="selectionLabel()"></span>
661
+ <span :if="bulkBusy()" :text="bulkProgressLabel()"></span>
662
+ </p>
663
+ <div class="flex flex-wrap gap-2 items-center">
664
+ <span :for="action in bulkActions()" class="contents">
665
+ <Button
666
+ variant="secondary"
667
+ size="sm"
668
+ :disabled="bulkBusy() || bulkTargets(action).length === 0"
669
+ :title="bulkTargets(action).length === 0 ? 'Does not apply to any of the selected rows' : action.label"
670
+ @click="startBulkAction(action)"
671
+ >
672
+ <span aria-hidden="true" :class="modelActionIconClass(action)"></span>
673
+ {{ action.label }}
674
+ </Button>
675
+ </span>
676
+ <Button
677
+ :if="writeCapabilities().destroy"
678
+ variant="secondary"
679
+ size="sm"
680
+ :disabled="bulkBusy() || bulkDeleteTargets().length === 0"
681
+ @click="confirmingBulk.set({ kind: 'delete' })"
682
+ >
683
+ <span aria-hidden="true" class="h-4 w-4 text-red-500 i-hugeicons-delete-02"></span>
684
+ Delete
685
+ </Button>
686
+ <Button variant="ghost" size="sm" :disabled="bulkBusy()" @click="selected.set([])">Clear</Button>
687
+ </div>
688
+ </div>
689
+
386
690
  <div :if="error()" class="p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 rounded-xl dark:border-red-800">
387
691
  <div class="flex gap-3 items-start">
388
692
  <span class="flex-shrink-0 mt-0.5 h-5 w-5 text-red-500 i-hugeicons-alert-02"></span>
@@ -423,6 +727,16 @@ void load()
423
727
  <table class="min-w-full">
424
728
  <thead class="bg-neutral-50 dark:bg-white/5">
425
729
  <tr>
730
+ <th :if="selectable()" scope="col" class="pl-3 pr-1 py-2 w-8">
731
+ <input
732
+ type="checkbox"
733
+ aria-label="Select every row on this page"
734
+ :checked="allSelected()"
735
+ :disabled="loading() || bulkBusy() || rows().length === 0"
736
+ class="block h-4 w-4 text-blue-600 border-neutral-300 rounded"
737
+ @change="toggleAllSelected()"
738
+ />
739
+ </th>
426
740
  <th :for="column in columnMeta()" scope="col" class="px-3 py-2 whitespace-nowrap group">
427
741
  <button type="button" @click="toggleSort(column)" :class="headerClass(column)">
428
742
  <span>{{ column.label }}</span>
@@ -434,6 +748,7 @@ void load()
434
748
 
435
749
  <!-- Per-column filter row -->
436
750
  <tr :if="showFilters()" class="bg-white dark:bg-neutral-900">
751
+ <th :if="selectable()"></th>
437
752
  <th :for="column in columnMeta()" scope="col" class="pb-2 px-2">
438
753
  <input
439
754
  type="text"
@@ -453,6 +768,7 @@ void load()
453
768
  compose, and a table may legally carry several bodies. -->
454
769
  <tbody :if="loading()" class="divide-black/5 divide-y dark:divide-white/8">
455
770
  <tr :for="i in skeletonRows()">
771
+ <td :if="selectable()" class="pl-3 pr-1 py-2 w-8"></td>
456
772
  <td :for="column in columnMeta()" class="px-3 py-2">
457
773
  <div class="h-3 bg-neutral-200 dark:bg-white/10 rounded animate-pulse"></div>
458
774
  </td>
@@ -464,9 +780,24 @@ void load()
464
780
 
465
781
  <tbody :if="!loading()" class="divide-black/5 divide-y dark:divide-white/8">
466
782
  <tr :for="row in rows()" class="hover:bg-neutral-50 dark:hover:bg-white/5 transition-colors group">
783
+ <td :if="selectable()" class="pl-3 pr-1 py-2 w-8">
784
+ <input
785
+ type="checkbox"
786
+ :aria-label="'Select ' + modelName() + ' ' + row.id"
787
+ :checked="isSelected(row)"
788
+ :disabled="bulkBusy()"
789
+ class="block h-4 w-4 text-blue-600 border-neutral-300 rounded"
790
+ @change="toggleSelected(row)"
791
+ />
792
+ </td>
467
793
  <td :for="column in columnMeta()" :class="cellClass(column)" :title="cellValue(row, column)">
468
794
  <StxLink :if="relationHref(row, column)" :to="relationHref(row, column)" class="font-medium text-blue-600 dark:text-blue-400 hover:underline">{{ cellValue(row, column) }}</StxLink>
469
- <span :if="!relationHref(row, column)">{{ cellValue(row, column) }}</span>
795
+ <span :if="cellKind(row, column) === 'text'">{{ cellValue(row, column) }}</span>
796
+ <ModelBadge :if="cellKind(row, column) === 'badge'" :text="cellValue(row, column)" :tone="cellTone(row, column)" />
797
+ <span :if="cellKind(row, column) === 'removed'" class="italic text-neutral-500 dark:text-neutral-400">{{ cellValue(row, column) }}</span>
798
+ <a :if="cellKind(row, column) === 'link'" :href="cellHref(row, column)" target="_blank" rel="noopener noreferrer" class="text-blue-600 dark:text-blue-400 hover:underline">{{ cellValue(row, column) }}</a>
799
+ <img :if="cellKind(row, column) === 'image'" :src="cellHref(row, column)" alt="" loading="lazy" class="inline-block object-cover h-7 w-7 bg-neutral-100 dark:bg-neutral-800 rounded" />
800
+ <code :if="cellKind(row, column) === 'code'" class="font-mono text-[12px]">{{ cellValue(row, column) }}</code>
470
801
  </td>
471
802
  <td class="right-0 sticky z-10 px-3 py-2 text-right bg-white dark:bg-neutral-900 group-hover:bg-neutral-50 dark:group-hover:bg-white/5 border-black/5 border-l dark:border-white/10 transition-colors">
472
803
  <ModelRecordActions
@@ -474,6 +805,9 @@ void load()
474
805
  :modelName="modelName()"
475
806
  :canUpdate="writeCapabilities().update && !isAnonymized(row)"
476
807
  :canDestroy="writeCapabilities().destroy && !isAnonymized(row)"
808
+ :actions="actionsFor(row)"
809
+ :running="runningOn(row)"
810
+ @action="startAction"
477
811
  @view="startView"
478
812
  @edit="startEdit"
479
813
  @delete="confirmingDelete.set($event)"
@@ -505,6 +839,39 @@ void load()
505
839
  @close="confirmingDelete.set(null)"
506
840
  @confirm="confirmDelete"
507
841
  />
842
+
843
+ <ConfirmDialog
844
+ :isOpen="Boolean(confirmingAction())"
845
+ :title="(confirmingAction()?.action.label || 'Run this action') + '?'"
846
+ :description="confirmingAction()?.action.confirm || ''"
847
+ :variant="confirmingAction()?.action.destructive ? 'danger' : 'warning'"
848
+ :busy="Boolean(runningAction())"
849
+ :confirmLabel="confirmingAction()?.action.label || 'Run'"
850
+ @close="confirmingAction.set(null)"
851
+ @confirm="confirmAction"
852
+ />
853
+
854
+ <ConfirmDialog
855
+ :isOpen="Boolean(confirmingBulk())"
856
+ :title="bulkConfirm().title"
857
+ :description="bulkConfirm().description"
858
+ :variant="bulkConfirm().destructive ? 'danger' : 'warning'"
859
+ :busy="bulkBusy()"
860
+ :confirmLabel="bulkBusy() ? bulkProgressLabel() : bulkConfirm().label"
861
+ @close="confirmingBulk.set(null)"
862
+ @confirm="runBulk()"
863
+ />
864
+
865
+ <ModelActionForm
866
+ :action="askingAction()?.action ?? null"
867
+ :note="actionFormNote()"
868
+ :busy="Boolean(runningAction()) || bulkBusy()"
869
+ :busyLabel="bulkProgressLabel()"
870
+ :error="actionError()"
871
+ :errors="actionErrors()"
872
+ @close="askingAction.set(null)"
873
+ @submit="submitAction"
874
+ />
508
875
  </div>
509
876
  </template>
510
877