awesome-timeline-react 0.2.0 → 0.4.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 +190 -4
- package/dist/_tsup-dts-rollup.d.mts +413 -59
- package/dist/_tsup-dts-rollup.d.ts +413 -59
- package/dist/index.css +9 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1234 -339
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1176 -279
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -21,9 +21,10 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
21
21
|
// src/timeline.tsx
|
|
22
22
|
import React6, {
|
|
23
23
|
forwardRef as forwardRef3,
|
|
24
|
+
useCallback as useCallback3,
|
|
24
25
|
useEffect as useEffect6,
|
|
25
26
|
useImperativeHandle as useImperativeHandle2,
|
|
26
|
-
useMemo as
|
|
27
|
+
useMemo as useMemo3,
|
|
27
28
|
useRef as useRef7,
|
|
28
29
|
useState as useState4
|
|
29
30
|
} from "react";
|
|
@@ -34,7 +35,6 @@ var DEFAULT_FADE_DURATION_MS = 120;
|
|
|
34
35
|
var ease = (t) => t * t * (3 - 2 * t);
|
|
35
36
|
var LayoutAnimator = class {
|
|
36
37
|
constructor() {
|
|
37
|
-
this.rowHeights = /* @__PURE__ */ new Map();
|
|
38
38
|
this.eventTops = /* @__PURE__ */ new Map();
|
|
39
39
|
this.handleAlphas = /* @__PURE__ */ new Map();
|
|
40
40
|
this.now = 0;
|
|
@@ -49,9 +49,6 @@ var LayoutAnimator = class {
|
|
|
49
49
|
beginFrame(now) {
|
|
50
50
|
this.now = now;
|
|
51
51
|
}
|
|
52
|
-
rowHeight(rowId, target) {
|
|
53
|
-
return this.value(this.rowHeights, rowId, target, this.layoutDuration);
|
|
54
|
-
}
|
|
55
52
|
eventTop(eventId, target) {
|
|
56
53
|
return this.value(this.eventTops, eventId, target, this.layoutDuration);
|
|
57
54
|
}
|
|
@@ -72,7 +69,6 @@ var LayoutAnimator = class {
|
|
|
72
69
|
}
|
|
73
70
|
/** Drop all state, e.g. when the scene is reset wholesale. */
|
|
74
71
|
reset() {
|
|
75
|
-
this.rowHeights.clear();
|
|
76
72
|
this.eventTops.clear();
|
|
77
73
|
this.handleAlphas.clear();
|
|
78
74
|
this.activeUntil = 0;
|
|
@@ -244,21 +240,6 @@ var event_prompt_default = EventPrompt;
|
|
|
244
240
|
// src/components/canvas-time-bar.tsx
|
|
245
241
|
import React3, { useEffect as useEffect3, useRef as useRef4 } from "react";
|
|
246
242
|
|
|
247
|
-
// src/hooks/use-get-block-properties.ts
|
|
248
|
-
import { useMemo as useMemo2 } from "react";
|
|
249
|
-
var useGetBlockProperties = ({
|
|
250
|
-
windowTime,
|
|
251
|
-
contentWidth
|
|
252
|
-
}) => {
|
|
253
|
-
const numberOfHourBlocks = useMemo2(
|
|
254
|
-
() => (windowTime[1] - windowTime[0]) / 3600,
|
|
255
|
-
[windowTime]
|
|
256
|
-
);
|
|
257
|
-
const blockWidth = contentWidth ? contentWidth / numberOfHourBlocks : 0;
|
|
258
|
-
return { numberOfHourBlocks, blockWidth };
|
|
259
|
-
};
|
|
260
|
-
var use_get_block_properties_default = useGetBlockProperties;
|
|
261
|
-
|
|
262
243
|
// src/helpers/get-month-name.ts
|
|
263
244
|
var getMonthName = (monthIndex) => {
|
|
264
245
|
let monthName = null;
|
|
@@ -307,106 +288,108 @@ var getMonthName = (monthIndex) => {
|
|
|
307
288
|
var get_month_name_default = getMonthName;
|
|
308
289
|
|
|
309
290
|
// src/helpers/get-week-day-name.ts
|
|
291
|
+
var WEEKDAY_NAMES = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
310
292
|
var getWeekDayName = (dayIndex) => {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
case 0:
|
|
314
|
-
dayName = "Mon";
|
|
315
|
-
break;
|
|
316
|
-
case 1:
|
|
317
|
-
dayName = "Tue";
|
|
318
|
-
break;
|
|
319
|
-
case 2:
|
|
320
|
-
dayName = "Wed";
|
|
321
|
-
break;
|
|
322
|
-
case 3:
|
|
323
|
-
dayName = "Thu";
|
|
324
|
-
break;
|
|
325
|
-
case 4:
|
|
326
|
-
dayName = "Fri";
|
|
327
|
-
break;
|
|
328
|
-
case 5:
|
|
329
|
-
dayName = "Sat";
|
|
330
|
-
break;
|
|
331
|
-
case 6:
|
|
332
|
-
dayName = "Sun";
|
|
333
|
-
break;
|
|
334
|
-
default:
|
|
335
|
-
dayName = "Mon";
|
|
336
|
-
}
|
|
337
|
-
return dayName;
|
|
293
|
+
var _a;
|
|
294
|
+
return (_a = WEEKDAY_NAMES[dayIndex]) != null ? _a : "Sun";
|
|
338
295
|
};
|
|
339
296
|
var get_week_day_name_default = getWeekDayName;
|
|
340
297
|
|
|
341
298
|
// src/core/time-blocks.ts
|
|
342
|
-
var
|
|
299
|
+
var pad2 = (n) => n < 10 ? `0${n}` : `${n}`;
|
|
300
|
+
var hourLabel = (hour) => `${pad2(hour)}:00`;
|
|
343
301
|
var dayLabel = (date) => `${get_week_day_name_default(date.getDay())} ${date.getDate()} ${get_month_name_default(
|
|
344
302
|
date.getMonth()
|
|
345
303
|
)}`;
|
|
346
|
-
var
|
|
304
|
+
var defaultFormat = (unit) => {
|
|
305
|
+
if (typeof unit === "object") {
|
|
306
|
+
return (d) => `${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
|
|
307
|
+
}
|
|
308
|
+
switch (unit) {
|
|
309
|
+
case "hour":
|
|
310
|
+
return (d) => hourLabel(d.getHours());
|
|
311
|
+
case "month":
|
|
312
|
+
return (d) => `${get_month_name_default(d.getMonth())} ${d.getFullYear()}`;
|
|
313
|
+
case "day":
|
|
314
|
+
case "week":
|
|
315
|
+
default:
|
|
316
|
+
return (d) => dayLabel(d);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
var floorToUnit = (date, unit, anchorSec) => {
|
|
320
|
+
if (typeof unit === "object") {
|
|
321
|
+
const t = date.getTime() / 1e3;
|
|
322
|
+
const step = unit.stepSeconds;
|
|
323
|
+
return new Date((anchorSec + Math.floor((t - anchorSec) / step) * step) * 1e3);
|
|
324
|
+
}
|
|
325
|
+
const y = date.getFullYear();
|
|
326
|
+
const mo = date.getMonth();
|
|
327
|
+
const d = date.getDate();
|
|
328
|
+
switch (unit) {
|
|
329
|
+
case "hour":
|
|
330
|
+
return new Date(y, mo, d, date.getHours());
|
|
331
|
+
case "day":
|
|
332
|
+
return new Date(y, mo, d);
|
|
333
|
+
case "week": {
|
|
334
|
+
const dow = (date.getDay() + 6) % 7;
|
|
335
|
+
return new Date(y, mo, d - dow);
|
|
336
|
+
}
|
|
337
|
+
case "month":
|
|
338
|
+
return new Date(y, mo, 1);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
var nextBoundary = (blockStart, unit) => {
|
|
342
|
+
if (typeof unit === "object") {
|
|
343
|
+
return new Date(blockStart.getTime() + unit.stepSeconds * 1e3);
|
|
344
|
+
}
|
|
345
|
+
const y = blockStart.getFullYear();
|
|
346
|
+
const mo = blockStart.getMonth();
|
|
347
|
+
const d = blockStart.getDate();
|
|
348
|
+
switch (unit) {
|
|
349
|
+
case "hour":
|
|
350
|
+
return new Date(y, mo, d, blockStart.getHours() + 1);
|
|
351
|
+
case "day":
|
|
352
|
+
return new Date(y, mo, d + 1);
|
|
353
|
+
case "week":
|
|
354
|
+
return new Date(y, mo, d + 7);
|
|
355
|
+
case "month":
|
|
356
|
+
return new Date(y, mo + 1, 1);
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
var generateUnitBlocks = ({
|
|
360
|
+
unit,
|
|
361
|
+
format,
|
|
347
362
|
windowStart,
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
blockWidth
|
|
363
|
+
windowEnd,
|
|
364
|
+
tick
|
|
351
365
|
}) => {
|
|
352
|
-
const
|
|
353
|
-
const
|
|
354
|
-
if (tick === null ||
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
);
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
for (let i = 0; i < numBlocks2; i++) {
|
|
376
|
-
hourBlocks.push({
|
|
377
|
-
label: hourLabel(i),
|
|
378
|
-
x: hourBlocks.length * blockWidth,
|
|
379
|
-
width: blockWidth
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
dayBlocks.push({
|
|
383
|
-
label: dayLabel(datePoint),
|
|
384
|
-
x: (prevNumBlocks - 1) * blockWidth,
|
|
385
|
-
width: numBlocks2 * blockWidth
|
|
386
|
-
});
|
|
387
|
-
prevNumBlocks += numBlocks2;
|
|
388
|
-
break;
|
|
389
|
-
}
|
|
390
|
-
const numBlocks = Math.round(dateWidth / blockWidth);
|
|
391
|
-
for (let i = 24 - numBlocks; i < 24; i++) {
|
|
392
|
-
hourBlocks.push({
|
|
393
|
-
label: hourLabel(i),
|
|
394
|
-
x: hourBlocks.length * blockWidth,
|
|
395
|
-
width: blockWidth
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
dayBlocks.push({
|
|
399
|
-
label: dayLabel(datePoint),
|
|
400
|
-
x: (prevNumBlocks - 1) * blockWidth,
|
|
401
|
-
width: numBlocks * blockWidth
|
|
366
|
+
const blocks = [];
|
|
367
|
+
const resolvedUnit = unit != null ? unit : "hour";
|
|
368
|
+
if (tick === null || tick <= 0 || windowEnd <= windowStart) return blocks;
|
|
369
|
+
const label = format != null ? format : defaultFormat(resolvedUnit);
|
|
370
|
+
const anchorSec = new Date(
|
|
371
|
+
new Date(windowStart * 1e3).getFullYear(),
|
|
372
|
+
new Date(windowStart * 1e3).getMonth(),
|
|
373
|
+
new Date(windowStart * 1e3).getDate()
|
|
374
|
+
).getTime() / 1e3;
|
|
375
|
+
let cursorSec = windowStart;
|
|
376
|
+
let guard = 0;
|
|
377
|
+
while (cursorSec < windowEnd && guard++ < 1e5) {
|
|
378
|
+
const blockStart = floorToUnit(new Date(cursorSec * 1e3), resolvedUnit, anchorSec);
|
|
379
|
+
const blockEnd = nextBoundary(blockStart, resolvedUnit);
|
|
380
|
+
const startSec = blockStart.getTime() / 1e3;
|
|
381
|
+
const endSec = blockEnd.getTime() / 1e3;
|
|
382
|
+
if (endSec <= startSec) break;
|
|
383
|
+
const visibleStart = Math.max(startSec, windowStart);
|
|
384
|
+
const visibleEnd = Math.min(endSec, windowEnd);
|
|
385
|
+
blocks.push({
|
|
386
|
+
label: label(blockStart, blockEnd),
|
|
387
|
+
x: (visibleStart - windowStart) / tick,
|
|
388
|
+
width: (visibleEnd - visibleStart) / tick
|
|
402
389
|
});
|
|
403
|
-
|
|
404
|
-
if (Math.round(widthLeft) === 0) {
|
|
405
|
-
break;
|
|
406
|
-
}
|
|
407
|
-
timePoint = (endDatePoint.getTime() + 1e3) / 1e3;
|
|
390
|
+
cursorSec = endSec;
|
|
408
391
|
}
|
|
409
|
-
return
|
|
392
|
+
return blocks;
|
|
410
393
|
};
|
|
411
394
|
|
|
412
395
|
// src/canvas/dpr.ts
|
|
@@ -454,7 +437,17 @@ var DEFAULT_THEME = {
|
|
|
454
437
|
gridColor: "#e4dcdc",
|
|
455
438
|
timeBarBorder: "yellow",
|
|
456
439
|
timeBarTextColor: "white",
|
|
457
|
-
|
|
440
|
+
dimmedOpacity: 0.35,
|
|
441
|
+
selectionShadowColor: "rgba(0,0,0,0.35)",
|
|
442
|
+
selectionShadowBlur: 8,
|
|
443
|
+
selectionElevation: 2,
|
|
444
|
+
font: void 0,
|
|
445
|
+
barHeight: 20,
|
|
446
|
+
laneGap: 2,
|
|
447
|
+
rowPaddingY: 10,
|
|
448
|
+
barRadius: 5,
|
|
449
|
+
groupChildBackground: "rgba(0,0,0,0.05)",
|
|
450
|
+
groupShadowColor: "rgba(0,0,0,0.22)"
|
|
458
451
|
};
|
|
459
452
|
var resolveTheme = (theme) => __spreadValues(__spreadValues({}, DEFAULT_THEME), theme);
|
|
460
453
|
|
|
@@ -463,14 +456,19 @@ var drawGridLines = (ctx, {
|
|
|
463
456
|
width,
|
|
464
457
|
height,
|
|
465
458
|
cellWidth,
|
|
459
|
+
windowStart,
|
|
460
|
+
tick,
|
|
466
461
|
color = DEFAULT_THEME.gridColor
|
|
467
462
|
}) => {
|
|
468
|
-
if (cellWidth <= 0) return;
|
|
463
|
+
if (cellWidth <= 0 || tick <= 0) return;
|
|
464
|
+
const cellTime = cellWidth * tick;
|
|
469
465
|
ctx.strokeStyle = color;
|
|
470
466
|
ctx.lineWidth = 1;
|
|
471
467
|
ctx.beginPath();
|
|
472
|
-
for (let
|
|
473
|
-
|
|
468
|
+
for (let t = Math.floor(windowStart / cellTime) * cellTime + cellTime; ; t += cellTime) {
|
|
469
|
+
const x = (t - windowStart) / tick;
|
|
470
|
+
if (x >= width || width - x < 1) break;
|
|
471
|
+
if (x < 1) continue;
|
|
474
472
|
const crisp = Math.round(x) - 0.5;
|
|
475
473
|
ctx.moveTo(crisp, 0);
|
|
476
474
|
ctx.lineTo(crisp, height);
|
|
@@ -480,8 +478,8 @@ var drawGridLines = (ctx, {
|
|
|
480
478
|
var drawTimeBar = (ctx, {
|
|
481
479
|
width,
|
|
482
480
|
height,
|
|
483
|
-
|
|
484
|
-
|
|
481
|
+
topBlocks,
|
|
482
|
+
bottomBlocks,
|
|
485
483
|
font,
|
|
486
484
|
borderColor = DEFAULT_THEME.timeBarBorder,
|
|
487
485
|
textColor = DEFAULT_THEME.timeBarTextColor
|
|
@@ -494,13 +492,13 @@ var drawTimeBar = (ctx, {
|
|
|
494
492
|
ctx.lineTo(width, Math.round(mid) - 0.5);
|
|
495
493
|
ctx.stroke();
|
|
496
494
|
ctx.beginPath();
|
|
497
|
-
for (let i = 0; i <
|
|
498
|
-
const edge = Math.round(
|
|
495
|
+
for (let i = 0; i < topBlocks.length - 1; i++) {
|
|
496
|
+
const edge = Math.round(topBlocks[i].x + topBlocks[i].width) - 0.5;
|
|
499
497
|
ctx.moveTo(edge, 0);
|
|
500
498
|
ctx.lineTo(edge, mid);
|
|
501
499
|
}
|
|
502
|
-
for (let i = 0; i <
|
|
503
|
-
const edge = Math.round(
|
|
500
|
+
for (let i = 0; i < bottomBlocks.length - 1; i++) {
|
|
501
|
+
const edge = Math.round(bottomBlocks[i].x + bottomBlocks[i].width) - 0.5;
|
|
504
502
|
ctx.moveTo(edge, mid);
|
|
505
503
|
ctx.lineTo(edge, height);
|
|
506
504
|
}
|
|
@@ -510,7 +508,7 @@ var drawTimeBar = (ctx, {
|
|
|
510
508
|
ctx.textBaseline = "middle";
|
|
511
509
|
ctx.textAlign = "center";
|
|
512
510
|
const inset = 4;
|
|
513
|
-
for (const block of
|
|
511
|
+
for (const block of topBlocks) {
|
|
514
512
|
ctx.fillText(
|
|
515
513
|
block.label,
|
|
516
514
|
block.x + block.width / 2,
|
|
@@ -518,7 +516,7 @@ var drawTimeBar = (ctx, {
|
|
|
518
516
|
block.width - inset
|
|
519
517
|
);
|
|
520
518
|
}
|
|
521
|
-
for (const block of
|
|
519
|
+
for (const block of bottomBlocks) {
|
|
522
520
|
ctx.fillText(
|
|
523
521
|
block.label,
|
|
524
522
|
block.x + block.width / 2,
|
|
@@ -535,15 +533,15 @@ var CanvasTimeBar = ({
|
|
|
535
533
|
tick,
|
|
536
534
|
contentWidth,
|
|
537
535
|
scrollWidth,
|
|
538
|
-
theme
|
|
536
|
+
theme,
|
|
537
|
+
timeBar
|
|
539
538
|
}) => {
|
|
539
|
+
var _a, _b;
|
|
540
540
|
const canvasRef = useRef4(null);
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
contentWidth
|
|
544
|
-
});
|
|
541
|
+
const topRow = (_a = timeBar == null ? void 0 : timeBar.topRow) != null ? _a : { unit: "day" };
|
|
542
|
+
const bottomRow = (_b = timeBar == null ? void 0 : timeBar.bottomRow) != null ? _b : { unit: "hour" };
|
|
545
543
|
useEffect3(() => {
|
|
546
|
-
var
|
|
544
|
+
var _a2;
|
|
547
545
|
const canvas = canvasRef.current;
|
|
548
546
|
if (!canvas || !contentWidth) return;
|
|
549
547
|
const ctx = sizeCanvas(
|
|
@@ -552,21 +550,22 @@ var CanvasTimeBar = ({
|
|
|
552
550
|
TIME_BAR_INNER_HEIGHT,
|
|
553
551
|
window.devicePixelRatio
|
|
554
552
|
);
|
|
555
|
-
if (ctx)
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
553
|
+
if (!ctx) return;
|
|
554
|
+
const [windowStart, windowEnd] = windowTime;
|
|
555
|
+
drawTimeBar(ctx, {
|
|
556
|
+
width: contentWidth,
|
|
557
|
+
height: TIME_BAR_INNER_HEIGHT,
|
|
558
|
+
font: (_a2 = theme == null ? void 0 : theme.font) != null ? _a2 : getComputedStyle(canvas).font,
|
|
559
|
+
borderColor: theme == null ? void 0 : theme.timeBarBorder,
|
|
560
|
+
textColor: theme == null ? void 0 : theme.timeBarTextColor,
|
|
561
|
+
topBlocks: generateUnitBlocks(__spreadProps(__spreadValues({}, topRow), { windowStart, windowEnd, tick })),
|
|
562
|
+
bottomBlocks: generateUnitBlocks(__spreadProps(__spreadValues({}, bottomRow), {
|
|
563
|
+
windowStart,
|
|
564
|
+
windowEnd,
|
|
565
|
+
tick
|
|
566
|
+
}))
|
|
567
|
+
});
|
|
568
|
+
}, [windowTime, tick, contentWidth, theme, timeBar]);
|
|
570
569
|
return /* @__PURE__ */ React3.createElement("div", { className: "time-bar" }, /* @__PURE__ */ React3.createElement("div", { className: "empty-block" }), /* @__PURE__ */ React3.createElement(
|
|
571
570
|
"canvas",
|
|
572
571
|
{
|
|
@@ -593,6 +592,7 @@ import React5, {
|
|
|
593
592
|
forwardRef as forwardRef2,
|
|
594
593
|
useCallback as useCallback2,
|
|
595
594
|
useEffect as useEffect5,
|
|
595
|
+
useLayoutEffect,
|
|
596
596
|
useRef as useRef6,
|
|
597
597
|
useState as useState3,
|
|
598
598
|
useSyncExternalStore
|
|
@@ -663,15 +663,32 @@ var timeToX = (time, windowStart, tick) => (time - windowStart) / tick;
|
|
|
663
663
|
var timeToWidth = (startTime, endTime, tick) => (endTime - startTime) / tick;
|
|
664
664
|
var intersectsWindow = (event, windowStart, windowEnd) => event.endTime >= windowStart && event.startTime <= windowEnd;
|
|
665
665
|
|
|
666
|
+
// src/core/geometry.ts
|
|
667
|
+
var DEFAULT_GEOMETRY = {
|
|
668
|
+
barHeight: 20,
|
|
669
|
+
laneHeight: 22,
|
|
670
|
+
laneTopOffset: 10,
|
|
671
|
+
rowBaseHeight: 40,
|
|
672
|
+
staticEventBaseHeight: 20,
|
|
673
|
+
barRadius: 5
|
|
674
|
+
};
|
|
675
|
+
var geometryFromTheme = (theme) => {
|
|
676
|
+
const barHeight = theme.barHeight;
|
|
677
|
+
const rowPaddingY = theme.rowPaddingY;
|
|
678
|
+
return {
|
|
679
|
+
barHeight,
|
|
680
|
+
laneHeight: barHeight + theme.laneGap,
|
|
681
|
+
laneTopOffset: rowPaddingY,
|
|
682
|
+
rowBaseHeight: barHeight + 2 * rowPaddingY,
|
|
683
|
+
staticEventBaseHeight: barHeight,
|
|
684
|
+
barRadius: theme.barRadius
|
|
685
|
+
};
|
|
686
|
+
};
|
|
687
|
+
|
|
666
688
|
// src/core/lanes.ts
|
|
667
|
-
var
|
|
668
|
-
var
|
|
669
|
-
var
|
|
670
|
-
var STATIC_EVENT_BASE_HEIGHT = 20;
|
|
671
|
-
var EVENT_BAR_HEIGHT = 20;
|
|
672
|
-
var laneTop = (lane) => LANE_TOP_OFFSET + LANE_HEIGHT * lane;
|
|
673
|
-
var rowMinHeight = (highestLane) => ROW_BASE_HEIGHT + highestLane * LANE_HEIGHT;
|
|
674
|
-
var staticEventHeight = (highestLane) => STATIC_EVENT_BASE_HEIGHT + highestLane * LANE_HEIGHT;
|
|
689
|
+
var laneTop = (lane, g = DEFAULT_GEOMETRY) => g.laneTopOffset + g.laneHeight * lane;
|
|
690
|
+
var rowMinHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.rowBaseHeight + highestLane * g.laneHeight;
|
|
691
|
+
var staticEventHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.staticEventBaseHeight + highestLane * g.laneHeight;
|
|
675
692
|
var assignLanes = (rowEvents, windowStart, windowEnd) => {
|
|
676
693
|
let eventOrder = 0;
|
|
677
694
|
const prevEvent = [];
|
|
@@ -713,9 +730,9 @@ var computeDropTimes = ({
|
|
|
713
730
|
windowStart,
|
|
714
731
|
duration
|
|
715
732
|
}) => {
|
|
716
|
-
const
|
|
717
|
-
const
|
|
718
|
-
const startTime =
|
|
733
|
+
const cellTime = cellWidth * tick;
|
|
734
|
+
const pointerTime = windowStart + pointerX * tick;
|
|
735
|
+
const startTime = Math.round(pointerTime / cellTime) * cellTime;
|
|
719
736
|
return { startTime, endTime: startTime + duration };
|
|
720
737
|
};
|
|
721
738
|
var computeResizeTimes = (event, deltaPx, tick, direction) => {
|
|
@@ -733,9 +750,10 @@ var computeResizeTimes = (event, deltaPx, tick, direction) => {
|
|
|
733
750
|
return null;
|
|
734
751
|
};
|
|
735
752
|
var canResizeEvent = (event, eventsResize) => {
|
|
736
|
-
var _a, _b, _c, _d;
|
|
737
|
-
return !((_a = event.props) == null ? void 0 : _a.isLocked) && (eventsResize && (((
|
|
753
|
+
var _a, _b, _c, _d, _e;
|
|
754
|
+
return !((_a = event.props) == null ? void 0 : _a.isLocked) && !((_b = event.props) == null ? void 0 : _b.isGroupParent) && (eventsResize && (((_c = event.props) == null ? void 0 : _c.isResizable) === true || ((_d = event.props) == null ? void 0 : _d.isResizable) === void 0) || !eventsResize && ((_e = event.props) == null ? void 0 : _e.isResizable) === true);
|
|
738
755
|
};
|
|
756
|
+
var isRowDroppable = (droppableRowIds, targetRowId) => droppableRowIds === void 0 || droppableRowIds.includes(targetRowId);
|
|
739
757
|
var stepCellWidth = (cellWidth, deltaY, tick) => {
|
|
740
758
|
const pixelsToCalculate = 900 / tick;
|
|
741
759
|
const next = deltaY > 0 ? cellWidth + pixelsToCalculate : cellWidth - pixelsToCalculate;
|
|
@@ -744,9 +762,26 @@ var stepCellWidth = (cellWidth, deltaY, tick) => {
|
|
|
744
762
|
}
|
|
745
763
|
return next;
|
|
746
764
|
};
|
|
765
|
+
var computeZoom = (windowTime, tick, cellWidth, anchorX, factor, contentWidth, { minWindowSeconds, maxWindowSeconds }) => {
|
|
766
|
+
const [start, end] = windowTime;
|
|
767
|
+
const oldDuration = end - start;
|
|
768
|
+
const newDuration = Math.min(
|
|
769
|
+
Math.max(oldDuration * factor, minWindowSeconds),
|
|
770
|
+
maxWindowSeconds
|
|
771
|
+
);
|
|
772
|
+
const cellTime = cellWidth * tick;
|
|
773
|
+
const tAnchor = start + anchorX * tick;
|
|
774
|
+
const newStart = Math.round(tAnchor - anchorX / contentWidth * newDuration);
|
|
775
|
+
const newEnd = newStart + Math.round(newDuration);
|
|
776
|
+
const newTick = (newEnd - newStart) / contentWidth;
|
|
777
|
+
return {
|
|
778
|
+
windowTime: [newStart, newEnd],
|
|
779
|
+
tick: newTick,
|
|
780
|
+
cellWidth: cellTime / newTick
|
|
781
|
+
};
|
|
782
|
+
};
|
|
747
783
|
|
|
748
784
|
// src/canvas/draw-events.ts
|
|
749
|
-
var EVENT_RADIUS = 5;
|
|
750
785
|
var EVENT_TEXT_INSET = 13;
|
|
751
786
|
var HANDLE_INSET = 4;
|
|
752
787
|
var HANDLE_BAR_WIDTH = 3;
|
|
@@ -766,18 +801,75 @@ var roundedRect = (ctx, x, y, width, height, radius) => {
|
|
|
766
801
|
ctx.closePath();
|
|
767
802
|
}
|
|
768
803
|
};
|
|
769
|
-
var
|
|
804
|
+
var drawGroupShading = (ctx, view, scene) => {
|
|
805
|
+
var _a;
|
|
806
|
+
const [windowStart, windowEnd] = view.windowTime;
|
|
807
|
+
const visible = scene.getVisibleRowIds();
|
|
808
|
+
const regions = [];
|
|
809
|
+
let y = 0;
|
|
810
|
+
let runParent = null;
|
|
811
|
+
let runTop = 0;
|
|
812
|
+
let runBottom = 0;
|
|
813
|
+
const flush = () => {
|
|
814
|
+
if (runParent !== null) regions.push({ top: runTop, bottom: runBottom });
|
|
815
|
+
runParent = null;
|
|
816
|
+
};
|
|
817
|
+
for (const rowId of visible) {
|
|
818
|
+
const height = scene.getRowHeight(rowId, windowStart, windowEnd);
|
|
819
|
+
const parentId = (_a = scene.getRow(rowId)) == null ? void 0 : _a.parentId;
|
|
820
|
+
if (parentId !== void 0) {
|
|
821
|
+
if (runParent === parentId) {
|
|
822
|
+
runBottom = y + height;
|
|
823
|
+
} else {
|
|
824
|
+
flush();
|
|
825
|
+
runParent = parentId;
|
|
826
|
+
runTop = y;
|
|
827
|
+
runBottom = y + height;
|
|
828
|
+
}
|
|
829
|
+
} else {
|
|
830
|
+
flush();
|
|
831
|
+
}
|
|
832
|
+
y += height;
|
|
833
|
+
}
|
|
834
|
+
flush();
|
|
835
|
+
if (regions.length === 0) return;
|
|
836
|
+
ctx.save();
|
|
837
|
+
for (const { top, bottom } of regions) {
|
|
838
|
+
const sTop = top - view.scrollTop;
|
|
839
|
+
const sBottom = bottom - view.scrollTop;
|
|
840
|
+
if (sBottom < 0 || sTop > view.height) continue;
|
|
841
|
+
const regionHeight = sBottom - sTop;
|
|
842
|
+
ctx.fillStyle = view.theme.groupChildBackground;
|
|
843
|
+
ctx.fillRect(0, sTop, view.width, regionHeight);
|
|
844
|
+
const depth = Math.min(12, regionHeight / 2);
|
|
845
|
+
const topGrad = ctx.createLinearGradient(0, sTop, 0, sTop + depth);
|
|
846
|
+
topGrad.addColorStop(0, view.theme.groupShadowColor);
|
|
847
|
+
topGrad.addColorStop(1, "rgba(0,0,0,0)");
|
|
848
|
+
ctx.fillStyle = topGrad;
|
|
849
|
+
ctx.fillRect(0, sTop, view.width, depth);
|
|
850
|
+
const botGrad = ctx.createLinearGradient(0, sBottom - depth, 0, sBottom);
|
|
851
|
+
botGrad.addColorStop(0, "rgba(0,0,0,0)");
|
|
852
|
+
botGrad.addColorStop(1, view.theme.groupShadowColor);
|
|
853
|
+
ctx.fillStyle = botGrad;
|
|
854
|
+
ctx.fillRect(0, sBottom - depth, view.width, depth);
|
|
855
|
+
const leftShadow = 10;
|
|
856
|
+
const hGrad = ctx.createLinearGradient(0, 0, leftShadow, 0);
|
|
857
|
+
hGrad.addColorStop(0, view.theme.groupShadowColor);
|
|
858
|
+
hGrad.addColorStop(1, "rgba(0,0,0,0)");
|
|
859
|
+
ctx.fillStyle = hGrad;
|
|
860
|
+
ctx.fillRect(0, sTop, leftShadow, regionHeight);
|
|
861
|
+
}
|
|
862
|
+
ctx.restore();
|
|
863
|
+
};
|
|
864
|
+
var drawRowDividers = (ctx, view, scene) => {
|
|
770
865
|
const [windowStart, windowEnd] = view.windowTime;
|
|
771
|
-
const rowIds = scene.
|
|
866
|
+
const rowIds = scene.getVisibleRowIds();
|
|
772
867
|
ctx.strokeStyle = view.theme.gridColor;
|
|
773
868
|
ctx.lineWidth = 1;
|
|
774
869
|
ctx.beginPath();
|
|
775
870
|
let y = 0;
|
|
776
871
|
for (let i = 0; i < rowIds.length; i++) {
|
|
777
|
-
y +=
|
|
778
|
-
rowIds[i],
|
|
779
|
-
scene.getRowHeight(rowIds[i], windowStart, windowEnd)
|
|
780
|
-
);
|
|
872
|
+
y += scene.getRowHeight(rowIds[i], windowStart, windowEnd);
|
|
781
873
|
if (i === rowIds.length - 1) break;
|
|
782
874
|
const screenY = y - view.scrollTop;
|
|
783
875
|
if (screenY < 0) continue;
|
|
@@ -817,7 +909,7 @@ var drawResizeHandles = (ctx, rect, alpha, strokeColor) => {
|
|
|
817
909
|
}
|
|
818
910
|
ctx.restore();
|
|
819
911
|
};
|
|
820
|
-
var defaultDrawEvent = (ctx, event, rect, view, font) => {
|
|
912
|
+
var defaultDrawEvent = (ctx, event, rect, view, font, barRadius) => {
|
|
821
913
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
822
914
|
const theme = view.theme;
|
|
823
915
|
const style = (_a = event.props) == null ? void 0 : _a.style;
|
|
@@ -831,7 +923,7 @@ var defaultDrawEvent = (ctx, event, rect, view, font) => {
|
|
|
831
923
|
rect.y + 0.5,
|
|
832
924
|
rect.width - 1,
|
|
833
925
|
rect.height - 1,
|
|
834
|
-
(_e = style == null ? void 0 : style.borderRadius) != null ? _e :
|
|
926
|
+
(_e = style == null ? void 0 : style.borderRadius) != null ? _e : barRadius
|
|
835
927
|
);
|
|
836
928
|
ctx.fill();
|
|
837
929
|
ctx.stroke();
|
|
@@ -853,19 +945,53 @@ var defaultDrawEvent = (ctx, event, rect, view, font) => {
|
|
|
853
945
|
}
|
|
854
946
|
};
|
|
855
947
|
var drawEvents = (ctx, view, scene, font, animator) => {
|
|
856
|
-
var _a
|
|
948
|
+
var _a;
|
|
857
949
|
if (view.tick === null) return;
|
|
858
950
|
const [windowStart, windowEnd] = view.windowTime;
|
|
859
951
|
const tick = view.tick;
|
|
952
|
+
const geometry = scene.getGeometry();
|
|
860
953
|
ctx.font = (_a = view.theme.font) != null ? _a : font;
|
|
861
954
|
ctx.textBaseline = "middle";
|
|
862
955
|
ctx.textAlign = "left";
|
|
956
|
+
const selectedIds = view.selectedEventIds;
|
|
957
|
+
const hasSelection = selectedIds.size > 0;
|
|
958
|
+
const deferred = [];
|
|
959
|
+
const paintEvent = (event, rect, state, opts) => {
|
|
960
|
+
var _a2, _b, _c, _d, _e;
|
|
961
|
+
ctx.save();
|
|
962
|
+
if (opts.elevate) {
|
|
963
|
+
ctx.translate(0, -view.theme.selectionElevation);
|
|
964
|
+
ctx.shadowColor = view.theme.selectionShadowColor;
|
|
965
|
+
ctx.shadowBlur = view.theme.selectionShadowBlur;
|
|
966
|
+
ctx.shadowOffsetY = view.theme.selectionElevation;
|
|
967
|
+
}
|
|
968
|
+
if (state.dragging) ctx.globalAlpha = 0.5;
|
|
969
|
+
else if (opts.dim) ctx.globalAlpha *= view.theme.dimmedOpacity;
|
|
970
|
+
const custom = (_b = (_a2 = event.props) == null ? void 0 : _a2.drawEvent) != null ? _b : view.drawEvent;
|
|
971
|
+
const drawn = custom !== void 0 && custom(ctx, event, rect, state, view.theme) !== false;
|
|
972
|
+
if (!drawn) {
|
|
973
|
+
defaultDrawEvent(ctx, event, rect, view, font, geometry.barRadius);
|
|
974
|
+
}
|
|
975
|
+
if (canResizeEvent(event, view.eventsResize)) {
|
|
976
|
+
const alpha = animator.handleAlpha(
|
|
977
|
+
event.id,
|
|
978
|
+
state.hovered || state.resizing ? 1 : 0
|
|
979
|
+
);
|
|
980
|
+
if (alpha > 0.01) {
|
|
981
|
+
ctx.shadowColor = "transparent";
|
|
982
|
+
drawResizeHandles(
|
|
983
|
+
ctx,
|
|
984
|
+
rect,
|
|
985
|
+
alpha,
|
|
986
|
+
(_e = (_d = (_c = event.props) == null ? void 0 : _c.style) == null ? void 0 : _d.stroke) != null ? _e : view.theme.eventStroke
|
|
987
|
+
);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
ctx.restore();
|
|
991
|
+
};
|
|
863
992
|
let rowTop = 0;
|
|
864
|
-
for (const rowId of scene.
|
|
865
|
-
const rowHeight =
|
|
866
|
-
rowId,
|
|
867
|
-
scene.getRowHeight(rowId, windowStart, windowEnd)
|
|
868
|
-
);
|
|
993
|
+
for (const rowId of scene.getVisibleRowIds()) {
|
|
994
|
+
const rowHeight = scene.getRowHeight(rowId, windowStart, windowEnd);
|
|
869
995
|
const rowY = rowTop - view.scrollTop;
|
|
870
996
|
rowTop += rowHeight;
|
|
871
997
|
if (rowY + rowHeight < 0) continue;
|
|
@@ -882,10 +1008,10 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
882
1008
|
roundedRect(
|
|
883
1009
|
ctx,
|
|
884
1010
|
x,
|
|
885
|
-
rowY +
|
|
1011
|
+
rowY + geometry.laneTopOffset,
|
|
886
1012
|
width,
|
|
887
|
-
staticEventHeight(lanes.highestLane),
|
|
888
|
-
|
|
1013
|
+
staticEventHeight(lanes.highestLane, geometry),
|
|
1014
|
+
geometry.barRadius
|
|
889
1015
|
);
|
|
890
1016
|
ctx.fill();
|
|
891
1017
|
}
|
|
@@ -898,7 +1024,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
898
1024
|
let width = timeToWidth(event.startTime, event.endTime, tick);
|
|
899
1025
|
const y = rowY + animator.eventTop(
|
|
900
1026
|
event.id,
|
|
901
|
-
laneTop(lanes.laneOf.get(event.id))
|
|
1027
|
+
laneTop(lanes.laneOf.get(event.id), geometry)
|
|
902
1028
|
);
|
|
903
1029
|
const resize = view.resizePreview;
|
|
904
1030
|
const resizing = resize !== null && resize.eventId === event.id;
|
|
@@ -910,37 +1036,24 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
910
1036
|
width += resize.deltaPx;
|
|
911
1037
|
}
|
|
912
1038
|
}
|
|
913
|
-
const rect = { x, y, width, height:
|
|
1039
|
+
const rect = { x, y, width, height: geometry.barHeight };
|
|
1040
|
+
const selected = selectedIds.has(event.id);
|
|
914
1041
|
const state = {
|
|
915
1042
|
hovered: view.hoveredEventId === event.id,
|
|
916
1043
|
dragging: view.draggedEventId === event.id,
|
|
917
1044
|
resizing,
|
|
918
|
-
selected
|
|
1045
|
+
selected
|
|
919
1046
|
};
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
const drawn = custom !== void 0 && custom(ctx, event, rect, state, view.theme) !== false;
|
|
924
|
-
if (!drawn) {
|
|
925
|
-
defaultDrawEvent(ctx, event, rect, view, font);
|
|
926
|
-
}
|
|
927
|
-
if (canResizeEvent(event, view.eventsResize)) {
|
|
928
|
-
const alpha = animator.handleAlpha(
|
|
929
|
-
event.id,
|
|
930
|
-
state.hovered || state.resizing ? 1 : 0
|
|
1047
|
+
if (selected) {
|
|
1048
|
+
deferred.push(
|
|
1049
|
+
() => paintEvent(event, rect, state, { dim: false, elevate: true })
|
|
931
1050
|
);
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
ctx,
|
|
935
|
-
rect,
|
|
936
|
-
alpha,
|
|
937
|
-
(_f = (_e = (_d = event.props) == null ? void 0 : _d.style) == null ? void 0 : _e.stroke) != null ? _f : view.theme.eventStroke
|
|
938
|
-
);
|
|
939
|
-
}
|
|
1051
|
+
} else {
|
|
1052
|
+
paintEvent(event, rect, state, { dim: hasSelection, elevate: false });
|
|
940
1053
|
}
|
|
941
|
-
ctx.restore();
|
|
942
1054
|
}
|
|
943
1055
|
}
|
|
1056
|
+
for (const paint of deferred) paint();
|
|
944
1057
|
};
|
|
945
1058
|
|
|
946
1059
|
// src/canvas/renderer.ts
|
|
@@ -961,7 +1074,8 @@ var TimelineRenderer = class {
|
|
|
961
1074
|
eventsResize: true,
|
|
962
1075
|
hoveredEventId: null,
|
|
963
1076
|
draggedEventId: null,
|
|
964
|
-
resizePreview: null
|
|
1077
|
+
resizePreview: null,
|
|
1078
|
+
selectedEventIds: /* @__PURE__ */ new Set()
|
|
965
1079
|
};
|
|
966
1080
|
this.animator = new LayoutAnimator();
|
|
967
1081
|
this.dpr = typeof window !== "undefined" ? window.devicePixelRatio : 1;
|
|
@@ -972,6 +1086,7 @@ var TimelineRenderer = class {
|
|
|
972
1086
|
this.dpr = dpr;
|
|
973
1087
|
this.resizeCanvases();
|
|
974
1088
|
this.invalidate("all");
|
|
1089
|
+
this.scheduler.flush();
|
|
975
1090
|
});
|
|
976
1091
|
}
|
|
977
1092
|
getView() {
|
|
@@ -983,6 +1098,7 @@ var TimelineRenderer = class {
|
|
|
983
1098
|
if (sizeChanged) {
|
|
984
1099
|
this.resizeCanvases();
|
|
985
1100
|
this.invalidate("all");
|
|
1101
|
+
this.scheduler.flush();
|
|
986
1102
|
return;
|
|
987
1103
|
}
|
|
988
1104
|
this.invalidate("all");
|
|
@@ -1013,13 +1129,16 @@ var TimelineRenderer = class {
|
|
|
1013
1129
|
const ctx = this.staticCanvas.getContext("2d");
|
|
1014
1130
|
if (ctx) {
|
|
1015
1131
|
ctx.clearRect(0, 0, this.view.width, this.view.height);
|
|
1132
|
+
drawGroupShading(ctx, this.view, this.scene);
|
|
1016
1133
|
drawGridLines(ctx, {
|
|
1017
1134
|
width: this.view.width,
|
|
1018
1135
|
height: this.view.height,
|
|
1019
1136
|
cellWidth: this.view.cellWidth,
|
|
1137
|
+
windowStart: this.view.windowTime[0],
|
|
1138
|
+
tick: this.view.tick,
|
|
1020
1139
|
color: this.view.theme.gridColor
|
|
1021
1140
|
});
|
|
1022
|
-
drawRowDividers(ctx, this.view, this.scene
|
|
1141
|
+
drawRowDividers(ctx, this.view, this.scene);
|
|
1023
1142
|
}
|
|
1024
1143
|
}
|
|
1025
1144
|
if (dirty.dynamic) {
|
|
@@ -1036,7 +1155,7 @@ var TimelineRenderer = class {
|
|
|
1036
1155
|
};
|
|
1037
1156
|
|
|
1038
1157
|
// src/hooks/use-canvas-interactions.ts
|
|
1039
|
-
import { useCallback, useEffect as useEffect4, useMemo as
|
|
1158
|
+
import { useCallback, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef5 } from "react";
|
|
1040
1159
|
|
|
1041
1160
|
// src/core/types.ts
|
|
1042
1161
|
var rectContains = (rect, x, y) => x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
|
|
@@ -1044,10 +1163,11 @@ var rectContains = (rect, x, y) => x >= rect.x && x <= rect.x + rect.width && y
|
|
|
1044
1163
|
// src/core/hit-test.ts
|
|
1045
1164
|
var hitTest = (scene, view, x, y) => {
|
|
1046
1165
|
const { windowStart, windowEnd, tick, scrollTop } = view;
|
|
1166
|
+
const geometry = scene.getGeometry();
|
|
1047
1167
|
const yContent = y + scrollTop;
|
|
1048
1168
|
let rowTop = 0;
|
|
1049
1169
|
let rowId = null;
|
|
1050
|
-
for (const id of scene.
|
|
1170
|
+
for (const id of scene.getVisibleRowIds()) {
|
|
1051
1171
|
const height = scene.getRowHeight(id, windowStart, windowEnd);
|
|
1052
1172
|
if (yContent >= rowTop && yContent < rowTop + height) {
|
|
1053
1173
|
rowId = id;
|
|
@@ -1067,9 +1187,9 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1067
1187
|
const event = events[i];
|
|
1068
1188
|
const rect = {
|
|
1069
1189
|
x: timeToX(event.startTime, windowStart, tick),
|
|
1070
|
-
y: rowY + laneTop(lanes.laneOf.get(event.id)),
|
|
1190
|
+
y: rowY + laneTop(lanes.laneOf.get(event.id), geometry),
|
|
1071
1191
|
width: timeToWidth(event.startTime, event.endTime, tick),
|
|
1072
|
-
height:
|
|
1192
|
+
height: geometry.barHeight
|
|
1073
1193
|
};
|
|
1074
1194
|
if (rectContains(rect, x, y)) {
|
|
1075
1195
|
return { kind: "event", event, rowId, rect };
|
|
@@ -1084,9 +1204,9 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1084
1204
|
const event = statics[i];
|
|
1085
1205
|
const rect = {
|
|
1086
1206
|
x: timeToX(event.startTime, windowStart, tick),
|
|
1087
|
-
y: rowY +
|
|
1207
|
+
y: rowY + geometry.laneTopOffset,
|
|
1088
1208
|
width: timeToWidth(event.startTime, event.endTime, tick),
|
|
1089
|
-
height: staticEventHeight(lanes.highestLane)
|
|
1209
|
+
height: staticEventHeight(lanes.highestLane, geometry)
|
|
1090
1210
|
};
|
|
1091
1211
|
if (rectContains(rect, x, y)) {
|
|
1092
1212
|
return { kind: "static", event, rowId, rect };
|
|
@@ -1098,6 +1218,7 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1098
1218
|
// src/hooks/use-canvas-interactions.ts
|
|
1099
1219
|
var DRAG_THRESHOLD_PX = 3;
|
|
1100
1220
|
var RESIZE_HOT_ZONE_PX = 8;
|
|
1221
|
+
var DRAG_ZOOM_PX_PER_DOUBLING = 300;
|
|
1101
1222
|
var lockCursor = (cursor) => {
|
|
1102
1223
|
const style = document.createElement("style");
|
|
1103
1224
|
style.id = "lock-cursor";
|
|
@@ -1117,30 +1238,99 @@ var useCanvasInteractions = ({
|
|
|
1117
1238
|
eventPromptRef,
|
|
1118
1239
|
setWindowTime,
|
|
1119
1240
|
setCellWidth,
|
|
1241
|
+
setTick,
|
|
1120
1242
|
onDrop,
|
|
1121
1243
|
onResize,
|
|
1122
1244
|
onEventClick,
|
|
1123
1245
|
onEventHover,
|
|
1124
1246
|
eventsResize,
|
|
1125
|
-
panZoom
|
|
1247
|
+
panZoom,
|
|
1248
|
+
selectable,
|
|
1249
|
+
applySelection,
|
|
1250
|
+
getSelection
|
|
1126
1251
|
}) => {
|
|
1127
1252
|
const stateRef = useRef5({ mode: "idle" });
|
|
1128
1253
|
const changeGridRef = useRef5(false);
|
|
1129
1254
|
const panFrameRef = useRef5(null);
|
|
1130
1255
|
const panPendingDxRef = useRef5(0);
|
|
1131
1256
|
const hoveredRef = useRef5(null);
|
|
1132
|
-
const
|
|
1257
|
+
const pointersRef = useRef5(/* @__PURE__ */ new Map());
|
|
1258
|
+
const zoomFrameRef = useRef5(null);
|
|
1259
|
+
const zoomPendingRef = useRef5(null);
|
|
1260
|
+
const config = useMemo2(
|
|
1133
1261
|
() => {
|
|
1134
|
-
var _a, _b, _c, _d;
|
|
1262
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1135
1263
|
return {
|
|
1136
1264
|
panOnDragBackground: (_a = panZoom == null ? void 0 : panZoom.panOnDragBackground) != null ? _a : true,
|
|
1137
1265
|
ctrlWheelZoom: (_b = panZoom == null ? void 0 : panZoom.ctrlWheelZoom) != null ? _b : true,
|
|
1138
|
-
|
|
1139
|
-
|
|
1266
|
+
pinchZoom: (_c = panZoom == null ? void 0 : panZoom.pinchZoom) != null ? _c : true,
|
|
1267
|
+
dragZoom: (_d = panZoom == null ? void 0 : panZoom.dragZoom) != null ? _d : true,
|
|
1268
|
+
zoomWheelFactor: (_e = panZoom == null ? void 0 : panZoom.zoomWheelFactor) != null ? _e : 1.15,
|
|
1269
|
+
middleClickGranularity: (_f = panZoom == null ? void 0 : panZoom.middleClickGranularity) != null ? _f : true,
|
|
1270
|
+
zoomStepSeconds: (_g = panZoom == null ? void 0 : panZoom.zoomStepSeconds) != null ? _g : 900
|
|
1140
1271
|
};
|
|
1141
1272
|
},
|
|
1142
1273
|
[panZoom]
|
|
1143
1274
|
);
|
|
1275
|
+
const limits = useMemo2(
|
|
1276
|
+
() => {
|
|
1277
|
+
var _a, _b;
|
|
1278
|
+
return {
|
|
1279
|
+
minWindowSeconds: (_a = panZoom == null ? void 0 : panZoom.minWindowSeconds) != null ? _a : 900,
|
|
1280
|
+
maxWindowSeconds: (_b = panZoom == null ? void 0 : panZoom.maxWindowSeconds) != null ? _b : 30 * 24 * 3600
|
|
1281
|
+
};
|
|
1282
|
+
},
|
|
1283
|
+
[panZoom]
|
|
1284
|
+
);
|
|
1285
|
+
const applyZoom = useCallback(
|
|
1286
|
+
(base, anchorX, factor, contentWidth) => {
|
|
1287
|
+
var _a;
|
|
1288
|
+
if (contentWidth <= 0) return;
|
|
1289
|
+
const next = computeZoom(
|
|
1290
|
+
base.windowTime,
|
|
1291
|
+
base.tick,
|
|
1292
|
+
base.cellWidth,
|
|
1293
|
+
anchorX,
|
|
1294
|
+
factor,
|
|
1295
|
+
contentWidth,
|
|
1296
|
+
limits
|
|
1297
|
+
);
|
|
1298
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({
|
|
1299
|
+
windowTime: next.windowTime,
|
|
1300
|
+
tick: next.tick,
|
|
1301
|
+
cellWidth: next.cellWidth
|
|
1302
|
+
});
|
|
1303
|
+
setWindowTime(next.windowTime);
|
|
1304
|
+
setTick(next.tick);
|
|
1305
|
+
setCellWidth(next.cellWidth);
|
|
1306
|
+
},
|
|
1307
|
+
[rendererRef, setWindowTime, setTick, setCellWidth, limits]
|
|
1308
|
+
);
|
|
1309
|
+
const scheduleContinuousZoom = useCallback(() => {
|
|
1310
|
+
if (zoomFrameRef.current !== null) return;
|
|
1311
|
+
zoomFrameRef.current = requestAnimationFrame(() => {
|
|
1312
|
+
zoomFrameRef.current = null;
|
|
1313
|
+
const pending = zoomPendingRef.current;
|
|
1314
|
+
const state = stateRef.current;
|
|
1315
|
+
if (!pending || state.mode !== "pinch" && state.mode !== "zoom") return;
|
|
1316
|
+
applyZoom(state.snapshot, pending.anchorX, pending.factor, state.contentWidth);
|
|
1317
|
+
});
|
|
1318
|
+
}, [applyZoom]);
|
|
1319
|
+
const snapshotView = useCallback(() => {
|
|
1320
|
+
const renderer = rendererRef.current;
|
|
1321
|
+
const canvas = dynamicCanvasRef.current;
|
|
1322
|
+
if (!renderer || !canvas) return null;
|
|
1323
|
+
const view = renderer.getView();
|
|
1324
|
+
if (view.tick === null) return null;
|
|
1325
|
+
return {
|
|
1326
|
+
base: {
|
|
1327
|
+
windowTime: [view.windowTime[0], view.windowTime[1]],
|
|
1328
|
+
tick: view.tick,
|
|
1329
|
+
cellWidth: view.cellWidth
|
|
1330
|
+
},
|
|
1331
|
+
contentWidth: canvas.getBoundingClientRect().width
|
|
1332
|
+
};
|
|
1333
|
+
}, [rendererRef, dynamicCanvasRef]);
|
|
1144
1334
|
const hidePrompt = useCallback(() => {
|
|
1145
1335
|
var _a;
|
|
1146
1336
|
(_a = eventPromptRef.current) == null ? void 0 : _a.hide();
|
|
@@ -1201,23 +1391,78 @@ var useCanvasInteractions = ({
|
|
|
1201
1391
|
}, [rendererRef, setWindowTime]);
|
|
1202
1392
|
const updateGhost = useCallback(
|
|
1203
1393
|
(state, clientX, clientY) => {
|
|
1394
|
+
var _a;
|
|
1204
1395
|
const ghost = ghostRef.current;
|
|
1205
1396
|
if (!ghost) return;
|
|
1397
|
+
const rawLeft = state.hit.rect.x + (clientX - state.startClientX);
|
|
1398
|
+
const rawTop = state.hit.rect.y + (clientY - state.startClientY);
|
|
1399
|
+
const view = (_a = rendererRef.current) == null ? void 0 : _a.getView();
|
|
1400
|
+
const ghostWidth = state.hit.rect.width;
|
|
1401
|
+
const ghostHeight = state.hit.rect.height;
|
|
1402
|
+
const left = view ? Math.max(0, Math.min(rawLeft, Math.max(0, view.width - ghostWidth))) : rawLeft;
|
|
1403
|
+
const top = view ? Math.max(0, Math.min(rawTop, Math.max(0, view.height - ghostHeight))) : rawTop;
|
|
1206
1404
|
ghost.style.display = "flex";
|
|
1207
|
-
ghost.style.left = `${
|
|
1208
|
-
ghost.style.top = `${
|
|
1209
|
-
ghost.style.width = `${
|
|
1405
|
+
ghost.style.left = `${left}px`;
|
|
1406
|
+
ghost.style.top = `${top}px`;
|
|
1407
|
+
ghost.style.width = `${ghostWidth}px`;
|
|
1408
|
+
},
|
|
1409
|
+
[ghostRef, rendererRef]
|
|
1410
|
+
);
|
|
1411
|
+
const styleGhost = useCallback(
|
|
1412
|
+
(event) => {
|
|
1413
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1414
|
+
const ghost = ghostRef.current;
|
|
1415
|
+
const theme = (_a = rendererRef.current) == null ? void 0 : _a.getView().theme;
|
|
1416
|
+
if (!ghost || !theme) return;
|
|
1417
|
+
const style = (_b = event.props) == null ? void 0 : _b.style;
|
|
1418
|
+
ghost.style.backgroundColor = (_c = style == null ? void 0 : style.fill) != null ? _c : theme.eventFill;
|
|
1419
|
+
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}`;
|
|
1420
|
+
ghost.style.borderRadius = `${(_f = style == null ? void 0 : style.borderRadius) != null ? _f : theme.barRadius}px`;
|
|
1421
|
+
ghost.style.color = (_g = style == null ? void 0 : style.textColor) != null ? _g : theme.eventTextColor;
|
|
1422
|
+
ghost.style.font = (_i = (_h = style == null ? void 0 : style.font) != null ? _h : theme.font) != null ? _i : "";
|
|
1423
|
+
ghost.style.justifyContent = "flex-start";
|
|
1424
|
+
ghost.style.alignItems = "center";
|
|
1425
|
+
ghost.style.paddingInline = "13px";
|
|
1426
|
+
ghost.style.overflow = "hidden";
|
|
1427
|
+
ghost.style.whiteSpace = "nowrap";
|
|
1428
|
+
ghost.textContent = (_k = (_j = event.props) == null ? void 0 : _j.label) != null ? _k : "";
|
|
1210
1429
|
},
|
|
1211
|
-
[ghostRef]
|
|
1430
|
+
[ghostRef, rendererRef]
|
|
1212
1431
|
);
|
|
1213
1432
|
const handlePointerDown = useCallback(
|
|
1214
1433
|
(pointerEvent) => {
|
|
1215
|
-
var _a;
|
|
1216
|
-
if (pointerEvent.button !== 0) return;
|
|
1434
|
+
var _a, _b;
|
|
1217
1435
|
const canvas = dynamicCanvasRef.current;
|
|
1218
1436
|
if (!canvas) return;
|
|
1437
|
+
const isTouch = pointerEvent.pointerType === "touch";
|
|
1438
|
+
pointersRef.current.set(pointerEvent.pointerId, {
|
|
1439
|
+
x: pointerEvent.clientX,
|
|
1440
|
+
y: pointerEvent.clientY,
|
|
1441
|
+
touch: isTouch
|
|
1442
|
+
});
|
|
1443
|
+
if (config.pinchZoom && isTouch && pointersRef.current.size === 2) {
|
|
1444
|
+
const snap = snapshotView();
|
|
1445
|
+
if (snap) {
|
|
1446
|
+
if (ghostRef.current) ghostRef.current.style.display = "none";
|
|
1447
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null });
|
|
1448
|
+
const pts = [...pointersRef.current.values()];
|
|
1449
|
+
const startDist = Math.hypot(pts[0].x - pts[1].x, pts[0].y - pts[1].y) || 1;
|
|
1450
|
+
const rect = canvas.getBoundingClientRect();
|
|
1451
|
+
stateRef.current = {
|
|
1452
|
+
mode: "pinch",
|
|
1453
|
+
startDist,
|
|
1454
|
+
anchorX: (pts[0].x + pts[1].x) / 2 - rect.left,
|
|
1455
|
+
contentWidth: snap.contentWidth,
|
|
1456
|
+
snapshot: snap.base
|
|
1457
|
+
};
|
|
1458
|
+
canvas.setPointerCapture(pointerEvent.pointerId);
|
|
1459
|
+
hidePrompt();
|
|
1460
|
+
}
|
|
1461
|
+
return;
|
|
1462
|
+
}
|
|
1463
|
+
if (pointerEvent.button !== 0) return;
|
|
1219
1464
|
const hit = currentHit(pointerEvent.clientX, pointerEvent.clientY);
|
|
1220
|
-
if ((hit == null ? void 0 : hit.kind) === "event" && !((
|
|
1465
|
+
if ((hit == null ? void 0 : hit.kind) === "event" && !((_b = hit.event.props) == null ? void 0 : _b.isLocked)) {
|
|
1221
1466
|
const direction = resizeDirectionAt(hit, pointerEvent.clientX);
|
|
1222
1467
|
if (direction) {
|
|
1223
1468
|
stateRef.current = {
|
|
@@ -1236,17 +1481,56 @@ var useCanvasInteractions = ({
|
|
|
1236
1481
|
startClientY: pointerEvent.clientY,
|
|
1237
1482
|
active: false
|
|
1238
1483
|
};
|
|
1484
|
+
styleGhost(hit.event);
|
|
1239
1485
|
}
|
|
1486
|
+
} else if (config.dragZoom && (pointerEvent.ctrlKey || pointerEvent.metaKey) && !isTouch) {
|
|
1487
|
+
const snap = snapshotView();
|
|
1488
|
+
if (!snap) return;
|
|
1489
|
+
const rect = canvas.getBoundingClientRect();
|
|
1490
|
+
stateRef.current = {
|
|
1491
|
+
mode: "zoom",
|
|
1492
|
+
startClientX: pointerEvent.clientX,
|
|
1493
|
+
anchorX: pointerEvent.clientX - rect.left,
|
|
1494
|
+
contentWidth: snap.contentWidth,
|
|
1495
|
+
snapshot: snap.base
|
|
1496
|
+
};
|
|
1240
1497
|
} else if (config.panOnDragBackground) {
|
|
1241
|
-
stateRef.current = {
|
|
1498
|
+
stateRef.current = {
|
|
1499
|
+
mode: "pan",
|
|
1500
|
+
lastClientX: pointerEvent.clientX,
|
|
1501
|
+
lastClientY: pointerEvent.clientY,
|
|
1502
|
+
startClientX: pointerEvent.clientX,
|
|
1503
|
+
startClientY: pointerEvent.clientY,
|
|
1504
|
+
touch: isTouch
|
|
1505
|
+
};
|
|
1242
1506
|
canvas.style.cursor = "grabbing";
|
|
1507
|
+
} else if (selectable && !hit) {
|
|
1508
|
+
stateRef.current = {
|
|
1509
|
+
mode: "pan",
|
|
1510
|
+
lastClientX: pointerEvent.clientX,
|
|
1511
|
+
lastClientY: pointerEvent.clientY,
|
|
1512
|
+
startClientX: pointerEvent.clientX,
|
|
1513
|
+
startClientY: pointerEvent.clientY,
|
|
1514
|
+
touch: isTouch
|
|
1515
|
+
};
|
|
1243
1516
|
} else {
|
|
1244
1517
|
return;
|
|
1245
1518
|
}
|
|
1246
1519
|
hidePrompt();
|
|
1247
1520
|
canvas.setPointerCapture(pointerEvent.pointerId);
|
|
1248
1521
|
},
|
|
1249
|
-
[
|
|
1522
|
+
[
|
|
1523
|
+
currentHit,
|
|
1524
|
+
resizeDirectionAt,
|
|
1525
|
+
dynamicCanvasRef,
|
|
1526
|
+
hidePrompt,
|
|
1527
|
+
config,
|
|
1528
|
+
snapshotView,
|
|
1529
|
+
ghostRef,
|
|
1530
|
+
rendererRef,
|
|
1531
|
+
styleGhost,
|
|
1532
|
+
selectable
|
|
1533
|
+
]
|
|
1250
1534
|
);
|
|
1251
1535
|
const handleHover = useCallback(
|
|
1252
1536
|
(pointerEvent) => {
|
|
@@ -1303,32 +1587,93 @@ var useCanvasInteractions = ({
|
|
|
1303
1587
|
onEventHover
|
|
1304
1588
|
]
|
|
1305
1589
|
);
|
|
1590
|
+
const resolveRowAtClientY = useCallback(
|
|
1591
|
+
(clientY) => {
|
|
1592
|
+
const canvas = dynamicCanvasRef.current;
|
|
1593
|
+
const renderer = rendererRef.current;
|
|
1594
|
+
if (!canvas || !renderer) return null;
|
|
1595
|
+
const view = renderer.getView();
|
|
1596
|
+
if (view.tick === null) return null;
|
|
1597
|
+
const yContent = clientY - canvas.getBoundingClientRect().top + view.scrollTop;
|
|
1598
|
+
let rowTop = 0;
|
|
1599
|
+
for (const id of scene.getVisibleRowIds()) {
|
|
1600
|
+
const height = scene.getRowHeight(
|
|
1601
|
+
id,
|
|
1602
|
+
view.windowTime[0],
|
|
1603
|
+
view.windowTime[1]
|
|
1604
|
+
);
|
|
1605
|
+
if (yContent >= rowTop && yContent < rowTop + height) return id;
|
|
1606
|
+
rowTop += height;
|
|
1607
|
+
}
|
|
1608
|
+
return null;
|
|
1609
|
+
},
|
|
1610
|
+
[dynamicCanvasRef, rendererRef, scene]
|
|
1611
|
+
);
|
|
1306
1612
|
const handlePointerMove = useCallback(
|
|
1307
1613
|
(pointerEvent) => {
|
|
1308
|
-
var _a, _b;
|
|
1614
|
+
var _a, _b, _c, _d;
|
|
1615
|
+
const tracked = pointersRef.current.get(pointerEvent.pointerId);
|
|
1616
|
+
if (tracked) {
|
|
1617
|
+
tracked.x = pointerEvent.clientX;
|
|
1618
|
+
tracked.y = pointerEvent.clientY;
|
|
1619
|
+
}
|
|
1309
1620
|
const state = stateRef.current;
|
|
1310
1621
|
if (state.mode === "idle") {
|
|
1311
1622
|
handleHover(pointerEvent);
|
|
1312
1623
|
return;
|
|
1313
1624
|
}
|
|
1625
|
+
if (state.mode === "pinch") {
|
|
1626
|
+
const pts = [...pointersRef.current.values()];
|
|
1627
|
+
if (pts.length < 2) return;
|
|
1628
|
+
const dist = Math.hypot(pts[0].x - pts[1].x, pts[0].y - pts[1].y) || 1;
|
|
1629
|
+
zoomPendingRef.current = {
|
|
1630
|
+
anchorX: state.anchorX,
|
|
1631
|
+
factor: state.startDist / dist
|
|
1632
|
+
// fingers apart -> factor<1 -> zoom in
|
|
1633
|
+
};
|
|
1634
|
+
scheduleContinuousZoom();
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
if (state.mode === "zoom") {
|
|
1638
|
+
const dx = pointerEvent.clientX - state.startClientX;
|
|
1639
|
+
zoomPendingRef.current = {
|
|
1640
|
+
anchorX: state.anchorX,
|
|
1641
|
+
factor: Math.pow(2, -dx / DRAG_ZOOM_PX_PER_DOUBLING)
|
|
1642
|
+
// right -> zoom in
|
|
1643
|
+
};
|
|
1644
|
+
scheduleContinuousZoom();
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1314
1647
|
if (state.mode === "pan") {
|
|
1315
1648
|
panPendingDxRef.current += pointerEvent.clientX - state.lastClientX;
|
|
1649
|
+
if (state.touch && bodyRef.current) {
|
|
1650
|
+
bodyRef.current.scrollTop -= pointerEvent.clientY - state.lastClientY;
|
|
1651
|
+
}
|
|
1316
1652
|
state.lastClientX = pointerEvent.clientX;
|
|
1653
|
+
state.lastClientY = pointerEvent.clientY;
|
|
1317
1654
|
schedulePan();
|
|
1318
1655
|
return;
|
|
1319
1656
|
}
|
|
1320
1657
|
if (state.mode === "drag") {
|
|
1658
|
+
if ((_a = state.hit.event.props) == null ? void 0 : _a.isGroupParent) return;
|
|
1321
1659
|
if (!state.active && Math.abs(pointerEvent.clientX - state.startClientX) + Math.abs(pointerEvent.clientY - state.startClientY) > DRAG_THRESHOLD_PX) {
|
|
1322
1660
|
state.active = true;
|
|
1323
|
-
(
|
|
1661
|
+
(_b = rendererRef.current) == null ? void 0 : _b.setView({ draggedEventId: state.hit.event.id });
|
|
1324
1662
|
}
|
|
1325
1663
|
if (state.active) {
|
|
1326
1664
|
updateGhost(state, pointerEvent.clientX, pointerEvent.clientY);
|
|
1665
|
+
const allowed = (_c = state.hit.event.props) == null ? void 0 : _c.droppableRowIds;
|
|
1666
|
+
if (allowed) {
|
|
1667
|
+
const row = resolveRowAtClientY(pointerEvent.clientY);
|
|
1668
|
+
const ok = row !== null && isRowDroppable(allowed, row);
|
|
1669
|
+
const canvas = dynamicCanvasRef.current;
|
|
1670
|
+
if (canvas) canvas.style.cursor = ok ? "grabbing" : "not-allowed";
|
|
1671
|
+
}
|
|
1327
1672
|
}
|
|
1328
1673
|
return;
|
|
1329
1674
|
}
|
|
1330
1675
|
state.deltaPx = pointerEvent.clientX - state.startClientX;
|
|
1331
|
-
(
|
|
1676
|
+
(_d = rendererRef.current) == null ? void 0 : _d.setView({
|
|
1332
1677
|
resizePreview: {
|
|
1333
1678
|
eventId: state.event.id,
|
|
1334
1679
|
deltaPx: state.deltaPx,
|
|
@@ -1336,34 +1681,34 @@ var useCanvasInteractions = ({
|
|
|
1336
1681
|
}
|
|
1337
1682
|
});
|
|
1338
1683
|
},
|
|
1339
|
-
[
|
|
1684
|
+
[
|
|
1685
|
+
handleHover,
|
|
1686
|
+
schedulePan,
|
|
1687
|
+
updateGhost,
|
|
1688
|
+
rendererRef,
|
|
1689
|
+
scheduleContinuousZoom,
|
|
1690
|
+
bodyRef,
|
|
1691
|
+
resolveRowAtClientY,
|
|
1692
|
+
dynamicCanvasRef
|
|
1693
|
+
]
|
|
1340
1694
|
);
|
|
1341
1695
|
const commitDrop = useCallback(
|
|
1342
1696
|
(state, clientX, clientY) => {
|
|
1697
|
+
var _a;
|
|
1343
1698
|
const canvas = dynamicCanvasRef.current;
|
|
1344
1699
|
const renderer = rendererRef.current;
|
|
1345
1700
|
if (!canvas || !renderer) return;
|
|
1346
1701
|
const view = renderer.getView();
|
|
1347
1702
|
if (view.tick === null || view.cellWidth <= 0) return;
|
|
1348
1703
|
const canvasRect = canvas.getBoundingClientRect();
|
|
1349
|
-
const
|
|
1350
|
-
let rowTop = 0;
|
|
1351
|
-
let targetRowId = null;
|
|
1352
|
-
for (const id of scene.getRowIds()) {
|
|
1353
|
-
const height = scene.getRowHeight(
|
|
1354
|
-
id,
|
|
1355
|
-
view.windowTime[0],
|
|
1356
|
-
view.windowTime[1]
|
|
1357
|
-
);
|
|
1358
|
-
if (yContent >= rowTop && yContent < rowTop + height) {
|
|
1359
|
-
targetRowId = id;
|
|
1360
|
-
break;
|
|
1361
|
-
}
|
|
1362
|
-
rowTop += height;
|
|
1363
|
-
}
|
|
1704
|
+
const targetRowId = resolveRowAtClientY(clientY);
|
|
1364
1705
|
if (targetRowId === null) return;
|
|
1365
1706
|
const liveEvent = scene.getEvent(state.hit.event.id);
|
|
1366
1707
|
if (!liveEvent) return;
|
|
1708
|
+
if (!isRowDroppable((_a = liveEvent.props) == null ? void 0 : _a.droppableRowIds, targetRowId)) {
|
|
1709
|
+
renderer.animator.snapEventTop(liveEvent.id);
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1367
1712
|
const { startTime, endTime } = computeDropTimes({
|
|
1368
1713
|
pointerX: clientX - canvasRect.left,
|
|
1369
1714
|
cellWidth: view.cellWidth,
|
|
@@ -1389,7 +1734,7 @@ var useCanvasInteractions = ({
|
|
|
1389
1734
|
}
|
|
1390
1735
|
]);
|
|
1391
1736
|
},
|
|
1392
|
-
[scene, dynamicCanvasRef, rendererRef, onDrop]
|
|
1737
|
+
[scene, dynamicCanvasRef, rendererRef, onDrop, resolveRowAtClientY]
|
|
1393
1738
|
);
|
|
1394
1739
|
const commitResize = useCallback(
|
|
1395
1740
|
(state) => {
|
|
@@ -1426,6 +1771,7 @@ var useCanvasInteractions = ({
|
|
|
1426
1771
|
var _a;
|
|
1427
1772
|
const canvas = dynamicCanvasRef.current;
|
|
1428
1773
|
const state = stateRef.current;
|
|
1774
|
+
pointersRef.current.delete(pointerEvent.pointerId);
|
|
1429
1775
|
stateRef.current = { mode: "idle" };
|
|
1430
1776
|
if (canvas == null ? void 0 : canvas.hasPointerCapture(pointerEvent.pointerId)) {
|
|
1431
1777
|
canvas.releasePointerCapture(pointerEvent.pointerId);
|
|
@@ -1449,6 +1795,19 @@ var useCanvasInteractions = ({
|
|
|
1449
1795
|
}
|
|
1450
1796
|
});
|
|
1451
1797
|
}
|
|
1798
|
+
if (selectable) {
|
|
1799
|
+
const id = state.hit.event.id;
|
|
1800
|
+
if (scene.isEventSelectable(id)) {
|
|
1801
|
+
applySelection(
|
|
1802
|
+
pointerEvent.ctrlKey || pointerEvent.metaKey ? scene.getConnectedEventIds(id) : [id]
|
|
1803
|
+
);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
} else if (state.mode === "pan") {
|
|
1807
|
+
const moved = Math.abs(pointerEvent.clientX - state.startClientX) + Math.abs(pointerEvent.clientY - state.startClientY) > DRAG_THRESHOLD_PX;
|
|
1808
|
+
if (selectable && !moved && getSelection().length > 0) {
|
|
1809
|
+
applySelection([]);
|
|
1810
|
+
}
|
|
1452
1811
|
} else if (state.mode === "resize") {
|
|
1453
1812
|
commitResize(state);
|
|
1454
1813
|
}
|
|
@@ -1459,9 +1818,27 @@ var useCanvasInteractions = ({
|
|
|
1459
1818
|
rendererRef,
|
|
1460
1819
|
commitDrop,
|
|
1461
1820
|
commitResize,
|
|
1462
|
-
onEventClick
|
|
1821
|
+
onEventClick,
|
|
1822
|
+
selectable,
|
|
1823
|
+
applySelection,
|
|
1824
|
+
getSelection,
|
|
1825
|
+
scene
|
|
1463
1826
|
]
|
|
1464
1827
|
);
|
|
1828
|
+
const handlePointerCancel = useCallback(
|
|
1829
|
+
(pointerEvent) => {
|
|
1830
|
+
var _a;
|
|
1831
|
+
pointersRef.current.delete(pointerEvent.pointerId);
|
|
1832
|
+
stateRef.current = { mode: "idle" };
|
|
1833
|
+
const canvas = dynamicCanvasRef.current;
|
|
1834
|
+
if (canvas == null ? void 0 : canvas.hasPointerCapture(pointerEvent.pointerId)) {
|
|
1835
|
+
canvas.releasePointerCapture(pointerEvent.pointerId);
|
|
1836
|
+
}
|
|
1837
|
+
if (ghostRef.current) ghostRef.current.style.display = "none";
|
|
1838
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null });
|
|
1839
|
+
},
|
|
1840
|
+
[dynamicCanvasRef, ghostRef, rendererRef]
|
|
1841
|
+
);
|
|
1465
1842
|
const handlePointerLeave = useCallback(() => {
|
|
1466
1843
|
var _a, _b;
|
|
1467
1844
|
if (stateRef.current.mode !== "idle") return;
|
|
@@ -1492,28 +1869,57 @@ var useCanvasInteractions = ({
|
|
|
1492
1869
|
if (!canvas) return;
|
|
1493
1870
|
const handleWheel = (wheelEvent) => {
|
|
1494
1871
|
var _a;
|
|
1495
|
-
const
|
|
1496
|
-
if (!
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1872
|
+
const view = (_a = rendererRef.current) == null ? void 0 : _a.getView();
|
|
1873
|
+
if (!view || view.tick === null) return;
|
|
1874
|
+
const tick = view.tick;
|
|
1875
|
+
if (changeGridRef.current) {
|
|
1876
|
+
wheelEvent.preventDefault();
|
|
1877
|
+
setCellWidth(
|
|
1878
|
+
(cellWidth) => stepCellWidth(
|
|
1879
|
+
cellWidth,
|
|
1880
|
+
wheelEvent.deltaY,
|
|
1881
|
+
tick * 900 / config.zoomStepSeconds
|
|
1882
|
+
)
|
|
1883
|
+
);
|
|
1884
|
+
return;
|
|
1885
|
+
}
|
|
1886
|
+
if ((wheelEvent.ctrlKey || wheelEvent.metaKey) && config.ctrlWheelZoom) {
|
|
1887
|
+
wheelEvent.preventDefault();
|
|
1888
|
+
const rect = canvas.getBoundingClientRect();
|
|
1889
|
+
const factor = wheelEvent.deltaY > 0 ? config.zoomWheelFactor : 1 / config.zoomWheelFactor;
|
|
1890
|
+
applyZoom(
|
|
1891
|
+
{
|
|
1892
|
+
windowTime: [view.windowTime[0], view.windowTime[1]],
|
|
1893
|
+
tick,
|
|
1894
|
+
cellWidth: view.cellWidth
|
|
1895
|
+
},
|
|
1896
|
+
wheelEvent.clientX - rect.left,
|
|
1897
|
+
factor,
|
|
1898
|
+
rect.width
|
|
1899
|
+
);
|
|
1900
|
+
return;
|
|
1901
|
+
}
|
|
1507
1902
|
};
|
|
1508
1903
|
canvas.addEventListener("wheel", handleWheel, { passive: false });
|
|
1509
1904
|
return () => canvas.removeEventListener("wheel", handleWheel);
|
|
1510
|
-
}, [dynamicCanvasRef, rendererRef, setCellWidth, config]);
|
|
1905
|
+
}, [dynamicCanvasRef, rendererRef, setCellWidth, applyZoom, config]);
|
|
1511
1906
|
useEffect4(() => unlockCursor, []);
|
|
1907
|
+
useEffect4(() => {
|
|
1908
|
+
if (!selectable) return;
|
|
1909
|
+
const handleKeyDown = (keyEvent) => {
|
|
1910
|
+
if (keyEvent.key === "Escape" && getSelection().length > 0) {
|
|
1911
|
+
applySelection([]);
|
|
1912
|
+
}
|
|
1913
|
+
};
|
|
1914
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
1915
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
1916
|
+
}, [selectable, getSelection, applySelection]);
|
|
1512
1917
|
return {
|
|
1513
1918
|
handlePointerDown,
|
|
1514
1919
|
handlePointerMove,
|
|
1515
1920
|
handlePointerUp,
|
|
1516
1921
|
handlePointerLeave,
|
|
1922
|
+
handlePointerCancel,
|
|
1517
1923
|
handleAuxClick
|
|
1518
1924
|
};
|
|
1519
1925
|
};
|
|
@@ -1535,17 +1941,23 @@ var CanvasBoard = forwardRef2(
|
|
|
1535
1941
|
rowsHeaderClassName,
|
|
1536
1942
|
setWindowTime,
|
|
1537
1943
|
setCellWidth,
|
|
1944
|
+
setTick,
|
|
1538
1945
|
onDrop,
|
|
1539
1946
|
onResize,
|
|
1540
1947
|
onEventClick,
|
|
1541
1948
|
onEventHover,
|
|
1542
1949
|
eventsResize,
|
|
1543
1950
|
panZoom,
|
|
1544
|
-
animations
|
|
1951
|
+
animations,
|
|
1952
|
+
selectable,
|
|
1953
|
+
applySelection,
|
|
1954
|
+
getSelection
|
|
1545
1955
|
}, contentRef) => {
|
|
1546
1956
|
const staticCanvasRef = useRef6(null);
|
|
1547
1957
|
const dynamicCanvasRef = useRef6(null);
|
|
1548
1958
|
const ghostRef = useRef6(null);
|
|
1959
|
+
const headerWrapperRef = useRef6(null);
|
|
1960
|
+
const totalHeightRef = useRef6(0);
|
|
1549
1961
|
const [scrollTop, setScrollTop] = useState3(0);
|
|
1550
1962
|
const [viewportHeight, setViewportHeight] = useState3(0);
|
|
1551
1963
|
useEffect5(() => {
|
|
@@ -1585,25 +1997,29 @@ var CanvasBoard = forwardRef2(
|
|
|
1585
1997
|
animations,
|
|
1586
1998
|
rendererRef
|
|
1587
1999
|
]);
|
|
2000
|
+
const measureViewport = useCallback2(() => {
|
|
2001
|
+
var _a;
|
|
2002
|
+
const column = contentRef && "current" in contentRef ? contentRef.current : null;
|
|
2003
|
+
const body = bodyRef.current;
|
|
2004
|
+
if (!column || !body) return;
|
|
2005
|
+
const cap = totalHeightRef.current > 0 ? totalHeightRef.current : Infinity;
|
|
2006
|
+
const height = Math.min(body.clientHeight, cap, window.innerHeight);
|
|
2007
|
+
setViewportHeight(height);
|
|
2008
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({
|
|
2009
|
+
width: column.getBoundingClientRect().width,
|
|
2010
|
+
height
|
|
2011
|
+
});
|
|
2012
|
+
}, [bodyRef, contentRef, rendererRef]);
|
|
1588
2013
|
useEffect5(() => {
|
|
1589
2014
|
const column = contentRef && "current" in contentRef ? contentRef.current : null;
|
|
1590
2015
|
const body = bodyRef.current;
|
|
1591
2016
|
if (!column || !body) return;
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
const height = Math.min(body.clientHeight, window.innerHeight);
|
|
1595
|
-
setViewportHeight(height);
|
|
1596
|
-
(_a = rendererRef.current) == null ? void 0 : _a.setView({
|
|
1597
|
-
width: column.getBoundingClientRect().width,
|
|
1598
|
-
height
|
|
1599
|
-
});
|
|
1600
|
-
};
|
|
1601
|
-
measure();
|
|
1602
|
-
const observer = new ResizeObserver(measure);
|
|
2017
|
+
measureViewport();
|
|
2018
|
+
const observer = new ResizeObserver(measureViewport);
|
|
1603
2019
|
observer.observe(column);
|
|
1604
2020
|
observer.observe(body);
|
|
1605
2021
|
return () => observer.disconnect();
|
|
1606
|
-
}, [bodyRef, contentRef,
|
|
2022
|
+
}, [bodyRef, contentRef, measureViewport]);
|
|
1607
2023
|
useEffect5(() => {
|
|
1608
2024
|
const body = bodyRef.current;
|
|
1609
2025
|
if (!body) return;
|
|
@@ -1619,11 +2035,49 @@ var CanvasBoard = forwardRef2(
|
|
|
1619
2035
|
useCallback2((listener) => scene.subscribe(listener), [scene]),
|
|
1620
2036
|
() => scene.version
|
|
1621
2037
|
);
|
|
2038
|
+
useLayoutEffect(() => {
|
|
2039
|
+
const wrapper = headerWrapperRef.current;
|
|
2040
|
+
if (!wrapper) return;
|
|
2041
|
+
const measurer = document.createElement("div");
|
|
2042
|
+
measurer.className = "row-header-label";
|
|
2043
|
+
measurer.setAttribute("aria-hidden", "true");
|
|
2044
|
+
measurer.style.position = "absolute";
|
|
2045
|
+
measurer.style.left = "-9999px";
|
|
2046
|
+
measurer.style.top = "0";
|
|
2047
|
+
measurer.style.visibility = "hidden";
|
|
2048
|
+
measurer.style.height = "auto";
|
|
2049
|
+
wrapper.appendChild(measurer);
|
|
2050
|
+
let lastWidth = -1;
|
|
2051
|
+
const measure = () => {
|
|
2052
|
+
var _a;
|
|
2053
|
+
const width = wrapper.clientWidth;
|
|
2054
|
+
if (width === 0 || width === lastWidth) return;
|
|
2055
|
+
lastWidth = width;
|
|
2056
|
+
measurer.style.width = `${width}px`;
|
|
2057
|
+
const heights = /* @__PURE__ */ new Map();
|
|
2058
|
+
for (const row of rows) {
|
|
2059
|
+
measurer.textContent = (_a = row.name) != null ? _a : "";
|
|
2060
|
+
heights.set(
|
|
2061
|
+
row.id,
|
|
2062
|
+
Math.ceil(measurer.offsetHeight) + 2 * theme.rowPaddingY
|
|
2063
|
+
);
|
|
2064
|
+
}
|
|
2065
|
+
scene.setLabelMinHeights(heights);
|
|
2066
|
+
};
|
|
2067
|
+
measure();
|
|
2068
|
+
const observer = new ResizeObserver(measure);
|
|
2069
|
+
observer.observe(wrapper);
|
|
2070
|
+
return () => {
|
|
2071
|
+
observer.disconnect();
|
|
2072
|
+
wrapper.removeChild(measurer);
|
|
2073
|
+
};
|
|
2074
|
+
}, [rows, scene, theme.rowPaddingY, rowsHeaderClassName]);
|
|
1622
2075
|
const {
|
|
1623
2076
|
handlePointerDown,
|
|
1624
2077
|
handlePointerMove,
|
|
1625
2078
|
handlePointerUp,
|
|
1626
2079
|
handlePointerLeave,
|
|
2080
|
+
handlePointerCancel,
|
|
1627
2081
|
handleAuxClick
|
|
1628
2082
|
} = use_canvas_interactions_default({
|
|
1629
2083
|
scene,
|
|
@@ -1634,24 +2088,52 @@ var CanvasBoard = forwardRef2(
|
|
|
1634
2088
|
eventPromptRef,
|
|
1635
2089
|
setWindowTime,
|
|
1636
2090
|
setCellWidth,
|
|
2091
|
+
setTick,
|
|
1637
2092
|
onDrop,
|
|
1638
2093
|
onResize,
|
|
1639
2094
|
onEventClick,
|
|
1640
2095
|
onEventHover,
|
|
1641
2096
|
eventsResize,
|
|
1642
|
-
panZoom
|
|
2097
|
+
panZoom,
|
|
2098
|
+
selectable,
|
|
2099
|
+
applySelection,
|
|
2100
|
+
getSelection
|
|
1643
2101
|
});
|
|
2102
|
+
useEffect5(() => {
|
|
2103
|
+
var _a;
|
|
2104
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({
|
|
2105
|
+
selectedEventIds: new Set(getSelection())
|
|
2106
|
+
});
|
|
2107
|
+
}, [getSelection, rendererRef]);
|
|
1644
2108
|
const { offsetOf, totalHeight } = scene.getRowOffsets(
|
|
1645
2109
|
windowTime[0],
|
|
1646
2110
|
windowTime[1]
|
|
1647
2111
|
);
|
|
2112
|
+
totalHeightRef.current = totalHeight;
|
|
2113
|
+
useLayoutEffect(() => {
|
|
2114
|
+
measureViewport();
|
|
2115
|
+
}, [totalHeight, measureViewport]);
|
|
2116
|
+
const lastChildOf = /* @__PURE__ */ new Map();
|
|
2117
|
+
for (const row of rows) {
|
|
2118
|
+
if (row.parentId !== void 0) lastChildOf.set(row.parentId, row.id);
|
|
2119
|
+
}
|
|
2120
|
+
const connectorColor = theme.gridColor;
|
|
2121
|
+
const SPINE_X = 11;
|
|
1648
2122
|
const visibleHeaders = [];
|
|
1649
2123
|
for (let i = 0; i < rows.length; i++) {
|
|
1650
2124
|
const row = rows[i];
|
|
2125
|
+
if (scene.isRowHidden(row.id)) continue;
|
|
1651
2126
|
const top = offsetOf.get(row.id);
|
|
2127
|
+
if (top === void 0) continue;
|
|
1652
2128
|
const height = scene.getRowHeight(row.id, windowTime[0], windowTime[1]);
|
|
1653
2129
|
if (top + height < scrollTop) continue;
|
|
1654
2130
|
if (top > scrollTop + viewportHeight) break;
|
|
2131
|
+
const isParent = scene.isRowParent(row.id);
|
|
2132
|
+
const parentId = row.parentId;
|
|
2133
|
+
const isChild = parentId !== void 0;
|
|
2134
|
+
const isLastChild = parentId !== void 0 && lastChildOf.get(parentId) === row.id;
|
|
2135
|
+
const collapsed = scene.isRowCollapsed(row.id);
|
|
2136
|
+
const grouped = isParent || isChild;
|
|
1655
2137
|
visibleHeaders.push(
|
|
1656
2138
|
/* @__PURE__ */ React5.createElement(
|
|
1657
2139
|
"div",
|
|
@@ -1662,16 +2144,79 @@ var CanvasBoard = forwardRef2(
|
|
|
1662
2144
|
top,
|
|
1663
2145
|
height,
|
|
1664
2146
|
borderBottom: i === rows.length - 1 ? "none" : "1px solid yellow",
|
|
1665
|
-
//
|
|
1666
|
-
|
|
2147
|
+
// Row heights/positions apply instantly (no layout tween) so the
|
|
2148
|
+
// header snaps in lockstep with its canvas row — see draw-events.
|
|
2149
|
+
// Grouped rows left-align so the caret + tree spine line up; plain
|
|
2150
|
+
// rows keep the centered default.
|
|
2151
|
+
justifyContent: grouped ? "flex-start" : void 0,
|
|
2152
|
+
paddingLeft: isChild ? 24 : isParent ? 6 : void 0
|
|
1667
2153
|
}
|
|
1668
2154
|
},
|
|
1669
|
-
row
|
|
2155
|
+
isChild && // tree connector: a vertical spine + a horizontal tick at the row's
|
|
2156
|
+
// vertical center. The spine runs the full height for a mid child
|
|
2157
|
+
// (├─) and stops at the center for the last child (└─), so stacked
|
|
2158
|
+
// children form one continuous spine descending from the parent.
|
|
2159
|
+
/* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(
|
|
2160
|
+
"span",
|
|
2161
|
+
{
|
|
2162
|
+
"aria-hidden": true,
|
|
2163
|
+
style: {
|
|
2164
|
+
position: "absolute",
|
|
2165
|
+
left: SPINE_X,
|
|
2166
|
+
top: 0,
|
|
2167
|
+
width: 1,
|
|
2168
|
+
height: isLastChild ? "50%" : "100%",
|
|
2169
|
+
backgroundColor: connectorColor,
|
|
2170
|
+
pointerEvents: "none"
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
), /* @__PURE__ */ React5.createElement(
|
|
2174
|
+
"span",
|
|
2175
|
+
{
|
|
2176
|
+
"aria-hidden": true,
|
|
2177
|
+
style: {
|
|
2178
|
+
position: "absolute",
|
|
2179
|
+
left: SPINE_X,
|
|
2180
|
+
top: "50%",
|
|
2181
|
+
width: 9,
|
|
2182
|
+
height: 1,
|
|
2183
|
+
backgroundColor: connectorColor,
|
|
2184
|
+
pointerEvents: "none"
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
)),
|
|
2188
|
+
isParent && /* @__PURE__ */ React5.createElement(
|
|
2189
|
+
"span",
|
|
2190
|
+
{
|
|
2191
|
+
className: "row-header-caret",
|
|
2192
|
+
role: "button",
|
|
2193
|
+
"aria-label": collapsed ? "Expand group" : "Collapse group",
|
|
2194
|
+
onClick: () => scene.toggleCollapsed(row.id),
|
|
2195
|
+
style: { cursor: "pointer", marginRight: 4, userSelect: "none" }
|
|
2196
|
+
},
|
|
2197
|
+
collapsed ? "\u25B8" : "\u25BE"
|
|
2198
|
+
),
|
|
2199
|
+
/* @__PURE__ */ React5.createElement(
|
|
2200
|
+
"span",
|
|
2201
|
+
{
|
|
2202
|
+
className: "row-header-label",
|
|
2203
|
+
style: grouped ? { textAlign: "left" } : void 0
|
|
2204
|
+
},
|
|
2205
|
+
row.name
|
|
2206
|
+
)
|
|
1670
2207
|
)
|
|
1671
2208
|
);
|
|
1672
2209
|
}
|
|
1673
2210
|
const headerClassNames = rowsHeaderClassName ? `rows-header-wrapper canvas-rows-header ${rowsHeaderClassName}` : "rows-header-wrapper canvas-rows-header";
|
|
1674
|
-
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(
|
|
2211
|
+
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(
|
|
2212
|
+
"div",
|
|
2213
|
+
{
|
|
2214
|
+
ref: headerWrapperRef,
|
|
2215
|
+
className: headerClassNames,
|
|
2216
|
+
style: { height: totalHeight }
|
|
2217
|
+
},
|
|
2218
|
+
visibleHeaders
|
|
2219
|
+
), /* @__PURE__ */ React5.createElement("div", { className: "canvas-content-column", ref: contentRef }, /* @__PURE__ */ React5.createElement("div", { className: "canvas-sticky" }, /* @__PURE__ */ React5.createElement("canvas", { ref: staticCanvasRef }), /* @__PURE__ */ React5.createElement(
|
|
1675
2220
|
"canvas",
|
|
1676
2221
|
{
|
|
1677
2222
|
ref: dynamicCanvasRef,
|
|
@@ -1679,9 +2224,17 @@ var CanvasBoard = forwardRef2(
|
|
|
1679
2224
|
onPointerMove: handlePointerMove,
|
|
1680
2225
|
onPointerUp: handlePointerUp,
|
|
1681
2226
|
onPointerLeave: handlePointerLeave,
|
|
2227
|
+
onPointerCancel: handlePointerCancel,
|
|
1682
2228
|
onAuxClick: handleAuxClick
|
|
1683
2229
|
}
|
|
1684
|
-
), /* @__PURE__ */ React5.createElement(
|
|
2230
|
+
), /* @__PURE__ */ React5.createElement(
|
|
2231
|
+
"div",
|
|
2232
|
+
{
|
|
2233
|
+
ref: ghostRef,
|
|
2234
|
+
className: "event canvas-drag-ghost",
|
|
2235
|
+
style: { height: scene.getGeometry().barHeight }
|
|
2236
|
+
}
|
|
2237
|
+
)), /* @__PURE__ */ React5.createElement(
|
|
1685
2238
|
"div",
|
|
1686
2239
|
{
|
|
1687
2240
|
className: "canvas-scroll-spacer",
|
|
@@ -1711,9 +2264,48 @@ var SceneStore = class {
|
|
|
1711
2264
|
this.rowIndexes = /* @__PURE__ */ new Map();
|
|
1712
2265
|
this.rowOrder = [];
|
|
1713
2266
|
this.eventRow = /* @__PURE__ */ new Map();
|
|
2267
|
+
// Group index for tag-based "connected" selection. eventGroup: eventId ->
|
|
2268
|
+
// groupId; groupMembers: groupId -> set of eventIds. Maintained alongside
|
|
2269
|
+
// eventRow so Cmd/Ctrl+click resolves the whole group in O(group size)
|
|
2270
|
+
// without scanning all rows.
|
|
2271
|
+
this.eventGroup = /* @__PURE__ */ new Map();
|
|
2272
|
+
this.groupMembers = /* @__PURE__ */ new Map();
|
|
2273
|
+
// Row hierarchy for grouped (collapsible) rows. parentOf: childRowId ->
|
|
2274
|
+
// parentRowId; childRowsOf: parentRowId -> ordered child row ids. Rebuilt in
|
|
2275
|
+
// setRows from `row.parentId`. One level of nesting only in v1.
|
|
2276
|
+
this.parentOf = /* @__PURE__ */ new Map();
|
|
2277
|
+
this.childRowsOf = /* @__PURE__ */ new Map();
|
|
2278
|
+
// Rows the user has collapsed. Lives only here so it survives every data
|
|
2279
|
+
// update (setEvents / applyPatches / events-prop reset); setRows only prunes
|
|
2280
|
+
// entries for rows that no longer exist.
|
|
2281
|
+
this.collapsedRows = /* @__PURE__ */ new Set();
|
|
2282
|
+
// Parent↔child EVENT index (distinct from the row hierarchy above).
|
|
2283
|
+
// childrenOf: parentEventId -> child event ids; parentEventOf: childEventId ->
|
|
2284
|
+
// parentEventId. Driven by props.parentEventId / props.isGroupParent. A parent
|
|
2285
|
+
// event's [startTime,endTime] is derived lazily from its children; any child
|
|
2286
|
+
// mutation marks the parent dirty and the span is recomputed on the next query
|
|
2287
|
+
// of the parent's row (flushParentSpans) — off-screen groups cost nothing.
|
|
2288
|
+
this.childrenOf = /* @__PURE__ */ new Map();
|
|
2289
|
+
this.parentEventOf = /* @__PURE__ */ new Map();
|
|
2290
|
+
this.parentSpanDirty = /* @__PURE__ */ new Set();
|
|
1714
2291
|
this.listeners = /* @__PURE__ */ new Set();
|
|
2292
|
+
// Themeable vertical layout. Lanes are geometry-free (pure time logic), so a
|
|
2293
|
+
// geometry change only affects heights/offsets — the cached lanes stay valid
|
|
2294
|
+
// and we just bump to trigger a redraw.
|
|
2295
|
+
this.geometry = DEFAULT_GEOMETRY;
|
|
2296
|
+
// Per-row minimum height demanded by the (DOM-measured) row label when it
|
|
2297
|
+
// wraps to multiple lines. Measured in the shell and fed back here so the
|
|
2298
|
+
// canvas grid/dividers, hit-testing and the DOM header all agree on height.
|
|
2299
|
+
this.labelMinHeights = /* @__PURE__ */ new Map();
|
|
1715
2300
|
this.version = 0;
|
|
1716
2301
|
}
|
|
2302
|
+
setGeometry(geometry) {
|
|
2303
|
+
this.geometry = geometry;
|
|
2304
|
+
this.bump();
|
|
2305
|
+
}
|
|
2306
|
+
getGeometry() {
|
|
2307
|
+
return this.geometry;
|
|
2308
|
+
}
|
|
1717
2309
|
setRows(rows) {
|
|
1718
2310
|
const next = /* @__PURE__ */ new Map();
|
|
1719
2311
|
for (const row of rows) {
|
|
@@ -1732,23 +2324,53 @@ var SceneStore = class {
|
|
|
1732
2324
|
);
|
|
1733
2325
|
}
|
|
1734
2326
|
for (const [id, rowId] of this.eventRow) {
|
|
1735
|
-
if (!next.has(rowId))
|
|
2327
|
+
if (!next.has(rowId)) {
|
|
2328
|
+
this.eventRow.delete(id);
|
|
2329
|
+
this.removeFromGroup(id);
|
|
2330
|
+
}
|
|
1736
2331
|
}
|
|
1737
2332
|
this.rowIndexes = next;
|
|
1738
2333
|
this.rowOrder = rows.map((row) => row.id);
|
|
2334
|
+
this.parentOf = /* @__PURE__ */ new Map();
|
|
2335
|
+
this.childRowsOf = /* @__PURE__ */ new Map();
|
|
2336
|
+
for (const row of rows) {
|
|
2337
|
+
if (row.parentId === void 0) continue;
|
|
2338
|
+
this.parentOf.set(row.id, row.parentId);
|
|
2339
|
+
let children = this.childRowsOf.get(row.parentId);
|
|
2340
|
+
if (!children) {
|
|
2341
|
+
children = [];
|
|
2342
|
+
this.childRowsOf.set(row.parentId, children);
|
|
2343
|
+
}
|
|
2344
|
+
children.push(row.id);
|
|
2345
|
+
}
|
|
2346
|
+
if (this.collapsedRows.size > 0) {
|
|
2347
|
+
const rowIds = new Set(this.rowOrder);
|
|
2348
|
+
for (const id of [...this.collapsedRows]) {
|
|
2349
|
+
if (!rowIds.has(id)) this.collapsedRows.delete(id);
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
1739
2352
|
this.bump();
|
|
1740
2353
|
}
|
|
1741
2354
|
setEvents(events) {
|
|
2355
|
+
var _a;
|
|
1742
2356
|
for (const index of this.rowIndexes.values()) {
|
|
1743
2357
|
index.events = [];
|
|
1744
2358
|
index.lanesDirty = true;
|
|
1745
2359
|
}
|
|
1746
2360
|
this.eventRow.clear();
|
|
2361
|
+
this.eventGroup.clear();
|
|
2362
|
+
this.groupMembers.clear();
|
|
2363
|
+
this.childrenOf.clear();
|
|
2364
|
+
this.parentEventOf.clear();
|
|
2365
|
+
this.parentSpanDirty.clear();
|
|
1747
2366
|
for (const event of events) {
|
|
1748
2367
|
const index = this.rowIndexes.get(event.rowId);
|
|
1749
2368
|
if (!index) continue;
|
|
1750
2369
|
index.events.push(event);
|
|
1751
2370
|
this.eventRow.set(event.id, event.rowId);
|
|
2371
|
+
this.addToGroup(event.id, (_a = event.props) == null ? void 0 : _a.groupId);
|
|
2372
|
+
this.addToParentIndex(event);
|
|
2373
|
+
this.validateDroppable(event);
|
|
1752
2374
|
}
|
|
1753
2375
|
for (const index of this.rowIndexes.values()) {
|
|
1754
2376
|
index.events.sort(sort_events_default);
|
|
@@ -1791,15 +2413,88 @@ var SceneStore = class {
|
|
|
1791
2413
|
if (rowId === void 0) return void 0;
|
|
1792
2414
|
return (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.events.find((event) => event.id === id);
|
|
1793
2415
|
}
|
|
2416
|
+
/**
|
|
2417
|
+
* Event ids "connected" to the given event via a shared `props.groupId`.
|
|
2418
|
+
* Returns every member of the group (including the event itself), or just
|
|
2419
|
+
* `[eventId]` when the event has no group / no other members / is unknown.
|
|
2420
|
+
*/
|
|
2421
|
+
getConnectedEventIds(eventId) {
|
|
2422
|
+
const groupId = this.eventGroup.get(eventId);
|
|
2423
|
+
if (groupId === void 0) return [eventId];
|
|
2424
|
+
const members = this.groupMembers.get(groupId);
|
|
2425
|
+
if (!members || members.size === 0) return [eventId];
|
|
2426
|
+
return [...members];
|
|
2427
|
+
}
|
|
2428
|
+
/**
|
|
2429
|
+
* Whether an event may enter the selection. False only when the event is
|
|
2430
|
+
* present and explicitly opted out (`props.isSelectable === false`); unknown
|
|
2431
|
+
* ids are treated as selectable so a selection can be set before data loads
|
|
2432
|
+
* and survives streaming.
|
|
2433
|
+
*/
|
|
2434
|
+
isEventSelectable(id) {
|
|
2435
|
+
var _a;
|
|
2436
|
+
const event = this.getEvent(id);
|
|
2437
|
+
return event === void 0 || ((_a = event.props) == null ? void 0 : _a.isSelectable) !== false;
|
|
2438
|
+
}
|
|
1794
2439
|
getRowIds() {
|
|
1795
2440
|
return this.rowOrder;
|
|
1796
2441
|
}
|
|
2442
|
+
/**
|
|
2443
|
+
* Row ids in display order, minus rows hidden inside a collapsed parent.
|
|
2444
|
+
* Drives offsets, drawing and hit-testing. The header still walks
|
|
2445
|
+
* `getRowIds()` so it can draw the carets and decide which rows to skip.
|
|
2446
|
+
*/
|
|
2447
|
+
getVisibleRowIds() {
|
|
2448
|
+
if (this.collapsedRows.size === 0) return this.rowOrder;
|
|
2449
|
+
const visible = [];
|
|
2450
|
+
for (const rowId of this.rowOrder) {
|
|
2451
|
+
const parent = this.parentOf.get(rowId);
|
|
2452
|
+
if (parent !== void 0 && this.collapsedRows.has(parent)) continue;
|
|
2453
|
+
visible.push(rowId);
|
|
2454
|
+
}
|
|
2455
|
+
return visible;
|
|
2456
|
+
}
|
|
2457
|
+
/** whether a row is a parent (owns at least one child row) */
|
|
2458
|
+
isRowParent(rowId) {
|
|
2459
|
+
var _a, _b;
|
|
2460
|
+
return ((_b = (_a = this.childRowsOf.get(rowId)) == null ? void 0 : _a.length) != null ? _b : 0) > 0;
|
|
2461
|
+
}
|
|
2462
|
+
/** whether a row is hidden because its parent row is collapsed */
|
|
2463
|
+
isRowHidden(rowId) {
|
|
2464
|
+
const parent = this.parentOf.get(rowId);
|
|
2465
|
+
return parent !== void 0 && this.collapsedRows.has(parent);
|
|
2466
|
+
}
|
|
2467
|
+
isRowCollapsed(rowId) {
|
|
2468
|
+
return this.collapsedRows.has(rowId);
|
|
2469
|
+
}
|
|
2470
|
+
getCollapsedRowIds() {
|
|
2471
|
+
return [...this.collapsedRows];
|
|
2472
|
+
}
|
|
2473
|
+
setCollapsed(rowId, collapsed) {
|
|
2474
|
+
const has = this.collapsedRows.has(rowId);
|
|
2475
|
+
if (collapsed && !has) {
|
|
2476
|
+
this.collapsedRows.add(rowId);
|
|
2477
|
+
this.bump();
|
|
2478
|
+
} else if (!collapsed && has) {
|
|
2479
|
+
this.collapsedRows.delete(rowId);
|
|
2480
|
+
this.bump();
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
toggleCollapsed(rowId) {
|
|
2484
|
+
this.setCollapsed(rowId, !this.collapsedRows.has(rowId));
|
|
2485
|
+
}
|
|
2486
|
+
/** child event ids of a parent (summary) event; empty if it has none */
|
|
2487
|
+
getChildEventIds(parentEventId) {
|
|
2488
|
+
const children = this.childrenOf.get(parentEventId);
|
|
2489
|
+
return children ? [...children] : [];
|
|
2490
|
+
}
|
|
1797
2491
|
getRow(rowId) {
|
|
1798
2492
|
var _a;
|
|
1799
2493
|
return (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.row;
|
|
1800
2494
|
}
|
|
1801
2495
|
getRowEvents(rowId) {
|
|
1802
2496
|
var _a, _b;
|
|
2497
|
+
this.flushParentSpans(rowId);
|
|
1803
2498
|
return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.events) != null ? _b : [];
|
|
1804
2499
|
}
|
|
1805
2500
|
getRowStaticEvents(rowId) {
|
|
@@ -1807,6 +2502,7 @@ var SceneStore = class {
|
|
|
1807
2502
|
return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.staticEvents) != null ? _b : [];
|
|
1808
2503
|
}
|
|
1809
2504
|
getLanes(rowId, windowStart, windowEnd) {
|
|
2505
|
+
this.flushParentSpans(rowId);
|
|
1810
2506
|
const index = this.rowIndexes.get(rowId);
|
|
1811
2507
|
if (!index) return { laneOf: /* @__PURE__ */ new Map(), highestLane: 0 };
|
|
1812
2508
|
if (index.lanesDirty || index.lanes === null || index.laneWindowStart !== windowStart || index.laneWindowEnd !== windowEnd) {
|
|
@@ -1817,8 +2513,35 @@ var SceneStore = class {
|
|
|
1817
2513
|
}
|
|
1818
2514
|
return index.lanes;
|
|
1819
2515
|
}
|
|
2516
|
+
/**
|
|
2517
|
+
* Report the per-row label heights measured against the live DOM header
|
|
2518
|
+
* (key: rowId, value: the minimum row height the wrapped label needs,
|
|
2519
|
+
* already including vertical padding). Replaces the previous map wholesale
|
|
2520
|
+
* and only bumps when a value actually changed, so re-measuring identical
|
|
2521
|
+
* labels is a no-op and can't feed back into an infinite render loop.
|
|
2522
|
+
*/
|
|
2523
|
+
setLabelMinHeights(heights) {
|
|
2524
|
+
let changed = heights.size !== this.labelMinHeights.size;
|
|
2525
|
+
if (!changed) {
|
|
2526
|
+
for (const [id, h] of heights) {
|
|
2527
|
+
if (this.labelMinHeights.get(id) !== h) {
|
|
2528
|
+
changed = true;
|
|
2529
|
+
break;
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
if (!changed) return;
|
|
2534
|
+
this.labelMinHeights = heights;
|
|
2535
|
+
this.bump();
|
|
2536
|
+
}
|
|
1820
2537
|
getRowHeight(rowId, windowStart, windowEnd) {
|
|
1821
|
-
|
|
2538
|
+
var _a;
|
|
2539
|
+
const laneHeight = rowMinHeight(
|
|
2540
|
+
this.getLanes(rowId, windowStart, windowEnd).highestLane,
|
|
2541
|
+
this.geometry
|
|
2542
|
+
);
|
|
2543
|
+
const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
|
|
2544
|
+
return Math.max(laneHeight, labelHeight);
|
|
1822
2545
|
}
|
|
1823
2546
|
/**
|
|
1824
2547
|
* y offset of each row's top edge (content coordinates, before scroll) plus
|
|
@@ -1827,7 +2550,7 @@ var SceneStore = class {
|
|
|
1827
2550
|
getRowOffsets(windowStart, windowEnd) {
|
|
1828
2551
|
const offsetOf = /* @__PURE__ */ new Map();
|
|
1829
2552
|
let y = 0;
|
|
1830
|
-
for (const rowId of this.
|
|
2553
|
+
for (const rowId of this.getVisibleRowIds()) {
|
|
1831
2554
|
offsetOf.set(rowId, y);
|
|
1832
2555
|
y += this.getRowHeight(rowId, windowStart, windowEnd);
|
|
1833
2556
|
}
|
|
@@ -1838,11 +2561,15 @@ var SceneStore = class {
|
|
|
1838
2561
|
return () => this.listeners.delete(listener);
|
|
1839
2562
|
}
|
|
1840
2563
|
insert(event) {
|
|
2564
|
+
var _a;
|
|
1841
2565
|
const index = this.rowIndexes.get(event.rowId);
|
|
1842
2566
|
if (!index) return;
|
|
1843
2567
|
index.events.splice(binaryInsertIndex(index.events, event), 0, event);
|
|
1844
2568
|
index.lanesDirty = true;
|
|
1845
2569
|
this.eventRow.set(event.id, event.rowId);
|
|
2570
|
+
this.addToGroup(event.id, (_a = event.props) == null ? void 0 : _a.groupId);
|
|
2571
|
+
this.addToParentIndex(event);
|
|
2572
|
+
this.validateDroppable(event);
|
|
1846
2573
|
}
|
|
1847
2574
|
remove(id) {
|
|
1848
2575
|
const rowId = this.eventRow.get(id);
|
|
@@ -1854,6 +2581,117 @@ var SceneStore = class {
|
|
|
1854
2581
|
index.lanesDirty = true;
|
|
1855
2582
|
}
|
|
1856
2583
|
this.eventRow.delete(id);
|
|
2584
|
+
this.removeFromGroup(id);
|
|
2585
|
+
this.removeFromParentIndex(id);
|
|
2586
|
+
}
|
|
2587
|
+
addToGroup(eventId, groupId) {
|
|
2588
|
+
if (groupId === void 0) return;
|
|
2589
|
+
this.eventGroup.set(eventId, groupId);
|
|
2590
|
+
let members = this.groupMembers.get(groupId);
|
|
2591
|
+
if (!members) {
|
|
2592
|
+
members = /* @__PURE__ */ new Set();
|
|
2593
|
+
this.groupMembers.set(groupId, members);
|
|
2594
|
+
}
|
|
2595
|
+
members.add(eventId);
|
|
2596
|
+
}
|
|
2597
|
+
removeFromGroup(eventId) {
|
|
2598
|
+
const groupId = this.eventGroup.get(eventId);
|
|
2599
|
+
if (groupId === void 0) return;
|
|
2600
|
+
this.eventGroup.delete(eventId);
|
|
2601
|
+
const members = this.groupMembers.get(groupId);
|
|
2602
|
+
if (members) {
|
|
2603
|
+
members.delete(eventId);
|
|
2604
|
+
if (members.size === 0) this.groupMembers.delete(groupId);
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
/**
|
|
2608
|
+
* Enforce the authoring contract for `props.droppableRowIds`: if the event's
|
|
2609
|
+
* current row is not among its allowed rows, record a `droppableError` on
|
|
2610
|
+
* `props.metadata` (merged non-destructively); otherwise clear any stale one.
|
|
2611
|
+
* Cheap no-op for events without `droppableRowIds` and no prior error.
|
|
2612
|
+
*/
|
|
2613
|
+
validateDroppable(event) {
|
|
2614
|
+
var _a, _b;
|
|
2615
|
+
const allowed = (_a = event.props) == null ? void 0 : _a.droppableRowIds;
|
|
2616
|
+
const meta = (_b = event.props) == null ? void 0 : _b.metadata;
|
|
2617
|
+
const metaObj = typeof meta === "object" && meta !== null ? meta : void 0;
|
|
2618
|
+
const hadError = metaObj !== void 0 && "droppableError" in metaObj;
|
|
2619
|
+
const needsError = allowed !== void 0 && !allowed.includes(event.rowId);
|
|
2620
|
+
if (!needsError && !hadError) return;
|
|
2621
|
+
if (!event.props) return;
|
|
2622
|
+
if (needsError) {
|
|
2623
|
+
event.props.metadata = __spreadProps(__spreadValues({}, metaObj != null ? metaObj : {}), {
|
|
2624
|
+
droppableError: {
|
|
2625
|
+
rowId: event.rowId,
|
|
2626
|
+
droppableRowIds: allowed
|
|
2627
|
+
}
|
|
2628
|
+
});
|
|
2629
|
+
} else {
|
|
2630
|
+
const rest = __spreadValues({}, metaObj);
|
|
2631
|
+
delete rest.droppableError;
|
|
2632
|
+
event.props.metadata = Object.keys(rest).length > 0 ? rest : void 0;
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
addToParentIndex(event) {
|
|
2636
|
+
var _a;
|
|
2637
|
+
const parentId = (_a = event.props) == null ? void 0 : _a.parentEventId;
|
|
2638
|
+
if (parentId === void 0) return;
|
|
2639
|
+
this.parentEventOf.set(event.id, parentId);
|
|
2640
|
+
let children = this.childrenOf.get(parentId);
|
|
2641
|
+
if (!children) {
|
|
2642
|
+
children = /* @__PURE__ */ new Set();
|
|
2643
|
+
this.childrenOf.set(parentId, children);
|
|
2644
|
+
}
|
|
2645
|
+
children.add(event.id);
|
|
2646
|
+
this.parentSpanDirty.add(parentId);
|
|
2647
|
+
}
|
|
2648
|
+
removeFromParentIndex(eventId) {
|
|
2649
|
+
const parentId = this.parentEventOf.get(eventId);
|
|
2650
|
+
if (parentId === void 0) return;
|
|
2651
|
+
this.parentEventOf.delete(eventId);
|
|
2652
|
+
const children = this.childrenOf.get(parentId);
|
|
2653
|
+
if (children) {
|
|
2654
|
+
children.delete(eventId);
|
|
2655
|
+
if (children.size === 0) this.childrenOf.delete(parentId);
|
|
2656
|
+
}
|
|
2657
|
+
this.parentSpanDirty.add(parentId);
|
|
2658
|
+
}
|
|
2659
|
+
/**
|
|
2660
|
+
* Recompute the derived span of any dirty parent event living on `rowId`
|
|
2661
|
+
* (earliest child start → latest child end), write it back into the parent
|
|
2662
|
+
* event, and re-sort the row so the sorted-array invariant holds. Cheap no-op
|
|
2663
|
+
* when nothing is dirty (the common no-groups case never touches this).
|
|
2664
|
+
*/
|
|
2665
|
+
flushParentSpans(rowId) {
|
|
2666
|
+
var _a;
|
|
2667
|
+
if (this.parentSpanDirty.size === 0) return;
|
|
2668
|
+
const index = this.rowIndexes.get(rowId);
|
|
2669
|
+
if (!index) return;
|
|
2670
|
+
let changed = false;
|
|
2671
|
+
for (const event of index.events) {
|
|
2672
|
+
if (!((_a = event.props) == null ? void 0 : _a.isGroupParent)) continue;
|
|
2673
|
+
if (!this.parentSpanDirty.has(event.id)) continue;
|
|
2674
|
+
this.parentSpanDirty.delete(event.id);
|
|
2675
|
+
const children = this.childrenOf.get(event.id);
|
|
2676
|
+
if (!children || children.size === 0) continue;
|
|
2677
|
+
let minStart = Infinity;
|
|
2678
|
+
let maxEnd = -Infinity;
|
|
2679
|
+
for (const childId of children) {
|
|
2680
|
+
const child = this.getEvent(childId);
|
|
2681
|
+
if (!child) continue;
|
|
2682
|
+
if (child.startTime < minStart) minStart = child.startTime;
|
|
2683
|
+
if (child.endTime > maxEnd) maxEnd = child.endTime;
|
|
2684
|
+
}
|
|
2685
|
+
if (minStart !== Infinity && (event.startTime !== minStart || event.endTime !== maxEnd)) {
|
|
2686
|
+
event.startTime = minStart;
|
|
2687
|
+
event.endTime = maxEnd;
|
|
2688
|
+
changed = true;
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
if (changed) {
|
|
2692
|
+
index.events.sort(sort_events_default);
|
|
2693
|
+
index.lanesDirty = true;
|
|
2694
|
+
}
|
|
1857
2695
|
}
|
|
1858
2696
|
bump() {
|
|
1859
2697
|
this.version++;
|
|
@@ -1871,6 +2709,10 @@ var Timeline = forwardRef3(
|
|
|
1871
2709
|
onResize,
|
|
1872
2710
|
onEventClick,
|
|
1873
2711
|
onEventHover,
|
|
2712
|
+
selectable = false,
|
|
2713
|
+
defaultSelectedEventIds,
|
|
2714
|
+
onSelectionChange,
|
|
2715
|
+
defaultCollapsedRowIds,
|
|
1874
2716
|
startDate,
|
|
1875
2717
|
endDate,
|
|
1876
2718
|
theme,
|
|
@@ -1881,6 +2723,7 @@ var Timeline = forwardRef3(
|
|
|
1881
2723
|
eventPromptTemplate,
|
|
1882
2724
|
showEventPrompt = true,
|
|
1883
2725
|
panZoom,
|
|
2726
|
+
timeBar,
|
|
1884
2727
|
animations = true
|
|
1885
2728
|
}, handleRef) => {
|
|
1886
2729
|
const [windowTime, setWindowTime] = useState4([
|
|
@@ -1914,15 +2757,53 @@ var Timeline = forwardRef3(
|
|
|
1914
2757
|
sceneRef.current = new SceneStore();
|
|
1915
2758
|
}
|
|
1916
2759
|
const scene = sceneRef.current;
|
|
2760
|
+
const selectionRef = useRef7(
|
|
2761
|
+
new Set(defaultSelectedEventIds != null ? defaultSelectedEventIds : [])
|
|
2762
|
+
);
|
|
2763
|
+
const onSelectionChangeRef = useRef7(onSelectionChange);
|
|
2764
|
+
onSelectionChangeRef.current = onSelectionChange;
|
|
2765
|
+
const applySelection = useCallback3(
|
|
2766
|
+
(ids) => {
|
|
2767
|
+
var _a, _b;
|
|
2768
|
+
const expanded = [];
|
|
2769
|
+
for (const id of ids) {
|
|
2770
|
+
expanded.push(id);
|
|
2771
|
+
for (const childId of scene.getChildEventIds(id)) {
|
|
2772
|
+
expanded.push(childId);
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
selectionRef.current = new Set(
|
|
2776
|
+
expanded.filter((id) => scene.isEventSelectable(id))
|
|
2777
|
+
);
|
|
2778
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({
|
|
2779
|
+
selectedEventIds: selectionRef.current
|
|
2780
|
+
});
|
|
2781
|
+
(_b = onSelectionChangeRef.current) == null ? void 0 : _b.call(onSelectionChangeRef, [...selectionRef.current]);
|
|
2782
|
+
},
|
|
2783
|
+
[scene]
|
|
2784
|
+
);
|
|
2785
|
+
const getSelection = useCallback3(() => [...selectionRef.current], []);
|
|
1917
2786
|
useEffect6(() => {
|
|
2787
|
+
var _a;
|
|
1918
2788
|
scene.setRows(rows);
|
|
2789
|
+
(_a = rendererRef.current) == null ? void 0 : _a.animator.reset();
|
|
1919
2790
|
}, [scene, rows]);
|
|
1920
2791
|
useEffect6(() => {
|
|
2792
|
+
var _a;
|
|
1921
2793
|
scene.setEvents([...events].sort(sort_events_default));
|
|
2794
|
+
(_a = rendererRef.current) == null ? void 0 : _a.animator.reset();
|
|
1922
2795
|
}, [scene, events]);
|
|
1923
2796
|
useEffect6(() => {
|
|
1924
2797
|
scene.setStaticEvents(staticEvents ? [...staticEvents] : []);
|
|
1925
2798
|
}, [scene, staticEvents]);
|
|
2799
|
+
const seededCollapseRef = useRef7(false);
|
|
2800
|
+
useEffect6(() => {
|
|
2801
|
+
if (seededCollapseRef.current) return;
|
|
2802
|
+
seededCollapseRef.current = true;
|
|
2803
|
+
for (const id of defaultCollapsedRowIds != null ? defaultCollapsedRowIds : []) {
|
|
2804
|
+
scene.setCollapsed(id, true);
|
|
2805
|
+
}
|
|
2806
|
+
}, [scene, defaultCollapsedRowIds]);
|
|
1926
2807
|
const windowTimeRef = useRef7(windowTime);
|
|
1927
2808
|
windowTimeRef.current = windowTime;
|
|
1928
2809
|
useImperativeHandle2(
|
|
@@ -1946,12 +2827,16 @@ var Timeline = forwardRef3(
|
|
|
1946
2827
|
startTime: windowTimeRef.current[0],
|
|
1947
2828
|
endTime: windowTimeRef.current[1]
|
|
1948
2829
|
}),
|
|
2830
|
+
setSelection: (ids) => applySelection(ids),
|
|
2831
|
+
getSelection,
|
|
2832
|
+
toggleRow: (rowId) => scene.toggleCollapsed(rowId),
|
|
2833
|
+
setCollapsed: (rowId, collapsed) => scene.setCollapsed(rowId, collapsed),
|
|
1949
2834
|
redraw: () => {
|
|
1950
2835
|
var _a;
|
|
1951
2836
|
return (_a = rendererRef.current) == null ? void 0 : _a.invalidate("all");
|
|
1952
2837
|
}
|
|
1953
2838
|
}),
|
|
1954
|
-
[scene]
|
|
2839
|
+
[scene, applySelection, getSelection]
|
|
1955
2840
|
);
|
|
1956
2841
|
useEffect6(() => {
|
|
1957
2842
|
if (contentRef.current) {
|
|
@@ -1973,8 +2858,15 @@ var Timeline = forwardRef3(
|
|
|
1973
2858
|
}
|
|
1974
2859
|
}, []);
|
|
1975
2860
|
use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTime });
|
|
1976
|
-
const resolvedTheme =
|
|
1977
|
-
const
|
|
2861
|
+
const resolvedTheme = useMemo3(() => resolveTheme(theme), [theme]);
|
|
2862
|
+
const geometry = useMemo3(
|
|
2863
|
+
() => geometryFromTheme(resolvedTheme),
|
|
2864
|
+
[resolvedTheme]
|
|
2865
|
+
);
|
|
2866
|
+
useEffect6(() => {
|
|
2867
|
+
scene.setGeometry(geometry);
|
|
2868
|
+
}, [scene, geometry]);
|
|
2869
|
+
const resolvedAnimations = useMemo3(() => {
|
|
1978
2870
|
var _a, _b;
|
|
1979
2871
|
if (animations === false) return { layoutMs: 0, fadeMs: 0 };
|
|
1980
2872
|
if (animations === true) {
|
|
@@ -1988,7 +2880,7 @@ var Timeline = forwardRef3(
|
|
|
1988
2880
|
fadeMs: (_b = animations.fadeMs) != null ? _b : DEFAULT_FADE_DURATION_MS
|
|
1989
2881
|
};
|
|
1990
2882
|
}, [animations]);
|
|
1991
|
-
const eventPrompt =
|
|
2883
|
+
const eventPrompt = useMemo3(
|
|
1992
2884
|
() => /* @__PURE__ */ React6.createElement(
|
|
1993
2885
|
event_prompt_default,
|
|
1994
2886
|
{
|
|
@@ -2005,7 +2897,8 @@ var Timeline = forwardRef3(
|
|
|
2005
2897
|
tick,
|
|
2006
2898
|
contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
|
|
2007
2899
|
scrollWidth,
|
|
2008
|
-
theme: resolvedTheme
|
|
2900
|
+
theme: resolvedTheme,
|
|
2901
|
+
timeBar
|
|
2009
2902
|
}
|
|
2010
2903
|
), /* @__PURE__ */ React6.createElement("div", { className: "body-wrapper", ref: bodyRef }, /* @__PURE__ */ React6.createElement(
|
|
2011
2904
|
canvas_board_default,
|
|
@@ -2023,6 +2916,7 @@ var Timeline = forwardRef3(
|
|
|
2023
2916
|
rowsHeaderClassName: additionalClassNames == null ? void 0 : additionalClassNames.rowsHeader,
|
|
2024
2917
|
setWindowTime,
|
|
2025
2918
|
setCellWidth,
|
|
2919
|
+
setTick,
|
|
2026
2920
|
onDrop,
|
|
2027
2921
|
onResize,
|
|
2028
2922
|
onEventClick,
|
|
@@ -2030,6 +2924,9 @@ var Timeline = forwardRef3(
|
|
|
2030
2924
|
eventsResize,
|
|
2031
2925
|
panZoom,
|
|
2032
2926
|
animations: resolvedAnimations,
|
|
2927
|
+
selectable,
|
|
2928
|
+
applySelection,
|
|
2929
|
+
getSelection,
|
|
2033
2930
|
ref: contentRef
|
|
2034
2931
|
}
|
|
2035
2932
|
), showEventPrompt && eventPrompt));
|