{"version":3,"file":"Template.js","names":["onTemplateLoad","options","template","content","default","data","isPlainHTML","frag","document","createRange","createContextualFragment","component","querySelector","Event","emit","onTemplateLoadError","error","loadTemplate","templateName","SystemJS","import","then","bind","catch","Promise","resolve","Error","b","a","setters","execute"],"sources":["services/Template.js"],"sourcesContent":["import 'core/templateHelpers';\nimport { Event } from 'services/EventEmitter';\n\n/**\n * Callback when template is loaded\n * @param {object} options - options passed to the template\n * @param {string} template - HTML structure\n * @returns {HTMLElement} - HTML Element\n */\nfunction onTemplateLoad(options, template) {\n const content = template.default(options.data);\n\n if (options.isPlainHTML) {\n return content;\n }\n\n const frag = document.createRange().createContextualFragment(content);\n const component = frag.querySelector('[data-component]');\n if (component) {\n Event.emit('registry.registerChildren', frag);\n }\n return frag;\n}\n\n/**\n * Error callback on template load\n * @param {object} error - Error thrown\n * @returns {object} error\n */\nfunction onTemplateLoadError(error) {\n return error;\n}\n\n/**\n * Load the template with its data\n * @param {Object} options - Data to be processed by the template\n * @returns {Promise} promise - Promise\n */\nexport function loadTemplate(options) {\n const { templateName, template } = options;\n if (templateName) {\n // In case of templateName (templatePath) we need to fetch the template\n return SystemJS.import(`templates/${templateName}`)\n .then(onTemplateLoad.bind(this, options))\n .catch(onTemplateLoadError.bind(this));\n }\n if (template) {\n // In case the template is provided directly in HTML format\n return Promise.resolve()\n .then(onTemplateLoad.bind(this, options));\n }\n\n throw new Error('loadTemplate is missing a template or templateName param');\n}\n"],"mappings":"uGASA,QAAS,CAAAA,cAAcA,CAACC,CAAO,CAAEC,CAAQ,CAAE,CACvC,KAAM,CAAAC,CAAO,CAAGD,CAAQ,CAACE,OAAO,CAACH,CAAO,CAACI,IAAI,CAAC,CAE9C,GAAIJ,CAAO,CAACK,WAAW,CACnB,MAAO,CAAAH,CAAO,CACjB,KAEK,CAAAI,CAAI,CAAGC,QAAQ,CAACC,WAAW,CAAC,CAAC,CAACC,wBAAwB,CAACP,CAAO,CAAC,CAC/DQ,CAAS,CAAGJ,CAAI,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