magic-pill 9.0.0-next.0 → 9.0.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 +15 -0
- package/README.md +6 -2
- package/dist/MagicPill/MagicPill.js +194 -2
- package/dist/MagicPill/MagicPill.mjs +194 -2
- package/dist/MagicPill/choreography.js +132 -2
- package/dist/MagicPill/choreography.mjs +125 -2
- package/dist/Pill/Pill.js +106 -2
- package/dist/Pill/Pill.mjs +106 -2
- package/dist/Pill/PillAction.js +67 -2
- package/dist/Pill/PillAction.mjs +67 -2
- package/dist/Pill/PillContext.js +26 -2
- package/dist/Pill/PillContext.mjs +24 -2
- package/dist/Pill/PillPanel.js +90 -2
- package/dist/Pill/PillPanel.mjs +89 -2
- package/dist/Pill/parts.js +46 -2
- package/dist/Pill/parts.mjs +43 -2
- package/dist/PillNavbar/PillNavbar.js +44 -2
- package/dist/PillNavbar/PillNavbar.mjs +44 -2
- package/dist/PillNavbar/matchPath.js +34 -2
- package/dist/PillNavbar/matchPath.mjs +34 -2
- package/dist/PillNotification/PillNotification.js +64 -2
- package/dist/PillNotification/PillNotification.mjs +63 -2
- package/dist/icons/ArrowIcon.js +21 -2
- package/dist/icons/ArrowIcon.mjs +21 -2
- package/dist/icons/BoxIcon.js +21 -2
- package/dist/icons/BoxIcon.mjs +21 -2
- package/dist/icons/CheckIcon.js +17 -2
- package/dist/icons/CheckIcon.mjs +17 -2
- package/dist/icons/CloseIcon.js +17 -2
- package/dist/icons/CloseIcon.mjs +17 -2
- package/dist/icons/CouponIcon.js +17 -2
- package/dist/icons/CouponIcon.mjs +17 -2
- package/dist/icons/DocumentIcon.js +17 -2
- package/dist/icons/DocumentIcon.mjs +17 -2
- package/dist/icons/HelpIcon.js +17 -2
- package/dist/icons/HelpIcon.mjs +17 -2
- package/dist/icons/InfoIcon.js +17 -2
- package/dist/icons/InfoIcon.mjs +17 -2
- package/dist/icons/MailIcon.js +17 -2
- package/dist/icons/MailIcon.mjs +17 -2
- package/dist/icons/PhoneIcon.js +21 -2
- package/dist/icons/PhoneIcon.mjs +21 -2
- package/dist/icons/PlusIcon.js +17 -2
- package/dist/icons/PlusIcon.mjs +17 -2
- package/dist/icons/UndoIcon.js +21 -2
- package/dist/icons/UndoIcon.mjs +21 -2
- package/dist/index.js +50 -1
- package/dist/index.mjs +24 -1
- package/dist/store/store.js +104 -2
- package/dist/store/store.mjs +102 -2
- package/dist/store/usePillQueue.js +17 -2
- package/dist/store/usePillQueue.mjs +17 -2
- package/dist/styles.css +125 -35
- package/dist/utils/inputModality.js +23 -0
- package/dist/utils/inputModality.mjs +22 -0
- package/dist/utils/react.js +23 -2
- package/dist/utils/react.mjs +21 -2
- package/dist/utils/url.js +22 -2
- package/dist/utils/url.mjs +22 -2
- package/package.json +3 -2
- package/dist/MagicPill/MagicPill.js.map +0 -1
- package/dist/MagicPill/MagicPill.mjs.map +0 -1
- package/dist/MagicPill/choreography.js.map +0 -1
- package/dist/MagicPill/choreography.mjs.map +0 -1
- package/dist/Pill/Pill.js.map +0 -1
- package/dist/Pill/Pill.mjs.map +0 -1
- package/dist/Pill/PillAction.js.map +0 -1
- package/dist/Pill/PillAction.mjs.map +0 -1
- package/dist/Pill/PillContext.js.map +0 -1
- package/dist/Pill/PillContext.mjs.map +0 -1
- package/dist/Pill/PillPanel.js.map +0 -1
- package/dist/Pill/PillPanel.mjs.map +0 -1
- package/dist/Pill/parts.js.map +0 -1
- package/dist/Pill/parts.mjs.map +0 -1
- package/dist/PillNavbar/PillNavbar.js.map +0 -1
- package/dist/PillNavbar/PillNavbar.mjs.map +0 -1
- package/dist/PillNavbar/matchPath.js.map +0 -1
- package/dist/PillNavbar/matchPath.mjs.map +0 -1
- package/dist/PillNotification/PillNotification.js.map +0 -1
- package/dist/PillNotification/PillNotification.mjs.map +0 -1
- package/dist/icons/ArrowIcon.js.map +0 -1
- package/dist/icons/ArrowIcon.mjs.map +0 -1
- package/dist/icons/BoxIcon.js.map +0 -1
- package/dist/icons/BoxIcon.mjs.map +0 -1
- package/dist/icons/CheckIcon.js.map +0 -1
- package/dist/icons/CheckIcon.mjs.map +0 -1
- package/dist/icons/CloseIcon.js.map +0 -1
- package/dist/icons/CloseIcon.mjs.map +0 -1
- package/dist/icons/CouponIcon.js.map +0 -1
- package/dist/icons/CouponIcon.mjs.map +0 -1
- package/dist/icons/DocumentIcon.js.map +0 -1
- package/dist/icons/DocumentIcon.mjs.map +0 -1
- package/dist/icons/HelpIcon.js.map +0 -1
- package/dist/icons/HelpIcon.mjs.map +0 -1
- package/dist/icons/InfoIcon.js.map +0 -1
- package/dist/icons/InfoIcon.mjs.map +0 -1
- package/dist/icons/MailIcon.js.map +0 -1
- package/dist/icons/MailIcon.mjs.map +0 -1
- package/dist/icons/PhoneIcon.js.map +0 -1
- package/dist/icons/PhoneIcon.mjs.map +0 -1
- package/dist/icons/PlusIcon.js.map +0 -1
- package/dist/icons/PlusIcon.mjs.map +0 -1
- package/dist/icons/UndoIcon.js.map +0 -1
- package/dist/icons/UndoIcon.mjs.map +0 -1
- package/dist/store/store.js.map +0 -1
- package/dist/store/store.mjs.map +0 -1
- package/dist/store/usePillQueue.js.map +0 -1
- package/dist/store/usePillQueue.mjs.map +0 -1
- package/dist/utils/react.js.map +0 -1
- package/dist/utils/react.mjs.map +0 -1
- package/dist/utils/url.js.map +0 -1
- package/dist/utils/url.mjs.map +0 -1
package/dist/Pill/PillPanel.mjs
CHANGED
|
@@ -1,2 +1,89 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useEffect, useId, useMemo, useRef } from "react";
|
|
4
|
+
import PillAction from "./PillAction.mjs";
|
|
5
|
+
import { useInternalPill } from "./PillContext.mjs";
|
|
6
|
+
import CloseIcon from "../icons/CloseIcon.mjs";
|
|
7
|
+
import { getInputModality, trackInputModality } from "../utils/inputModality.mjs";
|
|
8
|
+
import { mergeRefs } from "../utils/react.mjs";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
|
|
11
|
+
// src/Pill/PillPanel.tsx
|
|
12
|
+
/**
|
|
13
|
+
* Content shown when the pill's presence is `panel` (one panel per pill).
|
|
14
|
+
* Labelled by its title, focused when it opens, gives focus back to its
|
|
15
|
+
* trigger when it closes.
|
|
16
|
+
*/
|
|
17
|
+
const PillPanel = forwardRef(function PillPanel({ title, closeLabel = "Close", closeIcon, children, ...rest }, forwardedRef) {
|
|
18
|
+
const { presence, closePanel, panelId, panelTriggerRef, rootRef } = useInternalPill("<PillPanel>");
|
|
19
|
+
const isOpen = presence === "panel";
|
|
20
|
+
const titleId = useId();
|
|
21
|
+
const panelRef = useRef(null);
|
|
22
|
+
const ref = useMemo(() => mergeRefs(panelRef, forwardedRef), [forwardedRef]);
|
|
23
|
+
const wasOpenRef = useRef(isOpen);
|
|
24
|
+
useEffect(trackInputModality, []);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const wasOpen = wasOpenRef.current;
|
|
27
|
+
wasOpenRef.current = isOpen;
|
|
28
|
+
if (isOpen && !wasOpen) panelRef.current?.focus({ preventScroll: true });
|
|
29
|
+
else if (!isOpen && wasOpen) {
|
|
30
|
+
const active = document.activeElement;
|
|
31
|
+
if (!active || active === document.body || rootRef.current?.contains(active)) panelTriggerRef.current?.focus(getInputModality() === "pointer" ? { focusVisible: false } : void 0);
|
|
32
|
+
}
|
|
33
|
+
}, [
|
|
34
|
+
isOpen,
|
|
35
|
+
panelTriggerRef,
|
|
36
|
+
rootRef
|
|
37
|
+
]);
|
|
38
|
+
const hasTitle = title !== void 0 && title !== null;
|
|
39
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
40
|
+
...rest,
|
|
41
|
+
ref,
|
|
42
|
+
id: panelId,
|
|
43
|
+
"data-mp": "panel",
|
|
44
|
+
"data-open": isOpen ? "" : void 0,
|
|
45
|
+
role: "region",
|
|
46
|
+
"aria-labelledby": hasTitle ? titleId : void 0,
|
|
47
|
+
tabIndex: -1,
|
|
48
|
+
children: [
|
|
49
|
+
hasTitle && /* @__PURE__ */ jsx("div", {
|
|
50
|
+
id: titleId,
|
|
51
|
+
"data-mp": "panel-title",
|
|
52
|
+
children: title
|
|
53
|
+
}),
|
|
54
|
+
/* @__PURE__ */ jsx("div", {
|
|
55
|
+
"data-mp": "panel-body",
|
|
56
|
+
children
|
|
57
|
+
}),
|
|
58
|
+
/* @__PURE__ */ jsx("div", {
|
|
59
|
+
"data-mp": "panel-footer",
|
|
60
|
+
children: /* @__PURE__ */ jsx(PillAction, {
|
|
61
|
+
icon: closeIcon ?? /* @__PURE__ */ jsx(CloseIcon, {}),
|
|
62
|
+
label: closeLabel,
|
|
63
|
+
onClick: closePanel
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
]
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
/** An action that opens (and closes) the pill's panel. */
|
|
70
|
+
const PillPanelTrigger = forwardRef(function PillPanelTrigger(props, forwardedRef) {
|
|
71
|
+
const { presence, setPresence, closePanel, panelId, panelTriggerRef } = useInternalPill("<PillPanelTrigger>");
|
|
72
|
+
const isOpen = presence === "panel";
|
|
73
|
+
const triggerRef = useRef(null);
|
|
74
|
+
const ref = useMemo(() => mergeRefs(triggerRef, forwardedRef), [forwardedRef]);
|
|
75
|
+
const toggle = () => {
|
|
76
|
+
panelTriggerRef.current = triggerRef.current;
|
|
77
|
+
if (isOpen) closePanel();
|
|
78
|
+
else setPresence("panel");
|
|
79
|
+
};
|
|
80
|
+
return /* @__PURE__ */ jsx(PillAction, {
|
|
81
|
+
...props,
|
|
82
|
+
ref,
|
|
83
|
+
"aria-expanded": isOpen,
|
|
84
|
+
"aria-controls": panelId,
|
|
85
|
+
onClick: toggle
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export { PillPanel, PillPanelTrigger };
|
package/dist/Pill/parts.js
CHANGED
|
@@ -1,2 +1,46 @@
|
|
|
1
|
-
let
|
|
2
|
-
|
|
1
|
+
let react = require("react");
|
|
2
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
3
|
+
|
|
4
|
+
// src/Pill/parts.tsx
|
|
5
|
+
/** The leading icon. Decorative (`aria-hidden`) unless you give it a `label`. */
|
|
6
|
+
const PillIcon = (0, react.forwardRef)(function PillIcon({ label, ...rest }, ref) {
|
|
7
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
8
|
+
...label ? {
|
|
9
|
+
role: "img",
|
|
10
|
+
"aria-label": label
|
|
11
|
+
} : { "aria-hidden": true },
|
|
12
|
+
...rest,
|
|
13
|
+
ref,
|
|
14
|
+
"data-mp": "icon"
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
/** The thin line between the icon and the message. */
|
|
18
|
+
const PillDivider = (0, react.forwardRef)(function PillDivider(props, ref) {
|
|
19
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
20
|
+
"aria-hidden": "true",
|
|
21
|
+
...props,
|
|
22
|
+
ref,
|
|
23
|
+
"data-mp": "divider"
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
/** The message, in the italic serif. Accepts any content. */
|
|
27
|
+
const PillMessage = (0, react.forwardRef)(function PillMessage(props, ref) {
|
|
28
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
29
|
+
...props,
|
|
30
|
+
ref,
|
|
31
|
+
"data-mp": "message"
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
/** A row (or a column, in a vertical pill) of actions. */
|
|
35
|
+
const PillActions = (0, react.forwardRef)(function PillActions(props, ref) {
|
|
36
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
37
|
+
...props,
|
|
38
|
+
ref,
|
|
39
|
+
"data-mp": "actions"
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
exports.PillActions = PillActions;
|
|
44
|
+
exports.PillDivider = PillDivider;
|
|
45
|
+
exports.PillIcon = PillIcon;
|
|
46
|
+
exports.PillMessage = PillMessage;
|
package/dist/Pill/parts.mjs
CHANGED
|
@@ -1,2 +1,43 @@
|
|
|
1
|
-
import{forwardRef
|
|
2
|
-
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
// src/Pill/parts.tsx
|
|
5
|
+
/** The leading icon. Decorative (`aria-hidden`) unless you give it a `label`. */
|
|
6
|
+
const PillIcon = forwardRef(function PillIcon({ label, ...rest }, ref) {
|
|
7
|
+
return /* @__PURE__ */ jsx("span", {
|
|
8
|
+
...label ? {
|
|
9
|
+
role: "img",
|
|
10
|
+
"aria-label": label
|
|
11
|
+
} : { "aria-hidden": true },
|
|
12
|
+
...rest,
|
|
13
|
+
ref,
|
|
14
|
+
"data-mp": "icon"
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
/** The thin line between the icon and the message. */
|
|
18
|
+
const PillDivider = forwardRef(function PillDivider(props, ref) {
|
|
19
|
+
return /* @__PURE__ */ jsx("span", {
|
|
20
|
+
"aria-hidden": "true",
|
|
21
|
+
...props,
|
|
22
|
+
ref,
|
|
23
|
+
"data-mp": "divider"
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
/** The message, in the italic serif. Accepts any content. */
|
|
27
|
+
const PillMessage = forwardRef(function PillMessage(props, ref) {
|
|
28
|
+
return /* @__PURE__ */ jsx("div", {
|
|
29
|
+
...props,
|
|
30
|
+
ref,
|
|
31
|
+
"data-mp": "message"
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
/** A row (or a column, in a vertical pill) of actions. */
|
|
35
|
+
const PillActions = forwardRef(function PillActions(props, ref) {
|
|
36
|
+
return /* @__PURE__ */ jsx("div", {
|
|
37
|
+
...props,
|
|
38
|
+
ref,
|
|
39
|
+
"data-mp": "actions"
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export { PillActions, PillDivider, PillIcon, PillMessage };
|
|
@@ -1,2 +1,44 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
let react = require("react");
|
|
4
|
+
const require_parts = require("../Pill/parts.js");
|
|
5
|
+
const require_PillAction = require("../Pill/PillAction.js");
|
|
6
|
+
const require_matchPath = require("./matchPath.js");
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
|
|
9
|
+
// src/PillNavbar/PillNavbar.tsx
|
|
10
|
+
/** Without a `pathname` prop: the browser's path, read after mounting (no hydration mismatch). */
|
|
11
|
+
function useLocationPathname(enabled) {
|
|
12
|
+
const [pathname, setPathname] = (0, react.useState)(void 0);
|
|
13
|
+
(0, react.useEffect)(() => {
|
|
14
|
+
if (!enabled) return;
|
|
15
|
+
const update = () => setPathname(window.location.pathname);
|
|
16
|
+
update();
|
|
17
|
+
window.addEventListener("popstate", update);
|
|
18
|
+
return () => window.removeEventListener("popstate", update);
|
|
19
|
+
}, [enabled]);
|
|
20
|
+
return pathname;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A <nav> of icon links. The active one shows its label and gets
|
|
24
|
+
* `aria-current="page"`. Render it inside a <Pill>, or as the base layer of a <MagicPill>.
|
|
25
|
+
*/
|
|
26
|
+
const PillNavbar = (0, react.forwardRef)(function PillNavbar({ items, pathname, linkComponent, "aria-label": ariaLabel = "Main", ...rest }, ref) {
|
|
27
|
+
const locationPathname = useLocationPathname(pathname === void 0);
|
|
28
|
+
const activeIndex = require_matchPath.findActiveIndex(pathname ?? locationPathname, items);
|
|
29
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("nav", {
|
|
30
|
+
"aria-label": ariaLabel,
|
|
31
|
+
...rest,
|
|
32
|
+
ref,
|
|
33
|
+
"data-mp": "navbar",
|
|
34
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillActions, { children: items.map((item, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillAction, {
|
|
35
|
+
icon: item.icon,
|
|
36
|
+
label: item.label,
|
|
37
|
+
href: item.href,
|
|
38
|
+
linkComponent,
|
|
39
|
+
"aria-current": index === activeIndex ? "page" : void 0
|
|
40
|
+
}, item.href)) })
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
exports.PillNavbar = PillNavbar;
|
|
@@ -1,2 +1,44 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useEffect, useState } from "react";
|
|
4
|
+
import { PillActions } from "../Pill/parts.mjs";
|
|
5
|
+
import PillAction from "../Pill/PillAction.mjs";
|
|
6
|
+
import { findActiveIndex } from "./matchPath.mjs";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
|
|
9
|
+
// src/PillNavbar/PillNavbar.tsx
|
|
10
|
+
/** Without a `pathname` prop: the browser's path, read after mounting (no hydration mismatch). */
|
|
11
|
+
function useLocationPathname(enabled) {
|
|
12
|
+
const [pathname, setPathname] = useState(void 0);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (!enabled) return;
|
|
15
|
+
const update = () => setPathname(window.location.pathname);
|
|
16
|
+
update();
|
|
17
|
+
window.addEventListener("popstate", update);
|
|
18
|
+
return () => window.removeEventListener("popstate", update);
|
|
19
|
+
}, [enabled]);
|
|
20
|
+
return pathname;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A <nav> of icon links. The active one shows its label and gets
|
|
24
|
+
* `aria-current="page"`. Render it inside a <Pill>, or as the base layer of a <MagicPill>.
|
|
25
|
+
*/
|
|
26
|
+
const PillNavbar = forwardRef(function PillNavbar({ items, pathname, linkComponent, "aria-label": ariaLabel = "Main", ...rest }, ref) {
|
|
27
|
+
const locationPathname = useLocationPathname(pathname === void 0);
|
|
28
|
+
const activeIndex = findActiveIndex(pathname ?? locationPathname, items);
|
|
29
|
+
return /* @__PURE__ */ jsx("nav", {
|
|
30
|
+
"aria-label": ariaLabel,
|
|
31
|
+
...rest,
|
|
32
|
+
ref,
|
|
33
|
+
"data-mp": "navbar",
|
|
34
|
+
children: /* @__PURE__ */ jsx(PillActions, { children: items.map((item, index) => /* @__PURE__ */ jsx(PillAction, {
|
|
35
|
+
icon: item.icon,
|
|
36
|
+
label: item.label,
|
|
37
|
+
href: item.href,
|
|
38
|
+
linkComponent,
|
|
39
|
+
"aria-current": index === activeIndex ? "page" : void 0
|
|
40
|
+
}, item.href)) })
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export { PillNavbar };
|
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/PillNavbar/matchPath.ts
|
|
2
|
+
/** "/blog/?q=1#top" → "/blog": no query, no hash, no trailing slash (except the root). */
|
|
3
|
+
function normalisePath(path) {
|
|
4
|
+
const withoutSuffix = path.split(/[?#]/, 1)[0];
|
|
5
|
+
return withoutSuffix.length > 1 ? withoutSuffix.replace(/\/+$/, "") || "/" : withoutSuffix;
|
|
6
|
+
}
|
|
7
|
+
function matches(pathname, item) {
|
|
8
|
+
if (typeof item.match === "function") return item.match(pathname);
|
|
9
|
+
if (!item.href.startsWith("/") || item.href.startsWith("//")) return false;
|
|
10
|
+
const path = normalisePath(pathname);
|
|
11
|
+
const href = normalisePath(item.href);
|
|
12
|
+
if (item.match === "exact" || href === "/") return path === href;
|
|
13
|
+
return path === href || path.startsWith(`${href}/`);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The index of the active item, or -1. Several items can match ("/blog" and
|
|
17
|
+
* "/blog/drafts" on "/blog/drafts/1"): the longest href wins, so exactly one
|
|
18
|
+
* item is active.
|
|
19
|
+
*/
|
|
20
|
+
function findActiveIndex(pathname, items) {
|
|
21
|
+
if (pathname === void 0) return -1;
|
|
22
|
+
let activeIndex = -1;
|
|
23
|
+
let activeLength = -1;
|
|
24
|
+
items.forEach((item, index) => {
|
|
25
|
+
const length = normalisePath(item.href).length;
|
|
26
|
+
if (length > activeLength && matches(pathname, item)) {
|
|
27
|
+
activeIndex = index;
|
|
28
|
+
activeLength = length;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return activeIndex;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.findActiveIndex = findActiveIndex;
|
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/PillNavbar/matchPath.ts
|
|
2
|
+
/** "/blog/?q=1#top" → "/blog": no query, no hash, no trailing slash (except the root). */
|
|
3
|
+
function normalisePath(path) {
|
|
4
|
+
const withoutSuffix = path.split(/[?#]/, 1)[0];
|
|
5
|
+
return withoutSuffix.length > 1 ? withoutSuffix.replace(/\/+$/, "") || "/" : withoutSuffix;
|
|
6
|
+
}
|
|
7
|
+
function matches(pathname, item) {
|
|
8
|
+
if (typeof item.match === "function") return item.match(pathname);
|
|
9
|
+
if (!item.href.startsWith("/") || item.href.startsWith("//")) return false;
|
|
10
|
+
const path = normalisePath(pathname);
|
|
11
|
+
const href = normalisePath(item.href);
|
|
12
|
+
if (item.match === "exact" || href === "/") return path === href;
|
|
13
|
+
return path === href || path.startsWith(`${href}/`);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The index of the active item, or -1. Several items can match ("/blog" and
|
|
17
|
+
* "/blog/drafts" on "/blog/drafts/1"): the longest href wins, so exactly one
|
|
18
|
+
* item is active.
|
|
19
|
+
*/
|
|
20
|
+
function findActiveIndex(pathname, items) {
|
|
21
|
+
if (pathname === void 0) return -1;
|
|
22
|
+
let activeIndex = -1;
|
|
23
|
+
let activeLength = -1;
|
|
24
|
+
items.forEach((item, index) => {
|
|
25
|
+
const length = normalisePath(item.href).length;
|
|
26
|
+
if (length > activeLength && matches(pathname, item)) {
|
|
27
|
+
activeIndex = index;
|
|
28
|
+
activeLength = length;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return activeIndex;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { findActiveIndex };
|
|
@@ -1,2 +1,64 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const require_parts = require("../Pill/parts.js");
|
|
2
|
+
const require_PillAction = require("../Pill/PillAction.js");
|
|
3
|
+
const require_PillPanel = require("../Pill/PillPanel.js");
|
|
4
|
+
const require_PlusIcon = require("../icons/PlusIcon.js");
|
|
5
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
|
+
|
|
7
|
+
// src/PillNotification/PillNotification.tsx
|
|
8
|
+
/** The implementation, with the host-only `onAction` hook. */
|
|
9
|
+
function NotificationContent({ icon, message, action, panel, linkComponent, classNames = {}, onAction }) {
|
|
10
|
+
const hasIcon = icon !== void 0 && icon !== null;
|
|
11
|
+
const renderAction = (notificationAction) => {
|
|
12
|
+
const { icon: actionIcon, label } = notificationAction;
|
|
13
|
+
if (notificationAction.href !== void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillAction, {
|
|
14
|
+
icon: actionIcon,
|
|
15
|
+
label,
|
|
16
|
+
href: notificationAction.href,
|
|
17
|
+
linkComponent,
|
|
18
|
+
className: classNames.action,
|
|
19
|
+
onClick: onAction
|
|
20
|
+
});
|
|
21
|
+
const { onClick } = notificationAction;
|
|
22
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillAction, {
|
|
23
|
+
icon: actionIcon,
|
|
24
|
+
label,
|
|
25
|
+
className: classNames.action,
|
|
26
|
+
onClick: (event) => {
|
|
27
|
+
onClick(event);
|
|
28
|
+
onAction?.(event);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
33
|
+
hasIcon && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillIcon, {
|
|
34
|
+
className: classNames.icon,
|
|
35
|
+
children: icon
|
|
36
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillDivider, { className: classNames.divider })] }),
|
|
37
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillMessage, {
|
|
38
|
+
className: classNames.message,
|
|
39
|
+
children: message
|
|
40
|
+
}),
|
|
41
|
+
(action || panel) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_parts.PillActions, {
|
|
42
|
+
className: classNames.actions,
|
|
43
|
+
children: [action && renderAction(action), panel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillPanel.PillPanelTrigger, {
|
|
44
|
+
icon: panel.trigger ? panel.trigger.icon : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PlusIcon, {}),
|
|
45
|
+
label: panel.trigger?.label ?? "Learn more",
|
|
46
|
+
className: classNames.action
|
|
47
|
+
})]
|
|
48
|
+
}),
|
|
49
|
+
panel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillPanel.PillPanel, {
|
|
50
|
+
title: panel.title,
|
|
51
|
+
closeLabel: panel.closeLabel,
|
|
52
|
+
className: classNames.panel,
|
|
53
|
+
children: panel.content
|
|
54
|
+
})
|
|
55
|
+
] });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Icon · divider · message · action, with an optional expandable panel.
|
|
59
|
+
* Render it inside a <Pill>, or let <MagicPill> render it for pill().notify().
|
|
60
|
+
*/
|
|
61
|
+
const PillNotification = NotificationContent;
|
|
62
|
+
|
|
63
|
+
exports.NotificationContent = NotificationContent;
|
|
64
|
+
exports.PillNotification = PillNotification;
|
|
@@ -1,2 +1,63 @@
|
|
|
1
|
-
import{PillActions
|
|
2
|
-
|
|
1
|
+
import { PillActions, PillDivider, PillIcon, PillMessage } from "../Pill/parts.mjs";
|
|
2
|
+
import PillAction from "../Pill/PillAction.mjs";
|
|
3
|
+
import { PillPanel, PillPanelTrigger } from "../Pill/PillPanel.mjs";
|
|
4
|
+
import PlusIcon from "../icons/PlusIcon.mjs";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
// src/PillNotification/PillNotification.tsx
|
|
8
|
+
/** The implementation, with the host-only `onAction` hook. */
|
|
9
|
+
function NotificationContent({ icon, message, action, panel, linkComponent, classNames = {}, onAction }) {
|
|
10
|
+
const hasIcon = icon !== void 0 && icon !== null;
|
|
11
|
+
const renderAction = (notificationAction) => {
|
|
12
|
+
const { icon: actionIcon, label } = notificationAction;
|
|
13
|
+
if (notificationAction.href !== void 0) return /* @__PURE__ */ jsx(PillAction, {
|
|
14
|
+
icon: actionIcon,
|
|
15
|
+
label,
|
|
16
|
+
href: notificationAction.href,
|
|
17
|
+
linkComponent,
|
|
18
|
+
className: classNames.action,
|
|
19
|
+
onClick: onAction
|
|
20
|
+
});
|
|
21
|
+
const { onClick } = notificationAction;
|
|
22
|
+
return /* @__PURE__ */ jsx(PillAction, {
|
|
23
|
+
icon: actionIcon,
|
|
24
|
+
label,
|
|
25
|
+
className: classNames.action,
|
|
26
|
+
onClick: (event) => {
|
|
27
|
+
onClick(event);
|
|
28
|
+
onAction?.(event);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
33
|
+
hasIcon && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(PillIcon, {
|
|
34
|
+
className: classNames.icon,
|
|
35
|
+
children: icon
|
|
36
|
+
}), /* @__PURE__ */ jsx(PillDivider, { className: classNames.divider })] }),
|
|
37
|
+
/* @__PURE__ */ jsx(PillMessage, {
|
|
38
|
+
className: classNames.message,
|
|
39
|
+
children: message
|
|
40
|
+
}),
|
|
41
|
+
(action || panel) && /* @__PURE__ */ jsxs(PillActions, {
|
|
42
|
+
className: classNames.actions,
|
|
43
|
+
children: [action && renderAction(action), panel && /* @__PURE__ */ jsx(PillPanelTrigger, {
|
|
44
|
+
icon: panel.trigger ? panel.trigger.icon : /* @__PURE__ */ jsx(PlusIcon, {}),
|
|
45
|
+
label: panel.trigger?.label ?? "Learn more",
|
|
46
|
+
className: classNames.action
|
|
47
|
+
})]
|
|
48
|
+
}),
|
|
49
|
+
panel && /* @__PURE__ */ jsx(PillPanel, {
|
|
50
|
+
title: panel.title,
|
|
51
|
+
closeLabel: panel.closeLabel,
|
|
52
|
+
className: classNames.panel,
|
|
53
|
+
children: panel.content
|
|
54
|
+
})
|
|
55
|
+
] });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Icon · divider · message · action, with an optional expandable panel.
|
|
59
|
+
* Render it inside a <Pill>, or let <MagicPill> render it for pill().notify().
|
|
60
|
+
*/
|
|
61
|
+
const PillNotification = NotificationContent;
|
|
62
|
+
|
|
63
|
+
export { NotificationContent, PillNotification };
|
package/dist/icons/ArrowIcon.js
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
let
|
|
2
|
-
|
|
1
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
2
|
+
|
|
3
|
+
// src/icons/ArrowIcon.tsx
|
|
4
|
+
/** v9 icon (from `arrow_label`): drawn in `currentColor`, decorative by default. */
|
|
5
|
+
const ArrowIcon = (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
6
|
+
width: "1em",
|
|
7
|
+
height: "1em",
|
|
8
|
+
viewBox: "0 0 31 20",
|
|
9
|
+
fill: "currentColor",
|
|
10
|
+
"aria-hidden": "true",
|
|
11
|
+
focusable: "false",
|
|
12
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
13
|
+
...props,
|
|
14
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
15
|
+
fillRule: "evenodd",
|
|
16
|
+
clipRule: "evenodd",
|
|
17
|
+
d: "M0.813004 10.2755C0.813004 9.69059 1.28715 9.21645 1.87204 9.21645L26.8501 9.21645L20.1858 2.55207C19.7722 2.1385 19.7722 1.46795 20.1858 1.05438C20.5993 0.640799 21.2699 0.640799 21.6835 1.05438L30.1557 9.52663C30.5693 9.94021 30.5693 10.6107 30.1557 11.0243L21.6835 19.4966C21.2699 19.9102 20.5993 19.9102 20.1858 19.4966C19.7722 19.083 19.7722 18.4125 20.1858 17.9989L26.8501 11.3345L1.87204 11.3345C1.28715 11.3345 0.813004 10.8604 0.813004 10.2755Z"
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
module.exports = ArrowIcon;
|
package/dist/icons/ArrowIcon.mjs
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
import{jsx
|
|
2
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
|
|
3
|
+
// src/icons/ArrowIcon.tsx
|
|
4
|
+
/** v9 icon (from `arrow_label`): drawn in `currentColor`, decorative by default. */
|
|
5
|
+
const ArrowIcon = (props) => /* @__PURE__ */ jsx("svg", {
|
|
6
|
+
width: "1em",
|
|
7
|
+
height: "1em",
|
|
8
|
+
viewBox: "0 0 31 20",
|
|
9
|
+
fill: "currentColor",
|
|
10
|
+
"aria-hidden": "true",
|
|
11
|
+
focusable: "false",
|
|
12
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
13
|
+
...props,
|
|
14
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
15
|
+
fillRule: "evenodd",
|
|
16
|
+
clipRule: "evenodd",
|
|
17
|
+
d: "M0.813004 10.2755C0.813004 9.69059 1.28715 9.21645 1.87204 9.21645L26.8501 9.21645L20.1858 2.55207C19.7722 2.1385 19.7722 1.46795 20.1858 1.05438C20.5993 0.640799 21.2699 0.640799 21.6835 1.05438L30.1557 9.52663C30.5693 9.94021 30.5693 10.6107 30.1557 11.0243L21.6835 19.4966C21.2699 19.9102 20.5993 19.9102 20.1858 19.4966C19.7722 19.083 19.7722 18.4125 20.1858 17.9989L26.8501 11.3345L1.87204 11.3345C1.28715 11.3345 0.813004 10.8604 0.813004 10.2755Z"
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export { ArrowIcon as default };
|
package/dist/icons/BoxIcon.js
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
let
|
|
2
|
-
|
|
1
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
2
|
+
|
|
3
|
+
// src/icons/BoxIcon.tsx
|
|
4
|
+
/** v9 icon (from `box_label`): drawn in `currentColor`, decorative by default. */
|
|
5
|
+
const BoxIcon = (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
6
|
+
width: "1em",
|
|
7
|
+
height: "1em",
|
|
8
|
+
viewBox: "0 0 27 26",
|
|
9
|
+
fill: "currentColor",
|
|
10
|
+
"aria-hidden": "true",
|
|
11
|
+
focusable: "false",
|
|
12
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
13
|
+
...props,
|
|
14
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
15
|
+
fillRule: "evenodd",
|
|
16
|
+
clipRule: "evenodd",
|
|
17
|
+
d: "M25.5226 4.8102C25.9834 4.99448 26.2855 5.4407 26.2855 5.9369V19.9512C26.2855 20.4474 25.9834 20.8936 25.5226 21.0779L13.7921 25.7701C13.5028 25.8858 13.1801 25.8858 12.8908 25.7701L1.16028 21.0779C0.699563 20.8936 0.397461 20.4474 0.397461 19.9512V5.9369C0.397461 5.4407 0.699563 4.99448 1.16028 4.8102L12.4401 0.298213C12.4451 0.296221 12.4501 0.294245 12.4551 0.292286L12.8908 0.117998C13.1801 0.00227327 13.5028 0.00227283 13.7921 0.117998L14.2279 0.292303C14.2329 0.294256 14.2379 0.296226 14.2428 0.298213L25.5226 4.8102ZM17.2306 3.23602L7.27396 7.21868L3.38482 5.66302L2.01546 6.21076V6.85792L12.5325 11.0647V23.8841L13.3415 24.2077L14.1505 23.8841V11.0647L24.6675 6.85792V6.21076L23.2981 5.66302L13.3415 9.64568L9.45226 8.09L19.4089 4.10734L17.2306 3.23602Z"
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
module.exports = BoxIcon;
|
package/dist/icons/BoxIcon.mjs
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
import{jsx
|
|
2
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
|
|
3
|
+
// src/icons/BoxIcon.tsx
|
|
4
|
+
/** v9 icon (from `box_label`): drawn in `currentColor`, decorative by default. */
|
|
5
|
+
const BoxIcon = (props) => /* @__PURE__ */ jsx("svg", {
|
|
6
|
+
width: "1em",
|
|
7
|
+
height: "1em",
|
|
8
|
+
viewBox: "0 0 27 26",
|
|
9
|
+
fill: "currentColor",
|
|
10
|
+
"aria-hidden": "true",
|
|
11
|
+
focusable: "false",
|
|
12
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
13
|
+
...props,
|
|
14
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
15
|
+
fillRule: "evenodd",
|
|
16
|
+
clipRule: "evenodd",
|
|
17
|
+
d: "M25.5226 4.8102C25.9834 4.99448 26.2855 5.4407 26.2855 5.9369V19.9512C26.2855 20.4474 25.9834 20.8936 25.5226 21.0779L13.7921 25.7701C13.5028 25.8858 13.1801 25.8858 12.8908 25.7701L1.16028 21.0779C0.699563 20.8936 0.397461 20.4474 0.397461 19.9512V5.9369C0.397461 5.4407 0.699563 4.99448 1.16028 4.8102L12.4401 0.298213C12.4451 0.296221 12.4501 0.294245 12.4551 0.292286L12.8908 0.117998C13.1801 0.00227327 13.5028 0.00227283 13.7921 0.117998L14.2279 0.292303C14.2329 0.294256 14.2379 0.296226 14.2428 0.298213L25.5226 4.8102ZM17.2306 3.23602L7.27396 7.21868L3.38482 5.66302L2.01546 6.21076V6.85792L12.5325 11.0647V23.8841L13.3415 24.2077L14.1505 23.8841V11.0647L24.6675 6.85792V6.21076L23.2981 5.66302L13.3415 9.64568L9.45226 8.09L19.4089 4.10734L17.2306 3.23602Z"
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export { BoxIcon as default };
|
package/dist/icons/CheckIcon.js
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
let
|
|
2
|
-
|
|
1
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
2
|
+
|
|
3
|
+
// src/icons/CheckIcon.tsx
|
|
4
|
+
/** v9 icon (from `checkmark`): drawn in `currentColor`, decorative by default. */
|
|
5
|
+
const CheckIcon = (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
6
|
+
width: "1em",
|
|
7
|
+
height: "1em",
|
|
8
|
+
viewBox: "0 0 36 28",
|
|
9
|
+
fill: "currentColor",
|
|
10
|
+
"aria-hidden": "true",
|
|
11
|
+
focusable: "false",
|
|
12
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
13
|
+
...props,
|
|
14
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M31.7745 0.900854C32.7099 -0.0470194 34.2265 -0.0470194 35.1619 0.900854C36.0859 1.8371 36.0972 3.34793 35.1959 4.29828L16.0585 26.9205C16.0401 26.9438 16.0204 26.966 15.9996 26.9872C15.0641 27.935 13.5475 27.935 12.6121 26.9872L0.966345 15.1863C0.0309227 14.2385 0.0309227 12.7017 0.966344 11.7538C1.90177 10.8059 3.41838 10.8059 4.35381 11.7538L14.2337 21.7652L31.7109 0.97346C31.7307 0.947992 31.7519 0.923746 31.7745 0.900854Z" })
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
module.exports = CheckIcon;
|
package/dist/icons/CheckIcon.mjs
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
import{jsx
|
|
2
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
|
|
3
|
+
// src/icons/CheckIcon.tsx
|
|
4
|
+
/** v9 icon (from `checkmark`): drawn in `currentColor`, decorative by default. */
|
|
5
|
+
const CheckIcon = (props) => /* @__PURE__ */ jsx("svg", {
|
|
6
|
+
width: "1em",
|
|
7
|
+
height: "1em",
|
|
8
|
+
viewBox: "0 0 36 28",
|
|
9
|
+
fill: "currentColor",
|
|
10
|
+
"aria-hidden": "true",
|
|
11
|
+
focusable: "false",
|
|
12
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
13
|
+
...props,
|
|
14
|
+
children: /* @__PURE__ */ jsx("path", { d: "M31.7745 0.900854C32.7099 -0.0470194 34.2265 -0.0470194 35.1619 0.900854C36.0859 1.8371 36.0972 3.34793 35.1959 4.29828L16.0585 26.9205C16.0401 26.9438 16.0204 26.966 15.9996 26.9872C15.0641 27.935 13.5475 27.935 12.6121 26.9872L0.966345 15.1863C0.0309227 14.2385 0.0309227 12.7017 0.966344 11.7538C1.90177 10.8059 3.41838 10.8059 4.35381 11.7538L14.2337 21.7652L31.7109 0.97346C31.7307 0.947992 31.7519 0.923746 31.7745 0.900854Z" })
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export { CheckIcon as default };
|