awesome-timeline-react 0.1.14 → 0.2.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/LICENSE +21 -21
- package/README.md +184 -96
- package/dist/_tsup-dts-rollup.d.mts +738 -329
- package/dist/_tsup-dts-rollup.d.ts +738 -329
- package/dist/index.css +44 -125
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +1775 -1643
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1792 -1662
- package/dist/index.mjs.map +1 -1
- package/package.json +66 -62
- package/dist/src/index.d.mts +0 -1
- package/dist/src/index.d.ts +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -14,16 +16,248 @@ var __spreadValues = (a, b) => {
|
|
|
14
16
|
}
|
|
15
17
|
return a;
|
|
16
18
|
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
17
20
|
|
|
18
21
|
// src/timeline.tsx
|
|
19
|
-
import
|
|
22
|
+
import React6, {
|
|
23
|
+
forwardRef as forwardRef3,
|
|
24
|
+
useEffect as useEffect6,
|
|
25
|
+
useImperativeHandle as useImperativeHandle2,
|
|
26
|
+
useMemo as useMemo4,
|
|
27
|
+
useRef as useRef7,
|
|
28
|
+
useState as useState4
|
|
29
|
+
} from "react";
|
|
30
|
+
|
|
31
|
+
// src/canvas/animator.ts
|
|
32
|
+
var DEFAULT_LAYOUT_DURATION_MS = 200;
|
|
33
|
+
var DEFAULT_FADE_DURATION_MS = 120;
|
|
34
|
+
var ease = (t) => t * t * (3 - 2 * t);
|
|
35
|
+
var LayoutAnimator = class {
|
|
36
|
+
constructor() {
|
|
37
|
+
this.rowHeights = /* @__PURE__ */ new Map();
|
|
38
|
+
this.eventTops = /* @__PURE__ */ new Map();
|
|
39
|
+
this.handleAlphas = /* @__PURE__ */ new Map();
|
|
40
|
+
this.now = 0;
|
|
41
|
+
this.activeUntil = 0;
|
|
42
|
+
this.layoutDuration = DEFAULT_LAYOUT_DURATION_MS;
|
|
43
|
+
this.fadeDuration = DEFAULT_FADE_DURATION_MS;
|
|
44
|
+
}
|
|
45
|
+
setDurations(layoutMs, fadeMs) {
|
|
46
|
+
this.layoutDuration = layoutMs;
|
|
47
|
+
this.fadeDuration = fadeMs;
|
|
48
|
+
}
|
|
49
|
+
beginFrame(now) {
|
|
50
|
+
this.now = now;
|
|
51
|
+
}
|
|
52
|
+
rowHeight(rowId, target) {
|
|
53
|
+
return this.value(this.rowHeights, rowId, target, this.layoutDuration);
|
|
54
|
+
}
|
|
55
|
+
eventTop(eventId, target) {
|
|
56
|
+
return this.value(this.eventTops, eventId, target, this.layoutDuration);
|
|
57
|
+
}
|
|
58
|
+
/** 0..1 opacity of an event's resize handles; target 1 = hovered. */
|
|
59
|
+
handleAlpha(eventId, target) {
|
|
60
|
+
return this.value(this.handleAlphas, eventId, target, this.fadeDuration);
|
|
61
|
+
}
|
|
62
|
+
isAnimating() {
|
|
63
|
+
return this.now < this.activeUntil;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Drop an event's top tween so its next draw renders at the target
|
|
67
|
+
* instantly — used on drag-drop commit, where the ghost already previewed
|
|
68
|
+
* the final position and a tween would feel like a rubber-band.
|
|
69
|
+
*/
|
|
70
|
+
snapEventTop(eventId) {
|
|
71
|
+
this.eventTops.delete(eventId);
|
|
72
|
+
}
|
|
73
|
+
/** Drop all state, e.g. when the scene is reset wholesale. */
|
|
74
|
+
reset() {
|
|
75
|
+
this.rowHeights.clear();
|
|
76
|
+
this.eventTops.clear();
|
|
77
|
+
this.handleAlphas.clear();
|
|
78
|
+
this.activeUntil = 0;
|
|
79
|
+
}
|
|
80
|
+
value(map, key, target, duration) {
|
|
81
|
+
let tween = map.get(key);
|
|
82
|
+
if (!tween) {
|
|
83
|
+
tween = { from: target, to: target, start: 0, duration };
|
|
84
|
+
map.set(key, tween);
|
|
85
|
+
return target;
|
|
86
|
+
}
|
|
87
|
+
if (tween.to !== target) {
|
|
88
|
+
if (duration <= 0) {
|
|
89
|
+
tween.from = target;
|
|
90
|
+
tween.to = target;
|
|
91
|
+
return target;
|
|
92
|
+
}
|
|
93
|
+
const current = this.current(tween);
|
|
94
|
+
tween.from = current;
|
|
95
|
+
tween.to = target;
|
|
96
|
+
tween.start = this.now;
|
|
97
|
+
tween.duration = duration;
|
|
98
|
+
this.activeUntil = Math.max(this.activeUntil, this.now + duration);
|
|
99
|
+
}
|
|
100
|
+
return this.current(tween);
|
|
101
|
+
}
|
|
102
|
+
current(tween) {
|
|
103
|
+
if (tween.from === tween.to || tween.duration <= 0) return tween.to;
|
|
104
|
+
const t = Math.min(1, (this.now - tween.start) / tween.duration);
|
|
105
|
+
return tween.from + (tween.to - tween.from) * ease(t);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/hooks/use-resize-observer.ts
|
|
110
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
111
|
+
var useResizeObserver = ({
|
|
112
|
+
windowTime,
|
|
113
|
+
setTick,
|
|
114
|
+
setCellWidth,
|
|
115
|
+
contentRef
|
|
116
|
+
}) => {
|
|
117
|
+
const prevWidthRef = useRef(0);
|
|
118
|
+
const resizeObserver = useMemo(() => {
|
|
119
|
+
return new ResizeObserver((entries) => {
|
|
120
|
+
var _a;
|
|
121
|
+
for (const entry of entries) {
|
|
122
|
+
const width = (_a = entry.borderBoxSize) == null ? void 0 : _a[0].inlineSize;
|
|
123
|
+
if (typeof width === "number" && width !== prevWidthRef.current) {
|
|
124
|
+
prevWidthRef.current = width;
|
|
125
|
+
const windowDuration = windowTime[1] - windowTime[0];
|
|
126
|
+
const numberOfHourBlocks = windowDuration / 3600;
|
|
127
|
+
setTick(windowDuration / entry.contentRect.width);
|
|
128
|
+
setCellWidth(entry.contentRect.width / numberOfHourBlocks);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}, [windowTime]);
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
if (contentRef.current) {
|
|
135
|
+
resizeObserver.observe(contentRef.current, { box: "border-box" });
|
|
136
|
+
}
|
|
137
|
+
return () => resizeObserver.disconnect();
|
|
138
|
+
}, [resizeObserver]);
|
|
139
|
+
};
|
|
140
|
+
var use_resize_observer_default = useResizeObserver;
|
|
141
|
+
|
|
142
|
+
// src/helpers/sort-events.ts
|
|
143
|
+
var sortEvents = (eventA, eventB) => {
|
|
144
|
+
if (eventA.startTime - eventB.startTime < 0) return -1;
|
|
145
|
+
if (eventA.startTime === eventB.startTime) {
|
|
146
|
+
if (eventA.endTime < eventB.endTime) {
|
|
147
|
+
return -1;
|
|
148
|
+
} else {
|
|
149
|
+
return 1;
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
return 1;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var sort_events_default = sortEvents;
|
|
156
|
+
|
|
157
|
+
// src/components/rt-indicator.tsx
|
|
158
|
+
import React, { useEffect as useEffect2, useRef as useRef2, useState } from "react";
|
|
159
|
+
var RTIndicator = ({
|
|
160
|
+
tick,
|
|
161
|
+
windowTime
|
|
162
|
+
}) => {
|
|
163
|
+
const [currentTime, setCurrentTime] = useState((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
164
|
+
const [leftOffset, setLeftOffset] = useState(0);
|
|
165
|
+
const intervalIdRef = useRef2(null);
|
|
166
|
+
useEffect2(() => {
|
|
167
|
+
if (tick) {
|
|
168
|
+
const leftOffsetTime = currentTime - windowTime[0];
|
|
169
|
+
setLeftOffset(Math.round(leftOffsetTime / tick));
|
|
170
|
+
if (intervalIdRef.current !== null) {
|
|
171
|
+
clearInterval(intervalIdRef.current);
|
|
172
|
+
}
|
|
173
|
+
const intervalId = setInterval(() => {
|
|
174
|
+
setCurrentTime((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
175
|
+
}, tick * 1e3);
|
|
176
|
+
intervalIdRef.current = intervalId;
|
|
177
|
+
}
|
|
178
|
+
}, [tick, windowTime, currentTime]);
|
|
179
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, windowTime[0] <= currentTime && currentTime <= windowTime[1] && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "rt-arrow", style: { left: 86 + leftOffset } }), /* @__PURE__ */ React.createElement("div", { className: "rt-line", style: { left: 100 + leftOffset } })));
|
|
180
|
+
};
|
|
181
|
+
var rt_indicator_default = RTIndicator;
|
|
182
|
+
|
|
183
|
+
// src/components/event-prompt.tsx
|
|
184
|
+
import React2, {
|
|
185
|
+
forwardRef,
|
|
186
|
+
useImperativeHandle,
|
|
187
|
+
useRef as useRef3,
|
|
188
|
+
useState as useState2
|
|
189
|
+
} from "react";
|
|
190
|
+
import { computePosition, flip, offset, shift } from "@floating-ui/dom";
|
|
191
|
+
var EventPrompt = forwardRef(
|
|
192
|
+
({ template }, ref) => {
|
|
193
|
+
const promptRef = useRef3(null);
|
|
194
|
+
const [hoveredEvent, setHoveredEvent] = useState2();
|
|
195
|
+
const showSeqRef = useRef3(0);
|
|
196
|
+
useImperativeHandle(ref, () => {
|
|
197
|
+
return {
|
|
198
|
+
show(event, anchorRect) {
|
|
199
|
+
const prompt = promptRef.current;
|
|
200
|
+
if (!prompt) return;
|
|
201
|
+
setHoveredEvent(event);
|
|
202
|
+
const seq = ++showSeqRef.current;
|
|
203
|
+
const virtualAnchor = {
|
|
204
|
+
getBoundingClientRect: () => ({
|
|
205
|
+
x: anchorRect.x,
|
|
206
|
+
y: anchorRect.y,
|
|
207
|
+
width: anchorRect.width,
|
|
208
|
+
height: anchorRect.height,
|
|
209
|
+
top: anchorRect.y,
|
|
210
|
+
left: anchorRect.x,
|
|
211
|
+
right: anchorRect.x + anchorRect.width,
|
|
212
|
+
bottom: anchorRect.y + anchorRect.height
|
|
213
|
+
})
|
|
214
|
+
};
|
|
215
|
+
prompt.style.display = "block";
|
|
216
|
+
prompt.style.visibility = "hidden";
|
|
217
|
+
computePosition(virtualAnchor, prompt, {
|
|
218
|
+
placement: "top",
|
|
219
|
+
middleware: [
|
|
220
|
+
offset(8),
|
|
221
|
+
flip({ padding: 8 }),
|
|
222
|
+
shift({ padding: 8 })
|
|
223
|
+
]
|
|
224
|
+
}).then(({ x, y }) => {
|
|
225
|
+
if (seq !== showSeqRef.current || !promptRef.current) return;
|
|
226
|
+
promptRef.current.style.left = `${x}px`;
|
|
227
|
+
promptRef.current.style.top = `${y}px`;
|
|
228
|
+
promptRef.current.style.visibility = "visible";
|
|
229
|
+
});
|
|
230
|
+
},
|
|
231
|
+
hide() {
|
|
232
|
+
showSeqRef.current++;
|
|
233
|
+
if (promptRef.current) {
|
|
234
|
+
promptRef.current.style.display = "none";
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
return /* @__PURE__ */ React2.createElement("div", { className: "event-prompt", ref: promptRef }, template && hoveredEvent && template(hoveredEvent));
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
var event_prompt_default = EventPrompt;
|
|
20
243
|
|
|
21
|
-
// src/components/time-bar.tsx
|
|
22
|
-
import
|
|
244
|
+
// src/components/canvas-time-bar.tsx
|
|
245
|
+
import React3, { useEffect as useEffect3, useRef as useRef4 } from "react";
|
|
23
246
|
|
|
24
|
-
// src/hooks/use-
|
|
25
|
-
import
|
|
26
|
-
|
|
247
|
+
// src/hooks/use-get-block-properties.ts
|
|
248
|
+
import { useMemo as useMemo2 } from "react";
|
|
249
|
+
var useGetBlockProperties = ({
|
|
250
|
+
windowTime,
|
|
251
|
+
contentWidth
|
|
252
|
+
}) => {
|
|
253
|
+
const numberOfHourBlocks = useMemo2(
|
|
254
|
+
() => (windowTime[1] - windowTime[0]) / 3600,
|
|
255
|
+
[windowTime]
|
|
256
|
+
);
|
|
257
|
+
const blockWidth = contentWidth ? contentWidth / numberOfHourBlocks : 0;
|
|
258
|
+
return { numberOfHourBlocks, blockWidth };
|
|
259
|
+
};
|
|
260
|
+
var use_get_block_properties_default = useGetBlockProperties;
|
|
27
261
|
|
|
28
262
|
// src/helpers/get-month-name.ts
|
|
29
263
|
var getMonthName = (monthIndex) => {
|
|
@@ -104,173 +338,243 @@ var getWeekDayName = (dayIndex) => {
|
|
|
104
338
|
};
|
|
105
339
|
var get_week_day_name_default = getWeekDayName;
|
|
106
340
|
|
|
107
|
-
// src/
|
|
108
|
-
var
|
|
109
|
-
|
|
341
|
+
// src/core/time-blocks.ts
|
|
342
|
+
var hourLabel = (hour) => hour < 10 ? `0${hour}:00` : `${hour}:00`;
|
|
343
|
+
var dayLabel = (date) => `${get_week_day_name_default(date.getDay())} ${date.getDate()} ${get_month_name_default(
|
|
344
|
+
date.getMonth()
|
|
345
|
+
)}`;
|
|
346
|
+
var generateTimeBlocks = ({
|
|
347
|
+
windowStart,
|
|
110
348
|
tick,
|
|
111
349
|
contentWidth,
|
|
112
350
|
blockWidth
|
|
113
351
|
}) => {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
className: "hour-block",
|
|
144
|
-
key: `${datePoint.getDate()}_hour_${i}`
|
|
145
|
-
},
|
|
146
|
-
i < 10 ? `0${i}:00` : `${i}:00`
|
|
147
|
-
)
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
dayBlocks2.push(
|
|
151
|
-
/* @__PURE__ */ React.createElement(
|
|
152
|
-
"div",
|
|
153
|
-
{
|
|
154
|
-
className: "day-block",
|
|
155
|
-
key: `${datePoint.getDate()} ${datePoint.getMonth()}`,
|
|
156
|
-
style: {
|
|
157
|
-
gridColumn: `${prevNumBlocks} / ${prevNumBlocks + numBlocks2}`
|
|
158
|
-
// width: dateWidth + widthLeft,
|
|
159
|
-
// minWidth: dateWidth + widthLeft,
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
get_week_day_name_default(datePoint.getDay()),
|
|
163
|
-
" ",
|
|
164
|
-
datePoint.getDate(),
|
|
165
|
-
" ",
|
|
166
|
-
get_month_name_default(datePoint.getMonth())
|
|
167
|
-
)
|
|
168
|
-
);
|
|
169
|
-
prevNumBlocks += numBlocks2;
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
const numBlocks = Math.round(dateWidth / blockWidth);
|
|
173
|
-
for (let i = 24 - numBlocks; i < 24; i++) {
|
|
174
|
-
hourBlocks2.push(
|
|
175
|
-
/* @__PURE__ */ React.createElement("div", { className: "hour-block", key: `${datePoint.getDate()}_hour_${i}` }, i < 10 ? `0${i}:00` : `${i}:00`)
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
dayBlocks2.push(
|
|
179
|
-
/* @__PURE__ */ React.createElement(
|
|
180
|
-
"div",
|
|
181
|
-
{
|
|
182
|
-
className: "day-block",
|
|
183
|
-
key: `${datePoint.getDate()} ${datePoint.getMonth()}`,
|
|
184
|
-
style: {
|
|
185
|
-
gridColumn: `${prevNumBlocks} / ${prevNumBlocks + numBlocks}`
|
|
186
|
-
// width: dateWidth,
|
|
187
|
-
// minWidth: dateWidth,
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
get_week_day_name_default(datePoint.getDay()),
|
|
191
|
-
" ",
|
|
192
|
-
datePoint.getDate(),
|
|
193
|
-
" ",
|
|
194
|
-
get_month_name_default(datePoint.getMonth())
|
|
195
|
-
)
|
|
196
|
-
);
|
|
197
|
-
prevNumBlocks += numBlocks;
|
|
198
|
-
if (Math.round(widthLeft) === 0) {
|
|
199
|
-
break;
|
|
352
|
+
const dayBlocks = [];
|
|
353
|
+
const hourBlocks = [];
|
|
354
|
+
if (tick === null || contentWidth === null || blockWidth <= 0) {
|
|
355
|
+
return { dayBlocks, hourBlocks };
|
|
356
|
+
}
|
|
357
|
+
let timePoint = windowStart;
|
|
358
|
+
let widthLeft = contentWidth;
|
|
359
|
+
let prevNumBlocks = 1;
|
|
360
|
+
while (1) {
|
|
361
|
+
const datePoint = new Date(timePoint * 1e3);
|
|
362
|
+
const endDatePoint = new Date(
|
|
363
|
+
datePoint.getFullYear(),
|
|
364
|
+
datePoint.getMonth(),
|
|
365
|
+
datePoint.getDate(),
|
|
366
|
+
23,
|
|
367
|
+
59,
|
|
368
|
+
59
|
|
369
|
+
);
|
|
370
|
+
const dateDuration = endDatePoint.getTime() - datePoint.getTime();
|
|
371
|
+
const dateWidth = dateDuration / 1e3 / tick;
|
|
372
|
+
widthLeft -= dateWidth;
|
|
373
|
+
if (Math.round(widthLeft) < 0) {
|
|
374
|
+
const numBlocks2 = Math.round((dateWidth + widthLeft) / blockWidth);
|
|
375
|
+
for (let i = 0; i < numBlocks2; i++) {
|
|
376
|
+
hourBlocks.push({
|
|
377
|
+
label: hourLabel(i),
|
|
378
|
+
x: hourBlocks.length * blockWidth,
|
|
379
|
+
width: blockWidth
|
|
380
|
+
});
|
|
200
381
|
}
|
|
201
|
-
|
|
382
|
+
dayBlocks.push({
|
|
383
|
+
label: dayLabel(datePoint),
|
|
384
|
+
x: (prevNumBlocks - 1) * blockWidth,
|
|
385
|
+
width: numBlocks2 * blockWidth
|
|
386
|
+
});
|
|
387
|
+
prevNumBlocks += numBlocks2;
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
const numBlocks = Math.round(dateWidth / blockWidth);
|
|
391
|
+
for (let i = 24 - numBlocks; i < 24; i++) {
|
|
392
|
+
hourBlocks.push({
|
|
393
|
+
label: hourLabel(i),
|
|
394
|
+
x: hourBlocks.length * blockWidth,
|
|
395
|
+
width: blockWidth
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
dayBlocks.push({
|
|
399
|
+
label: dayLabel(datePoint),
|
|
400
|
+
x: (prevNumBlocks - 1) * blockWidth,
|
|
401
|
+
width: numBlocks * blockWidth
|
|
402
|
+
});
|
|
403
|
+
prevNumBlocks += numBlocks;
|
|
404
|
+
if (Math.round(widthLeft) === 0) {
|
|
405
|
+
break;
|
|
202
406
|
}
|
|
203
|
-
|
|
204
|
-
}
|
|
407
|
+
timePoint = (endDatePoint.getTime() + 1e3) / 1e3;
|
|
408
|
+
}
|
|
205
409
|
return { dayBlocks, hourBlocks };
|
|
206
410
|
};
|
|
207
|
-
var use_generate_blocks_default = useGenerateBlocks;
|
|
208
411
|
|
|
209
|
-
// src/
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
412
|
+
// src/canvas/dpr.ts
|
|
413
|
+
var sizeCanvas = (canvas, cssWidth, cssHeight, dpr) => {
|
|
414
|
+
canvas.width = Math.max(1, Math.round(cssWidth * dpr));
|
|
415
|
+
canvas.height = Math.max(1, Math.round(cssHeight * dpr));
|
|
416
|
+
canvas.style.width = `${cssWidth}px`;
|
|
417
|
+
canvas.style.height = `${cssHeight}px`;
|
|
418
|
+
const ctx = canvas.getContext("2d");
|
|
419
|
+
if (ctx) {
|
|
420
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
421
|
+
}
|
|
422
|
+
return ctx;
|
|
423
|
+
};
|
|
424
|
+
var watchDpr = (onChange) => {
|
|
425
|
+
let disposed = false;
|
|
426
|
+
let cleanup = () => {
|
|
427
|
+
};
|
|
428
|
+
const listen = () => {
|
|
429
|
+
if (disposed) return;
|
|
430
|
+
const media = window.matchMedia(
|
|
431
|
+
`(resolution: ${window.devicePixelRatio}dppx)`
|
|
432
|
+
);
|
|
433
|
+
const handler = () => {
|
|
434
|
+
onChange(window.devicePixelRatio);
|
|
435
|
+
media.removeEventListener("change", handler);
|
|
436
|
+
listen();
|
|
437
|
+
};
|
|
438
|
+
media.addEventListener("change", handler);
|
|
439
|
+
cleanup = () => media.removeEventListener("change", handler);
|
|
440
|
+
};
|
|
441
|
+
listen();
|
|
442
|
+
return () => {
|
|
443
|
+
disposed = true;
|
|
444
|
+
cleanup();
|
|
445
|
+
};
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
// src/canvas/theme.ts
|
|
449
|
+
var DEFAULT_THEME = {
|
|
450
|
+
eventFill: "#ffffff",
|
|
451
|
+
eventStroke: "#000000",
|
|
452
|
+
eventTextColor: "#000000",
|
|
453
|
+
staticEventFill: "#e0e0e0",
|
|
454
|
+
gridColor: "#e4dcdc",
|
|
455
|
+
timeBarBorder: "yellow",
|
|
456
|
+
timeBarTextColor: "white",
|
|
457
|
+
font: void 0
|
|
458
|
+
};
|
|
459
|
+
var resolveTheme = (theme) => __spreadValues(__spreadValues({}, DEFAULT_THEME), theme);
|
|
460
|
+
|
|
461
|
+
// src/canvas/draw-grid.ts
|
|
462
|
+
var drawGridLines = (ctx, {
|
|
463
|
+
width,
|
|
464
|
+
height,
|
|
465
|
+
cellWidth,
|
|
466
|
+
color = DEFAULT_THEME.gridColor
|
|
214
467
|
}) => {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
|
|
468
|
+
if (cellWidth <= 0) return;
|
|
469
|
+
ctx.strokeStyle = color;
|
|
470
|
+
ctx.lineWidth = 1;
|
|
471
|
+
ctx.beginPath();
|
|
472
|
+
for (let x = cellWidth; x < width; x += cellWidth) {
|
|
473
|
+
if (width - x < 1) break;
|
|
474
|
+
const crisp = Math.round(x) - 0.5;
|
|
475
|
+
ctx.moveTo(crisp, 0);
|
|
476
|
+
ctx.lineTo(crisp, height);
|
|
477
|
+
}
|
|
478
|
+
ctx.stroke();
|
|
479
|
+
};
|
|
480
|
+
var drawTimeBar = (ctx, {
|
|
481
|
+
width,
|
|
482
|
+
height,
|
|
483
|
+
dayBlocks,
|
|
484
|
+
hourBlocks,
|
|
485
|
+
font,
|
|
486
|
+
borderColor = DEFAULT_THEME.timeBarBorder,
|
|
487
|
+
textColor = DEFAULT_THEME.timeBarTextColor
|
|
488
|
+
}) => {
|
|
489
|
+
const mid = height / 2;
|
|
490
|
+
ctx.strokeStyle = borderColor;
|
|
491
|
+
ctx.lineWidth = 1;
|
|
492
|
+
ctx.beginPath();
|
|
493
|
+
ctx.moveTo(0, Math.round(mid) - 0.5);
|
|
494
|
+
ctx.lineTo(width, Math.round(mid) - 0.5);
|
|
495
|
+
ctx.stroke();
|
|
496
|
+
ctx.beginPath();
|
|
497
|
+
for (let i = 0; i < dayBlocks.length - 1; i++) {
|
|
498
|
+
const edge = Math.round(dayBlocks[i].x + dayBlocks[i].width) - 0.5;
|
|
499
|
+
ctx.moveTo(edge, 0);
|
|
500
|
+
ctx.lineTo(edge, mid);
|
|
501
|
+
}
|
|
502
|
+
for (let i = 0; i < hourBlocks.length - 1; i++) {
|
|
503
|
+
const edge = Math.round(hourBlocks[i].x + hourBlocks[i].width) - 0.5;
|
|
504
|
+
ctx.moveTo(edge, mid);
|
|
505
|
+
ctx.lineTo(edge, height);
|
|
506
|
+
}
|
|
507
|
+
ctx.stroke();
|
|
508
|
+
ctx.fillStyle = textColor;
|
|
509
|
+
ctx.font = font;
|
|
510
|
+
ctx.textBaseline = "middle";
|
|
511
|
+
ctx.textAlign = "center";
|
|
512
|
+
const inset = 4;
|
|
513
|
+
for (const block of dayBlocks) {
|
|
514
|
+
ctx.fillText(
|
|
515
|
+
block.label,
|
|
516
|
+
block.x + block.width / 2,
|
|
517
|
+
mid / 2,
|
|
518
|
+
block.width - inset
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
for (const block of hourBlocks) {
|
|
522
|
+
ctx.fillText(
|
|
523
|
+
block.label,
|
|
524
|
+
block.x + block.width / 2,
|
|
525
|
+
mid + mid / 2,
|
|
526
|
+
block.width - inset
|
|
527
|
+
);
|
|
528
|
+
}
|
|
221
529
|
};
|
|
222
|
-
var use_get_block_properties_default = useGetBlockProperties;
|
|
223
530
|
|
|
224
|
-
// src/components/time-bar.tsx
|
|
225
|
-
var
|
|
531
|
+
// src/components/canvas-time-bar.tsx
|
|
532
|
+
var TIME_BAR_INNER_HEIGHT = 48;
|
|
533
|
+
var CanvasTimeBar = ({
|
|
226
534
|
windowTime,
|
|
227
535
|
tick,
|
|
228
536
|
contentWidth,
|
|
229
537
|
scrollWidth,
|
|
230
|
-
|
|
538
|
+
theme
|
|
231
539
|
}) => {
|
|
232
|
-
const
|
|
540
|
+
const canvasRef = useRef4(null);
|
|
233
541
|
const { blockWidth } = use_get_block_properties_default({
|
|
234
542
|
windowTime,
|
|
235
543
|
contentWidth
|
|
236
544
|
});
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
contentWidth
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
545
|
+
useEffect3(() => {
|
|
546
|
+
var _a;
|
|
547
|
+
const canvas = canvasRef.current;
|
|
548
|
+
if (!canvas || !contentWidth) return;
|
|
549
|
+
const ctx = sizeCanvas(
|
|
550
|
+
canvas,
|
|
551
|
+
contentWidth,
|
|
552
|
+
TIME_BAR_INNER_HEIGHT,
|
|
553
|
+
window.devicePixelRatio
|
|
554
|
+
);
|
|
555
|
+
if (ctx) {
|
|
556
|
+
drawTimeBar(ctx, __spreadValues({
|
|
557
|
+
width: contentWidth,
|
|
558
|
+
height: TIME_BAR_INNER_HEIGHT,
|
|
559
|
+
font: (_a = theme == null ? void 0 : theme.font) != null ? _a : getComputedStyle(canvas).font,
|
|
560
|
+
borderColor: theme == null ? void 0 : theme.timeBarBorder,
|
|
561
|
+
textColor: theme == null ? void 0 : theme.timeBarTextColor
|
|
562
|
+
}, generateTimeBlocks({
|
|
563
|
+
windowStart: windowTime[0],
|
|
564
|
+
tick,
|
|
565
|
+
contentWidth,
|
|
566
|
+
blockWidth
|
|
567
|
+
})));
|
|
568
|
+
}
|
|
569
|
+
}, [windowTime, tick, contentWidth, blockWidth, theme]);
|
|
570
|
+
return /* @__PURE__ */ React3.createElement("div", { className: "time-bar" }, /* @__PURE__ */ React3.createElement("div", { className: "empty-block" }), /* @__PURE__ */ React3.createElement(
|
|
571
|
+
"canvas",
|
|
248
572
|
{
|
|
249
|
-
|
|
250
|
-
|
|
573
|
+
ref: canvasRef,
|
|
574
|
+
className: "canvas-time-bar",
|
|
251
575
|
style: { minWidth: contentWidth ? contentWidth : 0 }
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
"div",
|
|
255
|
-
{
|
|
256
|
-
className: dayRowClassNames,
|
|
257
|
-
style: {
|
|
258
|
-
gridTemplateColumns: `repeat(auto-fill, minmax(${blockWidth}px, 1fr))`
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
dayBlocks.map((block) => block)
|
|
262
|
-
),
|
|
263
|
-
/* @__PURE__ */ React2.createElement(
|
|
264
|
-
"div",
|
|
265
|
-
{
|
|
266
|
-
className: hourRowClassNames,
|
|
267
|
-
style: {
|
|
268
|
-
gridTemplateColumns: `repeat(auto-fill, minmax(${blockWidth}px, 1fr))`
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
hourBlocks.map((block) => block)
|
|
272
|
-
)
|
|
273
|
-
), scrollWidth ? /* @__PURE__ */ React2.createElement(
|
|
576
|
+
}
|
|
577
|
+
), scrollWidth ? /* @__PURE__ */ React3.createElement(
|
|
274
578
|
"div",
|
|
275
579
|
{
|
|
276
580
|
style: {
|
|
@@ -282,1629 +586,1455 @@ var TimeBar = ({
|
|
|
282
586
|
}
|
|
283
587
|
) : null);
|
|
284
588
|
};
|
|
285
|
-
var
|
|
589
|
+
var canvas_time_bar_default = CanvasTimeBar;
|
|
286
590
|
|
|
287
|
-
// src/components/
|
|
288
|
-
import
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
null
|
|
297
|
-
);
|
|
591
|
+
// src/components/canvas-board.tsx
|
|
592
|
+
import React5, {
|
|
593
|
+
forwardRef as forwardRef2,
|
|
594
|
+
useCallback as useCallback2,
|
|
595
|
+
useEffect as useEffect5,
|
|
596
|
+
useRef as useRef6,
|
|
597
|
+
useState as useState3,
|
|
598
|
+
useSyncExternalStore
|
|
599
|
+
} from "react";
|
|
298
600
|
|
|
299
|
-
// src/
|
|
300
|
-
var
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
601
|
+
// src/canvas/frame-scheduler.ts
|
|
602
|
+
var FrameScheduler = class {
|
|
603
|
+
constructor(onFrame) {
|
|
604
|
+
this.onFrame = onFrame;
|
|
605
|
+
this.rafId = null;
|
|
606
|
+
this.dirty = { static: false, dynamic: false };
|
|
607
|
+
}
|
|
608
|
+
invalidate(layer) {
|
|
609
|
+
if (layer === "all" || layer === "static") this.dirty.static = true;
|
|
610
|
+
if (layer === "all" || layer === "dynamic") this.dirty.dynamic = true;
|
|
611
|
+
this.schedule();
|
|
612
|
+
}
|
|
613
|
+
/** Runs a pending frame immediately (tests, synchronous reads). */
|
|
614
|
+
flush() {
|
|
615
|
+
if (this.rafId !== null) {
|
|
616
|
+
cancelAnimationFrame(this.rafId);
|
|
617
|
+
this.rafId = null;
|
|
618
|
+
this.run();
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
dispose() {
|
|
622
|
+
if (this.rafId !== null) {
|
|
623
|
+
cancelAnimationFrame(this.rafId);
|
|
624
|
+
this.rafId = null;
|
|
625
|
+
}
|
|
626
|
+
this.dirty = { static: false, dynamic: false };
|
|
627
|
+
}
|
|
628
|
+
schedule() {
|
|
629
|
+
if (this.rafId !== null) return;
|
|
630
|
+
this.rafId = requestAnimationFrame(() => {
|
|
631
|
+
this.rafId = null;
|
|
632
|
+
this.run();
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
run() {
|
|
636
|
+
const dirty = this.dirty;
|
|
637
|
+
this.dirty = { static: false, dynamic: false };
|
|
638
|
+
if (dirty.static || dirty.dynamic) this.onFrame(dirty);
|
|
639
|
+
}
|
|
304
640
|
};
|
|
305
|
-
var row_header_default = RowHeader;
|
|
306
641
|
|
|
307
|
-
// src/
|
|
308
|
-
var
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
{
|
|
316
|
-
|
|
317
|
-
id: row.id,
|
|
318
|
-
name: row.name
|
|
642
|
+
// src/core/culling.ts
|
|
643
|
+
var cullToWindow = (events, windowStart, windowEnd) => {
|
|
644
|
+
let lo = 0;
|
|
645
|
+
let hi = events.length;
|
|
646
|
+
while (lo < hi) {
|
|
647
|
+
const mid = lo + hi >> 1;
|
|
648
|
+
if (events[mid].startTime <= windowEnd) {
|
|
649
|
+
lo = mid + 1;
|
|
650
|
+
} else {
|
|
651
|
+
hi = mid;
|
|
319
652
|
}
|
|
320
|
-
|
|
653
|
+
}
|
|
654
|
+
const visible = [];
|
|
655
|
+
for (let i = 0; i < lo; i++) {
|
|
656
|
+
if (events[i].endTime >= windowStart) visible.push(events[i]);
|
|
657
|
+
}
|
|
658
|
+
return visible;
|
|
321
659
|
};
|
|
322
|
-
var rows_header_default = RowsHeader;
|
|
323
660
|
|
|
324
|
-
// src/
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
useContext as useContext6,
|
|
329
|
-
useEffect as useEffect3,
|
|
330
|
-
useRef as useRef5,
|
|
331
|
-
useState as useState3
|
|
332
|
-
} from "react";
|
|
661
|
+
// src/core/coords.ts
|
|
662
|
+
var timeToX = (time, windowStart, tick) => (time - windowStart) / tick;
|
|
663
|
+
var timeToWidth = (startTime, endTime, tick) => (endTime - startTime) / tick;
|
|
664
|
+
var intersectsWindow = (event, windowStart, windowEnd) => event.endTime >= windowStart && event.startTime <= windowEnd;
|
|
333
665
|
|
|
334
|
-
// src/
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
var
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
666
|
+
// src/core/lanes.ts
|
|
667
|
+
var LANE_HEIGHT = 22;
|
|
668
|
+
var LANE_TOP_OFFSET = 10;
|
|
669
|
+
var ROW_BASE_HEIGHT = 40;
|
|
670
|
+
var STATIC_EVENT_BASE_HEIGHT = 20;
|
|
671
|
+
var EVENT_BAR_HEIGHT = 20;
|
|
672
|
+
var laneTop = (lane) => LANE_TOP_OFFSET + LANE_HEIGHT * lane;
|
|
673
|
+
var rowMinHeight = (highestLane) => ROW_BASE_HEIGHT + highestLane * LANE_HEIGHT;
|
|
674
|
+
var staticEventHeight = (highestLane) => STATIC_EVENT_BASE_HEIGHT + highestLane * LANE_HEIGHT;
|
|
675
|
+
var assignLanes = (rowEvents, windowStart, windowEnd) => {
|
|
676
|
+
let eventOrder = 0;
|
|
677
|
+
const prevEvent = [];
|
|
678
|
+
let highestEventOrder = 0;
|
|
679
|
+
const laneOf = /* @__PURE__ */ new Map();
|
|
680
|
+
for (const event of rowEvents) {
|
|
681
|
+
if (!intersectsWindow(event, windowStart, windowEnd)) continue;
|
|
682
|
+
let tempEventOrder = 0;
|
|
683
|
+
let assignEventOrder = true;
|
|
684
|
+
for (let i = 0; i <= eventOrder; i++) {
|
|
685
|
+
if (prevEvent[i] && prevEvent[i].endTime > event.startTime) {
|
|
686
|
+
tempEventOrder += 1;
|
|
687
|
+
} else {
|
|
688
|
+
if (eventOrder > highestEventOrder) {
|
|
689
|
+
highestEventOrder = eventOrder;
|
|
690
|
+
}
|
|
691
|
+
eventOrder = 0;
|
|
692
|
+
assignEventOrder = false;
|
|
693
|
+
break;
|
|
348
694
|
}
|
|
349
695
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
gridTemplateColumns: `repeat(auto-fill, minmax(${cellWidth}px, 1fr))`
|
|
361
|
-
} : {
|
|
362
|
-
gridTemplateColumns: `repeat(auto-fill, minmax(${minWidth}px, ${cellWidth}px))`
|
|
363
|
-
}
|
|
364
|
-
},
|
|
365
|
-
lines
|
|
366
|
-
);
|
|
696
|
+
if (assignEventOrder) {
|
|
697
|
+
eventOrder = tempEventOrder;
|
|
698
|
+
}
|
|
699
|
+
prevEvent[tempEventOrder] = event;
|
|
700
|
+
laneOf.set(event.id, tempEventOrder);
|
|
701
|
+
}
|
|
702
|
+
if (eventOrder > highestEventOrder) {
|
|
703
|
+
highestEventOrder = eventOrder;
|
|
704
|
+
}
|
|
705
|
+
return { laneOf, highestLane: highestEventOrder };
|
|
367
706
|
};
|
|
368
|
-
var lines_canvas_default = LinesCanvas;
|
|
369
707
|
|
|
370
|
-
// src/
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
id,
|
|
378
|
-
startPosition,
|
|
379
|
-
width,
|
|
380
|
-
top,
|
|
381
|
-
height
|
|
708
|
+
// src/core/interactions.ts
|
|
709
|
+
var computeDropTimes = ({
|
|
710
|
+
pointerX,
|
|
711
|
+
cellWidth,
|
|
712
|
+
tick,
|
|
713
|
+
windowStart,
|
|
714
|
+
duration
|
|
382
715
|
}) => {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
top,
|
|
394
|
-
minHeight: height
|
|
395
|
-
}
|
|
716
|
+
const closestCell = Math.round(pointerX / cellWidth);
|
|
717
|
+
const newPosition = cellWidth * closestCell;
|
|
718
|
+
const startTime = windowStart + newPosition * tick;
|
|
719
|
+
return { startTime, endTime: startTime + duration };
|
|
720
|
+
};
|
|
721
|
+
var computeResizeTimes = (event, deltaPx, tick, direction) => {
|
|
722
|
+
if (direction === "left") {
|
|
723
|
+
const startTime = Math.round(event.startTime + deltaPx * tick);
|
|
724
|
+
if (event.endTime - startTime > 0) {
|
|
725
|
+
return { startTime, endTime: event.endTime };
|
|
396
726
|
}
|
|
397
|
-
|
|
727
|
+
return null;
|
|
728
|
+
}
|
|
729
|
+
const endTime = Math.round(event.endTime + deltaPx * tick);
|
|
730
|
+
if (endTime - event.startTime > 0) {
|
|
731
|
+
return { startTime: event.startTime, endTime };
|
|
732
|
+
}
|
|
733
|
+
return null;
|
|
734
|
+
};
|
|
735
|
+
var canResizeEvent = (event, eventsResize) => {
|
|
736
|
+
var _a, _b, _c, _d;
|
|
737
|
+
return !((_a = event.props) == null ? void 0 : _a.isLocked) && (eventsResize && (((_b = event.props) == null ? void 0 : _b.isResizable) === true || ((_c = event.props) == null ? void 0 : _c.isResizable) === void 0) || !eventsResize && ((_d = event.props) == null ? void 0 : _d.isResizable) === true);
|
|
738
|
+
};
|
|
739
|
+
var stepCellWidth = (cellWidth, deltaY, tick) => {
|
|
740
|
+
const pixelsToCalculate = 900 / tick;
|
|
741
|
+
const next = deltaY > 0 ? cellWidth + pixelsToCalculate : cellWidth - pixelsToCalculate;
|
|
742
|
+
if (next < pixelsToCalculate || next > pixelsToCalculate * 12) {
|
|
743
|
+
return cellWidth;
|
|
744
|
+
}
|
|
745
|
+
return next;
|
|
398
746
|
};
|
|
399
|
-
var static_event_default = StaticEvent;
|
|
400
|
-
|
|
401
|
-
// src/components/row-content.tsx
|
|
402
|
-
import React7, {
|
|
403
|
-
forwardRef,
|
|
404
|
-
useCallback as useCallback2,
|
|
405
|
-
useContext as useContext3
|
|
406
|
-
} from "react";
|
|
407
747
|
|
|
408
|
-
//
|
|
409
|
-
var
|
|
410
|
-
var
|
|
411
|
-
var
|
|
412
|
-
var
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
"This object has been frozen and should not be mutated",
|
|
421
|
-
function(data) {
|
|
422
|
-
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
|
|
423
|
-
},
|
|
424
|
-
"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
|
|
425
|
-
"Immer forbids circular references",
|
|
426
|
-
"The first or second argument to `produce` must be a function",
|
|
427
|
-
"The third argument to `produce` must be a function or undefined",
|
|
428
|
-
"First argument to `createDraft` must be a plain object, an array, or an immerable object",
|
|
429
|
-
"First argument to `finishDraft` must be a draft returned by `createDraft`",
|
|
430
|
-
function(thing) {
|
|
431
|
-
return `'current' expects a draft, got: ${thing}`;
|
|
432
|
-
},
|
|
433
|
-
"Object.defineProperty() cannot be used on an Immer draft",
|
|
434
|
-
"Object.setPrototypeOf() cannot be used on an Immer draft",
|
|
435
|
-
"Immer only supports deleting array indices",
|
|
436
|
-
"Immer only supports setting array indices and the 'length' property",
|
|
437
|
-
function(thing) {
|
|
438
|
-
return `'original' expects a draft, got: ${thing}`;
|
|
439
|
-
}
|
|
440
|
-
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
|
|
441
|
-
// See Patches.ts for additional errors
|
|
442
|
-
] : [];
|
|
443
|
-
function die(error, ...args) {
|
|
444
|
-
if (process.env.NODE_ENV !== "production") {
|
|
445
|
-
const e = errors[error];
|
|
446
|
-
const msg = typeof e === "function" ? e.apply(null, args) : e;
|
|
447
|
-
throw new Error(`[Immer] ${msg}`);
|
|
448
|
-
}
|
|
449
|
-
throw new Error(
|
|
450
|
-
`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
|
|
451
|
-
);
|
|
452
|
-
}
|
|
453
|
-
var getPrototypeOf = Object.getPrototypeOf;
|
|
454
|
-
function isDraft(value) {
|
|
455
|
-
return !!value && !!value[DRAFT_STATE];
|
|
456
|
-
}
|
|
457
|
-
function isDraftable(value) {
|
|
458
|
-
var _a;
|
|
459
|
-
if (!value)
|
|
460
|
-
return false;
|
|
461
|
-
return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!((_a = value.constructor) == null ? void 0 : _a[DRAFTABLE]) || isMap(value) || isSet(value);
|
|
462
|
-
}
|
|
463
|
-
var objectCtorString = Object.prototype.constructor.toString();
|
|
464
|
-
function isPlainObject(value) {
|
|
465
|
-
if (!value || typeof value !== "object")
|
|
466
|
-
return false;
|
|
467
|
-
const proto = getPrototypeOf(value);
|
|
468
|
-
if (proto === null) {
|
|
469
|
-
return true;
|
|
470
|
-
}
|
|
471
|
-
const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
472
|
-
if (Ctor === Object)
|
|
473
|
-
return true;
|
|
474
|
-
return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
|
|
475
|
-
}
|
|
476
|
-
function each(obj, iter) {
|
|
477
|
-
if (getArchtype(obj) === 0) {
|
|
478
|
-
Reflect.ownKeys(obj).forEach((key) => {
|
|
479
|
-
iter(key, obj[key], obj);
|
|
480
|
-
});
|
|
481
|
-
} else {
|
|
482
|
-
obj.forEach((entry, index) => iter(index, entry, obj));
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
function getArchtype(thing) {
|
|
486
|
-
const state = thing[DRAFT_STATE];
|
|
487
|
-
return state ? state.type_ : Array.isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
|
|
488
|
-
}
|
|
489
|
-
function has(thing, prop) {
|
|
490
|
-
return getArchtype(thing) === 2 ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
|
|
491
|
-
}
|
|
492
|
-
function set(thing, propOrOldValue, value) {
|
|
493
|
-
const t = getArchtype(thing);
|
|
494
|
-
if (t === 2)
|
|
495
|
-
thing.set(propOrOldValue, value);
|
|
496
|
-
else if (t === 3) {
|
|
497
|
-
thing.add(value);
|
|
498
|
-
} else
|
|
499
|
-
thing[propOrOldValue] = value;
|
|
500
|
-
}
|
|
501
|
-
function is(x, y) {
|
|
502
|
-
if (x === y) {
|
|
503
|
-
return x !== 0 || 1 / x === 1 / y;
|
|
504
|
-
} else {
|
|
505
|
-
return x !== x && y !== y;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
function isMap(target) {
|
|
509
|
-
return target instanceof Map;
|
|
510
|
-
}
|
|
511
|
-
function isSet(target) {
|
|
512
|
-
return target instanceof Set;
|
|
513
|
-
}
|
|
514
|
-
function latest(state) {
|
|
515
|
-
return state.copy_ || state.base_;
|
|
516
|
-
}
|
|
517
|
-
function shallowCopy(base, strict) {
|
|
518
|
-
if (isMap(base)) {
|
|
519
|
-
return new Map(base);
|
|
520
|
-
}
|
|
521
|
-
if (isSet(base)) {
|
|
522
|
-
return new Set(base);
|
|
523
|
-
}
|
|
524
|
-
if (Array.isArray(base))
|
|
525
|
-
return Array.prototype.slice.call(base);
|
|
526
|
-
const isPlain = isPlainObject(base);
|
|
527
|
-
if (strict === true || strict === "class_only" && !isPlain) {
|
|
528
|
-
const descriptors = Object.getOwnPropertyDescriptors(base);
|
|
529
|
-
delete descriptors[DRAFT_STATE];
|
|
530
|
-
let keys = Reflect.ownKeys(descriptors);
|
|
531
|
-
for (let i = 0; i < keys.length; i++) {
|
|
532
|
-
const key = keys[i];
|
|
533
|
-
const desc = descriptors[key];
|
|
534
|
-
if (desc.writable === false) {
|
|
535
|
-
desc.writable = true;
|
|
536
|
-
desc.configurable = true;
|
|
537
|
-
}
|
|
538
|
-
if (desc.get || desc.set)
|
|
539
|
-
descriptors[key] = {
|
|
540
|
-
configurable: true,
|
|
541
|
-
writable: true,
|
|
542
|
-
// could live with !!desc.set as well here...
|
|
543
|
-
enumerable: desc.enumerable,
|
|
544
|
-
value: base[key]
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
return Object.create(getPrototypeOf(base), descriptors);
|
|
548
|
-
} else {
|
|
549
|
-
const proto = getPrototypeOf(base);
|
|
550
|
-
if (proto !== null && isPlain) {
|
|
551
|
-
return __spreadValues({}, base);
|
|
552
|
-
}
|
|
553
|
-
const obj = Object.create(proto);
|
|
554
|
-
return Object.assign(obj, base);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
function freeze(obj, deep = false) {
|
|
558
|
-
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
|
|
559
|
-
return obj;
|
|
560
|
-
if (getArchtype(obj) > 1) {
|
|
561
|
-
obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
|
|
562
|
-
}
|
|
563
|
-
Object.freeze(obj);
|
|
564
|
-
if (deep)
|
|
565
|
-
Object.entries(obj).forEach(([key, value]) => freeze(value, true));
|
|
566
|
-
return obj;
|
|
567
|
-
}
|
|
568
|
-
function dontMutateFrozenCollections() {
|
|
569
|
-
die(2);
|
|
570
|
-
}
|
|
571
|
-
function isFrozen(obj) {
|
|
572
|
-
return Object.isFrozen(obj);
|
|
573
|
-
}
|
|
574
|
-
var plugins = {};
|
|
575
|
-
function getPlugin(pluginKey) {
|
|
576
|
-
const plugin = plugins[pluginKey];
|
|
577
|
-
if (!plugin) {
|
|
578
|
-
die(0, pluginKey);
|
|
579
|
-
}
|
|
580
|
-
return plugin;
|
|
581
|
-
}
|
|
582
|
-
var currentScope;
|
|
583
|
-
function getCurrentScope() {
|
|
584
|
-
return currentScope;
|
|
585
|
-
}
|
|
586
|
-
function createScope(parent_, immer_) {
|
|
587
|
-
return {
|
|
588
|
-
drafts_: [],
|
|
589
|
-
parent_,
|
|
590
|
-
immer_,
|
|
591
|
-
// Whenever the modified draft contains a draft from another scope, we
|
|
592
|
-
// need to prevent auto-freezing so the unowned draft can be finalized.
|
|
593
|
-
canAutoFreeze_: true,
|
|
594
|
-
unfinalizedDrafts_: 0
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
function usePatchesInScope(scope, patchListener) {
|
|
598
|
-
if (patchListener) {
|
|
599
|
-
getPlugin("Patches");
|
|
600
|
-
scope.patches_ = [];
|
|
601
|
-
scope.inversePatches_ = [];
|
|
602
|
-
scope.patchListener_ = patchListener;
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
function revokeScope(scope) {
|
|
606
|
-
leaveScope(scope);
|
|
607
|
-
scope.drafts_.forEach(revokeDraft);
|
|
608
|
-
scope.drafts_ = null;
|
|
609
|
-
}
|
|
610
|
-
function leaveScope(scope) {
|
|
611
|
-
if (scope === currentScope) {
|
|
612
|
-
currentScope = scope.parent_;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
function enterScope(immer2) {
|
|
616
|
-
return currentScope = createScope(currentScope, immer2);
|
|
617
|
-
}
|
|
618
|
-
function revokeDraft(draft) {
|
|
619
|
-
const state = draft[DRAFT_STATE];
|
|
620
|
-
if (state.type_ === 0 || state.type_ === 1)
|
|
621
|
-
state.revoke_();
|
|
622
|
-
else
|
|
623
|
-
state.revoked_ = true;
|
|
624
|
-
}
|
|
625
|
-
function processResult(result, scope) {
|
|
626
|
-
scope.unfinalizedDrafts_ = scope.drafts_.length;
|
|
627
|
-
const baseDraft = scope.drafts_[0];
|
|
628
|
-
const isReplaced = result !== void 0 && result !== baseDraft;
|
|
629
|
-
if (isReplaced) {
|
|
630
|
-
if (baseDraft[DRAFT_STATE].modified_) {
|
|
631
|
-
revokeScope(scope);
|
|
632
|
-
die(4);
|
|
633
|
-
}
|
|
634
|
-
if (isDraftable(result)) {
|
|
635
|
-
result = finalize(scope, result);
|
|
636
|
-
if (!scope.parent_)
|
|
637
|
-
maybeFreeze(scope, result);
|
|
638
|
-
}
|
|
639
|
-
if (scope.patches_) {
|
|
640
|
-
getPlugin("Patches").generateReplacementPatches_(
|
|
641
|
-
baseDraft[DRAFT_STATE].base_,
|
|
642
|
-
result,
|
|
643
|
-
scope.patches_,
|
|
644
|
-
scope.inversePatches_
|
|
645
|
-
);
|
|
646
|
-
}
|
|
748
|
+
// src/canvas/draw-events.ts
|
|
749
|
+
var EVENT_RADIUS = 5;
|
|
750
|
+
var EVENT_TEXT_INSET = 13;
|
|
751
|
+
var HANDLE_INSET = 4;
|
|
752
|
+
var HANDLE_BAR_WIDTH = 3;
|
|
753
|
+
var HANDLE_BAR_GAP = 1;
|
|
754
|
+
var HANDLE_BAR_HEIGHT = 10;
|
|
755
|
+
var roundedRect = (ctx, x, y, width, height, radius) => {
|
|
756
|
+
const r = Math.min(radius, width / 2, height / 2);
|
|
757
|
+
ctx.beginPath();
|
|
758
|
+
if (typeof ctx.roundRect === "function") {
|
|
759
|
+
ctx.roundRect(x, y, width, height, r);
|
|
647
760
|
} else {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
if (state.scope_ !== rootScope)
|
|
668
|
-
return value;
|
|
669
|
-
if (!state.modified_) {
|
|
670
|
-
maybeFreeze(rootScope, state.base_, true);
|
|
671
|
-
return state.base_;
|
|
672
|
-
}
|
|
673
|
-
if (!state.finalized_) {
|
|
674
|
-
state.finalized_ = true;
|
|
675
|
-
state.scope_.unfinalizedDrafts_--;
|
|
676
|
-
const result = state.copy_;
|
|
677
|
-
let resultEach = result;
|
|
678
|
-
let isSet2 = false;
|
|
679
|
-
if (state.type_ === 3) {
|
|
680
|
-
resultEach = new Set(result);
|
|
681
|
-
result.clear();
|
|
682
|
-
isSet2 = true;
|
|
683
|
-
}
|
|
684
|
-
each(
|
|
685
|
-
resultEach,
|
|
686
|
-
(key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2)
|
|
761
|
+
ctx.moveTo(x + r, y);
|
|
762
|
+
ctx.arcTo(x + width, y, x + width, y + height, r);
|
|
763
|
+
ctx.arcTo(x + width, y + height, x, y + height, r);
|
|
764
|
+
ctx.arcTo(x, y + height, x, y, r);
|
|
765
|
+
ctx.arcTo(x, y, x + width, y, r);
|
|
766
|
+
ctx.closePath();
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
var drawRowDividers = (ctx, view, scene, animator) => {
|
|
770
|
+
const [windowStart, windowEnd] = view.windowTime;
|
|
771
|
+
const rowIds = scene.getRowIds();
|
|
772
|
+
ctx.strokeStyle = view.theme.gridColor;
|
|
773
|
+
ctx.lineWidth = 1;
|
|
774
|
+
ctx.beginPath();
|
|
775
|
+
let y = 0;
|
|
776
|
+
for (let i = 0; i < rowIds.length; i++) {
|
|
777
|
+
y += animator.rowHeight(
|
|
778
|
+
rowIds[i],
|
|
779
|
+
scene.getRowHeight(rowIds[i], windowStart, windowEnd)
|
|
687
780
|
);
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
781
|
+
if (i === rowIds.length - 1) break;
|
|
782
|
+
const screenY = y - view.scrollTop;
|
|
783
|
+
if (screenY < 0) continue;
|
|
784
|
+
if (screenY > view.height) break;
|
|
785
|
+
const crisp = Math.round(screenY) - 0.5;
|
|
786
|
+
ctx.moveTo(0, crisp);
|
|
787
|
+
ctx.lineTo(view.width, crisp);
|
|
788
|
+
}
|
|
789
|
+
ctx.stroke();
|
|
790
|
+
};
|
|
791
|
+
var drawResizeHandles = (ctx, rect, alpha, strokeColor) => {
|
|
792
|
+
ctx.save();
|
|
793
|
+
ctx.globalAlpha *= alpha;
|
|
794
|
+
ctx.strokeStyle = strokeColor;
|
|
795
|
+
ctx.lineWidth = 1;
|
|
796
|
+
const barY = rect.y + (rect.height - HANDLE_BAR_HEIGHT) / 2;
|
|
797
|
+
const xs = [
|
|
798
|
+
rect.x + HANDLE_INSET,
|
|
799
|
+
rect.x + HANDLE_INSET + HANDLE_BAR_WIDTH + HANDLE_BAR_GAP,
|
|
800
|
+
rect.x + rect.width - HANDLE_INSET - HANDLE_BAR_WIDTH,
|
|
801
|
+
rect.x + rect.width - HANDLE_INSET - HANDLE_BAR_WIDTH * 2 - HANDLE_BAR_GAP
|
|
802
|
+
];
|
|
803
|
+
for (const barX of xs) {
|
|
804
|
+
ctx.beginPath();
|
|
805
|
+
if (typeof ctx.roundRect === "function") {
|
|
806
|
+
ctx.roundRect(
|
|
807
|
+
barX + 0.5,
|
|
808
|
+
barY + 0.5,
|
|
809
|
+
HANDLE_BAR_WIDTH - 1,
|
|
810
|
+
HANDLE_BAR_HEIGHT - 1,
|
|
811
|
+
1.5
|
|
695
812
|
);
|
|
813
|
+
} else {
|
|
814
|
+
ctx.rect(barX + 0.5, barY + 0.5, HANDLE_BAR_WIDTH - 1, HANDLE_BAR_HEIGHT - 1);
|
|
696
815
|
}
|
|
816
|
+
ctx.stroke();
|
|
697
817
|
}
|
|
698
|
-
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
818
|
+
ctx.restore();
|
|
819
|
+
};
|
|
820
|
+
var defaultDrawEvent = (ctx, event, rect, view, font) => {
|
|
821
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
822
|
+
const theme = view.theme;
|
|
823
|
+
const style = (_a = event.props) == null ? void 0 : _a.style;
|
|
824
|
+
if ((style == null ? void 0 : style.opacity) !== void 0) ctx.globalAlpha *= style.opacity;
|
|
825
|
+
ctx.fillStyle = (_b = style == null ? void 0 : style.fill) != null ? _b : theme.eventFill;
|
|
826
|
+
ctx.strokeStyle = (_c = style == null ? void 0 : style.stroke) != null ? _c : theme.eventStroke;
|
|
827
|
+
ctx.lineWidth = (_d = style == null ? void 0 : style.strokeWidth) != null ? _d : 1;
|
|
828
|
+
roundedRect(
|
|
829
|
+
ctx,
|
|
830
|
+
rect.x + 0.5,
|
|
831
|
+
rect.y + 0.5,
|
|
832
|
+
rect.width - 1,
|
|
833
|
+
rect.height - 1,
|
|
834
|
+
(_e = style == null ? void 0 : style.borderRadius) != null ? _e : EVENT_RADIUS
|
|
835
|
+
);
|
|
836
|
+
ctx.fill();
|
|
837
|
+
ctx.stroke();
|
|
838
|
+
const label = (_f = event.props) == null ? void 0 : _f.label;
|
|
839
|
+
if (label && rect.width > EVENT_TEXT_INSET * 2) {
|
|
840
|
+
ctx.fillStyle = (_g = style == null ? void 0 : style.textColor) != null ? _g : theme.eventTextColor;
|
|
841
|
+
ctx.font = (_i = (_h = style == null ? void 0 : style.font) != null ? _h : theme.font) != null ? _i : font;
|
|
842
|
+
ctx.save();
|
|
843
|
+
ctx.beginPath();
|
|
844
|
+
ctx.rect(
|
|
845
|
+
rect.x + EVENT_TEXT_INSET,
|
|
846
|
+
rect.y,
|
|
847
|
+
rect.width - EVENT_TEXT_INSET * 2,
|
|
848
|
+
rect.height
|
|
849
|
+
);
|
|
850
|
+
ctx.clip();
|
|
851
|
+
ctx.fillText(label, rect.x + EVENT_TEXT_INSET, rect.y + rect.height / 2);
|
|
852
|
+
ctx.restore();
|
|
714
853
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
isManual_: false
|
|
753
|
-
};
|
|
754
|
-
let target = state;
|
|
755
|
-
let traps = objectTraps;
|
|
756
|
-
if (isArray) {
|
|
757
|
-
target = [state];
|
|
758
|
-
traps = arrayTraps;
|
|
759
|
-
}
|
|
760
|
-
const { revoke, proxy } = Proxy.revocable(target, traps);
|
|
761
|
-
state.draft_ = proxy;
|
|
762
|
-
state.revoke_ = revoke;
|
|
763
|
-
return proxy;
|
|
764
|
-
}
|
|
765
|
-
var objectTraps = {
|
|
766
|
-
get(state, prop) {
|
|
767
|
-
if (prop === DRAFT_STATE)
|
|
768
|
-
return state;
|
|
769
|
-
const source = latest(state);
|
|
770
|
-
if (!has(source, prop)) {
|
|
771
|
-
return readPropFromProto(state, source, prop);
|
|
772
|
-
}
|
|
773
|
-
const value = source[prop];
|
|
774
|
-
if (state.finalized_ || !isDraftable(value)) {
|
|
775
|
-
return value;
|
|
776
|
-
}
|
|
777
|
-
if (value === peek(state.base_, prop)) {
|
|
778
|
-
prepareCopy(state);
|
|
779
|
-
return state.copy_[prop] = createProxy(value, state);
|
|
780
|
-
}
|
|
781
|
-
return value;
|
|
782
|
-
},
|
|
783
|
-
has(state, prop) {
|
|
784
|
-
return prop in latest(state);
|
|
785
|
-
},
|
|
786
|
-
ownKeys(state) {
|
|
787
|
-
return Reflect.ownKeys(latest(state));
|
|
788
|
-
},
|
|
789
|
-
set(state, prop, value) {
|
|
790
|
-
const desc = getDescriptorFromProto(latest(state), prop);
|
|
791
|
-
if (desc == null ? void 0 : desc.set) {
|
|
792
|
-
desc.set.call(state.draft_, value);
|
|
793
|
-
return true;
|
|
854
|
+
};
|
|
855
|
+
var drawEvents = (ctx, view, scene, font, animator) => {
|
|
856
|
+
var _a, _b, _c, _d, _e, _f;
|
|
857
|
+
if (view.tick === null) return;
|
|
858
|
+
const [windowStart, windowEnd] = view.windowTime;
|
|
859
|
+
const tick = view.tick;
|
|
860
|
+
ctx.font = (_a = view.theme.font) != null ? _a : font;
|
|
861
|
+
ctx.textBaseline = "middle";
|
|
862
|
+
ctx.textAlign = "left";
|
|
863
|
+
let rowTop = 0;
|
|
864
|
+
for (const rowId of scene.getRowIds()) {
|
|
865
|
+
const rowHeight = animator.rowHeight(
|
|
866
|
+
rowId,
|
|
867
|
+
scene.getRowHeight(rowId, windowStart, windowEnd)
|
|
868
|
+
);
|
|
869
|
+
const rowY = rowTop - view.scrollTop;
|
|
870
|
+
rowTop += rowHeight;
|
|
871
|
+
if (rowY + rowHeight < 0) continue;
|
|
872
|
+
if (rowY > view.height) break;
|
|
873
|
+
const lanes = scene.getLanes(rowId, windowStart, windowEnd);
|
|
874
|
+
for (const event of cullToWindow(
|
|
875
|
+
scene.getRowStaticEvents(rowId),
|
|
876
|
+
windowStart,
|
|
877
|
+
windowEnd
|
|
878
|
+
)) {
|
|
879
|
+
const x = timeToX(event.startTime, windowStart, tick);
|
|
880
|
+
const width = timeToWidth(event.startTime, event.endTime, tick);
|
|
881
|
+
ctx.fillStyle = view.theme.staticEventFill;
|
|
882
|
+
roundedRect(
|
|
883
|
+
ctx,
|
|
884
|
+
x,
|
|
885
|
+
rowY + LANE_TOP_OFFSET,
|
|
886
|
+
width,
|
|
887
|
+
staticEventHeight(lanes.highestLane),
|
|
888
|
+
EVENT_RADIUS
|
|
889
|
+
);
|
|
890
|
+
ctx.fill();
|
|
794
891
|
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
892
|
+
for (const event of cullToWindow(
|
|
893
|
+
scene.getRowEvents(rowId),
|
|
894
|
+
windowStart,
|
|
895
|
+
windowEnd
|
|
896
|
+
)) {
|
|
897
|
+
let x = timeToX(event.startTime, windowStart, tick);
|
|
898
|
+
let width = timeToWidth(event.startTime, event.endTime, tick);
|
|
899
|
+
const y = rowY + animator.eventTop(
|
|
900
|
+
event.id,
|
|
901
|
+
laneTop(lanes.laneOf.get(event.id))
|
|
902
|
+
);
|
|
903
|
+
const resize = view.resizePreview;
|
|
904
|
+
const resizing = resize !== null && resize.eventId === event.id;
|
|
905
|
+
if (resizing) {
|
|
906
|
+
if (resize.direction === "left") {
|
|
907
|
+
x += resize.deltaPx;
|
|
908
|
+
width -= resize.deltaPx;
|
|
909
|
+
} else {
|
|
910
|
+
width += resize.deltaPx;
|
|
911
|
+
}
|
|
802
912
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
913
|
+
const rect = { x, y, width, height: EVENT_BAR_HEIGHT };
|
|
914
|
+
const state = {
|
|
915
|
+
hovered: view.hoveredEventId === event.id,
|
|
916
|
+
dragging: view.draggedEventId === event.id,
|
|
917
|
+
resizing,
|
|
918
|
+
selected: false
|
|
919
|
+
};
|
|
920
|
+
ctx.save();
|
|
921
|
+
if (state.dragging) ctx.globalAlpha = 0.5;
|
|
922
|
+
const custom = (_c = (_b = event.props) == null ? void 0 : _b.drawEvent) != null ? _c : view.drawEvent;
|
|
923
|
+
const drawn = custom !== void 0 && custom(ctx, event, rect, state, view.theme) !== false;
|
|
924
|
+
if (!drawn) {
|
|
925
|
+
defaultDrawEvent(ctx, event, rect, view, font);
|
|
926
|
+
}
|
|
927
|
+
if (canResizeEvent(event, view.eventsResize)) {
|
|
928
|
+
const alpha = animator.handleAlpha(
|
|
929
|
+
event.id,
|
|
930
|
+
state.hovered || state.resizing ? 1 : 0
|
|
931
|
+
);
|
|
932
|
+
if (alpha > 0.01) {
|
|
933
|
+
drawResizeHandles(
|
|
934
|
+
ctx,
|
|
935
|
+
rect,
|
|
936
|
+
alpha,
|
|
937
|
+
(_f = (_e = (_d = event.props) == null ? void 0 : _d.style) == null ? void 0 : _e.stroke) != null ? _f : view.theme.eventStroke
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
ctx.restore();
|
|
826
942
|
}
|
|
827
|
-
return true;
|
|
828
|
-
},
|
|
829
|
-
// Note: We never coerce `desc.value` into an Immer draft, because we can't make
|
|
830
|
-
// the same guarantee in ES5 mode.
|
|
831
|
-
getOwnPropertyDescriptor(state, prop) {
|
|
832
|
-
const owner = latest(state);
|
|
833
|
-
const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
|
|
834
|
-
if (!desc)
|
|
835
|
-
return desc;
|
|
836
|
-
return {
|
|
837
|
-
writable: true,
|
|
838
|
-
configurable: state.type_ !== 1 || prop !== "length",
|
|
839
|
-
enumerable: desc.enumerable,
|
|
840
|
-
value: owner[prop]
|
|
841
|
-
};
|
|
842
|
-
},
|
|
843
|
-
defineProperty() {
|
|
844
|
-
die(11);
|
|
845
|
-
},
|
|
846
|
-
getPrototypeOf(state) {
|
|
847
|
-
return getPrototypeOf(state.base_);
|
|
848
|
-
},
|
|
849
|
-
setPrototypeOf() {
|
|
850
|
-
die(12);
|
|
851
943
|
}
|
|
852
944
|
};
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
return
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
}
|
|
896
|
-
function markChanged(state) {
|
|
897
|
-
if (!state.modified_) {
|
|
898
|
-
state.modified_ = true;
|
|
899
|
-
if (state.parent_) {
|
|
900
|
-
markChanged(state.parent_);
|
|
945
|
+
|
|
946
|
+
// src/canvas/renderer.ts
|
|
947
|
+
var TimelineRenderer = class {
|
|
948
|
+
constructor(staticCanvas, dynamicCanvas, scene) {
|
|
949
|
+
this.staticCanvas = staticCanvas;
|
|
950
|
+
this.dynamicCanvas = dynamicCanvas;
|
|
951
|
+
this.scene = scene;
|
|
952
|
+
this.view = {
|
|
953
|
+
windowTime: [0, 0],
|
|
954
|
+
tick: null,
|
|
955
|
+
cellWidth: 0,
|
|
956
|
+
scrollTop: 0,
|
|
957
|
+
width: 0,
|
|
958
|
+
height: 0,
|
|
959
|
+
theme: DEFAULT_THEME,
|
|
960
|
+
drawEvent: void 0,
|
|
961
|
+
eventsResize: true,
|
|
962
|
+
hoveredEventId: null,
|
|
963
|
+
draggedEventId: null,
|
|
964
|
+
resizePreview: null
|
|
965
|
+
};
|
|
966
|
+
this.animator = new LayoutAnimator();
|
|
967
|
+
this.dpr = typeof window !== "undefined" ? window.devicePixelRatio : 1;
|
|
968
|
+
this.font = "16px sans-serif";
|
|
969
|
+
this.scheduler = new FrameScheduler((dirty) => this.drawFrame(dirty));
|
|
970
|
+
this.unsubscribeScene = scene.subscribe(() => this.invalidate("all"));
|
|
971
|
+
this.unwatchDpr = watchDpr((dpr) => {
|
|
972
|
+
this.dpr = dpr;
|
|
973
|
+
this.resizeCanvases();
|
|
974
|
+
this.invalidate("all");
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
getView() {
|
|
978
|
+
return this.view;
|
|
979
|
+
}
|
|
980
|
+
setView(partial) {
|
|
981
|
+
const sizeChanged = partial.width !== void 0 && partial.width !== this.view.width || partial.height !== void 0 && partial.height !== this.view.height;
|
|
982
|
+
this.view = __spreadValues(__spreadValues({}, this.view), partial);
|
|
983
|
+
if (sizeChanged) {
|
|
984
|
+
this.resizeCanvases();
|
|
985
|
+
this.invalidate("all");
|
|
986
|
+
return;
|
|
901
987
|
}
|
|
988
|
+
this.invalidate("all");
|
|
902
989
|
}
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
if (!state.copy_) {
|
|
906
|
-
state.copy_ = shallowCopy(
|
|
907
|
-
state.base_,
|
|
908
|
-
state.scope_.immer_.useStrictShallowCopy_
|
|
909
|
-
);
|
|
990
|
+
invalidate(layer) {
|
|
991
|
+
this.scheduler.invalidate(layer);
|
|
910
992
|
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
this.autoFreeze_ = true;
|
|
915
|
-
this.useStrictShallowCopy_ = false;
|
|
916
|
-
this.produce = (base, recipe, patchListener) => {
|
|
917
|
-
if (typeof base === "function" && typeof recipe !== "function") {
|
|
918
|
-
const defaultBase = recipe;
|
|
919
|
-
recipe = base;
|
|
920
|
-
const self = this;
|
|
921
|
-
return function curriedProduce(base2 = defaultBase, ...args) {
|
|
922
|
-
return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
|
|
923
|
-
};
|
|
924
|
-
}
|
|
925
|
-
if (typeof recipe !== "function")
|
|
926
|
-
die(6);
|
|
927
|
-
if (patchListener !== void 0 && typeof patchListener !== "function")
|
|
928
|
-
die(7);
|
|
929
|
-
let result;
|
|
930
|
-
if (isDraftable(base)) {
|
|
931
|
-
const scope = enterScope(this);
|
|
932
|
-
const proxy = createProxy(base, void 0);
|
|
933
|
-
let hasError = true;
|
|
934
|
-
try {
|
|
935
|
-
result = recipe(proxy);
|
|
936
|
-
hasError = false;
|
|
937
|
-
} finally {
|
|
938
|
-
if (hasError)
|
|
939
|
-
revokeScope(scope);
|
|
940
|
-
else
|
|
941
|
-
leaveScope(scope);
|
|
942
|
-
}
|
|
943
|
-
usePatchesInScope(scope, patchListener);
|
|
944
|
-
return processResult(result, scope);
|
|
945
|
-
} else if (!base || typeof base !== "object") {
|
|
946
|
-
result = recipe(base);
|
|
947
|
-
if (result === void 0)
|
|
948
|
-
result = base;
|
|
949
|
-
if (result === NOTHING)
|
|
950
|
-
result = void 0;
|
|
951
|
-
if (this.autoFreeze_)
|
|
952
|
-
freeze(result, true);
|
|
953
|
-
if (patchListener) {
|
|
954
|
-
const p = [];
|
|
955
|
-
const ip = [];
|
|
956
|
-
getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
|
|
957
|
-
patchListener(p, ip);
|
|
958
|
-
}
|
|
959
|
-
return result;
|
|
960
|
-
} else
|
|
961
|
-
die(1, base);
|
|
962
|
-
};
|
|
963
|
-
this.produceWithPatches = (base, recipe) => {
|
|
964
|
-
if (typeof base === "function") {
|
|
965
|
-
return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
|
|
966
|
-
}
|
|
967
|
-
let patches, inversePatches;
|
|
968
|
-
const result = this.produce(base, recipe, (p, ip) => {
|
|
969
|
-
patches = p;
|
|
970
|
-
inversePatches = ip;
|
|
971
|
-
});
|
|
972
|
-
return [result, patches, inversePatches];
|
|
973
|
-
};
|
|
974
|
-
if (typeof (config == null ? void 0 : config.autoFreeze) === "boolean")
|
|
975
|
-
this.setAutoFreeze(config.autoFreeze);
|
|
976
|
-
if (typeof (config == null ? void 0 : config.useStrictShallowCopy) === "boolean")
|
|
977
|
-
this.setUseStrictShallowCopy(config.useStrictShallowCopy);
|
|
978
|
-
}
|
|
979
|
-
createDraft(base) {
|
|
980
|
-
if (!isDraftable(base))
|
|
981
|
-
die(8);
|
|
982
|
-
if (isDraft(base))
|
|
983
|
-
base = current(base);
|
|
984
|
-
const scope = enterScope(this);
|
|
985
|
-
const proxy = createProxy(base, void 0);
|
|
986
|
-
proxy[DRAFT_STATE].isManual_ = true;
|
|
987
|
-
leaveScope(scope);
|
|
988
|
-
return proxy;
|
|
989
|
-
}
|
|
990
|
-
finishDraft(draft, patchListener) {
|
|
991
|
-
const state = draft && draft[DRAFT_STATE];
|
|
992
|
-
if (!state || !state.isManual_)
|
|
993
|
-
die(9);
|
|
994
|
-
const { scope_: scope } = state;
|
|
995
|
-
usePatchesInScope(scope, patchListener);
|
|
996
|
-
return processResult(void 0, scope);
|
|
993
|
+
/** Force a synchronous draw of anything pending (tests, screenshots). */
|
|
994
|
+
flush() {
|
|
995
|
+
this.scheduler.flush();
|
|
997
996
|
}
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
*/
|
|
1003
|
-
setAutoFreeze(value) {
|
|
1004
|
-
this.autoFreeze_ = value;
|
|
997
|
+
dispose() {
|
|
998
|
+
this.scheduler.dispose();
|
|
999
|
+
this.unsubscribeScene();
|
|
1000
|
+
this.unwatchDpr();
|
|
1005
1001
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
const
|
|
1018
|
-
if (
|
|
1019
|
-
|
|
1020
|
-
|
|
1002
|
+
resizeCanvases() {
|
|
1003
|
+
sizeCanvas(this.staticCanvas, this.view.width, this.view.height, this.dpr);
|
|
1004
|
+
sizeCanvas(this.dynamicCanvas, this.view.width, this.view.height, this.dpr);
|
|
1005
|
+
if (typeof getComputedStyle === "function") {
|
|
1006
|
+
this.font = getComputedStyle(this.dynamicCanvas).font || this.font;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
drawFrame(dirty) {
|
|
1010
|
+
if (this.view.tick === null) return;
|
|
1011
|
+
this.animator.beginFrame(performance.now());
|
|
1012
|
+
if (dirty.static) {
|
|
1013
|
+
const ctx = this.staticCanvas.getContext("2d");
|
|
1014
|
+
if (ctx) {
|
|
1015
|
+
ctx.clearRect(0, 0, this.view.width, this.view.height);
|
|
1016
|
+
drawGridLines(ctx, {
|
|
1017
|
+
width: this.view.width,
|
|
1018
|
+
height: this.view.height,
|
|
1019
|
+
cellWidth: this.view.cellWidth,
|
|
1020
|
+
color: this.view.theme.gridColor
|
|
1021
|
+
});
|
|
1022
|
+
drawRowDividers(ctx, this.view, this.scene, this.animator);
|
|
1021
1023
|
}
|
|
1022
1024
|
}
|
|
1023
|
-
if (
|
|
1024
|
-
|
|
1025
|
+
if (dirty.dynamic) {
|
|
1026
|
+
const ctx = this.dynamicCanvas.getContext("2d");
|
|
1027
|
+
if (ctx) {
|
|
1028
|
+
ctx.clearRect(0, 0, this.view.width, this.view.height);
|
|
1029
|
+
drawEvents(ctx, this.view, this.scene, this.font, this.animator);
|
|
1030
|
+
}
|
|
1025
1031
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
return applyPatchesImpl(base, patches);
|
|
1032
|
+
if (this.animator.isAnimating()) {
|
|
1033
|
+
this.scheduler.invalidate("all");
|
|
1029
1034
|
}
|
|
1030
|
-
return this.produce(
|
|
1031
|
-
base,
|
|
1032
|
-
(draft) => applyPatchesImpl(draft, patches)
|
|
1033
|
-
);
|
|
1034
1035
|
}
|
|
1035
1036
|
};
|
|
1036
|
-
function createProxy(value, parent) {
|
|
1037
|
-
const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
|
|
1038
|
-
const scope = parent ? parent.scope_ : getCurrentScope();
|
|
1039
|
-
scope.drafts_.push(draft);
|
|
1040
|
-
return draft;
|
|
1041
|
-
}
|
|
1042
|
-
function current(value) {
|
|
1043
|
-
if (!isDraft(value))
|
|
1044
|
-
die(10, value);
|
|
1045
|
-
return currentImpl(value);
|
|
1046
|
-
}
|
|
1047
|
-
function currentImpl(value) {
|
|
1048
|
-
if (!isDraftable(value) || isFrozen(value))
|
|
1049
|
-
return value;
|
|
1050
|
-
const state = value[DRAFT_STATE];
|
|
1051
|
-
let copy;
|
|
1052
|
-
if (state) {
|
|
1053
|
-
if (!state.modified_)
|
|
1054
|
-
return state.base_;
|
|
1055
|
-
state.finalized_ = true;
|
|
1056
|
-
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
|
|
1057
|
-
} else {
|
|
1058
|
-
copy = shallowCopy(value, true);
|
|
1059
|
-
}
|
|
1060
|
-
each(copy, (key, childValue) => {
|
|
1061
|
-
set(copy, key, currentImpl(childValue));
|
|
1062
|
-
});
|
|
1063
|
-
if (state) {
|
|
1064
|
-
state.finalized_ = false;
|
|
1065
|
-
}
|
|
1066
|
-
return copy;
|
|
1067
|
-
}
|
|
1068
|
-
var immer = new Immer2();
|
|
1069
|
-
var produce = immer.produce;
|
|
1070
|
-
var produceWithPatches = immer.produceWithPatches.bind(
|
|
1071
|
-
immer
|
|
1072
|
-
);
|
|
1073
|
-
var setAutoFreeze = immer.setAutoFreeze.bind(immer);
|
|
1074
|
-
var setUseStrictShallowCopy = immer.setUseStrictShallowCopy.bind(immer);
|
|
1075
|
-
var applyPatches = immer.applyPatches.bind(immer);
|
|
1076
|
-
var createDraft = immer.createDraft.bind(immer);
|
|
1077
|
-
var finishDraft = immer.finishDraft.bind(immer);
|
|
1078
1037
|
|
|
1079
|
-
// src/
|
|
1080
|
-
import {
|
|
1081
|
-
var DragStartedContext = createContext2({
|
|
1082
|
-
dragStarted: false,
|
|
1083
|
-
setDragStarted: () => {
|
|
1084
|
-
}
|
|
1085
|
-
});
|
|
1038
|
+
// src/hooks/use-canvas-interactions.ts
|
|
1039
|
+
import { useCallback, useEffect as useEffect4, useMemo as useMemo3, useRef as useRef5 } from "react";
|
|
1086
1040
|
|
|
1087
|
-
// src/
|
|
1088
|
-
|
|
1089
|
-
var ExternalPropertiesContext = createContext3(
|
|
1090
|
-
{}
|
|
1091
|
-
);
|
|
1041
|
+
// src/core/types.ts
|
|
1042
|
+
var rectContains = (rect, x, y) => x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
|
|
1092
1043
|
|
|
1093
|
-
// src/
|
|
1094
|
-
var
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1044
|
+
// src/core/hit-test.ts
|
|
1045
|
+
var hitTest = (scene, view, x, y) => {
|
|
1046
|
+
const { windowStart, windowEnd, tick, scrollTop } = view;
|
|
1047
|
+
const yContent = y + scrollTop;
|
|
1048
|
+
let rowTop = 0;
|
|
1049
|
+
let rowId = null;
|
|
1050
|
+
for (const id of scene.getRowIds()) {
|
|
1051
|
+
const height = scene.getRowHeight(id, windowStart, windowEnd);
|
|
1052
|
+
if (yContent >= rowTop && yContent < rowTop + height) {
|
|
1053
|
+
rowId = id;
|
|
1054
|
+
break;
|
|
1101
1055
|
}
|
|
1102
|
-
|
|
1103
|
-
return 1;
|
|
1056
|
+
rowTop += height;
|
|
1104
1057
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
const { onDrop } = useContext3(ExternalPropertiesContext);
|
|
1113
|
-
const handleOnDrop = useCallback2(
|
|
1114
|
-
(event) => {
|
|
1115
|
-
event.preventDefault();
|
|
1116
|
-
const element = event.target;
|
|
1117
|
-
const { left } = element.getBoundingClientRect();
|
|
1118
|
-
const draggedEventId = event.dataTransfer.getData("eventId");
|
|
1119
|
-
const closestCell = Math.round((event.clientX - left) / cellWidth);
|
|
1120
|
-
const newPosition = cellWidth * closestCell;
|
|
1121
|
-
setEvents(
|
|
1122
|
-
produce((draft) => {
|
|
1123
|
-
const event2 = draft.find((event3) => event3.id === draggedEventId);
|
|
1124
|
-
if (event2 && tick) {
|
|
1125
|
-
const newStartTime = windowTime[0] + newPosition * tick;
|
|
1126
|
-
const eventDuration = event2.endTime - event2.startTime;
|
|
1127
|
-
const newEndTime = windowTime[0] + eventDuration + newPosition * tick;
|
|
1128
|
-
if (onDrop) {
|
|
1129
|
-
onDrop({
|
|
1130
|
-
eventId: event2.id,
|
|
1131
|
-
oldRowId: event2.rowId,
|
|
1132
|
-
newRowId: props.id,
|
|
1133
|
-
startTime: newStartTime,
|
|
1134
|
-
endTime: newEndTime
|
|
1135
|
-
});
|
|
1136
|
-
}
|
|
1137
|
-
event2.startTime = newStartTime;
|
|
1138
|
-
event2.endTime = newEndTime;
|
|
1139
|
-
event2.rowId = props.id;
|
|
1140
|
-
}
|
|
1141
|
-
draft.sort(sort_events_default);
|
|
1142
|
-
})
|
|
1143
|
-
);
|
|
1144
|
-
setDragStarted(false);
|
|
1145
|
-
},
|
|
1146
|
-
[setEvents, tick, windowTime, cellWidth]
|
|
1058
|
+
if (rowId === null) return null;
|
|
1059
|
+
const lanes = scene.getLanes(rowId, windowStart, windowEnd);
|
|
1060
|
+
const rowY = rowTop - scrollTop;
|
|
1061
|
+
const events = cullToWindow(
|
|
1062
|
+
scene.getRowEvents(rowId),
|
|
1063
|
+
windowStart,
|
|
1064
|
+
windowEnd
|
|
1147
1065
|
);
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1066
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
1067
|
+
const event = events[i];
|
|
1068
|
+
const rect = {
|
|
1069
|
+
x: timeToX(event.startTime, windowStart, tick),
|
|
1070
|
+
y: rowY + laneTop(lanes.laneOf.get(event.id)),
|
|
1071
|
+
width: timeToWidth(event.startTime, event.endTime, tick),
|
|
1072
|
+
height: EVENT_BAR_HEIGHT
|
|
1073
|
+
};
|
|
1074
|
+
if (rectContains(rect, x, y)) {
|
|
1075
|
+
return { kind: "event", event, rowId, rect };
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
const statics = cullToWindow(
|
|
1079
|
+
scene.getRowStaticEvents(rowId),
|
|
1080
|
+
windowStart,
|
|
1081
|
+
windowEnd
|
|
1164
1082
|
);
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
var ResizeIcon = () => {
|
|
1179
|
-
return /* @__PURE__ */ React8.createElement("div", { style: { display: "flex", gap: "1px" } }, /* @__PURE__ */ React8.createElement("div", { className: "resize-bar" }), /* @__PURE__ */ React8.createElement("div", { className: "resize-bar" }));
|
|
1083
|
+
for (let i = statics.length - 1; i >= 0; i--) {
|
|
1084
|
+
const event = statics[i];
|
|
1085
|
+
const rect = {
|
|
1086
|
+
x: timeToX(event.startTime, windowStart, tick),
|
|
1087
|
+
y: rowY + LANE_TOP_OFFSET,
|
|
1088
|
+
width: timeToWidth(event.startTime, event.endTime, tick),
|
|
1089
|
+
height: staticEventHeight(lanes.highestLane)
|
|
1090
|
+
};
|
|
1091
|
+
if (rectContains(rect, x, y)) {
|
|
1092
|
+
return { kind: "static", event, rowId, rect };
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
return null;
|
|
1180
1096
|
};
|
|
1181
|
-
var resize_icon_default = ResizeIcon;
|
|
1182
1097
|
|
|
1183
|
-
// src/
|
|
1184
|
-
var
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1098
|
+
// src/hooks/use-canvas-interactions.ts
|
|
1099
|
+
var DRAG_THRESHOLD_PX = 3;
|
|
1100
|
+
var RESIZE_HOT_ZONE_PX = 8;
|
|
1101
|
+
var lockCursor = (cursor) => {
|
|
1102
|
+
const style = document.createElement("style");
|
|
1103
|
+
style.id = "lock-cursor";
|
|
1104
|
+
style.innerHTML = `* { cursor: ${cursor} !important; }`;
|
|
1105
|
+
document.head.appendChild(style);
|
|
1106
|
+
};
|
|
1107
|
+
var unlockCursor = () => {
|
|
1108
|
+
var _a;
|
|
1109
|
+
(_a = document.getElementById("lock-cursor")) == null ? void 0 : _a.remove();
|
|
1110
|
+
};
|
|
1111
|
+
var useCanvasInteractions = ({
|
|
1112
|
+
scene,
|
|
1113
|
+
rendererRef,
|
|
1114
|
+
dynamicCanvasRef,
|
|
1115
|
+
bodyRef,
|
|
1116
|
+
ghostRef,
|
|
1117
|
+
eventPromptRef,
|
|
1118
|
+
setWindowTime,
|
|
1119
|
+
setCellWidth,
|
|
1120
|
+
onDrop,
|
|
1121
|
+
onResize,
|
|
1122
|
+
onEventClick,
|
|
1123
|
+
onEventHover,
|
|
1124
|
+
eventsResize,
|
|
1125
|
+
panZoom
|
|
1191
1126
|
}) => {
|
|
1192
|
-
|
|
1193
|
-
const
|
|
1194
|
-
const
|
|
1195
|
-
|
|
1127
|
+
const stateRef = useRef5({ mode: "idle" });
|
|
1128
|
+
const changeGridRef = useRef5(false);
|
|
1129
|
+
const panFrameRef = useRef5(null);
|
|
1130
|
+
const panPendingDxRef = useRef5(0);
|
|
1131
|
+
const hoveredRef = useRef5(null);
|
|
1132
|
+
const config = useMemo3(
|
|
1133
|
+
() => {
|
|
1134
|
+
var _a, _b, _c, _d;
|
|
1135
|
+
return {
|
|
1136
|
+
panOnDragBackground: (_a = panZoom == null ? void 0 : panZoom.panOnDragBackground) != null ? _a : true,
|
|
1137
|
+
ctrlWheelZoom: (_b = panZoom == null ? void 0 : panZoom.ctrlWheelZoom) != null ? _b : true,
|
|
1138
|
+
middleClickGranularity: (_c = panZoom == null ? void 0 : panZoom.middleClickGranularity) != null ? _c : true,
|
|
1139
|
+
zoomStepSeconds: (_d = panZoom == null ? void 0 : panZoom.zoomStepSeconds) != null ? _d : 900
|
|
1140
|
+
};
|
|
1141
|
+
},
|
|
1142
|
+
[panZoom]
|
|
1196
1143
|
);
|
|
1197
|
-
const
|
|
1198
|
-
|
|
1199
|
-
(
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
const
|
|
1204
|
-
|
|
1205
|
-
if (
|
|
1206
|
-
|
|
1144
|
+
const hidePrompt = useCallback(() => {
|
|
1145
|
+
var _a;
|
|
1146
|
+
(_a = eventPromptRef.current) == null ? void 0 : _a.hide();
|
|
1147
|
+
}, [eventPromptRef]);
|
|
1148
|
+
const currentHit = useCallback(
|
|
1149
|
+
(clientX, clientY) => {
|
|
1150
|
+
const canvas = dynamicCanvasRef.current;
|
|
1151
|
+
const renderer = rendererRef.current;
|
|
1152
|
+
if (!canvas || !renderer) return null;
|
|
1153
|
+
const view = renderer.getView();
|
|
1154
|
+
if (view.tick === null) return null;
|
|
1155
|
+
const rect = canvas.getBoundingClientRect();
|
|
1156
|
+
return hitTest(
|
|
1157
|
+
scene,
|
|
1158
|
+
{
|
|
1159
|
+
windowStart: view.windowTime[0],
|
|
1160
|
+
windowEnd: view.windowTime[1],
|
|
1161
|
+
tick: view.tick,
|
|
1162
|
+
scrollTop: view.scrollTop
|
|
1163
|
+
},
|
|
1164
|
+
clientX - rect.left,
|
|
1165
|
+
clientY - rect.top
|
|
1166
|
+
);
|
|
1167
|
+
},
|
|
1168
|
+
[scene, dynamicCanvasRef, rendererRef]
|
|
1169
|
+
);
|
|
1170
|
+
const resizeDirectionAt = useCallback(
|
|
1171
|
+
(hit, clientX) => {
|
|
1172
|
+
if (hit.kind !== "event" || !canResizeEvent(hit.event, eventsResize)) {
|
|
1173
|
+
return null;
|
|
1207
1174
|
}
|
|
1175
|
+
const canvas = dynamicCanvasRef.current;
|
|
1176
|
+
if (!canvas) return null;
|
|
1177
|
+
const x = clientX - canvas.getBoundingClientRect().left;
|
|
1178
|
+
const zone = Math.min(RESIZE_HOT_ZONE_PX, hit.rect.width / 3);
|
|
1179
|
+
if (x <= hit.rect.x + zone) return "left";
|
|
1180
|
+
if (x >= hit.rect.x + hit.rect.width - zone) return "right";
|
|
1181
|
+
return null;
|
|
1208
1182
|
},
|
|
1209
|
-
[
|
|
1183
|
+
[dynamicCanvasRef, eventsResize]
|
|
1210
1184
|
);
|
|
1211
|
-
const
|
|
1212
|
-
(
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
const
|
|
1216
|
-
|
|
1185
|
+
const schedulePan = useCallback(() => {
|
|
1186
|
+
if (panFrameRef.current !== null) return;
|
|
1187
|
+
panFrameRef.current = requestAnimationFrame(() => {
|
|
1188
|
+
panFrameRef.current = null;
|
|
1189
|
+
const renderer = rendererRef.current;
|
|
1190
|
+
const dx = panPendingDxRef.current;
|
|
1191
|
+
panPendingDxRef.current = 0;
|
|
1192
|
+
const tick = renderer == null ? void 0 : renderer.getView().tick;
|
|
1193
|
+
if (!tick || dx === 0) return;
|
|
1194
|
+
const dt = Math.round(dx * tick);
|
|
1195
|
+
if (dt === 0) {
|
|
1196
|
+
panPendingDxRef.current = dx;
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
setWindowTime((prev) => [prev[0] - dt, prev[1] - dt]);
|
|
1200
|
+
});
|
|
1201
|
+
}, [rendererRef, setWindowTime]);
|
|
1202
|
+
const updateGhost = useCallback(
|
|
1203
|
+
(state, clientX, clientY) => {
|
|
1204
|
+
const ghost = ghostRef.current;
|
|
1205
|
+
if (!ghost) return;
|
|
1206
|
+
ghost.style.display = "flex";
|
|
1207
|
+
ghost.style.left = `${state.hit.rect.x + (clientX - state.startClientX)}px`;
|
|
1208
|
+
ghost.style.top = `${state.hit.rect.y + (clientY - state.startClientY)}px`;
|
|
1209
|
+
ghost.style.width = `${state.hit.rect.width}px`;
|
|
1217
1210
|
},
|
|
1218
|
-
[
|
|
1211
|
+
[ghostRef]
|
|
1219
1212
|
);
|
|
1220
|
-
const
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1213
|
+
const handlePointerDown = useCallback(
|
|
1214
|
+
(pointerEvent) => {
|
|
1215
|
+
var _a;
|
|
1216
|
+
if (pointerEvent.button !== 0) return;
|
|
1217
|
+
const canvas = dynamicCanvasRef.current;
|
|
1218
|
+
if (!canvas) return;
|
|
1219
|
+
const hit = currentHit(pointerEvent.clientX, pointerEvent.clientY);
|
|
1220
|
+
if ((hit == null ? void 0 : hit.kind) === "event" && !((_a = hit.event.props) == null ? void 0 : _a.isLocked)) {
|
|
1221
|
+
const direction = resizeDirectionAt(hit, pointerEvent.clientX);
|
|
1222
|
+
if (direction) {
|
|
1223
|
+
stateRef.current = {
|
|
1224
|
+
mode: "resize",
|
|
1225
|
+
event: hit.event,
|
|
1226
|
+
direction,
|
|
1227
|
+
startClientX: pointerEvent.clientX,
|
|
1228
|
+
deltaPx: 0
|
|
1229
|
+
};
|
|
1230
|
+
lockCursor("e-resize");
|
|
1231
|
+
} else {
|
|
1232
|
+
stateRef.current = {
|
|
1233
|
+
mode: "drag",
|
|
1234
|
+
hit,
|
|
1235
|
+
startClientX: pointerEvent.clientX,
|
|
1236
|
+
startClientY: pointerEvent.clientY,
|
|
1237
|
+
active: false
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
} else if (config.panOnDragBackground) {
|
|
1241
|
+
stateRef.current = { mode: "pan", lastClientX: pointerEvent.clientX };
|
|
1242
|
+
canvas.style.cursor = "grabbing";
|
|
1243
|
+
} else {
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
hidePrompt();
|
|
1247
|
+
canvas.setPointerCapture(pointerEvent.pointerId);
|
|
1232
1248
|
},
|
|
1233
|
-
[
|
|
1249
|
+
[currentHit, resizeDirectionAt, dynamicCanvasRef, hidePrompt, config]
|
|
1234
1250
|
);
|
|
1235
|
-
const
|
|
1236
|
-
(
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1251
|
+
const handleHover = useCallback(
|
|
1252
|
+
(pointerEvent) => {
|
|
1253
|
+
var _a, _b, _c, _d;
|
|
1254
|
+
const canvas = dynamicCanvasRef.current;
|
|
1255
|
+
if (!canvas) return;
|
|
1256
|
+
const hit = currentHit(pointerEvent.clientX, pointerEvent.clientY);
|
|
1257
|
+
const prevHovered = hoveredRef.current;
|
|
1258
|
+
hoveredRef.current = hit;
|
|
1259
|
+
if ((hit == null ? void 0 : hit.kind) === "event") {
|
|
1260
|
+
if ((_a = hit.event.props) == null ? void 0 : _a.isLocked) {
|
|
1261
|
+
canvas.style.cursor = "not-allowed";
|
|
1262
|
+
} else if (resizeDirectionAt(hit, pointerEvent.clientX)) {
|
|
1263
|
+
canvas.style.cursor = "e-resize";
|
|
1264
|
+
} else {
|
|
1265
|
+
canvas.style.cursor = "pointer";
|
|
1266
|
+
}
|
|
1267
|
+
} else {
|
|
1268
|
+
canvas.style.cursor = "grab";
|
|
1269
|
+
}
|
|
1270
|
+
const hoveredId = (hit == null ? void 0 : hit.kind) === "event" ? hit.event.id : null;
|
|
1271
|
+
const prevId = (prevHovered == null ? void 0 : prevHovered.kind) === "event" ? prevHovered.event.id : null;
|
|
1272
|
+
if (hoveredId !== prevId) {
|
|
1273
|
+
(_b = rendererRef.current) == null ? void 0 : _b.setView({ hoveredEventId: hoveredId });
|
|
1274
|
+
if (onEventHover) {
|
|
1275
|
+
onEventHover({
|
|
1276
|
+
eventId: hoveredId,
|
|
1277
|
+
rowId: hoveredId !== null && hit ? hit.rowId : null
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
const prompt = eventPromptRef.current;
|
|
1282
|
+
if (!prompt) return;
|
|
1283
|
+
if ((hit == null ? void 0 : hit.kind) === "event" && (((_c = hit.event.props) == null ? void 0 : _c.showPrompt) || ((_d = hit.event.props) == null ? void 0 : _d.showPrompt) === void 0)) {
|
|
1284
|
+
if (prevId !== hit.event.id) {
|
|
1285
|
+
const canvasRect = canvas.getBoundingClientRect();
|
|
1286
|
+
prompt.show(hit.event, {
|
|
1287
|
+
x: canvasRect.left + hit.rect.x,
|
|
1288
|
+
y: canvasRect.top + hit.rect.y,
|
|
1289
|
+
width: hit.rect.width,
|
|
1290
|
+
height: hit.rect.height
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
} else {
|
|
1294
|
+
prompt.hide();
|
|
1246
1295
|
}
|
|
1247
|
-
setEvents(
|
|
1248
|
-
produce((draft) => {
|
|
1249
|
-
const event2 = draft.find((event3) => event3.id === eventData.id);
|
|
1250
|
-
if (event2 && tick) {
|
|
1251
|
-
if (resizeDirection === "left") {
|
|
1252
|
-
const newStartTime = Math.round(
|
|
1253
|
-
event2.startTime + resizeOffsetRef.current * tick
|
|
1254
|
-
);
|
|
1255
|
-
if (event2.endTime - newStartTime > 0) {
|
|
1256
|
-
event2.startTime = newStartTime;
|
|
1257
|
-
}
|
|
1258
|
-
} else {
|
|
1259
|
-
const newEndTime = Math.round(
|
|
1260
|
-
event2.endTime + resizeOffsetRef.current * tick
|
|
1261
|
-
);
|
|
1262
|
-
if (newEndTime - event2.startTime > 0) {
|
|
1263
|
-
event2.endTime = newEndTime;
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
if (onResize) {
|
|
1267
|
-
onResize({
|
|
1268
|
-
eventId: event2.id,
|
|
1269
|
-
startTime: event2.startTime,
|
|
1270
|
-
endTime: event2.endTime
|
|
1271
|
-
});
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
draft.sort(sort_events_default);
|
|
1275
|
-
resizeOffsetRef.current = 0;
|
|
1276
|
-
setResizeOffset(0);
|
|
1277
|
-
})
|
|
1278
|
-
);
|
|
1279
1296
|
},
|
|
1280
1297
|
[
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1298
|
+
currentHit,
|
|
1299
|
+
resizeDirectionAt,
|
|
1300
|
+
dynamicCanvasRef,
|
|
1301
|
+
eventPromptRef,
|
|
1302
|
+
rendererRef,
|
|
1303
|
+
onEventHover
|
|
1286
1304
|
]
|
|
1287
1305
|
);
|
|
1288
|
-
const
|
|
1289
|
-
(
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
{ once: true }
|
|
1302
|
-
);
|
|
1303
|
-
initialPositionForResizeRef.current = event.clientX;
|
|
1304
|
-
},
|
|
1305
|
-
[handleDocumentOnMouseMoveResize, handleDocumentOnMouseUp]
|
|
1306
|
-
);
|
|
1307
|
-
const handleOnMouseMove = useCallback3(
|
|
1308
|
-
(event) => {
|
|
1309
|
-
if (!resizeStarted) {
|
|
1310
|
-
event.stopPropagation();
|
|
1306
|
+
const handlePointerMove = useCallback(
|
|
1307
|
+
(pointerEvent) => {
|
|
1308
|
+
var _a, _b;
|
|
1309
|
+
const state = stateRef.current;
|
|
1310
|
+
if (state.mode === "idle") {
|
|
1311
|
+
handleHover(pointerEvent);
|
|
1312
|
+
return;
|
|
1313
|
+
}
|
|
1314
|
+
if (state.mode === "pan") {
|
|
1315
|
+
panPendingDxRef.current += pointerEvent.clientX - state.lastClientX;
|
|
1316
|
+
state.lastClientX = pointerEvent.clientX;
|
|
1317
|
+
schedulePan();
|
|
1318
|
+
return;
|
|
1311
1319
|
}
|
|
1320
|
+
if (state.mode === "drag") {
|
|
1321
|
+
if (!state.active && Math.abs(pointerEvent.clientX - state.startClientX) + Math.abs(pointerEvent.clientY - state.startClientY) > DRAG_THRESHOLD_PX) {
|
|
1322
|
+
state.active = true;
|
|
1323
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: state.hit.event.id });
|
|
1324
|
+
}
|
|
1325
|
+
if (state.active) {
|
|
1326
|
+
updateGhost(state, pointerEvent.clientX, pointerEvent.clientY);
|
|
1327
|
+
}
|
|
1328
|
+
return;
|
|
1329
|
+
}
|
|
1330
|
+
state.deltaPx = pointerEvent.clientX - state.startClientX;
|
|
1331
|
+
(_b = rendererRef.current) == null ? void 0 : _b.setView({
|
|
1332
|
+
resizePreview: {
|
|
1333
|
+
eventId: state.event.id,
|
|
1334
|
+
deltaPx: state.deltaPx,
|
|
1335
|
+
direction: state.direction
|
|
1336
|
+
}
|
|
1337
|
+
});
|
|
1312
1338
|
},
|
|
1313
|
-
[
|
|
1339
|
+
[handleHover, schedulePan, updateGhost, rendererRef]
|
|
1314
1340
|
);
|
|
1315
|
-
const
|
|
1316
|
-
(
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
if (
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1341
|
+
const commitDrop = useCallback(
|
|
1342
|
+
(state, clientX, clientY) => {
|
|
1343
|
+
const canvas = dynamicCanvasRef.current;
|
|
1344
|
+
const renderer = rendererRef.current;
|
|
1345
|
+
if (!canvas || !renderer) return;
|
|
1346
|
+
const view = renderer.getView();
|
|
1347
|
+
if (view.tick === null || view.cellWidth <= 0) return;
|
|
1348
|
+
const canvasRect = canvas.getBoundingClientRect();
|
|
1349
|
+
const yContent = clientY - canvasRect.top + view.scrollTop;
|
|
1350
|
+
let rowTop = 0;
|
|
1351
|
+
let targetRowId = null;
|
|
1352
|
+
for (const id of scene.getRowIds()) {
|
|
1353
|
+
const height = scene.getRowHeight(
|
|
1354
|
+
id,
|
|
1355
|
+
view.windowTime[0],
|
|
1356
|
+
view.windowTime[1]
|
|
1357
|
+
);
|
|
1358
|
+
if (yContent >= rowTop && yContent < rowTop + height) {
|
|
1359
|
+
targetRowId = id;
|
|
1360
|
+
break;
|
|
1330
1361
|
}
|
|
1362
|
+
rowTop += height;
|
|
1331
1363
|
}
|
|
1364
|
+
if (targetRowId === null) return;
|
|
1365
|
+
const liveEvent = scene.getEvent(state.hit.event.id);
|
|
1366
|
+
if (!liveEvent) return;
|
|
1367
|
+
const { startTime, endTime } = computeDropTimes({
|
|
1368
|
+
pointerX: clientX - canvasRect.left,
|
|
1369
|
+
cellWidth: view.cellWidth,
|
|
1370
|
+
tick: view.tick,
|
|
1371
|
+
windowStart: view.windowTime[0],
|
|
1372
|
+
duration: liveEvent.endTime - liveEvent.startTime
|
|
1373
|
+
});
|
|
1374
|
+
if (onDrop) {
|
|
1375
|
+
onDrop({
|
|
1376
|
+
eventId: liveEvent.id,
|
|
1377
|
+
oldRowId: liveEvent.rowId,
|
|
1378
|
+
newRowId: targetRowId,
|
|
1379
|
+
startTime,
|
|
1380
|
+
endTime
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
renderer.animator.snapEventTop(liveEvent.id);
|
|
1384
|
+
scene.applyPatches([
|
|
1385
|
+
{
|
|
1386
|
+
op: "update",
|
|
1387
|
+
id: liveEvent.id,
|
|
1388
|
+
changes: { startTime, endTime, rowId: targetRowId }
|
|
1389
|
+
}
|
|
1390
|
+
]);
|
|
1332
1391
|
},
|
|
1333
|
-
[
|
|
1392
|
+
[scene, dynamicCanvasRef, rendererRef, onDrop]
|
|
1334
1393
|
);
|
|
1335
|
-
const
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1394
|
+
const commitResize = useCallback(
|
|
1395
|
+
(state) => {
|
|
1396
|
+
const renderer = rendererRef.current;
|
|
1397
|
+
const tick = renderer == null ? void 0 : renderer.getView().tick;
|
|
1398
|
+
renderer == null ? void 0 : renderer.setView({ resizePreview: null });
|
|
1399
|
+
unlockCursor();
|
|
1400
|
+
if (!tick) return;
|
|
1401
|
+
const liveEvent = scene.getEvent(state.event.id);
|
|
1402
|
+
if (!liveEvent) return;
|
|
1403
|
+
const next = computeResizeTimes(
|
|
1404
|
+
liveEvent,
|
|
1405
|
+
state.deltaPx,
|
|
1406
|
+
tick,
|
|
1407
|
+
state.direction
|
|
1408
|
+
);
|
|
1409
|
+
if (next) {
|
|
1410
|
+
scene.applyPatches([
|
|
1411
|
+
{ op: "update", id: liveEvent.id, changes: next }
|
|
1412
|
+
]);
|
|
1413
|
+
}
|
|
1414
|
+
if (onResize) {
|
|
1415
|
+
const committed = next != null ? next : {
|
|
1416
|
+
startTime: liveEvent.startTime,
|
|
1417
|
+
endTime: liveEvent.endTime
|
|
1418
|
+
};
|
|
1419
|
+
onResize(__spreadValues({ eventId: liveEvent.id }, committed));
|
|
1358
1420
|
}
|
|
1359
1421
|
},
|
|
1360
|
-
|
|
1361
|
-
"div",
|
|
1362
|
-
{
|
|
1363
|
-
className: "event-resize",
|
|
1364
|
-
style: resizeStarted ? { opacity: "100%" } : void 0,
|
|
1365
|
-
draggable: false,
|
|
1366
|
-
onMouseEnter: () => setDraggableEvent(false),
|
|
1367
|
-
onMouseLeave: () => setDraggableEvent(true),
|
|
1368
|
-
onMouseDown: (event) => handleOnMouseDownEventResizer(event, "left"),
|
|
1369
|
-
onMouseOver: (event) => event.stopPropagation()
|
|
1370
|
-
},
|
|
1371
|
-
/* @__PURE__ */ React9.createElement(resize_icon_default, null)
|
|
1372
|
-
),
|
|
1373
|
-
/* @__PURE__ */ React9.createElement("div", { className: "event-content", onMouseOver: handleOnMouseOver }, ((_h = eventData.props) == null ? void 0 : _h.content) ? eventData.props.content : null),
|
|
1374
|
-
!((_i = eventData.props) == null ? void 0 : _i.isLocked) && (eventsResize && (((_j = eventData.props) == null ? void 0 : _j.isResizable) === true || ((_k = eventData.props) == null ? void 0 : _k.isResizable) === void 0) || !eventsResize && ((_l = eventData.props) == null ? void 0 : _l.isResizable)) && /* @__PURE__ */ React9.createElement(
|
|
1375
|
-
"div",
|
|
1376
|
-
{
|
|
1377
|
-
className: "event-resize",
|
|
1378
|
-
style: resizeStarted ? { opacity: "100%" } : void 0,
|
|
1379
|
-
draggable: false,
|
|
1380
|
-
onMouseEnter: () => setDraggableEvent(false),
|
|
1381
|
-
onMouseLeave: () => setDraggableEvent(true),
|
|
1382
|
-
onMouseDown: (event) => handleOnMouseDownEventResizer(event, "right"),
|
|
1383
|
-
onMouseOver: (event) => event.stopPropagation()
|
|
1384
|
-
},
|
|
1385
|
-
/* @__PURE__ */ React9.createElement(resize_icon_default, null)
|
|
1386
|
-
)
|
|
1422
|
+
[scene, rendererRef, onResize]
|
|
1387
1423
|
);
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
}) => {
|
|
1397
|
-
const callback = useCallback4((entries) => {
|
|
1398
|
-
entries.forEach((entry) => {
|
|
1399
|
-
if (entry.isIntersecting) {
|
|
1400
|
-
entry.target.classList.remove("row-hidden");
|
|
1401
|
-
} else {
|
|
1402
|
-
entry.target.classList.add("row-hidden");
|
|
1424
|
+
const handlePointerUp = useCallback(
|
|
1425
|
+
(pointerEvent) => {
|
|
1426
|
+
var _a;
|
|
1427
|
+
const canvas = dynamicCanvasRef.current;
|
|
1428
|
+
const state = stateRef.current;
|
|
1429
|
+
stateRef.current = { mode: "idle" };
|
|
1430
|
+
if (canvas == null ? void 0 : canvas.hasPointerCapture(pointerEvent.pointerId)) {
|
|
1431
|
+
canvas.releasePointerCapture(pointerEvent.pointerId);
|
|
1403
1432
|
}
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
// src/hooks/use-produce-content.tsx
|
|
1421
|
-
var useProduceContent = ({
|
|
1422
|
-
rows,
|
|
1423
|
-
windowTime,
|
|
1424
|
-
tick,
|
|
1425
|
-
events,
|
|
1426
|
-
staticEvents,
|
|
1427
|
-
cellWidth,
|
|
1428
|
-
setEvents,
|
|
1429
|
-
bodyRef
|
|
1430
|
-
}) => {
|
|
1431
|
-
const rowsHeightContext = useContext5(RowsHeightContext);
|
|
1432
|
-
const tempRowsHeightRef = useRef4(null);
|
|
1433
|
-
const rowsContentRef = useRef4([]);
|
|
1434
|
-
const [content, internalAllRowsHeight] = useMemo5(() => {
|
|
1435
|
-
let internalAllRowsHeight2 = 0;
|
|
1436
|
-
return [
|
|
1437
|
-
rows.map((row, i) => {
|
|
1438
|
-
let eventOrder = 0;
|
|
1439
|
-
let prevEvent = [];
|
|
1440
|
-
let highestEventOrder = 0;
|
|
1441
|
-
const rowEvents = tick ? events.filter((event) => event.rowId === row.id).map((event) => {
|
|
1442
|
-
if (event.endTime >= windowTime[0] && event.startTime <= windowTime[1]) {
|
|
1443
|
-
let tempEventOrder = 0;
|
|
1444
|
-
let assignEventOrder = true;
|
|
1445
|
-
for (let i2 = 0; i2 <= eventOrder; i2++) {
|
|
1446
|
-
if (prevEvent && prevEvent[i2] && prevEvent[i2].endTime > event.startTime) {
|
|
1447
|
-
tempEventOrder += 1;
|
|
1448
|
-
} else {
|
|
1449
|
-
if (eventOrder > highestEventOrder) {
|
|
1450
|
-
highestEventOrder = eventOrder;
|
|
1451
|
-
}
|
|
1452
|
-
eventOrder = 0;
|
|
1453
|
-
assignEventOrder = false;
|
|
1454
|
-
break;
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
if (assignEventOrder) {
|
|
1458
|
-
eventOrder = tempEventOrder;
|
|
1433
|
+
if (canvas) canvas.style.cursor = "grab";
|
|
1434
|
+
if (state.mode === "drag" && state.active) {
|
|
1435
|
+
if (ghostRef.current) ghostRef.current.style.display = "none";
|
|
1436
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null });
|
|
1437
|
+
commitDrop(state, pointerEvent.clientX, pointerEvent.clientY);
|
|
1438
|
+
} else if (state.mode === "drag" && !state.active) {
|
|
1439
|
+
if (onEventClick) {
|
|
1440
|
+
onEventClick({
|
|
1441
|
+
eventId: state.hit.event.id,
|
|
1442
|
+
rowId: state.hit.rowId,
|
|
1443
|
+
nativeEvent: pointerEvent.nativeEvent,
|
|
1444
|
+
modifiers: {
|
|
1445
|
+
shift: pointerEvent.shiftKey,
|
|
1446
|
+
ctrl: pointerEvent.ctrlKey,
|
|
1447
|
+
meta: pointerEvent.metaKey,
|
|
1448
|
+
alt: pointerEvent.altKey
|
|
1459
1449
|
}
|
|
1460
|
-
|
|
1461
|
-
return /* @__PURE__ */ React10.createElement(
|
|
1462
|
-
event_default,
|
|
1463
|
-
{
|
|
1464
|
-
key: `event_${event.id}`,
|
|
1465
|
-
eventData: event,
|
|
1466
|
-
startPosition: (event.startTime - windowTime[0]) / tick,
|
|
1467
|
-
width: (event.endTime - event.startTime) / tick,
|
|
1468
|
-
top: 10 + 22 * tempEventOrder,
|
|
1469
|
-
setEvents,
|
|
1470
|
-
tick
|
|
1471
|
-
}
|
|
1472
|
-
);
|
|
1473
|
-
}
|
|
1474
|
-
}) : null;
|
|
1475
|
-
if (eventOrder > highestEventOrder) {
|
|
1476
|
-
highestEventOrder = eventOrder;
|
|
1477
|
-
}
|
|
1478
|
-
if (tempRowsHeightRef.current === null) {
|
|
1479
|
-
tempRowsHeightRef.current = {
|
|
1480
|
-
[row.id]: { minHeight: 40 + highestEventOrder * 22 }
|
|
1481
|
-
};
|
|
1482
|
-
} else {
|
|
1483
|
-
tempRowsHeightRef.current[row.id] = {
|
|
1484
|
-
minHeight: 40 + highestEventOrder * 22
|
|
1485
|
-
};
|
|
1450
|
+
});
|
|
1486
1451
|
}
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
id: row.id,
|
|
1507
|
-
ref: (el) => {
|
|
1508
|
-
if (rowsContentRef.current && rowsContentRef.current[i] && el) {
|
|
1509
|
-
rowsContentRef.current[i] = el;
|
|
1510
|
-
} else if (rowsContentRef.current && el) {
|
|
1511
|
-
rowsContentRef.current.push(el);
|
|
1512
|
-
}
|
|
1513
|
-
},
|
|
1514
|
-
setEvents,
|
|
1515
|
-
tick,
|
|
1516
|
-
windowTime,
|
|
1517
|
-
cellWidth
|
|
1518
|
-
},
|
|
1519
|
-
rowEvents,
|
|
1520
|
-
rowStaticEvents
|
|
1521
|
-
));
|
|
1522
|
-
}),
|
|
1523
|
-
internalAllRowsHeight2
|
|
1524
|
-
];
|
|
1525
|
-
}, [rows, events, tick, windowTime, cellWidth]);
|
|
1526
|
-
use_intersection_observer_default({
|
|
1527
|
-
rowsContentRef,
|
|
1528
|
-
bodyRef
|
|
1529
|
-
});
|
|
1530
|
-
useEffect2(() => {
|
|
1531
|
-
if (rowsHeightContext) {
|
|
1532
|
-
rowsHeightContext.setRowsHeight(tempRowsHeightRef.current);
|
|
1533
|
-
rowsHeightContext.setAllRowsHeight(internalAllRowsHeight);
|
|
1452
|
+
} else if (state.mode === "resize") {
|
|
1453
|
+
commitResize(state);
|
|
1454
|
+
}
|
|
1455
|
+
},
|
|
1456
|
+
[
|
|
1457
|
+
dynamicCanvasRef,
|
|
1458
|
+
ghostRef,
|
|
1459
|
+
rendererRef,
|
|
1460
|
+
commitDrop,
|
|
1461
|
+
commitResize,
|
|
1462
|
+
onEventClick
|
|
1463
|
+
]
|
|
1464
|
+
);
|
|
1465
|
+
const handlePointerLeave = useCallback(() => {
|
|
1466
|
+
var _a, _b;
|
|
1467
|
+
if (stateRef.current.mode !== "idle") return;
|
|
1468
|
+
if (((_a = hoveredRef.current) == null ? void 0 : _a.kind) === "event") {
|
|
1469
|
+
(_b = rendererRef.current) == null ? void 0 : _b.setView({ hoveredEventId: null });
|
|
1470
|
+
if (onEventHover) onEventHover({ eventId: null, rowId: null });
|
|
1534
1471
|
}
|
|
1535
|
-
|
|
1536
|
-
|
|
1472
|
+
hoveredRef.current = null;
|
|
1473
|
+
if (dynamicCanvasRef.current) {
|
|
1474
|
+
dynamicCanvasRef.current.style.cursor = "";
|
|
1475
|
+
}
|
|
1476
|
+
hidePrompt();
|
|
1477
|
+
}, [dynamicCanvasRef, rendererRef, hidePrompt, onEventHover]);
|
|
1478
|
+
const handleAuxClick = useCallback(
|
|
1479
|
+
(pointerEvent) => {
|
|
1480
|
+
pointerEvent.preventDefault();
|
|
1481
|
+
if (pointerEvent.button === 1 && config.middleClickGranularity) {
|
|
1482
|
+
changeGridRef.current = !changeGridRef.current;
|
|
1483
|
+
if (bodyRef.current) {
|
|
1484
|
+
bodyRef.current.style.overflowY = changeGridRef.current ? "hidden" : "auto";
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
},
|
|
1488
|
+
[bodyRef, config]
|
|
1489
|
+
);
|
|
1490
|
+
useEffect4(() => {
|
|
1491
|
+
const canvas = dynamicCanvasRef.current;
|
|
1492
|
+
if (!canvas) return;
|
|
1493
|
+
const handleWheel = (wheelEvent) => {
|
|
1494
|
+
var _a;
|
|
1495
|
+
const viaCtrl = (wheelEvent.ctrlKey || wheelEvent.metaKey) && config.ctrlWheelZoom;
|
|
1496
|
+
if (!changeGridRef.current && !viaCtrl) return;
|
|
1497
|
+
wheelEvent.preventDefault();
|
|
1498
|
+
const tick = (_a = rendererRef.current) == null ? void 0 : _a.getView().tick;
|
|
1499
|
+
if (!tick) return;
|
|
1500
|
+
setCellWidth(
|
|
1501
|
+
(cellWidth) => stepCellWidth(
|
|
1502
|
+
cellWidth,
|
|
1503
|
+
wheelEvent.deltaY,
|
|
1504
|
+
tick * 900 / config.zoomStepSeconds
|
|
1505
|
+
)
|
|
1506
|
+
);
|
|
1507
|
+
};
|
|
1508
|
+
canvas.addEventListener("wheel", handleWheel, { passive: false });
|
|
1509
|
+
return () => canvas.removeEventListener("wheel", handleWheel);
|
|
1510
|
+
}, [dynamicCanvasRef, rendererRef, setCellWidth, config]);
|
|
1511
|
+
useEffect4(() => unlockCursor, []);
|
|
1512
|
+
return {
|
|
1513
|
+
handlePointerDown,
|
|
1514
|
+
handlePointerMove,
|
|
1515
|
+
handlePointerUp,
|
|
1516
|
+
handlePointerLeave,
|
|
1517
|
+
handleAuxClick
|
|
1518
|
+
};
|
|
1537
1519
|
};
|
|
1538
|
-
var
|
|
1520
|
+
var use_canvas_interactions_default = useCanvasInteractions;
|
|
1539
1521
|
|
|
1540
|
-
// src/components/
|
|
1541
|
-
var
|
|
1522
|
+
// src/components/canvas-board.tsx
|
|
1523
|
+
var CanvasBoard = forwardRef2(
|
|
1542
1524
|
({
|
|
1525
|
+
scene,
|
|
1543
1526
|
rows,
|
|
1544
|
-
events,
|
|
1545
|
-
staticEvents,
|
|
1546
|
-
setEvents,
|
|
1547
|
-
tick,
|
|
1548
1527
|
windowTime,
|
|
1528
|
+
tick,
|
|
1549
1529
|
cellWidth,
|
|
1530
|
+
theme,
|
|
1531
|
+
drawEvent,
|
|
1532
|
+
bodyRef,
|
|
1533
|
+
rendererRef,
|
|
1534
|
+
eventPromptRef,
|
|
1535
|
+
rowsHeaderClassName,
|
|
1550
1536
|
setWindowTime,
|
|
1551
|
-
contentWidth,
|
|
1552
1537
|
setCellWidth,
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
const
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
const { left } = element.getBoundingClientRect();
|
|
1595
|
-
startMovePosition.current = event.clientX - left;
|
|
1596
|
-
},
|
|
1597
|
-
[setMouseDown]
|
|
1598
|
-
);
|
|
1599
|
-
const handleOnMouseUp = useCallback5(() => {
|
|
1600
|
-
setMouseDown(false);
|
|
1601
|
-
}, [setMouseDown]);
|
|
1602
|
-
const handleOnMouseLeave = useCallback5(
|
|
1603
|
-
() => setMouseDown(false),
|
|
1604
|
-
[setMouseDown]
|
|
1605
|
-
);
|
|
1606
|
-
const content = use_produce_content_default({
|
|
1607
|
-
rows,
|
|
1538
|
+
onDrop,
|
|
1539
|
+
onResize,
|
|
1540
|
+
onEventClick,
|
|
1541
|
+
onEventHover,
|
|
1542
|
+
eventsResize,
|
|
1543
|
+
panZoom,
|
|
1544
|
+
animations
|
|
1545
|
+
}, contentRef) => {
|
|
1546
|
+
const staticCanvasRef = useRef6(null);
|
|
1547
|
+
const dynamicCanvasRef = useRef6(null);
|
|
1548
|
+
const ghostRef = useRef6(null);
|
|
1549
|
+
const [scrollTop, setScrollTop] = useState3(0);
|
|
1550
|
+
const [viewportHeight, setViewportHeight] = useState3(0);
|
|
1551
|
+
useEffect5(() => {
|
|
1552
|
+
if (!staticCanvasRef.current || !dynamicCanvasRef.current) return;
|
|
1553
|
+
const renderer = new TimelineRenderer(
|
|
1554
|
+
staticCanvasRef.current,
|
|
1555
|
+
dynamicCanvasRef.current,
|
|
1556
|
+
scene
|
|
1557
|
+
);
|
|
1558
|
+
rendererRef.current = renderer;
|
|
1559
|
+
return () => {
|
|
1560
|
+
renderer.dispose();
|
|
1561
|
+
rendererRef.current = null;
|
|
1562
|
+
};
|
|
1563
|
+
}, [scene, rendererRef]);
|
|
1564
|
+
useEffect5(() => {
|
|
1565
|
+
var _a, _b;
|
|
1566
|
+
(_a = rendererRef.current) == null ? void 0 : _a.animator.setDurations(
|
|
1567
|
+
animations.layoutMs,
|
|
1568
|
+
animations.fadeMs
|
|
1569
|
+
);
|
|
1570
|
+
(_b = rendererRef.current) == null ? void 0 : _b.setView({
|
|
1571
|
+
windowTime: [windowTime[0], windowTime[1]],
|
|
1572
|
+
tick,
|
|
1573
|
+
cellWidth,
|
|
1574
|
+
theme,
|
|
1575
|
+
drawEvent,
|
|
1576
|
+
eventsResize
|
|
1577
|
+
});
|
|
1578
|
+
}, [
|
|
1608
1579
|
windowTime,
|
|
1609
1580
|
tick,
|
|
1610
|
-
events,
|
|
1611
|
-
staticEvents,
|
|
1612
1581
|
cellWidth,
|
|
1613
|
-
|
|
1614
|
-
|
|
1582
|
+
theme,
|
|
1583
|
+
drawEvent,
|
|
1584
|
+
eventsResize,
|
|
1585
|
+
animations,
|
|
1586
|
+
rendererRef
|
|
1587
|
+
]);
|
|
1588
|
+
useEffect5(() => {
|
|
1589
|
+
const column = contentRef && "current" in contentRef ? contentRef.current : null;
|
|
1590
|
+
const body = bodyRef.current;
|
|
1591
|
+
if (!column || !body) return;
|
|
1592
|
+
const measure = () => {
|
|
1593
|
+
var _a;
|
|
1594
|
+
const height = Math.min(body.clientHeight, window.innerHeight);
|
|
1595
|
+
setViewportHeight(height);
|
|
1596
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({
|
|
1597
|
+
width: column.getBoundingClientRect().width,
|
|
1598
|
+
height
|
|
1599
|
+
});
|
|
1600
|
+
};
|
|
1601
|
+
measure();
|
|
1602
|
+
const observer = new ResizeObserver(measure);
|
|
1603
|
+
observer.observe(column);
|
|
1604
|
+
observer.observe(body);
|
|
1605
|
+
return () => observer.disconnect();
|
|
1606
|
+
}, [bodyRef, contentRef, rendererRef]);
|
|
1607
|
+
useEffect5(() => {
|
|
1608
|
+
const body = bodyRef.current;
|
|
1609
|
+
if (!body) return;
|
|
1610
|
+
const handleScroll = () => {
|
|
1611
|
+
var _a;
|
|
1612
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({ scrollTop: body.scrollTop });
|
|
1613
|
+
setScrollTop(body.scrollTop);
|
|
1614
|
+
};
|
|
1615
|
+
body.addEventListener("scroll", handleScroll, { passive: true });
|
|
1616
|
+
return () => body.removeEventListener("scroll", handleScroll);
|
|
1617
|
+
}, [bodyRef, rendererRef]);
|
|
1618
|
+
useSyncExternalStore(
|
|
1619
|
+
useCallback2((listener) => scene.subscribe(listener), [scene]),
|
|
1620
|
+
() => scene.version
|
|
1621
|
+
);
|
|
1622
|
+
const {
|
|
1623
|
+
handlePointerDown,
|
|
1624
|
+
handlePointerMove,
|
|
1625
|
+
handlePointerUp,
|
|
1626
|
+
handlePointerLeave,
|
|
1627
|
+
handleAuxClick
|
|
1628
|
+
} = use_canvas_interactions_default({
|
|
1629
|
+
scene,
|
|
1630
|
+
rendererRef,
|
|
1631
|
+
dynamicCanvasRef,
|
|
1632
|
+
bodyRef,
|
|
1633
|
+
ghostRef,
|
|
1634
|
+
eventPromptRef,
|
|
1635
|
+
setWindowTime,
|
|
1636
|
+
setCellWidth,
|
|
1637
|
+
onDrop,
|
|
1638
|
+
onResize,
|
|
1639
|
+
onEventClick,
|
|
1640
|
+
onEventHover,
|
|
1641
|
+
eventsResize,
|
|
1642
|
+
panZoom
|
|
1615
1643
|
});
|
|
1616
|
-
const
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
if (event.button === 1) {
|
|
1620
|
-
setChangeGrid((prev) => !prev);
|
|
1621
|
-
}
|
|
1622
|
-
},
|
|
1623
|
-
[]
|
|
1644
|
+
const { offsetOf, totalHeight } = scene.getRowOffsets(
|
|
1645
|
+
windowTime[0],
|
|
1646
|
+
windowTime[1]
|
|
1624
1647
|
);
|
|
1625
|
-
const
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1648
|
+
const visibleHeaders = [];
|
|
1649
|
+
for (let i = 0; i < rows.length; i++) {
|
|
1650
|
+
const row = rows[i];
|
|
1651
|
+
const top = offsetOf.get(row.id);
|
|
1652
|
+
const height = scene.getRowHeight(row.id, windowTime[0], windowTime[1]);
|
|
1653
|
+
if (top + height < scrollTop) continue;
|
|
1654
|
+
if (top > scrollTop + viewportHeight) break;
|
|
1655
|
+
visibleHeaders.push(
|
|
1656
|
+
/* @__PURE__ */ React5.createElement(
|
|
1657
|
+
"div",
|
|
1658
|
+
{
|
|
1659
|
+
key: `row_header_${row.id}`,
|
|
1660
|
+
className: "row-header canvas-row-header",
|
|
1661
|
+
style: {
|
|
1662
|
+
top,
|
|
1663
|
+
height,
|
|
1664
|
+
borderBottom: i === rows.length - 1 ? "none" : "1px solid yellow",
|
|
1665
|
+
// keeps the DOM header in step with the canvas layout tween
|
|
1666
|
+
transition: animations.layoutMs > 0 ? `top ${animations.layoutMs}ms ease-in-out, height ${animations.layoutMs}ms ease-in-out` : "none"
|
|
1633
1667
|
}
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1668
|
+
},
|
|
1669
|
+
row.name
|
|
1670
|
+
)
|
|
1671
|
+
);
|
|
1672
|
+
}
|
|
1673
|
+
const headerClassNames = rowsHeaderClassName ? `rows-header-wrapper canvas-rows-header ${rowsHeaderClassName}` : "rows-header-wrapper canvas-rows-header";
|
|
1674
|
+
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("div", { className: headerClassNames, style: { height: totalHeight } }, visibleHeaders), /* @__PURE__ */ React5.createElement("div", { className: "canvas-content-column", ref: contentRef }, /* @__PURE__ */ React5.createElement("div", { className: "canvas-sticky" }, /* @__PURE__ */ React5.createElement("canvas", { ref: staticCanvasRef }), /* @__PURE__ */ React5.createElement(
|
|
1675
|
+
"canvas",
|
|
1676
|
+
{
|
|
1677
|
+
ref: dynamicCanvasRef,
|
|
1678
|
+
onPointerDown: handlePointerDown,
|
|
1679
|
+
onPointerMove: handlePointerMove,
|
|
1680
|
+
onPointerUp: handlePointerUp,
|
|
1681
|
+
onPointerLeave: handlePointerLeave,
|
|
1682
|
+
onAuxClick: handleAuxClick
|
|
1643
1683
|
}
|
|
1644
|
-
},
|
|
1645
|
-
return /* @__PURE__ */ React11.createElement(
|
|
1684
|
+
), /* @__PURE__ */ React5.createElement("div", { ref: ghostRef, className: "event canvas-drag-ghost" })), /* @__PURE__ */ React5.createElement(
|
|
1646
1685
|
"div",
|
|
1647
1686
|
{
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
onMouseUp: handleOnMouseUp,
|
|
1653
|
-
onMouseMove: handleOnMouseMove,
|
|
1654
|
-
onMouseLeave: handleOnMouseLeave,
|
|
1655
|
-
onAuxClick: handleAuxClick,
|
|
1656
|
-
onWheel: handleOnWheel,
|
|
1657
|
-
style: {
|
|
1658
|
-
cursor: mouseDown ? "grabbing" : "grab",
|
|
1659
|
-
height: rowsHeightContext == null ? void 0 : rowsHeightContext.allRowsHeight
|
|
1660
|
-
}
|
|
1661
|
-
},
|
|
1662
|
-
/* @__PURE__ */ React11.createElement(
|
|
1663
|
-
lines_canvas_default,
|
|
1664
|
-
{
|
|
1665
|
-
contentWidth,
|
|
1666
|
-
cellWidth,
|
|
1667
|
-
lineClassName
|
|
1668
|
-
}
|
|
1669
|
-
),
|
|
1670
|
-
content
|
|
1671
|
-
);
|
|
1687
|
+
className: "canvas-scroll-spacer",
|
|
1688
|
+
style: { height: totalHeight }
|
|
1689
|
+
}
|
|
1690
|
+
)));
|
|
1672
1691
|
}
|
|
1673
1692
|
);
|
|
1674
|
-
var
|
|
1693
|
+
var canvas_board_default = CanvasBoard;
|
|
1675
1694
|
|
|
1676
|
-
// src/
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
return new ResizeObserver((entries) => {
|
|
1687
|
-
var _a;
|
|
1688
|
-
for (const entry of entries) {
|
|
1689
|
-
const width = (_a = entry.borderBoxSize) == null ? void 0 : _a[0].inlineSize;
|
|
1690
|
-
if (typeof width === "number" && width !== prevWidthRef.current) {
|
|
1691
|
-
prevWidthRef.current = width;
|
|
1692
|
-
const windowDuration = windowTime[1] - windowTime[0];
|
|
1693
|
-
const numberOfHourBlocks = windowDuration / 3600;
|
|
1694
|
-
setTick(windowDuration / entry.contentRect.width);
|
|
1695
|
-
setCellWidth(entry.contentRect.width / numberOfHourBlocks);
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
});
|
|
1699
|
-
}, [windowTime]);
|
|
1700
|
-
useEffect4(() => {
|
|
1701
|
-
if (contentRef.current) {
|
|
1702
|
-
resizeObserver.observe(contentRef.current, { box: "border-box" });
|
|
1695
|
+
// src/core/scene.ts
|
|
1696
|
+
var binaryInsertIndex = (events, event) => {
|
|
1697
|
+
let lo = 0;
|
|
1698
|
+
let hi = events.length;
|
|
1699
|
+
while (lo < hi) {
|
|
1700
|
+
const mid = lo + hi >> 1;
|
|
1701
|
+
if (sort_events_default(events[mid], event) < 0) {
|
|
1702
|
+
lo = mid + 1;
|
|
1703
|
+
} else {
|
|
1704
|
+
hi = mid;
|
|
1703
1705
|
}
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
+
}
|
|
1707
|
+
return lo;
|
|
1706
1708
|
};
|
|
1707
|
-
var
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
}
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1709
|
+
var SceneStore = class {
|
|
1710
|
+
constructor() {
|
|
1711
|
+
this.rowIndexes = /* @__PURE__ */ new Map();
|
|
1712
|
+
this.rowOrder = [];
|
|
1713
|
+
this.eventRow = /* @__PURE__ */ new Map();
|
|
1714
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
1715
|
+
this.version = 0;
|
|
1716
|
+
}
|
|
1717
|
+
setRows(rows) {
|
|
1718
|
+
const next = /* @__PURE__ */ new Map();
|
|
1719
|
+
for (const row of rows) {
|
|
1720
|
+
const existing = this.rowIndexes.get(row.id);
|
|
1721
|
+
next.set(
|
|
1722
|
+
row.id,
|
|
1723
|
+
existing ? __spreadProps(__spreadValues({}, existing), { row }) : {
|
|
1724
|
+
row,
|
|
1725
|
+
events: [],
|
|
1726
|
+
staticEvents: [],
|
|
1727
|
+
lanesDirty: true,
|
|
1728
|
+
lanes: null,
|
|
1729
|
+
laneWindowStart: NaN,
|
|
1730
|
+
laneWindowEnd: NaN
|
|
1731
|
+
}
|
|
1732
|
+
);
|
|
1733
|
+
}
|
|
1734
|
+
for (const [id, rowId] of this.eventRow) {
|
|
1735
|
+
if (!next.has(rowId)) this.eventRow.delete(id);
|
|
1736
|
+
}
|
|
1737
|
+
this.rowIndexes = next;
|
|
1738
|
+
this.rowOrder = rows.map((row) => row.id);
|
|
1739
|
+
this.bump();
|
|
1740
|
+
}
|
|
1741
|
+
setEvents(events) {
|
|
1742
|
+
for (const index of this.rowIndexes.values()) {
|
|
1743
|
+
index.events = [];
|
|
1744
|
+
index.lanesDirty = true;
|
|
1745
|
+
}
|
|
1746
|
+
this.eventRow.clear();
|
|
1747
|
+
for (const event of events) {
|
|
1748
|
+
const index = this.rowIndexes.get(event.rowId);
|
|
1749
|
+
if (!index) continue;
|
|
1750
|
+
index.events.push(event);
|
|
1751
|
+
this.eventRow.set(event.id, event.rowId);
|
|
1752
|
+
}
|
|
1753
|
+
for (const index of this.rowIndexes.values()) {
|
|
1754
|
+
index.events.sort(sort_events_default);
|
|
1755
|
+
}
|
|
1756
|
+
this.bump();
|
|
1757
|
+
}
|
|
1758
|
+
setStaticEvents(events) {
|
|
1759
|
+
for (const index of this.rowIndexes.values()) {
|
|
1760
|
+
index.staticEvents = [];
|
|
1761
|
+
}
|
|
1762
|
+
for (const event of events) {
|
|
1763
|
+
const index = this.rowIndexes.get(event.rowId);
|
|
1764
|
+
if (!index) continue;
|
|
1765
|
+
index.staticEvents.push(event);
|
|
1766
|
+
}
|
|
1767
|
+
for (const index of this.rowIndexes.values()) {
|
|
1768
|
+
index.staticEvents.sort(sort_events_default);
|
|
1769
|
+
}
|
|
1770
|
+
this.bump();
|
|
1771
|
+
}
|
|
1772
|
+
applyPatches(patches) {
|
|
1773
|
+
for (const patch of patches) {
|
|
1774
|
+
if (patch.op === "upsert") {
|
|
1775
|
+
this.remove(patch.event.id);
|
|
1776
|
+
this.insert(patch.event);
|
|
1777
|
+
} else if (patch.op === "update") {
|
|
1778
|
+
const existing = this.getEvent(patch.id);
|
|
1779
|
+
if (!existing) continue;
|
|
1780
|
+
this.remove(patch.id);
|
|
1781
|
+
this.insert(__spreadProps(__spreadValues(__spreadValues({}, existing), patch.changes), { id: patch.id }));
|
|
1782
|
+
} else {
|
|
1783
|
+
this.remove(patch.id);
|
|
1724
1784
|
}
|
|
1725
|
-
const intervalId = setInterval(() => {
|
|
1726
|
-
setCurrentTime((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
1727
|
-
}, tick * 1e3);
|
|
1728
|
-
intervalIdRef.current = intervalId;
|
|
1729
1785
|
}
|
|
1730
|
-
|
|
1731
|
-
|
|
1786
|
+
this.bump();
|
|
1787
|
+
}
|
|
1788
|
+
getEvent(id) {
|
|
1789
|
+
var _a;
|
|
1790
|
+
const rowId = this.eventRow.get(id);
|
|
1791
|
+
if (rowId === void 0) return void 0;
|
|
1792
|
+
return (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.events.find((event) => event.id === id);
|
|
1793
|
+
}
|
|
1794
|
+
getRowIds() {
|
|
1795
|
+
return this.rowOrder;
|
|
1796
|
+
}
|
|
1797
|
+
getRow(rowId) {
|
|
1798
|
+
var _a;
|
|
1799
|
+
return (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.row;
|
|
1800
|
+
}
|
|
1801
|
+
getRowEvents(rowId) {
|
|
1802
|
+
var _a, _b;
|
|
1803
|
+
return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.events) != null ? _b : [];
|
|
1804
|
+
}
|
|
1805
|
+
getRowStaticEvents(rowId) {
|
|
1806
|
+
var _a, _b;
|
|
1807
|
+
return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.staticEvents) != null ? _b : [];
|
|
1808
|
+
}
|
|
1809
|
+
getLanes(rowId, windowStart, windowEnd) {
|
|
1810
|
+
const index = this.rowIndexes.get(rowId);
|
|
1811
|
+
if (!index) return { laneOf: /* @__PURE__ */ new Map(), highestLane: 0 };
|
|
1812
|
+
if (index.lanesDirty || index.lanes === null || index.laneWindowStart !== windowStart || index.laneWindowEnd !== windowEnd) {
|
|
1813
|
+
index.lanes = assignLanes(index.events, windowStart, windowEnd);
|
|
1814
|
+
index.laneWindowStart = windowStart;
|
|
1815
|
+
index.laneWindowEnd = windowEnd;
|
|
1816
|
+
index.lanesDirty = false;
|
|
1817
|
+
}
|
|
1818
|
+
return index.lanes;
|
|
1819
|
+
}
|
|
1820
|
+
getRowHeight(rowId, windowStart, windowEnd) {
|
|
1821
|
+
return rowMinHeight(this.getLanes(rowId, windowStart, windowEnd).highestLane);
|
|
1822
|
+
}
|
|
1823
|
+
/**
|
|
1824
|
+
* y offset of each row's top edge (content coordinates, before scroll) plus
|
|
1825
|
+
* the total content height — drives both drawing and the scroll spacer.
|
|
1826
|
+
*/
|
|
1827
|
+
getRowOffsets(windowStart, windowEnd) {
|
|
1828
|
+
const offsetOf = /* @__PURE__ */ new Map();
|
|
1829
|
+
let y = 0;
|
|
1830
|
+
for (const rowId of this.rowOrder) {
|
|
1831
|
+
offsetOf.set(rowId, y);
|
|
1832
|
+
y += this.getRowHeight(rowId, windowStart, windowEnd);
|
|
1833
|
+
}
|
|
1834
|
+
return { offsetOf, totalHeight: y };
|
|
1835
|
+
}
|
|
1836
|
+
subscribe(listener) {
|
|
1837
|
+
this.listeners.add(listener);
|
|
1838
|
+
return () => this.listeners.delete(listener);
|
|
1839
|
+
}
|
|
1840
|
+
insert(event) {
|
|
1841
|
+
const index = this.rowIndexes.get(event.rowId);
|
|
1842
|
+
if (!index) return;
|
|
1843
|
+
index.events.splice(binaryInsertIndex(index.events, event), 0, event);
|
|
1844
|
+
index.lanesDirty = true;
|
|
1845
|
+
this.eventRow.set(event.id, event.rowId);
|
|
1846
|
+
}
|
|
1847
|
+
remove(id) {
|
|
1848
|
+
const rowId = this.eventRow.get(id);
|
|
1849
|
+
if (rowId === void 0) return;
|
|
1850
|
+
const index = this.rowIndexes.get(rowId);
|
|
1851
|
+
if (index) {
|
|
1852
|
+
const at = index.events.findIndex((event) => event.id === id);
|
|
1853
|
+
if (at !== -1) index.events.splice(at, 1);
|
|
1854
|
+
index.lanesDirty = true;
|
|
1855
|
+
}
|
|
1856
|
+
this.eventRow.delete(id);
|
|
1857
|
+
}
|
|
1858
|
+
bump() {
|
|
1859
|
+
this.version++;
|
|
1860
|
+
for (const listener of this.listeners) listener();
|
|
1861
|
+
}
|
|
1732
1862
|
};
|
|
1733
|
-
var rt_indicator_default = RTIndicator;
|
|
1734
1863
|
|
|
1735
|
-
// src/
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1864
|
+
// src/timeline.tsx
|
|
1865
|
+
var Timeline = forwardRef3(
|
|
1866
|
+
({
|
|
1867
|
+
rows,
|
|
1868
|
+
events,
|
|
1869
|
+
staticEvents,
|
|
1870
|
+
onDrop,
|
|
1871
|
+
onResize,
|
|
1872
|
+
onEventClick,
|
|
1873
|
+
onEventHover,
|
|
1874
|
+
startDate,
|
|
1875
|
+
endDate,
|
|
1876
|
+
theme,
|
|
1877
|
+
drawEvent,
|
|
1878
|
+
additionalClassNames,
|
|
1879
|
+
showRTIndicator = true,
|
|
1880
|
+
eventsResize = true,
|
|
1881
|
+
eventPromptTemplate,
|
|
1882
|
+
showEventPrompt = true,
|
|
1883
|
+
panZoom,
|
|
1884
|
+
animations = true
|
|
1885
|
+
}, handleRef) => {
|
|
1886
|
+
const [windowTime, setWindowTime] = useState4([
|
|
1887
|
+
new Date(
|
|
1888
|
+
startDate.getFullYear(),
|
|
1889
|
+
startDate.getMonth(),
|
|
1890
|
+
startDate.getDate(),
|
|
1891
|
+
startDate.getHours(),
|
|
1892
|
+
0,
|
|
1893
|
+
0
|
|
1894
|
+
).getTime() / 1e3,
|
|
1895
|
+
new Date(
|
|
1896
|
+
endDate.getFullYear(),
|
|
1897
|
+
endDate.getMonth(),
|
|
1898
|
+
endDate.getDate(),
|
|
1899
|
+
endDate.getHours(),
|
|
1900
|
+
0,
|
|
1901
|
+
0
|
|
1902
|
+
).getTime() / 1e3
|
|
1903
|
+
]);
|
|
1904
|
+
const [cellWidth, setCellWidth] = useState4(0);
|
|
1905
|
+
const contentRef = useRef7(null);
|
|
1906
|
+
const mainRef = useRef7(null);
|
|
1907
|
+
const bodyRef = useRef7(null);
|
|
1908
|
+
const [tick, setTick] = useState4(null);
|
|
1909
|
+
const [scrollWidth, setScrollWidth] = useState4(0);
|
|
1910
|
+
const eventPromptRef = useRef7(null);
|
|
1911
|
+
const rendererRef = useRef7(null);
|
|
1912
|
+
const sceneRef = useRef7(null);
|
|
1913
|
+
if (sceneRef.current === null) {
|
|
1914
|
+
sceneRef.current = new SceneStore();
|
|
1915
|
+
}
|
|
1916
|
+
const scene = sceneRef.current;
|
|
1917
|
+
useEffect6(() => {
|
|
1918
|
+
scene.setRows(rows);
|
|
1919
|
+
}, [scene, rows]);
|
|
1920
|
+
useEffect6(() => {
|
|
1921
|
+
scene.setEvents([...events].sort(sort_events_default));
|
|
1922
|
+
}, [scene, events]);
|
|
1923
|
+
useEffect6(() => {
|
|
1924
|
+
scene.setStaticEvents(staticEvents ? [...staticEvents] : []);
|
|
1925
|
+
}, [scene, staticEvents]);
|
|
1926
|
+
const windowTimeRef = useRef7(windowTime);
|
|
1927
|
+
windowTimeRef.current = windowTime;
|
|
1928
|
+
useImperativeHandle2(
|
|
1929
|
+
handleRef,
|
|
1930
|
+
() => ({
|
|
1931
|
+
setEvents: (next) => scene.setEvents([...next].sort(sort_events_default)),
|
|
1932
|
+
updateEvents: (patches) => scene.applyPatches(patches),
|
|
1933
|
+
getEvent: (id) => scene.getEvent(id),
|
|
1934
|
+
scrollToRow: (rowId) => {
|
|
1935
|
+
const [windowStart, windowEnd] = windowTimeRef.current;
|
|
1936
|
+
const offset2 = scene.getRowOffsets(windowStart, windowEnd).offsetOf.get(rowId);
|
|
1937
|
+
if (offset2 !== void 0 && bodyRef.current) {
|
|
1938
|
+
bodyRef.current.scrollTop = offset2;
|
|
1756
1939
|
}
|
|
1757
1940
|
},
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
eventRef.current.style.bottom = value;
|
|
1761
|
-
}
|
|
1941
|
+
scrollToTime: (time) => {
|
|
1942
|
+
setWindowTime((prev) => [time, time + (prev[1] - prev[0])]);
|
|
1762
1943
|
},
|
|
1763
|
-
|
|
1764
|
-
|
|
1944
|
+
setWindow: (startTime, endTime) => setWindowTime([startTime, endTime]),
|
|
1945
|
+
getVisibleRange: () => ({
|
|
1946
|
+
startTime: windowTimeRef.current[0],
|
|
1947
|
+
endTime: windowTimeRef.current[1]
|
|
1948
|
+
}),
|
|
1949
|
+
redraw: () => {
|
|
1950
|
+
var _a;
|
|
1951
|
+
return (_a = rendererRef.current) == null ? void 0 : _a.invalidate("all");
|
|
1765
1952
|
}
|
|
1766
|
-
}
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
)
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
onResize,
|
|
1780
|
-
startDate,
|
|
1781
|
-
endDate,
|
|
1782
|
-
additionalClassNames,
|
|
1783
|
-
showRTIndicator = true,
|
|
1784
|
-
eventsResize = true,
|
|
1785
|
-
eventPromptTemplate,
|
|
1786
|
-
showEventPrompt = true
|
|
1787
|
-
}) => {
|
|
1788
|
-
const [windowTime, setWindowTime] = useState6([
|
|
1789
|
-
new Date(
|
|
1790
|
-
startDate.getFullYear(),
|
|
1791
|
-
startDate.getMonth(),
|
|
1792
|
-
startDate.getDate(),
|
|
1793
|
-
startDate.getHours(),
|
|
1794
|
-
0,
|
|
1795
|
-
0
|
|
1796
|
-
).getTime() / 1e3,
|
|
1797
|
-
new Date(
|
|
1798
|
-
endDate.getFullYear(),
|
|
1799
|
-
endDate.getMonth(),
|
|
1800
|
-
endDate.getDate(),
|
|
1801
|
-
endDate.getHours(),
|
|
1802
|
-
0,
|
|
1803
|
-
0
|
|
1804
|
-
).getTime() / 1e3
|
|
1805
|
-
]);
|
|
1806
|
-
const [cellWidth, setCellWidth] = useState6(0);
|
|
1807
|
-
const [internalEvents, setInternalEvents] = useState6([]);
|
|
1808
|
-
const contentRef = useRef9(null);
|
|
1809
|
-
const mainRef = useRef9(null);
|
|
1810
|
-
const bodyRef = useRef9(null);
|
|
1811
|
-
const [tick, setTick] = useState6(null);
|
|
1812
|
-
const [scrollWidth, setScrollWidth] = useState6(0);
|
|
1813
|
-
const [rowsHeight, setRowsHeight] = useState6(null);
|
|
1814
|
-
const [allRowsHeight, setAllRowsHeight] = useState6(0);
|
|
1815
|
-
const eventPromptRef = useRef9(null);
|
|
1816
|
-
useEffect6(() => {
|
|
1817
|
-
if (contentRef.current) {
|
|
1818
|
-
const windowDuration = windowTime[1] - windowTime[0];
|
|
1819
|
-
const numberOfHourBlocks = windowDuration / 3600;
|
|
1820
|
-
setTick(
|
|
1821
|
-
windowDuration / contentRef.current.getBoundingClientRect().width
|
|
1822
|
-
);
|
|
1823
|
-
setCellWidth(
|
|
1824
|
-
contentRef.current.getBoundingClientRect().width / numberOfHourBlocks
|
|
1825
|
-
);
|
|
1826
|
-
}
|
|
1827
|
-
}, []);
|
|
1828
|
-
useEffect6(() => {
|
|
1829
|
-
if (bodyRef.current) {
|
|
1830
|
-
setScrollWidth(
|
|
1831
|
-
bodyRef.current.getBoundingClientRect().width - bodyRef.current.scrollWidth
|
|
1832
|
-
);
|
|
1833
|
-
}
|
|
1834
|
-
}, []);
|
|
1835
|
-
useEffect6(() => {
|
|
1836
|
-
setInternalEvents(events.sort(sort_events_default));
|
|
1837
|
-
}, [events]);
|
|
1838
|
-
const [dragStarted, setDragStarted] = useState6(false);
|
|
1839
|
-
useEffect6(() => {
|
|
1840
|
-
let tempRowsHeight = null;
|
|
1841
|
-
rows.forEach((row) => {
|
|
1842
|
-
if (tempRowsHeight === null) {
|
|
1843
|
-
tempRowsHeight = { [row.id]: { minHeight: 40 } };
|
|
1844
|
-
} else {
|
|
1845
|
-
tempRowsHeight[row.id] = { minHeight: 40 };
|
|
1953
|
+
}),
|
|
1954
|
+
[scene]
|
|
1955
|
+
);
|
|
1956
|
+
useEffect6(() => {
|
|
1957
|
+
if (contentRef.current) {
|
|
1958
|
+
const windowDuration = windowTime[1] - windowTime[0];
|
|
1959
|
+
const numberOfHourBlocks = windowDuration / 3600;
|
|
1960
|
+
setTick(
|
|
1961
|
+
windowDuration / contentRef.current.getBoundingClientRect().width
|
|
1962
|
+
);
|
|
1963
|
+
setCellWidth(
|
|
1964
|
+
contentRef.current.getBoundingClientRect().width / numberOfHourBlocks
|
|
1965
|
+
);
|
|
1846
1966
|
}
|
|
1847
|
-
});
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
event_prompt_default,
|
|
1854
|
-
{
|
|
1855
|
-
ref: eventPromptRef,
|
|
1856
|
-
template: eventPromptTemplate
|
|
1967
|
+
}, []);
|
|
1968
|
+
useEffect6(() => {
|
|
1969
|
+
if (bodyRef.current) {
|
|
1970
|
+
setScrollWidth(
|
|
1971
|
+
bodyRef.current.getBoundingClientRect().width - bodyRef.current.scrollWidth
|
|
1972
|
+
);
|
|
1857
1973
|
}
|
|
1858
|
-
)
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
), /* @__PURE__ */ React14.createElement("div", { className: "body-wrapper", ref: bodyRef }, /* @__PURE__ */ React14.createElement(
|
|
1870
|
-
RowsHeightContext.Provider,
|
|
1871
|
-
{
|
|
1872
|
-
value: { rowsHeight, setRowsHeight, allRowsHeight, setAllRowsHeight }
|
|
1873
|
-
},
|
|
1874
|
-
/* @__PURE__ */ React14.createElement(
|
|
1875
|
-
rows_header_default,
|
|
1876
|
-
{
|
|
1877
|
-
rows,
|
|
1878
|
-
className: additionalClassNames == null ? void 0 : additionalClassNames.rowsHeader
|
|
1974
|
+
}, []);
|
|
1975
|
+
use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTime });
|
|
1976
|
+
const resolvedTheme = useMemo4(() => resolveTheme(theme), [theme]);
|
|
1977
|
+
const resolvedAnimations = useMemo4(() => {
|
|
1978
|
+
var _a, _b;
|
|
1979
|
+
if (animations === false) return { layoutMs: 0, fadeMs: 0 };
|
|
1980
|
+
if (animations === true) {
|
|
1981
|
+
return {
|
|
1982
|
+
layoutMs: DEFAULT_LAYOUT_DURATION_MS,
|
|
1983
|
+
fadeMs: DEFAULT_FADE_DURATION_MS
|
|
1984
|
+
};
|
|
1879
1985
|
}
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
/* @__PURE__ */
|
|
1887
|
-
|
|
1986
|
+
return {
|
|
1987
|
+
layoutMs: (_a = animations.layoutMs) != null ? _a : DEFAULT_LAYOUT_DURATION_MS,
|
|
1988
|
+
fadeMs: (_b = animations.fadeMs) != null ? _b : DEFAULT_FADE_DURATION_MS
|
|
1989
|
+
};
|
|
1990
|
+
}, [animations]);
|
|
1991
|
+
const eventPrompt = useMemo4(
|
|
1992
|
+
() => /* @__PURE__ */ React6.createElement(
|
|
1993
|
+
event_prompt_default,
|
|
1888
1994
|
{
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
rows,
|
|
1892
|
-
setEvents: setInternalEvents,
|
|
1893
|
-
tick,
|
|
1894
|
-
windowTime,
|
|
1895
|
-
cellWidth,
|
|
1896
|
-
setWindowTime,
|
|
1897
|
-
ref: contentRef,
|
|
1898
|
-
setCellWidth,
|
|
1899
|
-
contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
|
|
1900
|
-
bodyRef,
|
|
1901
|
-
lineClassName: additionalClassNames == null ? void 0 : additionalClassNames.gridLine
|
|
1995
|
+
ref: eventPromptRef,
|
|
1996
|
+
template: eventPromptTemplate
|
|
1902
1997
|
}
|
|
1903
1998
|
),
|
|
1904
|
-
|
|
1905
|
-
)
|
|
1906
|
-
|
|
1907
|
-
|
|
1999
|
+
[eventPromptTemplate]
|
|
2000
|
+
);
|
|
2001
|
+
return /* @__PURE__ */ React6.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ React6.createElement(rt_indicator_default, { tick, windowTime }), /* @__PURE__ */ React6.createElement(
|
|
2002
|
+
canvas_time_bar_default,
|
|
2003
|
+
{
|
|
2004
|
+
windowTime,
|
|
2005
|
+
tick,
|
|
2006
|
+
contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
|
|
2007
|
+
scrollWidth,
|
|
2008
|
+
theme: resolvedTheme
|
|
2009
|
+
}
|
|
2010
|
+
), /* @__PURE__ */ React6.createElement("div", { className: "body-wrapper", ref: bodyRef }, /* @__PURE__ */ React6.createElement(
|
|
2011
|
+
canvas_board_default,
|
|
2012
|
+
{
|
|
2013
|
+
scene,
|
|
2014
|
+
rows,
|
|
2015
|
+
windowTime,
|
|
2016
|
+
tick,
|
|
2017
|
+
cellWidth,
|
|
2018
|
+
theme: resolvedTheme,
|
|
2019
|
+
drawEvent,
|
|
2020
|
+
bodyRef,
|
|
2021
|
+
rendererRef,
|
|
2022
|
+
eventPromptRef,
|
|
2023
|
+
rowsHeaderClassName: additionalClassNames == null ? void 0 : additionalClassNames.rowsHeader,
|
|
2024
|
+
setWindowTime,
|
|
2025
|
+
setCellWidth,
|
|
2026
|
+
onDrop,
|
|
2027
|
+
onResize,
|
|
2028
|
+
onEventClick,
|
|
2029
|
+
onEventHover,
|
|
2030
|
+
eventsResize,
|
|
2031
|
+
panZoom,
|
|
2032
|
+
animations: resolvedAnimations,
|
|
2033
|
+
ref: contentRef
|
|
2034
|
+
}
|
|
2035
|
+
), showEventPrompt && eventPrompt));
|
|
2036
|
+
}
|
|
2037
|
+
);
|
|
1908
2038
|
export {
|
|
1909
2039
|
Timeline
|
|
1910
2040
|
};
|