magic-pill 9.3.0 → 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.
Files changed (54) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +114 -3
  3. package/dist/MagicPill/MagicPill.d.mts +51 -1
  4. package/dist/MagicPill/MagicPill.d.ts +51 -1
  5. package/dist/MagicPill/MagicPill.js +53 -4
  6. package/dist/MagicPill/MagicPill.mjs +55 -6
  7. package/dist/MagicPill/flag.js +1 -59
  8. package/dist/MagicPill/flag.mjs +1 -58
  9. package/dist/Pill/PillProgress.d.mts +12 -0
  10. package/dist/Pill/PillProgress.d.ts +12 -0
  11. package/dist/Pill/PillProgress.js +42 -0
  12. package/dist/Pill/PillProgress.mjs +42 -0
  13. package/dist/Pill/goo.js +576 -0
  14. package/dist/Pill/goo.mjs +566 -0
  15. package/dist/Pill/morph.js +11 -4
  16. package/dist/Pill/morph.mjs +10 -5
  17. package/dist/PillNavbar/PillNavbar.d.mts +8 -0
  18. package/dist/PillNavbar/PillNavbar.d.ts +8 -0
  19. package/dist/PillNavbar/PillNavbar.js +3 -2
  20. package/dist/PillNavbar/PillNavbar.mjs +3 -2
  21. package/dist/PillNavbar/room.d.mts +3 -0
  22. package/dist/PillNavbar/room.d.ts +2 -0
  23. package/dist/PillNavbar/room.js +89 -17
  24. package/dist/PillNavbar/room.mjs +89 -18
  25. package/dist/index.d.mts +3 -2
  26. package/dist/index.d.ts +3 -2
  27. package/dist/index.js +2 -0
  28. package/dist/index.mjs +2 -1
  29. package/dist/satellites/Actions.d.mts +12 -0
  30. package/dist/satellites/Actions.d.ts +11 -0
  31. package/dist/satellites/Actions.js +181 -0
  32. package/dist/satellites/Actions.mjs +177 -0
  33. package/dist/satellites/Orbitals.js +585 -0
  34. package/dist/satellites/Orbitals.mjs +585 -0
  35. package/dist/satellites/Satellites.js +634 -0
  36. package/dist/satellites/Satellites.mjs +634 -0
  37. package/dist/satellites/layout.js +209 -0
  38. package/dist/satellites/layout.mjs +209 -0
  39. package/dist/satellites/measure.js +25 -0
  40. package/dist/satellites/measure.mjs +24 -0
  41. package/dist/satellites/orbits.js +139 -0
  42. package/dist/satellites/orbits.mjs +136 -0
  43. package/dist/satellites/types.d.mts +58 -0
  44. package/dist/satellites/types.d.ts +58 -0
  45. package/dist/satellites.d.mts +5 -0
  46. package/dist/satellites.d.ts +5 -0
  47. package/dist/satellites.js +14 -0
  48. package/dist/satellites.mjs +12 -0
  49. package/dist/store/store.d.mts +103 -0
  50. package/dist/store/store.d.ts +103 -0
  51. package/dist/store/store.js +52 -1
  52. package/dist/store/store.mjs +52 -2
  53. package/dist/styles.css +322 -8
  54. package/package.json +11 -1
@@ -1,6 +1,7 @@
1
1
  import { ComponentPropsWithoutRef, MouseEvent, ReactNode } from "react";
2
2
  import { LinkComponent } from "../Pill/types.js";
3
3
  import { NavMatch } from "./matchPath.js";
4
+ import { NavLabels } from "./room.js";
4
5
  interface NavItemBase {
5
6
  label: string;
6
7
  icon?: ReactNode;
@@ -43,6 +44,13 @@ export interface PillNavbarProps extends Omit<ComponentPropsWithoutRef<"nav">, "
43
44
  */
44
45
  pathname?: string;
45
46
  linkComponent?: LinkComponent;
47
+ /**
48
+ * Which labels show at rest: the current page's ("current"), none
49
+ * ("closed"), or the current page's while the pill has room for it
50
+ * ("auto", the default: it folds next to an electron on a narrow screen).
51
+ * An item pointed at or focused shows its label in every case.
52
+ */
53
+ labels?: NavLabels;
46
54
  /** Default "Main". */
47
55
  "aria-label"?: string;
48
56
  }
@@ -27,10 +27,10 @@ const isLink = (item) => item.href !== void 0;
27
27
  * A <nav> of icon links, actions and panel triggers. The active link shows its
28
28
  * label and gets `aria-current="page"`. Render it inside a <Pill>, or as the base layer of a <MagicPill>.
29
29
  */
30
- const PillNavbar = (0, react.forwardRef)(function PillNavbar({ items, pathname, linkComponent, "aria-label": ariaLabel = "Main", ...rest }, forwardedRef) {
30
+ const PillNavbar = (0, react.forwardRef)(function PillNavbar({ items, pathname, linkComponent, labels = "auto", "aria-label": ariaLabel = "Main", ...rest }, forwardedRef) {
31
31
  const navRef = (0, react.useRef)(null);
32
32
  const ref = (0, react.useMemo)(() => require_react.mergeRefs(navRef, forwardedRef), [forwardedRef]);
33
- require_room.useRoom(navRef);
33
+ require_room.useRoom(navRef, labels);
34
34
  const locationPathname = useLocationPathname(pathname === void 0);
35
35
  const links = items.filter(isLink);
36
36
  const active = links[require_matchPath.findActiveIndex(pathname ?? locationPathname, links)];
@@ -62,6 +62,7 @@ const PillNavbar = (0, react.forwardRef)(function PillNavbar({ items, pathname,
62
62
  ...rest,
63
63
  ref,
64
64
  "data-mp": "navbar",
65
+ "data-labels": labels,
65
66
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillActions, { children: items.map(renderItem) })
66
67
  });
67
68
  });
@@ -27,10 +27,10 @@ const isLink = (item) => item.href !== void 0;
27
27
  * A <nav> of icon links, actions and panel triggers. The active link shows its
28
28
  * label and gets `aria-current="page"`. Render it inside a <Pill>, or as the base layer of a <MagicPill>.
29
29
  */
30
- const PillNavbar = forwardRef(function PillNavbar({ items, pathname, linkComponent, "aria-label": ariaLabel = "Main", ...rest }, forwardedRef) {
30
+ const PillNavbar = forwardRef(function PillNavbar({ items, pathname, linkComponent, labels = "auto", "aria-label": ariaLabel = "Main", ...rest }, forwardedRef) {
31
31
  const navRef = useRef(null);
32
32
  const ref = useMemo(() => mergeRefs(navRef, forwardedRef), [forwardedRef]);
33
- useRoom(navRef);
33
+ useRoom(navRef, labels);
34
34
  const locationPathname = useLocationPathname(pathname === void 0);
35
35
  const links = items.filter(isLink);
36
36
  const active = links[findActiveIndex(pathname ?? locationPathname, links)];
@@ -62,6 +62,7 @@ const PillNavbar = forwardRef(function PillNavbar({ items, pathname, linkCompone
62
62
  ...rest,
63
63
  ref,
64
64
  "data-mp": "navbar",
65
+ "data-labels": labels,
65
66
  children: /* @__PURE__ */ jsx(PillActions, { children: items.map(renderItem) })
66
67
  });
67
68
  });
@@ -0,0 +1,3 @@
1
+ import "react";
2
+ /** Which labels a navbar shows at rest. */
3
+ export type NavLabels = "current" | "closed" | "auto";
@@ -0,0 +1,2 @@
1
+ /** Which labels a navbar shows at rest. */
2
+ export type NavLabels = "current" | "closed" | "auto";
@@ -4,35 +4,62 @@ let react = require("react");
4
4
 
5
5
  // src/PillNavbar/room.ts
6
6
  const ACTION = "[data-mp=\"action\"]";
7
- /**
8
- * Whether the navbar still fits its pill with this item's label open. Laid out
9
- * on a copy, removed before anything is painted: the labels on screen may be
10
- * moving, and the app's own styles count.
11
- */
12
- function fitsWith(navbar, item) {
13
- const pill = navbar.closest("[data-mp=\"pill\"]");
14
- if (!pill) return true;
15
- const index = [...navbar.querySelectorAll(ACTION)].indexOf(item);
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) {
16
9
  const copy = pill.cloneNode(false);
17
10
  for (const child of pill.children) if (child.getAttribute("data-mp") !== "panel") copy.append(child.cloneNode(true));
18
11
  copy.querySelectorAll("[id], [name]").forEach((node) => {
19
12
  node.removeAttribute("id");
20
13
  node.removeAttribute("name");
21
14
  });
22
- const copiedNavbar = copy.querySelector("[data-mp=\"navbar\"]");
23
- if (!copiedNavbar) return true;
24
- copiedNavbar.removeAttribute("data-tight");
25
- copiedNavbar.querySelectorAll(ACTION)[index]?.setAttribute("data-expanded", "");
15
+ const navbar = copy.querySelector("[data-mp=\"navbar\"]");
16
+ if (!navbar) return null;
17
+ navbar.removeAttribute("data-tight");
18
+ prepare(navbar);
26
19
  copy.querySelectorAll("[data-mp=\"navbar\"], [data-mp=\"actions\"], [data-mp=\"action\"]").forEach((node) => {
27
20
  node.style.flexShrink = "0";
28
21
  });
29
22
  copy.inert = true;
30
23
  copy.style.visibility = "hidden";
31
24
  pill.after(copy);
32
- const fits = isInside(copiedNavbar, copy);
33
- copy.remove();
25
+ return {
26
+ copy,
27
+ navbar
28
+ };
29
+ }
30
+ /**
31
+ * Whether the navbar still fits its pill with this item's label open (or as
32
+ * it is at rest, with no item; `unfold`: with the current page's label open
33
+ * even if it's folded). Laid out on a copy, removed before anything is
34
+ * painted: the labels on screen may be moving, and the app's own styles count.
35
+ */
36
+ function fitsWith(navbar, item, { unfold = false } = {}) {
37
+ const pill = navbar.closest("[data-mp=\"pill\"]");
38
+ if (!pill) return true;
39
+ 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", "");
43
+ });
44
+ if (!laidOut) return true;
45
+ const fits = isInside(laidOut.navbar, laidOut.copy);
46
+ laidOut.copy.remove();
34
47
  return fits;
35
48
  }
49
+ /**
50
+ * How wide the pill is with all its navbar's labels folded, or its own width
51
+ * if it has no navbar that can fold them (`labels="current"`). The
52
+ * satellites ask, to know whether an electron fits next to it.
53
+ */
54
+ function foldedWidth(pill) {
55
+ const navbar = pill.querySelector("[data-mp=\"navbar\"]");
56
+ 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();
61
+ return width;
62
+ }
36
63
  /** Whether the navbar ends before the pill's padding does. */
37
64
  function isInside(navbar, pill) {
38
65
  const style = getComputedStyle(pill);
@@ -45,9 +72,53 @@ const isHorizontal = (navbar) => {
45
72
  };
46
73
  /**
47
74
  * Writes `data-tight` on the navbar while the item pointed at (or focused with
48
- * the keyboard) has no room for its label next to the open ones.
75
+ * the keyboard) has no room for its label next to the open ones, and
76
+ * `data-folded` while the current page's label folds at rest (`labels`).
49
77
  */
50
- function useRoom(ref) {
78
+ function useRoom(ref, labels = "auto") {
79
+ (0, react.useEffect)(() => {
80
+ const navbar = ref.current;
81
+ if (!navbar) return;
82
+ const fold = (folded) => {
83
+ if (folded) navbar.setAttribute("data-folded", "");
84
+ else navbar.removeAttribute("data-folded");
85
+ };
86
+ if (labels !== "auto") {
87
+ fold(labels === "closed");
88
+ return () => fold(false);
89
+ }
90
+ const pill = navbar.closest("[data-mp=\"pill\"]");
91
+ let frame = 0;
92
+ const update = () => {
93
+ cancelAnimationFrame(frame);
94
+ frame = requestAnimationFrame(() => fold(isHorizontal(navbar) && !fitsWith(navbar, null, { unfold: true })));
95
+ };
96
+ fold(isHorizontal(navbar) && !fitsWith(navbar, null, { unfold: true }));
97
+ const mutations = new MutationObserver(update);
98
+ mutations.observe(navbar, {
99
+ subtree: true,
100
+ attributes: true,
101
+ attributeFilter: ["aria-current"]
102
+ });
103
+ if (pill) mutations.observe(pill, {
104
+ attributes: true,
105
+ attributeFilter: [
106
+ "style",
107
+ "data-orientation",
108
+ "data-presence"
109
+ ]
110
+ });
111
+ const sizes = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
112
+ if (pill) sizes?.observe(pill);
113
+ window.addEventListener("resize", update);
114
+ return () => {
115
+ cancelAnimationFrame(frame);
116
+ mutations.disconnect();
117
+ sizes?.disconnect();
118
+ window.removeEventListener("resize", update);
119
+ fold(false);
120
+ };
121
+ }, [ref, labels]);
51
122
  (0, react.useEffect)(() => {
52
123
  const navbar = ref.current;
53
124
  if (!navbar) return;
@@ -81,4 +152,5 @@ function useRoom(ref) {
81
152
  }
82
153
 
83
154
  exports.fitsWith = fitsWith;
155
+ exports.foldedWidth = foldedWidth;
84
156
  exports.useRoom = useRoom;
@@ -4,35 +4,62 @@ import { useEffect } from "react";
4
4
 
5
5
  // src/PillNavbar/room.ts
6
6
  const ACTION = "[data-mp=\"action\"]";
7
- /**
8
- * Whether the navbar still fits its pill with this item's label open. Laid out
9
- * on a copy, removed before anything is painted: the labels on screen may be
10
- * moving, and the app's own styles count.
11
- */
12
- function fitsWith(navbar, item) {
13
- const pill = navbar.closest("[data-mp=\"pill\"]");
14
- if (!pill) return true;
15
- const index = [...navbar.querySelectorAll(ACTION)].indexOf(item);
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) {
16
9
  const copy = pill.cloneNode(false);
17
10
  for (const child of pill.children) if (child.getAttribute("data-mp") !== "panel") copy.append(child.cloneNode(true));
18
11
  copy.querySelectorAll("[id], [name]").forEach((node) => {
19
12
  node.removeAttribute("id");
20
13
  node.removeAttribute("name");
21
14
  });
22
- const copiedNavbar = copy.querySelector("[data-mp=\"navbar\"]");
23
- if (!copiedNavbar) return true;
24
- copiedNavbar.removeAttribute("data-tight");
25
- copiedNavbar.querySelectorAll(ACTION)[index]?.setAttribute("data-expanded", "");
15
+ const navbar = copy.querySelector("[data-mp=\"navbar\"]");
16
+ if (!navbar) return null;
17
+ navbar.removeAttribute("data-tight");
18
+ prepare(navbar);
26
19
  copy.querySelectorAll("[data-mp=\"navbar\"], [data-mp=\"actions\"], [data-mp=\"action\"]").forEach((node) => {
27
20
  node.style.flexShrink = "0";
28
21
  });
29
22
  copy.inert = true;
30
23
  copy.style.visibility = "hidden";
31
24
  pill.after(copy);
32
- const fits = isInside(copiedNavbar, copy);
33
- copy.remove();
25
+ return {
26
+ copy,
27
+ navbar
28
+ };
29
+ }
30
+ /**
31
+ * Whether the navbar still fits its pill with this item's label open (or as
32
+ * it is at rest, with no item; `unfold`: with the current page's label open
33
+ * even if it's folded). Laid out on a copy, removed before anything is
34
+ * painted: the labels on screen may be moving, and the app's own styles count.
35
+ */
36
+ function fitsWith(navbar, item, { unfold = false } = {}) {
37
+ const pill = navbar.closest("[data-mp=\"pill\"]");
38
+ if (!pill) return true;
39
+ 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", "");
43
+ });
44
+ if (!laidOut) return true;
45
+ const fits = isInside(laidOut.navbar, laidOut.copy);
46
+ laidOut.copy.remove();
34
47
  return fits;
35
48
  }
49
+ /**
50
+ * How wide the pill is with all its navbar's labels folded, or its own width
51
+ * if it has no navbar that can fold them (`labels="current"`). The
52
+ * satellites ask, to know whether an electron fits next to it.
53
+ */
54
+ function foldedWidth(pill) {
55
+ const navbar = pill.querySelector("[data-mp=\"navbar\"]");
56
+ 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();
61
+ return width;
62
+ }
36
63
  /** Whether the navbar ends before the pill's padding does. */
37
64
  function isInside(navbar, pill) {
38
65
  const style = getComputedStyle(pill);
@@ -45,9 +72,53 @@ const isHorizontal = (navbar) => {
45
72
  };
46
73
  /**
47
74
  * Writes `data-tight` on the navbar while the item pointed at (or focused with
48
- * the keyboard) has no room for its label next to the open ones.
75
+ * the keyboard) has no room for its label next to the open ones, and
76
+ * `data-folded` while the current page's label folds at rest (`labels`).
49
77
  */
50
- function useRoom(ref) {
78
+ function useRoom(ref, labels = "auto") {
79
+ useEffect(() => {
80
+ const navbar = ref.current;
81
+ if (!navbar) return;
82
+ const fold = (folded) => {
83
+ if (folded) navbar.setAttribute("data-folded", "");
84
+ else navbar.removeAttribute("data-folded");
85
+ };
86
+ if (labels !== "auto") {
87
+ fold(labels === "closed");
88
+ return () => fold(false);
89
+ }
90
+ const pill = navbar.closest("[data-mp=\"pill\"]");
91
+ let frame = 0;
92
+ const update = () => {
93
+ cancelAnimationFrame(frame);
94
+ frame = requestAnimationFrame(() => fold(isHorizontal(navbar) && !fitsWith(navbar, null, { unfold: true })));
95
+ };
96
+ fold(isHorizontal(navbar) && !fitsWith(navbar, null, { unfold: true }));
97
+ const mutations = new MutationObserver(update);
98
+ mutations.observe(navbar, {
99
+ subtree: true,
100
+ attributes: true,
101
+ attributeFilter: ["aria-current"]
102
+ });
103
+ if (pill) mutations.observe(pill, {
104
+ attributes: true,
105
+ attributeFilter: [
106
+ "style",
107
+ "data-orientation",
108
+ "data-presence"
109
+ ]
110
+ });
111
+ const sizes = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
112
+ if (pill) sizes?.observe(pill);
113
+ window.addEventListener("resize", update);
114
+ return () => {
115
+ cancelAnimationFrame(frame);
116
+ mutations.disconnect();
117
+ sizes?.disconnect();
118
+ window.removeEventListener("resize", update);
119
+ fold(false);
120
+ };
121
+ }, [ref, labels]);
51
122
  useEffect(() => {
52
123
  const navbar = ref.current;
53
124
  if (!navbar) return;
@@ -80,4 +151,4 @@ function useRoom(ref) {
80
151
  }, [ref]);
81
152
  }
82
153
 
83
- export { fitsWith, useRoom };
154
+ export { fitsWith, foldedWidth, useRoom };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import Pill from "./Pill/Pill.mjs";
2
2
  import { PillActions, PillDivider, PillIcon, PillMessage } from "./Pill/parts.mjs";
3
+ import { PillProgress, PillProgressProps } from "./Pill/PillProgress.mjs";
3
4
  import PillAction from "./Pill/PillAction.mjs";
4
5
  import { PillPanel, PillPanelTrigger } from "./Pill/PillPanel.mjs";
5
6
  import { usePill } from "./Pill/PillContext.mjs";
@@ -28,7 +29,7 @@ import { CalendarLabels } from "./PillForm/Calendar.mjs";
28
29
  import { DateType } from "./PillForm/dates.mjs";
29
30
  import { PillColor, PillColorProps } from "./PillForm/PillColor.mjs";
30
31
  import MagicPill, { MagicPillProps } from "./MagicPill/MagicPill.mjs";
31
- import { DismissReason, NotifyInput, NotifyOptions, NotifyRenderOptions, PillController, PillQueueState, QueuedNotification, pill } from "./store/store.mjs";
32
+ import { DismissReason, Electron, ElectronOptions, NotifyInput, NotifyOptions, NotifyRenderOptions, Orbital, PillActionItem, PillController, PillQueueState, QueuedNotification, pill } from "./store/store.mjs";
32
33
  import { usePillQueue } from "./store/usePillQueue.mjs";
33
34
  import { IconProps as IconProps$1 } from "./icons/types.mjs";
34
35
  /** @deprecated Bring your own icons: any svg, image or icon component works (README, "Icons"). The built-in ones go in the next major version. */
@@ -57,4 +58,4 @@ export declare const PlusIcon: (props: IconProps$1) => import("react").JSX.Eleme
57
58
  export declare const UndoIcon: (props: IconProps$1) => import("react").JSX.Element;
58
59
  /** @deprecated The props of the built-in icons, which are deprecated: any `<svg>` attribute, `ComponentPropsWithoutRef<"svg">`. */
59
60
  export type IconProps = IconProps$1;
60
- export { type CalendarLabels, type DateType, type DismissReason, type FieldControlProps, type FieldProps, type LinkComponent, MagicPill, type MagicPillProps, type NavActionItem, type NavItem, type NavLinkItem, type NavPanelItem, type NotificationAction, type NotificationLayout, type NotificationPanel, type NotifyInput, type NotifyOptions, type NotifyRenderOptions, Pill, PillAction, type PillActionProps, PillActions, type PillButtonActionProps, PillCheckbox, type PillCheckboxProps, type PillChoice, PillChoices, type PillChoicesProps, PillCode, type PillCodeProps, PillColor, type PillColorProps, type PillContextValue, type PillController, PillDate, type PillDateProps, PillDivider, PillField, type PillFieldProps, PillFields, type PillFieldsProps, PillFile, type PillFileProps, PillForm, PillFormPanel, type PillFormPanelProps, type PillFormProps, PillIcon, PillInput, type PillInputProps, type PillInputType, type PillLinkActionProps, PillMessage, type PillMultipleChoiceProps, PillNavbar, type PillNavbarProps, PillNotification, type PillNotificationClassNames, type PillNotificationProps, PillOptics, type PillOption, type PillOptionGroup, type PillOrientation, PillPanel, type PillPanelProps, PillPanelTrigger, type PillPanelTriggerProps, type PillPlacement, type PillPresence, type PillProps, type PillQueueState, PillSelect, type PillSelectProps, type PillSingleChoiceProps, PillSlider, type PillSliderProps, PillStepper, type PillStepperProps, PillSubmit, type PillSubmitProps, PillSwitch, type PillSwitchProps, PillTextarea, type PillTextareaProps, type PillTheme, type PillVariant, type QueuedNotification, type SceneChange, type SendHandler, pill, usePill, usePillQueue };
61
+ export { type CalendarLabels, type DateType, type DismissReason, type Electron, type ElectronOptions, type FieldControlProps, type FieldProps, type LinkComponent, MagicPill, type MagicPillProps, type NavActionItem, type NavItem, type NavLinkItem, type NavPanelItem, type NotificationAction, type NotificationLayout, type NotificationPanel, type NotifyInput, type NotifyOptions, type NotifyRenderOptions, type Orbital, Pill, PillAction, type PillActionItem, type PillActionProps, PillActions, type PillButtonActionProps, PillCheckbox, type PillCheckboxProps, type PillChoice, PillChoices, type PillChoicesProps, PillCode, type PillCodeProps, PillColor, type PillColorProps, type PillContextValue, type PillController, PillDate, type PillDateProps, PillDivider, PillField, type PillFieldProps, PillFields, type PillFieldsProps, PillFile, type PillFileProps, PillForm, PillFormPanel, type PillFormPanelProps, type PillFormProps, PillIcon, PillInput, type PillInputProps, type PillInputType, type PillLinkActionProps, PillMessage, type PillMultipleChoiceProps, PillNavbar, type PillNavbarProps, PillNotification, type PillNotificationClassNames, type PillNotificationProps, PillOptics, type PillOption, type PillOptionGroup, type PillOrientation, PillPanel, type PillPanelProps, PillPanelTrigger, type PillPanelTriggerProps, type PillPlacement, type PillPresence, PillProgress, type PillProgressProps, type PillProps, type PillQueueState, PillSelect, type PillSelectProps, type PillSingleChoiceProps, PillSlider, type PillSliderProps, PillStepper, type PillStepperProps, PillSubmit, type PillSubmitProps, PillSwitch, type PillSwitchProps, PillTextarea, type PillTextareaProps, type PillTheme, type PillVariant, type QueuedNotification, type SceneChange, type SendHandler, pill, usePill, usePillQueue };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import Pill from "./Pill/Pill.js";
2
2
  import { PillActions, PillDivider, PillIcon, PillMessage } from "./Pill/parts.js";
3
+ import { PillProgress, PillProgressProps } from "./Pill/PillProgress.js";
3
4
  import PillAction from "./Pill/PillAction.js";
4
5
  import { PillPanel, PillPanelTrigger } from "./Pill/PillPanel.js";
5
6
  import { usePill } from "./Pill/PillContext.js";
@@ -28,7 +29,7 @@ import { CalendarLabels } from "./PillForm/Calendar.js";
28
29
  import { DateType } from "./PillForm/dates.js";
29
30
  import { PillColor, PillColorProps } from "./PillForm/PillColor.js";
30
31
  import MagicPill, { MagicPillProps } from "./MagicPill/MagicPill.js";
31
- import { DismissReason, NotifyInput, NotifyOptions, NotifyRenderOptions, PillController, PillQueueState, QueuedNotification, pill } from "./store/store.js";
32
+ import { DismissReason, Electron, ElectronOptions, NotifyInput, NotifyOptions, NotifyRenderOptions, Orbital, PillActionItem, PillController, PillQueueState, QueuedNotification, pill } from "./store/store.js";
32
33
  import { usePillQueue } from "./store/usePillQueue.js";
33
34
  import { IconProps as IconProps$1 } from "./icons/types.js";
34
35
  /** @deprecated Bring your own icons: any svg, image or icon component works (README, "Icons"). The built-in ones go in the next major version. */
@@ -57,4 +58,4 @@ export declare const PlusIcon: (props: IconProps$1) => import("react").JSX.Eleme
57
58
  export declare const UndoIcon: (props: IconProps$1) => import("react").JSX.Element;
58
59
  /** @deprecated The props of the built-in icons, which are deprecated: any `<svg>` attribute, `ComponentPropsWithoutRef<"svg">`. */
59
60
  export type IconProps = IconProps$1;
60
- export { type CalendarLabels, type DateType, type DismissReason, type FieldControlProps, type FieldProps, type LinkComponent, MagicPill, type MagicPillProps, type NavActionItem, type NavItem, type NavLinkItem, type NavPanelItem, type NotificationAction, type NotificationLayout, type NotificationPanel, type NotifyInput, type NotifyOptions, type NotifyRenderOptions, Pill, PillAction, type PillActionProps, PillActions, type PillButtonActionProps, PillCheckbox, type PillCheckboxProps, type PillChoice, PillChoices, type PillChoicesProps, PillCode, type PillCodeProps, PillColor, type PillColorProps, type PillContextValue, type PillController, PillDate, type PillDateProps, PillDivider, PillField, type PillFieldProps, PillFields, type PillFieldsProps, PillFile, type PillFileProps, PillForm, PillFormPanel, type PillFormPanelProps, type PillFormProps, PillIcon, PillInput, type PillInputProps, type PillInputType, type PillLinkActionProps, PillMessage, type PillMultipleChoiceProps, PillNavbar, type PillNavbarProps, PillNotification, type PillNotificationClassNames, type PillNotificationProps, PillOptics, type PillOption, type PillOptionGroup, type PillOrientation, PillPanel, type PillPanelProps, PillPanelTrigger, type PillPanelTriggerProps, type PillPlacement, type PillPresence, type PillProps, type PillQueueState, PillSelect, type PillSelectProps, type PillSingleChoiceProps, PillSlider, type PillSliderProps, PillStepper, type PillStepperProps, PillSubmit, type PillSubmitProps, PillSwitch, type PillSwitchProps, PillTextarea, type PillTextareaProps, type PillTheme, type PillVariant, type QueuedNotification, type SceneChange, type SendHandler, pill, usePill, usePillQueue };
61
+ export { type CalendarLabels, type DateType, type DismissReason, type Electron, type ElectronOptions, type FieldControlProps, type FieldProps, type LinkComponent, MagicPill, type MagicPillProps, type NavActionItem, type NavItem, type NavLinkItem, type NavPanelItem, type NotificationAction, type NotificationLayout, type NotificationPanel, type NotifyInput, type NotifyOptions, type NotifyRenderOptions, type Orbital, Pill, PillAction, type PillActionItem, type PillActionProps, PillActions, type PillButtonActionProps, PillCheckbox, type PillCheckboxProps, type PillChoice, PillChoices, type PillChoicesProps, PillCode, type PillCodeProps, PillColor, type PillColorProps, type PillContextValue, type PillController, PillDate, type PillDateProps, PillDivider, PillField, type PillFieldProps, PillFields, type PillFieldsProps, PillFile, type PillFileProps, PillForm, PillFormPanel, type PillFormPanelProps, type PillFormProps, PillIcon, PillInput, type PillInputProps, type PillInputType, type PillLinkActionProps, PillMessage, type PillMultipleChoiceProps, PillNavbar, type PillNavbarProps, PillNotification, type PillNotificationClassNames, type PillNotificationProps, PillOptics, type PillOption, type PillOptionGroup, type PillOrientation, PillPanel, type PillPanelProps, PillPanelTrigger, type PillPanelTriggerProps, type PillPlacement, type PillPresence, PillProgress, type PillProgressProps, type PillProps, type PillQueueState, PillSelect, type PillSelectProps, type PillSingleChoiceProps, PillSlider, type PillSliderProps, PillStepper, type PillStepperProps, PillSubmit, type PillSubmitProps, PillSwitch, type PillSwitchProps, PillTextarea, type PillTextareaProps, type PillTheme, type PillVariant, type QueuedNotification, type SceneChange, type SendHandler, pill, usePill, usePillQueue };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_Pill = require("./Pill/Pill.js");
3
3
  const require_parts = require("./Pill/parts.js");
4
+ const require_PillProgress = require("./Pill/PillProgress.js");
4
5
  const require_PillAction = require("./Pill/PillAction.js");
5
6
  const require_PillPanel = require("./Pill/PillPanel.js");
6
7
  const require_PillContext = require("./Pill/PillContext.js");
@@ -99,6 +100,7 @@ exports.PillNotification = require_PillNotification.PillNotification;
99
100
  exports.PillOptics = require_PillOptics.PillOptics;
100
101
  exports.PillPanel = require_PillPanel.PillPanel;
101
102
  exports.PillPanelTrigger = require_PillPanel.PillPanelTrigger;
103
+ exports.PillProgress = require_PillProgress.PillProgress;
102
104
  exports.PillSelect = require_PillSelect.PillSelect;
103
105
  exports.PillSlider = require_PillSlider.PillSlider;
104
106
  exports.PillStepper = require_PillStepper.PillStepper;
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import Pill from "./Pill/Pill.mjs";
2
2
  import { PillActions, PillDivider, PillIcon, PillMessage } from "./Pill/parts.mjs";
3
+ import { PillProgress } from "./Pill/PillProgress.mjs";
3
4
  import PillAction from "./Pill/PillAction.mjs";
4
5
  import { PillPanel, PillPanelTrigger } from "./Pill/PillPanel.mjs";
5
6
  import { usePill } from "./Pill/PillContext.mjs";
@@ -65,4 +66,4 @@ const PlusIcon = PlusIcon$1;
65
66
  /** @deprecated Bring your own icons: any svg, image or icon component works (README, "Icons"). The built-in ones go in the next major version. */
66
67
  const UndoIcon = UndoIcon$1;
67
68
 
68
- export { ArrowIcon, BoxIcon, CheckIcon, CloseIcon, CouponIcon, DocumentIcon, HelpIcon, InfoIcon, MagicPill, MailIcon, PhoneIcon, Pill, PillAction, PillActions, PillCheckbox, PillChoices, PillCode, PillColor, PillDate, PillDivider, PillField, PillFields, PillFile, PillForm, PillFormPanel, PillIcon, PillInput, PillMessage, PillNavbar, PillNotification, PillOptics, PillPanel, PillPanelTrigger, PillSelect, PillSlider, PillStepper, PillSubmit, PillSwitch, PillTextarea, PlusIcon, UndoIcon, pill, usePill, usePillQueue };
69
+ export { ArrowIcon, BoxIcon, CheckIcon, CloseIcon, CouponIcon, DocumentIcon, HelpIcon, InfoIcon, MagicPill, MailIcon, PhoneIcon, Pill, PillAction, PillActions, PillCheckbox, PillChoices, PillCode, PillColor, PillDate, PillDivider, PillField, PillFields, PillFile, PillForm, PillFormPanel, PillIcon, PillInput, PillMessage, PillNavbar, PillNotification, PillOptics, PillPanel, PillPanelTrigger, PillProgress, PillSelect, PillSlider, PillStepper, PillSubmit, PillSwitch, PillTextarea, PlusIcon, UndoIcon, pill, usePill, usePillQueue };
@@ -0,0 +1,12 @@
1
+ import "react";
2
+ import { PillActionItem } from "../store/store.mjs";
3
+ import "./types.mjs";
4
+ /**
5
+ * Sets the current page's actions while the calling component is mounted:
6
+ * call it in a page, and they show next to the pill there, and go when the
7
+ * page goes. `null` or none: no actions. Give a stable array (a constant or
8
+ * `useMemo`), or they're set again at every render.
9
+ */
10
+ export declare function usePillActions(items: readonly PillActionItem[] | null, options?: {
11
+ pill?: string;
12
+ }): void;
@@ -0,0 +1,11 @@
1
+ import { PillActionItem } from "../store/store.js";
2
+ import "./types.js";
3
+ /**
4
+ * Sets the current page's actions while the calling component is mounted:
5
+ * call it in a page, and they show next to the pill there, and go when the
6
+ * page goes. `null` or none: no actions. Give a stable array (a constant or
7
+ * `useMemo`), or they're set again at every render.
8
+ */
9
+ export declare function usePillActions(items: readonly PillActionItem[] | null, options?: {
10
+ pill?: string;
11
+ }): void;
@@ -0,0 +1,181 @@
1
+ "use client";
2
+
3
+ let react = require("react");
4
+ const require_PillAction = require("../Pill/PillAction.js");
5
+ const require_parts = require("../Pill/parts.js");
6
+ const require_store = require("../store/store.js");
7
+ let react_jsx_runtime = require("react/jsx-runtime");
8
+
9
+ // src/satellites/Actions.tsx
10
+ /**
11
+ * Sets the current page's actions while the calling component is mounted:
12
+ * call it in a page, and they show next to the pill there, and go when the
13
+ * page goes. `null` or none: no actions. Give a stable array (a constant or
14
+ * `useMemo`), or they're set again at every render.
15
+ */
16
+ function usePillActions(items, options = {}) {
17
+ const store = require_store.getStore(options.pill ?? "main");
18
+ (0, react.useEffect)(() => {
19
+ store.setActions(items);
20
+ return () => {
21
+ if (store.getActions() === items) store.setActions(null);
22
+ };
23
+ }, [store, items]);
24
+ }
25
+ /** The host's page actions, as they change. */
26
+ function useHostActions(host) {
27
+ return (0, react.useSyncExternalStore)(host.store.subscribe, host.store.getActions, () => null);
28
+ }
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
+ (0, react.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 = (0, react.useRef)(null);
144
+ useActionsWheel(track);
145
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.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__ */ (0, react_jsx_runtime.jsx)(require_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__ */ (0, react_jsx_runtime.jsx)(require_PillAction, {
158
+ icon: item.icon,
159
+ label: item.label,
160
+ expanded: item.expanded,
161
+ onClick: item.onClick
162
+ }, item.id ?? item.label))
163
+ });
164
+ }
165
+ /** In the pill itself (`actionsStyle="inside"`): the actions, then a divider (the other way round on the end side). */
166
+ function InsideActions({ host }) {
167
+ const items = useHostActions(host);
168
+ if (!items) return null;
169
+ const list = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ActionList, {
170
+ items,
171
+ host,
172
+ inside: true
173
+ });
174
+ return host.actionsSide === "end" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillDivider, {}), list] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [list, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillDivider, {})] });
175
+ }
176
+
177
+ exports.ActionList = ActionList;
178
+ exports.InsideActions = InsideActions;
179
+ exports.useActionsWheel = useActionsWheel;
180
+ exports.useHostActions = useHostActions;
181
+ exports.usePillActions = usePillActions;