@douyinfe/semi-foundation 2.10.0 → 2.10.4

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.
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-nested-ternary */
2
2
  /* eslint-disable max-len, max-depth, */
3
3
  import { format, isValid, isSameSecond, isEqual as isDateEqual, isDate } from 'date-fns';
4
- import { get, isObject, isString, isEqual } from 'lodash';
4
+ import { get, isObject, isString, isEqual, isFunction } from 'lodash';
5
5
 
6
6
  import BaseFoundation, { DefaultAdapter } from '../base/foundation';
7
7
  import { isValidDate, isTimestamp } from './_utils/index';
@@ -244,12 +244,25 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
244
244
  this._adapter.updatePrevTimezone(prevTimeZone);
245
245
  this._adapter.updateInputValue(null);
246
246
  this._adapter.updateValue(result);
247
+ this.initRangeInputFocus(result);
247
248
 
248
249
  if (this._adapter.needConfirm()) {
249
250
  this._adapter.updateCachedSelectedValue(result);
250
251
  }
251
252
  }
252
253
 
254
+ /**
255
+ * 如果用户传了一个空的 value,需要把 range input focus 设置为 rangeStart,这样用户可以清除完之后继续从开始选择
256
+ *
257
+ * If the user passes an empty value, you need to set the range input focus to rangeStart, so that the user can continue to select from the beginning after clearing
258
+ */
259
+ initRangeInputFocus(result: Date[]) {
260
+ const { triggerRender } = this.getProps();
261
+ if (this._isRangeType() && isFunction(triggerRender) && result.length === 0) {
262
+ this._adapter.setRangeInputFocus('rangeStart');
263
+ }
264
+ }
265
+
253
266
  parseWithTimezone(value: ValueType, timeZone: string | number, prevTimeZone: string | number) {
254
267
  const result: Date[] = [];
255
268
  if (Array.isArray(value) && value.length) {
@@ -1161,7 +1174,7 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
1161
1174
  * @returns
1162
1175
  */
1163
1176
  handleTriggerWrapperClick(e: any) {
1164
- const { disabled } = this._adapter.getProps();
1177
+ const { disabled, triggerRender } = this._adapter.getProps();
1165
1178
  const { rangeInputFocus } = this._adapter.getStates();
1166
1179
  if (disabled) {
1167
1180
  return;
@@ -1173,12 +1186,18 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
1173
1186
  * - When type is not range type, Input component will automatically focus in the same case
1174
1187
  * - isEventTarget is used to judge whether the event is a bubbling event
1175
1188
  */
1176
- if (this._isRangeType() && !rangeInputFocus && this._adapter.isEventTarget(e)) {
1177
- setTimeout(() => {
1178
- // using setTimeout get correct state value 'rangeInputFocus'
1179
- this.handleInputFocus(e, 'rangeStart');
1180
- this.openPanel();
1181
- }, 0);
1189
+ if (this._isRangeType() && !rangeInputFocus) {
1190
+ if (this._adapter.isEventTarget(e)) {
1191
+ setTimeout(() => {
1192
+ // using setTimeout get correct state value 'rangeInputFocus'
1193
+ this.handleInputFocus(e, 'rangeStart');
1194
+ }, 0);
1195
+ } else if (isFunction(triggerRender)) {
1196
+ // 如果是 triggerRender 场景,因为没有 input,因此打开面板时默认 focus 在 rangeStart
1197
+ // If it is a triggerRender scene, because there is no input, the default focus is rangeStart when the panel is opened
1198
+ this._adapter.setRangeInputFocus('rangeStart');
1199
+ }
1200
+ this.openPanel();
1182
1201
  } else {
1183
1202
  this.openPanel();
1184
1203
  }
@@ -720,9 +720,8 @@ export default class MonthsGridFoundation extends BaseFoundation<MonthsGridAdapt
720
720
  /**
721
721
  * no need to check focus then
722
722
  * - dateRange and isDateRangeAndHasOffset
723
- * - dateRange and triggerRender
724
723
  */
725
- const needCheckFocusRecord = !(type === 'dateRange' && (isDateRangeAndHasOffset || isFunction(triggerRender)));
724
+ const needCheckFocusRecord = !(type === 'dateRange' && isDateRangeAndHasOffset);
726
725
  this._adapter.notifySelectedChange(date, { needCheckFocusRecord });
727
726
  }
728
727
  }
@@ -185,6 +185,12 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
185
185
  initFromProps({ value, timeZone, prevTimeZone }: Pick<DatePickerFoundationProps, 'value' | 'timeZone'> & {
186
186
  prevTimeZone?: string | number;
187
187
  }): void;
188
+ /**
189
+ * 如果用户传了一个空的 value,需要把 range input focus 设置为 rangeStart,这样用户可以清除完之后继续从开始选择
190
+ *
191
+ * If the user passes an empty value, you need to set the range input focus to rangeStart, so that the user can continue to select from the beginning after clearing
192
+ */
193
+ initRangeInputFocus(result: Date[]): void;
188
194
  parseWithTimezone(value: ValueType, timeZone: string | number, prevTimeZone: string | number): Date[];
189
195
  _isMultiple(): boolean;
190
196
  /**
@@ -38,6 +38,8 @@ var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable
38
38
 
39
39
  var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
40
40
 
41
+ var _isFunction2 = _interopRequireDefault(require("lodash/isFunction"));
42
+
41
43
  var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
42
44
 
43
45
  var _isString2 = _interopRequireDefault(require("lodash/isString"));
@@ -173,10 +175,28 @@ class DatePickerFoundation extends _foundation.default {
173
175
 
174
176
  this._adapter.updateValue(result);
175
177
 
178
+ this.initRangeInputFocus(result);
179
+
176
180
  if (this._adapter.needConfirm()) {
177
181
  this._adapter.updateCachedSelectedValue(result);
178
182
  }
179
183
  }
184
+ /**
185
+ * 如果用户传了一个空的 value,需要把 range input focus 设置为 rangeStart,这样用户可以清除完之后继续从开始选择
186
+ *
187
+ * If the user passes an empty value, you need to set the range input focus to rangeStart, so that the user can continue to select from the beginning after clearing
188
+ */
189
+
190
+
191
+ initRangeInputFocus(result) {
192
+ const {
193
+ triggerRender
194
+ } = this.getProps();
195
+
196
+ if (this._isRangeType() && (0, _isFunction2.default)(triggerRender) && result.length === 0) {
197
+ this._adapter.setRangeInputFocus('rangeStart');
198
+ }
199
+ }
180
200
 
181
201
  parseWithTimezone(value, timeZone, prevTimeZone) {
182
202
  const result = [];
@@ -1270,7 +1290,8 @@ class DatePickerFoundation extends _foundation.default {
1270
1290
 
1271
1291
  handleTriggerWrapperClick(e) {
1272
1292
  const {
1273
- disabled
1293
+ disabled,
1294
+ triggerRender
1274
1295
  } = this._adapter.getProps();
1275
1296
 
1276
1297
  const {
@@ -1289,12 +1310,19 @@ class DatePickerFoundation extends _foundation.default {
1289
1310
  */
1290
1311
 
1291
1312
 
1292
- if (this._isRangeType() && !rangeInputFocus && this._adapter.isEventTarget(e)) {
1293
- (0, _setTimeout2.default)(() => {
1294
- // using setTimeout get correct state value 'rangeInputFocus'
1295
- this.handleInputFocus(e, 'rangeStart');
1296
- this.openPanel();
1297
- }, 0);
1313
+ if (this._isRangeType() && !rangeInputFocus) {
1314
+ if (this._adapter.isEventTarget(e)) {
1315
+ (0, _setTimeout2.default)(() => {
1316
+ // using setTimeout get correct state value 'rangeInputFocus'
1317
+ this.handleInputFocus(e, 'rangeStart');
1318
+ }, 0);
1319
+ } else if ((0, _isFunction2.default)(triggerRender)) {
1320
+ // 如果是 triggerRender 场景,因为没有 input,因此打开面板时默认 focus 在 rangeStart
1321
+ // If it is a triggerRender scene, because there is no input, the default focus is rangeStart when the panel is opened
1322
+ this._adapter.setRangeInputFocus('rangeStart');
1323
+ }
1324
+
1325
+ this.openPanel();
1298
1326
  } else {
1299
1327
  this.openPanel();
1300
1328
  }
@@ -28,8 +28,6 @@ var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-sta
28
28
 
29
29
  var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
30
30
 
31
- var _isFunction2 = _interopRequireDefault(require("lodash/isFunction"));
32
-
33
31
  var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
34
32
 
35
33
  var _isSet2 = _interopRequireDefault(require("lodash/isSet"));
@@ -828,11 +826,10 @@ class MonthsGridFoundation extends _foundation.default {
828
826
  /**
829
827
  * no need to check focus then
830
828
  * - dateRange and isDateRangeAndHasOffset
831
- * - dateRange and triggerRender
832
829
  */
833
830
 
834
831
 
835
- const needCheckFocusRecord = !(type === 'dateRange' && (isDateRangeAndHasOffset || (0, _isFunction2.default)(triggerRender)));
832
+ const needCheckFocusRecord = !(type === 'dateRange' && isDateRangeAndHasOffset);
836
833
 
837
834
  this._adapter.notifySelectedChange(date, {
838
835
  needCheckFocusRecord
@@ -1092,6 +1092,7 @@ class UploadFoundation extends _foundation.default {
1092
1092
  if (!disabled) {
1093
1093
  if (directory) {
1094
1094
  this.handleDirectoryDrop(e);
1095
+ return;
1095
1096
  }
1096
1097
 
1097
1098
  const files = (0, _from.default)(e.dataTransfer.files);
@@ -185,6 +185,12 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
185
185
  initFromProps({ value, timeZone, prevTimeZone }: Pick<DatePickerFoundationProps, 'value' | 'timeZone'> & {
186
186
  prevTimeZone?: string | number;
187
187
  }): void;
188
+ /**
189
+ * 如果用户传了一个空的 value,需要把 range input focus 设置为 rangeStart,这样用户可以清除完之后继续从开始选择
190
+ *
191
+ * If the user passes an empty value, you need to set the range input focus to rangeStart, so that the user can continue to select from the beginning after clearing
192
+ */
193
+ initRangeInputFocus(result: Date[]): void;
188
194
  parseWithTimezone(value: ValueType, timeZone: string | number, prevTimeZone: string | number): Date[];
189
195
  _isMultiple(): boolean;
190
196
  /**
@@ -1,3 +1,4 @@
1
+ import _isFunction from "lodash/isFunction";
1
2
  import _isEqual from "lodash/isEqual";
2
3
  import _isString from "lodash/isString";
3
4
  import _isObject from "lodash/isObject";
@@ -133,10 +134,28 @@ export default class DatePickerFoundation extends BaseFoundation {
133
134
 
134
135
  this._adapter.updateValue(result);
135
136
 
137
+ this.initRangeInputFocus(result);
138
+
136
139
  if (this._adapter.needConfirm()) {
137
140
  this._adapter.updateCachedSelectedValue(result);
138
141
  }
139
142
  }
143
+ /**
144
+ * 如果用户传了一个空的 value,需要把 range input focus 设置为 rangeStart,这样用户可以清除完之后继续从开始选择
145
+ *
146
+ * If the user passes an empty value, you need to set the range input focus to rangeStart, so that the user can continue to select from the beginning after clearing
147
+ */
148
+
149
+
150
+ initRangeInputFocus(result) {
151
+ const {
152
+ triggerRender
153
+ } = this.getProps();
154
+
155
+ if (this._isRangeType() && _isFunction(triggerRender) && result.length === 0) {
156
+ this._adapter.setRangeInputFocus('rangeStart');
157
+ }
158
+ }
140
159
 
141
160
  parseWithTimezone(value, timeZone, prevTimeZone) {
142
161
  const result = [];
@@ -1238,7 +1257,8 @@ export default class DatePickerFoundation extends BaseFoundation {
1238
1257
 
1239
1258
  handleTriggerWrapperClick(e) {
1240
1259
  const {
1241
- disabled
1260
+ disabled,
1261
+ triggerRender
1242
1262
  } = this._adapter.getProps();
1243
1263
 
1244
1264
  const {
@@ -1257,12 +1277,19 @@ export default class DatePickerFoundation extends BaseFoundation {
1257
1277
  */
1258
1278
 
1259
1279
 
1260
- if (this._isRangeType() && !rangeInputFocus && this._adapter.isEventTarget(e)) {
1261
- _setTimeout(() => {
1262
- // using setTimeout get correct state value 'rangeInputFocus'
1263
- this.handleInputFocus(e, 'rangeStart');
1264
- this.openPanel();
1265
- }, 0);
1280
+ if (this._isRangeType() && !rangeInputFocus) {
1281
+ if (this._adapter.isEventTarget(e)) {
1282
+ _setTimeout(() => {
1283
+ // using setTimeout get correct state value 'rangeInputFocus'
1284
+ this.handleInputFocus(e, 'rangeStart');
1285
+ }, 0);
1286
+ } else if (_isFunction(triggerRender)) {
1287
+ // 如果是 triggerRender 场景,因为没有 input,因此打开面板时默认 focus 在 rangeStart
1288
+ // If it is a triggerRender scene, because there is no input, the default focus is rangeStart when the panel is opened
1289
+ this._adapter.setRangeInputFocus('rangeStart');
1290
+ }
1291
+
1292
+ this.openPanel();
1266
1293
  } else {
1267
1294
  this.openPanel();
1268
1295
  }
@@ -1,4 +1,3 @@
1
- import _isFunction from "lodash/isFunction";
2
1
  import _isEqual from "lodash/isEqual";
3
2
  import _isSet from "lodash/isSet";
4
3
  import _includes from "lodash/includes";
@@ -800,11 +799,10 @@ export default class MonthsGridFoundation extends BaseFoundation {
800
799
  /**
801
800
  * no need to check focus then
802
801
  * - dateRange and isDateRangeAndHasOffset
803
- * - dateRange and triggerRender
804
802
  */
805
803
 
806
804
 
807
- const needCheckFocusRecord = !(type === 'dateRange' && (isDateRangeAndHasOffset || _isFunction(triggerRender)));
805
+ const needCheckFocusRecord = !(type === 'dateRange' && isDateRangeAndHasOffset);
808
806
 
809
807
  this._adapter.notifySelectedChange(date, {
810
808
  needCheckFocusRecord
@@ -1086,6 +1086,7 @@ class UploadFoundation extends BaseFoundation {
1086
1086
  if (!disabled) {
1087
1087
  if (directory) {
1088
1088
  this.handleDirectoryDrop(e);
1089
+ return;
1089
1090
  }
1090
1091
 
1091
1092
  const files = _Array$from(e.dataTransfer.files);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-foundation",
3
- "version": "2.10.0",
3
+ "version": "2.10.4",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build:lib": "node ./scripts/compileLib.js",
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "@babel/runtime-corejs3": "^7.15.4",
11
- "@douyinfe/semi-animation": "2.10.0",
11
+ "@douyinfe/semi-animation": "2.10.4",
12
12
  "async-validator": "^3.5.0",
13
13
  "classnames": "^2.2.6",
14
14
  "date-fns": "^2.9.0",
@@ -24,7 +24,7 @@
24
24
  "*.scss",
25
25
  "*.css"
26
26
  ],
27
- "gitHead": "0cbe3b9873aa550afa2eda0997eaa7015983fe0d",
27
+ "gitHead": "5c0370819f1ab319ceded2fbf0c9c7a12e4f1b77",
28
28
  "devDependencies": {
29
29
  "@babel/plugin-proposal-decorators": "^7.15.8",
30
30
  "@babel/plugin-transform-runtime": "^7.15.8",
@@ -773,6 +773,7 @@ class UploadFoundation<P = Record<string, any>, S = Record<string, any>> extends
773
773
  if (!disabled) {
774
774
  if (directory) {
775
775
  this.handleDirectoryDrop(e);
776
+ return;
776
777
  }
777
778
  const files: File[] = Array.from(e.dataTransfer.files);
778
779
  this.handleChange(files);