@tft/interact 12.4.3 → 12.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/tft-interact.umd.js +255 -120
- package/bundles/tft-interact.umd.js.map +1 -1
- package/esm2015/lib/directives/account-for-scale.directive.js +3 -11
- package/esm2015/lib/directives/account-for-scale.directive.js.map +1 -1
- package/esm2015/lib/directives/account-for-scale.directive.metadata.json +1 -1
- package/esm2015/lib/directives/account-for-scale.directive.ngfactory.js.map +1 -0
- package/esm2015/lib/directives/apply-scale.directive.js +4 -13
- package/esm2015/lib/directives/apply-scale.directive.js.map +1 -1
- package/esm2015/lib/directives/apply-scale.directive.metadata.json +1 -1
- package/esm2015/lib/directives/apply-scale.directive.ngfactory.js.map +1 -0
- package/esm2015/lib/directives/auto-scroll.directive.js +54 -0
- package/esm2015/lib/directives/auto-scroll.directive.js.map +1 -0
- package/esm2015/lib/directives/auto-scroll.directive.metadata.json +1 -0
- package/esm2015/lib/directives/auto-scroll.directive.ngfactory.js.map +1 -0
- package/esm2015/lib/directives/drag-preview.directive.ngfactory.js.map +1 -0
- package/esm2015/lib/directives/drag-root.directive.js +8 -11
- package/esm2015/lib/directives/drag-root.directive.js.map +1 -1
- package/esm2015/lib/directives/drag-root.directive.metadata.json +1 -1
- package/esm2015/lib/directives/drag-root.directive.ngfactory.js.map +1 -0
- package/esm2015/lib/directives/draggable.directive.js +45 -15
- package/esm2015/lib/directives/draggable.directive.js.map +1 -1
- package/esm2015/lib/directives/draggable.directive.metadata.json +1 -1
- package/esm2015/lib/directives/draggable.directive.ngfactory.js.map +1 -0
- package/esm2015/lib/directives/dropzone.directive.js +9 -6
- package/esm2015/lib/directives/dropzone.directive.js.map +1 -1
- package/esm2015/lib/directives/dropzone.directive.metadata.json +1 -1
- package/esm2015/lib/directives/dropzone.directive.ngfactory.js.map +1 -0
- package/esm2015/lib/directives/gesturable.directive.ngfactory.js.map +1 -0
- package/esm2015/lib/directives/index.js +1 -0
- package/esm2015/lib/directives/index.js.map +1 -1
- package/esm2015/lib/directives/index.metadata.json +1 -1
- package/esm2015/lib/directives/resizable.directive.js +62 -13
- package/esm2015/lib/directives/resizable.directive.js.map +1 -1
- package/esm2015/lib/directives/resizable.directive.metadata.json +1 -1
- package/esm2015/lib/directives/resizable.directive.ngfactory.js.map +1 -0
- package/esm2015/lib/interact.module.js +15 -1
- package/esm2015/lib/interact.module.js.map +1 -1
- package/esm2015/lib/interact.module.metadata.json +1 -1
- package/esm2015/lib/interact.module.ngfactory.js.map +1 -0
- package/esm2015/lib/models/interact.js +2 -0
- package/esm2015/lib/models/interact.js.map +1 -1
- package/esm2015/lib/models/interact.metadata.json +1 -1
- package/esm2015/lib/pipes/array-of-n.pipe.ngfactory.js.map +1 -0
- package/esm2015/lib/services/interact.service.js +31 -36
- package/esm2015/lib/services/interact.service.js.map +1 -1
- package/esm2015/lib/services/interact.service.metadata.json +1 -1
- package/esm2015/lib/services/interact.service.ngfactory.js.map +1 -0
- package/esm2015/tft-interact.js +2 -2
- package/esm2015/tft-interact.js.map +1 -1
- package/esm2015/tft-interact.metadata.json +1 -1
- package/fesm2015/tft-interact.js +223 -105
- package/fesm2015/tft-interact.js.map +1 -1
- package/lib/directives/account-for-scale.directive.d.ts +1 -3
- package/lib/directives/apply-scale.directive.d.ts +4 -7
- package/lib/directives/auto-scroll.directive.d.ts +31 -0
- package/lib/directives/drag-root.directive.d.ts +2 -1
- package/lib/directives/draggable.directive.d.ts +8 -2
- package/lib/directives/dropzone.directive.d.ts +7 -4
- package/lib/directives/index.d.ts +1 -0
- package/lib/directives/resizable.directive.d.ts +10 -3
- package/lib/interact.module.d.ts +3 -0
- package/lib/models/interact.d.ts +10 -0
- package/lib/services/interact.service.d.ts +6 -7
- package/package.json +1 -1
- package/tft-interact-12.5.3.tgz +0 -0
- package/tft-interact.d.ts +2 -2
- package/tft-interact.metadata.json +1 -1
- package/tft-interact-12.4.3.tgz +0 -0
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
123
|
-
|
|
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
|
-
|
|
136
|
-
|
|
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
|
-
|
|
159
|
-
|
|
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}
|
|
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
|
|
185
|
-
y: (dragRect.top - zoneRect.top) / scale
|
|
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,OAAO,eAAe;IAS1B,YACU,eAAiC,EACjC,MAAc;QADd,oBAAe,GAAf,eAAe,CAAkB;QACjC,WAAM,GAAN,MAAM,CAAQ;QAThB,uBAAkB,GAAG,CAAC,CAAC;QACvB,mBAAc,GAAG,CAAC,CAAC;QAG3B,gCAAgC;QACvB,uBAAkB,GAA4C,EAAG,CAAC;QAMzE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClE,CAAC;IAED,kBAAkB,CAAC,KAAY,EAAE,QAAkB;QACjD,OAAO;YACL,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC;YAC5B,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC;YAC5B,aAAa,EAAE,QAAQ,CAAC,aAAa,IAAI,KAAK,CAAC,aAAa;SAC7D,CAAA;IACH,CAAC;IAED,mBAAmB,CAAC,mBAAkC,IAAI;QACxD,MAAM,UAAU,GAAG,gBAAgB,IAAI,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;QACpF,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,GAAG,EAAE,C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AG,CAAC,IAAI,CAAC,CAAC;SACjE;IACH,CAAC;IACD;;;;;OAKG;IACH,qBAAqB,CAAC,CAAS,EAAE,CAAS;QACxC,OAAO,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAA;IACzC,CAAC;IAED,0BAA0B,CAAC,WAA6B,EAAE,WAA2B,EAAE,KAA8B;QACnH,qGAAqG;QACrG,MAAM,QAAQ,GAAG,WAAW,CAAC,qBAAqB,EAAE,CAAC;QACrD,MAAM,QAAQ,GAAG,WAAW,CAAC,qBAAqB,EAAE,CAAC;QACrD,MAAM,QAAQ,GAAG,KAAK;YACpB,CAAC,CAAC;gBACF,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,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,MAAM,WAAW,CAAC;;;AAKnB,MAAM,OAAO,eAAe;IAS1B,YACU,eAAiC,EACjC,MAAc,EAC2B,UAAU;QAFnD,oBAAe,GAAf,eAAe,CAAkB;QACjC,WAAM,GAAN,MAAM,CAAQ;QAC2B,eAAU,GAAV,UAAU,CAAA;QAVrD,uBAAkB,GAAG,CAAC,CAAC;QACvB,mBAAc,GAAG,CAAC,CAAC;QAG3B,gCAAgC;QACvB,uBAAkB,GAA4C,EAAG,CAAC;QACnE,YAAO,GAAG,IAAI,CAAA;QAMpB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAChE,IAAI,CAAC,OAAO,GAAG,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,gBAAgB,KAAI,IAAI,CAAC;IACtD,CAAC;IAED,kBAAkB,CAAC,KAAY,EAAE,QAAkB;QACjD,OAAO;YACL,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC;YAC5B,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC;YAC5B,aAAa,EAAE,QAAQ,CAAC,aAAa,IAAI,KAAK,CAAC,aAAa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,GAAG,WAAW,CAAC,qBAAqB,EAAE,CAAC;QACrD,MAAM,QAAQ,GAAG,WAAW,CAAC,qBAAqB,EAAE,CAAC;QACrD,MAAM,QAAQ,GAAG,KAAK;YACpB,CAAC,CAAC;gBACF,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,IAAK,CAAC;gBAChD,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,IAAI,CAAC;aAC5C,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,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":
|
|
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":{}}}}}]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interact.service.ngfactory.js","sourceRoot":"","sources":["../../../../../../libs/interact/src/lib/services/interact.service.ngfactory.ts"],"names":[],"mappings":"","sourcesContent":["import * as i0 from '@angular/core';\ni0.ComponentFactory;\n"]}
|
package/esm2015/tft-interact.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Generated bundle index. Do not edit.
|
|
3
3
|
*/
|
|
4
4
|
export * from './index';
|
|
5
|
-
export { AccountForScaleDirective as
|
|
6
|
-
export { ArrayOfNPipe as
|
|
5
|
+
export { AccountForScaleDirective as ɵg, ApplyScaleDirective as ɵh, AutoScrollDirective as ɵf, DragPreviewDirective as ɵi, DragRootDirective as ɵe, DraggableDirective as ɵa, DropzoneDirective as ɵc, GesturableDirective as ɵd, ResizableDirective as ɵb } from './lib/directives';
|
|
6
|
+
export { ArrayOfNPipe as ɵj } from './lib/pipes/array-of-n.pipe';
|
|
7
7
|
//# sourceMappingURL=tft-interact.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tft-interact.js","sourceRoot":"","sources":["../../../../libs/interact/src/tft-interact.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AAExB,OAAO,EAAC,wBAAwB,IAAI,EAAE,EAAC,mBAAmB,IAAI,EAAE,EAAC,oBAAoB,IAAI,EAAE,EAAC,iBAAiB,IAAI,EAAE,EAAC,kBAAkB,IAAI,EAAE,EAAC,iBAAiB,IAAI,EAAE,EAAC,mBAAmB,IAAI,EAAE,EAAC,kBAAkB,IAAI,EAAE,EAAC,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"tft-interact.js","sourceRoot":"","sources":["../../../../libs/interact/src/tft-interact.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AAExB,OAAO,EAAC,wBAAwB,IAAI,EAAE,EAAC,mBAAmB,IAAI,EAAE,EAAC,mBAAmB,IAAI,EAAE,EAAC,oBAAoB,IAAI,EAAE,EAAC,iBAAiB,IAAI,EAAE,EAAC,kBAAkB,IAAI,EAAE,EAAC,iBAAiB,IAAI,EAAE,EAAC,mBAAmB,IAAI,EAAE,EAAC,kBAAkB,IAAI,EAAE,EAAC,MAAM,kBAAkB,CAAC;AAC3Q,OAAO,EAAC,YAAY,IAAI,EAAE,EAAC,MAAM,6BAA6B,CAAC","sourcesContent":["/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n\nexport {AccountForScaleDirective as ɵg,ApplyScaleDirective as ɵh,AutoScrollDirective as ɵf,DragPreviewDirective as ɵi,DragRootDirective as ɵe,DraggableDirective as ɵa,DropzoneDirective as ɵc,GesturableDirective as ɵd,ResizableDirective as ɵb} from './lib/directives';\nexport {ArrayOfNPipe as ɵj} from './lib/pipes/array-of-n.pipe';"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"__symbolic":"module","version":4,"metadata":{},"exports":[{"from":"./index"},{"from":"./lib/directives","export":[{"name":"AccountForScaleDirective","as":"
|
|
1
|
+
[{"__symbolic":"module","version":4,"metadata":{},"exports":[{"from":"./index"},{"from":"./lib/directives","export":[{"name":"AccountForScaleDirective","as":"ɵg"},{"name":"ApplyScaleDirective","as":"ɵh"},{"name":"AutoScrollDirective","as":"ɵf"},{"name":"DragPreviewDirective","as":"ɵi"},{"name":"DragRootDirective","as":"ɵe"},{"name":"DraggableDirective","as":"ɵa"},{"name":"DropzoneDirective","as":"ɵc"},{"name":"GesturableDirective","as":"ɵd"},{"name":"ResizableDirective","as":"ɵb"}]},{"from":"./lib/pipes/array-of-n.pipe","export":[{"name":"ArrayOfNPipe","as":"ɵj"}]}]}]
|