@getcortexlabs/mavis-core 0.1.0-rc.11.1 → 0.1.0-rc.12.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/advanced-collections.d.ts +74 -0
- package/dist/advanced-collections.d.ts.map +1 -0
- package/dist/advanced-collections.js +129 -0
- package/dist/advanced-collections.js.map +1 -0
- 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/creative-controls.d.ts +47 -0
- package/dist/creative-controls.d.ts.map +1 -0
- package/dist/creative-controls.js +112 -0
- package/dist/creative-controls.js.map +1 -0
- package/dist/dashboard.d.ts +72 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/dashboard.js +115 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/image-crop.d.ts +49 -0
- package/dist/image-crop.d.ts.map +1 -0
- package/dist/image-crop.js +71 -0
- package/dist/image-crop.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/scheduler.d.ts +45 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +142 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/screen-components.d.ts +45 -0
- package/dist/screen-components.d.ts.map +1 -0
- package/dist/screen-components.js +23 -0
- package/dist/screen-components.js.map +1 -0
- package/dist/vue/advanced-collections.d.ts +486 -0
- package/dist/vue/advanced-collections.d.ts.map +1 -0
- package/dist/vue/advanced-collections.js +476 -0
- package/dist/vue/advanced-collections.js.map +1 -0
- package/dist/vue/advanced-props.d.ts +398 -0
- package/dist/vue/advanced-props.d.ts.map +1 -0
- package/dist/vue/advanced-props.js +128 -0
- package/dist/vue/advanced-props.js.map +1 -0
- package/dist/vue/animated-text.d.ts +101 -0
- package/dist/vue/animated-text.d.ts.map +1 -0
- package/dist/vue/animated-text.js +56 -0
- package/dist/vue/animated-text.js.map +1 -0
- package/dist/vue/chart.d.ts +1 -1
- package/dist/vue/command-palette.d.ts +3 -3
- package/dist/vue/component-props.d.ts +1045 -0
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/component-props.js +29 -0
- package/dist/vue/component-props.js.map +1 -1
- package/dist/vue/composer.d.ts +159 -0
- package/dist/vue/composer.d.ts.map +1 -0
- package/dist/vue/composer.js +142 -0
- package/dist/vue/composer.js.map +1 -0
- package/dist/vue/configurator.d.ts +5 -5
- package/dist/vue/creative-controls.d.ts +328 -0
- package/dist/vue/creative-controls.d.ts.map +1 -0
- package/dist/vue/creative-controls.js +396 -0
- package/dist/vue/creative-controls.js.map +1 -0
- package/dist/vue/creative-props.d.ts +260 -0
- package/dist/vue/creative-props.d.ts.map +1 -0
- package/dist/vue/creative-props.js +92 -0
- package/dist/vue/creative-props.js.map +1 -0
- package/dist/vue/dashboard-charts.d.ts +240 -0
- package/dist/vue/dashboard-charts.d.ts.map +1 -0
- package/dist/vue/dashboard-charts.js +263 -0
- package/dist/vue/dashboard-charts.js.map +1 -0
- package/dist/vue/dashboard-effects.d.ts +211 -0
- package/dist/vue/dashboard-effects.d.ts.map +1 -0
- package/dist/vue/dashboard-effects.js +235 -0
- package/dist/vue/dashboard-effects.js.map +1 -0
- package/dist/vue/dashboard-props.d.ts +244 -0
- package/dist/vue/dashboard-props.d.ts.map +1 -0
- package/dist/vue/dashboard-props.js +94 -0
- package/dist/vue/dashboard-props.js.map +1 -0
- package/dist/vue/date-picker.d.ts +8 -8
- package/dist/vue/discovery-controls.d.ts +2 -2
- package/dist/vue/global-components.d.ts +152 -0
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/image-cropper.d.ts +187 -0
- package/dist/vue/image-cropper.d.ts.map +1 -0
- package/dist/vue/image-cropper.js +310 -0
- package/dist/vue/image-cropper.js.map +1 -0
- package/dist/vue/index.d.ts +20 -0
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +20 -0
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/kanban.d.ts +150 -0
- package/dist/vue/kanban.d.ts.map +1 -0
- package/dist/vue/kanban.js +267 -0
- package/dist/vue/kanban.js.map +1 -0
- package/dist/vue/marquee.d.ts +96 -0
- package/dist/vue/marquee.d.ts.map +1 -0
- package/dist/vue/marquee.js +186 -0
- package/dist/vue/marquee.js.map +1 -0
- package/dist/vue/menu.d.ts +2 -2
- package/dist/vue/navigation-controls.d.ts +1 -1
- package/dist/vue/pin-cell.d.ts +14 -0
- package/dist/vue/pin-cell.d.ts.map +1 -0
- package/dist/vue/pin-cell.js +19 -0
- package/dist/vue/pin-cell.js.map +1 -0
- package/dist/vue/pin-input.d.ts +14 -0
- package/dist/vue/pin-input.d.ts.map +1 -0
- package/dist/vue/pin-input.js +23 -0
- package/dist/vue/pin-input.js.map +1 -0
- package/dist/vue/scheduler.d.ts +229 -0
- package/dist/vue/scheduler.d.ts.map +1 -0
- package/dist/vue/scheduler.js +363 -0
- package/dist/vue/scheduler.js.map +1 -0
- package/dist/vue/screen-component-props.d.ts +236 -0
- package/dist/vue/screen-component-props.d.ts.map +1 -0
- package/dist/vue/screen-component-props.js +90 -0
- package/dist/vue/screen-component-props.js.map +1 -0
- package/dist/vue/scroll-frame.d.ts +223 -0
- package/dist/vue/scroll-frame.d.ts.map +1 -0
- package/dist/vue/scroll-frame.js +346 -0
- package/dist/vue/scroll-frame.js.map +1 -0
- package/dist/vue/speed-dial.d.ts +73 -0
- package/dist/vue/speed-dial.d.ts.map +1 -0
- package/dist/vue/speed-dial.js +78 -0
- package/dist/vue/speed-dial.js.map +1 -0
- package/dist/vue/swipe-actions.d.ts +1 -1
- package/dist/vue/swipe-deck.d.ts +120 -0
- package/dist/vue/swipe-deck.d.ts.map +1 -0
- package/dist/vue/swipe-deck.js +229 -0
- package/dist/vue/swipe-deck.js.map +1 -0
- package/dist/vue/time-picker.d.ts +6 -6
- package/dist/vue/tour.d.ts +120 -0
- package/dist/vue/tour.d.ts.map +1 -0
- package/dist/vue/tour.js +165 -0
- package/dist/vue/tour.js.map +1 -0
- package/dist/vue/tree-view.d.ts +1 -1
- package/dist/vue/wayfinding-controls.d.ts +2 -2
- package/dist/vue/workflows.d.ts +3 -3
- package/package.json +1 -1
- package/src/advanced-collections.ts +199 -0
- package/src/capabilities.ts +30 -4
- package/src/creative-controls.ts +169 -0
- package/src/dashboard.ts +164 -0
- package/src/image-crop.ts +125 -0
- package/src/index.ts +11 -0
- package/src/scheduler.ts +194 -0
- package/src/screen-components.ts +59 -0
- package/src/vue/advanced-collections.ts +679 -0
- package/src/vue/advanced-props.ts +144 -0
- package/src/vue/animated-text.ts +72 -0
- package/src/vue/component-props.ts +61 -0
- package/src/vue/composer.ts +192 -0
- package/src/vue/creative-controls.ts +524 -0
- package/src/vue/creative-props.ts +94 -0
- package/src/vue/dashboard-charts.ts +346 -0
- package/src/vue/dashboard-effects.ts +304 -0
- package/src/vue/dashboard-props.ts +95 -0
- package/src/vue/global-components.ts +162 -0
- package/src/vue/image-cropper.ts +413 -0
- package/src/vue/index.ts +28 -0
- package/src/vue/kanban.ts +360 -0
- package/src/vue/marquee.ts +248 -0
- package/src/vue/pin-cell.ts +26 -0
- package/src/vue/pin-input.ts +31 -0
- package/src/vue/scheduler.ts +505 -0
- package/src/vue/screen-component-props.ts +92 -0
- package/src/vue/scroll-frame.ts +429 -0
- package/src/vue/speed-dial.ts +108 -0
- package/src/vue/swipe-deck.ts +277 -0
- package/src/vue/tour.ts +239 -0
|
@@ -0,0 +1,679 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
defineComponent,
|
|
4
|
+
h,
|
|
5
|
+
markRaw,
|
|
6
|
+
mergeProps,
|
|
7
|
+
nextTick,
|
|
8
|
+
onScopeDispose,
|
|
9
|
+
ref,
|
|
10
|
+
useId,
|
|
11
|
+
watch,
|
|
12
|
+
type Component,
|
|
13
|
+
} from '@vue/runtime-core'
|
|
14
|
+
import {
|
|
15
|
+
treeSelectRows,
|
|
16
|
+
visibleTreeSelection,
|
|
17
|
+
toggleTreeSelection,
|
|
18
|
+
masonryLayout,
|
|
19
|
+
heatmapCalendar,
|
|
20
|
+
heatmapColor,
|
|
21
|
+
updateNotifications,
|
|
22
|
+
uniqueAdvanced,
|
|
23
|
+
type MavisNotification,
|
|
24
|
+
} from '../advanced-collections.js'
|
|
25
|
+
import { createMotionSurface, type MotionGradient } from '../experimental.js'
|
|
26
|
+
import { componentMotion } from '../motion.js'
|
|
27
|
+
import { resolveSpace } from '../theme/resolve.js'
|
|
28
|
+
import type { CivilDate } from '../date.js'
|
|
29
|
+
import {
|
|
30
|
+
treeSelectProps,
|
|
31
|
+
masonryProps,
|
|
32
|
+
heatmapProps,
|
|
33
|
+
notificationCenterProps,
|
|
34
|
+
} from './advanced-props.js'
|
|
35
|
+
import { useComponentLayout } from './component-motion.js'
|
|
36
|
+
import { useMavisTheme } from './theme.js'
|
|
37
|
+
export interface AdvancedUI {
|
|
38
|
+
Box: Component
|
|
39
|
+
Column: Component
|
|
40
|
+
Row: Component
|
|
41
|
+
Stack: Component
|
|
42
|
+
Card: Component
|
|
43
|
+
Text: Component
|
|
44
|
+
Button: Component
|
|
45
|
+
Input: Component
|
|
46
|
+
Checkbox: Component
|
|
47
|
+
Slider: Component
|
|
48
|
+
Popover: Component
|
|
49
|
+
Segmented: Component
|
|
50
|
+
Image: Component
|
|
51
|
+
Host: Component
|
|
52
|
+
Measure: Component
|
|
53
|
+
Canvas: Component
|
|
54
|
+
Cell: Component
|
|
55
|
+
Scroll: Component
|
|
56
|
+
Gesture: Component
|
|
57
|
+
}
|
|
58
|
+
export interface AdvancedFocus {
|
|
59
|
+
focus(id?: string): void
|
|
60
|
+
}
|
|
61
|
+
const web = (platform: string, attrs: Record<string, unknown>) => (platform === 'web' ? attrs : {})
|
|
62
|
+
export function createAdvancedPaint(ui: AdvancedUI) {
|
|
63
|
+
return defineComponent({
|
|
64
|
+
props: { color: { type: String, required: true }, animated: Boolean },
|
|
65
|
+
setup(props, { slots }) {
|
|
66
|
+
const surface = markRaw(createMotionSurface()),
|
|
67
|
+
{ theme } = useMavisTheme()
|
|
68
|
+
onScopeDispose(
|
|
69
|
+
surface.use((owner) => {
|
|
70
|
+
let paint: MotionGradient | undefined
|
|
71
|
+
const stop = watch(
|
|
72
|
+
() => [props.color, props.animated],
|
|
73
|
+
() => {
|
|
74
|
+
if (!/^#[\da-f]{6}$/i.test(props.color)) {
|
|
75
|
+
paint?.dispose()
|
|
76
|
+
paint = undefined
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
if (!owner.supports('gradient')) return
|
|
80
|
+
const colors = [props.color, props.color]
|
|
81
|
+
if (!paint) paint = owner.gradient({ type: 'linear', colors, angle: 0 })
|
|
82
|
+
else if (props.animated)
|
|
83
|
+
paint.animate({ colors }, componentMotion(theme.value, 'data'))
|
|
84
|
+
else {
|
|
85
|
+
paint.stop()
|
|
86
|
+
paint.set({ colors })
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
{ immediate: true },
|
|
90
|
+
)
|
|
91
|
+
return () => {
|
|
92
|
+
stop()
|
|
93
|
+
paint?.dispose()
|
|
94
|
+
}
|
|
95
|
+
}),
|
|
96
|
+
)
|
|
97
|
+
return () =>
|
|
98
|
+
h(
|
|
99
|
+
ui.Box,
|
|
100
|
+
{
|
|
101
|
+
motionSurface: surface,
|
|
102
|
+
backgroundColor: props.color,
|
|
103
|
+
radius: 'sm',
|
|
104
|
+
width: '100%',
|
|
105
|
+
height: '100%',
|
|
106
|
+
},
|
|
107
|
+
slots,
|
|
108
|
+
)
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
export function createTreeSelect(ui: AdvancedUI, platform: 'web' | 'native') {
|
|
113
|
+
return defineComponent({
|
|
114
|
+
name: 'MTreeSelect',
|
|
115
|
+
inheritAttrs: false,
|
|
116
|
+
props: treeSelectProps,
|
|
117
|
+
emits: {
|
|
118
|
+
'update:modelValue': (_v: string[]) => true,
|
|
119
|
+
'update:expanded': (_v: string[]) => true,
|
|
120
|
+
},
|
|
121
|
+
setup(props, { attrs, emit }) {
|
|
122
|
+
const open = ref(false),
|
|
123
|
+
query = ref(''),
|
|
124
|
+
rows = computed(() => treeSelectRows(props.nodes)),
|
|
125
|
+
visible = computed(() => visibleTreeSelection(rows.value, props.expanded, query.value))
|
|
126
|
+
const region = useComponentLayout(
|
|
127
|
+
() => [props.expanded, query.value, props.modelValue],
|
|
128
|
+
true,
|
|
129
|
+
() => props.animated,
|
|
130
|
+
)
|
|
131
|
+
const mutable = (id: string) =>
|
|
132
|
+
rows.value.some((r) => r.node.id === id && !r.disabled && r.node.selectable !== false)
|
|
133
|
+
function choose(id: string) {
|
|
134
|
+
if (props.disabled) return
|
|
135
|
+
emit(
|
|
136
|
+
'update:modelValue',
|
|
137
|
+
toggleTreeSelection(props.nodes, props.modelValue, id, props.multiple),
|
|
138
|
+
)
|
|
139
|
+
if (!props.multiple) open.value = false
|
|
140
|
+
}
|
|
141
|
+
watch(
|
|
142
|
+
() => props.disabled,
|
|
143
|
+
(v) => {
|
|
144
|
+
if (v) open.value = false
|
|
145
|
+
},
|
|
146
|
+
)
|
|
147
|
+
return () => {
|
|
148
|
+
if (!props.multiple && props.modelValue.length > 1)
|
|
149
|
+
throw new RangeError('Single TreeSelect accepts at most one selected ID.')
|
|
150
|
+
const selected = props.modelValue.map(
|
|
151
|
+
(id) => rows.value.find((r) => r.node.id === id)?.node.label ?? id,
|
|
152
|
+
)
|
|
153
|
+
return h(
|
|
154
|
+
ui.Column,
|
|
155
|
+
mergeProps(attrs, {
|
|
156
|
+
id: props.id,
|
|
157
|
+
gap: 'sm',
|
|
158
|
+
...web(platform, { class: 'm-tree-select' }),
|
|
159
|
+
}),
|
|
160
|
+
() => [
|
|
161
|
+
h(ui.Text, { text: props.label, variant: 'body', weight: '600' }),
|
|
162
|
+
h(
|
|
163
|
+
ui.Popover,
|
|
164
|
+
{
|
|
165
|
+
open: open.value,
|
|
166
|
+
'onUpdate:open': (v: boolean) => (open.value = v),
|
|
167
|
+
label: props.label,
|
|
168
|
+
triggerLabel: selected.join(', ') || props.placeholder,
|
|
169
|
+
disabled: props.disabled,
|
|
170
|
+
width: 360,
|
|
171
|
+
},
|
|
172
|
+
() =>
|
|
173
|
+
h(ui.Column, { gap: 'sm', motionRegion: region }, () => [
|
|
174
|
+
h(ui.Input, {
|
|
175
|
+
label: props.searchLabel,
|
|
176
|
+
modelValue: query.value,
|
|
177
|
+
'onUpdate:modelValue': (v: string) => (query.value = v),
|
|
178
|
+
disabled: props.disabled,
|
|
179
|
+
}),
|
|
180
|
+
...visible.value.map((row) =>
|
|
181
|
+
h(ui.Row, { key: row.node.id, gap: 'xs', align: 'center' }, () => [
|
|
182
|
+
row.depth
|
|
183
|
+
? h(ui.Box, { width: row.depth * 16, accessibilityHidden: true })
|
|
184
|
+
: null,
|
|
185
|
+
row.node.children?.length
|
|
186
|
+
? h(ui.Button, {
|
|
187
|
+
text: query.value || props.expanded.includes(row.node.id) ? '−' : '+',
|
|
188
|
+
variant: 'ghost',
|
|
189
|
+
size: 'sm',
|
|
190
|
+
accessibilityLabel: `${query.value || props.expanded.includes(row.node.id) ? props.collapseLabel : props.expandLabel}: ${row.node.label}`,
|
|
191
|
+
disabled: props.disabled || !!query.value,
|
|
192
|
+
...web(platform, {
|
|
193
|
+
'aria-expanded':
|
|
194
|
+
!!query.value || props.expanded.includes(row.node.id),
|
|
195
|
+
}),
|
|
196
|
+
onClick: () => {
|
|
197
|
+
if (props.disabled) return
|
|
198
|
+
emit(
|
|
199
|
+
'update:expanded',
|
|
200
|
+
props.expanded.includes(row.node.id)
|
|
201
|
+
? props.expanded.filter((id) => id !== row.node.id)
|
|
202
|
+
: [...props.expanded, row.node.id],
|
|
203
|
+
)
|
|
204
|
+
},
|
|
205
|
+
})
|
|
206
|
+
: h(ui.Box, { width: 24 }),
|
|
207
|
+
props.multiple
|
|
208
|
+
? h(ui.Checkbox, {
|
|
209
|
+
label: row.node.label,
|
|
210
|
+
modelValue: props.modelValue.includes(row.node.id),
|
|
211
|
+
disabled:
|
|
212
|
+
props.disabled || row.disabled || row.node.selectable === false,
|
|
213
|
+
'onUpdate:modelValue': () => choose(row.node.id),
|
|
214
|
+
})
|
|
215
|
+
: h(ui.Button, {
|
|
216
|
+
text: row.node.label,
|
|
217
|
+
variant: props.modelValue.includes(row.node.id) ? 'secondary' : 'ghost',
|
|
218
|
+
disabled:
|
|
219
|
+
props.disabled || row.disabled || row.node.selectable === false,
|
|
220
|
+
...(platform === 'native'
|
|
221
|
+
? {
|
|
222
|
+
accessibilityState: props.modelValue.includes(row.node.id)
|
|
223
|
+
? 'selected'
|
|
224
|
+
: '',
|
|
225
|
+
}
|
|
226
|
+
: {}),
|
|
227
|
+
...web(platform, {
|
|
228
|
+
'aria-pressed': props.modelValue.includes(row.node.id),
|
|
229
|
+
}),
|
|
230
|
+
onClick: () => choose(row.node.id),
|
|
231
|
+
}),
|
|
232
|
+
]),
|
|
233
|
+
),
|
|
234
|
+
!visible.value.length
|
|
235
|
+
? h(ui.Text, { text: props.emptyLabel, tone: 'muted' })
|
|
236
|
+
: null,
|
|
237
|
+
h(ui.Button, {
|
|
238
|
+
text: props.clearLabel,
|
|
239
|
+
variant: 'ghost',
|
|
240
|
+
disabled: props.disabled || !props.modelValue.some(mutable),
|
|
241
|
+
onClick: () => {
|
|
242
|
+
if (!props.disabled)
|
|
243
|
+
emit(
|
|
244
|
+
'update:modelValue',
|
|
245
|
+
props.modelValue.filter((id) => !mutable(id)),
|
|
246
|
+
)
|
|
247
|
+
},
|
|
248
|
+
}),
|
|
249
|
+
]),
|
|
250
|
+
),
|
|
251
|
+
],
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
})
|
|
256
|
+
}
|
|
257
|
+
export function createMasonry(ui: AdvancedUI, platform: 'web' | 'native') {
|
|
258
|
+
return defineComponent({
|
|
259
|
+
name: 'MMasonry',
|
|
260
|
+
inheritAttrs: false,
|
|
261
|
+
props: masonryProps,
|
|
262
|
+
setup(props, { attrs, slots }) {
|
|
263
|
+
const width = ref(props.minColumnWidth),
|
|
264
|
+
heights = ref(new Map<string, number>()),
|
|
265
|
+
{ theme } = useMavisTheme()
|
|
266
|
+
const layout = computed(() =>
|
|
267
|
+
masonryLayout(
|
|
268
|
+
props.items,
|
|
269
|
+
width.value,
|
|
270
|
+
props.minColumnWidth,
|
|
271
|
+
resolveSpace(theme.value, props.gap),
|
|
272
|
+
props.columns,
|
|
273
|
+
heights.value,
|
|
274
|
+
),
|
|
275
|
+
)
|
|
276
|
+
let measured = false
|
|
277
|
+
const region = useComponentLayout(
|
|
278
|
+
() => [props.items, layout.value],
|
|
279
|
+
false,
|
|
280
|
+
() => props.animated && measured,
|
|
281
|
+
)
|
|
282
|
+
watch(
|
|
283
|
+
width,
|
|
284
|
+
() => {
|
|
285
|
+
measured = width.value > 0
|
|
286
|
+
},
|
|
287
|
+
{ flush: 'post' },
|
|
288
|
+
)
|
|
289
|
+
watch(
|
|
290
|
+
() => props.items,
|
|
291
|
+
() => {
|
|
292
|
+
const next = new Map(heights.value)
|
|
293
|
+
for (const id of next.keys())
|
|
294
|
+
if (!props.items.some((item) => item.id === id)) next.delete(id)
|
|
295
|
+
heights.value = next
|
|
296
|
+
},
|
|
297
|
+
)
|
|
298
|
+
function measure(id: string, height: number) {
|
|
299
|
+
if (
|
|
300
|
+
height >= 0 &&
|
|
301
|
+
Number.isFinite(height) &&
|
|
302
|
+
Math.abs((heights.value.get(id) ?? -1) - height) > 0.5
|
|
303
|
+
)
|
|
304
|
+
heights.value = new Map(heights.value).set(id, height)
|
|
305
|
+
}
|
|
306
|
+
return () =>
|
|
307
|
+
h(
|
|
308
|
+
ui.Host,
|
|
309
|
+
mergeProps(attrs, {
|
|
310
|
+
id: props.id,
|
|
311
|
+
label: props.label,
|
|
312
|
+
...web(platform, { class: 'm-masonry' }),
|
|
313
|
+
}),
|
|
314
|
+
() =>
|
|
315
|
+
h(
|
|
316
|
+
ui.Measure,
|
|
317
|
+
{
|
|
318
|
+
onWidth: (v: number) => {
|
|
319
|
+
if (Math.abs(width.value - v) > 0.5) width.value = v
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
() =>
|
|
323
|
+
h(ui.Box, { motionRegion: region }, () => [
|
|
324
|
+
!props.items.length
|
|
325
|
+
? h(ui.Text, { text: props.emptyLabel, tone: 'muted' })
|
|
326
|
+
: h(ui.Canvas, { height: layout.value.height }, () =>
|
|
327
|
+
layout.value.placements.map((item, index) =>
|
|
328
|
+
h(
|
|
329
|
+
ui.Cell,
|
|
330
|
+
{
|
|
331
|
+
...item,
|
|
332
|
+
key: item.id,
|
|
333
|
+
measure: true,
|
|
334
|
+
height: undefined,
|
|
335
|
+
onHeight: (height: number) => measure(item.id, height),
|
|
336
|
+
},
|
|
337
|
+
() =>
|
|
338
|
+
slots.item?.({
|
|
339
|
+
item: props.items[index],
|
|
340
|
+
index,
|
|
341
|
+
width: item.width,
|
|
342
|
+
}) ?? h(ui.Text, { text: item.id }),
|
|
343
|
+
),
|
|
344
|
+
),
|
|
345
|
+
),
|
|
346
|
+
]),
|
|
347
|
+
),
|
|
348
|
+
)
|
|
349
|
+
},
|
|
350
|
+
})
|
|
351
|
+
}
|
|
352
|
+
export function createHeatmap(ui: AdvancedUI, platform: 'web' | 'native') {
|
|
353
|
+
const Paint = createAdvancedPaint(ui)
|
|
354
|
+
return defineComponent({
|
|
355
|
+
name: 'MHeatmap',
|
|
356
|
+
inheritAttrs: false,
|
|
357
|
+
props: heatmapProps,
|
|
358
|
+
emits: { 'update:modelValue': (_v: CivilDate) => true },
|
|
359
|
+
setup(props, { attrs, emit }) {
|
|
360
|
+
const uid = useId(),
|
|
361
|
+
host = ref<AdvancedFocus>(),
|
|
362
|
+
showData = ref(false)
|
|
363
|
+
const geometry = computed(() =>
|
|
364
|
+
heatmapCalendar(props.start, props.end, props.values, props.weekStartsOn),
|
|
365
|
+
)
|
|
366
|
+
function choose(date: CivilDate) {
|
|
367
|
+
const cell = geometry.value.cells.find((c) => c.date === date)
|
|
368
|
+
if (!props.disabled && cell && !cell.disabled) emit('update:modelValue', date)
|
|
369
|
+
}
|
|
370
|
+
const title = (cell: (typeof geometry.value.cells)[number]) =>
|
|
371
|
+
`${cell.label ?? cell.date}: ${cell.value === null ? props.missingLabel : (props.formatValue?.(cell.value) ?? String(cell.value))}`
|
|
372
|
+
function key(event: { key: string; preventDefault(): void }, index: number) {
|
|
373
|
+
const delta: Record<string, number> = {
|
|
374
|
+
ArrowUp: -1,
|
|
375
|
+
ArrowDown: 1,
|
|
376
|
+
ArrowLeft: -7,
|
|
377
|
+
ArrowRight: 7,
|
|
378
|
+
Home: -index,
|
|
379
|
+
End: geometry.value.cells.length - 1 - index,
|
|
380
|
+
}
|
|
381
|
+
if (event.key in delta) {
|
|
382
|
+
event.preventDefault()
|
|
383
|
+
const cell =
|
|
384
|
+
geometry.value.cells[
|
|
385
|
+
Math.max(0, Math.min(geometry.value.cells.length - 1, index + delta[event.key]!))
|
|
386
|
+
]
|
|
387
|
+
if (cell && !cell.disabled) host.value?.focus(`${uid}-${cell.date}`)
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return () => {
|
|
391
|
+
if (!Number.isFinite(props.cellSize) || props.cellSize < 28 || props.cellSize > 80)
|
|
392
|
+
throw new RangeError('Heatmap cellSize must be 28–80.')
|
|
393
|
+
const g = geometry.value,
|
|
394
|
+
step = props.cellSize + 4
|
|
395
|
+
return h(
|
|
396
|
+
ui.Host,
|
|
397
|
+
mergeProps(attrs, {
|
|
398
|
+
id: props.id,
|
|
399
|
+
label: props.label,
|
|
400
|
+
ref: host,
|
|
401
|
+
...web(platform, { class: 'm-heatmap' }),
|
|
402
|
+
}),
|
|
403
|
+
() =>
|
|
404
|
+
h(ui.Column, { gap: 'md' }, () => [
|
|
405
|
+
h(ui.Text, { text: props.label, variant: 'heading' }),
|
|
406
|
+
h(ui.Scroll, {}, () =>
|
|
407
|
+
h(ui.Canvas, { width: g.columns * step, height: 7 * step }, () =>
|
|
408
|
+
g.cells.map((cell, index) =>
|
|
409
|
+
h(
|
|
410
|
+
ui.Cell,
|
|
411
|
+
{
|
|
412
|
+
key: cell.date,
|
|
413
|
+
x: cell.column * step,
|
|
414
|
+
y: cell.row * step,
|
|
415
|
+
width: props.cellSize,
|
|
416
|
+
height: props.cellSize,
|
|
417
|
+
},
|
|
418
|
+
() =>
|
|
419
|
+
h(
|
|
420
|
+
Paint,
|
|
421
|
+
{
|
|
422
|
+
color: heatmapColor(cell.value, g.max, props.colors),
|
|
423
|
+
animated: props.animated,
|
|
424
|
+
},
|
|
425
|
+
() =>
|
|
426
|
+
h(ui.Button, {
|
|
427
|
+
id: `${uid}-${cell.date}`,
|
|
428
|
+
text: cell.missing ? '·' : props.modelValue === cell.date ? '✓' : ' ',
|
|
429
|
+
accessibilityLabel: title(cell),
|
|
430
|
+
variant: 'ghost',
|
|
431
|
+
size: 'sm',
|
|
432
|
+
height: props.cellSize,
|
|
433
|
+
width: props.cellSize,
|
|
434
|
+
disabled: props.disabled || cell.disabled,
|
|
435
|
+
...(platform === 'native'
|
|
436
|
+
? {
|
|
437
|
+
accessibilityState:
|
|
438
|
+
props.modelValue === cell.date ? 'selected' : '',
|
|
439
|
+
}
|
|
440
|
+
: {}),
|
|
441
|
+
...web(platform, {
|
|
442
|
+
'aria-pressed': props.modelValue === cell.date,
|
|
443
|
+
onKeydown: (e: { key: string; preventDefault(): void }) =>
|
|
444
|
+
key(e, index),
|
|
445
|
+
style: {
|
|
446
|
+
padding: 0,
|
|
447
|
+
color: (() => {
|
|
448
|
+
const color = heatmapColor(cell.value, g.max, props.colors)
|
|
449
|
+
if (color === 'transparent') return undefined
|
|
450
|
+
const rgb = [1, 3, 5]
|
|
451
|
+
.map((i) => parseInt(color.slice(i, i + 2), 16) / 255)
|
|
452
|
+
.map((v) =>
|
|
453
|
+
v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4,
|
|
454
|
+
)
|
|
455
|
+
return 0.2126 * rgb[0]! + 0.7152 * rgb[1]! + 0.0722 * rgb[2]! >
|
|
456
|
+
0.179
|
|
457
|
+
? '#000000'
|
|
458
|
+
: '#FFFFFF'
|
|
459
|
+
})(),
|
|
460
|
+
border:
|
|
461
|
+
props.modelValue === cell.date
|
|
462
|
+
? '2px solid currentColor'
|
|
463
|
+
: undefined,
|
|
464
|
+
},
|
|
465
|
+
}),
|
|
466
|
+
onClick: () => choose(cell.date),
|
|
467
|
+
}),
|
|
468
|
+
),
|
|
469
|
+
),
|
|
470
|
+
),
|
|
471
|
+
),
|
|
472
|
+
),
|
|
473
|
+
h(ui.Row, { gap: 'xs', align: 'center' }, () => [
|
|
474
|
+
h(ui.Text, { text: props.lessLabel, variant: 'caption' }),
|
|
475
|
+
...props.colors.map((color) =>
|
|
476
|
+
h(ui.Box, {
|
|
477
|
+
key: color,
|
|
478
|
+
width: 16,
|
|
479
|
+
height: 16,
|
|
480
|
+
radius: 'sm',
|
|
481
|
+
backgroundColor: color,
|
|
482
|
+
accessibilityHidden: true,
|
|
483
|
+
}),
|
|
484
|
+
),
|
|
485
|
+
h(ui.Text, { text: props.moreLabel, variant: 'caption' }),
|
|
486
|
+
]),
|
|
487
|
+
h(ui.Button, {
|
|
488
|
+
text: props.dataLabel,
|
|
489
|
+
variant: 'ghost',
|
|
490
|
+
...web(platform, { 'aria-expanded': showData.value }),
|
|
491
|
+
onClick: () => (showData.value = !showData.value),
|
|
492
|
+
}),
|
|
493
|
+
showData.value
|
|
494
|
+
? h(ui.Column, { gap: 'xs' }, () =>
|
|
495
|
+
g.cells.map((cell) =>
|
|
496
|
+
h(ui.Button, {
|
|
497
|
+
key: cell.date,
|
|
498
|
+
text: title(cell),
|
|
499
|
+
variant: props.modelValue === cell.date ? 'secondary' : 'ghost',
|
|
500
|
+
disabled: props.disabled || cell.disabled,
|
|
501
|
+
onClick: () => choose(cell.date),
|
|
502
|
+
}),
|
|
503
|
+
),
|
|
504
|
+
)
|
|
505
|
+
: null,
|
|
506
|
+
]),
|
|
507
|
+
)
|
|
508
|
+
}
|
|
509
|
+
},
|
|
510
|
+
})
|
|
511
|
+
}
|
|
512
|
+
export function createNotificationCenter(ui: AdvancedUI, platform: 'web' | 'native') {
|
|
513
|
+
return defineComponent({
|
|
514
|
+
name: 'MNotificationCenter',
|
|
515
|
+
inheritAttrs: false,
|
|
516
|
+
props: notificationCenterProps,
|
|
517
|
+
emits: {
|
|
518
|
+
'update:modelValue': (_v: MavisNotification[]) => true,
|
|
519
|
+
'update:filter': (_v: 'all' | 'unread') => true,
|
|
520
|
+
action: (_id: string) => true,
|
|
521
|
+
},
|
|
522
|
+
setup(props, { attrs, emit }) {
|
|
523
|
+
const uid = useId(),
|
|
524
|
+
host = ref<AdvancedFocus>(),
|
|
525
|
+
{ theme } = useMavisTheme()
|
|
526
|
+
const visible = computed(() =>
|
|
527
|
+
props.modelValue.filter((item) => props.filter === 'all' || !item.read),
|
|
528
|
+
)
|
|
529
|
+
const region = useComponentLayout(
|
|
530
|
+
() => [props.modelValue, props.filter],
|
|
531
|
+
true,
|
|
532
|
+
() => props.animated,
|
|
533
|
+
)
|
|
534
|
+
function change(ids: string[], action: 'read' | 'unread' | 'dismiss') {
|
|
535
|
+
if (props.disabled) return
|
|
536
|
+
emit('update:modelValue', updateNotifications(props.modelValue, ids, action))
|
|
537
|
+
if (action === 'dismiss' || (action === 'read' && props.filter === 'unread'))
|
|
538
|
+
void nextTick(() => host.value?.focus(`${uid}-filter`))
|
|
539
|
+
}
|
|
540
|
+
return () => {
|
|
541
|
+
uniqueAdvanced(props.modelValue, 'NotificationCenter', 1000)
|
|
542
|
+
if (props.modelValue.some((item) => !item.title.trim()))
|
|
543
|
+
throw new TypeError('Notifications require a title.')
|
|
544
|
+
const groups = [...new Set(visible.value.map((item) => item.group ?? props.ungroupedLabel))]
|
|
545
|
+
return h(
|
|
546
|
+
ui.Host,
|
|
547
|
+
mergeProps(attrs, {
|
|
548
|
+
id: props.id,
|
|
549
|
+
label: props.label,
|
|
550
|
+
ref: host,
|
|
551
|
+
...web(platform, { class: 'm-notification-center' }),
|
|
552
|
+
}),
|
|
553
|
+
() =>
|
|
554
|
+
h(ui.Column, { gap: 'md', motionRegion: region }, () => [
|
|
555
|
+
h(ui.Row, { gap: 'sm', align: 'center' }, () => [
|
|
556
|
+
h(ui.Text, { text: props.label, variant: 'heading', grow: 1 }),
|
|
557
|
+
h(ui.Text, {
|
|
558
|
+
text: String(props.modelValue.filter((item) => !item.read).length),
|
|
559
|
+
variant: 'body',
|
|
560
|
+
weight: '600',
|
|
561
|
+
accessibilityLabel: props.unreadLabel,
|
|
562
|
+
}),
|
|
563
|
+
]),
|
|
564
|
+
h(ui.Row, { gap: 'sm', wrap: true }, () => [
|
|
565
|
+
h(ui.Button, {
|
|
566
|
+
id: `uid-${uid}-all`,
|
|
567
|
+
text: props.allLabel,
|
|
568
|
+
variant: props.filter === 'all' ? 'secondary' : 'ghost',
|
|
569
|
+
disabled: props.disabled,
|
|
570
|
+
...(platform === 'native'
|
|
571
|
+
? { accessibilityState: props.filter === 'all' ? 'selected' : '' }
|
|
572
|
+
: {}),
|
|
573
|
+
...web(platform, { 'aria-pressed': props.filter === 'all' }),
|
|
574
|
+
onClick: () => {
|
|
575
|
+
if (!props.disabled) emit('update:filter', 'all')
|
|
576
|
+
},
|
|
577
|
+
}),
|
|
578
|
+
h(ui.Button, {
|
|
579
|
+
id: `${uid}-filter`,
|
|
580
|
+
text: props.unreadLabel,
|
|
581
|
+
variant: props.filter === 'unread' ? 'secondary' : 'ghost',
|
|
582
|
+
disabled: props.disabled,
|
|
583
|
+
...(platform === 'native'
|
|
584
|
+
? { accessibilityState: props.filter === 'unread' ? 'selected' : '' }
|
|
585
|
+
: {}),
|
|
586
|
+
...web(platform, { 'aria-pressed': props.filter === 'unread' }),
|
|
587
|
+
onClick: () => {
|
|
588
|
+
if (!props.disabled) emit('update:filter', 'unread')
|
|
589
|
+
},
|
|
590
|
+
}),
|
|
591
|
+
h(ui.Button, {
|
|
592
|
+
text: props.readAllLabel,
|
|
593
|
+
variant: 'ghost',
|
|
594
|
+
disabled:
|
|
595
|
+
props.disabled ||
|
|
596
|
+
!props.modelValue.some((item) => !item.read && !item.disabled),
|
|
597
|
+
onClick: () =>
|
|
598
|
+
change(
|
|
599
|
+
props.modelValue.map((item) => item.id),
|
|
600
|
+
'read',
|
|
601
|
+
),
|
|
602
|
+
}),
|
|
603
|
+
]),
|
|
604
|
+
!visible.value.length
|
|
605
|
+
? h(ui.Card, { padding: 'lg' }, () =>
|
|
606
|
+
h(ui.Text, { text: props.emptyLabel, tone: 'muted' }),
|
|
607
|
+
)
|
|
608
|
+
: null,
|
|
609
|
+
...groups.map((group) =>
|
|
610
|
+
h(ui.Column, { key: group, gap: 'sm' }, () => [
|
|
611
|
+
h(ui.Text, { text: group, variant: 'body', weight: '600', tone: 'muted' }),
|
|
612
|
+
...visible.value
|
|
613
|
+
.filter((item) => (item.group ?? props.ungroupedLabel) === group)
|
|
614
|
+
.map((item) =>
|
|
615
|
+
h(
|
|
616
|
+
ui.Card,
|
|
617
|
+
{
|
|
618
|
+
key: item.id,
|
|
619
|
+
padding: 'md',
|
|
620
|
+
borderColor: item.read
|
|
621
|
+
? theme.value.colors.border
|
|
622
|
+
: theme.value.colors.primary,
|
|
623
|
+
},
|
|
624
|
+
() =>
|
|
625
|
+
h(ui.Column, { gap: 'sm' }, () => [
|
|
626
|
+
h(ui.Text, { text: item.title, variant: 'heading' }),
|
|
627
|
+
item.description
|
|
628
|
+
? h(ui.Text, { text: item.description, tone: 'muted' })
|
|
629
|
+
: null,
|
|
630
|
+
item.time
|
|
631
|
+
? h(ui.Text, { text: item.time, variant: 'caption', tone: 'muted' })
|
|
632
|
+
: null,
|
|
633
|
+
h(
|
|
634
|
+
ui.Stack,
|
|
635
|
+
{
|
|
636
|
+
direction: 'column',
|
|
637
|
+
responsive: { at: 520, direction: 'row' },
|
|
638
|
+
gap: 'xs',
|
|
639
|
+
},
|
|
640
|
+
() => [
|
|
641
|
+
item.actionLabel
|
|
642
|
+
? h(ui.Button, {
|
|
643
|
+
text: item.actionLabel,
|
|
644
|
+
disabled: props.disabled || item.disabled,
|
|
645
|
+
onClick: () => {
|
|
646
|
+
if (!props.disabled && !item.disabled)
|
|
647
|
+
emit('action', item.id)
|
|
648
|
+
},
|
|
649
|
+
})
|
|
650
|
+
: null,
|
|
651
|
+
h(ui.Button, {
|
|
652
|
+
text: item.read ? props.unreadActionLabel : props.readLabel,
|
|
653
|
+
variant: 'ghost',
|
|
654
|
+
disabled: props.disabled || item.disabled,
|
|
655
|
+
accessibilityLabel: `${item.read ? props.unreadActionLabel : props.readLabel}: ${item.title}`,
|
|
656
|
+
onClick: () => change([item.id], item.read ? 'unread' : 'read'),
|
|
657
|
+
}),
|
|
658
|
+
item.dismissible !== false
|
|
659
|
+
? h(ui.Button, {
|
|
660
|
+
text: props.dismissLabel,
|
|
661
|
+
variant: 'ghost',
|
|
662
|
+
disabled: props.disabled || item.disabled,
|
|
663
|
+
accessibilityLabel: `${props.dismissLabel}: ${item.title}`,
|
|
664
|
+
onClick: () => change([item.id], 'dismiss'),
|
|
665
|
+
})
|
|
666
|
+
: null,
|
|
667
|
+
],
|
|
668
|
+
),
|
|
669
|
+
]),
|
|
670
|
+
),
|
|
671
|
+
),
|
|
672
|
+
]),
|
|
673
|
+
),
|
|
674
|
+
]),
|
|
675
|
+
)
|
|
676
|
+
}
|
|
677
|
+
},
|
|
678
|
+
})
|
|
679
|
+
}
|