@vulcantech/banners 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -3
- package/dist/index.d.mts +109 -7
- package/dist/index.d.ts +109 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -4,6 +4,116 @@ CMS-driven announcement banners for VulcanTech consumer sites. Renders top/botto
|
|
|
4
4
|
|
|
5
5
|
Exports: `CMSBanners` (drop-in layout component), `BannerBar` (single bar), and the `BannerData` type.
|
|
6
6
|
|
|
7
|
+
**Display only** — this package ships no fetcher. You own the server fetch (step 3 below) and pass the result in as props.
|
|
8
|
+
|
|
9
|
+
## Banner shape (`BannerData`)
|
|
10
|
+
|
|
11
|
+
`message` and `linkText` are **plain text**, not HTML — they are rendered as React
|
|
12
|
+
children (`<span>{banner.message}</span>`), so any markup in them is escaped and
|
|
13
|
+
shown literally. There is no HTML field on a banner and nothing here is ever
|
|
14
|
+
injected with `dangerouslySetInnerHTML`.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
interface BannerData {
|
|
18
|
+
id: string; // Firestore doc id
|
|
19
|
+
position: "top" | "bottom"; // which bar this belongs to — you render both
|
|
20
|
+
message: string; // plain text — see above
|
|
21
|
+
linkText?: string; // plain text; a "→" is appended by the renderer
|
|
22
|
+
linkUrl?: string; // plain <a href>, same tab, no next/link
|
|
23
|
+
backgroundColor: string; // raw CSS color, applied inline — required
|
|
24
|
+
textColor: string; // raw CSS color, applied inline — required
|
|
25
|
+
icon?: string; // preset icon NAME, not a URL — not rendered here
|
|
26
|
+
dismissible: boolean; // shows the ✕ button
|
|
27
|
+
/** Key used for dismiss localStorage. Reset in CMS to re-show to users. */
|
|
28
|
+
dismissKey?: string; // rotates on save — see below
|
|
29
|
+
priority: number; // ascending: lower numbers render first
|
|
30
|
+
/** Page slugs where this banner appears. Empty = all pages. */
|
|
31
|
+
pages?: string[]; // needs `currentPath` to have any effect
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Field notes:
|
|
36
|
+
|
|
37
|
+
- **`message` / `linkText` are plain text**; `linkUrl` renders as a bare `<a href>`
|
|
38
|
+
in the same tab with no `target` or `rel`. The CMS rejects `javascript:`,
|
|
39
|
+
`data:` and `vbscript:` URLs on write, so the stored value is a navigable URL.
|
|
40
|
+
- **`backgroundColor` / `textColor`** are whatever string an editor saved (the CMS
|
|
41
|
+
presets store hex like `#2563eb`) and go straight into `style`. They are
|
|
42
|
+
**required** — a banner never falls back to a themed default, so this package
|
|
43
|
+
deliberately ignores your Tailwind theme. Don't expect token classes to apply.
|
|
44
|
+
- **`icon`** is a preset icon *name* (`"info"`, `"alert"`, `"sparkles"`, `"gift"`,
|
|
45
|
+
`"wrench"`, `"rocket"`, `"alert-triangle"`), not an image URL. `BannerBar` does
|
|
46
|
+
**not render it** — only the CMS dashboard preview maps those names to icons.
|
|
47
|
+
Treat it as advisory metadata if you build your own bar.
|
|
48
|
+
- **`dismissKey` vs `id`** — dismissal is keyed on `dismissKey || id` (the fallback
|
|
49
|
+
is for banners created before the field existed). The CMS **regenerates
|
|
50
|
+
`dismissKey` on every save** from the editor's default "Save & Reset Dismiss"
|
|
51
|
+
button, which re-shows the banner to everyone who dismissed it; the "Save
|
|
52
|
+
without resetting" option in that button's dropdown preserves it. So an edited
|
|
53
|
+
banner reappearing for users is intended behavior, not a cache bug.
|
|
54
|
+
- **`priority`** sorts **ascending** — `0` renders above `10`. The CMS already
|
|
55
|
+
returns banners in this order and `CMSBanners` sorts again, so the order is the
|
|
56
|
+
same whichever way you render them.
|
|
57
|
+
- **`pages`** is a list of path prefixes (`["/", "/services", "/blog"]`); empty or
|
|
58
|
+
absent means every page. Matching is case-insensitive, ignores trailing slashes,
|
|
59
|
+
and matches **subtrees** — `"/blog"` also matches `/blog/my-post`, while `"/"`
|
|
60
|
+
matches only the root. **Targeting is inert unless you pass `currentPath`**: with
|
|
61
|
+
no `currentPath` every banner passes the filter, including page-targeted ones.
|
|
62
|
+
Note that the CMS's current `/api/banners` write validators do not persist this
|
|
63
|
+
field, so banners authored through the dashboard today arrive with `pages`
|
|
64
|
+
absent — build against the semantics above, but don't expect live data in it yet.
|
|
65
|
+
|
|
66
|
+
`BannerData` is a **display subset** of the CMS's internal `Banner` record. The API
|
|
67
|
+
response also carries `projectId`, `preset`, `active`, `startDate`, `endDate`,
|
|
68
|
+
`createdAt` and `updatedAt`; they are typed away here because the display
|
|
69
|
+
components never need them. `active` and the date window are applied server-side
|
|
70
|
+
(below), so there is nothing to filter yourself.
|
|
71
|
+
|
|
72
|
+
### Fetching and failure mode
|
|
73
|
+
|
|
74
|
+
`GET /api/banners?projectId=…&apiKey=…` returns `{ banners: BannerData[] }` for
|
|
75
|
+
**both positions at once**, already filtered to `active === true` and inside the
|
|
76
|
+
`startDate`/`endDate` window, sorted by `priority` ascending. Fetch it once in the
|
|
77
|
+
layout and hand the same array to both `<CMSBanners position="top">` and
|
|
78
|
+
`position="bottom"` — do not fetch twice.
|
|
79
|
+
|
|
80
|
+
Two consequences of the server-side date filter:
|
|
81
|
+
|
|
82
|
+
- **Scheduling resolves at fetch time, not render time.** A banner starts or
|
|
83
|
+
expires only as fast as your ISR window (60s in the fetcher below) plus the
|
|
84
|
+
CMS's own `s-maxage=60`. The CMS purges the `banners:{projectId}` tag on every
|
|
85
|
+
create/update/delete, so editor changes land immediately; a `startDate` passing
|
|
86
|
+
on its own does not trigger a purge.
|
|
87
|
+
- Dates are ISO 8601 UTC strings and are compared as strings by the CMS, which is
|
|
88
|
+
correct for the `toISOString()` values its editor writes.
|
|
89
|
+
|
|
90
|
+
**Nothing in this package throws.** The components have no fetching and no error
|
|
91
|
+
path: `CMSBanners` returns `null` when nothing matches the position/path filter,
|
|
92
|
+
and `BannerBar` returns `null` when the banner is dismissed or before mount. The
|
|
93
|
+
recommended fetcher swallows every failure (unconfigured env, non-2xx, network
|
|
94
|
+
error) and returns `[]`. So there is no error UI to write — a broken CMS looks
|
|
95
|
+
exactly like "no banners".
|
|
96
|
+
|
|
97
|
+
### Rendering behavior
|
|
98
|
+
|
|
99
|
+
- Both components are `"use client"`. `BannerBar` renders `null` until it has
|
|
100
|
+
mounted (it must read `localStorage` to know what was dismissed), so **banners
|
|
101
|
+
are never in the server-rendered HTML** — they appear after hydration. Expect a
|
|
102
|
+
small shift at the top of the page and don't rely on banner text for SEO.
|
|
103
|
+
- `CMSBanners` wraps the `top` group in a `position: relative; z-index: 51` div
|
|
104
|
+
**in normal flow**, and the `bottom` group in `position: sticky; bottom: 0;
|
|
105
|
+
z-index: 40`. A site whose header is `position: fixed` will cover the top
|
|
106
|
+
banner — offset the header yourself (measure the rendered height and push the
|
|
107
|
+
header down; the CMS does this with a ResizeObserver and a CSS variable).
|
|
108
|
+
- Dismissals persist to one shared `localStorage` key,
|
|
109
|
+
`vulcantech_dismissed_banners` (a JSON array of dismiss ids, capped at the 50
|
|
110
|
+
most recent). It is per-browser, not per-user account, and the cap means a site
|
|
111
|
+
with heavy banner turnover eventually forgets the oldest dismissals. Writes are
|
|
112
|
+
wrapped in try/catch, so a full or blocked storage quota degrades to "the banner
|
|
113
|
+
comes back", never an exception.
|
|
114
|
+
- Flipping `dismissible` to `false` re-shows the banner to everyone: the dismissal
|
|
115
|
+
lookup only runs for dismissible banners.
|
|
116
|
+
|
|
7
117
|
## Integration
|
|
8
118
|
|
|
9
119
|
Wire banners into a consumer site (Next.js App Router):
|
|
@@ -51,14 +161,35 @@ const banners = await fetchBanners();
|
|
|
51
161
|
// <CMSBanners banners={banners} position="bottom" />
|
|
52
162
|
// </body>
|
|
53
163
|
```
|
|
164
|
+
One fetch feeds both positions — the API returns top and bottom banners together.
|
|
165
|
+
|
|
166
|
+
**4b. (Optional) page targeting** — `pages` is only honored when `CMSBanners`
|
|
167
|
+
receives `currentPath`. A root layout is a server component and has no pathname,
|
|
168
|
+
so pass it from a thin client wrapper:
|
|
169
|
+
```tsx
|
|
170
|
+
"use client";
|
|
171
|
+
import { usePathname } from "next/navigation";
|
|
172
|
+
import { CMSBanners, type BannerData } from "@vulcantech/banners";
|
|
173
|
+
|
|
174
|
+
export function SiteBanners({ banners }: { banners: BannerData[] }) {
|
|
175
|
+
const pathname = usePathname();
|
|
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.
|
|
54
185
|
|
|
55
|
-
**5. ISR invalidation** — ensure `src/app/api/revalidate/route.ts` exists
|
|
186
|
+
**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).
|
|
56
187
|
|
|
57
188
|
### Required env
|
|
58
|
-
`VULCANTECH_PROJECT_ID`, `VULCANTECH_API_KEY` (required) · `VULCANTECH_CMS_URL` (optional, defaults to `https://cms.vulcantech.io`).
|
|
189
|
+
`VULCANTECH_PROJECT_ID`, `VULCANTECH_API_KEY` (required) · `VULCANTECH_REVALIDATE_SECRET` (required for instant ISR purges; see step 5) · `VULCANTECH_CMS_URL` (optional, defaults to `https://cms.vulcantech.io`).
|
|
59
190
|
|
|
60
191
|
### Per-app values
|
|
61
192
|
None beyond env — banners is fully config-driven from the CMS.
|
|
62
193
|
|
|
63
194
|
### Notes
|
|
64
|
-
- Components are `"use client"`; dismissal persists to `localStorage` (`vulcantech_dismissed_banners`).
|
|
195
|
+
- Components are `"use client"`; dismissal persists to `localStorage` (`vulcantech_dismissed_banners`). See [Rendering behavior](#rendering-behavior) for the hydration, stacking, and dismissal-cap details.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,37 +1,122 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Shared banner types used by both the CMS and consumer sites.
|
|
5
5
|
* Keep in sync with apps/vulcantech-cms/src/types/BANNER.ts.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* A single announcement banner, as returned by the CMS
|
|
9
|
+
* `GET /api/banners?projectId=…&apiKey=…` endpoint under `{ banners: [...] }`.
|
|
10
|
+
*
|
|
11
|
+
* This is a **display subset** of the CMS's internal `Banner` record. The API
|
|
12
|
+
* response also carries `projectId`, `preset`, `active`, `startDate`, `endDate`,
|
|
13
|
+
* `createdAt` and `updatedAt`; they are omitted here because the display
|
|
14
|
+
* components never need them. `active` and the `startDate`/`endDate` window are
|
|
15
|
+
* applied server-side, and the list arrives sorted by `priority` ascending, so
|
|
16
|
+
* there is nothing to filter yourself.
|
|
17
|
+
*
|
|
18
|
+
* Every text field is **plain text**, not HTML — `message` and `linkText` are
|
|
19
|
+
* rendered as React children, so markup in them is escaped and shown literally.
|
|
20
|
+
* Nothing in this package uses `dangerouslySetInnerHTML`.
|
|
21
|
+
*
|
|
22
|
+
* One fetch returns BOTH positions; render the same array twice (once per
|
|
23
|
+
* `position`) rather than fetching again.
|
|
24
|
+
*/
|
|
7
25
|
interface BannerData {
|
|
26
|
+
/** Firestore document id (`projects/{projectId}/banners/{id}`). */
|
|
8
27
|
id: string;
|
|
28
|
+
/** Which bar this banner belongs to. Both arrive in the same payload. */
|
|
9
29
|
position: "top" | "bottom";
|
|
30
|
+
/** Plain text, escaped on render — not HTML and not markdown. */
|
|
10
31
|
message: string;
|
|
32
|
+
/** Plain text label for the trailing link; the renderer appends a "→". */
|
|
11
33
|
linkText?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Link target. Rendered as a bare `<a href>` in the same tab, with no
|
|
36
|
+
* `target`/`rel` and no `next/link`. The CMS rejects `javascript:`, `data:`
|
|
37
|
+
* and `vbscript:` URLs on write, so the stored value is navigable.
|
|
38
|
+
*/
|
|
12
39
|
linkUrl?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Raw CSS color applied inline (CMS presets store hex, e.g. `#2563eb`).
|
|
42
|
+
* Required — banners never fall back to a themed default, so this package
|
|
43
|
+
* deliberately ignores the host site's Tailwind theme.
|
|
44
|
+
*/
|
|
13
45
|
backgroundColor: string;
|
|
46
|
+
/** Raw CSS color applied inline. Required, like `backgroundColor`. */
|
|
14
47
|
textColor: string;
|
|
48
|
+
/**
|
|
49
|
+
* Preset icon NAME — one of `info`, `alert`, `sparkles`, `gift`, `wrench`,
|
|
50
|
+
* `rocket`, `alert-triangle` — never an image URL. `BannerBar` does NOT
|
|
51
|
+
* render it; only the CMS dashboard preview maps these names to icons.
|
|
52
|
+
* Treat it as advisory metadata for a custom bar.
|
|
53
|
+
*/
|
|
15
54
|
icon?: string;
|
|
55
|
+
/** Whether the ✕ dismiss button is shown. */
|
|
16
56
|
dismissible: boolean;
|
|
17
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Key used for dismiss localStorage; dismissal is keyed on
|
|
59
|
+
* `dismissKey || id` (the fallback covers banners predating the field).
|
|
60
|
+
*
|
|
61
|
+
* The CMS **regenerates this on every save** from the editor's default
|
|
62
|
+
* "Save & Reset Dismiss" action, which re-shows the banner to everyone who
|
|
63
|
+
* dismissed it. The "Save without resetting" option preserves it. An edited
|
|
64
|
+
* banner reappearing is therefore intended, not a cache bug.
|
|
65
|
+
*/
|
|
18
66
|
dismissKey?: string;
|
|
67
|
+
/** Sort order, **ascending** — `0` renders above `10`. */
|
|
19
68
|
priority: number;
|
|
20
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Path prefixes this banner is targeted at (e.g. `["/", "/services"]`);
|
|
71
|
+
* empty or absent means every page. Matching is case-insensitive, ignores
|
|
72
|
+
* trailing slashes, and matches subtrees — `"/blog"` also matches
|
|
73
|
+
* `/blog/my-post`, while `"/"` matches only the root.
|
|
74
|
+
*
|
|
75
|
+
* Targeting is INERT unless `CMSBanners` receives `currentPath`: with no
|
|
76
|
+
* `currentPath`, every banner passes the filter. Note also that the CMS's
|
|
77
|
+
* current `/api/banners` write validators do not persist this field, so
|
|
78
|
+
* banners authored through the dashboard today arrive with `pages` absent.
|
|
79
|
+
*/
|
|
21
80
|
pages?: string[];
|
|
22
81
|
}
|
|
23
82
|
|
|
24
83
|
interface CMSBannersProps {
|
|
25
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* All banners fetched server-side via ISR — BOTH positions. The CMS returns
|
|
86
|
+
* top and bottom banners in one payload, already filtered to active +
|
|
87
|
+
* in-schedule and sorted by ascending `priority`; pass the same array to both
|
|
88
|
+
* renders rather than fetching twice.
|
|
89
|
+
*/
|
|
26
90
|
banners: BannerData[];
|
|
27
91
|
/** Which position to render — "top" or "bottom". */
|
|
28
92
|
position: "top" | "bottom";
|
|
29
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Current page path for page-targeted banners (e.g. "/services").
|
|
95
|
+
*
|
|
96
|
+
* **Omitting this disables targeting entirely** — every banner passes the
|
|
97
|
+
* filter, including ones with a `pages` list. A root layout is a server
|
|
98
|
+
* component with no pathname, so pass it from a thin `"use client"` wrapper
|
|
99
|
+
* that calls `usePathname()`.
|
|
100
|
+
*/
|
|
30
101
|
currentPath?: string;
|
|
31
102
|
}
|
|
32
103
|
/**
|
|
33
104
|
* Drop-in banner component for consumer site layouts.
|
|
34
105
|
*
|
|
106
|
+
* Filters `banners` to the given `position`, then to `currentPath` (see that
|
|
107
|
+
* prop — subtree prefix match, case-insensitive, trailing slashes ignored),
|
|
108
|
+
* sorts by ascending `priority`, and renders one {@link BannerBar} each.
|
|
109
|
+
*
|
|
110
|
+
* **Never throws and has no error path** — it does no fetching. It returns
|
|
111
|
+
* `null` when nothing matches, which is also what a failed fetch looks like
|
|
112
|
+
* (the recommended fetcher returns `[]` on any failure), so there is no error
|
|
113
|
+
* UI to write.
|
|
114
|
+
*
|
|
115
|
+
* Layout: the `top` group is wrapped in a `position: relative; z-index: 51`
|
|
116
|
+
* div **in normal flow**, the `bottom` group in `position: sticky; bottom: 0;
|
|
117
|
+
* z-index: 40`. A `position: fixed` site header will cover the top banner
|
|
118
|
+
* unless the host site offsets it.
|
|
119
|
+
*
|
|
35
120
|
* Usage in a root layout:
|
|
36
121
|
* ```tsx
|
|
37
122
|
* import { CMSBanners } from "@vulcantech/banners";
|
|
@@ -47,13 +132,30 @@ interface CMSBannersProps {
|
|
|
47
132
|
* </body>
|
|
48
133
|
* ```
|
|
49
134
|
*/
|
|
50
|
-
declare function CMSBanners({ banners, position, currentPath }: CMSBannersProps):
|
|
135
|
+
declare function CMSBanners({ banners, position, currentPath }: CMSBannersProps): react.JSX.Element | null;
|
|
51
136
|
|
|
52
137
|
/**
|
|
53
138
|
* Renders a single banner bar. Handles dismissal via localStorage.
|
|
139
|
+
*
|
|
140
|
+
* `message` and `linkText` are rendered as React children, so they are treated
|
|
141
|
+
* as **plain text** and any markup in them is escaped. `backgroundColor` and
|
|
142
|
+
* `textColor` are applied as inline styles — the host site's theme has no say.
|
|
143
|
+
* `banner.icon` is NOT rendered here (see {@link BannerData.icon}).
|
|
144
|
+
*
|
|
145
|
+
* Dismissal is keyed on `banner.dismissKey || banner.id` and persisted to the
|
|
146
|
+
* shared `vulcantech_dismissed_banners` localStorage key — a JSON array capped
|
|
147
|
+
* at the 50 most recent ids, per-browser rather than per-user-account. Reads and
|
|
148
|
+
* writes are wrapped in try/catch, so blocked or full storage degrades to "the
|
|
149
|
+
* banner comes back" instead of throwing. Because the lookup only runs for
|
|
150
|
+
* dismissible banners, flipping `dismissible` to `false` re-shows the banner to
|
|
151
|
+
* everyone who had dismissed it.
|
|
152
|
+
*
|
|
153
|
+
* Returns `null` until mounted (localStorage is unreadable during SSR), so
|
|
154
|
+
* **banners are absent from the server-rendered HTML** and appear after
|
|
155
|
+
* hydration — expect a small shift, and do not rely on banner text for SEO.
|
|
54
156
|
*/
|
|
55
157
|
declare function BannerBar({ banner }: {
|
|
56
158
|
banner: BannerData;
|
|
57
|
-
}):
|
|
159
|
+
}): react.JSX.Element | null;
|
|
58
160
|
|
|
59
161
|
export { BannerBar, type BannerData, CMSBanners };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,37 +1,122 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Shared banner types used by both the CMS and consumer sites.
|
|
5
5
|
* Keep in sync with apps/vulcantech-cms/src/types/BANNER.ts.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* A single announcement banner, as returned by the CMS
|
|
9
|
+
* `GET /api/banners?projectId=…&apiKey=…` endpoint under `{ banners: [...] }`.
|
|
10
|
+
*
|
|
11
|
+
* This is a **display subset** of the CMS's internal `Banner` record. The API
|
|
12
|
+
* response also carries `projectId`, `preset`, `active`, `startDate`, `endDate`,
|
|
13
|
+
* `createdAt` and `updatedAt`; they are omitted here because the display
|
|
14
|
+
* components never need them. `active` and the `startDate`/`endDate` window are
|
|
15
|
+
* applied server-side, and the list arrives sorted by `priority` ascending, so
|
|
16
|
+
* there is nothing to filter yourself.
|
|
17
|
+
*
|
|
18
|
+
* Every text field is **plain text**, not HTML — `message` and `linkText` are
|
|
19
|
+
* rendered as React children, so markup in them is escaped and shown literally.
|
|
20
|
+
* Nothing in this package uses `dangerouslySetInnerHTML`.
|
|
21
|
+
*
|
|
22
|
+
* One fetch returns BOTH positions; render the same array twice (once per
|
|
23
|
+
* `position`) rather than fetching again.
|
|
24
|
+
*/
|
|
7
25
|
interface BannerData {
|
|
26
|
+
/** Firestore document id (`projects/{projectId}/banners/{id}`). */
|
|
8
27
|
id: string;
|
|
28
|
+
/** Which bar this banner belongs to. Both arrive in the same payload. */
|
|
9
29
|
position: "top" | "bottom";
|
|
30
|
+
/** Plain text, escaped on render — not HTML and not markdown. */
|
|
10
31
|
message: string;
|
|
32
|
+
/** Plain text label for the trailing link; the renderer appends a "→". */
|
|
11
33
|
linkText?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Link target. Rendered as a bare `<a href>` in the same tab, with no
|
|
36
|
+
* `target`/`rel` and no `next/link`. The CMS rejects `javascript:`, `data:`
|
|
37
|
+
* and `vbscript:` URLs on write, so the stored value is navigable.
|
|
38
|
+
*/
|
|
12
39
|
linkUrl?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Raw CSS color applied inline (CMS presets store hex, e.g. `#2563eb`).
|
|
42
|
+
* Required — banners never fall back to a themed default, so this package
|
|
43
|
+
* deliberately ignores the host site's Tailwind theme.
|
|
44
|
+
*/
|
|
13
45
|
backgroundColor: string;
|
|
46
|
+
/** Raw CSS color applied inline. Required, like `backgroundColor`. */
|
|
14
47
|
textColor: string;
|
|
48
|
+
/**
|
|
49
|
+
* Preset icon NAME — one of `info`, `alert`, `sparkles`, `gift`, `wrench`,
|
|
50
|
+
* `rocket`, `alert-triangle` — never an image URL. `BannerBar` does NOT
|
|
51
|
+
* render it; only the CMS dashboard preview maps these names to icons.
|
|
52
|
+
* Treat it as advisory metadata for a custom bar.
|
|
53
|
+
*/
|
|
15
54
|
icon?: string;
|
|
55
|
+
/** Whether the ✕ dismiss button is shown. */
|
|
16
56
|
dismissible: boolean;
|
|
17
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Key used for dismiss localStorage; dismissal is keyed on
|
|
59
|
+
* `dismissKey || id` (the fallback covers banners predating the field).
|
|
60
|
+
*
|
|
61
|
+
* The CMS **regenerates this on every save** from the editor's default
|
|
62
|
+
* "Save & Reset Dismiss" action, which re-shows the banner to everyone who
|
|
63
|
+
* dismissed it. The "Save without resetting" option preserves it. An edited
|
|
64
|
+
* banner reappearing is therefore intended, not a cache bug.
|
|
65
|
+
*/
|
|
18
66
|
dismissKey?: string;
|
|
67
|
+
/** Sort order, **ascending** — `0` renders above `10`. */
|
|
19
68
|
priority: number;
|
|
20
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Path prefixes this banner is targeted at (e.g. `["/", "/services"]`);
|
|
71
|
+
* empty or absent means every page. Matching is case-insensitive, ignores
|
|
72
|
+
* trailing slashes, and matches subtrees — `"/blog"` also matches
|
|
73
|
+
* `/blog/my-post`, while `"/"` matches only the root.
|
|
74
|
+
*
|
|
75
|
+
* Targeting is INERT unless `CMSBanners` receives `currentPath`: with no
|
|
76
|
+
* `currentPath`, every banner passes the filter. Note also that the CMS's
|
|
77
|
+
* current `/api/banners` write validators do not persist this field, so
|
|
78
|
+
* banners authored through the dashboard today arrive with `pages` absent.
|
|
79
|
+
*/
|
|
21
80
|
pages?: string[];
|
|
22
81
|
}
|
|
23
82
|
|
|
24
83
|
interface CMSBannersProps {
|
|
25
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* All banners fetched server-side via ISR — BOTH positions. The CMS returns
|
|
86
|
+
* top and bottom banners in one payload, already filtered to active +
|
|
87
|
+
* in-schedule and sorted by ascending `priority`; pass the same array to both
|
|
88
|
+
* renders rather than fetching twice.
|
|
89
|
+
*/
|
|
26
90
|
banners: BannerData[];
|
|
27
91
|
/** Which position to render — "top" or "bottom". */
|
|
28
92
|
position: "top" | "bottom";
|
|
29
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Current page path for page-targeted banners (e.g. "/services").
|
|
95
|
+
*
|
|
96
|
+
* **Omitting this disables targeting entirely** — every banner passes the
|
|
97
|
+
* filter, including ones with a `pages` list. A root layout is a server
|
|
98
|
+
* component with no pathname, so pass it from a thin `"use client"` wrapper
|
|
99
|
+
* that calls `usePathname()`.
|
|
100
|
+
*/
|
|
30
101
|
currentPath?: string;
|
|
31
102
|
}
|
|
32
103
|
/**
|
|
33
104
|
* Drop-in banner component for consumer site layouts.
|
|
34
105
|
*
|
|
106
|
+
* Filters `banners` to the given `position`, then to `currentPath` (see that
|
|
107
|
+
* prop — subtree prefix match, case-insensitive, trailing slashes ignored),
|
|
108
|
+
* sorts by ascending `priority`, and renders one {@link BannerBar} each.
|
|
109
|
+
*
|
|
110
|
+
* **Never throws and has no error path** — it does no fetching. It returns
|
|
111
|
+
* `null` when nothing matches, which is also what a failed fetch looks like
|
|
112
|
+
* (the recommended fetcher returns `[]` on any failure), so there is no error
|
|
113
|
+
* UI to write.
|
|
114
|
+
*
|
|
115
|
+
* Layout: the `top` group is wrapped in a `position: relative; z-index: 51`
|
|
116
|
+
* div **in normal flow**, the `bottom` group in `position: sticky; bottom: 0;
|
|
117
|
+
* z-index: 40`. A `position: fixed` site header will cover the top banner
|
|
118
|
+
* unless the host site offsets it.
|
|
119
|
+
*
|
|
35
120
|
* Usage in a root layout:
|
|
36
121
|
* ```tsx
|
|
37
122
|
* import { CMSBanners } from "@vulcantech/banners";
|
|
@@ -47,13 +132,30 @@ interface CMSBannersProps {
|
|
|
47
132
|
* </body>
|
|
48
133
|
* ```
|
|
49
134
|
*/
|
|
50
|
-
declare function CMSBanners({ banners, position, currentPath }: CMSBannersProps):
|
|
135
|
+
declare function CMSBanners({ banners, position, currentPath }: CMSBannersProps): react.JSX.Element | null;
|
|
51
136
|
|
|
52
137
|
/**
|
|
53
138
|
* Renders a single banner bar. Handles dismissal via localStorage.
|
|
139
|
+
*
|
|
140
|
+
* `message` and `linkText` are rendered as React children, so they are treated
|
|
141
|
+
* as **plain text** and any markup in them is escaped. `backgroundColor` and
|
|
142
|
+
* `textColor` are applied as inline styles — the host site's theme has no say.
|
|
143
|
+
* `banner.icon` is NOT rendered here (see {@link BannerData.icon}).
|
|
144
|
+
*
|
|
145
|
+
* Dismissal is keyed on `banner.dismissKey || banner.id` and persisted to the
|
|
146
|
+
* shared `vulcantech_dismissed_banners` localStorage key — a JSON array capped
|
|
147
|
+
* at the 50 most recent ids, per-browser rather than per-user-account. Reads and
|
|
148
|
+
* writes are wrapped in try/catch, so blocked or full storage degrades to "the
|
|
149
|
+
* banner comes back" instead of throwing. Because the lookup only runs for
|
|
150
|
+
* dismissible banners, flipping `dismissible` to `false` re-shows the banner to
|
|
151
|
+
* everyone who had dismissed it.
|
|
152
|
+
*
|
|
153
|
+
* Returns `null` until mounted (localStorage is unreadable during SSR), so
|
|
154
|
+
* **banners are absent from the server-rendered HTML** and appear after
|
|
155
|
+
* hydration — expect a small shift, and do not rely on banner text for SEO.
|
|
54
156
|
*/
|
|
55
157
|
declare function BannerBar({ banner }: {
|
|
56
158
|
banner: BannerData;
|
|
57
|
-
}):
|
|
159
|
+
}): react.JSX.Element | null;
|
|
58
160
|
|
|
59
161
|
export { BannerBar, type BannerData, CMSBanners };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../BannerBar.tsx","../CMSBanners.tsx"],"names":["useState","useEffect","jsxs","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,M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AE,QAAQ,CAAA;AAEzC,EAAA,IAAI,QAAA,CAAS,MAAA,KAAW,CAAA,EAAG,OAAO,IAAA;AAElC,EAAA,uBACEA,cAAAA;AAAA,IAAC,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,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 */\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 /** All banners fetched server-side via ISR. */\n banners: BannerData[];\n /** Which position to render — \"top\" or \"bottom\". */\n position: \"top\" | \"bottom\";\n /** Current page path for page-targeted banners (e.g. \"/services\"). */\n currentPath?: string;\n}\n\n/**\n * Drop-in banner component for consumer site layouts.\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"],"names":["useState","useEffect","jsxs","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,GA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,IAAK,GAAA;AAC9D,IAAA,OAAO,CAAA,CAAE,KAAA,CAAM,IAAA,CAAK,CAAC,CAAA,KAAM;AACzB,MAAA,MAAM,UAAU,CAAA,CAAE,WAAA,GAAc,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA,IAAK,GAAA;AACvD,MAAA,OAAO,IAAA,KAAS,OAAA,IAAW,IAAA,CAAK,UAAA,CAAW,UAAU,GAAG,CAAA;AAAA,IAC1D,CAAC,CAAA;AAAA,EACH,CAAC,EACA,IAAA,CAAK,CAAC,GAAG,CAAA,KAAM,CAAA,CAAE,QAAA,GAAW,CAAA,CAAE,QAAQ,CAAA;AAEzC,EAAA,IAAI,QAAA,CAAS,MAAA,KAAW,CAAA,EAAG,OAAO,IAAA;AAElC,EAAA,uBACEA,cAAAA;AAAA,IAAC,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,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"]}
|
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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annerData } 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 */\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 /** All banners fetched server-side via ISR. */\n banners: BannerData[];\n /** Which position to render — \"top\" or \"bottom\". */\n position: \"top\" | \"bottom\";\n /** Current page path for page-targeted banners (e.g. \"/services\"). */\n currentPath?: string;\n}\n\n/**\n * Drop-in banner component for consumer site layouts.\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"],"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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AAa,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","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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulcantech/banners",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"import": "./dist/index.mjs",
|
|
14
14
|
"require": "./dist/index.js",
|
|
15
|
-
"default": "./index.
|
|
15
|
+
"default": "./dist/index.mjs"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
],
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|
|
46
|
-
"url": "https://github.com/vulcantech/vulcantech"
|
|
46
|
+
"url": "git+https://github.com/vulcantech/vulcantech.git"
|
|
47
47
|
},
|
|
48
48
|
"author": "VulcanTech <vulcantechnologies.io@gmail.com>",
|
|
49
49
|
"publishConfig": {
|