@douyinfe/semi-foundation 2.31.3-alpha.0 → 2.31.3
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/datePicker/_utils/isValidTimeZone.ts +3 -0
- package/datePicker/foundation.ts +18 -13
- package/datePicker/monthsGridFoundation.ts +3 -9
- package/lib/cjs/datePicker/_utils/isValidTimeZone.d.ts +1 -0
- package/lib/cjs/datePicker/_utils/isValidTimeZone.js +10 -0
- package/lib/cjs/datePicker/foundation.d.ts +12 -1
- package/lib/cjs/datePicker/foundation.js +20 -12
- package/lib/cjs/datePicker/monthsGridFoundation.d.ts +0 -1
- package/lib/cjs/datePicker/monthsGridFoundation.js +4 -11
- package/lib/cjs/overflowList/constants.d.ts +1 -1
- package/lib/cjs/table/utils.d.ts +3 -52
- package/lib/cjs/table/utils.js +48 -1
- package/lib/cjs/tree/treeUtil.d.ts +1 -1
- package/lib/cjs/upload/constants.d.ts +1 -1
- package/lib/cjs/utils/date-fns-extra.d.ts +24 -17
- package/lib/cjs/utils/date-fns-extra.js +22 -16
- package/lib/es/datePicker/_utils/isValidTimeZone.d.ts +1 -0
- package/lib/es/datePicker/_utils/isValidTimeZone.js +3 -0
- package/lib/es/datePicker/foundation.d.ts +12 -1
- package/lib/es/datePicker/foundation.js +19 -12
- package/lib/es/datePicker/monthsGridFoundation.d.ts +0 -1
- package/lib/es/datePicker/monthsGridFoundation.js +4 -11
- package/lib/es/overflowList/constants.d.ts +1 -1
- package/lib/es/table/utils.d.ts +3 -52
- package/lib/es/table/utils.js +43 -1
- package/lib/es/tree/treeUtil.d.ts +1 -1
- package/lib/es/upload/constants.d.ts +1 -1
- package/lib/es/utils/date-fns-extra.d.ts +24 -17
- package/lib/es/utils/date-fns-extra.js +22 -16
- package/package.json +4 -4
- package/table/utils.ts +43 -1
- package/utils/date-fns-extra.ts +27 -20
package/datePicker/foundation.ts
CHANGED
|
@@ -19,6 +19,7 @@ import type { ArrayElement, Motion } from '../utils/type';
|
|
|
19
19
|
import type { Type, DateInputFoundationProps, InsetInputValue } from './inputFoundation';
|
|
20
20
|
import type { MonthsGridFoundationProps } from './monthsGridFoundation';
|
|
21
21
|
import type { WeekStartNumber } from './_utils/getMonthTable';
|
|
22
|
+
import isValidTimeZone from './_utils/isValidTimeZone';
|
|
22
23
|
|
|
23
24
|
export type ValidateStatus = ArrayElement<typeof strings.STATUS>;
|
|
24
25
|
export type InputSize = ArrayElement<typeof strings.SIZE_SET>;
|
|
@@ -238,13 +239,6 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
238
239
|
this.initPanelOpenStatus(this.getProp('defaultOpen'));
|
|
239
240
|
}
|
|
240
241
|
|
|
241
|
-
isValidTimeZone(timeZone?: string | number) {
|
|
242
|
-
const propTimeZone = this.getProp('timeZone');
|
|
243
|
-
const _timeZone = isNullOrUndefined(timeZone) ? propTimeZone : timeZone;
|
|
244
|
-
|
|
245
|
-
return ['string', 'number'].includes(typeof _timeZone) && _timeZone !== '';
|
|
246
|
-
}
|
|
247
|
-
|
|
248
242
|
initFromProps({ value, timeZone, prevTimeZone }: Pick<DatePickerFoundationProps, 'value' | 'timeZone'> & { prevTimeZone?: string | number }) {
|
|
249
243
|
const _value = (Array.isArray(value) ? [...value] : (value || value === 0) && [value]) || [];
|
|
250
244
|
|
|
@@ -274,17 +268,28 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
274
268
|
}
|
|
275
269
|
}
|
|
276
270
|
|
|
271
|
+
/**
|
|
272
|
+
* value 可能是 UTC value 也可能是 zoned value
|
|
273
|
+
*
|
|
274
|
+
* UTC value -> 受控传入的 value
|
|
275
|
+
*
|
|
276
|
+
* zoned value -> statue.value,保存的是当前计算机时区下选择的日期
|
|
277
|
+
*
|
|
278
|
+
* 如果是时区变化,则需要将旧 zoned value 转为新时区下的 zoned value
|
|
279
|
+
*
|
|
280
|
+
* 如果是 value 变化,则不需要传入之前的时区,将 UTC value 转为 zoned value 即可
|
|
281
|
+
*
|
|
282
|
+
*/
|
|
277
283
|
parseWithTimezone(value: ValueType, timeZone: string | number, prevTimeZone: string | number) {
|
|
278
284
|
const result: Date[] = [];
|
|
279
285
|
if (Array.isArray(value) && value.length) {
|
|
280
286
|
for (const v of value) {
|
|
281
287
|
let parsedV = (v || v === 0) && this._parseValue(v);
|
|
282
288
|
if (parsedV) {
|
|
283
|
-
if (
|
|
284
|
-
parsedV = zonedTimeToUtc(parsedV, prevTimeZone
|
|
289
|
+
if (isValidTimeZone(prevTimeZone)) {
|
|
290
|
+
parsedV = zonedTimeToUtc(parsedV, prevTimeZone);
|
|
285
291
|
}
|
|
286
|
-
|
|
287
|
-
result.push(this.isValidTimeZone(timeZone) ? utcToZonedTime(parsedV, timeZone as string) : parsedV);
|
|
292
|
+
result.push(isValidTimeZone(timeZone) ? utcToZonedTime(parsedV, timeZone) : parsedV);
|
|
288
293
|
}
|
|
289
294
|
}
|
|
290
295
|
}
|
|
@@ -1098,9 +1103,9 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
1098
1103
|
*/
|
|
1099
1104
|
disposeCallbackArgs(value: Date | Date[]) {
|
|
1100
1105
|
let _value = Array.isArray(value) ? value : (value && [value]) || [];
|
|
1106
|
+
const timeZone = this.getProp('timeZone');
|
|
1101
1107
|
|
|
1102
|
-
if (
|
|
1103
|
-
const timeZone = this.getProp('timeZone');
|
|
1108
|
+
if (isValidTimeZone(timeZone)) {
|
|
1104
1109
|
_value = _value.map(date => zonedTimeToUtc(date, timeZone));
|
|
1105
1110
|
}
|
|
1106
1111
|
const type = this.getProp('type');
|
|
@@ -23,6 +23,7 @@ import isNullOrUndefined from '../utils/isNullOrUndefined';
|
|
|
23
23
|
import { BaseValueType, DateInputFoundationProps, PresetPosition, ValueType } from './foundation';
|
|
24
24
|
import { MonthDayInfo } from './monthFoundation';
|
|
25
25
|
import { ArrayElement } from '../utils/type';
|
|
26
|
+
import isValidTimeZone from './_utils/isValidTimeZone';
|
|
26
27
|
|
|
27
28
|
const dateDiffFns = {
|
|
28
29
|
month: differenceInCalendarMonths,
|
|
@@ -448,13 +449,6 @@ export default class MonthsGridFoundation extends BaseFoundation<MonthsGridAdapt
|
|
|
448
449
|
return format(date, token, { locale: dateFnsLocale });
|
|
449
450
|
}
|
|
450
451
|
|
|
451
|
-
isValidTimeZone(timeZone?: string | number) {
|
|
452
|
-
const propTimeZone = this.getProp('timeZone');
|
|
453
|
-
const _timeZone = isNullOrUndefined(timeZone) ? propTimeZone : timeZone;
|
|
454
|
-
|
|
455
|
-
return ['string', 'number'].includes(typeof _timeZone) && _timeZone !== '';
|
|
456
|
-
}
|
|
457
|
-
|
|
458
452
|
/**
|
|
459
453
|
* 根据 type 处理 onChange 返回的参数
|
|
460
454
|
*
|
|
@@ -484,9 +478,9 @@ export default class MonthsGridFoundation extends BaseFoundation<MonthsGridAdapt
|
|
|
484
478
|
*/
|
|
485
479
|
disposeCallbackArgs(value: Date | Date[]) {
|
|
486
480
|
let _value = Array.isArray(value) ? value : (value && [value]) || [];
|
|
481
|
+
const timeZone = this.getProp('timeZone');
|
|
487
482
|
|
|
488
|
-
if (
|
|
489
|
-
const timeZone = this.getProp('timeZone');
|
|
483
|
+
if (isValidTimeZone(timeZone)) {
|
|
490
484
|
_value = _value.map(date => zonedTimeToUtc(date, timeZone));
|
|
491
485
|
}
|
|
492
486
|
const type = this.getProp('type');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isValidTimeZone(timeZone?: string | number): boolean;
|
|
@@ -187,7 +187,6 @@ export interface DatePickerAdapter extends DefaultAdapter<DatePickerFoundationPr
|
|
|
187
187
|
export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapter> {
|
|
188
188
|
constructor(adapter: DatePickerAdapter);
|
|
189
189
|
init(): void;
|
|
190
|
-
isValidTimeZone(timeZone?: string | number): boolean;
|
|
191
190
|
initFromProps({ value, timeZone, prevTimeZone }: Pick<DatePickerFoundationProps, 'value' | 'timeZone'> & {
|
|
192
191
|
prevTimeZone?: string | number;
|
|
193
192
|
}): void;
|
|
@@ -197,6 +196,18 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
197
196
|
* If the user passes an empty value, you need to set the range input focus to rangeStart, so that the user can continue to select from the beginning after clearing
|
|
198
197
|
*/
|
|
199
198
|
initRangeInputFocus(result: Date[]): void;
|
|
199
|
+
/**
|
|
200
|
+
* value 可能是 UTC value 也可能是 zoned value
|
|
201
|
+
*
|
|
202
|
+
* UTC value -> 受控传入的 value
|
|
203
|
+
*
|
|
204
|
+
* zoned value -> statue.value,保存的是当前计算机时区下选择的日期
|
|
205
|
+
*
|
|
206
|
+
* 如果是时区变化,则需要将旧 zoned value 转为新时区下的 zoned value
|
|
207
|
+
*
|
|
208
|
+
* 如果是 value 变化,则不需要传入之前的时区,将 UTC value 转为 zoned value 即可
|
|
209
|
+
*
|
|
210
|
+
*/
|
|
200
211
|
parseWithTimezone(value: ValueType, timeZone: string | number, prevTimeZone: string | number): Date[];
|
|
201
212
|
_isMultiple(): boolean;
|
|
202
213
|
/**
|
|
@@ -37,6 +37,8 @@ var _getInsetInputFormatToken = _interopRequireDefault(require("./_utils/getInse
|
|
|
37
37
|
|
|
38
38
|
var _getInsetInputValueFromInsetInputStr = _interopRequireDefault(require("./_utils/getInsetInputValueFromInsetInputStr"));
|
|
39
39
|
|
|
40
|
+
var _isValidTimeZone = _interopRequireDefault(require("./_utils/isValidTimeZone"));
|
|
41
|
+
|
|
40
42
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
41
43
|
|
|
42
44
|
/* eslint-disable no-nested-ternary */
|
|
@@ -105,14 +107,6 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
105
107
|
this.initPanelOpenStatus(this.getProp('defaultOpen'));
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
isValidTimeZone(timeZone) {
|
|
109
|
-
const propTimeZone = this.getProp('timeZone');
|
|
110
|
-
|
|
111
|
-
const _timeZone = (0, _isNullOrUndefined.default)(timeZone) ? propTimeZone : timeZone;
|
|
112
|
-
|
|
113
|
-
return ['string', 'number'].includes(typeof _timeZone) && _timeZone !== '';
|
|
114
|
-
}
|
|
115
|
-
|
|
116
110
|
initFromProps(_ref) {
|
|
117
111
|
let {
|
|
118
112
|
value,
|
|
@@ -156,6 +150,19 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
156
150
|
this._adapter.setRangeInputFocus('rangeStart');
|
|
157
151
|
}
|
|
158
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* value 可能是 UTC value 也可能是 zoned value
|
|
155
|
+
*
|
|
156
|
+
* UTC value -> 受控传入的 value
|
|
157
|
+
*
|
|
158
|
+
* zoned value -> statue.value,保存的是当前计算机时区下选择的日期
|
|
159
|
+
*
|
|
160
|
+
* 如果是时区变化,则需要将旧 zoned value 转为新时区下的 zoned value
|
|
161
|
+
*
|
|
162
|
+
* 如果是 value 变化,则不需要传入之前的时区,将 UTC value 转为 zoned value 即可
|
|
163
|
+
*
|
|
164
|
+
*/
|
|
165
|
+
|
|
159
166
|
|
|
160
167
|
parseWithTimezone(value, timeZone, prevTimeZone) {
|
|
161
168
|
const result = [];
|
|
@@ -165,11 +172,11 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
165
172
|
let parsedV = (v || v === 0) && this._parseValue(v);
|
|
166
173
|
|
|
167
174
|
if (parsedV) {
|
|
168
|
-
if (
|
|
175
|
+
if ((0, _isValidTimeZone.default)(prevTimeZone)) {
|
|
169
176
|
parsedV = (0, _dateFnsExtra.zonedTimeToUtc)(parsedV, prevTimeZone);
|
|
170
177
|
}
|
|
171
178
|
|
|
172
|
-
result.push(
|
|
179
|
+
result.push((0, _isValidTimeZone.default)(timeZone) ? (0, _dateFnsExtra.utcToZonedTime)(parsedV, timeZone) : parsedV);
|
|
173
180
|
}
|
|
174
181
|
}
|
|
175
182
|
}
|
|
@@ -1155,8 +1162,9 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
1155
1162
|
disposeCallbackArgs(value) {
|
|
1156
1163
|
let _value = Array.isArray(value) ? value : value && [value] || [];
|
|
1157
1164
|
|
|
1158
|
-
|
|
1159
|
-
|
|
1165
|
+
const timeZone = this.getProp('timeZone');
|
|
1166
|
+
|
|
1167
|
+
if ((0, _isValidTimeZone.default)(timeZone)) {
|
|
1160
1168
|
_value = _value.map(date => (0, _dateFnsExtra.zonedTimeToUtc)(date, timeZone));
|
|
1161
1169
|
}
|
|
1162
1170
|
|
|
@@ -158,7 +158,6 @@ export default class MonthsGridFoundation extends BaseFoundation<MonthsGridAdapt
|
|
|
158
158
|
* @returns
|
|
159
159
|
*/
|
|
160
160
|
localeFormat(date: Date, token: string): string;
|
|
161
|
-
isValidTimeZone(timeZone?: string | number): boolean;
|
|
162
161
|
/**
|
|
163
162
|
* 根据 type 处理 onChange 返回的参数
|
|
164
163
|
*
|
|
@@ -27,7 +27,7 @@ var _dateFnsExtra = require("../utils/date-fns-extra");
|
|
|
27
27
|
|
|
28
28
|
var _getDefaultFormatToken = require("./_utils/getDefaultFormatToken");
|
|
29
29
|
|
|
30
|
-
var
|
|
30
|
+
var _isValidTimeZone = _interopRequireDefault(require("./_utils/isValidTimeZone"));
|
|
31
31
|
|
|
32
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
33
|
|
|
@@ -438,14 +438,6 @@ class MonthsGridFoundation extends _foundation.default {
|
|
|
438
438
|
locale: dateFnsLocale
|
|
439
439
|
});
|
|
440
440
|
}
|
|
441
|
-
|
|
442
|
-
isValidTimeZone(timeZone) {
|
|
443
|
-
const propTimeZone = this.getProp('timeZone');
|
|
444
|
-
|
|
445
|
-
const _timeZone = (0, _isNullOrUndefined.default)(timeZone) ? propTimeZone : timeZone;
|
|
446
|
-
|
|
447
|
-
return ['string', 'number'].includes(typeof _timeZone) && _timeZone !== '';
|
|
448
|
-
}
|
|
449
441
|
/**
|
|
450
442
|
* 根据 type 处理 onChange 返回的参数
|
|
451
443
|
*
|
|
@@ -478,8 +470,9 @@ class MonthsGridFoundation extends _foundation.default {
|
|
|
478
470
|
disposeCallbackArgs(value) {
|
|
479
471
|
let _value = Array.isArray(value) ? value : value && [value] || [];
|
|
480
472
|
|
|
481
|
-
|
|
482
|
-
|
|
473
|
+
const timeZone = this.getProp('timeZone');
|
|
474
|
+
|
|
475
|
+
if ((0, _isValidTimeZone.default)(timeZone)) {
|
|
483
476
|
_value = _value.map(date => (0, _dateFnsExtra.zonedTimeToUtc)(date, timeZone));
|
|
484
477
|
}
|
|
485
478
|
|
package/lib/cjs/table/utils.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { strings } from './constants';
|
|
2
|
+
export declare function cloneDeep(value: any, customizer?: (v: any) => any): any;
|
|
2
3
|
export declare function equalWith(value: any, other: any, customizer?: (...args: any[]) => boolean): boolean;
|
|
3
4
|
export declare function getColumnKey(column: any, keyPropNames: any[]): any;
|
|
5
|
+
export declare function mergeColumns(oldColumns?: any[], newColumns?: any[], keyPropNames?: any[], deep?: boolean): any[];
|
|
4
6
|
/**
|
|
5
7
|
*
|
|
6
8
|
* @param {Array<number>} arr
|
|
@@ -79,58 +81,7 @@ export declare function mergeQueries(query: Record<string, any>, queries?: Recor
|
|
|
79
81
|
* @param {Object[]} columns columns retain the column width after resize
|
|
80
82
|
* @param {Object[]} newColumns
|
|
81
83
|
*/
|
|
82
|
-
export declare function withResizeWidth(columns: Record<string, any>[], newColumns: Record<string, any>[]):
|
|
83
|
-
[x: number]: Record<string, any>;
|
|
84
|
-
length: number;
|
|
85
|
-
toString(): string;
|
|
86
|
-
toLocaleString(): string;
|
|
87
|
-
pop(): Record<string, any>;
|
|
88
|
-
push(...items: Record<string, any>[]): number;
|
|
89
|
-
concat(...items: ConcatArray<Record<string, any>>[]): Record<string, any>[];
|
|
90
|
-
concat(...items: (Record<string, any> | ConcatArray<Record<string, any>>)[]): Record<string, any>[];
|
|
91
|
-
join(separator?: string): string;
|
|
92
|
-
reverse(): Record<string, any>[];
|
|
93
|
-
shift(): Record<string, any>;
|
|
94
|
-
slice(start?: number, end?: number): Record<string, any>[];
|
|
95
|
-
sort(compareFn?: (a: Record<string, any>, b: Record<string, any>) => number): Record<string, any>[];
|
|
96
|
-
splice(start: number, deleteCount?: number): Record<string, any>[];
|
|
97
|
-
splice(start: number, deleteCount: number, ...items: Record<string, any>[]): Record<string, any>[];
|
|
98
|
-
unshift(...items: Record<string, any>[]): number;
|
|
99
|
-
indexOf(searchElement: Record<string, any>, fromIndex?: number): number;
|
|
100
|
-
lastIndexOf(searchElement: Record<string, any>, fromIndex?: number): number;
|
|
101
|
-
every<S extends Record<string, any>>(predicate: (value: Record<string, any>, index: number, array: Record<string, any>[]) => value is S, thisArg?: any): this is S[];
|
|
102
|
-
every(predicate: (value: Record<string, any>, index: number, array: Record<string, any>[]) => unknown, thisArg?: any): boolean;
|
|
103
|
-
some(predicate: (value: Record<string, any>, index: number, array: Record<string, any>[]) => unknown, thisArg?: any): boolean;
|
|
104
|
-
forEach(callbackfn: (value: Record<string, any>, index: number, array: Record<string, any>[]) => void, thisArg?: any): void;
|
|
105
|
-
map<U>(callbackfn: (value: Record<string, any>, index: number, array: Record<string, any>[]) => U, thisArg?: any): U[];
|
|
106
|
-
filter<S_1 extends Record<string, any>>(predicate: (value: Record<string, any>, index: number, array: Record<string, any>[]) => value is S_1, thisArg?: any): S_1[];
|
|
107
|
-
filter(predicate: (value: Record<string, any>, index: number, array: Record<string, any>[]) => unknown, thisArg?: any): Record<string, any>[];
|
|
108
|
-
reduce(callbackfn: (previousValue: Record<string, any>, currentValue: Record<string, any>, currentIndex: number, array: Record<string, any>[]) => Record<string, any>): Record<string, any>;
|
|
109
|
-
reduce(callbackfn: (previousValue: Record<string, any>, currentValue: Record<string, any>, currentIndex: number, array: Record<string, any>[]) => Record<string, any>, initialValue: Record<string, any>): Record<string, any>;
|
|
110
|
-
reduce<U_1>(callbackfn: (previousValue: U_1, currentValue: Record<string, any>, currentIndex: number, array: Record<string, any>[]) => U_1, initialValue: U_1): U_1;
|
|
111
|
-
reduceRight(callbackfn: (previousValue: Record<string, any>, currentValue: Record<string, any>, currentIndex: number, array: Record<string, any>[]) => Record<string, any>): Record<string, any>;
|
|
112
|
-
reduceRight(callbackfn: (previousValue: Record<string, any>, currentValue: Record<string, any>, currentIndex: number, array: Record<string, any>[]) => Record<string, any>, initialValue: Record<string, any>): Record<string, any>;
|
|
113
|
-
reduceRight<U_2>(callbackfn: (previousValue: U_2, currentValue: Record<string, any>, currentIndex: number, array: Record<string, any>[]) => U_2, initialValue: U_2): U_2;
|
|
114
|
-
find<S_2 extends Record<string, any>>(predicate: (this: void, value: Record<string, any>, index: number, obj: Record<string, any>[]) => value is S_2, thisArg?: any): S_2;
|
|
115
|
-
find(predicate: (value: Record<string, any>, index: number, obj: Record<string, any>[]) => unknown, thisArg?: any): Record<string, any>;
|
|
116
|
-
findIndex(predicate: (value: Record<string, any>, index: number, obj: Record<string, any>[]) => unknown, thisArg?: any): number;
|
|
117
|
-
fill(value: Record<string, any>, start?: number, end?: number): Record<string, any>[];
|
|
118
|
-
copyWithin(target: number, start: number, end?: number): Record<string, any>[];
|
|
119
|
-
entries(): IterableIterator<[number, Record<string, any>]>;
|
|
120
|
-
keys(): IterableIterator<number>;
|
|
121
|
-
values(): IterableIterator<Record<string, any>>;
|
|
122
|
-
includes(searchElement: Record<string, any>, fromIndex?: number): boolean;
|
|
123
|
-
[Symbol.iterator](): IterableIterator<Record<string, any>>;
|
|
124
|
-
[Symbol.unscopables](): {
|
|
125
|
-
copyWithin: boolean;
|
|
126
|
-
entries: boolean;
|
|
127
|
-
fill: boolean;
|
|
128
|
-
find: boolean;
|
|
129
|
-
findIndex: boolean;
|
|
130
|
-
keys: boolean;
|
|
131
|
-
values: boolean;
|
|
132
|
-
};
|
|
133
|
-
};
|
|
84
|
+
export declare function withResizeWidth(columns: Record<string, any>[], newColumns: Record<string, any>[]): any;
|
|
134
85
|
/**
|
|
135
86
|
* Pure function version of the same function in table foundation
|
|
136
87
|
* This is not accessible in getDerivedStateFromProps, so fork one out
|
package/lib/cjs/table/utils.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.arrayAdd = arrayAdd;
|
|
7
7
|
exports.assignColumnKeys = assignColumnKeys;
|
|
8
|
+
exports.cloneDeep = cloneDeep;
|
|
8
9
|
exports.equalWith = equalWith;
|
|
9
10
|
exports.expandBtnShouldInRow = expandBtnShouldInRow;
|
|
10
11
|
exports.filterColumns = filterColumns;
|
|
@@ -37,6 +38,7 @@ exports.isScrollbarColumn = isScrollbarColumn;
|
|
|
37
38
|
exports.isSelected = isSelected;
|
|
38
39
|
exports.isSelectionColumn = isSelectionColumn;
|
|
39
40
|
exports.isTreeTable = isTreeTable;
|
|
41
|
+
exports.mergeColumns = mergeColumns;
|
|
40
42
|
exports.mergeQueries = mergeQueries;
|
|
41
43
|
exports.sliceColumnsByLevel = sliceColumnsByLevel;
|
|
42
44
|
exports.warnIfNoDataIndex = warnIfNoDataIndex;
|
|
@@ -54,6 +56,10 @@ var _findIndex2 = _interopRequireDefault(require("lodash/findIndex"));
|
|
|
54
56
|
|
|
55
57
|
var _each2 = _interopRequireDefault(require("lodash/each"));
|
|
56
58
|
|
|
59
|
+
var _clone2 = _interopRequireDefault(require("lodash/clone"));
|
|
60
|
+
|
|
61
|
+
var _map2 = _interopRequireDefault(require("lodash/map"));
|
|
62
|
+
|
|
57
63
|
var _find2 = _interopRequireDefault(require("lodash/find"));
|
|
58
64
|
|
|
59
65
|
var _filter2 = _interopRequireDefault(require("lodash/filter"));
|
|
@@ -62,6 +68,8 @@ var _get2 = _interopRequireDefault(require("lodash/get"));
|
|
|
62
68
|
|
|
63
69
|
var _isEqualWith2 = _interopRequireDefault(require("lodash/isEqualWith"));
|
|
64
70
|
|
|
71
|
+
var _cloneDeepWith2 = _interopRequireDefault(require("lodash/cloneDeepWith"));
|
|
72
|
+
|
|
65
73
|
var _constants = require("./constants");
|
|
66
74
|
|
|
67
75
|
var _isNullOrUndefined = _interopRequireDefault(require("../utils/isNullOrUndefined"));
|
|
@@ -70,6 +78,18 @@ var _Logger = _interopRequireDefault(require("../utils/Logger"));
|
|
|
70
78
|
|
|
71
79
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
72
80
|
|
|
81
|
+
function cloneDeep(value, customizer) {
|
|
82
|
+
return (0, _cloneDeepWith2.default)(value, v => {
|
|
83
|
+
if (typeof v === 'function') {
|
|
84
|
+
return v;
|
|
85
|
+
} else if (typeof customizer === 'function') {
|
|
86
|
+
return customizer(v);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return undefined;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
73
93
|
function equalWith(value, other, customizer) {
|
|
74
94
|
return (0, _isEqualWith2.default)(value, other, function (objVal, othVal) {
|
|
75
95
|
if (typeof objVal === 'function' && typeof othVal === 'function') {
|
|
@@ -103,6 +123,33 @@ function getColumnKey(column, keyPropNames) {
|
|
|
103
123
|
});
|
|
104
124
|
return key;
|
|
105
125
|
}
|
|
126
|
+
|
|
127
|
+
function mergeColumns() {
|
|
128
|
+
let oldColumns = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
129
|
+
let newColumns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
130
|
+
let keyPropNames = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
131
|
+
let deep = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
132
|
+
const finalColumns = [];
|
|
133
|
+
const clone = deep ? cloneDeep : _clone2.default;
|
|
134
|
+
|
|
135
|
+
if (deep) {
|
|
136
|
+
const logger = new _Logger.default('[@douyinfe/semi-ui Table]');
|
|
137
|
+
logger.warn('Should not deep merge columns from foundation since columns may have react elements. Merge columns deep from semi-ui');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
(0, _map2.default)(newColumns, newColumn => {
|
|
141
|
+
newColumn = Object.assign({}, newColumn);
|
|
142
|
+
const key = getColumnKey(newColumn, keyPropNames);
|
|
143
|
+
const oldColumn = key != null && (0, _find2.default)(oldColumns, item => getColumnKey(item, keyPropNames) === key);
|
|
144
|
+
|
|
145
|
+
if (oldColumn) {
|
|
146
|
+
finalColumns.push(clone(Object.assign(Object.assign({}, oldColumn), newColumn)));
|
|
147
|
+
} else {
|
|
148
|
+
finalColumns.push(clone(newColumn));
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return finalColumns;
|
|
152
|
+
}
|
|
106
153
|
/**
|
|
107
154
|
*
|
|
108
155
|
* @param {Array<number>} arr
|
|
@@ -482,7 +529,7 @@ function mergeQueries(query) {
|
|
|
482
529
|
|
|
483
530
|
|
|
484
531
|
function withResizeWidth(columns, newColumns) {
|
|
485
|
-
const _newColumns =
|
|
532
|
+
const _newColumns = cloneDeep(newColumns);
|
|
486
533
|
|
|
487
534
|
for (const column of columns) {
|
|
488
535
|
if (!(0, _isNullOrUndefined.default)(column.width)) {
|
|
@@ -75,6 +75,6 @@ export declare function getValueOrKey(data: any): any;
|
|
|
75
75
|
export declare function normalizeValue(value: any, withObject: boolean): any;
|
|
76
76
|
export declare function updateKeys(keySet: Set<string> | string[], keyEntities: KeyEntities): string[];
|
|
77
77
|
export declare function calcDisabledKeys(keyEntities: KeyEntities): Set<string>;
|
|
78
|
-
export declare function calcDropRelativePosition(event: any, treeNode: any):
|
|
78
|
+
export declare function calcDropRelativePosition(event: any, treeNode: any): 1 | -1 | 0;
|
|
79
79
|
export declare function getDragNodesKeys(key: string, keyEntities: KeyEntities): string[];
|
|
80
80
|
export declare function calcDropActualPosition(pos: string, relativeDropPos: any): any;
|
|
@@ -18,7 +18,7 @@ declare const strings: {
|
|
|
18
18
|
DRAG_AREA_ILLEGAL: string;
|
|
19
19
|
TRIGGER_AUTO: "auto";
|
|
20
20
|
TRIGGER_CUSTOM: "custom";
|
|
21
|
-
UPLOAD_TRIGGER: ("
|
|
21
|
+
UPLOAD_TRIGGER: ("auto" | "custom")[];
|
|
22
22
|
VALIDATE_STATUS: readonly ["default", "error", "warning", "success"];
|
|
23
23
|
PROMPT_POSITION: readonly ["left", "right", "bottom"];
|
|
24
24
|
};
|
|
@@ -18,30 +18,37 @@ export declare const toIANA: (tz: string | number) => any;
|
|
|
18
18
|
* @returns {Date}
|
|
19
19
|
*/
|
|
20
20
|
declare const parse: (date: string | number | Date, formatToken: string, options?: any) => Date;
|
|
21
|
+
declare const format: (date: number | Date, formatToken: string, options?: any) => string;
|
|
21
22
|
/**
|
|
23
|
+
* Returns a Date which will format as the local time of any time zone from a specific UTC time
|
|
22
24
|
*
|
|
23
|
-
* @
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
* @example
|
|
26
|
+
* ```javascript
|
|
27
|
+
* import { utcToZonedTime } from 'date-fns-tz'
|
|
28
|
+
* const { isoDate, timeZone } = fetchInitialValues() // 2014-06-25T10:00:00.000Z, America/New_York
|
|
29
|
+
* const date = utcToZonedTime(isoDate, timeZone) // In June 10am UTC is 6am in New York (-04:00)
|
|
30
|
+
* renderDatePicker(date) // 2014-06-25 06:00:00 (in the system time zone)
|
|
31
|
+
* renderTimeZoneSelect(timeZone) // America/New_York
|
|
32
|
+
* ```
|
|
30
33
|
*
|
|
31
|
-
* @
|
|
32
|
-
* @param {string} timeZone
|
|
33
|
-
* @param {object} options
|
|
34
|
-
* @returns {Date}
|
|
34
|
+
* @see https://github.com/marnusw/date-fns-tz#utctozonedtime
|
|
35
35
|
*/
|
|
36
|
-
declare const utcToZonedTime: (date: string | number | Date, timeZone: string, options?: OptionsWithTZ) => Date;
|
|
36
|
+
declare const utcToZonedTime: (date: string | number | Date, timeZone: string | number, options?: OptionsWithTZ) => Date;
|
|
37
37
|
/**
|
|
38
|
+
* Given a date and any time zone, returns a Date with the equivalent UTC time
|
|
38
39
|
*
|
|
39
|
-
* @
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```
|
|
42
|
+
* import { zonedTimeToUtc } from 'date-fns-tz'
|
|
43
|
+
* const date = getDatePickerValue() // e.g. 2014-06-25 10:00:00 (picked in any time zone)
|
|
44
|
+
* const timeZone = getTimeZoneValue() // e.g. America/Los_Angeles
|
|
45
|
+
* const utcDate = zonedTimeToUtc(date, timeZone) // In June 10am in Los Angeles is 5pm UTC
|
|
46
|
+
* postToServer(utcDate.toISOString(), timeZone) // post 2014-06-25T17:00:00.000Z, America/Los_Angeles
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @see https://github.com/marnusw/date-fns-tz#zonedtimetoutc
|
|
43
50
|
*/
|
|
44
|
-
declare const zonedTimeToUtc: (date: string | number | Date, timeZone: string, options?: OptionsWithTZ) => Date;
|
|
51
|
+
declare const zonedTimeToUtc: (date: string | number | Date, timeZone: string | number, options?: OptionsWithTZ) => Date;
|
|
45
52
|
/**
|
|
46
53
|
* return current system hour offset based on utc:
|
|
47
54
|
*
|
|
@@ -75,14 +75,6 @@ const parse = (date, formatToken, options) => {
|
|
|
75
75
|
|
|
76
76
|
return (0, _dateFnsTz.toDate)(date, options);
|
|
77
77
|
};
|
|
78
|
-
/**
|
|
79
|
-
*
|
|
80
|
-
* @param {string | number | Date} date
|
|
81
|
-
* @param {string} formatToken
|
|
82
|
-
* @param {object} [options]
|
|
83
|
-
* @param {string} [options.timeZone]
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
78
|
/* istanbul ignore next */
|
|
87
79
|
|
|
88
80
|
|
|
@@ -100,11 +92,18 @@ const format = (date, formatToken, options) => {
|
|
|
100
92
|
return (0, _dateFnsTz.format)(date, formatToken, options);
|
|
101
93
|
};
|
|
102
94
|
/**
|
|
95
|
+
* Returns a Date which will format as the local time of any time zone from a specific UTC time
|
|
103
96
|
*
|
|
104
|
-
* @
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```javascript
|
|
99
|
+
* import { utcToZonedTime } from 'date-fns-tz'
|
|
100
|
+
* const { isoDate, timeZone } = fetchInitialValues() // 2014-06-25T10:00:00.000Z, America/New_York
|
|
101
|
+
* const date = utcToZonedTime(isoDate, timeZone) // In June 10am UTC is 6am in New York (-04:00)
|
|
102
|
+
* renderDatePicker(date) // 2014-06-25 06:00:00 (in the system time zone)
|
|
103
|
+
* renderTimeZoneSelect(timeZone) // America/New_York
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @see https://github.com/marnusw/date-fns-tz#utctozonedtime
|
|
108
107
|
*/
|
|
109
108
|
|
|
110
109
|
|
|
@@ -112,11 +111,18 @@ exports.format = format;
|
|
|
112
111
|
|
|
113
112
|
const utcToZonedTime = (date, timeZone, options) => (0, _dateFnsTz.utcToZonedTime)(date, toIANA(timeZone), options);
|
|
114
113
|
/**
|
|
114
|
+
* Given a date and any time zone, returns a Date with the equivalent UTC time
|
|
115
115
|
*
|
|
116
|
-
* @
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```
|
|
118
|
+
* import { zonedTimeToUtc } from 'date-fns-tz'
|
|
119
|
+
* const date = getDatePickerValue() // e.g. 2014-06-25 10:00:00 (picked in any time zone)
|
|
120
|
+
* const timeZone = getTimeZoneValue() // e.g. America/Los_Angeles
|
|
121
|
+
* const utcDate = zonedTimeToUtc(date, timeZone) // In June 10am in Los Angeles is 5pm UTC
|
|
122
|
+
* postToServer(utcDate.toISOString(), timeZone) // post 2014-06-25T17:00:00.000Z, America/Los_Angeles
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @see https://github.com/marnusw/date-fns-tz#zonedtimetoutc
|
|
120
126
|
*/
|
|
121
127
|
|
|
122
128
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isValidTimeZone(timeZone?: string | number): boolean;
|
|
@@ -187,7 +187,6 @@ export interface DatePickerAdapter extends DefaultAdapter<DatePickerFoundationPr
|
|
|
187
187
|
export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapter> {
|
|
188
188
|
constructor(adapter: DatePickerAdapter);
|
|
189
189
|
init(): void;
|
|
190
|
-
isValidTimeZone(timeZone?: string | number): boolean;
|
|
191
190
|
initFromProps({ value, timeZone, prevTimeZone }: Pick<DatePickerFoundationProps, 'value' | 'timeZone'> & {
|
|
192
191
|
prevTimeZone?: string | number;
|
|
193
192
|
}): void;
|
|
@@ -197,6 +196,18 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
197
196
|
* If the user passes an empty value, you need to set the range input focus to rangeStart, so that the user can continue to select from the beginning after clearing
|
|
198
197
|
*/
|
|
199
198
|
initRangeInputFocus(result: Date[]): void;
|
|
199
|
+
/**
|
|
200
|
+
* value 可能是 UTC value 也可能是 zoned value
|
|
201
|
+
*
|
|
202
|
+
* UTC value -> 受控传入的 value
|
|
203
|
+
*
|
|
204
|
+
* zoned value -> statue.value,保存的是当前计算机时区下选择的日期
|
|
205
|
+
*
|
|
206
|
+
* 如果是时区变化,则需要将旧 zoned value 转为新时区下的 zoned value
|
|
207
|
+
*
|
|
208
|
+
* 如果是 value 变化,则不需要传入之前的时区,将 UTC value 转为 zoned value 即可
|
|
209
|
+
*
|
|
210
|
+
*/
|
|
200
211
|
parseWithTimezone(value: ValueType, timeZone: string | number, prevTimeZone: string | number): Date[];
|
|
201
212
|
_isMultiple(): boolean;
|
|
202
213
|
/**
|
|
@@ -18,6 +18,7 @@ import { strings } from './constants';
|
|
|
18
18
|
import { strings as inputStrings } from '../input/constants';
|
|
19
19
|
import getInsetInputFormatToken from './_utils/getInsetInputFormatToken';
|
|
20
20
|
import getInsetInputValueFromInsetInputStr from './_utils/getInsetInputValueFromInsetInputStr';
|
|
21
|
+
import isValidTimeZone from './_utils/isValidTimeZone';
|
|
21
22
|
/**
|
|
22
23
|
* The datePicker foundation.js is responsible for maintaining the date value and the input box value, as well as the callback of both
|
|
23
24
|
* task 1. Accept the selected date change, update the date value, and update the input box value according to the date = > Notify the change
|
|
@@ -81,14 +82,6 @@ export default class DatePickerFoundation extends BaseFoundation {
|
|
|
81
82
|
this.initPanelOpenStatus(this.getProp('defaultOpen'));
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
isValidTimeZone(timeZone) {
|
|
85
|
-
const propTimeZone = this.getProp('timeZone');
|
|
86
|
-
|
|
87
|
-
const _timeZone = isNullOrUndefined(timeZone) ? propTimeZone : timeZone;
|
|
88
|
-
|
|
89
|
-
return ['string', 'number'].includes(typeof _timeZone) && _timeZone !== '';
|
|
90
|
-
}
|
|
91
|
-
|
|
92
85
|
initFromProps(_ref) {
|
|
93
86
|
let {
|
|
94
87
|
value,
|
|
@@ -132,6 +125,19 @@ export default class DatePickerFoundation extends BaseFoundation {
|
|
|
132
125
|
this._adapter.setRangeInputFocus('rangeStart');
|
|
133
126
|
}
|
|
134
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* value 可能是 UTC value 也可能是 zoned value
|
|
130
|
+
*
|
|
131
|
+
* UTC value -> 受控传入的 value
|
|
132
|
+
*
|
|
133
|
+
* zoned value -> statue.value,保存的是当前计算机时区下选择的日期
|
|
134
|
+
*
|
|
135
|
+
* 如果是时区变化,则需要将旧 zoned value 转为新时区下的 zoned value
|
|
136
|
+
*
|
|
137
|
+
* 如果是 value 变化,则不需要传入之前的时区,将 UTC value 转为 zoned value 即可
|
|
138
|
+
*
|
|
139
|
+
*/
|
|
140
|
+
|
|
135
141
|
|
|
136
142
|
parseWithTimezone(value, timeZone, prevTimeZone) {
|
|
137
143
|
const result = [];
|
|
@@ -141,11 +147,11 @@ export default class DatePickerFoundation extends BaseFoundation {
|
|
|
141
147
|
let parsedV = (v || v === 0) && this._parseValue(v);
|
|
142
148
|
|
|
143
149
|
if (parsedV) {
|
|
144
|
-
if (
|
|
150
|
+
if (isValidTimeZone(prevTimeZone)) {
|
|
145
151
|
parsedV = zonedTimeToUtc(parsedV, prevTimeZone);
|
|
146
152
|
}
|
|
147
153
|
|
|
148
|
-
result.push(
|
|
154
|
+
result.push(isValidTimeZone(timeZone) ? utcToZonedTime(parsedV, timeZone) : parsedV);
|
|
149
155
|
}
|
|
150
156
|
}
|
|
151
157
|
}
|
|
@@ -1134,8 +1140,9 @@ export default class DatePickerFoundation extends BaseFoundation {
|
|
|
1134
1140
|
disposeCallbackArgs(value) {
|
|
1135
1141
|
let _value = Array.isArray(value) ? value : value && [value] || [];
|
|
1136
1142
|
|
|
1137
|
-
|
|
1138
|
-
|
|
1143
|
+
const timeZone = this.getProp('timeZone');
|
|
1144
|
+
|
|
1145
|
+
if (isValidTimeZone(timeZone)) {
|
|
1139
1146
|
_value = _value.map(date => zonedTimeToUtc(date, timeZone));
|
|
1140
1147
|
}
|
|
1141
1148
|
|
|
@@ -158,7 +158,6 @@ export default class MonthsGridFoundation extends BaseFoundation<MonthsGridAdapt
|
|
|
158
158
|
* @returns
|
|
159
159
|
*/
|
|
160
160
|
localeFormat(date: Date, token: string): string;
|
|
161
|
-
isValidTimeZone(timeZone?: string | number): boolean;
|
|
162
161
|
/**
|
|
163
162
|
* 根据 type 处理 onChange 返回的参数
|
|
164
163
|
*
|
|
@@ -11,7 +11,7 @@ import { formatFullDate } from './_utils/getMonthTable';
|
|
|
11
11
|
import { compatibleParse } from './_utils/parser';
|
|
12
12
|
import { zonedTimeToUtc } from '../utils/date-fns-extra';
|
|
13
13
|
import { getDefaultFormatTokenByType } from './_utils/getDefaultFormatToken';
|
|
14
|
-
import
|
|
14
|
+
import isValidTimeZone from './_utils/isValidTimeZone';
|
|
15
15
|
const dateDiffFns = {
|
|
16
16
|
month: differenceInCalendarMonths,
|
|
17
17
|
year: differenceInCalendarYears
|
|
@@ -417,14 +417,6 @@ export default class MonthsGridFoundation extends BaseFoundation {
|
|
|
417
417
|
locale: dateFnsLocale
|
|
418
418
|
});
|
|
419
419
|
}
|
|
420
|
-
|
|
421
|
-
isValidTimeZone(timeZone) {
|
|
422
|
-
const propTimeZone = this.getProp('timeZone');
|
|
423
|
-
|
|
424
|
-
const _timeZone = isNullOrUndefined(timeZone) ? propTimeZone : timeZone;
|
|
425
|
-
|
|
426
|
-
return ['string', 'number'].includes(typeof _timeZone) && _timeZone !== '';
|
|
427
|
-
}
|
|
428
420
|
/**
|
|
429
421
|
* 根据 type 处理 onChange 返回的参数
|
|
430
422
|
*
|
|
@@ -457,8 +449,9 @@ export default class MonthsGridFoundation extends BaseFoundation {
|
|
|
457
449
|
disposeCallbackArgs(value) {
|
|
458
450
|
let _value = Array.isArray(value) ? value : value && [value] || [];
|
|
459
451
|
|
|
460
|
-
|
|
461
|
-
|
|
452
|
+
const timeZone = this.getProp('timeZone');
|
|
453
|
+
|
|
454
|
+
if (isValidTimeZone(timeZone)) {
|
|
462
455
|
_value = _value.map(date => zonedTimeToUtc(date, timeZone));
|
|
463
456
|
}
|
|
464
457
|
|
package/lib/es/table/utils.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { strings } from './constants';
|
|
2
|
+
export declare function cloneDeep(value: any, customizer?: (v: any) => any): any;
|
|
2
3
|
export declare function equalWith(value: any, other: any, customizer?: (...args: any[]) => boolean): boolean;
|
|
3
4
|
export declare function getColumnKey(column: any, keyPropNames: any[]): any;
|
|
5
|
+
export declare function mergeColumns(oldColumns?: any[], newColumns?: any[], keyPropNames?: any[], deep?: boolean): any[];
|
|
4
6
|
/**
|
|
5
7
|
*
|
|
6
8
|
* @param {Array<number>} arr
|
|
@@ -79,58 +81,7 @@ export declare function mergeQueries(query: Record<string, any>, queries?: Recor
|
|
|
79
81
|
* @param {Object[]} columns columns retain the column width after resize
|
|
80
82
|
* @param {Object[]} newColumns
|
|
81
83
|
*/
|
|
82
|
-
export declare function withResizeWidth(columns: Record<string, any>[], newColumns: Record<string, any>[]):
|
|
83
|
-
[x: number]: Record<string, any>;
|
|
84
|
-
length: number;
|
|
85
|
-
toString(): string;
|
|
86
|
-
toLocaleString(): string;
|
|
87
|
-
pop(): Record<string, any>;
|
|
88
|
-
push(...items: Record<string, any>[]): number;
|
|
89
|
-
concat(...items: ConcatArray<Record<string, any>>[]): Record<string, any>[];
|
|
90
|
-
concat(...items: (Record<string, any> | ConcatArray<Record<string, any>>)[]): Record<string, any>[];
|
|
91
|
-
join(separator?: string): string;
|
|
92
|
-
reverse(): Record<string, any>[];
|
|
93
|
-
shift(): Record<string, any>;
|
|
94
|
-
slice(start?: number, end?: number): Record<string, any>[];
|
|
95
|
-
sort(compareFn?: (a: Record<string, any>, b: Record<string, any>) => number): Record<string, any>[];
|
|
96
|
-
splice(start: number, deleteCount?: number): Record<string, any>[];
|
|
97
|
-
splice(start: number, deleteCount: number, ...items: Record<string, any>[]): Record<string, any>[];
|
|
98
|
-
unshift(...items: Record<string, any>[]): number;
|
|
99
|
-
indexOf(searchElement: Record<string, any>, fromIndex?: number): number;
|
|
100
|
-
lastIndexOf(searchElement: Record<string, any>, fromIndex?: number): number;
|
|
101
|
-
every<S extends Record<string, any>>(predicate: (value: Record<string, any>, index: number, array: Record<string, any>[]) => value is S, thisArg?: any): this is S[];
|
|
102
|
-
every(predicate: (value: Record<string, any>, index: number, array: Record<string, any>[]) => unknown, thisArg?: any): boolean;
|
|
103
|
-
some(predicate: (value: Record<string, any>, index: number, array: Record<string, any>[]) => unknown, thisArg?: any): boolean;
|
|
104
|
-
forEach(callbackfn: (value: Record<string, any>, index: number, array: Record<string, any>[]) => void, thisArg?: any): void;
|
|
105
|
-
map<U>(callbackfn: (value: Record<string, any>, index: number, array: Record<string, any>[]) => U, thisArg?: any): U[];
|
|
106
|
-
filter<S_1 extends Record<string, any>>(predicate: (value: Record<string, any>, index: number, array: Record<string, any>[]) => value is S_1, thisArg?: any): S_1[];
|
|
107
|
-
filter(predicate: (value: Record<string, any>, index: number, array: Record<string, any>[]) => unknown, thisArg?: any): Record<string, any>[];
|
|
108
|
-
reduce(callbackfn: (previousValue: Record<string, any>, currentValue: Record<string, any>, currentIndex: number, array: Record<string, any>[]) => Record<string, any>): Record<string, any>;
|
|
109
|
-
reduce(callbackfn: (previousValue: Record<string, any>, currentValue: Record<string, any>, currentIndex: number, array: Record<string, any>[]) => Record<string, any>, initialValue: Record<string, any>): Record<string, any>;
|
|
110
|
-
reduce<U_1>(callbackfn: (previousValue: U_1, currentValue: Record<string, any>, currentIndex: number, array: Record<string, any>[]) => U_1, initialValue: U_1): U_1;
|
|
111
|
-
reduceRight(callbackfn: (previousValue: Record<string, any>, currentValue: Record<string, any>, currentIndex: number, array: Record<string, any>[]) => Record<string, any>): Record<string, any>;
|
|
112
|
-
reduceRight(callbackfn: (previousValue: Record<string, any>, currentValue: Record<string, any>, currentIndex: number, array: Record<string, any>[]) => Record<string, any>, initialValue: Record<string, any>): Record<string, any>;
|
|
113
|
-
reduceRight<U_2>(callbackfn: (previousValue: U_2, currentValue: Record<string, any>, currentIndex: number, array: Record<string, any>[]) => U_2, initialValue: U_2): U_2;
|
|
114
|
-
find<S_2 extends Record<string, any>>(predicate: (this: void, value: Record<string, any>, index: number, obj: Record<string, any>[]) => value is S_2, thisArg?: any): S_2;
|
|
115
|
-
find(predicate: (value: Record<string, any>, index: number, obj: Record<string, any>[]) => unknown, thisArg?: any): Record<string, any>;
|
|
116
|
-
findIndex(predicate: (value: Record<string, any>, index: number, obj: Record<string, any>[]) => unknown, thisArg?: any): number;
|
|
117
|
-
fill(value: Record<string, any>, start?: number, end?: number): Record<string, any>[];
|
|
118
|
-
copyWithin(target: number, start: number, end?: number): Record<string, any>[];
|
|
119
|
-
entries(): IterableIterator<[number, Record<string, any>]>;
|
|
120
|
-
keys(): IterableIterator<number>;
|
|
121
|
-
values(): IterableIterator<Record<string, any>>;
|
|
122
|
-
includes(searchElement: Record<string, any>, fromIndex?: number): boolean;
|
|
123
|
-
[Symbol.iterator](): IterableIterator<Record<string, any>>;
|
|
124
|
-
[Symbol.unscopables](): {
|
|
125
|
-
copyWithin: boolean;
|
|
126
|
-
entries: boolean;
|
|
127
|
-
fill: boolean;
|
|
128
|
-
find: boolean;
|
|
129
|
-
findIndex: boolean;
|
|
130
|
-
keys: boolean;
|
|
131
|
-
values: boolean;
|
|
132
|
-
};
|
|
133
|
-
};
|
|
84
|
+
export declare function withResizeWidth(columns: Record<string, any>[], newColumns: Record<string, any>[]): any;
|
|
134
85
|
/**
|
|
135
86
|
* Pure function version of the same function in table foundation
|
|
136
87
|
* This is not accessible in getDerivedStateFromProps, so fork one out
|
package/lib/es/table/utils.js
CHANGED
|
@@ -4,13 +4,27 @@ import _includes from "lodash/includes";
|
|
|
4
4
|
import _some from "lodash/some";
|
|
5
5
|
import _findIndex from "lodash/findIndex";
|
|
6
6
|
import _each from "lodash/each";
|
|
7
|
+
import _clone from "lodash/clone";
|
|
8
|
+
import _map from "lodash/map";
|
|
7
9
|
import _find from "lodash/find";
|
|
8
10
|
import _filter from "lodash/filter";
|
|
9
11
|
import _get from "lodash/get";
|
|
10
12
|
import _isEqualWith from "lodash/isEqualWith";
|
|
13
|
+
import _cloneDeepWith from "lodash/cloneDeepWith";
|
|
11
14
|
import { strings, numbers } from './constants';
|
|
12
15
|
import isNullOrUndefined from '../utils/isNullOrUndefined';
|
|
13
16
|
import Logger from '../utils/Logger';
|
|
17
|
+
export function cloneDeep(value, customizer) {
|
|
18
|
+
return _cloneDeepWith(value, v => {
|
|
19
|
+
if (typeof v === 'function') {
|
|
20
|
+
return v;
|
|
21
|
+
} else if (typeof customizer === 'function') {
|
|
22
|
+
return customizer(v);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return undefined;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
14
28
|
export function equalWith(value, other, customizer) {
|
|
15
29
|
return _isEqualWith(value, other, function (objVal, othVal) {
|
|
16
30
|
if (typeof objVal === 'function' && typeof othVal === 'function') {
|
|
@@ -45,6 +59,34 @@ export function getColumnKey(column, keyPropNames) {
|
|
|
45
59
|
|
|
46
60
|
return key;
|
|
47
61
|
}
|
|
62
|
+
export function mergeColumns() {
|
|
63
|
+
let oldColumns = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
64
|
+
let newColumns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
65
|
+
let keyPropNames = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
66
|
+
let deep = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
67
|
+
const finalColumns = [];
|
|
68
|
+
const clone = deep ? cloneDeep : _clone;
|
|
69
|
+
|
|
70
|
+
if (deep) {
|
|
71
|
+
const logger = new Logger('[@douyinfe/semi-ui Table]');
|
|
72
|
+
logger.warn('Should not deep merge columns from foundation since columns may have react elements. Merge columns deep from semi-ui');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
_map(newColumns, newColumn => {
|
|
76
|
+
newColumn = Object.assign({}, newColumn);
|
|
77
|
+
const key = getColumnKey(newColumn, keyPropNames);
|
|
78
|
+
|
|
79
|
+
const oldColumn = key != null && _find(oldColumns, item => getColumnKey(item, keyPropNames) === key);
|
|
80
|
+
|
|
81
|
+
if (oldColumn) {
|
|
82
|
+
finalColumns.push(clone(Object.assign(Object.assign({}, oldColumn), newColumn)));
|
|
83
|
+
} else {
|
|
84
|
+
finalColumns.push(clone(newColumn));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return finalColumns;
|
|
89
|
+
}
|
|
48
90
|
/**
|
|
49
91
|
*
|
|
50
92
|
* @param {Array<number>} arr
|
|
@@ -403,7 +445,7 @@ export function mergeQueries(query) {
|
|
|
403
445
|
*/
|
|
404
446
|
|
|
405
447
|
export function withResizeWidth(columns, newColumns) {
|
|
406
|
-
const _newColumns =
|
|
448
|
+
const _newColumns = cloneDeep(newColumns);
|
|
407
449
|
|
|
408
450
|
for (const column of columns) {
|
|
409
451
|
if (!isNullOrUndefined(column.width)) {
|
|
@@ -75,6 +75,6 @@ export declare function getValueOrKey(data: any): any;
|
|
|
75
75
|
export declare function normalizeValue(value: any, withObject: boolean): any;
|
|
76
76
|
export declare function updateKeys(keySet: Set<string> | string[], keyEntities: KeyEntities): string[];
|
|
77
77
|
export declare function calcDisabledKeys(keyEntities: KeyEntities): Set<string>;
|
|
78
|
-
export declare function calcDropRelativePosition(event: any, treeNode: any):
|
|
78
|
+
export declare function calcDropRelativePosition(event: any, treeNode: any): 1 | -1 | 0;
|
|
79
79
|
export declare function getDragNodesKeys(key: string, keyEntities: KeyEntities): string[];
|
|
80
80
|
export declare function calcDropActualPosition(pos: string, relativeDropPos: any): any;
|
|
@@ -18,7 +18,7 @@ declare const strings: {
|
|
|
18
18
|
DRAG_AREA_ILLEGAL: string;
|
|
19
19
|
TRIGGER_AUTO: "auto";
|
|
20
20
|
TRIGGER_CUSTOM: "custom";
|
|
21
|
-
UPLOAD_TRIGGER: ("
|
|
21
|
+
UPLOAD_TRIGGER: ("auto" | "custom")[];
|
|
22
22
|
VALIDATE_STATUS: readonly ["default", "error", "warning", "success"];
|
|
23
23
|
PROMPT_POSITION: readonly ["left", "right", "bottom"];
|
|
24
24
|
};
|
|
@@ -18,30 +18,37 @@ export declare const toIANA: (tz: string | number) => any;
|
|
|
18
18
|
* @returns {Date}
|
|
19
19
|
*/
|
|
20
20
|
declare const parse: (date: string | number | Date, formatToken: string, options?: any) => Date;
|
|
21
|
+
declare const format: (date: number | Date, formatToken: string, options?: any) => string;
|
|
21
22
|
/**
|
|
23
|
+
* Returns a Date which will format as the local time of any time zone from a specific UTC time
|
|
22
24
|
*
|
|
23
|
-
* @
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
* @example
|
|
26
|
+
* ```javascript
|
|
27
|
+
* import { utcToZonedTime } from 'date-fns-tz'
|
|
28
|
+
* const { isoDate, timeZone } = fetchInitialValues() // 2014-06-25T10:00:00.000Z, America/New_York
|
|
29
|
+
* const date = utcToZonedTime(isoDate, timeZone) // In June 10am UTC is 6am in New York (-04:00)
|
|
30
|
+
* renderDatePicker(date) // 2014-06-25 06:00:00 (in the system time zone)
|
|
31
|
+
* renderTimeZoneSelect(timeZone) // America/New_York
|
|
32
|
+
* ```
|
|
30
33
|
*
|
|
31
|
-
* @
|
|
32
|
-
* @param {string} timeZone
|
|
33
|
-
* @param {object} options
|
|
34
|
-
* @returns {Date}
|
|
34
|
+
* @see https://github.com/marnusw/date-fns-tz#utctozonedtime
|
|
35
35
|
*/
|
|
36
|
-
declare const utcToZonedTime: (date: string | number | Date, timeZone: string, options?: OptionsWithTZ) => Date;
|
|
36
|
+
declare const utcToZonedTime: (date: string | number | Date, timeZone: string | number, options?: OptionsWithTZ) => Date;
|
|
37
37
|
/**
|
|
38
|
+
* Given a date and any time zone, returns a Date with the equivalent UTC time
|
|
38
39
|
*
|
|
39
|
-
* @
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```
|
|
42
|
+
* import { zonedTimeToUtc } from 'date-fns-tz'
|
|
43
|
+
* const date = getDatePickerValue() // e.g. 2014-06-25 10:00:00 (picked in any time zone)
|
|
44
|
+
* const timeZone = getTimeZoneValue() // e.g. America/Los_Angeles
|
|
45
|
+
* const utcDate = zonedTimeToUtc(date, timeZone) // In June 10am in Los Angeles is 5pm UTC
|
|
46
|
+
* postToServer(utcDate.toISOString(), timeZone) // post 2014-06-25T17:00:00.000Z, America/Los_Angeles
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @see https://github.com/marnusw/date-fns-tz#zonedtimetoutc
|
|
43
50
|
*/
|
|
44
|
-
declare const zonedTimeToUtc: (date: string | number | Date, timeZone: string, options?: OptionsWithTZ) => Date;
|
|
51
|
+
declare const zonedTimeToUtc: (date: string | number | Date, timeZone: string | number, options?: OptionsWithTZ) => Date;
|
|
45
52
|
/**
|
|
46
53
|
* return current system hour offset based on utc:
|
|
47
54
|
*
|
|
@@ -62,14 +62,6 @@ const parse = (date, formatToken, options) => {
|
|
|
62
62
|
|
|
63
63
|
return toDate(date, options);
|
|
64
64
|
};
|
|
65
|
-
/**
|
|
66
|
-
*
|
|
67
|
-
* @param {string | number | Date} date
|
|
68
|
-
* @param {string} formatToken
|
|
69
|
-
* @param {object} [options]
|
|
70
|
-
* @param {string} [options.timeZone]
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
65
|
/* istanbul ignore next */
|
|
74
66
|
|
|
75
67
|
|
|
@@ -85,21 +77,35 @@ const format = (date, formatToken, options) => {
|
|
|
85
77
|
return dateFnsFormat(date, formatToken, options);
|
|
86
78
|
};
|
|
87
79
|
/**
|
|
80
|
+
* Returns a Date which will format as the local time of any time zone from a specific UTC time
|
|
88
81
|
*
|
|
89
|
-
* @
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```javascript
|
|
84
|
+
* import { utcToZonedTime } from 'date-fns-tz'
|
|
85
|
+
* const { isoDate, timeZone } = fetchInitialValues() // 2014-06-25T10:00:00.000Z, America/New_York
|
|
86
|
+
* const date = utcToZonedTime(isoDate, timeZone) // In June 10am UTC is 6am in New York (-04:00)
|
|
87
|
+
* renderDatePicker(date) // 2014-06-25 06:00:00 (in the system time zone)
|
|
88
|
+
* renderTimeZoneSelect(timeZone) // America/New_York
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @see https://github.com/marnusw/date-fns-tz#utctozonedtime
|
|
93
92
|
*/
|
|
94
93
|
|
|
95
94
|
|
|
96
95
|
const utcToZonedTime = (date, timeZone, options) => dateFnsUtcToZonedTime(date, toIANA(timeZone), options);
|
|
97
96
|
/**
|
|
97
|
+
* Given a date and any time zone, returns a Date with the equivalent UTC time
|
|
98
98
|
*
|
|
99
|
-
* @
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```
|
|
101
|
+
* import { zonedTimeToUtc } from 'date-fns-tz'
|
|
102
|
+
* const date = getDatePickerValue() // e.g. 2014-06-25 10:00:00 (picked in any time zone)
|
|
103
|
+
* const timeZone = getTimeZoneValue() // e.g. America/Los_Angeles
|
|
104
|
+
* const utcDate = zonedTimeToUtc(date, timeZone) // In June 10am in Los Angeles is 5pm UTC
|
|
105
|
+
* postToServer(utcDate.toISOString(), timeZone) // post 2014-06-25T17:00:00.000Z, America/Los_Angeles
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @see https://github.com/marnusw/date-fns-tz#zonedtimetoutc
|
|
103
109
|
*/
|
|
104
110
|
|
|
105
111
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douyinfe/semi-foundation",
|
|
3
|
-
"version": "2.31.3
|
|
3
|
+
"version": "2.31.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build:lib": "node ./scripts/compileLib.js",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"@douyinfe/semi-animation": "2.12.0",
|
|
11
11
|
"async-validator": "^3.5.0",
|
|
12
12
|
"classnames": "^2.2.6",
|
|
13
|
-
"date-fns": "^2.
|
|
14
|
-
"date-fns-tz": "^1.
|
|
13
|
+
"date-fns": "^2.29.3",
|
|
14
|
+
"date-fns-tz": "^1.3.8",
|
|
15
15
|
"lodash": "^4.17.21",
|
|
16
16
|
"memoize-one": "^5.2.1",
|
|
17
17
|
"scroll-into-view-if-needed": "^2.2.24"
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"*.scss",
|
|
24
24
|
"*.css"
|
|
25
25
|
],
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "6335109d0cfce3930842beeefcf11efa296da433",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/plugin-transform-runtime": "^7.15.8",
|
|
29
29
|
"@babel/preset-env": "^7.15.8",
|
package/table/utils.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/* eslint-disable no-param-reassign */
|
|
3
3
|
/* eslint-disable eqeqeq */
|
|
4
4
|
import {
|
|
5
|
+
cloneDeepWith,
|
|
5
6
|
isEqualWith,
|
|
6
7
|
get,
|
|
7
8
|
filter,
|
|
@@ -20,6 +21,17 @@ import isNullOrUndefined from '../utils/isNullOrUndefined';
|
|
|
20
21
|
import Logger from '../utils/Logger';
|
|
21
22
|
|
|
22
23
|
|
|
24
|
+
export function cloneDeep(value: any, customizer?: (v: any) => any) {
|
|
25
|
+
return cloneDeepWith(value, v => {
|
|
26
|
+
if (typeof v === 'function') {
|
|
27
|
+
return v;
|
|
28
|
+
} else if (typeof customizer === 'function') {
|
|
29
|
+
return customizer(v);
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
23
35
|
export function equalWith(value: any, other: any, customizer?: (...args: any[]) => boolean) {
|
|
24
36
|
return isEqualWith(value, other, (objVal, othVal, ...rest) => {
|
|
25
37
|
if (typeof objVal === 'function' && typeof othVal === 'function') {
|
|
@@ -49,6 +61,36 @@ export function getColumnKey(column: any, keyPropNames: any[]): any {
|
|
|
49
61
|
return key;
|
|
50
62
|
}
|
|
51
63
|
|
|
64
|
+
export function mergeColumns(oldColumns: any[] = [], newColumns: any[] = [], keyPropNames: any[] = null, deep = true) {
|
|
65
|
+
const finalColumns: any[] = [];
|
|
66
|
+
const clone = deep ? cloneDeep : lodashClone;
|
|
67
|
+
|
|
68
|
+
if (deep) {
|
|
69
|
+
const logger = new Logger('[@douyinfe/semi-ui Table]');
|
|
70
|
+
logger.warn('Should not deep merge columns from foundation since columns may have react elements. Merge columns deep from semi-ui');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
map(newColumns, newColumn => {
|
|
74
|
+
newColumn = { ...newColumn };
|
|
75
|
+
const key = getColumnKey(newColumn, keyPropNames);
|
|
76
|
+
|
|
77
|
+
const oldColumn = key != null && find(oldColumns, item => getColumnKey(item, keyPropNames) === key);
|
|
78
|
+
|
|
79
|
+
if (oldColumn) {
|
|
80
|
+
finalColumns.push(
|
|
81
|
+
clone({
|
|
82
|
+
...oldColumn,
|
|
83
|
+
...newColumn,
|
|
84
|
+
})
|
|
85
|
+
);
|
|
86
|
+
} else {
|
|
87
|
+
finalColumns.push(clone(newColumn));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return finalColumns;
|
|
92
|
+
}
|
|
93
|
+
|
|
52
94
|
/**
|
|
53
95
|
*
|
|
54
96
|
* @param {Array<number>} arr
|
|
@@ -395,7 +437,7 @@ export function mergeQueries(query: Record<string, any>, queries: Record<string,
|
|
|
395
437
|
* @param {Object[]} newColumns
|
|
396
438
|
*/
|
|
397
439
|
export function withResizeWidth(columns: Record<string, any>[], newColumns: Record<string, any>[]) {
|
|
398
|
-
const _newColumns =
|
|
440
|
+
const _newColumns = cloneDeep(newColumns);
|
|
399
441
|
for (const column of columns) {
|
|
400
442
|
if (!isNullOrUndefined(column.width)) {
|
|
401
443
|
const currentColumn = column.key;
|
package/utils/date-fns-extra.ts
CHANGED
|
@@ -100,15 +100,8 @@ const parse = (date: string | number | Date, formatToken: string, options?: any)
|
|
|
100
100
|
return toDate(date, options);
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
/**
|
|
104
|
-
*
|
|
105
|
-
* @param {string | number | Date} date
|
|
106
|
-
* @param {string} formatToken
|
|
107
|
-
* @param {object} [options]
|
|
108
|
-
* @param {string} [options.timeZone]
|
|
109
|
-
*/
|
|
110
103
|
/* istanbul ignore next */
|
|
111
|
-
const format = (date:
|
|
104
|
+
const format = (date: number | Date, formatToken: string, options?: any) => {
|
|
112
105
|
if (options && options.timeZone != null && options.timeZone !== '') {
|
|
113
106
|
const timeZone = toIANA(options.timeZone);
|
|
114
107
|
options = { ...options, timeZone };
|
|
@@ -120,22 +113,36 @@ const format = (date: string | number | Date, formatToken: string, options?: any
|
|
|
120
113
|
};
|
|
121
114
|
|
|
122
115
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* @
|
|
126
|
-
*
|
|
127
|
-
*
|
|
116
|
+
* Returns a Date which will format as the local time of any time zone from a specific UTC time
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```javascript
|
|
120
|
+
* import { utcToZonedTime } from 'date-fns-tz'
|
|
121
|
+
* const { isoDate, timeZone } = fetchInitialValues() // 2014-06-25T10:00:00.000Z, America/New_York
|
|
122
|
+
* const date = utcToZonedTime(isoDate, timeZone) // In June 10am UTC is 6am in New York (-04:00)
|
|
123
|
+
* renderDatePicker(date) // 2014-06-25 06:00:00 (in the system time zone)
|
|
124
|
+
* renderTimeZoneSelect(timeZone) // America/New_York
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @see https://github.com/marnusw/date-fns-tz#utctozonedtime
|
|
128
128
|
*/
|
|
129
|
-
const utcToZonedTime = (date: string | number | Date, timeZone: string, options?: OptionsWithTZ) => dateFnsUtcToZonedTime(date, toIANA(timeZone), options);
|
|
129
|
+
const utcToZonedTime = (date: string | number | Date, timeZone: string | number, options?: OptionsWithTZ) => dateFnsUtcToZonedTime(date, toIANA(timeZone), options);
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* @
|
|
135
|
-
*
|
|
136
|
-
*
|
|
132
|
+
* Given a date and any time zone, returns a Date with the equivalent UTC time
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```
|
|
136
|
+
* import { zonedTimeToUtc } from 'date-fns-tz'
|
|
137
|
+
* const date = getDatePickerValue() // e.g. 2014-06-25 10:00:00 (picked in any time zone)
|
|
138
|
+
* const timeZone = getTimeZoneValue() // e.g. America/Los_Angeles
|
|
139
|
+
* const utcDate = zonedTimeToUtc(date, timeZone) // In June 10am in Los Angeles is 5pm UTC
|
|
140
|
+
* postToServer(utcDate.toISOString(), timeZone) // post 2014-06-25T17:00:00.000Z, America/Los_Angeles
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @see https://github.com/marnusw/date-fns-tz#zonedtimetoutc
|
|
137
144
|
*/
|
|
138
|
-
const zonedTimeToUtc = (date: string | number | Date, timeZone: string, options?: OptionsWithTZ) => dateFnsZonedTimeToUtc(date, toIANA(timeZone), options);
|
|
145
|
+
const zonedTimeToUtc = (date: string | number | Date, timeZone: string | number, options?: OptionsWithTZ) => dateFnsZonedTimeToUtc(date, toIANA(timeZone), options);
|
|
139
146
|
|
|
140
147
|
/**
|
|
141
148
|
* return current system hour offset based on utc:
|