@jay-framework/compiler-jay-html 0.5.0 → 0.5.1

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 ADDED
@@ -0,0 +1,13 @@
1
+ # @jay-framework/compiler-jay-html
2
+
3
+ ## 0.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - updating the dependencies to be fixed versions
8
+ - Updated dependencies
9
+ - @jay-framework/compiler-analyze-exported-types@0.5.1
10
+ - @jay-framework/compiler-shared@0.5.1
11
+ - @jay-framework/component@0.5.1
12
+ - @jay-framework/runtime@0.5.1
13
+ - @jay-framework/secure@0.5.1
package/dist/index.d.ts CHANGED
@@ -13,6 +13,11 @@ interface JayHeadlessImports {
13
13
  contractLinks: JayImportLink[];
14
14
  codeLink: JayImportLink;
15
15
  }
16
+ interface JayHtmlHeadLink {
17
+ rel: string;
18
+ href: string;
19
+ attributes: Record<string, string>;
20
+ }
16
21
  interface JayHtmlSourceFile extends CompilerSourceFile {
17
22
  format: SourceFileFormat.JayHtml;
18
23
  baseElementName: string;
@@ -20,6 +25,7 @@ interface JayHtmlSourceFile extends CompilerSourceFile {
20
25
  body: HTMLElement;
21
26
  namespaces: JayHtmlNamespace[];
22
27
  headlessImports: JayHeadlessImports[];
28
+ headLinks: JayHtmlHeadLink[];
23
29
  }
24
30
 
25
31
  declare function generateElementDefinitionFile(parsedFile: WithValidations<JayHtmlSourceFile>): WithValidations<string>;
package/dist/index.js CHANGED
@@ -5111,7 +5111,17 @@ function processImportedHeadless(headlessImports) {
5111
5111
  });
5112
5112
  return result;
5113
5113
  }
5114
- function renderFunctionImplementation$1(types, rootBodyElement, importStatements, baseElementName, namespaces, headlessImports, importerMode) {
5114
+ function renderHeadLinksArray(headLinks) {
5115
+ if (headLinks.length === 0) {
5116
+ return "[]";
5117
+ }
5118
+ const linksCode = headLinks.map((link) => {
5119
+ const attributesCode = Object.keys(link.attributes).length > 0 ? `, attributes: ${JSON.stringify(link.attributes)}` : "";
5120
+ return `{ rel: ${JSON.stringify(link.rel)}, href: ${JSON.stringify(link.href)}${attributesCode} }`;
5121
+ }).join(", ");
5122
+ return `[${linksCode}]`;
5123
+ }
5124
+ function renderFunctionImplementation$1(types, rootBodyElement, importStatements, baseElementName, namespaces, headlessImports, importerMode, headLinks = []) {
5115
5125
  const variables = new Variables(types);
5116
5126
  const { importedSymbols, importedSandboxedSymbols } = processImportedComponents(importStatements);
5117
5127
  const importedRefNameToRef = processImportedHeadless(headlessImports);
@@ -5139,6 +5149,9 @@ function renderFunctionImplementation$1(types, rootBodyElement, importStatements
5139
5149
  const preRenderType = `${elementType}PreRender`;
5140
5150
  const contractType = `${baseElementName}Contract`;
5141
5151
  let imports = renderedRoot.imports.plus(compilerShared.Import.ConstructContext).plus(compilerShared.Import.RenderElementOptions).plus(compilerShared.Import.RenderElement).plus(compilerShared.Import.ReferencesManager).plus(compilerShared.Import.jayContract);
5152
+ if (headLinks.length > 0) {
5153
+ imports = imports.plus(compilerShared.Import.injectHeadLinks);
5154
+ }
5142
5155
  const { imports: refImports, renderedRefs } = renderRefsType(renderedRoot.refs, refsType);
5143
5156
  imports = imports.plus(refImports);
5144
5157
  let renderedElement = `export type ${elementType} = JayElement<${viewStateType}, ${refsType}>
@@ -5158,9 +5171,11 @@ ${Indent.forceIndent(code, 4)},
5158
5171
  renderedRoot.refs,
5159
5172
  ReferenceManagerTarget.element
5160
5173
  );
5174
+ const headLinksInjection = headLinks.length > 0 ? ` injectHeadLinks(${renderHeadLinksArray(headLinks)});
5175
+ ` : "";
5161
5176
  const body = `export function render(options?: RenderElementOptions): ${preRenderType} {
5162
5177
  ${renderedRefsManager}
5163
- const render = (viewState: ${viewStateType}) => ConstructContext.withRootContext(
5178
+ ${headLinksInjection}const render = (viewState: ${viewStateType}) => ConstructContext.withRootContext(
5164
5179
  viewState, refManager,
5165
5180
  () => ${renderedRoot.rendered.trim()}
5166
5181
  ) as ${elementType};
@@ -5340,7 +5355,8 @@ function generateElementDefinitionFile(parsedFile) {
5340
5355
  jayFile.baseElementName,
5341
5356
  jayFile.namespaces,
5342
5357
  jayFile.headlessImports,
5343
- compilerShared.RuntimeMode.WorkerTrusted
5358
+ compilerShared.RuntimeMode.WorkerTrusted,
5359
+ jayFile.headLinks
5344
5360
  );
5345
5361
  return [
5346
5362
  renderImports$1(
@@ -5365,7 +5381,8 @@ function generateElementFile(jayFile, importerMode) {
5365
5381
  jayFile.baseElementName,
5366
5382
  jayFile.namespaces,
5367
5383
  jayFile.headlessImports,
5368
- importerMode
5384
+ importerMode,
5385
+ jayFile.headLinks
5369
5386
  );
5370
5387
  const renderedFile = [
5371
5388
  renderImports$1(
@@ -5397,7 +5414,8 @@ function generateElementBridgeFile(jayFile) {
5397
5414
  jayFile.baseElementName,
5398
5415
  jayFile.namespaces,
5399
5416
  jayFile.headlessImports,
5400
- compilerShared.RuntimeMode.WorkerSandbox
5417
+ compilerShared.RuntimeMode.WorkerSandbox,
5418
+ jayFile.headLinks
5401
5419
  );
5402
5420
  let renderedBridge = renderBridge(
5403
5421
  jayFile.types,
@@ -6378,6 +6396,21 @@ async function parseHeadlessImports(elements, validations, filePath, importResol
6378
6396
  function normalizeFilename(filename) {
6379
6397
  return filename.replace(".jay-html", "");
6380
6398
  }
6399
+ function parseHeadLinks(root) {
6400
+ const allLinks = root.querySelectorAll("head link");
6401
+ return allLinks.filter((link) => link.getAttribute("rel") !== "import").map((link) => {
6402
+ const attributes = { ...link.attributes };
6403
+ const rel = attributes.rel || "";
6404
+ const href = attributes.href || "";
6405
+ delete attributes.rel;
6406
+ delete attributes.href;
6407
+ return {
6408
+ rel,
6409
+ href,
6410
+ attributes
6411
+ };
6412
+ });
6413
+ }
6381
6414
  async function parseJayFile(html, filename, filePath, options, linkedContractResolver) {
6382
6415
  const normalizedFileName = normalizeFilename(filename);
6383
6416
  const baseElementName = changeCase.capitalCase(normalizedFileName, { delimiter: "" });
@@ -6405,6 +6438,7 @@ async function parseJayFile(html, filename, filePath, options, linkedContractRes
6405
6438
  ...headfullImports,
6406
6439
  ...headlessImports.flatMap((_) => _.contractLinks)
6407
6440
  ];
6441
+ const headLinks = parseHeadLinks(root);
6408
6442
  if (validations.length > 0)
6409
6443
  return new compilerShared.WithValidations(void 0, validations);
6410
6444
  let body = root.querySelector("body");
@@ -6420,7 +6454,8 @@ async function parseJayFile(html, filename, filePath, options, linkedContractRes
6420
6454
  body,
6421
6455
  baseElementName,
6422
6456
  namespaces,
6423
- headlessImports
6457
+ headlessImports,
6458
+ headLinks
6424
6459
  },
6425
6460
  validations
6426
6461
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/compiler-jay-html",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -27,11 +27,11 @@
27
27
  },
28
28
  "author": "",
29
29
  "dependencies": {
30
- "@jay-framework/compiler-analyze-exported-types": "workspace:^",
31
- "@jay-framework/compiler-shared": "workspace:^",
32
- "@jay-framework/component": "workspace:^",
33
- "@jay-framework/runtime": "workspace:^",
34
- "@jay-framework/secure": "workspace:^",
30
+ "@jay-framework/compiler-analyze-exported-types": "^0.5.1",
31
+ "@jay-framework/compiler-shared": "^0.5.1",
32
+ "@jay-framework/component": "^0.5.1",
33
+ "@jay-framework/runtime": "^0.5.1",
34
+ "@jay-framework/secure": "^0.5.1",
35
35
  "@types/js-yaml": "^4.0.9",
36
36
  "change-case": "^4.1.2",
37
37
  "js-yaml": "^4.1.0",
@@ -43,8 +43,8 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@caiogondim/strip-margin": "^1.0.0",
46
- "@jay-framework/4-react": "workspace:^",
47
- "@jay-framework/dev-environment": "workspace:^",
46
+ "@jay-framework/4-react": "^0.5.1",
47
+ "@jay-framework/dev-environment": "^0.5.1",
48
48
  "@testing-library/jest-dom": "^6.2.0",
49
49
  "@types/js-beautify": "^1",
50
50
  "@types/node": "^20.11.5",
@@ -59,4 +59,4 @@
59
59
  "vite": "^5.0.11",
60
60
  "vitest": "^1.2.1"
61
61
  }
62
- }
62
+ }