@xh/hoist 75.0.0-SNAPSHOT.1753454795132 → 75.0.0-SNAPSHOT.1753458616250

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.
@@ -13,7 +13,7 @@ export declare class DraggerModel extends HoistModel {
13
13
  maxSize: any;
14
14
  throttledSetSize: any;
15
15
  onLinked(): void;
16
- private addListeners;
16
+ private toggleListeners;
17
17
  private onDragStart;
18
18
  private onDrag;
19
19
  private onDragEnd;
@@ -24,9 +24,11 @@ export declare class DraggerModel extends HoistModel {
24
24
  private parseEventPositions;
25
25
  private isValidMouseEvent;
26
26
  private isValidTouchEvent;
27
+ private get isFirefox();
27
28
  /**
28
29
  * @param v - Workaround to allow dragging over iframe, which is its own
29
30
  * separate document and cannot listen for events from main document.
30
31
  */
31
32
  setIframePointerEvents(v: 'none' | 'auto'): void;
33
+ destroy(): void;
32
34
  }
@@ -30,25 +30,34 @@ export class DraggerModel extends HoistModel {
30
30
  override onLinked() {
31
31
  this.throttledSetSize = throttle(size => (this.panelModel.size = size), 50);
32
32
 
33
- // Add listeners to el to ensure we can get non-passive handlers than can preventDefault()
33
+ // maintain listeners on el to ensure we can get non-passive handlers than can preventDefault()
34
34
  // React synthetic touch events on certain browsers (e.g. airwatch) don't yield that
35
35
  this.addReaction({
36
36
  track: () => this.ref.current,
37
- run: current => {
38
- if (current) this.addListeners(current);
37
+ run: (current, old) => {
38
+ this.toggleListeners(old, false);
39
+ this.toggleListeners(current, true);
39
40
  }
40
41
  });
41
42
  }
42
43
 
43
- private addListeners(el) {
44
+ private toggleListeners(el, add: boolean) {
45
+ if (!el) return;
46
+ const fn = (element, event, handler, options = undefined) => {
47
+ add
48
+ ? element.addEventListener(event, handler, options)
49
+ : element.removeEventListener(event, handler, options);
50
+ };
44
51
  if (XH.isDesktop) {
45
- el.addEventListener('dragstart', this.onDragStart);
46
- el.addEventListener('drag', this.onDrag);
47
- el.addEventListener('dragend', this.onDragEnd);
52
+ fn(el, 'dragstart', this.onDragStart);
53
+ fn(el, 'dragend', this.onDragEnd);
54
+ this.isFirefox // drag co-ordinates not impl in firefox -- use 'dragover' on doc
55
+ ? fn(document, `dragover`, this.onDrag)
56
+ : fn(el, 'drag', this.onDrag);
48
57
  } else {
49
- el.addEventListener('touchstart', this.onDragStart);
50
- el.addEventListener('touchmove', this.onDrag, {passive: false});
51
- el.addEventListener('touchend', this.onDragEnd);
58
+ fn(el, 'touchstart', this.onDragStart);
59
+ fn(el, 'touchmove', this.onDrag, {passive: false});
60
+ fn(el, 'touchend', this.onDragEnd);
52
61
  }
53
62
  }
54
63
 
@@ -263,6 +272,10 @@ export class DraggerModel extends HoistModel {
263
272
  return e.touches && e.touches.length > 0;
264
273
  }
265
274
 
275
+ private get isFirefox(): boolean {
276
+ return navigator.userAgent.toLowerCase().includes('firefox');
277
+ }
278
+
266
279
  /**
267
280
  * @param v - Workaround to allow dragging over iframe, which is its own
268
281
  * separate document and cannot listen for events from main document.
@@ -272,4 +285,9 @@ export class DraggerModel extends HoistModel {
272
285
  el.style['pointer-events'] = v;
273
286
  }
274
287
  }
288
+
289
+ override destroy() {
290
+ this.toggleListeners(this.ref.current, false);
291
+ super.destroy();
292
+ }
275
293
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "75.0.0-SNAPSHOT.1753454795132",
3
+ "version": "75.0.0-SNAPSHOT.1753458616250",
4
4
  "description": "Hoist add-on for building and deploying React Applications.",
5
5
  "repository": "github:xh/hoist-react",
6
6
  "homepage": "https://xh.io",