@jay-framework/compiler-jay-html 0.10.0 → 0.12.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/dist/index.d.cts +183 -2
- package/dist/index.js +16693 -7520
- package/package.json +10 -9
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { JayType, WithValidations, PluginComponentResolution, JayEnumType, RefsTree, CompilerSourceFile, SourceFileFormat, JayImportLink, MainRuntimeModes, GenerateTarget, Imports } from '@jay-framework/compiler-shared';
|
|
2
2
|
import { HTMLElement } from 'node-html-parser';
|
|
3
3
|
import { ResolveTsConfigOptions } from '@jay-framework/compiler-analyze-exported-types';
|
|
4
|
+
import { Coordinate } from '@jay-framework/runtime';
|
|
4
5
|
|
|
5
6
|
declare enum ContractTagType {
|
|
6
7
|
data = 0,
|
|
@@ -23,20 +24,71 @@ interface ContractTag {
|
|
|
23
24
|
async?: boolean;
|
|
24
25
|
phase?: RenderingPhase;
|
|
25
26
|
}
|
|
27
|
+
interface ContractProp {
|
|
28
|
+
name: string;
|
|
29
|
+
dataType: JayType;
|
|
30
|
+
required?: boolean;
|
|
31
|
+
description?: Array<string>;
|
|
32
|
+
default?: string;
|
|
33
|
+
}
|
|
34
|
+
/** URL/load params for a page (e.g. [slug]). Always string in generated type (UrlParams = Record<string, string>). Design Log #85. */
|
|
35
|
+
interface ContractParam {
|
|
36
|
+
name: string;
|
|
37
|
+
}
|
|
26
38
|
interface Contract {
|
|
27
39
|
name: string;
|
|
28
40
|
tags: Array<ContractTag>;
|
|
41
|
+
props?: Array<ContractProp>;
|
|
42
|
+
/** URL/load params (e.g. slug for [slug] route). Generates Params extends UrlParams. */
|
|
43
|
+
params?: Array<ContractParam>;
|
|
29
44
|
}
|
|
30
45
|
|
|
31
46
|
declare function compileContract(contractWithValidations: WithValidations<Contract>, contractFilePath: string, jayImportResolver: JayImportResolver): Promise<WithValidations<string>>;
|
|
32
47
|
|
|
33
48
|
declare function parseContract(contractYaml: string, fileName: string): WithValidations<Contract>;
|
|
34
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Get the effective phase for a tag (explicit or default)
|
|
52
|
+
*/
|
|
53
|
+
declare function getEffectivePhase(tag: ContractTag, parentPhase?: RenderingPhase): RenderingPhase;
|
|
54
|
+
/**
|
|
55
|
+
* Check if a tag should be included in a specific phase's ViewState
|
|
56
|
+
* A tag is included if its effective phase exactly matches the target phase
|
|
57
|
+
*/
|
|
58
|
+
declare function isTagInPhase(tag: ContractTag, targetPhase: RenderingPhase, parentPhase?: RenderingPhase): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Validate phase constraints across the entire contract
|
|
61
|
+
*/
|
|
62
|
+
declare function validateContractPhases(contract: Contract): string[];
|
|
63
|
+
/**
|
|
64
|
+
* Filter tags recursively by phase
|
|
65
|
+
* Returns only tags that should be included in the target phase's ViewState
|
|
66
|
+
*/
|
|
67
|
+
declare function filterTagsByPhase(tags: ContractTag[], targetPhase: RenderingPhase, parentPhase?: RenderingPhase): ContractTag[];
|
|
68
|
+
/**
|
|
69
|
+
* Create a phase-specific contract
|
|
70
|
+
* Returns a contract with only tags that belong to the target phase
|
|
71
|
+
*/
|
|
72
|
+
declare function createPhaseContract(contract: Contract, targetPhase: RenderingPhase): Contract;
|
|
73
|
+
|
|
35
74
|
interface JayImportResolver {
|
|
36
75
|
resolveLink(importingModuleDir: string, link: string): string;
|
|
76
|
+
/** Load a contract from an absolute file path */
|
|
37
77
|
loadContract(fullPath: string): WithValidations<Contract>;
|
|
38
78
|
analyzeExportedTypes(fullPath: string, options: ResolveTsConfigOptions): JayType[];
|
|
39
79
|
resolvePluginComponent(pluginName: string, contractName: string, projectRoot: string): WithValidations<PluginComponentResolution>;
|
|
80
|
+
/**
|
|
81
|
+
* Load a contract from a plugin, handling both static and dynamic contracts.
|
|
82
|
+
* For static contracts, loads from the plugin's contract file.
|
|
83
|
+
* For dynamic contracts, loads from materialized location (build/materialized-contracts/).
|
|
84
|
+
*
|
|
85
|
+
* Returns the contract, path, and optional metadata (for dynamic contracts).
|
|
86
|
+
*/
|
|
87
|
+
loadPluginContract(pluginName: string, contractName: string, projectRoot: string): WithValidations<{
|
|
88
|
+
contract: Contract;
|
|
89
|
+
contractPath: string;
|
|
90
|
+
metadata?: Record<string, unknown>;
|
|
91
|
+
}>;
|
|
40
92
|
}
|
|
41
93
|
declare const JAY_IMPORT_RESOLVER: JayImportResolver;
|
|
42
94
|
|
|
@@ -71,17 +123,38 @@ interface PhaseViewStates {
|
|
|
71
123
|
*/
|
|
72
124
|
declare function contractToAllPhaseViewStates(contract: Contract, contractFilePath: string, jayImportResolver: JayImportResolver): Promise<WithValidations<PhaseViewStates>>;
|
|
73
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Load a linked contract using the import resolver.
|
|
128
|
+
* Returns the parsed contract or null if not found/failed.
|
|
129
|
+
*
|
|
130
|
+
* @param linkPath - The link path from the contract (e.g., "./product-card")
|
|
131
|
+
* @param baseContractDir - Directory of the contract containing the link
|
|
132
|
+
* @param importResolver - Import resolver for loading contracts
|
|
133
|
+
*/
|
|
134
|
+
declare function loadLinkedContract(linkPath: string, baseContractDir: string, importResolver: JayImportResolver): Contract | null;
|
|
135
|
+
/**
|
|
136
|
+
* Get the directory of a linked contract for resolving nested links.
|
|
137
|
+
*
|
|
138
|
+
* @param linkPath - The link path from the contract (e.g., "./product-card")
|
|
139
|
+
* @param baseContractDir - Directory of the contract containing the link
|
|
140
|
+
* @param importResolver - Import resolver for path resolution
|
|
141
|
+
*/
|
|
142
|
+
declare function getLinkedContractDir(linkPath: string, baseContractDir: string, importResolver: JayImportResolver): string;
|
|
143
|
+
|
|
74
144
|
interface JayHtmlNamespace {
|
|
75
145
|
prefix: string;
|
|
76
146
|
namespace: string;
|
|
77
147
|
}
|
|
78
148
|
interface JayHeadlessImports {
|
|
79
|
-
key
|
|
149
|
+
key?: string;
|
|
150
|
+
contractName: string;
|
|
80
151
|
refs: RefsTree;
|
|
81
152
|
rootType: JayType;
|
|
82
153
|
contractLinks: JayImportLink[];
|
|
83
154
|
codeLink: JayImportLink;
|
|
84
155
|
contract?: Contract;
|
|
156
|
+
contractPath?: string;
|
|
157
|
+
metadata?: Record<string, unknown>;
|
|
85
158
|
}
|
|
86
159
|
interface JayHtmlHeadLink {
|
|
87
160
|
rel: string;
|
|
@@ -97,6 +170,11 @@ interface JayHtmlSourceFile extends CompilerSourceFile {
|
|
|
97
170
|
headlessImports: JayHeadlessImports[];
|
|
98
171
|
headLinks: JayHtmlHeadLink[];
|
|
99
172
|
css?: string;
|
|
173
|
+
/**
|
|
174
|
+
* Absolute paths to linked CSS files referenced via <link rel="stylesheet">.
|
|
175
|
+
* Used by the dev server to watch these files for changes.
|
|
176
|
+
*/
|
|
177
|
+
linkedCssFiles?: string[];
|
|
100
178
|
filename?: string;
|
|
101
179
|
contract?: Contract;
|
|
102
180
|
contractRef?: string;
|
|
@@ -133,4 +211,107 @@ declare function renderRefsType(refs: RefsTree, refsType: string, generateTarget
|
|
|
133
211
|
|
|
134
212
|
declare function generateTypes(types: JayType): string;
|
|
135
213
|
|
|
136
|
-
|
|
214
|
+
/**
|
|
215
|
+
* Headless contract with its key (used for property path prefix)
|
|
216
|
+
*/
|
|
217
|
+
interface HeadlessContractInfo {
|
|
218
|
+
/** The key attribute from the headless script tag */
|
|
219
|
+
key: string;
|
|
220
|
+
/** The parsed contract */
|
|
221
|
+
contract: Contract;
|
|
222
|
+
/** Path to the contract file (used to resolve linked sub-contracts) */
|
|
223
|
+
contractPath?: string;
|
|
224
|
+
/** Optional metadata from the generator (for dynamic contracts) */
|
|
225
|
+
metadata?: Record<string, unknown>;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Input for slow render transformation
|
|
229
|
+
*/
|
|
230
|
+
interface SlowRenderInput {
|
|
231
|
+
/** Original jay-html content */
|
|
232
|
+
jayHtmlContent: string;
|
|
233
|
+
/** Slow phase view state data */
|
|
234
|
+
slowViewState: Record<string, unknown>;
|
|
235
|
+
/** Contract metadata for phase detection (page's main contract) */
|
|
236
|
+
contract?: Contract;
|
|
237
|
+
/**
|
|
238
|
+
* Headless component contracts, keyed by their `key` attribute.
|
|
239
|
+
* These contracts provide phase info for properties like `productSearch.categoryName`.
|
|
240
|
+
*/
|
|
241
|
+
headlessContracts?: HeadlessContractInfo[];
|
|
242
|
+
/**
|
|
243
|
+
* Source directory of the original jay-html file.
|
|
244
|
+
* Used to resolve relative paths (contracts, CSS, components) to absolute paths
|
|
245
|
+
* so the pre-rendered file can be placed in a different directory.
|
|
246
|
+
*/
|
|
247
|
+
sourceDir?: string;
|
|
248
|
+
/**
|
|
249
|
+
* Import resolver for loading linked sub-contracts.
|
|
250
|
+
* If not provided, linked sub-contracts will not be resolved.
|
|
251
|
+
*/
|
|
252
|
+
importResolver?: JayImportResolver;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Output of slow render transformation
|
|
256
|
+
*/
|
|
257
|
+
interface SlowRenderOutput {
|
|
258
|
+
/** Pre-rendered jay-html content */
|
|
259
|
+
preRenderedJayHtml: string;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Transform a jay-html file by resolving slow-phase bindings
|
|
263
|
+
*
|
|
264
|
+
* This is the main entry point for slow rendering.
|
|
265
|
+
*
|
|
266
|
+
* @param input - The input containing jay-html content, slow view state, and contract
|
|
267
|
+
* @returns The pre-rendered jay-html with slow bindings resolved
|
|
268
|
+
*/
|
|
269
|
+
declare function slowRenderTransform(input: SlowRenderInput): WithValidations<SlowRenderOutput>;
|
|
270
|
+
/**
|
|
271
|
+
* Discovered headless component instance in pre-rendered jay-html.
|
|
272
|
+
* Found after Pass 1 (page bindings resolved, slow forEach unrolled).
|
|
273
|
+
*/
|
|
274
|
+
interface DiscoveredHeadlessInstance {
|
|
275
|
+
/** Contract name from tag name (e.g., "product-card" from <jay:product-card>) */
|
|
276
|
+
contractName: string;
|
|
277
|
+
/** Props extracted from element attributes (camelCased keys, string values) */
|
|
278
|
+
props: Record<string, string>;
|
|
279
|
+
/**
|
|
280
|
+
* Coordinate that uniquely identifies this instance in the page tree.
|
|
281
|
+
* Built from ancestor slowForEach jayTrackBy values + "contractName:localIndex".
|
|
282
|
+
*/
|
|
283
|
+
coordinate: Coordinate;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Resolved data for a headless component instance.
|
|
287
|
+
* Provided by the dev server after calling slowlyRender for each discovered instance.
|
|
288
|
+
*/
|
|
289
|
+
interface HeadlessInstanceResolvedData {
|
|
290
|
+
/** Coordinate matching the discovered instance */
|
|
291
|
+
coordinate: Coordinate;
|
|
292
|
+
/** The component's contract (for phase detection) */
|
|
293
|
+
contract: Contract;
|
|
294
|
+
/** Slow phase ViewState data for this instance */
|
|
295
|
+
slowViewState: Record<string, unknown>;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Build the full coordinate key string for a <jay:xxx> element.
|
|
299
|
+
* Format: "jayTrackBy1/jayTrackBy2/.../contractName:ref"
|
|
300
|
+
*
|
|
301
|
+
* Uses the element's `ref` attribute if present. If the element has no ref,
|
|
302
|
+
* a coordinateCounters map must be provided to auto-assign an index.
|
|
303
|
+
*/
|
|
304
|
+
declare function buildInstanceCoordinateKey(element: HTMLElement, contractName: string, coordinateCounters?: Map<string, number>): string;
|
|
305
|
+
interface HeadlessInstanceDiscoveryResult {
|
|
306
|
+
instances: DiscoveredHeadlessInstance[];
|
|
307
|
+
/** HTML with auto-generated ref attributes embedded on <jay:xxx> elements */
|
|
308
|
+
preRenderedJayHtml: string;
|
|
309
|
+
}
|
|
310
|
+
declare function discoverHeadlessInstances(preRenderedJayHtml: string): HeadlessInstanceDiscoveryResult;
|
|
311
|
+
declare function resolveHeadlessInstances(preRenderedJayHtml: string, instanceData: HeadlessInstanceResolvedData[], importResolver?: JayImportResolver): WithValidations<string>;
|
|
312
|
+
/**
|
|
313
|
+
* Check if a jay-html file has any slow-phase properties that can be pre-rendered
|
|
314
|
+
*/
|
|
315
|
+
declare function hasSlowPhaseProperties(contract: Contract | undefined): boolean;
|
|
316
|
+
|
|
317
|
+
export { type Contract, type ContractParam, type ContractProp, type ContractTag, ContractTagType, type DiscoveredHeadlessInstance, type EnumToImport, type HeadlessContractInfo, type HeadlessInstanceDiscoveryResult, type HeadlessInstanceResolvedData, JAY_IMPORT_RESOLVER, type JayContractImportLink, type JayHtmlSourceFile, type JayImportResolver, type PhaseViewStates, type RenderingPhase, type SlowRenderInput, type SlowRenderOutput, buildInstanceCoordinateKey, compileContract, contractToAllPhaseViewStates, contractToImportsViewStateAndRefs, contractToPhaseViewState, createPhaseContract, discoverHeadlessInstances, filterTagsByPhase, generateElementBridgeFile, generateElementDefinitionFile, generateElementFile, generateElementFileReactTarget, generateSandboxRootFile, generateTypes, getEffectivePhase, getJayHtmlImports, getLinkedContractDir, hasSlowPhaseProperties, isTagInPhase, loadLinkedContract, parseContract, parseEnumValues, parseIsEnum, parseJayFile, renderRefsType, resolveHeadlessInstances, slowRenderTransform, validateContractPhases };
|