@panneau/list-calendar 3.0.222 → 3.0.224
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/package.json +12 -9
- package/lib/index.js +0 -286
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panneau/list-calendar",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.224",
|
|
4
4
|
"description": "Calendar list",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -25,8 +25,11 @@
|
|
|
25
25
|
}
|
|
26
26
|
],
|
|
27
27
|
"license": "ISC",
|
|
28
|
-
"
|
|
28
|
+
"type": "module",
|
|
29
29
|
"module": "es/index.js",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": "./es/index.js"
|
|
32
|
+
},
|
|
30
33
|
"files": [
|
|
31
34
|
"lib",
|
|
32
35
|
"es",
|
|
@@ -46,12 +49,12 @@
|
|
|
46
49
|
},
|
|
47
50
|
"dependencies": {
|
|
48
51
|
"@babel/runtime": "^7.12.5",
|
|
49
|
-
"@panneau/core": "^3.0.
|
|
50
|
-
"@panneau/element-button": "^3.0.
|
|
51
|
-
"@panneau/element-card": "^3.0.
|
|
52
|
-
"@panneau/element-icon": "^3.0.
|
|
53
|
-
"@panneau/element-loading": "^3.0.
|
|
54
|
-
"@panneau/themes": "^3.0.
|
|
52
|
+
"@panneau/core": "^3.0.224",
|
|
53
|
+
"@panneau/element-button": "^3.0.224",
|
|
54
|
+
"@panneau/element-card": "^3.0.224",
|
|
55
|
+
"@panneau/element-icon": "^3.0.224",
|
|
56
|
+
"@panneau/element-loading": "^3.0.224",
|
|
57
|
+
"@panneau/themes": "^3.0.224",
|
|
55
58
|
"classnames": "^2.5.1",
|
|
56
59
|
"date-fns": "^3.3.1",
|
|
57
60
|
"lodash": "^4.17.21",
|
|
@@ -62,5 +65,5 @@
|
|
|
62
65
|
"publishConfig": {
|
|
63
66
|
"access": "public"
|
|
64
67
|
},
|
|
65
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "c95bd465867c4c7d112bf0ed66036574cc05c627"
|
|
66
69
|
}
|
package/lib/index.js
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
-
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
7
|
-
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
8
|
-
var classNames = require('classnames');
|
|
9
|
-
var dateFns = require('date-fns');
|
|
10
|
-
var PropTypes = require('prop-types');
|
|
11
|
-
var React = require('react');
|
|
12
|
-
var reactIntl = require('react-intl');
|
|
13
|
-
var core = require('@panneau/core');
|
|
14
|
-
var Button = require('@panneau/element-button');
|
|
15
|
-
var Icon = require('@panneau/element-icon');
|
|
16
|
-
|
|
17
|
-
var styles = {"container":"panneau-list-calendar-container","inner":"panneau-list-calendar-inner","calendarHeader":"panneau-list-calendar-calendarHeader","activePeriod":"panneau-list-calendar-activePeriod","activePeriodWithDates":"panneau-list-calendar-activePeriodWithDates","arrow":"panneau-list-calendar-arrow","calendarGrid":"panneau-list-calendar-calendarGrid","calendarBox":"panneau-list-calendar-calendarBox","headerBox":"panneau-list-calendar-headerBox","day":"panneau-list-calendar-day","isToday":"panneau-list-calendar-isToday","isPast":"panneau-list-calendar-isPast","dayButton":"panneau-list-calendar-dayButton","active":"panneau-list-calendar-active"};
|
|
18
|
-
|
|
19
|
-
var propTypes = {
|
|
20
|
-
mode: PropTypes.string,
|
|
21
|
-
resource: core.PropTypes.resource.isRequired,
|
|
22
|
-
component: PropTypes.func,
|
|
23
|
-
items: core.PropTypes.items,
|
|
24
|
-
itemDateField: PropTypes.string,
|
|
25
|
-
loading: PropTypes.bool,
|
|
26
|
-
// onQueryChange: PropTypes.func,
|
|
27
|
-
filter: PropTypes.shape({
|
|
28
|
-
dates: PropTypes.arrayOf(PropTypes.string)
|
|
29
|
-
}),
|
|
30
|
-
// eslint-disable-next-line react/forbid-prop-types
|
|
31
|
-
value: PropTypes.any,
|
|
32
|
-
multiple: PropTypes.bool,
|
|
33
|
-
onDateChange: PropTypes.func,
|
|
34
|
-
onPeriodChange: PropTypes.func,
|
|
35
|
-
initialDate: PropTypes.string,
|
|
36
|
-
className: PropTypes.string
|
|
37
|
-
};
|
|
38
|
-
var defaultProps = {
|
|
39
|
-
mode: 'monthly',
|
|
40
|
-
component: null,
|
|
41
|
-
items: [],
|
|
42
|
-
itemDateField: 'date',
|
|
43
|
-
filter: null,
|
|
44
|
-
value: null,
|
|
45
|
-
multiple: false,
|
|
46
|
-
onDateChange: null,
|
|
47
|
-
onPeriodChange: null,
|
|
48
|
-
initialDate: null,
|
|
49
|
-
loading: false,
|
|
50
|
-
className: null
|
|
51
|
-
};
|
|
52
|
-
var CalendarList = function CalendarList(_ref) {
|
|
53
|
-
var mode = _ref.mode;
|
|
54
|
-
_ref.resource;
|
|
55
|
-
_ref.component;
|
|
56
|
-
var items = _ref.items,
|
|
57
|
-
itemDateField = _ref.itemDateField;
|
|
58
|
-
_ref.loading;
|
|
59
|
-
var value = _ref.value,
|
|
60
|
-
multiple = _ref.multiple,
|
|
61
|
-
onDateChange = _ref.onDateChange,
|
|
62
|
-
onPeriodChange = _ref.onPeriodChange,
|
|
63
|
-
initialDate = _ref.initialDate,
|
|
64
|
-
className = _ref.className;
|
|
65
|
-
var intl = reactIntl.useIntl();
|
|
66
|
-
var _useState = React.useState(0),
|
|
67
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
68
|
-
monthIdx = _useState2[0],
|
|
69
|
-
setMonthIdx = _useState2[1];
|
|
70
|
-
var _useState3 = React.useState(0),
|
|
71
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
72
|
-
weekIdx = _useState4[0],
|
|
73
|
-
setWeekIdx = _useState4[1];
|
|
74
|
-
var currentDate = new Date();
|
|
75
|
-
var currentYear = currentDate.getUTCFullYear();
|
|
76
|
-
var currentMonth = currentDate.getUTCMonth();
|
|
77
|
-
var currentDayOfTheMonth = currentDate.getDate();
|
|
78
|
-
var dates = (items || []).map(function (it) {
|
|
79
|
-
return it !== null && it[itemDateField] ? it[itemDateField] : null;
|
|
80
|
-
}).filter(function (d) {
|
|
81
|
-
return d !== null;
|
|
82
|
-
});
|
|
83
|
-
var parsedInitialDate = initialDate !== null ? dateFns.parseISO(initialDate) : null;
|
|
84
|
-
var partialInitialDate = parsedInitialDate !== null ? dateFns.toDate(parsedInitialDate) : new Date();
|
|
85
|
-
var finalInitialDate = mode === 'weekly' ? dateFns.startOfWeek(partialInitialDate) : partialInitialDate;
|
|
86
|
-
var activeDate = mode === 'weekly' ? dateFns.addWeeks(finalInitialDate, weekIdx) : dateFns.addMonths(finalInitialDate, monthIdx);
|
|
87
|
-
var activeYear = activeDate.getFullYear();
|
|
88
|
-
var activeMonth = activeDate.getUTCMonth();
|
|
89
|
-
var activeWeekStart = dateFns.startOfWeek(activeDate);
|
|
90
|
-
var activeWeekEnd = dateFns.endOfWeek(activeDate);
|
|
91
|
-
var days = React.useMemo(function () {
|
|
92
|
-
return [intl.formatMessage({
|
|
93
|
-
"id": "fSfLk8",
|
|
94
|
-
"defaultMessage": [{
|
|
95
|
-
"type": 0,
|
|
96
|
-
"value": "S"
|
|
97
|
-
}]
|
|
98
|
-
}), intl.formatMessage({
|
|
99
|
-
"id": "jbT/g6",
|
|
100
|
-
"defaultMessage": [{
|
|
101
|
-
"type": 0,
|
|
102
|
-
"value": "M"
|
|
103
|
-
}]
|
|
104
|
-
}), intl.formatMessage({
|
|
105
|
-
"id": "Of2stw",
|
|
106
|
-
"defaultMessage": [{
|
|
107
|
-
"type": 0,
|
|
108
|
-
"value": "T"
|
|
109
|
-
}]
|
|
110
|
-
}), intl.formatMessage({
|
|
111
|
-
"id": "BAKfhq",
|
|
112
|
-
"defaultMessage": [{
|
|
113
|
-
"type": 0,
|
|
114
|
-
"value": "W"
|
|
115
|
-
}]
|
|
116
|
-
}), intl.formatMessage({
|
|
117
|
-
"id": "DBU3cu",
|
|
118
|
-
"defaultMessage": [{
|
|
119
|
-
"type": 0,
|
|
120
|
-
"value": "T"
|
|
121
|
-
}]
|
|
122
|
-
}), intl.formatMessage({
|
|
123
|
-
"id": "J6Mhku",
|
|
124
|
-
"defaultMessage": [{
|
|
125
|
-
"type": 0,
|
|
126
|
-
"value": "F"
|
|
127
|
-
}]
|
|
128
|
-
}), intl.formatMessage({
|
|
129
|
-
"id": "0F5X3C",
|
|
130
|
-
"defaultMessage": [{
|
|
131
|
-
"type": 0,
|
|
132
|
-
"value": "S"
|
|
133
|
-
}]
|
|
134
|
-
})];
|
|
135
|
-
}, []);
|
|
136
|
-
var datesArray = [];
|
|
137
|
-
if (mode === 'weekly') {
|
|
138
|
-
// eslint-disable-next-line no-plusplus
|
|
139
|
-
for (var i = 0; i < 7; i++) {
|
|
140
|
-
var dte = dateFns.addDays(activeWeekStart, i);
|
|
141
|
-
datesArray.push(dte);
|
|
142
|
-
}
|
|
143
|
-
} else {
|
|
144
|
-
var firstDayOfActualMonth = new Date(activeYear, activeMonth, 1).getDay();
|
|
145
|
-
var dayBeforeDiff = firstDayOfActualMonth === 0 ? 6 : firstDayOfActualMonth;
|
|
146
|
-
var gridMax = 35;
|
|
147
|
-
// eslint-disable-next-line no-plusplus
|
|
148
|
-
for (var _i = 1 - dayBeforeDiff; _i <= gridMax; _i++) {
|
|
149
|
-
datesArray.push(new Date(activeYear, activeMonth, _i));
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
var onClickPeriodChange = React.useCallback(function (e, previous) {
|
|
153
|
-
e.preventDefault();
|
|
154
|
-
if (mode === 'weekly') {
|
|
155
|
-
if (previous) {
|
|
156
|
-
setWeekIdx(weekIdx - 1);
|
|
157
|
-
} else {
|
|
158
|
-
setWeekIdx(weekIdx + 1);
|
|
159
|
-
}
|
|
160
|
-
} else if (previous) {
|
|
161
|
-
setMonthIdx(monthIdx - 1);
|
|
162
|
-
} else {
|
|
163
|
-
setMonthIdx(monthIdx + 1);
|
|
164
|
-
}
|
|
165
|
-
}, [mode, monthIdx, setMonthIdx, weekIdx, setWeekIdx]);
|
|
166
|
-
React.useEffect(function () {
|
|
167
|
-
if (onPeriodChange !== null) {
|
|
168
|
-
onPeriodChange(activeDate);
|
|
169
|
-
}
|
|
170
|
-
}, [activeDate, onPeriodChange]);
|
|
171
|
-
var onSelectDate = React.useCallback(function (e, newDate) {
|
|
172
|
-
e.preventDefault();
|
|
173
|
-
if (!multiple) {
|
|
174
|
-
onDateChange(newDate ? null : newDate);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
var valuesUpdate = _toConsumableArray(dates);
|
|
178
|
-
if (!valuesUpdate.includes(newDate)) {
|
|
179
|
-
onDateChange([newDate]);
|
|
180
|
-
} else {
|
|
181
|
-
var filteredOptions = valuesUpdate.filter(function (oldDate) {
|
|
182
|
-
return oldDate !== newDate;
|
|
183
|
-
});
|
|
184
|
-
onDateChange(filteredOptions);
|
|
185
|
-
}
|
|
186
|
-
}, [dates, onDateChange, multiple, value]);
|
|
187
|
-
var weekHasDates = dates.reduce(function (acc, dte) {
|
|
188
|
-
var parseDte = dte !== null ? dateFns.parseISO(dte) : null;
|
|
189
|
-
if (parseDte !== null && dateFns.compareAsc(parseDte, activeWeekStart) >= 0 && dateFns.compareDesc(parseDte, activeWeekEnd) >= 0) {
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
return acc;
|
|
193
|
-
}, false);
|
|
194
|
-
var monthHasDates = dates.reduce(function (acc, dte) {
|
|
195
|
-
var splitDate = dte.split(/\s*-\s*/g);
|
|
196
|
-
var _ref2 = splitDate || [],
|
|
197
|
-
_ref3 = _slicedToArray(_ref2, 2),
|
|
198
|
-
_ref3$ = _ref3[0],
|
|
199
|
-
year = _ref3$ === void 0 ? null : _ref3$,
|
|
200
|
-
_ref3$2 = _ref3[1],
|
|
201
|
-
month = _ref3$2 === void 0 ? null : _ref3$2;
|
|
202
|
-
if (parseInt(year, 10) === parseInt(activeYear, 10) && parseInt(month, 10) === parseInt(activeMonth, 10) + 1 // yes this is incredibly stupid
|
|
203
|
-
) {
|
|
204
|
-
return true;
|
|
205
|
-
}
|
|
206
|
-
return acc;
|
|
207
|
-
}, false);
|
|
208
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
209
|
-
className: classNames([styles.container, _defineProperty({}, className, className !== null)])
|
|
210
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
211
|
-
className: styles.inner
|
|
212
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
213
|
-
className: styles.calendarHeader
|
|
214
|
-
}, /*#__PURE__*/React.createElement(Button, {
|
|
215
|
-
className: styles.arrow,
|
|
216
|
-
onClick: function onClick(e) {
|
|
217
|
-
return onClickPeriodChange(e, true);
|
|
218
|
-
}
|
|
219
|
-
}, /*#__PURE__*/React.createElement(Icon, {
|
|
220
|
-
name: "arrow-left"
|
|
221
|
-
})), mode === 'weekly' ? /*#__PURE__*/React.createElement("div", {
|
|
222
|
-
className: styles.activePeriod
|
|
223
|
-
}, weekHasDates ? /*#__PURE__*/React.createElement("span", {
|
|
224
|
-
className: styles.activePeriodWithDates
|
|
225
|
-
}, /*#__PURE__*/React.createElement(reactIntl.FormattedDate, {
|
|
226
|
-
value: activeDate,
|
|
227
|
-
day: "numeric",
|
|
228
|
-
month: "long",
|
|
229
|
-
year: "numeric"
|
|
230
|
-
})) : /*#__PURE__*/React.createElement(reactIntl.FormattedDate, {
|
|
231
|
-
value: activeDate,
|
|
232
|
-
day: "numeric",
|
|
233
|
-
month: "long",
|
|
234
|
-
year: "numeric"
|
|
235
|
-
})) : /*#__PURE__*/React.createElement("div", {
|
|
236
|
-
className: styles.activePeriod
|
|
237
|
-
}, monthHasDates ? /*#__PURE__*/React.createElement("span", {
|
|
238
|
-
className: styles.activePeriodWithDates
|
|
239
|
-
}, /*#__PURE__*/React.createElement(reactIntl.FormattedDate, {
|
|
240
|
-
value: activeDate,
|
|
241
|
-
month: "long",
|
|
242
|
-
year: "numeric"
|
|
243
|
-
})) : /*#__PURE__*/React.createElement(reactIntl.FormattedDate, {
|
|
244
|
-
value: activeDate,
|
|
245
|
-
month: "long",
|
|
246
|
-
year: "numeric"
|
|
247
|
-
})), /*#__PURE__*/React.createElement(Button, {
|
|
248
|
-
className: classNames([styles.arrow, styles.right]),
|
|
249
|
-
onClick: onClickPeriodChange
|
|
250
|
-
}, /*#__PURE__*/React.createElement(Icon, {
|
|
251
|
-
name: "arrow-right"
|
|
252
|
-
}))), /*#__PURE__*/React.createElement("div", {
|
|
253
|
-
className: styles.calendarGrid
|
|
254
|
-
}, days.map(function (d, i) {
|
|
255
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
256
|
-
key: "day-".concat(d.getTime, "-").concat(i + 1),
|
|
257
|
-
className: classNames([styles.calendarBox, styles.headerBox])
|
|
258
|
-
}, d);
|
|
259
|
-
}), datesArray.map(function (d, i) {
|
|
260
|
-
var dTime = dateFns.format(d, 'yyyy-MM-dd');
|
|
261
|
-
var isCurrentYear = d.getUTCFullYear() === currentYear;
|
|
262
|
-
var isCurrentMonth = d.getUTCMonth() === currentMonth;
|
|
263
|
-
var isToday = isCurrentYear && isCurrentMonth && d.getDate() === currentDayOfTheMonth;
|
|
264
|
-
var eventTime = d.getTime();
|
|
265
|
-
var todayTime = currentDate.getTime();
|
|
266
|
-
var isPast = eventTime < todayTime && !isToday;
|
|
267
|
-
var hasItem = dates.includes(dTime);
|
|
268
|
-
var inner = hasItem ? /*#__PURE__*/React.createElement(Button, {
|
|
269
|
-
onClick: function onClick(e) {
|
|
270
|
-
return onSelectDate(e, dTime);
|
|
271
|
-
},
|
|
272
|
-
className: classNames(styles.day, styles.dayButton, _defineProperty(_defineProperty(_defineProperty({}, styles.isToday, isToday), styles.isPast, isPast), styles.active, dates.includes(dTime)))
|
|
273
|
-
}, dateFns.format(d, 'd')) : /*#__PURE__*/React.createElement("div", {
|
|
274
|
-
className: classNames(styles.day, _defineProperty({}, styles.isToday, isToday))
|
|
275
|
-
}, dateFns.format(d, 'd'));
|
|
276
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
277
|
-
key: "date-".concat(d.getTime, "-").concat(i + 1),
|
|
278
|
-
className: styles.calendarBox
|
|
279
|
-
}, d.getUTCMonth() !== activeMonth && mode === 'monthly' ? '' : inner);
|
|
280
|
-
}))));
|
|
281
|
-
};
|
|
282
|
-
CalendarList.propTypes = propTypes;
|
|
283
|
-
CalendarList.defaultProps = defaultProps;
|
|
284
|
-
var Calendar = CalendarList;
|
|
285
|
-
|
|
286
|
-
exports.default = Calendar;
|