@tmagic/stage 1.1.0-beta.3 → 1.1.0-beta.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.
@@ -4,7 +4,7 @@ import Moveable from 'moveable';
4
4
  import { GuidesType, Mode } from './const';
5
5
  import StageCore from './StageCore';
6
6
  import StageMask from './StageMask';
7
- import type { SortEventData, StageDragResizeConfig } from './types';
7
+ import type { StageDragResizeConfig } from './types';
8
8
  /**
9
9
  * 选中框
10
10
  */
@@ -68,17 +68,3 @@ export default class StageDragResize extends EventEmitter {
68
68
  private destroyGhostEl;
69
69
  private getOptions;
70
70
  }
71
- /**
72
- * 下移组件位置
73
- * @param {number} deltaTop 偏移量
74
- * @param {Object} detail 当前选中的组件配置
75
- */
76
- export declare const down: (deltaTop: number, target: HTMLElement | SVGElement) => SortEventData | void;
77
- /**
78
- * 上移组件位置
79
- * @param {Array} brothers 处于同一容器下的所有子组件配置
80
- * @param {number} index 当前组件所处的位置
81
- * @param {number} deltaTop 偏移量
82
- * @param {Object} detail 当前选中的组件配置
83
- */
84
- export declare const up: (deltaTop: number, target: HTMLElement | SVGElement) => SortEventData | void;
@@ -1,5 +1,5 @@
1
1
  import { Mode } from './const';
2
- import type { Offset } from './types';
2
+ import type { Offset, SortEventData } from './types';
3
3
  export declare const getOffset: (el: HTMLElement) => Offset;
4
4
  export declare const getTargetElStyle: (el: HTMLElement) => string;
5
5
  export declare const getAbsolutePosition: (el: HTMLElement, { top, left }: Offset) => {
@@ -16,3 +16,17 @@ export declare const getScrollParent: (element: HTMLElement, includeHidden?: boo
16
16
  export declare const removeSelectedClassName: (doc: Document) => void;
17
17
  export declare const addSelectedClassName: (el: Element, doc: Document) => void;
18
18
  export declare const calcValueByFontsize: (doc: Document, value: number) => number;
19
+ /**
20
+ * 下移组件位置
21
+ * @param {number} deltaTop 偏移量
22
+ * @param {Object} detail 当前选中的组件配置
23
+ */
24
+ export declare const down: (deltaTop: number, target: HTMLElement | SVGElement) => SortEventData | void;
25
+ /**
26
+ * 上移组件位置
27
+ * @param {Array} brothers 处于同一容器下的所有子组件配置
28
+ * @param {number} index 当前组件所处的位置
29
+ * @param {number} deltaTop 偏移量
30
+ * @param {Object} detail 当前选中的组件配置
31
+ */
32
+ export declare const up: (deltaTop: number, target: HTMLElement | SVGElement) => SortEventData | void;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.0-beta.3",
2
+ "version": "1.1.0-beta.4",
3
3
  "name": "@tmagic/stage",
4
4
  "sideEffects": [
5
5
  "dist/*"
@@ -27,9 +27,9 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@scena/guides": "^0.17.0",
30
- "@tmagic/core": "1.1.0-beta.3",
31
- "@tmagic/schema": "1.1.0-beta.3",
32
- "@tmagic/utils": "1.1.0-beta.3",
30
+ "@tmagic/core": "1.1.0-beta.4",
31
+ "@tmagic/schema": "1.1.0-beta.4",
32
+ "@tmagic/utils": "1.1.0-beta.4",
33
33
  "events": "^3.3.0",
34
34
  "keycon": "^1.1.2",
35
35
  "lodash-es": "^4.17.21",
@@ -28,8 +28,8 @@ import { removeClassNameByClassName } from '@tmagic/utils';
28
28
  import { DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, Mode, ZIndex } from './const';
29
29
  import StageCore from './StageCore';
30
30
  import StageMask from './StageMask';
31
- import type { SortEventData, StageDragResizeConfig } from './types';
32
- import { calcValueByFontsize, getAbsolutePosition, getMode, getOffset, getTargetElStyle } from './util';
31
+ import type { StageDragResizeConfig } from './types';
32
+ import { calcValueByFontsize, down, getAbsolutePosition, getMode, getOffset, getTargetElStyle, up } from './util';
33
33
 
34
34
  /** 拖动状态 */
35
35
  enum ActionStatus {
@@ -558,7 +558,7 @@ export default class StageDragResize extends EventEmitter {
558
558
  top: 0,
559
559
  // 设置0的话无法移动到left为0,所以只能设置为-1
560
560
  left: -1,
561
- right: this.container.clientWidth,
561
+ right: this.container.clientWidth - 1,
562
562
  bottom: this.container.clientHeight,
563
563
  ...(moveableOptions.bounds || {}),
564
564
  },
@@ -567,73 +567,3 @@ export default class StageDragResize extends EventEmitter {
567
567
  };
568
568
  }
569
569
  }
570
-
571
- /**
572
- * 下移组件位置
573
- * @param {number} deltaTop 偏移量
574
- * @param {Object} detail 当前选中的组件配置
575
- */
576
- export const down = (deltaTop: number, target: HTMLElement | SVGElement): SortEventData | void => {
577
- let swapIndex = 0;
578
- let addUpH = target.clientHeight;
579
- const brothers = Array.from(target.parentNode?.children || []).filter(
580
- (node) => !node.id.startsWith(GHOST_EL_ID_PREFIX),
581
- );
582
- const index = brothers.indexOf(target);
583
- // 往下移动
584
- const downEls = brothers.slice(index + 1) as HTMLElement[];
585
-
586
- for (let i = 0; i < downEls.length; i++) {
587
- const ele = downEls[i];
588
- // 是 fixed 不做处理
589
- if (ele.style?.position === 'fixed') {
590
- continue;
591
- }
592
- addUpH += ele.clientHeight / 2;
593
- if (deltaTop <= addUpH) {
594
- break;
595
- }
596
- addUpH += ele.clientHeight / 2;
597
- swapIndex = i;
598
- }
599
- return {
600
- src: target.id,
601
- dist: downEls.length && swapIndex > -1 ? downEls[swapIndex].id : target.id,
602
- };
603
- };
604
-
605
- /**
606
- * 上移组件位置
607
- * @param {Array} brothers 处于同一容器下的所有子组件配置
608
- * @param {number} index 当前组件所处的位置
609
- * @param {number} deltaTop 偏移量
610
- * @param {Object} detail 当前选中的组件配置
611
- */
612
- export const up = (deltaTop: number, target: HTMLElement | SVGElement): SortEventData | void => {
613
- const brothers = Array.from(target.parentNode?.children || []).filter(
614
- (node) => !node.id.startsWith(GHOST_EL_ID_PREFIX),
615
- );
616
- const index = brothers.indexOf(target);
617
- // 往上移动
618
- const upEls = brothers.slice(0, index) as HTMLElement[];
619
-
620
- let addUpH = target.clientHeight;
621
- let swapIndex = upEls.length - 1;
622
-
623
- for (let i = upEls.length - 1; i >= 0; i--) {
624
- const ele = upEls[i];
625
- if (!ele) continue;
626
- // 是 fixed 不做处理
627
- if (ele.style.position === 'fixed') continue;
628
-
629
- addUpH += ele.clientHeight / 2;
630
- if (-deltaTop <= addUpH) break;
631
- addUpH += ele.clientHeight / 2;
632
-
633
- swapIndex = i;
634
- }
635
- return {
636
- src: target.id,
637
- dist: upEls.length && swapIndex > -1 ? upEls[swapIndex].id : target.id,
638
- };
639
- };
package/src/util.ts CHANGED
@@ -17,8 +17,8 @@
17
17
  */
18
18
  import { removeClassName } from '@tmagic/utils';
19
19
 
20
- import { Mode, SELECTED_CLASS, ZIndex } from './const';
21
- import type { Offset } from './types';
20
+ import { GHOST_EL_ID_PREFIX, Mode, SELECTED_CLASS, ZIndex } from './const';
21
+ import type { Offset, SortEventData } from './types';
22
22
 
23
23
  const getParents = (el: Element, relative: Element) => {
24
24
  let cur: Element | null = el.parentElement;
@@ -159,3 +159,73 @@ export const calcValueByFontsize = (doc: Document, value: number) => {
159
159
 
160
160
  return value;
161
161
  };
162
+
163
+ /**
164
+ * 下移组件位置
165
+ * @param {number} deltaTop 偏移量
166
+ * @param {Object} detail 当前选中的组件配置
167
+ */
168
+ export const down = (deltaTop: number, target: HTMLElement | SVGElement): SortEventData | void => {
169
+ let swapIndex = 0;
170
+ let addUpH = target.clientHeight;
171
+ const brothers = Array.from(target.parentNode?.children || []).filter(
172
+ (node) => !node.id.startsWith(GHOST_EL_ID_PREFIX),
173
+ );
174
+ const index = brothers.indexOf(target);
175
+ // 往下移动
176
+ const downEls = brothers.slice(index + 1) as HTMLElement[];
177
+
178
+ for (let i = 0; i < downEls.length; i++) {
179
+ const ele = downEls[i];
180
+ // 是 fixed 不做处理
181
+ if (ele.style?.position === 'fixed') {
182
+ continue;
183
+ }
184
+ addUpH += ele.clientHeight / 2;
185
+ if (deltaTop <= addUpH) {
186
+ break;
187
+ }
188
+ addUpH += ele.clientHeight / 2;
189
+ swapIndex = i;
190
+ }
191
+ return {
192
+ src: target.id,
193
+ dist: downEls.length && swapIndex > -1 ? downEls[swapIndex].id : target.id,
194
+ };
195
+ };
196
+
197
+ /**
198
+ * 上移组件位置
199
+ * @param {Array} brothers 处于同一容器下的所有子组件配置
200
+ * @param {number} index 当前组件所处的位置
201
+ * @param {number} deltaTop 偏移量
202
+ * @param {Object} detail 当前选中的组件配置
203
+ */
204
+ export const up = (deltaTop: number, target: HTMLElement | SVGElement): SortEventData | void => {
205
+ const brothers = Array.from(target.parentNode?.children || []).filter(
206
+ (node) => !node.id.startsWith(GHOST_EL_ID_PREFIX),
207
+ );
208
+ const index = brothers.indexOf(target);
209
+ // 往上移动
210
+ const upEls = brothers.slice(0, index) as HTMLElement[];
211
+
212
+ let addUpH = target.clientHeight;
213
+ let swapIndex = upEls.length - 1;
214
+
215
+ for (let i = upEls.length - 1; i >= 0; i--) {
216
+ const ele = upEls[i];
217
+ if (!ele) continue;
218
+ // 是 fixed 不做处理
219
+ if (ele.style.position === 'fixed') continue;
220
+
221
+ addUpH += ele.clientHeight / 2;
222
+ if (-deltaTop <= addUpH) break;
223
+ addUpH += ele.clientHeight / 2;
224
+
225
+ swapIndex = i;
226
+ }
227
+ return {
228
+ src: target.id,
229
+ dist: upEls.length && swapIndex > -1 ? upEls[swapIndex].id : target.id,
230
+ };
231
+ };