awesome-timeline-react 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -3
- package/dist/_tsup-dts-rollup.d.mts +186 -52
- package/dist/_tsup-dts-rollup.d.ts +186 -52
- package/dist/index.js +535 -252
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +474 -191
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -52,7 +52,7 @@ __export(index_exports, {
|
|
|
52
52
|
module.exports = __toCommonJS(index_exports);
|
|
53
53
|
|
|
54
54
|
// src/timeline.tsx
|
|
55
|
-
var
|
|
55
|
+
var import_react7 = __toESM(require("react"));
|
|
56
56
|
|
|
57
57
|
// src/canvas/animator.ts
|
|
58
58
|
var DEFAULT_LAYOUT_DURATION_MS = 200;
|
|
@@ -263,22 +263,7 @@ var EventPrompt = (0, import_react3.forwardRef)(
|
|
|
263
263
|
var event_prompt_default = EventPrompt;
|
|
264
264
|
|
|
265
265
|
// src/components/canvas-time-bar.tsx
|
|
266
|
-
var
|
|
267
|
-
|
|
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;
|
|
266
|
+
var import_react4 = __toESM(require("react"));
|
|
282
267
|
|
|
283
268
|
// src/helpers/get-month-name.ts
|
|
284
269
|
var getMonthName = (monthIndex) => {
|
|
@@ -328,106 +313,108 @@ var getMonthName = (monthIndex) => {
|
|
|
328
313
|
var get_month_name_default = getMonthName;
|
|
329
314
|
|
|
330
315
|
// src/helpers/get-week-day-name.ts
|
|
316
|
+
var WEEKDAY_NAMES = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
331
317
|
var getWeekDayName = (dayIndex) => {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
case 0:
|
|
335
|
-
dayName = "Mon";
|
|
336
|
-
break;
|
|
337
|
-
case 1:
|
|
338
|
-
dayName = "Tue";
|
|
339
|
-
break;
|
|
340
|
-
case 2:
|
|
341
|
-
dayName = "Wed";
|
|
342
|
-
break;
|
|
343
|
-
case 3:
|
|
344
|
-
dayName = "Thu";
|
|
345
|
-
break;
|
|
346
|
-
case 4:
|
|
347
|
-
dayName = "Fri";
|
|
348
|
-
break;
|
|
349
|
-
case 5:
|
|
350
|
-
dayName = "Sat";
|
|
351
|
-
break;
|
|
352
|
-
case 6:
|
|
353
|
-
dayName = "Sun";
|
|
354
|
-
break;
|
|
355
|
-
default:
|
|
356
|
-
dayName = "Mon";
|
|
357
|
-
}
|
|
358
|
-
return dayName;
|
|
318
|
+
var _a;
|
|
319
|
+
return (_a = WEEKDAY_NAMES[dayIndex]) != null ? _a : "Sun";
|
|
359
320
|
};
|
|
360
321
|
var get_week_day_name_default = getWeekDayName;
|
|
361
322
|
|
|
362
323
|
// src/core/time-blocks.ts
|
|
363
|
-
var
|
|
324
|
+
var pad2 = (n) => n < 10 ? `0${n}` : `${n}`;
|
|
325
|
+
var hourLabel = (hour) => `${pad2(hour)}:00`;
|
|
364
326
|
var dayLabel = (date) => `${get_week_day_name_default(date.getDay())} ${date.getDate()} ${get_month_name_default(
|
|
365
327
|
date.getMonth()
|
|
366
328
|
)}`;
|
|
367
|
-
var
|
|
329
|
+
var defaultFormat = (unit) => {
|
|
330
|
+
if (typeof unit === "object") {
|
|
331
|
+
return (d) => `${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
|
|
332
|
+
}
|
|
333
|
+
switch (unit) {
|
|
334
|
+
case "hour":
|
|
335
|
+
return (d) => hourLabel(d.getHours());
|
|
336
|
+
case "month":
|
|
337
|
+
return (d) => `${get_month_name_default(d.getMonth())} ${d.getFullYear()}`;
|
|
338
|
+
case "day":
|
|
339
|
+
case "week":
|
|
340
|
+
default:
|
|
341
|
+
return (d) => dayLabel(d);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
var floorToUnit = (date, unit, anchorSec) => {
|
|
345
|
+
if (typeof unit === "object") {
|
|
346
|
+
const t = date.getTime() / 1e3;
|
|
347
|
+
const step = unit.stepSeconds;
|
|
348
|
+
return new Date((anchorSec + Math.floor((t - anchorSec) / step) * step) * 1e3);
|
|
349
|
+
}
|
|
350
|
+
const y = date.getFullYear();
|
|
351
|
+
const mo = date.getMonth();
|
|
352
|
+
const d = date.getDate();
|
|
353
|
+
switch (unit) {
|
|
354
|
+
case "hour":
|
|
355
|
+
return new Date(y, mo, d, date.getHours());
|
|
356
|
+
case "day":
|
|
357
|
+
return new Date(y, mo, d);
|
|
358
|
+
case "week": {
|
|
359
|
+
const dow = (date.getDay() + 6) % 7;
|
|
360
|
+
return new Date(y, mo, d - dow);
|
|
361
|
+
}
|
|
362
|
+
case "month":
|
|
363
|
+
return new Date(y, mo, 1);
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
var nextBoundary = (blockStart, unit) => {
|
|
367
|
+
if (typeof unit === "object") {
|
|
368
|
+
return new Date(blockStart.getTime() + unit.stepSeconds * 1e3);
|
|
369
|
+
}
|
|
370
|
+
const y = blockStart.getFullYear();
|
|
371
|
+
const mo = blockStart.getMonth();
|
|
372
|
+
const d = blockStart.getDate();
|
|
373
|
+
switch (unit) {
|
|
374
|
+
case "hour":
|
|
375
|
+
return new Date(y, mo, d, blockStart.getHours() + 1);
|
|
376
|
+
case "day":
|
|
377
|
+
return new Date(y, mo, d + 1);
|
|
378
|
+
case "week":
|
|
379
|
+
return new Date(y, mo, d + 7);
|
|
380
|
+
case "month":
|
|
381
|
+
return new Date(y, mo + 1, 1);
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
var generateUnitBlocks = ({
|
|
385
|
+
unit,
|
|
386
|
+
format,
|
|
368
387
|
windowStart,
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
blockWidth
|
|
388
|
+
windowEnd,
|
|
389
|
+
tick
|
|
372
390
|
}) => {
|
|
373
|
-
const
|
|
374
|
-
const
|
|
375
|
-
if (tick === null ||
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
);
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
for (let i = 0; i < numBlocks2; i++) {
|
|
397
|
-
hourBlocks.push({
|
|
398
|
-
label: hourLabel(i),
|
|
399
|
-
x: hourBlocks.length * blockWidth,
|
|
400
|
-
width: blockWidth
|
|
401
|
-
});
|
|
402
|
-
}
|
|
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
|
|
391
|
+
const blocks = [];
|
|
392
|
+
const resolvedUnit = unit != null ? unit : "hour";
|
|
393
|
+
if (tick === null || tick <= 0 || windowEnd <= windowStart) return blocks;
|
|
394
|
+
const label = format != null ? format : defaultFormat(resolvedUnit);
|
|
395
|
+
const anchorSec = new Date(
|
|
396
|
+
new Date(windowStart * 1e3).getFullYear(),
|
|
397
|
+
new Date(windowStart * 1e3).getMonth(),
|
|
398
|
+
new Date(windowStart * 1e3).getDate()
|
|
399
|
+
).getTime() / 1e3;
|
|
400
|
+
let cursorSec = windowStart;
|
|
401
|
+
let guard = 0;
|
|
402
|
+
while (cursorSec < windowEnd && guard++ < 1e5) {
|
|
403
|
+
const blockStart = floorToUnit(new Date(cursorSec * 1e3), resolvedUnit, anchorSec);
|
|
404
|
+
const blockEnd = nextBoundary(blockStart, resolvedUnit);
|
|
405
|
+
const startSec = blockStart.getTime() / 1e3;
|
|
406
|
+
const endSec = blockEnd.getTime() / 1e3;
|
|
407
|
+
if (endSec <= startSec) break;
|
|
408
|
+
const visibleStart = Math.max(startSec, windowStart);
|
|
409
|
+
const visibleEnd = Math.min(endSec, windowEnd);
|
|
410
|
+
blocks.push({
|
|
411
|
+
label: label(blockStart, blockEnd),
|
|
412
|
+
x: (visibleStart - windowStart) / tick,
|
|
413
|
+
width: (visibleEnd - visibleStart) / tick
|
|
423
414
|
});
|
|
424
|
-
|
|
425
|
-
if (Math.round(widthLeft) === 0) {
|
|
426
|
-
break;
|
|
427
|
-
}
|
|
428
|
-
timePoint = (endDatePoint.getTime() + 1e3) / 1e3;
|
|
415
|
+
cursorSec = endSec;
|
|
429
416
|
}
|
|
430
|
-
return
|
|
417
|
+
return blocks;
|
|
431
418
|
};
|
|
432
419
|
|
|
433
420
|
// src/canvas/dpr.ts
|
|
@@ -475,7 +462,11 @@ var DEFAULT_THEME = {
|
|
|
475
462
|
gridColor: "#e4dcdc",
|
|
476
463
|
timeBarBorder: "yellow",
|
|
477
464
|
timeBarTextColor: "white",
|
|
478
|
-
font: void 0
|
|
465
|
+
font: void 0,
|
|
466
|
+
barHeight: 20,
|
|
467
|
+
laneGap: 2,
|
|
468
|
+
rowPaddingY: 10,
|
|
469
|
+
barRadius: 5
|
|
479
470
|
};
|
|
480
471
|
var resolveTheme = (theme) => __spreadValues(__spreadValues({}, DEFAULT_THEME), theme);
|
|
481
472
|
|
|
@@ -484,14 +475,19 @@ var drawGridLines = (ctx, {
|
|
|
484
475
|
width,
|
|
485
476
|
height,
|
|
486
477
|
cellWidth,
|
|
478
|
+
windowStart,
|
|
479
|
+
tick,
|
|
487
480
|
color = DEFAULT_THEME.gridColor
|
|
488
481
|
}) => {
|
|
489
|
-
if (cellWidth <= 0) return;
|
|
482
|
+
if (cellWidth <= 0 || tick <= 0) return;
|
|
483
|
+
const cellTime = cellWidth * tick;
|
|
490
484
|
ctx.strokeStyle = color;
|
|
491
485
|
ctx.lineWidth = 1;
|
|
492
486
|
ctx.beginPath();
|
|
493
|
-
for (let
|
|
494
|
-
|
|
487
|
+
for (let t = Math.floor(windowStart / cellTime) * cellTime + cellTime; ; t += cellTime) {
|
|
488
|
+
const x = (t - windowStart) / tick;
|
|
489
|
+
if (x >= width || width - x < 1) break;
|
|
490
|
+
if (x < 1) continue;
|
|
495
491
|
const crisp = Math.round(x) - 0.5;
|
|
496
492
|
ctx.moveTo(crisp, 0);
|
|
497
493
|
ctx.lineTo(crisp, height);
|
|
@@ -501,8 +497,8 @@ var drawGridLines = (ctx, {
|
|
|
501
497
|
var drawTimeBar = (ctx, {
|
|
502
498
|
width,
|
|
503
499
|
height,
|
|
504
|
-
|
|
505
|
-
|
|
500
|
+
topBlocks,
|
|
501
|
+
bottomBlocks,
|
|
506
502
|
font,
|
|
507
503
|
borderColor = DEFAULT_THEME.timeBarBorder,
|
|
508
504
|
textColor = DEFAULT_THEME.timeBarTextColor
|
|
@@ -515,13 +511,13 @@ var drawTimeBar = (ctx, {
|
|
|
515
511
|
ctx.lineTo(width, Math.round(mid) - 0.5);
|
|
516
512
|
ctx.stroke();
|
|
517
513
|
ctx.beginPath();
|
|
518
|
-
for (let i = 0; i <
|
|
519
|
-
const edge = Math.round(
|
|
514
|
+
for (let i = 0; i < topBlocks.length - 1; i++) {
|
|
515
|
+
const edge = Math.round(topBlocks[i].x + topBlocks[i].width) - 0.5;
|
|
520
516
|
ctx.moveTo(edge, 0);
|
|
521
517
|
ctx.lineTo(edge, mid);
|
|
522
518
|
}
|
|
523
|
-
for (let i = 0; i <
|
|
524
|
-
const edge = Math.round(
|
|
519
|
+
for (let i = 0; i < bottomBlocks.length - 1; i++) {
|
|
520
|
+
const edge = Math.round(bottomBlocks[i].x + bottomBlocks[i].width) - 0.5;
|
|
525
521
|
ctx.moveTo(edge, mid);
|
|
526
522
|
ctx.lineTo(edge, height);
|
|
527
523
|
}
|
|
@@ -531,7 +527,7 @@ var drawTimeBar = (ctx, {
|
|
|
531
527
|
ctx.textBaseline = "middle";
|
|
532
528
|
ctx.textAlign = "center";
|
|
533
529
|
const inset = 4;
|
|
534
|
-
for (const block of
|
|
530
|
+
for (const block of topBlocks) {
|
|
535
531
|
ctx.fillText(
|
|
536
532
|
block.label,
|
|
537
533
|
block.x + block.width / 2,
|
|
@@ -539,7 +535,7 @@ var drawTimeBar = (ctx, {
|
|
|
539
535
|
block.width - inset
|
|
540
536
|
);
|
|
541
537
|
}
|
|
542
|
-
for (const block of
|
|
538
|
+
for (const block of bottomBlocks) {
|
|
543
539
|
ctx.fillText(
|
|
544
540
|
block.label,
|
|
545
541
|
block.x + block.width / 2,
|
|
@@ -556,15 +552,15 @@ var CanvasTimeBar = ({
|
|
|
556
552
|
tick,
|
|
557
553
|
contentWidth,
|
|
558
554
|
scrollWidth,
|
|
559
|
-
theme
|
|
555
|
+
theme,
|
|
556
|
+
timeBar
|
|
560
557
|
}) => {
|
|
561
|
-
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
var _a;
|
|
558
|
+
var _a, _b;
|
|
559
|
+
const canvasRef = (0, import_react4.useRef)(null);
|
|
560
|
+
const topRow = (_a = timeBar == null ? void 0 : timeBar.topRow) != null ? _a : { unit: "day" };
|
|
561
|
+
const bottomRow = (_b = timeBar == null ? void 0 : timeBar.bottomRow) != null ? _b : { unit: "hour" };
|
|
562
|
+
(0, import_react4.useEffect)(() => {
|
|
563
|
+
var _a2;
|
|
568
564
|
const canvas = canvasRef.current;
|
|
569
565
|
if (!canvas || !contentWidth) return;
|
|
570
566
|
const ctx = sizeCanvas(
|
|
@@ -573,29 +569,30 @@ var CanvasTimeBar = ({
|
|
|
573
569
|
TIME_BAR_INNER_HEIGHT,
|
|
574
570
|
window.devicePixelRatio
|
|
575
571
|
);
|
|
576
|
-
if (ctx)
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
572
|
+
if (!ctx) return;
|
|
573
|
+
const [windowStart, windowEnd] = windowTime;
|
|
574
|
+
drawTimeBar(ctx, {
|
|
575
|
+
width: contentWidth,
|
|
576
|
+
height: TIME_BAR_INNER_HEIGHT,
|
|
577
|
+
font: (_a2 = theme == null ? void 0 : theme.font) != null ? _a2 : getComputedStyle(canvas).font,
|
|
578
|
+
borderColor: theme == null ? void 0 : theme.timeBarBorder,
|
|
579
|
+
textColor: theme == null ? void 0 : theme.timeBarTextColor,
|
|
580
|
+
topBlocks: generateUnitBlocks(__spreadProps(__spreadValues({}, topRow), { windowStart, windowEnd, tick })),
|
|
581
|
+
bottomBlocks: generateUnitBlocks(__spreadProps(__spreadValues({}, bottomRow), {
|
|
582
|
+
windowStart,
|
|
583
|
+
windowEnd,
|
|
584
|
+
tick
|
|
585
|
+
}))
|
|
586
|
+
});
|
|
587
|
+
}, [windowTime, tick, contentWidth, theme, timeBar]);
|
|
588
|
+
return /* @__PURE__ */ import_react4.default.createElement("div", { className: "time-bar" }, /* @__PURE__ */ import_react4.default.createElement("div", { className: "empty-block" }), /* @__PURE__ */ import_react4.default.createElement(
|
|
592
589
|
"canvas",
|
|
593
590
|
{
|
|
594
591
|
ref: canvasRef,
|
|
595
592
|
className: "canvas-time-bar",
|
|
596
593
|
style: { minWidth: contentWidth ? contentWidth : 0 }
|
|
597
594
|
}
|
|
598
|
-
), scrollWidth ? /* @__PURE__ */
|
|
595
|
+
), scrollWidth ? /* @__PURE__ */ import_react4.default.createElement(
|
|
599
596
|
"div",
|
|
600
597
|
{
|
|
601
598
|
style: {
|
|
@@ -610,7 +607,7 @@ var CanvasTimeBar = ({
|
|
|
610
607
|
var canvas_time_bar_default = CanvasTimeBar;
|
|
611
608
|
|
|
612
609
|
// src/components/canvas-board.tsx
|
|
613
|
-
var
|
|
610
|
+
var import_react6 = __toESM(require("react"));
|
|
614
611
|
|
|
615
612
|
// src/canvas/frame-scheduler.ts
|
|
616
613
|
var FrameScheduler = class {
|
|
@@ -677,15 +674,32 @@ var timeToX = (time, windowStart, tick) => (time - windowStart) / tick;
|
|
|
677
674
|
var timeToWidth = (startTime, endTime, tick) => (endTime - startTime) / tick;
|
|
678
675
|
var intersectsWindow = (event, windowStart, windowEnd) => event.endTime >= windowStart && event.startTime <= windowEnd;
|
|
679
676
|
|
|
677
|
+
// src/core/geometry.ts
|
|
678
|
+
var DEFAULT_GEOMETRY = {
|
|
679
|
+
barHeight: 20,
|
|
680
|
+
laneHeight: 22,
|
|
681
|
+
laneTopOffset: 10,
|
|
682
|
+
rowBaseHeight: 40,
|
|
683
|
+
staticEventBaseHeight: 20,
|
|
684
|
+
barRadius: 5
|
|
685
|
+
};
|
|
686
|
+
var geometryFromTheme = (theme) => {
|
|
687
|
+
const barHeight = theme.barHeight;
|
|
688
|
+
const rowPaddingY = theme.rowPaddingY;
|
|
689
|
+
return {
|
|
690
|
+
barHeight,
|
|
691
|
+
laneHeight: barHeight + theme.laneGap,
|
|
692
|
+
laneTopOffset: rowPaddingY,
|
|
693
|
+
rowBaseHeight: barHeight + 2 * rowPaddingY,
|
|
694
|
+
staticEventBaseHeight: barHeight,
|
|
695
|
+
barRadius: theme.barRadius
|
|
696
|
+
};
|
|
697
|
+
};
|
|
698
|
+
|
|
680
699
|
// src/core/lanes.ts
|
|
681
|
-
var
|
|
682
|
-
var
|
|
683
|
-
var
|
|
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;
|
|
700
|
+
var laneTop = (lane, g = DEFAULT_GEOMETRY) => g.laneTopOffset + g.laneHeight * lane;
|
|
701
|
+
var rowMinHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.rowBaseHeight + highestLane * g.laneHeight;
|
|
702
|
+
var staticEventHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.staticEventBaseHeight + highestLane * g.laneHeight;
|
|
689
703
|
var assignLanes = (rowEvents, windowStart, windowEnd) => {
|
|
690
704
|
let eventOrder = 0;
|
|
691
705
|
const prevEvent = [];
|
|
@@ -727,9 +741,9 @@ var computeDropTimes = ({
|
|
|
727
741
|
windowStart,
|
|
728
742
|
duration
|
|
729
743
|
}) => {
|
|
730
|
-
const
|
|
731
|
-
const
|
|
732
|
-
const startTime =
|
|
744
|
+
const cellTime = cellWidth * tick;
|
|
745
|
+
const pointerTime = windowStart + pointerX * tick;
|
|
746
|
+
const startTime = Math.round(pointerTime / cellTime) * cellTime;
|
|
733
747
|
return { startTime, endTime: startTime + duration };
|
|
734
748
|
};
|
|
735
749
|
var computeResizeTimes = (event, deltaPx, tick, direction) => {
|
|
@@ -758,9 +772,26 @@ var stepCellWidth = (cellWidth, deltaY, tick) => {
|
|
|
758
772
|
}
|
|
759
773
|
return next;
|
|
760
774
|
};
|
|
775
|
+
var computeZoom = (windowTime, tick, cellWidth, anchorX, factor, contentWidth, { minWindowSeconds, maxWindowSeconds }) => {
|
|
776
|
+
const [start, end] = windowTime;
|
|
777
|
+
const oldDuration = end - start;
|
|
778
|
+
const newDuration = Math.min(
|
|
779
|
+
Math.max(oldDuration * factor, minWindowSeconds),
|
|
780
|
+
maxWindowSeconds
|
|
781
|
+
);
|
|
782
|
+
const cellTime = cellWidth * tick;
|
|
783
|
+
const tAnchor = start + anchorX * tick;
|
|
784
|
+
const newStart = Math.round(tAnchor - anchorX / contentWidth * newDuration);
|
|
785
|
+
const newEnd = newStart + Math.round(newDuration);
|
|
786
|
+
const newTick = (newEnd - newStart) / contentWidth;
|
|
787
|
+
return {
|
|
788
|
+
windowTime: [newStart, newEnd],
|
|
789
|
+
tick: newTick,
|
|
790
|
+
cellWidth: cellTime / newTick
|
|
791
|
+
};
|
|
792
|
+
};
|
|
761
793
|
|
|
762
794
|
// src/canvas/draw-events.ts
|
|
763
|
-
var EVENT_RADIUS = 5;
|
|
764
795
|
var EVENT_TEXT_INSET = 13;
|
|
765
796
|
var HANDLE_INSET = 4;
|
|
766
797
|
var HANDLE_BAR_WIDTH = 3;
|
|
@@ -831,7 +862,7 @@ var drawResizeHandles = (ctx, rect, alpha, strokeColor) => {
|
|
|
831
862
|
}
|
|
832
863
|
ctx.restore();
|
|
833
864
|
};
|
|
834
|
-
var defaultDrawEvent = (ctx, event, rect, view, font) => {
|
|
865
|
+
var defaultDrawEvent = (ctx, event, rect, view, font, barRadius) => {
|
|
835
866
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
836
867
|
const theme = view.theme;
|
|
837
868
|
const style = (_a = event.props) == null ? void 0 : _a.style;
|
|
@@ -845,7 +876,7 @@ var defaultDrawEvent = (ctx, event, rect, view, font) => {
|
|
|
845
876
|
rect.y + 0.5,
|
|
846
877
|
rect.width - 1,
|
|
847
878
|
rect.height - 1,
|
|
848
|
-
(_e = style == null ? void 0 : style.borderRadius) != null ? _e :
|
|
879
|
+
(_e = style == null ? void 0 : style.borderRadius) != null ? _e : barRadius
|
|
849
880
|
);
|
|
850
881
|
ctx.fill();
|
|
851
882
|
ctx.stroke();
|
|
@@ -871,6 +902,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
871
902
|
if (view.tick === null) return;
|
|
872
903
|
const [windowStart, windowEnd] = view.windowTime;
|
|
873
904
|
const tick = view.tick;
|
|
905
|
+
const geometry = scene.getGeometry();
|
|
874
906
|
ctx.font = (_a = view.theme.font) != null ? _a : font;
|
|
875
907
|
ctx.textBaseline = "middle";
|
|
876
908
|
ctx.textAlign = "left";
|
|
@@ -896,10 +928,10 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
896
928
|
roundedRect(
|
|
897
929
|
ctx,
|
|
898
930
|
x,
|
|
899
|
-
rowY +
|
|
931
|
+
rowY + geometry.laneTopOffset,
|
|
900
932
|
width,
|
|
901
|
-
staticEventHeight(lanes.highestLane),
|
|
902
|
-
|
|
933
|
+
staticEventHeight(lanes.highestLane, geometry),
|
|
934
|
+
geometry.barRadius
|
|
903
935
|
);
|
|
904
936
|
ctx.fill();
|
|
905
937
|
}
|
|
@@ -912,7 +944,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
912
944
|
let width = timeToWidth(event.startTime, event.endTime, tick);
|
|
913
945
|
const y = rowY + animator.eventTop(
|
|
914
946
|
event.id,
|
|
915
|
-
laneTop(lanes.laneOf.get(event.id))
|
|
947
|
+
laneTop(lanes.laneOf.get(event.id), geometry)
|
|
916
948
|
);
|
|
917
949
|
const resize = view.resizePreview;
|
|
918
950
|
const resizing = resize !== null && resize.eventId === event.id;
|
|
@@ -924,7 +956,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
924
956
|
width += resize.deltaPx;
|
|
925
957
|
}
|
|
926
958
|
}
|
|
927
|
-
const rect = { x, y, width, height:
|
|
959
|
+
const rect = { x, y, width, height: geometry.barHeight };
|
|
928
960
|
const state = {
|
|
929
961
|
hovered: view.hoveredEventId === event.id,
|
|
930
962
|
dragging: view.draggedEventId === event.id,
|
|
@@ -936,7 +968,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
936
968
|
const custom = (_c = (_b = event.props) == null ? void 0 : _b.drawEvent) != null ? _c : view.drawEvent;
|
|
937
969
|
const drawn = custom !== void 0 && custom(ctx, event, rect, state, view.theme) !== false;
|
|
938
970
|
if (!drawn) {
|
|
939
|
-
defaultDrawEvent(ctx, event, rect, view, font);
|
|
971
|
+
defaultDrawEvent(ctx, event, rect, view, font, geometry.barRadius);
|
|
940
972
|
}
|
|
941
973
|
if (canResizeEvent(event, view.eventsResize)) {
|
|
942
974
|
const alpha = animator.handleAlpha(
|
|
@@ -1031,6 +1063,8 @@ var TimelineRenderer = class {
|
|
|
1031
1063
|
width: this.view.width,
|
|
1032
1064
|
height: this.view.height,
|
|
1033
1065
|
cellWidth: this.view.cellWidth,
|
|
1066
|
+
windowStart: this.view.windowTime[0],
|
|
1067
|
+
tick: this.view.tick,
|
|
1034
1068
|
color: this.view.theme.gridColor
|
|
1035
1069
|
});
|
|
1036
1070
|
drawRowDividers(ctx, this.view, this.scene, this.animator);
|
|
@@ -1050,7 +1084,7 @@ var TimelineRenderer = class {
|
|
|
1050
1084
|
};
|
|
1051
1085
|
|
|
1052
1086
|
// src/hooks/use-canvas-interactions.ts
|
|
1053
|
-
var
|
|
1087
|
+
var import_react5 = require("react");
|
|
1054
1088
|
|
|
1055
1089
|
// src/core/types.ts
|
|
1056
1090
|
var rectContains = (rect, x, y) => x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
|
|
@@ -1058,6 +1092,7 @@ var rectContains = (rect, x, y) => x >= rect.x && x <= rect.x + rect.width && y
|
|
|
1058
1092
|
// src/core/hit-test.ts
|
|
1059
1093
|
var hitTest = (scene, view, x, y) => {
|
|
1060
1094
|
const { windowStart, windowEnd, tick, scrollTop } = view;
|
|
1095
|
+
const geometry = scene.getGeometry();
|
|
1061
1096
|
const yContent = y + scrollTop;
|
|
1062
1097
|
let rowTop = 0;
|
|
1063
1098
|
let rowId = null;
|
|
@@ -1081,9 +1116,9 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1081
1116
|
const event = events[i];
|
|
1082
1117
|
const rect = {
|
|
1083
1118
|
x: timeToX(event.startTime, windowStart, tick),
|
|
1084
|
-
y: rowY + laneTop(lanes.laneOf.get(event.id)),
|
|
1119
|
+
y: rowY + laneTop(lanes.laneOf.get(event.id), geometry),
|
|
1085
1120
|
width: timeToWidth(event.startTime, event.endTime, tick),
|
|
1086
|
-
height:
|
|
1121
|
+
height: geometry.barHeight
|
|
1087
1122
|
};
|
|
1088
1123
|
if (rectContains(rect, x, y)) {
|
|
1089
1124
|
return { kind: "event", event, rowId, rect };
|
|
@@ -1098,9 +1133,9 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1098
1133
|
const event = statics[i];
|
|
1099
1134
|
const rect = {
|
|
1100
1135
|
x: timeToX(event.startTime, windowStart, tick),
|
|
1101
|
-
y: rowY +
|
|
1136
|
+
y: rowY + geometry.laneTopOffset,
|
|
1102
1137
|
width: timeToWidth(event.startTime, event.endTime, tick),
|
|
1103
|
-
height: staticEventHeight(lanes.highestLane)
|
|
1138
|
+
height: staticEventHeight(lanes.highestLane, geometry)
|
|
1104
1139
|
};
|
|
1105
1140
|
if (rectContains(rect, x, y)) {
|
|
1106
1141
|
return { kind: "static", event, rowId, rect };
|
|
@@ -1112,6 +1147,7 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1112
1147
|
// src/hooks/use-canvas-interactions.ts
|
|
1113
1148
|
var DRAG_THRESHOLD_PX = 3;
|
|
1114
1149
|
var RESIZE_HOT_ZONE_PX = 8;
|
|
1150
|
+
var DRAG_ZOOM_PX_PER_DOUBLING = 300;
|
|
1115
1151
|
var lockCursor = (cursor) => {
|
|
1116
1152
|
const style = document.createElement("style");
|
|
1117
1153
|
style.id = "lock-cursor";
|
|
@@ -1131,6 +1167,7 @@ var useCanvasInteractions = ({
|
|
|
1131
1167
|
eventPromptRef,
|
|
1132
1168
|
setWindowTime,
|
|
1133
1169
|
setCellWidth,
|
|
1170
|
+
setTick,
|
|
1134
1171
|
onDrop,
|
|
1135
1172
|
onResize,
|
|
1136
1173
|
onEventClick,
|
|
@@ -1138,28 +1175,93 @@ var useCanvasInteractions = ({
|
|
|
1138
1175
|
eventsResize,
|
|
1139
1176
|
panZoom
|
|
1140
1177
|
}) => {
|
|
1141
|
-
const stateRef = (0,
|
|
1142
|
-
const changeGridRef = (0,
|
|
1143
|
-
const panFrameRef = (0,
|
|
1144
|
-
const panPendingDxRef = (0,
|
|
1145
|
-
const hoveredRef = (0,
|
|
1146
|
-
const
|
|
1178
|
+
const stateRef = (0, import_react5.useRef)({ mode: "idle" });
|
|
1179
|
+
const changeGridRef = (0, import_react5.useRef)(false);
|
|
1180
|
+
const panFrameRef = (0, import_react5.useRef)(null);
|
|
1181
|
+
const panPendingDxRef = (0, import_react5.useRef)(0);
|
|
1182
|
+
const hoveredRef = (0, import_react5.useRef)(null);
|
|
1183
|
+
const pointersRef = (0, import_react5.useRef)(/* @__PURE__ */ new Map());
|
|
1184
|
+
const zoomFrameRef = (0, import_react5.useRef)(null);
|
|
1185
|
+
const zoomPendingRef = (0, import_react5.useRef)(null);
|
|
1186
|
+
const config = (0, import_react5.useMemo)(
|
|
1147
1187
|
() => {
|
|
1148
|
-
var _a, _b, _c, _d;
|
|
1188
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1149
1189
|
return {
|
|
1150
1190
|
panOnDragBackground: (_a = panZoom == null ? void 0 : panZoom.panOnDragBackground) != null ? _a : true,
|
|
1151
1191
|
ctrlWheelZoom: (_b = panZoom == null ? void 0 : panZoom.ctrlWheelZoom) != null ? _b : true,
|
|
1152
|
-
|
|
1153
|
-
|
|
1192
|
+
pinchZoom: (_c = panZoom == null ? void 0 : panZoom.pinchZoom) != null ? _c : true,
|
|
1193
|
+
dragZoom: (_d = panZoom == null ? void 0 : panZoom.dragZoom) != null ? _d : true,
|
|
1194
|
+
zoomWheelFactor: (_e = panZoom == null ? void 0 : panZoom.zoomWheelFactor) != null ? _e : 1.15,
|
|
1195
|
+
middleClickGranularity: (_f = panZoom == null ? void 0 : panZoom.middleClickGranularity) != null ? _f : true,
|
|
1196
|
+
zoomStepSeconds: (_g = panZoom == null ? void 0 : panZoom.zoomStepSeconds) != null ? _g : 900
|
|
1154
1197
|
};
|
|
1155
1198
|
},
|
|
1156
1199
|
[panZoom]
|
|
1157
1200
|
);
|
|
1158
|
-
const
|
|
1201
|
+
const limits = (0, import_react5.useMemo)(
|
|
1202
|
+
() => {
|
|
1203
|
+
var _a, _b;
|
|
1204
|
+
return {
|
|
1205
|
+
minWindowSeconds: (_a = panZoom == null ? void 0 : panZoom.minWindowSeconds) != null ? _a : 900,
|
|
1206
|
+
maxWindowSeconds: (_b = panZoom == null ? void 0 : panZoom.maxWindowSeconds) != null ? _b : 30 * 24 * 3600
|
|
1207
|
+
};
|
|
1208
|
+
},
|
|
1209
|
+
[panZoom]
|
|
1210
|
+
);
|
|
1211
|
+
const applyZoom = (0, import_react5.useCallback)(
|
|
1212
|
+
(base, anchorX, factor, contentWidth) => {
|
|
1213
|
+
var _a;
|
|
1214
|
+
if (contentWidth <= 0) return;
|
|
1215
|
+
const next = computeZoom(
|
|
1216
|
+
base.windowTime,
|
|
1217
|
+
base.tick,
|
|
1218
|
+
base.cellWidth,
|
|
1219
|
+
anchorX,
|
|
1220
|
+
factor,
|
|
1221
|
+
contentWidth,
|
|
1222
|
+
limits
|
|
1223
|
+
);
|
|
1224
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({
|
|
1225
|
+
windowTime: next.windowTime,
|
|
1226
|
+
tick: next.tick,
|
|
1227
|
+
cellWidth: next.cellWidth
|
|
1228
|
+
});
|
|
1229
|
+
setWindowTime(next.windowTime);
|
|
1230
|
+
setTick(next.tick);
|
|
1231
|
+
setCellWidth(next.cellWidth);
|
|
1232
|
+
},
|
|
1233
|
+
[rendererRef, setWindowTime, setTick, setCellWidth, limits]
|
|
1234
|
+
);
|
|
1235
|
+
const scheduleContinuousZoom = (0, import_react5.useCallback)(() => {
|
|
1236
|
+
if (zoomFrameRef.current !== null) return;
|
|
1237
|
+
zoomFrameRef.current = requestAnimationFrame(() => {
|
|
1238
|
+
zoomFrameRef.current = null;
|
|
1239
|
+
const pending = zoomPendingRef.current;
|
|
1240
|
+
const state = stateRef.current;
|
|
1241
|
+
if (!pending || state.mode !== "pinch" && state.mode !== "zoom") return;
|
|
1242
|
+
applyZoom(state.snapshot, pending.anchorX, pending.factor, state.contentWidth);
|
|
1243
|
+
});
|
|
1244
|
+
}, [applyZoom]);
|
|
1245
|
+
const snapshotView = (0, import_react5.useCallback)(() => {
|
|
1246
|
+
const renderer = rendererRef.current;
|
|
1247
|
+
const canvas = dynamicCanvasRef.current;
|
|
1248
|
+
if (!renderer || !canvas) return null;
|
|
1249
|
+
const view = renderer.getView();
|
|
1250
|
+
if (view.tick === null) return null;
|
|
1251
|
+
return {
|
|
1252
|
+
base: {
|
|
1253
|
+
windowTime: [view.windowTime[0], view.windowTime[1]],
|
|
1254
|
+
tick: view.tick,
|
|
1255
|
+
cellWidth: view.cellWidth
|
|
1256
|
+
},
|
|
1257
|
+
contentWidth: canvas.getBoundingClientRect().width
|
|
1258
|
+
};
|
|
1259
|
+
}, [rendererRef, dynamicCanvasRef]);
|
|
1260
|
+
const hidePrompt = (0, import_react5.useCallback)(() => {
|
|
1159
1261
|
var _a;
|
|
1160
1262
|
(_a = eventPromptRef.current) == null ? void 0 : _a.hide();
|
|
1161
1263
|
}, [eventPromptRef]);
|
|
1162
|
-
const currentHit = (0,
|
|
1264
|
+
const currentHit = (0, import_react5.useCallback)(
|
|
1163
1265
|
(clientX, clientY) => {
|
|
1164
1266
|
const canvas = dynamicCanvasRef.current;
|
|
1165
1267
|
const renderer = rendererRef.current;
|
|
@@ -1181,7 +1283,7 @@ var useCanvasInteractions = ({
|
|
|
1181
1283
|
},
|
|
1182
1284
|
[scene, dynamicCanvasRef, rendererRef]
|
|
1183
1285
|
);
|
|
1184
|
-
const resizeDirectionAt = (0,
|
|
1286
|
+
const resizeDirectionAt = (0, import_react5.useCallback)(
|
|
1185
1287
|
(hit, clientX) => {
|
|
1186
1288
|
if (hit.kind !== "event" || !canResizeEvent(hit.event, eventsResize)) {
|
|
1187
1289
|
return null;
|
|
@@ -1196,7 +1298,7 @@ var useCanvasInteractions = ({
|
|
|
1196
1298
|
},
|
|
1197
1299
|
[dynamicCanvasRef, eventsResize]
|
|
1198
1300
|
);
|
|
1199
|
-
const schedulePan = (0,
|
|
1301
|
+
const schedulePan = (0, import_react5.useCallback)(() => {
|
|
1200
1302
|
if (panFrameRef.current !== null) return;
|
|
1201
1303
|
panFrameRef.current = requestAnimationFrame(() => {
|
|
1202
1304
|
panFrameRef.current = null;
|
|
@@ -1213,7 +1315,7 @@ var useCanvasInteractions = ({
|
|
|
1213
1315
|
setWindowTime((prev) => [prev[0] - dt, prev[1] - dt]);
|
|
1214
1316
|
});
|
|
1215
1317
|
}, [rendererRef, setWindowTime]);
|
|
1216
|
-
const updateGhost = (0,
|
|
1318
|
+
const updateGhost = (0, import_react5.useCallback)(
|
|
1217
1319
|
(state, clientX, clientY) => {
|
|
1218
1320
|
const ghost = ghostRef.current;
|
|
1219
1321
|
if (!ghost) return;
|
|
@@ -1224,14 +1326,61 @@ var useCanvasInteractions = ({
|
|
|
1224
1326
|
},
|
|
1225
1327
|
[ghostRef]
|
|
1226
1328
|
);
|
|
1227
|
-
const
|
|
1329
|
+
const styleGhost = (0, import_react5.useCallback)(
|
|
1330
|
+
(event) => {
|
|
1331
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1332
|
+
const ghost = ghostRef.current;
|
|
1333
|
+
const theme = (_a = rendererRef.current) == null ? void 0 : _a.getView().theme;
|
|
1334
|
+
if (!ghost || !theme) return;
|
|
1335
|
+
const style = (_b = event.props) == null ? void 0 : _b.style;
|
|
1336
|
+
ghost.style.backgroundColor = (_c = style == null ? void 0 : style.fill) != null ? _c : theme.eventFill;
|
|
1337
|
+
ghost.style.border = `${(_d = style == null ? void 0 : style.strokeWidth) != null ? _d : 1}px solid ${(_e = style == null ? void 0 : style.stroke) != null ? _e : theme.eventStroke}`;
|
|
1338
|
+
ghost.style.borderRadius = `${(_f = style == null ? void 0 : style.borderRadius) != null ? _f : theme.barRadius}px`;
|
|
1339
|
+
ghost.style.color = (_g = style == null ? void 0 : style.textColor) != null ? _g : theme.eventTextColor;
|
|
1340
|
+
ghost.style.font = (_i = (_h = style == null ? void 0 : style.font) != null ? _h : theme.font) != null ? _i : "";
|
|
1341
|
+
ghost.style.justifyContent = "flex-start";
|
|
1342
|
+
ghost.style.alignItems = "center";
|
|
1343
|
+
ghost.style.paddingInline = "13px";
|
|
1344
|
+
ghost.style.overflow = "hidden";
|
|
1345
|
+
ghost.style.whiteSpace = "nowrap";
|
|
1346
|
+
ghost.textContent = (_k = (_j = event.props) == null ? void 0 : _j.label) != null ? _k : "";
|
|
1347
|
+
},
|
|
1348
|
+
[ghostRef, rendererRef]
|
|
1349
|
+
);
|
|
1350
|
+
const handlePointerDown = (0, import_react5.useCallback)(
|
|
1228
1351
|
(pointerEvent) => {
|
|
1229
|
-
var _a;
|
|
1230
|
-
if (pointerEvent.button !== 0) return;
|
|
1352
|
+
var _a, _b;
|
|
1231
1353
|
const canvas = dynamicCanvasRef.current;
|
|
1232
1354
|
if (!canvas) return;
|
|
1355
|
+
const isTouch = pointerEvent.pointerType === "touch";
|
|
1356
|
+
pointersRef.current.set(pointerEvent.pointerId, {
|
|
1357
|
+
x: pointerEvent.clientX,
|
|
1358
|
+
y: pointerEvent.clientY,
|
|
1359
|
+
touch: isTouch
|
|
1360
|
+
});
|
|
1361
|
+
if (config.pinchZoom && isTouch && pointersRef.current.size === 2) {
|
|
1362
|
+
const snap = snapshotView();
|
|
1363
|
+
if (snap) {
|
|
1364
|
+
if (ghostRef.current) ghostRef.current.style.display = "none";
|
|
1365
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null });
|
|
1366
|
+
const pts = [...pointersRef.current.values()];
|
|
1367
|
+
const startDist = Math.hypot(pts[0].x - pts[1].x, pts[0].y - pts[1].y) || 1;
|
|
1368
|
+
const rect = canvas.getBoundingClientRect();
|
|
1369
|
+
stateRef.current = {
|
|
1370
|
+
mode: "pinch",
|
|
1371
|
+
startDist,
|
|
1372
|
+
anchorX: (pts[0].x + pts[1].x) / 2 - rect.left,
|
|
1373
|
+
contentWidth: snap.contentWidth,
|
|
1374
|
+
snapshot: snap.base
|
|
1375
|
+
};
|
|
1376
|
+
canvas.setPointerCapture(pointerEvent.pointerId);
|
|
1377
|
+
hidePrompt();
|
|
1378
|
+
}
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1381
|
+
if (pointerEvent.button !== 0) return;
|
|
1233
1382
|
const hit = currentHit(pointerEvent.clientX, pointerEvent.clientY);
|
|
1234
|
-
if ((hit == null ? void 0 : hit.kind) === "event" && !((
|
|
1383
|
+
if ((hit == null ? void 0 : hit.kind) === "event" && !((_b = hit.event.props) == null ? void 0 : _b.isLocked)) {
|
|
1235
1384
|
const direction = resizeDirectionAt(hit, pointerEvent.clientX);
|
|
1236
1385
|
if (direction) {
|
|
1237
1386
|
stateRef.current = {
|
|
@@ -1250,9 +1399,26 @@ var useCanvasInteractions = ({
|
|
|
1250
1399
|
startClientY: pointerEvent.clientY,
|
|
1251
1400
|
active: false
|
|
1252
1401
|
};
|
|
1402
|
+
styleGhost(hit.event);
|
|
1253
1403
|
}
|
|
1404
|
+
} else if (config.dragZoom && (pointerEvent.ctrlKey || pointerEvent.metaKey) && !isTouch) {
|
|
1405
|
+
const snap = snapshotView();
|
|
1406
|
+
if (!snap) return;
|
|
1407
|
+
const rect = canvas.getBoundingClientRect();
|
|
1408
|
+
stateRef.current = {
|
|
1409
|
+
mode: "zoom",
|
|
1410
|
+
startClientX: pointerEvent.clientX,
|
|
1411
|
+
anchorX: pointerEvent.clientX - rect.left,
|
|
1412
|
+
contentWidth: snap.contentWidth,
|
|
1413
|
+
snapshot: snap.base
|
|
1414
|
+
};
|
|
1254
1415
|
} else if (config.panOnDragBackground) {
|
|
1255
|
-
stateRef.current = {
|
|
1416
|
+
stateRef.current = {
|
|
1417
|
+
mode: "pan",
|
|
1418
|
+
lastClientX: pointerEvent.clientX,
|
|
1419
|
+
lastClientY: pointerEvent.clientY,
|
|
1420
|
+
touch: isTouch
|
|
1421
|
+
};
|
|
1256
1422
|
canvas.style.cursor = "grabbing";
|
|
1257
1423
|
} else {
|
|
1258
1424
|
return;
|
|
@@ -1260,9 +1426,19 @@ var useCanvasInteractions = ({
|
|
|
1260
1426
|
hidePrompt();
|
|
1261
1427
|
canvas.setPointerCapture(pointerEvent.pointerId);
|
|
1262
1428
|
},
|
|
1263
|
-
[
|
|
1429
|
+
[
|
|
1430
|
+
currentHit,
|
|
1431
|
+
resizeDirectionAt,
|
|
1432
|
+
dynamicCanvasRef,
|
|
1433
|
+
hidePrompt,
|
|
1434
|
+
config,
|
|
1435
|
+
snapshotView,
|
|
1436
|
+
ghostRef,
|
|
1437
|
+
rendererRef,
|
|
1438
|
+
styleGhost
|
|
1439
|
+
]
|
|
1264
1440
|
);
|
|
1265
|
-
const handleHover = (0,
|
|
1441
|
+
const handleHover = (0, import_react5.useCallback)(
|
|
1266
1442
|
(pointerEvent) => {
|
|
1267
1443
|
var _a, _b, _c, _d;
|
|
1268
1444
|
const canvas = dynamicCanvasRef.current;
|
|
@@ -1317,17 +1493,48 @@ var useCanvasInteractions = ({
|
|
|
1317
1493
|
onEventHover
|
|
1318
1494
|
]
|
|
1319
1495
|
);
|
|
1320
|
-
const handlePointerMove = (0,
|
|
1496
|
+
const handlePointerMove = (0, import_react5.useCallback)(
|
|
1321
1497
|
(pointerEvent) => {
|
|
1322
1498
|
var _a, _b;
|
|
1499
|
+
const tracked = pointersRef.current.get(pointerEvent.pointerId);
|
|
1500
|
+
if (tracked) {
|
|
1501
|
+
tracked.x = pointerEvent.clientX;
|
|
1502
|
+
tracked.y = pointerEvent.clientY;
|
|
1503
|
+
}
|
|
1323
1504
|
const state = stateRef.current;
|
|
1324
1505
|
if (state.mode === "idle") {
|
|
1325
1506
|
handleHover(pointerEvent);
|
|
1326
1507
|
return;
|
|
1327
1508
|
}
|
|
1509
|
+
if (state.mode === "pinch") {
|
|
1510
|
+
const pts = [...pointersRef.current.values()];
|
|
1511
|
+
if (pts.length < 2) return;
|
|
1512
|
+
const dist = Math.hypot(pts[0].x - pts[1].x, pts[0].y - pts[1].y) || 1;
|
|
1513
|
+
zoomPendingRef.current = {
|
|
1514
|
+
anchorX: state.anchorX,
|
|
1515
|
+
factor: state.startDist / dist
|
|
1516
|
+
// fingers apart -> factor<1 -> zoom in
|
|
1517
|
+
};
|
|
1518
|
+
scheduleContinuousZoom();
|
|
1519
|
+
return;
|
|
1520
|
+
}
|
|
1521
|
+
if (state.mode === "zoom") {
|
|
1522
|
+
const dx = pointerEvent.clientX - state.startClientX;
|
|
1523
|
+
zoomPendingRef.current = {
|
|
1524
|
+
anchorX: state.anchorX,
|
|
1525
|
+
factor: Math.pow(2, -dx / DRAG_ZOOM_PX_PER_DOUBLING)
|
|
1526
|
+
// right -> zoom in
|
|
1527
|
+
};
|
|
1528
|
+
scheduleContinuousZoom();
|
|
1529
|
+
return;
|
|
1530
|
+
}
|
|
1328
1531
|
if (state.mode === "pan") {
|
|
1329
1532
|
panPendingDxRef.current += pointerEvent.clientX - state.lastClientX;
|
|
1533
|
+
if (state.touch && bodyRef.current) {
|
|
1534
|
+
bodyRef.current.scrollTop -= pointerEvent.clientY - state.lastClientY;
|
|
1535
|
+
}
|
|
1330
1536
|
state.lastClientX = pointerEvent.clientX;
|
|
1537
|
+
state.lastClientY = pointerEvent.clientY;
|
|
1331
1538
|
schedulePan();
|
|
1332
1539
|
return;
|
|
1333
1540
|
}
|
|
@@ -1350,9 +1557,16 @@ var useCanvasInteractions = ({
|
|
|
1350
1557
|
}
|
|
1351
1558
|
});
|
|
1352
1559
|
},
|
|
1353
|
-
[
|
|
1560
|
+
[
|
|
1561
|
+
handleHover,
|
|
1562
|
+
schedulePan,
|
|
1563
|
+
updateGhost,
|
|
1564
|
+
rendererRef,
|
|
1565
|
+
scheduleContinuousZoom,
|
|
1566
|
+
bodyRef
|
|
1567
|
+
]
|
|
1354
1568
|
);
|
|
1355
|
-
const commitDrop = (0,
|
|
1569
|
+
const commitDrop = (0, import_react5.useCallback)(
|
|
1356
1570
|
(state, clientX, clientY) => {
|
|
1357
1571
|
const canvas = dynamicCanvasRef.current;
|
|
1358
1572
|
const renderer = rendererRef.current;
|
|
@@ -1405,7 +1619,7 @@ var useCanvasInteractions = ({
|
|
|
1405
1619
|
},
|
|
1406
1620
|
[scene, dynamicCanvasRef, rendererRef, onDrop]
|
|
1407
1621
|
);
|
|
1408
|
-
const commitResize = (0,
|
|
1622
|
+
const commitResize = (0, import_react5.useCallback)(
|
|
1409
1623
|
(state) => {
|
|
1410
1624
|
const renderer = rendererRef.current;
|
|
1411
1625
|
const tick = renderer == null ? void 0 : renderer.getView().tick;
|
|
@@ -1435,11 +1649,12 @@ var useCanvasInteractions = ({
|
|
|
1435
1649
|
},
|
|
1436
1650
|
[scene, rendererRef, onResize]
|
|
1437
1651
|
);
|
|
1438
|
-
const handlePointerUp = (0,
|
|
1652
|
+
const handlePointerUp = (0, import_react5.useCallback)(
|
|
1439
1653
|
(pointerEvent) => {
|
|
1440
1654
|
var _a;
|
|
1441
1655
|
const canvas = dynamicCanvasRef.current;
|
|
1442
1656
|
const state = stateRef.current;
|
|
1657
|
+
pointersRef.current.delete(pointerEvent.pointerId);
|
|
1443
1658
|
stateRef.current = { mode: "idle" };
|
|
1444
1659
|
if (canvas == null ? void 0 : canvas.hasPointerCapture(pointerEvent.pointerId)) {
|
|
1445
1660
|
canvas.releasePointerCapture(pointerEvent.pointerId);
|
|
@@ -1476,7 +1691,21 @@ var useCanvasInteractions = ({
|
|
|
1476
1691
|
onEventClick
|
|
1477
1692
|
]
|
|
1478
1693
|
);
|
|
1479
|
-
const
|
|
1694
|
+
const handlePointerCancel = (0, import_react5.useCallback)(
|
|
1695
|
+
(pointerEvent) => {
|
|
1696
|
+
var _a;
|
|
1697
|
+
pointersRef.current.delete(pointerEvent.pointerId);
|
|
1698
|
+
stateRef.current = { mode: "idle" };
|
|
1699
|
+
const canvas = dynamicCanvasRef.current;
|
|
1700
|
+
if (canvas == null ? void 0 : canvas.hasPointerCapture(pointerEvent.pointerId)) {
|
|
1701
|
+
canvas.releasePointerCapture(pointerEvent.pointerId);
|
|
1702
|
+
}
|
|
1703
|
+
if (ghostRef.current) ghostRef.current.style.display = "none";
|
|
1704
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null });
|
|
1705
|
+
},
|
|
1706
|
+
[dynamicCanvasRef, ghostRef, rendererRef]
|
|
1707
|
+
);
|
|
1708
|
+
const handlePointerLeave = (0, import_react5.useCallback)(() => {
|
|
1480
1709
|
var _a, _b;
|
|
1481
1710
|
if (stateRef.current.mode !== "idle") return;
|
|
1482
1711
|
if (((_a = hoveredRef.current) == null ? void 0 : _a.kind) === "event") {
|
|
@@ -1489,7 +1718,7 @@ var useCanvasInteractions = ({
|
|
|
1489
1718
|
}
|
|
1490
1719
|
hidePrompt();
|
|
1491
1720
|
}, [dynamicCanvasRef, rendererRef, hidePrompt, onEventHover]);
|
|
1492
|
-
const handleAuxClick = (0,
|
|
1721
|
+
const handleAuxClick = (0, import_react5.useCallback)(
|
|
1493
1722
|
(pointerEvent) => {
|
|
1494
1723
|
pointerEvent.preventDefault();
|
|
1495
1724
|
if (pointerEvent.button === 1 && config.middleClickGranularity) {
|
|
@@ -1501,40 +1730,59 @@ var useCanvasInteractions = ({
|
|
|
1501
1730
|
},
|
|
1502
1731
|
[bodyRef, config]
|
|
1503
1732
|
);
|
|
1504
|
-
(0,
|
|
1733
|
+
(0, import_react5.useEffect)(() => {
|
|
1505
1734
|
const canvas = dynamicCanvasRef.current;
|
|
1506
1735
|
if (!canvas) return;
|
|
1507
1736
|
const handleWheel = (wheelEvent) => {
|
|
1508
1737
|
var _a;
|
|
1509
|
-
const
|
|
1510
|
-
if (!
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1738
|
+
const view = (_a = rendererRef.current) == null ? void 0 : _a.getView();
|
|
1739
|
+
if (!view || view.tick === null) return;
|
|
1740
|
+
const tick = view.tick;
|
|
1741
|
+
if (changeGridRef.current) {
|
|
1742
|
+
wheelEvent.preventDefault();
|
|
1743
|
+
setCellWidth(
|
|
1744
|
+
(cellWidth) => stepCellWidth(
|
|
1745
|
+
cellWidth,
|
|
1746
|
+
wheelEvent.deltaY,
|
|
1747
|
+
tick * 900 / config.zoomStepSeconds
|
|
1748
|
+
)
|
|
1749
|
+
);
|
|
1750
|
+
return;
|
|
1751
|
+
}
|
|
1752
|
+
if ((wheelEvent.ctrlKey || wheelEvent.metaKey) && config.ctrlWheelZoom) {
|
|
1753
|
+
wheelEvent.preventDefault();
|
|
1754
|
+
const rect = canvas.getBoundingClientRect();
|
|
1755
|
+
const factor = wheelEvent.deltaY > 0 ? config.zoomWheelFactor : 1 / config.zoomWheelFactor;
|
|
1756
|
+
applyZoom(
|
|
1757
|
+
{
|
|
1758
|
+
windowTime: [view.windowTime[0], view.windowTime[1]],
|
|
1759
|
+
tick,
|
|
1760
|
+
cellWidth: view.cellWidth
|
|
1761
|
+
},
|
|
1762
|
+
wheelEvent.clientX - rect.left,
|
|
1763
|
+
factor,
|
|
1764
|
+
rect.width
|
|
1765
|
+
);
|
|
1766
|
+
return;
|
|
1767
|
+
}
|
|
1521
1768
|
};
|
|
1522
1769
|
canvas.addEventListener("wheel", handleWheel, { passive: false });
|
|
1523
1770
|
return () => canvas.removeEventListener("wheel", handleWheel);
|
|
1524
|
-
}, [dynamicCanvasRef, rendererRef, setCellWidth, config]);
|
|
1525
|
-
(0,
|
|
1771
|
+
}, [dynamicCanvasRef, rendererRef, setCellWidth, applyZoom, config]);
|
|
1772
|
+
(0, import_react5.useEffect)(() => unlockCursor, []);
|
|
1526
1773
|
return {
|
|
1527
1774
|
handlePointerDown,
|
|
1528
1775
|
handlePointerMove,
|
|
1529
1776
|
handlePointerUp,
|
|
1530
1777
|
handlePointerLeave,
|
|
1778
|
+
handlePointerCancel,
|
|
1531
1779
|
handleAuxClick
|
|
1532
1780
|
};
|
|
1533
1781
|
};
|
|
1534
1782
|
var use_canvas_interactions_default = useCanvasInteractions;
|
|
1535
1783
|
|
|
1536
1784
|
// src/components/canvas-board.tsx
|
|
1537
|
-
var CanvasBoard = (0,
|
|
1785
|
+
var CanvasBoard = (0, import_react6.forwardRef)(
|
|
1538
1786
|
({
|
|
1539
1787
|
scene,
|
|
1540
1788
|
rows,
|
|
@@ -1549,6 +1797,7 @@ var CanvasBoard = (0, import_react7.forwardRef)(
|
|
|
1549
1797
|
rowsHeaderClassName,
|
|
1550
1798
|
setWindowTime,
|
|
1551
1799
|
setCellWidth,
|
|
1800
|
+
setTick,
|
|
1552
1801
|
onDrop,
|
|
1553
1802
|
onResize,
|
|
1554
1803
|
onEventClick,
|
|
@@ -1557,12 +1806,12 @@ var CanvasBoard = (0, import_react7.forwardRef)(
|
|
|
1557
1806
|
panZoom,
|
|
1558
1807
|
animations
|
|
1559
1808
|
}, contentRef) => {
|
|
1560
|
-
const staticCanvasRef = (0,
|
|
1561
|
-
const dynamicCanvasRef = (0,
|
|
1562
|
-
const ghostRef = (0,
|
|
1563
|
-
const [scrollTop, setScrollTop] = (0,
|
|
1564
|
-
const [viewportHeight, setViewportHeight] = (0,
|
|
1565
|
-
(0,
|
|
1809
|
+
const staticCanvasRef = (0, import_react6.useRef)(null);
|
|
1810
|
+
const dynamicCanvasRef = (0, import_react6.useRef)(null);
|
|
1811
|
+
const ghostRef = (0, import_react6.useRef)(null);
|
|
1812
|
+
const [scrollTop, setScrollTop] = (0, import_react6.useState)(0);
|
|
1813
|
+
const [viewportHeight, setViewportHeight] = (0, import_react6.useState)(0);
|
|
1814
|
+
(0, import_react6.useEffect)(() => {
|
|
1566
1815
|
if (!staticCanvasRef.current || !dynamicCanvasRef.current) return;
|
|
1567
1816
|
const renderer = new TimelineRenderer(
|
|
1568
1817
|
staticCanvasRef.current,
|
|
@@ -1575,7 +1824,7 @@ var CanvasBoard = (0, import_react7.forwardRef)(
|
|
|
1575
1824
|
rendererRef.current = null;
|
|
1576
1825
|
};
|
|
1577
1826
|
}, [scene, rendererRef]);
|
|
1578
|
-
(0,
|
|
1827
|
+
(0, import_react6.useEffect)(() => {
|
|
1579
1828
|
var _a, _b;
|
|
1580
1829
|
(_a = rendererRef.current) == null ? void 0 : _a.animator.setDurations(
|
|
1581
1830
|
animations.layoutMs,
|
|
@@ -1599,7 +1848,7 @@ var CanvasBoard = (0, import_react7.forwardRef)(
|
|
|
1599
1848
|
animations,
|
|
1600
1849
|
rendererRef
|
|
1601
1850
|
]);
|
|
1602
|
-
(0,
|
|
1851
|
+
(0, import_react6.useEffect)(() => {
|
|
1603
1852
|
const column = contentRef && "current" in contentRef ? contentRef.current : null;
|
|
1604
1853
|
const body = bodyRef.current;
|
|
1605
1854
|
if (!column || !body) return;
|
|
@@ -1618,7 +1867,7 @@ var CanvasBoard = (0, import_react7.forwardRef)(
|
|
|
1618
1867
|
observer.observe(body);
|
|
1619
1868
|
return () => observer.disconnect();
|
|
1620
1869
|
}, [bodyRef, contentRef, rendererRef]);
|
|
1621
|
-
(0,
|
|
1870
|
+
(0, import_react6.useEffect)(() => {
|
|
1622
1871
|
const body = bodyRef.current;
|
|
1623
1872
|
if (!body) return;
|
|
1624
1873
|
const handleScroll = () => {
|
|
@@ -1629,8 +1878,8 @@ var CanvasBoard = (0, import_react7.forwardRef)(
|
|
|
1629
1878
|
body.addEventListener("scroll", handleScroll, { passive: true });
|
|
1630
1879
|
return () => body.removeEventListener("scroll", handleScroll);
|
|
1631
1880
|
}, [bodyRef, rendererRef]);
|
|
1632
|
-
(0,
|
|
1633
|
-
(0,
|
|
1881
|
+
(0, import_react6.useSyncExternalStore)(
|
|
1882
|
+
(0, import_react6.useCallback)((listener) => scene.subscribe(listener), [scene]),
|
|
1634
1883
|
() => scene.version
|
|
1635
1884
|
);
|
|
1636
1885
|
const {
|
|
@@ -1638,6 +1887,7 @@ var CanvasBoard = (0, import_react7.forwardRef)(
|
|
|
1638
1887
|
handlePointerMove,
|
|
1639
1888
|
handlePointerUp,
|
|
1640
1889
|
handlePointerLeave,
|
|
1890
|
+
handlePointerCancel,
|
|
1641
1891
|
handleAuxClick
|
|
1642
1892
|
} = use_canvas_interactions_default({
|
|
1643
1893
|
scene,
|
|
@@ -1648,6 +1898,7 @@ var CanvasBoard = (0, import_react7.forwardRef)(
|
|
|
1648
1898
|
eventPromptRef,
|
|
1649
1899
|
setWindowTime,
|
|
1650
1900
|
setCellWidth,
|
|
1901
|
+
setTick,
|
|
1651
1902
|
onDrop,
|
|
1652
1903
|
onResize,
|
|
1653
1904
|
onEventClick,
|
|
@@ -1667,7 +1918,7 @@ var CanvasBoard = (0, import_react7.forwardRef)(
|
|
|
1667
1918
|
if (top + height < scrollTop) continue;
|
|
1668
1919
|
if (top > scrollTop + viewportHeight) break;
|
|
1669
1920
|
visibleHeaders.push(
|
|
1670
|
-
/* @__PURE__ */
|
|
1921
|
+
/* @__PURE__ */ import_react6.default.createElement(
|
|
1671
1922
|
"div",
|
|
1672
1923
|
{
|
|
1673
1924
|
key: `row_header_${row.id}`,
|
|
@@ -1685,7 +1936,7 @@ var CanvasBoard = (0, import_react7.forwardRef)(
|
|
|
1685
1936
|
);
|
|
1686
1937
|
}
|
|
1687
1938
|
const headerClassNames = rowsHeaderClassName ? `rows-header-wrapper canvas-rows-header ${rowsHeaderClassName}` : "rows-header-wrapper canvas-rows-header";
|
|
1688
|
-
return /* @__PURE__ */
|
|
1939
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, /* @__PURE__ */ import_react6.default.createElement("div", { className: headerClassNames, style: { height: totalHeight } }, visibleHeaders), /* @__PURE__ */ import_react6.default.createElement("div", { className: "canvas-content-column", ref: contentRef }, /* @__PURE__ */ import_react6.default.createElement("div", { className: "canvas-sticky" }, /* @__PURE__ */ import_react6.default.createElement("canvas", { ref: staticCanvasRef }), /* @__PURE__ */ import_react6.default.createElement(
|
|
1689
1940
|
"canvas",
|
|
1690
1941
|
{
|
|
1691
1942
|
ref: dynamicCanvasRef,
|
|
@@ -1693,9 +1944,17 @@ var CanvasBoard = (0, import_react7.forwardRef)(
|
|
|
1693
1944
|
onPointerMove: handlePointerMove,
|
|
1694
1945
|
onPointerUp: handlePointerUp,
|
|
1695
1946
|
onPointerLeave: handlePointerLeave,
|
|
1947
|
+
onPointerCancel: handlePointerCancel,
|
|
1696
1948
|
onAuxClick: handleAuxClick
|
|
1697
1949
|
}
|
|
1698
|
-
), /* @__PURE__ */
|
|
1950
|
+
), /* @__PURE__ */ import_react6.default.createElement(
|
|
1951
|
+
"div",
|
|
1952
|
+
{
|
|
1953
|
+
ref: ghostRef,
|
|
1954
|
+
className: "event canvas-drag-ghost",
|
|
1955
|
+
style: { height: scene.getGeometry().barHeight }
|
|
1956
|
+
}
|
|
1957
|
+
)), /* @__PURE__ */ import_react6.default.createElement(
|
|
1699
1958
|
"div",
|
|
1700
1959
|
{
|
|
1701
1960
|
className: "canvas-scroll-spacer",
|
|
@@ -1726,8 +1985,19 @@ var SceneStore = class {
|
|
|
1726
1985
|
this.rowOrder = [];
|
|
1727
1986
|
this.eventRow = /* @__PURE__ */ new Map();
|
|
1728
1987
|
this.listeners = /* @__PURE__ */ new Set();
|
|
1988
|
+
// Themeable vertical layout. Lanes are geometry-free (pure time logic), so a
|
|
1989
|
+
// geometry change only affects heights/offsets — the cached lanes stay valid
|
|
1990
|
+
// and we just bump to trigger a redraw.
|
|
1991
|
+
this.geometry = DEFAULT_GEOMETRY;
|
|
1729
1992
|
this.version = 0;
|
|
1730
1993
|
}
|
|
1994
|
+
setGeometry(geometry) {
|
|
1995
|
+
this.geometry = geometry;
|
|
1996
|
+
this.bump();
|
|
1997
|
+
}
|
|
1998
|
+
getGeometry() {
|
|
1999
|
+
return this.geometry;
|
|
2000
|
+
}
|
|
1731
2001
|
setRows(rows) {
|
|
1732
2002
|
const next = /* @__PURE__ */ new Map();
|
|
1733
2003
|
for (const row of rows) {
|
|
@@ -1832,7 +2102,10 @@ var SceneStore = class {
|
|
|
1832
2102
|
return index.lanes;
|
|
1833
2103
|
}
|
|
1834
2104
|
getRowHeight(rowId, windowStart, windowEnd) {
|
|
1835
|
-
return rowMinHeight(
|
|
2105
|
+
return rowMinHeight(
|
|
2106
|
+
this.getLanes(rowId, windowStart, windowEnd).highestLane,
|
|
2107
|
+
this.geometry
|
|
2108
|
+
);
|
|
1836
2109
|
}
|
|
1837
2110
|
/**
|
|
1838
2111
|
* y offset of each row's top edge (content coordinates, before scroll) plus
|
|
@@ -1876,7 +2149,7 @@ var SceneStore = class {
|
|
|
1876
2149
|
};
|
|
1877
2150
|
|
|
1878
2151
|
// src/timeline.tsx
|
|
1879
|
-
var Timeline = (0,
|
|
2152
|
+
var Timeline = (0, import_react7.forwardRef)(
|
|
1880
2153
|
({
|
|
1881
2154
|
rows,
|
|
1882
2155
|
events,
|
|
@@ -1895,9 +2168,10 @@ var Timeline = (0, import_react8.forwardRef)(
|
|
|
1895
2168
|
eventPromptTemplate,
|
|
1896
2169
|
showEventPrompt = true,
|
|
1897
2170
|
panZoom,
|
|
2171
|
+
timeBar,
|
|
1898
2172
|
animations = true
|
|
1899
2173
|
}, handleRef) => {
|
|
1900
|
-
const [windowTime, setWindowTime] = (0,
|
|
2174
|
+
const [windowTime, setWindowTime] = (0, import_react7.useState)([
|
|
1901
2175
|
new Date(
|
|
1902
2176
|
startDate.getFullYear(),
|
|
1903
2177
|
startDate.getMonth(),
|
|
@@ -1915,31 +2189,31 @@ var Timeline = (0, import_react8.forwardRef)(
|
|
|
1915
2189
|
0
|
|
1916
2190
|
).getTime() / 1e3
|
|
1917
2191
|
]);
|
|
1918
|
-
const [cellWidth, setCellWidth] = (0,
|
|
1919
|
-
const contentRef = (0,
|
|
1920
|
-
const mainRef = (0,
|
|
1921
|
-
const bodyRef = (0,
|
|
1922
|
-
const [tick, setTick] = (0,
|
|
1923
|
-
const [scrollWidth, setScrollWidth] = (0,
|
|
1924
|
-
const eventPromptRef = (0,
|
|
1925
|
-
const rendererRef = (0,
|
|
1926
|
-
const sceneRef = (0,
|
|
2192
|
+
const [cellWidth, setCellWidth] = (0, import_react7.useState)(0);
|
|
2193
|
+
const contentRef = (0, import_react7.useRef)(null);
|
|
2194
|
+
const mainRef = (0, import_react7.useRef)(null);
|
|
2195
|
+
const bodyRef = (0, import_react7.useRef)(null);
|
|
2196
|
+
const [tick, setTick] = (0, import_react7.useState)(null);
|
|
2197
|
+
const [scrollWidth, setScrollWidth] = (0, import_react7.useState)(0);
|
|
2198
|
+
const eventPromptRef = (0, import_react7.useRef)(null);
|
|
2199
|
+
const rendererRef = (0, import_react7.useRef)(null);
|
|
2200
|
+
const sceneRef = (0, import_react7.useRef)(null);
|
|
1927
2201
|
if (sceneRef.current === null) {
|
|
1928
2202
|
sceneRef.current = new SceneStore();
|
|
1929
2203
|
}
|
|
1930
2204
|
const scene = sceneRef.current;
|
|
1931
|
-
(0,
|
|
2205
|
+
(0, import_react7.useEffect)(() => {
|
|
1932
2206
|
scene.setRows(rows);
|
|
1933
2207
|
}, [scene, rows]);
|
|
1934
|
-
(0,
|
|
2208
|
+
(0, import_react7.useEffect)(() => {
|
|
1935
2209
|
scene.setEvents([...events].sort(sort_events_default));
|
|
1936
2210
|
}, [scene, events]);
|
|
1937
|
-
(0,
|
|
2211
|
+
(0, import_react7.useEffect)(() => {
|
|
1938
2212
|
scene.setStaticEvents(staticEvents ? [...staticEvents] : []);
|
|
1939
2213
|
}, [scene, staticEvents]);
|
|
1940
|
-
const windowTimeRef = (0,
|
|
2214
|
+
const windowTimeRef = (0, import_react7.useRef)(windowTime);
|
|
1941
2215
|
windowTimeRef.current = windowTime;
|
|
1942
|
-
(0,
|
|
2216
|
+
(0, import_react7.useImperativeHandle)(
|
|
1943
2217
|
handleRef,
|
|
1944
2218
|
() => ({
|
|
1945
2219
|
setEvents: (next) => scene.setEvents([...next].sort(sort_events_default)),
|
|
@@ -1967,7 +2241,7 @@ var Timeline = (0, import_react8.forwardRef)(
|
|
|
1967
2241
|
}),
|
|
1968
2242
|
[scene]
|
|
1969
2243
|
);
|
|
1970
|
-
(0,
|
|
2244
|
+
(0, import_react7.useEffect)(() => {
|
|
1971
2245
|
if (contentRef.current) {
|
|
1972
2246
|
const windowDuration = windowTime[1] - windowTime[0];
|
|
1973
2247
|
const numberOfHourBlocks = windowDuration / 3600;
|
|
@@ -1979,7 +2253,7 @@ var Timeline = (0, import_react8.forwardRef)(
|
|
|
1979
2253
|
);
|
|
1980
2254
|
}
|
|
1981
2255
|
}, []);
|
|
1982
|
-
(0,
|
|
2256
|
+
(0, import_react7.useEffect)(() => {
|
|
1983
2257
|
if (bodyRef.current) {
|
|
1984
2258
|
setScrollWidth(
|
|
1985
2259
|
bodyRef.current.getBoundingClientRect().width - bodyRef.current.scrollWidth
|
|
@@ -1987,8 +2261,15 @@ var Timeline = (0, import_react8.forwardRef)(
|
|
|
1987
2261
|
}
|
|
1988
2262
|
}, []);
|
|
1989
2263
|
use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTime });
|
|
1990
|
-
const resolvedTheme = (0,
|
|
1991
|
-
const
|
|
2264
|
+
const resolvedTheme = (0, import_react7.useMemo)(() => resolveTheme(theme), [theme]);
|
|
2265
|
+
const geometry = (0, import_react7.useMemo)(
|
|
2266
|
+
() => geometryFromTheme(resolvedTheme),
|
|
2267
|
+
[resolvedTheme]
|
|
2268
|
+
);
|
|
2269
|
+
(0, import_react7.useEffect)(() => {
|
|
2270
|
+
scene.setGeometry(geometry);
|
|
2271
|
+
}, [scene, geometry]);
|
|
2272
|
+
const resolvedAnimations = (0, import_react7.useMemo)(() => {
|
|
1992
2273
|
var _a, _b;
|
|
1993
2274
|
if (animations === false) return { layoutMs: 0, fadeMs: 0 };
|
|
1994
2275
|
if (animations === true) {
|
|
@@ -2002,8 +2283,8 @@ var Timeline = (0, import_react8.forwardRef)(
|
|
|
2002
2283
|
fadeMs: (_b = animations.fadeMs) != null ? _b : DEFAULT_FADE_DURATION_MS
|
|
2003
2284
|
};
|
|
2004
2285
|
}, [animations]);
|
|
2005
|
-
const eventPrompt = (0,
|
|
2006
|
-
() => /* @__PURE__ */
|
|
2286
|
+
const eventPrompt = (0, import_react7.useMemo)(
|
|
2287
|
+
() => /* @__PURE__ */ import_react7.default.createElement(
|
|
2007
2288
|
event_prompt_default,
|
|
2008
2289
|
{
|
|
2009
2290
|
ref: eventPromptRef,
|
|
@@ -2012,16 +2293,17 @@ var Timeline = (0, import_react8.forwardRef)(
|
|
|
2012
2293
|
),
|
|
2013
2294
|
[eventPromptTemplate]
|
|
2014
2295
|
);
|
|
2015
|
-
return /* @__PURE__ */
|
|
2296
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ import_react7.default.createElement(rt_indicator_default, { tick, windowTime }), /* @__PURE__ */ import_react7.default.createElement(
|
|
2016
2297
|
canvas_time_bar_default,
|
|
2017
2298
|
{
|
|
2018
2299
|
windowTime,
|
|
2019
2300
|
tick,
|
|
2020
2301
|
contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
|
|
2021
2302
|
scrollWidth,
|
|
2022
|
-
theme: resolvedTheme
|
|
2303
|
+
theme: resolvedTheme,
|
|
2304
|
+
timeBar
|
|
2023
2305
|
}
|
|
2024
|
-
), /* @__PURE__ */
|
|
2306
|
+
), /* @__PURE__ */ import_react7.default.createElement("div", { className: "body-wrapper", ref: bodyRef }, /* @__PURE__ */ import_react7.default.createElement(
|
|
2025
2307
|
canvas_board_default,
|
|
2026
2308
|
{
|
|
2027
2309
|
scene,
|
|
@@ -2037,6 +2319,7 @@ var Timeline = (0, import_react8.forwardRef)(
|
|
|
2037
2319
|
rowsHeaderClassName: additionalClassNames == null ? void 0 : additionalClassNames.rowsHeader,
|
|
2038
2320
|
setWindowTime,
|
|
2039
2321
|
setCellWidth,
|
|
2322
|
+
setTick,
|
|
2040
2323
|
onDrop,
|
|
2041
2324
|
onResize,
|
|
2042
2325
|
onEventClick,
|