@getcortexlabs/mavis-core 0.1.0-rc.12 → 0.1.0-rc.12.2

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.
Files changed (82) hide show
  1. package/README.md +2 -2
  2. package/dist/advanced-collections.d.ts +74 -0
  3. package/dist/advanced-collections.d.ts.map +1 -0
  4. package/dist/advanced-collections.js +129 -0
  5. package/dist/advanced-collections.js.map +1 -0
  6. package/dist/capabilities.d.ts +7 -7
  7. package/dist/capabilities.d.ts.map +1 -1
  8. package/dist/capabilities.js +10 -4
  9. package/dist/capabilities.js.map +1 -1
  10. package/dist/image-crop.d.ts +49 -0
  11. package/dist/image-crop.d.ts.map +1 -0
  12. package/dist/image-crop.js +71 -0
  13. package/dist/image-crop.js.map +1 -0
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +3 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/scheduler.d.ts +45 -0
  19. package/dist/scheduler.d.ts.map +1 -0
  20. package/dist/scheduler.js +142 -0
  21. package/dist/scheduler.js.map +1 -0
  22. package/dist/vue/advanced-collections.d.ts +486 -0
  23. package/dist/vue/advanced-collections.d.ts.map +1 -0
  24. package/dist/vue/advanced-collections.js +476 -0
  25. package/dist/vue/advanced-collections.js.map +1 -0
  26. package/dist/vue/advanced-props.d.ts +398 -0
  27. package/dist/vue/advanced-props.d.ts.map +1 -0
  28. package/dist/vue/advanced-props.js +128 -0
  29. package/dist/vue/advanced-props.js.map +1 -0
  30. package/dist/vue/animated-text.d.ts +1 -1
  31. package/dist/vue/chart.d.ts +1 -1
  32. package/dist/vue/command-palette.d.ts +3 -3
  33. package/dist/vue/component-props.d.ts +359 -3
  34. package/dist/vue/component-props.d.ts.map +1 -1
  35. package/dist/vue/component-props.js +7 -0
  36. package/dist/vue/component-props.js.map +1 -1
  37. package/dist/vue/composer.d.ts +1 -1
  38. package/dist/vue/configurator.d.ts +4 -4
  39. package/dist/vue/creative-controls.d.ts +1 -1
  40. package/dist/vue/dashboard-charts.d.ts +1 -1
  41. package/dist/vue/dashboard-effects.d.ts +2 -2
  42. package/dist/vue/date-picker.d.ts +8 -8
  43. package/dist/vue/discovery-controls.d.ts +1 -1
  44. package/dist/vue/global-components.d.ts +46 -0
  45. package/dist/vue/global-components.d.ts.map +1 -1
  46. package/dist/vue/image-cropper.d.ts +187 -0
  47. package/dist/vue/image-cropper.d.ts.map +1 -0
  48. package/dist/vue/image-cropper.js +310 -0
  49. package/dist/vue/image-cropper.js.map +1 -0
  50. package/dist/vue/index.d.ts +4 -0
  51. package/dist/vue/index.d.ts.map +1 -1
  52. package/dist/vue/index.js +4 -0
  53. package/dist/vue/index.js.map +1 -1
  54. package/dist/vue/kanban.d.ts +2 -2
  55. package/dist/vue/menu.d.ts +2 -2
  56. package/dist/vue/navigation-controls.d.ts +1 -1
  57. package/dist/vue/props.d.ts +6 -6
  58. package/dist/vue/scheduler.d.ts +229 -0
  59. package/dist/vue/scheduler.d.ts.map +1 -0
  60. package/dist/vue/scheduler.js +363 -0
  61. package/dist/vue/scheduler.js.map +1 -0
  62. package/dist/vue/scroll-frame.d.ts +1 -1
  63. package/dist/vue/speed-dial.d.ts +2 -2
  64. package/dist/vue/swipe-actions.d.ts +1 -1
  65. package/dist/vue/swipe-deck.d.ts +1 -1
  66. package/dist/vue/time-picker.d.ts +4 -4
  67. package/dist/vue/tour.d.ts +1 -1
  68. package/dist/vue/wayfinding-controls.d.ts +2 -2
  69. package/dist/vue/workflows.d.ts +3 -3
  70. package/package.json +1 -1
  71. package/src/advanced-collections.ts +199 -0
  72. package/src/capabilities.ts +10 -4
  73. package/src/image-crop.ts +125 -0
  74. package/src/index.ts +6 -0
  75. package/src/scheduler.ts +194 -0
  76. package/src/vue/advanced-collections.ts +679 -0
  77. package/src/vue/advanced-props.ts +144 -0
  78. package/src/vue/component-props.ts +14 -0
  79. package/src/vue/global-components.ts +46 -0
  80. package/src/vue/image-cropper.ts +413 -0
  81. package/src/vue/index.ts +8 -0
  82. package/src/vue/scheduler.ts +505 -0
@@ -0,0 +1,505 @@
1
+ import {
2
+ computed,
3
+ defineComponent,
4
+ h,
5
+ mergeProps,
6
+ nextTick,
7
+ ref,
8
+ useId,
9
+ watch,
10
+ } from '@vue/runtime-core'
11
+ import { addCivilDays } from '../date.js'
12
+ import {
13
+ schedulerOffset,
14
+ schedulerLayout,
15
+ schedulerInstant,
16
+ schedulerCivilFromUTC,
17
+ changeSchedulerEvent,
18
+ type SchedulerClock,
19
+ type SchedulerChange,
20
+ type SchedulerEvent,
21
+ } from '../scheduler.js'
22
+ import { schedulerProps, type AdvancedGesture } from './advanced-props.js'
23
+ import { useComponentLayout } from './component-motion.js'
24
+ import { useMavisTheme } from './theme.js'
25
+ import type { AdvancedUI, AdvancedFocus } from './advanced-collections.js'
26
+ const time = (minutes: number) =>
27
+ `${String(Math.floor(minutes / 60)).padStart(2, '0')}:${String(minutes % 60).padStart(2, '0')}`
28
+ export function createScheduler(ui: AdvancedUI, platform: 'web' | 'native', clock: SchedulerClock) {
29
+ return defineComponent({
30
+ name: 'MScheduler',
31
+ inheritAttrs: false,
32
+ props: schedulerProps,
33
+ emits: {
34
+ 'update:modelValue': (_v: SchedulerEvent[]) => true,
35
+ 'update:date': (_v: string) => true,
36
+ change: (_v: SchedulerChange) => true,
37
+ error: (_v: string) => true,
38
+ select: (_id: string) => true,
39
+ },
40
+ setup(props, { attrs, emit }) {
41
+ const { theme } = useMavisTheme(),
42
+ uid = useId(),
43
+ host = ref<AdvancedFocus>(),
44
+ selected = ref<string | null>(null),
45
+ draft = ref<SchedulerChange>(),
46
+ failure = ref(''),
47
+ dragging = ref(false)
48
+ let original: SchedulerEvent | undefined,
49
+ kind: 'move' | 'resize' = 'move'
50
+ const shown = computed(() =>
51
+ draft.value ? changeSchedulerEvent(props.modelValue, draft.value) : props.modelValue,
52
+ )
53
+ const layout = computed(() =>
54
+ schedulerLayout(
55
+ shown.value,
56
+ props.date,
57
+ props.days,
58
+ props.timeZone,
59
+ clock,
60
+ props.startHour,
61
+ props.endHour,
62
+ ),
63
+ )
64
+ const region = useComponentLayout(
65
+ () => [shown.value, props.date, props.days, props.hourHeight],
66
+ false,
67
+ () => props.animated && !dragging.value,
68
+ )
69
+ const describe = (event: SchedulerEvent) =>
70
+ `${event.title} · ${clock.parts(event.start, props.timeZone).date} ${time(clock.parts(event.start, props.timeZone).minute)}–${time(clock.parts(event.end, props.timeZone).minute)} · ${props.timeZone} ${schedulerOffset(event.start, props.timeZone, clock)} → ${schedulerOffset(event.end, props.timeZone, clock)}`
71
+ function cancel() {
72
+ draft.value = undefined
73
+ original = undefined
74
+ dragging.value = false
75
+ }
76
+ watch(
77
+ () => [
78
+ props.modelValue,
79
+ props.date,
80
+ props.days,
81
+ props.timeZone,
82
+ props.disabled,
83
+ props.startHour,
84
+ props.endHour,
85
+ props.slotMinutes,
86
+ props.hourHeight,
87
+ props.dayWidth,
88
+ ],
89
+ cancel,
90
+ { deep: true, flush: 'sync' },
91
+ )
92
+ function propose(
93
+ event: SchedulerEvent,
94
+ minutes: number,
95
+ days: number,
96
+ operation: 'move' | 'resize',
97
+ ): SchedulerChange {
98
+ const target = operation === 'move' ? event.start : event.end,
99
+ civil = clock.parts(target, props.timeZone)
100
+ const nominal =
101
+ new Date(`${civil.date}T00:00:00.000Z`).getTime() +
102
+ (civil.minute + minutes) * 60000 +
103
+ days * 86400000
104
+ const next = schedulerCivilFromUTC(nominal)
105
+ const instant =
106
+ schedulerInstant(next, props.timeZone, clock, props.disambiguation) +
107
+ (target - Math.floor(target / 60000) * 60000)
108
+ const result = {
109
+ id: event.id,
110
+ start: operation === 'move' ? instant : event.start,
111
+ end: operation === 'move' ? instant + event.end - event.start : instant,
112
+ kind: operation,
113
+ }
114
+ changeSchedulerEvent(props.modelValue, result)
115
+ return result
116
+ }
117
+ function commit(change: SchedulerChange) {
118
+ if (props.disabled || props.modelValue.find((event) => event.id === change.id)?.disabled)
119
+ return
120
+ emit('update:modelValue', changeSchedulerEvent(props.modelValue, change))
121
+ emit('change', change)
122
+ }
123
+ function change(
124
+ event: SchedulerEvent,
125
+ minutes: number,
126
+ days: number,
127
+ operation: 'move' | 'resize',
128
+ ) {
129
+ if (props.disabled || event.disabled) return
130
+ failure.value = ''
131
+ try {
132
+ commit(propose(event, minutes, days, operation))
133
+ } catch (e) {
134
+ failure.value = e instanceof Error ? e.message : String(e)
135
+ emit('error', failure.value)
136
+ }
137
+ }
138
+ function gesture(
139
+ event: SchedulerEvent,
140
+ operation: 'move' | 'resize',
141
+ input: AdvancedGesture,
142
+ ) {
143
+ if (props.disabled || event.disabled) return
144
+ if (input.phase === 'start') {
145
+ original = { ...event }
146
+ kind = operation
147
+ dragging.value = true
148
+ failure.value = ''
149
+ }
150
+ if (input.phase === 'move' && original) {
151
+ const minutes =
152
+ Math.round(((input.y / props.hourHeight) * 60) / props.slotMinutes) *
153
+ props.slotMinutes,
154
+ days = kind === 'move' ? Math.round(input.x / props.dayWidth) : 0
155
+ try {
156
+ const proposal = propose(original, minutes, days, kind),
157
+ start = clock.parts(proposal.start, props.timeZone),
158
+ end = clock.parts(proposal.end, props.timeZone)
159
+ if (
160
+ start.date < props.date ||
161
+ start.date > addCivilDays(props.date, props.days - 1) ||
162
+ start.minute < props.startHour * 60 ||
163
+ end.date !== start.date ||
164
+ end.minute > props.endHour * 60 ||
165
+ end.minute <= start.minute
166
+ ) {
167
+ draft.value = undefined
168
+ return
169
+ }
170
+ draft.value = proposal
171
+ } catch (e) {
172
+ draft.value = undefined
173
+ failure.value = e instanceof Error ? e.message : String(e)
174
+ }
175
+ }
176
+ if (input.phase === 'end') {
177
+ const pending = draft.value
178
+ cancel()
179
+ if (pending) commit(pending)
180
+ else if (failure.value) emit('error', failure.value)
181
+ }
182
+ if (input.phase === 'cancel') cancel()
183
+ }
184
+ function focus(event: SchedulerEvent) {
185
+ selected.value = event.id
186
+ emit('select', event.id)
187
+ void nextTick(() => host.value?.focus(`${uid}-earlier`))
188
+ }
189
+ return () => {
190
+ if (
191
+ !Number.isFinite(props.hourHeight) ||
192
+ props.hourHeight < 48 ||
193
+ props.hourHeight > 180 ||
194
+ !Number.isFinite(props.dayWidth) ||
195
+ props.dayWidth < 140 ||
196
+ props.dayWidth > 500 ||
197
+ !Number.isInteger(props.slotMinutes) ||
198
+ props.slotMinutes < 5 ||
199
+ props.slotMinutes > 60 ||
200
+ 60 % props.slotMinutes !== 0
201
+ )
202
+ throw new RangeError(
203
+ 'Scheduler needs hourHeight 48–180, dayWidth 140–500 and a 5–60 minute divisor of an hour.',
204
+ )
205
+ const grid = layout.value,
206
+ gridHeight = (props.endHour - props.startHour) * props.hourHeight + 44,
207
+ totalWidth = 64 + props.days * props.dayWidth,
208
+ event = props.modelValue.find((item) => item.id === selected.value)
209
+ return h(
210
+ ui.Host,
211
+ mergeProps(attrs, {
212
+ id: props.id,
213
+ label: props.label,
214
+ ref: host,
215
+ ...(platform === 'web' ? { class: 'm-scheduler' } : {}),
216
+ }),
217
+ () =>
218
+ h(ui.Column, { gap: 'md', motionRegion: region }, () => [
219
+ h(ui.Text, { text: props.label, variant: 'heading' }),
220
+ h(ui.Text, {
221
+ text: `${props.date} · ${props.timeZone}`,
222
+ tone: 'muted',
223
+ variant: 'caption',
224
+ }),
225
+ h(ui.Row, { gap: 'sm' }, () => [
226
+ h(ui.Button, {
227
+ text: props.previousLabel,
228
+ variant: 'secondary',
229
+ disabled: props.disabled,
230
+ onClick: () => {
231
+ if (!props.disabled) emit('update:date', addCivilDays(props.date, -props.days))
232
+ },
233
+ }),
234
+ h(ui.Button, {
235
+ text: props.nextLabel,
236
+ variant: 'secondary',
237
+ disabled: props.disabled,
238
+ onClick: () => {
239
+ if (!props.disabled) emit('update:date', addCivilDays(props.date, props.days))
240
+ },
241
+ }),
242
+ ]),
243
+ h(ui.Scroll, {}, () =>
244
+ h(ui.Canvas, { height: gridHeight, width: totalWidth }, () => [
245
+ ...Array.from({ length: props.endHour - props.startHour }, (_, i) =>
246
+ h(
247
+ ui.Cell,
248
+ {
249
+ key: `hour-${i}`,
250
+ x: 0,
251
+ y: 44 + i * props.hourHeight,
252
+ width: totalWidth,
253
+ height: props.hourHeight,
254
+ },
255
+ () =>
256
+ h(
257
+ ui.Box,
258
+ {
259
+ height: '100%',
260
+ borderColor: theme.value.colors.border,
261
+ borderWidth: 0.5,
262
+ ...(platform === 'web'
263
+ ? {
264
+ style: {
265
+ borderTop: `1px solid ${theme.value.colors.border}`,
266
+ boxSizing: 'border-box',
267
+ },
268
+ }
269
+ : {}),
270
+ accessibilityHidden: true,
271
+ },
272
+ () =>
273
+ h(ui.Text, {
274
+ text: time((props.startHour + i) * 60),
275
+ variant: 'caption',
276
+ tone: 'muted',
277
+ width: 60,
278
+ }),
279
+ ),
280
+ ),
281
+ ),
282
+ ...grid.flatMap((column, day) => [
283
+ h(
284
+ ui.Cell,
285
+ {
286
+ key: `day-${column.date}`,
287
+ x: 64 + day * props.dayWidth,
288
+ y: 0,
289
+ width: props.dayWidth,
290
+ height: 40,
291
+ },
292
+ () =>
293
+ h(ui.Text, {
294
+ text: column.date,
295
+ variant: 'body',
296
+ weight: '600',
297
+ align: 'center',
298
+ }),
299
+ ),
300
+ ...column.segments.map((segment) => {
301
+ const item = segment.event,
302
+ editable = !props.disabled && !item.disabled,
303
+ full =
304
+ segment.startsHere &&
305
+ segment.endsHere &&
306
+ ((segment.bottom - segment.top) / 60) * props.hourHeight >= 100
307
+ return h(
308
+ ui.Cell,
309
+ {
310
+ key: `event-${column.date}-${item.id}`,
311
+ x:
312
+ 64 +
313
+ day * props.dayWidth +
314
+ (segment.lane * props.dayWidth) / segment.lanes +
315
+ 3,
316
+ y: 44 + ((segment.top - props.startHour * 60) / 60) * props.hourHeight,
317
+ width: props.dayWidth / segment.lanes - 6,
318
+ height: Math.max(
319
+ 28,
320
+ ((segment.bottom - segment.top) / 60) * props.hourHeight - 3,
321
+ ),
322
+ },
323
+ () =>
324
+ h(
325
+ ui.Box,
326
+ {
327
+ height: '100%',
328
+ backgroundColor: theme.value.colors.surface,
329
+ radius: 'sm',
330
+ borderWidth: 1,
331
+ borderColor: item.color ?? theme.value.colors.primary,
332
+ clipToBounds: true,
333
+ ...(platform === 'web'
334
+ ? {
335
+ style: {
336
+ overflow: 'hidden',
337
+ border: `1px solid ${item.color ?? theme.value.colors.primary}`,
338
+ borderLeftWidth: '3px',
339
+ boxSizing: 'border-box',
340
+ },
341
+ }
342
+ : {}),
343
+ },
344
+ () =>
345
+ h(ui.Column, { gap: 'none' }, () => [
346
+ full
347
+ ? h(
348
+ ui.Gesture,
349
+ {
350
+ label: `${props.moveLabel}: ${item.title}`,
351
+ disabled: !editable,
352
+ onGesture: (input: AdvancedGesture) =>
353
+ gesture(item, 'move', input),
354
+ onStep: (v: { x: number; y: number }) =>
355
+ change(item, v.y * props.slotMinutes, v.x, 'move'),
356
+ },
357
+ () =>
358
+ h(ui.Text, {
359
+ text: '⠿',
360
+ variant: 'caption',
361
+ align: 'center',
362
+ accessibilityHidden: true,
363
+ }),
364
+ )
365
+ : null,
366
+ h(ui.Button, {
367
+ text: item.title,
368
+ height: full
369
+ ? undefined
370
+ : Math.max(
371
+ 4,
372
+ ((segment.bottom - segment.top) / 60) * props.hourHeight -
373
+ 3,
374
+ ),
375
+ ...(platform === 'web'
376
+ ? {
377
+ style: {
378
+ padding: '0 4px',
379
+ minHeight: 0,
380
+ fontSize: '12px',
381
+ overflow: 'hidden',
382
+ },
383
+ }
384
+ : {}),
385
+ accessibilityLabel: describe(item),
386
+ size: 'sm',
387
+ variant: selected.value === item.id ? 'secondary' : 'ghost',
388
+ disabled: props.disabled || item.disabled,
389
+ onClick: () => focus(item),
390
+ }),
391
+ full
392
+ ? h(
393
+ ui.Gesture,
394
+ {
395
+ label: `${props.resizeLabel}: ${item.title}`,
396
+ disabled: !editable,
397
+ onGesture: (input: AdvancedGesture) =>
398
+ gesture(item, 'resize', input),
399
+ onStep: (v: { x: number; y: number }) =>
400
+ change(
401
+ item,
402
+ (v.y || v.x) * props.slotMinutes,
403
+ 0,
404
+ 'resize',
405
+ ),
406
+ },
407
+ () =>
408
+ h(ui.Text, {
409
+ text: '━',
410
+ variant: 'caption',
411
+ align: 'center',
412
+ accessibilityHidden: true,
413
+ }),
414
+ )
415
+ : null,
416
+ ]),
417
+ ),
418
+ )
419
+ }),
420
+ ]),
421
+ ]),
422
+ ),
423
+ !grid.some((column) => column.segments.length)
424
+ ? h(ui.Text, { text: props.emptyLabel, tone: 'muted' })
425
+ : null,
426
+ failure.value
427
+ ? h(ui.Text, {
428
+ text: failure.value,
429
+ ...(platform === 'web' ? { role: 'alert' } : {}),
430
+ })
431
+ : null,
432
+ h(ui.Column, { gap: 'xs' }, () =>
433
+ props.modelValue.map((item) =>
434
+ h(ui.Button, {
435
+ key: item.id,
436
+ text: describe(item),
437
+ variant: selected.value === item.id ? 'secondary' : 'ghost',
438
+ disabled: props.disabled || item.disabled,
439
+ onClick: () => focus(item),
440
+ }),
441
+ ),
442
+ ),
443
+ event
444
+ ? h(ui.Card, { padding: 'md' }, () =>
445
+ h(ui.Column, { gap: 'sm' }, () => [
446
+ h(ui.Text, { text: describe(event), variant: 'body', weight: '600' }),
447
+ h(
448
+ ui.Stack,
449
+ {
450
+ direction: 'column',
451
+ responsive: { at: 600, direction: 'row' },
452
+ gap: 'xs',
453
+ },
454
+ () => [
455
+ h(ui.Button, {
456
+ id: `${uid}-earlier`,
457
+ text: props.earlierLabel,
458
+ variant: 'secondary',
459
+ disabled: props.disabled || event.disabled,
460
+ onClick: () => change(event, -props.slotMinutes, 0, 'move'),
461
+ }),
462
+ h(ui.Button, {
463
+ text: props.laterLabel,
464
+ variant: 'secondary',
465
+ disabled: props.disabled || event.disabled,
466
+ onClick: () => change(event, props.slotMinutes, 0, 'move'),
467
+ }),
468
+ h(ui.Button, {
469
+ text: props.previousDayLabel,
470
+ variant: 'ghost',
471
+ disabled: props.disabled || event.disabled,
472
+ onClick: () => change(event, 0, -1, 'move'),
473
+ }),
474
+ h(ui.Button, {
475
+ text: props.nextDayLabel,
476
+ variant: 'ghost',
477
+ disabled: props.disabled || event.disabled,
478
+ onClick: () => change(event, 0, 1, 'move'),
479
+ }),
480
+ h(ui.Button, {
481
+ text: props.shorterLabel,
482
+ variant: 'ghost',
483
+ disabled:
484
+ props.disabled ||
485
+ event.disabled ||
486
+ event.end - event.start <= props.slotMinutes * 60000,
487
+ onClick: () => change(event, -props.slotMinutes, 0, 'resize'),
488
+ }),
489
+ h(ui.Button, {
490
+ text: props.longerLabel,
491
+ variant: 'ghost',
492
+ disabled: props.disabled || event.disabled,
493
+ onClick: () => change(event, props.slotMinutes, 0, 'resize'),
494
+ }),
495
+ ],
496
+ ),
497
+ ]),
498
+ )
499
+ : null,
500
+ ]),
501
+ )
502
+ }
503
+ },
504
+ })
505
+ }