@stacksjs/defaults 0.75.556 → 0.75.558

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 (49) hide show
  1. package/ai/skills/stacks-dashboard/SKILL.md +88 -11
  2. package/ai/skills/stacks-desktop/SKILL.md +15 -4
  3. package/ai/skills/stacks-migrations/SKILL.md +10 -0
  4. package/ai/skills/stacks-native/CATALOG.md +3 -3
  5. package/app/Actions/Dashboard/Models/GetModels.ts +4 -3
  6. package/app/Actions/Dashboard/Models/ModelsIndexAction.ts +6 -4
  7. package/app/Actions/Dashboard/Search/GlobalSearchAction.ts +3 -4
  8. package/app/Actions/Dashboard/Search/SearchEngineIndexAction.ts +4 -4
  9. package/app/Models/Board.ts +4 -0
  10. package/app/Models/Campaign.ts +24 -0
  11. package/app/Models/Card.ts +4 -0
  12. package/app/Models/CardComment.ts +7 -1
  13. package/app/Models/Comment.ts +8 -0
  14. package/app/Models/Content/Author.ts +6 -0
  15. package/app/Models/Content/Page.ts +7 -0
  16. package/app/Models/Content/Post.ts +12 -0
  17. package/app/Models/EmailList.ts +4 -0
  18. package/app/Models/FailedJob.ts +11 -0
  19. package/app/Models/MailPreference.ts +4 -0
  20. package/app/Models/NotificationDelivery.ts +12 -0
  21. package/app/Models/SocialPost.ts +6 -0
  22. package/app/Models/Tag.ts +7 -0
  23. package/app/Models/Team.ts +1 -0
  24. package/app/Models/User.ts +2 -1
  25. package/app/Models/commerce/AuctionItem.ts +4 -0
  26. package/app/Models/commerce/Cart.ts +4 -0
  27. package/app/Models/commerce/Category.ts +4 -0
  28. package/app/Models/commerce/Customer.ts +4 -0
  29. package/app/Models/commerce/DeliveryStop.ts +4 -0
  30. package/app/Models/commerce/LoyaltyReward.ts +6 -0
  31. package/app/Models/commerce/Manufacturer.ts +4 -0
  32. package/app/Models/commerce/Product.ts +4 -0
  33. package/app/Models/commerce/ProductUnit.ts +4 -0
  34. package/app/Models/commerce/Review.ts +4 -0
  35. package/app/Models/commerce/ShippingMethod.ts +4 -0
  36. package/app/Models/commerce/WaitlistProduct.ts +4 -0
  37. package/app/Notifications/Welcome.ts +1 -1
  38. package/functions/dashboard-loading.ts +36 -0
  39. package/functions/dashboard-model-record.ts +11 -0
  40. package/ide/vscode/package.json +1 -1
  41. package/package.json +5 -5
  42. package/resources/components/Dashboard/Data/DataModelRecords.stx +6 -3
  43. package/resources/components/Dashboard/Models/ModelRecordCreate.stx +9 -6
  44. package/resources/components/Dashboard/Models/ModelRecordDetail.stx +17 -10
  45. package/resources/components/Dashboard/Models/ModelRecordEdit.stx +9 -6
  46. package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +38 -25
  47. package/resources/components/Dashboard/Models/ModelsOverview.stx +30 -11
  48. package/resources/components/Dashboard/UI/QuietLoader.stx +24 -0
  49. package/resources/functions/dashboard/model-access.ts +22 -4
@@ -92,5 +92,9 @@ export default defineModel({
92
92
 
93
93
  dashboard: {
94
94
  highlight: true,
95
+ // Prose, asked for in a box with room for it.
96
+ fields: {
97
+ description: { input: 'longtext' },
98
+ },
95
99
  },
96
100
  } as const)
@@ -170,5 +170,9 @@ export default defineModel({
170
170
 
171
171
  dashboard: {
172
172
  highlight: true,
173
+ // An address that leads to a picture: shown as one.
174
+ fields: {
175
+ imageUrl: { format: 'image' },
176
+ },
173
177
  },
174
178
  } as const)
@@ -115,5 +115,9 @@ export default defineModel({
115
115
 
116
116
  dashboard: {
117
117
  highlight: true,
118
+ // Prose, asked for in a box with room for it.
119
+ fields: {
120
+ description: { input: 'longtext' },
121
+ },
118
122
  },
119
123
  } as const)
@@ -174,5 +174,9 @@ export default defineModel({
174
174
 
175
175
  dashboard: {
176
176
  highlight: true,
177
+ // Prose, asked for in a box with room for it.
178
+ fields: {
179
+ content: { input: 'longtext' },
180
+ },
177
181
  },
178
182
  } as const)
@@ -104,5 +104,9 @@ export default defineModel({
104
104
 
105
105
  dashboard: {
106
106
  highlight: true,
107
+ // Prose, asked for in a box with room for it.
108
+ fields: {
109
+ description: { input: 'longtext' },
110
+ },
107
111
  },
108
112
  } as const)
@@ -157,5 +157,9 @@ export default defineModel({
157
157
 
158
158
  dashboard: {
159
159
  highlight: true,
160
+ // Prose, asked for in a box with room for it.
161
+ fields: {
162
+ notes: { input: 'longtext' },
163
+ },
160
164
  },
161
165
  } as const)
@@ -5,7 +5,7 @@ import { log } from '@stacksjs/logging'
5
5
  export default new Email({
6
6
  // or Sms or Push or Webhook or Chat
7
7
  name: 'welcome', // optional, defaults to the file name
8
- subject: 'Welcome to Stacks', // optional, but recommended
8
+ subject: `Welcome to ${config.app.name || 'our app'}`, // optional, but recommended
9
9
  to: 'some@email.com', // optional, has to be defined here or set when sending
10
10
  from: config.email.from, // optional, defaults to the config value
11
11
  template: 'Welcome', // resources/emails/Welcome.stx
@@ -0,0 +1,36 @@
1
+ /**
2
+ * When a page says it is loading.
3
+ *
4
+ * Not at once. Most dashboard requests answer in a few tens of milliseconds,
5
+ * and a loader drawn for that long is a flash: something appears, means
6
+ * nothing, and is gone. A page waits this long first, and says it is loading
7
+ * only if the answer has still not come.
8
+ *
9
+ * What a page shows meanwhile is its own: one quiet panel where the content
10
+ * will be before a first answer (`UI/QuietLoader.stx`), and the content it
11
+ * already has, dimmed, when it is asking again. Never placeholder shapes, and
12
+ * never a number or an empty state it does not know to be true.
13
+ */
14
+ export const DASHBOARD_LOADER_DELAY = 250
15
+
16
+ /**
17
+ * Start waiting on a request. `slow` is set once it has taken long enough to
18
+ * say so, and the function this returns ends the wait: call it when the
19
+ * answer (or the failure) comes.
20
+ *
21
+ * const settle = dashboardLoaderTimer(slow)
22
+ * try { ... } finally { settle() }
23
+ */
24
+ export function dashboardLoaderTimer(slow: { set: (value: boolean) => void }, delay: number = DASHBOARD_LOADER_DELAY): () => void {
25
+ const timer = setTimeout(() => slow.set(true), delay)
26
+ return () => {
27
+ clearTimeout(timer)
28
+ slow.set(false)
29
+ }
30
+ }
31
+
32
+ /** The classes of content that stays on screen while it is asked for again. */
33
+ export function dashboardReloadingClass(loading: boolean, base: string = ''): string {
34
+ const classes = loading ? 'opacity-50 pointer-events-none transition-opacity duration-150' : 'transition-opacity duration-150'
35
+ return base ? `${base} ${classes}` : classes
36
+ }
@@ -357,6 +357,17 @@ export function modelRecordListLabel(record: { tableName?: string } | null, back
357
357
  return record?.tableName ? titleCase(record.tableName) : 'Records'
358
358
  }
359
359
 
360
+ /**
361
+ * What a model is called before its record has come, from the page's address:
362
+ * `social-post` is "Social Post". The heading says "View Social Post" from
363
+ * the first paint and does not change when the answer arrives. (The server's
364
+ * own word wins once it does; it differs only where it spells an initialism,
365
+ * "GDPR Request".)
366
+ */
367
+ export function modelNameFromSlug(slug: string): string {
368
+ return titleCase(slug.trim()) || 'Record'
369
+ }
370
+
360
371
  /** What to call a record in a heading: its name, title or email, else its id. */
361
372
  export function modelRecordTitle(record: ModelRecord): string {
362
373
  for (const key of ['name', 'title', 'email', 'subject']) {
@@ -2,7 +2,7 @@
2
2
  "publisher": "Stacks",
3
3
  "name": "vscode-stacks",
4
4
  "displayName": "Stacks",
5
- "version": "0.75.556",
5
+ "version": "0.75.558",
6
6
  "description": "Stacks, built into VS Code: stx templates, pickier linting and formatting, encrypted env files, the dev server preview and every buddy command. No other extensions required.",
7
7
  "license": "MIT",
8
8
  "funding": "https://github.com/sponsors/chrisbbreuer",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/defaults",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.556",
5
+ "version": "0.75.558",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/stacksjs/stacks.git",
@@ -45,10 +45,10 @@
45
45
  "dependencies": {
46
46
  "@iconify-json/f7": "^1.2.2",
47
47
  "@iconify-json/hugeicons": "^1.2.35",
48
- "@stacksjs/mobile": "0.75.556",
49
- "@stacksjs/sanitizer": "^0.2.859",
50
- "@stacksjs/stx": "^0.2.859",
51
- "@stacksjs/strings": "0.75.556",
48
+ "@stacksjs/mobile": "0.75.558",
49
+ "@stacksjs/sanitizer": "^0.2.864",
50
+ "@stacksjs/stx": "^0.2.864",
51
+ "@stacksjs/strings": "0.75.558",
52
52
  "@xterm/addon-fit": "^0.11.0",
53
53
  "@xterm/xterm": "^6.0.0",
54
54
  "ts-qr-codes": "^0.1.8"
@@ -17,7 +17,9 @@ import { fetchDashboardStats } from '../../../../functions/data'
17
17
  type RecordsPage = 'users' | 'teams' | 'subscribers'
18
18
 
19
19
  const pageMode = useReactiveProp<RecordsPage>('mode', 'users')
20
- const pageStats = state<DataStats>({ total: 0 })
20
+ // Null until the numbers have come. A card says nothing until then: a 0 is a
21
+ // count, and "no users" is not what is known while the page is still asking.
22
+ const pageStats = state<DataStats | null>(null)
21
23
 
22
24
  const PAGES: Record<RecordsPage, { model: string, title: string, description: string, icon: string, cards: 3 | 4 }> = {
23
25
  users: { model: 'user', title: 'Users', description: 'Review registered application users.', icon: 'i-hugeicons-user-group', cards: 3 },
@@ -29,8 +31,9 @@ const recordsPage = derived(() => PAGES[pageMode()] ?? PAGES.users)
29
31
  /** Each page's stats fill their row: three cards in a four-column grid left a hole. */
30
32
  const pageStatsGrid = derived(() => recordsPage().cards === 3 ? 'grid-cols-1 sm:grid-cols-3' : 'grid-cols-2 lg:grid-cols-4')
31
33
 
32
- function pageStat(key: string): number {
33
- return Number(pageStats()[key] || 0)
34
+ function pageStat(key: string): string {
35
+ const numbers = pageStats()
36
+ return numbers ? Number(numbers[key] || 0).toLocaleString() : '-'
34
37
  }
35
38
 
36
39
  async function loadPageStats(): Promise<void> {
@@ -7,13 +7,16 @@
7
7
  // page.
8
8
  import { useNavigation } from '@stacksjs/defaults/views/dashboard/composables/useNavigation'
9
9
  import type { ModelCreateForm, ModelFormValues } from '../../../../functions/dashboard-model-record'
10
- import { createModelRecord, fetchModelCreateForm, modelFormPayload, modelFormPrefill, modelFormValues, modelRecordBackHref, modelRecordHref, modelRecordListLabel, userInviteHref } from '../../../../functions/dashboard-model-record'
10
+ import { createModelRecord, fetchModelCreateForm, modelNameFromSlug, modelFormPayload, modelFormPrefill, modelFormValues, modelRecordBackHref, modelRecordHref, modelRecordListLabel, userInviteHref } from '../../../../functions/dashboard-model-record'
11
+ import { dashboardLoaderTimer } from '../../../../functions/dashboard-loading'
11
12
  import { pushToast } from '../../../../functions/toasts'
12
13
 
13
14
  const navigation = useNavigation()
14
15
  const form = state<ModelCreateForm | null>(null)
15
16
  const values = state<ModelFormValues>({})
16
17
  const loading = state(true)
18
+ // Set once the request has taken long enough to say so (dashboard-loading.ts).
19
+ const slow = state(false)
17
20
  const loadError = state('')
18
21
  const creating = state(false)
19
22
  const createError = state('')
@@ -27,7 +30,8 @@ function slug(): string {
27
30
  const from = navigation.urlQuery('from')
28
31
  const listHref = derived(() => modelRecordBackHref(slug(), from))
29
32
  const listLabel = derived(() => modelRecordListLabel(form(), listHref()))
30
- const modelName = derived(() => form()?.modelName || 'Record')
33
+ // Known from the address before the form comes, so the heading does not change.
34
+ const modelName = derived(() => form()?.modelName || modelNameFromSlug(slug()))
31
35
  const fields = derived(() => form()?.fields ?? [])
32
36
  const canCreate = derived(() => Boolean(form()?.canCreate) && fields().length > 0)
33
37
  /** A model added by invitation has no form here; the page points at the one that does. */
@@ -44,6 +48,7 @@ function setValue(change: { name: string, value: string | boolean }): void {
44
48
  async function loadForm(): Promise<void> {
45
49
  loading.set(true)
46
50
  loadError.set('')
51
+ const settle = dashboardLoaderTimer(slow)
47
52
  try {
48
53
  const loaded = await fetchModelCreateForm(slug())
49
54
  form.set(loaded)
@@ -55,6 +60,7 @@ async function loadForm(): Promise<void> {
55
60
  loadError.set(error instanceof Error ? error.message : 'This form could not be loaded.')
56
61
  }
57
62
  finally {
63
+ settle()
58
64
  loading.set(false)
59
65
  }
60
66
  }
@@ -100,10 +106,7 @@ onMount(() => {
100
106
  <h1 class="font-bold text-3xl text-neutral-900 tracking-tight truncate dark:text-white">Create {{ modelName() }}</h1>
101
107
  </header>
102
108
 
103
- <div :if="loading()" class="flex items-center justify-center py-20 text-neutral-500 text-sm dark:text-neutral-400">
104
- <span aria-hidden="true" class="mr-2 h-5 w-5 animate-spin i-hugeicons-loading-03"></span>
105
- Loading form
106
- </div>
109
+ <QuietLoader :if="loading()" :slow="slow()" label="Loading form" />
107
110
 
108
111
  <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">
109
112
  <span>{{ loadError() }}</span>
@@ -9,12 +9,16 @@
9
9
  // address to share, open in a tab and come back to.
10
10
  import { useNavigation } from '@stacksjs/defaults/views/dashboard/composables/useNavigation'
11
11
  import type { ModelCustomAction, ModelRecord, ModelRelatedPanel } from '../../../../functions/dashboard-model-record'
12
- import { deleteModelRecord, fetchModelRecord, fetchModelRelated, modelActionAsks, modelActionIconClass, modelActionNotice, modelDeleteNotice, modelDeleteWarning, modelRecordBackHref, modelRecordEditHref, modelRecordHref, modelRecordListLabel, modelRecordSections, modelRecordTitle, runModelAction } from '../../../../functions/dashboard-model-record'
12
+ import { deleteModelRecord, fetchModelRecord, fetchModelRelated, modelActionAsks, modelActionIconClass, modelActionNotice, modelDeleteNotice, modelDeleteWarning, modelNameFromSlug, modelRecordBackHref, modelRecordEditHref, modelRecordHref, modelRecordListLabel, modelRecordSections, modelRecordTitle, runModelAction } from '../../../../functions/dashboard-model-record'
13
+ import { dashboardLoaderTimer, dashboardReloadingClass } from '../../../../functions/dashboard-loading'
13
14
  import { pushToast } from '../../../../functions/toasts'
14
15
 
15
16
  const navigation = useNavigation()
16
17
  const record = state<ModelRecord | null>(null)
17
18
  const loading = state(true)
19
+ // Set once a request has taken long enough to say so. The record's page
20
+ // waits quietly before that (see dashboard-loading.ts).
21
+ const slow = state(false)
18
22
  const loadError = state('')
19
23
  const confirmingDelete = state(false)
20
24
  const working = state(false)
@@ -43,7 +47,11 @@ const selfHref = derived(() => modelRecordHref(slug(), recordId()))
43
47
  /** The list in the breadcrumb: "Users" for /data/users, else the model's table. */
44
48
  const listLabel = derived(() => modelRecordListLabel(record(), backHref()))
45
49
 
46
- const modelName = derived(() => record()?.modelName || 'Record')
50
+ // Known from the address before the record comes, so the heading does not change.
51
+ const modelName = derived(() => record()?.modelName || modelNameFromSlug(slug()))
52
+ // The record stays on the page while it is read again (after one of its
53
+ // actions), dimmed, and is swapped when the answer comes.
54
+ const contentClass = derived(() => dashboardReloadingClass(loading(), 'grid gap-6 grid-cols-1 items-start lg:grid-cols-2'))
47
55
  const title = derived(() => record() ? modelRecordTitle(record()!) : '')
48
56
  // Who points at this record: its panels. Also after the record itself.
49
57
  const related = state<ModelRelatedPanel[]>([])
@@ -60,18 +68,20 @@ const actions = derived(() => record()?.actions ?? [])
60
68
  async function loadRecord(): Promise<void> {
61
69
  loading.set(true)
62
70
  loadError.set('')
71
+ const settle = dashboardLoaderTimer(slow)
63
72
  try {
64
73
  const loaded = await fetchModelRecord(slug(), recordId())
65
- related.set([])
66
74
  record.set(loaded)
67
75
  // Not awaited, and a page whose panels cannot be read is still the record's page.
68
76
  void fetchModelRelated(slug(), recordId()).then(panels => related.set(panels)).catch(() => related.set([]))
69
77
  }
70
78
  catch (error) {
71
79
  record.set(null)
80
+ related.set([])
72
81
  loadError.set(error instanceof Error ? error.message : 'This record could not be loaded.')
73
82
  }
74
83
  finally {
84
+ settle()
75
85
  loading.set(false)
76
86
  }
77
87
  }
@@ -190,22 +200,19 @@ onMount(() => {
190
200
  </div>
191
201
  </header>
192
202
 
193
- <div :if="loading()" class="flex items-center justify-center py-20 text-neutral-500 text-sm dark:text-neutral-400">
194
- <span aria-hidden="true" class="mr-2 h-5 w-5 animate-spin i-hugeicons-loading-03"></span>
195
- Loading record
196
- </div>
203
+ <QuietLoader :if="loading() && !record()" :slow="slow()" label="Loading record" />
197
204
 
198
205
  <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">
199
206
  <span>{{ loadError() }}</span>
200
207
  <Button variant="secondary" size="sm" @click="loadRecord">Try again</Button>
201
208
  </div>
202
209
 
203
- <div :if="!loading() && record()?.anonymized" role="note" class="flex gap-3 items-start px-4 py-3 text-neutral-700 text-sm dark:text-neutral-200 bg-neutral-100 dark:bg-white/5 border border-neutral-200 rounded-lg dark:border-neutral-700">
210
+ <div :if="record()?.anonymized" role="note" class="flex gap-3 items-start px-4 py-3 text-neutral-700 text-sm dark:text-neutral-200 bg-neutral-100 dark:bg-white/5 border border-neutral-200 rounded-lg dark:border-neutral-700">
204
211
  <span aria-hidden="true" class="flex-none mt-0.5 h-4 w-4 text-neutral-500 i-hugeicons-user-remove-01"></span>
205
212
  <span>This account was anonymized. Its name and email were removed and it can no longer sign in. Records that refer to it were kept.</span>
206
213
  </div>
207
214
 
208
- <div :if="!loading() && record()" class="grid gap-6 grid-cols-1 items-start lg:grid-cols-2">
215
+ <div :if="record()" :class="contentClass()" :aria-busy="loading() ? 'true' : null" data-record-content>
209
216
  <div :for="section in sections()" class="min-w-0">
210
217
  <Card padding="none">
211
218
  <h2 class="px-6 py-4 font-semibold text-base text-neutral-900 dark:text-white border-b border-neutral-200 dark:border-neutral-700">{{ section.title }}</h2>
@@ -240,7 +247,7 @@ onMount(() => {
240
247
  </div>
241
248
 
242
249
  <ModelRelatedPanels
243
- :if="!loading() && record() && related().length > 0"
250
+ :if="record() && related().length > 0"
244
251
  :panels="related()"
245
252
  :parentId="recordId()"
246
253
  :from="selfHref()"
@@ -6,7 +6,8 @@
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, modelFormPayload, modelFormValues, modelRecordBackHref, modelRecordHref, modelRecordListLabel, modelRecordSections, updateModelRecord } from '../../../../functions/dashboard-model-record'
9
+ import { fetchModelRecord, modelNameFromSlug, modelFormPayload, modelFormValues, modelRecordBackHref, modelRecordHref, modelRecordListLabel, modelRecordSections, updateModelRecord } from '../../../../functions/dashboard-model-record'
10
+ import { dashboardLoaderTimer } from '../../../../functions/dashboard-loading'
10
11
  import { pushToast } from '../../../../functions/toasts'
11
12
 
12
13
  const navigation = useNavigation()
@@ -15,6 +16,8 @@ const values = state<ModelFormValues>({})
15
16
  /** What the form started with, so a save sends only what was changed. */
16
17
  const initial = state<ModelFormValues>({})
17
18
  const loading = state(true)
19
+ // Set once the request has taken long enough to say so (dashboard-loading.ts).
20
+ const slow = state(false)
18
21
  const loadError = state('')
19
22
  const saving = state(false)
20
23
  const saveError = state('')
@@ -36,7 +39,8 @@ const viewHref = derived(() => modelRecordHref(slug(), recordId(), listHref() ==
36
39
  /** After saving or cancelling: the page the visitor came from. */
37
40
  const returnHref = derived(() => cameFromView ? viewHref() : listHref())
38
41
  const listLabel = derived(() => modelRecordListLabel(record(), listHref()))
39
- const modelName = derived(() => record()?.modelName || 'Record')
42
+ // Known from the address before the record comes, so the heading does not change.
43
+ const modelName = derived(() => record()?.modelName || modelNameFromSlug(slug()))
40
44
 
41
45
  const writable = derived(() => record()?.fields ?? [])
42
46
  /** What cannot be changed here, formatted as the record's page shows it. */
@@ -58,6 +62,7 @@ function setValue(change: { name: string, value: string | boolean }): void {
58
62
  async function loadRecord(): Promise<void> {
59
63
  loading.set(true)
60
64
  loadError.set('')
65
+ const settle = dashboardLoaderTimer(slow)
61
66
  try {
62
67
  const loaded = await fetchModelRecord(slug(), recordId())
63
68
  record.set(loaded)
@@ -70,6 +75,7 @@ async function loadRecord(): Promise<void> {
70
75
  loadError.set(error instanceof Error ? error.message : 'This record could not be loaded.')
71
76
  }
72
77
  finally {
78
+ settle()
73
79
  loading.set(false)
74
80
  }
75
81
  }
@@ -121,10 +127,7 @@ onMount(() => {
121
127
  <h1 class="font-bold text-3xl text-neutral-900 tracking-tight truncate dark:text-white">Edit {{ modelName() }}</h1>
122
128
  </header>
123
129
 
124
- <div :if="loading()" class="flex items-center justify-center py-20 text-neutral-500 text-sm dark:text-neutral-400">
125
- <span aria-hidden="true" class="mr-2 h-5 w-5 animate-spin i-hugeicons-loading-03"></span>
126
- Loading record
127
- </div>
130
+ <QuietLoader :if="loading()" :slow="slow()" label="Loading record" />
128
131
 
129
132
  <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">
130
133
  <span>{{ loadError() }}</span>
@@ -18,6 +18,7 @@ import type { ModelBulkResult } from '@stacksjs/defaults/functions/dashboard-mod
18
18
  import { deleteModelRecords, modelBulkActionConfirm, modelBulkActionScope, modelBulkActions, modelBulkDeleteConfirm, modelBulkDeleteTargets, modelBulkNotice, modelBulkTargets, runModelActionOnEach } from '@stacksjs/defaults/functions/dashboard-model-bulk'
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
+ import { dashboardLoaderTimer, dashboardReloadingClass } from '@stacksjs/defaults/functions/dashboard-loading'
21
22
  import { pushToast } from '@stacksjs/defaults/functions/toasts'
22
23
 
23
24
  interface ColumnMeta {
@@ -97,6 +98,13 @@ const error = state<string | null>(null)
97
98
  // catalog after the query failed, so this is never a guess from an error.
98
99
  const migrated = state(true)
99
100
  const loading = state(true)
101
+ // Whether a first answer has come. Until it has, nothing is known about the
102
+ // model: not its columns, not how many rows it has. Nothing is drawn that
103
+ // would say otherwise ("No records", a table of one column).
104
+ const loaded = state(false)
105
+ // Said only once a query has taken long enough to wonder about. A list that
106
+ // answers at once never flashes a loader (`dashboardLoaderTimer`).
107
+ const slow = state(false)
100
108
  // Open when it arrives filtered, so what narrowed the list can be seen and cleared.
101
109
  const showFilters = state(Object.keys(filters()).length > 0)
102
110
 
@@ -162,9 +170,14 @@ const filterLabel = derived(() => {
162
170
  return n === 0 ? 'Filter' : `Filter (${n})`
163
171
  })
164
172
 
165
- const isEmpty = derived(() => !loading() && !error() && migrated() && rows().length === 0)
173
+ // Not hidden while a query is in flight: what is on the page stays until the
174
+ // answer replaces it.
175
+ const isEmpty = derived(() => loaded() && !error() && migrated() && rows().length === 0)
166
176
 
167
177
  const subtitle = derived(() => {
178
+ // A page's own description is known from the start; a count is not.
179
+ if (!loaded())
180
+ return description()
168
181
  if (!migrated())
169
182
  return `The ${tableName()} table has not been created yet`
170
183
  return description() || `${recordLabel()} in the ${tableName()} table`
@@ -177,9 +190,14 @@ const deleteDescription = derived(() => {
177
190
  return modelDeleteWarning(`Row ${row.id}`, writeCapabilities().anonymize)
178
191
  })
179
192
 
180
- // Skeleton rows while a query is in flight. Matching the real row count
181
- // keeps the table from collapsing and jumping back on every keystroke.
182
- const skeletonRows = derived(() => Array.from({ length: Math.min(8, Math.max(3, rows().length || 6)) }, (_, i) => i))
193
+ // While a query is in flight the rows already there stay, dimmed and out of
194
+ // reach, and are swapped when the answer comes. Nothing collapses or jumps on
195
+ // a keystroke, and there is no placeholder to draw.
196
+ const bodyClass = derived(() => dashboardReloadingClass(loading(), 'divide-black/5 divide-y dark:divide-white/8'))
197
+ // A hosting page's heading is known from the first paint, so the box does not
198
+ // change its wording when the answer comes.
199
+ const searchPlaceholder = derived(() => `Search ${(heading() || modelName() || 'records').toLowerCase()}`)
200
+ const loadingLabel = derived(() => `Loading ${(title() || 'records').toLowerCase()}`)
183
201
 
184
202
  function formatDate(value: unknown): string {
185
203
  const date = new Date(value as string | number)
@@ -285,6 +303,7 @@ async function load() {
285
303
  error.set(null)
286
304
  // The rows about to arrive may not be the ones that were ticked.
287
305
  selected.set([])
306
+ const settle = dashboardLoaderTimer(slow)
288
307
  try {
289
308
  const params = new URLSearchParams({
290
309
  page: String(page()),
@@ -330,7 +349,9 @@ async function load() {
330
349
  error.set(e instanceof Error ? e.message : String(e))
331
350
  }
332
351
  finally {
352
+ settle()
333
353
  loading.set(false)
354
+ loaded.set(true)
334
355
  }
335
356
  }
336
357
 
@@ -631,7 +652,7 @@ onMount(() => {
631
652
  type="search"
632
653
  x-model="search"
633
654
  @input="onSearchInput"
634
- :placeholder="'Search ' + (modelName() || 'records')"
655
+ :placeholder="searchPlaceholder()"
635
656
  class="block pl-9 pr-3 py-1.5 w-full 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-lg dark:border-white/15 focus:border-blue-400 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-all"
636
657
  >
637
658
  </div>
@@ -700,7 +721,7 @@ onMount(() => {
700
721
  </div>
701
722
  </div>
702
723
 
703
- <div :if="!loading() && !error() && !migrated()" role="status" class="p-12 text-center bg-white dark:bg-neutral-900 border border-black/8 rounded-xl dark:border-white/10">
724
+ <div :if="loaded() && !loading() && !error() && !migrated()" role="status" class="p-12 text-center bg-white dark:bg-neutral-900 border border-black/8 rounded-xl dark:border-white/10">
704
725
  <span aria-hidden="true" class="mx-auto h-10 w-10 text-neutral-300 dark:text-neutral-600 i-hugeicons-database-sync-01"></span>
705
726
  <h3 class="mt-3 font-medium text-[15px] text-neutral-900 dark:text-white">
706
727
  The <code :text="tableName()"></code> table has not been created yet
@@ -722,7 +743,12 @@ onMount(() => {
722
743
  </p>
723
744
  </div>
724
745
 
725
- <div :if="!error() && migrated() && (rows().length > 0 || loading())" class="overflow-hidden bg-white dark:bg-neutral-900 border border-black/8 rounded-xl dark:border-white/10">
746
+ <!-- Before the first answer: one quiet card where the table will be. No
747
+ column is known yet, so no table is drawn, and it says it is loading
748
+ only if that takes long enough to notice. -->
749
+ <QuietLoader :if="!loaded()" :slow="slow()" :label="loadingLabel()" />
750
+
751
+ <div :if="loaded() && !error() && migrated() && rows().length > 0" class="overflow-hidden bg-white dark:bg-neutral-900 border border-black/8 rounded-xl dark:border-white/10">
726
752
  <div class="overflow-x-auto">
727
753
  <table class="min-w-full">
728
754
  <thead class="bg-neutral-50 dark:bg-white/5">
@@ -762,23 +788,7 @@ onMount(() => {
762
788
  </tr>
763
789
  </thead>
764
790
 
765
- <!-- Loading skeleton, shaped like the real rows so the table does not
766
- collapse and jump back on every keystroke. Two <tbody> elements
767
- rather than one: `:if` and `:for` on the same <template> do not
768
- compose, and a table may legally carry several bodies. -->
769
- <tbody :if="loading()" class="divide-black/5 divide-y dark:divide-white/8">
770
- <tr :for="i in skeletonRows()">
771
- <td :if="selectable()" class="pl-3 pr-1 py-2 w-8"></td>
772
- <td :for="column in columnMeta()" class="px-3 py-2">
773
- <div class="h-3 bg-neutral-200 dark:bg-white/10 rounded animate-pulse"></div>
774
- </td>
775
- <td class="right-0 sticky z-10 px-3 py-2 bg-white dark:bg-neutral-900 border-black/5 border-l dark:border-white/10">
776
- <div class="ml-auto h-3 w-16 bg-neutral-200 dark:bg-white/10 rounded animate-pulse"></div>
777
- </td>
778
- </tr>
779
- </tbody>
780
-
781
- <tbody :if="!loading()" class="divide-black/5 divide-y dark:divide-white/8">
791
+ <tbody :class="bodyClass()" :aria-busy="loading() ? 'true' : null">
782
792
  <tr :for="row in rows()" class="hover:bg-neutral-50 dark:hover:bg-white/5 transition-colors group">
783
793
  <td :if="selectable()" class="pl-3 pr-1 py-2 w-8">
784
794
  <input
@@ -819,7 +829,10 @@ onMount(() => {
819
829
  </div>
820
830
 
821
831
  <div class="flex flex-wrap gap-3 items-center justify-between px-3 py-2 bg-neutral-50 dark:bg-white/5 border-black/5 border-t dark:border-white/10">
822
- <p class="text-[12px] text-neutral-500 dark:text-neutral-400" :text="rangeLabel()"></p>
832
+ <p class="flex gap-2 items-center text-[12px] text-neutral-500 dark:text-neutral-400">
833
+ <span :text="rangeLabel()"></span>
834
+ <span :if="slow()" role="status" aria-label="Loading" class="h-3.5 w-3.5 animate-spin i-hugeicons-loading-03"></span>
835
+ </p>
823
836
  <div class="flex gap-1 items-center">
824
837
  <Button variant="secondary" size="xs" :disabled="page() === 1" @click="goToPage(1)">First</Button>
825
838
  <Button variant="secondary" size="xs" :disabled="page() === 1" @click="goToPage(page() - 1)">Previous</Button>