awesome-timeline-react 0.7.0 → 0.8.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 +6 -6
- package/dist/_tsup-dts-rollup.d.mts +43 -30
- package/dist/_tsup-dts-rollup.d.ts +43 -30
- package/dist/index.css +6 -0
- package/dist/index.css.map +1 -1
- package/dist/index.js +43 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -52
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -674,7 +674,6 @@ var cullToWindow = (events, windowStart, windowEnd) => {
|
|
|
674
674
|
// src/core/coords.ts
|
|
675
675
|
var timeToX = (time, windowStart, tick) => (time - windowStart) / tick;
|
|
676
676
|
var timeToWidth = (startTime, endTime, tick) => (endTime - startTime) / tick;
|
|
677
|
-
var intersectsWindow = (event, windowStart, windowEnd) => event.endTime >= windowStart && event.startTime <= windowEnd;
|
|
678
677
|
|
|
679
678
|
// src/core/geometry.ts
|
|
680
679
|
var DEFAULT_GEOMETRY = {
|
|
@@ -702,11 +701,10 @@ var geometryFromTheme = (theme) => {
|
|
|
702
701
|
var laneTop = (lane, g = DEFAULT_GEOMETRY) => g.laneTopOffset + g.laneHeight * lane;
|
|
703
702
|
var rowMinHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.rowBaseHeight + highestLane * g.laneHeight;
|
|
704
703
|
var staticEventHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.staticEventBaseHeight + highestLane * g.laneHeight;
|
|
705
|
-
var assignLanes = (rowEvents
|
|
704
|
+
var assignLanes = (rowEvents) => {
|
|
706
705
|
const laneEnd = [];
|
|
707
706
|
const laneOf = /* @__PURE__ */ new Map();
|
|
708
707
|
for (const event of rowEvents) {
|
|
709
|
-
if (!intersectsWindow(event, windowStart, windowEnd)) continue;
|
|
710
708
|
let lane = laneEnd.findIndex((end) => end <= event.startTime);
|
|
711
709
|
if (lane === -1) {
|
|
712
710
|
lane = laneEnd.length;
|
|
@@ -800,7 +798,6 @@ var roundedRect = (ctx, x, y, width, height, radius) => {
|
|
|
800
798
|
};
|
|
801
799
|
var drawGroupShading = (ctx, view, scene) => {
|
|
802
800
|
var _a;
|
|
803
|
-
const [windowStart, windowEnd] = view.windowTime;
|
|
804
801
|
const visible = scene.getVisibleRowIds();
|
|
805
802
|
const regions = [];
|
|
806
803
|
let y = 0;
|
|
@@ -812,7 +809,7 @@ var drawGroupShading = (ctx, view, scene) => {
|
|
|
812
809
|
runParent = null;
|
|
813
810
|
};
|
|
814
811
|
for (const rowId of visible) {
|
|
815
|
-
const height = scene.getRowHeight(rowId
|
|
812
|
+
const height = scene.getRowHeight(rowId);
|
|
816
813
|
const parentId = (_a = scene.getRow(rowId)) == null ? void 0 : _a.parentId;
|
|
817
814
|
if (parentId !== void 0) {
|
|
818
815
|
if (runParent === parentId) {
|
|
@@ -859,14 +856,13 @@ var drawGroupShading = (ctx, view, scene) => {
|
|
|
859
856
|
ctx.restore();
|
|
860
857
|
};
|
|
861
858
|
var drawRowDividers = (ctx, view, scene) => {
|
|
862
|
-
const [windowStart, windowEnd] = view.windowTime;
|
|
863
859
|
const rowIds = scene.getVisibleRowIds();
|
|
864
860
|
ctx.strokeStyle = view.theme.gridColor;
|
|
865
861
|
ctx.lineWidth = 1;
|
|
866
862
|
ctx.beginPath();
|
|
867
863
|
let y = 0;
|
|
868
864
|
for (let i = 0; i < rowIds.length; i++) {
|
|
869
|
-
y += scene.getRowHeight(rowIds[i]
|
|
865
|
+
y += scene.getRowHeight(rowIds[i]);
|
|
870
866
|
if (i === rowIds.length - 1) break;
|
|
871
867
|
const screenY = y - view.scrollTop;
|
|
872
868
|
if (screenY < 0) continue;
|
|
@@ -979,7 +975,7 @@ var paintOverlapStripes = (ctx, event, rect, rowStatics, windowStart, tick, colo
|
|
|
979
975
|
}
|
|
980
976
|
};
|
|
981
977
|
var drawEvents = (ctx, view, scene, font, animator) => {
|
|
982
|
-
var _a;
|
|
978
|
+
var _a, _b, _c, _d;
|
|
983
979
|
if (view.tick === null) return;
|
|
984
980
|
const [windowStart, windowEnd] = view.windowTime;
|
|
985
981
|
const tick = view.tick;
|
|
@@ -991,7 +987,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
991
987
|
const hasSelection = selectedIds.size > 0;
|
|
992
988
|
const deferred = [];
|
|
993
989
|
const paintEvent = (event, rect, state, opts, rowStatics) => {
|
|
994
|
-
var _a2,
|
|
990
|
+
var _a2, _b2, _c2, _d2, _e;
|
|
995
991
|
ctx.save();
|
|
996
992
|
ctx.globalAlpha = 1;
|
|
997
993
|
if (opts.elevate) {
|
|
@@ -1002,7 +998,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
1002
998
|
}
|
|
1003
999
|
if (state.dragging) ctx.globalAlpha = 0.5;
|
|
1004
1000
|
else if (opts.dim) ctx.globalAlpha *= view.theme.dimmedOpacity;
|
|
1005
|
-
const custom = (
|
|
1001
|
+
const custom = (_b2 = (_a2 = event.props) == null ? void 0 : _a2.drawEvent) != null ? _b2 : view.drawEvent;
|
|
1006
1002
|
const drawn = custom !== void 0 && custom(ctx, event, rect, state, view.theme) !== false;
|
|
1007
1003
|
if (!drawn) {
|
|
1008
1004
|
defaultDrawEvent(ctx, event, rect, view, font, geometry.barRadius);
|
|
@@ -1029,7 +1025,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
1029
1025
|
ctx,
|
|
1030
1026
|
rect,
|
|
1031
1027
|
alpha,
|
|
1032
|
-
(_e = (
|
|
1028
|
+
(_e = (_d2 = (_c2 = event.props) == null ? void 0 : _c2.style) == null ? void 0 : _d2.stroke) != null ? _e : view.theme.eventStroke
|
|
1033
1029
|
);
|
|
1034
1030
|
}
|
|
1035
1031
|
}
|
|
@@ -1037,13 +1033,13 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
1037
1033
|
};
|
|
1038
1034
|
let rowTop = 0;
|
|
1039
1035
|
for (const rowId of scene.getVisibleRowIds()) {
|
|
1040
|
-
const rowHeight = scene.getRowHeight(rowId
|
|
1036
|
+
const rowHeight = scene.getRowHeight(rowId);
|
|
1041
1037
|
const rowY = rowTop - view.scrollTop;
|
|
1042
1038
|
rowTop += rowHeight;
|
|
1043
1039
|
if (rowY + rowHeight < 0) continue;
|
|
1044
1040
|
if (rowY > view.height) break;
|
|
1045
|
-
const lanes = scene.getLanes(rowId
|
|
1046
|
-
const inset = scene.getLaneInset(rowId
|
|
1041
|
+
const lanes = scene.getLanes(rowId);
|
|
1042
|
+
const inset = scene.getLaneInset(rowId);
|
|
1047
1043
|
const rowStatics = cullToWindow(
|
|
1048
1044
|
scene.getRowStaticEvents(rowId),
|
|
1049
1045
|
windowStart,
|
|
@@ -1052,7 +1048,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
1052
1048
|
for (const event of rowStatics) {
|
|
1053
1049
|
const x = timeToX(event.startTime, windowStart, tick);
|
|
1054
1050
|
const width = timeToWidth(event.startTime, event.endTime, tick);
|
|
1055
|
-
ctx.fillStyle = view.theme.staticEventFill;
|
|
1051
|
+
ctx.fillStyle = (_d = (_c = (_b = event.props) == null ? void 0 : _b.style) == null ? void 0 : _c.fill) != null ? _d : view.theme.staticEventFill;
|
|
1056
1052
|
roundedRect(
|
|
1057
1053
|
ctx,
|
|
1058
1054
|
x,
|
|
@@ -1223,7 +1219,7 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1223
1219
|
let rowTop = 0;
|
|
1224
1220
|
let rowId = null;
|
|
1225
1221
|
for (const id of scene.getVisibleRowIds()) {
|
|
1226
|
-
const height = scene.getRowHeight(id
|
|
1222
|
+
const height = scene.getRowHeight(id);
|
|
1227
1223
|
if (yContent >= rowTop && yContent < rowTop + height) {
|
|
1228
1224
|
rowId = id;
|
|
1229
1225
|
break;
|
|
@@ -1231,8 +1227,8 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1231
1227
|
rowTop += height;
|
|
1232
1228
|
}
|
|
1233
1229
|
if (rowId === null) return null;
|
|
1234
|
-
const lanes = scene.getLanes(rowId
|
|
1235
|
-
const lanesY = rowTop - scrollTop + scene.getLaneInset(rowId
|
|
1230
|
+
const lanes = scene.getLanes(rowId);
|
|
1231
|
+
const lanesY = rowTop - scrollTop + scene.getLaneInset(rowId);
|
|
1236
1232
|
const events = cullToWindow(
|
|
1237
1233
|
scene.getRowEvents(rowId),
|
|
1238
1234
|
windowStart,
|
|
@@ -1652,11 +1648,7 @@ var useCanvasInteractions = ({
|
|
|
1652
1648
|
const yContent = clientY - canvas.getBoundingClientRect().top + view.scrollTop;
|
|
1653
1649
|
let rowTop = 0;
|
|
1654
1650
|
for (const id of scene.getVisibleRowIds()) {
|
|
1655
|
-
const height = scene.getRowHeight(
|
|
1656
|
-
id,
|
|
1657
|
-
view.windowTime[0],
|
|
1658
|
-
view.windowTime[1]
|
|
1659
|
-
);
|
|
1651
|
+
const height = scene.getRowHeight(id);
|
|
1660
1652
|
if (yContent >= rowTop && yContent < rowTop + height) return id;
|
|
1661
1653
|
rowTop += height;
|
|
1662
1654
|
}
|
|
@@ -2193,10 +2185,7 @@ var CanvasBoard = (0, import_react6.forwardRef)(
|
|
|
2193
2185
|
selectedEventIds: new Set(getSelection())
|
|
2194
2186
|
});
|
|
2195
2187
|
}, [getSelection, rendererRef]);
|
|
2196
|
-
const { offsetOf, totalHeight } = scene.getRowOffsets(
|
|
2197
|
-
windowTime[0],
|
|
2198
|
-
windowTime[1]
|
|
2199
|
-
);
|
|
2188
|
+
const { offsetOf, totalHeight } = scene.getRowOffsets();
|
|
2200
2189
|
totalHeightRef.current = totalHeight;
|
|
2201
2190
|
(0, import_react6.useLayoutEffect)(() => {
|
|
2202
2191
|
measureViewport();
|
|
@@ -2213,7 +2202,7 @@ var CanvasBoard = (0, import_react6.forwardRef)(
|
|
|
2213
2202
|
if (scene.isRowHidden(row.id)) continue;
|
|
2214
2203
|
const top = offsetOf.get(row.id);
|
|
2215
2204
|
if (top === void 0) continue;
|
|
2216
|
-
const height = scene.getRowHeight(row.id
|
|
2205
|
+
const height = scene.getRowHeight(row.id);
|
|
2217
2206
|
if (top + height < scrollTop) continue;
|
|
2218
2207
|
if (top > scrollTop + viewportHeight) break;
|
|
2219
2208
|
const isParent = scene.isRowParent(row.id);
|
|
@@ -2420,9 +2409,7 @@ var SceneStore = class {
|
|
|
2420
2409
|
events: [],
|
|
2421
2410
|
staticEvents: [],
|
|
2422
2411
|
lanesDirty: true,
|
|
2423
|
-
lanes: null
|
|
2424
|
-
laneWindowStart: NaN,
|
|
2425
|
-
laneWindowEnd: NaN
|
|
2412
|
+
lanes: null
|
|
2426
2413
|
}
|
|
2427
2414
|
);
|
|
2428
2415
|
}
|
|
@@ -2604,14 +2591,15 @@ var SceneStore = class {
|
|
|
2604
2591
|
var _a, _b;
|
|
2605
2592
|
return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.staticEvents) != null ? _b : [];
|
|
2606
2593
|
}
|
|
2607
|
-
|
|
2594
|
+
/** Lanes over ALL the row's events, not just those in view: a lane assignment that followed the
|
|
2595
|
+
* window re-packed the row on every pan frame, so bars jumped between lanes as others scrolled in
|
|
2596
|
+
* and out. The row is as tall as its peak overlap anywhere. */
|
|
2597
|
+
getLanes(rowId) {
|
|
2608
2598
|
this.flushParentSpans(rowId);
|
|
2609
2599
|
const index = this.rowIndexes.get(rowId);
|
|
2610
2600
|
if (!index) return { laneOf: /* @__PURE__ */ new Map(), highestLane: 0 };
|
|
2611
|
-
if (index.lanesDirty || index.lanes === null
|
|
2612
|
-
index.lanes = assignLanes(index.events
|
|
2613
|
-
index.laneWindowStart = windowStart;
|
|
2614
|
-
index.laneWindowEnd = windowEnd;
|
|
2601
|
+
if (index.lanesDirty || index.lanes === null) {
|
|
2602
|
+
index.lanes = assignLanes(index.events);
|
|
2615
2603
|
index.lanesDirty = false;
|
|
2616
2604
|
}
|
|
2617
2605
|
return index.lanes;
|
|
@@ -2637,23 +2625,17 @@ var SceneStore = class {
|
|
|
2637
2625
|
this.labelMinHeights = heights;
|
|
2638
2626
|
this.bump();
|
|
2639
2627
|
}
|
|
2640
|
-
getRowHeight(rowId
|
|
2628
|
+
getRowHeight(rowId) {
|
|
2641
2629
|
var _a;
|
|
2642
|
-
const laneHeight = rowMinHeight(
|
|
2643
|
-
this.getLanes(rowId, windowStart, windowEnd).highestLane,
|
|
2644
|
-
this.geometry
|
|
2645
|
-
);
|
|
2630
|
+
const laneHeight = rowMinHeight(this.getLanes(rowId).highestLane, this.geometry);
|
|
2646
2631
|
const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
|
|
2647
2632
|
return Math.max(laneHeight, labelHeight);
|
|
2648
2633
|
}
|
|
2649
2634
|
/** Extra top offset for a row's lanes: when a tall label grows the row past what its lanes need,
|
|
2650
2635
|
* the lanes sit centred in it rather than hugging the top with the surplus all below. */
|
|
2651
|
-
getLaneInset(rowId
|
|
2636
|
+
getLaneInset(rowId) {
|
|
2652
2637
|
var _a;
|
|
2653
|
-
const laneHeight = rowMinHeight(
|
|
2654
|
-
this.getLanes(rowId, windowStart, windowEnd).highestLane,
|
|
2655
|
-
this.geometry
|
|
2656
|
-
);
|
|
2638
|
+
const laneHeight = rowMinHeight(this.getLanes(rowId).highestLane, this.geometry);
|
|
2657
2639
|
const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
|
|
2658
2640
|
return labelHeight > laneHeight ? Math.floor((labelHeight - laneHeight) / 2) : 0;
|
|
2659
2641
|
}
|
|
@@ -2661,12 +2643,12 @@ var SceneStore = class {
|
|
|
2661
2643
|
* y offset of each row's top edge (content coordinates, before scroll) plus
|
|
2662
2644
|
* the total content height — drives both drawing and the scroll spacer.
|
|
2663
2645
|
*/
|
|
2664
|
-
getRowOffsets(
|
|
2646
|
+
getRowOffsets() {
|
|
2665
2647
|
const offsetOf = /* @__PURE__ */ new Map();
|
|
2666
2648
|
let y = 0;
|
|
2667
2649
|
for (const rowId of this.getVisibleRowIds()) {
|
|
2668
2650
|
offsetOf.set(rowId, y);
|
|
2669
|
-
y += this.getRowHeight(rowId
|
|
2651
|
+
y += this.getRowHeight(rowId);
|
|
2670
2652
|
}
|
|
2671
2653
|
return { offsetOf, totalHeight: y };
|
|
2672
2654
|
}
|
|
@@ -2841,6 +2823,7 @@ var Timeline = (0, import_react7.forwardRef)(
|
|
|
2841
2823
|
showEventPrompt = true,
|
|
2842
2824
|
panZoom,
|
|
2843
2825
|
timeBar,
|
|
2826
|
+
showTimeBar = true,
|
|
2844
2827
|
animations = true
|
|
2845
2828
|
}, handleRef) => {
|
|
2846
2829
|
const [windowTime, setWindowTime] = (0, import_react7.useState)([
|
|
@@ -2944,8 +2927,7 @@ var Timeline = (0, import_react7.forwardRef)(
|
|
|
2944
2927
|
updateEvents: (patches) => scene.applyPatches(patches),
|
|
2945
2928
|
getEvent: (id) => scene.getEvent(id),
|
|
2946
2929
|
scrollToRow: (rowId) => {
|
|
2947
|
-
const
|
|
2948
|
-
const offset2 = scene.getRowOffsets(windowStart, windowEnd).offsetOf.get(rowId);
|
|
2930
|
+
const offset2 = scene.getRowOffsets().offsetOf.get(rowId);
|
|
2949
2931
|
if (offset2 !== void 0 && bodyRef.current) {
|
|
2950
2932
|
bodyRef.current.scrollTop = offset2;
|
|
2951
2933
|
}
|
|
@@ -2953,7 +2935,16 @@ var Timeline = (0, import_react7.forwardRef)(
|
|
|
2953
2935
|
scrollToTime: (time) => {
|
|
2954
2936
|
setWindowTime((prev) => [time, time + (prev[1] - prev[0])]);
|
|
2955
2937
|
},
|
|
2956
|
-
|
|
2938
|
+
// the scale follows the window, or a zoom applied from outside draws and pans at the old one
|
|
2939
|
+
setWindow: (startTime, endTime) => {
|
|
2940
|
+
var _a;
|
|
2941
|
+
setWindowTime([startTime, endTime]);
|
|
2942
|
+
const width = (_a = contentRef.current) == null ? void 0 : _a.getBoundingClientRect().width;
|
|
2943
|
+
if (width && endTime > startTime) {
|
|
2944
|
+
setTick((endTime - startTime) / width);
|
|
2945
|
+
setCellWidth(width / ((endTime - startTime) / 3600));
|
|
2946
|
+
}
|
|
2947
|
+
},
|
|
2957
2948
|
getVisibleRange: () => ({
|
|
2958
2949
|
startTime: windowTimeRef.current[0],
|
|
2959
2950
|
endTime: windowTimeRef.current[1]
|
|
@@ -3052,7 +3043,7 @@ var Timeline = (0, import_react7.forwardRef)(
|
|
|
3052
3043
|
),
|
|
3053
3044
|
[eventPromptTemplate]
|
|
3054
3045
|
);
|
|
3055
|
-
return /* @__PURE__ */ import_react7.default.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ import_react7.default.createElement(rt_indicator_default, { tick, windowTime }), /* @__PURE__ */ import_react7.default.createElement(
|
|
3046
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ import_react7.default.createElement(rt_indicator_default, { tick, windowTime }), showTimeBar && /* @__PURE__ */ import_react7.default.createElement(
|
|
3056
3047
|
canvas_time_bar_default,
|
|
3057
3048
|
{
|
|
3058
3049
|
windowTime,
|