@stacksjs/components 0.2.890 → 0.2.891

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 (64) hide show
  1. package/dist/{AppearancePicker-61r20jpp.stx → AppearancePicker-30fetv0a.stx} +45 -0
  2. package/dist/{Button-r8q6v9m3.stx → Button-ghdfqwg0.stx} +54 -1
  3. package/dist/{Checkbox-52mhrzkz.stx → Checkbox-355qsbwd.stx} +13 -3
  4. package/dist/{PasswordInput-z2g5ha65.stx → PasswordInput-hhq64qzr.stx} +15 -1
  5. package/dist/{SegmentedControl-7q0t8c9s.stx → SegmentedControl-b93n9n2v.stx} +9 -1
  6. package/dist/{Select-ygzchedx.stx → Select-p8mgxthn.stx} +13 -2
  7. package/dist/{SettingsGroup-dkae46k5.stx → SettingsGroup-g1hnxp1p.stx} +52 -0
  8. package/dist/{SettingsPane-jbd1gbdt.stx → SettingsPane-9svk1w3e.stx} +21 -2
  9. package/dist/{SettingsPaneHeader-f0cvkqs7.stx → SettingsPaneHeader-am42srhp.stx} +24 -0
  10. package/dist/{SettingsRow-4cxbsf1q.stx → SettingsRow-kgda3nv1.stx} +63 -0
  11. package/dist/{SettingsSidebarGroup-p2ygv5yy.stx → SettingsSidebarGroup-4ag5qjpw.stx} +17 -0
  12. package/dist/{SettingsSidebarItem-x8fsn3w5.stx → SettingsSidebarItem-ga2jxq53.stx} +33 -0
  13. package/dist/SettingsUpdateRow-ajpnqx8a.stx +143 -0
  14. package/dist/{SettingsWindow-mm490ymt.stx → SettingsWindow-586aps08.stx} +186 -19
  15. package/dist/{Switch-ga9ap8n8.stx → Switch-vd8k23sr.stx} +4 -1
  16. package/dist/{TextInput-m4a4kpfy.stx → TextInput-492d1c3n.stx} +15 -2
  17. package/dist/component-api/component-api.js +21 -3
  18. package/dist/index.js +24 -24
  19. package/dist/settings/settings.js +371 -15
  20. package/dist/ui/appearance-picker/AppearancePicker.d.ts +1 -0
  21. package/dist/ui/button/Button.d.ts +16 -0
  22. package/dist/ui/checkbox/Checkbox.d.ts +7 -0
  23. package/dist/ui/input/PasswordInput.d.ts +10 -0
  24. package/dist/ui/input/TextInput.d.ts +11 -0
  25. package/dist/ui/segmented-control/SegmentedControl.d.ts +7 -0
  26. package/dist/ui/settings/SettingsGroup.d.ts +5 -0
  27. package/dist/ui/settings/SettingsPane.d.ts +4 -0
  28. package/dist/ui/settings/SettingsPaneHeader.d.ts +10 -1
  29. package/dist/ui/settings/SettingsRow.d.ts +20 -1
  30. package/dist/ui/settings/SettingsSidebarGroup.d.ts +5 -0
  31. package/dist/ui/settings/SettingsSidebarItem.d.ts +11 -1
  32. package/dist/ui/settings/SettingsUpdateRow.d.ts +34 -0
  33. package/dist/ui/settings/SettingsWindow.d.ts +12 -0
  34. package/dist/ui/settings/index.d.ts +18 -0
  35. package/dist/ui/settings/native-theme.d.ts +130 -0
  36. package/dist/ui/settings/native.d.ts +51 -0
  37. package/dist/ui/settings/settings.d.ts +5 -2
  38. package/dist/ui/settings/update.d.ts +45 -0
  39. package/dist/utils/component-api.d.ts +2 -0
  40. package/package.json +3 -3
  41. package/src/ui/appearance-picker/AppearancePicker.stx +45 -0
  42. package/src/ui/appearance-picker/README.md +4 -0
  43. package/src/ui/button/Button.stx +54 -1
  44. package/src/ui/checkbox/Checkbox.stx +13 -3
  45. package/src/ui/input/PasswordInput.stx +15 -1
  46. package/src/ui/input/TextInput.stx +15 -2
  47. package/src/ui/segmented-control/SegmentedControl.stx +9 -1
  48. package/src/ui/select/Select.stx +13 -2
  49. package/src/ui/settings/README.md +210 -15
  50. package/src/ui/settings/SettingsGroup.stx +52 -0
  51. package/src/ui/settings/SettingsPane.stx +21 -2
  52. package/src/ui/settings/SettingsPaneHeader.stx +24 -0
  53. package/src/ui/settings/SettingsRow.stx +63 -0
  54. package/src/ui/settings/SettingsSidebarGroup.stx +17 -0
  55. package/src/ui/settings/SettingsSidebarItem.stx +33 -0
  56. package/src/ui/settings/SettingsUpdateRow.stx +143 -0
  57. package/src/ui/settings/SettingsWindow.stx +186 -19
  58. package/src/ui/settings/index.ts +31 -3
  59. package/src/ui/settings/native-theme.ts +169 -0
  60. package/src/ui/settings/native.ts +456 -0
  61. package/src/ui/settings/settings.ts +5 -2
  62. package/src/ui/settings/update.ts +119 -0
  63. package/src/ui/switch/Switch.stx +4 -1
  64. package/src/utils/component-api.ts +36 -3
@@ -101,6 +101,16 @@ export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
101
101
  */
102
102
  export const nativeAutocomplete = autocomplete || 'current-password'
103
103
  export const nativeFieldClasses = `min-h-12 pl-4 pr-11 text-[17px] text-[#000000] dark:text-[#ffffff] bg-[#767680]/12 dark:bg-[#767680]/24 rounded-[10px] border-0 ${error ? 'border border-[#ff3b30] dark:border-[#ff453a]' : ''} ${disabled ? 'opacity-50' : ''} ${inputClassName}`.replace(/\s+/g, ' ').trim()
104
+ /*
105
+ * `variant="mac"` on Craft's AppKit host is AppKit's secure field (an
106
+ * NSSecureTextField), sized as TextInput's Mac field is. It has no reveal
107
+ * button there: AppKit's secure field has none, and the host does not turn
108
+ * one back into a plain field. Which host this is is known only on the
109
+ * device, so the client script decides.
110
+ */
111
+ export const nativeMac = mac && $native
112
+ export const nativeMacFieldClasses = 'min-h-0 h-[22px] pl-0 pr-0 text-[13px] bg-[#00000000] dark:bg-[#00000000] rounded-none'
113
+ export const nativeMacWrapClasses = 'w-[170px]'
104
114
  export const nativeLabelClasses = 'mb-1.5 px-4 text-[13px] uppercase text-[#6d6d72] dark:text-[#8d8d93]'
105
115
  export const nativeHelperClasses = `mt-1.5 px-4 text-[13px] ${error ? 'text-[#ff3b30] dark:text-[#ff453a]' : 'text-[#6d6d72] dark:text-[#8d8d93]'}`
106
116
  </script>
@@ -158,12 +168,14 @@ const inputType = derived(() => showPassword() ? 'text' : 'password')
158
168
  const toggleAriaLabel = derived(() => showPassword() ? 'Hide password' : 'Show password')
159
169
  // The Mac look colours its strength bar from this word rather than a class.
160
170
  const strengthLevel = derived(() => strengthText().toLowerCase())
171
+ // `variant="mac"` on Craft's AppKit host: AppKit's own secure field (see the server script).
172
+ const macDesktop = {{ nativeMac }} && typeof craft !== 'undefined' && craft.platform === 'macos'
161
173
 
162
174
  defineExpose({ value: inputValue })
163
175
  </script>
164
176
 
165
177
  @if($native)
166
- <div class="w-full {{ className }}">
178
+ <div class="{{ className }}" :class="macDesktop ? '{{ nativeMacWrapClasses }}' : 'w-full'">
167
179
  @if(label)
168
180
  <label for="{{ inputId }}" class="{{ nativeLabelClasses }}">{{ label }}</label>
169
181
  @endif
@@ -189,8 +201,10 @@ defineExpose({ value: inputValue })
189
201
  @input="onInput($event)"
190
202
  @change="onChange($event)"
191
203
  aria-invalid="{{ error ? 'true' : 'false' }}"
204
+ :class="{ '{{ nativeMacFieldClasses }}': macDesktop }"
192
205
  />
193
206
  <button
207
+ :if="!macDesktop"
194
208
  type="button"
195
209
  @click="toggleVisibility()"
196
210
  class="absolute top-0 bottom-0 right-0 w-11 items-center justify-center"
@@ -166,6 +166,17 @@ export const autofocus = $bool($props.autofocus)
166
166
  * system red outline, a disabled one dims as UIKit's do.
167
167
  */
168
168
  export const nativeFieldClasses = `min-h-12 px-4 text-[17px] text-[#000000] dark:text-[#ffffff] bg-[#767680]/12 dark:bg-[#767680]/24 rounded-[10px] border-0 ${inputClassName}`.trim()
169
+ /*
170
+ * `variant="mac"` on Craft's AppKit host is AppKit's text field (the host
171
+ * draws an NSTextField): 22pt tall at 13pt, with the bezel and the fill the
172
+ * system gives it, so the phone's fill, corners and padding come off. It is a
173
+ * field at the end of a settings row, 170pt wide; `className="w-full"` (or
174
+ * any width) makes it something else. Which host this is is known only on
175
+ * the device, so these are classes the client script adds there.
176
+ */
177
+ export const nativeMac = mac && $native
178
+ export const nativeMacFieldClasses = 'min-h-0 h-[22px] px-0 text-[13px] bg-[#00000000] dark:bg-[#00000000] rounded-none'
179
+ export const nativeMacWrapClasses = 'w-[170px]'
169
180
  export const nativeLabelClasses = 'mb-1.5 px-4 text-[13px] uppercase text-[#6d6d72] dark:text-[#8d8d93]'
170
181
  export const nativeHelperClasses = `mt-1.5 px-4 text-[13px] ${error ? 'text-[#ff3b30] dark:text-[#ff453a]' : 'text-[#6d6d72] dark:text-[#8d8d93]'}`
171
182
  </script>
@@ -177,6 +188,8 @@ const emit = defineEmits(['input', 'clear', 'focus', 'blur', 'submit', 'submit-e
177
188
  // Validity is live, for the same reason `disabled` is: a form posted with
178
189
  // fetch learns it after the submit, and nothing re-renders (#2047).
179
190
  const nativeClear = typeof craft !== 'undefined' && craft.capabilities.nativePlatformControls === true
191
+ // `variant="mac"` on Craft's AppKit host: AppKit's own field (see the server script).
192
+ const macDesktop = {{ nativeMac }} && typeof craft !== 'undefined' && craft.platform === 'macos'
180
193
  const isError = useReactiveProp('error', {{ error }})
181
194
  // Keep the physical control and its affordances live on both web and native.
182
195
  const isDisabled = useReactiveProp('disabled', {{ disabled }})
@@ -280,7 +293,7 @@ defineExpose({ value: inputValue, clear: onClear })
280
293
  </script>
281
294
 
282
295
  @if($native)
283
- <div class="w-full {{ className }}">
296
+ <div class="{{ className }}" :class="macDesktop ? '{{ nativeMacWrapClasses }}' : 'w-full'">
284
297
  @if(label)
285
298
  <label for="{{ inputId }}" class="{{ nativeLabelClasses }}">{{ label }}</label>
286
299
  @endif
@@ -315,7 +328,7 @@ defineExpose({ value: inputValue, clear: onClear })
315
328
  @end-editing="onNativeEndEditing($event)"
316
329
  aria-invalid="{{ error ? 'true' : 'false' }}"
317
330
  :aria-invalid="isError() ? 'true' : 'false'"
318
- :class="{ 'border border-[#ff3b30] dark:border-[#ff453a]': isError(), 'opacity-50': isDisabled() }"
331
+ :class="{ 'border border-[#ff3b30] dark:border-[#ff453a]': isError(), 'opacity-50': isDisabled(), '{{ nativeMacFieldClasses }}': macDesktop }"
319
332
  @if(clearable):clearButtonMode="nativeClear ? 'while-editing' : 'never'" :style="nativeClear ? null : { paddingRight: 40 }"@endif
320
333
  />
321
334
 
@@ -60,6 +60,13 @@ const sizeClasses = {
60
60
  // of a phone broke in two ("Breakfa / st").
61
61
  const stretchedPadding = { sm: 'px-1', md: 'px-1.5', lg: 'px-1.5' }
62
62
  export const sizing = sizeClasses[size]
63
+ /*
64
+ * `variant="mac"` on Craft's AppKit host (known only on the device) is
65
+ * AppKit's segmented control: 24pt tall whatever `size` says, as the web's
66
+ * Mac look has one size. The host has no segmented control of its own, so
67
+ * the segments are drawn there as they are where a phone has none.
68
+ */
69
+ export const macNative = $props.variant === 'mac' && $native
63
70
 
64
71
  // A block flex box already fills its column, so `stretch` needs no `w-full` -
65
72
  // which beside a margin (`mx-4`) ran the track off the screen's edge.
@@ -91,7 +98,8 @@ const groupLabel = useReactiveProp('label', {{ label }})
91
98
  const selected = useModel('value', { default: {{ value }}, parse: v => v == null ? '' : String(v) })
92
99
  const choices = useReactiveProp('options', {{ options }})
93
100
  const isDisabled = useReactiveProp('disabled', {{ disabled }})
94
- const segmentBase = {{ segmentBase }}
101
+ const macDesktop = {{ macNative }} && typeof craft !== 'undefined' && craft.platform === 'macos'
102
+ const segmentBase = macDesktop ? {{ segmentBase }}.replace(/\bmin-h-\S+/, 'min-h-[24px]').replace(/\bpy-\S+/, 'py-0.5') : {{ segmentBase }}
95
103
  const textSize = {{ sizing.text }}
96
104
  const groupID = {{ testID }}
97
105
  const nativeSegments = typeof craft !== 'undefined' && craft.capabilities.nativePlatformControls === true
@@ -124,6 +124,9 @@ const emit = defineEmits()
124
124
  // Validity is live, for the same reason `disabled` is: a form posted with
125
125
  // fetch learns it after the submit, and nothing re-renders (#2047).
126
126
  const isError = useReactiveProp('error', {{ error }})
127
+ const macDesktop = {{ $native && mac }} && typeof craft !== 'undefined' && craft.platform === 'macos'
128
+ // Live on a native host, where the picker is told so rather than styled so.
129
+ const isDisabled = useReactiveProp('disabled', {{ disabled }})
127
130
  /*
128
131
  * Two-way, like TextInput (stacksjs/stx#2059): `v-model:value="group"` keeps
129
132
  * the page's signal in step, so a call site no longer pairs `:value` with an
@@ -180,18 +183,26 @@ defineExpose({ value: selectedValue, options: optionList })
180
183
  {{-- On a native host the control is the platform's picker (UIPickerView,
181
184
  Android's Spinner) fed with its items. Children are not something either
182
185
  picker holds, so slotted <option>s are a web-only spelling. --}}
183
- <div class="w-full {{ className }}">
186
+ {{-- A phone's picker fills its row. `variant="mac"` on Craft's AppKit host
187
+ is the pop-up button, as wide as its longest choice at the end of a
188
+ settings row; which host this is is known only on the device. --}}
189
+ <div class="{{ className }}" :class="{ 'w-full': !macDesktop }">
184
190
  @if(label)
185
191
  <label for="{{ selectId }}" class="mb-1.5 px-4 text-[13px] uppercase text-[#6d6d72] dark:text-[#8d8d93]">{{ label }}</label>
186
192
  @endif
193
+ {{-- The choices under both names a host reads them by: the phone hosts'
194
+ `items`, and `options` for Craft's AppKit host (an NSPopUpButton). --}}
187
195
  <div
188
196
  data-native="Picker"
189
197
  data-stx-native-host-root
190
198
  id="{{ selectId }}"
191
199
  :items="nativeItems()"
200
+ :options="nativeItems()"
192
201
  :value="selectedValue()"
193
202
  @if(disabled)disabled@endif
194
- class="w-full disabled:opacity-50"
203
+ :disabled="isDisabled()"
204
+ class="disabled:opacity-50"
205
+ :class="{ 'w-full': !macDesktop }"
195
206
  @change="onChange($event)"
196
207
  aria-invalid="{{ error ? 'true' : 'false' }}"
197
208
  :aria-invalid="isError() ? 'true' : 'false'"
@@ -5,6 +5,10 @@ has, its sidebar and search, panes with back and forward, the rounded groups of
5
5
  rows, and controls drawn the way AppKit draws them. Measured against System
6
6
  Settings on macOS 26 and later, in light, dark and an inactive window.
7
7
 
8
+ The same tags and props draw it twice: in a web view, from this package's
9
+ stylesheets, and on a native host (Craft's AppKit host), from the host's own
10
+ views. See [On a native host](#on-a-native-host).
11
+
8
12
  ```html
9
13
  <script client>
10
14
  const pane = state('general')
@@ -15,8 +19,8 @@ const size = state('medium')
15
19
  <SettingsWindow title="Settings" storageKey="my-app" v-model:pane="pane">
16
20
  <template #sidebar>
17
21
  <SettingsSidebarGroup>
18
- <SettingsSidebarItem id="general" label="General" icon="i-f7-gear-alt-fill" tone="grey" />
19
- <SettingsSidebarItem id="appearance" label="Appearance" icon="i-f7-circle-lefthalf-fill" tone="ink" />
22
+ <SettingsSidebarItem id="general" label="General" icon="i-f7-gear-alt-fill" symbol="gearshape.fill" tone="grey" />
23
+ <SettingsSidebarItem id="appearance" label="Appearance" icon="i-f7-circle-lefthalf-fill" symbol="circle.lefthalf.filled" tone="ink" />
20
24
  </SettingsSidebarGroup>
21
25
  </template>
22
26
 
@@ -62,6 +66,7 @@ with `presentation="sheet"`.
62
66
  | `<SettingsPaneHeader>` | The card at the top of a pane: icon, title, a sentence. |
63
67
  | `<SettingsGroup>` | The rounded card of rows, with an optional heading above and footnote below. |
64
68
  | `<SettingsRow>` | A label, an optional description, and the control at the trailing edge. |
69
+ | `<SettingsUpdateRow>` | The row an app that updates itself needs: its version, where the update stands, and the button for it. |
65
70
 
66
71
  Controls, each the library's own component in its Mac look:
67
72
 
@@ -86,14 +91,18 @@ what the button is for.
86
91
  |---|---|
87
92
  | `core.ts` | What the window decides: which pane, the history trail, what a search finds and in what order, where an arrow key lands. No DOM. |
88
93
  | `view.ts` | The DOM: shows a pane, runs the search, moves focus, remembers the pane, marks the window inactive. |
89
- | `*.stx` | The templates and their styles. |
94
+ | `native.ts` | The same window over a native host's tree of views, through stx's host adapter. |
95
+ | `native-theme.ts` | Every size, padding, radius and colour the native branches draw with. |
96
+ | `update.ts` | What an update row says for each state an updater reports. |
97
+ | `*.stx` | The templates and their styles, with an `@if($native)` branch for a native host. |
90
98
 
91
99
  The pieces meet in the DOM, not in each other's scripts. A sidebar item is a
92
100
  `[data-settings-item]`, a pane a `[data-settings-pane]`, a row a
93
101
  `[data-settings-row]`; the shell finds them wherever they are, so a row can be
94
102
  your own markup as long as it carries those attributes.
95
- `@stacksjs/components/settings` exports the core and the view without the
96
- templates.
103
+ `@stacksjs/components/settings` exports the core, both views and the update
104
+ row's words without the templates. On a native host the pieces meet the same
105
+ way, as attributes on the host's views.
97
106
 
98
107
  ## SettingsWindow
99
108
 
@@ -121,7 +130,11 @@ account this is), and the default slot (the panes).
121
130
  From `componentApi(target)` (`@stacksjs/components/component-api`):
122
131
  `showPane(id)`, `revealSetting(id)` (opens the pane that holds the row with
123
132
  that `setting`, scrolls to it and highlights it; false when there is none),
124
- `back()`, `forward()`, `focusSearch()`, `getPane()`.
133
+ `back()`, `forward()`, `focusSearch()`, `getPane()`. On a native host, which
134
+ has no document to find the window in, `componentApi(id)` takes the window's
135
+ `id` and nothing else.
136
+ A native sidebar item carries the test id `settings-item-<id>`, so a UI test can
137
+ open a pane by pressing it.
125
138
 
126
139
  ```ts
127
140
  import { componentApi } from '@stacksjs/components/component-api'
@@ -133,10 +146,11 @@ componentApi('settings').revealSetting('open-at-login')
133
146
  ## Rows
134
147
 
135
148
  `<SettingsRow>` props: `label`, `description`, `icon` and `tone` (a leading
136
- tile), `setting` (its id), `keywords`, `to` (a pane id: a navigation row with a
137
- chevron), `value` (text beside the chevron), `multiline`, `destructive`,
138
- `disabled`, `layout="stacked"` (the control under the label, for a text area or
139
- a list of radio buttons).
149
+ tile), `symbol` (the tile's glyph on a native host), `setting` (its id),
150
+ `keywords`, `to` (a pane id: a navigation row with a chevron), `value` (text
151
+ beside the chevron), `multiline`, `destructive`, `disabled`,
152
+ `layout="stacked"` (the control under the label, for a text area or a list of
153
+ radio buttons).
140
154
 
141
155
  The row's label names the control inside it: a control with no accessible name
142
156
  of its own gets `aria-labelledby` pointing at the label, and the description
@@ -145,6 +159,50 @@ becomes its `aria-describedby`.
145
159
  Tones: `grey`, `blue`, `red`, `orange`, `yellow`, `green`, `indigo`, `purple`,
146
160
  `pink`, `ink`. Icons are Iconify classes, such as `i-f7-bell-fill`.
147
161
 
162
+ `icon` and `symbol` are the same glyph for two hosts. `icon` is an Iconify
163
+ class, which is CSS and so the web's. `symbol` is an SF Symbol name
164
+ (`bell.fill`), which a native host draws. `<SettingsSidebarItem>`,
165
+ `<SettingsRow>` and `<SettingsPaneHeader>` take both; give both to a screen
166
+ that is built for both. Nothing maps one to the other.
167
+
168
+ ## Update row
169
+
170
+ ```html
171
+ <script client>
172
+ const status = state(null)
173
+ onMount(async () => {
174
+ onDestroy(craft.updater.onChange(next => status.set(next)))
175
+ status.set(await craft.updater.status())
176
+ })
177
+ </script>
178
+
179
+ <SettingsGroup header="Software Update">
180
+ <SettingsUpdateRow appName="Library" :status="status()"
181
+ @check="craft.updater.check()" @install="craft.updater.install()"
182
+ @relaunch="craft.updater.relaunch()" />
183
+ </SettingsGroup>
184
+ ```
185
+
186
+ `status` is what an updater reports: `craft.updater`'s `UpdateStatus` on
187
+ Craft's AppKit host, or a web app's own of the same shape
188
+ (`SettingsUpdateStatus`). The row says the app and its version, a sentence for
189
+ the state, and shows one button: **Check Now** (`idle`, `current`, `error`,
190
+ and disabled while `checking`), **Download and Install** (`available`, and
191
+ disabled beside the percentage while `downloading` and `installing`), or
192
+ **Restart to Update** (`installed`). An app that cannot replace itself
193
+ (`selfUpdating: false`) is never offered an install and says why (`reason`).
194
+ It emits `check`, `install` and `relaunch` and does nothing else.
195
+
196
+ | Prop | Default | |
197
+ |---|---|---|
198
+ | `appName` | | The app's name, before its version. |
199
+ | `status` | | The updater's status. Reactive. |
200
+ | `setting` | `'software-update'` | The row's id, for search and `revealSetting`. |
201
+ | `keywords` | `'update version upgrade release'` | |
202
+
203
+ `settingsUpdateView(status, appName)` (`@stacksjs/components/settings`) is the
204
+ same words without the row, for an app that draws its own.
205
+
148
206
  ## Search
149
207
 
150
208
  The field filters the sidebar and, like System Settings, also lists the
@@ -167,6 +225,139 @@ briefly. The number of results is announced to a screen reader.
167
225
  The sidebar is a vertical tab list with one tab stop; each pane is a labelled
168
226
  tab panel. Nothing traps focus.
169
227
 
228
+ ## On a native host
229
+
230
+ A native screen (Craft's AppKit host, where a window is AppKit views and not a
231
+ web view) is written with the same tags:
232
+
233
+ ```html
234
+ <script client>
235
+ const pane = state('general')
236
+ const openAtLogin = state(true)
237
+ const size = state('medium')
238
+ const appearance = state('auto')
239
+ const status = state(null)
240
+
241
+ onMount(async () => {
242
+ if (!craft.updater) return
243
+ onDestroy(craft.updater.onChange(next => status.set(next)))
244
+ status.set(await craft.updater.status())
245
+ })
246
+ </script>
247
+
248
+ <SettingsWindow id="settings" title="Settings" storageKey="library" v-model:pane="pane">
249
+ <template #account>
250
+ <View class="flex-row items-center gap-2 px-2 py-1">
251
+ <Icon symbol="person.crop.circle.fill" class="h-[32px] w-[32px]" style="color: secondaryLabel" />
252
+ <View class="flex-col">
253
+ <Text class="text-[13px] font-semibold">Ada Lovelace</Text>
254
+ <Text class="text-[11px]" style="color: secondaryLabel">ada@example.com</Text>
255
+ </View>
256
+ </View>
257
+ </template>
258
+
259
+ <template #sidebar>
260
+ <SettingsSidebarGroup>
261
+ <SettingsSidebarItem id="general" label="General" symbol="gearshape.fill" tone="grey" />
262
+ <SettingsSidebarItem id="appearance" label="Appearance" symbol="circle.lefthalf.filled" tone="ink" />
263
+ </SettingsSidebarGroup>
264
+ <SettingsSidebarGroup>
265
+ <SettingsSidebarItem id="updates" label="Software Update" symbol="arrow.down.circle.fill" tone="blue" />
266
+ <SettingsSidebarItem id="about" label="About" symbol="info.circle.fill" tone="grey" />
267
+ </SettingsSidebarGroup>
268
+ </template>
269
+
270
+ <SettingsPane id="general" title="General" active>
271
+ <SettingsGroup header="Startup" footer="Starts in the background when you sign in.">
272
+ <SettingsRow label="Open at login" setting="open-at-login" keywords="launch start">
273
+ <Switch variant="mac" v-model:checked="openAtLogin" />
274
+ </SettingsRow>
275
+ <SettingsRow label="Sidebar icon size" setting="icon-size">
276
+ <Select variant="mac" v-model:value="size" placeholder="" :options="['small', 'medium', 'large']" />
277
+ </SettingsRow>
278
+ </SettingsGroup>
279
+ </SettingsPane>
280
+
281
+ <SettingsPane id="appearance" title="Appearance">
282
+ <SettingsGroup>
283
+ <SettingsRow label="Appearance" layout="stacked" setting="appearance">
284
+ <AppearancePicker v-model:value="appearance" label="Appearance" />
285
+ </SettingsRow>
286
+ </SettingsGroup>
287
+ </SettingsPane>
288
+
289
+ <SettingsPane id="updates" title="Software Update">
290
+ <SettingsGroup>
291
+ <SettingsUpdateRow appName="Library" :status="status()"
292
+ @check="craft.updater.check()" @install="craft.updater.install()"
293
+ @relaunch="craft.updater.relaunch()" />
294
+ </SettingsGroup>
295
+ </SettingsPane>
296
+
297
+ <SettingsPane id="about" title="About">
298
+ <SettingsPaneHeader symbol="books.vertical.fill" tone="blue" title="Library"
299
+ description="Lists, notes and prompts, on every Mac you sign in to." />
300
+ <SettingsGroup>
301
+ <SettingsRow label="Version" setting="version"><Text :text="craft.app.version" /></SettingsRow>
302
+ <SettingsRow label="Acknowledgements" to="acknowledgements" />
303
+ </SettingsGroup>
304
+ </SettingsPane>
305
+
306
+ <SettingsPane id="acknowledgements" title="Acknowledgements" parent="about">
307
+ <SettingsGroup><SettingsRow label="stx" description="MIT" /></SettingsGroup>
308
+ </SettingsPane>
309
+ </SettingsWindow>
310
+ ```
311
+
312
+ It is drawn from the host's own views: the sidebar on the system's sidebar
313
+ material with the system's search field, each item a tinted tile holding an SF
314
+ Symbol, the selected one a blue pill with white words; the pane under back,
315
+ forward and its name; groups as raised cards with a hairline above every row
316
+ but the first. Every size, padding, radius and colour is a class list in
317
+ `native-theme.ts` and nowhere else.
318
+
319
+ What is the same as the web: `pane` and `v-model:pane`, `active`, `storageKey`
320
+ (the app's storage, which stx serves as `localStorage`), the `account` and
321
+ `sidebar` slots, `@pane`, `@search` and `@navigate`, navigation rows with back
322
+ and forward, sub-panes keeping their parent's item selected, the search (the
323
+ same ranking, sidebar items filtered and matching settings listed with their
324
+ pane), `tone`, `badge`, `destructive`, `disabled`, `multiline`, `value`,
325
+ `layout="stacked"`, a group's `header` and `footer`, and
326
+ `showPane`, `revealSetting`, `back`, `forward`, `focusSearch` and `getPane`
327
+ through `componentApi(id)`.
328
+
329
+ The controls in a row are the host's: `<Switch>` is an NSSwitch, `<Select>` an
330
+ NSPopUpButton, `<Checkbox>` the system checkbox, `<TextInput>` and
331
+ `<PasswordInput>` an NSTextField and an NSSecureTextField, and `<Button>` an
332
+ NSButton (`variant="primary"`, `"danger"` and `"ghost"` are the host's default,
333
+ destructive and borderless buttons; anything else is the plain push button).
334
+ `variant="mac"` sizes a field, a label and a segment as AppKit does; without it
335
+ they keep the sizes the phone hosts use.
336
+
337
+ What differs, because the host does not offer it:
338
+
339
+ - **Glyphs are `symbol`.** An Iconify `icon` class draws nothing natively.
340
+ - **No keys.** A native host reports no key presses to a screen, so the arrow
341
+ keys, type-ahead, Cmd+F and Cmd+[ and ] are the web's. Wire them through the
342
+ app's menus (`craft.desktop.setMenus` and `onCommand`) to `focusSearch()`,
343
+ `back()` and `forward()`. Escape in the search field does clear it.
344
+ - **`revealSetting` does not scroll.** It opens the pane and highlights the
345
+ row; a host has no way to scroll a view into sight.
346
+ - **A navigation row is one press target.** The whole row opens the pane, so a
347
+ control in its slot is not pressed for itself.
348
+ - **The selection is the system blue,** not the accent the person chose in
349
+ System Settings, and the window does not grey it when it is not in front:
350
+ the host does not report either.
351
+ - **A pane keeps its own scroll position,** since each is a scroll view.
352
+ - **`presentation`, `height` and `--stx-*` variables are the web's.** The
353
+ window fills what it is given; `sidebarWidth` still sets the sidebar.
354
+ - **A row does not name its control.** The control's own accessible name is
355
+ what a screen reader hears.
356
+ - **`<SegmentedControl>` is drawn,** not an NSSegmentedControl, and
357
+ **`<Slider>` does not work**: Craft's AppKit host has neither primitive.
358
+ - **`<SettingsUpdateRow>` shows the download as a percentage.** The host has no
359
+ determinate progress bar.
360
+
170
361
  ## Theming
171
362
 
172
363
  Everything is drawn from `--stx-mac-*` custom properties
@@ -212,10 +403,14 @@ point where a display can draw one. Motion stops under
212
403
  cannot see the window's `pane` prop while the server renders it. Without it
213
404
  the first pane shows until the script runs.
214
405
  - **Appearance thumbnails are sketches** drawn in CSS, not Apple's artwork.
215
- - **The Mac look is for a web view.** Its styles are left out of a native
216
- (iOS, Android) build, where a control has the platform's own look already.
406
+ - **The Mac stylesheets are for a web view.** They are left out of a native
407
+ build, which draws the same components from the host's own views
408
+ ([On a native host](#on-a-native-host)). The native look is measured for a
409
+ Mac; on a phone the controls keep the platform's own look and the window is
410
+ not laid out for a phone's width.
217
411
  - **Icons need the app's icon CSS.** A tile shows nothing if the page does not
218
412
  generate the Iconify class it was given.
219
- - **Not looked at:** a real Craft window, Windows and Linux web views, a screen
220
- reader. Focus rings are tested from their CSS rules, since a headless window
221
- never shows keyboard focus.
413
+ - **Not looked at:** a real Craft window (web view or AppKit), Windows and
414
+ Linux web views, a screen reader. Focus rings are tested from their CSS
415
+ rules, since a headless window never shows keyboard focus. The native tree
416
+ is tested as the host receives it, not as AppKit draws it.
@@ -1,4 +1,6 @@
1
1
  <script server>
2
+ import { SETTINGS_NATIVE } from './native-theme'
3
+
2
4
  /*
3
5
  * <SettingsGroup>: the rounded inset card a Settings pane is made of, with an
4
6
  * optional heading above it and a footnote below.
@@ -18,6 +20,10 @@
18
20
  * `footer` is text, or a named slot when the footnote carries a link:
19
21
  *
20
22
  * <template #footer>Read the <a href="/privacy">privacy notes</a>.</template>
23
+ *
24
+ * On a native host ($native) there is no sibling selector, so each row
25
+ * carries its own hairline (`data-settings-row-rule`) and the group shows it
26
+ * on every row but the first, again whenever its rows change.
21
27
  */
22
28
  export const header = $props.header || ''
23
29
  export const footer = $props.footer || ''
@@ -25,14 +31,59 @@ export const hasFooterSlot = Boolean($slots && $slots.footer)
25
31
  export const groupId = $props.id || `settings-section-${$uid}`
26
32
  export const headerId = `${groupId}-header`
27
33
  export const className = $props.className || ''
34
+ export const T = SETTINGS_NATIVE
28
35
  </script>
29
36
 
30
37
  <script client>
31
38
  const heading = useReactiveProp('header', {{ header }})
32
39
  const note = useReactiveProp('footer', {{ footer }})
33
40
  const headerId = {{ headerId }}
41
+
42
+ // A native host: the hairline above every row but the first.
43
+ const native = {{ $native }}
44
+ const cardRef = useRef('card')
45
+ let stopObserving = null
46
+
47
+ function ruleRows() {
48
+ const tree = window.stx._host
49
+ const card = cardRef()
50
+ if (!card) return
51
+ let first = true
52
+ for (const node of tree.descendants(card)) {
53
+ if (tree.getAttribute(node, 'data-settings-row-rule') == null) continue
54
+ // Served hidden by class, so no card draws a rule above its first row for a frame.
55
+ const classes = String(tree.getAttribute(node, 'class') || '').split(/\s+/).filter(name => name && name !== 'hidden')
56
+ tree.setAttribute(node, 'class', (first ? [...classes, 'hidden'] : classes).join(' '))
57
+ first = false
58
+ }
59
+ }
60
+
61
+ if (native) {
62
+ onMount(() => {
63
+ ruleRows()
64
+ const card = cardRef()
65
+ if (card) stopObserving = window.stx._host.observeChildren(card, ruleRows)
66
+ })
67
+ onDestroy(() => {
68
+ if (stopObserving) stopObserving()
69
+ stopObserving = null
70
+ })
71
+ }
34
72
  </script>
35
73
 
74
+ @if($native)
75
+ <section id="{{ groupId }}" data-settings-section class="{{ T.section }} {{ className }}">
76
+ <h3 :show="heading()" :text="heading()" class="{{ T.sectionHeader }}">{{ header }}</h3>
77
+ <div ref="card" class="{{ T.card }}" role="group" data-settings-card>
78
+ <slot />
79
+ </div>
80
+ @if(hasFooterSlot)
81
+ <div class="{{ T.sectionFooter }}"><slot name="footer" /></div>
82
+ @else
83
+ <p :show="note()" :text="note()" class="{{ T.sectionFooter }}">{{ footer }}</p>
84
+ @endif
85
+ </section>
86
+ @else
36
87
  <section id="{{ groupId }}" data-settings-section class="stx-settings-section {{ className }}">
37
88
  <h3 id="{{ headerId }}" :show="heading()" :text="heading()" class="stx-settings-section-header">{{ header }}</h3>
38
89
  <div class="stx-settings-card" role="group" @if(header)aria-labelledby="{{ headerId }}"@endif :aria-labelledby="heading() ? headerId : null">
@@ -44,6 +95,7 @@ const headerId = {{ headerId }}
44
95
  <p :show="note()" :text="note()" class="stx-settings-section-footer">{{ footer }}</p>
45
96
  @endif
46
97
  </section>
98
+ @endif
47
99
 
48
100
  <style data-native-exclude>
49
101
  :where(:root) {
@@ -1,4 +1,6 @@
1
1
  <script server>
2
+ import { SETTINGS_NATIVE } from './native-theme'
3
+
2
4
  /*
3
5
  * <SettingsPane>: one screen of a Settings window. Its `id` is the id its
4
6
  * sidebar item carries; a pane with a `parent` is a sub-pane, reached by a
@@ -6,6 +8,9 @@
6
8
  *
7
9
  * Every pane is in the page from the start and all but one are hidden. The
8
10
  * shell shows the open one; `active` leaves this one showing before it has.
11
+ *
12
+ * On a native host ($native) a pane is a scroll view of its own, so each pane
13
+ * keeps its place when the window moves between them.
9
14
  */
10
15
  export const paneId = $props.id || ''
11
16
  export const title = $props.title || paneId
@@ -14,9 +19,23 @@ export const parent = $props.parent || ''
14
19
  export const active = $bool($props.active)
15
20
  export const role = parent ? 'region' : 'tabpanel'
16
21
  export const className = $props.className || ''
22
+ export const T = SETTINGS_NATIVE
17
23
  </script>
18
24
 
19
- @if(active)
25
+ @if($native)
26
+ <section
27
+ data-native="ScrollView"
28
+ data-settings-pane="{{ paneId }}"
29
+ data-title="{{ title }}"
30
+ data-keywords="{{ keywords }}"
31
+ data-parent="{{ parent }}"
32
+ @if(active)data-active@endif
33
+ aria-label="{{ title }}"
34
+ class="{{ T.pane }} {{ active ? '' : 'hidden' }} {{ className }}"
35
+ >
36
+ <div class="{{ T.paneContent }}"><slot /></div>
37
+ </section>
38
+ @elseif(active)
20
39
  <section
21
40
  data-settings-pane="{{ paneId }}"
22
41
  data-title="{{ title }}"
@@ -44,7 +63,7 @@ export const className = $props.className || ''
44
63
  </section>
45
64
  @endif
46
65
 
47
- <style>
66
+ <style data-native-exclude>
48
67
  .stx-settings-pane { display: block; min-width: 0; outline: 0; }
49
68
  .stx-settings-pane[hidden] { display: none; }
50
69
  </style>
@@ -1,4 +1,6 @@
1
1
  <script server>
2
+ import { SETTINGS_NATIVE, SETTINGS_NATIVE_TONES, settingsNativeGlyph } from './native-theme'
3
+
2
4
  /*
3
5
  * <SettingsPaneHeader>: the card at the top of a pane that says what the pane
4
6
  * is. A large icon tile, the pane's name, and a sentence about it.
@@ -7,6 +9,9 @@
7
9
  * description="Manage your overall setup and preferences." />
8
10
  *
9
11
  * Anything in the slot goes under the description: a link, a button.
12
+ *
13
+ * On a native host ($native) the glyph is the SF Symbol named by `symbol`;
14
+ * `icon`, an Iconify class, is the web's.
10
15
  */
11
16
  const TONES = ['grey', 'blue', 'red', 'orange', 'yellow', 'green', 'indigo', 'purple', 'pink', 'ink']
12
17
  export const icon = $props.icon || ''
@@ -14,6 +19,11 @@ export const tone = TONES.includes($props.tone) ? $props.tone : 'grey'
14
19
  export const title = $props.title || ''
15
20
  export const description = $props.description || ''
16
21
  export const className = $props.className || ''
22
+ export const symbol = $props.symbol || ''
23
+ export const T = SETTINGS_NATIVE
24
+ export const tileFill = SETTINGS_NATIVE_TONES[tone]
25
+ export const glyphInk = settingsNativeGlyph(tone)
26
+ export const hasExtra = Boolean($slots && $slots.default)
17
27
  </script>
18
28
 
19
29
  <script client>
@@ -21,6 +31,19 @@ const heading = useReactiveProp('title', {{ title }})
21
31
  const detail = useReactiveProp('description', {{ description }})
22
32
  </script>
23
33
 
34
+ @if($native)
35
+ {{-- A div: a native build reads <header> as the safe-area view. --}}
36
+ <div data-settings-pane-header class="{{ T.hero }} {{ className }}">
37
+ @if(symbol)
38
+ <div class="{{ T.heroTile }} {{ tileFill }}" data-settings-tile="{{ tone }}"><span data-native="Icon" symbol="{{ symbol }}" class="{{ T.heroGlyph }} {{ glyphInk }}"></span></div>
39
+ @endif
40
+ <h2 :text="heading()" class="{{ T.heroTitle }}">{{ title }}</h2>
41
+ <p :show="detail()" :text="detail()" class="{{ T.heroDescription }}">{{ description }}</p>
42
+ @if(hasExtra)
43
+ <div class="{{ T.heroExtra }}"><slot /></div>
44
+ @endif
45
+ </div>
46
+ @else
24
47
  <header data-settings-pane-header class="stx-settings-hero {{ className }}">
25
48
  @if(icon)
26
49
  <span class="stx-settings-hero-tile" data-tone="{{ tone }}" aria-hidden="true"><i class="{{ icon }}"></i></span>
@@ -29,6 +52,7 @@ const detail = useReactiveProp('description', {{ description }})
29
52
  <p :show="detail()" :text="detail()" class="stx-settings-hero-description">{{ description }}</p>
30
53
  <div class="stx-settings-hero-extra"><slot /></div>
31
54
  </header>
55
+ @endif
32
56
 
33
57
  <style data-native-exclude>
34
58
  :where(:root) {