all files / src/ template.js

88.46% Statements 23/26
68.75% Branches 11/16
100% Functions 3/3
88.46% Lines 23/26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                                      
define(["require", "exports", "@syncfusion/ej2-base", "react-dom", "react"], function (require, exports, ej2_base_1, ReactDOM, React) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var stringCompiler = ej2_base_1.getTemplateEngine();
    function compile(templateElement, helper) {
        Iif (typeof templateElement === 'string' || (templateElement.prototype && templateElement.prototype.CSPTemplate && typeof templateElement === 'function')) {
            return stringCompiler(templateElement, helper);
        }
        else {
            return function (data, component, prop, element) {
                var actTemplate = templateElement;
                var actData = data;
                if (typeof actTemplate === 'object') {
                    actTemplate = templateElement.template;
                    actData = ej2_base_1.extend({}, data, templateElement.data || {});
                }
                var cEle;
                Iif (element) {
                    cEle = element;
                }
                else {
                    cEle = document.createElement('div');
                }
                var rele = React.createElement(actTemplate, actData);
                var portal = ReactDOM.createPortal(rele, cEle);
                portal.propName = prop;
                Eif (!component.portals) {
                    component.portals = [portal];
                }
                else {
                    component.portals.push(portal);
                }
                Eif (!element) {
                    return [cEle];
                }
            };
        }
    }
    exports.compile = compile;
    ej2_base_1.setTemplateEngine({ compile: compile });
});