@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_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) {
@@ -89,6 +89,9 @@ function thumbClasses() {
89
89
  return `${thumbBase} ${pos} ${config.thumb}`.trim()
90
90
  }
91
91
 
92
+ // `variant="mac"` on Craft's AppKit host: the label at AppKit's 13pt beside the NSSwitch.
93
+ const macDesktop = {{ $native && mac }} && typeof craft !== 'undefined' && craft.platform === 'macos'
94
+
92
95
  defineExpose({ isChecked, toggle })
93
96
  </script>
94
97
 
@@ -96,7 +99,7 @@ defineExpose({ isChecked, toggle })
96
99
  {{-- On a native host the control is the platform's own switch (UISwitch,
97
100
  Android's Switch), at the end of its row as a settings row puts it. --}}
98
101
  <label class="flex-row items-center justify-between gap-3 {{ className }}">
99
- <span :if="currentLabel()" :text="currentLabel()" class="flex-1 text-[17px] text-[#000000] dark:text-[#ffffff]">{{ label }}</span>
102
+ <span :if="currentLabel()" :text="currentLabel()" class="flex-1 text-[17px] text-[#000000] dark:text-[#ffffff]" :class="{ 'text-[13px]': macDesktop }">{{ label }}</span>
100
103
  @if(name)
101
104
  <input
102
105
  type="hidden"
@@ -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
 
@@ -16,10 +16,27 @@ function find(target) {
16
16
  return null;
17
17
  }
18
18
  }
19
+ var REGISTRY = "__stxComponentApis";
20
+ function registry() {
21
+ const host = globalThis;
22
+ return host[REGISTRY] ?? (host[REGISTRY] = Object.create(null));
23
+ }
24
+ function registerComponentApi(id, api) {
25
+ if (!id)
26
+ return () => {};
27
+ const known = registry();
28
+ known[id] = api;
29
+ return () => {
30
+ if (known[id] === api)
31
+ delete known[id];
32
+ };
33
+ }
19
34
  function componentApi(target) {
20
35
  const element = find(target);
21
- if (!element || typeof element.closest !== "function")
22
- return null;
36
+ if (!element || typeof element.closest !== "function") {
37
+ const id = typeof target === "string" ? target.replace(/^#/, "") : "";
38
+ return id && id in registry() ? registry()[id] : null;
39
+ }
23
40
  if (element.__stx_exposed)
24
41
  return element.__stx_exposed;
25
42
  const around = element.closest(SCOPE);
@@ -32,5 +49,6 @@ function componentApi(target) {
32
49
  return null;
33
50
  }
34
51
  export {
35
- componentApi
52
+ componentApi,
53
+ registerComponentApi
36
54
  };