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.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,13 +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
|
|
1034
|
-
const inset = scene.getLaneInset(rowId
|
|
1029
|
+
const lanes = scene.getLanes(rowId);
|
|
1030
|
+
const inset = scene.getLaneInset(rowId);
|
|
1035
1031
|
const rowStatics = cullToWindow(
|
|
1036
1032
|
scene.getRowStaticEvents(rowId),
|
|
1037
1033
|
windowStart,
|
|
@@ -1040,7 +1036,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
1040
1036
|
for (const event of rowStatics) {
|
|
1041
1037
|
const x = timeToX(event.startTime, windowStart, tick);
|
|
1042
1038
|
const width = timeToWidth(event.startTime, event.endTime, tick);
|
|
1043
|
-
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;
|
|
1044
1040
|
roundedRect(
|
|
1045
1041
|
ctx,
|
|
1046
1042
|
x,
|
|
@@ -1211,7 +1207,7 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1211
1207
|
let rowTop = 0;
|
|
1212
1208
|
let rowId = null;
|
|
1213
1209
|
for (const id of scene.getVisibleRowIds()) {
|
|
1214
|
-
const height = scene.getRowHeight(id
|
|
1210
|
+
const height = scene.getRowHeight(id);
|
|
1215
1211
|
if (yContent >= rowTop && yContent < rowTop + height) {
|
|
1216
1212
|
rowId = id;
|
|
1217
1213
|
break;
|
|
@@ -1219,8 +1215,8 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1219
1215
|
rowTop += height;
|
|
1220
1216
|
}
|
|
1221
1217
|
if (rowId === null) return null;
|
|
1222
|
-
const lanes = scene.getLanes(rowId
|
|
1223
|
-
const lanesY = rowTop - scrollTop + scene.getLaneInset(rowId
|
|
1218
|
+
const lanes = scene.getLanes(rowId);
|
|
1219
|
+
const lanesY = rowTop - scrollTop + scene.getLaneInset(rowId);
|
|
1224
1220
|
const events = cullToWindow(
|
|
1225
1221
|
scene.getRowEvents(rowId),
|
|
1226
1222
|
windowStart,
|
|
@@ -1640,11 +1636,7 @@ var useCanvasInteractions = ({
|
|
|
1640
1636
|
const yContent = clientY - canvas.getBoundingClientRect().top + view.scrollTop;
|
|
1641
1637
|
let rowTop = 0;
|
|
1642
1638
|
for (const id of scene.getVisibleRowIds()) {
|
|
1643
|
-
const height = scene.getRowHeight(
|
|
1644
|
-
id,
|
|
1645
|
-
view.windowTime[0],
|
|
1646
|
-
view.windowTime[1]
|
|
1647
|
-
);
|
|
1639
|
+
const height = scene.getRowHeight(id);
|
|
1648
1640
|
if (yContent >= rowTop && yContent < rowTop + height) return id;
|
|
1649
1641
|
rowTop += height;
|
|
1650
1642
|
}
|
|
@@ -2181,10 +2173,7 @@ var CanvasBoard = forwardRef2(
|
|
|
2181
2173
|
selectedEventIds: new Set(getSelection())
|
|
2182
2174
|
});
|
|
2183
2175
|
}, [getSelection, rendererRef]);
|
|
2184
|
-
const { offsetOf, totalHeight } = scene.getRowOffsets(
|
|
2185
|
-
windowTime[0],
|
|
2186
|
-
windowTime[1]
|
|
2187
|
-
);
|
|
2176
|
+
const { offsetOf, totalHeight } = scene.getRowOffsets();
|
|
2188
2177
|
totalHeightRef.current = totalHeight;
|
|
2189
2178
|
useLayoutEffect(() => {
|
|
2190
2179
|
measureViewport();
|
|
@@ -2201,7 +2190,7 @@ var CanvasBoard = forwardRef2(
|
|
|
2201
2190
|
if (scene.isRowHidden(row.id)) continue;
|
|
2202
2191
|
const top = offsetOf.get(row.id);
|
|
2203
2192
|
if (top === void 0) continue;
|
|
2204
|
-
const height = scene.getRowHeight(row.id
|
|
2193
|
+
const height = scene.getRowHeight(row.id);
|
|
2205
2194
|
if (top + height < scrollTop) continue;
|
|
2206
2195
|
if (top > scrollTop + viewportHeight) break;
|
|
2207
2196
|
const isParent = scene.isRowParent(row.id);
|
|
@@ -2408,9 +2397,7 @@ var SceneStore = class {
|
|
|
2408
2397
|
events: [],
|
|
2409
2398
|
staticEvents: [],
|
|
2410
2399
|
lanesDirty: true,
|
|
2411
|
-
lanes: null
|
|
2412
|
-
laneWindowStart: NaN,
|
|
2413
|
-
laneWindowEnd: NaN
|
|
2400
|
+
lanes: null
|
|
2414
2401
|
}
|
|
2415
2402
|
);
|
|
2416
2403
|
}
|
|
@@ -2592,14 +2579,15 @@ var SceneStore = class {
|
|
|
2592
2579
|
var _a, _b;
|
|
2593
2580
|
return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.staticEvents) != null ? _b : [];
|
|
2594
2581
|
}
|
|
2595
|
-
|
|
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) {
|
|
2596
2586
|
this.flushParentSpans(rowId);
|
|
2597
2587
|
const index = this.rowIndexes.get(rowId);
|
|
2598
2588
|
if (!index) return { laneOf: /* @__PURE__ */ new Map(), highestLane: 0 };
|
|
2599
|
-
if (index.lanesDirty || index.lanes === null
|
|
2600
|
-
index.lanes = assignLanes(index.events
|
|
2601
|
-
index.laneWindowStart = windowStart;
|
|
2602
|
-
index.laneWindowEnd = windowEnd;
|
|
2589
|
+
if (index.lanesDirty || index.lanes === null) {
|
|
2590
|
+
index.lanes = assignLanes(index.events);
|
|
2603
2591
|
index.lanesDirty = false;
|
|
2604
2592
|
}
|
|
2605
2593
|
return index.lanes;
|
|
@@ -2625,23 +2613,17 @@ var SceneStore = class {
|
|
|
2625
2613
|
this.labelMinHeights = heights;
|
|
2626
2614
|
this.bump();
|
|
2627
2615
|
}
|
|
2628
|
-
getRowHeight(rowId
|
|
2616
|
+
getRowHeight(rowId) {
|
|
2629
2617
|
var _a;
|
|
2630
|
-
const laneHeight = rowMinHeight(
|
|
2631
|
-
this.getLanes(rowId, windowStart, windowEnd).highestLane,
|
|
2632
|
-
this.geometry
|
|
2633
|
-
);
|
|
2618
|
+
const laneHeight = rowMinHeight(this.getLanes(rowId).highestLane, this.geometry);
|
|
2634
2619
|
const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
|
|
2635
2620
|
return Math.max(laneHeight, labelHeight);
|
|
2636
2621
|
}
|
|
2637
2622
|
/** Extra top offset for a row's lanes: when a tall label grows the row past what its lanes need,
|
|
2638
2623
|
* the lanes sit centred in it rather than hugging the top with the surplus all below. */
|
|
2639
|
-
getLaneInset(rowId
|
|
2624
|
+
getLaneInset(rowId) {
|
|
2640
2625
|
var _a;
|
|
2641
|
-
const laneHeight = rowMinHeight(
|
|
2642
|
-
this.getLanes(rowId, windowStart, windowEnd).highestLane,
|
|
2643
|
-
this.geometry
|
|
2644
|
-
);
|
|
2626
|
+
const laneHeight = rowMinHeight(this.getLanes(rowId).highestLane, this.geometry);
|
|
2645
2627
|
const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
|
|
2646
2628
|
return labelHeight > laneHeight ? Math.floor((labelHeight - laneHeight) / 2) : 0;
|
|
2647
2629
|
}
|
|
@@ -2649,12 +2631,12 @@ var SceneStore = class {
|
|
|
2649
2631
|
* y offset of each row's top edge (content coordinates, before scroll) plus
|
|
2650
2632
|
* the total content height — drives both drawing and the scroll spacer.
|
|
2651
2633
|
*/
|
|
2652
|
-
getRowOffsets(
|
|
2634
|
+
getRowOffsets() {
|
|
2653
2635
|
const offsetOf = /* @__PURE__ */ new Map();
|
|
2654
2636
|
let y = 0;
|
|
2655
2637
|
for (const rowId of this.getVisibleRowIds()) {
|
|
2656
2638
|
offsetOf.set(rowId, y);
|
|
2657
|
-
y += this.getRowHeight(rowId
|
|
2639
|
+
y += this.getRowHeight(rowId);
|
|
2658
2640
|
}
|
|
2659
2641
|
return { offsetOf, totalHeight: y };
|
|
2660
2642
|
}
|
|
@@ -2829,6 +2811,7 @@ var Timeline = forwardRef3(
|
|
|
2829
2811
|
showEventPrompt = true,
|
|
2830
2812
|
panZoom,
|
|
2831
2813
|
timeBar,
|
|
2814
|
+
showTimeBar = true,
|
|
2832
2815
|
animations = true
|
|
2833
2816
|
}, handleRef) => {
|
|
2834
2817
|
const [windowTime, setWindowTime] = useState4([
|
|
@@ -2932,8 +2915,7 @@ var Timeline = forwardRef3(
|
|
|
2932
2915
|
updateEvents: (patches) => scene.applyPatches(patches),
|
|
2933
2916
|
getEvent: (id) => scene.getEvent(id),
|
|
2934
2917
|
scrollToRow: (rowId) => {
|
|
2935
|
-
const
|
|
2936
|
-
const offset2 = scene.getRowOffsets(windowStart, windowEnd).offsetOf.get(rowId);
|
|
2918
|
+
const offset2 = scene.getRowOffsets().offsetOf.get(rowId);
|
|
2937
2919
|
if (offset2 !== void 0 && bodyRef.current) {
|
|
2938
2920
|
bodyRef.current.scrollTop = offset2;
|
|
2939
2921
|
}
|
|
@@ -2941,7 +2923,16 @@ var Timeline = forwardRef3(
|
|
|
2941
2923
|
scrollToTime: (time) => {
|
|
2942
2924
|
setWindowTime((prev) => [time, time + (prev[1] - prev[0])]);
|
|
2943
2925
|
},
|
|
2944
|
-
|
|
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
|
+
},
|
|
2945
2936
|
getVisibleRange: () => ({
|
|
2946
2937
|
startTime: windowTimeRef.current[0],
|
|
2947
2938
|
endTime: windowTimeRef.current[1]
|
|
@@ -3040,7 +3031,7 @@ var Timeline = forwardRef3(
|
|
|
3040
3031
|
),
|
|
3041
3032
|
[eventPromptTemplate]
|
|
3042
3033
|
);
|
|
3043
|
-
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(
|
|
3044
3035
|
canvas_time_bar_default,
|
|
3045
3036
|
{
|
|
3046
3037
|
windowTime,
|