awesome-timeline-react 0.6.1 → 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 +60 -29
- package/dist/_tsup-dts-rollup.d.ts +60 -29
- package/dist/index.css +6 -0
- package/dist/index.css.map +1 -1
- package/dist/index.js +60 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -662,7 +662,6 @@ var cullToWindow = (events, windowStart, windowEnd) => {
|
|
|
662
662
|
// src/core/coords.ts
|
|
663
663
|
var timeToX = (time, windowStart, tick) => (time - windowStart) / tick;
|
|
664
664
|
var timeToWidth = (startTime, endTime, tick) => (endTime - startTime) / tick;
|
|
665
|
-
var intersectsWindow = (event, windowStart, windowEnd) => event.endTime >= windowStart && event.startTime <= windowEnd;
|
|
666
665
|
|
|
667
666
|
// src/core/geometry.ts
|
|
668
667
|
var DEFAULT_GEOMETRY = {
|
|
@@ -690,11 +689,10 @@ var geometryFromTheme = (theme) => {
|
|
|
690
689
|
var laneTop = (lane, g = DEFAULT_GEOMETRY) => g.laneTopOffset + g.laneHeight * lane;
|
|
691
690
|
var rowMinHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.rowBaseHeight + highestLane * g.laneHeight;
|
|
692
691
|
var staticEventHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.staticEventBaseHeight + highestLane * g.laneHeight;
|
|
693
|
-
var assignLanes = (rowEvents
|
|
692
|
+
var assignLanes = (rowEvents) => {
|
|
694
693
|
const laneEnd = [];
|
|
695
694
|
const laneOf = /* @__PURE__ */ new Map();
|
|
696
695
|
for (const event of rowEvents) {
|
|
697
|
-
if (!intersectsWindow(event, windowStart, windowEnd)) continue;
|
|
698
696
|
let lane = laneEnd.findIndex((end) => end <= event.startTime);
|
|
699
697
|
if (lane === -1) {
|
|
700
698
|
lane = laneEnd.length;
|
|
@@ -788,7 +786,6 @@ var roundedRect = (ctx, x, y, width, height, radius) => {
|
|
|
788
786
|
};
|
|
789
787
|
var drawGroupShading = (ctx, view, scene) => {
|
|
790
788
|
var _a;
|
|
791
|
-
const [windowStart, windowEnd] = view.windowTime;
|
|
792
789
|
const visible = scene.getVisibleRowIds();
|
|
793
790
|
const regions = [];
|
|
794
791
|
let y = 0;
|
|
@@ -800,7 +797,7 @@ var drawGroupShading = (ctx, view, scene) => {
|
|
|
800
797
|
runParent = null;
|
|
801
798
|
};
|
|
802
799
|
for (const rowId of visible) {
|
|
803
|
-
const height = scene.getRowHeight(rowId
|
|
800
|
+
const height = scene.getRowHeight(rowId);
|
|
804
801
|
const parentId = (_a = scene.getRow(rowId)) == null ? void 0 : _a.parentId;
|
|
805
802
|
if (parentId !== void 0) {
|
|
806
803
|
if (runParent === parentId) {
|
|
@@ -847,14 +844,13 @@ var drawGroupShading = (ctx, view, scene) => {
|
|
|
847
844
|
ctx.restore();
|
|
848
845
|
};
|
|
849
846
|
var drawRowDividers = (ctx, view, scene) => {
|
|
850
|
-
const [windowStart, windowEnd] = view.windowTime;
|
|
851
847
|
const rowIds = scene.getVisibleRowIds();
|
|
852
848
|
ctx.strokeStyle = view.theme.gridColor;
|
|
853
849
|
ctx.lineWidth = 1;
|
|
854
850
|
ctx.beginPath();
|
|
855
851
|
let y = 0;
|
|
856
852
|
for (let i = 0; i < rowIds.length; i++) {
|
|
857
|
-
y += scene.getRowHeight(rowIds[i]
|
|
853
|
+
y += scene.getRowHeight(rowIds[i]);
|
|
858
854
|
if (i === rowIds.length - 1) break;
|
|
859
855
|
const screenY = y - view.scrollTop;
|
|
860
856
|
if (screenY < 0) continue;
|
|
@@ -967,7 +963,7 @@ var paintOverlapStripes = (ctx, event, rect, rowStatics, windowStart, tick, colo
|
|
|
967
963
|
}
|
|
968
964
|
};
|
|
969
965
|
var drawEvents = (ctx, view, scene, font, animator) => {
|
|
970
|
-
var _a;
|
|
966
|
+
var _a, _b, _c, _d;
|
|
971
967
|
if (view.tick === null) return;
|
|
972
968
|
const [windowStart, windowEnd] = view.windowTime;
|
|
973
969
|
const tick = view.tick;
|
|
@@ -979,7 +975,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
979
975
|
const hasSelection = selectedIds.size > 0;
|
|
980
976
|
const deferred = [];
|
|
981
977
|
const paintEvent = (event, rect, state, opts, rowStatics) => {
|
|
982
|
-
var _a2,
|
|
978
|
+
var _a2, _b2, _c2, _d2, _e;
|
|
983
979
|
ctx.save();
|
|
984
980
|
ctx.globalAlpha = 1;
|
|
985
981
|
if (opts.elevate) {
|
|
@@ -990,7 +986,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
990
986
|
}
|
|
991
987
|
if (state.dragging) ctx.globalAlpha = 0.5;
|
|
992
988
|
else if (opts.dim) ctx.globalAlpha *= view.theme.dimmedOpacity;
|
|
993
|
-
const custom = (
|
|
989
|
+
const custom = (_b2 = (_a2 = event.props) == null ? void 0 : _a2.drawEvent) != null ? _b2 : view.drawEvent;
|
|
994
990
|
const drawn = custom !== void 0 && custom(ctx, event, rect, state, view.theme) !== false;
|
|
995
991
|
if (!drawn) {
|
|
996
992
|
defaultDrawEvent(ctx, event, rect, view, font, geometry.barRadius);
|
|
@@ -1017,7 +1013,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
1017
1013
|
ctx,
|
|
1018
1014
|
rect,
|
|
1019
1015
|
alpha,
|
|
1020
|
-
(_e = (
|
|
1016
|
+
(_e = (_d2 = (_c2 = event.props) == null ? void 0 : _c2.style) == null ? void 0 : _d2.stroke) != null ? _e : view.theme.eventStroke
|
|
1021
1017
|
);
|
|
1022
1018
|
}
|
|
1023
1019
|
}
|
|
@@ -1025,12 +1021,13 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
1025
1021
|
};
|
|
1026
1022
|
let rowTop = 0;
|
|
1027
1023
|
for (const rowId of scene.getVisibleRowIds()) {
|
|
1028
|
-
const rowHeight = scene.getRowHeight(rowId
|
|
1024
|
+
const rowHeight = scene.getRowHeight(rowId);
|
|
1029
1025
|
const rowY = rowTop - view.scrollTop;
|
|
1030
1026
|
rowTop += rowHeight;
|
|
1031
1027
|
if (rowY + rowHeight < 0) continue;
|
|
1032
1028
|
if (rowY > view.height) break;
|
|
1033
|
-
const lanes = scene.getLanes(rowId
|
|
1029
|
+
const lanes = scene.getLanes(rowId);
|
|
1030
|
+
const inset = scene.getLaneInset(rowId);
|
|
1034
1031
|
const rowStatics = cullToWindow(
|
|
1035
1032
|
scene.getRowStaticEvents(rowId),
|
|
1036
1033
|
windowStart,
|
|
@@ -1039,11 +1036,11 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
1039
1036
|
for (const event of rowStatics) {
|
|
1040
1037
|
const x = timeToX(event.startTime, windowStart, tick);
|
|
1041
1038
|
const width = timeToWidth(event.startTime, event.endTime, tick);
|
|
1042
|
-
ctx.fillStyle = view.theme.staticEventFill;
|
|
1039
|
+
ctx.fillStyle = (_d = (_c = (_b = event.props) == null ? void 0 : _b.style) == null ? void 0 : _c.fill) != null ? _d : view.theme.staticEventFill;
|
|
1043
1040
|
roundedRect(
|
|
1044
1041
|
ctx,
|
|
1045
1042
|
x,
|
|
1046
|
-
rowY + geometry.laneTopOffset,
|
|
1043
|
+
rowY + inset + geometry.laneTopOffset,
|
|
1047
1044
|
width,
|
|
1048
1045
|
staticEventHeight(lanes.highestLane, geometry),
|
|
1049
1046
|
geometry.barRadius
|
|
@@ -1059,7 +1056,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
1059
1056
|
let width = timeToWidth(event.startTime, event.endTime, tick);
|
|
1060
1057
|
const y = rowY + animator.eventTop(
|
|
1061
1058
|
event.id,
|
|
1062
|
-
laneTop(lanes.laneOf.get(event.id), geometry)
|
|
1059
|
+
inset + laneTop(lanes.laneOf.get(event.id), geometry)
|
|
1063
1060
|
);
|
|
1064
1061
|
const resize = view.resizePreview;
|
|
1065
1062
|
const resizing = resize !== null && resize.eventId === event.id;
|
|
@@ -1210,7 +1207,7 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1210
1207
|
let rowTop = 0;
|
|
1211
1208
|
let rowId = null;
|
|
1212
1209
|
for (const id of scene.getVisibleRowIds()) {
|
|
1213
|
-
const height = scene.getRowHeight(id
|
|
1210
|
+
const height = scene.getRowHeight(id);
|
|
1214
1211
|
if (yContent >= rowTop && yContent < rowTop + height) {
|
|
1215
1212
|
rowId = id;
|
|
1216
1213
|
break;
|
|
@@ -1218,8 +1215,8 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1218
1215
|
rowTop += height;
|
|
1219
1216
|
}
|
|
1220
1217
|
if (rowId === null) return null;
|
|
1221
|
-
const lanes = scene.getLanes(rowId
|
|
1222
|
-
const
|
|
1218
|
+
const lanes = scene.getLanes(rowId);
|
|
1219
|
+
const lanesY = rowTop - scrollTop + scene.getLaneInset(rowId);
|
|
1223
1220
|
const events = cullToWindow(
|
|
1224
1221
|
scene.getRowEvents(rowId),
|
|
1225
1222
|
windowStart,
|
|
@@ -1229,7 +1226,7 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1229
1226
|
const event = events[i];
|
|
1230
1227
|
const rect = {
|
|
1231
1228
|
x: timeToX(event.startTime, windowStart, tick),
|
|
1232
|
-
y:
|
|
1229
|
+
y: lanesY + laneTop(lanes.laneOf.get(event.id), geometry),
|
|
1233
1230
|
width: timeToWidth(event.startTime, event.endTime, tick),
|
|
1234
1231
|
height: geometry.barHeight
|
|
1235
1232
|
};
|
|
@@ -1246,7 +1243,7 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1246
1243
|
const event = statics[i];
|
|
1247
1244
|
const rect = {
|
|
1248
1245
|
x: timeToX(event.startTime, windowStart, tick),
|
|
1249
|
-
y:
|
|
1246
|
+
y: lanesY + geometry.laneTopOffset,
|
|
1250
1247
|
width: timeToWidth(event.startTime, event.endTime, tick),
|
|
1251
1248
|
height: staticEventHeight(lanes.highestLane, geometry)
|
|
1252
1249
|
};
|
|
@@ -1639,11 +1636,7 @@ var useCanvasInteractions = ({
|
|
|
1639
1636
|
const yContent = clientY - canvas.getBoundingClientRect().top + view.scrollTop;
|
|
1640
1637
|
let rowTop = 0;
|
|
1641
1638
|
for (const id of scene.getVisibleRowIds()) {
|
|
1642
|
-
const height = scene.getRowHeight(
|
|
1643
|
-
id,
|
|
1644
|
-
view.windowTime[0],
|
|
1645
|
-
view.windowTime[1]
|
|
1646
|
-
);
|
|
1639
|
+
const height = scene.getRowHeight(id);
|
|
1647
1640
|
if (yContent >= rowTop && yContent < rowTop + height) return id;
|
|
1648
1641
|
rowTop += height;
|
|
1649
1642
|
}
|
|
@@ -2180,10 +2173,7 @@ var CanvasBoard = forwardRef2(
|
|
|
2180
2173
|
selectedEventIds: new Set(getSelection())
|
|
2181
2174
|
});
|
|
2182
2175
|
}, [getSelection, rendererRef]);
|
|
2183
|
-
const { offsetOf, totalHeight } = scene.getRowOffsets(
|
|
2184
|
-
windowTime[0],
|
|
2185
|
-
windowTime[1]
|
|
2186
|
-
);
|
|
2176
|
+
const { offsetOf, totalHeight } = scene.getRowOffsets();
|
|
2187
2177
|
totalHeightRef.current = totalHeight;
|
|
2188
2178
|
useLayoutEffect(() => {
|
|
2189
2179
|
measureViewport();
|
|
@@ -2200,7 +2190,7 @@ var CanvasBoard = forwardRef2(
|
|
|
2200
2190
|
if (scene.isRowHidden(row.id)) continue;
|
|
2201
2191
|
const top = offsetOf.get(row.id);
|
|
2202
2192
|
if (top === void 0) continue;
|
|
2203
|
-
const height = scene.getRowHeight(row.id
|
|
2193
|
+
const height = scene.getRowHeight(row.id);
|
|
2204
2194
|
if (top + height < scrollTop) continue;
|
|
2205
2195
|
if (top > scrollTop + viewportHeight) break;
|
|
2206
2196
|
const isParent = scene.isRowParent(row.id);
|
|
@@ -2407,9 +2397,7 @@ var SceneStore = class {
|
|
|
2407
2397
|
events: [],
|
|
2408
2398
|
staticEvents: [],
|
|
2409
2399
|
lanesDirty: true,
|
|
2410
|
-
lanes: null
|
|
2411
|
-
laneWindowStart: NaN,
|
|
2412
|
-
laneWindowEnd: NaN
|
|
2400
|
+
lanes: null
|
|
2413
2401
|
}
|
|
2414
2402
|
);
|
|
2415
2403
|
}
|
|
@@ -2591,14 +2579,15 @@ var SceneStore = class {
|
|
|
2591
2579
|
var _a, _b;
|
|
2592
2580
|
return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.staticEvents) != null ? _b : [];
|
|
2593
2581
|
}
|
|
2594
|
-
|
|
2582
|
+
/** Lanes over ALL the row's events, not just those in view: a lane assignment that followed the
|
|
2583
|
+
* window re-packed the row on every pan frame, so bars jumped between lanes as others scrolled in
|
|
2584
|
+
* and out. The row is as tall as its peak overlap anywhere. */
|
|
2585
|
+
getLanes(rowId) {
|
|
2595
2586
|
this.flushParentSpans(rowId);
|
|
2596
2587
|
const index = this.rowIndexes.get(rowId);
|
|
2597
2588
|
if (!index) return { laneOf: /* @__PURE__ */ new Map(), highestLane: 0 };
|
|
2598
|
-
if (index.lanesDirty || index.lanes === null
|
|
2599
|
-
index.lanes = assignLanes(index.events
|
|
2600
|
-
index.laneWindowStart = windowStart;
|
|
2601
|
-
index.laneWindowEnd = windowEnd;
|
|
2589
|
+
if (index.lanesDirty || index.lanes === null) {
|
|
2590
|
+
index.lanes = assignLanes(index.events);
|
|
2602
2591
|
index.lanesDirty = false;
|
|
2603
2592
|
}
|
|
2604
2593
|
return index.lanes;
|
|
@@ -2624,25 +2613,30 @@ var SceneStore = class {
|
|
|
2624
2613
|
this.labelMinHeights = heights;
|
|
2625
2614
|
this.bump();
|
|
2626
2615
|
}
|
|
2627
|
-
getRowHeight(rowId
|
|
2616
|
+
getRowHeight(rowId) {
|
|
2628
2617
|
var _a;
|
|
2629
|
-
const laneHeight = rowMinHeight(
|
|
2630
|
-
this.getLanes(rowId, windowStart, windowEnd).highestLane,
|
|
2631
|
-
this.geometry
|
|
2632
|
-
);
|
|
2618
|
+
const laneHeight = rowMinHeight(this.getLanes(rowId).highestLane, this.geometry);
|
|
2633
2619
|
const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
|
|
2634
2620
|
return Math.max(laneHeight, labelHeight);
|
|
2635
2621
|
}
|
|
2622
|
+
/** Extra top offset for a row's lanes: when a tall label grows the row past what its lanes need,
|
|
2623
|
+
* the lanes sit centred in it rather than hugging the top with the surplus all below. */
|
|
2624
|
+
getLaneInset(rowId) {
|
|
2625
|
+
var _a;
|
|
2626
|
+
const laneHeight = rowMinHeight(this.getLanes(rowId).highestLane, this.geometry);
|
|
2627
|
+
const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
|
|
2628
|
+
return labelHeight > laneHeight ? Math.floor((labelHeight - laneHeight) / 2) : 0;
|
|
2629
|
+
}
|
|
2636
2630
|
/**
|
|
2637
2631
|
* y offset of each row's top edge (content coordinates, before scroll) plus
|
|
2638
2632
|
* the total content height — drives both drawing and the scroll spacer.
|
|
2639
2633
|
*/
|
|
2640
|
-
getRowOffsets(
|
|
2634
|
+
getRowOffsets() {
|
|
2641
2635
|
const offsetOf = /* @__PURE__ */ new Map();
|
|
2642
2636
|
let y = 0;
|
|
2643
2637
|
for (const rowId of this.getVisibleRowIds()) {
|
|
2644
2638
|
offsetOf.set(rowId, y);
|
|
2645
|
-
y += this.getRowHeight(rowId
|
|
2639
|
+
y += this.getRowHeight(rowId);
|
|
2646
2640
|
}
|
|
2647
2641
|
return { offsetOf, totalHeight: y };
|
|
2648
2642
|
}
|
|
@@ -2802,6 +2796,7 @@ var Timeline = forwardRef3(
|
|
|
2802
2796
|
selectable = false,
|
|
2803
2797
|
defaultSelectedEventIds,
|
|
2804
2798
|
onSelectionChange,
|
|
2799
|
+
onWindowChange,
|
|
2805
2800
|
defaultCollapsedRowIds,
|
|
2806
2801
|
startDate,
|
|
2807
2802
|
endDate,
|
|
@@ -2816,6 +2811,7 @@ var Timeline = forwardRef3(
|
|
|
2816
2811
|
showEventPrompt = true,
|
|
2817
2812
|
panZoom,
|
|
2818
2813
|
timeBar,
|
|
2814
|
+
showTimeBar = true,
|
|
2819
2815
|
animations = true
|
|
2820
2816
|
}, handleRef) => {
|
|
2821
2817
|
const [windowTime, setWindowTime] = useState4([
|
|
@@ -2906,6 +2902,12 @@ var Timeline = forwardRef3(
|
|
|
2906
2902
|
}, [scene, defaultCollapsedRowIds]);
|
|
2907
2903
|
const windowTimeRef = useRef7(windowTime);
|
|
2908
2904
|
windowTimeRef.current = windowTime;
|
|
2905
|
+
const onWindowChangeRef = useRef7(onWindowChange);
|
|
2906
|
+
onWindowChangeRef.current = onWindowChange;
|
|
2907
|
+
useEffect6(() => {
|
|
2908
|
+
var _a;
|
|
2909
|
+
(_a = onWindowChangeRef.current) == null ? void 0 : _a.call(onWindowChangeRef, { startTime: windowTime[0], endTime: windowTime[1] });
|
|
2910
|
+
}, [windowTime[0], windowTime[1]]);
|
|
2909
2911
|
useImperativeHandle2(
|
|
2910
2912
|
handleRef,
|
|
2911
2913
|
() => ({
|
|
@@ -2913,8 +2915,7 @@ var Timeline = forwardRef3(
|
|
|
2913
2915
|
updateEvents: (patches) => scene.applyPatches(patches),
|
|
2914
2916
|
getEvent: (id) => scene.getEvent(id),
|
|
2915
2917
|
scrollToRow: (rowId) => {
|
|
2916
|
-
const
|
|
2917
|
-
const offset2 = scene.getRowOffsets(windowStart, windowEnd).offsetOf.get(rowId);
|
|
2918
|
+
const offset2 = scene.getRowOffsets().offsetOf.get(rowId);
|
|
2918
2919
|
if (offset2 !== void 0 && bodyRef.current) {
|
|
2919
2920
|
bodyRef.current.scrollTop = offset2;
|
|
2920
2921
|
}
|
|
@@ -2922,7 +2923,16 @@ var Timeline = forwardRef3(
|
|
|
2922
2923
|
scrollToTime: (time) => {
|
|
2923
2924
|
setWindowTime((prev) => [time, time + (prev[1] - prev[0])]);
|
|
2924
2925
|
},
|
|
2925
|
-
|
|
2926
|
+
// the scale follows the window, or a zoom applied from outside draws and pans at the old one
|
|
2927
|
+
setWindow: (startTime, endTime) => {
|
|
2928
|
+
var _a;
|
|
2929
|
+
setWindowTime([startTime, endTime]);
|
|
2930
|
+
const width = (_a = contentRef.current) == null ? void 0 : _a.getBoundingClientRect().width;
|
|
2931
|
+
if (width && endTime > startTime) {
|
|
2932
|
+
setTick((endTime - startTime) / width);
|
|
2933
|
+
setCellWidth(width / ((endTime - startTime) / 3600));
|
|
2934
|
+
}
|
|
2935
|
+
},
|
|
2926
2936
|
getVisibleRange: () => ({
|
|
2927
2937
|
startTime: windowTimeRef.current[0],
|
|
2928
2938
|
endTime: windowTimeRef.current[1]
|
|
@@ -3021,7 +3031,7 @@ var Timeline = forwardRef3(
|
|
|
3021
3031
|
),
|
|
3022
3032
|
[eventPromptTemplate]
|
|
3023
3033
|
);
|
|
3024
|
-
return /* @__PURE__ */ React6.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ React6.createElement(rt_indicator_default, { tick, windowTime }), /* @__PURE__ */ React6.createElement(
|
|
3034
|
+
return /* @__PURE__ */ React6.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ React6.createElement(rt_indicator_default, { tick, windowTime }), showTimeBar && /* @__PURE__ */ React6.createElement(
|
|
3025
3035
|
canvas_time_bar_default,
|
|
3026
3036
|
{
|
|
3027
3037
|
windowTime,
|