@tft/interact 12.5.2 → 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 (47) hide show
  1. package/bundles/tft-interact.umd.js +137 -30
  2. package/bundles/tft-interact.umd.js.map +1 -1
  3. package/esm2015/lib/directives/account-for-scale.directive.ngfactory.js.map +1 -0
  4. package/esm2015/lib/directives/apply-scale.directive.ngfactory.js.map +1 -0
  5. package/esm2015/lib/directives/auto-scroll.directive.js +54 -0
  6. package/esm2015/lib/directives/auto-scroll.directive.js.map +1 -0
  7. package/esm2015/lib/directives/auto-scroll.directive.metadata.json +1 -0
  8. package/esm2015/lib/directives/auto-scroll.directive.ngfactory.js.map +1 -0
  9. package/esm2015/lib/directives/drag-preview.directive.ngfactory.js.map +1 -0
  10. package/esm2015/lib/directives/drag-root.directive.ngfactory.js.map +1 -0
  11. package/esm2015/lib/directives/draggable.directive.js +24 -3
  12. package/esm2015/lib/directives/draggable.directive.js.map +1 -1
  13. package/esm2015/lib/directives/draggable.directive.metadata.json +1 -1
  14. package/esm2015/lib/directives/draggable.directive.ngfactory.js.map +1 -0
  15. package/esm2015/lib/directives/dropzone.directive.js +4 -2
  16. package/esm2015/lib/directives/dropzone.directive.js.map +1 -1
  17. package/esm2015/lib/directives/dropzone.directive.metadata.json +1 -1
  18. package/esm2015/lib/directives/dropzone.directive.ngfactory.js.map +1 -0
  19. package/esm2015/lib/directives/gesturable.directive.ngfactory.js.map +1 -0
  20. package/esm2015/lib/directives/index.js +1 -0
  21. package/esm2015/lib/directives/index.js.map +1 -1
  22. package/esm2015/lib/directives/index.metadata.json +1 -1
  23. package/esm2015/lib/directives/resizable.directive.js +48 -22
  24. package/esm2015/lib/directives/resizable.directive.js.map +1 -1
  25. package/esm2015/lib/directives/resizable.directive.metadata.json +1 -1
  26. package/esm2015/lib/directives/resizable.directive.ngfactory.js.map +1 -0
  27. package/esm2015/lib/interact.module.js +2 -1
  28. package/esm2015/lib/interact.module.js.map +1 -1
  29. package/esm2015/lib/interact.module.metadata.json +1 -1
  30. package/esm2015/lib/interact.module.ngfactory.js.map +1 -0
  31. package/esm2015/lib/pipes/array-of-n.pipe.ngfactory.js.map +1 -0
  32. package/esm2015/lib/services/interact.service.ngfactory.js.map +1 -0
  33. package/esm2015/tft-interact.js +2 -2
  34. package/esm2015/tft-interact.js.map +1 -1
  35. package/esm2015/tft-interact.metadata.json +1 -1
  36. package/fesm2015/tft-interact.js +129 -30
  37. package/fesm2015/tft-interact.js.map +1 -1
  38. package/lib/directives/auto-scroll.directive.d.ts +31 -0
  39. package/lib/directives/draggable.directive.d.ts +5 -1
  40. package/lib/directives/dropzone.directive.d.ts +2 -0
  41. package/lib/directives/index.d.ts +1 -0
  42. package/lib/directives/resizable.directive.d.ts +7 -2
  43. package/package.json +1 -1
  44. package/tft-interact-12.5.3.tgz +0 -0
  45. package/tft-interact.d.ts +2 -2
  46. package/tft-interact.metadata.json +1 -1
  47. package/tft-interact-12.5.2.tgz +0 -0
@@ -626,6 +626,7 @@
626
626
  this.interactService = interactService;
627
627
  this.account_for_scale_dir = account_for_scale_dir;
628
628
  this.dropzoneConfig = {};
629
+ this.position = 'relative';
629
630
  // proxies to pass interact events through to consumer of directive
630
631
  this.dropActivate = new i0.EventEmitter();
631
632
  this.dragEnter = new i0.EventEmitter();
@@ -704,7 +705,7 @@
704
705
  { type: i0.Directive, args: [{
705
706
  selector: '[tftDropzone]',
706
707
  host: {
707
- '[id]': 'dropzoneId',
708
+ '[id]': 'dropzoneId'
708
709
  }
709
710
  },] }
710
711
  ];
@@ -718,6 +719,7 @@
718
719
  dropzoneId: [{ type: i0.Input }],
719
720
  dropzoneConfig: [{ type: i0.Input }],
720
721
  dropzoneData: [{ type: i0.Input }],
722
+ position: [{ type: i0.Input }, { type: i0.HostBinding, args: ['style.position',] }],
721
723
  dropActivate: [{ type: i0.Output }],
722
724
  dragEnter: [{ type: i0.Output }],
723
725
  dragLeave: [{ type: i0.Output }],
@@ -805,10 +807,63 @@
805
807
  { type: AccountForScaleDirective, decorators: [{ type: i0.Optional }, { type: i0.Self }] }
806
808
  ]; };
807
809
 
810
+ ;
811
+ /**
812
+ * Use to apply scale to the element and tell the drag and resize directives to account for the scale when
813
+ * @example <div tftAccountForScale [scale]="2.5"> <div tftDraggable> </div> </div>
814
+ * @note if `dragRoot` is used this directive should be used on the same element to ensure that the drag
815
+ * element accounts for scale
816
+ */
817
+ var AutoScrollDirective = /** @class */ (function () {
818
+ function AutoScrollDirective(el) {
819
+ var _this = this;
820
+ this.el = el;
821
+ /**
822
+ * Limit minimum time between scroll events in milliseconds
823
+ */
824
+ this.autoScrollConfig = {
825
+ margin: 50,
826
+ distance: 3,
827
+ interval: 50,
828
+ speed: 300,
829
+ enabled: true
830
+ };
831
+ this.scrollDeltaObserver = new rxjs.Subject();
832
+ var _a = el.nativeElement, scrollTop = _a.scrollTop, scrollLeft = _a.scrollLeft;
833
+ this.scrollSubject = new rxjs.BehaviorSubject({ scrollTop: scrollTop, scrollLeft: scrollLeft });
834
+ this.scrollObserver = this.scrollSubject.pipe(operators.scan(function (previous, current) {
835
+ var scrollTop = current.scrollTop - previous.scrollTop;
836
+ var scrollLeft = current.scrollLeft - previous.scrollLeft;
837
+ _this.scrollDeltaObserver.next({ scrollTop: scrollTop, scrollLeft: scrollLeft });
838
+ return current;
839
+ }), operators.shareReplay(1));
840
+ this.scrollObserver.subscribe();
841
+ }
842
+ // this setup allows consumers to set x, y scale independently or just set them both with scale
843
+ AutoScrollDirective.prototype.scroll = function (scrollEvent) {
844
+ var target = scrollEvent.target;
845
+ var scrollTop = target.scrollTop, scrollLeft = target.scrollLeft;
846
+ this.scrollSubject.next({ scrollTop: scrollTop, scrollLeft: scrollLeft });
847
+ };
848
+ return AutoScrollDirective;
849
+ }());
850
+ AutoScrollDirective.decorators = [
851
+ { type: i0.Directive, args: [{
852
+ selector: '[tftAutoScroll]'
853
+ },] }
854
+ ];
855
+ AutoScrollDirective.ctorParameters = function () { return [
856
+ { type: i0.ElementRef }
857
+ ]; };
858
+ AutoScrollDirective.propDecorators = {
859
+ autoScrollConfig: [{ type: i0.Input }],
860
+ scroll: [{ type: i0.HostListener, args: ['scroll', ['$event'],] }]
861
+ };
862
+
808
863
  /** @dynamic */
809
864
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
810
865
  var DraggableDirective = /** @class */ (function () {
811
- function DraggableDirective(el, interactService, renderer, _viewContainerRef, _document, account_for_scale_dir, dropzone_dir, drag_root_dir) {
866
+ function DraggableDirective(el, interactService, renderer, _viewContainerRef, _document, account_for_scale_dir, dropzone_dir, drag_root_dir, auto_scroll_dir) {
812
867
  this.el = el;
813
868
  this.interactService = interactService;
814
869
  this.renderer = renderer;
@@ -817,6 +872,7 @@
817
872
  this.account_for_scale_dir = account_for_scale_dir;
818
873
  this.dropzone_dir = dropzone_dir;
819
874
  this.drag_root_dir = drag_root_dir;
875
+ this.auto_scroll_dir = auto_scroll_dir;
820
876
  /* zIndex while dragging*/
821
877
  this.dragZIndex = 10000;
822
878
  this.enableDragDefault = true;
@@ -949,7 +1005,10 @@
949
1005
  };
950
1006
  DraggableDirective.prototype.initiateDragEvents = function (dragConfig, nativeElement) {
951
1007
  var _this = this;
952
- return interact__default['default'](nativeElement).draggable(Object.assign(Object.assign({}, dragConfig), { enabled: !(this.disabled || this.dragDisabled) }))
1008
+ var defaultDragConfig = Object.assign(Object.assign(Object.assign({}, dragConfig), { enabled: !(this.disabled || this.dragDisabled) }), (this.auto_scroll_dir && {
1009
+ autoScroll: Object.assign(Object.assign({}, this.auto_scroll_dir.autoScrollConfig), { container: this.auto_scroll_dir.el.nativeElement })
1010
+ }));
1011
+ return interact__default['default'](nativeElement).draggable(defaultDragConfig)
953
1012
  .on('dragstart', function (event) {
954
1013
  var _a, _b, _c;
955
1014
  var interaction = event.interaction;
@@ -977,6 +1036,10 @@
977
1036
  _this.renderer.setStyle(_this.el.nativeElement, 'display', 'none');
978
1037
  }
979
1038
  }
1039
+ // subscribe to scroll events if they are there, by only subscribing on dragstart we avoid wasting subscriptions on interactables that aren't be dragged
1040
+ if (_this.auto_scroll_dir) {
1041
+ _this.subscribeToScrollEvents();
1042
+ }
980
1043
  _this.dragStart.emit(_this.mapDragEvent(event));
981
1044
  })
982
1045
  .on('dragmove', function (event) {
@@ -998,6 +1061,10 @@
998
1061
  }
999
1062
  _this.renderer.setStyle(_this.el.nativeElement, 'display', '');
1000
1063
  _this.dragEnd.emit(mappedEvent);
1064
+ // unsubscribe from scroll events if subscribed
1065
+ if (_this.auto_scroll_dir) {
1066
+ _this.scrollEventsSubscription.unsubscribe();
1067
+ }
1001
1068
  if (_this.el.nativeElement !== _this.previewRef) {
1002
1069
  // we do this in a timeout, so that we don't remove before the dropzone can get the boundingElementRect
1003
1070
  setTimeout(function () {
@@ -1006,6 +1073,15 @@
1006
1073
  }
1007
1074
  });
1008
1075
  };
1076
+ DraggableDirective.prototype.subscribeToScrollEvents = function () {
1077
+ var _this = this;
1078
+ this.scrollEventsSubscription = this.auto_scroll_dir.scrollDeltaObserver.subscribe(function (_f) {
1079
+ var scrollLeft = _f.scrollLeft, scrollTop = _f.scrollTop;
1080
+ var deltaX = _this.scale ? scrollLeft / _this.scale : scrollLeft;
1081
+ var deltaY = _this.scale ? scrollTop / _this.scale : scrollTop;
1082
+ _this.interactService.updateDeltas(_this.interactableId, _this.registryId, { deltaX: deltaX, deltaY: deltaY }, _this.previewRef);
1083
+ });
1084
+ };
1009
1085
  return DraggableDirective;
1010
1086
  }());
1011
1087
  DraggableDirective.decorators = [
@@ -1027,7 +1103,8 @@
1027
1103
  { type: Document, decorators: [{ type: i0.Inject, args: [common.DOCUMENT,] }] },
1028
1104
  { type: AccountForScaleDirective, decorators: [{ type: i0.Optional }] },
1029
1105
  { type: DropzoneDirective, decorators: [{ type: i0.Optional }, { type: i0.SkipSelf }] },
1030
- { type: DragRootDirective, decorators: [{ type: i0.Optional }, { type: i0.SkipSelf }] }
1106
+ { type: DragRootDirective, decorators: [{ type: i0.Optional }, { type: i0.SkipSelf }] },
1107
+ { type: AutoScrollDirective, decorators: [{ type: i0.Optional }, { type: i0.SkipSelf }] }
1031
1108
  ]; };
1032
1109
  DraggableDirective.propDecorators = {
1033
1110
  x: [{ type: i0.Input }],
@@ -1069,7 +1146,7 @@
1069
1146
 
1070
1147
  /** @dynamic */
1071
1148
  var ResizableDirective = /** @class */ (function () {
1072
- function ResizableDirective(el, _document, interactService, renderer, drag_root_dir, account_for_scale_dir, draggable_dir, dropzone_dir) {
1149
+ function ResizableDirective(el, _document, interactService, renderer, drag_root_dir, account_for_scale_dir, draggable_dir, dropzone_dir, auto_scroll_dir) {
1073
1150
  var _a;
1074
1151
  this.el = el;
1075
1152
  this._document = _document;
@@ -1079,6 +1156,7 @@
1079
1156
  this.account_for_scale_dir = account_for_scale_dir;
1080
1157
  this.draggable_dir = draggable_dir;
1081
1158
  this.dropzone_dir = dropzone_dir;
1159
+ this.auto_scroll_dir = auto_scroll_dir;
1082
1160
  this.enableResizeDefault = true;
1083
1161
  // TODO: should this be an input with default or should consuming user set display in styles each time
1084
1162
  this.position = 'absolute';
@@ -1090,6 +1168,7 @@
1090
1168
  this.defaultConfig = {
1091
1169
  edges: { left: true, right: true, bottom: true, top: true }
1092
1170
  };
1171
+ this.activeEdges = { left: false, right: false, top: false, bottom: false };
1093
1172
  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;
1094
1173
  }
1095
1174
  Object.defineProperty(ResizableDirective.prototype, "scale", {
@@ -1127,23 +1206,16 @@
1127
1206
  this.interactService.destroyInteractable(this.interactableId, this.registryId);
1128
1207
  };
1129
1208
  ResizableDirective.prototype.resizeListener = function (event) {
1209
+ var element = this.el.nativeElement;
1130
1210
  var scale = this.scale;
1131
- var deltaX;
1132
- var deltaY;
1133
- var height;
1134
- var width;
1135
- if (scale) {
1136
- deltaX = event.deltaRect.left / scale;
1137
- deltaY = event.deltaRect.top / scale;
1138
- height = event.rect.height / scale;
1139
- width = event.rect.width / scale;
1140
- }
1141
- else {
1142
- deltaX = event.deltaRect.left;
1143
- deltaY = event.deltaRect.top;
1144
- width = event.rect.width;
1145
- height = event.rect.height;
1146
- }
1211
+ var deltaRect = event.deltaRect;
1212
+ var deltaX = deltaRect.left / scale;
1213
+ var deltaY = deltaRect.top / scale;
1214
+ // We get the width and height directly from the native element because
1215
+ // the event dimension can get out of sync when resizing with autoScroll
1216
+ var rect = element.getBoundingClientRect();
1217
+ var width = (rect.width + deltaRect.width) / scale;
1218
+ var height = (rect.height + deltaRect.height) / scale;
1147
1219
  this.interactService.updateSize(this.interactableId, this.registryId, { deltaX: deltaX, deltaY: deltaY, width: width, height: height }, this.el.nativeElement);
1148
1220
  };
1149
1221
  /**
@@ -1157,9 +1229,18 @@
1157
1229
  var _this = this;
1158
1230
  var _a;
1159
1231
  // TODO: This should try and get interactable from tft_draggable if it exists
1232
+ var defaultResizeConfig = Object.assign(Object.assign(Object.assign({}, resizeConfig), { enabled: !this.resizeDisabled }), (this.auto_scroll_dir && {
1233
+ autoScroll: Object.assign(Object.assign({}, this.auto_scroll_dir.autoScrollConfig), { container: this.auto_scroll_dir.el.nativeElement })
1234
+ }));
1160
1235
  var interactable = ((_a = this.draggable_dir) === null || _a === void 0 ? void 0 : _a.interactable) || interact__default['default'](nativeElement);
1161
- return interactable.resizable(Object.assign(Object.assign({}, resizeConfig), { enabled: !this.resizeDisabled }))
1162
- .on('resizestart', function (event) { _this.resizeStart.emit(_this.mapResizeEvent(event)); })
1236
+ return interactable.resizable(defaultResizeConfig)
1237
+ .on('resizestart', function (event) {
1238
+ _this.activeEdges = event.edges;
1239
+ if (_this.auto_scroll_dir) {
1240
+ _this.subscribeToScrollEvents();
1241
+ }
1242
+ _this.resizeStart.emit(_this.mapResizeEvent(event));
1243
+ })
1163
1244
  .on('resizemove', function (event) {
1164
1245
  if (_this.enableResizeDefault) {
1165
1246
  _this.resizeListener(event);
@@ -1168,11 +1249,17 @@
1168
1249
  _this.resizeMove.emit(mappedEvent);
1169
1250
  })
1170
1251
  .on('resizeinertiastart', function (event) { return _this.resizeInertiaStart.emit(_this.mapResizeEvent(event)); })
1171
- .on('resizeend', function (event) { return _this.resizeEnd.emit(_this.mapResizeEvent(event)); });
1252
+ .on('resizeend', function (event) {
1253
+ if (_this.auto_scroll_dir) {
1254
+ _this.scrollEventsSubscription.unsubscribe();
1255
+ }
1256
+ _this.activeEdges = { left: false, right: false, top: false, bottom: false };
1257
+ _this.resizeEnd.emit(_this.mapResizeEvent(event));
1258
+ });
1172
1259
  };
1173
1260
  ResizableDirective.prototype.mapResizeEvent = function (event) {
1174
1261
  var _a, _b;
1175
- var target = event.target;
1262
+ var target = this.el.nativeElement;
1176
1263
  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;
1177
1264
  var scale = this.scale;
1178
1265
  var positionInDropTarget = target && relatedTarget
@@ -1197,6 +1284,22 @@
1197
1284
  ResizableDirective.prototype.addResizePropertiesToElement = function (nativeElement) {
1198
1285
  this.renderer.setProperty(nativeElement, 'resizeRef', this);
1199
1286
  };
1287
+ ResizableDirective.prototype.subscribeToScrollEvents = function () {
1288
+ var _this = this;
1289
+ this.scrollEventsSubscription = this.auto_scroll_dir.scrollDeltaObserver.subscribe(function (_d) {
1290
+ var scrollLeft = _d.scrollLeft, scrollTop = _d.scrollTop;
1291
+ var scale = _this.scale;
1292
+ var target = _this.el.nativeElement;
1293
+ var _e = target.getBoundingClientRect(), prevWidth = _e.width, prevHeight = _e.height;
1294
+ var deltaHeight = scrollTop * (_this.activeEdges.top ? -1 : _this.activeEdges.bottom ? 1 : 0);
1295
+ var deltaWidth = scrollLeft * (_this.activeEdges.left ? -1 : _this.activeEdges.right ? 1 : 0);
1296
+ var height = (prevHeight + deltaHeight) / scale;
1297
+ var width = (prevWidth + deltaWidth) / scale;
1298
+ var deltaX = _this.activeEdges.left ? (scrollLeft / scale) : 0;
1299
+ var deltaY = _this.activeEdges.top ? (scrollTop / scale) : 0;
1300
+ _this.interactService.updateSize(_this.interactableId, _this.registryId, { deltaX: deltaX, deltaY: deltaY, width: width, height: height }, _this.el.nativeElement);
1301
+ });
1302
+ };
1200
1303
  return ResizableDirective;
1201
1304
  }());
1202
1305
  ResizableDirective.decorators = [
@@ -1223,7 +1326,8 @@
1223
1326
  { type: DragRootDirective, decorators: [{ type: i0.Optional }] },
1224
1327
  { type: AccountForScaleDirective, decorators: [{ type: i0.Optional }] },
1225
1328
  { type: DraggableDirective, decorators: [{ type: i0.Optional }] },
1226
- { type: DropzoneDirective, decorators: [{ type: i0.Optional }, { type: i0.SkipSelf }] }
1329
+ { type: DropzoneDirective, decorators: [{ type: i0.Optional }, { type: i0.SkipSelf }] },
1330
+ { type: AutoScrollDirective, decorators: [{ type: i0.Optional }, { type: i0.SkipSelf }] }
1227
1331
  ]; };
1228
1332
  ResizableDirective.propDecorators = {
1229
1333
  enableResizeDefault: [{ type: i0.Input }],
@@ -1351,6 +1455,7 @@
1351
1455
  DropzoneDirective,
1352
1456
  GesturableDirective,
1353
1457
  DragRootDirective,
1458
+ AutoScrollDirective,
1354
1459
  AccountForScaleDirective,
1355
1460
  ApplyScaleDirective,
1356
1461
  DragPreviewDirective,
@@ -1387,6 +1492,7 @@
1387
1492
  exports.AccountForScaleDirective = AccountForScaleDirective;
1388
1493
  exports.ApplyScaleDirective = ApplyScaleDirective;
1389
1494
  exports.ArrayOfNPipe = ArrayOfNPipe;
1495
+ exports.AutoScrollDirective = AutoScrollDirective;
1390
1496
  exports.DEFAULT_REGISTRY_ID = DEFAULT_REGISTRY_ID;
1391
1497
  exports.DragPreviewDirective = DragPreviewDirective;
1392
1498
  exports.DragRootDirective = DragRootDirective;
@@ -1408,10 +1514,11 @@
1408
1514
  exports.ɵc = DropzoneDirective;
1409
1515
  exports.ɵd = GesturableDirective;
1410
1516
  exports.ɵe = DragRootDirective;
1411
- exports.ɵf = AccountForScaleDirective;
1412
- exports.ɵg = ApplyScaleDirective;
1413
- exports.ɵh = DragPreviewDirective;
1414
- exports.ɵi = ArrayOfNPipe;
1517
+ exports.ɵf = AutoScrollDirective;
1518
+ exports.ɵg = AccountForScaleDirective;
1519
+ exports.ɵh = ApplyScaleDirective;
1520
+ exports.ɵi = DragPreviewDirective;
1521
+ exports.ɵj = ArrayOfNPipe;
1415
1522
 
1416
1523
  Object.defineProperty(exports, '__esModule', { value: true });
1417
1524