@tft/interact 12.4.3 → 12.5.3

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.
Files changed (68) hide show
  1. package/bundles/tft-interact.umd.js +255 -120
  2. package/bundles/tft-interact.umd.js.map +1 -1
  3. package/esm2015/lib/directives/account-for-scale.directive.js +3 -11
  4. package/esm2015/lib/directives/account-for-scale.directive.js.map +1 -1
  5. package/esm2015/lib/directives/account-for-scale.directive.metadata.json +1 -1
  6. package/esm2015/lib/directives/account-for-scale.directive.ngfactory.js.map +1 -0
  7. package/esm2015/lib/directives/apply-scale.directive.js +4 -13
  8. package/esm2015/lib/directives/apply-scale.directive.js.map +1 -1
  9. package/esm2015/lib/directives/apply-scale.directive.metadata.json +1 -1
  10. package/esm2015/lib/directives/apply-scale.directive.ngfactory.js.map +1 -0
  11. package/esm2015/lib/directives/auto-scroll.directive.js +54 -0
  12. package/esm2015/lib/directives/auto-scroll.directive.js.map +1 -0
  13. package/esm2015/lib/directives/auto-scroll.directive.metadata.json +1 -0
  14. package/esm2015/lib/directives/auto-scroll.directive.ngfactory.js.map +1 -0
  15. package/esm2015/lib/directives/drag-preview.directive.ngfactory.js.map +1 -0
  16. package/esm2015/lib/directives/drag-root.directive.js +8 -11
  17. package/esm2015/lib/directives/drag-root.directive.js.map +1 -1
  18. package/esm2015/lib/directives/drag-root.directive.metadata.json +1 -1
  19. package/esm2015/lib/directives/drag-root.directive.ngfactory.js.map +1 -0
  20. package/esm2015/lib/directives/draggable.directive.js +45 -15
  21. package/esm2015/lib/directives/draggable.directive.js.map +1 -1
  22. package/esm2015/lib/directives/draggable.directive.metadata.json +1 -1
  23. package/esm2015/lib/directives/draggable.directive.ngfactory.js.map +1 -0
  24. package/esm2015/lib/directives/dropzone.directive.js +9 -6
  25. package/esm2015/lib/directives/dropzone.directive.js.map +1 -1
  26. package/esm2015/lib/directives/dropzone.directive.metadata.json +1 -1
  27. package/esm2015/lib/directives/dropzone.directive.ngfactory.js.map +1 -0
  28. package/esm2015/lib/directives/gesturable.directive.ngfactory.js.map +1 -0
  29. package/esm2015/lib/directives/index.js +1 -0
  30. package/esm2015/lib/directives/index.js.map +1 -1
  31. package/esm2015/lib/directives/index.metadata.json +1 -1
  32. package/esm2015/lib/directives/resizable.directive.js +62 -13
  33. package/esm2015/lib/directives/resizable.directive.js.map +1 -1
  34. package/esm2015/lib/directives/resizable.directive.metadata.json +1 -1
  35. package/esm2015/lib/directives/resizable.directive.ngfactory.js.map +1 -0
  36. package/esm2015/lib/interact.module.js +15 -1
  37. package/esm2015/lib/interact.module.js.map +1 -1
  38. package/esm2015/lib/interact.module.metadata.json +1 -1
  39. package/esm2015/lib/interact.module.ngfactory.js.map +1 -0
  40. package/esm2015/lib/models/interact.js +2 -0
  41. package/esm2015/lib/models/interact.js.map +1 -1
  42. package/esm2015/lib/models/interact.metadata.json +1 -1
  43. package/esm2015/lib/pipes/array-of-n.pipe.ngfactory.js.map +1 -0
  44. package/esm2015/lib/services/interact.service.js +31 -36
  45. package/esm2015/lib/services/interact.service.js.map +1 -1
  46. package/esm2015/lib/services/interact.service.metadata.json +1 -1
  47. package/esm2015/lib/services/interact.service.ngfactory.js.map +1 -0
  48. package/esm2015/tft-interact.js +2 -2
  49. package/esm2015/tft-interact.js.map +1 -1
  50. package/esm2015/tft-interact.metadata.json +1 -1
  51. package/fesm2015/tft-interact.js +223 -105
  52. package/fesm2015/tft-interact.js.map +1 -1
  53. package/lib/directives/account-for-scale.directive.d.ts +1 -3
  54. package/lib/directives/apply-scale.directive.d.ts +4 -7
  55. package/lib/directives/auto-scroll.directive.d.ts +31 -0
  56. package/lib/directives/drag-root.directive.d.ts +2 -1
  57. package/lib/directives/draggable.directive.d.ts +8 -2
  58. package/lib/directives/dropzone.directive.d.ts +7 -4
  59. package/lib/directives/index.d.ts +1 -0
  60. package/lib/directives/resizable.directive.d.ts +10 -3
  61. package/lib/interact.module.d.ts +3 -0
  62. package/lib/models/interact.d.ts +10 -0
  63. package/lib/services/interact.service.d.ts +6 -7
  64. package/package.json +1 -1
  65. package/tft-interact-12.5.3.tgz +0 -0
  66. package/tft-interact.d.ts +2 -2
  67. package/tft-interact.metadata.json +1 -1
  68. package/tft-interact-12.4.3.tgz +0 -0
@@ -1,9 +1,9 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Pipe, Injectable, RendererFactory2, NgZone, Directive, ElementRef, Input, EventEmitter, Renderer2, Optional, Output, InjectionToken, TemplateRef, Self, ViewContainerRef, Inject, SkipSelf, ContentChild, HostBinding, NgModule } from '@angular/core';
2
+ import { Pipe, InjectionToken, Injectable, RendererFactory2, NgZone, Optional, Inject, Directive, ElementRef, Input, EventEmitter, Renderer2, HostBinding, Output, TemplateRef, Self, HostListener, ViewContainerRef, SkipSelf, ContentChild, NgModule } from '@angular/core';
3
3
  import { DOCUMENT, CommonModule } from '@angular/common';
4
4
  import interact from 'interactjs';
5
- import { BehaviorSubject, combineLatest } from 'rxjs';
6
- import { shareReplay, tap, map } from 'rxjs/operators';
5
+ import { BehaviorSubject, combineLatest, Subject } from 'rxjs';
6
+ import { shareReplay, tap, map, scan } from 'rxjs/operators';
7
7
 
8
8
  class ArrayOfNPipe {
9
9
  /**
@@ -22,6 +22,7 @@ ArrayOfNPipe.decorators = [
22
22
  },] }
23
23
  ];
24
24
 
25
+ const INTERACT_ROOT_CONFIG = new InjectionToken('INTERACT_ROOT_CONFIG_PARAMS');
25
26
  const DEFAULT_REGISTRY_ID = 'DEFAULT';
26
27
  /**
27
28
  * Default initial value for Delta BehaviorSubject
@@ -49,14 +50,17 @@ const defaultPosition = {
49
50
  };
50
51
 
51
52
  class InteractService {
52
- constructor(rendererFactory, ngZone) {
53
+ constructor(rendererFactory, ngZone, rootConfig) {
53
54
  this.rendererFactory = rendererFactory;
54
55
  this.ngZone = ngZone;
56
+ this.rootConfig = rootConfig;
55
57
  this._interactableIndex = 0;
56
58
  this._dropzoneIndex = 0;
57
59
  // TODO: consider using Map here
58
60
  this.dragRegistrySystem = {};
61
+ this.cssUnit = 'px';
59
62
  this.renderer = this.rendererFactory.createRenderer(null, null);
63
+ this.cssUnit = (rootConfig === null || rootConfig === void 0 ? void 0 : rootConfig.cssDimensionUnit) || 'px';
60
64
  }
61
65
  addDeltaToPosition(delta, position) {
62
66
  return {
@@ -73,7 +77,7 @@ class InteractService {
73
77
  addDraggableToRegistry(customRegistryId = null, interactableId = null) {
74
78
  const registryId = customRegistryId || DEFAULT_REGISTRY_ID;
75
79
  // if we pass an id to createInteractableId then it is used when creating the interactable
76
- // and returned, otherwise a an id is created for the draggable.
80
+ // and returned, otherwise a new id is created for the draggable.
77
81
  const key = this.createInteractableId(interactableId);
78
82
  if (!Object.prototype.hasOwnProperty.call(this.dragRegistrySystem, registryId)) {
79
83
  this.dragRegistrySystem[registryId] = {};
@@ -82,7 +86,16 @@ class InteractService {
82
86
  return key;
83
87
  }
84
88
  destroyInteractable(interactableId, registryId = DEFAULT_REGISTRY_ID) {
85
- if (this.dragRegistrySystem[registryId][interactableId]) {
89
+ const interactableSystem = this.dragRegistrySystem[registryId][interactableId];
90
+ if (interactableSystem) {
91
+ // unsubscribe from all the subscriptions if they're subscriptions
92
+ for (const propName in interactableSystem) {
93
+ const prop = interactableSystem[propName];
94
+ if (prop.unsubscribe && typeof prop.unsubscribe === 'function') {
95
+ prop.unsubscribe();
96
+ }
97
+ ;
98
+ }
86
99
  delete this.dragRegistrySystem[registryId][interactableId];
87
100
  }
88
101
  }
@@ -164,8 +177,8 @@ class InteractService {
164
177
  this.dragRegistrySystem[registryId][interactId].size$.next({ deltaX, deltaY, width, height, targetElement });
165
178
  }
166
179
  interactableExistOnRegistry(interactId, registryId = DEFAULT_REGISTRY_ID) {
167
- return this.dragRegistrySystem.hasOwnProperty(registryId)
168
- && this.dragRegistrySystem[registryId].hasOwnProperty(interactId);
180
+ // eslint-disable-next-line no-prototype-builtins
181
+ return this.dragRegistrySystem.hasOwnProperty(registryId) && this.dragRegistrySystem[registryId].hasOwnProperty(interactId);
169
182
  }
170
183
  /**
171
184
  * Uses renderer to set width and height of angular component
@@ -174,21 +187,10 @@ class InteractService {
174
187
  * @param target the element to transform
175
188
  */
176
189
  setElementSize(width, height, target) {
177
- var _a;
178
190
  if (!target)
179
191
  return;
180
- const accountForScaleDirective = (_a = target.resizeRef) === null || _a === void 0 ? void 0 : _a.account_for_scale_dir;
181
- if (accountForScaleDirective) {
182
- const { scaleX, scaleY } = accountForScaleDirective;
183
- const scaledWidth = width / scaleX;
184
- const scaledHeight = height / scaleY;
185
- this.renderer.setStyle(target, 'width', `${scaledWidth}px`);
186
- this.renderer.setStyle(target, 'height', `${scaledHeight}px`);
187
- }
188
- else {
189
- this.renderer.setStyle(target, 'width', `${width}px`);
190
- this.renderer.setStyle(target, 'height', `${height}px`);
191
- }
192
+ this.renderer.setStyle(target, 'width', `${width}${this.cssUnit}`);
193
+ this.renderer.setStyle(target, 'height', `${height}${this.cssUnit}`);
192
194
  }
193
195
  /**
194
196
  * Uses renderer to set position of angular component
@@ -197,19 +199,10 @@ class InteractService {
197
199
  * @param target the element to transform
198
200
  */
199
201
  setElementTransform(x, y, position) {
200
- var _a, _b;
201
202
  if (!(position === null || position === void 0 ? void 0 : position.targetElement))
202
203
  return;
203
- const accountForScaleDirective = (_b = (_a = position.targetElement) === null || _a === void 0 ? void 0 : _a.dragRef) === null || _b === void 0 ? void 0 : _b.account_for_scale_dir;
204
- if (accountForScaleDirective) {
205
- const { scaleX, scaleY } = accountForScaleDirective;
206
- this.renderer.setStyle(position.targetElement, 'left', `${x / scaleX}px`);
207
- this.renderer.setStyle(position.targetElement, 'top', `${y / scaleY}px`);
208
- }
209
- else {
210
- this.renderer.setStyle(position.targetElement, 'left', `${x}px`);
211
- this.renderer.setStyle(position.targetElement, 'top', `${y}px`);
212
- }
204
+ this.renderer.setStyle(position.targetElement, 'left', `${x}${this.cssUnit}`);
205
+ this.renderer.setStyle(position.targetElement, 'top', `${y}${this.cssUnit}`);
213
206
  }
214
207
  /**
215
208
  * Generates a translate string for the x and y arguments passed to
@@ -218,7 +211,7 @@ class InteractService {
218
211
  * @param y the position along the y axis
219
212
  */
220
213
  createTransformString(x, y) {
221
- return `translate3d(${x}px, ${y}px, 0)`;
214
+ return `translate3d(${x}${this.cssUnit}, ${y}${this.cssUnit}, 0)`;
222
215
  }
223
216
  calculatePositionInElement(zoneElement, dragElement, scale) {
224
217
  // TODO: this calculation may not cover a lot of scenarios, keep an eye out for possible improvements
@@ -226,22 +219,24 @@ class InteractService {
226
219
  const dragRect = dragElement.getBoundingClientRect();
227
220
  const position = scale
228
221
  ? {
229
- x: (dragRect.left - zoneRect.left) / scale.x || 1,
230
- y: (dragRect.top - zoneRect.top) / scale.y || 1
222
+ x: (dragRect.left - zoneRect.left) / scale || 1,
223
+ y: (dragRect.top - zoneRect.top) / scale || 1
231
224
  } : {
232
225
  x: dragRect.left - zoneRect.left,
233
226
  y: dragRect.top - zoneRect.top
234
227
  };
228
+ // console.log({ y:position.y, drt:dragRect.top, zrt: zoneRect.top})
235
229
  return position;
236
230
  }
237
231
  }
238
- InteractService.ɵprov = i0.ɵɵdefineInjectable({ factory: function InteractService_Factory() { return new InteractService(i0.ɵɵinject(i0.RendererFactory2), i0.ɵɵinject(i0.NgZone)); }, token: InteractService, providedIn: "root" });
232
+ InteractService.ɵprov = i0.ɵɵdefineInjectable({ factory: function InteractService_Factory() { return new InteractService(i0.ɵɵinject(i0.RendererFactory2), i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(INTERACT_ROOT_CONFIG, 8)); }, token: InteractService, providedIn: "root" });
239
233
  InteractService.decorators = [
240
234
  { type: Injectable, args: [{ providedIn: 'root' },] }
241
235
  ];
242
236
  InteractService.ctorParameters = () => [
243
237
  { type: RendererFactory2 },
244
- { type: NgZone }
238
+ { type: NgZone },
239
+ { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [INTERACT_ROOT_CONFIG,] }] }
245
240
  ];
246
241
 
247
242
  /**
@@ -253,15 +248,9 @@ InteractService.ctorParameters = () => [
253
248
  class AccountForScaleDirective {
254
249
  constructor(el) {
255
250
  this.el = el;
256
- this.scaleX = 1;
257
- this.scaleY = 1;
251
+ // this setup allows consumers to set x, y scale independently or just set them both with scale
252
+ this.scale = 1;
258
253
  }
259
- // this setup allows consumers to set x, y scale independently or just set them both with scale
260
- set scale(val) {
261
- this.scaleY = val;
262
- this.scaleX = val;
263
- }
264
- ;
265
254
  }
266
255
  AccountForScaleDirective.decorators = [
267
256
  { type: Directive, args: [{
@@ -272,9 +261,7 @@ AccountForScaleDirective.ctorParameters = () => [
272
261
  { type: ElementRef }
273
262
  ];
274
263
  AccountForScaleDirective.propDecorators = {
275
- scale: [{ type: Input }],
276
- scaleX: [{ type: Input }],
277
- scaleY: [{ type: Input }]
264
+ scale: [{ type: Input }]
278
265
  };
279
266
 
280
267
  class DropzoneDirective {
@@ -284,12 +271,17 @@ class DropzoneDirective {
284
271
  this.interactService = interactService;
285
272
  this.account_for_scale_dir = account_for_scale_dir;
286
273
  this.dropzoneConfig = {};
274
+ this.position = 'relative';
287
275
  // proxies to pass interact events through to consumer of directive
288
276
  this.dropActivate = new EventEmitter();
289
277
  this.dragEnter = new EventEmitter();
290
278
  this.dragLeave = new EventEmitter();
291
279
  this.dragDrop = new EventEmitter();
292
280
  }
281
+ get scale() {
282
+ var _a;
283
+ return (_a = this.account_for_scale_dir) === null || _a === void 0 ? void 0 : _a.scale;
284
+ }
293
285
  ngOnInit() {
294
286
  // connects
295
287
  this.dropzone = this.connectDropzoneEvents(this.el.nativeElement, this.dropzoneConfig);
@@ -335,10 +327,7 @@ class DropzoneDirective {
335
327
  var _a, _b;
336
328
  const zoneElement = event.target;
337
329
  const dragElement = (_b = (_a = event.relatedTarget) === null || _a === void 0 ? void 0 : _a.dragRef) === null || _b === void 0 ? void 0 : _b.previewRef;
338
- const scale = this.account_for_scale_dir ? {
339
- x: this.account_for_scale_dir.scaleX,
340
- y: this.account_for_scale_dir.scaleY
341
- } : null;
330
+ const scale = this.scale;
342
331
  const positionInDropTarget = zoneElement && dragElement
343
332
  ? this.interactService.calculatePositionInElement(zoneElement, dragElement, scale)
344
333
  : null;
@@ -355,7 +344,7 @@ DropzoneDirective.decorators = [
355
344
  { type: Directive, args: [{
356
345
  selector: '[tftDropzone]',
357
346
  host: {
358
- '[id]': 'dropzoneId',
347
+ '[id]': 'dropzoneId'
359
348
  }
360
349
  },] }
361
350
  ];
@@ -369,6 +358,7 @@ DropzoneDirective.propDecorators = {
369
358
  dropzoneId: [{ type: Input }],
370
359
  dropzoneConfig: [{ type: Input }],
371
360
  dropzoneData: [{ type: Input }],
361
+ position: [{ type: Input }, { type: HostBinding, args: ['style.position',] }],
372
362
  dropActivate: [{ type: Output }],
373
363
  dragEnter: [{ type: Output }],
374
364
  dragLeave: [{ type: Output }],
@@ -435,21 +425,18 @@ function getRootNode(viewRef, _document) {
435
425
  * @note this directive will overwrite any style transformations (e.g. transform: scale(2); )
436
426
  */
437
427
  class DragRootDirective {
438
- constructor(el, account_for_scale_dir) {
428
+ constructor(el,
429
+ // This is used when passing a dragRoot as in input to a draggable element that not a child of that dragRoot
430
+ // It allows the the interact service to check if the drag root has some scaling applied to it and account for it when the component is dragged
431
+ account_for_scale_dir) {
439
432
  this.el = el;
440
- // This accounts for a bug where drag element is misaligned when using a drag root
441
- // with a dropzone inside of it and a drag item inside the dropzone
442
- // e.g <div tftDragRoot> <div tftDropzone> <div tftDraggable</div> </div> </div>
443
- // TODO: This is a band-aid, root cause in misunderstood, it started after switching from
444
- // using `translate3d` to top/left for positioning
445
- if (!account_for_scale_dir) {
446
- el.nativeElement.style.transform = 'scale(1)';
447
- }
433
+ this.account_for_scale_dir = account_for_scale_dir;
448
434
  }
449
435
  }
450
436
  DragRootDirective.decorators = [
451
437
  { type: Directive, args: [{
452
- selector: '[tftDragRoot]'
438
+ selector: '[tftDragRoot]',
439
+ exportAs: 'tftDragRoot'
453
440
  },] }
454
441
  ];
455
442
  DragRootDirective.ctorParameters = () => [
@@ -457,11 +444,61 @@ DragRootDirective.ctorParameters = () => [
457
444
  { type: AccountForScaleDirective, decorators: [{ type: Optional }, { type: Self }] }
458
445
  ];
459
446
 
447
+ ;
448
+ /**
449
+ * Use to apply scale to the element and tell the drag and resize directives to account for the scale when
450
+ * @example <div tftAccountForScale [scale]="2.5"> <div tftDraggable> </div> </div>
451
+ * @note if `dragRoot` is used this directive should be used on the same element to ensure that the drag
452
+ * element accounts for scale
453
+ */
454
+ class AutoScrollDirective {
455
+ constructor(el) {
456
+ this.el = el;
457
+ /**
458
+ * Limit minimum time between scroll events in milliseconds
459
+ */
460
+ this.autoScrollConfig = {
461
+ margin: 50,
462
+ distance: 3,
463
+ interval: 50,
464
+ speed: 300,
465
+ enabled: true
466
+ };
467
+ this.scrollDeltaObserver = new Subject();
468
+ const { scrollTop, scrollLeft } = el.nativeElement;
469
+ this.scrollSubject = new BehaviorSubject({ scrollTop, scrollLeft });
470
+ this.scrollObserver = this.scrollSubject.pipe(scan((previous, current) => {
471
+ const scrollTop = current.scrollTop - previous.scrollTop;
472
+ const scrollLeft = current.scrollLeft - previous.scrollLeft;
473
+ this.scrollDeltaObserver.next({ scrollTop, scrollLeft });
474
+ return current;
475
+ }), shareReplay(1));
476
+ this.scrollObserver.subscribe();
477
+ }
478
+ // this setup allows consumers to set x, y scale independently or just set them both with scale
479
+ scroll(scrollEvent) {
480
+ const target = scrollEvent.target;
481
+ const { scrollTop, scrollLeft } = target;
482
+ this.scrollSubject.next({ scrollTop, scrollLeft });
483
+ }
484
+ }
485
+ AutoScrollDirective.decorators = [
486
+ { type: Directive, args: [{
487
+ selector: '[tftAutoScroll]'
488
+ },] }
489
+ ];
490
+ AutoScrollDirective.ctorParameters = () => [
491
+ { type: ElementRef }
492
+ ];
493
+ AutoScrollDirective.propDecorators = {
494
+ autoScrollConfig: [{ type: Input }],
495
+ scroll: [{ type: HostListener, args: ['scroll', ['$event'],] }]
496
+ };
497
+
460
498
  /** @dynamic */
461
499
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
462
500
  class DraggableDirective {
463
- // cache holding element to use as placeholder while dragging
464
- constructor(el, interactService, renderer, _viewContainerRef, _document, account_for_scale_dir, dropzone_dir, drag_root_dir) {
501
+ constructor(el, interactService, renderer, _viewContainerRef, _document, account_for_scale_dir, dropzone_dir, drag_root_dir, auto_scroll_dir) {
465
502
  this.el = el;
466
503
  this.interactService = interactService;
467
504
  this.renderer = renderer;
@@ -470,6 +507,7 @@ class DraggableDirective {
470
507
  this.account_for_scale_dir = account_for_scale_dir;
471
508
  this.dropzone_dir = dropzone_dir;
472
509
  this.drag_root_dir = drag_root_dir;
510
+ this.auto_scroll_dir = auto_scroll_dir;
473
511
  /* zIndex while dragging*/
474
512
  this.dragZIndex = 10000;
475
513
  this.enableDragDefault = true;
@@ -485,13 +523,18 @@ class DraggableDirective {
485
523
  this.dragInertiaStart = new EventEmitter();
486
524
  this.dragEnd = new EventEmitter();
487
525
  }
526
+ // check all the different places for scale
527
+ get scale() {
528
+ var _a, _b, _c, _d;
529
+ return ((_a = this.account_for_scale_dir) === null || _a === void 0 ? void 0 : _a.scale) || ((_b = this.drag_root_dir) === null || _b === void 0 ? void 0 : _b.account_for_scale_dir.scale) || ((_d = (_c = this.dragRoot) === null || _c === void 0 ? void 0 : _c.account_for_scale_dir) === null || _d === void 0 ? void 0 : _d.scale);
530
+ }
488
531
  ngOnInit() {
489
- var _a, _b, _c;
532
+ var _a, _b, _c, _d, _e;
490
533
  this.interactable = this.initiateDragEvents(this.dragConfig, this.el.nativeElement);
491
- this.dragRoot = this.dragRoot || ((_b = (_a = this.drag_root_dir) === null || _a === void 0 ? void 0 : _a.el) === null || _b === void 0 ? void 0 : _b.nativeElement) || this._document.body;
534
+ this.dragRootEl = (((_b = (_a = this.dragRoot) === null || _a === void 0 ? void 0 : _a.el) === null || _b === void 0 ? void 0 : _b.nativeElement) || ((_d = (_c = this.drag_root_dir) === null || _c === void 0 ? void 0 : _c.el) === null || _d === void 0 ? void 0 : _d.nativeElement)) || this._document.body;
492
535
  // register with parent dropzone if it exists, otherwise use default
493
536
  // this gives us a place on the registry to store our drag items that don't have a dropzone
494
- this.registryId = ((_c = this.dropzone_dir) === null || _c === void 0 ? void 0 : _c.dropzoneId) || DEFAULT_REGISTRY_ID;
537
+ this.registryId = ((_e = this.dropzone_dir) === null || _e === void 0 ? void 0 : _e.dropzoneId) || DEFAULT_REGISTRY_ID;
495
538
  // add draggable to directory and store its id
496
539
  this.interactableId = this.interactService.addDraggableToRegistry(this.registryId, this.interactableId);
497
540
  this.alignPositionWithInputs(this.x, this.y);
@@ -542,12 +585,15 @@ class DraggableDirective {
542
585
  }
543
586
  dragMoveListener(event, element) {
544
587
  const { dx, dy } = event;
545
- this.interactService.updateDeltas(this.interactableId, this.registryId, { deltaX: dx, deltaY: dy }, element);
588
+ const scale = this.scale;
589
+ const deltaX = scale ? dx / scale : dx;
590
+ const deltaY = scale ? dy / scale : dy;
591
+ this.interactService.updateDeltas(this.interactableId, this.registryId, { deltaX, deltaY }, element);
546
592
  }
547
593
  setDragStyles(dragElement) {
548
594
  this.renderer.setStyle(dragElement, 'touchAction', 'none');
549
595
  this.renderer.setStyle(dragElement, 'zIndex', this.dragZIndex);
550
- this.renderer.setStyle(dragElement, 'position', 'fixed');
596
+ this.renderer.setStyle(dragElement, 'position', 'absolute');
551
597
  }
552
598
  addDragPropertiesToElement(nativeElement) {
553
599
  this.renderer.setProperty(nativeElement, 'dropTarget', this.dropzone_dir || null);
@@ -558,8 +604,9 @@ class DraggableDirective {
558
604
  var _a;
559
605
  const { target, dropzone } = event;
560
606
  const dropzoneElement = (dropzone === null || dropzone === void 0 ? void 0 : dropzone.target) || ((_a = target.dropTarget) === null || _a === void 0 ? void 0 : _a.el.nativeElement);
607
+ const scale = this.scale;
561
608
  const positionInDropTarget = target && dropzoneElement
562
- ? this.interactService.calculatePositionInElement(dropzoneElement, this.previewRef)
609
+ ? this.interactService.calculatePositionInElement(dropzoneElement, this.previewRef, scale)
563
610
  : null;
564
611
  return {
565
612
  interactEvent: event,
@@ -587,8 +634,12 @@ class DraggableDirective {
587
634
  return typeof num === 'number' && !isNaN(num);
588
635
  }
589
636
  initiateDragEvents(dragConfig, nativeElement) {
590
- return interact(nativeElement).draggable(Object.assign(Object.assign({}, dragConfig), { enabled: !(this.disabled || this.dragDisabled) }))
637
+ const defaultDragConfig = Object.assign(Object.assign(Object.assign({}, dragConfig), { enabled: !(this.disabled || this.dragDisabled) }), (this.auto_scroll_dir && {
638
+ autoScroll: Object.assign(Object.assign({}, this.auto_scroll_dir.autoScrollConfig), { container: this.auto_scroll_dir.el.nativeElement })
639
+ }));
640
+ return interact(nativeElement).draggable(defaultDragConfig)
591
641
  .on('dragstart', (event) => {
642
+ var _a, _b, _c;
592
643
  const interaction = event.interaction;
593
644
  // check if we should append drag element to body
594
645
  if (this.enableDragDefault
@@ -606,13 +657,18 @@ class DraggableDirective {
606
657
  }
607
658
  this.addDragPropertiesToElement(this.previewRef);
608
659
  this.setDragStyles(this.previewRef);
609
- this.dragRoot.prepend(this.previewRef);
610
- const { x, y } = this.interactService.calculatePositionInElement(this.dragRoot, nativeElement);
660
+ this.dragRootEl.prepend(this.previewRef);
661
+ const scale = ((_a = this.account_for_scale_dir) === null || _a === void 0 ? void 0 : _a.scale) || ((_c = (_b = this.dragRoot) === null || _b === void 0 ? void 0 : _b.account_for_scale_dir) === null || _c === void 0 ? void 0 : _c.scale) || 1;
662
+ const { x, y } = this.interactService.calculatePositionInElement(this.dragRootEl, nativeElement, scale);
611
663
  this.interactService.updatePosition(this.interactableId, this.registryId, { x, y }, this.previewRef);
612
664
  if (!this.showPlaceholder) {
613
665
  this.renderer.setStyle(this.el.nativeElement, 'display', 'none');
614
666
  }
615
667
  }
668
+ // subscribe to scroll events if they are there, by only subscribing on dragstart we avoid wasting subscriptions on interactables that aren't be dragged
669
+ if (this.auto_scroll_dir) {
670
+ this.subscribeToScrollEvents();
671
+ }
616
672
  this.dragStart.emit(this.mapDragEvent(event));
617
673
  })
618
674
  .on('dragmove', (event) => {
@@ -634,15 +690,25 @@ class DraggableDirective {
634
690
  }
635
691
  this.renderer.setStyle(this.el.nativeElement, 'display', '');
636
692
  this.dragEnd.emit(mappedEvent);
693
+ // unsubscribe from scroll events if subscribed
694
+ if (this.auto_scroll_dir) {
695
+ this.scrollEventsSubscription.unsubscribe();
696
+ }
637
697
  if (this.el.nativeElement !== this.previewRef) {
638
- // we do this in a timeout, so that we don't
639
- // remove before the dropzone can get the boundingElementRect
698
+ // we do this in a timeout, so that we don't remove before the dropzone can get the boundingElementRect
640
699
  setTimeout(() => {
641
- this.dragRoot.removeChild(this.previewRef);
700
+ this.dragRootEl.removeChild(this.previewRef);
642
701
  });
643
702
  }
644
703
  });
645
704
  }
705
+ subscribeToScrollEvents() {
706
+ this.scrollEventsSubscription = this.auto_scroll_dir.scrollDeltaObserver.subscribe(({ scrollLeft, scrollTop }) => {
707
+ const deltaX = this.scale ? scrollLeft / this.scale : scrollLeft;
708
+ const deltaY = this.scale ? scrollTop / this.scale : scrollTop;
709
+ this.interactService.updateDeltas(this.interactableId, this.registryId, { deltaX, deltaY }, this.previewRef);
710
+ });
711
+ }
646
712
  }
647
713
  DraggableDirective.decorators = [
648
714
  { type: Directive, args: [{
@@ -663,7 +729,8 @@ DraggableDirective.ctorParameters = () => [
663
729
  { type: Document, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
664
730
  { type: AccountForScaleDirective, decorators: [{ type: Optional }] },
665
731
  { type: DropzoneDirective, decorators: [{ type: Optional }, { type: SkipSelf }] },
666
- { type: DragRootDirective, decorators: [{ type: Optional }, { type: SkipSelf }] }
732
+ { type: DragRootDirective, decorators: [{ type: Optional }, { type: SkipSelf }] },
733
+ { type: AutoScrollDirective, decorators: [{ type: Optional }, { type: SkipSelf }] }
667
734
  ];
668
735
  DraggableDirective.propDecorators = {
669
736
  x: [{ type: Input }],
@@ -705,15 +772,17 @@ function getPreviewInsertionPoint(documentRef) {
705
772
 
706
773
  /** @dynamic */
707
774
  class ResizableDirective {
708
- constructor(el, _document, interactService, renderer, drag_root_dir, account_for_scale_dir, draggable_dir, dropzone_dir) {
775
+ constructor(el, _document, interactService, renderer, drag_root_dir, account_for_scale_dir, draggable_dir, dropzone_dir, auto_scroll_dir) {
709
776
  var _a;
710
777
  this.el = el;
711
778
  this._document = _document;
712
779
  this.interactService = interactService;
713
780
  this.renderer = renderer;
781
+ this.drag_root_dir = drag_root_dir;
714
782
  this.account_for_scale_dir = account_for_scale_dir;
715
783
  this.draggable_dir = draggable_dir;
716
784
  this.dropzone_dir = dropzone_dir;
785
+ this.auto_scroll_dir = auto_scroll_dir;
717
786
  this.enableResizeDefault = true;
718
787
  // TODO: should this be an input with default or should consuming user set display in styles each time
719
788
  this.position = 'absolute';
@@ -725,7 +794,12 @@ class ResizableDirective {
725
794
  this.defaultConfig = {
726
795
  edges: { left: true, right: true, bottom: true, top: true }
727
796
  };
728
- this.dragRoot = ((_a = drag_root_dir === null || drag_root_dir === void 0 ? void 0 : drag_root_dir.el) === null || _a === void 0 ? void 0 : _a.nativeElement) || this._document.body;
797
+ this.activeEdges = { left: false, right: false, top: false, bottom: false };
798
+ this.dragRootEl = ((_a = drag_root_dir === null || drag_root_dir === void 0 ? void 0 : drag_root_dir.el) === null || _a === void 0 ? void 0 : _a.nativeElement) || this._document.body;
799
+ }
800
+ get scale() {
801
+ var _a, _b, _c;
802
+ return ((_a = this.account_for_scale_dir) === null || _a === void 0 ? void 0 : _a.scale) || ((_c = (_b = this.drag_root_dir) === null || _b === void 0 ? void 0 : _b.account_for_scale_dir) === null || _c === void 0 ? void 0 : _c.scale);
729
803
  }
730
804
  ngOnInit() {
731
805
  var _a, _b;
@@ -754,9 +828,16 @@ class ResizableDirective {
754
828
  this.interactService.destroyInteractable(this.interactableId, this.registryId);
755
829
  }
756
830
  resizeListener(event) {
757
- const deltaX = event.deltaRect.left;
758
- const deltaY = event.deltaRect.top;
759
- const { width, height } = event.rect;
831
+ const element = this.el.nativeElement;
832
+ const scale = this.scale;
833
+ const { deltaRect } = event;
834
+ const deltaX = deltaRect.left / scale;
835
+ const deltaY = deltaRect.top / scale;
836
+ // We get the width and height directly from the native element because
837
+ // the event dimension can get out of sync when resizing with autoScroll
838
+ const rect = element.getBoundingClientRect();
839
+ const width = (rect.width + deltaRect.width) / scale;
840
+ const height = (rect.height + deltaRect.height) / scale;
760
841
  this.interactService.updateSize(this.interactableId, this.registryId, { deltaX, deltaY, width, height }, this.el.nativeElement);
761
842
  }
762
843
  /**
@@ -769,9 +850,18 @@ class ResizableDirective {
769
850
  initiateResizeEvents(resizeConfig, nativeElement) {
770
851
  var _a;
771
852
  // TODO: This should try and get interactable from tft_draggable if it exists
853
+ const defaultResizeConfig = Object.assign(Object.assign(Object.assign({}, resizeConfig), { enabled: !this.resizeDisabled }), (this.auto_scroll_dir && {
854
+ autoScroll: Object.assign(Object.assign({}, this.auto_scroll_dir.autoScrollConfig), { container: this.auto_scroll_dir.el.nativeElement })
855
+ }));
772
856
  const interactable = ((_a = this.draggable_dir) === null || _a === void 0 ? void 0 : _a.interactable) || interact(nativeElement);
773
- return interactable.resizable(Object.assign(Object.assign({}, resizeConfig), { enabled: !this.resizeDisabled }))
774
- .on('resizestart', (event) => { this.resizeStart.emit(this.mapResizeEvent(event)); })
857
+ return interactable.resizable(defaultResizeConfig)
858
+ .on('resizestart', (event) => {
859
+ this.activeEdges = event.edges;
860
+ if (this.auto_scroll_dir) {
861
+ this.subscribeToScrollEvents();
862
+ }
863
+ this.resizeStart.emit(this.mapResizeEvent(event));
864
+ })
775
865
  .on('resizemove', (event) => {
776
866
  if (this.enableResizeDefault) {
777
867
  this.resizeListener(event);
@@ -780,23 +870,33 @@ class ResizableDirective {
780
870
  this.resizeMove.emit(mappedEvent);
781
871
  })
782
872
  .on('resizeinertiastart', (event) => this.resizeInertiaStart.emit(this.mapResizeEvent(event)))
783
- .on('resizeend', (event) => this.resizeEnd.emit(this.mapResizeEvent(event)));
873
+ .on('resizeend', (event) => {
874
+ if (this.auto_scroll_dir) {
875
+ this.scrollEventsSubscription.unsubscribe();
876
+ }
877
+ this.activeEdges = { left: false, right: false, top: false, bottom: false };
878
+ this.resizeEnd.emit(this.mapResizeEvent(event));
879
+ });
784
880
  }
785
881
  mapResizeEvent(event) {
786
882
  var _a, _b;
787
- const target = event.target;
883
+ const target = this.el.nativeElement;
788
884
  const relatedTarget = (_b = (_a = this.draggable_dir) === null || _a === void 0 ? void 0 : _a.dropzone_dir) === null || _b === void 0 ? void 0 : _b.el.nativeElement;
885
+ const scale = this.scale;
789
886
  const positionInDropTarget = target && relatedTarget
790
- ? this.interactService.calculatePositionInElement(relatedTarget, target)
887
+ ? this.interactService.calculatePositionInElement(relatedTarget, target, scale)
791
888
  : null;
792
889
  return {
793
890
  interactEvent: event,
794
891
  resizeRef: this,
795
- // should I remove this?
796
892
  dragRef: this.draggable_dir,
797
893
  dragOrigin: this.dropzone_dir,
798
894
  dropTarget: this.el.nativeElement.dropTarget,
799
- positionInDropTarget
895
+ positionInDropTarget,
896
+ size: {
897
+ width: target.clientWidth / scale,
898
+ height: target.clientHeight / scale
899
+ }
800
900
  };
801
901
  }
802
902
  alignDimensionsWithInputs(width, height) {
@@ -805,6 +905,20 @@ class ResizableDirective {
805
905
  addResizePropertiesToElement(nativeElement) {
806
906
  this.renderer.setProperty(nativeElement, 'resizeRef', this);
807
907
  }
908
+ subscribeToScrollEvents() {
909
+ this.scrollEventsSubscription = this.auto_scroll_dir.scrollDeltaObserver.subscribe(({ scrollLeft, scrollTop }) => {
910
+ const scale = this.scale;
911
+ const target = this.el.nativeElement;
912
+ const { width: prevWidth, height: prevHeight } = target.getBoundingClientRect();
913
+ const deltaHeight = scrollTop * (this.activeEdges.top ? -1 : this.activeEdges.bottom ? 1 : 0);
914
+ const deltaWidth = scrollLeft * (this.activeEdges.left ? -1 : this.activeEdges.right ? 1 : 0);
915
+ const height = (prevHeight + deltaHeight) / scale;
916
+ const width = (prevWidth + deltaWidth) / scale;
917
+ const deltaX = this.activeEdges.left ? (scrollLeft / scale) : 0;
918
+ const deltaY = this.activeEdges.top ? (scrollTop / scale) : 0;
919
+ this.interactService.updateSize(this.interactableId, this.registryId, { deltaX, deltaY, width, height }, this.el.nativeElement);
920
+ });
921
+ }
808
922
  }
809
923
  ResizableDirective.decorators = [
810
924
  { type: Directive, args: [{
@@ -830,7 +944,8 @@ ResizableDirective.ctorParameters = () => [
830
944
  { type: DragRootDirective, decorators: [{ type: Optional }] },
831
945
  { type: AccountForScaleDirective, decorators: [{ type: Optional }] },
832
946
  { type: DraggableDirective, decorators: [{ type: Optional }] },
833
- { type: DropzoneDirective, decorators: [{ type: Optional }, { type: SkipSelf }] }
947
+ { type: DropzoneDirective, decorators: [{ type: Optional }, { type: SkipSelf }] },
948
+ { type: AutoScrollDirective, decorators: [{ type: Optional }, { type: SkipSelf }] }
834
949
  ];
835
950
  ResizableDirective.propDecorators = {
836
951
  enableResizeDefault: [{ type: Input }],
@@ -923,20 +1038,14 @@ GesturableDirective.propDecorators = {
923
1038
  class ApplyScaleDirective {
924
1039
  constructor(el) {
925
1040
  this.el = el;
926
- this.scaleX = 1;
927
- this.scaleY = 1;
928
- this.transformOrigin = '0 0';
1041
+ this._scale = 1;
929
1042
  }
930
1043
  // this setup allows consumers to set x, y scale independently or just set them both with scale
931
1044
  set scale(val) {
932
- this.scaleY = val;
933
- this.scaleX = val;
1045
+ this._scale;
1046
+ this.fontSize = `${val}px`;
934
1047
  }
935
1048
  ;
936
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
937
- ngOnChanges(_changes) {
938
- this.transform = `scaleX(${this.scaleX}) scaleY(${this.scaleY})`;
939
- }
940
1049
  }
941
1050
  ApplyScaleDirective.decorators = [
942
1051
  { type: Directive, args: [{
@@ -948,10 +1057,7 @@ ApplyScaleDirective.ctorParameters = () => [
948
1057
  ];
949
1058
  ApplyScaleDirective.propDecorators = {
950
1059
  scale: [{ type: Input }],
951
- scaleX: [{ type: Input }],
952
- scaleY: [{ type: Input }],
953
- transform: [{ type: HostBinding, args: ['style.transform',] }],
954
- transformOrigin: [{ type: Input }, { type: HostBinding, args: ['style.transformOrigin',] }]
1060
+ fontSize: [{ type: HostBinding, args: ['style.fontSize',] }]
955
1061
  };
956
1062
 
957
1063
  const EXPORTS = [
@@ -960,16 +1066,28 @@ const EXPORTS = [
960
1066
  DropzoneDirective,
961
1067
  GesturableDirective,
962
1068
  DragRootDirective,
1069
+ AutoScrollDirective,
963
1070
  AccountForScaleDirective,
964
1071
  ApplyScaleDirective,
965
1072
  DragPreviewDirective,
966
1073
  ArrayOfNPipe,
967
1074
  ];
968
1075
  class InteractModule {
1076
+ static forRoot(config) {
1077
+ const defaultConfig = { cssDimensionUnit: 'px' };
1078
+ return {
1079
+ ngModule: InteractModule,
1080
+ providers: [
1081
+ { provide: INTERACT_ROOT_CONFIG, useValue: Object.assign(Object.assign({}, defaultConfig), config) },
1082
+ InteractService
1083
+ ]
1084
+ };
1085
+ }
969
1086
  }
970
1087
  InteractModule.decorators = [
971
1088
  { type: NgModule, args: [{
972
1089
  imports: [CommonModule],
1090
+ // providers: [{ provide: INTERACT_ROOT_CONFIG, useValue: 'px' }],
973
1091
  declarations: [
974
1092
  ...EXPORTS,
975
1093
  ],
@@ -983,5 +1101,5 @@ InteractModule.decorators = [
983
1101
  * Generated bundle index. Do not edit.
984
1102
  */
985
1103
 
986
- export { AccountForScaleDirective, ApplyScaleDirective, ArrayOfNPipe, DEFAULT_REGISTRY_ID, DragPreviewDirective, DragRootDirective, DraggableDirective, DropzoneDirective, GesturableDirective, InteractModule, ResizableDirective, TFT_DRAG_PREVIEW, cloneElement$1 as cloneElement, defaultDelta, defaultPosition, defaultSize, getClosestMatchingAncestor, getRootNode, DraggableDirective as ɵa, ResizableDirective as ɵb, DropzoneDirective as ɵc, GesturableDirective as ɵd, DragRootDirective as ɵe, AccountForScaleDirective as ɵf, ApplyScaleDirective as ɵg, DragPreviewDirective as ɵh, ArrayOfNPipe as ɵi };
1104
+ export { AccountForScaleDirective, ApplyScaleDirective, ArrayOfNPipe, AutoScrollDirective, DEFAULT_REGISTRY_ID, DragPreviewDirective, DragRootDirective, DraggableDirective, DropzoneDirective, GesturableDirective, INTERACT_ROOT_CONFIG, InteractModule, ResizableDirective, TFT_DRAG_PREVIEW, cloneElement$1 as cloneElement, defaultDelta, defaultPosition, defaultSize, getClosestMatchingAncestor, getRootNode, DraggableDirective as ɵa, ResizableDirective as ɵb, DropzoneDirective as ɵc, GesturableDirective as ɵd, DragRootDirective as ɵe, AutoScrollDirective as ɵf, AccountForScaleDirective as ɵg, ApplyScaleDirective as ɵh, DragPreviewDirective as ɵi, ArrayOfNPipe as ɵj };
987
1105
  //# sourceMappingURL=tft-interact.js.map