@leafer-in/position 2.3.2 → 2.3.4
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/dist/position.cjs +60 -26
- package/dist/position.esm.js +61 -27
- package/dist/position.esm.min.js +1 -1
- package/dist/position.esm.min.js.map +1 -1
- package/dist/position.js +59 -26
- package/dist/position.min.cjs +1 -1
- package/dist/position.min.cjs.map +1 -1
- package/dist/position.min.js +1 -1
- package/dist/position.min.js.map +1 -1
- package/package.json +5 -5
- package/src/decorate.ts +10 -2
- package/src/index.ts +70 -28
package/dist/position.cjs
CHANGED
|
@@ -12,7 +12,15 @@ function positionType(defaultValue) {
|
|
|
12
12
|
return draw.decorateLeafAttr(defaultValue, key => draw.attr({
|
|
13
13
|
set(value) {
|
|
14
14
|
if (this.__setAttr(key, value)) {
|
|
15
|
-
if (value)
|
|
15
|
+
if (value) {
|
|
16
|
+
if (value.id) {
|
|
17
|
+
const data = this.__;
|
|
18
|
+
if (!data.__usePositionNode) {
|
|
19
|
+
data.__usePositionNode = true;
|
|
20
|
+
this.__updatePositionLayout = this.__updatePositionLayout.bind(this);
|
|
21
|
+
}
|
|
22
|
+
} else this.waitParentChange(positionParentChange);
|
|
23
|
+
}
|
|
16
24
|
draw.doBoundsType(this);
|
|
17
25
|
}
|
|
18
26
|
}
|
|
@@ -26,46 +34,72 @@ draw.UI.addAttr("position", false, positionType);
|
|
|
26
34
|
const tempPoint = draw.getPointData();
|
|
27
35
|
|
|
28
36
|
draw.UI.prototype.__updatePositionLayout = function() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
const {leaferIsCreated: leaferIsCreated, position: position, positionNode: positionNode, boxBounds: boxBounds, parent: parent} = this, {width: width, height: height} = boxBounds;
|
|
38
|
+
let parentBox = parent.boxBounds, align, sizeChanged;
|
|
39
|
+
if (positionNode) {
|
|
40
|
+
if (!positionNode.parent || positionNode.destroyed) return false;
|
|
41
|
+
this.__extraUpdate();
|
|
42
|
+
}
|
|
32
43
|
if (leaferIsCreated) this.leafer.created = false;
|
|
33
44
|
if (draw.isString(position)) {
|
|
34
|
-
|
|
35
|
-
this.set(tempPoint);
|
|
45
|
+
align = position;
|
|
36
46
|
} else {
|
|
37
47
|
let {left: left, top: top, right: right, bottom: bottom} = position;
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
if (positionNode) parentBox = positionNode.getBounds("box", positionNode.parent === parent ? "local" : parent);
|
|
49
|
+
if (position.align) {
|
|
50
|
+
align = position.align;
|
|
51
|
+
} else {
|
|
52
|
+
const {x: parentX, y: parentY, width: parentWidth, height: parentHeight} = parentBox;
|
|
53
|
+
const hasLeft = !draw.isUndefined(left), hasTop = !draw.isUndefined(top);
|
|
54
|
+
if (hasLeft) {
|
|
55
|
+
left = draw.UnitConvert.number(left, parentWidth);
|
|
56
|
+
this.x = parentX + left;
|
|
57
|
+
}
|
|
58
|
+
if (!draw.isUndefined(right)) {
|
|
59
|
+
right = draw.UnitConvert.number(right, parentWidth);
|
|
60
|
+
if (hasLeft) this.resizeWidth(parentWidth - left - right), sizeChanged = true; else this.x = parentX + parentWidth - width - right;
|
|
61
|
+
}
|
|
62
|
+
if (hasTop) {
|
|
63
|
+
top = draw.UnitConvert.number(top, parentHeight);
|
|
64
|
+
this.y = parentY + top;
|
|
65
|
+
}
|
|
66
|
+
if (!draw.isUndefined(bottom)) {
|
|
67
|
+
bottom = draw.UnitConvert.number(bottom, parentHeight);
|
|
68
|
+
if (position.top !== undefined) this.resizeHeight(parentHeight - top - bottom),
|
|
69
|
+
sizeChanged = true; else this.y = parentY + parentHeight - height - bottom;
|
|
70
|
+
}
|
|
55
71
|
}
|
|
56
72
|
}
|
|
73
|
+
if (align) {
|
|
74
|
+
draw.AlignHelper.toPoint(align, boxBounds, parentBox, tempPoint, false);
|
|
75
|
+
this.set(tempPoint);
|
|
76
|
+
}
|
|
57
77
|
if (leaferIsCreated) this.leafer.created = true;
|
|
78
|
+
draw.LeafHelper.updateAllMatrix(this);
|
|
79
|
+
this.isBranch ? draw.BranchHelper.updateBounds(this) : draw.LeafHelper.updateBounds(this);
|
|
58
80
|
return sizeChanged;
|
|
59
81
|
};
|
|
60
82
|
|
|
83
|
+
draw.LeafHelper.listenPositionNode = function(leaf) {
|
|
84
|
+
const {position: position, positionNode: positionNode} = leaf;
|
|
85
|
+
if (draw.isObject(position) && position.id) leaf.positionNode = draw.isString(position.id) ? leaf.app.findId(position.id) : position.id; else if (leaf.positionNode) leaf.positionNode = undefined;
|
|
86
|
+
if (positionNode !== leaf.positionNode) {
|
|
87
|
+
if (positionNode) positionNode.off(positionNode.parent === leaf.parent ? draw.BoundsEvent.LOCAL : draw.BoundsEvent.WORLD, leaf.__updatePositionLayout);
|
|
88
|
+
if (leaf.positionNode) {
|
|
89
|
+
leaf.positionNode.on(leaf.positionNode.parent === leaf.parent ? draw.BoundsEvent.LOCAL : draw.BoundsEvent.WORLD, leaf.__updatePositionLayout);
|
|
90
|
+
draw.LeafHelper.updateBounds(leaf.positionNode);
|
|
91
|
+
}
|
|
92
|
+
leaf.__updatePositionLayout();
|
|
93
|
+
if (!leaf.positionNode) leaf.__.__usePositionNode = undefined;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
61
97
|
draw.LeafHelper.updatePositionLayout = function(leaf) {
|
|
62
98
|
let hasPosition;
|
|
63
99
|
leaf.children.forEach(item => {
|
|
64
|
-
if (item.position) {
|
|
100
|
+
if (item.position && !item.position.id) {
|
|
65
101
|
hasPosition = true;
|
|
66
102
|
item.__updatePositionLayout();
|
|
67
|
-
draw.LeafHelper.updateAllMatrix(item);
|
|
68
|
-
item.isBranch ? draw.BranchHelper.updateBounds(item) : draw.LeafHelper.updateBounds(item);
|
|
69
103
|
}
|
|
70
104
|
});
|
|
71
105
|
leaf.__hasPosition = hasPosition;
|
package/dist/position.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { decorateLeafAttr, attr, doBoundsType, Plugin, UI, getPointData, isString,
|
|
1
|
+
import { decorateLeafAttr, attr, doBoundsType, Plugin, UI, getPointData, isString, isUndefined, UnitConvert, AlignHelper, LeafHelper, BranchHelper, isObject, BoundsEvent } from "@leafer-ui/draw";
|
|
2
2
|
|
|
3
3
|
import "@leafer-in/resize";
|
|
4
4
|
|
|
@@ -10,7 +10,15 @@ function positionType(defaultValue) {
|
|
|
10
10
|
return decorateLeafAttr(defaultValue, key => attr({
|
|
11
11
|
set(value) {
|
|
12
12
|
if (this.__setAttr(key, value)) {
|
|
13
|
-
if (value)
|
|
13
|
+
if (value) {
|
|
14
|
+
if (value.id) {
|
|
15
|
+
const data = this.__;
|
|
16
|
+
if (!data.__usePositionNode) {
|
|
17
|
+
data.__usePositionNode = true;
|
|
18
|
+
this.__updatePositionLayout = this.__updatePositionLayout.bind(this);
|
|
19
|
+
}
|
|
20
|
+
} else this.waitParentChange(positionParentChange);
|
|
21
|
+
}
|
|
14
22
|
doBoundsType(this);
|
|
15
23
|
}
|
|
16
24
|
}
|
|
@@ -24,46 +32,72 @@ UI.addAttr("position", false, positionType);
|
|
|
24
32
|
const tempPoint = getPointData();
|
|
25
33
|
|
|
26
34
|
UI.prototype.__updatePositionLayout = function() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
const {leaferIsCreated: leaferIsCreated, position: position, positionNode: positionNode, boxBounds: boxBounds, parent: parent} = this, {width: width, height: height} = boxBounds;
|
|
36
|
+
let parentBox = parent.boxBounds, align, sizeChanged;
|
|
37
|
+
if (positionNode) {
|
|
38
|
+
if (!positionNode.parent || positionNode.destroyed) return false;
|
|
39
|
+
this.__extraUpdate();
|
|
40
|
+
}
|
|
30
41
|
if (leaferIsCreated) this.leafer.created = false;
|
|
31
42
|
if (isString(position)) {
|
|
32
|
-
|
|
33
|
-
this.set(tempPoint);
|
|
43
|
+
align = position;
|
|
34
44
|
} else {
|
|
35
45
|
let {left: left, top: top, right: right, bottom: bottom} = position;
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
if (positionNode) parentBox = positionNode.getBounds("box", positionNode.parent === parent ? "local" : parent);
|
|
47
|
+
if (position.align) {
|
|
48
|
+
align = position.align;
|
|
49
|
+
} else {
|
|
50
|
+
const {x: parentX, y: parentY, width: parentWidth, height: parentHeight} = parentBox;
|
|
51
|
+
const hasLeft = !isUndefined(left), hasTop = !isUndefined(top);
|
|
52
|
+
if (hasLeft) {
|
|
53
|
+
left = UnitConvert.number(left, parentWidth);
|
|
54
|
+
this.x = parentX + left;
|
|
55
|
+
}
|
|
56
|
+
if (!isUndefined(right)) {
|
|
57
|
+
right = UnitConvert.number(right, parentWidth);
|
|
58
|
+
if (hasLeft) this.resizeWidth(parentWidth - left - right), sizeChanged = true; else this.x = parentX + parentWidth - width - right;
|
|
59
|
+
}
|
|
60
|
+
if (hasTop) {
|
|
61
|
+
top = UnitConvert.number(top, parentHeight);
|
|
62
|
+
this.y = parentY + top;
|
|
63
|
+
}
|
|
64
|
+
if (!isUndefined(bottom)) {
|
|
65
|
+
bottom = UnitConvert.number(bottom, parentHeight);
|
|
66
|
+
if (position.top !== undefined) this.resizeHeight(parentHeight - top - bottom),
|
|
67
|
+
sizeChanged = true; else this.y = parentY + parentHeight - height - bottom;
|
|
68
|
+
}
|
|
53
69
|
}
|
|
54
70
|
}
|
|
71
|
+
if (align) {
|
|
72
|
+
AlignHelper.toPoint(align, boxBounds, parentBox, tempPoint, false);
|
|
73
|
+
this.set(tempPoint);
|
|
74
|
+
}
|
|
55
75
|
if (leaferIsCreated) this.leafer.created = true;
|
|
76
|
+
LeafHelper.updateAllMatrix(this);
|
|
77
|
+
this.isBranch ? BranchHelper.updateBounds(this) : LeafHelper.updateBounds(this);
|
|
56
78
|
return sizeChanged;
|
|
57
79
|
};
|
|
58
80
|
|
|
81
|
+
LeafHelper.listenPositionNode = function(leaf) {
|
|
82
|
+
const {position: position, positionNode: positionNode} = leaf;
|
|
83
|
+
if (isObject(position) && position.id) leaf.positionNode = isString(position.id) ? leaf.app.findId(position.id) : position.id; else if (leaf.positionNode) leaf.positionNode = undefined;
|
|
84
|
+
if (positionNode !== leaf.positionNode) {
|
|
85
|
+
if (positionNode) positionNode.off(positionNode.parent === leaf.parent ? BoundsEvent.LOCAL : BoundsEvent.WORLD, leaf.__updatePositionLayout);
|
|
86
|
+
if (leaf.positionNode) {
|
|
87
|
+
leaf.positionNode.on(leaf.positionNode.parent === leaf.parent ? BoundsEvent.LOCAL : BoundsEvent.WORLD, leaf.__updatePositionLayout);
|
|
88
|
+
LeafHelper.updateBounds(leaf.positionNode);
|
|
89
|
+
}
|
|
90
|
+
leaf.__updatePositionLayout();
|
|
91
|
+
if (!leaf.positionNode) leaf.__.__usePositionNode = undefined;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
59
95
|
LeafHelper.updatePositionLayout = function(leaf) {
|
|
60
96
|
let hasPosition;
|
|
61
97
|
leaf.children.forEach(item => {
|
|
62
|
-
if (item.position) {
|
|
98
|
+
if (item.position && !item.position.id) {
|
|
63
99
|
hasPosition = true;
|
|
64
100
|
item.__updatePositionLayout();
|
|
65
|
-
LeafHelper.updateAllMatrix(item);
|
|
66
|
-
item.isBranch ? BranchHelper.updateBounds(item) : LeafHelper.updateBounds(item);
|
|
67
101
|
}
|
|
68
102
|
});
|
|
69
103
|
leaf.__hasPosition = hasPosition;
|
package/dist/position.esm.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{decorateLeafAttr as t,attr as i,doBoundsType as
|
|
1
|
+
import{decorateLeafAttr as t,attr as i,doBoundsType as o,Plugin as e,UI as s,getPointData as n,isString as d,isUndefined as a,UnitConvert as p,AlignHelper as r,LeafHelper as u,BranchHelper as h,isObject as _,BoundsEvent as f}from"@leafer-ui/draw";import"@leafer-in/resize";function l(t){t.__hasPosition=!0}e.add("position","resize"),s.addAttr("position",!1,function(e){return t(e,t=>i({set(i){if(this.__setAttr(t,i)){if(i)if(i.id){const t=this.__;t.__usePositionNode||(t.__usePositionNode=!0,this.__updatePositionLayout=this.__updatePositionLayout.bind(this))}else this.waitParentChange(l);o(this)}}}))});const c=n();s.prototype.__updatePositionLayout=function(){const{leaferIsCreated:t,position:i,positionNode:o,boxBounds:e,parent:s}=this,{width:n,height:_}=e;let f,l,P=s.boxBounds;if(o){if(!o.parent||o.destroyed)return!1;this.__extraUpdate()}if(t&&(this.leafer.created=!1),d(i))f=i;else{let{left:t,top:e,right:d,bottom:r}=i;if(o&&(P=o.getBounds("box",o.parent===s?"local":s)),i.align)f=i.align;else{const{x:o,y:s,width:u,height:h}=P,f=!a(t),c=!a(e);f&&(t=p.number(t,u),this.x=o+t),a(d)||(d=p.number(d,u),f?(this.resizeWidth(u-t-d),l=!0):this.x=o+u-n-d),c&&(e=p.number(e,h),this.y=s+e),a(r)||(r=p.number(r,h),void 0!==i.top?(this.resizeHeight(h-e-r),l=!0):this.y=s+h-_-r)}}return f&&(r.toPoint(f,e,P,c,!1),this.set(c)),t&&(this.leafer.created=!0),u.updateAllMatrix(this),this.isBranch?h.updateBounds(this):u.updateBounds(this),l},u.listenPositionNode=function(t){const{position:i,positionNode:o}=t;_(i)&&i.id?t.positionNode=d(i.id)?t.app.findId(i.id):i.id:t.positionNode&&(t.positionNode=void 0),o!==t.positionNode&&(o&&o.off(o.parent===t.parent?f.LOCAL:f.WORLD,t.__updatePositionLayout),t.positionNode&&(t.positionNode.on(t.positionNode.parent===t.parent?f.LOCAL:f.WORLD,t.__updatePositionLayout),u.updateBounds(t.positionNode)),t.__updatePositionLayout(),t.positionNode||(t.__.__usePositionNode=void 0))},u.updatePositionLayout=function(t){let i;t.children.forEach(t=>{t.position&&!t.position.id&&(i=!0,t.__updatePositionLayout())}),t.__hasPosition=i};
|
|
2
2
|
//# sourceMappingURL=position.esm.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"position.esm.min.js","sources":["../../../../../../src/in/packages/position/src/decorate.ts","../../../../../../src/in/packages/position/src/index.ts"],"sourcesContent":["import { attr, decorateLeafAttr, doBoundsType } from '@leafer-ui/draw'\nimport { ILeaf, IValue } from '@leafer/interface'\n\n\nfunction positionParentChange(parent: ILeaf) {\n parent.__hasPosition = true\n}\n\nexport function positionType(defaultValue?: IValue) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: IValue) {\n if (this.__setAttr(key, value)) {\n if (value) this.waitParentChange(positionParentChange)\n doBoundsType(this)\n }\n }\n }))\n}","import { UI, Plugin, UnitConvert, isUndefined, LeafHelper, BranchHelper, isString, AlignHelper, getPointData } from '@leafer-ui/draw'\n\nimport '@leafer-in/resize'\n\nimport { positionType } from './decorate'\n\n\nPlugin.add('position', 'resize')\n\n\n// addAttr\nUI.addAttr('position', false, positionType)\n\n\nconst tempPoint = getPointData()\n\nUI.prototype.__updatePositionLayout = function (): boolean {\n\n
|
|
1
|
+
{"version":3,"file":"position.esm.min.js","sources":["../../../../../../src/in/packages/position/src/decorate.ts","../../../../../../src/in/packages/position/src/index.ts"],"sourcesContent":["import { attr, decorateLeafAttr, doBoundsType } from '@leafer-ui/draw'\nimport { ILeaf, IValue, IInset } from '@leafer-ui/interface'\n\n\nfunction positionParentChange(parent: ILeaf) {\n parent.__hasPosition = true\n}\n\nexport function positionType(defaultValue?: IValue) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: IValue) {\n if (this.__setAttr(key, value)) {\n if (value) {\n if ((value as IInset).id) {\n const data = this.__\n if (!data.__usePositionNode) {\n data.__usePositionNode = true\n this.__updatePositionLayout = this.__updatePositionLayout.bind(this)\n }\n } else this.waitParentChange(positionParentChange)\n }\n doBoundsType(this)\n }\n }\n }))\n}","import { IDirection, IInset } from '@leafer-ui/interface'\nimport { UI, Plugin, UnitConvert, isUndefined, LeafHelper, BranchHelper, isString, AlignHelper, getPointData, isObject, BoundsEvent } from '@leafer-ui/draw'\n\nimport '@leafer-in/resize'\n\nimport { positionType } from './decorate'\n\n\nPlugin.add('position', 'resize')\n\n\n// addAttr\nUI.addAttr('position', false, positionType)\n\n\nconst tempPoint = getPointData()\n\nUI.prototype.__updatePositionLayout = function (): boolean {\n\n const { leaferIsCreated, position, positionNode, boxBounds, parent } = this, { width, height } = boxBounds\n let parentBox = parent.boxBounds, align: IDirection, sizeChanged: boolean\n\n if (positionNode) {\n if (!positionNode.parent || positionNode.destroyed) return false\n this.__extraUpdate()\n }\n\n if (leaferIsCreated) this.leafer.created = false // 拦截布局更新通知,进行手动更新布局\n\n if (isString(position)) {\n\n align = position\n\n } else {\n\n let { left, top, right, bottom } = position\n\n if (positionNode) parentBox = positionNode.getBounds('box', positionNode.parent === parent ? 'local' : parent)\n\n if (position.align) {\n\n align = position.align\n\n } else {\n\n const { x: parentX, y: parentY, width: parentWidth, height: parentHeight } = parentBox\n\n const hasLeft = !isUndefined(left), hasTop = !isUndefined(top)\n\n // 布局\n if (hasLeft) {\n left = UnitConvert.number(left, parentWidth)\n this.x = parentX + left\n }\n\n if (!isUndefined(right)) {\n right = UnitConvert.number(right, parentWidth)\n\n if (hasLeft) this.resizeWidth(parentWidth - (left as number) - right), sizeChanged = true\n else this.x = parentX + parentWidth - width - right\n\n }\n\n if (hasTop) {\n top = UnitConvert.number(top, parentHeight)\n this.y = parentY + top\n }\n\n if (!isUndefined(bottom)) {\n bottom = UnitConvert.number(bottom, parentHeight)\n\n if (position.top !== undefined) this.resizeHeight(parentHeight - (top as number) - bottom), sizeChanged = true\n else this.y = parentY + parentHeight - height - bottom\n }\n }\n\n }\n\n if (align) {\n AlignHelper.toPoint(align, boxBounds, parentBox, tempPoint, false)\n this.set(tempPoint)\n }\n\n if (leaferIsCreated) this.leafer.created = true\n\n LeafHelper.updateAllMatrix(this)\n this.isBranch ? BranchHelper.updateBounds(this) : LeafHelper.updateBounds(this)\n\n return sizeChanged\n}\n\n// 监听相对元素\nLeafHelper.listenPositionNode = function (leaf: UI): void {\n const { position, positionNode } = leaf\n\n if (isObject(position) && position.id) leaf.positionNode = isString(position.id) ? leaf.app.findId(position.id) : position.id\n else if (leaf.positionNode) leaf.positionNode = undefined\n\n if (positionNode !== leaf.positionNode) {\n if (positionNode) positionNode.off(positionNode.parent === leaf.parent ? BoundsEvent.LOCAL : BoundsEvent.WORLD, leaf.__updatePositionLayout) // leaf.__updatePositionLayout 在属性装饰器中已经绑定\n if (leaf.positionNode) {\n leaf.positionNode.on(leaf.positionNode.parent === leaf.parent ? BoundsEvent.LOCAL : BoundsEvent.WORLD, leaf.__updatePositionLayout)\n LeafHelper.updateBounds(leaf.positionNode)\n }\n leaf.__updatePositionLayout()\n if (!leaf.positionNode) leaf.__.__usePositionNode = undefined\n }\n}\n\n// 更新子级\nLeafHelper.updatePositionLayout = function (leaf: UI): void {\n let hasPosition\n leaf.children.forEach(item => {\n if (item.position && !(item.position as IInset).id) {\n hasPosition = true\n item.__updatePositionLayout()\n }\n })\n leaf.__hasPosition = hasPosition\n}\n"],"names":["positionParentChange","parent","__hasPosition","Plugin","add","UI","addAttr","defaultValue","decorateLeafAttr","key","attr","set","value","this","__setAttr","id","data","__","__usePositionNode","__updatePositionLayout","bind","waitParentChange","doBoundsType","tempPoint","getPointData","prototype","leaferIsCreated","position","positionNode","boxBounds","width","height","align","sizeChanged","parentBox","destroyed","__extraUpdate","leafer","created","isString","left","top","right","bottom","getBounds","x","parentX","y","parentY","parentWidth","parentHeight","hasLeft","isUndefined","hasTop","UnitConvert","number","resizeWidth","undefined","resizeHeight","AlignHelper","toPoint","LeafHelper","updateAllMatrix","isBranch","BranchHelper","updateBounds","listenPositionNode","leaf","isObject","app","findId","off","BoundsEvent","LOCAL","WORLD","on","updatePositionLayout","hasPosition","children","forEach","item"],"mappings":"iRAIA,SAASA,EAAqBC,GAC1BA,EAAOC,eAAgB,CAC3B,CCEAC,EAAOC,IAAI,WAAY,UAIvBC,EAAGC,QAAQ,YAAY,EDJjB,SAAuBC,GACzB,OAAOC,EAAiBD,EAAeE,GAAgBC,EAAK,CACxD,GAAAC,CAAIC,GACA,GAAIC,KAAKC,UAAUL,EAAKG,GAAQ,CAC5B,GAAIA,EACA,GAAKA,EAAiBG,GAAI,CACtB,MAAMC,EAAOH,KAAKI,GACbD,EAAKE,oBACNF,EAAKE,mBAAoB,EACzBL,KAAKM,uBAAyBN,KAAKM,uBAAuBC,KAAKP,MAEvE,MAAOA,KAAKQ,iBAAiBrB,GAEjCsB,EAAaT,KACjB,CACJ,IAER,GCVA,MAAMU,EAAYC,IAElBnB,EAAGoB,UAAUN,uBAAyB,WAElC,MAAMO,gBAAEA,EAAeC,SAAEA,EAAQC,aAAEA,EAAYC,UAAEA,EAAS5B,OAAEA,GAAWY,MAAMiB,MAAEA,EAAKC,OAAEA,GAAWF,EACjG,IAAkCG,EAAmBC,EAAjDC,EAAYjC,EAAO4B,UAEvB,GAAID,EAAc,CACd,IAAKA,EAAa3B,QAAU2B,EAAaO,UAAW,OAAO,EAC3DtB,KAAKuB,eACT,CAIA,GAFIV,IAAiBb,KAAKwB,OAAOC,SAAU,GAEvCC,EAASZ,GAETK,EAAQL,MAEL,CAEH,IAAIa,KAAEA,EAAIC,IAAEA,EAAGC,MAAEA,EAAKC,OAAEA,GAAWhB,EAInC,GAFIC,IAAcM,EAAYN,EAAagB,UAAU,MAAOhB,EAAa3B,SAAWA,EAAS,QAAUA,IAEnG0B,EAASK,MAETA,EAAQL,EAASK,UAEd,CAEH,MAAQa,EAAGC,EAASC,EAAGC,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AAKvC,aAAa3B,SAAWkE,EAAKlE,OAASuE,EAAYC,MAAQD,EAAYE,MAAOP,EAAKhD,wBAC5G0C,EAAWI,aAAaE,EAAKvC,eAEjCuC,EAAKhD,yBACAgD,EAAKvC,eAAcuC,EAAKlD,GAAGC,uBAAoBuC,GAE5D,EAGAI,EAAWe,qBAAuB,SAAUT,GACxC,IAAIU,EACJV,EAAKW,SAASC,QAAQC,IACdA,EAAKrD,WAAcqD,EAAKrD,SAAoBZ,KAC5C8D,GAAc,EACdG,EAAK7D,4BAGbgD,EAAKjE,cAAgB2E,CACzB"}
|
package/dist/position.js
CHANGED
|
@@ -7,7 +7,15 @@
|
|
|
7
7
|
return draw.decorateLeafAttr(defaultValue, key => draw.attr({
|
|
8
8
|
set(value) {
|
|
9
9
|
if (this.__setAttr(key, value)) {
|
|
10
|
-
if (value)
|
|
10
|
+
if (value) {
|
|
11
|
+
if (value.id) {
|
|
12
|
+
const data = this.__;
|
|
13
|
+
if (!data.__usePositionNode) {
|
|
14
|
+
data.__usePositionNode = true;
|
|
15
|
+
this.__updatePositionLayout = this.__updatePositionLayout.bind(this);
|
|
16
|
+
}
|
|
17
|
+
} else this.waitParentChange(positionParentChange);
|
|
18
|
+
}
|
|
11
19
|
draw.doBoundsType(this);
|
|
12
20
|
}
|
|
13
21
|
}
|
|
@@ -17,45 +25,70 @@
|
|
|
17
25
|
draw.UI.addAttr("position", false, positionType);
|
|
18
26
|
const tempPoint = draw.getPointData();
|
|
19
27
|
draw.UI.prototype.__updatePositionLayout = function() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
const {leaferIsCreated: leaferIsCreated, position: position, positionNode: positionNode, boxBounds: boxBounds, parent: parent} = this, {width: width, height: height} = boxBounds;
|
|
29
|
+
let parentBox = parent.boxBounds, align, sizeChanged;
|
|
30
|
+
if (positionNode) {
|
|
31
|
+
if (!positionNode.parent || positionNode.destroyed) return false;
|
|
32
|
+
this.__extraUpdate();
|
|
33
|
+
}
|
|
23
34
|
if (leaferIsCreated) this.leafer.created = false;
|
|
24
35
|
if (draw.isString(position)) {
|
|
25
|
-
|
|
26
|
-
this.set(tempPoint);
|
|
36
|
+
align = position;
|
|
27
37
|
} else {
|
|
28
38
|
let {left: left, top: top, right: right, bottom: bottom} = position;
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
if (positionNode) parentBox = positionNode.getBounds("box", positionNode.parent === parent ? "local" : parent);
|
|
40
|
+
if (position.align) {
|
|
41
|
+
align = position.align;
|
|
42
|
+
} else {
|
|
43
|
+
const {x: parentX, y: parentY, width: parentWidth, height: parentHeight} = parentBox;
|
|
44
|
+
const hasLeft = !draw.isUndefined(left), hasTop = !draw.isUndefined(top);
|
|
45
|
+
if (hasLeft) {
|
|
46
|
+
left = draw.UnitConvert.number(left, parentWidth);
|
|
47
|
+
this.x = parentX + left;
|
|
48
|
+
}
|
|
49
|
+
if (!draw.isUndefined(right)) {
|
|
50
|
+
right = draw.UnitConvert.number(right, parentWidth);
|
|
51
|
+
if (hasLeft) this.resizeWidth(parentWidth - left - right), sizeChanged = true; else this.x = parentX + parentWidth - width - right;
|
|
52
|
+
}
|
|
53
|
+
if (hasTop) {
|
|
54
|
+
top = draw.UnitConvert.number(top, parentHeight);
|
|
55
|
+
this.y = parentY + top;
|
|
56
|
+
}
|
|
57
|
+
if (!draw.isUndefined(bottom)) {
|
|
58
|
+
bottom = draw.UnitConvert.number(bottom, parentHeight);
|
|
59
|
+
if (position.top !== undefined) this.resizeHeight(parentHeight - top - bottom),
|
|
60
|
+
sizeChanged = true; else this.y = parentY + parentHeight - height - bottom;
|
|
61
|
+
}
|
|
46
62
|
}
|
|
47
63
|
}
|
|
64
|
+
if (align) {
|
|
65
|
+
draw.AlignHelper.toPoint(align, boxBounds, parentBox, tempPoint, false);
|
|
66
|
+
this.set(tempPoint);
|
|
67
|
+
}
|
|
48
68
|
if (leaferIsCreated) this.leafer.created = true;
|
|
69
|
+
draw.LeafHelper.updateAllMatrix(this);
|
|
70
|
+
this.isBranch ? draw.BranchHelper.updateBounds(this) : draw.LeafHelper.updateBounds(this);
|
|
49
71
|
return sizeChanged;
|
|
50
72
|
};
|
|
73
|
+
draw.LeafHelper.listenPositionNode = function(leaf) {
|
|
74
|
+
const {position: position, positionNode: positionNode} = leaf;
|
|
75
|
+
if (draw.isObject(position) && position.id) leaf.positionNode = draw.isString(position.id) ? leaf.app.findId(position.id) : position.id; else if (leaf.positionNode) leaf.positionNode = undefined;
|
|
76
|
+
if (positionNode !== leaf.positionNode) {
|
|
77
|
+
if (positionNode) positionNode.off(positionNode.parent === leaf.parent ? draw.BoundsEvent.LOCAL : draw.BoundsEvent.WORLD, leaf.__updatePositionLayout);
|
|
78
|
+
if (leaf.positionNode) {
|
|
79
|
+
leaf.positionNode.on(leaf.positionNode.parent === leaf.parent ? draw.BoundsEvent.LOCAL : draw.BoundsEvent.WORLD, leaf.__updatePositionLayout);
|
|
80
|
+
draw.LeafHelper.updateBounds(leaf.positionNode);
|
|
81
|
+
}
|
|
82
|
+
leaf.__updatePositionLayout();
|
|
83
|
+
if (!leaf.positionNode) leaf.__.__usePositionNode = undefined;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
51
86
|
draw.LeafHelper.updatePositionLayout = function(leaf) {
|
|
52
87
|
let hasPosition;
|
|
53
88
|
leaf.children.forEach(item => {
|
|
54
|
-
if (item.position) {
|
|
89
|
+
if (item.position && !item.position.id) {
|
|
55
90
|
hasPosition = true;
|
|
56
91
|
item.__updatePositionLayout();
|
|
57
|
-
draw.LeafHelper.updateAllMatrix(item);
|
|
58
|
-
item.isBranch ? draw.BranchHelper.updateBounds(item) : draw.LeafHelper.updateBounds(item);
|
|
59
92
|
}
|
|
60
93
|
});
|
|
61
94
|
leaf.__hasPosition = hasPosition;
|
package/dist/position.min.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("@leafer-ui/draw");function
|
|
1
|
+
"use strict";var t=require("@leafer-ui/draw");function i(t){t.__hasPosition=!0}require("@leafer-in/resize"),t.Plugin.add("position","resize"),t.UI.addAttr("position",!1,function(e){return t.decorateLeafAttr(e,e=>t.attr({set(o){if(this.__setAttr(e,o)){if(o)if(o.id){const t=this.__;t.__usePositionNode||(t.__usePositionNode=!0,this.__updatePositionLayout=this.__updatePositionLayout.bind(this))}else this.waitParentChange(i);t.doBoundsType(this)}}}))});const e=t.getPointData();t.UI.prototype.__updatePositionLayout=function(){const{leaferIsCreated:i,position:o,positionNode:n,boxBounds:s,parent:d}=this,{width:a,height:r}=s;let p,u,h=d.boxBounds;if(n){if(!n.parent||n.destroyed)return!1;this.__extraUpdate()}if(i&&(this.leafer.created=!1),t.isString(o))p=o;else{let{left:i,top:e,right:s,bottom:f}=o;if(n&&(h=n.getBounds("box",n.parent===d?"local":d)),o.align)p=o.align;else{const{x:n,y:d,width:p,height:_}=h,l=!t.isUndefined(i),c=!t.isUndefined(e);l&&(i=t.UnitConvert.number(i,p),this.x=n+i),t.isUndefined(s)||(s=t.UnitConvert.number(s,p),l?(this.resizeWidth(p-i-s),u=!0):this.x=n+p-a-s),c&&(e=t.UnitConvert.number(e,_),this.y=d+e),t.isUndefined(f)||(f=t.UnitConvert.number(f,_),void 0!==o.top?(this.resizeHeight(_-e-f),u=!0):this.y=d+_-r-f)}}return p&&(t.AlignHelper.toPoint(p,s,h,e,!1),this.set(e)),i&&(this.leafer.created=!0),t.LeafHelper.updateAllMatrix(this),this.isBranch?t.BranchHelper.updateBounds(this):t.LeafHelper.updateBounds(this),u},t.LeafHelper.listenPositionNode=function(i){const{position:e,positionNode:o}=i;t.isObject(e)&&e.id?i.positionNode=t.isString(e.id)?i.app.findId(e.id):e.id:i.positionNode&&(i.positionNode=void 0),o!==i.positionNode&&(o&&o.off(o.parent===i.parent?t.BoundsEvent.LOCAL:t.BoundsEvent.WORLD,i.__updatePositionLayout),i.positionNode&&(i.positionNode.on(i.positionNode.parent===i.parent?t.BoundsEvent.LOCAL:t.BoundsEvent.WORLD,i.__updatePositionLayout),t.LeafHelper.updateBounds(i.positionNode)),i.__updatePositionLayout(),i.positionNode||(i.__.__usePositionNode=void 0))},t.LeafHelper.updatePositionLayout=function(t){let i;t.children.forEach(t=>{t.position&&!t.position.id&&(i=!0,t.__updatePositionLayout())}),t.__hasPosition=i};
|
|
2
2
|
//# sourceMappingURL=position.min.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"position.min.cjs","sources":["../../../../../../src/in/packages/position/src/decorate.ts","../../../../../../src/in/packages/position/src/index.ts"],"sourcesContent":["import { attr, decorateLeafAttr, doBoundsType } from '@leafer-ui/draw'\nimport { ILeaf, IValue } from '@leafer/interface'\n\n\nfunction positionParentChange(parent: ILeaf) {\n parent.__hasPosition = true\n}\n\nexport function positionType(defaultValue?: IValue) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: IValue) {\n if (this.__setAttr(key, value)) {\n if (value) this.waitParentChange(positionParentChange)\n doBoundsType(this)\n }\n }\n }))\n}","import { UI, Plugin, UnitConvert, isUndefined, LeafHelper, BranchHelper, isString, AlignHelper, getPointData } from '@leafer-ui/draw'\n\nimport '@leafer-in/resize'\n\nimport { positionType } from './decorate'\n\n\nPlugin.add('position', 'resize')\n\n\n// addAttr\nUI.addAttr('position', false, positionType)\n\n\nconst tempPoint = getPointData()\n\nUI.prototype.__updatePositionLayout = function (): boolean {\n\n
|
|
1
|
+
{"version":3,"file":"position.min.cjs","sources":["../../../../../../src/in/packages/position/src/decorate.ts","../../../../../../src/in/packages/position/src/index.ts"],"sourcesContent":["import { attr, decorateLeafAttr, doBoundsType } from '@leafer-ui/draw'\nimport { ILeaf, IValue, IInset } from '@leafer-ui/interface'\n\n\nfunction positionParentChange(parent: ILeaf) {\n parent.__hasPosition = true\n}\n\nexport function positionType(defaultValue?: IValue) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: IValue) {\n if (this.__setAttr(key, value)) {\n if (value) {\n if ((value as IInset).id) {\n const data = this.__\n if (!data.__usePositionNode) {\n data.__usePositionNode = true\n this.__updatePositionLayout = this.__updatePositionLayout.bind(this)\n }\n } else this.waitParentChange(positionParentChange)\n }\n doBoundsType(this)\n }\n }\n }))\n}","import { IDirection, IInset } from '@leafer-ui/interface'\nimport { UI, Plugin, UnitConvert, isUndefined, LeafHelper, BranchHelper, isString, AlignHelper, getPointData, isObject, BoundsEvent } from '@leafer-ui/draw'\n\nimport '@leafer-in/resize'\n\nimport { positionType } from './decorate'\n\n\nPlugin.add('position', 'resize')\n\n\n// addAttr\nUI.addAttr('position', false, positionType)\n\n\nconst tempPoint = getPointData()\n\nUI.prototype.__updatePositionLayout = function (): boolean {\n\n const { leaferIsCreated, position, positionNode, boxBounds, parent } = this, { width, height } = boxBounds\n let parentBox = parent.boxBounds, align: IDirection, sizeChanged: boolean\n\n if (positionNode) {\n if (!positionNode.parent || positionNode.destroyed) return false\n this.__extraUpdate()\n }\n\n if (leaferIsCreated) this.leafer.created = false // 拦截布局更新通知,进行手动更新布局\n\n if (isString(position)) {\n\n align = position\n\n } else {\n\n let { left, top, right, bottom } = position\n\n if (positionNode) parentBox = positionNode.getBounds('box', positionNode.parent === parent ? 'local' : parent)\n\n if (position.align) {\n\n align = position.align\n\n } else {\n\n const { x: parentX, y: parentY, width: parentWidth, height: parentHeight } = parentBox\n\n const hasLeft = !isUndefined(left), hasTop = !isUndefined(top)\n\n // 布局\n if (hasLeft) {\n left = UnitConvert.number(left, parentWidth)\n this.x = parentX + left\n }\n\n if (!isUndefined(right)) {\n right = UnitConvert.number(right, parentWidth)\n\n if (hasLeft) this.resizeWidth(parentWidth - (left as number) - right), sizeChanged = true\n else this.x = parentX + parentWidth - width - right\n\n }\n\n if (hasTop) {\n top = UnitConvert.number(top, parentHeight)\n this.y = parentY + top\n }\n\n if (!isUndefined(bottom)) {\n bottom = UnitConvert.number(bottom, parentHeight)\n\n if (position.top !== undefined) this.resizeHeight(parentHeight - (top as number) - bottom), sizeChanged = true\n else this.y = parentY + parentHeight - height - bottom\n }\n }\n\n }\n\n if (align) {\n AlignHelper.toPoint(align, boxBounds, parentBox, tempPoint, false)\n this.set(tempPoint)\n }\n\n if (leaferIsCreated) this.leafer.created = true\n\n LeafHelper.updateAllMatrix(this)\n this.isBranch ? BranchHelper.updateBounds(this) : LeafHelper.updateBounds(this)\n\n return sizeChanged\n}\n\n// 监听相对元素\nLeafHelper.listenPositionNode = function (leaf: UI): void {\n const { position, positionNode } = leaf\n\n if (isObject(position) && position.id) leaf.positionNode = isString(position.id) ? leaf.app.findId(position.id) : position.id\n else if (leaf.positionNode) leaf.positionNode = undefined\n\n if (positionNode !== leaf.positionNode) {\n if (positionNode) positionNode.off(positionNode.parent === leaf.parent ? BoundsEvent.LOCAL : BoundsEvent.WORLD, leaf.__updatePositionLayout) // leaf.__updatePositionLayout 在属性装饰器中已经绑定\n if (leaf.positionNode) {\n leaf.positionNode.on(leaf.positionNode.parent === leaf.parent ? BoundsEvent.LOCAL : BoundsEvent.WORLD, leaf.__updatePositionLayout)\n LeafHelper.updateBounds(leaf.positionNode)\n }\n leaf.__updatePositionLayout()\n if (!leaf.positionNode) leaf.__.__usePositionNode = undefined\n }\n}\n\n// 更新子级\nLeafHelper.updatePositionLayout = function (leaf: UI): void {\n let hasPosition\n leaf.children.forEach(item => {\n if (item.position && !(item.position as IInset).id) {\n hasPosition = true\n item.__updatePositionLayout()\n }\n })\n leaf.__hasPosition = hasPosition\n}\n"],"names":["positionParentChange","parent","__hasPosition","Plugin","add","UI","addAttr","defaultValue","decorateLeafAttr","key","attr","set","value","this","__setAttr","id","data","__","__usePositionNode","__updatePositionLayout","bind","waitParentChange","doBoundsType","tempPoint","getPointData","prototype","leaferIsCreated","position","positionNode","boxBounds","width","height","align","sizeChanged","parentBox","destroyed","__extraUpdate","leafer","created","isString","left","top","right","bottom","getBounds","x","parentX","y","parentY","parentWidth","parentHeight","hasLeft","isUndefined","hasTop","UnitConvert","number","resizeWidth","undefined","resizeHeight","AlignHelper","toPoint","LeafHelper","updateAllMatrix","isBranch","BranchHelper","updateBounds","listenPositionNode","leaf","isObject","app","findId","off","BoundsEvent","LOCAL","WORLD","on","updatePositionLayout","hasPosition","children","forEach","item"],"mappings":"8CAIA,SAASA,EAAqBC,GAC1BA,EAAOC,eAAgB,CAC3B,8BCEAC,EAAAA,OAAOC,IAAI,WAAY,UAIvBC,EAAAA,GAAGC,QAAQ,YAAY,EDJjB,SAAuBC,GACzB,OAAOC,mBAAiBD,EAAeE,GAAgBC,EAAAA,KAAK,CACxD,GAAAC,CAAIC,GACA,GAAIC,KAAKC,UAAUL,EAAKG,GAAQ,CAC5B,GAAIA,EACA,GAAKA,EAAiBG,GAAI,CACtB,MAAMC,EAAOH,KAAKI,GACbD,EAAKE,oBACNF,EAAKE,mBAAoB,EACzBL,KAAKM,uBAAyBN,KAAKM,uBAAuBC,KAAKP,MAEvE,MAAOA,KAAKQ,iBAAiBrB,GAEjCsB,EAAAA,aAAaT,KACjB,CACJ,IAER,GCVA,MAAMU,EAAYC,EAAAA,eAElBnB,EAAAA,GAAGoB,UAAUN,uBAAyB,WAElC,MAAMO,gBAAEA,EAAeC,SAAEA,EAAQC,aAAEA,EAAYC,UAAEA,EAAS5B,OAAEA,GAAWY,MAAMiB,MAAEA,EAAKC,OAAEA,GAAWF,EACjG,IAAkCG,EAAmBC,EAAjDC,EAAYjC,EAAO4B,UAEvB,GAAID,EAAc,CACd,IAAKA,EAAa3B,QAAU2B,EAAaO,UAAW,OAAO,EAC3DtB,KAAKuB,eACT,CAIA,GAFIV,IAAiBb,KAAKwB,OAAOC,SAAU,GAEvCC,EAAAA,SAASZ,GAETK,EAAQL,MAEL,CAEH,IAAIa,KAAE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eW,EAAAA,SAASZ,EAASZ,IAAMoD,EAAKE,IAAIC,OAAO3C,EAASZ,IAAMY,EAASZ,GAClHoD,EAAKvC,eAAcuC,EAAKvC,kBAAe6B,GAE5C7B,IAAiBuC,EAAKvC,eAClBA,GAAcA,EAAa2C,IAAI3C,EAAa3B,SAAWkE,EAAKlE,OAASuE,cAAYC,MAAQD,EAAAA,YAAYE,MAAOP,EAAKhD,wBACjHgD,EAAKvC,eACLuC,EAAKvC,aAAa+C,GAAGR,EAAKvC,aAAa3B,SAAWkE,EAAKlE,OAASuE,EAAAA,YAAYC,MAAQD,EAAAA,YAAYE,MAAOP,EAAKhD,wBAC5G0C,aAAWI,aAAaE,EAAKvC,eAEjCuC,EAAKhD,yBACAgD,EAAKvC,eAAcuC,EAAKlD,GAAGC,uBAAoBuC,GAE5D,EAGAI,EAAAA,WAAWe,qBAAuB,SAAUT,GACxC,IAAIU,EACJV,EAAKW,SAASC,QAAQC,IACdA,EAAKrD,WAAcqD,EAAKrD,SAAoBZ,KAC5C8D,GAAc,EACdG,EAAK7D,4BAGbgD,EAAKjE,cAAgB2E,CACzB"}
|
package/dist/position.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t){"use strict";function
|
|
1
|
+
!function(t){"use strict";function i(t){t.__hasPosition=!0}t.Plugin.add("position","resize"),t.UI.addAttr("position",!1,function(o){return t.decorateLeafAttr(o,o=>t.attr({set(e){if(this.__setAttr(o,e)){if(e)if(e.id){const t=this.__;t.__usePositionNode||(t.__usePositionNode=!0,this.__updatePositionLayout=this.__updatePositionLayout.bind(this))}else this.waitParentChange(i);t.doBoundsType(this)}}}))});const o=t.getPointData();t.UI.prototype.__updatePositionLayout=function(){const{leaferIsCreated:i,position:e,positionNode:n,boxBounds:s,parent:d}=this,{width:a,height:r}=s;let p,u,h=d.boxBounds;if(n){if(!n.parent||n.destroyed)return!1;this.__extraUpdate()}if(i&&(this.leafer.created=!1),t.isString(e))p=e;else{let{left:i,top:o,right:s,bottom:f}=e;if(n&&(h=n.getBounds("box",n.parent===d?"local":d)),e.align)p=e.align;else{const{x:n,y:d,width:p,height:_}=h,l=!t.isUndefined(i),c=!t.isUndefined(o);l&&(i=t.UnitConvert.number(i,p),this.x=n+i),t.isUndefined(s)||(s=t.UnitConvert.number(s,p),l?(this.resizeWidth(p-i-s),u=!0):this.x=n+p-a-s),c&&(o=t.UnitConvert.number(o,_),this.y=d+o),t.isUndefined(f)||(f=t.UnitConvert.number(f,_),void 0!==e.top?(this.resizeHeight(_-o-f),u=!0):this.y=d+_-r-f)}}return p&&(t.AlignHelper.toPoint(p,s,h,o,!1),this.set(o)),i&&(this.leafer.created=!0),t.LeafHelper.updateAllMatrix(this),this.isBranch?t.BranchHelper.updateBounds(this):t.LeafHelper.updateBounds(this),u},t.LeafHelper.listenPositionNode=function(i){const{position:o,positionNode:e}=i;t.isObject(o)&&o.id?i.positionNode=t.isString(o.id)?i.app.findId(o.id):o.id:i.positionNode&&(i.positionNode=void 0),e!==i.positionNode&&(e&&e.off(e.parent===i.parent?t.BoundsEvent.LOCAL:t.BoundsEvent.WORLD,i.__updatePositionLayout),i.positionNode&&(i.positionNode.on(i.positionNode.parent===i.parent?t.BoundsEvent.LOCAL:t.BoundsEvent.WORLD,i.__updatePositionLayout),t.LeafHelper.updateBounds(i.positionNode)),i.__updatePositionLayout(),i.positionNode||(i.__.__usePositionNode=void 0))},t.LeafHelper.updatePositionLayout=function(t){let i;t.children.forEach(t=>{t.position&&!t.position.id&&(i=!0,t.__updatePositionLayout())}),t.__hasPosition=i}}(LeaferUI);
|
|
2
2
|
//# sourceMappingURL=position.min.js.map
|
package/dist/position.min.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"position.min.js","sources":["../../../../../../src/in/packages/position/src/decorate.ts","../../../../../../src/in/packages/position/src/index.ts"],"sourcesContent":["import { attr, decorateLeafAttr, doBoundsType } from '@leafer-ui/draw'\nimport { ILeaf, IValue } from '@leafer/interface'\n\n\nfunction positionParentChange(parent: ILeaf) {\n parent.__hasPosition = true\n}\n\nexport function positionType(defaultValue?: IValue) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: IValue) {\n if (this.__setAttr(key, value)) {\n if (value) this.waitParentChange(positionParentChange)\n doBoundsType(this)\n }\n }\n }))\n}","import { UI, Plugin, UnitConvert, isUndefined, LeafHelper, BranchHelper, isString, AlignHelper, getPointData } from '@leafer-ui/draw'\n\nimport '@leafer-in/resize'\n\nimport { positionType } from './decorate'\n\n\nPlugin.add('position', 'resize')\n\n\n// addAttr\nUI.addAttr('position', false, positionType)\n\n\nconst tempPoint = getPointData()\n\nUI.prototype.__updatePositionLayout = function (): boolean {\n\n
|
|
1
|
+
{"version":3,"file":"position.min.js","sources":["../../../../../../src/in/packages/position/src/decorate.ts","../../../../../../src/in/packages/position/src/index.ts"],"sourcesContent":["import { attr, decorateLeafAttr, doBoundsType } from '@leafer-ui/draw'\nimport { ILeaf, IValue, IInset } from '@leafer-ui/interface'\n\n\nfunction positionParentChange(parent: ILeaf) {\n parent.__hasPosition = true\n}\n\nexport function positionType(defaultValue?: IValue) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: IValue) {\n if (this.__setAttr(key, value)) {\n if (value) {\n if ((value as IInset).id) {\n const data = this.__\n if (!data.__usePositionNode) {\n data.__usePositionNode = true\n this.__updatePositionLayout = this.__updatePositionLayout.bind(this)\n }\n } else this.waitParentChange(positionParentChange)\n }\n doBoundsType(this)\n }\n }\n }))\n}","import { IDirection, IInset } from '@leafer-ui/interface'\nimport { UI, Plugin, UnitConvert, isUndefined, LeafHelper, BranchHelper, isString, AlignHelper, getPointData, isObject, BoundsEvent } from '@leafer-ui/draw'\n\nimport '@leafer-in/resize'\n\nimport { positionType } from './decorate'\n\n\nPlugin.add('position', 'resize')\n\n\n// addAttr\nUI.addAttr('position', false, positionType)\n\n\nconst tempPoint = getPointData()\n\nUI.prototype.__updatePositionLayout = function (): boolean {\n\n const { leaferIsCreated, position, positionNode, boxBounds, parent } = this, { width, height } = boxBounds\n let parentBox = parent.boxBounds, align: IDirection, sizeChanged: boolean\n\n if (positionNode) {\n if (!positionNode.parent || positionNode.destroyed) return false\n this.__extraUpdate()\n }\n\n if (leaferIsCreated) this.leafer.created = false // 拦截布局更新通知,进行手动更新布局\n\n if (isString(position)) {\n\n align = position\n\n } else {\n\n let { left, top, right, bottom } = position\n\n if (positionNode) parentBox = positionNode.getBounds('box', positionNode.parent === parent ? 'local' : parent)\n\n if (position.align) {\n\n align = position.align\n\n } else {\n\n const { x: parentX, y: parentY, width: parentWidth, height: parentHeight } = parentBox\n\n const hasLeft = !isUndefined(left), hasTop = !isUndefined(top)\n\n // 布局\n if (hasLeft) {\n left = UnitConvert.number(left, parentWidth)\n this.x = parentX + left\n }\n\n if (!isUndefined(right)) {\n right = UnitConvert.number(right, parentWidth)\n\n if (hasLeft) this.resizeWidth(parentWidth - (left as number) - right), sizeChanged = true\n else this.x = parentX + parentWidth - width - right\n\n }\n\n if (hasTop) {\n top = UnitConvert.number(top, parentHeight)\n this.y = parentY + top\n }\n\n if (!isUndefined(bottom)) {\n bottom = UnitConvert.number(bottom, parentHeight)\n\n if (position.top !== undefined) this.resizeHeight(parentHeight - (top as number) - bottom), sizeChanged = true\n else this.y = parentY + parentHeight - height - bottom\n }\n }\n\n }\n\n if (align) {\n AlignHelper.toPoint(align, boxBounds, parentBox, tempPoint, false)\n this.set(tempPoint)\n }\n\n if (leaferIsCreated) this.leafer.created = true\n\n LeafHelper.updateAllMatrix(this)\n this.isBranch ? BranchHelper.updateBounds(this) : LeafHelper.updateBounds(this)\n\n return sizeChanged\n}\n\n// 监听相对元素\nLeafHelper.listenPositionNode = function (leaf: UI): void {\n const { position, positionNode } = leaf\n\n if (isObject(position) && position.id) leaf.positionNode = isString(position.id) ? leaf.app.findId(position.id) : position.id\n else if (leaf.positionNode) leaf.positionNode = undefined\n\n if (positionNode !== leaf.positionNode) {\n if (positionNode) positionNode.off(positionNode.parent === leaf.parent ? BoundsEvent.LOCAL : BoundsEvent.WORLD, leaf.__updatePositionLayout) // leaf.__updatePositionLayout 在属性装饰器中已经绑定\n if (leaf.positionNode) {\n leaf.positionNode.on(leaf.positionNode.parent === leaf.parent ? BoundsEvent.LOCAL : BoundsEvent.WORLD, leaf.__updatePositionLayout)\n LeafHelper.updateBounds(leaf.positionNode)\n }\n leaf.__updatePositionLayout()\n if (!leaf.positionNode) leaf.__.__usePositionNode = undefined\n }\n}\n\n// 更新子级\nLeafHelper.updatePositionLayout = function (leaf: UI): void {\n let hasPosition\n leaf.children.forEach(item => {\n if (item.position && !(item.position as IInset).id) {\n hasPosition = true\n item.__updatePositionLayout()\n }\n })\n leaf.__hasPosition = hasPosition\n}\n"],"names":["positionParentChange","parent","__hasPosition","Plugin","add","UI","addAttr","defaultValue","decorateLeafAttr","key","attr","set","value","this","__setAttr","id","data","__","__usePositionNode","__updatePositionLayout","bind","waitParentChange","doBoundsType","tempPoint","getPointData","prototype","leaferIsCreated","position","positionNode","boxBounds","width","height","align","sizeChanged","parentBox","destroyed","__extraUpdate","leafer","created","isString","left","top","right","bottom","getBounds","x","parentX","y","parentY","parentWidth","parentHeight","hasLeft","isUndefined","hasTop","UnitConvert","number","resizeWidth","undefined","resizeHeight","AlignHelper","toPoint","LeafHelper","updateAllMatrix","isBranch","BranchHelper","updateBounds","listenPositionNode","leaf","isObject","app","findId","off","BoundsEvent","LOCAL","WORLD","on","updatePositionLayout","hasPosition","children","forEach","item"],"mappings":"0BAIA,SAASA,EAAqBC,GAC1BA,EAAOC,eAAgB,CAC3B,CCEAC,EAAAA,OAAOC,IAAI,WAAY,UAIvBC,EAAAA,GAAGC,QAAQ,YAAY,EDJjB,SAAuBC,GACzB,OAAOC,mBAAiBD,EAAeE,GAAgBC,EAAAA,KAAK,CACxD,GAAAC,CAAIC,GACA,GAAIC,KAAKC,UAAUL,EAAKG,GAAQ,CAC5B,GAAIA,EACA,GAAKA,EAAiBG,GAAI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EAAKrD,SAAoBZ,KAC5C8D,GAAc,EACdG,EAAK7D,4BAGbgD,EAAKjE,cAAgB2E,CACzB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/position",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4",
|
|
4
4
|
"description": "@leafer-in/position",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"leaferjs"
|
|
35
35
|
],
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@leafer-ui/draw": "^2.3.
|
|
38
|
-
"@leafer-in/resize": "^2.3.
|
|
39
|
-
"@leafer-ui/interface": "^2.3.
|
|
40
|
-
"@leafer-in/interface": "^2.3.
|
|
37
|
+
"@leafer-ui/draw": "^2.3.4",
|
|
38
|
+
"@leafer-in/resize": "^2.3.4",
|
|
39
|
+
"@leafer-ui/interface": "^2.3.4",
|
|
40
|
+
"@leafer-in/interface": "^2.3.4"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/decorate.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { attr, decorateLeafAttr, doBoundsType } from '@leafer-ui/draw'
|
|
2
|
-
import { ILeaf, IValue } from '@leafer/interface'
|
|
2
|
+
import { ILeaf, IValue, IInset } from '@leafer-ui/interface'
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
function positionParentChange(parent: ILeaf) {
|
|
@@ -10,7 +10,15 @@ export function positionType(defaultValue?: IValue) {
|
|
|
10
10
|
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
11
11
|
set(value: IValue) {
|
|
12
12
|
if (this.__setAttr(key, value)) {
|
|
13
|
-
if (value)
|
|
13
|
+
if (value) {
|
|
14
|
+
if ((value as IInset).id) {
|
|
15
|
+
const data = this.__
|
|
16
|
+
if (!data.__usePositionNode) {
|
|
17
|
+
data.__usePositionNode = true
|
|
18
|
+
this.__updatePositionLayout = this.__updatePositionLayout.bind(this)
|
|
19
|
+
}
|
|
20
|
+
} else this.waitParentChange(positionParentChange)
|
|
21
|
+
}
|
|
14
22
|
doBoundsType(this)
|
|
15
23
|
}
|
|
16
24
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IDirection, IInset } from '@leafer-ui/interface'
|
|
2
|
+
import { UI, Plugin, UnitConvert, isUndefined, LeafHelper, BranchHelper, isString, AlignHelper, getPointData, isObject, BoundsEvent } from '@leafer-ui/draw'
|
|
2
3
|
|
|
3
4
|
import '@leafer-in/resize'
|
|
4
5
|
|
|
@@ -16,62 +17,103 @@ const tempPoint = getPointData()
|
|
|
16
17
|
|
|
17
18
|
UI.prototype.__updatePositionLayout = function (): boolean {
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const { leaferIsCreated, position, positionNode, boxBounds, parent } = this, { width, height } = boxBounds
|
|
21
|
+
let parentBox = parent.boxBounds, align: IDirection, sizeChanged: boolean
|
|
22
|
+
|
|
23
|
+
if (positionNode) {
|
|
24
|
+
if (!positionNode.parent || positionNode.destroyed) return false
|
|
25
|
+
this.__extraUpdate()
|
|
26
|
+
}
|
|
22
27
|
|
|
23
28
|
if (leaferIsCreated) this.leafer.created = false // 拦截布局更新通知,进行手动更新布局
|
|
24
29
|
|
|
25
30
|
if (isString(position)) {
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
this.set(tempPoint)
|
|
32
|
+
align = position
|
|
29
33
|
|
|
30
34
|
} else {
|
|
31
35
|
|
|
32
36
|
let { left, top, right, bottom } = position
|
|
33
|
-
const hasLeft = !isUndefined(left), hasTop = !isUndefined(top)
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
if (hasLeft) {
|
|
37
|
-
left = UnitConvert.number(left, parentWidth)
|
|
38
|
-
this.x = left
|
|
39
|
-
}
|
|
38
|
+
if (positionNode) parentBox = positionNode.getBounds('box', positionNode.parent === parent ? 'local' : parent)
|
|
40
39
|
|
|
41
|
-
if (
|
|
42
|
-
right = UnitConvert.number(right, parentWidth)
|
|
40
|
+
if (position.align) {
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
else this.x = parentWidth - width - right
|
|
42
|
+
align = position.align
|
|
46
43
|
|
|
47
|
-
}
|
|
44
|
+
} else {
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
const { x: parentX, y: parentY, width: parentWidth, height: parentHeight } = parentBox
|
|
47
|
+
|
|
48
|
+
const hasLeft = !isUndefined(left), hasTop = !isUndefined(top)
|
|
49
|
+
|
|
50
|
+
// 布局
|
|
51
|
+
if (hasLeft) {
|
|
52
|
+
left = UnitConvert.number(left, parentWidth)
|
|
53
|
+
this.x = parentX + left
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!isUndefined(right)) {
|
|
57
|
+
right = UnitConvert.number(right, parentWidth)
|
|
58
|
+
|
|
59
|
+
if (hasLeft) this.resizeWidth(parentWidth - (left as number) - right), sizeChanged = true
|
|
60
|
+
else this.x = parentX + parentWidth - width - right
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (hasTop) {
|
|
65
|
+
top = UnitConvert.number(top, parentHeight)
|
|
66
|
+
this.y = parentY + top
|
|
67
|
+
}
|
|
53
68
|
|
|
54
|
-
|
|
55
|
-
|
|
69
|
+
if (!isUndefined(bottom)) {
|
|
70
|
+
bottom = UnitConvert.number(bottom, parentHeight)
|
|
56
71
|
|
|
57
|
-
|
|
58
|
-
|
|
72
|
+
if (position.top !== undefined) this.resizeHeight(parentHeight - (top as number) - bottom), sizeChanged = true
|
|
73
|
+
else this.y = parentY + parentHeight - height - bottom
|
|
74
|
+
}
|
|
59
75
|
}
|
|
76
|
+
|
|
60
77
|
}
|
|
61
78
|
|
|
79
|
+
if (align) {
|
|
80
|
+
AlignHelper.toPoint(align, boxBounds, parentBox, tempPoint, false)
|
|
81
|
+
this.set(tempPoint)
|
|
82
|
+
}
|
|
62
83
|
|
|
63
84
|
if (leaferIsCreated) this.leafer.created = true
|
|
85
|
+
|
|
86
|
+
LeafHelper.updateAllMatrix(this)
|
|
87
|
+
this.isBranch ? BranchHelper.updateBounds(this) : LeafHelper.updateBounds(this)
|
|
88
|
+
|
|
64
89
|
return sizeChanged
|
|
65
90
|
}
|
|
66
91
|
|
|
92
|
+
// 监听相对元素
|
|
93
|
+
LeafHelper.listenPositionNode = function (leaf: UI): void {
|
|
94
|
+
const { position, positionNode } = leaf
|
|
95
|
+
|
|
96
|
+
if (isObject(position) && position.id) leaf.positionNode = isString(position.id) ? leaf.app.findId(position.id) : position.id
|
|
97
|
+
else if (leaf.positionNode) leaf.positionNode = undefined
|
|
98
|
+
|
|
99
|
+
if (positionNode !== leaf.positionNode) {
|
|
100
|
+
if (positionNode) positionNode.off(positionNode.parent === leaf.parent ? BoundsEvent.LOCAL : BoundsEvent.WORLD, leaf.__updatePositionLayout) // leaf.__updatePositionLayout 在属性装饰器中已经绑定
|
|
101
|
+
if (leaf.positionNode) {
|
|
102
|
+
leaf.positionNode.on(leaf.positionNode.parent === leaf.parent ? BoundsEvent.LOCAL : BoundsEvent.WORLD, leaf.__updatePositionLayout)
|
|
103
|
+
LeafHelper.updateBounds(leaf.positionNode)
|
|
104
|
+
}
|
|
105
|
+
leaf.__updatePositionLayout()
|
|
106
|
+
if (!leaf.positionNode) leaf.__.__usePositionNode = undefined
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 更新子级
|
|
67
111
|
LeafHelper.updatePositionLayout = function (leaf: UI): void {
|
|
68
112
|
let hasPosition
|
|
69
113
|
leaf.children.forEach(item => {
|
|
70
|
-
if (item.position) {
|
|
114
|
+
if (item.position && !(item.position as IInset).id) {
|
|
71
115
|
hasPosition = true
|
|
72
116
|
item.__updatePositionLayout()
|
|
73
|
-
LeafHelper.updateAllMatrix(item)
|
|
74
|
-
item.isBranch ? BranchHelper.updateBounds(item) : LeafHelper.updateBounds(item)
|
|
75
117
|
}
|
|
76
118
|
})
|
|
77
119
|
leaf.__hasPosition = hasPosition
|