{"version":3,"sources":["../host/ContentIrProvider.tsx","../host/host-types.ts"],"sourcesContent":["\"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\";\nimport { DirectiveHostProvider } from \"../react-directives/directive-host\";\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      <DirectiveHostProvider host={host.directives ?? {}}>{children}</DirectiveHostProvider>\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","/**\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 \"../registry\";\nimport type { ContentIrErrorReporter } from \"./error-report\";\nimport type { ComponentResolutionSource } from \"../resolver/component-resolution.types\";\nimport type { DirectiveHost } from \"../react-directives/directive-host\";\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   * The Kind Directives seams (apply / open item / copy / noun catalog / item\n   * kind). Optional: a host without them still renders every directive card,\n   * apply-less and copy-less — honest chrome, never hidden content. Provided\n   * to the directive tier by `ContentIrRenderProvider`; a host that has not\n   * adopted the render provider mounts `DirectiveHostProvider` directly.\n   */\n  directives?: DirectiveHost;\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  /**\n   * `schemaState` is optional and read ONLY to suppress a negative verdict while this kind's\n   * definition read has not answered (\"pending\") — THE COLD-VERDICT RULE, per kind.\n   */\n  kinds: Pick<KindDefinitionSource, \"getDefinition\"> & {\n    schemaState?(kind: string): \"loaded\" | \"pending\" | \"absent\" | \"failed\";\n  };\n  /**\n   * `hasSettled` is optional and read ONLY to suppress a negative verdict from\n   * a registry that has not loaded yet — see THE COLD-VERDICT RULE on\n   * `ComponentResolutionSource`.\n   */\n  components: Pick<ComponentResolutionSource, \"resolve\"> &\n    Partial<Pick<ComponentResolutionSource, \"hasSettled\" | \"hasSettledFor\">>;\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBA,mBAAmE;;;ACyI5D,SAAS,WAAW,MAAmC;AAC5D,SAAO;AAAA,IACL,OAAO,KAAK;AAAA,IACZ,YAAY,KAAK;AAAA,IACjB,aAAa,KAAK;AAAA,IAClB,UAAU,KAAK;AAAA,EACjB;AACF;;;AD7IA,4BAAsC;AAehC;AAbN,IAAM,2BAAuB,4BAAoC,IAAI;AAO9D,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AACF,GAAiC;AAC/B,SACE,4CAAC,qBAAqB,UAArB,EAA8B,OAAO,MACpC,sDAAC,+CAAsB,MAAM,KAAK,cAAc,CAAC,GAAI,UAAS,GAChE;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":[]}