gantt-lib 0.62.0 → 0.63.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/dist/index.mjs CHANGED
@@ -5342,7 +5342,8 @@ var TaskListRow = React9.memo(
5342
5342
  id: crypto.randomUUID(),
5343
5343
  name: "\u041D\u043E\u0432\u0430\u044F \u0437\u0430\u0434\u0430\u0447\u0430",
5344
5344
  startDate: todayISO,
5345
- endDate: endISO
5345
+ endDate: endISO,
5346
+ parentId: task.parentId
5346
5347
  };
5347
5348
  onInsertAfter(task.id, newTask);
5348
5349
  },
@@ -5910,10 +5911,17 @@ TaskListRow.displayName = "TaskListRow";
5910
5911
  // src/components/TaskList/NewTaskRow.tsx
5911
5912
  import { useState as useState5, useRef as useRef5, useEffect as useEffect5 } from "react";
5912
5913
  import { jsx as jsx13, jsxs as jsxs10 } from "react/jsx-runtime";
5913
- var NewTaskRow = ({ rowHeight, onConfirm, onCancel }) => {
5914
+ var NewTaskRow = ({
5915
+ rowHeight,
5916
+ onConfirm,
5917
+ onCancel,
5918
+ nestingDepth = 0
5919
+ }) => {
5914
5920
  const [nameValue, setNameValue] = useState5("");
5915
5921
  const inputRef = useRef5(null);
5916
5922
  const confirmedRef = useRef5(false);
5923
+ const inputInnerPadding = 4;
5924
+ const levelOffset = nestingDepth > 0 ? nestingDepth * 20 + 8 : 0;
5917
5925
  useEffect5(() => {
5918
5926
  if (inputRef.current) {
5919
5927
  inputRef.current.focus();
@@ -5952,7 +5960,12 @@ var NewTaskRow = ({ rowHeight, onConfirm, onCancel }) => {
5952
5960
  onKeyDown: handleKeyDown,
5953
5961
  onBlur: handleBlur,
5954
5962
  placeholder: "\u041D\u0430\u0437\u0432\u0430\u043D\u0438\u0435",
5955
- className: "gantt-tl-name-input"
5963
+ className: "gantt-tl-name-input",
5964
+ style: {
5965
+ left: `${Math.max(0, levelOffset - inputInnerPadding)}px`,
5966
+ width: levelOffset > 0 ? `calc(100% - ${Math.max(0, levelOffset - inputInnerPadding)}px)` : "100%",
5967
+ paddingLeft: `${inputInnerPadding}px`
5968
+ }
5956
5969
  }
5957
5970
  ) }),
5958
5971
  /* @__PURE__ */ jsx13("div", { className: "gantt-tl-cell" }),
@@ -6376,6 +6389,7 @@ var TaskList = ({
6376
6389
  onTasksChange?.([{ ...task, dependencies: updatedDeps }]);
6377
6390
  }, [tasks, onTasksChange]);
6378
6391
  const [isCreating, setIsCreating] = useState6(false);
6392
+ const [pendingInsert, setPendingInsert] = useState6(null);
6379
6393
  const [draggingIndex, setDraggingIndex] = useState6(null);
6380
6394
  const [dragOverIndex, setDragOverIndex] = useState6(null);
6381
6395
  const dragOriginIndexRef = useRef6(null);
@@ -6534,6 +6548,81 @@ var TaskList = ({
6534
6548
  setIsCreating(false);
6535
6549
  }, [onAdd]);
6536
6550
  const handleCancelNewTask = useCallback5(() => setIsCreating(false), []);
6551
+ const findInsertAfterTaskId = useCallback5((anchorTaskId) => {
6552
+ const anchorIndex = orderedTasks.findIndex((task) => task.id === anchorTaskId);
6553
+ if (anchorIndex === -1) {
6554
+ return anchorTaskId;
6555
+ }
6556
+ const taskById = new Map(orderedTasks.map((task) => [task.id, task]));
6557
+ let insertAfterTaskId = anchorTaskId;
6558
+ for (let index = anchorIndex + 1; index < orderedTasks.length; index += 1) {
6559
+ let currentParentId = orderedTasks[index]?.parentId;
6560
+ let isDescendant = false;
6561
+ while (currentParentId) {
6562
+ if (currentParentId === anchorTaskId) {
6563
+ isDescendant = true;
6564
+ break;
6565
+ }
6566
+ currentParentId = taskById.get(currentParentId)?.parentId;
6567
+ }
6568
+ if (!isDescendant) {
6569
+ break;
6570
+ }
6571
+ insertAfterTaskId = orderedTasks[index].id;
6572
+ }
6573
+ return insertAfterTaskId;
6574
+ }, [orderedTasks]);
6575
+ const pendingInsertDisplayTaskId = useMemo8(() => {
6576
+ if (!pendingInsert) {
6577
+ return null;
6578
+ }
6579
+ const taskById = new Map(visibleTasks.map((task) => [task.id, task]));
6580
+ if (!taskById.has(pendingInsert.anchorTaskId)) {
6581
+ return null;
6582
+ }
6583
+ let displayTaskId = pendingInsert.anchorTaskId;
6584
+ for (const task of visibleTasks) {
6585
+ let currentParentId = task.parentId;
6586
+ while (currentParentId) {
6587
+ if (currentParentId === pendingInsert.anchorTaskId) {
6588
+ displayTaskId = task.id;
6589
+ break;
6590
+ }
6591
+ currentParentId = taskById.get(currentParentId)?.parentId;
6592
+ }
6593
+ }
6594
+ return displayTaskId;
6595
+ }, [pendingInsert, visibleTasks]);
6596
+ const handleStartInsertAfter = useCallback5((taskId, newTask) => {
6597
+ const anchorTask = orderedTasks.find((task) => task.id === taskId);
6598
+ if (!anchorTask) {
6599
+ return;
6600
+ }
6601
+ setIsCreating(false);
6602
+ setPendingInsert({
6603
+ anchorTaskId: taskId,
6604
+ insertAfterTaskId: findInsertAfterTaskId(taskId),
6605
+ parentId: anchorTask.parentId,
6606
+ startDate: newTask.startDate,
6607
+ endDate: newTask.endDate,
6608
+ nestingDepth: nestingDepthMap.get(taskId) ?? 0
6609
+ });
6610
+ }, [findInsertAfterTaskId, nestingDepthMap, orderedTasks]);
6611
+ const handleConfirmInsertedTask = useCallback5((name) => {
6612
+ if (!pendingInsert) {
6613
+ return;
6614
+ }
6615
+ const newTask = {
6616
+ id: crypto.randomUUID(),
6617
+ name,
6618
+ startDate: pendingInsert.startDate,
6619
+ endDate: pendingInsert.endDate,
6620
+ parentId: pendingInsert.parentId
6621
+ };
6622
+ onInsertAfter?.(pendingInsert.insertAfterTaskId, newTask);
6623
+ setPendingInsert(null);
6624
+ }, [onInsertAfter, pendingInsert]);
6625
+ const handleCancelInsertedTask = useCallback5(() => setPendingInsert(null), []);
6537
6626
  function getTaskDepth(task, tasks2) {
6538
6627
  if (!task) return 0;
6539
6628
  let depth = 0;
@@ -6673,73 +6762,87 @@ var TaskList = ({
6673
6762
  /* @__PURE__ */ jsx14("div", { className: "gantt-tl-body", style: { height: `${totalHeight}px` }, children: visibleTasks.map((task, index) => {
6674
6763
  const previousVisibleTask = index > 0 ? visibleTasks[index - 1] : void 0;
6675
6764
  const canDemoteTask = index === 0 || !task.parentId || previousVisibleTask?.id !== task.parentId;
6676
- return /* @__PURE__ */ jsx14(
6677
- TaskListRow,
6678
- {
6679
- task,
6680
- rowIndex: index,
6681
- taskNumber: originalTaskNumberMap[task.id] || "",
6682
- taskNumberMap: originalTaskNumberMap,
6683
- rowHeight,
6684
- onTasksChange,
6685
- selectedTaskId,
6686
- onRowClick: handleRowClick,
6687
- disableTaskNameEditing,
6688
- disableDependencyEditing,
6689
- allTasks: tasks,
6690
- activeLinkType,
6691
- onSetActiveLinkType: setActiveLinkType,
6692
- selectingPredecessorFor,
6693
- dependencyPickMode,
6694
- onSetDependencyPickMode: setDependencyPickMode,
6695
- onSetSelectingPredecessorFor: setSelectingPredecessorFor,
6696
- onAddDependency: handleAddDependency,
6697
- onRemoveDependency: handleRemoveDependency,
6698
- selectedChip,
6699
- onChipSelect: handleChipSelect,
6700
- onScrollToTask,
6701
- onDelete,
6702
- onAdd,
6703
- onInsertAfter,
6704
- editingTaskId: propEditingTaskId,
6705
- isDragging: draggingIndex === index,
6706
- isDragOver: dragOverIndex === index,
6707
- onDragStart: handleDragStart,
6708
- onDragOver: handleDragOver,
6709
- onDrop: handleDrop,
6710
- onDragEnd: handleDragEnd,
6711
- collapsedParentIds,
6712
- onToggleCollapse: handleToggleCollapse,
6713
- onPromoteTask,
6714
- onDemoteTask: onDemoteTask ? handleDemoteWrapper : void 0,
6715
- onDuplicateTask: onReorder ? handleDuplicateTask : void 0,
6716
- canDemoteTask,
6717
- isLastChild: lastChildIds.has(task.id),
6718
- nestingDepth: nestingDepthMap.get(task.id) ?? 0,
6719
- ancestorContinues: ancestorContinuesMap.get(task.id) ?? [],
6720
- customDays,
6721
- isWeekend: isWeekend3,
6722
- businessDays,
6723
- isFilterMatch: filterMode === "highlight" ? highlightedTaskIds.has(task.id) : false,
6724
- isFilterHideMode: filterMode === "hide" && isFilterActive,
6725
- resolvedColumns
6726
- },
6727
- task.id
6728
- );
6765
+ return /* @__PURE__ */ jsxs11(React11.Fragment, { children: [
6766
+ /* @__PURE__ */ jsx14(
6767
+ TaskListRow,
6768
+ {
6769
+ task,
6770
+ rowIndex: index,
6771
+ taskNumber: originalTaskNumberMap[task.id] || "",
6772
+ taskNumberMap: originalTaskNumberMap,
6773
+ rowHeight,
6774
+ onTasksChange,
6775
+ selectedTaskId,
6776
+ onRowClick: handleRowClick,
6777
+ disableTaskNameEditing,
6778
+ disableDependencyEditing,
6779
+ allTasks: tasks,
6780
+ activeLinkType,
6781
+ onSetActiveLinkType: setActiveLinkType,
6782
+ selectingPredecessorFor,
6783
+ dependencyPickMode,
6784
+ onSetDependencyPickMode: setDependencyPickMode,
6785
+ onSetSelectingPredecessorFor: setSelectingPredecessorFor,
6786
+ onAddDependency: handleAddDependency,
6787
+ onRemoveDependency: handleRemoveDependency,
6788
+ selectedChip,
6789
+ onChipSelect: handleChipSelect,
6790
+ onScrollToTask,
6791
+ onDelete,
6792
+ onAdd,
6793
+ onInsertAfter: handleStartInsertAfter,
6794
+ editingTaskId: propEditingTaskId,
6795
+ isDragging: draggingIndex === index,
6796
+ isDragOver: dragOverIndex === index,
6797
+ onDragStart: handleDragStart,
6798
+ onDragOver: handleDragOver,
6799
+ onDrop: handleDrop,
6800
+ onDragEnd: handleDragEnd,
6801
+ collapsedParentIds,
6802
+ onToggleCollapse: handleToggleCollapse,
6803
+ onPromoteTask,
6804
+ onDemoteTask: onDemoteTask ? handleDemoteWrapper : void 0,
6805
+ onDuplicateTask: onReorder ? handleDuplicateTask : void 0,
6806
+ canDemoteTask,
6807
+ isLastChild: lastChildIds.has(task.id),
6808
+ nestingDepth: nestingDepthMap.get(task.id) ?? 0,
6809
+ ancestorContinues: ancestorContinuesMap.get(task.id) ?? [],
6810
+ customDays,
6811
+ isWeekend: isWeekend3,
6812
+ businessDays,
6813
+ isFilterMatch: filterMode === "highlight" ? highlightedTaskIds.has(task.id) : false,
6814
+ isFilterHideMode: filterMode === "hide" && isFilterActive,
6815
+ resolvedColumns
6816
+ }
6817
+ ),
6818
+ pendingInsertDisplayTaskId === task.id && /* @__PURE__ */ jsx14(
6819
+ NewTaskRow,
6820
+ {
6821
+ rowHeight,
6822
+ onConfirm: handleConfirmInsertedTask,
6823
+ onCancel: handleCancelInsertedTask,
6824
+ nestingDepth: pendingInsert?.nestingDepth ?? 0
6825
+ }
6826
+ )
6827
+ ] }, task.id);
6729
6828
  }) }),
6730
- isCreating && /* @__PURE__ */ jsx14(
6829
+ isCreating && !pendingInsert && /* @__PURE__ */ jsx14(
6731
6830
  NewTaskRow,
6732
6831
  {
6733
6832
  rowHeight,
6734
6833
  onConfirm: handleConfirmNewTask,
6735
- onCancel: handleCancelNewTask
6834
+ onCancel: handleCancelNewTask,
6835
+ nestingDepth: 0
6736
6836
  }
6737
6837
  ),
6738
- enableAddTask && onAdd && !isCreating && /* @__PURE__ */ jsx14(
6838
+ enableAddTask && onAdd && !isCreating && !pendingInsert && /* @__PURE__ */ jsx14(
6739
6839
  "button",
6740
6840
  {
6741
6841
  className: `gantt-tl-add-btn${dragOverIndex === visibleTasks.length ? " gantt-tl-add-btn-drag-over" : ""}`,
6742
- onClick: () => setIsCreating(true),
6842
+ onClick: () => {
6843
+ setPendingInsert(null);
6844
+ setIsCreating(true);
6845
+ },
6743
6846
  onDragEnter: (e) => {
6744
6847
  e.preventDefault();
6745
6848
  setDragOverIndex(visibleTasks.length);
@@ -7016,7 +7119,6 @@ function GanttChartInner(props, ref) {
7016
7119
  toDelete.forEach((id) => onDelete?.(id));
7017
7120
  }, [tasks, onTasksChange, onDelete]);
7018
7121
  const handleInsertAfter = useCallback6((taskId, newTask) => {
7019
- setEditingTaskId(newTask.id);
7020
7122
  onInsertAfter?.(taskId, newTask);
7021
7123
  }, [onInsertAfter]);
7022
7124
  const handleReorder = useCallback6((reorderedTasks, movedTaskId, inferredParentId) => {