@tft/interact 12.4.2 → 12.5.2

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 (45) hide show
  1. package/bundles/tft-interact.umd.js +133 -109
  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 +21 -12
  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 +5 -4
  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/index.js.map +1 -1
  19. package/esm2015/lib/directives/resizable.directive.js +29 -10
  20. package/esm2015/lib/directives/resizable.directive.js.map +1 -1
  21. package/esm2015/lib/directives/resizable.directive.metadata.json +1 -1
  22. package/esm2015/lib/interact.module.js +13 -0
  23. package/esm2015/lib/interact.module.js.map +1 -1
  24. package/esm2015/lib/interact.module.metadata.json +1 -1
  25. package/esm2015/lib/models/interact.js +2 -0
  26. package/esm2015/lib/models/interact.js.map +1 -1
  27. package/esm2015/lib/models/interact.metadata.json +1 -1
  28. package/esm2015/lib/services/interact.service.js +31 -36
  29. package/esm2015/lib/services/interact.service.js.map +1 -1
  30. package/esm2015/lib/services/interact.service.metadata.json +1 -1
  31. package/fesm2015/tft-interact.js +111 -96
  32. package/fesm2015/tft-interact.js.map +1 -1
  33. package/lib/directives/account-for-scale.directive.d.ts +1 -3
  34. package/lib/directives/apply-scale.directive.d.ts +4 -7
  35. package/lib/directives/drag-root.directive.d.ts +2 -1
  36. package/lib/directives/draggable.directive.d.ts +3 -1
  37. package/lib/directives/dropzone.directive.d.ts +5 -4
  38. package/lib/directives/resizable.directive.d.ts +3 -1
  39. package/lib/interact.module.d.ts +3 -0
  40. package/lib/models/interact.d.ts +10 -0
  41. package/lib/services/interact.service.d.ts +6 -7
  42. package/package.json +1 -1
  43. package/tft-interact-12.5.2.tgz +0 -0
  44. package/tft-interact.metadata.json +1 -1
  45. package/tft-interact-12.4.2.tgz +0 -0
@@ -2,6 +2,8 @@ import { NgModule } from '@angular/core';
2
2
  import { CommonModule } from '@angular/common';
3
3
  import { ArrayOfNPipe } from './pipes/array-of-n.pipe';
4
4
  import { ApplyScaleDirective, DraggableDirective, DragRootDirective, AccountForScaleDirective, GesturableDirective, ResizableDirective, DropzoneDirective, DragPreviewDirective } from './directives';
5
+ import { InteractService } from './services/interact.service';
6
+ import { INTERACT_ROOT_CONFIG } from './models';
5
7
  const EXPORTS = [
6
8
  DraggableDirective,
7
9
  ResizableDirective,
@@ -14,10 +16,21 @@ const EXPORTS = [
14
16
  ArrayOfNPipe,
15
17
  ];
16
18
  export class InteractModule {
19
+ static forRoot(config) {
20
+ const defaultConfig = { cssDimensionUnit: 'px' };
21
+ return {
22
+ ngModule: InteractModule,
23
+ providers: [
24
+ { provide: INTERACT_ROOT_CONFIG, useValue: Object.assign(Object.assign({}, defaultConfig), config) },
25
+ InteractService
26
+ ]
27
+ };
28
+ }
17
29
  }
18
30
  InteractModule.decorators = [
19
31
  { type: NgModule, args: [{
20
32
  imports: [CommonModule],
33
+ // providers: [{ provide: INTERACT_ROOT_CONFIG, useValue: 'px' }],
21
34
  declarations: [
22
35
  ...EXPORTS,
23
36
  ],
@@ -1 +1 @@
1
- {"version":3,"file":"interact.module.js","sourceRoot":"","sources":["../../../../../libs/interact/src/lib/interact.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEtM,MAAM,OAAO,GAAG;IACd,kBAAkB;IAClB,kBAAkB;IAClB,iBAAiB;IACjB,mBAAmB;IACnB,iBAAiB;IACjB,wBAAwB;IACxB,mBAAmB;IACnB,oBAAoB;IACpB,YAAY;CACb,CAAC;AAYF,MAAM,OAAO,cAAc;;;YAT1B,QAAQ,SAAC;gBACR,OAAO,EAAE,CAAC,YAAY,CAAC;gBACvB,YAAY,EAAE;oBACZ,GAAG,OAAO;iBACX;gBACD,OAAO,EAAE;oBACP,GAAG,OAAO;iBACX;aACF","sourcesContent":["import { NgModule } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { ArrayOfNPipe } from './pipes/array-of-n.pipe';\nimport { ApplyScaleDirective, DraggableDirective, DragRootDirective, AccountForScaleDirective, GesturableDirective, ResizableDirective, DropzoneDirective, DragPreviewDirective } from './directives';\n\nconst EXPORTS = [\n DraggableDirective,\n ResizableDirective,\n DropzoneDirective,\n GesturableDirective,\n DragRootDirective,\n AccountForScaleDirective,\n ApplyScaleDirective,\n DragPreviewDirective,\n ArrayOfNPipe,\n];\n\n\n@NgModule({\n imports: [CommonModule],\n declarations: [\n ...EXPORTS,\n ],\n exports: [\n ...EXPORTS\n ]\n})\nexport class InteractModule {}\n"]}
1
+ {"version":3,"file":"interact.module.js","sourceRoot":"","sources":["../../../../../libs/interact/src/lib/interact.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACtM,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAsB,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAIpE,MAAM,OAAO,GAAG;IACd,kBAAkB;IAClB,kBAAkB;IAClB,iBAAiB;IACjB,mBAAmB;IACnB,iBAAiB;IACjB,wBAAwB;IACxB,mBAAmB;IACnB,oBAAoB;IACpB,YAAY;CACb,CAAC;AAaF,MAAM,OAAO,cAAc;IACzB,MAAM,CAAC,OAAO,CAAC,MAA0B;QACvC,MAAM,aAAa,GAAuB,EAAC,gBAAgB,EAAE,IAAI,EAAC,CAAA;QAClE,OAAO;YACL,QAAQ,EAAE,cAAc;YACxB,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,oBAAoB,EAAE,QAAQ,kCAAM,aAAa,GAAK,MAAM,CAAC,EAAE;gBAC1E,eAAe;aAChB;SACF,CAAC;IACJ,CAAC;;;YApBF,QAAQ,SAAC;gBACR,OAAO,EAAE,CAAC,YAAY,CAAC;gBACvB,kEAAkE;gBAClE,YAAY,EAAE;oBACZ,GAAG,OAAO;iBACX;gBACD,OAAO,EAAE;oBACP,GAAG,OAAO;iBACX;aACF","sourcesContent":["import { ModuleWithProviders, NgModule } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { ArrayOfNPipe } from './pipes/array-of-n.pipe';\nimport { ApplyScaleDirective, DraggableDirective, DragRootDirective, AccountForScaleDirective, GesturableDirective, ResizableDirective, DropzoneDirective, DragPreviewDirective } from './directives';\nimport { InteractService } from './services/interact.service';\nimport { InteractRootConfig, INTERACT_ROOT_CONFIG } from './models';\n\n\n\nconst EXPORTS = [\n DraggableDirective,\n ResizableDirective,\n DropzoneDirective,\n GesturableDirective,\n DragRootDirective,\n AccountForScaleDirective,\n ApplyScaleDirective,\n DragPreviewDirective,\n ArrayOfNPipe,\n];\n\n\n@NgModule({\n imports: [CommonModule],\n // providers: [{ provide: INTERACT_ROOT_CONFIG, useValue: 'px' }],\n declarations: [\n ...EXPORTS,\n ],\n exports: [\n ...EXPORTS\n ]\n})\nexport class InteractModule {\n static forRoot(config: InteractRootConfig): ModuleWithProviders<InteractModule> {\n const defaultConfig: InteractRootConfig = {cssDimensionUnit: 'px'}\n return {\n ngModule: InteractModule,\n providers: [\n { provide: INTERACT_ROOT_CONFIG, useValue: {...defaultConfig, ...config} },\n InteractService\n ]\n };\n }\n}\n"]}
@@ -1 +1 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"InteractModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":18,"character":1},"arguments":[{"imports":[{"__symbolic":"reference","module":"@angular/common","name":"CommonModule","line":19,"character":12}],"declarations":[{"__symbolic":"reference","module":"./directives","name":"DraggableDirective","line":6,"character":2},{"__symbolic":"reference","module":"./directives","name":"ResizableDirective","line":7,"character":2},{"__symbolic":"reference","module":"./directives","name":"DropzoneDirective","line":8,"character":2},{"__symbolic":"reference","module":"./directives","name":"GesturableDirective","line":9,"character":2},{"__symbolic":"reference","module":"./directives","name":"DragRootDirective","line":10,"character":2},{"__symbolic":"reference","module":"./directives","name":"AccountForScaleDirective","line":11,"character":2},{"__symbolic":"reference","module":"./directives","name":"ApplyScaleDirective","line":12,"character":2},{"__symbolic":"reference","module":"./directives","name":"DragPreviewDirective","line":13,"character":2},{"__symbolic":"reference","module":"./pipes/array-of-n.pipe","name":"ArrayOfNPipe","line":14,"character":2}],"exports":[{"__symbolic":"reference","module":"./directives","name":"DraggableDirective","line":6,"character":2},{"__symbolic":"reference","module":"./directives","name":"ResizableDirective","line":7,"character":2},{"__symbolic":"reference","module":"./directives","name":"DropzoneDirective","line":8,"character":2},{"__symbolic":"reference","module":"./directives","name":"GesturableDirective","line":9,"character":2},{"__symbolic":"reference","module":"./directives","name":"DragRootDirective","line":10,"character":2},{"__symbolic":"reference","module":"./directives","name":"AccountForScaleDirective","line":11,"character":2},{"__symbolic":"reference","module":"./directives","name":"ApplyScaleDirective","line":12,"character":2},{"__symbolic":"reference","module":"./directives","name":"DragPreviewDirective","line":13,"character":2},{"__symbolic":"reference","module":"./pipes/array-of-n.pipe","name":"ArrayOfNPipe","line":14,"character":2}]}]}]}}}]
1
+ [{"__symbolic":"module","version":4,"metadata":{"InteractModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":22,"character":1},"arguments":[{"imports":[{"__symbolic":"reference","module":"@angular/common","name":"CommonModule","line":23,"character":12}],"declarations":[{"__symbolic":"reference","module":"./directives","name":"DraggableDirective","line":10,"character":2},{"__symbolic":"reference","module":"./directives","name":"ResizableDirective","line":11,"character":2},{"__symbolic":"reference","module":"./directives","name":"DropzoneDirective","line":12,"character":2},{"__symbolic":"reference","module":"./directives","name":"GesturableDirective","line":13,"character":2},{"__symbolic":"reference","module":"./directives","name":"DragRootDirective","line":14,"character":2},{"__symbolic":"reference","module":"./directives","name":"AccountForScaleDirective","line":15,"character":2},{"__symbolic":"reference","module":"./directives","name":"ApplyScaleDirective","line":16,"character":2},{"__symbolic":"reference","module":"./directives","name":"DragPreviewDirective","line":17,"character":2},{"__symbolic":"reference","module":"./pipes/array-of-n.pipe","name":"ArrayOfNPipe","line":18,"character":2}],"exports":[{"__symbolic":"reference","module":"./directives","name":"DraggableDirective","line":10,"character":2},{"__symbolic":"reference","module":"./directives","name":"ResizableDirective","line":11,"character":2},{"__symbolic":"reference","module":"./directives","name":"DropzoneDirective","line":12,"character":2},{"__symbolic":"reference","module":"./directives","name":"GesturableDirective","line":13,"character":2},{"__symbolic":"reference","module":"./directives","name":"DragRootDirective","line":14,"character":2},{"__symbolic":"reference","module":"./directives","name":"AccountForScaleDirective","line":15,"character":2},{"__symbolic":"reference","module":"./directives","name":"ApplyScaleDirective","line":16,"character":2},{"__symbolic":"reference","module":"./directives","name":"DragPreviewDirective","line":17,"character":2},{"__symbolic":"reference","module":"./pipes/array-of-n.pipe","name":"ArrayOfNPipe","line":18,"character":2}]}]}]}}}]
@@ -1,3 +1,5 @@
1
+ import { InjectionToken } from '@angular/core';
2
+ export const INTERACT_ROOT_CONFIG = new InjectionToken('INTERACT_ROOT_CONFIG_PARAMS');
1
3
  export const DEFAULT_REGISTRY_ID = 'DEFAULT';
2
4
  /**
3
5
  * Default initial value for Delta BehaviorSubject
@@ -1 +1 @@
1
- {"version":3,"file":"interact.js","sourceRoot":"","sources":["../../../../../../libs/interact/src/lib/models/interact.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAC7C;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAU;IACjC,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,aAAa,EAAE,IAAI;CACpB,CAAC;AACF;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAS;IAC/B,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;IACZ,aAAa,EAAE,IAAI;CACpB,CAAA;AACD;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAa;IACvC,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,aAAa,EAAE,IAAI;CACpB,CAAA","sourcesContent":["import { DropzoneDirective, DraggableDirective, GesturableDirective, ResizableDirective } from '../directives';\nimport { Point, DragEvent, ResizeEvent, Interactable, DropEvent, GestureEvent } from '@interactjs/types';\nimport { BehaviorSubject, Observable } from 'rxjs';\n\nexport const DEFAULT_REGISTRY_ID = 'DEFAULT';\n/**\n * Default initial value for Delta BehaviorSubject\n */\nexport const defaultDelta: Delta = {\n deltaX: 0,\n deltaY: 0,\n targetElement: null\n};\n/**\n * Default initial value for Size BehaviorSubject\n */\nexport const defaultSize: Size = {\n width: null,\n height: null,\n targetElement: null\n}\n/**\n * Default initial value for Position BehaviorSubject\n */\nexport const defaultPosition: Position = {\n x: 0,\n y: 0,\n targetElement: null\n}\n/**\n * The shape of the state/events/behavior system for each dropzone\n * and the DEFAULT_REGISTRY_ID system (for drop components initialized outside\n * of a dropzone).\n */\nexport interface InteractableSystem {\n deltas$: BehaviorSubject<Delta>;\n position$: BehaviorSubject<Position>;\n size$: BehaviorSubject<Size & Delta>;\n\n interactable$: Observable<TftCoords>;\n}\n/**\n * The key map of InteractableSystems. One for the drag components\n * that originated outside of a dropzone, plus one for each dropzone.\n */\nexport interface InteractableRegistry {\n [key: string]: InteractableSystem\n}\n\n/**\n * HTMLElement with helpful drag directives attached to facilitate moving drag data between dropzones\n */\nexport type TftDragElement = HTMLElement & {\n dragRef?: DraggableDirective\n dragOrigin?: DropzoneDirective\n dropTarget?: DropzoneDirective\n}\n\n/**\n * HTMLElement with helpful drag directives attached to facilitate moving drag data between dropzones\n */\n export type TftResizeElement = HTMLElement & {\n resizeRef?: ResizableDirective\n}\n\n/**\n * Extends the interact drop events by adding reference to the dropped components drag\n * directive to the html element. This gives the dropzone access to things like data\n * and parent dropzone of the dropped component.\n */\nexport type NgDropEvent = DropEvent & {\n draggable: Interactable & {\n target: TftDragElement;\n };\n relatedTarget: TftDragElement;\n};\n/**\n * Extends the interact resize events by adding a reference to the dragRef\n * directive to the html element.\n */\nexport type NgResizeEvent = ResizeEvent & {\n draggable: Interactable & {\n target: TftDragElement;\n };\n};\n/**\n * We extend the interact DragEvent a little here, adding to the target element references for:\n * - the component we are dragging (dragRef)\n * - the dropzone component where the drag component originated (dragOrigin)\n * - the dropzone component that it was dropped in (dropTarget)\n * This helps us to pass references to directive classes as events like dragenter and drag exit happens.\n * We use these references to emit a (mostly) consistent event across drag, drop, resize event.\n */\nexport type NgDragEvent = DragEvent & {\n dropzone: { target: HTMLElement},\n target: TftDragElement\n};\n/**\n * Event emitted when resizing, dragging, dropping\n */\nexport interface TftInteractableEvent {\n dragRef: DraggableDirective;\n dragOrigin?: DropzoneDirective;\n dropTarget?: DropzoneDirective;\n positionInDropTarget: Point;\n}\n/**\n * Event emitted on drop\n */\nexport interface TftDropEvent extends TftInteractableEvent {\n interactEvent: NgDropEvent\n}\n/**\n * Event emitted on drag\n */\nexport interface TftDragEvent extends TftInteractableEvent {\n interactEvent: NgDragEvent\n}\n/**\n * Event emitted on resize\n */\nexport interface TftResizeEvent extends TftInteractableEvent {\n interactEvent: ResizeEvent,\n resizeRef: ResizableDirective\n}\n\nexport type TftCoords= Delta & Position & Size;\n\nexport interface Delta {\n deltaX: number | null;\n deltaY: number | null;\n targetElement: TftDragElement | null;\n}\n\nexport interface Position {\n x: number | null;\n y: number | null;\n targetElement: TftDragElement | null;\n}\n\nexport interface Size {\n width: number | null;\n height: number | null;\n targetElement: TftResizeElement | null;\n}\n\nexport interface TftGestureEvent {\n gestureRef: GesturableDirective;\n interactEvent: GestureEvent;\n}\n"]}
1
+ {"version":3,"file":"interact.js","sourceRoot":"","sources":["../../../../../../libs/interact/src/lib/models/interact.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAQ/C,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,cAAc,CAAqB,6BAA6B,CAAC,CAAC;AAE1G,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAC7C;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAU;IACjC,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,aAAa,EAAE,IAAI;CACpB,CAAC;AACF;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAS;IAC/B,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;IACZ,aAAa,EAAE,IAAI;CACpB,CAAA;AACD;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAa;IACvC,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,aAAa,EAAE,IAAI;CACpB,CAAA","sourcesContent":["import { DropzoneDirective, DraggableDirective, GesturableDirective, ResizableDirective } from '../directives';\nimport { Point, DragEvent, ResizeEvent, Interactable, DropEvent, GestureEvent } from '@interactjs/types';\nimport { BehaviorSubject, Observable } from 'rxjs';\nimport { InjectionToken } from '@angular/core';\n\n\n\nexport type CssDimensionUnit = 'px' | 'em';\nexport interface InteractRootConfig {\n cssDimensionUnit: CssDimensionUnit;\n}\nexport const INTERACT_ROOT_CONFIG = new InjectionToken<InteractRootConfig>('INTERACT_ROOT_CONFIG_PARAMS');\n\nexport const DEFAULT_REGISTRY_ID = 'DEFAULT';\n/**\n * Default initial value for Delta BehaviorSubject\n */\nexport const defaultDelta: Delta = {\n deltaX: 0,\n deltaY: 0,\n targetElement: null\n};\n/**\n * Default initial value for Size BehaviorSubject\n */\nexport const defaultSize: Size = {\n width: null,\n height: null,\n targetElement: null\n}\n/**\n * Default initial value for Position BehaviorSubject\n */\nexport const defaultPosition: Position = {\n x: 0,\n y: 0,\n targetElement: null\n}\n/**\n * The shape of the state/events/behavior system for each dropzone\n * and the DEFAULT_REGISTRY_ID system (for drop components initialized outside\n * of a dropzone).\n */\nexport interface InteractableSystem {\n deltas$: BehaviorSubject<Delta>;\n position$: BehaviorSubject<Position>;\n size$: BehaviorSubject<Size & Delta>;\n\n interactable$: Observable<TftCoords>;\n}\n/**\n * The key map of InteractableSystems. One for the drag components\n * that originated outside of a dropzone, plus one for each dropzone.\n */\nexport interface InteractableRegistry {\n [key: string]: InteractableSystem\n}\n\n/**\n * HTMLElement with helpful drag directives attached to facilitate moving drag data between dropzones\n */\nexport type TftDragElement = HTMLElement & {\n dragRef?: DraggableDirective\n dragOrigin?: DropzoneDirective\n dropTarget?: DropzoneDirective\n}\n\n/**\n * HTMLElement with helpful drag directives attached to facilitate moving drag data between dropzones\n */\n export type TftResizeElement = HTMLElement & {\n resizeRef?: ResizableDirective\n}\n\n/**\n * Extends the interact drop events by adding reference to the dropped components drag\n * directive to the html element. This gives the dropzone access to things like data\n * and parent dropzone of the dropped component.\n */\nexport type NgDropEvent = DropEvent & {\n draggable: Interactable & {\n target: TftDragElement;\n };\n relatedTarget: TftDragElement;\n};\n/**\n * Extends the interact resize events by adding a reference to the dragRef\n * directive to the html element.\n */\nexport type NgResizeEvent = ResizeEvent & {\n draggable: Interactable & {\n target: TftDragElement;\n };\n};\n/**\n * We extend the interact DragEvent a little here, adding to the target element references for:\n * - the component we are dragging (dragRef)\n * - the dropzone component where the drag component originated (dragOrigin)\n * - the dropzone component that it was dropped in (dropTarget)\n * This helps us to pass references to directive classes as events like dragenter and drag exit happens.\n * We use these references to emit a (mostly) consistent event across drag, drop, resize event.\n */\nexport type NgDragEvent = DragEvent & {\n dropzone: { target: HTMLElement},\n target: TftDragElement\n};\n/**\n * Event emitted when resizing, dragging, dropping\n */\nexport interface TftInteractableEvent {\n dragRef: DraggableDirective;\n dragOrigin?: DropzoneDirective;\n dropTarget?: DropzoneDirective;\n positionInDropTarget: Point;\n}\n/**\n * Event emitted on drop\n */\nexport interface TftDropEvent extends TftInteractableEvent {\n interactEvent: NgDropEvent\n}\n/**\n * Event emitted on drag\n */\nexport interface TftDragEvent extends TftInteractableEvent {\n interactEvent: NgDragEvent\n}\n/**\n * Event emitted on resize\n */\nexport interface TftResizeEvent extends TftInteractableEvent {\n interactEvent: ResizeEvent,\n resizeRef: ResizableDirective\n size: {\n width: number;\n height: number;\n }\n}\n\nexport type TftCoords= Delta & Position & Size;\n\nexport interface Delta {\n deltaX: number | null;\n deltaY: number | null;\n targetElement: TftDragElement | null;\n}\n\nexport interface Position {\n x: number | null;\n y: number | null;\n targetElement: TftDragElement | null;\n}\n\nexport interface Size {\n width: number | null;\n height: number | null;\n targetElement: TftResizeElement | null;\n}\n\nexport interface TftGestureEvent {\n gestureRef: GesturableDirective;\n interactEvent: GestureEvent;\n}\n"]}
@@ -1 +1 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"DEFAULT_REGISTRY_ID":"DEFAULT","defaultDelta":{"deltaX":0,"deltaY":0,"targetElement":null},"defaultSize":{"width":null,"height":null,"targetElement":null},"defaultPosition":{"x":0,"y":0,"targetElement":null},"InteractableSystem":{"__symbolic":"interface"},"InteractableRegistry":{"__symbolic":"interface"},"TftDragElement":{"__symbolic":"interface"},"TftResizeElement":{"__symbolic":"interface"},"NgDropEvent":{"__symbolic":"interface"},"NgResizeEvent":{"__symbolic":"interface"},"NgDragEvent":{"__symbolic":"interface"},"TftInteractableEvent":{"__symbolic":"interface"},"TftDropEvent":{"__symbolic":"interface"},"TftDragEvent":{"__symbolic":"interface"},"TftResizeEvent":{"__symbolic":"interface"},"TftCoords":{"__symbolic":"interface"},"Delta":{"__symbolic":"interface"},"Position":{"__symbolic":"interface"},"Size":{"__symbolic":"interface"},"TftGestureEvent":{"__symbolic":"interface"}}}]
1
+ [{"__symbolic":"module","version":4,"metadata":{"CssDimensionUnit":{"__symbolic":"interface"},"InteractRootConfig":{"__symbolic":"interface"},"INTERACT_ROOT_CONFIG":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":11,"character":40},"arguments":["INTERACT_ROOT_CONFIG_PARAMS"]},"DEFAULT_REGISTRY_ID":"DEFAULT","defaultDelta":{"deltaX":0,"deltaY":0,"targetElement":null},"defaultSize":{"width":null,"height":null,"targetElement":null},"defaultPosition":{"x":0,"y":0,"targetElement":null},"InteractableSystem":{"__symbolic":"interface"},"InteractableRegistry":{"__symbolic":"interface"},"TftDragElement":{"__symbolic":"interface"},"TftResizeElement":{"__symbolic":"interface"},"NgDropEvent":{"__symbolic":"interface"},"NgResizeEvent":{"__symbolic":"interface"},"NgDragEvent":{"__symbolic":"interface"},"TftInteractableEvent":{"__symbolic":"interface"},"TftDropEvent":{"__symbolic":"interface"},"TftDragEvent":{"__symbolic":"interface"},"TftResizeEvent":{"__symbolic":"interface"},"TftCoords":{"__symbolic":"interface"},"Delta":{"__symbolic":"interface"},"Position":{"__symbolic":"interface"},"Size":{"__symbolic":"interface"},"TftGestureEvent":{"__symbolic":"interface"}}}]
@@ -1,17 +1,21 @@
1
- import { Injectable, RendererFactory2, NgZone } from '@angular/core';
1
+ import { Injectable, RendererFactory2, NgZone, Inject, Optional } from '@angular/core';
2
2
  import { BehaviorSubject, combineLatest } from 'rxjs';
3
3
  import { tap, map, shareReplay } from 'rxjs/operators';
4
- import { defaultPosition, defaultSize, defaultDelta, DEFAULT_REGISTRY_ID } from '../models';
4
+ import { defaultPosition, defaultSize, defaultDelta, DEFAULT_REGISTRY_ID, INTERACT_ROOT_CONFIG } from '../models';
5
5
  import * as i0 from "@angular/core";
6
+ import * as i1 from "../models/interact";
6
7
  export class InteractService {
7
- constructor(rendererFactory, ngZone) {
8
+ constructor(rendererFactory, ngZone, rootConfig) {
8
9
  this.rendererFactory = rendererFactory;
9
10
  this.ngZone = ngZone;
11
+ this.rootConfig = rootConfig;
10
12
  this._interactableIndex = 0;
11
13
  this._dropzoneIndex = 0;
12
14
  // TODO: consider using Map here
13
15
  this.dragRegistrySystem = {};
16
+ this.cssUnit = 'px';
14
17
  this.renderer = this.rendererFactory.createRenderer(null, null);
18
+ this.cssUnit = (rootConfig === null || rootConfig === void 0 ? void 0 : rootConfig.cssDimensionUnit) || 'px';
15
19
  }
16
20
  addDeltaToPosition(delta, position) {
17
21
  return {
@@ -28,7 +32,7 @@ export class InteractService {
28
32
  addDraggableToRegistry(customRegistryId = null, interactableId = null) {
29
33
  const registryId = customRegistryId || DEFAULT_REGISTRY_ID;
30
34
  // if we pass an id to createInteractableId then it is used when creating the interactable
31
- // and returned, otherwise a an id is created for the draggable.
35
+ // and returned, otherwise a new id is created for the draggable.
32
36
  const key = this.createInteractableId(interactableId);
33
37
  if (!Object.prototype.hasOwnProperty.call(this.dragRegistrySystem, registryId)) {
34
38
  this.dragRegistrySystem[registryId] = {};
@@ -37,7 +41,16 @@ export class InteractService {
37
41
  return key;
38
42
  }
39
43
  destroyInteractable(interactableId, registryId = DEFAULT_REGISTRY_ID) {
40
- if (this.dragRegistrySystem[registryId][interactableId]) {
44
+ const interactableSystem = this.dragRegistrySystem[registryId][interactableId];
45
+ if (interactableSystem) {
46
+ // unsubscribe from all the subscriptions if they're subscriptions
47
+ for (const propName in interactableSystem) {
48
+ const prop = interactableSystem[propName];
49
+ if (prop.unsubscribe && typeof prop.unsubscribe === 'function') {
50
+ prop.unsubscribe();
51
+ }
52
+ ;
53
+ }
41
54
  delete this.dragRegistrySystem[registryId][interactableId];
42
55
  }
43
56
  }
@@ -119,8 +132,8 @@ export class InteractService {
119
132
  this.dragRegistrySystem[registryId][interactId].size$.next({ deltaX, deltaY, width, height, targetElement });
120
133
  }
121
134
  interactableExistOnRegistry(interactId, registryId = DEFAULT_REGISTRY_ID) {
122
- return this.dragRegistrySystem.hasOwnProperty(registryId)
123
- && this.dragRegistrySystem[registryId].hasOwnProperty(interactId);
135
+ // eslint-disable-next-line no-prototype-builtins
136
+ return this.dragRegistrySystem.hasOwnProperty(registryId) && this.dragRegistrySystem[registryId].hasOwnProperty(interactId);
124
137
  }
125
138
  /**
126
139
  * Uses renderer to set width and height of angular component
@@ -129,21 +142,10 @@ export class InteractService {
129
142
  * @param target the element to transform
130
143
  */
131
144
  setElementSize(width, height, target) {
132
- var _a;
133
145
  if (!target)
134
146
  return;
135
- const accountForScaleDirective = (_a = target.resizeRef) === null || _a === void 0 ? void 0 : _a.account_for_scale_dir;
136
- if (accountForScaleDirective) {
137
- const { scaleX, scaleY } = accountForScaleDirective;
138
- const scaledWidth = width / scaleX;
139
- const scaledHeight = height / scaleY;
140
- this.renderer.setStyle(target, 'width', `${scaledWidth}px`);
141
- this.renderer.setStyle(target, 'height', `${scaledHeight}px`);
142
- }
143
- else {
144
- this.renderer.setStyle(target, 'width', `${width}px`);
145
- this.renderer.setStyle(target, 'height', `${height}px`);
146
- }
147
+ this.renderer.setStyle(target, 'width', `${width}${this.cssUnit}`);
148
+ this.renderer.setStyle(target, 'height', `${height}${this.cssUnit}`);
147
149
  }
148
150
  /**
149
151
  * Uses renderer to set position of angular component
@@ -152,19 +154,10 @@ export class InteractService {
152
154
  * @param target the element to transform
153
155
  */
154
156
  setElementTransform(x, y, position) {
155
- var _a, _b;
156
157
  if (!(position === null || position === void 0 ? void 0 : position.targetElement))
157
158
  return;
158
- 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;
159
- if (accountForScaleDirective) {
160
- const { scaleX, scaleY } = accountForScaleDirective;
161
- this.renderer.setStyle(position.targetElement, 'left', `${x / scaleX}px`);
162
- this.renderer.setStyle(position.targetElement, 'top', `${y / scaleY}px`);
163
- }
164
- else {
165
- this.renderer.setStyle(position.targetElement, 'left', `${x}px`);
166
- this.renderer.setStyle(position.targetElement, 'top', `${y}px`);
167
- }
159
+ this.renderer.setStyle(position.targetElement, 'left', `${x}${this.cssUnit}`);
160
+ this.renderer.setStyle(position.targetElement, 'top', `${y}${this.cssUnit}`);
168
161
  }
169
162
  /**
170
163
  * Generates a translate string for the x and y arguments passed to
@@ -173,7 +166,7 @@ export class InteractService {
173
166
  * @param y the position along the y axis
174
167
  */
175
168
  createTransformString(x, y) {
176
- return `translate3d(${x}px, ${y}px, 0)`;
169
+ return `translate3d(${x}${this.cssUnit}, ${y}${this.cssUnit}, 0)`;
177
170
  }
178
171
  calculatePositionInElement(zoneElement, dragElement, scale) {
179
172
  // TODO: this calculation may not cover a lot of scenarios, keep an eye out for possible improvements
@@ -181,21 +174,23 @@ export class InteractService {
181
174
  const dragRect = dragElement.getBoundingClientRect();
182
175
  const position = scale
183
176
  ? {
184
- x: (dragRect.left - zoneRect.left) / scale.x || 1,
185
- y: (dragRect.top - zoneRect.top) / scale.y || 1
177
+ x: (dragRect.left - zoneRect.left) / scale || 1,
178
+ y: (dragRect.top - zoneRect.top) / scale || 1
186
179
  } : {
187
180
  x: dragRect.left - zoneRect.left,
188
181
  y: dragRect.top - zoneRect.top
189
182
  };
183
+ // console.log({ y:position.y, drt:dragRect.top, zrt: zoneRect.top})
190
184
  return position;
191
185
  }
192
186
  }
193
- InteractService.ɵprov = i0.ɵɵdefineInjectable({ factory: function InteractService_Factory() { return new InteractService(i0.ɵɵinject(i0.RendererFactory2), i0.ɵɵinject(i0.NgZone)); }, token: InteractService, providedIn: "root" });
187
+ InteractService.ɵprov = i0.ɵɵdefineInjectable({ factory: function InteractService_Factory() { return new InteractService(i0.ɵɵinject(i0.RendererFactory2), i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i1.INTERACT_ROOT_CONFIG, 8)); }, token: InteractService, providedIn: "root" });
194
188
  InteractService.decorators = [
195
189
  { type: Injectable, args: [{ providedIn: 'root' },] }
196
190
  ];
197
191
  InteractService.ctorParameters = () => [
198
192
  { type: RendererFactory2 },
199
- { type: NgZone }
193
+ { type: NgZone },
194
+ { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [INTERACT_ROOT_CONFIG,] }] }
200
195
  ];
201
196
  //# sourceMappingURL=interact.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interact.service.js","sourceRoot":"","sources":["../../../../../../libs/interact/src/lib/services/interact.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAa,gBAAgB,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,eAAe,EAAc,aAAa,EAAE,MAAM,MAAM,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAEL,eAAe,EAAE,WAAW,EAAE,YAAY,EAAE,mBAAmB,EAChE,MAAM,WAAW,CAAC;;AAGnB,MAAM,OA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,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,IAAK,CAAC;gBAClD,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC;aAC9C,CAAC,CAAC,CAAC;YACF,CAAC,EAAE,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI;YAChC,CAAC,EAAE,QAAQ,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG;SACjC,CAAC;QACF,OAAO,QAAQ,CAAC;IAClB,CAAC;;;;YAjNF,UAAU,SAAC,EAAC,UAAU,EAAE,MAAM,EAAC;;;YARA,gBAAgB;YAAE,MAAM","sourcesContent":["\nimport { Injectable, Renderer2, RendererFactory2, NgZone } from '@angular/core';\nimport { BehaviorSubject, Observable, combineLatest } from 'rxjs';\nimport { tap, map, shareReplay } from 'rxjs/operators';\nimport {\n TftCoords, Delta, Size, Position, InteractableRegistry,\n defaultPosition, defaultSize, defaultDelta, DEFAULT_REGISTRY_ID, TftDragElement, TftResizeElement\n} from '../models';\n\n@Injectable({providedIn: 'root'})\nexport class InteractService {\n\n private _interactableIndex = 0;\n private _dropzoneIndex = 0;\n private renderer: Renderer2;\n\n // TODO: consider using Map here\n readonly dragRegistrySystem: { [key: string]: InteractableRegistry } = { };\n\n constructor(\n private rendererFactory: RendererFactory2,\n private ngZone: NgZone\n ) {\n this.renderer = this.rendererFactory.createRenderer(null, null);\n }\n\n addDeltaToPosition(delta: Delta, position: Position) {\n return {\n x: delta.deltaX + position.x,\n y: delta.deltaY + position.y,\n targetElement: position.targetElement || delta.targetElement\n }\n }\n\n addRegistryToSystem(customRegistryId: string | null = null) {\n const registryId = customRegistryId || this.createDropzoneId(this._dropzoneIndex++);\n this.dragRegistrySystem[registryId] = {};\n return registryId;\n }\n\n addDraggableToRegistry(customRegistryId = null, interactableId: string | null = null ) {\n const registryId = customRegistryId || DEFAULT_REGISTRY_ID;\n // if we pass an id to createInteractableId then it is used when creating the interactable\n // and returned, otherwise a an id is created for the draggable.\n const key = this.createInteractableId(interactableId );\n if (!Object.prototype.hasOwnProperty.call(this.dragRegistrySystem, registryId)) {\n this.dragRegistrySystem[registryId] = {};\n }\n this.dragRegistrySystem[registryId][key] = this.createInteractableState(defaultPosition, defaultSize, defaultDelta);\n return key\n }\n\n destroyInteractable(interactableId: string, registryId = DEFAULT_REGISTRY_ID) {\n if(this.dragRegistrySystem[registryId][interactableId]) {\n delete this.dragRegistrySystem[registryId][interactableId];\n }\n }\n\n subscribeToInteractable(interactableId: string, registryId = DEFAULT_REGISTRY_ID) {\n return this.dragRegistrySystem[registryId][interactableId];\n }\n\n createInteractableState(initialPosition: Position, initialSize: Size, initialDelta: Delta ) {\n\n const deltas$ = new BehaviorSubject(initialDelta);\n // tracks the size of the element\n const size$ = new BehaviorSubject({...initialSize, ...initialDelta});\n // Stream of positions as they change\n const position$ = new BehaviorSubject(initialPosition);\n\n // All draggable data mapped together\n const interactable$: Observable<TftCoords> = combineLatest([\n size$.pipe(\n // startWith({...initialSize, ...initialDelta}),\n shareReplay(1),\n // filter(resizeEvent => !!resizeEvent.targetElement),\n tap(({deltaX, deltaY, width, height, targetElement}) => {\n this.ngZone.runOutsideAngular(() => {\n this.setElementSize(width, height, targetElement);\n });\n // only reposition if necessary i.e when resizing left or up\n if(deltaX || deltaY) {\n deltas$.next({deltaX, deltaY, targetElement});\n }\n })\n ),\n deltas$.pipe(\n shareReplay(1),\n tap((delta) => {\n const position = position$.value;\n const newPosition = this.addDeltaToPosition(delta, position);\n position$.next(newPosition);\n })\n ),\n position$.pipe(\n shareReplay(1),\n tap( position => {\n this.ngZone.runOutsideAngular(() => {\n this.setElementTransform(position.x, position.y, position);\n })\n })\n )\n ]).pipe(\n shareReplay(1),\n map( ([size, deltas, position]): TftCoords=> {\n return {\n x: position.x,\n y: position.y,\n deltaX: deltas.deltaX,\n deltaY: deltas.deltaY,\n width: size.width,\n height: size.height,\n targetElement: size.targetElement || position.targetElement || deltas.targetElement\n }\n }),\n )\n // TODO: update system to handle only returning interactable$\n return {\n deltas$,\n position$,\n size$,\n interactable$\n }\n }\n\n createInteractableId(customInteractableId: string | null = null) {\n return customInteractableId || `interactable${this._interactableIndex++}`\n }\n\n createDropzoneId(index: number) {\n return `dropzone${index}`\n }\n\n getInteractableState( interactableId: string, registryId = DEFAULT_REGISTRY_ID) {\n return this.dragRegistrySystem[registryId][interactableId].interactable$;\n }\n\n updateDeltas(interactId: string, registryId: string, { deltaX, deltaY }, targetElement) {\n if (!this.interactableExistOnRegistry(interactId, registryId)) return;\n this.dragRegistrySystem[registryId][interactId].deltas$.next({ deltaX, deltaY, targetElement })\n }\n\n updatePosition(interactId: string, registryId: string, { x, y }, targetElement) {\n if (!this.interactableExistOnRegistry(interactId, registryId)) return;\n this.dragRegistrySystem[registryId][interactId].position$.next({ x, y, targetElement })\n }\n\n updateSize(interactId: string, registryId: string, { deltaX, deltaY, width, height }, targetElement) {\n if (!this.interactableExistOnRegistry(interactId, registryId)) return\n this.dragRegistrySystem[registryId][interactId].size$.next({deltaX, deltaY, width, height, targetElement});\n }\n\n interactableExistOnRegistry(interactId: string, registryId = DEFAULT_REGISTRY_ID) {\n return this.dragRegistrySystem.hasOwnProperty(registryId)\n && this.dragRegistrySystem[registryId].hasOwnProperty(interactId);\n }\n /**\n * Uses renderer to set width and height of angular component\n * @param width the desired width of component\n * @param height the desired height of component\n * @param target the element to transform\n */\n setElementSize(width: number, height: number, target: TftResizeElement) {\n if(!target) return;\n\n const accountForScaleDirective = target.resizeRef?.account_for_scale_dir\n if (accountForScaleDirective) {\n const { scaleX, scaleY } = accountForScaleDirective\n const scaledWidth = width / scaleX;\n const scaledHeight = height / scaleY;\n this.renderer.setStyle(target, 'width', `${scaledWidth}px`);\n this.renderer.setStyle(target, 'height', `${scaledHeight}px`);\n } else {\n this.renderer.setStyle(target, 'width', `${width}px`);\n this.renderer.setStyle(target, 'height', `${height}px`);\n }\n }\n /**\n * Uses renderer to set position of angular component\n * @param x position on x axis\n * @param y position on y axis\n * @param target the element to transform\n */\n setElementTransform(x: number, y: number, position: Position ) {\n if(!position?.targetElement) return;\n const accountForScaleDirective = position.targetElement?.dragRef?.account_for_scale_dir\n if (accountForScaleDirective) {\n const {scaleX, scaleY} = accountForScaleDirective;\n this.renderer.setStyle(position.targetElement, 'left', `${x / scaleX}px`);\n this.renderer.setStyle(position.targetElement, 'top', `${y / scaleY}px`);\n } else {\n this.renderer.setStyle(position.targetElement, 'left', `${x}px`);\n this.renderer.setStyle(position.targetElement, 'top', `${y}px`);\n }\n }\n /**\n * Generates a translate string for the x and y arguments passed to\n * be passed to css transform\n * @param x the position along the x axis\n * @param y the position along the y axis\n */\n createTransformString(x: number, y: number) {\n return `translate3d(${x}px, ${y}px, 0)`\n }\n\n calculatePositionInElement(zoneElement: Interact.Element, dragElement: TftDragElement, scale?: {x: number, y: number}) {\n // TODO: this calculation may not cover a lot of scenarios, keep an eye out for possible improvements\n const zoneRect = zoneElement.getBoundingClientRect();\n const dragRect = dragElement.getBoundingClientRect();\n const position = scale\n ? {\n x: (dragRect.left - zoneRect.left) / scale.x || 1,\n y: (dragRect.top - zoneRect.top) / scale.y || 1\n } : {\n x: dragRect.left - zoneRect.left,\n y: dragRect.top - zoneRect.top\n };\n return position;\n }\n}\n"]}
1
+ {"version":3,"file":"interact.service.js","sourceRoot":"","sources":["../../../../../../libs/interact/src/lib/services/interact.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAa,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAClG,OAAO,EAAE,eAAe,EAAc,aAAa,EAAE,MAAM,MAAM,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAEL,eAAe,EAAE,WAAW,EAAE,YAAY,EAAE,mBAAmB,EAAoC,oBAAoB,EACxH,MAA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AC,GAAG,GAAG,QAAQ,CAAC,GAAG;SACjC,CAAC;QACF,oEAAoE;QACpE,OAAO,QAAQ,CAAC;IAClB,CAAC;;;;YA3MF,UAAU,SAAC,EAAC,UAAU,EAAE,MAAM,EAAC;;;YAVA,gBAAgB;YAAE,MAAM;4CAuBnD,QAAQ,YAAI,MAAM,SAAC,oBAAoB","sourcesContent":["\nimport { Injectable, Renderer2, RendererFactory2, NgZone, Inject, Optional } from '@angular/core';\nimport { BehaviorSubject, Observable, combineLatest } from 'rxjs';\nimport { tap, map, shareReplay } from 'rxjs/operators';\nimport {\n TftCoords, Delta, Size, Position, InteractableRegistry,\n defaultPosition, defaultSize, defaultDelta, DEFAULT_REGISTRY_ID, TftDragElement, TftResizeElement, INTERACT_ROOT_CONFIG, InteractRootConfig\n} from '../models';\n\n\n\n@Injectable({providedIn: 'root'})\nexport class InteractService {\n\n private _interactableIndex = 0;\n private _dropzoneIndex = 0;\n private renderer: Renderer2;\n\n // TODO: consider using Map here\n readonly dragRegistrySystem: { [key: string]: InteractableRegistry } = { };\n private cssUnit = 'px'\n constructor(\n private rendererFactory: RendererFactory2,\n private ngZone: NgZone,\n @Optional() @Inject(INTERACT_ROOT_CONFIG) public rootConfig\n ) {\n this.renderer = this.rendererFactory.createRenderer(null, null);\n this.cssUnit = rootConfig?.cssDimensionUnit || 'px';\n }\n\n addDeltaToPosition(delta: Delta, position: Position) {\n return {\n x: delta.deltaX + position.x,\n y: delta.deltaY + position.y,\n targetElement: position.targetElement || delta.targetElement\n }\n }\n\n addRegistryToSystem(customRegistryId: string | null = null) {\n const registryId = customRegistryId || this.createDropzoneId(this._dropzoneIndex++);\n this.dragRegistrySystem[registryId] = {};\n return registryId;\n }\n\n addDraggableToRegistry(customRegistryId = null, interactableId: string | null = null ) {\n const registryId = customRegistryId || DEFAULT_REGISTRY_ID;\n // if we pass an id to createInteractableId then it is used when creating the interactable\n // and returned, otherwise a new id is created for the draggable.\n const key = this.createInteractableId(interactableId );\n if (!Object.prototype.hasOwnProperty.call(this.dragRegistrySystem, registryId)) {\n this.dragRegistrySystem[registryId] = {};\n }\n this.dragRegistrySystem[registryId][key] = this.createInteractableState(defaultPosition, defaultSize, defaultDelta);\n return key\n }\n\n destroyInteractable(interactableId: string, registryId = DEFAULT_REGISTRY_ID) {\n const interactableSystem =this.dragRegistrySystem[registryId][interactableId];\n if(interactableSystem) {\n // unsubscribe from all the subscriptions if they're subscriptions\n for (const propName in interactableSystem) {\n const prop = interactableSystem[propName];\n if (prop.unsubscribe && typeof prop.unsubscribe === 'function' ) {\n prop.unsubscribe();\n };\n }\n delete this.dragRegistrySystem[registryId][interactableId];\n }\n }\n\n subscribeToInteractable(interactableId: string, registryId = DEFAULT_REGISTRY_ID) {\n return this.dragRegistrySystem[registryId][interactableId];\n }\n\n createInteractableState(initialPosition: Position, initialSize: Size, initialDelta: Delta ) {\n\n const deltas$ = new BehaviorSubject(initialDelta);\n // tracks the size of the element\n const size$ = new BehaviorSubject({...initialSize, ...initialDelta});\n // Stream of positions as they change\n const position$ = new BehaviorSubject(initialPosition);\n\n // All draggable data mapped together\n const interactable$: Observable<TftCoords> = combineLatest([\n size$.pipe(\n // startWith({...initialSize, ...initialDelta}),\n shareReplay(1),\n // filter(resizeEvent => !!resizeEvent.targetElement),\n tap(({deltaX, deltaY, width, height, targetElement}) => {\n this.ngZone.runOutsideAngular(() => {\n this.setElementSize(width, height, targetElement);\n });\n // only reposition if necessary i.e when resizing left or up\n if(deltaX || deltaY) {\n deltas$.next({deltaX, deltaY, targetElement});\n }\n })\n ),\n deltas$.pipe(\n shareReplay(1),\n tap((delta) => {\n const position = position$.value;\n const newPosition = this.addDeltaToPosition(delta, position);\n position$.next(newPosition);\n })\n ),\n position$.pipe(\n shareReplay(1),\n tap( position => {\n this.ngZone.runOutsideAngular(() => {\n this.setElementTransform(position.x, position.y, position);\n })\n })\n )\n ]).pipe(\n shareReplay(1),\n map( ([size, deltas, position]): TftCoords=> {\n return {\n x: position.x,\n y: position.y,\n deltaX: deltas.deltaX,\n deltaY: deltas.deltaY,\n width: size.width,\n height: size.height,\n targetElement: size.targetElement || position.targetElement || deltas.targetElement\n }\n }),\n )\n // TODO: update system to handle only returning interactable$\n return {\n deltas$,\n position$,\n size$,\n interactable$\n }\n }\n\n createInteractableId(customInteractableId: string | null = null) {\n return customInteractableId || `interactable${this._interactableIndex++}`\n }\n\n createDropzoneId(index: number) {\n return `dropzone${index}`\n }\n\n getInteractableState( interactableId: string, registryId = DEFAULT_REGISTRY_ID) {\n return this.dragRegistrySystem[registryId][interactableId].interactable$;\n }\n\n updateDeltas(interactId: string, registryId: string, { deltaX, deltaY }, targetElement) {\n if (!this.interactableExistOnRegistry(interactId, registryId)) return;\n this.dragRegistrySystem[registryId][interactId].deltas$.next({ deltaX, deltaY, targetElement })\n }\n\n updatePosition(interactId: string, registryId: string, { x, y }: {x: number; y: number;}, targetElement) {\n if (!this.interactableExistOnRegistry(interactId, registryId)) return;\n this.dragRegistrySystem[registryId][interactId].position$.next({ x, y, targetElement })\n }\n\n updateSize(interactId: string, registryId: string, { deltaX, deltaY, width, height }, targetElement) {\n if (!this.interactableExistOnRegistry(interactId, registryId)) return\n this.dragRegistrySystem[registryId][interactId].size$.next({deltaX, deltaY, width, height, targetElement});\n }\n\n interactableExistOnRegistry(interactId: string, registryId = DEFAULT_REGISTRY_ID) {\n // eslint-disable-next-line no-prototype-builtins\n return this.dragRegistrySystem.hasOwnProperty(registryId) && this.dragRegistrySystem[registryId].hasOwnProperty(interactId);\n }\n /**\n * Uses renderer to set width and height of angular component\n * @param width the desired width of component\n * @param height the desired height of component\n * @param target the element to transform\n */\n setElementSize(width: number, height: number, target: TftResizeElement) {\n if(!target) return;\n this.renderer.setStyle(target, 'width', `${width}${this.cssUnit}`);\n this.renderer.setStyle(target, 'height', `${height}${this.cssUnit}`);\n }\n /**\n * Uses renderer to set position of angular component\n * @param x position on x axis\n * @param y position on y axis\n * @param target the element to transform\n */\n setElementTransform(x: number, y: number, position: Position ) {\n if(!position?.targetElement) return;\n this.renderer.setStyle(position.targetElement, 'left', `${x}${this.cssUnit}`);\n this.renderer.setStyle(position.targetElement, 'top', `${y}${this.cssUnit}`);\n }\n /**\n * Generates a translate string for the x and y arguments passed to\n * be passed to css transform\n * @param x the position along the x axis\n * @param y the position along the y axis\n */\n createTransformString(x: number, y: number) {\n return `translate3d(${x}${this.cssUnit}, ${y}${this.cssUnit}, 0)`\n }\n\n calculatePositionInElement(zoneElement: Interact.Element, dragElement: TftDragElement, scale?: number) {\n // TODO: this calculation may not cover a lot of scenarios, keep an eye out for possible improvements\n const zoneRect = zoneElement.getBoundingClientRect();\n const dragRect = dragElement.getBoundingClientRect();\n const position = scale\n ? {\n x: (dragRect.left - zoneRect.left) / scale || 1,\n y: (dragRect.top - zoneRect.top) / scale || 1\n } : {\n x: dragRect.left - zoneRect.left,\n y: dragRect.top - zoneRect.top\n };\n // console.log({ y:position.y, drt:dragRect.top, zrt: zoneRect.top})\n return position;\n }\n}\n"]}
@@ -1 +1 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"InteractService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":9,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"RendererFactory2","line":20,"character":29},{"__symbolic":"reference","module":"@angular/core","name":"NgZone","line":21,"character":20}]}],"addDeltaToPosition":[{"__symbolic":"method"}],"addRegistryToSystem":[{"__symbolic":"method"}],"addDraggableToRegistry":[{"__symbolic":"method"}],"destroyInteractable":[{"__symbolic":"method"}],"subscribeToInteractable":[{"__symbolic":"method"}],"createInteractableState":[{"__symbolic":"method"}],"createInteractableId":[{"__symbolic":"method"}],"createDropzoneId":[{"__symbolic":"method"}],"getInteractableState":[{"__symbolic":"method"}],"updateDeltas":[{"__symbolic":"method"}],"updatePosition":[{"__symbolic":"method"}],"updateSize":[{"__symbolic":"method"}],"interactableExistOnRegistry":[{"__symbolic":"method"}],"setElementSize":[{"__symbolic":"method"}],"setElementTransform":[{"__symbolic":"method"}],"createTransformString":[{"__symbolic":"method"}],"calculatePositionInElement":[{"__symbolic":"method"}]},"statics":{"ɵprov":{}}}}}]
1
+ [{"__symbolic":"module","version":4,"metadata":{"InteractService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":11,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":24,"character":5}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":24,"character":17},"arguments":[{"__symbolic":"reference","module":"../models","name":"INTERACT_ROOT_CONFIG","line":24,"character":24}]}]],"parameters":[{"__symbolic":"reference","module":"@angular/core","name":"RendererFactory2","line":22,"character":29},{"__symbolic":"reference","module":"@angular/core","name":"NgZone","line":23,"character":20},null]}],"addDeltaToPosition":[{"__symbolic":"method"}],"addRegistryToSystem":[{"__symbolic":"method"}],"addDraggableToRegistry":[{"__symbolic":"method"}],"destroyInteractable":[{"__symbolic":"method"}],"subscribeToInteractable":[{"__symbolic":"method"}],"createInteractableState":[{"__symbolic":"method"}],"createInteractableId":[{"__symbolic":"method"}],"createDropzoneId":[{"__symbolic":"method"}],"getInteractableState":[{"__symbolic":"method"}],"updateDeltas":[{"__symbolic":"method"}],"updatePosition":[{"__symbolic":"method"}],"updateSize":[{"__symbolic":"method"}],"interactableExistOnRegistry":[{"__symbolic":"method"}],"setElementSize":[{"__symbolic":"method"}],"setElementTransform":[{"__symbolic":"method"}],"createTransformString":[{"__symbolic":"method"}],"calculatePositionInElement":[{"__symbolic":"method"}]},"statics":{"ɵprov":{}}}}}]