react-weekly-planning 1.0.40 → 1.0.42

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 CHANGED
@@ -425,7 +425,41 @@ to create an organization that truly reflects you.
425
425
  console.log(hashes.day); // "0/group-1/2"
426
426
  ```
427
427
 
428
+ ### `getNewTaskForDropOrPaste`
428
429
 
429
- ---
430
+ - **Description**: Utility function to generate a new task correctly positioned when dropping or pasting it in a custom calendar context. It reads the dragged task information from the browser's `sessionStorage` and calculates the new start/end dates based on the drop target.
431
+ - **Parameters**:
432
+ - `positionDay` (number): The index of the day where the task is dropped or pasted (0-6).
433
+ - `dropGroupId` (string): The ID of the group where the task is dropped or pasted.
434
+ - `getTask` (function): The function `(hash: string, taskId: string) => TaskFeildsType | undefined` (available from `useCalendarTaskContext`) to retrieve the original task being dragged.
435
+ - `hash` (string): The hash for the current view, representing the destination bucket.
436
+ - **Returns**: An object containing `{ taskDropStart, taskDropEnd, taskDropDate, newTask }` or `undefined` if no task is currently in the session storage.
430
437
 
438
+ **Example**:
439
+ ```tsx
440
+ import { getNewTaskForDropOrPaste, useCalendarTaskContext } from "react-weekly-planning";
441
+
442
+ const CustomCell = ({ dayIndex, groupId, currentHash }) => {
443
+ const { getTask, addTask } = useCalendarTaskContext();
444
+
445
+ const handleDrop = (e) => {
446
+ e.preventDefault();
447
+
448
+ const result = getNewTaskForDropOrPaste(
449
+ dayIndex,
450
+ groupId,
451
+ getTask,
452
+ currentHash
453
+ );
454
+
455
+ if (result && result.newTask) {
456
+ addTask(result.newTask);
457
+ }
458
+ };
459
+
460
+ return <div onDrop={handleDrop} onDragOver={(e) => e.preventDefault()}>Drop Here</div>;
461
+ };
462
+ ```
463
+
464
+ ---
431
465
 
@@ -5,7 +5,7 @@ import { useIntersectionObserver } from "../hooks/useIntersectionObserver";
5
5
  import GroupContainer from "./GroupContainer";
6
6
  import TaskVirtual from "./TaskContainer/TaskVirtual";
7
7
  import AddTask from "./AddTask";
8
- import { getHash, getSessionStorageRecordForDragAndDrop, getUnqueId, updateOffsetWithDateCalendar, } from "../lib/utils";
8
+ import { getHash, getNewTaskForDropOrPaste, getUnqueId, updateOffsetWithDateCalendar, } from "../lib/utils";
9
9
  import { groupTdStyle } from "../lib/slyles";
10
10
  const VirtualGroupRow = ({ group, i, props, getTasks, isValidTask, addTask, deleteTask, getTask, dailyHours, hashScope, tasks, sumHoursByGroupsCount }) => {
11
11
  const ref = useRef(null);
@@ -30,7 +30,7 @@ const VirtualGroupRow = ({ group, i, props, getTasks, isValidTask, addTask, dele
30
30
  }, [isVisible, offset, group.id, dailyHours, hashScope, getTasks, isValidTask, tasks]);
31
31
  return (_jsx("div", { ref: ref, className: `planningCalendarRow ${props.rowsClassName}`, style: Object.assign(Object.assign({}, props.rowsStyle), { minHeight: isVisible ? "auto" : "60px" }), children: isVisible ? (_jsxs(_Fragment, { children: [_jsx("div", { className: `groupCol ${props.groupsColsClassName}`, style: Object.assign(Object.assign({}, groupTdStyle), props.groupsColsStyle), children: _jsx(GroupContainer, { style: props.groupContainerStyle, className: props.groupContainerClassName, groupRender: props.groupRender, currentGroup: group, handleClickGroup: props.handleClickGroup }) }, group.id), cellData.map((cell) => {
32
32
  return (_jsx("div", { onDragOver: (e) => e.preventDefault(), onDrop: (event) => {
33
- const dropInfo = getSessionStorageRecordForDragAndDrop(cell.tasks, cell.positionDay, group.id, getTask, cell.hash);
33
+ const dropInfo = getNewTaskForDropOrPaste(cell.positionDay, group.id, getTask, cell.hash);
34
34
  if (!dropInfo)
35
35
  return;
36
36
  if (props.drop === "copy") {
@@ -4,7 +4,7 @@ import { useIntersectionObserver } from "../hooks/useIntersectionObserver";
4
4
  import GroupContainer from "./GroupContainer";
5
5
  import TaskVirtual from "./TaskContainer/TaskVirtual";
6
6
  import AddTask from "./AddTask";
7
- import { getHash, getSessionStorageRecordForDragAndDrop, getUnqueId, updateOffsetWithDateCalendar, } from "../lib/utils";
7
+ import { getHash, getNewTaskForDropOrPaste, getUnqueId, updateOffsetWithDateCalendar, } from "../lib/utils";
8
8
  const VirtualGroupRowDay = ({ group, i, props, getTasks, isValidTask, addTask, deleteTask, updateTask, getTask, dailyHours, dayOffset, hashScope, tasks, }) => {
9
9
  const ref = useRef(null);
10
10
  const entry = useIntersectionObserver(ref, {
@@ -22,7 +22,7 @@ const VirtualGroupRowDay = ({ group, i, props, getTasks, isValidTask, addTask, d
22
22
  return (_jsx("div", { ref: ref, style: Object.assign({ width: "100%", height: "auto", padding: "5px", borderBottom: "1.5px solid #0f52737e", borderRight: "0.74px solid rgba(198, 219, 225, 0.68)", borderLeft: "0.74px solid rgba(198, 219, 225, 0.68)", minHeight: isVisible ? "auto" : "60px" }, props.rowsStyle), className: `CalendarTableForDayRow ${props.rowsClassName}`, children: isVisible ? (_jsxs(_Fragment, { children: [_jsx("div", { style: Object.assign({ width: "auto", height: "auto" }, props.groupsColsStyle), className: props.groupsColsClassName, children: _jsx(GroupContainer, { style: props.groupContainerStyle, className: props.groupContainerClassName, groupRender: props.groupRender, currentGroup: group, handleClickGroup: props.handleClickGroup }) }), _jsxs("div", { className: "CalendarTableForDayGroupTasks", onDragOver: handleDragOver, onDrop: (event) => {
23
23
  if (!cellTasks)
24
24
  return;
25
- const dropInfo = getSessionStorageRecordForDragAndDrop(cellTasks, currentDailyHours.positionDay, group.id, getTask, hash[hashScope]);
25
+ const dropInfo = getNewTaskForDropOrPaste(currentDailyHours.positionDay, group.id, getTask, hash[hashScope]);
26
26
  if (!dropInfo)
27
27
  return;
28
28
  if (props.drop === "copy") {
@@ -0,0 +1,167 @@
1
+ .addPlanStyle {
2
+ cursor: pointer;
3
+ display: flex;
4
+ align-items: center;
5
+ justify-content: center;
6
+ flex: 1;
7
+ background-color: #f2f8fb;
8
+ opacity: 0;
9
+ border-radius: 5px;
10
+ color: #0f5173;
11
+ transition: background-color 0.3s, opacity 0.3s;
12
+ }
13
+
14
+ .addPlanStyle:hover {
15
+ background-color: #c6dbe159;
16
+ opacity: 1;
17
+ }
18
+
19
+ .taskContainer {
20
+ box-shadow: 0px 7px 18px 0px rgba(15, 105, 115, 0.03),
21
+ 0px 6px 10px 0px rgba(15, 105, 115, 0.04),
22
+ 0px 3px 5px 0px rgba(15, 105, 115, 0.05);
23
+ display: flex;
24
+ justify-content: center;
25
+ column-gap: 10px;
26
+ flex-direction: column;
27
+ height: auto;
28
+ border-left: 5px solid #457993;
29
+ background-color: #f4ffff;
30
+ color: #457993;
31
+ cursor: pointer;
32
+ border-radius: 5px;
33
+ margin-bottom: 5px;
34
+ font-size: 13px;
35
+ overflow: auto;
36
+ padding: 2px;
37
+ z-index: 10;
38
+ }
39
+
40
+ .tasklabel {
41
+ color: #55585d;
42
+ font-size: 12px;
43
+ line-height: 16px;
44
+ font-weight: 400;
45
+ margin-left: 5px;
46
+ }
47
+
48
+ .taskhour {
49
+ font-size: 12px;
50
+ line-height: 16px;
51
+ font-weight: 600;
52
+ margin-left: 5px;
53
+ }
54
+
55
+ .planningCalendar {
56
+ width: 100%;
57
+ border-radius: 0.5rem;
58
+ z-index: 10;
59
+ display: flex;
60
+ flex-direction: column;
61
+ border: 0.74px solid rgba(198, 219, 225, 0.68);
62
+
63
+ background-color: white;
64
+
65
+ }
66
+
67
+ .planningCalendarHeader {
68
+ display: flex;
69
+ width: 100%;
70
+ z-index: 200;
71
+ border-bottom: 1.5px solid #0f52737e;
72
+ background-color: #fff;
73
+ }
74
+
75
+ .planningCalendarRow {
76
+ display: flex;
77
+ width: 100%;
78
+ border-bottom: 1.5px solid #0f52737e;
79
+ }
80
+
81
+ .planningCalendarRow:last-child {
82
+ border-bottom: none;
83
+ }
84
+
85
+ .planningCalendar .dayTh,
86
+ .planningCalendar .groupCol {
87
+ flex: 0 0 150px;
88
+ color: #0f5173;
89
+ padding-left: 5px;
90
+ display: flex;
91
+ align-items: center;
92
+ }
93
+
94
+ .planningCalendar .dayCol {
95
+ flex: 1;
96
+ border-left: 0.74px solid rgba(198, 219, 225, 0.68);
97
+ min-width: 0;
98
+ display: flex;
99
+ flex-direction: column;
100
+ justify-content: center;
101
+ }
102
+
103
+ .planningCalendar .totalTh,
104
+ .planningCalendar .totalCol {
105
+ flex: 0 0 50px;
106
+ color: #0f5173;
107
+ text-align: right;
108
+ padding-right: 5px;
109
+ border-left: 0.74px solid rgba(198, 219, 225, 0.68);
110
+ display: flex;
111
+ align-items: center;
112
+ justify-content: flex-end;
113
+ }
114
+
115
+ .CalendarTableForDay {
116
+ display: flex;
117
+ gap: 10px;
118
+ width: 100vw;
119
+ height: auto;
120
+ }
121
+
122
+ .CalendarTableForDayTasksContainer {
123
+ flex: 1;
124
+ display: flex;
125
+ flex-direction: column;
126
+ height: auto;
127
+ padding: 10px;
128
+ position: relative;
129
+ }
130
+
131
+ .CalendarTableForDayRow {
132
+ display: flex !important;
133
+ flex-direction: row !important;
134
+ gap: 15px;
135
+ align-items: flex-start;
136
+ padding: 15px !important;
137
+ }
138
+
139
+ .CalendarTableForDayGroupTasks {
140
+ flex: 1;
141
+ display: grid;
142
+ grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
143
+ gap: 10px;
144
+ }
145
+
146
+ .CalendarTableForDayGroupTasks .taskContainer,
147
+ .CalendarTableForDayGroupTasks .addPlanStyle {
148
+ margin-bottom: 0px;
149
+ height: 100%;
150
+ min-height: 80px;
151
+ }
152
+
153
+ .calendarForWeek {
154
+ display: flex;
155
+ width: 100%;
156
+ flex: 1;
157
+ overflow: auto;
158
+ position: relative;
159
+
160
+ }
161
+
162
+ .calendarForWeek-container {
163
+ display: flex;
164
+ flex-direction: column;
165
+ width: 100%;
166
+ height: 100%;
167
+ }
@@ -1,6 +1,5 @@
1
1
  import { useMemo } from "react";
2
2
  export const useData = (sliceIndex, itemsByLine, windowLines, tasks, bottomBufferSize, topBufferSize) => {
3
- console.log(sliceIndex, itemsByLine, windowLines, tasks, "virtual");
4
3
  const visibleTasks = useMemo(() => tasks.slice(Math.max(sliceIndex - topBufferSize, 0) * itemsByLine, Math.min(tasks.length, (windowLines + bottomBufferSize) * itemsByLine +
5
4
  sliceIndex * itemsByLine)), [sliceIndex, itemsByLine, windowLines, tasks]);
6
5
  return { visibleTasks };
package/dist/lib/utils.js CHANGED
@@ -186,7 +186,7 @@ export function calculateWeekDifference(dateSelectionnee, timeZone) {
186
186
  * @param numeroSemaine - The week number.
187
187
  * @returns The number of weeks since the origin date.
188
188
  */
189
- export function getSessionStorageRecordForDragAndDrop(tasks, positionDay, dropGroupId, getTask, hash) {
189
+ export function getNewTaskForDropOrPaste(positionDay, dropGroupId, getTask, hash) {
190
190
  const dragtaskId = window.sessionStorage.getItem("calendardragtaskId");
191
191
  const dragtaskStart = window.sessionStorage.getItem("calendardragtaskStart");
192
192
  const dragtaskEnd = window.sessionStorage.getItem("calendardragtaskEnd");
@@ -194,13 +194,12 @@ export function getSessionStorageRecordForDragAndDrop(tasks, positionDay, dropGr
194
194
  const draghash = window.sessionStorage.getItem("calendardraghash");
195
195
  let newTask;
196
196
  window.sessionStorage.clear();
197
- if (!dragdayIndex || !dragtaskStart || !dragtaskEnd || !dragtaskId || !tasks)
197
+ if (!dragdayIndex || !dragtaskStart || !dragtaskEnd || !dragtaskId)
198
198
  return;
199
199
  const convertTaskDropStart = new Date(parseInt(dragtaskStart));
200
200
  if (draghash === null)
201
201
  return;
202
202
  const dragTask = getTask(draghash, dragtaskId);
203
- console.log('dragTask', dragTask, draghash, hash);
204
203
  if (!dragTask)
205
204
  return;
206
205
  const dayIndex = parseInt(dragdayIndex);
@@ -35,7 +35,7 @@ export declare function calculateWeekDifference(dateSelectionnee: Date, timeZone
35
35
  * @param numeroSemaine - The week number.
36
36
  * @returns The number of weeks since the origin date.
37
37
  */
38
- export declare function getSessionStorageRecordForDragAndDrop(tasks: TasksType, positionDay: number, dropGroupId: string, getTask: (hash: string, taskId: string) => TaskFeildsType | undefined, hash: string): {
38
+ export declare function getNewTaskForDropOrPaste(positionDay: number, dropGroupId: string, getTask: (hash: string, taskId: string) => TaskFeildsType | undefined, hash: string): {
39
39
  taskDropStart: number;
40
40
  taskDropEnd: number;
41
41
  taskDropDate: Date;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-weekly-planning",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/types/index.d.ts",
6
6
  "exports": {