@stacksjs/components 0.2.890 → 0.2.891
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AppearancePicker-61r20jpp.stx → AppearancePicker-30fetv0a.stx} +45 -0
- package/dist/{Button-r8q6v9m3.stx → Button-ghdfqwg0.stx} +54 -1
- package/dist/{Checkbox-52mhrzkz.stx → Checkbox-355qsbwd.stx} +13 -3
- package/dist/{PasswordInput-z2g5ha65.stx → PasswordInput-hhq64qzr.stx} +15 -1
- package/dist/{SegmentedControl-7q0t8c9s.stx → SegmentedControl-b93n9n2v.stx} +9 -1
- package/dist/{Select-ygzchedx.stx → Select-p8mgxthn.stx} +13 -2
- package/dist/{SettingsGroup-dkae46k5.stx → SettingsGroup-g1hnxp1p.stx} +52 -0
- package/dist/{SettingsPane-jbd1gbdt.stx → SettingsPane-9svk1w3e.stx} +21 -2
- package/dist/{SettingsPaneHeader-f0cvkqs7.stx → SettingsPaneHeader-am42srhp.stx} +24 -0
- package/dist/{SettingsRow-4cxbsf1q.stx → SettingsRow-kgda3nv1.stx} +63 -0
- package/dist/{SettingsSidebarGroup-p2ygv5yy.stx → SettingsSidebarGroup-4ag5qjpw.stx} +17 -0
- package/dist/{SettingsSidebarItem-x8fsn3w5.stx → SettingsSidebarItem-ga2jxq53.stx} +33 -0
- package/dist/SettingsUpdateRow-ajpnqx8a.stx +143 -0
- package/dist/{SettingsWindow-mm490ymt.stx → SettingsWindow-586aps08.stx} +186 -19
- package/dist/{Switch-ga9ap8n8.stx → Switch-vd8k23sr.stx} +4 -1
- package/dist/{TextInput-m4a4kpfy.stx → TextInput-492d1c3n.stx} +15 -2
- package/dist/component-api/component-api.js +21 -3
- package/dist/index.js +24 -24
- package/dist/settings/settings.js +371 -15
- package/dist/ui/appearance-picker/AppearancePicker.d.ts +1 -0
- package/dist/ui/button/Button.d.ts +16 -0
- package/dist/ui/checkbox/Checkbox.d.ts +7 -0
- package/dist/ui/input/PasswordInput.d.ts +10 -0
- package/dist/ui/input/TextInput.d.ts +11 -0
- package/dist/ui/segmented-control/SegmentedControl.d.ts +7 -0
- package/dist/ui/settings/SettingsGroup.d.ts +5 -0
- package/dist/ui/settings/SettingsPane.d.ts +4 -0
- package/dist/ui/settings/SettingsPaneHeader.d.ts +10 -1
- package/dist/ui/settings/SettingsRow.d.ts +20 -1
- package/dist/ui/settings/SettingsSidebarGroup.d.ts +5 -0
- package/dist/ui/settings/SettingsSidebarItem.d.ts +11 -1
- package/dist/ui/settings/SettingsUpdateRow.d.ts +34 -0
- package/dist/ui/settings/SettingsWindow.d.ts +12 -0
- package/dist/ui/settings/index.d.ts +18 -0
- package/dist/ui/settings/native-theme.d.ts +130 -0
- package/dist/ui/settings/native.d.ts +51 -0
- package/dist/ui/settings/settings.d.ts +5 -2
- package/dist/ui/settings/update.d.ts +45 -0
- package/dist/utils/component-api.d.ts +2 -0
- package/package.json +3 -3
- package/src/ui/appearance-picker/AppearancePicker.stx +45 -0
- package/src/ui/appearance-picker/README.md +4 -0
- package/src/ui/button/Button.stx +54 -1
- package/src/ui/checkbox/Checkbox.stx +13 -3
- package/src/ui/input/PasswordInput.stx +15 -1
- package/src/ui/input/TextInput.stx +15 -2
- package/src/ui/segmented-control/SegmentedControl.stx +9 -1
- package/src/ui/select/Select.stx +13 -2
- package/src/ui/settings/README.md +210 -15
- package/src/ui/settings/SettingsGroup.stx +52 -0
- package/src/ui/settings/SettingsPane.stx +21 -2
- package/src/ui/settings/SettingsPaneHeader.stx +24 -0
- package/src/ui/settings/SettingsRow.stx +63 -0
- package/src/ui/settings/SettingsSidebarGroup.stx +17 -0
- package/src/ui/settings/SettingsSidebarItem.stx +33 -0
- package/src/ui/settings/SettingsUpdateRow.stx +143 -0
- package/src/ui/settings/SettingsWindow.stx +186 -19
- package/src/ui/settings/index.ts +31 -3
- package/src/ui/settings/native-theme.ts +169 -0
- package/src/ui/settings/native.ts +456 -0
- package/src/ui/settings/settings.ts +5 -2
- package/src/ui/settings/update.ts +119 -0
- package/src/ui/switch/Switch.stx +4 -1
- package/src/utils/component-api.ts +36 -3
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an update row says, without a template.
|
|
3
|
+
*
|
|
4
|
+
* An app that updates itself shows the same row everywhere: its name and
|
|
5
|
+
* version, a sentence about where the update stands, and the one button that
|
|
6
|
+
* moves it on. `settingsUpdateView` turns the status the host reports
|
|
7
|
+
* (`craft.updater`, or a web app's own updater) into those words, so the row
|
|
8
|
+
* is a function of the status and nothing else.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Where an update stands. The states `craft.updater` reports. */
|
|
12
|
+
export type SettingsUpdateState = 'unavailable' | 'idle' | 'checking' | 'current' | 'available' | 'downloading' | 'installing' | 'installed' | 'error'
|
|
13
|
+
|
|
14
|
+
/** The status an updater reports. The shape of `craft.updater`'s `UpdateStatus`. */
|
|
15
|
+
export interface SettingsUpdateStatus {
|
|
16
|
+
currentVersion: string
|
|
17
|
+
state: SettingsUpdateState
|
|
18
|
+
/** False when the app cannot replace itself. */
|
|
19
|
+
selfUpdating: boolean
|
|
20
|
+
/** Why `selfUpdating` is false, as a sentence. */
|
|
21
|
+
reason?: string
|
|
22
|
+
/** The update's version, from `available` on. */
|
|
23
|
+
version?: string
|
|
24
|
+
notes?: string
|
|
25
|
+
publishedAt?: string
|
|
26
|
+
/** 0 to 1 while downloading. */
|
|
27
|
+
progress?: number
|
|
28
|
+
error?: string
|
|
29
|
+
lastCheckedAt?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** What the row's button does: the event the row emits when it is pressed. */
|
|
33
|
+
export type SettingsUpdateAction = 'check' | 'install' | 'relaunch'
|
|
34
|
+
|
|
35
|
+
export interface SettingsUpdateView {
|
|
36
|
+
/** The app and the version it is: `Library 2.4`. */
|
|
37
|
+
title: string
|
|
38
|
+
/** Where the update stands, as a sentence. */
|
|
39
|
+
sentence: string
|
|
40
|
+
/** The button to show, or null for none. */
|
|
41
|
+
action: SettingsUpdateAction | null
|
|
42
|
+
actionLabel: string
|
|
43
|
+
/** Work is under way: the button is there and cannot be pressed. */
|
|
44
|
+
busy: boolean
|
|
45
|
+
/** `42%` while downloading, otherwise empty. */
|
|
46
|
+
progress: string
|
|
47
|
+
/** The sentence reports a failure. */
|
|
48
|
+
failed: boolean
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The words on the button for each action. */
|
|
52
|
+
export const SETTINGS_UPDATE_LABELS: Readonly<Record<SettingsUpdateAction, string>> = {
|
|
53
|
+
check: 'Check Now',
|
|
54
|
+
install: 'Download and Install',
|
|
55
|
+
relaunch: 'Restart to Update',
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function percent(progress: unknown): string {
|
|
59
|
+
const value = Number(progress)
|
|
60
|
+
if (!Number.isFinite(value))
|
|
61
|
+
return ''
|
|
62
|
+
return `${Math.round(Math.min(1, Math.max(0, value)) * 100)}%`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The row for `status`.
|
|
67
|
+
*
|
|
68
|
+
* No status yet (the host has not answered) is the app's name and nothing to
|
|
69
|
+
* press. An app that cannot replace itself (`selfUpdating: false`: a Mac App
|
|
70
|
+
* Store copy, a read-only volume) is never offered an install; it says why.
|
|
71
|
+
*/
|
|
72
|
+
export function settingsUpdateView(status: Partial<SettingsUpdateStatus> | null | undefined, appName = ''): SettingsUpdateView {
|
|
73
|
+
const name = String(appName || '').trim()
|
|
74
|
+
const version = String(status?.currentVersion || '').trim()
|
|
75
|
+
const title = [name, version].filter(Boolean).join(' ')
|
|
76
|
+
const view = (sentence: string, action: SettingsUpdateAction | null, extra: Partial<SettingsUpdateView> = {}): SettingsUpdateView => ({
|
|
77
|
+
title,
|
|
78
|
+
sentence,
|
|
79
|
+
action,
|
|
80
|
+
actionLabel: action ? SETTINGS_UPDATE_LABELS[action] : '',
|
|
81
|
+
busy: false,
|
|
82
|
+
progress: '',
|
|
83
|
+
failed: false,
|
|
84
|
+
...extra,
|
|
85
|
+
})
|
|
86
|
+
if (!status || typeof status.state !== 'string')
|
|
87
|
+
return view('', null)
|
|
88
|
+
|
|
89
|
+
const app = name || 'This app'
|
|
90
|
+
const next = String(status.version || '').trim()
|
|
91
|
+
const update = next ? `Version ${next}` : 'An update'
|
|
92
|
+
const canInstall = status.selfUpdating !== false
|
|
93
|
+
const why = String(status.reason || '').trim()
|
|
94
|
+
|
|
95
|
+
switch (status.state) {
|
|
96
|
+
case 'unavailable':
|
|
97
|
+
return view(why || `${app} cannot update itself.`, null)
|
|
98
|
+
case 'idle':
|
|
99
|
+
return view('Check for a newer version.', 'check')
|
|
100
|
+
case 'checking':
|
|
101
|
+
return view('Checking for updates...', 'check', { busy: true })
|
|
102
|
+
case 'current':
|
|
103
|
+
return view(`${app} is up to date.`, 'check')
|
|
104
|
+
case 'available':
|
|
105
|
+
return canInstall
|
|
106
|
+
? view(`${update} is available.`, 'install')
|
|
107
|
+
: view(`${update} is available. ${why || `${app} cannot update itself.`}`, 'check')
|
|
108
|
+
case 'downloading':
|
|
109
|
+
return view(`Downloading ${next ? `version ${next}` : 'the update'}...`, 'install', { busy: true, progress: percent(status.progress) })
|
|
110
|
+
case 'installing':
|
|
111
|
+
return view(`Installing ${next ? `version ${next}` : 'the update'}...`, 'install', { busy: true })
|
|
112
|
+
case 'installed':
|
|
113
|
+
return view(`${update} is installed. Restart ${app} to finish updating.`, 'relaunch')
|
|
114
|
+
case 'error':
|
|
115
|
+
return view(String(status.error || '').trim() || 'The update could not be completed.', 'check', { failed: true })
|
|
116
|
+
default:
|
|
117
|
+
return view('', null)
|
|
118
|
+
}
|
|
119
|
+
}
|
package/src/ui/switch/Switch.stx
CHANGED
|
@@ -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"
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
* ```
|
|
16
16
|
*
|
|
17
17
|
* The target is the component's own element, or its id, or a selector, or any
|
|
18
|
-
* element around exactly one component.
|
|
18
|
+
* element around exactly one component. On a native screen, which has no
|
|
19
|
+
* elements, it is the id of a component that registered itself
|
|
20
|
+
* (`registerComponentApi`; `<SettingsWindow>` does). Null where there is nothing to find:
|
|
19
21
|
* on the server, before the component has mounted, or for an element that is
|
|
20
22
|
* not a component. A component mounts after the page's own script has run, so
|
|
21
23
|
* ask for its methods when they are needed, not at the top of the script.
|
|
@@ -46,14 +48,45 @@ function find(target: Element | string | null | undefined): Element | null {
|
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Where a component on a host with no DOM answers by id.
|
|
53
|
+
*
|
|
54
|
+
* A native screen (Craft's AppKit and phone hosts) has no document to find an
|
|
55
|
+
* element in, so a component that wants to be reached there registers what it
|
|
56
|
+
* exposes under its id, and `componentApi('settings')` reads it back. Kept on
|
|
57
|
+
* the global object, not in this module: the app imports this file from the
|
|
58
|
+
* built package and a component from its source, and the two must agree.
|
|
59
|
+
*/
|
|
60
|
+
const REGISTRY = '__stxComponentApis'
|
|
61
|
+
|
|
62
|
+
function registry(): Record<string, unknown> {
|
|
63
|
+
const host = globalThis as unknown as Record<string, Record<string, unknown> | undefined>
|
|
64
|
+
return host[REGISTRY] ?? (host[REGISTRY] = Object.create(null) as Record<string, unknown>)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Answer `componentApi(id)` with `api` on a host that has no DOM. Returns the undo. */
|
|
68
|
+
export function registerComponentApi(id: string, api: unknown): () => void {
|
|
69
|
+
if (!id)
|
|
70
|
+
return () => {}
|
|
71
|
+
const known = registry()
|
|
72
|
+
known[id] = api
|
|
73
|
+
return () => {
|
|
74
|
+
if (known[id] === api)
|
|
75
|
+
delete known[id]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
49
79
|
/** What a component exposes when nothing more precise is known: methods by name. */
|
|
50
80
|
// eslint-disable-next-line ts/no-explicit-any
|
|
51
81
|
export type ExposedMethods = Record<string, (..._arguments: any[]) => any>
|
|
52
82
|
|
|
53
83
|
export function componentApi<T = ExposedMethods>(target: Element | string | null | undefined): T | null {
|
|
54
84
|
const element = find(target) as ExposingElement | null
|
|
55
|
-
if (!element || typeof element.closest !== 'function')
|
|
56
|
-
|
|
85
|
+
if (!element || typeof element.closest !== 'function') {
|
|
86
|
+
// No element to find it on: a native screen, where it registered by id.
|
|
87
|
+
const id = typeof target === 'string' ? target.replace(/^#/, '') : ''
|
|
88
|
+
return id && id in registry() ? registry()[id] as T : null
|
|
89
|
+
}
|
|
57
90
|
|
|
58
91
|
if (element.__stx_exposed)
|
|
59
92
|
return element.__stx_exposed as T
|