@pisell/date-picker 1.0.84 → 1.0.86

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.
@@ -92,9 +92,10 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
92
92
  _useState4 = _slicedToArray(_useState3, 2),
93
93
  currentShortcut = _useState4[0],
94
94
  setCurrentShortcut = _useState4[1];
95
-
96
- // const [rangePosition, setRangePosition] = useState('start');
97
-
95
+ var _useState5 = useState('start'),
96
+ _useState6 = _slicedToArray(_useState5, 2),
97
+ rangePosition = _useState6[0],
98
+ setRangePosition = _useState6[1];
98
99
  var lastConfirmShortcut = useRef(isString(propsValue) ? propsValue : null);
99
100
  useEffect(function () {
100
101
  isBoolean(propsOpen) && setOpen(propsOpen);
@@ -102,12 +103,12 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
102
103
  var _presets = useMemo(function () {
103
104
  return formatPresets(presets || defaultPresets, locale);
104
105
  }, [presets]);
105
- var _useState5 = useState(function () {
106
+ var _useState7 = useState(function () {
106
107
  return transDayjsArr(propsValue, defaultValue, _presets);
107
108
  }),
108
- _useState6 = _slicedToArray(_useState5, 2),
109
- _value = _useState6[0],
110
- setValue = _useState6[1];
109
+ _useState8 = _slicedToArray(_useState7, 2),
110
+ _value = _useState8[0],
111
+ setValue = _useState8[1];
111
112
  useEffect(function () {
112
113
  setValue(transDayjsArr(propsValue, defaultValue, _presets));
113
114
  if (isString(propsValue)) {
@@ -162,11 +163,12 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
162
163
  return item || null;
163
164
  });
164
165
  }
165
- if (!clearEndOnSelection) {
166
- if (newVal[0] && !newVal[1]) {
167
- newVal[1] = newVal[0];
168
- } else if (newVal[1] && !newVal[0]) {
169
- newVal[0] = newVal[1];
166
+ if (!clearEndOnSelection && type !== "shortcuts" && type !== "write") {
167
+ if (rangePosition === 'start') {
168
+ newVal = [newVal[0], newVal[0]];
169
+ }
170
+ if (!newVal[1]) {
171
+ newVal = [newVal[0], newVal[0]];
170
172
  }
171
173
  }
172
174
  if (clearEndOnSelection && type !== "set" && _value.filter(Boolean).length === 2) {
@@ -207,7 +209,7 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
207
209
  if (inputReadOnly) {
208
210
  return {
209
211
  readOnly: true,
210
- selectedSections: null
212
+ selectedSections: 0
211
213
  };
212
214
  }
213
215
  return {};
@@ -262,18 +264,13 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
262
264
  onClose: handleClose,
263
265
  onChange: handleChange,
264
266
  onOpen: handleOpen,
265
- open: open
266
- // onRangePositionChange={(rp) => {
267
- // console.log(rp, "rangePosition");
268
- // // if (_value.every(item => !Boolean(item))) {
269
- // // return
270
- // // } else {
271
- // setRangePosition(rp)
272
- // // }
273
- // }}
267
+ open: open,
268
+ onRangePositionChange: function onRangePositionChange(rp) {
269
+ setRangePosition(rp);
270
+ }
274
271
  // defaultRangePosition="start"
275
- // rangePosition={rangePosition}
276
272
  ,
273
+ rangePosition: rangePosition,
277
274
  defaultCalendarMonth: defaultCalendarMonth,
278
275
  shouldDisableDate: function shouldDisableDate(current, position) {
279
276
  return disabledDate === null || disabledDate === void 0 ? void 0 : disabledDate(current, position, _value);
@@ -290,6 +287,7 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
290
287
  dayOfWeekFormatter: function dayOfWeekFormatter(day) {
291
288
  return day;
292
289
  },
290
+ disableDragEditing: true,
293
291
  slotProps: {
294
292
  shortcuts: {
295
293
  items: [],
@@ -60,14 +60,14 @@ var Toolbar = function Toolbar(props) {
60
60
  var handleStartChange = function handleStartChange(e) {
61
61
  var val = e.target.value;
62
62
  setStartStr(val);
63
- if (isValidDate(val, format)) {
63
+ if (isValidDate(val, format) && (value[1] ? dayjs(val, format) <= value[1] : true)) {
64
64
  var _start$set, _start$set$set;
65
65
  setStartError(false);
66
66
  var valDate = dayjs(val, format);
67
67
  var newValue = _toConsumableArray(value);
68
68
  var start = newValue[0] || dayjs();
69
69
  newValue[0] = (start === null || start === void 0 ? void 0 : (_start$set = start.set('year', (valDate === null || valDate === void 0 ? void 0 : valDate.get('year')) || 0)) === null || _start$set === void 0 ? void 0 : (_start$set$set = _start$set.set('month', (valDate === null || valDate === void 0 ? void 0 : valDate.get('month')) || 0)) === null || _start$set$set === void 0 ? void 0 : _start$set$set.set('date', (valDate === null || valDate === void 0 ? void 0 : valDate.get('date')) || 0)) || null;
70
- onChange(newValue);
70
+ onChange(newValue, 'write');
71
71
  } else {
72
72
  setStartError(true);
73
73
  }
@@ -75,14 +75,14 @@ var Toolbar = function Toolbar(props) {
75
75
  var handleEndChange = function handleEndChange(e) {
76
76
  var val = e.target.value;
77
77
  setEndStr(val);
78
- if (isValidDate(val, format)) {
78
+ if (isValidDate(val, format) && (value[0] ? dayjs(val, format) >= value[0] : true)) {
79
79
  var _end$set, _end$set$set;
80
80
  setEndError(false);
81
81
  var valDate = dayjs(val, format);
82
82
  var newValue = _toConsumableArray(value);
83
83
  var end = newValue[1] || dayjs();
84
84
  newValue[1] = (end === null || end === void 0 ? void 0 : (_end$set = end.set('year', (valDate === null || valDate === void 0 ? void 0 : valDate.get('year')) || 0)) === null || _end$set === void 0 ? void 0 : (_end$set$set = _end$set.set('month', (valDate === null || valDate === void 0 ? void 0 : valDate.get('month')) || 0)) === null || _end$set$set === void 0 ? void 0 : _end$set$set.set('date', (valDate === null || valDate === void 0 ? void 0 : valDate.get('date')) || 0)) || null;
85
- onChange(newValue);
85
+ onChange(newValue, 'write');
86
86
  } else {
87
87
  setEndError(true);
88
88
  }
@@ -101,6 +101,7 @@ var PisellDateRangePicker = (props) => {
101
101
  const [open, setOpen] = (0, import_react.useState)(propsOpen ?? false);
102
102
  const { locale } = (0, import_react.useContext)(import_LocaleContext.LocaleContext) || {};
103
103
  const [currentShortcut, setCurrentShortcut] = (0, import_react.useState)("");
104
+ const [rangePosition, setRangePosition] = (0, import_react.useState)("start");
104
105
  const lastConfirmShortcut = (0, import_react.useRef)((0, import_utils.isString)(propsValue) ? propsValue : null);
105
106
  (0, import_react.useEffect)(() => {
106
107
  (0, import_utils.isBoolean)(propsOpen) && setOpen(propsOpen);
@@ -164,11 +165,12 @@ var PisellDateRangePicker = (props) => {
164
165
  return item || null;
165
166
  });
166
167
  }
167
- if (!clearEndOnSelection) {
168
- if (newVal[0] && !newVal[1]) {
169
- newVal[1] = newVal[0];
170
- } else if (newVal[1] && !newVal[0]) {
171
- newVal[0] = newVal[1];
168
+ if (!clearEndOnSelection && type !== "shortcuts" && type !== "write") {
169
+ if (rangePosition === "start") {
170
+ newVal = [newVal[0], newVal[0]];
171
+ }
172
+ if (!newVal[1]) {
173
+ newVal = [newVal[0], newVal[0]];
172
174
  }
173
175
  }
174
176
  if (clearEndOnSelection && type !== "set" && _value.filter(Boolean).length === 2) {
@@ -210,7 +212,7 @@ var PisellDateRangePicker = (props) => {
210
212
  if (inputReadOnly) {
211
213
  return {
212
214
  readOnly: true,
213
- selectedSections: null
215
+ selectedSections: 0
214
216
  };
215
217
  }
216
218
  return {};
@@ -262,6 +264,10 @@ var PisellDateRangePicker = (props) => {
262
264
  onChange: handleChange,
263
265
  onOpen: handleOpen,
264
266
  open,
267
+ onRangePositionChange: (rp) => {
268
+ setRangePosition(rp);
269
+ },
270
+ rangePosition,
265
271
  defaultCalendarMonth,
266
272
  shouldDisableDate: (current, position) => disabledDate == null ? void 0 : disabledDate(current, position, _value),
267
273
  slots: {
@@ -276,6 +282,7 @@ var PisellDateRangePicker = (props) => {
276
282
  dayOfWeekFormatter: (day) => {
277
283
  return day;
278
284
  },
285
+ disableDragEditing: true,
279
286
  slotProps: {
280
287
  shortcuts: {
281
288
  items: [],
@@ -74,13 +74,13 @@ var Toolbar = (props) => {
74
74
  var _a, _b;
75
75
  const val = e.target.value;
76
76
  setStartStr(val);
77
- if (isValidDate(val, format)) {
77
+ if (isValidDate(val, format) && (value[1] ? (0, import_dayjs.default)(val, format) <= value[1] : true)) {
78
78
  setStartError(false);
79
79
  const valDate = (0, import_dayjs.default)(val, format);
80
80
  const newValue = [...value];
81
81
  const start = newValue[0] || (0, import_dayjs.default)();
82
82
  newValue[0] = ((_b = (_a = start == null ? void 0 : start.set("year", (valDate == null ? void 0 : valDate.get("year")) || 0)) == null ? void 0 : _a.set("month", (valDate == null ? void 0 : valDate.get("month")) || 0)) == null ? void 0 : _b.set("date", (valDate == null ? void 0 : valDate.get("date")) || 0)) || null;
83
- onChange(newValue);
83
+ onChange(newValue, "write");
84
84
  } else {
85
85
  setStartError(true);
86
86
  }
@@ -89,13 +89,13 @@ var Toolbar = (props) => {
89
89
  var _a, _b;
90
90
  const val = e.target.value;
91
91
  setEndStr(val);
92
- if (isValidDate(val, format)) {
92
+ if (isValidDate(val, format) && (value[0] ? (0, import_dayjs.default)(val, format) >= value[0] : true)) {
93
93
  setEndError(false);
94
94
  const valDate = (0, import_dayjs.default)(val, format);
95
95
  const newValue = [...value];
96
96
  const end = newValue[1] || (0, import_dayjs.default)();
97
97
  newValue[1] = ((_b = (_a = end == null ? void 0 : end.set("year", (valDate == null ? void 0 : valDate.get("year")) || 0)) == null ? void 0 : _a.set("month", (valDate == null ? void 0 : valDate.get("month")) || 0)) == null ? void 0 : _b.set("date", (valDate == null ? void 0 : valDate.get("date")) || 0)) || null;
98
- onChange(newValue);
98
+ onChange(newValue, "write");
99
99
  } else {
100
100
  setEndError(true);
101
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/date-picker",
3
- "version": "1.0.84",
3
+ "version": "1.0.86",
4
4
  "sideEffects": [
5
5
  "*.less"
6
6
  ],
@@ -26,7 +26,7 @@
26
26
  "antd": "^5.5.0",
27
27
  "react": "^18.0.0",
28
28
  "react-dom": "^18.0.0",
29
- "@pisell/utils": "1.0.27"
29
+ "@pisell/utils": "1.0.25"
30
30
  },
31
31
  "files": [
32
32
  "es",