@vulcantech/banners 0.1.3 → 0.2.0
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/README.md +26 -30
- package/dist/index.d.mts +44 -5
- package/dist/index.d.ts +44 -5
- package/dist/index.js +39 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ interface BannerData {
|
|
|
19
19
|
position: "top" | "bottom"; // which bar this belongs to — you render both
|
|
20
20
|
message: string; // plain text — see above
|
|
21
21
|
linkText?: string; // plain text; a "→" is appended by the renderer
|
|
22
|
-
linkUrl?: string; // plain <a href>,
|
|
22
|
+
linkUrl?: string; // plain <a href>, opens in a new tab, no next/link
|
|
23
23
|
backgroundColor: string; // raw CSS color, applied inline — required
|
|
24
24
|
textColor: string; // raw CSS color, applied inline — required
|
|
25
25
|
icon?: string; // preset icon NAME, not a URL — not rendered here
|
|
@@ -35,8 +35,9 @@ interface BannerData {
|
|
|
35
35
|
Field notes:
|
|
36
36
|
|
|
37
37
|
- **`message` / `linkText` are plain text**; `linkUrl` renders as a bare `<a href>`
|
|
38
|
-
in
|
|
39
|
-
`data:` and `vbscript:` URLs on write, so the stored
|
|
38
|
+
that opens in a new tab (`target="_blank" rel="noopener noreferrer"`). The CMS
|
|
39
|
+
rejects `javascript:`, `data:` and `vbscript:` URLs on write, so the stored
|
|
40
|
+
value is a navigable URL.
|
|
40
41
|
- **`backgroundColor` / `textColor`** are whatever string an editor saved (the CMS
|
|
41
42
|
presets store hex like `#2563eb`) and go straight into `style`. They are
|
|
42
43
|
**required** — a banner never falls back to a themed default, so this package
|
|
@@ -57,11 +58,15 @@ Field notes:
|
|
|
57
58
|
- **`pages`** is a list of path prefixes (`["/", "/services", "/blog"]`); empty or
|
|
58
59
|
absent means every page. Matching is case-insensitive, ignores trailing slashes,
|
|
59
60
|
and matches **subtrees** — `"/blog"` also matches `/blog/my-post`, while `"/"`
|
|
60
|
-
matches only the root. **Targeting is inert unless
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
matches only the root. **Targeting is inert unless `CMSBanners` gets
|
|
62
|
+
`currentPath`**: with none, every banner passes the filter, including
|
|
63
|
+
page-targeted ones. Mount `SiteBanners` (step 4), which supplies it from
|
|
64
|
+
`usePathname()`; every monorepo consumer does as of 2026-11.
|
|
65
|
+
The CMS persists the field as of 2026-09 (before that its write validators
|
|
66
|
+
dropped it silently), normalizing each entry to lowercase, leading-slash,
|
|
67
|
+
no-trailing-slash on save — so a banner authored through the dashboard arrives
|
|
68
|
+
in exactly the form the matcher above expects. Banners saved before that date
|
|
69
|
+
have no `pages` and therefore show everywhere; re-save one to set targeting.
|
|
65
70
|
|
|
66
71
|
`BannerData` is a **display subset** of the CMS's internal `Banner` record. The API
|
|
67
72
|
response also carries `projectId`, `preset`, `active`, `startDate`, `endDate`,
|
|
@@ -152,36 +157,27 @@ export async function fetchBanners(): Promise<BannerData[]> {
|
|
|
152
157
|
|
|
153
158
|
**4. Render in the root layout** (`src/app/layout.tsx`):
|
|
154
159
|
```tsx
|
|
155
|
-
import {
|
|
160
|
+
import { SiteBanners } from "@vulcantech/banners";
|
|
156
161
|
|
|
157
162
|
const banners = await fetchBanners();
|
|
158
163
|
// <body>
|
|
159
|
-
// <
|
|
164
|
+
// <SiteBanners banners={banners} position="top" />
|
|
160
165
|
// {children}
|
|
161
|
-
// <
|
|
166
|
+
// <SiteBanners banners={banners} position="bottom" />
|
|
162
167
|
// </body>
|
|
163
168
|
```
|
|
164
169
|
One fetch feeds both positions — the API returns top and bottom banners together.
|
|
165
170
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return (
|
|
177
|
-
<>
|
|
178
|
-
<CMSBanners banners={banners} position="top" currentPath={pathname} />
|
|
179
|
-
<CMSBanners banners={banners} position="bottom" currentPath={pathname} />
|
|
180
|
-
</>
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
```
|
|
184
|
-
Without this, every banner shows on every page.
|
|
171
|
+
`SiteBanners` is `CMSBanners` plus `currentPath={usePathname()}` — a root layout
|
|
172
|
+
is a server component with no pathname, so a bare `<CMSBanners>` there silently
|
|
173
|
+
ignores every banner's `pages` targeting (a banner a staff member restricted to
|
|
174
|
+
`/services` shows site-wide, which reads as the CMS ignoring the setting). It
|
|
175
|
+
imports `next/navigation`, hence the `next` peer dependency.
|
|
176
|
+
|
|
177
|
+
**4b. Non-Next or custom mounts** — use `CMSBanners` directly and pass
|
|
178
|
+
`currentPath` yourself (the CMS's own `self-banners.tsx` does this because it
|
|
179
|
+
wraps the top bar in a measured fixed container). Omitting `currentPath`
|
|
180
|
+
disables targeting.
|
|
185
181
|
|
|
186
182
|
**5. ISR invalidation** — ensure `src/app/api/revalidate/route.ts` exists, set `VULCANTECH_REVALIDATE_SECRET`, and register the site under **Settings → Form Consumers (ISR Revalidation)** in the CMS (the list serves every integration, not just forms). The CMS purges the `banners:{projectId}` tag when a banner is edited. Route contract and reference copy: the `@vulcantech/cms` README, [ISR revalidation](../cms/README.md#isr-revalidation).
|
|
187
183
|
|
package/dist/index.d.mts
CHANGED
|
@@ -32,9 +32,10 @@ interface BannerData {
|
|
|
32
32
|
/** Plain text label for the trailing link; the renderer appends a "→". */
|
|
33
33
|
linkText?: string;
|
|
34
34
|
/**
|
|
35
|
-
* Link target. Rendered as a bare `<a href>` in
|
|
36
|
-
* `target
|
|
37
|
-
* and `vbscript:` URLs on write, so the
|
|
35
|
+
* Link target. Rendered as a bare `<a href>` that opens in a new tab
|
|
36
|
+
* (`target="_blank" rel="noopener noreferrer"`), with no `next/link`. The
|
|
37
|
+
* CMS rejects `javascript:`, `data:` and `vbscript:` URLs on write, so the
|
|
38
|
+
* stored value is navigable.
|
|
38
39
|
*/
|
|
39
40
|
linkUrl?: string;
|
|
40
41
|
/**
|
|
@@ -117,7 +118,8 @@ interface CMSBannersProps {
|
|
|
117
118
|
* z-index: 40`. A `position: fixed` site header will cover the top banner
|
|
118
119
|
* unless the host site offsets it.
|
|
119
120
|
*
|
|
120
|
-
*
|
|
121
|
+
* Next.js root layouts should mount `SiteBanners` instead, which supplies
|
|
122
|
+
* `currentPath` from `usePathname()`. Bare usage (targeting disabled):
|
|
121
123
|
* ```tsx
|
|
122
124
|
* import { CMSBanners } from "@vulcantech/banners";
|
|
123
125
|
*
|
|
@@ -134,6 +136,43 @@ interface CMSBannersProps {
|
|
|
134
136
|
*/
|
|
135
137
|
declare function CMSBanners({ banners, position, currentPath }: CMSBannersProps): react.JSX.Element | null;
|
|
136
138
|
|
|
139
|
+
interface SiteBannersProps {
|
|
140
|
+
/** All banners from the layout's one fetch — both positions (see `CMSBanners`). */
|
|
141
|
+
banners: BannerData[];
|
|
142
|
+
/** Which position to render — "top" or "bottom". */
|
|
143
|
+
position: "top" | "bottom";
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Path-aware {@link CMSBanners} for Next.js App Router sites — the component a
|
|
147
|
+
* consumer root layout should mount.
|
|
148
|
+
*
|
|
149
|
+
* A root layout is a server component with no pathname, so a bare
|
|
150
|
+
* `<CMSBanners>` there never receives `currentPath` and silently ignores every
|
|
151
|
+
* banner's `pages` targeting. This client component reads `usePathname()` and
|
|
152
|
+
* passes it through, so targeting works and re-evaluates on client-side
|
|
153
|
+
* navigation (the layout itself does not re-render on navigation, but this
|
|
154
|
+
* hook does).
|
|
155
|
+
*
|
|
156
|
+
* Same rendering, stacking and failure behavior as `CMSBanners` — it adds
|
|
157
|
+
* nothing but the path.
|
|
158
|
+
*
|
|
159
|
+
* @param props.banners The full `BannerData[]` from the layout's fetcher.
|
|
160
|
+
* @param props.position Which group to render.
|
|
161
|
+
* @returns The filtered banner group, or `null` when nothing matches.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```tsx
|
|
165
|
+
* import { SiteBanners } from "@vulcantech/banners";
|
|
166
|
+
*
|
|
167
|
+
* <body>
|
|
168
|
+
* <SiteBanners banners={banners} position="top" />
|
|
169
|
+
* {children}
|
|
170
|
+
* <SiteBanners banners={banners} position="bottom" />
|
|
171
|
+
* </body>
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
declare function SiteBanners({ banners, position }: SiteBannersProps): react.JSX.Element;
|
|
175
|
+
|
|
137
176
|
/**
|
|
138
177
|
* Renders a single banner bar. Handles dismissal via localStorage.
|
|
139
178
|
*
|
|
@@ -158,4 +197,4 @@ declare function BannerBar({ banner }: {
|
|
|
158
197
|
banner: BannerData;
|
|
159
198
|
}): react.JSX.Element | null;
|
|
160
199
|
|
|
161
|
-
export { BannerBar, type BannerData, CMSBanners };
|
|
200
|
+
export { BannerBar, type BannerData, CMSBanners, SiteBanners };
|
package/dist/index.d.ts
CHANGED
|
@@ -32,9 +32,10 @@ interface BannerData {
|
|
|
32
32
|
/** Plain text label for the trailing link; the renderer appends a "→". */
|
|
33
33
|
linkText?: string;
|
|
34
34
|
/**
|
|
35
|
-
* Link target. Rendered as a bare `<a href>` in
|
|
36
|
-
* `target
|
|
37
|
-
* and `vbscript:` URLs on write, so the
|
|
35
|
+
* Link target. Rendered as a bare `<a href>` that opens in a new tab
|
|
36
|
+
* (`target="_blank" rel="noopener noreferrer"`), with no `next/link`. The
|
|
37
|
+
* CMS rejects `javascript:`, `data:` and `vbscript:` URLs on write, so the
|
|
38
|
+
* stored value is navigable.
|
|
38
39
|
*/
|
|
39
40
|
linkUrl?: string;
|
|
40
41
|
/**
|
|
@@ -117,7 +118,8 @@ interface CMSBannersProps {
|
|
|
117
118
|
* z-index: 40`. A `position: fixed` site header will cover the top banner
|
|
118
119
|
* unless the host site offsets it.
|
|
119
120
|
*
|
|
120
|
-
*
|
|
121
|
+
* Next.js root layouts should mount `SiteBanners` instead, which supplies
|
|
122
|
+
* `currentPath` from `usePathname()`. Bare usage (targeting disabled):
|
|
121
123
|
* ```tsx
|
|
122
124
|
* import { CMSBanners } from "@vulcantech/banners";
|
|
123
125
|
*
|
|
@@ -134,6 +136,43 @@ interface CMSBannersProps {
|
|
|
134
136
|
*/
|
|
135
137
|
declare function CMSBanners({ banners, position, currentPath }: CMSBannersProps): react.JSX.Element | null;
|
|
136
138
|
|
|
139
|
+
interface SiteBannersProps {
|
|
140
|
+
/** All banners from the layout's one fetch — both positions (see `CMSBanners`). */
|
|
141
|
+
banners: BannerData[];
|
|
142
|
+
/** Which position to render — "top" or "bottom". */
|
|
143
|
+
position: "top" | "bottom";
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Path-aware {@link CMSBanners} for Next.js App Router sites — the component a
|
|
147
|
+
* consumer root layout should mount.
|
|
148
|
+
*
|
|
149
|
+
* A root layout is a server component with no pathname, so a bare
|
|
150
|
+
* `<CMSBanners>` there never receives `currentPath` and silently ignores every
|
|
151
|
+
* banner's `pages` targeting. This client component reads `usePathname()` and
|
|
152
|
+
* passes it through, so targeting works and re-evaluates on client-side
|
|
153
|
+
* navigation (the layout itself does not re-render on navigation, but this
|
|
154
|
+
* hook does).
|
|
155
|
+
*
|
|
156
|
+
* Same rendering, stacking and failure behavior as `CMSBanners` — it adds
|
|
157
|
+
* nothing but the path.
|
|
158
|
+
*
|
|
159
|
+
* @param props.banners The full `BannerData[]` from the layout's fetcher.
|
|
160
|
+
* @param props.position Which group to render.
|
|
161
|
+
* @returns The filtered banner group, or `null` when nothing matches.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```tsx
|
|
165
|
+
* import { SiteBanners } from "@vulcantech/banners";
|
|
166
|
+
*
|
|
167
|
+
* <body>
|
|
168
|
+
* <SiteBanners banners={banners} position="top" />
|
|
169
|
+
* {children}
|
|
170
|
+
* <SiteBanners banners={banners} position="bottom" />
|
|
171
|
+
* </body>
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
declare function SiteBanners({ banners, position }: SiteBannersProps): react.JSX.Element;
|
|
175
|
+
|
|
137
176
|
/**
|
|
138
177
|
* Renders a single banner bar. Handles dismissal via localStorage.
|
|
139
178
|
*
|
|
@@ -158,4 +197,4 @@ declare function BannerBar({ banner }: {
|
|
|
158
197
|
banner: BannerData;
|
|
159
198
|
}): react.JSX.Element | null;
|
|
160
199
|
|
|
161
|
-
export { BannerBar, type BannerData, CMSBanners };
|
|
200
|
+
export { BannerBar, type BannerData, CMSBanners, SiteBanners };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var navigation = require('next/navigation');
|
|
5
6
|
|
|
6
7
|
// BannerBar.tsx
|
|
7
8
|
var DISMISSED_KEY = "vulcantech_dismissed_banners";
|
|
@@ -54,38 +55,39 @@ function BannerBar({ banner }) {
|
|
|
54
55
|
},
|
|
55
56
|
children: [
|
|
56
57
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
57
|
-
"
|
|
58
|
+
"p",
|
|
58
59
|
{
|
|
59
60
|
style: {
|
|
60
|
-
|
|
61
|
-
alignItems: "center",
|
|
62
|
-
justifyContent: "center",
|
|
63
|
-
gap: "0.5rem",
|
|
61
|
+
margin: 0,
|
|
64
62
|
padding: banner.dismissible ? "0.625rem 2.5rem 0.625rem 1rem" : "0.625rem 1rem",
|
|
65
63
|
fontSize: "0.875rem",
|
|
66
64
|
lineHeight: "1.25rem",
|
|
67
|
-
textAlign: "center"
|
|
68
|
-
minHeight: "2.5rem"
|
|
65
|
+
textAlign: "center"
|
|
69
66
|
},
|
|
70
67
|
children: [
|
|
71
|
-
|
|
72
|
-
banner.linkText && banner.linkUrl && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
68
|
+
banner.message,
|
|
69
|
+
banner.linkText && banner.linkUrl && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
70
|
+
" ",
|
|
71
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
72
|
+
"a",
|
|
73
|
+
{
|
|
74
|
+
href: banner.linkUrl,
|
|
75
|
+
target: "_blank",
|
|
76
|
+
rel: "noopener noreferrer",
|
|
77
|
+
style: {
|
|
78
|
+
color: banner.textColor,
|
|
79
|
+
fontWeight: 600,
|
|
80
|
+
textDecoration: "underline",
|
|
81
|
+
textUnderlineOffset: "2px",
|
|
82
|
+
cursor: "pointer"
|
|
83
|
+
},
|
|
84
|
+
children: [
|
|
85
|
+
banner.linkText,
|
|
86
|
+
"\xA0\u2192"
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
)
|
|
90
|
+
] })
|
|
89
91
|
]
|
|
90
92
|
}
|
|
91
93
|
),
|
|
@@ -140,8 +142,20 @@ function CMSBanners({ banners, position, currentPath }) {
|
|
|
140
142
|
}
|
|
141
143
|
);
|
|
142
144
|
}
|
|
145
|
+
function SiteBanners({ banners, position }) {
|
|
146
|
+
const pathname = navigation.usePathname();
|
|
147
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
148
|
+
CMSBanners,
|
|
149
|
+
{
|
|
150
|
+
banners,
|
|
151
|
+
position,
|
|
152
|
+
currentPath: pathname != null ? pathname : void 0
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
}
|
|
143
156
|
|
|
144
157
|
exports.BannerBar = BannerBar;
|
|
145
158
|
exports.CMSBanners = CMSBanners;
|
|
159
|
+
exports.SiteBanners = SiteBanners;
|
|
146
160
|
//# sourceMappingURL=index.js.map
|
|
147
161
|
//# sourceMapping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AAAA,OACT;AAAA,MAEC,QAAA,EAAA,QAAA,CAAS,GAAA,CAAI,CAAC,MAAA,qBACbA,eAAC,SAAA,EAAA,EAA0B,MAAA,EAAA,EAAX,MAAA,CAAO,EAAoB,CAC5C;AAAA;AAAA,GACH;AAEJ","file":"index.js","sourcesContent":["\"use client\";\n\nimport { useState, useEffect } from \"react\";\nimport type { BannerData } from \"./types\";\n\nconst DISMISSED_KEY = \"vulcantech_dismissed_banners\";\nconst MAX_DISMISSED = 50;\n\nfunction getDismissed(): Set<string> {\n if (typeof window === \"undefined\") return new Set();\n try {\n const raw = localStorage.getItem(DISMISSED_KEY);\n return raw ? new Set(JSON.parse(raw)) : new Set();\n } catch {\n return new Set();\n }\n}\n\nfunction persistDismissed(id: string) {\n if (typeof window === \"undefined\") return;\n try {\n const current = getDismissed();\n current.add(id);\n // Cap stored dismissals to prevent unbounded growth\n const arr = Array.from(current);\n const trimmed = arr.length > MAX_DISMISSED ? arr.slice(-MAX_DISMISSED) : arr;\n localStorage.setItem(DISMISSED_KEY, JSON.stringify(trimmed));\n } catch {\n /* quota */\n }\n}\n\n/**\n * Renders a single banner bar. Handles dismissal via localStorage.\n *\n * `message` and `linkText` are rendered as React children, so they are treated\n * as **plain text** and any markup in them is escaped. `backgroundColor` and\n * `textColor` are applied as inline styles — the host site's theme has no say.\n * `banner.icon` is NOT rendered here (see {@link BannerData.icon}).\n *\n * Dismissal is keyed on `banner.dismissKey || banner.id` and persisted to the\n * shared `vulcantech_dismissed_banners` localStorage key — a JSON array capped\n * at the 50 most recent ids, per-browser rather than per-user-account. Reads and\n * writes are wrapped in try/catch, so blocked or full storage degrades to \"the\n * banner comes back\" instead of throwing. Because the lookup only runs for\n * dismissible banners, flipping `dismissible` to `false` re-shows the banner to\n * everyone who had dismissed it.\n *\n * Returns `null` until mounted (localStorage is unreadable during SSR), so\n * **banners are absent from the server-rendered HTML** and appear after\n * hydration — expect a small shift, and do not rely on banner text for SEO.\n */\nexport function BannerBar({ banner }: { banner: BannerData }) {\n const [dismissed, setDismissedState] = useState(false);\n const [mounted, setMounted] = useState(false);\n\n // Use dismissKey if available, fall back to id for backwards compat\n const dismissId = banner.dismissKey || banner.id;\n\n useEffect(() => {\n setMounted(true);\n if (banner.dismissible && getDismissed().has(dismissId)) {\n setDismissedState(true);\n }\n }, [dismissId, banner.dismissible]);\n\n // Don't render until mounted to avoid hydration mismatch with localStorage\n if (!mounted || dismissed) return null;\n\n const handleDismiss = () => {\n persistDismissed(dismissId);\n setDismissedState(true);\n };\n\n return (\n <div\n id={`cms-banner-${banner.id}`}\n data-banner-id={banner.id}\n data-banner-position={banner.position}\n style={{\n backgroundColor: banner.backgroundColor,\n color: banner.textColor,\n position: \"relative\",\n }}\n >\n <div\n style={{\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: \"0.5rem\",\n padding: banner.dismissible\n ? \"0.625rem 2.5rem 0.625rem 1rem\"\n : \"0.625rem 1rem\",\n fontSize: \"0.875rem\",\n lineHeight: \"1.25rem\",\n textAlign: \"center\",\n minHeight: \"2.5rem\",\n }}\n >\n <span>{banner.message}</span>\n {banner.linkText && banner.linkUrl && (\n <a\n href={banner.linkUrl}\n style={{\n color: banner.textColor,\n fontWeight: 600,\n textDecoration: \"underline\",\n textUnderlineOffset: \"2px\",\n whiteSpace: \"nowrap\",\n }}\n >\n {banner.linkText} →\n </a>\n )}\n </div>\n {banner.dismissible && (\n <button\n type=\"button\"\n onClick={handleDismiss}\n aria-label=\"Dismiss banner\"\n style={{\n position: \"absolute\",\n right: \"0.75rem\",\n top: \"50%\",\n transform: \"translateY(-50%)\",\n background: \"none\",\n border: \"none\",\n color: banner.textColor,\n cursor: \"pointer\",\n padding: \"0.25rem\",\n opacity: 0.7,\n fontSize: \"1.125rem\",\n lineHeight: 1,\n }}\n >\n ✕\n </button>\n )}\n </div>\n );\n}\n","\"use client\";\n\nimport type { BannerData } from \"./types\";\nimport { BannerBar } from \"./BannerBar\";\n\ninterface CMSBannersProps {\n /**\n * All banners fetched server-side via ISR — BOTH positions. The CMS returns\n * top and bottom banners in one payload, already filtered to active +\n * in-schedule and sorted by ascending `priority`; pass the same array to both\n * renders rather than fetching twice.\n */\n banners: BannerData[];\n /** Which position to render — \"top\" or \"bottom\". */\n position: \"top\" | \"bottom\";\n /**\n * Current page path for page-targeted banners (e.g. \"/services\").\n *\n * **Omitting this disables targeting entirely** — every banner passes the\n * filter, including ones with a `pages` list. A root layout is a server\n * component with no pathname, so pass it from a thin `\"use client\"` wrapper\n * that calls `usePathname()`.\n */\n currentPath?: string;\n}\n\n/**\n * Drop-in banner component for consumer site layouts.\n *\n * Filters `banners` to the given `position`, then to `currentPath` (see that\n * prop — subtree prefix match, case-insensitive, trailing slashes ignored),\n * sorts by ascending `priority`, and renders one {@link BannerBar} each.\n *\n * **Never throws and has no error path** — it does no fetching. It returns\n * `null` when nothing matches, which is also what a failed fetch looks like\n * (the recommended fetcher returns `[]` on any failure), so there is no error\n * UI to write.\n *\n * Layout: the `top` group is wrapped in a `position: relative; z-index: 51`\n * div **in normal flow**, the `bottom` group in `position: sticky; bottom: 0;\n * z-index: 40`. A `position: fixed` site header will cover the top banner\n * unless the host site offsets it.\n *\n * Usage in a root layout:\n * ```tsx\n * import { CMSBanners } from \"@vulcantech/banners\";\n *\n * const banners = await fetchBanners(); // ISR cached\n *\n * <body>\n * <CMSBanners banners={banners} position=\"top\" />\n * <Nav />\n * {children}\n * <Footer />\n * <CMSBanners banners={banners} position=\"bottom\" />\n * </body>\n * ```\n */\nexport function CMSBanners({ banners, position, currentPath }: CMSBannersProps) {\n const filtered = banners\n .filter((b) => b.position === position)\n .filter((b) => {\n // No pages specified = show everywhere\n if (!b.pages || b.pages.length === 0) return true;\n if (!currentPath) return true;\n // Match current path against allowed pages\n const path = currentPath.toLowerCase().replace(/\\/+$/, \"\") || \"/\";\n return b.pages.some((p) => {\n const allowed = p.toLowerCase().replace(/\\/+$/, \"\") || \"/\";\n return path === allowed || path.startsWith(allowed + \"/\");\n });\n })\n .sort((a, b) => a.priority - b.priority);\n\n if (filtered.length === 0) return null;\n\n return (\n <div\n style={{\n position: position === \"bottom\" ? \"sticky\" : \"relative\",\n bottom: position === \"bottom\" ? 0 : undefined,\n zIndex: position === \"bottom\" ? 40 : 51,\n width: \"100%\",\n }}\n >\n {filtered.map((banner) => (\n <BannerBar key={banner.id} banner={banner} />\n ))}\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../BannerBar.tsx","../CMSBanners.tsx","../SiteBanners.tsx"],"names":["useState","useEffect","jsxs","Fragment","jsx","usePathname"],"mappings":";;;;;;;AAKA,IAAM,aAAA,GAAgB,8BAAA;AACtB,IAAM,aAAA,GAAgB,EAAA;AAEtB,SAAS,YAAA,GAA4B;AACnC,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,EAAa,2BAAW,GAAA,EAAI;AAClD,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,YAAA,CAAa,OAAA,CAAQ,aAAa,CAAA;AAC9C,IAAA,OAAO,GAAA,GAAM,IAAI,GAAA,CAAI,IAAA,CAAK,MAAM,GAAG,CAAC,CAAA,mBAAI,IAAI,GAAA,EAAI;AAAA,EAClD,CAAA,CAAA,OAAQ,CAAA,EAAA;AACN,IAAA,2BAAW,GAAA,EAAI;AAAA,EACjB;AACF;AAEA,SAAS,iBAAiB,EAAA,EAAY;AACpC,EAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACnC,EAAA,IAAI;AACF,IAAA,MAAM,UAAU,YAAA,EAAa;AAC7B,IAAA,OAAA,CAAQ,IAAI,EAAE,CAAA;AAEd,IAAA,MAAM,GAAA,GAAM,KAAA,CAAM,IAAA,CAAK,OAAO,CAAA;AAC9B,IAAA,MAAM,OAAA,GAAU,IAAI,MAAA,GAAS,aAAA,GAAgB,IAAI,KAAA,CAAM,CAAC,aAAa,CAAA,GAAI,GAAA;AACzE,IAAA,YAAA,CAAa,OAAA,CAAQ,aAAA,EAAe,IAAA,C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A,EAAO;AAAA,QACL,QAAA,EAAU,QAAA,KAAa,QAAA,GAAW,QAAA,GAAW,UAAA;AAAA,QAC7C,MAAA,EAAQ,QAAA,KAAa,QAAA,GAAW,CAAA,GAAI,MAAA;AAAA,QACpC,MAAA,EAAQ,QAAA,KAAa,QAAA,GAAW,EAAA,GAAK,EAAA;AAAA,QACrC,KAAA,EAAO;AAAA,OACT;AAAA,MAEC,QAAA,EAAA,QAAA,CAAS,GAAA,CAAI,CAAC,MAAA,qBACbA,eAAC,SAAA,EAAA,EAA0B,MAAA,EAAA,EAAX,MAAA,CAAO,EAAoB,CAC5C;AAAA;AAAA,GACH;AAEJ;ACjDO,SAAS,WAAA,CAAY,EAAE,OAAA,EAAS,QAAA,EAAS,EAAqB;AACnE,EAAA,MAAM,WAAWC,sBAAA,EAAY;AAC7B,EAAA,uBACED,cAAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,OAAA;AAAA,MACA,QAAA;AAAA,MACA,aAAa,QAAA,IAAA,IAAA,GAAA,QAAA,GAAY;AAAA;AAAA,GAC3B;AAEJ","file":"index.js","sourcesContent":["\"use client\";\n\nimport { useState, useEffect } from \"react\";\nimport type { BannerData } from \"./types\";\n\nconst DISMISSED_KEY = \"vulcantech_dismissed_banners\";\nconst MAX_DISMISSED = 50;\n\nfunction getDismissed(): Set<string> {\n if (typeof window === \"undefined\") return new Set();\n try {\n const raw = localStorage.getItem(DISMISSED_KEY);\n return raw ? new Set(JSON.parse(raw)) : new Set();\n } catch {\n return new Set();\n }\n}\n\nfunction persistDismissed(id: string) {\n if (typeof window === \"undefined\") return;\n try {\n const current = getDismissed();\n current.add(id);\n // Cap stored dismissals to prevent unbounded growth\n const arr = Array.from(current);\n const trimmed = arr.length > MAX_DISMISSED ? arr.slice(-MAX_DISMISSED) : arr;\n localStorage.setItem(DISMISSED_KEY, JSON.stringify(trimmed));\n } catch {\n /* quota */\n }\n}\n\n/**\n * Renders a single banner bar. Handles dismissal via localStorage.\n *\n * `message` and `linkText` are rendered as React children, so they are treated\n * as **plain text** and any markup in them is escaped. `backgroundColor` and\n * `textColor` are applied as inline styles — the host site's theme has no say.\n * `banner.icon` is NOT rendered here (see {@link BannerData.icon}).\n *\n * Dismissal is keyed on `banner.dismissKey || banner.id` and persisted to the\n * shared `vulcantech_dismissed_banners` localStorage key — a JSON array capped\n * at the 50 most recent ids, per-browser rather than per-user-account. Reads and\n * writes are wrapped in try/catch, so blocked or full storage degrades to \"the\n * banner comes back\" instead of throwing. Because the lookup only runs for\n * dismissible banners, flipping `dismissible` to `false` re-shows the banner to\n * everyone who had dismissed it.\n *\n * Returns `null` until mounted (localStorage is unreadable during SSR), so\n * **banners are absent from the server-rendered HTML** and appear after\n * hydration — expect a small shift, and do not rely on banner text for SEO.\n */\nexport function BannerBar({ banner }: { banner: BannerData }) {\n const [dismissed, setDismissedState] = useState(false);\n const [mounted, setMounted] = useState(false);\n\n // Use dismissKey if available, fall back to id for backwards compat\n const dismissId = banner.dismissKey || banner.id;\n\n useEffect(() => {\n setMounted(true);\n if (banner.dismissible && getDismissed().has(dismissId)) {\n setDismissedState(true);\n }\n }, [dismissId, banner.dismissible]);\n\n // Don't render until mounted to avoid hydration mismatch with localStorage\n if (!mounted || dismissed) return null;\n\n const handleDismiss = () => {\n persistDismissed(dismissId);\n setDismissedState(true);\n };\n\n return (\n <div\n id={`cms-banner-${banner.id}`}\n data-banner-id={banner.id}\n data-banner-position={banner.position}\n style={{\n backgroundColor: banner.backgroundColor,\n color: banner.textColor,\n position: \"relative\",\n }}\n >\n {/* The link sits inline inside the message paragraph (not a sibling flex\n item), so on narrow screens it wraps with the sentence instead of\n splitting the bar into two columns. */}\n <p\n style={{\n margin: 0,\n padding: banner.dismissible\n ? \"0.625rem 2.5rem 0.625rem 1rem\"\n : \"0.625rem 1rem\",\n fontSize: \"0.875rem\",\n lineHeight: \"1.25rem\",\n textAlign: \"center\",\n }}\n >\n {banner.message}\n {banner.linkText && banner.linkUrl && (\n <>\n {\" \"}\n <a\n href={banner.linkUrl}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n style={{\n color: banner.textColor,\n fontWeight: 600,\n textDecoration: \"underline\",\n textUnderlineOffset: \"2px\",\n cursor: \"pointer\",\n }}\n >\n {banner.linkText} →\n </a>\n </>\n )}\n </p>\n {banner.dismissible && (\n <button\n type=\"button\"\n onClick={handleDismiss}\n aria-label=\"Dismiss banner\"\n style={{\n position: \"absolute\",\n right: \"0.75rem\",\n top: \"50%\",\n transform: \"translateY(-50%)\",\n background: \"none\",\n border: \"none\",\n color: banner.textColor,\n cursor: \"pointer\",\n padding: \"0.25rem\",\n opacity: 0.7,\n fontSize: \"1.125rem\",\n lineHeight: 1,\n }}\n >\n ✕\n </button>\n )}\n </div>\n );\n}\n","\"use client\";\n\nimport type { BannerData } from \"./types\";\nimport { BannerBar } from \"./BannerBar\";\n\ninterface CMSBannersProps {\n /**\n * All banners fetched server-side via ISR — BOTH positions. The CMS returns\n * top and bottom banners in one payload, already filtered to active +\n * in-schedule and sorted by ascending `priority`; pass the same array to both\n * renders rather than fetching twice.\n */\n banners: BannerData[];\n /** Which position to render — \"top\" or \"bottom\". */\n position: \"top\" | \"bottom\";\n /**\n * Current page path for page-targeted banners (e.g. \"/services\").\n *\n * **Omitting this disables targeting entirely** — every banner passes the\n * filter, including ones with a `pages` list. A root layout is a server\n * component with no pathname, so pass it from a thin `\"use client\"` wrapper\n * that calls `usePathname()`.\n */\n currentPath?: string;\n}\n\n/**\n * Drop-in banner component for consumer site layouts.\n *\n * Filters `banners` to the given `position`, then to `currentPath` (see that\n * prop — subtree prefix match, case-insensitive, trailing slashes ignored),\n * sorts by ascending `priority`, and renders one {@link BannerBar} each.\n *\n * **Never throws and has no error path** — it does no fetching. It returns\n * `null` when nothing matches, which is also what a failed fetch looks like\n * (the recommended fetcher returns `[]` on any failure), so there is no error\n * UI to write.\n *\n * Layout: the `top` group is wrapped in a `position: relative; z-index: 51`\n * div **in normal flow**, the `bottom` group in `position: sticky; bottom: 0;\n * z-index: 40`. A `position: fixed` site header will cover the top banner\n * unless the host site offsets it.\n *\n * Next.js root layouts should mount `SiteBanners` instead, which supplies\n * `currentPath` from `usePathname()`. Bare usage (targeting disabled):\n * ```tsx\n * import { CMSBanners } from \"@vulcantech/banners\";\n *\n * const banners = await fetchBanners(); // ISR cached\n *\n * <body>\n * <CMSBanners banners={banners} position=\"top\" />\n * <Nav />\n * {children}\n * <Footer />\n * <CMSBanners banners={banners} position=\"bottom\" />\n * </body>\n * ```\n */\nexport function CMSBanners({ banners, position, currentPath }: CMSBannersProps) {\n const filtered = banners\n .filter((b) => b.position === position)\n .filter((b) => {\n // No pages specified = show everywhere\n if (!b.pages || b.pages.length === 0) return true;\n if (!currentPath) return true;\n // Match current path against allowed pages\n const path = currentPath.toLowerCase().replace(/\\/+$/, \"\") || \"/\";\n return b.pages.some((p) => {\n const allowed = p.toLowerCase().replace(/\\/+$/, \"\") || \"/\";\n return path === allowed || path.startsWith(allowed + \"/\");\n });\n })\n .sort((a, b) => a.priority - b.priority);\n\n if (filtered.length === 0) return null;\n\n return (\n <div\n style={{\n position: position === \"bottom\" ? \"sticky\" : \"relative\",\n bottom: position === \"bottom\" ? 0 : undefined,\n zIndex: position === \"bottom\" ? 40 : 51,\n width: \"100%\",\n }}\n >\n {filtered.map((banner) => (\n <BannerBar key={banner.id} banner={banner} />\n ))}\n </div>\n );\n}\n","\"use client\";\n\nimport { usePathname } from \"next/navigation\";\nimport type { BannerData } from \"./types\";\nimport { CMSBanners } from \"./CMSBanners\";\n\ninterface SiteBannersProps {\n /** All banners from the layout's one fetch — both positions (see `CMSBanners`). */\n banners: BannerData[];\n /** Which position to render — \"top\" or \"bottom\". */\n position: \"top\" | \"bottom\";\n}\n\n/**\n * Path-aware {@link CMSBanners} for Next.js App Router sites — the component a\n * consumer root layout should mount.\n *\n * A root layout is a server component with no pathname, so a bare\n * `<CMSBanners>` there never receives `currentPath` and silently ignores every\n * banner's `pages` targeting. This client component reads `usePathname()` and\n * passes it through, so targeting works and re-evaluates on client-side\n * navigation (the layout itself does not re-render on navigation, but this\n * hook does).\n *\n * Same rendering, stacking and failure behavior as `CMSBanners` — it adds\n * nothing but the path.\n *\n * @param props.banners The full `BannerData[]` from the layout's fetcher.\n * @param props.position Which group to render.\n * @returns The filtered banner group, or `null` when nothing matches.\n *\n * @example\n * ```tsx\n * import { SiteBanners } from \"@vulcantech/banners\";\n *\n * <body>\n * <SiteBanners banners={banners} position=\"top\" />\n * {children}\n * <SiteBanners banners={banners} position=\"bottom\" />\n * </body>\n * ```\n */\nexport function SiteBanners({ banners, position }: SiteBannersProps) {\n const pathname = usePathname();\n return (\n <CMSBanners\n banners={banners}\n position={position}\n currentPath={pathname ?? undefined}\n />\n );\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { usePathname } from 'next/navigation';
|
|
3
4
|
|
|
4
5
|
// BannerBar.tsx
|
|
5
6
|
var DISMISSED_KEY = "vulcantech_dismissed_banners";
|
|
@@ -52,38 +53,39 @@ function BannerBar({ banner }) {
|
|
|
52
53
|
},
|
|
53
54
|
children: [
|
|
54
55
|
/* @__PURE__ */ jsxs(
|
|
55
|
-
"
|
|
56
|
+
"p",
|
|
56
57
|
{
|
|
57
58
|
style: {
|
|
58
|
-
|
|
59
|
-
alignItems: "center",
|
|
60
|
-
justifyContent: "center",
|
|
61
|
-
gap: "0.5rem",
|
|
59
|
+
margin: 0,
|
|
62
60
|
padding: banner.dismissible ? "0.625rem 2.5rem 0.625rem 1rem" : "0.625rem 1rem",
|
|
63
61
|
fontSize: "0.875rem",
|
|
64
62
|
lineHeight: "1.25rem",
|
|
65
|
-
textAlign: "center"
|
|
66
|
-
minHeight: "2.5rem"
|
|
63
|
+
textAlign: "center"
|
|
67
64
|
},
|
|
68
65
|
children: [
|
|
69
|
-
|
|
70
|
-
banner.linkText && banner.linkUrl && /* @__PURE__ */ jsxs(
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
66
|
+
banner.message,
|
|
67
|
+
banner.linkText && banner.linkUrl && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
68
|
+
" ",
|
|
69
|
+
/* @__PURE__ */ jsxs(
|
|
70
|
+
"a",
|
|
71
|
+
{
|
|
72
|
+
href: banner.linkUrl,
|
|
73
|
+
target: "_blank",
|
|
74
|
+
rel: "noopener noreferrer",
|
|
75
|
+
style: {
|
|
76
|
+
color: banner.textColor,
|
|
77
|
+
fontWeight: 600,
|
|
78
|
+
textDecoration: "underline",
|
|
79
|
+
textUnderlineOffset: "2px",
|
|
80
|
+
cursor: "pointer"
|
|
81
|
+
},
|
|
82
|
+
children: [
|
|
83
|
+
banner.linkText,
|
|
84
|
+
"\xA0\u2192"
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
] })
|
|
87
89
|
]
|
|
88
90
|
}
|
|
89
91
|
),
|
|
@@ -138,7 +140,18 @@ function CMSBanners({ banners, position, currentPath }) {
|
|
|
138
140
|
}
|
|
139
141
|
);
|
|
140
142
|
}
|
|
143
|
+
function SiteBanners({ banners, position }) {
|
|
144
|
+
const pathname = usePathname();
|
|
145
|
+
return /* @__PURE__ */ jsx(
|
|
146
|
+
CMSBanners,
|
|
147
|
+
{
|
|
148
|
+
banners,
|
|
149
|
+
position,
|
|
150
|
+
currentPath: pathname != null ? pathname : void 0
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
}
|
|
141
154
|
|
|
142
|
-
export { BannerBar, CMSBanners };
|
|
155
|
+
export { BannerBar, CMSBanners, SiteBanners };
|
|
143
156
|
//# sourceMappingURL=index.mjs.map
|
|
144
157
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../BannerBar.tsx","../CMSBanners.tsx"],"names":["jsx"],"mappings":";;;;AAKA,IAAM,aAAA,GAAgB,8BAAA;AACtB,IAAM,aAAA,GAAgB,EAAA;AAEtB,SAAS,YAAA,GAA4B;AACnC,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,EAAa,2BAAW,GAAA,EAAI;AAClD,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,YAAA,CAAa,OAAA,CAAQ,aAAa,CAAA;AAC9C,IAAA,OAAO,GAAA,GAAM,IAAI,GAAA,CAAI,IAAA,CAAK,MAAM,GAAG,CAAC,CAAA,mBAAI,IAAI,GAAA,EAAI;AAAA,EAClD,CAAA,CAAA,OAAQ,CAAA,EAAA;AACN,IAAA,2BAAW,GAAA,EAAI;AAAA,EACjB;AACF;AAEA,SAAS,iBAAiB,EAAA,EAAY;AACpC,EAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACnC,EAAA,IAAI;AACF,IAAA,MAAM,UAAU,YAAA,EAAa;AAC7B,IAAA,OAAA,CAAQ,IAAI,EAAE,CAAA;AAEd,IAAA,MAAM,GAAA,GAAM,KAAA,CAAM,IAAA,CAAK,OAAO,CAAA;AAC9B,IAAA,MAAM,OAAA,GAAU,IAAI,MAAA,GAAS,aAAA,GAAgB,IAAI,KAAA,CAAM,CAAC,aAAa,CAAA,GAAI,GAAA;AACzE,IAAA,YAAA,CAAa,OAAA,CAAQ,aAAA,EAAe,IAAA,CAAK,SAAA,CAAU,OAAO,CAAC,CAAA;AAAA,EAC7D,CAAA,CAAA,OAAQ,CAAA,EAAA;AAAA,EAER;AACF;AAsBO,SAAS,SAAA,CAAU,EAAE,MAAA,EAAO,EAA2B;AAC5D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A,EAAQ,QAAA,KAAa,QAAA,GAAW,EAAA,GAAK,EAAA;AAAA,QACrC,KAAA,EAAO;AAAA,OACT;AAAA,MAEC,QAAA,EAAA,QAAA,CAAS,GAAA,CAAI,CAAC,MAAA,qBACbA,IAAC,SAAA,EAAA,EAA0B,MAAA,EAAA,EAAX,MAAA,CAAO,EAAoB,CAC5C;AAAA;AAAA,GACH;AAEJ","file":"index.mjs","sourcesContent":["\"use client\";\n\nimport { useState, useEffect } from \"react\";\nimport type { BannerData } from \"./types\";\n\nconst DISMISSED_KEY = \"vulcantech_dismissed_banners\";\nconst MAX_DISMISSED = 50;\n\nfunction getDismissed(): Set<string> {\n if (typeof window === \"undefined\") return new Set();\n try {\n const raw = localStorage.getItem(DISMISSED_KEY);\n return raw ? new Set(JSON.parse(raw)) : new Set();\n } catch {\n return new Set();\n }\n}\n\nfunction persistDismissed(id: string) {\n if (typeof window === \"undefined\") return;\n try {\n const current = getDismissed();\n current.add(id);\n // Cap stored dismissals to prevent unbounded growth\n const arr = Array.from(current);\n const trimmed = arr.length > MAX_DISMISSED ? arr.slice(-MAX_DISMISSED) : arr;\n localStorage.setItem(DISMISSED_KEY, JSON.stringify(trimmed));\n } catch {\n /* quota */\n }\n}\n\n/**\n * Renders a single banner bar. Handles dismissal via localStorage.\n *\n * `message` and `linkText` are rendered as React children, so they are treated\n * as **plain text** and any markup in them is escaped. `backgroundColor` and\n * `textColor` are applied as inline styles — the host site's theme has no say.\n * `banner.icon` is NOT rendered here (see {@link BannerData.icon}).\n *\n * Dismissal is keyed on `banner.dismissKey || banner.id` and persisted to the\n * shared `vulcantech_dismissed_banners` localStorage key — a JSON array capped\n * at the 50 most recent ids, per-browser rather than per-user-account. Reads and\n * writes are wrapped in try/catch, so blocked or full storage degrades to \"the\n * banner comes back\" instead of throwing. Because the lookup only runs for\n * dismissible banners, flipping `dismissible` to `false` re-shows the banner to\n * everyone who had dismissed it.\n *\n * Returns `null` until mounted (localStorage is unreadable during SSR), so\n * **banners are absent from the server-rendered HTML** and appear after\n * hydration — expect a small shift, and do not rely on banner text for SEO.\n */\nexport function BannerBar({ banner }: { banner: BannerData }) {\n const [dismissed, setDismissedState] = useState(false);\n const [mounted, setMounted] = useState(false);\n\n // Use dismissKey if available, fall back to id for backwards compat\n const dismissId = banner.dismissKey || banner.id;\n\n useEffect(() => {\n setMounted(true);\n if (banner.dismissible && getDismissed().has(dismissId)) {\n setDismissedState(true);\n }\n }, [dismissId, banner.dismissible]);\n\n // Don't render until mounted to avoid hydration mismatch with localStorage\n if (!mounted || dismissed) return null;\n\n const handleDismiss = () => {\n persistDismissed(dismissId);\n setDismissedState(true);\n };\n\n return (\n <div\n id={`cms-banner-${banner.id}`}\n data-banner-id={banner.id}\n data-banner-position={banner.position}\n style={{\n backgroundColor: banner.backgroundColor,\n color: banner.textColor,\n position: \"relative\",\n }}\n >\n <div\n style={{\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: \"0.5rem\",\n padding: banner.dismissible\n ? \"0.625rem 2.5rem 0.625rem 1rem\"\n : \"0.625rem 1rem\",\n fontSize: \"0.875rem\",\n lineHeight: \"1.25rem\",\n textAlign: \"center\",\n minHeight: \"2.5rem\",\n }}\n >\n <span>{banner.message}</span>\n {banner.linkText && banner.linkUrl && (\n <a\n href={banner.linkUrl}\n style={{\n color: banner.textColor,\n fontWeight: 600,\n textDecoration: \"underline\",\n textUnderlineOffset: \"2px\",\n whiteSpace: \"nowrap\",\n }}\n >\n {banner.linkText} →\n </a>\n )}\n </div>\n {banner.dismissible && (\n <button\n type=\"button\"\n onClick={handleDismiss}\n aria-label=\"Dismiss banner\"\n style={{\n position: \"absolute\",\n right: \"0.75rem\",\n top: \"50%\",\n transform: \"translateY(-50%)\",\n background: \"none\",\n border: \"none\",\n color: banner.textColor,\n cursor: \"pointer\",\n padding: \"0.25rem\",\n opacity: 0.7,\n fontSize: \"1.125rem\",\n lineHeight: 1,\n }}\n >\n ✕\n </button>\n )}\n </div>\n );\n}\n","\"use client\";\n\nimport type { BannerData } from \"./types\";\nimport { BannerBar } from \"./BannerBar\";\n\ninterface CMSBannersProps {\n /**\n * All banners fetched server-side via ISR — BOTH positions. The CMS returns\n * top and bottom banners in one payload, already filtered to active +\n * in-schedule and sorted by ascending `priority`; pass the same array to both\n * renders rather than fetching twice.\n */\n banners: BannerData[];\n /** Which position to render — \"top\" or \"bottom\". */\n position: \"top\" | \"bottom\";\n /**\n * Current page path for page-targeted banners (e.g. \"/services\").\n *\n * **Omitting this disables targeting entirely** — every banner passes the\n * filter, including ones with a `pages` list. A root layout is a server\n * component with no pathname, so pass it from a thin `\"use client\"` wrapper\n * that calls `usePathname()`.\n */\n currentPath?: string;\n}\n\n/**\n * Drop-in banner component for consumer site layouts.\n *\n * Filters `banners` to the given `position`, then to `currentPath` (see that\n * prop — subtree prefix match, case-insensitive, trailing slashes ignored),\n * sorts by ascending `priority`, and renders one {@link BannerBar} each.\n *\n * **Never throws and has no error path** — it does no fetching. It returns\n * `null` when nothing matches, which is also what a failed fetch looks like\n * (the recommended fetcher returns `[]` on any failure), so there is no error\n * UI to write.\n *\n * Layout: the `top` group is wrapped in a `position: relative; z-index: 51`\n * div **in normal flow**, the `bottom` group in `position: sticky; bottom: 0;\n * z-index: 40`. A `position: fixed` site header will cover the top banner\n * unless the host site offsets it.\n *\n * Usage in a root layout:\n * ```tsx\n * import { CMSBanners } from \"@vulcantech/banners\";\n *\n * const banners = await fetchBanners(); // ISR cached\n *\n * <body>\n * <CMSBanners banners={banners} position=\"top\" />\n * <Nav />\n * {children}\n * <Footer />\n * <CMSBanners banners={banners} position=\"bottom\" />\n * </body>\n * ```\n */\nexport function CMSBanners({ banners, position, currentPath }: CMSBannersProps) {\n const filtered = banners\n .filter((b) => b.position === position)\n .filter((b) => {\n // No pages specified = show everywhere\n if (!b.pages || b.pages.length === 0) return true;\n if (!currentPath) return true;\n // Match current path against allowed pages\n const path = currentPath.toLowerCase().replace(/\\/+$/, \"\") || \"/\";\n return b.pages.some((p) => {\n const allowed = p.toLowerCase().replace(/\\/+$/, \"\") || \"/\";\n return path === allowed || path.startsWith(allowed + \"/\");\n });\n })\n .sort((a, b) => a.priority - b.priority);\n\n if (filtered.length === 0) return null;\n\n return (\n <div\n style={{\n position: position === \"bottom\" ? \"sticky\" : \"relative\",\n bottom: position === \"bottom\" ? 0 : undefined,\n zIndex: position === \"bottom\" ? 40 : 51,\n width: \"100%\",\n }}\n >\n {filtered.map((banner) => (\n <BannerBar key={banner.id} banner={banner} />\n ))}\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../BannerBar.tsx","../CMSBanners.tsx","../SiteBanners.tsx"],"names":["jsx"],"mappings":";;;;;AAKA,IAAM,aAAA,GAAgB,8BAAA;AACtB,IAAM,aAAA,GAAgB,EAAA;AAEtB,SAAS,YAAA,GAA4B;AACnC,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,EAAa,2BAAW,GAAA,EAAI;AAClD,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,YAAA,CAAa,OAAA,CAAQ,aAAa,CAAA;AAC9C,IAAA,OAAO,GAAA,GAAM,IAAI,GAAA,CAAI,IAAA,CAAK,MAAM,GAAG,CAAC,CAAA,mBAAI,IAAI,GAAA,EAAI;AAAA,EAClD,CAAA,CAAA,OAAQ,CAAA,EAAA;AACN,IAAA,2BAAW,GAAA,EAAI;AAAA,EACjB;AACF;AAEA,SAAS,iBAAiB,EAAA,EAAY;AACpC,EAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACnC,EAAA,IAAI;AACF,IAAA,MAAM,UAAU,YAAA,EAAa;AAC7B,IAAA,OAAA,CAAQ,IAAI,EAAE,CAAA;AAEd,IAAA,MAAM,GAAA,GAAM,KAAA,CAAM,IAAA,CAAK,OAAO,CAAA;AAC9B,IAAA,MAAM,OAAA,GAAU,IAAI,MAAA,GAAS,aAAA,GAAgB,IAAI,KAAA,CAAM,CAAC,aAAa,CAAA,GAAI,GAAA;AACzE,IA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AC,KAAA;AAAA,IAAA;AAAA,MACC,KAAA,EAAO;AAAA,QACL,QAAA,EAAU,QAAA,KAAa,QAAA,GAAW,QAAA,GAAW,UAAA;AAAA,QAC7C,MAAA,EAAQ,QAAA,KAAa,QAAA,GAAW,CAAA,GAAI,MAAA;AAAA,QACpC,MAAA,EAAQ,QAAA,KAAa,QAAA,GAAW,EAAA,GAAK,EAAA;AAAA,QACrC,KAAA,EAAO;AAAA,OACT;AAAA,MAEC,QAAA,EAAA,QAAA,CAAS,GAAA,CAAI,CAAC,MAAA,qBACbA,IAAC,SAAA,EAAA,EAA0B,MAAA,EAAA,EAAX,MAAA,CAAO,EAAoB,CAC5C;AAAA;AAAA,GACH;AAEJ;ACjDO,SAAS,WAAA,CAAY,EAAE,OAAA,EAAS,QAAA,EAAS,EAAqB;AACnE,EAAA,MAAM,WAAW,WAAA,EAAY;AAC7B,EAAA,uBACEA,GAAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,OAAA;AAAA,MACA,QAAA;AAAA,MACA,aAAa,QAAA,IAAA,IAAA,GAAA,QAAA,GAAY;AAAA;AAAA,GAC3B;AAEJ","file":"index.mjs","sourcesContent":["\"use client\";\n\nimport { useState, useEffect } from \"react\";\nimport type { BannerData } from \"./types\";\n\nconst DISMISSED_KEY = \"vulcantech_dismissed_banners\";\nconst MAX_DISMISSED = 50;\n\nfunction getDismissed(): Set<string> {\n if (typeof window === \"undefined\") return new Set();\n try {\n const raw = localStorage.getItem(DISMISSED_KEY);\n return raw ? new Set(JSON.parse(raw)) : new Set();\n } catch {\n return new Set();\n }\n}\n\nfunction persistDismissed(id: string) {\n if (typeof window === \"undefined\") return;\n try {\n const current = getDismissed();\n current.add(id);\n // Cap stored dismissals to prevent unbounded growth\n const arr = Array.from(current);\n const trimmed = arr.length > MAX_DISMISSED ? arr.slice(-MAX_DISMISSED) : arr;\n localStorage.setItem(DISMISSED_KEY, JSON.stringify(trimmed));\n } catch {\n /* quota */\n }\n}\n\n/**\n * Renders a single banner bar. Handles dismissal via localStorage.\n *\n * `message` and `linkText` are rendered as React children, so they are treated\n * as **plain text** and any markup in them is escaped. `backgroundColor` and\n * `textColor` are applied as inline styles — the host site's theme has no say.\n * `banner.icon` is NOT rendered here (see {@link BannerData.icon}).\n *\n * Dismissal is keyed on `banner.dismissKey || banner.id` and persisted to the\n * shared `vulcantech_dismissed_banners` localStorage key — a JSON array capped\n * at the 50 most recent ids, per-browser rather than per-user-account. Reads and\n * writes are wrapped in try/catch, so blocked or full storage degrades to \"the\n * banner comes back\" instead of throwing. Because the lookup only runs for\n * dismissible banners, flipping `dismissible` to `false` re-shows the banner to\n * everyone who had dismissed it.\n *\n * Returns `null` until mounted (localStorage is unreadable during SSR), so\n * **banners are absent from the server-rendered HTML** and appear after\n * hydration — expect a small shift, and do not rely on banner text for SEO.\n */\nexport function BannerBar({ banner }: { banner: BannerData }) {\n const [dismissed, setDismissedState] = useState(false);\n const [mounted, setMounted] = useState(false);\n\n // Use dismissKey if available, fall back to id for backwards compat\n const dismissId = banner.dismissKey || banner.id;\n\n useEffect(() => {\n setMounted(true);\n if (banner.dismissible && getDismissed().has(dismissId)) {\n setDismissedState(true);\n }\n }, [dismissId, banner.dismissible]);\n\n // Don't render until mounted to avoid hydration mismatch with localStorage\n if (!mounted || dismissed) return null;\n\n const handleDismiss = () => {\n persistDismissed(dismissId);\n setDismissedState(true);\n };\n\n return (\n <div\n id={`cms-banner-${banner.id}`}\n data-banner-id={banner.id}\n data-banner-position={banner.position}\n style={{\n backgroundColor: banner.backgroundColor,\n color: banner.textColor,\n position: \"relative\",\n }}\n >\n {/* The link sits inline inside the message paragraph (not a sibling flex\n item), so on narrow screens it wraps with the sentence instead of\n splitting the bar into two columns. */}\n <p\n style={{\n margin: 0,\n padding: banner.dismissible\n ? \"0.625rem 2.5rem 0.625rem 1rem\"\n : \"0.625rem 1rem\",\n fontSize: \"0.875rem\",\n lineHeight: \"1.25rem\",\n textAlign: \"center\",\n }}\n >\n {banner.message}\n {banner.linkText && banner.linkUrl && (\n <>\n {\" \"}\n <a\n href={banner.linkUrl}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n style={{\n color: banner.textColor,\n fontWeight: 600,\n textDecoration: \"underline\",\n textUnderlineOffset: \"2px\",\n cursor: \"pointer\",\n }}\n >\n {banner.linkText} →\n </a>\n </>\n )}\n </p>\n {banner.dismissible && (\n <button\n type=\"button\"\n onClick={handleDismiss}\n aria-label=\"Dismiss banner\"\n style={{\n position: \"absolute\",\n right: \"0.75rem\",\n top: \"50%\",\n transform: \"translateY(-50%)\",\n background: \"none\",\n border: \"none\",\n color: banner.textColor,\n cursor: \"pointer\",\n padding: \"0.25rem\",\n opacity: 0.7,\n fontSize: \"1.125rem\",\n lineHeight: 1,\n }}\n >\n ✕\n </button>\n )}\n </div>\n );\n}\n","\"use client\";\n\nimport type { BannerData } from \"./types\";\nimport { BannerBar } from \"./BannerBar\";\n\ninterface CMSBannersProps {\n /**\n * All banners fetched server-side via ISR — BOTH positions. The CMS returns\n * top and bottom banners in one payload, already filtered to active +\n * in-schedule and sorted by ascending `priority`; pass the same array to both\n * renders rather than fetching twice.\n */\n banners: BannerData[];\n /** Which position to render — \"top\" or \"bottom\". */\n position: \"top\" | \"bottom\";\n /**\n * Current page path for page-targeted banners (e.g. \"/services\").\n *\n * **Omitting this disables targeting entirely** — every banner passes the\n * filter, including ones with a `pages` list. A root layout is a server\n * component with no pathname, so pass it from a thin `\"use client\"` wrapper\n * that calls `usePathname()`.\n */\n currentPath?: string;\n}\n\n/**\n * Drop-in banner component for consumer site layouts.\n *\n * Filters `banners` to the given `position`, then to `currentPath` (see that\n * prop — subtree prefix match, case-insensitive, trailing slashes ignored),\n * sorts by ascending `priority`, and renders one {@link BannerBar} each.\n *\n * **Never throws and has no error path** — it does no fetching. It returns\n * `null` when nothing matches, which is also what a failed fetch looks like\n * (the recommended fetcher returns `[]` on any failure), so there is no error\n * UI to write.\n *\n * Layout: the `top` group is wrapped in a `position: relative; z-index: 51`\n * div **in normal flow**, the `bottom` group in `position: sticky; bottom: 0;\n * z-index: 40`. A `position: fixed` site header will cover the top banner\n * unless the host site offsets it.\n *\n * Next.js root layouts should mount `SiteBanners` instead, which supplies\n * `currentPath` from `usePathname()`. Bare usage (targeting disabled):\n * ```tsx\n * import { CMSBanners } from \"@vulcantech/banners\";\n *\n * const banners = await fetchBanners(); // ISR cached\n *\n * <body>\n * <CMSBanners banners={banners} position=\"top\" />\n * <Nav />\n * {children}\n * <Footer />\n * <CMSBanners banners={banners} position=\"bottom\" />\n * </body>\n * ```\n */\nexport function CMSBanners({ banners, position, currentPath }: CMSBannersProps) {\n const filtered = banners\n .filter((b) => b.position === position)\n .filter((b) => {\n // No pages specified = show everywhere\n if (!b.pages || b.pages.length === 0) return true;\n if (!currentPath) return true;\n // Match current path against allowed pages\n const path = currentPath.toLowerCase().replace(/\\/+$/, \"\") || \"/\";\n return b.pages.some((p) => {\n const allowed = p.toLowerCase().replace(/\\/+$/, \"\") || \"/\";\n return path === allowed || path.startsWith(allowed + \"/\");\n });\n })\n .sort((a, b) => a.priority - b.priority);\n\n if (filtered.length === 0) return null;\n\n return (\n <div\n style={{\n position: position === \"bottom\" ? \"sticky\" : \"relative\",\n bottom: position === \"bottom\" ? 0 : undefined,\n zIndex: position === \"bottom\" ? 40 : 51,\n width: \"100%\",\n }}\n >\n {filtered.map((banner) => (\n <BannerBar key={banner.id} banner={banner} />\n ))}\n </div>\n );\n}\n","\"use client\";\n\nimport { usePathname } from \"next/navigation\";\nimport type { BannerData } from \"./types\";\nimport { CMSBanners } from \"./CMSBanners\";\n\ninterface SiteBannersProps {\n /** All banners from the layout's one fetch — both positions (see `CMSBanners`). */\n banners: BannerData[];\n /** Which position to render — \"top\" or \"bottom\". */\n position: \"top\" | \"bottom\";\n}\n\n/**\n * Path-aware {@link CMSBanners} for Next.js App Router sites — the component a\n * consumer root layout should mount.\n *\n * A root layout is a server component with no pathname, so a bare\n * `<CMSBanners>` there never receives `currentPath` and silently ignores every\n * banner's `pages` targeting. This client component reads `usePathname()` and\n * passes it through, so targeting works and re-evaluates on client-side\n * navigation (the layout itself does not re-render on navigation, but this\n * hook does).\n *\n * Same rendering, stacking and failure behavior as `CMSBanners` — it adds\n * nothing but the path.\n *\n * @param props.banners The full `BannerData[]` from the layout's fetcher.\n * @param props.position Which group to render.\n * @returns The filtered banner group, or `null` when nothing matches.\n *\n * @example\n * ```tsx\n * import { SiteBanners } from \"@vulcantech/banners\";\n *\n * <body>\n * <SiteBanners banners={banners} position=\"top\" />\n * {children}\n * <SiteBanners banners={banners} position=\"bottom\" />\n * </body>\n * ```\n */\nexport function SiteBanners({ banners, position }: SiteBannersProps) {\n const pathname = usePathname();\n return (\n <CMSBanners\n banners={banners}\n position={position}\n currentPath={pathname ?? undefined}\n />\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulcantech/banners",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "CMS-driven announcement banners for consumer sites — top/bottom positions, page targeting, priority ordering, and dismissible bars backed by localStorage",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"source": "./index.ts",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": ">=18.0.0",
|
|
30
|
-
"react-dom": ">=18.0.0"
|
|
30
|
+
"react-dom": ">=18.0.0",
|
|
31
|
+
"next": ">=14.0.0"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@types/react": "^19",
|