@king-design/intact 3.6.0-beta.0 → 3.6.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.
- package/components/button/demos/basic.md +0 -1
- package/components/cascader/index.spec.ts +7 -6
- package/components/copy/index.spec.ts +9 -14
- package/components/datepicker/basepicker.ts +26 -314
- package/components/datepicker/calendar.ts +3 -1
- package/components/datepicker/calendar.vdt +5 -2
- package/components/datepicker/dayjs.ts +2 -16
- package/components/datepicker/demos/multiple.md +5 -0
- package/components/datepicker/demos/yearMonth.md +2 -8
- package/components/datepicker/helpers.ts +5 -7
- package/components/datepicker/index.md +1 -2
- package/components/datepicker/index.spec.ts +596 -157
- package/components/datepicker/index.ts +16 -33
- package/components/datepicker/index.vdt +41 -35
- package/components/datepicker/shortcuts.ts +1 -1
- package/components/datepicker/styles.ts +27 -18
- package/components/datepicker/useConfirm.ts +82 -0
- package/components/datepicker/useDisabled.ts +29 -31
- package/components/datepicker/useFormats.ts +8 -4
- package/components/datepicker/useHighlight.ts +81 -0
- package/components/datepicker/useKeyboards.ts +2 -1
- package/components/datepicker/useMergeRange.ts +12 -12
- package/components/datepicker/useMonths.ts +6 -3
- package/components/datepicker/usePanel.ts +19 -19
- package/components/datepicker/useShowDate.ts +21 -41
- package/components/datepicker/useStatus.ts +34 -15
- package/components/datepicker/useValue.ts +43 -72
- package/components/datepicker/useValueBase.ts +312 -0
- package/components/datepicker/useWeeks.ts +1 -1
- package/components/datepicker/useYears.ts +7 -3
- package/components/dropdown/dropdown.ts +5 -4
- package/components/dropdown/index.md +1 -0
- package/components/dropdown/item.ts +1 -1
- package/components/dropdown/useKeyboard.ts +0 -1
- package/components/form/form.ts +4 -0
- package/components/form/index.md +2 -1
- package/components/form/index.spec.ts +2 -0
- package/components/input/index.spec.ts +42 -0
- package/components/input/index.ts +8 -0
- package/components/input/index.vdt +3 -4
- package/components/input/useAutoWidth.ts +19 -1
- package/components/menu/demos/horizontal.md +7 -1
- package/components/menu/index.spec.ts +19 -0
- package/components/menu/styles.ts +2 -1
- package/components/scrollSelect/useMouseEvents.ts +5 -4
- package/components/select/base.ts +3 -2
- package/components/select/base.vdt +2 -1
- package/components/select/demos/creatable.md +2 -2
- package/components/select/index.md +1 -1
- package/components/select/index.spec.ts +142 -36
- package/components/select/menu.ts +1 -1
- package/components/select/option.ts +2 -1
- package/components/select/select.ts +1 -0
- package/components/select/styles.ts +3 -1
- package/components/select/useCard.ts +22 -4
- package/components/select/useInput.ts +5 -9
- package/components/spinner/index.spec.ts +18 -0
- package/components/spinner/useValue.ts +2 -1
- package/components/table/index.spec.ts +69 -1
- package/components/table/useStickyHeader.ts +1 -1
- package/components/timepicker/index.spec.ts +145 -27
- package/components/timepicker/panelPicker.ts +10 -4
- package/components/timepicker/panelPicker.vdt +3 -5
- package/components/timepicker/styles.ts +1 -0
- package/components/timepicker/useConfirm.ts +33 -0
- package/components/timepicker/useDefaultValue.ts +30 -0
- package/components/timepicker/useDisabled.ts +17 -4
- package/components/timepicker/useFormats.ts +1 -1
- package/components/timepicker/useValue.ts +22 -19
- package/components/tour/index.spec.ts +1 -1
- package/es/components/cascader/index.spec.js +18 -19
- package/es/components/copy/index.spec.js +14 -31
- package/es/components/datepicker/basepicker.d.ts +6 -27
- package/es/components/datepicker/basepicker.js +23 -268
- package/es/components/datepicker/calendar.d.ts +4 -2
- package/es/components/datepicker/dayjs.d.ts +2 -13
- package/es/components/datepicker/helpers.d.ts +3 -2
- package/es/components/datepicker/helpers.js +2 -3
- package/es/components/datepicker/index.d.ts +21 -29
- package/es/components/datepicker/index.js +22 -32
- package/es/components/datepicker/index.spec.js +1277 -484
- package/es/components/datepicker/index.vdt.js +39 -38
- package/es/components/datepicker/shortcuts.d.ts +1 -1
- package/es/components/datepicker/styles.d.ts +7 -2
- package/es/components/datepicker/styles.js +10 -15
- package/es/components/datepicker/useConfirm.d.ts +6 -0
- package/es/components/datepicker/useConfirm.js +65 -0
- package/es/components/datepicker/useDisabled.d.ts +5 -3
- package/es/components/datepicker/useDisabled.js +22 -27
- package/es/components/datepicker/useFormats.d.ts +2 -2
- package/es/components/datepicker/useFormats.js +6 -2
- package/es/components/datepicker/useHighlight.d.ts +14 -0
- package/es/components/datepicker/useHighlight.js +60 -0
- package/es/components/datepicker/useKeyboards.js +2 -1
- package/es/components/datepicker/useMergeRange.d.ts +1 -1
- package/es/components/datepicker/useMergeRange.js +11 -16
- package/es/components/datepicker/useMonths.js +5 -3
- package/es/components/datepicker/usePanel.d.ts +1 -10
- package/es/components/datepicker/usePanel.js +19 -32
- package/es/components/datepicker/useShowDate.d.ts +1 -1
- package/es/components/datepicker/useShowDate.js +15 -40
- package/es/components/datepicker/useStatus.js +33 -16
- package/es/components/datepicker/useValue.d.ts +11 -6
- package/es/components/datepicker/useValue.js +49 -69
- package/es/components/datepicker/useValueBase.d.ts +28 -0
- package/es/components/datepicker/useValueBase.js +280 -0
- package/es/components/datepicker/useYears.js +6 -3
- package/es/components/dropdown/dropdown.d.ts +1 -0
- package/es/components/dropdown/dropdown.js +7 -4
- package/es/components/form/form.d.ts +1 -0
- package/es/components/form/form.js +7 -0
- package/es/components/form/index.spec.js +10 -8
- package/es/components/input/index.d.ts +2 -0
- package/es/components/input/index.js +6 -0
- package/es/components/input/index.spec.js +45 -0
- package/es/components/input/index.vdt.js +4 -3
- package/es/components/input/useAutoWidth.d.ts +2 -0
- package/es/components/input/useAutoWidth.js +19 -1
- package/es/components/menu/index.spec.js +28 -0
- package/es/components/menu/styles.js +2 -2
- package/es/components/scrollSelect/useMouseEvents.js +5 -4
- package/es/components/select/base.d.ts +1 -1
- package/es/components/select/base.js +3 -2
- package/es/components/select/base.vdt.js +4 -3
- package/es/components/select/index.spec.js +346 -218
- package/es/components/select/menu.js +1 -1
- package/es/components/select/option.js +2 -1
- package/es/components/select/select.js +2 -1
- package/es/components/select/styles.d.ts +79 -0
- package/es/components/select/styles.js +1 -0
- package/es/components/select/useCard.d.ts +4 -3
- package/es/components/select/useCard.js +15 -4
- package/es/components/select/useInput.d.ts +1 -1
- package/es/components/select/useInput.js +4 -4
- package/es/components/spinner/index.spec.js +82 -44
- package/es/components/spinner/useValue.js +2 -1
- package/es/components/table/index.spec.js +84 -6
- package/es/components/table/useStickyHeader.js +1 -1
- package/es/components/timepicker/index.spec.js +298 -128
- package/es/components/timepicker/panelPicker.d.ts +21 -16
- package/es/components/timepicker/panelPicker.js +7 -4
- package/es/components/timepicker/panelPicker.vdt.js +5 -9
- package/es/components/timepicker/selectPicker.d.ts +4 -3
- package/es/components/timepicker/styles.js +1 -1
- package/es/components/timepicker/useConfirm.d.ts +6 -0
- package/es/components/timepicker/useConfirm.js +19 -0
- package/es/components/timepicker/useDefaultValue.d.ts +4 -0
- package/es/components/timepicker/useDefaultValue.js +27 -0
- package/es/components/timepicker/useDisabled.d.ts +6 -3
- package/es/components/timepicker/useDisabled.js +13 -4
- package/es/components/timepicker/useFormats.d.ts +1 -1
- package/es/components/timepicker/useValue.d.ts +13 -8
- package/es/components/timepicker/useValue.js +14 -15
- package/es/components/tour/index.spec.js +1 -1
- package/es/index.d.ts +2 -2
- package/es/index.js +2 -2
- package/es/site/data/components/button/demos/basic/react.js +0 -2
- package/es/site/data/components/datepicker/demos/multiple/index.d.ts +1 -0
- package/es/site/data/components/datepicker/demos/multiple/index.js +2 -1
- package/es/site/data/components/datepicker/demos/multiple/react.d.ts +1 -0
- package/es/site/data/components/datepicker/demos/multiple/react.js +13 -2
- package/es/site/data/components/datepicker/demos/yearMonth/index.d.ts +0 -2
- package/es/site/data/components/datepicker/demos/yearMonth/index.js +1 -3
- package/es/site/data/components/datepicker/demos/yearMonth/react.d.ts +0 -2
- package/es/site/data/components/datepicker/demos/yearMonth/react.js +1 -21
- package/es/site/data/components/menu/demos/horizontal/react.js +5 -1
- package/es/site/data/components/select/demos/creatable/react.js +2 -2
- package/es/site/data/components/select/demos/searchable/index.js +1 -1
- package/es/site/data/components/select/demos/searchable/react.js +1 -1
- package/es/site/data/components/tour/demos/customText/index.d.ts +19 -6
- package/es/site/data/components/tour/demos/customText/index.js +18 -17
- package/es/site/data/components/tour/demos/customText/react.d.ts +20 -6
- package/es/site/data/components/tour/demos/customText/react.js +31 -27
- package/es/test/demos.js +1 -1
- package/index.ts +2 -2
- package/package.json +2 -2
- package/components/datepicker/demos/nowrap.md +0 -35
- package/components/datepicker/usePosition.ts +0 -169
- package/es/components/datepicker/usePosition.d.ts +0 -10
- package/es/components/datepicker/usePosition.js +0 -166
- package/es/site/data/components/datepicker/demos/nowrap/index.d.ts +0 -10
- package/es/site/data/components/datepicker/demos/nowrap/index.js +0 -19
- package/es/site/data/components/datepicker/demos/nowrap/react.d.ts +0 -10
- package/es/site/data/components/datepicker/demos/nowrap/react.js +0 -49
- package/es/site/data/components/tour/demos/customButtons/index.d.ts +0 -33
- package/es/site/data/components/tour/demos/customButtons/index.js +0 -55
- package/es/site/data/components/tour/demos/customButtons/react.d.ts +0 -33
- package/es/site/data/components/tour/demos/customButtons/react.js +0 -99
|
@@ -20,36 +20,30 @@ describe('Copy', function () {
|
|
|
20
20
|
}, _callee);
|
|
21
21
|
})));
|
|
22
22
|
it('should copy', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
23
|
-
var _mount, instance, element
|
|
23
|
+
var spy, _mount, instance, element;
|
|
24
24
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
25
25
|
while (1) switch (_context2.prev = _context2.next) {
|
|
26
26
|
case 0:
|
|
27
|
+
spy = sinon.spy(navigator.clipboard, 'writeText');
|
|
27
28
|
_mount = mount(BasicDemo), instance = _mount[0], element = _mount[1];
|
|
28
29
|
element.click();
|
|
29
|
-
_context2.prev = 2;
|
|
30
30
|
_context2.next = 5;
|
|
31
|
-
return
|
|
31
|
+
return wait();
|
|
32
32
|
case 5:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
break;
|
|
37
|
-
case 9:
|
|
38
|
-
_context2.prev = 9;
|
|
39
|
-
_context2.t0 = _context2["catch"](2);
|
|
40
|
-
// Read permisson denied
|
|
41
|
-
console.log(_context2.t0);
|
|
42
|
-
case 12:
|
|
33
|
+
expect(spy.calledWith('Hello King Desgin!')).to.be.true;
|
|
34
|
+
spy.restore();
|
|
35
|
+
case 7:
|
|
43
36
|
case "end":
|
|
44
37
|
return _context2.stop();
|
|
45
38
|
}
|
|
46
|
-
}, _callee2
|
|
39
|
+
}, _callee2);
|
|
47
40
|
})));
|
|
48
41
|
it('wrap copy with tooltip', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
49
|
-
var Demo, _mount2, instance, element
|
|
42
|
+
var spy, Demo, _mount2, instance, element;
|
|
50
43
|
return _regeneratorRuntime.wrap(function _callee3$(_context4) {
|
|
51
44
|
while (1) switch (_context4.prev = _context4.next) {
|
|
52
45
|
case 0:
|
|
46
|
+
spy = sinon.spy(navigator.clipboard, 'writeText');
|
|
53
47
|
Demo = /*#__PURE__*/function (_Component) {
|
|
54
48
|
_inheritsLoose(Demo, _Component);
|
|
55
49
|
function Demo() {
|
|
@@ -68,26 +62,15 @@ describe('Copy', function () {
|
|
|
68
62
|
Demo.template = "\n const { Tooltip, Copy } = this;\n <Tooltip content=\"test\">\n <Copy text=\"test\" />\n </Tooltip>\n ";
|
|
69
63
|
_mount2 = mount(Demo), instance = _mount2[0], element = _mount2[1];
|
|
70
64
|
element.click();
|
|
71
|
-
_context4.next =
|
|
65
|
+
_context4.next = 7;
|
|
72
66
|
return wait();
|
|
73
|
-
case
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return navigator.clipboard.readText();
|
|
67
|
+
case 7:
|
|
68
|
+
expect(spy.calledWith('test')).to.be.true;
|
|
69
|
+
spy.restore();
|
|
77
70
|
case 9:
|
|
78
|
-
text = _context4.sent;
|
|
79
|
-
expect(text).to.eql('test');
|
|
80
|
-
_context4.next = 16;
|
|
81
|
-
break;
|
|
82
|
-
case 13:
|
|
83
|
-
_context4.prev = 13;
|
|
84
|
-
_context4.t0 = _context4["catch"](6);
|
|
85
|
-
// Read permisson denied
|
|
86
|
-
console.log(_context4.t0);
|
|
87
|
-
case 16:
|
|
88
71
|
case "end":
|
|
89
72
|
return _context4.stop();
|
|
90
73
|
}
|
|
91
|
-
}, _callee3
|
|
74
|
+
}, _callee3);
|
|
92
75
|
})));
|
|
93
76
|
});
|
|
@@ -2,20 +2,12 @@
|
|
|
2
2
|
* The base hook for handling value of Datepicker and Timepicker
|
|
3
3
|
*/
|
|
4
4
|
import { TypeDefs } from 'intact';
|
|
5
|
-
import {
|
|
6
|
-
import { Dayjs, OpUnitType, QUnitType } from './dayjs';
|
|
5
|
+
import { Dayjs } from './dayjs';
|
|
7
6
|
import type { useFormats } from './useFormats';
|
|
8
|
-
import
|
|
9
|
-
import { PanelFlags, usePanel } from './usePanel';
|
|
7
|
+
import { usePanel } from './usePanel';
|
|
10
8
|
import { BaseSelect, BaseSelectProps, BaseSelectEvents, BaseSelectBlocks } from '../select/base';
|
|
11
9
|
import type { Events } from '../types';
|
|
12
|
-
|
|
13
|
-
export type StateValueItem = Dayjs | StateValueRange;
|
|
14
|
-
export type StateValue = StateValueItem[];
|
|
15
|
-
export type StringValue = string | string[] | [string, string] | [string, string][];
|
|
16
|
-
export type DayjsValueRange = [Dayjs, Dayjs];
|
|
17
|
-
export type DayjsValueItem = Dayjs | DayjsValueRange;
|
|
18
|
-
export type DayjsValue = DayjsValueItem[];
|
|
10
|
+
import type { useValueBase, StateValueRange, Value } from './useValueBase';
|
|
19
11
|
export interface BasePickerProps<V extends Value = Value, Multipe extends boolean = boolean, Range extends boolean = boolean> extends BaseSelectProps<V | [V, V], Multipe> {
|
|
20
12
|
value?: Multipe extends true ? Range extends true ? [
|
|
21
13
|
V,
|
|
@@ -33,29 +25,16 @@ export interface BasePickerProps<V extends Value = Value, Multipe extends boolea
|
|
|
33
25
|
disabledDate?: (v: Dayjs) => boolean;
|
|
34
26
|
}
|
|
35
27
|
export interface BasePickerEvents extends BaseSelectEvents {
|
|
36
|
-
selecting: [StateValueRange];
|
|
37
|
-
togglePosition: [];
|
|
28
|
+
selecting: [StateValueRange, boolean];
|
|
38
29
|
}
|
|
39
30
|
export interface BasePickerBlocks<V extends Value = Value, R extends boolean = boolean> extends BaseSelectBlocks<R extends true ? [Value, Value] : Value> {
|
|
40
31
|
}
|
|
41
|
-
export type Value = string | Date | number | Dayjs;
|
|
42
32
|
export declare abstract class BasePicker<T extends BasePickerProps = BasePickerProps, E extends BasePickerEvents = BasePickerEvents, B extends BasePickerBlocks<any> = BasePickerBlocks<any>> extends BaseSelect<T, E, B> {
|
|
43
33
|
static typeDefs: Required<TypeDefs<BasePickerProps<Value, boolean, boolean>>>;
|
|
44
34
|
static defaults: () => Partial<BasePickerProps<any, boolean, boolean>>;
|
|
45
35
|
static events: Events<BasePickerEvents>;
|
|
46
|
-
abstract value: ReturnType<typeof
|
|
36
|
+
abstract value: ReturnType<typeof useValueBase>;
|
|
47
37
|
abstract formats: ReturnType<typeof useFormats>;
|
|
48
38
|
abstract panel: ReturnType<typeof usePanel>;
|
|
49
|
-
resetKeywords(
|
|
39
|
+
resetKeywords(silent?: boolean): void;
|
|
50
40
|
}
|
|
51
|
-
export declare function useValue({ createDateByValueFormat, createDateByShowFormat, getShowString, getValueString, }: ReturnType<typeof useFormats>, { isDisabled, minDate }: ReturnType<typeof useDisabled>, panel: ReturnType<typeof usePanel>, shouldUpdateValue: (v: StateValueItem) => boolean, updateValueOnInput: (v: DayjsValueItem) => void, getEqualType: () => OpUnitType | QUnitType, updateStateValue: (v: DayjsValue, value: State<StateValue>) => void): {
|
|
52
|
-
value: State<StateValue>;
|
|
53
|
-
format: () => string | string[];
|
|
54
|
-
onConfirm: () => void;
|
|
55
|
-
onChangeTime: (date: Dayjs, flag: PanelFlags) => void;
|
|
56
|
-
getTimeValue: (flag: PanelFlags) => Dayjs | null | undefined;
|
|
57
|
-
setValue: (v: StateValueItem, fromInput: boolean) => void;
|
|
58
|
-
convertToDayjs: (v: BasePickerProps<Value>['value']) => DayjsValue;
|
|
59
|
-
getDayjsValue: () => DayjsValue;
|
|
60
|
-
setMoment: () => void;
|
|
61
|
-
};
|
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
2
2
|
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
3
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js/instance/map";
|
|
4
|
-
import _trimInstanceProperty from "@babel/runtime-corejs3/core-js/instance/trim";
|
|
5
|
-
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/slice";
|
|
6
|
-
import _spliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/splice";
|
|
7
3
|
import { __decorate } from "tslib";
|
|
8
|
-
/**
|
|
9
|
-
* The base hook for handling value of Datepicker and Timepicker
|
|
10
|
-
*/
|
|
11
|
-
import { useInstance } from 'intact';
|
|
12
|
-
import { useState, watchState } from '../../hooks/useState';
|
|
13
4
|
import dayjs from './dayjs';
|
|
14
|
-
import {
|
|
15
|
-
import { isEqualArray, last, bind } from '../utils';
|
|
5
|
+
import { last, bind } from '../utils';
|
|
16
6
|
import { BaseSelect } from '../select/base';
|
|
17
7
|
var typeDefs = _extends({}, BaseSelect.typeDefs, {
|
|
18
8
|
value: [String, Array, Date, Number, dayjs],
|
|
@@ -30,8 +20,7 @@ var defaults = function defaults() {
|
|
|
30
20
|
});
|
|
31
21
|
};
|
|
32
22
|
var events = _extends({}, BaseSelect.events, {
|
|
33
|
-
selecting: true
|
|
34
|
-
togglePosition: true
|
|
23
|
+
selecting: true
|
|
35
24
|
});
|
|
36
25
|
export var BasePicker = /*#__PURE__*/function (_BaseSelect) {
|
|
37
26
|
_inheritsLoose(BasePicker, _BaseSelect);
|
|
@@ -39,264 +28,30 @@ export var BasePicker = /*#__PURE__*/function (_BaseSelect) {
|
|
|
39
28
|
return _BaseSelect.apply(this, arguments) || this;
|
|
40
29
|
}
|
|
41
30
|
var _proto = BasePicker.prototype;
|
|
42
|
-
_proto.resetKeywords = function resetKeywords(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var value = last(
|
|
49
|
-
keywords
|
|
31
|
+
_proto.resetKeywords = function resetKeywords(silent) {
|
|
32
|
+
if (silent === void 0) {
|
|
33
|
+
silent = false;
|
|
34
|
+
}
|
|
35
|
+
// const {multiple} = this.get();
|
|
36
|
+
// const dayjsValue = this.value.getDayjsValue();
|
|
37
|
+
var value = last(this.value.value.value);
|
|
38
|
+
var keywords = this.input.keywords;
|
|
39
|
+
var _keywords = '';
|
|
40
|
+
if (value && !this.value.allValuesUpdatedInMultipleMode()) {
|
|
41
|
+
_keywords = this.value.formatSingleValue(value);
|
|
42
|
+
}
|
|
43
|
+
if (!silent) {
|
|
44
|
+
keywords.set(_keywords);
|
|
45
|
+
} else {
|
|
46
|
+
// update keywords will update value, because it is been watched in useValueBase
|
|
47
|
+
// silent in this case to update keywords to show it in input
|
|
48
|
+
keywords.value = _keywords;
|
|
49
|
+
this.forceUpdate();
|
|
50
|
+
}
|
|
50
51
|
};
|
|
51
52
|
return BasePicker;
|
|
52
53
|
}(BaseSelect);
|
|
53
54
|
BasePicker.typeDefs = typeDefs;
|
|
54
55
|
BasePicker.defaults = defaults;
|
|
55
56
|
BasePicker.events = events;
|
|
56
|
-
__decorate([bind], BasePicker.prototype, "resetKeywords", null);
|
|
57
|
-
export function useValue(_ref, _ref2, panel, shouldUpdateValue, updateValueOnInput, getEqualType, updateStateValue) {
|
|
58
|
-
var createDateByValueFormat = _ref.createDateByValueFormat,
|
|
59
|
-
createDateByShowFormat = _ref.createDateByShowFormat,
|
|
60
|
-
getShowString = _ref.getShowString,
|
|
61
|
-
getValueString = _ref.getValueString;
|
|
62
|
-
var isDisabled = _ref2.isDisabled,
|
|
63
|
-
minDate = _ref2.minDate;
|
|
64
|
-
// Normalize the value to multipe values, no matter it's multipe or not
|
|
65
|
-
var value = useState([]);
|
|
66
|
-
var instance = useInstance();
|
|
67
|
-
var dayjsValue = [];
|
|
68
|
-
instance.watch('value', function (newValue, oldValue) {
|
|
69
|
-
if (isEqualArray(newValue, oldValue)) return;
|
|
70
|
-
// 检查是否与当前 dayjsValue 对应的字符串相同,避免循环
|
|
71
|
-
var currentValueStr = convertToValueString(dayjsValue);
|
|
72
|
-
if (newValue === currentValueStr) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
// 只执行一次转换和更新逻辑
|
|
76
|
-
var _value = convertToDayjs(newValue);
|
|
77
|
-
dayjsValue = _value;
|
|
78
|
-
updateStateValue(_value, value);
|
|
79
|
-
instance.resetKeywords(instance.input.keywords);
|
|
80
|
-
});
|
|
81
|
-
watchState(instance.input.keywords, function (v) {
|
|
82
|
-
var _instance$get = instance.get(),
|
|
83
|
-
range = _instance$get.range,
|
|
84
|
-
multiple = _instance$get.multiple;
|
|
85
|
-
if (!multiple && v === '') return instance.set('value', null);
|
|
86
|
-
if (range) {
|
|
87
|
-
var _context;
|
|
88
|
-
var _v$split$map = _mapInstanceProperty(_context = v.split(/\s*~\s*/)).call(_context, function (s) {
|
|
89
|
-
return _trimInstanceProperty(s).call(s);
|
|
90
|
-
}),
|
|
91
|
-
start = _v$split$map[0],
|
|
92
|
-
end = _v$split$map[1];
|
|
93
|
-
if (start && end) {
|
|
94
|
-
var startDate = createDateByShowFormat(start);
|
|
95
|
-
if (!isValidDate(startDate)) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
var endDate = createDateByShowFormat(end);
|
|
99
|
-
if (!isValidDate(endDate)) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (endDate.isAfter(startDate)) {
|
|
103
|
-
updateValueOnInput([startDate, endDate]);
|
|
104
|
-
} else {
|
|
105
|
-
updateValueOnInput([endDate, startDate]);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
var date = createDateByShowFormat(v);
|
|
110
|
-
if (isValidDate(date)) {
|
|
111
|
-
updateValueOnInput(date);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
function convertToDayjs(v) {
|
|
116
|
-
if (!v || Array.isArray(v) && !v.length) return [];
|
|
117
|
-
var _instance$get2 = instance.get(),
|
|
118
|
-
multiple = _instance$get2.multiple;
|
|
119
|
-
if (!multiple) {
|
|
120
|
-
v = [v];
|
|
121
|
-
}
|
|
122
|
-
return _mapInstanceProperty(v).call(v, function (value) {
|
|
123
|
-
if (Array.isArray(value)) {
|
|
124
|
-
// range
|
|
125
|
-
return _mapInstanceProperty(value).call(value, createDateByValueFormat);
|
|
126
|
-
}
|
|
127
|
-
return createDateByValueFormat(value);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
function convertToValueString(v) {
|
|
131
|
-
var results = _mapInstanceProperty(v).call(v, function (value) {
|
|
132
|
-
if (Array.isArray(value)) {
|
|
133
|
-
return _mapInstanceProperty(value).call(value, getValueString);
|
|
134
|
-
}
|
|
135
|
-
return getValueString(value);
|
|
136
|
-
});
|
|
137
|
-
if (!instance.get('multiple')) {
|
|
138
|
-
return results[0] || null;
|
|
139
|
-
}
|
|
140
|
-
return results;
|
|
141
|
-
}
|
|
142
|
-
function format() {
|
|
143
|
-
var results = _mapInstanceProperty(dayjsValue).call(dayjsValue, function (value) {
|
|
144
|
-
if (Array.isArray(value)) {
|
|
145
|
-
return _mapInstanceProperty(value).call(value, getShowString).join(' ~ ');
|
|
146
|
-
}
|
|
147
|
-
return getShowString(value);
|
|
148
|
-
});
|
|
149
|
-
if (!instance.get('multiple')) {
|
|
150
|
-
return results[0];
|
|
151
|
-
}
|
|
152
|
-
return results;
|
|
153
|
-
}
|
|
154
|
-
function setSingleDate(v, fromInput) {
|
|
155
|
-
value.set([v]);
|
|
156
|
-
if (fromInput || shouldUpdateValue(v)) {
|
|
157
|
-
updateValue();
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
function addMultipeDate(v, fromInput) {
|
|
161
|
-
var _instance$get3 = instance.get(),
|
|
162
|
-
range = _instance$get3.range;
|
|
163
|
-
var _value = value.value;
|
|
164
|
-
_value = !_value ? [] : _sliceInstanceProperty(_value).call(_value);
|
|
165
|
-
if (range && v.length === 2) {
|
|
166
|
-
// pop the last value firstly, if it only has the start date
|
|
167
|
-
var lastValue = last(_value);
|
|
168
|
-
if (lastValue && lastValue.length < 2) {
|
|
169
|
-
_value.pop();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
var _shouldUpdateValue = true;
|
|
173
|
-
if (fromInput || shouldUpdateValue(v)) {
|
|
174
|
-
// if select the date/year/month, then toggle the value.
|
|
175
|
-
// if from input, treat the value as the final value
|
|
176
|
-
var index = findValueIndex(_value, v, getEqualType());
|
|
177
|
-
if (index > -1) {
|
|
178
|
-
_spliceInstanceProperty(_value).call(_value, index, 1);
|
|
179
|
-
} else {
|
|
180
|
-
_value.push(v);
|
|
181
|
-
}
|
|
182
|
-
} else {
|
|
183
|
-
// select the datetime, only push the value,
|
|
184
|
-
// and unique the array on click confrim button
|
|
185
|
-
_value.push(v);
|
|
186
|
-
_shouldUpdateValue = false;
|
|
187
|
-
}
|
|
188
|
-
value.set(_value);
|
|
189
|
-
if (_shouldUpdateValue) {
|
|
190
|
-
updateValue();
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
function setValue(v, fromInput) {
|
|
194
|
-
var multiple = instance.get('multiple');
|
|
195
|
-
if (multiple) {
|
|
196
|
-
addMultipeDate(v, fromInput);
|
|
197
|
-
} else {
|
|
198
|
-
setSingleDate(v, fromInput);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
function updateValue() {
|
|
202
|
-
var _value = value.value;
|
|
203
|
-
var valueStr = convertToValueString(_value);
|
|
204
|
-
// 检查是否需要更新,避免循环调用
|
|
205
|
-
if (instance.get('value') === valueStr) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
// 在设置 value 之前先更新 dayjsValue
|
|
209
|
-
dayjsValue = _value;
|
|
210
|
-
instance.set('value', valueStr);
|
|
211
|
-
instance.resetKeywords(instance.input.keywords);
|
|
212
|
-
}
|
|
213
|
-
function onConfirm() {
|
|
214
|
-
var lastValue = last(instance.value.value.value);
|
|
215
|
-
var _instance$get4 = instance.get(),
|
|
216
|
-
multiple = _instance$get4.multiple,
|
|
217
|
-
range = _instance$get4.range;
|
|
218
|
-
if (!multiple) {
|
|
219
|
-
if (range) {
|
|
220
|
-
// 范围选择:需要开始和结束时间都选择完才关闭
|
|
221
|
-
if (lastValue.length === 2) {
|
|
222
|
-
instance.hide();
|
|
223
|
-
}
|
|
224
|
-
instance.trigger('togglePosition');
|
|
225
|
-
} else {
|
|
226
|
-
// 单选:选择完时间就关闭
|
|
227
|
-
if (lastValue) {
|
|
228
|
-
instance.hide();
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
} else {
|
|
232
|
-
unique();
|
|
233
|
-
panel.reset();
|
|
234
|
-
}
|
|
235
|
-
updateValue();
|
|
236
|
-
}
|
|
237
|
-
function setMoment() {
|
|
238
|
-
var now = dayjs();
|
|
239
|
-
setValue(now, true);
|
|
240
|
-
instance.hide();
|
|
241
|
-
}
|
|
242
|
-
function unique() {
|
|
243
|
-
var _value = value.value;
|
|
244
|
-
var map = {};
|
|
245
|
-
var results = [];
|
|
246
|
-
_value.forEach(function (value) {
|
|
247
|
-
var key;
|
|
248
|
-
if (Array.isArray(value)) {
|
|
249
|
-
key = _mapInstanceProperty(value).call(value, getValueString).join(' ~ ');
|
|
250
|
-
} else {
|
|
251
|
-
key = getValueString(value);
|
|
252
|
-
}
|
|
253
|
-
if (!map[key]) {
|
|
254
|
-
map[key] = true;
|
|
255
|
-
results.push(value);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
value.set(results);
|
|
259
|
-
}
|
|
260
|
-
function isValidDate(date) {
|
|
261
|
-
return date.isValid() && !isDisabled(date, getEqualType());
|
|
262
|
-
}
|
|
263
|
-
function onChangeTime(date, flag) {
|
|
264
|
-
var _context2;
|
|
265
|
-
var _instance$get5 = instance.get(),
|
|
266
|
-
range = _instance$get5.range;
|
|
267
|
-
var values = _sliceInstanceProperty(_context2 = value.value).call(_context2);
|
|
268
|
-
var lastIndex = values.length - 1;
|
|
269
|
-
var _value = date;
|
|
270
|
-
if (range) {
|
|
271
|
-
var _context3;
|
|
272
|
-
_value = _sliceInstanceProperty(_context3 = values[lastIndex]).call(_context3);
|
|
273
|
-
_value[flag] = date;
|
|
274
|
-
instance.trigger('selecting', _value);
|
|
275
|
-
}
|
|
276
|
-
values[lastIndex] = _value;
|
|
277
|
-
value.set(values);
|
|
278
|
-
}
|
|
279
|
-
function getTimeValue(flag) {
|
|
280
|
-
var _value = value.value;
|
|
281
|
-
if (!_value.length) return null;
|
|
282
|
-
var _instance$get6 = instance.get(),
|
|
283
|
-
range = _instance$get6.range,
|
|
284
|
-
min = _instance$get6.min;
|
|
285
|
-
var lastValue = last(_value);
|
|
286
|
-
return range ? lastValue[flag] : lastValue;
|
|
287
|
-
}
|
|
288
|
-
function getDayjsValue() {
|
|
289
|
-
return dayjsValue;
|
|
290
|
-
}
|
|
291
|
-
return {
|
|
292
|
-
value: value,
|
|
293
|
-
format: format,
|
|
294
|
-
onConfirm: onConfirm,
|
|
295
|
-
onChangeTime: onChangeTime,
|
|
296
|
-
getTimeValue: getTimeValue,
|
|
297
|
-
setValue: setValue,
|
|
298
|
-
convertToDayjs: convertToDayjs,
|
|
299
|
-
getDayjsValue: getDayjsValue,
|
|
300
|
-
setMoment: setMoment
|
|
301
|
-
};
|
|
302
|
-
}
|
|
57
|
+
__decorate([bind], BasePicker.prototype, "resetKeywords", null);
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Component } from 'intact';
|
|
2
2
|
import { Dayjs } from 'dayjs';
|
|
3
3
|
import type { Datepicker } from './index';
|
|
4
|
-
import { StateValue } from './
|
|
4
|
+
import type { StateValue } from './useValueBase';
|
|
5
5
|
import { PanelFlags } from './usePanel';
|
|
6
|
+
import { Position } from './useHighlight';
|
|
6
7
|
export interface DatepickerCalendarProps {
|
|
7
8
|
value: StateValue;
|
|
8
9
|
type?: 'date' | 'year' | 'month' | 'week' | 'quarter';
|
|
9
10
|
flag: PanelFlags;
|
|
11
|
+
highlightPosition: Position;
|
|
10
12
|
}
|
|
11
13
|
export interface DatepickerCalendarEvents {
|
|
12
14
|
change: [Dayjs, PanelFlags];
|
|
@@ -20,7 +22,7 @@ export declare class DatepickerCalendar extends Component<DatepickerCalendarProp
|
|
|
20
22
|
date: import("../../hooks/useState").State<Dayjs>;
|
|
21
23
|
getDateLabel: () => {
|
|
22
24
|
value: string;
|
|
23
|
-
onClick
|
|
25
|
+
onClick(e: import("../../hooks/useDocumentClick").IgnoreClickEvent): void;
|
|
24
26
|
}[];
|
|
25
27
|
prevMonth: () => void;
|
|
26
28
|
nextMonth: () => void;
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
import dayjs, { Dayjs, OpUnitType
|
|
2
|
-
export type OpUnitType = DayjsOpUnitType;
|
|
3
|
-
export type QUnitType = DayjsQUnitType;
|
|
4
|
-
declare module 'dayjs' {
|
|
5
|
-
interface Dayjs {
|
|
6
|
-
isSame(date?: dayjs.ConfigType, unit?: DayjsOpUnitType | DayjsQUnitType): boolean;
|
|
7
|
-
isBefore(date?: dayjs.ConfigType, unit?: DayjsOpUnitType | DayjsQUnitType): boolean;
|
|
8
|
-
isAfter(date?: dayjs.ConfigType, unit?: DayjsOpUnitType | DayjsQUnitType): boolean;
|
|
9
|
-
add(value: number, unit?: DayjsOpUnitType | DayjsQUnitType): dayjs.Dayjs;
|
|
10
|
-
subtract(value: number, unit?: DayjsOpUnitType | DayjsQUnitType): dayjs.Dayjs;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
1
|
+
import dayjs, { Dayjs, OpUnitType, QUnitType } from 'dayjs';
|
|
13
2
|
export default dayjs;
|
|
14
|
-
export type { Dayjs };
|
|
3
|
+
export type { Dayjs, OpUnitType, QUnitType };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import dayjs, { Dayjs, OpUnitType, QUnitType } from 'dayjs';
|
|
2
|
-
import {
|
|
2
|
+
import { last } from '../utils';
|
|
3
|
+
import { StateValueItem } from './useValueBase';
|
|
3
4
|
export declare function getNowDate(isEnd?: boolean): dayjs.Dayjs;
|
|
4
5
|
export declare function clearTime(date: Date): void;
|
|
5
6
|
export declare function endTime(date: Date): void;
|
|
@@ -8,4 +9,4 @@ export declare function isLT(a: Dayjs | undefined | null, b: Dayjs | undefined |
|
|
|
8
9
|
export declare function isGT(a: Dayjs | undefined | null, b: Dayjs | undefined | null, type?: OpUnitType | QUnitType): boolean;
|
|
9
10
|
export declare function createDate(date: string): Date;
|
|
10
11
|
export declare function findValueIndex(values: StateValueItem[], value: StateValueItem, type: OpUnitType | QUnitType): number;
|
|
11
|
-
export
|
|
12
|
+
export { last };
|
|
@@ -2,6 +2,7 @@ import _construct from "@babel/runtime-corejs3/helpers/construct";
|
|
|
2
2
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js/instance/map";
|
|
3
3
|
import _findIndexInstanceProperty from "@babel/runtime-corejs3/core-js/instance/find-index";
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
|
+
import { last } from '../utils';
|
|
5
6
|
export function getNowDate(isEnd) {
|
|
6
7
|
// only date without time
|
|
7
8
|
var now = new Date();
|
|
@@ -73,6 +74,4 @@ export function findValueIndex(values, value, type) {
|
|
|
73
74
|
}
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
|
-
export
|
|
77
|
-
return arr[arr.length - 1];
|
|
78
|
-
}
|
|
77
|
+
export { last };
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { TypeDefs } from 'intact';
|
|
2
2
|
import dayjs from './dayjs';
|
|
3
|
-
import { State } from '../../hooks/useState';
|
|
4
3
|
import { Shortcut } from './shortcuts';
|
|
5
|
-
import { BasePicker, BasePickerProps, BasePickerEvents, BasePickerBlocks
|
|
4
|
+
import { BasePicker, BasePickerProps, BasePickerEvents, BasePickerBlocks } from './basepicker';
|
|
5
|
+
import { Value } from './useValueBase';
|
|
6
6
|
export * as shortcuts from './shortcuts';
|
|
7
7
|
export { dayjs };
|
|
8
8
|
export interface DatepickerProps<V extends Value = Value, M extends boolean = boolean, R extends boolean = boolean> extends BasePickerProps<V extends string ? V : V | string, M, R> {
|
|
9
9
|
type?: 'date' | 'datetime' | 'year' | 'month' | 'week' | 'quarter';
|
|
10
10
|
shortcuts?: Shortcut[];
|
|
11
|
-
isMerge?: boolean;
|
|
12
11
|
}
|
|
13
12
|
export interface DatepickerEvents extends BasePickerEvents {
|
|
14
13
|
}
|
|
@@ -28,52 +27,45 @@ export declare class Datepicker<V extends Value = Value, M extends boolean = fal
|
|
|
28
27
|
};
|
|
29
28
|
disabled: {
|
|
30
29
|
isDisabled: (value: dayjs.Dayjs, type?: "h" | "s" | "y" | "date" | "month" | "week" | "millisecond" | "second" | "minute" | "hour" | "day" | "year" | "milliseconds" | "seconds" | "minutes" | "hours" | "days" | "months" | "years" | "dates" | "d" | "D" | "M" | "m" | "ms" | "weeks" | "w" | "quarter" | "quarters" | "Q") => boolean;
|
|
31
|
-
isDisabledTime: (value: dayjs.Dayjs
|
|
30
|
+
isDisabledTime: (value: dayjs.Dayjs) => boolean;
|
|
32
31
|
isDisabledConfirm: () => boolean;
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
isDisabledValue: (value: import("./useValueBase").StateValueItem) => boolean;
|
|
33
|
+
maxDate: import("../../hooks/useState").State<dayjs.Dayjs | null>;
|
|
34
|
+
minDate: import("../../hooks/useState").State<dayjs.Dayjs | null>;
|
|
35
35
|
};
|
|
36
36
|
panel: {
|
|
37
|
-
startPanel: State<import("./usePanel").PanelTypes>;
|
|
38
|
-
endPanel: State<import("./usePanel").PanelTypes>;
|
|
39
|
-
changePanel: (type: import("./usePanel").PanelTypes, flag?: import("./usePanel").PanelFlags) => void;
|
|
40
|
-
getPanel: (flag: import("./usePanel").PanelFlags) => State<import("./usePanel").PanelTypes>;
|
|
41
|
-
reset: () => void;
|
|
42
37
|
startRef: import("intact").RefObject<import("./calendar").DatepickerCalendar>;
|
|
43
38
|
endRef: import("intact").RefObject<import("./calendar").DatepickerCalendar>;
|
|
44
39
|
};
|
|
45
40
|
focusDate: {
|
|
46
|
-
focusDate: State<dayjs.Dayjs | null>;
|
|
41
|
+
focusDate: import("../../hooks/useState").State<dayjs.Dayjs | null>;
|
|
47
42
|
reset: () => void;
|
|
48
43
|
};
|
|
49
44
|
value: {
|
|
50
45
|
format: () => string | string[];
|
|
51
|
-
|
|
46
|
+
formatSingleValue: (value: import("./useValueBase").StateValueItem) => string;
|
|
52
47
|
onChangeTime: (date: dayjs.Dayjs, flag: import("./usePanel").PanelFlags) => void;
|
|
53
48
|
getTimeValue: (flag: import("./usePanel").PanelFlags) => dayjs.Dayjs | null | undefined;
|
|
54
|
-
convertToDayjs: (v: Value | [Value, Value] | Value[] | [Value, Value][] | null | undefined) => import("./
|
|
55
|
-
|
|
49
|
+
convertToDayjs: (v: Value | [Value, Value] | Value[] | [Value, Value][] | null | undefined) => import("./useValueBase").DayjsValue;
|
|
50
|
+
unique: () => void;
|
|
56
51
|
setMoment: () => void;
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
updateValue: () => void;
|
|
53
|
+
value: import("../../hooks/useState").State<import("./useValueBase").StateValue>;
|
|
54
|
+
setValue: (v: import("./useValueBase").StateValueItem, fromInput: boolean) => void;
|
|
59
55
|
onChangeDate: (v: dayjs.Dayjs, flag: import("./usePanel").PanelFlags) => void;
|
|
56
|
+
getDayjsValue: () => import("./useValueBase").DayjsValue;
|
|
57
|
+
allValuesUpdatedInMultipleMode: () => boolean | undefined;
|
|
60
58
|
};
|
|
61
|
-
|
|
62
|
-
position: State<"
|
|
63
|
-
|
|
64
|
-
startTextLength: State<number>;
|
|
65
|
-
handleInputClick: (e: MouseEvent) => void;
|
|
66
|
-
resetPosition: (pos?: "end" | "start") => void;
|
|
59
|
+
highlight: {
|
|
60
|
+
position: import("../../hooks/useState").State<import("./useHighlight").Position>;
|
|
61
|
+
handleInputClick: () => void;
|
|
67
62
|
togglePosition: () => void;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
};
|
|
71
|
-
mergeRange: {
|
|
72
|
-
formatMultipleValues: (dayjsValue: import("./basepicker").DayjsValue, results: string[]) => string[];
|
|
63
|
+
highlightWidth: import("../../hooks/useState").State<number>;
|
|
64
|
+
highlightLeft: import("../../hooks/useState").State<number>;
|
|
73
65
|
};
|
|
66
|
+
private confirm;
|
|
74
67
|
init(): void;
|
|
75
68
|
protected getPlaceholder(): string | number | boolean | import("misstime/dist/utils/types").VNode<any> | import("intact").Children[];
|
|
76
69
|
protected getLabel(): string | string[];
|
|
77
|
-
protected clear(e: MouseEvent): void;
|
|
78
70
|
private setByShortcut;
|
|
79
71
|
}
|