@webmate-studio/builder 0.2.179 → 0.2.181
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/package.json +1 -1
- package/src/template-evaluator.js +38 -0
package/package.json
CHANGED
|
@@ -40,6 +40,10 @@ class TemplateEvaluator {
|
|
|
40
40
|
case 'Fragment':
|
|
41
41
|
return this.evalFragment(node, ctx);
|
|
42
42
|
case 'Text':
|
|
43
|
+
// Strip closing tags of built-in micro-components (only if present)
|
|
44
|
+
if (node.value.includes('</wm-')) {
|
|
45
|
+
return node.value.replace(/<\/wm-button>/g, '');
|
|
46
|
+
}
|
|
43
47
|
return node.value;
|
|
44
48
|
case 'Expression':
|
|
45
49
|
return this.evalExpression(node, ctx);
|
|
@@ -194,6 +198,11 @@ class TemplateEvaluator {
|
|
|
194
198
|
return this.evalIslandTag(node, ctx);
|
|
195
199
|
}
|
|
196
200
|
|
|
201
|
+
// Built-in micro-components
|
|
202
|
+
if (node.tagName === 'wm-button') {
|
|
203
|
+
return this.evalWmButton(node, ctx);
|
|
204
|
+
}
|
|
205
|
+
|
|
197
206
|
let result = `<${node.tagName}`;
|
|
198
207
|
|
|
199
208
|
// Collect all class names (static + conditional)
|
|
@@ -305,6 +314,35 @@ class TemplateEvaluator {
|
|
|
305
314
|
return `<${kebabTag}${propsAttr}></${kebabTag}>`;
|
|
306
315
|
}
|
|
307
316
|
|
|
317
|
+
/**
|
|
318
|
+
* Built-in micro-component: <wm-button settings={button}></wm-button>
|
|
319
|
+
*
|
|
320
|
+
* Outputs a <wm-button> Custom Element with serialized settings.
|
|
321
|
+
* In Preview: Web Component (wm-button.js) renders it live.
|
|
322
|
+
* In Build: html-static-builder resolves it to static <a> HTML.
|
|
323
|
+
*/
|
|
324
|
+
evalWmButton(node, ctx) {
|
|
325
|
+
// Resolve the settings prop
|
|
326
|
+
let settings = null;
|
|
327
|
+
for (const attr of node.attributes) {
|
|
328
|
+
if (attr.name === 'settings') {
|
|
329
|
+
if (attr.type === 'DynamicAttribute') {
|
|
330
|
+
settings = this.expr.evaluate(attr.expression, ctx);
|
|
331
|
+
} else if (attr.type === 'StaticAttribute') {
|
|
332
|
+
settings = attr.value;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (!settings || typeof settings !== 'object') {
|
|
338
|
+
return '<!-- wm-button: no settings -->';
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Serialize settings as JSON attribute for the Web Component
|
|
342
|
+
const json = JSON.stringify(settings).replace(/'/g, ''');
|
|
343
|
+
return `<wm-button settings='${json}'></wm-button>`;
|
|
344
|
+
}
|
|
345
|
+
|
|
308
346
|
// ========================================
|
|
309
347
|
// Value resolution helpers
|
|
310
348
|
// ========================================
|