UNPKG

@rxdi/ui-kit

Version:

UI Components for building graphql-server website

36 lines 1.84 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Template = Template; const lit_html_1 = require("@rxdi/lit-html"); const interpolate2 = (template, params = {}) => new Function(...Object.keys(params), `return \`${template}\`;`)(...Object.values(params)); const regexes = [/\${[^{]+}/g, /\@\{(.*?)(?!\@\{)\}/g, /{(.*?)}/g]; function Template(options) { function interpolate(string) { return string.replace(regexes[0], (match) => match .slice(2, -1) .trim() .split('.') .reduce((el, k) => String(el[k]), this)); } return function (target) { target.prototype['getTemplate'] = function () { return __awaiter(this, void 0, void 0, function* () { return (0, lit_html_1.unsafeHTML)(interpolate.call(this, yield options.templateUrl)); }); }; target.prototype['render'] = function () { return (0, lit_html_1.html) ` ${(0, lit_html_1.async)(this.getTemplate())} `; }; return (0, lit_html_1.Component)(options)(target); }; } //# sourceMappingURL=template.decorator.js.map