@jay-framework/compiler-jay-html 0.15.1 → 0.15.3

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 (2) hide show
  1. package/dist/index.js +35 -11
  2. package/package.json +9 -9
package/dist/index.js CHANGED
@@ -20554,9 +20554,25 @@ ${context.indent.firstLine} ${createBody})`,
20554
20554
  itemChildNodes.map((child) => renderHydrateNode(child, itemContext)),
20555
20555
  ",\n"
20556
20556
  );
20557
- const adoptBody = itemContent.rendered.trim() ? `() => [
20557
+ const itemRenderCtx = buildRenderContext(itemContext);
20558
+ const itemAttrs = renderDynamicAttributes(element, itemRenderCtx);
20559
+ const itemHasDynamicAttrs = itemAttrs.imports.has(Import.dynamicAttribute) || itemAttrs.imports.has(Import.dynamicProperty) || itemAttrs.imports.has(Import.booleanAttribute);
20560
+ const itemRefFragment = renderElementRef$1(element, itemRenderCtx);
20561
+ const needsItemAdoption = itemHasDynamicAttrs || !!itemRefFragment.rendered.trim();
20562
+ let adoptBody;
20563
+ if (needsItemAdoption) {
20564
+ const refSuffix = itemRefFragment.rendered ? `, ${itemRefFragment.rendered}` : "";
20565
+ const childrenArr = itemContent.rendered.trim() ? `[
20566
+ ${itemContent.rendered},
20567
+ ${indent.firstLine} ]` : "[]";
20568
+ adoptBody = `() => [
20569
+ ${indent.firstLine} adoptElement("", ${itemAttrs.rendered}, ${childrenArr}${refSuffix}),
20570
+ ${indent.firstLine} ]`;
20571
+ } else {
20572
+ adoptBody = itemContent.rendered.trim() ? `() => [
20558
20573
  ${itemContent.rendered},
20559
20574
  ${indent.firstLine} ]` : "() => []";
20575
+ }
20560
20576
  const createRenderContext = {
20561
20577
  ...renderContext,
20562
20578
  variables: forEachVariables,
@@ -20585,21 +20601,27 @@ ${indent.firstLine} ]` : "() => []";
20585
20601
  );
20586
20602
  const forEachElementFunc = forEachNeedsDynamic ? "de" : "e";
20587
20603
  const forEachElementImport = forEachNeedsDynamic ? Import.dynamicElement : Import.element;
20604
+ const createItemRef = renderElementRef$1(element, createRenderContext);
20605
+ const createRefSuffix = createItemRef.rendered ? `, ${createItemRef.rendered}` : "";
20588
20606
  const createBody = `(${forEachVariables.currentVar}: ${forEachVariables.currentType.name}) => {
20589
- ${indent.firstLine} return ${forEachElementFunc}('${element.rawTagName}', ${createAttributes.rendered}, [${createChildren.rendered}]);
20607
+ ${indent.firstLine} return ${forEachElementFunc}('${element.rawTagName}', ${createAttributes.rendered}, [${createChildren.rendered}]${createRefSuffix});
20590
20608
  ${indent.firstLine} }`;
20609
+ let allImports = Imports.for(Import.hydrateForEach).plus(forEachElementImport).plus(forEachFragment.imports).plus(itemContent.imports).plus(createChildren.imports).plus(createAttributes.imports).plus(itemAttrs.imports).plus(itemRefFragment.imports).plus(createItemRef.imports);
20610
+ if (needsItemAdoption) {
20611
+ allImports = allImports.plus(Import.adoptElement);
20612
+ }
20591
20613
  const hydrateForEachFragment = new RenderFragment(
20592
20614
  `${indent.firstLine}hydrateForEach(${forEachFragment.rendered}, '${trackBy}',
20593
20615
  ${indent.firstLine} ${adoptBody},
20594
20616
  ${indent.firstLine} ${createBody},
20595
20617
  ${indent.firstLine})`,
20596
- Imports.for(Import.hydrateForEach).plus(forEachElementImport).plus(forEachFragment.imports).plus(itemContent.imports).plus(createChildren.imports).plus(createAttributes.imports),
20618
+ allImports,
20597
20619
  [
20598
20620
  ...forEachFragment.validations,
20599
20621
  ...itemContent.validations,
20600
20622
  ...createChildren.validations
20601
20623
  ],
20602
- itemContent.refs
20624
+ mergeRefsTrees(itemContent.refs, itemRefFragment.refs)
20603
20625
  );
20604
20626
  return nestRefs(forEachAccessor.terms, hydrateForEachFragment);
20605
20627
  }
@@ -21729,6 +21751,7 @@ function renderServerElementAsString(element, context, overrideCoordinate) {
21729
21751
  const coordTemplate = element.getAttribute(COORD_ATTR);
21730
21752
  const coordinate = coordTemplate || (needsCoordinate ? overrideCoordinate || null : null);
21731
21753
  const isVoid = voidElements.has(element.rawTagName.toLowerCase());
21754
+ const closeTag = isVoid ? " />" : ">";
21732
21755
  const stringParts = [];
21733
21756
  stringParts.push(new RenderFragment(`'<${element.rawTagName}'`));
21734
21757
  const attrs = renderServerAttributesAsString(element, context);
@@ -21736,9 +21759,9 @@ function renderServerElementAsString(element, context, overrideCoordinate) {
21736
21759
  stringParts.push(attrs);
21737
21760
  }
21738
21761
  if (coordinate !== null) {
21739
- stringParts.push(new RenderFragment(`' jay-coordinate="${coordinate}">'`));
21762
+ stringParts.push(new RenderFragment(`' jay-coordinate="${coordinate}"${closeTag}'`));
21740
21763
  } else {
21741
- stringParts.push(new RenderFragment(`'>'`));
21764
+ stringParts.push(new RenderFragment(`'${closeTag}'`));
21742
21765
  }
21743
21766
  if (!isVoid) {
21744
21767
  if (dynamicTextFragment) {
@@ -21902,6 +21925,7 @@ function renderServerElementContent(element, context, options) {
21902
21925
  const needsCoordinate = options?.isRoot === true || isConditional(element) && conditionIsInteractive(element.getAttribute("if"), context.interactivePaths) || dynamicTextFragment !== null || refName !== null || hasDynamicAttributeBindings(element, variables) || hasInteractiveChildElements(childNodes) || hasMixedContentDynamicTextInteractive(childNodes, context.interactivePaths);
21903
21926
  const coordTemplate = needsCoordinate ? element.getAttribute(COORD_ATTR) : null;
21904
21927
  const isVoid = voidElements.has(element.rawTagName.toLowerCase());
21928
+ const closeTag = isVoid ? " />" : ">";
21905
21929
  const parts = [];
21906
21930
  parts.push(w(indent, `'<${element.rawTagName}'`));
21907
21931
  const attrs = renderServerAttributes(element, context);
@@ -21914,12 +21938,12 @@ function renderServerElementContent(element, context, options) {
21914
21938
  parts.push(
21915
21939
  w(
21916
21940
  indent,
21917
- `' jay-coordinate="' + ${context.forEachAccumulatedPrefix} + '/${coordTemplate}">'`,
21941
+ `' jay-coordinate="' + ${context.forEachAccumulatedPrefix} + '/${coordTemplate}"${closeTag}'`,
21918
21942
  Imports.for(Import.escapeAttr)
21919
21943
  )
21920
21944
  );
21921
21945
  } else {
21922
- parts.push(w(indent, `' jay-coordinate="${coordTemplate}">'`));
21946
+ parts.push(w(indent, `' jay-coordinate="${coordTemplate}"${closeTag}'`));
21923
21947
  }
21924
21948
  } else {
21925
21949
  const coordExpr = compileCoordinateExpr(coordTemplate, context.varMappings);
@@ -21927,7 +21951,7 @@ function renderServerElementContent(element, context, options) {
21927
21951
  parts.push(
21928
21952
  w(
21929
21953
  indent,
21930
- `' jay-coordinate="' + ${context.forEachAncestorPrefix} + '/' + ${coordExpr} + '">'`,
21954
+ `' jay-coordinate="' + ${context.forEachAncestorPrefix} + '/' + ${coordExpr} + '"${closeTag}'`,
21931
21955
  Imports.for(Import.escapeAttr)
21932
21956
  )
21933
21957
  );
@@ -21935,14 +21959,14 @@ function renderServerElementContent(element, context, options) {
21935
21959
  parts.push(
21936
21960
  w(
21937
21961
  indent,
21938
- `' jay-coordinate="' + ${coordExpr} + '">'`,
21962
+ `' jay-coordinate="' + ${coordExpr} + '"${closeTag}'`,
21939
21963
  Imports.for(Import.escapeAttr)
21940
21964
  )
21941
21965
  );
21942
21966
  }
21943
21967
  }
21944
21968
  } else {
21945
- parts.push(w(indent, `'>'`));
21969
+ parts.push(w(indent, `'${closeTag}'`));
21946
21970
  }
21947
21971
  if (isVoid)
21948
21972
  return mergeServerFragments(parts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/compiler-jay-html",
3
- "version": "0.15.1",
3
+ "version": "0.15.3",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -34,12 +34,12 @@
34
34
  },
35
35
  "author": "",
36
36
  "dependencies": {
37
- "@jay-framework/compiler-analyze-exported-types": "^0.15.1",
38
- "@jay-framework/compiler-shared": "^0.15.1",
39
- "@jay-framework/component": "^0.15.1",
40
- "@jay-framework/logger": "^0.15.1",
41
- "@jay-framework/runtime": "^0.15.1",
42
- "@jay-framework/secure": "^0.15.1",
37
+ "@jay-framework/compiler-analyze-exported-types": "^0.15.3",
38
+ "@jay-framework/compiler-shared": "^0.15.3",
39
+ "@jay-framework/component": "^0.15.3",
40
+ "@jay-framework/logger": "^0.15.3",
41
+ "@jay-framework/runtime": "^0.15.3",
42
+ "@jay-framework/secure": "^0.15.3",
43
43
  "@types/js-yaml": "^4.0.9",
44
44
  "change-case": "^4.1.2",
45
45
  "js-yaml": "^4.1.0",
@@ -51,8 +51,8 @@
51
51
  },
52
52
  "devDependencies": {
53
53
  "@caiogondim/strip-margin": "^1.0.0",
54
- "@jay-framework/4-react": "^0.15.1",
55
- "@jay-framework/dev-environment": "^0.15.1",
54
+ "@jay-framework/4-react": "^0.15.3",
55
+ "@jay-framework/dev-environment": "^0.15.3",
56
56
  "@testing-library/jest-dom": "^6.2.0",
57
57
  "@types/js-beautify": "^1",
58
58
  "@types/node": "^20.11.5",