magic-pill 9.4.0-next.3 → 9.4.0-next.4
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 +26 -0
- package/README.md +10 -7
- package/dist/MagicPill/MagicPill.d.mts +2 -1
- package/dist/MagicPill/MagicPill.d.ts +2 -1
- package/dist/MagicPill/MagicPill.js +10 -3
- package/dist/MagicPill/MagicPill.mjs +10 -3
- package/dist/Pill/Pill.js +1 -0
- package/dist/Pill/Pill.mjs +1 -0
- package/dist/Pill/goo.js +60 -28
- package/dist/Pill/goo.mjs +60 -28
- package/dist/Pill/modal.js +3 -1
- package/dist/Pill/modal.mjs +3 -1
- package/dist/Pill/morph.js +56 -2
- package/dist/Pill/morph.mjs +56 -3
- package/dist/PillForm/PillForm.js +6 -1
- package/dist/PillForm/PillForm.mjs +7 -2
- package/dist/PillForm/dates.js +14 -3
- package/dist/PillForm/dates.mjs +14 -3
- package/dist/PillForm/room.js +46 -0
- package/dist/PillForm/room.mjs +46 -0
- package/dist/PillNavbar/PillNavbar.js +3 -1
- package/dist/PillNavbar/PillNavbar.mjs +4 -2
- package/dist/PillNavbar/room.js +65 -11
- package/dist/PillNavbar/room.mjs +65 -12
- package/dist/PillNotification/PillNotification.js +2 -4
- package/dist/PillNotification/PillNotification.mjs +2 -4
- package/dist/PillNotification/RowsBody.js +77 -0
- package/dist/PillNotification/RowsBody.mjs +77 -0
- package/dist/forms.css +14 -0
- package/dist/satellites/Actions.js +181 -6
- package/dist/satellites/Actions.mjs +182 -7
- package/dist/satellites/Orbitals.js +67 -17
- package/dist/satellites/Orbitals.mjs +69 -19
- package/dist/satellites/Satellites.js +197 -84
- package/dist/satellites/Satellites.mjs +198 -86
- package/dist/satellites/handoff.js +36 -0
- package/dist/satellites/handoff.mjs +34 -0
- package/dist/satellites/measure.js +22 -0
- package/dist/satellites/measure.mjs +22 -1
- package/dist/satellites/orbits.js +12 -0
- package/dist/satellites/orbits.mjs +12 -1
- package/dist/satellites/types.d.mts +7 -1
- package/dist/satellites/types.d.ts +7 -1
- package/dist/styles.css +78 -15
- package/package.json +1 -1
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { useEffect, useRef, useSyncExternalStore } from "react";
|
|
3
|
+
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { readMorphTimings } from "../Pill/morph.mjs";
|
|
4
5
|
import PillAction from "../Pill/PillAction.mjs";
|
|
5
6
|
import { PillActions, PillDivider } from "../Pill/parts.mjs";
|
|
6
7
|
import { getStore } from "../store/store.mjs";
|
|
8
|
+
import { useIsomorphicLayoutEffect } from "../utils/react.mjs";
|
|
9
|
+
import { prefersReducedMotion } from "../utils/timing.mjs";
|
|
10
|
+
import { getHandoff, setHandoff, useHandoff } from "./handoff.mjs";
|
|
7
11
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
12
|
|
|
9
13
|
// src/satellites/Actions.tsx
|
|
@@ -139,12 +143,13 @@ function useActionsWheel(track) {
|
|
|
139
143
|
* a link or a button. `wheel`: cut short to that length, in px, turning to
|
|
140
144
|
* show the others.
|
|
141
145
|
*/
|
|
142
|
-
function ActionList({ items, host, wheel, inside }) {
|
|
146
|
+
function ActionList({ items, host, wheel, inside, leaving }) {
|
|
143
147
|
const track = useRef(null);
|
|
144
148
|
useActionsWheel(track);
|
|
145
149
|
return /* @__PURE__ */ jsx(PillActions, {
|
|
146
150
|
ref: track,
|
|
147
151
|
"data-inside": inside ? "" : void 0,
|
|
152
|
+
"data-leaving": leaving ? "" : void 0,
|
|
148
153
|
"data-wheel": wheel !== void 0 ? "" : void 0,
|
|
149
154
|
style: wheel !== void 0 ? { "--_mp-wheel-length": `${wheel}px` } : void 0,
|
|
150
155
|
children: items.map((item) => item.href !== void 0 ? /* @__PURE__ */ jsx(PillAction, {
|
|
@@ -162,16 +167,186 @@ function ActionList({ items, host, wheel, inside }) {
|
|
|
162
167
|
}, item.id ?? item.label))
|
|
163
168
|
});
|
|
164
169
|
}
|
|
165
|
-
/**
|
|
170
|
+
/** The actions in the pill opening or folding away (playInside), or held closed until they open */
|
|
171
|
+
const INSIDE = "mp-inside-actions";
|
|
172
|
+
/** Their row and its divider with nothing of them left: no length, no gap on either side of the divider */
|
|
173
|
+
function closedFrames(pill) {
|
|
174
|
+
const vertical = pill.dataset.orientation === "vertical";
|
|
175
|
+
const size = vertical ? "height" : "width";
|
|
176
|
+
const [start, end] = vertical ? ["marginBlockStart", "marginBlockEnd"] : ["marginInlineStart", "marginInlineEnd"];
|
|
177
|
+
const style = getComputedStyle(pill);
|
|
178
|
+
const gap = Number.parseFloat(vertical ? style.rowGap : style.columnGap) || 0;
|
|
179
|
+
return {
|
|
180
|
+
size,
|
|
181
|
+
start,
|
|
182
|
+
end,
|
|
183
|
+
list: {
|
|
184
|
+
opacity: 0,
|
|
185
|
+
[size]: "0px"
|
|
186
|
+
},
|
|
187
|
+
divider: {
|
|
188
|
+
opacity: 0,
|
|
189
|
+
[size]: "0px",
|
|
190
|
+
[start]: `${-gap}px`,
|
|
191
|
+
[end]: `${-gap}px`
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The actions in the pill opening out of nothing as they come (their row growing, then showing), or
|
|
197
|
+
* folding back into nothing before they go: the pill follows its content at each frame, and the
|
|
198
|
+
* satellites follow the pill. Their divider and its gaps go with them. Undefined: no motion.
|
|
199
|
+
*/
|
|
200
|
+
function playInside(list, divider, kind) {
|
|
201
|
+
const pill = list.closest("[data-mp=\"pill\"]");
|
|
202
|
+
if (!pill || typeof list.animate !== "function" || prefersReducedMotion()) return void 0;
|
|
203
|
+
const { fade, change } = readMorphTimings(pill);
|
|
204
|
+
if (fade + change <= 0) return void 0;
|
|
205
|
+
const closed = closedFrames(pill);
|
|
206
|
+
const { size, start, end } = closed;
|
|
207
|
+
const vertical = size === "height";
|
|
208
|
+
const length = vertical ? list.offsetHeight : list.offsetWidth;
|
|
209
|
+
const thickness = vertical ? divider.offsetHeight : divider.offsetWidth;
|
|
210
|
+
const grown = {
|
|
211
|
+
list: { [size]: `${length}px` },
|
|
212
|
+
divider: {
|
|
213
|
+
[size]: `${thickness}px`,
|
|
214
|
+
[start]: "0px",
|
|
215
|
+
[end]: "0px"
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
const frames = (part) => kind === "in" ? [
|
|
219
|
+
closed[part],
|
|
220
|
+
{
|
|
221
|
+
...grown[part],
|
|
222
|
+
opacity: 0,
|
|
223
|
+
offset: change / (fade + change)
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
...grown[part],
|
|
227
|
+
opacity: 1
|
|
228
|
+
}
|
|
229
|
+
] : [
|
|
230
|
+
{
|
|
231
|
+
...grown[part],
|
|
232
|
+
opacity: 1
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
...grown[part],
|
|
236
|
+
opacity: 0,
|
|
237
|
+
offset: fade / (fade + change)
|
|
238
|
+
},
|
|
239
|
+
closed[part]
|
|
240
|
+
];
|
|
241
|
+
const options = {
|
|
242
|
+
id: INSIDE,
|
|
243
|
+
duration: fade + change,
|
|
244
|
+
easing: "ease-in-out",
|
|
245
|
+
fill: kind === "out" ? "forwards" : "none"
|
|
246
|
+
};
|
|
247
|
+
list.style.overflow = "clip";
|
|
248
|
+
const animation = list.animate(frames("list"), options);
|
|
249
|
+
divider.animate(frames("divider"), options);
|
|
250
|
+
const done = () => list.style.removeProperty("overflow");
|
|
251
|
+
animation.finished.then(done, done);
|
|
252
|
+
return animation;
|
|
253
|
+
}
|
|
254
|
+
/** Stops their motion (an opening, a fold, the hold before they open) */
|
|
255
|
+
const stopInside = (...elements) => {
|
|
256
|
+
for (const element of elements) for (const animation of element?.getAnimations?.() ?? []) if (animation.id === INSIDE) animation.cancel();
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* In the pill itself (`actionsStyle="inside"`): the actions, then a divider (the other way round on
|
|
260
|
+
* the end side). They open out of nothing as they come, and fold away before they go. Switching to
|
|
261
|
+
* the pill, they wait for their own pill to go back into it; switching away, their own pill waits
|
|
262
|
+
* for them to have gone (handoff.ts).
|
|
263
|
+
*/
|
|
166
264
|
function InsideActions({ host }) {
|
|
167
265
|
const items = useHostActions(host);
|
|
168
|
-
|
|
266
|
+
const handoff = useHandoff(host.store);
|
|
267
|
+
const inside = host.actionsStyle === "inside";
|
|
268
|
+
const [style, setStyle] = useState(host.actionsStyle);
|
|
269
|
+
const [waiting, setWaiting] = useState(false);
|
|
270
|
+
const waits = style !== host.actionsStyle ? inside && style === "detached" && !!items : waiting;
|
|
271
|
+
if (style !== host.actionsStyle) {
|
|
272
|
+
setStyle(host.actionsStyle);
|
|
273
|
+
setWaiting(waits);
|
|
274
|
+
}
|
|
275
|
+
useEffect(() => {
|
|
276
|
+
if (waiting) setWaiting(false);
|
|
277
|
+
}, [waiting]);
|
|
278
|
+
const wanted = inside && handoff !== "in" && !waits ? items : null;
|
|
279
|
+
const [shown, setShown] = useState(wanted);
|
|
280
|
+
if (wanted && wanted !== shown) setShown(wanted);
|
|
281
|
+
const listed = wanted ?? shown;
|
|
282
|
+
const leaving = !wanted && !!shown;
|
|
283
|
+
const divider = useRef(null);
|
|
284
|
+
const store = host.store;
|
|
285
|
+
const handingOut = leaving && !inside && !!items;
|
|
286
|
+
const open = !!listed && !leaving;
|
|
287
|
+
const sideOf = () => {
|
|
288
|
+
const line = divider.current;
|
|
289
|
+
return {
|
|
290
|
+
line,
|
|
291
|
+
list: (host.actionsSide === "end" ? line?.nextElementSibling : line?.previousElementSibling) ?? null
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
useIsomorphicLayoutEffect(() => {
|
|
295
|
+
const { line, list } = sideOf();
|
|
296
|
+
const pill = list?.closest("[data-mp=\"pill\"]");
|
|
297
|
+
if (!open || !line || !list || !pill || typeof list.animate !== "function" || prefersReducedMotion()) return;
|
|
298
|
+
const closed = closedFrames(pill);
|
|
299
|
+
const hold = {
|
|
300
|
+
id: INSIDE,
|
|
301
|
+
duration: 6e4,
|
|
302
|
+
fill: "forwards"
|
|
303
|
+
};
|
|
304
|
+
list.style.overflow = "clip";
|
|
305
|
+
list.animate([closed.list, closed.list], hold);
|
|
306
|
+
line.animate([closed.divider, closed.divider], hold);
|
|
307
|
+
const frame = requestAnimationFrame(() => {
|
|
308
|
+
stopInside(list, line);
|
|
309
|
+
playInside(list, line, "in");
|
|
310
|
+
});
|
|
311
|
+
return () => {
|
|
312
|
+
cancelAnimationFrame(frame);
|
|
313
|
+
stopInside(list, line);
|
|
314
|
+
list.style.removeProperty("overflow");
|
|
315
|
+
};
|
|
316
|
+
}, [open]);
|
|
317
|
+
useIsomorphicLayoutEffect(() => {
|
|
318
|
+
if (!leaving) return;
|
|
319
|
+
if (handingOut) setHandoff(store, "out");
|
|
320
|
+
const { line, list } = sideOf();
|
|
321
|
+
let cancelled = false;
|
|
322
|
+
const gone = () => {
|
|
323
|
+
if (cancelled) return;
|
|
324
|
+
setShown(null);
|
|
325
|
+
if (getHandoff(store) === "out") setHandoff(store, void 0);
|
|
326
|
+
};
|
|
327
|
+
stopInside(list, line);
|
|
328
|
+
const animation = list && line ? playInside(list, line, "out") : void 0;
|
|
329
|
+
if (animation) animation.finished.then(gone, () => {});
|
|
330
|
+
else gone();
|
|
331
|
+
return () => {
|
|
332
|
+
cancelled = true;
|
|
333
|
+
stopInside(list, line);
|
|
334
|
+
list?.style.removeProperty("overflow");
|
|
335
|
+
if (getHandoff(store) === "out") setHandoff(store, void 0);
|
|
336
|
+
};
|
|
337
|
+
}, [leaving]);
|
|
338
|
+
if (!listed) return null;
|
|
169
339
|
const list = /* @__PURE__ */ jsx(ActionList, {
|
|
170
|
-
items,
|
|
340
|
+
items: listed,
|
|
171
341
|
host,
|
|
172
|
-
inside: true
|
|
342
|
+
inside: true,
|
|
343
|
+
leaving
|
|
344
|
+
});
|
|
345
|
+
const line = /* @__PURE__ */ jsx(PillDivider, {
|
|
346
|
+
ref: divider,
|
|
347
|
+
"data-leaving": leaving ? "" : void 0
|
|
173
348
|
});
|
|
174
|
-
return host.actionsSide === "end" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
349
|
+
return host.actionsSide === "end" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [line, list] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [list, line] });
|
|
175
350
|
}
|
|
176
351
|
|
|
177
352
|
export { ActionList, InsideActions, useActionsWheel, useHostActions, usePillActions };
|
|
@@ -14,7 +14,7 @@ const MENU_STYLE = {
|
|
|
14
14
|
position: "fixed",
|
|
15
15
|
inset: 0,
|
|
16
16
|
pointerEvents: "none",
|
|
17
|
-
zIndex: "var(--mp-z-index, 50)"
|
|
17
|
+
zIndex: "calc(var(--mp-z-index, 50) - 2)"
|
|
18
18
|
};
|
|
19
19
|
const ORBITAL_STYLE = {
|
|
20
20
|
position: "fixed",
|
|
@@ -28,6 +28,12 @@ const LABEL_STYLE = {
|
|
|
28
28
|
left: 0,
|
|
29
29
|
top: 0
|
|
30
30
|
};
|
|
31
|
+
const TRACK_STYLE = {
|
|
32
|
+
position: "fixed",
|
|
33
|
+
left: 0,
|
|
34
|
+
top: 0,
|
|
35
|
+
borderRadius: "50%"
|
|
36
|
+
};
|
|
31
37
|
const MARKER_STYLE = {
|
|
32
38
|
position: "fixed",
|
|
33
39
|
left: 0,
|
|
@@ -108,6 +114,7 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
108
114
|
low: null,
|
|
109
115
|
high: null
|
|
110
116
|
});
|
|
117
|
+
const track = (0, react.useRef)(null);
|
|
111
118
|
const [past, setPast] = (0, react.useState)({
|
|
112
119
|
low: 0,
|
|
113
120
|
high: 0
|
|
@@ -124,7 +131,7 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
124
131
|
if (!element || !root) return null;
|
|
125
132
|
const read = readSettings(element);
|
|
126
133
|
settings.current = read;
|
|
127
|
-
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());
|
|
134
|
+
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()), ...host.avoidPills ? require_measure.otherPills(root) : []];
|
|
128
135
|
orbit.current = require_orbits.planOrbit({
|
|
129
136
|
electron: element.getBoundingClientRect(),
|
|
130
137
|
count: items.length,
|
|
@@ -170,6 +177,12 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
170
177
|
});
|
|
171
178
|
placeMarkers(current);
|
|
172
179
|
placeLabel();
|
|
180
|
+
const disc = track.current;
|
|
181
|
+
if (disc && settings.current) {
|
|
182
|
+
const reach = current.radius + settings.current.size * .8;
|
|
183
|
+
disc.style.width = disc.style.height = `${reach * 2}px`;
|
|
184
|
+
disc.style.translate = `${current.x - reach}px ${current.y - reach}px`;
|
|
185
|
+
}
|
|
173
186
|
};
|
|
174
187
|
const placeMarkers = (current) => {
|
|
175
188
|
if (host.orbitalsMore === "peek") return;
|
|
@@ -452,14 +465,6 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
452
465
|
host.placement,
|
|
453
466
|
electron.id
|
|
454
467
|
]);
|
|
455
|
-
require_react.useIsomorphicLayoutEffect(() => {
|
|
456
|
-
const element = getElement();
|
|
457
|
-
if (!ring || !element) return;
|
|
458
|
-
element.style.zIndex = "calc(var(--mp-z-index, 50) + 1)";
|
|
459
|
-
return () => {
|
|
460
|
-
element.style.zIndex = "var(--mp-z-index, 50)";
|
|
461
|
-
};
|
|
462
|
-
}, [ring !== null]);
|
|
463
468
|
(0, react.useEffect)(() => {
|
|
464
469
|
const link = getElement()?.querySelector("[data-mp=\"electron\"]");
|
|
465
470
|
if (!ring) {
|
|
@@ -467,7 +472,11 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
467
472
|
return;
|
|
468
473
|
}
|
|
469
474
|
link?.setAttribute("aria-expanded", "true");
|
|
470
|
-
const inside = (target) => target instanceof Node && ([
|
|
475
|
+
const inside = (target) => target instanceof Node && ([
|
|
476
|
+
...pills.current.values(),
|
|
477
|
+
...Object.values(markers.current),
|
|
478
|
+
track.current
|
|
479
|
+
].some((pill) => !!pill?.contains(target)) || !!link?.contains(target));
|
|
471
480
|
const onPointerDown = (event) => {
|
|
472
481
|
if (!inside(event.target)) api.current.close();
|
|
473
482
|
};
|
|
@@ -497,13 +506,15 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
497
506
|
let drag = null;
|
|
498
507
|
const onDragStart = (event) => {
|
|
499
508
|
if (!orbit.current?.wheel || event.button !== 0 || !(event.target instanceof Node)) return;
|
|
500
|
-
|
|
509
|
+
const onTrack = !!track.current?.contains(event.target);
|
|
510
|
+
if (!onTrack && ![...pills.current.values()].some((pill) => pill.contains(event.target))) return;
|
|
501
511
|
drag = {
|
|
502
512
|
angle: angleOf(event),
|
|
503
513
|
turn: turn.current,
|
|
504
514
|
x: event.clientX,
|
|
505
515
|
y: event.clientY,
|
|
506
|
-
moved: false
|
|
516
|
+
moved: false,
|
|
517
|
+
onTrack
|
|
507
518
|
};
|
|
508
519
|
};
|
|
509
520
|
const onDragMove = (event) => {
|
|
@@ -515,8 +526,9 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
515
526
|
};
|
|
516
527
|
const onDragEnd = () => {
|
|
517
528
|
if (!drag) return;
|
|
518
|
-
const { moved } = drag;
|
|
529
|
+
const { moved, onTrack } = drag;
|
|
519
530
|
drag = null;
|
|
531
|
+
if (!moved && onTrack) return api.current.close();
|
|
520
532
|
if (!moved) return;
|
|
521
533
|
api.current.snap();
|
|
522
534
|
const swallow = (event) => {
|
|
@@ -576,6 +588,28 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
576
588
|
(0, react.useEffect)(() => {
|
|
577
589
|
if (!ring) turn.current = 0;
|
|
578
590
|
}, [ring]);
|
|
591
|
+
const follow = (0, react.useRef)(applyTurn);
|
|
592
|
+
follow.current = applyTurn;
|
|
593
|
+
(0, react.useEffect)(() => {
|
|
594
|
+
if (!ring) return;
|
|
595
|
+
let frame = 0;
|
|
596
|
+
const step = () => {
|
|
597
|
+
const element = getElement();
|
|
598
|
+
const current = orbit.current;
|
|
599
|
+
if (element && current) {
|
|
600
|
+
const rect = element.getBoundingClientRect();
|
|
601
|
+
const dx = rect.left + rect.width / 2 - current.x;
|
|
602
|
+
const dy = rect.top + rect.height / 2 - current.y;
|
|
603
|
+
if (Math.abs(dx) > .5 || Math.abs(dy) > .5) {
|
|
604
|
+
orbit.current = require_orbits.movedOrbit(current, dx, dy);
|
|
605
|
+
follow.current();
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
frame = requestAnimationFrame(step);
|
|
609
|
+
};
|
|
610
|
+
frame = requestAnimationFrame(step);
|
|
611
|
+
return () => cancelAnimationFrame(frame);
|
|
612
|
+
}, [ring]);
|
|
579
613
|
if (!ring || items.length === 0) return null;
|
|
580
614
|
const run = (item) => (event) => {
|
|
581
615
|
item.onClick?.(event);
|
|
@@ -609,8 +643,15 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
609
643
|
"aria-label": electron.input.label,
|
|
610
644
|
"data-mp": "orbitals",
|
|
611
645
|
"data-orbitals": electron.id,
|
|
646
|
+
"data-wheel": orbit.current?.wheel ? "" : void 0,
|
|
612
647
|
style: MENU_STYLE,
|
|
613
648
|
children: [
|
|
649
|
+
orbit.current?.wheel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
650
|
+
ref: track,
|
|
651
|
+
"data-mp": "orbital-track",
|
|
652
|
+
"aria-hidden": "true",
|
|
653
|
+
style: TRACK_STYLE
|
|
654
|
+
}),
|
|
614
655
|
items.map((item, index) => {
|
|
615
656
|
const common = {
|
|
616
657
|
role: "menuitem",
|
|
@@ -635,7 +676,10 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
635
676
|
"data-satellite": "orbital",
|
|
636
677
|
"data-index": index,
|
|
637
678
|
"data-hot": hot === index ? "" : void 0,
|
|
638
|
-
style:
|
|
679
|
+
style: host.tokens ? {
|
|
680
|
+
...host.tokens,
|
|
681
|
+
...ORBITAL_STYLE
|
|
682
|
+
} : ORBITAL_STYLE,
|
|
639
683
|
onPointerEnter: (event) => {
|
|
640
684
|
const moving = event.currentTarget.getAnimations?.().some((animation) => animation.id === "mp-split" && animation.playState === "running");
|
|
641
685
|
if (!closing.current && !moving) setHot(index);
|
|
@@ -674,7 +718,10 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
674
718
|
presence: "compact",
|
|
675
719
|
"data-satellite": "orbital-more",
|
|
676
720
|
"data-end": end,
|
|
677
|
-
style:
|
|
721
|
+
style: host.tokens ? {
|
|
722
|
+
...host.tokens,
|
|
723
|
+
...MARKER_STYLE
|
|
724
|
+
} : MARKER_STYLE,
|
|
678
725
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
679
726
|
type: "button",
|
|
680
727
|
tabIndex: -1,
|
|
@@ -693,7 +740,10 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
693
740
|
presence: "compact",
|
|
694
741
|
"aria-hidden": "true",
|
|
695
742
|
"data-satellite": "orbital-label",
|
|
696
|
-
style:
|
|
743
|
+
style: host.tokens ? {
|
|
744
|
+
...host.tokens,
|
|
745
|
+
...LABEL_STYLE
|
|
746
|
+
} : LABEL_STYLE,
|
|
697
747
|
children: items[hot].label
|
|
698
748
|
})
|
|
699
749
|
]
|
|
@@ -5,8 +5,8 @@ import Pill from "../Pill/Pill.mjs";
|
|
|
5
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
|
-
import { durations, toPixels } from "./measure.mjs";
|
|
9
|
-
import { hiddenPast, orbitalAt, pastEnd, planOrbit, spotOn, wheelEnd } from "./orbits.mjs";
|
|
8
|
+
import { durations, otherPills, toPixels } from "./measure.mjs";
|
|
9
|
+
import { hiddenPast, movedOrbit, orbitalAt, pastEnd, planOrbit, spotOn, wheelEnd } from "./orbits.mjs";
|
|
10
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
|
|
12
12
|
// src/satellites/Orbitals.tsx
|
|
@@ -14,7 +14,7 @@ const MENU_STYLE = {
|
|
|
14
14
|
position: "fixed",
|
|
15
15
|
inset: 0,
|
|
16
16
|
pointerEvents: "none",
|
|
17
|
-
zIndex: "var(--mp-z-index, 50)"
|
|
17
|
+
zIndex: "calc(var(--mp-z-index, 50) - 2)"
|
|
18
18
|
};
|
|
19
19
|
const ORBITAL_STYLE = {
|
|
20
20
|
position: "fixed",
|
|
@@ -28,6 +28,12 @@ const LABEL_STYLE = {
|
|
|
28
28
|
left: 0,
|
|
29
29
|
top: 0
|
|
30
30
|
};
|
|
31
|
+
const TRACK_STYLE = {
|
|
32
|
+
position: "fixed",
|
|
33
|
+
left: 0,
|
|
34
|
+
top: 0,
|
|
35
|
+
borderRadius: "50%"
|
|
36
|
+
};
|
|
31
37
|
const MARKER_STYLE = {
|
|
32
38
|
position: "fixed",
|
|
33
39
|
left: 0,
|
|
@@ -108,6 +114,7 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
108
114
|
low: null,
|
|
109
115
|
high: null
|
|
110
116
|
});
|
|
117
|
+
const track = useRef(null);
|
|
111
118
|
const [past, setPast] = useState({
|
|
112
119
|
low: 0,
|
|
113
120
|
high: 0
|
|
@@ -124,7 +131,7 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
124
131
|
if (!element || !root) return null;
|
|
125
132
|
const read = readSettings(element);
|
|
126
133
|
settings.current = read;
|
|
127
|
-
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());
|
|
134
|
+
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()), ...host.avoidPills ? otherPills(root) : []];
|
|
128
135
|
orbit.current = planOrbit({
|
|
129
136
|
electron: element.getBoundingClientRect(),
|
|
130
137
|
count: items.length,
|
|
@@ -170,6 +177,12 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
170
177
|
});
|
|
171
178
|
placeMarkers(current);
|
|
172
179
|
placeLabel();
|
|
180
|
+
const disc = track.current;
|
|
181
|
+
if (disc && settings.current) {
|
|
182
|
+
const reach = current.radius + settings.current.size * .8;
|
|
183
|
+
disc.style.width = disc.style.height = `${reach * 2}px`;
|
|
184
|
+
disc.style.translate = `${current.x - reach}px ${current.y - reach}px`;
|
|
185
|
+
}
|
|
173
186
|
};
|
|
174
187
|
const placeMarkers = (current) => {
|
|
175
188
|
if (host.orbitalsMore === "peek") return;
|
|
@@ -452,14 +465,6 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
452
465
|
host.placement,
|
|
453
466
|
electron.id
|
|
454
467
|
]);
|
|
455
|
-
useIsomorphicLayoutEffect(() => {
|
|
456
|
-
const element = getElement();
|
|
457
|
-
if (!ring || !element) return;
|
|
458
|
-
element.style.zIndex = "calc(var(--mp-z-index, 50) + 1)";
|
|
459
|
-
return () => {
|
|
460
|
-
element.style.zIndex = "var(--mp-z-index, 50)";
|
|
461
|
-
};
|
|
462
|
-
}, [ring !== null]);
|
|
463
468
|
useEffect(() => {
|
|
464
469
|
const link = getElement()?.querySelector("[data-mp=\"electron\"]");
|
|
465
470
|
if (!ring) {
|
|
@@ -467,7 +472,11 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
467
472
|
return;
|
|
468
473
|
}
|
|
469
474
|
link?.setAttribute("aria-expanded", "true");
|
|
470
|
-
const inside = (target) => target instanceof Node && ([
|
|
475
|
+
const inside = (target) => target instanceof Node && ([
|
|
476
|
+
...pills.current.values(),
|
|
477
|
+
...Object.values(markers.current),
|
|
478
|
+
track.current
|
|
479
|
+
].some((pill) => !!pill?.contains(target)) || !!link?.contains(target));
|
|
471
480
|
const onPointerDown = (event) => {
|
|
472
481
|
if (!inside(event.target)) api.current.close();
|
|
473
482
|
};
|
|
@@ -497,13 +506,15 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
497
506
|
let drag = null;
|
|
498
507
|
const onDragStart = (event) => {
|
|
499
508
|
if (!orbit.current?.wheel || event.button !== 0 || !(event.target instanceof Node)) return;
|
|
500
|
-
|
|
509
|
+
const onTrack = !!track.current?.contains(event.target);
|
|
510
|
+
if (!onTrack && ![...pills.current.values()].some((pill) => pill.contains(event.target))) return;
|
|
501
511
|
drag = {
|
|
502
512
|
angle: angleOf(event),
|
|
503
513
|
turn: turn.current,
|
|
504
514
|
x: event.clientX,
|
|
505
515
|
y: event.clientY,
|
|
506
|
-
moved: false
|
|
516
|
+
moved: false,
|
|
517
|
+
onTrack
|
|
507
518
|
};
|
|
508
519
|
};
|
|
509
520
|
const onDragMove = (event) => {
|
|
@@ -515,8 +526,9 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
515
526
|
};
|
|
516
527
|
const onDragEnd = () => {
|
|
517
528
|
if (!drag) return;
|
|
518
|
-
const { moved } = drag;
|
|
529
|
+
const { moved, onTrack } = drag;
|
|
519
530
|
drag = null;
|
|
531
|
+
if (!moved && onTrack) return api.current.close();
|
|
520
532
|
if (!moved) return;
|
|
521
533
|
api.current.snap();
|
|
522
534
|
const swallow = (event) => {
|
|
@@ -576,6 +588,28 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
576
588
|
useEffect(() => {
|
|
577
589
|
if (!ring) turn.current = 0;
|
|
578
590
|
}, [ring]);
|
|
591
|
+
const follow = useRef(applyTurn);
|
|
592
|
+
follow.current = applyTurn;
|
|
593
|
+
useEffect(() => {
|
|
594
|
+
if (!ring) return;
|
|
595
|
+
let frame = 0;
|
|
596
|
+
const step = () => {
|
|
597
|
+
const element = getElement();
|
|
598
|
+
const current = orbit.current;
|
|
599
|
+
if (element && current) {
|
|
600
|
+
const rect = element.getBoundingClientRect();
|
|
601
|
+
const dx = rect.left + rect.width / 2 - current.x;
|
|
602
|
+
const dy = rect.top + rect.height / 2 - current.y;
|
|
603
|
+
if (Math.abs(dx) > .5 || Math.abs(dy) > .5) {
|
|
604
|
+
orbit.current = movedOrbit(current, dx, dy);
|
|
605
|
+
follow.current();
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
frame = requestAnimationFrame(step);
|
|
609
|
+
};
|
|
610
|
+
frame = requestAnimationFrame(step);
|
|
611
|
+
return () => cancelAnimationFrame(frame);
|
|
612
|
+
}, [ring]);
|
|
579
613
|
if (!ring || items.length === 0) return null;
|
|
580
614
|
const run = (item) => (event) => {
|
|
581
615
|
item.onClick?.(event);
|
|
@@ -609,8 +643,15 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
609
643
|
"aria-label": electron.input.label,
|
|
610
644
|
"data-mp": "orbitals",
|
|
611
645
|
"data-orbitals": electron.id,
|
|
646
|
+
"data-wheel": orbit.current?.wheel ? "" : void 0,
|
|
612
647
|
style: MENU_STYLE,
|
|
613
648
|
children: [
|
|
649
|
+
orbit.current?.wheel && /* @__PURE__ */ jsx("div", {
|
|
650
|
+
ref: track,
|
|
651
|
+
"data-mp": "orbital-track",
|
|
652
|
+
"aria-hidden": "true",
|
|
653
|
+
style: TRACK_STYLE
|
|
654
|
+
}),
|
|
614
655
|
items.map((item, index) => {
|
|
615
656
|
const common = {
|
|
616
657
|
role: "menuitem",
|
|
@@ -635,7 +676,10 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
635
676
|
"data-satellite": "orbital",
|
|
636
677
|
"data-index": index,
|
|
637
678
|
"data-hot": hot === index ? "" : void 0,
|
|
638
|
-
style:
|
|
679
|
+
style: host.tokens ? {
|
|
680
|
+
...host.tokens,
|
|
681
|
+
...ORBITAL_STYLE
|
|
682
|
+
} : ORBITAL_STYLE,
|
|
639
683
|
onPointerEnter: (event) => {
|
|
640
684
|
const moving = event.currentTarget.getAnimations?.().some((animation) => animation.id === "mp-split" && animation.playState === "running");
|
|
641
685
|
if (!closing.current && !moving) setHot(index);
|
|
@@ -674,7 +718,10 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
674
718
|
presence: "compact",
|
|
675
719
|
"data-satellite": "orbital-more",
|
|
676
720
|
"data-end": end,
|
|
677
|
-
style:
|
|
721
|
+
style: host.tokens ? {
|
|
722
|
+
...host.tokens,
|
|
723
|
+
...MARKER_STYLE
|
|
724
|
+
} : MARKER_STYLE,
|
|
678
725
|
children: /* @__PURE__ */ jsxs("button", {
|
|
679
726
|
type: "button",
|
|
680
727
|
tabIndex: -1,
|
|
@@ -693,7 +740,10 @@ function Orbitals({ electron, getElement, host, out }) {
|
|
|
693
740
|
presence: "compact",
|
|
694
741
|
"aria-hidden": "true",
|
|
695
742
|
"data-satellite": "orbital-label",
|
|
696
|
-
style:
|
|
743
|
+
style: host.tokens ? {
|
|
744
|
+
...host.tokens,
|
|
745
|
+
...LABEL_STYLE
|
|
746
|
+
} : LABEL_STYLE,
|
|
697
747
|
children: items[hot].label
|
|
698
748
|
})
|
|
699
749
|
]
|