@getcortexlabs/mavis-core 0.1.0-alpha.4 → 0.1.0-alpha.6
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/README.md +2 -2
- package/dist/app-icons.d.ts +27 -0
- package/dist/app-icons.d.ts.map +1 -0
- package/dist/app-icons.js +42 -0
- package/dist/app-icons.js.map +1 -0
- package/dist/capabilities.d.ts +119 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +144 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/combobox.d.ts +42 -0
- package/dist/combobox.d.ts.map +1 -0
- package/dist/combobox.js +159 -0
- package/dist/combobox.js.map +1 -0
- package/dist/contracts.d.ts +1261 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +249 -0
- package/dist/contracts.js.map +1 -0
- package/dist/date.d.ts +96 -0
- package/dist/date.d.ts.map +1 -0
- package/dist/date.js +235 -0
- package/dist/date.js.map +1 -0
- package/dist/experimental-playback.d.ts +63 -0
- package/dist/experimental-playback.d.ts.map +1 -0
- package/dist/experimental-playback.js +46 -0
- package/dist/experimental-playback.js.map +1 -0
- package/dist/experimental-regions.d.ts +154 -0
- package/dist/experimental-regions.d.ts.map +1 -0
- package/dist/experimental-regions.js +440 -0
- package/dist/experimental-regions.js.map +1 -0
- package/dist/experimental.d.ts +42 -3
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +200 -30
- package/dist/experimental.js.map +1 -1
- package/dist/files.d.ts +87 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +328 -0
- package/dist/files.js.map +1 -0
- package/dist/form.d.ts +39 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +170 -0
- package/dist/form.js.map +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/link.d.ts +12 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +19 -0
- package/dist/link.js.map +1 -0
- package/dist/motion.d.ts +29 -4
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +55 -3
- package/dist/motion.js.map +1 -1
- package/dist/navigation.d.ts +22 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +54 -0
- package/dist/navigation.js.map +1 -0
- package/dist/responsive.d.ts +18 -0
- package/dist/responsive.d.ts.map +1 -0
- package/dist/responsive.js +35 -0
- package/dist/responsive.js.map +1 -0
- package/dist/theme/themes.js +3 -3
- package/dist/theme/themes.js.map +1 -1
- package/dist/theme/types.d.ts +12 -3
- package/dist/theme/types.d.ts.map +1 -1
- package/dist/vue/combobox.d.ts +155 -0
- package/dist/vue/combobox.d.ts.map +1 -0
- package/dist/vue/combobox.js +195 -0
- package/dist/vue/combobox.js.map +1 -0
- package/dist/vue/component-props.d.ts +2176 -0
- package/dist/vue/component-props.d.ts.map +1 -0
- package/dist/vue/component-props.js +18 -0
- package/dist/vue/component-props.js.map +1 -0
- package/dist/vue/contracts.d.ts +18 -0
- package/dist/vue/contracts.d.ts.map +1 -0
- package/dist/vue/contracts.js +24 -0
- package/dist/vue/contracts.js.map +1 -0
- package/dist/vue/date-calendar.d.ts +64 -0
- package/dist/vue/date-calendar.d.ts.map +1 -0
- package/dist/vue/date-calendar.js +65 -0
- package/dist/vue/date-calendar.js.map +1 -0
- package/dist/vue/date-picker.d.ts +965 -0
- package/dist/vue/date-picker.d.ts.map +1 -0
- package/dist/vue/date-picker.js +341 -0
- package/dist/vue/date-picker.js.map +1 -0
- package/dist/vue/date-props.d.ts +263 -0
- package/dist/vue/date-props.d.ts.map +1 -0
- package/dist/vue/date-props.js +77 -0
- package/dist/vue/date-props.js.map +1 -0
- package/dist/vue/files.d.ts +53 -0
- package/dist/vue/files.d.ts.map +1 -0
- package/dist/vue/files.js +40 -0
- package/dist/vue/files.js.map +1 -0
- package/dist/vue/forms.d.ts +4 -0
- package/dist/vue/forms.d.ts.map +1 -0
- package/dist/vue/forms.js +15 -0
- package/dist/vue/forms.js.map +1 -0
- package/dist/vue/global-components.d.ts +40 -2
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +15 -3
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +12 -2
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/inline-content.d.ts +3 -1
- package/dist/vue/inline-content.d.ts.map +1 -1
- package/dist/vue/layout-context.d.ts +4 -2
- package/dist/vue/layout-context.d.ts.map +1 -1
- package/dist/vue/layout-context.js +7 -2
- package/dist/vue/layout-context.js.map +1 -1
- package/dist/vue/props.d.ts +1392 -496
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +39 -116
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/reveal-state.d.ts +18 -0
- package/dist/vue/reveal-state.d.ts.map +1 -0
- package/dist/vue/reveal-state.js +76 -0
- package/dist/vue/reveal-state.js.map +1 -0
- package/dist/vue/theme.d.ts +42 -0
- package/dist/vue/theme.d.ts.map +1 -1
- package/dist/vue/workflow-props.d.ts +110 -0
- package/dist/vue/workflow-props.d.ts.map +1 -0
- package/dist/vue/workflow-props.js +37 -0
- package/dist/vue/workflow-props.js.map +1 -0
- package/dist/vue/workflows.d.ts +267 -0
- package/dist/vue/workflows.d.ts.map +1 -0
- package/dist/vue/workflows.js +200 -0
- package/dist/vue/workflows.js.map +1 -0
- package/package.json +1 -1
- package/src/app-icons.ts +57 -0
- package/src/capabilities.ts +147 -0
- package/src/combobox.ts +198 -0
- package/src/contracts.ts +305 -0
- package/src/date.ts +280 -0
- package/src/experimental-playback.ts +115 -0
- package/src/experimental-regions.ts +614 -0
- package/src/experimental.ts +239 -25
- package/src/files.ts +408 -0
- package/src/form.ts +190 -0
- package/src/index.ts +23 -1
- package/src/link.ts +28 -0
- package/src/motion.ts +61 -3
- package/src/navigation.ts +61 -0
- package/src/responsive.ts +61 -0
- package/src/theme/themes.ts +3 -3
- package/src/theme/types.ts +13 -1
- package/src/vue/combobox.ts +238 -0
- package/src/vue/component-props.ts +24 -0
- package/src/vue/contracts.ts +39 -0
- package/src/vue/date-calendar.ts +76 -0
- package/src/vue/date-picker.ts +414 -0
- package/src/vue/date-props.ts +84 -0
- package/src/vue/files.ts +53 -0
- package/src/vue/forms.ts +20 -0
- package/src/vue/global-components.ts +49 -3
- package/src/vue/index.ts +19 -3
- package/src/vue/layout-context.ts +10 -3
- package/src/vue/props.ts +57 -127
- package/src/vue/reveal-state.ts +83 -0
- package/src/vue/workflow-props.ts +41 -0
- package/src/vue/workflows.ts +257 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/** Source capabilities, not a promise that every feature is in the last npm release. */
|
|
2
|
+
export const componentNames = [
|
|
3
|
+
'MScreen',
|
|
4
|
+
'MRow',
|
|
5
|
+
'MColumn',
|
|
6
|
+
'MStack',
|
|
7
|
+
'MLink',
|
|
8
|
+
'MBox',
|
|
9
|
+
'MCard',
|
|
10
|
+
'MText',
|
|
11
|
+
'MSpan',
|
|
12
|
+
'MThemeProvider',
|
|
13
|
+
'MIcon',
|
|
14
|
+
'MButton',
|
|
15
|
+
'MInput',
|
|
16
|
+
'MSlider',
|
|
17
|
+
'MSwitch',
|
|
18
|
+
'MCheckbox',
|
|
19
|
+
'MRadioGroup',
|
|
20
|
+
'MSelect',
|
|
21
|
+
'MSheet',
|
|
22
|
+
'MDialog',
|
|
23
|
+
'MToast',
|
|
24
|
+
'MTabs',
|
|
25
|
+
'MChip',
|
|
26
|
+
'MEmptyState',
|
|
27
|
+
'MAccordion',
|
|
28
|
+
'MSegmentedControl',
|
|
29
|
+
'MSkeleton',
|
|
30
|
+
'MProgress',
|
|
31
|
+
'MAlert',
|
|
32
|
+
'MAvatar',
|
|
33
|
+
'MBadge',
|
|
34
|
+
'MListItem',
|
|
35
|
+
'MSeparator',
|
|
36
|
+
'MReveal',
|
|
37
|
+
'MDatePicker',
|
|
38
|
+
'MDateRangePicker',
|
|
39
|
+
'MCombobox',
|
|
40
|
+
'MFilePicker',
|
|
41
|
+
'MFormGroup',
|
|
42
|
+
'MFormErrors',
|
|
43
|
+
'MSteps',
|
|
44
|
+
'MPagination',
|
|
45
|
+
] as const
|
|
46
|
+
export type ComponentName = (typeof componentNames)[number]
|
|
47
|
+
export type CapabilityStatus = 'experimental' | 'planned' | 'unsupported' | 'unverified'
|
|
48
|
+
|
|
49
|
+
export const targetCapabilities = {
|
|
50
|
+
version: 1,
|
|
51
|
+
source: 'repository',
|
|
52
|
+
publishedBaseline: '0.1.0-alpha.5',
|
|
53
|
+
targets: [
|
|
54
|
+
{
|
|
55
|
+
id: 'vue-web',
|
|
56
|
+
framework: 'vue',
|
|
57
|
+
renderer: 'dom',
|
|
58
|
+
status: 'experimental',
|
|
59
|
+
components: componentNames,
|
|
60
|
+
rendering: {
|
|
61
|
+
client: 'experimental',
|
|
62
|
+
serverImport: 'experimental',
|
|
63
|
+
serverHTML: 'experimental',
|
|
64
|
+
hydration: 'experimental',
|
|
65
|
+
ssg: 'experimental',
|
|
66
|
+
streaming: 'unverified',
|
|
67
|
+
rsc: 'unsupported',
|
|
68
|
+
},
|
|
69
|
+
motion: { engine: 'jolt', minimum: '0.1.0-rc.8', start: 'client-mount' },
|
|
70
|
+
ssr: {
|
|
71
|
+
availability: '0.1.0-alpha.5',
|
|
72
|
+
host: 'nuxt',
|
|
73
|
+
hostVersion: '4.6.3',
|
|
74
|
+
vueVersion: '3.5.44',
|
|
75
|
+
nodeVersion: '22.23.3',
|
|
76
|
+
preset: 'node-server',
|
|
77
|
+
deferred: [
|
|
78
|
+
'sheet-dialog-presentation',
|
|
79
|
+
'select-popup',
|
|
80
|
+
'date-calendar',
|
|
81
|
+
'combobox-results',
|
|
82
|
+
'file-selection',
|
|
83
|
+
'toast-presentation',
|
|
84
|
+
'motion-measurement',
|
|
85
|
+
],
|
|
86
|
+
preHydrationEditors: [
|
|
87
|
+
'MInput',
|
|
88
|
+
'MCheckbox',
|
|
89
|
+
'MRadioGroup',
|
|
90
|
+
'MSlider',
|
|
91
|
+
'MDatePicker',
|
|
92
|
+
'MDateRangePicker',
|
|
93
|
+
'MCombobox',
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: 'vue-nativescript',
|
|
99
|
+
framework: 'vue',
|
|
100
|
+
renderer: 'nativescript',
|
|
101
|
+
status: 'experimental',
|
|
102
|
+
components: componentNames,
|
|
103
|
+
rendering: {
|
|
104
|
+
client: 'experimental',
|
|
105
|
+
serverImport: 'unsupported',
|
|
106
|
+
serverHTML: 'unsupported',
|
|
107
|
+
hydration: 'unsupported',
|
|
108
|
+
ssg: 'unsupported',
|
|
109
|
+
streaming: 'unsupported',
|
|
110
|
+
rsc: 'unsupported',
|
|
111
|
+
},
|
|
112
|
+
motion: { engine: 'jolt', minimum: '0.1.0-rc.8', start: 'native-loaded' },
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
planned: [
|
|
116
|
+
{ id: 'react-web', issue: 145 },
|
|
117
|
+
{ id: 'next', issue: 159 },
|
|
118
|
+
{ id: 'angular-web', issue: 152 },
|
|
119
|
+
{ id: 'svelte-web', issue: 153 },
|
|
120
|
+
{ id: 'solid-web', issue: 154 },
|
|
121
|
+
{ id: 'react-nativescript', issue: 35 },
|
|
122
|
+
{ id: 'angular-nativescript', issue: 36 },
|
|
123
|
+
{ id: 'svelte-nativescript', issue: 37 },
|
|
124
|
+
{ id: 'solid-nativescript', issue: 38 },
|
|
125
|
+
{ id: 'typescript-nativescript', issue: 39 },
|
|
126
|
+
],
|
|
127
|
+
research: [
|
|
128
|
+
{ id: 'react-native', issue: 40 },
|
|
129
|
+
{ id: 'flutter', issue: 41 },
|
|
130
|
+
{ id: 'swiftui-compose', issue: 42 },
|
|
131
|
+
],
|
|
132
|
+
} as const
|
|
133
|
+
|
|
134
|
+
export const themeContract = {
|
|
135
|
+
version: 1,
|
|
136
|
+
units: {
|
|
137
|
+
layout: { web: 'css-px', nativescript: 'dip' },
|
|
138
|
+
dimension: ['layout-number', 'percent', 'auto'],
|
|
139
|
+
fontSize: 'layout',
|
|
140
|
+
lineHeight: 'ratio',
|
|
141
|
+
letterSpacing: 'em',
|
|
142
|
+
pressScale: 'multiplier',
|
|
143
|
+
},
|
|
144
|
+
tokens: ['colors', 'space', 'radius', 'typography', 'components', 'elevation', 'motion'],
|
|
145
|
+
fontFamily: ['system', 'shared-family-name', 'platform-family-record'],
|
|
146
|
+
ownership: 'application-or-controlled-scope',
|
|
147
|
+
} as const
|
package/src/combobox.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { choiceKey, validateChoices, type ChoiceOption, type ChoiceValue } from './choice.js'
|
|
2
|
+
|
|
3
|
+
/** The application owns networking, authentication and cancellation primitives. */
|
|
4
|
+
export interface ComboboxSearchContext {
|
|
5
|
+
readonly requestId: number
|
|
6
|
+
readonly limit: number
|
|
7
|
+
/** Register fetch.abort(), a timer cleanup, or another host cancellation callback. */
|
|
8
|
+
onCancel(cleanup: () => void): void
|
|
9
|
+
}
|
|
10
|
+
export type ComboboxSearch = (
|
|
11
|
+
query: string,
|
|
12
|
+
context: ComboboxSearchContext,
|
|
13
|
+
) => Promise<readonly ChoiceOption[]>
|
|
14
|
+
export interface ComboboxSnapshot {
|
|
15
|
+
query: string
|
|
16
|
+
options: readonly ChoiceOption[]
|
|
17
|
+
}
|
|
18
|
+
export type ComboboxSearchStatus = 'idle' | 'debouncing' | 'loading' | 'success' | 'empty' | 'error'
|
|
19
|
+
export interface ComboboxSearchState {
|
|
20
|
+
readonly query: string
|
|
21
|
+
readonly status: ComboboxSearchStatus
|
|
22
|
+
readonly options: readonly ChoiceOption[]
|
|
23
|
+
readonly limited: boolean
|
|
24
|
+
}
|
|
25
|
+
export interface ComboboxSearchOptions {
|
|
26
|
+
search: ComboboxSearch
|
|
27
|
+
debounce?: number
|
|
28
|
+
minQueryLength?: number
|
|
29
|
+
maxResults?: number
|
|
30
|
+
initialResults?: ComboboxSnapshot
|
|
31
|
+
onChange?: (state: ComboboxSearchState) => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function validateComboboxPolicy(
|
|
35
|
+
debounce: number,
|
|
36
|
+
minQueryLength: number,
|
|
37
|
+
maxResults: number,
|
|
38
|
+
) {
|
|
39
|
+
if (!Number.isInteger(debounce) || debounce < 0 || debounce > 60000)
|
|
40
|
+
throw new RangeError('Combobox debounce must be an integer from 0 to 60000 milliseconds.')
|
|
41
|
+
if (!Number.isInteger(minQueryLength) || minQueryLength < 0 || minQueryLength > 1000)
|
|
42
|
+
throw new RangeError('Combobox minQueryLength must be an integer from 0 to 1000.')
|
|
43
|
+
if (!Number.isInteger(maxResults) || maxResults < 1 || maxResults > 100)
|
|
44
|
+
throw new RangeError('Combobox maxResults must be an integer from 1 to 100.')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A single bounded result page. No request starts at construction, including during SSR. */
|
|
48
|
+
export function createComboboxSearch(config: ComboboxSearchOptions) {
|
|
49
|
+
const debounce = config.debounce ?? 200
|
|
50
|
+
const minQueryLength = config.minQueryLength ?? 1
|
|
51
|
+
const maxResults = config.maxResults ?? 50
|
|
52
|
+
validateComboboxPolicy(debounce, minQueryLength, maxResults)
|
|
53
|
+
let generation = 0
|
|
54
|
+
let disposed = false
|
|
55
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
56
|
+
let cleanups: (() => void)[] = []
|
|
57
|
+
let cached: ComboboxSearchState | undefined
|
|
58
|
+
function result(query: string, options: readonly ChoiceOption[]): ComboboxSearchState {
|
|
59
|
+
if (!Array.isArray(options)) throw new TypeError('Combobox search must return an array.')
|
|
60
|
+
validateChoices(options, null)
|
|
61
|
+
return Object.freeze({
|
|
62
|
+
query,
|
|
63
|
+
status: options.length ? 'success' : 'empty',
|
|
64
|
+
options: Object.freeze(
|
|
65
|
+
options.slice(0, maxResults).map((option) => Object.freeze({ ...option })),
|
|
66
|
+
),
|
|
67
|
+
limited: options.length > maxResults,
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
let state: ComboboxSearchState = Object.freeze({
|
|
71
|
+
query: '',
|
|
72
|
+
status: 'idle',
|
|
73
|
+
options: [],
|
|
74
|
+
limited: false,
|
|
75
|
+
})
|
|
76
|
+
if (config.initialResults)
|
|
77
|
+
state = cached = result(config.initialResults.query, config.initialResults.options)
|
|
78
|
+
function publish(next: ComboboxSearchState) {
|
|
79
|
+
state = Object.freeze(next)
|
|
80
|
+
config.onChange?.(state)
|
|
81
|
+
}
|
|
82
|
+
function invalidate() {
|
|
83
|
+
generation++
|
|
84
|
+
clearTimeout(timer)
|
|
85
|
+
timer = undefined
|
|
86
|
+
const previous = cleanups
|
|
87
|
+
cleanups = []
|
|
88
|
+
// One host cleanup cannot prevent the remaining requests/resources from being cancelled.
|
|
89
|
+
for (const cleanup of previous) {
|
|
90
|
+
try {
|
|
91
|
+
cleanup()
|
|
92
|
+
} catch {
|
|
93
|
+
/* Host cancellation failures never revive a request. */
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function cancel() {
|
|
98
|
+
invalidate()
|
|
99
|
+
if (!disposed && (state.status === 'loading' || state.status === 'debouncing'))
|
|
100
|
+
publish({ query: state.query, status: 'idle', options: [], limited: false })
|
|
101
|
+
}
|
|
102
|
+
function request(query: string, force = false) {
|
|
103
|
+
if (disposed) return
|
|
104
|
+
invalidate()
|
|
105
|
+
if (!force && cached?.query === query) {
|
|
106
|
+
publish(cached)
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
if (query.trim().length < minQueryLength) {
|
|
110
|
+
publish({ query, status: 'idle', options: [], limited: false })
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
const identity = generation
|
|
114
|
+
publish({
|
|
115
|
+
query,
|
|
116
|
+
status: debounce && !force ? 'debouncing' : 'loading',
|
|
117
|
+
options: [],
|
|
118
|
+
limited: false,
|
|
119
|
+
})
|
|
120
|
+
const run = async () => {
|
|
121
|
+
timer = undefined
|
|
122
|
+
if (disposed || identity !== generation) return
|
|
123
|
+
publish({ query, status: 'loading', options: [], limited: false })
|
|
124
|
+
try {
|
|
125
|
+
const options = await config.search(query, {
|
|
126
|
+
requestId: identity,
|
|
127
|
+
limit: maxResults,
|
|
128
|
+
onCancel(cleanup) {
|
|
129
|
+
if (disposed || identity !== generation) cleanup()
|
|
130
|
+
else cleanups.push(cleanup)
|
|
131
|
+
},
|
|
132
|
+
})
|
|
133
|
+
if (disposed || identity !== generation) return
|
|
134
|
+
const next = result(query, options)
|
|
135
|
+
cleanups = []
|
|
136
|
+
cached = next
|
|
137
|
+
publish(next)
|
|
138
|
+
} catch {
|
|
139
|
+
if (disposed || identity !== generation) return
|
|
140
|
+
cleanups = []
|
|
141
|
+
publish({ query, status: 'error', options: [], limited: false })
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (debounce && !force) timer = setTimeout(() => void run(), debounce)
|
|
145
|
+
else void run()
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
get state() {
|
|
149
|
+
return state
|
|
150
|
+
},
|
|
151
|
+
request,
|
|
152
|
+
retry: () => request(state.query, true),
|
|
153
|
+
cancel,
|
|
154
|
+
dispose() {
|
|
155
|
+
if (disposed) return
|
|
156
|
+
disposed = true
|
|
157
|
+
invalidate()
|
|
158
|
+
cached = undefined
|
|
159
|
+
},
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Highlight identity survives a page replacement only while its enabled option remains. */
|
|
164
|
+
export function comboboxHighlight(
|
|
165
|
+
options: readonly ChoiceOption[],
|
|
166
|
+
previous?: string,
|
|
167
|
+
): string | undefined {
|
|
168
|
+
return options.some((option) => !option.disabled && choiceKey(option.value) === previous)
|
|
169
|
+
? previous
|
|
170
|
+
: undefined
|
|
171
|
+
}
|
|
172
|
+
export function comboboxMove(
|
|
173
|
+
options: readonly ChoiceOption[],
|
|
174
|
+
previous: string | undefined,
|
|
175
|
+
direction: 1 | -1,
|
|
176
|
+
) {
|
|
177
|
+
const available = options.filter((option) => !option.disabled)
|
|
178
|
+
if (!available.length) return undefined
|
|
179
|
+
const index = available.findIndex((option) => choiceKey(option.value) === previous)
|
|
180
|
+
const next =
|
|
181
|
+
index < 0
|
|
182
|
+
? direction === 1
|
|
183
|
+
? 0
|
|
184
|
+
: available.length - 1
|
|
185
|
+
: Math.max(0, Math.min(available.length - 1, index + direction))
|
|
186
|
+
return choiceKey(available[next]!.value)
|
|
187
|
+
}
|
|
188
|
+
export function comboboxSelected(
|
|
189
|
+
value: ChoiceValue | null,
|
|
190
|
+
options: readonly ChoiceOption[],
|
|
191
|
+
retained?: ChoiceOption | null,
|
|
192
|
+
): ChoiceOption | undefined {
|
|
193
|
+
if (value === null) return undefined
|
|
194
|
+
return (
|
|
195
|
+
options.find((option) => option.value === value) ??
|
|
196
|
+
(retained?.value === value ? retained : undefined)
|
|
197
|
+
)
|
|
198
|
+
}
|
package/src/contracts.ts
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import type { MotionSurface, MotionRegion } from './experimental.js'
|
|
2
|
+
import type { Dimension } from './layout.js'
|
|
3
|
+
import type { InputAction, InputHandle } from './input.js'
|
|
4
|
+
import type { IconName } from './icon.js'
|
|
5
|
+
import type { LinkNavigate, LinkTarget } from './link.js'
|
|
6
|
+
import type { FontWeight, Palette, Radius, Spacing } from './theme/types.js'
|
|
7
|
+
|
|
8
|
+
type PropertyKind = 'string' | 'number' | 'boolean' | 'object' | 'function'
|
|
9
|
+
declare const propertyValue: unique symbol
|
|
10
|
+
|
|
11
|
+
/** Plain metadata; the symbol carries a TypeScript type and is never emitted. */
|
|
12
|
+
export interface Property<T = unknown> {
|
|
13
|
+
readonly kind: PropertyKind | readonly PropertyKind[]
|
|
14
|
+
readonly default?: T
|
|
15
|
+
readonly required?: boolean
|
|
16
|
+
readonly values?: readonly T[]
|
|
17
|
+
readonly token?: 'space' | 'radius' | 'palette' | 'fontWeight' | 'icon'
|
|
18
|
+
readonly units?: 'layout' | 'dimension'
|
|
19
|
+
readonly runtimeOnly?: boolean
|
|
20
|
+
readonly [propertyValue]?: T
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function property<T>() {
|
|
24
|
+
return <const D extends Property<T>>(definition: D) => definition as D & Property<T>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type PropertyValue<P> = P extends Property<infer T> ? T : never
|
|
28
|
+
export type ContractProps<P extends Record<string, Property>> = {
|
|
29
|
+
[K in keyof P as P[K] extends { required: true } ? K : never]: PropertyValue<P[K]>
|
|
30
|
+
} & {
|
|
31
|
+
[K in keyof P as P[K] extends { required: true } ? never : K]?: PropertyValue<P[K]>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const text = property<string>()
|
|
35
|
+
const number = property<number>()
|
|
36
|
+
const boolean = property<boolean>()
|
|
37
|
+
const optionalText = text({ kind: 'string', default: undefined })
|
|
38
|
+
const flag = boolean({ kind: 'boolean', default: false })
|
|
39
|
+
|
|
40
|
+
export const spacingProperty = property<Spacing>()({
|
|
41
|
+
kind: ['string', 'number'],
|
|
42
|
+
default: undefined,
|
|
43
|
+
token: 'space',
|
|
44
|
+
units: 'layout',
|
|
45
|
+
})
|
|
46
|
+
export const radiusProperty = property<Radius | number>()({
|
|
47
|
+
kind: ['string', 'number'],
|
|
48
|
+
default: undefined,
|
|
49
|
+
token: 'radius',
|
|
50
|
+
units: 'layout',
|
|
51
|
+
})
|
|
52
|
+
export const dimensionProperty = property<Dimension>()({
|
|
53
|
+
kind: ['number', 'string'],
|
|
54
|
+
default: undefined,
|
|
55
|
+
units: 'dimension',
|
|
56
|
+
})
|
|
57
|
+
export const weightProperty = property<FontWeight>()({
|
|
58
|
+
kind: 'string',
|
|
59
|
+
default: undefined,
|
|
60
|
+
token: 'fontWeight',
|
|
61
|
+
})
|
|
62
|
+
const icon = property<IconName>()({ kind: 'string', default: undefined, token: 'icon' })
|
|
63
|
+
|
|
64
|
+
export const viewContract = {
|
|
65
|
+
id: optionalText,
|
|
66
|
+
accessibilityLabel: optionalText,
|
|
67
|
+
accessibilityHidden: boolean({ kind: 'boolean', default: undefined }),
|
|
68
|
+
}
|
|
69
|
+
export const flexContract = {
|
|
70
|
+
grow: number({ kind: 'number', default: 0 }),
|
|
71
|
+
shrink: number({ kind: 'number', default: undefined }),
|
|
72
|
+
}
|
|
73
|
+
export const boxContract = {
|
|
74
|
+
...viewContract,
|
|
75
|
+
...flexContract,
|
|
76
|
+
padding: spacingProperty,
|
|
77
|
+
paddingX: spacingProperty,
|
|
78
|
+
paddingY: spacingProperty,
|
|
79
|
+
radius: radiusProperty,
|
|
80
|
+
width: dimensionProperty,
|
|
81
|
+
height: dimensionProperty,
|
|
82
|
+
backgroundColor: text({ kind: 'string' }),
|
|
83
|
+
}
|
|
84
|
+
export const motionBoxContract = {
|
|
85
|
+
...boxContract,
|
|
86
|
+
motionRegion: property<MotionRegion>()({ kind: 'object', default: undefined, runtimeOnly: true }),
|
|
87
|
+
}
|
|
88
|
+
export type Align = 'start' | 'center' | 'end' | 'stretch'
|
|
89
|
+
export type Justify = 'start' | 'center' | 'end' | 'between' | 'around'
|
|
90
|
+
const layout = {
|
|
91
|
+
...boxContract,
|
|
92
|
+
gap: spacingProperty,
|
|
93
|
+
justify: property<Justify>()({
|
|
94
|
+
kind: 'string',
|
|
95
|
+
values: ['start', 'center', 'end', 'between', 'around'],
|
|
96
|
+
default: 'start',
|
|
97
|
+
}),
|
|
98
|
+
wrap: flag,
|
|
99
|
+
}
|
|
100
|
+
export const rowContract = {
|
|
101
|
+
...layout,
|
|
102
|
+
align: property<Align>()({
|
|
103
|
+
kind: 'string',
|
|
104
|
+
values: ['start', 'center', 'end', 'stretch'],
|
|
105
|
+
default: 'center',
|
|
106
|
+
}),
|
|
107
|
+
}
|
|
108
|
+
export const columnContract = {
|
|
109
|
+
...layout,
|
|
110
|
+
align: property<Align>()({
|
|
111
|
+
kind: 'string',
|
|
112
|
+
values: ['start', 'center', 'end', 'stretch'],
|
|
113
|
+
default: 'stretch',
|
|
114
|
+
}),
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const navigationContract = {
|
|
118
|
+
href: optionalText,
|
|
119
|
+
target: property<LinkTarget>()({ kind: 'string', values: ['_self', '_blank'], default: '_self' }),
|
|
120
|
+
rel: optionalText,
|
|
121
|
+
navigate: property<LinkNavigate>()({ kind: 'function', default: undefined, runtimeOnly: true }),
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export const buttonContract = {
|
|
125
|
+
...navigationContract,
|
|
126
|
+
motionSurface: property<MotionSurface>()({
|
|
127
|
+
kind: 'object',
|
|
128
|
+
default: undefined,
|
|
129
|
+
runtimeOnly: true,
|
|
130
|
+
}),
|
|
131
|
+
...viewContract,
|
|
132
|
+
...flexContract,
|
|
133
|
+
text: optionalText,
|
|
134
|
+
type: property<'button' | 'submit' | 'reset'>()({
|
|
135
|
+
kind: 'string',
|
|
136
|
+
values: ['button', 'submit', 'reset'],
|
|
137
|
+
default: 'button',
|
|
138
|
+
}),
|
|
139
|
+
name: optionalText,
|
|
140
|
+
value: optionalText,
|
|
141
|
+
form: optionalText,
|
|
142
|
+
variant: property<'primary' | 'secondary' | 'ghost'>()({
|
|
143
|
+
kind: 'string',
|
|
144
|
+
values: ['primary', 'secondary', 'ghost'],
|
|
145
|
+
default: 'primary',
|
|
146
|
+
}),
|
|
147
|
+
size: property<'sm' | 'md' | 'lg'>()({
|
|
148
|
+
kind: 'string',
|
|
149
|
+
values: ['sm', 'md', 'lg'],
|
|
150
|
+
default: 'md',
|
|
151
|
+
}),
|
|
152
|
+
disabled: flag,
|
|
153
|
+
loading: flag,
|
|
154
|
+
loadingText: text({ kind: 'string', default: 'Loading…' }),
|
|
155
|
+
icon,
|
|
156
|
+
trailingIcon: icon,
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export const paletteTones: readonly (keyof Palette)[] = [
|
|
160
|
+
'background',
|
|
161
|
+
'surface',
|
|
162
|
+
'elevated',
|
|
163
|
+
'text',
|
|
164
|
+
'muted',
|
|
165
|
+
'primary',
|
|
166
|
+
'onPrimary',
|
|
167
|
+
'primarySoft',
|
|
168
|
+
'accent',
|
|
169
|
+
'onAccent',
|
|
170
|
+
'accentSoft',
|
|
171
|
+
'border',
|
|
172
|
+
'warning',
|
|
173
|
+
'success',
|
|
174
|
+
'danger',
|
|
175
|
+
]
|
|
176
|
+
export const textContract = {
|
|
177
|
+
weight: weightProperty,
|
|
178
|
+
...viewContract,
|
|
179
|
+
...flexContract,
|
|
180
|
+
text: optionalText,
|
|
181
|
+
as: property<'p' | 'span' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'>()({
|
|
182
|
+
kind: 'string',
|
|
183
|
+
values: ['p', 'span', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
|
|
184
|
+
default: 'p',
|
|
185
|
+
}),
|
|
186
|
+
variant: property<'display' | 'title' | 'heading' | 'body' | 'caption' | 'overline'>()({
|
|
187
|
+
kind: 'string',
|
|
188
|
+
values: ['display', 'title', 'heading', 'body', 'caption', 'overline'],
|
|
189
|
+
default: 'body',
|
|
190
|
+
}),
|
|
191
|
+
tone: property<keyof Palette>()({
|
|
192
|
+
kind: 'string',
|
|
193
|
+
values: paletteTones,
|
|
194
|
+
default: 'text',
|
|
195
|
+
token: 'palette',
|
|
196
|
+
}),
|
|
197
|
+
align: property<'left' | 'center' | 'right'>()({
|
|
198
|
+
kind: 'string',
|
|
199
|
+
values: ['left', 'center', 'right'],
|
|
200
|
+
default: 'left',
|
|
201
|
+
}),
|
|
202
|
+
wrap: boolean({ kind: 'boolean', default: true }),
|
|
203
|
+
}
|
|
204
|
+
export const inputContract = {
|
|
205
|
+
id: viewContract.id,
|
|
206
|
+
accessibilityHidden: viewContract.accessibilityHidden,
|
|
207
|
+
...flexContract,
|
|
208
|
+
width: dimensionProperty,
|
|
209
|
+
modelValue: text({ kind: 'string', default: '' }),
|
|
210
|
+
label: text({ kind: 'string', required: true }),
|
|
211
|
+
placeholder: text({ kind: 'string', default: '' }),
|
|
212
|
+
helperText: text({ kind: 'string', default: '' }),
|
|
213
|
+
error: text({ kind: 'string', default: '' }),
|
|
214
|
+
type: property<'text' | 'email' | 'password' | 'tel' | 'url' | 'search'>()({
|
|
215
|
+
kind: 'string',
|
|
216
|
+
values: ['text', 'email', 'password', 'tel', 'url', 'search'],
|
|
217
|
+
default: 'text',
|
|
218
|
+
}),
|
|
219
|
+
name: optionalText,
|
|
220
|
+
autocomplete: optionalText,
|
|
221
|
+
required: flag,
|
|
222
|
+
inputmode: property<
|
|
223
|
+
'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url'
|
|
224
|
+
>()({ kind: 'string', default: undefined }),
|
|
225
|
+
form: optionalText,
|
|
226
|
+
disabled: flag,
|
|
227
|
+
readonly: flag,
|
|
228
|
+
multiline: flag,
|
|
229
|
+
rows: number({ kind: 'number', default: 3 }),
|
|
230
|
+
maxLength: number({ kind: 'number', default: undefined }),
|
|
231
|
+
autocapitalize: property<'none' | 'sentences' | 'words' | 'characters'>()({
|
|
232
|
+
kind: 'string',
|
|
233
|
+
values: ['none', 'sentences', 'words', 'characters'],
|
|
234
|
+
default: undefined,
|
|
235
|
+
}),
|
|
236
|
+
autocorrect: boolean({ kind: 'boolean', default: undefined }),
|
|
237
|
+
returnKey: property<'done' | 'next' | 'go' | 'search' | 'send'>()({
|
|
238
|
+
kind: 'string',
|
|
239
|
+
values: ['done', 'next', 'go', 'search', 'send'],
|
|
240
|
+
default: 'done',
|
|
241
|
+
}),
|
|
242
|
+
trailingAction: property<InputAction>()({ kind: 'object', default: undefined }),
|
|
243
|
+
icon,
|
|
244
|
+
trailingIcon: icon,
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** Value changes are requests to the owner, not mutations of parent state. */
|
|
248
|
+
export interface InputEvents {
|
|
249
|
+
valueChange(value: string): void
|
|
250
|
+
submit(value: string): void
|
|
251
|
+
focus(): void
|
|
252
|
+
blur(): void
|
|
253
|
+
action(): void
|
|
254
|
+
}
|
|
255
|
+
export interface ButtonEvents {
|
|
256
|
+
activate(): void
|
|
257
|
+
error(error: unknown): void
|
|
258
|
+
}
|
|
259
|
+
export type TextInputHandle = InputHandle
|
|
260
|
+
|
|
261
|
+
export const componentContracts = {
|
|
262
|
+
MBox: { version: 1, props: motionBoxContract, slots: ['default'], events: {} },
|
|
263
|
+
MRow: { version: 1, props: rowContract, slots: ['default'], events: {} },
|
|
264
|
+
MColumn: { version: 1, props: columnContract, slots: ['default'], events: {} },
|
|
265
|
+
MText: { version: 1, props: textContract, slots: ['text', 'spans'], events: {} },
|
|
266
|
+
MButton: {
|
|
267
|
+
version: 1,
|
|
268
|
+
props: buttonContract,
|
|
269
|
+
slots: ['text', 'leading-decoration', 'trailing-decoration'],
|
|
270
|
+
events: { activate: 'none', error: 'unknown' },
|
|
271
|
+
},
|
|
272
|
+
MInput: {
|
|
273
|
+
version: 1,
|
|
274
|
+
props: inputContract,
|
|
275
|
+
slots: [],
|
|
276
|
+
events: {
|
|
277
|
+
valueChange: 'string',
|
|
278
|
+
submit: 'string',
|
|
279
|
+
focus: 'none',
|
|
280
|
+
blur: 'none',
|
|
281
|
+
action: 'none',
|
|
282
|
+
},
|
|
283
|
+
binding: { prop: 'modelValue', event: 'valueChange', owner: 'parent' },
|
|
284
|
+
handles: ['focus', 'blur'],
|
|
285
|
+
},
|
|
286
|
+
} as const
|
|
287
|
+
|
|
288
|
+
/** JSON-compatible descriptions; unset defaults remain distinct from no default. */
|
|
289
|
+
export function describeContract(name: keyof typeof componentContracts) {
|
|
290
|
+
const contract = componentContracts[name]
|
|
291
|
+
return {
|
|
292
|
+
...contract,
|
|
293
|
+
props: Object.fromEntries(
|
|
294
|
+
Object.entries(contract.props).map(([name, definition]) => [
|
|
295
|
+
name,
|
|
296
|
+
{
|
|
297
|
+
...definition,
|
|
298
|
+
...('default' in definition && definition.default === undefined
|
|
299
|
+
? { default: { unset: true } }
|
|
300
|
+
: {}),
|
|
301
|
+
},
|
|
302
|
+
]),
|
|
303
|
+
),
|
|
304
|
+
}
|
|
305
|
+
}
|