@rc-component/picker 1.9.0 → 1.9.1

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.
@@ -355,6 +355,7 @@ function RangePicker(props, ref) {
355
355
  var onPresetSubmit = function onPresetSubmit(nextValues) {
356
356
  var passed = triggerSubmitChange(nextValues);
357
357
  if (passed) {
358
+ lastOperation('preset-click');
358
359
  triggerOpen(false, {
359
360
  force: true
360
361
  });
@@ -98,6 +98,8 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
98
98
  // ========================= Refs =========================
99
99
  var holderRef = React.useRef(null);
100
100
  var inputRef = React.useRef(null);
101
+ // When mousedown get focus, defer selection to mouseUp so click position is used
102
+ var mouseDownRef = React.useRef(false);
101
103
  React.useImperativeHandle(ref, function () {
102
104
  return {
103
105
  nativeElement: holderRef.current,
@@ -156,6 +158,12 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
156
158
  }
157
159
  };
158
160
  var onFormatPaste = function onFormatPaste(event) {
161
+ // Block paste until selection is set (after mouseUp when focus was by mousedown)
162
+ if (mouseDownRef.current) {
163
+ event.preventDefault();
164
+ return;
165
+ }
166
+
159
167
  // Get paste text
160
168
  var pasteText = event.clipboardData.getData('text');
161
169
  if (validateFormat(pasteText)) {
@@ -166,7 +174,6 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
166
174
  // ======================== Mouse =========================
167
175
  // When `mouseDown` get focus, it's better to not to change the selection
168
176
  // Since the up position maybe not is the first cell
169
- var mouseDownRef = React.useRef(false);
170
177
  var onFormatMouseDown = function onFormatMouseDown() {
171
178
  mouseDownRef.current = true;
172
179
  };
@@ -213,6 +220,11 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
213
220
  onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);
214
221
  };
215
222
  var onFormatKeyDown = function onFormatKeyDown(event) {
223
+ // Block key input until selection is set (after mouseUp when focus was by mousedown)
224
+ if (mouseDownRef.current) {
225
+ event.preventDefault();
226
+ return;
227
+ }
216
228
  onSharedKeyDown(event);
217
229
  var key = event.key;
218
230
 
@@ -5,4 +5,4 @@ import * as React from 'react';
5
5
  */
6
6
  export declare function fillClearIcon(prefixCls: string, allowClear?: boolean | {
7
7
  clearIcon?: ReactNode;
8
- }, clearIcon?: ReactNode): string | number | true | Iterable<ReactNode> | React.JSX.Element;
8
+ }, clearIcon?: ReactNode): string | number | true | React.JSX.Element | Iterable<ReactNode>;
@@ -4,7 +4,4 @@ export type IsInvalidBoundary<DateType> = (currentDate: DateType, type: Internal
4
4
  /**
5
5
  * Merge `disabledDate` with `minDate` & `maxDate`.
6
6
  */
7
- export default function useDisabledBoundary<DateType extends object = any>(generateConfig: GenerateConfig<DateType>, locale: Locale, disabledDate?: DisabledDate<DateType>, minDate?: DateType, maxDate?: DateType): (date: DateType, info: {
8
- type: import("../../interface").PanelMode;
9
- from?: DateType;
10
- }) => boolean;
7
+ export default function useDisabledBoundary<DateType extends object = any>(generateConfig: GenerateConfig<DateType>, locale: Locale, disabledDate?: DisabledDate<DateType>, minDate?: DateType, maxDate?: DateType): DisabledDate<DateType>;
@@ -1,5 +1,5 @@
1
1
  import type { RangeValueType } from '../RangePicker';
2
- export type OperationType = 'input' | 'panel';
2
+ export type OperationType = 'input' | 'panel' | 'preset-click';
3
3
  export type NextActive<DateType> = (nextValue: RangeValueType<DateType>) => number | null;
4
4
  /**
5
5
  * When user first focus one input, any submit will trigger focus another one.
@@ -101,6 +101,14 @@ var parseNoMatchNotice = function parseNoMatchNotice() {
101
101
  // https://github.com/ant-design/ant-design/issues/51839
102
102
  // noteOnce(false, 'Not match any format. Please help to fire a issue about this.');
103
103
  };
104
+
105
+ // Use internal dayjs instance to avoid implicit dependency on plugins extended by external dayjs versions
106
+ var getUDayjs = function getUDayjs(value) {
107
+ if (!dayjs.isDayjs(value) || value instanceof dayjs) {
108
+ return value;
109
+ }
110
+ return dayjs(value.valueOf());
111
+ };
104
112
  var generateConfig = {
105
113
  // get
106
114
  getNow: function getNow() {
@@ -115,80 +123,80 @@ var generateConfig = {
115
123
  return dayjs(string, ['YYYY-M-DD', 'YYYY-MM-DD']);
116
124
  },
117
125
  getEndDate: function getEndDate(date) {
118
- return date.endOf('month');
126
+ return getUDayjs(date).endOf('month');
119
127
  },
120
128
  getWeekDay: function getWeekDay(date) {
121
- var clone = date.locale('en');
129
+ var clone = getUDayjs(date).locale('en');
122
130
  return clone.weekday() + clone.localeData().firstDayOfWeek();
123
131
  },
124
132
  getYear: function getYear(date) {
125
- return date.year();
133
+ return getUDayjs(date).year();
126
134
  },
127
135
  getMonth: function getMonth(date) {
128
- return date.month();
136
+ return getUDayjs(date).month();
129
137
  },
130
138
  getDate: function getDate(date) {
131
- return date.date();
139
+ return getUDayjs(date).date();
132
140
  },
133
141
  getHour: function getHour(date) {
134
- return date.hour();
142
+ return getUDayjs(date).hour();
135
143
  },
136
144
  getMinute: function getMinute(date) {
137
- return date.minute();
145
+ return getUDayjs(date).minute();
138
146
  },
139
147
  getSecond: function getSecond(date) {
140
- return date.second();
148
+ return getUDayjs(date).second();
141
149
  },
142
150
  getMillisecond: function getMillisecond(date) {
143
- return date.millisecond();
151
+ return getUDayjs(date).millisecond();
144
152
  },
145
153
  // set
146
154
  addYear: function addYear(date, diff) {
147
- return date.add(diff, 'year');
155
+ return getUDayjs(date).add(diff, 'year');
148
156
  },
149
157
  addMonth: function addMonth(date, diff) {
150
- return date.add(diff, 'month');
158
+ return getUDayjs(date).add(diff, 'month');
151
159
  },
152
160
  addDate: function addDate(date, diff) {
153
- return date.add(diff, 'day');
161
+ return getUDayjs(date).add(diff, 'day');
154
162
  },
155
163
  setYear: function setYear(date, year) {
156
- return date.year(year);
164
+ return getUDayjs(date).year(year);
157
165
  },
158
166
  setMonth: function setMonth(date, month) {
159
- return date.month(month);
167
+ return getUDayjs(date).month(month);
160
168
  },
161
169
  setDate: function setDate(date, num) {
162
- return date.date(num);
170
+ return getUDayjs(date).date(num);
163
171
  },
164
172
  setHour: function setHour(date, hour) {
165
- return date.hour(hour);
173
+ return getUDayjs(date).hour(hour);
166
174
  },
167
175
  setMinute: function setMinute(date, minute) {
168
- return date.minute(minute);
176
+ return getUDayjs(date).minute(minute);
169
177
  },
170
178
  setSecond: function setSecond(date, second) {
171
- return date.second(second);
179
+ return getUDayjs(date).second(second);
172
180
  },
173
181
  setMillisecond: function setMillisecond(date, milliseconds) {
174
- return date.millisecond(milliseconds);
182
+ return getUDayjs(date).millisecond(milliseconds);
175
183
  },
176
184
  // Compare
177
185
  isAfter: function isAfter(date1, date2) {
178
- return date1.isAfter(date2);
186
+ return getUDayjs(date1).isAfter(getUDayjs(date2));
179
187
  },
180
188
  isValidate: function isValidate(date) {
181
- return date.isValid();
189
+ return getUDayjs(date).isValid();
182
190
  },
183
191
  locale: {
184
192
  getWeekFirstDay: function getWeekFirstDay(locale) {
185
193
  return dayjs().locale(parseLocale(locale)).localeData().firstDayOfWeek();
186
194
  },
187
195
  getWeekFirstDate: function getWeekFirstDate(locale, date) {
188
- return date.locale(parseLocale(locale)).weekday(0);
196
+ return getUDayjs(date).locale(parseLocale(locale)).weekday(0);
189
197
  },
190
198
  getWeek: function getWeek(locale, date) {
191
- return date.locale(parseLocale(locale)).week();
199
+ return getUDayjs(date).locale(parseLocale(locale)).week();
192
200
  },
193
201
  getShortWeekDays: function getShortWeekDays(locale) {
194
202
  return dayjs().locale(parseLocale(locale)).localeData().weekdaysMin();
@@ -197,7 +205,7 @@ var generateConfig = {
197
205
  return dayjs().locale(parseLocale(locale)).localeData().monthsShort();
198
206
  },
199
207
  format: function format(locale, date, _format) {
200
- return date.locale(parseLocale(locale)).format(_format);
208
+ return getUDayjs(date).locale(parseLocale(locale)).format(_format);
201
209
  },
202
210
  parse: function parse(locale, text, formats) {
203
211
  var localeStr = parseLocale(locale);
@@ -2,4 +2,4 @@ import type { ReactNode } from "react";
2
2
  import React from "react";
3
3
  export declare function getClearIcon(prefixCls: string, allowClear?: boolean | {
4
4
  clearIcon?: ReactNode;
5
- }, clearIcon?: ReactNode): string | number | true | Iterable<ReactNode> | React.JSX.Element;
5
+ }, clearIcon?: ReactNode): string | number | true | React.JSX.Element | Iterable<ReactNode>;
@@ -364,6 +364,7 @@ function RangePicker(props, ref) {
364
364
  var onPresetSubmit = function onPresetSubmit(nextValues) {
365
365
  var passed = triggerSubmitChange(nextValues);
366
366
  if (passed) {
367
+ lastOperation('preset-click');
367
368
  triggerOpen(false, {
368
369
  force: true
369
370
  });
@@ -106,6 +106,8 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
106
106
  // ========================= Refs =========================
107
107
  var holderRef = React.useRef(null);
108
108
  var inputRef = React.useRef(null);
109
+ // When mousedown get focus, defer selection to mouseUp so click position is used
110
+ var mouseDownRef = React.useRef(false);
109
111
  React.useImperativeHandle(ref, function () {
110
112
  return {
111
113
  nativeElement: holderRef.current,
@@ -164,6 +166,12 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
164
166
  }
165
167
  };
166
168
  var onFormatPaste = function onFormatPaste(event) {
169
+ // Block paste until selection is set (after mouseUp when focus was by mousedown)
170
+ if (mouseDownRef.current) {
171
+ event.preventDefault();
172
+ return;
173
+ }
174
+
167
175
  // Get paste text
168
176
  var pasteText = event.clipboardData.getData('text');
169
177
  if (validateFormat(pasteText)) {
@@ -174,7 +182,6 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
174
182
  // ======================== Mouse =========================
175
183
  // When `mouseDown` get focus, it's better to not to change the selection
176
184
  // Since the up position maybe not is the first cell
177
- var mouseDownRef = React.useRef(false);
178
185
  var onFormatMouseDown = function onFormatMouseDown() {
179
186
  mouseDownRef.current = true;
180
187
  };
@@ -221,6 +228,11 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
221
228
  onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);
222
229
  };
223
230
  var onFormatKeyDown = function onFormatKeyDown(event) {
231
+ // Block key input until selection is set (after mouseUp when focus was by mousedown)
232
+ if (mouseDownRef.current) {
233
+ event.preventDefault();
234
+ return;
235
+ }
224
236
  onSharedKeyDown(event);
225
237
  var key = event.key;
226
238
 
@@ -5,4 +5,4 @@ import * as React from 'react';
5
5
  */
6
6
  export declare function fillClearIcon(prefixCls: string, allowClear?: boolean | {
7
7
  clearIcon?: ReactNode;
8
- }, clearIcon?: ReactNode): string | number | true | Iterable<ReactNode> | React.JSX.Element;
8
+ }, clearIcon?: ReactNode): string | number | true | React.JSX.Element | Iterable<ReactNode>;
@@ -4,7 +4,4 @@ export type IsInvalidBoundary<DateType> = (currentDate: DateType, type: Internal
4
4
  /**
5
5
  * Merge `disabledDate` with `minDate` & `maxDate`.
6
6
  */
7
- export default function useDisabledBoundary<DateType extends object = any>(generateConfig: GenerateConfig<DateType>, locale: Locale, disabledDate?: DisabledDate<DateType>, minDate?: DateType, maxDate?: DateType): (date: DateType, info: {
8
- type: import("../../interface").PanelMode;
9
- from?: DateType;
10
- }) => boolean;
7
+ export default function useDisabledBoundary<DateType extends object = any>(generateConfig: GenerateConfig<DateType>, locale: Locale, disabledDate?: DisabledDate<DateType>, minDate?: DateType, maxDate?: DateType): DisabledDate<DateType>;
@@ -1,5 +1,5 @@
1
1
  import type { RangeValueType } from '../RangePicker';
2
- export type OperationType = 'input' | 'panel';
2
+ export type OperationType = 'input' | 'panel' | 'preset-click';
3
3
  export type NextActive<DateType> = (nextValue: RangeValueType<DateType>) => number | null;
4
4
  /**
5
5
  * When user first focus one input, any submit will trigger focus another one.
@@ -108,6 +108,14 @@ var parseNoMatchNotice = function parseNoMatchNotice() {
108
108
  // https://github.com/ant-design/ant-design/issues/51839
109
109
  // noteOnce(false, 'Not match any format. Please help to fire a issue about this.');
110
110
  };
111
+
112
+ // Use internal dayjs instance to avoid implicit dependency on plugins extended by external dayjs versions
113
+ var getUDayjs = function getUDayjs(value) {
114
+ if (!_dayjs.default.isDayjs(value) || value instanceof _dayjs.default) {
115
+ return value;
116
+ }
117
+ return (0, _dayjs.default)(value.valueOf());
118
+ };
111
119
  var generateConfig = {
112
120
  // get
113
121
  getNow: function getNow() {
@@ -122,80 +130,80 @@ var generateConfig = {
122
130
  return (0, _dayjs.default)(string, ['YYYY-M-DD', 'YYYY-MM-DD']);
123
131
  },
124
132
  getEndDate: function getEndDate(date) {
125
- return date.endOf('month');
133
+ return getUDayjs(date).endOf('month');
126
134
  },
127
135
  getWeekDay: function getWeekDay(date) {
128
- var clone = date.locale('en');
136
+ var clone = getUDayjs(date).locale('en');
129
137
  return clone.weekday() + clone.localeData().firstDayOfWeek();
130
138
  },
131
139
  getYear: function getYear(date) {
132
- return date.year();
140
+ return getUDayjs(date).year();
133
141
  },
134
142
  getMonth: function getMonth(date) {
135
- return date.month();
143
+ return getUDayjs(date).month();
136
144
  },
137
145
  getDate: function getDate(date) {
138
- return date.date();
146
+ return getUDayjs(date).date();
139
147
  },
140
148
  getHour: function getHour(date) {
141
- return date.hour();
149
+ return getUDayjs(date).hour();
142
150
  },
143
151
  getMinute: function getMinute(date) {
144
- return date.minute();
152
+ return getUDayjs(date).minute();
145
153
  },
146
154
  getSecond: function getSecond(date) {
147
- return date.second();
155
+ return getUDayjs(date).second();
148
156
  },
149
157
  getMillisecond: function getMillisecond(date) {
150
- return date.millisecond();
158
+ return getUDayjs(date).millisecond();
151
159
  },
152
160
  // set
153
161
  addYear: function addYear(date, diff) {
154
- return date.add(diff, 'year');
162
+ return getUDayjs(date).add(diff, 'year');
155
163
  },
156
164
  addMonth: function addMonth(date, diff) {
157
- return date.add(diff, 'month');
165
+ return getUDayjs(date).add(diff, 'month');
158
166
  },
159
167
  addDate: function addDate(date, diff) {
160
- return date.add(diff, 'day');
168
+ return getUDayjs(date).add(diff, 'day');
161
169
  },
162
170
  setYear: function setYear(date, year) {
163
- return date.year(year);
171
+ return getUDayjs(date).year(year);
164
172
  },
165
173
  setMonth: function setMonth(date, month) {
166
- return date.month(month);
174
+ return getUDayjs(date).month(month);
167
175
  },
168
176
  setDate: function setDate(date, num) {
169
- return date.date(num);
177
+ return getUDayjs(date).date(num);
170
178
  },
171
179
  setHour: function setHour(date, hour) {
172
- return date.hour(hour);
180
+ return getUDayjs(date).hour(hour);
173
181
  },
174
182
  setMinute: function setMinute(date, minute) {
175
- return date.minute(minute);
183
+ return getUDayjs(date).minute(minute);
176
184
  },
177
185
  setSecond: function setSecond(date, second) {
178
- return date.second(second);
186
+ return getUDayjs(date).second(second);
179
187
  },
180
188
  setMillisecond: function setMillisecond(date, milliseconds) {
181
- return date.millisecond(milliseconds);
189
+ return getUDayjs(date).millisecond(milliseconds);
182
190
  },
183
191
  // Compare
184
192
  isAfter: function isAfter(date1, date2) {
185
- return date1.isAfter(date2);
193
+ return getUDayjs(date1).isAfter(getUDayjs(date2));
186
194
  },
187
195
  isValidate: function isValidate(date) {
188
- return date.isValid();
196
+ return getUDayjs(date).isValid();
189
197
  },
190
198
  locale: {
191
199
  getWeekFirstDay: function getWeekFirstDay(locale) {
192
200
  return (0, _dayjs.default)().locale(parseLocale(locale)).localeData().firstDayOfWeek();
193
201
  },
194
202
  getWeekFirstDate: function getWeekFirstDate(locale, date) {
195
- return date.locale(parseLocale(locale)).weekday(0);
203
+ return getUDayjs(date).locale(parseLocale(locale)).weekday(0);
196
204
  },
197
205
  getWeek: function getWeek(locale, date) {
198
- return date.locale(parseLocale(locale)).week();
206
+ return getUDayjs(date).locale(parseLocale(locale)).week();
199
207
  },
200
208
  getShortWeekDays: function getShortWeekDays(locale) {
201
209
  return (0, _dayjs.default)().locale(parseLocale(locale)).localeData().weekdaysMin();
@@ -204,7 +212,7 @@ var generateConfig = {
204
212
  return (0, _dayjs.default)().locale(parseLocale(locale)).localeData().monthsShort();
205
213
  },
206
214
  format: function format(locale, date, _format) {
207
- return date.locale(parseLocale(locale)).format(_format);
215
+ return getUDayjs(date).locale(parseLocale(locale)).format(_format);
208
216
  },
209
217
  parse: function parse(locale, text, formats) {
210
218
  var localeStr = parseLocale(locale);
@@ -2,4 +2,4 @@ import type { ReactNode } from "react";
2
2
  import React from "react";
3
3
  export declare function getClearIcon(prefixCls: string, allowClear?: boolean | {
4
4
  clearIcon?: ReactNode;
5
- }, clearIcon?: ReactNode): string | number | true | Iterable<ReactNode> | React.JSX.Element;
5
+ }, clearIcon?: ReactNode): string | number | true | React.JSX.Element | Iterable<ReactNode>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/picker",
3
- "version": "1.9.0",
3
+ "version": "1.9.1",
4
4
  "description": "React date & time picker",
5
5
  "keywords": [
6
6
  "react",