@jsenv/dom 0.17.82 → 0.17.83

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 +65 -20
  2. package/package.json +1 -1
package/dist/jsenv_dom.js CHANGED
@@ -10147,6 +10147,11 @@ const dragSourceThatStoodDown = (pressEvent) => {
10147
10147
  return pressEvent[STOOD_DOWN] || null;
10148
10148
  };
10149
10149
 
10150
+ // How far (px) a press travels before it means drag. Also how far a carry that
10151
+ // was handed over must go before it has gone anywhere (see handedOver in
10152
+ // drag_to.js): that is the same question, asked of the hand holding it.
10153
+ const DRAG_INTENT_THRESHOLD = 5;
10154
+
10150
10155
  /**
10151
10156
  * Waits for the user to mean it, then starts a drag gesture.
10152
10157
  *
@@ -10192,7 +10197,7 @@ const dragAfterIntent = (
10192
10197
  grabEvent,
10193
10198
  dragGestureInitializer,
10194
10199
  {
10195
- threshold = 5,
10200
+ threshold = DRAG_INTENT_THRESHOLD,
10196
10201
  longPress = "if-touch",
10197
10202
  longPressDelay = 400,
10198
10203
  longPressSlop = 8,
@@ -14960,8 +14965,12 @@ const createDragToMoveGestureController = ({
14960
14965
  * hold that handed it over, so the carry starts at once. And where the hand is
14961
14966
  * has nothing to do with where the element stands, so the copy is brought to
14962
14967
  * the hand — centred on the finger, flying there from the element's box —
14963
- * rather than following it from a distance. The pointer is taken on the
14964
- * element, away from what the finger first touched. Only a copy can be brought
14968
+ * rather than following it from a distance. Where it was brought then stands
14969
+ * for the element's own place: over whatever the finger happened to be on, so
14970
+ * nothing counts as under it until the hand has taken it further than
14971
+ * `threshold`, and a release before that is a hand that changed its mind. The
14972
+ * pointer is taken on the element, away from what the finger first touched.
14973
+ * Only a copy can be brought
14965
14974
  * like that: `move` carries the element itself, which would leave its place
14966
14975
  * just by being handed a press, and is not started.
14967
14976
  *
@@ -15316,6 +15325,10 @@ const resolveDropMeaning = ({
15316
15325
  canLeave,
15317
15326
  tossDistance = TOSS_DISTANCE_TO_COMMIT,
15318
15327
  tossSpeed = TOSS_SPEED_TO_COMMIT,
15328
+ // How far it may have been taken and still have been taken nowhere: not at
15329
+ // all for a carry that starts over its own place, the drag threshold for one
15330
+ // brought to a hand (see handedOver).
15331
+ stillWithin = 0,
15319
15332
  }) => {
15320
15333
  if (gestureInfo.cancelled) {
15321
15334
  // Nobody let go of anything: the gesture was taken away mid-air (the
@@ -15341,7 +15354,7 @@ const resolveDropMeaning = ({
15341
15354
  // It has to have gone somewhere to be put anywhere, or away from anything:
15342
15355
  // picked up and put straight back down is a hand that changed its mind.
15343
15356
  const { xDelta, yDelta } = gestureInfo.layout;
15344
- if (!xDelta && !yDelta) {
15357
+ if (Math.hypot(xDelta, yDelta) <= stillWithin) {
15345
15358
  return "cancel";
15346
15359
  }
15347
15360
  if (canLeave && releasedOutside) {
@@ -15399,7 +15412,9 @@ const startDragToCarryCopy = (
15399
15412
  direction = canLand || canLeave
15400
15413
  ? { x: true, y: true }
15401
15414
  : { x: false, y: true },
15402
- threshold,
15415
+ // Defaulted here rather than left to dragAfterIntent: a carry handed over
15416
+ // reads it too (see stillWithin).
15417
+ threshold = DRAG_INTENT_THRESHOLD,
15403
15418
  longPress,
15404
15419
  longPressDelay,
15405
15420
  longPressSlop,
@@ -15448,6 +15463,13 @@ const startDragToCarryCopy = (
15448
15463
  const reach = handedTo
15449
15464
  ? measureReach(draggedElement, handedTo)
15450
15465
  : undefined;
15466
+ // …and has been taken nowhere until it is further from there than a
15467
+ // press travels to mean drag.
15468
+ const stillWithin = handedTo ? threshold : 0;
15469
+ const hasNotLeftHand = (gestureInfo) =>
15470
+ Boolean(handedTo) &&
15471
+ Math.hypot(gestureInfo.layout.xDelta, gestureInfo.layout.yDelta) <=
15472
+ stillWithin;
15451
15473
  const cloneWrapper =
15452
15474
  cloneWrapperCaught ||
15453
15475
  createDragClone(draggedElement, handedTo || pointerEvent, reach);
@@ -15540,6 +15562,16 @@ const startDragToCarryCopy = (
15540
15562
  if (!dropHintEl) {
15541
15563
  return;
15542
15564
  }
15565
+ // Brought to the hand, the copy starts over whatever the finger is on,
15566
+ // and a place found there is one it was never taken to — the release
15567
+ // frame included, which is how a hold let go of without moving would
15568
+ // land. Around where it was brought is its own place, as the element's
15569
+ // box is for a carry that starts there: nothing is under it yet.
15570
+ if (hasNotLeftHand(gestureInfo)) {
15571
+ clearDropHint();
15572
+ gestureInfo.dropTargetInfo = null;
15573
+ return;
15574
+ }
15543
15575
  const allItems = [];
15544
15576
  const items = [];
15545
15577
  for (const el of containerElement.querySelectorAll(itemSelector)) {
@@ -15686,6 +15718,7 @@ const startDragToCarryCopy = (
15686
15718
  canLeave,
15687
15719
  tossDistance,
15688
15720
  tossSpeed,
15721
+ stillWithin,
15689
15722
  });
15690
15723
  // The hand has let go, and what that means is already known — the
15691
15724
  // answer to it has not run yet. Told, not asked: nothing here waits on
@@ -22186,33 +22219,45 @@ const measureWidestChildRow = (el) => {
22186
22219
  const borderLeft = parseFloat(containerStyle.borderLeftWidth);
22187
22220
  const borderRight = parseFloat(containerStyle.borderRightWidth);
22188
22221
 
22189
- // Group children by row using their top position
22190
- const rowsByTop = new Map();
22222
+ // Rows are found by vertical overlap, not by top: in an "align-items: center"
22223
+ // row, a child taller than its neighbours (a 1px border is enough) starts
22224
+ // higher than them and would open a row of its own.
22225
+ const rows = [];
22191
22226
  for (const child of children) {
22192
22227
  const rect = child.getBoundingClientRect();
22193
22228
  if (rect.width === 0 && rect.height === 0) {
22194
22229
  continue;
22195
22230
  }
22196
- const top = Math.round(rect.top);
22197
- const existing = rowsByTop.get(top);
22198
- if (existing === undefined) {
22199
- rowsByTop.set(top, { left: rect.left, right: rect.right });
22200
- } else {
22201
- if (rect.left < existing.left) {
22202
- existing.left = rect.left;
22203
- }
22204
- if (rect.right > existing.right) {
22205
- existing.right = rect.right;
22206
- }
22231
+ const row = rows.find((candidate) => sharesLine(candidate, rect));
22232
+ if (row === undefined) {
22233
+ rows.push({
22234
+ top: rect.top,
22235
+ bottom: rect.bottom,
22236
+ left: rect.left,
22237
+ right: rect.right,
22238
+ });
22239
+ continue;
22240
+ }
22241
+ if (rect.top < row.top) {
22242
+ row.top = rect.top;
22243
+ }
22244
+ if (rect.bottom > row.bottom) {
22245
+ row.bottom = rect.bottom;
22246
+ }
22247
+ if (rect.left < row.left) {
22248
+ row.left = rect.left;
22249
+ }
22250
+ if (rect.right > row.right) {
22251
+ row.right = rect.right;
22207
22252
  }
22208
22253
  }
22209
22254
 
22210
- if (rowsByTop.size <= 1) {
22255
+ if (rows.length <= 1) {
22211
22256
  return null;
22212
22257
  }
22213
22258
 
22214
22259
  let widestRowWidth = 0;
22215
- for (const { left, right } of rowsByTop.values()) {
22260
+ for (const { left, right } of rows) {
22216
22261
  const rowWidth = right - left;
22217
22262
  if (rowWidth > widestRowWidth) {
22218
22263
  widestRowWidth = rowWidth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/dom",
3
- "version": "0.17.82",
3
+ "version": "0.17.83",
4
4
  "type": "module",
5
5
  "description": "DOM utilities for writing frontend code",
6
6
  "repository": {