@veroxm/react-sdk 0.0.0-stage → 0.1.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.
Files changed (98) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +295 -2
  4. package/dist/cache.d.ts +69 -0
  5. package/dist/cache.js +89 -0
  6. package/dist/client-slots.d.ts +35 -0
  7. package/dist/client-slots.js +169 -0
  8. package/dist/client.d.ts +65 -0
  9. package/dist/client.js +87 -0
  10. package/dist/editor/constants.d.ts +12 -0
  11. package/dist/editor/constants.js +12 -0
  12. package/dist/editor/handler.d.ts +16 -0
  13. package/dist/editor/handler.js +175 -0
  14. package/dist/editor/inline.d.ts +25 -0
  15. package/dist/editor/inline.js +149 -0
  16. package/dist/editor/menu-input.d.ts +26 -0
  17. package/dist/editor/menu-input.js +110 -0
  18. package/dist/editor/overlay.d.ts +31 -0
  19. package/dist/editor/overlay.js +856 -0
  20. package/dist/editor/rich-text.d.ts +21 -0
  21. package/dist/editor/rich-text.js +232 -0
  22. package/dist/editor/server.d.ts +9 -0
  23. package/dist/editor/server.js +43 -0
  24. package/dist/errors.d.ts +20 -0
  25. package/dist/errors.js +26 -0
  26. package/dist/hooks/use-cached-query.d.ts +21 -0
  27. package/dist/hooks/use-cached-query.js +59 -0
  28. package/dist/hooks/use-collection.d.ts +10 -0
  29. package/dist/hooks/use-collection.js +14 -0
  30. package/dist/hooks/use-entries.d.ts +18 -0
  31. package/dist/hooks/use-entries.js +25 -0
  32. package/dist/hooks/use-entry.d.ts +21 -0
  33. package/dist/hooks/use-entry.js +22 -0
  34. package/dist/hooks/use-media.d.ts +9 -0
  35. package/dist/hooks/use-media.js +13 -0
  36. package/dist/hydration-boundary.d.ts +35 -0
  37. package/dist/hydration-boundary.js +38 -0
  38. package/dist/image.d.ts +34 -0
  39. package/dist/image.js +39 -0
  40. package/dist/index.d.ts +46 -0
  41. package/dist/index.js +32 -0
  42. package/dist/next/cache-components.d.ts +15 -0
  43. package/dist/next/cache-components.js +25 -0
  44. package/dist/next/cached.d.ts +9 -0
  45. package/dist/next/cached.js +20 -0
  46. package/dist/next/edge-slot.d.ts +21 -0
  47. package/dist/next/edge-slot.js +29 -0
  48. package/dist/next/editor.d.ts +7 -0
  49. package/dist/next/editor.js +13 -0
  50. package/dist/next/index.d.ts +17 -0
  51. package/dist/next/index.js +21 -0
  52. package/dist/next/llms.d.ts +2 -0
  53. package/dist/next/llms.js +44 -0
  54. package/dist/next/route.d.ts +12 -0
  55. package/dist/next/route.js +16 -0
  56. package/dist/next/slot.d.ts +21 -0
  57. package/dist/next/slot.js +160 -0
  58. package/dist/node.d.ts +43 -0
  59. package/dist/node.js +67 -0
  60. package/dist/preview.d.ts +35 -0
  61. package/dist/preview.js +46 -0
  62. package/dist/provider.d.ts +29 -0
  63. package/dist/provider.js +37 -0
  64. package/dist/query-keys.d.ts +19 -0
  65. package/dist/query-keys.js +49 -0
  66. package/dist/site/chart-view.d.ts +14 -0
  67. package/dist/site/chart-view.js +44 -0
  68. package/dist/site/chart.d.ts +127 -0
  69. package/dist/site/chart.js +639 -0
  70. package/dist/site/map-embed.d.ts +32 -0
  71. package/dist/site/map-embed.js +139 -0
  72. package/dist/site/map-math.d.ts +27 -0
  73. package/dist/site/map-math.js +89 -0
  74. package/dist/site/nav-menu.d.ts +19 -0
  75. package/dist/site/nav-menu.js +76 -0
  76. package/dist/site/site-parts.d.ts +87 -0
  77. package/dist/site/site-parts.js +46 -0
  78. package/dist/site/slider.d.ts +17 -0
  79. package/dist/site/slider.js +78 -0
  80. package/dist/site/styles.d.ts +3 -0
  81. package/dist/site/styles.js +155 -0
  82. package/dist/site/video-embed.d.ts +15 -0
  83. package/dist/site/video-embed.js +27 -0
  84. package/dist/site/video.d.ts +18 -0
  85. package/dist/site/video.js +73 -0
  86. package/dist/slots-core.d.ts +397 -0
  87. package/dist/slots-core.js +367 -0
  88. package/dist/slots.d.ts +13 -0
  89. package/dist/slots.js +30 -0
  90. package/dist/ssr.d.ts +20 -0
  91. package/dist/ssr.js +35 -0
  92. package/dist/structured-data.d.ts +13 -0
  93. package/dist/structured-data.js +36 -0
  94. package/dist/tracking.d.ts +142 -0
  95. package/dist/tracking.js +152 -0
  96. package/dist/types.d.ts +106 -0
  97. package/dist/types.js +6 -0
  98. package/package.json +95 -4
@@ -0,0 +1,38 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useVeroxmClient } from './provider.js';
3
+ /**
4
+ * Seeds the nearest <VeroxmProvider>'s cache with already-fetched data
5
+ * BEFORE this subtree's own hooks (§5.2) mount, so a hook whose query
6
+ * matches one of `state`'s keys sees it as already-fresh and skips an
7
+ * immediate client-side refetch (docs/REACT-SDK-GRAPHQL-IMPLEMENTATION-
8
+ * PLAN.md §5.5) -- the "no double-fetch" piece of SSR support. Typical
9
+ * Next.js usage: fetch server-side with ./ssr.ts's helpers, pass the
10
+ * data down as normal props/RSC payload for your own rendering, AND pass
11
+ * each result's `hydration` here so the client-side useEntries()/
12
+ * useEntry()/etc. for that same query doesn't re-fetch on mount:
13
+ *
14
+ * ```tsx
15
+ * const { data, hydration } = await fetchEntries(client, 'posts');
16
+ * return (
17
+ * <VeroxmHydrationBoundary state={hydration}>
18
+ * <PostsList initialPosts={data} />
19
+ * </VeroxmHydrationBoundary>
20
+ * );
21
+ * ```
22
+ *
23
+ * Seeding happens synchronously during render (not inside a useEffect),
24
+ * so it's in place before any descendant hook's own mount-time effect
25
+ * runs. Seeding is idempotent and cheap, so this runs unconditionally on
26
+ * every render, not just the first -- a re-render with the same
27
+ * server-fetched props just means "this data is still fresh", which is
28
+ * exactly what it should mean.
29
+ */
30
+ export function VeroxmHydrationBoundary(props) {
31
+ const { state, children } = props;
32
+ const client = useVeroxmClient();
33
+ const entries = Array.isArray(state) ? state : [state];
34
+ for (const entry of entries) {
35
+ client.cache.seed(entry.key, entry.data, entry.tags);
36
+ }
37
+ return _jsx(_Fragment, { children: children });
38
+ }
@@ -0,0 +1,34 @@
1
+ import type { ComponentPropsWithoutRef, ReactElement } from 'react';
2
+ import type { MediaView } from './types.js';
3
+ type VeroxmImageMedia = Pick<MediaView, 'fullUrl' | 'thumbUrl' | 'fullWebpUrl' | 'thumbWebpUrl' | 'width' | 'height' | 'caption' | 'focalPoint'>;
4
+ /** CSS object-position for a media item's focal point ("50% 50%" without one). */
5
+ export declare function focalPosition(media: {
6
+ focalPoint?: {
7
+ x: number;
8
+ y: number;
9
+ } | null;
10
+ }): string;
11
+ export interface VeroxmImageProps extends Omit<ComponentPropsWithoutRef<'img'>, 'src' | 'srcSet'> {
12
+ media: VeroxmImageMedia;
13
+ /** Render the thumbnail variant (thumbUrl/thumbWebpUrl) instead of the full-size original (fullUrl/fullWebpUrl). Defaults to false. */
14
+ thumb?: boolean;
15
+ }
16
+ /**
17
+ * Renders one of PublicContentService's already-generated media variants
18
+ * (docs/REACT-SDK-GRAPHQL-IMPLEMENTATION-PLAN.md §5.6) as a `<picture>`
19
+ * -- the WebP variant preferred via a `<source>`, the original format as
20
+ * the `<img>` fallback for a browser/crawler that doesn't support WebP.
21
+ * No new server-side image transform work needed; this only consumes
22
+ * URLs apps/api's toMediaPublicView() already produces.
23
+ *
24
+ * Lazy-loads by default (`loading="lazy"`) -- pass `loading="eager"` for
25
+ * an above-the-fold image. Uses `media.width`/`media.height` to avoid
26
+ * layout shift unless you override them via `width`/`height` props (e.g.
27
+ * to display the image at a different size than its stored dimensions).
28
+ * `thumbUrl`/`thumbWebpUrl` are `null` for a non-image file or when no
29
+ * thumbnail was generated for it (see MediaView's own comment) -- this
30
+ * falls back to the full-size variant rather than rendering a broken
31
+ * `<img>` in that case.
32
+ */
33
+ export declare function VeroxmImage(props: VeroxmImageProps): ReactElement;
34
+ export {};
package/dist/image.js ADDED
@@ -0,0 +1,39 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /** CSS object-position for a media item's focal point ("50% 50%" without one). */
3
+ export function focalPosition(media) {
4
+ const p = media.focalPoint;
5
+ if (!p || !Number.isFinite(p.x) || !Number.isFinite(p.y))
6
+ return '50% 50%';
7
+ const clamp = (v) => Math.min(100, Math.max(0, Math.round(v * 10000) / 100));
8
+ return `${clamp(p.x)}% ${clamp(p.y)}%`;
9
+ }
10
+ /**
11
+ * Renders one of PublicContentService's already-generated media variants
12
+ * (docs/REACT-SDK-GRAPHQL-IMPLEMENTATION-PLAN.md §5.6) as a `<picture>`
13
+ * -- the WebP variant preferred via a `<source>`, the original format as
14
+ * the `<img>` fallback for a browser/crawler that doesn't support WebP.
15
+ * No new server-side image transform work needed; this only consumes
16
+ * URLs apps/api's toMediaPublicView() already produces.
17
+ *
18
+ * Lazy-loads by default (`loading="lazy"`) -- pass `loading="eager"` for
19
+ * an above-the-fold image. Uses `media.width`/`media.height` to avoid
20
+ * layout shift unless you override them via `width`/`height` props (e.g.
21
+ * to display the image at a different size than its stored dimensions).
22
+ * `thumbUrl`/`thumbWebpUrl` are `null` for a non-image file or when no
23
+ * thumbnail was generated for it (see MediaView's own comment) -- this
24
+ * falls back to the full-size variant rather than rendering a broken
25
+ * `<img>` in that case.
26
+ */
27
+ export function VeroxmImage(props) {
28
+ const { media, thumb = false, width, height, loading = 'lazy', alt, style, ...imgProps } = props;
29
+ const webpSrc = thumb ? media.thumbWebpUrl : media.fullWebpUrl;
30
+ const fallbackSrc = (thumb ? media.thumbUrl : media.fullUrl) ?? media.fullUrl;
31
+ return (_jsxs("picture", { children: [webpSrc ? _jsx("source", { srcSet: webpSrc, type: "image/webp" }) : null, _jsx("img", { src: fallbackSrc, width: width ?? media.width ?? undefined, height: height ?? media.height ?? undefined, loading: loading,
32
+ // Falls back to the media item's own caption, then an empty
33
+ // string (a purely decorative image) -- never omits alt
34
+ // entirely, which would leave assistive tech reading the
35
+ // filename or full URL instead.
36
+ alt: alt ?? media.caption ?? '',
37
+ // Crops (object-fit: cover) keep the focal point set in VeroXM in view; your own style wins.
38
+ style: { objectPosition: focalPosition(media), ...style }, ...imgProps })] }));
39
+ }
@@ -0,0 +1,46 @@
1
+ export { VeroxmProvider, useVeroxmClient } from './provider.js';
2
+ export type { VeroxmProviderProps } from './provider.js';
3
+ export { VeroxmClient } from './client.js';
4
+ export type { VeroxmClientOptions } from './client.js';
5
+ export { VeroxmCache } from './cache.js';
6
+ export type { CacheOptions } from './cache.js';
7
+ export { VeroxmGraphQLError } from './errors.js';
8
+ export { useCollection } from './hooks/use-collection.js';
9
+ export { useEntry } from './hooks/use-entry.js';
10
+ export type { UseEntryOptions } from './hooks/use-entry.js';
11
+ export { useEntries } from './hooks/use-entries.js';
12
+ export { useMedia } from './hooks/use-media.js';
13
+ export type { QueryState } from './hooks/use-cached-query.js';
14
+ export { VeroxmPreviewProvider, useDraftMode } from './preview.js';
15
+ export type { VeroxmPreviewProviderProps, DraftModeState } from './preview.js';
16
+ export { fetchCollection, fetchCollections, fetchEntry, fetchEntries, fetchMedia } from './ssr.js';
17
+ export type { SsrResult, VeroxmHydrationEntry } from './ssr.js';
18
+ export { VeroxmHydrationBoundary } from './hydration-boundary.js';
19
+ export type { VeroxmHydrationBoundaryProps } from './hydration-boundary.js';
20
+ export { VeroxmImage, focalPosition } from './image.js';
21
+ export type { VeroxmImageProps } from './image.js';
22
+ export { NavMenu, isSafeMenuHref } from './site/nav-menu.js';
23
+ export type { NavMenuProps } from './site/nav-menu.js';
24
+ export { SiteHeader, SiteFooter, headerFields, footerFields } from './site/site-parts.js';
25
+ export type { SiteHeaderProps, SiteFooterProps } from './site/site-parts.js';
26
+ export { VeroxmSiteStyles, SITE_STYLES } from './site/styles.js';
27
+ export { VideoEmbed } from './site/video-embed.js';
28
+ export type { VideoEmbedProps } from './site/video-embed.js';
29
+ export { Slider } from './site/slider.js';
30
+ export { MapEmbed } from './site/map-embed.js';
31
+ export type { MapEmbedProps } from './site/map-embed.js';
32
+ export { parseMapLink } from './site/map-math.js';
33
+ export { Chart } from './site/chart-view.js';
34
+ export type { ChartProps } from './site/chart-view.js';
35
+ export { chartSvg, chartSummary, formatChartNumber, chartFromRows, chartDataFromRows, CHART_TEMPLATES } from './site/chart.js';
36
+ export type { ChartValue, ChartKind, ChartSeries, ChartSource, ChartTemplate, RowsSpec } from './site/chart.js';
37
+ export type { SliderProps } from './site/slider.js';
38
+ export { parseVideoUrl, videoEmbedUrl, videoThumbnailUrl } from './site/video.js';
39
+ export type { VideoRef, VideoProvider } from './site/video.js';
40
+ export type { CollectionFieldMeta, CollectionMeta, Entry, EntryConnection, EntriesQueryOptions, MediaView, MediaHotspot, WhereClause, } from './types.js';
41
+ export { VeroxmTrackerProvider, useTracker, usePageViews, useExperience, Experience, useContentView, useRecommendations, } from './tracking.js';
42
+ export type { VeroxmTrackerProviderProps, VeroxmTrackerLike, ExperienceDecision, ExperienceState, ExperienceProps, RecommendationsState, } from './tracking.js';
43
+ export { VeroxmSlot, useSlot, field, configureSlots, loadSlot, mergeSlotValues } from './slots.js';
44
+ export type { VeroxmSlotProps, SlotFieldDef, SlotFieldDefs, SlotValues, SlotInfo, SlotTest, SlotMedia, SlotLink, SlotMenuItem, SlotVideo, SlotSlide, SlotMap, SlotPlace, SlotChart, SlotState, SlotsConfig, LoadSlotOptions, SlotPerson, } from './slots.js';
45
+ export { loadStructuredData, jsonLdScript } from './structured-data.js';
46
+ export type { StructuredDataOptions } from './structured-data.js';
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ export { VeroxmProvider, useVeroxmClient } from './provider.js';
2
+ export { VeroxmClient } from './client.js';
3
+ export { VeroxmCache } from './cache.js';
4
+ export { VeroxmGraphQLError } from './errors.js';
5
+ export { useCollection } from './hooks/use-collection.js';
6
+ export { useEntry } from './hooks/use-entry.js';
7
+ export { useEntries } from './hooks/use-entries.js';
8
+ export { useMedia } from './hooks/use-media.js';
9
+ // Live preview / draft mode (§5.4).
10
+ export { VeroxmPreviewProvider, useDraftMode } from './preview.js';
11
+ // SSR / Next.js helpers (§5.5).
12
+ export { fetchCollection, fetchCollections, fetchEntry, fetchEntries, fetchMedia } from './ssr.js';
13
+ export { VeroxmHydrationBoundary } from './hydration-boundary.js';
14
+ // Media/image component (§5.6).
15
+ export { VeroxmImage, focalPosition } from './image.js';
16
+ // Site parts: a menu with sub-menus, header and footer, from slot fields.
17
+ export { NavMenu, isSafeMenuHref } from './site/nav-menu.js';
18
+ export { SiteHeader, SiteFooter, headerFields, footerFields } from './site/site-parts.js';
19
+ export { VeroxmSiteStyles, SITE_STYLES } from './site/styles.js';
20
+ export { VideoEmbed } from './site/video-embed.js';
21
+ export { Slider } from './site/slider.js';
22
+ export { MapEmbed } from './site/map-embed.js';
23
+ export { parseMapLink } from './site/map-math.js';
24
+ export { Chart } from './site/chart-view.js';
25
+ export { chartSvg, chartSummary, formatChartNumber, chartFromRows, chartDataFromRows, CHART_TEMPLATES } from './site/chart.js';
26
+ export { parseVideoUrl, videoEmbedUrl, videoThumbnailUrl } from './site/video.js';
27
+ // Experience OS visitor tracking -- pair with @veroxm/sdk's createTracker().
28
+ export { VeroxmTrackerProvider, useTracker, usePageViews, useExperience, Experience, useContentView, useRecommendations, } from './tracking.js';
29
+ // Visual slots (Experience Layer): named regions marketers edit from VeroXM.
30
+ export { VeroxmSlot, useSlot, field, configureSlots, loadSlot, mergeSlotValues } from './slots.js';
31
+ // Structured data (schema.org JSON-LD) for a page: render jsonLdScript(data) in a <script type="application/ld+json">.
32
+ export { loadStructuredData, jsonLdScript } from './structured-data.js';
@@ -0,0 +1,15 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { SlotFieldDefs, VeroxmSlotProps } from '../slots-core.js';
3
+ export declare function VeroxmSlot<F extends SlotFieldDefs>(props: VeroxmSlotProps<F>): Promise<ReactNode>;
4
+ export { VeroxmEditor } from './editor.js';
5
+ export { field, configureSlots, mergeSlotValues } from '../slots-core.js';
6
+ export type { VeroxmSlotProps, SlotFieldDef, SlotFieldDefs, SlotValues, SlotInfo, SlotTest, SlotMedia, SlotLink, SlotMenuItem, SlotVideo, SlotSlide, SlotMap, SlotPlace, SlotChart, SlotsConfig } from '../slots-core.js';
7
+ export { NavMenu } from '../site/nav-menu.js';
8
+ export { SiteHeader, SiteFooter, headerFields, footerFields } from '../site/site-parts.js';
9
+ export { VeroxmSiteStyles } from '../site/styles.js';
10
+ export { VideoEmbed } from '../site/video-embed.js';
11
+ export { Slider } from '../site/slider.js';
12
+ export { MapEmbed } from '../site/map-embed.js';
13
+ export { Chart } from '../site/chart-view.js';
14
+ export { chartFromRows } from '../site/chart.js';
15
+ export { parseVideoUrl } from '../site/video.js';
@@ -0,0 +1,25 @@
1
+ import { slotWith } from './slot.js';
2
+ import { cachedPublishedSlot } from './cached.js';
3
+ // @veroxm/react-sdk/next/cache-components -- <VeroxmSlot> for Next.js apps
4
+ // with `cacheComponents: true`. Same props and behaviour as the one from
5
+ // '@veroxm/react-sdk/next', but each slot's published content is cached
6
+ // with 'use cache' (tag "veroxm-slots"), so it is part of the static shell
7
+ // instead of being fetched on every request. A slot under a live A/B test
8
+ // shows the published version in the shell and streams the visitor's
9
+ // variant in. (Kept separate because 'use cache' only compiles when Cache
10
+ // Components is on.)
11
+ export function VeroxmSlot(props) {
12
+ return slotWith(props, cachedPublishedSlot, true);
13
+ }
14
+ export { VeroxmEditor } from './editor.js';
15
+ export { field, configureSlots, mergeSlotValues } from '../slots-core.js';
16
+ // Site parts: header, footer and menus from slot fields.
17
+ export { NavMenu } from '../site/nav-menu.js';
18
+ export { SiteHeader, SiteFooter, headerFields, footerFields } from '../site/site-parts.js';
19
+ export { VeroxmSiteStyles } from '../site/styles.js';
20
+ export { VideoEmbed } from '../site/video-embed.js';
21
+ export { Slider } from '../site/slider.js';
22
+ export { MapEmbed } from '../site/map-embed.js';
23
+ export { Chart } from '../site/chart-view.js';
24
+ export { chartFromRows } from '../site/chart.js';
25
+ export { parseVideoUrl } from '../site/video.js';
@@ -0,0 +1,9 @@
1
+ import { type PublishedSlot, type SlotFieldDefs } from '../slots-core.js';
2
+ export declare function cachedPublishedSlot(name: string, locale: string | undefined, def?: SlotDefinition): Promise<PublishedSlot | null>;
3
+ export interface SlotDefinition {
4
+ fields: SlotFieldDefs;
5
+ label?: string;
6
+ path?: string;
7
+ /** What the site shows from its fallback, for VeroXM's dashboard. */
8
+ shown?: Record<string, unknown>;
9
+ }
@@ -0,0 +1,20 @@
1
+ import { cacheLife, cacheTag } from 'next/cache';
2
+ import { fetchPublishedSlot, reportSlotNow } from '../slots-core.js';
3
+ // The published-content read for apps with Next.js Cache Components
4
+ // (`cacheComponents: true`). There, a fetch outside a cache scope makes a
5
+ // route wait for it on every request; this caches each slot's published
6
+ // content in Next's cache instead, so it becomes part of the static shell.
7
+ // Tagged "veroxm-slots" (and per slot), so publishing from the on-page
8
+ // editor -- or your own revalidateTag("veroxm-slots", "max") -- refreshes it.
9
+ // Only loaded when Cache Components is on (see slot.tsx).
10
+ //
11
+ // The slot's definition is reported here too (once per process): a
12
+ // prerender rejects requests that outlive it, so reporting can't be left
13
+ // for later the way the uncached path does.
14
+ export async function cachedPublishedSlot(name, locale, def) {
15
+ 'use cache';
16
+ cacheTag('veroxm-slots', `veroxm-slot:${name}`);
17
+ cacheLife({ stale: 30, revalidate: 30, expire: 86400 });
18
+ const [slot] = await Promise.all([fetchPublishedSlot(name, locale), def ? reportSlotNow(name, def.fields, def.label, def.path, def.shown ? { values: def.shown, locale } : undefined) : null]);
19
+ return slot;
20
+ }
@@ -0,0 +1,21 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface EdgeSlotProps {
3
+ name: string;
4
+ experienceId: number;
5
+ locale?: string;
6
+ /** The published version (the control). */
7
+ shown: ReactNode;
8
+ variants: Array<{
9
+ variantId: number;
10
+ node: ReactNode;
11
+ }>;
12
+ }
13
+ export declare const EDGE_ATTRS: {
14
+ readonly slot: "data-veroxm-edge-slot";
15
+ readonly test: "data-veroxm-test";
16
+ readonly shown: "data-veroxm-shown";
17
+ readonly variant: "data-veroxm-variant";
18
+ readonly end: "data-veroxm-end";
19
+ readonly chosen: "data-veroxm-edge";
20
+ };
21
+ export declare function EdgeSlot({ name, experienceId, locale, shown, variants }: EdgeSlotProps): import("react").JSX.Element;
@@ -0,0 +1,29 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from 'react';
4
+ export const EDGE_ATTRS = {
5
+ slot: 'data-veroxm-edge-slot',
6
+ test: 'data-veroxm-test',
7
+ shown: 'data-veroxm-shown',
8
+ variant: 'data-veroxm-variant',
9
+ end: 'data-veroxm-end',
10
+ chosen: 'data-veroxm-edge',
11
+ };
12
+ const onServer = typeof window === 'undefined';
13
+ /** The variant the edge worker put in this slot, read from the page (null = published). */
14
+ function edgeChoice(name, experienceId) {
15
+ if (onServer)
16
+ return null;
17
+ const el = document.querySelector(`[${EDGE_ATTRS.slot}="${cssEscape(name)}"][${EDGE_ATTRS.test}="${experienceId}"]`);
18
+ const raw = el?.getAttribute(EDGE_ATTRS.chosen);
19
+ return raw && /^\d+$/.test(raw) ? Number(raw) : null;
20
+ }
21
+ export function EdgeSlot({ name, experienceId, locale, shown, variants }) {
22
+ // Read once, while hydrating: what the visitor already sees.
23
+ const [chosen] = useState(() => edgeChoice(name, experienceId));
24
+ const picked = chosen === null ? undefined : variants.find((v) => v.variantId === chosen);
25
+ return (_jsxs("div", { [EDGE_ATTRS.slot]: name, [EDGE_ATTRS.test]: String(experienceId), 'data-veroxm-locale': locale ?? '', ...(picked ? { [EDGE_ATTRS.chosen]: String(picked.variantId) } : {}), style: { display: 'contents' }, suppressHydrationWarning: true, children: [_jsx("div", { [EDGE_ATTRS.shown]: '1', style: { display: 'contents' }, children: picked ? picked.node : shown }), variants.map((v) => (_jsx("template", { [EDGE_ATTRS.variant]: String(v.variantId), children: onServer ? v.node : null }, v.variantId))), _jsx("template", { [EDGE_ATTRS.end]: '1' })] }));
26
+ }
27
+ function cssEscape(s) {
28
+ return typeof CSS !== 'undefined' && CSS.escape ? CSS.escape(s) : s.replace(/["\\]/g, '\\$&');
29
+ }
@@ -0,0 +1,7 @@
1
+ import type { ReactNode } from 'react';
2
+ /**
3
+ * The on-page editor for Next.js: after each save the server components
4
+ * re-render with the draft (router.refresh()). <VeroxmSlot> from
5
+ * '@veroxm/react-sdk/next' mounts it in draft mode; you don't need to.
6
+ */
7
+ export declare function VeroxmEditor(): ReactNode;
@@ -0,0 +1,13 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useRouter } from 'next/navigation';
4
+ import { VeroxmEditorOverlay } from '../editor/overlay.js';
5
+ /**
6
+ * The on-page editor for Next.js: after each save the server components
7
+ * re-render with the draft (router.refresh()). <VeroxmSlot> from
8
+ * '@veroxm/react-sdk/next' mounts it in draft mode; you don't need to.
9
+ */
10
+ export function VeroxmEditor() {
11
+ const router = useRouter();
12
+ return _jsx(VeroxmEditorOverlay, { onChange: () => router.refresh() });
13
+ }
@@ -0,0 +1,17 @@
1
+ export { VeroxmSlot } from './slot.js';
2
+ export { VeroxmEditor } from './editor.js';
3
+ export { field, configureSlots, loadSlot, mergeSlotValues } from '../slots-core.js';
4
+ export type { VeroxmSlotProps, SlotFieldDef, SlotFieldDefs, SlotValues, SlotInfo, SlotTest, SlotMedia, SlotLink, SlotMenuItem, SlotVideo, SlotSlide, SlotMap, SlotPlace, SlotChart, SlotsConfig, LoadSlotOptions, SlotPerson } from '../slots-core.js';
5
+ export { NavMenu } from '../site/nav-menu.js';
6
+ export { SiteHeader, SiteFooter, headerFields, footerFields } from '../site/site-parts.js';
7
+ export { VeroxmSiteStyles } from '../site/styles.js';
8
+ export { VideoEmbed } from '../site/video-embed.js';
9
+ export { Slider } from '../site/slider.js';
10
+ export { MapEmbed } from '../site/map-embed.js';
11
+ export { Chart } from '../site/chart-view.js';
12
+ export { chartFromRows } from '../site/chart.js';
13
+ export { parseVideoUrl } from '../site/video.js';
14
+ export type { NavMenuProps } from '../site/nav-menu.js';
15
+ export type { SiteHeaderProps, SiteFooterProps } from '../site/site-parts.js';
16
+ export { VeroxmStructuredData, loadStructuredData } from '../structured-data.js';
17
+ export type { StructuredDataOptions } from '../structured-data.js';
@@ -0,0 +1,21 @@
1
+ // @veroxm/react-sdk/next -- visual slots for Next.js App Router, with
2
+ // VeroXM's on-page editor in draft mode. Use this <VeroxmSlot> instead of
3
+ // the one from '@veroxm/react-sdk', and add the route:
4
+ //
5
+ // // app/api/veroxm/[...veroxm]/route.ts
6
+ // export { GET, PUT, POST } from '@veroxm/react-sdk/next/route';
7
+ export { VeroxmSlot } from './slot.js';
8
+ export { VeroxmEditor } from './editor.js';
9
+ export { field, configureSlots, loadSlot, mergeSlotValues } from '../slots-core.js';
10
+ // Site parts (also in '@veroxm/react-sdk'), here so a Next.js site imports from one place.
11
+ export { NavMenu } from '../site/nav-menu.js';
12
+ export { SiteHeader, SiteFooter, headerFields, footerFields } from '../site/site-parts.js';
13
+ export { VeroxmSiteStyles } from '../site/styles.js';
14
+ export { VideoEmbed } from '../site/video-embed.js';
15
+ export { Slider } from '../site/slider.js';
16
+ export { MapEmbed } from '../site/map-embed.js';
17
+ export { Chart } from '../site/chart-view.js';
18
+ export { chartFromRows } from '../site/chart.js';
19
+ export { parseVideoUrl } from '../site/video.js';
20
+ // Structured data (schema.org JSON-LD) for a page, from the AI agents page in VeroXM.
21
+ export { VeroxmStructuredData, loadStructuredData } from '../structured-data.js';
@@ -0,0 +1,2 @@
1
+ export declare const GET: (request: Request) => Promise<Response>;
2
+ export declare const GET_FULL: (request: Request) => Promise<Response>;
@@ -0,0 +1,44 @@
1
+ import { resolveSlotsConfig } from '../slots-core.js';
2
+ // Your site's /llms.txt and /llms-full.txt, written by VeroXM from your
3
+ // published collections (Agents page > llms.txt in the dashboard).
4
+ //
5
+ // // app/llms.txt/route.ts
6
+ // export { GET } from '@veroxm/react-sdk/next/llms';
7
+ // // app/llms-full.txt/route.ts
8
+ // export { GET_FULL as GET } from '@veroxm/react-sdk/next/llms';
9
+ //
10
+ // Uses the same VEROXM_API_BASE / VEROXM_PROJECT_ID / VEROXM_API_KEY as
11
+ // slots. Cached for five minutes. When an AI agent fetches it, the visit
12
+ // is reported to the Agents page too.
13
+ /** AI crawler and assistant user agents (VeroXM recognises which one). */
14
+ const AI_AGENT_UA = /GPTBot|OAI-SearchBot|ChatGPT-User|ClaudeBot|anthropic-ai|Claude-SearchBot|Claude-User|Claude-Web|PerplexityBot|Perplexity-User|Google-CloudVertexBot|meta-externalagent|meta-externalfetcher|Amazonbot|Applebot|DuckAssistBot|MistralAI-User|cohere-ai|cohere-training-data-crawler|Bytespider|CCBot|AI2Bot|YouBot/i;
15
+ async function serve(request, file) {
16
+ const cfg = resolveSlotsConfig();
17
+ if (!cfg.ready || !cfg.fetch)
18
+ return new Response('Not found', { status: 404 });
19
+ const base = `${cfg.baseUrl}/public/v2/projects/${encodeURIComponent(cfg.projectId)}`;
20
+ const headers = { Authorization: `Bearer ${cfg.apiKey}` };
21
+ let res;
22
+ try {
23
+ res = await cfg.fetch(`${base}/${file}`, { headers, next: { revalidate: 300 } });
24
+ }
25
+ catch {
26
+ return new Response('Unavailable', { status: 503 });
27
+ }
28
+ const ua = request.headers.get('user-agent') ?? '';
29
+ if (AI_AGENT_UA.test(ua)) {
30
+ // Fire and forget: a visit that can't be reported mustn't slow the answer.
31
+ void cfg
32
+ .fetch(`${base}/agents/hits`, {
33
+ method: 'POST',
34
+ headers: { ...headers, 'Content-Type': 'application/json' },
35
+ body: JSON.stringify({ source: 'server', hits: [{ ua: ua.slice(0, 500), path: `/${file}`, status: res.status === 200 ? 200 : 404 }] }),
36
+ })
37
+ .catch(() => undefined);
38
+ }
39
+ if (res.status !== 200)
40
+ return new Response('Not found', { status: 404 });
41
+ return new Response(await res.text(), { status: 200, headers: { 'Content-Type': 'text/plain; charset=utf-8', 'Cache-Control': 'public, max-age=300' } });
42
+ }
43
+ export const GET = (request) => serve(request, 'llms.txt');
44
+ export const GET_FULL = (request) => serve(request, 'llms-full.txt');
@@ -0,0 +1,12 @@
1
+ type Ctx = {
2
+ params?: Promise<{
3
+ veroxm?: string[];
4
+ }> | {
5
+ veroxm?: string[];
6
+ };
7
+ };
8
+ declare function route(request: Request, ctx?: Ctx): Promise<Response>;
9
+ export declare const GET: typeof route;
10
+ export declare const PUT: typeof route;
11
+ export declare const POST: typeof route;
12
+ export {};
@@ -0,0 +1,16 @@
1
+ import { draftMode } from 'next/headers';
2
+ import { revalidateTag } from 'next/cache';
3
+ import { createEditorHandler } from '../editor/handler.js';
4
+ const handle = createEditorHandler({
5
+ isEditing: async () => (await draftMode()).isEnabled,
6
+ enter: async () => (await draftMode()).enable(),
7
+ exit: async () => (await draftMode()).disable(),
8
+ published: () => revalidateTag('veroxm-slots', { expire: 0 }),
9
+ });
10
+ async function route(request, ctx) {
11
+ const params = ctx?.params ? await ctx.params : undefined;
12
+ return handle(request, params?.veroxm);
13
+ }
14
+ export const GET = route;
15
+ export const PUT = route;
16
+ export const POST = route;
@@ -0,0 +1,21 @@
1
+ import { type ReactNode } from 'react';
2
+ import { loadPublishedSlot, type SlotFieldDefs, type VeroxmSlotProps } from '../slots-core.js';
3
+ /**
4
+ * <VeroxmSlot> for Next.js App Router. Outside draft mode it shows the
5
+ * published content (cached) -- or, when the slot is under a live A/B test
6
+ * and the visitor has the tracker's visitor cookie, that visitor's variant.
7
+ * In draft mode -- after "Edit on page" in VeroXM -- it renders the slot's
8
+ * draft, marks it for the on-page editor, and mounts the editor overlay.
9
+ */
10
+ export declare function VeroxmSlot<F extends SlotFieldDefs>(props: VeroxmSlotProps<F>): Promise<ReactNode>;
11
+ /** Reads a slot's published content; `def` is passed when the loader also reports the definition. */
12
+ type Loader = (name: string, locale: string | undefined, def?: {
13
+ fields: SlotFieldDefs;
14
+ label?: string;
15
+ path?: string;
16
+ shown?: Record<string, unknown>;
17
+ }) => Promise<Loaded>;
18
+ /** Shared by this entry and '@veroxm/react-sdk/next/cache-components' (which passes a cached loader). */
19
+ export declare function slotWith<F extends SlotFieldDefs>(props: VeroxmSlotProps<F>, load: Loader, cached: boolean): Promise<ReactNode>;
20
+ type Loaded = Awaited<ReturnType<typeof loadPublishedSlot>>;
21
+ export {};