|
|
|
@ -502,207 +502,208 @@ export function getComboPositionByDirections(combo, popup, extraWidth, extraHeig
|
|
|
|
|
for (i = 0; i < directions.length; i++) { |
|
|
|
|
direct = directions[i]; |
|
|
|
|
switch (direct) { |
|
|
|
|
case "left": |
|
|
|
|
leftRight.push(direct); |
|
|
|
|
break; |
|
|
|
|
case "right": |
|
|
|
|
leftRight.push(direct); |
|
|
|
|
break; |
|
|
|
|
case "top": |
|
|
|
|
topBottom.push(direct); |
|
|
|
|
break; |
|
|
|
|
case "bottom": |
|
|
|
|
topBottom.push(direct); |
|
|
|
|
break; |
|
|
|
|
case "innerLeft": |
|
|
|
|
innerLeftRight.push(direct); |
|
|
|
|
break; |
|
|
|
|
case "innerRight": |
|
|
|
|
innerLeftRight.push(direct); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
case "left": |
|
|
|
|
leftRight.push(direct); |
|
|
|
|
break; |
|
|
|
|
case "right": |
|
|
|
|
leftRight.push(direct); |
|
|
|
|
break; |
|
|
|
|
case "top": |
|
|
|
|
topBottom.push(direct); |
|
|
|
|
break; |
|
|
|
|
case "bottom": |
|
|
|
|
topBottom.push(direct); |
|
|
|
|
break; |
|
|
|
|
case "innerLeft": |
|
|
|
|
innerLeftRight.push(direct); |
|
|
|
|
break; |
|
|
|
|
case "innerRight": |
|
|
|
|
innerLeftRight.push(direct); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (i = 0; i < directions.length; i++) { |
|
|
|
|
let tW, tH; |
|
|
|
|
direct = directions[i]; |
|
|
|
|
switch (direct) { |
|
|
|
|
case "left": |
|
|
|
|
if (!isNeedAdaptHeight) { |
|
|
|
|
var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight; |
|
|
|
|
if (isLeftSpaceEnough(combo, popup, tW)) { |
|
|
|
|
left = getLeftPosition(combo, popup, tW, container).left; |
|
|
|
|
if (topBottom[0] === "bottom") { |
|
|
|
|
pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight, container); |
|
|
|
|
} else { |
|
|
|
|
pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight, container); |
|
|
|
|
} |
|
|
|
|
pos.dir = `left,${pos.dir}`; |
|
|
|
|
if (tbFirst) { |
|
|
|
|
pos.change = "left"; |
|
|
|
|
} |
|
|
|
|
pos.left = left; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
case "left": |
|
|
|
|
if (!isNeedAdaptHeight) { |
|
|
|
|
tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight; |
|
|
|
|
if (isLeftSpaceEnough(combo, popup, tW)) { |
|
|
|
|
left = getLeftPosition(combo, popup, tW, container).left; |
|
|
|
|
if (topBottom[0] === "bottom") { |
|
|
|
|
pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight, container); |
|
|
|
|
} else { |
|
|
|
|
pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight, container); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
lrFirst = true; |
|
|
|
|
break; |
|
|
|
|
case "right": |
|
|
|
|
if (!isNeedAdaptHeight) { |
|
|
|
|
var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight; |
|
|
|
|
if (isRightSpaceEnough(combo, popup, tW)) { |
|
|
|
|
left = getRightPosition(combo, popup, tW, container).left; |
|
|
|
|
if (topBottom[0] === "bottom") { |
|
|
|
|
pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight, container); |
|
|
|
|
} else { |
|
|
|
|
pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight, container); |
|
|
|
|
} |
|
|
|
|
pos.dir = `right,${pos.dir}`; |
|
|
|
|
if (tbFirst) { |
|
|
|
|
pos.change = "right"; |
|
|
|
|
} |
|
|
|
|
pos.left = left; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
pos.dir = `left,${pos.dir}`; |
|
|
|
|
if (tbFirst) { |
|
|
|
|
pos.change = "left"; |
|
|
|
|
} |
|
|
|
|
pos.left = left; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
lrFirst = true; |
|
|
|
|
break; |
|
|
|
|
case "top": |
|
|
|
|
var tW = lrFirst ? extraHeight : extraWidth, tH = lrFirst ? extraWidth : extraHeight; |
|
|
|
|
if (isTopSpaceEnough(combo, popup, tH)) { |
|
|
|
|
top = getTopPosition(combo, popup, tH, container).top; |
|
|
|
|
if (leftRight[0] === "right") { |
|
|
|
|
pos = getLeftAlignPosition(combo, popup, tW, container); |
|
|
|
|
} |
|
|
|
|
lrFirst = true; |
|
|
|
|
break; |
|
|
|
|
case "right": |
|
|
|
|
if (!isNeedAdaptHeight) { |
|
|
|
|
tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight; |
|
|
|
|
if (isRightSpaceEnough(combo, popup, tW)) { |
|
|
|
|
left = getRightPosition(combo, popup, tW, container).left; |
|
|
|
|
if (topBottom[0] === "bottom") { |
|
|
|
|
pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight, container); |
|
|
|
|
} else { |
|
|
|
|
pos = getRightAlignPosition(combo, popup, tW, container); |
|
|
|
|
pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight, container); |
|
|
|
|
} |
|
|
|
|
pos.dir = `top,${pos.dir}`; |
|
|
|
|
if (lrFirst) { |
|
|
|
|
pos.change = "top"; |
|
|
|
|
pos.dir = `right,${pos.dir}`; |
|
|
|
|
if (tbFirst) { |
|
|
|
|
pos.change = "right"; |
|
|
|
|
} |
|
|
|
|
pos.top = top; |
|
|
|
|
pos.left = left; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
if (needAdaptHeight) { |
|
|
|
|
isNeedAdaptHeight = true; |
|
|
|
|
} |
|
|
|
|
lrFirst = true; |
|
|
|
|
break; |
|
|
|
|
case "top": |
|
|
|
|
tW = lrFirst ? extraHeight : extraWidth, tH = lrFirst ? extraWidth : extraHeight; |
|
|
|
|
if (isTopSpaceEnough(combo, popup, tH)) { |
|
|
|
|
top = getTopPosition(combo, popup, tH, container).top; |
|
|
|
|
if (leftRight[0] === "right") { |
|
|
|
|
pos = getLeftAlignPosition(combo, popup, tW, container); |
|
|
|
|
} else { |
|
|
|
|
pos = getRightAlignPosition(combo, popup, tW, container); |
|
|
|
|
} |
|
|
|
|
pos.dir = `top,${pos.dir}`; |
|
|
|
|
if (lrFirst) { |
|
|
|
|
pos.change = "top"; |
|
|
|
|
} |
|
|
|
|
tbFirst = true; |
|
|
|
|
break; |
|
|
|
|
case "bottom": |
|
|
|
|
var tW = lrFirst ? extraHeight : extraWidth, tH = lrFirst ? extraWidth : extraHeight; |
|
|
|
|
if (isBottomSpaceEnough(combo, popup, tH)) { |
|
|
|
|
top = getBottomPosition(combo, popup, tH, container).top; |
|
|
|
|
if (leftRight[0] === "right") { |
|
|
|
|
pos = getLeftAlignPosition(combo, popup, tW, container); |
|
|
|
|
pos.top = top; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
if (needAdaptHeight) { |
|
|
|
|
isNeedAdaptHeight = true; |
|
|
|
|
} |
|
|
|
|
tbFirst = true; |
|
|
|
|
break; |
|
|
|
|
case "bottom": |
|
|
|
|
tW = lrFirst ? extraHeight : extraWidth, tH = lrFirst ? extraWidth : extraHeight; |
|
|
|
|
if (isBottomSpaceEnough(combo, popup, tH)) { |
|
|
|
|
top = getBottomPosition(combo, popup, tH, container).top; |
|
|
|
|
if (leftRight[0] === "right") { |
|
|
|
|
pos = getLeftAlignPosition(combo, popup, tW, container); |
|
|
|
|
} else { |
|
|
|
|
pos = getRightAlignPosition(combo, popup, tW, container); |
|
|
|
|
} |
|
|
|
|
pos.dir = `bottom,${pos.dir}`; |
|
|
|
|
if (lrFirst) { |
|
|
|
|
pos.change = "bottom"; |
|
|
|
|
} |
|
|
|
|
pos.top = top; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
if (needAdaptHeight) { |
|
|
|
|
isNeedAdaptHeight = true; |
|
|
|
|
} |
|
|
|
|
tbFirst = true; |
|
|
|
|
break; |
|
|
|
|
case "innerLeft": |
|
|
|
|
if (!isNeedAdaptHeight) { |
|
|
|
|
tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight; |
|
|
|
|
if (isInnerLeftSpaceEnough(combo, popup, tW)) { |
|
|
|
|
left = getInnerLeftPosition(combo, popup, tW).left; |
|
|
|
|
if (topBottom[0] === "bottom") { |
|
|
|
|
pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight); |
|
|
|
|
} else { |
|
|
|
|
pos = getRightAlignPosition(combo, popup, tW, container); |
|
|
|
|
pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight); |
|
|
|
|
} |
|
|
|
|
pos.dir = `bottom,${pos.dir}`; |
|
|
|
|
if (lrFirst) { |
|
|
|
|
pos.change = "bottom"; |
|
|
|
|
pos.dir = `innerLeft,${pos.dir}`; |
|
|
|
|
if (tbFirst) { |
|
|
|
|
pos.change = "innerLeft"; |
|
|
|
|
} |
|
|
|
|
pos.top = top; |
|
|
|
|
pos.left = left; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
if (needAdaptHeight) { |
|
|
|
|
isNeedAdaptHeight = true; |
|
|
|
|
} |
|
|
|
|
tbFirst = true; |
|
|
|
|
break; |
|
|
|
|
case "innerLeft": |
|
|
|
|
if (!isNeedAdaptHeight) { |
|
|
|
|
var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight; |
|
|
|
|
if (isInnerLeftSpaceEnough(combo, popup, tW)) { |
|
|
|
|
left = getInnerLeftPosition(combo, popup, tW).left; |
|
|
|
|
if (topBottom[0] === "bottom") { |
|
|
|
|
pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight); |
|
|
|
|
} else { |
|
|
|
|
pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight); |
|
|
|
|
} |
|
|
|
|
pos.dir = `innerLeft,${pos.dir}`; |
|
|
|
|
if (tbFirst) { |
|
|
|
|
pos.change = "innerLeft"; |
|
|
|
|
} |
|
|
|
|
pos.left = left; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
lrFirst = true; |
|
|
|
|
break; |
|
|
|
|
case "innerRight": |
|
|
|
|
if (!isNeedAdaptHeight) { |
|
|
|
|
tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight; |
|
|
|
|
if (isInnerRightSpaceEnough(combo, popup, tW)) { |
|
|
|
|
left = getInnerRightPosition(combo, popup, tW).left; |
|
|
|
|
if (topBottom[0] === "bottom") { |
|
|
|
|
pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight); |
|
|
|
|
} else { |
|
|
|
|
pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
lrFirst = true; |
|
|
|
|
break; |
|
|
|
|
case "innerRight": |
|
|
|
|
if (!isNeedAdaptHeight) { |
|
|
|
|
var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight; |
|
|
|
|
if (isInnerRightSpaceEnough(combo, popup, tW)) { |
|
|
|
|
left = getInnerRightPosition(combo, popup, tW).left; |
|
|
|
|
if (topBottom[0] === "bottom") { |
|
|
|
|
pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight); |
|
|
|
|
} else { |
|
|
|
|
pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight); |
|
|
|
|
} |
|
|
|
|
pos.dir = `innerLeft,${pos.dir}`; |
|
|
|
|
if (tbFirst) { |
|
|
|
|
pos.change = "innerRight"; |
|
|
|
|
} |
|
|
|
|
pos.left = left; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
pos.dir = `innerLeft,${pos.dir}`; |
|
|
|
|
if (tbFirst) { |
|
|
|
|
pos.change = "innerRight"; |
|
|
|
|
} |
|
|
|
|
pos.left = left; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 此处为四个方向放不下时挑空间最大的方向去放置, 也就是说我设置了弹出方向为"bottom,left",
|
|
|
|
|
// 最后发现实际弹出方向可能是"top,left",那么此时外界获取popup的方向应该是"top,left"
|
|
|
|
|
switch (directions[0]) { |
|
|
|
|
case "left": |
|
|
|
|
case "right": |
|
|
|
|
if (isRightSpaceLarger(combo)) { |
|
|
|
|
left = getRightAdaptPosition(combo, popup, extraWidth, container).left; |
|
|
|
|
firstDir = "right"; |
|
|
|
|
} else { |
|
|
|
|
left = getLeftAdaptPosition(combo, popup, extraWidth, container).left; |
|
|
|
|
firstDir = "left"; |
|
|
|
|
} |
|
|
|
|
if (topBottom[0] === "bottom") { |
|
|
|
|
pos = getTopAlignPosition(combo, popup, extraHeight, needAdaptHeight); |
|
|
|
|
pos.left = left; |
|
|
|
|
pos.dir = `${firstDir},${pos.dir}`; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
pos = getBottomAlignPosition(combo, popup, extraHeight, needAdaptHeight); |
|
|
|
|
case "left": |
|
|
|
|
case "right": |
|
|
|
|
if (isRightSpaceLarger(combo)) { |
|
|
|
|
left = getRightAdaptPosition(combo, popup, extraWidth, container).left; |
|
|
|
|
firstDir = "right"; |
|
|
|
|
} else { |
|
|
|
|
left = getLeftAdaptPosition(combo, popup, extraWidth, container).left; |
|
|
|
|
firstDir = "left"; |
|
|
|
|
} |
|
|
|
|
if (topBottom[0] === "bottom") { |
|
|
|
|
pos = getTopAlignPosition(combo, popup, extraHeight, needAdaptHeight); |
|
|
|
|
pos.left = left; |
|
|
|
|
pos.dir = `${firstDir},${pos.dir}`; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
default : |
|
|
|
|
if (isBottomSpaceLarger(combo)) { |
|
|
|
|
top = getBottomAdaptPosition(combo, popup, extraHeight, needAdaptHeight, container).top; |
|
|
|
|
firstDir = "bottom"; |
|
|
|
|
} else { |
|
|
|
|
top = getTopAdaptPosition(combo, popup, extraHeight, needAdaptHeight, container).top; |
|
|
|
|
firstDir = "top"; |
|
|
|
|
} |
|
|
|
|
if (leftRight[0] === "right") { |
|
|
|
|
pos = getLeftAlignPosition(combo, popup, extraWidth, container); |
|
|
|
|
pos.top = top; |
|
|
|
|
pos.dir = `${firstDir},${pos.dir}`; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
pos = getRightAlignPosition(combo, popup, extraWidth, container); |
|
|
|
|
} |
|
|
|
|
pos = getBottomAlignPosition(combo, popup, extraHeight, needAdaptHeight); |
|
|
|
|
pos.left = left; |
|
|
|
|
pos.dir = `${firstDir},${pos.dir}`; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
default : |
|
|
|
|
if (isBottomSpaceLarger(combo)) { |
|
|
|
|
top = getBottomAdaptPosition(combo, popup, extraHeight, needAdaptHeight, container).top; |
|
|
|
|
firstDir = "bottom"; |
|
|
|
|
} else { |
|
|
|
|
top = getTopAdaptPosition(combo, popup, extraHeight, needAdaptHeight, container).top; |
|
|
|
|
firstDir = "top"; |
|
|
|
|
} |
|
|
|
|
if (leftRight[0] === "right") { |
|
|
|
|
pos = getLeftAlignPosition(combo, popup, extraWidth, container); |
|
|
|
|
pos.top = top; |
|
|
|
|
pos.dir = `${firstDir},${pos.dir}`; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
pos = getRightAlignPosition(combo, popup, extraWidth, container); |
|
|
|
|
pos.top = top; |
|
|
|
|
pos.dir = `${firstDir},${pos.dir}`; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -715,26 +716,26 @@ export function getComboPosition(combo, popup, extraWidth, extraHeight, needAdap
|
|
|
|
|
popup.resetHeight && popup.resetHeight(maxHeight); |
|
|
|
|
const position = getComboPositionByDirections(combo, popup, extraWidth, extraHeight, needAdaptHeight, directions || ["bottom", "top", "right", "left"], positionRelativeElement); |
|
|
|
|
switch (offsetStyle) { |
|
|
|
|
case "center": |
|
|
|
|
if (position.change) { |
|
|
|
|
var p = getMiddleAdaptPosition(combo, popup, positionRelativeElement); |
|
|
|
|
position.top = p.top; |
|
|
|
|
} else { |
|
|
|
|
var p = getCenterAdaptPosition(combo, popup, positionRelativeElement); |
|
|
|
|
position.left = p.left; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "middle": |
|
|
|
|
if (position.change) { |
|
|
|
|
var p = getCenterAdaptPosition(combo, popup, positionRelativeElement); |
|
|
|
|
position.left = p.left; |
|
|
|
|
} else { |
|
|
|
|
var p = getMiddleAdaptPosition(combo, popup, positionRelativeElement); |
|
|
|
|
position.top = p.top; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
case "center": |
|
|
|
|
if (position.change) { |
|
|
|
|
const p = getMiddleAdaptPosition(combo, popup, positionRelativeElement); |
|
|
|
|
position.top = p.top; |
|
|
|
|
} else { |
|
|
|
|
const p = getCenterAdaptPosition(combo, popup, positionRelativeElement); |
|
|
|
|
position.left = p.left; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "middle": |
|
|
|
|
if (position.change) { |
|
|
|
|
const p = getCenterAdaptPosition(combo, popup, positionRelativeElement); |
|
|
|
|
position.left = p.left; |
|
|
|
|
} else { |
|
|
|
|
const p = getMiddleAdaptPosition(combo, popup, positionRelativeElement); |
|
|
|
|
position.top = p.top; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if (needAdaptHeight === true) { |
|
|
|
|
popup.resetHeight && popup.resetHeight(Math.min(viewportBounds.height - position.top - (positionRelativeElement ? positionRelativeElement.getBoundingClientRect().top : 0), maxHeight)); |
|
|
|
|