@webmate-studio/builder 0.2.181 → 0.2.183
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 +28 -15
package/package.json
CHANGED
|
@@ -40,10 +40,6 @@ 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
|
-
}
|
|
47
43
|
return node.value;
|
|
48
44
|
case 'Expression':
|
|
49
45
|
return this.evalExpression(node, ctx);
|
|
@@ -198,10 +194,10 @@ class TemplateEvaluator {
|
|
|
198
194
|
return this.evalIslandTag(node, ctx);
|
|
199
195
|
}
|
|
200
196
|
|
|
201
|
-
// Built-in micro-components
|
|
202
|
-
if (node.tagName === 'wm-button') {
|
|
203
|
-
|
|
204
|
-
}
|
|
197
|
+
// Built-in micro-components (disabled for testing)
|
|
198
|
+
// if (node.tagName === 'wm-button') {
|
|
199
|
+
// return this.evalWmButton(node, ctx);
|
|
200
|
+
// }
|
|
205
201
|
|
|
206
202
|
let result = `<${node.tagName}`;
|
|
207
203
|
|
|
@@ -317,12 +313,10 @@ class TemplateEvaluator {
|
|
|
317
313
|
/**
|
|
318
314
|
* Built-in micro-component: <wm-button settings={button}></wm-button>
|
|
319
315
|
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
* In Build: html-static-builder resolves it to static <a> HTML.
|
|
316
|
+
* Resolves to static <a> HTML with Design System button classes.
|
|
317
|
+
* Works identically in Preview and Build — no Web Component needed.
|
|
323
318
|
*/
|
|
324
319
|
evalWmButton(node, ctx) {
|
|
325
|
-
// Resolve the settings prop
|
|
326
320
|
let settings = null;
|
|
327
321
|
for (const attr of node.attributes) {
|
|
328
322
|
if (attr.name === 'settings') {
|
|
@@ -338,9 +332,28 @@ class TemplateEvaluator {
|
|
|
338
332
|
return '<!-- wm-button: no settings -->';
|
|
339
333
|
}
|
|
340
334
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
335
|
+
const {
|
|
336
|
+
title = '', link = '#', icon = '', variant = 'filled',
|
|
337
|
+
size = 'md', iconPosition = 'left', openInNewTab = false
|
|
338
|
+
} = settings;
|
|
339
|
+
|
|
340
|
+
const sizeMap = { small: 'sm', medium: 'md', large: 'lg', sm: 'sm', md: 'md', lg: 'lg' };
|
|
341
|
+
const variantMap = { primary: 'filled', secondary: 'tonal' };
|
|
342
|
+
const classes = `btn btn-${sizeMap[size] || 'md'} btn-${variantMap[variant] || variant}`;
|
|
343
|
+
const href = typeof link === 'object' ? (link.path || link.url || '#') : (link || '#');
|
|
344
|
+
const target = openInNewTab ? ' target="_blank" rel="noopener noreferrer"' : '';
|
|
345
|
+
const iconHtml = icon ? `<iconify-icon icon="${this.escapeAttr(icon)}"></iconify-icon>` : '';
|
|
346
|
+
|
|
347
|
+
let content;
|
|
348
|
+
if (icon && iconPosition === 'right') {
|
|
349
|
+
content = `${this.escapeHtml(title)}${iconHtml ? ' ' + iconHtml : ''}`;
|
|
350
|
+
} else if (icon) {
|
|
351
|
+
content = `${iconHtml ? iconHtml + ' ' : ''}${this.escapeHtml(title)}`;
|
|
352
|
+
} else {
|
|
353
|
+
content = this.escapeHtml(title);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return `<a href="${this.escapeAttr(href)}" class="${classes}"${target}>${content}</a>`;
|
|
344
357
|
}
|
|
345
358
|
|
|
346
359
|
// ========================================
|