@sheinx/hooks 3.3.6-beta.1 → 3.3.6-beta.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. package/cjs/common/use-position-style/index.d.ts +4 -1
  2. package/cjs/common/use-position-style/index.d.ts.map +1 -1
  3. package/cjs/common/use-position-style/index.js +98 -11
  4. package/cjs/components/use-datepicker/use-date.d.ts +1 -1
  5. package/cjs/components/use-datepicker/use-month.d.ts +1 -1
  6. package/cjs/components/use-datepicker/use-quarter.d.ts +1 -1
  7. package/cjs/components/use-datepicker/use-year.d.ts +1 -1
  8. package/cjs/components/use-input/use-input-format.d.ts +1 -1
  9. package/cjs/components/use-input/use-input-number.d.ts +1 -1
  10. package/cjs/components/use-popup/use-popup.d.ts +1 -0
  11. package/cjs/components/use-popup/use-popup.d.ts.map +1 -1
  12. package/cjs/components/use-popup/use-popup.js +7 -4
  13. package/cjs/utils/position.d.ts +1 -1
  14. package/cjs/utils/position.d.ts.map +1 -1
  15. package/cjs/utils/position.js +20 -5
  16. package/esm/common/use-position-style/index.d.ts +4 -1
  17. package/esm/common/use-position-style/index.d.ts.map +1 -1
  18. package/esm/common/use-position-style/index.js +99 -12
  19. package/esm/components/use-datepicker/use-date.d.ts +1 -1
  20. package/esm/components/use-datepicker/use-month.d.ts +1 -1
  21. package/esm/components/use-datepicker/use-quarter.d.ts +1 -1
  22. package/esm/components/use-datepicker/use-year.d.ts +1 -1
  23. package/esm/components/use-input/use-input-format.d.ts +1 -1
  24. package/esm/components/use-input/use-input-number.d.ts +1 -1
  25. package/esm/components/use-popup/use-popup.d.ts +1 -0
  26. package/esm/components/use-popup/use-popup.d.ts.map +1 -1
  27. package/esm/components/use-popup/use-popup.js +7 -4
  28. package/esm/utils/position.d.ts +1 -1
  29. package/esm/utils/position.d.ts.map +1 -1
  30. package/esm/utils/position.js +20 -5
  31. package/package.json +1 -1
@@ -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) => React.CSSProperties;
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,wBAsO3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
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"}
@@ -49,6 +49,10 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
49
49
  _useState2 = _slicedToArray(_useState, 2),
50
50
  style = _useState2[0],
51
51
  setStyle = _useState2[1];
52
+ var _useState3 = (0, _react.useState)({}),
53
+ _useState4 = _slicedToArray(_useState3, 2),
54
+ arrayStyle = _useState4[0],
55
+ setArrayStyle = _useState4[1];
52
56
  var _React$useRef = _react.default.useRef({
53
57
  element: null,
54
58
  containerRect: {
@@ -122,10 +126,12 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
122
126
  };
123
127
  };
124
128
  var getAbsolutePositionStyle = function getAbsolutePositionStyle(rect, position) {
129
+ var _popupElRef$current;
125
130
  var style = {
126
131
  position: 'absolute',
127
132
  zIndex: zIndex
128
133
  };
134
+ var arrayStyle = {};
129
135
  if (fixedWidth) {
130
136
  var widthKey = fixedWidth === 'min' ? 'minWidth' : 'width';
131
137
  style[widthKey] = rect.width;
@@ -135,6 +141,7 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
135
141
  var containerRect = rootContainer.getBoundingClientRect();
136
142
  var bodyRect = (document.documentElement || document.body).getBoundingClientRect();
137
143
  var containerScrollBarWidth = rootContainer.offsetWidth - rootContainer.clientWidth;
144
+ var targetRect = (_popupElRef$current = popupElRef.current) === null || _popupElRef$current === void 0 ? void 0 : _popupElRef$current.getBoundingClientRect();
138
145
  var containerScroll = {
139
146
  left: rootContainer.scrollLeft,
140
147
  top: rootContainer.scrollTop
@@ -151,14 +158,25 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
151
158
  if (h === 'left') {
152
159
  style.left = rect.left - containerRect.left + containerScroll.left;
153
160
  style.transform = '';
161
+ arrayStyle.left = "8px";
154
162
  if (adjust) {
155
163
  overRight = rect.left + context.popUpWidth - bodyRect.right + containerScrollBarWidth;
164
+ if (style.left < 0 && targetRect) {
165
+ style.left = 'auto';
166
+ }
156
167
  }
157
168
  } else if (h === 'right') {
158
169
  style.right = containerRect.right - rect.right + containerScrollBarWidth - containerScroll.left;
159
170
  style.left = 'auto';
160
171
  style.transform = '';
161
- if (adjust) overLeft = bodyRect.left - (rect.right - context.popUpWidth);
172
+ arrayStyle.right = "8px";
173
+ if (adjust) {
174
+ overLeft = bodyRect.left - (rect.right - context.popUpWidth);
175
+ if (style.right < 0 && targetRect) {
176
+ style.left = bodyRect.width - targetRect.width;
177
+ style.right = 'auto';
178
+ }
179
+ }
162
180
  } else {
163
181
  // 居中对齐
164
182
  style.left = rect.left + rect.width / 2 - containerRect.left + containerScroll.left;
@@ -167,6 +185,9 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
167
185
  overRight = rect.left + rect.width / 2 + context.popUpWidth / 2 - bodyRect.width + containerScrollBarWidth;
168
186
  overLeft = bodyRect.left - (rect.left + rect.width / 2 - context.popUpWidth / 2);
169
187
  }
188
+ if (targetRect) {
189
+ arrayStyle.left = "".concat(targetRect.width / 2 - 5.9, "px");
190
+ }
170
191
  }
171
192
  if (adjust) {
172
193
  // 调节左右溢出
@@ -175,16 +196,26 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
175
196
  style.left -= overRight;
176
197
  // 扣除触发器距离页面右侧的距离,以保证从右侧弹出的窗口最右边对齐触发器最右边
177
198
  style.left -= toRightDistance;
199
+ if (targetRect) {
200
+ arrayStyle.left = "".concat((targetRect === null || targetRect === void 0 ? void 0 : targetRect.width) - context.parentRect.width / 2 - 5.9, "px");
201
+ }
178
202
  }
179
203
  if (overLeft > 0) {
180
204
  style.left += overLeft;
205
+ arrayStyle.left = "".concat(rect.width / 2 - 5.9, "px");
181
206
  }
182
207
  }
183
208
  if (v === 'bottom') {
184
209
  style.top = rect.bottom - containerRect.top + containerScroll.top + popupGap;
210
+ if (targetRect) {
211
+ arrayStyle.top = "".concat(0, "px");
212
+ }
185
213
  } else {
186
214
  style.top = rect.top - containerRect.top + containerScroll.top - popupGap;
187
215
  style.transform += 'translateY(-100%)';
216
+ if (targetRect) {
217
+ arrayStyle.top = "".concat(targetRect.height - 5.9 - 4, "px");
218
+ }
188
219
  }
189
220
  } else if (horizontalPosition.includes(targetPosition)) {
190
221
  var _targetPosition$split3 = targetPosition.split('-'),
@@ -194,45 +225,88 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
194
225
  if (_v === 'top') {
195
226
  style.top = rect.top - containerRect.top + containerScroll.top;
196
227
  style.transform = '';
228
+ arrayStyle.top = "8px";
197
229
  } else if (_v === 'bottom') {
198
230
  style.top = rect.bottom - containerRect.top + containerScroll.top;
231
+ arrayStyle.bottom = "8px";
199
232
  style.transform = 'translateY(-100%)';
200
233
  } else {
201
234
  // 居中对齐
202
235
  style.top = rect.top - containerRect.top + containerScroll.top + rect.height / 2;
236
+ if (targetRect) {
237
+ arrayStyle.top = "".concat(targetRect.height / 2 - 5.9 / 2, "px");
238
+ }
203
239
  style.transform = 'translateY(-50%)';
204
240
  }
205
241
  if (_h === 'right') {
206
242
  style.left = rect.right - containerRect.left + containerScroll.left + popupGap;
207
243
  } else {
208
244
  style.left = rect.left - containerRect.left + containerScroll.left - popupGap;
245
+ arrayStyle.right = "0px";
209
246
  style.transform += ' translateX(-100%)';
210
247
  }
211
248
  } else if (position === 'cover') {
212
249
  style.top = rect.top - containerRect.top + containerScroll.top;
213
250
  style.left = rect.left - containerRect.left + containerScroll.left;
214
251
  }
215
- return style;
252
+ return {
253
+ style: style,
254
+ arrayStyle: arrayStyle
255
+ };
216
256
  };
217
257
  var getAbsoluteStyle = function getAbsoluteStyle(position) {
218
- if (!parentElRef.current) return hideStyle;
258
+ if (!parentElRef.current) return {
259
+ style: hideStyle
260
+ };
219
261
  var rect = context.parentRect;
220
262
  if (scrollElRef !== null && scrollElRef !== void 0 && scrollElRef.current) {
221
263
  var _scrollElRef$current;
222
264
  var visibleRect = ((_scrollElRef$current = scrollElRef.current) === null || _scrollElRef$current === void 0 ? void 0 : _scrollElRef$current.getBoundingClientRect()) || {};
223
265
  if (rect.bottom < visibleRect.top || rect.top > visibleRect.bottom || rect.right < visibleRect.left || rect.left > visibleRect.right) {
224
- return hideStyle;
266
+ return {
267
+ style: hideStyle
268
+ };
225
269
  }
226
270
  }
227
- var style = getAbsolutePositionStyle(rect, position);
228
- return style;
271
+ var _getAbsolutePositionS = getAbsolutePositionStyle(rect, position),
272
+ style = _getAbsolutePositionS.style,
273
+ arrayStyle = _getAbsolutePositionS.arrayStyle;
274
+
275
+ // TODO: 如果是版本大于chrome128,需要根据currentCSSZoom处理chrome的bug
276
+ if (!(0, _utils.isChromeLowerThan)(128)) {
277
+ // @ts-ignore currentCSSZoom
278
+ var currentCSSZoom = document.body.currentCSSZoom;
279
+ if (currentCSSZoom === 1 || !currentCSSZoom) return {
280
+ style: style,
281
+ arrayStyle: arrayStyle
282
+ };
283
+ if (style.left && typeof style.left === 'number') {
284
+ style.left = style.left * (1 / currentCSSZoom);
285
+ }
286
+ if (style.top && typeof style.top === 'number') {
287
+ style.top = style.top * (1 / currentCSSZoom);
288
+ }
289
+ if (style.right && typeof style.right === 'number') {
290
+ style.right = style.right * (1 / currentCSSZoom);
291
+ }
292
+ if (style.bottom && typeof style.bottom === 'number') {
293
+ style.bottom = style.bottom * (1 / currentCSSZoom);
294
+ }
295
+ }
296
+ return {
297
+ style: style,
298
+ arrayStyle: arrayStyle
299
+ };
229
300
  };
230
301
  var getStyle = function getStyle() {
231
302
  var newStyle = {};
303
+ var newArrayStyle = {};
232
304
  var _ref2 = config || {},
233
305
  position = _ref2.position,
234
306
  absolute = _ref2.absolute;
235
- if (!position || !show || !parentElRef.current) return style;
307
+ if (!position || !show || !parentElRef.current) return {
308
+ newStyle: style
309
+ };
236
310
  context.parentRect = parentElRef.current.getBoundingClientRect();
237
311
  if (adjust) {
238
312
  var popupInfo = getPopUpInfo(context.parentRect);
@@ -247,21 +321,34 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
247
321
  fixedWidth: fixedWidth
248
322
  });
249
323
  } else {
250
- newStyle = getAbsoluteStyle(realPosition);
324
+ var _ref3 = getAbsoluteStyle(realPosition),
325
+ nextStyle = _ref3.style,
326
+ nextArrayStyle = _ref3.arrayStyle;
327
+ newStyle = nextStyle;
328
+ newArrayStyle = nextArrayStyle;
251
329
  }
252
330
  // for animation
253
331
  if (realPosition.indexOf('top') === 0) {
254
332
  newStyle.transformOrigin = 'center bottom';
255
333
  }
256
- return newStyle;
334
+ return {
335
+ newStyle: newStyle,
336
+ newArrayStyle: newArrayStyle
337
+ };
257
338
  };
258
339
  var updateStyle = (0, _usePersistFn.default)(function () {
259
- var newStyle = getStyle();
340
+ var _getStyle = getStyle(),
341
+ newStyle = _getStyle.newStyle,
342
+ newArrayStyle = _getStyle.newArrayStyle;
260
343
  if (newStyle && !(0, _shallowEqual.default)(style, newStyle)) {
261
344
  setStyle(newStyle);
345
+ setArrayStyle(newArrayStyle || {});
262
346
  }
263
347
  });
264
348
  (0, _react.useEffect)(updateStyle, [show, position, absolute, updateKey, fixedWidth]);
265
- return style;
349
+ return {
350
+ style: style,
351
+ arrayStyle: arrayStyle
352
+ };
266
353
  };
267
354
  var _default = exports.default = usePositionStyle;
@@ -12,7 +12,7 @@ declare const useDate: (props: UseDateProps) => {
12
12
  isToday: (date: Date) => boolean;
13
13
  isDisabled: (date: Date) => boolean;
14
14
  isActive: (date: Date) => boolean;
15
- isInRange: (date: Date) => false | "start" | "end" | "start-end" | "in";
15
+ isInRange: (date: Date) => false | "end" | "start" | "start-end" | "in";
16
16
  isCurrentMonth: (date: Date) => boolean;
17
17
  handleDayClick: (date: Date) => void;
18
18
  getDayStr: (date: Date) => number;
@@ -9,7 +9,7 @@ declare const useMonth: (props: UseMonthProps) => {
9
9
  isNow: (date: Date) => boolean;
10
10
  isDisabled: (date: Date) => boolean;
11
11
  isActive: (date: Date) => boolean;
12
- isInRange: (date: Date) => false | "start" | "end" | "start-end" | "in";
12
+ isInRange: (date: Date) => false | "end" | "start" | "start-end" | "in";
13
13
  handleMonthClick: (date: Date) => void;
14
14
  getMonthStr: (date: Date) => number;
15
15
  };
@@ -9,7 +9,7 @@ declare const useQuarter: (props: UseMonthProps) => {
9
9
  isNow: (date: Date) => boolean;
10
10
  isDisabled: (date: Date) => boolean;
11
11
  isActive: (date: Date) => boolean;
12
- isInRange: (date: Date) => false | "start" | "end" | "start-end" | "in";
12
+ isInRange: (date: Date) => false | "end" | "start" | "start-end" | "in";
13
13
  handleQuarterClick: (date: Date) => void;
14
14
  getQuarterStr: (date: Date) => number;
15
15
  };
@@ -11,7 +11,7 @@ declare const useYear: (props: UseYearProps) => {
11
11
  isNow: (date: Date) => boolean;
12
12
  isDisabled: (date: Date) => boolean;
13
13
  isActive: (date: Date) => boolean;
14
- isInRange: (date: Date) => false | "start" | "end" | "start-end" | "in";
14
+ isInRange: (date: Date) => false | "end" | "start" | "start-end" | "in";
15
15
  handleYearClick: (date: Date) => void;
16
16
  getYearStr: (date: Date) => number;
17
17
  };
@@ -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 & {}) | "hidden" | "checkbox" | "date" | "datetime-local" | "file" | "month" | "password" | "radio" | "week" | undefined;
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 & {}) | "hidden" | "checkbox" | "date" | "datetime-local" | "file" | "month" | "password" | "radio" | "week" | undefined;
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;;;;;;0BAoHK;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;;CAqBpE,CAAC;AAEF,eAAe,QAAQ,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
- var newPosition = (0, _position.getPosition)(targetRef.current, props.priorityDirection, autoMode);
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,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":"AAgFA,eAAO,MAAM,WAAW,WACd,WAAW,GAAG,IAAI,2EAEpB,SAAS,GAAG,MAAM,GAAG,MAAM,gKAKlC,CAAC"}
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"}
@@ -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
- if (horizontalPoint > windowWidth * 0.6) {
67
- position += '-right';
68
- } else if (horizontalPoint < windowWidth * 0.4) {
69
- position += '-left';
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
- if (mode === 'popover') return getPopoverPosition(target, priorityDirection);
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) => React.CSSProperties;
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,wBAsO3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
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
- if (adjust) overLeft = bodyRect.left - (rect.right - context.popUpWidth);
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 style;
242
+ return {
243
+ style: style,
244
+ arrayStyle: arrayStyle
245
+ };
206
246
  };
207
247
  var getAbsoluteStyle = function getAbsoluteStyle(position) {
208
- if (!parentElRef.current) return hideStyle;
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 hideStyle;
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
- var style = getAbsolutePositionStyle(rect, position);
218
- return style;
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 style;
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
- newStyle = getAbsoluteStyle(realPosition);
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 newStyle;
324
+ return {
325
+ newStyle: newStyle,
326
+ newArrayStyle: newArrayStyle
327
+ };
247
328
  };
248
329
  var updateStyle = usePersistFn(function () {
249
- var newStyle = getStyle();
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 style;
339
+ return {
340
+ style: style,
341
+ arrayStyle: arrayStyle
342
+ };
256
343
  };
257
344
  export default usePositionStyle;
@@ -12,7 +12,7 @@ declare const useDate: (props: UseDateProps) => {
12
12
  isToday: (date: Date) => boolean;
13
13
  isDisabled: (date: Date) => boolean;
14
14
  isActive: (date: Date) => boolean;
15
- isInRange: (date: Date) => false | "start" | "end" | "start-end" | "in";
15
+ isInRange: (date: Date) => false | "end" | "start" | "start-end" | "in";
16
16
  isCurrentMonth: (date: Date) => boolean;
17
17
  handleDayClick: (date: Date) => void;
18
18
  getDayStr: (date: Date) => number;
@@ -9,7 +9,7 @@ declare const useMonth: (props: UseMonthProps) => {
9
9
  isNow: (date: Date) => boolean;
10
10
  isDisabled: (date: Date) => boolean;
11
11
  isActive: (date: Date) => boolean;
12
- isInRange: (date: Date) => false | "start" | "end" | "start-end" | "in";
12
+ isInRange: (date: Date) => false | "end" | "start" | "start-end" | "in";
13
13
  handleMonthClick: (date: Date) => void;
14
14
  getMonthStr: (date: Date) => number;
15
15
  };
@@ -9,7 +9,7 @@ declare const useQuarter: (props: UseMonthProps) => {
9
9
  isNow: (date: Date) => boolean;
10
10
  isDisabled: (date: Date) => boolean;
11
11
  isActive: (date: Date) => boolean;
12
- isInRange: (date: Date) => false | "start" | "end" | "start-end" | "in";
12
+ isInRange: (date: Date) => false | "end" | "start" | "start-end" | "in";
13
13
  handleQuarterClick: (date: Date) => void;
14
14
  getQuarterStr: (date: Date) => number;
15
15
  };
@@ -11,7 +11,7 @@ declare const useYear: (props: UseYearProps) => {
11
11
  isNow: (date: Date) => boolean;
12
12
  isDisabled: (date: Date) => boolean;
13
13
  isActive: (date: Date) => boolean;
14
- isInRange: (date: Date) => false | "start" | "end" | "start-end" | "in";
14
+ isInRange: (date: Date) => false | "end" | "start" | "start-end" | "in";
15
15
  handleYearClick: (date: Date) => void;
16
16
  getYearStr: (date: Date) => number;
17
17
  };
@@ -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 & {}) | "hidden" | "checkbox" | "date" | "datetime-local" | "file" | "month" | "password" | "radio" | "week" | undefined;
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 & {}) | "hidden" | "checkbox" | "date" | "datetime-local" | "file" | "month" | "password" | "radio" | "week" | undefined;
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;;;;;;0BAoHK;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;;CAqBpE,CAAC;AAEF,eAAe,QAAQ,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"}
@@ -30,6 +30,7 @@ var usePopup = function usePopup(props) {
30
30
  removeChild = _useContext.removeChild;
31
31
  var targetRef = useRef(null);
32
32
  var popupRef = useRef(null);
33
+ var arrowRef = useRef(null);
33
34
  useEffect(function () {
34
35
  bindChild(popupRef);
35
36
  return function () {
@@ -61,11 +62,12 @@ var usePopup = function usePopup(props) {
61
62
  setPositionState = _useState4[1];
62
63
  var position = isPositionControl ? props.position : positionState;
63
64
  var updatePosition = usePersistFn(function () {
64
- if (isPositionControl) return;
65
- if (props.position === 'auto' || !props.position) {
66
- var newPosition = getPosition(targetRef.current, props.priorityDirection, autoMode);
65
+ // if (isPositionControl) return;
66
+ // if (props.position === 'auto' || !props.position) {
67
+ setTimeout(function () {
68
+ var newPosition = getPosition(targetRef.current, props.priorityDirection, autoMode, popupRef.current || undefined);
67
69
  if (newPosition !== position) setPositionState(newPosition);
68
- }
70
+ }, 10);
69
71
  });
70
72
  useEffect(function () {
71
73
  if (props.open) {
@@ -194,6 +196,7 @@ var usePopup = function usePopup(props) {
194
196
  position: position,
195
197
  targetRef: targetRef,
196
198
  popupRef: popupRef,
199
+ arrowRef: arrowRef,
197
200
  getTargetProps: getTargetProps,
198
201
  openPop: openPop,
199
202
  closePop: closePop,
@@ -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":"AAgFA,eAAO,MAAM,WAAW,WACd,WAAW,GAAG,IAAI,2EAEpB,SAAS,GAAG,MAAM,GAAG,MAAM,gKAKlC,CAAC"}
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"}
@@ -35,6 +35,7 @@ var getMenuPosition = function getMenuPosition(target) {
35
35
  };
36
36
  var getPopoverPosition = function getPopoverPosition(target) {
37
37
  var priorityDirection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'vertical';
38
+ var popup = arguments.length > 2 ? arguments[2] : undefined;
38
39
  var position = 'bottom-left';
39
40
  if (!target) return position;
40
41
  var rect = target.getBoundingClientRect();
@@ -56,11 +57,24 @@ var getPopoverPosition = function getPopoverPosition(target) {
56
57
  position += '-top';
57
58
  }
58
59
  } else {
60
+ var popupRect = popup === null || popup === void 0 ? void 0 : popup.getBoundingClientRect();
59
61
  if (verticalPoint > windowHeight / 2) position = 'top';else position = 'bottom';
60
- if (horizontalPoint > windowWidth * 0.6) {
61
- position += '-right';
62
- } else if (horizontalPoint < windowWidth * 0.4) {
63
- position += '-left';
62
+
63
+ // 如果渲染了弹出内容,则根据弹出内容宽度计算是否自动调整位置
64
+ if (popupRect) {
65
+ if ((popupRect === null || popupRect === void 0 ? void 0 : popupRect.width) / 2 > rect.left) {
66
+ position += '-left';
67
+ }
68
+ if ((popupRect === null || popupRect === void 0 ? void 0 : popupRect.width) / 2 > windowWidth - rect.right) {
69
+ position += '-right';
70
+ }
71
+ } else {
72
+ // 兜底计算
73
+ if (horizontalPoint > windowWidth * 0.6) {
74
+ position += '-right';
75
+ } else if (horizontalPoint < windowWidth * 0.4) {
76
+ position += '-left';
77
+ }
64
78
  }
65
79
  }
66
80
  return position;
@@ -68,7 +82,8 @@ var getPopoverPosition = function getPopoverPosition(target) {
68
82
  export var getPosition = function getPosition(target) {
69
83
  var priorityDirection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'vertical';
70
84
  var mode = arguments.length > 2 ? arguments[2] : undefined;
71
- if (mode === 'popover') return getPopoverPosition(target, priorityDirection);
85
+ var popup = arguments.length > 3 ? arguments[3] : undefined;
86
+ if (mode === 'popover') return getPopoverPosition(target, priorityDirection, popup);
72
87
  if (mode === 'menu') return getMenuPosition(target, priorityDirection);
73
88
  return 'bottom-left';
74
89
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/hooks",
3
- "version": "3.3.6-beta.1",
3
+ "version": "3.3.6-beta.3",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",