@muban/template
Version:
Writing templates for Muban components during development
45 lines (44 loc) • 2.36 kB
JavaScript
;
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderComponentWrapper = exports.templateComponentFactory = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
var mtl_1 = require("../mtl");
var jsonScriptTemplate_1 = require("./jsonScriptTemplate");
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),
});
};
}
exports.templateComponentFactory = templateComponentFactory;
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 (0, mtl_1.html)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["<", " data-ref=", " ...", ">\n ", "\n ", "\n </", ">"], ["<", " data-ref=", " ...", ">\n ", "\n ", "\n </", ">"])), tag, ref, componentAttributes, jsonProps ? (0, jsonScriptTemplate_1.jsonScriptTemplate)(jsonProps) : '', children, tag);
}
exports.renderComponentWrapper = renderComponentWrapper;
var templateObject_1;