@tmagic/stage 1.0.0-rc.8 → 1.0.0-rc.9

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.
@@ -25,7 +25,7 @@ import MoveableHelper from 'moveable-helper';
25
25
 
26
26
  import { DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, Mode, ZIndex } from './const';
27
27
  import StageCore from './StageCore';
28
- import type { Offset, SortEventData, StageDragResizeConfig } from './types';
28
+ import type { SortEventData, StageDragResizeConfig } from './types';
29
29
  import { getAbsolutePosition, getGuideLineFromCache, getMode, getOffset } from './util';
30
30
 
31
31
  /** 拖动状态 */
@@ -233,10 +233,16 @@ export default class StageDragResize extends EventEmitter {
233
233
 
234
234
  this.moveableHelper?.onResize(e);
235
235
 
236
+ // 流式布局
237
+ if (this.mode === Mode.SORTABLE) {
238
+ this.target.style.top = '0px';
239
+ } else {
240
+ this.target.style.left = `${frame.left + beforeTranslate[0]}px`;
241
+ this.target.style.top = `${frame.top + beforeTranslate[1]}px`;
242
+ }
243
+
236
244
  this.target.style.width = `${width}px`;
237
245
  this.target.style.height = `${height}px`;
238
- this.target.style.left = `${frame.left + beforeTranslate[0]}px`;
239
- this.target.style.top = `${frame.top + beforeTranslate[1]}px`;
240
246
  })
241
247
  .on('resizeEnd', () => {
242
248
  this.dragStatus = ActionStatus.END;
@@ -247,7 +253,10 @@ export default class StageDragResize extends EventEmitter {
247
253
  private bindDragEvent(): void {
248
254
  if (!this.moveable) throw new Error('moveable 为初始化');
249
255
 
250
- let offset: Offset | null = null;
256
+ const frame = {
257
+ left: 0,
258
+ top: 0,
259
+ };
251
260
 
252
261
  this.moveable
253
262
  .on('dragStart', (e) => {
@@ -260,29 +269,25 @@ export default class StageDragResize extends EventEmitter {
260
269
  if (this.mode === Mode.SORTABLE) {
261
270
  this.ghostEl = this.generateGhostEl(this.target);
262
271
  }
272
+
273
+ frame.top = this.target.offsetTop;
274
+ frame.left = this.target.offsetLeft;
263
275
  })
264
276
  .on('drag', (e) => {
265
277
  if (!this.target || !this.dragEl) return;
266
278
 
267
- if (!offset) {
268
- offset = getAbsolutePosition(this.target, { left: 0, top: 0 });
269
- }
270
-
271
279
  this.dragStatus = ActionStatus.ING;
272
280
 
273
- const { left, top } = e;
274
-
275
281
  // 流式布局
276
282
  if (this.ghostEl) {
277
- this.dragEl.style.top = `${top}px`;
278
- this.ghostEl.style.top = `${top + offset.top}px`;
283
+ this.ghostEl.style.top = `${frame.top + e.beforeTranslate[1]}px`;
279
284
  return;
280
285
  }
281
286
 
282
287
  this.moveableHelper?.onDrag(e);
283
288
 
284
- this.target.style.left = `${left + offset.left}px`;
285
- this.target.style.top = `${top + offset.top}px`;
289
+ this.target.style.left = `${frame.left + e.beforeTranslate[0]}px`;
290
+ this.target.style.top = `${frame.top + e.beforeTranslate[1]}px`;
286
291
  })
287
292
  .on('dragEnd', () => {
288
293
  // 点击不拖动时会触发dragStart和dragEnd,但是不会有drag事件
@@ -295,7 +300,6 @@ export default class StageDragResize extends EventEmitter {
295
300
  this.update();
296
301
  }
297
302
  }
298
- offset = null;
299
303
 
300
304
  this.dragStatus = ActionStatus.END;
301
305
  this.destroyGhostEl();