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.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,12 +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
|
|
1041
|
+
const lanes = scene.getLanes(rowId);
|
|
1042
|
+
const inset = scene.getLaneInset(rowId);
|
|
1046
1043
|
const rowStatics = cullToWindow(
|
|
1047
1044
|
scene.getRowStaticEvents(rowId),
|
|
1048
1045
|
windowStart,
|
|
@@ -1051,11 +1048,11 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
1051
1048
|
for (const event of rowStatics) {
|
|
1052
1049
|
const x = timeToX(event.startTime, windowStart, tick);
|
|
1053
1050
|
const width = timeToWidth(event.startTime, event.endTime, tick);
|
|
1054
|
-
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;
|
|
1055
1052
|
roundedRect(
|
|
1056
1053
|
ctx,
|
|
1057
1054
|
x,
|
|
1058
|
-
rowY + geometry.laneTopOffset,
|
|
1055
|
+
rowY + inset + geometry.laneTopOffset,
|
|
1059
1056
|
width,
|
|
1060
1057
|
staticEventHeight(lanes.highestLane, geometry),
|
|
1061
1058
|
geometry.barRadius
|
|
@@ -1071,7 +1068,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
1071
1068
|
let width = timeToWidth(event.startTime, event.endTime, tick);
|
|
1072
1069
|
const y = rowY + animator.eventTop(
|
|
1073
1070
|
event.id,
|
|
1074
|
-
laneTop(lanes.laneOf.get(event.id), geometry)
|
|
1071
|
+
inset + laneTop(lanes.laneOf.get(event.id), geometry)
|
|
1075
1072
|
);
|
|
1076
1073
|
const resize = view.resizePreview;
|
|
1077
1074
|
const resizing = resize !== null && resize.eventId === event.id;
|
|
@@ -1222,7 +1219,7 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1222
1219
|
let rowTop = 0;
|
|
1223
1220
|
let rowId = null;
|
|
1224
1221
|
for (const id of scene.getVisibleRowIds()) {
|
|
1225
|
-
const height = scene.getRowHeight(id
|
|
1222
|
+
const height = scene.getRowHeight(id);
|
|
1226
1223
|
if (yContent >= rowTop && yContent < rowTop + height) {
|
|
1227
1224
|
rowId = id;
|
|
1228
1225
|
break;
|
|
@@ -1230,8 +1227,8 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1230
1227
|
rowTop += height;
|
|
1231
1228
|
}
|
|
1232
1229
|
if (rowId === null) return null;
|
|
1233
|
-
const lanes = scene.getLanes(rowId
|
|
1234
|
-
const
|
|
1230
|
+
const lanes = scene.getLanes(rowId);
|
|
1231
|
+
const lanesY = rowTop - scrollTop + scene.getLaneInset(rowId);
|
|
1235
1232
|
const events = cullToWindow(
|
|
1236
1233
|
scene.getRowEvents(rowId),
|
|
1237
1234
|
windowStart,
|
|
@@ -1241,7 +1238,7 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1241
1238
|
const event = events[i];
|
|
1242
1239
|
const rect = {
|
|
1243
1240
|
x: timeToX(event.startTime, windowStart, tick),
|
|
1244
|
-
y:
|
|
1241
|
+
y: lanesY + laneTop(lanes.laneOf.get(event.id), geometry),
|
|
1245
1242
|
width: timeToWidth(event.startTime, event.endTime, tick),
|
|
1246
1243
|
height: geometry.barHeight
|
|
1247
1244
|
};
|
|
@@ -1258,7 +1255,7 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1258
1255
|
const event = statics[i];
|
|
1259
1256
|
const rect = {
|
|
1260
1257
|
x: timeToX(event.startTime, windowStart, tick),
|
|
1261
|
-
y:
|
|
1258
|
+
y: lanesY + geometry.laneTopOffset,
|
|
1262
1259
|
width: timeToWidth(event.startTime, event.endTime, tick),
|
|
1263
1260
|
height: staticEventHeight(lanes.highestLane, geometry)
|
|
1264
1261
|
};
|
|
@@ -1651,11 +1648,7 @@ var useCanvasInteractions = ({
|
|
|
1651
1648
|
const yContent = clientY - canvas.getBoundingClientRect().top + view.scrollTop;
|
|
1652
1649
|
let rowTop = 0;
|
|
1653
1650
|
for (const id of scene.getVisibleRowIds()) {
|
|
1654
|
-
const height = scene.getRowHeight(
|
|
1655
|
-
id,
|
|
1656
|
-
view.windowTime[0],
|
|
1657
|
-
view.windowTime[1]
|
|
1658
|
-
);
|
|
1651
|
+
const height = scene.getRowHeight(id);
|
|
1659
1652
|
if (yContent >= rowTop && yContent < rowTop + height) return id;
|
|
1660
1653
|
rowTop += height;
|
|
1661
1654
|
}
|
|
@@ -2192,10 +2185,7 @@ var CanvasBoard = (0, import_react6.forwardRef)(
|
|
|
2192
2185
|
selectedEventIds: new Set(getSelection())
|
|
2193
2186
|
});
|
|
2194
2187
|
}, [getSelection, rendererRef]);
|
|
2195
|
-
const { offsetOf, totalHeight } = scene.getRowOffsets(
|
|
2196
|
-
windowTime[0],
|
|
2197
|
-
windowTime[1]
|
|
2198
|
-
);
|
|
2188
|
+
const { offsetOf, totalHeight } = scene.getRowOffsets();
|
|
2199
2189
|
totalHeightRef.current = totalHeight;
|
|
2200
2190
|
(0, import_react6.useLayoutEffect)(() => {
|
|
2201
2191
|
measureViewport();
|
|
@@ -2212,7 +2202,7 @@ var CanvasBoard = (0, import_react6.forwardRef)(
|
|
|
2212
2202
|
if (scene.isRowHidden(row.id)) continue;
|
|
2213
2203
|
const top = offsetOf.get(row.id);
|
|
2214
2204
|
if (top === void 0) continue;
|
|
2215
|
-
const height = scene.getRowHeight(row.id
|
|
2205
|
+
const height = scene.getRowHeight(row.id);
|
|
2216
2206
|
if (top + height < scrollTop) continue;
|
|
2217
2207
|
if (top > scrollTop + viewportHeight) break;
|
|
2218
2208
|
const isParent = scene.isRowParent(row.id);
|
|
@@ -2419,9 +2409,7 @@ var SceneStore = class {
|
|
|
2419
2409
|
events: [],
|
|
2420
2410
|
staticEvents: [],
|
|
2421
2411
|
lanesDirty: true,
|
|
2422
|
-
lanes: null
|
|
2423
|
-
laneWindowStart: NaN,
|
|
2424
|
-
laneWindowEnd: NaN
|
|
2412
|
+
lanes: null
|
|
2425
2413
|
}
|
|
2426
2414
|
);
|
|
2427
2415
|
}
|
|
@@ -2603,14 +2591,15 @@ var SceneStore = class {
|
|
|
2603
2591
|
var _a, _b;
|
|
2604
2592
|
return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.staticEvents) != null ? _b : [];
|
|
2605
2593
|
}
|
|
2606
|
-
|
|
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) {
|
|
2607
2598
|
this.flushParentSpans(rowId);
|
|
2608
2599
|
const index = this.rowIndexes.get(rowId);
|
|
2609
2600
|
if (!index) return { laneOf: /* @__PURE__ */ new Map(), highestLane: 0 };
|
|
2610
|
-
if (index.lanesDirty || index.lanes === null
|
|
2611
|
-
index.lanes = assignLanes(index.events
|
|
2612
|
-
index.laneWindowStart = windowStart;
|
|
2613
|
-
index.laneWindowEnd = windowEnd;
|
|
2601
|
+
if (index.lanesDirty || index.lanes === null) {
|
|
2602
|
+
index.lanes = assignLanes(index.events);
|
|
2614
2603
|
index.lanesDirty = false;
|
|
2615
2604
|
}
|
|
2616
2605
|
return index.lanes;
|
|
@@ -2636,25 +2625,30 @@ var SceneStore = class {
|
|
|
2636
2625
|
this.labelMinHeights = heights;
|
|
2637
2626
|
this.bump();
|
|
2638
2627
|
}
|
|
2639
|
-
getRowHeight(rowId
|
|
2628
|
+
getRowHeight(rowId) {
|
|
2640
2629
|
var _a;
|
|
2641
|
-
const laneHeight = rowMinHeight(
|
|
2642
|
-
this.getLanes(rowId, windowStart, windowEnd).highestLane,
|
|
2643
|
-
this.geometry
|
|
2644
|
-
);
|
|
2630
|
+
const laneHeight = rowMinHeight(this.getLanes(rowId).highestLane, this.geometry);
|
|
2645
2631
|
const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
|
|
2646
2632
|
return Math.max(laneHeight, labelHeight);
|
|
2647
2633
|
}
|
|
2634
|
+
/** Extra top offset for a row's lanes: when a tall label grows the row past what its lanes need,
|
|
2635
|
+
* the lanes sit centred in it rather than hugging the top with the surplus all below. */
|
|
2636
|
+
getLaneInset(rowId) {
|
|
2637
|
+
var _a;
|
|
2638
|
+
const laneHeight = rowMinHeight(this.getLanes(rowId).highestLane, this.geometry);
|
|
2639
|
+
const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
|
|
2640
|
+
return labelHeight > laneHeight ? Math.floor((labelHeight - laneHeight) / 2) : 0;
|
|
2641
|
+
}
|
|
2648
2642
|
/**
|
|
2649
2643
|
* y offset of each row's top edge (content coordinates, before scroll) plus
|
|
2650
2644
|
* the total content height — drives both drawing and the scroll spacer.
|
|
2651
2645
|
*/
|
|
2652
|
-
getRowOffsets(
|
|
2646
|
+
getRowOffsets() {
|
|
2653
2647
|
const offsetOf = /* @__PURE__ */ new Map();
|
|
2654
2648
|
let y = 0;
|
|
2655
2649
|
for (const rowId of this.getVisibleRowIds()) {
|
|
2656
2650
|
offsetOf.set(rowId, y);
|
|
2657
|
-
y += this.getRowHeight(rowId
|
|
2651
|
+
y += this.getRowHeight(rowId);
|
|
2658
2652
|
}
|
|
2659
2653
|
return { offsetOf, totalHeight: y };
|
|
2660
2654
|
}
|
|
@@ -2814,6 +2808,7 @@ var Timeline = (0, import_react7.forwardRef)(
|
|
|
2814
2808
|
selectable = false,
|
|
2815
2809
|
defaultSelectedEventIds,
|
|
2816
2810
|
onSelectionChange,
|
|
2811
|
+
onWindowChange,
|
|
2817
2812
|
defaultCollapsedRowIds,
|
|
2818
2813
|
startDate,
|
|
2819
2814
|
endDate,
|
|
@@ -2828,6 +2823,7 @@ var Timeline = (0, import_react7.forwardRef)(
|
|
|
2828
2823
|
showEventPrompt = true,
|
|
2829
2824
|
panZoom,
|
|
2830
2825
|
timeBar,
|
|
2826
|
+
showTimeBar = true,
|
|
2831
2827
|
animations = true
|
|
2832
2828
|
}, handleRef) => {
|
|
2833
2829
|
const [windowTime, setWindowTime] = (0, import_react7.useState)([
|
|
@@ -2918,6 +2914,12 @@ var Timeline = (0, import_react7.forwardRef)(
|
|
|
2918
2914
|
}, [scene, defaultCollapsedRowIds]);
|
|
2919
2915
|
const windowTimeRef = (0, import_react7.useRef)(windowTime);
|
|
2920
2916
|
windowTimeRef.current = windowTime;
|
|
2917
|
+
const onWindowChangeRef = (0, import_react7.useRef)(onWindowChange);
|
|
2918
|
+
onWindowChangeRef.current = onWindowChange;
|
|
2919
|
+
(0, import_react7.useEffect)(() => {
|
|
2920
|
+
var _a;
|
|
2921
|
+
(_a = onWindowChangeRef.current) == null ? void 0 : _a.call(onWindowChangeRef, { startTime: windowTime[0], endTime: windowTime[1] });
|
|
2922
|
+
}, [windowTime[0], windowTime[1]]);
|
|
2921
2923
|
(0, import_react7.useImperativeHandle)(
|
|
2922
2924
|
handleRef,
|
|
2923
2925
|
() => ({
|
|
@@ -2925,8 +2927,7 @@ var Timeline = (0, import_react7.forwardRef)(
|
|
|
2925
2927
|
updateEvents: (patches) => scene.applyPatches(patches),
|
|
2926
2928
|
getEvent: (id) => scene.getEvent(id),
|
|
2927
2929
|
scrollToRow: (rowId) => {
|
|
2928
|
-
const
|
|
2929
|
-
const offset2 = scene.getRowOffsets(windowStart, windowEnd).offsetOf.get(rowId);
|
|
2930
|
+
const offset2 = scene.getRowOffsets().offsetOf.get(rowId);
|
|
2930
2931
|
if (offset2 !== void 0 && bodyRef.current) {
|
|
2931
2932
|
bodyRef.current.scrollTop = offset2;
|
|
2932
2933
|
}
|
|
@@ -2934,7 +2935,16 @@ var Timeline = (0, import_react7.forwardRef)(
|
|
|
2934
2935
|
scrollToTime: (time) => {
|
|
2935
2936
|
setWindowTime((prev) => [time, time + (prev[1] - prev[0])]);
|
|
2936
2937
|
},
|
|
2937
|
-
|
|
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
|
+
},
|
|
2938
2948
|
getVisibleRange: () => ({
|
|
2939
2949
|
startTime: windowTimeRef.current[0],
|
|
2940
2950
|
endTime: windowTimeRef.current[1]
|
|
@@ -3033,7 +3043,7 @@ var Timeline = (0, import_react7.forwardRef)(
|
|
|
3033
3043
|
),
|
|
3034
3044
|
[eventPromptTemplate]
|
|
3035
3045
|
);
|
|
3036
|
-
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(
|
|
3037
3047
|
canvas_time_bar_default,
|
|
3038
3048
|
{
|
|
3039
3049
|
windowTime,
|