magic-pill 9.4.0-next.2 → 9.4.0-next.3

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/dist/Pill/zone.js CHANGED
@@ -120,8 +120,7 @@ function useZone(rootRef, zone, presence) {
120
120
  return () => {
121
121
  observer?.disconnect();
122
122
  rungs.splice(rungs.indexOf(rung), 1);
123
- element.style.removeProperty(SHIFTS.x);
124
- element.style.removeProperty(SHIFTS.y);
123
+ element.style.removeProperty(axisOf(zone).shift);
125
124
  arrange(zone, () => travel(element));
126
125
  };
127
126
  }, [rootRef, zone]);
@@ -120,8 +120,7 @@ function useZone(rootRef, zone, presence) {
120
120
  return () => {
121
121
  observer?.disconnect();
122
122
  rungs.splice(rungs.indexOf(rung), 1);
123
- element.style.removeProperty(SHIFTS.x);
124
- element.style.removeProperty(SHIFTS.y);
123
+ element.style.removeProperty(axisOf(zone).shift);
125
124
  arrange(zone, () => travel(element));
126
125
  };
127
126
  }, [rootRef, zone]);
@@ -4,18 +4,26 @@ let react = require("react");
4
4
 
5
5
  // src/PillNavbar/room.ts
6
6
  const ACTION = "[data-mp=\"action\"]";
7
- /** A copy of the pill with its navbar, laid out next to it, hidden, to measure. Removed by the caller. */
8
- function layOutCopy(pill, prepare) {
7
+ /**
8
+ * A copy of the pill (and its navbar, if it has one), laid out next to it, hidden, to measure.
9
+ * Removed by the caller. `free`: without the room its satellites take beside it (what they plan
10
+ * with: measured within it, the pill would only seem to fit what they left it the time before).
11
+ */
12
+ function layOutCopy(pill, prepare = () => {}, free = false) {
9
13
  const copy = pill.cloneNode(false);
14
+ const side = copy.dataset.placement === "left" || copy.dataset.placement === "right";
15
+ if (free && !side) copy.style.removeProperty("--_mp-shift-x");
16
+ if (copy.dataset.presence === "rest" || copy.dataset.presence === "hidden") copy.dataset.presence = "compact";
10
17
  for (const child of pill.children) if (child.getAttribute("data-mp") !== "panel") copy.append(child.cloneNode(true));
11
18
  copy.querySelectorAll("[id], [name]").forEach((node) => {
12
19
  node.removeAttribute("id");
13
20
  node.removeAttribute("name");
14
21
  });
15
22
  const navbar = copy.querySelector("[data-mp=\"navbar\"]");
16
- if (!navbar) return null;
17
- navbar.removeAttribute("data-tight");
18
- prepare(navbar);
23
+ if (navbar) {
24
+ navbar.removeAttribute("data-tight");
25
+ prepare(navbar);
26
+ }
19
27
  copy.querySelectorAll("[data-mp=\"navbar\"], [data-mp=\"actions\"], [data-mp=\"action\"]").forEach((node) => {
20
28
  node.style.flexShrink = "0";
21
29
  });
@@ -37,13 +45,12 @@ function fitsWith(navbar, item, { unfold = false } = {}) {
37
45
  const pill = navbar.closest("[data-mp=\"pill\"]");
38
46
  if (!pill) return true;
39
47
  const index = item ? [...navbar.querySelectorAll(ACTION)].indexOf(item) : -1;
40
- const laidOut = layOutCopy(pill, (copied) => {
41
- if (unfold) copied.removeAttribute("data-folded");
42
- if (index >= 0) copied.querySelectorAll(ACTION)[index]?.setAttribute("data-expanded", "");
48
+ const { copy, navbar: copied } = layOutCopy(pill, (laidOut) => {
49
+ if (unfold) laidOut.removeAttribute("data-folded");
50
+ if (index >= 0) laidOut.querySelectorAll(ACTION)[index]?.setAttribute("data-expanded", "");
43
51
  });
44
- if (!laidOut) return true;
45
- const fits = isInside(laidOut.navbar, laidOut.copy);
46
- laidOut.copy.remove();
52
+ const fits = !copied || isInside(copied, copy);
53
+ copy.remove();
47
54
  return fits;
48
55
  }
49
56
  /**
@@ -54,12 +61,25 @@ function fitsWith(navbar, item, { unfold = false } = {}) {
54
61
  function foldedWidth(pill) {
55
62
  const navbar = pill.querySelector("[data-mp=\"navbar\"]");
56
63
  if (!navbar || navbar.dataset.labels === "current") return pill.offsetWidth;
57
- const laidOut = layOutCopy(pill, (copied) => copied.setAttribute("data-folded", ""));
58
- if (!laidOut) return pill.offsetWidth;
59
- const width = laidOut.copy.offsetWidth;
60
- laidOut.copy.remove();
64
+ const { copy } = layOutCopy(pill, (copied) => copied.setAttribute("data-folded", ""), true);
65
+ const width = copy.offsetWidth;
66
+ copy.remove();
61
67
  return width;
62
68
  }
69
+ /**
70
+ * How big the pill is open, laid out on a copy: what a pill closed to a
71
+ * circle (on its way to another placement) opens to. The satellites ask,
72
+ * to give it its room and its spot before it opens.
73
+ */
74
+ function openSize(pill) {
75
+ const { copy } = layOutCopy(pill, void 0, true);
76
+ const size = {
77
+ width: copy.offsetWidth,
78
+ height: copy.offsetHeight
79
+ };
80
+ copy.remove();
81
+ return size;
82
+ }
63
83
  /** Whether the navbar ends before the pill's padding does. */
64
84
  function isInside(navbar, pill) {
65
85
  const style = getComputedStyle(pill);
@@ -153,4 +173,5 @@ function useRoom(ref, labels = "auto") {
153
173
 
154
174
  exports.fitsWith = fitsWith;
155
175
  exports.foldedWidth = foldedWidth;
176
+ exports.openSize = openSize;
156
177
  exports.useRoom = useRoom;
@@ -4,18 +4,26 @@ import { useEffect } from "react";
4
4
 
5
5
  // src/PillNavbar/room.ts
6
6
  const ACTION = "[data-mp=\"action\"]";
7
- /** A copy of the pill with its navbar, laid out next to it, hidden, to measure. Removed by the caller. */
8
- function layOutCopy(pill, prepare) {
7
+ /**
8
+ * A copy of the pill (and its navbar, if it has one), laid out next to it, hidden, to measure.
9
+ * Removed by the caller. `free`: without the room its satellites take beside it (what they plan
10
+ * with: measured within it, the pill would only seem to fit what they left it the time before).
11
+ */
12
+ function layOutCopy(pill, prepare = () => {}, free = false) {
9
13
  const copy = pill.cloneNode(false);
14
+ const side = copy.dataset.placement === "left" || copy.dataset.placement === "right";
15
+ if (free && !side) copy.style.removeProperty("--_mp-shift-x");
16
+ if (copy.dataset.presence === "rest" || copy.dataset.presence === "hidden") copy.dataset.presence = "compact";
10
17
  for (const child of pill.children) if (child.getAttribute("data-mp") !== "panel") copy.append(child.cloneNode(true));
11
18
  copy.querySelectorAll("[id], [name]").forEach((node) => {
12
19
  node.removeAttribute("id");
13
20
  node.removeAttribute("name");
14
21
  });
15
22
  const navbar = copy.querySelector("[data-mp=\"navbar\"]");
16
- if (!navbar) return null;
17
- navbar.removeAttribute("data-tight");
18
- prepare(navbar);
23
+ if (navbar) {
24
+ navbar.removeAttribute("data-tight");
25
+ prepare(navbar);
26
+ }
19
27
  copy.querySelectorAll("[data-mp=\"navbar\"], [data-mp=\"actions\"], [data-mp=\"action\"]").forEach((node) => {
20
28
  node.style.flexShrink = "0";
21
29
  });
@@ -37,13 +45,12 @@ function fitsWith(navbar, item, { unfold = false } = {}) {
37
45
  const pill = navbar.closest("[data-mp=\"pill\"]");
38
46
  if (!pill) return true;
39
47
  const index = item ? [...navbar.querySelectorAll(ACTION)].indexOf(item) : -1;
40
- const laidOut = layOutCopy(pill, (copied) => {
41
- if (unfold) copied.removeAttribute("data-folded");
42
- if (index >= 0) copied.querySelectorAll(ACTION)[index]?.setAttribute("data-expanded", "");
48
+ const { copy, navbar: copied } = layOutCopy(pill, (laidOut) => {
49
+ if (unfold) laidOut.removeAttribute("data-folded");
50
+ if (index >= 0) laidOut.querySelectorAll(ACTION)[index]?.setAttribute("data-expanded", "");
43
51
  });
44
- if (!laidOut) return true;
45
- const fits = isInside(laidOut.navbar, laidOut.copy);
46
- laidOut.copy.remove();
52
+ const fits = !copied || isInside(copied, copy);
53
+ copy.remove();
47
54
  return fits;
48
55
  }
49
56
  /**
@@ -54,12 +61,25 @@ function fitsWith(navbar, item, { unfold = false } = {}) {
54
61
  function foldedWidth(pill) {
55
62
  const navbar = pill.querySelector("[data-mp=\"navbar\"]");
56
63
  if (!navbar || navbar.dataset.labels === "current") return pill.offsetWidth;
57
- const laidOut = layOutCopy(pill, (copied) => copied.setAttribute("data-folded", ""));
58
- if (!laidOut) return pill.offsetWidth;
59
- const width = laidOut.copy.offsetWidth;
60
- laidOut.copy.remove();
64
+ const { copy } = layOutCopy(pill, (copied) => copied.setAttribute("data-folded", ""), true);
65
+ const width = copy.offsetWidth;
66
+ copy.remove();
61
67
  return width;
62
68
  }
69
+ /**
70
+ * How big the pill is open, laid out on a copy: what a pill closed to a
71
+ * circle (on its way to another placement) opens to. The satellites ask,
72
+ * to give it its room and its spot before it opens.
73
+ */
74
+ function openSize(pill) {
75
+ const { copy } = layOutCopy(pill, void 0, true);
76
+ const size = {
77
+ width: copy.offsetWidth,
78
+ height: copy.offsetHeight
79
+ };
80
+ copy.remove();
81
+ return size;
82
+ }
63
83
  /** Whether the navbar ends before the pill's padding does. */
64
84
  function isInside(navbar, pill) {
65
85
  const style = getComputedStyle(pill);
@@ -151,4 +171,4 @@ function useRoom(ref, labels = "auto") {
151
171
  }, [ref]);
152
172
  }
153
173
 
154
- export { fitsWith, foldedWidth, useRoom };
174
+ export { fitsWith, foldedWidth, openSize, useRoom };
@@ -28,6 +28,28 @@ const LABEL_STYLE = {
28
28
  left: 0,
29
29
  top: 0
30
30
  };
31
+ const MARKER_STYLE = {
32
+ position: "fixed",
33
+ left: 0,
34
+ top: 0,
35
+ margin: 0,
36
+ opacity: 0,
37
+ pointerEvents: "none"
38
+ };
39
+ const DOTS_STYLE = {
40
+ ...MARKER_STYLE,
41
+ display: "flex",
42
+ gap: 4,
43
+ transition: "opacity 150ms ease-out"
44
+ };
45
+ const DOT_STYLE = {
46
+ display: "block",
47
+ inlineSize: 6,
48
+ blockSize: 6,
49
+ borderRadius: "50%",
50
+ background: "currentColor"
51
+ };
52
+ const ENDS = ["low", "high"];
31
53
  /** Another electron opened its orbitals: these close */
32
54
  const OPENED = "mp-orbitals-open";
33
55
  /** The direction away from the screen's edge, by the host's placement */
@@ -82,6 +104,16 @@ function Orbitals({ electron, getElement, host, out }) {
82
104
  const focusFirst = (0, react.useRef)(false);
83
105
  const turn = (0, react.useRef)(0);
84
106
  const snapping = (0, react.useRef)(0);
107
+ const markers = (0, react.useRef)({
108
+ low: null,
109
+ high: null
110
+ });
111
+ const [past, setPast] = (0, react.useState)({
112
+ low: 0,
113
+ high: 0
114
+ });
115
+ const lastPast = (0, react.useRef)(past);
116
+ const surface = (0, react.useRef)("");
85
117
  const clearTimers = () => {
86
118
  timers.current.forEach(clearTimeout);
87
119
  timers.current = [];
@@ -107,6 +139,14 @@ function Orbitals({ electron, getElement, host, out }) {
107
139
  },
108
140
  rtl: getComputedStyle(root).direction === "rtl"
109
141
  });
142
+ if (host.orbitalsMore !== "peek") orbit.current = {
143
+ ...orbit.current,
144
+ peek: {
145
+ low: false,
146
+ high: false
147
+ }
148
+ };
149
+ surface.current = getComputedStyle(element).backgroundColor;
110
150
  return read;
111
151
  };
112
152
  const applyTurn = () => {
@@ -128,8 +168,44 @@ function Orbitals({ electron, getElement, host, out }) {
128
168
  pill.style.pointerEvents = closing.current ? "none" : "auto";
129
169
  }
130
170
  });
171
+ placeMarkers(current);
131
172
  placeLabel();
132
173
  };
174
+ const placeMarkers = (current) => {
175
+ if (host.orbitalsMore === "peek") return;
176
+ const counts = require_orbits.hiddenPast(current, turn.current);
177
+ if (counts.low !== lastPast.current.low || counts.high !== lastPast.current.high) {
178
+ lastPast.current = counts;
179
+ setPast(counts);
180
+ }
181
+ const size = settings.current?.size ?? 44;
182
+ for (const end of ENDS) {
183
+ const marker = markers.current[end];
184
+ if (!marker) continue;
185
+ const on = current.wheel && counts[end] > 0 && !closing.current;
186
+ const length = marker.offsetWidth;
187
+ const height = marker.offsetHeight;
188
+ const outward = host.orbitalsMore === "count" ? size / 2 + Math.min(length, height) / 2 - 2 : size / 2 + 7;
189
+ const spot = require_orbits.pastEnd(current, end, size * .45, outward);
190
+ const reach = Math.max(length, height) / 2 + 6;
191
+ const x = Math.min(Math.max(spot.x, reach), (document.documentElement.clientWidth || window.innerWidth) - reach);
192
+ const y = Math.min(Math.max(spot.y, reach), window.innerHeight - reach);
193
+ marker.style.translate = `${x - length / 2}px ${y - height / 2}px`;
194
+ if (host.orbitalsMore === "dots") {
195
+ marker.style.rotate = `${spot.angle + 90}deg`;
196
+ marker.style.color = surface.current;
197
+ }
198
+ marker.style.opacity = on ? "1" : "0";
199
+ marker.style.pointerEvents = on && host.orbitalsMore === "count" ? "auto" : "none";
200
+ }
201
+ };
202
+ const turnPage = (end) => {
203
+ const current = orbit.current;
204
+ if (!current?.wheel) return;
205
+ const page = Math.max(1, current.visible - 1);
206
+ const towards = (end === "low" ? -1 : 1) * (current.rtl ? -1 : 1);
207
+ turnTo(Math.round(turn.current) + towards * page, true);
208
+ };
133
209
  const placeLabel = () => {
134
210
  const label = labelRef.current;
135
211
  const index = api.current.hot;
@@ -376,6 +452,14 @@ function Orbitals({ electron, getElement, host, out }) {
376
452
  host.placement,
377
453
  electron.id
378
454
  ]);
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]);
379
463
  (0, react.useEffect)(() => {
380
464
  const link = getElement()?.querySelector("[data-mp=\"electron\"]");
381
465
  if (!ring) {
@@ -383,7 +467,7 @@ function Orbitals({ electron, getElement, host, out }) {
383
467
  return;
384
468
  }
385
469
  link?.setAttribute("aria-expanded", "true");
386
- const inside = (target) => target instanceof Node && ([...pills.current.values()].some((pill) => pill.contains(target)) || !!link?.contains(target));
470
+ const inside = (target) => target instanceof Node && ([...pills.current.values(), ...Object.values(markers.current)].some((pill) => !!pill?.contains(target)) || !!link?.contains(target));
387
471
  const onPointerDown = (event) => {
388
472
  if (!inside(event.target)) api.current.close();
389
473
  };
@@ -526,59 +610,93 @@ function Orbitals({ electron, getElement, host, out }) {
526
610
  "data-mp": "orbitals",
527
611
  "data-orbitals": electron.id,
528
612
  style: MENU_STYLE,
529
- children: [items.map((item, index) => {
530
- const common = {
531
- role: "menuitem",
532
- tabIndex: -1,
533
- "data-mp": "orbital",
534
- "aria-label": item.label,
535
- onClick: run(item),
536
- onKeyDown: onKeyDown(index),
537
- onFocus: () => setHot(index)
538
- };
539
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Pill, {
613
+ children: [
614
+ items.map((item, index) => {
615
+ const common = {
616
+ role: "menuitem",
617
+ tabIndex: -1,
618
+ "data-mp": "orbital",
619
+ "aria-label": item.label,
620
+ onClick: run(item),
621
+ onKeyDown: onKeyDown(index),
622
+ onFocus: () => setHot(index)
623
+ };
624
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Pill, {
625
+ ref: (element) => {
626
+ if (element) pills.current.set(index, element);
627
+ else pills.current.delete(index);
628
+ },
629
+ placement: "inline",
630
+ ladder: false,
631
+ moveThroughCircle: false,
632
+ theme: host.theme,
633
+ variant: electron.input.variant ?? host.variant,
634
+ presence: shown[index] ? "compact" : "hidden",
635
+ "data-satellite": "orbital",
636
+ "data-index": index,
637
+ "data-hot": hot === index ? "" : void 0,
638
+ style: ORBITAL_STYLE,
639
+ onPointerEnter: (event) => {
640
+ const moving = event.currentTarget.getAnimations?.().some((animation) => animation.id === "mp-split" && animation.playState === "running");
641
+ if (!closing.current && !moving) setHot(index);
642
+ },
643
+ onPointerLeave: () => setHot(-1),
644
+ children: item.href !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Link, {
645
+ href: item.href,
646
+ ...common,
647
+ children: item.icon
648
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
649
+ type: "button",
650
+ ...common,
651
+ children: item.icon
652
+ })
653
+ }, item.id ?? index);
654
+ }),
655
+ host.orbitalsMore === "dots" && ENDS.map((end) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
540
656
  ref: (element) => {
541
- if (element) pills.current.set(index, element);
542
- else pills.current.delete(index);
657
+ markers.current[end] = element;
658
+ },
659
+ "aria-hidden": "true",
660
+ "data-mp": "orbital-dots",
661
+ "data-end": end,
662
+ style: DOTS_STYLE,
663
+ children: Array.from({ length: Math.min(3, past[end]) }, (_, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", { style: DOT_STYLE }, index))
664
+ }, end)),
665
+ host.orbitalsMore === "count" && ENDS.map((end) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Pill, {
666
+ ref: (element) => {
667
+ markers.current[end] = element;
543
668
  },
544
669
  placement: "inline",
545
670
  ladder: false,
546
671
  moveThroughCircle: false,
547
672
  theme: host.theme,
548
673
  variant: electron.input.variant ?? host.variant,
549
- presence: shown[index] ? "compact" : "hidden",
550
- "data-satellite": "orbital",
551
- "data-index": index,
552
- "data-hot": hot === index ? "" : void 0,
553
- style: ORBITAL_STYLE,
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
- },
558
- onPointerLeave: () => setHot(-1),
559
- children: item.href !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Link, {
560
- href: item.href,
561
- ...common,
562
- children: item.icon
563
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
674
+ presence: "compact",
675
+ "data-satellite": "orbital-more",
676
+ "data-end": end,
677
+ style: MARKER_STYLE,
678
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
564
679
  type: "button",
565
- ...common,
566
- children: item.icon
680
+ tabIndex: -1,
681
+ "aria-hidden": "true",
682
+ onClick: () => turnPage(end),
683
+ children: ["+", past[end]]
567
684
  })
568
- }, item.id ?? index);
569
- }), host.orbitalLabels && hot >= 0 && items[hot] && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Pill, {
570
- ref: labelRef,
571
- placement: "inline",
572
- ladder: false,
573
- moveThroughCircle: false,
574
- theme: host.theme,
575
- variant: electron.input.variant ?? host.variant,
576
- presence: "compact",
577
- "aria-hidden": "true",
578
- "data-satellite": "orbital-label",
579
- style: LABEL_STYLE,
580
- children: items[hot].label
581
- })]
685
+ }, end)),
686
+ host.orbitalLabels && hot >= 0 && items[hot] && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Pill, {
687
+ ref: labelRef,
688
+ placement: "inline",
689
+ ladder: false,
690
+ moveThroughCircle: false,
691
+ theme: host.theme,
692
+ variant: electron.input.variant ?? host.variant,
693
+ presence: "compact",
694
+ "aria-hidden": "true",
695
+ "data-satellite": "orbital-label",
696
+ style: LABEL_STYLE,
697
+ children: items[hot].label
698
+ })
699
+ ]
582
700
  });
583
701
  }
584
702