es5-lit-html
Version:
An ES5 transpiled version of lit-html
75 lines (59 loc) • 2.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.defaultTemplateProcessor = exports.DefaultTemplateProcessor = void 0;
var _parts = require("./parts.js");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* Creates Parts when a template is instantiated.
*/
var DefaultTemplateProcessor =
/*#__PURE__*/
function () {
function DefaultTemplateProcessor() {
_classCallCheck(this, DefaultTemplateProcessor);
}
_createClass(DefaultTemplateProcessor, [{
key: "handleAttributeExpressions",
/**
* Create parts for an attribute-position binding, given the event, attribute
* name, and string literals.
*
* @param element The element containing the binding
* @param name The attribute name
* @param strings The string literals. There are always at least two strings,
* event for fully-controlled bindings with a single expression.
*/
value: function handleAttributeExpressions(element, name, strings, options) {
var prefix = name[0];
if (prefix === '.') {
var _committer = new _parts.PropertyCommitter(element, name.slice(1), strings);
return _committer.parts;
}
if (prefix === '@') {
return [new _parts.EventPart(element, name.slice(1), options.eventContext)];
}
if (prefix === '?') {
return [new _parts.BooleanAttributePart(element, name.slice(1), strings)];
}
var committer = new _parts.AttributeCommitter(element, name, strings);
return committer.parts;
}
/**
* Create parts for a text-position binding.
* @param templateFactory
*/
}, {
key: "handleTextExpression",
value: function handleTextExpression(options) {
return new _parts.NodePart(options);
}
}]);
return DefaultTemplateProcessor;
}();
exports.DefaultTemplateProcessor = DefaultTemplateProcessor;
var defaultTemplateProcessor = new DefaultTemplateProcessor();
exports.defaultTemplateProcessor = defaultTemplateProcessor;