@stacksjs/defaults 0.75.569 → 0.75.572

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/ai/skills/stacks-actions/SKILL.md +1 -1
  2. package/ai/skills/stacks-cms/SKILL.md +1 -1
  3. package/ai/skills/stacks-dashboard/SKILL.md +283 -12
  4. package/ai/skills/stacks-database/SKILL.md +50 -0
  5. package/ai/skills/stacks-http/SKILL.md +33 -2
  6. package/ai/skills/stacks-native/CATALOG.md +8 -8
  7. package/ai/skills/stacks-orm/SKILL.md +20 -10
  8. package/ai/skills/stacks-query-builder/SKILL.md +7 -0
  9. package/app/Actions/Dashboard/Commerce/commerce-sql.ts +1 -1
  10. package/app/Actions/Dashboard/Content/CommentUpdateAction.ts +1 -1
  11. package/app/Actions/Dashboard/Content/PostStoreAction.ts +1 -1
  12. package/app/Actions/Dashboard/Content/PostUpdateAction.ts +1 -1
  13. package/app/Actions/Dashboard/Content/comment-list.ts +2 -2
  14. package/app/Actions/Dashboard/Content/page-list.ts +2 -2
  15. package/app/Actions/Dashboard/Content/post-list.ts +2 -2
  16. package/app/Actions/Dashboard/Infrastructure/InsightsAction.ts +24 -19
  17. package/app/Actions/Dashboard/Infrastructure/log-provider.ts +4 -4
  18. package/app/Actions/Dashboard/Jobs/job-list.ts +1 -1
  19. package/app/Actions/Dashboard/Kanban/BoardShowAction.ts +2 -2
  20. package/app/Actions/Dashboard/Kanban/CardShowAction.ts +3 -3
  21. package/app/Actions/Dashboard/Kanban/card-attachments.ts +1 -1
  22. package/app/Actions/Dashboard/Marketing/marketing-list-records.test.ts +2 -2
  23. package/app/Actions/Dashboard/Marketing/marketing-list-records.ts +4 -4
  24. package/app/Actions/Dashboard/Models/ModelShowAction.ts +42 -43
  25. package/app/Actions/Dashboard/Models/ModelUpdateAction.ts +17 -3
  26. package/app/Actions/Dashboard/Models/model-filters.ts +429 -0
  27. package/app/Actions/Dashboard/Models/model-switches.ts +159 -0
  28. package/app/Actions/Dashboard/Models/model-write.ts +6 -0
  29. package/app/Actions/Dashboard/Notifications/NotificationDeliveryOverviewAction.ts +1 -1
  30. package/app/Actions/Dashboard/Queries/query-list.ts +1 -1
  31. package/app/Actions/Dashboard/Queue/queue-stats.ts +2 -2
  32. package/app/Actions/Dashboard/named-search.ts +1 -1
  33. package/app/Models/Comment.ts +3 -3
  34. package/app/Models/Content/Post.ts +3 -3
  35. package/app/Models/EmailList.ts +8 -6
  36. package/app/Models/Subscriber.ts +2 -0
  37. package/app/Models/Team.ts +2 -0
  38. package/app/Models/User.ts +3 -0
  39. package/functions/dashboard-model-filters.ts +219 -0
  40. package/functions/dashboard-model-record.ts +42 -8
  41. package/ide/vscode/package.json +1 -1
  42. package/package.json +3 -3
  43. package/resources/components/Dashboard/Commerce/CommerceCategoryDialog.stx +3 -1
  44. package/resources/components/Dashboard/Commerce/CommerceCouponDialog.stx +3 -1
  45. package/resources/components/Dashboard/Commerce/CommerceGiftCardDialog.stx +9 -3
  46. package/resources/components/Dashboard/Commerce/CommerceManufacturerDialog.stx +3 -4
  47. package/resources/components/Dashboard/Commerce/CommerceProductDialog.stx +3 -1
  48. package/resources/components/Dashboard/Commerce/CommerceReviewEditDialog.stx +6 -8
  49. package/resources/components/Dashboard/Commerce/CommerceTaxDialog.stx +6 -14
  50. package/resources/components/Dashboard/Commerce/CommerceUnitDialog.stx +3 -7
  51. package/resources/components/Dashboard/Commerce/Delivery/DigitalDeliveryDialog.stx +6 -2
  52. package/resources/components/Dashboard/Content/BlogPostEditorDialog.stx +2 -8
  53. package/resources/components/Dashboard/Content/PageEditorDialog.stx +3 -7
  54. package/resources/components/Dashboard/Content/PostEditorDialog.stx +3 -4
  55. package/resources/components/Dashboard/Data/DataModelRecords.stx +12 -75
  56. package/resources/components/Dashboard/Data/DataStatCards.stx +110 -0
  57. package/resources/components/Dashboard/Email/InboxSettingsDashboard.stx +20 -36
  58. package/resources/components/Dashboard/Marketing/MarketingListDialog.stx +7 -14
  59. package/resources/components/Dashboard/Marketing/MarketingListsDashboard.stx +3 -2
  60. package/resources/components/Dashboard/Models/ModelFieldInputs.stx +10 -13
  61. package/resources/components/Dashboard/Models/ModelFilterPanel.stx +166 -0
  62. package/resources/components/Dashboard/Models/ModelRecordDetail.stx +18 -0
  63. package/resources/components/Dashboard/Models/ModelRecordEdit.stx +3 -2
  64. package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +96 -29
  65. package/resources/components/Dashboard/Models/ModelRegion.stx +25 -0
  66. package/resources/components/Dashboard/Models/ModelRegionFor.stx +31 -0
  67. package/resources/components/Dashboard/Operations/RecoveryDestinationDialog.stx +2 -2
  68. package/resources/components/Dashboard/Operations/RecoveryPolicyDialog.stx +3 -1
  69. package/resources/components/Dashboard/Operations/RecoveryRestoreDialog.stx +3 -1
  70. package/resources/components/Dashboard/Settings/AppearanceSettingsDashboard.stx +11 -14
  71. package/resources/components/Dashboard/Settings/SettingsDashboard.stx +6 -9
  72. package/resources/components/Dashboard/UI/Toggle.stx +16 -12
  73. package/resources/functions/dashboard/regions.ts +113 -0
  74. package/resources/functions/dashboard/sidebar.ts +2 -0
  75. package/views/dashboard/composables/useModelList.ts +52 -0
  76. package/views/dashboard/composables/useModelRecord.ts +46 -0
  77. package/views/dashboard/stores/model-page.ts +105 -0
@@ -69,13 +69,9 @@ function submit(): void {
69
69
  <option value="contact">Contact</option>
70
70
  </select>
71
71
  </label>
72
- <label class="flex gap-3 items-start p-3 bg-gray-50 dark:bg-neutral-900/50 border border-gray-200 rounded-lg dark:border-neutral-700">
73
- <input x-model="published" name="published" type="checkbox" class="mt-0.5 h-4 w-4 rounded" />
74
- <span>
75
- <span class="block font-medium text-gray-700 text-sm dark:text-neutral-200">Published</span>
76
- <span class="block mt-1 text-gray-500 text-xs dark:text-neutral-400">Published pages receive a timestamp. Clearing this returns the page to draft.</span>
77
- </span>
78
- </label>
72
+ <div class="p-3 bg-gray-50 dark:bg-neutral-900/50 border border-gray-200 rounded-lg dark:border-neutral-700">
73
+ <Toggle v-model:checked="published" name="published" label="Published" description="Published pages receive a timestamp. Clearing this returns the page to draft." labelPosition="left" />
74
+ </div>
79
75
  </form>
80
76
 
81
77
  <div :if="error()" role="alert" class="mt-4 p-3 text-red-700 text-sm dark:text-red-300 bg-red-50 dark:bg-red-950/30 border border-red-200 rounded-lg dark:border-red-900">
@@ -137,10 +137,9 @@ function submit(): void {
137
137
  <option :for="author in authors()" :value="author.id">{{ author.name }} ({{ author.email }})</option>
138
138
  </select>
139
139
  </label>
140
- <label class="flex gap-3 items-center self-end px-3 py-2 min-h-10 bg-gray-50 dark:bg-neutral-900/60 border border-gray-200 rounded-md dark:border-neutral-700">
141
- <input x-model="featured" name="featured" type="checkbox" class="h-4 w-4 text-blue-600 border-gray-300 rounded" />
142
- <span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Featured post</span>
143
- </label>
140
+ <div class="self-end px-3 py-2 min-h-10 bg-gray-50 dark:bg-neutral-900/60 border border-gray-200 rounded-md dark:border-neutral-700">
141
+ <Toggle v-model:checked="featured" name="featured" label="Featured post" labelPosition="left" />
142
+ </div>
144
143
  </div>
145
144
  <label>
146
145
  <span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Poster URL</span>
@@ -1,54 +1,24 @@
1
1
  <script client>
2
2
  // The Users, Teams and Subscribers pages. Each is the model's own list, the
3
- // one every model has, hosted under the page's name with its row of stats
4
- // above it. Nothing about the rows is this page's: paging, search, columns,
5
- // actions and selection are the list's, so they are built once.
3
+ // one every model has, hosted under the page's name. Nothing about the rows
4
+ // is this page's: paging, search, columns, actions and selection are the
5
+ // list's, so they are built once.
6
6
  //
7
- // What is the page's own: what it is called, what it is for, and the numbers
8
- // at the top, which are read again whenever the list changes a record.
9
- //
10
- // Every name here that the summary below uses is the page's alone
11
- // (`recordsPage`, `pageStats`). What goes in the list's slot is read against
12
- // the list's own names first, and a `page` here was read as the list's page
13
- // number: the first card said "Total undefined".
14
- import type { DataStats } from '../../../../functions/data'
15
- import { fetchDashboardStats } from '../../../../functions/data'
16
-
7
+ // What is the page's own: what it is called and what it is for. The row of
8
+ // numbers above the list is the model's, placed there by the model
9
+ // (`dashboard.regions.listTop`, `Data/DataStatCards.stx`), so it is on the
10
+ // model's list wherever that list is shown.
17
11
  type RecordsPage = 'users' | 'teams' | 'subscribers'
18
12
 
19
13
  const pageMode = useReactiveProp<RecordsPage>('mode', 'users')
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)
23
14
 
24
- const PAGES: Record<RecordsPage, { model: string, title: string, description: string, icon: string, cards: 3 | 4 }> = {
25
- users: { model: 'user', title: 'Users', description: 'Review registered application users.', icon: 'i-hugeicons-user-group', cards: 3 },
26
- teams: { model: 'team', title: 'Teams', description: 'Review collaborative teams and membership totals.', icon: 'i-hugeicons-user-multiple-02', cards: 4 },
27
- subscribers: { model: 'subscriber', title: 'Subscribers', description: 'Review subscription status and acquisition sources.', icon: 'i-hugeicons-mail-account-01', cards: 4 },
15
+ const PAGES: Record<RecordsPage, { model: string, title: string, description: string }> = {
16
+ users: { model: 'user', title: 'Users', description: 'Review registered application users.' },
17
+ teams: { model: 'team', title: 'Teams', description: 'Review collaborative teams and membership totals.' },
18
+ subscribers: { model: 'subscriber', title: 'Subscribers', description: 'Review subscription status and acquisition sources.' },
28
19
  }
29
20
 
30
21
  const recordsPage = derived(() => PAGES[pageMode()] ?? PAGES.users)
31
- /** Each page's stats fill their row: three cards in a four-column grid left a hole. */
32
- const pageStatsGrid = derived(() => recordsPage().cards === 3 ? 'grid-cols-1 sm:grid-cols-3' : 'grid-cols-2 lg:grid-cols-4')
33
-
34
- function pageStat(key: string): string {
35
- const numbers = pageStats()
36
- return numbers ? Number(numbers[key] || 0).toLocaleString() : '-'
37
- }
38
-
39
- async function loadPageStats(): Promise<void> {
40
- try {
41
- pageStats.set(await fetchDashboardStats(pageMode()))
42
- }
43
- catch {
44
- // The list below says what is wrong when the model cannot be read; the
45
- // numbers stay as they were.
46
- }
47
- }
48
-
49
- onMount(() => {
50
- void loadPageStats()
51
- })
52
22
  </script>
53
23
 
54
24
  <ModelRecordsDashboard
@@ -56,37 +26,4 @@ onMount(() => {
56
26
  :heading="recordsPage().title"
57
27
  :description="recordsPage().description"
58
28
  :home="'/data/' + pageMode()"
59
- @changed="loadPageStats"
60
- >
61
- <template #summary>
62
- <div class="grid gap-4" :class="pageStatsGrid()" data-page-stats>
63
- <StatsCard :title="'Total ' + recordsPage().title" :icon="recordsPage().icon" iconBg="primary">
64
- <template #value>{{ pageStat('total') }}</template>
65
- </StatsCard>
66
- <StatsCard :if="pageMode() === 'users'" title="New This Week" icon="i-hugeicons-user-add-01" iconBg="success">
67
- <template #value>{{ pageStat('newThisWeek') }}</template>
68
- </StatsCard>
69
- <StatsCard :if="pageMode() === 'users'" title="Email Verified" icon="i-hugeicons-mail-validation-01" iconBg="info">
70
- <template #value>{{ pageStat('verified') }}</template>
71
- </StatsCard>
72
- <StatsCard :if="pageMode() === 'teams'" title="Active Teams" icon="i-hugeicons-checkmark-circle-02" iconBg="success">
73
- <template #value>{{ pageStat('active') }}</template>
74
- </StatsCard>
75
- <StatsCard :if="pageMode() === 'teams'" title="Members" icon="i-hugeicons-user-multiple" iconBg="info">
76
- <template #value>{{ pageStat('members') }}</template>
77
- </StatsCard>
78
- <StatsCard :if="pageMode() === 'teams'" title="New This Month" icon="i-hugeicons-calendar-add-01" iconBg="warning">
79
- <template #value>{{ pageStat('newThisMonth') }}</template>
80
- </StatsCard>
81
- <StatsCard :if="pageMode() === 'subscribers'" title="Subscribed" icon="i-hugeicons-mail-open-01" iconBg="success">
82
- <template #value>{{ pageStat('subscribed') }}</template>
83
- </StatsCard>
84
- <StatsCard :if="pageMode() === 'subscribers'" title="Unsubscribed" icon="i-hugeicons-mail-remove-01" iconBg="warning">
85
- <template #value>{{ pageStat('unsubscribed') }}</template>
86
- </StatsCard>
87
- <StatsCard :if="pageMode() === 'subscribers'" title="New This Month" icon="i-hugeicons-calendar-add-01" iconBg="info">
88
- <template #value>{{ pageStat('newThisMonth') }}</template>
89
- </StatsCard>
90
- </div>
91
- </template>
92
- </ModelRecordsDashboard>
29
+ />
@@ -0,0 +1,110 @@
1
+ <script client>
2
+ // The row of numbers above the Users, Teams and Subscribers lists.
3
+ //
4
+ // Each of those models places this on its own list
5
+ // (`dashboard.regions.listTop`), which is how a model puts anything of its
6
+ // own on a page the dashboard draws. So the numbers are on `/data/users` and
7
+ // on `/models/user` alike: they belong to the model, not to one of its pages.
8
+ //
9
+ // It is handed the model and nothing else. The numbers are its own to ask
10
+ // for, and it asks again when the list says a record was changed.
11
+ import type { DataMode, DataStats } from '../../../../functions/data'
12
+ import { useModelList } from '@stacksjs/defaults/views/dashboard/composables/useModelList'
13
+ import { fetchDashboardStats } from '../../../../functions/data'
14
+
15
+ interface StatCard {
16
+ /** The number's name in the stats the model's endpoint answers. */
17
+ key: string
18
+ title: string
19
+ icon: string
20
+ tone: 'primary' | 'success' | 'info' | 'warning'
21
+ }
22
+
23
+ const STAT_CARDS: Record<string, { mode: DataMode, cards: StatCard[] }> = {
24
+ user: {
25
+ mode: 'users',
26
+ cards: [
27
+ { key: 'total', title: 'Total Users', icon: 'i-hugeicons-user-group', tone: 'primary' },
28
+ { key: 'newThisWeek', title: 'New This Week', icon: 'i-hugeicons-user-add-01', tone: 'success' },
29
+ { key: 'verified', title: 'Email Verified', icon: 'i-hugeicons-mail-validation-01', tone: 'info' },
30
+ ],
31
+ },
32
+ team: {
33
+ mode: 'teams',
34
+ cards: [
35
+ { key: 'total', title: 'Total Teams', icon: 'i-hugeicons-user-multiple-02', tone: 'primary' },
36
+ { key: 'active', title: 'Active Teams', icon: 'i-hugeicons-checkmark-circle-02', tone: 'success' },
37
+ { key: 'members', title: 'Members', icon: 'i-hugeicons-user-multiple', tone: 'info' },
38
+ { key: 'newThisMonth', title: 'New This Month', icon: 'i-hugeicons-calendar-add-01', tone: 'warning' },
39
+ ],
40
+ },
41
+ subscriber: {
42
+ mode: 'subscribers',
43
+ cards: [
44
+ { key: 'total', title: 'Total Subscribers', icon: 'i-hugeicons-mail-account-01', tone: 'primary' },
45
+ { key: 'subscribed', title: 'Subscribed', icon: 'i-hugeicons-mail-open-01', tone: 'success' },
46
+ { key: 'unsubscribed', title: 'Unsubscribed', icon: 'i-hugeicons-mail-remove-01', tone: 'warning' },
47
+ { key: 'newThisMonth', title: 'New This Month', icon: 'i-hugeicons-calendar-add-01', tone: 'info' },
48
+ ],
49
+ },
50
+ }
51
+
52
+ const statModel = useReactiveProp('model', '')
53
+ // Null until the numbers have come. A card says nothing until then: a 0 is a
54
+ // count, and "no users" is not what is known while the page is still asking.
55
+ const statNumbers = state<DataStats | null>(null)
56
+ const statCards = derived(() => STAT_CARDS[statModel()]?.cards ?? [])
57
+ /** Each model's cards fill their row: three in a four-column grid left a hole. */
58
+ const statGrid = derived(() => statCards().length === 3 ? 'grid-cols-1 sm:grid-cols-3' : 'grid-cols-2 lg:grid-cols-4')
59
+ const { changes } = useModelList()
60
+ // Stops watching the list. Set while this is on the page, and only then.
61
+ let stopWatchingList: (() => void) | null = null
62
+
63
+ function statValue(key: string): string {
64
+ const numbers = statNumbers()
65
+ return numbers ? Number(numbers[key] || 0).toLocaleString() : '-'
66
+ }
67
+
68
+ async function loadStatNumbers(): Promise<void> {
69
+ const shown = STAT_CARDS[statModel()]
70
+ if (!shown)
71
+ return
72
+ try {
73
+ statNumbers.set(await fetchDashboardStats(shown.mode))
74
+ }
75
+ catch {
76
+ // The list below says what is wrong when the model cannot be read; the
77
+ // numbers stay as they were.
78
+ }
79
+ }
80
+
81
+ // Everything this does starts here and stops in onDestroy. A model's
82
+ // component is drawn on every page that has its place, and its script runs
83
+ // there whether or not it is put on the page: an `effect` at the top of the
84
+ // script would ask for users' numbers every time a team was deleted, and
85
+ // would never be stopped (stacksjs/stx#2189). The model is also a prop, which
86
+ // is not bound sooner.
87
+ onMount(() => {
88
+ void loadStatNumbers()
89
+ // What the list had changed before now is already in the numbers just asked for.
90
+ let seen = changes()
91
+ stopWatchingList = effect(() => {
92
+ const count = changes()
93
+ if (count === seen)
94
+ return
95
+ seen = count
96
+ void loadStatNumbers()
97
+ })
98
+ })
99
+
100
+ onDestroy(() => {
101
+ stopWatchingList?.()
102
+ stopWatchingList = null
103
+ })
104
+ </script>
105
+
106
+ <div :if="statCards().length > 0" class="grid gap-4" :class="statGrid()" data-page-stats>
107
+ <div :for="card in statCards()" class="contents">
108
+ <StatsCard :title="card.title" :value="statValue(card.key)" :icon="card.icon" :iconBg="card.tone" />
109
+ </div>
110
+ </div>
@@ -80,14 +80,12 @@
80
80
  </select>
81
81
  </div>
82
82
 
83
- <div class="flex items-center">
84
- <input id="sendAndArchive" type="checkbox" x-model="sendAndArchive" class="h-4 w-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500" />
85
- <label for="sendAndArchive" class="block ml-2 text-gray-700 text-sm dark:text-neutral-300">Show "Send & Archive" button in reply</label>
83
+ <div>
84
+ <Toggle id="sendAndArchive" v-model:checked="sendAndArchive" :label="sendAndArchiveLabel" labelPosition="left" />
86
85
  </div>
87
86
 
88
- <div class="flex items-center">
89
- <input id="desktopNotifications" type="checkbox" x-model="desktopNotifications" class="h-4 w-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500" />
90
- <label for="desktopNotifications" class="block ml-2 text-gray-700 text-sm dark:text-neutral-300">Enable desktop notifications</label>
87
+ <div>
88
+ <Toggle id="desktopNotifications" v-model:checked="desktopNotifications" label="Enable desktop notifications" labelPosition="left" />
91
89
  </div>
92
90
  </div>
93
91
  </div>
@@ -164,21 +162,13 @@
164
162
  <p class="mt-1 text-gray-500 text-sm dark:text-neutral-400">Choose how new mailbox activity is announced on this device.</p>
165
163
 
166
164
  <div class="mt-5 space-y-4">
167
- <label class="flex items-start">
168
- <input id="desktopNotificationsDelivery" type="checkbox" x-model="desktopNotifications" class="mt-0.5 h-4 w-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500" />
169
- <span class="ml-3">
170
- <span class="block font-medium text-gray-700 text-sm dark:text-neutral-200">Desktop notifications</span>
171
- <span class="block text-gray-500 text-xs dark:text-neutral-400">Show a system notification when new mail arrives.</span>
172
- </span>
173
- </label>
174
-
175
- <label class="flex items-start">
176
- <input id="notificationPreview" type="checkbox" x-model="notificationPreview" class="mt-0.5 h-4 w-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500" />
177
- <span class="ml-3">
178
- <span class="block font-medium text-gray-700 text-sm dark:text-neutral-200">Message previews</span>
179
- <span class="block text-gray-500 text-xs dark:text-neutral-400">Include sender and subject in notifications.</span>
180
- </span>
181
- </label>
165
+ <div>
166
+ <Toggle id="desktopNotificationsDelivery" v-model:checked="desktopNotifications" label="Desktop notifications" description="Show a system notification when new mail arrives." labelPosition="left" />
167
+ </div>
168
+
169
+ <div>
170
+ <Toggle id="notificationPreview" v-model:checked="notificationPreview" label="Message previews" description="Include sender and subject in notifications." labelPosition="left" />
171
+ </div>
182
172
 
183
173
  <div>
184
174
  <label for="notificationSound" class="block font-medium text-gray-700 text-sm dark:text-neutral-300">Notification sound</label>
@@ -228,21 +218,13 @@
228
218
  <p class="mt-1 text-gray-500 text-sm dark:text-neutral-400">Remote content stays blocked by default to reduce tracking and untrusted requests.</p>
229
219
 
230
220
  <div class="mt-5 space-y-4">
231
- <label class="flex items-start">
232
- <input id="loadRemoteImages" type="checkbox" x-model="loadRemoteImages" class="mt-0.5 h-4 w-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500" />
233
- <span class="ml-3">
234
- <span class="block font-medium text-gray-700 text-sm dark:text-neutral-200">Load remote images</span>
235
- <span class="block text-gray-500 text-xs dark:text-neutral-400">Allow message images hosted outside your application.</span>
236
- </span>
237
- </label>
238
-
239
- <label class="flex items-start">
240
- <input id="showExternalContent" type="checkbox" x-model="showExternalContent" class="mt-0.5 h-4 w-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500" />
241
- <span class="ml-3">
242
- <span class="block font-medium text-gray-700 text-sm dark:text-neutral-200">Show external content</span>
243
- <span class="block text-gray-500 text-xs dark:text-neutral-400">Permit embedded content from message authors.</span>
244
- </span>
245
- </label>
221
+ <div>
222
+ <Toggle id="loadRemoteImages" v-model:checked="loadRemoteImages" label="Load remote images" description="Allow message images hosted outside your application." labelPosition="left" />
223
+ </div>
224
+
225
+ <div>
226
+ <Toggle id="showExternalContent" v-model:checked="showExternalContent" label="Show external content" description="Permit embedded content from message authors." labelPosition="left" />
227
+ </div>
246
228
  </div>
247
229
  </div>
248
230
  </div>
@@ -309,6 +291,8 @@ const isLoading = state(true)
309
291
  const displayDensity = state<DisplayDensity>('default')
310
292
  const defaultReplyBehavior = state<ReplyBehavior>('replyAll')
311
293
  const sendAndArchive = state(true)
294
+ // Said here because it has quotation marks of its own, which an attribute cannot hold.
295
+ const sendAndArchiveLabel = 'Show "Send & Archive" button in reply'
312
296
  const autoAdvance = state<AutoAdvance>('newer')
313
297
  const desktopNotifications = state(true)
314
298
  const notificationSound = state<NotificationSound>('default')
@@ -101,20 +101,13 @@ function submit(): void {
101
101
  </select>
102
102
  </label>
103
103
  <div class="grid gap-3 sm:grid-cols-2">
104
- <label class="flex gap-3 items-start p-3 border border-gray-200 rounded-lg dark:border-neutral-700">
105
- <input x-model="isPublic" type="checkbox" class="mt-0.5 h-4 w-4 text-blue-600 border-gray-300 rounded" />
106
- <span>
107
- <span class="block font-medium text-gray-700 text-sm dark:text-neutral-200">Public signup</span>
108
- <span class="block mt-0.5 text-gray-500 text-xs dark:text-neutral-400">Allow signup forms to target this list.</span>
109
- </span>
110
- </label>
111
- <label class="flex gap-3 items-start p-3 border border-gray-200 rounded-lg dark:border-neutral-700">
112
- <input x-model="doubleOptIn" type="checkbox" class="mt-0.5 h-4 w-4 text-blue-600 border-gray-300 rounded" />
113
- <span>
114
- <span class="block font-medium text-gray-700 text-sm dark:text-neutral-200">Double opt-in</span>
115
- <span class="block mt-0.5 text-gray-500 text-xs dark:text-neutral-400">Require confirmation before activation.</span>
116
- </span>
117
- </label>
104
+ <!-- Yes or no is the shared switch, as in every model form. -->
105
+ <div class="p-3 border border-gray-200 rounded-lg dark:border-neutral-700">
106
+ <Toggle v-model:checked="isPublic" label="Public signup" description="Allow signup forms to target this list." labelPosition="left" />
107
+ </div>
108
+ <div class="p-3 border border-gray-200 rounded-lg dark:border-neutral-700">
109
+ <Toggle v-model:checked="doubleOptIn" label="Double opt-in" description="Require confirmation before activation." labelPosition="left" />
110
+ </div>
118
111
  </div>
119
112
  </div>
120
113
  </form>
@@ -128,10 +128,11 @@ async function saveList(payload: MarketingListPayload): Promise<void> {
128
128
  editing ? `/api/dashboard/marketing/lists/${current.id}` : '/api/dashboard/marketing/lists',
129
129
  {
130
130
  method: editing ? 'PATCH' : 'POST',
131
+ // Yes or no go as they are: the columns are booleans.
131
132
  body: {
132
133
  ...payload,
133
- isPublic: payload.isPublic ? 1 : 0,
134
- doubleOptIn: payload.doubleOptIn ? 1 : 0,
134
+ isPublic: Boolean(payload.isPublic),
135
+ doubleOptIn: Boolean(payload.doubleOptIn),
135
136
  },
136
137
  },
137
138
  )
@@ -1,6 +1,6 @@
1
1
  <script client>
2
2
  // The inputs of a model's form, one per field, each in the control its kind
3
- // calls for: a select for a choice, a checkbox for yes or no, a date or a
3
+ // calls for: a select for a choice, a switch for yes or no, a date or a
4
4
  // date-and-time picker, a number box, a tall box for prose and for JSON, a
5
5
  // search for another model's record, a file chooser, a Markdown editor, and a
6
6
  // line of text for the rest. Under each, the sentence the model wrote for it,
@@ -58,21 +58,18 @@ function change(field: ModelCreateField, value: string | boolean): void {
58
58
 
59
59
  <div class="flex flex-col gap-5">
60
60
  <div :for="field in fields()" class="contents">
61
- <label :if="field.type === 'boolean'" class="flex gap-3 items-start p-3 border border-neutral-200 rounded-lg dark:border-neutral-700">
62
- <input
61
+ <div :if="field.type === 'boolean'" class="p-3 border border-neutral-200 rounded-lg dark:border-neutral-700">
62
+ <Toggle
63
63
  :name="field.name"
64
- type="checkbox"
65
64
  :checked="values()[field.name] === true"
66
- :disabled="disabled()"
67
- class="mt-0.5 h-4 w-4 text-blue-600 border-neutral-300 rounded"
68
- @change="change(field, $event.target.checked)"
65
+ :label="field.label"
66
+ :description="hint(field)"
67
+ :error="error(field)"
68
+ :disabled="disabled() || field.disabled === true"
69
+ labelPosition="left"
70
+ @update:checked="change(field, $event)"
69
71
  />
70
- <span>
71
- <span class="block font-medium text-neutral-900 text-sm dark:text-white">{{ field.label }}</span>
72
- <span :if="hint(field) && !error(field)" class="block mt-0.5 text-neutral-500 text-xs dark:text-neutral-400">{{ hint(field) }}</span>
73
- <span :if="error(field)" role="alert" class="block mt-0.5 text-red-600 text-xs dark:text-red-400">{{ error(field) }}</span>
74
- </span>
75
- </label>
72
+ </div>
76
73
 
77
74
  <Select
78
75
  :if="field.type === 'enum'"
@@ -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>