@cujuju/solid-reorder-list 0.3.0 → 0.4.0
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/README.md +561 -551
- package/dist/index.cjs +126 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +126 -14
- package/dist/index.js.map +1 -1
- package/package.json +60 -60
- package/src/createReorderGrid.ts +824 -778
- package/src/createReorderList.ts +489 -442
- package/src/shared.ts +53 -0
package/src/shared.ts
CHANGED
|
@@ -67,3 +67,56 @@ export function createCancelListeners(opts: { onCancel: () => void }): CancelLis
|
|
|
67
67
|
},
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
/** Default milliseconds a touch or pen press is held before it can drag. */
|
|
72
|
+
export const DEFAULT_TOUCH_HOLD_MS = 200;
|
|
73
|
+
/** Default pixels a held touch may wander before the hold is abandoned. */
|
|
74
|
+
export const DEFAULT_TOUCH_HOLD_TOLERANCE = 10;
|
|
75
|
+
/** Default class on an item whose touch hold has completed. */
|
|
76
|
+
export const DEFAULT_ARMED_CLASS = 'reorder-armed';
|
|
77
|
+
|
|
78
|
+
export interface PressHold {
|
|
79
|
+
/** True once the press may start a drag: at once for a mouse, after the hold for touch and pen. */
|
|
80
|
+
readonly held: boolean;
|
|
81
|
+
/** Feed each pointermove before activation. Returns false when the press
|
|
82
|
+
* wandered too far during the hold, and the caller should give it up. */
|
|
83
|
+
move(ev: PointerEvent): boolean;
|
|
84
|
+
/** Clear the timer and listeners. Safe to call more than once. */
|
|
85
|
+
stop(): void;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Gate a press behind a hold. A touch or pen press must stay down, within
|
|
90
|
+
* `tolerance` pixels of where it started, for `ms` before it may drag, so a
|
|
91
|
+
* finger flick across a list scrolls or does nothing instead of grabbing an
|
|
92
|
+
* item. A mouse is never held. `ms <= 0` turns the hold off.
|
|
93
|
+
*
|
|
94
|
+
* While a touch press is down, its contextmenu (the long-press menu) is
|
|
95
|
+
* swallowed so it neither opens nor cancels the drag that follows.
|
|
96
|
+
*/
|
|
97
|
+
export function startPressHold(e: PointerEvent, opts: {
|
|
98
|
+
ms: number;
|
|
99
|
+
tolerance: number;
|
|
100
|
+
onHeld: () => void;
|
|
101
|
+
}): PressHold {
|
|
102
|
+
const touch = e.pointerType === 'touch' || e.pointerType === 'pen';
|
|
103
|
+
if (opts.ms <= 0 || !touch) {
|
|
104
|
+
return { held: true, move: () => true, stop: () => {} };
|
|
105
|
+
}
|
|
106
|
+
const startX = e.clientX;
|
|
107
|
+
const startY = e.clientY;
|
|
108
|
+
let held = false;
|
|
109
|
+
const swallowMenu = (ev: Event) => { ev.preventDefault(); ev.stopPropagation(); };
|
|
110
|
+
const timer = setTimeout(() => { held = true; opts.onHeld(); }, opts.ms);
|
|
111
|
+
document.addEventListener('contextmenu', swallowMenu, { capture: true });
|
|
112
|
+
return {
|
|
113
|
+
get held() { return held; },
|
|
114
|
+
move(ev) {
|
|
115
|
+
return held || Math.hypot(ev.clientX - startX, ev.clientY - startY) <= opts.tolerance;
|
|
116
|
+
},
|
|
117
|
+
stop() {
|
|
118
|
+
clearTimeout(timer);
|
|
119
|
+
document.removeEventListener('contextmenu', swallowMenu, { capture: true });
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|