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