UNPKG

@muban/template

Version:

Writing templates for Muban components during development

40 lines (39 loc) 2.07 kB
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; }; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; /* eslint-disable @typescript-eslint/no-explicit-any */ import { html } from '../mtl'; import { jsonScriptTemplate } from './jsonScriptTemplate'; export function templateComponentFactory(_a) { var tag = _a.tag, component = _a.component, tagAttributes = _a.tagAttributes, children = _a.children, jsonProps = _a.jsonProps; return function (props, ref) { return renderComponentWrapper({ tag: tag, ref: ref, component: component, tagAttributes: tagAttributes, children: children(props), jsonProps: jsonProps === null || jsonProps === void 0 ? void 0 : jsonProps(props), }); }; } export function renderComponentWrapper(_a) { var _b = _a.tag, tag = _b === void 0 ? 'div' : _b, component = _a.component, ref = _a.ref, children = _a.children, tagAttributes = _a.tagAttributes, jsonProps = _a.jsonProps; var componentAttributes = __assign(__assign({}, tagAttributes), { 'data-component': typeof component === 'string' || typeof component === 'undefined' ? component : component.displayName }); return html(templateObject_1 || (templateObject_1 = __makeTemplateObject(["<", " data-ref=", " ...", ">\n ", "\n ", "\n </", ">"], ["<", " data-ref=", " ...", ">\n ", "\n ", "\n </", ">"])), tag, ref, componentAttributes, jsonProps ? jsonScriptTemplate(jsonProps) : '', children, tag); } var templateObject_1;