@m3ui-vue/m3ui-vue 1.2.2 → 1.3.0
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/dist/API.md +2776 -351
- package/dist/MButton-CuNzpoxm.js +172 -0
- package/dist/MButton-CuNzpoxm.js.map +1 -0
- package/dist/MDialog-HxEL-m58.js +173 -0
- package/dist/MDialog-HxEL-m58.js.map +1 -0
- package/dist/MIconButton-DoNotQ9v.js +282 -0
- package/dist/MIconButton-DoNotQ9v.js.map +1 -0
- package/dist/MListItem-DnPtv-hY.js +824 -0
- package/dist/MListItem-DnPtv-hY.js.map +1 -0
- package/dist/MLoadingIndicator-BQMNX6Dx.js +115 -0
- package/dist/MLoadingIndicator-BQMNX6Dx.js.map +1 -0
- package/dist/MMenuItem-Bih0h4-n.js +604 -0
- package/dist/MMenuItem-Bih0h4-n.js.map +1 -0
- package/dist/MProgressBar-BCoruxA-.js +184 -0
- package/dist/MProgressBar-BCoruxA-.js.map +1 -0
- package/dist/MSeekBar-LURE1Ah7.js +435 -0
- package/dist/MSeekBar-LURE1Ah7.js.map +1 -0
- package/dist/MSegmentedButton-DL9JtJFX.js +65 -0
- package/dist/MSegmentedButton-DL9JtJFX.js.map +1 -0
- package/dist/MSlider-_J4IS2_z.js +691 -0
- package/dist/MSlider-_J4IS2_z.js.map +1 -0
- package/dist/MSpinner-BhkMYKOM.js +65 -0
- package/dist/MSpinner-BhkMYKOM.js.map +1 -0
- package/dist/MTextField-CkzwNBWS.js +296 -0
- package/dist/MTextField-CkzwNBWS.js.map +1 -0
- package/dist/MTooltip-B67ZDSGp.js +756 -0
- package/dist/MTooltip-B67ZDSGp.js.map +1 -0
- package/dist/_storageKeys-CYXsUBwK.js +18 -0
- package/dist/_storageKeys-CYXsUBwK.js.map +1 -0
- package/dist/_useEscapeStack-CjndQhqg.js +19 -0
- package/dist/_useEscapeStack-CjndQhqg.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/chart.js +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAudioPlayer.vue.d.ts +115 -0
- package/dist/components/MBadge.vue.d.ts +1 -1
- package/dist/components/MBottomSheetScaffold.vue.d.ts +1 -1
- package/dist/components/MBox.vue.d.ts +1 -1
- package/dist/components/MButton.vue.d.ts +1 -1
- package/dist/components/MConfirmDialog.vue.d.ts +1 -1
- package/dist/components/MCopyButton.vue.d.ts +2 -2
- package/dist/components/MDataTable.vue.d.ts +2 -2
- package/dist/components/MDialog.vue.d.ts +2 -2
- package/dist/components/MDivider.vue.d.ts +1 -1
- package/dist/components/MDragHandle.vue.d.ts +1 -1
- package/dist/components/MDrawCanvas.vue.d.ts +148 -0
- package/dist/components/MDrawLayers.vue.d.ts +3 -0
- package/dist/components/MDrawToolbar.vue.d.ts +34 -0
- package/dist/components/MExportButton.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MFabMenu.vue.d.ts +2 -2
- package/dist/components/MFixed.vue.d.ts +1 -1
- package/dist/components/MFlex.vue.d.ts +2 -2
- package/dist/components/MFloorPlan.vue.d.ts +160 -0
- package/dist/components/MFlow.vue.d.ts +305 -0
- package/dist/components/MFlowControls.vue.d.ts +33 -0
- package/dist/components/MFlowHandle.vue.d.ts +16 -0
- package/dist/components/MFlowMinimap.vue.d.ts +22 -0
- package/dist/components/MFlowNode.vue.d.ts +35 -0
- package/dist/components/MGantt.vue.d.ts +141 -0
- package/dist/components/MGanttControls.vue.d.ts +32 -0
- package/dist/components/MIconButton.vue.d.ts +3 -1
- package/dist/components/MImageCropper.vue.d.ts +110 -0
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MLightbox.vue.d.ts +2 -2
- package/dist/components/MList.vue.d.ts +1 -1
- package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
- package/dist/components/MMapControl.vue.d.ts +1 -1
- package/dist/components/MMapSearch.vue.d.ts +1 -1
- package/dist/components/MMaskField.vue.d.ts +12 -1
- package/dist/components/MMenu.vue.d.ts +1 -1
- package/dist/components/MNavigationDrawer.vue.d.ts +1 -1
- package/dist/components/MNumberField.vue.d.ts +11 -2
- package/dist/components/MPdfViewer.vue.d.ts +174 -0
- package/dist/components/MPullToRefresh.vue.d.ts +1 -1
- package/dist/components/MResourceTimeline.vue.d.ts +149 -0
- package/dist/components/MScheduler.vue.d.ts +3 -3
- package/dist/components/MScheme.vue.d.ts +1 -1
- package/dist/components/MSearchField.vue.d.ts +1 -1
- package/dist/components/MSeekBar.vue.d.ts +1 -1
- package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
- package/dist/components/MSkeleton.vue.d.ts +1 -1
- package/dist/components/MSlider.vue.d.ts +2 -2
- package/dist/components/MSparkline.vue.d.ts +1 -1
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +2 -2
- package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
- package/dist/components/MSwitch.vue.d.ts +1 -1
- package/dist/components/MTable.vue.d.ts +1 -1
- package/dist/components/MTagInput.vue.d.ts +12 -1
- package/dist/components/MTextField.vue.d.ts +13 -2
- package/dist/components/MToolbar.vue.d.ts +1 -1
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/MVideoPlayer.vue.d.ts +253 -0
- package/dist/components/MVirtualTable.vue.d.ts +1 -1
- package/dist/components/MWindow.vue.d.ts +3 -3
- package/dist/components/_MFlowEdge.vue.d.ts +9 -0
- package/dist/components/_MFlowEdgeLabel.vue.d.ts +9 -0
- package/dist/components/_MFlowNodeShell.vue.d.ts +9 -0
- package/dist/components/_MPdfPage.vue.d.ts +76 -0
- package/dist/components/_MTimeBackground.vue.d.ts +14 -0
- package/dist/components/_MTimeHeader.vue.d.ts +20 -0
- package/dist/composables/_flowPanel.d.ts +2 -0
- package/dist/composables/_flowSlot.d.ts +5 -0
- package/dist/composables/_ganttTime.d.ts +41 -0
- package/dist/composables/_useTimeAxis.d.ts +90 -0
- package/dist/composables/drawGeometry.d.ts +119 -0
- package/dist/composables/flowFormats.d.ts +79 -0
- package/dist/composables/flowLayout.d.ts +45 -0
- package/dist/composables/flowPaths.d.ts +53 -0
- package/dist/composables/ganttFormats.d.ts +52 -0
- package/dist/composables/ganttSchedule.d.ts +99 -0
- package/dist/composables/useDrawing.d.ts +44 -0
- package/dist/composables/useFlow.d.ts +266 -0
- package/dist/composables/useGantt.d.ts +87 -0
- package/dist/composables/useLocale.d.ts +163 -0
- package/dist/composables/useMediaPlayer.d.ts +101 -0
- package/dist/composables/usePdf.d.ts +119 -0
- package/dist/composables/useResourceTimeline.d.ts +70 -0
- package/dist/draw.d.ts +7 -0
- package/dist/draw.js +1700 -0
- package/dist/draw.js.map +1 -0
- package/dist/flow.d.ts +14 -0
- package/dist/flow.js +3542 -0
- package/dist/flow.js.map +1 -0
- package/dist/flowPaths-CUc6X373.js +161 -0
- package/dist/flowPaths-CUc6X373.js.map +1 -0
- package/dist/gantt.d.ts +12 -0
- package/dist/gantt.js +3575 -0
- package/dist/gantt.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/locales/index.js +1148 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7286 -7654
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +113 -108
- package/dist/map.js.map +1 -1
- package/dist/media.d.ts +5 -0
- package/dist/media.js +1311 -0
- package/dist/media.js.map +1 -0
- package/dist/pdf.d.ts +4 -0
- package/dist/pdf.js +1871 -0
- package/dist/pdf.js.map +1 -0
- package/dist/rich-text-editor.js +28 -26
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-JYxDDeXC.js → useLocale-BpGxplLV.js} +165 -2
- package/dist/useLocale-BpGxplLV.js.map +1 -0
- package/dist/{useThemeTokens-y0HZpyhL.js → useThemeTokens-DQQcaWbE.js} +40 -54
- package/dist/useThemeTokens-DQQcaWbE.js.map +1 -0
- package/package.json +29 -5
- package/src/__tests__/MAudioPlayer.test.ts +75 -0
- package/src/__tests__/MDrawCanvas.test.ts +110 -0
- package/src/__tests__/MFloorPlan.test.ts +97 -0
- package/src/__tests__/MFlow.test.ts +575 -0
- package/src/__tests__/MGantt.test.ts +130 -0
- package/src/__tests__/MImageCropper.test.ts +89 -0
- package/src/__tests__/MPdfViewer.test.ts +235 -0
- package/src/__tests__/MResourceTimeline.test.ts +102 -0
- package/src/__tests__/MVideoPlayer.test.ts +201 -0
- package/src/__tests__/drawGeometry.test.ts +58 -0
- package/src/__tests__/fieldExpose.test.ts +30 -0
- package/src/__tests__/flowFormats.test.ts +185 -0
- package/src/__tests__/flowLayout.test.ts +113 -0
- package/src/__tests__/ganttFormats.test.ts +76 -0
- package/src/__tests__/ganttSchedule.test.ts +136 -0
- package/src/__tests__/pdfMock.ts +83 -0
- package/src/__tests__/useMediaPlayer.test.ts +182 -0
- package/src/__tests__/usePdf.test.ts +102 -0
- package/src/components/MAudioPlayer.vue +319 -0
- package/src/components/MDrawCanvas.vue +813 -0
- package/src/components/MDrawLayers.vue +114 -0
- package/src/components/MDrawToolbar.vue +171 -0
- package/src/components/MFloorPlan.vue +581 -0
- package/src/components/MFlow.vue +2049 -0
- package/src/components/MFlowControls.vue +110 -0
- package/src/components/MFlowHandle.vue +60 -0
- package/src/components/MFlowMinimap.vue +134 -0
- package/src/components/MFlowNode.vue +98 -0
- package/src/components/MGantt.vue +1609 -0
- package/src/components/MGanttControls.vue +77 -0
- package/src/components/MIconButton.vue +3 -1
- package/src/components/MImageCropper.vue +507 -0
- package/src/components/MMaskField.vue +13 -0
- package/src/components/MNumberField.vue +13 -0
- package/src/components/MPdfViewer.vue +1269 -0
- package/src/components/MResourceTimeline.vue +1020 -0
- package/src/components/MTagInput.vue +13 -0
- package/src/components/MTextField.vue +16 -0
- package/src/components/MVideoPlayer.vue +839 -0
- package/src/components/_MFlowEdge.vue +100 -0
- package/src/components/_MFlowEdgeLabel.vue +56 -0
- package/src/components/_MFlowNodeShell.vue +111 -0
- package/src/components/_MPdfPage.vue +456 -0
- package/src/components/_MTimeBackground.vue +16 -0
- package/src/components/_MTimeHeader.vue +31 -0
- package/src/composables/_flowPanel.ts +13 -0
- package/src/composables/_flowSlot.ts +6 -0
- package/src/composables/_ganttTime.ts +200 -0
- package/src/composables/_useTimeAxis.ts +224 -0
- package/src/composables/drawGeometry.ts +405 -0
- package/src/composables/flowFormats.ts +916 -0
- package/src/composables/flowLayout.ts +297 -0
- package/src/composables/flowPaths.ts +239 -0
- package/src/composables/ganttFormats.ts +366 -0
- package/src/composables/ganttSchedule.ts +403 -0
- package/src/composables/useDrawing.ts +53 -0
- package/src/composables/useFlow.ts +250 -0
- package/src/composables/useGantt.ts +92 -0
- package/src/composables/useLocale.ts +328 -0
- package/src/composables/useMediaPlayer.ts +406 -0
- package/src/composables/usePdf.ts +456 -0
- package/src/composables/useResourceTimeline.ts +76 -0
- package/src/draw.ts +25 -0
- package/src/flow.ts +26 -0
- package/src/gantt.ts +12 -0
- package/src/index.ts +4 -0
- package/src/locales/de.ts +163 -0
- package/src/locales/es.ts +163 -0
- package/src/locales/fr.ts +163 -0
- package/src/locales/ja.ts +163 -0
- package/src/locales/ko.ts +163 -0
- package/src/locales/pt.ts +163 -0
- package/src/locales/zh.ts +163 -0
- package/src/media.ts +5 -0
- package/src/pdf.ts +15 -0
- package/dist/MMenuItem-D4Gx_l3F.js +0 -929
- package/dist/MMenuItem-D4Gx_l3F.js.map +0 -1
- package/dist/MSlider-Dx_S3vJ9.js +0 -1506
- package/dist/MSlider-Dx_S3vJ9.js.map +0 -1
- package/dist/MTextField-Bz8JIsnl.js +0 -633
- package/dist/MTextField-Bz8JIsnl.js.map +0 -1
- package/dist/useLocale-JYxDDeXC.js.map +0 -1
- package/dist/useThemeTokens-y0HZpyhL.js.map +0 -1
|
@@ -0,0 +1,1020 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A resource timeline: one row per person, table, room or machine, with their bookings (shifts, reservations,
|
|
4
|
+
* jobs) along a timeline you zoom from hours to months. Not an M3 spec component: MGantt's timeline, for planning
|
|
5
|
+
* who or what is busy when rather than tasks and their order.
|
|
6
|
+
*
|
|
7
|
+
* Bookings are a `v-model` of plain objects (`TimelineEvent`: `resourceId`, `start`/`end` datetimes or whole days,
|
|
8
|
+
* `title`, `color`). Drag one along its row to move it, to another row to give it to that resource, or by its ends
|
|
9
|
+
* to resize it; snapped to `snap` minutes. Bookings that overlap share the row in lanes, and more than a resource's
|
|
10
|
+
* `capacity` at once are marked as conflicts (`overlap="prevent"` refuses a drop that makes one). With `creatable`,
|
|
11
|
+
* dragging across empty time (a short press first with a finger) asks for a new booking there (`create`).
|
|
12
|
+
* Resources with a `group` sit under headers that fold. Rows and time render only near the view; every edit is
|
|
13
|
+
* undoable.
|
|
14
|
+
*
|
|
15
|
+
* Keyboard (on a booking): ←/→ move it a step, Shift + ←/→ change its end, ↑/↓ move it to the resource above or
|
|
16
|
+
* below, Enter opens it (`event-dblclick`), Delete deletes, Ctrl+Z / Ctrl+Shift+Z undo and redo.
|
|
17
|
+
*
|
|
18
|
+
* @slot default Above the timeline: MGanttControls, filters of yours. Props: `{ timeline }`
|
|
19
|
+
* @slot resource A resource's cell. Props: `{ resource, events, hours }` (`hours`: booked in total)
|
|
20
|
+
* @slot event A booking's content. Props: `{ event, resource, selected, conflict }`
|
|
21
|
+
* @slot group A group's header. Props: `{ group, resources, collapsed }`
|
|
22
|
+
* @slot empty Shown while there are no resources
|
|
23
|
+
* @event event-click / event-dblclick / event-contextmenu `(event, mouseEvent)`
|
|
24
|
+
* @event create Empty time was dragged across (or long pressed) on a resource: `{ resourceId, start, end }`; add the booking yourself
|
|
25
|
+
* @event slot-click Empty time was clicked: `{ resourceId, start }`
|
|
26
|
+
* @event change A drag or a key changed bookings: `{ events, kind: 'move' | 'resize' }`
|
|
27
|
+
* @event conflict A drop was refused (`overlap="prevent"`): `{ event, with }`
|
|
28
|
+
* @event delete Bookings were deleted: `{ events }`
|
|
29
|
+
*/
|
|
30
|
+
import { computed, nextTick, onBeforeUnmount, onMounted, provide, ref, shallowRef, toRaw, watch } from 'vue'
|
|
31
|
+
import { RESOURCE_TIMELINE_KEY, type ResourceTimelineContext, type TimelineEvent, type TimelineResource } from '../composables/useResourceTimeline'
|
|
32
|
+
import { TIMELINE_CONTROLS_KEY, type GanttScale } from '../composables/useGantt'
|
|
33
|
+
import { spanDates, taskSpan, type GanttCalendar } from '../composables/ganttSchedule'
|
|
34
|
+
import { DAY, HOUR, defaultSnap, formatDate, parseDate, snapTime } from '../composables/_ganttTime'
|
|
35
|
+
import { prefersReducedMotion } from '../composables/_springAnimation'
|
|
36
|
+
import { useTimeAxis } from '../composables/_useTimeAxis'
|
|
37
|
+
import { useLocale } from '../composables/useLocale'
|
|
38
|
+
import MTimeHeader from './_MTimeHeader.vue'
|
|
39
|
+
import MTimeBackground from './_MTimeBackground.vue'
|
|
40
|
+
|
|
41
|
+
const props = withDefaults(defineProps<{
|
|
42
|
+
events?: TimelineEvent[]
|
|
43
|
+
resources?: TimelineResource[]
|
|
44
|
+
/** The zoom as a named level (`v-model:scale`) */
|
|
45
|
+
scale?: GanttScale
|
|
46
|
+
/** The starting zoom in px per day, between the named levels (default 240: 10 px an hour) */
|
|
47
|
+
pxPerDay?: number
|
|
48
|
+
/** Selected booking ids (`v-model:selection`) */
|
|
49
|
+
selection?: string[]
|
|
50
|
+
/** Folded group names (`v-model:collapsed`) */
|
|
51
|
+
collapsed?: string[]
|
|
52
|
+
/** The resource column's width, px (`v-model:list-width`; drag its edge); 0 hides it */
|
|
53
|
+
listWidth?: number
|
|
54
|
+
/** A row's least height; rows grow with their lanes */
|
|
55
|
+
rowHeight?: number
|
|
56
|
+
/** One lane's height (a booking and its gap) */
|
|
57
|
+
laneHeight?: number
|
|
58
|
+
/** `'stack'` (default): overlaps share the row in lanes and show as conflicts past `capacity`; `'prevent'` also refuses a drop that makes one */
|
|
59
|
+
overlap?: 'stack' | 'prevent'
|
|
60
|
+
/** Dragging across empty time asks for a booking there (`create`) */
|
|
61
|
+
creatable?: boolean
|
|
62
|
+
readonly?: boolean
|
|
63
|
+
/** Minutes bookings snap to (default 15; by zoom when zoomed far out); whole-day bookings snap to days */
|
|
64
|
+
snap?: number
|
|
65
|
+
/** Days worked (shaded when they aren't) */
|
|
66
|
+
calendar?: GanttCalendar
|
|
67
|
+
/** Working hours, shaded outside them when zoomed in to hours, e.g. `[9, 18]` */
|
|
68
|
+
workHours?: [number, number]
|
|
69
|
+
/** Now, for the line across the timeline (default the current time; `null` hides it) */
|
|
70
|
+
now?: string | null
|
|
71
|
+
/** Where the view starts (default now, or the first booking) */
|
|
72
|
+
start?: string
|
|
73
|
+
weekStartsOn?: 0 | 1
|
|
74
|
+
minPxPerDay?: number
|
|
75
|
+
maxPxPerDay?: number
|
|
76
|
+
locale?: string
|
|
77
|
+
label?: string
|
|
78
|
+
beforeDelete?: (events: TimelineEvent[]) => boolean | Promise<boolean>
|
|
79
|
+
}>(), {
|
|
80
|
+
events: () => [],
|
|
81
|
+
resources: () => [],
|
|
82
|
+
scale: 'day',
|
|
83
|
+
pxPerDay: 240,
|
|
84
|
+
rowHeight: 56,
|
|
85
|
+
laneHeight: 40,
|
|
86
|
+
overlap: 'stack',
|
|
87
|
+
creatable: false,
|
|
88
|
+
readonly: false,
|
|
89
|
+
weekStartsOn: 1,
|
|
90
|
+
minPxPerDay: 2,
|
|
91
|
+
maxPxPerDay: 4800,
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
const emit = defineEmits<{
|
|
95
|
+
'update:events': [TimelineEvent[]]
|
|
96
|
+
'update:scale': [GanttScale]
|
|
97
|
+
'update:selection': [string[]]
|
|
98
|
+
'update:collapsed': [string[]]
|
|
99
|
+
'update:listWidth': [number]
|
|
100
|
+
'event-click': [TimelineEvent, MouseEvent]
|
|
101
|
+
'event-dblclick': [TimelineEvent, MouseEvent | KeyboardEvent]
|
|
102
|
+
'event-contextmenu': [TimelineEvent, MouseEvent]
|
|
103
|
+
create: [{ resourceId: string; start: string; end: string }]
|
|
104
|
+
'slot-click': [{ resourceId: string; start: string }]
|
|
105
|
+
change: [{ events: TimelineEvent[]; kind: 'move' | 'resize' }]
|
|
106
|
+
conflict: [{ event: TimelineEvent; with: TimelineEvent[] }]
|
|
107
|
+
delete: [{ events: TimelineEvent[] }]
|
|
108
|
+
}>()
|
|
109
|
+
|
|
110
|
+
const locale = useLocale()
|
|
111
|
+
const lang = computed(() => props.locale ?? (locale.lang === 'en' ? undefined : locale.lang))
|
|
112
|
+
|
|
113
|
+
// ── Events, history ───────────────────────────────────────────────────────────────────────────────────────
|
|
114
|
+
const current = shallowRef<TimelineEvent[]>(props.events)
|
|
115
|
+
watch(() => props.events, (e) => { current.value = e })
|
|
116
|
+
const preview = shallowRef<TimelineEvent[] | null>(null)
|
|
117
|
+
const shown = computed(() => preview.value ?? current.value)
|
|
118
|
+
const past: TimelineEvent[][] = []
|
|
119
|
+
const future: TimelineEvent[][] = []
|
|
120
|
+
const historyTick = ref(0)
|
|
121
|
+
function emitEvents(next: TimelineEvent[]) {
|
|
122
|
+
current.value = next
|
|
123
|
+
emit('update:events', next)
|
|
124
|
+
}
|
|
125
|
+
function commit(next: TimelineEvent[]) {
|
|
126
|
+
past.push(toRaw(current.value))
|
|
127
|
+
if (past.length > 100) past.shift()
|
|
128
|
+
future.length = 0
|
|
129
|
+
historyTick.value++
|
|
130
|
+
emitEvents(next)
|
|
131
|
+
}
|
|
132
|
+
function undo() {
|
|
133
|
+
const prev = past.pop()
|
|
134
|
+
if (!prev) return
|
|
135
|
+
future.push(toRaw(current.value))
|
|
136
|
+
historyTick.value++
|
|
137
|
+
emitEvents(prev)
|
|
138
|
+
}
|
|
139
|
+
function redo() {
|
|
140
|
+
const next = future.pop()
|
|
141
|
+
if (!next) return
|
|
142
|
+
past.push(toRaw(current.value))
|
|
143
|
+
historyTick.value++
|
|
144
|
+
emitEvents(next)
|
|
145
|
+
}
|
|
146
|
+
const canUndo = computed(() => (historyTick.value, past.length > 0))
|
|
147
|
+
const canRedo = computed(() => (historyTick.value, future.length > 0))
|
|
148
|
+
const eventById = computed(() => new Map(shown.value.map((e) => [e.id, e])))
|
|
149
|
+
const resourceById = computed(() => new Map(props.resources.map((r) => [r.id, r])))
|
|
150
|
+
|
|
151
|
+
const selected = ref<string[]>(props.selection ?? [])
|
|
152
|
+
watch(() => props.selection, (s) => { if (s) selected.value = s })
|
|
153
|
+
const selectedSet = computed(() => new Set(selected.value))
|
|
154
|
+
function setSelection(ids: string[]) {
|
|
155
|
+
const ok = ids.filter((id) => eventById.value.get(id)?.selectable !== false)
|
|
156
|
+
selected.value = ok
|
|
157
|
+
emit('update:selection', ok)
|
|
158
|
+
}
|
|
159
|
+
const folded = ref<string[]>(props.collapsed ?? [])
|
|
160
|
+
watch(() => props.collapsed, (c) => { if (c) folded.value = c })
|
|
161
|
+
const foldedSet = computed(() => new Set(folded.value))
|
|
162
|
+
function setFolded(ids: string[]) {
|
|
163
|
+
folded.value = ids
|
|
164
|
+
emit('update:collapsed', ids)
|
|
165
|
+
}
|
|
166
|
+
const toggleGroup = (g: string) => setFolded(foldedSet.value.has(g) ? folded.value.filter((x) => x !== g) : [...folded.value, g])
|
|
167
|
+
|
|
168
|
+
// ── Lanes, conflicts, rows ────────────────────────────────────────────────────────────────────────────────
|
|
169
|
+
type Span = { start: number; end: number; dateOnly: boolean }
|
|
170
|
+
const spans = computed(() => {
|
|
171
|
+
const m = new Map<string, Span>()
|
|
172
|
+
for (const e of shown.value) {
|
|
173
|
+
const s = taskSpan({ start: e.start, end: e.end })
|
|
174
|
+
if (Number.isFinite(s.start)) m.set(e.id, s)
|
|
175
|
+
}
|
|
176
|
+
return m
|
|
177
|
+
})
|
|
178
|
+
const byResource = computed(() => {
|
|
179
|
+
const m = new Map<string, TimelineEvent[]>()
|
|
180
|
+
for (const e of shown.value) if (spans.value.has(e.id)) (m.get(e.resourceId) ?? m.set(e.resourceId, []).get(e.resourceId)!).push(e)
|
|
181
|
+
for (const list of m.values()) list.sort((a, b) => spans.value.get(a.id)!.start - spans.value.get(b.id)!.start)
|
|
182
|
+
return m
|
|
183
|
+
})
|
|
184
|
+
// Each booking's lane in its row (first lane free when it starts), and the row's lane count
|
|
185
|
+
const lanes = computed(() => {
|
|
186
|
+
const lane = new Map<string, number>()
|
|
187
|
+
const count = new Map<string, number>()
|
|
188
|
+
for (const [rid, list] of byResource.value) {
|
|
189
|
+
const ends: number[] = []
|
|
190
|
+
for (const e of list) {
|
|
191
|
+
const s = spans.value.get(e.id)!
|
|
192
|
+
let i = ends.findIndex((end) => end <= s.start)
|
|
193
|
+
if (i < 0) { i = ends.length; ends.push(0) }
|
|
194
|
+
ends[i] = s.end
|
|
195
|
+
lane.set(e.id, i)
|
|
196
|
+
}
|
|
197
|
+
count.set(rid, Math.max(1, ends.length))
|
|
198
|
+
}
|
|
199
|
+
return { lane, count }
|
|
200
|
+
})
|
|
201
|
+
function overlapsOf(list: TimelineEvent[], capacity: number, sp: Map<string, Span>): Map<string, string[]> {
|
|
202
|
+
// A sweep: at every start, what's still running
|
|
203
|
+
const out = new Map<string, string[]>()
|
|
204
|
+
const running: TimelineEvent[] = []
|
|
205
|
+
for (const e of list) {
|
|
206
|
+
const s = sp.get(e.id)!
|
|
207
|
+
for (let i = running.length - 1; i >= 0; i--) if (sp.get(running[i]!.id)!.end <= s.start) running.splice(i, 1)
|
|
208
|
+
running.push(e)
|
|
209
|
+
if (running.length > capacity) for (const r of running) out.set(r.id, running.filter((x) => x !== r).map((x) => x.id))
|
|
210
|
+
}
|
|
211
|
+
return out
|
|
212
|
+
}
|
|
213
|
+
const conflictMap = computed(() => {
|
|
214
|
+
const all = new Map<string, string[]>()
|
|
215
|
+
for (const [rid, list] of byResource.value) {
|
|
216
|
+
for (const [id, w] of overlapsOf(list, resourceById.value.get(rid)?.capacity ?? 1, spans.value)) all.set(id, w)
|
|
217
|
+
}
|
|
218
|
+
return all
|
|
219
|
+
})
|
|
220
|
+
const conflicts = computed(() => new Set(conflictMap.value.keys()))
|
|
221
|
+
|
|
222
|
+
type Row =
|
|
223
|
+
| { kind: 'group'; key: string; group: string; top: number; height: number; resources: TimelineResource[] }
|
|
224
|
+
| { kind: 'resource'; key: string; resource: TimelineResource; top: number; height: number }
|
|
225
|
+
const GROUP_H = 40
|
|
226
|
+
const rows = computed(() => {
|
|
227
|
+
const out: Row[] = []
|
|
228
|
+
const groups = new Map<string, TimelineResource[]>()
|
|
229
|
+
const order: (TimelineResource | string)[] = []
|
|
230
|
+
for (const r of props.resources) {
|
|
231
|
+
if (!r.group) { order.push(r); continue }
|
|
232
|
+
if (!groups.has(r.group)) { groups.set(r.group, []); order.push(r.group) }
|
|
233
|
+
groups.get(r.group)!.push(r)
|
|
234
|
+
}
|
|
235
|
+
let top = 0
|
|
236
|
+
const addResource = (r: TimelineResource) => {
|
|
237
|
+
const height = Math.max(props.rowHeight, (lanes.value.count.get(r.id) ?? 1) * props.laneHeight + 8)
|
|
238
|
+
out.push({ kind: 'resource', key: r.id, resource: r, top, height })
|
|
239
|
+
top += height
|
|
240
|
+
}
|
|
241
|
+
for (const item of order) {
|
|
242
|
+
if (typeof item !== 'string') { addResource(item); continue }
|
|
243
|
+
const rs = groups.get(item)!
|
|
244
|
+
out.push({ kind: 'group', key: `group:${item}`, group: item, top, height: GROUP_H, resources: rs })
|
|
245
|
+
top += GROUP_H
|
|
246
|
+
if (!foldedSet.value.has(item)) rs.forEach(addResource)
|
|
247
|
+
}
|
|
248
|
+
return out
|
|
249
|
+
})
|
|
250
|
+
const rowOf = computed(() => {
|
|
251
|
+
const m = new Map<string, Extract<Row, { kind: 'resource' }>>()
|
|
252
|
+
for (const r of rows.value) if (r.kind === 'resource') m.set(r.resource.id, r)
|
|
253
|
+
return m
|
|
254
|
+
})
|
|
255
|
+
const contentHeight = computed(() => {
|
|
256
|
+
const last = rows.value.at(-1)
|
|
257
|
+
return last ? last.top + last.height : 0
|
|
258
|
+
})
|
|
259
|
+
const groupOf = (rid: string) => resourceById.value.get(rid)?.group
|
|
260
|
+
|
|
261
|
+
// ── Axis ──────────────────────────────────────────────────────────────────────────────────────────────────
|
|
262
|
+
const scroller = ref<HTMLElement>()
|
|
263
|
+
const headerHeight = 56
|
|
264
|
+
const listW = ref(props.listWidth ?? 220)
|
|
265
|
+
watch(() => props.listWidth, (w) => { if (w !== undefined) listW.value = w })
|
|
266
|
+
const listWidth = computed(() => listW.value)
|
|
267
|
+
const extent = computed(() => {
|
|
268
|
+
let min = Infinity
|
|
269
|
+
let max = -Infinity
|
|
270
|
+
for (const s of spans.value.values()) { min = Math.min(min, s.start); max = Math.max(max, s.end) }
|
|
271
|
+
const now = props.start ? parseDate(props.start) : props.now ? parseDate(props.now) : Date.now()
|
|
272
|
+
if (!Number.isFinite(min)) { min = now; max = now + DAY }
|
|
273
|
+
return { min: Math.min(min, now), max: Math.max(max, now + DAY) }
|
|
274
|
+
})
|
|
275
|
+
const axis = useTimeAxis({
|
|
276
|
+
scroller,
|
|
277
|
+
listWidth,
|
|
278
|
+
headerHeight,
|
|
279
|
+
extent,
|
|
280
|
+
scale: () => props.scale,
|
|
281
|
+
pxPerDay: () => props.pxPerDay,
|
|
282
|
+
minPxPerDay: () => props.minPxPerDay,
|
|
283
|
+
maxPxPerDay: () => props.maxPxPerDay,
|
|
284
|
+
weekStartsOn: () => props.weekStartsOn,
|
|
285
|
+
lang,
|
|
286
|
+
quarterLabel: () => locale.ganttQuarter,
|
|
287
|
+
today: () => props.now,
|
|
288
|
+
calendar: () => props.calendar ?? { workingDays: [0, 1, 2, 3, 4, 5, 6] },
|
|
289
|
+
workHours: () => props.workHours,
|
|
290
|
+
onScale: (s) => emit('update:scale', s),
|
|
291
|
+
onPinch: () => { if (gesture) onCancel({ pointerId: gesture.id } as PointerEvent) },
|
|
292
|
+
})
|
|
293
|
+
const { ppd, view, timelineView, timelineWidth, todayMs, xOf, timeAt, zoomIn, zoomOut, setScale, scrollToDate, topCells, bottomCells, offTimes } = axis
|
|
294
|
+
|
|
295
|
+
const OVERSCAN = 400
|
|
296
|
+
const visibleRows = computed(() => {
|
|
297
|
+
const top = view.value.top - OVERSCAN
|
|
298
|
+
const bottom = view.value.top + view.value.height + OVERSCAN
|
|
299
|
+
return rows.value.filter((r) => r.top + r.height >= top && r.top <= bottom)
|
|
300
|
+
})
|
|
301
|
+
const visibleFrom = computed(() => timeAt(view.value.left - 400))
|
|
302
|
+
const visibleTo = computed(() => timeAt(view.value.left + timelineView.value + 400))
|
|
303
|
+
const visibleEvents = computed(() => {
|
|
304
|
+
const out: { event: TimelineEvent; row: Extract<Row, { kind: 'resource' }> }[] = []
|
|
305
|
+
for (const r of visibleRows.value) {
|
|
306
|
+
if (r.kind !== 'resource') continue
|
|
307
|
+
for (const e of byResource.value.get(r.resource.id) ?? []) {
|
|
308
|
+
const s = spans.value.get(e.id)!
|
|
309
|
+
if (s.end >= visibleFrom.value && s.start <= visibleTo.value) out.push({ event: e, row: r })
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return out
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
// ── Blocks: geometry and springs ──────────────────────────────────────────────────────────────────────────
|
|
316
|
+
type Geo = { x: number; y: number; w: number }
|
|
317
|
+
const blockH = computed(() => props.laneHeight - 8)
|
|
318
|
+
const geometry = computed(() => {
|
|
319
|
+
const m = new Map<string, Geo>()
|
|
320
|
+
for (const e of shown.value) {
|
|
321
|
+
const s = spans.value.get(e.id)
|
|
322
|
+
const row = rowOf.value.get(e.resourceId)
|
|
323
|
+
if (!s || !row) continue
|
|
324
|
+
// Lanes sit centered in a row taller than they need
|
|
325
|
+
const lanesH = (lanes.value.count.get(e.resourceId) ?? 1) * props.laneHeight
|
|
326
|
+
const y = row.top + (row.height - lanesH) / 2 + (lanes.value.lane.get(e.id) ?? 0) * props.laneHeight + 4
|
|
327
|
+
m.set(e.id, { x: xOf(s.start), y, w: Math.max(4, xOf(s.end) - xOf(s.start)) })
|
|
328
|
+
}
|
|
329
|
+
return m
|
|
330
|
+
})
|
|
331
|
+
const springs = new Map<string, { x: number; y: number; w: number; vx: number; vy: number; vw: number; tx: number; ty: number; tw: number }>()
|
|
332
|
+
const blockEls = new Map<string, HTMLElement>()
|
|
333
|
+
let springRaf = 0
|
|
334
|
+
let lastZoom = { ppd: ppd.value, origin: axis.origin.value }
|
|
335
|
+
watch(geometry, (g) => {
|
|
336
|
+
const instant = lastZoom.ppd !== ppd.value || lastZoom.origin !== axis.origin.value || prefersReducedMotion()
|
|
337
|
+
lastZoom = { ppd: ppd.value, origin: axis.origin.value }
|
|
338
|
+
let animate = false
|
|
339
|
+
for (const [id, t] of g) {
|
|
340
|
+
const s = springs.get(id)
|
|
341
|
+
if (!s || instant) {
|
|
342
|
+
springs.set(id, { ...t, vx: 0, vy: 0, vw: 0, tx: t.x, ty: t.y, tw: t.w })
|
|
343
|
+
continue
|
|
344
|
+
}
|
|
345
|
+
// The dragged booking follows the pointer as it is; the rest spring
|
|
346
|
+
if (dragging.value?.id === id && dragging.value.part === 'body') {
|
|
347
|
+
Object.assign(s, { x: t.x, y: t.y, w: t.w, tx: t.x, ty: t.y, tw: t.w, vx: 0, vy: 0, vw: 0 })
|
|
348
|
+
continue
|
|
349
|
+
}
|
|
350
|
+
if (s.tx !== t.x || s.ty !== t.y || s.tw !== t.w) { s.tx = t.x; s.ty = t.y; s.tw = t.w; animate = true }
|
|
351
|
+
}
|
|
352
|
+
for (const id of springs.keys()) if (!g.has(id)) springs.delete(id)
|
|
353
|
+
if (animate) startSprings()
|
|
354
|
+
else writeAll()
|
|
355
|
+
}, { immediate: true, flush: 'post' })
|
|
356
|
+
function startSprings() {
|
|
357
|
+
if (springRaf) return
|
|
358
|
+
let last = performance.now()
|
|
359
|
+
const k = 700
|
|
360
|
+
const c = 2 * 0.9 * Math.sqrt(k)
|
|
361
|
+
const step = (now: number) => {
|
|
362
|
+
let dt = Math.min((now - last) / 1000, 1 / 30)
|
|
363
|
+
last = now
|
|
364
|
+
while (dt > 0) {
|
|
365
|
+
const h = Math.min(dt, 0.004)
|
|
366
|
+
for (const s of springs.values()) {
|
|
367
|
+
s.vx += (-k * (s.x - s.tx) - c * s.vx) * h
|
|
368
|
+
s.x += s.vx * h
|
|
369
|
+
s.vy += (-k * (s.y - s.ty) - c * s.vy) * h
|
|
370
|
+
s.y += s.vy * h
|
|
371
|
+
s.vw += (-k * (s.w - s.tw) - c * s.vw) * h
|
|
372
|
+
s.w += s.vw * h
|
|
373
|
+
}
|
|
374
|
+
dt -= h
|
|
375
|
+
}
|
|
376
|
+
let moving = false
|
|
377
|
+
for (const s of springs.values()) {
|
|
378
|
+
if (Math.abs(s.x - s.tx) + Math.abs(s.y - s.ty) + Math.abs(s.w - s.tw) < 0.6 && Math.abs(s.vx) + Math.abs(s.vy) + Math.abs(s.vw) < 4) {
|
|
379
|
+
Object.assign(s, { x: s.tx, y: s.ty, w: s.tw, vx: 0, vy: 0, vw: 0 })
|
|
380
|
+
} else moving = true
|
|
381
|
+
}
|
|
382
|
+
writeAll()
|
|
383
|
+
springRaf = moving ? requestAnimationFrame(step) : 0
|
|
384
|
+
}
|
|
385
|
+
springRaf = requestAnimationFrame(step)
|
|
386
|
+
}
|
|
387
|
+
function writeBlock(id: string, el: HTMLElement) {
|
|
388
|
+
const s = springs.get(id)
|
|
389
|
+
if (!s) return
|
|
390
|
+
el.style.transform = `translate(${s.x}px, ${s.y}px)`
|
|
391
|
+
el.style.width = `${s.w}px`
|
|
392
|
+
}
|
|
393
|
+
function writeAll() {
|
|
394
|
+
for (const [id, el] of blockEls) writeBlock(id, el)
|
|
395
|
+
}
|
|
396
|
+
function bindBlock(id: string, el: unknown) {
|
|
397
|
+
if (el instanceof HTMLElement) {
|
|
398
|
+
blockEls.set(id, el)
|
|
399
|
+
writeBlock(id, el)
|
|
400
|
+
} else blockEls.delete(id)
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// ── Pointer gestures ──────────────────────────────────────────────────────────────────────────────────────
|
|
404
|
+
type Part = 'body' | 'start' | 'end'
|
|
405
|
+
type Gesture =
|
|
406
|
+
| { kind: 'event'; part: Part; id: number; eventId: string; sx: number; sy: number; sl: number; st: number; touch: boolean; active: boolean; span: Span; resourceId: string }
|
|
407
|
+
| { kind: 'empty'; id: number; resourceId: string; sx: number; sy: number; t0: number; touch: boolean; active: boolean }
|
|
408
|
+
| { kind: 'pan'; id: number; sx: number; sy: number; sl: number; st: number; moved: boolean; resourceId?: string }
|
|
409
|
+
| { kind: 'split'; id: number; sx: number; w: number }
|
|
410
|
+
let gesture: Gesture | null = null
|
|
411
|
+
let pressTimer: ReturnType<typeof setTimeout> | undefined
|
|
412
|
+
const dragging = ref<{ id: string; part: Part } | null>(null)
|
|
413
|
+
const draft = ref<{ resourceId: string; start: number; end: number } | null>(null)
|
|
414
|
+
const refused = ref(false)
|
|
415
|
+
const pointer = { x: 0, y: 0 }
|
|
416
|
+
const isControl = (t: EventTarget | null) => t instanceof Element && !!t.closest('input, textarea, select, button, a, [contenteditable], [data-timeline-action]')
|
|
417
|
+
|
|
418
|
+
function contentPoint(clientX: number, clientY: number) {
|
|
419
|
+
const r = scroller.value!.getBoundingClientRect()
|
|
420
|
+
return { x: clientX - r.left - listWidth.value + scroller.value!.scrollLeft, y: clientY - r.top - headerHeight + scroller.value!.scrollTop }
|
|
421
|
+
}
|
|
422
|
+
function resourceAtY(y: number) {
|
|
423
|
+
const r = rows.value.find((x) => y >= x.top && y < x.top + x.height)
|
|
424
|
+
return r?.kind === 'resource' ? r.resource : undefined
|
|
425
|
+
}
|
|
426
|
+
function snapStep(dateOnly: boolean) {
|
|
427
|
+
// 15 minutes while they're at least 2 px wide, coarser as it zooms out
|
|
428
|
+
return dateOnly ? 1440 : (props.snap ?? (ppd.value >= 192 ? 15 : defaultSnap(ppd.value)))
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function onEventDown(e: PointerEvent, ev: TimelineEvent, part: Part) {
|
|
432
|
+
if (e.button !== 0 || isControl(e.target)) return
|
|
433
|
+
e.stopPropagation()
|
|
434
|
+
const s = spans.value.get(ev.id)
|
|
435
|
+
if (!s) return
|
|
436
|
+
const touch = e.pointerType === 'touch'
|
|
437
|
+
gesture = { kind: 'event', part, id: e.pointerId, eventId: ev.id, sx: e.clientX, sy: e.clientY, sl: scroller.value!.scrollLeft, st: scroller.value!.scrollTop, touch, active: false, span: s, resourceId: ev.resourceId }
|
|
438
|
+
addWindow()
|
|
439
|
+
if (touch && part === 'body') pressTimer = setTimeout(() => activate(), 250)
|
|
440
|
+
else if (touch) activate()
|
|
441
|
+
}
|
|
442
|
+
function onPaneDown(e: PointerEvent) {
|
|
443
|
+
if (e.button !== 0 || isControl(e.target)) return
|
|
444
|
+
const p = contentPoint(e.clientX, e.clientY)
|
|
445
|
+
const res = resourceAtY(p.y)
|
|
446
|
+
const touch = e.pointerType === 'touch'
|
|
447
|
+
if (res && props.creatable && !props.readonly) {
|
|
448
|
+
gesture = { kind: 'empty', id: e.pointerId, resourceId: res.id, sx: e.clientX, sy: e.clientY, t0: timeAt(p.x), touch, active: false }
|
|
449
|
+
addWindow()
|
|
450
|
+
if (touch) pressTimer = setTimeout(() => activate(), 350)
|
|
451
|
+
return
|
|
452
|
+
}
|
|
453
|
+
if (touch) {
|
|
454
|
+
if (res) {
|
|
455
|
+
gesture = { kind: 'empty', id: e.pointerId, resourceId: res.id, sx: e.clientX, sy: e.clientY, t0: timeAt(p.x), touch, active: false }
|
|
456
|
+
addWindow()
|
|
457
|
+
}
|
|
458
|
+
return
|
|
459
|
+
}
|
|
460
|
+
gesture = { kind: 'pan', id: e.pointerId, sx: e.clientX, sy: e.clientY, sl: scroller.value!.scrollLeft, st: scroller.value!.scrollTop, moved: false, resourceId: res?.id }
|
|
461
|
+
addWindow()
|
|
462
|
+
}
|
|
463
|
+
function onSplitDown(e: PointerEvent) {
|
|
464
|
+
if (e.button !== 0) return
|
|
465
|
+
e.preventDefault()
|
|
466
|
+
gesture = { kind: 'split', id: e.pointerId, sx: e.clientX, w: listW.value }
|
|
467
|
+
addWindow()
|
|
468
|
+
}
|
|
469
|
+
function addWindow() {
|
|
470
|
+
window.addEventListener('pointermove', onMove)
|
|
471
|
+
window.addEventListener('pointerup', onUp)
|
|
472
|
+
window.addEventListener('pointercancel', onCancel)
|
|
473
|
+
}
|
|
474
|
+
function removeWindow() {
|
|
475
|
+
window.removeEventListener('pointermove', onMove)
|
|
476
|
+
window.removeEventListener('pointerup', onUp)
|
|
477
|
+
window.removeEventListener('pointercancel', onCancel)
|
|
478
|
+
clearTimeout(pressTimer)
|
|
479
|
+
document.body.style.userSelect = ''
|
|
480
|
+
}
|
|
481
|
+
function activate() {
|
|
482
|
+
const g = gesture
|
|
483
|
+
if (!g || (g.kind !== 'event' && g.kind !== 'empty') || g.active) return
|
|
484
|
+
if (g.kind === 'event') {
|
|
485
|
+
const ev = eventById.value.get(g.eventId)
|
|
486
|
+
if (!ev || props.readonly) return
|
|
487
|
+
if (g.part === 'body' && ev.draggable === false) return
|
|
488
|
+
if (g.part !== 'body' && ev.resizable === false) return
|
|
489
|
+
g.active = true
|
|
490
|
+
if (!selectedSet.value.has(ev.id)) setSelection([ev.id])
|
|
491
|
+
dragging.value = { id: ev.id, part: g.part }
|
|
492
|
+
} else {
|
|
493
|
+
if (!props.creatable || props.readonly) return
|
|
494
|
+
g.active = true
|
|
495
|
+
const step = snapStep(false) * 60_000
|
|
496
|
+
const s = snapTime(g.t0, snapStep(false))
|
|
497
|
+
draft.value = { resourceId: g.resourceId, start: s, end: s + Math.max(step, HOUR) }
|
|
498
|
+
}
|
|
499
|
+
if (g.touch) navigator.vibrate?.(10)
|
|
500
|
+
document.body.style.userSelect = 'none'
|
|
501
|
+
startAutoScroll()
|
|
502
|
+
}
|
|
503
|
+
function onMove(e: PointerEvent) {
|
|
504
|
+
const g = gesture
|
|
505
|
+
if (!g || g.id !== e.pointerId) return
|
|
506
|
+
pointer.x = e.clientX
|
|
507
|
+
pointer.y = e.clientY
|
|
508
|
+
if (g.kind === 'split') {
|
|
509
|
+
const w = Math.round(Math.min(Math.max(0, g.w + e.clientX - g.sx), Math.max(160, view.value.width - 80)))
|
|
510
|
+
listW.value = w
|
|
511
|
+
emit('update:listWidth', w)
|
|
512
|
+
return
|
|
513
|
+
}
|
|
514
|
+
if (g.kind === 'pan') {
|
|
515
|
+
const dx = e.clientX - g.sx
|
|
516
|
+
const dy = e.clientY - g.sy
|
|
517
|
+
if (!g.moved && Math.hypot(dx, dy) < 4) return
|
|
518
|
+
g.moved = true
|
|
519
|
+
scroller.value!.scrollLeft = g.sl - dx
|
|
520
|
+
scroller.value!.scrollTop = g.st - dy
|
|
521
|
+
return
|
|
522
|
+
}
|
|
523
|
+
if (!g.active) {
|
|
524
|
+
const d = Math.hypot(e.clientX - g.sx, e.clientY - g.sy)
|
|
525
|
+
if (g.touch) {
|
|
526
|
+
if (d > 8) { gesture = null; removeWindow() }
|
|
527
|
+
return
|
|
528
|
+
}
|
|
529
|
+
if (d < 4) return
|
|
530
|
+
activate()
|
|
531
|
+
if (!g.active) return
|
|
532
|
+
}
|
|
533
|
+
dragTo(e.clientX, e.clientY)
|
|
534
|
+
}
|
|
535
|
+
function dragTo(clientX: number, clientY: number) {
|
|
536
|
+
const g = gesture
|
|
537
|
+
if (!g || (g.kind !== 'event' && g.kind !== 'empty') || !g.active) return
|
|
538
|
+
const p = contentPoint(clientX, clientY)
|
|
539
|
+
if (g.kind === 'empty') {
|
|
540
|
+
const step = snapStep(false)
|
|
541
|
+
const a = snapTime(g.t0, step)
|
|
542
|
+
const b = snapTime(timeAt(p.x), step)
|
|
543
|
+
const min = Math.max(step * 60_000, 15 * 60_000)
|
|
544
|
+
draft.value = { resourceId: g.resourceId, start: Math.min(a, b), end: Math.max(Math.max(a, b), Math.min(a, b) + min) }
|
|
545
|
+
return
|
|
546
|
+
}
|
|
547
|
+
const ev = current.value.find((x) => x.id === g.eventId)
|
|
548
|
+
if (!ev) return
|
|
549
|
+
const s0 = g.span
|
|
550
|
+
const dt = ((clientX - g.sx + (scroller.value!.scrollLeft - g.sl)) / ppd.value) * DAY
|
|
551
|
+
const step = snapStep(s0.dateOnly)
|
|
552
|
+
const min = s0.dateOnly ? DAY : step * 60_000
|
|
553
|
+
let next: TimelineEvent
|
|
554
|
+
if (g.part === 'body') {
|
|
555
|
+
const ns = snapTime(s0.start + dt, step)
|
|
556
|
+
const res = resourceAtY(p.y)
|
|
557
|
+
const resourceId = res && !props.readonly ? res.id : ev.resourceId
|
|
558
|
+
next = { ...ev, ...spanDates({ start: ev.start, end: ev.end }, ns, ns + (s0.end - s0.start)) as { start: string; end: string }, resourceId }
|
|
559
|
+
} else if (g.part === 'start') {
|
|
560
|
+
const ns = Math.min(snapTime(s0.start + dt, step), s0.end - min)
|
|
561
|
+
next = { ...ev, ...spanDates({ start: ev.start, end: ev.end }, ns, s0.end) as { start: string; end: string } }
|
|
562
|
+
} else {
|
|
563
|
+
const ne = Math.max(snapTime(s0.end + dt, step), s0.start + min)
|
|
564
|
+
next = { ...ev, ...spanDates({ start: ev.start, end: ev.end }, s0.start, ne) as { start: string; end: string } }
|
|
565
|
+
}
|
|
566
|
+
const list = current.value.map((x) => (x.id === ev.id ? next : x))
|
|
567
|
+
preview.value = list
|
|
568
|
+
refused.value = props.overlap === 'prevent' && clashes(next, list).length > 0
|
|
569
|
+
}
|
|
570
|
+
// The bookings `ev` would overlap past its resource's capacity
|
|
571
|
+
function clashes(ev: TimelineEvent, list: TimelineEvent[]): TimelineEvent[] {
|
|
572
|
+
const sp = new Map<string, Span>()
|
|
573
|
+
const same = list.filter((x) => x.resourceId === ev.resourceId)
|
|
574
|
+
for (const x of same) sp.set(x.id, taskSpan({ start: x.start, end: x.end }))
|
|
575
|
+
same.sort((a, b) => sp.get(a.id)!.start - sp.get(b.id)!.start)
|
|
576
|
+
const hit = overlapsOf(same, resourceById.value.get(ev.resourceId)?.capacity ?? 1, sp).get(ev.id)
|
|
577
|
+
return hit ? same.filter((x) => hit.includes(x.id)) : []
|
|
578
|
+
}
|
|
579
|
+
function onUp(e: PointerEvent) {
|
|
580
|
+
const g = gesture
|
|
581
|
+
if (!g || g.id !== e.pointerId) return
|
|
582
|
+
gesture = null
|
|
583
|
+
removeWindow()
|
|
584
|
+
stopAutoScroll()
|
|
585
|
+
if (g.kind === 'split') return
|
|
586
|
+
if (g.kind === 'pan') {
|
|
587
|
+
if (!g.moved && g.resourceId) emit('slot-click', { resourceId: g.resourceId, start: formatDate(snapTime(timeAt(contentPoint(e.clientX, e.clientY).x), snapStep(false)), false) })
|
|
588
|
+
if (!g.moved) setSelection([])
|
|
589
|
+
return
|
|
590
|
+
}
|
|
591
|
+
if (g.kind === 'empty') {
|
|
592
|
+
const d = draft.value
|
|
593
|
+
draft.value = null
|
|
594
|
+
if (g.active && d) emit('create', { resourceId: d.resourceId, start: formatDate(d.start, false), end: formatDate(d.end, false) })
|
|
595
|
+
else if (!g.active) {
|
|
596
|
+
emit('slot-click', { resourceId: g.resourceId, start: formatDate(snapTime(g.t0, snapStep(false)), false) })
|
|
597
|
+
setSelection([])
|
|
598
|
+
}
|
|
599
|
+
return
|
|
600
|
+
}
|
|
601
|
+
dragging.value = null
|
|
602
|
+
const ev = eventById.value.get(g.eventId)
|
|
603
|
+
if (!g.active) {
|
|
604
|
+
preview.value = null
|
|
605
|
+
if (!ev) return
|
|
606
|
+
if (ev.selectable !== false) {
|
|
607
|
+
if (e.shiftKey || e.ctrlKey || e.metaKey) setSelection(selectedSet.value.has(ev.id) ? selected.value.filter((x) => x !== ev.id) : [...selected.value, ev.id])
|
|
608
|
+
else setSelection([ev.id])
|
|
609
|
+
}
|
|
610
|
+
emit('event-click', ev, e)
|
|
611
|
+
return
|
|
612
|
+
}
|
|
613
|
+
const next = preview.value
|
|
614
|
+
preview.value = null
|
|
615
|
+
const moved = next?.find((x) => x.id === g.eventId)
|
|
616
|
+
const before = current.value.find((x) => x.id === g.eventId)
|
|
617
|
+
refused.value = false
|
|
618
|
+
if (!next || !moved || !before || (moved.start === before.start && moved.end === before.end && moved.resourceId === before.resourceId)) return
|
|
619
|
+
if (props.overlap === 'prevent') {
|
|
620
|
+
const hit = clashes(moved, next)
|
|
621
|
+
if (hit.length) {
|
|
622
|
+
emit('conflict', { event: moved, with: hit })
|
|
623
|
+
announce(locale.timelineConflict)
|
|
624
|
+
return
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
commit(next)
|
|
628
|
+
emit('change', { events: [moved], kind: g.part === 'body' ? 'move' : 'resize' })
|
|
629
|
+
announceMove(moved)
|
|
630
|
+
}
|
|
631
|
+
function onCancel(e: PointerEvent) {
|
|
632
|
+
if (!gesture || gesture.id !== e.pointerId) return
|
|
633
|
+
gesture = null
|
|
634
|
+
removeWindow()
|
|
635
|
+
stopAutoScroll()
|
|
636
|
+
preview.value = null
|
|
637
|
+
dragging.value = null
|
|
638
|
+
draft.value = null
|
|
639
|
+
refused.value = false
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
let autoRaf = 0
|
|
643
|
+
function startAutoScroll() {
|
|
644
|
+
if (autoRaf) return
|
|
645
|
+
const step = () => {
|
|
646
|
+
autoRaf = requestAnimationFrame(step)
|
|
647
|
+
const el = scroller.value
|
|
648
|
+
if (!el || !gesture || !('active' in gesture) || !gesture.active) return
|
|
649
|
+
const r = el.getBoundingClientRect()
|
|
650
|
+
const edge = 40
|
|
651
|
+
const left = r.left + listWidth.value
|
|
652
|
+
let dx = 0
|
|
653
|
+
let dy = 0
|
|
654
|
+
if (pointer.x < left + edge) dx = -Math.ceil((left + edge - pointer.x) / 4)
|
|
655
|
+
else if (pointer.x > r.right - edge) dx = Math.ceil((pointer.x - r.right + edge) / 4)
|
|
656
|
+
if (pointer.y < r.top + headerHeight + edge) dy = -Math.ceil((r.top + headerHeight + edge - pointer.y) / 4)
|
|
657
|
+
else if (pointer.y > r.bottom - edge) dy = Math.ceil((pointer.y - r.bottom + edge) / 4)
|
|
658
|
+
if (!dx && !dy) return
|
|
659
|
+
el.scrollLeft += dx
|
|
660
|
+
el.scrollTop += dy
|
|
661
|
+
dragTo(pointer.x, pointer.y)
|
|
662
|
+
}
|
|
663
|
+
autoRaf = requestAnimationFrame(step)
|
|
664
|
+
}
|
|
665
|
+
function stopAutoScroll() {
|
|
666
|
+
cancelAnimationFrame(autoRaf)
|
|
667
|
+
autoRaf = 0
|
|
668
|
+
}
|
|
669
|
+
function onTouchMove(e: TouchEvent) {
|
|
670
|
+
if (axis.pinchMove(e)) return
|
|
671
|
+
if (gesture && 'active' in gesture && gesture.active && e.cancelable) e.preventDefault()
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// ── Editing API, keyboard ─────────────────────────────────────────────────────────────────────────────────
|
|
675
|
+
const message = ref('')
|
|
676
|
+
function announce(text: string) {
|
|
677
|
+
message.value = ''
|
|
678
|
+
nextTick(() => { message.value = text })
|
|
679
|
+
}
|
|
680
|
+
function formatTime(s: string) {
|
|
681
|
+
const ms = parseDate(s)
|
|
682
|
+
const dateOnly = /^\d{4}-\d{2}-\d{2}$/.test(s)
|
|
683
|
+
return new Intl.DateTimeFormat(lang.value, dateOnly ? { day: 'numeric', month: 'short' } : { weekday: 'short', hour: 'numeric', minute: '2-digit' }).format(ms)
|
|
684
|
+
}
|
|
685
|
+
function timeRange(ev: TimelineEvent) {
|
|
686
|
+
const s = parseDate(ev.start)
|
|
687
|
+
const e = parseDate(ev.end)
|
|
688
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(ev.start)) return `${formatTime(ev.start)} – ${formatTime(ev.end)}`
|
|
689
|
+
// Minutes only when there are some: "9–17:30", "9 AM–5 PM"
|
|
690
|
+
const f = (ms: number) => new Intl.DateTimeFormat(lang.value, new Date(ms).getMinutes() ? { hour: 'numeric', minute: '2-digit' } : { hour: 'numeric' }).format(ms)
|
|
691
|
+
return `${f(s)}–${f(e)}`
|
|
692
|
+
}
|
|
693
|
+
function announceMove(ev: TimelineEvent) {
|
|
694
|
+
announce(locale.timelineMoved.replace('{title}', ev.title).replace('{resource}', resourceById.value.get(ev.resourceId)?.name ?? '').replace('{start}', formatTime(ev.start)).replace('{end}', formatTime(ev.end)))
|
|
695
|
+
}
|
|
696
|
+
function addEvents(events: TimelineEvent | TimelineEvent[]) {
|
|
697
|
+
commit([...current.value, ...(Array.isArray(events) ? events : [events])])
|
|
698
|
+
}
|
|
699
|
+
function updateEvent(id: string, patch: Partial<TimelineEvent> | ((e: TimelineEvent) => TimelineEvent)) {
|
|
700
|
+
commit(current.value.map((e) => (e.id === id ? (typeof patch === 'function' ? patch(e) : { ...e, ...patch }) : e)))
|
|
701
|
+
}
|
|
702
|
+
async function removeEvents(ids: string[]) {
|
|
703
|
+
const gone = current.value.filter((e) => ids.includes(e.id) && e.deletable !== false)
|
|
704
|
+
if (!gone.length) return
|
|
705
|
+
if (props.beforeDelete && !(await props.beforeDelete(gone))) return
|
|
706
|
+
const set = new Set(gone.map((e) => e.id))
|
|
707
|
+
commit(current.value.filter((e) => !set.has(e.id)))
|
|
708
|
+
setSelection(selected.value.filter((id) => !set.has(id)))
|
|
709
|
+
emit('delete', { events: gone })
|
|
710
|
+
announce(locale.ganttDeleted.replace('{count}', String(gone.length)))
|
|
711
|
+
}
|
|
712
|
+
function resourceRows() {
|
|
713
|
+
return rows.value.filter((r): r is Extract<Row, { kind: 'resource' }> => r.kind === 'resource')
|
|
714
|
+
}
|
|
715
|
+
function onEventKey(e: KeyboardEvent, ev: TimelineEvent) {
|
|
716
|
+
const mod = e.ctrlKey || e.metaKey
|
|
717
|
+
if (mod && e.key.toLowerCase() === 'z') { e.preventDefault(); e.shiftKey ? redo() : undo(); return }
|
|
718
|
+
if (mod && e.key.toLowerCase() === 'y') { e.preventDefault(); redo(); return }
|
|
719
|
+
if (e.key === 'Enter') { e.preventDefault(); emit('event-dblclick', ev, e); return }
|
|
720
|
+
if (props.readonly) return
|
|
721
|
+
if (e.key === 'Delete' || e.key === 'Backspace') {
|
|
722
|
+
e.preventDefault()
|
|
723
|
+
removeEvents(selectedSet.value.has(ev.id) ? selected.value : [ev.id])
|
|
724
|
+
return
|
|
725
|
+
}
|
|
726
|
+
const s = spans.value.get(ev.id)
|
|
727
|
+
if (!s) return
|
|
728
|
+
const step = s.dateOnly ? DAY : snapStep(false) * 60_000
|
|
729
|
+
let next: TimelineEvent | null = null
|
|
730
|
+
if ((e.key === 'ArrowLeft' || e.key === 'ArrowRight') && ev.draggable !== false) {
|
|
731
|
+
const d = e.key === 'ArrowLeft' ? -step : step
|
|
732
|
+
if (e.shiftKey) {
|
|
733
|
+
if (ev.resizable === false) return
|
|
734
|
+
next = { ...ev, ...spanDates({ start: ev.start, end: ev.end }, s.start, Math.max(s.start + step, s.end + d)) as { start: string; end: string } }
|
|
735
|
+
} else next = { ...ev, ...spanDates({ start: ev.start, end: ev.end }, s.start + d, s.end + d) as { start: string; end: string } }
|
|
736
|
+
} else if ((e.key === 'ArrowUp' || e.key === 'ArrowDown') && ev.draggable !== false) {
|
|
737
|
+
const list = resourceRows()
|
|
738
|
+
const i = list.findIndex((r) => r.resource.id === ev.resourceId)
|
|
739
|
+
const other = list[i + (e.key === 'ArrowUp' ? -1 : 1)]
|
|
740
|
+
if (other) next = { ...ev, resourceId: other.resource.id }
|
|
741
|
+
}
|
|
742
|
+
if (!next) return
|
|
743
|
+
e.preventDefault()
|
|
744
|
+
const list = current.value.map((x) => (x.id === ev.id ? next! : x))
|
|
745
|
+
if (props.overlap === 'prevent' && clashes(next, list).length) {
|
|
746
|
+
emit('conflict', { event: next, with: clashes(next, list) })
|
|
747
|
+
announce(locale.timelineConflict)
|
|
748
|
+
return
|
|
749
|
+
}
|
|
750
|
+
commit(list)
|
|
751
|
+
emit('change', { events: [next], kind: e.shiftKey ? 'resize' : 'move' })
|
|
752
|
+
announceMove(next)
|
|
753
|
+
nextTick(() => blockEls.get(ev.id)?.querySelector<HTMLElement>('[data-timeline-event]')?.focus({ preventScroll: true }))
|
|
754
|
+
}
|
|
755
|
+
function scrollToEvent(id: string) {
|
|
756
|
+
const ev = eventById.value.get(id)
|
|
757
|
+
if (!ev) return
|
|
758
|
+
const g = groupOf(ev.resourceId)
|
|
759
|
+
if (g && foldedSet.value.has(g)) toggleGroup(g)
|
|
760
|
+
nextTick(() => {
|
|
761
|
+
const geo = geometry.value.get(id)
|
|
762
|
+
const el = scroller.value
|
|
763
|
+
if (!geo || !el) return
|
|
764
|
+
el.scrollTo({ left: Math.max(0, geo.x - 48), top: Math.max(0, geo.y - 48), behavior: prefersReducedMotion() ? 'auto' : 'smooth' })
|
|
765
|
+
})
|
|
766
|
+
}
|
|
767
|
+
function onRootKey(e: KeyboardEvent) {
|
|
768
|
+
const mod = e.ctrlKey || e.metaKey
|
|
769
|
+
if (mod && e.key.toLowerCase() === 'z' && !(e.target as HTMLElement).closest?.('[data-timeline-event]')) { e.preventDefault(); e.shiftKey ? redo() : undo() }
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
const TONES = {
|
|
773
|
+
primary: 'bg-primary-container text-on-primary-container',
|
|
774
|
+
secondary: 'bg-secondary-container text-on-secondary-container',
|
|
775
|
+
tertiary: 'bg-tertiary-container text-on-tertiary-container',
|
|
776
|
+
error: 'bg-error-container text-on-error-container',
|
|
777
|
+
success: 'bg-success-container text-on-success-container',
|
|
778
|
+
neutral: 'bg-surface-container-highest text-on-surface',
|
|
779
|
+
}
|
|
780
|
+
const ACCENT = { primary: 'bg-primary', secondary: 'bg-secondary', tertiary: 'bg-tertiary', error: 'bg-error', success: 'bg-success', neutral: 'bg-outline' }
|
|
781
|
+
const toneOf = (ev: TimelineEvent) => ev.color ?? resourceById.value.get(ev.resourceId)?.color ?? 'primary'
|
|
782
|
+
function initials(name: string) {
|
|
783
|
+
return name.split(/\s+/).filter(Boolean).slice(0, 2).map((w) => w[0]!.toUpperCase()).join('')
|
|
784
|
+
}
|
|
785
|
+
const bookedHours = computed(() => {
|
|
786
|
+
const m = new Map<string, number>()
|
|
787
|
+
for (const e of shown.value) {
|
|
788
|
+
const s = spans.value.get(e.id)
|
|
789
|
+
if (s) m.set(e.resourceId, (m.get(e.resourceId) ?? 0) + (s.end - s.start) / HOUR)
|
|
790
|
+
}
|
|
791
|
+
return m
|
|
792
|
+
})
|
|
793
|
+
|
|
794
|
+
// ── Context ───────────────────────────────────────────────────────────────────────────────────────────────
|
|
795
|
+
const context: ResourceTimelineContext = {
|
|
796
|
+
events: computed(() => shown.value),
|
|
797
|
+
selection: computed(() => selected.value),
|
|
798
|
+
conflicts,
|
|
799
|
+
scale: axis.scaleNow,
|
|
800
|
+
pxPerDay: ppd,
|
|
801
|
+
canUndo,
|
|
802
|
+
canRedo,
|
|
803
|
+
undo,
|
|
804
|
+
redo,
|
|
805
|
+
zoomIn,
|
|
806
|
+
zoomOut,
|
|
807
|
+
setScale,
|
|
808
|
+
scrollToDate,
|
|
809
|
+
scrollToEvent,
|
|
810
|
+
setSelection,
|
|
811
|
+
addEvents,
|
|
812
|
+
updateEvent,
|
|
813
|
+
removeEvents,
|
|
814
|
+
dateAt: (clientX) => {
|
|
815
|
+
const r = scroller.value?.getBoundingClientRect()
|
|
816
|
+
return formatDate(snapTime(timeAt(clientX - (r?.left ?? 0) - listWidth.value + view.value.left), snapStep(false)), false)
|
|
817
|
+
},
|
|
818
|
+
resourceAt: (clientY) => {
|
|
819
|
+
const r = scroller.value?.getBoundingClientRect()
|
|
820
|
+
return resourceAtY(clientY - (r?.top ?? 0) - headerHeight + view.value.top)
|
|
821
|
+
},
|
|
822
|
+
}
|
|
823
|
+
provide(RESOURCE_TIMELINE_KEY, context)
|
|
824
|
+
provide(TIMELINE_CONTROLS_KEY, {
|
|
825
|
+
scale: axis.scaleNow,
|
|
826
|
+
readonly: computed(() => props.readonly),
|
|
827
|
+
canUndo,
|
|
828
|
+
canRedo,
|
|
829
|
+
foldable: computed(() => props.resources.some((r) => r.group)),
|
|
830
|
+
folded: computed(() => folded.value.length > 0),
|
|
831
|
+
undo,
|
|
832
|
+
redo,
|
|
833
|
+
zoomIn,
|
|
834
|
+
zoomOut,
|
|
835
|
+
setScale,
|
|
836
|
+
scrollToDate,
|
|
837
|
+
expandAll: () => setFolded([]),
|
|
838
|
+
collapseAll: () => setFolded([...new Set(props.resources.map((r) => r.group).filter((g): g is string => !!g))]),
|
|
839
|
+
})
|
|
840
|
+
|
|
841
|
+
onMounted(() => {
|
|
842
|
+
const el = scroller.value!
|
|
843
|
+
el.addEventListener('touchmove', onTouchMove, { passive: false })
|
|
844
|
+
nextTick(() => {
|
|
845
|
+
const at = props.start ? parseDate(props.start) : todayMs.value ?? extent.value.min
|
|
846
|
+
el.scrollLeft = Math.max(0, xOf(at) - Math.min(48, timelineView.value / 4))
|
|
847
|
+
view.value.left = el.scrollLeft
|
|
848
|
+
})
|
|
849
|
+
})
|
|
850
|
+
onBeforeUnmount(() => {
|
|
851
|
+
scroller.value?.removeEventListener('touchmove', onTouchMove)
|
|
852
|
+
removeWindow()
|
|
853
|
+
stopAutoScroll()
|
|
854
|
+
cancelAnimationFrame(springRaf)
|
|
855
|
+
})
|
|
856
|
+
|
|
857
|
+
defineExpose(context)
|
|
858
|
+
</script>
|
|
859
|
+
|
|
860
|
+
<template>
|
|
861
|
+
<div class="m3-resource-timeline flex flex-col overflow-hidden rounded-md bg-surface text-on-surface" @keydown="onRootKey">
|
|
862
|
+
<slot :timeline="context" />
|
|
863
|
+
<div
|
|
864
|
+
ref="scroller"
|
|
865
|
+
class="relative min-h-0 flex-1 touch-pan-x touch-pan-y overflow-auto overscroll-contain"
|
|
866
|
+
@scroll.passive="axis.readView"
|
|
867
|
+
@touchstart.passive="axis.onTouchStart"
|
|
868
|
+
@touchend.passive="axis.onTouchEnd"
|
|
869
|
+
@contextmenu="gesture && $event.preventDefault()"
|
|
870
|
+
>
|
|
871
|
+
<div class="relative" :style="{ width: `${listWidth + timelineWidth}px`, height: `${headerHeight + Math.max(contentHeight, view.height - headerHeight)}px` }">
|
|
872
|
+
<div class="sticky top-0 z-20 flex" :style="{ height: `${headerHeight}px`, width: `${listWidth + timelineWidth}px` }">
|
|
873
|
+
<div
|
|
874
|
+
v-if="listWidth"
|
|
875
|
+
class="sticky left-0 z-10 flex shrink-0 items-end border-r border-b border-outline-variant bg-surface-container-low px-4 pb-2 text-label-medium text-on-surface-variant"
|
|
876
|
+
:style="{ width: `${listWidth}px` }"
|
|
877
|
+
>
|
|
878
|
+
{{ locale.timelineResource }}
|
|
879
|
+
</div>
|
|
880
|
+
<MTimeHeader :width="timelineWidth" :top-cells="topCells" :bottom-cells="bottomCells" :today-x="todayMs === null ? null : xOf(todayMs)" />
|
|
881
|
+
</div>
|
|
882
|
+
|
|
883
|
+
<div class="flex" :style="{ height: `${Math.max(contentHeight, view.height - headerHeight)}px` }">
|
|
884
|
+
<!-- Resources -->
|
|
885
|
+
<div v-if="listWidth" class="sticky left-0 z-10 shrink-0 border-r border-outline-variant bg-surface" :style="{ width: `${listWidth}px` }" role="list" :aria-label="label">
|
|
886
|
+
<template v-for="r in visibleRows" :key="r.key">
|
|
887
|
+
<button
|
|
888
|
+
v-if="r.kind === 'group'"
|
|
889
|
+
type="button"
|
|
890
|
+
class="absolute inset-x-0 flex items-center gap-1 border-b border-outline-variant/60 bg-surface-container-low px-2 text-left text-title-small text-on-surface outline-none hover:bg-on-surface/8 focus-visible:ring-2 focus-visible:ring-secondary focus-visible:ring-inset"
|
|
891
|
+
:style="{ top: `${r.top}px`, height: `${r.height}px` }"
|
|
892
|
+
:aria-expanded="!foldedSet.has(r.group)"
|
|
893
|
+
@click="toggleGroup(r.group)"
|
|
894
|
+
>
|
|
895
|
+
<span class="material-symbols-outlined text-[20px] text-on-surface-variant transition-transform duration-200" :class="foldedSet.has(r.group) ? '-rotate-90' : ''">expand_more</span>
|
|
896
|
+
<slot name="group" :group="r.group" :resources="r.resources" :collapsed="foldedSet.has(r.group)">
|
|
897
|
+
<span class="truncate">{{ r.group }}</span>
|
|
898
|
+
<span class="ml-auto pr-2 text-label-medium text-on-surface-variant">{{ r.resources.length }}</span>
|
|
899
|
+
</slot>
|
|
900
|
+
</button>
|
|
901
|
+
<div
|
|
902
|
+
v-else
|
|
903
|
+
role="listitem"
|
|
904
|
+
class="absolute inset-x-0 flex items-center gap-3 border-b border-outline-variant/60 px-4"
|
|
905
|
+
:style="{ top: `${r.top}px`, height: `${r.height}px` }"
|
|
906
|
+
>
|
|
907
|
+
<slot name="resource" :resource="r.resource" :events="byResource.get(r.resource.id) ?? []" :hours="Math.round((bookedHours.get(r.resource.id) ?? 0) * 10) / 10">
|
|
908
|
+
<img v-if="r.resource.avatar" :src="r.resource.avatar" alt="" class="size-9 shrink-0 rounded-full object-cover">
|
|
909
|
+
<span
|
|
910
|
+
v-else
|
|
911
|
+
class="flex size-9 shrink-0 items-center justify-center rounded-full text-label-large"
|
|
912
|
+
:class="TONES[r.resource.color ?? 'neutral']"
|
|
913
|
+
>
|
|
914
|
+
<span v-if="r.resource.icon" class="material-symbols-outlined text-[20px]">{{ r.resource.icon }}</span>
|
|
915
|
+
<template v-else>{{ initials(r.resource.name) }}</template>
|
|
916
|
+
</span>
|
|
917
|
+
<span class="min-w-0">
|
|
918
|
+
<span class="block truncate text-body-large text-on-surface">{{ r.resource.name }}</span>
|
|
919
|
+
<span v-if="r.resource.subtitle" class="block truncate text-body-small text-on-surface-variant">{{ r.resource.subtitle }}</span>
|
|
920
|
+
</span>
|
|
921
|
+
</slot>
|
|
922
|
+
</div>
|
|
923
|
+
</template>
|
|
924
|
+
<div
|
|
925
|
+
role="separator"
|
|
926
|
+
aria-orientation="vertical"
|
|
927
|
+
:aria-label="locale.ganttResize"
|
|
928
|
+
tabindex="0"
|
|
929
|
+
class="absolute inset-y-0 -right-1 z-30 w-2 cursor-col-resize touch-none outline-none hover:bg-primary/20 focus-visible:bg-primary/30"
|
|
930
|
+
@pointerdown="onSplitDown"
|
|
931
|
+
@keydown.left.prevent="listW = Math.max(120, listW - 16); emit('update:listWidth', listW)"
|
|
932
|
+
@keydown.right.prevent="listW = listW + 16; emit('update:listWidth', listW)"
|
|
933
|
+
/>
|
|
934
|
+
</div>
|
|
935
|
+
|
|
936
|
+
<!-- Timeline -->
|
|
937
|
+
<div class="relative shrink-0" :style="{ width: `${timelineWidth}px` }" @pointerdown="onPaneDown">
|
|
938
|
+
<MTimeBackground :off-times="offTimes" :cells="bottomCells" :today-x="todayMs === null ? null : xOf(todayMs)" />
|
|
939
|
+
<div
|
|
940
|
+
v-for="r in visibleRows"
|
|
941
|
+
:key="`r${r.key}`"
|
|
942
|
+
class="pointer-events-none absolute inset-x-0 border-b border-outline-variant/60"
|
|
943
|
+
:class="r.kind === 'group' ? 'bg-surface-container-low/60' : ''"
|
|
944
|
+
:style="{ top: `${r.top}px`, height: `${r.height}px` }"
|
|
945
|
+
/>
|
|
946
|
+
<!-- A booking being drawn on empty time -->
|
|
947
|
+
<div
|
|
948
|
+
v-if="draft && rowOf.get(draft.resourceId)"
|
|
949
|
+
class="pointer-events-none absolute rounded-sm border-2 border-dashed border-primary bg-primary/12"
|
|
950
|
+
:style="{
|
|
951
|
+
left: `${xOf(draft.start)}px`,
|
|
952
|
+
width: `${xOf(draft.end) - xOf(draft.start)}px`,
|
|
953
|
+
top: `${rowOf.get(draft.resourceId)!.top + 4}px`,
|
|
954
|
+
height: `${rowOf.get(draft.resourceId)!.height - 8}px`,
|
|
955
|
+
}"
|
|
956
|
+
/>
|
|
957
|
+
<div
|
|
958
|
+
v-for="{ event: ev } in visibleEvents"
|
|
959
|
+
:key="ev.id"
|
|
960
|
+
:ref="(el) => bindBlock(ev.id, el)"
|
|
961
|
+
class="absolute top-0 left-0"
|
|
962
|
+
:class="[ev.class, dragging?.id === ev.id ? 'z-10' : '']"
|
|
963
|
+
:style="{ height: `${blockH}px` }"
|
|
964
|
+
>
|
|
965
|
+
<div
|
|
966
|
+
data-timeline-event
|
|
967
|
+
role="button"
|
|
968
|
+
tabindex="0"
|
|
969
|
+
:aria-label="`${ev.title}, ${resourceById.get(ev.resourceId)?.name ?? ''}, ${timeRange(ev)}`"
|
|
970
|
+
:aria-pressed="selectedSet.has(ev.id)"
|
|
971
|
+
class="group absolute inset-0 flex items-stretch overflow-hidden rounded-sm text-left outline-none select-none focus-visible:ring-2 focus-visible:ring-secondary focus-visible:ring-offset-1"
|
|
972
|
+
:class="[
|
|
973
|
+
TONES[toneOf(ev)],
|
|
974
|
+
selectedSet.has(ev.id) ? 'ring-2 ring-on-surface ring-offset-1 ring-offset-surface' : '',
|
|
975
|
+
conflicts.has(ev.id) || (dragging?.id === ev.id && refused) ? 'outline-2 outline-offset-1 outline-error' : '',
|
|
976
|
+
dragging?.id === ev.id ? 'shadow-elevation-3' : 'hover:shadow-elevation-1',
|
|
977
|
+
readonly || ev.draggable === false ? '' : 'cursor-grab active:cursor-grabbing',
|
|
978
|
+
]"
|
|
979
|
+
@pointerdown="onEventDown($event, ev, 'body')"
|
|
980
|
+
@dblclick="emit('event-dblclick', ev, $event)"
|
|
981
|
+
@contextmenu="emit('event-contextmenu', ev, $event)"
|
|
982
|
+
@keydown="onEventKey($event, ev)"
|
|
983
|
+
>
|
|
984
|
+
<span class="w-1 shrink-0" :class="ACCENT[toneOf(ev)]" />
|
|
985
|
+
<span class="flex min-w-0 flex-1 items-center gap-1 px-2">
|
|
986
|
+
<slot name="event" :event="ev" :resource="resourceById.get(ev.resourceId)" :selected="selectedSet.has(ev.id)" :conflict="conflicts.has(ev.id)">
|
|
987
|
+
<span class="min-w-0 flex-1 leading-tight">
|
|
988
|
+
<span class="block truncate text-label-large">{{ ev.title }}</span>
|
|
989
|
+
<span v-if="blockH >= 30" class="block truncate text-label-small opacity-80">{{ ev.subtitle ?? timeRange(ev) }}</span>
|
|
990
|
+
</span>
|
|
991
|
+
<span v-if="conflicts.has(ev.id) && (geometry.get(ev.id)?.w ?? 0) > 72" class="material-symbols-outlined shrink-0 text-[18px] text-error" :title="locale.timelineConflict">warning</span>
|
|
992
|
+
</slot>
|
|
993
|
+
</span>
|
|
994
|
+
</div>
|
|
995
|
+
<!-- Resize handles, outside the block's clipping: wider for a finger, with a grip while selected -->
|
|
996
|
+
<template v-if="!readonly && ev.resizable !== false">
|
|
997
|
+
<span
|
|
998
|
+
v-for="side in (['start', 'end'] as const)"
|
|
999
|
+
:key="side"
|
|
1000
|
+
:data-timeline-resize="side"
|
|
1001
|
+
class="absolute inset-y-0 z-[1] flex w-3 cursor-ew-resize items-center justify-center pointer-coarse:w-7"
|
|
1002
|
+
:class="side === 'start' ? '-left-1 pointer-coarse:-left-3.5' : '-right-1 pointer-coarse:-right-3.5'"
|
|
1003
|
+
@pointerdown="onEventDown($event, ev, side)"
|
|
1004
|
+
>
|
|
1005
|
+
<span class="hidden h-3/5 w-1 rounded-full bg-on-surface pointer-coarse:block" :class="selectedSet.has(ev.id) ? 'opacity-100' : 'opacity-0'" />
|
|
1006
|
+
</span>
|
|
1007
|
+
</template>
|
|
1008
|
+
</div>
|
|
1009
|
+
<div v-if="!resources.length" class="absolute flex items-center justify-center p-6" :style="{ left: `${view.left}px`, width: `${timelineView}px`, top: 0, height: `${Math.max(120, view.height - headerHeight)}px` }">
|
|
1010
|
+
<slot name="empty">
|
|
1011
|
+
<span class="text-body-medium text-on-surface-variant">{{ locale.timelineEmpty }}</span>
|
|
1012
|
+
</slot>
|
|
1013
|
+
</div>
|
|
1014
|
+
</div>
|
|
1015
|
+
</div>
|
|
1016
|
+
</div>
|
|
1017
|
+
</div>
|
|
1018
|
+
<div class="sr-only" aria-live="polite">{{ message }}</div>
|
|
1019
|
+
</div>
|
|
1020
|
+
</template>
|