aurelia-templating
Version:
An extensible HTML templating engine supporting databinding, custom elements, attached behaviors and more.
1,566 lines (1,228 loc) • 160 kB
JavaScript
var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _class, _temp, _dec, _class2, _dec2, _class3, _dec3, _class4, _dec4, _class5, _dec5, _class6, _dec6, _class7, _class8, _temp2, _class9, _temp3, _class11, _dec7, _class13, _dec8, _class14, _class15, _temp4, _dec9, _class16, _dec10, _class17, _dec11, _class18;
import * as LogManager from 'aurelia-logging';
import { metadata, Origin, protocol } from 'aurelia-metadata';
import { DOM, PLATFORM, FEATURE } from 'aurelia-pal';
import { TemplateRegistryEntry, Loader } from 'aurelia-loader';
import { relativeToFile } from 'aurelia-path';
import { Scope, Expression, ValueConverterResource, BindingBehaviorResource, camelCase, Binding, createOverrideContext, subscriberCollection, bindingMode, ObserverLocator, EventManager } from 'aurelia-binding';
import { Container, resolver, inject } from 'aurelia-dependency-injection';
import { TaskQueue } from 'aurelia-task-queue';
export var animationEvent = {
enterBegin: 'animation:enter:begin',
enterActive: 'animation:enter:active',
enterDone: 'animation:enter:done',
enterTimeout: 'animation:enter:timeout',
leaveBegin: 'animation:leave:begin',
leaveActive: 'animation:leave:active',
leaveDone: 'animation:leave:done',
leaveTimeout: 'animation:leave:timeout',
staggerNext: 'animation:stagger:next',
removeClassBegin: 'animation:remove-class:begin',
removeClassActive: 'animation:remove-class:active',
removeClassDone: 'animation:remove-class:done',
removeClassTimeout: 'animation:remove-class:timeout',
addClassBegin: 'animation:add-class:begin',
addClassActive: 'animation:add-class:active',
addClassDone: 'animation:add-class:done',
addClassTimeout: 'animation:add-class:timeout',
animateBegin: 'animation:animate:begin',
animateActive: 'animation:animate:active',
animateDone: 'animation:animate:done',
animateTimeout: 'animation:animate:timeout',
sequenceBegin: 'animation:sequence:begin',
sequenceDone: 'animation:sequence:done'
};
export var Animator = function () {
function Animator() {
}
Animator.prototype.enter = function enter(element) {
return Promise.resolve(false);
};
Animator.prototype.leave = function leave(element) {
return Promise.resolve(false);
};
Animator.prototype.removeClass = function removeClass(element, className) {
element.classList.remove(className);
return Promise.resolve(false);
};
Animator.prototype.addClass = function addClass(element, className) {
element.classList.add(className);
return Promise.resolve(false);
};
Animator.prototype.animate = function animate(element, className) {
return Promise.resolve(false);
};
Animator.prototype.runSequence = function runSequence(animations) {};
Animator.prototype.registerEffect = function registerEffect(effectName, properties) {};
Animator.prototype.unregisterEffect = function unregisterEffect(effectName) {};
return Animator;
}();
export var CompositionTransactionNotifier = function () {
function CompositionTransactionNotifier(owner) {
this.owner = owner;
this.owner._compositionCount++;
}
CompositionTransactionNotifier.prototype.done = function done() {
this.owner._compositionCount--;
this.owner._tryCompleteTransaction();
};
return CompositionTransactionNotifier;
}();
export var CompositionTransactionOwnershipToken = function () {
function CompositionTransactionOwnershipToken(owner) {
this.owner = owner;
this.owner._ownershipToken = this;
this.thenable = this._createThenable();
}
CompositionTransactionOwnershipToken.prototype.waitForCompositionComplete = function waitForCompositionComplete() {
this.owner._tryCompleteTransaction();
return this.thenable;
};
CompositionTransactionOwnershipToken.prototype.resolve = function resolve() {
this._resolveCallback();
};
CompositionTransactionOwnershipToken.prototype._createThenable = function _createThenable() {
var _this = this;
return new Promise(function (resolve, reject) {
_this._resolveCallback = resolve;
});
};
return CompositionTransactionOwnershipToken;
}();
export var CompositionTransaction = function () {
function CompositionTransaction() {
this._ownershipToken = null;
this._compositionCount = 0;
}
CompositionTransaction.prototype.tryCapture = function tryCapture() {
return this._ownershipToken === null ? new CompositionTransactionOwnershipToken(this) : null;
};
CompositionTransaction.prototype.enlist = function enlist() {
return new CompositionTransactionNotifier(this);
};
CompositionTransaction.prototype._tryCompleteTransaction = function _tryCompleteTransaction() {
if (this._compositionCount <= 0) {
this._compositionCount = 0;
if (this._ownershipToken !== null) {
var token = this._ownershipToken;
this._ownershipToken = null;
token.resolve();
}
}
};
return CompositionTransaction;
}();
var capitalMatcher = /([A-Z])/g;
function addHyphenAndLower(char) {
return '-' + char.toLowerCase();
}
export function _hyphenate(name) {
return (name.charAt(0).toLowerCase() + name.slice(1)).replace(capitalMatcher, addHyphenAndLower);
}
export function _isAllWhitespace(node) {
return !(node.auInterpolationTarget || /[^\t\n\r ]/.test(node.textContent));
}
export var ViewEngineHooksResource = function () {
function ViewEngineHooksResource() {
}
ViewEngineHooksResource.prototype.initialize = function initialize(container, target) {
this.instance = container.get(target);
};
ViewEngineHooksResource.prototype.register = function register(registry, name) {
registry.registerViewEngineHooks(this.instance);
};
ViewEngineHooksResource.prototype.load = function load(container, target) {};
ViewEngineHooksResource.convention = function convention(name) {
if (name.endsWith('ViewEngineHooks')) {
return new ViewEngineHooksResource();
}
};
return ViewEngineHooksResource;
}();
export function viewEngineHooks(target) {
var deco = function deco(t) {
metadata.define(metadata.resource, new ViewEngineHooksResource(), t);
};
return target ? deco(target) : deco;
}
export var ElementEvents = function () {
function ElementEvents(element) {
this.element = element;
this.subscriptions = {};
}
ElementEvents.prototype._enqueueHandler = function _enqueueHandler(handler) {
this.subscriptions[handler.eventName] = this.subscriptions[handler.eventName] || [];
this.subscriptions[handler.eventName].push(handler);
};
ElementEvents.prototype._dequeueHandler = function _dequeueHandler(handler) {
var index = void 0;
var subscriptions = this.subscriptions[handler.eventName];
if (subscriptions) {
index = subscriptions.indexOf(handler);
if (index > -1) {
subscriptions.splice(index, 1);
}
}
return handler;
};
ElementEvents.prototype.publish = function publish(eventName) {
var detail = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var bubbles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var cancelable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
var event = DOM.createCustomEvent(eventName, { cancelable: cancelable, bubbles: bubbles, detail: detail });
this.element.dispatchEvent(event);
};
ElementEvents.prototype.subscribe = function subscribe(eventName, handler) {
var captureOrOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
if (typeof handler === 'function') {
var eventHandler = new EventHandlerImpl(this, eventName, handler, captureOrOptions, false);
return eventHandler;
}
return undefined;
};
ElementEvents.prototype.subscribeOnce = function subscribeOnce(eventName, handler) {
var captureOrOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
if (typeof handler === 'function') {
var eventHandler = new EventHandlerImpl(this, eventName, handler, captureOrOptions, true);
return eventHandler;
}
return undefined;
};
ElementEvents.prototype.dispose = function dispose(eventName) {
if (eventName && typeof eventName === 'string') {
var subscriptions = this.subscriptions[eventName];
if (subscriptions) {
while (subscriptions.length) {
var subscription = subscriptions.pop();
if (subscription) {
subscription.dispose();
}
}
}
} else {
this.disposeAll();
}
};
ElementEvents.prototype.disposeAll = function disposeAll() {
for (var _key in this.subscriptions) {
this.dispose(_key);
}
};
return ElementEvents;
}();
var EventHandlerImpl = function () {
function EventHandlerImpl(owner, eventName, handler, captureOrOptions, once) {
this.owner = owner;
this.eventName = eventName;
this.handler = handler;
this.capture = typeof captureOrOptions === 'boolean' ? captureOrOptions : captureOrOptions.capture;
this.bubbles = !this.capture;
this.captureOrOptions = captureOrOptions;
this.once = once;
owner.element.addEventListener(eventName, this, captureOrOptions);
owner._enqueueHandler(this);
}
EventHandlerImpl.prototype.handleEvent = function handleEvent(e) {
var fn = this.handler;
fn(e);
if (this.once) {
this.dispose();
}
};
EventHandlerImpl.prototype.dispose = function dispose() {
this.owner.element.removeEventListener(this.eventName, this, this.captureOrOptions);
this.owner._dequeueHandler(this);
this.owner = this.handler = null;
};
return EventHandlerImpl;
}();
export var ResourceLoadContext = function () {
function ResourceLoadContext() {
this.dependencies = {};
}
ResourceLoadContext.prototype.addDependency = function addDependency(url) {
this.dependencies[url] = true;
};
ResourceLoadContext.prototype.hasDependency = function hasDependency(url) {
return url in this.dependencies;
};
return ResourceLoadContext;
}();
export var ViewCompileInstruction = function ViewCompileInstruction() {
var targetShadowDOM = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var compileSurrogate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
this.targetShadowDOM = targetShadowDOM;
this.compileSurrogate = compileSurrogate;
this.associatedModuleId = null;
};
ViewCompileInstruction.normal = new ViewCompileInstruction();
export var BehaviorInstruction = function () {
function BehaviorInstruction() {
}
BehaviorInstruction.enhance = function enhance() {
var instruction = new BehaviorInstruction();
instruction.enhance = true;
return instruction;
};
BehaviorInstruction.unitTest = function unitTest(type, attributes) {
var instruction = new BehaviorInstruction();
instruction.type = type;
instruction.attributes = attributes || {};
return instruction;
};
BehaviorInstruction.element = function element(node, type) {
var instruction = new BehaviorInstruction();
instruction.type = type;
instruction.attributes = {};
instruction.anchorIsContainer = !(node.hasAttribute('containerless') || type.containerless);
instruction.initiatedByBehavior = true;
return instruction;
};
BehaviorInstruction.attribute = function attribute(attrName, type) {
var instruction = new BehaviorInstruction();
instruction.attrName = attrName;
instruction.type = type || null;
instruction.attributes = {};
return instruction;
};
BehaviorInstruction.dynamic = function dynamic(host, viewModel, viewFactory) {
var instruction = new BehaviorInstruction();
instruction.host = host;
instruction.viewModel = viewModel;
instruction.viewFactory = viewFactory;
instruction.inheritBindingContext = true;
return instruction;
};
return BehaviorInstruction;
}();
var biProto = BehaviorInstruction.prototype;
biProto.initiatedByBehavior = false;
biProto.enhance = false;
biProto.partReplacements = null;
biProto.viewFactory = null;
biProto.originalAttrName = null;
biProto.skipContentProcessing = false;
biProto.contentFactory = null;
biProto.viewModel = null;
biProto.anchorIsContainer = false;
biProto.host = null;
biProto.attributes = null;
biProto.type = null;
biProto.attrName = null;
biProto.inheritBindingContext = false;
BehaviorInstruction.normal = new BehaviorInstruction();
export var TargetInstruction = (_temp = _class = function () {
function TargetInstruction() {
}
TargetInstruction.shadowSlot = function shadowSlot(parentInjectorId) {
var instruction = new TargetInstruction();
instruction.parentInjectorId = parentInjectorId;
instruction.shadowSlot = true;
return instruction;
};
TargetInstruction.contentExpression = function contentExpression(expression) {
var instruction = new TargetInstruction();
instruction.contentExpression = expression;
return instruction;
};
TargetInstruction.letElement = function letElement(expressions) {
var instruction = new TargetInstruction();
instruction.expressions = expressions;
instruction.letElement = true;
return instruction;
};
TargetInstruction.lifting = function lifting(parentInjectorId, liftingInstruction) {
var instruction = new TargetInstruction();
instruction.parentInjectorId = parentInjectorId;
instruction.expressions = TargetInstruction.noExpressions;
instruction.behaviorInstructions = [liftingInstruction];
instruction.viewFactory = liftingInstruction.viewFactory;
instruction.providers = [liftingInstruction.type.target];
instruction.lifting = true;
return instruction;
};
TargetInstruction.normal = function normal(injectorId, parentInjectorId, providers, behaviorInstructions, expressions, elementInstruction) {
var instruction = new TargetInstruction();
instruction.injectorId = injectorId;
instruction.parentInjectorId = parentInjectorId;
instruction.providers = providers;
instruction.behaviorInstructions = behaviorInstructions;
instruction.expressions = expressions;
instruction.anchorIsContainer = elementInstruction ? elementInstruction.anchorIsContainer : true;
instruction.elementInstruction = elementInstruction;
return instruction;
};
TargetInstruction.surrogate = function surrogate(providers, behaviorInstructions, expressions, values) {
var instruction = new TargetInstruction();
instruction.expressions = expressions;
instruction.behaviorInstructions = behaviorInstructions;
instruction.providers = providers;
instruction.values = values;
return instruction;
};
return TargetInstruction;
}(), _class.noExpressions = Object.freeze([]), _temp);
var tiProto = TargetInstruction.prototype;
tiProto.injectorId = null;
tiProto.parentInjectorId = null;
tiProto.shadowSlot = false;
tiProto.slotName = null;
tiProto.slotFallbackFactory = null;
tiProto.contentExpression = null;
tiProto.letElement = false;
tiProto.expressions = null;
tiProto.expressions = null;
tiProto.providers = null;
tiProto.viewFactory = null;
tiProto.anchorIsContainer = false;
tiProto.elementInstruction = null;
tiProto.lifting = false;
tiProto.values = null;
export var viewStrategy = protocol.create('aurelia:view-strategy', {
validate: function validate(target) {
if (!(typeof target.loadViewFactory === 'function')) {
return 'View strategies must implement: loadViewFactory(viewEngine: ViewEngine, compileInstruction: ViewCompileInstruction, loadContext?: ResourceLoadContext): Promise<ViewFactory>';
}
return true;
},
compose: function compose(target) {
if (!(typeof target.makeRelativeTo === 'function')) {
target.makeRelativeTo = PLATFORM.noop;
}
}
});
export var RelativeViewStrategy = (_dec = viewStrategy(), _dec(_class2 = function () {
function RelativeViewStrategy(path) {
this.path = path;
this.absolutePath = null;
}
RelativeViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, compileInstruction, loadContext, target) {
if (this.absolutePath === null && this.moduleId) {
this.absolutePath = relativeToFile(this.path, this.moduleId);
}
compileInstruction.associatedModuleId = this.moduleId;
return viewEngine.loadViewFactory(this.absolutePath || this.path, compileInstruction, loadContext, target);
};
RelativeViewStrategy.prototype.makeRelativeTo = function makeRelativeTo(file) {
if (this.absolutePath === null) {
this.absolutePath = relativeToFile(this.path, file);
}
};
return RelativeViewStrategy;
}()) || _class2);
export var ConventionalViewStrategy = (_dec2 = viewStrategy(), _dec2(_class3 = function () {
function ConventionalViewStrategy(viewLocator, origin) {
this.moduleId = origin.moduleId;
this.viewUrl = viewLocator.convertOriginToViewUrl(origin);
}
ConventionalViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, compileInstruction, loadContext, target) {
compileInstruction.associatedModuleId = this.moduleId;
return viewEngine.loadViewFactory(this.viewUrl, compileInstruction, loadContext, target);
};
return ConventionalViewStrategy;
}()) || _class3);
export var NoViewStrategy = (_dec3 = viewStrategy(), _dec3(_class4 = function () {
function NoViewStrategy(dependencies, dependencyBaseUrl) {
this.dependencies = dependencies || null;
this.dependencyBaseUrl = dependencyBaseUrl || '';
}
NoViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, compileInstruction, loadContext, target) {
var entry = this.entry;
var dependencies = this.dependencies;
if (entry && entry.factoryIsReady) {
return Promise.resolve(null);
}
this.entry = entry = new TemplateRegistryEntry(this.moduleId || this.dependencyBaseUrl);
entry.dependencies = [];
entry.templateIsLoaded = true;
if (dependencies !== null) {
for (var i = 0, ii = dependencies.length; i < ii; ++i) {
var current = dependencies[i];
if (typeof current === 'string' || typeof current === 'function') {
entry.addDependency(current);
} else {
entry.addDependency(current.from, current.as);
}
}
}
compileInstruction.associatedModuleId = this.moduleId;
return viewEngine.loadViewFactory(entry, compileInstruction, loadContext, target);
};
return NoViewStrategy;
}()) || _class4);
export var TemplateRegistryViewStrategy = (_dec4 = viewStrategy(), _dec4(_class5 = function () {
function TemplateRegistryViewStrategy(moduleId, entry) {
this.moduleId = moduleId;
this.entry = entry;
}
TemplateRegistryViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, compileInstruction, loadContext, target) {
var entry = this.entry;
if (entry.factoryIsReady) {
return Promise.resolve(entry.factory);
}
compileInstruction.associatedModuleId = this.moduleId;
return viewEngine.loadViewFactory(entry, compileInstruction, loadContext, target);
};
return TemplateRegistryViewStrategy;
}()) || _class5);
export var InlineViewStrategy = (_dec5 = viewStrategy(), _dec5(_class6 = function () {
function InlineViewStrategy(markup, dependencies, dependencyBaseUrl) {
this.markup = markup;
this.dependencies = dependencies || null;
this.dependencyBaseUrl = dependencyBaseUrl || '';
}
InlineViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, compileInstruction, loadContext, target) {
var entry = this.entry;
var dependencies = this.dependencies;
if (entry && entry.factoryIsReady) {
return Promise.resolve(entry.factory);
}
this.entry = entry = new TemplateRegistryEntry(this.moduleId || this.dependencyBaseUrl);
entry.template = DOM.createTemplateFromMarkup(this.markup);
if (dependencies !== null) {
for (var i = 0, ii = dependencies.length; i < ii; ++i) {
var current = dependencies[i];
if (typeof current === 'string' || typeof current === 'function') {
entry.addDependency(current);
} else {
entry.addDependency(current.from, current.as);
}
}
}
compileInstruction.associatedModuleId = this.moduleId;
return viewEngine.loadViewFactory(entry, compileInstruction, loadContext, target);
};
return InlineViewStrategy;
}()) || _class6);
export var StaticViewStrategy = (_dec6 = viewStrategy(), _dec6(_class7 = function () {
function StaticViewStrategy(config) {
if (typeof config === 'string' || config instanceof DOM.Element && config.tagName === 'TEMPLATE') {
config = {
template: config
};
}
this.template = config.template;
this.dependencies = config.dependencies || [];
this.factoryIsReady = false;
this.onReady = null;
this.moduleId = 'undefined';
}
StaticViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, compileInstruction, loadContext, target) {
var _this2 = this;
if (this.factoryIsReady) {
return Promise.resolve(this.factory);
}
var deps = this.dependencies;
deps = typeof deps === 'function' ? deps() : deps;
deps = deps ? deps : [];
deps = Array.isArray(deps) ? deps : [deps];
return Promise.all(deps).then(function (dependencies) {
var container = viewEngine.container;
var appResources = viewEngine.appResources;
var viewCompiler = viewEngine.viewCompiler;
var viewResources = new ViewResources(appResources);
var resource = void 0;
var elDeps = [];
if (target) {
viewResources.autoRegister(container, target);
}
for (var _iterator = dependencies, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var dep = _ref;
if (typeof dep === 'function') {
resource = viewResources.autoRegister(container, dep);
} else if (dep && (typeof dep === 'undefined' ? 'undefined' : _typeof(dep)) === 'object') {
for (var _key2 in dep) {
var exported = dep[_key2];
if (typeof exported === 'function') {
resource = viewResources.autoRegister(container, exported);
}
}
} else {
throw new Error('dependency neither function nor object. Received: "' + (typeof dep === 'undefined' ? 'undefined' : _typeof(dep)) + '"');
}
if (resource.elementName !== null) {
elDeps.push(resource);
}
}
return Promise.all(elDeps.map(function (el) {
return el.load(container, el.target);
})).then(function () {
var factory = _this2.template !== null ? viewCompiler.compile(_this2.template, viewResources, compileInstruction) : null;
_this2.factoryIsReady = true;
_this2.factory = factory;
return factory;
});
});
};
return StaticViewStrategy;
}()) || _class7);
export var ViewLocator = (_temp2 = _class8 = function () {
function ViewLocator() {
}
ViewLocator.prototype.getViewStrategy = function getViewStrategy(value) {
if (!value) {
return null;
}
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && 'getViewStrategy' in value) {
var _origin = Origin.get(value.constructor);
value = value.getViewStrategy();
if (typeof value === 'string') {
value = new RelativeViewStrategy(value);
}
viewStrategy.assert(value);
if (_origin.moduleId) {
value.makeRelativeTo(_origin.moduleId);
}
return value;
}
if (typeof value === 'string') {
value = new RelativeViewStrategy(value);
}
if (viewStrategy.validate(value)) {
return value;
}
if (typeof value !== 'function') {
value = value.constructor;
}
if ('$view' in value) {
var c = value.$view;
var _view = void 0;
c = typeof c === 'function' ? c.call(value) : c;
if (c === null) {
_view = new NoViewStrategy();
} else {
_view = c instanceof StaticViewStrategy ? c : new StaticViewStrategy(c);
}
metadata.define(ViewLocator.viewStrategyMetadataKey, _view, value);
return _view;
}
var origin = Origin.get(value);
var strategy = metadata.get(ViewLocator.viewStrategyMetadataKey, value);
if (!strategy) {
if (!origin.moduleId) {
throw new Error('Cannot determine default view strategy for object.', value);
}
strategy = this.createFallbackViewStrategy(origin);
} else if (origin.moduleId) {
strategy.moduleId = origin.moduleId;
}
return strategy;
};
ViewLocator.prototype.createFallbackViewStrategy = function createFallbackViewStrategy(origin) {
return new ConventionalViewStrategy(this, origin);
};
ViewLocator.prototype.convertOriginToViewUrl = function convertOriginToViewUrl(origin) {
var moduleId = origin.moduleId;
var id = moduleId.endsWith('.js') || moduleId.endsWith('.ts') ? moduleId.substring(0, moduleId.length - 3) : moduleId;
return id + '.html';
};
return ViewLocator;
}(), _class8.viewStrategyMetadataKey = 'aurelia:view-strategy', _temp2);
function mi(name) {
throw new Error('BindingLanguage must implement ' + name + '().');
}
export var BindingLanguage = function () {
function BindingLanguage() {
}
BindingLanguage.prototype.inspectAttribute = function inspectAttribute(resources, elementName, attrName, attrValue) {
mi('inspectAttribute');
};
BindingLanguage.prototype.createAttributeInstruction = function createAttributeInstruction(resources, element, info, existingInstruction) {
mi('createAttributeInstruction');
};
BindingLanguage.prototype.createLetExpressions = function createLetExpressions(resources, element) {
mi('createLetExpressions');
};
BindingLanguage.prototype.inspectTextContent = function inspectTextContent(resources, value) {
mi('inspectTextContent');
};
return BindingLanguage;
}();
var noNodes = Object.freeze([]);
export var SlotCustomAttribute = function () {
SlotCustomAttribute.inject = function inject() {
return [DOM.Element];
};
function SlotCustomAttribute(element) {
this.element = element;
this.element.auSlotAttribute = this;
}
SlotCustomAttribute.prototype.valueChanged = function valueChanged(newValue, oldValue) {};
return SlotCustomAttribute;
}();
export var PassThroughSlot = function () {
function PassThroughSlot(anchor, name, destinationName, fallbackFactory) {
this.anchor = anchor;
this.anchor.viewSlot = this;
this.name = name;
this.destinationName = destinationName;
this.fallbackFactory = fallbackFactory;
this.destinationSlot = null;
this.projections = 0;
this.contentView = null;
var attr = new SlotCustomAttribute(this.anchor);
attr.value = this.destinationName;
}
PassThroughSlot.prototype.renderFallbackContent = function renderFallbackContent(view, nodes, projectionSource, index) {
if (this.contentView === null) {
this.contentView = this.fallbackFactory.create(this.ownerView.container);
this.contentView.bind(this.ownerView.bindingContext, this.ownerView.overrideContext);
var slots = Object.create(null);
slots[this.destinationSlot.name] = this.destinationSlot;
ShadowDOM.distributeView(this.contentView, slots, projectionSource, index, this.destinationSlot.name);
}
};
PassThroughSlot.prototype.passThroughTo = function passThroughTo(destinationSlot) {
this.destinationSlot = destinationSlot;
};
PassThroughSlot.prototype.addNode = function addNode(view, node, projectionSource, index) {
if (this.contentView !== null) {
this.contentView.removeNodes();
this.contentView.detached();
this.contentView.unbind();
this.contentView = null;
}
if (node.viewSlot instanceof PassThroughSlot) {
node.viewSlot.passThroughTo(this);
return;
}
this.projections++;
this.destinationSlot.addNode(view, node, projectionSource, index);
};
PassThroughSlot.prototype.removeView = function removeView(view, projectionSource) {
this.projections--;
this.destinationSlot.removeView(view, projectionSource);
if (this.needsFallbackRendering) {
this.renderFallbackContent(null, noNodes, projectionSource);
}
};
PassThroughSlot.prototype.removeAll = function removeAll(projectionSource) {
this.projections = 0;
this.destinationSlot.removeAll(projectionSource);
if (this.needsFallbackRendering) {
this.renderFallbackContent(null, noNodes, projectionSource);
}
};
PassThroughSlot.prototype.projectFrom = function projectFrom(view, projectionSource) {
this.destinationSlot.projectFrom(view, projectionSource);
};
PassThroughSlot.prototype.created = function created(ownerView) {
this.ownerView = ownerView;
};
PassThroughSlot.prototype.bind = function bind(view) {
if (this.contentView) {
this.contentView.bind(view.bindingContext, view.overrideContext);
}
};
PassThroughSlot.prototype.attached = function attached() {
if (this.contentView) {
this.contentView.attached();
}
};
PassThroughSlot.prototype.detached = function detached() {
if (this.contentView) {
this.contentView.detached();
}
};
PassThroughSlot.prototype.unbind = function unbind() {
if (this.contentView) {
this.contentView.unbind();
}
};
_createClass(PassThroughSlot, [{
key: 'needsFallbackRendering',
get: function get() {
return this.fallbackFactory && this.projections === 0;
}
}]);
return PassThroughSlot;
}();
export var ShadowSlot = function () {
function ShadowSlot(anchor, name, fallbackFactory) {
this.anchor = anchor;
this.anchor.isContentProjectionSource = true;
this.anchor.viewSlot = this;
this.name = name;
this.fallbackFactory = fallbackFactory;
this.contentView = null;
this.projections = 0;
this.children = [];
this.projectFromAnchors = null;
this.destinationSlots = null;
}
ShadowSlot.prototype.addNode = function addNode(view, node, projectionSource, index, destination) {
if (this.contentView !== null) {
this.contentView.removeNodes();
this.contentView.detached();
this.contentView.unbind();
this.contentView = null;
}
if (node.viewSlot instanceof PassThroughSlot) {
node.viewSlot.passThroughTo(this);
return;
}
if (this.destinationSlots !== null) {
ShadowDOM.distributeNodes(view, [node], this.destinationSlots, this, index);
} else {
node.auOwnerView = view;
node.auProjectionSource = projectionSource;
node.auAssignedSlot = this;
var anchor = this._findAnchor(view, node, projectionSource, index);
var parent = anchor.parentNode;
parent.insertBefore(node, anchor);
this.children.push(node);
this.projections++;
}
};
ShadowSlot.prototype.removeView = function removeView(view, projectionSource) {
if (this.destinationSlots !== null) {
ShadowDOM.undistributeView(view, this.destinationSlots, this);
} else if (this.contentView && this.contentView.hasSlots) {
ShadowDOM.undistributeView(view, this.contentView.slots, projectionSource);
} else {
var found = this.children.find(function (x) {
return x.auSlotProjectFrom === projectionSource;
});
if (found) {
var _children = found.auProjectionChildren;
for (var i = 0, ii = _children.length; i < ii; ++i) {
var _child = _children[i];
if (_child.auOwnerView === view) {
_children.splice(i, 1);
view.fragment.appendChild(_child);
i--;ii--;
this.projections--;
}
}
if (this.needsFallbackRendering) {
this.renderFallbackContent(view, noNodes, projectionSource);
}
}
}
};
ShadowSlot.prototype.removeAll = function removeAll(projectionSource) {
if (this.destinationSlots !== null) {
ShadowDOM.undistributeAll(this.destinationSlots, this);
} else if (this.contentView && this.contentView.hasSlots) {
ShadowDOM.undistributeAll(this.contentView.slots, projectionSource);
} else {
var found = this.children.find(function (x) {
return x.auSlotProjectFrom === projectionSource;
});
if (found) {
var _children2 = found.auProjectionChildren;
for (var i = 0, ii = _children2.length; i < ii; ++i) {
var _child2 = _children2[i];
_child2.auOwnerView.fragment.appendChild(_child2);
this.projections--;
}
found.auProjectionChildren = [];
if (this.needsFallbackRendering) {
this.renderFallbackContent(null, noNodes, projectionSource);
}
}
}
};
ShadowSlot.prototype._findAnchor = function _findAnchor(view, node, projectionSource, index) {
if (projectionSource) {
var found = this.children.find(function (x) {
return x.auSlotProjectFrom === projectionSource;
});
if (found) {
if (index !== undefined) {
var _children3 = found.auProjectionChildren;
var viewIndex = -1;
var lastView = void 0;
for (var i = 0, ii = _children3.length; i < ii; ++i) {
var current = _children3[i];
if (current.auOwnerView !== lastView) {
viewIndex++;
lastView = current.auOwnerView;
if (viewIndex >= index && lastView !== view) {
_children3.splice(i, 0, node);
return current;
}
}
}
}
found.auProjectionChildren.push(node);
return found;
}
}
return this.anchor;
};
ShadowSlot.prototype.projectTo = function projectTo(slots) {
this.destinationSlots = slots;
};
ShadowSlot.prototype.projectFrom = function projectFrom(view, projectionSource) {
var anchor = DOM.createComment('anchor');
var parent = this.anchor.parentNode;
anchor.auSlotProjectFrom = projectionSource;
anchor.auOwnerView = view;
anchor.auProjectionChildren = [];
parent.insertBefore(anchor, this.anchor);
this.children.push(anchor);
if (this.projectFromAnchors === null) {
this.projectFromAnchors = [];
}
this.projectFromAnchors.push(anchor);
};
ShadowSlot.prototype.renderFallbackContent = function renderFallbackContent(view, nodes, projectionSource, index) {
if (this.contentView === null) {
this.contentView = this.fallbackFactory.create(this.ownerView.container);
this.contentView.bind(this.ownerView.bindingContext, this.ownerView.overrideContext);
this.contentView.insertNodesBefore(this.anchor);
}
if (this.contentView.hasSlots) {
var slots = this.contentView.slots;
var projectFromAnchors = this.projectFromAnchors;
if (projectFromAnchors !== null) {
for (var slotName in slots) {
var slot = slots[slotName];
for (var i = 0, ii = projectFromAnchors.length; i < ii; ++i) {
var anchor = projectFromAnchors[i];
slot.projectFrom(anchor.auOwnerView, anchor.auSlotProjectFrom);
}
}
}
this.fallbackSlots = slots;
ShadowDOM.distributeNodes(view, nodes, slots, projectionSource, index);
}
};
ShadowSlot.prototype.created = function created(ownerView) {
this.ownerView = ownerView;
};
ShadowSlot.prototype.bind = function bind(view) {
if (this.contentView) {
this.contentView.bind(view.bindingContext, view.overrideContext);
}
};
ShadowSlot.prototype.attached = function attached() {
if (this.contentView) {
this.contentView.attached();
}
};
ShadowSlot.prototype.detached = function detached() {
if (this.contentView) {
this.contentView.detached();
}
};
ShadowSlot.prototype.unbind = function unbind() {
if (this.contentView) {
this.contentView.unbind();
}
};
_createClass(ShadowSlot, [{
key: 'needsFallbackRendering',
get: function get() {
return this.fallbackFactory && this.projections === 0;
}
}]);
return ShadowSlot;
}();
export var ShadowDOM = (_temp3 = _class9 = function () {
function ShadowDOM() {
}
ShadowDOM.getSlotName = function getSlotName(node) {
if (node.auSlotAttribute === undefined) {
return ShadowDOM.defaultSlotKey;
}
return node.auSlotAttribute.value;
};
ShadowDOM.distributeView = function distributeView(view, slots, projectionSource, index, destinationOverride) {
var nodes = void 0;
if (view === null) {
nodes = noNodes;
} else {
var childNodes = view.fragment.childNodes;
var ii = childNodes.length;
nodes = new Array(ii);
for (var i = 0; i < ii; ++i) {
nodes[i] = childNodes[i];
}
}
ShadowDOM.distributeNodes(view, nodes, slots, projectionSource, index, destinationOverride);
};
ShadowDOM.undistributeView = function undistributeView(view, slots, projectionSource) {
for (var slotName in slots) {
slots[slotName].removeView(view, projectionSource);
}
};
ShadowDOM.undistributeAll = function undistributeAll(slots, projectionSource) {
for (var slotName in slots) {
slots[slotName].removeAll(projectionSource);
}
};
ShadowDOM.distributeNodes = function distributeNodes(view, nodes, slots, projectionSource, index, destinationOverride) {
for (var i = 0, ii = nodes.length; i < ii; ++i) {
var currentNode = nodes[i];
var nodeType = currentNode.nodeType;
if (currentNode.isContentProjectionSource) {
currentNode.viewSlot.projectTo(slots);
for (var slotName in slots) {
slots[slotName].projectFrom(view, currentNode.viewSlot);
}
nodes.splice(i, 1);
ii--;i--;
} else if (nodeType === 1 || nodeType === 3 || currentNode.viewSlot instanceof PassThroughSlot) {
if (nodeType === 3 && _isAllWhitespace(currentNode)) {
nodes.splice(i, 1);
ii--;i--;
} else {
var found = slots[destinationOverride || ShadowDOM.getSlotName(currentNode)];
if (found) {
found.addNode(view, currentNode, projectionSource, index);
nodes.splice(i, 1);
ii--;i--;
}
}
} else {
nodes.splice(i, 1);
ii--;i--;
}
}
for (var _slotName in slots) {
var slot = slots[_slotName];
if (slot.needsFallbackRendering) {
slot.renderFallbackContent(view, nodes, projectionSource, index);
}
}
};
return ShadowDOM;
}(), _class9.defaultSlotKey = '__au-default-slot-key__', _temp3);
function register(lookup, name, resource, type) {
if (!name) {
return;
}
var existing = lookup[name];
if (existing) {
if (existing !== resource) {
throw new Error('Attempted to register ' + type + ' when one with the same name already exists. Name: ' + name + '.');
}
return;
}
lookup[name] = resource;
}
export function validateBehaviorName(name, type) {
if (/[A-Z]/.test(name)) {
var newName = _hyphenate(name);
LogManager.getLogger('templating').warn('\'' + name + '\' is not a valid ' + type + ' name and has been converted to \'' + newName + '\'. Upper-case letters are not allowed because the DOM is not case-sensitive.');
return newName;
}
return name;
}
var conventionMark = '__au_resource__';
export var ViewResources = function () {
ViewResources.convention = function convention(target, existing) {
var resource = void 0;
if (existing && conventionMark in existing) {
return existing;
}
if ('$resource' in target) {
var config = target.$resource;
if (typeof config === 'string') {
resource = existing || new HtmlBehaviorResource();
resource[conventionMark] = true;
if (!resource.elementName) {
resource.elementName = validateBehaviorName(config, 'custom element');
}
} else {
if (typeof config === 'function') {
config = config.call(target);
}
if (typeof config === 'string') {
config = { name: config };
}
config = Object.assign({}, config);
var resourceType = config.type || 'element';
var _name = config.name;
switch (resourceType) {
case 'element':case 'attribute':
resource = existing || new HtmlBehaviorResource();
resource[conventionMark] = true;
if (resourceType === 'element') {
if (!resource.elementName) {
resource.elementName = _name ? validateBehaviorName(_name, 'custom element') : _hyphenate(target.name);
}
} else {
if (!resource.attributeName) {
resource.attributeName = _name ? validateBehaviorName(_name, 'custom attribute') : _hyphenate(target.name);
}
}
if ('templateController' in config) {
config.liftsContent = config.templateController;
delete config.templateController;
}
if ('defaultBindingMode' in config && resource.attributeDefaultBindingMode !== undefined) {
config.attributeDefaultBindingMode = config.defaultBindingMode;
delete config.defaultBindingMode;
}
delete config.name;
Object.assign(resource, config);
break;
case 'valueConverter':
resource = new ValueConverterResource(camelCase(_name || target.name));
break;
case 'bindingBehavior':
resource = new BindingBehaviorResource(camelCase(_name || target.name));
break;
case 'viewEngineHooks':
resource = new ViewEngineHooksResource();
break;
}
}
if (resource instanceof HtmlBehaviorResource) {
var _bindables = typeof config === 'string' ? undefined : config.bindables;
var currentProps = resource.properties;
if (Array.isArray(_bindables)) {
for (var i = 0, ii = _bindables.length; ii > i; ++i) {
var prop = _bindables[i];
if (!prop || typeof prop !== 'string' && !prop.name) {
throw new Error('Invalid bindable property at "' + i + '" for class "' + target.name + '". Expected either a string or an object with "name" property.');
}
var newProp = new BindableProperty(prop);
var existed = false;
for (var j = 0, jj = currentProps.length; jj > j; ++j) {
if (currentProps[j].name === newProp.name) {
existed = true;
break;
}
}
if (existed) {
continue;
}
newProp.registerWith(target, resource);
}
}
}
}
return resource;
};
function ViewResources(parent, viewUrl) {
this.bindingLanguage = null;
this.parent = parent || null;
this.hasParent = this.parent !== null;
this.viewUrl = viewUrl || '';
this.lookupFunctions = {
valueConverters: this.getValueConverter.bind(this),
bindingBehaviors: this.getBindingBehavior.bind(this)
};
this.attributes = Object.create(null);
this.elements = Object.create(null);
this.valueConverters = Object.create(null);
this.bindingBehaviors = Object.create(null);
this.attributeMap = Object.create(null);
this.values = Object.create(null);
this.beforeCompile = this.afterCompile = this.beforeCreate = this.afterCreate = this.beforeBind = this.beforeUnbind = false;
}
ViewResources.prototype._tryAddHook = function _tryAddHook(obj, name) {
if (typeof obj[name] === 'function') {
var func = obj[name].bind(obj);
var counter = 1;
var callbackName = void 0;
while (this[callbackName = name + counter.toString()] !== undefined) {
counter++;
}
this[name] = true;
this[callbackName] = func;
}
};
ViewResources.prototype._invokeHook = function _invokeHook(name, one, two, three, four) {
if (this.hasParent) {
this.parent._invokeHook(name, one, two, three, four);
}
if (this[name]) {
this[name + '1'](one, two, three, four);
var callbackName = name + '2';
if (this[callbackName]) {
this[callbackName](one, two, three, four);
callbackName = name + '3';
if (this[callbackName]) {
this[callbackName](one, two, three, four);
var counter = 4;
while (this[callbackName = name + counter.toString()] !== undefined) {
this[callbackName](one, two, three, four);
counter++;
}
}
}
}
};
ViewResources.prototype.registerViewEngineHooks = function registerViewEngineHooks(hooks) {
this._tryAddHook(hooks, 'beforeCompile');
this._tryAddHook(hooks, 'afterCompile');
this._tryAddHook(hooks, 'beforeCreate');
this._tryAddHook(hooks, 'afterCreate');
this._tryAddHook(hooks, 'beforeBind');
this._tryAddHook(hooks, 'beforeUnbind');
};
ViewResources.prototype.getBindingLanguage = function getBindingLanguage(bindingLanguageFallback) {
return this.bindingLanguage || (this.bindingLanguage = bindingLanguageFallback);
};
ViewResources.prototype.patchInParent = function patchInParent(newParent) {
var originalParent = this.parent;
this.parent = newParent || null;
this.hasParent = this.parent !== null;
if (newParent.parent === null) {
newParent.parent = originalParent;
newParent.hasParent = originalParent !== null;
}
};
ViewResources.prototype.relativeToView = function relativeToView(path) {
return relativeToFile(path, this.viewUrl);
};
ViewResources.prototype.registerElement = function registerElement(tagName, behavior) {
register(this.elements, tagName, behavior, 'an Element');
};
ViewResources.prototype.getElement = function getElement(tagName) {
return this.elements[tagName] || (this.hasParent ? this.parent.getElement(tagName) : null);
};
ViewResources.prototype.mapAttribute = function mapAttribute(attribute) {
return this.attributeMap[attribute] || (this.hasParent ? this.parent.mapAttribute(attribute) : null);
};
ViewResources.prototype.registerAttribute = function registerAttribute(attribute, behavior, knownAttribute) {
this.attributeMap[attribute] = knownAttribute;
register(this.attributes, attribute, behavior, 'an Attribute');
};
ViewResources.prototype.getAttribute = function getAttribute(attribute) {
return this.attributes[attribute] || (this.hasParent ? this.parent.getAttribute(attribute) : null);
};
ViewResources.prototype.registerValueConverter = function registerValueConverter(name, valueConverter) {
register(this.valueConverters, name, valueConverter, 'a ValueConverter');
};
ViewResources.prototype.getValueConverter = function getValueConverter(name) {
return this.valueConverters[name] || (this.hasParent ? this.parent.getValueConverter(name) : null);
};
ViewResources.prototype.registerBindingBehavior = function registerBindingBehavior(name, bindingBehavior) {
register(this.bindingBehaviors, name, bindingBehavior, 'a BindingBehavior');
};
ViewResources.prototype.getBindingBehavior = function getBindingBehavior(name) {
return this.bindingBehaviors[name] || (this.hasParent ? this.parent.getBindingBehavior(name) : null);
};
ViewResources.prototype.registerValue = function registerValue(name, value) {
register(this.values, name, value, 'a value');
};
ViewResources.prototype.getValue = function getValue(name) {
return this.values[name] || (this.hasParent ? this.parent.getValue(name) : null);
};
ViewResources.prototype.autoRegister = function autoRegister(container, impl) {
var resourceTypeMeta = metadata.getOwn(metadata.resource, impl);
if (resourceTypeMeta) {
if (resourceTypeMeta instanceof HtmlBehaviorResource) {
ViewResources.convention(impl, resourceTypeMeta);
if (resourceTypeMeta.attributeName === null && resourceTypeMeta.elementName === null) {
HtmlBehaviorResource.convention(impl.name, resourceTypeMeta);
}
if (resourceTypeMeta.attributeName === null && resourceTypeMeta.elementName === null) {
resourceTypeMeta.elementName = _hyphenate(impl.name);