-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8ab6ca
commit fa3825f
Showing
4 changed files
with
840 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); |
Oops, something went wrong.