diff --git a/dist/amd/template-controller.js b/dist/amd/template-controller.js new file mode 100644 index 00000000..b8bdf900 --- /dev/null +++ b/dist/amd/template-controller.js @@ -0,0 +1,120 @@ +define(["exports", "aurelia-metadata", "./behavior-instance", "./behaviors", "./property", "./util"], function (exports, _aureliaMetadata, _behaviorInstance, _behaviors, _property, _util) { + "use strict"; + + var _prototypeProperties = function (child, staticProps, instanceProps) { + if (staticProps) Object.defineProperties(child, staticProps); + if (instanceProps) Object.defineProperties(child.prototype, instanceProps); + }; + + var _inherits = function (child, parent) { + if (typeof parent !== "function" && parent !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof parent); + } + child.prototype = Object.create(parent && parent.prototype, { + constructor: { + value: child, + enumerable: false, + writable: true, + configurable: true + } + }); + if (parent) child.__proto__ = parent; + }; + + var ResourceType = _aureliaMetadata.ResourceType; + var BehaviorInstance = _behaviorInstance.BehaviorInstance; + var configureBehavior = _behaviors.configureBehavior; + var Property = _property.Property; + var hyphenate = _util.hyphenate; + var TemplateController = (function (ResourceType) { + var TemplateController = function TemplateController(attribute) { + this.name = attribute; + this.properties = []; + this.attributes = {}; + this.liftsContent = true; + }; + + _inherits(TemplateController, ResourceType); + + _prototypeProperties(TemplateController, { + convention: { + value: function (name) { + if (name.endsWith("TemplateController")) { + return new TemplateController(hyphenate(name.substring(0, name.length - 18))); + } + }, + writable: true, + enumerable: true, + configurable: true + } + }, { + load: { + value: function (container, target) { + configureBehavior(this, container, target); + + if (this.properties.length === 0 && "valueChanged" in target.prototype) { + new Property("value", "valueChanged", this.name).configureBehavior(this); + } + + return Promise.resolve(this); + }, + writable: true, + enumerable: true, + configurable: true + }, + register: { + value: function (registry, name) { + registry.registerAttribute(name || this.name, this, this.name); + }, + writable: true, + enumerable: true, + configurable: true + }, + compile: { + value: function (compiler, resources, node, instruction, parentNode) { + if (!instruction.viewFactory) { + var template = document.createElement("template"), + fragment = document.createDocumentFragment(); + + node.removeAttribute(instruction.originalAttrName); + + if (node.parentNode) { + node.parentNode.replaceChild(template, node); + } else if (window.ShadowDOMPolyfill) { + ShadowDOMPolyfill.unwrap(parentNode).replaceChild(ShadowDOMPolyfill.unwrap(template), ShadowDOMPolyfill.unwrap(node)); + } else { + parentNode.replaceChild(template, node); + } + + fragment.appendChild(node); + + instruction.viewFactory = compiler.compile(fragment, resources); + node = template; + } + + instruction.suppressBind = true; + + return node; + }, + writable: true, + enumerable: true, + configurable: true + }, + create: { + value: function (container, instruction, element) { + var executionContext = instruction.executionContext || container.get(this.target), + behaviorInstance = new BehaviorInstance(this.taskQueue, this.observerLocator, this, executionContext, instruction); + element.primaryBehavior = behaviorInstance; + return behaviorInstance; + }, + writable: true, + enumerable: true, + configurable: true + } + }); + + return TemplateController; + })(ResourceType); + + exports.TemplateController = TemplateController; +}); \ No newline at end of file diff --git a/dist/amd/view-strategy.js b/dist/amd/view-strategy.js new file mode 100644 index 00000000..91bbd8e3 --- /dev/null +++ b/dist/amd/view-strategy.js @@ -0,0 +1,181 @@ +define(["exports", "aurelia-metadata", "aurelia-path"], function (exports, _aureliaMetadata, _aureliaPath) { + "use strict"; + + var _inherits = function (child, parent) { + if (typeof parent !== "function" && parent !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof parent); + } + child.prototype = Object.create(parent && parent.prototype, { + constructor: { + value: child, + enumerable: false, + writable: true, + configurable: true + } + }); + if (parent) child.__proto__ = parent; + }; + + var _prototypeProperties = function (child, staticProps, instanceProps) { + if (staticProps) Object.defineProperties(child, staticProps); + if (instanceProps) Object.defineProperties(child.prototype, instanceProps); + }; + + var getAnnotation = _aureliaMetadata.getAnnotation; + var Origin = _aureliaMetadata.Origin; + var relativeToFile = _aureliaPath.relativeToFile; + var ViewStrategy = (function () { + var ViewStrategy = function ViewStrategy() {}; + + _prototypeProperties(ViewStrategy, { + normalize: { + value: function (value) { + if (typeof value === "string") { + value = new UseView(value); + } + + if (value && !(value instanceof ViewStrategy)) { + throw new Error("The view must be a string or an instance of ViewStrategy."); + } + + return value; + }, + writable: true, + enumerable: true, + configurable: true + }, + getDefault: { + value: function (target) { + var strategy, annotation; + + if (typeof target !== "function") { + target = target.constructor; + } + + annotation = Origin.get(target); + strategy = getAnnotation(target, ViewStrategy); + + if (!strategy) { + if (!annotation) { + throw new Error("Cannot determinte default view strategy for object.", target); + } + + strategy = new ConventionalView(annotation.moduleId); + } else if (annotation) { + strategy.moduleId = annotation.moduleId; + } + + return strategy; + }, + writable: true, + enumerable: true, + configurable: true + } + }, { + makeRelativeTo: { + value: function (baseUrl) {}, + writable: true, + enumerable: true, + configurable: true + }, + loadViewFactory: { + value: function (viewEngine, options) { + throw new Error("A ViewStrategy must implement loadViewFactory(viewEngine, options)."); + }, + writable: true, + enumerable: true, + configurable: true + } + }); + + return ViewStrategy; + })(); + + exports.ViewStrategy = ViewStrategy; + var UseView = (function (ViewStrategy) { + var UseView = function UseView(path) { + this.path = path; + }; + + _inherits(UseView, ViewStrategy); + + _prototypeProperties(UseView, null, { + loadViewFactory: { + value: function (viewEngine, options) { + return viewEngine.loadViewFactory(this.absolutePath || this.path, options, this.moduleId); + }, + writable: true, + enumerable: true, + configurable: true + }, + makeRelativeTo: { + value: function (file) { + this.absolutePath = relativeToFile(this.path, file); + }, + writable: true, + enumerable: true, + configurable: true + } + }); + + return UseView; + })(ViewStrategy); + + exports.UseView = UseView; + var ConventionalView = (function (ViewStrategy) { + var ConventionalView = function ConventionalView(moduleId) { + this.moduleId = moduleId; + this.viewUrl = ConventionalView.convertModuleIdToViewUrl(moduleId); + }; + + _inherits(ConventionalView, ViewStrategy); + + _prototypeProperties(ConventionalView, { + convertModuleIdToViewUrl: { + value: function (moduleId) { + return moduleId + ".html"; + }, + writable: true, + enumerable: true, + configurable: true + } + }, { + loadViewFactory: { + value: function (viewEngine, options) { + return viewEngine.loadViewFactory(this.viewUrl, options, this.moduleId); + }, + writable: true, + enumerable: true, + configurable: true + } + }); + + return ConventionalView; + })(ViewStrategy); + + exports.ConventionalView = ConventionalView; + var NoView = (function (ViewStrategy) { + var NoView = function NoView() { + if (Object.getPrototypeOf(NoView) !== null) { + Object.getPrototypeOf(NoView).apply(this, arguments); + } + }; + + _inherits(NoView, ViewStrategy); + + _prototypeProperties(NoView, null, { + loadViewFactory: { + value: function () { + return Promise.resolve(null); + }, + writable: true, + enumerable: true, + configurable: true + } + }); + + return NoView; + })(ViewStrategy); + + exports.NoView = NoView; +}); \ No newline at end of file diff --git a/dist/amd/view.js b/dist/amd/view.js new file mode 100644 index 00000000..f09a6360 --- /dev/null +++ b/dist/amd/view.js @@ -0,0 +1,224 @@ +define(["exports"], function (exports) { + "use strict"; + + var _prototypeProperties = function (child, staticProps, instanceProps) { + if (staticProps) Object.defineProperties(child, staticProps); + if (instanceProps) Object.defineProperties(child.prototype, instanceProps); + }; + + var View = (function () { + var View = function View(fragment, behaviors, bindings, children, systemControlled, contentSelectors) { + this.fragment = fragment; + this.behaviors = behaviors; + this.bindings = bindings; + this.children = children; + this.systemControlled = systemControlled; + this.contentSelectors = contentSelectors; + this.firstChild = fragment.firstChild; + this.lastChild = fragment.lastChild; + this.isBound = false; + this.isAttached = false; + }; + + _prototypeProperties(View, null, { + created: { + value: function (executionContext) { + var i, ii, behaviors = this.behaviors; + for (i = 0, ii = behaviors.length; i < ii; ++i) { + behaviors[i].created(executionContext); + } + }, + writable: true, + enumerable: true, + configurable: true + }, + bind: { + value: function (executionContext, systemUpdate) { + var context, behaviors, bindings, children, i, ii; + + if (systemUpdate && !this.systemControlled) { + context = this.executionContext || executionContext; + } else { + context = executionContext || this.executionContext; + } + + if (this.isBound) { + if (this.executionContext === context) { + return; + } + + this.unbind(); + } + + this.isBound = true; + this.executionContext = context; + + if (this.owner) { + this.owner.bind(context); + } + + bindings = this.bindings; + for (i = 0, ii = bindings.length; i < ii; ++i) { + bindings[i].bind(context); + } + + behaviors = this.behaviors; + for (i = 0, ii = behaviors.length; i < ii; ++i) { + behaviors[i].bind(context); + } + + children = this.children; + for (i = 0, ii = children.length; i < ii; ++i) { + children[i].bind(context, true); + } + }, + writable: true, + enumerable: true, + configurable: true + }, + addBinding: { + value: function (binding) { + this.bindings.push(binding); + + if (this.isBound) { + binding.bind(this.executionContext); + } + }, + writable: true, + enumerable: true, + configurable: true + }, + unbind: { + value: function () { + var behaviors, bindings, children, i, ii; + + if (this.isBound) { + this.isBound = false; + + if (this.owner) { + this.owner.unbind(); + } + + bindings = this.bindings; + for (i = 0, ii = bindings.length; i < ii; ++i) { + bindings[i].unbind(); + } + + behaviors = this.behaviors; + for (i = 0, ii = behaviors.length; i < ii; ++i) { + behaviors[i].unbind(); + } + + children = this.children; + for (i = 0, ii = children.length; i < ii; ++i) { + children[i].unbind(); + } + } + }, + writable: true, + enumerable: true, + configurable: true + }, + insertNodesBefore: { + value: function (refNode) { + var parent = refNode.parentNode; + parent.insertBefore(this.fragment, refNode); + }, + writable: true, + enumerable: true, + configurable: true + }, + appendNodesTo: { + value: function (parent) { + parent.appendChild(this.fragment); + }, + writable: true, + enumerable: true, + configurable: true + }, + removeNodes: { + value: function () { + var start = this.firstChild, + end = this.lastChild, + fragment = this.fragment, + next; + + var current = start, + loop = true, + nodes = []; + + while (loop) { + if (current === end) { + loop = false; + } + + next = current.nextSibling; + this.fragment.appendChild(current); + current = next; + } + }, + writable: true, + enumerable: true, + configurable: true + }, + attached: { + value: function () { + var behaviors, children, i, ii; + + if (this.isAttached) { + return; + } + + this.isAttached = true; + + if (this.owner) { + this.owner.attached(); + } + + behaviors = this.behaviors; + for (i = 0, ii = behaviors.length; i < ii; ++i) { + behaviors[i].attached(); + } + + children = this.children; + for (i = 0, ii = children.length; i < ii; ++i) { + children[i].attached(); + } + }, + writable: true, + enumerable: true, + configurable: true + }, + detached: { + value: function () { + var behaviors, children, i, ii; + + if (this.isAttached) { + this.isAttached = false; + + if (this.owner) { + this.owner.detached(); + } + + behaviors = this.behaviors; + for (i = 0, ii = behaviors.length; i < ii; ++i) { + behaviors[i].detached(); + } + + children = this.children; + for (i = 0, ii = children.length; i < ii; ++i) { + children[i].detached(); + } + } + }, + writable: true, + enumerable: true, + configurable: true + } + }); + + return View; + })(); + + exports.View = View; +}); \ No newline at end of file diff --git a/dist/system/view-slot.js b/dist/system/view-slot.js new file mode 100644 index 00000000..b907ac64 --- /dev/null +++ b/dist/system/view-slot.js @@ -0,0 +1,315 @@ +System.register(["./content-selector"], function (_export) { + "use strict"; + + var ContentSelector, _prototypeProperties, ViewSlot; + return { + setters: [function (_contentSelector) { + ContentSelector = _contentSelector.ContentSelector; + }], + execute: function () { + _prototypeProperties = function (child, staticProps, instanceProps) { + if (staticProps) Object.defineProperties(child, staticProps); + if (instanceProps) Object.defineProperties(child.prototype, instanceProps); + }; + + ViewSlot = (function () { + var ViewSlot = function ViewSlot(anchor, anchorIsContainer, executionContext) { + this.anchor = anchor; + this.viewAddMethod = anchorIsContainer ? "appendNodesTo" : "insertNodesBefore"; + this.executionContext = executionContext; + this.children = []; + this.isBound = false; + this.isAttached = false; + + anchor.viewSlot = this; + }; + + _prototypeProperties(ViewSlot, null, { + bind: { + value: function (executionContext) { + var i, ii, children; + + if (this.isBound) { + if (this.executionContext === executionContext) { + return; + } + + this.unbind(); + } + + this.isBound = true; + this.executionContext = executionContext = executionContext || this.executionContext; + + children = this.children; + for (i = 0, ii = children.length; i < ii; ++i) { + children[i].bind(executionContext, true); + } + }, + writable: true, + enumerable: true, + configurable: true + }, + unbind: { + value: function () { + var i, ii, children = this.children; + this.isBound = false; + + for (i = 0, ii = children.length; i < ii; ++i) { + children[i].unbind(); + } + }, + writable: true, + enumerable: true, + configurable: true + }, + add: { + value: function (view) { + view[this.viewAddMethod](this.anchor); + this.children.push(view); + + if (this.isAttached) { + view.attached(); + } + }, + writable: true, + enumerable: true, + configurable: true + }, + insert: { + value: function (index, view) { + if (index === 0 && !this.children.length || index >= this.children.length) { + this.add(view); + } else { + view.insertNodesBefore(this.children[index].firstChild); + this.children.splice(index, 0, view); + + if (this.isAttached) { + view.attached(); + } + } + }, + writable: true, + enumerable: true, + configurable: true + }, + remove: { + value: function (view) { + view.removeNodes(); + this.children.splice(this.children.indexOf(view), 1); + + if (this.isAttached) { + view.detached(); + } + }, + writable: true, + enumerable: true, + configurable: true + }, + removeAt: { + value: function (index) { + var view = this.children[index]; + + view.removeNodes(); + this.children.splice(index, 1); + + if (this.isAttached) { + view.detached(); + } + + return view; + }, + writable: true, + enumerable: true, + configurable: true + }, + removeAll: { + value: function () { + var children = this.children, + ii = children.length, + i; + + for (i = 0; i < ii; ++i) { + children[i].removeNodes(); + } + + if (this.isAttached) { + for (i = 0; i < ii; ++i) { + children[i].detached(); + } + } + + this.children = []; + }, + writable: true, + enumerable: true, + configurable: true + }, + swap: { + value: function (view) { + this.removeAll(); + this.add(view); + }, + writable: true, + enumerable: true, + configurable: true + }, + attached: { + value: function () { + var i, ii, children; + + if (this.isAttached) { + return; + } + + this.isAttached = true; + + children = this.children; + for (i = 0, ii = children.length; i < ii; ++i) { + children[i].attached(); + } + }, + writable: true, + enumerable: true, + configurable: true + }, + detached: { + value: function () { + var i, ii, children; + + if (this.isAttached) { + this.isAttached = false; + children = this.children; + for (i = 0, ii = children.length; i < ii; ++i) { + children[i].detached(); + } + } + }, + writable: true, + enumerable: true, + configurable: true + }, + installContentSelectors: { + value: function (contentSelectors) { + this.contentSelectors = contentSelectors; + this.add = this.contentSelectorAdd; + this.insert = this.contentSelectorInsert; + this.remove = this.contentSelectorRemove; + this.removeAt = this.contentSelectorRemoveAt; + this.removeAll = this.contentSelectorRemoveAll; + }, + writable: true, + enumerable: true, + configurable: true + }, + contentSelectorAdd: { + value: function (view) { + ContentSelector.applySelectors(view, this.contentSelectors, function (contentSelector, group) { + return contentSelector.add(group); + }); + + this.children.push(view); + + if (this.isAttached) { + view.attached(); + } + }, + writable: true, + enumerable: true, + configurable: true + }, + contentSelectorInsert: { + value: function (index, view) { + if (index === 0 && !this.children.length || index >= this.children.length) { + this.add(view); + } else { + ContentSelector.applySelectors(view, this.contentSelectors, function (contentSelector, group) { + return contentSelector.insert(index, group); + }); + + this.children.splice(index, 0, view); + + if (this.isAttached) { + view.attached(); + } + } + }, + writable: true, + enumerable: true, + configurable: true + }, + contentSelectorRemove: { + value: function (view) { + var index = this.children.indexOf(view), contentSelectors = this.contentSelectors, i, ii; + + for (i = 0, ii = contentSelectors.length; i < ii; ++i) { + contentSelectors[i].removeAt(index, view.fragment); + } + + this.children.splice(index, 1); + + if (this.isAttached) { + view.detached(); + } + }, + writable: true, + enumerable: true, + configurable: true + }, + contentSelectorRemoveAt: { + value: function (index) { + var view = this.children[index], contentSelectors = this.contentSelectors, i, ii; + + for (i = 0, ii = contentSelectors.length; i < ii; ++i) { + contentSelectors[i].removeAt(index, view.fragment); + } + + this.children.splice(index, 1); + + if (this.isAttached) { + view.detached(); + } + + return view; + }, + writable: true, + enumerable: true, + configurable: true + }, + contentSelectorRemoveAll: { + value: function () { + var children = this.children, + contentSelectors = this.contentSelectors, + ii = children.length, + jj = contentSelectors.length, + i, + j, + view; + + for (i = 0; i < ii; ++i) { + view = children[i]; + + for (j = 0; j < jj; ++j) { + contentSelectors[j].removeAt(i, view.fragment); + } + } + + if (this.isAttached) { + for (i = 0; i < ii; ++i) { + children[i].detached(); + } + } + + this.children = []; + }, + writable: true, + enumerable: true, + configurable: true + } + }); + + return ViewSlot; + })(); + _export("ViewSlot", ViewSlot); + } + }; +}); \ No newline at end of file