@draftbase/renderer 0.5.2 → 0.5.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/dist/MDXContent.d.ts +7 -2
- package/dist/MDXContent.js +9 -3
- package/dist/core.d.ts +23 -4
- package/dist/core.js +11 -0
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/MDXContent.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MDXComponents } from "mdx/types";
|
|
2
2
|
import type { ComponentType, ElementType, ReactNode } from "react";
|
|
3
|
-
import { type FailedMDX } from "./core.js";
|
|
3
|
+
import { type FailedMDX, type LinkedEntryData } from "./core.js";
|
|
4
4
|
export interface CompiledMDX {
|
|
5
5
|
ok: true;
|
|
6
6
|
Content: ComponentType<{
|
|
@@ -33,9 +33,14 @@ export interface MDXContentProps {
|
|
|
33
33
|
* throws while rendering. Either way the fallback plain-text output still renders instead of
|
|
34
34
|
* crashing. */
|
|
35
35
|
onError?: (error: unknown) => void;
|
|
36
|
+
/** The containing entry's own `entryLinks` (from `getEntry`/`getEntries` called with `include`
|
|
37
|
+
* set) — id-keyed resolved data for every `<EntryLink id="...">` found in `source`. When given,
|
|
38
|
+
* each `EntryLink` instance receives its target's data as extra props, so `components.EntryLink`
|
|
39
|
+
* doesn't need to re-fetch it. */
|
|
40
|
+
entryLinks?: Record<string, LinkedEntryData>;
|
|
36
41
|
}
|
|
37
42
|
/**
|
|
38
43
|
* Next.js Server Component wrapper around {@link compileMDX}. For non-RSC React, call `compileMDX` directly instead —
|
|
39
44
|
* `await` inside a component body only works as an RSC.
|
|
40
45
|
*/
|
|
41
|
-
export declare function MDXContent({ source, components, unstyled, className, wrapperTag, errorTag, onError, }: MDXContentProps): Promise<ReactNode>;
|
|
46
|
+
export declare function MDXContent({ source, components, unstyled, className, wrapperTag, errorTag, onError, entryLinks, }: MDXContentProps): Promise<ReactNode>;
|
package/dist/MDXContent.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import * as runtime from "react/jsx-runtime";
|
|
3
|
-
import { compileMDXCore, makeDefaultEntryLink, makeDefaultImage } from "./core.js";
|
|
3
|
+
import { compileMDXCore, makeDefaultEntryLink, makeDefaultImage, withEntryLinkData, } from "./core.js";
|
|
4
4
|
import { wrapperClassName } from "./wrapperClassName.js";
|
|
5
5
|
import { MDXErrorBoundary } from "./MDXErrorBoundary.js";
|
|
6
6
|
import { CSS_TEXT } from "./cssText.js";
|
|
@@ -19,10 +19,16 @@ export async function compileMDX(source) {
|
|
|
19
19
|
* Next.js Server Component wrapper around {@link compileMDX}. For non-RSC React, call `compileMDX` directly instead —
|
|
20
20
|
* `await` inside a component body only works as an RSC.
|
|
21
21
|
*/
|
|
22
|
-
export async function MDXContent({ source, components, unstyled, className, wrapperTag = "div", errorTag = "p", onError, }) {
|
|
22
|
+
export async function MDXContent({ source, components, unstyled, className, wrapperTag = "div", errorTag = "p", onError, entryLinks, }) {
|
|
23
23
|
const Wrapper = wrapperTag;
|
|
24
24
|
const ErrorTag = errorTag;
|
|
25
25
|
const wrapperClass = wrapperClassName(unstyled, className);
|
|
26
|
+
const effectiveComponents = entryLinks
|
|
27
|
+
? {
|
|
28
|
+
...components,
|
|
29
|
+
EntryLink: withEntryLinkData(components?.EntryLink ?? defaultComponents.EntryLink, entryLinks, runtime),
|
|
30
|
+
}
|
|
31
|
+
: components;
|
|
26
32
|
// `href` + `precedence` make React DOM treat this as a de-duplicated, hoisted stylesheet
|
|
27
33
|
// resource (React 19+) instead of a plain inline tag repeated per render.
|
|
28
34
|
const styles = unstyled ? null : (_jsx("style", { href: "db-content-styles", precedence: "default", children: CSS_TEXT }));
|
|
@@ -35,5 +41,5 @@ export async function MDXContent({ source, components, unstyled, className, wrap
|
|
|
35
41
|
return (_jsxs(_Fragment, { children: [styles, _jsx(Wrapper, { className: wrapperClass, children: _jsx(ErrorTag, { children: source }) })] }));
|
|
36
42
|
}
|
|
37
43
|
const { Content } = compiled;
|
|
38
|
-
return (_jsxs(_Fragment, { children: [styles, _jsx(Wrapper, { className: wrapperClass, children: _jsx(MDXErrorBoundary, { fallback: _jsx(ErrorTag, { children: source }), onError: onError, children: _jsx(Content, { components:
|
|
44
|
+
return (_jsxs(_Fragment, { children: [styles, _jsx(Wrapper, { className: wrapperClass, children: _jsx(MDXErrorBoundary, { fallback: _jsx(ErrorTag, { children: source }), onError: onError, children: _jsx(Content, { components: effectiveComponents }) }) })] }));
|
|
39
45
|
}
|
package/dist/core.d.ts
CHANGED
|
@@ -13,12 +13,31 @@ export interface FailedMDX {
|
|
|
13
13
|
* the remark/rehype pipeline. `defaultComponents`, when given, are merged underneath the caller's own `components` (caller always wins per-tag).
|
|
14
14
|
*/
|
|
15
15
|
export declare function compileMDXCore<TComponent>(source: string, jsxRuntime: JsxRuntime, defaultComponents?: Record<string, unknown>): Promise<CompiledMDX<TComponent> | FailedMDX>;
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
|
|
16
|
+
/** The linked entry's own resolved data — the same shape the delivery API's `getEntry`/`getEntries`
|
|
17
|
+
* attach at `entry.entryLinks[id]` when called with `include` set (optionally widened with
|
|
18
|
+
* `entryLinkFields`). Mirrors the SDK's `EntryLinkView` minus `id`, kept local so the
|
|
19
|
+
* framework-agnostic renderer doesn't depend on `@draftbase/sdk`. */
|
|
20
|
+
export interface LinkedEntryData {
|
|
21
|
+
templateId: string;
|
|
22
|
+
title: string;
|
|
23
|
+
status: string;
|
|
24
|
+
fields?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/** Props passed to `EntryLink` — the id of the linked entry, authored via the entry picker in
|
|
27
|
+
* the MDX editor, plus that entry's own resolved data when the caller passed `entryLinks` to
|
|
28
|
+
* `MDXContent`/`compileMDX` (avoids an extra per-link fetch at render time). Apps overriding
|
|
29
|
+
* `components.EntryLink` should type their component against this. */
|
|
30
|
+
export interface EntryLinkProps extends Partial<LinkedEntryData> {
|
|
19
31
|
id?: string;
|
|
20
32
|
children?: unknown;
|
|
21
|
-
}
|
|
33
|
+
}
|
|
34
|
+
/** Default `EntryLink` for a given JSX runtime — renders `<a href="/entries/{id}">`; apps that
|
|
35
|
+
* route entries differently override it by passing `components.EntryLink`. */
|
|
36
|
+
export declare function makeDefaultEntryLink(jsxRuntime: JsxRuntime): ({ id, children }: EntryLinkProps) => JSX.Element;
|
|
37
|
+
/** Wraps `EntryLink` (custom or default) so every instance also receives its resolved
|
|
38
|
+
* `LinkedEntryData` from `entryLinks[id]` — the caller's already-fetched `getEntry`/`getEntries`
|
|
39
|
+
* result — instead of each link having to re-fetch its own target. */
|
|
40
|
+
export declare function withEntryLinkData(EntryLink: unknown, entryLinks: Record<string, LinkedEntryData> | undefined, jsxRuntime: JsxRuntime): unknown;
|
|
22
41
|
/** Default `img` for a given JSX runtime — defers offscreen image loads instead of the browser's
|
|
23
42
|
* eager default. Apps that want `next/image` (or another optimizer) override it via `components.img`;
|
|
24
43
|
* an explicit `loading`/`decoding` on the element itself (rare, but author-settable) still wins. */
|
package/dist/core.js
CHANGED
|
@@ -38,6 +38,17 @@ export function makeDefaultEntryLink(jsxRuntime) {
|
|
|
38
38
|
return jsxRuntime.jsx("a", { href: id ? `/entries/${id}` : undefined, children });
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
+
/** Wraps `EntryLink` (custom or default) so every instance also receives its resolved
|
|
42
|
+
* `LinkedEntryData` from `entryLinks[id]` — the caller's already-fetched `getEntry`/`getEntries`
|
|
43
|
+
* result — instead of each link having to re-fetch its own target. */
|
|
44
|
+
export function withEntryLinkData(EntryLink, entryLinks, jsxRuntime) {
|
|
45
|
+
if (!entryLinks)
|
|
46
|
+
return EntryLink;
|
|
47
|
+
return function EntryLinkWithData(props) {
|
|
48
|
+
const linked = props.id ? entryLinks[props.id] : undefined;
|
|
49
|
+
return jsxRuntime.jsx(EntryLink, { ...props, ...linked });
|
|
50
|
+
};
|
|
51
|
+
}
|
|
41
52
|
/** Default `img` for a given JSX runtime — defers offscreen image loads instead of the browser's
|
|
42
53
|
* eager default. Apps that want `next/image` (or another optimizer) override it via `components.img`;
|
|
43
54
|
* an explicit `loading`/`decoding` on the element itself (rare, but author-settable) still wins. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { MDXContent, compileMDX } from "./MDXContent.js";
|
|
2
2
|
export type { MDXContentProps, CompiledMDX, FailedMDX } from "./MDXContent.js";
|
|
3
|
+
export type { EntryLinkProps, LinkedEntryData } from "./core.js";
|
|
3
4
|
export { toHtml } from "./toHtml.js";
|
|
4
5
|
export { MDXErrorBoundary } from "./MDXErrorBoundary.js";
|