@stacksjs/components 0.2.889 → 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
@@ -1,4 +1,6 @@
1
1
  <script server>
2
+ import { SETTINGS_NATIVE } from '../settings/native-theme'
3
+
2
4
  /*
3
5
  * <AppearancePicker>: light, dark, or whatever the system is, picked from
4
6
  * three small pictures of a desktop, as System Settings offers it.
@@ -13,6 +15,11 @@
13
15
  *
14
16
  * A radio group: one tab stop, arrow keys move the choice. The pictures are
15
17
  * drawn in CSS and say nothing to a screen reader; the captions do.
18
+ *
19
+ * On a native host ($native) each choice is a pressable picture drawn from
20
+ * views (a light half, a dark half, both for Auto) with the chosen one ringed
21
+ * in the accent, from the class lists in ../settings/native-theme. There are
22
+ * no arrow keys there: a native host reports no key presses to a screen.
16
23
  */
17
24
  const MODES = ['light', 'dark', 'auto']
18
25
  export const value = MODES.includes($props.value) ? $props.value : 'auto'
@@ -21,6 +28,7 @@ export const label = $props.label || ''
21
28
  export const disabled = $bool($props.disabled)
22
29
  export const pickerId = $props.id || `appearance-picker-${$uid}`
23
30
  export const className = $props.className || ''
31
+ export const T = SETTINGS_NATIVE
24
32
  </script>
25
33
 
26
34
  <script client>
@@ -89,9 +97,45 @@ function onKey(event, mode) {
89
97
  if (picture) picture.focus()
90
98
  }
91
99
 
100
+ // A native host: which half of the picture is light and which dark.
101
+ const lightHalf = {{ $native ? T.appearanceLight : '' }}
102
+ const darkHalf = {{ $native ? T.appearanceDark : '' }}
103
+
92
104
  defineExpose({ value: chosen })
93
105
  </script>
94
106
 
107
+ @if($native)
108
+ <div
109
+ id="{{ pickerId }}"
110
+ role="radiogroup"
111
+ data-stx-appearance-picker
112
+ @if(label)aria-label="{{ label }}"@endif
113
+ :aria-label="groupLabel() || null"
114
+ class="{{ T.appearance }} {{ className }}"
115
+ :class="{ 'opacity-50': isDisabled() }"
116
+ >
117
+ <div
118
+ data-native="Pressable"
119
+ :for="mode in modes()"
120
+ :key="mode.value"
121
+ role="radio"
122
+ class="{{ T.appearanceOption }}"
123
+ :data-mode="mode.value"
124
+ :aria-label="mode.label"
125
+ :aria-checked="isOn(mode) ? 'true' : 'false'"
126
+ @click="choose(mode)"
127
+ >
128
+ <div class="{{ T.appearanceFrame }}" :aria-checked="isOn(mode) ? 'true' : 'false'">
129
+ <div class="{{ T.appearanceThumb }}">
130
+ <div :class="mode.value === 'dark' ? darkHalf : lightHalf"></div>
131
+ <div :class="mode.value === 'light' ? lightHalf : darkHalf"></div>
132
+ </div>
133
+ </div>
134
+ <span class="{{ T.appearanceCaption }}" :text="mode.label"></span>
135
+ </div>
136
+ </div>
137
+ @else
138
+
95
139
  <div
96
140
  id="{{ pickerId }}"
97
141
  role="radiogroup"
@@ -116,6 +160,7 @@ defineExpose({ value: chosen })
116
160
  @keydown="onKey($event, mode)"
117
161
  ><span class="stx-appearance-frame" aria-hidden="true"><span class="stx-appearance-thumb"><span class="stx-appearance-scene" data-scheme="light"></span><span class="stx-appearance-scene" data-scheme="dark"></span></span></span><span class="stx-appearance-caption" :text="mode.label"></span></button>
118
162
  </div>
163
+ @endif
119
164
 
120
165
  <style data-native-exclude>
121
166
  :where(:root) {
@@ -181,6 +181,21 @@ export const nativeButtonClasses = `flex-row items-center justify-center ${nativ
181
181
  export const nativeTextClasses = `font-semibold ${nativeSize.text} ${nativeVariant.text}`
182
182
  export const legacyNativeTint = variant === 'primary' || variant === 'danger' ? '#ffffff' : '#007aff'
183
183
  export const nativeTintClass = nativeVariant.text
184
+ /*
185
+ * On a Mac (Craft's AppKit host) a button is the system's push button, an
186
+ * NSButton the host draws, not the phone's filled one: 13pt words on the
187
+ * standard bezel. The host knows four looks by name and only a written
188
+ * `variant` asks for one: `primary` is the default (accent) button, `danger`
189
+ * the destructive one, `ghost` a borderless one, `toolbar` the toolbar's.
190
+ * Anything else, and no variant at all, is the plain push button, as
191
+ * `appearance="mac"` has it on the web, because on a Mac most buttons are.
192
+ * Which host this is is only known on the device, so both are in the screen
193
+ * and the client script keeps one.
194
+ */
195
+ const desktopVariants = ['primary', 'danger', 'ghost', 'toolbar']
196
+ export const desktopVariant = desktopVariants.includes($props.variant) ? $props.variant : ''
197
+ /** `title` names the button only when nothing in the slot does: beside content it is the tooltip. */
198
+ export const titleNames = !slotWords
184
199
  </script>
185
200
 
186
201
  <script client>
@@ -213,7 +228,18 @@ const labelProp = useReactiveProp('label', {{ label }}, { parse: value => value
213
228
  // Preserve native Button's text prop when the same shared file is selected.
214
229
  // Read it as a prop, not a root text binding that would erase icons/spinners.
215
230
  const textProp = useReactiveProp('text', '', { parse: value => value == null ? '' : String(value) })
216
- const labelText = derived(() => labelProp() || textProp())
231
+ /*
232
+ * `title` is the desktop spelling of the words (stacksjs/stx#2091), and it is
233
+ * live as `label` is: `:title="busy() ? 'One moment' : 'Sign In'"` is a
234
+ * binding the server never sees, so read once there it was no words at all
235
+ * and the button drew empty. Beside slot content it stays the tooltip.
236
+ */
237
+ const titleNames = {{ titleNames }}
238
+ const titleProp = useReactiveProp('title', {{ titleWords }}, { parse: value => value == null ? '' : String(value) })
239
+ const labelText = derived(() => labelProp() || textProp() || (titleNames ? titleProp() : ''))
240
+ const symbolProp = useReactiveProp('symbol', {{ symbol }}, { parse: value => value == null ? '' : String(value) })
241
+ // Craft's AppKit host: the button is the system's own (see the server script).
242
+ const desktop = typeof craft !== 'undefined' && craft.platform === 'macos'
217
243
  const isLoading = useReactiveProp('loading', {{ loading }})
218
244
  // The accessible name is live too. Read once on the server, a bound one
219
245
  // (:ariaLabel="action.label" in a row of icon buttons) stayed on the boxless
@@ -237,11 +263,38 @@ function onClick(event) {
237
263
  </script>
238
264
 
239
265
  @if($native)
266
+ {{-- A Mac: the host's push button. Its words are `title` (the label, or the
267
+ slot's text when there is no label), its glyph `symbol`. A caller's
268
+ `class` and `style` land on it, so a font size and a colour are the
269
+ button's own. --}}
270
+ <button
271
+ :if="desktop"
272
+ data-native="Button"
273
+ data-stx-native-host-root
274
+ type="{{ type }}"
275
+ class="text-accent {{ fullWidth ? 'w-full' : '' }} {{ className }}"
276
+ @if(desktopVariant)variant="{{ desktopVariant }}"@endif
277
+ @if(symbol)symbol="{{ symbol }}"@endif
278
+ :symbol="symbolProp() || null"
279
+ @if(iconOnly)iconOnly="true"@endif
280
+ @if(label)title="{{ label }}"@endif
281
+ :title="labelText() || null"
282
+ @if(isDisabled)disabled@endif
283
+ :disabled="isDisabled()"
284
+ aria-busy="{{ loading ? 'true' : 'false' }}"
285
+ :aria-busy="isLoading() ? 'true' : 'false'"
286
+ @if(ariaLabel)aria-label="{{ ariaLabel }}"@endif
287
+ :aria-label="String(ariaLabelProp() ?? '') || null"
288
+ @click="onClick($event)"
289
+ ><slot /></button>
240
290
  <button
291
+ :if="!desktop"
292
+ data-stx-native-host-root
241
293
  type="{{ type }}"
242
294
  class="{{ nativeButtonClasses }}"
243
295
  activeOpacity="0.6"
244
296
  @if(symbol)symbol="{{ symbol }}"@endif
297
+ :symbol="symbolProp() || null"
245
298
  @if(iconOnly)iconOnly="true"@endif
246
299
  @if(isDisabled)disabled@endif
247
300
  :disabled="isDisabled()"
@@ -20,7 +20,14 @@ export const switchAppearance = $props.appearance === 'switch'
20
20
  * are the browser's own; only the classes change, to `stx-mac-checkbox`,
21
21
  * which this file's <style> block draws from the `--stx-mac-*` tokens.
22
22
  */
23
- export const mac = $props.variant === 'mac'
23
+ export const mac = $props.variant === 'mac' && !$native
24
+ /*
25
+ * The Mac look is a stylesheet, and a native host has none: there the box is
26
+ * the platform's own control whatever `variant` says. On a Mac (Craft's
27
+ * AppKit host, known only on the device) `variant="mac"` also sets the words
28
+ * at AppKit's sizes, 13pt over 11pt; a phone keeps its own.
29
+ */
30
+ export const macNative = $props.variant === 'mac' && $native
24
31
 
25
32
  const sizeClasses = { sm: 'h-4 w-4', md: 'h-5 w-5', lg: 'h-6 w-6' }
26
33
  const baseClasses = 'rounded border-line-strong text-accent focus:ring-accent focus:ring-2 focus:ring-offset-2 focus:ring-offset-panel transition-colors'
@@ -89,6 +96,9 @@ const isIndeterminate = useReactiveProp('indeterminate', {{ indeterminate }})
89
96
  const isChecked = useReactiveProp('checked', {{ checked }})
90
97
  const currentLabel = useReactiveProp('label', {{ label }}, { parse: value => value ?? '' })
91
98
 
99
+ // `variant="mac"` on Craft's AppKit host: the words at AppKit's sizes.
100
+ const macDesktop = {{ macNative }} && typeof craft !== 'undefined' && craft.platform === 'macos'
101
+
92
102
  function onInputChange(event) {
93
103
  if (isDisabled()) {
94
104
  event.target.checked = isChecked()
@@ -182,13 +192,13 @@ defineExpose({ isChecked })
182
192
 
183
193
  <div :if="currentLabel() || {{ !!description }}" class="ml-3 text-sm leading-6">
184
194
  <label :if="currentLabel()" for="{{ inputId }}" class="{{ labelClasses }} inline-flex flex-row items-center" :class="{ 'opacity-50 cursor-not-allowed': isDisabled(), 'cursor-pointer': !isDisabled() }">
185
- <span :text="currentLabel()">{{ label }}</span>
195
+ <span :text="currentLabel()"@if($native) :class="{ 'text-[13px]': macDesktop }"@endif>{{ label }}</span>
186
196
  @if(required)
187
197
  <span class="text-danger ml-1">*</span>
188
198
  @endif
189
199
  </label>
190
200
  @if(description)
191
- <p id="{{ descriptionId }}" class="{{ descriptionClasses }}">
201
+ <p id="{{ descriptionId }}" class="{{ descriptionClasses }}"@if($native) :class="{ 'text-[11px]': macDesktop }"@endif>
192
202
  {{ description }}
193
203
  </p>
194
204
  @endif
@@ -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"
@@ -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'"
@@ -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) {
@@ -1,4 +1,6 @@
1
1
  <script server>
2
+ import { SETTINGS_NATIVE, SETTINGS_NATIVE_SYMBOLS, SETTINGS_NATIVE_TONES, settingsNativeGlyph } from './native-theme'
3
+
2
4
  /*
3
5
  * <SettingsRow>: one setting in a <SettingsGroup>. Its name at the leading
4
6
  * edge, a description under it, and the control (whatever is in the slot) at
@@ -25,6 +27,12 @@
25
27
  * `layout="stacked"` puts the control under the label at full width;
26
28
  * `destructive` paints the label as a destructive action. `icon` is an
27
29
  * Iconify class on a tile of `tone`.
30
+ *
31
+ * On a native host ($native) the tile's glyph is the SF Symbol named by
32
+ * `symbol` (`icon` is CSS, which a native host has none of), the chevron is
33
+ * the system's, and a navigation row is one press target: the whole row opens
34
+ * the pane, so a control in its slot is not pressed for itself there. The
35
+ * hairline above the row is the row's own view, shown by its group.
28
36
  */
29
37
  const TONES = ['grey', 'blue', 'red', 'orange', 'yellow', 'green', 'indigo', 'purple', 'pink', 'ink']
30
38
  export const label = $props.label || ''
@@ -45,6 +53,21 @@ export const rowId = $props.id || (settingSlug ? `settings-row-${settingSlug}` :
45
53
  export const labelId = `${rowId}-label`
46
54
  export const descriptionId = `${rowId}-description`
47
55
  export const className = $props.className || ''
56
+
57
+ export const symbol = $props.symbol || ''
58
+ export const T = SETTINGS_NATIVE
59
+ export const chevron = SETTINGS_NATIVE_SYMBOLS.disclosure
60
+ export const tileFill = SETTINGS_NATIVE_TONES[tone]
61
+ export const glyphInk = settingsNativeGlyph(tone)
62
+ export const hasControl = Boolean($slots && $slots.default)
63
+ const stacked = layout === 'stacked'
64
+ export const nativeRowClasses = (stacked
65
+ ? T.rowStacked
66
+ : `${T.row} ${navigates && symbol ? T.rowTall : ''} ${multiline ? T.rowMultiline : ''} ${navigates ? T.rowPressed : ''}`).replace(/\s+/g, ' ').trim()
67
+ export const nativeTextClasses = stacked ? T.rowTextStacked : multiline ? T.rowTextMultiline : T.rowText
68
+ export const nativeControlClasses = stacked ? T.rowControlStacked : multiline ? T.rowControlMultiline : T.rowControl
69
+ export const nativeLabelClasses = destructive ? T.rowLabelDestructive : T.rowLabel
70
+ export const nativeTileClasses = `${T.rowTile} ${tileFill} ${multiline ? T.rowTileMultiline : ''}`.trim()
48
71
  </script>
49
72
 
50
73
  <script client>
@@ -78,6 +101,8 @@ function isNamed(control) {
78
101
 
79
102
  /** Name the slot's first control after the row, unless it has a name. */
80
103
  function nameControl() {
104
+ // A native host has no elements to query: its controls carry their own names.
105
+ if ({{ $native }}) return null
81
106
  const row = rowRef()
82
107
  const slot = row ? row.querySelector('.stx-settings-row-control') : null
83
108
  const control = slot ? slot.querySelector(CONTROLS) : null
@@ -94,6 +119,43 @@ onMount(() => {
94
119
  defineExpose({ labelId, descriptionId, nameControl })
95
120
  </script>
96
121
 
122
+ @if($native)
123
+ <div class="flex-col {{ className }}">
124
+ <div data-settings-row-rule class="{{ T.rowRule }} hidden"></div>
125
+ <div
126
+ @if(navigates)data-native="Pressable"@endif
127
+ ref="row"
128
+ id="{{ rowId }}"
129
+ data-settings-row
130
+ @if(setting)data-setting="{{ setting }}"@endif
131
+ data-label="{{ label }}"
132
+ :data-label="heading()"
133
+ data-keywords="{{ keywords }}"
134
+ data-layout="{{ layout }}"
135
+ @if(navigates)data-navigate="{{ to }}" role="button" aria-label="{{ label }}"@endif
136
+ @if(disabled)aria-disabled="true"@endif
137
+ :aria-disabled="isDisabled() ? 'true' : null"
138
+ class="{{ nativeRowClasses }}"
139
+ :class="{ '{{ T.rowDisabled }}': isDisabled() }"
140
+ >
141
+ @if(symbol)
142
+ <div class="{{ nativeTileClasses }}" data-settings-tile="{{ tone }}"><span data-native="Icon" symbol="{{ symbol }}" class="{{ T.rowGlyph }} {{ glyphInk }}"></span></div>
143
+ @endif
144
+ {{-- Divs hold views and spans are words: a span around spans is read as one run of text. --}}
145
+ <div class="{{ nativeTextClasses }}">
146
+ <span :text="heading()" class="{{ nativeLabelClasses }}" @if(!multiline)numberOfLines="1"@endif>{{ label }}</span>
147
+ <span :show="detail()" :text="detail()" class="{{ T.rowDescription }}">{{ description }}</span>
148
+ </div>
149
+ @if(hasControl)
150
+ <div class="{{ nativeControlClasses }}" data-settings-row-control><slot /></div>
151
+ @endif
152
+ @if(navigates)
153
+ <span :show="trailing()" :text="trailing()" class="{{ T.rowValue }}" numberOfLines="1">{{ value }}</span>
154
+ <span data-native="Icon" symbol="{{ chevron }}" class="{{ T.rowChevron }}"></span>
155
+ @endif
156
+ </div>
157
+ </div>
158
+ @else
97
159
  <div
98
160
  ref="row"
99
161
  id="{{ rowId }}"
@@ -125,6 +187,7 @@ defineExpose({ labelId, descriptionId, nameControl })
125
187
  <span class="stx-settings-row-chevron" aria-hidden="true"></span>
126
188
  @endif
127
189
  </div>
190
+ @endif
128
191
 
129
192
  <style data-native-exclude>
130
193
  :where(:root) {
@@ -1,19 +1,36 @@
1
1
  <script server>
2
+ import { SETTINGS_NATIVE } from './native-theme'
3
+
2
4
  /*
3
5
  * <SettingsSidebarGroup>: a run of sidebar items, set a little apart from the
4
6
  * next. System Settings gives its groups no headings; `label` is there for
5
7
  * the window that needs one.
8
+ *
9
+ * On a native host ($native) the gap above the group is a view of its own
10
+ * (`data-settings-group-gap`), which the window shows above every group but
11
+ * the first one showing: there is no sibling selector to do it.
6
12
  */
7
13
  export const label = $props.label || ''
8
14
  export const className = $props.className || ''
15
+ export const T = SETTINGS_NATIVE
9
16
  </script>
10
17
 
18
+ @if($native)
19
+ <div data-settings-group class="{{ T.group }} {{ className }}">
20
+ <div data-settings-group-gap class="{{ T.groupGap }} hidden"></div>
21
+ @if(label)
22
+ <span class="{{ T.groupLabel }}">{{ label }}</span>
23
+ @endif
24
+ <slot />
25
+ </div>
26
+ @else
11
27
  <div data-settings-group role="presentation" class="stx-settings-group {{ className }}">
12
28
  @if(label)
13
29
  <div class="stx-settings-group-label" role="presentation">{{ label }}</div>
14
30
  @endif
15
31
  <slot />
16
32
  </div>
33
+ @endif
17
34
 
18
35
  <style data-native-exclude>
19
36
  :where(:root) {