@jsenv/dom 0.17.11 → 0.17.12

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 (2) hide show
  1. package/dist/jsenv_dom.js +42 -2
  2. package/package.json +1 -1
package/dist/jsenv_dom.js CHANGED
@@ -9093,11 +9093,47 @@ const dragAfterLongPress = (grabEvent, dragGestureInitializer, {
9093
9093
  onPressCancel,
9094
9094
  onPress
9095
9095
  }) => {
9096
+ /*
9097
+ * WHETHER a touchmove can be refused at all is decided when the touch BEGINS,
9098
+ * from the non-passive listeners present at that moment — and on this path the
9099
+ * gesture, which is what refuses it (see preventTouchScroll in
9100
+ * drag_gesture.js), is only born once the wait is over. By then the browser has
9101
+ * long made up its mind: every touchmove it hands over is already
9102
+ * `cancelable: false`, the refusal does nothing, and the page scrolls away with
9103
+ * the object still under the finger — until the touch is taken for a scroll and
9104
+ * the pointer stream is cancelled, which is the drag dying mid-gesture.
9105
+ *
9106
+ * So the listener the decision looks for is put down with the FINGER, before
9107
+ * anyone knows whether this press is a drag. It refuses nothing — a press that
9108
+ * is still only a press must leave the scroll alone, which is exactly what the
9109
+ * wait is there to tell apart. Its only job is to be there, so that the
9110
+ * refusal made later is one the browser still listens to.
9111
+ */
9112
+ const keepTouchRefusable = () => {
9113
+ // Being registered IS the whole of it — see above.
9114
+ };
9115
+ const grabTarget = grabEvent.target;
9116
+ window.addEventListener("touchmove", keepTouchRefusable, {
9117
+ passive: false,
9118
+ capture: true
9119
+ });
9120
+ grabTarget.addEventListener("touchmove", keepTouchRefusable, {
9121
+ passive: false
9122
+ });
9123
+ const stopKeepingTouchRefusable = () => {
9124
+ window.removeEventListener("touchmove", keepTouchRefusable, {
9125
+ capture: true
9126
+ });
9127
+ grabTarget.removeEventListener("touchmove", keepTouchRefusable);
9128
+ };
9096
9129
  waitForPressHeld(grabEvent, {
9097
9130
  delay: longPressDelay,
9098
9131
  slop: longPressSlop,
9099
9132
  onPressStart,
9100
- onPressCancel,
9133
+ onPressCancel: pointerEvent => {
9134
+ stopKeepingTouchRefusable();
9135
+ onPressCancel?.(pointerEvent);
9136
+ },
9101
9137
  onPressHeld: (pressEvent, {
9102
9138
  endPress
9103
9139
  }) => {
@@ -9107,10 +9143,14 @@ const dragAfterLongPress = (grabEvent, dragGestureInitializer, {
9107
9143
  // for every way a drag can begin.
9108
9144
  const dragGesture = startDragGesture(dragGestureInitializer);
9109
9145
  if (!dragGesture) {
9146
+ stopKeepingTouchRefusable();
9110
9147
  endPress();
9111
9148
  return;
9112
9149
  }
9113
- dragGesture.addReleaseCallback(endPress);
9150
+ dragGesture.addReleaseCallback(() => {
9151
+ stopKeepingTouchRefusable();
9152
+ endPress();
9153
+ });
9114
9154
  }
9115
9155
  });
9116
9156
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/dom",
3
- "version": "0.17.11",
3
+ "version": "0.17.12",
4
4
  "type": "module",
5
5
  "description": "DOM utilities for writing frontend code",
6
6
  "repository": {