@tft/interact 12.5.0 → 12.5.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.
@@ -419,7 +419,7 @@
419
419
  if (interactableId === void 0) { interactableId = null; }
420
420
  var registryId = customRegistryId || DEFAULT_REGISTRY_ID;
421
421
  // if we pass an id to createInteractableId then it is used when creating the interactable
422
- // and returned, otherwise a an id is created for the draggable.
422
+ // and returned, otherwise a new id is created for the draggable.
423
423
  var key = this.createInteractableId(interactableId);
424
424
  if (!Object.prototype.hasOwnProperty.call(this.dragRegistrySystem, registryId)) {
425
425
  this.dragRegistrySystem[registryId] = {};
@@ -430,6 +430,11 @@
430
430
  InteractService.prototype.destroyInteractable = function (interactableId, registryId) {
431
431
  if (registryId === void 0) { registryId = DEFAULT_REGISTRY_ID; }
432
432
  if (this.dragRegistrySystem[registryId][interactableId]) {
433
+ // unsubscribe from all the subscriptions if they're subscriptions
434
+ for (var propName in this.dragRegistrySystem[registryId][interactableId]) {
435
+ var prop = this.dragRegistrySystem[registryId][interactableId][propName];
436
+ prop === null || prop === void 0 ? void 0 : prop.unsubscribe();
437
+ }
433
438
  delete this.dragRegistrySystem[registryId][interactableId];
434
439
  }
435
440
  };
@@ -450,8 +455,8 @@
450
455
  // startWith({...initialSize, ...initialDelta}),
451
456
  operators.shareReplay(1),
452
457
  // filter(resizeEvent => !!resizeEvent.targetElement),
453
- operators.tap(function (_c) {
454
- var deltaX = _c.deltaX, deltaY = _c.deltaY, width = _c.width, height = _c.height, targetElement = _c.targetElement;
458
+ operators.tap(function (_a) {
459
+ var deltaX = _a.deltaX, deltaY = _a.deltaY, width = _a.width, height = _a.height, targetElement = _a.targetElement;
455
460
  _this.ngZone.runOutsideAngular(function () {
456
461
  _this.setElementSize(width, height, targetElement);
457
462
  });
@@ -470,8 +475,8 @@
470
475
  _this.setElementTransform(position.x, position.y, position);
471
476
  });
472
477
  }))
473
- ]).pipe(operators.shareReplay(1), operators.map(function (_c) {
474
- var _d = __read(_c, 3), size = _d[0], deltas = _d[1], position = _d[2];
478
+ ]).pipe(operators.shareReplay(1), operators.map(function (_a) {
479
+ var _b = __read(_a, 3), size = _b[0], deltas = _b[1], position = _b[2];
475
480
  return {
476
481
  x: position.x,
477
482
  y: position.y,
@@ -501,20 +506,20 @@
501
506
  if (registryId === void 0) { registryId = DEFAULT_REGISTRY_ID; }
502
507
  return this.dragRegistrySystem[registryId][interactableId].interactable$;
503
508
  };
504
- InteractService.prototype.updateDeltas = function (interactId, registryId, _c, targetElement) {
505
- var deltaX = _c.deltaX, deltaY = _c.deltaY;
509
+ InteractService.prototype.updateDeltas = function (interactId, registryId, _a, targetElement) {
510
+ var deltaX = _a.deltaX, deltaY = _a.deltaY;
506
511
  if (!this.interactableExistOnRegistry(interactId, registryId))
507
512
  return;
508
513
  this.dragRegistrySystem[registryId][interactId].deltas$.next({ deltaX: deltaX, deltaY: deltaY, targetElement: targetElement });
509
514
  };
510
- InteractService.prototype.updatePosition = function (interactId, registryId, _c, targetElement) {
511
- var x = _c.x, y = _c.y;
515
+ InteractService.prototype.updatePosition = function (interactId, registryId, _a, targetElement) {
516
+ var x = _a.x, y = _a.y;
512
517
  if (!this.interactableExistOnRegistry(interactId, registryId))
513
518
  return;
514
519
  this.dragRegistrySystem[registryId][interactId].position$.next({ x: x, y: y, targetElement: targetElement });
515
520
  };
516
- InteractService.prototype.updateSize = function (interactId, registryId, _c, targetElement) {
517
- var deltaX = _c.deltaX, deltaY = _c.deltaY, width = _c.width, height = _c.height;
521
+ InteractService.prototype.updateSize = function (interactId, registryId, _a, targetElement) {
522
+ var deltaX = _a.deltaX, deltaY = _a.deltaY, width = _a.width, height = _a.height;
518
523
  if (!this.interactableExistOnRegistry(interactId, registryId))
519
524
  return;
520
525
  this.dragRegistrySystem[registryId][interactId].size$.next({ deltaX: deltaX, deltaY: deltaY, width: width, height: height, targetElement: targetElement });
@@ -531,21 +536,10 @@
531
536
  * @param target the element to transform
532
537
  */
533
538
  InteractService.prototype.setElementSize = function (width, height, target) {
534
- var _a;
535
539
  if (!target)
536
540
  return;
537
- var accountForScaleDirective = (_a = target.resizeRef) === null || _a === void 0 ? void 0 : _a.account_for_scale_dir;
538
- if (accountForScaleDirective) {
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);
544
- }
545
- else {
546
- this.renderer.setStyle(target, 'width', "" + width + this.cssUnit);
547
- this.renderer.setStyle(target, 'height', "" + height + this.cssUnit);
548
- }
541
+ this.renderer.setStyle(target, 'width', "" + width + this.cssUnit);
542
+ this.renderer.setStyle(target, 'height', "" + height + this.cssUnit);
549
543
  };
550
544
  /**
551
545
  * Uses renderer to set position of angular component
@@ -554,20 +548,10 @@
554
548
  * @param target the element to transform
555
549
  */
556
550
  InteractService.prototype.setElementTransform = function (x, y, position) {
557
- var _a, _b;
558
551
  if (!(position === null || position === void 0 ? void 0 : position.targetElement))
559
552
  return;
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);
562
- if (accountForScaleDirective) {
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);
566
- }
567
- else {
568
- this.renderer.setStyle(position.targetElement, 'left', "" + x + this.cssUnit);
569
- this.renderer.setStyle(position.targetElement, 'top', "" + y + this.cssUnit);
570
- }
553
+ this.renderer.setStyle(position.targetElement, 'left', "" + x + this.cssUnit);
554
+ this.renderer.setStyle(position.targetElement, 'top', "" + y + this.cssUnit);
571
555
  };
572
556
  /**
573
557
  * Generates a translate string for the x and y arguments passed to
@@ -644,6 +628,14 @@
644
628
  this.dragLeave = new i0.EventEmitter();
645
629
  this.dragDrop = new i0.EventEmitter();
646
630
  }
631
+ Object.defineProperty(DropzoneDirective.prototype, "scale", {
632
+ get: function () {
633
+ var _a;
634
+ return (_a = this.account_for_scale_dir) === null || _a === void 0 ? void 0 : _a.scale;
635
+ },
636
+ enumerable: false,
637
+ configurable: true
638
+ });
647
639
  DropzoneDirective.prototype.ngOnInit = function () {
648
640
  // connects
649
641
  this.dropzone = this.connectDropzoneEvents(this.el.nativeElement, this.dropzoneConfig);
@@ -687,10 +679,10 @@
687
679
  * @param event the drop event emitted by interact, extended with extra fields we added to
688
680
  */
689
681
  DropzoneDirective.prototype.mapDropzoneEvent = function (event) {
690
- var _a, _b, _c;
682
+ var _a, _b;
691
683
  var zoneElement = event.target;
692
684
  var dragElement = (_b = (_a = event.relatedTarget) === null || _a === void 0 ? void 0 : _a.dragRef) === null || _b === void 0 ? void 0 : _b.previewRef;
693
- var scale = ((_c = this.account_for_scale_dir) === null || _c === void 0 ? void 0 : _c.scale) || null;
685
+ var scale = this.scale;
694
686
  var positionInDropTarget = zoneElement && dragElement
695
687
  ? this.interactService.calculatePositionInElement(zoneElement, dragElement, scale)
696
688
  : null;
@@ -812,7 +804,6 @@
812
804
  /** @dynamic */
813
805
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
814
806
  var DraggableDirective = /** @class */ (function () {
815
- // cache holding element to use as placeholder while dragging
816
807
  function DraggableDirective(el, interactService, renderer, _viewContainerRef, _document, account_for_scale_dir, dropzone_dir, drag_root_dir) {
817
808
  this.el = el;
818
809
  this.interactService = interactService;
@@ -837,6 +828,15 @@
837
828
  this.dragInertiaStart = new i0.EventEmitter();
838
829
  this.dragEnd = new i0.EventEmitter();
839
830
  }
831
+ Object.defineProperty(DraggableDirective.prototype, "scale", {
832
+ // check all the different places for scale
833
+ get: function () {
834
+ var _a, _b, _c, _d;
835
+ 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);
836
+ },
837
+ enumerable: false,
838
+ configurable: true
839
+ });
840
840
  DraggableDirective.prototype.ngOnInit = function () {
841
841
  var _this = this;
842
842
  var _a, _b, _c, _d, _e;
@@ -895,7 +895,10 @@
895
895
  };
896
896
  DraggableDirective.prototype.dragMoveListener = function (event, element) {
897
897
  var dx = event.dx, dy = event.dy;
898
- this.interactService.updateDeltas(this.interactableId, this.registryId, { deltaX: dx, deltaY: dy }, element);
898
+ var scale = this.scale;
899
+ var deltaX = scale ? dx / scale : dx;
900
+ var deltaY = scale ? dy / scale : dy;
901
+ this.interactService.updateDeltas(this.interactableId, this.registryId, { deltaX: deltaX, deltaY: deltaY }, element);
899
902
  };
900
903
  DraggableDirective.prototype.setDragStyles = function (dragElement) {
901
904
  this.renderer.setStyle(dragElement, 'touchAction', 'none');
@@ -911,8 +914,9 @@
911
914
  var _a;
912
915
  var target = event.target, dropzone = event.dropzone;
913
916
  var dropzoneElement = (dropzone === null || dropzone === void 0 ? void 0 : dropzone.target) || ((_a = target.dropTarget) === null || _a === void 0 ? void 0 : _a.el.nativeElement);
917
+ var scale = this.scale;
914
918
  var positionInDropTarget = target && dropzoneElement
915
- ? this.interactService.calculatePositionInElement(dropzoneElement, this.previewRef)
919
+ ? this.interactService.calculatePositionInElement(dropzoneElement, this.previewRef, scale)
916
920
  : null;
917
921
  return {
918
922
  interactEvent: event,
@@ -943,6 +947,7 @@
943
947
  var _this = this;
944
948
  return interact__default['default'](nativeElement).draggable(Object.assign(Object.assign({}, dragConfig), { enabled: !(this.disabled || this.dragDisabled) }))
945
949
  .on('dragstart', function (event) {
950
+ var _a, _b, _c;
946
951
  var interaction = event.interaction;
947
952
  // check if we should append drag element to body
948
953
  if (_this.enableDragDefault
@@ -961,7 +966,8 @@
961
966
  _this.addDragPropertiesToElement(_this.previewRef);
962
967
  _this.setDragStyles(_this.previewRef);
963
968
  _this.dragRootEl.prepend(_this.previewRef);
964
- var _f = _this.interactService.calculatePositionInElement(_this.dragRootEl, nativeElement), x = _f.x, y = _f.y;
969
+ var 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;
970
+ var _f = _this.interactService.calculatePositionInElement(_this.dragRootEl, nativeElement, scale), x = _f.x, y = _f.y;
965
971
  _this.interactService.updatePosition(_this.interactableId, _this.registryId, { x: x, y: y }, _this.previewRef);
966
972
  if (!_this.showPlaceholder) {
967
973
  _this.renderer.setStyle(_this.el.nativeElement, 'display', 'none');
@@ -1065,6 +1071,7 @@
1065
1071
  this._document = _document;
1066
1072
  this.interactService = interactService;
1067
1073
  this.renderer = renderer;
1074
+ this.drag_root_dir = drag_root_dir;
1068
1075
  this.account_for_scale_dir = account_for_scale_dir;
1069
1076
  this.draggable_dir = draggable_dir;
1070
1077
  this.dropzone_dir = dropzone_dir;
@@ -1079,8 +1086,16 @@
1079
1086
  this.defaultConfig = {
1080
1087
  edges: { left: true, right: true, bottom: true, top: true }
1081
1088
  };
1082
- 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;
1089
+ 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;
1083
1090
  }
1091
+ Object.defineProperty(ResizableDirective.prototype, "scale", {
1092
+ get: function () {
1093
+ var _a, _b;
1094
+ 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);
1095
+ },
1096
+ enumerable: false,
1097
+ configurable: true
1098
+ });
1084
1099
  ResizableDirective.prototype.ngOnInit = function () {
1085
1100
  var _a, _b;
1086
1101
  this.addResizePropertiesToElement(this.el.nativeElement);
@@ -1108,9 +1123,23 @@
1108
1123
  this.interactService.destroyInteractable(this.interactableId, this.registryId);
1109
1124
  };
1110
1125
  ResizableDirective.prototype.resizeListener = function (event) {
1111
- var deltaX = event.deltaRect.left;
1112
- var deltaY = event.deltaRect.top;
1113
- var _c = event.rect, width = _c.width, height = _c.height;
1126
+ var scale = this.scale;
1127
+ var deltaX;
1128
+ var deltaY;
1129
+ var height;
1130
+ var width;
1131
+ if (scale) {
1132
+ deltaX = event.deltaRect.left / scale;
1133
+ deltaY = event.deltaRect.top / scale;
1134
+ height = event.rect.height / scale;
1135
+ width = event.rect.width / scale;
1136
+ }
1137
+ else {
1138
+ deltaX = event.deltaRect.left;
1139
+ deltaY = event.deltaRect.top;
1140
+ width = event.rect.width;
1141
+ height = event.rect.height;
1142
+ }
1114
1143
  this.interactService.updateSize(this.interactableId, this.registryId, { deltaX: deltaX, deltaY: deltaY, width: width, height: height }, this.el.nativeElement);
1115
1144
  };
1116
1145
  /**
@@ -1138,16 +1167,16 @@
1138
1167
  .on('resizeend', function (event) { return _this.resizeEnd.emit(_this.mapResizeEvent(event)); });
1139
1168
  };
1140
1169
  ResizableDirective.prototype.mapResizeEvent = function (event) {
1141
- var _a, _b;
1170
+ var _a, _b, _c, _d, _e;
1142
1171
  var target = event.target;
1143
1172
  var relatedTarget = (_b = (_a = this.draggable_dir) === null || _a === void 0 ? void 0 : _a.dropzone_dir) === null || _b === void 0 ? void 0 : _b.el.nativeElement;
1173
+ var scale = ((_c = this.account_for_scale_dir) === null || _c === void 0 ? void 0 : _c.scale) || ((_e = (_d = this.drag_root_dir) === null || _d === void 0 ? void 0 : _d.account_for_scale_dir) === null || _e === void 0 ? void 0 : _e.scale) || 1;
1144
1174
  var positionInDropTarget = target && relatedTarget
1145
- ? this.interactService.calculatePositionInElement(relatedTarget, target)
1175
+ ? this.interactService.calculatePositionInElement(relatedTarget, target, scale)
1146
1176
  : null;
1147
1177
  return {
1148
1178
  interactEvent: event,
1149
1179
  resizeRef: this,
1150
- // should I remove this?
1151
1180
  dragRef: this.draggable_dir,
1152
1181
  dragOrigin: this.dropzone_dir,
1153
1182
  dropTarget: this.el.nativeElement.dropTarget,