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/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 React14, { useEffect as useEffect6, useMemo as useMemo7, useRef as useRef9, useState as useState6 } from "react";
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 React2, { useRef } from "react";
244
+ // src/components/canvas-time-bar.tsx
245
+ import React3, { useEffect as useEffect3, useRef as useRef4 } from "react";
23
246
 
24
- // src/hooks/use-generate-blocks.tsx
25
- import React from "react";
26
- import { useMemo } from "react";
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/hooks/use-generate-blocks.tsx
108
- var useGenerateBlocks = ({
109
- windowTime,
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 { dayBlocks, hourBlocks } = useMemo(() => {
115
- let timePoint = windowTime[0];
116
- const dayBlocks2 = [];
117
- const hourBlocks2 = [];
118
- if (tick === null || contentWidth === null) {
119
- return { dayBlocks: [], hourBlocks: [] };
120
- }
121
- let widthLeft = contentWidth;
122
- let prevNumBlocks = 1;
123
- while (1) {
124
- let datePoint = new Date(timePoint * 1e3);
125
- const endDatePoint = new Date(
126
- datePoint.getFullYear(),
127
- datePoint.getMonth(),
128
- datePoint.getDate(),
129
- 23,
130
- 59,
131
- 59
132
- );
133
- const dateDuration = endDatePoint.getTime() - datePoint.getTime();
134
- const dateWidth = dateDuration / 1e3 / tick;
135
- widthLeft -= dateWidth;
136
- if (Math.round(widthLeft) < 0) {
137
- const numBlocks2 = Math.round((dateWidth + widthLeft) / blockWidth);
138
- for (let i = 0; i < numBlocks2; i++) {
139
- hourBlocks2.push(
140
- /* @__PURE__ */ React.createElement(
141
- "div",
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
- timePoint = (endDatePoint.getTime() + 1e3) / 1e3;
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
- return { dayBlocks: dayBlocks2, hourBlocks: hourBlocks2 };
204
- }, [tick, windowTime, contentWidth]);
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/hooks/use-get-block-properties.ts
210
- import { useMemo as useMemo2 } from "react";
211
- var useGetBlockProperties = ({
212
- windowTime,
213
- contentWidth
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
- const numberOfHourBlocks = useMemo2(
216
- () => (windowTime[1] - windowTime[0]) / 3600,
217
- [windowTime]
218
- );
219
- const blockWidth = contentWidth ? contentWidth / numberOfHourBlocks : 0;
220
- return { numberOfHourBlocks, blockWidth };
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 TimeBar = ({
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
- additionalClassNames
538
+ theme
231
539
  }) => {
232
- const timeContentRef = useRef(null);
540
+ const canvasRef = useRef4(null);
233
541
  const { blockWidth } = use_get_block_properties_default({
234
542
  windowTime,
235
543
  contentWidth
236
544
  });
237
- const { dayBlocks, hourBlocks } = use_generate_blocks_default({
238
- windowTime,
239
- tick,
240
- contentWidth,
241
- blockWidth
242
- });
243
- const timeBarClassNames = (additionalClassNames == null ? void 0 : additionalClassNames.timeBar) ? "time-bar " + additionalClassNames.timeBar : "time-bar";
244
- const dayRowClassNames = (additionalClassNames == null ? void 0 : additionalClassNames.dayRow) ? "day-row " + additionalClassNames.dayRow : "day-row";
245
- const hourRowClassNames = (additionalClassNames == null ? void 0 : additionalClassNames.hourRow) ? "hour-row " + additionalClassNames.hourRow : "hour-row";
246
- return /* @__PURE__ */ React2.createElement("div", { className: timeBarClassNames }, /* @__PURE__ */ React2.createElement("div", { className: "empty-block" }), /* @__PURE__ */ React2.createElement(
247
- "div",
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
- className: "time-content",
250
- ref: timeContentRef,
573
+ ref: canvasRef,
574
+ className: "canvas-time-bar",
251
575
  style: { minWidth: contentWidth ? contentWidth : 0 }
252
- },
253
- /* @__PURE__ */ React2.createElement(
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 time_bar_default = TimeBar;
589
+ var canvas_time_bar_default = CanvasTimeBar;
286
590
 
287
- // src/components/rows-header.tsx
288
- import React4 from "react";
289
-
290
- // src/components/row-header.tsx
291
- import React3, { useContext } from "react";
292
-
293
- // src/contexts/row-height-context.ts
294
- import { createContext } from "react";
295
- var RowsHeightContext = createContext(
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/components/row-header.tsx
300
- var RowHeader = ({ name, id }) => {
301
- const rowsHeightContext = useContext(RowsHeightContext);
302
- const minHeight = rowsHeightContext && rowsHeightContext.rowsHeight && rowsHeightContext.rowsHeight[id] ? rowsHeightContext.rowsHeight[id].minHeight : 40;
303
- return /* @__PURE__ */ React3.createElement("div", { className: "row-header", style: { minHeight } }, name);
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/components/rows-header.tsx
308
- var RowsHeader = ({
309
- rows,
310
- className
311
- }) => {
312
- const classNames = className ? "rows-header-wrapper " + className : "rows-header-wrapper";
313
- return /* @__PURE__ */ React4.createElement("div", { className: classNames }, rows.map((row) => /* @__PURE__ */ React4.createElement(
314
- row_header_default,
315
- {
316
- key: `row_header_${row.id}`,
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/components/content.tsx
325
- import React11, {
326
- forwardRef as forwardRef2,
327
- useCallback as useCallback5,
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/components/lines-canvas.tsx
335
- import React5 from "react";
336
- import { useMemo as useMemo3 } from "react";
337
- var LinesCanvas = ({
338
- contentWidth,
339
- cellWidth,
340
- lineClassName
341
- }) => {
342
- const lines = useMemo3(() => {
343
- const lines2 = [];
344
- const classNames = lineClassName ? "line " + lineClassName : "line";
345
- if (contentWidth) {
346
- for (let i = cellWidth; i < contentWidth; i = i + cellWidth) {
347
- lines2.push(/* @__PURE__ */ React5.createElement("div", { key: `line_${i}`, className: classNames }));
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
- return lines2;
351
- }, [cellWidth, contentWidth]);
352
- const minWidth = useMemo3(() => {
353
- return contentWidth ? contentWidth - lines.length * cellWidth : 0;
354
- }, [contentWidth, cellWidth, lines]);
355
- return /* @__PURE__ */ React5.createElement(
356
- "div",
357
- {
358
- className: minWidth < 1 ? "lines-canvas hide-last-line" : "lines-canvas",
359
- style: minWidth < 1 ? {
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/hooks/use-produce-content.tsx
371
- import { useContext as useContext5, useEffect as useEffect2, useMemo as useMemo5, useRef as useRef4 } from "react";
372
- import React10 from "react";
373
-
374
- // src/components/static-event.tsx
375
- import React6 from "react";
376
- var StaticEvent = ({
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
- return /* @__PURE__ */ React6.createElement(
384
- "div",
385
- {
386
- id: `static_event_${id}`,
387
- key: `static_event_${id}`,
388
- className: "static-event",
389
- onDrop: (event) => event.stopPropagation(),
390
- style: {
391
- left: startPosition,
392
- width,
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
- // node_modules/immer/dist/immer.mjs
409
- var NOTHING = Symbol.for("immer-nothing");
410
- var DRAFTABLE = Symbol.for("immer-draftable");
411
- var DRAFT_STATE = Symbol.for("immer-state");
412
- var errors = process.env.NODE_ENV !== "production" ? [
413
- // All error codes, starting by 0:
414
- function(plugin) {
415
- return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
416
- },
417
- function(thing) {
418
- return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
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
- result = finalize(scope, baseDraft, []);
649
- }
650
- revokeScope(scope);
651
- if (scope.patches_) {
652
- scope.patchListener_(scope.patches_, scope.inversePatches_);
653
- }
654
- return result !== NOTHING ? result : void 0;
655
- }
656
- function finalize(rootScope, value, path) {
657
- if (isFrozen(value))
658
- return value;
659
- const state = value[DRAFT_STATE];
660
- if (!state) {
661
- each(
662
- value,
663
- (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path)
664
- );
665
- return value;
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
- maybeFreeze(rootScope, result, false);
689
- if (path && rootScope.patches_) {
690
- getPlugin("Patches").generatePatches_(
691
- state,
692
- path,
693
- rootScope.patches_,
694
- rootScope.inversePatches_
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
- return state.copy_;
699
- }
700
- function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
701
- if (process.env.NODE_ENV !== "production" && childValue === targetObject)
702
- die(5);
703
- if (isDraft(childValue)) {
704
- const path = rootPath && parentState && parentState.type_ !== 3 && // Set objects are atomic since they have no keys.
705
- !has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
706
- const res = finalize(rootScope, childValue, path);
707
- set(targetObject, prop, res);
708
- if (isDraft(res)) {
709
- rootScope.canAutoFreeze_ = false;
710
- } else
711
- return;
712
- } else if (targetIsSet) {
713
- targetObject.add(childValue);
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
- if (isDraftable(childValue) && !isFrozen(childValue)) {
716
- if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
717
- return;
718
- }
719
- finalize(rootScope, childValue);
720
- if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && Object.prototype.propertyIsEnumerable.call(targetObject, prop))
721
- maybeFreeze(rootScope, childValue);
722
- }
723
- }
724
- function maybeFreeze(scope, value, deep = false) {
725
- if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
726
- freeze(value, deep);
727
- }
728
- }
729
- function createProxyProxy(base, parent) {
730
- const isArray = Array.isArray(base);
731
- const state = {
732
- type_: isArray ? 1 : 0,
733
- // Track which produce call this is associated with.
734
- scope_: parent ? parent.scope_ : getCurrentScope(),
735
- // True for both shallow and deep changes.
736
- modified_: false,
737
- // Used during finalization.
738
- finalized_: false,
739
- // Track which properties have been assigned (true) or deleted (false).
740
- assigned_: {},
741
- // The parent draft state.
742
- parent_: parent,
743
- // The base state.
744
- base_: base,
745
- // The base proxy.
746
- draft_: null,
747
- // set below
748
- // The base copy with any updated values.
749
- copy_: null,
750
- // Called by the `produce` function.
751
- revoke_: null,
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
- if (!state.modified_) {
796
- const current2 = peek(latest(state), prop);
797
- const currentState = current2 == null ? void 0 : current2[DRAFT_STATE];
798
- if (currentState && currentState.base_ === value) {
799
- state.copy_[prop] = value;
800
- state.assigned_[prop] = false;
801
- return true;
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
- if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
804
- return true;
805
- prepareCopy(state);
806
- markChanged(state);
807
- }
808
- if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
809
- (value !== void 0 || prop in state.copy_) || // special case: NaN
810
- Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
811
- return true;
812
- state.copy_[prop] = value;
813
- state.assigned_[prop] = true;
814
- return true;
815
- },
816
- deleteProperty(state, prop) {
817
- if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
818
- state.assigned_[prop] = false;
819
- prepareCopy(state);
820
- markChanged(state);
821
- } else {
822
- delete state.assigned_[prop];
823
- }
824
- if (state.copy_) {
825
- delete state.copy_[prop];
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
- var arrayTraps = {};
854
- each(objectTraps, (key, fn) => {
855
- arrayTraps[key] = function() {
856
- arguments[0] = arguments[0][0];
857
- return fn.apply(this, arguments);
858
- };
859
- });
860
- arrayTraps.deleteProperty = function(state, prop) {
861
- if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
862
- die(13);
863
- return arrayTraps.set.call(this, state, prop, void 0);
864
- };
865
- arrayTraps.set = function(state, prop, value) {
866
- if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
867
- die(14);
868
- return objectTraps.set.call(this, state[0], prop, value, state[0]);
869
- };
870
- function peek(draft, prop) {
871
- const state = draft[DRAFT_STATE];
872
- const source = state ? latest(state) : draft;
873
- return source[prop];
874
- }
875
- function readPropFromProto(state, source, prop) {
876
- var _a;
877
- const desc = getDescriptorFromProto(source, prop);
878
- return desc ? `value` in desc ? desc.value : (
879
- // This is a very special case, if the prop is a getter defined by the
880
- // prototype, we should invoke it with the draft as context!
881
- (_a = desc.get) == null ? void 0 : _a.call(state.draft_)
882
- ) : void 0;
883
- }
884
- function getDescriptorFromProto(source, prop) {
885
- if (!(prop in source))
886
- return void 0;
887
- let proto = getPrototypeOf(source);
888
- while (proto) {
889
- const desc = Object.getOwnPropertyDescriptor(proto, prop);
890
- if (desc)
891
- return desc;
892
- proto = getPrototypeOf(proto);
893
- }
894
- return void 0;
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
- function prepareCopy(state) {
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
- var Immer2 = class {
913
- constructor(config) {
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
- * Pass true to automatically freeze all copies created by Immer.
1000
- *
1001
- * By default, auto-freezing is enabled.
1002
- */
1003
- setAutoFreeze(value) {
1004
- this.autoFreeze_ = value;
997
+ dispose() {
998
+ this.scheduler.dispose();
999
+ this.unsubscribeScene();
1000
+ this.unwatchDpr();
1005
1001
  }
1006
- /**
1007
- * Pass true to enable strict shallow copy.
1008
- *
1009
- * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
1010
- */
1011
- setUseStrictShallowCopy(value) {
1012
- this.useStrictShallowCopy_ = value;
1013
- }
1014
- applyPatches(base, patches) {
1015
- let i;
1016
- for (i = patches.length - 1; i >= 0; i--) {
1017
- const patch = patches[i];
1018
- if (patch.path.length === 0 && patch.op === "replace") {
1019
- base = patch.value;
1020
- break;
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 (i > -1) {
1024
- patches = patches.slice(i + 1);
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
- const applyPatchesImpl = getPlugin("Patches").applyPatches_;
1027
- if (isDraft(base)) {
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/contexts/drag-started-context.ts
1080
- import { createContext as createContext2 } from "react";
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/contexts/external-properties-context.ts
1088
- import { createContext as createContext3 } from "react";
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/helpers/sort-events.ts
1094
- var sortEvents = (eventA, eventB) => {
1095
- if (eventA.startTime - eventB.startTime < 0) return -1;
1096
- if (eventA.startTime === eventB.startTime) {
1097
- if (eventA.endTime < eventB.endTime) {
1098
- return -1;
1099
- } else {
1100
- return 1;
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
- } else {
1103
- return 1;
1056
+ rowTop += height;
1104
1057
  }
1105
- };
1106
- var sort_events_default = sortEvents;
1107
-
1108
- // src/components/row-content.tsx
1109
- var RowContent = forwardRef((props, ref) => {
1110
- const { setEvents, tick, id, windowTime, cellWidth, children } = props;
1111
- const { dragStarted, setDragStarted } = useContext3(DragStartedContext);
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
- const rowsHeightContext = useContext3(RowsHeightContext);
1149
- const minHeight = rowsHeightContext && rowsHeightContext.rowsHeight && rowsHeightContext.rowsHeight[id] ? rowsHeightContext.rowsHeight[id].minHeight : 40;
1150
- return /* @__PURE__ */ React7.createElement(
1151
- "div",
1152
- {
1153
- id: `row_${id}`,
1154
- ref,
1155
- onDragOver: (event) => event.preventDefault(),
1156
- onDrop: handleOnDrop,
1157
- className: dragStarted ? "row-content not-clickable" : "row-content",
1158
- "data-index": id,
1159
- style: {
1160
- minHeight
1161
- }
1162
- },
1163
- children
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
- var row_content_default = RowContent;
1167
-
1168
- // src/components/event.tsx
1169
- import React9, {
1170
- useCallback as useCallback3,
1171
- useContext as useContext4,
1172
- useRef as useRef2,
1173
- useState
1174
- } from "react";
1175
-
1176
- // src/components/resize-icon.tsx
1177
- import React8 from "react";
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/components/event.tsx
1184
- var Event = ({
1185
- eventData,
1186
- startPosition,
1187
- width,
1188
- top,
1189
- setEvents,
1190
- tick
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
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1193
- const { setDragStarted } = useContext4(DragStartedContext);
1194
- const { onResize, eventsResize, eventPromptRef } = useContext4(
1195
- ExternalPropertiesContext
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 initialPositionForResizeRef = useRef2(0);
1198
- const handleOnDragStart = useCallback3(
1199
- (event) => {
1200
- event.stopPropagation();
1201
- event.dataTransfer.setData("eventId", eventData.id);
1202
- setTimeout(() => setDragStarted(true), 0);
1203
- const target = event.target;
1204
- target.style.opacity = "50%";
1205
- if (eventPromptRef == null ? void 0 : eventPromptRef.current) {
1206
- eventPromptRef.current.setDisplay("none");
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
- [setDragStarted]
1183
+ [dynamicCanvasRef, eventsResize]
1210
1184
  );
1211
- const handleOnDragEnd = useCallback3(
1212
- (event) => {
1213
- event.stopPropagation();
1214
- setDragStarted(false);
1215
- const target = event.target;
1216
- target.style.opacity = "100%";
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
- [setDragStarted]
1211
+ [ghostRef]
1219
1212
  );
1220
- const classNames = ((_a = eventData.props) == null ? void 0 : _a.classNames) ? "event " + eventData.props.classNames.join(" ") : "event";
1221
- const [draggableEvent, setDraggableEvent] = useState(true);
1222
- const [resizeOffset, setResizeOffset] = useState(0);
1223
- const resizeOffsetRef = useRef2(0);
1224
- const [resizeStarted, setResizeStarted] = useState(false);
1225
- const resizeDirectionRef = useRef2(null);
1226
- const handleDocumentOnMouseMoveResize = useCallback3(
1227
- (event) => {
1228
- const offset = event.clientX - initialPositionForResizeRef.current;
1229
- let internalResizeOffset = resizeDirectionRef.current === "left" ? offset * -1 : offset;
1230
- setResizeOffset(internalResizeOffset);
1231
- resizeOffsetRef.current = offset;
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
- [setResizeOffset]
1249
+ [currentHit, resizeDirectionAt, dynamicCanvasRef, hidePrompt, config]
1234
1250
  );
1235
- const handleDocumentOnMouseUp = useCallback3(
1236
- (event, resizeDirection) => {
1237
- initialPositionForResizeRef.current = 0;
1238
- setResizeStarted(false);
1239
- document.removeEventListener(
1240
- "mousemove",
1241
- handleDocumentOnMouseMoveResize
1242
- );
1243
- const lockedStyle = document.getElementById("lock-cursor");
1244
- if (lockedStyle) {
1245
- lockedStyle.remove();
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
- handleDocumentOnMouseMoveResize,
1282
- setEvents,
1283
- tick,
1284
- setResizeOffset,
1285
- sort_events_default
1298
+ currentHit,
1299
+ resizeDirectionAt,
1300
+ dynamicCanvasRef,
1301
+ eventPromptRef,
1302
+ rendererRef,
1303
+ onEventHover
1286
1304
  ]
1287
1305
  );
1288
- const handleOnMouseDownEventResizer = useCallback3(
1289
- (event, resizeDirection) => {
1290
- event.stopPropagation();
1291
- resizeDirectionRef.current = resizeDirection;
1292
- setResizeStarted(true);
1293
- const style = document.createElement("style");
1294
- style.id = "lock-cursor";
1295
- style.innerHTML = "* { cursor: e-resize !important; }";
1296
- document.head.appendChild(style);
1297
- document.addEventListener("mousemove", handleDocumentOnMouseMoveResize);
1298
- document.addEventListener(
1299
- "mouseup",
1300
- (event2) => handleDocumentOnMouseUp(event2, resizeDirection),
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
- [resizeStarted]
1339
+ [handleHover, schedulePan, updateGhost, rendererRef]
1314
1340
  );
1315
- const handleOnMouseOver = useCallback3(
1316
- (event) => {
1317
- var _a2, _b2;
1318
- event.stopPropagation();
1319
- if (((_a2 = eventData.props) == null ? void 0 : _a2.showPrompt) || ((_b2 = eventData.props) == null ? void 0 : _b2.showPrompt) === void 0) {
1320
- const target = event.target;
1321
- if (eventPromptRef == null ? void 0 : eventPromptRef.current) {
1322
- eventPromptRef.current.setDisplay("block");
1323
- eventPromptRef.current.setRight(
1324
- `calc(100% - ${target.getBoundingClientRect().left}px + 60px)`
1325
- );
1326
- eventPromptRef.current.setBottom(
1327
- `calc(100% - ${target.getBoundingClientRect().top}px + 60px)`
1328
- );
1329
- eventPromptRef.current.setEvent(eventData);
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
- [eventData]
1392
+ [scene, dynamicCanvasRef, rendererRef, onDrop]
1334
1393
  );
1335
- const handleOnMouseOut = useCallback3(() => {
1336
- if (eventPromptRef == null ? void 0 : eventPromptRef.current) {
1337
- eventPromptRef.current.setDisplay("none");
1338
- }
1339
- }, []);
1340
- return /* @__PURE__ */ React9.createElement(
1341
- "div",
1342
- {
1343
- id: `event_${eventData.id}`,
1344
- key: `event_${eventData.id}`,
1345
- className: classNames,
1346
- draggable: ((_b = eventData.props) == null ? void 0 : _b.isLocked) ? false : draggableEvent,
1347
- onDragStart: handleOnDragStart,
1348
- onDragEnd: handleOnDragEnd,
1349
- onMouseDown: (event) => event.stopPropagation(),
1350
- onMouseMove: handleOnMouseMove,
1351
- onMouseOut: handleOnMouseOut,
1352
- onDrop: (event) => event.stopPropagation(),
1353
- style: {
1354
- left: resizeDirectionRef.current === "left" ? startPosition - resizeOffset : startPosition,
1355
- width: width + resizeOffset,
1356
- top,
1357
- cursor: ((_c = eventData.props) == null ? void 0 : _c.isLocked) ? "not-allowed" : "pointer"
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
- !((_d = eventData.props) == null ? void 0 : _d.isLocked) && (eventsResize && (((_e = eventData.props) == null ? void 0 : _e.isResizable) === true || ((_f = eventData.props) == null ? void 0 : _f.isResizable) === void 0) || !eventsResize && ((_g = eventData.props) == null ? void 0 : _g.isResizable)) && /* @__PURE__ */ React9.createElement(
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
- var event_default = Event;
1390
-
1391
- // src/hooks/use-intersection-observer.ts
1392
- import { useCallback as useCallback4, useEffect } from "react";
1393
- var useIntersectionObserver = ({
1394
- bodyRef,
1395
- rowsContentRef
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
- const observer = new IntersectionObserver(callback, {
1407
- root: bodyRef.current
1408
- });
1409
- useEffect(() => {
1410
- if (rowsContentRef.current) {
1411
- rowsContentRef.current.forEach((row) => {
1412
- observer.observe(row);
1413
- });
1414
- }
1415
- return () => observer.disconnect();
1416
- }, [observer]);
1417
- };
1418
- var use_intersection_observer_default = useIntersectionObserver;
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
- prevEvent[tempEventOrder] = event;
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
- internalAllRowsHeight2 += 40 + highestEventOrder * 22;
1488
- const rowStaticEvents = tick && staticEvents ? staticEvents.filter((event) => event.rowId === row.id).map((event) => {
1489
- if (event.endTime >= windowTime[0] && event.startTime <= windowTime[1]) {
1490
- return /* @__PURE__ */ React10.createElement(
1491
- static_event_default,
1492
- {
1493
- key: `static_event_${event.id}`,
1494
- id: event.id,
1495
- startPosition: (event.startTime - windowTime[0]) / tick,
1496
- width: (event.endTime - event.startTime) / tick,
1497
- top: 10,
1498
- height: 20 + highestEventOrder * 22
1499
- }
1500
- );
1501
- }
1502
- }) : null;
1503
- return /* @__PURE__ */ React10.createElement(React10.Fragment, { key: `row_content_${row.id}` }, /* @__PURE__ */ React10.createElement(
1504
- row_content_default,
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
- }, [content, internalAllRowsHeight]);
1536
- return content;
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 use_produce_content_default = useProduceContent;
1520
+ var use_canvas_interactions_default = useCanvasInteractions;
1539
1521
 
1540
- // src/components/content.tsx
1541
- var Content = forwardRef2(
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
- bodyRef,
1554
- lineClassName
1555
- }, ref) => {
1556
- const [mouseDown, setMouseDown] = useState3(false);
1557
- const startMovePosition = useRef5(null);
1558
- const [changeGrid, setChangeGrid] = useState3(false);
1559
- const { blockWidth } = use_get_block_properties_default({ windowTime, contentWidth });
1560
- const rowsHeightContext = useContext6(RowsHeightContext);
1561
- const handleOnMouseMove = useCallback5(
1562
- (event) => {
1563
- event.preventDefault();
1564
- if (!mouseDown) {
1565
- return;
1566
- }
1567
- const element = event.target;
1568
- const { left } = element.getBoundingClientRect();
1569
- const movePosition = event.clientX - left;
1570
- const moveTimestamp = tick ? Math.floor(tick * blockWidth) : 0;
1571
- if (startMovePosition.current && startMovePosition.current - movePosition >= blockWidth) {
1572
- startMovePosition.current = movePosition;
1573
- setWindowTime((prev) => [
1574
- prev[0] + moveTimestamp,
1575
- prev[1] + moveTimestamp
1576
- ]);
1577
- } else if (startMovePosition.current && movePosition - startMovePosition.current >= blockWidth) {
1578
- startMovePosition.current = movePosition;
1579
- setWindowTime((prev) => [
1580
- prev[0] - moveTimestamp,
1581
- prev[1] - moveTimestamp
1582
- ]);
1583
- }
1584
- },
1585
- [blockWidth, setWindowTime, mouseDown]
1586
- );
1587
- const handleOnMouseDown = useCallback5(
1588
- (event) => {
1589
- setMouseDown(true);
1590
- if (event.button === 1) {
1591
- event.preventDefault();
1592
- }
1593
- const element = event.target;
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
- setEvents,
1614
- bodyRef
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 handleAuxClick = useCallback5(
1617
- (event) => {
1618
- event.preventDefault();
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 handleOnWheel = useCallback5(
1626
- (event) => {
1627
- const pixelsToCalculate = tick ? 900 / tick : 0;
1628
- if (changeGrid) {
1629
- setCellWidth((cellWidth2) => {
1630
- const newCellWidth = event.deltaY > 0 ? cellWidth2 + pixelsToCalculate : cellWidth2 - pixelsToCalculate;
1631
- if (newCellWidth < pixelsToCalculate || newCellWidth > pixelsToCalculate * 12) {
1632
- return cellWidth2;
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
- return newCellWidth;
1635
- });
1636
- }
1637
- },
1638
- [changeGrid, cellWidth, tick]
1639
- );
1640
- useEffect3(() => {
1641
- if (bodyRef.current) {
1642
- bodyRef.current.style.overflow = changeGrid ? "hidden" : "auto";
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
- }, [changeGrid]);
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
- key: "content",
1649
- ref,
1650
- className: "content-wrapper",
1651
- onMouseDown: handleOnMouseDown,
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 content_default = Content;
1693
+ var canvas_board_default = CanvasBoard;
1675
1694
 
1676
- // src/hooks/use-resize-observer.ts
1677
- import { useEffect as useEffect4, useMemo as useMemo6, useRef as useRef6 } from "react";
1678
- var useResizeObserver = ({
1679
- windowTime,
1680
- setTick,
1681
- setCellWidth,
1682
- contentRef
1683
- }) => {
1684
- const prevWidthRef = useRef6(0);
1685
- const resizeObserver = useMemo6(() => {
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
- return () => resizeObserver.disconnect();
1705
- }, [resizeObserver]);
1706
+ }
1707
+ return lo;
1706
1708
  };
1707
- var use_resize_observer_default = useResizeObserver;
1708
-
1709
- // src/components/rt-indicator.tsx
1710
- import React12, { useEffect as useEffect5, useRef as useRef7, useState as useState4 } from "react";
1711
- var RTIndicator = ({
1712
- tick,
1713
- windowTime
1714
- }) => {
1715
- const [currentTime, setCurrentTime] = useState4((/* @__PURE__ */ new Date()).getTime() / 1e3);
1716
- const [leftOffset, setLeftOffset] = useState4(0);
1717
- const intervalIdRef = useRef7(null);
1718
- useEffect5(() => {
1719
- if (tick) {
1720
- const leftOffsetTime = currentTime - windowTime[0];
1721
- setLeftOffset(Math.round(leftOffsetTime / tick));
1722
- if (intervalIdRef.current !== null) {
1723
- clearInterval(intervalIdRef.current);
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
- }, [tick, windowTime, currentTime]);
1731
- return /* @__PURE__ */ React12.createElement(React12.Fragment, null, windowTime[0] <= currentTime && currentTime <= windowTime[1] && /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement("div", { className: "rt-arrow", style: { left: 86 + leftOffset } }), /* @__PURE__ */ React12.createElement("div", { className: "rt-line", style: { left: 100 + leftOffset } })));
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/components/event-prompt.tsx
1736
- import React13, {
1737
- forwardRef as forwardRef3,
1738
- useImperativeHandle,
1739
- useRef as useRef8,
1740
- useState as useState5
1741
- } from "react";
1742
- var EventPrompt = forwardRef3(
1743
- ({ template }, ref) => {
1744
- const eventRef = useRef8(null);
1745
- const [hoveredEvent, setHoveredEvent] = useState5();
1746
- useImperativeHandle(ref, () => {
1747
- return {
1748
- setDisplay(value) {
1749
- if (eventRef.current) {
1750
- eventRef.current.style.display = value;
1751
- }
1752
- },
1753
- setRight(value) {
1754
- if (eventRef.current) {
1755
- eventRef.current.style.right = value;
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
- setBottom(value) {
1759
- if (eventRef.current) {
1760
- eventRef.current.style.bottom = value;
1761
- }
1941
+ scrollToTime: (time) => {
1942
+ setWindowTime((prev) => [time, time + (prev[1] - prev[0])]);
1762
1943
  },
1763
- setEvent(event) {
1764
- setHoveredEvent(event);
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
- return /* @__PURE__ */ React13.createElement("div", { className: "event-prompt", ref: eventRef }, template && hoveredEvent && template(hoveredEvent));
1769
- }
1770
- );
1771
- var event_prompt_default = EventPrompt;
1772
-
1773
- // src/timeline.tsx
1774
- var Timeline = ({
1775
- rows,
1776
- events,
1777
- staticEvents,
1778
- onDrop,
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
- setRowsHeight(tempRowsHeight);
1849
- }, [rows]);
1850
- use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTime });
1851
- const eventPrompt = useMemo7(
1852
- () => /* @__PURE__ */ React14.createElement(
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
- [eventPromptTemplate]
1860
- );
1861
- return /* @__PURE__ */ React14.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ React14.createElement(rt_indicator_default, { tick, windowTime }), /* @__PURE__ */ React14.createElement(
1862
- time_bar_default,
1863
- {
1864
- windowTime,
1865
- tick,
1866
- contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
1867
- scrollWidth
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
- /* @__PURE__ */ React14.createElement(DragStartedContext.Provider, { value: { dragStarted, setDragStarted } }, /* @__PURE__ */ React14.createElement(
1882
- ExternalPropertiesContext.Provider,
1883
- {
1884
- value: { onDrop, onResize, eventsResize, eventPromptRef }
1885
- },
1886
- /* @__PURE__ */ React14.createElement(
1887
- content_default,
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
- events: internalEvents,
1890
- staticEvents,
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
- showEventPrompt && eventPrompt
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
  };