awesome-timeline-react 0.10.0 → 0.12.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 +7 -1
- package/dist/_tsup-dts-rollup.d.mts +123 -18
- package/dist/_tsup-dts-rollup.d.ts +123 -18
- package/dist/index.css +22 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +330 -100
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +331 -102
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -19,12 +19,12 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
|
|
21
21
|
// src/timeline.tsx
|
|
22
|
-
import
|
|
23
|
-
forwardRef as
|
|
22
|
+
import React7, {
|
|
23
|
+
forwardRef as forwardRef4,
|
|
24
24
|
useCallback as useCallback3,
|
|
25
25
|
useEffect as useEffect6,
|
|
26
|
-
useImperativeHandle as
|
|
27
|
-
useMemo as
|
|
26
|
+
useImperativeHandle as useImperativeHandle3,
|
|
27
|
+
useMemo as useMemo2,
|
|
28
28
|
useRef as useRef7,
|
|
29
29
|
useState as useState4
|
|
30
30
|
} from "react";
|
|
@@ -103,35 +103,41 @@ var LayoutAnimator = class {
|
|
|
103
103
|
};
|
|
104
104
|
|
|
105
105
|
// src/hooks/use-resize-observer.ts
|
|
106
|
-
import { useEffect
|
|
106
|
+
import { useEffect } from "react";
|
|
107
|
+
var createWidthObserver = (getWindow, onScale) => {
|
|
108
|
+
let prevWidth = 0;
|
|
109
|
+
return new ResizeObserver((entries) => {
|
|
110
|
+
var _a;
|
|
111
|
+
for (const entry of entries) {
|
|
112
|
+
const width = (_a = entry.borderBoxSize) == null ? void 0 : _a[0].inlineSize;
|
|
113
|
+
if (typeof width === "number" && width !== prevWidth) {
|
|
114
|
+
prevWidth = width;
|
|
115
|
+
const [start, end] = getWindow();
|
|
116
|
+
const windowDuration = end - start;
|
|
117
|
+
onScale(
|
|
118
|
+
windowDuration / entry.contentRect.width,
|
|
119
|
+
entry.contentRect.width / (windowDuration / 3600)
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
};
|
|
107
125
|
var useResizeObserver = ({
|
|
108
|
-
|
|
126
|
+
windowTimeRef,
|
|
109
127
|
setTick,
|
|
110
128
|
setCellWidth,
|
|
111
129
|
contentRef
|
|
112
130
|
}) => {
|
|
113
|
-
const prevWidthRef = useRef(0);
|
|
114
|
-
const resizeObserver = useMemo(() => {
|
|
115
|
-
return new ResizeObserver((entries) => {
|
|
116
|
-
var _a;
|
|
117
|
-
for (const entry of entries) {
|
|
118
|
-
const width = (_a = entry.borderBoxSize) == null ? void 0 : _a[0].inlineSize;
|
|
119
|
-
if (typeof width === "number" && width !== prevWidthRef.current) {
|
|
120
|
-
prevWidthRef.current = width;
|
|
121
|
-
const windowDuration = windowTime[1] - windowTime[0];
|
|
122
|
-
const numberOfHourBlocks = windowDuration / 3600;
|
|
123
|
-
setTick(windowDuration / entry.contentRect.width);
|
|
124
|
-
setCellWidth(entry.contentRect.width / numberOfHourBlocks);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}, [windowTime]);
|
|
129
131
|
useEffect(() => {
|
|
132
|
+
const observer = createWidthObserver(() => windowTimeRef.current, (tick, cellWidth) => {
|
|
133
|
+
setTick(tick);
|
|
134
|
+
setCellWidth(cellWidth);
|
|
135
|
+
});
|
|
130
136
|
if (contentRef.current) {
|
|
131
|
-
|
|
137
|
+
observer.observe(contentRef.current, { box: "border-box" });
|
|
132
138
|
}
|
|
133
|
-
return () =>
|
|
134
|
-
}, [
|
|
139
|
+
return () => observer.disconnect();
|
|
140
|
+
}, [windowTimeRef, setTick, setCellWidth, contentRef]);
|
|
135
141
|
};
|
|
136
142
|
var use_resize_observer_default = useResizeObserver;
|
|
137
143
|
|
|
@@ -151,14 +157,14 @@ var sortEvents = (eventA, eventB) => {
|
|
|
151
157
|
var sort_events_default = sortEvents;
|
|
152
158
|
|
|
153
159
|
// src/components/rt-indicator.tsx
|
|
154
|
-
import React, { useEffect as useEffect2, useRef
|
|
160
|
+
import React, { useEffect as useEffect2, useRef, useState } from "react";
|
|
155
161
|
var RTIndicator = ({
|
|
156
162
|
tick,
|
|
157
163
|
windowTime
|
|
158
164
|
}) => {
|
|
159
165
|
const [currentTime, setCurrentTime] = useState((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
160
166
|
const [leftOffset, setLeftOffset] = useState(0);
|
|
161
|
-
const intervalIdRef =
|
|
167
|
+
const intervalIdRef = useRef(null);
|
|
162
168
|
useEffect2(() => {
|
|
163
169
|
if (tick) {
|
|
164
170
|
const leftOffsetTime = currentTime - windowTime[0];
|
|
@@ -180,15 +186,15 @@ var rt_indicator_default = RTIndicator;
|
|
|
180
186
|
import React2, {
|
|
181
187
|
forwardRef,
|
|
182
188
|
useImperativeHandle,
|
|
183
|
-
useRef as
|
|
189
|
+
useRef as useRef2,
|
|
184
190
|
useState as useState2
|
|
185
191
|
} from "react";
|
|
186
192
|
import { computePosition, flip, offset, shift } from "@floating-ui/dom";
|
|
187
193
|
var EventPrompt = forwardRef(
|
|
188
194
|
({ template }, ref) => {
|
|
189
|
-
const promptRef =
|
|
195
|
+
const promptRef = useRef2(null);
|
|
190
196
|
const [hoveredEvent, setHoveredEvent] = useState2();
|
|
191
|
-
const showSeqRef =
|
|
197
|
+
const showSeqRef = useRef2(0);
|
|
192
198
|
useImperativeHandle(ref, () => {
|
|
193
199
|
return {
|
|
194
200
|
show(event, anchorRect) {
|
|
@@ -238,7 +244,7 @@ var EventPrompt = forwardRef(
|
|
|
238
244
|
var event_prompt_default = EventPrompt;
|
|
239
245
|
|
|
240
246
|
// src/components/canvas-time-bar.tsx
|
|
241
|
-
import React3, { useEffect as useEffect3, useRef as
|
|
247
|
+
import React3, { useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
242
248
|
|
|
243
249
|
// src/helpers/get-month-name.ts
|
|
244
250
|
var getMonthName = (monthIndex) => {
|
|
@@ -301,6 +307,15 @@ var hourLabel = (hour) => `${pad2(hour)}:00`;
|
|
|
301
307
|
var dayLabel = (date) => `${get_week_day_name_default(date.getDay())} ${date.getDate()} ${get_month_name_default(
|
|
302
308
|
date.getMonth()
|
|
303
309
|
)}`;
|
|
310
|
+
var isoWeek = (date) => {
|
|
311
|
+
const thursday = new Date(
|
|
312
|
+
date.getFullYear(),
|
|
313
|
+
date.getMonth(),
|
|
314
|
+
date.getDate() + 3 - (date.getDay() + 6) % 7
|
|
315
|
+
);
|
|
316
|
+
const jan1 = new Date(thursday.getFullYear(), 0, 1);
|
|
317
|
+
return 1 + Math.floor(Math.round((thursday.getTime() - jan1.getTime()) / 864e5) / 7);
|
|
318
|
+
};
|
|
304
319
|
var defaultFormat = (unit) => {
|
|
305
320
|
if (typeof unit === "object") {
|
|
306
321
|
return (d) => `${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
|
|
@@ -310,6 +325,8 @@ var defaultFormat = (unit) => {
|
|
|
310
325
|
return (d) => hourLabel(d.getHours());
|
|
311
326
|
case "month":
|
|
312
327
|
return (d) => `${get_month_name_default(d.getMonth())} ${d.getFullYear()}`;
|
|
328
|
+
case "year":
|
|
329
|
+
return (d) => `${d.getFullYear()}`;
|
|
313
330
|
case "day":
|
|
314
331
|
case "week":
|
|
315
332
|
default:
|
|
@@ -336,6 +353,8 @@ var floorToUnit = (date, unit, anchorSec) => {
|
|
|
336
353
|
}
|
|
337
354
|
case "month":
|
|
338
355
|
return new Date(y, mo, 1);
|
|
356
|
+
case "year":
|
|
357
|
+
return new Date(y, 0, 1);
|
|
339
358
|
}
|
|
340
359
|
};
|
|
341
360
|
var nextBoundary = (blockStart, unit) => {
|
|
@@ -354,8 +373,36 @@ var nextBoundary = (blockStart, unit) => {
|
|
|
354
373
|
return new Date(y, mo, d + 7);
|
|
355
374
|
case "month":
|
|
356
375
|
return new Date(y, mo + 1, 1);
|
|
376
|
+
case "year":
|
|
377
|
+
return new Date(y + 1, 0, 1);
|
|
357
378
|
}
|
|
358
379
|
};
|
|
380
|
+
var blockSpans = (unit, windowStart, windowEnd, limit = 1e5) => {
|
|
381
|
+
const spans = [];
|
|
382
|
+
if (typeof unit === "object" && "boundaries" in unit) {
|
|
383
|
+
const edges = unit.boundaries(windowStart, windowEnd);
|
|
384
|
+
for (let i = 0; i + 1 < edges.length; i++) {
|
|
385
|
+
const [start, end] = [edges[i], edges[i + 1]];
|
|
386
|
+
if (end <= windowStart || start >= windowEnd || end <= start) continue;
|
|
387
|
+
if (spans.length >= limit) return null;
|
|
388
|
+
spans.push([start, end]);
|
|
389
|
+
}
|
|
390
|
+
return spans;
|
|
391
|
+
}
|
|
392
|
+
const day = new Date(windowStart * 1e3);
|
|
393
|
+
const anchorSec = new Date(day.getFullYear(), day.getMonth(), day.getDate()).getTime() / 1e3;
|
|
394
|
+
let cursorSec = windowStart;
|
|
395
|
+
while (cursorSec < windowEnd) {
|
|
396
|
+
const blockStart = floorToUnit(new Date(cursorSec * 1e3), unit, anchorSec);
|
|
397
|
+
const startSec = blockStart.getTime() / 1e3;
|
|
398
|
+
const endSec = nextBoundary(blockStart, unit).getTime() / 1e3;
|
|
399
|
+
if (endSec <= startSec) break;
|
|
400
|
+
if (spans.length >= limit) return null;
|
|
401
|
+
spans.push([startSec, endSec]);
|
|
402
|
+
cursorSec = endSec;
|
|
403
|
+
}
|
|
404
|
+
return spans;
|
|
405
|
+
};
|
|
359
406
|
var generateUnitBlocks = ({
|
|
360
407
|
unit,
|
|
361
408
|
format,
|
|
@@ -363,33 +410,55 @@ var generateUnitBlocks = ({
|
|
|
363
410
|
windowEnd,
|
|
364
411
|
tick
|
|
365
412
|
}) => {
|
|
366
|
-
|
|
413
|
+
var _a;
|
|
414
|
+
if (tick === null || tick <= 0 || windowEnd <= windowStart) return [];
|
|
367
415
|
const resolvedUnit = unit != null ? unit : "hour";
|
|
368
|
-
if (tick === null || tick <= 0 || windowEnd <= windowStart) return blocks;
|
|
369
416
|
const label = format != null ? format : defaultFormat(resolvedUnit);
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
417
|
+
return ((_a = blockSpans(resolvedUnit, windowStart, windowEnd)) != null ? _a : []).map(
|
|
418
|
+
([startSec, endSec]) => {
|
|
419
|
+
const visibleStart = Math.max(startSec, windowStart);
|
|
420
|
+
const visibleEnd = Math.min(endSec, windowEnd);
|
|
421
|
+
return {
|
|
422
|
+
label: label(new Date(startSec * 1e3), new Date(endSec * 1e3)),
|
|
423
|
+
x: (visibleStart - windowStart) / tick,
|
|
424
|
+
width: (visibleEnd - visibleStart) / tick
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
);
|
|
428
|
+
};
|
|
429
|
+
var shortDay = (d) => `${get_week_day_name_default(d.getDay())} ${d.getDate()}`;
|
|
430
|
+
var DEFAULT_TIME_BAR_LEVELS = [
|
|
431
|
+
{ topRow: { unit: "day" }, bottomRow: { unit: "hour" } },
|
|
432
|
+
{ topRow: { unit: "day" }, bottomRow: { unit: { stepSeconds: 6 * 3600 } } },
|
|
433
|
+
{
|
|
434
|
+
topRow: {
|
|
435
|
+
unit: "week",
|
|
436
|
+
format: (d) => `W${isoWeek(d)} \xB7 ${d.getDate()} ${get_month_name_default(d.getMonth())}`
|
|
437
|
+
},
|
|
438
|
+
bottomRow: { unit: "day", format: shortDay }
|
|
439
|
+
},
|
|
440
|
+
{ topRow: { unit: "month" }, bottomRow: { unit: "week", format: (d) => `W${isoWeek(d)}` } },
|
|
441
|
+
{ topRow: { unit: "year" }, bottomRow: { unit: "month", format: (d) => get_month_name_default(d.getMonth()) } }
|
|
442
|
+
];
|
|
443
|
+
var DEFAULT_MIN_BLOCK_WIDTH = 40;
|
|
444
|
+
var resolveTimeBar = (timeBar, windowStart, windowEnd, tick) => {
|
|
445
|
+
var _a, _b, _c;
|
|
446
|
+
if (!(timeBar == null ? void 0 : timeBar.auto)) {
|
|
447
|
+
return {
|
|
448
|
+
topRow: (_a = timeBar == null ? void 0 : timeBar.topRow) != null ? _a : { unit: "day" },
|
|
449
|
+
bottomRow: (_b = timeBar == null ? void 0 : timeBar.bottomRow) != null ? _b : { unit: "hour" }
|
|
450
|
+
};
|
|
391
451
|
}
|
|
392
|
-
|
|
452
|
+
const { levels = DEFAULT_TIME_BAR_LEVELS, minBlockWidth = DEFAULT_MIN_BLOCK_WIDTH } = timeBar.auto === true ? {} : timeBar.auto;
|
|
453
|
+
const levelsOrDefault = levels.length > 0 ? levels : DEFAULT_TIME_BAR_LEVELS;
|
|
454
|
+
if (tick === null || tick <= 0 || windowEnd <= windowStart) return levelsOrDefault[0];
|
|
455
|
+
const minSecs = minBlockWidth * tick;
|
|
456
|
+
const limit = Math.ceil((windowEnd - windowStart) / minSecs) + 2;
|
|
457
|
+
return (_c = levelsOrDefault.find((level) => {
|
|
458
|
+
var _a2;
|
|
459
|
+
const spans = blockSpans((_a2 = level.bottomRow.unit) != null ? _a2 : "hour", windowStart, windowEnd, limit);
|
|
460
|
+
return spans !== null && spans.every(([start, end]) => end - start >= minSecs);
|
|
461
|
+
})) != null ? _c : levelsOrDefault[levelsOrDefault.length - 1];
|
|
393
462
|
};
|
|
394
463
|
|
|
395
464
|
// src/canvas/dpr.ts
|
|
@@ -449,7 +518,9 @@ var DEFAULT_THEME = {
|
|
|
449
518
|
barRadius: 5,
|
|
450
519
|
minHitWidth: 0,
|
|
451
520
|
groupChildBackground: "rgba(0,0,0,0.05)",
|
|
452
|
-
groupShadowColor: "rgba(0,0,0,0.22)"
|
|
521
|
+
groupShadowColor: "rgba(0,0,0,0.22)",
|
|
522
|
+
pointerLineColor: "rgba(15,23,42,0.7)",
|
|
523
|
+
pointerLabelColor: "#ffffff"
|
|
453
524
|
};
|
|
454
525
|
var resolveTheme = (theme) => __spreadValues(__spreadValues({}, DEFAULT_THEME), theme);
|
|
455
526
|
|
|
@@ -477,6 +548,24 @@ var drawGridLines = (ctx, {
|
|
|
477
548
|
}
|
|
478
549
|
ctx.stroke();
|
|
479
550
|
};
|
|
551
|
+
var drawBlockGridLines = (ctx, {
|
|
552
|
+
width,
|
|
553
|
+
height,
|
|
554
|
+
blocks,
|
|
555
|
+
color = DEFAULT_THEME.gridColor
|
|
556
|
+
}) => {
|
|
557
|
+
ctx.strokeStyle = color;
|
|
558
|
+
ctx.lineWidth = 1;
|
|
559
|
+
ctx.beginPath();
|
|
560
|
+
for (let i = 0; i < blocks.length - 1; i++) {
|
|
561
|
+
const x = blocks[i].x + blocks[i].width;
|
|
562
|
+
if (x < 1 || width - x < 1) continue;
|
|
563
|
+
const crisp = Math.round(x) - 0.5;
|
|
564
|
+
ctx.moveTo(crisp, 0);
|
|
565
|
+
ctx.lineTo(crisp, height);
|
|
566
|
+
}
|
|
567
|
+
ctx.stroke();
|
|
568
|
+
};
|
|
480
569
|
var drawTimeBar = (ctx, {
|
|
481
570
|
width,
|
|
482
571
|
height,
|
|
@@ -529,7 +618,8 @@ var drawTimeBar = (ctx, {
|
|
|
529
618
|
};
|
|
530
619
|
|
|
531
620
|
// src/components/canvas-time-bar.tsx
|
|
532
|
-
var
|
|
621
|
+
var TIME_BAR_HEIGHT = 50;
|
|
622
|
+
var TIME_BAR_INNER_HEIGHT = TIME_BAR_HEIGHT - 2;
|
|
533
623
|
var CanvasTimeBar = ({
|
|
534
624
|
windowTime,
|
|
535
625
|
tick,
|
|
@@ -538,11 +628,9 @@ var CanvasTimeBar = ({
|
|
|
538
628
|
theme,
|
|
539
629
|
timeBar
|
|
540
630
|
}) => {
|
|
541
|
-
var _a
|
|
542
|
-
const canvasRef =
|
|
631
|
+
var _a;
|
|
632
|
+
const canvasRef = useRef3(null);
|
|
543
633
|
const header = theme != null ? theme : DEFAULT_THEME;
|
|
544
|
-
const topRow = (_a = timeBar == null ? void 0 : timeBar.topRow) != null ? _a : { unit: "day" };
|
|
545
|
-
const bottomRow = (_b = timeBar == null ? void 0 : timeBar.bottomRow) != null ? _b : { unit: "hour" };
|
|
546
634
|
useEffect3(() => {
|
|
547
635
|
var _a2;
|
|
548
636
|
const canvas = canvasRef.current;
|
|
@@ -555,6 +643,7 @@ var CanvasTimeBar = ({
|
|
|
555
643
|
);
|
|
556
644
|
if (!ctx) return;
|
|
557
645
|
const [windowStart, windowEnd] = windowTime;
|
|
646
|
+
const { topRow, bottomRow } = resolveTimeBar(timeBar, windowStart, windowEnd, tick);
|
|
558
647
|
drawTimeBar(ctx, {
|
|
559
648
|
width: contentWidth,
|
|
560
649
|
height: TIME_BAR_INNER_HEIGHT,
|
|
@@ -591,7 +680,7 @@ var CanvasTimeBar = ({
|
|
|
591
680
|
width: scrollWidth,
|
|
592
681
|
height: "100%",
|
|
593
682
|
boxSizing: "border-box",
|
|
594
|
-
borderLeft: `1px solid ${(
|
|
683
|
+
borderLeft: `1px solid ${(_a = header.headerBorderColor) != null ? _a : "yellow"}`
|
|
595
684
|
}
|
|
596
685
|
}
|
|
597
686
|
) : null
|
|
@@ -605,7 +694,7 @@ import React5, {
|
|
|
605
694
|
useCallback as useCallback2,
|
|
606
695
|
useEffect as useEffect5,
|
|
607
696
|
useLayoutEffect,
|
|
608
|
-
useRef as
|
|
697
|
+
useRef as useRef5,
|
|
609
698
|
useState as useState3,
|
|
610
699
|
useSyncExternalStore
|
|
611
700
|
} from "react";
|
|
@@ -1174,6 +1263,28 @@ var TimelineRenderer = class {
|
|
|
1174
1263
|
this.font = getComputedStyle(this.dynamicCanvas).font || this.font;
|
|
1175
1264
|
}
|
|
1176
1265
|
}
|
|
1266
|
+
drawGrid(ctx, tick) {
|
|
1267
|
+
const { width, height, windowTime, timeBar, theme } = this.view;
|
|
1268
|
+
if (timeBar == null ? void 0 : timeBar.auto) {
|
|
1269
|
+
const [windowStart, windowEnd] = windowTime;
|
|
1270
|
+
const { bottomRow } = resolveTimeBar(timeBar, windowStart, windowEnd, tick);
|
|
1271
|
+
drawBlockGridLines(ctx, {
|
|
1272
|
+
width,
|
|
1273
|
+
height,
|
|
1274
|
+
blocks: generateUnitBlocks(__spreadProps(__spreadValues({}, bottomRow), { windowStart, windowEnd, tick })),
|
|
1275
|
+
color: theme.gridColor
|
|
1276
|
+
});
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
drawGridLines(ctx, {
|
|
1280
|
+
width,
|
|
1281
|
+
height,
|
|
1282
|
+
cellWidth: this.view.cellWidth,
|
|
1283
|
+
windowStart: windowTime[0],
|
|
1284
|
+
tick,
|
|
1285
|
+
color: theme.gridColor
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1177
1288
|
drawFrame(dirty) {
|
|
1178
1289
|
if (this.view.tick === null) return;
|
|
1179
1290
|
this.animator.beginFrame(performance.now());
|
|
@@ -1182,14 +1293,7 @@ var TimelineRenderer = class {
|
|
|
1182
1293
|
if (ctx) {
|
|
1183
1294
|
ctx.clearRect(0, 0, this.view.width, this.view.height);
|
|
1184
1295
|
drawGroupShading(ctx, this.view, this.scene);
|
|
1185
|
-
|
|
1186
|
-
width: this.view.width,
|
|
1187
|
-
height: this.view.height,
|
|
1188
|
-
cellWidth: this.view.cellWidth,
|
|
1189
|
-
windowStart: this.view.windowTime[0],
|
|
1190
|
-
tick: this.view.tick,
|
|
1191
|
-
color: this.view.theme.gridColor
|
|
1192
|
-
});
|
|
1296
|
+
this.drawGrid(ctx, this.view.tick);
|
|
1193
1297
|
drawRowDividers(ctx, this.view, this.scene);
|
|
1194
1298
|
}
|
|
1195
1299
|
}
|
|
@@ -1207,7 +1311,7 @@ var TimelineRenderer = class {
|
|
|
1207
1311
|
};
|
|
1208
1312
|
|
|
1209
1313
|
// src/hooks/use-canvas-interactions.ts
|
|
1210
|
-
import { useCallback, useEffect as useEffect4, useMemo
|
|
1314
|
+
import { useCallback, useEffect as useEffect4, useMemo, useRef as useRef4 } from "react";
|
|
1211
1315
|
|
|
1212
1316
|
// src/core/types.ts
|
|
1213
1317
|
var rectContains = (rect, x, y) => x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
|
|
@@ -1302,15 +1406,15 @@ var useCanvasInteractions = ({
|
|
|
1302
1406
|
applySelection,
|
|
1303
1407
|
getSelection
|
|
1304
1408
|
}) => {
|
|
1305
|
-
const stateRef =
|
|
1306
|
-
const changeGridRef =
|
|
1307
|
-
const panFrameRef =
|
|
1308
|
-
const panPendingDxRef =
|
|
1309
|
-
const hoveredRef =
|
|
1310
|
-
const pointersRef =
|
|
1311
|
-
const zoomFrameRef =
|
|
1312
|
-
const zoomPendingRef =
|
|
1313
|
-
const config =
|
|
1409
|
+
const stateRef = useRef4({ mode: "idle" });
|
|
1410
|
+
const changeGridRef = useRef4(false);
|
|
1411
|
+
const panFrameRef = useRef4(null);
|
|
1412
|
+
const panPendingDxRef = useRef4(0);
|
|
1413
|
+
const hoveredRef = useRef4(null);
|
|
1414
|
+
const pointersRef = useRef4(/* @__PURE__ */ new Map());
|
|
1415
|
+
const zoomFrameRef = useRef4(null);
|
|
1416
|
+
const zoomPendingRef = useRef4(null);
|
|
1417
|
+
const config = useMemo(
|
|
1314
1418
|
() => {
|
|
1315
1419
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1316
1420
|
return {
|
|
@@ -1325,7 +1429,7 @@ var useCanvasInteractions = ({
|
|
|
1325
1429
|
},
|
|
1326
1430
|
[panZoom]
|
|
1327
1431
|
);
|
|
1328
|
-
const limits =
|
|
1432
|
+
const limits = useMemo(
|
|
1329
1433
|
() => {
|
|
1330
1434
|
var _a, _b;
|
|
1331
1435
|
return {
|
|
@@ -1998,6 +2102,7 @@ var CanvasBoard = forwardRef2(
|
|
|
1998
2102
|
onEventHover,
|
|
1999
2103
|
eventsResize,
|
|
2000
2104
|
stripeOverlap,
|
|
2105
|
+
timeBar,
|
|
2001
2106
|
panZoom,
|
|
2002
2107
|
animations,
|
|
2003
2108
|
selectable,
|
|
@@ -2005,12 +2110,12 @@ var CanvasBoard = forwardRef2(
|
|
|
2005
2110
|
getSelection
|
|
2006
2111
|
}, contentRef) => {
|
|
2007
2112
|
var _a;
|
|
2008
|
-
const staticCanvasRef =
|
|
2009
|
-
const dynamicCanvasRef =
|
|
2010
|
-
const ghostRef =
|
|
2011
|
-
const headerWrapperRef =
|
|
2012
|
-
const measureLayerRef =
|
|
2013
|
-
const totalHeightRef =
|
|
2113
|
+
const staticCanvasRef = useRef5(null);
|
|
2114
|
+
const dynamicCanvasRef = useRef5(null);
|
|
2115
|
+
const ghostRef = useRef5(null);
|
|
2116
|
+
const headerWrapperRef = useRef5(null);
|
|
2117
|
+
const measureLayerRef = useRef5(null);
|
|
2118
|
+
const totalHeightRef = useRef5(0);
|
|
2014
2119
|
const [scrollTop, setScrollTop] = useState3(0);
|
|
2015
2120
|
const [viewportHeight, setViewportHeight] = useState3(0);
|
|
2016
2121
|
useEffect5(() => {
|
|
@@ -2039,7 +2144,8 @@ var CanvasBoard = forwardRef2(
|
|
|
2039
2144
|
theme,
|
|
2040
2145
|
drawEvent,
|
|
2041
2146
|
eventsResize,
|
|
2042
|
-
stripeOverlap
|
|
2147
|
+
stripeOverlap,
|
|
2148
|
+
timeBar
|
|
2043
2149
|
});
|
|
2044
2150
|
}, [
|
|
2045
2151
|
windowTime,
|
|
@@ -2049,6 +2155,7 @@ var CanvasBoard = forwardRef2(
|
|
|
2049
2155
|
drawEvent,
|
|
2050
2156
|
eventsResize,
|
|
2051
2157
|
stripeOverlap,
|
|
2158
|
+
timeBar,
|
|
2052
2159
|
animations,
|
|
2053
2160
|
rendererRef
|
|
2054
2161
|
]);
|
|
@@ -2346,6 +2453,43 @@ var CanvasBoard = forwardRef2(
|
|
|
2346
2453
|
);
|
|
2347
2454
|
var canvas_board_default = CanvasBoard;
|
|
2348
2455
|
|
|
2456
|
+
// src/components/pointer-line.tsx
|
|
2457
|
+
import React6, { forwardRef as forwardRef3, useImperativeHandle as useImperativeHandle2, useRef as useRef6 } from "react";
|
|
2458
|
+
var PointerLine = forwardRef3(({ contentRef, mainRef, top, color, labelColor, font }, ref) => {
|
|
2459
|
+
const lineRef = useRef6(null);
|
|
2460
|
+
const labelRef = useRef6(null);
|
|
2461
|
+
useImperativeHandle2(ref, () => ({
|
|
2462
|
+
show: (x, label) => {
|
|
2463
|
+
var _a, _b;
|
|
2464
|
+
const line = lineRef.current, tag = labelRef.current;
|
|
2465
|
+
const content = contentRef.current, main = mainRef.current;
|
|
2466
|
+
if (!line || !tag || !content || !main) return;
|
|
2467
|
+
const box = content.getBoundingClientRect();
|
|
2468
|
+
const frame = main.getBoundingClientRect();
|
|
2469
|
+
const left = box.left - frame.left;
|
|
2470
|
+
const bottom = Math.min(box.bottom, (_b = (_a = content.parentElement) == null ? void 0 : _a.getBoundingClientRect().bottom) != null ? _b : box.bottom);
|
|
2471
|
+
line.style.height = `${Math.max(bottom - frame.top - top, 0)}px`;
|
|
2472
|
+
line.style.display = "block";
|
|
2473
|
+
line.style.transform = `translateX(${Math.round(left + x)}px)`;
|
|
2474
|
+
if (label === null) {
|
|
2475
|
+
tag.style.display = "none";
|
|
2476
|
+
return;
|
|
2477
|
+
}
|
|
2478
|
+
tag.textContent = label;
|
|
2479
|
+
tag.style.display = "block";
|
|
2480
|
+
const w = tag.offsetWidth;
|
|
2481
|
+
const at = Math.min(Math.max(x - w / 2, 0), Math.max(box.width - w, 0));
|
|
2482
|
+
tag.style.transform = `translateX(${Math.round(left + at)}px)`;
|
|
2483
|
+
},
|
|
2484
|
+
hide: () => {
|
|
2485
|
+
if (lineRef.current) lineRef.current.style.display = "none";
|
|
2486
|
+
if (labelRef.current) labelRef.current.style.display = "none";
|
|
2487
|
+
}
|
|
2488
|
+
}), [contentRef, mainRef, top]);
|
|
2489
|
+
return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement("div", { ref: lineRef, className: "pointer-line", style: { top, borderLeftColor: color } }), /* @__PURE__ */ React6.createElement("div", { ref: labelRef, className: "pointer-label", style: { background: color, color: labelColor, font } }));
|
|
2490
|
+
});
|
|
2491
|
+
var pointer_line_default = PointerLine;
|
|
2492
|
+
|
|
2349
2493
|
// src/core/scene.ts
|
|
2350
2494
|
var binaryInsertIndex = (events, event) => {
|
|
2351
2495
|
let lo = 0;
|
|
@@ -2805,7 +2949,8 @@ var SceneStore = class {
|
|
|
2805
2949
|
};
|
|
2806
2950
|
|
|
2807
2951
|
// src/timeline.tsx
|
|
2808
|
-
var
|
|
2952
|
+
var defaultPointerFormat = (time) => new Date(time * 1e3).toLocaleString();
|
|
2953
|
+
var Timeline = forwardRef4(
|
|
2809
2954
|
({
|
|
2810
2955
|
rows,
|
|
2811
2956
|
events,
|
|
@@ -2833,6 +2978,9 @@ var Timeline = forwardRef3(
|
|
|
2833
2978
|
panZoom,
|
|
2834
2979
|
timeBar,
|
|
2835
2980
|
showTimeBar = true,
|
|
2981
|
+
showPointerLine = false,
|
|
2982
|
+
formatPointerTime,
|
|
2983
|
+
onPointerTime,
|
|
2836
2984
|
animations = true
|
|
2837
2985
|
}, handleRef) => {
|
|
2838
2986
|
const [windowTime, setWindowTime] = useState4([
|
|
@@ -2929,7 +3077,70 @@ var Timeline = forwardRef3(
|
|
|
2929
3077
|
var _a;
|
|
2930
3078
|
(_a = onWindowChangeRef.current) == null ? void 0 : _a.call(onWindowChangeRef, { startTime: windowTime[0], endTime: windowTime[1] });
|
|
2931
3079
|
}, [windowTime[0], windowTime[1]]);
|
|
2932
|
-
|
|
3080
|
+
const tickRef = useRef7(tick);
|
|
3081
|
+
tickRef.current = tick;
|
|
3082
|
+
const pointerLineRef = useRef7(null);
|
|
3083
|
+
const pointerRef = useRef7(null);
|
|
3084
|
+
const pointerOpts = useRef7({ showPointerLine, showTimeBar, formatPointerTime, onPointerTime });
|
|
3085
|
+
pointerOpts.current = { showPointerLine, showTimeBar, formatPointerTime, onPointerTime };
|
|
3086
|
+
const drawPointer = useCallback3(() => {
|
|
3087
|
+
var _a, _b, _c;
|
|
3088
|
+
const line = pointerLineRef.current;
|
|
3089
|
+
const p = pointerRef.current;
|
|
3090
|
+
const t = tickRef.current;
|
|
3091
|
+
if (!line) return;
|
|
3092
|
+
if (!p || !t) return line.hide();
|
|
3093
|
+
if ("x" in p && ((_a = rendererRef.current) == null ? void 0 : _a.getView().hoveredEventId)) return line.hide();
|
|
3094
|
+
const start = windowTimeRef.current[0];
|
|
3095
|
+
const time = "x" in p ? start + p.x * t : p.time;
|
|
3096
|
+
const x = "x" in p ? p.x : (p.time - start) / t;
|
|
3097
|
+
const width = (_c = (_b = contentRef.current) == null ? void 0 : _b.getBoundingClientRect().width) != null ? _c : 0;
|
|
3098
|
+
if (x < 0 || x > width) return line.hide();
|
|
3099
|
+
const { showTimeBar: labelled, formatPointerTime: format } = pointerOpts.current;
|
|
3100
|
+
line.show(x, labelled ? (format != null ? format : defaultPointerFormat)(time) : null);
|
|
3101
|
+
}, []);
|
|
3102
|
+
useEffect6(() => {
|
|
3103
|
+
const column = contentRef.current;
|
|
3104
|
+
if (!column) return;
|
|
3105
|
+
const move = (e) => {
|
|
3106
|
+
var _a, _b;
|
|
3107
|
+
const t = tickRef.current;
|
|
3108
|
+
if (!t) return;
|
|
3109
|
+
const x = e.clientX - column.getBoundingClientRect().left;
|
|
3110
|
+
(_b = (_a = pointerOpts.current).onPointerTime) == null ? void 0 : _b.call(_a, windowTimeRef.current[0] + x * t);
|
|
3111
|
+
if (!pointerOpts.current.showPointerLine) return;
|
|
3112
|
+
pointerRef.current = { x };
|
|
3113
|
+
drawPointer();
|
|
3114
|
+
};
|
|
3115
|
+
const leave = () => {
|
|
3116
|
+
var _a, _b;
|
|
3117
|
+
(_b = (_a = pointerOpts.current).onPointerTime) == null ? void 0 : _b.call(_a, null);
|
|
3118
|
+
if (pointerRef.current && "x" in pointerRef.current) {
|
|
3119
|
+
pointerRef.current = null;
|
|
3120
|
+
drawPointer();
|
|
3121
|
+
}
|
|
3122
|
+
};
|
|
3123
|
+
column.addEventListener("pointermove", move);
|
|
3124
|
+
column.addEventListener("pointerleave", leave);
|
|
3125
|
+
return () => {
|
|
3126
|
+
column.removeEventListener("pointermove", move);
|
|
3127
|
+
column.removeEventListener("pointerleave", leave);
|
|
3128
|
+
};
|
|
3129
|
+
}, [drawPointer]);
|
|
3130
|
+
useEffect6(() => {
|
|
3131
|
+
var _a, _b;
|
|
3132
|
+
const p = pointerRef.current;
|
|
3133
|
+
if (p && "x" in p && tick) (_b = (_a = pointerOpts.current).onPointerTime) == null ? void 0 : _b.call(_a, windowTime[0] + p.x * tick);
|
|
3134
|
+
drawPointer();
|
|
3135
|
+
}, [windowTime[0], windowTime[1], tick, drawPointer]);
|
|
3136
|
+
const onEventHoverRef = useRef7(onEventHover);
|
|
3137
|
+
onEventHoverRef.current = onEventHover;
|
|
3138
|
+
const handleEventHover = useCallback3((hover) => {
|
|
3139
|
+
var _a;
|
|
3140
|
+
drawPointer();
|
|
3141
|
+
(_a = onEventHoverRef.current) == null ? void 0 : _a.call(onEventHoverRef, hover);
|
|
3142
|
+
}, [drawPointer]);
|
|
3143
|
+
useImperativeHandle3(
|
|
2933
3144
|
handleRef,
|
|
2934
3145
|
() => ({
|
|
2935
3146
|
setEvents: (next) => scene.setEvents([...next].sort(sort_events_default)),
|
|
@@ -2947,6 +3158,7 @@ var Timeline = forwardRef3(
|
|
|
2947
3158
|
// the scale follows the window, or a zoom applied from outside draws and pans at the old one
|
|
2948
3159
|
setWindow: (startTime, endTime) => {
|
|
2949
3160
|
var _a;
|
|
3161
|
+
windowTimeRef.current = [startTime, endTime];
|
|
2950
3162
|
setWindowTime([startTime, endTime]);
|
|
2951
3163
|
const width = (_a = contentRef.current) == null ? void 0 : _a.getBoundingClientRect().width;
|
|
2952
3164
|
if (width && endTime > startTime) {
|
|
@@ -2958,6 +3170,10 @@ var Timeline = forwardRef3(
|
|
|
2958
3170
|
startTime: windowTimeRef.current[0],
|
|
2959
3171
|
endTime: windowTimeRef.current[1]
|
|
2960
3172
|
}),
|
|
3173
|
+
setPointerTime: (time) => {
|
|
3174
|
+
pointerRef.current = time === null ? null : { time };
|
|
3175
|
+
drawPointer();
|
|
3176
|
+
},
|
|
2961
3177
|
setSelection: (ids) => applySelection(ids),
|
|
2962
3178
|
getSelection,
|
|
2963
3179
|
toggleRow: (rowId) => scene.toggleCollapsed(rowId),
|
|
@@ -2967,7 +3183,7 @@ var Timeline = forwardRef3(
|
|
|
2967
3183
|
return (_a = rendererRef.current) == null ? void 0 : _a.invalidate("all");
|
|
2968
3184
|
}
|
|
2969
3185
|
}),
|
|
2970
|
-
[scene, applySelection, getSelection]
|
|
3186
|
+
[scene, applySelection, getSelection, drawPointer]
|
|
2971
3187
|
);
|
|
2972
3188
|
useEffect6(() => {
|
|
2973
3189
|
if (contentRef.current) {
|
|
@@ -3019,16 +3235,16 @@ var Timeline = forwardRef3(
|
|
|
3019
3235
|
);
|
|
3020
3236
|
}
|
|
3021
3237
|
}, []);
|
|
3022
|
-
use_resize_observer_default({ contentRef, setCellWidth, setTick,
|
|
3023
|
-
const resolvedTheme =
|
|
3024
|
-
const geometry =
|
|
3238
|
+
use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTimeRef });
|
|
3239
|
+
const resolvedTheme = useMemo2(() => resolveTheme(theme), [theme]);
|
|
3240
|
+
const geometry = useMemo2(
|
|
3025
3241
|
() => geometryFromTheme(resolvedTheme),
|
|
3026
3242
|
[resolvedTheme]
|
|
3027
3243
|
);
|
|
3028
3244
|
useEffect6(() => {
|
|
3029
3245
|
scene.setGeometry(geometry);
|
|
3030
3246
|
}, [scene, geometry]);
|
|
3031
|
-
const resolvedAnimations =
|
|
3247
|
+
const resolvedAnimations = useMemo2(() => {
|
|
3032
3248
|
var _a, _b;
|
|
3033
3249
|
if (animations === false) return { layoutMs: 0, fadeMs: 0 };
|
|
3034
3250
|
if (animations === true) {
|
|
@@ -3042,8 +3258,8 @@ var Timeline = forwardRef3(
|
|
|
3042
3258
|
fadeMs: (_b = animations.fadeMs) != null ? _b : DEFAULT_FADE_DURATION_MS
|
|
3043
3259
|
};
|
|
3044
3260
|
}, [animations]);
|
|
3045
|
-
const eventPrompt =
|
|
3046
|
-
() => /* @__PURE__ */
|
|
3261
|
+
const eventPrompt = useMemo2(
|
|
3262
|
+
() => /* @__PURE__ */ React7.createElement(
|
|
3047
3263
|
event_prompt_default,
|
|
3048
3264
|
{
|
|
3049
3265
|
ref: eventPromptRef,
|
|
@@ -3052,7 +3268,7 @@ var Timeline = forwardRef3(
|
|
|
3052
3268
|
),
|
|
3053
3269
|
[eventPromptTemplate]
|
|
3054
3270
|
);
|
|
3055
|
-
return /* @__PURE__ */
|
|
3271
|
+
return /* @__PURE__ */ React7.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ React7.createElement(rt_indicator_default, { tick, windowTime }), showTimeBar && /* @__PURE__ */ React7.createElement(
|
|
3056
3272
|
canvas_time_bar_default,
|
|
3057
3273
|
{
|
|
3058
3274
|
windowTime,
|
|
@@ -3062,7 +3278,7 @@ var Timeline = forwardRef3(
|
|
|
3062
3278
|
theme: resolvedTheme,
|
|
3063
3279
|
timeBar
|
|
3064
3280
|
}
|
|
3065
|
-
), /* @__PURE__ */
|
|
3281
|
+
), /* @__PURE__ */ React7.createElement("div", { className: "body-wrapper", ref: bodyRef, style: { borderColor: resolvedTheme.borderColor } }, /* @__PURE__ */ React7.createElement(
|
|
3066
3282
|
canvas_board_default,
|
|
3067
3283
|
{
|
|
3068
3284
|
scene,
|
|
@@ -3083,9 +3299,10 @@ var Timeline = forwardRef3(
|
|
|
3083
3299
|
onDrop,
|
|
3084
3300
|
onResize,
|
|
3085
3301
|
onEventClick,
|
|
3086
|
-
onEventHover,
|
|
3302
|
+
onEventHover: handleEventHover,
|
|
3087
3303
|
eventsResize,
|
|
3088
3304
|
stripeOverlap,
|
|
3305
|
+
timeBar,
|
|
3089
3306
|
panZoom,
|
|
3090
3307
|
animations: resolvedAnimations,
|
|
3091
3308
|
selectable,
|
|
@@ -3093,10 +3310,22 @@ var Timeline = forwardRef3(
|
|
|
3093
3310
|
getSelection,
|
|
3094
3311
|
ref: contentRef
|
|
3095
3312
|
}
|
|
3096
|
-
), showEventPrompt && eventPrompt)
|
|
3313
|
+
), showEventPrompt && eventPrompt), /* @__PURE__ */ React7.createElement(
|
|
3314
|
+
pointer_line_default,
|
|
3315
|
+
{
|
|
3316
|
+
ref: pointerLineRef,
|
|
3317
|
+
contentRef,
|
|
3318
|
+
mainRef,
|
|
3319
|
+
top: showTimeBar ? TIME_BAR_HEIGHT : 0,
|
|
3320
|
+
color: resolvedTheme.pointerLineColor,
|
|
3321
|
+
labelColor: resolvedTheme.pointerLabelColor,
|
|
3322
|
+
font: resolvedTheme.font
|
|
3323
|
+
}
|
|
3324
|
+
));
|
|
3097
3325
|
}
|
|
3098
3326
|
);
|
|
3099
3327
|
export {
|
|
3328
|
+
DEFAULT_TIME_BAR_LEVELS,
|
|
3100
3329
|
Timeline
|
|
3101
3330
|
};
|
|
3102
3331
|
//# sourceMappingURL=index.mjs.map
|