@leafer-in/position 0.0.0-stage → 2.3.2
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 +72 -0
- package/dist/position.esm.js +70 -0
- package/dist/position.esm.min.js +2 -0
- package/dist/position.esm.min.js.map +1 -0
- package/dist/position.js +63 -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 +18 -0
- package/src/index.ts +78 -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,72 @@
|
|
|
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) this.waitParentChange(positionParentChange);
|
|
16
|
+
draw.doBoundsType(this);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
draw.Plugin.add("position", "resize");
|
|
23
|
+
|
|
24
|
+
draw.UI.addAttr("position", false, positionType);
|
|
25
|
+
|
|
26
|
+
const tempPoint = draw.getPointData();
|
|
27
|
+
|
|
28
|
+
draw.UI.prototype.__updatePositionLayout = function() {
|
|
29
|
+
let sizeChanged;
|
|
30
|
+
const {leaferIsCreated: leaferIsCreated, position: position, boxBounds: boxBounds} = this, parentBox = this.parent.boxBounds;
|
|
31
|
+
const {width: parentWidth, height: parentHeight} = parentBox, {width: width, height: height} = boxBounds;
|
|
32
|
+
if (leaferIsCreated) this.leafer.created = false;
|
|
33
|
+
if (draw.isString(position)) {
|
|
34
|
+
draw.AlignHelper.toPoint(position, boxBounds, parentBox, tempPoint, true);
|
|
35
|
+
this.set(tempPoint);
|
|
36
|
+
} else {
|
|
37
|
+
let {left: left, top: top, right: right, bottom: bottom} = position;
|
|
38
|
+
const hasLeft = !draw.isUndefined(left), hasTop = !draw.isUndefined(top);
|
|
39
|
+
if (hasLeft) {
|
|
40
|
+
left = draw.UnitConvert.number(left, parentWidth);
|
|
41
|
+
this.x = left;
|
|
42
|
+
}
|
|
43
|
+
if (!draw.isUndefined(right)) {
|
|
44
|
+
right = draw.UnitConvert.number(right, parentWidth);
|
|
45
|
+
if (hasLeft) this.resizeWidth(parentWidth - left - right), sizeChanged = true; else this.x = parentWidth - width - right;
|
|
46
|
+
}
|
|
47
|
+
if (hasTop) {
|
|
48
|
+
top = draw.UnitConvert.number(top, parentHeight);
|
|
49
|
+
this.y = top;
|
|
50
|
+
}
|
|
51
|
+
if (!draw.isUndefined(bottom)) {
|
|
52
|
+
bottom = draw.UnitConvert.number(bottom, parentHeight);
|
|
53
|
+
if (position.top !== undefined) this.resizeHeight(parentHeight - top - bottom),
|
|
54
|
+
sizeChanged = true; else this.y = parentHeight - height - bottom;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (leaferIsCreated) this.leafer.created = true;
|
|
58
|
+
return sizeChanged;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
draw.LeafHelper.updatePositionLayout = function(leaf) {
|
|
62
|
+
let hasPosition;
|
|
63
|
+
leaf.children.forEach(item => {
|
|
64
|
+
if (item.position) {
|
|
65
|
+
hasPosition = true;
|
|
66
|
+
item.__updatePositionLayout();
|
|
67
|
+
draw.LeafHelper.updateAllMatrix(item);
|
|
68
|
+
item.isBranch ? draw.BranchHelper.updateBounds(item) : draw.LeafHelper.updateBounds(item);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
leaf.__hasPosition = hasPosition;
|
|
72
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { decorateLeafAttr, attr, doBoundsType, Plugin, UI, getPointData, isString, AlignHelper, isUndefined, UnitConvert, LeafHelper, BranchHelper } 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) this.waitParentChange(positionParentChange);
|
|
14
|
+
doBoundsType(this);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
Plugin.add("position", "resize");
|
|
21
|
+
|
|
22
|
+
UI.addAttr("position", false, positionType);
|
|
23
|
+
|
|
24
|
+
const tempPoint = getPointData();
|
|
25
|
+
|
|
26
|
+
UI.prototype.__updatePositionLayout = function() {
|
|
27
|
+
let sizeChanged;
|
|
28
|
+
const {leaferIsCreated: leaferIsCreated, position: position, boxBounds: boxBounds} = this, parentBox = this.parent.boxBounds;
|
|
29
|
+
const {width: parentWidth, height: parentHeight} = parentBox, {width: width, height: height} = boxBounds;
|
|
30
|
+
if (leaferIsCreated) this.leafer.created = false;
|
|
31
|
+
if (isString(position)) {
|
|
32
|
+
AlignHelper.toPoint(position, boxBounds, parentBox, tempPoint, true);
|
|
33
|
+
this.set(tempPoint);
|
|
34
|
+
} else {
|
|
35
|
+
let {left: left, top: top, right: right, bottom: bottom} = position;
|
|
36
|
+
const hasLeft = !isUndefined(left), hasTop = !isUndefined(top);
|
|
37
|
+
if (hasLeft) {
|
|
38
|
+
left = UnitConvert.number(left, parentWidth);
|
|
39
|
+
this.x = left;
|
|
40
|
+
}
|
|
41
|
+
if (!isUndefined(right)) {
|
|
42
|
+
right = UnitConvert.number(right, parentWidth);
|
|
43
|
+
if (hasLeft) this.resizeWidth(parentWidth - left - right), sizeChanged = true; else this.x = parentWidth - width - right;
|
|
44
|
+
}
|
|
45
|
+
if (hasTop) {
|
|
46
|
+
top = UnitConvert.number(top, parentHeight);
|
|
47
|
+
this.y = top;
|
|
48
|
+
}
|
|
49
|
+
if (!isUndefined(bottom)) {
|
|
50
|
+
bottom = UnitConvert.number(bottom, parentHeight);
|
|
51
|
+
if (position.top !== undefined) this.resizeHeight(parentHeight - top - bottom),
|
|
52
|
+
sizeChanged = true; else this.y = parentHeight - height - bottom;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (leaferIsCreated) this.leafer.created = true;
|
|
56
|
+
return sizeChanged;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
LeafHelper.updatePositionLayout = function(leaf) {
|
|
60
|
+
let hasPosition;
|
|
61
|
+
leaf.children.forEach(item => {
|
|
62
|
+
if (item.position) {
|
|
63
|
+
hasPosition = true;
|
|
64
|
+
item.__updatePositionLayout();
|
|
65
|
+
LeafHelper.updateAllMatrix(item);
|
|
66
|
+
item.isBranch ? BranchHelper.updateBounds(item) : LeafHelper.updateBounds(item);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
leaf.__hasPosition = hasPosition;
|
|
70
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{decorateLeafAttr as t,attr as i,doBoundsType as e,Plugin as o,UI as s,getPointData as n,isString as r,AlignHelper as a,isUndefined as h,UnitConvert as u,LeafHelper as d,BranchHelper as p}from"@leafer-ui/draw";import"@leafer-in/resize";function f(t){t.__hasPosition=!0}o.add("position","resize"),s.addAttr("position",!1,function(o){return t(o,t=>i({set(i){this.__setAttr(t,i)&&(i&&this.waitParentChange(f),e(this))}}))});const l=n();s.prototype.__updatePositionLayout=function(){let t;const{leaferIsCreated:i,position:e,boxBounds:o}=this,s=this.parent.boxBounds,{width:n,height:d}=s,{width:p,height:f}=o;if(i&&(this.leafer.created=!1),r(e))a.toPoint(e,o,s,l,!0),this.set(l);else{let{left:i,top:o,right:s,bottom:r}=e;const a=!h(i),l=!h(o);a&&(i=u.number(i,n),this.x=i),h(s)||(s=u.number(s,n),a?(this.resizeWidth(n-i-s),t=!0):this.x=n-p-s),l&&(o=u.number(o,d),this.y=o),h(r)||(r=u.number(r,d),void 0!==e.top?(this.resizeHeight(d-o-r),t=!0):this.y=d-f-r)}return i&&(this.leafer.created=!0),t},d.updatePositionLayout=function(t){let i;t.children.forEach(t=>{t.position&&(i=!0,t.__updatePositionLayout(),d.updateAllMatrix(t),t.isBranch?p.updateBounds(t):d.updateBounds(t))}),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 } 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 let sizeChanged: boolean\n const { leaferIsCreated, position, boxBounds } = this, parentBox = this.parent.boxBounds\n const { width: parentWidth, height: parentHeight } = parentBox, { width, height } = boxBounds\n\n if (leaferIsCreated) this.leafer.created = false // 拦截布局更新通知,进行手动更新布局\n\n if (isString(position)) {\n\n AlignHelper.toPoint(position, boxBounds, parentBox, tempPoint, true)\n this.set(tempPoint)\n\n } else {\n\n let { left, top, right, bottom } = position\n const hasLeft = !isUndefined(left), hasTop = !isUndefined(top)\n\n // 布局\n if (hasLeft) {\n left = UnitConvert.number(left, parentWidth)\n this.x = 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 = parentWidth - width - right\n\n }\n\n if (hasTop) {\n top = UnitConvert.number(top, parentHeight)\n this.y = 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 = parentHeight - height - bottom\n }\n }\n\n\n if (leaferIsCreated) this.leafer.created = true\n return sizeChanged\n}\n\nLeafHelper.updatePositionLayout = function (leaf: UI): void {\n let hasPosition\n leaf.children.forEach(item => {\n if (item.position) {\n hasPosition = true\n item.__updatePositionLayout()\n LeafHelper.updateAllMatrix(item)\n item.isBranch ? BranchHelper.updateBounds(item) : LeafHelper.updateBounds(item)\n }\n })\n leaf.__hasPosition = hasPosition\n}\n"],"names":["positionParentChange","parent","__hasPosition","Plugin","add","UI","addAttr","defaultValue","decorateLeafAttr","key","attr","set","value","this","__setAttr","waitParentChange","doBoundsType","tempPoint","getPointData","prototype","__updatePositionLayout","sizeChanged","leaferIsCreated","position","boxBounds","parentBox","width","parentWidth","height","parentHeight","leafer","created","isString","AlignHelper","toPoint","left","top","right","bottom","hasLeft","isUndefined","hasTop","UnitConvert","number","x","resizeWidth","y","undefined","resizeHeight","LeafHelper","updatePositionLayout","leaf","hasPosition","children","forEach","item","updateAllMatrix","isBranch","BranchHelper","updateBounds"],"mappings":"kPAIA,SAASA,EAAqBC,GAC1BA,EAAOC,eAAgB,CAC3B,CCCAC,EAAOC,IAAI,WAAY,UAIvBC,EAAGC,QAAQ,YAAY,EDHjB,SAAuBC,GACzB,OAAOC,EAAiBD,EAAeE,GAAgBC,EAAK,CACxD,GAAAC,CAAIC,GACIC,KAAKC,UAAUL,EAAKG,KAChBA,GAAOC,KAAKE,iBAAiBf,GACjCgB,EAAaH,MAErB,IAER,GCHA,MAAMI,EAAYC,I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
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
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) this.waitParentChange(positionParentChange);
|
|
11
|
+
draw.doBoundsType(this);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
draw.Plugin.add("position", "resize");
|
|
17
|
+
draw.UI.addAttr("position", false, positionType);
|
|
18
|
+
const tempPoint = draw.getPointData();
|
|
19
|
+
draw.UI.prototype.__updatePositionLayout = function() {
|
|
20
|
+
let sizeChanged;
|
|
21
|
+
const {leaferIsCreated: leaferIsCreated, position: position, boxBounds: boxBounds} = this, parentBox = this.parent.boxBounds;
|
|
22
|
+
const {width: parentWidth, height: parentHeight} = parentBox, {width: width, height: height} = boxBounds;
|
|
23
|
+
if (leaferIsCreated) this.leafer.created = false;
|
|
24
|
+
if (draw.isString(position)) {
|
|
25
|
+
draw.AlignHelper.toPoint(position, boxBounds, parentBox, tempPoint, true);
|
|
26
|
+
this.set(tempPoint);
|
|
27
|
+
} else {
|
|
28
|
+
let {left: left, top: top, right: right, bottom: bottom} = position;
|
|
29
|
+
const hasLeft = !draw.isUndefined(left), hasTop = !draw.isUndefined(top);
|
|
30
|
+
if (hasLeft) {
|
|
31
|
+
left = draw.UnitConvert.number(left, parentWidth);
|
|
32
|
+
this.x = left;
|
|
33
|
+
}
|
|
34
|
+
if (!draw.isUndefined(right)) {
|
|
35
|
+
right = draw.UnitConvert.number(right, parentWidth);
|
|
36
|
+
if (hasLeft) this.resizeWidth(parentWidth - left - right), sizeChanged = true; else this.x = parentWidth - width - right;
|
|
37
|
+
}
|
|
38
|
+
if (hasTop) {
|
|
39
|
+
top = draw.UnitConvert.number(top, parentHeight);
|
|
40
|
+
this.y = top;
|
|
41
|
+
}
|
|
42
|
+
if (!draw.isUndefined(bottom)) {
|
|
43
|
+
bottom = draw.UnitConvert.number(bottom, parentHeight);
|
|
44
|
+
if (position.top !== undefined) this.resizeHeight(parentHeight - top - bottom),
|
|
45
|
+
sizeChanged = true; else this.y = parentHeight - height - bottom;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (leaferIsCreated) this.leafer.created = true;
|
|
49
|
+
return sizeChanged;
|
|
50
|
+
};
|
|
51
|
+
draw.LeafHelper.updatePositionLayout = function(leaf) {
|
|
52
|
+
let hasPosition;
|
|
53
|
+
leaf.children.forEach(item => {
|
|
54
|
+
if (item.position) {
|
|
55
|
+
hasPosition = true;
|
|
56
|
+
item.__updatePositionLayout();
|
|
57
|
+
draw.LeafHelper.updateAllMatrix(item);
|
|
58
|
+
item.isBranch ? draw.BranchHelper.updateBounds(item) : draw.LeafHelper.updateBounds(item);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
leaf.__hasPosition = hasPosition;
|
|
62
|
+
};
|
|
63
|
+
})(LeaferUI);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var t=require("@leafer-ui/draw");function e(t){t.__hasPosition=!0}require("@leafer-in/resize"),t.Plugin.add("position","resize"),t.UI.addAttr("position",!1,function(i){return t.decorateLeafAttr(i,i=>t.attr({set(n){this.__setAttr(i,n)&&(n&&this.waitParentChange(e),t.doBoundsType(this))}}))});const i=t.getPointData();t.UI.prototype.__updatePositionLayout=function(){let e;const{leaferIsCreated:n,position:o,boxBounds:r}=this,s=this.parent.boxBounds,{width:a,height:d}=s,{width:h,height:u}=r;if(n&&(this.leafer.created=!1),t.isString(o))t.AlignHelper.toPoint(o,r,s,i,!0),this.set(i);else{let{left:i,top:n,right:r,bottom:s}=o;const p=!t.isUndefined(i),f=!t.isUndefined(n);p&&(i=t.UnitConvert.number(i,a),this.x=i),t.isUndefined(r)||(r=t.UnitConvert.number(r,a),p?(this.resizeWidth(a-i-r),e=!0):this.x=a-h-r),f&&(n=t.UnitConvert.number(n,d),this.y=n),t.isUndefined(s)||(s=t.UnitConvert.number(s,d),void 0!==o.top?(this.resizeHeight(d-n-s),e=!0):this.y=d-u-s)}return n&&(this.leafer.created=!0),e},t.LeafHelper.updatePositionLayout=function(e){let i;e.children.forEach(e=>{e.position&&(i=!0,e.__updatePositionLayout(),t.LeafHelper.updateAllMatrix(e),e.isBranch?t.BranchHelper.updateBounds(e):t.LeafHelper.updateBounds(e))}),e.__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 } 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 let sizeChanged: boolean\n const { leaferIsCreated, position, boxBounds } = this, parentBox = this.parent.boxBounds\n const { width: parentWidth, height: parentHeight } = parentBox, { width, height } = boxBounds\n\n if (leaferIsCreated) this.leafer.created = false // 拦截布局更新通知,进行手动更新布局\n\n if (isString(position)) {\n\n AlignHelper.toPoint(position, boxBounds, parentBox, tempPoint, true)\n this.set(tempPoint)\n\n } else {\n\n let { left, top, right, bottom } = position\n const hasLeft = !isUndefined(left), hasTop = !isUndefined(top)\n\n // 布局\n if (hasLeft) {\n left = UnitConvert.number(left, parentWidth)\n this.x = 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 = parentWidth - width - right\n\n }\n\n if (hasTop) {\n top = UnitConvert.number(top, parentHeight)\n this.y = 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 = parentHeight - height - bottom\n }\n }\n\n\n if (leaferIsCreated) this.leafer.created = true\n return sizeChanged\n}\n\nLeafHelper.updatePositionLayout = function (leaf: UI): void {\n let hasPosition\n leaf.children.forEach(item => {\n if (item.position) {\n hasPosition = true\n item.__updatePositionLayout()\n LeafHelper.updateAllMatrix(item)\n item.isBranch ? BranchHelper.updateBounds(item) : LeafHelper.updateBounds(item)\n }\n })\n leaf.__hasPosition = hasPosition\n}\n"],"names":["positionParentChange","parent","__hasPosition","Plugin","add","UI","addAttr","defaultValue","decorateLeafAttr","key","attr","set","value","this","__setAttr","waitParentChange","doBoundsType","tempPoint","getPointData","prototype","__updatePositionLayout","sizeChanged","leaferIsCreated","position","boxBounds","parentBox","width","parentWidth","height","parentHeight","leafer","created","isString","AlignHelper","toPoint","left","top","right","bottom","hasLeft","isUndefined","hasTop","UnitConvert","number","x","resizeWidth","y","undefined","resizeHeight","LeafHelper","updatePositionLayout","leaf","hasPosition","children","forEach","item","updateAllMatrix","isBranch","BranchHelper","updateBounds"],"mappings":"8CAIA,SAASA,EAAqBC,GAC1BA,EAAOC,eAAgB,CAC3B,8BCCAC,EAAAA,OAAOC,IAAI,WAAY,UAIvB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,EAE9C,CAIA,OADIhB,IAAiBT,KAAKiB,OAAOC,SAAU,GACpCV,CACX,EAEA4B,EAAAA,WAAWC,qBAAuB,SAAUC,GACxC,IAAIC,EACJD,EAAKE,SAASC,QAAQC,IACdA,EAAKhC,WACL6B,GAAc,EACdG,EAAKnC,yBACL6B,EAAAA,WAAWO,gBAAgBD,GAC3BA,EAAKE,SAAWC,EAAAA,aAAaC,aAAaJ,GAAQN,EAAAA,WAAWU,aAAaJ,MAGlFJ,EAAKjD,cAAgBkD,CACzB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(t){"use strict";function e(t){t.__hasPosition=!0}t.Plugin.add("position","resize"),t.UI.addAttr("position",!1,function(i){return t.decorateLeafAttr(i,i=>t.attr({set(n){this.__setAttr(i,n)&&(n&&this.waitParentChange(e),t.doBoundsType(this))}}))});const i=t.getPointData();t.UI.prototype.__updatePositionLayout=function(){let e;const{leaferIsCreated:n,position:o,boxBounds:s}=this,r=this.parent.boxBounds,{width:a,height:d}=r,{width:h,height:u}=s;if(n&&(this.leafer.created=!1),t.isString(o))t.AlignHelper.toPoint(o,s,r,i,!0),this.set(i);else{let{left:i,top:n,right:s,bottom:r}=o;const p=!t.isUndefined(i),f=!t.isUndefined(n);p&&(i=t.UnitConvert.number(i,a),this.x=i),t.isUndefined(s)||(s=t.UnitConvert.number(s,a),p?(this.resizeWidth(a-i-s),e=!0):this.x=a-h-s),f&&(n=t.UnitConvert.number(n,d),this.y=n),t.isUndefined(r)||(r=t.UnitConvert.number(r,d),void 0!==o.top?(this.resizeHeight(d-n-r),e=!0):this.y=d-u-r)}return n&&(this.leafer.created=!0),e},t.LeafHelper.updatePositionLayout=function(e){let i;e.children.forEach(e=>{e.position&&(i=!0,e.__updatePositionLayout(),t.LeafHelper.updateAllMatrix(e),e.isBranch?t.BranchHelper.updateBounds(e):t.LeafHelper.updateBounds(e))}),e.__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 } 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 let sizeChanged: boolean\n const { leaferIsCreated, position, boxBounds } = this, parentBox = this.parent.boxBounds\n const { width: parentWidth, height: parentHeight } = parentBox, { width, height } = boxBounds\n\n if (leaferIsCreated) this.leafer.created = false // 拦截布局更新通知,进行手动更新布局\n\n if (isString(position)) {\n\n AlignHelper.toPoint(position, boxBounds, parentBox, tempPoint, true)\n this.set(tempPoint)\n\n } else {\n\n let { left, top, right, bottom } = position\n const hasLeft = !isUndefined(left), hasTop = !isUndefined(top)\n\n // 布局\n if (hasLeft) {\n left = UnitConvert.number(left, parentWidth)\n this.x = 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 = parentWidth - width - right\n\n }\n\n if (hasTop) {\n top = UnitConvert.number(top, parentHeight)\n this.y = 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 = parentHeight - height - bottom\n }\n }\n\n\n if (leaferIsCreated) this.leafer.created = true\n return sizeChanged\n}\n\nLeafHelper.updatePositionLayout = function (leaf: UI): void {\n let hasPosition\n leaf.children.forEach(item => {\n if (item.position) {\n hasPosition = true\n item.__updatePositionLayout()\n LeafHelper.updateAllMatrix(item)\n item.isBranch ? BranchHelper.updateBounds(item) : LeafHelper.updateBounds(item)\n }\n })\n leaf.__hasPosition = hasPosition\n}\n"],"names":["positionParentChange","parent","__hasPosition","Plugin","add","UI","addAttr","defaultValue","decorateLeafAttr","key","attr","set","value","this","__setAttr","waitParentChange","doBoundsType","tempPoint","getPointData","prototype","__updatePositionLayout","sizeChanged","leaferIsCreated","position","boxBounds","parentBox","width","parentWidth","height","parentHeight","leafer","created","isString","AlignHelper","toPoint","left","top","right","bottom","hasLeft","isUndefined","hasTop","UnitConvert","number","x","resizeWidth","y","undefined","resizeHeight","LeafHelper","updatePositionLayout","leaf","hasPosition","children","forEach","item","updateAllMatrix","isBranch","BranchHelper","updateBounds"],"mappings":"0BAIA,SAASA,EAAqBC,GAC1BA,EAAOC,eAAgB,CAC3B,CCCAC,EAAAA,OAAOC,IAAI,WAAY,UAIvBC,EAAAA,GAAGC,QAAQ,YAAY,EDHjB,SAAuBC,GACzB,OAAOC,mBAAiBD,EAAeE,GAAgBC,EAAAA,KAAK,CACxD,GAAAC,CAAIC,GACIC,KAAKC,UAAUL,EAAKG,KAChBA,GAAOC,KAAKE,iBAAiBf,GACjCgB,EAAAA,aAAaH,MAErB,IAER,GCHA,MAAMI,EAAYC,EAAAA,eAElBb,EAAAA,GAAGc,UAAUC,uBAAyB,WAElC,IAAIC,EACJ,MAAMC,gBAAEA,EAAeC,SAAEA,EAAQC,UAAEA,GAAcX,KAAMY,EAAYZ,KAAKZ,OAAOuB,WACvEE,MAAOC,EAAaC,OAAQC,GAAiBJ,GAAWC,MAAEA,EAAK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
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.3.2",
|
|
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.2",
|
|
38
|
+
"@leafer-in/resize": "^2.3.2",
|
|
39
|
+
"@leafer-ui/interface": "^2.3.2",
|
|
40
|
+
"@leafer-in/interface": "^2.3.2"
|
|
41
|
+
}
|
|
6
42
|
}
|
package/src/decorate.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { attr, decorateLeafAttr, doBoundsType } from '@leafer-ui/draw'
|
|
2
|
+
import { ILeaf, IValue } from '@leafer/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) this.waitParentChange(positionParentChange)
|
|
14
|
+
doBoundsType(this)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}))
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { UI, Plugin, UnitConvert, isUndefined, LeafHelper, BranchHelper, isString, AlignHelper, getPointData } from '@leafer-ui/draw'
|
|
2
|
+
|
|
3
|
+
import '@leafer-in/resize'
|
|
4
|
+
|
|
5
|
+
import { positionType } from './decorate'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Plugin.add('position', 'resize')
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
// addAttr
|
|
12
|
+
UI.addAttr('position', false, positionType)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const tempPoint = getPointData()
|
|
16
|
+
|
|
17
|
+
UI.prototype.__updatePositionLayout = function (): boolean {
|
|
18
|
+
|
|
19
|
+
let sizeChanged: boolean
|
|
20
|
+
const { leaferIsCreated, position, boxBounds } = this, parentBox = this.parent.boxBounds
|
|
21
|
+
const { width: parentWidth, height: parentHeight } = parentBox, { width, height } = boxBounds
|
|
22
|
+
|
|
23
|
+
if (leaferIsCreated) this.leafer.created = false // 拦截布局更新通知,进行手动更新布局
|
|
24
|
+
|
|
25
|
+
if (isString(position)) {
|
|
26
|
+
|
|
27
|
+
AlignHelper.toPoint(position, boxBounds, parentBox, tempPoint, true)
|
|
28
|
+
this.set(tempPoint)
|
|
29
|
+
|
|
30
|
+
} else {
|
|
31
|
+
|
|
32
|
+
let { left, top, right, bottom } = position
|
|
33
|
+
const hasLeft = !isUndefined(left), hasTop = !isUndefined(top)
|
|
34
|
+
|
|
35
|
+
// 布局
|
|
36
|
+
if (hasLeft) {
|
|
37
|
+
left = UnitConvert.number(left, parentWidth)
|
|
38
|
+
this.x = left
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!isUndefined(right)) {
|
|
42
|
+
right = UnitConvert.number(right, parentWidth)
|
|
43
|
+
|
|
44
|
+
if (hasLeft) this.resizeWidth(parentWidth - (left as number) - right), sizeChanged = true
|
|
45
|
+
else this.x = parentWidth - width - right
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (hasTop) {
|
|
50
|
+
top = UnitConvert.number(top, parentHeight)
|
|
51
|
+
this.y = top
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!isUndefined(bottom)) {
|
|
55
|
+
bottom = UnitConvert.number(bottom, parentHeight)
|
|
56
|
+
|
|
57
|
+
if (position.top !== undefined) this.resizeHeight(parentHeight - (top as number) - bottom), sizeChanged = true
|
|
58
|
+
else this.y = parentHeight - height - bottom
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if (leaferIsCreated) this.leafer.created = true
|
|
64
|
+
return sizeChanged
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
LeafHelper.updatePositionLayout = function (leaf: UI): void {
|
|
68
|
+
let hasPosition
|
|
69
|
+
leaf.children.forEach(item => {
|
|
70
|
+
if (item.position) {
|
|
71
|
+
hasPosition = true
|
|
72
|
+
item.__updatePositionLayout()
|
|
73
|
+
LeafHelper.updateAllMatrix(item)
|
|
74
|
+
item.isBranch ? BranchHelper.updateBounds(item) : LeafHelper.updateBounds(item)
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
leaf.__hasPosition = hasPosition
|
|
78
|
+
}
|
package/types/index.d.ts
ADDED