@refrakt-md/react 0.9.2
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/Renderer.d.ts +28 -0
- package/dist/Renderer.d.ts.map +1 -0
- package/dist/Renderer.js +116 -0
- package/dist/Renderer.js.map +1 -0
- package/dist/elements/Pre.d.ts +15 -0
- package/dist/elements/Pre.d.ts.map +1 -0
- package/dist/elements/Pre.js +27 -0
- package/dist/elements/Pre.js.map +1 -0
- package/dist/elements/Table.d.ts +14 -0
- package/dist/elements/Table.d.ts.map +1 -0
- package/dist/elements/Table.js +21 -0
- package/dist/elements/Table.js.map +1 -0
- package/dist/elements.d.ts +10 -0
- package/dist/elements.d.ts.map +1 -0
- package/dist/elements.js +13 -0
- package/dist/elements.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/registry.d.ts +11 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +9 -0
- package/dist/registry.js.map +1 -0
- package/dist/theme.d.ts +17 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +2 -0
- package/dist/theme.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ReactNode, ComponentType } from 'react';
|
|
2
|
+
import type { RendererNode } from '@refrakt-md/types';
|
|
3
|
+
export interface RendererProps {
|
|
4
|
+
node: RendererNode;
|
|
5
|
+
/** typeof name → React component (component overrides) */
|
|
6
|
+
components?: Record<string, ComponentType<any>>;
|
|
7
|
+
/** HTML element name → React component (element-level overrides) */
|
|
8
|
+
elements?: Record<string, ComponentType<any>>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Render a RendererNode tree as a ReactNode.
|
|
12
|
+
*
|
|
13
|
+
* This is the primary rendering function for the React renderer (ADR-008).
|
|
14
|
+
*
|
|
15
|
+
* When a tag has a `data-rune` attribute matching a registered component:
|
|
16
|
+
* 1. `extractComponentInterface` partitions children into properties, named refs, and content
|
|
17
|
+
* 2. Properties become named React props (scalar strings)
|
|
18
|
+
* 3. Named refs become ReactNode props (pre-rendered HTML via dangerouslySetInnerHTML)
|
|
19
|
+
* 4. Anonymous content becomes the `children` prop
|
|
20
|
+
* 5. The original `tag` is passed for backwards-compatible escape-hatch access
|
|
21
|
+
*
|
|
22
|
+
* Element overrides (table, pre) receive `tag` and `children` props.
|
|
23
|
+
*
|
|
24
|
+
* Props are passed through explicitly (no React Context) so the renderer
|
|
25
|
+
* works in both Server Components and Client Components.
|
|
26
|
+
*/
|
|
27
|
+
export declare function Renderer({ node, components, elements }: RendererProps): ReactNode;
|
|
28
|
+
//# sourceMappingURL=Renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Renderer.d.ts","sourceRoot":"","sources":["../src/Renderer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGrE,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,YAAY,CAAC;IACnB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;IAChD,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;CAC9C;AAwBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,aAAa,GAAG,SAAS,CAoGjF"}
|
package/dist/Renderer.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createElement, Fragment } from 'react';
|
|
2
|
+
import { isTag, extractComponentInterface, renderToHtml } from '@refrakt-md/transform';
|
|
3
|
+
const VOID_ELEMENTS = new Set([
|
|
4
|
+
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',
|
|
5
|
+
'link', 'meta', 'param', 'source', 'track', 'wbr',
|
|
6
|
+
]);
|
|
7
|
+
/**
|
|
8
|
+
* Convert serialized tag attributes to React-compatible props.
|
|
9
|
+
* - Renames `class` → `className`
|
|
10
|
+
* - Strips internal `$$mdtype` attribute
|
|
11
|
+
* - Drops null/undefined/false values
|
|
12
|
+
* - Converts `true` to empty string (bare HTML attribute)
|
|
13
|
+
*/
|
|
14
|
+
function toReactProps(attrs) {
|
|
15
|
+
const result = {};
|
|
16
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
17
|
+
if (k === '$$mdtype' || v === undefined || v === null || v === false)
|
|
18
|
+
continue;
|
|
19
|
+
if (k === 'class') {
|
|
20
|
+
result.className = v;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
result[k] = v === true ? '' : v;
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Render a RendererNode tree as a ReactNode.
|
|
29
|
+
*
|
|
30
|
+
* This is the primary rendering function for the React renderer (ADR-008).
|
|
31
|
+
*
|
|
32
|
+
* When a tag has a `data-rune` attribute matching a registered component:
|
|
33
|
+
* 1. `extractComponentInterface` partitions children into properties, named refs, and content
|
|
34
|
+
* 2. Properties become named React props (scalar strings)
|
|
35
|
+
* 3. Named refs become ReactNode props (pre-rendered HTML via dangerouslySetInnerHTML)
|
|
36
|
+
* 4. Anonymous content becomes the `children` prop
|
|
37
|
+
* 5. The original `tag` is passed for backwards-compatible escape-hatch access
|
|
38
|
+
*
|
|
39
|
+
* Element overrides (table, pre) receive `tag` and `children` props.
|
|
40
|
+
*
|
|
41
|
+
* Props are passed through explicitly (no React Context) so the renderer
|
|
42
|
+
* works in both Server Components and Client Components.
|
|
43
|
+
*/
|
|
44
|
+
export function Renderer({ node, components, elements }) {
|
|
45
|
+
if (node === null || node === undefined)
|
|
46
|
+
return null;
|
|
47
|
+
if (typeof node === 'string')
|
|
48
|
+
return node;
|
|
49
|
+
if (typeof node === 'number')
|
|
50
|
+
return String(node);
|
|
51
|
+
if (Array.isArray(node)) {
|
|
52
|
+
return createElement(Fragment, null, ...node.map((child, i) => createElement(Renderer, { key: i, node: child, components, elements })));
|
|
53
|
+
}
|
|
54
|
+
if (!isTag(node))
|
|
55
|
+
return null;
|
|
56
|
+
// Component override dispatch via data-rune attribute
|
|
57
|
+
const runeType = node.attributes?.['data-rune'];
|
|
58
|
+
const Component = runeType && components?.[runeType];
|
|
59
|
+
if (Component) {
|
|
60
|
+
const iface = extractComponentInterface(node);
|
|
61
|
+
// Convert named refs to ReactNode values (pre-rendered HTML)
|
|
62
|
+
const refNodes = {};
|
|
63
|
+
for (const [name, tags] of Object.entries(iface.refs)) {
|
|
64
|
+
const html = tags.map(t => renderToHtml(t)).join('');
|
|
65
|
+
refNodes[name] = createElement('div', {
|
|
66
|
+
'data-ref': name,
|
|
67
|
+
dangerouslySetInnerHTML: { __html: html },
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
// Convert anonymous children to ReactNode
|
|
71
|
+
const childContent = iface.children.length > 0
|
|
72
|
+
? createElement(Fragment, null, ...iface.children.map((child, i) => createElement(Renderer, { key: i, node: child, components, elements })))
|
|
73
|
+
: undefined;
|
|
74
|
+
return createElement(Component, {
|
|
75
|
+
...iface.properties,
|
|
76
|
+
...refNodes,
|
|
77
|
+
children: childContent,
|
|
78
|
+
tag: node,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
// Element override dispatch via tag name
|
|
82
|
+
const ElementOverride = elements?.[node.name];
|
|
83
|
+
if (ElementOverride) {
|
|
84
|
+
return createElement(ElementOverride, { tag: node }, ...node.children.map((child, i) => createElement(Renderer, { key: i, node: child, components, elements })));
|
|
85
|
+
}
|
|
86
|
+
// SVG — render as raw HTML to avoid namespace issues
|
|
87
|
+
if (node.name === 'svg') {
|
|
88
|
+
return createElement('span', {
|
|
89
|
+
dangerouslySetInnerHTML: { __html: renderToHtml(node) },
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
// Null-named tags (Markdoc document root) — render children without wrapper
|
|
93
|
+
if (!node.name) {
|
|
94
|
+
return createElement(Fragment, null, ...node.children.map((child, i) => createElement(Renderer, { key: i, node: child, components, elements })));
|
|
95
|
+
}
|
|
96
|
+
// Void elements
|
|
97
|
+
if (VOID_ELEMENTS.has(node.name)) {
|
|
98
|
+
return createElement(node.name, toReactProps(node.attributes));
|
|
99
|
+
}
|
|
100
|
+
// Raw HTML content (code blocks, raw-html attribute)
|
|
101
|
+
const isRaw = node.attributes?.['data-codeblock'] || node.attributes?.['data-raw-html'];
|
|
102
|
+
if (isRaw) {
|
|
103
|
+
const html = node.children.map(child => {
|
|
104
|
+
if (typeof child === 'string')
|
|
105
|
+
return child;
|
|
106
|
+
return renderToHtml(child);
|
|
107
|
+
}).join('');
|
|
108
|
+
return createElement(node.name, {
|
|
109
|
+
...toReactProps(node.attributes),
|
|
110
|
+
dangerouslySetInnerHTML: { __html: html },
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// Regular HTML element — recursively render children
|
|
114
|
+
return createElement(node.name, toReactProps(node.attributes), ...node.children.map((child, i) => createElement(Renderer, { key: i, node: child, components, elements })));
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=Renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Renderer.js","sourceRoot":"","sources":["../src/Renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGhD,OAAO,EAAE,KAAK,EAAE,yBAAyB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAUvF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC7B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,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I,CAAC,IAAI,CAAC,EAAE,CAAC;QAClC,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,qDAAqD;IACrD,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,gBAAgB,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC,eAAe,CAAC,CAAC;IACxF,IAAI,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YACtC,IAAI,OAAO,KAAK,KAAK,QAAQ;gBAAE,OAAO,KAAK,CAAC;YAC5C,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACZ,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE;YAC/B,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;YAChC,uBAAuB,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;SACzC,CAAC,CAAC;IACJ,CAAC;IAED,qDAAqD;IACrD,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,EAC5D,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CACjC,aAAa,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CACtE,CACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { SerializedTag } from '@refrakt-md/types';
|
|
3
|
+
interface PreProps {
|
|
4
|
+
tag: SerializedTag;
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Pre element override — wraps code blocks in the rf-codeblock structure
|
|
9
|
+
* that @refrakt-md/behaviors enhances with a copy button.
|
|
10
|
+
*/
|
|
11
|
+
export declare function Pre({ tag, children }: PreProps): import("react").DetailedReactHTMLElement<Record<string, any>, HTMLElement> | import("react").DetailedReactHTMLElement<{
|
|
12
|
+
className: string;
|
|
13
|
+
}, HTMLElement>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=Pre.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pre.d.ts","sourceRoot":"","sources":["../../src/elements/Pre.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,UAAU,QAAQ;IACjB,GAAG,EAAE,aAAa,CAAC;IACnB,QAAQ,EAAE,SAAS,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,GAAG,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,QAAQ;;gBAY9C"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Pre element override — wraps code blocks in the rf-codeblock structure
|
|
4
|
+
* that @refrakt-md/behaviors enhances with a copy button.
|
|
5
|
+
*/
|
|
6
|
+
export function Pre({ tag, children }) {
|
|
7
|
+
const isCodeBlock = 'data-language' in (tag.attributes || {});
|
|
8
|
+
const attrs = filterAttrs(tag.attributes);
|
|
9
|
+
if (isCodeBlock) {
|
|
10
|
+
return createElement('div', { className: 'rf-codeblock' }, createElement('pre', attrs, children));
|
|
11
|
+
}
|
|
12
|
+
return createElement('pre', attrs, children);
|
|
13
|
+
}
|
|
14
|
+
function filterAttrs(attrs) {
|
|
15
|
+
const result = {};
|
|
16
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
17
|
+
if (k === '$$mdtype' || v === undefined || v === null || v === false)
|
|
18
|
+
continue;
|
|
19
|
+
if (k === 'class') {
|
|
20
|
+
result.className = v;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
result[k] = v === true ? '' : v;
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=Pre.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pre.js","sourceRoot":"","sources":["../../src/elements/Pre.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAStC;;;GAGG;AACH,MAAM,UAAU,GAAG,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAY;IAC9C,MAAM,WAAW,GAAG,eAAe,IAAI,CAAC,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;IAE9D,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAE1C,IAAI,WAAW,EAAE,CAAC;QACjB,OAAO,aAAa,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,cAAc,EAAE,EACxD,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,CACrC,CAAC;IACH,CAAC;IAED,OAAO,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,WAAW,CAAC,KAA0B;IAC9C,MAAM,MAAM,GAAwB,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5C,IAAI,CAAC,KAAK,UAAU,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,KAAK;YAAE,SAAS;QAC/E,IAAI,CAAC,KAAK,OAAO,EAAE,CAAC;YAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC;YAAC,SAAS;QAAC,CAAC;QACtD,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { SerializedTag } from '@refrakt-md/types';
|
|
3
|
+
interface TableProps {
|
|
4
|
+
tag: SerializedTag;
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Table element override — wraps <table> in a scrollable container.
|
|
9
|
+
*/
|
|
10
|
+
export declare function Table({ tag, children }: TableProps): import("react").DetailedReactHTMLElement<{
|
|
11
|
+
className: string;
|
|
12
|
+
}, HTMLElement>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=Table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../src/elements/Table.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,UAAU,UAAU;IACnB,GAAG,EAAE,aAAa,CAAC;IACnB,QAAQ,EAAE,SAAS,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,UAAU;;gBAIlD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Table element override — wraps <table> in a scrollable container.
|
|
4
|
+
*/
|
|
5
|
+
export function Table({ tag, children }) {
|
|
6
|
+
return createElement('div', { className: 'rf-table-wrapper' }, createElement('table', filterAttrs(tag.attributes), children));
|
|
7
|
+
}
|
|
8
|
+
function filterAttrs(attrs) {
|
|
9
|
+
const result = {};
|
|
10
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
11
|
+
if (k === '$$mdtype' || v === undefined || v === null || v === false)
|
|
12
|
+
continue;
|
|
13
|
+
if (k === 'class') {
|
|
14
|
+
result.className = v;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
result[k] = v === true ? '' : v;
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=Table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../../src/elements/Table.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAStC;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAc;IAClD,OAAO,aAAa,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,kBAAkB,EAAE,EAC5D,aAAa,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,CAC7D,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAA0B;IAC9C,MAAM,MAAM,GAAwB,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5C,IAAI,CAAC,KAAK,UAAU,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,KAAK;YAAE,SAAS;QAC/E,IAAI,CAAC,KAAK,OAAO,EAAE,CAAC;YAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC;YAAC,SAAS;QAAC,CAAC;QACtD,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
export type ElementOverrides = Record<string, ComponentType<any>>;
|
|
3
|
+
/**
|
|
4
|
+
* Default element overrides for the React renderer.
|
|
5
|
+
*
|
|
6
|
+
* - `table`: Wraps in scrollable container
|
|
7
|
+
* - `pre`: Wraps code blocks in rf-codeblock structure for behaviors
|
|
8
|
+
*/
|
|
9
|
+
export declare const elements: ElementOverrides;
|
|
10
|
+
//# sourceMappingURL=elements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../src/elements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI3C,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;AAElE;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,EAAE,gBAGtB,CAAC"}
|
package/dist/elements.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Table } from './elements/Table.js';
|
|
2
|
+
import { Pre } from './elements/Pre.js';
|
|
3
|
+
/**
|
|
4
|
+
* Default element overrides for the React renderer.
|
|
5
|
+
*
|
|
6
|
+
* - `table`: Wraps in scrollable container
|
|
7
|
+
* - `pre`: Wraps code blocks in rf-codeblock structure for behaviors
|
|
8
|
+
*/
|
|
9
|
+
export const elements = {
|
|
10
|
+
table: Table,
|
|
11
|
+
pre: Pre,
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=elements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elements.js","sourceRoot":"","sources":["../src/elements.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAIxC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAqB;IACzC,KAAK,EAAE,KAAK;IACZ,GAAG,EAAE,GAAG;CACR,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { Renderer } from './Renderer.js';
|
|
2
|
+
export type { RendererProps } from './Renderer.js';
|
|
3
|
+
export type { ReactTheme } from './theme.js';
|
|
4
|
+
export { registry } from './registry.js';
|
|
5
|
+
export type { ComponentRegistry } from './registry.js';
|
|
6
|
+
export { elements } from './elements.js';
|
|
7
|
+
export type { ElementOverrides } from './elements.js';
|
|
8
|
+
export { Table } from './elements/Table.js';
|
|
9
|
+
export { Pre } from './elements/Pre.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGvD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Renderer
|
|
2
|
+
export { Renderer } from './Renderer.js';
|
|
3
|
+
// Component registry
|
|
4
|
+
export { registry } from './registry.js';
|
|
5
|
+
// Element overrides
|
|
6
|
+
export { elements } from './elements.js';
|
|
7
|
+
// Element override components
|
|
8
|
+
export { Table } from './elements/Table.js';
|
|
9
|
+
export { Pre } from './elements/Pre.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAMzC,qBAAqB;AACrB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,oBAAoB;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,8BAA8B;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
export type ComponentRegistry = Record<string, ComponentType<any>>;
|
|
3
|
+
/**
|
|
4
|
+
* Default component registry — empty by default.
|
|
5
|
+
*
|
|
6
|
+
* All runes render through the identity transform + @refrakt-md/behaviors.
|
|
7
|
+
* Theme authors register component overrides for runes that need
|
|
8
|
+
* custom React rendering.
|
|
9
|
+
*/
|
|
10
|
+
export declare const registry: ComponentRegistry;
|
|
11
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;AAEnE;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,EAAE,iBAAsB,CAAC"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default component registry — empty by default.
|
|
3
|
+
*
|
|
4
|
+
* All runes render through the identity transform + @refrakt-md/behaviors.
|
|
5
|
+
* Theme authors register component overrides for runes that need
|
|
6
|
+
* custom React rendering.
|
|
7
|
+
*/
|
|
8
|
+
export const registry = {};
|
|
9
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAsB,EAAE,CAAC"}
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ThemeManifest } from '@refrakt-md/types';
|
|
2
|
+
import type { LayoutConfig } from '@refrakt-md/transform';
|
|
3
|
+
import type { ComponentType } from 'react';
|
|
4
|
+
/**
|
|
5
|
+
* A resolved React theme: the manifest plus live component references.
|
|
6
|
+
* This is the runtime contract between a theme package and the React renderer.
|
|
7
|
+
*/
|
|
8
|
+
export interface ReactTheme {
|
|
9
|
+
manifest: ThemeManifest;
|
|
10
|
+
/** Layout name → declarative LayoutConfig */
|
|
11
|
+
layouts: Record<string, LayoutConfig>;
|
|
12
|
+
/** typeof name → React component (the component registry) */
|
|
13
|
+
components: Record<string, ComponentType<any>>;
|
|
14
|
+
/** HTML element name → React component (element-level overrides) */
|
|
15
|
+
elements?: Record<string, ComponentType<any>>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C;;;GAGG;AACH,MAAM,WAAW,UAAU;IAC1B,QAAQ,EAAE,aAAa,CAAC;IACxB,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACtC,6DAA6D;IAC7D,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/C,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;CAC9C"}
|
package/dist/theme.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.js","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@refrakt-md/react",
|
|
3
|
+
"description": "React renderer for refrakt.md content — ADR-008 component interface with props and named slots",
|
|
4
|
+
"version": "0.9.2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/refrakt-md/refrakt.git",
|
|
10
|
+
"directory": "packages/react"
|
|
11
|
+
},
|
|
12
|
+
"bugs": "https://github.com/refrakt-md/refrakt/issues",
|
|
13
|
+
"homepage": "https://github.com/refrakt-md/refrakt",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@refrakt-md/transform": "0.9.2",
|
|
33
|
+
"@refrakt-md/types": "0.9.2"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"react": "^19.0.0",
|
|
37
|
+
"@types/react": "^19.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
41
|
+
}
|
|
42
|
+
}
|