@stacksjs/stx 0.2.121 → 0.2.123

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.
@@ -222,6 +222,10 @@ function parseComponentProps(rawProps, context, options) {
222
222
  }
223
223
  if (attrName.startsWith(":")) {
224
224
  const propName = kebabToCamel(attrName.slice(1)), expression = attrValue === BOOLEAN_ATTRIBUTE_SENTINEL ? propName : attrValue;
225
+ if (propName === "if" || propName === "for" || propName === "show") {
226
+ resolved.clientReactive[propName] = expression;
227
+ continue;
228
+ }
225
229
  try {
226
230
  if (!isExpressionSafe(expression)) {
227
231
  if (options.debug)
@@ -642,11 +646,20 @@ async function processCustomElementTags(template, context, filePath, options, de
642
646
  }
643
647
  }
644
648
  function emitClientReactiveAttrs(html, clientReactive) {
645
- const root = findRenderedComponentRoot(html);
646
- if (!root)
647
- return html;
648
- const structuralBindings = new Set(["if", "for", "show"]), reactiveAttrs = Object.entries(clientReactive).map(([key, expr]) => `:${pascalToKebab(key)}="${expr.replace(/"/g, """)}"`).join(" "), parentBindings = Object.keys(clientReactive).filter((key) => !structuralBindings.has(key)).map((key) => pascalToKebab(key)).join(" "), parentBindingAttr = parentBindings ? ` data-stx-parent-bindings="${parentBindings}"` : "";
649
- return html.substring(0, root.insertPos) + `${parentBindingAttr} ${reactiveAttrs}` + html.substring(root.insertPos);
649
+ const componentControlBindings = new Set(["if", "for"]), rootStructuralBindings = new Set(["show"]), rootBindings = Object.entries(clientReactive).filter(([key]) => !componentControlBindings.has(key)), parentBindings = rootBindings.filter(([key]) => !rootStructuralBindings.has(key)).map(([key]) => pascalToKebab(key)).join(" ");
650
+ let output = html;
651
+ const root = rootBindings.length > 0 ? findRenderedComponentRoot(output) : null;
652
+ if (root) {
653
+ const reactiveAttrs = rootBindings.map(([key, expr]) => `:${pascalToKebab(key)}="${expr.replace(/"/g, """)}"`).join(" "), parentBindingAttr = parentBindings ? ` data-stx-parent-bindings="${parentBindings}"` : "";
654
+ output = output.substring(0, root.insertPos) + `${parentBindingAttr} ${reactiveAttrs}` + output.substring(root.insertPos);
655
+ }
656
+ const ifExpression = clientReactive.if;
657
+ if (ifExpression)
658
+ output = `<template :if="${ifExpression.replace(/"/g, "&quot;")}">${output}</template>`;
659
+ const forExpression = clientReactive.for;
660
+ if (forExpression)
661
+ output = `<template :for="${forExpression.replace(/"/g, "&quot;")}">${output}</template>`;
662
+ return output;
650
663
  }
651
664
  function findRenderedComponentRoot(html) {
652
665
  const scopedRoot = /<([a-zA-Z][a-zA-Z0-9-]*)\b[^>]*\bdata-stx-scope(?:\s|=|>)/i.exec(html);