@leafer-in/position 0.0.0-stage → 2.3.3
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/LICENSE +21 -0
- package/README.md +1 -3
- package/dist/position.cjs +106 -0
- package/dist/position.esm.js +104 -0
- package/dist/position.esm.min.js +2 -0
- package/dist/position.esm.min.js.map +1 -0
- package/dist/position.js +96 -0
- package/dist/position.min.cjs +2 -0
- package/dist/position.min.cjs.map +1 -0
- package/dist/position.min.js +2 -0
- package/dist/position.min.js.map +1 -0
- package/package.json +39 -3
- package/src/decorate.ts +26 -0
- package/src/index.ts +120 -0
- package/types/index.d.ts +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present, Chao (Leafer) Wan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var draw = require("@leafer-ui/draw");
|
|
4
|
+
|
|
5
|
+
require("@leafer-in/resize");
|
|
6
|
+
|
|
7
|
+
function positionParentChange(parent) {
|
|
8
|
+
parent.__hasPosition = true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function positionType(defaultValue) {
|
|
12
|
+
return draw.decorateLeafAttr(defaultValue, key => draw.attr({
|
|
13
|
+
set(value) {
|
|
14
|
+
if (this.__setAttr(key, 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
|
+
}
|
|
24
|
+
draw.doBoundsType(this);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
draw.Plugin.add("position", "resize");
|
|
31
|
+
|
|
32
|
+
draw.UI.addAttr("position", false, positionType);
|
|
33
|
+
|
|
34
|
+
const tempPoint = draw.getPointData();
|
|
35
|
+
|
|
36
|
+
draw.UI.prototype.__updatePositionLayout = function() {
|
|
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
|
+
}
|
|
43
|
+
if (leaferIsCreated) this.leafer.created = false;
|
|
44
|
+
if (draw.isString(position)) {
|
|
45
|
+
align = position;
|
|
46
|
+
} else {
|
|
47
|
+
let {left: left, top: top, right: right, bottom: bottom} = position;
|
|
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
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (align) {
|
|
74
|
+
draw.AlignHelper.toPoint(align, boxBounds, parentBox, tempPoint, false);
|
|
75
|
+
this.set(tempPoint);
|
|
76
|
+
}
|
|
77
|
+
if (leaferIsCreated) this.leafer.created = true;
|
|
78
|
+
draw.LeafHelper.updateAllMatrix(this);
|
|
79
|
+
this.isBranch ? draw.BranchHelper.updateBounds(this) : draw.LeafHelper.updateBounds(this);
|
|
80
|
+
return sizeChanged;
|
|
81
|
+
};
|
|
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
|
+
|
|
97
|
+
draw.LeafHelper.updatePositionLayout = function(leaf) {
|
|
98
|
+
let hasPosition;
|
|
99
|
+
leaf.children.forEach(item => {
|
|
100
|
+
if (item.position && !item.position.id) {
|
|
101
|
+
hasPosition = true;
|
|
102
|
+
item.__updatePositionLayout();
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
leaf.__hasPosition = hasPosition;
|
|
106
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { decorateLeafAttr, attr, doBoundsType, Plugin, UI, getPointData, isString, isUndefined, UnitConvert, AlignHelper, LeafHelper, BranchHelper, isObject, BoundsEvent } from "@leafer-ui/draw";
|
|
2
|
+
|
|
3
|
+
import "@leafer-in/resize";
|
|
4
|
+
|
|
5
|
+
function positionParentChange(parent) {
|
|
6
|
+
parent.__hasPosition = true;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function positionType(defaultValue) {
|
|
10
|
+
return decorateLeafAttr(defaultValue, key => attr({
|
|
11
|
+
set(value) {
|
|
12
|
+
if (this.__setAttr(key, 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
|
+
}
|
|
22
|
+
doBoundsType(this);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Plugin.add("position", "resize");
|
|
29
|
+
|
|
30
|
+
UI.addAttr("position", false, positionType);
|
|
31
|
+
|
|
32
|
+
const tempPoint = getPointData();
|
|
33
|
+
|
|
34
|
+
UI.prototype.__updatePositionLayout = function() {
|
|
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
|
+
}
|
|
41
|
+
if (leaferIsCreated) this.leafer.created = false;
|
|
42
|
+
if (isString(position)) {
|
|
43
|
+
align = position;
|
|
44
|
+
} else {
|
|
45
|
+
let {left: left, top: top, right: right, bottom: bottom} = position;
|
|
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
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (align) {
|
|
72
|
+
AlignHelper.toPoint(align, boxBounds, parentBox, tempPoint, false);
|
|
73
|
+
this.set(tempPoint);
|
|
74
|
+
}
|
|
75
|
+
if (leaferIsCreated) this.leafer.created = true;
|
|
76
|
+
LeafHelper.updateAllMatrix(this);
|
|
77
|
+
this.isBranch ? BranchHelper.updateBounds(this) : LeafHelper.updateBounds(this);
|
|
78
|
+
return sizeChanged;
|
|
79
|
+
};
|
|
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
|
+
|
|
95
|
+
LeafHelper.updatePositionLayout = function(leaf) {
|
|
96
|
+
let hasPosition;
|
|
97
|
+
leaf.children.forEach(item => {
|
|
98
|
+
if (item.position && !item.position.id) {
|
|
99
|
+
hasPosition = true;
|
|
100
|
+
item.__updatePositionLayout();
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
leaf.__hasPosition = hasPosition;
|
|
104
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
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
|
+
//# sourceMappingURL=position.esm.min.js.map
|
|
@@ -0,0 +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, 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,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AAoBuC,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
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
(function(draw) {
|
|
2
|
+
"use strict";
|
|
3
|
+
function positionParentChange(parent) {
|
|
4
|
+
parent.__hasPosition = true;
|
|
5
|
+
}
|
|
6
|
+
function positionType(defaultValue) {
|
|
7
|
+
return draw.decorateLeafAttr(defaultValue, key => draw.attr({
|
|
8
|
+
set(value) {
|
|
9
|
+
if (this.__setAttr(key, 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
|
+
}
|
|
19
|
+
draw.doBoundsType(this);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
draw.Plugin.add("position", "resize");
|
|
25
|
+
draw.UI.addAttr("position", false, positionType);
|
|
26
|
+
const tempPoint = draw.getPointData();
|
|
27
|
+
draw.UI.prototype.__updatePositionLayout = function() {
|
|
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
|
+
}
|
|
34
|
+
if (leaferIsCreated) this.leafer.created = false;
|
|
35
|
+
if (draw.isString(position)) {
|
|
36
|
+
align = position;
|
|
37
|
+
} else {
|
|
38
|
+
let {left: left, top: top, right: right, bottom: bottom} = position;
|
|
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
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (align) {
|
|
65
|
+
draw.AlignHelper.toPoint(align, boxBounds, parentBox, tempPoint, false);
|
|
66
|
+
this.set(tempPoint);
|
|
67
|
+
}
|
|
68
|
+
if (leaferIsCreated) this.leafer.created = true;
|
|
69
|
+
draw.LeafHelper.updateAllMatrix(this);
|
|
70
|
+
this.isBranch ? draw.BranchHelper.updateBounds(this) : draw.LeafHelper.updateBounds(this);
|
|
71
|
+
return sizeChanged;
|
|
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
|
+
};
|
|
86
|
+
draw.LeafHelper.updatePositionLayout = function(leaf) {
|
|
87
|
+
let hasPosition;
|
|
88
|
+
leaf.children.forEach(item => {
|
|
89
|
+
if (item.position && !item.position.id) {
|
|
90
|
+
hasPosition = true;
|
|
91
|
+
item.__updatePositionLayout();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
leaf.__hasPosition = hasPosition;
|
|
95
|
+
};
|
|
96
|
+
})(LeaferUI);
|
|
@@ -0,0 +1,2 @@
|
|
|
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
|
+
//# sourceMappingURL=position.min.cjs.map
|
|
@@ -0,0 +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, 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,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AAWI,aAAapD,MAEnEoB,CACX,EAGA4B,EAAAA,WAAWK,mBAAqB,SAAUC,GACtC,MAAMxC,SAAEA,EAAQC,aAAEA,GAAiBuC,EAE/BC,WAASzC,IAAaA,EAASZ,GAAIoD,EAAKvC,aAAeW,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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
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
|
+
//# sourceMappingURL=position.min.js.map
|
|
@@ -0,0 +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, 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,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,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,GACtC,MAAMxC,SAAEA,EAAQC,aAAEA,GAAiBuC,EAE/BC,WAASzC,IAAaA,EAASZ,GAAIoD,EAAKvC,aAAeW,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/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/position",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.3.3",
|
|
4
|
+
"description": "@leafer-in/position",
|
|
5
|
+
"author": "Chao (Leafer) Wan",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/position.esm.min.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
"import": "./dist/position.esm.min.js",
|
|
11
|
+
"require": "./dist/position.min.cjs",
|
|
12
|
+
"types": "./types/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"types": "types/index.d.ts",
|
|
15
|
+
"unpkg": "dist/position.min.js",
|
|
16
|
+
"jsdelivr": "dist/position.min.js",
|
|
17
|
+
"files": [
|
|
18
|
+
"src",
|
|
19
|
+
"types",
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/leaferjs/leafer-in.git"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/leaferjs/leafer-in/tree/main/packages/position",
|
|
27
|
+
"bugs": "https://github.com/leaferjs/leafer-in/issues",
|
|
28
|
+
"keywords": [
|
|
29
|
+
"leafer position",
|
|
30
|
+
"leafer-position",
|
|
31
|
+
"leafer-in",
|
|
32
|
+
"position",
|
|
33
|
+
"leafer-ui",
|
|
34
|
+
"leaferjs"
|
|
35
|
+
],
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@leafer-ui/draw": "^2.3.3",
|
|
38
|
+
"@leafer-in/resize": "^2.3.3",
|
|
39
|
+
"@leafer-ui/interface": "^2.3.3",
|
|
40
|
+
"@leafer-in/interface": "^2.3.3"
|
|
41
|
+
}
|
|
6
42
|
}
|
package/src/decorate.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { attr, decorateLeafAttr, doBoundsType } from '@leafer-ui/draw'
|
|
2
|
+
import { ILeaf, IValue, IInset } from '@leafer-ui/interface'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function positionParentChange(parent: ILeaf) {
|
|
6
|
+
parent.__hasPosition = true
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function positionType(defaultValue?: IValue) {
|
|
10
|
+
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
11
|
+
set(value: IValue) {
|
|
12
|
+
if (this.__setAttr(key, 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
|
+
}
|
|
22
|
+
doBoundsType(this)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}))
|
|
26
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
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'
|
|
3
|
+
|
|
4
|
+
import '@leafer-in/resize'
|
|
5
|
+
|
|
6
|
+
import { positionType } from './decorate'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Plugin.add('position', 'resize')
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
// addAttr
|
|
13
|
+
UI.addAttr('position', false, positionType)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const tempPoint = getPointData()
|
|
17
|
+
|
|
18
|
+
UI.prototype.__updatePositionLayout = function (): boolean {
|
|
19
|
+
|
|
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
|
+
}
|
|
27
|
+
|
|
28
|
+
if (leaferIsCreated) this.leafer.created = false // 拦截布局更新通知,进行手动更新布局
|
|
29
|
+
|
|
30
|
+
if (isString(position)) {
|
|
31
|
+
|
|
32
|
+
align = position
|
|
33
|
+
|
|
34
|
+
} else {
|
|
35
|
+
|
|
36
|
+
let { left, top, right, bottom } = position
|
|
37
|
+
|
|
38
|
+
if (positionNode) parentBox = positionNode.getBounds('box', positionNode.parent === parent ? 'local' : parent)
|
|
39
|
+
|
|
40
|
+
if (position.align) {
|
|
41
|
+
|
|
42
|
+
align = position.align
|
|
43
|
+
|
|
44
|
+
} else {
|
|
45
|
+
|
|
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
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!isUndefined(bottom)) {
|
|
70
|
+
bottom = UnitConvert.number(bottom, parentHeight)
|
|
71
|
+
|
|
72
|
+
if (position.top !== undefined) this.resizeHeight(parentHeight - (top as number) - bottom), sizeChanged = true
|
|
73
|
+
else this.y = parentY + parentHeight - height - bottom
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (align) {
|
|
80
|
+
AlignHelper.toPoint(align, boxBounds, parentBox, tempPoint, false)
|
|
81
|
+
this.set(tempPoint)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (leaferIsCreated) this.leafer.created = true
|
|
85
|
+
|
|
86
|
+
LeafHelper.updateAllMatrix(this)
|
|
87
|
+
this.isBranch ? BranchHelper.updateBounds(this) : LeafHelper.updateBounds(this)
|
|
88
|
+
|
|
89
|
+
return sizeChanged
|
|
90
|
+
}
|
|
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
|
+
// 更新子级
|
|
111
|
+
LeafHelper.updatePositionLayout = function (leaf: UI): void {
|
|
112
|
+
let hasPosition
|
|
113
|
+
leaf.children.forEach(item => {
|
|
114
|
+
if (item.position && !(item.position as IInset).id) {
|
|
115
|
+
hasPosition = true
|
|
116
|
+
item.__updatePositionLayout()
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
leaf.__hasPosition = hasPosition
|
|
120
|
+
}
|
package/types/index.d.ts
ADDED