awesome-timeline-react 0.1.13 → 0.1.14
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 +53 -33
- package/dist/_tsup-dts-rollup.d.ts +53 -33
- package/dist/index.css +4 -0
- package/dist/index.css.map +1 -1
- package/dist/index.js +120 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +121 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -49,7 +49,7 @@ __export(src_exports, {
|
|
|
49
49
|
module.exports = __toCommonJS(src_exports);
|
|
50
50
|
|
|
51
51
|
// src/timeline.tsx
|
|
52
|
-
var
|
|
52
|
+
var import_react23 = __toESM(require("react"));
|
|
53
53
|
|
|
54
54
|
// src/components/time-bar.tsx
|
|
55
55
|
var import_react4 = __toESM(require("react"));
|
|
@@ -1180,13 +1180,6 @@ var RowContent = (0, import_react13.forwardRef)((props, ref) => {
|
|
|
1180
1180
|
"data-index": id,
|
|
1181
1181
|
style: {
|
|
1182
1182
|
minHeight
|
|
1183
|
-
// background: `linear-gradient(to left, white, white 1px, transparent 0, transparent 100%), repeating-linear-gradient(
|
|
1184
|
-
// to left,
|
|
1185
|
-
// #aaaaaa,
|
|
1186
|
-
// #aaaaaa 1px,
|
|
1187
|
-
// transparent 0px,
|
|
1188
|
-
// transparent ${cellWidth}px
|
|
1189
|
-
// )`,
|
|
1190
1183
|
}
|
|
1191
1184
|
},
|
|
1192
1185
|
children
|
|
@@ -1206,24 +1199,29 @@ var resize_icon_default = ResizeIcon;
|
|
|
1206
1199
|
|
|
1207
1200
|
// src/components/event.tsx
|
|
1208
1201
|
var Event = ({
|
|
1209
|
-
|
|
1202
|
+
eventData,
|
|
1210
1203
|
startPosition,
|
|
1211
1204
|
width,
|
|
1212
1205
|
top,
|
|
1213
|
-
props,
|
|
1214
1206
|
setEvents,
|
|
1215
1207
|
tick
|
|
1216
1208
|
}) => {
|
|
1209
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1217
1210
|
const { setDragStarted } = (0, import_react15.useContext)(DragStartedContext);
|
|
1218
|
-
const { onResize, eventsResize } = (0, import_react15.useContext)(
|
|
1211
|
+
const { onResize, eventsResize, eventPromptRef } = (0, import_react15.useContext)(
|
|
1212
|
+
ExternalPropertiesContext
|
|
1213
|
+
);
|
|
1219
1214
|
const initialPositionForResizeRef = (0, import_react15.useRef)(0);
|
|
1220
1215
|
const handleOnDragStart = (0, import_react15.useCallback)(
|
|
1221
1216
|
(event) => {
|
|
1222
1217
|
event.stopPropagation();
|
|
1223
|
-
event.dataTransfer.setData("eventId", id);
|
|
1218
|
+
event.dataTransfer.setData("eventId", eventData.id);
|
|
1224
1219
|
setTimeout(() => setDragStarted(true), 0);
|
|
1225
1220
|
const target = event.target;
|
|
1226
1221
|
target.style.opacity = "50%";
|
|
1222
|
+
if (eventPromptRef == null ? void 0 : eventPromptRef.current) {
|
|
1223
|
+
eventPromptRef.current.setDisplay("none");
|
|
1224
|
+
}
|
|
1227
1225
|
},
|
|
1228
1226
|
[setDragStarted]
|
|
1229
1227
|
);
|
|
@@ -1236,7 +1234,7 @@ var Event = ({
|
|
|
1236
1234
|
},
|
|
1237
1235
|
[setDragStarted]
|
|
1238
1236
|
);
|
|
1239
|
-
const classNames = (props == null ? void 0 :
|
|
1237
|
+
const classNames = ((_a = eventData.props) == null ? void 0 : _a.classNames) ? "event " + eventData.props.classNames.join(" ") : "event";
|
|
1240
1238
|
const [draggableEvent, setDraggableEvent] = (0, import_react15.useState)(true);
|
|
1241
1239
|
const [resizeOffset, setResizeOffset] = (0, import_react15.useState)(0);
|
|
1242
1240
|
const resizeOffsetRef = (0, import_react15.useRef)(0);
|
|
@@ -1265,7 +1263,7 @@ var Event = ({
|
|
|
1265
1263
|
}
|
|
1266
1264
|
setEvents(
|
|
1267
1265
|
produce((draft) => {
|
|
1268
|
-
const event2 = draft.find((event3) => event3.id === id);
|
|
1266
|
+
const event2 = draft.find((event3) => event3.id === eventData.id);
|
|
1269
1267
|
if (event2 && tick) {
|
|
1270
1268
|
if (resizeDirection === "left") {
|
|
1271
1269
|
const newStartTime = Math.round(
|
|
@@ -1331,26 +1329,52 @@ var Event = ({
|
|
|
1331
1329
|
},
|
|
1332
1330
|
[resizeStarted]
|
|
1333
1331
|
);
|
|
1332
|
+
const handleOnMouseOver = (0, import_react15.useCallback)(
|
|
1333
|
+
(event) => {
|
|
1334
|
+
var _a2, _b2;
|
|
1335
|
+
event.stopPropagation();
|
|
1336
|
+
if (((_a2 = eventData.props) == null ? void 0 : _a2.showPrompt) || ((_b2 = eventData.props) == null ? void 0 : _b2.showPrompt) === void 0) {
|
|
1337
|
+
const target = event.target;
|
|
1338
|
+
if (eventPromptRef == null ? void 0 : eventPromptRef.current) {
|
|
1339
|
+
eventPromptRef.current.setDisplay("block");
|
|
1340
|
+
eventPromptRef.current.setRight(
|
|
1341
|
+
`calc(100% - ${target.getBoundingClientRect().left}px + 60px)`
|
|
1342
|
+
);
|
|
1343
|
+
eventPromptRef.current.setBottom(
|
|
1344
|
+
`calc(100% - ${target.getBoundingClientRect().top}px + 60px)`
|
|
1345
|
+
);
|
|
1346
|
+
eventPromptRef.current.setEvent(eventData);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
},
|
|
1350
|
+
[eventData]
|
|
1351
|
+
);
|
|
1352
|
+
const handleOnMouseOut = (0, import_react15.useCallback)(() => {
|
|
1353
|
+
if (eventPromptRef == null ? void 0 : eventPromptRef.current) {
|
|
1354
|
+
eventPromptRef.current.setDisplay("none");
|
|
1355
|
+
}
|
|
1356
|
+
}, []);
|
|
1334
1357
|
return /* @__PURE__ */ import_react15.default.createElement(
|
|
1335
1358
|
"div",
|
|
1336
1359
|
{
|
|
1337
|
-
id: `event_${id}`,
|
|
1338
|
-
key: `event_${id}`,
|
|
1360
|
+
id: `event_${eventData.id}`,
|
|
1361
|
+
key: `event_${eventData.id}`,
|
|
1339
1362
|
className: classNames,
|
|
1340
|
-
draggable: (props == null ? void 0 :
|
|
1363
|
+
draggable: ((_b = eventData.props) == null ? void 0 : _b.isLocked) ? false : draggableEvent,
|
|
1341
1364
|
onDragStart: handleOnDragStart,
|
|
1342
1365
|
onDragEnd: handleOnDragEnd,
|
|
1343
1366
|
onMouseDown: (event) => event.stopPropagation(),
|
|
1344
1367
|
onMouseMove: handleOnMouseMove,
|
|
1368
|
+
onMouseOut: handleOnMouseOut,
|
|
1345
1369
|
onDrop: (event) => event.stopPropagation(),
|
|
1346
1370
|
style: {
|
|
1347
1371
|
left: resizeDirectionRef.current === "left" ? startPosition - resizeOffset : startPosition,
|
|
1348
1372
|
width: width + resizeOffset,
|
|
1349
1373
|
top,
|
|
1350
|
-
cursor: (props == null ? void 0 :
|
|
1374
|
+
cursor: ((_c = eventData.props) == null ? void 0 : _c.isLocked) ? "not-allowed" : "pointer"
|
|
1351
1375
|
}
|
|
1352
1376
|
},
|
|
1353
|
-
!(props == null ? void 0 :
|
|
1377
|
+
!((_d = eventData.props) == null ? void 0 : _d.isLocked) && (eventsResize && (((_e = eventData.props) == null ? void 0 : _e.isResizable) === true || ((_f = eventData.props) == null ? void 0 : _f.isResizable) === void 0) || !eventsResize && ((_g = eventData.props) == null ? void 0 : _g.isResizable)) && /* @__PURE__ */ import_react15.default.createElement(
|
|
1354
1378
|
"div",
|
|
1355
1379
|
{
|
|
1356
1380
|
className: "event-resize",
|
|
@@ -1358,12 +1382,13 @@ var Event = ({
|
|
|
1358
1382
|
draggable: false,
|
|
1359
1383
|
onMouseEnter: () => setDraggableEvent(false),
|
|
1360
1384
|
onMouseLeave: () => setDraggableEvent(true),
|
|
1361
|
-
onMouseDown: (event) => handleOnMouseDownEventResizer(event, "left")
|
|
1385
|
+
onMouseDown: (event) => handleOnMouseDownEventResizer(event, "left"),
|
|
1386
|
+
onMouseOver: (event) => event.stopPropagation()
|
|
1362
1387
|
},
|
|
1363
1388
|
/* @__PURE__ */ import_react15.default.createElement(resize_icon_default, null)
|
|
1364
1389
|
),
|
|
1365
|
-
/* @__PURE__ */ import_react15.default.createElement("div", { className: "event-content" }, (props == null ? void 0 :
|
|
1366
|
-
!(props == null ? void 0 :
|
|
1390
|
+
/* @__PURE__ */ import_react15.default.createElement("div", { className: "event-content", onMouseOver: handleOnMouseOver }, ((_h = eventData.props) == null ? void 0 : _h.content) ? eventData.props.content : null),
|
|
1391
|
+
!((_i = eventData.props) == null ? void 0 : _i.isLocked) && (eventsResize && (((_j = eventData.props) == null ? void 0 : _j.isResizable) === true || ((_k = eventData.props) == null ? void 0 : _k.isResizable) === void 0) || !eventsResize && ((_l = eventData.props) == null ? void 0 : _l.isResizable)) && /* @__PURE__ */ import_react15.default.createElement(
|
|
1367
1392
|
"div",
|
|
1368
1393
|
{
|
|
1369
1394
|
className: "event-resize",
|
|
@@ -1371,7 +1396,8 @@ var Event = ({
|
|
|
1371
1396
|
draggable: false,
|
|
1372
1397
|
onMouseEnter: () => setDraggableEvent(false),
|
|
1373
1398
|
onMouseLeave: () => setDraggableEvent(true),
|
|
1374
|
-
onMouseDown: (event) => handleOnMouseDownEventResizer(event, "right")
|
|
1399
|
+
onMouseDown: (event) => handleOnMouseDownEventResizer(event, "right"),
|
|
1400
|
+
onMouseOver: (event) => event.stopPropagation()
|
|
1375
1401
|
},
|
|
1376
1402
|
/* @__PURE__ */ import_react15.default.createElement(resize_icon_default, null)
|
|
1377
1403
|
)
|
|
@@ -1453,11 +1479,10 @@ var useProduceContent = ({
|
|
|
1453
1479
|
event_default,
|
|
1454
1480
|
{
|
|
1455
1481
|
key: `event_${event.id}`,
|
|
1456
|
-
|
|
1482
|
+
eventData: event,
|
|
1457
1483
|
startPosition: (event.startTime - windowTime[0]) / tick,
|
|
1458
1484
|
width: (event.endTime - event.startTime) / tick,
|
|
1459
1485
|
top: 10 + 22 * tempEventOrder,
|
|
1460
|
-
props: event.props,
|
|
1461
1486
|
setEvents,
|
|
1462
1487
|
tick
|
|
1463
1488
|
}
|
|
@@ -1724,6 +1749,39 @@ var RTIndicator = ({
|
|
|
1724
1749
|
};
|
|
1725
1750
|
var rt_indicator_default = RTIndicator;
|
|
1726
1751
|
|
|
1752
|
+
// src/components/event-prompt.tsx
|
|
1753
|
+
var import_react22 = __toESM(require("react"));
|
|
1754
|
+
var EventPrompt = (0, import_react22.forwardRef)(
|
|
1755
|
+
({ template }, ref) => {
|
|
1756
|
+
const eventRef = (0, import_react22.useRef)(null);
|
|
1757
|
+
const [hoveredEvent, setHoveredEvent] = (0, import_react22.useState)();
|
|
1758
|
+
(0, import_react22.useImperativeHandle)(ref, () => {
|
|
1759
|
+
return {
|
|
1760
|
+
setDisplay(value) {
|
|
1761
|
+
if (eventRef.current) {
|
|
1762
|
+
eventRef.current.style.display = value;
|
|
1763
|
+
}
|
|
1764
|
+
},
|
|
1765
|
+
setRight(value) {
|
|
1766
|
+
if (eventRef.current) {
|
|
1767
|
+
eventRef.current.style.right = value;
|
|
1768
|
+
}
|
|
1769
|
+
},
|
|
1770
|
+
setBottom(value) {
|
|
1771
|
+
if (eventRef.current) {
|
|
1772
|
+
eventRef.current.style.bottom = value;
|
|
1773
|
+
}
|
|
1774
|
+
},
|
|
1775
|
+
setEvent(event) {
|
|
1776
|
+
setHoveredEvent(event);
|
|
1777
|
+
}
|
|
1778
|
+
};
|
|
1779
|
+
});
|
|
1780
|
+
return /* @__PURE__ */ import_react22.default.createElement("div", { className: "event-prompt", ref: eventRef }, template && hoveredEvent && template(hoveredEvent));
|
|
1781
|
+
}
|
|
1782
|
+
);
|
|
1783
|
+
var event_prompt_default = EventPrompt;
|
|
1784
|
+
|
|
1727
1785
|
// src/timeline.tsx
|
|
1728
1786
|
var Timeline = ({
|
|
1729
1787
|
rows,
|
|
@@ -1735,9 +1793,11 @@ var Timeline = ({
|
|
|
1735
1793
|
endDate,
|
|
1736
1794
|
additionalClassNames,
|
|
1737
1795
|
showRTIndicator = true,
|
|
1738
|
-
eventsResize = true
|
|
1796
|
+
eventsResize = true,
|
|
1797
|
+
eventPromptTemplate,
|
|
1798
|
+
showEventPrompt = true
|
|
1739
1799
|
}) => {
|
|
1740
|
-
const [windowTime, setWindowTime] = (0,
|
|
1800
|
+
const [windowTime, setWindowTime] = (0, import_react23.useState)([
|
|
1741
1801
|
new Date(
|
|
1742
1802
|
startDate.getFullYear(),
|
|
1743
1803
|
startDate.getMonth(),
|
|
@@ -1755,16 +1815,17 @@ var Timeline = ({
|
|
|
1755
1815
|
0
|
|
1756
1816
|
).getTime() / 1e3
|
|
1757
1817
|
]);
|
|
1758
|
-
const [cellWidth, setCellWidth] = (0,
|
|
1759
|
-
const [internalEvents, setInternalEvents] = (0,
|
|
1760
|
-
const contentRef = (0,
|
|
1761
|
-
const mainRef = (0,
|
|
1762
|
-
const bodyRef = (0,
|
|
1763
|
-
const [tick, setTick] = (0,
|
|
1764
|
-
const [scrollWidth, setScrollWidth] = (0,
|
|
1765
|
-
const [rowsHeight, setRowsHeight] = (0,
|
|
1766
|
-
const [allRowsHeight, setAllRowsHeight] = (0,
|
|
1767
|
-
(0,
|
|
1818
|
+
const [cellWidth, setCellWidth] = (0, import_react23.useState)(0);
|
|
1819
|
+
const [internalEvents, setInternalEvents] = (0, import_react23.useState)([]);
|
|
1820
|
+
const contentRef = (0, import_react23.useRef)(null);
|
|
1821
|
+
const mainRef = (0, import_react23.useRef)(null);
|
|
1822
|
+
const bodyRef = (0, import_react23.useRef)(null);
|
|
1823
|
+
const [tick, setTick] = (0, import_react23.useState)(null);
|
|
1824
|
+
const [scrollWidth, setScrollWidth] = (0, import_react23.useState)(0);
|
|
1825
|
+
const [rowsHeight, setRowsHeight] = (0, import_react23.useState)(null);
|
|
1826
|
+
const [allRowsHeight, setAllRowsHeight] = (0, import_react23.useState)(0);
|
|
1827
|
+
const eventPromptRef = (0, import_react23.useRef)(null);
|
|
1828
|
+
(0, import_react23.useEffect)(() => {
|
|
1768
1829
|
if (contentRef.current) {
|
|
1769
1830
|
const windowDuration = windowTime[1] - windowTime[0];
|
|
1770
1831
|
const numberOfHourBlocks = windowDuration / 3600;
|
|
@@ -1776,18 +1837,18 @@ var Timeline = ({
|
|
|
1776
1837
|
);
|
|
1777
1838
|
}
|
|
1778
1839
|
}, []);
|
|
1779
|
-
(0,
|
|
1840
|
+
(0, import_react23.useEffect)(() => {
|
|
1780
1841
|
if (bodyRef.current) {
|
|
1781
1842
|
setScrollWidth(
|
|
1782
1843
|
bodyRef.current.getBoundingClientRect().width - bodyRef.current.scrollWidth
|
|
1783
1844
|
);
|
|
1784
1845
|
}
|
|
1785
1846
|
}, []);
|
|
1786
|
-
(0,
|
|
1847
|
+
(0, import_react23.useEffect)(() => {
|
|
1787
1848
|
setInternalEvents(events.sort(sort_events_default));
|
|
1788
1849
|
}, [events]);
|
|
1789
|
-
const [dragStarted, setDragStarted] = (0,
|
|
1790
|
-
(0,
|
|
1850
|
+
const [dragStarted, setDragStarted] = (0, import_react23.useState)(false);
|
|
1851
|
+
(0, import_react23.useEffect)(() => {
|
|
1791
1852
|
let tempRowsHeight = null;
|
|
1792
1853
|
rows.forEach((row) => {
|
|
1793
1854
|
if (tempRowsHeight === null) {
|
|
@@ -1799,7 +1860,17 @@ var Timeline = ({
|
|
|
1799
1860
|
setRowsHeight(tempRowsHeight);
|
|
1800
1861
|
}, [rows]);
|
|
1801
1862
|
use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTime });
|
|
1802
|
-
|
|
1863
|
+
const eventPrompt = (0, import_react23.useMemo)(
|
|
1864
|
+
() => /* @__PURE__ */ import_react23.default.createElement(
|
|
1865
|
+
event_prompt_default,
|
|
1866
|
+
{
|
|
1867
|
+
ref: eventPromptRef,
|
|
1868
|
+
template: eventPromptTemplate
|
|
1869
|
+
}
|
|
1870
|
+
),
|
|
1871
|
+
[eventPromptTemplate]
|
|
1872
|
+
);
|
|
1873
|
+
return /* @__PURE__ */ import_react23.default.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ import_react23.default.createElement(rt_indicator_default, { tick, windowTime }), /* @__PURE__ */ import_react23.default.createElement(
|
|
1803
1874
|
time_bar_default,
|
|
1804
1875
|
{
|
|
1805
1876
|
windowTime,
|
|
@@ -1807,24 +1878,24 @@ var Timeline = ({
|
|
|
1807
1878
|
contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
|
|
1808
1879
|
scrollWidth
|
|
1809
1880
|
}
|
|
1810
|
-
), /* @__PURE__ */
|
|
1881
|
+
), /* @__PURE__ */ import_react23.default.createElement("div", { className: "body-wrapper", ref: bodyRef }, /* @__PURE__ */ import_react23.default.createElement(
|
|
1811
1882
|
RowsHeightContext.Provider,
|
|
1812
1883
|
{
|
|
1813
1884
|
value: { rowsHeight, setRowsHeight, allRowsHeight, setAllRowsHeight }
|
|
1814
1885
|
},
|
|
1815
|
-
/* @__PURE__ */
|
|
1886
|
+
/* @__PURE__ */ import_react23.default.createElement(
|
|
1816
1887
|
rows_header_default,
|
|
1817
1888
|
{
|
|
1818
1889
|
rows,
|
|
1819
1890
|
className: additionalClassNames == null ? void 0 : additionalClassNames.rowsHeader
|
|
1820
1891
|
}
|
|
1821
1892
|
),
|
|
1822
|
-
/* @__PURE__ */
|
|
1893
|
+
/* @__PURE__ */ import_react23.default.createElement(DragStartedContext.Provider, { value: { dragStarted, setDragStarted } }, /* @__PURE__ */ import_react23.default.createElement(
|
|
1823
1894
|
ExternalPropertiesContext.Provider,
|
|
1824
1895
|
{
|
|
1825
|
-
value: { onDrop, onResize, eventsResize }
|
|
1896
|
+
value: { onDrop, onResize, eventsResize, eventPromptRef }
|
|
1826
1897
|
},
|
|
1827
|
-
/* @__PURE__ */
|
|
1898
|
+
/* @__PURE__ */ import_react23.default.createElement(
|
|
1828
1899
|
content_default,
|
|
1829
1900
|
{
|
|
1830
1901
|
events: internalEvents,
|
|
@@ -1841,7 +1912,8 @@ var Timeline = ({
|
|
|
1841
1912
|
bodyRef,
|
|
1842
1913
|
lineClassName: additionalClassNames == null ? void 0 : additionalClassNames.gridLine
|
|
1843
1914
|
}
|
|
1844
|
-
)
|
|
1915
|
+
),
|
|
1916
|
+
showEventPrompt && eventPrompt
|
|
1845
1917
|
))
|
|
1846
1918
|
)));
|
|
1847
1919
|
};
|