@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
package/src/motion.ts
CHANGED
|
@@ -8,15 +8,73 @@ export function resolvePressScale(scale: number): number {
|
|
|
8
8
|
|
|
9
9
|
// Recipes describe motion, not input or lifecycle. Adapters own reduced-motion detection:
|
|
10
10
|
// native follows Jolt configuration; Web follows prefers-reduced-motion. See guide/motion.
|
|
11
|
-
export function pressMotion(
|
|
11
|
+
export function pressMotion(value: number | Readonly<MotionTheme>) {
|
|
12
|
+
if (value === null || (typeof value !== 'number' && typeof value !== 'object'))
|
|
13
|
+
throw new RangeError('Press motion needs a valid scale or motion theme')
|
|
14
|
+
const motion = typeof value === 'number' ? { ...defaultMotion, pressScale: value } : value
|
|
15
|
+
validateMotion(motion)
|
|
12
16
|
return {
|
|
13
17
|
composition: 'multiply',
|
|
14
|
-
pressed: [
|
|
15
|
-
|
|
18
|
+
pressed: [
|
|
19
|
+
{ scale: motion.pressScale },
|
|
20
|
+
{ type: 'spring', duration: motion.pressDuration, bounce: 0 },
|
|
21
|
+
],
|
|
22
|
+
released: [
|
|
23
|
+
{ scale: 1 },
|
|
24
|
+
{ type: 'spring', duration: motion.releaseDuration, bounce: motion.releaseBounce },
|
|
25
|
+
],
|
|
16
26
|
} as const
|
|
17
27
|
}
|
|
18
28
|
|
|
29
|
+
/** Platform-neutral recipe. The host supplies the target and owns the Jolt playback. */
|
|
30
|
+
export function motionRecipe(theme: MavisTheme, name: 'enter' | 'exit') {
|
|
31
|
+
const motion = theme.motion
|
|
32
|
+
validateMotion(motion)
|
|
33
|
+
return name === 'enter'
|
|
34
|
+
? {
|
|
35
|
+
keyframes: { opacity: [0, 1], y: [motion.enterOffset, 0] },
|
|
36
|
+
transition: { type: 'tween' as const, duration: motion.enterDuration, ease: motion.ease },
|
|
37
|
+
}
|
|
38
|
+
: {
|
|
39
|
+
keyframes: { opacity: [1, 0] },
|
|
40
|
+
transition: { type: 'tween' as const, duration: motion.exitDuration, ease: motion.ease },
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
19
44
|
export const revealMotion = {
|
|
20
45
|
enter: [{ opacity: [0, 1], y: [8, 0] }, { duration: 180 }],
|
|
21
46
|
leave: [{ opacity: 0 }, { duration: 120 }],
|
|
22
47
|
} as const
|
|
48
|
+
import type { MotionTheme, MavisTheme } from './theme/types.js'
|
|
49
|
+
|
|
50
|
+
export const defaultMotion: Readonly<MotionTheme> = Object.freeze({
|
|
51
|
+
pressScale: 0.97,
|
|
52
|
+
pressDuration: 200,
|
|
53
|
+
releaseDuration: 450,
|
|
54
|
+
releaseBounce: 0.35,
|
|
55
|
+
enterDuration: 180,
|
|
56
|
+
exitDuration: 120,
|
|
57
|
+
enterOffset: 8,
|
|
58
|
+
ease: 'easeOut',
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
export function validateMotion(motion: Readonly<MotionTheme>) {
|
|
62
|
+
resolvePressScale(motion.pressScale)
|
|
63
|
+
for (const key of [
|
|
64
|
+
'pressDuration',
|
|
65
|
+
'releaseDuration',
|
|
66
|
+
'enterDuration',
|
|
67
|
+
'exitDuration',
|
|
68
|
+
'enterOffset',
|
|
69
|
+
] as const)
|
|
70
|
+
if (!Number.isFinite(motion[key]) || motion[key] < 0)
|
|
71
|
+
throw new RangeError(`${key} must be a finite nonnegative number`)
|
|
72
|
+
if (
|
|
73
|
+
!Number.isFinite(motion.releaseBounce) ||
|
|
74
|
+
motion.releaseBounce < 0 ||
|
|
75
|
+
motion.releaseBounce > 1
|
|
76
|
+
)
|
|
77
|
+
throw new RangeError('releaseBounce must be between 0 and 1')
|
|
78
|
+
if (!['linear', 'easeIn', 'easeOut', 'easeInOut'].includes(motion.ease))
|
|
79
|
+
throw new RangeError('Unknown motion easing')
|
|
80
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { validateChoices, type ChoiceOption, type ChoiceValue } from './choice.js'
|
|
2
|
+
|
|
3
|
+
export interface StepOption extends ChoiceOption {
|
|
4
|
+
status?: 'pending' | 'complete' | 'error'
|
|
5
|
+
}
|
|
6
|
+
export function validateSteps(steps: readonly StepOption[], current: ChoiceValue | null) {
|
|
7
|
+
validateChoices(steps, current)
|
|
8
|
+
if (!steps.length) throw new RangeError('Steps require at least one item.')
|
|
9
|
+
if (current !== null && !steps.some((step) => step.value === current))
|
|
10
|
+
throw new RangeError('The current step must exist in steps.')
|
|
11
|
+
for (const step of steps)
|
|
12
|
+
if (step.status && !['pending', 'complete', 'error'].includes(step.status))
|
|
13
|
+
throw new RangeError(`Unknown step status: ${step.status}`)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type PaginationItem = { kind: 'page'; page: number } | { kind: 'gap'; key: string }
|
|
17
|
+
export function pageCount(total: number, pageSize: number) {
|
|
18
|
+
if (!Number.isSafeInteger(total) || total < 0)
|
|
19
|
+
throw new RangeError('total must be a non-negative safe integer.')
|
|
20
|
+
if (!Number.isSafeInteger(pageSize) || pageSize < 1)
|
|
21
|
+
throw new RangeError('pageSize must be a positive safe integer.')
|
|
22
|
+
return Math.ceil(total / pageSize)
|
|
23
|
+
}
|
|
24
|
+
/** 1-based pages. Empty results retain page 1 without inventing a result page. */
|
|
25
|
+
export function pagination(total: number, pageSize: number, page: number, siblingCount = 1) {
|
|
26
|
+
const count = pageCount(total, pageSize)
|
|
27
|
+
if (!Number.isSafeInteger(page) || page < 1)
|
|
28
|
+
throw new RangeError('page must be a positive safe integer.')
|
|
29
|
+
if (!Number.isInteger(siblingCount) || siblingCount < 0 || siblingCount > 2)
|
|
30
|
+
throw new RangeError('siblingCount must be 0, 1 or 2.')
|
|
31
|
+
// A changed total can temporarily make the parent's page stale. Report it without mutation.
|
|
32
|
+
const outOfRange = page > Math.max(1, count)
|
|
33
|
+
const pages = new Set<number>()
|
|
34
|
+
if (count > 0) {
|
|
35
|
+
pages.add(1)
|
|
36
|
+
pages.add(count)
|
|
37
|
+
}
|
|
38
|
+
const anchor = Math.min(page, count)
|
|
39
|
+
for (
|
|
40
|
+
let value = Math.max(1, anchor - siblingCount);
|
|
41
|
+
value <= Math.min(count, anchor + siblingCount);
|
|
42
|
+
value++
|
|
43
|
+
)
|
|
44
|
+
pages.add(value)
|
|
45
|
+
const items: PaginationItem[] = []
|
|
46
|
+
let previous = 0
|
|
47
|
+
for (const value of [...pages].sort((a, b) => a - b)) {
|
|
48
|
+
if (previous && value - previous === 2) items.push({ kind: 'page', page: previous + 1 })
|
|
49
|
+
else if (previous && value - previous > 2)
|
|
50
|
+
items.push({ kind: 'gap', key: `${previous}-${value}` })
|
|
51
|
+
items.push({ kind: 'page', page: value })
|
|
52
|
+
previous = value
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
count,
|
|
56
|
+
items,
|
|
57
|
+
outOfRange,
|
|
58
|
+
previous: count > 0 && page > 1 ? Math.min(page - 1, count) : null,
|
|
59
|
+
next: page < count ? page + 1 : null,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Spacing } from './theme/types.js'
|
|
2
|
+
|
|
3
|
+
export type StackDirection = 'row' | 'column'
|
|
4
|
+
export interface StackLayout {
|
|
5
|
+
direction?: StackDirection
|
|
6
|
+
gap?: Spacing
|
|
7
|
+
align?: 'start' | 'end' | 'center' | 'stretch'
|
|
8
|
+
justify?: 'start' | 'end' | 'center' | 'between' | 'around'
|
|
9
|
+
wrap?: boolean
|
|
10
|
+
}
|
|
11
|
+
export interface StackBreakpoint extends StackLayout {
|
|
12
|
+
/** Content width in CSS pixels on Web and DIPs on NativeScript. */
|
|
13
|
+
at: number
|
|
14
|
+
}
|
|
15
|
+
export type StackResponsive = StackBreakpoint | readonly StackBreakpoint[]
|
|
16
|
+
|
|
17
|
+
/** Sorted min-width overrides; the input order never changes the resulting layout. */
|
|
18
|
+
export function stackLayout(
|
|
19
|
+
base: StackLayout,
|
|
20
|
+
responsive: StackResponsive | undefined,
|
|
21
|
+
width?: number,
|
|
22
|
+
): StackLayout {
|
|
23
|
+
const points =
|
|
24
|
+
responsive === undefined
|
|
25
|
+
? []
|
|
26
|
+
: Array.isArray(responsive)
|
|
27
|
+
? [...responsive]
|
|
28
|
+
: [responsive as StackBreakpoint]
|
|
29
|
+
const seen = new Set<number>()
|
|
30
|
+
const result = { ...base }
|
|
31
|
+
for (const point of points.sort((a, b) => a.at - b.at)) {
|
|
32
|
+
if (!Number.isFinite(point.at) || point.at <= 0 || seen.has(point.at))
|
|
33
|
+
throw new RangeError('Stack breakpoints must be distinct positive content widths.')
|
|
34
|
+
seen.add(point.at)
|
|
35
|
+
if (point.direction !== undefined && !['row', 'column'].includes(point.direction))
|
|
36
|
+
throw new TypeError('Unknown responsive stack direction.')
|
|
37
|
+
if (point.align !== undefined && !['start', 'end', 'center', 'stretch'].includes(point.align))
|
|
38
|
+
throw new TypeError('Unknown responsive alignment.')
|
|
39
|
+
if (
|
|
40
|
+
point.justify !== undefined &&
|
|
41
|
+
!['start', 'end', 'center', 'between', 'around'].includes(point.justify)
|
|
42
|
+
)
|
|
43
|
+
throw new TypeError('Unknown responsive distribution.')
|
|
44
|
+
if (point.wrap !== undefined && typeof point.wrap !== 'boolean')
|
|
45
|
+
throw new TypeError('wrap must be boolean.')
|
|
46
|
+
if (width !== undefined && width >= point.at) {
|
|
47
|
+
const { at, ...override } = point
|
|
48
|
+
Object.assign(result, override)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function stackDirection(
|
|
55
|
+
base: StackDirection,
|
|
56
|
+
responsive: StackResponsive | undefined,
|
|
57
|
+
width?: number,
|
|
58
|
+
): StackDirection {
|
|
59
|
+
if (!['row', 'column'].includes(base)) throw new TypeError('Unknown stack direction.')
|
|
60
|
+
return stackLayout({ direction: base }, responsive, width).direction ?? base
|
|
61
|
+
}
|
package/src/theme/themes.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
validateShadow,
|
|
6
6
|
freezeFamily,
|
|
7
7
|
} from './typography.js'
|
|
8
|
-
import {
|
|
8
|
+
import { defaultMotion, validateMotion } from '../motion.js'
|
|
9
9
|
|
|
10
10
|
const foundation: MavisTheme = {
|
|
11
11
|
name: 'mavis',
|
|
@@ -89,7 +89,7 @@ const foundation: MavisTheme = {
|
|
|
89
89
|
input: { fontWeight: 'normal', lineHeight: 1.5, paddingX: 16, paddingY: 14, radius: 'md' },
|
|
90
90
|
card: { padding: 'lg', radius: 'lg', elevation: 'none' },
|
|
91
91
|
},
|
|
92
|
-
motion:
|
|
92
|
+
motion: defaultMotion,
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
/** Derive a complete theme without changing the original. */
|
|
@@ -141,7 +141,7 @@ export function defineTheme(options: ThemeOptions, base: MavisTheme = foundation
|
|
|
141
141
|
for (const [key, value] of [...Object.entries(theme.space), ...Object.entries(theme.radius)]) {
|
|
142
142
|
if (!Number.isFinite(value) || value < 0) throw new RangeError(`Invalid theme token: ${key}`)
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
validateMotion(theme.motion)
|
|
145
145
|
return Object.freeze(theme)
|
|
146
146
|
}
|
|
147
147
|
|
package/src/theme/types.ts
CHANGED
|
@@ -65,6 +65,18 @@ export interface Typography {
|
|
|
65
65
|
letterSpacing: number
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
export type MotionEase = 'linear' | 'easeIn' | 'easeOut' | 'easeInOut'
|
|
69
|
+
export interface MotionTheme {
|
|
70
|
+
pressScale: number
|
|
71
|
+
pressDuration: number
|
|
72
|
+
releaseDuration: number
|
|
73
|
+
releaseBounce: number
|
|
74
|
+
enterDuration: number
|
|
75
|
+
exitDuration: number
|
|
76
|
+
enterOffset: number
|
|
77
|
+
ease: MotionEase
|
|
78
|
+
}
|
|
79
|
+
|
|
68
80
|
export interface MavisTheme {
|
|
69
81
|
readonly name: string
|
|
70
82
|
readonly appearance: 'light' | 'dark'
|
|
@@ -77,7 +89,7 @@ export interface MavisTheme {
|
|
|
77
89
|
>
|
|
78
90
|
readonly elevation: Readonly<Record<Elevation, Readonly<Shadow>>>
|
|
79
91
|
readonly components: { readonly [K in keyof ComponentTheme]: Readonly<ComponentTheme[K]> }
|
|
80
|
-
readonly motion: Readonly<
|
|
92
|
+
readonly motion: Readonly<MotionTheme>
|
|
81
93
|
}
|
|
82
94
|
|
|
83
95
|
export interface ThemeOptions {
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
onBeforeUnmount,
|
|
4
|
+
ref,
|
|
5
|
+
shallowRef,
|
|
6
|
+
watch,
|
|
7
|
+
type ExtractPropTypes,
|
|
8
|
+
type PropType,
|
|
9
|
+
} from '@vue/runtime-core'
|
|
10
|
+
import { dimensionProperty, flexContract, viewContract } from '../contracts.js'
|
|
11
|
+
import { vueProperty, vueProps } from './contracts.js'
|
|
12
|
+
import { useCachedActivity } from './cached-activity.js'
|
|
13
|
+
import {
|
|
14
|
+
choiceKey,
|
|
15
|
+
isChoiceValue,
|
|
16
|
+
validateChoices,
|
|
17
|
+
type ChoiceOption,
|
|
18
|
+
type ChoiceValue,
|
|
19
|
+
} from '../choice.js'
|
|
20
|
+
import {
|
|
21
|
+
comboboxHighlight,
|
|
22
|
+
comboboxMove,
|
|
23
|
+
comboboxSelected,
|
|
24
|
+
createComboboxSearch,
|
|
25
|
+
type ComboboxSearch,
|
|
26
|
+
type ComboboxSnapshot,
|
|
27
|
+
} from '../combobox.js'
|
|
28
|
+
|
|
29
|
+
export const comboboxProps = {
|
|
30
|
+
...vueProps(viewContract),
|
|
31
|
+
...vueProps(flexContract),
|
|
32
|
+
width: vueProperty(dimensionProperty),
|
|
33
|
+
modelValue: { type: [String, Number] as PropType<ChoiceValue | null>, default: null },
|
|
34
|
+
query: { type: String, required: true as const },
|
|
35
|
+
selectedOption: { type: Object as PropType<ChoiceOption | null>, default: null },
|
|
36
|
+
search: { type: Function as PropType<ComboboxSearch>, required: true as const },
|
|
37
|
+
initialResults: { type: Object as PropType<ComboboxSnapshot>, default: undefined },
|
|
38
|
+
debounce: { type: Number, default: 200 },
|
|
39
|
+
minQueryLength: { type: Number, default: 1 },
|
|
40
|
+
maxResults: { type: Number, default: 50 },
|
|
41
|
+
label: { type: String, required: true as const },
|
|
42
|
+
placeholder: { type: String, default: 'Search options' },
|
|
43
|
+
helperText: { type: String, default: '' },
|
|
44
|
+
error: { type: String, default: '' },
|
|
45
|
+
disabled: Boolean,
|
|
46
|
+
clearable: { type: Boolean, default: true },
|
|
47
|
+
clearLabel: { type: String, default: 'Clear selection' },
|
|
48
|
+
closeLabel: { type: String, default: 'Close results' },
|
|
49
|
+
loadingText: { type: String, default: 'Searching…' },
|
|
50
|
+
emptyText: { type: String, default: 'No results' },
|
|
51
|
+
searchErrorText: { type: String, default: 'Could not load results.' },
|
|
52
|
+
retryLabel: { type: String, default: 'Try again' },
|
|
53
|
+
idleText: { type: String, default: 'Type to search.' },
|
|
54
|
+
limitedText: { type: String, default: 'Refine your search to see more results.' },
|
|
55
|
+
}
|
|
56
|
+
export const comboboxEmits = {
|
|
57
|
+
'update:modelValue': (value: ChoiceValue | null) => value === null || isChoiceValue(value),
|
|
58
|
+
'update:query': (value: string) => typeof value === 'string',
|
|
59
|
+
select: (option: ChoiceOption | null) => option === null || isChoiceValue(option.value),
|
|
60
|
+
focus: () => true,
|
|
61
|
+
blur: () => true,
|
|
62
|
+
}
|
|
63
|
+
type Props = Readonly<ExtractPropTypes<typeof comboboxProps>>
|
|
64
|
+
type Emit = {
|
|
65
|
+
(event: 'update:modelValue', value: ChoiceValue | null): void
|
|
66
|
+
(event: 'update:query', value: string): void
|
|
67
|
+
(event: 'select', value: ChoiceOption | null): void
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** @internal Shared request ownership and controlled selection for the two Vue renderers. */
|
|
71
|
+
export function useCombobox(props: Props, emit: Emit) {
|
|
72
|
+
watch(
|
|
73
|
+
() => props.label,
|
|
74
|
+
(label) => {
|
|
75
|
+
if (!label.trim()) throw new RangeError('Combobox needs a nonempty label.')
|
|
76
|
+
},
|
|
77
|
+
{ immediate: true },
|
|
78
|
+
)
|
|
79
|
+
const open = ref(false)
|
|
80
|
+
const revision = ref(0)
|
|
81
|
+
const composing = ref(false)
|
|
82
|
+
const active = ref<string>()
|
|
83
|
+
const retained = shallowRef<ChoiceOption | null>(props.selectedOption)
|
|
84
|
+
const pendingSelection = shallowRef<ChoiceOption>()
|
|
85
|
+
const activity = useCachedActivity()
|
|
86
|
+
const makeSearch = () =>
|
|
87
|
+
createComboboxSearch({
|
|
88
|
+
search: (query, context) => props.search(query, context),
|
|
89
|
+
debounce: props.debounce,
|
|
90
|
+
minQueryLength: props.minQueryLength,
|
|
91
|
+
maxResults: props.maxResults,
|
|
92
|
+
initialResults: props.initialResults,
|
|
93
|
+
onChange(value) {
|
|
94
|
+
state.value = value
|
|
95
|
+
active.value = comboboxHighlight(value.options, active.value)
|
|
96
|
+
},
|
|
97
|
+
})
|
|
98
|
+
let search = makeSearch()
|
|
99
|
+
const state = shallowRef(search.state)
|
|
100
|
+
const selected = computed(() =>
|
|
101
|
+
comboboxSelected(
|
|
102
|
+
props.modelValue,
|
|
103
|
+
state.value.options,
|
|
104
|
+
props.selectedOption?.value === props.modelValue
|
|
105
|
+
? props.selectedOption
|
|
106
|
+
: pendingSelection.value?.value === props.modelValue
|
|
107
|
+
? pendingSelection.value
|
|
108
|
+
: retained.value,
|
|
109
|
+
),
|
|
110
|
+
)
|
|
111
|
+
watch(
|
|
112
|
+
selected,
|
|
113
|
+
(option) => {
|
|
114
|
+
if (option) retained.value = option
|
|
115
|
+
},
|
|
116
|
+
{ immediate: true },
|
|
117
|
+
)
|
|
118
|
+
watch(
|
|
119
|
+
() => [props.modelValue, props.selectedOption] as const,
|
|
120
|
+
() => {
|
|
121
|
+
validateChoices(props.selectedOption ? [props.selectedOption] : [], props.modelValue)
|
|
122
|
+
if (props.modelValue === null) {
|
|
123
|
+
retained.value = null
|
|
124
|
+
pendingSelection.value = undefined
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
{ immediate: true, deep: true },
|
|
128
|
+
)
|
|
129
|
+
watch(
|
|
130
|
+
() => props.query,
|
|
131
|
+
() => {
|
|
132
|
+
if (open.value && !composing.value) search.request(props.query)
|
|
133
|
+
else search.cancel()
|
|
134
|
+
},
|
|
135
|
+
{ flush: 'sync' },
|
|
136
|
+
)
|
|
137
|
+
watch(
|
|
138
|
+
() => [props.search, props.debounce, props.minQueryLength, props.maxResults],
|
|
139
|
+
() => {
|
|
140
|
+
search.dispose()
|
|
141
|
+
search = makeSearch()
|
|
142
|
+
state.value = search.state
|
|
143
|
+
if (open.value && !composing.value) search.request(props.query)
|
|
144
|
+
},
|
|
145
|
+
)
|
|
146
|
+
watch(
|
|
147
|
+
() => props.disabled || !activity.value,
|
|
148
|
+
(blocked) => {
|
|
149
|
+
if (blocked) close()
|
|
150
|
+
},
|
|
151
|
+
)
|
|
152
|
+
onBeforeUnmount(() => search.dispose())
|
|
153
|
+
function show() {
|
|
154
|
+
if (props.disabled || !activity.value) return
|
|
155
|
+
open.value = true
|
|
156
|
+
if (!composing.value) search.request(props.query)
|
|
157
|
+
}
|
|
158
|
+
function close() {
|
|
159
|
+
open.value = false
|
|
160
|
+
active.value = undefined
|
|
161
|
+
composing.value = false
|
|
162
|
+
search.cancel()
|
|
163
|
+
}
|
|
164
|
+
function edit(query: string) {
|
|
165
|
+
if (props.disabled) return
|
|
166
|
+
revision.value++
|
|
167
|
+
// Browsers may send a final input event after compositionend. It is the same
|
|
168
|
+
// accepted query, not a second request (including when debounce is zero).
|
|
169
|
+
if (
|
|
170
|
+
query === props.query &&
|
|
171
|
+
!composing.value &&
|
|
172
|
+
open.value &&
|
|
173
|
+
state.value.query === query &&
|
|
174
|
+
state.value.status !== 'idle'
|
|
175
|
+
)
|
|
176
|
+
return
|
|
177
|
+
search.cancel()
|
|
178
|
+
active.value = undefined
|
|
179
|
+
open.value = true
|
|
180
|
+
emit('update:query', query)
|
|
181
|
+
if (props.query === query && !composing.value) search.request(query)
|
|
182
|
+
// Only the accepted controlled query starts a request (the synchronous watch owns it).
|
|
183
|
+
}
|
|
184
|
+
function choose(option: ChoiceOption) {
|
|
185
|
+
const current = state.value.options.find((item) => item.value === option.value)
|
|
186
|
+
if (!open.value || props.disabled || composing.value || !current || current.disabled) return
|
|
187
|
+
pendingSelection.value = current
|
|
188
|
+
if (props.modelValue !== current.value) emit('update:modelValue', current.value)
|
|
189
|
+
emit('update:query', current.label)
|
|
190
|
+
emit('select', current)
|
|
191
|
+
close()
|
|
192
|
+
}
|
|
193
|
+
function clear() {
|
|
194
|
+
if (props.disabled) return
|
|
195
|
+
close()
|
|
196
|
+
emit('update:modelValue', null)
|
|
197
|
+
emit('update:query', '')
|
|
198
|
+
emit('select', null)
|
|
199
|
+
}
|
|
200
|
+
function cancel() {
|
|
201
|
+
close()
|
|
202
|
+
emit('update:query', selected.value?.label ?? '')
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
open,
|
|
206
|
+
composing,
|
|
207
|
+
active,
|
|
208
|
+
state,
|
|
209
|
+
selected,
|
|
210
|
+
revision,
|
|
211
|
+
show,
|
|
212
|
+
close,
|
|
213
|
+
edit,
|
|
214
|
+
choose,
|
|
215
|
+
clear,
|
|
216
|
+
cancel,
|
|
217
|
+
startComposition() {
|
|
218
|
+
composing.value = true
|
|
219
|
+
search.cancel()
|
|
220
|
+
active.value = undefined
|
|
221
|
+
},
|
|
222
|
+
endComposition(query: string) {
|
|
223
|
+
composing.value = false
|
|
224
|
+
edit(query)
|
|
225
|
+
},
|
|
226
|
+
move(direction: 1 | -1) {
|
|
227
|
+
if (!open.value) show()
|
|
228
|
+
active.value = comboboxMove(state.value.options, active.value, direction)
|
|
229
|
+
},
|
|
230
|
+
commit() {
|
|
231
|
+
const option = state.value.options.find((item) => choiceKey(item.value) === active.value)
|
|
232
|
+
if (option) choose(option)
|
|
233
|
+
},
|
|
234
|
+
retry() {
|
|
235
|
+
if (!props.disabled && open.value && !composing.value) search.request(props.query, true)
|
|
236
|
+
},
|
|
237
|
+
}
|
|
238
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ExtractPublicPropTypes } from '@vue/runtime-core'
|
|
2
|
+
import type { SheetName } from '../sheet.js'
|
|
3
|
+
import { componentProps as foundationProps } from './props.js'
|
|
4
|
+
import { datePickerProps, dateRangePickerProps } from './date-props.js'
|
|
5
|
+
import { comboboxProps } from './combobox.js'
|
|
6
|
+
import { filePickerProps } from './files.js'
|
|
7
|
+
import { formGroupProps, formErrorsProps, stepsProps, paginationProps } from './workflow-props.js'
|
|
8
|
+
|
|
9
|
+
/** Complete registry, kept separate from the primitives used to compose controls. */
|
|
10
|
+
export const componentProps = {
|
|
11
|
+
...foundationProps,
|
|
12
|
+
MDatePicker: datePickerProps,
|
|
13
|
+
MDateRangePicker: dateRangePickerProps,
|
|
14
|
+
MCombobox: comboboxProps,
|
|
15
|
+
MFilePicker: filePickerProps,
|
|
16
|
+
MFormGroup: formGroupProps,
|
|
17
|
+
MFormErrors: formErrorsProps,
|
|
18
|
+
MSteps: stepsProps,
|
|
19
|
+
MPagination: paginationProps,
|
|
20
|
+
}
|
|
21
|
+
export type ComponentProps = {
|
|
22
|
+
[Name in keyof typeof componentProps]: ExtractPublicPropTypes<(typeof componentProps)[Name]> &
|
|
23
|
+
(Name extends 'MSheet' ? SheetName : unknown)
|
|
24
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { PropType } from '@vue/runtime-core'
|
|
2
|
+
import type { Property, PropertyValue } from '../contracts.js'
|
|
3
|
+
|
|
4
|
+
type VueProperty<P extends Property> = { type: PropType<PropertyValue<P>> } & (P extends {
|
|
5
|
+
default: infer D
|
|
6
|
+
}
|
|
7
|
+
? { default: D extends undefined ? undefined : PropertyValue<P> }
|
|
8
|
+
: unknown) &
|
|
9
|
+
(P extends { required: true } ? { required: true } : unknown)
|
|
10
|
+
|
|
11
|
+
const constructors = {
|
|
12
|
+
string: String,
|
|
13
|
+
number: Number,
|
|
14
|
+
boolean: Boolean,
|
|
15
|
+
object: Object,
|
|
16
|
+
function: Function,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Vue owns coercion and warnings; portable metadata owns names, defaults and allowed values. */
|
|
20
|
+
export function vueProperty<P extends Property>(definition: P): VueProperty<P> {
|
|
21
|
+
const kinds = Array.isArray(definition.kind) ? definition.kind : [definition.kind]
|
|
22
|
+
const types = kinds.map((kind: keyof typeof constructors) => constructors[kind])
|
|
23
|
+
return {
|
|
24
|
+
type: types.length === 1 ? types[0] : types,
|
|
25
|
+
...('default' in definition ? { default: definition.default } : {}),
|
|
26
|
+
...(definition.required ? { required: true } : {}),
|
|
27
|
+
...(definition.values
|
|
28
|
+
? { validator: (value: unknown) => definition.values!.includes(value) }
|
|
29
|
+
: {}),
|
|
30
|
+
} as VueProperty<P>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function vueProps<P extends Record<string, Property>>(properties: P) {
|
|
34
|
+
return Object.fromEntries(
|
|
35
|
+
Object.entries(properties).map(([key, value]) => [key, vueProperty(value)]),
|
|
36
|
+
) as {
|
|
37
|
+
[K in keyof P]: VueProperty<P[K]>
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { computed, watch, type ExtractPropTypes } from '@vue/runtime-core'
|
|
2
|
+
import {
|
|
3
|
+
addCivilDays,
|
|
4
|
+
addCivilMonths,
|
|
5
|
+
calendarMonth,
|
|
6
|
+
civilWeekday,
|
|
7
|
+
dateAvailability,
|
|
8
|
+
dateLocales,
|
|
9
|
+
parseCivilDate,
|
|
10
|
+
type CivilDate,
|
|
11
|
+
} from '../date.js'
|
|
12
|
+
import { dateCalendarProps } from './date-props.js'
|
|
13
|
+
|
|
14
|
+
/** @internal Calendar arithmetic and live bounds shared by Web and native presentations. */
|
|
15
|
+
export function useDateCalendar(
|
|
16
|
+
props: ExtractPropTypes<typeof dateCalendarProps>,
|
|
17
|
+
change: (value: CivilDate) => void,
|
|
18
|
+
) {
|
|
19
|
+
const words = computed(() => dateLocales[props.locale])
|
|
20
|
+
const firstDay = computed(() => props.firstDayOfWeek ?? words.value.firstDayOfWeek)
|
|
21
|
+
const cells = computed(() => calendarMonth(props.activeDate, firstDay.value))
|
|
22
|
+
const title = computed(() => {
|
|
23
|
+
const parts = parseCivilDate(props.activeDate)!
|
|
24
|
+
return `${words.value.months[parts.month - 1]} ${String(parts.year).padStart(4, '0')}`
|
|
25
|
+
})
|
|
26
|
+
const weekdays = computed(() =>
|
|
27
|
+
Array.from({ length: 7 }, (_, index) => (index + firstDay.value) % 7),
|
|
28
|
+
)
|
|
29
|
+
const available = (date: CivilDate) => dateAvailability(date, props) === null
|
|
30
|
+
function clamp(value: CivilDate) {
|
|
31
|
+
if (props.min && value < props.min) return props.min
|
|
32
|
+
if (props.max && value > props.max) return props.max
|
|
33
|
+
return value
|
|
34
|
+
}
|
|
35
|
+
function move(value: CivilDate) {
|
|
36
|
+
change(clamp(value))
|
|
37
|
+
}
|
|
38
|
+
function canPage(amount: number) {
|
|
39
|
+
const next = addCivilMonths(props.activeDate, amount)
|
|
40
|
+
return (
|
|
41
|
+
next.slice(0, 7) !== props.activeDate.slice(0, 7) &&
|
|
42
|
+
(!props.min || next.slice(0, 7) >= props.min.slice(0, 7)) &&
|
|
43
|
+
(!props.max || next.slice(0, 7) <= props.max.slice(0, 7))
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
function page(amount: number) {
|
|
47
|
+
if (canPage(amount)) move(addCivilMonths(props.activeDate, amount))
|
|
48
|
+
}
|
|
49
|
+
function key(key: string, shift = false, rtl = false): boolean {
|
|
50
|
+
const active = props.activeDate
|
|
51
|
+
if (key === 'ArrowLeft') move(addCivilDays(active, rtl ? 1 : -1))
|
|
52
|
+
else if (key === 'ArrowRight') move(addCivilDays(active, rtl ? -1 : 1))
|
|
53
|
+
else if (key === 'ArrowUp') move(addCivilDays(active, -7))
|
|
54
|
+
else if (key === 'ArrowDown') move(addCivilDays(active, 7))
|
|
55
|
+
else if (key === 'Home')
|
|
56
|
+
move(addCivilDays(active, -((civilWeekday(active) - firstDay.value + 7) % 7)))
|
|
57
|
+
else if (key === 'End')
|
|
58
|
+
move(addCivilDays(active, 6 - ((civilWeekday(active) - firstDay.value + 7) % 7)))
|
|
59
|
+
else if (key === 'PageUp') move(addCivilMonths(active, shift ? -12 : -1))
|
|
60
|
+
else if (key === 'PageDown') move(addCivilMonths(active, shift ? 12 : 1))
|
|
61
|
+
else return false
|
|
62
|
+
return true
|
|
63
|
+
}
|
|
64
|
+
watch(
|
|
65
|
+
() => [props.min, props.max, props.activeDate],
|
|
66
|
+
() => {
|
|
67
|
+
const value = clamp(props.activeDate)
|
|
68
|
+
if (value !== props.activeDate) change(value)
|
|
69
|
+
},
|
|
70
|
+
)
|
|
71
|
+
const inRange = (date: CivilDate) =>
|
|
72
|
+
Boolean(
|
|
73
|
+
props.rangeStart && props.rangeEnd && date >= props.rangeStart && date <= props.rangeEnd,
|
|
74
|
+
)
|
|
75
|
+
return { words, title, firstDay, cells, weekdays, available, move, canPage, page, key, inRange }
|
|
76
|
+
}
|