@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 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) this.waitParentChange(positionParentChange);
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
- 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;
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
- draw.AlignHelper.toPoint(position, boxBounds, parentBox, tempPoint, true);
35
- this.set(tempPoint);
45
+ align = position;
36
46
  } else {
37
47
  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;
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;
@@ -1,4 +1,4 @@
1
- import { decorateLeafAttr, attr, doBoundsType, Plugin, UI, getPointData, isString, AlignHelper, isUndefined, UnitConvert, LeafHelper, BranchHelper } from "@leafer-ui/draw";
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) this.waitParentChange(positionParentChange);
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
- 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;
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
- AlignHelper.toPoint(position, boxBounds, parentBox, tempPoint, true);
33
- this.set(tempPoint);
43
+ align = position;
34
44
  } else {
35
45
  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;
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;
@@ -1,2 +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};
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 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,IAElBb,EAAGc,UAAUC,uBAAyB,WAElC,IAAIC,EACJ,MAAMC,gBAAEA,EAAeC,SAAEA,EAAQC,UAAEA,GAAcX,KAAMY,EAAYZ,KAAKZ,OAAOuB,WACvEE,MAAOC,EAAaC,OAAQC,GAAiBJ,GAAWC,MAAEA,EAAKE,OAAEA,GAAWJ,EAIpF,GAFIF,IAAiBT,KAAKiB,OAAOC,SAAU,GAEvCC,EAAST,GAETU,EAAYC,QAAQX,EAAUC,EAAWC,EAAWR,GAAW,GAC/DJ,KAAKF,IAAIM,OAEN,CAEH,IAAIkB,KAAEA,EAAIC,IAAEA,EAAGC,MAAEA,EAAKC,OAAEA,GAAWf,EACnC,MAAMgB,GAAWC,EAAYL,GAAOM,GAAUD,EAAYJ,GAGtDG,IACAJ,EAAOO,EAAYC,OAAOR,EAAMR,GAChCd,KAAK+B,EAAIT,GAGRK,EAAYH,KACbA,EAAQK,EAAYC,OAAON,EAAOV,GAE9BY,GAAS1B,KAAKgC,YAAYlB,EAAeQ,EAAkBE,GAAQhB,GAAc,GAChFR,KAAK+B,EAAIjB,EAAcD,EAAQW,GAIpCI,IACAL,EAAMM,EAAYC,OAAOP,EAAKP,GAC9BhB,KAAKiC,EAAIV,GAGRI,EAAYF,KACbA,EAASI,EAAYC,OAAOL,EAAQT,QAEfkB,IAAjBxB,EAASa,KAAmBvB,KAAKmC,aAAanB,EAAgBO,EAAiBE,GAASjB,GAAc,GACrGR,KAAKiC,EAAIjB,EAAeD,EAASU,EAE9C,CAIA,OADIhB,IAAiBT,KAAKiB,OAAOC,SAAU,GACpCV,CACX,EAEA4B,EAAWC,qBAAuB,SAAUC,GACxC,IAAIC,EACJD,EAAKE,SAASC,QAAQC,IACdA,EAAKhC,WACL6B,GAAc,EACdG,EAAKnC,yBACL6B,EAAWO,gBAAgBD,GAC3BA,EAAKE,SAAWC,EAAaC,aAAaJ,GAAQN,EAAWU,aAAaJ,MAGlFJ,EAAKjD,cAAgBkD,CACzB"}
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,E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IAAMY,EAASZ,GAClHoD,EAAKvC,eAAcuC,EAAKvC,kBAAe6B,GAE5C7B,IAAiBuC,EAAKvC,eAClBA,GAAcA,EAAa2C,IAAI3C,EAAa3B,SAAWkE,EAAKlE,OAASuE,EAAYC,MAAQD,EAAYE,MAAOP,EAAKhD,wBACjHgD,EAAKvC,eACLuC,EAAKvC,aAAa+C,GAAGR,EAAKvC,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) this.waitParentChange(positionParentChange);
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
- 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;
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
- draw.AlignHelper.toPoint(position, boxBounds, parentBox, tempPoint, true);
26
- this.set(tempPoint);
36
+ align = position;
27
37
  } else {
28
38
  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;
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;
@@ -1,2 +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};
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 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,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,EAAKE,OAAEA,GAAWJ,EAIpF,GAFIF,IAAiBT,KAAKiB,OAAOC,SAAU,GAEvCC,EAAAA,SAAST,GAETU,EAAAA,YAAYC,QAAQX,EAAUC,EAAWC,EAAWR,GAAW,GAC/DJ,KAAKF,IAAIM,OAEN,CAEH,IAAIkB,KAAEA,EAAIC,IAAEA,EAAGC,MAAEA,EAAKC,OAAEA,GAAWf,EACnC,MAAMgB,GAAWC,cAAYL,GAAOM,GAAUD,EAAAA,YAAYJ,GAGtDG,IACAJ,EAAOO,EAAAA,YAAYC,OAAOR,EAAMR,GAChCd,KAAK+B,EAAIT,GAGRK,EAAAA,YAAYH,KACbA,EAAQK,EAAAA,YAAYC,OAAON,EAAOV,GAE9BY,GAAS1B,KAAKgC,YAAYlB,EAAeQ,EAAkBE,GAAQhB,GAAc,GAChFR,KAAK+B,EAAIjB,EAAcD,EAAQW,GAIpCI,IACAL,EAAMM,EAAAA,YAAYC,OAAOP,EAAKP,GAC9BhB,KAAKiC,EAAIV,GAGRI,EAAAA,YAAYF,KACbA,EAASI,EAAAA,YAAYC,OAAOL,EAAQT,QAEfkB,IAAjBxB,EAASa,KAAmBvB,KAAKmC,aAAanB,EAAgBO,EAAiBE,GAASjB,GAAc,GACrGR,KAAKiC,EAAIjB,EAAeD,EAASU,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"}
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,KAAEA,EAAIC,IA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AASZ,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"}
@@ -1,2 +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);
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
@@ -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 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,SA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KAAKmC,aAAanB,EAAgBO,EAAiBE,GAASjB,GAAc,GACrGR,KAAKiC,EAAIjB,EAAeD,EAASU,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"}
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,o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K7D,4BAGbgD,EAAKjE,cAAgB2E,CACzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/position",
3
- "version": "2.3.2",
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.2",
38
- "@leafer-in/resize": "^2.3.2",
39
- "@leafer-ui/interface": "^2.3.2",
40
- "@leafer-in/interface": "^2.3.2"
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) this.waitParentChange(positionParentChange)
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 { UI, Plugin, UnitConvert, isUndefined, LeafHelper, BranchHelper, isString, AlignHelper, getPointData } from '@leafer-ui/draw'
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
- let sizeChanged: boolean
20
- const { leaferIsCreated, position, boxBounds } = this, parentBox = this.parent.boxBounds
21
- const { width: parentWidth, height: parentHeight } = parentBox, { width, height } = boxBounds
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
- AlignHelper.toPoint(position, boxBounds, parentBox, tempPoint, true)
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 (!isUndefined(right)) {
42
- right = UnitConvert.number(right, parentWidth)
40
+ if (position.align) {
43
41
 
44
- if (hasLeft) this.resizeWidth(parentWidth - (left as number) - right), sizeChanged = true
45
- else this.x = parentWidth - width - right
42
+ align = position.align
46
43
 
47
- }
44
+ } else {
48
45
 
49
- if (hasTop) {
50
- top = UnitConvert.number(top, parentHeight)
51
- this.y = top
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
- if (!isUndefined(bottom)) {
55
- bottom = UnitConvert.number(bottom, parentHeight)
69
+ if (!isUndefined(bottom)) {
70
+ bottom = UnitConvert.number(bottom, parentHeight)
56
71
 
57
- if (position.top !== undefined) this.resizeHeight(parentHeight - (top as number) - bottom), sizeChanged = true
58
- else this.y = parentHeight - height - bottom
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