@getcortexlabs/mavis-core 0.1.0-alpha.9 → 0.1.0-rc.11.1
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/capabilities.d.ts +7 -7
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +29 -4
- package/dist/capabilities.js.map +1 -1
- package/dist/chart.d.ts +43 -0
- package/dist/chart.d.ts.map +1 -0
- package/dist/chart.js +105 -0
- package/dist/chart.js.map +1 -0
- package/dist/collections.d.ts +46 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +48 -0
- package/dist/collections.js.map +1 -0
- package/dist/contracts.d.ts +20 -0
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +2 -0
- package/dist/contracts.js.map +1 -1
- package/dist/discovery.d.ts +49 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +80 -0
- package/dist/discovery.js.map +1 -0
- package/dist/experimental-regions.d.ts +10 -0
- package/dist/experimental-regions.d.ts.map +1 -1
- package/dist/experimental-regions.js +23 -0
- package/dist/experimental-regions.js.map +1 -1
- package/dist/experimental.d.ts +5 -0
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +29 -0
- package/dist/experimental.js.map +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/interactive.d.ts +36 -0
- package/dist/interactive.d.ts.map +1 -0
- package/dist/interactive.js +61 -0
- package/dist/interactive.js.map +1 -0
- package/dist/link.d.ts +2 -0
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js.map +1 -1
- package/dist/motion.d.ts +8 -0
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +11 -0
- package/dist/motion.js.map +1 -1
- package/dist/navigation-transition.d.ts +10 -0
- package/dist/navigation-transition.d.ts.map +1 -0
- package/dist/navigation-transition.js +10 -0
- package/dist/navigation-transition.js.map +1 -0
- package/dist/number-flow-format.d.ts +16 -0
- package/dist/number-flow-format.d.ts.map +1 -0
- package/dist/number-flow-format.js +49 -0
- package/dist/number-flow-format.js.map +1 -0
- package/dist/popover.d.ts +17 -0
- package/dist/popover.d.ts.map +1 -0
- package/dist/popover.js +19 -0
- package/dist/popover.js.map +1 -0
- package/dist/section-scroll.d.ts +14 -0
- package/dist/section-scroll.d.ts.map +1 -0
- package/dist/section-scroll.js +28 -0
- package/dist/section-scroll.js.map +1 -0
- package/dist/time.d.ts +34 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +78 -0
- package/dist/time.js.map +1 -0
- package/dist/vue/carousel.d.ts +13 -0
- package/dist/vue/carousel.d.ts.map +1 -0
- package/dist/vue/carousel.js +136 -0
- package/dist/vue/carousel.js.map +1 -0
- package/dist/vue/chart.d.ts +194 -0
- package/dist/vue/chart.d.ts.map +1 -0
- package/dist/vue/chart.js +245 -0
- package/dist/vue/chart.js.map +1 -0
- package/dist/vue/command-palette.d.ts +129 -0
- package/dist/vue/command-palette.d.ts.map +1 -0
- package/dist/vue/command-palette.js +190 -0
- package/dist/vue/command-palette.js.map +1 -0
- package/dist/vue/component-motion.d.ts +17 -0
- package/dist/vue/component-motion.d.ts.map +1 -0
- package/dist/vue/component-motion.js +83 -0
- package/dist/vue/component-motion.js.map +1 -0
- package/dist/vue/component-props.d.ts +1016 -18
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/component-props.js +28 -0
- package/dist/vue/component-props.js.map +1 -1
- package/dist/vue/configurator.d.ts +2 -2
- package/dist/vue/configurator.d.ts.map +1 -1
- package/dist/vue/configurator.js +3 -1
- package/dist/vue/configurator.js.map +1 -1
- package/dist/vue/data-table.d.ts +17 -0
- package/dist/vue/data-table.d.ts.map +1 -0
- package/dist/vue/data-table.js +133 -0
- package/dist/vue/data-table.js.map +1 -0
- package/dist/vue/date-calendar.d.ts +2 -0
- package/dist/vue/date-calendar.d.ts.map +1 -1
- package/dist/vue/date-calendar.js +20 -1
- package/dist/vue/date-calendar.js.map +1 -1
- package/dist/vue/date-picker.d.ts +8 -8
- package/dist/vue/date-props.d.ts +6 -0
- package/dist/vue/date-props.d.ts.map +1 -1
- package/dist/vue/date-props.js +3 -0
- package/dist/vue/date-props.js.map +1 -1
- package/dist/vue/discovery-components.d.ts +50 -0
- package/dist/vue/discovery-components.d.ts.map +1 -0
- package/dist/vue/discovery-components.js +2 -0
- package/dist/vue/discovery-components.js.map +1 -0
- package/dist/vue/discovery-controls.d.ts +197 -0
- package/dist/vue/discovery-controls.d.ts.map +1 -0
- package/dist/vue/discovery-controls.js +185 -0
- package/dist/vue/discovery-controls.js.map +1 -0
- package/dist/vue/discovery-props.d.ts +249 -0
- package/dist/vue/discovery-props.d.ts.map +1 -0
- package/dist/vue/discovery-props.js +87 -0
- package/dist/vue/discovery-props.js.map +1 -0
- package/dist/vue/global-components.d.ts +131 -0
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +25 -0
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +21 -0
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/interactive-components.d.ts +31 -0
- package/dist/vue/interactive-components.d.ts.map +1 -0
- package/dist/vue/interactive-components.js +2 -0
- package/dist/vue/interactive-components.js.map +1 -0
- package/dist/vue/interactive-props.d.ts +254 -0
- package/dist/vue/interactive-props.d.ts.map +1 -0
- package/dist/vue/interactive-props.js +85 -0
- package/dist/vue/interactive-props.js.map +1 -0
- package/dist/vue/list-motion.d.ts +7 -0
- package/dist/vue/list-motion.d.ts.map +1 -0
- package/dist/vue/list-motion.js +28 -0
- package/dist/vue/list-motion.js.map +1 -0
- package/dist/vue/menu.d.ts +122 -0
- package/dist/vue/menu.d.ts.map +1 -0
- package/dist/vue/menu.js +79 -0
- package/dist/vue/menu.js.map +1 -0
- package/dist/vue/navigation-controls.d.ts +125 -0
- package/dist/vue/navigation-controls.d.ts.map +1 -0
- package/dist/vue/navigation-controls.js +130 -0
- package/dist/vue/navigation-controls.js.map +1 -0
- package/dist/vue/navigation-props.d.ts +283 -0
- package/dist/vue/navigation-props.d.ts.map +1 -0
- package/dist/vue/navigation-props.js +82 -0
- package/dist/vue/navigation-props.js.map +1 -0
- package/dist/vue/number-flow.d.ts +75 -0
- package/dist/vue/number-flow.d.ts.map +1 -0
- package/dist/vue/number-flow.js +57 -0
- package/dist/vue/number-flow.js.map +1 -0
- package/dist/vue/partition.d.ts +15 -0
- package/dist/vue/partition.d.ts.map +1 -0
- package/dist/vue/partition.js +42 -0
- package/dist/vue/partition.js.map +1 -0
- package/dist/vue/platform.d.ts +37 -0
- package/dist/vue/platform.d.ts.map +1 -0
- package/dist/vue/platform.js +46 -0
- package/dist/vue/platform.js.map +1 -0
- package/dist/vue/props.d.ts +76 -36
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +3 -1
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/sortable-list.d.ts +24 -0
- package/dist/vue/sortable-list.d.ts.map +1 -0
- package/dist/vue/sortable-list.js +251 -0
- package/dist/vue/sortable-list.js.map +1 -0
- package/dist/vue/swipe-actions.d.ts +96 -0
- package/dist/vue/swipe-actions.d.ts.map +1 -0
- package/dist/vue/swipe-actions.js +174 -0
- package/dist/vue/swipe-actions.js.map +1 -0
- package/dist/vue/time-picker.d.ts +488 -0
- package/dist/vue/time-picker.d.ts.map +1 -0
- package/dist/vue/time-picker.js +190 -0
- package/dist/vue/time-picker.js.map +1 -0
- package/dist/vue/tree-view.d.ts +111 -0
- package/dist/vue/tree-view.d.ts.map +1 -0
- package/dist/vue/tree-view.js +204 -0
- package/dist/vue/tree-view.js.map +1 -0
- package/dist/vue/virtual-list.d.ts +26 -0
- package/dist/vue/virtual-list.d.ts.map +1 -0
- package/dist/vue/virtual-list.js +2 -0
- package/dist/vue/virtual-list.js.map +1 -0
- package/dist/vue/wayfinding-controls.d.ts +199 -0
- package/dist/vue/wayfinding-controls.d.ts.map +1 -0
- package/dist/vue/wayfinding-controls.js +330 -0
- package/dist/vue/wayfinding-controls.js.map +1 -0
- package/dist/vue/wayfinding-props.d.ts +221 -0
- package/dist/vue/wayfinding-props.d.ts.map +1 -0
- package/dist/vue/wayfinding-props.js +86 -0
- package/dist/vue/wayfinding-props.js.map +1 -0
- package/dist/vue/workflows.d.ts +2 -2
- package/dist/vue/workflows.d.ts.map +1 -1
- package/dist/vue/workflows.js +17 -4
- package/dist/vue/workflows.js.map +1 -1
- package/dist/wayfinding.d.ts +50 -0
- package/dist/wayfinding.d.ts.map +1 -0
- package/dist/wayfinding.js +54 -0
- package/dist/wayfinding.js.map +1 -0
- package/package.json +2 -2
- package/src/capabilities.ts +30 -4
- package/src/chart.ts +151 -0
- package/src/collections.ts +87 -0
- package/src/contracts.ts +2 -0
- package/src/discovery.ts +139 -0
- package/src/experimental-regions.ts +29 -0
- package/src/experimental.ts +40 -0
- package/src/index.ts +18 -1
- package/src/interactive.ts +91 -0
- package/src/link.ts +2 -0
- package/src/motion.ts +14 -0
- package/src/navigation-transition.ts +14 -0
- package/src/number-flow-format.ts +68 -0
- package/src/popover.ts +38 -0
- package/src/section-scroll.ts +46 -0
- package/src/time.ts +83 -0
- package/src/vue/carousel.ts +198 -0
- package/src/vue/chart.ts +337 -0
- package/src/vue/command-palette.ts +235 -0
- package/src/vue/component-motion.ts +109 -0
- package/src/vue/component-props.ts +57 -0
- package/src/vue/configurator.ts +3 -1
- package/src/vue/data-table.ts +190 -0
- package/src/vue/date-calendar.ts +30 -1
- package/src/vue/date-props.ts +3 -0
- package/src/vue/discovery-components.ts +60 -0
- package/src/vue/discovery-controls.ts +241 -0
- package/src/vue/discovery-props.ts +92 -0
- package/src/vue/global-components.ts +121 -0
- package/src/vue/index.ts +44 -0
- package/src/vue/interactive-components.ts +29 -0
- package/src/vue/interactive-props.ts +90 -0
- package/src/vue/list-motion.ts +31 -0
- package/src/vue/menu.ts +100 -0
- package/src/vue/navigation-controls.ts +159 -0
- package/src/vue/navigation-props.ts +87 -0
- package/src/vue/number-flow.ts +83 -0
- package/src/vue/partition.ts +49 -0
- package/src/vue/platform.ts +73 -0
- package/src/vue/props.ts +3 -1
- package/src/vue/sortable-list.ts +308 -0
- package/src/vue/swipe-actions.ts +226 -0
- package/src/vue/time-picker.ts +227 -0
- package/src/vue/tree-view.ts +259 -0
- package/src/vue/virtual-list.ts +28 -0
- package/src/vue/wayfinding-controls.ts +430 -0
- package/src/vue/wayfinding-props.ts +97 -0
- package/src/vue/workflows.ts +17 -4
- package/src/wayfinding.ts +85 -0
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sortableListProps,
|
|
3
|
+
swipeActionsProps,
|
|
4
|
+
numberFlowProps,
|
|
5
|
+
resizablePanelsProps,
|
|
6
|
+
imageCompareProps,
|
|
7
|
+
imageViewerProps,
|
|
8
|
+
} from './interactive-props.js'
|
|
9
|
+
import {
|
|
10
|
+
commandPaletteProps,
|
|
11
|
+
navigationRailProps,
|
|
12
|
+
breadcrumbProps,
|
|
13
|
+
tooltipProps,
|
|
14
|
+
timelineProps,
|
|
15
|
+
chartProps,
|
|
16
|
+
} from './wayfinding-props.js'
|
|
17
|
+
import {
|
|
18
|
+
dataTableProps,
|
|
19
|
+
carouselProps,
|
|
20
|
+
rangeSliderProps,
|
|
21
|
+
calendarProps,
|
|
22
|
+
ratingProps,
|
|
23
|
+
treeViewProps,
|
|
24
|
+
} from './discovery-props.js'
|
|
25
|
+
import {
|
|
26
|
+
popoverProps,
|
|
27
|
+
menuProps,
|
|
28
|
+
appBarProps,
|
|
29
|
+
tabBarProps,
|
|
30
|
+
timePickerProps,
|
|
31
|
+
virtualListProps,
|
|
32
|
+
} from './navigation-props.js'
|
|
1
33
|
import { numberInputProps, multiSelectProps, imageProps } from './configurator-props.js'
|
|
2
34
|
import type { ExtractPublicPropTypes } from '@vue/runtime-core'
|
|
3
35
|
import type { SheetName } from '../sheet.js'
|
|
@@ -10,6 +42,25 @@ import { formGroupProps, formErrorsProps, stepsProps, paginationProps } from './
|
|
|
10
42
|
/** Complete registry, kept separate from the primitives used to compose controls. */
|
|
11
43
|
export const componentProps = {
|
|
12
44
|
...foundationProps,
|
|
45
|
+
MSortableList: sortableListProps,
|
|
46
|
+
MSwipeActions: swipeActionsProps,
|
|
47
|
+
MNumberFlow: numberFlowProps,
|
|
48
|
+
MResizablePanels: resizablePanelsProps,
|
|
49
|
+
MImageCompare: imageCompareProps,
|
|
50
|
+
MImageViewer: imageViewerProps,
|
|
51
|
+
|
|
52
|
+
MCommandPalette: commandPaletteProps,
|
|
53
|
+
MNavigationRail: navigationRailProps,
|
|
54
|
+
MBreadcrumb: breadcrumbProps,
|
|
55
|
+
MTooltip: tooltipProps,
|
|
56
|
+
MTimeline: timelineProps,
|
|
57
|
+
MChart: chartProps,
|
|
58
|
+
MDataTable: dataTableProps,
|
|
59
|
+
MCarousel: carouselProps,
|
|
60
|
+
MRangeSlider: rangeSliderProps,
|
|
61
|
+
MCalendar: calendarProps,
|
|
62
|
+
MRating: ratingProps,
|
|
63
|
+
MTreeView: treeViewProps,
|
|
13
64
|
MNumberInput: numberInputProps,
|
|
14
65
|
MMultiSelect: multiSelectProps,
|
|
15
66
|
MImage: imageProps,
|
|
@@ -21,6 +72,12 @@ export const componentProps = {
|
|
|
21
72
|
MFormErrors: formErrorsProps,
|
|
22
73
|
MSteps: stepsProps,
|
|
23
74
|
MPagination: paginationProps,
|
|
75
|
+
MPopover: popoverProps,
|
|
76
|
+
MMenu: menuProps,
|
|
77
|
+
MAppBar: appBarProps,
|
|
78
|
+
MTabBar: tabBarProps,
|
|
79
|
+
MTimePicker: timePickerProps,
|
|
80
|
+
MVirtualList: virtualListProps,
|
|
24
81
|
}
|
|
25
82
|
export type ComponentProps = {
|
|
26
83
|
[Name in keyof typeof componentProps]: ExtractPublicPropTypes<(typeof componentProps)[Name]> &
|
package/src/vue/configurator.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useComponentLayout } from './component-motion.js'
|
|
1
2
|
import {
|
|
2
3
|
computed,
|
|
3
4
|
onBeforeUnmount,
|
|
@@ -206,6 +207,7 @@ export function createConfiguratorControls(ui: Primitives, platform: 'web' | 'na
|
|
|
206
207
|
props: multiSelectProps,
|
|
207
208
|
emits: { 'update:modelValue': (_values: ChoiceValue[]) => true },
|
|
208
209
|
setup(props, { attrs, emit }) {
|
|
210
|
+
const selectedMotion = useComponentLayout(() => props.modelValue)
|
|
209
211
|
useButtonAction()
|
|
210
212
|
const open = ref(false),
|
|
211
213
|
query = ref('')
|
|
@@ -268,7 +270,7 @@ export function createConfiguratorControls(ui: Primitives, platform: 'web' | 'na
|
|
|
268
270
|
},
|
|
269
271
|
}),
|
|
270
272
|
selected.length
|
|
271
|
-
? h(ui.Row, { gap: 'sm', wrap: true }, () =>
|
|
273
|
+
? h(ui.Row, { gap: 'sm', wrap: true, motionRegion: selectedMotion }, () =>
|
|
272
274
|
selected.map((option) =>
|
|
273
275
|
h(ui.Chip, {
|
|
274
276
|
key: choiceKey(option.value),
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type { DataTableComponent } from './discovery-components.js'
|
|
2
|
+
import {
|
|
3
|
+
computed,
|
|
4
|
+
defineComponent,
|
|
5
|
+
h,
|
|
6
|
+
mergeProps,
|
|
7
|
+
type Component,
|
|
8
|
+
type VNodeChild,
|
|
9
|
+
} from '@vue/runtime-core'
|
|
10
|
+
import { choiceKey, type ChoiceValue } from '../choice.js'
|
|
11
|
+
import {
|
|
12
|
+
collectionKeys,
|
|
13
|
+
nextDataSort,
|
|
14
|
+
selectPage,
|
|
15
|
+
validateColumns,
|
|
16
|
+
type DataColumn,
|
|
17
|
+
type DataSort,
|
|
18
|
+
} from '../discovery.js'
|
|
19
|
+
import { dataTableProps } from './discovery-props.js'
|
|
20
|
+
import { useMavisTheme } from './theme.js'
|
|
21
|
+
|
|
22
|
+
export function createDataTable(
|
|
23
|
+
ui: {
|
|
24
|
+
Column: Component
|
|
25
|
+
Row: Component
|
|
26
|
+
Text: Component
|
|
27
|
+
Button: Component
|
|
28
|
+
Checkbox: Component
|
|
29
|
+
Progress: Component
|
|
30
|
+
table: (
|
|
31
|
+
columns: readonly DataColumn[],
|
|
32
|
+
header: VNodeChild[],
|
|
33
|
+
rows: { key: string; cells: VNodeChild[]; selected: boolean }[],
|
|
34
|
+
label: string,
|
|
35
|
+
busy: boolean,
|
|
36
|
+
) => VNodeChild
|
|
37
|
+
},
|
|
38
|
+
platform: 'web' | 'native',
|
|
39
|
+
) {
|
|
40
|
+
return defineComponent({
|
|
41
|
+
name: 'MDataTable',
|
|
42
|
+
inheritAttrs: false,
|
|
43
|
+
props: dataTableProps,
|
|
44
|
+
emits: {
|
|
45
|
+
'update:sort': (_sort: DataSort | null) => true,
|
|
46
|
+
'update:selected': (_selected: ChoiceValue[]) => true,
|
|
47
|
+
},
|
|
48
|
+
setup(props, { attrs, slots, emit }) {
|
|
49
|
+
const { theme } = useMavisTheme()
|
|
50
|
+
const keys = computed(() => collectionKeys(props.items, props.itemKey))
|
|
51
|
+
const selectable = computed(() =>
|
|
52
|
+
keys.value.filter((_, index) => !props.rowDisabled?.(props.items[index]!)),
|
|
53
|
+
)
|
|
54
|
+
const selectedIds = computed(() => new Set(props.selected.map(choiceKey)))
|
|
55
|
+
function select(page: readonly ChoiceValue[], checked: boolean) {
|
|
56
|
+
if (!props.disabled && !props.loading)
|
|
57
|
+
emit('update:selected', selectPage(props.selected, page, checked))
|
|
58
|
+
}
|
|
59
|
+
return () => {
|
|
60
|
+
validateColumns(props.columns)
|
|
61
|
+
if (
|
|
62
|
+
props.sort &&
|
|
63
|
+
!props.columns.some((column) => column.key === props.sort!.key && column.sortable)
|
|
64
|
+
)
|
|
65
|
+
throw new RangeError('Sort must identify a sortable column.')
|
|
66
|
+
const count = selectable.value.filter((key) => selectedIds.value.has(choiceKey(key))).length
|
|
67
|
+
const headers = props.columns.map((column) =>
|
|
68
|
+
column.sortable
|
|
69
|
+
? h(ui.Button, {
|
|
70
|
+
text: column.label,
|
|
71
|
+
variant: 'ghost',
|
|
72
|
+
disabled: props.disabled || props.loading,
|
|
73
|
+
icon:
|
|
74
|
+
props.sort?.key !== column.key
|
|
75
|
+
? 'arrow-up-down'
|
|
76
|
+
: props.sort.direction === 'ascending'
|
|
77
|
+
? 'arrow-up'
|
|
78
|
+
: 'arrow-down',
|
|
79
|
+
accessibilityLabel: `${column.label}${platform === 'native' && props.sort?.key === column.key ? `, ${props.sort.direction}` : ''}`,
|
|
80
|
+
onClick: () => {
|
|
81
|
+
if (!props.disabled && !props.loading)
|
|
82
|
+
emit('update:sort', nextDataSort(props.sort, column.key))
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
: h(ui.Text, { text: column.label, weight: '600', variant: 'caption' }),
|
|
86
|
+
)
|
|
87
|
+
const columns = props.columns.map((column) => ({
|
|
88
|
+
...column,
|
|
89
|
+
sort: props.sort?.key === column.key ? props.sort.direction : undefined,
|
|
90
|
+
}))
|
|
91
|
+
if (props.selectable) {
|
|
92
|
+
let selectionKey = '__mavis_selection'
|
|
93
|
+
while (columns.some((column) => column.key === selectionKey))
|
|
94
|
+
selectionKey = '_' + selectionKey
|
|
95
|
+
columns.unshift({
|
|
96
|
+
key: selectionKey,
|
|
97
|
+
// The checkbox carries the accessible label; this column has no visible caption.
|
|
98
|
+
label: '',
|
|
99
|
+
width: 64,
|
|
100
|
+
sort: undefined,
|
|
101
|
+
})
|
|
102
|
+
headers.unshift(
|
|
103
|
+
h(ui.Checkbox, {
|
|
104
|
+
label: props.selectAllLabel,
|
|
105
|
+
modelValue: count > 0 && count === selectable.value.length,
|
|
106
|
+
indeterminate: count > 0 && count < selectable.value.length,
|
|
107
|
+
disabled: props.disabled || props.loading || !selectable.value.length,
|
|
108
|
+
'onUpdate:modelValue': (value: boolean) => select(selectable.value, value),
|
|
109
|
+
...(platform === 'web' ? { class: 'm-data-table-selection' } : {}),
|
|
110
|
+
}),
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
const rows = props.items.map((item, index) => {
|
|
114
|
+
const key = keys.value[index]!
|
|
115
|
+
const cells = props.columns.map((column) => {
|
|
116
|
+
const raw = column.value ? column.value(item) : item[column.key]
|
|
117
|
+
const value =
|
|
118
|
+
raw == null || typeof raw === 'string' || typeof raw === 'number' ? raw : String(raw)
|
|
119
|
+
const slot = { item, itemKey: key, column, value, index }
|
|
120
|
+
return (
|
|
121
|
+
slots[`cell:${column.key}`]?.(slot) ??
|
|
122
|
+
slots.cell?.(slot) ??
|
|
123
|
+
h(ui.Text, {
|
|
124
|
+
text: String(value ?? '—'),
|
|
125
|
+
align: column.align === 'end' ? 'right' : 'left',
|
|
126
|
+
})
|
|
127
|
+
)
|
|
128
|
+
})
|
|
129
|
+
if (props.selectable)
|
|
130
|
+
cells.unshift(
|
|
131
|
+
h(ui.Checkbox, {
|
|
132
|
+
label: `${props.selectLabel} ${props.rowLabel?.(item) ?? String(key)}`,
|
|
133
|
+
modelValue: selectedIds.value.has(choiceKey(key)),
|
|
134
|
+
disabled: props.disabled || props.loading || props.rowDisabled?.(item),
|
|
135
|
+
'onUpdate:modelValue': (value: boolean) => {
|
|
136
|
+
if (!props.rowDisabled?.(item)) select([key], value)
|
|
137
|
+
},
|
|
138
|
+
...(platform === 'web' ? { class: 'm-data-table-selection' } : {}),
|
|
139
|
+
}),
|
|
140
|
+
)
|
|
141
|
+
return { key: choiceKey(key), cells, selected: selectedIds.value.has(choiceKey(key)) }
|
|
142
|
+
})
|
|
143
|
+
return h(
|
|
144
|
+
ui.Column,
|
|
145
|
+
mergeProps(
|
|
146
|
+
{ id: props.id, gap: 'md' },
|
|
147
|
+
attrs,
|
|
148
|
+
platform === 'web'
|
|
149
|
+
? {
|
|
150
|
+
class: 'm-data-table',
|
|
151
|
+
style: {
|
|
152
|
+
'--m-color-border': theme.value.colors.border,
|
|
153
|
+
'--m-color-primarySoft': theme.value.colors.primarySoft,
|
|
154
|
+
},
|
|
155
|
+
}
|
|
156
|
+
: {},
|
|
157
|
+
),
|
|
158
|
+
() => [
|
|
159
|
+
h(ui.Row, { justify: 'between', gap: 'md', wrap: true }, () => [
|
|
160
|
+
h(ui.Text, { as: 'h2', variant: 'heading', text: props.label }),
|
|
161
|
+
slots.actions?.(),
|
|
162
|
+
]),
|
|
163
|
+
h(
|
|
164
|
+
ui.Column,
|
|
165
|
+
{ radius: 'lg', backgroundColor: theme.value.colors.surface, gap: 'none' },
|
|
166
|
+
() => [
|
|
167
|
+
props.loading
|
|
168
|
+
? h(ui.Progress, { indeterminate: true, label: props.loadingLabel, size: 'sm' })
|
|
169
|
+
: null,
|
|
170
|
+
ui.table(columns, headers, rows, props.label, props.loading),
|
|
171
|
+
!rows.length
|
|
172
|
+
? (slots.empty?.() ??
|
|
173
|
+
h(ui.Text, {
|
|
174
|
+
text: props.loading ? props.loadingLabel : props.emptyLabel,
|
|
175
|
+
tone: 'muted',
|
|
176
|
+
style: { padding: 24 },
|
|
177
|
+
...(platform === 'web'
|
|
178
|
+
? { role: 'status' }
|
|
179
|
+
: { accessibilityLiveRegion: 'polite' }),
|
|
180
|
+
}))
|
|
181
|
+
: null,
|
|
182
|
+
],
|
|
183
|
+
),
|
|
184
|
+
slots.footer?.(),
|
|
185
|
+
],
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
}) as unknown as DataTableComponent
|
|
190
|
+
}
|
package/src/vue/date-calendar.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createMotionSurface } from '../experimental.js'
|
|
2
|
+
import { componentMotion } from '../motion.js'
|
|
3
|
+
import { useMavisTheme } from './theme.js'
|
|
4
|
+
import { computed, watch, markRaw, onScopeDispose, type ExtractPropTypes } from '@vue/runtime-core'
|
|
2
5
|
import {
|
|
3
6
|
addCivilDays,
|
|
4
7
|
addCivilMonths,
|
|
@@ -74,3 +77,29 @@ export function useDateCalendar(
|
|
|
74
77
|
)
|
|
75
78
|
return { words, title, firstDay, cells, weekdays, available, move, canPage, page, key, inRange }
|
|
76
79
|
}
|
|
80
|
+
|
|
81
|
+
/** Month presentation never delays canonical dates or keyboard focus. */
|
|
82
|
+
export function useCalendarMotion(read: () => string) {
|
|
83
|
+
const { theme } = useMavisTheme()
|
|
84
|
+
const surface = markRaw(createMotionSurface())
|
|
85
|
+
onScopeDispose(
|
|
86
|
+
surface.use((owner) => {
|
|
87
|
+
owner.set({ x: 0, opacity: 1 })
|
|
88
|
+
}),
|
|
89
|
+
)
|
|
90
|
+
watch(
|
|
91
|
+
() => read().slice(0, 7),
|
|
92
|
+
(month, previous) => {
|
|
93
|
+
if (surface.available)
|
|
94
|
+
surface.animate(
|
|
95
|
+
{
|
|
96
|
+
x: [(month > previous ? 1 : -1) * theme.value.motion.enterOffset * 2, 0],
|
|
97
|
+
opacity: [0.65, 1],
|
|
98
|
+
},
|
|
99
|
+
componentMotion(theme.value, 'overlay'),
|
|
100
|
+
)
|
|
101
|
+
},
|
|
102
|
+
{ flush: 'post' },
|
|
103
|
+
)
|
|
104
|
+
return surface
|
|
105
|
+
}
|
package/src/vue/date-props.ts
CHANGED
|
@@ -74,6 +74,9 @@ export type DateRangePickerProps = ExtractPublicPropTypes<typeof dateRangePicker
|
|
|
74
74
|
|
|
75
75
|
/** @internal Shared themed calendar presentation contract. */
|
|
76
76
|
export const dateCalendarProps = {
|
|
77
|
+
autofocus: { type: Boolean, default: true },
|
|
78
|
+
disabled: Boolean,
|
|
79
|
+
readonly: Boolean,
|
|
77
80
|
...dateOptions,
|
|
78
81
|
activeDate: { type: String as PropType<CivilDate>, required: true as const },
|
|
79
82
|
selected: { type: String as PropType<CivilDate | null>, default: null },
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { PublicProps, VNode, VNodeChild } from '@vue/runtime-core'
|
|
2
|
+
import type { ComponentProps } from './component-props.js'
|
|
3
|
+
import type { ChoiceValue } from '../choice.js'
|
|
4
|
+
import type { VirtualItemSlot } from '../collections.js'
|
|
5
|
+
import type { DataColumn, DataCellSlot, DataSort } from '../discovery.js'
|
|
6
|
+
|
|
7
|
+
type Key<T> = Extract<keyof T, string> | ((item: T) => ChoiceValue)
|
|
8
|
+
interface Context<P, S> {
|
|
9
|
+
props: P
|
|
10
|
+
attrs: Record<string, unknown>
|
|
11
|
+
emit: (event: string, ...args: unknown[]) => void
|
|
12
|
+
slots: S
|
|
13
|
+
}
|
|
14
|
+
type CarouselProps<T> = PublicProps &
|
|
15
|
+
Omit<ComponentProps['MCarousel'], 'items' | 'itemKey'> & {
|
|
16
|
+
items: readonly T[]
|
|
17
|
+
itemKey?: Key<T>
|
|
18
|
+
'onUpdate:modelValue'?: (key: ChoiceValue) => void
|
|
19
|
+
}
|
|
20
|
+
type CarouselContext<T> = Context<
|
|
21
|
+
CarouselProps<T>,
|
|
22
|
+
{ default?: (scope: VirtualItemSlot<T>) => VNodeChild; empty?: () => VNodeChild }
|
|
23
|
+
>
|
|
24
|
+
export interface CarouselComponent {
|
|
25
|
+
<T>(
|
|
26
|
+
props: NonNullable<Awaited<typeof setup>>['props'],
|
|
27
|
+
context?: Pick<NonNullable<Awaited<typeof setup>>, 'attrs' | 'emit' | 'slots'>,
|
|
28
|
+
exposed?: undefined,
|
|
29
|
+
setup?: Promise<CarouselContext<T>>,
|
|
30
|
+
): VNode & { __ctx?: NonNullable<Awaited<typeof setup>> }
|
|
31
|
+
}
|
|
32
|
+
type TableProps<T> = PublicProps &
|
|
33
|
+
Omit<
|
|
34
|
+
ComponentProps['MDataTable'],
|
|
35
|
+
'items' | 'itemKey' | 'columns' | 'rowLabel' | 'rowDisabled'
|
|
36
|
+
> & {
|
|
37
|
+
items: readonly T[]
|
|
38
|
+
itemKey?: Key<T>
|
|
39
|
+
columns: readonly DataColumn<T>[]
|
|
40
|
+
rowLabel?: (item: T) => string
|
|
41
|
+
rowDisabled?: (item: T) => boolean
|
|
42
|
+
'onUpdate:sort'?: (sort: DataSort | null) => void
|
|
43
|
+
'onUpdate:selected'?: (keys: ChoiceValue[]) => void
|
|
44
|
+
}
|
|
45
|
+
type TableSlots<T> = {
|
|
46
|
+
cell?: (scope: DataCellSlot<T>) => VNodeChild
|
|
47
|
+
actions?: () => VNodeChild
|
|
48
|
+
footer?: () => VNodeChild
|
|
49
|
+
empty?: () => VNodeChild
|
|
50
|
+
} & {
|
|
51
|
+
[name: `cell:${string}`]: ((scope: DataCellSlot<T>) => VNodeChild) | undefined
|
|
52
|
+
}
|
|
53
|
+
export interface DataTableComponent {
|
|
54
|
+
<T>(
|
|
55
|
+
props: NonNullable<Awaited<typeof setup>>['props'],
|
|
56
|
+
context?: Pick<NonNullable<Awaited<typeof setup>>, 'attrs' | 'emit' | 'slots'>,
|
|
57
|
+
exposed?: undefined,
|
|
58
|
+
setup?: Promise<Context<TableProps<T>, TableSlots<T>>>,
|
|
59
|
+
): VNode & { __ctx?: NonNullable<Awaited<typeof setup>> }
|
|
60
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { useComponentState } from './component-motion.js'
|
|
2
|
+
import {
|
|
3
|
+
computed,
|
|
4
|
+
defineComponent,
|
|
5
|
+
h,
|
|
6
|
+
mergeProps,
|
|
7
|
+
ref,
|
|
8
|
+
watch,
|
|
9
|
+
type Component,
|
|
10
|
+
} from '@vue/runtime-core'
|
|
11
|
+
import { calendarProps, ratingProps } from './discovery-props.js'
|
|
12
|
+
import { ratingValue } from '../discovery.js'
|
|
13
|
+
import {
|
|
14
|
+
civilDate,
|
|
15
|
+
dateAvailability,
|
|
16
|
+
validateDateConstraints,
|
|
17
|
+
validateDateRangeDraft,
|
|
18
|
+
type CivilDate,
|
|
19
|
+
type DateRange,
|
|
20
|
+
} from '../date.js'
|
|
21
|
+
import { useMavisTheme } from './theme.js'
|
|
22
|
+
|
|
23
|
+
interface Primitives {
|
|
24
|
+
Column: Component
|
|
25
|
+
Row: Component
|
|
26
|
+
Text: Component
|
|
27
|
+
Button: Component
|
|
28
|
+
Icon: Component
|
|
29
|
+
Slider: Component
|
|
30
|
+
Calendar: Component
|
|
31
|
+
}
|
|
32
|
+
function initialCalendarDate(
|
|
33
|
+
value: CivilDate | null,
|
|
34
|
+
props: { min?: CivilDate; max?: CivilDate; initialMonth: string },
|
|
35
|
+
) {
|
|
36
|
+
let date = value ?? props.min ?? civilDate(`${props.initialMonth}-01`)
|
|
37
|
+
if (props.min && date < props.min) date = props.min
|
|
38
|
+
if (props.max && date > props.max) date = props.max
|
|
39
|
+
return date
|
|
40
|
+
}
|
|
41
|
+
export function createDiscoveryControls(ui: Primitives, platform: 'web' | 'native') {
|
|
42
|
+
const MCalendar = defineComponent({
|
|
43
|
+
name: 'MCalendar',
|
|
44
|
+
inheritAttrs: false,
|
|
45
|
+
props: calendarProps,
|
|
46
|
+
emits: {
|
|
47
|
+
'update:modelValue': (_value: CivilDate | DateRange | null) => true,
|
|
48
|
+
invalid: () => true,
|
|
49
|
+
},
|
|
50
|
+
setup(props, { attrs, emit, slots }) {
|
|
51
|
+
const { theme } = useMavisTheme()
|
|
52
|
+
const selected = computed(() =>
|
|
53
|
+
typeof props.modelValue === 'string' ? civilDate(props.modelValue) : null,
|
|
54
|
+
)
|
|
55
|
+
const range = computed(() =>
|
|
56
|
+
typeof props.modelValue === 'object' && props.modelValue !== null
|
|
57
|
+
? props.modelValue
|
|
58
|
+
: { start: null, end: null },
|
|
59
|
+
)
|
|
60
|
+
const active = ref<CivilDate>(initialCalendarDate(selected.value ?? range.value.start, props))
|
|
61
|
+
const invalid = ref(false)
|
|
62
|
+
watch(
|
|
63
|
+
() => [props.modelValue, props.initialMonth],
|
|
64
|
+
() => {
|
|
65
|
+
active.value = initialCalendarDate(
|
|
66
|
+
selected.value ?? range.value.end ?? range.value.start,
|
|
67
|
+
props,
|
|
68
|
+
)
|
|
69
|
+
invalid.value = false
|
|
70
|
+
},
|
|
71
|
+
)
|
|
72
|
+
function select(date: CivilDate) {
|
|
73
|
+
if (props.disabled || props.readonly || dateAvailability(date, props)) return
|
|
74
|
+
invalid.value = false
|
|
75
|
+
if (props.mode === 'single') emit('update:modelValue', date)
|
|
76
|
+
else if (!range.value.start || range.value.end)
|
|
77
|
+
emit('update:modelValue', { start: date, end: null })
|
|
78
|
+
else {
|
|
79
|
+
const next =
|
|
80
|
+
date < range.value.start
|
|
81
|
+
? { start: date, end: range.value.start }
|
|
82
|
+
: { start: range.value.start, end: date }
|
|
83
|
+
if (!validateDateRangeDraft({ start: next.start, end: next.end }, props).valid) {
|
|
84
|
+
invalid.value = true
|
|
85
|
+
emit('invalid')
|
|
86
|
+
} else emit('update:modelValue', next)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return () => {
|
|
90
|
+
validateDateConstraints(props)
|
|
91
|
+
if (
|
|
92
|
+
props.mode === 'single' &&
|
|
93
|
+
props.modelValue !== null &&
|
|
94
|
+
typeof props.modelValue !== 'string'
|
|
95
|
+
)
|
|
96
|
+
throw new TypeError('Single calendars require a civil date.')
|
|
97
|
+
if (props.mode === 'range' && typeof props.modelValue === 'string')
|
|
98
|
+
throw new TypeError('Range calendars require start and end.')
|
|
99
|
+
for (const date of [range.value.start, range.value.end]) if (date !== null) civilDate(date)
|
|
100
|
+
return h(
|
|
101
|
+
ui.Column,
|
|
102
|
+
mergeProps(
|
|
103
|
+
{
|
|
104
|
+
id: props.id,
|
|
105
|
+
gap: 'md',
|
|
106
|
+
padding: 'sm',
|
|
107
|
+
radius: 'lg',
|
|
108
|
+
backgroundColor: theme.value.colors.surface,
|
|
109
|
+
},
|
|
110
|
+
attrs,
|
|
111
|
+
platform === 'web'
|
|
112
|
+
? { role: 'group', 'aria-label': props.label, class: 'm-calendar' }
|
|
113
|
+
: {},
|
|
114
|
+
),
|
|
115
|
+
() => [
|
|
116
|
+
h(ui.Text, { as: 'h2', variant: 'heading', text: props.label }),
|
|
117
|
+
h(ui.Calendar, {
|
|
118
|
+
...props,
|
|
119
|
+
autofocus: false,
|
|
120
|
+
activeDate: active.value,
|
|
121
|
+
selected: selected.value,
|
|
122
|
+
rangeStart: range.value.start,
|
|
123
|
+
rangeEnd: range.value.end,
|
|
124
|
+
'onUpdate:activeDate': (date: CivilDate) => {
|
|
125
|
+
active.value = date
|
|
126
|
+
},
|
|
127
|
+
onSelect: select,
|
|
128
|
+
}),
|
|
129
|
+
invalid.value
|
|
130
|
+
? h(ui.Text, {
|
|
131
|
+
text: props.invalidRangeLabel,
|
|
132
|
+
tone: 'danger',
|
|
133
|
+
...(platform === 'web'
|
|
134
|
+
? { role: 'alert' }
|
|
135
|
+
: { accessibilityLiveRegion: 'assertive' }),
|
|
136
|
+
})
|
|
137
|
+
: null,
|
|
138
|
+
slots.footer?.(),
|
|
139
|
+
],
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
})
|
|
144
|
+
const RatingStar = defineComponent({
|
|
145
|
+
props: { filled: Boolean, half: Boolean, readonly: Boolean, disabled: Boolean, label: String },
|
|
146
|
+
emits: ['choose'],
|
|
147
|
+
setup(props, { emit }) {
|
|
148
|
+
const motion = useComponentState(
|
|
149
|
+
() => ({
|
|
150
|
+
scale: props.filled || props.half ? 1 : 0.9,
|
|
151
|
+
rotate: props.filled || props.half ? 0 : -8,
|
|
152
|
+
}),
|
|
153
|
+
'feedback',
|
|
154
|
+
)
|
|
155
|
+
return () =>
|
|
156
|
+
props.readonly
|
|
157
|
+
? h(ui.Icon, {
|
|
158
|
+
name: props.half ? 'star-half' : 'star',
|
|
159
|
+
size: 28,
|
|
160
|
+
tone: props.filled || props.half ? 'primary' : 'muted',
|
|
161
|
+
motionSurface: motion,
|
|
162
|
+
accessibilityHidden: true,
|
|
163
|
+
})
|
|
164
|
+
: h(ui.Button, {
|
|
165
|
+
icon: props.half ? 'star-half' : 'star',
|
|
166
|
+
variant: props.filled || props.half ? 'primary' : 'secondary',
|
|
167
|
+
motionSurface: motion,
|
|
168
|
+
disabled: props.disabled,
|
|
169
|
+
accessibilityLabel: props.label,
|
|
170
|
+
onClick: () => emit('choose'),
|
|
171
|
+
})
|
|
172
|
+
},
|
|
173
|
+
})
|
|
174
|
+
const MRating = defineComponent({
|
|
175
|
+
name: 'MRating',
|
|
176
|
+
inheritAttrs: false,
|
|
177
|
+
props: ratingProps,
|
|
178
|
+
emits: { 'update:modelValue': (_value: number) => true },
|
|
179
|
+
setup(props, { attrs, emit }) {
|
|
180
|
+
const value = computed(() => ratingValue(props.modelValue, props.max, props.step))
|
|
181
|
+
const label = (next: number) =>
|
|
182
|
+
props.formatValue?.(next, props.max) ?? `${next} / ${props.max}`
|
|
183
|
+
function choose(next: number) {
|
|
184
|
+
if (!props.readonly && !props.disabled && next !== value.value)
|
|
185
|
+
emit('update:modelValue', ratingValue(next, props.max, props.step))
|
|
186
|
+
}
|
|
187
|
+
return () =>
|
|
188
|
+
h(
|
|
189
|
+
ui.Column,
|
|
190
|
+
mergeProps(
|
|
191
|
+
{ id: props.id, gap: 'sm' },
|
|
192
|
+
attrs,
|
|
193
|
+
platform === 'web'
|
|
194
|
+
? { class: 'm-rating', role: 'group', 'aria-label': props.label }
|
|
195
|
+
: {},
|
|
196
|
+
),
|
|
197
|
+
() => [
|
|
198
|
+
h(ui.Row, { justify: 'between', gap: 'sm', wrap: true }, () => [
|
|
199
|
+
h(ui.Text, { text: props.label, weight: '600' }),
|
|
200
|
+
h(ui.Text, { text: label(value.value), tone: 'muted', variant: 'caption' }),
|
|
201
|
+
]),
|
|
202
|
+
h(ui.Row, { gap: 'xs', wrap: true }, () =>
|
|
203
|
+
Array.from({ length: props.max }, (_, index) => {
|
|
204
|
+
const filled = value.value >= index + 1
|
|
205
|
+
const half = value.value > index && !filled
|
|
206
|
+
return h(RatingStar, {
|
|
207
|
+
key: index,
|
|
208
|
+
filled,
|
|
209
|
+
half,
|
|
210
|
+
readonly: props.readonly,
|
|
211
|
+
disabled: props.disabled,
|
|
212
|
+
label: `${props.label}: ${label(index + 1)}`,
|
|
213
|
+
onChoose: () => choose(index + 1),
|
|
214
|
+
})
|
|
215
|
+
}),
|
|
216
|
+
),
|
|
217
|
+
!props.readonly && props.step === 0.5
|
|
218
|
+
? h(ui.Slider, {
|
|
219
|
+
modelValue: value.value,
|
|
220
|
+
min: 0,
|
|
221
|
+
max: props.max,
|
|
222
|
+
step: props.step,
|
|
223
|
+
label: props.label,
|
|
224
|
+
disabled: props.disabled,
|
|
225
|
+
'onUpdate:modelValue': choose,
|
|
226
|
+
})
|
|
227
|
+
: null,
|
|
228
|
+
props.clearable && !props.readonly
|
|
229
|
+
? h(ui.Button, {
|
|
230
|
+
text: props.clearLabel,
|
|
231
|
+
variant: 'ghost',
|
|
232
|
+
disabled: props.disabled || value.value === 0,
|
|
233
|
+
onClick: () => choose(0),
|
|
234
|
+
})
|
|
235
|
+
: null,
|
|
236
|
+
],
|
|
237
|
+
)
|
|
238
|
+
},
|
|
239
|
+
})
|
|
240
|
+
return { MCalendar, MRating }
|
|
241
|
+
}
|