@tft/interact 12.4.3 → 12.5.0

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 (40) hide show
  1. package/bundles/tft-interact.umd.js +65 -74
  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/apply-scale.directive.js +4 -13
  7. package/esm2015/lib/directives/apply-scale.directive.js.map +1 -1
  8. package/esm2015/lib/directives/apply-scale.directive.metadata.json +1 -1
  9. package/esm2015/lib/directives/drag-root.directive.js +8 -11
  10. package/esm2015/lib/directives/drag-root.directive.js.map +1 -1
  11. package/esm2015/lib/directives/drag-root.directive.metadata.json +1 -1
  12. package/esm2015/lib/directives/draggable.directive.js +8 -9
  13. package/esm2015/lib/directives/draggable.directive.js.map +1 -1
  14. package/esm2015/lib/directives/draggable.directive.metadata.json +1 -1
  15. package/esm2015/lib/directives/dropzone.directive.js +2 -5
  16. package/esm2015/lib/directives/dropzone.directive.js.map +1 -1
  17. package/esm2015/lib/directives/index.js.map +1 -1
  18. package/esm2015/lib/interact.module.js +13 -0
  19. package/esm2015/lib/interact.module.js.map +1 -1
  20. package/esm2015/lib/interact.module.metadata.json +1 -1
  21. package/esm2015/lib/models/interact.js +2 -0
  22. package/esm2015/lib/models/interact.js.map +1 -1
  23. package/esm2015/lib/models/interact.metadata.json +1 -1
  24. package/esm2015/lib/services/interact.service.js +30 -23
  25. package/esm2015/lib/services/interact.service.js.map +1 -1
  26. package/esm2015/lib/services/interact.service.metadata.json +1 -1
  27. package/fesm2015/tft-interact.js +65 -71
  28. package/fesm2015/tft-interact.js.map +1 -1
  29. package/lib/directives/account-for-scale.directive.d.ts +1 -3
  30. package/lib/directives/apply-scale.directive.d.ts +4 -7
  31. package/lib/directives/drag-root.directive.d.ts +2 -1
  32. package/lib/directives/draggable.directive.d.ts +2 -1
  33. package/lib/directives/dropzone.directive.d.ts +4 -4
  34. package/lib/interact.module.d.ts +3 -0
  35. package/lib/models/interact.d.ts +6 -0
  36. package/lib/services/interact.service.d.ts +4 -5
  37. package/package.json +1 -1
  38. package/tft-interact-12.5.0.tgz +0 -0
  39. package/tft-interact.metadata.json +1 -1
  40. package/tft-interact-12.4.3.tgz +0 -0
@@ -361,6 +361,7 @@
361
361
  },] }
362
362
  ];
363
363
 
364
+ var INTERACT_ROOT_CONFIG = new i0.InjectionToken('INTERACT_ROOT_CONFIG_PARAMS');
364
365
  var DEFAULT_REGISTRY_ID = 'DEFAULT';
365
366
  /**
366
367
  * Default initial value for Delta BehaviorSubject
@@ -388,14 +389,17 @@
388
389
  };
389
390
 
390
391
  var InteractService = /** @class */ (function () {
391
- function InteractService(rendererFactory, ngZone) {
392
+ function InteractService(rendererFactory, ngZone, rootConfig) {
392
393
  this.rendererFactory = rendererFactory;
393
394
  this.ngZone = ngZone;
395
+ this.rootConfig = rootConfig;
394
396
  this._interactableIndex = 0;
395
397
  this._dropzoneIndex = 0;
396
398
  // TODO: consider using Map here
397
399
  this.dragRegistrySystem = {};
400
+ this.cssUnit = 'px';
398
401
  this.renderer = this.rendererFactory.createRenderer(null, null);
402
+ this.cssUnit = (rootConfig === null || rootConfig === void 0 ? void 0 : rootConfig.cssDimensionUnit) || 'px';
399
403
  }
400
404
  InteractService.prototype.addDeltaToPosition = function (delta, position) {
401
405
  return {
@@ -517,8 +521,8 @@
517
521
  };
518
522
  InteractService.prototype.interactableExistOnRegistry = function (interactId, registryId) {
519
523
  if (registryId === void 0) { registryId = DEFAULT_REGISTRY_ID; }
520
- return this.dragRegistrySystem.hasOwnProperty(registryId)
521
- && this.dragRegistrySystem[registryId].hasOwnProperty(interactId);
524
+ // eslint-disable-next-line no-prototype-builtins
525
+ return this.dragRegistrySystem.hasOwnProperty(registryId) && this.dragRegistrySystem[registryId].hasOwnProperty(interactId);
522
526
  };
523
527
  /**
524
528
  * Uses renderer to set width and height of angular component
@@ -532,15 +536,15 @@
532
536
  return;
533
537
  var accountForScaleDirective = (_a = target.resizeRef) === null || _a === void 0 ? void 0 : _a.account_for_scale_dir;
534
538
  if (accountForScaleDirective) {
535
- var scaleX = accountForScaleDirective.scaleX, scaleY = accountForScaleDirective.scaleY;
536
- var scaledWidth = width / scaleX;
537
- var scaledHeight = height / scaleY;
538
- this.renderer.setStyle(target, 'width', scaledWidth + "px");
539
- this.renderer.setStyle(target, 'height', scaledHeight + "px");
539
+ var scale = accountForScaleDirective.scale;
540
+ var scaledWidth = width / scale;
541
+ var scaledHeight = height / scale;
542
+ this.renderer.setStyle(target, 'width', "" + scaledWidth + this.cssUnit);
543
+ this.renderer.setStyle(target, 'height', "" + scaledHeight + this.cssUnit);
540
544
  }
541
545
  else {
542
- this.renderer.setStyle(target, 'width', width + "px");
543
- this.renderer.setStyle(target, 'height', height + "px");
546
+ this.renderer.setStyle(target, 'width', "" + width + this.cssUnit);
547
+ this.renderer.setStyle(target, 'height', "" + height + this.cssUnit);
544
548
  }
545
549
  };
546
550
  /**
@@ -553,15 +557,16 @@
553
557
  var _a, _b;
554
558
  if (!(position === null || position === void 0 ? void 0 : position.targetElement))
555
559
  return;
556
- var accountForScaleDirective = (_b = (_a = position.targetElement) === null || _a === void 0 ? void 0 : _a.dragRef) === null || _b === void 0 ? void 0 : _b.account_for_scale_dir;
560
+ var dragRef = (_a = position.targetElement) === null || _a === void 0 ? void 0 : _a.dragRef;
561
+ var accountForScaleDirective = (dragRef === null || dragRef === void 0 ? void 0 : dragRef.account_for_scale_dir) || ((_b = dragRef === null || dragRef === void 0 ? void 0 : dragRef.dragRoot) === null || _b === void 0 ? void 0 : _b.account_for_scale_dir);
557
562
  if (accountForScaleDirective) {
558
- var scaleX = accountForScaleDirective.scaleX, scaleY = accountForScaleDirective.scaleY;
559
- this.renderer.setStyle(position.targetElement, 'left', x / scaleX + "px");
560
- this.renderer.setStyle(position.targetElement, 'top', y / scaleY + "px");
563
+ var scale = accountForScaleDirective.scale;
564
+ this.renderer.setStyle(position.targetElement, 'left', "" + x / scale + this.cssUnit);
565
+ this.renderer.setStyle(position.targetElement, 'top', "" + y / scale + this.cssUnit);
561
566
  }
562
567
  else {
563
- this.renderer.setStyle(position.targetElement, 'left', x + "px");
564
- this.renderer.setStyle(position.targetElement, 'top', y + "px");
568
+ this.renderer.setStyle(position.targetElement, 'left', "" + x + this.cssUnit);
569
+ this.renderer.setStyle(position.targetElement, 'top', "" + y + this.cssUnit);
565
570
  }
566
571
  };
567
572
  /**
@@ -571,7 +576,7 @@
571
576
  * @param y the position along the y axis
572
577
  */
573
578
  InteractService.prototype.createTransformString = function (x, y) {
574
- return "translate3d(" + x + "px, " + y + "px, 0)";
579
+ return "translate3d(" + x + this.cssUnit + ", " + y + this.cssUnit + ", 0)";
575
580
  };
576
581
  InteractService.prototype.calculatePositionInElement = function (zoneElement, dragElement, scale) {
577
582
  // TODO: this calculation may not cover a lot of scenarios, keep an eye out for possible improvements
@@ -579,23 +584,25 @@
579
584
  var dragRect = dragElement.getBoundingClientRect();
580
585
  var position = scale
581
586
  ? {
582
- x: (dragRect.left - zoneRect.left) / scale.x || 1,
583
- y: (dragRect.top - zoneRect.top) / scale.y || 1
587
+ x: (dragRect.left - zoneRect.left) / scale || 1,
588
+ y: (dragRect.top - zoneRect.top) / scale || 1
584
589
  } : {
585
590
  x: dragRect.left - zoneRect.left,
586
591
  y: dragRect.top - zoneRect.top
587
592
  };
593
+ // console.log({ y:position.y, drt:dragRect.top, zrt: zoneRect.top})
588
594
  return position;
589
595
  };
590
596
  return InteractService;
591
597
  }());
592
- InteractService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function InteractService_Factory() { return new InteractService(i0__namespace.ɵɵinject(i0__namespace.RendererFactory2), i0__namespace.ɵɵinject(i0__namespace.NgZone)); }, token: InteractService, providedIn: "root" });
598
+ InteractService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function InteractService_Factory() { return new InteractService(i0__namespace.ɵɵinject(i0__namespace.RendererFactory2), i0__namespace.ɵɵinject(i0__namespace.NgZone), i0__namespace.ɵɵinject(INTERACT_ROOT_CONFIG, 8)); }, token: InteractService, providedIn: "root" });
593
599
  InteractService.decorators = [
594
600
  { type: i0.Injectable, args: [{ providedIn: 'root' },] }
595
601
  ];
596
602
  InteractService.ctorParameters = function () { return [
597
603
  { type: i0.RendererFactory2 },
598
- { type: i0.NgZone }
604
+ { type: i0.NgZone },
605
+ { type: undefined, decorators: [{ type: i0.Optional }, { type: i0.Inject, args: [INTERACT_ROOT_CONFIG,] }] }
599
606
  ]; };
600
607
 
601
608
  /**
@@ -607,19 +614,9 @@
607
614
  var AccountForScaleDirective = /** @class */ (function () {
608
615
  function AccountForScaleDirective(el) {
609
616
  this.el = el;
610
- this.scaleX = 1;
611
- this.scaleY = 1;
612
- }
613
- Object.defineProperty(AccountForScaleDirective.prototype, "scale", {
614
617
  // this setup allows consumers to set x, y scale independently or just set them both with scale
615
- set: function (val) {
616
- this.scaleY = val;
617
- this.scaleX = val;
618
- },
619
- enumerable: false,
620
- configurable: true
621
- });
622
- ;
618
+ this.scale = 1;
619
+ }
623
620
  return AccountForScaleDirective;
624
621
  }());
625
622
  AccountForScaleDirective.decorators = [
@@ -631,9 +628,7 @@
631
628
  { type: i0.ElementRef }
632
629
  ]; };
633
630
  AccountForScaleDirective.propDecorators = {
634
- scale: [{ type: i0.Input }],
635
- scaleX: [{ type: i0.Input }],
636
- scaleY: [{ type: i0.Input }]
631
+ scale: [{ type: i0.Input }]
637
632
  };
638
633
 
639
634
  var DropzoneDirective = /** @class */ (function () {
@@ -692,13 +687,10 @@
692
687
  * @param event the drop event emitted by interact, extended with extra fields we added to
693
688
  */
694
689
  DropzoneDirective.prototype.mapDropzoneEvent = function (event) {
695
- var _a, _b;
690
+ var _a, _b, _c;
696
691
  var zoneElement = event.target;
697
692
  var dragElement = (_b = (_a = event.relatedTarget) === null || _a === void 0 ? void 0 : _a.dragRef) === null || _b === void 0 ? void 0 : _b.previewRef;
698
- var scale = this.account_for_scale_dir ? {
699
- x: this.account_for_scale_dir.scaleX,
700
- y: this.account_for_scale_dir.scaleY
701
- } : null;
693
+ var scale = ((_c = this.account_for_scale_dir) === null || _c === void 0 ? void 0 : _c.scale) || null;
702
694
  var positionInDropTarget = zoneElement && dragElement
703
695
  ? this.interactService.calculatePositionInElement(zoneElement, dragElement, scale)
704
696
  : null;
@@ -797,22 +789,19 @@
797
789
  * @note this directive will overwrite any style transformations (e.g. transform: scale(2); )
798
790
  */
799
791
  var DragRootDirective = /** @class */ (function () {
800
- function DragRootDirective(el, account_for_scale_dir) {
792
+ function DragRootDirective(el,
793
+ // This is used when passing a dragRoot as in input to a draggable element that not a child of that dragRoot
794
+ // 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
795
+ account_for_scale_dir) {
801
796
  this.el = el;
802
- // This accounts for a bug where drag element is misaligned when using a drag root
803
- // with a dropzone inside of it and a drag item inside the dropzone
804
- // e.g <div tftDragRoot> <div tftDropzone> <div tftDraggable</div> </div> </div>
805
- // TODO: This is a band-aid, root cause in misunderstood, it started after switching from
806
- // using `translate3d` to top/left for positioning
807
- if (!account_for_scale_dir) {
808
- el.nativeElement.style.transform = 'scale(1)';
809
- }
797
+ this.account_for_scale_dir = account_for_scale_dir;
810
798
  }
811
799
  return DragRootDirective;
812
800
  }());
813
801
  DragRootDirective.decorators = [
814
802
  { type: i0.Directive, args: [{
815
- selector: '[tftDragRoot]'
803
+ selector: '[tftDragRoot]',
804
+ exportAs: 'tftDragRoot'
816
805
  },] }
817
806
  ];
818
807
  DragRootDirective.ctorParameters = function () { return [
@@ -850,12 +839,12 @@
850
839
  }
851
840
  DraggableDirective.prototype.ngOnInit = function () {
852
841
  var _this = this;
853
- var _a, _b, _c;
842
+ var _a, _b, _c, _d, _e;
854
843
  this.interactable = this.initiateDragEvents(this.dragConfig, this.el.nativeElement);
855
- 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;
844
+ 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;
856
845
  // register with parent dropzone if it exists, otherwise use default
857
846
  // this gives us a place on the registry to store our drag items that don't have a dropzone
858
- this.registryId = ((_c = this.dropzone_dir) === null || _c === void 0 ? void 0 : _c.dropzoneId) || DEFAULT_REGISTRY_ID;
847
+ this.registryId = ((_e = this.dropzone_dir) === null || _e === void 0 ? void 0 : _e.dropzoneId) || DEFAULT_REGISTRY_ID;
859
848
  // add draggable to directory and store its id
860
849
  this.interactableId = this.interactService.addDraggableToRegistry(this.registryId, this.interactableId);
861
850
  this.alignPositionWithInputs(this.x, this.y);
@@ -911,7 +900,7 @@
911
900
  DraggableDirective.prototype.setDragStyles = function (dragElement) {
912
901
  this.renderer.setStyle(dragElement, 'touchAction', 'none');
913
902
  this.renderer.setStyle(dragElement, 'zIndex', this.dragZIndex);
914
- this.renderer.setStyle(dragElement, 'position', 'fixed');
903
+ this.renderer.setStyle(dragElement, 'position', 'absolute');
915
904
  };
916
905
  DraggableDirective.prototype.addDragPropertiesToElement = function (nativeElement) {
917
906
  this.renderer.setProperty(nativeElement, 'dropTarget', this.dropzone_dir || null);
@@ -971,8 +960,8 @@
971
960
  }
972
961
  _this.addDragPropertiesToElement(_this.previewRef);
973
962
  _this.setDragStyles(_this.previewRef);
974
- _this.dragRoot.prepend(_this.previewRef);
975
- var _d = _this.interactService.calculatePositionInElement(_this.dragRoot, nativeElement), x = _d.x, y = _d.y;
963
+ _this.dragRootEl.prepend(_this.previewRef);
964
+ var _f = _this.interactService.calculatePositionInElement(_this.dragRootEl, nativeElement), x = _f.x, y = _f.y;
976
965
  _this.interactService.updatePosition(_this.interactableId, _this.registryId, { x: x, y: y }, _this.previewRef);
977
966
  if (!_this.showPlaceholder) {
978
967
  _this.renderer.setStyle(_this.el.nativeElement, 'display', 'none');
@@ -994,16 +983,15 @@
994
983
  .on('dragend', function (event) {
995
984
  var mappedEvent = _this.mapDragEvent(event);
996
985
  if (!!_this.dropzone_dir && _this.dropzone_dir === event.target.dropTarget) {
997
- var _d = mappedEvent.positionInDropTarget, x = _d.x, y = _d.y;
986
+ var _f = mappedEvent.positionInDropTarget, x = _f.x, y = _f.y;
998
987
  _this.setPosition(x, y);
999
988
  }
1000
989
  _this.renderer.setStyle(_this.el.nativeElement, 'display', '');
1001
990
  _this.dragEnd.emit(mappedEvent);
1002
991
  if (_this.el.nativeElement !== _this.previewRef) {
1003
- // we do this in a timeout, so that we don't
1004
- // remove before the dropzone can get the boundingElementRect
992
+ // we do this in a timeout, so that we don't remove before the dropzone can get the boundingElementRect
1005
993
  setTimeout(function () {
1006
- _this.dragRoot.removeChild(_this.previewRef);
994
+ _this.dragRootEl.removeChild(_this.previewRef);
1007
995
  });
1008
996
  }
1009
997
  });
@@ -1293,24 +1281,18 @@
1293
1281
  var ApplyScaleDirective = /** @class */ (function () {
1294
1282
  function ApplyScaleDirective(el) {
1295
1283
  this.el = el;
1296
- this.scaleX = 1;
1297
- this.scaleY = 1;
1298
- this.transformOrigin = '0 0';
1284
+ this._scale = 1;
1299
1285
  }
1300
1286
  Object.defineProperty(ApplyScaleDirective.prototype, "scale", {
1301
1287
  // this setup allows consumers to set x, y scale independently or just set them both with scale
1302
1288
  set: function (val) {
1303
- this.scaleY = val;
1304
- this.scaleX = val;
1289
+ this._scale;
1290
+ this.fontSize = val + "px";
1305
1291
  },
1306
1292
  enumerable: false,
1307
1293
  configurable: true
1308
1294
  });
1309
1295
  ;
1310
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1311
- ApplyScaleDirective.prototype.ngOnChanges = function (_changes) {
1312
- this.transform = "scaleX(" + this.scaleX + ") scaleY(" + this.scaleY + ")";
1313
- };
1314
1296
  return ApplyScaleDirective;
1315
1297
  }());
1316
1298
  ApplyScaleDirective.decorators = [
@@ -1323,10 +1305,7 @@
1323
1305
  ]; };
1324
1306
  ApplyScaleDirective.propDecorators = {
1325
1307
  scale: [{ type: i0.Input }],
1326
- scaleX: [{ type: i0.Input }],
1327
- scaleY: [{ type: i0.Input }],
1328
- transform: [{ type: i0.HostBinding, args: ['style.transform',] }],
1329
- transformOrigin: [{ type: i0.Input }, { type: i0.HostBinding, args: ['style.transformOrigin',] }]
1308
+ fontSize: [{ type: i0.HostBinding, args: ['style.fontSize',] }]
1330
1309
  };
1331
1310
 
1332
1311
  var EXPORTS = [
@@ -1343,11 +1322,22 @@
1343
1322
  var InteractModule = /** @class */ (function () {
1344
1323
  function InteractModule() {
1345
1324
  }
1325
+ InteractModule.forRoot = function (config) {
1326
+ var defaultConfig = { cssDimensionUnit: 'px' };
1327
+ return {
1328
+ ngModule: InteractModule,
1329
+ providers: [
1330
+ { provide: INTERACT_ROOT_CONFIG, useValue: Object.assign(Object.assign({}, defaultConfig), config) },
1331
+ InteractService
1332
+ ]
1333
+ };
1334
+ };
1346
1335
  return InteractModule;
1347
1336
  }());
1348
1337
  InteractModule.decorators = [
1349
1338
  { type: i0.NgModule, args: [{
1350
1339
  imports: [common.CommonModule],
1340
+ // providers: [{ provide: INTERACT_ROOT_CONFIG, useValue: 'px' }],
1351
1341
  declarations: __spreadArray([], __read(EXPORTS)),
1352
1342
  exports: __spreadArray([], __read(EXPORTS))
1353
1343
  },] }
@@ -1366,6 +1356,7 @@
1366
1356
  exports.DraggableDirective = DraggableDirective;
1367
1357
  exports.DropzoneDirective = DropzoneDirective;
1368
1358
  exports.GesturableDirective = GesturableDirective;
1359
+ exports.INTERACT_ROOT_CONFIG = INTERACT_ROOT_CONFIG;
1369
1360
  exports.InteractModule = InteractModule;
1370
1361
  exports.ResizableDirective = ResizableDirective;
1371
1362
  exports.TFT_DRAG_PREVIEW = TFT_DRAG_PREVIEW;