Browse Source

Merge pull request #212118 in DEC/fineui from release/11.0 to bugfix/11.0

* commit '67c47cd7a81505c2980dc2d99c92db50cb9433f3':
  BI-119055 fix: needadaptive的下拉计算NaN
  auto upgrade version to 2.0.20221215171537
  BI-118849 fix: combo在屏幕边缘,左右位置不够之后的位置调整逻辑
  auto upgrade version to 2.0.20221215144622
  auto upgrade version to 2.0.20221215141039
  BI-118659 fix: belowMouse的实现
  无JIRA "bi.number_editor" 支持水印
  BI-118917 fix: bi.switcher这种利用Masker遮罩的场景处理
  auto upgrade version to 2.0.20221214115751
  BI-118849 fix: 适配 offsetStyle center和middle问题
  auto upgrade version to 2.0.20221214104244
  KERNEL-11877 fix: supportCSSTransform 默认改为true
  KERNEL-11877 fix: 关掉BI.BubblesController的
  BI-118754 fix(getMinimumFontSize): 获取最小字号无效
  KERNEL-11877 feat: 升级popperjs 解决scale问题
  auto upgrade version to 2.0.20221213152248
research/test
superman 2 years ago
parent
commit
8f90e82ca2
  1. 3
      demo/js/widget/numbereditor/demo.number_editor.js
  2. 2
      package.json
  3. 36
      src/base/combination/combo.js
  4. 17
      src/core/controller/controller.bubbles.js
  5. 61
      src/core/controller/controller.layer.js
  6. 3474
      src/core/controller/popper.js
  7. 111
      src/core/platform/web/dom.js
  8. 3
      src/core/platform/web/function.js
  9. 48
      src/widget/numbereditor/number.editor.js

3
demo/js/widget/numbereditor/demo.number_editor.js

@ -14,7 +14,8 @@ Demo.FileManager = BI.inherit(BI.Widget, {
},
height: 24,
width: 150,
errorText: "hahah"
errorText: "hahah",
watermark: "每个人都是自己健康的第一责任人",
});
editor1.on(BI.NumberEditor.EVENT_CHANGE, function () {
if (BI.parseFloat(this.getValue()) < 1) {

2
package.json

@ -1,6 +1,6 @@
{
"name": "fineui",
"version": "2.0.20221210193709",
"version": "2.0.20221215171537",
"description": "fineui",
"main": "dist/fineui_without_conflict.min.js",
"types": "dist/lib/index.d.ts",

36
src/base/combination/combo.js

@ -38,9 +38,9 @@
adjustLength: 0, // 调整的距离
adjustXOffset: 0,
adjustYOffset: 0,
supportCSSTransform: false,
supportCSSTransform: true,
hideChecker: BI.emptyFn,
offsetStyle: "left", // left,right,center
offsetStyle: "", // "",center,middle
el: {},
popup: {},
comboClass: "bi-combo-popup",
@ -196,28 +196,22 @@
this.popupView.visible();
var combo = (o.belowMouse && BI.isNotNull(e)) ? {
element: {
0: e.target,
0: BI.extend({}, e.target, {
getBoundingClientRect: function () {
return {
left: e.pageX,
top: e.pageY,
width: 0,
height: 0,
};
}
}),
offset: function () {
return {
left: e.pageX,
top: e.pageY,
};
},
bounds: function () {
// offset为其相对于父定位元素的偏移
return {
x: e.offsetX,
y: e.offsetY,
width: 0,
height: 24,
};
},
outerWidth: function () {
return 0;
},
outerHeight: function () {
return 24;
},
},
} : this.combo;
var positionRelativeElement = BI.DOM.getPositionRelativeContainingBlock(BI.isNull(o.container) ? this.element[0] : BI.Widget._renderEngine.createElement(BI.isFunction(o.container) ? o.container() : o.container)[0]);
@ -308,10 +302,10 @@
var scaleX = positonedRect.width / positionRelativeElement.offsetWidth;
var scaleY = positonedRect.height / positionRelativeElement.offsetHeight;
p.top && (p.top = p.top / scaleY);
p.left && (p.left = p.left / scaleX);
p.top && (p.top = Math.round(p.top / scaleY));
p.left && (p.left = Math.round(p.left / scaleX));
p.adaptHeight && (p.adaptHeight = p.adaptHeight / scaleY);
p.adaptHeight && (p.adaptHeight = Math.round(p.adaptHeight / scaleY));
}
if ("adaptHeight" in p) {

17
src/core/controller/controller.bubbles.js

@ -45,9 +45,11 @@ BI.BubblesController = BI.inherit(BI.Controller, {
BI.createWidget({
type: "bi.default",
element: container,
items: [{
el: bubble
}]
items: [
{
el: bubble
}
]
});
if (this.storePoppers[name]) {
this.storePoppers[name].destroy();
@ -65,7 +67,14 @@ BI.BubblesController = BI.inherit(BI.Controller, {
options: {
offset: [adjustXOffset, adjustYOffset]
}
}
},
{
name: "preventOverflow",
enabled: false
}, {
name: "flip",
enabled: false
},
]
});
return this;

61
src/core/controller/controller.layer.js

@ -63,41 +63,54 @@ BI.LayerController = BI.inherit(BI.Controller, {
var layout = BI.createWidget({
type: "bi.absolute",
invisible: true,
items: [{
el: widget,
left: 0,
right: 0,
top: 0,
bottom: 0
}]
items: [
{
el: widget,
left: 0,
right: 0,
top: 0,
bottom: 0
}
]
}, context);
BI.createWidget({
type: "bi.absolute",
element: op.container || this.options.render,
items: [{
el: layout,
left: offset.left || 0,
right: offset.right || 0,
top: offset.top || 0,
bottom: offset.bottom || 0
}]
items: [
{
el: layout,
left: offset.left || 0,
right: offset.right || 0,
top: offset.top || 0,
bottom: offset.bottom || 0
}
]
});
if (w) {
layout.element.addClass("bi-popup-view");
layout.element.css({
left: w.offset().left + (offset.left || 0),
top: w.offset().top + (offset.top || 0),
width: offset.width || (w.outerWidth() - (offset.left || 0) - (offset.right || 0)) || "",
height: offset.height || (w.outerHeight() - (offset.top || 0) - (offset.bottom || 0)) || ""
});
layout.element.on("__resize__", function () {
w.is(":visible") &&
layout.element.css({
function getComputedPosition() {
var css = {
left: w.offset().left + (offset.left || 0),
top: w.offset().top + (offset.top || 0),
width: offset.width || (w.outerWidth() - (offset.left || 0) - (offset.right || 0)) || "",
height: offset.height || (w.outerHeight() - (offset.top || 0) - (offset.bottom || 0)) || ""
});
};
const { top, left, scaleY, scaleX } = BI.DOM.getPositionRelativeContainingBlockRect(layout.element[0]);
css.top = (css.top - top) / scaleY;
css.left = (css.left - left) / scaleX;
return css;
}
layout.element.css(getComputedPosition());
layout.element.on("__resize__", function () {
w.is(":visible") &&
layout.element.css(getComputedPosition());
});
}
this.add(name, widget, layout);

3474
src/core/controller/popper.js

File diff suppressed because it is too large Load Diff

111
src/core/platform/web/dom.js

@ -249,12 +249,14 @@
},
_getLeftAlignPosition: function (combo, popup, extraWidth, container) {
var viewBounds = popup.element.bounds(),
windowBounds = BI.Widget._renderEngine.createElement("body").bounds();
var left = combo.element.offset().left - (container ? container.getBoundingClientRect().left : 0) + extraWidth;
var comboRect = combo.element[0].getBoundingClientRect(),
popupRect = popup.element[0].getBoundingClientRect(),
viewportRect = document.documentElement.getBoundingClientRect(),
containerRect = container ? container.getBoundingClientRect() : { left: 0 };
var left = comboRect.left - containerRect.left + extraWidth;
if (left + viewBounds.width > windowBounds.width) {
left = windowBounds.width - viewBounds.width;
if (comboRect.left + popupRect.width > viewportRect.width) {
left = viewportRect.width - popupRect.width - containerRect.left;
}
return left;
},
@ -263,12 +265,13 @@
var left = this._getLeftAlignPosition(combo, popup, extraWidth, container);
var dir = "";
// 如果放不下,优先使用RightAlign, 如果RightAlign也放不下, 再使用left=0
if (left < 0) {
var containerRect = container ? container.getBoundingClientRect() : { left: 0 };
if (left + containerRect.left < 0) {
left = this._getRightAlignPosition(combo, popup, extraWidth);
dir = "left";
}
if (left < 0) {
left = 0;
if (left + containerRect.left < 0) {
left = 0 - containerRect.left;
}
return {
left: left,
@ -285,17 +288,19 @@
};
},
_getRightAlignPosition: function (combo, popup, extraWidth) {
var comboBounds = combo.element.bounds(), viewBounds = popup.element.bounds();
return combo.element.offset().left + comboBounds.width - viewBounds.width - extraWidth;
_getRightAlignPosition: function (combo, popup, extraWidth, container) {
var comboBounds = combo.element[0].getBoundingClientRect(),
viewBounds = popup.element[0].getBoundingClientRect(),
containerRect = container ? container.getBoundingClientRect() : { left: 0 };
return comboBounds.left + comboBounds.width - viewBounds.width - extraWidth - containerRect.left;
},
getRightAlignPosition: function (combo, popup, extraWidth) {
var left = this._getRightAlignPosition(combo, popup, extraWidth);
getRightAlignPosition: function (combo, popup, extraWidth, container) {
var left = this._getRightAlignPosition(combo, popup, extraWidth, container);
var dir = "";
// 如果放不下,优先使用LeftAlign, 如果LeftAlign也放不下, 再使用left=0
if (left < 0) {
left = this._getLeftAlignPosition(combo, popup, extraWidth);
left = this._getLeftAlignPosition(combo, popup, extraWidth, container);
dir = "right";
}
if (left < 0) {
@ -317,14 +322,13 @@
},
getTopAlignPosition: function (combo, popup, extraHeight, needAdaptHeight, container) {
var comboOffset = combo.element.offset();
var comboBounds = combo.element[0].getBoundingClientRect(),
popupBounds = popup.element[0].getBoundingClientRect(),
viewportBounds = document.documentElement.getBoundingClientRect(),
containerBounds = container ? container.getBoundingClientRect() : { top: 0 };
var top, adaptHeight, dir;
if (BI.DOM.isBottomSpaceEnough(combo, popup, -1 * comboBounds.height + extraHeight)) {
top = comboOffset.top - containerBounds.top + extraHeight;
top = comboBounds.top - containerBounds.top + extraHeight;
} else if (needAdaptHeight) {
top = comboBounds.top - containerBounds.top + extraHeight;
adaptHeight = viewportBounds.height - comboBounds.top;
@ -375,20 +379,19 @@
},
getBottomAlignPosition: function (combo, popup, extraHeight, needAdaptHeight, container) {
var comboOffset = combo.element.offset();
var comboBounds = combo.element[0].getBoundingClientRect(),
popupBounds = popup.element[0].getBoundingClientRect(),
windowBounds = BI.Widget._renderEngine.createElement("body").bounds(),
containerBounds = container ? container.getBoundingClientRect() : { top: 0 };
var top, adaptHeight, dir;
if (BI.DOM.isTopSpaceEnough(combo, popup, -1 * comboBounds.height + extraHeight)) {
top = comboOffset.top + comboBounds.height - containerBounds.top - popupBounds.height;
top = comboBounds.top + comboBounds.height - containerBounds.top - popupBounds.height;
} else if (needAdaptHeight) {
top = 0 - containerBounds.top;
adaptHeight = comboBounds.top + comboBounds.height - extraHeight;
} else if (BI.DOM.isBottomSpaceEnough(combo, popup, -1 * comboBounds.height + extraHeight)) {
// 上方空间不足且不允许调整高度的情况下,优先使用下对齐
top = comboOffset.top - containerBounds.top + extraHeight;
top = comboBounds.top - containerBounds.top + extraHeight;
dir = "bottom";
} else {
top = 0;
@ -410,16 +413,15 @@
},
getBottomAdaptPosition: function (combo, popup, extraHeight, needAdaptHeight) {
var comboOffset = combo.element.offset();
var comboBounds = combo.element.bounds(), popupBounds = popup.element.bounds(),
var comboBounds = combo.element[0].getBoundingClientRect(), popupBounds = popup.element[0].getBoundingClientRect(),
windowBounds = BI.Widget._renderEngine.createElement("body").bounds();
if (BI.DOM.isBottomSpaceEnough(combo, popup, extraHeight)) {
return BI.DOM.getBottomPosition(combo, popup, extraHeight);
}
if (needAdaptHeight) {
return {
top: comboOffset.top + comboBounds.height + extraHeight,
adaptHeight: windowBounds.height - comboOffset.top - comboBounds.height - extraHeight
top: comboBounds.top + comboBounds.height + extraHeight,
adaptHeight: windowBounds.height - comboBounds.top - comboBounds.height - extraHeight
};
}
if (popupBounds.height + extraHeight > windowBounds.height) {
@ -433,17 +435,18 @@
};
},
getCenterAdaptPosition: function (combo, popup) {
var comboOffset = combo.element.offset();
var comboBounds = combo.element.bounds(), popupBounds = popup.element.bounds(),
windowBounds = BI.Widget._renderEngine.createElement("body").bounds();
getCenterAdaptPosition: function (combo, popup, positionRelativeElement) {
var comboRect = combo.element[0].getBoundingClientRect(),
popupRect = popup.element[0].getBoundingClientRect(),
positionRelativeElementRect = positionRelativeElement.getBoundingClientRect(),
viewportBounds = document.documentElement.getBoundingClientRect();
var left;
if (comboOffset.left + comboBounds.width / 2 + popupBounds.width / 2 > windowBounds.width) {
left = windowBounds.width - popupBounds.width;
if (comboRect.left + comboRect.width / 2 + popupRect.width / 2 > viewportBounds.width) {
left = viewportBounds.width - comboRect.width - positionRelativeElementRect.left;
} else {
left = comboOffset.left + comboBounds.width / 2 - popupBounds.width / 2;
left = comboRect.left + (comboRect.width - popupRect.width) / 2 - positionRelativeElementRect.left;
}
if (left < 0) {
if (left + positionRelativeElementRect.left < 0) {
left = 0;
}
return {
@ -451,17 +454,19 @@
};
},
getMiddleAdaptPosition: function (combo, popup) {
var comboOffset = combo.element.offset();
var comboBounds = combo.element.bounds(), popupBounds = popup.element.bounds(),
windowBounds = BI.Widget._renderEngine.createElement("body").bounds();
getMiddleAdaptPosition: function (combo, popup, positionRelativeElement) {
var comboRect = combo.element[0].getBoundingClientRect(),
popupRect = popup.element[0].getBoundingClientRect(),
positionRelativeElementRect = positionRelativeElement.getBoundingClientRect(),
viewportBounds = document.documentElement.getBoundingClientRect();
var top;
if (comboOffset.top + comboBounds.height / 2 + popupBounds.height / 2 > windowBounds.height) {
top = windowBounds.height - popupBounds.height;
if (comboRect.top + comboRect.height / 2 + popupRect.height / 2 > viewportBounds.height) {
top = viewportBounds.height - popupRect.height - positionRelativeElementRect.top;
} else {
top = comboOffset.top + comboBounds.height / 2 - popupBounds.height / 2;
top = comboRect.top + (comboRect.height - popupRect.height) / 2 - positionRelativeElementRect.top;
}
if (top < 0) {
if (top + positionRelativeElementRect.top < 0) {
top = 0;
}
return {
@ -674,32 +679,32 @@
getComboPosition: function (combo, popup, extraWidth, extraHeight, needAdaptHeight, directions, offsetStyle, positionRelativeElement) {
extraWidth || (extraWidth = 0);
extraHeight || (extraHeight = 0);
var bodyHeight = BI.Widget._renderEngine.createElement("body").bounds().height - extraHeight;
var maxHeight = Math.min(popup.attr("maxHeight") || bodyHeight, bodyHeight);
var viewportBounds = document.documentElement.getBoundingClientRect();
var maxHeight = Math.min(popup.attr("maxHeight") || viewportBounds.height, viewportBounds.height);
popup.resetHeight && popup.resetHeight(maxHeight);
var position = BI.DOM.getComboPositionByDirections(combo, popup, extraWidth, extraHeight, needAdaptHeight, directions || ["bottom", "top", "right", "left"], positionRelativeElement);
switch (offsetStyle) {
case "center":
if (position.change) {
var p = BI.DOM.getMiddleAdaptPosition(combo, popup);
var p = BI.DOM.getMiddleAdaptPosition(combo, popup, positionRelativeElement);
position.top = p.top;
} else {
var p = BI.DOM.getCenterAdaptPosition(combo, popup);
var p = BI.DOM.getCenterAdaptPosition(combo, popup, positionRelativeElement);
position.left = p.left;
}
break;
case "middle":
if (position.change) {
var p = BI.DOM.getCenterAdaptPosition(combo, popup);
var p = BI.DOM.getCenterAdaptPosition(combo, popup, positionRelativeElement);
position.left = p.left;
} else {
var p = BI.DOM.getMiddleAdaptPosition(combo, popup);
var p = BI.DOM.getMiddleAdaptPosition(combo, popup, positionRelativeElement);
position.top = p.top;
}
break;
}
if (needAdaptHeight === true) {
popup.resetHeight && popup.resetHeight(Math.min(bodyHeight - position.top + (positionRelativeElement ? positionRelativeElement.getBoundingClientRect().top : 0), maxHeight));
popup.resetHeight && popup.resetHeight(Math.min(viewportBounds.height - position.top + (positionRelativeElement ? positionRelativeElement.getBoundingClientRect().top : 0), maxHeight));
}
return position;
},
@ -729,5 +734,19 @@
return BI.DOM.getPositionRelativeContainingBlock(element.parentNode);
},
/**
* 获取position:fixed相对定位的元素的clientRect
*/
getPositionRelativeContainingBlockRect: function (element) {
var positionRelativeElement = BI.DOM.getPositionRelativeContainingBlock(element);
var rect = positionRelativeElement.getBoundingClientRect();
return {
...rect.toJSON(),
scaleX: rect.width / positionRelativeElement.offsetWidth,
scaleY: rect.height / positionRelativeElement.offsetHeight
};
},
});
})();

3
src/core/platform/web/function.js

@ -140,8 +140,9 @@ BI._.extend(BI, {
},
getMinimumFontSize: function () {
// not work for firefox
const el = document.createElement('div');
el.style.fontSize = "0px";
el.style.fontSize = "1px";
document.body.appendChild(el);
const size = getComputedStyle(el).fontSize;
el.remove();

48
src/widget/numbereditor/number.editor.js

@ -18,7 +18,8 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
errorText: "",
step: 1,
min: BI.MIN,
max: BI.MAX
max: BI.MAX,
watermark: "",
});
},
@ -30,6 +31,7 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
height: BI.toPix(o.height, 2),
simple: o.simple,
allowBlank: o.allowBlank,
watermark: o.watermark,
value: o.valueFormatter(o.value),
validationChecker: function (v) {
// 不设置validationChecker就自动检测
@ -89,23 +91,27 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
type: "bi.htape",
height: BI.toPix(o.height, 2),
element: this,
items: [this.editor, {
el: {
type: "bi.grid",
columns: 1,
rows: 2,
items: [{
column: 0,
row: 0,
el: this.topBtn
}, {
column: 0,
row: 1,
el: this.bottomBtn
}]
},
width: 23
}]
items: [
this.editor, {
el: {
type: "bi.grid",
columns: 1,
rows: 2,
items: [
{
column: 0,
row: 0,
el: this.topBtn
}, {
column: 0,
row: 1,
el: this.bottomBtn
}
]
},
width: 23
}
]
});
},
@ -117,13 +123,13 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
return this.editor.isEditing();
},
_checkValueInRange: function(v) {
_checkValueInRange: function (v) {
var o = this.options;
return !!(BI.isNumeric(v) && BI.parseFloat(v) >= o.min && BI.parseFloat(v) <= o.max);
},
_checkAdjustDisabled: function(v) {
if(this.options.validationChecker === BI.emptyFn) {
_checkAdjustDisabled: function (v) {
if (this.options.validationChecker === BI.emptyFn) {
this.bottomBtn.setEnable(BI.parseFloat(v) > this.options.min);
this.topBtn.setEnable(BI.parseFloat(v) < this.options.max);
}

Loading…
Cancel
Save