@ebitex/content-sdk 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.
- package/README.md +62 -0
- package/dist/content/cache.d.ts +26 -0
- package/dist/content/cache.d.ts.map +1 -0
- package/dist/content/cache.js +107 -0
- package/dist/content/cache.js.map +1 -0
- package/dist/content/client.d.ts +78 -0
- package/dist/content/client.d.ts.map +1 -0
- package/dist/content/client.js +150 -0
- package/dist/content/client.js.map +1 -0
- package/dist/content/locale.d.ts +18 -0
- package/dist/content/locale.d.ts.map +1 -0
- package/dist/content/locale.js +54 -0
- package/dist/content/locale.js.map +1 -0
- package/dist/content/overlay.d.ts +16 -0
- package/dist/content/overlay.d.ts.map +1 -0
- package/dist/content/overlay.js +20 -0
- package/dist/content/overlay.js.map +1 -0
- package/dist/content/site.d.ts +15 -0
- package/dist/content/site.d.ts.map +1 -0
- package/dist/content/site.js +26 -0
- package/dist/content/site.js.map +1 -0
- package/dist/content/strategy.d.ts +24 -0
- package/dist/content/strategy.d.ts.map +1 -0
- package/dist/content/strategy.js +15 -0
- package/dist/content/strategy.js.map +1 -0
- package/dist/delivery/client.d.ts +61 -0
- package/dist/delivery/client.d.ts.map +1 -0
- package/dist/delivery/client.js +88 -0
- package/dist/delivery/client.js.map +1 -0
- package/dist/delivery/query.d.ts +21 -0
- package/dist/delivery/query.d.ts.map +1 -0
- package/dist/delivery/query.js +49 -0
- package/dist/delivery/query.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +46 -0
- package/dist/errors.js.map +1 -0
- package/dist/guards.d.ts +42 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/guards.js +75 -0
- package/dist/guards.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/react/ContentProvider.d.ts +43 -0
- package/dist/react/ContentProvider.d.ts.map +1 -0
- package/dist/react/ContentProvider.js +36 -0
- package/dist/react/ContentProvider.js.map +1 -0
- package/dist/react/Experience.d.ts +54 -0
- package/dist/react/Experience.d.ts.map +1 -0
- package/dist/react/Experience.js +99 -0
- package/dist/react/Experience.js.map +1 -0
- package/dist/react/PresentationList.d.ts +14 -0
- package/dist/react/PresentationList.d.ts.map +1 -0
- package/dist/react/PresentationList.js +20 -0
- package/dist/react/PresentationList.js.map +1 -0
- package/dist/react/RenderPresentation.d.ts +20 -0
- package/dist/react/RenderPresentation.d.ts.map +1 -0
- package/dist/react/RenderPresentation.js +59 -0
- package/dist/react/RenderPresentation.js.map +1 -0
- package/dist/react/Resolve.d.ts +34 -0
- package/dist/react/Resolve.d.ts.map +1 -0
- package/dist/react/Resolve.js +79 -0
- package/dist/react/Resolve.js.map +1 -0
- package/dist/react/RichText.d.ts +19 -0
- package/dist/react/RichText.d.ts.map +1 -0
- package/dist/react/RichText.js +37 -0
- package/dist/react/RichText.js.map +1 -0
- package/dist/react/index.d.ts +15 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +15 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/panels.d.ts +47 -0
- package/dist/react/panels.d.ts.map +1 -0
- package/dist/react/panels.js +92 -0
- package/dist/react/panels.js.map +1 -0
- package/dist/react/registry.d.ts +58 -0
- package/dist/react/registry.d.ts.map +1 -0
- package/dist/react/registry.js +92 -0
- package/dist/react/registry.js.map +1 -0
- package/dist/types.d.ts +187 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentProvider.d.ts","sourceRoot":"","sources":["../../src/react/ContentProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAC9F,OAAO,KAAK,EAAE,aAAa,EAAE,MAA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C,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,GAAG,SAAS,CAEpH;AAED,8FAA8F;AAC9F,wBAAgB,kBAAkB,IAAI,eAAe,CAIpD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
3
|
+
import { ContentError, UnresolvedPresentation } from './panels.js';
|
|
4
|
+
import { RendererRegistry } from './registry.js';
|
|
5
|
+
const ContentContext = createContext(null);
|
|
6
|
+
/** The strategy a subtree was resolved under — set by `<Experience>` from its result, so `RenderPresentation` knows whether an unexpanded reference is a depth hole or something to fetch. */
|
|
7
|
+
const StrategyContext = createContext(null);
|
|
8
|
+
export function ContentProvider({ client, renderers, markdown, fallback, loading, errorFallback, children }) {
|
|
9
|
+
const registry = useMemo(() => new RendererRegistry(renderers), [renderers]);
|
|
10
|
+
const value = useMemo(() => ({
|
|
11
|
+
client,
|
|
12
|
+
registry,
|
|
13
|
+
Markdown: markdown,
|
|
14
|
+
Fallback: fallback ?? UnresolvedPresentation,
|
|
15
|
+
loading: loading ?? null,
|
|
16
|
+
ErrorFallback: errorFallback ?? ContentError,
|
|
17
|
+
}), [client, registry, markdown, fallback, loading, errorFallback]);
|
|
18
|
+
return _jsx(ContentContext.Provider, { value: value, children: children });
|
|
19
|
+
}
|
|
20
|
+
export function useContentContext() {
|
|
21
|
+
const value = useContext(ContentContext);
|
|
22
|
+
if (value === null) {
|
|
23
|
+
throw new Error('@ebitex/content-sdk/react: wrap your tree in <ContentProvider renderers={…}>.');
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
export function StrategyScope({ strategy, children }) {
|
|
28
|
+
return _jsx(StrategyContext.Provider, { value: strategy, children: children });
|
|
29
|
+
}
|
|
30
|
+
/** The effective strategy: the enclosing `<Experience>`'s, else the client's, else `full`. */
|
|
31
|
+
export function useResolveStrategy() {
|
|
32
|
+
const scoped = useContext(StrategyContext);
|
|
33
|
+
const { client } = useContentContext();
|
|
34
|
+
return scoped ?? client?.strategy ?? { strategy: 'full' };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=ContentProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentProvider.js","sourceRoot":"","sources":["../../src/react/ContentProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAsC,MAAM,OAAO,CAAA;AAG9F,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAA4D,MAAM,aAAa,CAAA;AAC5H,OAAO,EAAE,gBAAgB,EAAkB,MAAM,eAAe,CAAA;AAkChE,MAAM,cAAc,GAAG,aAAa,CAA6B,IAAI,CAAC,CAAA;AAEtE,8LAA8L;AAC9L,MAAM,eAAe,GAAG,aAAa,CAAyB,IAAI,CAAC,CAAA;AAEnE,MAAM,UAAU,eAAe,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAwB;IAC/H,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,gBAAgB,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IAC5E,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC;QACL,MAAM;QACN,QAAQ;QACR,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,QAAQ,IAAI,sBAAsB;QAC5C,OAAO,EAAE,OAAO,IAAI,IAAI;QACxB,aAAa,EAAE,aAAa,IAAI,YAAY;KAC7C,CAAC,EACF,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,CAAC,CAC/D,CAAA;IAED,OAAO,KAAC,cAAc,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAA2B,CAAA;AACpF,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,MAAM,KAAK,GAAG,UAAU,CAAC,cAAc,CAAC,CAAA;IACxC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,+EAA+E,CAAC,CAAA;IAClG,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAuD;IACvG,OAAO,KAAC,eAAe,CAAC,QAAQ,IAAC,KAAK,EAAE,QAAQ,YAAG,QAAQ,GAA4B,CAAA;AACzF,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,kBAAkB;IAChC,MAAM,MAAM,GAAG,UAAU,CAAC,eAAe,CAAC,CAAA;IAC1C,MAAM,EAAE,MAAM,EAAE,GAAG,iBAAiB,EAAE,CAAA;IACtC,OAAO,MAAM,IAAI,MAAM,EAAE,QAAQ,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;AAC3D,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type ComponentType, type ReactNode } from 'react';
|
|
2
|
+
import type { ExperienceResult } from '../content/client.js';
|
|
3
|
+
import type { ContextBag } from '../types.js';
|
|
4
|
+
import type { ContentErrorProps } from './panels.js';
|
|
5
|
+
export interface UseExperienceInput {
|
|
6
|
+
/** The current location's pathname — from your router (`useLocation().pathname`), never hard-coded. */
|
|
7
|
+
path: string;
|
|
8
|
+
context?: ContextBag;
|
|
9
|
+
locale?: string;
|
|
10
|
+
site?: string;
|
|
11
|
+
/** Keep the previous result visible while the next loads (default `true`), so a navigation doesn't flash to a loading state. */
|
|
12
|
+
keepPrevious?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export type ExperienceStatus = 'loading' | 'ready' | 'redirect' | 'notFound' | 'error';
|
|
15
|
+
export interface ExperienceState {
|
|
16
|
+
status: ExperienceStatus;
|
|
17
|
+
/** The latest result — under `keepPrevious`, still the previous one while `status` is `loading`. */
|
|
18
|
+
result: ExperienceResult | undefined;
|
|
19
|
+
error: unknown;
|
|
20
|
+
/** Re-resolves the current inputs, bypassing the cache. */
|
|
21
|
+
refresh: () => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Resolves the Experience at `path` and re-resolves when the path, locale, site, or context
|
|
25
|
+
* changes (the context compared by its serialized form); a superseded resolve is aborted and
|
|
26
|
+
* never updates state.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useExperience(input: UseExperienceInput): ExperienceState;
|
|
29
|
+
interface ExperienceCommonProps {
|
|
30
|
+
/** Rendered for a `notFound` result. */
|
|
31
|
+
notFound?: ReactNode;
|
|
32
|
+
loading?: ReactNode;
|
|
33
|
+
/** Replaces the provider's error panel for this page. */
|
|
34
|
+
error?: ComponentType<ContentErrorProps>;
|
|
35
|
+
}
|
|
36
|
+
export interface ExperienceByPathProps extends ExperienceCommonProps, UseExperienceInput {
|
|
37
|
+
result?: undefined;
|
|
38
|
+
/** Called for a redirect result; nothing is rendered until the consumer navigates — the SDK never follows redirects itself. */
|
|
39
|
+
onRedirect?: (targetPath: string, targetNodeId: string | null) => void;
|
|
40
|
+
}
|
|
41
|
+
/** The controlled form: render a result the consumer already holds — no hook, no client, no request. */
|
|
42
|
+
export interface ExperienceByResultProps extends ExperienceCommonProps {
|
|
43
|
+
result: ExperienceResult;
|
|
44
|
+
path?: undefined;
|
|
45
|
+
onRedirect?: (targetPath: string, targetNodeId: string | null) => void;
|
|
46
|
+
}
|
|
47
|
+
export type ExperienceProps = ExperienceByPathProps | ExperienceByResultProps;
|
|
48
|
+
/**
|
|
49
|
+
* Renders whatever lives at a path. Hook-driven (`<Experience path={pathname} />`) or controlled
|
|
50
|
+
* (`<Experience result={resolved} />` — SSR, or a live-preview bridge injecting a document).
|
|
51
|
+
*/
|
|
52
|
+
export declare function Experience(props: ExperienceProps): ReactNode;
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=Experience.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Experience.d.ts","sourceRoot":"","sources":["../../src/react/Experience.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAqD,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAC7G,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAG5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAGpD,MAAM,WAAW,kBAAkB;IACjC,uGAAuG;IACvG,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,UAAU,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,gIAAgI;IAChI,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;AAEtF,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,gBAAgB,CAAA;IACxB,oGAAoG;IACpG,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAAA;IACpC,KAAK,EAAE,OAAO,CAAA;IACd,2DAA2D;IAC3D,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,eAAe,CA2CxE;AAaD,UAAU,qBAAqB;IAC7B,wCAAwC;IACxC,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,yDAAyD;IACzD,KAAK,CAAC,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAA;CACzC;AAED,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB,EAAE,kBAAkB;IACtF,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,+HAA+H;IAC/H,UAAU,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;CACvE;AAED,wGAAwG;AACxG,MAAM,WAAW,uBAAwB,SAAQ,qBAAqB;IACpE,MAAM,EAAE,gBAAgB,CAAA;IACxB,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,UAAU,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;CACvE;AAED,MAAM,MAAM,eAAe,GAAG,qBAAqB,GAAG,uBAAuB,CAAA;AAE7E;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,CAiB5D"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { serializeContext } from '../delivery/query.js';
|
|
4
|
+
import { isAbortError } from '../errors.js';
|
|
5
|
+
import { StrategyScope, useContentContext } from './ContentProvider.js';
|
|
6
|
+
import { RenderPresentation } from './RenderPresentation.js';
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the Experience at `path` and re-resolves when the path, locale, site, or context
|
|
9
|
+
* changes (the context compared by its serialized form); a superseded resolve is aborted and
|
|
10
|
+
* never updates state.
|
|
11
|
+
*/
|
|
12
|
+
export function useExperience(input) {
|
|
13
|
+
const { client } = useContentContext();
|
|
14
|
+
if (client === undefined) {
|
|
15
|
+
throw new Error('@ebitex/content-sdk/react: useExperience needs a client — pass one to <ContentProvider>, or render a pre-resolved result with <Experience result>.');
|
|
16
|
+
}
|
|
17
|
+
const { path, locale, site, keepPrevious = true } = input;
|
|
18
|
+
const contextKey = input.context === undefined ? '' : serializeContext(input.context);
|
|
19
|
+
const context = useMemo(() => input.context, [contextKey]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
20
|
+
const [tick, setTick] = useState(0);
|
|
21
|
+
const freshRef = useRef(false);
|
|
22
|
+
const [state, setState] = useState({
|
|
23
|
+
status: 'loading',
|
|
24
|
+
result: undefined,
|
|
25
|
+
error: undefined,
|
|
26
|
+
});
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const controller = new AbortController();
|
|
29
|
+
const fresh = freshRef.current;
|
|
30
|
+
freshRef.current = false;
|
|
31
|
+
setState((previous) => ({ status: 'loading', result: keepPrevious ? previous.result : undefined, error: undefined }));
|
|
32
|
+
client.resolveLocation({ pathname: path }, { context, locale, site, signal: controller.signal, fresh }).then((result) => {
|
|
33
|
+
if (controller.signal.aborted)
|
|
34
|
+
return;
|
|
35
|
+
setState({ status: statusOf(result), result, error: undefined });
|
|
36
|
+
}, (error) => {
|
|
37
|
+
if (controller.signal.aborted || isAbortError(error))
|
|
38
|
+
return;
|
|
39
|
+
setState((previous) => ({ status: 'error', result: keepPrevious ? previous.result : undefined, error }));
|
|
40
|
+
});
|
|
41
|
+
return () => controller.abort();
|
|
42
|
+
}, [client, path, locale, site, context, keepPrevious, tick]);
|
|
43
|
+
const refresh = useCallback(() => {
|
|
44
|
+
freshRef.current = true;
|
|
45
|
+
setTick((t) => t + 1);
|
|
46
|
+
}, []);
|
|
47
|
+
return { ...state, refresh };
|
|
48
|
+
}
|
|
49
|
+
function statusOf(result) {
|
|
50
|
+
switch (result.kind) {
|
|
51
|
+
case 'presentation':
|
|
52
|
+
return 'ready';
|
|
53
|
+
case 'redirect':
|
|
54
|
+
return 'redirect';
|
|
55
|
+
case 'notFound':
|
|
56
|
+
return 'notFound';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Renders whatever lives at a path. Hook-driven (`<Experience path={pathname} />`) or controlled
|
|
61
|
+
* (`<Experience result={resolved} />` — SSR, or a live-preview bridge injecting a document).
|
|
62
|
+
*/
|
|
63
|
+
export function Experience(props) {
|
|
64
|
+
if (props.result !== undefined) {
|
|
65
|
+
const { result, notFound, loading, error, onRedirect } = props;
|
|
66
|
+
return (_jsx(ExperienceView, { result: result, status: statusOf(result), failure: undefined, notFound: notFound, loading: loading, errorComponent: error, onRedirect: onRedirect }));
|
|
67
|
+
}
|
|
68
|
+
return _jsx(ExperienceByPath, { ...props });
|
|
69
|
+
}
|
|
70
|
+
function ExperienceByPath(props) {
|
|
71
|
+
const { path, context, locale, site, keepPrevious, notFound, loading, error, onRedirect } = props;
|
|
72
|
+
const state = useExperience({ path, context, locale, site, keepPrevious });
|
|
73
|
+
return (_jsx(ExperienceView, { result: state.result, status: state.status, failure: state.error, path: path, notFound: notFound, loading: loading, errorComponent: error, onRedirect: onRedirect }));
|
|
74
|
+
}
|
|
75
|
+
function ExperienceView({ result, status, failure, path, notFound = null, loading, errorComponent, onRedirect }) {
|
|
76
|
+
const { loading: defaultLoading, ErrorFallback } = useContentContext();
|
|
77
|
+
const redirect = result?.kind === 'redirect' ? result : null;
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (redirect !== null && onRedirect) {
|
|
80
|
+
onRedirect(redirect.targetPath, redirect.targetNodeId);
|
|
81
|
+
}
|
|
82
|
+
}, [redirect, onRedirect]);
|
|
83
|
+
if (status === 'error') {
|
|
84
|
+
const Panel = errorComponent ?? ErrorFallback;
|
|
85
|
+
return _jsx(Panel, { error: failure, path: path });
|
|
86
|
+
}
|
|
87
|
+
if (result === undefined) {
|
|
88
|
+
return loading === undefined ? defaultLoading : loading;
|
|
89
|
+
}
|
|
90
|
+
switch (result.kind) {
|
|
91
|
+
case 'redirect':
|
|
92
|
+
return null;
|
|
93
|
+
case 'notFound':
|
|
94
|
+
return notFound;
|
|
95
|
+
case 'presentation':
|
|
96
|
+
return (_jsx(StrategyScope, { strategy: result.strategy, children: _jsx(RenderPresentation, { ...result.presentation }) }));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=Experience.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Experience.js","sourceRoot":"","sources":["../../src/react/Experience.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAsC,MAAM,OAAO,CAAA;AAE7G,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAuB5D;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,MAAM,EAAE,MAAM,EAAE,GAAG,iBAAiB,EAAE,CAAA;IACtC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,oJAAoJ,CAAC,CAAA;IACvK,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,EAAE,GAAG,KAAK,CAAA;IACzD,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACrF,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA,CAAC,kDAAkD;IAC7G,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IACnC,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IAC9B,MAAM,CAAC,KAA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IAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAI,CAAA;IAC9C,CAAC;IAED,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAA;IACzD,CAAC;IAED,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,UAAU;YACb,OAAO,IAAI,CAAA;QACb,KAAK,UAAU;YACb,OAAO,QAAQ,CAAA;QACjB,KAAK,cAAc;YACjB,OAAO,CACL,KAAC,aAAa,IAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,YACtC,KAAC,kBAAkB,OAAK,MAAM,CAAC,YAAY,GAAI,GACjC,CACjB,CAAA;IACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { PresentationEnvelope } from '../types.js';
|
|
3
|
+
export interface PresentationListProps {
|
|
4
|
+
/** An `isEnumerable` Presentation field's value, or a relayed list. `null` positions are skipped (spec #292 nulls a violator rather than dropping it). */
|
|
5
|
+
items: ReadonlyArray<PresentationEnvelope | null | undefined> | null | undefined;
|
|
6
|
+
/** Rendered when there is nothing to render. */
|
|
7
|
+
empty?: ReactNode;
|
|
8
|
+
/** Wraps each rendered item — e.g. `(node, envelope, i) => <li key={i}>{node}</li>`. The key is applied to the wrapper's parent Fragment either way. */
|
|
9
|
+
wrap?: (rendered: ReactNode, envelope: PresentationEnvelope, index: number) => ReactNode;
|
|
10
|
+
}
|
|
11
|
+
/** Maps a list of envelopes to `<RenderPresentation>` with a stable key per item. */
|
|
12
|
+
export declare function PresentationList({ items, empty, wrap }: PresentationListProps): ReactNode;
|
|
13
|
+
export declare function keyFor(envelope: PresentationEnvelope, index: number): string;
|
|
14
|
+
//# sourceMappingURL=PresentationList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PresentationList.d.ts","sourceRoot":"","sources":["../../src/react/PresentationList.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAEhD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAGvD,MAAM,WAAW,qBAAqB;IACpC,0JAA0J;IAC1J,KAAK,EAAE,aAAa,CAAC,oBAAoB,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,CAAA;IAChF,gDAAgD;IAChD,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,wJAAwJ;IACxJ,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAA;CACzF;AAED,qFAAqF;AACrF,wBAAgB,gBAAgB,CAAC,EAAE,KAAK,EAAE,KAAY,EAAE,IAAI,EAAE,EAAE,qBAAqB,GAAG,SAAS,CAUhG;AAED,wBAAgB,MAAM,CAAC,QAAQ,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG5E"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment } from 'react';
|
|
3
|
+
import { isPresentationEnvelope } from '../guards.js';
|
|
4
|
+
import { RenderPresentation } from './RenderPresentation.js';
|
|
5
|
+
/** Maps a list of envelopes to `<RenderPresentation>` with a stable key per item. */
|
|
6
|
+
export function PresentationList({ items, empty = null, wrap }) {
|
|
7
|
+
const envelopes = (items ?? []).filter(isPresentationEnvelope);
|
|
8
|
+
if (envelopes.length === 0) {
|
|
9
|
+
return empty;
|
|
10
|
+
}
|
|
11
|
+
return envelopes.map((envelope, index) => {
|
|
12
|
+
const rendered = _jsx(RenderPresentation, { ...envelope });
|
|
13
|
+
return _jsx(Fragment, { children: wrap ? wrap(rendered, envelope, index) : rendered }, keyFor(envelope, index));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export function keyFor(envelope, index) {
|
|
17
|
+
const { component } = envelope;
|
|
18
|
+
return component.provider !== undefined && component.key !== undefined ? `${component.provider}:${component.key}:${index}` : `inline:${index}`;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=PresentationList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PresentationList.js","sourceRoot":"","sources":["../../src/react/PresentationList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAErD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAW5D,qFAAqF;AACrF,MAAM,UAAU,gBAAgB,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,IAAI,EAAyB;IACnF,MAAM,SAAS,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAA;IAC9D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;QACvC,MAAM,QAAQ,GAAG,KAAC,kBAAkB,OAAK,QAAQ,GAAI,CAAA;QACrD,OAAO,KAAC,QAAQ,cAAgC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,IAA3E,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAgE,CAAA;IAC/G,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,QAA8B,EAAE,KAAa;IAClE,MAAM,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAA;IAC9B,OAAO,SAAS,CAAC,QAAQ,KAAK,SAAS,IAAI,SAAS,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,QAAQ,IAAI,SAAS,CAAC,GAAG,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,EAAE,CAAA;AAChJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ComponentType, type ReactNode } from 'react';
|
|
2
|
+
import type { ComponentValue, ContentDocument, EntityDescriptor } from '../types.js';
|
|
3
|
+
import { type UnresolvedPresentationProps } from './panels.js';
|
|
4
|
+
export interface RenderPresentationProps<TContent = ContentDocument, TSettings = ContentDocument> {
|
|
5
|
+
template: EntityDescriptor;
|
|
6
|
+
settings: TSettings;
|
|
7
|
+
component: ComponentValue<TContent>;
|
|
8
|
+
/** Per-call-site replacement for the provider's fallback panel. */
|
|
9
|
+
fallback?: ComponentType<UnresolvedPresentationProps>;
|
|
10
|
+
loading?: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The dispatch point (spec 359 Business Logic §5): looks the renderer up by
|
|
14
|
+
* `template.externalId`, gates on the bound Component's resolution, and renders
|
|
15
|
+
* `<Renderer template settings component />` with `component.content` guaranteed present. Every
|
|
16
|
+
* case where it cannot is rendered through the fallback with a specific reason. Spread an
|
|
17
|
+
* envelope straight in: `<RenderPresentation {...envelope} />`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function RenderPresentation<TContent = ContentDocument, TSettings = ContentDocument>(props: RenderPresentationProps<TContent, TSettings>): ReactNode;
|
|
20
|
+
//# sourceMappingURL=RenderPresentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderPresentation.d.ts","sourceRoot":"","sources":["../../src/react/RenderPresentation.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEpF,OAAO,EAAY,KAAK,2BAA2B,EAAE,MAAM,aAAa,CAAA;AAIxE,MAAM,WAAW,uBAAuB,CAAC,QAAQ,GAAG,eAAe,EAAE,SAAS,GAAG,eAAe;IAC9F,QAAQ,EAAE,gBAAgB,CAAA;IAC1B,QAAQ,EAAE,SAAS,CAAA;IACnB,SAAS,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAA;IACnC,mEAAmE;IACnE,QAAQ,CAAC,EAAE,aAAa,CAAC,2BAA2B,CAAC,CAAA;IACrD,OAAO,CAAC,EAAE,SAAS,CAAA;CACpB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,GAAG,eAAe,EAAE,SAAS,GAAG,eAAe,EACxF,KAAK,EAAE,uBAAuB,CAAC,QAAQ,EAAE,SAAS,CAAC,GAClD,SAAS,CA4BX"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { useContentContext } from './ContentProvider.js';
|
|
4
|
+
import { REMEDIES } from './panels.js';
|
|
5
|
+
import { useResolvedComponent } from './Resolve.js';
|
|
6
|
+
/**
|
|
7
|
+
* The dispatch point (spec 359 Business Logic §5): looks the renderer up by
|
|
8
|
+
* `template.externalId`, gates on the bound Component's resolution, and renders
|
|
9
|
+
* `<Renderer template settings component />` with `component.content` guaranteed present. Every
|
|
10
|
+
* case where it cannot is rendered through the fallback with a specific reason. Spread an
|
|
11
|
+
* envelope straight in: `<RenderPresentation {...envelope} />`.
|
|
12
|
+
*/
|
|
13
|
+
export function RenderPresentation(props) {
|
|
14
|
+
const { template, settings, component } = props;
|
|
15
|
+
const { registry, Fallback: DefaultFallback, loading: defaultLoading } = useContentContext();
|
|
16
|
+
const Fallback = props.fallback ?? DefaultFallback;
|
|
17
|
+
const loading = props.loading === undefined ? defaultLoading : props.loading;
|
|
18
|
+
const rendererState = useRendererState(registry.get(template.externalId));
|
|
19
|
+
const resolution = useResolvedComponent(component);
|
|
20
|
+
const envelope = { template, settings, component };
|
|
21
|
+
if (rendererState.status === 'missing') {
|
|
22
|
+
return _jsx(Fallback, { reason: "not_registered", remedy: REMEDIES.not_registered(template), template: template, envelope: envelope });
|
|
23
|
+
}
|
|
24
|
+
if (rendererState.status === 'failed') {
|
|
25
|
+
return _jsx(Fallback, { reason: "load_failed", remedy: REMEDIES.load_failed(template), template: template, envelope: envelope, error: rendererState.error });
|
|
26
|
+
}
|
|
27
|
+
if (resolution.status === 'fallback') {
|
|
28
|
+
return _jsx(Fallback, { reason: resolution.reason, remedy: REMEDIES[resolution.reason](template), template: template, envelope: envelope, error: resolution.error });
|
|
29
|
+
}
|
|
30
|
+
if (rendererState.status === 'loading' || resolution.status === 'loading') {
|
|
31
|
+
return loading;
|
|
32
|
+
}
|
|
33
|
+
const Renderer = rendererState.renderer;
|
|
34
|
+
return _jsx(Renderer, { template: template, settings: settings, component: resolution.value });
|
|
35
|
+
}
|
|
36
|
+
/** Subscribes to a lazy renderer's load; a `ready`/`missing`/`failed` state is returned synchronously. */
|
|
37
|
+
function useRendererState(initial) {
|
|
38
|
+
const [settled, setSettled] = useState(null);
|
|
39
|
+
const pending = initial.status === 'loading' ? initial.promise : null;
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (pending === null) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let active = true;
|
|
45
|
+
pending.then((state) => {
|
|
46
|
+
if (active) {
|
|
47
|
+
setSettled({ promise: pending, state });
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return () => {
|
|
51
|
+
active = false;
|
|
52
|
+
};
|
|
53
|
+
}, [pending]);
|
|
54
|
+
if (pending === null) {
|
|
55
|
+
return initial;
|
|
56
|
+
}
|
|
57
|
+
return settled !== null && settled.promise === pending ? settled.state : initial;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AAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,OAAM;QACR,CAAC;QAED,IAAI,MAAM,GAAG,IAAI,CAAA;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;YACrB,IAAI,MAAM,EAAE,CAAC;gBACX,UAAU,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAA;YACzC,CAAC;QACH,CAAC,CAAC,CAAA;QACF,OAAO,GAAG,EAAE;YACV,MAAM,GAAG,KAAK,CAAA;QAChB,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAEb,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAA;AAClF,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { ComponentValue, ContentDocument, RenderableComponentValue } from '../types.js';
|
|
3
|
+
import { type FallbackReason, type UnresolvedPresentationProps } from './panels.js';
|
|
4
|
+
export type ResolutionState<TContent = ContentDocument> = {
|
|
5
|
+
status: 'ready';
|
|
6
|
+
value: RenderableComponentValue<TContent>;
|
|
7
|
+
} | {
|
|
8
|
+
status: 'loading';
|
|
9
|
+
} | {
|
|
10
|
+
status: 'fallback';
|
|
11
|
+
reason: FallbackReason;
|
|
12
|
+
error?: unknown;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The resolution gate (spec 359 Business Logic §5 step 2): decides, from the value alone plus the
|
|
16
|
+
* strategy in force, whether a component value can be rendered right now, must be fetched (the
|
|
17
|
+
* normalized strategy), or falls back — and fetches it when that's the answer.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useResolvedComponent<TContent = ContentDocument>(value: ComponentValue<TContent> | null | undefined): ResolutionState<TContent>;
|
|
20
|
+
/** Pure classification; `canFetch` is "the normalized strategy is in force and a client exists". */
|
|
21
|
+
export declare function classify<TContent>(value: ComponentValue<TContent> | null | undefined, canFetch: boolean): ResolutionState<TContent>;
|
|
22
|
+
export interface ResolveProps<TContent = ContentDocument> {
|
|
23
|
+
value: ComponentValue<TContent> | null | undefined;
|
|
24
|
+
children: (content: TContent, value: RenderableComponentValue<TContent>) => ReactNode;
|
|
25
|
+
/** Rendered instead of the provider's fallback panel; receives the same props. */
|
|
26
|
+
fallback?: (props: UnresolvedPresentationProps) => ReactNode;
|
|
27
|
+
loading?: ReactNode;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Render-prop form of `useResolvedComponent` for a Reference field inside a renderer:
|
|
31
|
+
* `<Resolve value={content.author}>{(author) => <Byline {...author} />}</Resolve>`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function Resolve<TContent = ContentDocument>({ value, children, fallback, loading }: ResolveProps<TContent>): ReactNode;
|
|
34
|
+
//# sourceMappingURL=Resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Resolve.d.ts","sourceRoot":"","sources":["../../src/react/Resolve.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAE5F,OAAO,EAAY,KAAK,cAAc,EAAE,KAAK,2BAA2B,EAAE,MAAM,aAAa,CAAA;AAE7F,MAAM,MAAM,eAAe,CAAC,QAAQ,GAAG,eAAe,IAClD;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,wBAAwB,CAAC,QAAQ,CAAC,CAAA;CAAE,GAC9D;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,cAAc,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAEnE;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,GAAG,eAAe,EAAE,KAAK,EAAE,cAAc,CAAC,QAAQ,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,CAiC9I;AAED,oGAAoG;AACpG,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,KAAK,EAAE,cAAc,CAAC,QAAQ,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,QAAQ,EAAE,OAAO,GAAG,eAAe,CAAC,QAAQ,CAAC,CAuBnI;AAED,MAAM,WAAW,YAAY,CAAC,QAAQ,GAAG,eAAe;IACtD,KAAK,EAAE,cAAc,CAAC,QAAQ,CAAC,GAAG,IAAI,GAAG,SAAS,CAAA;IAClD,QAAQ,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,wBAAwB,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAA;IACrF,kFAAkF;IAClF,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,2BAA2B,KAAK,SAAS,CAAA;IAC5D,OAAO,CAAC,EAAE,SAAS,CAAA;CACpB;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,QAAQ,GAAG,eAAe,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,YAAY,CAAC,QAAQ,CAAC,GAAG,SAAS,CAmB7H"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { isAbortError } from '../errors.js';
|
|
4
|
+
import { hasAdapter, isReference, isResolved, isUnresolvable, isVariantSetEnvelope } from '../guards.js';
|
|
5
|
+
import { useContentContext, useResolveStrategy } from './ContentProvider.js';
|
|
6
|
+
import { REMEDIES } from './panels.js';
|
|
7
|
+
/**
|
|
8
|
+
* The resolution gate (spec 359 Business Logic §5 step 2): decides, from the value alone plus the
|
|
9
|
+
* strategy in force, whether a component value can be rendered right now, must be fetched (the
|
|
10
|
+
* normalized strategy), or falls back — and fetches it when that's the answer.
|
|
11
|
+
*/
|
|
12
|
+
export function useResolvedComponent(value) {
|
|
13
|
+
const { client } = useContentContext();
|
|
14
|
+
const strategy = useResolveStrategy();
|
|
15
|
+
const immediate = classify(value, strategy.strategy === 'normalized' && client !== undefined);
|
|
16
|
+
const needsFetch = immediate.status === 'loading';
|
|
17
|
+
const fetchKey = needsFetch && isReference(value) ? `${value.provider}:${value.key}:${JSON.stringify(value.contextualValues ?? null)}` : null;
|
|
18
|
+
const [fetched, setFetched] = useState(null);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (fetchKey === null || client === undefined || !isReference(value)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const controller = new AbortController();
|
|
24
|
+
client.resolveReference(value, { signal: controller.signal }).then((resolved) => setFetched({ key: fetchKey, state: classify(resolved, false) }), (error) => {
|
|
25
|
+
if (!isAbortError(error)) {
|
|
26
|
+
setFetched({ key: fetchKey, state: { status: 'fallback', reason: 'resolve_failed', error } });
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return () => controller.abort();
|
|
30
|
+
// `value`'s identity is captured by fetchKey; refetching for every new object with the same key would loop.
|
|
31
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
|
+
}, [fetchKey, client]);
|
|
33
|
+
if (!needsFetch) {
|
|
34
|
+
return immediate;
|
|
35
|
+
}
|
|
36
|
+
return fetched !== null && fetched.key === fetchKey ? fetched.state : immediate;
|
|
37
|
+
}
|
|
38
|
+
/** Pure classification; `canFetch` is "the normalized strategy is in force and a client exists". */
|
|
39
|
+
export function classify(value, canFetch) {
|
|
40
|
+
if (isResolved(value)) {
|
|
41
|
+
const content = value.content;
|
|
42
|
+
if (Object.values(content).some(isVariantSetEnvelope)) {
|
|
43
|
+
return { status: 'fallback', reason: 'client_resolve_unsupported' };
|
|
44
|
+
}
|
|
45
|
+
return { status: 'ready', value: value };
|
|
46
|
+
}
|
|
47
|
+
if (isUnresolvable(value)) {
|
|
48
|
+
return { status: 'fallback', reason: 'unresolvable' };
|
|
49
|
+
}
|
|
50
|
+
if (isReference(value)) {
|
|
51
|
+
if (hasAdapter(value)) {
|
|
52
|
+
return { status: 'fallback', reason: 'adapter_requires_server_resolve' };
|
|
53
|
+
}
|
|
54
|
+
return canFetch ? { status: 'loading' } : { status: 'fallback', reason: 'depth_exceeded' };
|
|
55
|
+
}
|
|
56
|
+
return { status: 'fallback', reason: 'unresolvable' };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Render-prop form of `useResolvedComponent` for a Reference field inside a renderer:
|
|
60
|
+
* `<Resolve value={content.author}>{(author) => <Byline {...author} />}</Resolve>`.
|
|
61
|
+
*/
|
|
62
|
+
export function Resolve({ value, children, fallback, loading }) {
|
|
63
|
+
const { Fallback, loading: defaultLoading } = useContentContext();
|
|
64
|
+
const state = useResolvedComponent(value);
|
|
65
|
+
if (state.status === 'loading') {
|
|
66
|
+
return loading ?? defaultLoading;
|
|
67
|
+
}
|
|
68
|
+
if (state.status === 'fallback') {
|
|
69
|
+
const props = {
|
|
70
|
+
reason: state.reason,
|
|
71
|
+
remedy: REMEDIES[state.reason](undefined),
|
|
72
|
+
envelope: { component: value },
|
|
73
|
+
error: state.error,
|
|
74
|
+
};
|
|
75
|
+
return fallback ? fallback(props) : _jsx(Fallback, { ...props });
|
|
76
|
+
}
|
|
77
|
+
return children(state.value.content, state.value);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=Resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Resolve.js","sourceRoot":"","sources":["../../src/react/Resolve.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAA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C,KAAK,CAAC,CAAC,CAAC,CAAC,KAAC,QAAQ,OAAK,KAAK,GAAI,CAAA;IAC7D,CAAC;IAED,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;AACnD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { ComponentValue, RichTextValue } from '../types.js';
|
|
3
|
+
export interface RichTextProps {
|
|
4
|
+
fragments: RichTextValue | null | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Renders a `reference` fragment (deprecated as an embed kind, still delivered when authored).
|
|
7
|
+
* There is no Template to dispatch on, so without this the fragment renders through the
|
|
8
|
+
* fallback.
|
|
9
|
+
*/
|
|
10
|
+
renderReference?: (value: ComponentValue, index: number) => ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Renders a delivered RichText value (docs/content-delivery-api.md §9) by dispatching on each
|
|
14
|
+
* fragment's `kind`: `markdown` → the provider's `markdown` renderer, `presentation` →
|
|
15
|
+
* `<RenderPresentation>`, `reference` → `renderReference`, `personalized` → the fallback
|
|
16
|
+
* (client-resolve is not supported by this layer).
|
|
17
|
+
*/
|
|
18
|
+
export declare function RichText({ fragments, renderReference }: RichTextProps): ReactNode;
|
|
19
|
+
//# sourceMappingURL=RichText.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RichText.d.ts","sourceRoot":"","sources":["../../src/react/RichText.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAChD,OAAO,KAAK,EAAE,cAAc,EAAoB,aAAa,EAAE,MAAM,aAAa,CAAA;AAKlF,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,aAAa,GAAG,IAAI,GAAG,SAAS,CAAA;IAC3C;;;;OAIG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAA;CACtE;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,EAAE,aAAa,GAAG,SAAS,CA0BjF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment } from 'react';
|
|
3
|
+
import { useContentContext } from './ContentProvider.js';
|
|
4
|
+
import { REMEDIES } from './panels.js';
|
|
5
|
+
import { RenderPresentation } from './RenderPresentation.js';
|
|
6
|
+
/**
|
|
7
|
+
* Renders a delivered RichText value (docs/content-delivery-api.md §9) by dispatching on each
|
|
8
|
+
* fragment's `kind`: `markdown` → the provider's `markdown` renderer, `presentation` →
|
|
9
|
+
* `<RenderPresentation>`, `reference` → `renderReference`, `personalized` → the fallback
|
|
10
|
+
* (client-resolve is not supported by this layer).
|
|
11
|
+
*/
|
|
12
|
+
export function RichText({ fragments, renderReference }) {
|
|
13
|
+
const { Markdown, Fallback } = useContentContext();
|
|
14
|
+
if (!fragments || fragments.length === 0) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return fragments.map((fragment, index) => _jsx(Fragment, { children: renderFragment(fragment, index) }, index));
|
|
18
|
+
function renderFragment(fragment, index) {
|
|
19
|
+
switch (fragment.kind) {
|
|
20
|
+
case 'markdown':
|
|
21
|
+
return Markdown ? _jsx(Markdown, { markdown: fragment.markdown }) : _jsx(DefaultMarkdown, { markdown: fragment.markdown });
|
|
22
|
+
case 'presentation':
|
|
23
|
+
return _jsx(RenderPresentation, { ...fragment.presentation });
|
|
24
|
+
case 'reference':
|
|
25
|
+
return renderReference ? (renderReference(fragment.reference, index)) : (_jsx(Fallback, { reason: "reference_needs_renderer", remedy: REMEDIES.reference_needs_renderer(undefined), envelope: fragment }));
|
|
26
|
+
case 'personalized':
|
|
27
|
+
return _jsx(Fallback, { reason: "client_resolve_unsupported", remedy: REMEDIES.client_resolve_unsupported(undefined), envelope: fragment });
|
|
28
|
+
default:
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** Shows the markdown source with a note — a visible reminder to supply a real renderer, never a silent blank. */
|
|
34
|
+
function DefaultMarkdown({ markdown }) {
|
|
35
|
+
return (_jsxs("div", { role: "note", "data-ebitex-content": "markdown-source", style: { fontFamily: 'system-ui, sans-serif', fontSize: '0.875rem' }, children: [_jsxs("p", { style: { margin: '0 0 0.25rem', opacity: 0.8 }, children: ["Markdown source \u2014 pass a ", _jsx("code", { children: "markdown" }), " renderer to <ContentProvider> (see docs/content-sdk.md)."] }), _jsx("pre", { style: { whiteSpace: 'pre-wrap', margin: 0 }, children: markdown })] }));
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=RichText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RichText.js","sourceRoot":"","sources":["../../src/react/RichText.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAY5D;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,EAAE,SAAS,EAAE,eAAe,EAAiB;IACpE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,iBAAiB,EAAE,CAAA;IAClD,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,KAAC,QAAQ,cAAc,cAAc,CAAC,QAAQ,E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AK,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,EAAE,YAAG,QAAQ,GAAO,IAC/D,CACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ebitex/content-sdk/react` — the rendering half. Crawls a delivered document by dispatching
|
|
3
|
+
* at every Presentation envelope on `template.externalId` to a renderer you register by
|
|
4
|
+
* convention (`presentations/<externalId>.tsx`, default export), with a guiding fallback for
|
|
5
|
+
* everything that cannot be rendered. React is a peer dependency, never bundled.
|
|
6
|
+
*/
|
|
7
|
+
export { ContentProvider, useResolveStrategy, type ContentProviderProps, type MarkdownRendererProps } from './ContentProvider.js';
|
|
8
|
+
export { Experience, useExperience, type ExperienceProps, type ExperienceState, type ExperienceStatus, type UseExperienceInput } from './Experience.js';
|
|
9
|
+
export { RenderPresentation, type RenderPresentationProps } from './RenderPresentation.js';
|
|
10
|
+
export { PresentationList, type PresentationListProps } from './PresentationList.js';
|
|
11
|
+
export { RichText, type RichTextProps } from './RichText.js';
|
|
12
|
+
export { Resolve, useResolvedComponent, type ResolutionState, type ResolveProps } from './Resolve.js';
|
|
13
|
+
export { defineRenderers, lazyRenderer, renderersFromGlob, type LazyRenderer, type PresentationRenderer, type PresentationRendererProps, type RendererEntry, type RendererModule, type RendererResolver, type Renderers, } from './registry.js';
|
|
14
|
+
export { ContentError, REMEDIES, UnresolvedPresentation, type ContentErrorProps, type FallbackReason, type UnresolvedPresentationProps, } from './panels.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AACjI,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,eAAe,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACvJ,OAAO,EAAE,kBAAkB,EAAE,KAAK,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AAC1F,OAAO,EAAE,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AACpF,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AACrG,OAAO,EACL,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,SAAS,GACf,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,sBAAsB,EACtB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,2BAA2B,GACjC,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ebitex/content-sdk/react` — the rendering half. Crawls a delivered document by dispatching
|
|
3
|
+
* at every Presentation envelope on `template.externalId` to a renderer you register by
|
|
4
|
+
* convention (`presentations/<externalId>.tsx`, default export), with a guiding fallback for
|
|
5
|
+
* everything that cannot be rendered. React is a peer dependency, never bundled.
|
|
6
|
+
*/
|
|
7
|
+
export { ContentProvider, useResolveStrategy } from './ContentProvider.js';
|
|
8
|
+
export { Experience, useExperience } from './Experience.js';
|
|
9
|
+
export { RenderPresentation } from './RenderPresentation.js';
|
|
10
|
+
export { PresentationList } from './PresentationList.js';
|
|
11
|
+
export { RichText } from './RichText.js';
|
|
12
|
+
export { Resolve, useResolvedComponent } from './Resolve.js';
|
|
13
|
+
export { defineRenderers, lazyRenderer, renderersFromGlob, } from './registry.js';
|
|
14
|
+
export { ContentError, REMEDIES, UnresolvedPresentation, } from './panels.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAyD,MAAM,sBAAsB,CAAA;AACjI,OAAO,EAAE,UAAU,EAAE,aAAa,EAA8F,MAAM,iBAAiB,CAAA;AACvJ,OAAO,EAAE,kBAAkB,EAAgC,MAAM,yBAAyB,CAAA;AAC1F,OAAO,EAAE,gBAAgB,EAA8B,MAAM,uBAAuB,CAAA;AACpF,OAAO,EAAE,QAAQ,EAAsB,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAA2C,MAAM,cAAc,CAAA;AACrG,OAAO,EACL,eAAe,EACf,YAAY,EACZ,iBAAiB,GAQlB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,sBAAsB,GAIvB,MAAM,aAAa,CAAA"}
|