awesome-timeline-react 0.1.12 → 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/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 import_react22 = __toESM(require("react"));
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
- id,
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)(ExternalPropertiesContext);
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 : props.classNames) ? "event " + props.classNames.join(" ") : "event";
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,9 +1263,8 @@ 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
- console.log(resizeOffsetRef.current);
1271
1268
  if (resizeDirection === "left") {
1272
1269
  const newStartTime = Math.round(
1273
1270
  event2.startTime + resizeOffsetRef.current * tick
@@ -1332,26 +1329,52 @@ var Event = ({
1332
1329
  },
1333
1330
  [resizeStarted]
1334
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
+ }, []);
1335
1357
  return /* @__PURE__ */ import_react15.default.createElement(
1336
1358
  "div",
1337
1359
  {
1338
- id: `event_${id}`,
1339
- key: `event_${id}`,
1360
+ id: `event_${eventData.id}`,
1361
+ key: `event_${eventData.id}`,
1340
1362
  className: classNames,
1341
- draggable: (props == null ? void 0 : props.isLocked) ? false : draggableEvent,
1363
+ draggable: ((_b = eventData.props) == null ? void 0 : _b.isLocked) ? false : draggableEvent,
1342
1364
  onDragStart: handleOnDragStart,
1343
1365
  onDragEnd: handleOnDragEnd,
1344
1366
  onMouseDown: (event) => event.stopPropagation(),
1345
1367
  onMouseMove: handleOnMouseMove,
1368
+ onMouseOut: handleOnMouseOut,
1346
1369
  onDrop: (event) => event.stopPropagation(),
1347
1370
  style: {
1348
1371
  left: resizeDirectionRef.current === "left" ? startPosition - resizeOffset : startPosition,
1349
1372
  width: width + resizeOffset,
1350
1373
  top,
1351
- cursor: (props == null ? void 0 : props.isLocked) ? "not-allowed" : "pointer"
1374
+ cursor: ((_c = eventData.props) == null ? void 0 : _c.isLocked) ? "not-allowed" : "pointer"
1352
1375
  }
1353
1376
  },
1354
- !(props == null ? void 0 : props.isLocked) && (eventsResize && ((props == null ? void 0 : props.isResizable) === true || (props == null ? void 0 : props.isResizable) === void 0) || !eventsResize && (props == null ? void 0 : props.isResizable)) && /* @__PURE__ */ import_react15.default.createElement(
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(
1355
1378
  "div",
1356
1379
  {
1357
1380
  className: "event-resize",
@@ -1359,12 +1382,13 @@ var Event = ({
1359
1382
  draggable: false,
1360
1383
  onMouseEnter: () => setDraggableEvent(false),
1361
1384
  onMouseLeave: () => setDraggableEvent(true),
1362
- onMouseDown: (event) => handleOnMouseDownEventResizer(event, "left")
1385
+ onMouseDown: (event) => handleOnMouseDownEventResizer(event, "left"),
1386
+ onMouseOver: (event) => event.stopPropagation()
1363
1387
  },
1364
1388
  /* @__PURE__ */ import_react15.default.createElement(resize_icon_default, null)
1365
1389
  ),
1366
- /* @__PURE__ */ import_react15.default.createElement("div", { className: "event-content" }, (props == null ? void 0 : props.content) ? props.content : null),
1367
- !(props == null ? void 0 : props.isLocked) && (eventsResize && ((props == null ? void 0 : props.isResizable) === true || (props == null ? void 0 : props.isResizable) === void 0) || !eventsResize && (props == null ? void 0 : props.isResizable)) && /* @__PURE__ */ import_react15.default.createElement(
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(
1368
1392
  "div",
1369
1393
  {
1370
1394
  className: "event-resize",
@@ -1372,7 +1396,8 @@ var Event = ({
1372
1396
  draggable: false,
1373
1397
  onMouseEnter: () => setDraggableEvent(false),
1374
1398
  onMouseLeave: () => setDraggableEvent(true),
1375
- onMouseDown: (event) => handleOnMouseDownEventResizer(event, "right")
1399
+ onMouseDown: (event) => handleOnMouseDownEventResizer(event, "right"),
1400
+ onMouseOver: (event) => event.stopPropagation()
1376
1401
  },
1377
1402
  /* @__PURE__ */ import_react15.default.createElement(resize_icon_default, null)
1378
1403
  )
@@ -1454,11 +1479,10 @@ var useProduceContent = ({
1454
1479
  event_default,
1455
1480
  {
1456
1481
  key: `event_${event.id}`,
1457
- id: event.id,
1482
+ eventData: event,
1458
1483
  startPosition: (event.startTime - windowTime[0]) / tick,
1459
1484
  width: (event.endTime - event.startTime) / tick,
1460
1485
  top: 10 + 22 * tempEventOrder,
1461
- props: event.props,
1462
1486
  setEvents,
1463
1487
  tick
1464
1488
  }
@@ -1725,6 +1749,39 @@ var RTIndicator = ({
1725
1749
  };
1726
1750
  var rt_indicator_default = RTIndicator;
1727
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
+
1728
1785
  // src/timeline.tsx
1729
1786
  var Timeline = ({
1730
1787
  rows,
@@ -1736,9 +1793,11 @@ var Timeline = ({
1736
1793
  endDate,
1737
1794
  additionalClassNames,
1738
1795
  showRTIndicator = true,
1739
- eventsResize = true
1796
+ eventsResize = true,
1797
+ eventPromptTemplate,
1798
+ showEventPrompt = true
1740
1799
  }) => {
1741
- const [windowTime, setWindowTime] = (0, import_react22.useState)([
1800
+ const [windowTime, setWindowTime] = (0, import_react23.useState)([
1742
1801
  new Date(
1743
1802
  startDate.getFullYear(),
1744
1803
  startDate.getMonth(),
@@ -1756,16 +1815,17 @@ var Timeline = ({
1756
1815
  0
1757
1816
  ).getTime() / 1e3
1758
1817
  ]);
1759
- const [cellWidth, setCellWidth] = (0, import_react22.useState)(0);
1760
- const [internalEvents, setInternalEvents] = (0, import_react22.useState)([]);
1761
- const contentRef = (0, import_react22.useRef)(null);
1762
- const mainRef = (0, import_react22.useRef)(null);
1763
- const bodyRef = (0, import_react22.useRef)(null);
1764
- const [tick, setTick] = (0, import_react22.useState)(null);
1765
- const [scrollWidth, setScrollWidth] = (0, import_react22.useState)(0);
1766
- const [rowsHeight, setRowsHeight] = (0, import_react22.useState)(null);
1767
- const [allRowsHeight, setAllRowsHeight] = (0, import_react22.useState)(0);
1768
- (0, import_react22.useEffect)(() => {
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)(() => {
1769
1829
  if (contentRef.current) {
1770
1830
  const windowDuration = windowTime[1] - windowTime[0];
1771
1831
  const numberOfHourBlocks = windowDuration / 3600;
@@ -1777,18 +1837,18 @@ var Timeline = ({
1777
1837
  );
1778
1838
  }
1779
1839
  }, []);
1780
- (0, import_react22.useEffect)(() => {
1840
+ (0, import_react23.useEffect)(() => {
1781
1841
  if (bodyRef.current) {
1782
1842
  setScrollWidth(
1783
1843
  bodyRef.current.getBoundingClientRect().width - bodyRef.current.scrollWidth
1784
1844
  );
1785
1845
  }
1786
1846
  }, []);
1787
- (0, import_react22.useEffect)(() => {
1847
+ (0, import_react23.useEffect)(() => {
1788
1848
  setInternalEvents(events.sort(sort_events_default));
1789
1849
  }, [events]);
1790
- const [dragStarted, setDragStarted] = (0, import_react22.useState)(false);
1791
- (0, import_react22.useEffect)(() => {
1850
+ const [dragStarted, setDragStarted] = (0, import_react23.useState)(false);
1851
+ (0, import_react23.useEffect)(() => {
1792
1852
  let tempRowsHeight = null;
1793
1853
  rows.forEach((row) => {
1794
1854
  if (tempRowsHeight === null) {
@@ -1800,7 +1860,17 @@ var Timeline = ({
1800
1860
  setRowsHeight(tempRowsHeight);
1801
1861
  }, [rows]);
1802
1862
  use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTime });
1803
- return /* @__PURE__ */ import_react22.default.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ import_react22.default.createElement(rt_indicator_default, { tick, windowTime }), /* @__PURE__ */ import_react22.default.createElement(
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(
1804
1874
  time_bar_default,
1805
1875
  {
1806
1876
  windowTime,
@@ -1808,24 +1878,24 @@ var Timeline = ({
1808
1878
  contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
1809
1879
  scrollWidth
1810
1880
  }
1811
- ), /* @__PURE__ */ import_react22.default.createElement("div", { className: "body-wrapper", ref: bodyRef }, /* @__PURE__ */ import_react22.default.createElement(
1881
+ ), /* @__PURE__ */ import_react23.default.createElement("div", { className: "body-wrapper", ref: bodyRef }, /* @__PURE__ */ import_react23.default.createElement(
1812
1882
  RowsHeightContext.Provider,
1813
1883
  {
1814
1884
  value: { rowsHeight, setRowsHeight, allRowsHeight, setAllRowsHeight }
1815
1885
  },
1816
- /* @__PURE__ */ import_react22.default.createElement(
1886
+ /* @__PURE__ */ import_react23.default.createElement(
1817
1887
  rows_header_default,
1818
1888
  {
1819
1889
  rows,
1820
1890
  className: additionalClassNames == null ? void 0 : additionalClassNames.rowsHeader
1821
1891
  }
1822
1892
  ),
1823
- /* @__PURE__ */ import_react22.default.createElement(DragStartedContext.Provider, { value: { dragStarted, setDragStarted } }, /* @__PURE__ */ import_react22.default.createElement(
1893
+ /* @__PURE__ */ import_react23.default.createElement(DragStartedContext.Provider, { value: { dragStarted, setDragStarted } }, /* @__PURE__ */ import_react23.default.createElement(
1824
1894
  ExternalPropertiesContext.Provider,
1825
1895
  {
1826
- value: { onDrop, onResize, eventsResize }
1896
+ value: { onDrop, onResize, eventsResize, eventPromptRef }
1827
1897
  },
1828
- /* @__PURE__ */ import_react22.default.createElement(
1898
+ /* @__PURE__ */ import_react23.default.createElement(
1829
1899
  content_default,
1830
1900
  {
1831
1901
  events: internalEvents,
@@ -1842,7 +1912,8 @@ var Timeline = ({
1842
1912
  bodyRef,
1843
1913
  lineClassName: additionalClassNames == null ? void 0 : additionalClassNames.gridLine
1844
1914
  }
1845
- )
1915
+ ),
1916
+ showEventPrompt && eventPrompt
1846
1917
  ))
1847
1918
  )));
1848
1919
  };