magic-pill 9.4.0-next.1 → 9.4.0-next.2
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/CHANGELOG.md +17 -0
- package/dist/MagicPill/MagicPill.d.mts +9 -1
- package/dist/MagicPill/MagicPill.d.ts +9 -1
- package/dist/MagicPill/MagicPill.js +3 -1
- package/dist/MagicPill/MagicPill.mjs +3 -1
- package/dist/Pill/goo.js +238 -15
- package/dist/Pill/goo.mjs +235 -16
- package/dist/Pill/morph.js +8 -3
- package/dist/Pill/morph.mjs +7 -4
- package/dist/satellites/Actions.js +138 -16
- package/dist/satellites/Actions.mjs +139 -18
- package/dist/satellites/Orbitals.js +76 -45
- package/dist/satellites/Orbitals.mjs +77 -46
- package/dist/satellites/Satellites.js +284 -50
- package/dist/satellites/Satellites.mjs +285 -51
- package/dist/satellites/layout.js +83 -30
- package/dist/satellites/layout.mjs +83 -30
- package/dist/satellites/types.d.mts +4 -0
- package/dist/satellites/types.d.ts +4 -0
- package/dist/satellites.d.mts +2 -2
- package/dist/satellites.d.ts +2 -2
- package/dist/store/store.js +1 -1
- package/dist/store/store.mjs +1 -1
- package/dist/styles.css +170 -17
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { useEffect, useSyncExternalStore } from "react";
|
|
3
|
+
import { useEffect, useRef, useSyncExternalStore } from "react";
|
|
4
4
|
import PillAction from "../Pill/PillAction.mjs";
|
|
5
5
|
import { PillActions, PillDivider } from "../Pill/parts.mjs";
|
|
6
6
|
import { getStore } from "../store/store.mjs";
|
|
@@ -26,21 +26,141 @@ function usePillActions(items, options = {}) {
|
|
|
26
26
|
function useHostActions(host) {
|
|
27
27
|
return useSyncExternalStore(host.store.subscribe, host.store.getActions, () => null);
|
|
28
28
|
}
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
29
|
+
/**
|
|
30
|
+
* A row of actions cut short (`data-wheel`) turns like a wheel: a mouse
|
|
31
|
+
* wheel, a drag, a swipe or the arrow keys bring the others in, each one
|
|
32
|
+
* snapping into place, and the ends that hide some fade out.
|
|
33
|
+
*/
|
|
34
|
+
function useActionsWheel(track) {
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const element = track.current;
|
|
37
|
+
if (!element) return;
|
|
38
|
+
const vertical = () => getComputedStyle(element).flexDirection.startsWith("column");
|
|
39
|
+
const cut = () => element.hasAttribute("data-wheel");
|
|
40
|
+
const ends = () => {
|
|
41
|
+
const along = vertical();
|
|
42
|
+
const position = Math.abs(along ? element.scrollTop : element.scrollLeft);
|
|
43
|
+
const room = along ? element.scrollHeight - element.clientHeight : element.scrollWidth - element.clientWidth;
|
|
44
|
+
element.toggleAttribute("data-more-start", cut() && position > 1);
|
|
45
|
+
element.toggleAttribute("data-more-end", cut() && position < room - 1);
|
|
46
|
+
};
|
|
47
|
+
const onWheel = (event) => {
|
|
48
|
+
if (!cut() || vertical()) return;
|
|
49
|
+
if (Math.abs(event.deltaY) <= Math.abs(event.deltaX)) return;
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
element.scrollBy({ left: event.deltaY });
|
|
52
|
+
};
|
|
53
|
+
let drag = null;
|
|
54
|
+
let swallowClick = false;
|
|
55
|
+
const onPointerDown = (event) => {
|
|
56
|
+
if (!cut() || event.pointerType !== "mouse" || event.button !== 0) return;
|
|
57
|
+
drag = {
|
|
58
|
+
x: event.clientX,
|
|
59
|
+
y: event.clientY,
|
|
60
|
+
start: vertical() ? element.scrollTop : element.scrollLeft,
|
|
61
|
+
moved: false
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
const onPointerMove = (event) => {
|
|
65
|
+
if (!drag) return;
|
|
66
|
+
const along = vertical();
|
|
67
|
+
const delta = along ? event.clientY - drag.y : event.clientX - drag.x;
|
|
68
|
+
if (!drag.moved && Math.abs(delta) < 6) return;
|
|
69
|
+
if (!drag.moved) {
|
|
70
|
+
drag.moved = true;
|
|
71
|
+
element.style.scrollSnapType = "none";
|
|
72
|
+
}
|
|
73
|
+
if (along) element.scrollTop = drag.start - delta;
|
|
74
|
+
else element.scrollLeft = drag.start - delta;
|
|
75
|
+
};
|
|
76
|
+
const onPointerUp = () => {
|
|
77
|
+
if (!drag) return;
|
|
78
|
+
if (drag.moved) {
|
|
79
|
+
swallowClick = true;
|
|
80
|
+
element.style.removeProperty("scroll-snap-type");
|
|
81
|
+
setTimeout(() => swallowClick = false, 0);
|
|
82
|
+
}
|
|
83
|
+
drag = null;
|
|
84
|
+
};
|
|
85
|
+
const onClick = (event) => {
|
|
86
|
+
if (!swallowClick) return;
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
event.stopPropagation();
|
|
89
|
+
swallowClick = false;
|
|
90
|
+
};
|
|
91
|
+
const onKeyDown = (event) => {
|
|
92
|
+
if (!cut()) return;
|
|
93
|
+
const along = vertical();
|
|
94
|
+
const rtl = getComputedStyle(element).direction === "rtl";
|
|
95
|
+
const next = along ? "ArrowDown" : rtl ? "ArrowLeft" : "ArrowRight";
|
|
96
|
+
const previous = along ? "ArrowUp" : rtl ? "ArrowRight" : "ArrowLeft";
|
|
97
|
+
if (event.key !== next && event.key !== previous) return;
|
|
98
|
+
const actions = [...element.children];
|
|
99
|
+
const index = actions.findIndex((action) => action.contains(document.activeElement));
|
|
100
|
+
if (index < 0) return;
|
|
101
|
+
const target = actions[index + (event.key === next ? 1 : -1)];
|
|
102
|
+
const focusable = target?.matches("a, button") ? target : target?.querySelector("a, button");
|
|
103
|
+
if (!focusable) return;
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
focusable.focus({ preventScroll: true });
|
|
106
|
+
target.scrollIntoView({
|
|
107
|
+
block: "nearest",
|
|
108
|
+
inline: "nearest",
|
|
109
|
+
behavior: "smooth"
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const observer = typeof MutationObserver === "undefined" ? void 0 : new MutationObserver(ends);
|
|
113
|
+
observer?.observe(element, {
|
|
114
|
+
attributes: true,
|
|
115
|
+
attributeFilter: ["data-wheel", "style"]
|
|
116
|
+
});
|
|
117
|
+
element.addEventListener("scroll", ends, { passive: true });
|
|
118
|
+
element.addEventListener("wheel", onWheel, { passive: false });
|
|
119
|
+
element.addEventListener("pointerdown", onPointerDown);
|
|
120
|
+
window.addEventListener("pointermove", onPointerMove);
|
|
121
|
+
window.addEventListener("pointerup", onPointerUp);
|
|
122
|
+
element.addEventListener("click", onClick, true);
|
|
123
|
+
element.addEventListener("keydown", onKeyDown);
|
|
124
|
+
ends();
|
|
125
|
+
return () => {
|
|
126
|
+
observer?.disconnect();
|
|
127
|
+
element.removeEventListener("scroll", ends);
|
|
128
|
+
element.removeEventListener("wheel", onWheel);
|
|
129
|
+
element.removeEventListener("pointerdown", onPointerDown);
|
|
130
|
+
window.removeEventListener("pointermove", onPointerMove);
|
|
131
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
132
|
+
element.removeEventListener("click", onClick, true);
|
|
133
|
+
element.removeEventListener("keydown", onKeyDown);
|
|
134
|
+
};
|
|
135
|
+
}, [track]);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The actions themselves, as the pill's own: their label on hover and focus,
|
|
139
|
+
* a link or a button. `wheel`: cut short to that length, in px, turning to
|
|
140
|
+
* show the others.
|
|
141
|
+
*/
|
|
142
|
+
function ActionList({ items, host, wheel, inside }) {
|
|
143
|
+
const track = useRef(null);
|
|
144
|
+
useActionsWheel(track);
|
|
145
|
+
return /* @__PURE__ */ jsx(PillActions, {
|
|
146
|
+
ref: track,
|
|
147
|
+
"data-inside": inside ? "" : void 0,
|
|
148
|
+
"data-wheel": wheel !== void 0 ? "" : void 0,
|
|
149
|
+
style: wheel !== void 0 ? { "--_mp-wheel-length": `${wheel}px` } : void 0,
|
|
150
|
+
children: items.map((item) => item.href !== void 0 ? /* @__PURE__ */ jsx(PillAction, {
|
|
151
|
+
icon: item.icon,
|
|
152
|
+
label: item.label,
|
|
153
|
+
expanded: item.expanded,
|
|
154
|
+
href: item.href,
|
|
155
|
+
linkComponent: host.linkComponent,
|
|
156
|
+
onClick: item.onClick
|
|
157
|
+
}, item.id ?? item.label) : /* @__PURE__ */ jsx(PillAction, {
|
|
158
|
+
icon: item.icon,
|
|
159
|
+
label: item.label,
|
|
160
|
+
expanded: item.expanded,
|
|
161
|
+
onClick: item.onClick
|
|
162
|
+
}, item.id ?? item.label))
|
|
163
|
+
});
|
|
44
164
|
}
|
|
45
165
|
/** In the pill itself (`actionsStyle="inside"`): the actions, then a divider (the other way round on the end side). */
|
|
46
166
|
function InsideActions({ host }) {
|
|
@@ -48,9 +168,10 @@ function InsideActions({ host }) {
|
|
|
48
168
|
if (!items) return null;
|
|
49
169
|
const list = /* @__PURE__ */ jsx(ActionList, {
|
|
50
170
|
items,
|
|
51
|
-
host
|
|
171
|
+
host,
|
|
172
|
+
inside: true
|
|
52
173
|
});
|
|
53
174
|
return host.actionsSide === "end" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(PillDivider, {}), list] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [list, /* @__PURE__ */ jsx(PillDivider, {})] });
|
|
54
175
|
}
|
|
55
176
|
|
|
56
|
-
export { ActionList, InsideActions, useHostActions, usePillActions };
|
|
177
|
+
export { ActionList, InsideActions, useActionsWheel, useHostActions, usePillActions };
|
|
@@ -77,7 +77,6 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
77
77
|
const orbit = (0, react.useRef)(null);
|
|
78
78
|
const settings = (0, react.useRef)(null);
|
|
79
79
|
const pills = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
80
|
-
const was = (0, react.useRef)([]);
|
|
81
80
|
const timers = (0, react.useRef)([]);
|
|
82
81
|
const labelRef = (0, react.useRef)(null);
|
|
83
82
|
const focusFirst = (0, react.useRef)(false);
|
|
@@ -87,18 +86,13 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
87
86
|
timers.current.forEach(clearTimeout);
|
|
88
87
|
timers.current = [];
|
|
89
88
|
};
|
|
90
|
-
const showAt = (index, value) => setShown((current) => {
|
|
91
|
-
const next = [...current];
|
|
92
|
-
next[index] = value;
|
|
93
|
-
return next;
|
|
94
|
-
});
|
|
95
89
|
const plan = () => {
|
|
96
90
|
const element = getElement();
|
|
97
91
|
const root = host.rootRef.current;
|
|
98
92
|
if (!element || !root) return null;
|
|
99
93
|
const read = readSettings(element);
|
|
100
94
|
settings.current = read;
|
|
101
|
-
const obstacles = [root, ...document.querySelectorAll("[data-mp=\"pill\"][data-satellite=\"electron\"]")].filter((other) => other !== element && other.dataset.presence !== "hidden").map((other) => other.getBoundingClientRect());
|
|
95
|
+
const obstacles = [root, ...document.querySelectorAll("[data-mp=\"pill\"]:is([data-satellite=\"electron\"], [data-satellite=\"actions\"])")].filter((other) => other !== element && other.dataset.presence !== "hidden").map((other) => other.getBoundingClientRect());
|
|
102
96
|
orbit.current = require_orbits.planOrbit({
|
|
103
97
|
electron: element.getBoundingClientRect(),
|
|
104
98
|
count: items.length,
|
|
@@ -127,11 +121,11 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
127
121
|
if (current.wheel) {
|
|
128
122
|
pill.style.opacity = String(spot.shown);
|
|
129
123
|
pill.style.scale = String((.6 + .4 * spot.shown) * (api.current.hot === index ? 1.12 : 1));
|
|
130
|
-
pill.style.pointerEvents = spot.shown < .5 ? "none" : "auto";
|
|
124
|
+
pill.style.pointerEvents = spot.shown < .5 || closing.current ? "none" : "auto";
|
|
131
125
|
} else {
|
|
132
126
|
pill.style.removeProperty("opacity");
|
|
133
127
|
pill.style.removeProperty("scale");
|
|
134
|
-
pill.style.pointerEvents = "auto";
|
|
128
|
+
pill.style.pointerEvents = closing.current ? "none" : "auto";
|
|
135
129
|
}
|
|
136
130
|
});
|
|
137
131
|
placeLabel();
|
|
@@ -170,31 +164,59 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
170
164
|
snapping.current = requestAnimationFrame(step);
|
|
171
165
|
};
|
|
172
166
|
const snap = () => turnTo(Math.round(turn.current), true);
|
|
167
|
+
const motion = (0, react.useRef)(() => {});
|
|
168
|
+
const opening = (0, react.useRef)(false);
|
|
169
|
+
const closing = (0, react.useRef)(false);
|
|
170
|
+
/** The orbitals that show, each with its delay: one after the other along the arc (or the other way round). */
|
|
171
|
+
const sequence = (reverse, stagger) => {
|
|
172
|
+
const current = orbit.current;
|
|
173
|
+
const shownOnes = items.map((_, index) => ({
|
|
174
|
+
index,
|
|
175
|
+
shown: current ? require_orbits.spotOn(current, index, turn.current).shown : 1
|
|
176
|
+
})).filter(({ shown }) => shown > 0);
|
|
177
|
+
return shownOnes.map(({ index, shown }, rank) => ({
|
|
178
|
+
element: pills.current.get(index),
|
|
179
|
+
shown,
|
|
180
|
+
delay: (reverse ? shownOnes.length - 1 - rank : rank) * stagger
|
|
181
|
+
})).filter(({ element }) => element);
|
|
182
|
+
};
|
|
173
183
|
const open = (how) => {
|
|
174
184
|
if (items.length === 0 || !out) return;
|
|
175
185
|
window.dispatchEvent(new CustomEvent(OPENED, { detail: electron.id }));
|
|
176
186
|
clearTimers();
|
|
177
|
-
|
|
178
|
-
if (!
|
|
187
|
+
motion.current();
|
|
188
|
+
if (!plan()) return;
|
|
179
189
|
focusFirst.current = how === "key";
|
|
180
190
|
turn.current = 0;
|
|
191
|
+
opening.current = true;
|
|
192
|
+
closing.current = false;
|
|
181
193
|
setHot(-1);
|
|
182
194
|
setRing({ how });
|
|
183
|
-
items.
|
|
195
|
+
setShown(items.map(() => true));
|
|
184
196
|
};
|
|
185
197
|
const close = (quick = false) => {
|
|
186
198
|
if (!ring) return;
|
|
187
199
|
clearTimers();
|
|
188
200
|
setHot(-1);
|
|
189
|
-
|
|
190
|
-
const
|
|
201
|
+
closing.current = true;
|
|
202
|
+
for (const pill of pills.current.values()) pill.style.pointerEvents = "none";
|
|
203
|
+
const element = getElement();
|
|
204
|
+
const first = pills.current.get(0);
|
|
205
|
+
const { fade, exit } = first ? require_measure.durations(first) : {
|
|
191
206
|
fade: 150,
|
|
192
207
|
exit: 300
|
|
193
208
|
};
|
|
209
|
+
const duration = quick ? fade + 100 : exit * .8;
|
|
194
210
|
const stagger = quick ? 0 : (settings.current?.stagger ?? 30) * .6;
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
211
|
+
const steps = sequence(true, stagger);
|
|
212
|
+
motion.current();
|
|
213
|
+
if (element) motion.current = require_goo.playOrbit(element, steps, "close", { duration });
|
|
214
|
+
const longest = Math.max(0, ...steps.map(({ delay }) => delay)) + duration;
|
|
215
|
+
timers.current.push(setTimeout(() => {
|
|
216
|
+
setRing(null);
|
|
217
|
+
setShown([]);
|
|
218
|
+
closing.current = false;
|
|
219
|
+
}, longest + 30));
|
|
198
220
|
};
|
|
199
221
|
const api = (0, react.useRef)({
|
|
200
222
|
open,
|
|
@@ -232,6 +254,20 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
232
254
|
const onPointerDown = (event) => {
|
|
233
255
|
if (event.button !== 0) return;
|
|
234
256
|
clearTimeout(hoverTimer);
|
|
257
|
+
if (api.current.ring) {
|
|
258
|
+
press = {
|
|
259
|
+
x: event.clientX,
|
|
260
|
+
y: event.clientY,
|
|
261
|
+
opened: true,
|
|
262
|
+
moved: false,
|
|
263
|
+
already: true,
|
|
264
|
+
timer: setTimeout(() => {}, 0)
|
|
265
|
+
};
|
|
266
|
+
try {
|
|
267
|
+
link.setPointerCapture(event.pointerId);
|
|
268
|
+
} catch {}
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
235
271
|
const longPress = settings.current?.longPress ?? readSettings(getElement()).longPress;
|
|
236
272
|
press = {
|
|
237
273
|
x: event.clientX,
|
|
@@ -250,18 +286,19 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
250
286
|
};
|
|
251
287
|
const onPointerMove = (event) => {
|
|
252
288
|
if (!press) return;
|
|
253
|
-
if (
|
|
289
|
+
if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > 12) {
|
|
290
|
+
if (!press.opened) clearTimeout(press.timer);
|
|
254
291
|
press.moved = true;
|
|
255
|
-
clearTimeout(press.timer);
|
|
256
292
|
}
|
|
257
293
|
if (press.opened) hotAt(event);
|
|
258
294
|
};
|
|
259
295
|
const onPointerUp = () => {
|
|
260
296
|
if (!press) return;
|
|
261
297
|
clearTimeout(press.timer);
|
|
262
|
-
const { opened } = press;
|
|
298
|
+
const { opened, already, moved } = press;
|
|
263
299
|
press = null;
|
|
264
300
|
if (!opened) return;
|
|
301
|
+
if (already && !moved && api.current.hot < 0) return;
|
|
265
302
|
swallowClick = true;
|
|
266
303
|
const { hot: index } = api.current;
|
|
267
304
|
if (index >= 0) pills.current.get(index)?.querySelector("[data-mp=\"orbital\"]")?.click();
|
|
@@ -441,34 +478,19 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
441
478
|
const element = getElement();
|
|
442
479
|
if (!ring || !element || !orbit.current) return;
|
|
443
480
|
applyTurn();
|
|
444
|
-
items.
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
delay: 0,
|
|
451
|
-
duration: require_measure.durations(pill).enter
|
|
452
|
-
});
|
|
453
|
-
if (!now && was.current[index] && onArc) {
|
|
454
|
-
const { fade, exit } = require_measure.durations(pill);
|
|
455
|
-
require_goo.playSplit(element, pill, "join", {
|
|
456
|
-
delay: fade,
|
|
457
|
-
duration: exit
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
was.current[index] = now;
|
|
461
|
-
});
|
|
481
|
+
if (opening.current && pills.current.size >= items.length) {
|
|
482
|
+
opening.current = false;
|
|
483
|
+
const first = pills.current.get(0);
|
|
484
|
+
const duration = (first ? require_measure.durations(first).enter : 500) * .8;
|
|
485
|
+
motion.current = require_goo.playOrbit(element, sequence(false, settings.current?.stagger ?? 30), "open", { duration });
|
|
486
|
+
}
|
|
462
487
|
if (focusFirst.current && shown[0]) {
|
|
463
488
|
focusFirst.current = false;
|
|
464
489
|
pills.current.get(0)?.querySelector("[data-mp=\"orbital\"]")?.focus();
|
|
465
490
|
}
|
|
466
491
|
});
|
|
467
492
|
(0, react.useEffect)(() => {
|
|
468
|
-
if (!ring)
|
|
469
|
-
was.current = [];
|
|
470
|
-
turn.current = 0;
|
|
471
|
-
}
|
|
493
|
+
if (!ring) turn.current = 0;
|
|
472
494
|
}, [ring]);
|
|
473
495
|
if (!ring || items.length === 0) return null;
|
|
474
496
|
const run = (item) => (event) => {
|
|
@@ -529,7 +551,10 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
529
551
|
"data-index": index,
|
|
530
552
|
"data-hot": hot === index ? "" : void 0,
|
|
531
553
|
style: ORBITAL_STYLE,
|
|
532
|
-
onPointerEnter: () =>
|
|
554
|
+
onPointerEnter: (event) => {
|
|
555
|
+
const moving = event.currentTarget.getAnimations?.().some((animation) => animation.id === "mp-split" && animation.playState === "running");
|
|
556
|
+
if (!closing.current && !moving) setHot(index);
|
|
557
|
+
},
|
|
533
558
|
onPointerLeave: () => setHot(-1),
|
|
534
559
|
children: item.href !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Link, {
|
|
535
560
|
href: item.href,
|
|
@@ -541,10 +566,16 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
541
566
|
children: item.icon
|
|
542
567
|
})
|
|
543
568
|
}, item.id ?? index);
|
|
544
|
-
}), host.orbitalLabels && hot >= 0 && items[hot] && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
569
|
+
}), host.orbitalLabels && hot >= 0 && items[hot] && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Pill, {
|
|
545
570
|
ref: labelRef,
|
|
546
|
-
|
|
571
|
+
placement: "inline",
|
|
572
|
+
ladder: false,
|
|
573
|
+
moveThroughCircle: false,
|
|
574
|
+
theme: host.theme,
|
|
575
|
+
variant: electron.input.variant ?? host.variant,
|
|
576
|
+
presence: "compact",
|
|
547
577
|
"aria-hidden": "true",
|
|
578
|
+
"data-satellite": "orbital-label",
|
|
548
579
|
style: LABEL_STYLE,
|
|
549
580
|
children: items[hot].label
|
|
550
581
|
})]
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import Pill from "../Pill/Pill.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { SPLIT, playOrbit } from "../Pill/goo.mjs";
|
|
6
6
|
import { useIsomorphicLayoutEffect } from "../utils/react.mjs";
|
|
7
7
|
import { parseDuration } from "../utils/timing.mjs";
|
|
8
8
|
import { durations, toPixels } from "./measure.mjs";
|
|
@@ -77,7 +77,6 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
77
77
|
const orbit = useRef(null);
|
|
78
78
|
const settings = useRef(null);
|
|
79
79
|
const pills = useRef(/* @__PURE__ */ new Map());
|
|
80
|
-
const was = useRef([]);
|
|
81
80
|
const timers = useRef([]);
|
|
82
81
|
const labelRef = useRef(null);
|
|
83
82
|
const focusFirst = useRef(false);
|
|
@@ -87,18 +86,13 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
87
86
|
timers.current.forEach(clearTimeout);
|
|
88
87
|
timers.current = [];
|
|
89
88
|
};
|
|
90
|
-
const showAt = (index, value) => setShown((current) => {
|
|
91
|
-
const next = [...current];
|
|
92
|
-
next[index] = value;
|
|
93
|
-
return next;
|
|
94
|
-
});
|
|
95
89
|
const plan = () => {
|
|
96
90
|
const element = getElement();
|
|
97
91
|
const root = host.rootRef.current;
|
|
98
92
|
if (!element || !root) return null;
|
|
99
93
|
const read = readSettings(element);
|
|
100
94
|
settings.current = read;
|
|
101
|
-
const obstacles = [root, ...document.querySelectorAll("[data-mp=\"pill\"][data-satellite=\"electron\"]")].filter((other) => other !== element && other.dataset.presence !== "hidden").map((other) => other.getBoundingClientRect());
|
|
95
|
+
const obstacles = [root, ...document.querySelectorAll("[data-mp=\"pill\"]:is([data-satellite=\"electron\"], [data-satellite=\"actions\"])")].filter((other) => other !== element && other.dataset.presence !== "hidden").map((other) => other.getBoundingClientRect());
|
|
102
96
|
orbit.current = planOrbit({
|
|
103
97
|
electron: element.getBoundingClientRect(),
|
|
104
98
|
count: items.length,
|
|
@@ -127,11 +121,11 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
127
121
|
if (current.wheel) {
|
|
128
122
|
pill.style.opacity = String(spot.shown);
|
|
129
123
|
pill.style.scale = String((.6 + .4 * spot.shown) * (api.current.hot === index ? 1.12 : 1));
|
|
130
|
-
pill.style.pointerEvents = spot.shown < .5 ? "none" : "auto";
|
|
124
|
+
pill.style.pointerEvents = spot.shown < .5 || closing.current ? "none" : "auto";
|
|
131
125
|
} else {
|
|
132
126
|
pill.style.removeProperty("opacity");
|
|
133
127
|
pill.style.removeProperty("scale");
|
|
134
|
-
pill.style.pointerEvents = "auto";
|
|
128
|
+
pill.style.pointerEvents = closing.current ? "none" : "auto";
|
|
135
129
|
}
|
|
136
130
|
});
|
|
137
131
|
placeLabel();
|
|
@@ -170,31 +164,59 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
170
164
|
snapping.current = requestAnimationFrame(step);
|
|
171
165
|
};
|
|
172
166
|
const snap = () => turnTo(Math.round(turn.current), true);
|
|
167
|
+
const motion = useRef(() => {});
|
|
168
|
+
const opening = useRef(false);
|
|
169
|
+
const closing = useRef(false);
|
|
170
|
+
/** The orbitals that show, each with its delay: one after the other along the arc (or the other way round). */
|
|
171
|
+
const sequence = (reverse, stagger) => {
|
|
172
|
+
const current = orbit.current;
|
|
173
|
+
const shownOnes = items.map((_, index) => ({
|
|
174
|
+
index,
|
|
175
|
+
shown: current ? spotOn(current, index, turn.current).shown : 1
|
|
176
|
+
})).filter(({ shown }) => shown > 0);
|
|
177
|
+
return shownOnes.map(({ index, shown }, rank) => ({
|
|
178
|
+
element: pills.current.get(index),
|
|
179
|
+
shown,
|
|
180
|
+
delay: (reverse ? shownOnes.length - 1 - rank : rank) * stagger
|
|
181
|
+
})).filter(({ element }) => element);
|
|
182
|
+
};
|
|
173
183
|
const open = (how) => {
|
|
174
184
|
if (items.length === 0 || !out) return;
|
|
175
185
|
window.dispatchEvent(new CustomEvent(OPENED, { detail: electron.id }));
|
|
176
186
|
clearTimers();
|
|
177
|
-
|
|
178
|
-
if (!
|
|
187
|
+
motion.current();
|
|
188
|
+
if (!plan()) return;
|
|
179
189
|
focusFirst.current = how === "key";
|
|
180
190
|
turn.current = 0;
|
|
191
|
+
opening.current = true;
|
|
192
|
+
closing.current = false;
|
|
181
193
|
setHot(-1);
|
|
182
194
|
setRing({ how });
|
|
183
|
-
items.
|
|
195
|
+
setShown(items.map(() => true));
|
|
184
196
|
};
|
|
185
197
|
const close = (quick = false) => {
|
|
186
198
|
if (!ring) return;
|
|
187
199
|
clearTimers();
|
|
188
200
|
setHot(-1);
|
|
189
|
-
|
|
190
|
-
const
|
|
201
|
+
closing.current = true;
|
|
202
|
+
for (const pill of pills.current.values()) pill.style.pointerEvents = "none";
|
|
203
|
+
const element = getElement();
|
|
204
|
+
const first = pills.current.get(0);
|
|
205
|
+
const { fade, exit } = first ? durations(first) : {
|
|
191
206
|
fade: 150,
|
|
192
207
|
exit: 300
|
|
193
208
|
};
|
|
209
|
+
const duration = quick ? fade + 100 : exit * .8;
|
|
194
210
|
const stagger = quick ? 0 : (settings.current?.stagger ?? 30) * .6;
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
211
|
+
const steps = sequence(true, stagger);
|
|
212
|
+
motion.current();
|
|
213
|
+
if (element) motion.current = playOrbit(element, steps, "close", { duration });
|
|
214
|
+
const longest = Math.max(0, ...steps.map(({ delay }) => delay)) + duration;
|
|
215
|
+
timers.current.push(setTimeout(() => {
|
|
216
|
+
setRing(null);
|
|
217
|
+
setShown([]);
|
|
218
|
+
closing.current = false;
|
|
219
|
+
}, longest + 30));
|
|
198
220
|
};
|
|
199
221
|
const api = useRef({
|
|
200
222
|
open,
|
|
@@ -232,6 +254,20 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
232
254
|
const onPointerDown = (event) => {
|
|
233
255
|
if (event.button !== 0) return;
|
|
234
256
|
clearTimeout(hoverTimer);
|
|
257
|
+
if (api.current.ring) {
|
|
258
|
+
press = {
|
|
259
|
+
x: event.clientX,
|
|
260
|
+
y: event.clientY,
|
|
261
|
+
opened: true,
|
|
262
|
+
moved: false,
|
|
263
|
+
already: true,
|
|
264
|
+
timer: setTimeout(() => {}, 0)
|
|
265
|
+
};
|
|
266
|
+
try {
|
|
267
|
+
link.setPointerCapture(event.pointerId);
|
|
268
|
+
} catch {}
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
235
271
|
const longPress = settings.current?.longPress ?? readSettings(getElement()).longPress;
|
|
236
272
|
press = {
|
|
237
273
|
x: event.clientX,
|
|
@@ -250,18 +286,19 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
250
286
|
};
|
|
251
287
|
const onPointerMove = (event) => {
|
|
252
288
|
if (!press) return;
|
|
253
|
-
if (
|
|
289
|
+
if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > 12) {
|
|
290
|
+
if (!press.opened) clearTimeout(press.timer);
|
|
254
291
|
press.moved = true;
|
|
255
|
-
clearTimeout(press.timer);
|
|
256
292
|
}
|
|
257
293
|
if (press.opened) hotAt(event);
|
|
258
294
|
};
|
|
259
295
|
const onPointerUp = () => {
|
|
260
296
|
if (!press) return;
|
|
261
297
|
clearTimeout(press.timer);
|
|
262
|
-
const { opened } = press;
|
|
298
|
+
const { opened, already, moved } = press;
|
|
263
299
|
press = null;
|
|
264
300
|
if (!opened) return;
|
|
301
|
+
if (already && !moved && api.current.hot < 0) return;
|
|
265
302
|
swallowClick = true;
|
|
266
303
|
const { hot: index } = api.current;
|
|
267
304
|
if (index >= 0) pills.current.get(index)?.querySelector("[data-mp=\"orbital\"]")?.click();
|
|
@@ -441,34 +478,19 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
441
478
|
const element = getElement();
|
|
442
479
|
if (!ring || !element || !orbit.current) return;
|
|
443
480
|
applyTurn();
|
|
444
|
-
items.
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
delay: 0,
|
|
451
|
-
duration: durations(pill).enter
|
|
452
|
-
});
|
|
453
|
-
if (!now && was.current[index] && onArc) {
|
|
454
|
-
const { fade, exit } = durations(pill);
|
|
455
|
-
playSplit(element, pill, "join", {
|
|
456
|
-
delay: fade,
|
|
457
|
-
duration: exit
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
was.current[index] = now;
|
|
461
|
-
});
|
|
481
|
+
if (opening.current && pills.current.size >= items.length) {
|
|
482
|
+
opening.current = false;
|
|
483
|
+
const first = pills.current.get(0);
|
|
484
|
+
const duration = (first ? durations(first).enter : 500) * .8;
|
|
485
|
+
motion.current = playOrbit(element, sequence(false, settings.current?.stagger ?? 30), "open", { duration });
|
|
486
|
+
}
|
|
462
487
|
if (focusFirst.current && shown[0]) {
|
|
463
488
|
focusFirst.current = false;
|
|
464
489
|
pills.current.get(0)?.querySelector("[data-mp=\"orbital\"]")?.focus();
|
|
465
490
|
}
|
|
466
491
|
});
|
|
467
492
|
useEffect(() => {
|
|
468
|
-
if (!ring)
|
|
469
|
-
was.current = [];
|
|
470
|
-
turn.current = 0;
|
|
471
|
-
}
|
|
493
|
+
if (!ring) turn.current = 0;
|
|
472
494
|
}, [ring]);
|
|
473
495
|
if (!ring || items.length === 0) return null;
|
|
474
496
|
const run = (item) => (event) => {
|
|
@@ -529,7 +551,10 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
529
551
|
"data-index": index,
|
|
530
552
|
"data-hot": hot === index ? "" : void 0,
|
|
531
553
|
style: ORBITAL_STYLE,
|
|
532
|
-
onPointerEnter: () =>
|
|
554
|
+
onPointerEnter: (event) => {
|
|
555
|
+
const moving = event.currentTarget.getAnimations?.().some((animation) => animation.id === "mp-split" && animation.playState === "running");
|
|
556
|
+
if (!closing.current && !moving) setHot(index);
|
|
557
|
+
},
|
|
533
558
|
onPointerLeave: () => setHot(-1),
|
|
534
559
|
children: item.href !== void 0 ? /* @__PURE__ */ jsx(Link, {
|
|
535
560
|
href: item.href,
|
|
@@ -541,10 +566,16 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
541
566
|
children: item.icon
|
|
542
567
|
})
|
|
543
568
|
}, item.id ?? index);
|
|
544
|
-
}), host.orbitalLabels && hot >= 0 && items[hot] && /* @__PURE__ */ jsx(
|
|
569
|
+
}), host.orbitalLabels && hot >= 0 && items[hot] && /* @__PURE__ */ jsx(Pill, {
|
|
545
570
|
ref: labelRef,
|
|
546
|
-
|
|
571
|
+
placement: "inline",
|
|
572
|
+
ladder: false,
|
|
573
|
+
moveThroughCircle: false,
|
|
574
|
+
theme: host.theme,
|
|
575
|
+
variant: electron.input.variant ?? host.variant,
|
|
576
|
+
presence: "compact",
|
|
547
577
|
"aria-hidden": "true",
|
|
578
|
+
"data-satellite": "orbital-label",
|
|
548
579
|
style: LABEL_STYLE,
|
|
549
580
|
children: items[hot].label
|
|
550
581
|
})]
|