@ai-matrx/content-ir-react 0.7.1 → 0.8.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/CHANGELOG.md +61 -0
- package/dist/component-resolution.types-BS1ySIg-.d.cts +104 -0
- package/dist/component-resolution.types-BS1ySIg-.d.ts +104 -0
- package/dist/component-resolution.types-fvR92hW7.d.cts +142 -0
- package/dist/component-resolution.types-fvR92hW7.d.ts +142 -0
- package/dist/db-component.cjs +226 -0
- package/dist/db-component.cjs.map +1 -0
- package/dist/db-component.d.cts +267 -0
- package/dist/db-component.d.ts +267 -0
- package/dist/db-component.js +194 -0
- package/dist/db-component.js.map +1 -0
- package/dist/host-types-CZ_Bkp4R.d.ts +131 -0
- package/dist/host-types-DvGv8s9L.d.cts +131 -0
- package/dist/host.cjs +74 -0
- package/dist/host.cjs.map +1 -0
- package/dist/host.d.cts +24 -0
- package/dist/host.d.ts +24 -0
- package/dist/host.js +52 -0
- package/dist/host.js.map +1 -0
- package/dist/index.cjs +356 -90
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +280 -672
- package/dist/index.d.ts +280 -672
- package/dist/index.js +316 -31
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +361 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +195 -0
- package/dist/react.d.ts +195 -0
- package/dist/react.js +344 -0
- package/dist/react.js.map +1 -0
- package/dist/resolver.cjs +327 -0
- package/dist/resolver.cjs.map +1 -0
- package/dist/resolver.d.cts +133 -0
- package/dist/resolver.d.ts +133 -0
- package/dist/resolver.js +304 -0
- package/dist/resolver.js.map +1 -0
- package/dist/route-C1XNcubB.d.ts +433 -0
- package/dist/route-C55jsF4B.d.cts +433 -0
- package/dist/route.cjs +259 -0
- package/dist/route.cjs.map +1 -0
- package/dist/route.d.cts +4 -0
- package/dist/route.d.ts +4 -0
- package/dist/route.js +247 -0
- package/dist/route.js.map +1 -0
- package/package.json +75 -2
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { KindDefinition } from '@ai-matrx/content-ir';
|
|
3
|
+
import { d as ComponentResolutionSource, a as ContentIrErrorReporter } from './component-resolution.types-BS1ySIg-.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* THE HOST CONTRACT — everything this package refuses to decide.
|
|
7
|
+
*
|
|
8
|
+
* The kernel (`@ai-matrx/content-ir`) proved the shape: extract the portable
|
|
9
|
+
* part, let host capability enter through explicit named seams. The render
|
|
10
|
+
* layer needs four things it must never own:
|
|
11
|
+
*
|
|
12
|
+
* 1. WHERE KIND DEFINITIONS COME FROM (a bundled table, `content_ir`, a REST
|
|
13
|
+
* call). The route only asks "is this kind registered, and does it carry a
|
|
14
|
+
* legacy bridge / a partial-ready opt-in".
|
|
15
|
+
* 2. WHERE COMPONENT ROWS COME FROM — {@link ComponentResolutionSource}. The
|
|
16
|
+
* package ships `ComponentResolver`, which any host can construct with its
|
|
17
|
+
* own loaders; a host with its own resolver only has to satisfy the type.
|
|
18
|
+
* 3. HOW A ROUTED BLOCK ACTUALLY DRAWS. `applyIrKindRoute` decides a block's
|
|
19
|
+
* TYPE; turning that type into pixels is the host's dispatch table
|
|
20
|
+
* (matrx-frontend's `BlockRenderer`, the dashboard's small map). The
|
|
21
|
+
* package never imports a component library.
|
|
22
|
+
* 4. WHERE SCREAMS LAND — {@link ContentIrErrorReporter}.
|
|
23
|
+
*
|
|
24
|
+
* No Next.js, no Redux, no Supabase, no router, no host error capture. If a
|
|
25
|
+
* seam is missing, ADD A SEAM — never an import.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The minimum a render block must expose for the kind route to work. Hosts
|
|
30
|
+
* pass their own richer block type through; the route is generic over `T` and
|
|
31
|
+
* preserves every extra field.
|
|
32
|
+
*/
|
|
33
|
+
interface IrRoutableBlock {
|
|
34
|
+
type: string;
|
|
35
|
+
serverData?: Record<string, unknown>;
|
|
36
|
+
metadata?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
/** A routable block that also carries its source text (the raw region). */
|
|
39
|
+
interface IrRenderBlock extends IrRoutableBlock {
|
|
40
|
+
content: string;
|
|
41
|
+
language?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Where registered kinds come from. `getDefinition` is the only method the
|
|
45
|
+
* pure route needs; the rest drive the granular repaint and the warm-up tick
|
|
46
|
+
* that keeps a cold registry from being mistaken for "this kind has no
|
|
47
|
+
* component".
|
|
48
|
+
*/
|
|
49
|
+
interface KindDefinitionSource {
|
|
50
|
+
getDefinition(kind: string): KindDefinition | undefined;
|
|
51
|
+
/** Monotonic per-kind version — the repaint snapshot key. */
|
|
52
|
+
getKindVersion(kind: string): number;
|
|
53
|
+
subscribeKind(kind: string, listener: () => void): () => void;
|
|
54
|
+
/** One definition load per app session. */
|
|
55
|
+
ensureWarm(): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The rendering seams. Everything here returns host UI; the package supplies
|
|
59
|
+
* the DECISIONS and the chrome-free structure around them.
|
|
60
|
+
*/
|
|
61
|
+
interface ContentIrRenderSeams {
|
|
62
|
+
/**
|
|
63
|
+
* Draw a block the kind route has already typed. This is the host's dispatch
|
|
64
|
+
* table — the single place a component key becomes a component.
|
|
65
|
+
*/
|
|
66
|
+
renderBlock(block: IrRenderBlock): ReactNode;
|
|
67
|
+
/**
|
|
68
|
+
* THE FLOOR: render ANY JSON value as a human document. Reached when a kind
|
|
69
|
+
* has no render-trusted component, when the value is not an object at all,
|
|
70
|
+
* and by the generic structured view.
|
|
71
|
+
*
|
|
72
|
+
* This is deliberately a seam and not a bundled component. Rendering a value
|
|
73
|
+
* WELL means prose through the host's markdown renderer, media through the
|
|
74
|
+
* host's file handler, and uniform arrays through the host's data table —
|
|
75
|
+
* all of which are host property. A host that has none of those can pass a
|
|
76
|
+
* `<pre>`; it will be honest, just plain.
|
|
77
|
+
*/
|
|
78
|
+
renderValue(props: StructuredValueRenderProps): ReactNode;
|
|
79
|
+
/**
|
|
80
|
+
* The "still arriving" indicator used by the provisional frame. Optional —
|
|
81
|
+
* hosts without a shimmer get plain text.
|
|
82
|
+
*/
|
|
83
|
+
renderShimmer?(text: string): ReactNode;
|
|
84
|
+
/**
|
|
85
|
+
* The honest "this shape has no custom component yet" notice. Optional: the
|
|
86
|
+
* package draws a plain amber line when a host supplies nothing, and a host
|
|
87
|
+
* with an icon set or its own callout component supplies that instead. It is
|
|
88
|
+
* a seam and not a bundled component because this package depends on no icon
|
|
89
|
+
* library.
|
|
90
|
+
*/
|
|
91
|
+
renderNotice?(text: string): ReactNode;
|
|
92
|
+
}
|
|
93
|
+
interface StructuredValueRenderProps {
|
|
94
|
+
value: unknown;
|
|
95
|
+
/** The kind slug this value claims, when known. Honesty line only — never a renderer choice. */
|
|
96
|
+
kind?: string;
|
|
97
|
+
/** Why this shape has no custom view, in human words. */
|
|
98
|
+
note?: string;
|
|
99
|
+
/** Show the "what this is / raw data" footer. Default true. */
|
|
100
|
+
footer?: boolean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* One host, wired once, read by every component in this package through
|
|
104
|
+
* {@link ContentIrRenderProvider}.
|
|
105
|
+
*/
|
|
106
|
+
interface ContentIrHost extends ContentIrRenderSeams {
|
|
107
|
+
kinds: KindDefinitionSource;
|
|
108
|
+
components: ComponentResolutionSource;
|
|
109
|
+
reportError: ContentIrErrorReporter;
|
|
110
|
+
/**
|
|
111
|
+
* The `kind_component.platform` this host resolves as. "web" for every
|
|
112
|
+
* browser UI; the column already models "react-native" and friends, and a
|
|
113
|
+
* host that lies here renders the wrong component everywhere.
|
|
114
|
+
*/
|
|
115
|
+
platform: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The pure route's dependencies — a strict subset of {@link ContentIrHost},
|
|
119
|
+
* because `applyIrKindRoute` is called OUTSIDE React (reducers, stream
|
|
120
|
+
* accumulators, tests) where there is no provider to read.
|
|
121
|
+
*/
|
|
122
|
+
interface KindRouteEnv {
|
|
123
|
+
kinds: Pick<KindDefinitionSource, "getDefinition">;
|
|
124
|
+
components: Pick<ComponentResolutionSource, "resolve">;
|
|
125
|
+
reportError: ContentIrErrorReporter;
|
|
126
|
+
platform: string;
|
|
127
|
+
}
|
|
128
|
+
/** Narrow a host (or anything host-shaped) to what the pure route needs. */
|
|
129
|
+
declare function routeEnvOf(host: ContentIrHost): KindRouteEnv;
|
|
130
|
+
|
|
131
|
+
export { type ContentIrHost as C, type IrRenderBlock as I, type KindRouteEnv as K, type StructuredValueRenderProps as S, type ContentIrRenderSeams as a, type IrRoutableBlock as b, type KindDefinitionSource as c, routeEnvOf as r };
|
package/dist/host.cjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// host.ts
|
|
22
|
+
var host_exports = {};
|
|
23
|
+
__export(host_exports, {
|
|
24
|
+
ContentIrRenderProvider: () => ContentIrRenderProvider,
|
|
25
|
+
consoleErrorReporter: () => consoleErrorReporter,
|
|
26
|
+
routeEnvOf: () => routeEnvOf,
|
|
27
|
+
useContentIrHost: () => useContentIrHost,
|
|
28
|
+
useContentIrHostOrNull: () => useContentIrHostOrNull,
|
|
29
|
+
useKindRouteEnv: () => useKindRouteEnv
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(host_exports);
|
|
32
|
+
|
|
33
|
+
// host/error-report.ts
|
|
34
|
+
var consoleErrorReporter = (report) => {
|
|
35
|
+
console.error(`[content-ir] ${report.message}`, report.raw ?? "");
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// host/host-types.ts
|
|
39
|
+
function routeEnvOf(host) {
|
|
40
|
+
return {
|
|
41
|
+
kinds: host.kinds,
|
|
42
|
+
components: host.components,
|
|
43
|
+
reportError: host.reportError,
|
|
44
|
+
platform: host.platform
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// host/ContentIrProvider.tsx
|
|
49
|
+
var import_react = require("react");
|
|
50
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
51
|
+
var ContentIrHostContext = (0, import_react.createContext)(null);
|
|
52
|
+
function ContentIrRenderProvider({
|
|
53
|
+
host,
|
|
54
|
+
children
|
|
55
|
+
}) {
|
|
56
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContentIrHostContext.Provider, { value: host, children });
|
|
57
|
+
}
|
|
58
|
+
function useContentIrHostOrNull() {
|
|
59
|
+
return (0, import_react.useContext)(ContentIrHostContext);
|
|
60
|
+
}
|
|
61
|
+
function useContentIrHost() {
|
|
62
|
+
const host = useContentIrHostOrNull();
|
|
63
|
+
if (!host) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
"[content-ir-react] No ContentIrRenderProvider above this component. Mount one at the app root with your host adapter (kind definitions, component resolver, renderBlock, renderValue, reportError)."
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return host;
|
|
69
|
+
}
|
|
70
|
+
function useKindRouteEnv() {
|
|
71
|
+
const host = useContentIrHost();
|
|
72
|
+
return (0, import_react.useMemo)(() => routeEnvOf(host), [host]);
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=host.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../host.ts","../host/error-report.ts","../host/host-types.ts","../host/ContentIrProvider.tsx"],"sourcesContent":["/**\n * `@ai-matrx/content-ir-react/host` — the contract every consumer wires once:\n * the scream seam, the host/seam types, and the React provider.\n *\n * NOTE: this entry is stamped \"use client\" (it carries the provider). The\n * TYPES here are importable from anywhere; a server-side module that needs\n * only pure route logic imports `/route` instead.\n */\nexport * from \"./host/error-report\";\nexport * from \"./host/host-types\";\nexport * from \"./host/ContentIrProvider\";\n","/**\n * THE SCREAM SEAM.\n *\n * Every recovery path in this package is loud: a defective component row, a\n * failed resolver load, a kind whose component throws on a provisional value.\n * The package refuses to own where those screams land — matrx-frontend routes\n * them to the Error Inspector, the dashboard to its own log, the extension to\n * its background page. Each host binds one function.\n *\n * A host that binds a no-op has chosen silence, which is a defect in itself;\n * {@link consoleErrorReporter} is the honest default.\n */\n\nexport interface ContentIrErrorReport {\n /** Always `\"content-ir\"` — hosts key their capture stores on it. */\n source: \"content-ir\";\n message: string;\n name?: string;\n stack?: string;\n /** Free-form grouping key (the host's `relation`), e.g. `\"partial-kind\"`. */\n relation?: string;\n raw?: unknown;\n}\n\nexport type ContentIrErrorReporter = (report: ContentIrErrorReport) => void;\n\n/** The default when a host binds nothing: never silent. */\nexport const consoleErrorReporter: ContentIrErrorReporter = (report) => {\n console.error(`[content-ir] ${report.message}`, report.raw ?? \"\");\n};\n","/**\n * THE HOST CONTRACT — everything this package refuses to decide.\n *\n * The kernel (`@ai-matrx/content-ir`) proved the shape: extract the portable\n * part, let host capability enter through explicit named seams. The render\n * layer needs four things it must never own:\n *\n * 1. WHERE KIND DEFINITIONS COME FROM (a bundled table, `content_ir`, a REST\n * call). The route only asks \"is this kind registered, and does it carry a\n * legacy bridge / a partial-ready opt-in\".\n * 2. WHERE COMPONENT ROWS COME FROM — {@link ComponentResolutionSource}. The\n * package ships `ComponentResolver`, which any host can construct with its\n * own loaders; a host with its own resolver only has to satisfy the type.\n * 3. HOW A ROUTED BLOCK ACTUALLY DRAWS. `applyIrKindRoute` decides a block's\n * TYPE; turning that type into pixels is the host's dispatch table\n * (matrx-frontend's `BlockRenderer`, the dashboard's small map). The\n * package never imports a component library.\n * 4. WHERE SCREAMS LAND — {@link ContentIrErrorReporter}.\n *\n * No Next.js, no Redux, no Supabase, no router, no host error capture. If a\n * seam is missing, ADD A SEAM — never an import.\n */\n\nimport type { ReactNode } from \"react\";\nimport type { KindDefinition } from \"@ai-matrx/content-ir\";\nimport type { ContentIrErrorReporter } from \"./error-report\";\nimport type { ComponentResolutionSource } from \"../resolver/component-resolution.types\";\n\n/**\n * The minimum a render block must expose for the kind route to work. Hosts\n * pass their own richer block type through; the route is generic over `T` and\n * preserves every extra field.\n */\nexport interface IrRoutableBlock {\n type: string;\n serverData?: Record<string, unknown>;\n metadata?: Record<string, unknown>;\n}\n\n/** A routable block that also carries its source text (the raw region). */\nexport interface IrRenderBlock extends IrRoutableBlock {\n content: string;\n language?: string;\n}\n\n/**\n * Where registered kinds come from. `getDefinition` is the only method the\n * pure route needs; the rest drive the granular repaint and the warm-up tick\n * that keeps a cold registry from being mistaken for \"this kind has no\n * component\".\n */\nexport interface KindDefinitionSource {\n getDefinition(kind: string): KindDefinition | undefined;\n /** Monotonic per-kind version — the repaint snapshot key. */\n getKindVersion(kind: string): number;\n subscribeKind(kind: string, listener: () => void): () => void;\n /** One definition load per app session. */\n ensureWarm(): Promise<void>;\n}\n\n/**\n * The rendering seams. Everything here returns host UI; the package supplies\n * the DECISIONS and the chrome-free structure around them.\n */\nexport interface ContentIrRenderSeams {\n /**\n * Draw a block the kind route has already typed. This is the host's dispatch\n * table — the single place a component key becomes a component.\n */\n renderBlock(block: IrRenderBlock): ReactNode;\n /**\n * THE FLOOR: render ANY JSON value as a human document. Reached when a kind\n * has no render-trusted component, when the value is not an object at all,\n * and by the generic structured view.\n *\n * This is deliberately a seam and not a bundled component. Rendering a value\n * WELL means prose through the host's markdown renderer, media through the\n * host's file handler, and uniform arrays through the host's data table —\n * all of which are host property. A host that has none of those can pass a\n * `<pre>`; it will be honest, just plain.\n */\n renderValue(props: StructuredValueRenderProps): ReactNode;\n /**\n * The \"still arriving\" indicator used by the provisional frame. Optional —\n * hosts without a shimmer get plain text.\n */\n renderShimmer?(text: string): ReactNode;\n /**\n * The honest \"this shape has no custom component yet\" notice. Optional: the\n * package draws a plain amber line when a host supplies nothing, and a host\n * with an icon set or its own callout component supplies that instead. It is\n * a seam and not a bundled component because this package depends on no icon\n * library.\n */\n renderNotice?(text: string): ReactNode;\n}\n\nexport interface StructuredValueRenderProps {\n value: unknown;\n /** The kind slug this value claims, when known. Honesty line only — never a renderer choice. */\n kind?: string;\n /** Why this shape has no custom view, in human words. */\n note?: string;\n /** Show the \"what this is / raw data\" footer. Default true. */\n footer?: boolean;\n}\n\n/**\n * One host, wired once, read by every component in this package through\n * {@link ContentIrRenderProvider}.\n */\nexport interface ContentIrHost extends ContentIrRenderSeams {\n kinds: KindDefinitionSource;\n components: ComponentResolutionSource;\n reportError: ContentIrErrorReporter;\n /**\n * The `kind_component.platform` this host resolves as. \"web\" for every\n * browser UI; the column already models \"react-native\" and friends, and a\n * host that lies here renders the wrong component everywhere.\n */\n platform: string;\n}\n\n/**\n * The pure route's dependencies — a strict subset of {@link ContentIrHost},\n * because `applyIrKindRoute` is called OUTSIDE React (reducers, stream\n * accumulators, tests) where there is no provider to read.\n */\nexport interface KindRouteEnv {\n kinds: Pick<KindDefinitionSource, \"getDefinition\">;\n components: Pick<ComponentResolutionSource, \"resolve\">;\n reportError: ContentIrErrorReporter;\n platform: string;\n}\n\n/** Narrow a host (or anything host-shaped) to what the pure route needs. */\nexport function routeEnvOf(host: ContentIrHost): KindRouteEnv {\n return {\n kinds: host.kinds,\n components: host.components,\n reportError: host.reportError,\n platform: host.platform,\n };\n}\n","\"use client\";\n\n/**\n * The one place a host is wired in. Everything React in this package reads its\n * capability from here — no module singleton, no import into an app.\n *\n * A host mounts this ONCE, high enough that every kind-rendering surface is\n * inside it:\n *\n * ```tsx\n * <ContentIrRenderProvider host={matrxContentIrHost}>\n * <App />\n * </ContentIrRenderProvider>\n * ```\n *\n * Reading it outside a provider THROWS rather than falling back to a default.\n * A silent default would render the wrong component for every kind in the app\n * and look like a data problem for weeks.\n */\n\nimport { createContext, useContext, useMemo, type ReactNode } from \"react\";\nimport type { ContentIrHost, KindRouteEnv } from \"./host-types\";\nimport { routeEnvOf } from \"./host-types\";\n\nconst ContentIrHostContext = createContext<ContentIrHost | null>(null);\n\nexport interface ContentIrRenderProviderProps {\n host: ContentIrHost;\n children: ReactNode;\n}\n\nexport function ContentIrRenderProvider({\n host,\n children,\n}: ContentIrRenderProviderProps) {\n return (\n <ContentIrHostContext.Provider value={host}>\n {children}\n </ContentIrHostContext.Provider>\n );\n}\n\n/**\n * The wired host, or null. For the rare consumer that can legitimately run\n * without a provider because it was handed its sources explicitly (see\n * `useContentIrKindVersion`). Everything else uses {@link useContentIrHost}.\n */\nexport function useContentIrHostOrNull(): ContentIrHost | null {\n return useContext(ContentIrHostContext);\n}\n\n/** The wired host. Throws outside a provider — see the module doc. */\nexport function useContentIrHost(): ContentIrHost {\n const host = useContentIrHostOrNull();\n if (!host) {\n throw new Error(\n \"[content-ir-react] No ContentIrRenderProvider above this component. \" +\n \"Mount one at the app root with your host adapter (kind definitions, \" +\n \"component resolver, renderBlock, renderValue, reportError).\",\n );\n }\n return host;\n}\n\n/** The wired host narrowed to what the pure route functions take. */\nexport function useKindRouteEnv(): KindRouteEnv {\n const host = useContentIrHost();\n return useMemo(() => routeEnvOf(host), [host]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC2BO,IAAM,uBAA+C,CAAC,WAAW;AACtE,UAAQ,MAAM,gBAAgB,OAAO,OAAO,IAAI,OAAO,OAAO,EAAE;AAClE;;;AC2GO,SAAS,WAAW,MAAmC;AAC5D,SAAO;AAAA,IACL,OAAO,KAAK;AAAA,IACZ,YAAY,KAAK;AAAA,IACjB,aAAa,KAAK;AAAA,IAClB,UAAU,KAAK;AAAA,EACjB;AACF;;;AC3HA,mBAAmE;AAgB/D;AAZJ,IAAM,2BAAuB,4BAAoC,IAAI;AAO9D,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AACF,GAAiC;AAC/B,SACE,4CAAC,qBAAqB,UAArB,EAA8B,OAAO,MACnC,UACH;AAEJ;AAOO,SAAS,yBAA+C;AAC7D,aAAO,yBAAW,oBAAoB;AACxC;AAGO,SAAS,mBAAkC;AAChD,QAAM,OAAO,uBAAuB;AACpC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AACA,SAAO;AACT;AAGO,SAAS,kBAAgC;AAC9C,QAAM,OAAO,iBAAiB;AAC9B,aAAO,sBAAQ,MAAM,WAAW,IAAI,GAAG,CAAC,IAAI,CAAC;AAC/C;","names":[]}
|
package/dist/host.d.cts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { b as ContentIrErrorReport, a as ContentIrErrorReporter, c as consoleErrorReporter } from './component-resolution.types-BS1ySIg-.cjs';
|
|
2
|
+
import { C as ContentIrHost, K as KindRouteEnv } from './host-types-DvGv8s9L.cjs';
|
|
3
|
+
export { a as ContentIrRenderSeams, I as IrRenderBlock, b as IrRoutableBlock, c as KindDefinitionSource, S as StructuredValueRenderProps, r as routeEnvOf } from './host-types-DvGv8s9L.cjs';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { ReactNode } from 'react';
|
|
6
|
+
import '@ai-matrx/content-ir';
|
|
7
|
+
|
|
8
|
+
interface ContentIrRenderProviderProps {
|
|
9
|
+
host: ContentIrHost;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
declare function ContentIrRenderProvider({ host, children, }: ContentIrRenderProviderProps): React.JSX.Element;
|
|
13
|
+
/**
|
|
14
|
+
* The wired host, or null. For the rare consumer that can legitimately run
|
|
15
|
+
* without a provider because it was handed its sources explicitly (see
|
|
16
|
+
* `useContentIrKindVersion`). Everything else uses {@link useContentIrHost}.
|
|
17
|
+
*/
|
|
18
|
+
declare function useContentIrHostOrNull(): ContentIrHost | null;
|
|
19
|
+
/** The wired host. Throws outside a provider — see the module doc. */
|
|
20
|
+
declare function useContentIrHost(): ContentIrHost;
|
|
21
|
+
/** The wired host narrowed to what the pure route functions take. */
|
|
22
|
+
declare function useKindRouteEnv(): KindRouteEnv;
|
|
23
|
+
|
|
24
|
+
export { ContentIrHost, ContentIrRenderProvider, type ContentIrRenderProviderProps, KindRouteEnv, useContentIrHost, useContentIrHostOrNull, useKindRouteEnv };
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { b as ContentIrErrorReport, a as ContentIrErrorReporter, c as consoleErrorReporter } from './component-resolution.types-BS1ySIg-.js';
|
|
2
|
+
import { C as ContentIrHost, K as KindRouteEnv } from './host-types-CZ_Bkp4R.js';
|
|
3
|
+
export { a as ContentIrRenderSeams, I as IrRenderBlock, b as IrRoutableBlock, c as KindDefinitionSource, S as StructuredValueRenderProps, r as routeEnvOf } from './host-types-CZ_Bkp4R.js';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { ReactNode } from 'react';
|
|
6
|
+
import '@ai-matrx/content-ir';
|
|
7
|
+
|
|
8
|
+
interface ContentIrRenderProviderProps {
|
|
9
|
+
host: ContentIrHost;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
declare function ContentIrRenderProvider({ host, children, }: ContentIrRenderProviderProps): React.JSX.Element;
|
|
13
|
+
/**
|
|
14
|
+
* The wired host, or null. For the rare consumer that can legitimately run
|
|
15
|
+
* without a provider because it was handed its sources explicitly (see
|
|
16
|
+
* `useContentIrKindVersion`). Everything else uses {@link useContentIrHost}.
|
|
17
|
+
*/
|
|
18
|
+
declare function useContentIrHostOrNull(): ContentIrHost | null;
|
|
19
|
+
/** The wired host. Throws outside a provider — see the module doc. */
|
|
20
|
+
declare function useContentIrHost(): ContentIrHost;
|
|
21
|
+
/** The wired host narrowed to what the pure route functions take. */
|
|
22
|
+
declare function useKindRouteEnv(): KindRouteEnv;
|
|
23
|
+
|
|
24
|
+
export { ContentIrHost, ContentIrRenderProvider, type ContentIrRenderProviderProps, KindRouteEnv, useContentIrHost, useContentIrHostOrNull, useKindRouteEnv };
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// host/error-report.ts
|
|
4
|
+
var consoleErrorReporter = (report) => {
|
|
5
|
+
console.error(`[content-ir] ${report.message}`, report.raw ?? "");
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// host/host-types.ts
|
|
9
|
+
function routeEnvOf(host) {
|
|
10
|
+
return {
|
|
11
|
+
kinds: host.kinds,
|
|
12
|
+
components: host.components,
|
|
13
|
+
reportError: host.reportError,
|
|
14
|
+
platform: host.platform
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// host/ContentIrProvider.tsx
|
|
19
|
+
import { createContext, useContext, useMemo } from "react";
|
|
20
|
+
import { jsx } from "react/jsx-runtime";
|
|
21
|
+
var ContentIrHostContext = createContext(null);
|
|
22
|
+
function ContentIrRenderProvider({
|
|
23
|
+
host,
|
|
24
|
+
children
|
|
25
|
+
}) {
|
|
26
|
+
return /* @__PURE__ */ jsx(ContentIrHostContext.Provider, { value: host, children });
|
|
27
|
+
}
|
|
28
|
+
function useContentIrHostOrNull() {
|
|
29
|
+
return useContext(ContentIrHostContext);
|
|
30
|
+
}
|
|
31
|
+
function useContentIrHost() {
|
|
32
|
+
const host = useContentIrHostOrNull();
|
|
33
|
+
if (!host) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
"[content-ir-react] No ContentIrRenderProvider above this component. Mount one at the app root with your host adapter (kind definitions, component resolver, renderBlock, renderValue, reportError)."
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return host;
|
|
39
|
+
}
|
|
40
|
+
function useKindRouteEnv() {
|
|
41
|
+
const host = useContentIrHost();
|
|
42
|
+
return useMemo(() => routeEnvOf(host), [host]);
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
ContentIrRenderProvider,
|
|
46
|
+
consoleErrorReporter,
|
|
47
|
+
routeEnvOf,
|
|
48
|
+
useContentIrHost,
|
|
49
|
+
useContentIrHostOrNull,
|
|
50
|
+
useKindRouteEnv
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../host/error-report.ts","../host/host-types.ts","../host/ContentIrProvider.tsx"],"sourcesContent":["/**\n * THE SCREAM SEAM.\n *\n * Every recovery path in this package is loud: a defective component row, a\n * failed resolver load, a kind whose component throws on a provisional value.\n * The package refuses to own where those screams land — matrx-frontend routes\n * them to the Error Inspector, the dashboard to its own log, the extension to\n * its background page. Each host binds one function.\n *\n * A host that binds a no-op has chosen silence, which is a defect in itself;\n * {@link consoleErrorReporter} is the honest default.\n */\n\nexport interface ContentIrErrorReport {\n /** Always `\"content-ir\"` — hosts key their capture stores on it. */\n source: \"content-ir\";\n message: string;\n name?: string;\n stack?: string;\n /** Free-form grouping key (the host's `relation`), e.g. `\"partial-kind\"`. */\n relation?: string;\n raw?: unknown;\n}\n\nexport type ContentIrErrorReporter = (report: ContentIrErrorReport) => void;\n\n/** The default when a host binds nothing: never silent. */\nexport const consoleErrorReporter: ContentIrErrorReporter = (report) => {\n console.error(`[content-ir] ${report.message}`, report.raw ?? \"\");\n};\n","/**\n * THE HOST CONTRACT — everything this package refuses to decide.\n *\n * The kernel (`@ai-matrx/content-ir`) proved the shape: extract the portable\n * part, let host capability enter through explicit named seams. The render\n * layer needs four things it must never own:\n *\n * 1. WHERE KIND DEFINITIONS COME FROM (a bundled table, `content_ir`, a REST\n * call). The route only asks \"is this kind registered, and does it carry a\n * legacy bridge / a partial-ready opt-in\".\n * 2. WHERE COMPONENT ROWS COME FROM — {@link ComponentResolutionSource}. The\n * package ships `ComponentResolver`, which any host can construct with its\n * own loaders; a host with its own resolver only has to satisfy the type.\n * 3. HOW A ROUTED BLOCK ACTUALLY DRAWS. `applyIrKindRoute` decides a block's\n * TYPE; turning that type into pixels is the host's dispatch table\n * (matrx-frontend's `BlockRenderer`, the dashboard's small map). The\n * package never imports a component library.\n * 4. WHERE SCREAMS LAND — {@link ContentIrErrorReporter}.\n *\n * No Next.js, no Redux, no Supabase, no router, no host error capture. If a\n * seam is missing, ADD A SEAM — never an import.\n */\n\nimport type { ReactNode } from \"react\";\nimport type { KindDefinition } from \"@ai-matrx/content-ir\";\nimport type { ContentIrErrorReporter } from \"./error-report\";\nimport type { ComponentResolutionSource } from \"../resolver/component-resolution.types\";\n\n/**\n * The minimum a render block must expose for the kind route to work. Hosts\n * pass their own richer block type through; the route is generic over `T` and\n * preserves every extra field.\n */\nexport interface IrRoutableBlock {\n type: string;\n serverData?: Record<string, unknown>;\n metadata?: Record<string, unknown>;\n}\n\n/** A routable block that also carries its source text (the raw region). */\nexport interface IrRenderBlock extends IrRoutableBlock {\n content: string;\n language?: string;\n}\n\n/**\n * Where registered kinds come from. `getDefinition` is the only method the\n * pure route needs; the rest drive the granular repaint and the warm-up tick\n * that keeps a cold registry from being mistaken for \"this kind has no\n * component\".\n */\nexport interface KindDefinitionSource {\n getDefinition(kind: string): KindDefinition | undefined;\n /** Monotonic per-kind version — the repaint snapshot key. */\n getKindVersion(kind: string): number;\n subscribeKind(kind: string, listener: () => void): () => void;\n /** One definition load per app session. */\n ensureWarm(): Promise<void>;\n}\n\n/**\n * The rendering seams. Everything here returns host UI; the package supplies\n * the DECISIONS and the chrome-free structure around them.\n */\nexport interface ContentIrRenderSeams {\n /**\n * Draw a block the kind route has already typed. This is the host's dispatch\n * table — the single place a component key becomes a component.\n */\n renderBlock(block: IrRenderBlock): ReactNode;\n /**\n * THE FLOOR: render ANY JSON value as a human document. Reached when a kind\n * has no render-trusted component, when the value is not an object at all,\n * and by the generic structured view.\n *\n * This is deliberately a seam and not a bundled component. Rendering a value\n * WELL means prose through the host's markdown renderer, media through the\n * host's file handler, and uniform arrays through the host's data table —\n * all of which are host property. A host that has none of those can pass a\n * `<pre>`; it will be honest, just plain.\n */\n renderValue(props: StructuredValueRenderProps): ReactNode;\n /**\n * The \"still arriving\" indicator used by the provisional frame. Optional —\n * hosts without a shimmer get plain text.\n */\n renderShimmer?(text: string): ReactNode;\n /**\n * The honest \"this shape has no custom component yet\" notice. Optional: the\n * package draws a plain amber line when a host supplies nothing, and a host\n * with an icon set or its own callout component supplies that instead. It is\n * a seam and not a bundled component because this package depends on no icon\n * library.\n */\n renderNotice?(text: string): ReactNode;\n}\n\nexport interface StructuredValueRenderProps {\n value: unknown;\n /** The kind slug this value claims, when known. Honesty line only — never a renderer choice. */\n kind?: string;\n /** Why this shape has no custom view, in human words. */\n note?: string;\n /** Show the \"what this is / raw data\" footer. Default true. */\n footer?: boolean;\n}\n\n/**\n * One host, wired once, read by every component in this package through\n * {@link ContentIrRenderProvider}.\n */\nexport interface ContentIrHost extends ContentIrRenderSeams {\n kinds: KindDefinitionSource;\n components: ComponentResolutionSource;\n reportError: ContentIrErrorReporter;\n /**\n * The `kind_component.platform` this host resolves as. \"web\" for every\n * browser UI; the column already models \"react-native\" and friends, and a\n * host that lies here renders the wrong component everywhere.\n */\n platform: string;\n}\n\n/**\n * The pure route's dependencies — a strict subset of {@link ContentIrHost},\n * because `applyIrKindRoute` is called OUTSIDE React (reducers, stream\n * accumulators, tests) where there is no provider to read.\n */\nexport interface KindRouteEnv {\n kinds: Pick<KindDefinitionSource, \"getDefinition\">;\n components: Pick<ComponentResolutionSource, \"resolve\">;\n reportError: ContentIrErrorReporter;\n platform: string;\n}\n\n/** Narrow a host (or anything host-shaped) to what the pure route needs. */\nexport function routeEnvOf(host: ContentIrHost): KindRouteEnv {\n return {\n kinds: host.kinds,\n components: host.components,\n reportError: host.reportError,\n platform: host.platform,\n };\n}\n","\"use client\";\n\n/**\n * The one place a host is wired in. Everything React in this package reads its\n * capability from here — no module singleton, no import into an app.\n *\n * A host mounts this ONCE, high enough that every kind-rendering surface is\n * inside it:\n *\n * ```tsx\n * <ContentIrRenderProvider host={matrxContentIrHost}>\n * <App />\n * </ContentIrRenderProvider>\n * ```\n *\n * Reading it outside a provider THROWS rather than falling back to a default.\n * A silent default would render the wrong component for every kind in the app\n * and look like a data problem for weeks.\n */\n\nimport { createContext, useContext, useMemo, type ReactNode } from \"react\";\nimport type { ContentIrHost, KindRouteEnv } from \"./host-types\";\nimport { routeEnvOf } from \"./host-types\";\n\nconst ContentIrHostContext = createContext<ContentIrHost | null>(null);\n\nexport interface ContentIrRenderProviderProps {\n host: ContentIrHost;\n children: ReactNode;\n}\n\nexport function ContentIrRenderProvider({\n host,\n children,\n}: ContentIrRenderProviderProps) {\n return (\n <ContentIrHostContext.Provider value={host}>\n {children}\n </ContentIrHostContext.Provider>\n );\n}\n\n/**\n * The wired host, or null. For the rare consumer that can legitimately run\n * without a provider because it was handed its sources explicitly (see\n * `useContentIrKindVersion`). Everything else uses {@link useContentIrHost}.\n */\nexport function useContentIrHostOrNull(): ContentIrHost | null {\n return useContext(ContentIrHostContext);\n}\n\n/** The wired host. Throws outside a provider — see the module doc. */\nexport function useContentIrHost(): ContentIrHost {\n const host = useContentIrHostOrNull();\n if (!host) {\n throw new Error(\n \"[content-ir-react] No ContentIrRenderProvider above this component. \" +\n \"Mount one at the app root with your host adapter (kind definitions, \" +\n \"component resolver, renderBlock, renderValue, reportError).\",\n );\n }\n return host;\n}\n\n/** The wired host narrowed to what the pure route functions take. */\nexport function useKindRouteEnv(): KindRouteEnv {\n const host = useContentIrHost();\n return useMemo(() => routeEnvOf(host), [host]);\n}\n"],"mappings":";;;AA2BO,IAAM,uBAA+C,CAAC,WAAW;AACtE,UAAQ,MAAM,gBAAgB,OAAO,OAAO,IAAI,OAAO,OAAO,EAAE;AAClE;;;AC2GO,SAAS,WAAW,MAAmC;AAC5D,SAAO;AAAA,IACL,OAAO,KAAK;AAAA,IACZ,YAAY,KAAK;AAAA,IACjB,aAAa,KAAK;AAAA,IAClB,UAAU,KAAK;AAAA,EACjB;AACF;;;AC3HA,SAAS,eAAe,YAAY,eAA+B;AAgB/D;AAZJ,IAAM,uBAAuB,cAAoC,IAAI;AAO9D,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AACF,GAAiC;AAC/B,SACE,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,MACnC,UACH;AAEJ;AAOO,SAAS,yBAA+C;AAC7D,SAAO,WAAW,oBAAoB;AACxC;AAGO,SAAS,mBAAkC;AAChD,QAAM,OAAO,uBAAuB;AACpC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AACA,SAAO;AACT;AAGO,SAAS,kBAAgC;AAC9C,QAAM,OAAO,iBAAiB;AAC9B,SAAO,QAAQ,MAAM,WAAW,IAAI,GAAG,CAAC,IAAI,CAAC;AAC/C;","names":[]}
|