@sheinx/hooks 3.8.4-beta.5 → 3.8.4-beta.7
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 +1 -0
- package/cjs/common/use-position-style/index.d.ts.map +1 -1
- package/cjs/common/use-position-style/index.js +44 -5
- package/esm/common/use-position-style/index.d.ts +1 -0
- package/esm/common/use-position-style/index.d.ts.map +1 -1
- package/esm/common/use-position-style/index.js +44 -5
- package/package.json +1 -1
@@ -15,6 +15,7 @@ export interface PositionStyleConfig {
|
|
15
15
|
fixedWidth?: boolean | 'min';
|
16
16
|
updateKey?: number | string;
|
17
17
|
adjust?: boolean;
|
18
|
+
onAdjust?: (position: HorizontalPosition | VerticalPosition) => void;
|
18
19
|
offset?: [number, number];
|
19
20
|
}
|
20
21
|
export declare const usePositionStyle: (config: PositionStyleConfig) => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAUpE,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,K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E,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,kBAAkB,GAAG,gBAAgB,KAAK,IAAI,CAAC;IACrE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3B;AAsBD,eAAO,MAAM,gBAAgB,WAAY,mBAAmB;;CAsV3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
@@ -108,10 +108,43 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
108
108
|
setPopupElWidth(popupElRef.current.getBoundingClientRect().width);
|
109
109
|
}
|
110
110
|
}, [show, popupElRef.current]);
|
111
|
-
var
|
111
|
+
var adjustHorizontalPosition = function adjustHorizontalPosition(position) {
|
112
|
+
var _config$onAdjust;
|
113
|
+
var winWidth = _utils.docSize.width;
|
112
114
|
var winHeight = _utils.docSize.height;
|
113
|
-
if (!verticalPosition.includes(position)) return position;
|
114
115
|
var newPosition = position;
|
116
|
+
var _position$split = position.split('-'),
|
117
|
+
_position$split2 = _slicedToArray(_position$split, 2),
|
118
|
+
h = _position$split2[0],
|
119
|
+
v = _position$split2[1];
|
120
|
+
if (h === 'right') {
|
121
|
+
var horizontalPoint = context.parentRect.left + context.parentRect.width;
|
122
|
+
if (horizontalPoint / winWidth > 0.5 && horizontalPoint + context.popUpWidth > winWidth) {
|
123
|
+
newPosition = position.replace('right', 'left');
|
124
|
+
}
|
125
|
+
} else if (h === 'left') {
|
126
|
+
var _horizontalPoint = context.parentRect.left;
|
127
|
+
if (_horizontalPoint / winWidth < 0.5 && _horizontalPoint < context.popUpWidth) {
|
128
|
+
newPosition = position.replace('left', 'right');
|
129
|
+
}
|
130
|
+
}
|
131
|
+
if (v === 'top') {
|
132
|
+
var verticalPoint = context.parentRect.top;
|
133
|
+
if (verticalPoint / winHeight > 0.5 && verticalPoint + context.popUpHeight > winHeight) {
|
134
|
+
newPosition = newPosition.replace('top', 'bottom');
|
135
|
+
}
|
136
|
+
} else if (v === 'bottom') {
|
137
|
+
var _verticalPoint = context.parentRect.bottom;
|
138
|
+
if (_verticalPoint / winHeight < 0.5 && _verticalPoint < context.popUpHeight) {
|
139
|
+
newPosition = newPosition.replace('bottom', 'top');
|
140
|
+
}
|
141
|
+
}
|
142
|
+
config === null || config === void 0 || (_config$onAdjust = config.onAdjust) === null || _config$onAdjust === void 0 || _config$onAdjust.call(config, newPosition);
|
143
|
+
return newPosition;
|
144
|
+
};
|
145
|
+
var adjustVerticalPosition = function adjustVerticalPosition(position) {
|
146
|
+
var newPosition = position;
|
147
|
+
var winHeight = _utils.docSize.height;
|
115
148
|
var verticalPoint = context.parentRect.top + context.parentRect.height / 2;
|
116
149
|
if (position.startsWith('top')) {
|
117
150
|
if (verticalPoint / winHeight < 0.5 && context.parentRect.top - context.popUpHeight - popupGap < 0) {
|
@@ -136,15 +169,21 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
136
169
|
}
|
137
170
|
} else {
|
138
171
|
// absolute 场景下,右侧溢出判断需要考虑弹出层元素的尺寸
|
139
|
-
var _position$
|
140
|
-
_position$
|
141
|
-
_horizontalPosition = _position$
|
172
|
+
var _position$split3 = position.split('-'),
|
173
|
+
_position$split4 = _slicedToArray(_position$split3, 2),
|
174
|
+
_horizontalPosition = _position$split4[1];
|
142
175
|
if (_horizontalPosition === 'left' && context.parentRect.left + (popupElWidth || context.popUpWidth) > _utils.docSize.width) {
|
143
176
|
newPosition = newPosition.replace('left', 'right');
|
144
177
|
}
|
145
178
|
}
|
146
179
|
return newPosition;
|
147
180
|
};
|
181
|
+
var adjustPosition = function adjustPosition(position) {
|
182
|
+
if (!verticalPosition.includes(position)) {
|
183
|
+
return adjustHorizontalPosition(position);
|
184
|
+
}
|
185
|
+
return adjustVerticalPosition(position);
|
186
|
+
};
|
148
187
|
var getPopUpInfo = function getPopUpInfo(parentRect) {
|
149
188
|
var _popupElRef$current$p;
|
150
189
|
if (!popupElRef.current) return {
|
@@ -15,6 +15,7 @@ export interface PositionStyleConfig {
|
|
15
15
|
fixedWidth?: boolean | 'min';
|
16
16
|
updateKey?: number | string;
|
17
17
|
adjust?: boolean;
|
18
|
+
onAdjust?: (position: HorizontalPosition | VerticalPosition) => void;
|
18
19
|
offset?: [number, number];
|
19
20
|
}
|
20
21
|
export declare const usePositionStyle: (config: PositionStyleConfig) => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAUpE,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,K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gB,KAAK,IAAI,CAAC;IACrE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3B;AAsBD,eAAO,MAAM,gBAAgB,WAAY,mBAAmB;;CAsV3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
@@ -99,10 +99,43 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
99
99
|
setPopupElWidth(popupElRef.current.getBoundingClientRect().width);
|
100
100
|
}
|
101
101
|
}, [show, popupElRef.current]);
|
102
|
-
var
|
102
|
+
var adjustHorizontalPosition = function adjustHorizontalPosition(position) {
|
103
|
+
var _config$onAdjust;
|
104
|
+
var winWidth = docSize.width;
|
103
105
|
var winHeight = docSize.height;
|
104
|
-
if (!verticalPosition.includes(position)) return position;
|
105
106
|
var newPosition = position;
|
107
|
+
var _position$split = position.split('-'),
|
108
|
+
_position$split2 = _slicedToArray(_position$split, 2),
|
109
|
+
h = _position$split2[0],
|
110
|
+
v = _position$split2[1];
|
111
|
+
if (h === 'right') {
|
112
|
+
var horizontalPoint = context.parentRect.left + context.parentRect.width;
|
113
|
+
if (horizontalPoint / winWidth > 0.5 && horizontalPoint + context.popUpWidth > winWidth) {
|
114
|
+
newPosition = position.replace('right', 'left');
|
115
|
+
}
|
116
|
+
} else if (h === 'left') {
|
117
|
+
var _horizontalPoint = context.parentRect.left;
|
118
|
+
if (_horizontalPoint / winWidth < 0.5 && _horizontalPoint < context.popUpWidth) {
|
119
|
+
newPosition = position.replace('left', 'right');
|
120
|
+
}
|
121
|
+
}
|
122
|
+
if (v === 'top') {
|
123
|
+
var verticalPoint = context.parentRect.top;
|
124
|
+
if (verticalPoint / winHeight > 0.5 && verticalPoint + context.popUpHeight > winHeight) {
|
125
|
+
newPosition = newPosition.replace('top', 'bottom');
|
126
|
+
}
|
127
|
+
} else if (v === 'bottom') {
|
128
|
+
var _verticalPoint = context.parentRect.bottom;
|
129
|
+
if (_verticalPoint / winHeight < 0.5 && _verticalPoint < context.popUpHeight) {
|
130
|
+
newPosition = newPosition.replace('bottom', 'top');
|
131
|
+
}
|
132
|
+
}
|
133
|
+
config === null || config === void 0 || (_config$onAdjust = config.onAdjust) === null || _config$onAdjust === void 0 || _config$onAdjust.call(config, newPosition);
|
134
|
+
return newPosition;
|
135
|
+
};
|
136
|
+
var adjustVerticalPosition = function adjustVerticalPosition(position) {
|
137
|
+
var newPosition = position;
|
138
|
+
var winHeight = docSize.height;
|
106
139
|
var verticalPoint = context.parentRect.top + context.parentRect.height / 2;
|
107
140
|
if (position.startsWith('top')) {
|
108
141
|
if (verticalPoint / winHeight < 0.5 && context.parentRect.top - context.popUpHeight - popupGap < 0) {
|
@@ -127,15 +160,21 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
127
160
|
}
|
128
161
|
} else {
|
129
162
|
// absolute 场景下,右侧溢出判断需要考虑弹出层元素的尺寸
|
130
|
-
var _position$
|
131
|
-
_position$
|
132
|
-
_horizontalPosition = _position$
|
163
|
+
var _position$split3 = position.split('-'),
|
164
|
+
_position$split4 = _slicedToArray(_position$split3, 2),
|
165
|
+
_horizontalPosition = _position$split4[1];
|
133
166
|
if (_horizontalPosition === 'left' && context.parentRect.left + (popupElWidth || context.popUpWidth) > docSize.width) {
|
134
167
|
newPosition = newPosition.replace('left', 'right');
|
135
168
|
}
|
136
169
|
}
|
137
170
|
return newPosition;
|
138
171
|
};
|
172
|
+
var adjustPosition = function adjustPosition(position) {
|
173
|
+
if (!verticalPosition.includes(position)) {
|
174
|
+
return adjustHorizontalPosition(position);
|
175
|
+
}
|
176
|
+
return adjustVerticalPosition(position);
|
177
|
+
};
|
139
178
|
var getPopUpInfo = function getPopUpInfo(parentRect) {
|
140
179
|
var _popupElRef$current$p;
|
141
180
|
if (!popupElRef.current) return {
|