@tmagic/stage 1.3.15 → 1.4.0-beta.1

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/README.md CHANGED
@@ -35,7 +35,7 @@ mask是一个盖在画布区域的一个蒙层,主要作用是隔离鼠标事
35
35
  ## ActionManager
36
36
  - 负责监听鼠标和键盘事件,基于这些事件,形成单选、多选、高亮行为。主要监听的是蒙层上的鼠标事件,通过StageRender.getElementsFromPoint计算获得鼠标下方的组件,实现事件监听和实际组件的解构。
37
37
  - 向上负责跟StageCore双向通信,提供接口供core调用,并向core抛出事件
38
- - 向下管理StageDragResize、StageMultiDragResize、StageHightlight这三个单选、多选、高亮类,让它们协同工作
38
+ - 向下管理StageDragResize、StageMultiDragResize、StageHighlight这三个单选、多选、高亮类,让它们协同工作
39
39
  <br/><br/>
40
40
  ## StageDragResize
41
41
  负责单选相关逻辑,拖拽、改变大小、旋转等行为是依赖于开源库Moveable实现的,这些行为并不是直接作用于组件本身,而是在蒙层上创建了一个跟组件同等大小的边框div,实际拖拽的是边框div,在拖拽过程中同步更新组件。
@@ -47,7 +47,7 @@ mask是一个盖在画布区域的一个蒙层,主要作用是隔离鼠标事
47
47
  ## StageMultiDragResize
48
48
  功能跟StageDragResize类似,只是这个类是负责多选操作的,通过ctrl健选中多个组件,多选状态下不支持通过表单配置组件。
49
49
  <br/><br/>
50
- ## StageHightlight
50
+ ## StageHighlight
51
51
  在鼠标经过画布中的组件、或者鼠标经过组件目录树中的组件时,会触发组件高亮,高亮也是通过moveable实现的,这个类主要负责初始化moveable并管理高亮状态。
52
52
  <br/><br/>
53
53
  ## MoveableOptionsManager
@@ -302,7 +302,7 @@ class TargetShadow {
302
302
  }
303
303
  updateEl(target, src) {
304
304
  const el = src || globalThis.document.createElement("div");
305
- el.id = `${this.idPrefix}${target.id}`;
305
+ el.id = `${this.idPrefix}_${target.id}`;
306
306
  el.style.cssText = getTargetElStyle(target, this.zIndex);
307
307
  if (typeof this.updateDragEl === "function") {
308
308
  this.updateDragEl(el, target, this.container);
@@ -478,6 +478,7 @@ class DragResizeHelper {
478
478
  */
479
479
  onResizeGroup(e) {
480
480
  const { events } = e;
481
+ this.moveableHelper.onResizeGroup(e);
481
482
  events.forEach((ev) => {
482
483
  const { width, height, beforeTranslate } = ev.drag;
483
484
  const frameSnapShot = this.framesSnapShot.find(
@@ -499,23 +500,23 @@ class DragResizeHelper {
499
500
  targeEl.style.width = `${width}px`;
500
501
  targeEl.style.height = `${height}px`;
501
502
  });
502
- this.moveableHelper.onResizeGroup(e);
503
503
  }
504
504
  onDragGroupStart(e) {
505
- const { events } = e;
506
505
  this.moveableHelper.onDragGroupStart(e);
506
+ const { events } = e;
507
507
  this.setFramesSnapShot(events);
508
508
  }
509
509
  onDragGroup(e) {
510
+ this.moveableHelper.onDragGroup(e);
510
511
  const { events } = e;
511
512
  events.forEach((ev) => {
512
513
  const frameSnapShot = this.framesSnapShot.find(
513
- (frameItem) => frameItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
514
+ (frameItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(frameItem.id)
514
515
  );
515
516
  if (!frameSnapShot)
516
517
  return;
517
518
  const targeEl = this.targetList.find(
518
- (targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
519
+ (targetItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(targetItem.id)
519
520
  );
520
521
  if (!targeEl)
521
522
  return;
@@ -526,7 +527,6 @@ class DragResizeHelper {
526
527
  targeEl.style.top = `${frameSnapShot.top + ev.beforeTranslate[1] - marginTop}px`;
527
528
  }
528
529
  });
529
- this.moveableHelper.onDragGroup(e);
530
530
  }
531
531
  getUpdatedElRect(el, parentEl, doc) {
532
532
  const offset = this.mode === Mode.SORTABLE ? { left: 0, top: 0 } : { left: el.offsetLeft, top: el.offsetTop };
@@ -561,7 +561,7 @@ class DragResizeHelper {
561
561
  return;
562
562
  events.forEach((ev) => {
563
563
  const matchEventTarget = this.targetList.find(
564
- (targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
564
+ (targetItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(targetItem.id)
565
565
  );
566
566
  if (!matchEventTarget)
567
567
  return;
@@ -622,7 +622,7 @@ const MoveableActionsAble = (handler) => ({
622
622
  left: 0px;
623
623
  top: 0px;
624
624
  will-change: transform;
625
- transform-origin: 0px 0px;
625
+ transform-origin: 60px 28px;
626
626
  display: flex;
627
627
  }
628
628
  ${ableCss}
@@ -1305,6 +1305,10 @@ class StageMultiDragResize extends MoveableOptionsManager {
1305
1305
  this.dragResizeHelper.onDragGroup(e);
1306
1306
  this.dragStatus = StageDragStatus.ING;
1307
1307
  }).on("dragGroupEnd", () => {
1308
+ if (timeout) {
1309
+ globalThis.clearTimeout(timeout);
1310
+ timeout = void 0;
1311
+ }
1308
1312
  const parentEl = this.markContainerEnd();
1309
1313
  this.update(false, parentEl);
1310
1314
  this.dragStatus = StageDragStatus.END;
@@ -299,7 +299,7 @@
299
299
  }
300
300
  updateEl(target, src) {
301
301
  const el = src || globalThis.document.createElement("div");
302
- el.id = `${this.idPrefix}${target.id}`;
302
+ el.id = `${this.idPrefix}_${target.id}`;
303
303
  el.style.cssText = getTargetElStyle(target, this.zIndex);
304
304
  if (typeof this.updateDragEl === "function") {
305
305
  this.updateDragEl(el, target, this.container);
@@ -475,6 +475,7 @@
475
475
  */
476
476
  onResizeGroup(e) {
477
477
  const { events } = e;
478
+ this.moveableHelper.onResizeGroup(e);
478
479
  events.forEach((ev) => {
479
480
  const { width, height, beforeTranslate } = ev.drag;
480
481
  const frameSnapShot = this.framesSnapShot.find(
@@ -496,23 +497,23 @@
496
497
  targeEl.style.width = `${width}px`;
497
498
  targeEl.style.height = `${height}px`;
498
499
  });
499
- this.moveableHelper.onResizeGroup(e);
500
500
  }
501
501
  onDragGroupStart(e) {
502
- const { events } = e;
503
502
  this.moveableHelper.onDragGroupStart(e);
503
+ const { events } = e;
504
504
  this.setFramesSnapShot(events);
505
505
  }
506
506
  onDragGroup(e) {
507
+ this.moveableHelper.onDragGroup(e);
507
508
  const { events } = e;
508
509
  events.forEach((ev) => {
509
510
  const frameSnapShot = this.framesSnapShot.find(
510
- (frameItem) => frameItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
511
+ (frameItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(frameItem.id)
511
512
  );
512
513
  if (!frameSnapShot)
513
514
  return;
514
515
  const targeEl = this.targetList.find(
515
- (targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
516
+ (targetItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(targetItem.id)
516
517
  );
517
518
  if (!targeEl)
518
519
  return;
@@ -523,7 +524,6 @@
523
524
  targeEl.style.top = `${frameSnapShot.top + ev.beforeTranslate[1] - marginTop}px`;
524
525
  }
525
526
  });
526
- this.moveableHelper.onDragGroup(e);
527
527
  }
528
528
  getUpdatedElRect(el, parentEl, doc) {
529
529
  const offset = this.mode === Mode.SORTABLE ? { left: 0, top: 0 } : { left: el.offsetLeft, top: el.offsetTop };
@@ -558,7 +558,7 @@
558
558
  return;
559
559
  events.forEach((ev) => {
560
560
  const matchEventTarget = this.targetList.find(
561
- (targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
561
+ (targetItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(targetItem.id)
562
562
  );
563
563
  if (!matchEventTarget)
564
564
  return;
@@ -619,7 +619,7 @@
619
619
  left: 0px;
620
620
  top: 0px;
621
621
  will-change: transform;
622
- transform-origin: 0px 0px;
622
+ transform-origin: 60px 28px;
623
623
  display: flex;
624
624
  }
625
625
  ${ableCss}
@@ -1302,6 +1302,10 @@
1302
1302
  this.dragResizeHelper.onDragGroup(e);
1303
1303
  this.dragStatus = StageDragStatus.ING;
1304
1304
  }).on("dragGroupEnd", () => {
1305
+ if (timeout) {
1306
+ globalThis.clearTimeout(timeout);
1307
+ timeout = void 0;
1308
+ }
1305
1309
  const parentEl = this.markContainerEnd();
1306
1310
  this.update(false, parentEl);
1307
1311
  this.dragStatus = StageDragStatus.END;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.15",
2
+ "version": "1.4.0-beta.1",
3
3
  "name": "@tmagic/stage",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -26,9 +26,9 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@scena/guides": "^0.29.2",
29
- "@tmagic/core": "1.3.15",
30
- "@tmagic/schema": "1.3.15",
31
- "@tmagic/utils": "1.3.15",
29
+ "@tmagic/core": "1.4.0-beta.1",
30
+ "@tmagic/schema": "1.4.0-beta.1",
31
+ "@tmagic/utils": "1.4.0-beta.1",
32
32
  "events": "^3.3.0",
33
33
  "keycon": "^1.4.0",
34
34
  "lodash-es": "^4.17.21",
@@ -41,8 +41,8 @@
41
41
  "@types/node": "^18.19.0",
42
42
  "rimraf": "^3.0.2",
43
43
  "sass": "^1.35.1",
44
- "typescript": "^5.0.4",
45
- "vite": "^5.0.7"
44
+ "typescript": "^5.4.2",
45
+ "vite": "^5.1.6"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "npm run build:type && vite build",
@@ -230,6 +230,9 @@ export default class DragResizeHelper {
230
230
  */
231
231
  public onResizeGroup(e: OnResizeGroup): void {
232
232
  const { events } = e;
233
+
234
+ this.moveableHelper.onResizeGroup(e);
235
+
233
236
  // 拖动过程更新
234
237
  events.forEach((ev) => {
235
238
  const { width, height, beforeTranslate } = ev.drag;
@@ -255,26 +258,28 @@ export default class DragResizeHelper {
255
258
  targeEl.style.width = `${width}px`;
256
259
  targeEl.style.height = `${height}px`;
257
260
  });
258
- this.moveableHelper.onResizeGroup(e);
259
261
  }
260
262
 
261
263
  public onDragGroupStart(e: OnDragGroupStart): void {
262
- const { events } = e;
263
264
  this.moveableHelper.onDragGroupStart(e);
265
+
266
+ const { events } = e;
264
267
  // 记录拖动前快照
265
268
  this.setFramesSnapShot(events);
266
269
  }
267
270
 
268
271
  public onDragGroup(e: OnDragGroup): void {
272
+ this.moveableHelper.onDragGroup(e);
273
+
269
274
  const { events } = e;
270
275
  // 拖动过程更新
271
276
  events.forEach((ev) => {
272
277
  const frameSnapShot = this.framesSnapShot.find(
273
- (frameItem) => frameItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ''),
278
+ (frameItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(frameItem.id),
274
279
  );
275
280
  if (!frameSnapShot) return;
276
281
  const targeEl = this.targetList.find(
277
- (targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ''),
282
+ (targetItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(targetItem.id),
278
283
  );
279
284
  if (!targeEl) return;
280
285
  // 元素与其所属组同时加入多选列表时,只更新父元素
@@ -286,7 +291,6 @@ export default class DragResizeHelper {
286
291
  targeEl.style.top = `${frameSnapShot.top + ev.beforeTranslate[1] - marginTop}px`;
287
292
  }
288
293
  });
289
- this.moveableHelper.onDragGroup(e);
290
294
  }
291
295
 
292
296
  public getUpdatedElRect(el: HTMLElement, parentEl: HTMLElement | null, doc: Document): Rect {
@@ -342,7 +346,7 @@ export default class DragResizeHelper {
342
346
  events.forEach((ev) => {
343
347
  // 实际目标元素
344
348
  const matchEventTarget = this.targetList.find(
345
- (targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ''),
349
+ (targetItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(targetItem.id),
346
350
  );
347
351
  if (!matchEventTarget) return;
348
352
  this.framesSnapShot.push({
@@ -20,7 +20,7 @@ export default (handler: (type: AbleActionEventType) => void) => ({
20
20
  left: 0px;
21
21
  top: 0px;
22
22
  will-change: transform;
23
- transform-origin: 0px 0px;
23
+ transform-origin: 60px 28px;
24
24
  display: flex;
25
25
  }
26
26
  ${ableCss}
@@ -120,6 +120,10 @@ export default class StageMultiDragResize extends MoveableOptionsManager {
120
120
  this.dragStatus = StageDragStatus.ING;
121
121
  })
122
122
  .on('dragGroupEnd', () => {
123
+ if (timeout) {
124
+ globalThis.clearTimeout(timeout);
125
+ timeout = undefined;
126
+ }
123
127
  const parentEl = this.markContainerEnd();
124
128
  this.update(false, parentEl);
125
129
  this.dragStatus = StageDragStatus.END;
@@ -93,7 +93,7 @@ export default class TargetShadow {
93
93
  private updateEl(target: ShadowElement, src?: ShadowElement): ShadowElement {
94
94
  const el = src || globalThis.document.createElement('div');
95
95
 
96
- el.id = `${this.idPrefix}${target.id}`;
96
+ el.id = `${this.idPrefix}_${target.id}`;
97
97
 
98
98
  el.style.cssText = getTargetElStyle(target, this.zIndex);
99
99