@douyinfe/semi-foundation 2.10.1 → 2.11.0-beta.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/cjs/upload/foundation.js +1 -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/lib/es/upload/foundation.js +1 -0
- package/package.json +3 -3
- package/radio/radioFoundation.ts +11 -0
- package/tooltip/foundation.ts +5 -0
- package/upload/foundation.ts +1 -0
|
@@ -21,6 +21,8 @@ export interface CheckboxAdapter<P = Record<string, any>, S = Record<string, any
|
|
|
21
21
|
setNativeControlChecked: (checked: boolean) => void;
|
|
22
22
|
getState: noopFunction;
|
|
23
23
|
notifyChange: (event: BasicCheckboxEvent) => void;
|
|
24
|
+
setAddonId: () => void;
|
|
25
|
+
setExtraId: () => void;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
class CheckboxFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<CheckboxAdapter<P, S>, P, S> {
|
|
@@ -29,8 +31,15 @@ class CheckboxFoundation<P = Record<string, any>, S = Record<string, any>> exten
|
|
|
29
31
|
super({ ...adapter });
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
init() {
|
|
35
|
+
const { children, extra, extraId, addonId } = this.getProps();
|
|
36
|
+
if (children && !addonId) {
|
|
37
|
+
this._adapter.setAddonId();
|
|
38
|
+
}
|
|
39
|
+
if (extra && !extraId) {
|
|
40
|
+
this._adapter.setExtraId();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
34
43
|
|
|
35
44
|
getEvent(checked: boolean, e: any) {
|
|
36
45
|
const props = this.getProps();
|
|
@@ -32,3 +32,24 @@ export function compatibleParse(
|
|
|
32
32
|
}
|
|
33
33
|
return result;
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* whether value can be parsed with date-fns `parse`
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* isValueParseValid({ value: '2021-01-01', formatToken: 'yyyy-MM-dd' }); // true
|
|
42
|
+
* isValueParseValid({ value: '2021-01-0', formatToken: 'yyyy-MM-dd' }); // false
|
|
43
|
+
* isValueParseValid({ value: '2021-01', formatToken: 'yyyy-MM-dd' }); // false
|
|
44
|
+
*/
|
|
45
|
+
export function isValueParseValid(options: {
|
|
46
|
+
value: string;
|
|
47
|
+
formatToken: string;
|
|
48
|
+
baseDate?: Date;
|
|
49
|
+
locale?: Locale;
|
|
50
|
+
}) {
|
|
51
|
+
const { value, locale, formatToken } = options;
|
|
52
|
+
const baseDate = options.baseDate || new Date();
|
|
53
|
+
const result = parse(value, formatToken, baseDate, { locale });
|
|
54
|
+
return isValid(result);
|
|
55
|
+
}
|
package/datePicker/foundation.ts
CHANGED
|
@@ -244,10 +244,7 @@ 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
|
-
|
|
248
|
-
if (this._adapter.needConfirm()) {
|
|
249
|
-
this._adapter.updateCachedSelectedValue(result);
|
|
250
|
-
}
|
|
247
|
+
this.resetCachedSelectedValue(result);
|
|
251
248
|
}
|
|
252
249
|
|
|
253
250
|
parseWithTimezone(value: ValueType, timeZone: string | number, prevTimeZone: string | number) {
|
|
@@ -370,6 +367,9 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
370
367
|
}
|
|
371
368
|
}
|
|
372
369
|
|
|
370
|
+
/**
|
|
371
|
+
* call it when change state value or input value
|
|
372
|
+
*/
|
|
373
373
|
resetCachedSelectedValue(willUpdateDates?: Date[]) {
|
|
374
374
|
const { value, cachedSelectedValue } = this._adapter.getStates();
|
|
375
375
|
const newCachedSelectedValue = Array.isArray(willUpdateDates) ? willUpdateDates : value;
|
|
@@ -391,8 +391,8 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
391
391
|
* @param {Date[]} dates
|
|
392
392
|
*/
|
|
393
393
|
closePanel(e?: any, inputValue: string = null, dates?: Date[]) {
|
|
394
|
-
const { value
|
|
395
|
-
const willUpdateDates = isNullOrUndefined(dates) ?
|
|
394
|
+
const { value } = this._adapter.getStates();
|
|
395
|
+
const willUpdateDates = isNullOrUndefined(dates) ? value : dates;
|
|
396
396
|
if (!this._isControlledComponent('open')) {
|
|
397
397
|
this._adapter.togglePanel(false);
|
|
398
398
|
this._adapter.unregisterClickOutSide();
|
|
@@ -426,6 +426,7 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
426
426
|
handleInputChange(input: string, e: any) {
|
|
427
427
|
const result = this._isMultiple() ? this.parseMultipleInput(input) : this.parseInput(input);
|
|
428
428
|
const { value: stateValue } = this.getStates();
|
|
429
|
+
this._updateCachedSelectedValueFromInput(input);
|
|
429
430
|
// Enter a valid date or empty
|
|
430
431
|
if ((result && result.length) || input === '') {
|
|
431
432
|
// If you click the clear button
|
|
@@ -437,9 +438,6 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
437
438
|
// Updates the selected value when entering a valid date
|
|
438
439
|
const changedDates = this._getChangedDates(result);
|
|
439
440
|
if (!this._someDateDisabled(changedDates)) {
|
|
440
|
-
if (this._adapter.needConfirm()) {
|
|
441
|
-
this._adapter.updateCachedSelectedValue(result);
|
|
442
|
-
}
|
|
443
441
|
if (!isEqual(result, stateValue)) {
|
|
444
442
|
this._notifyChange(result);
|
|
445
443
|
}
|
|
@@ -460,15 +458,13 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
460
458
|
const _isMultiple = this._isMultiple();
|
|
461
459
|
const result = _isMultiple ? this.parseMultipleInput(insetInputStr, format) : this.parseInput(insetInputStr, format);
|
|
462
460
|
const { value: stateValue } = this.getStates();
|
|
461
|
+
this._updateCachedSelectedValueFromInput(insetInputStr);
|
|
463
462
|
|
|
464
463
|
if ((result && result.length)) {
|
|
465
464
|
const changedDates = this._getChangedDates(result);
|
|
466
465
|
if (!this._someDateDisabled(changedDates)) {
|
|
467
|
-
if (this._adapter.needConfirm()) {
|
|
468
|
-
this._adapter.updateCachedSelectedValue(result);
|
|
469
|
-
}
|
|
470
466
|
if (!isEqual(result, stateValue)) {
|
|
471
|
-
if (!this._isControlledComponent()) {
|
|
467
|
+
if (!this._isControlledComponent() && !this._adapter.needConfirm()) {
|
|
472
468
|
this._adapter.updateValue(result);
|
|
473
469
|
}
|
|
474
470
|
this._notifyChange(result);
|
|
@@ -480,6 +476,17 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
480
476
|
this._adapter.updateInsetInputValue(insetInputValue);
|
|
481
477
|
}
|
|
482
478
|
|
|
479
|
+
/**
|
|
480
|
+
* when input change we reset cached selected value
|
|
481
|
+
*/
|
|
482
|
+
_updateCachedSelectedValueFromInput(input: string) {
|
|
483
|
+
const looseResult = this.getLooseDateFromInput(input);
|
|
484
|
+
const changedLooseResult = this._getChangedDates(looseResult);
|
|
485
|
+
if (!this._someDateDisabled(changedLooseResult)) {
|
|
486
|
+
this.resetCachedSelectedValue(looseResult);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
483
490
|
/**
|
|
484
491
|
* Input box blur
|
|
485
492
|
* @param {String} input
|
|
@@ -504,6 +511,19 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
504
511
|
} else {
|
|
505
512
|
this._updateValueAndInput(stateValue);
|
|
506
513
|
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* 当不是范围类型且不需要确认时,使用 stateValue 重置 cachedSelectedValue
|
|
517
|
+
* 这样做的目的是,在输入非法值时,使用上次选中的值作为已选值
|
|
518
|
+
* needConfirm 或者 range type 时,我们在 close panel 时调用 resetCachedSelectedValue,这里不用重复调用
|
|
519
|
+
*
|
|
520
|
+
* Use stateValue to reset cachedSelectedValue when it is not a range type and does not require confirmation
|
|
521
|
+
* The purpose of this is to use the last selected value as the selected value when an invalid value is entered
|
|
522
|
+
* When needConfirm or range type, we call resetCachedSelectedValue when close panel, no need to call repeatedly here
|
|
523
|
+
*/
|
|
524
|
+
if (!this._adapter.needConfirm() && !this._isRangeType()) {
|
|
525
|
+
this.resetCachedSelectedValue(stateValue);
|
|
526
|
+
}
|
|
507
527
|
}
|
|
508
528
|
|
|
509
529
|
/**
|
|
@@ -551,9 +571,7 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
551
571
|
const inputValue = '';
|
|
552
572
|
if (!this._isControlledComponent('value')) {
|
|
553
573
|
this._updateValueAndInput(value, true, inputValue);
|
|
554
|
-
|
|
555
|
-
this._adapter.updateCachedSelectedValue(value);
|
|
556
|
-
}
|
|
574
|
+
this.resetCachedSelectedValue(value);
|
|
557
575
|
}
|
|
558
576
|
this._notifyChange(value);
|
|
559
577
|
this._adapter.notifyClear(e);
|
|
@@ -646,6 +664,115 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
646
664
|
return result;
|
|
647
665
|
}
|
|
648
666
|
|
|
667
|
+
/**
|
|
668
|
+
* get date which may include null from input
|
|
669
|
+
*/
|
|
670
|
+
getLooseDateFromInput(input: string): Array<Date | null> {
|
|
671
|
+
const value = this._isMultiple() ? this.parseMultipleInputLoose(input) : this.parseInputLoose(input);
|
|
672
|
+
return value;
|
|
673
|
+
}
|
|
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
|
+
parseInputLoose(input = ''): Array<Date | null> {
|
|
687
|
+
let result: Array<Date | null> = [];
|
|
688
|
+
const { dateFnsLocale, rangeSeparator, type, format } = this.getProps();
|
|
689
|
+
|
|
690
|
+
if (input && input.length) {
|
|
691
|
+
const formatToken = format || getDefaultFormatTokenByType(type);
|
|
692
|
+
let parsedResult, formatedInput;
|
|
693
|
+
const nowDate = new Date();
|
|
694
|
+
switch (type) {
|
|
695
|
+
case 'date':
|
|
696
|
+
case 'dateTime':
|
|
697
|
+
case 'month':
|
|
698
|
+
const _parsedResult = compatibleParse(input, formatToken, nowDate, dateFnsLocale);
|
|
699
|
+
if (isValidDate(_parsedResult)) {
|
|
700
|
+
formatedInput = this.localeFormat(_parsedResult as Date, formatToken);
|
|
701
|
+
if (formatedInput === input) {
|
|
702
|
+
parsedResult = _parsedResult;
|
|
703
|
+
}
|
|
704
|
+
} else {
|
|
705
|
+
parsedResult = null;
|
|
706
|
+
}
|
|
707
|
+
result = [parsedResult];
|
|
708
|
+
break;
|
|
709
|
+
case 'dateRange':
|
|
710
|
+
case 'dateTimeRange':
|
|
711
|
+
const separator = rangeSeparator;
|
|
712
|
+
const values = input.split(separator);
|
|
713
|
+
parsedResult =
|
|
714
|
+
values &&
|
|
715
|
+
values.reduce((arr, cur) => {
|
|
716
|
+
let parsedVal = null;
|
|
717
|
+
const _parsedResult = compatibleParse(cur, formatToken, nowDate, dateFnsLocale);
|
|
718
|
+
if (isValidDate(_parsedResult)) {
|
|
719
|
+
formatedInput = this.localeFormat(_parsedResult as Date, formatToken);
|
|
720
|
+
if (formatedInput === cur) {
|
|
721
|
+
parsedVal = _parsedResult;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
arr.push(parsedVal);
|
|
725
|
+
return arr;
|
|
726
|
+
}, []);
|
|
727
|
+
if (Array.isArray(parsedResult) && parsedResult.every(item => isValid(item))) {
|
|
728
|
+
parsedResult.sort((d1, d2) => d1.getTime() - d2.getTime());
|
|
729
|
+
}
|
|
730
|
+
result = parsedResult;
|
|
731
|
+
break;
|
|
732
|
+
default:
|
|
733
|
+
break;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
return result;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* parse multiple into `Array<Date|null>`, loose means return value includes `null`
|
|
742
|
+
*
|
|
743
|
+
* @example
|
|
744
|
+
* ```javascript
|
|
745
|
+
* parseMultipleInputLoose('2021-01-01,2021-10-15'); // [Date, Date];
|
|
746
|
+
* parseMultipleInputLoose('2021-01-01,2021-10-'); // [Date, null];
|
|
747
|
+
* parseMultipleInputLoose(''); // [];
|
|
748
|
+
* ```
|
|
749
|
+
*/
|
|
750
|
+
parseMultipleInputLoose(input = '', separator: string = strings.DEFAULT_SEPARATOR_MULTIPLE, needDedupe = false) {
|
|
751
|
+
const max = this.getProp('max');
|
|
752
|
+
const inputArr = input.split(separator);
|
|
753
|
+
const result: Date[] = [];
|
|
754
|
+
|
|
755
|
+
for (const curInput of inputArr) {
|
|
756
|
+
let tmpParsed = curInput && this.parseInputLoose(curInput);
|
|
757
|
+
tmpParsed = Array.isArray(tmpParsed) ? tmpParsed : tmpParsed && [tmpParsed];
|
|
758
|
+
if (tmpParsed && tmpParsed.length) {
|
|
759
|
+
if (needDedupe) {
|
|
760
|
+
!result.filter(r => Boolean(tmpParsed.find(tp => isSameSecond(r, tp)))) && result.push(...tmpParsed);
|
|
761
|
+
} else {
|
|
762
|
+
result.push(...tmpParsed);
|
|
763
|
+
}
|
|
764
|
+
} else {
|
|
765
|
+
return [];
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
if (max && max > 0 && result.length > max) {
|
|
769
|
+
return [];
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
return result;
|
|
774
|
+
}
|
|
775
|
+
|
|
649
776
|
/**
|
|
650
777
|
* Parses the input when multiple is true, if valid,
|
|
651
778
|
* returns a list of time objects, otherwise returns an array
|
|
@@ -799,15 +926,12 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
799
926
|
*/
|
|
800
927
|
const needCheckFocusRecord = get(options, 'needCheckFocusRecord', true);
|
|
801
928
|
|
|
802
|
-
if (this._adapter.needConfirm()) {
|
|
803
|
-
this._adapter.updateCachedSelectedValue(value);
|
|
804
|
-
}
|
|
805
|
-
|
|
806
929
|
const dates = Array.isArray(value) ? [...value] : value ? [value] : [];
|
|
807
930
|
const changedDates = this._getChangedDates(dates);
|
|
808
931
|
|
|
809
932
|
let inputValue, insetInputValue;
|
|
810
933
|
if (!this._someDateDisabled(changedDates)) {
|
|
934
|
+
this.resetCachedSelectedValue(dates);
|
|
811
935
|
inputValue = this._isMultiple() ? this.formatMultipleDates(dates) : this.formatDates(dates);
|
|
812
936
|
if (insetInput) {
|
|
813
937
|
const insetInputFormatToken = getInsetInputFormatToken({ format, type });
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
/* eslint-disable max-len */
|
|
2
|
-
import { cloneDeep, isObject, set } from 'lodash';
|
|
2
|
+
import { cloneDeep, isObject, set, get } from 'lodash';
|
|
3
|
+
import { format as formatFn } from 'date-fns';
|
|
3
4
|
|
|
4
5
|
import BaseFoundation, { DefaultAdapter } from '../base/foundation';
|
|
5
|
-
import { BaseValueType, ValidateStatus } from './foundation';
|
|
6
|
+
import { BaseValueType, ValidateStatus, ValueType } from './foundation';
|
|
6
7
|
import { formatDateValues } from './_utils/formatter';
|
|
7
8
|
import { getDefaultFormatTokenByType } from './_utils/getDefaultFormatToken';
|
|
8
9
|
import getInsetInputFormatToken from './_utils/getInsetInputFormatToken';
|
|
9
10
|
import getInsetInputValueFromInsetInputStr from './_utils/getInsetInputValueFromInsetInputStr';
|
|
10
11
|
import { strings } from './constants';
|
|
12
|
+
import getDefaultPickerDate from './_utils/getDefaultPickerDate';
|
|
13
|
+
import { compatibleParse } from '@douyinfe/semi-foundation/datePicker/_utils/parser';
|
|
14
|
+
import { isValidDate } from './_utils';
|
|
11
15
|
|
|
12
16
|
const KEY_CODE_ENTER = 'Enter';
|
|
13
17
|
const KEY_CODE_TAB = 'Tab';
|
|
@@ -50,6 +54,7 @@ export interface DateInputFoundationProps extends DateInputElementProps, DateInp
|
|
|
50
54
|
insetInput?: boolean;
|
|
51
55
|
insetInputValue?: InsetInputValue;
|
|
52
56
|
density?: typeof strings.DENSITY_SET[number];
|
|
57
|
+
defaultPickerValue?: ValueType;
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
export interface InsetInputValue {
|
|
@@ -175,11 +180,52 @@ export default class InputFoundation extends BaseFoundation<DateInputAdapter> {
|
|
|
175
180
|
const { value, valuePath, insetInputValue } = options;
|
|
176
181
|
const { format, type } = this._adapter.getProps();
|
|
177
182
|
const insetFormatToken = getInsetInputFormatToken({ type, format });
|
|
178
|
-
|
|
183
|
+
let newInsetInputValue = set(cloneDeep(insetInputValue), valuePath, value);
|
|
184
|
+
newInsetInputValue = this._autoFillTimeToInsetInputValue({ insetInputValue: newInsetInputValue, valuePath, format: insetFormatToken });
|
|
179
185
|
const newInputValue = this.concatInsetInputValue({ insetInputValue: newInsetInputValue });
|
|
180
186
|
this._adapter.notifyInsetInputChange({ insetInputValue: newInsetInputValue, format: insetFormatToken, insetInputStr: newInputValue });
|
|
181
187
|
}
|
|
182
188
|
|
|
189
|
+
_autoFillTimeToInsetInputValue(options: { insetInputValue: InsetInputValue; format: string; valuePath: string;}) {
|
|
190
|
+
const { valuePath, insetInputValue, format } = options;
|
|
191
|
+
const { type, defaultPickerValue, dateFnsLocale } = this._adapter.getProps();
|
|
192
|
+
const insetInputValueWithTime = cloneDeep(insetInputValue);
|
|
193
|
+
const { nowDate, nextDate } = getDefaultPickerDate({ defaultPickerValue, format, dateFnsLocale });
|
|
194
|
+
|
|
195
|
+
if (type.includes('Time')) {
|
|
196
|
+
let timeStr = '';
|
|
197
|
+
const dateFormatToken = get(format.split(' '), '0', strings.FORMAT_FULL_DATE);
|
|
198
|
+
const timeFormatToken = get(format.split(' '), '1', strings.FORMAT_TIME_PICKER);
|
|
199
|
+
|
|
200
|
+
switch (valuePath) {
|
|
201
|
+
case 'monthLeft.dateInput':
|
|
202
|
+
const dateLeftStr = insetInputValueWithTime.monthLeft.dateInput;
|
|
203
|
+
if (!insetInputValueWithTime.monthLeft.timeInput && dateLeftStr.length === dateFormatToken.length) {
|
|
204
|
+
const dateLeftParsed = compatibleParse(insetInputValueWithTime.monthLeft.dateInput, dateFormatToken);
|
|
205
|
+
if (isValidDate(dateLeftParsed)) {
|
|
206
|
+
timeStr = formatFn(nowDate, timeFormatToken);
|
|
207
|
+
insetInputValueWithTime.monthLeft.timeInput = timeStr;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
break;
|
|
211
|
+
case 'monthRight.dateInput':
|
|
212
|
+
const dateRightStr = insetInputValueWithTime.monthRight.dateInput;
|
|
213
|
+
if (!insetInputValueWithTime.monthRight.timeInput && dateRightStr.length === dateFormatToken.length) {
|
|
214
|
+
const dateRightParsed = compatibleParse(dateRightStr, dateFormatToken);
|
|
215
|
+
if (isValidDate(dateRightParsed)) {
|
|
216
|
+
timeStr = formatFn(nextDate, timeFormatToken);
|
|
217
|
+
insetInputValueWithTime.monthRight.timeInput = timeStr;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
break;
|
|
221
|
+
default:
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return insetInputValueWithTime;
|
|
227
|
+
}
|
|
228
|
+
|
|
183
229
|
/**
|
|
184
230
|
* 只有传入的 format 符合 formatReg 时,才会使用用户传入的 format
|
|
185
231
|
* 否则会使用默认的 format 作为 placeholder
|
|
@@ -223,10 +223,10 @@ export default class MonthsGridFoundation extends BaseFoundation<MonthsGridAdapt
|
|
|
223
223
|
this._adapter.updateMonthOnLeft(newMonthLeft);
|
|
224
224
|
const newSelected = new Set<string>();
|
|
225
225
|
if (!this._isMultiple()) {
|
|
226
|
-
newSelected.add(format(values[0] as Date, strings.FORMAT_FULL_DATE));
|
|
226
|
+
values[0] && newSelected.add(format(values[0] as Date, strings.FORMAT_FULL_DATE));
|
|
227
227
|
} else {
|
|
228
228
|
values.forEach(date => {
|
|
229
|
-
newSelected.add(format(date as Date, strings.FORMAT_FULL_DATE));
|
|
229
|
+
date && newSelected.add(format(date as Date, strings.FORMAT_FULL_DATE));
|
|
230
230
|
});
|
|
231
231
|
}
|
|
232
232
|
if (refreshPicker) {
|
|
@@ -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>);
|
|
@@ -21,10 +21,24 @@ var _isEnterPress = _interopRequireDefault(require("../utils/isEnterPress"));
|
|
|
21
21
|
class CheckboxFoundation extends _foundation.default {
|
|
22
22
|
constructor(adapter) {
|
|
23
23
|
super((0, _assign.default)({}, adapter));
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
init() {
|
|
27
|
+
const {
|
|
28
|
+
children,
|
|
29
|
+
extra,
|
|
30
|
+
extraId,
|
|
31
|
+
addonId
|
|
32
|
+
} = this.getProps();
|
|
25
33
|
|
|
34
|
+
if (children && !addonId) {
|
|
35
|
+
this._adapter.setAddonId();
|
|
36
|
+
}
|
|
26
37
|
|
|
27
|
-
|
|
38
|
+
if (extra && !extraId) {
|
|
39
|
+
this._adapter.setExtraId();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
28
42
|
|
|
29
43
|
getEvent(checked, e) {
|
|
30
44
|
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;
|
|
@@ -7,6 +7,7 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
exports.compatibleParse = compatibleParse;
|
|
10
|
+
exports.isValueParseValid = isValueParseValid;
|
|
10
11
|
|
|
11
12
|
var _dateFns = require("date-fns");
|
|
12
13
|
|
|
@@ -45,4 +46,26 @@ function compatibleParse(value, formatToken, baseDate, locale) {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
return result;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* whether value can be parsed with date-fns `parse`
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* isValueParseValid({ value: '2021-01-01', formatToken: 'yyyy-MM-dd' }); // true
|
|
55
|
+
* isValueParseValid({ value: '2021-01-0', formatToken: 'yyyy-MM-dd' }); // false
|
|
56
|
+
* isValueParseValid({ value: '2021-01', formatToken: 'yyyy-MM-dd' }); // false
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
function isValueParseValid(options) {
|
|
61
|
+
const {
|
|
62
|
+
value,
|
|
63
|
+
locale,
|
|
64
|
+
formatToken
|
|
65
|
+
} = options;
|
|
66
|
+
const baseDate = options.baseDate || new Date();
|
|
67
|
+
const result = (0, _dateFns.parse)(value, formatToken, baseDate, {
|
|
68
|
+
locale
|
|
69
|
+
});
|
|
70
|
+
return (0, _dateFns.isValid)(result);
|
|
48
71
|
}
|
|
@@ -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
|