@jay-framework/compiler-jay-html 0.13.0 → 0.15.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.
Files changed (3) hide show
  1. package/dist/index.d.cts +71 -3
  2. package/dist/index.js +16551 -14186
  3. package/package.json +10 -10
package/dist/index.d.cts CHANGED
@@ -31,9 +31,11 @@ interface ContractProp {
31
31
  description?: Array<string>;
32
32
  default?: string;
33
33
  }
34
- /** URL/load params for a page (e.g. [slug]). Always string in generated type (UrlParams = Record<string, string>). Design Log #85. */
34
+ type ContractParamKind = 'required' | 'optional' | 'catch-all';
35
+ /** URL/load params for a page (e.g. [slug]). Design Log #85, #113. */
35
36
  interface ContractParam {
36
37
  name: string;
38
+ kind: ContractParamKind;
37
39
  }
38
40
  interface Contract {
39
41
  name: string;
@@ -80,7 +82,7 @@ interface JayImportResolver {
80
82
  /**
81
83
  * Load a contract from a plugin, handling both static and dynamic contracts.
82
84
  * For static contracts, loads from the plugin's contract file.
83
- * For dynamic contracts, loads from materialized location (build/materialized-contracts/).
85
+ * For dynamic contracts, loads from materialized location (agent-kit/materialized-contracts/).
84
86
  *
85
87
  * Returns the contract, path, and optional metadata (for dynamic contracts).
86
88
  */
@@ -90,6 +92,13 @@ interface JayImportResolver {
90
92
  metadata?: Record<string, unknown>;
91
93
  }>;
92
94
  resolvePluginManifest(pluginName: string, projectRoot: string): WithValidations<PluginManifest>;
95
+ /**
96
+ * Read a jay-html file adjacent to a component module.
97
+ * Given a module src path (e.g., "./header/header"), resolves to the absolute path
98
+ * and reads the corresponding .jay-html file (same base name + .jay-html extension).
99
+ * Returns the file content string, or null if not found.
100
+ */
101
+ readJayHtml(importingModuleDir: string, src: string): string | null;
93
102
  }
94
103
  declare const JAY_IMPORT_RESOLVER: JayImportResolver;
95
104
 
@@ -195,10 +204,69 @@ interface JayHtmlSourceFile extends CompilerSourceFile {
195
204
  declare function generateElementDefinitionFile(parsedFile: WithValidations<JayHtmlSourceFile>): WithValidations<string>;
196
205
  declare function generateElementFile(jayFile: JayHtmlSourceFile, importerMode: MainRuntimeModes): WithValidations<string>;
197
206
  declare function generateElementBridgeFile(jayFile: JayHtmlSourceFile): string;
207
+ declare function generateElementHydrateFile(jayFile: JayHtmlSourceFile, importerMode: MainRuntimeModes): WithValidations<string>;
208
+ interface ServerElementOptions {
209
+ /** Path to write debug coordinate pre-process output. When provided, the
210
+ * serialized DOM with jay-coordinate-base attributes is returned via result. */
211
+ debugCoordinatePreprocessPath?: string;
212
+ }
213
+ declare function generateServerElementFile(jayFile: JayHtmlSourceFile, _options?: ServerElementOptions): WithValidations<string>;
198
214
  declare function generateSandboxRootFile(jayFile: JayHtmlSourceFile): string;
199
215
 
200
216
  declare function generateElementFileReactTarget(jayFile: JayHtmlSourceFile, importerMode: MainRuntimeModes): WithValidations<string>;
201
217
 
218
+ /**
219
+ * Coordinate pre-processing for SSR/hydration consistency.
220
+ *
221
+ * Assigns `jay-coordinate-base` attributes to all elements that need coordinates,
222
+ * in a single pass before either server or hydrate compilation runs.
223
+ * Both compilers read this attribute instead of computing coordinates independently.
224
+ *
225
+ * See Design Log #103, #106.
226
+ */
227
+
228
+ interface AssignCoordinatesOptions {
229
+ /** Set of headless contract names (for detecting <jay:xxx> tags) */
230
+ headlessContractNames: Set<string>;
231
+ /** @internal Auto-generated ref counters for headless instances without explicit refs.
232
+ * Created automatically if not provided. */
233
+ _refCounters?: Map<string, number>;
234
+ }
235
+ interface AssignCoordinatesResult {
236
+ /** Serialized DOM with jay-coordinate-base attributes, for debug output */
237
+ debugHtml: string;
238
+ }
239
+ /**
240
+ * Assign coordinates to a full jay-html string and return the result.
241
+ * Used by the pre-render pipeline so discoverHeadlessInstances gets elements
242
+ * with jay-coordinate-base, matching the hydrate compiler's coordinate format.
243
+ */
244
+ declare function assignCoordinatesToJayHtml(jayHtml: string, headlessContractNames: Set<string>): string;
245
+ /**
246
+ * Assign `jay-coordinate-base` attributes to elements in the DOM tree.
247
+ *
248
+ * Must run after slow-render (which resolves slow conditions, unrolls slowForEach,
249
+ * and wraps multi-child headless inline templates).
250
+ *
251
+ * Mutates the DOM in place. Returns the serialized DOM for debug output.
252
+ */
253
+ declare function assignCoordinates(body: HTMLElement, options: AssignCoordinatesOptions): AssignCoordinatesResult;
254
+
255
+ /**
256
+ * Inject headfull full-stack component templates into jay-html.
257
+ * Finds <script type="application/jay-headfull" contract="..."> tags,
258
+ * reads each component's jay-html file, and injects the body content
259
+ * into matching <jay:Name> tags that are empty/self-closing.
260
+ *
261
+ * This must be called on the raw HTML string BEFORE the slow render pipeline,
262
+ * so that instance bindings can be resolved during pre-rendering.
263
+ *
264
+ * @param html - The raw jay-html content
265
+ * @param sourceDir - Absolute path to the directory containing the jay-html file
266
+ * @param importResolver - Resolver for reading component jay-html files
267
+ * @returns The HTML with headfull FS templates injected (or unchanged if none found)
268
+ */
269
+ declare function injectHeadfullFSTemplates(html: string, sourceDir: string, importResolver: JayImportResolver): string;
202
270
  declare function parseJayFile(html: string, filename: string, filePath: string, options: ResolveTsConfigOptions, linkedContractResolver: JayImportResolver, projectRoot: string): Promise<WithValidations<JayHtmlSourceFile>>;
203
271
  declare function getJayHtmlImports(html: string): string[];
204
272
 
@@ -385,4 +453,4 @@ declare function resolveHeadlessInstances(preRenderedJayHtml: string, instanceDa
385
453
  */
386
454
  declare function hasSlowPhaseProperties(contract: Contract | undefined): boolean;
387
455
 
388
- export { type ActionDefinition, type Contract, type ContractImportInfo, type ContractParam, type ContractProp, type ContractResolver, type ContractTag, ContractTagType, type DiscoveredHeadlessInstance, type EnumToImport, type ForEachHeadlessInstance, type HeadlessContractInfo, type HeadlessInstanceDiscoveryResult, type HeadlessInstanceResolvedData, JAY_IMPORT_RESOLVER, type JayContractImportLink, type JayHtmlSourceFile, type JayImportResolver, type PhaseViewStates, type RenderingPhase, type SlowRenderInput, type SlowRenderOutput, buildInstanceCoordinateKey, compileAction, compileContract, contractToAllPhaseViewStates, contractToImportsViewStateAndRefs, contractToPhaseViewState, createPhaseContract, defaultContractResolver, discoverHeadlessInstances, filterTagsByPhase, generateElementBridgeFile, generateElementDefinitionFile, generateElementFile, generateElementFileReactTarget, generateSandboxRootFile, generateTypes, getEffectivePhase, getJayHtmlImports, getLinkedContractDir, hasSlowPhaseProperties, isTagInPhase, loadLinkedContract, parseAction, parseContract, parseEnumValues, parseIsEnum, parseJayFile, renderRefsType, resolveHeadlessInstances, slowRenderTransform, validateContractPhases };
456
+ export { type ActionDefinition, type AssignCoordinatesOptions, type AssignCoordinatesResult, type Contract, type ContractImportInfo, type ContractParam, type ContractParamKind, type ContractProp, type ContractResolver, type ContractTag, ContractTagType, type DiscoveredHeadlessInstance, type EnumToImport, type ForEachHeadlessInstance, type HeadlessContractInfo, type HeadlessInstanceDiscoveryResult, type HeadlessInstanceResolvedData, JAY_IMPORT_RESOLVER, type JayContractImportLink, type JayHtmlSourceFile, type JayImportResolver, type PhaseViewStates, type RenderingPhase, type ServerElementOptions, type SlowRenderInput, type SlowRenderOutput, assignCoordinates, assignCoordinatesToJayHtml, buildInstanceCoordinateKey, compileAction, compileContract, contractToAllPhaseViewStates, contractToImportsViewStateAndRefs, contractToPhaseViewState, createPhaseContract, defaultContractResolver, discoverHeadlessInstances, filterTagsByPhase, generateElementBridgeFile, generateElementDefinitionFile, generateElementFile, generateElementFileReactTarget, generateElementHydrateFile, generateSandboxRootFile, generateServerElementFile, generateTypes, getEffectivePhase, getJayHtmlImports, getLinkedContractDir, hasSlowPhaseProperties, injectHeadfullFSTemplates, isTagInPhase, loadLinkedContract, parseAction, parseContract, parseEnumValues, parseIsEnum, parseJayFile, renderRefsType, resolveHeadlessInstances, slowRenderTransform, validateContractPhases };