@stacksjs/defaults 0.75.571 → 0.75.572
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai/skills/stacks-actions/SKILL.md +1 -1
- package/ai/skills/stacks-cms/SKILL.md +1 -1
- package/ai/skills/stacks-dashboard/SKILL.md +283 -12
- package/ai/skills/stacks-database/SKILL.md +3 -1
- package/ai/skills/stacks-native/CATALOG.md +2 -2
- package/ai/skills/stacks-orm/SKILL.md +5 -1
- package/app/Actions/Dashboard/Content/CommentUpdateAction.ts +1 -1
- package/app/Actions/Dashboard/Content/PostStoreAction.ts +1 -1
- package/app/Actions/Dashboard/Content/PostUpdateAction.ts +1 -1
- package/app/Actions/Dashboard/Marketing/marketing-list-records.test.ts +2 -2
- package/app/Actions/Dashboard/Marketing/marketing-list-records.ts +4 -4
- package/app/Actions/Dashboard/Models/ModelShowAction.ts +42 -43
- package/app/Actions/Dashboard/Models/ModelUpdateAction.ts +17 -3
- package/app/Actions/Dashboard/Models/model-filters.ts +429 -0
- package/app/Actions/Dashboard/Models/model-switches.ts +159 -0
- package/app/Actions/Dashboard/Models/model-write.ts +6 -0
- package/app/Models/Comment.ts +3 -3
- package/app/Models/Content/Post.ts +3 -3
- package/app/Models/EmailList.ts +8 -6
- package/app/Models/Subscriber.ts +2 -0
- package/app/Models/Team.ts +2 -0
- package/app/Models/User.ts +3 -0
- package/functions/dashboard-model-filters.ts +219 -0
- package/functions/dashboard-model-record.ts +42 -8
- package/ide/vscode/package.json +1 -1
- package/package.json +3 -3
- package/resources/components/Dashboard/Commerce/CommerceCategoryDialog.stx +3 -1
- package/resources/components/Dashboard/Commerce/CommerceCouponDialog.stx +3 -1
- package/resources/components/Dashboard/Commerce/CommerceGiftCardDialog.stx +9 -3
- package/resources/components/Dashboard/Commerce/CommerceManufacturerDialog.stx +3 -4
- package/resources/components/Dashboard/Commerce/CommerceProductDialog.stx +3 -1
- package/resources/components/Dashboard/Commerce/CommerceReviewEditDialog.stx +6 -8
- package/resources/components/Dashboard/Commerce/CommerceTaxDialog.stx +6 -14
- package/resources/components/Dashboard/Commerce/CommerceUnitDialog.stx +3 -7
- package/resources/components/Dashboard/Commerce/Delivery/DigitalDeliveryDialog.stx +6 -2
- package/resources/components/Dashboard/Content/BlogPostEditorDialog.stx +2 -8
- package/resources/components/Dashboard/Content/PageEditorDialog.stx +3 -7
- package/resources/components/Dashboard/Content/PostEditorDialog.stx +3 -4
- package/resources/components/Dashboard/Data/DataModelRecords.stx +12 -75
- package/resources/components/Dashboard/Data/DataStatCards.stx +110 -0
- package/resources/components/Dashboard/Email/InboxSettingsDashboard.stx +20 -36
- package/resources/components/Dashboard/Marketing/MarketingListDialog.stx +7 -14
- package/resources/components/Dashboard/Marketing/MarketingListsDashboard.stx +3 -2
- package/resources/components/Dashboard/Models/ModelFieldInputs.stx +10 -13
- package/resources/components/Dashboard/Models/ModelFilterPanel.stx +166 -0
- package/resources/components/Dashboard/Models/ModelRecordDetail.stx +18 -0
- package/resources/components/Dashboard/Models/ModelRecordEdit.stx +3 -2
- package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +96 -29
- package/resources/components/Dashboard/Models/ModelRegion.stx +25 -0
- package/resources/components/Dashboard/Models/ModelRegionFor.stx +31 -0
- package/resources/components/Dashboard/Operations/RecoveryDestinationDialog.stx +2 -2
- package/resources/components/Dashboard/Operations/RecoveryPolicyDialog.stx +3 -1
- package/resources/components/Dashboard/Operations/RecoveryRestoreDialog.stx +3 -1
- package/resources/components/Dashboard/Settings/AppearanceSettingsDashboard.stx +11 -14
- package/resources/components/Dashboard/Settings/SettingsDashboard.stx +6 -9
- package/resources/components/Dashboard/UI/Toggle.stx +16 -12
- package/resources/functions/dashboard/regions.ts +113 -0
- package/resources/functions/dashboard/sidebar.ts +2 -0
- package/views/dashboard/composables/useModelList.ts +52 -0
- package/views/dashboard/composables/useModelRecord.ts +46 -0
- package/views/dashboard/stores/model-page.ts +105 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The yes-or-no facts a trait keeps about a record for itself, offered on the
|
|
3
|
+
* record's edit form as switches (stacksjs/stacks#3298).
|
|
4
|
+
*
|
|
5
|
+
* A model's form asks for the model's own fillable attributes. Whether an
|
|
6
|
+
* account's email is confirmed and whether it signs in with two-factor are
|
|
7
|
+
* not attributes: the `useAuth` trait owns those columns, and changing one
|
|
8
|
+
* is more than writing it. Turning two-factor off removes the secret, the
|
|
9
|
+
* recovery codes and any open challenge. So each switch names the function
|
|
10
|
+
* that changes it, and the form's save calls that function instead of
|
|
11
|
+
* writing the column.
|
|
12
|
+
*
|
|
13
|
+
* Derived from the trait, not declared by the model. Only the model the auth
|
|
14
|
+
* package writes (`User`, on `users`) has any.
|
|
15
|
+
*/
|
|
16
|
+
import type { ModelCreateField } from './model-write'
|
|
17
|
+
import { db } from '@stacksjs/database/runtime'
|
|
18
|
+
import { isAccountModel, modelColumnLabel } from './model-write'
|
|
19
|
+
|
|
20
|
+
export interface ModelSwitch {
|
|
21
|
+
/** The field, as a form names it: `emailVerifiedAt`. */
|
|
22
|
+
name: string
|
|
23
|
+
/** Where its state is read from: `email_verified_at`. Set when not null, not false and not zero. */
|
|
24
|
+
column: string
|
|
25
|
+
/** The sentence under the switch. */
|
|
26
|
+
help: string
|
|
27
|
+
/** The one way it can be turned from here, when it has only one. */
|
|
28
|
+
only?: 'off' | 'on'
|
|
29
|
+
/** The sentence under it while it cannot be turned. */
|
|
30
|
+
lockedHelp?: string
|
|
31
|
+
/** What changes it. Never a bare write of the column. */
|
|
32
|
+
set: (id: number, on: boolean) => Promise<void>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const ACCOUNT_SWITCHES: ModelSwitch[] = [
|
|
36
|
+
{
|
|
37
|
+
name: 'emailVerifiedAt',
|
|
38
|
+
column: 'email_verified_at',
|
|
39
|
+
help: 'On, this address counts as confirmed, as if they had used the emailed link. Off, it does not.',
|
|
40
|
+
async set(id, on) {
|
|
41
|
+
const { setEmailVerified } = await import('@stacksjs/auth')
|
|
42
|
+
await setEmailVerified(id, on)
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'twoFactorEnabled',
|
|
47
|
+
column: 'two_factor_enabled',
|
|
48
|
+
only: 'off',
|
|
49
|
+
help: 'Turn off for someone who lost their device. Their authenticator and recovery codes stop working, and they can set two-factor up again from their own account.',
|
|
50
|
+
lockedHelp: 'Only the account holder can turn this on, by setting up an authenticator from their own account.',
|
|
51
|
+
async set(id) {
|
|
52
|
+
const { disableTwoFactor } = await import('@stacksjs/auth')
|
|
53
|
+
await disableTwoFactor(id)
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
/** The switches a model's edit form has beside its own fields. */
|
|
59
|
+
export function modelSwitches(Model: any): ModelSwitch[] {
|
|
60
|
+
// The auth package writes `users`, as the invitation does, so this is
|
|
61
|
+
// `User` and not every model with `useAuth`.
|
|
62
|
+
return Model?.name === 'User' && isAccountModel(Model) ? ACCOUNT_SWITCHES : []
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Whether a stored value reads as yes: a moment that is set, a true, a one. */
|
|
66
|
+
export function modelSwitchOn(stored: unknown): boolean {
|
|
67
|
+
return !(stored === null || stored === undefined || stored === false || stored === 0 || stored === '' || stored === '0' || stored === 'false')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The switches as fields of the edit form. */
|
|
71
|
+
export function modelSwitchFields(Model: any): ModelCreateField[] {
|
|
72
|
+
return modelSwitches(Model).map(entry => ({
|
|
73
|
+
name: entry.name,
|
|
74
|
+
label: modelColumnLabel(Model, entry.name),
|
|
75
|
+
type: 'boolean' as const,
|
|
76
|
+
required: false,
|
|
77
|
+
defaultValue: false,
|
|
78
|
+
options: [],
|
|
79
|
+
help: entry.help,
|
|
80
|
+
switch: {
|
|
81
|
+
...(entry.only ? { only: entry.only } : {}),
|
|
82
|
+
...(entry.lockedHelp ? { lockedHelp: entry.lockedHelp } : {}),
|
|
83
|
+
},
|
|
84
|
+
}))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The columns the switches read, for the page to know they are asked for and not only shown. */
|
|
88
|
+
export function modelSwitchColumns(Model: any): string[] {
|
|
89
|
+
return modelSwitches(Model).map(entry => entry.column)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface ModelSwitchRequest {
|
|
93
|
+
switch: ModelSwitch
|
|
94
|
+
on: boolean
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** What a save can ask of a switch, however a form or an API caller spells yes and no. */
|
|
98
|
+
function askedState(value: unknown): boolean | null {
|
|
99
|
+
if (value === true || value === 1 || value === '1' || value === 'true' || value === 'on')
|
|
100
|
+
return true
|
|
101
|
+
if (value === false || value === 0 || value === '0' || value === 'false' || value === 'off')
|
|
102
|
+
return false
|
|
103
|
+
return null
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The switches a save names, by field or by column, and what it asks of
|
|
108
|
+
* each. A value that is not a yes or a no is refused and not guessed at: a
|
|
109
|
+
* date sent for `email_verified_at` must not read as "off".
|
|
110
|
+
*/
|
|
111
|
+
export function requestedSwitches(Model: any, body: Record<string, unknown>): { asked: ModelSwitchRequest[], errors: Record<string, string[]> } {
|
|
112
|
+
const asked: ModelSwitchRequest[] = []
|
|
113
|
+
const errors: Record<string, string[]> = {}
|
|
114
|
+
for (const entry of modelSwitches(Model)) {
|
|
115
|
+
const key = [entry.name, entry.column].find(name => Object.prototype.hasOwnProperty.call(body, name))
|
|
116
|
+
if (key === undefined)
|
|
117
|
+
continue
|
|
118
|
+
const on = askedState(body[key])
|
|
119
|
+
if (on === null)
|
|
120
|
+
errors[entry.name] = [`${modelColumnLabel(Model, entry.name)} is on or off.`]
|
|
121
|
+
else
|
|
122
|
+
asked.push({ switch: entry, on })
|
|
123
|
+
}
|
|
124
|
+
return { asked, errors }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Of the switches a save asks for, the ones that would change something and
|
|
129
|
+
* the ones that cannot be turned that way.
|
|
130
|
+
*
|
|
131
|
+
* `stored` is the record's row as the database has it. A switch already
|
|
132
|
+
* where it is asked to be is neither: asking twice is not a mistake.
|
|
133
|
+
*/
|
|
134
|
+
export function planSwitches(Model: any, asked: ModelSwitchRequest[], stored: Record<string, unknown>): { turning: ModelSwitchRequest[], errors: Record<string, string[]> } {
|
|
135
|
+
const turning: ModelSwitchRequest[] = []
|
|
136
|
+
const errors: Record<string, string[]> = {}
|
|
137
|
+
for (const request of asked) {
|
|
138
|
+
if (modelSwitchOn(stored[request.switch.column]) === request.on)
|
|
139
|
+
continue
|
|
140
|
+
if (request.switch.only && (request.switch.only === 'on') !== request.on) {
|
|
141
|
+
errors[request.switch.name] = [request.switch.lockedHelp ?? `${modelColumnLabel(Model, request.switch.name)} cannot be turned ${request.on ? 'on' : 'off'} from here.`]
|
|
142
|
+
continue
|
|
143
|
+
}
|
|
144
|
+
turning.push(request)
|
|
145
|
+
}
|
|
146
|
+
return { turning, errors }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** What the switches of one record are stored as. Read from the table: the columns are not the model's own. */
|
|
150
|
+
export async function storedSwitches(Model: any, id: number): Promise<Record<string, unknown>> {
|
|
151
|
+
const columns = modelSwitchColumns(Model)
|
|
152
|
+
if (columns.length === 0)
|
|
153
|
+
return {}
|
|
154
|
+
const row = await db.selectFrom(String(Model.table) as never)
|
|
155
|
+
.select(columns as never)
|
|
156
|
+
.where(String(Model.primaryKey || 'id') as never, '=', id as never)
|
|
157
|
+
.executeTakeFirst()
|
|
158
|
+
return (row ?? {}) as Record<string, unknown>
|
|
159
|
+
}
|
|
@@ -99,6 +99,12 @@ export interface ModelCreateField {
|
|
|
99
99
|
help?: string
|
|
100
100
|
/** For an `upload`: the kinds of file that may be chosen. */
|
|
101
101
|
accept?: string
|
|
102
|
+
/**
|
|
103
|
+
* A yes or no a trait keeps for itself, changed by a function of its own
|
|
104
|
+
* and not by writing its column (`./model-switches`): the one way it can
|
|
105
|
+
* be turned, when it has only one, and what is said while it cannot be.
|
|
106
|
+
*/
|
|
107
|
+
switch?: { only?: 'off' | 'on', lockedHelp?: string }
|
|
102
108
|
}
|
|
103
109
|
|
|
104
110
|
export interface PreparedModelFields {
|
package/app/Models/Comment.ts
CHANGED
|
@@ -104,11 +104,11 @@ export default defineModel({
|
|
|
104
104
|
isApproved: {
|
|
105
105
|
required: false,
|
|
106
106
|
fillable: true,
|
|
107
|
-
default:
|
|
107
|
+
default: false,
|
|
108
108
|
validation: {
|
|
109
|
-
rule: schema.
|
|
109
|
+
rule: schema.boolean(),
|
|
110
110
|
},
|
|
111
|
-
factory: faker => faker.
|
|
111
|
+
factory: faker => faker.datatype.boolean(),
|
|
112
112
|
},
|
|
113
113
|
},
|
|
114
114
|
|
|
@@ -227,12 +227,12 @@ export default defineModel({
|
|
|
227
227
|
order: 13,
|
|
228
228
|
fillable: true,
|
|
229
229
|
validation: {
|
|
230
|
-
rule: schema.
|
|
230
|
+
rule: schema.boolean(),
|
|
231
231
|
message: {
|
|
232
|
-
|
|
232
|
+
boolean: 'Featured must be yes or no',
|
|
233
233
|
},
|
|
234
234
|
},
|
|
235
|
-
factory: faker => faker.
|
|
235
|
+
factory: faker => faker.datatype.boolean(),
|
|
236
236
|
},
|
|
237
237
|
},
|
|
238
238
|
|
package/app/Models/EmailList.ts
CHANGED
|
@@ -117,24 +117,26 @@ export default defineModel({
|
|
|
117
117
|
factory: faker => faker.helpers.arrayElement(['active', 'active', 'active', 'inactive']),
|
|
118
118
|
},
|
|
119
119
|
|
|
120
|
+
// Yes or no, and declared as one: a switch in a form, `true` or `false`
|
|
121
|
+
// in a query. Declared as a number, the form asked for 0 or 1.
|
|
120
122
|
isPublic: {
|
|
121
123
|
required: false,
|
|
122
124
|
fillable: true,
|
|
123
|
-
default:
|
|
125
|
+
default: true,
|
|
124
126
|
validation: {
|
|
125
|
-
rule: schema.
|
|
127
|
+
rule: schema.boolean(),
|
|
126
128
|
},
|
|
127
|
-
factory: faker => faker.
|
|
129
|
+
factory: faker => faker.datatype.boolean(),
|
|
128
130
|
},
|
|
129
131
|
|
|
130
132
|
doubleOptIn: {
|
|
131
133
|
required: false,
|
|
132
134
|
fillable: true,
|
|
133
|
-
default:
|
|
135
|
+
default: true,
|
|
134
136
|
validation: {
|
|
135
|
-
rule: schema.
|
|
137
|
+
rule: schema.boolean(),
|
|
136
138
|
},
|
|
137
|
-
factory: () =>
|
|
139
|
+
factory: () => true,
|
|
138
140
|
},
|
|
139
141
|
},
|
|
140
142
|
|
package/app/Models/Subscriber.ts
CHANGED
package/app/Models/Team.ts
CHANGED
|
@@ -76,6 +76,8 @@ export default defineModel({
|
|
|
76
76
|
|
|
77
77
|
dashboard: {
|
|
78
78
|
columns: ['name', 'memberCount', 'status', 'createdAt'],
|
|
79
|
+
// The row of numbers above the list: teams, active ones, members.
|
|
80
|
+
regions: { listTop: 'DataStatCards' },
|
|
79
81
|
// A count of members is called what it counts.
|
|
80
82
|
fields: {
|
|
81
83
|
memberCount: { label: 'Members' },
|
package/app/Models/User.ts
CHANGED
|
@@ -165,6 +165,9 @@ export default defineModel({
|
|
|
165
165
|
// The list is for telling accounts apart. The two-factor step, the
|
|
166
166
|
// billing id and the rest are on the account's own page.
|
|
167
167
|
columns: ['name', 'email', 'emailVerifiedAt', 'createdAt'],
|
|
168
|
+
// The row of numbers above the list: how many, how many are new, how
|
|
169
|
+
// many confirmed their email.
|
|
170
|
+
regions: { listTop: 'DataStatCards' },
|
|
168
171
|
// An avatar is a picture, not the address of one.
|
|
169
172
|
fields: {
|
|
170
173
|
// Chosen as a file, and shown as the picture it is.
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A list's filters, on the page: what each one's value looks like, how it is
|
|
3
|
+
* worded, and how the days a person picks become what the server compares.
|
|
4
|
+
*
|
|
5
|
+
* The server says which filters a model's list has and what kind each is
|
|
6
|
+
* (`Models/model-filters.ts`: derived from the model's fields, never
|
|
7
|
+
* declared one by one). Nothing here knows a model; it knows the kinds.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** How a filter is asked for. Matches the server's `ModelFilterKind`. */
|
|
11
|
+
export type ModelListFilterKind = 'choice' | 'boolean' | 'relation' | 'date' | 'datetime' | 'number' | 'text'
|
|
12
|
+
|
|
13
|
+
export interface ModelListFilter {
|
|
14
|
+
/** The column it narrows. */
|
|
15
|
+
name: string
|
|
16
|
+
label: string
|
|
17
|
+
kind: ModelListFilterKind
|
|
18
|
+
options?: Array<{ value: string, label: string }>
|
|
19
|
+
/** The options are what the table holds now, not all the field may ever hold. */
|
|
20
|
+
open?: boolean
|
|
21
|
+
relation?: { slug: string, label: string }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A filter's value. Text is "exactly this"; the rest say how: any of
|
|
26
|
+
* several, between two days, between two numbers.
|
|
27
|
+
*/
|
|
28
|
+
export type ModelListFilterValue = string | { in: string[] } | { from?: string, to?: string } | { min?: number, max?: number }
|
|
29
|
+
|
|
30
|
+
export type ModelListFilterValues = Record<string, ModelListFilterValue>
|
|
31
|
+
|
|
32
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
33
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** One value from an address, or null when it is not a shape a filter has. */
|
|
37
|
+
export function modelFilterValue(value: unknown): ModelListFilterValue | null {
|
|
38
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')
|
|
39
|
+
return String(value) === '' ? null : String(value)
|
|
40
|
+
if (!isRecord(value))
|
|
41
|
+
return null
|
|
42
|
+
const keys = Object.keys(value)
|
|
43
|
+
if (keys.length === 1 && keys[0] === 'in') {
|
|
44
|
+
const list = Array.isArray(value.in) ? value.in.filter(item => typeof item === 'string' || typeof item === 'number').map(String).filter(item => item !== '') : []
|
|
45
|
+
return list.length > 0 ? { in: [...new Set(list)] } : null
|
|
46
|
+
}
|
|
47
|
+
if (keys.length > 0 && keys.every(key => key === 'from' || key === 'to')) {
|
|
48
|
+
const range: { from?: string, to?: string } = {}
|
|
49
|
+
if (typeof value.from === 'string' && value.from !== '')
|
|
50
|
+
range.from = value.from
|
|
51
|
+
if (typeof value.to === 'string' && value.to !== '')
|
|
52
|
+
range.to = value.to
|
|
53
|
+
return range.from !== undefined || range.to !== undefined ? range : null
|
|
54
|
+
}
|
|
55
|
+
if (keys.length > 0 && keys.every(key => key === 'min' || key === 'max')) {
|
|
56
|
+
const range: { min?: number, max?: number } = {}
|
|
57
|
+
for (const edge of ['min', 'max'] as const) {
|
|
58
|
+
const amount = value[edge]
|
|
59
|
+
const number = typeof amount === 'number' ? amount : typeof amount === 'string' && amount.trim() !== '' ? Number(amount) : Number.NaN
|
|
60
|
+
if (Number.isFinite(number))
|
|
61
|
+
range[edge] = number
|
|
62
|
+
}
|
|
63
|
+
return range.min !== undefined || range.max !== undefined ? range : null
|
|
64
|
+
}
|
|
65
|
+
return null
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Whether a filter narrows anything. An empty box, list or range does not. */
|
|
69
|
+
export function modelFilterIsSet(value: ModelListFilterValue | undefined | null): boolean {
|
|
70
|
+
return value !== undefined && value !== null && modelFilterValue(value) !== null
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The filters that narrow something, as the list sends them and its address carries them. */
|
|
74
|
+
export function modelFiltersSet(values: ModelListFilterValues): ModelListFilterValues {
|
|
75
|
+
const out: ModelListFilterValues = {}
|
|
76
|
+
for (const [column, value] of Object.entries(values)) {
|
|
77
|
+
const read = modelFilterValue(value)
|
|
78
|
+
if (read !== null)
|
|
79
|
+
out[column] = read
|
|
80
|
+
}
|
|
81
|
+
return out
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The values a choice filter has picked. */
|
|
85
|
+
export function modelFilterChosen(value: ModelListFilterValue | undefined): string[] {
|
|
86
|
+
if (typeof value === 'string')
|
|
87
|
+
return value === '' ? [] : [value]
|
|
88
|
+
return value && 'in' in value ? value.in : []
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Pick or unpick one option of a choice filter. Unpicking the last one clears the filter. */
|
|
92
|
+
export function modelFilterToggle(value: ModelListFilterValue | undefined, option: string): ModelListFilterValue {
|
|
93
|
+
const chosen = modelFilterChosen(value)
|
|
94
|
+
const next = chosen.includes(option) ? chosen.filter(item => item !== option) : [...chosen, option]
|
|
95
|
+
return next.length === 0 ? '' : { in: next }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function pad(number: number): string {
|
|
99
|
+
return String(number).padStart(2, '0')
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** A date as the day it is where the viewer is: `2026-01-31`. */
|
|
103
|
+
export function modelFilterDay(date: Date): string {
|
|
104
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The start of a day where the viewer is, or null when it is not a day. */
|
|
108
|
+
function startOfDay(day: string): Date | null {
|
|
109
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(day)
|
|
110
|
+
if (!match)
|
|
111
|
+
return null
|
|
112
|
+
const date = new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3]))
|
|
113
|
+
return Number.isNaN(date.getTime()) || modelFilterDay(date) !== day ? null : date
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The value a range of days narrows by.
|
|
118
|
+
*
|
|
119
|
+
* A date column stores days, so the days go as they are, both included. A
|
|
120
|
+
* moment is stored as an instant, and "the 5th" is a different stretch of
|
|
121
|
+
* instants in Manila than in London: the page sends where the viewer's first
|
|
122
|
+
* day starts and where the day after their last one does.
|
|
123
|
+
*/
|
|
124
|
+
export function modelFilterRange(kind: 'date' | 'datetime', from: string, to: string): ModelListFilterValue {
|
|
125
|
+
const first = startOfDay(from)
|
|
126
|
+
const last = startOfDay(to)
|
|
127
|
+
if (!first && !last)
|
|
128
|
+
return ''
|
|
129
|
+
if (kind === 'date')
|
|
130
|
+
return { ...(first ? { from } : {}), ...(last ? { to } : {}) }
|
|
131
|
+
const range: { from?: string, to?: string } = {}
|
|
132
|
+
if (first)
|
|
133
|
+
range.from = first.toISOString()
|
|
134
|
+
if (last)
|
|
135
|
+
range.to = new Date(last.getFullYear(), last.getMonth(), last.getDate() + 1).toISOString()
|
|
136
|
+
return range
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The days a range filter is showing in its two date boxes. */
|
|
140
|
+
export function modelFilterDays(kind: 'date' | 'datetime', value: ModelListFilterValue | undefined): { from: string, to: string } {
|
|
141
|
+
if (!value || typeof value === 'string' || !('from' in value || 'to' in value))
|
|
142
|
+
return { from: '', to: '' }
|
|
143
|
+
const range = value as { from?: string, to?: string }
|
|
144
|
+
if (kind === 'date')
|
|
145
|
+
return { from: range.from ?? '', to: range.to ?? '' }
|
|
146
|
+
const from = range.from ? new Date(range.from) : null
|
|
147
|
+
const to = range.to ? new Date(range.to) : null
|
|
148
|
+
return {
|
|
149
|
+
from: from && !Number.isNaN(from.getTime()) ? modelFilterDay(from) : '',
|
|
150
|
+
// The instant sent is the start of the day after the last one.
|
|
151
|
+
to: to && !Number.isNaN(to.getTime()) ? modelFilterDay(new Date(to.getTime() - 1)) : '',
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** The ranges offered in one press. */
|
|
156
|
+
export const MODEL_FILTER_PRESETS = [
|
|
157
|
+
{ name: 'today', label: 'Today' },
|
|
158
|
+
{ name: 'week', label: 'Last 7 days' },
|
|
159
|
+
{ name: 'month', label: 'This month' },
|
|
160
|
+
] as const
|
|
161
|
+
|
|
162
|
+
export type ModelFilterPreset = typeof MODEL_FILTER_PRESETS[number]['name']
|
|
163
|
+
|
|
164
|
+
/** The first and last day of a preset, as of `now`. */
|
|
165
|
+
export function modelFilterPresetDays(preset: ModelFilterPreset, now: Date = new Date()): { from: string, to: string } {
|
|
166
|
+
const today = modelFilterDay(now)
|
|
167
|
+
if (preset === 'today')
|
|
168
|
+
return { from: today, to: today }
|
|
169
|
+
if (preset === 'week')
|
|
170
|
+
return { from: modelFilterDay(new Date(now.getFullYear(), now.getMonth(), now.getDate() - 6)), to: today }
|
|
171
|
+
return { from: modelFilterDay(new Date(now.getFullYear(), now.getMonth(), 1)), to: today }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** A day as a sentence has it: "Jan 31, 2026". */
|
|
175
|
+
function wordedDay(day: string): string {
|
|
176
|
+
const date = startOfDay(day)
|
|
177
|
+
return date ? date.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' }) : day
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* What an active filter says in its chip: "Active, Pending", "from Jan 1,
|
|
182
|
+
* 2026", "at least 10". `names` words a record a relation filter points at;
|
|
183
|
+
* without one it is named by its id, which is still true.
|
|
184
|
+
*/
|
|
185
|
+
export function modelFilterSummary(filter: ModelListFilter | undefined, value: ModelListFilterValue, names: Record<string, string> = {}): string {
|
|
186
|
+
const worded = (stored: string): string => {
|
|
187
|
+
if (filter?.kind === 'relation')
|
|
188
|
+
return names[stored] ?? `#${stored}`
|
|
189
|
+
if (filter?.kind === 'boolean')
|
|
190
|
+
return ['true', '1', 'yes'].includes(stored.toLowerCase()) ? 'Yes' : 'No'
|
|
191
|
+
return filter?.options?.find(option => option.value === stored)?.label ?? names[stored] ?? stored
|
|
192
|
+
}
|
|
193
|
+
if (typeof value === 'string')
|
|
194
|
+
return worded(value)
|
|
195
|
+
if ('in' in value)
|
|
196
|
+
return value.in.map(worded).join(', ')
|
|
197
|
+
if ('from' in value || 'to' in value) {
|
|
198
|
+
const days = modelFilterDays(filter?.kind === 'date' ? 'date' : 'datetime', value)
|
|
199
|
+
if (days.from && days.to)
|
|
200
|
+
return days.from === days.to ? wordedDay(days.from) : `${wordedDay(days.from)} to ${wordedDay(days.to)}`
|
|
201
|
+
return days.from ? `from ${wordedDay(days.from)}` : `until ${wordedDay(days.to)}`
|
|
202
|
+
}
|
|
203
|
+
const range = value as { min?: number, max?: number }
|
|
204
|
+
if (range.min !== undefined && range.max !== undefined)
|
|
205
|
+
return `${range.min.toLocaleString()} to ${range.max.toLocaleString()}`
|
|
206
|
+
return range.min !== undefined ? `at least ${range.min.toLocaleString()}` : `at most ${(range.max ?? 0).toLocaleString()}`
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** A list's address with what narrows it: `?q=ava&filters={...}`. Nothing else is kept. */
|
|
210
|
+
export function modelListAddress(path: string, search: string, values: ModelListFilterValues): string {
|
|
211
|
+
const params = new URLSearchParams()
|
|
212
|
+
if (search.trim())
|
|
213
|
+
params.set('q', search.trim())
|
|
214
|
+
const set = modelFiltersSet(values)
|
|
215
|
+
if (Object.keys(set).length > 0)
|
|
216
|
+
params.set('filters', JSON.stringify(set))
|
|
217
|
+
const query = params.toString()
|
|
218
|
+
return query ? `${path}?${query}` : path
|
|
219
|
+
}
|
|
@@ -15,6 +15,8 @@ import { DashboardApiError, dashboardApi } from './dashboard-api'
|
|
|
15
15
|
import { parseDashboardDate } from './dashboard-dates'
|
|
16
16
|
import type { ModelFieldDisplay } from './dashboard-model-format'
|
|
17
17
|
import type { ModelBadgeTone } from './dashboard-model-format'
|
|
18
|
+
import type { ModelListFilterValues } from './dashboard-model-filters'
|
|
19
|
+
import { modelFilterValue } from './dashboard-model-filters'
|
|
18
20
|
import { MODEL_BADGE_COLUMNS, modelBadgeTone, modelColumnIsDate, modelFormattedValue } from './dashboard-model-format'
|
|
19
21
|
|
|
20
22
|
export interface ModelWriteCapabilities {
|
|
@@ -136,9 +138,17 @@ export interface ModelCreateField {
|
|
|
136
138
|
help?: string
|
|
137
139
|
/** For an `upload`: the kinds of file that may be chosen, as a file input's `accept` spells them. */
|
|
138
140
|
accept?: string
|
|
141
|
+
/**
|
|
142
|
+
* A yes or no the application keeps for itself (a confirmed email,
|
|
143
|
+
* two-factor), offered as a switch: the one way it can be turned, when it
|
|
144
|
+
* has only one, and what is said under it while it cannot be.
|
|
145
|
+
*/
|
|
146
|
+
switch?: { only?: 'off' | 'on', lockedHelp?: string }
|
|
147
|
+
/** Shown but not to be changed: a switch that cannot be turned from where it is. */
|
|
148
|
+
disabled?: boolean
|
|
139
149
|
}
|
|
140
150
|
|
|
141
|
-
/** What a form holds for each field: a
|
|
151
|
+
/** What a form holds for each field: a switch's state, or an input's text. */
|
|
142
152
|
export type ModelFormValues = Record<string, string | boolean>
|
|
143
153
|
|
|
144
154
|
export interface ModelCreateForm {
|
|
@@ -442,6 +452,9 @@ function localMoment(stored: unknown): string {
|
|
|
442
452
|
* of braces in plain text boxes.
|
|
443
453
|
*/
|
|
444
454
|
export function modelFieldInputValue(field: ModelCreateField, stored: unknown): string | boolean {
|
|
455
|
+
// A switch reads yes from whatever marks it: a moment that is set, a true, a one.
|
|
456
|
+
if (field.switch)
|
|
457
|
+
return !(stored === null || stored === undefined || stored === false || stored === 0 || stored === '' || stored === '0' || stored === 'false')
|
|
445
458
|
if (field.type === 'boolean')
|
|
446
459
|
return stored === true || stored === 1 || stored === '1' || stored === 'true'
|
|
447
460
|
if (stored === null || stored === undefined || stored === '')
|
|
@@ -496,6 +509,21 @@ export function modelFormValues(fields: ModelCreateField[], row?: Record<string,
|
|
|
496
509
|
]))
|
|
497
510
|
}
|
|
498
511
|
|
|
512
|
+
/**
|
|
513
|
+
* The form's fields for a record as it is stored. A switch that can only be
|
|
514
|
+
* turned one way is shown but not offered once it is already there:
|
|
515
|
+
* two-factor can be turned off for someone, never on. It then says why
|
|
516
|
+
* instead of what turning it would do.
|
|
517
|
+
*/
|
|
518
|
+
export function modelFormFieldsFor(fields: ModelCreateField[], stored: ModelFormValues): ModelCreateField[] {
|
|
519
|
+
return fields.map((field) => {
|
|
520
|
+
const only = field.switch?.only
|
|
521
|
+
if (!only || (stored[field.name] === true) === (only === 'off'))
|
|
522
|
+
return field
|
|
523
|
+
return { ...field, disabled: true, ...(field.switch?.lockedHelp ? { help: field.switch.lockedHelp } : {}) }
|
|
524
|
+
})
|
|
525
|
+
}
|
|
526
|
+
|
|
499
527
|
/**
|
|
500
528
|
* What a form sends. Given what it started with, only the fields that were
|
|
501
529
|
* changed: a value the editor merely displayed is never written back.
|
|
@@ -799,7 +827,7 @@ export async function fetchModelOptions(slug: string, search: { q?: string, ids?
|
|
|
799
827
|
* when the model left it out: a list opened from a record's panel arrives
|
|
800
828
|
* narrowed by that record, and what narrowed it has to be in view to clear.
|
|
801
829
|
*/
|
|
802
|
-
export function modelListColumnNames(all: string[], chosen: string[] | undefined, filters: Record<string,
|
|
830
|
+
export function modelListColumnNames(all: string[], chosen: string[] | undefined, filters: Record<string, unknown> = {}): string[] {
|
|
803
831
|
const list = chosen && chosen.length > 0 ? chosen.filter(column => all.includes(column)) : all
|
|
804
832
|
const filtered = Object.entries(filters).filter(([column, value]) => value !== '' && all.includes(column) && !list.includes(column)).map(([column]) => column)
|
|
805
833
|
return [...list, ...filtered]
|
|
@@ -932,19 +960,25 @@ export function modelRelatedCreateHref(panel: ModelRelatedPanel, parentId: strin
|
|
|
932
960
|
}
|
|
933
961
|
|
|
934
962
|
/**
|
|
935
|
-
* The filters a list starts with, from its address: `?filters={"team_id":"3"}
|
|
936
|
-
*
|
|
963
|
+
* The filters a list starts with, from its address: `?filters={"team_id":"3"}`
|
|
964
|
+
* or `{"status":{"in":["active","pending"]}}`. A column or a value that is
|
|
965
|
+
* not a shape a filter has is ignored, never trusted.
|
|
937
966
|
*/
|
|
938
|
-
export function modelListFilters(raw: string | null):
|
|
967
|
+
export function modelListFilters(raw: string | null): ModelListFilterValues {
|
|
939
968
|
if (!raw)
|
|
940
969
|
return {}
|
|
941
970
|
try {
|
|
942
971
|
const parsed = JSON.parse(raw) as unknown
|
|
943
972
|
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
944
973
|
return {}
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
974
|
+
const out: ModelListFilterValues = {}
|
|
975
|
+
for (const [column, value] of Object.entries(parsed as Record<string, unknown>)) {
|
|
976
|
+
// A yes-or-no is not something an address is trusted to carry as true.
|
|
977
|
+
const read = typeof value === 'boolean' ? null : modelFilterValue(value)
|
|
978
|
+
if (/^[a-z_][a-z0-9_]*$/i.test(column) && read !== null)
|
|
979
|
+
out[column] = read
|
|
980
|
+
}
|
|
981
|
+
return out
|
|
948
982
|
}
|
|
949
983
|
catch {
|
|
950
984
|
return {}
|
package/ide/vscode/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"publisher": "Stacks",
|
|
3
3
|
"name": "vscode-stacks",
|
|
4
4
|
"displayName": "Stacks",
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.572",
|
|
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.
|
|
5
|
+
"version": "0.75.572",
|
|
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.
|
|
48
|
+
"@stacksjs/mobile": "0.75.572",
|
|
49
49
|
"@stacksjs/sanitizer": "^0.2.864",
|
|
50
50
|
"@stacksjs/stx": "^0.2.864",
|
|
51
|
-
"@stacksjs/strings": "0.75.
|
|
51
|
+
"@stacksjs/strings": "0.75.572",
|
|
52
52
|
"@xterm/addon-fit": "^0.11.0",
|
|
53
53
|
"@xterm/xterm": "^6.0.0",
|
|
54
54
|
"ts-qr-codes": "^0.1.8"
|
|
@@ -127,7 +127,9 @@ function errorMessages(): string[] {
|
|
|
127
127
|
<label class="block sm:col-span-2"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Image URL</span><input x-model="imageUrl" type="text" placeholder="Optional persisted asset URL" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /><span class="block mt-1 text-gray-500 text-xs dark:text-neutral-500">Use a stored asset URL. File uploads belong to the native storage workflow.</span></label>
|
|
128
128
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Parent category</span><select x-model="parentCategoryId" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"><option value="">Root category</option><option :for="option in parentOptions()" :key="option.id" :value="option.id">{{ option.name }}</option></select></label>
|
|
129
129
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Display order</span><input x-model="displayOrder" type="number" min="0" step="1" required class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /></label>
|
|
130
|
-
<
|
|
130
|
+
<div class="sm:col-span-2 p-3 border border-gray-200 rounded-lg dark:border-neutral-700">
|
|
131
|
+
<Toggle v-model:checked="isActive" label="Active in the storefront" description="Availability is independent from the hierarchy." labelPosition="left" />
|
|
132
|
+
</div>
|
|
131
133
|
</div>
|
|
132
134
|
</form>
|
|
133
135
|
<template #footer>
|
|
@@ -132,7 +132,9 @@ function errorMessages(): string[] {
|
|
|
132
132
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Free product ID</span><input x-model="freeProductId" type="text" placeholder="Optional" class="mt-1 px-3 py-2 w-full font-mono text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /></label>
|
|
133
133
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Start date</span><input x-model="startDate" type="date" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /></label>
|
|
134
134
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">End date</span><input x-model="endDate" type="date" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /></label>
|
|
135
|
-
<
|
|
135
|
+
<div class="sm:col-span-2 p-3 border border-gray-200 rounded-lg dark:border-neutral-700">
|
|
136
|
+
<Toggle v-model:checked="isActive" label="Enabled for redemption" description="Availability is stored separately from lifecycle status." labelPosition="left" />
|
|
137
|
+
</div>
|
|
136
138
|
</div>
|
|
137
139
|
</form>
|
|
138
140
|
<template #footer>
|