@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, 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) {
@@ -1,4 +1,6 @@
1
1
  <script server>
2
+ import { SETTINGS_NATIVE, SETTINGS_NATIVE_TONES, settingsNativeGlyph } from './native-theme'
3
+
2
4
  /*
3
5
  * <SettingsSidebarItem>: one row of the sidebar, opening the pane whose id it
4
6
  * carries. The icon is an Iconify class, drawn white on a rounded tile in one
@@ -6,6 +8,11 @@
6
8
  *
7
9
  * It only draws. The shell selects it, gives it its place in the tab order
8
10
  * and links it to its pane.
11
+ *
12
+ * On a native host ($native) the glyph is an SF Symbol, named by `symbol`
13
+ * (`gearshape.fill`): an Iconify class is CSS, which a native host has none
14
+ * of. `icon` stays the web's. The selected row is the blue pill, drawn from
15
+ * `aria-selected`, which the window sets on the row and on what is inside it.
9
16
  */
10
17
  const TONES = ['grey', 'blue', 'red', 'orange', 'yellow', 'green', 'indigo', 'purple', 'pink', 'ink']
11
18
  export const paneId = $props.id || ''
@@ -16,8 +23,33 @@ export const badge = $props.badge == null || $props.badge === false ? '' : Strin
16
23
  /* Words a search should find this item by, beyond its label. */
17
24
  export const keywords = $props.keywords || ''
18
25
  export const className = $props.className || ''
26
+ export const symbol = $props.symbol || ''
27
+ export const T = SETTINGS_NATIVE
28
+ export const tileFill = SETTINGS_NATIVE_TONES[tone]
29
+ export const glyphInk = settingsNativeGlyph(tone)
19
30
  </script>
20
31
 
32
+ @if($native)
33
+ <div
34
+ data-native="Pressable"
35
+ role="tab"
36
+ aria-selected="false"
37
+ aria-label="{{ label }}"
38
+ testID="settings-item-{{ paneId }}"
39
+ data-settings-item="{{ paneId }}"
40
+ data-label="{{ label }}"
41
+ data-keywords="{{ keywords }}"
42
+ class="{{ T.item }} {{ className }}"
43
+ >
44
+ @if(symbol)
45
+ <div class="{{ T.itemTile }} {{ tileFill }}" data-settings-tile="{{ tone }}"><span data-native="Icon" symbol="{{ symbol }}" class="{{ T.itemGlyph }} {{ glyphInk }}"></span></div>
46
+ @endif
47
+ <span class="{{ T.itemLabel }}" numberOfLines="1">{{ label }}</span>
48
+ @if(badge)
49
+ <span class="{{ T.itemBadge }}">{{ badge }}</span>
50
+ @endif
51
+ </div>
52
+ @else
21
53
  <button
22
54
  type="button"
23
55
  role="tab"
@@ -35,6 +67,7 @@ export const className = $props.className || ''
35
67
  <span class="stx-settings-item-badge">{{ badge }}</span>
36
68
  @endif
37
69
  </button>
70
+ @endif
38
71
 
39
72
  <style data-native-exclude>
40
73
  :where(:root) {
@@ -0,0 +1,143 @@
1
+ <script server>
2
+ import { SETTINGS_NATIVE } from './native-theme'
3
+ import { settingsUpdateView } from './update'
4
+
5
+ /*
6
+ * <SettingsUpdateRow>: the row every app that updates itself needs. The app
7
+ * and its version, a sentence about where the update stands, and the one
8
+ * button that moves it on: Check Now, Download and Install (with its
9
+ * progress), or Restart to Update.
10
+ *
11
+ * <SettingsGroup header="Software Update">
12
+ * <SettingsUpdateRow appName="Library" :status="status()"
13
+ * @check="craft.updater.check()" @install="craft.updater.install()"
14
+ * @relaunch="craft.updater.relaunch()" />
15
+ * </SettingsGroup>
16
+ *
17
+ * `status` is what the updater reports (`craft.updater`'s `UpdateStatus`, or
18
+ * a web app's own of the same shape). The row does nothing on its own: it
19
+ * says what the status says and emits `check`, `install` or `relaunch`. What
20
+ * it says for each state is `settingsUpdateView` in ./update.
21
+ *
22
+ * It is a <SettingsRow> holding <Button appearance="mac">, so it is the same
23
+ * row on the web and on a native host, and the window's search finds it
24
+ * (`setting`, default `software-update`).
25
+ */
26
+ export const appName = $props.appName || ''
27
+ export const status = $props.status && typeof $props.status === 'object' ? $props.status : null
28
+ export const setting = $props.setting || 'software-update'
29
+ export const keywords = Array.isArray($props.keywords) ? $props.keywords.join(' ') : ($props.keywords || 'update version upgrade release')
30
+ export const className = $props.className || ''
31
+ export const served = settingsUpdateView(status, appName)
32
+ export const progressClasses = $native ? SETTINGS_NATIVE.updateProgress : 'stx-settings-update-progress'
33
+ </script>
34
+
35
+ <script client>
36
+ import { settingsUpdateView } from './update'
37
+
38
+ const emit = defineEmits(['check', 'install', 'relaunch'])
39
+ const current = useReactiveProp('status', {{ status }})
40
+ const name = useReactiveProp('appName', {{ appName }})
41
+ const view = derived(() => settingsUpdateView(current(), name()))
42
+
43
+ function act(action) {
44
+ // The status may have moved on since the button was drawn.
45
+ if (view().action === action && !view().busy) emit(action)
46
+ }
47
+
48
+ defineExpose({ view })
49
+ </script>
50
+
51
+ <SettingsRow
52
+ label="{{ served.title }}"
53
+ :label="view().title"
54
+ description="{{ served.sentence }}"
55
+ :description="view().sentence"
56
+ setting="{{ setting }}"
57
+ keywords="{{ keywords }}"
58
+ multiline
59
+ className="{{ className }}"
60
+ >
61
+ <span :show="view().progress" :text="view().progress" class="{{ progressClasses }}" data-settings-update-progress>{{ served.progress }}</span>
62
+ <Button :if="view().action === 'check'" appearance="mac" :label="view().actionLabel" :loading="view().busy" @click="act('check')" />
63
+ <Button :if="view().action === 'install'" appearance="mac" variant="primary" :label="view().actionLabel" :loading="view().busy" @click="act('install')" />
64
+ <Button :if="view().action === 'relaunch'" appearance="mac" variant="primary" :label="view().actionLabel" @click="act('relaunch')" />
65
+ </SettingsRow>
66
+
67
+ <style data-native-exclude>
68
+ :where(:root) {
69
+ --stx-mac-font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI Variable Text', 'Segoe UI', system-ui, Roboto, 'Helvetica Neue', sans-serif;
70
+ --stx-mac-font-size: 13px;
71
+ --stx-mac-font-size-small: 11px;
72
+ --stx-mac-hairline: 0.5px;
73
+ --stx-mac-focus-ring: 0 0 0 3px color-mix(in srgb, var(--stx-mac-accent) 35%, transparent);
74
+ --stx-mac-card-radius: 12px;
75
+ --stx-mac-control-radius: 6px;
76
+ --stx-mac-row-height: 38px;
77
+ --stx-mac-row-inset: 10px;
78
+ --stx-mac-sidebar-width: 226px;
79
+ --stx-mac-accent: var(--stx-accent, rgb(0, 122, 255));
80
+ --stx-mac-accent-ink: #ffffff;
81
+ --stx-mac-ink: rgba(0, 0, 0, 0.85);
82
+ --stx-mac-ink-secondary: rgba(0, 0, 0, 0.5);
83
+ --stx-mac-ink-tertiary: rgba(0, 0, 0, 0.26);
84
+ --stx-mac-window: #ffffff;
85
+ --stx-mac-sidebar: #f2f1f0;
86
+ --stx-mac-card: rgba(0, 0, 0, 0.04);
87
+ --stx-mac-separator: rgba(0, 0, 0, 0.1);
88
+ --stx-mac-hover: rgba(0, 0, 0, 0.05);
89
+ --stx-mac-selection-inactive: rgba(0, 0, 0, 0.08);
90
+ --stx-mac-well: rgba(0, 0, 0, 0.07);
91
+ --stx-mac-control: #ffffff;
92
+ --stx-mac-control-line: rgba(0, 0, 0, 0.12);
93
+ --stx-mac-control-shadow: 0 0.5px 1.5px rgba(0, 0, 0, 0.14), 0 0 0 0.5px rgba(0, 0, 0, 0.08);
94
+ --stx-mac-switch-on: #34c759;
95
+ --stx-mac-knob: #ffffff;
96
+ --stx-mac-danger: #ff3b30;
97
+ }
98
+ :where(.dark) {
99
+ --stx-mac-accent: var(--stx-accent, #0a84ff);
100
+ --stx-mac-accent-ink: #ffffff;
101
+ --stx-mac-ink: rgba(255, 255, 255, 0.85);
102
+ --stx-mac-ink-secondary: rgba(255, 255, 255, 0.55);
103
+ --stx-mac-ink-tertiary: rgba(255, 255, 255, 0.25);
104
+ --stx-mac-window: #1e1e1e;
105
+ --stx-mac-sidebar: #2a2a2a;
106
+ --stx-mac-card: rgba(255, 255, 255, 0.05);
107
+ --stx-mac-separator: rgba(255, 255, 255, 0.1);
108
+ --stx-mac-hover: rgba(255, 255, 255, 0.06);
109
+ --stx-mac-selection-inactive: rgba(255, 255, 255, 0.1);
110
+ --stx-mac-well: rgba(255, 255, 255, 0.1);
111
+ --stx-mac-control: rgba(255, 255, 255, 0.14);
112
+ --stx-mac-control-line: rgba(255, 255, 255, 0.06);
113
+ --stx-mac-control-shadow: 0 0.5px 1.5px rgba(0, 0, 0, 0.4), inset 0 0.5px 0 rgba(255, 255, 255, 0.12);
114
+ --stx-mac-switch-on: #30d158;
115
+ --stx-mac-knob: #ffffff;
116
+ --stx-mac-danger: #ff453a;
117
+ }
118
+ @media (max-resolution: 1.5dppx) {
119
+ :where(:root) {
120
+ --stx-mac-hairline: 1px;
121
+ }
122
+ }
123
+ @media (prefers-contrast: more) {
124
+ :where(:root) {
125
+ --stx-mac-separator: rgba(0, 0, 0, 0.4);
126
+ --stx-mac-control-line: rgba(0, 0, 0, 0.5);
127
+ --stx-mac-ink-secondary: rgba(0, 0, 0, 0.75);
128
+ --stx-mac-hairline: 1px;
129
+ }
130
+ :where(.dark) {
131
+ --stx-mac-separator: rgba(255, 255, 255, 0.45);
132
+ --stx-mac-control-line: rgba(255, 255, 255, 0.5);
133
+ --stx-mac-ink-secondary: rgba(255, 255, 255, 0.8);
134
+ }
135
+ }
136
+
137
+ .stx-settings-update-progress {
138
+ color: var(--stx-mac-ink-secondary);
139
+ font-size: var(--stx-mac-font-size-small);
140
+ font-variant-numeric: tabular-nums;
141
+ letter-spacing: 0;
142
+ }
143
+ </style>
@@ -1,4 +1,6 @@
1
1
  <script server>
2
+ import { SETTINGS_NATIVE, SETTINGS_NATIVE_SYMBOLS } from './native-theme'
3
+
2
4
  export const title = $props.title || 'Settings'
3
5
  export const pane = $props.pane || ''
4
6
  export const searchable = $bool($props.searchable, true)
@@ -21,6 +23,19 @@ export const rootStyle = [
21
23
  sidebarWidth > 0 ? `--stx-settings-sidebar-width: ${sidebarWidth}px` : '',
22
24
  height ? `--stx-settings-height: ${height}` : '',
23
25
  ].filter(Boolean).join('; ')
26
+
27
+ /*
28
+ * On a native host ($native) the window is two columns of the host's own
29
+ * views, drawn from the class lists in ./native-theme: the sidebar on the
30
+ * system's sidebar material with the system's search field, and the detail
31
+ * column under back, forward and the pane's name. The window fills what it is
32
+ * given, so `presentation` and `height` are the window's own business there.
33
+ */
34
+ export const T = SETTINGS_NATIVE
35
+ export const SYMBOLS = SETTINGS_NATIVE_SYMBOLS
36
+ export const nativeSidebarWidth = sidebarWidth > 0 ? sidebarWidth : SETTINGS_NATIVE.sidebarWidth
37
+ export const hasAccount = Boolean($slots && $slots.account)
38
+ export const wash = SETTINGS_NATIVE.rowWash
24
39
  </script>
25
40
 
26
41
  <script client>
@@ -29,11 +44,14 @@ export const rootStyle = [
29
44
  * items under a search field, and beside it the open pane under a toolbar
30
45
  * with back, forward and the pane's name.
31
46
  *
32
- * What it decides is in ./core and what it does to the page in ./view; this
33
- * is the wiring. The items, panes and rows are other components, found by the
47
+ * What it decides is in ./core. What it does to the page is in ./view, and
48
+ * what it does to a native host's tree of views in ./native; this is the
49
+ * wiring. The items, panes and rows are other components, found by the
34
50
  * attributes they carry.
35
51
  */
52
+ import { SettingsWindowTree } from './native'
36
53
  import { SettingsWindowView } from './view'
54
+ import { registerComponentApi } from '../../utils/component-api'
37
55
 
38
56
  const emit = defineEmits(['pane', 'search', 'navigate'])
39
57
 
@@ -43,22 +61,104 @@ const openPane = useModel('pane', { default: {{ pane }}, parse: asText })
43
61
  const rootRef = useRef('settings')
44
62
  let settings = null
45
63
 
64
+ // A native host has no DOM: the window is ./native's, and what the shell
65
+ // draws itself comes from these.
66
+ const native = {{ $native }}
67
+ const settingsId = {{ settingsId }}
68
+ const wash = {{ $native ? wash : null }}
69
+ const paneTitle = state('')
70
+ const canGoBack = state(false)
71
+ const canGoForward = state(false)
72
+ const query = state('')
73
+ const results = state([])
74
+ const noResults = state(false)
75
+ const searchFocus = state(false)
76
+ let stopCommands = null
77
+ let unregister = null
78
+
79
+ /** The app's own storage on a native host, which stx serves as localStorage. */
80
+ const nativeStorage = {
81
+ get: name => (typeof localStorage === 'undefined' ? null : localStorage.getItem(name)),
82
+ set: (name, value) => { if (typeof localStorage !== 'undefined') localStorage.setItem(name, value) },
83
+ }
84
+
85
+ function onSearchInput(event) {
86
+ if (settings) settings.search(asText(event.text ?? event.target?.value))
87
+ }
88
+
89
+ function chooseResult(position) {
90
+ if (settings) settings.chooseResult(position)
91
+ }
92
+
93
+ function back() {
94
+ if (settings) settings.back()
95
+ }
96
+
97
+ function forward() {
98
+ if (settings) settings.forward()
99
+ }
100
+
101
+ /*
102
+ * The AppKit host gives a field the keyboard when its `autoFocus` turns on,
103
+ * so focusing is turning it off and on again.
104
+ */
105
+ function focusSearch() {
106
+ if (!settings) return
107
+ if (!native) { settings.focusSearch(); return }
108
+ searchFocus.set(false)
109
+ setTimeout(() => searchFocus.set(true), 0)
110
+ }
111
+
112
+ const callbacks = {
113
+ onPane(detail) {
114
+ openPane.set(detail.id)
115
+ emit('pane', detail)
116
+ },
117
+ onSearch(detail) { emit('search', detail) },
118
+ onNavigate(detail) { emit('navigate', detail) },
119
+ }
120
+
46
121
  onMount(() => {
47
122
  const root = rootRef()
48
123
  if (!root) return
49
124
 
50
- settings = new SettingsWindowView(root, {
51
- pane: asText(openPane()),
52
- storageKey: {{ storageKey }},
53
- globalKeys: {{ globalKeys }},
54
- }, {
55
- onPane(detail) {
56
- openPane.set(detail.id)
57
- emit('pane', detail)
58
- },
59
- onSearch(detail) { emit('search', detail) },
60
- onNavigate(detail) { emit('navigate', detail) },
61
- })
125
+ if (native) {
126
+ const craftHost = typeof craft === 'undefined' ? null : craft
127
+ settings = new SettingsWindowTree(window.stx._host, root, {
128
+ pane: asText(openPane()),
129
+ storageKey: {{ storageKey }},
130
+ storage: nativeStorage,
131
+ wash: () => (craftHost && craftHost.appearance && craftHost.appearance.colorScheme() === 'dark' ? wash.dark : wash.light),
132
+ }, {
133
+ ...callbacks,
134
+ onState(next) {
135
+ batch(() => {
136
+ paneTitle.set(next.title)
137
+ canGoBack.set(next.canGoBack)
138
+ canGoForward.set(next.canGoForward)
139
+ query.set(next.query)
140
+ results.set(next.results)
141
+ noResults.set(next.empty)
142
+ })
143
+ },
144
+ })
145
+ // Escape in the search field clears it, as on the web: the host reports
146
+ // the key as a desktop command.
147
+ if (craftHost && craftHost.desktop && typeof craftHost.desktop.onCommand === 'function') {
148
+ stopCommands = craftHost.desktop.onCommand((id) => {
149
+ if (id === 'escape' && settings && query() !== '') settings.search('')
150
+ })
151
+ }
152
+ // No DOM to find the window in: componentApi(id) reads it from here.
153
+ unregister = registerComponentApi(settingsId, api)
154
+ }
155
+ else {
156
+ settings = new SettingsWindowView(root, {
157
+ pane: asText(openPane()),
158
+ storageKey: {{ storageKey }},
159
+ globalKeys: {{ globalKeys }},
160
+ }, callbacks)
161
+ }
62
162
 
63
163
  // The first run finds the pane the view just opened, which may be a stored
64
164
  // one; only a later change of the prop is an instruction.
@@ -69,20 +169,86 @@ onMount(() => {
69
169
  })
70
170
 
71
171
  onDestroy(() => {
172
+ if (stopCommands) stopCommands()
173
+ if (unregister) unregister()
174
+ stopCommands = null
175
+ unregister = null
72
176
  if (settings) settings.destroy()
73
177
  settings = null
74
178
  })
75
179
 
76
- defineExpose({
180
+ const api = {
77
181
  showPane: id => (settings ? settings.showPane(asText(id)) : false),
78
182
  revealSetting: id => (settings ? settings.revealSetting(asText(id)) : false),
79
- back: () => { if (settings) settings.back() },
80
- forward: () => { if (settings) settings.forward() },
81
- focusSearch: () => { if (settings) settings.focusSearch() },
183
+ back,
184
+ forward,
185
+ focusSearch,
82
186
  getPane: () => (settings ? settings.getPane() : ''),
83
- })
187
+ }
188
+
189
+ defineExpose(api)
84
190
  </script>
85
191
 
192
+ @if($native)
193
+ <div
194
+ ref="settings"
195
+ id="{{ settingsId }}"
196
+ data-stx-settings
197
+ data-presentation="{{ presentation }}"
198
+ role="group"
199
+ aria-label="{{ title }}"
200
+ class="{{ T.shell }} {{ className }}"
201
+ >
202
+ <div class="{{ T.sidebar }}" style="width: {{ nativeSidebarWidth }}px" material="{{ T.sidebarMaterial }}" data-settings-sidebar>
203
+ <div class="{{ T.sidebarTop }}">
204
+ @if(searchable)
205
+ <input
206
+ type="search"
207
+ class="{{ T.search }}"
208
+ placeholder="{{ searchPlaceholder }}"
209
+ aria-label="{{ searchPlaceholder }}"
210
+ selectTextOnFocus="true"
211
+ :value="query()"
212
+ :autoFocus="searchFocus()"
213
+ @input="onSearchInput($event)"
214
+ @blur="searchFocus.set(false)"
215
+ data-settings-search-input
216
+ >
217
+ @endif
218
+ </div>
219
+
220
+ <div data-native="ScrollView" class="{{ T.nav }}" data-settings-nav>
221
+ @if(hasAccount)
222
+ <div class="{{ T.account }}" data-settings-account><slot name="account" /></div>
223
+ @endif
224
+ <div class="{{ T.list }}" role="tablist" aria-label="{{ title }}" data-settings-list><slot name="sidebar" /></div>
225
+ <div class="{{ T.results }}" :show="results().length > 0" data-settings-results>
226
+ <div
227
+ data-native="Pressable"
228
+ :for="hit in results()"
229
+ :key="hit.position"
230
+ class="{{ T.result }}"
231
+ :data-settings-result="hit.position"
232
+ @click="chooseResult(hit.position)"
233
+ ><span class="{{ T.resultLabel }}" numberOfLines="1" :text="hit.label"></span><span class="{{ T.resultPane }}" numberOfLines="1" :text="hit.pane"></span></div>
234
+ </div>
235
+ <p class="{{ T.empty }}" :show="noResults()" data-settings-empty>No Results</p>
236
+ </div>
237
+ </div>
238
+
239
+ <div class="{{ T.detail }}" data-settings-detail>
240
+ <div class="{{ T.toolbar }}" data-settings-toolbar>
241
+ <div class="{{ T.history }}" role="group" aria-label="History">
242
+ <button data-native="Button" variant="toolbar" symbol="{{ SYMBOLS.back }}" iconOnly="true" class="{{ T.historyButton }}" aria-label="Back" :disabled="!canGoBack()" @click="back()" data-settings-back></button>
243
+ <button data-native="Button" variant="toolbar" symbol="{{ SYMBOLS.forward }}" iconOnly="true" class="{{ T.historyButton }}" aria-label="Forward" :disabled="!canGoForward()" @click="forward()" data-settings-forward></button>
244
+ </div>
245
+ <span class="{{ T.title }}" role="heading" numberOfLines="1" :text="paneTitle()" data-settings-title></span>
246
+ </div>
247
+
248
+ <div class="{{ T.body }}" data-settings-body><slot /></div>
249
+ </div>
250
+ </div>
251
+ @else
86
252
  <div
87
253
  ref="settings"
88
254
  id="{{ settingsId }}"
@@ -148,6 +314,7 @@ defineExpose({
148
314
  </div>
149
315
  </div>
150
316
  </div>
317
+ @endif
151
318
 
152
319
  <style data-native-exclude>
153
320
  :where(:root) {
@@ -1,3 +1,5 @@
1
+ import type { SettingsUpdateStatus } from './update'
2
+
1
3
  export * from './core'
2
4
  export { default as SettingsGroup } from './SettingsGroup.stx'
3
5
  export { default as SettingsPane } from './SettingsPane.stx'
@@ -5,7 +7,11 @@ export { default as SettingsPaneHeader } from './SettingsPaneHeader.stx'
5
7
  export { default as SettingsRow } from './SettingsRow.stx'
6
8
  export { default as SettingsSidebarGroup } from './SettingsSidebarGroup.stx'
7
9
  export { default as SettingsSidebarItem } from './SettingsSidebarItem.stx'
10
+ export { default as SettingsUpdateRow } from './SettingsUpdateRow.stx'
8
11
  export { default as SettingsWindow } from './SettingsWindow.stx'
12
+ export * from './native'
13
+ export * from './native-theme'
14
+ export * from './update'
9
15
  export * from './view'
10
16
 
11
17
  /** The colour of an icon tile, in the sidebar or leading a row. */
@@ -20,7 +26,7 @@ export interface SettingsWindowProps {
20
26
  searchable?: boolean
21
27
  /** Default `Search`. */
22
28
  searchPlaceholder?: string
23
- /** Remembers the last pane in local storage under `stx:settings:<key>`. */
29
+ /** Remembers the last pane under `stx:settings:<key>`: in local storage, which on a native host is the app's storage. */
24
30
  storageKey?: string
25
31
  /** `window` fills a titlebar-less window and clears its buttons; `sheet` is a rounded panel inside another window. Default `window`. */
26
32
  presentation?: 'window' | 'sheet'
@@ -42,8 +48,10 @@ export interface SettingsSidebarItemProps {
42
48
  /** The id of the pane this row opens. */
43
49
  id: string
44
50
  label: string
45
- /** An Iconify class, drawn white in the tile: `i-f7-gear-alt-fill`. */
51
+ /** An Iconify class, drawn white in the tile: `i-f7-gear-alt-fill`. The web's. */
46
52
  icon?: string
53
+ /** An SF Symbol name, drawn in the tile on a native host: `gearshape.fill`. */
54
+ symbol?: string
47
55
  /** Default `grey`. */
48
56
  tone?: SettingsTone
49
57
  /** A count at the trailing edge. */
@@ -80,8 +88,10 @@ export interface SettingsRowProps {
80
88
  label: string
81
89
  /** A second line under the label. */
82
90
  description?: string
83
- /** An Iconify class for a leading tile. */
91
+ /** An Iconify class for a leading tile. The web's. */
84
92
  icon?: string
93
+ /** An SF Symbol name for the leading tile on a native host. */
94
+ symbol?: string
85
95
  tone?: SettingsTone
86
96
  /** Names the setting, for `revealSetting(id)` and for its label's id. */
87
97
  setting?: string
@@ -103,9 +113,27 @@ export interface SettingsRowProps {
103
113
  }
104
114
 
105
115
  export interface SettingsPaneHeaderProps {
116
+ /** An Iconify class for the tile. The web's. */
106
117
  icon?: string
118
+ /** An SF Symbol name for the tile on a native host. */
119
+ symbol?: string
107
120
  tone?: SettingsTone
108
121
  title: string
109
122
  description?: string
110
123
  className?: string
111
124
  }
125
+
126
+ export interface SettingsUpdateRowProps {
127
+ /** The app's name, shown before its version. */
128
+ appName?: string
129
+ /** What the updater reports: `craft.updater`'s status, or a web app's own of the same shape. */
130
+ status?: Partial<SettingsUpdateStatus> | null
131
+ /** The row's id, for search and `revealSetting`. Default `software-update`. */
132
+ setting?: string
133
+ /** More words the search finds this row by. */
134
+ keywords?: string
135
+ className?: string
136
+ onCheck?: () => void
137
+ onInstall?: () => void
138
+ onRelaunch?: () => void
139
+ }