@douyinfe/semi-foundation 2.10.2 → 2.11.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.
- package/checkbox/checkboxFoundation.ts +11 -2
- package/datePicker/_utils/parser.ts +21 -0
- package/datePicker/foundation.ts +144 -20
- package/datePicker/inputFoundation.ts +49 -3
- package/datePicker/monthsGridFoundation.ts +2 -2
- package/lib/cjs/checkbox/checkboxFoundation.d.ts +2 -0
- package/lib/cjs/checkbox/checkboxFoundation.js +16 -2
- package/lib/cjs/datePicker/_utils/parser.d.ts +14 -0
- package/lib/cjs/datePicker/_utils/parser.js +23 -0
- package/lib/cjs/datePicker/foundation.d.ts +34 -0
- package/lib/cjs/datePicker/foundation.js +178 -24
- package/lib/cjs/datePicker/inputFoundation.d.ts +7 -1
- package/lib/cjs/datePicker/inputFoundation.js +85 -1
- package/lib/cjs/datePicker/monthsGridFoundation.js +2 -2
- package/lib/cjs/radio/radioFoundation.d.ts +3 -0
- package/lib/cjs/radio/radioFoundation.js +17 -0
- package/lib/cjs/tooltip/foundation.d.ts +1 -0
- package/lib/cjs/tooltip/foundation.js +7 -0
- package/lib/es/checkbox/checkboxFoundation.d.ts +2 -0
- package/lib/es/checkbox/checkboxFoundation.js +16 -2
- package/lib/es/datePicker/_utils/parser.d.ts +14 -0
- package/lib/es/datePicker/_utils/parser.js +21 -0
- package/lib/es/datePicker/foundation.d.ts +34 -0
- package/lib/es/datePicker/foundation.js +177 -23
- package/lib/es/datePicker/inputFoundation.d.ts +7 -1
- package/lib/es/datePicker/inputFoundation.js +81 -1
- package/lib/es/datePicker/monthsGridFoundation.js +2 -2
- package/lib/es/radio/radioFoundation.d.ts +3 -0
- package/lib/es/radio/radioFoundation.js +17 -0
- package/lib/es/tooltip/foundation.d.ts +1 -0
- package/lib/es/tooltip/foundation.js +7 -0
- package/package.json +3 -3
- package/radio/radioFoundation.ts +11 -0
- package/tooltip/foundation.ts +5 -0
|
@@ -24,6 +24,8 @@ var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable
|
|
|
24
24
|
|
|
25
25
|
var _sort = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/sort"));
|
|
26
26
|
|
|
27
|
+
var _every = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/every"));
|
|
28
|
+
|
|
27
29
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
28
30
|
|
|
29
31
|
var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
|
|
@@ -173,9 +175,7 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
173
175
|
|
|
174
176
|
this._adapter.updateValue(result);
|
|
175
177
|
|
|
176
|
-
|
|
177
|
-
this._adapter.updateCachedSelectedValue(result);
|
|
178
|
-
}
|
|
178
|
+
this.resetCachedSelectedValue(result);
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
parseWithTimezone(value, timeZone, prevTimeZone) {
|
|
@@ -316,6 +316,10 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
316
316
|
this._adapter.updateInsetInputValue(null);
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* call it when change state value or input value
|
|
321
|
+
*/
|
|
322
|
+
|
|
319
323
|
|
|
320
324
|
resetCachedSelectedValue(willUpdateDates) {
|
|
321
325
|
const {
|
|
@@ -348,11 +352,10 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
348
352
|
let dates = arguments.length > 2 ? arguments[2] : undefined;
|
|
349
353
|
|
|
350
354
|
const {
|
|
351
|
-
value
|
|
352
|
-
cachedSelectedValue
|
|
355
|
+
value
|
|
353
356
|
} = this._adapter.getStates();
|
|
354
357
|
|
|
355
|
-
const willUpdateDates = (0, _isNullOrUndefined.default)(dates) ?
|
|
358
|
+
const willUpdateDates = (0, _isNullOrUndefined.default)(dates) ? value : dates;
|
|
356
359
|
|
|
357
360
|
if (!this._isControlledComponent('open')) {
|
|
358
361
|
this._adapter.togglePanel(false);
|
|
@@ -381,7 +384,10 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
381
384
|
const result = this._isMultiple() ? this.parseMultipleInput(input) : this.parseInput(input);
|
|
382
385
|
const {
|
|
383
386
|
value: stateValue
|
|
384
|
-
} = this.getStates();
|
|
387
|
+
} = this.getStates();
|
|
388
|
+
|
|
389
|
+
this._updateCachedSelectedValueFromInput(input); // Enter a valid date or empty
|
|
390
|
+
|
|
385
391
|
|
|
386
392
|
if (result && result.length || input === '') {
|
|
387
393
|
// If you click the clear button
|
|
@@ -397,10 +403,6 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
397
403
|
const changedDates = this._getChangedDates(result);
|
|
398
404
|
|
|
399
405
|
if (!this._someDateDisabled(changedDates)) {
|
|
400
|
-
if (this._adapter.needConfirm()) {
|
|
401
|
-
this._adapter.updateCachedSelectedValue(result);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
406
|
if (!(0, _isEqual2.default)(result, stateValue)) {
|
|
405
407
|
this._notifyChange(result);
|
|
406
408
|
}
|
|
@@ -431,16 +433,14 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
431
433
|
value: stateValue
|
|
432
434
|
} = this.getStates();
|
|
433
435
|
|
|
436
|
+
this._updateCachedSelectedValueFromInput(insetInputStr);
|
|
437
|
+
|
|
434
438
|
if (result && result.length) {
|
|
435
439
|
const changedDates = this._getChangedDates(result);
|
|
436
440
|
|
|
437
441
|
if (!this._someDateDisabled(changedDates)) {
|
|
438
|
-
if (this._adapter.needConfirm()) {
|
|
439
|
-
this._adapter.updateCachedSelectedValue(result);
|
|
440
|
-
}
|
|
441
|
-
|
|
442
442
|
if (!(0, _isEqual2.default)(result, stateValue)) {
|
|
443
|
-
if (!this._isControlledComponent()) {
|
|
443
|
+
if (!this._isControlledComponent() && !this._adapter.needConfirm()) {
|
|
444
444
|
this._adapter.updateValue(result);
|
|
445
445
|
}
|
|
446
446
|
|
|
@@ -455,6 +455,20 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
455
455
|
|
|
456
456
|
this._adapter.updateInsetInputValue(insetInputValue);
|
|
457
457
|
}
|
|
458
|
+
/**
|
|
459
|
+
* when input change we reset cached selected value
|
|
460
|
+
*/
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
_updateCachedSelectedValueFromInput(input) {
|
|
464
|
+
const looseResult = this.getLooseDateFromInput(input);
|
|
465
|
+
|
|
466
|
+
const changedLooseResult = this._getChangedDates(looseResult);
|
|
467
|
+
|
|
468
|
+
if (!this._someDateDisabled(changedLooseResult)) {
|
|
469
|
+
this.resetCachedSelectedValue(looseResult);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
458
472
|
/**
|
|
459
473
|
* Input box blur
|
|
460
474
|
* @param {String} input
|
|
@@ -476,6 +490,20 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
476
490
|
} else {
|
|
477
491
|
this._updateValueAndInput(stateValue);
|
|
478
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* 当不是范围类型且不需要确认时,使用 stateValue 重置 cachedSelectedValue
|
|
495
|
+
* 这样做的目的是,在输入非法值时,使用上次选中的值作为已选值
|
|
496
|
+
* needConfirm 或者 range type 时,我们在 close panel 时调用 resetCachedSelectedValue,这里不用重复调用
|
|
497
|
+
*
|
|
498
|
+
* Use stateValue to reset cachedSelectedValue when it is not a range type and does not require confirmation
|
|
499
|
+
* The purpose of this is to use the last selected value as the selected value when an invalid value is entered
|
|
500
|
+
* When needConfirm or range type, we call resetCachedSelectedValue when close panel, no need to call repeatedly here
|
|
501
|
+
*/
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
if (!this._adapter.needConfirm() && !this._isRangeType()) {
|
|
505
|
+
this.resetCachedSelectedValue(stateValue);
|
|
506
|
+
}
|
|
479
507
|
}
|
|
480
508
|
/**
|
|
481
509
|
* called when range type rangeEnd input tab press
|
|
@@ -532,9 +560,7 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
532
560
|
if (!this._isControlledComponent('value')) {
|
|
533
561
|
this._updateValueAndInput(value, true, inputValue);
|
|
534
562
|
|
|
535
|
-
|
|
536
|
-
this._adapter.updateCachedSelectedValue(value);
|
|
537
|
-
}
|
|
563
|
+
this.resetCachedSelectedValue(value);
|
|
538
564
|
}
|
|
539
565
|
|
|
540
566
|
this._notifyChange(value);
|
|
@@ -637,6 +663,138 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
637
663
|
|
|
638
664
|
return result;
|
|
639
665
|
}
|
|
666
|
+
/**
|
|
667
|
+
* get date which may include null from input
|
|
668
|
+
*/
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
getLooseDateFromInput(input) {
|
|
672
|
+
const value = this._isMultiple() ? this.parseMultipleInputLoose(input) : this.parseInputLoose(input);
|
|
673
|
+
return value;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* parse input into `Array<Date|null>`, loose means return value includes `null`
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```javascript
|
|
680
|
+
* parseInputLoose('2022-03-15 ~ '); // [Date, null]
|
|
681
|
+
* parseInputLoose(' ~ 2022-03-15 '); // [null, Date]
|
|
682
|
+
* parseInputLoose(''); // []
|
|
683
|
+
* parseInputLoose('2022-03- ~ 2022-0'); // [null, null]
|
|
684
|
+
* ```
|
|
685
|
+
*/
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
parseInputLoose() {
|
|
689
|
+
let input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
690
|
+
let result = [];
|
|
691
|
+
const {
|
|
692
|
+
dateFnsLocale,
|
|
693
|
+
rangeSeparator,
|
|
694
|
+
type,
|
|
695
|
+
format
|
|
696
|
+
} = this.getProps();
|
|
697
|
+
|
|
698
|
+
if (input && input.length) {
|
|
699
|
+
const formatToken = format || (0, _getDefaultFormatToken.getDefaultFormatTokenByType)(type);
|
|
700
|
+
let parsedResult, formatedInput;
|
|
701
|
+
const nowDate = new Date();
|
|
702
|
+
|
|
703
|
+
switch (type) {
|
|
704
|
+
case 'date':
|
|
705
|
+
case 'dateTime':
|
|
706
|
+
case 'month':
|
|
707
|
+
const _parsedResult = (0, _parser.compatibleParse)(input, formatToken, nowDate, dateFnsLocale);
|
|
708
|
+
|
|
709
|
+
if ((0, _index.isValidDate)(_parsedResult)) {
|
|
710
|
+
formatedInput = this.localeFormat(_parsedResult, formatToken);
|
|
711
|
+
|
|
712
|
+
if (formatedInput === input) {
|
|
713
|
+
parsedResult = _parsedResult;
|
|
714
|
+
}
|
|
715
|
+
} else {
|
|
716
|
+
parsedResult = null;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
result = [parsedResult];
|
|
720
|
+
break;
|
|
721
|
+
|
|
722
|
+
case 'dateRange':
|
|
723
|
+
case 'dateTimeRange':
|
|
724
|
+
const separator = rangeSeparator;
|
|
725
|
+
const values = input.split(separator);
|
|
726
|
+
parsedResult = values && (0, _reduce.default)(values).call(values, (arr, cur) => {
|
|
727
|
+
let parsedVal = null;
|
|
728
|
+
|
|
729
|
+
const _parsedResult = (0, _parser.compatibleParse)(cur, formatToken, nowDate, dateFnsLocale);
|
|
730
|
+
|
|
731
|
+
if ((0, _index.isValidDate)(_parsedResult)) {
|
|
732
|
+
formatedInput = this.localeFormat(_parsedResult, formatToken);
|
|
733
|
+
|
|
734
|
+
if (formatedInput === cur) {
|
|
735
|
+
parsedVal = _parsedResult;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
arr.push(parsedVal);
|
|
740
|
+
return arr;
|
|
741
|
+
}, []);
|
|
742
|
+
|
|
743
|
+
if ((0, _isArray.default)(parsedResult) && (0, _every.default)(parsedResult).call(parsedResult, item => (0, _dateFns.isValid)(item))) {
|
|
744
|
+
(0, _sort.default)(parsedResult).call(parsedResult, (d1, d2) => d1.getTime() - d2.getTime());
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
result = parsedResult;
|
|
748
|
+
break;
|
|
749
|
+
|
|
750
|
+
default:
|
|
751
|
+
break;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
return result;
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* parse multiple into `Array<Date|null>`, loose means return value includes `null`
|
|
759
|
+
*
|
|
760
|
+
* @example
|
|
761
|
+
* ```javascript
|
|
762
|
+
* parseMultipleInputLoose('2021-01-01,2021-10-15'); // [Date, Date];
|
|
763
|
+
* parseMultipleInputLoose('2021-01-01,2021-10-'); // [Date, null];
|
|
764
|
+
* parseMultipleInputLoose(''); // [];
|
|
765
|
+
* ```
|
|
766
|
+
*/
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
parseMultipleInputLoose() {
|
|
770
|
+
let input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
771
|
+
let separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _constants.strings.DEFAULT_SEPARATOR_MULTIPLE;
|
|
772
|
+
let needDedupe = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
773
|
+
const max = this.getProp('max');
|
|
774
|
+
const inputArr = input.split(separator);
|
|
775
|
+
const result = [];
|
|
776
|
+
|
|
777
|
+
for (const curInput of inputArr) {
|
|
778
|
+
let tmpParsed = curInput && this.parseInputLoose(curInput);
|
|
779
|
+
tmpParsed = (0, _isArray.default)(tmpParsed) ? tmpParsed : tmpParsed && [tmpParsed];
|
|
780
|
+
|
|
781
|
+
if (tmpParsed && tmpParsed.length) {
|
|
782
|
+
if (needDedupe) {
|
|
783
|
+
!(0, _filter.default)(result).call(result, r => Boolean((0, _find.default)(tmpParsed).call(tmpParsed, tp => (0, _dateFns.isSameSecond)(r, tp)))) && result.push(...tmpParsed);
|
|
784
|
+
} else {
|
|
785
|
+
result.push(...tmpParsed);
|
|
786
|
+
}
|
|
787
|
+
} else {
|
|
788
|
+
return [];
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
if (max && max > 0 && result.length > max) {
|
|
792
|
+
return [];
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
return result;
|
|
797
|
+
}
|
|
640
798
|
/**
|
|
641
799
|
* Parses the input when multiple is true, if valid,
|
|
642
800
|
* returns a list of time objects, otherwise returns an array
|
|
@@ -832,11 +990,6 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
832
990
|
*/
|
|
833
991
|
|
|
834
992
|
const needCheckFocusRecord = (0, _get2.default)(options, 'needCheckFocusRecord', true);
|
|
835
|
-
|
|
836
|
-
if (this._adapter.needConfirm()) {
|
|
837
|
-
this._adapter.updateCachedSelectedValue(value);
|
|
838
|
-
}
|
|
839
|
-
|
|
840
993
|
const dates = (0, _isArray.default)(value) ? [...value] : value ? [value] : [];
|
|
841
994
|
|
|
842
995
|
const changedDates = this._getChangedDates(dates);
|
|
@@ -844,6 +997,7 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
844
997
|
let inputValue, insetInputValue;
|
|
845
998
|
|
|
846
999
|
if (!this._someDateDisabled(changedDates)) {
|
|
1000
|
+
this.resetCachedSelectedValue(dates);
|
|
847
1001
|
inputValue = this._isMultiple() ? this.formatMultipleDates(dates) : this.formatDates(dates);
|
|
848
1002
|
|
|
849
1003
|
if (insetInput) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import BaseFoundation, { DefaultAdapter } from '../base/foundation';
|
|
3
|
-
import { BaseValueType, ValidateStatus } from './foundation';
|
|
3
|
+
import { BaseValueType, ValidateStatus, ValueType } from './foundation';
|
|
4
4
|
import { strings } from './constants';
|
|
5
5
|
export declare type Type = 'date' | 'dateRange' | 'year' | 'month' | 'dateTime' | 'dateTimeRange';
|
|
6
6
|
export declare type RangeType = 'rangeStart' | 'rangeEnd';
|
|
@@ -36,6 +36,7 @@ export interface DateInputFoundationProps extends DateInputElementProps, DateInp
|
|
|
36
36
|
insetInput?: boolean;
|
|
37
37
|
insetInputValue?: InsetInputValue;
|
|
38
38
|
density?: typeof strings.DENSITY_SET[number];
|
|
39
|
+
defaultPickerValue?: ValueType;
|
|
39
40
|
}
|
|
40
41
|
export interface InsetInputValue {
|
|
41
42
|
monthLeft: {
|
|
@@ -85,6 +86,11 @@ export default class InputFoundation extends BaseFoundation<DateInputAdapter> {
|
|
|
85
86
|
handleRangeInputFocus(e: any, rangeType: RangeType): void;
|
|
86
87
|
formatShowText(value: BaseValueType[], customFormat?: string): string;
|
|
87
88
|
handleInsetInputChange(options: InsetInputChangeFoundationProps): void;
|
|
89
|
+
_autoFillTimeToInsetInputValue(options: {
|
|
90
|
+
insetInputValue: InsetInputValue;
|
|
91
|
+
format: string;
|
|
92
|
+
valuePath: string;
|
|
93
|
+
}): InsetInputValue;
|
|
88
94
|
/**
|
|
89
95
|
* 只有传入的 format 符合 formatReg 时,才会使用用户传入的 format
|
|
90
96
|
* 否则会使用默认的 format 作为 placeholder
|
|
@@ -12,14 +12,20 @@ exports.default = void 0;
|
|
|
12
12
|
|
|
13
13
|
var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
|
|
14
14
|
|
|
15
|
+
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
16
|
+
|
|
15
17
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
16
18
|
|
|
19
|
+
var _get2 = _interopRequireDefault(require("lodash/get"));
|
|
20
|
+
|
|
17
21
|
var _set2 = _interopRequireDefault(require("lodash/set"));
|
|
18
22
|
|
|
19
23
|
var _isObject2 = _interopRequireDefault(require("lodash/isObject"));
|
|
20
24
|
|
|
21
25
|
var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
22
26
|
|
|
27
|
+
var _dateFns = require("date-fns");
|
|
28
|
+
|
|
23
29
|
var _foundation = _interopRequireDefault(require("../base/foundation"));
|
|
24
30
|
|
|
25
31
|
var _formatter = require("./_utils/formatter");
|
|
@@ -30,6 +36,14 @@ var _getInsetInputFormatToken = _interopRequireDefault(require("./_utils/getInse
|
|
|
30
36
|
|
|
31
37
|
var _getInsetInputValueFromInsetInputStr = _interopRequireDefault(require("./_utils/getInsetInputValueFromInsetInputStr"));
|
|
32
38
|
|
|
39
|
+
var _constants = require("./constants");
|
|
40
|
+
|
|
41
|
+
var _getDefaultPickerDate = _interopRequireDefault(require("./_utils/getDefaultPickerDate"));
|
|
42
|
+
|
|
43
|
+
var _parser = require("./_utils/parser");
|
|
44
|
+
|
|
45
|
+
var _utils = require("./_utils");
|
|
46
|
+
|
|
33
47
|
const KEY_CODE_ENTER = 'Enter';
|
|
34
48
|
const KEY_CODE_TAB = 'Tab';
|
|
35
49
|
|
|
@@ -150,7 +164,12 @@ class InputFoundation extends _foundation.default {
|
|
|
150
164
|
type,
|
|
151
165
|
format
|
|
152
166
|
});
|
|
153
|
-
|
|
167
|
+
let newInsetInputValue = (0, _set2.default)((0, _cloneDeep2.default)(insetInputValue), valuePath, value);
|
|
168
|
+
newInsetInputValue = this._autoFillTimeToInsetInputValue({
|
|
169
|
+
insetInputValue: newInsetInputValue,
|
|
170
|
+
valuePath,
|
|
171
|
+
format: insetFormatToken
|
|
172
|
+
});
|
|
154
173
|
const newInputValue = this.concatInsetInputValue({
|
|
155
174
|
insetInputValue: newInsetInputValue
|
|
156
175
|
});
|
|
@@ -161,6 +180,71 @@ class InputFoundation extends _foundation.default {
|
|
|
161
180
|
insetInputStr: newInputValue
|
|
162
181
|
});
|
|
163
182
|
}
|
|
183
|
+
|
|
184
|
+
_autoFillTimeToInsetInputValue(options) {
|
|
185
|
+
const {
|
|
186
|
+
valuePath,
|
|
187
|
+
insetInputValue,
|
|
188
|
+
format
|
|
189
|
+
} = options;
|
|
190
|
+
|
|
191
|
+
const {
|
|
192
|
+
type,
|
|
193
|
+
defaultPickerValue,
|
|
194
|
+
dateFnsLocale
|
|
195
|
+
} = this._adapter.getProps();
|
|
196
|
+
|
|
197
|
+
const insetInputValueWithTime = (0, _cloneDeep2.default)(insetInputValue);
|
|
198
|
+
const {
|
|
199
|
+
nowDate,
|
|
200
|
+
nextDate
|
|
201
|
+
} = (0, _getDefaultPickerDate.default)({
|
|
202
|
+
defaultPickerValue,
|
|
203
|
+
format,
|
|
204
|
+
dateFnsLocale
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
if ((0, _includes.default)(type).call(type, 'Time')) {
|
|
208
|
+
let timeStr = '';
|
|
209
|
+
const dateFormatToken = (0, _get2.default)(format.split(' '), '0', _constants.strings.FORMAT_FULL_DATE);
|
|
210
|
+
const timeFormatToken = (0, _get2.default)(format.split(' '), '1', _constants.strings.FORMAT_TIME_PICKER);
|
|
211
|
+
|
|
212
|
+
switch (valuePath) {
|
|
213
|
+
case 'monthLeft.dateInput':
|
|
214
|
+
const dateLeftStr = insetInputValueWithTime.monthLeft.dateInput;
|
|
215
|
+
|
|
216
|
+
if (!insetInputValueWithTime.monthLeft.timeInput && dateLeftStr.length === dateFormatToken.length) {
|
|
217
|
+
const dateLeftParsed = (0, _parser.compatibleParse)(insetInputValueWithTime.monthLeft.dateInput, dateFormatToken);
|
|
218
|
+
|
|
219
|
+
if ((0, _utils.isValidDate)(dateLeftParsed)) {
|
|
220
|
+
timeStr = (0, _dateFns.format)(nowDate, timeFormatToken);
|
|
221
|
+
insetInputValueWithTime.monthLeft.timeInput = timeStr;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
break;
|
|
226
|
+
|
|
227
|
+
case 'monthRight.dateInput':
|
|
228
|
+
const dateRightStr = insetInputValueWithTime.monthRight.dateInput;
|
|
229
|
+
|
|
230
|
+
if (!insetInputValueWithTime.monthRight.timeInput && dateRightStr.length === dateFormatToken.length) {
|
|
231
|
+
const dateRightParsed = (0, _parser.compatibleParse)(dateRightStr, dateFormatToken);
|
|
232
|
+
|
|
233
|
+
if ((0, _utils.isValidDate)(dateRightParsed)) {
|
|
234
|
+
timeStr = (0, _dateFns.format)(nextDate, timeFormatToken);
|
|
235
|
+
insetInputValueWithTime.monthRight.timeInput = timeStr;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
break;
|
|
240
|
+
|
|
241
|
+
default:
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return insetInputValueWithTime;
|
|
247
|
+
}
|
|
164
248
|
/**
|
|
165
249
|
* 只有传入的 format 符合 formatReg 时,才会使用用户传入的 format
|
|
166
250
|
* 否则会使用默认的 format 作为 placeholder
|
|
@@ -187,10 +187,10 @@ class MonthsGridFoundation extends _foundation.default {
|
|
|
187
187
|
const newSelected = new _set.default();
|
|
188
188
|
|
|
189
189
|
if (!this._isMultiple()) {
|
|
190
|
-
newSelected.add((0, _dateFns.format)(values[0], _constants.strings.FORMAT_FULL_DATE));
|
|
190
|
+
values[0] && newSelected.add((0, _dateFns.format)(values[0], _constants.strings.FORMAT_FULL_DATE));
|
|
191
191
|
} else {
|
|
192
192
|
(0, _forEach.default)(values).call(values, date => {
|
|
193
|
-
newSelected.add((0, _dateFns.format)(date, _constants.strings.FORMAT_FULL_DATE));
|
|
193
|
+
date && newSelected.add((0, _dateFns.format)(date, _constants.strings.FORMAT_FULL_DATE));
|
|
194
194
|
});
|
|
195
195
|
}
|
|
196
196
|
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import BaseFoundation, { DefaultAdapter } from '../base/foundation';
|
|
2
2
|
export interface RadioAdapter extends DefaultAdapter {
|
|
3
3
|
setHover: (hover: boolean) => void;
|
|
4
|
+
setAddonId: () => void;
|
|
5
|
+
setExtraId: () => void;
|
|
4
6
|
}
|
|
5
7
|
export default class RadioFoundation extends BaseFoundation<RadioAdapter> {
|
|
8
|
+
init(): void;
|
|
6
9
|
setHover(hover: boolean): void;
|
|
7
10
|
}
|
|
@@ -13,6 +13,23 @@ exports.default = void 0;
|
|
|
13
13
|
var _foundation = _interopRequireDefault(require("../base/foundation"));
|
|
14
14
|
|
|
15
15
|
class RadioFoundation extends _foundation.default {
|
|
16
|
+
init() {
|
|
17
|
+
const {
|
|
18
|
+
children,
|
|
19
|
+
extra,
|
|
20
|
+
extraId,
|
|
21
|
+
addonId
|
|
22
|
+
} = this._adapter.getProps();
|
|
23
|
+
|
|
24
|
+
if (children && !addonId) {
|
|
25
|
+
this._adapter.setAddonId();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (extra && !extraId) {
|
|
29
|
+
this._adapter.setExtraId();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
16
33
|
setHover(hover) {
|
|
17
34
|
this._adapter.setHover(hover);
|
|
18
35
|
}
|
|
@@ -47,6 +47,7 @@ export interface TooltipAdapter<P = Record<string, any>, S = Record<string, any>
|
|
|
47
47
|
setInitialFocus(): void;
|
|
48
48
|
notifyEscKeydown(event: any): void;
|
|
49
49
|
getTriggerNode(): any;
|
|
50
|
+
setId(): void;
|
|
50
51
|
}
|
|
51
52
|
export declare type Position = ArrayElement<typeof strings.POSITION_SET>;
|
|
52
53
|
export interface PopupContainerDOMRect extends DOMRectLikeType {
|
|
@@ -237,6 +237,9 @@ class Tooltip extends _foundation.default {
|
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
init() {
|
|
240
|
+
const {
|
|
241
|
+
wrapperId
|
|
242
|
+
} = this.getProps();
|
|
240
243
|
this._mounted = true;
|
|
241
244
|
|
|
242
245
|
this._bindEvent();
|
|
@@ -244,6 +247,10 @@ class Tooltip extends _foundation.default {
|
|
|
244
247
|
this._shouldShow();
|
|
245
248
|
|
|
246
249
|
this._initContainerPosition();
|
|
250
|
+
|
|
251
|
+
if (!wrapperId) {
|
|
252
|
+
this._adapter.setId();
|
|
253
|
+
}
|
|
247
254
|
}
|
|
248
255
|
|
|
249
256
|
destroy() {
|
|
@@ -19,6 +19,8 @@ export interface CheckboxAdapter<P = Record<string, any>, S = Record<string, any
|
|
|
19
19
|
setNativeControlChecked: (checked: boolean) => void;
|
|
20
20
|
getState: noopFunction;
|
|
21
21
|
notifyChange: (event: BasicCheckboxEvent) => void;
|
|
22
|
+
setAddonId: () => void;
|
|
23
|
+
setExtraId: () => void;
|
|
22
24
|
}
|
|
23
25
|
declare class CheckboxFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<CheckboxAdapter<P, S>, P, S> {
|
|
24
26
|
constructor(adapter: CheckboxAdapter<P, S>);
|
|
@@ -6,10 +6,24 @@ import isEnterPress from '../utils/isEnterPress';
|
|
|
6
6
|
class CheckboxFoundation extends BaseFoundation {
|
|
7
7
|
constructor(adapter) {
|
|
8
8
|
super(_Object$assign({}, adapter));
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
init() {
|
|
12
|
+
const {
|
|
13
|
+
children,
|
|
14
|
+
extra,
|
|
15
|
+
extraId,
|
|
16
|
+
addonId
|
|
17
|
+
} = this.getProps();
|
|
10
18
|
|
|
19
|
+
if (children && !addonId) {
|
|
20
|
+
this._adapter.setAddonId();
|
|
21
|
+
}
|
|
11
22
|
|
|
12
|
-
|
|
23
|
+
if (extra && !extraId) {
|
|
24
|
+
this._adapter.setExtraId();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
13
27
|
|
|
14
28
|
getEvent(checked, e) {
|
|
15
29
|
const props = this.getProps();
|
|
@@ -7,3 +7,17 @@ import { Locale } from 'date-fns';
|
|
|
7
7
|
* Parsing value to Date object
|
|
8
8
|
*/
|
|
9
9
|
export declare function compatibleParse(value: string, formatToken?: string, baseDate?: Date, locale?: Locale): Date | null;
|
|
10
|
+
/**
|
|
11
|
+
* whether value can be parsed with date-fns `parse`
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* isValueParseValid({ value: '2021-01-01', formatToken: 'yyyy-MM-dd' }); // true
|
|
15
|
+
* isValueParseValid({ value: '2021-01-0', formatToken: 'yyyy-MM-dd' }); // false
|
|
16
|
+
* isValueParseValid({ value: '2021-01', formatToken: 'yyyy-MM-dd' }); // false
|
|
17
|
+
*/
|
|
18
|
+
export declare function isValueParseValid(options: {
|
|
19
|
+
value: string;
|
|
20
|
+
formatToken: string;
|
|
21
|
+
baseDate?: Date;
|
|
22
|
+
locale?: Locale;
|
|
23
|
+
}): boolean;
|
|
@@ -34,4 +34,25 @@ export function compatibleParse(value, formatToken, baseDate, locale) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
return result;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* whether value can be parsed with date-fns `parse`
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* isValueParseValid({ value: '2021-01-01', formatToken: 'yyyy-MM-dd' }); // true
|
|
43
|
+
* isValueParseValid({ value: '2021-01-0', formatToken: 'yyyy-MM-dd' }); // false
|
|
44
|
+
* isValueParseValid({ value: '2021-01', formatToken: 'yyyy-MM-dd' }); // false
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
export function isValueParseValid(options) {
|
|
48
|
+
const {
|
|
49
|
+
value,
|
|
50
|
+
locale,
|
|
51
|
+
formatToken
|
|
52
|
+
} = options;
|
|
53
|
+
const baseDate = options.baseDate || new Date();
|
|
54
|
+
const result = parse(value, formatToken, baseDate, {
|
|
55
|
+
locale
|
|
56
|
+
});
|
|
57
|
+
return isValid(result);
|
|
37
58
|
}
|
|
@@ -218,6 +218,9 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
218
218
|
* clear inset input value when close panel
|
|
219
219
|
*/
|
|
220
220
|
clearInsetInputValue(): void;
|
|
221
|
+
/**
|
|
222
|
+
* call it when change state value or input value
|
|
223
|
+
*/
|
|
221
224
|
resetCachedSelectedValue(willUpdateDates?: Date[]): void;
|
|
222
225
|
/**
|
|
223
226
|
* timing to call closePanel
|
|
@@ -255,6 +258,10 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
255
258
|
format: string;
|
|
256
259
|
insetInputValue: InsetInputValue;
|
|
257
260
|
}): void;
|
|
261
|
+
/**
|
|
262
|
+
* when input change we reset cached selected value
|
|
263
|
+
*/
|
|
264
|
+
_updateCachedSelectedValueFromInput(input: string): void;
|
|
258
265
|
/**
|
|
259
266
|
* Input box blur
|
|
260
267
|
* @param {String} input
|
|
@@ -292,6 +299,33 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
292
299
|
* @returns {Date [] | '}
|
|
293
300
|
*/
|
|
294
301
|
parseInput(input?: string, format?: string): Date[];
|
|
302
|
+
/**
|
|
303
|
+
* get date which may include null from input
|
|
304
|
+
*/
|
|
305
|
+
getLooseDateFromInput(input: string): Array<Date | null>;
|
|
306
|
+
/**
|
|
307
|
+
* parse input into `Array<Date|null>`, loose means return value includes `null`
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```javascript
|
|
311
|
+
* parseInputLoose('2022-03-15 ~ '); // [Date, null]
|
|
312
|
+
* parseInputLoose(' ~ 2022-03-15 '); // [null, Date]
|
|
313
|
+
* parseInputLoose(''); // []
|
|
314
|
+
* parseInputLoose('2022-03- ~ 2022-0'); // [null, null]
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
parseInputLoose(input?: string): Array<Date | null>;
|
|
318
|
+
/**
|
|
319
|
+
* parse multiple into `Array<Date|null>`, loose means return value includes `null`
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```javascript
|
|
323
|
+
* parseMultipleInputLoose('2021-01-01,2021-10-15'); // [Date, Date];
|
|
324
|
+
* parseMultipleInputLoose('2021-01-01,2021-10-'); // [Date, null];
|
|
325
|
+
* parseMultipleInputLoose(''); // [];
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
parseMultipleInputLoose(input?: string, separator?: string, needDedupe?: boolean): Date[];
|
|
295
329
|
/**
|
|
296
330
|
* Parses the input when multiple is true, if valid,
|
|
297
331
|
* returns a list of time objects, otherwise returns an array
|