@peripheries/renderer 0.29.0 → 0.31.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 CHANGED
@@ -56,6 +56,15 @@ const runtime = await loadPageData(page, source, { params, baseProps, viewer, co
56
56
  small "hidden (empty)" placeholder instead of nothing.
57
57
  - `showProblemCodes`: a cell's problem notice adds its diagnostic code, for
58
58
  staff and editors; without it a viewer reads only the plain wording.
59
+ - `mockCell(cellId)`: a design preview's stand-in for a cell. It returns
60
+ `{ props?, data? }`: the props are merged over the cell's resolved ones, and
61
+ `data` becomes its whole data bundle, settled (`isLoading: false`, no error).
62
+ `context` and `style` are never the mock's to set. A cell it returns nothing
63
+ for is drawn as the page has it; the page's own reads still run. It is read
64
+ only in a Vite build made with `VITE_PREVIEW=true` (the host's preview
65
+ build): a production build replaces the flag with `false` and drops the
66
+ code, so it adds no bytes to what a phone loads (a build without
67
+ `import.meta.env` ignores it too).
59
68
 
60
69
  A consumer with resolved values instead of a graph (the component repos'
61
70
  harness) builds its runtime with `pageRuntimeFromValues(page, { values,
@@ -137,25 +137,19 @@ function loadChunked(row, files, plan, wanted) {
137
137
  const doImport = files.import ?? browserImport;
138
138
  const asked = row.components.filter((c) => c.component_name && (wanted === "all" || wanted.has(c.component_name)));
139
139
  const inPlan = asked.every((c) => Object.hasOwn(plan.entries, exportOf(c)));
140
- const manifestUrl = `${plan.base}manifest.json`;
141
140
  let manifest = null;
142
- if (wanted === "all" || !inPlan) {
143
- let m = manifests.get(manifestUrl);
144
- if (!m) {
145
- m = get(manifestUrl).then(async (r) => {
146
- const parsed = r.ok ? parseComponentManifest(await r.json().catch(() => null)) : null;
147
- if (!parsed) throw new Error(`[bundles] ${row.org_slug}/${row.bundle_name}: manifest.json is not readable`);
148
- return parsed;
149
- });
150
- m.catch(() => manifests.delete(manifestUrl));
151
- manifests.set(manifestUrl, m);
152
- }
153
- manifest = await m;
154
- }
141
+ if (wanted === "all" || !inPlan) manifest = await manifestOf(row, plan, get);
155
142
  const fileOf = (name) => plan.entries[name] ?? manifest?.components[name]?.js;
156
143
  const exportsWanted = [...new Set([...asked.map(exportOf), ...wanted === "all" && manifest ? BUNDLE_LEVEL_EXPORTS.filter((n) => manifest.components[n]) : []])].filter((n) => fileOf(n));
157
144
  const css = new Set();
158
145
  for (const n of exportsWanted) for (const f of manifest?.components[n]?.css ?? (plan.entries[n] ? plan.css : [])) css.add(f);
146
+ const closure = new Set();
147
+ for (const n of exportsWanted) {
148
+ const m = manifest?.components[n];
149
+ if (m) for (const f of [m.js, ...m.imports ?? []]) closure.add(f);
150
+ }
151
+ if (closure.size) files.preload?.([...closure].map((f) => `${plan.base}${f}`));
152
+ if (css.size) files.linkStyles?.([...css].map((f) => `${plan.base}${f}`));
159
153
  const contractsUrl = `${plan.base}contracts.json`;
160
154
  let contractsP = contractsOf.get(contractsUrl);
161
155
  if (!contractsP) {
@@ -173,7 +167,6 @@ function loadChunked(row, files, plan, wanted) {
173
167
  return [n, (await m)[n]];
174
168
  });
175
169
  const [loaded, contracts] = await Promise.all([Promise.all(imports), contractsP]);
176
- if (css.size) files.linkStyles?.([...css].map((f) => `${plan.base}${f}`));
177
170
  return projectModule(row, Object.fromEntries(loaded), contracts);
178
171
  })();
179
172
  pending.catch(() => chunkedBundles.delete(key));
@@ -181,6 +174,25 @@ function loadChunked(row, files, plan, wanted) {
181
174
  }
182
175
  return pending;
183
176
  }
177
+ function manifestOf(row, plan, get) {
178
+ const manifestUrl = `${plan.base}manifest.json`;
179
+ let m = manifests.get(manifestUrl);
180
+ if (!m) {
181
+ m = get(manifestUrl).then(async (r) => {
182
+ const parsed = r.ok ? parseComponentManifest(await r.json().catch(() => null)) : null;
183
+ if (!parsed) throw new Error(`[bundles] ${row.org_slug}/${row.bundle_name}: manifest.json is not readable`);
184
+ return parsed;
185
+ });
186
+ m.catch(() => manifests.delete(manifestUrl));
187
+ manifests.set(manifestUrl, m);
188
+ }
189
+ return m;
190
+ }
191
+ function warmChunkManifest(row, files) {
192
+ const plan = row.specifier ? files.chunkPlan?.(row.specifier) : null;
193
+ if (!plan) return;
194
+ manifestOf(row, plan, files.fetch ?? ((u) => fetch(u))).catch(() => void 0);
195
+ }
184
196
  var requiresOf = (row, files) => row.requires ?? (row.specifier && files.chunkPlan?.(row.specifier) ? row.specifier === "@stack/core" ? [] : ["@stack/core"] : void 0);
185
197
  var escapeRe = (v) => v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
186
198
  async function sharedDependencies(rows, files) {
@@ -274,4 +286,4 @@ function _clearBundleCache() {
274
286
  manifests.clear();
275
287
  contractsOf.clear();
276
288
  }
277
- export { loadBundlesSettled as a, chunkPlan as c, loadBundles as i, parseChunkPlans as l, isComponentExport as n, projectModule as o, loadBundle as r, runtimeReady as s, _clearBundleCache as t, parseComponentManifest as u };
289
+ export { loadBundlesSettled as a, warmChunkManifest as c, parseComponentManifest as d, loadBundles as i, chunkPlan as l, isComponentExport as n, projectModule as o, loadBundle as r, runtimeReady as s, _clearBundleCache as t, parseChunkPlans as u };
package/dist/core.js CHANGED
@@ -2,7 +2,7 @@ import { A as rootCells, C as CONTENT_FIELDS, D as hasRef, E as STORE_FIELDS, O
2
2
  import { C as passesConditions, S as pageContext, T as settled, _ as EACH, a as VARIABLE_NAMESPACES, b as cellResolutionContext, c as pageVariables, d as resolveDescriptorVariables, f as selectionShape, g as variableReferences, h as variableLabels, i as UnsafeDocumentError, l as prepareDocument, m as validateDescriptor, n as RENDER_FUNCTIONS, o as descriptorShape, p as shapeAt, r as RENDER_FUNCTIONS_AHEAD, s as orderByVariable, t as PAGING_VARIABLES, u as queryKey, v as EACH_DEFAULT_AS, w as resolveReferences, x as isEach, y as cellContext } from "./chunks/query-D_f73wsU.js";
3
3
  import { S as walkRequest, _ as stateNames, a as eachFormProblems, b as systemsFromProcess, c as validatePage, d as mergeStates, f as needsWalk, g as resolveWalkStart, h as referencedLabels, i as componentsFor, l as selectionIssues, m as readWalk, n as STORE_SCOPES, o as nearestNames, p as readField, r as WALK_DIRECTIONS, s as validateCell, t as RESPONSIVE_BUCKETS, u as RESERVED_LABELS, v as stateValue, x as walkKey, y as systemsFromGraphs } from "./chunks/validate-BfXuQLmV.js";
4
4
  import { C as actionReferences, D as resolveAction, E as projectCellActions, S as actionProblems, T as normalizeActionDeclaration, _ as HOST_READ_KEY, a as deriveSectionReferences, b as isHostRead, c as nodePrintStyle, d as referencesFor, f as sectionAnchor, g as usesStructureLayout, h as tableOfContents, i as deriveSectionNumbering, l as normalizeStructure, m as structureIssues, n as SECTION_KINDS, r as deriveElementReferences, s as mergeSectionReferences, t as PAGE_DOCUMENT, u as numberingFor, v as bindHostReads, w as declaredActions, x as actionBindingKey, y as hostReadProblem } from "./chunks/structure-Ds2wfhkH.js";
5
- import { a as loadBundlesSettled, c as chunkPlan, i as loadBundles, l as parseChunkPlans, n as isComponentExport, o as projectModule, r as loadBundle, s as runtimeReady, t as _clearBundleCache, u as parseComponentManifest } from "./chunks/load-CAus-wv_.js";
5
+ import { a as loadBundlesSettled, c as warmChunkManifest, d as parseComponentManifest, i as loadBundles, l as chunkPlan, n as isComponentExport, o as projectModule, r as loadBundle, s as runtimeReady, t as _clearBundleCache, u as parseChunkPlans } from "./chunks/load-BU9C8x6-.js";
6
6
  import { a as normalizeRef, i as bundleScope, n as MAIN, o as refKey, r as PUBLIC, t as CORE_SPECIFIER } from "./chunks/refs-Csgh6rXq.js";
7
7
  import { a as rowsInScope, i as rowForCell, n as pageBundleRefs, o as rowsNeededBy, r as pageBundles, t as componentNames } from "./chunks/page-bundles-dUYH4D73.js";
8
8
  import { a as createStackStore, i as saveScope, n as clearScope, r as loadScope } from "./chunks/persistence-hurkUUQ0.js";
@@ -1184,4 +1184,4 @@ function manifestPageFrom(graphNodeId, data) {
1184
1184
  }
1185
1185
  };
1186
1186
  }
1187
- export { CONTENT_FIELDS, CORE_SPECIFIER, DIAGNOSTICS, EACH, EACH_DEFAULT_AS, HOST_READ_KEY, HYDRATED_CELL_FIELDS, LAYER_ROLES, LAYOUT_TYPES, MAIN, PAGE_DOCUMENT, PAGE_RULES, PAGING_VARIABLES, PUBLIC, RENDER_FIELDS, RENDER_FUNCTIONS, RENDER_FUNCTIONS_AHEAD, RESERVED_LABELS, RESPONSIVE_BUCKETS, SECTION_KINDS, STORE_FIELDS, STORE_SCOPES, STRUCTURE_FIELDS, TOOL_OWNED_KEYS, UnsafeDocumentError, VARIABLE_NAMESPACES, WALK_DIRECTIONS, _clearBundleCache, actionBindingKey, actionProblems, actionReferences, assembleCellProps, attachSelectionSetters, attachViewStateSetters, bindHostReads, buildDataContext, bundleScope, cellAttributes, cellContext, cellPlacementStyle, cellPropSources, cellResolutionContext, chunkPlan, clearScope, collectDeclarations, collectDescriptors, collectScopeIds, collectStatic, componentNames, componentsFor, createStackStore, declaredActions, deriveElementReferences, deriveSectionNumbering, deriveSectionReferences, descriptorShape, eachFormProblems, editTarget, hasRef, hiddenWhenEmpty, hideWhenEmptyProblem, hostReadProblem, isComponentExport, isEach, isEmptyPropValue, isHostRead, layerName, loadBundle, loadBundles, loadBundlesSettled, loadPageData, loadScope, manifestPageFrom, mergeSectionReferences, mergeStates, nearestNames, needsWalk, nodePrintStyle, normalizeActionDeclaration, normalizeCell, normalizeRef, normalizeStructure, numberingFor, orderByVariable, pageBundleRefs, pageBundles, pageContainerStyle, pageContext, pageForCell, pageRuntimeFromValues, pageScopeKey, pageVariables, parseChunkPlans, parseComponentManifest, passesConditions, patchAt, prepareDocument, projectCellActions, projectCellData, projectLive, projectModule, projectScopeKey, projectSelections, projectViewState, queryKey, readField, readWalk, refKey, referencedLabels, referencesFor, resolveAction, resolveCell, resolveComponent, resolveDataSystem, resolveDeclarations, resolveDescriptorVariables, resolveReferences, resolveScopeId, resolveSystems, resolveWalkStart, rootCells, rowForCell, rowsInScope, rowsNeededBy, runtimeReady, saveScope, sectionAnchor, selectionIssues, selectionShape, settled, shallowEqualBundle, shapeAt, stateNames, stateValue, structureIssues, systemsFromGraphs, systemsFromProcess, tableOfContents, usesStructureLayout, validateCell, validateDescriptor, validateManifest, validatePage, variableLabels, variableReferences, walkKey, walkRequest };
1187
+ export { CONTENT_FIELDS, CORE_SPECIFIER, DIAGNOSTICS, EACH, EACH_DEFAULT_AS, HOST_READ_KEY, HYDRATED_CELL_FIELDS, LAYER_ROLES, LAYOUT_TYPES, MAIN, PAGE_DOCUMENT, PAGE_RULES, PAGING_VARIABLES, PUBLIC, RENDER_FIELDS, RENDER_FUNCTIONS, RENDER_FUNCTIONS_AHEAD, RESERVED_LABELS, RESPONSIVE_BUCKETS, SECTION_KINDS, STORE_FIELDS, STORE_SCOPES, STRUCTURE_FIELDS, TOOL_OWNED_KEYS, UnsafeDocumentError, VARIABLE_NAMESPACES, WALK_DIRECTIONS, _clearBundleCache, actionBindingKey, actionProblems, actionReferences, assembleCellProps, attachSelectionSetters, attachViewStateSetters, bindHostReads, buildDataContext, bundleScope, cellAttributes, cellContext, cellPlacementStyle, cellPropSources, cellResolutionContext, chunkPlan, clearScope, collectDeclarations, collectDescriptors, collectScopeIds, collectStatic, componentNames, componentsFor, createStackStore, declaredActions, deriveElementReferences, deriveSectionNumbering, deriveSectionReferences, descriptorShape, eachFormProblems, editTarget, hasRef, hiddenWhenEmpty, hideWhenEmptyProblem, hostReadProblem, isComponentExport, isEach, isEmptyPropValue, isHostRead, layerName, loadBundle, loadBundles, loadBundlesSettled, loadPageData, loadScope, manifestPageFrom, mergeSectionReferences, mergeStates, nearestNames, needsWalk, nodePrintStyle, normalizeActionDeclaration, normalizeCell, normalizeRef, normalizeStructure, numberingFor, orderByVariable, pageBundleRefs, pageBundles, pageContainerStyle, pageContext, pageForCell, pageRuntimeFromValues, pageScopeKey, pageVariables, parseChunkPlans, parseComponentManifest, passesConditions, patchAt, prepareDocument, projectCellActions, projectCellData, projectLive, projectModule, projectScopeKey, projectSelections, projectViewState, queryKey, readField, readWalk, refKey, referencedLabels, referencesFor, resolveAction, resolveCell, resolveComponent, resolveDataSystem, resolveDeclarations, resolveDescriptorVariables, resolveReferences, resolveScopeId, resolveSystems, resolveWalkStart, rootCells, rowForCell, rowsInScope, rowsNeededBy, runtimeReady, saveScope, sectionAnchor, selectionIssues, selectionShape, settled, shallowEqualBundle, shapeAt, stateNames, stateValue, structureIssues, systemsFromGraphs, systemsFromProcess, tableOfContents, usesStructureLayout, validateCell, validateDescriptor, validateManifest, validatePage, variableLabels, variableReferences, walkKey, walkRequest, warmChunkManifest };
package/dist/runtime.js CHANGED
@@ -1,4 +1,4 @@
1
- import { s as runtimeReady } from "./chunks/load-CAus-wv_.js";
1
+ import { s as runtimeReady } from "./chunks/load-BU9C8x6-.js";
2
2
  import { a as createStackStore, t as clearAllScopes } from "./chunks/persistence-hurkUUQ0.js";
3
3
  import { PINNED_RUNTIMES, READY_GLOBAL, RESOLVE_GLOBAL, RUNTIME_GLOBAL, buildImportMap } from "@peripheries/runtime";
4
4
  import * as React from "react";
package/dist/testing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { l as prepareDocument } from "./chunks/query-D_f73wsU.js";
2
- import { o as projectModule } from "./chunks/load-CAus-wv_.js";
2
+ import { o as projectModule } from "./chunks/load-BU9C8x6-.js";
3
3
  import { i as bundleScope } from "./chunks/refs-Csgh6rXq.js";
4
4
  import { n as pageBundleRefs, r as pageBundles } from "./chunks/page-bundles-dUYH4D73.js";
5
5
  import { r as fromPageSteps } from "./chunks/forms-DxA9WzCt.js";
@@ -33,9 +33,11 @@ export type BundleFiles = {
33
33
  fetch?: (url: string) => Promise<Response>;
34
34
  chunkPlan?: (specifier: string) => ChunkPlan | null;
35
35
  linkStyles?: (urls: string[]) => void;
36
+ preload?: (urls: string[]) => void;
36
37
  };
37
38
  export declare function runtimeReady(g?: Record<string, unknown>): Promise<void>;
38
39
  export declare function loadBundle(row: BundleRow, files: BundleFiles, wanted?: ReadonlySet<string> | 'all'): Promise<LoadedBundle>;
40
+ export declare function warmChunkManifest(row: BundleRow, files: Pick<BundleFiles, 'chunkPlan' | 'fetch'>): void;
39
41
  export type LoadedBundles = {
40
42
  loaded: LoadedBundle[];
41
43
  failed: string[];
@@ -12,6 +12,10 @@ export declare function failedLabels(cell: PageCell, data: DataContext): string[
12
12
  export declare function isEmptyPropValue(value: unknown): boolean;
13
13
  export declare function hideWhenEmptyProblem(cell: Pick<PageCell, 'hide_when_empty' | 'props'>, data: DataContext): 'QUERY_UNRESOLVED' | null;
14
14
  export declare function hiddenWhenEmpty(cell: Pick<PageCell, 'hide_when_empty' | 'props'>, props: Record<string, unknown>, data: DataContext): boolean;
15
+ export type CellMock = {
16
+ props?: Record<string, unknown>;
17
+ data?: unknown;
18
+ };
15
19
  export type AssembledInputs = {
16
20
  resolvedProps: Record<string, unknown>;
17
21
  children: unknown;
@@ -34,5 +38,6 @@ export type AssembledInputs = {
34
38
  navigate: (to: string) => void;
35
39
  context: Record<string, unknown>;
36
40
  renderComponent?: (key: string, props?: Record<string, unknown>) => unknown;
41
+ mock?: CellMock;
37
42
  };
38
43
  export declare function assembleCellProps(i: AssembledInputs): Record<string, unknown>;
@@ -16,10 +16,10 @@ export { pageRuntimeFromValues } from './values.js';
16
16
  export { actionBindingKey, actionProblems, actionReferences, declaredActions, normalizeActionDeclaration, projectCellActions, resolveAction, type RunAction } from './actions.js';
17
17
  export type { ActionDeclaration } from '@peripheries/runtime';
18
18
  export type * from './types.js';
19
- export { assembleCellProps, hiddenWhenEmpty, hideWhenEmptyProblem, isEmptyPropValue, projectCellData, type CellStatus } from './cell-props.js';
19
+ export { assembleCellProps, hiddenWhenEmpty, hideWhenEmptyProblem, isEmptyPropValue, projectCellData, type CellMock, type CellStatus } from './cell-props.js';
20
20
  export { cellAttributes, cellPlacementStyle, pageContainerStyle } from './layout.js';
21
21
  export { deriveElementReferences, deriveSectionNumbering, deriveSectionReferences, mergeSectionReferences, nodePrintStyle, normalizeStructure, numberingFor, PAGE_DOCUMENT, referencesFor, SECTION_KINDS, sectionAnchor, structureIssues, tableOfContents, usesStructureLayout, type ContentsEntry, type LayoutNode, type SectionNumbering, type SectionReference, type SectionReferences, } from './structure.js';
22
- export { _clearBundleCache, isComponentExport, loadBundle, loadBundles, loadBundlesSettled, projectModule, runtimeReady, type BundleFiles, type BundleRow, type LoadedBundle, type LoadedBundles, } from './bundles/load.js';
22
+ export { _clearBundleCache, isComponentExport, loadBundle, loadBundles, loadBundlesSettled, projectModule, runtimeReady, warmChunkManifest, type BundleFiles, type BundleRow, type LoadedBundle, type LoadedBundles, } from './bundles/load.js';
23
23
  export { chunkPlan, parseChunkPlans, parseComponentManifest, type ChunkPlan, type ComponentManifest, type ManifestComponent } from './bundles/component-manifest.js';
24
24
  export { componentNames, pageBundleRefs, pageBundles, rowForCell, rowsInScope, rowsNeededBy, type PageBundles } from './bundles/page-bundles.js';
25
25
  export { bundleScope, CORE_SPECIFIER, MAIN, normalizeRef, PUBLIC, refKey, type BundleRef, type BundleScopeInput, type LineageRef, type SharedLineage } from './bundles/refs.js';
@@ -4,6 +4,7 @@ import type { LoadedBundle } from '../core/bundles/load.js';
4
4
  import type { Diagnostic } from '../core/graph.js';
5
5
  import { type CoreRegistry } from '../core/bundles/resolve.js';
6
6
  import { type RunAction } from '../core/actions.js';
7
+ import { type CellMock } from '../core/cell-props.js';
7
8
  import { type HostReads } from '../core/host-reads.js';
8
9
  import type { CellData } from '../core/load-page.js';
9
10
  import { type ResolutionContext } from '../core/references.js';
@@ -44,6 +45,7 @@ export type CellEnvironment = {
44
45
  cellProps?: (cell: PageCell) => Record<string, unknown> | undefined;
45
46
  showHiddenCells?: boolean;
46
47
  showProblemCodes?: boolean;
48
+ mockCell?: (cellId: string) => CellMock | undefined;
47
49
  };
48
50
  export type FrameProps = {
49
51
  attributes?: Record<string, string>;
@@ -1,6 +1,7 @@
1
1
  import type { CellAction, ComponentContract } from '@peripheries/runtime';
2
2
  import type { RunAction } from '../core/actions.js';
3
3
  import type { PageBundles } from '../core/bundles/page-bundles.js';
4
+ import type { CellMock } from '../core/cell-props.js';
4
5
  import type { CoreRegistry } from '../core/bundles/resolve.js';
5
6
  import type { HostReads } from '../core/host-reads.js';
6
7
  import type { Diagnostic } from '../core/graph.js';
@@ -27,6 +28,7 @@ export type RendererEnvironment = {
27
28
  cellProps?: (cell: PageCell) => Record<string, unknown> | undefined;
28
29
  showHiddenCells?: boolean;
29
30
  showProblemCodes?: boolean;
31
+ mockCell?: (cellId: string) => CellMock | undefined;
30
32
  };
31
33
  export type PageRendererProps = {
32
34
  runtime: PageRuntime;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peripheries/renderer",
3
- "version": "0.29.0",
3
+ "version": "0.31.0",
4
4
  "description": "The one renderer for pages of federated component bundles: a framework-free core, a React renderer, the runtime a page boots with, and golden pages for testing.",
5
5
  "type": "module",
6
6
  "sideEffects": [