react-weekly-planning 1.0.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.
@@ -0,0 +1,111 @@
1
+ /* JSDoc prettify.js theme */
2
+
3
+ /* plain text */
4
+ .pln {
5
+ color: #000000;
6
+ font-weight: normal;
7
+ font-style: normal;
8
+ }
9
+
10
+ /* string content */
11
+ .str {
12
+ color: #006400;
13
+ font-weight: normal;
14
+ font-style: normal;
15
+ }
16
+
17
+ /* a keyword */
18
+ .kwd {
19
+ color: #000000;
20
+ font-weight: bold;
21
+ font-style: normal;
22
+ }
23
+
24
+ /* a comment */
25
+ .com {
26
+ font-weight: normal;
27
+ font-style: italic;
28
+ }
29
+
30
+ /* a type name */
31
+ .typ {
32
+ color: #000000;
33
+ font-weight: normal;
34
+ font-style: normal;
35
+ }
36
+
37
+ /* a literal value */
38
+ .lit {
39
+ color: #006400;
40
+ font-weight: normal;
41
+ font-style: normal;
42
+ }
43
+
44
+ /* punctuation */
45
+ .pun {
46
+ color: #000000;
47
+ font-weight: bold;
48
+ font-style: normal;
49
+ }
50
+
51
+ /* lisp open bracket */
52
+ .opn {
53
+ color: #000000;
54
+ font-weight: bold;
55
+ font-style: normal;
56
+ }
57
+
58
+ /* lisp close bracket */
59
+ .clo {
60
+ color: #000000;
61
+ font-weight: bold;
62
+ font-style: normal;
63
+ }
64
+
65
+ /* a markup tag name */
66
+ .tag {
67
+ color: #006400;
68
+ font-weight: normal;
69
+ font-style: normal;
70
+ }
71
+
72
+ /* a markup attribute name */
73
+ .atn {
74
+ color: #006400;
75
+ font-weight: normal;
76
+ font-style: normal;
77
+ }
78
+
79
+ /* a markup attribute value */
80
+ .atv {
81
+ color: #006400;
82
+ font-weight: normal;
83
+ font-style: normal;
84
+ }
85
+
86
+ /* a declaration */
87
+ .dec {
88
+ color: #000000;
89
+ font-weight: bold;
90
+ font-style: normal;
91
+ }
92
+
93
+ /* a variable name */
94
+ .var {
95
+ color: #000000;
96
+ font-weight: normal;
97
+ font-style: normal;
98
+ }
99
+
100
+ /* a function name */
101
+ .fun {
102
+ color: #000000;
103
+ font-weight: bold;
104
+ font-style: normal;
105
+ }
106
+
107
+ /* Specify class=linenums on a pre to get line numbering */
108
+ ol.linenums {
109
+ margin-top: 0;
110
+ margin-bottom: 0;
111
+ }
@@ -0,0 +1,132 @@
1
+ /* Tomorrow Theme */
2
+ /* Original theme - https://github.com/chriskempson/tomorrow-theme */
3
+ /* Pretty printing styles. Used with prettify.js. */
4
+ /* SPAN elements with the classes below are added by prettyprint. */
5
+ /* plain text */
6
+ .pln {
7
+ color: #4d4d4c; }
8
+
9
+ @media screen {
10
+ /* string content */
11
+ .str {
12
+ color: #718c00; }
13
+
14
+ /* a keyword */
15
+ .kwd {
16
+ color: #8959a8; }
17
+
18
+ /* a comment */
19
+ .com {
20
+ color: #8e908c; }
21
+
22
+ /* a type name */
23
+ .typ {
24
+ color: #4271ae; }
25
+
26
+ /* a literal value */
27
+ .lit {
28
+ color: #f5871f; }
29
+
30
+ /* punctuation */
31
+ .pun {
32
+ color: #4d4d4c; }
33
+
34
+ /* lisp open bracket */
35
+ .opn {
36
+ color: #4d4d4c; }
37
+
38
+ /* lisp close bracket */
39
+ .clo {
40
+ color: #4d4d4c; }
41
+
42
+ /* a markup tag name */
43
+ .tag {
44
+ color: #c82829; }
45
+
46
+ /* a markup attribute name */
47
+ .atn {
48
+ color: #f5871f; }
49
+
50
+ /* a markup attribute value */
51
+ .atv {
52
+ color: #3e999f; }
53
+
54
+ /* a declaration */
55
+ .dec {
56
+ color: #f5871f; }
57
+
58
+ /* a variable name */
59
+ .var {
60
+ color: #c82829; }
61
+
62
+ /* a function name */
63
+ .fun {
64
+ color: #4271ae; } }
65
+ /* Use higher contrast and text-weight for printable form. */
66
+ @media print, projection {
67
+ .str {
68
+ color: #060; }
69
+
70
+ .kwd {
71
+ color: #006;
72
+ font-weight: bold; }
73
+
74
+ .com {
75
+ color: #600;
76
+ font-style: italic; }
77
+
78
+ .typ {
79
+ color: #404;
80
+ font-weight: bold; }
81
+
82
+ .lit {
83
+ color: #044; }
84
+
85
+ .pun, .opn, .clo {
86
+ color: #440; }
87
+
88
+ .tag {
89
+ color: #006;
90
+ font-weight: bold; }
91
+
92
+ .atn {
93
+ color: #404; }
94
+
95
+ .atv {
96
+ color: #060; } }
97
+ /* Style */
98
+ /*
99
+ pre.prettyprint {
100
+ background: white;
101
+ font-family: Consolas, Monaco, 'Andale Mono', monospace;
102
+ font-size: 12px;
103
+ line-height: 1.5;
104
+ border: 1px solid #ccc;
105
+ padding: 10px; }
106
+ */
107
+
108
+ /* Specify class=linenums on a pre to get line numbering */
109
+ ol.linenums {
110
+ margin-top: 0;
111
+ margin-bottom: 0; }
112
+
113
+ /* IE indents via margin-left */
114
+ li.L0,
115
+ li.L1,
116
+ li.L2,
117
+ li.L3,
118
+ li.L4,
119
+ li.L5,
120
+ li.L6,
121
+ li.L7,
122
+ li.L8,
123
+ li.L9 {
124
+ /* */ }
125
+
126
+ /* Alternate shading for lines */
127
+ li.L1,
128
+ li.L3,
129
+ li.L5,
130
+ li.L7,
131
+ li.L9 {
132
+ /* */ }
@@ -0,0 +1,44 @@
1
+ /* reset css */
2
+ html, body, div, span, applet, object, iframe,
3
+ h1, h2, h3, h4, h5, h6, p, blockquote, pre,
4
+ a, abbr, acronym, address, big, cite, code,
5
+ del, dfn, em, img, ins, kbd, q, s, samp,
6
+ small, strike, strong, sub, sup, tt, var,
7
+ b, u, i, center,
8
+ dl, dt, dd, ol, ul, li,
9
+ fieldset, form, label, legend,
10
+ table, caption, tbody, tfoot, thead, tr, th, td,
11
+ article, aside, canvas, details, embed,
12
+ figure, figcaption, footer, header, hgroup,
13
+ menu, nav, output, ruby, section, summary,
14
+ time, mark, audio, video {
15
+ margin: 0;
16
+ padding: 0;
17
+ border: 0;
18
+ font-size: 100%;
19
+ font: inherit;
20
+ vertical-align: baseline;
21
+ }
22
+ /* HTML5 display-role reset for older browsers */
23
+ article, aside, details, figcaption, figure,
24
+ footer, header, hgroup, menu, nav, section {
25
+ display: block;
26
+ }
27
+ body {
28
+ line-height: 1;
29
+ }
30
+ ol, ul {
31
+ list-style: none;
32
+ }
33
+ blockquote, q {
34
+ quotes: none;
35
+ }
36
+ blockquote:before, blockquote:after,
37
+ q:before, q:after {
38
+ content: '';
39
+ content: none;
40
+ }
41
+ table {
42
+ border-collapse: collapse;
43
+ border-spacing: 0;
44
+ }
package/index.js ADDED
@@ -0,0 +1,224 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import "./style.css";
3
+ import { getWeekDays, getDayHourly, calculerEcartSemaine, getSessionStorageRecordForDragAndDrop, sumHoursByGroups, millisecondsToDate, compareWeekOffset, } from "./lib/utils";
4
+ const tableStyle = {
5
+ width: "100%",
6
+ height: "150px",
7
+ borderRadius: "0.5rem",
8
+ zIndex: 10,
9
+ };
10
+ const trStyle = {
11
+ color: "#0f5173",
12
+ fontWeight: "300",
13
+ position: "sticky",
14
+ top: 0,
15
+ };
16
+ const thStyle = {
17
+ color: "#0f5173",
18
+ paddingLeft: "5px",
19
+ };
20
+ const weekDayThStyle = {};
21
+ const totalThStyle = {
22
+ width: "40px",
23
+ textAlign: "right",
24
+ paddingRight: "2px",
25
+ };
26
+ const tdStyle = {
27
+ height: "auto",
28
+ width: "150px",
29
+ };
30
+ const tableTrStyle = {
31
+ borderBottom: "1.5px solid #0f52737e",
32
+ // backgroundColor: "#f2f8fb",
33
+ padding: "2px",
34
+ };
35
+ const tableTdStyle = {
36
+ borderLeft: "0.74px solid rgba(198, 219, 225, 0.68)",
37
+ borderRight: "0.74px solid rgba(198, 219, 225, 0.68)",
38
+ };
39
+ const groupContainerStyle = {
40
+ width: "100%",
41
+ height: "100%",
42
+ display: "flex",
43
+ alignItems: "center",
44
+ justifyContent: "space-between",
45
+ gap: "0.75rem", // Correspond à gap-3
46
+ padding: "0.75rem", // Correspond à p-3
47
+ color: "#0f5173",
48
+ cursor: "pointer",
49
+ };
50
+ /**
51
+ * Calendar component to display tasks and groups in a weekly view.
52
+ *
53
+ * @param {Object} props - The props for the Calendar component.
54
+ * @param {React.CSSProperties} [props.style] - Additional styles for the calendar component.
55
+ * @param {string} [props.className] - Additional class names for the calendar component.
56
+ * @param {Array} props.groups - Array of group data to be displayed in the calendar.
57
+ * @param {number} [props.weekOffset] - Offset for the week (e.g., -1 for last week, 0 for current week, 1 for next week).
58
+ * @param {Date} props.date - The current date to display in the calendar.
59
+ * @param {Function} [props.groupRender] - Custom render function for a group.
60
+ * @param {Function} [props.dayRender] - Custom render function for a day.
61
+ * @param {React.CSSProperties} [props.rowsStyle] - Additional styles for the rows.
62
+ * @param {React.CSSProperties} [props.groupsColsStyle] - Additional styles for the group columns.
63
+ * @param {React.CSSProperties} [props.daysColsStyle] - Additional styles for the day columns.
64
+ * @param {Function} [props.addTaskRender] - Custom render function for the add task button.
65
+ * @param {Function} [props.handleAddTask] - Handler function for adding a new task.
66
+ * @param {string} [props.dayClassName] - Additional class names for the days.
67
+ * @param {React.CSSProperties} [props.dayStyle] - Additional styles for the days.
68
+ * @param {string} [props.groupClassName] - Additional class names for the groups.
69
+ * @param {React.CSSProperties} [props.groupStyle] - Additional styles for the groups.
70
+ * @param {string} [props.addTaskClassName] - Additional class names for the add task button.
71
+ * @param {React.CSSProperties} [props.addTaskStyle] - Additional styles for the add task button.
72
+ * @param {Array} props.tasks - Array of tasks to be displayed in the calendar.
73
+ * @param {Function} [props.handleDragTask] - Handler function for dragging a task.
74
+ * @param {Function} [props.handleDropTask] - Handler function for dropping a task.
75
+ * @param {Function} [props.taskRender] - Custom render function for a task.
76
+ * @param {Function} [props.groupsHeadRender] - Custom render function for the groups header.
77
+ * @param {Function} [props.sumHoursRender] - Custom render function for the sum of hours.
78
+ * @param {Function} [props.sumHoursHeadRender] - Custom render function for the sum of hours header.
79
+ * @param {Function} [props.handleDragTaskEnd] - Handler function for ending the drag of a task.
80
+ * @param {string} [props.rowsClassName] - Additional class names for the rows.
81
+ * @param {string} [props.daysColsClassName] - Additional class names for the day columns.
82
+ * @param {string} [props.sumHoursContainerClassName] - Additional class names for the sum hours container.
83
+ * @param {React.CSSProperties} [props.sumHoursContainerStyle] - Additional styles for the sum hours container.
84
+ * @param {string} [props.groupHeadContainerClassName] - Additional class names for the group head container.
85
+ * @param {React.CSSProperties} [props.groupHeadContainerStyle] - Additional styles for the group head container.
86
+ * @param {string} [props.groupsColsClassName] - Additional class names for the group columns.
87
+ * @param {string} [props.taskContainerClassName] - Additional class names for the task container.
88
+ * @param {React.CSSProperties} [props.taskContainerStyle] - Additional styles for the task container.
89
+ * @param {string} [props.sumHoursHeadClassName] - Additional class names for the sum hours header.
90
+ * @param {React.CSSProperties} [props.sumHoursHeadStyle] - Additional styles for the sum hours header.
91
+ * @param {Function} [props.handleClickGroup] - Handler function for clicking a group.
92
+ * @param {Function} [props.handleClickTask] - Handler function for clicking a task.
93
+ * @returns {JSX.Element} The rendered Calendar component.
94
+ */
95
+ const Calendar = ({ style, className, groups, weekOffset, date, groupRender, dayRender, rowsStyle, groupsColsStyle, daysColsStyle, addTaskRender, handleAddTask, dayClassName, dayStyle, groupClassName, groupStyle, addTaskClassName, addTaskStyle, tasks, handleDragTask, handleDropTask, taskRender, groupsHeadRender, sumHoursRender, sumHoursHeadRender, handleDragTaskEnd, rowsClassName, daysColsClassName, sumHoursContainerClassName, sumHoursContainerStyle, groupHeadContainerClassName, groupHeadContainerStyle, groupsColsClassName, taskContainerClassName, taskContainerStyle, sumHoursHeadClassName, sumHoursHeadStyle, handleClickGroup, handleClickTask, }) => {
96
+ const weekOffsetByDate = calculerEcartSemaine(date);
97
+ const weekDays = getWeekDays(weekOffsetByDate || weekOffset || 0);
98
+ const dailyHours = getDayHourly(weekOffsetByDate || weekOffset || 0);
99
+ const handleDragOver = (event) => {
100
+ event.preventDefault();
101
+ };
102
+ return (_jsxs("table", { className: `${className}`, style: Object.assign(Object.assign({}, tableStyle), style), children: [_jsx("thead", { children: _jsxs("tr", { className: `${rowsClassName}`, style: Object.assign(Object.assign(Object.assign({}, trStyle), tableTrStyle), rowsStyle), children: [_jsx("th", { style: thStyle, children: _jsx(GroupsHeadContainer, { className: `${groupHeadContainerClassName}`, style: groupHeadContainerStyle, groupsHeadRender: groupsHeadRender }) }), weekDays.map((day, i) => (_jsx("th", { className: `${daysColsClassName}`, style: Object.assign(Object.assign({}, weekDayThStyle), daysColsStyle), children: _jsx(DayContainer, { style: dayStyle, className: dayClassName, dayIndex: i, dayRender: dayRender, day: day.day, dayOfTheMonth: day.dayOfTheMonth, dayMonth: day.dayMonth, dayYear: day.dayYear }) }, i))), _jsx("th", { style: totalThStyle, children: _jsx(SumHoursHead, { className: sumHoursHeadClassName, style: sumHoursHeadStyle, sumHoursHeadRender: sumHoursHeadRender }) })] }, "") }), _jsx("tbody", { children: groups === null || groups === void 0 ? void 0 : groups.map((group, i) => (_jsxs("tr", { className: `${rowsClassName}`, style: Object.assign(Object.assign({}, tableTrStyle), rowsStyle), children: [_jsx("td", { className: `${groupsColsClassName}`, style: Object.assign(Object.assign(Object.assign({}, tdStyle), tableTdStyle), groupsColsStyle), children: _jsx(GroupContainer, { style: groupStyle, className: groupClassName, groupRender: groupRender, currentGroup: group, handleClickGroup: handleClickGroup }) }, i), dailyHours.map((_, positionDay) => (_jsx("td", { style: Object.assign({ width: "8vw" }, tableTdStyle), onDragOver: handleDragOver, onDrop: (event) => {
103
+ if (!handleDropTask || !tasks)
104
+ return;
105
+ const dropInfo = getSessionStorageRecordForDragAndDrop(tasks, positionDay, group.id);
106
+ if (!dropInfo)
107
+ return;
108
+ handleDropTask(event, dropInfo.taskDropStart, dropInfo.taskDropEnd, dropInfo.taskDropDate, group.id, positionDay, dropInfo.newTask, dropInfo.newTasks);
109
+ }, id: `td-${group.id}day-i`, children: _jsxs("div", { style: {
110
+ display: "flex",
111
+ width: "100%",
112
+ height: "100%",
113
+ flexDirection: "column",
114
+ padding: "5px",
115
+ }, children: [_jsx(_Fragment, { children: tasks === null || tasks === void 0 ? void 0 : tasks.filter((task) => task.dayIndex === positionDay &&
116
+ task.groupId === group.id &&
117
+ compareWeekOffset(date, weekOffset || 0, task.taskDate)).sort((a, b) => a.taskStart - b.taskStart).map((task, taskKey) => {
118
+ return (_jsx(TaskContainer, { handleDragTask: handleDragTask, taskRender: taskRender, handleDragTaskEnd: handleDragTaskEnd, style: taskContainerStyle, className: `${taskContainerClassName}`, currentTask: task, handleClickTask: handleClickTask }, `${taskKey} task`));
119
+ }) }), _jsx(AddTask, { addTaskStyle: addTaskStyle, addTaskClassName: addTaskClassName, groupId: group.id, dayInfo: dailyHours[positionDay], addTaskRender: addTaskRender, handleAddTask: handleAddTask })] }, positionDay) }, `td-${group.id}day-i${positionDay}`))), _jsx("td", { children: _jsx(SumHoursContainer, { groupId: group.id, tasks: tasks, weekOffset: weekOffset || 0, calendarDate: date, sumHoursRender: sumHoursRender, sumHoursByGroups: sumHoursByGroups(group.id, tasks, weekOffset || 0, date), className: sumHoursContainerClassName, style: sumHoursContainerStyle }) }, `${i}sumHours`)] }, `${i} tr`))) })] }));
120
+ };
121
+ const SumHoursHead = ({ sumHoursHeadRender, className, style, }) => {
122
+ if (sumHoursHeadRender) {
123
+ return _jsx(_Fragment, { children: sumHoursHeadRender() });
124
+ }
125
+ return (_jsx("div", { className: `${className}`, style: Object.assign({ textAlign: "right", marginRight: "5px" }, style), children: "Hours" }));
126
+ };
127
+ const SumHoursContainer = ({ groupId, tasks, weekOffset, calendarDate, sumHoursByGroups, sumHoursRender, className, style, }) => {
128
+ if (sumHoursRender) {
129
+ return (_jsx(_Fragment, { children: sumHoursRender({
130
+ groupId,
131
+ tasks,
132
+ weekOffset,
133
+ calendarDate,
134
+ sumHoursByGroups,
135
+ }) }));
136
+ }
137
+ return (_jsx("div", { style: Object.assign({ textAlign: "right", marginRight: "5px" }, style), className: `${className}`, children: sumHoursByGroups }));
138
+ };
139
+ const DayContainer = ({ dayIndex, dayOfTheMonth, day, dayMonth, dayYear, dayRender, className, style, }) => {
140
+ if (dayRender) {
141
+ return (_jsx(_Fragment, { children: dayRender({
142
+ dayIndex,
143
+ day,
144
+ dayOfTheMonth,
145
+ dayMonth,
146
+ dayYear,
147
+ }) }));
148
+ }
149
+ return (_jsx("div", { className: `${className}`, style: style, children: `${day}. ${dayOfTheMonth}` }));
150
+ };
151
+ const GroupContainer = ({ className, style, groupRender, currentGroup, handleClickGroup, }) => {
152
+ if (groupRender) {
153
+ return _jsx(_Fragment, { children: groupRender({ currentGroup }) });
154
+ }
155
+ const handleClick = () => {
156
+ if (!handleClickGroup)
157
+ return;
158
+ handleClickGroup(currentGroup);
159
+ };
160
+ return (_jsxs("div", { onClick: handleClick, className: `${className}`, style: Object.assign(Object.assign({}, groupContainerStyle), style), children: [currentGroup.imageUrl && (_jsx("img", { width: 30, height: 30, src: currentGroup.imageUrl, alt: "groupimg" })), _jsx("label", { children: currentGroup.label && currentGroup.label })] }));
161
+ };
162
+ const AddTask = ({ groupId, handleAddTask, addTaskRender, dayInfo, addTaskStyle, addTaskClassName, }) => {
163
+ if (addTaskRender) {
164
+ return (_jsx(_Fragment, { children: addTaskRender({
165
+ groupId,
166
+ dayInfo,
167
+ }) }));
168
+ }
169
+ const handleClick = () => {
170
+ if (!handleAddTask)
171
+ return;
172
+ handleAddTask(groupId, dayInfo);
173
+ };
174
+ return (_jsx("div", { onClick: handleClick, style: addTaskStyle, className: `addPlanStyle ${addTaskClassName}`, children: "+" }));
175
+ };
176
+ const TaskContainer = ({ handleDragTask, taskRender, handleDragTaskEnd, style, className, currentTask, handleClickTask, }) => {
177
+ const handleDragStart = (event) => {
178
+ if (!handleDragTask)
179
+ return;
180
+ event.dataTransfer.effectAllowed = "move";
181
+ event.dataTransfer.setData("text/plain", currentTask.taskId);
182
+ window.sessionStorage.setItem("calendardragtaskId", currentTask.taskId);
183
+ window.sessionStorage.setItem("calendardragtaskStart", `${currentTask.taskStart}`);
184
+ window.sessionStorage.setItem("calendardragtaskEnd", `${currentTask.taskEnd}`);
185
+ window.sessionStorage.setItem("calendardragdayIndex", `${currentTask.dayIndex}`);
186
+ handleDragTask(event, currentTask);
187
+ };
188
+ const handleDragEnd = (event) => {
189
+ if (!handleDragTaskEnd)
190
+ return;
191
+ handleDragTaskEnd(event);
192
+ };
193
+ const handleClick = () => {
194
+ if (!handleClickTask)
195
+ return;
196
+ handleClickTask(currentTask);
197
+ };
198
+ if (taskRender) {
199
+ return (_jsx("div", { onClick: handleClick, id: currentTask.taskId, className: `taskContainer ${className}`, style: Object.assign({}, style), draggable: true, onDragStart: handleDragStart, onDragEnd: handleDragEnd, children: taskRender({
200
+ currentTask,
201
+ }) }));
202
+ }
203
+ return (_jsxs("div", { onClick: handleClick, id: currentTask.taskId, className: `taskContainer ${className}`, style: Object.assign({}, style), draggable: true, onDragStart: handleDragStart, onDragEnd: handleDragEnd, children: [_jsx("p", { className: "tasklabel", children: currentTask.task && currentTask.task }), _jsx("p", { className: "taskhour", children: currentTask.taskStart &&
204
+ currentTask.taskEnd &&
205
+ `${millisecondsToDate(currentTask.taskStart).formattedDate} - ${millisecondsToDate(currentTask.taskEnd).formattedDate}` })] }));
206
+ };
207
+ const GroupsHeadContainer = ({ groupsHeadRender, style, className, }) => {
208
+ if (groupsHeadRender) {
209
+ return _jsx(_Fragment, { children: groupsHeadRender() });
210
+ }
211
+ return (_jsx("div", { className: `${className}`, style: style, children: "WeeklyCalendar" }));
212
+ };
213
+ export const updateCalendarDateWithOffset = (offset, calendarDate) => {
214
+ const newDate = new Date(calendarDate);
215
+ newDate.setDate(newDate.getDate() + offset);
216
+ return newDate;
217
+ };
218
+ export const updateOffsetWithDateCalendar = (calendarDate) => {
219
+ return calculerEcartSemaine(calendarDate);
220
+ };
221
+ export const millisecondsToHours = (milliseconds) => {
222
+ return millisecondsToDate(milliseconds).formattedDate;
223
+ };
224
+ export default Calendar;