@sheinx/hooks 3.4.0-beta.4 → 3.4.0-beta.6
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/cjs/common/use-position-style/index.d.ts +4 -1
- package/cjs/common/use-position-style/index.d.ts.map +1 -1
- package/cjs/common/use-position-style/index.js +98 -11
- package/cjs/components/use-datepicker/use-date.d.ts +2 -2
- package/cjs/components/use-datepicker/use-date.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-date.js +2 -2
- package/cjs/components/use-datepicker/use-date.type.d.ts +1 -1
- package/cjs/components/use-datepicker/use-date.type.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-datepicker-format.d.ts +1 -1
- package/cjs/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-datepicker-format.js +4 -2
- package/cjs/components/use-datepicker/use-datepicker-format.type.d.ts +1 -0
- package/cjs/components/use-datepicker/use-datepicker-format.type.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-month.d.ts +2 -2
- package/cjs/components/use-datepicker/use-month.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-month.js +2 -2
- package/cjs/components/use-datepicker/use-month.type.d.ts +1 -1
- package/cjs/components/use-datepicker/use-month.type.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-quarter.d.ts +2 -2
- package/cjs/components/use-datepicker/use-quarter.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-quarter.js +2 -2
- package/cjs/components/use-datepicker/use-year.d.ts +2 -2
- package/cjs/components/use-datepicker/use-year.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-year.js +2 -2
- package/cjs/components/use-datepicker/use-year.type.d.ts +1 -1
- package/cjs/components/use-datepicker/use-year.type.d.ts.map +1 -1
- package/cjs/components/use-datepicker/util.d.ts +1 -1
- package/cjs/components/use-datepicker/util.d.ts.map +1 -1
- package/cjs/components/use-datepicker/util.js +2 -1
- package/cjs/components/use-form/use-form-control/use-form-control.js +2 -2
- package/cjs/components/use-form/use-form.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.js +40 -19
- package/cjs/components/use-form/use-form.type.d.ts +11 -6
- package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
- package/cjs/components/use-input/use-input-format.d.ts +1 -1
- package/cjs/components/use-input/use-input-number.d.ts +1 -1
- package/cjs/components/use-popup/use-popup.d.ts +1 -0
- package/cjs/components/use-popup/use-popup.d.ts.map +1 -1
- package/cjs/components/use-popup/use-popup.js +7 -4
- package/cjs/components/use-table/use-table-virtual.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-virtual.js +28 -3
- package/cjs/utils/position.d.ts +1 -1
- package/cjs/utils/position.d.ts.map +1 -1
- package/cjs/utils/position.js +20 -5
- package/esm/common/use-position-style/index.d.ts +4 -1
- package/esm/common/use-position-style/index.d.ts.map +1 -1
- package/esm/common/use-position-style/index.js +99 -12
- package/esm/components/use-datepicker/use-date.d.ts +2 -2
- package/esm/components/use-datepicker/use-date.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-date.js +2 -2
- package/esm/components/use-datepicker/use-date.type.d.ts +1 -1
- package/esm/components/use-datepicker/use-date.type.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-datepicker-format.d.ts +1 -1
- package/esm/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-datepicker-format.js +4 -2
- package/esm/components/use-datepicker/use-datepicker-format.type.d.ts +1 -0
- package/esm/components/use-datepicker/use-datepicker-format.type.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-month.d.ts +2 -2
- package/esm/components/use-datepicker/use-month.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-month.js +2 -2
- package/esm/components/use-datepicker/use-month.type.d.ts +1 -1
- package/esm/components/use-datepicker/use-month.type.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-quarter.d.ts +2 -2
- package/esm/components/use-datepicker/use-quarter.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-quarter.js +2 -2
- package/esm/components/use-datepicker/use-year.d.ts +2 -2
- package/esm/components/use-datepicker/use-year.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-year.js +2 -2
- package/esm/components/use-datepicker/use-year.type.d.ts +1 -1
- package/esm/components/use-datepicker/use-year.type.d.ts.map +1 -1
- package/esm/components/use-datepicker/util.d.ts +1 -1
- package/esm/components/use-datepicker/util.d.ts.map +1 -1
- package/esm/components/use-datepicker/util.js +2 -1
- package/esm/components/use-form/use-form-control/use-form-control.js +2 -2
- package/esm/components/use-form/use-form.d.ts.map +1 -1
- package/esm/components/use-form/use-form.js +40 -19
- package/esm/components/use-form/use-form.type.d.ts +11 -6
- package/esm/components/use-form/use-form.type.d.ts.map +1 -1
- package/esm/components/use-input/use-input-format.d.ts +1 -1
- package/esm/components/use-input/use-input-number.d.ts +1 -1
- package/esm/components/use-popup/use-popup.d.ts +1 -0
- package/esm/components/use-popup/use-popup.d.ts.map +1 -1
- package/esm/components/use-popup/use-popup.js +7 -4
- package/esm/components/use-table/use-table-virtual.d.ts.map +1 -1
- package/esm/components/use-table/use-table-virtual.js +28 -3
- package/esm/utils/position.d.ts +1 -1
- package/esm/utils/position.d.ts.map +1 -1
- package/esm/utils/position.js +20 -5
- package/package.json +1 -1
|
@@ -74,8 +74,10 @@ var useForm = function useForm(props) {
|
|
|
74
74
|
var _context$flowMap$glob;
|
|
75
75
|
if (!name) {
|
|
76
76
|
Object.keys(context.updateMap).forEach(function (key) {
|
|
77
|
-
var _context$updateMap$ke
|
|
78
|
-
(_context$updateMap$ke =
|
|
77
|
+
var _context$updateMap$ke;
|
|
78
|
+
(_context$updateMap$ke = context.updateMap[key]) === null || _context$updateMap$ke === void 0 || _context$updateMap$ke.forEach(function (update) {
|
|
79
|
+
update(context.value, context.errors, context.serverErrors);
|
|
80
|
+
});
|
|
79
81
|
});
|
|
80
82
|
Object.keys(context.flowMap).forEach(function (key) {
|
|
81
83
|
context.flowMap[key].forEach(function (update) {
|
|
@@ -85,8 +87,10 @@ var useForm = function useForm(props) {
|
|
|
85
87
|
} else {
|
|
86
88
|
var names = (0, _utils.isArray)(name) ? name : [name];
|
|
87
89
|
names.forEach(function (key) {
|
|
88
|
-
var _context$updateMap$ke2, _context$
|
|
89
|
-
(_context$updateMap$ke2 =
|
|
90
|
+
var _context$updateMap$ke2, _context$flowMap$key;
|
|
91
|
+
(_context$updateMap$ke2 = context.updateMap[key]) === null || _context$updateMap$ke2 === void 0 || _context$updateMap$ke2.forEach(function (update) {
|
|
92
|
+
update(context.value, context.errors, context.serverErrors);
|
|
93
|
+
});
|
|
90
94
|
(_context$flowMap$key = context.flowMap[key]) === null || _context$flowMap$key === void 0 || _context$flowMap$key.forEach(function (update) {
|
|
91
95
|
update();
|
|
92
96
|
});
|
|
@@ -142,9 +146,11 @@ var useForm = function useForm(props) {
|
|
|
142
146
|
}) : Object.keys(context.validateMap);
|
|
143
147
|
var validates = files2.map(function (key) {
|
|
144
148
|
var validateField = context.validateMap[key];
|
|
145
|
-
return validateField(
|
|
149
|
+
return Array.from(validateField).map(function (validate) {
|
|
150
|
+
return validate(key, (0, _utils.deepGet)(context.value, key), context.value, config);
|
|
151
|
+
});
|
|
146
152
|
});
|
|
147
|
-
Promise.all(validates).then(function (results) {
|
|
153
|
+
Promise.all(validates.flat()).then(function (results) {
|
|
148
154
|
var error = results.find(function (n) {
|
|
149
155
|
return n !== true;
|
|
150
156
|
});
|
|
@@ -189,8 +195,10 @@ var useForm = function useForm(props) {
|
|
|
189
195
|
Object.keys(vals).forEach(function (key) {
|
|
190
196
|
(0, _utils.deepSet)(draft, key, vals[key], deepSetOptions);
|
|
191
197
|
if (option.validate) {
|
|
192
|
-
var _context$validateMap
|
|
193
|
-
(_context$validateMap$ =
|
|
198
|
+
var _context$validateMap$;
|
|
199
|
+
(_context$validateMap$ = context.validateMap[key]) === null || _context$validateMap$ === void 0 || _context$validateMap$.forEach(function (validate) {
|
|
200
|
+
validate(key, vals[key], (0, _immer.current)(draft));
|
|
201
|
+
});
|
|
194
202
|
}
|
|
195
203
|
});
|
|
196
204
|
});
|
|
@@ -334,12 +342,17 @@ var useForm = function useForm(props) {
|
|
|
334
342
|
var controlFunc = (0, _useLatestObj.default)({
|
|
335
343
|
bind: function bind(n, df, validate, updateFn) {
|
|
336
344
|
if (context.names.has(n)) {
|
|
337
|
-
console.
|
|
338
|
-
return;
|
|
345
|
+
console.warn("name \"".concat(n, "\" already exist"));
|
|
339
346
|
}
|
|
340
347
|
context.names.add(n);
|
|
341
|
-
context.validateMap[n]
|
|
342
|
-
|
|
348
|
+
if (!context.validateMap[n]) {
|
|
349
|
+
context.validateMap[n] = new Set();
|
|
350
|
+
}
|
|
351
|
+
context.validateMap[n].add(validate);
|
|
352
|
+
if (!context.updateMap[n]) {
|
|
353
|
+
context.updateMap[n] = new Set();
|
|
354
|
+
}
|
|
355
|
+
context.updateMap[n].add(updateFn);
|
|
343
356
|
context.removeArr.delete(n);
|
|
344
357
|
if (df !== undefined && (0, _utils.deepGet)(context.value, n) === undefined) {
|
|
345
358
|
if (!context.mounted) context.defaultValues[n] = df;
|
|
@@ -349,11 +362,19 @@ var useForm = function useForm(props) {
|
|
|
349
362
|
}
|
|
350
363
|
update(n);
|
|
351
364
|
},
|
|
352
|
-
unbind: function unbind(n, reserveAble) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
365
|
+
unbind: function unbind(n, reserveAble, validateFiled, update) {
|
|
366
|
+
var validateFieldSet = context.validateMap[n];
|
|
367
|
+
if (validateFiled && validateFieldSet.has(validateFiled)) {
|
|
368
|
+
validateFieldSet.delete(validateFiled);
|
|
369
|
+
}
|
|
370
|
+
var updateFieldSet = context.updateMap[n];
|
|
371
|
+
if (update && updateFieldSet.has(update)) {
|
|
372
|
+
updateFieldSet.delete(update);
|
|
373
|
+
}
|
|
374
|
+
if (validateFieldSet.size === 0 && updateFieldSet.size === 0) {
|
|
375
|
+
context.names.delete(n);
|
|
376
|
+
delete context.defaultValues[n];
|
|
377
|
+
}
|
|
357
378
|
if (!reserveAble && !context.removeLock) {
|
|
358
379
|
addRemove(n);
|
|
359
380
|
}
|
|
@@ -428,12 +449,12 @@ var useForm = function useForm(props) {
|
|
|
428
449
|
React.useEffect(function () {
|
|
429
450
|
// 服务端错误更新
|
|
430
451
|
if (!props.error) context.serverErrors = {};else {
|
|
431
|
-
var
|
|
452
|
+
var errors = Object.keys(props.error).reduce(function (prev, cur) {
|
|
432
453
|
var item = props.error[cur];
|
|
433
454
|
var error = item instanceof Error ? item : new Error(item);
|
|
434
455
|
return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, cur, error));
|
|
435
456
|
}, {});
|
|
436
|
-
context.serverErrors =
|
|
457
|
+
context.serverErrors = errors;
|
|
437
458
|
}
|
|
438
459
|
update();
|
|
439
460
|
}, [props.error]);
|
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { AddNoProps, ObjectType } from '../../common/type';
|
|
4
4
|
import { FormItemRule } from '../../utils/rule/rule.type';
|
|
5
|
+
import { FormError } from '../../utils';
|
|
6
|
+
export type ValidateFn = (name: string, value: any, formData: ObjectType, config?: {
|
|
7
|
+
ignoreBind?: boolean;
|
|
8
|
+
}) => Promise<boolean | FormError>;
|
|
9
|
+
export type UpdateFn = (formValue: ObjectType, errors: ObjectType<Error | undefined>, serverErrors: ObjectType<Error | undefined>) => void;
|
|
5
10
|
export interface FormContextValueType {
|
|
6
11
|
func?: {
|
|
7
|
-
unbind: (n: string, reserveAble?: boolean) => void;
|
|
8
|
-
bind: (n: string, df: any, validate:
|
|
9
|
-
ignoreBind?: boolean;
|
|
10
|
-
}) => void, update: (formValue: ObjectType, errors: ObjectType<Error>, serverErrors: ObjectType<Error>) => void) => void;
|
|
12
|
+
unbind: (n: string, reserveAble?: boolean, validate?: ValidateFn, update?: UpdateFn) => void;
|
|
13
|
+
bind: (n: string, df: any, validate: ValidateFn, update: UpdateFn) => void;
|
|
11
14
|
combineRules: <ValueItem>(name: string, propRules: FormItemRule<ValueItem>) => FormItemRule<ValueItem>;
|
|
12
15
|
watch: (names: string[] | undefined, update: () => void) => void;
|
|
13
16
|
unWatch: (names: string[] | undefined, update: () => void) => void;
|
|
@@ -149,7 +152,9 @@ export interface BaseFormProps<T> extends FormCommonConfig {
|
|
|
149
152
|
export type UseFormProps<T> = BaseFormProps<T>;
|
|
150
153
|
export type FormContext = {
|
|
151
154
|
defaultValues: ObjectType;
|
|
152
|
-
validateMap: ObjectType
|
|
155
|
+
validateMap: ObjectType<Set<(name: string, v: any, formValue: ObjectType, config?: {
|
|
156
|
+
ignoreBind?: boolean;
|
|
157
|
+
}) => Promise<boolean | FormError>>>;
|
|
153
158
|
removeArr: Set<string>;
|
|
154
159
|
removeTimer?: number | NodeJS.Timeout;
|
|
155
160
|
names: Set<string>;
|
|
@@ -157,7 +162,7 @@ export type FormContext = {
|
|
|
157
162
|
lastValue: ObjectType | undefined;
|
|
158
163
|
resetTime: number;
|
|
159
164
|
mounted: boolean;
|
|
160
|
-
updateMap: ObjectType
|
|
165
|
+
updateMap: ObjectType<Set<(formValue: ObjectType, errors: ObjectType<Error | undefined>, serverErrors: ObjectType<Error | undefined>) => void>>;
|
|
161
166
|
flowMap: ObjectType<Set<() => void>>;
|
|
162
167
|
value: ObjectType;
|
|
163
168
|
errors: ObjectType<Error | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-form.type.d.ts","sourceRoot":"","sources":["use-form.type.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"use-form.type.d.ts","sourceRoot":"","sources":["use-form.type.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS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,UAAU,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;IACrC,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,UAAU,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IACtC,YAAY,EAAE,UAAU,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IAC5C,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,UAAU,CACzE,mBAAmB,EACnB,MAAM,CACP,CAAC"}
|
|
@@ -5,7 +5,7 @@ declare const useInputFormat: (props: InputFormatProps) => {
|
|
|
5
5
|
onBlur: (e: React.FocusEvent) => void;
|
|
6
6
|
onFocus: (e: React.FocusEvent) => void;
|
|
7
7
|
value: string | undefined;
|
|
8
|
-
type: "search" | "color" | "button" | "time" | "image" | "text" | "reset" | "submit" | "email" | "url" | "range" | "tel" | (string & {}) | "
|
|
8
|
+
type: "search" | "color" | "button" | "time" | "image" | "text" | "reset" | "submit" | "email" | "url" | "range" | "tel" | (string & {}) | "checkbox" | "radio" | "hidden" | "date" | "datetime-local" | "file" | "month" | "password" | "week" | undefined;
|
|
9
9
|
};
|
|
10
10
|
export default useInputFormat;
|
|
11
11
|
//# sourceMappingURL=use-input-format.d.ts.map
|
|
@@ -7,7 +7,7 @@ declare const useNumberFormat: (props: InputNumberProps) => {
|
|
|
7
7
|
onBlur: (e: React.FocusEvent<Element, Element>) => void;
|
|
8
8
|
onFocus: (e: React.FocusEvent<Element, Element>) => void;
|
|
9
9
|
value: string | undefined;
|
|
10
|
-
type: "search" | "color" | "button" | "time" | "image" | "text" | "reset" | "submit" | "email" | "url" | "range" | "tel" | (string & {}) | "
|
|
10
|
+
type: "search" | "color" | "button" | "time" | "image" | "text" | "reset" | "submit" | "email" | "url" | "range" | "tel" | (string & {}) | "checkbox" | "radio" | "hidden" | "date" | "datetime-local" | "file" | "month" | "password" | "week" | undefined;
|
|
11
11
|
};
|
|
12
12
|
export default useNumberFormat;
|
|
13
13
|
//# sourceMappingURL=use-input-number.d.ts.map
|
|
@@ -5,6 +5,7 @@ declare const usePopup: (props: BasePopupProps) => {
|
|
|
5
5
|
position: PositionType;
|
|
6
6
|
targetRef: React.MutableRefObject<HTMLDivElement | null>;
|
|
7
7
|
popupRef: React.MutableRefObject<HTMLDivElement | null>;
|
|
8
|
+
arrowRef: React.MutableRefObject<HTMLSpanElement | null>;
|
|
8
9
|
getTargetProps: () => {
|
|
9
10
|
onMouseEnter: (e: {
|
|
10
11
|
target: EventTarget | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-popup.d.ts","sourceRoot":"","sources":["use-popup.ts"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAMhE,QAAA,MAAM,QAAQ,UAAW,cAAc
|
|
1
|
+
{"version":3,"file":"use-popup.d.ts","sourceRoot":"","sources":["use-popup.ts"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAMhE,QAAA,MAAM,QAAQ,UAAW,cAAc;;;;;;;0BA2HK;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;0BAM9B;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;;;;;qBA5B7B;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;;;;;;;;;;;;;;;;;;;;;;;;;2BA6ElD,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;6BAGxC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;;CAsBpE,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -37,6 +37,7 @@ var usePopup = function usePopup(props) {
|
|
|
37
37
|
removeChild = _useContext.removeChild;
|
|
38
38
|
var targetRef = (0, _react.useRef)(null);
|
|
39
39
|
var popupRef = (0, _react.useRef)(null);
|
|
40
|
+
var arrowRef = (0, _react.useRef)(null);
|
|
40
41
|
(0, _react.useEffect)(function () {
|
|
41
42
|
bindChild(popupRef);
|
|
42
43
|
return function () {
|
|
@@ -68,11 +69,12 @@ var usePopup = function usePopup(props) {
|
|
|
68
69
|
setPositionState = _useState4[1];
|
|
69
70
|
var position = isPositionControl ? props.position : positionState;
|
|
70
71
|
var updatePosition = (0, _usePersistFn.default)(function () {
|
|
71
|
-
if (isPositionControl) return;
|
|
72
|
-
if (props.position === 'auto' || !props.position) {
|
|
73
|
-
|
|
72
|
+
// if (isPositionControl) return;
|
|
73
|
+
// if (props.position === 'auto' || !props.position) {
|
|
74
|
+
setTimeout(function () {
|
|
75
|
+
var newPosition = (0, _position.getPosition)(targetRef.current, props.priorityDirection, autoMode, popupRef.current || undefined);
|
|
74
76
|
if (newPosition !== position) setPositionState(newPosition);
|
|
75
|
-
}
|
|
77
|
+
}, 10);
|
|
76
78
|
});
|
|
77
79
|
(0, _react.useEffect)(function () {
|
|
78
80
|
if (props.open) {
|
|
@@ -201,6 +203,7 @@ var usePopup = function usePopup(props) {
|
|
|
201
203
|
position: position,
|
|
202
204
|
targetRef: targetRef,
|
|
203
205
|
popupRef: popupRef,
|
|
206
|
+
arrowRef: arrowRef,
|
|
204
207
|
getTargetProps: getTargetProps,
|
|
205
208
|
openPop: openPop,
|
|
206
209
|
closePop: closePop,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,UAAU,oBAAoB;IAC5B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC3C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;CACnC;AACD,QAAA,MAAM,eAAe,UAAW,oBAAoB;;;;;;;oBAsLpC,MAAM;mBACP,MAAM;WACd,MAAM;gBACD,MAAM;kBACJ,OAAO;;0BAtFuB,MAAM,UAAU,MAAM;0BAxBtB,MAAM,QAAQ,MAAM;2BAkJnB,MAAM;CAwFlD,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -16,6 +16,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
16
16
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
17
17
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
18
18
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
19
|
+
var MAX_ROW_SPAN = 200;
|
|
19
20
|
var useTableVirtual = function useTableVirtual(props) {
|
|
20
21
|
var _useState = (0, _react.useState)(0),
|
|
21
22
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -98,7 +99,9 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
|
98
99
|
topTimer: null,
|
|
99
100
|
controlScrollRate: null,
|
|
100
101
|
heightCallback: null,
|
|
101
|
-
preIndex: null
|
|
102
|
+
preIndex: null,
|
|
103
|
+
rowSpanRows: 0,
|
|
104
|
+
autoAddRows: 0
|
|
102
105
|
}),
|
|
103
106
|
context = _useRef.current;
|
|
104
107
|
var getTranslate = (0, _usePersistFn.usePersistFn)(function (left, top) {
|
|
@@ -149,17 +152,20 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
|
149
152
|
var top = 0;
|
|
150
153
|
var maxIndex = Math.max(props.data.length - rowsInView, 0);
|
|
151
154
|
for (var i = 0; i <= maxIndex; i++) {
|
|
155
|
+
context.rowSpanRows = 0;
|
|
152
156
|
sum += context.cachedHeight[i] || props.rowHeight;
|
|
153
157
|
var rowSpanHeight = 0;
|
|
154
158
|
if (rowSpanInfos) {
|
|
159
|
+
var maxRowSpanLenth = Math.min(rowSpanInfos.length, props.rowsInView > MAX_ROW_SPAN ? props.rowsInView : props.rowsInView || MAX_ROW_SPAN);
|
|
155
160
|
var siblingsIndexs = [];
|
|
156
|
-
for (var k = 0; k <
|
|
161
|
+
for (var k = 0; k < maxRowSpanLenth; k++) {
|
|
157
162
|
if (rowSpanInfos[k] <= i && k > i) {
|
|
158
163
|
siblingsIndexs.push(k);
|
|
159
164
|
}
|
|
160
165
|
}
|
|
161
166
|
for (var j = 0; j < siblingsIndexs.length; j++) {
|
|
162
167
|
var index = siblingsIndexs[j];
|
|
168
|
+
context.rowSpanRows += 1;
|
|
163
169
|
rowSpanHeight += context.cachedHeight[index] || props.rowHeight;
|
|
164
170
|
}
|
|
165
171
|
}
|
|
@@ -250,6 +256,24 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
|
250
256
|
props.scrollRef.current.scrollTop = beforeHeight;
|
|
251
257
|
}
|
|
252
258
|
});
|
|
259
|
+
(0, _react.useEffect)(function () {
|
|
260
|
+
var scrollRefHeight = props.scrollRef.current ? props.scrollRef.current.clientHeight : 0;
|
|
261
|
+
var tableRefHeight = props.innerRef.current ? props.innerRef.current.clientHeight : 0;
|
|
262
|
+
var remainHeight = scrollRefHeight - tableRefHeight;
|
|
263
|
+
if (remainHeight > 0) {
|
|
264
|
+
var addonHeight = 0;
|
|
265
|
+
var addonCount = 0;
|
|
266
|
+
for (var i = startIndex + rowsInView; i < props.data.length; i++) {
|
|
267
|
+
var height = context.cachedHeight[i] || props.rowHeight;
|
|
268
|
+
addonHeight += height;
|
|
269
|
+
addonCount += 1;
|
|
270
|
+
if (addonHeight >= remainHeight + context.cachedHeight[0]) break;
|
|
271
|
+
}
|
|
272
|
+
if (addonCount > 0) {
|
|
273
|
+
context.autoAddRows = addonCount;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}, []);
|
|
253
277
|
(0, _react.useEffect)(function () {
|
|
254
278
|
// 记录preIndex
|
|
255
279
|
context.preIndex = startIndex;
|
|
@@ -284,7 +308,8 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
|
284
308
|
cb();
|
|
285
309
|
}
|
|
286
310
|
}, [scrollHeight]);
|
|
287
|
-
var
|
|
311
|
+
var finalRowsInView = rowsInView + context.rowSpanRows + context.autoAddRows;
|
|
312
|
+
var renderData = props.disabled ? props.data : _toConsumableArray(props.data).slice(startIndex, startIndex + finalRowsInView);
|
|
288
313
|
return {
|
|
289
314
|
scrollHeight: scrollHeight,
|
|
290
315
|
startIndex: startIndex,
|
package/cjs/utils/position.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const getPosition: (target: HTMLElement | null, priorityDirection: "vertical" | "horizontal" | "auto" | undefined, mode: 'popover' | 'menu' | 'list') => "bottom" | "left" | "right" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "left-top" | "left-bottom" | "right-top" | "right-bottom";
|
|
1
|
+
export declare const getPosition: (target: HTMLElement | null, priorityDirection: "vertical" | "horizontal" | "auto" | undefined, mode: 'popover' | 'menu' | 'list', popup?: HTMLElement) => "bottom" | "left" | "right" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "left-top" | "left-bottom" | "right-top" | "right-bottom";
|
|
2
2
|
//# sourceMappingURL=position.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["position.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["position.ts"],"names":[],"mappings":"AAiGA,eAAO,MAAM,WAAW,WACd,WAAW,GAAG,IAAI,2EAEpB,SAAS,GAAG,MAAM,GAAG,MAAM,UACzB,WAAW,gKAKpB,CAAC"}
|
package/cjs/utils/position.js
CHANGED
|
@@ -41,6 +41,7 @@ var getMenuPosition = function getMenuPosition(target) {
|
|
|
41
41
|
};
|
|
42
42
|
var getPopoverPosition = function getPopoverPosition(target) {
|
|
43
43
|
var priorityDirection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'vertical';
|
|
44
|
+
var popup = arguments.length > 2 ? arguments[2] : undefined;
|
|
44
45
|
var position = 'bottom-left';
|
|
45
46
|
if (!target) return position;
|
|
46
47
|
var rect = target.getBoundingClientRect();
|
|
@@ -62,11 +63,24 @@ var getPopoverPosition = function getPopoverPosition(target) {
|
|
|
62
63
|
position += '-top';
|
|
63
64
|
}
|
|
64
65
|
} else {
|
|
66
|
+
var popupRect = popup === null || popup === void 0 ? void 0 : popup.getBoundingClientRect();
|
|
65
67
|
if (verticalPoint > windowHeight / 2) position = 'top';else position = 'bottom';
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
|
|
69
|
+
// 如果渲染了弹出内容,则根据弹出内容宽度计算是否自动调整位置
|
|
70
|
+
if (popupRect) {
|
|
71
|
+
if ((popupRect === null || popupRect === void 0 ? void 0 : popupRect.width) / 2 > rect.left) {
|
|
72
|
+
position += '-left';
|
|
73
|
+
}
|
|
74
|
+
if ((popupRect === null || popupRect === void 0 ? void 0 : popupRect.width) / 2 > windowWidth - rect.right) {
|
|
75
|
+
position += '-right';
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
// 兜底计算
|
|
79
|
+
if (horizontalPoint > windowWidth * 0.6) {
|
|
80
|
+
position += '-right';
|
|
81
|
+
} else if (horizontalPoint < windowWidth * 0.4) {
|
|
82
|
+
position += '-left';
|
|
83
|
+
}
|
|
70
84
|
}
|
|
71
85
|
}
|
|
72
86
|
return position;
|
|
@@ -74,7 +88,8 @@ var getPopoverPosition = function getPopoverPosition(target) {
|
|
|
74
88
|
var getPosition = exports.getPosition = function getPosition(target) {
|
|
75
89
|
var priorityDirection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'vertical';
|
|
76
90
|
var mode = arguments.length > 2 ? arguments[2] : undefined;
|
|
77
|
-
|
|
91
|
+
var popup = arguments.length > 3 ? arguments[3] : undefined;
|
|
92
|
+
if (mode === 'popover') return getPopoverPosition(target, priorityDirection, popup);
|
|
78
93
|
if (mode === 'menu') return getMenuPosition(target, priorityDirection);
|
|
79
94
|
return 'bottom-left';
|
|
80
95
|
};
|
|
@@ -16,6 +16,9 @@ export interface PositionStyleConfig {
|
|
|
16
16
|
updateKey?: number | string;
|
|
17
17
|
adjust?: boolean;
|
|
18
18
|
}
|
|
19
|
-
export declare const usePositionStyle: (config: PositionStyleConfig) =>
|
|
19
|
+
export declare const usePositionStyle: (config: PositionStyleConfig) => {
|
|
20
|
+
style: React.CSSProperties;
|
|
21
|
+
arrayStyle: React.CSSProperties;
|
|
22
|
+
};
|
|
20
23
|
export default usePositionStyle;
|
|
21
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAMnD,MAAM,MAAM,kBAAkB,GAC1B,aAAa,GACb,UAAU,GACV,cAAc,GACd,WAAW,GACX,MAAM,GACN,OAAO,CAAC;AACZ,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,cAAc,GACd,UAAU,GACV,WAAW,GACX,KAAK,GACL,QAAQ,CAAC;AAYb,KAAK,YAAY,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,OAAO,CAAC;AACpE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IAEd,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAEzC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAQD,eAAO,MAAM,gBAAgB,WAAY,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAMnD,MAAM,MAAM,kBAAkB,GAC1B,aAAa,GACb,UAAU,GACV,cAAc,GACd,WAAW,GACX,MAAM,GACN,OAAO,CAAC;AACZ,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,cAAc,GACd,UAAU,GACV,WAAW,GACX,KAAK,GACL,QAAQ,CAAC;AAYb,KAAK,YAAY,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,OAAO,CAAC;AACpE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IAEd,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAEzC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAQD,eAAO,MAAM,gBAAgB,WAAY,mBAAmB;;;CAmS3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -9,7 +9,7 @@ import React, { useEffect, useState } from 'react';
|
|
|
9
9
|
import { getPositionStyle } from "./get-position-style";
|
|
10
10
|
import shallowEqual from "../../utils/shallow-equal";
|
|
11
11
|
import usePersistFn from "../use-persist-fn";
|
|
12
|
-
import { docSize } from "../../utils";
|
|
12
|
+
import { docSize, isChromeLowerThan } from "../../utils";
|
|
13
13
|
var horizontalPosition = ['left-bottom', 'left-top', 'right-bottom', 'right-top', 'left', 'right'];
|
|
14
14
|
var verticalPosition = ['bottom-left', 'bottom-right', 'top-left', 'top-right', 'bottom', 'top'];
|
|
15
15
|
var hideStyle = {
|
|
@@ -39,6 +39,10 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
|
39
39
|
_useState2 = _slicedToArray(_useState, 2),
|
|
40
40
|
style = _useState2[0],
|
|
41
41
|
setStyle = _useState2[1];
|
|
42
|
+
var _useState3 = useState({}),
|
|
43
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
44
|
+
arrayStyle = _useState4[0],
|
|
45
|
+
setArrayStyle = _useState4[1];
|
|
42
46
|
var _React$useRef = React.useRef({
|
|
43
47
|
element: null,
|
|
44
48
|
containerRect: {
|
|
@@ -112,10 +116,12 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
|
112
116
|
};
|
|
113
117
|
};
|
|
114
118
|
var getAbsolutePositionStyle = function getAbsolutePositionStyle(rect, position) {
|
|
119
|
+
var _popupElRef$current;
|
|
115
120
|
var style = {
|
|
116
121
|
position: 'absolute',
|
|
117
122
|
zIndex: zIndex
|
|
118
123
|
};
|
|
124
|
+
var arrayStyle = {};
|
|
119
125
|
if (fixedWidth) {
|
|
120
126
|
var widthKey = fixedWidth === 'min' ? 'minWidth' : 'width';
|
|
121
127
|
style[widthKey] = rect.width;
|
|
@@ -125,6 +131,7 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
|
125
131
|
var containerRect = rootContainer.getBoundingClientRect();
|
|
126
132
|
var bodyRect = (document.documentElement || document.body).getBoundingClientRect();
|
|
127
133
|
var containerScrollBarWidth = rootContainer.offsetWidth - rootContainer.clientWidth;
|
|
134
|
+
var targetRect = (_popupElRef$current = popupElRef.current) === null || _popupElRef$current === void 0 ? void 0 : _popupElRef$current.getBoundingClientRect();
|
|
128
135
|
var containerScroll = {
|
|
129
136
|
left: rootContainer.scrollLeft,
|
|
130
137
|
top: rootContainer.scrollTop
|
|
@@ -141,14 +148,25 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
|
141
148
|
if (h === 'left') {
|
|
142
149
|
style.left = rect.left - containerRect.left + containerScroll.left;
|
|
143
150
|
style.transform = '';
|
|
151
|
+
arrayStyle.left = "8px";
|
|
144
152
|
if (adjust) {
|
|
145
153
|
overRight = rect.left + context.popUpWidth - bodyRect.right + containerScrollBarWidth;
|
|
154
|
+
if (style.left < 0 && targetRect) {
|
|
155
|
+
style.left = 'auto';
|
|
156
|
+
}
|
|
146
157
|
}
|
|
147
158
|
} else if (h === 'right') {
|
|
148
159
|
style.right = containerRect.right - rect.right + containerScrollBarWidth - containerScroll.left;
|
|
149
160
|
style.left = 'auto';
|
|
150
161
|
style.transform = '';
|
|
151
|
-
|
|
162
|
+
arrayStyle.right = "8px";
|
|
163
|
+
if (adjust) {
|
|
164
|
+
overLeft = bodyRect.left - (rect.right - context.popUpWidth);
|
|
165
|
+
if (style.right < 0 && targetRect) {
|
|
166
|
+
style.left = bodyRect.width - targetRect.width;
|
|
167
|
+
style.right = 'auto';
|
|
168
|
+
}
|
|
169
|
+
}
|
|
152
170
|
} else {
|
|
153
171
|
// 居中对齐
|
|
154
172
|
style.left = rect.left + rect.width / 2 - containerRect.left + containerScroll.left;
|
|
@@ -157,6 +175,9 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
|
157
175
|
overRight = rect.left + rect.width / 2 + context.popUpWidth / 2 - bodyRect.width + containerScrollBarWidth;
|
|
158
176
|
overLeft = bodyRect.left - (rect.left + rect.width / 2 - context.popUpWidth / 2);
|
|
159
177
|
}
|
|
178
|
+
if (targetRect) {
|
|
179
|
+
arrayStyle.left = "".concat(targetRect.width / 2 - 5.9, "px");
|
|
180
|
+
}
|
|
160
181
|
}
|
|
161
182
|
if (adjust) {
|
|
162
183
|
// 调节左右溢出
|
|
@@ -165,16 +186,26 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
|
165
186
|
style.left -= overRight;
|
|
166
187
|
// 扣除触发器距离页面右侧的距离,以保证从右侧弹出的窗口最右边对齐触发器最右边
|
|
167
188
|
style.left -= toRightDistance;
|
|
189
|
+
if (targetRect) {
|
|
190
|
+
arrayStyle.left = "".concat((targetRect === null || targetRect === void 0 ? void 0 : targetRect.width) - context.parentRect.width / 2 - 5.9, "px");
|
|
191
|
+
}
|
|
168
192
|
}
|
|
169
193
|
if (overLeft > 0) {
|
|
170
194
|
style.left += overLeft;
|
|
195
|
+
arrayStyle.left = "".concat(rect.width / 2 - 5.9, "px");
|
|
171
196
|
}
|
|
172
197
|
}
|
|
173
198
|
if (v === 'bottom') {
|
|
174
199
|
style.top = rect.bottom - containerRect.top + containerScroll.top + popupGap;
|
|
200
|
+
if (targetRect) {
|
|
201
|
+
arrayStyle.top = "".concat(0, "px");
|
|
202
|
+
}
|
|
175
203
|
} else {
|
|
176
204
|
style.top = rect.top - containerRect.top + containerScroll.top - popupGap;
|
|
177
205
|
style.transform += 'translateY(-100%)';
|
|
206
|
+
if (targetRect) {
|
|
207
|
+
arrayStyle.top = "".concat(targetRect.height - 5.9 - 4, "px");
|
|
208
|
+
}
|
|
178
209
|
}
|
|
179
210
|
} else if (horizontalPosition.includes(targetPosition)) {
|
|
180
211
|
var _targetPosition$split3 = targetPosition.split('-'),
|
|
@@ -184,45 +215,88 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
|
184
215
|
if (_v === 'top') {
|
|
185
216
|
style.top = rect.top - containerRect.top + containerScroll.top;
|
|
186
217
|
style.transform = '';
|
|
218
|
+
arrayStyle.top = "8px";
|
|
187
219
|
} else if (_v === 'bottom') {
|
|
188
220
|
style.top = rect.bottom - containerRect.top + containerScroll.top;
|
|
221
|
+
arrayStyle.bottom = "8px";
|
|
189
222
|
style.transform = 'translateY(-100%)';
|
|
190
223
|
} else {
|
|
191
224
|
// 居中对齐
|
|
192
225
|
style.top = rect.top - containerRect.top + containerScroll.top + rect.height / 2;
|
|
226
|
+
if (targetRect) {
|
|
227
|
+
arrayStyle.top = "".concat(targetRect.height / 2 - 5.9 / 2, "px");
|
|
228
|
+
}
|
|
193
229
|
style.transform = 'translateY(-50%)';
|
|
194
230
|
}
|
|
195
231
|
if (_h === 'right') {
|
|
196
232
|
style.left = rect.right - containerRect.left + containerScroll.left + popupGap;
|
|
197
233
|
} else {
|
|
198
234
|
style.left = rect.left - containerRect.left + containerScroll.left - popupGap;
|
|
235
|
+
arrayStyle.right = "0px";
|
|
199
236
|
style.transform += ' translateX(-100%)';
|
|
200
237
|
}
|
|
201
238
|
} else if (position === 'cover') {
|
|
202
239
|
style.top = rect.top - containerRect.top + containerScroll.top;
|
|
203
240
|
style.left = rect.left - containerRect.left + containerScroll.left;
|
|
204
241
|
}
|
|
205
|
-
return
|
|
242
|
+
return {
|
|
243
|
+
style: style,
|
|
244
|
+
arrayStyle: arrayStyle
|
|
245
|
+
};
|
|
206
246
|
};
|
|
207
247
|
var getAbsoluteStyle = function getAbsoluteStyle(position) {
|
|
208
|
-
if (!parentElRef.current) return
|
|
248
|
+
if (!parentElRef.current) return {
|
|
249
|
+
style: hideStyle
|
|
250
|
+
};
|
|
209
251
|
var rect = context.parentRect;
|
|
210
252
|
if (scrollElRef !== null && scrollElRef !== void 0 && scrollElRef.current) {
|
|
211
253
|
var _scrollElRef$current;
|
|
212
254
|
var visibleRect = ((_scrollElRef$current = scrollElRef.current) === null || _scrollElRef$current === void 0 ? void 0 : _scrollElRef$current.getBoundingClientRect()) || {};
|
|
213
255
|
if (rect.bottom < visibleRect.top || rect.top > visibleRect.bottom || rect.right < visibleRect.left || rect.left > visibleRect.right) {
|
|
214
|
-
return
|
|
256
|
+
return {
|
|
257
|
+
style: hideStyle
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
var _getAbsolutePositionS = getAbsolutePositionStyle(rect, position),
|
|
262
|
+
style = _getAbsolutePositionS.style,
|
|
263
|
+
arrayStyle = _getAbsolutePositionS.arrayStyle;
|
|
264
|
+
|
|
265
|
+
// TODO: 如果是版本大于chrome128,需要根据currentCSSZoom处理chrome的bug
|
|
266
|
+
if (!isChromeLowerThan(128)) {
|
|
267
|
+
// @ts-ignore currentCSSZoom
|
|
268
|
+
var currentCSSZoom = document.body.currentCSSZoom;
|
|
269
|
+
if (currentCSSZoom === 1 || !currentCSSZoom) return {
|
|
270
|
+
style: style,
|
|
271
|
+
arrayStyle: arrayStyle
|
|
272
|
+
};
|
|
273
|
+
if (style.left && typeof style.left === 'number') {
|
|
274
|
+
style.left = style.left * (1 / currentCSSZoom);
|
|
275
|
+
}
|
|
276
|
+
if (style.top && typeof style.top === 'number') {
|
|
277
|
+
style.top = style.top * (1 / currentCSSZoom);
|
|
278
|
+
}
|
|
279
|
+
if (style.right && typeof style.right === 'number') {
|
|
280
|
+
style.right = style.right * (1 / currentCSSZoom);
|
|
281
|
+
}
|
|
282
|
+
if (style.bottom && typeof style.bottom === 'number') {
|
|
283
|
+
style.bottom = style.bottom * (1 / currentCSSZoom);
|
|
215
284
|
}
|
|
216
285
|
}
|
|
217
|
-
|
|
218
|
-
|
|
286
|
+
return {
|
|
287
|
+
style: style,
|
|
288
|
+
arrayStyle: arrayStyle
|
|
289
|
+
};
|
|
219
290
|
};
|
|
220
291
|
var getStyle = function getStyle() {
|
|
221
292
|
var newStyle = {};
|
|
293
|
+
var newArrayStyle = {};
|
|
222
294
|
var _ref2 = config || {},
|
|
223
295
|
position = _ref2.position,
|
|
224
296
|
absolute = _ref2.absolute;
|
|
225
|
-
if (!position || !show || !parentElRef.current) return
|
|
297
|
+
if (!position || !show || !parentElRef.current) return {
|
|
298
|
+
newStyle: style
|
|
299
|
+
};
|
|
226
300
|
context.parentRect = parentElRef.current.getBoundingClientRect();
|
|
227
301
|
if (adjust) {
|
|
228
302
|
var popupInfo = getPopUpInfo(context.parentRect);
|
|
@@ -237,21 +311,34 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
|
237
311
|
fixedWidth: fixedWidth
|
|
238
312
|
});
|
|
239
313
|
} else {
|
|
240
|
-
|
|
314
|
+
var _ref3 = getAbsoluteStyle(realPosition),
|
|
315
|
+
nextStyle = _ref3.style,
|
|
316
|
+
nextArrayStyle = _ref3.arrayStyle;
|
|
317
|
+
newStyle = nextStyle;
|
|
318
|
+
newArrayStyle = nextArrayStyle;
|
|
241
319
|
}
|
|
242
320
|
// for animation
|
|
243
321
|
if (realPosition.indexOf('top') === 0) {
|
|
244
322
|
newStyle.transformOrigin = 'center bottom';
|
|
245
323
|
}
|
|
246
|
-
return
|
|
324
|
+
return {
|
|
325
|
+
newStyle: newStyle,
|
|
326
|
+
newArrayStyle: newArrayStyle
|
|
327
|
+
};
|
|
247
328
|
};
|
|
248
329
|
var updateStyle = usePersistFn(function () {
|
|
249
|
-
var
|
|
330
|
+
var _getStyle = getStyle(),
|
|
331
|
+
newStyle = _getStyle.newStyle,
|
|
332
|
+
newArrayStyle = _getStyle.newArrayStyle;
|
|
250
333
|
if (newStyle && !shallowEqual(style, newStyle)) {
|
|
251
334
|
setStyle(newStyle);
|
|
335
|
+
setArrayStyle(newArrayStyle || {});
|
|
252
336
|
}
|
|
253
337
|
});
|
|
254
338
|
useEffect(updateStyle, [show, position, absolute, updateKey, fixedWidth]);
|
|
255
|
-
return
|
|
339
|
+
return {
|
|
340
|
+
style: style,
|
|
341
|
+
arrayStyle: arrayStyle
|
|
342
|
+
};
|
|
256
343
|
};
|
|
257
344
|
export default usePositionStyle;
|