From 1d2d415af9718bf8778e13fc8e8dba6a08ded0f7 Mon Sep 17 00:00:00 2001 From: Rob Eisenberg Date: Wed, 1 May 2019 20:32:27 -0700 Subject: [PATCH] chore(all): prepare release 1.10.0 --- bower.json | 2 +- dist/amd/abstract-repeater.js | 66 - dist/amd/analyze-view-factory.js | 57 - dist/amd/array-repeat-strategy.js | 239 -- dist/amd/attr-binding-behavior.js | 26 - dist/amd/aurelia-hide-style.js | 24 - dist/amd/aurelia-templating-resources.js | 1983 +++++++++++++- dist/amd/aurelia-templating-resources.js.map | 1 + dist/amd/binding-mode-behaviors.js | 49 - dist/amd/binding-signaler.js | 31 - dist/amd/compose.js | 215 -- dist/amd/css-resource.js | 130 - dist/amd/debounce-binding-behavior.js | 82 - dist/amd/dynamic-element.js | 58 - dist/amd/else.js | 73 - dist/amd/focus.js | 75 - dist/amd/hide.js | 44 - dist/amd/html-resource-plugin.js | 41 - dist/amd/html-sanitizer.js | 31 - dist/amd/if-core.js | 99 - dist/amd/if.js | 162 -- dist/amd/index.js | 16 - dist/amd/map-repeat-strategy.js | 117 - dist/amd/null-repeat-strategy.js | 23 - dist/amd/number-repeat-strategy.js | 65 - dist/amd/repeat-strategy-locator.js | 54 - dist/amd/repeat-utilities.js | 106 - dist/amd/repeat.js | 324 --- dist/amd/replaceable.js | 37 - dist/amd/sanitize-html.js | 30 - dist/amd/self-binding-behavior.js | 41 - dist/amd/set-repeat-strategy.js | 104 - dist/amd/show.js | 44 - dist/amd/signal-binding-behavior.js | 70 - dist/amd/throttle-binding-behavior.js | 72 - dist/amd/update-trigger-binding-behavior.js | 53 - dist/amd/with.js | 49 - dist/aurelia-templating-resources.d.ts | 1254 ++++----- dist/aurelia-templating-resources.js | 2389 ----------------- dist/commonjs/abstract-repeater.js | 64 - dist/commonjs/analyze-view-factory.js | 55 - dist/commonjs/array-repeat-strategy.js | 241 -- dist/commonjs/attr-binding-behavior.js | 26 - dist/commonjs/aurelia-hide-style.js | 25 - dist/commonjs/aurelia-templating-resources.js | 1972 +++++++++++++- .../aurelia-templating-resources.js.map | 1 + dist/commonjs/binding-mode-behaviors.js | 51 - dist/commonjs/binding-signaler.js | 31 - dist/commonjs/compose.js | 221 -- dist/commonjs/css-resource.js | 118 - dist/commonjs/debounce-binding-behavior.js | 82 - dist/commonjs/dynamic-element.js | 60 - dist/commonjs/else.js | 57 - dist/commonjs/focus.js | 81 - dist/commonjs/hide.js | 50 - dist/commonjs/html-resource-plugin.js | 44 - dist/commonjs/html-sanitizer.js | 31 - dist/commonjs/if-core.js | 97 - dist/commonjs/if.js | 146 - dist/commonjs/index.js | 17 - dist/commonjs/map-repeat-strategy.js | 117 - dist/commonjs/null-repeat-strategy.js | 21 - dist/commonjs/number-repeat-strategy.js | 65 - dist/commonjs/repeat-strategy-locator.js | 62 - dist/commonjs/repeat-utilities.js | 105 - dist/commonjs/repeat.js | 316 --- dist/commonjs/replaceable.js | 39 - dist/commonjs/sanitize-html.js | 34 - dist/commonjs/self-binding-behavior.js | 41 - dist/commonjs/set-repeat-strategy.js | 104 - dist/commonjs/show.js | 50 - dist/commonjs/signal-binding-behavior.js | 72 - dist/commonjs/throttle-binding-behavior.js | 72 - .../update-trigger-binding-behavior.js | 53 - dist/commonjs/with.js | 53 - dist/es2015/abstract-repeater.js | 53 - dist/es2015/analyze-view-factory.js | 50 - dist/es2015/array-repeat-strategy.js | 213 -- dist/es2015/attr-binding-behavior.js | 11 - dist/es2015/aurelia-hide-style.js | 16 - dist/es2015/aurelia-templating-resources.js | 1823 ++++++++++++- .../aurelia-templating-resources.js.map | 1 + dist/es2015/binding-mode-behaviors.js | 46 - dist/es2015/binding-signaler.js | 18 - dist/es2015/compose.js | 205 -- dist/es2015/css-resource.js | 80 - dist/es2015/debounce-binding-behavior.js | 59 - dist/es2015/dynamic-element.js | 41 - dist/es2015/else.js | 34 - dist/es2015/focus.js | 64 - dist/es2015/hide.js | 35 - dist/es2015/html-resource-plugin.js | 31 - dist/es2015/html-sanitizer.js | 18 - dist/es2015/if-core.js | 84 - dist/es2015/if.js | 115 - dist/es2015/index.js | 1 - dist/es2015/map-repeat-strategy.js | 98 - dist/es2015/null-repeat-strategy.js | 8 - dist/es2015/number-repeat-strategy.js | 46 - dist/es2015/repeat-strategy-locator.js | 35 - dist/es2015/repeat-utilities.js | 89 - dist/es2015/repeat.js | 281 -- dist/es2015/replaceable.js | 25 - dist/es2015/sanitize-html.js | 19 - dist/es2015/self-binding-behavior.js | 26 - dist/es2015/set-repeat-strategy.js | 85 - dist/es2015/show.js | 35 - dist/es2015/signal-binding-behavior.js | 54 - dist/es2015/throttle-binding-behavior.js | 53 - .../es2015/update-trigger-binding-behavior.js | 35 - dist/es2015/with.js | 38 - dist/es2017/aurelia-templating-resources.js | 1773 ++++++++++++ .../aurelia-templating-resources.js.map | 1 + dist/native-modules/abstract-repeater.js | 58 - dist/native-modules/analyze-view-factory.js | 50 - dist/native-modules/array-repeat-strategy.js | 233 -- dist/native-modules/attr-binding-behavior.js | 19 - dist/native-modules/aurelia-hide-style.js | 16 - .../aurelia-templating-resources.js | 1936 ++++++++++++- .../aurelia-templating-resources.js.map | 1 + dist/native-modules/binding-mode-behaviors.js | 47 - dist/native-modules/binding-signaler.js | 24 - dist/native-modules/compose.js | 210 -- dist/native-modules/css-resource.js | 107 - .../debounce-binding-behavior.js | 75 - dist/native-modules/dynamic-element.js | 52 - dist/native-modules/else.js | 48 - dist/native-modules/focus.js | 71 - dist/native-modules/hide.js | 40 - dist/native-modules/html-resource-plugin.js | 35 - dist/native-modules/html-sanitizer.js | 24 - dist/native-modules/if-core.js | 91 - dist/native-modules/if.js | 137 - dist/native-modules/index.js | 1 - dist/native-modules/map-repeat-strategy.js | 110 - dist/native-modules/null-repeat-strategy.js | 15 - dist/native-modules/number-repeat-strategy.js | 58 - .../native-modules/repeat-strategy-locator.js | 51 - dist/native-modules/repeat-utilities.js | 91 - dist/native-modules/repeat.js | 303 --- dist/native-modules/replaceable.js | 31 - dist/native-modules/sanitize-html.js | 25 - dist/native-modules/self-binding-behavior.js | 34 - dist/native-modules/set-repeat-strategy.js | 97 - dist/native-modules/show.js | 40 - .../native-modules/signal-binding-behavior.js | 64 - .../throttle-binding-behavior.js | 65 - .../update-trigger-binding-behavior.js | 46 - dist/native-modules/with.js | 44 - dist/system/abstract-repeater.js | 73 - dist/system/analyze-view-factory.js | 67 - dist/system/array-repeat-strategy.js | 252 -- dist/system/attr-binding-behavior.js | 33 - dist/system/aurelia-hide-style.js | 35 - dist/system/aurelia-templating-resources.js | 2055 +++++++++++++- .../aurelia-templating-resources.js.map | 1 + dist/system/binding-mode-behaviors.js | 70 - dist/system/binding-signaler.js | 39 - dist/system/compose.js | 232 -- dist/system/css-resource.js | 149 - dist/system/debounce-binding-behavior.js | 91 - dist/system/dynamic-element.js | 71 - dist/system/else.js | 86 - dist/system/focus.js | 87 - dist/system/hide.js | 58 - dist/system/html-resource-plugin.js | 53 - dist/system/html-sanitizer.js | 39 - dist/system/if-core.js | 106 - dist/system/if.js | 176 -- dist/system/index.js | 18 - dist/system/map-repeat-strategy.js | 126 - dist/system/null-repeat-strategy.js | 30 - dist/system/number-repeat-strategy.js | 74 - dist/system/repeat-strategy-locator.js | 70 - dist/system/repeat-utilities.js | 123 - dist/system/repeat.js | 351 --- dist/system/replaceable.js | 48 - dist/system/sanitize-html.js | 40 - dist/system/self-binding-behavior.js | 47 - dist/system/set-repeat-strategy.js | 113 - dist/system/show.js | 58 - dist/system/signal-binding-behavior.js | 78 - dist/system/throttle-binding-behavior.js | 79 - .../system/update-trigger-binding-behavior.js | 61 - dist/system/with.js | 62 - dist/temp/aurelia-templating-resources.js | 2191 --------------- doc/CHANGELOG.md | 4 + package.json | 2 +- 188 files changed, 11708 insertions(+), 18698 deletions(-) delete mode 100644 dist/amd/abstract-repeater.js delete mode 100644 dist/amd/analyze-view-factory.js delete mode 100644 dist/amd/array-repeat-strategy.js delete mode 100644 dist/amd/attr-binding-behavior.js delete mode 100644 dist/amd/aurelia-hide-style.js create mode 100644 dist/amd/aurelia-templating-resources.js.map delete mode 100644 dist/amd/binding-mode-behaviors.js delete mode 100644 dist/amd/binding-signaler.js delete mode 100644 dist/amd/compose.js delete mode 100644 dist/amd/css-resource.js delete mode 100644 dist/amd/debounce-binding-behavior.js delete mode 100644 dist/amd/dynamic-element.js delete mode 100644 dist/amd/else.js delete mode 100644 dist/amd/focus.js delete mode 100644 dist/amd/hide.js delete mode 100644 dist/amd/html-resource-plugin.js delete mode 100644 dist/amd/html-sanitizer.js delete mode 100644 dist/amd/if-core.js delete mode 100644 dist/amd/if.js delete mode 100644 dist/amd/index.js delete mode 100644 dist/amd/map-repeat-strategy.js delete mode 100644 dist/amd/null-repeat-strategy.js delete mode 100644 dist/amd/number-repeat-strategy.js delete mode 100644 dist/amd/repeat-strategy-locator.js delete mode 100644 dist/amd/repeat-utilities.js delete mode 100644 dist/amd/repeat.js delete mode 100644 dist/amd/replaceable.js delete mode 100644 dist/amd/sanitize-html.js delete mode 100644 dist/amd/self-binding-behavior.js delete mode 100644 dist/amd/set-repeat-strategy.js delete mode 100644 dist/amd/show.js delete mode 100644 dist/amd/signal-binding-behavior.js delete mode 100644 dist/amd/throttle-binding-behavior.js delete mode 100644 dist/amd/update-trigger-binding-behavior.js delete mode 100644 dist/amd/with.js delete mode 100644 dist/aurelia-templating-resources.js delete mode 100644 dist/commonjs/abstract-repeater.js delete mode 100644 dist/commonjs/analyze-view-factory.js delete mode 100644 dist/commonjs/array-repeat-strategy.js delete mode 100644 dist/commonjs/attr-binding-behavior.js delete mode 100644 dist/commonjs/aurelia-hide-style.js create mode 100644 dist/commonjs/aurelia-templating-resources.js.map delete mode 100644 dist/commonjs/binding-mode-behaviors.js delete mode 100644 dist/commonjs/binding-signaler.js delete mode 100644 dist/commonjs/compose.js delete mode 100644 dist/commonjs/css-resource.js delete mode 100644 dist/commonjs/debounce-binding-behavior.js delete mode 100644 dist/commonjs/dynamic-element.js delete mode 100644 dist/commonjs/else.js delete mode 100644 dist/commonjs/focus.js delete mode 100644 dist/commonjs/hide.js delete mode 100644 dist/commonjs/html-resource-plugin.js delete mode 100644 dist/commonjs/html-sanitizer.js delete mode 100644 dist/commonjs/if-core.js delete mode 100644 dist/commonjs/if.js delete mode 100644 dist/commonjs/index.js delete mode 100644 dist/commonjs/map-repeat-strategy.js delete mode 100644 dist/commonjs/null-repeat-strategy.js delete mode 100644 dist/commonjs/number-repeat-strategy.js delete mode 100644 dist/commonjs/repeat-strategy-locator.js delete mode 100644 dist/commonjs/repeat-utilities.js delete mode 100644 dist/commonjs/repeat.js delete mode 100644 dist/commonjs/replaceable.js delete mode 100644 dist/commonjs/sanitize-html.js delete mode 100644 dist/commonjs/self-binding-behavior.js delete mode 100644 dist/commonjs/set-repeat-strategy.js delete mode 100644 dist/commonjs/show.js delete mode 100644 dist/commonjs/signal-binding-behavior.js delete mode 100644 dist/commonjs/throttle-binding-behavior.js delete mode 100644 dist/commonjs/update-trigger-binding-behavior.js delete mode 100644 dist/commonjs/with.js delete mode 100644 dist/es2015/abstract-repeater.js delete mode 100644 dist/es2015/analyze-view-factory.js delete mode 100644 dist/es2015/array-repeat-strategy.js delete mode 100644 dist/es2015/attr-binding-behavior.js delete mode 100644 dist/es2015/aurelia-hide-style.js create mode 100644 dist/es2015/aurelia-templating-resources.js.map delete mode 100644 dist/es2015/binding-mode-behaviors.js delete mode 100644 dist/es2015/binding-signaler.js delete mode 100644 dist/es2015/compose.js delete mode 100644 dist/es2015/css-resource.js delete mode 100644 dist/es2015/debounce-binding-behavior.js delete mode 100644 dist/es2015/dynamic-element.js delete mode 100644 dist/es2015/else.js delete mode 100644 dist/es2015/focus.js delete mode 100644 dist/es2015/hide.js delete mode 100644 dist/es2015/html-resource-plugin.js delete mode 100644 dist/es2015/html-sanitizer.js delete mode 100644 dist/es2015/if-core.js delete mode 100644 dist/es2015/if.js delete mode 100644 dist/es2015/index.js delete mode 100644 dist/es2015/map-repeat-strategy.js delete mode 100644 dist/es2015/null-repeat-strategy.js delete mode 100644 dist/es2015/number-repeat-strategy.js delete mode 100644 dist/es2015/repeat-strategy-locator.js delete mode 100644 dist/es2015/repeat-utilities.js delete mode 100644 dist/es2015/repeat.js delete mode 100644 dist/es2015/replaceable.js delete mode 100644 dist/es2015/sanitize-html.js delete mode 100644 dist/es2015/self-binding-behavior.js delete mode 100644 dist/es2015/set-repeat-strategy.js delete mode 100644 dist/es2015/show.js delete mode 100644 dist/es2015/signal-binding-behavior.js delete mode 100644 dist/es2015/throttle-binding-behavior.js delete mode 100644 dist/es2015/update-trigger-binding-behavior.js delete mode 100644 dist/es2015/with.js create mode 100644 dist/es2017/aurelia-templating-resources.js create mode 100644 dist/es2017/aurelia-templating-resources.js.map delete mode 100644 dist/native-modules/abstract-repeater.js delete mode 100644 dist/native-modules/analyze-view-factory.js delete mode 100644 dist/native-modules/array-repeat-strategy.js delete mode 100644 dist/native-modules/attr-binding-behavior.js delete mode 100644 dist/native-modules/aurelia-hide-style.js create mode 100644 dist/native-modules/aurelia-templating-resources.js.map delete mode 100644 dist/native-modules/binding-mode-behaviors.js delete mode 100644 dist/native-modules/binding-signaler.js delete mode 100644 dist/native-modules/compose.js delete mode 100644 dist/native-modules/css-resource.js delete mode 100644 dist/native-modules/debounce-binding-behavior.js delete mode 100644 dist/native-modules/dynamic-element.js delete mode 100644 dist/native-modules/else.js delete mode 100644 dist/native-modules/focus.js delete mode 100644 dist/native-modules/hide.js delete mode 100644 dist/native-modules/html-resource-plugin.js delete mode 100644 dist/native-modules/html-sanitizer.js delete mode 100644 dist/native-modules/if-core.js delete mode 100644 dist/native-modules/if.js delete mode 100644 dist/native-modules/index.js delete mode 100644 dist/native-modules/map-repeat-strategy.js delete mode 100644 dist/native-modules/null-repeat-strategy.js delete mode 100644 dist/native-modules/number-repeat-strategy.js delete mode 100644 dist/native-modules/repeat-strategy-locator.js delete mode 100644 dist/native-modules/repeat-utilities.js delete mode 100644 dist/native-modules/repeat.js delete mode 100644 dist/native-modules/replaceable.js delete mode 100644 dist/native-modules/sanitize-html.js delete mode 100644 dist/native-modules/self-binding-behavior.js delete mode 100644 dist/native-modules/set-repeat-strategy.js delete mode 100644 dist/native-modules/show.js delete mode 100644 dist/native-modules/signal-binding-behavior.js delete mode 100644 dist/native-modules/throttle-binding-behavior.js delete mode 100644 dist/native-modules/update-trigger-binding-behavior.js delete mode 100644 dist/native-modules/with.js delete mode 100644 dist/system/abstract-repeater.js delete mode 100644 dist/system/analyze-view-factory.js delete mode 100644 dist/system/array-repeat-strategy.js delete mode 100644 dist/system/attr-binding-behavior.js delete mode 100644 dist/system/aurelia-hide-style.js create mode 100644 dist/system/aurelia-templating-resources.js.map delete mode 100644 dist/system/binding-mode-behaviors.js delete mode 100644 dist/system/binding-signaler.js delete mode 100644 dist/system/compose.js delete mode 100644 dist/system/css-resource.js delete mode 100644 dist/system/debounce-binding-behavior.js delete mode 100644 dist/system/dynamic-element.js delete mode 100644 dist/system/else.js delete mode 100644 dist/system/focus.js delete mode 100644 dist/system/hide.js delete mode 100644 dist/system/html-resource-plugin.js delete mode 100644 dist/system/html-sanitizer.js delete mode 100644 dist/system/if-core.js delete mode 100644 dist/system/if.js delete mode 100644 dist/system/index.js delete mode 100644 dist/system/map-repeat-strategy.js delete mode 100644 dist/system/null-repeat-strategy.js delete mode 100644 dist/system/number-repeat-strategy.js delete mode 100644 dist/system/repeat-strategy-locator.js delete mode 100644 dist/system/repeat-utilities.js delete mode 100644 dist/system/repeat.js delete mode 100644 dist/system/replaceable.js delete mode 100644 dist/system/sanitize-html.js delete mode 100644 dist/system/self-binding-behavior.js delete mode 100644 dist/system/set-repeat-strategy.js delete mode 100644 dist/system/show.js delete mode 100644 dist/system/signal-binding-behavior.js delete mode 100644 dist/system/throttle-binding-behavior.js delete mode 100644 dist/system/update-trigger-binding-behavior.js delete mode 100644 dist/system/with.js delete mode 100644 dist/temp/aurelia-templating-resources.js diff --git a/bower.json b/bower.json index df0cb94..03354c3 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-templating-resources", - "version": "1.9.1", + "version": "1.10.0", "description": "A standard set of behaviors, converters and other resources for use with the Aurelia templating library.", "keywords": [ "aurelia", diff --git a/dist/amd/abstract-repeater.js b/dist/amd/abstract-repeater.js deleted file mode 100644 index cff7281..0000000 --- a/dist/amd/abstract-repeater.js +++ /dev/null @@ -1,66 +0,0 @@ -define(['exports'], function (exports) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - - - - var AbstractRepeater = exports.AbstractRepeater = function () { - function AbstractRepeater(options) { - - - Object.assign(this, { - local: 'items', - viewsRequireLifecycle: true - }, options); - } - - AbstractRepeater.prototype.viewCount = function viewCount() { - throw new Error('subclass must implement `viewCount`'); - }; - - AbstractRepeater.prototype.views = function views() { - throw new Error('subclass must implement `views`'); - }; - - AbstractRepeater.prototype.view = function view(index) { - throw new Error('subclass must implement `view`'); - }; - - AbstractRepeater.prototype.matcher = function matcher() { - throw new Error('subclass must implement `matcher`'); - }; - - AbstractRepeater.prototype.addView = function addView(bindingContext, overrideContext) { - throw new Error('subclass must implement `addView`'); - }; - - AbstractRepeater.prototype.insertView = function insertView(index, bindingContext, overrideContext) { - throw new Error('subclass must implement `insertView`'); - }; - - AbstractRepeater.prototype.moveView = function moveView(sourceIndex, targetIndex) { - throw new Error('subclass must implement `moveView`'); - }; - - AbstractRepeater.prototype.removeAllViews = function removeAllViews(returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeAllViews`'); - }; - - AbstractRepeater.prototype.removeViews = function removeViews(viewsToRemove, returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeView`'); - }; - - AbstractRepeater.prototype.removeView = function removeView(index, returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeView`'); - }; - - AbstractRepeater.prototype.updateBindings = function updateBindings(view) { - throw new Error('subclass must implement `updateBindings`'); - }; - - return AbstractRepeater; - }(); -}); \ No newline at end of file diff --git a/dist/amd/analyze-view-factory.js b/dist/amd/analyze-view-factory.js deleted file mode 100644 index 8bfd5ff..0000000 --- a/dist/amd/analyze-view-factory.js +++ /dev/null @@ -1,57 +0,0 @@ -define(['exports'], function (exports) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.viewsRequireLifecycle = viewsRequireLifecycle; - var lifecycleOptionalBehaviors = exports.lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with']; - - function behaviorRequiresLifecycle(instruction) { - var t = instruction.type; - var name = t.elementName !== null ? t.elementName : t.attributeName; - return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind) || t.viewFactory && viewsRequireLifecycle(t.viewFactory) || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); - } - - function targetRequiresLifecycle(instruction) { - var behaviors = instruction.behaviorInstructions; - if (behaviors) { - var i = behaviors.length; - while (i--) { - if (behaviorRequiresLifecycle(behaviors[i])) { - return true; - } - } - } - - return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); - } - - function viewsRequireLifecycle(viewFactory) { - if ('_viewsRequireLifecycle' in viewFactory) { - return viewFactory._viewsRequireLifecycle; - } - - viewFactory._viewsRequireLifecycle = false; - - if (viewFactory.viewFactory) { - viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory); - return viewFactory._viewsRequireLifecycle; - } - - if (viewFactory.template.querySelector('.au-animate')) { - viewFactory._viewsRequireLifecycle = true; - return true; - } - - for (var id in viewFactory.instructions) { - if (targetRequiresLifecycle(viewFactory.instructions[id])) { - viewFactory._viewsRequireLifecycle = true; - return true; - } - } - - viewFactory._viewsRequireLifecycle = false; - return false; - } -}); \ No newline at end of file diff --git a/dist/amd/array-repeat-strategy.js b/dist/amd/array-repeat-strategy.js deleted file mode 100644 index 64885de..0000000 --- a/dist/amd/array-repeat-strategy.js +++ /dev/null @@ -1,239 +0,0 @@ -define(['exports', './repeat-utilities', 'aurelia-binding'], function (exports, _repeatUtilities, _aureliaBinding) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.ArrayRepeatStrategy = undefined; - - - - var ArrayRepeatStrategy = exports.ArrayRepeatStrategy = function () { - function ArrayRepeatStrategy() { - - } - - ArrayRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getArrayObserver(items); - }; - - ArrayRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this = this; - - var itemsLength = items.length; - - if (!items || itemsLength === 0) { - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - return; - } - - var children = repeat.views(); - var viewsLength = children.length; - - if (viewsLength === 0) { - this._standardProcessInstanceChanged(repeat, items); - return; - } - - if (repeat.viewsRequireLifecycle) { - var childrenSnapshot = children.slice(0); - var itemNameInBindingContext = repeat.local; - var matcher = repeat.matcher(); - - var itemsPreviouslyInViews = []; - var viewsToRemove = []; - - for (var index = 0; index < viewsLength; index++) { - var view = childrenSnapshot[index]; - var oldItem = view.bindingContext[itemNameInBindingContext]; - - if ((0, _repeatUtilities.indexOf)(items, oldItem, matcher) === -1) { - viewsToRemove.push(view); - } else { - itemsPreviouslyInViews.push(oldItem); - } - } - - var updateViews = void 0; - var removePromise = void 0; - - if (itemsPreviouslyInViews.length > 0) { - removePromise = repeat.removeViews(viewsToRemove, true, !repeat.viewsRequireLifecycle); - updateViews = function updateViews() { - for (var _index = 0; _index < itemsLength; _index++) { - var item = items[_index]; - var indexOfView = (0, _repeatUtilities.indexOf)(itemsPreviouslyInViews, item, matcher, _index); - var _view = void 0; - - if (indexOfView === -1) { - var overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, items[_index], _index, itemsLength); - repeat.insertView(_index, overrideContext.bindingContext, overrideContext); - - itemsPreviouslyInViews.splice(_index, 0, undefined); - } else if (indexOfView === _index) { - _view = children[indexOfView]; - itemsPreviouslyInViews[indexOfView] = undefined; - } else { - _view = children[indexOfView]; - repeat.moveView(indexOfView, _index); - itemsPreviouslyInViews.splice(indexOfView, 1); - itemsPreviouslyInViews.splice(_index, 0, undefined); - } - - if (_view) { - (0, _repeatUtilities.updateOverrideContext)(_view.overrideContext, _index, itemsLength); - } - } - - _this._inPlaceProcessItems(repeat, items); - }; - } else { - removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - updateViews = function updateViews() { - return _this._standardProcessInstanceChanged(repeat, items); - }; - } - - if (removePromise instanceof Promise) { - removePromise.then(updateViews); - } else { - updateViews(); - } - } else { - this._inPlaceProcessItems(repeat, items); - } - }; - - ArrayRepeatStrategy.prototype._standardProcessInstanceChanged = function _standardProcessInstanceChanged(repeat, items) { - for (var i = 0, ii = items.length; i < ii; i++) { - var overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, items[i], i, ii); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - }; - - ArrayRepeatStrategy.prototype._inPlaceProcessItems = function _inPlaceProcessItems(repeat, items) { - var itemsLength = items.length; - var viewsLength = repeat.viewCount(); - - while (viewsLength > itemsLength) { - viewsLength--; - repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle); - } - - var local = repeat.local; - - for (var i = 0; i < viewsLength; i++) { - var view = repeat.view(i); - var last = i === itemsLength - 1; - var middle = i !== 0 && !last; - - if (view.bindingContext[local] === items[i] && view.overrideContext.$middle === middle && view.overrideContext.$last === last) { - continue; - } - - view.bindingContext[local] = items[i]; - view.overrideContext.$middle = middle; - view.overrideContext.$last = last; - repeat.updateBindings(view); - } - - for (var _i = viewsLength; _i < itemsLength; _i++) { - var overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, items[_i], _i, itemsLength); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - }; - - ArrayRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, array, splices) { - var _this2 = this; - - if (repeat.__queuedSplices) { - for (var i = 0, ii = splices.length; i < ii; ++i) { - var _splices$i = splices[i], - index = _splices$i.index, - removed = _splices$i.removed, - addedCount = _splices$i.addedCount; - - (0, _aureliaBinding.mergeSplice)(repeat.__queuedSplices, index, removed, addedCount); - } - - repeat.__array = array.slice(0); - return; - } - - var maybePromise = this._runSplices(repeat, array.slice(0), splices); - if (maybePromise instanceof Promise) { - var queuedSplices = repeat.__queuedSplices = []; - - var runQueuedSplices = function runQueuedSplices() { - if (!queuedSplices.length) { - repeat.__queuedSplices = undefined; - repeat.__array = undefined; - return; - } - - var nextPromise = _this2._runSplices(repeat, repeat.__array, queuedSplices) || Promise.resolve(); - queuedSplices = repeat.__queuedSplices = []; - nextPromise.then(runQueuedSplices); - }; - - maybePromise.then(runQueuedSplices); - } - }; - - ArrayRepeatStrategy.prototype._runSplices = function _runSplices(repeat, array, splices) { - var _this3 = this; - - var removeDelta = 0; - var rmPromises = []; - - for (var i = 0, ii = splices.length; i < ii; ++i) { - var splice = splices[i]; - var removed = splice.removed; - - for (var j = 0, jj = removed.length; j < jj; ++j) { - var viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - } - removeDelta -= splice.addedCount; - } - - if (rmPromises.length > 0) { - return Promise.all(rmPromises).then(function () { - var spliceIndexLow = _this3._handleAddedSplices(repeat, array, splices); - (0, _repeatUtilities.updateOverrideContexts)(repeat.views(), spliceIndexLow); - }); - } - - var spliceIndexLow = this._handleAddedSplices(repeat, array, splices); - (0, _repeatUtilities.updateOverrideContexts)(repeat.views(), spliceIndexLow); - - return undefined; - }; - - ArrayRepeatStrategy.prototype._handleAddedSplices = function _handleAddedSplices(repeat, array, splices) { - var spliceIndex = void 0; - var spliceIndexLow = void 0; - var arrayLength = array.length; - for (var i = 0, ii = splices.length; i < ii; ++i) { - var splice = splices[i]; - var addIndex = spliceIndex = splice.index; - var end = splice.index + splice.addedCount; - - if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) { - spliceIndexLow = spliceIndex; - } - - for (; addIndex < end; ++addIndex) { - var overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, array[addIndex], addIndex, arrayLength); - repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext); - } - } - - return spliceIndexLow; - }; - - return ArrayRepeatStrategy; - }(); -}); \ No newline at end of file diff --git a/dist/amd/attr-binding-behavior.js b/dist/amd/attr-binding-behavior.js deleted file mode 100644 index 9124e93..0000000 --- a/dist/amd/attr-binding-behavior.js +++ /dev/null @@ -1,26 +0,0 @@ -define(['exports', 'aurelia-binding'], function (exports, _aureliaBinding) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.AttrBindingBehavior = undefined; - - - - var _dec, _class; - - var AttrBindingBehavior = exports.AttrBindingBehavior = (_dec = (0, _aureliaBinding.bindingBehavior)('attr'), _dec(_class = function () { - function AttrBindingBehavior() { - - } - - AttrBindingBehavior.prototype.bind = function bind(binding, source) { - binding.targetObserver = new _aureliaBinding.DataAttributeObserver(binding.target, binding.targetProperty); - }; - - AttrBindingBehavior.prototype.unbind = function unbind(binding, source) {}; - - return AttrBindingBehavior; - }()) || _class); -}); \ No newline at end of file diff --git a/dist/amd/aurelia-hide-style.js b/dist/amd/aurelia-hide-style.js deleted file mode 100644 index 0fd2652..0000000 --- a/dist/amd/aurelia-hide-style.js +++ /dev/null @@ -1,24 +0,0 @@ -define(['exports', 'aurelia-pal'], function (exports, _aureliaPal) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.aureliaHideClassName = undefined; - exports.injectAureliaHideStyleAtHead = injectAureliaHideStyleAtHead; - exports.injectAureliaHideStyleAtBoundary = injectAureliaHideStyleAtBoundary; - var aureliaHideClassName = exports.aureliaHideClassName = 'aurelia-hide'; - - var aureliaHideClass = '.' + aureliaHideClassName + ' { display:none !important; }'; - - function injectAureliaHideStyleAtHead() { - _aureliaPal.DOM.injectStyles(aureliaHideClass); - } - - function injectAureliaHideStyleAtBoundary(domBoundary) { - if (_aureliaPal.FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) { - domBoundary.hasAureliaHideStyle = true; - _aureliaPal.DOM.injectStyles(aureliaHideClass, domBoundary); - } - } -}); \ No newline at end of file diff --git a/dist/amd/aurelia-templating-resources.js b/dist/amd/aurelia-templating-resources.js index 7efbb31..9fc6ad6 100644 --- a/dist/amd/aurelia-templating-resources.js +++ b/dist/amd/aurelia-templating-resources.js @@ -1,68 +1,1915 @@ -define(['exports', './compose', './if', './else', './with', './repeat', './show', './hide', './sanitize-html', './replaceable', './focus', 'aurelia-templating', './css-resource', './html-sanitizer', './attr-binding-behavior', './binding-mode-behaviors', './throttle-binding-behavior', './debounce-binding-behavior', './self-binding-behavior', './signal-binding-behavior', './binding-signaler', './update-trigger-binding-behavior', './abstract-repeater', './repeat-strategy-locator', './html-resource-plugin', './null-repeat-strategy', './array-repeat-strategy', './map-repeat-strategy', './set-repeat-strategy', './number-repeat-strategy', './repeat-utilities', './analyze-view-factory', './aurelia-hide-style'], function (exports, _compose, _if, _else, _with, _repeat, _show, _hide, _sanitizeHtml, _replaceable, _focus, _aureliaTemplating, _cssResource, _htmlSanitizer, _attrBindingBehavior, _bindingModeBehaviors, _throttleBindingBehavior, _debounceBindingBehavior, _selfBindingBehavior, _signalBindingBehavior, _bindingSignaler, _updateTriggerBindingBehavior, _abstractRepeater, _repeatStrategyLocator, _htmlResourcePlugin, _nullRepeatStrategy, _arrayRepeatStrategy, _mapRepeatStrategy, _setRepeatStrategy, _numberRepeatStrategy, _repeatUtilities, _analyzeViewFactory, _aureliaHideStyle) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.viewsRequireLifecycle = exports.unwrapExpression = exports.updateOneTimeBinding = exports.isOneTime = exports.getItemsSourceExpression = exports.updateOverrideContext = exports.createFullOverrideContext = exports.NumberRepeatStrategy = exports.SetRepeatStrategy = exports.MapRepeatStrategy = exports.ArrayRepeatStrategy = exports.NullRepeatStrategy = exports.RepeatStrategyLocator = exports.AbstractRepeater = exports.UpdateTriggerBindingBehavior = exports.BindingSignaler = exports.SignalBindingBehavior = exports.SelfBindingBehavior = exports.DebounceBindingBehavior = exports.ThrottleBindingBehavior = exports.TwoWayBindingBehavior = exports.FromViewBindingBehavior = exports.ToViewBindingBehavior = exports.OneWayBindingBehavior = exports.OneTimeBindingBehavior = exports.AttrBindingBehavior = exports.configure = exports.Focus = exports.Replaceable = exports.SanitizeHTMLValueConverter = exports.HTMLSanitizer = exports.Hide = exports.Show = exports.Repeat = exports.With = exports.Else = exports.If = exports.Compose = undefined; - - - function configure(config) { - (0, _aureliaHideStyle.injectAureliaHideStyleAtHead)(); - - config.globalResources(_compose.Compose, _if.If, _else.Else, _with.With, _repeat.Repeat, _show.Show, _hide.Hide, _replaceable.Replaceable, _focus.Focus, _sanitizeHtml.SanitizeHTMLValueConverter, _bindingModeBehaviors.OneTimeBindingBehavior, _bindingModeBehaviors.OneWayBindingBehavior, _bindingModeBehaviors.ToViewBindingBehavior, _bindingModeBehaviors.FromViewBindingBehavior, _bindingModeBehaviors.TwoWayBindingBehavior, _throttleBindingBehavior.ThrottleBindingBehavior, _debounceBindingBehavior.DebounceBindingBehavior, _selfBindingBehavior.SelfBindingBehavior, _signalBindingBehavior.SignalBindingBehavior, _updateTriggerBindingBehavior.UpdateTriggerBindingBehavior, _attrBindingBehavior.AttrBindingBehavior); - - (0, _htmlResourcePlugin.configure)(config); - - var viewEngine = config.container.get(_aureliaTemplating.ViewEngine); - var styleResourcePlugin = { - fetch: function fetch(address) { - var _ref; - - return _ref = {}, _ref[address] = (0, _cssResource._createCSSResource)(address), _ref; - } - }; - ['.css', '.less', '.sass', '.scss', '.styl'].forEach(function (ext) { - return viewEngine.addResourcePlugin(ext, styleResourcePlugin); - }); - } - - exports.Compose = _compose.Compose; - exports.If = _if.If; - exports.Else = _else.Else; - exports.With = _with.With; - exports.Repeat = _repeat.Repeat; - exports.Show = _show.Show; - exports.Hide = _hide.Hide; - exports.HTMLSanitizer = _htmlSanitizer.HTMLSanitizer; - exports.SanitizeHTMLValueConverter = _sanitizeHtml.SanitizeHTMLValueConverter; - exports.Replaceable = _replaceable.Replaceable; - exports.Focus = _focus.Focus; - exports.configure = configure; - exports.AttrBindingBehavior = _attrBindingBehavior.AttrBindingBehavior; - exports.OneTimeBindingBehavior = _bindingModeBehaviors.OneTimeBindingBehavior; - exports.OneWayBindingBehavior = _bindingModeBehaviors.OneWayBindingBehavior; - exports.ToViewBindingBehavior = _bindingModeBehaviors.ToViewBindingBehavior; - exports.FromViewBindingBehavior = _bindingModeBehaviors.FromViewBindingBehavior; - exports.TwoWayBindingBehavior = _bindingModeBehaviors.TwoWayBindingBehavior; - exports.ThrottleBindingBehavior = _throttleBindingBehavior.ThrottleBindingBehavior; - exports.DebounceBindingBehavior = _debounceBindingBehavior.DebounceBindingBehavior; - exports.SelfBindingBehavior = _selfBindingBehavior.SelfBindingBehavior; - exports.SignalBindingBehavior = _signalBindingBehavior.SignalBindingBehavior; - exports.BindingSignaler = _bindingSignaler.BindingSignaler; - exports.UpdateTriggerBindingBehavior = _updateTriggerBindingBehavior.UpdateTriggerBindingBehavior; - exports.AbstractRepeater = _abstractRepeater.AbstractRepeater; - exports.RepeatStrategyLocator = _repeatStrategyLocator.RepeatStrategyLocator; - exports.NullRepeatStrategy = _nullRepeatStrategy.NullRepeatStrategy; - exports.ArrayRepeatStrategy = _arrayRepeatStrategy.ArrayRepeatStrategy; - exports.MapRepeatStrategy = _mapRepeatStrategy.MapRepeatStrategy; - exports.SetRepeatStrategy = _setRepeatStrategy.SetRepeatStrategy; - exports.NumberRepeatStrategy = _numberRepeatStrategy.NumberRepeatStrategy; - exports.createFullOverrideContext = _repeatUtilities.createFullOverrideContext; - exports.updateOverrideContext = _repeatUtilities.updateOverrideContext; - exports.getItemsSourceExpression = _repeatUtilities.getItemsSourceExpression; - exports.isOneTime = _repeatUtilities.isOneTime; - exports.updateOneTimeBinding = _repeatUtilities.updateOneTimeBinding; - exports.unwrapExpression = _repeatUtilities.unwrapExpression; - exports.viewsRequireLifecycle = _analyzeViewFactory.viewsRequireLifecycle; -}); \ No newline at end of file +define(['exports', 'aurelia-dependency-injection', 'aurelia-pal', 'aurelia-task-queue', 'aurelia-templating', 'aurelia-binding', 'aurelia-logging', 'aurelia-loader', 'aurelia-path', 'aurelia-metadata'], function (exports, aureliaDependencyInjection, aureliaPal, aureliaTaskQueue, aureliaTemplating, aureliaBinding, aureliaLogging, aureliaLoader, aureliaPath, aureliaMetadata) { 'use strict'; + + /*! ***************************************************************************** + Copyright (c) Microsoft Corporation. All rights reserved. + Licensed under the Apache License, Version 2.0 (the "License"); you may not use + this file except in compliance with the License. You may obtain a copy of the + License at http://www.apache.org/licenses/LICENSE-2.0 + + THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED + WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, + MERCHANTABLITY OR NON-INFRINGEMENT. + + See the Apache Version 2.0 License for specific language governing permissions + and limitations under the License. + ***************************************************************************** */ + /* global Reflect, Promise */ + + var extendStatics = function(d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + + function __extends(d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + } + + function __decorate(decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; + } + + var Compose = (function () { + function Compose(element, container, compositionEngine, viewSlot, viewResources, taskQueue) { + this.element = element; + this.container = container; + this.compositionEngine = compositionEngine; + this.viewSlot = viewSlot; + this.viewResources = viewResources; + this.taskQueue = taskQueue; + this.currentController = null; + this.currentViewModel = null; + this.changes = Object.create(null); + } + Compose.inject = function () { + return [aureliaPal.DOM.Element, aureliaDependencyInjection.Container, aureliaTemplating.CompositionEngine, aureliaTemplating.ViewSlot, aureliaTemplating.ViewResources, aureliaTaskQueue.TaskQueue]; + }; + Compose.prototype.created = function (owningView) { + this.owningView = owningView; + }; + Compose.prototype.bind = function (bindingContext, overrideContext) { + this.bindingContext = bindingContext; + this.overrideContext = overrideContext; + var changes = this.changes; + changes.view = this.view; + changes.viewModel = this.viewModel; + changes.model = this.model; + if (!this.pendingTask) { + processChanges(this); + } + }; + Compose.prototype.unbind = function () { + this.changes = Object.create(null); + this.bindingContext = null; + this.overrideContext = null; + var returnToCache = true; + var skipAnimation = true; + this.viewSlot.removeAll(returnToCache, skipAnimation); + }; + Compose.prototype.modelChanged = function (newValue, oldValue) { + this.changes.model = newValue; + requestUpdate(this); + }; + Compose.prototype.viewChanged = function (newValue, oldValue) { + this.changes.view = newValue; + requestUpdate(this); + }; + Compose.prototype.viewModelChanged = function (newValue, oldValue) { + this.changes.viewModel = newValue; + requestUpdate(this); + }; + __decorate([ + aureliaTemplating.bindable + ], Compose.prototype, "model", void 0); + __decorate([ + aureliaTemplating.bindable + ], Compose.prototype, "view", void 0); + __decorate([ + aureliaTemplating.bindable + ], Compose.prototype, "viewModel", void 0); + __decorate([ + aureliaTemplating.bindable + ], Compose.prototype, "swapOrder", void 0); + Compose = __decorate([ + aureliaTemplating.noView, + aureliaTemplating.customElement('compose') + ], Compose); + return Compose; + }()); + function isEmpty(obj) { + for (var _ in obj) { + return false; + } + return true; + } + function tryActivateViewModel(vm, model) { + if (vm && typeof vm.activate === 'function') { + return Promise.resolve(vm.activate(model)); + } + } + function createInstruction(composer, instruction) { + return Object.assign(instruction, { + bindingContext: composer.bindingContext, + overrideContext: composer.overrideContext, + owningView: composer.owningView, + container: composer.container, + viewSlot: composer.viewSlot, + viewResources: composer.viewResources, + currentController: composer.currentController, + host: composer.element, + swapOrder: composer.swapOrder + }); + } + function processChanges(composer) { + var changes = composer.changes; + composer.changes = Object.create(null); + if (!('view' in changes) && !('viewModel' in changes) && ('model' in changes)) { + composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model); + if (!composer.pendingTask) { + return; + } + } + else { + var instruction = { + view: composer.view, + viewModel: composer.currentViewModel || composer.viewModel, + model: composer.model + }; + instruction = Object.assign(instruction, changes); + instruction = createInstruction(composer, instruction); + composer.pendingTask = composer.compositionEngine.compose(instruction).then(function (controller) { + composer.currentController = controller; + composer.currentViewModel = controller ? controller.viewModel : null; + }); + } + composer.pendingTask = composer.pendingTask + .then(function () { + completeCompositionTask(composer); + }, function (reason) { + completeCompositionTask(composer); + throw reason; + }); + } + function completeCompositionTask(composer) { + composer.pendingTask = null; + if (!isEmpty(composer.changes)) { + processChanges(composer); + } + } + function requestUpdate(composer) { + if (composer.pendingTask || composer.updateRequested) { + return; + } + composer.updateRequested = true; + composer.taskQueue.queueMicroTask(function () { + composer.updateRequested = false; + processChanges(composer); + }); + } + + var IfCore = (function () { + function IfCore(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.view = null; + this.bindingContext = null; + this.overrideContext = null; + this.showing = false; + this.cache = true; + } + IfCore.prototype.bind = function (bindingContext, overrideContext) { + this.bindingContext = bindingContext; + this.overrideContext = overrideContext; + }; + IfCore.prototype.unbind = function () { + if (this.view === null) { + return; + } + this.view.unbind(); + if (!this.viewFactory.isCaching) { + return; + } + if (this.showing) { + this.showing = false; + this.viewSlot.remove(this.view, true, true); + } + else { + this.view.returnToCache(); + } + this.view = null; + }; + IfCore.prototype._show = function () { + if (this.showing) { + if (!this.view.isBound) { + this.view.bind(this.bindingContext, this.overrideContext); + } + return; + } + if (this.view === null) { + this.view = this.viewFactory.create(); + } + if (!this.view.isBound) { + this.view.bind(this.bindingContext, this.overrideContext); + } + this.showing = true; + return this.viewSlot.add(this.view); + }; + IfCore.prototype._hide = function () { + var _this = this; + if (!this.showing) { + return; + } + this.showing = false; + var removed = this.viewSlot.remove(this.view); + if (removed instanceof Promise) { + return removed.then(function () { + _this._unbindView(); + }); + } + this._unbindView(); + }; + IfCore.prototype._unbindView = function () { + var cache = this.cache === 'false' ? false : !!this.cache; + this.view.unbind(); + if (!cache) { + this.view = null; + } + }; + return IfCore; + }()); + + var If = (function (_super) { + __extends(If, _super); + function If() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.cache = true; + return _this; + } + If.prototype.bind = function (bindingContext, overrideContext) { + _super.prototype.bind.call(this, bindingContext, overrideContext); + if (this.condition) { + this._show(); + } + else { + this._hide(); + } + }; + If.prototype.conditionChanged = function (newValue) { + this._update(newValue); + }; + If.prototype._update = function (show) { + var _this = this; + if (this.animating) { + return; + } + var promise; + if (this.elseVm) { + promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm); + } + else { + promise = show ? this._show() : this._hide(); + } + if (promise) { + this.animating = true; + promise.then(function () { + _this.animating = false; + if (_this.condition !== _this.showing) { + _this._update(_this.condition); + } + }); + } + }; + If.prototype._swap = function (remove, add) { + switch (this.swapOrder) { + case 'before': + return Promise.resolve(add._show()).then(function () { return remove._hide(); }); + case 'with': + return Promise.all([remove._hide(), add._show()]); + default: + var promise = remove._hide(); + return promise ? promise.then(function () { return add._show(); }) : add._show(); + } + }; + __decorate([ + aureliaTemplating.bindable({ primaryProperty: true }) + ], If.prototype, "condition", void 0); + __decorate([ + aureliaTemplating.bindable + ], If.prototype, "swapOrder", void 0); + __decorate([ + aureliaTemplating.bindable + ], If.prototype, "cache", void 0); + If = __decorate([ + aureliaTemplating.customAttribute('if'), + aureliaTemplating.templateController, + aureliaDependencyInjection.inject(aureliaTemplating.BoundViewFactory, aureliaTemplating.ViewSlot) + ], If); + return If; + }(IfCore)); + + var Else = (function (_super) { + __extends(Else, _super); + function Else(viewFactory, viewSlot) { + var _this = _super.call(this, viewFactory, viewSlot) || this; + _this._registerInIf(); + return _this; + } + Else.prototype.bind = function (bindingContext, overrideContext) { + _super.prototype.bind.call(this, bindingContext, overrideContext); + if (this.ifVm.condition) { + this._hide(); + } + else { + this._show(); + } + }; + Else.prototype._registerInIf = function () { + var previous = this.viewSlot.anchor.previousSibling; + while (previous && !previous.au) { + previous = previous.previousSibling; + } + if (!previous || !previous.au.if) { + throw new Error("Can't find matching If for Else custom attribute."); + } + this.ifVm = previous.au.if.viewModel; + this.ifVm.elseVm = this; + }; + Else = __decorate([ + aureliaTemplating.customAttribute('else'), + aureliaTemplating.templateController, + aureliaDependencyInjection.inject(aureliaTemplating.BoundViewFactory, aureliaTemplating.ViewSlot) + ], Else); + return Else; + }(IfCore)); + + var With = (function () { + function With(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.parentOverrideContext = null; + this.view = null; + } + With.prototype.bind = function (bindingContext, overrideContext) { + this.parentOverrideContext = overrideContext; + this.valueChanged(this.value); + }; + With.prototype.valueChanged = function (newValue) { + var overrideContext = aureliaBinding.createOverrideContext(newValue, this.parentOverrideContext); + var view = this.view; + if (!view) { + view = this.view = this.viewFactory.create(); + view.bind(newValue, overrideContext); + this.viewSlot.add(view); + } + else { + view.bind(newValue, overrideContext); + } + }; + With.prototype.unbind = function () { + var view = this.view; + this.parentOverrideContext = null; + if (view) { + view.unbind(); + } + }; + With = __decorate([ + aureliaTemplating.customAttribute('with'), + aureliaTemplating.templateController, + aureliaDependencyInjection.inject(aureliaTemplating.BoundViewFactory, aureliaTemplating.ViewSlot) + ], With); + return With; + }()); + + var oneTime = aureliaBinding.bindingMode.oneTime; + function updateOverrideContexts(views, startIndex) { + var length = views.length; + if (startIndex > 0) { + startIndex = startIndex - 1; + } + for (; startIndex < length; ++startIndex) { + updateOverrideContext(views[startIndex].overrideContext, startIndex, length); + } + } + function createFullOverrideContext(repeat, data, index, length, key) { + var bindingContext = {}; + var overrideContext = aureliaBinding.createOverrideContext(bindingContext, repeat.scope.overrideContext); + if (typeof key !== 'undefined') { + bindingContext[repeat.key] = key; + bindingContext[repeat.value] = data; + } + else { + bindingContext[repeat.local] = data; + } + updateOverrideContext(overrideContext, index, length); + return overrideContext; + } + function updateOverrideContext(overrideContext, index, length) { + var first = (index === 0); + var last = (index === length - 1); + var even = index % 2 === 0; + overrideContext.$index = index; + overrideContext.$first = first; + overrideContext.$last = last; + overrideContext.$middle = !(first || last); + overrideContext.$odd = !even; + overrideContext.$even = even; + } + function getItemsSourceExpression(instruction, attrName) { + return instruction.behaviorInstructions + .filter(function (bi) { return bi.originalAttrName === attrName; })[0] + .attributes + .items + .sourceExpression; + } + function unwrapExpression(expression) { + var unwrapped = false; + while (expression instanceof aureliaBinding.BindingBehavior) { + expression = expression.expression; + } + while (expression instanceof aureliaBinding.ValueConverter) { + expression = expression.expression; + unwrapped = true; + } + return unwrapped ? expression : null; + } + function isOneTime(expression) { + while (expression instanceof aureliaBinding.BindingBehavior) { + if (expression.name === 'oneTime') { + return true; + } + expression = expression.expression; + } + return false; + } + function updateOneTimeBinding(binding) { + if (binding.call && binding.mode === oneTime) { + binding.call(aureliaBinding.sourceContext); + } + else if (binding.updateOneTimeBindings) { + binding.updateOneTimeBindings(); + } + } + function indexOf(array, item, matcher, startIndex) { + if (!matcher) { + return array.indexOf(item); + } + var length = array.length; + for (var index = startIndex || 0; index < length; index++) { + if (matcher(array[index], item)) { + return index; + } + } + return -1; + } + + var ArrayRepeatStrategy = (function () { + function ArrayRepeatStrategy() { + } + ArrayRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + return observerLocator.getArrayObserver(items); + }; + ArrayRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + var _this = this; + var itemsLength = items.length; + if (!items || itemsLength === 0) { + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + return; + } + var children = repeat.views(); + var viewsLength = children.length; + if (viewsLength === 0) { + this._standardProcessInstanceChanged(repeat, items); + return; + } + if (repeat.viewsRequireLifecycle) { + var childrenSnapshot = children.slice(0); + var itemNameInBindingContext = repeat.local; + var matcher_1 = repeat.matcher(); + var itemsPreviouslyInViews_1 = []; + var viewsToRemove = []; + for (var index = 0; index < viewsLength; index++) { + var view = childrenSnapshot[index]; + var oldItem = view.bindingContext[itemNameInBindingContext]; + if (indexOf(items, oldItem, matcher_1) === -1) { + viewsToRemove.push(view); + } + else { + itemsPreviouslyInViews_1.push(oldItem); + } + } + var updateViews = void 0; + var removePromise = void 0; + if (itemsPreviouslyInViews_1.length > 0) { + removePromise = repeat.removeViews(viewsToRemove, true, !repeat.viewsRequireLifecycle); + updateViews = function () { + for (var index = 0; index < itemsLength; index++) { + var item = items[index]; + var indexOfView = indexOf(itemsPreviouslyInViews_1, item, matcher_1, index); + var view = void 0; + if (indexOfView === -1) { + var overrideContext = createFullOverrideContext(repeat, items[index], index, itemsLength); + repeat.insertView(index, overrideContext.bindingContext, overrideContext); + itemsPreviouslyInViews_1.splice(index, 0, undefined); + } + else if (indexOfView === index) { + view = children[indexOfView]; + itemsPreviouslyInViews_1[indexOfView] = undefined; + } + else { + view = children[indexOfView]; + repeat.moveView(indexOfView, index); + itemsPreviouslyInViews_1.splice(indexOfView, 1); + itemsPreviouslyInViews_1.splice(index, 0, undefined); + } + if (view) { + updateOverrideContext(view.overrideContext, index, itemsLength); + } + } + _this._inPlaceProcessItems(repeat, items); + }; + } + else { + removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + updateViews = function () { return _this._standardProcessInstanceChanged(repeat, items); }; + } + if (removePromise instanceof Promise) { + removePromise.then(updateViews); + } + else { + updateViews(); + } + } + else { + this._inPlaceProcessItems(repeat, items); + } + }; + ArrayRepeatStrategy.prototype._standardProcessInstanceChanged = function (repeat, items) { + for (var i = 0, ii = items.length; i < ii; i++) { + var overrideContext = createFullOverrideContext(repeat, items[i], i, ii); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + }; + ArrayRepeatStrategy.prototype._inPlaceProcessItems = function (repeat, items) { + var itemsLength = items.length; + var viewsLength = repeat.viewCount(); + while (viewsLength > itemsLength) { + viewsLength--; + repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle); + } + var local = repeat.local; + for (var i = 0; i < viewsLength; i++) { + var view = repeat.view(i); + var last = i === itemsLength - 1; + var middle = i !== 0 && !last; + var bindingContext = view.bindingContext; + var overrideContext = view.overrideContext; + if (bindingContext[local] === items[i] + && overrideContext.$middle === middle + && overrideContext.$last === last) { + continue; + } + bindingContext[local] = items[i]; + overrideContext.$middle = middle; + overrideContext.$last = last; + repeat.updateBindings(view); + } + for (var i = viewsLength; i < itemsLength; i++) { + var overrideContext = createFullOverrideContext(repeat, items[i], i, itemsLength); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + }; + ArrayRepeatStrategy.prototype.instanceMutated = function (repeat, array, splices) { + var _this = this; + if (repeat.__queuedSplices) { + for (var i = 0, ii = splices.length; i < ii; ++i) { + var _a = splices[i], index = _a.index, removed = _a.removed, addedCount = _a.addedCount; + aureliaBinding.mergeSplice(repeat.__queuedSplices, index, removed, addedCount); + } + repeat.__array = array.slice(0); + return; + } + var maybePromise = this._runSplices(repeat, array.slice(0), splices); + if (maybePromise instanceof Promise) { + var queuedSplices_1 = repeat.__queuedSplices = []; + var runQueuedSplices_1 = function () { + if (!queuedSplices_1.length) { + repeat.__queuedSplices = undefined; + repeat.__array = undefined; + return; + } + var nextPromise = _this._runSplices(repeat, repeat.__array, queuedSplices_1) || Promise.resolve(); + queuedSplices_1 = repeat.__queuedSplices = []; + nextPromise.then(runQueuedSplices_1); + }; + maybePromise.then(runQueuedSplices_1); + } + }; + ArrayRepeatStrategy.prototype._runSplices = function (repeat, array, splices) { + var _this = this; + var removeDelta = 0; + var rmPromises = []; + for (var i = 0, ii = splices.length; i < ii; ++i) { + var splice = splices[i]; + var removed = splice.removed; + for (var j = 0, jj = removed.length; j < jj; ++j) { + var viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + } + removeDelta -= splice.addedCount; + } + if (rmPromises.length > 0) { + return Promise.all(rmPromises).then(function () { + var spliceIndexLow = _this._handleAddedSplices(repeat, array, splices); + updateOverrideContexts(repeat.views(), spliceIndexLow); + }); + } + var spliceIndexLow = this._handleAddedSplices(repeat, array, splices); + updateOverrideContexts(repeat.views(), spliceIndexLow); + return undefined; + }; + ArrayRepeatStrategy.prototype._handleAddedSplices = function (repeat, array, splices) { + var spliceIndex; + var spliceIndexLow; + var arrayLength = array.length; + for (var i = 0, ii = splices.length; i < ii; ++i) { + var splice = splices[i]; + var addIndex = spliceIndex = splice.index; + var end = splice.index + splice.addedCount; + if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) { + spliceIndexLow = spliceIndex; + } + for (; addIndex < end; ++addIndex) { + var overrideContext = createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength); + repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext); + } + } + return spliceIndexLow; + }; + return ArrayRepeatStrategy; + }()); + + var MapRepeatStrategy = (function () { + function MapRepeatStrategy() { + } + MapRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + return observerLocator.getMapObserver(items); + }; + MapRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + var _this = this; + var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(function () { return _this._standardProcessItems(repeat, items); }); + return; + } + this._standardProcessItems(repeat, items); + }; + MapRepeatStrategy.prototype._standardProcessItems = function (repeat, items) { + var index = 0; + var overrideContext; + items.forEach(function (value, key) { + overrideContext = createFullOverrideContext(repeat, value, index, items.size, key); + repeat.addView(overrideContext.bindingContext, overrideContext); + ++index; + }); + }; + MapRepeatStrategy.prototype.instanceMutated = function (repeat, map, records) { + var key; + var i; + var ii; + var overrideContext; + var removeIndex; + var addIndex; + var record; + var rmPromises = []; + var viewOrPromise; + for (i = 0, ii = records.length; i < ii; ++i) { + record = records[i]; + key = record.key; + switch (record.type) { + case 'update': + removeIndex = this._getViewIndexByKey(repeat, key); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + overrideContext = createFullOverrideContext(repeat, map.get(key), removeIndex, map.size, key); + repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext); + break; + case 'add': + addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1; + overrideContext = createFullOverrideContext(repeat, map.get(key), addIndex, map.size, key); + repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext); + break; + case 'delete': + if (record.oldValue === undefined) { + return; + } + removeIndex = this._getViewIndexByKey(repeat, key); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + break; + case 'clear': + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + break; + default: + continue; + } + } + if (rmPromises.length > 0) { + Promise.all(rmPromises).then(function () { + updateOverrideContexts(repeat.views(), 0); + }); + } + else { + updateOverrideContexts(repeat.views(), 0); + } + }; + MapRepeatStrategy.prototype._getViewIndexByKey = function (repeat, key) { + var i; + var ii; + var child; + for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { + child = repeat.view(i); + if (child.bindingContext[repeat.key] === key) { + return i; + } + } + return undefined; + }; + return MapRepeatStrategy; + }()); + + var NullRepeatStrategy = (function () { + function NullRepeatStrategy() { + } + NullRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + repeat.removeAllViews(true); + }; + NullRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + }; + return NullRepeatStrategy; + }()); + + var NumberRepeatStrategy = (function () { + function NumberRepeatStrategy() { + } + NumberRepeatStrategy.prototype.getCollectionObserver = function () { + return null; + }; + NumberRepeatStrategy.prototype.instanceChanged = function (repeat, value) { + var _this = this; + var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(function () { return _this._standardProcessItems(repeat, value); }); + return; + } + this._standardProcessItems(repeat, value); + }; + NumberRepeatStrategy.prototype._standardProcessItems = function (repeat, value) { + var childrenLength = repeat.viewCount(); + var i; + var ii; + var overrideContext; + var viewsToRemove; + value = Math.floor(value); + viewsToRemove = childrenLength - value; + if (viewsToRemove > 0) { + if (viewsToRemove > childrenLength) { + viewsToRemove = childrenLength; + } + for (i = 0, ii = viewsToRemove; i < ii; ++i) { + repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle); + } + return; + } + for (i = childrenLength, ii = value; i < ii; ++i) { + overrideContext = createFullOverrideContext(repeat, i, i, ii); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + updateOverrideContexts(repeat.views(), 0); + }; + return NumberRepeatStrategy; + }()); + + var SetRepeatStrategy = (function () { + function SetRepeatStrategy() { + } + SetRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + return observerLocator.getSetObserver(items); + }; + SetRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + var _this = this; + var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(function () { return _this._standardProcessItems(repeat, items); }); + return; + } + this._standardProcessItems(repeat, items); + }; + SetRepeatStrategy.prototype._standardProcessItems = function (repeat, items) { + var index = 0; + var overrideContext; + items.forEach(function (value) { + overrideContext = createFullOverrideContext(repeat, value, index, items.size); + repeat.addView(overrideContext.bindingContext, overrideContext); + ++index; + }); + }; + SetRepeatStrategy.prototype.instanceMutated = function (repeat, set, records) { + var value; + var i; + var ii; + var overrideContext; + var removeIndex; + var record; + var rmPromises = []; + var viewOrPromise; + for (i = 0, ii = records.length; i < ii; ++i) { + record = records[i]; + value = record.value; + switch (record.type) { + case 'add': + var size = Math.max(set.size - 1, 0); + overrideContext = createFullOverrideContext(repeat, value, size, set.size); + repeat.insertView(size, overrideContext.bindingContext, overrideContext); + break; + case 'delete': + removeIndex = this._getViewIndexByValue(repeat, value); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + break; + case 'clear': + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + break; + default: + continue; + } + } + if (rmPromises.length > 0) { + Promise.all(rmPromises).then(function () { + updateOverrideContexts(repeat.views(), 0); + }); + } + else { + updateOverrideContexts(repeat.views(), 0); + } + }; + SetRepeatStrategy.prototype._getViewIndexByValue = function (repeat, value) { + var i; + var ii; + var child; + for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { + child = repeat.view(i); + if (child.bindingContext[repeat.local] === value) { + return i; + } + } + return undefined; + }; + return SetRepeatStrategy; + }()); + + var RepeatStrategyLocator = (function () { + function RepeatStrategyLocator() { + this.matchers = []; + this.strategies = []; + this.addStrategy(function (items) { return items === null || items === undefined; }, new NullRepeatStrategy()); + this.addStrategy(function (items) { return items instanceof Array; }, new ArrayRepeatStrategy()); + this.addStrategy(function (items) { return items instanceof Map; }, new MapRepeatStrategy()); + this.addStrategy(function (items) { return items instanceof Set; }, new SetRepeatStrategy()); + this.addStrategy(function (items) { return typeof items === 'number'; }, new NumberRepeatStrategy()); + } + RepeatStrategyLocator.prototype.addStrategy = function (matcher, strategy) { + this.matchers.push(matcher); + this.strategies.push(strategy); + }; + RepeatStrategyLocator.prototype.getStrategy = function (items) { + var matchers = this.matchers; + for (var i = 0, ii = matchers.length; i < ii; ++i) { + if (matchers[i](items)) { + return this.strategies[i]; + } + } + return null; + }; + return RepeatStrategyLocator; + }()); + + var lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with']; + function behaviorRequiresLifecycle(instruction) { + var t = instruction.type; + var name = t.elementName !== null ? t.elementName : t.attributeName; + return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind) + || t.viewFactory && viewsRequireLifecycle(t.viewFactory) + || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); + } + function targetRequiresLifecycle(instruction) { + var behaviors = instruction.behaviorInstructions; + if (behaviors) { + var i = behaviors.length; + while (i--) { + if (behaviorRequiresLifecycle(behaviors[i])) { + return true; + } + } + } + return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); + } + function viewsRequireLifecycle(viewFactory) { + if ('_viewsRequireLifecycle' in viewFactory) { + return viewFactory._viewsRequireLifecycle; + } + viewFactory._viewsRequireLifecycle = false; + if (viewFactory.viewFactory) { + viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory); + return viewFactory._viewsRequireLifecycle; + } + if (viewFactory.template.querySelector('.au-animate')) { + viewFactory._viewsRequireLifecycle = true; + return true; + } + for (var id in viewFactory.instructions) { + if (targetRequiresLifecycle(viewFactory.instructions[id])) { + viewFactory._viewsRequireLifecycle = true; + return true; + } + } + viewFactory._viewsRequireLifecycle = false; + return false; + } + + var AbstractRepeater = (function () { + function AbstractRepeater(options) { + Object.assign(this, { + local: 'items', + viewsRequireLifecycle: true + }, options); + } + AbstractRepeater.prototype.viewCount = function () { + throw new Error('subclass must implement `viewCount`'); + }; + AbstractRepeater.prototype.views = function () { + throw new Error('subclass must implement `views`'); + }; + AbstractRepeater.prototype.view = function (index) { + throw new Error('subclass must implement `view`'); + }; + AbstractRepeater.prototype.matcher = function () { + throw new Error('subclass must implement `matcher`'); + }; + AbstractRepeater.prototype.addView = function (bindingContext, overrideContext) { + throw new Error('subclass must implement `addView`'); + }; + AbstractRepeater.prototype.insertView = function (index, bindingContext, overrideContext) { + throw new Error('subclass must implement `insertView`'); + }; + AbstractRepeater.prototype.moveView = function (sourceIndex, targetIndex) { + throw new Error('subclass must implement `moveView`'); + }; + AbstractRepeater.prototype.removeAllViews = function (returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeAllViews`'); + }; + AbstractRepeater.prototype.removeViews = function (viewsToRemove, returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeView`'); + }; + AbstractRepeater.prototype.removeView = function (index, returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeView`'); + }; + AbstractRepeater.prototype.updateBindings = function (view) { + throw new Error('subclass must implement `updateBindings`'); + }; + return AbstractRepeater; + }()); + + var Repeat = (function (_super) { + __extends(Repeat, _super); + function Repeat(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) { + var _this = _super.call(this, { + local: 'item', + viewsRequireLifecycle: viewsRequireLifecycle(viewFactory) + }) || this; + _this.viewFactory = viewFactory; + _this.instruction = instruction; + _this.viewSlot = viewSlot; + _this.lookupFunctions = viewResources.lookupFunctions; + _this.observerLocator = observerLocator; + _this.key = 'key'; + _this.value = 'value'; + _this.strategyLocator = strategyLocator; + _this.ignoreMutation = false; + _this.sourceExpression = getItemsSourceExpression(_this.instruction, 'repeat.for'); + _this.isOneTime = isOneTime(_this.sourceExpression); + _this.viewsRequireLifecycle = viewsRequireLifecycle(viewFactory); + return _this; + } + Repeat.prototype.call = function (context, changes) { + this[context](this.items, changes); + }; + Repeat.prototype.bind = function (bindingContext, overrideContext) { + this.scope = { bindingContext: bindingContext, overrideContext: overrideContext }; + this.matcherBinding = this._captureAndRemoveMatcherBinding(); + this.itemsChanged(); + }; + Repeat.prototype.unbind = function () { + this.scope = null; + this.items = null; + this.matcherBinding = null; + this.viewSlot.removeAll(true, true); + this._unsubscribeCollection(); + }; + Repeat.prototype._unsubscribeCollection = function () { + if (this.collectionObserver) { + this.collectionObserver.unsubscribe(this.callContext, this); + this.collectionObserver = null; + this.callContext = null; + } + }; + Repeat.prototype.itemsChanged = function () { + var _this = this; + this._unsubscribeCollection(); + if (!this.scope) { + return; + } + var items = this.items; + this.strategy = this.strategyLocator.getStrategy(items); + if (!this.strategy) { + throw new Error("Value for '" + this.sourceExpression + "' is non-repeatable"); + } + if (!this.isOneTime && !this._observeInnerCollection()) { + this._observeCollection(); + } + this.ignoreMutation = true; + this.strategy.instanceChanged(this, items); + this.observerLocator.taskQueue.queueMicroTask(function () { + _this.ignoreMutation = false; + }); + }; + Repeat.prototype._getInnerCollection = function () { + var expression = unwrapExpression(this.sourceExpression); + if (!expression) { + return null; + } + return expression.evaluate(this.scope, null); + }; + Repeat.prototype.handleCollectionMutated = function (collection, changes) { + if (!this.collectionObserver) { + return; + } + if (this.ignoreMutation) { + return; + } + this.strategy.instanceMutated(this, collection, changes); + }; + Repeat.prototype.handleInnerCollectionMutated = function (collection, changes) { + var _this = this; + if (!this.collectionObserver) { + return; + } + if (this.ignoreMutation) { + return; + } + this.ignoreMutation = true; + var newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions); + this.observerLocator.taskQueue.queueMicroTask(function () { return _this.ignoreMutation = false; }); + if (newItems === this.items) { + this.itemsChanged(); + } + else { + this.items = newItems; + } + }; + Repeat.prototype._observeInnerCollection = function () { + var items = this._getInnerCollection(); + var strategy = this.strategyLocator.getStrategy(items); + if (!strategy) { + return false; + } + this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items); + if (!this.collectionObserver) { + return false; + } + this.callContext = 'handleInnerCollectionMutated'; + this.collectionObserver.subscribe(this.callContext, this); + return true; + }; + Repeat.prototype._observeCollection = function () { + var items = this.items; + this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items); + if (this.collectionObserver) { + this.callContext = 'handleCollectionMutated'; + this.collectionObserver.subscribe(this.callContext, this); + } + }; + Repeat.prototype._captureAndRemoveMatcherBinding = function () { + if (this.viewFactory.viewFactory) { + var instructions = this.viewFactory.viewFactory.instructions; + var instructionIds = Object.keys(instructions); + for (var i = 0; i < instructionIds.length; i++) { + var expressions = instructions[instructionIds[i]].expressions; + if (expressions) { + for (var ii = 0; ii < expressions.length; ii++) { + if (expressions[ii].targetProperty === 'matcher') { + var matcherBinding = expressions[ii]; + expressions.splice(ii, 1); + return matcherBinding; + } + } + } + } + } + return undefined; + }; + Repeat.prototype.viewCount = function () { return this.viewSlot.children.length; }; + Repeat.prototype.views = function () { return this.viewSlot.children; }; + Repeat.prototype.view = function (index) { return this.viewSlot.children[index]; }; + Repeat.prototype.matcher = function () { return this.matcherBinding ? this.matcherBinding.sourceExpression.evaluate(this.scope, this.matcherBinding.lookupFunctions) : null; }; + Repeat.prototype.addView = function (bindingContext, overrideContext) { + var view = this.viewFactory.create(); + view.bind(bindingContext, overrideContext); + this.viewSlot.add(view); + }; + Repeat.prototype.insertView = function (index, bindingContext, overrideContext) { + var view = this.viewFactory.create(); + view.bind(bindingContext, overrideContext); + this.viewSlot.insert(index, view); + }; + Repeat.prototype.moveView = function (sourceIndex, targetIndex) { + this.viewSlot.move(sourceIndex, targetIndex); + }; + Repeat.prototype.removeAllViews = function (returnToCache, skipAnimation) { + return this.viewSlot.removeAll(returnToCache, skipAnimation); + }; + Repeat.prototype.removeViews = function (viewsToRemove, returnToCache, skipAnimation) { + return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation); + }; + Repeat.prototype.removeView = function (index, returnToCache, skipAnimation) { + return this.viewSlot.removeAt(index, returnToCache, skipAnimation); + }; + Repeat.prototype.updateBindings = function (view) { + var $view = view; + var j = $view.bindings.length; + while (j--) { + updateOneTimeBinding($view.bindings[j]); + } + j = $view.controllers.length; + while (j--) { + var k = $view.controllers[j].boundProperties.length; + while (k--) { + var binding = $view.controllers[j].boundProperties[k].binding; + updateOneTimeBinding(binding); + } + } + }; + __decorate([ + aureliaTemplating.bindable + ], Repeat.prototype, "items", void 0); + __decorate([ + aureliaTemplating.bindable + ], Repeat.prototype, "local", void 0); + __decorate([ + aureliaTemplating.bindable + ], Repeat.prototype, "key", void 0); + __decorate([ + aureliaTemplating.bindable + ], Repeat.prototype, "value", void 0); + Repeat = __decorate([ + aureliaTemplating.customAttribute('repeat'), + aureliaTemplating.templateController, + aureliaDependencyInjection.inject(aureliaTemplating.BoundViewFactory, aureliaTemplating.TargetInstruction, aureliaTemplating.ViewSlot, aureliaTemplating.ViewResources, aureliaBinding.ObserverLocator, RepeatStrategyLocator) + ], Repeat); + return Repeat; + }(AbstractRepeater)); + + var aureliaHideClassName = 'aurelia-hide'; + var aureliaHideClass = "." + aureliaHideClassName + " { display:none !important; }"; + function injectAureliaHideStyleAtHead() { + aureliaPal.DOM.injectStyles(aureliaHideClass); + } + function injectAureliaHideStyleAtBoundary(domBoundary) { + if (aureliaPal.FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) { + domBoundary.hasAureliaHideStyle = true; + aureliaPal.DOM.injectStyles(aureliaHideClass, domBoundary); + } + } + + var Show = (function () { + function Show(element, animator, domBoundary) { + this.element = element; + this.animator = animator; + this.domBoundary = domBoundary; + } + Show.inject = function () { + return [aureliaPal.DOM.Element, aureliaTemplating.Animator, aureliaDependencyInjection.Optional.of(aureliaPal.DOM.boundary, true)]; + }; + Show.prototype.created = function () { + injectAureliaHideStyleAtBoundary(this.domBoundary); + }; + Show.prototype.valueChanged = function (newValue) { + var element = this.element; + var animator = this.animator; + if (newValue) { + animator.removeClass(element, aureliaHideClassName); + } + else { + animator.addClass(element, aureliaHideClassName); + } + }; + Show.prototype.bind = function (bindingContext) { + this.valueChanged(this.value); + }; + Show = __decorate([ + aureliaTemplating.customAttribute('show') + ], Show); + return Show; + }()); + + var Hide = (function () { + function Hide(element, animator, domBoundary) { + this.element = element; + this.animator = animator; + this.domBoundary = domBoundary; + } + Hide.inject = function () { + return [aureliaPal.DOM.Element, aureliaTemplating.Animator, aureliaDependencyInjection.Optional.of(aureliaPal.DOM.boundary, true)]; + }; + Hide.prototype.created = function () { + injectAureliaHideStyleAtBoundary(this.domBoundary); + }; + Hide.prototype.valueChanged = function (newValue) { + if (newValue) { + this.animator.addClass(this.element, aureliaHideClassName); + } + else { + this.animator.removeClass(this.element, aureliaHideClassName); + } + }; + Hide.prototype.bind = function (bindingContext) { + this.valueChanged(this.value); + }; + Hide.prototype.value = function (value) { + throw new Error('Method not implemented.'); + }; + Hide = __decorate([ + aureliaTemplating.customAttribute('hide') + ], Hide); + return Hide; + }()); + + var SCRIPT_REGEX = /)<[^<]*)*<\/script>/gi; + var needsToWarn = true; + var HTMLSanitizer = (function () { + function HTMLSanitizer() { + } + HTMLSanitizer.prototype.sanitize = function (input) { + if (needsToWarn) { + needsToWarn = false; + aureliaLogging.getLogger('html-sanitizer') + .warn("CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks,\nand should not be relied on for sanitizing input from unknown sources.\nPlease see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html."); + } + return input.replace(SCRIPT_REGEX, ''); + }; + return HTMLSanitizer; + }()); + + var SanitizeHTMLValueConverter = (function () { + function SanitizeHTMLValueConverter(sanitizer) { + this.sanitizer = sanitizer; + } + SanitizeHTMLValueConverter.prototype.toView = function (untrustedMarkup) { + if (untrustedMarkup === null || untrustedMarkup === undefined) { + return null; + } + return this.sanitizer.sanitize(untrustedMarkup); + }; + SanitizeHTMLValueConverter = __decorate([ + aureliaBinding.valueConverter('sanitizeHTML'), + aureliaDependencyInjection.inject(HTMLSanitizer) + ], SanitizeHTMLValueConverter); + return SanitizeHTMLValueConverter; + }()); + + var Replaceable = (function () { + function Replaceable(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.view = null; + } + Replaceable.prototype.bind = function (bindingContext, overrideContext) { + if (this.view === null) { + this.view = this.viewFactory.create(); + this.viewSlot.add(this.view); + } + this.view.bind(bindingContext, overrideContext); + }; + Replaceable.prototype.unbind = function () { + this.view.unbind(); + }; + Replaceable = __decorate([ + aureliaTemplating.customAttribute('replaceable'), + aureliaTemplating.templateController, + aureliaDependencyInjection.inject(aureliaTemplating.BoundViewFactory, aureliaTemplating.ViewSlot) + ], Replaceable); + return Replaceable; + }()); + + var Focus = (function () { + function Focus(element, taskQueue) { + this.element = element; + this.taskQueue = taskQueue; + this.isAttached = false; + this.needsApply = false; + } + Focus.inject = function () { + return [aureliaPal.DOM.Element, aureliaTaskQueue.TaskQueue]; + }; + Focus.prototype.valueChanged = function (newValue) { + if (this.isAttached) { + this._apply(); + } + else { + this.needsApply = true; + } + }; + Focus.prototype._apply = function () { + var _this = this; + if (this.value) { + this.taskQueue.queueMicroTask(function () { + if (_this.value) { + _this.element.focus(); + } + }); + } + else { + this.element.blur(); + } + }; + Focus.prototype.attached = function () { + this.isAttached = true; + if (this.needsApply) { + this.needsApply = false; + this._apply(); + } + this.element.addEventListener('focus', this); + this.element.addEventListener('blur', this); + }; + Focus.prototype.detached = function () { + this.isAttached = false; + this.element.removeEventListener('focus', this); + this.element.removeEventListener('blur', this); + }; + Focus.prototype.handleEvent = function (e) { + if (e.type === 'focus') { + this.value = true; + } + else if (aureliaPal.DOM.activeElement !== this.element) { + this.value = false; + } + }; + Focus = __decorate([ + aureliaTemplating.customAttribute('focus', aureliaBinding.bindingMode.twoWay) + ], Focus); + return Focus; + }()); + + var cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi; + function fixupCSSUrls(address, css) { + if (typeof css !== 'string') { + throw new Error("Failed loading required CSS file: " + address); + } + return css.replace(cssUrlMatcher, function (match, p1) { + var quote = p1.charAt(0); + if (quote === '\'' || quote === '"') { + p1 = p1.substr(1, p1.length - 2); + } + return 'url(\'' + aureliaPath.relativeToFile(p1, address) + '\')'; + }); + } + var CSSResource = (function () { + function CSSResource(address) { + this.address = address; + this._scoped = null; + this._global = false; + this._alreadyGloballyInjected = false; + } + CSSResource.prototype.initialize = function (container, Target) { + this._scoped = new Target(this); + }; + CSSResource.prototype.register = function (registry, name) { + if (name === 'scoped') { + registry.registerViewEngineHooks(this._scoped); + } + else { + this._global = true; + } + }; + CSSResource.prototype.load = function (container) { + var _this = this; + return container.get(aureliaLoader.Loader) + .loadText(this.address) + .catch(function (err) { return null; }) + .then(function (text) { + text = fixupCSSUrls(_this.address, text); + _this._scoped.css = text; + if (_this._global) { + _this._alreadyGloballyInjected = true; + aureliaPal.DOM.injectStyles(text); + } + }); + }; + return CSSResource; + }()); + var CSSViewEngineHooks = (function () { + function CSSViewEngineHooks(owner) { + this.owner = owner; + this.css = null; + } + CSSViewEngineHooks.prototype.beforeCompile = function (content, resources, instruction) { + if (instruction.targetShadowDOM) { + aureliaPal.DOM.injectStyles(this.css, content, true); + } + else if (aureliaPal.FEATURE.scopedCSS) { + var styleNode = aureliaPal.DOM.injectStyles(this.css, content, true); + styleNode.setAttribute('scoped', 'scoped'); + } + else if (this._global && !this.owner._alreadyGloballyInjected) { + aureliaPal.DOM.injectStyles(this.css); + this.owner._alreadyGloballyInjected = true; + } + }; + return CSSViewEngineHooks; + }()); + function _createCSSResource(address) { + var ViewCSS = (function (_super) { + __extends(ViewCSS, _super); + function ViewCSS() { + return _super !== null && _super.apply(this, arguments) || this; + } + ViewCSS = __decorate([ + aureliaTemplating.resource(new CSSResource(address)) + ], ViewCSS); + return ViewCSS; + }(CSSViewEngineHooks)); + return ViewCSS; + } + + var AttrBindingBehavior = (function () { + function AttrBindingBehavior() { + } + AttrBindingBehavior.prototype.bind = function (binding, source) { + binding.targetObserver = new aureliaBinding.DataAttributeObserver(binding.target, binding.targetProperty); + }; + AttrBindingBehavior.prototype.unbind = function (binding, source) { + }; + AttrBindingBehavior = __decorate([ + aureliaBinding.bindingBehavior('attr') + ], AttrBindingBehavior); + return AttrBindingBehavior; + }()); + + var modeBindingBehavior = { + bind: function (binding, source, lookupFunctions) { + binding.originalMode = binding.mode; + binding.mode = this.mode; + }, + unbind: function (binding, source) { + binding.mode = binding.originalMode; + binding.originalMode = null; + } + }; + var OneTimeBindingBehavior = (function () { + function OneTimeBindingBehavior() { + this.mode = aureliaBinding.bindingMode.oneTime; + } + OneTimeBindingBehavior = __decorate([ + aureliaMetadata.mixin(modeBindingBehavior), + aureliaBinding.bindingBehavior('oneTime') + ], OneTimeBindingBehavior); + return OneTimeBindingBehavior; + }()); + var OneWayBindingBehavior = (function () { + function OneWayBindingBehavior() { + this.mode = aureliaBinding.bindingMode.toView; + } + OneWayBindingBehavior = __decorate([ + aureliaMetadata.mixin(modeBindingBehavior), + aureliaBinding.bindingBehavior('oneWay') + ], OneWayBindingBehavior); + return OneWayBindingBehavior; + }()); + var ToViewBindingBehavior = (function () { + function ToViewBindingBehavior() { + this.mode = aureliaBinding.bindingMode.toView; + } + ToViewBindingBehavior = __decorate([ + aureliaMetadata.mixin(modeBindingBehavior), + aureliaBinding.bindingBehavior('toView') + ], ToViewBindingBehavior); + return ToViewBindingBehavior; + }()); + var FromViewBindingBehavior = (function () { + function FromViewBindingBehavior() { + this.mode = aureliaBinding.bindingMode.fromView; + } + FromViewBindingBehavior = __decorate([ + aureliaMetadata.mixin(modeBindingBehavior), + aureliaBinding.bindingBehavior('fromView') + ], FromViewBindingBehavior); + return FromViewBindingBehavior; + }()); + var TwoWayBindingBehavior = (function () { + function TwoWayBindingBehavior() { + this.mode = aureliaBinding.bindingMode.twoWay; + } + TwoWayBindingBehavior = __decorate([ + aureliaMetadata.mixin(modeBindingBehavior), + aureliaBinding.bindingBehavior('twoWay') + ], TwoWayBindingBehavior); + return TwoWayBindingBehavior; + }()); + + function throttle(newValue) { + var _this = this; + var state = this.throttleState; + var elapsed = +new Date() - state.last; + if (elapsed >= state.delay) { + clearTimeout(state.timeoutId); + state.timeoutId = null; + state.last = +new Date(); + this.throttledMethod(newValue); + return; + } + state.newValue = newValue; + if (state.timeoutId === null) { + state.timeoutId = setTimeout(function () { + state.timeoutId = null; + state.last = +new Date(); + _this.throttledMethod(state.newValue); + }, state.delay - elapsed); + } + } + var ThrottleBindingBehavior = (function () { + function ThrottleBindingBehavior() { + } + ThrottleBindingBehavior.prototype.bind = function (binding, source, delay) { + if (delay === void 0) { delay = 200; } + var methodToThrottle = 'updateTarget'; + if (binding.callSource) { + methodToThrottle = 'callSource'; + } + else if (binding.updateSource && binding.mode === aureliaBinding.bindingMode.twoWay) { + methodToThrottle = 'updateSource'; + } + binding.throttledMethod = binding[methodToThrottle]; + binding.throttledMethod.originalName = methodToThrottle; + binding[methodToThrottle] = throttle; + binding.throttleState = { + delay: delay, + last: 0, + timeoutId: null + }; + }; + ThrottleBindingBehavior.prototype.unbind = function (binding, source) { + var methodToRestore = binding.throttledMethod.originalName; + binding[methodToRestore] = binding.throttledMethod; + binding.throttledMethod = null; + clearTimeout(binding.throttleState.timeoutId); + binding.throttleState = null; + }; + ThrottleBindingBehavior = __decorate([ + aureliaBinding.bindingBehavior('throttle') + ], ThrottleBindingBehavior); + return ThrottleBindingBehavior; + }()); + + var unset = {}; + function debounceCallSource(event) { + var _this = this; + var state = this.debounceState; + clearTimeout(state.timeoutId); + state.timeoutId = setTimeout(function () { return _this.debouncedMethod(event); }, state.delay); + } + function debounceCall(context, newValue, oldValue) { + var _this = this; + var state = this.debounceState; + clearTimeout(state.timeoutId); + if (context !== state.callContextToDebounce) { + state.oldValue = unset; + this.debouncedMethod(context, newValue, oldValue); + return; + } + if (state.oldValue === unset) { + state.oldValue = oldValue; + } + state.timeoutId = setTimeout(function () { + var _oldValue = state.oldValue; + state.oldValue = unset; + _this.debouncedMethod(context, newValue, _oldValue); + }, state.delay); + } + var DebounceBindingBehavior = (function () { + function DebounceBindingBehavior() { + } + DebounceBindingBehavior.prototype.bind = function (binding, source, delay) { + if (delay === void 0) { delay = 200; } + var isCallSource = binding.callSource !== undefined; + var methodToDebounce = isCallSource ? 'callSource' : 'call'; + var debouncer = isCallSource ? debounceCallSource : debounceCall; + var mode = binding.mode; + var callContextToDebounce = mode === aureliaBinding.bindingMode.twoWay || mode === aureliaBinding.bindingMode.fromView ? aureliaBinding.targetContext : aureliaBinding.sourceContext; + binding.debouncedMethod = binding[methodToDebounce]; + binding.debouncedMethod.originalName = methodToDebounce; + binding[methodToDebounce] = debouncer; + binding.debounceState = { + callContextToDebounce: callContextToDebounce, + delay: delay, + timeoutId: 0, + oldValue: unset + }; + }; + DebounceBindingBehavior.prototype.unbind = function (binding, source) { + var methodToRestore = binding.debouncedMethod.originalName; + binding[methodToRestore] = binding.debouncedMethod; + binding.debouncedMethod = null; + clearTimeout(binding.debounceState.timeoutId); + binding.debounceState = null; + }; + DebounceBindingBehavior = __decorate([ + aureliaBinding.bindingBehavior('debounce') + ], DebounceBindingBehavior); + return DebounceBindingBehavior; + }()); + + function findOriginalEventTarget(event) { + return (event.path && event.path[0]) || (event.deepPath && event.deepPath[0]) || event.target; + } + function handleSelfEvent(event) { + var target = findOriginalEventTarget(event); + if (this.target !== target) { + return; + } + this.selfEventCallSource(event); + } + var SelfBindingBehavior = (function () { + function SelfBindingBehavior() { + } + SelfBindingBehavior.prototype.bind = function (binding, source) { + if (!binding.callSource || !binding.targetEvent) { + throw new Error('Self binding behavior only supports event.'); + } + binding.selfEventCallSource = binding.callSource; + binding.callSource = handleSelfEvent; + }; + SelfBindingBehavior.prototype.unbind = function (binding, source) { + binding.callSource = binding.selfEventCallSource; + binding.selfEventCallSource = null; + }; + SelfBindingBehavior = __decorate([ + aureliaBinding.bindingBehavior('self') + ], SelfBindingBehavior); + return SelfBindingBehavior; + }()); + + var BindingSignaler = (function () { + function BindingSignaler() { + this.signals = {}; + } + BindingSignaler.prototype.signal = function (name) { + var bindings = this.signals[name]; + if (!bindings) { + return; + } + var i = bindings.length; + while (i--) { + bindings[i].call(aureliaBinding.sourceContext); + } + }; + return BindingSignaler; + }()); + + var SignalBindingBehavior = (function () { + function SignalBindingBehavior(bindingSignaler) { + this.signals = bindingSignaler.signals; + } + SignalBindingBehavior.inject = function () { return [BindingSignaler]; }; + SignalBindingBehavior.prototype.bind = function (binding, source) { + var names = []; + for (var _i = 2; _i < arguments.length; _i++) { + names[_i - 2] = arguments[_i]; + } + if (!binding.updateTarget) { + throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.'); + } + var signals = this.signals; + if (names.length === 1) { + var name_1 = names[0]; + var bindings = signals[name_1] || (signals[name_1] = []); + bindings.push(binding); + binding.signalName = name_1; + } + else if (names.length > 1) { + var i = names.length; + while (i--) { + var name_2 = names[i]; + var bindings = signals[name_2] || (signals[name_2] = []); + bindings.push(binding); + } + binding.signalName = names; + } + else { + throw new Error('Signal name is required.'); + } + }; + SignalBindingBehavior.prototype.unbind = function (binding, source) { + var signals = this.signals; + var name = binding.signalName; + binding.signalName = null; + if (Array.isArray(name)) { + var names = name; + var i = names.length; + while (i--) { + var n = names[i]; + var bindings = signals[n]; + bindings.splice(bindings.indexOf(binding), 1); + } + } + else { + var bindings = signals[name]; + bindings.splice(bindings.indexOf(binding), 1); + } + }; + SignalBindingBehavior = __decorate([ + aureliaBinding.bindingBehavior('signal') + ], SignalBindingBehavior); + return SignalBindingBehavior; + }()); + + var eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg '; + var notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.'; + var UpdateTriggerBindingBehavior = (function () { + function UpdateTriggerBindingBehavior() { + } + UpdateTriggerBindingBehavior.prototype.bind = function (binding, source) { + var events = []; + for (var _i = 2; _i < arguments.length; _i++) { + events[_i - 2] = arguments[_i]; + } + if (events.length === 0) { + throw new Error(eventNamesRequired); + } + if (binding.mode !== aureliaBinding.bindingMode.twoWay && binding.mode !== aureliaBinding.bindingMode.fromView) { + throw new Error(notApplicableMessage); + } + var targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty); + if (!targetObserver.handler) { + throw new Error(notApplicableMessage); + } + binding.targetObserver = targetObserver; + targetObserver.originalHandler = binding.targetObserver.handler; + var handler = new aureliaBinding.EventSubscriber(events); + targetObserver.handler = handler; + }; + UpdateTriggerBindingBehavior.prototype.unbind = function (binding, source) { + var targetObserver = binding.targetObserver; + targetObserver.handler.dispose(); + targetObserver.handler = targetObserver.originalHandler; + targetObserver.originalHandler = null; + }; + UpdateTriggerBindingBehavior = __decorate([ + aureliaBinding.bindingBehavior('updateTrigger') + ], UpdateTriggerBindingBehavior); + return UpdateTriggerBindingBehavior; + }()); + + function _createDynamicElement(_a) { + var name = _a.name, viewUrl = _a.viewUrl, bindableNames = _a.bindableNames, useShadowDOMmode = _a.useShadowDOMmode; + var DynamicElement = (function () { + function DynamicElement() { + } + DynamicElement.prototype.bind = function (bindingContext) { + this.$parent = bindingContext; + }; + DynamicElement = __decorate([ + aureliaTemplating.customElement(name), + aureliaTemplating.useView(viewUrl) + ], DynamicElement); + return DynamicElement; + }()); + for (var i = 0, ii = bindableNames.length; i < ii; ++i) { + aureliaTemplating.bindable(bindableNames[i])(DynamicElement); + } + switch (useShadowDOMmode) { + case 'open': + aureliaTemplating.useShadowDOM({ mode: 'open' })(DynamicElement); + break; + case 'closed': + aureliaTemplating.useShadowDOM({ mode: 'closed' })(DynamicElement); + break; + case '': + aureliaTemplating.useShadowDOM(DynamicElement); + break; + case null: + break; + default: + aureliaLogging.getLogger('aurelia-html-only-element') + .warn("Expected 'use-shadow-dom' value to be \"close\", \"open\" or \"\", received " + useShadowDOMmode); + break; + } + return DynamicElement; + } + + function getElementName(address) { + return /([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase(); + } + function configure(config) { + var viewEngine = config.container.get(aureliaTemplating.ViewEngine); + var loader = config.aurelia.loader; + viewEngine.addResourcePlugin('.html', { + 'fetch': function (viewUrl) { + return loader.loadTemplate(viewUrl).then(function (registryEntry) { + var _a; + var bindableNames = registryEntry.template.getAttribute('bindable'); + var useShadowDOMmode = registryEntry.template.getAttribute('use-shadow-dom'); + var name = getElementName(viewUrl); + if (bindableNames) { + bindableNames = bindableNames.split(',').map(function (x) { return x.trim(); }); + registryEntry.template.removeAttribute('bindable'); + } + else { + bindableNames = []; + } + return _a = {}, _a[name] = _createDynamicElement({ name: name, viewUrl: viewUrl, bindableNames: bindableNames, useShadowDOMmode: useShadowDOMmode }), _a; + }); + } + }); + } + + function configure$1(config) { + injectAureliaHideStyleAtHead(); + config.globalResources(Compose, If, Else, With, Repeat, Show, Hide, Replaceable, Focus, SanitizeHTMLValueConverter, OneTimeBindingBehavior, OneWayBindingBehavior, ToViewBindingBehavior, FromViewBindingBehavior, TwoWayBindingBehavior, ThrottleBindingBehavior, DebounceBindingBehavior, SelfBindingBehavior, SignalBindingBehavior, UpdateTriggerBindingBehavior, AttrBindingBehavior); + configure(config); + var viewEngine = config.container.get(aureliaTemplating.ViewEngine); + var styleResourcePlugin = { + fetch: function (address) { + var _a; + return _a = {}, _a[address] = _createCSSResource(address), _a; + } + }; + ['.css', '.less', '.sass', '.scss', '.styl'].forEach(function (ext) { return viewEngine.addResourcePlugin(ext, styleResourcePlugin); }); + } + + exports.AbstractRepeater = AbstractRepeater; + exports.ArrayRepeatStrategy = ArrayRepeatStrategy; + exports.AttrBindingBehavior = AttrBindingBehavior; + exports.BindingSignaler = BindingSignaler; + exports.Compose = Compose; + exports.DebounceBindingBehavior = DebounceBindingBehavior; + exports.Else = Else; + exports.Focus = Focus; + exports.FromViewBindingBehavior = FromViewBindingBehavior; + exports.HTMLSanitizer = HTMLSanitizer; + exports.Hide = Hide; + exports.If = If; + exports.MapRepeatStrategy = MapRepeatStrategy; + exports.NullRepeatStrategy = NullRepeatStrategy; + exports.NumberRepeatStrategy = NumberRepeatStrategy; + exports.OneTimeBindingBehavior = OneTimeBindingBehavior; + exports.OneWayBindingBehavior = OneWayBindingBehavior; + exports.Repeat = Repeat; + exports.RepeatStrategyLocator = RepeatStrategyLocator; + exports.Replaceable = Replaceable; + exports.SanitizeHTMLValueConverter = SanitizeHTMLValueConverter; + exports.SelfBindingBehavior = SelfBindingBehavior; + exports.SetRepeatStrategy = SetRepeatStrategy; + exports.Show = Show; + exports.SignalBindingBehavior = SignalBindingBehavior; + exports.ThrottleBindingBehavior = ThrottleBindingBehavior; + exports.ToViewBindingBehavior = ToViewBindingBehavior; + exports.TwoWayBindingBehavior = TwoWayBindingBehavior; + exports.UpdateTriggerBindingBehavior = UpdateTriggerBindingBehavior; + exports.With = With; + exports.configure = configure$1; + exports.createFullOverrideContext = createFullOverrideContext; + exports.getItemsSourceExpression = getItemsSourceExpression; + exports.isOneTime = isOneTime; + exports.unwrapExpression = unwrapExpression; + exports.updateOneTimeBinding = updateOneTimeBinding; + exports.updateOverrideContext = updateOverrideContext; + exports.viewsRequireLifecycle = viewsRequireLifecycle; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); +//# sourceMappingURL=aurelia-templating-resources.js.map diff --git a/dist/amd/aurelia-templating-resources.js.map b/dist/amd/aurelia-templating-resources.js.map new file mode 100644 index 0000000..03a31ab --- /dev/null +++ b/dist/amd/aurelia-templating-resources.js.map @@ -0,0 +1 @@ +{"version":3,"file":"aurelia-templating-resources.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/amd/binding-mode-behaviors.js b/dist/amd/binding-mode-behaviors.js deleted file mode 100644 index 851d655..0000000 --- a/dist/amd/binding-mode-behaviors.js +++ /dev/null @@ -1,49 +0,0 @@ -define(['exports', 'aurelia-binding', 'aurelia-metadata'], function (exports, _aureliaBinding, _aureliaMetadata) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.TwoWayBindingBehavior = exports.FromViewBindingBehavior = exports.ToViewBindingBehavior = exports.OneWayBindingBehavior = exports.OneTimeBindingBehavior = undefined; - - - - var _dec, _dec2, _class, _dec3, _dec4, _class2, _dec5, _dec6, _class3, _dec7, _dec8, _class4, _dec9, _dec10, _class5; - - var modeBindingBehavior = { - bind: function bind(binding, source, lookupFunctions) { - binding.originalMode = binding.mode; - binding.mode = this.mode; - }, - unbind: function unbind(binding, source) { - binding.mode = binding.originalMode; - binding.originalMode = null; - } - }; - - var OneTimeBindingBehavior = exports.OneTimeBindingBehavior = (_dec = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec2 = (0, _aureliaBinding.bindingBehavior)('oneTime'), _dec(_class = _dec2(_class = function OneTimeBindingBehavior() { - - - this.mode = _aureliaBinding.bindingMode.oneTime; - }) || _class) || _class); - var OneWayBindingBehavior = exports.OneWayBindingBehavior = (_dec3 = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec4 = (0, _aureliaBinding.bindingBehavior)('oneWay'), _dec3(_class2 = _dec4(_class2 = function OneWayBindingBehavior() { - - - this.mode = _aureliaBinding.bindingMode.toView; - }) || _class2) || _class2); - var ToViewBindingBehavior = exports.ToViewBindingBehavior = (_dec5 = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec6 = (0, _aureliaBinding.bindingBehavior)('toView'), _dec5(_class3 = _dec6(_class3 = function ToViewBindingBehavior() { - - - this.mode = _aureliaBinding.bindingMode.toView; - }) || _class3) || _class3); - var FromViewBindingBehavior = exports.FromViewBindingBehavior = (_dec7 = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec8 = (0, _aureliaBinding.bindingBehavior)('fromView'), _dec7(_class4 = _dec8(_class4 = function FromViewBindingBehavior() { - - - this.mode = _aureliaBinding.bindingMode.fromView; - }) || _class4) || _class4); - var TwoWayBindingBehavior = exports.TwoWayBindingBehavior = (_dec9 = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec10 = (0, _aureliaBinding.bindingBehavior)('twoWay'), _dec9(_class5 = _dec10(_class5 = function TwoWayBindingBehavior() { - - - this.mode = _aureliaBinding.bindingMode.twoWay; - }) || _class5) || _class5); -}); \ No newline at end of file diff --git a/dist/amd/binding-signaler.js b/dist/amd/binding-signaler.js deleted file mode 100644 index 81dd390..0000000 --- a/dist/amd/binding-signaler.js +++ /dev/null @@ -1,31 +0,0 @@ -define(['exports', 'aurelia-binding'], function (exports, _aureliaBinding) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.BindingSignaler = undefined; - - - - var BindingSignaler = exports.BindingSignaler = function () { - function BindingSignaler() { - - - this.signals = {}; - } - - BindingSignaler.prototype.signal = function signal(name) { - var bindings = this.signals[name]; - if (!bindings) { - return; - } - var i = bindings.length; - while (i--) { - bindings[i].call(_aureliaBinding.sourceContext); - } - }; - - return BindingSignaler; - }(); -}); \ No newline at end of file diff --git a/dist/amd/compose.js b/dist/amd/compose.js deleted file mode 100644 index eeea20b..0000000 --- a/dist/amd/compose.js +++ /dev/null @@ -1,215 +0,0 @@ -define(['exports', 'aurelia-dependency-injection', 'aurelia-task-queue', 'aurelia-templating', 'aurelia-pal'], function (exports, _aureliaDependencyInjection, _aureliaTaskQueue, _aureliaTemplating, _aureliaPal) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.Compose = undefined; - - function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); - } - - - - function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; - } - - function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); - } - - var _dec, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4; - - var Compose = exports.Compose = (_dec = (0, _aureliaTemplating.customElement)('compose'), _dec(_class = (0, _aureliaTemplating.noView)(_class = (_class2 = function () { - Compose.inject = function inject() { - return [_aureliaPal.DOM.Element, _aureliaDependencyInjection.Container, _aureliaTemplating.CompositionEngine, _aureliaTemplating.ViewSlot, _aureliaTemplating.ViewResources, _aureliaTaskQueue.TaskQueue]; - }; - - function Compose(element, container, compositionEngine, viewSlot, viewResources, taskQueue) { - - - _initDefineProp(this, 'model', _descriptor, this); - - _initDefineProp(this, 'view', _descriptor2, this); - - _initDefineProp(this, 'viewModel', _descriptor3, this); - - _initDefineProp(this, 'swapOrder', _descriptor4, this); - - this.element = element; - this.container = container; - this.compositionEngine = compositionEngine; - this.viewSlot = viewSlot; - this.viewResources = viewResources; - this.taskQueue = taskQueue; - this.currentController = null; - this.currentViewModel = null; - this.changes = Object.create(null); - } - - Compose.prototype.created = function created(owningView) { - this.owningView = owningView; - }; - - Compose.prototype.bind = function bind(bindingContext, overrideContext) { - this.bindingContext = bindingContext; - this.overrideContext = overrideContext; - this.changes.view = this.view; - this.changes.viewModel = this.viewModel; - this.changes.model = this.model; - if (!this.pendingTask) { - processChanges(this); - } - }; - - Compose.prototype.unbind = function unbind() { - this.changes = Object.create(null); - this.bindingContext = null; - this.overrideContext = null; - var returnToCache = true; - var skipAnimation = true; - this.viewSlot.removeAll(returnToCache, skipAnimation); - }; - - Compose.prototype.modelChanged = function modelChanged(newValue, oldValue) { - this.changes.model = newValue; - requestUpdate(this); - }; - - Compose.prototype.viewChanged = function viewChanged(newValue, oldValue) { - this.changes.view = newValue; - requestUpdate(this); - }; - - Compose.prototype.viewModelChanged = function viewModelChanged(newValue, oldValue) { - this.changes.viewModel = newValue; - requestUpdate(this); - }; - - return Compose; - }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'model', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null - }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'view', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null - }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'viewModel', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null - }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, 'swapOrder', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null - })), _class2)) || _class) || _class); - - - function isEmpty(obj) { - for (var key in obj) { - return false; - } - return true; - } - - function tryActivateViewModel(vm, model) { - if (vm && typeof vm.activate === 'function') { - return Promise.resolve(vm.activate(model)); - } - } - - function createInstruction(composer, instruction) { - return Object.assign(instruction, { - bindingContext: composer.bindingContext, - overrideContext: composer.overrideContext, - owningView: composer.owningView, - container: composer.container, - viewSlot: composer.viewSlot, - viewResources: composer.viewResources, - currentController: composer.currentController, - host: composer.element, - swapOrder: composer.swapOrder - }); - } - - function processChanges(composer) { - var changes = composer.changes; - composer.changes = Object.create(null); - - if (!('view' in changes) && !('viewModel' in changes) && 'model' in changes) { - composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model); - if (!composer.pendingTask) { - return; - } - } else { - var instruction = { - view: composer.view, - viewModel: composer.currentViewModel || composer.viewModel, - model: composer.model - }; - - instruction = Object.assign(instruction, changes); - - instruction = createInstruction(composer, instruction); - composer.pendingTask = composer.compositionEngine.compose(instruction).then(function (controller) { - composer.currentController = controller; - composer.currentViewModel = controller ? controller.viewModel : null; - }); - } - - composer.pendingTask = composer.pendingTask.then(function () { - completeCompositionTask(composer); - }, function (reason) { - completeCompositionTask(composer); - throw reason; - }); - } - - function completeCompositionTask(composer) { - composer.pendingTask = null; - if (!isEmpty(composer.changes)) { - processChanges(composer); - } - } - - function requestUpdate(composer) { - if (composer.pendingTask || composer.updateRequested) { - return; - } - composer.updateRequested = true; - composer.taskQueue.queueMicroTask(function () { - composer.updateRequested = false; - processChanges(composer); - }); - } -}); \ No newline at end of file diff --git a/dist/amd/css-resource.js b/dist/amd/css-resource.js deleted file mode 100644 index 357d13d..0000000 --- a/dist/amd/css-resource.js +++ /dev/null @@ -1,130 +0,0 @@ -define(['exports', 'aurelia-templating', 'aurelia-loader', 'aurelia-dependency-injection', 'aurelia-path', 'aurelia-pal'], function (exports, _aureliaTemplating, _aureliaLoader, _aureliaDependencyInjection, _aureliaPath, _aureliaPal) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports._createCSSResource = _createCSSResource; - - function _possibleConstructorReturn(self, call) { - if (!self) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return call && (typeof call === "object" || typeof call === "function") ? call : self; - } - - function _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - enumerable: false, - writable: true, - configurable: true - } - }); - if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; - } - - - - var cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi; - - function fixupCSSUrls(address, css) { - if (typeof css !== 'string') { - throw new Error('Failed loading required CSS file: ' + address); - } - return css.replace(cssUrlMatcher, function (match, p1) { - var quote = p1.charAt(0); - if (quote === '\'' || quote === '"') { - p1 = p1.substr(1, p1.length - 2); - } - return 'url(\'' + (0, _aureliaPath.relativeToFile)(p1, address) + '\')'; - }); - } - - var CSSResource = function () { - function CSSResource(address) { - - - this.address = address; - this._scoped = null; - this._global = false; - this._alreadyGloballyInjected = false; - } - - CSSResource.prototype.initialize = function initialize(container, target) { - this._scoped = new target(this); - }; - - CSSResource.prototype.register = function register(registry, name) { - if (name === 'scoped') { - registry.registerViewEngineHooks(this._scoped); - } else { - this._global = true; - } - }; - - CSSResource.prototype.load = function load(container) { - var _this = this; - - return container.get(_aureliaLoader.Loader).loadText(this.address).catch(function (err) { - return null; - }).then(function (text) { - text = fixupCSSUrls(_this.address, text); - _this._scoped.css = text; - if (_this._global) { - _this._alreadyGloballyInjected = true; - _aureliaPal.DOM.injectStyles(text); - } - }); - }; - - return CSSResource; - }(); - - var CSSViewEngineHooks = function () { - function CSSViewEngineHooks(owner) { - - - this.owner = owner; - this.css = null; - } - - CSSViewEngineHooks.prototype.beforeCompile = function beforeCompile(content, resources, instruction) { - if (instruction.targetShadowDOM) { - _aureliaPal.DOM.injectStyles(this.css, content, true); - } else if (_aureliaPal.FEATURE.scopedCSS) { - var styleNode = _aureliaPal.DOM.injectStyles(this.css, content, true); - styleNode.setAttribute('scoped', 'scoped'); - } else if (this._global && !this.owner._alreadyGloballyInjected) { - _aureliaPal.DOM.injectStyles(this.css); - this.owner._alreadyGloballyInjected = true; - } - }; - - return CSSViewEngineHooks; - }(); - - function _createCSSResource(address) { - var _dec, _class; - - var ViewCSS = (_dec = (0, _aureliaTemplating.resource)(new CSSResource(address)), _dec(_class = function (_CSSViewEngineHooks) { - _inherits(ViewCSS, _CSSViewEngineHooks); - - function ViewCSS() { - - - return _possibleConstructorReturn(this, _CSSViewEngineHooks.apply(this, arguments)); - } - - return ViewCSS; - }(CSSViewEngineHooks)) || _class); - - return ViewCSS; - } -}); \ No newline at end of file diff --git a/dist/amd/debounce-binding-behavior.js b/dist/amd/debounce-binding-behavior.js deleted file mode 100644 index 7c2f394..0000000 --- a/dist/amd/debounce-binding-behavior.js +++ /dev/null @@ -1,82 +0,0 @@ -define(['exports', 'aurelia-binding'], function (exports, _aureliaBinding) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.DebounceBindingBehavior = undefined; - - - - var _dec, _class; - - var unset = {}; - - function debounceCallSource(event) { - var _this = this; - - var state = this.debounceState; - clearTimeout(state.timeoutId); - state.timeoutId = setTimeout(function () { - return _this.debouncedMethod(event); - }, state.delay); - } - - function debounceCall(context, newValue, oldValue) { - var _this2 = this; - - var state = this.debounceState; - clearTimeout(state.timeoutId); - if (context !== state.callContextToDebounce) { - state.oldValue = unset; - this.debouncedMethod(context, newValue, oldValue); - return; - } - if (state.oldValue === unset) { - state.oldValue = oldValue; - } - state.timeoutId = setTimeout(function () { - var _oldValue = state.oldValue; - state.oldValue = unset; - _this2.debouncedMethod(context, newValue, _oldValue); - }, state.delay); - } - - var DebounceBindingBehavior = exports.DebounceBindingBehavior = (_dec = (0, _aureliaBinding.bindingBehavior)('debounce'), _dec(_class = function () { - function DebounceBindingBehavior() { - - } - - DebounceBindingBehavior.prototype.bind = function bind(binding, source) { - var delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200; - - var isCallSource = binding.callSource !== undefined; - var methodToDebounce = isCallSource ? 'callSource' : 'call'; - var debouncer = isCallSource ? debounceCallSource : debounceCall; - var mode = binding.mode; - var callContextToDebounce = mode === _aureliaBinding.bindingMode.twoWay || mode === _aureliaBinding.bindingMode.fromView ? _aureliaBinding.targetContext : _aureliaBinding.sourceContext; - - binding.debouncedMethod = binding[methodToDebounce]; - binding.debouncedMethod.originalName = methodToDebounce; - - binding[methodToDebounce] = debouncer; - - binding.debounceState = { - callContextToDebounce: callContextToDebounce, - delay: delay, - timeoutId: 0, - oldValue: unset - }; - }; - - DebounceBindingBehavior.prototype.unbind = function unbind(binding, source) { - var methodToRestore = binding.debouncedMethod.originalName; - binding[methodToRestore] = binding.debouncedMethod; - binding.debouncedMethod = null; - clearTimeout(binding.debounceState.timeoutId); - binding.debounceState = null; - }; - - return DebounceBindingBehavior; - }()) || _class); -}); \ No newline at end of file diff --git a/dist/amd/dynamic-element.js b/dist/amd/dynamic-element.js deleted file mode 100644 index f526ff7..0000000 --- a/dist/amd/dynamic-element.js +++ /dev/null @@ -1,58 +0,0 @@ -define(['exports', 'aurelia-templating', 'aurelia-logging'], function (exports, _aureliaTemplating, _aureliaLogging) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports._createDynamicElement = _createDynamicElement; - - - - function _createDynamicElement(_ref) { - var _dec, _dec2, _class; - - var name = _ref.name, - viewUrl = _ref.viewUrl, - bindableNames = _ref.bindableNames, - useShadowDOMmode = _ref.useShadowDOMmode; - var DynamicElement = (_dec = (0, _aureliaTemplating.customElement)(name), _dec2 = (0, _aureliaTemplating.useView)(viewUrl), _dec(_class = _dec2(_class = function () { - function DynamicElement() { - - } - - DynamicElement.prototype.bind = function bind(bindingContext) { - this.$parent = bindingContext; - }; - - return DynamicElement; - }()) || _class) || _class); - - - for (var i = 0, ii = bindableNames.length; i < ii; ++i) { - (0, _aureliaTemplating.bindable)(bindableNames[i])(DynamicElement); - } - - switch (useShadowDOMmode) { - case 'open': - (0, _aureliaTemplating.useShadowDOM)({ mode: 'open' })(DynamicElement); - break; - - case 'closed': - (0, _aureliaTemplating.useShadowDOM)({ mode: 'closed' })(DynamicElement); - break; - - case '': - (0, _aureliaTemplating.useShadowDOM)(DynamicElement); - break; - - case null: - break; - - default: - (0, _aureliaLogging.getLogger)('aurelia-html-only-element').warn('Expected \'use-shadow-dom\' value to be "close", "open" or "", received ' + useShadowDOMmode); - break; - } - - return DynamicElement; - } -}); \ No newline at end of file diff --git a/dist/amd/else.js b/dist/amd/else.js deleted file mode 100644 index d153ba6..0000000 --- a/dist/amd/else.js +++ /dev/null @@ -1,73 +0,0 @@ -define(['exports', 'aurelia-templating', 'aurelia-dependency-injection', './if-core'], function (exports, _aureliaTemplating, _aureliaDependencyInjection, _ifCore) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.Else = undefined; - - - - function _possibleConstructorReturn(self, call) { - if (!self) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return call && (typeof call === "object" || typeof call === "function") ? call : self; - } - - function _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - enumerable: false, - writable: true, - configurable: true - } - }); - if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; - } - - var _dec, _dec2, _class; - - var Else = exports.Else = (_dec = (0, _aureliaTemplating.customAttribute)('else'), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.ViewSlot), _dec(_class = (0, _aureliaTemplating.templateController)(_class = _dec2(_class = function (_IfCore) { - _inherits(Else, _IfCore); - - function Else(viewFactory, viewSlot) { - - - var _this = _possibleConstructorReturn(this, _IfCore.call(this, viewFactory, viewSlot)); - - _this._registerInIf(); - return _this; - } - - Else.prototype.bind = function bind(bindingContext, overrideContext) { - _IfCore.prototype.bind.call(this, bindingContext, overrideContext); - - if (this.ifVm.condition) { - this._hide(); - } else { - this._show(); - } - }; - - Else.prototype._registerInIf = function _registerInIf() { - var previous = this.viewSlot.anchor.previousSibling; - while (previous && !previous.au) { - previous = previous.previousSibling; - } - if (!previous || !previous.au.if) { - throw new Error("Can't find matching If for Else custom attribute."); - } - this.ifVm = previous.au.if.viewModel; - this.ifVm.elseVm = this; - }; - - return Else; - }(_ifCore.IfCore)) || _class) || _class) || _class); -}); \ No newline at end of file diff --git a/dist/amd/focus.js b/dist/amd/focus.js deleted file mode 100644 index 4033a30..0000000 --- a/dist/amd/focus.js +++ /dev/null @@ -1,75 +0,0 @@ -define(['exports', 'aurelia-templating', 'aurelia-binding', 'aurelia-task-queue', 'aurelia-pal'], function (exports, _aureliaTemplating, _aureliaBinding, _aureliaTaskQueue, _aureliaPal) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.Focus = undefined; - - - - var _dec, _class; - - var Focus = exports.Focus = (_dec = (0, _aureliaTemplating.customAttribute)('focus', _aureliaBinding.bindingMode.twoWay), _dec(_class = function () { - Focus.inject = function inject() { - return [_aureliaPal.DOM.Element, _aureliaTaskQueue.TaskQueue]; - }; - - function Focus(element, taskQueue) { - - - this.element = element; - this.taskQueue = taskQueue; - this.isAttached = false; - this.needsApply = false; - } - - Focus.prototype.valueChanged = function valueChanged(newValue) { - if (this.isAttached) { - this._apply(); - } else { - this.needsApply = true; - } - }; - - Focus.prototype._apply = function _apply() { - var _this = this; - - if (this.value) { - this.taskQueue.queueMicroTask(function () { - if (_this.value) { - _this.element.focus(); - } - }); - } else { - this.element.blur(); - } - }; - - Focus.prototype.attached = function attached() { - this.isAttached = true; - if (this.needsApply) { - this.needsApply = false; - this._apply(); - } - this.element.addEventListener('focus', this); - this.element.addEventListener('blur', this); - }; - - Focus.prototype.detached = function detached() { - this.isAttached = false; - this.element.removeEventListener('focus', this); - this.element.removeEventListener('blur', this); - }; - - Focus.prototype.handleEvent = function handleEvent(e) { - if (e.type === 'focus') { - this.value = true; - } else if (_aureliaPal.DOM.activeElement !== this.element) { - this.value = false; - } - }; - - return Focus; - }()) || _class); -}); \ No newline at end of file diff --git a/dist/amd/hide.js b/dist/amd/hide.js deleted file mode 100644 index d2cf19b..0000000 --- a/dist/amd/hide.js +++ /dev/null @@ -1,44 +0,0 @@ -define(['exports', 'aurelia-dependency-injection', 'aurelia-templating', 'aurelia-pal', './aurelia-hide-style'], function (exports, _aureliaDependencyInjection, _aureliaTemplating, _aureliaPal, _aureliaHideStyle) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.Hide = undefined; - - - - var _dec, _class; - - var Hide = exports.Hide = (_dec = (0, _aureliaTemplating.customAttribute)('hide'), _dec(_class = function () { - Hide.inject = function inject() { - return [_aureliaPal.DOM.Element, _aureliaTemplating.Animator, _aureliaDependencyInjection.Optional.of(_aureliaPal.DOM.boundary, true)]; - }; - - function Hide(element, animator, domBoundary) { - - - this.element = element; - this.animator = animator; - this.domBoundary = domBoundary; - } - - Hide.prototype.created = function created() { - (0, _aureliaHideStyle.injectAureliaHideStyleAtBoundary)(this.domBoundary); - }; - - Hide.prototype.valueChanged = function valueChanged(newValue) { - if (newValue) { - this.animator.addClass(this.element, _aureliaHideStyle.aureliaHideClassName); - } else { - this.animator.removeClass(this.element, _aureliaHideStyle.aureliaHideClassName); - } - }; - - Hide.prototype.bind = function bind(bindingContext) { - this.valueChanged(this.value); - }; - - return Hide; - }()) || _class); -}); \ No newline at end of file diff --git a/dist/amd/html-resource-plugin.js b/dist/amd/html-resource-plugin.js deleted file mode 100644 index c1e68fd..0000000 --- a/dist/amd/html-resource-plugin.js +++ /dev/null @@ -1,41 +0,0 @@ -define(['exports', 'aurelia-templating', './dynamic-element'], function (exports, _aureliaTemplating, _dynamicElement) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.getElementName = getElementName; - exports.configure = configure; - function getElementName(address) { - return (/([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase() - ); - } - - function configure(config) { - var viewEngine = config.container.get(_aureliaTemplating.ViewEngine); - var loader = config.aurelia.loader; - - viewEngine.addResourcePlugin('.html', { - 'fetch': function fetch(viewUrl) { - return loader.loadTemplate(viewUrl).then(function (registryEntry) { - var _ref; - - var bindableNames = registryEntry.template.getAttribute('bindable'); - var useShadowDOMmode = registryEntry.template.getAttribute('use-shadow-dom'); - var name = getElementName(viewUrl); - - if (bindableNames) { - bindableNames = bindableNames.split(',').map(function (x) { - return x.trim(); - }); - registryEntry.template.removeAttribute('bindable'); - } else { - bindableNames = []; - } - - return _ref = {}, _ref[name] = (0, _dynamicElement._createDynamicElement)({ name: name, viewUrl: viewUrl, bindableNames: bindableNames, useShadowDOMmode: useShadowDOMmode }), _ref; - }); - } - }); - } -}); \ No newline at end of file diff --git a/dist/amd/html-sanitizer.js b/dist/amd/html-sanitizer.js deleted file mode 100644 index 1584a6b..0000000 --- a/dist/amd/html-sanitizer.js +++ /dev/null @@ -1,31 +0,0 @@ -define(['exports', 'aurelia-logging'], function (exports, _aureliaLogging) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.HTMLSanitizer = undefined; - - - - var SCRIPT_REGEX = /)<[^<]*)*<\/script>/gi; - var needsToWarn = true; - - var HTMLSanitizer = exports.HTMLSanitizer = function () { - function HTMLSanitizer() { - - } - - HTMLSanitizer.prototype.sanitize = function sanitize(input) { - if (needsToWarn) { - needsToWarn = false; - - (0, _aureliaLogging.getLogger)('html-sanitizer').warn('CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks,\n and should not be relied on for sanitizing input from unknown sources.\n Please see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html.'); - } - - return input.replace(SCRIPT_REGEX, ''); - }; - - return HTMLSanitizer; - }(); -}); \ No newline at end of file diff --git a/dist/amd/if-core.js b/dist/amd/if-core.js deleted file mode 100644 index 7eaf344..0000000 --- a/dist/amd/if-core.js +++ /dev/null @@ -1,99 +0,0 @@ -define(['exports'], function (exports) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - - - - var IfCore = exports.IfCore = function () { - function IfCore(viewFactory, viewSlot) { - - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.view = null; - this.bindingContext = null; - this.overrideContext = null; - - this.showing = false; - this.cache = true; - } - - IfCore.prototype.bind = function bind(bindingContext, overrideContext) { - this.bindingContext = bindingContext; - this.overrideContext = overrideContext; - }; - - IfCore.prototype.unbind = function unbind() { - if (this.view === null) { - return; - } - - this.view.unbind(); - - if (!this.viewFactory.isCaching) { - return; - } - - if (this.showing) { - this.showing = false; - this.viewSlot.remove(this.view, true, true); - } else { - this.view.returnToCache(); - } - - this.view = null; - }; - - IfCore.prototype._show = function _show() { - if (this.showing) { - if (!this.view.isBound) { - this.view.bind(this.bindingContext, this.overrideContext); - } - return; - } - - if (this.view === null) { - this.view = this.viewFactory.create(); - } - - if (!this.view.isBound) { - this.view.bind(this.bindingContext, this.overrideContext); - } - - this.showing = true; - return this.viewSlot.add(this.view); - }; - - IfCore.prototype._hide = function _hide() { - var _this = this; - - if (!this.showing) { - return; - } - - this.showing = false; - var removed = this.viewSlot.remove(this.view); - - if (removed instanceof Promise) { - return removed.then(function () { - _this._unbindView(); - }); - } - - this._unbindView(); - }; - - IfCore.prototype._unbindView = function _unbindView() { - var cache = this.cache === 'false' ? false : !!this.cache; - this.view.unbind(); - if (!cache) { - this.view = null; - } - }; - - return IfCore; - }(); -}); \ No newline at end of file diff --git a/dist/amd/if.js b/dist/amd/if.js deleted file mode 100644 index 0af909d..0000000 --- a/dist/amd/if.js +++ /dev/null @@ -1,162 +0,0 @@ -define(['exports', 'aurelia-templating', 'aurelia-dependency-injection', './if-core'], function (exports, _aureliaTemplating, _aureliaDependencyInjection, _ifCore) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.If = undefined; - - function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); - } - - - - function _possibleConstructorReturn(self, call) { - if (!self) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return call && (typeof call === "object" || typeof call === "function") ? call : self; - } - - function _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - enumerable: false, - writable: true, - configurable: true - } - }); - if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; - } - - function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; - } - - function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); - } - - var _dec, _dec2, _dec3, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3; - - var If = exports.If = (_dec = (0, _aureliaTemplating.customAttribute)('if'), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.ViewSlot), _dec3 = (0, _aureliaTemplating.bindable)({ primaryProperty: true }), _dec(_class = (0, _aureliaTemplating.templateController)(_class = _dec2(_class = (_class2 = function (_IfCore) { - _inherits(If, _IfCore); - - function If() { - var _temp, _this, _ret; - - - - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - return _ret = (_temp = (_this = _possibleConstructorReturn(this, _IfCore.call.apply(_IfCore, [this].concat(args))), _this), _initDefineProp(_this, 'condition', _descriptor, _this), _initDefineProp(_this, 'swapOrder', _descriptor2, _this), _initDefineProp(_this, 'cache', _descriptor3, _this), _temp), _possibleConstructorReturn(_this, _ret); - } - - If.prototype.bind = function bind(bindingContext, overrideContext) { - _IfCore.prototype.bind.call(this, bindingContext, overrideContext); - if (this.condition) { - this._show(); - } else { - this._hide(); - } - }; - - If.prototype.conditionChanged = function conditionChanged(newValue) { - this._update(newValue); - }; - - If.prototype._update = function _update(show) { - var _this2 = this; - - if (this.animating) { - return; - } - - var promise = void 0; - if (this.elseVm) { - promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm); - } else { - promise = show ? this._show() : this._hide(); - } - - if (promise) { - this.animating = true; - promise.then(function () { - _this2.animating = false; - if (_this2.condition !== _this2.showing) { - _this2._update(_this2.condition); - } - }); - } - }; - - If.prototype._swap = function _swap(remove, add) { - switch (this.swapOrder) { - case 'before': - return Promise.resolve(add._show()).then(function () { - return remove._hide(); - }); - case 'with': - return Promise.all([remove._hide(), add._show()]); - default: - var promise = remove._hide(); - return promise ? promise.then(function () { - return add._show(); - }) : add._show(); - } - }; - - return If; - }(_ifCore.IfCore), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'condition', [_dec3], { - enumerable: true, - initializer: null - }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'swapOrder', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null - }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'cache', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: function initializer() { - return true; - } - })), _class2)) || _class) || _class) || _class); -}); \ No newline at end of file diff --git a/dist/amd/index.js b/dist/amd/index.js deleted file mode 100644 index 1beef4e..0000000 --- a/dist/amd/index.js +++ /dev/null @@ -1,16 +0,0 @@ -define(['exports', './aurelia-templating-resources'], function (exports, _aureliaTemplatingResources) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - Object.keys(_aureliaTemplatingResources).forEach(function (key) { - if (key === "default" || key === "__esModule") return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function () { - return _aureliaTemplatingResources[key]; - } - }); - }); -}); \ No newline at end of file diff --git a/dist/amd/map-repeat-strategy.js b/dist/amd/map-repeat-strategy.js deleted file mode 100644 index e5fdb00..0000000 --- a/dist/amd/map-repeat-strategy.js +++ /dev/null @@ -1,117 +0,0 @@ -define(['exports', './repeat-utilities'], function (exports, _repeatUtilities) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.MapRepeatStrategy = undefined; - - - - var MapRepeatStrategy = exports.MapRepeatStrategy = function () { - function MapRepeatStrategy() { - - } - - MapRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getMapObserver(items); - }; - - MapRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this._standardProcessItems(repeat, items); - }); - return; - } - this._standardProcessItems(repeat, items); - }; - - MapRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, items) { - var index = 0; - var overrideContext = void 0; - - items.forEach(function (value, key) { - overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, value, index, items.size, key); - repeat.addView(overrideContext.bindingContext, overrideContext); - ++index; - }); - }; - - MapRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, map, records) { - var key = void 0; - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var removeIndex = void 0; - var addIndex = void 0; - var record = void 0; - var rmPromises = []; - var viewOrPromise = void 0; - - for (i = 0, ii = records.length; i < ii; ++i) { - record = records[i]; - key = record.key; - switch (record.type) { - case 'update': - removeIndex = this._getViewIndexByKey(repeat, key); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, map.get(key), removeIndex, map.size, key); - repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext); - break; - case 'add': - addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1; - overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, map.get(key), addIndex, map.size, key); - repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext); - break; - case 'delete': - if (record.oldValue === undefined) { - return; - } - removeIndex = this._getViewIndexByKey(repeat, key); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - break; - case 'clear': - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - break; - default: - continue; - } - } - - if (rmPromises.length > 0) { - Promise.all(rmPromises).then(function () { - (0, _repeatUtilities.updateOverrideContexts)(repeat.views(), 0); - }); - } else { - (0, _repeatUtilities.updateOverrideContexts)(repeat.views(), 0); - } - }; - - MapRepeatStrategy.prototype._getViewIndexByKey = function _getViewIndexByKey(repeat, key) { - var i = void 0; - var ii = void 0; - var child = void 0; - - for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { - child = repeat.view(i); - if (child.bindingContext[repeat.key] === key) { - return i; - } - } - - return undefined; - }; - - return MapRepeatStrategy; - }(); -}); \ No newline at end of file diff --git a/dist/amd/null-repeat-strategy.js b/dist/amd/null-repeat-strategy.js deleted file mode 100644 index 8d186d4..0000000 --- a/dist/amd/null-repeat-strategy.js +++ /dev/null @@ -1,23 +0,0 @@ -define(["exports"], function (exports) { - "use strict"; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - - - - var NullRepeatStrategy = exports.NullRepeatStrategy = function () { - function NullRepeatStrategy() { - - } - - NullRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - repeat.removeAllViews(true); - }; - - NullRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) {}; - - return NullRepeatStrategy; - }(); -}); \ No newline at end of file diff --git a/dist/amd/number-repeat-strategy.js b/dist/amd/number-repeat-strategy.js deleted file mode 100644 index e8275cc..0000000 --- a/dist/amd/number-repeat-strategy.js +++ /dev/null @@ -1,65 +0,0 @@ -define(['exports', './repeat-utilities'], function (exports, _repeatUtilities) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.NumberRepeatStrategy = undefined; - - - - var NumberRepeatStrategy = exports.NumberRepeatStrategy = function () { - function NumberRepeatStrategy() { - - } - - NumberRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver() { - return null; - }; - - NumberRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, value) { - var _this = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this._standardProcessItems(repeat, value); - }); - return; - } - this._standardProcessItems(repeat, value); - }; - - NumberRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, value) { - var childrenLength = repeat.viewCount(); - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var viewsToRemove = void 0; - - value = Math.floor(value); - viewsToRemove = childrenLength - value; - - if (viewsToRemove > 0) { - if (viewsToRemove > childrenLength) { - viewsToRemove = childrenLength; - } - - for (i = 0, ii = viewsToRemove; i < ii; ++i) { - repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle); - } - - return; - } - - for (i = childrenLength, ii = value; i < ii; ++i) { - overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, i, i, ii); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - - (0, _repeatUtilities.updateOverrideContexts)(repeat.views(), 0); - }; - - return NumberRepeatStrategy; - }(); -}); \ No newline at end of file diff --git a/dist/amd/repeat-strategy-locator.js b/dist/amd/repeat-strategy-locator.js deleted file mode 100644 index 03f0cdf..0000000 --- a/dist/amd/repeat-strategy-locator.js +++ /dev/null @@ -1,54 +0,0 @@ -define(['exports', './null-repeat-strategy', './array-repeat-strategy', './map-repeat-strategy', './set-repeat-strategy', './number-repeat-strategy'], function (exports, _nullRepeatStrategy, _arrayRepeatStrategy, _mapRepeatStrategy, _setRepeatStrategy, _numberRepeatStrategy) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.RepeatStrategyLocator = undefined; - - - - var RepeatStrategyLocator = exports.RepeatStrategyLocator = function () { - function RepeatStrategyLocator() { - - - this.matchers = []; - this.strategies = []; - - this.addStrategy(function (items) { - return items === null || items === undefined; - }, new _nullRepeatStrategy.NullRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Array; - }, new _arrayRepeatStrategy.ArrayRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Map; - }, new _mapRepeatStrategy.MapRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Set; - }, new _setRepeatStrategy.SetRepeatStrategy()); - this.addStrategy(function (items) { - return typeof items === 'number'; - }, new _numberRepeatStrategy.NumberRepeatStrategy()); - } - - RepeatStrategyLocator.prototype.addStrategy = function addStrategy(matcher, strategy) { - this.matchers.push(matcher); - this.strategies.push(strategy); - }; - - RepeatStrategyLocator.prototype.getStrategy = function getStrategy(items) { - var matchers = this.matchers; - - for (var i = 0, ii = matchers.length; i < ii; ++i) { - if (matchers[i](items)) { - return this.strategies[i]; - } - } - - return null; - }; - - return RepeatStrategyLocator; - }(); -}); \ No newline at end of file diff --git a/dist/amd/repeat-utilities.js b/dist/amd/repeat-utilities.js deleted file mode 100644 index 606fec7..0000000 --- a/dist/amd/repeat-utilities.js +++ /dev/null @@ -1,106 +0,0 @@ -define(['exports', 'aurelia-binding'], function (exports, _aureliaBinding) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.updateOverrideContexts = updateOverrideContexts; - exports.createFullOverrideContext = createFullOverrideContext; - exports.updateOverrideContext = updateOverrideContext; - exports.getItemsSourceExpression = getItemsSourceExpression; - exports.unwrapExpression = unwrapExpression; - exports.isOneTime = isOneTime; - exports.updateOneTimeBinding = updateOneTimeBinding; - exports.indexOf = indexOf; - - - var oneTime = _aureliaBinding.bindingMode.oneTime; - - function updateOverrideContexts(views, startIndex) { - var length = views.length; - - if (startIndex > 0) { - startIndex = startIndex - 1; - } - - for (; startIndex < length; ++startIndex) { - updateOverrideContext(views[startIndex].overrideContext, startIndex, length); - } - } - - function createFullOverrideContext(repeat, data, index, length, key) { - var bindingContext = {}; - var overrideContext = (0, _aureliaBinding.createOverrideContext)(bindingContext, repeat.scope.overrideContext); - - if (typeof key !== 'undefined') { - bindingContext[repeat.key] = key; - bindingContext[repeat.value] = data; - } else { - bindingContext[repeat.local] = data; - } - updateOverrideContext(overrideContext, index, length); - return overrideContext; - } - - function updateOverrideContext(overrideContext, index, length) { - var first = index === 0; - var last = index === length - 1; - var even = index % 2 === 0; - - overrideContext.$index = index; - overrideContext.$first = first; - overrideContext.$last = last; - overrideContext.$middle = !(first || last); - overrideContext.$odd = !even; - overrideContext.$even = even; - } - - function getItemsSourceExpression(instruction, attrName) { - return instruction.behaviorInstructions.filter(function (bi) { - return bi.originalAttrName === attrName; - })[0].attributes.items.sourceExpression; - } - - function unwrapExpression(expression) { - var unwrapped = false; - while (expression instanceof _aureliaBinding.BindingBehavior) { - expression = expression.expression; - } - while (expression instanceof _aureliaBinding.ValueConverter) { - expression = expression.expression; - unwrapped = true; - } - return unwrapped ? expression : null; - } - - function isOneTime(expression) { - while (expression instanceof _aureliaBinding.BindingBehavior) { - if (expression.name === 'oneTime') { - return true; - } - expression = expression.expression; - } - return false; - } - - function updateOneTimeBinding(binding) { - if (binding.call && binding.mode === oneTime) { - binding.call(_aureliaBinding.sourceContext); - } else if (binding.updateOneTimeBindings) { - binding.updateOneTimeBindings(); - } - } - - function indexOf(array, item, matcher, startIndex) { - if (!matcher) { - return array.indexOf(item); - } - var length = array.length; - for (var index = startIndex || 0; index < length; index++) { - if (matcher(array[index], item)) { - return index; - } - } - return -1; - } -}); \ No newline at end of file diff --git a/dist/amd/repeat.js b/dist/amd/repeat.js deleted file mode 100644 index c6571aa..0000000 --- a/dist/amd/repeat.js +++ /dev/null @@ -1,324 +0,0 @@ -define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-templating', './repeat-strategy-locator', './repeat-utilities', './analyze-view-factory', './abstract-repeater'], function (exports, _aureliaDependencyInjection, _aureliaBinding, _aureliaTemplating, _repeatStrategyLocator, _repeatUtilities, _analyzeViewFactory, _abstractRepeater) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.Repeat = undefined; - - function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); - } - - - - function _possibleConstructorReturn(self, call) { - if (!self) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return call && (typeof call === "object" || typeof call === "function") ? call : self; - } - - function _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - enumerable: false, - writable: true, - configurable: true - } - }); - if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; - } - - function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; - } - - function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); - } - - var _dec, _dec2, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4; - - var Repeat = exports.Repeat = (_dec = (0, _aureliaTemplating.customAttribute)('repeat'), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.TargetInstruction, _aureliaTemplating.ViewSlot, _aureliaTemplating.ViewResources, _aureliaBinding.ObserverLocator, _repeatStrategyLocator.RepeatStrategyLocator), _dec(_class = (0, _aureliaTemplating.templateController)(_class = _dec2(_class = (_class2 = function (_AbstractRepeater) { - _inherits(Repeat, _AbstractRepeater); - - function Repeat(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) { - - - var _this = _possibleConstructorReturn(this, _AbstractRepeater.call(this, { - local: 'item', - viewsRequireLifecycle: (0, _analyzeViewFactory.viewsRequireLifecycle)(viewFactory) - })); - - _initDefineProp(_this, 'items', _descriptor, _this); - - _initDefineProp(_this, 'local', _descriptor2, _this); - - _initDefineProp(_this, 'key', _descriptor3, _this); - - _initDefineProp(_this, 'value', _descriptor4, _this); - - _this.viewFactory = viewFactory; - _this.instruction = instruction; - _this.viewSlot = viewSlot; - _this.lookupFunctions = viewResources.lookupFunctions; - _this.observerLocator = observerLocator; - _this.key = 'key'; - _this.value = 'value'; - _this.strategyLocator = strategyLocator; - _this.ignoreMutation = false; - _this.sourceExpression = (0, _repeatUtilities.getItemsSourceExpression)(_this.instruction, 'repeat.for'); - _this.isOneTime = (0, _repeatUtilities.isOneTime)(_this.sourceExpression); - _this.viewsRequireLifecycle = (0, _analyzeViewFactory.viewsRequireLifecycle)(viewFactory); - return _this; - } - - Repeat.prototype.call = function call(context, changes) { - this[context](this.items, changes); - }; - - Repeat.prototype.bind = function bind(bindingContext, overrideContext) { - this.scope = { bindingContext: bindingContext, overrideContext: overrideContext }; - this.matcherBinding = this._captureAndRemoveMatcherBinding(); - this.itemsChanged(); - }; - - Repeat.prototype.unbind = function unbind() { - this.scope = null; - this.items = null; - this.matcherBinding = null; - this.viewSlot.removeAll(true, true); - this._unsubscribeCollection(); - }; - - Repeat.prototype._unsubscribeCollection = function _unsubscribeCollection() { - if (this.collectionObserver) { - this.collectionObserver.unsubscribe(this.callContext, this); - this.collectionObserver = null; - this.callContext = null; - } - }; - - Repeat.prototype.itemsChanged = function itemsChanged() { - var _this2 = this; - - this._unsubscribeCollection(); - - if (!this.scope) { - return; - } - - var items = this.items; - this.strategy = this.strategyLocator.getStrategy(items); - if (!this.strategy) { - throw new Error('Value for \'' + this.sourceExpression + '\' is non-repeatable'); - } - - if (!this.isOneTime && !this._observeInnerCollection()) { - this._observeCollection(); - } - this.ignoreMutation = true; - this.strategy.instanceChanged(this, items); - this.observerLocator.taskQueue.queueMicroTask(function () { - _this2.ignoreMutation = false; - }); - }; - - Repeat.prototype._getInnerCollection = function _getInnerCollection() { - var expression = (0, _repeatUtilities.unwrapExpression)(this.sourceExpression); - if (!expression) { - return null; - } - return expression.evaluate(this.scope, null); - }; - - Repeat.prototype.handleCollectionMutated = function handleCollectionMutated(collection, changes) { - if (!this.collectionObserver) { - return; - } - if (this.ignoreMutation) { - return; - } - this.strategy.instanceMutated(this, collection, changes); - }; - - Repeat.prototype.handleInnerCollectionMutated = function handleInnerCollectionMutated(collection, changes) { - var _this3 = this; - - if (!this.collectionObserver) { - return; - } - - if (this.ignoreMutation) { - return; - } - this.ignoreMutation = true; - var newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions); - this.observerLocator.taskQueue.queueMicroTask(function () { - return _this3.ignoreMutation = false; - }); - - if (newItems === this.items) { - this.itemsChanged(); - } else { - this.items = newItems; - } - }; - - Repeat.prototype._observeInnerCollection = function _observeInnerCollection() { - var items = this._getInnerCollection(); - var strategy = this.strategyLocator.getStrategy(items); - if (!strategy) { - return false; - } - this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items); - if (!this.collectionObserver) { - return false; - } - this.callContext = 'handleInnerCollectionMutated'; - this.collectionObserver.subscribe(this.callContext, this); - return true; - }; - - Repeat.prototype._observeCollection = function _observeCollection() { - var items = this.items; - this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items); - if (this.collectionObserver) { - this.callContext = 'handleCollectionMutated'; - this.collectionObserver.subscribe(this.callContext, this); - } - }; - - Repeat.prototype._captureAndRemoveMatcherBinding = function _captureAndRemoveMatcherBinding() { - if (this.viewFactory.viewFactory) { - var instructions = this.viewFactory.viewFactory.instructions; - var instructionIds = Object.keys(instructions); - for (var i = 0; i < instructionIds.length; i++) { - var expressions = instructions[instructionIds[i]].expressions; - if (expressions) { - for (var ii = 0; i < expressions.length; i++) { - if (expressions[ii].targetProperty === 'matcher') { - var matcherBinding = expressions[ii]; - expressions.splice(ii, 1); - return matcherBinding; - } - } - } - } - } - - return undefined; - }; - - Repeat.prototype.viewCount = function viewCount() { - return this.viewSlot.children.length; - }; - - Repeat.prototype.views = function views() { - return this.viewSlot.children; - }; - - Repeat.prototype.view = function view(index) { - return this.viewSlot.children[index]; - }; - - Repeat.prototype.matcher = function matcher() { - return this.matcherBinding ? this.matcherBinding.sourceExpression.evaluate(this.scope, this.matcherBinding.lookupFunctions) : null; - }; - - Repeat.prototype.addView = function addView(bindingContext, overrideContext) { - var view = this.viewFactory.create(); - view.bind(bindingContext, overrideContext); - this.viewSlot.add(view); - }; - - Repeat.prototype.insertView = function insertView(index, bindingContext, overrideContext) { - var view = this.viewFactory.create(); - view.bind(bindingContext, overrideContext); - this.viewSlot.insert(index, view); - }; - - Repeat.prototype.moveView = function moveView(sourceIndex, targetIndex) { - this.viewSlot.move(sourceIndex, targetIndex); - }; - - Repeat.prototype.removeAllViews = function removeAllViews(returnToCache, skipAnimation) { - return this.viewSlot.removeAll(returnToCache, skipAnimation); - }; - - Repeat.prototype.removeViews = function removeViews(viewsToRemove, returnToCache, skipAnimation) { - return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation); - }; - - Repeat.prototype.removeView = function removeView(index, returnToCache, skipAnimation) { - return this.viewSlot.removeAt(index, returnToCache, skipAnimation); - }; - - Repeat.prototype.updateBindings = function updateBindings(view) { - var j = view.bindings.length; - while (j--) { - (0, _repeatUtilities.updateOneTimeBinding)(view.bindings[j]); - } - j = view.controllers.length; - while (j--) { - var k = view.controllers[j].boundProperties.length; - while (k--) { - var binding = view.controllers[j].boundProperties[k].binding; - (0, _repeatUtilities.updateOneTimeBinding)(binding); - } - } - }; - - return Repeat; - }(_abstractRepeater.AbstractRepeater), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'items', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null - }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'local', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null - }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'key', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null - }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, 'value', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null - })), _class2)) || _class) || _class) || _class); -}); \ No newline at end of file diff --git a/dist/amd/replaceable.js b/dist/amd/replaceable.js deleted file mode 100644 index 84a08f5..0000000 --- a/dist/amd/replaceable.js +++ /dev/null @@ -1,37 +0,0 @@ -define(['exports', 'aurelia-dependency-injection', 'aurelia-templating'], function (exports, _aureliaDependencyInjection, _aureliaTemplating) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.Replaceable = undefined; - - - - var _dec, _dec2, _class; - - var Replaceable = exports.Replaceable = (_dec = (0, _aureliaTemplating.customAttribute)('replaceable'), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.ViewSlot), _dec(_class = (0, _aureliaTemplating.templateController)(_class = _dec2(_class = function () { - function Replaceable(viewFactory, viewSlot) { - - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.view = null; - } - - Replaceable.prototype.bind = function bind(bindingContext, overrideContext) { - if (this.view === null) { - this.view = this.viewFactory.create(); - this.viewSlot.add(this.view); - } - - this.view.bind(bindingContext, overrideContext); - }; - - Replaceable.prototype.unbind = function unbind() { - this.view.unbind(); - }; - - return Replaceable; - }()) || _class) || _class) || _class); -}); \ No newline at end of file diff --git a/dist/amd/sanitize-html.js b/dist/amd/sanitize-html.js deleted file mode 100644 index 5ca7e3a..0000000 --- a/dist/amd/sanitize-html.js +++ /dev/null @@ -1,30 +0,0 @@ -define(['exports', 'aurelia-binding', 'aurelia-dependency-injection', './html-sanitizer'], function (exports, _aureliaBinding, _aureliaDependencyInjection, _htmlSanitizer) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.SanitizeHTMLValueConverter = undefined; - - - - var _dec, _dec2, _class; - - var SanitizeHTMLValueConverter = exports.SanitizeHTMLValueConverter = (_dec = (0, _aureliaBinding.valueConverter)('sanitizeHTML'), _dec2 = (0, _aureliaDependencyInjection.inject)(_htmlSanitizer.HTMLSanitizer), _dec(_class = _dec2(_class = function () { - function SanitizeHTMLValueConverter(sanitizer) { - - - this.sanitizer = sanitizer; - } - - SanitizeHTMLValueConverter.prototype.toView = function toView(untrustedMarkup) { - if (untrustedMarkup === null || untrustedMarkup === undefined) { - return null; - } - - return this.sanitizer.sanitize(untrustedMarkup); - }; - - return SanitizeHTMLValueConverter; - }()) || _class) || _class); -}); \ No newline at end of file diff --git a/dist/amd/self-binding-behavior.js b/dist/amd/self-binding-behavior.js deleted file mode 100644 index 5e8648a..0000000 --- a/dist/amd/self-binding-behavior.js +++ /dev/null @@ -1,41 +0,0 @@ -define(['exports', 'aurelia-binding'], function (exports, _aureliaBinding) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.SelfBindingBehavior = undefined; - - - - var _dec, _class; - - function findOriginalEventTarget(event) { - return event.path && event.path[0] || event.deepPath && event.deepPath[0] || event.target; - } - - function handleSelfEvent(event) { - var target = findOriginalEventTarget(event); - if (this.target !== target) return; - this.selfEventCallSource(event); - } - - var SelfBindingBehavior = exports.SelfBindingBehavior = (_dec = (0, _aureliaBinding.bindingBehavior)('self'), _dec(_class = function () { - function SelfBindingBehavior() { - - } - - SelfBindingBehavior.prototype.bind = function bind(binding, source) { - if (!binding.callSource || !binding.targetEvent) throw new Error('Self binding behavior only supports event.'); - binding.selfEventCallSource = binding.callSource; - binding.callSource = handleSelfEvent; - }; - - SelfBindingBehavior.prototype.unbind = function unbind(binding, source) { - binding.callSource = binding.selfEventCallSource; - binding.selfEventCallSource = null; - }; - - return SelfBindingBehavior; - }()) || _class); -}); \ No newline at end of file diff --git a/dist/amd/set-repeat-strategy.js b/dist/amd/set-repeat-strategy.js deleted file mode 100644 index cf72d50..0000000 --- a/dist/amd/set-repeat-strategy.js +++ /dev/null @@ -1,104 +0,0 @@ -define(['exports', './repeat-utilities'], function (exports, _repeatUtilities) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.SetRepeatStrategy = undefined; - - - - var SetRepeatStrategy = exports.SetRepeatStrategy = function () { - function SetRepeatStrategy() { - - } - - SetRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getSetObserver(items); - }; - - SetRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this._standardProcessItems(repeat, items); - }); - return; - } - this._standardProcessItems(repeat, items); - }; - - SetRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, items) { - var index = 0; - var overrideContext = void 0; - - items.forEach(function (value) { - overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, value, index, items.size); - repeat.addView(overrideContext.bindingContext, overrideContext); - ++index; - }); - }; - - SetRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, set, records) { - var value = void 0; - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var removeIndex = void 0; - var record = void 0; - var rmPromises = []; - var viewOrPromise = void 0; - - for (i = 0, ii = records.length; i < ii; ++i) { - record = records[i]; - value = record.value; - switch (record.type) { - case 'add': - var size = Math.max(set.size - 1, 0); - overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, value, size, set.size); - repeat.insertView(size, overrideContext.bindingContext, overrideContext); - break; - case 'delete': - removeIndex = this._getViewIndexByValue(repeat, value); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - break; - case 'clear': - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - break; - default: - continue; - } - } - - if (rmPromises.length > 0) { - Promise.all(rmPromises).then(function () { - (0, _repeatUtilities.updateOverrideContexts)(repeat.views(), 0); - }); - } else { - (0, _repeatUtilities.updateOverrideContexts)(repeat.views(), 0); - } - }; - - SetRepeatStrategy.prototype._getViewIndexByValue = function _getViewIndexByValue(repeat, value) { - var i = void 0; - var ii = void 0; - var child = void 0; - - for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { - child = repeat.view(i); - if (child.bindingContext[repeat.local] === value) { - return i; - } - } - - return undefined; - }; - - return SetRepeatStrategy; - }(); -}); \ No newline at end of file diff --git a/dist/amd/show.js b/dist/amd/show.js deleted file mode 100644 index f639024..0000000 --- a/dist/amd/show.js +++ /dev/null @@ -1,44 +0,0 @@ -define(['exports', 'aurelia-dependency-injection', 'aurelia-templating', 'aurelia-pal', './aurelia-hide-style'], function (exports, _aureliaDependencyInjection, _aureliaTemplating, _aureliaPal, _aureliaHideStyle) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.Show = undefined; - - - - var _dec, _class; - - var Show = exports.Show = (_dec = (0, _aureliaTemplating.customAttribute)('show'), _dec(_class = function () { - Show.inject = function inject() { - return [_aureliaPal.DOM.Element, _aureliaTemplating.Animator, _aureliaDependencyInjection.Optional.of(_aureliaPal.DOM.boundary, true)]; - }; - - function Show(element, animator, domBoundary) { - - - this.element = element; - this.animator = animator; - this.domBoundary = domBoundary; - } - - Show.prototype.created = function created() { - (0, _aureliaHideStyle.injectAureliaHideStyleAtBoundary)(this.domBoundary); - }; - - Show.prototype.valueChanged = function valueChanged(newValue) { - if (newValue) { - this.animator.removeClass(this.element, _aureliaHideStyle.aureliaHideClassName); - } else { - this.animator.addClass(this.element, _aureliaHideStyle.aureliaHideClassName); - } - }; - - Show.prototype.bind = function bind(bindingContext) { - this.valueChanged(this.value); - }; - - return Show; - }()) || _class); -}); \ No newline at end of file diff --git a/dist/amd/signal-binding-behavior.js b/dist/amd/signal-binding-behavior.js deleted file mode 100644 index 79268df..0000000 --- a/dist/amd/signal-binding-behavior.js +++ /dev/null @@ -1,70 +0,0 @@ -define(['exports', 'aurelia-binding', './binding-signaler'], function (exports, _aureliaBinding, _bindingSignaler) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.SignalBindingBehavior = undefined; - - - - var _dec, _class; - - var SignalBindingBehavior = exports.SignalBindingBehavior = (_dec = (0, _aureliaBinding.bindingBehavior)('signal'), _dec(_class = function () { - SignalBindingBehavior.inject = function inject() { - return [_bindingSignaler.BindingSignaler]; - }; - - function SignalBindingBehavior(bindingSignaler) { - - - this.signals = bindingSignaler.signals; - } - - SignalBindingBehavior.prototype.bind = function bind(binding, source) { - if (!binding.updateTarget) { - throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.'); - } - - for (var _len = arguments.length, names = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { - names[_key - 2] = arguments[_key]; - } - - if (names.length === 1) { - var name = names[0]; - var bindings = this.signals[name] || (this.signals[name] = []); - bindings.push(binding); - binding.signalName = name; - } else if (names.length > 1) { - var i = names.length; - while (i--) { - var _name = names[i]; - var _bindings = this.signals[_name] || (this.signals[_name] = []); - _bindings.push(binding); - } - binding.signalName = names; - } else { - throw new Error('Signal name is required.'); - } - }; - - SignalBindingBehavior.prototype.unbind = function unbind(binding, source) { - var name = binding.signalName; - binding.signalName = null; - if (Array.isArray(name)) { - var _names = name; - var i = _names.length; - while (i--) { - var n = _names[i]; - var bindings = this.signals[n]; - bindings.splice(bindings.indexOf(binding), 1); - } - } else { - var _bindings2 = this.signals[name]; - _bindings2.splice(_bindings2.indexOf(binding), 1); - } - }; - - return SignalBindingBehavior; - }()) || _class); -}); \ No newline at end of file diff --git a/dist/amd/throttle-binding-behavior.js b/dist/amd/throttle-binding-behavior.js deleted file mode 100644 index 77bb51e..0000000 --- a/dist/amd/throttle-binding-behavior.js +++ /dev/null @@ -1,72 +0,0 @@ -define(['exports', 'aurelia-binding'], function (exports, _aureliaBinding) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.ThrottleBindingBehavior = undefined; - - - - var _dec, _class; - - function throttle(newValue) { - var _this = this; - - var state = this.throttleState; - var elapsed = +new Date() - state.last; - if (elapsed >= state.delay) { - clearTimeout(state.timeoutId); - state.timeoutId = null; - state.last = +new Date(); - this.throttledMethod(newValue); - return; - } - state.newValue = newValue; - if (state.timeoutId === null) { - state.timeoutId = setTimeout(function () { - state.timeoutId = null; - state.last = +new Date(); - _this.throttledMethod(state.newValue); - }, state.delay - elapsed); - } - } - - var ThrottleBindingBehavior = exports.ThrottleBindingBehavior = (_dec = (0, _aureliaBinding.bindingBehavior)('throttle'), _dec(_class = function () { - function ThrottleBindingBehavior() { - - } - - ThrottleBindingBehavior.prototype.bind = function bind(binding, source) { - var delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200; - - var methodToThrottle = 'updateTarget'; - if (binding.callSource) { - methodToThrottle = 'callSource'; - } else if (binding.updateSource && binding.mode === _aureliaBinding.bindingMode.twoWay) { - methodToThrottle = 'updateSource'; - } - - binding.throttledMethod = binding[methodToThrottle]; - binding.throttledMethod.originalName = methodToThrottle; - - binding[methodToThrottle] = throttle; - - binding.throttleState = { - delay: delay, - last: 0, - timeoutId: null - }; - }; - - ThrottleBindingBehavior.prototype.unbind = function unbind(binding, source) { - var methodToRestore = binding.throttledMethod.originalName; - binding[methodToRestore] = binding.throttledMethod; - binding.throttledMethod = null; - clearTimeout(binding.throttleState.timeoutId); - binding.throttleState = null; - }; - - return ThrottleBindingBehavior; - }()) || _class); -}); \ No newline at end of file diff --git a/dist/amd/update-trigger-binding-behavior.js b/dist/amd/update-trigger-binding-behavior.js deleted file mode 100644 index 03e6129..0000000 --- a/dist/amd/update-trigger-binding-behavior.js +++ /dev/null @@ -1,53 +0,0 @@ -define(['exports', 'aurelia-binding'], function (exports, _aureliaBinding) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.UpdateTriggerBindingBehavior = undefined; - - - - var _dec, _class; - - var eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg '; - var notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.'; - - var UpdateTriggerBindingBehavior = exports.UpdateTriggerBindingBehavior = (_dec = (0, _aureliaBinding.bindingBehavior)('updateTrigger'), _dec(_class = function () { - function UpdateTriggerBindingBehavior() { - - } - - UpdateTriggerBindingBehavior.prototype.bind = function bind(binding, source) { - for (var _len = arguments.length, events = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { - events[_key - 2] = arguments[_key]; - } - - if (events.length === 0) { - throw new Error(eventNamesRequired); - } - if (binding.mode !== _aureliaBinding.bindingMode.twoWay && binding.mode !== _aureliaBinding.bindingMode.fromView) { - throw new Error(notApplicableMessage); - } - - var targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty); - if (!targetObserver.handler) { - throw new Error(notApplicableMessage); - } - binding.targetObserver = targetObserver; - - targetObserver.originalHandler = binding.targetObserver.handler; - - var handler = new _aureliaBinding.EventSubscriber(events); - targetObserver.handler = handler; - }; - - UpdateTriggerBindingBehavior.prototype.unbind = function unbind(binding, source) { - binding.targetObserver.handler.dispose(); - binding.targetObserver.handler = binding.targetObserver.originalHandler; - binding.targetObserver.originalHandler = null; - }; - - return UpdateTriggerBindingBehavior; - }()) || _class); -}); \ No newline at end of file diff --git a/dist/amd/with.js b/dist/amd/with.js deleted file mode 100644 index f921328..0000000 --- a/dist/amd/with.js +++ /dev/null @@ -1,49 +0,0 @@ -define(['exports', 'aurelia-dependency-injection', 'aurelia-templating', 'aurelia-binding'], function (exports, _aureliaDependencyInjection, _aureliaTemplating, _aureliaBinding) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.With = undefined; - - - - var _dec, _dec2, _class; - - var With = exports.With = (_dec = (0, _aureliaTemplating.customAttribute)('with'), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.ViewSlot), _dec(_class = (0, _aureliaTemplating.templateController)(_class = _dec2(_class = function () { - function With(viewFactory, viewSlot) { - - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.parentOverrideContext = null; - this.view = null; - } - - With.prototype.bind = function bind(bindingContext, overrideContext) { - this.parentOverrideContext = overrideContext; - this.valueChanged(this.value); - }; - - With.prototype.valueChanged = function valueChanged(newValue) { - var overrideContext = (0, _aureliaBinding.createOverrideContext)(newValue, this.parentOverrideContext); - if (!this.view) { - this.view = this.viewFactory.create(); - this.view.bind(newValue, overrideContext); - this.viewSlot.add(this.view); - } else { - this.view.bind(newValue, overrideContext); - } - }; - - With.prototype.unbind = function unbind() { - this.parentOverrideContext = null; - - if (this.view) { - this.view.unbind(); - } - }; - - return With; - }()) || _class) || _class) || _class); -}); \ No newline at end of file diff --git a/dist/aurelia-templating-resources.d.ts b/dist/aurelia-templating-resources.d.ts index 135fd44..2830490 100644 --- a/dist/aurelia-templating-resources.d.ts +++ b/dist/aurelia-templating-resources.d.ts @@ -1,746 +1,620 @@ -import { - inject, - Container, - Optional -} from 'aurelia-dependency-injection'; -import { - BoundViewFactory, - ViewSlot, - customAttribute, - templateController, - useView, - customElement, - bindable, - useShadowDOM, - ViewResources, - resource, - ViewCompileInstruction, - CompositionEngine, - CompositionContext, - noView, - View, - ViewEngine, - Animator, - TargetInstruction -} from 'aurelia-templating'; -import { - createOverrideContext, - bindingMode, - EventSubscriber, - bindingBehavior, - BindingBehavior, - ValueConverter, - sourceContext, - targetContext, - DataAttributeObserver, - mergeSplice, - valueConverter, - ObserverLocator -} from 'aurelia-binding'; -import { - getLogger -} from 'aurelia-logging'; -import { - TaskQueue -} from 'aurelia-task-queue'; -import { - DOM, - FEATURE -} from 'aurelia-pal'; -import { - Loader -} from 'aurelia-loader'; -import { - relativeToFile -} from 'aurelia-path'; -import { - mixin -} from 'aurelia-metadata'; +import { OverrideContext, bindingMode } from 'aurelia-binding'; +import { View, ViewFactory, ViewSlot } from 'aurelia-templating'; /** -* A strategy is for repeating a template over an iterable or iterable-like object. -*/ -export declare interface RepeatStrategy { - instanceChanged(repeat: Repeat, items: any): void; - instanceMutated(repeat: Repeat, items: any, changes: any): void; - getCollectionObserver(observerLocator: any, items: any): any; -} - -/** -* Creates a binding context for decandant elements to bind to. -*/ -export declare class With { - - /** - * Creates an instance of With. - * @param viewFactory The factory generating the view. - * @param viewSlot The slot the view is injected in to. - */ - constructor(viewFactory?: any, viewSlot?: any); - - /** - * Binds the With with provided binding context and override context. - * @param bindingContext The binding context. - * @param overrideContext An override context for binding. - */ - bind(bindingContext?: any, overrideContext?: any): any; - - /** - * Invoked everytime the bound value changes. - * @param newValue The new value. - */ - valueChanged(newValue?: any): any; - - /** - * Unbinds With - */ - unbind(): any; + * Used to compose a new view / view-model template or bind to an existing instance. + */ +export declare class Compose { + /** + * Model to bind the custom element to. + * + * @property model + * @type {CustomElement} + */ + model: any; + /** + * View to bind the custom element to. + * + * @property view + * @type {HtmlElement} + */ + view: any; + /** + * View-model to bind the custom element's template to. + * + * @property viewModel + * @type {Class} + */ + viewModel: any; + /** + * SwapOrder to control the swapping order of the custom element's view. + * + * @property view + * @type {String} + */ + swapOrder: any; + /** + * Creates an instance of Compose. + * @param element The Compose element. + * @param container The dependency injection container instance. + * @param compositionEngine CompositionEngine instance to compose the element. + * @param viewSlot The slot the view is injected in to. + * @param viewResources Collection of resources used to compile the the view. + * @param taskQueue The TaskQueue instance. + */ + constructor(element: any, container: any, compositionEngine: any, viewSlot: any, viewResources: any, taskQueue: any); + /** + * Invoked when the component has been created. + * + * @param owningView The view that this component was created inside of. + */ + created(owningView: View): void; + /** + * Used to set the bindingContext. + * + * @param bindingContext The context in which the view model is executed in. + * @param overrideContext The context in which the view model is executed in. + */ + bind(bindingContext: any, overrideContext: any): void; + /** + * Unbinds the Compose. + */ + unbind(): void; + /** + * Invoked everytime the bound model changes. + * @param newValue The new value. + * @param oldValue The old value. + */ + modelChanged(newValue: any, oldValue: any): void; + /** + * Invoked everytime the bound view changes. + * @param newValue The new value. + * @param oldValue The old value. + */ + viewChanged(newValue: any, oldValue: any): void; + /** + * Invoked everytime the bound view model changes. + * @param newValue The new value. + * @param oldValue The old value. + */ + viewModelChanged(newValue: any, oldValue: any): void; } -export declare class UpdateTriggerBindingBehavior { - bind(binding?: any, source?: any, ...events: any[]): any; - unbind(binding?: any, source?: any): any; +declare class IfCore { + constructor(viewFactory: ViewFactory, viewSlot: ViewSlot); + bind(bindingContext: any, overrideContext: any): void; + unbind(): void; } -export declare class ThrottleBindingBehavior { - bind(binding?: any, source?: any, delay?: any): any; - unbind(binding?: any, source?: any): any; +/** + * Binding to conditionally include or not include template logic depending on returned result + * - value should be Boolean or will be treated as such (truthy / falsey) + */ +export declare class If extends IfCore { + condition: any; + swapOrder: 'before' | 'with' | 'after'; + cache: boolean | string; + /** + * Binds the if to the binding context and override context + * @param bindingContext The binding context + * @param overrideContext An override context for binding. + */ + bind(bindingContext: any, overrideContext: any): void; + /** + * Invoked everytime value property changes. + * @param newValue The new value + */ + conditionChanged(newValue: any): void; } -export declare class SelfBindingBehavior { - bind(binding?: any, source?: any): any; - unbind(binding?: any, source?: any): any; +export declare class Else extends IfCore { + constructor(viewFactory: any, viewSlot: any); + bind(bindingContext: any, overrideContext: any): void; } - /** -* Marks any part of a view to be replacable by the consumer. -*/ -export declare class Replaceable { - - /** - * @param viewFactory target The factory generating the view. - * @param viewSlot viewSlot The slot the view is injected in to. - */ - constructor(viewFactory?: any, viewSlot?: any); - - /** - * Binds the replaceable to the binding context and override context. - * @param bindingContext The binding context. - * @param overrideContext An override context for binding. - */ - bind(bindingContext?: any, overrideContext?: any): any; - - /** - * Unbinds the replaceable. - */ - unbind(): any; + * Creates a binding context for decandant elements to bind to. + */ +export declare class With { + value: any; + /** + * Creates an instance of With. + * @param viewFactory The factory generating the view. + * @param viewSlot The slot the view is injected in to. + */ + constructor(viewFactory: ViewFactory, viewSlot: ViewSlot); + /** + * Binds the With with provided binding context and override context. + * @param bindingContext The binding context. + * @param overrideContext An override context for binding. + */ + bind(bindingContext: any, overrideContext: any): void; + /** + * Invoked everytime the bound value changes. + * @param newValue The new value. + */ + valueChanged(newValue: any): void; + /** + * Unbinds With + */ + unbind(): void; } - /** -* Update the override context. -* @param startIndex index in collection where to start updating. -*/ -export declare function updateOverrideContexts(views?: any, startIndex?: any): any; - -/** - * Creates a complete override context. - * @param data The item's value. - * @param index The item's index. - * @param length The collections total length. - * @param key The key in a key/value pair. - */ -export declare function createFullOverrideContext(repeat?: any, data?: any, index?: any, length?: any, key?: any): any; - -/** -* Updates the override context. -* @param context The context to be updated. -* @param index The context's index. -* @param length The collection's length. -*/ -export declare function updateOverrideContext(overrideContext?: any, index?: any, length?: any): any; - -/** -* Gets a repeat instruction's source expression. -*/ -export declare function getItemsSourceExpression(instruction?: any, attrName?: any): any; - -/** -* Unwraps an expression to expose the inner, pre-converted / behavior-free expression. -*/ -export declare function unwrapExpression(expression?: any): any; - -/** -* Returns whether an expression has the OneTimeBindingBehavior applied. -*/ -export declare function isOneTime(expression?: any): any; - -/** -* Forces a binding instance to reevaluate. +* An abstract base class for elements and attributes that repeat +* views. */ -export declare function updateOneTimeBinding(binding?: any): any; - +export declare class AbstractRepeater { + constructor(options: any); + /** + * Returns the number of views the repeater knows about. + * + * @return {Number} the number of views. + */ + viewCount(): number; + /** + * Returns all of the repeaters views as an array. + * + * @return {Array} The repeater's array of views; + */ + views(): any[]; + /** + * Returns a single view from the repeater at the provided index. + * + * @param {Number} index The index of the requested view. + * @return {View|ViewSlot} The requested view. + */ + view(index: any): any; + /** + * Returns the matcher function to be used by the repeater, or null if strict matching is to be performed. + * + * @return {Function|null} The requested matcher function. + */ + matcher(): void; + /** + * Adds a view to the repeater, binding the view to the + * provided contexts. + * + * @param {Object} bindingContext The binding context to bind the new view to. + * @param {Object} overrideContext A secondary binding context that can override the primary context. + */ + addView(bindingContext: any, overrideContext: any): void; + /** + * Inserts a view to the repeater at a specific index, binding the view to the + * provided contexts. + * + * @param {Number} index The index at which to create the new view at. + * @param {Object} bindingContext The binding context to bind the new view to. + * @param {Object} overrideContext A secondary binding context that can override the primary context. + */ + insertView(index: any, bindingContext: any, overrideContext: any): void; + /** + * Moves a view across the repeater. + * + * @param {Number} sourceIndex The index of the view to be moved. + * @param {Number} sourceIndex The index where the view should be placed at. + */ + moveView(sourceIndex: any, targetIndex: any): void; + /** + * Removes all views from the repeater. + * @param {Boolean} returnToCache Should the view be returned to the view cache? + * @param {Boolean} skipAnimation Should the removal animation be skipped? + * @return {Promise|null} + */ + removeAllViews(returnToCache?: boolean, skipAnimation?: boolean): void; + /** + * Removes an array of Views from the repeater. + * + * @param {Array} viewsToRemove The array of views to be removed. + * @param {Boolean} returnToCache Should the view be returned to the view cache? + * @param {Boolean} skipAnimation Should the removal animation be skipped? + * @return {Promise|null} + */ + removeViews(viewsToRemove: Array, returnToCache?: boolean, skipAnimation?: boolean): void; + /** + * Removes a view from the repeater at a specific index. + * + * @param {Number} index The index of the view to be removed. + * @param {Boolean} returnToCache Should the view be returned to the view cache? + * @param {Boolean} skipAnimation Should the removal animation be skipped? + * @return {Promise|null} + */ + removeView(index: number, returnToCache?: boolean, skipAnimation?: boolean): void; + /** + * Forces a particular view to update it's bindings, called as part of + * an in-place processing of items for better performance + * + * @param {Object} view the target view for bindings updates + */ + updateBindings(view: View): void; +} /** - * Returns the index of the element in an array, optionally using a matcher function. + * Binding to iterate over iterable objects (Array, Map and Number) to genereate a template for each iteration. */ -export declare function indexOf(array?: any, item?: any, matcher?: any, startIndex?: any): any; - +export declare class Repeat extends AbstractRepeater { + /** + * List of items to bind the repeater to. + * + * @property items + */ + items: any; + /** + * Local variable which gets assigned on each iteration. + * + * @property local + */ + local: any; + /** + * Key when iterating over Maps. + * + * @property key + */ + key: any; + /** + * Value when iterating over Maps. + * + * @property value + */ + value: any; + /** + * Creates an instance of Repeat. + * @param viewFactory The factory generating the view + * @param instruction The instructions for how the element should be enhanced. + * @param viewResources Collection of resources used to compile the the views. + * @param viewSlot The slot the view is injected in to. + * @param observerLocator The observer locator instance. + * @param collectionStrategyLocator The strategy locator to locate best strategy to iterate the collection. + */ + constructor(viewFactory: any, instruction: any, viewSlot: any, viewResources: any, observerLocator: any, strategyLocator: any); + call(context: any, changes: any): void; + /** + * Binds the repeat to the binding context and override context. + * @param bindingContext The binding context. + * @param overrideContext An override context for binding. + */ + bind(bindingContext: any, overrideContext: any): void; + /** + * Unbinds the repeat + */ + unbind(): void; + /** + * Invoked everytime the item property changes. + */ + itemsChanged(): void; + /** + * Invoked when the underlying collection changes. + */ + handleCollectionMutated(collection: any, changes: any): void; + /** + * Invoked when the underlying inner collection changes. + */ + handleInnerCollectionMutated(collection: any, changes: any): void; + viewCount(): any; + views(): any; + view(index: any): any; + matcher(): any; + addView(bindingContext: any, overrideContext: any): void; + insertView(index: any, bindingContext: any, overrideContext: any): void; + moveView(sourceIndex: any, targetIndex: any): void; + removeAllViews(returnToCache: any, skipAnimation: any): any; + removeViews(viewsToRemove: any, returnToCache: any, skipAnimation: any): any; + removeView(index: any, returnToCache: any, skipAnimation: any): any; + updateBindings(view: View): void; +} /** -* A strategy for repeating a template over null or undefined (does nothing) -*/ -export declare class NullRepeatStrategy { - instanceChanged(repeat?: any, items?: any): any; - getCollectionObserver(observerLocator?: any, items?: any): any; + * Binding to conditionally show markup in the DOM based on the value. + * - different from "if" in that the markup is still added to the DOM, simply not shown. + */ +export declare class Show { + value: any; + /** + * Creates a new instance of Show. + * @param element Target element to conditionally show. + * @param animator The animator that conditionally adds or removes the aurelia-hide css class. + * @param domBoundary The DOM boundary. Used when the behavior appears within a component that utilizes the shadow DOM. + */ + constructor(element: any, animator: any, domBoundary: any); + /** + * Invoked when the behavior is created. + */ + created(): void; + /** + * Invoked everytime the bound value changes. + * @param newValue The new value. + */ + valueChanged(newValue: any): void; + /** + * Binds the Show attribute. + */ + bind(bindingContext: any): void; } - /** -* For internal use only. May change without warning. -*/ -export declare class IfCore { - constructor(viewFactory?: any, viewSlot?: any); - bind(bindingContext?: any, overrideContext?: any): any; - unbind(): any; + * Binding to conditionally show markup in the DOM based on the value. + * - different from "if" in that the markup is still added to the DOM, simply not shown. + */ +export declare class Hide { + /** + * Creates a new instance of Hide. + * @param element Target element to conditionally hide. + * @param animator The animator that conditionally adds or removes the aurelia-hide css class. + * @param domBoundary The DOM boundary. Used when the behavior appears within a component that utilizes the shadow DOM. + */ + constructor(element: any, animator: any, domBoundary: any); + /** + * Invoked when the behavior is created. + */ + created(): void; + /** + * Invoked everytime the bound value changes. + * @param newValue The new value. + */ + valueChanged(newValue: any): void; + /** + * Binds the Hide attribute. + */ + bind(bindingContext: any): void; + value(value: any): void; } - /** -* Default Html Sanitizer to prevent script injection. -*/ + * Default Html Sanitizer to prevent script injection. + */ export declare class HTMLSanitizer { - - /** - * Sanitizes the provided input. - * @param input The input to be sanitized. - */ - sanitize(input?: any): any; + /** + * Sanitizes the provided input. + * @param input The input to be sanitized. + */ + sanitize(input: any): any; } - /** -* CustomAttribute that binds provided DOM element's focus attribute with a property on the viewmodel. -*/ -export declare class Focus { - static inject(): any; - - /** - * Creates an instance of Focus. - * @paramelement Target element on where attribute is placed on. - * @param taskQueue The TaskQueue instance. - */ - constructor(element?: any, taskQueue?: any); - - /** - * Invoked everytime the bound value changes. - * @param newValue The new value. - */ - valueChanged(newValue?: any): any; - - /** - * Invoked when the attribute is attached to the DOM. - */ - attached(): any; - - /** - * Invoked when the attribute is detached from the DOM. - */ - detached(): any; - handleEvent(e?: any): any; + * Simple html sanitization converter to preserve whitelisted elements and attributes on a bound property containing html. + */ +export declare class SanitizeHTMLValueConverter { + /** + * Creates an instanse of the value converter. + * @param sanitizer The html sanitizer. + */ + constructor(sanitizer: HTMLSanitizer); + /** + * Process the provided markup that flows to the view. + * @param untrustedMarkup The untrusted markup to be sanitized. + */ + toView(untrustedMarkup: any): any; } -export declare class DebounceBindingBehavior { - bind(binding?: any, source?: any, delay?: any): any; - unbind(binding?: any, source?: any): any; +/** + * Marks any part of a view to be replacable by the consumer. + */ +export declare class Replaceable { + /** + * @param viewFactory target The factory generating the view. + * @param viewSlot viewSlot The slot the view is injected in to. + */ + constructor(viewFactory: ViewFactory, viewSlot: ViewSlot); + /** + * Binds the replaceable to the binding context and override context. + * @param bindingContext The binding context. + * @param overrideContext An override context for binding. + */ + bind(bindingContext: any, overrideContext: any): void; + /** + * Unbinds the replaceable. + */ + unbind(): void; } - /** -* Used to compose a new view / view-model template or bind to an existing instance. -*/ -export declare class Compose { - static inject(): any; - model: any; - view: any; - viewModel: any; - swapOrder: any; - - /** - * Creates an instance of Compose. - * @param element The Compose element. - * @param container The dependency injection container instance. - * @param compositionEngine CompositionEngine instance to compose the element. - * @param viewSlot The slot the view is injected in to. - * @param viewResources Collection of resources used to compile the the view. - * @param taskQueue The TaskQueue instance. - */ - constructor(element?: any, container?: any, compositionEngine?: any, viewSlot?: any, viewResources?: any, taskQueue?: any); - - /** - * Invoked when the component has been created. - * - * @param owningView The view that this component was created inside of. - */ - created(owningView: View): any; - - /** - * Used to set the bindingContext. - * - * @param bindingContext The context in which the view model is executed in. - * @param overrideContext The context in which the view model is executed in. - */ - bind(bindingContext?: any, overrideContext?: any): any; - - /** - * Unbinds the Compose. - */ - unbind(): any; - - /** - * Invoked everytime the bound model changes. - * @param newValue The new value. - * @param oldValue The old value. - */ - modelChanged(newValue?: any, oldValue?: any): any; - - /** - * Invoked everytime the bound view changes. - * @param newValue The new value. - * @param oldValue The old value. - */ - viewChanged(newValue?: any, oldValue?: any): any; - - /** - * Invoked everytime the bound view model changes. - * @param newValue The new value. - * @param oldValue The old value. - */ - viewModelChanged(newValue?: any, oldValue?: any): any; + * CustomAttribute that binds provided DOM element's focus attribute with a property on the viewmodel. + */ +export declare class Focus { + /** + * Creates an instance of Focus. + * @paramelement Target element on where attribute is placed on. + * @param taskQueue The TaskQueue instance. + */ + constructor(element: any, taskQueue: any); + /** + * Invoked everytime the bound value changes. + * @param newValue The new value. + */ + valueChanged(newValue: any): void; + /** + * Invoked when the attribute is attached to the DOM. + */ + attached(): void; + /** + * Invoked when the attribute is detached from the DOM. + */ + detached(): void; + handleEvent(e: any): void; } -export declare class BindingSignaler { - signals: any; - signal(name: string): void; +export declare class AttrBindingBehavior { + bind(binding: any, source: any): void; + unbind(binding: any, source: any): void; } export declare class OneTimeBindingBehavior { - constructor(); + mode: bindingMode; + constructor(); } export declare class OneWayBindingBehavior { - constructor(); + mode: bindingMode; + constructor(); } export declare class ToViewBindingBehavior { - constructor(); + mode: bindingMode; + constructor(); } export declare class FromViewBindingBehavior { - constructor(); + mode: bindingMode; + constructor(); } export declare class TwoWayBindingBehavior { - constructor(); + mode: bindingMode; + constructor(); } -export declare const aureliaHideClassName: any; -export declare function injectAureliaHideStyleAtHead(): any; -export declare function injectAureliaHideStyleAtBoundary(domBoundary?: any): any; -export declare class AttrBindingBehavior { - bind(binding?: any, source?: any): any; - unbind(binding?: any, source?: any): any; +export declare class ThrottleBindingBehavior { + bind(binding: any, source: any, delay?: number): void; + unbind(binding: any, source: any): void; +} +export declare class DebounceBindingBehavior { + bind(binding: any, source: any, delay?: number): void; + unbind(binding: any, source: any): void; +} +export declare class SelfBindingBehavior { + bind(binding: any, source: any): void; + unbind(binding: any, source: any): void; +} +export declare class SignalBindingBehavior { + signals: any; + constructor(bindingSignaler: any); + bind(binding: any, source: any, ...names: any[]): void; + unbind(binding: any, source: any): void; +} +export declare class BindingSignaler { + signals: {}; + signal(name: string): void; +} +export declare class UpdateTriggerBindingBehavior { + bind(binding: any, source: any, ...events: any[]): void; + unbind(binding: any, source: any): void; } - /** -* Behaviors that do not require the composition lifecycle callbacks when replacing -* their binding context. -*/ -export declare const lifecycleOptionalBehaviors: any; -export declare function viewsRequireLifecycle(viewFactory?: any): any; - + * A strategy is for repeating a template over an iterable or iterable-like object. + */ +export interface RepeatStrategy { + instanceChanged(repeat: Repeat, items: any): void; + instanceMutated(repeat: Repeat, items: any, changes: any): void; + getCollectionObserver(observerLocator: any, items: any): any; +} /** -* An abstract base class for elements and attributes that repeat -* views. -*/ -export declare class AbstractRepeater { - constructor(options?: any); - - /** - * Returns the number of views the repeater knows about. - * - * @return {Number} the number of views. - */ - viewCount(): any; - - /** - * Returns all of the repeaters views as an array. - * - * @return {Array} The repeater's array of views; - */ - views(): any; - - /** - * Returns a single view from the repeater at the provided index. - * - * @param {Number} index The index of the requested view. - * @return {View|ViewSlot} The requested view. - */ - view(index?: any): any; - - /** - * Returns the matcher function to be used by the repeater, or null if strict matching is to be performed. - * - * @return {Function|null} The requested matcher function. - */ - matcher(): any; - - /** - * Adds a view to the repeater, binding the view to the - * provided contexts. - * - * @param {Object} bindingContext The binding context to bind the new view to. - * @param {Object} overrideContext A secondary binding context that can override the primary context. - */ - addView(bindingContext?: any, overrideContext?: any): any; - - /** - * Inserts a view to the repeater at a specific index, binding the view to the - * provided contexts. - * - * @param {Number} index The index at which to create the new view at. - * @param {Object} bindingContext The binding context to bind the new view to. - * @param {Object} overrideContext A secondary binding context that can override the primary context. - */ - insertView(index?: any, bindingContext?: any, overrideContext?: any): any; - - /** - * Moves a view across the repeater. - * - * @param {Number} sourceIndex The index of the view to be moved. - * @param {Number} sourceIndex The index where the view should be placed at. - */ - moveView(sourceIndex?: any, targetIndex?: any): any; - - /** - * Removes all views from the repeater. - * @param {Boolean} returnToCache Should the view be returned to the view cache? - * @param {Boolean} skipAnimation Should the removal animation be skipped? - * @return {Promise|null} - */ - removeAllViews(returnToCache?: boolean, skipAnimation?: boolean): any; - - /** - * Removes an array of Views from the repeater. - * - * @param {Array} viewsToRemove The array of views to be removed. - * @param {Boolean} returnToCache Should the view be returned to the view cache? - * @param {Boolean} skipAnimation Should the removal animation be skipped? - * @return {Promise|null} - */ - removeViews(viewsToRemove: Array, returnToCache?: boolean, skipAnimation?: boolean): any; - - /** - * Removes a view from the repeater at a specific index. - * - * @param {Number} index The index of the view to be removed. - * @param {Boolean} returnToCache Should the view be returned to the view cache? - * @param {Boolean} skipAnimation Should the removal animation be skipped? - * @return {Promise|null} - */ - removeView(index: number, returnToCache?: boolean, skipAnimation?: boolean): any; - - /** - * Forces a particular view to update it's bindings, called as part of - * an in-place processing of items for better performance - * - * @param {Object} view the target view for bindings updates - */ - updateBindings(view: View): any; + * Locates the best strategy to best repeating a template over different types of collections. + * Custom strategies can be plugged in as well. + */ +export declare class RepeatStrategyLocator { + /** + * Creates a new RepeatStrategyLocator. + */ + constructor(); + /** + * Adds a repeat strategy to be located when repeating a template over different collection types. + * @param strategy A repeat strategy that can iterate a specific collection type. + */ + addStrategy(matcher: (items: any) => boolean, strategy: RepeatStrategy): void; + /** + * Gets the best strategy to handle iteration. + */ + getStrategy(items: any): RepeatStrategy; } - /** -* A strategy for repeating a template over an array. -*/ -export declare class ArrayRepeatStrategy { - - /** - * Gets an observer for the specified collection. - * @param observerLocator The observer locator instance. - * @param items The items to be observed. - */ - getCollectionObserver(observerLocator?: any, items?: any): any; - - /** - * Handle the repeat's collection instance changing. - * @param repeat The repeater instance. - * @param items The new array instance. - */ - instanceChanged(repeat?: any, items?: any): any; - - /** - * Handle the repeat's collection instance mutating. - * @param repeat The repeat instance. - * @param array The modified array. - * @param splices Records of array changes. - */ - instanceMutated(repeat?: any, array?: any, splices?: any): any; + * A strategy for repeating a template over null or undefined (does nothing) + */ +export declare class NullRepeatStrategy { + instanceChanged(repeat: any, items: any): void; + getCollectionObserver(observerLocator: any, items: any): void; } - /** -* A strategy for repeating a template over a Map. -*/ -export declare class MapRepeatStrategy { - - /** - * Gets a Map observer. - * @param items The items to be observed. - */ - getCollectionObserver(observerLocator?: any, items?: any): any; - - /** - * Process the provided Map entries. - * @param items The entries to process. - */ - instanceChanged(repeat?: any, items?: any): any; - - /** - * Handle changes in a Map collection. - * @param map The underlying Map collection. - * @param records The change records. - */ - instanceMutated(repeat?: any, map?: any, records?: any): any; + * A strategy for repeating a template over an array. + */ +export declare class ArrayRepeatStrategy { + /** + * Gets an observer for the specified collection. + * @param observerLocator The observer locator instance. + * @param items The items to be observed. + */ + getCollectionObserver(observerLocator: any, items: any): any; + /** + * Handle the repeat's collection instance changing. + * @param repeat The repeater instance. + * @param items The new array instance. + */ + instanceChanged(repeat: any, items: any): void; + /** + * Handle the repeat's collection instance mutating. + * @param repeat The repeat instance. + * @param array The modified array. + * @param splices Records of array changes. + */ + instanceMutated(repeat: any, array: any, splices: any): void; } - /** -* A strategy for repeating a template over a number. -*/ -export declare class NumberRepeatStrategy { - - /** - * Return the strategies collection observer. In this case none. - */ - getCollectionObserver(): any; - - /** - * Process the provided Number. - * @param value The Number of how many time to iterate. - */ - instanceChanged(repeat?: any, value?: any): any; + * A strategy for repeating a template over a Map. + */ +export declare class MapRepeatStrategy { + /** + * Gets a Map observer. + * @param items The items to be observed. + */ + getCollectionObserver(observerLocator: any, items: any): any; + /** + * Process the provided Map entries. + * @param items The entries to process. + */ + instanceChanged(repeat: any, items: any): void; + /** + * Handle changes in a Map collection. + * @param map The underlying Map collection. + * @param records The change records. + */ + instanceMutated(repeat: any, map: any, records: any): void; } - /** -* A strategy for repeating a template over a Set. -*/ + * A strategy for repeating a template over a Set. + */ export declare class SetRepeatStrategy { - - /** - * Gets a Set observer. - * @param items The items to be observed. - */ - getCollectionObserver(observerLocator?: any, items?: any): any; - - /** - * Process the provided Set entries. - * @param items The entries to process. - */ - instanceChanged(repeat?: any, items?: any): any; - - /** - * Handle changes in a Set collection. - * @param repeat The repeat instance. - * @param set The underlying Set collection. - * @param records The change records. - */ - instanceMutated(repeat?: any, set?: any, records?: any): any; -} -export declare class Else extends IfCore { - constructor(viewFactory?: any, viewSlot?: any); - bind(bindingContext?: any, overrideContext?: any): any; + /** + * Gets a Set observer. + * @param items The items to be observed. + */ + getCollectionObserver(observerLocator: any, items: any): any; + /** + * Process the provided Set entries. + * @param items The entries to process. + */ + instanceChanged(repeat: any, items: any): void; + /** + * Handle changes in a Set collection. + * @param repeat The repeat instance. + * @param set The underlying Set collection. + * @param records The change records. + */ + instanceMutated(repeat: any, set: any, records: any): void; } - /** -* Binding to conditionally include or not include template logic depending on returned result -* - value should be Boolean or will be treated as such (truthy / falsey) -*/ -export declare class If extends IfCore { - condition: any; - swapOrder: 'before' | 'with' | 'after'; - cache: boolean | string; - - /** - * Binds the if to the binding context and override context - * @param bindingContext The binding context - * @param overrideContext An override context for binding. - */ - bind(bindingContext?: any, overrideContext?: any): any; - - /** - * Invoked everytime value property changes. - * @param newValue The new value - */ - conditionChanged(newValue?: any): any; + * A strategy for repeating a template over a number. + */ +export declare class NumberRepeatStrategy { + /** + * Return the strategies collection observer. In this case none. + */ + getCollectionObserver(): any; + /** + * Process the provided Number. + * @param value The Number of how many time to iterate. + */ + instanceChanged(repeat: any, value: any): void; } - /** -* Simple html sanitization converter to preserve whitelisted elements and attributes on a bound property containing html. -*/ -export declare class SanitizeHTMLValueConverter { - - /** - * Creates an instanse of the value converter. - * @param sanitizer The html sanitizer. - */ - constructor(sanitizer?: any); - - /** - * Process the provided markup that flows to the view. - * @param untrustedMarkup The untrusted markup to be sanitized. - */ - toView(untrustedMarkup?: any): any; -} -export declare function getElementName(address?: any): any; -export declare function configure(config?: any): any; -export declare class SignalBindingBehavior { - static inject(): any; - signals: any; - constructor(bindingSignaler?: any); - bind(binding?: any, source?: any, ...names: any[]): any; - unbind(binding?: any, source?: any): any; -} - + * Creates a complete override context. + * @param data The item's value. + * @param index The item's index. + * @param length The collections total length. + * @param key The key in a key/value pair. + */ +export declare function createFullOverrideContext(repeat: any, data: any, index: any, length: any, key?: string): import("aurelia-binding").OverrideContext; /** -* Binding to conditionally show markup in the DOM based on the value. -* - different from "if" in that the markup is still added to the DOM, simply not shown. -*/ -export declare class Hide { - static inject(): any; - - /** - * Creates a new instance of Hide. - * @param element Target element to conditionally hide. - * @param animator The animator that conditionally adds or removes the aurelia-hide css class. - * @param domBoundary The DOM boundary. Used when the behavior appears within a component that utilizes the shadow DOM. - */ - constructor(element?: any, animator?: any, domBoundary?: any); - - /** - * Invoked when the behavior is created. - */ - created(): any; - - /** - * Invoked everytime the bound value changes. - * @param newValue The new value. - */ - valueChanged(newValue?: any): any; - - /** - * Binds the Hide attribute. - */ - bind(bindingContext?: any): any; -} - + * Updates the override context. + * @param context The context to be updated. + * @param index The context's index. + * @param length The collection's length. + */ +export declare function updateOverrideContext(overrideContext: any, index: any, length: any): void; /** -* Binding to conditionally show markup in the DOM based on the value. -* - different from "if" in that the markup is still added to the DOM, simply not shown. -*/ -export declare class Show { - static inject(): any; - - /** - * Creates a new instance of Show. - * @param element Target element to conditionally show. - * @param animator The animator that conditionally adds or removes the aurelia-hide css class. - * @param domBoundary The DOM boundary. Used when the behavior appears within a component that utilizes the shadow DOM. - */ - constructor(element?: any, animator?: any, domBoundary?: any); - - /** - * Invoked when the behavior is created. - */ - created(): any; - - /** - * Invoked everytime the bound value changes. - * @param newValue The new value. - */ - valueChanged(newValue?: any): any; - - /** - * Binds the Show attribute. - */ - bind(bindingContext?: any): any; -} - + * Gets a repeat instruction's source expression. + */ +export declare function getItemsSourceExpression(instruction: any, attrName: any): any; /** -* Locates the best strategy to best repeating a template over different types of collections. -* Custom strategies can be plugged in as well. -*/ + * Unwraps an expression to expose the inner, pre-converted / behavior-free expression. + */ +export declare function unwrapExpression(expression: any): any; /** -* Locates the best strategy to best repeating a template over different types of collections. -* Custom strategies can be plugged in as well. -*/ -export declare class RepeatStrategyLocator { - - /** - * Creates a new RepeatStrategyLocator. - */ - constructor(); - - /** - * Adds a repeat strategy to be located when repeating a template over different collection types. - * @param strategy A repeat strategy that can iterate a specific collection type. - */ - addStrategy(matcher: ((items: any) => boolean), strategy: RepeatStrategy): any; - - /** - * Gets the best strategy to handle iteration. - */ - getStrategy(items: any): RepeatStrategy; -} - -/*eslint no-loop-func:0, no-unused-vars:0*/ + * Returns whether an expression has the OneTimeBindingBehavior applied. + */ +export declare function isOneTime(expression: any): boolean; /** -* Binding to iterate over iterable objects (Array, Map and Number) to genereate a template for each iteration. -*/ -export declare class Repeat extends AbstractRepeater { - items: any; - local: any; - key: any; - value: any; - - /** - * Creates an instance of Repeat. - * @param viewFactory The factory generating the view - * @param instruction The instructions for how the element should be enhanced. - * @param viewResources Collection of resources used to compile the the views. - * @param viewSlot The slot the view is injected in to. - * @param observerLocator The observer locator instance. - * @param collectionStrategyLocator The strategy locator to locate best strategy to iterate the collection. - */ - constructor(viewFactory?: any, instruction?: any, viewSlot?: any, viewResources?: any, observerLocator?: any, strategyLocator?: any); - call(context?: any, changes?: any): any; - - /** - * Binds the repeat to the binding context and override context. - * @param bindingContext The binding context. - * @param overrideContext An override context for binding. - */ - bind(bindingContext?: any, overrideContext?: any): any; - - /** - * Unbinds the repeat - */ - unbind(): any; - - /** - * Invoked everytime the item property changes. - */ - itemsChanged(): any; - - /** - * Invoked when the underlying collection changes. - */ - handleCollectionMutated(collection?: any, changes?: any): any; - - /** - * Invoked when the underlying inner collection changes. - */ - handleInnerCollectionMutated(collection?: any, changes?: any): any; - - // @override AbstractRepeater - viewCount(): any; - views(): any; - view(index?: any): any; - matcher(): any; - addView(bindingContext?: any, overrideContext?: any): any; - insertView(index?: any, bindingContext?: any, overrideContext?: any): any; - moveView(sourceIndex?: any, targetIndex?: any): any; - removeAllViews(returnToCache?: any, skipAnimation?: any): any; - removeViews(viewsToRemove?: any, returnToCache?: any, skipAnimation?: any): any; - removeView(index?: any, returnToCache?: any, skipAnimation?: any): any; - updateBindings(view: View): any; -} \ No newline at end of file + * Forces a binding instance to reevaluate. + */ +export declare function updateOneTimeBinding(binding: any): void; +export declare function viewsRequireLifecycle(viewFactory: any): any; +export declare function configure(config: any): void; \ No newline at end of file diff --git a/dist/aurelia-templating-resources.js b/dist/aurelia-templating-resources.js deleted file mode 100644 index 71f9305..0000000 --- a/dist/aurelia-templating-resources.js +++ /dev/null @@ -1,2389 +0,0 @@ -import {inject,Container,Optional} from 'aurelia-dependency-injection'; -import {BoundViewFactory,ViewSlot,customAttribute,templateController,useView,customElement,bindable,useShadowDOM,ViewResources,resource,ViewCompileInstruction,CompositionEngine,CompositionContext,noView,View,ViewEngine,Animator,TargetInstruction} from 'aurelia-templating'; -import {createOverrideContext,bindingMode,EventSubscriber,bindingBehavior,BindingBehavior,ValueConverter,sourceContext,targetContext,DataAttributeObserver,mergeSplice,valueConverter,ObserverLocator} from 'aurelia-binding'; -import {getLogger} from 'aurelia-logging'; -import {TaskQueue} from 'aurelia-task-queue'; -import {DOM,FEATURE} from 'aurelia-pal'; -import {Loader} from 'aurelia-loader'; -import {relativeToFile} from 'aurelia-path'; -import {mixin} from 'aurelia-metadata'; - -/** -* Creates a binding context for decandant elements to bind to. -*/ -@customAttribute('with') -@templateController -@inject(BoundViewFactory, ViewSlot) -export class With { - /** - * Creates an instance of With. - * @param viewFactory The factory generating the view. - * @param viewSlot The slot the view is injected in to. - */ - constructor(viewFactory, viewSlot) { - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.parentOverrideContext = null; - this.view = null; - } - - /** - * Binds the With with provided binding context and override context. - * @param bindingContext The binding context. - * @param overrideContext An override context for binding. - */ - bind(bindingContext, overrideContext) { - this.parentOverrideContext = overrideContext; - this.valueChanged(this.value); - } - - /** - * Invoked everytime the bound value changes. - * @param newValue The new value. - */ - valueChanged(newValue) { - let overrideContext = createOverrideContext(newValue, this.parentOverrideContext); - if (!this.view) { - this.view = this.viewFactory.create(); - this.view.bind(newValue, overrideContext); - this.viewSlot.add(this.view); - } else { - this.view.bind(newValue, overrideContext); - } - } - - /** - * Unbinds With - */ - unbind() { - this.parentOverrideContext = null; - - if (this.view) { - this.view.unbind(); - } - } -} - -const eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg '; -const notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.'; - -@bindingBehavior('updateTrigger') -export class UpdateTriggerBindingBehavior { - - bind(binding, source, ...events) { - if (events.length === 0) { - throw new Error(eventNamesRequired); - } - if (binding.mode !== bindingMode.twoWay && binding.mode !== bindingMode.fromView) { - throw new Error(notApplicableMessage); - } - - // ensure the binding's target observer has been set. - let targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty); - if (!targetObserver.handler) { - throw new Error(notApplicableMessage); - } - binding.targetObserver = targetObserver; - - // stash the original element subscribe function. - targetObserver.originalHandler = binding.targetObserver.handler; - - // replace the element subscribe function with one that uses the correct events. - let handler = new EventSubscriber(events); - targetObserver.handler = handler; - } - - unbind(binding, source) { - // restore the state of the binding. - binding.targetObserver.handler.dispose(); - binding.targetObserver.handler = binding.targetObserver.originalHandler; - binding.targetObserver.originalHandler = null; - } -} - -function throttle(newValue) { - let state = this.throttleState; - let elapsed = +new Date() - state.last; - if (elapsed >= state.delay) { - clearTimeout(state.timeoutId); - state.timeoutId = null; - state.last = +new Date(); - this.throttledMethod(newValue); - return; - } - state.newValue = newValue; - if (state.timeoutId === null) { - state.timeoutId = setTimeout( - () => { - state.timeoutId = null; - state.last = +new Date(); - this.throttledMethod(state.newValue); - }, - state.delay - elapsed); - } -} - -@bindingBehavior('throttle') -export class ThrottleBindingBehavior { - bind(binding, source, delay = 200) { - // determine which method to throttle. - let methodToThrottle = 'updateTarget'; // one-way bindings or interpolation bindings - if (binding.callSource) { - methodToThrottle = 'callSource'; // listener and call bindings - } else if (binding.updateSource && binding.mode === bindingMode.twoWay) { - methodToThrottle = 'updateSource'; // two-way bindings - } - - // stash the original method and it's name. - // note: a generic name like "originalMethod" is not used to avoid collisions - // with other binding behavior types. - binding.throttledMethod = binding[methodToThrottle]; - binding.throttledMethod.originalName = methodToThrottle; - - // replace the original method with the throttling version. - binding[methodToThrottle] = throttle; - - // create the throttle state. - binding.throttleState = { - delay: delay, - last: 0, - timeoutId: null - }; - } - - unbind(binding, source) { - // restore the state of the binding. - let methodToRestore = binding.throttledMethod.originalName; - binding[methodToRestore] = binding.throttledMethod; - binding.throttledMethod = null; - clearTimeout(binding.throttleState.timeoutId); - binding.throttleState = null; - } -} - -function findOriginalEventTarget(event) { - return (event.path && event.path[0]) || (event.deepPath && event.deepPath[0]) || event.target; -} - -function handleSelfEvent(event) { - let target = findOriginalEventTarget(event); - if (this.target !== target) return; - this.selfEventCallSource(event); -} - -@bindingBehavior('self') -export class SelfBindingBehavior { - bind(binding, source) { - if (!binding.callSource || !binding.targetEvent) throw new Error('Self binding behavior only supports event.'); - binding.selfEventCallSource = binding.callSource; - binding.callSource = handleSelfEvent; - } - - unbind(binding, source) { - binding.callSource = binding.selfEventCallSource; - binding.selfEventCallSource = null; - } -} - -/** -* Marks any part of a view to be replacable by the consumer. -*/ -@customAttribute('replaceable') -@templateController -@inject(BoundViewFactory, ViewSlot) -export class Replaceable { - - /** - * @param viewFactory target The factory generating the view. - * @param viewSlot viewSlot The slot the view is injected in to. - */ - constructor(viewFactory, viewSlot) { - this.viewFactory = viewFactory; //This is referenced internally in the Controller's bind method. - this.viewSlot = viewSlot; - this.view = null; - } - - /** - * Binds the replaceable to the binding context and override context. - * @param bindingContext The binding context. - * @param overrideContext An override context for binding. - */ - bind(bindingContext, overrideContext) { - if (this.view === null) { - this.view = this.viewFactory.create(); - this.viewSlot.add(this.view); - } - - this.view.bind(bindingContext, overrideContext); - } - - /** - * Unbinds the replaceable. - */ - unbind() { - this.view.unbind(); - } -} - -const oneTime = bindingMode.oneTime; - -/** -* Update the override context. -* @param startIndex index in collection where to start updating. -*/ -export function updateOverrideContexts(views, startIndex) { - let length = views.length; - - if (startIndex > 0) { - startIndex = startIndex - 1; - } - - for (; startIndex < length; ++startIndex) { - updateOverrideContext(views[startIndex].overrideContext, startIndex, length); - } -} - -/** - * Creates a complete override context. - * @param data The item's value. - * @param index The item's index. - * @param length The collections total length. - * @param key The key in a key/value pair. - */ -export function createFullOverrideContext(repeat, data, index, length, key) { - let bindingContext = {}; - let overrideContext = createOverrideContext(bindingContext, repeat.scope.overrideContext); - // is key/value pair (Map) - if (typeof key !== 'undefined') { - bindingContext[repeat.key] = key; - bindingContext[repeat.value] = data; - } else { - bindingContext[repeat.local] = data; - } - updateOverrideContext(overrideContext, index, length); - return overrideContext; -} - -/** -* Updates the override context. -* @param context The context to be updated. -* @param index The context's index. -* @param length The collection's length. -*/ -export function updateOverrideContext(overrideContext, index, length) { - let first = (index === 0); - let last = (index === length - 1); - let even = index % 2 === 0; - - overrideContext.$index = index; - overrideContext.$first = first; - overrideContext.$last = last; - overrideContext.$middle = !(first || last); - overrideContext.$odd = !even; - overrideContext.$even = even; -} - -/** -* Gets a repeat instruction's source expression. -*/ -export function getItemsSourceExpression(instruction, attrName) { - return instruction.behaviorInstructions - .filter(bi => bi.originalAttrName === attrName)[0] - .attributes - .items - .sourceExpression; -} - -/** -* Unwraps an expression to expose the inner, pre-converted / behavior-free expression. -*/ -export function unwrapExpression(expression) { - let unwrapped = false; - while (expression instanceof BindingBehavior) { - expression = expression.expression; - } - while (expression instanceof ValueConverter) { - expression = expression.expression; - unwrapped = true; - } - return unwrapped ? expression : null; -} - -/** -* Returns whether an expression has the OneTimeBindingBehavior applied. -*/ -export function isOneTime(expression) { - while (expression instanceof BindingBehavior) { - if (expression.name === 'oneTime') { - return true; - } - expression = expression.expression; - } - return false; -} - -/** -* Forces a binding instance to reevaluate. -*/ -export function updateOneTimeBinding(binding) { - if (binding.call && binding.mode === oneTime) { - binding.call(sourceContext); - } else if (binding.updateOneTimeBindings) { - binding.updateOneTimeBindings(); - } -} - -/** - * Returns the index of the element in an array, optionally using a matcher function. - */ -export function indexOf(array, item, matcher, startIndex) { - if (!matcher) { - // native indexOf is more performant than a for loop - return array.indexOf(item); - } - const length = array.length; - for (let index = startIndex || 0; index < length; index++) { - if (matcher(array[index], item)) { - return index; - } - } - return -1; -} - -/** -* A strategy for repeating a template over null or undefined (does nothing) -*/ -export class NullRepeatStrategy { - instanceChanged(repeat, items) { - repeat.removeAllViews(true); - } - - getCollectionObserver(observerLocator, items) { - } -} - -/** -* For internal use only. May change without warning. -*/ -export class IfCore { - constructor(viewFactory, viewSlot) { - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.view = null; - this.bindingContext = null; - this.overrideContext = null; - // If the child view is animated, `value` might not reflect the internal - // state anymore, so we use `showing` for that. - // Eventually, `showing` and `value` should be consistent. - this.showing = false; - this.cache = true; - } - - bind(bindingContext, overrideContext) { - // Store parent bindingContext, so we can pass it down - this.bindingContext = bindingContext; - this.overrideContext = overrideContext; - } - - unbind() { - if (this.view === null) { - return; - } - - this.view.unbind(); - - // It seems to me that this code is subject to race conditions when animating. - // For example a view could be returned to the cache and reused while it's still - // attached to the DOM and animated. - if (!this.viewFactory.isCaching) { - return; - } - - if (this.showing) { - this.showing = false; - this.viewSlot.remove(this.view, /*returnToCache:*/true, /*skipAnimation:*/true); - } else { - this.view.returnToCache(); - } - - this.view = null; - } - - _show() { - if (this.showing) { - // Ensures the view is bound. - // It might not be the case when the if was unbound but not detached, then rebound. - // Typical case where this happens is nested ifs - if (!this.view.isBound) { - this.view.bind(this.bindingContext, this.overrideContext); - } - return; - } - - if (this.view === null) { - this.view = this.viewFactory.create(); - } - - if (!this.view.isBound) { - this.view.bind(this.bindingContext, this.overrideContext); - } - - this.showing = true; - return this.viewSlot.add(this.view); // Promise or void - } - - _hide() { - if (!this.showing) { - return; - } - - this.showing = false; - let removed = this.viewSlot.remove(this.view); // Promise or View - - if (removed instanceof Promise) { - return removed.then(() => { - this._unbindView(); - }); - } - - this._unbindView(); - } - - _unbindView() { - const cache = this.cache === 'false' ? false : !!this.cache; - this.view.unbind(); - if (!cache) { - this.view = null; - } - } -} - -const SCRIPT_REGEX = /)<[^<]*)*<\/script>/gi; -let needsToWarn = true; - -/** -* Default Html Sanitizer to prevent script injection. -*/ -export class HTMLSanitizer { - /** - * Sanitizes the provided input. - * @param input The input to be sanitized. - */ - sanitize(input) { - if (needsToWarn) { - needsToWarn = false; - - getLogger('html-sanitizer') - .warn(`CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks, - and should not be relied on for sanitizing input from unknown sources. - Please see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html.`); - } - - return input.replace(SCRIPT_REGEX, ''); - } -} - -/** -* CustomAttribute that binds provided DOM element's focus attribute with a property on the viewmodel. -*/ -@customAttribute('focus', bindingMode.twoWay) -export class Focus { - - static inject() { - return [DOM.Element, TaskQueue]; - } - /** - * Creates an instance of Focus. - * @paramelement Target element on where attribute is placed on. - * @param taskQueue The TaskQueue instance. - */ - constructor(element, taskQueue) { - this.element = element; - this.taskQueue = taskQueue; - this.isAttached = false; - this.needsApply = false; - } - - /** - * Invoked everytime the bound value changes. - * @param newValue The new value. - */ - valueChanged(newValue) { - if (this.isAttached) { - this._apply(); - } else { - this.needsApply = true; - } - } - - _apply() { - if (this.value) { - this.taskQueue.queueMicroTask(() => { - if (this.value) { - this.element.focus(); - } - }); - } else { - this.element.blur(); - } - } - - /** - * Invoked when the attribute is attached to the DOM. - */ - attached() { - this.isAttached = true; - if (this.needsApply) { - this.needsApply = false; - this._apply(); - } - this.element.addEventListener('focus', this); - this.element.addEventListener('blur', this); - } - - /** - * Invoked when the attribute is detached from the DOM. - */ - detached() { - this.isAttached = false; - this.element.removeEventListener('focus', this); - this.element.removeEventListener('blur', this); - } - - handleEvent(e) { - if (e.type === 'focus') { - this.value = true; - } else if (DOM.activeElement !== this.element) { - this.value = false; - } - } -} - -/*eslint padded-blocks:0*/ -export function _createDynamicElement({ name, viewUrl, bindableNames, useShadowDOMmode } : { - name: string, - viewUrl: string, - bindableNames: string[], - useShadowDOMmode: null | '' | 'open' | 'closed' -}): Function { - @customElement(name) - @useView(viewUrl) - class DynamicElement { - bind(bindingContext) { - this.$parent = bindingContext; - } - } - - for (let i = 0, ii = bindableNames.length; i < ii; ++i) { - bindable(bindableNames[i])(DynamicElement); - } - - switch (useShadowDOMmode) { - case 'open': - useShadowDOM({ mode: 'open' })(DynamicElement); - break; - - case 'closed': - useShadowDOM({ mode: 'closed' })(DynamicElement); - break; - - case '': - useShadowDOM(DynamicElement); - break; - - case null: - // Do not use shadow dom - break; - - default: - getLogger('aurelia-html-only-element') - .warn(`Expected 'use-shadow-dom' value to be "close", "open" or "", received ${useShadowDOMmode}`); - break; - } - - return DynamicElement; -} - -const unset = {}; - -function debounceCallSource(event) { - const state = this.debounceState; - clearTimeout(state.timeoutId); - state.timeoutId = setTimeout(() => this.debouncedMethod(event), state.delay); -} - -function debounceCall(context, newValue, oldValue) { - const state = this.debounceState; - clearTimeout(state.timeoutId); - if (context !== state.callContextToDebounce) { - state.oldValue = unset; - this.debouncedMethod(context, newValue, oldValue); - return; - } - if (state.oldValue === unset) { - state.oldValue = oldValue; - } - state.timeoutId = setTimeout(() => { - const _oldValue = state.oldValue; - state.oldValue = unset; - this.debouncedMethod(context, newValue, _oldValue); - }, state.delay); -} - -@bindingBehavior('debounce') -export class DebounceBindingBehavior { - bind(binding, source, delay = 200) { - const isCallSource = binding.callSource !== undefined; - const methodToDebounce = isCallSource ? 'callSource' : 'call'; - const debouncer = isCallSource ? debounceCallSource : debounceCall; - const mode = binding.mode; - const callContextToDebounce = mode === bindingMode.twoWay || mode === bindingMode.fromView ? targetContext : sourceContext; - - // stash the original method and it's name. - // note: a generic name like "originalMethod" is not used to avoid collisions - // with other binding behavior types. - binding.debouncedMethod = binding[methodToDebounce]; - binding.debouncedMethod.originalName = methodToDebounce; - - // replace the original method with the debouncing version. - binding[methodToDebounce] = debouncer; - - // create the debounce state. - binding.debounceState = { - callContextToDebounce, - delay, - timeoutId: 0, - oldValue: unset - }; - } - - unbind(binding, source) { - // restore the state of the binding. - const methodToRestore = binding.debouncedMethod.originalName; - binding[methodToRestore] = binding.debouncedMethod; - binding.debouncedMethod = null; - clearTimeout(binding.debounceState.timeoutId); - binding.debounceState = null; - } -} - -/*eslint new-cap:0, padded-blocks:0*/ -let cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi; - -function fixupCSSUrls(address, css) { - if (typeof css !== 'string') { - throw new Error(`Failed loading required CSS file: ${address}`); - } - return css.replace(cssUrlMatcher, (match, p1) => { - let quote = p1.charAt(0); - if (quote === '\'' || quote === '"') { - p1 = p1.substr(1, p1.length - 2); - } - return 'url(\'' + relativeToFile(p1, address) + '\')'; - }); -} - -class CSSResource { - constructor(address: string) { - this.address = address; - this._scoped = null; - this._global = false; - this._alreadyGloballyInjected = false; - } - - initialize(container: Container, target: Function): void { - this._scoped = new target(this); - } - - register(registry: ViewResources, name?: string): void { - if (name === 'scoped') { - registry.registerViewEngineHooks(this._scoped); - } else { - this._global = true; - } - } - - load(container: Container): Promise { - return container.get(Loader) - .loadText(this.address) - .catch(err => null) - .then(text => { - text = fixupCSSUrls(this.address, text); - this._scoped.css = text; - if (this._global) { - this._alreadyGloballyInjected = true; - DOM.injectStyles(text); - } - }); - } -} - -class CSSViewEngineHooks { - constructor(owner: CSSResource) { - this.owner = owner; - this.css = null; - } - - beforeCompile(content: DocumentFragment, resources: ViewResources, instruction: ViewCompileInstruction): void { - if (instruction.targetShadowDOM) { - DOM.injectStyles(this.css, content, true); - } else if (FEATURE.scopedCSS) { - let styleNode = DOM.injectStyles(this.css, content, true); - styleNode.setAttribute('scoped', 'scoped'); - } else if (this._global && !this.owner._alreadyGloballyInjected) { - DOM.injectStyles(this.css); - this.owner._alreadyGloballyInjected = true; - } - } -} - -export function _createCSSResource(address: string): Function { - @resource(new CSSResource(address)) - class ViewCSS extends CSSViewEngineHooks {} - return ViewCSS; -} - -/** -* Used to compose a new view / view-model template or bind to an existing instance. -*/ -@customElement('compose') -@noView -export class Compose { - - static inject() { - return [DOM.Element, Container, CompositionEngine, ViewSlot, ViewResources, TaskQueue]; - } - /** - * Model to bind the custom element to. - * - * @property model - * @type {CustomElement} - */ - @bindable model; - /** - * View to bind the custom element to. - * - * @property view - * @type {HtmlElement} - */ - @bindable view; - /** - * View-model to bind the custom element's template to. - * - * @property viewModel - * @type {Class} - */ - @bindable viewModel; - - /** - * SwapOrder to control the swapping order of the custom element's view. - * - * @property view - * @type {String} - */ - @bindable swapOrder; - - /** - * Creates an instance of Compose. - * @param element The Compose element. - * @param container The dependency injection container instance. - * @param compositionEngine CompositionEngine instance to compose the element. - * @param viewSlot The slot the view is injected in to. - * @param viewResources Collection of resources used to compile the the view. - * @param taskQueue The TaskQueue instance. - */ - constructor(element, container, compositionEngine, viewSlot, viewResources, taskQueue) { - this.element = element; - this.container = container; - this.compositionEngine = compositionEngine; - this.viewSlot = viewSlot; - this.viewResources = viewResources; - this.taskQueue = taskQueue; - this.currentController = null; - this.currentViewModel = null; - this.changes = Object.create(null); - } - - /** - * Invoked when the component has been created. - * - * @param owningView The view that this component was created inside of. - */ - created(owningView: View) { - this.owningView = owningView; - } - - /** - * Used to set the bindingContext. - * - * @param bindingContext The context in which the view model is executed in. - * @param overrideContext The context in which the view model is executed in. - */ - bind(bindingContext, overrideContext) { - this.bindingContext = bindingContext; - this.overrideContext = overrideContext; - this.changes.view = this.view; - this.changes.viewModel = this.viewModel; - this.changes.model = this.model; - if (!this.pendingTask) { - processChanges(this); - } - } - - /** - * Unbinds the Compose. - */ - unbind() { - this.changes = Object.create(null); - this.bindingContext = null; - this.overrideContext = null; - let returnToCache = true; - let skipAnimation = true; - this.viewSlot.removeAll(returnToCache, skipAnimation); - } - - /** - * Invoked everytime the bound model changes. - * @param newValue The new value. - * @param oldValue The old value. - */ - modelChanged(newValue, oldValue) { - this.changes.model = newValue; - requestUpdate(this); - } - - /** - * Invoked everytime the bound view changes. - * @param newValue The new value. - * @param oldValue The old value. - */ - viewChanged(newValue, oldValue) { - this.changes.view = newValue; - requestUpdate(this); - } - - /** - * Invoked everytime the bound view model changes. - * @param newValue The new value. - * @param oldValue The old value. - */ - viewModelChanged(newValue, oldValue) { - this.changes.viewModel = newValue; - requestUpdate(this); - } -} - -function isEmpty(obj) { - for (const key in obj) { - return false; - } - return true; -} - -function tryActivateViewModel(vm, model) { - if (vm && typeof vm.activate === 'function') { - return Promise.resolve(vm.activate(model)); - } -} - -function createInstruction(composer: Compose, instruction: CompositionContext): CompositionContext { - return Object.assign(instruction, { - bindingContext: composer.bindingContext, - overrideContext: composer.overrideContext, - owningView: composer.owningView, - container: composer.container, - viewSlot: composer.viewSlot, - viewResources: composer.viewResources, - currentController: composer.currentController, - host: composer.element, - swapOrder: composer.swapOrder - }); -} - -function processChanges(composer: Compose) { - const changes = composer.changes; - composer.changes = Object.create(null); - - if (!('view' in changes) && !('viewModel' in changes) && ('model' in changes)) { - // just try to activate the current view model - composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model); - if (!composer.pendingTask) { return; } - } else { - // init context - let instruction = { - view: composer.view, - viewModel: composer.currentViewModel || composer.viewModel, - model: composer.model - }; - - // apply changes - instruction = Object.assign(instruction, changes); - - // create context - instruction = createInstruction(composer, instruction); - composer.pendingTask = composer.compositionEngine.compose(instruction).then(controller => { - composer.currentController = controller; - composer.currentViewModel = controller ? controller.viewModel : null; - }); - } - - composer.pendingTask = composer.pendingTask - .then(() => { - completeCompositionTask(composer); - }, reason => { - completeCompositionTask(composer); - throw reason; - }); -} - -function completeCompositionTask(composer) { - composer.pendingTask = null; - if (!isEmpty(composer.changes)) { - processChanges(composer); - } -} - -function requestUpdate(composer: Compose) { - if (composer.pendingTask || composer.updateRequested) { return; } - composer.updateRequested = true; - composer.taskQueue.queueMicroTask(() => { - composer.updateRequested = false; - processChanges(composer); - }); -} - -export class BindingSignaler { - signals = {}; - - signal(name: string): void { - let bindings = this.signals[name]; - if (!bindings) { - return; - } - let i = bindings.length; - while (i--) { - bindings[i].call(sourceContext); - } - } -} - -let modeBindingBehavior = { - bind(binding, source, lookupFunctions) { - binding.originalMode = binding.mode; - binding.mode = this.mode; - }, - - unbind(binding, source) { - binding.mode = binding.originalMode; - binding.originalMode = null; - } -}; - -@mixin(modeBindingBehavior) -@bindingBehavior('oneTime') -export class OneTimeBindingBehavior { - constructor() { - this.mode = bindingMode.oneTime; - } -} - -@mixin(modeBindingBehavior) -@bindingBehavior('oneWay') -export class OneWayBindingBehavior { - constructor() { - this.mode = bindingMode.toView; - } -} - -@mixin(modeBindingBehavior) -@bindingBehavior('toView') -export class ToViewBindingBehavior { - constructor() { - this.mode = bindingMode.toView; - } -} - -@mixin(modeBindingBehavior) -@bindingBehavior('fromView') -export class FromViewBindingBehavior { - constructor() { - this.mode = bindingMode.fromView; - } -} - -@mixin(modeBindingBehavior) -@bindingBehavior('twoWay') -export class TwoWayBindingBehavior { - constructor() { - this.mode = bindingMode.twoWay; - } -} - -export const aureliaHideClassName = 'aurelia-hide'; - -const aureliaHideClass = `.${aureliaHideClassName} { display:none !important; }`; - -export function injectAureliaHideStyleAtHead() { - DOM.injectStyles(aureliaHideClass); -} - -export function injectAureliaHideStyleAtBoundary(domBoundary) { - if (FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) { - domBoundary.hasAureliaHideStyle = true; - DOM.injectStyles(aureliaHideClass, domBoundary); - } -} - -@bindingBehavior('attr') -export class AttrBindingBehavior { - bind(binding, source) { - binding.targetObserver = new DataAttributeObserver(binding.target, binding.targetProperty); - } - - unbind(binding, source) {} -} - -/** -* Behaviors that do not require the composition lifecycle callbacks when replacing -* their binding context. -*/ -export const lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with']; - -function behaviorRequiresLifecycle(instruction) { - let t = instruction.type; - let name = t.elementName !== null ? t.elementName : t.attributeName; - return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind) - || t.viewFactory && viewsRequireLifecycle(t.viewFactory) - || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); -} - -function targetRequiresLifecycle(instruction) { - // check each behavior instruction. - let behaviors = instruction.behaviorInstructions; - if (behaviors) { - let i = behaviors.length; - while (i--) { - if (behaviorRequiresLifecycle(behaviors[i])) { - return true; - } - } - } - - // check the instruction's view factory (if it has one). - return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); -} - -export function viewsRequireLifecycle(viewFactory) { - // already analyzed? - if ('_viewsRequireLifecycle' in viewFactory) { - return viewFactory._viewsRequireLifecycle; - } - - // set prop to avoid infinite recursion. - viewFactory._viewsRequireLifecycle = false; - - // access inner view factory. - if (viewFactory.viewFactory) { - viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory); - return viewFactory._viewsRequireLifecycle; - } - - // template uses animation? - if (viewFactory.template.querySelector('.au-animate')) { - viewFactory._viewsRequireLifecycle = true; - return true; - } - - // target instructions require lifecycle? - for (let id in viewFactory.instructions) { - if (targetRequiresLifecycle(viewFactory.instructions[id])) { - viewFactory._viewsRequireLifecycle = true; - return true; - } - } - - // safe to skip lifecycle. - viewFactory._viewsRequireLifecycle = false; - return false; -} - -/** -* An abstract base class for elements and attributes that repeat -* views. -*/ -export class AbstractRepeater { - constructor(options) { - Object.assign(this, { - local: 'items', - viewsRequireLifecycle: true - }, options); - } - - /** - * Returns the number of views the repeater knows about. - * - * @return {Number} the number of views. - */ - viewCount() { - throw new Error('subclass must implement `viewCount`'); - } - - /** - * Returns all of the repeaters views as an array. - * - * @return {Array} The repeater's array of views; - */ - views() { - throw new Error('subclass must implement `views`'); - } - - /** - * Returns a single view from the repeater at the provided index. - * - * @param {Number} index The index of the requested view. - * @return {View|ViewSlot} The requested view. - */ - view(index) { - throw new Error('subclass must implement `view`'); - } - - /** - * Returns the matcher function to be used by the repeater, or null if strict matching is to be performed. - * - * @return {Function|null} The requested matcher function. - */ - matcher() { - throw new Error('subclass must implement `matcher`'); - } - - /** - * Adds a view to the repeater, binding the view to the - * provided contexts. - * - * @param {Object} bindingContext The binding context to bind the new view to. - * @param {Object} overrideContext A secondary binding context that can override the primary context. - */ - addView(bindingContext, overrideContext) { - throw new Error('subclass must implement `addView`'); - } - - /** - * Inserts a view to the repeater at a specific index, binding the view to the - * provided contexts. - * - * @param {Number} index The index at which to create the new view at. - * @param {Object} bindingContext The binding context to bind the new view to. - * @param {Object} overrideContext A secondary binding context that can override the primary context. - */ - insertView(index, bindingContext, overrideContext) { - throw new Error('subclass must implement `insertView`'); - } - - /** - * Moves a view across the repeater. - * - * @param {Number} sourceIndex The index of the view to be moved. - * @param {Number} sourceIndex The index where the view should be placed at. - */ - moveView(sourceIndex, targetIndex) { - throw new Error('subclass must implement `moveView`'); - } - - /** - * Removes all views from the repeater. - * @param {Boolean} returnToCache Should the view be returned to the view cache? - * @param {Boolean} skipAnimation Should the removal animation be skipped? - * @return {Promise|null} - */ - removeAllViews(returnToCache?: boolean, skipAnimation?: boolean) { - throw new Error('subclass must implement `removeAllViews`'); - } - - /** - * Removes an array of Views from the repeater. - * - * @param {Array} viewsToRemove The array of views to be removed. - * @param {Boolean} returnToCache Should the view be returned to the view cache? - * @param {Boolean} skipAnimation Should the removal animation be skipped? - * @return {Promise|null} - */ - removeViews(viewsToRemove: Array, returnToCache?: boolean, skipAnimation?: boolean) { - throw new Error('subclass must implement `removeView`'); - } - - /** - * Removes a view from the repeater at a specific index. - * - * @param {Number} index The index of the view to be removed. - * @param {Boolean} returnToCache Should the view be returned to the view cache? - * @param {Boolean} skipAnimation Should the removal animation be skipped? - * @return {Promise|null} - */ - removeView(index: number, returnToCache?: boolean, skipAnimation?: boolean) { - throw new Error('subclass must implement `removeView`'); - } - - /** - * Forces a particular view to update it's bindings, called as part of - * an in-place processing of items for better performance - * - * @param {Object} view the target view for bindings updates - */ - updateBindings(view: View) { - throw new Error('subclass must implement `updateBindings`'); - } -} - -/** -* A strategy for repeating a template over an array. -*/ -export class ArrayRepeatStrategy { - /** - * Gets an observer for the specified collection. - * @param observerLocator The observer locator instance. - * @param items The items to be observed. - */ - getCollectionObserver(observerLocator, items) { - return observerLocator.getArrayObserver(items); - } - - /** - * Handle the repeat's collection instance changing. - * @param repeat The repeater instance. - * @param items The new array instance. - */ - instanceChanged(repeat, items) { - const itemsLength = items.length; - - // if the new instance does not contain any items, - // just remove all views and don't do any further processing - if (!items || itemsLength === 0) { - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - return; - } - - const children = repeat.views(); - const viewsLength = children.length; - - // likewise, if we previously didn't have any views, - // simply make them and return - if (viewsLength === 0) { - this._standardProcessInstanceChanged(repeat, items); - return; - } - - if (repeat.viewsRequireLifecycle) { - const childrenSnapshot = children.slice(0); - const itemNameInBindingContext = repeat.local; - const matcher = repeat.matcher(); - - // the cache of the current state (it will be transformed along with the views to keep track of indicies) - let itemsPreviouslyInViews = []; - const viewsToRemove = []; - - for (let index = 0; index < viewsLength; index++) { - const view = childrenSnapshot[index]; - const oldItem = view.bindingContext[itemNameInBindingContext]; - - if (indexOf(items, oldItem, matcher) === -1) { - // remove the item if no longer in the new instance of items - viewsToRemove.push(view); - } else { - // or add the item to the cache list - itemsPreviouslyInViews.push(oldItem); - } - } - - let updateViews; - let removePromise; - - if (itemsPreviouslyInViews.length > 0) { - removePromise = repeat.removeViews(viewsToRemove, true, !repeat.viewsRequireLifecycle); - updateViews = () => { - // update views (create new and move existing) - for (let index = 0; index < itemsLength; index++) { - const item = items[index]; - const indexOfView = indexOf(itemsPreviouslyInViews, item, matcher, index); - let view; - - if (indexOfView === -1) { // create views for new items - const overrideContext = createFullOverrideContext(repeat, items[index], index, itemsLength); - repeat.insertView(index, overrideContext.bindingContext, overrideContext); - // reflect the change in our cache list so indicies are valid - itemsPreviouslyInViews.splice(index, 0, undefined); - } else if (indexOfView === index) { // leave unchanged items - view = children[indexOfView]; - itemsPreviouslyInViews[indexOfView] = undefined; - } else { // move the element to the right place - view = children[indexOfView]; - repeat.moveView(indexOfView, index); - itemsPreviouslyInViews.splice(indexOfView, 1); - itemsPreviouslyInViews.splice(index, 0, undefined); - } - - if (view) { - updateOverrideContext(view.overrideContext, index, itemsLength); - } - } - - // remove extraneous elements in case of duplicates, - // also update binding contexts if objects changed using the matcher function - this._inPlaceProcessItems(repeat, items); - }; - } else { - // if all of the items are different, remove all and add all from scratch - removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - updateViews = () => this._standardProcessInstanceChanged(repeat, items); - } - - if (removePromise instanceof Promise) { - removePromise.then(updateViews); - } else { - updateViews(); - } - } else { - // no lifecycle needed, use the fast in-place processing - this._inPlaceProcessItems(repeat, items); - } - } - - _standardProcessInstanceChanged(repeat, items) { - for (let i = 0, ii = items.length; i < ii; i++) { - let overrideContext = createFullOverrideContext(repeat, items[i], i, ii); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - } - - _inPlaceProcessItems(repeat, items) { - let itemsLength = items.length; - let viewsLength = repeat.viewCount(); - // remove unneeded views. - while (viewsLength > itemsLength) { - viewsLength--; - repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle); - } - // avoid repeated evaluating the property-getter for the "local" property. - let local = repeat.local; - // re-evaluate bindings on existing views. - for (let i = 0; i < viewsLength; i++) { - let view = repeat.view(i); - let last = i === itemsLength - 1; - let middle = i !== 0 && !last; - // any changes to the binding context? - if (view.bindingContext[local] === items[i] - && view.overrideContext.$middle === middle - && view.overrideContext.$last === last) { - // no changes. continue... - continue; - } - // update the binding context and refresh the bindings. - view.bindingContext[local] = items[i]; - view.overrideContext.$middle = middle; - view.overrideContext.$last = last; - repeat.updateBindings(view); - } - // add new views - for (let i = viewsLength; i < itemsLength; i++) { - let overrideContext = createFullOverrideContext(repeat, items[i], i, itemsLength); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - } - - /** - * Handle the repeat's collection instance mutating. - * @param repeat The repeat instance. - * @param array The modified array. - * @param splices Records of array changes. - */ - instanceMutated(repeat, array, splices) { - if (repeat.__queuedSplices) { - for (let i = 0, ii = splices.length; i < ii; ++i) { - let {index, removed, addedCount} = splices[i]; - mergeSplice(repeat.__queuedSplices, index, removed, addedCount); - } - // Array.prototype.slice is used here to clone the array - repeat.__array = array.slice(0); - return; - } - - // Array.prototype.slice is used here to clone the array - let maybePromise = this._runSplices(repeat, array.slice(0), splices); - if (maybePromise instanceof Promise) { - let queuedSplices = repeat.__queuedSplices = []; - - let runQueuedSplices = () => { - if (!queuedSplices.length) { - repeat.__queuedSplices = undefined; - repeat.__array = undefined; - return; - } - - let nextPromise = this._runSplices(repeat, repeat.__array, queuedSplices) || Promise.resolve(); - queuedSplices = repeat.__queuedSplices = []; - nextPromise.then(runQueuedSplices); - }; - - maybePromise.then(runQueuedSplices); - } - } - - /** - * Run a normalised set of splices against the viewSlot children. - * @param repeat The repeat instance. - * @param array The modified array. - * @param splices Records of array changes. - * @return {Promise|undefined} A promise if animations have to be run. - * @pre The splices must be normalised so as: - * * Any item added may not be later removed. - * * Removals are ordered by asending index - */ - _runSplices(repeat, array, splices) { - let removeDelta = 0; - let rmPromises = []; - - for (let i = 0, ii = splices.length; i < ii; ++i) { - let splice = splices[i]; - let removed = splice.removed; - - for (let j = 0, jj = removed.length; j < jj; ++j) { - // the rmPromises.length correction works due to the ordered removal precondition - let viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - } - removeDelta -= splice.addedCount; - } - - if (rmPromises.length > 0) { - return Promise.all(rmPromises).then(() => { - let spliceIndexLow = this._handleAddedSplices(repeat, array, splices); - updateOverrideContexts(repeat.views(), spliceIndexLow); - }); - } - - let spliceIndexLow = this._handleAddedSplices(repeat, array, splices); - updateOverrideContexts(repeat.views(), spliceIndexLow); - - return undefined; - } - - _handleAddedSplices(repeat, array, splices) { - let spliceIndex; - let spliceIndexLow; - let arrayLength = array.length; - for (let i = 0, ii = splices.length; i < ii; ++i) { - let splice = splices[i]; - let addIndex = spliceIndex = splice.index; - let end = splice.index + splice.addedCount; - - if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) { - spliceIndexLow = spliceIndex; - } - - for (; addIndex < end; ++addIndex) { - let overrideContext = createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength); - repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext); - } - } - - return spliceIndexLow; - } -} - -/** -* A strategy for repeating a template over a Map. -*/ -export class MapRepeatStrategy { - /** - * Gets a Map observer. - * @param items The items to be observed. - */ - getCollectionObserver(observerLocator, items) { - return observerLocator.getMapObserver(items); - } - - /** - * Process the provided Map entries. - * @param items The entries to process. - */ - instanceChanged(repeat, items) { - let removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(() => this._standardProcessItems(repeat, items)); - return; - } - this._standardProcessItems(repeat, items); - } - - _standardProcessItems(repeat, items) { - let index = 0; - let overrideContext; - - items.forEach((value, key) => { - overrideContext = createFullOverrideContext(repeat, value, index, items.size, key); - repeat.addView(overrideContext.bindingContext, overrideContext); - ++index; - }); - } - - /** - * Handle changes in a Map collection. - * @param map The underlying Map collection. - * @param records The change records. - */ - instanceMutated(repeat, map, records) { - let key; - let i; - let ii; - let overrideContext; - let removeIndex; - let addIndex; - let record; - let rmPromises = []; - let viewOrPromise; - - for (i = 0, ii = records.length; i < ii; ++i) { - record = records[i]; - key = record.key; - switch (record.type) { - case 'update': - removeIndex = this._getViewIndexByKey(repeat, key); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - overrideContext = createFullOverrideContext(repeat, map.get(key), removeIndex, map.size, key); - repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext); - break; - case 'add': - addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1; - overrideContext = createFullOverrideContext(repeat, map.get(key), addIndex, map.size, key); - repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext); - break; - case 'delete': - if (record.oldValue === undefined) { return; } - removeIndex = this._getViewIndexByKey(repeat, key); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - break; - case 'clear': - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - break; - default: - continue; - } - } - - if (rmPromises.length > 0) { - Promise.all(rmPromises).then(() => { - updateOverrideContexts(repeat.views(), 0); - }); - } else { - updateOverrideContexts(repeat.views(), 0); - } - } - - _getViewIndexByKey(repeat, key) { - let i; - let ii; - let child; - - for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { - child = repeat.view(i); - if (child.bindingContext[repeat.key] === key) { - return i; - } - } - - return undefined; - } -} - -/** -* A strategy for repeating a template over a number. -*/ -export class NumberRepeatStrategy { - /** - * Return the strategies collection observer. In this case none. - */ - getCollectionObserver() { - return null; - } - - /** - * Process the provided Number. - * @param value The Number of how many time to iterate. - */ - instanceChanged(repeat, value) { - let removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(() => this._standardProcessItems(repeat, value)); - return; - } - this._standardProcessItems(repeat, value); - } - - _standardProcessItems(repeat, value) { - let childrenLength = repeat.viewCount(); - let i; - let ii; - let overrideContext; - let viewsToRemove; - - value = Math.floor(value); - viewsToRemove = childrenLength - value; - - if (viewsToRemove > 0) { - if (viewsToRemove > childrenLength) { - viewsToRemove = childrenLength; - } - - for (i = 0, ii = viewsToRemove; i < ii; ++i) { - repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle); - } - - return; - } - - for (i = childrenLength, ii = value; i < ii; ++i) { - overrideContext = createFullOverrideContext(repeat, i, i, ii); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - - updateOverrideContexts(repeat.views(), 0); - } -} - -/** -* A strategy for repeating a template over a Set. -*/ -export class SetRepeatStrategy { - /** - * Gets a Set observer. - * @param items The items to be observed. - */ - getCollectionObserver(observerLocator, items) { - return observerLocator.getSetObserver(items); - } - - /** - * Process the provided Set entries. - * @param items The entries to process. - */ - instanceChanged(repeat, items) { - let removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(() => this._standardProcessItems(repeat, items)); - return; - } - this._standardProcessItems(repeat, items); - } - - _standardProcessItems(repeat, items) { - let index = 0; - let overrideContext; - - items.forEach(value => { - overrideContext = createFullOverrideContext(repeat, value, index, items.size); - repeat.addView(overrideContext.bindingContext, overrideContext); - ++index; - }); - } - - /** - * Handle changes in a Set collection. - * @param repeat The repeat instance. - * @param set The underlying Set collection. - * @param records The change records. - */ - instanceMutated(repeat, set, records) { - let value; - let i; - let ii; - let overrideContext; - let removeIndex; - let record; - let rmPromises = []; - let viewOrPromise; - - for (i = 0, ii = records.length; i < ii; ++i) { - record = records[i]; - value = record.value; - switch (record.type) { - case 'add': - let size = Math.max(set.size - 1, 0); - overrideContext = createFullOverrideContext(repeat, value, size, set.size); - repeat.insertView(size, overrideContext.bindingContext, overrideContext); - break; - case 'delete': - removeIndex = this._getViewIndexByValue(repeat, value); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - break; - case 'clear': - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - break; - default: - continue; - } - } - - if (rmPromises.length > 0) { - Promise.all(rmPromises).then(() => { - updateOverrideContexts(repeat.views(), 0); - }); - } else { - updateOverrideContexts(repeat.views(), 0); - } - } - - _getViewIndexByValue(repeat, value) { - let i; - let ii; - let child; - - for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { - child = repeat.view(i); - if (child.bindingContext[repeat.local] === value) { - return i; - } - } - - return undefined; - } -} - -@customAttribute('else') -@templateController -@inject(BoundViewFactory, ViewSlot) -export class Else extends IfCore { - constructor(viewFactory, viewSlot) { - super(viewFactory, viewSlot); - this._registerInIf(); - } - - bind(bindingContext, overrideContext) { - super.bind(bindingContext, overrideContext); - // Render on initial - if (this.ifVm.condition) { - this._hide(); - } else { - this._show(); - } - } - - _registerInIf() { - // We support the pattern
. - // Obvisouly between the two, we must accepts text (spaces) and comments. - // The `if` node is expected to be a comment anchor, because of `@templateController`. - // To simplify the code we basically walk up to the first Aurelia predecessor, - // so having static tags in between (no binding) would work but is not intended to be supported. - let previous = this.viewSlot.anchor.previousSibling; - while (previous && !previous.au) { - previous = previous.previousSibling; - } - if (!previous || !previous.au.if) { - throw new Error("Can't find matching If for Else custom attribute."); - } - this.ifVm = previous.au.if.viewModel; - this.ifVm.elseVm = this; - } -} - -/** -* Binding to conditionally include or not include template logic depending on returned result -* - value should be Boolean or will be treated as such (truthy / falsey) -*/ -@customAttribute('if') -@templateController -@inject(BoundViewFactory, ViewSlot) -export class If extends IfCore { - @bindable({ primaryProperty: true }) condition: any; - @bindable swapOrder: "before"|"with"|"after"; - @bindable cache: boolean|string = true; - - /** - * Binds the if to the binding context and override context - * @param bindingContext The binding context - * @param overrideContext An override context for binding. - */ - bind(bindingContext, overrideContext) { - super.bind(bindingContext, overrideContext); - if (this.condition) { - this._show(); - } else { - this._hide(); - } - } - - /** - * Invoked everytime value property changes. - * @param newValue The new value - */ - conditionChanged(newValue) { - this._update(newValue); - } - - _update(show) { - if (this.animating) { - return; - } - - let promise; - if (this.elseVm) { - promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm); - } else { - promise = show ? this._show() : this._hide(); - } - - if (promise) { - this.animating = true; - promise.then(() => { - this.animating = false; - if (this.condition !== this.showing) { - this._update(this.condition); - } - }); - } - } - - _swap(remove, add) { - switch (this.swapOrder) { - case 'before': - return Promise.resolve(add._show()).then(() => remove._hide()); - case 'with': - return Promise.all([ remove._hide(), add._show() ]); - default: // "after", default and unknown values - let promise = remove._hide(); - return promise ? promise.then(() => add._show()) : add._show(); - } - } -} - -/** -* Simple html sanitization converter to preserve whitelisted elements and attributes on a bound property containing html. -*/ -@valueConverter('sanitizeHTML') -@inject(HTMLSanitizer) -export class SanitizeHTMLValueConverter { - /** - * Creates an instanse of the value converter. - * @param sanitizer The html sanitizer. - */ - constructor(sanitizer) { - this.sanitizer = sanitizer; - } - - /** - * Process the provided markup that flows to the view. - * @param untrustedMarkup The untrusted markup to be sanitized. - */ - toView(untrustedMarkup) { - if (untrustedMarkup === null || untrustedMarkup === undefined) { - return null; - } - - return this.sanitizer.sanitize(untrustedMarkup); - } -} - -export function getElementName(address) { - return /([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase(); -} - -export function configure(config) { - const viewEngine = config.container.get(ViewEngine); - const loader = config.aurelia.loader; - - viewEngine.addResourcePlugin('.html', { - 'fetch': function(viewUrl) { - return loader.loadTemplate(viewUrl).then(registryEntry => { - let bindableNames = registryEntry.template.getAttribute('bindable'); - const useShadowDOMmode: null | '' | 'open' | 'closed' = registryEntry.template.getAttribute('use-shadow-dom'); - const name = getElementName(viewUrl); - - if (bindableNames) { - bindableNames = bindableNames.split(',').map(x => x.trim()); - registryEntry.template.removeAttribute('bindable'); - } else { - bindableNames = []; - } - - return { [name]: _createDynamicElement({name, viewUrl, bindableNames, useShadowDOMmode}) }; - }); - } - }); -} - -@bindingBehavior('signal') -export class SignalBindingBehavior { - static inject() { return [BindingSignaler]; } - signals; - - constructor(bindingSignaler) { - this.signals = bindingSignaler.signals; - } - - bind(binding, source, ...names) { - if (!binding.updateTarget) { - throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.'); - } - if (names.length === 1) { - let name = names[0]; - let bindings = this.signals[name] || (this.signals[name] = []); - bindings.push(binding); - binding.signalName = name; - } else if (names.length > 1) { - let i = names.length; - while (i--) { - let name = names[i]; - let bindings = this.signals[name] || (this.signals[name] = []); - bindings.push(binding); - } - binding.signalName = names; - } else { - throw new Error('Signal name is required.'); - } - } - - unbind(binding, source) { - let name = binding.signalName; - binding.signalName = null; - if (Array.isArray(name)) { - let names = name; - let i = names.length; - while (i--) { - let n = names[i]; - let bindings = this.signals[n]; - bindings.splice(bindings.indexOf(binding), 1); - } - } else { - let bindings = this.signals[name]; - bindings.splice(bindings.indexOf(binding), 1); - } - } -} - -/** -* Binding to conditionally show markup in the DOM based on the value. -* - different from "if" in that the markup is still added to the DOM, simply not shown. -*/ -@customAttribute('hide') -export class Hide { - - static inject() { - return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; - } - - /** - * Creates a new instance of Hide. - * @param element Target element to conditionally hide. - * @param animator The animator that conditionally adds or removes the aurelia-hide css class. - * @param domBoundary The DOM boundary. Used when the behavior appears within a component that utilizes the shadow DOM. - */ - constructor(element, animator, domBoundary) { - this.element = element; - this.animator = animator; - this.domBoundary = domBoundary; - } - - /** - * Invoked when the behavior is created. - */ - created() { - injectAureliaHideStyleAtBoundary(this.domBoundary); - } - - /** - * Invoked everytime the bound value changes. - * @param newValue The new value. - */ - valueChanged(newValue) { - if (newValue) { - this.animator.addClass(this.element, aureliaHideClassName); - } else { - this.animator.removeClass(this.element, aureliaHideClassName); - } - } - - /** - * Binds the Hide attribute. - */ - bind(bindingContext) { - this.valueChanged(this.value); - } -} - -/** -* Binding to conditionally show markup in the DOM based on the value. -* - different from "if" in that the markup is still added to the DOM, simply not shown. -*/ -@customAttribute('show') -export class Show { - - static inject() { - return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; - } - - /** - * Creates a new instance of Show. - * @param element Target element to conditionally show. - * @param animator The animator that conditionally adds or removes the aurelia-hide css class. - * @param domBoundary The DOM boundary. Used when the behavior appears within a component that utilizes the shadow DOM. - */ - constructor(element, animator, domBoundary) { - this.element = element; - this.animator = animator; - this.domBoundary = domBoundary; - } - - /** - * Invoked when the behavior is created. - */ - created() { - injectAureliaHideStyleAtBoundary(this.domBoundary); - } - - /** - * Invoked everytime the bound value changes. - * @param newValue The new value. - */ - valueChanged(newValue) { - if (newValue) { - this.animator.removeClass(this.element, aureliaHideClassName); - } else { - this.animator.addClass(this.element, aureliaHideClassName); - } - } - - /** - * Binds the Show attribute. - */ - bind(bindingContext) { - this.valueChanged(this.value); - } -} - -/** -* A strategy is for repeating a template over an iterable or iterable-like object. -*/ -interface RepeatStrategy { - instanceChanged(repeat: Repeat, items: any): void; - instanceMutated(repeat: Repeat, items: any, changes: any): void; - getCollectionObserver(observerLocator: any, items: any): any; -} - -/** -* Locates the best strategy to best repeating a template over different types of collections. -* Custom strategies can be plugged in as well. -*/ -export class RepeatStrategyLocator { - /** - * Creates a new RepeatStrategyLocator. - */ - constructor() { - this.matchers = []; - this.strategies = []; - - this.addStrategy(items => items === null || items === undefined, new NullRepeatStrategy()); - this.addStrategy(items => items instanceof Array, new ArrayRepeatStrategy()); - this.addStrategy(items => items instanceof Map, new MapRepeatStrategy()); - this.addStrategy(items => items instanceof Set, new SetRepeatStrategy()); - this.addStrategy(items => typeof items === 'number', new NumberRepeatStrategy()); - } - - /** - * Adds a repeat strategy to be located when repeating a template over different collection types. - * @param strategy A repeat strategy that can iterate a specific collection type. - */ - addStrategy(matcher: (items: any) => boolean, strategy: RepeatStrategy) { - this.matchers.push(matcher); - this.strategies.push(strategy); - } - - /** - * Gets the best strategy to handle iteration. - */ - getStrategy(items: any): RepeatStrategy { - let matchers = this.matchers; - - for (let i = 0, ii = matchers.length; i < ii; ++i) { - if (matchers[i](items)) { - return this.strategies[i]; - } - } - - return null; - } -} - -/*eslint no-loop-func:0, no-unused-vars:0*/ -/** -* Binding to iterate over iterable objects (Array, Map and Number) to genereate a template for each iteration. -*/ -@customAttribute('repeat') -@templateController -@inject(BoundViewFactory, TargetInstruction, ViewSlot, ViewResources, ObserverLocator, RepeatStrategyLocator) -export class Repeat extends AbstractRepeater { - /** - * List of items to bind the repeater to. - * - * @property items - */ - @bindable items - /** - * Local variable which gets assigned on each iteration. - * - * @property local - */ - @bindable local - /** - * Key when iterating over Maps. - * - * @property key - */ - @bindable key - /** - * Value when iterating over Maps. - * - * @property value - */ - @bindable value - - /** - * Creates an instance of Repeat. - * @param viewFactory The factory generating the view - * @param instruction The instructions for how the element should be enhanced. - * @param viewResources Collection of resources used to compile the the views. - * @param viewSlot The slot the view is injected in to. - * @param observerLocator The observer locator instance. - * @param collectionStrategyLocator The strategy locator to locate best strategy to iterate the collection. - */ - constructor(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) { - super({ - local: 'item', - viewsRequireLifecycle: viewsRequireLifecycle(viewFactory) - }); - - this.viewFactory = viewFactory; - this.instruction = instruction; - this.viewSlot = viewSlot; - this.lookupFunctions = viewResources.lookupFunctions; - this.observerLocator = observerLocator; - this.key = 'key'; - this.value = 'value'; - this.strategyLocator = strategyLocator; - this.ignoreMutation = false; - this.sourceExpression = getItemsSourceExpression(this.instruction, 'repeat.for'); - this.isOneTime = isOneTime(this.sourceExpression); - this.viewsRequireLifecycle = viewsRequireLifecycle(viewFactory); - } - - call(context, changes) { - this[context](this.items, changes); - } - - /** - * Binds the repeat to the binding context and override context. - * @param bindingContext The binding context. - * @param overrideContext An override context for binding. - */ - bind(bindingContext, overrideContext) { - this.scope = { bindingContext, overrideContext }; - this.matcherBinding = this._captureAndRemoveMatcherBinding(); - this.itemsChanged(); - } - - /** - * Unbinds the repeat - */ - unbind() { - this.scope = null; - this.items = null; - this.matcherBinding = null; - this.viewSlot.removeAll(true, true); - this._unsubscribeCollection(); - } - - _unsubscribeCollection() { - if (this.collectionObserver) { - this.collectionObserver.unsubscribe(this.callContext, this); - this.collectionObserver = null; - this.callContext = null; - } - } - - /** - * Invoked everytime the item property changes. - */ - itemsChanged() { - this._unsubscribeCollection(); - - // still bound? - if (!this.scope) { - return; - } - - let items = this.items; - this.strategy = this.strategyLocator.getStrategy(items); - if (!this.strategy) { - throw new Error(`Value for '${this.sourceExpression}' is non-repeatable`); - } - - if (!this.isOneTime && !this._observeInnerCollection()) { - this._observeCollection(); - } - this.ignoreMutation = true; - this.strategy.instanceChanged(this, items); - this.observerLocator.taskQueue.queueMicroTask(() => { - this.ignoreMutation = false; - }); - } - - _getInnerCollection() { - let expression = unwrapExpression(this.sourceExpression); - if (!expression) { - return null; - } - return expression.evaluate(this.scope, null); - } - - /** - * Invoked when the underlying collection changes. - */ - handleCollectionMutated(collection, changes) { - if (!this.collectionObserver) { - return; - } - if (this.ignoreMutation) { - return; - } - this.strategy.instanceMutated(this, collection, changes); - } - - /** - * Invoked when the underlying inner collection changes. - */ - handleInnerCollectionMutated(collection, changes) { - if (!this.collectionObserver) { - return; - } - // guard against source expressions that have observable side-effects that could - // cause an infinite loop- eg a value converter that mutates the source array. - if (this.ignoreMutation) { - return; - } - this.ignoreMutation = true; - let newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions); - this.observerLocator.taskQueue.queueMicroTask(() => this.ignoreMutation = false); - - // call itemsChanged... - if (newItems === this.items) { - // call itemsChanged directly. - this.itemsChanged(); - } else { - // call itemsChanged indirectly by assigning the new collection value to - // the items property, which will trigger the self-subscriber to call itemsChanged. - this.items = newItems; - } - } - - _observeInnerCollection() { - let items = this._getInnerCollection(); - let strategy = this.strategyLocator.getStrategy(items); - if (!strategy) { - return false; - } - this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items); - if (!this.collectionObserver) { - return false; - } - this.callContext = 'handleInnerCollectionMutated'; - this.collectionObserver.subscribe(this.callContext, this); - return true; - } - - _observeCollection() { - let items = this.items; - this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items); - if (this.collectionObserver) { - this.callContext = 'handleCollectionMutated'; - this.collectionObserver.subscribe(this.callContext, this); - } - } - - _captureAndRemoveMatcherBinding() { - if (this.viewFactory.viewFactory) { - const instructions = this.viewFactory.viewFactory.instructions; - const instructionIds = Object.keys(instructions); - for (let i = 0; i < instructionIds.length; i++) { - const expressions = instructions[instructionIds[i]].expressions; - if (expressions) { - for (let ii = 0; i < expressions.length; i++) { - if (expressions[ii].targetProperty === 'matcher') { - const matcherBinding = expressions[ii]; - expressions.splice(ii, 1); - return matcherBinding; - } - } - } - } - } - - return undefined; - } - - // @override AbstractRepeater - viewCount() { return this.viewSlot.children.length; } - views() { return this.viewSlot.children; } - view(index) { return this.viewSlot.children[index]; } - matcher() { return this.matcherBinding ? this.matcherBinding.sourceExpression.evaluate(this.scope, this.matcherBinding.lookupFunctions) : null; } - - addView(bindingContext, overrideContext) { - let view = this.viewFactory.create(); - view.bind(bindingContext, overrideContext); - this.viewSlot.add(view); - } - - insertView(index, bindingContext, overrideContext) { - let view = this.viewFactory.create(); - view.bind(bindingContext, overrideContext); - this.viewSlot.insert(index, view); - } - - moveView(sourceIndex, targetIndex) { - this.viewSlot.move(sourceIndex, targetIndex); - } - - removeAllViews(returnToCache, skipAnimation) { - return this.viewSlot.removeAll(returnToCache, skipAnimation); - } - - removeViews(viewsToRemove, returnToCache, skipAnimation) { - return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation); - } - - removeView(index, returnToCache, skipAnimation) { - return this.viewSlot.removeAt(index, returnToCache, skipAnimation); - } - - updateBindings(view: View) { - let j = view.bindings.length; - while (j--) { - updateOneTimeBinding(view.bindings[j]); - } - j = view.controllers.length; - while (j--) { - let k = view.controllers[j].boundProperties.length; - while (k--) { - let binding = view.controllers[j].boundProperties[k].binding; - updateOneTimeBinding(binding); - } - } - } -} diff --git a/dist/commonjs/abstract-repeater.js b/dist/commonjs/abstract-repeater.js deleted file mode 100644 index 3a1effe..0000000 --- a/dist/commonjs/abstract-repeater.js +++ /dev/null @@ -1,64 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - - - -var AbstractRepeater = exports.AbstractRepeater = function () { - function AbstractRepeater(options) { - - - Object.assign(this, { - local: 'items', - viewsRequireLifecycle: true - }, options); - } - - AbstractRepeater.prototype.viewCount = function viewCount() { - throw new Error('subclass must implement `viewCount`'); - }; - - AbstractRepeater.prototype.views = function views() { - throw new Error('subclass must implement `views`'); - }; - - AbstractRepeater.prototype.view = function view(index) { - throw new Error('subclass must implement `view`'); - }; - - AbstractRepeater.prototype.matcher = function matcher() { - throw new Error('subclass must implement `matcher`'); - }; - - AbstractRepeater.prototype.addView = function addView(bindingContext, overrideContext) { - throw new Error('subclass must implement `addView`'); - }; - - AbstractRepeater.prototype.insertView = function insertView(index, bindingContext, overrideContext) { - throw new Error('subclass must implement `insertView`'); - }; - - AbstractRepeater.prototype.moveView = function moveView(sourceIndex, targetIndex) { - throw new Error('subclass must implement `moveView`'); - }; - - AbstractRepeater.prototype.removeAllViews = function removeAllViews(returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeAllViews`'); - }; - - AbstractRepeater.prototype.removeViews = function removeViews(viewsToRemove, returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeView`'); - }; - - AbstractRepeater.prototype.removeView = function removeView(index, returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeView`'); - }; - - AbstractRepeater.prototype.updateBindings = function updateBindings(view) { - throw new Error('subclass must implement `updateBindings`'); - }; - - return AbstractRepeater; -}(); \ No newline at end of file diff --git a/dist/commonjs/analyze-view-factory.js b/dist/commonjs/analyze-view-factory.js deleted file mode 100644 index e2ce295..0000000 --- a/dist/commonjs/analyze-view-factory.js +++ /dev/null @@ -1,55 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.viewsRequireLifecycle = viewsRequireLifecycle; -var lifecycleOptionalBehaviors = exports.lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with']; - -function behaviorRequiresLifecycle(instruction) { - var t = instruction.type; - var name = t.elementName !== null ? t.elementName : t.attributeName; - return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind) || t.viewFactory && viewsRequireLifecycle(t.viewFactory) || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); -} - -function targetRequiresLifecycle(instruction) { - var behaviors = instruction.behaviorInstructions; - if (behaviors) { - var i = behaviors.length; - while (i--) { - if (behaviorRequiresLifecycle(behaviors[i])) { - return true; - } - } - } - - return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); -} - -function viewsRequireLifecycle(viewFactory) { - if ('_viewsRequireLifecycle' in viewFactory) { - return viewFactory._viewsRequireLifecycle; - } - - viewFactory._viewsRequireLifecycle = false; - - if (viewFactory.viewFactory) { - viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory); - return viewFactory._viewsRequireLifecycle; - } - - if (viewFactory.template.querySelector('.au-animate')) { - viewFactory._viewsRequireLifecycle = true; - return true; - } - - for (var id in viewFactory.instructions) { - if (targetRequiresLifecycle(viewFactory.instructions[id])) { - viewFactory._viewsRequireLifecycle = true; - return true; - } - } - - viewFactory._viewsRequireLifecycle = false; - return false; -} \ No newline at end of file diff --git a/dist/commonjs/array-repeat-strategy.js b/dist/commonjs/array-repeat-strategy.js deleted file mode 100644 index 38d8b88..0000000 --- a/dist/commonjs/array-repeat-strategy.js +++ /dev/null @@ -1,241 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.ArrayRepeatStrategy = undefined; - -var _repeatUtilities = require('./repeat-utilities'); - -var _aureliaBinding = require('aurelia-binding'); - - - -var ArrayRepeatStrategy = exports.ArrayRepeatStrategy = function () { - function ArrayRepeatStrategy() { - - } - - ArrayRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getArrayObserver(items); - }; - - ArrayRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this = this; - - var itemsLength = items.length; - - if (!items || itemsLength === 0) { - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - return; - } - - var children = repeat.views(); - var viewsLength = children.length; - - if (viewsLength === 0) { - this._standardProcessInstanceChanged(repeat, items); - return; - } - - if (repeat.viewsRequireLifecycle) { - var childrenSnapshot = children.slice(0); - var itemNameInBindingContext = repeat.local; - var matcher = repeat.matcher(); - - var itemsPreviouslyInViews = []; - var viewsToRemove = []; - - for (var index = 0; index < viewsLength; index++) { - var view = childrenSnapshot[index]; - var oldItem = view.bindingContext[itemNameInBindingContext]; - - if ((0, _repeatUtilities.indexOf)(items, oldItem, matcher) === -1) { - viewsToRemove.push(view); - } else { - itemsPreviouslyInViews.push(oldItem); - } - } - - var updateViews = void 0; - var removePromise = void 0; - - if (itemsPreviouslyInViews.length > 0) { - removePromise = repeat.removeViews(viewsToRemove, true, !repeat.viewsRequireLifecycle); - updateViews = function updateViews() { - for (var _index = 0; _index < itemsLength; _index++) { - var item = items[_index]; - var indexOfView = (0, _repeatUtilities.indexOf)(itemsPreviouslyInViews, item, matcher, _index); - var _view = void 0; - - if (indexOfView === -1) { - var overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, items[_index], _index, itemsLength); - repeat.insertView(_index, overrideContext.bindingContext, overrideContext); - - itemsPreviouslyInViews.splice(_index, 0, undefined); - } else if (indexOfView === _index) { - _view = children[indexOfView]; - itemsPreviouslyInViews[indexOfView] = undefined; - } else { - _view = children[indexOfView]; - repeat.moveView(indexOfView, _index); - itemsPreviouslyInViews.splice(indexOfView, 1); - itemsPreviouslyInViews.splice(_index, 0, undefined); - } - - if (_view) { - (0, _repeatUtilities.updateOverrideContext)(_view.overrideContext, _index, itemsLength); - } - } - - _this._inPlaceProcessItems(repeat, items); - }; - } else { - removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - updateViews = function updateViews() { - return _this._standardProcessInstanceChanged(repeat, items); - }; - } - - if (removePromise instanceof Promise) { - removePromise.then(updateViews); - } else { - updateViews(); - } - } else { - this._inPlaceProcessItems(repeat, items); - } - }; - - ArrayRepeatStrategy.prototype._standardProcessInstanceChanged = function _standardProcessInstanceChanged(repeat, items) { - for (var i = 0, ii = items.length; i < ii; i++) { - var overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, items[i], i, ii); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - }; - - ArrayRepeatStrategy.prototype._inPlaceProcessItems = function _inPlaceProcessItems(repeat, items) { - var itemsLength = items.length; - var viewsLength = repeat.viewCount(); - - while (viewsLength > itemsLength) { - viewsLength--; - repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle); - } - - var local = repeat.local; - - for (var i = 0; i < viewsLength; i++) { - var view = repeat.view(i); - var last = i === itemsLength - 1; - var middle = i !== 0 && !last; - - if (view.bindingContext[local] === items[i] && view.overrideContext.$middle === middle && view.overrideContext.$last === last) { - continue; - } - - view.bindingContext[local] = items[i]; - view.overrideContext.$middle = middle; - view.overrideContext.$last = last; - repeat.updateBindings(view); - } - - for (var _i = viewsLength; _i < itemsLength; _i++) { - var overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, items[_i], _i, itemsLength); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - }; - - ArrayRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, array, splices) { - var _this2 = this; - - if (repeat.__queuedSplices) { - for (var i = 0, ii = splices.length; i < ii; ++i) { - var _splices$i = splices[i], - index = _splices$i.index, - removed = _splices$i.removed, - addedCount = _splices$i.addedCount; - - (0, _aureliaBinding.mergeSplice)(repeat.__queuedSplices, index, removed, addedCount); - } - - repeat.__array = array.slice(0); - return; - } - - var maybePromise = this._runSplices(repeat, array.slice(0), splices); - if (maybePromise instanceof Promise) { - var queuedSplices = repeat.__queuedSplices = []; - - var runQueuedSplices = function runQueuedSplices() { - if (!queuedSplices.length) { - repeat.__queuedSplices = undefined; - repeat.__array = undefined; - return; - } - - var nextPromise = _this2._runSplices(repeat, repeat.__array, queuedSplices) || Promise.resolve(); - queuedSplices = repeat.__queuedSplices = []; - nextPromise.then(runQueuedSplices); - }; - - maybePromise.then(runQueuedSplices); - } - }; - - ArrayRepeatStrategy.prototype._runSplices = function _runSplices(repeat, array, splices) { - var _this3 = this; - - var removeDelta = 0; - var rmPromises = []; - - for (var i = 0, ii = splices.length; i < ii; ++i) { - var splice = splices[i]; - var removed = splice.removed; - - for (var j = 0, jj = removed.length; j < jj; ++j) { - var viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - } - removeDelta -= splice.addedCount; - } - - if (rmPromises.length > 0) { - return Promise.all(rmPromises).then(function () { - var spliceIndexLow = _this3._handleAddedSplices(repeat, array, splices); - (0, _repeatUtilities.updateOverrideContexts)(repeat.views(), spliceIndexLow); - }); - } - - var spliceIndexLow = this._handleAddedSplices(repeat, array, splices); - (0, _repeatUtilities.updateOverrideContexts)(repeat.views(), spliceIndexLow); - - return undefined; - }; - - ArrayRepeatStrategy.prototype._handleAddedSplices = function _handleAddedSplices(repeat, array, splices) { - var spliceIndex = void 0; - var spliceIndexLow = void 0; - var arrayLength = array.length; - for (var i = 0, ii = splices.length; i < ii; ++i) { - var splice = splices[i]; - var addIndex = spliceIndex = splice.index; - var end = splice.index + splice.addedCount; - - if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) { - spliceIndexLow = spliceIndex; - } - - for (; addIndex < end; ++addIndex) { - var overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, array[addIndex], addIndex, arrayLength); - repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext); - } - } - - return spliceIndexLow; - }; - - return ArrayRepeatStrategy; -}(); \ No newline at end of file diff --git a/dist/commonjs/attr-binding-behavior.js b/dist/commonjs/attr-binding-behavior.js deleted file mode 100644 index 5c8fc03..0000000 --- a/dist/commonjs/attr-binding-behavior.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.AttrBindingBehavior = undefined; - -var _dec, _class; - -var _aureliaBinding = require('aurelia-binding'); - - - -var AttrBindingBehavior = exports.AttrBindingBehavior = (_dec = (0, _aureliaBinding.bindingBehavior)('attr'), _dec(_class = function () { - function AttrBindingBehavior() { - - } - - AttrBindingBehavior.prototype.bind = function bind(binding, source) { - binding.targetObserver = new _aureliaBinding.DataAttributeObserver(binding.target, binding.targetProperty); - }; - - AttrBindingBehavior.prototype.unbind = function unbind(binding, source) {}; - - return AttrBindingBehavior; -}()) || _class); \ No newline at end of file diff --git a/dist/commonjs/aurelia-hide-style.js b/dist/commonjs/aurelia-hide-style.js deleted file mode 100644 index ce171bf..0000000 --- a/dist/commonjs/aurelia-hide-style.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.aureliaHideClassName = undefined; -exports.injectAureliaHideStyleAtHead = injectAureliaHideStyleAtHead; -exports.injectAureliaHideStyleAtBoundary = injectAureliaHideStyleAtBoundary; - -var _aureliaPal = require('aurelia-pal'); - -var aureliaHideClassName = exports.aureliaHideClassName = 'aurelia-hide'; - -var aureliaHideClass = '.' + aureliaHideClassName + ' { display:none !important; }'; - -function injectAureliaHideStyleAtHead() { - _aureliaPal.DOM.injectStyles(aureliaHideClass); -} - -function injectAureliaHideStyleAtBoundary(domBoundary) { - if (_aureliaPal.FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) { - domBoundary.hasAureliaHideStyle = true; - _aureliaPal.DOM.injectStyles(aureliaHideClass, domBoundary); - } -} \ No newline at end of file diff --git a/dist/commonjs/aurelia-templating-resources.js b/dist/commonjs/aurelia-templating-resources.js index df98351..ae21a8e 100644 --- a/dist/commonjs/aurelia-templating-resources.js +++ b/dist/commonjs/aurelia-templating-resources.js @@ -1,129 +1,1923 @@ 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.viewsRequireLifecycle = exports.unwrapExpression = exports.updateOneTimeBinding = exports.isOneTime = exports.getItemsSourceExpression = exports.updateOverrideContext = exports.createFullOverrideContext = exports.NumberRepeatStrategy = exports.SetRepeatStrategy = exports.MapRepeatStrategy = exports.ArrayRepeatStrategy = exports.NullRepeatStrategy = exports.RepeatStrategyLocator = exports.AbstractRepeater = exports.UpdateTriggerBindingBehavior = exports.BindingSignaler = exports.SignalBindingBehavior = exports.SelfBindingBehavior = exports.DebounceBindingBehavior = exports.ThrottleBindingBehavior = exports.TwoWayBindingBehavior = exports.FromViewBindingBehavior = exports.ToViewBindingBehavior = exports.OneWayBindingBehavior = exports.OneTimeBindingBehavior = exports.AttrBindingBehavior = exports.configure = exports.Focus = exports.Replaceable = exports.SanitizeHTMLValueConverter = exports.HTMLSanitizer = exports.Hide = exports.Show = exports.Repeat = exports.With = exports.Else = exports.If = exports.Compose = undefined; +Object.defineProperty(exports, '__esModule', { value: true }); -var _compose = require('./compose'); +var aureliaDependencyInjection = require('aurelia-dependency-injection'); +var aureliaPal = require('aurelia-pal'); +var aureliaTaskQueue = require('aurelia-task-queue'); +var aureliaTemplating = require('aurelia-templating'); +var aureliaBinding = require('aurelia-binding'); +var aureliaLogging = require('aurelia-logging'); +var aureliaLoader = require('aurelia-loader'); +var aureliaPath = require('aurelia-path'); +var aureliaMetadata = require('aurelia-metadata'); -var _if = require('./if'); - -var _else = require('./else'); +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ +/* global Reflect, Promise */ + +var extendStatics = function(d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); +}; + +function __extends(d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +} + +function __decorate(decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +} -var _with = require('./with'); +var Compose = (function () { + function Compose(element, container, compositionEngine, viewSlot, viewResources, taskQueue) { + this.element = element; + this.container = container; + this.compositionEngine = compositionEngine; + this.viewSlot = viewSlot; + this.viewResources = viewResources; + this.taskQueue = taskQueue; + this.currentController = null; + this.currentViewModel = null; + this.changes = Object.create(null); + } + Compose.inject = function () { + return [aureliaPal.DOM.Element, aureliaDependencyInjection.Container, aureliaTemplating.CompositionEngine, aureliaTemplating.ViewSlot, aureliaTemplating.ViewResources, aureliaTaskQueue.TaskQueue]; + }; + Compose.prototype.created = function (owningView) { + this.owningView = owningView; + }; + Compose.prototype.bind = function (bindingContext, overrideContext) { + this.bindingContext = bindingContext; + this.overrideContext = overrideContext; + var changes = this.changes; + changes.view = this.view; + changes.viewModel = this.viewModel; + changes.model = this.model; + if (!this.pendingTask) { + processChanges(this); + } + }; + Compose.prototype.unbind = function () { + this.changes = Object.create(null); + this.bindingContext = null; + this.overrideContext = null; + var returnToCache = true; + var skipAnimation = true; + this.viewSlot.removeAll(returnToCache, skipAnimation); + }; + Compose.prototype.modelChanged = function (newValue, oldValue) { + this.changes.model = newValue; + requestUpdate(this); + }; + Compose.prototype.viewChanged = function (newValue, oldValue) { + this.changes.view = newValue; + requestUpdate(this); + }; + Compose.prototype.viewModelChanged = function (newValue, oldValue) { + this.changes.viewModel = newValue; + requestUpdate(this); + }; + __decorate([ + aureliaTemplating.bindable + ], Compose.prototype, "model", void 0); + __decorate([ + aureliaTemplating.bindable + ], Compose.prototype, "view", void 0); + __decorate([ + aureliaTemplating.bindable + ], Compose.prototype, "viewModel", void 0); + __decorate([ + aureliaTemplating.bindable + ], Compose.prototype, "swapOrder", void 0); + Compose = __decorate([ + aureliaTemplating.noView, + aureliaTemplating.customElement('compose') + ], Compose); + return Compose; +}()); +function isEmpty(obj) { + for (var _ in obj) { + return false; + } + return true; +} +function tryActivateViewModel(vm, model) { + if (vm && typeof vm.activate === 'function') { + return Promise.resolve(vm.activate(model)); + } +} +function createInstruction(composer, instruction) { + return Object.assign(instruction, { + bindingContext: composer.bindingContext, + overrideContext: composer.overrideContext, + owningView: composer.owningView, + container: composer.container, + viewSlot: composer.viewSlot, + viewResources: composer.viewResources, + currentController: composer.currentController, + host: composer.element, + swapOrder: composer.swapOrder + }); +} +function processChanges(composer) { + var changes = composer.changes; + composer.changes = Object.create(null); + if (!('view' in changes) && !('viewModel' in changes) && ('model' in changes)) { + composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model); + if (!composer.pendingTask) { + return; + } + } + else { + var instruction = { + view: composer.view, + viewModel: composer.currentViewModel || composer.viewModel, + model: composer.model + }; + instruction = Object.assign(instruction, changes); + instruction = createInstruction(composer, instruction); + composer.pendingTask = composer.compositionEngine.compose(instruction).then(function (controller) { + composer.currentController = controller; + composer.currentViewModel = controller ? controller.viewModel : null; + }); + } + composer.pendingTask = composer.pendingTask + .then(function () { + completeCompositionTask(composer); + }, function (reason) { + completeCompositionTask(composer); + throw reason; + }); +} +function completeCompositionTask(composer) { + composer.pendingTask = null; + if (!isEmpty(composer.changes)) { + processChanges(composer); + } +} +function requestUpdate(composer) { + if (composer.pendingTask || composer.updateRequested) { + return; + } + composer.updateRequested = true; + composer.taskQueue.queueMicroTask(function () { + composer.updateRequested = false; + processChanges(composer); + }); +} -var _repeat = require('./repeat'); +var IfCore = (function () { + function IfCore(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.view = null; + this.bindingContext = null; + this.overrideContext = null; + this.showing = false; + this.cache = true; + } + IfCore.prototype.bind = function (bindingContext, overrideContext) { + this.bindingContext = bindingContext; + this.overrideContext = overrideContext; + }; + IfCore.prototype.unbind = function () { + if (this.view === null) { + return; + } + this.view.unbind(); + if (!this.viewFactory.isCaching) { + return; + } + if (this.showing) { + this.showing = false; + this.viewSlot.remove(this.view, true, true); + } + else { + this.view.returnToCache(); + } + this.view = null; + }; + IfCore.prototype._show = function () { + if (this.showing) { + if (!this.view.isBound) { + this.view.bind(this.bindingContext, this.overrideContext); + } + return; + } + if (this.view === null) { + this.view = this.viewFactory.create(); + } + if (!this.view.isBound) { + this.view.bind(this.bindingContext, this.overrideContext); + } + this.showing = true; + return this.viewSlot.add(this.view); + }; + IfCore.prototype._hide = function () { + var _this = this; + if (!this.showing) { + return; + } + this.showing = false; + var removed = this.viewSlot.remove(this.view); + if (removed instanceof Promise) { + return removed.then(function () { + _this._unbindView(); + }); + } + this._unbindView(); + }; + IfCore.prototype._unbindView = function () { + var cache = this.cache === 'false' ? false : !!this.cache; + this.view.unbind(); + if (!cache) { + this.view = null; + } + }; + return IfCore; +}()); -var _show = require('./show'); +var If = (function (_super) { + __extends(If, _super); + function If() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.cache = true; + return _this; + } + If.prototype.bind = function (bindingContext, overrideContext) { + _super.prototype.bind.call(this, bindingContext, overrideContext); + if (this.condition) { + this._show(); + } + else { + this._hide(); + } + }; + If.prototype.conditionChanged = function (newValue) { + this._update(newValue); + }; + If.prototype._update = function (show) { + var _this = this; + if (this.animating) { + return; + } + var promise; + if (this.elseVm) { + promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm); + } + else { + promise = show ? this._show() : this._hide(); + } + if (promise) { + this.animating = true; + promise.then(function () { + _this.animating = false; + if (_this.condition !== _this.showing) { + _this._update(_this.condition); + } + }); + } + }; + If.prototype._swap = function (remove, add) { + switch (this.swapOrder) { + case 'before': + return Promise.resolve(add._show()).then(function () { return remove._hide(); }); + case 'with': + return Promise.all([remove._hide(), add._show()]); + default: + var promise = remove._hide(); + return promise ? promise.then(function () { return add._show(); }) : add._show(); + } + }; + __decorate([ + aureliaTemplating.bindable({ primaryProperty: true }) + ], If.prototype, "condition", void 0); + __decorate([ + aureliaTemplating.bindable + ], If.prototype, "swapOrder", void 0); + __decorate([ + aureliaTemplating.bindable + ], If.prototype, "cache", void 0); + If = __decorate([ + aureliaTemplating.customAttribute('if'), + aureliaTemplating.templateController, + aureliaDependencyInjection.inject(aureliaTemplating.BoundViewFactory, aureliaTemplating.ViewSlot) + ], If); + return If; +}(IfCore)); -var _hide = require('./hide'); +var Else = (function (_super) { + __extends(Else, _super); + function Else(viewFactory, viewSlot) { + var _this = _super.call(this, viewFactory, viewSlot) || this; + _this._registerInIf(); + return _this; + } + Else.prototype.bind = function (bindingContext, overrideContext) { + _super.prototype.bind.call(this, bindingContext, overrideContext); + if (this.ifVm.condition) { + this._hide(); + } + else { + this._show(); + } + }; + Else.prototype._registerInIf = function () { + var previous = this.viewSlot.anchor.previousSibling; + while (previous && !previous.au) { + previous = previous.previousSibling; + } + if (!previous || !previous.au.if) { + throw new Error("Can't find matching If for Else custom attribute."); + } + this.ifVm = previous.au.if.viewModel; + this.ifVm.elseVm = this; + }; + Else = __decorate([ + aureliaTemplating.customAttribute('else'), + aureliaTemplating.templateController, + aureliaDependencyInjection.inject(aureliaTemplating.BoundViewFactory, aureliaTemplating.ViewSlot) + ], Else); + return Else; +}(IfCore)); -var _sanitizeHtml = require('./sanitize-html'); +var With = (function () { + function With(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.parentOverrideContext = null; + this.view = null; + } + With.prototype.bind = function (bindingContext, overrideContext) { + this.parentOverrideContext = overrideContext; + this.valueChanged(this.value); + }; + With.prototype.valueChanged = function (newValue) { + var overrideContext = aureliaBinding.createOverrideContext(newValue, this.parentOverrideContext); + var view = this.view; + if (!view) { + view = this.view = this.viewFactory.create(); + view.bind(newValue, overrideContext); + this.viewSlot.add(view); + } + else { + view.bind(newValue, overrideContext); + } + }; + With.prototype.unbind = function () { + var view = this.view; + this.parentOverrideContext = null; + if (view) { + view.unbind(); + } + }; + With = __decorate([ + aureliaTemplating.customAttribute('with'), + aureliaTemplating.templateController, + aureliaDependencyInjection.inject(aureliaTemplating.BoundViewFactory, aureliaTemplating.ViewSlot) + ], With); + return With; +}()); -var _replaceable = require('./replaceable'); +var oneTime = aureliaBinding.bindingMode.oneTime; +function updateOverrideContexts(views, startIndex) { + var length = views.length; + if (startIndex > 0) { + startIndex = startIndex - 1; + } + for (; startIndex < length; ++startIndex) { + updateOverrideContext(views[startIndex].overrideContext, startIndex, length); + } +} +function createFullOverrideContext(repeat, data, index, length, key) { + var bindingContext = {}; + var overrideContext = aureliaBinding.createOverrideContext(bindingContext, repeat.scope.overrideContext); + if (typeof key !== 'undefined') { + bindingContext[repeat.key] = key; + bindingContext[repeat.value] = data; + } + else { + bindingContext[repeat.local] = data; + } + updateOverrideContext(overrideContext, index, length); + return overrideContext; +} +function updateOverrideContext(overrideContext, index, length) { + var first = (index === 0); + var last = (index === length - 1); + var even = index % 2 === 0; + overrideContext.$index = index; + overrideContext.$first = first; + overrideContext.$last = last; + overrideContext.$middle = !(first || last); + overrideContext.$odd = !even; + overrideContext.$even = even; +} +function getItemsSourceExpression(instruction, attrName) { + return instruction.behaviorInstructions + .filter(function (bi) { return bi.originalAttrName === attrName; })[0] + .attributes + .items + .sourceExpression; +} +function unwrapExpression(expression) { + var unwrapped = false; + while (expression instanceof aureliaBinding.BindingBehavior) { + expression = expression.expression; + } + while (expression instanceof aureliaBinding.ValueConverter) { + expression = expression.expression; + unwrapped = true; + } + return unwrapped ? expression : null; +} +function isOneTime(expression) { + while (expression instanceof aureliaBinding.BindingBehavior) { + if (expression.name === 'oneTime') { + return true; + } + expression = expression.expression; + } + return false; +} +function updateOneTimeBinding(binding) { + if (binding.call && binding.mode === oneTime) { + binding.call(aureliaBinding.sourceContext); + } + else if (binding.updateOneTimeBindings) { + binding.updateOneTimeBindings(); + } +} +function indexOf(array, item, matcher, startIndex) { + if (!matcher) { + return array.indexOf(item); + } + var length = array.length; + for (var index = startIndex || 0; index < length; index++) { + if (matcher(array[index], item)) { + return index; + } + } + return -1; +} -var _focus = require('./focus'); +var ArrayRepeatStrategy = (function () { + function ArrayRepeatStrategy() { + } + ArrayRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + return observerLocator.getArrayObserver(items); + }; + ArrayRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + var _this = this; + var itemsLength = items.length; + if (!items || itemsLength === 0) { + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + return; + } + var children = repeat.views(); + var viewsLength = children.length; + if (viewsLength === 0) { + this._standardProcessInstanceChanged(repeat, items); + return; + } + if (repeat.viewsRequireLifecycle) { + var childrenSnapshot = children.slice(0); + var itemNameInBindingContext = repeat.local; + var matcher_1 = repeat.matcher(); + var itemsPreviouslyInViews_1 = []; + var viewsToRemove = []; + for (var index = 0; index < viewsLength; index++) { + var view = childrenSnapshot[index]; + var oldItem = view.bindingContext[itemNameInBindingContext]; + if (indexOf(items, oldItem, matcher_1) === -1) { + viewsToRemove.push(view); + } + else { + itemsPreviouslyInViews_1.push(oldItem); + } + } + var updateViews = void 0; + var removePromise = void 0; + if (itemsPreviouslyInViews_1.length > 0) { + removePromise = repeat.removeViews(viewsToRemove, true, !repeat.viewsRequireLifecycle); + updateViews = function () { + for (var index = 0; index < itemsLength; index++) { + var item = items[index]; + var indexOfView = indexOf(itemsPreviouslyInViews_1, item, matcher_1, index); + var view = void 0; + if (indexOfView === -1) { + var overrideContext = createFullOverrideContext(repeat, items[index], index, itemsLength); + repeat.insertView(index, overrideContext.bindingContext, overrideContext); + itemsPreviouslyInViews_1.splice(index, 0, undefined); + } + else if (indexOfView === index) { + view = children[indexOfView]; + itemsPreviouslyInViews_1[indexOfView] = undefined; + } + else { + view = children[indexOfView]; + repeat.moveView(indexOfView, index); + itemsPreviouslyInViews_1.splice(indexOfView, 1); + itemsPreviouslyInViews_1.splice(index, 0, undefined); + } + if (view) { + updateOverrideContext(view.overrideContext, index, itemsLength); + } + } + _this._inPlaceProcessItems(repeat, items); + }; + } + else { + removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + updateViews = function () { return _this._standardProcessInstanceChanged(repeat, items); }; + } + if (removePromise instanceof Promise) { + removePromise.then(updateViews); + } + else { + updateViews(); + } + } + else { + this._inPlaceProcessItems(repeat, items); + } + }; + ArrayRepeatStrategy.prototype._standardProcessInstanceChanged = function (repeat, items) { + for (var i = 0, ii = items.length; i < ii; i++) { + var overrideContext = createFullOverrideContext(repeat, items[i], i, ii); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + }; + ArrayRepeatStrategy.prototype._inPlaceProcessItems = function (repeat, items) { + var itemsLength = items.length; + var viewsLength = repeat.viewCount(); + while (viewsLength > itemsLength) { + viewsLength--; + repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle); + } + var local = repeat.local; + for (var i = 0; i < viewsLength; i++) { + var view = repeat.view(i); + var last = i === itemsLength - 1; + var middle = i !== 0 && !last; + var bindingContext = view.bindingContext; + var overrideContext = view.overrideContext; + if (bindingContext[local] === items[i] + && overrideContext.$middle === middle + && overrideContext.$last === last) { + continue; + } + bindingContext[local] = items[i]; + overrideContext.$middle = middle; + overrideContext.$last = last; + repeat.updateBindings(view); + } + for (var i = viewsLength; i < itemsLength; i++) { + var overrideContext = createFullOverrideContext(repeat, items[i], i, itemsLength); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + }; + ArrayRepeatStrategy.prototype.instanceMutated = function (repeat, array, splices) { + var _this = this; + if (repeat.__queuedSplices) { + for (var i = 0, ii = splices.length; i < ii; ++i) { + var _a = splices[i], index = _a.index, removed = _a.removed, addedCount = _a.addedCount; + aureliaBinding.mergeSplice(repeat.__queuedSplices, index, removed, addedCount); + } + repeat.__array = array.slice(0); + return; + } + var maybePromise = this._runSplices(repeat, array.slice(0), splices); + if (maybePromise instanceof Promise) { + var queuedSplices_1 = repeat.__queuedSplices = []; + var runQueuedSplices_1 = function () { + if (!queuedSplices_1.length) { + repeat.__queuedSplices = undefined; + repeat.__array = undefined; + return; + } + var nextPromise = _this._runSplices(repeat, repeat.__array, queuedSplices_1) || Promise.resolve(); + queuedSplices_1 = repeat.__queuedSplices = []; + nextPromise.then(runQueuedSplices_1); + }; + maybePromise.then(runQueuedSplices_1); + } + }; + ArrayRepeatStrategy.prototype._runSplices = function (repeat, array, splices) { + var _this = this; + var removeDelta = 0; + var rmPromises = []; + for (var i = 0, ii = splices.length; i < ii; ++i) { + var splice = splices[i]; + var removed = splice.removed; + for (var j = 0, jj = removed.length; j < jj; ++j) { + var viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + } + removeDelta -= splice.addedCount; + } + if (rmPromises.length > 0) { + return Promise.all(rmPromises).then(function () { + var spliceIndexLow = _this._handleAddedSplices(repeat, array, splices); + updateOverrideContexts(repeat.views(), spliceIndexLow); + }); + } + var spliceIndexLow = this._handleAddedSplices(repeat, array, splices); + updateOverrideContexts(repeat.views(), spliceIndexLow); + return undefined; + }; + ArrayRepeatStrategy.prototype._handleAddedSplices = function (repeat, array, splices) { + var spliceIndex; + var spliceIndexLow; + var arrayLength = array.length; + for (var i = 0, ii = splices.length; i < ii; ++i) { + var splice = splices[i]; + var addIndex = spliceIndex = splice.index; + var end = splice.index + splice.addedCount; + if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) { + spliceIndexLow = spliceIndex; + } + for (; addIndex < end; ++addIndex) { + var overrideContext = createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength); + repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext); + } + } + return spliceIndexLow; + }; + return ArrayRepeatStrategy; +}()); -var _aureliaTemplating = require('aurelia-templating'); +var MapRepeatStrategy = (function () { + function MapRepeatStrategy() { + } + MapRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + return observerLocator.getMapObserver(items); + }; + MapRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + var _this = this; + var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(function () { return _this._standardProcessItems(repeat, items); }); + return; + } + this._standardProcessItems(repeat, items); + }; + MapRepeatStrategy.prototype._standardProcessItems = function (repeat, items) { + var index = 0; + var overrideContext; + items.forEach(function (value, key) { + overrideContext = createFullOverrideContext(repeat, value, index, items.size, key); + repeat.addView(overrideContext.bindingContext, overrideContext); + ++index; + }); + }; + MapRepeatStrategy.prototype.instanceMutated = function (repeat, map, records) { + var key; + var i; + var ii; + var overrideContext; + var removeIndex; + var addIndex; + var record; + var rmPromises = []; + var viewOrPromise; + for (i = 0, ii = records.length; i < ii; ++i) { + record = records[i]; + key = record.key; + switch (record.type) { + case 'update': + removeIndex = this._getViewIndexByKey(repeat, key); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + overrideContext = createFullOverrideContext(repeat, map.get(key), removeIndex, map.size, key); + repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext); + break; + case 'add': + addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1; + overrideContext = createFullOverrideContext(repeat, map.get(key), addIndex, map.size, key); + repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext); + break; + case 'delete': + if (record.oldValue === undefined) { + return; + } + removeIndex = this._getViewIndexByKey(repeat, key); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + break; + case 'clear': + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + break; + default: + continue; + } + } + if (rmPromises.length > 0) { + Promise.all(rmPromises).then(function () { + updateOverrideContexts(repeat.views(), 0); + }); + } + else { + updateOverrideContexts(repeat.views(), 0); + } + }; + MapRepeatStrategy.prototype._getViewIndexByKey = function (repeat, key) { + var i; + var ii; + var child; + for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { + child = repeat.view(i); + if (child.bindingContext[repeat.key] === key) { + return i; + } + } + return undefined; + }; + return MapRepeatStrategy; +}()); -var _cssResource = require('./css-resource'); +var NullRepeatStrategy = (function () { + function NullRepeatStrategy() { + } + NullRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + repeat.removeAllViews(true); + }; + NullRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + }; + return NullRepeatStrategy; +}()); -var _htmlSanitizer = require('./html-sanitizer'); +var NumberRepeatStrategy = (function () { + function NumberRepeatStrategy() { + } + NumberRepeatStrategy.prototype.getCollectionObserver = function () { + return null; + }; + NumberRepeatStrategy.prototype.instanceChanged = function (repeat, value) { + var _this = this; + var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(function () { return _this._standardProcessItems(repeat, value); }); + return; + } + this._standardProcessItems(repeat, value); + }; + NumberRepeatStrategy.prototype._standardProcessItems = function (repeat, value) { + var childrenLength = repeat.viewCount(); + var i; + var ii; + var overrideContext; + var viewsToRemove; + value = Math.floor(value); + viewsToRemove = childrenLength - value; + if (viewsToRemove > 0) { + if (viewsToRemove > childrenLength) { + viewsToRemove = childrenLength; + } + for (i = 0, ii = viewsToRemove; i < ii; ++i) { + repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle); + } + return; + } + for (i = childrenLength, ii = value; i < ii; ++i) { + overrideContext = createFullOverrideContext(repeat, i, i, ii); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + updateOverrideContexts(repeat.views(), 0); + }; + return NumberRepeatStrategy; +}()); -var _attrBindingBehavior = require('./attr-binding-behavior'); +var SetRepeatStrategy = (function () { + function SetRepeatStrategy() { + } + SetRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + return observerLocator.getSetObserver(items); + }; + SetRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + var _this = this; + var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(function () { return _this._standardProcessItems(repeat, items); }); + return; + } + this._standardProcessItems(repeat, items); + }; + SetRepeatStrategy.prototype._standardProcessItems = function (repeat, items) { + var index = 0; + var overrideContext; + items.forEach(function (value) { + overrideContext = createFullOverrideContext(repeat, value, index, items.size); + repeat.addView(overrideContext.bindingContext, overrideContext); + ++index; + }); + }; + SetRepeatStrategy.prototype.instanceMutated = function (repeat, set, records) { + var value; + var i; + var ii; + var overrideContext; + var removeIndex; + var record; + var rmPromises = []; + var viewOrPromise; + for (i = 0, ii = records.length; i < ii; ++i) { + record = records[i]; + value = record.value; + switch (record.type) { + case 'add': + var size = Math.max(set.size - 1, 0); + overrideContext = createFullOverrideContext(repeat, value, size, set.size); + repeat.insertView(size, overrideContext.bindingContext, overrideContext); + break; + case 'delete': + removeIndex = this._getViewIndexByValue(repeat, value); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + break; + case 'clear': + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + break; + default: + continue; + } + } + if (rmPromises.length > 0) { + Promise.all(rmPromises).then(function () { + updateOverrideContexts(repeat.views(), 0); + }); + } + else { + updateOverrideContexts(repeat.views(), 0); + } + }; + SetRepeatStrategy.prototype._getViewIndexByValue = function (repeat, value) { + var i; + var ii; + var child; + for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { + child = repeat.view(i); + if (child.bindingContext[repeat.local] === value) { + return i; + } + } + return undefined; + }; + return SetRepeatStrategy; +}()); -var _bindingModeBehaviors = require('./binding-mode-behaviors'); +var RepeatStrategyLocator = (function () { + function RepeatStrategyLocator() { + this.matchers = []; + this.strategies = []; + this.addStrategy(function (items) { return items === null || items === undefined; }, new NullRepeatStrategy()); + this.addStrategy(function (items) { return items instanceof Array; }, new ArrayRepeatStrategy()); + this.addStrategy(function (items) { return items instanceof Map; }, new MapRepeatStrategy()); + this.addStrategy(function (items) { return items instanceof Set; }, new SetRepeatStrategy()); + this.addStrategy(function (items) { return typeof items === 'number'; }, new NumberRepeatStrategy()); + } + RepeatStrategyLocator.prototype.addStrategy = function (matcher, strategy) { + this.matchers.push(matcher); + this.strategies.push(strategy); + }; + RepeatStrategyLocator.prototype.getStrategy = function (items) { + var matchers = this.matchers; + for (var i = 0, ii = matchers.length; i < ii; ++i) { + if (matchers[i](items)) { + return this.strategies[i]; + } + } + return null; + }; + return RepeatStrategyLocator; +}()); -var _throttleBindingBehavior = require('./throttle-binding-behavior'); +var lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with']; +function behaviorRequiresLifecycle(instruction) { + var t = instruction.type; + var name = t.elementName !== null ? t.elementName : t.attributeName; + return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind) + || t.viewFactory && viewsRequireLifecycle(t.viewFactory) + || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); +} +function targetRequiresLifecycle(instruction) { + var behaviors = instruction.behaviorInstructions; + if (behaviors) { + var i = behaviors.length; + while (i--) { + if (behaviorRequiresLifecycle(behaviors[i])) { + return true; + } + } + } + return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); +} +function viewsRequireLifecycle(viewFactory) { + if ('_viewsRequireLifecycle' in viewFactory) { + return viewFactory._viewsRequireLifecycle; + } + viewFactory._viewsRequireLifecycle = false; + if (viewFactory.viewFactory) { + viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory); + return viewFactory._viewsRequireLifecycle; + } + if (viewFactory.template.querySelector('.au-animate')) { + viewFactory._viewsRequireLifecycle = true; + return true; + } + for (var id in viewFactory.instructions) { + if (targetRequiresLifecycle(viewFactory.instructions[id])) { + viewFactory._viewsRequireLifecycle = true; + return true; + } + } + viewFactory._viewsRequireLifecycle = false; + return false; +} -var _debounceBindingBehavior = require('./debounce-binding-behavior'); +var AbstractRepeater = (function () { + function AbstractRepeater(options) { + Object.assign(this, { + local: 'items', + viewsRequireLifecycle: true + }, options); + } + AbstractRepeater.prototype.viewCount = function () { + throw new Error('subclass must implement `viewCount`'); + }; + AbstractRepeater.prototype.views = function () { + throw new Error('subclass must implement `views`'); + }; + AbstractRepeater.prototype.view = function (index) { + throw new Error('subclass must implement `view`'); + }; + AbstractRepeater.prototype.matcher = function () { + throw new Error('subclass must implement `matcher`'); + }; + AbstractRepeater.prototype.addView = function (bindingContext, overrideContext) { + throw new Error('subclass must implement `addView`'); + }; + AbstractRepeater.prototype.insertView = function (index, bindingContext, overrideContext) { + throw new Error('subclass must implement `insertView`'); + }; + AbstractRepeater.prototype.moveView = function (sourceIndex, targetIndex) { + throw new Error('subclass must implement `moveView`'); + }; + AbstractRepeater.prototype.removeAllViews = function (returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeAllViews`'); + }; + AbstractRepeater.prototype.removeViews = function (viewsToRemove, returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeView`'); + }; + AbstractRepeater.prototype.removeView = function (index, returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeView`'); + }; + AbstractRepeater.prototype.updateBindings = function (view) { + throw new Error('subclass must implement `updateBindings`'); + }; + return AbstractRepeater; +}()); -var _selfBindingBehavior = require('./self-binding-behavior'); +var Repeat = (function (_super) { + __extends(Repeat, _super); + function Repeat(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) { + var _this = _super.call(this, { + local: 'item', + viewsRequireLifecycle: viewsRequireLifecycle(viewFactory) + }) || this; + _this.viewFactory = viewFactory; + _this.instruction = instruction; + _this.viewSlot = viewSlot; + _this.lookupFunctions = viewResources.lookupFunctions; + _this.observerLocator = observerLocator; + _this.key = 'key'; + _this.value = 'value'; + _this.strategyLocator = strategyLocator; + _this.ignoreMutation = false; + _this.sourceExpression = getItemsSourceExpression(_this.instruction, 'repeat.for'); + _this.isOneTime = isOneTime(_this.sourceExpression); + _this.viewsRequireLifecycle = viewsRequireLifecycle(viewFactory); + return _this; + } + Repeat.prototype.call = function (context, changes) { + this[context](this.items, changes); + }; + Repeat.prototype.bind = function (bindingContext, overrideContext) { + this.scope = { bindingContext: bindingContext, overrideContext: overrideContext }; + this.matcherBinding = this._captureAndRemoveMatcherBinding(); + this.itemsChanged(); + }; + Repeat.prototype.unbind = function () { + this.scope = null; + this.items = null; + this.matcherBinding = null; + this.viewSlot.removeAll(true, true); + this._unsubscribeCollection(); + }; + Repeat.prototype._unsubscribeCollection = function () { + if (this.collectionObserver) { + this.collectionObserver.unsubscribe(this.callContext, this); + this.collectionObserver = null; + this.callContext = null; + } + }; + Repeat.prototype.itemsChanged = function () { + var _this = this; + this._unsubscribeCollection(); + if (!this.scope) { + return; + } + var items = this.items; + this.strategy = this.strategyLocator.getStrategy(items); + if (!this.strategy) { + throw new Error("Value for '" + this.sourceExpression + "' is non-repeatable"); + } + if (!this.isOneTime && !this._observeInnerCollection()) { + this._observeCollection(); + } + this.ignoreMutation = true; + this.strategy.instanceChanged(this, items); + this.observerLocator.taskQueue.queueMicroTask(function () { + _this.ignoreMutation = false; + }); + }; + Repeat.prototype._getInnerCollection = function () { + var expression = unwrapExpression(this.sourceExpression); + if (!expression) { + return null; + } + return expression.evaluate(this.scope, null); + }; + Repeat.prototype.handleCollectionMutated = function (collection, changes) { + if (!this.collectionObserver) { + return; + } + if (this.ignoreMutation) { + return; + } + this.strategy.instanceMutated(this, collection, changes); + }; + Repeat.prototype.handleInnerCollectionMutated = function (collection, changes) { + var _this = this; + if (!this.collectionObserver) { + return; + } + if (this.ignoreMutation) { + return; + } + this.ignoreMutation = true; + var newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions); + this.observerLocator.taskQueue.queueMicroTask(function () { return _this.ignoreMutation = false; }); + if (newItems === this.items) { + this.itemsChanged(); + } + else { + this.items = newItems; + } + }; + Repeat.prototype._observeInnerCollection = function () { + var items = this._getInnerCollection(); + var strategy = this.strategyLocator.getStrategy(items); + if (!strategy) { + return false; + } + this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items); + if (!this.collectionObserver) { + return false; + } + this.callContext = 'handleInnerCollectionMutated'; + this.collectionObserver.subscribe(this.callContext, this); + return true; + }; + Repeat.prototype._observeCollection = function () { + var items = this.items; + this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items); + if (this.collectionObserver) { + this.callContext = 'handleCollectionMutated'; + this.collectionObserver.subscribe(this.callContext, this); + } + }; + Repeat.prototype._captureAndRemoveMatcherBinding = function () { + if (this.viewFactory.viewFactory) { + var instructions = this.viewFactory.viewFactory.instructions; + var instructionIds = Object.keys(instructions); + for (var i = 0; i < instructionIds.length; i++) { + var expressions = instructions[instructionIds[i]].expressions; + if (expressions) { + for (var ii = 0; ii < expressions.length; ii++) { + if (expressions[ii].targetProperty === 'matcher') { + var matcherBinding = expressions[ii]; + expressions.splice(ii, 1); + return matcherBinding; + } + } + } + } + } + return undefined; + }; + Repeat.prototype.viewCount = function () { return this.viewSlot.children.length; }; + Repeat.prototype.views = function () { return this.viewSlot.children; }; + Repeat.prototype.view = function (index) { return this.viewSlot.children[index]; }; + Repeat.prototype.matcher = function () { return this.matcherBinding ? this.matcherBinding.sourceExpression.evaluate(this.scope, this.matcherBinding.lookupFunctions) : null; }; + Repeat.prototype.addView = function (bindingContext, overrideContext) { + var view = this.viewFactory.create(); + view.bind(bindingContext, overrideContext); + this.viewSlot.add(view); + }; + Repeat.prototype.insertView = function (index, bindingContext, overrideContext) { + var view = this.viewFactory.create(); + view.bind(bindingContext, overrideContext); + this.viewSlot.insert(index, view); + }; + Repeat.prototype.moveView = function (sourceIndex, targetIndex) { + this.viewSlot.move(sourceIndex, targetIndex); + }; + Repeat.prototype.removeAllViews = function (returnToCache, skipAnimation) { + return this.viewSlot.removeAll(returnToCache, skipAnimation); + }; + Repeat.prototype.removeViews = function (viewsToRemove, returnToCache, skipAnimation) { + return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation); + }; + Repeat.prototype.removeView = function (index, returnToCache, skipAnimation) { + return this.viewSlot.removeAt(index, returnToCache, skipAnimation); + }; + Repeat.prototype.updateBindings = function (view) { + var $view = view; + var j = $view.bindings.length; + while (j--) { + updateOneTimeBinding($view.bindings[j]); + } + j = $view.controllers.length; + while (j--) { + var k = $view.controllers[j].boundProperties.length; + while (k--) { + var binding = $view.controllers[j].boundProperties[k].binding; + updateOneTimeBinding(binding); + } + } + }; + __decorate([ + aureliaTemplating.bindable + ], Repeat.prototype, "items", void 0); + __decorate([ + aureliaTemplating.bindable + ], Repeat.prototype, "local", void 0); + __decorate([ + aureliaTemplating.bindable + ], Repeat.prototype, "key", void 0); + __decorate([ + aureliaTemplating.bindable + ], Repeat.prototype, "value", void 0); + Repeat = __decorate([ + aureliaTemplating.customAttribute('repeat'), + aureliaTemplating.templateController, + aureliaDependencyInjection.inject(aureliaTemplating.BoundViewFactory, aureliaTemplating.TargetInstruction, aureliaTemplating.ViewSlot, aureliaTemplating.ViewResources, aureliaBinding.ObserverLocator, RepeatStrategyLocator) + ], Repeat); + return Repeat; +}(AbstractRepeater)); -var _signalBindingBehavior = require('./signal-binding-behavior'); +var aureliaHideClassName = 'aurelia-hide'; +var aureliaHideClass = "." + aureliaHideClassName + " { display:none !important; }"; +function injectAureliaHideStyleAtHead() { + aureliaPal.DOM.injectStyles(aureliaHideClass); +} +function injectAureliaHideStyleAtBoundary(domBoundary) { + if (aureliaPal.FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) { + domBoundary.hasAureliaHideStyle = true; + aureliaPal.DOM.injectStyles(aureliaHideClass, domBoundary); + } +} -var _bindingSignaler = require('./binding-signaler'); +var Show = (function () { + function Show(element, animator, domBoundary) { + this.element = element; + this.animator = animator; + this.domBoundary = domBoundary; + } + Show.inject = function () { + return [aureliaPal.DOM.Element, aureliaTemplating.Animator, aureliaDependencyInjection.Optional.of(aureliaPal.DOM.boundary, true)]; + }; + Show.prototype.created = function () { + injectAureliaHideStyleAtBoundary(this.domBoundary); + }; + Show.prototype.valueChanged = function (newValue) { + var element = this.element; + var animator = this.animator; + if (newValue) { + animator.removeClass(element, aureliaHideClassName); + } + else { + animator.addClass(element, aureliaHideClassName); + } + }; + Show.prototype.bind = function (bindingContext) { + this.valueChanged(this.value); + }; + Show = __decorate([ + aureliaTemplating.customAttribute('show') + ], Show); + return Show; +}()); -var _updateTriggerBindingBehavior = require('./update-trigger-binding-behavior'); +var Hide = (function () { + function Hide(element, animator, domBoundary) { + this.element = element; + this.animator = animator; + this.domBoundary = domBoundary; + } + Hide.inject = function () { + return [aureliaPal.DOM.Element, aureliaTemplating.Animator, aureliaDependencyInjection.Optional.of(aureliaPal.DOM.boundary, true)]; + }; + Hide.prototype.created = function () { + injectAureliaHideStyleAtBoundary(this.domBoundary); + }; + Hide.prototype.valueChanged = function (newValue) { + if (newValue) { + this.animator.addClass(this.element, aureliaHideClassName); + } + else { + this.animator.removeClass(this.element, aureliaHideClassName); + } + }; + Hide.prototype.bind = function (bindingContext) { + this.valueChanged(this.value); + }; + Hide.prototype.value = function (value) { + throw new Error('Method not implemented.'); + }; + Hide = __decorate([ + aureliaTemplating.customAttribute('hide') + ], Hide); + return Hide; +}()); -var _abstractRepeater = require('./abstract-repeater'); +var SCRIPT_REGEX = /)<[^<]*)*<\/script>/gi; +var needsToWarn = true; +var HTMLSanitizer = (function () { + function HTMLSanitizer() { + } + HTMLSanitizer.prototype.sanitize = function (input) { + if (needsToWarn) { + needsToWarn = false; + aureliaLogging.getLogger('html-sanitizer') + .warn("CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks,\nand should not be relied on for sanitizing input from unknown sources.\nPlease see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html."); + } + return input.replace(SCRIPT_REGEX, ''); + }; + return HTMLSanitizer; +}()); -var _repeatStrategyLocator = require('./repeat-strategy-locator'); +var SanitizeHTMLValueConverter = (function () { + function SanitizeHTMLValueConverter(sanitizer) { + this.sanitizer = sanitizer; + } + SanitizeHTMLValueConverter.prototype.toView = function (untrustedMarkup) { + if (untrustedMarkup === null || untrustedMarkup === undefined) { + return null; + } + return this.sanitizer.sanitize(untrustedMarkup); + }; + SanitizeHTMLValueConverter = __decorate([ + aureliaBinding.valueConverter('sanitizeHTML'), + aureliaDependencyInjection.inject(HTMLSanitizer) + ], SanitizeHTMLValueConverter); + return SanitizeHTMLValueConverter; +}()); -var _htmlResourcePlugin = require('./html-resource-plugin'); +var Replaceable = (function () { + function Replaceable(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.view = null; + } + Replaceable.prototype.bind = function (bindingContext, overrideContext) { + if (this.view === null) { + this.view = this.viewFactory.create(); + this.viewSlot.add(this.view); + } + this.view.bind(bindingContext, overrideContext); + }; + Replaceable.prototype.unbind = function () { + this.view.unbind(); + }; + Replaceable = __decorate([ + aureliaTemplating.customAttribute('replaceable'), + aureliaTemplating.templateController, + aureliaDependencyInjection.inject(aureliaTemplating.BoundViewFactory, aureliaTemplating.ViewSlot) + ], Replaceable); + return Replaceable; +}()); -var _nullRepeatStrategy = require('./null-repeat-strategy'); +var Focus = (function () { + function Focus(element, taskQueue) { + this.element = element; + this.taskQueue = taskQueue; + this.isAttached = false; + this.needsApply = false; + } + Focus.inject = function () { + return [aureliaPal.DOM.Element, aureliaTaskQueue.TaskQueue]; + }; + Focus.prototype.valueChanged = function (newValue) { + if (this.isAttached) { + this._apply(); + } + else { + this.needsApply = true; + } + }; + Focus.prototype._apply = function () { + var _this = this; + if (this.value) { + this.taskQueue.queueMicroTask(function () { + if (_this.value) { + _this.element.focus(); + } + }); + } + else { + this.element.blur(); + } + }; + Focus.prototype.attached = function () { + this.isAttached = true; + if (this.needsApply) { + this.needsApply = false; + this._apply(); + } + this.element.addEventListener('focus', this); + this.element.addEventListener('blur', this); + }; + Focus.prototype.detached = function () { + this.isAttached = false; + this.element.removeEventListener('focus', this); + this.element.removeEventListener('blur', this); + }; + Focus.prototype.handleEvent = function (e) { + if (e.type === 'focus') { + this.value = true; + } + else if (aureliaPal.DOM.activeElement !== this.element) { + this.value = false; + } + }; + Focus = __decorate([ + aureliaTemplating.customAttribute('focus', aureliaBinding.bindingMode.twoWay) + ], Focus); + return Focus; +}()); -var _arrayRepeatStrategy = require('./array-repeat-strategy'); +var cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi; +function fixupCSSUrls(address, css) { + if (typeof css !== 'string') { + throw new Error("Failed loading required CSS file: " + address); + } + return css.replace(cssUrlMatcher, function (match, p1) { + var quote = p1.charAt(0); + if (quote === '\'' || quote === '"') { + p1 = p1.substr(1, p1.length - 2); + } + return 'url(\'' + aureliaPath.relativeToFile(p1, address) + '\')'; + }); +} +var CSSResource = (function () { + function CSSResource(address) { + this.address = address; + this._scoped = null; + this._global = false; + this._alreadyGloballyInjected = false; + } + CSSResource.prototype.initialize = function (container, Target) { + this._scoped = new Target(this); + }; + CSSResource.prototype.register = function (registry, name) { + if (name === 'scoped') { + registry.registerViewEngineHooks(this._scoped); + } + else { + this._global = true; + } + }; + CSSResource.prototype.load = function (container) { + var _this = this; + return container.get(aureliaLoader.Loader) + .loadText(this.address) + .catch(function (err) { return null; }) + .then(function (text) { + text = fixupCSSUrls(_this.address, text); + _this._scoped.css = text; + if (_this._global) { + _this._alreadyGloballyInjected = true; + aureliaPal.DOM.injectStyles(text); + } + }); + }; + return CSSResource; +}()); +var CSSViewEngineHooks = (function () { + function CSSViewEngineHooks(owner) { + this.owner = owner; + this.css = null; + } + CSSViewEngineHooks.prototype.beforeCompile = function (content, resources, instruction) { + if (instruction.targetShadowDOM) { + aureliaPal.DOM.injectStyles(this.css, content, true); + } + else if (aureliaPal.FEATURE.scopedCSS) { + var styleNode = aureliaPal.DOM.injectStyles(this.css, content, true); + styleNode.setAttribute('scoped', 'scoped'); + } + else if (this._global && !this.owner._alreadyGloballyInjected) { + aureliaPal.DOM.injectStyles(this.css); + this.owner._alreadyGloballyInjected = true; + } + }; + return CSSViewEngineHooks; +}()); +function _createCSSResource(address) { + var ViewCSS = (function (_super) { + __extends(ViewCSS, _super); + function ViewCSS() { + return _super !== null && _super.apply(this, arguments) || this; + } + ViewCSS = __decorate([ + aureliaTemplating.resource(new CSSResource(address)) + ], ViewCSS); + return ViewCSS; + }(CSSViewEngineHooks)); + return ViewCSS; +} -var _mapRepeatStrategy = require('./map-repeat-strategy'); +var AttrBindingBehavior = (function () { + function AttrBindingBehavior() { + } + AttrBindingBehavior.prototype.bind = function (binding, source) { + binding.targetObserver = new aureliaBinding.DataAttributeObserver(binding.target, binding.targetProperty); + }; + AttrBindingBehavior.prototype.unbind = function (binding, source) { + }; + AttrBindingBehavior = __decorate([ + aureliaBinding.bindingBehavior('attr') + ], AttrBindingBehavior); + return AttrBindingBehavior; +}()); -var _setRepeatStrategy = require('./set-repeat-strategy'); +var modeBindingBehavior = { + bind: function (binding, source, lookupFunctions) { + binding.originalMode = binding.mode; + binding.mode = this.mode; + }, + unbind: function (binding, source) { + binding.mode = binding.originalMode; + binding.originalMode = null; + } +}; +var OneTimeBindingBehavior = (function () { + function OneTimeBindingBehavior() { + this.mode = aureliaBinding.bindingMode.oneTime; + } + OneTimeBindingBehavior = __decorate([ + aureliaMetadata.mixin(modeBindingBehavior), + aureliaBinding.bindingBehavior('oneTime') + ], OneTimeBindingBehavior); + return OneTimeBindingBehavior; +}()); +var OneWayBindingBehavior = (function () { + function OneWayBindingBehavior() { + this.mode = aureliaBinding.bindingMode.toView; + } + OneWayBindingBehavior = __decorate([ + aureliaMetadata.mixin(modeBindingBehavior), + aureliaBinding.bindingBehavior('oneWay') + ], OneWayBindingBehavior); + return OneWayBindingBehavior; +}()); +var ToViewBindingBehavior = (function () { + function ToViewBindingBehavior() { + this.mode = aureliaBinding.bindingMode.toView; + } + ToViewBindingBehavior = __decorate([ + aureliaMetadata.mixin(modeBindingBehavior), + aureliaBinding.bindingBehavior('toView') + ], ToViewBindingBehavior); + return ToViewBindingBehavior; +}()); +var FromViewBindingBehavior = (function () { + function FromViewBindingBehavior() { + this.mode = aureliaBinding.bindingMode.fromView; + } + FromViewBindingBehavior = __decorate([ + aureliaMetadata.mixin(modeBindingBehavior), + aureliaBinding.bindingBehavior('fromView') + ], FromViewBindingBehavior); + return FromViewBindingBehavior; +}()); +var TwoWayBindingBehavior = (function () { + function TwoWayBindingBehavior() { + this.mode = aureliaBinding.bindingMode.twoWay; + } + TwoWayBindingBehavior = __decorate([ + aureliaMetadata.mixin(modeBindingBehavior), + aureliaBinding.bindingBehavior('twoWay') + ], TwoWayBindingBehavior); + return TwoWayBindingBehavior; +}()); -var _numberRepeatStrategy = require('./number-repeat-strategy'); +function throttle(newValue) { + var _this = this; + var state = this.throttleState; + var elapsed = +new Date() - state.last; + if (elapsed >= state.delay) { + clearTimeout(state.timeoutId); + state.timeoutId = null; + state.last = +new Date(); + this.throttledMethod(newValue); + return; + } + state.newValue = newValue; + if (state.timeoutId === null) { + state.timeoutId = setTimeout(function () { + state.timeoutId = null; + state.last = +new Date(); + _this.throttledMethod(state.newValue); + }, state.delay - elapsed); + } +} +var ThrottleBindingBehavior = (function () { + function ThrottleBindingBehavior() { + } + ThrottleBindingBehavior.prototype.bind = function (binding, source, delay) { + if (delay === void 0) { delay = 200; } + var methodToThrottle = 'updateTarget'; + if (binding.callSource) { + methodToThrottle = 'callSource'; + } + else if (binding.updateSource && binding.mode === aureliaBinding.bindingMode.twoWay) { + methodToThrottle = 'updateSource'; + } + binding.throttledMethod = binding[methodToThrottle]; + binding.throttledMethod.originalName = methodToThrottle; + binding[methodToThrottle] = throttle; + binding.throttleState = { + delay: delay, + last: 0, + timeoutId: null + }; + }; + ThrottleBindingBehavior.prototype.unbind = function (binding, source) { + var methodToRestore = binding.throttledMethod.originalName; + binding[methodToRestore] = binding.throttledMethod; + binding.throttledMethod = null; + clearTimeout(binding.throttleState.timeoutId); + binding.throttleState = null; + }; + ThrottleBindingBehavior = __decorate([ + aureliaBinding.bindingBehavior('throttle') + ], ThrottleBindingBehavior); + return ThrottleBindingBehavior; +}()); -var _repeatUtilities = require('./repeat-utilities'); +var unset = {}; +function debounceCallSource(event) { + var _this = this; + var state = this.debounceState; + clearTimeout(state.timeoutId); + state.timeoutId = setTimeout(function () { return _this.debouncedMethod(event); }, state.delay); +} +function debounceCall(context, newValue, oldValue) { + var _this = this; + var state = this.debounceState; + clearTimeout(state.timeoutId); + if (context !== state.callContextToDebounce) { + state.oldValue = unset; + this.debouncedMethod(context, newValue, oldValue); + return; + } + if (state.oldValue === unset) { + state.oldValue = oldValue; + } + state.timeoutId = setTimeout(function () { + var _oldValue = state.oldValue; + state.oldValue = unset; + _this.debouncedMethod(context, newValue, _oldValue); + }, state.delay); +} +var DebounceBindingBehavior = (function () { + function DebounceBindingBehavior() { + } + DebounceBindingBehavior.prototype.bind = function (binding, source, delay) { + if (delay === void 0) { delay = 200; } + var isCallSource = binding.callSource !== undefined; + var methodToDebounce = isCallSource ? 'callSource' : 'call'; + var debouncer = isCallSource ? debounceCallSource : debounceCall; + var mode = binding.mode; + var callContextToDebounce = mode === aureliaBinding.bindingMode.twoWay || mode === aureliaBinding.bindingMode.fromView ? aureliaBinding.targetContext : aureliaBinding.sourceContext; + binding.debouncedMethod = binding[methodToDebounce]; + binding.debouncedMethod.originalName = methodToDebounce; + binding[methodToDebounce] = debouncer; + binding.debounceState = { + callContextToDebounce: callContextToDebounce, + delay: delay, + timeoutId: 0, + oldValue: unset + }; + }; + DebounceBindingBehavior.prototype.unbind = function (binding, source) { + var methodToRestore = binding.debouncedMethod.originalName; + binding[methodToRestore] = binding.debouncedMethod; + binding.debouncedMethod = null; + clearTimeout(binding.debounceState.timeoutId); + binding.debounceState = null; + }; + DebounceBindingBehavior = __decorate([ + aureliaBinding.bindingBehavior('debounce') + ], DebounceBindingBehavior); + return DebounceBindingBehavior; +}()); -var _analyzeViewFactory = require('./analyze-view-factory'); +function findOriginalEventTarget(event) { + return (event.path && event.path[0]) || (event.deepPath && event.deepPath[0]) || event.target; +} +function handleSelfEvent(event) { + var target = findOriginalEventTarget(event); + if (this.target !== target) { + return; + } + this.selfEventCallSource(event); +} +var SelfBindingBehavior = (function () { + function SelfBindingBehavior() { + } + SelfBindingBehavior.prototype.bind = function (binding, source) { + if (!binding.callSource || !binding.targetEvent) { + throw new Error('Self binding behavior only supports event.'); + } + binding.selfEventCallSource = binding.callSource; + binding.callSource = handleSelfEvent; + }; + SelfBindingBehavior.prototype.unbind = function (binding, source) { + binding.callSource = binding.selfEventCallSource; + binding.selfEventCallSource = null; + }; + SelfBindingBehavior = __decorate([ + aureliaBinding.bindingBehavior('self') + ], SelfBindingBehavior); + return SelfBindingBehavior; +}()); -var _aureliaHideStyle = require('./aurelia-hide-style'); +var BindingSignaler = (function () { + function BindingSignaler() { + this.signals = {}; + } + BindingSignaler.prototype.signal = function (name) { + var bindings = this.signals[name]; + if (!bindings) { + return; + } + var i = bindings.length; + while (i--) { + bindings[i].call(aureliaBinding.sourceContext); + } + }; + return BindingSignaler; +}()); -function configure(config) { - (0, _aureliaHideStyle.injectAureliaHideStyleAtHead)(); +var SignalBindingBehavior = (function () { + function SignalBindingBehavior(bindingSignaler) { + this.signals = bindingSignaler.signals; + } + SignalBindingBehavior.inject = function () { return [BindingSignaler]; }; + SignalBindingBehavior.prototype.bind = function (binding, source) { + var names = []; + for (var _i = 2; _i < arguments.length; _i++) { + names[_i - 2] = arguments[_i]; + } + if (!binding.updateTarget) { + throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.'); + } + var signals = this.signals; + if (names.length === 1) { + var name_1 = names[0]; + var bindings = signals[name_1] || (signals[name_1] = []); + bindings.push(binding); + binding.signalName = name_1; + } + else if (names.length > 1) { + var i = names.length; + while (i--) { + var name_2 = names[i]; + var bindings = signals[name_2] || (signals[name_2] = []); + bindings.push(binding); + } + binding.signalName = names; + } + else { + throw new Error('Signal name is required.'); + } + }; + SignalBindingBehavior.prototype.unbind = function (binding, source) { + var signals = this.signals; + var name = binding.signalName; + binding.signalName = null; + if (Array.isArray(name)) { + var names = name; + var i = names.length; + while (i--) { + var n = names[i]; + var bindings = signals[n]; + bindings.splice(bindings.indexOf(binding), 1); + } + } + else { + var bindings = signals[name]; + bindings.splice(bindings.indexOf(binding), 1); + } + }; + SignalBindingBehavior = __decorate([ + aureliaBinding.bindingBehavior('signal') + ], SignalBindingBehavior); + return SignalBindingBehavior; +}()); - config.globalResources(_compose.Compose, _if.If, _else.Else, _with.With, _repeat.Repeat, _show.Show, _hide.Hide, _replaceable.Replaceable, _focus.Focus, _sanitizeHtml.SanitizeHTMLValueConverter, _bindingModeBehaviors.OneTimeBindingBehavior, _bindingModeBehaviors.OneWayBindingBehavior, _bindingModeBehaviors.ToViewBindingBehavior, _bindingModeBehaviors.FromViewBindingBehavior, _bindingModeBehaviors.TwoWayBindingBehavior, _throttleBindingBehavior.ThrottleBindingBehavior, _debounceBindingBehavior.DebounceBindingBehavior, _selfBindingBehavior.SelfBindingBehavior, _signalBindingBehavior.SignalBindingBehavior, _updateTriggerBindingBehavior.UpdateTriggerBindingBehavior, _attrBindingBehavior.AttrBindingBehavior); +var eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg '; +var notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.'; +var UpdateTriggerBindingBehavior = (function () { + function UpdateTriggerBindingBehavior() { + } + UpdateTriggerBindingBehavior.prototype.bind = function (binding, source) { + var events = []; + for (var _i = 2; _i < arguments.length; _i++) { + events[_i - 2] = arguments[_i]; + } + if (events.length === 0) { + throw new Error(eventNamesRequired); + } + if (binding.mode !== aureliaBinding.bindingMode.twoWay && binding.mode !== aureliaBinding.bindingMode.fromView) { + throw new Error(notApplicableMessage); + } + var targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty); + if (!targetObserver.handler) { + throw new Error(notApplicableMessage); + } + binding.targetObserver = targetObserver; + targetObserver.originalHandler = binding.targetObserver.handler; + var handler = new aureliaBinding.EventSubscriber(events); + targetObserver.handler = handler; + }; + UpdateTriggerBindingBehavior.prototype.unbind = function (binding, source) { + var targetObserver = binding.targetObserver; + targetObserver.handler.dispose(); + targetObserver.handler = targetObserver.originalHandler; + targetObserver.originalHandler = null; + }; + UpdateTriggerBindingBehavior = __decorate([ + aureliaBinding.bindingBehavior('updateTrigger') + ], UpdateTriggerBindingBehavior); + return UpdateTriggerBindingBehavior; +}()); - (0, _htmlResourcePlugin.configure)(config); +function _createDynamicElement(_a) { + var name = _a.name, viewUrl = _a.viewUrl, bindableNames = _a.bindableNames, useShadowDOMmode = _a.useShadowDOMmode; + var DynamicElement = (function () { + function DynamicElement() { + } + DynamicElement.prototype.bind = function (bindingContext) { + this.$parent = bindingContext; + }; + DynamicElement = __decorate([ + aureliaTemplating.customElement(name), + aureliaTemplating.useView(viewUrl) + ], DynamicElement); + return DynamicElement; + }()); + for (var i = 0, ii = bindableNames.length; i < ii; ++i) { + aureliaTemplating.bindable(bindableNames[i])(DynamicElement); + } + switch (useShadowDOMmode) { + case 'open': + aureliaTemplating.useShadowDOM({ mode: 'open' })(DynamicElement); + break; + case 'closed': + aureliaTemplating.useShadowDOM({ mode: 'closed' })(DynamicElement); + break; + case '': + aureliaTemplating.useShadowDOM(DynamicElement); + break; + case null: + break; + default: + aureliaLogging.getLogger('aurelia-html-only-element') + .warn("Expected 'use-shadow-dom' value to be \"close\", \"open\" or \"\", received " + useShadowDOMmode); + break; + } + return DynamicElement; +} - var viewEngine = config.container.get(_aureliaTemplating.ViewEngine); - var styleResourcePlugin = { - fetch: function fetch(address) { - var _ref; +function getElementName(address) { + return /([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase(); +} +function configure(config) { + var viewEngine = config.container.get(aureliaTemplating.ViewEngine); + var loader = config.aurelia.loader; + viewEngine.addResourcePlugin('.html', { + 'fetch': function (viewUrl) { + return loader.loadTemplate(viewUrl).then(function (registryEntry) { + var _a; + var bindableNames = registryEntry.template.getAttribute('bindable'); + var useShadowDOMmode = registryEntry.template.getAttribute('use-shadow-dom'); + var name = getElementName(viewUrl); + if (bindableNames) { + bindableNames = bindableNames.split(',').map(function (x) { return x.trim(); }); + registryEntry.template.removeAttribute('bindable'); + } + else { + bindableNames = []; + } + return _a = {}, _a[name] = _createDynamicElement({ name: name, viewUrl: viewUrl, bindableNames: bindableNames, useShadowDOMmode: useShadowDOMmode }), _a; + }); + } + }); +} - return _ref = {}, _ref[address] = (0, _cssResource._createCSSResource)(address), _ref; - } - }; - ['.css', '.less', '.sass', '.scss', '.styl'].forEach(function (ext) { - return viewEngine.addResourcePlugin(ext, styleResourcePlugin); - }); +function configure$1(config) { + injectAureliaHideStyleAtHead(); + config.globalResources(Compose, If, Else, With, Repeat, Show, Hide, Replaceable, Focus, SanitizeHTMLValueConverter, OneTimeBindingBehavior, OneWayBindingBehavior, ToViewBindingBehavior, FromViewBindingBehavior, TwoWayBindingBehavior, ThrottleBindingBehavior, DebounceBindingBehavior, SelfBindingBehavior, SignalBindingBehavior, UpdateTriggerBindingBehavior, AttrBindingBehavior); + configure(config); + var viewEngine = config.container.get(aureliaTemplating.ViewEngine); + var styleResourcePlugin = { + fetch: function (address) { + var _a; + return _a = {}, _a[address] = _createCSSResource(address), _a; + } + }; + ['.css', '.less', '.sass', '.scss', '.styl'].forEach(function (ext) { return viewEngine.addResourcePlugin(ext, styleResourcePlugin); }); } -exports.Compose = _compose.Compose; -exports.If = _if.If; -exports.Else = _else.Else; -exports.With = _with.With; -exports.Repeat = _repeat.Repeat; -exports.Show = _show.Show; -exports.Hide = _hide.Hide; -exports.HTMLSanitizer = _htmlSanitizer.HTMLSanitizer; -exports.SanitizeHTMLValueConverter = _sanitizeHtml.SanitizeHTMLValueConverter; -exports.Replaceable = _replaceable.Replaceable; -exports.Focus = _focus.Focus; -exports.configure = configure; -exports.AttrBindingBehavior = _attrBindingBehavior.AttrBindingBehavior; -exports.OneTimeBindingBehavior = _bindingModeBehaviors.OneTimeBindingBehavior; -exports.OneWayBindingBehavior = _bindingModeBehaviors.OneWayBindingBehavior; -exports.ToViewBindingBehavior = _bindingModeBehaviors.ToViewBindingBehavior; -exports.FromViewBindingBehavior = _bindingModeBehaviors.FromViewBindingBehavior; -exports.TwoWayBindingBehavior = _bindingModeBehaviors.TwoWayBindingBehavior; -exports.ThrottleBindingBehavior = _throttleBindingBehavior.ThrottleBindingBehavior; -exports.DebounceBindingBehavior = _debounceBindingBehavior.DebounceBindingBehavior; -exports.SelfBindingBehavior = _selfBindingBehavior.SelfBindingBehavior; -exports.SignalBindingBehavior = _signalBindingBehavior.SignalBindingBehavior; -exports.BindingSignaler = _bindingSignaler.BindingSignaler; -exports.UpdateTriggerBindingBehavior = _updateTriggerBindingBehavior.UpdateTriggerBindingBehavior; -exports.AbstractRepeater = _abstractRepeater.AbstractRepeater; -exports.RepeatStrategyLocator = _repeatStrategyLocator.RepeatStrategyLocator; -exports.NullRepeatStrategy = _nullRepeatStrategy.NullRepeatStrategy; -exports.ArrayRepeatStrategy = _arrayRepeatStrategy.ArrayRepeatStrategy; -exports.MapRepeatStrategy = _mapRepeatStrategy.MapRepeatStrategy; -exports.SetRepeatStrategy = _setRepeatStrategy.SetRepeatStrategy; -exports.NumberRepeatStrategy = _numberRepeatStrategy.NumberRepeatStrategy; -exports.createFullOverrideContext = _repeatUtilities.createFullOverrideContext; -exports.updateOverrideContext = _repeatUtilities.updateOverrideContext; -exports.getItemsSourceExpression = _repeatUtilities.getItemsSourceExpression; -exports.isOneTime = _repeatUtilities.isOneTime; -exports.updateOneTimeBinding = _repeatUtilities.updateOneTimeBinding; -exports.unwrapExpression = _repeatUtilities.unwrapExpression; -exports.viewsRequireLifecycle = _analyzeViewFactory.viewsRequireLifecycle; \ No newline at end of file +exports.AbstractRepeater = AbstractRepeater; +exports.ArrayRepeatStrategy = ArrayRepeatStrategy; +exports.AttrBindingBehavior = AttrBindingBehavior; +exports.BindingSignaler = BindingSignaler; +exports.Compose = Compose; +exports.DebounceBindingBehavior = DebounceBindingBehavior; +exports.Else = Else; +exports.Focus = Focus; +exports.FromViewBindingBehavior = FromViewBindingBehavior; +exports.HTMLSanitizer = HTMLSanitizer; +exports.Hide = Hide; +exports.If = If; +exports.MapRepeatStrategy = MapRepeatStrategy; +exports.NullRepeatStrategy = NullRepeatStrategy; +exports.NumberRepeatStrategy = NumberRepeatStrategy; +exports.OneTimeBindingBehavior = OneTimeBindingBehavior; +exports.OneWayBindingBehavior = OneWayBindingBehavior; +exports.Repeat = Repeat; +exports.RepeatStrategyLocator = RepeatStrategyLocator; +exports.Replaceable = Replaceable; +exports.SanitizeHTMLValueConverter = SanitizeHTMLValueConverter; +exports.SelfBindingBehavior = SelfBindingBehavior; +exports.SetRepeatStrategy = SetRepeatStrategy; +exports.Show = Show; +exports.SignalBindingBehavior = SignalBindingBehavior; +exports.ThrottleBindingBehavior = ThrottleBindingBehavior; +exports.ToViewBindingBehavior = ToViewBindingBehavior; +exports.TwoWayBindingBehavior = TwoWayBindingBehavior; +exports.UpdateTriggerBindingBehavior = UpdateTriggerBindingBehavior; +exports.With = With; +exports.configure = configure$1; +exports.createFullOverrideContext = createFullOverrideContext; +exports.getItemsSourceExpression = getItemsSourceExpression; +exports.isOneTime = isOneTime; +exports.unwrapExpression = unwrapExpression; +exports.updateOneTimeBinding = updateOneTimeBinding; +exports.updateOverrideContext = updateOverrideContext; +exports.viewsRequireLifecycle = viewsRequireLifecycle; +//# sourceMappingURL=aurelia-templating-resources.js.map diff --git a/dist/commonjs/aurelia-templating-resources.js.map b/dist/commonjs/aurelia-templating-resources.js.map new file mode 100644 index 0000000..b068050 --- /dev/null +++ b/dist/commonjs/aurelia-templating-resources.js.map @@ -0,0 +1 @@ +{"version":3,"file":"aurelia-templating-resources.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/commonjs/binding-mode-behaviors.js b/dist/commonjs/binding-mode-behaviors.js deleted file mode 100644 index 8ed0607..0000000 --- a/dist/commonjs/binding-mode-behaviors.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.TwoWayBindingBehavior = exports.FromViewBindingBehavior = exports.ToViewBindingBehavior = exports.OneWayBindingBehavior = exports.OneTimeBindingBehavior = undefined; - -var _dec, _dec2, _class, _dec3, _dec4, _class2, _dec5, _dec6, _class3, _dec7, _dec8, _class4, _dec9, _dec10, _class5; - -var _aureliaBinding = require('aurelia-binding'); - -var _aureliaMetadata = require('aurelia-metadata'); - - - -var modeBindingBehavior = { - bind: function bind(binding, source, lookupFunctions) { - binding.originalMode = binding.mode; - binding.mode = this.mode; - }, - unbind: function unbind(binding, source) { - binding.mode = binding.originalMode; - binding.originalMode = null; - } -}; - -var OneTimeBindingBehavior = exports.OneTimeBindingBehavior = (_dec = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec2 = (0, _aureliaBinding.bindingBehavior)('oneTime'), _dec(_class = _dec2(_class = function OneTimeBindingBehavior() { - - - this.mode = _aureliaBinding.bindingMode.oneTime; -}) || _class) || _class); -var OneWayBindingBehavior = exports.OneWayBindingBehavior = (_dec3 = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec4 = (0, _aureliaBinding.bindingBehavior)('oneWay'), _dec3(_class2 = _dec4(_class2 = function OneWayBindingBehavior() { - - - this.mode = _aureliaBinding.bindingMode.toView; -}) || _class2) || _class2); -var ToViewBindingBehavior = exports.ToViewBindingBehavior = (_dec5 = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec6 = (0, _aureliaBinding.bindingBehavior)('toView'), _dec5(_class3 = _dec6(_class3 = function ToViewBindingBehavior() { - - - this.mode = _aureliaBinding.bindingMode.toView; -}) || _class3) || _class3); -var FromViewBindingBehavior = exports.FromViewBindingBehavior = (_dec7 = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec8 = (0, _aureliaBinding.bindingBehavior)('fromView'), _dec7(_class4 = _dec8(_class4 = function FromViewBindingBehavior() { - - - this.mode = _aureliaBinding.bindingMode.fromView; -}) || _class4) || _class4); -var TwoWayBindingBehavior = exports.TwoWayBindingBehavior = (_dec9 = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec10 = (0, _aureliaBinding.bindingBehavior)('twoWay'), _dec9(_class5 = _dec10(_class5 = function TwoWayBindingBehavior() { - - - this.mode = _aureliaBinding.bindingMode.twoWay; -}) || _class5) || _class5); \ No newline at end of file diff --git a/dist/commonjs/binding-signaler.js b/dist/commonjs/binding-signaler.js deleted file mode 100644 index 6440711..0000000 --- a/dist/commonjs/binding-signaler.js +++ /dev/null @@ -1,31 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.BindingSignaler = undefined; - -var _aureliaBinding = require('aurelia-binding'); - - - -var BindingSignaler = exports.BindingSignaler = function () { - function BindingSignaler() { - - - this.signals = {}; - } - - BindingSignaler.prototype.signal = function signal(name) { - var bindings = this.signals[name]; - if (!bindings) { - return; - } - var i = bindings.length; - while (i--) { - bindings[i].call(_aureliaBinding.sourceContext); - } - }; - - return BindingSignaler; -}(); \ No newline at end of file diff --git a/dist/commonjs/compose.js b/dist/commonjs/compose.js deleted file mode 100644 index 1bf0a55..0000000 --- a/dist/commonjs/compose.js +++ /dev/null @@ -1,221 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.Compose = undefined; - -var _dec, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4; - -var _aureliaDependencyInjection = require('aurelia-dependency-injection'); - -var _aureliaTaskQueue = require('aurelia-task-queue'); - -var _aureliaTemplating = require('aurelia-templating'); - -var _aureliaPal = require('aurelia-pal'); - -function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); -} - - - -function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; -} - -function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); -} - -var Compose = exports.Compose = (_dec = (0, _aureliaTemplating.customElement)('compose'), _dec(_class = (0, _aureliaTemplating.noView)(_class = (_class2 = function () { - Compose.inject = function inject() { - return [_aureliaPal.DOM.Element, _aureliaDependencyInjection.Container, _aureliaTemplating.CompositionEngine, _aureliaTemplating.ViewSlot, _aureliaTemplating.ViewResources, _aureliaTaskQueue.TaskQueue]; - }; - - function Compose(element, container, compositionEngine, viewSlot, viewResources, taskQueue) { - - - _initDefineProp(this, 'model', _descriptor, this); - - _initDefineProp(this, 'view', _descriptor2, this); - - _initDefineProp(this, 'viewModel', _descriptor3, this); - - _initDefineProp(this, 'swapOrder', _descriptor4, this); - - this.element = element; - this.container = container; - this.compositionEngine = compositionEngine; - this.viewSlot = viewSlot; - this.viewResources = viewResources; - this.taskQueue = taskQueue; - this.currentController = null; - this.currentViewModel = null; - this.changes = Object.create(null); - } - - Compose.prototype.created = function created(owningView) { - this.owningView = owningView; - }; - - Compose.prototype.bind = function bind(bindingContext, overrideContext) { - this.bindingContext = bindingContext; - this.overrideContext = overrideContext; - this.changes.view = this.view; - this.changes.viewModel = this.viewModel; - this.changes.model = this.model; - if (!this.pendingTask) { - processChanges(this); - } - }; - - Compose.prototype.unbind = function unbind() { - this.changes = Object.create(null); - this.bindingContext = null; - this.overrideContext = null; - var returnToCache = true; - var skipAnimation = true; - this.viewSlot.removeAll(returnToCache, skipAnimation); - }; - - Compose.prototype.modelChanged = function modelChanged(newValue, oldValue) { - this.changes.model = newValue; - requestUpdate(this); - }; - - Compose.prototype.viewChanged = function viewChanged(newValue, oldValue) { - this.changes.view = newValue; - requestUpdate(this); - }; - - Compose.prototype.viewModelChanged = function viewModelChanged(newValue, oldValue) { - this.changes.viewModel = newValue; - requestUpdate(this); - }; - - return Compose; -}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'model', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'view', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'viewModel', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, 'swapOrder', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -})), _class2)) || _class) || _class); - - -function isEmpty(obj) { - for (var key in obj) { - return false; - } - return true; -} - -function tryActivateViewModel(vm, model) { - if (vm && typeof vm.activate === 'function') { - return Promise.resolve(vm.activate(model)); - } -} - -function createInstruction(composer, instruction) { - return Object.assign(instruction, { - bindingContext: composer.bindingContext, - overrideContext: composer.overrideContext, - owningView: composer.owningView, - container: composer.container, - viewSlot: composer.viewSlot, - viewResources: composer.viewResources, - currentController: composer.currentController, - host: composer.element, - swapOrder: composer.swapOrder - }); -} - -function processChanges(composer) { - var changes = composer.changes; - composer.changes = Object.create(null); - - if (!('view' in changes) && !('viewModel' in changes) && 'model' in changes) { - composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model); - if (!composer.pendingTask) { - return; - } - } else { - var instruction = { - view: composer.view, - viewModel: composer.currentViewModel || composer.viewModel, - model: composer.model - }; - - instruction = Object.assign(instruction, changes); - - instruction = createInstruction(composer, instruction); - composer.pendingTask = composer.compositionEngine.compose(instruction).then(function (controller) { - composer.currentController = controller; - composer.currentViewModel = controller ? controller.viewModel : null; - }); - } - - composer.pendingTask = composer.pendingTask.then(function () { - completeCompositionTask(composer); - }, function (reason) { - completeCompositionTask(composer); - throw reason; - }); -} - -function completeCompositionTask(composer) { - composer.pendingTask = null; - if (!isEmpty(composer.changes)) { - processChanges(composer); - } -} - -function requestUpdate(composer) { - if (composer.pendingTask || composer.updateRequested) { - return; - } - composer.updateRequested = true; - composer.taskQueue.queueMicroTask(function () { - composer.updateRequested = false; - processChanges(composer); - }); -} \ No newline at end of file diff --git a/dist/commonjs/css-resource.js b/dist/commonjs/css-resource.js deleted file mode 100644 index ff83a2b..0000000 --- a/dist/commonjs/css-resource.js +++ /dev/null @@ -1,118 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports._createCSSResource = _createCSSResource; - -var _aureliaTemplating = require('aurelia-templating'); - -var _aureliaLoader = require('aurelia-loader'); - -var _aureliaDependencyInjection = require('aurelia-dependency-injection'); - -var _aureliaPath = require('aurelia-path'); - -var _aureliaPal = require('aurelia-pal'); - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - - - -var cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi; - -function fixupCSSUrls(address, css) { - if (typeof css !== 'string') { - throw new Error('Failed loading required CSS file: ' + address); - } - return css.replace(cssUrlMatcher, function (match, p1) { - var quote = p1.charAt(0); - if (quote === '\'' || quote === '"') { - p1 = p1.substr(1, p1.length - 2); - } - return 'url(\'' + (0, _aureliaPath.relativeToFile)(p1, address) + '\')'; - }); -} - -var CSSResource = function () { - function CSSResource(address) { - - - this.address = address; - this._scoped = null; - this._global = false; - this._alreadyGloballyInjected = false; - } - - CSSResource.prototype.initialize = function initialize(container, target) { - this._scoped = new target(this); - }; - - CSSResource.prototype.register = function register(registry, name) { - if (name === 'scoped') { - registry.registerViewEngineHooks(this._scoped); - } else { - this._global = true; - } - }; - - CSSResource.prototype.load = function load(container) { - var _this = this; - - return container.get(_aureliaLoader.Loader).loadText(this.address).catch(function (err) { - return null; - }).then(function (text) { - text = fixupCSSUrls(_this.address, text); - _this._scoped.css = text; - if (_this._global) { - _this._alreadyGloballyInjected = true; - _aureliaPal.DOM.injectStyles(text); - } - }); - }; - - return CSSResource; -}(); - -var CSSViewEngineHooks = function () { - function CSSViewEngineHooks(owner) { - - - this.owner = owner; - this.css = null; - } - - CSSViewEngineHooks.prototype.beforeCompile = function beforeCompile(content, resources, instruction) { - if (instruction.targetShadowDOM) { - _aureliaPal.DOM.injectStyles(this.css, content, true); - } else if (_aureliaPal.FEATURE.scopedCSS) { - var styleNode = _aureliaPal.DOM.injectStyles(this.css, content, true); - styleNode.setAttribute('scoped', 'scoped'); - } else if (this._global && !this.owner._alreadyGloballyInjected) { - _aureliaPal.DOM.injectStyles(this.css); - this.owner._alreadyGloballyInjected = true; - } - }; - - return CSSViewEngineHooks; -}(); - -function _createCSSResource(address) { - var _dec, _class; - - var ViewCSS = (_dec = (0, _aureliaTemplating.resource)(new CSSResource(address)), _dec(_class = function (_CSSViewEngineHooks) { - _inherits(ViewCSS, _CSSViewEngineHooks); - - function ViewCSS() { - - - return _possibleConstructorReturn(this, _CSSViewEngineHooks.apply(this, arguments)); - } - - return ViewCSS; - }(CSSViewEngineHooks)) || _class); - - return ViewCSS; -} \ No newline at end of file diff --git a/dist/commonjs/debounce-binding-behavior.js b/dist/commonjs/debounce-binding-behavior.js deleted file mode 100644 index 756a5ae..0000000 --- a/dist/commonjs/debounce-binding-behavior.js +++ /dev/null @@ -1,82 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.DebounceBindingBehavior = undefined; - -var _dec, _class; - -var _aureliaBinding = require('aurelia-binding'); - - - -var unset = {}; - -function debounceCallSource(event) { - var _this = this; - - var state = this.debounceState; - clearTimeout(state.timeoutId); - state.timeoutId = setTimeout(function () { - return _this.debouncedMethod(event); - }, state.delay); -} - -function debounceCall(context, newValue, oldValue) { - var _this2 = this; - - var state = this.debounceState; - clearTimeout(state.timeoutId); - if (context !== state.callContextToDebounce) { - state.oldValue = unset; - this.debouncedMethod(context, newValue, oldValue); - return; - } - if (state.oldValue === unset) { - state.oldValue = oldValue; - } - state.timeoutId = setTimeout(function () { - var _oldValue = state.oldValue; - state.oldValue = unset; - _this2.debouncedMethod(context, newValue, _oldValue); - }, state.delay); -} - -var DebounceBindingBehavior = exports.DebounceBindingBehavior = (_dec = (0, _aureliaBinding.bindingBehavior)('debounce'), _dec(_class = function () { - function DebounceBindingBehavior() { - - } - - DebounceBindingBehavior.prototype.bind = function bind(binding, source) { - var delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200; - - var isCallSource = binding.callSource !== undefined; - var methodToDebounce = isCallSource ? 'callSource' : 'call'; - var debouncer = isCallSource ? debounceCallSource : debounceCall; - var mode = binding.mode; - var callContextToDebounce = mode === _aureliaBinding.bindingMode.twoWay || mode === _aureliaBinding.bindingMode.fromView ? _aureliaBinding.targetContext : _aureliaBinding.sourceContext; - - binding.debouncedMethod = binding[methodToDebounce]; - binding.debouncedMethod.originalName = methodToDebounce; - - binding[methodToDebounce] = debouncer; - - binding.debounceState = { - callContextToDebounce: callContextToDebounce, - delay: delay, - timeoutId: 0, - oldValue: unset - }; - }; - - DebounceBindingBehavior.prototype.unbind = function unbind(binding, source) { - var methodToRestore = binding.debouncedMethod.originalName; - binding[methodToRestore] = binding.debouncedMethod; - binding.debouncedMethod = null; - clearTimeout(binding.debounceState.timeoutId); - binding.debounceState = null; - }; - - return DebounceBindingBehavior; -}()) || _class); \ No newline at end of file diff --git a/dist/commonjs/dynamic-element.js b/dist/commonjs/dynamic-element.js deleted file mode 100644 index 0331de4..0000000 --- a/dist/commonjs/dynamic-element.js +++ /dev/null @@ -1,60 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports._createDynamicElement = _createDynamicElement; - -var _aureliaTemplating = require('aurelia-templating'); - -var _aureliaLogging = require('aurelia-logging'); - - - -function _createDynamicElement(_ref) { - var _dec, _dec2, _class; - - var name = _ref.name, - viewUrl = _ref.viewUrl, - bindableNames = _ref.bindableNames, - useShadowDOMmode = _ref.useShadowDOMmode; - var DynamicElement = (_dec = (0, _aureliaTemplating.customElement)(name), _dec2 = (0, _aureliaTemplating.useView)(viewUrl), _dec(_class = _dec2(_class = function () { - function DynamicElement() { - - } - - DynamicElement.prototype.bind = function bind(bindingContext) { - this.$parent = bindingContext; - }; - - return DynamicElement; - }()) || _class) || _class); - - - for (var i = 0, ii = bindableNames.length; i < ii; ++i) { - (0, _aureliaTemplating.bindable)(bindableNames[i])(DynamicElement); - } - - switch (useShadowDOMmode) { - case 'open': - (0, _aureliaTemplating.useShadowDOM)({ mode: 'open' })(DynamicElement); - break; - - case 'closed': - (0, _aureliaTemplating.useShadowDOM)({ mode: 'closed' })(DynamicElement); - break; - - case '': - (0, _aureliaTemplating.useShadowDOM)(DynamicElement); - break; - - case null: - break; - - default: - (0, _aureliaLogging.getLogger)('aurelia-html-only-element').warn('Expected \'use-shadow-dom\' value to be "close", "open" or "", received ' + useShadowDOMmode); - break; - } - - return DynamicElement; -} \ No newline at end of file diff --git a/dist/commonjs/else.js b/dist/commonjs/else.js deleted file mode 100644 index 22daeed..0000000 --- a/dist/commonjs/else.js +++ /dev/null @@ -1,57 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.Else = undefined; - -var _dec, _dec2, _class; - -var _aureliaTemplating = require('aurelia-templating'); - -var _aureliaDependencyInjection = require('aurelia-dependency-injection'); - -var _ifCore = require('./if-core'); - - - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -var Else = exports.Else = (_dec = (0, _aureliaTemplating.customAttribute)('else'), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.ViewSlot), _dec(_class = (0, _aureliaTemplating.templateController)(_class = _dec2(_class = function (_IfCore) { - _inherits(Else, _IfCore); - - function Else(viewFactory, viewSlot) { - - - var _this = _possibleConstructorReturn(this, _IfCore.call(this, viewFactory, viewSlot)); - - _this._registerInIf(); - return _this; - } - - Else.prototype.bind = function bind(bindingContext, overrideContext) { - _IfCore.prototype.bind.call(this, bindingContext, overrideContext); - - if (this.ifVm.condition) { - this._hide(); - } else { - this._show(); - } - }; - - Else.prototype._registerInIf = function _registerInIf() { - var previous = this.viewSlot.anchor.previousSibling; - while (previous && !previous.au) { - previous = previous.previousSibling; - } - if (!previous || !previous.au.if) { - throw new Error("Can't find matching If for Else custom attribute."); - } - this.ifVm = previous.au.if.viewModel; - this.ifVm.elseVm = this; - }; - - return Else; -}(_ifCore.IfCore)) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/commonjs/focus.js b/dist/commonjs/focus.js deleted file mode 100644 index eeec295..0000000 --- a/dist/commonjs/focus.js +++ /dev/null @@ -1,81 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.Focus = undefined; - -var _dec, _class; - -var _aureliaTemplating = require('aurelia-templating'); - -var _aureliaBinding = require('aurelia-binding'); - -var _aureliaTaskQueue = require('aurelia-task-queue'); - -var _aureliaPal = require('aurelia-pal'); - - - -var Focus = exports.Focus = (_dec = (0, _aureliaTemplating.customAttribute)('focus', _aureliaBinding.bindingMode.twoWay), _dec(_class = function () { - Focus.inject = function inject() { - return [_aureliaPal.DOM.Element, _aureliaTaskQueue.TaskQueue]; - }; - - function Focus(element, taskQueue) { - - - this.element = element; - this.taskQueue = taskQueue; - this.isAttached = false; - this.needsApply = false; - } - - Focus.prototype.valueChanged = function valueChanged(newValue) { - if (this.isAttached) { - this._apply(); - } else { - this.needsApply = true; - } - }; - - Focus.prototype._apply = function _apply() { - var _this = this; - - if (this.value) { - this.taskQueue.queueMicroTask(function () { - if (_this.value) { - _this.element.focus(); - } - }); - } else { - this.element.blur(); - } - }; - - Focus.prototype.attached = function attached() { - this.isAttached = true; - if (this.needsApply) { - this.needsApply = false; - this._apply(); - } - this.element.addEventListener('focus', this); - this.element.addEventListener('blur', this); - }; - - Focus.prototype.detached = function detached() { - this.isAttached = false; - this.element.removeEventListener('focus', this); - this.element.removeEventListener('blur', this); - }; - - Focus.prototype.handleEvent = function handleEvent(e) { - if (e.type === 'focus') { - this.value = true; - } else if (_aureliaPal.DOM.activeElement !== this.element) { - this.value = false; - } - }; - - return Focus; -}()) || _class); \ No newline at end of file diff --git a/dist/commonjs/hide.js b/dist/commonjs/hide.js deleted file mode 100644 index d02c34f..0000000 --- a/dist/commonjs/hide.js +++ /dev/null @@ -1,50 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.Hide = undefined; - -var _dec, _class; - -var _aureliaDependencyInjection = require('aurelia-dependency-injection'); - -var _aureliaTemplating = require('aurelia-templating'); - -var _aureliaPal = require('aurelia-pal'); - -var _aureliaHideStyle = require('./aurelia-hide-style'); - - - -var Hide = exports.Hide = (_dec = (0, _aureliaTemplating.customAttribute)('hide'), _dec(_class = function () { - Hide.inject = function inject() { - return [_aureliaPal.DOM.Element, _aureliaTemplating.Animator, _aureliaDependencyInjection.Optional.of(_aureliaPal.DOM.boundary, true)]; - }; - - function Hide(element, animator, domBoundary) { - - - this.element = element; - this.animator = animator; - this.domBoundary = domBoundary; - } - - Hide.prototype.created = function created() { - (0, _aureliaHideStyle.injectAureliaHideStyleAtBoundary)(this.domBoundary); - }; - - Hide.prototype.valueChanged = function valueChanged(newValue) { - if (newValue) { - this.animator.addClass(this.element, _aureliaHideStyle.aureliaHideClassName); - } else { - this.animator.removeClass(this.element, _aureliaHideStyle.aureliaHideClassName); - } - }; - - Hide.prototype.bind = function bind(bindingContext) { - this.valueChanged(this.value); - }; - - return Hide; -}()) || _class); \ No newline at end of file diff --git a/dist/commonjs/html-resource-plugin.js b/dist/commonjs/html-resource-plugin.js deleted file mode 100644 index fda2003..0000000 --- a/dist/commonjs/html-resource-plugin.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.getElementName = getElementName; -exports.configure = configure; - -var _aureliaTemplating = require('aurelia-templating'); - -var _dynamicElement = require('./dynamic-element'); - -function getElementName(address) { - return (/([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase() - ); -} - -function configure(config) { - var viewEngine = config.container.get(_aureliaTemplating.ViewEngine); - var loader = config.aurelia.loader; - - viewEngine.addResourcePlugin('.html', { - 'fetch': function fetch(viewUrl) { - return loader.loadTemplate(viewUrl).then(function (registryEntry) { - var _ref; - - var bindableNames = registryEntry.template.getAttribute('bindable'); - var useShadowDOMmode = registryEntry.template.getAttribute('use-shadow-dom'); - var name = getElementName(viewUrl); - - if (bindableNames) { - bindableNames = bindableNames.split(',').map(function (x) { - return x.trim(); - }); - registryEntry.template.removeAttribute('bindable'); - } else { - bindableNames = []; - } - - return _ref = {}, _ref[name] = (0, _dynamicElement._createDynamicElement)({ name: name, viewUrl: viewUrl, bindableNames: bindableNames, useShadowDOMmode: useShadowDOMmode }), _ref; - }); - } - }); -} \ No newline at end of file diff --git a/dist/commonjs/html-sanitizer.js b/dist/commonjs/html-sanitizer.js deleted file mode 100644 index 258b1ec..0000000 --- a/dist/commonjs/html-sanitizer.js +++ /dev/null @@ -1,31 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.HTMLSanitizer = undefined; - -var _aureliaLogging = require('aurelia-logging'); - - - -var SCRIPT_REGEX = /)<[^<]*)*<\/script>/gi; -var needsToWarn = true; - -var HTMLSanitizer = exports.HTMLSanitizer = function () { - function HTMLSanitizer() { - - } - - HTMLSanitizer.prototype.sanitize = function sanitize(input) { - if (needsToWarn) { - needsToWarn = false; - - (0, _aureliaLogging.getLogger)('html-sanitizer').warn('CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks,\n and should not be relied on for sanitizing input from unknown sources.\n Please see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html.'); - } - - return input.replace(SCRIPT_REGEX, ''); - }; - - return HTMLSanitizer; -}(); \ No newline at end of file diff --git a/dist/commonjs/if-core.js b/dist/commonjs/if-core.js deleted file mode 100644 index d577156..0000000 --- a/dist/commonjs/if-core.js +++ /dev/null @@ -1,97 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - - - -var IfCore = exports.IfCore = function () { - function IfCore(viewFactory, viewSlot) { - - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.view = null; - this.bindingContext = null; - this.overrideContext = null; - - this.showing = false; - this.cache = true; - } - - IfCore.prototype.bind = function bind(bindingContext, overrideContext) { - this.bindingContext = bindingContext; - this.overrideContext = overrideContext; - }; - - IfCore.prototype.unbind = function unbind() { - if (this.view === null) { - return; - } - - this.view.unbind(); - - if (!this.viewFactory.isCaching) { - return; - } - - if (this.showing) { - this.showing = false; - this.viewSlot.remove(this.view, true, true); - } else { - this.view.returnToCache(); - } - - this.view = null; - }; - - IfCore.prototype._show = function _show() { - if (this.showing) { - if (!this.view.isBound) { - this.view.bind(this.bindingContext, this.overrideContext); - } - return; - } - - if (this.view === null) { - this.view = this.viewFactory.create(); - } - - if (!this.view.isBound) { - this.view.bind(this.bindingContext, this.overrideContext); - } - - this.showing = true; - return this.viewSlot.add(this.view); - }; - - IfCore.prototype._hide = function _hide() { - var _this = this; - - if (!this.showing) { - return; - } - - this.showing = false; - var removed = this.viewSlot.remove(this.view); - - if (removed instanceof Promise) { - return removed.then(function () { - _this._unbindView(); - }); - } - - this._unbindView(); - }; - - IfCore.prototype._unbindView = function _unbindView() { - var cache = this.cache === 'false' ? false : !!this.cache; - this.view.unbind(); - if (!cache) { - this.view = null; - } - }; - - return IfCore; -}(); \ No newline at end of file diff --git a/dist/commonjs/if.js b/dist/commonjs/if.js deleted file mode 100644 index 262e00f..0000000 --- a/dist/commonjs/if.js +++ /dev/null @@ -1,146 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.If = undefined; - -var _dec, _dec2, _dec3, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3; - -var _aureliaTemplating = require('aurelia-templating'); - -var _aureliaDependencyInjection = require('aurelia-dependency-injection'); - -var _ifCore = require('./if-core'); - -function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); -} - - - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; -} - -function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); -} - -var If = exports.If = (_dec = (0, _aureliaTemplating.customAttribute)('if'), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.ViewSlot), _dec3 = (0, _aureliaTemplating.bindable)({ primaryProperty: true }), _dec(_class = (0, _aureliaTemplating.templateController)(_class = _dec2(_class = (_class2 = function (_IfCore) { - _inherits(If, _IfCore); - - function If() { - var _temp, _this, _ret; - - - - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - return _ret = (_temp = (_this = _possibleConstructorReturn(this, _IfCore.call.apply(_IfCore, [this].concat(args))), _this), _initDefineProp(_this, 'condition', _descriptor, _this), _initDefineProp(_this, 'swapOrder', _descriptor2, _this), _initDefineProp(_this, 'cache', _descriptor3, _this), _temp), _possibleConstructorReturn(_this, _ret); - } - - If.prototype.bind = function bind(bindingContext, overrideContext) { - _IfCore.prototype.bind.call(this, bindingContext, overrideContext); - if (this.condition) { - this._show(); - } else { - this._hide(); - } - }; - - If.prototype.conditionChanged = function conditionChanged(newValue) { - this._update(newValue); - }; - - If.prototype._update = function _update(show) { - var _this2 = this; - - if (this.animating) { - return; - } - - var promise = void 0; - if (this.elseVm) { - promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm); - } else { - promise = show ? this._show() : this._hide(); - } - - if (promise) { - this.animating = true; - promise.then(function () { - _this2.animating = false; - if (_this2.condition !== _this2.showing) { - _this2._update(_this2.condition); - } - }); - } - }; - - If.prototype._swap = function _swap(remove, add) { - switch (this.swapOrder) { - case 'before': - return Promise.resolve(add._show()).then(function () { - return remove._hide(); - }); - case 'with': - return Promise.all([remove._hide(), add._show()]); - default: - var promise = remove._hide(); - return promise ? promise.then(function () { - return add._show(); - }) : add._show(); - } - }; - - return If; -}(_ifCore.IfCore), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'condition', [_dec3], { - enumerable: true, - initializer: null -}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'swapOrder', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'cache', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: function initializer() { - return true; - } -})), _class2)) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/commonjs/index.js b/dist/commonjs/index.js deleted file mode 100644 index 9cca5a4..0000000 --- a/dist/commonjs/index.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _aureliaTemplatingResources = require('./aurelia-templating-resources'); - -Object.keys(_aureliaTemplatingResources).forEach(function (key) { - if (key === "default" || key === "__esModule") return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function get() { - return _aureliaTemplatingResources[key]; - } - }); -}); \ No newline at end of file diff --git a/dist/commonjs/map-repeat-strategy.js b/dist/commonjs/map-repeat-strategy.js deleted file mode 100644 index fbb1998..0000000 --- a/dist/commonjs/map-repeat-strategy.js +++ /dev/null @@ -1,117 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.MapRepeatStrategy = undefined; - -var _repeatUtilities = require('./repeat-utilities'); - - - -var MapRepeatStrategy = exports.MapRepeatStrategy = function () { - function MapRepeatStrategy() { - - } - - MapRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getMapObserver(items); - }; - - MapRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this._standardProcessItems(repeat, items); - }); - return; - } - this._standardProcessItems(repeat, items); - }; - - MapRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, items) { - var index = 0; - var overrideContext = void 0; - - items.forEach(function (value, key) { - overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, value, index, items.size, key); - repeat.addView(overrideContext.bindingContext, overrideContext); - ++index; - }); - }; - - MapRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, map, records) { - var key = void 0; - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var removeIndex = void 0; - var addIndex = void 0; - var record = void 0; - var rmPromises = []; - var viewOrPromise = void 0; - - for (i = 0, ii = records.length; i < ii; ++i) { - record = records[i]; - key = record.key; - switch (record.type) { - case 'update': - removeIndex = this._getViewIndexByKey(repeat, key); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, map.get(key), removeIndex, map.size, key); - repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext); - break; - case 'add': - addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1; - overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, map.get(key), addIndex, map.size, key); - repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext); - break; - case 'delete': - if (record.oldValue === undefined) { - return; - } - removeIndex = this._getViewIndexByKey(repeat, key); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - break; - case 'clear': - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - break; - default: - continue; - } - } - - if (rmPromises.length > 0) { - Promise.all(rmPromises).then(function () { - (0, _repeatUtilities.updateOverrideContexts)(repeat.views(), 0); - }); - } else { - (0, _repeatUtilities.updateOverrideContexts)(repeat.views(), 0); - } - }; - - MapRepeatStrategy.prototype._getViewIndexByKey = function _getViewIndexByKey(repeat, key) { - var i = void 0; - var ii = void 0; - var child = void 0; - - for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { - child = repeat.view(i); - if (child.bindingContext[repeat.key] === key) { - return i; - } - } - - return undefined; - }; - - return MapRepeatStrategy; -}(); \ No newline at end of file diff --git a/dist/commonjs/null-repeat-strategy.js b/dist/commonjs/null-repeat-strategy.js deleted file mode 100644 index 133d93c..0000000 --- a/dist/commonjs/null-repeat-strategy.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - - - -var NullRepeatStrategy = exports.NullRepeatStrategy = function () { - function NullRepeatStrategy() { - - } - - NullRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - repeat.removeAllViews(true); - }; - - NullRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) {}; - - return NullRepeatStrategy; -}(); \ No newline at end of file diff --git a/dist/commonjs/number-repeat-strategy.js b/dist/commonjs/number-repeat-strategy.js deleted file mode 100644 index 601e64c..0000000 --- a/dist/commonjs/number-repeat-strategy.js +++ /dev/null @@ -1,65 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.NumberRepeatStrategy = undefined; - -var _repeatUtilities = require('./repeat-utilities'); - - - -var NumberRepeatStrategy = exports.NumberRepeatStrategy = function () { - function NumberRepeatStrategy() { - - } - - NumberRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver() { - return null; - }; - - NumberRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, value) { - var _this = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this._standardProcessItems(repeat, value); - }); - return; - } - this._standardProcessItems(repeat, value); - }; - - NumberRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, value) { - var childrenLength = repeat.viewCount(); - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var viewsToRemove = void 0; - - value = Math.floor(value); - viewsToRemove = childrenLength - value; - - if (viewsToRemove > 0) { - if (viewsToRemove > childrenLength) { - viewsToRemove = childrenLength; - } - - for (i = 0, ii = viewsToRemove; i < ii; ++i) { - repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle); - } - - return; - } - - for (i = childrenLength, ii = value; i < ii; ++i) { - overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, i, i, ii); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - - (0, _repeatUtilities.updateOverrideContexts)(repeat.views(), 0); - }; - - return NumberRepeatStrategy; -}(); \ No newline at end of file diff --git a/dist/commonjs/repeat-strategy-locator.js b/dist/commonjs/repeat-strategy-locator.js deleted file mode 100644 index 547d0f7..0000000 --- a/dist/commonjs/repeat-strategy-locator.js +++ /dev/null @@ -1,62 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.RepeatStrategyLocator = undefined; - -var _nullRepeatStrategy = require('./null-repeat-strategy'); - -var _arrayRepeatStrategy = require('./array-repeat-strategy'); - -var _mapRepeatStrategy = require('./map-repeat-strategy'); - -var _setRepeatStrategy = require('./set-repeat-strategy'); - -var _numberRepeatStrategy = require('./number-repeat-strategy'); - - - -var RepeatStrategyLocator = exports.RepeatStrategyLocator = function () { - function RepeatStrategyLocator() { - - - this.matchers = []; - this.strategies = []; - - this.addStrategy(function (items) { - return items === null || items === undefined; - }, new _nullRepeatStrategy.NullRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Array; - }, new _arrayRepeatStrategy.ArrayRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Map; - }, new _mapRepeatStrategy.MapRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Set; - }, new _setRepeatStrategy.SetRepeatStrategy()); - this.addStrategy(function (items) { - return typeof items === 'number'; - }, new _numberRepeatStrategy.NumberRepeatStrategy()); - } - - RepeatStrategyLocator.prototype.addStrategy = function addStrategy(matcher, strategy) { - this.matchers.push(matcher); - this.strategies.push(strategy); - }; - - RepeatStrategyLocator.prototype.getStrategy = function getStrategy(items) { - var matchers = this.matchers; - - for (var i = 0, ii = matchers.length; i < ii; ++i) { - if (matchers[i](items)) { - return this.strategies[i]; - } - } - - return null; - }; - - return RepeatStrategyLocator; -}(); \ No newline at end of file diff --git a/dist/commonjs/repeat-utilities.js b/dist/commonjs/repeat-utilities.js deleted file mode 100644 index 48de57d..0000000 --- a/dist/commonjs/repeat-utilities.js +++ /dev/null @@ -1,105 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.updateOverrideContexts = updateOverrideContexts; -exports.createFullOverrideContext = createFullOverrideContext; -exports.updateOverrideContext = updateOverrideContext; -exports.getItemsSourceExpression = getItemsSourceExpression; -exports.unwrapExpression = unwrapExpression; -exports.isOneTime = isOneTime; -exports.updateOneTimeBinding = updateOneTimeBinding; -exports.indexOf = indexOf; - -var _aureliaBinding = require('aurelia-binding'); - -var oneTime = _aureliaBinding.bindingMode.oneTime; - -function updateOverrideContexts(views, startIndex) { - var length = views.length; - - if (startIndex > 0) { - startIndex = startIndex - 1; - } - - for (; startIndex < length; ++startIndex) { - updateOverrideContext(views[startIndex].overrideContext, startIndex, length); - } -} - -function createFullOverrideContext(repeat, data, index, length, key) { - var bindingContext = {}; - var overrideContext = (0, _aureliaBinding.createOverrideContext)(bindingContext, repeat.scope.overrideContext); - - if (typeof key !== 'undefined') { - bindingContext[repeat.key] = key; - bindingContext[repeat.value] = data; - } else { - bindingContext[repeat.local] = data; - } - updateOverrideContext(overrideContext, index, length); - return overrideContext; -} - -function updateOverrideContext(overrideContext, index, length) { - var first = index === 0; - var last = index === length - 1; - var even = index % 2 === 0; - - overrideContext.$index = index; - overrideContext.$first = first; - overrideContext.$last = last; - overrideContext.$middle = !(first || last); - overrideContext.$odd = !even; - overrideContext.$even = even; -} - -function getItemsSourceExpression(instruction, attrName) { - return instruction.behaviorInstructions.filter(function (bi) { - return bi.originalAttrName === attrName; - })[0].attributes.items.sourceExpression; -} - -function unwrapExpression(expression) { - var unwrapped = false; - while (expression instanceof _aureliaBinding.BindingBehavior) { - expression = expression.expression; - } - while (expression instanceof _aureliaBinding.ValueConverter) { - expression = expression.expression; - unwrapped = true; - } - return unwrapped ? expression : null; -} - -function isOneTime(expression) { - while (expression instanceof _aureliaBinding.BindingBehavior) { - if (expression.name === 'oneTime') { - return true; - } - expression = expression.expression; - } - return false; -} - -function updateOneTimeBinding(binding) { - if (binding.call && binding.mode === oneTime) { - binding.call(_aureliaBinding.sourceContext); - } else if (binding.updateOneTimeBindings) { - binding.updateOneTimeBindings(); - } -} - -function indexOf(array, item, matcher, startIndex) { - if (!matcher) { - return array.indexOf(item); - } - var length = array.length; - for (var index = startIndex || 0; index < length; index++) { - if (matcher(array[index], item)) { - return index; - } - } - return -1; -} \ No newline at end of file diff --git a/dist/commonjs/repeat.js b/dist/commonjs/repeat.js deleted file mode 100644 index e78c75a..0000000 --- a/dist/commonjs/repeat.js +++ /dev/null @@ -1,316 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.Repeat = undefined; - -var _dec, _dec2, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4; - -var _aureliaDependencyInjection = require('aurelia-dependency-injection'); - -var _aureliaBinding = require('aurelia-binding'); - -var _aureliaTemplating = require('aurelia-templating'); - -var _repeatStrategyLocator = require('./repeat-strategy-locator'); - -var _repeatUtilities = require('./repeat-utilities'); - -var _analyzeViewFactory = require('./analyze-view-factory'); - -var _abstractRepeater = require('./abstract-repeater'); - -function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); -} - - - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; -} - -function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); -} - -var Repeat = exports.Repeat = (_dec = (0, _aureliaTemplating.customAttribute)('repeat'), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.TargetInstruction, _aureliaTemplating.ViewSlot, _aureliaTemplating.ViewResources, _aureliaBinding.ObserverLocator, _repeatStrategyLocator.RepeatStrategyLocator), _dec(_class = (0, _aureliaTemplating.templateController)(_class = _dec2(_class = (_class2 = function (_AbstractRepeater) { - _inherits(Repeat, _AbstractRepeater); - - function Repeat(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) { - - - var _this = _possibleConstructorReturn(this, _AbstractRepeater.call(this, { - local: 'item', - viewsRequireLifecycle: (0, _analyzeViewFactory.viewsRequireLifecycle)(viewFactory) - })); - - _initDefineProp(_this, 'items', _descriptor, _this); - - _initDefineProp(_this, 'local', _descriptor2, _this); - - _initDefineProp(_this, 'key', _descriptor3, _this); - - _initDefineProp(_this, 'value', _descriptor4, _this); - - _this.viewFactory = viewFactory; - _this.instruction = instruction; - _this.viewSlot = viewSlot; - _this.lookupFunctions = viewResources.lookupFunctions; - _this.observerLocator = observerLocator; - _this.key = 'key'; - _this.value = 'value'; - _this.strategyLocator = strategyLocator; - _this.ignoreMutation = false; - _this.sourceExpression = (0, _repeatUtilities.getItemsSourceExpression)(_this.instruction, 'repeat.for'); - _this.isOneTime = (0, _repeatUtilities.isOneTime)(_this.sourceExpression); - _this.viewsRequireLifecycle = (0, _analyzeViewFactory.viewsRequireLifecycle)(viewFactory); - return _this; - } - - Repeat.prototype.call = function call(context, changes) { - this[context](this.items, changes); - }; - - Repeat.prototype.bind = function bind(bindingContext, overrideContext) { - this.scope = { bindingContext: bindingContext, overrideContext: overrideContext }; - this.matcherBinding = this._captureAndRemoveMatcherBinding(); - this.itemsChanged(); - }; - - Repeat.prototype.unbind = function unbind() { - this.scope = null; - this.items = null; - this.matcherBinding = null; - this.viewSlot.removeAll(true, true); - this._unsubscribeCollection(); - }; - - Repeat.prototype._unsubscribeCollection = function _unsubscribeCollection() { - if (this.collectionObserver) { - this.collectionObserver.unsubscribe(this.callContext, this); - this.collectionObserver = null; - this.callContext = null; - } - }; - - Repeat.prototype.itemsChanged = function itemsChanged() { - var _this2 = this; - - this._unsubscribeCollection(); - - if (!this.scope) { - return; - } - - var items = this.items; - this.strategy = this.strategyLocator.getStrategy(items); - if (!this.strategy) { - throw new Error('Value for \'' + this.sourceExpression + '\' is non-repeatable'); - } - - if (!this.isOneTime && !this._observeInnerCollection()) { - this._observeCollection(); - } - this.ignoreMutation = true; - this.strategy.instanceChanged(this, items); - this.observerLocator.taskQueue.queueMicroTask(function () { - _this2.ignoreMutation = false; - }); - }; - - Repeat.prototype._getInnerCollection = function _getInnerCollection() { - var expression = (0, _repeatUtilities.unwrapExpression)(this.sourceExpression); - if (!expression) { - return null; - } - return expression.evaluate(this.scope, null); - }; - - Repeat.prototype.handleCollectionMutated = function handleCollectionMutated(collection, changes) { - if (!this.collectionObserver) { - return; - } - if (this.ignoreMutation) { - return; - } - this.strategy.instanceMutated(this, collection, changes); - }; - - Repeat.prototype.handleInnerCollectionMutated = function handleInnerCollectionMutated(collection, changes) { - var _this3 = this; - - if (!this.collectionObserver) { - return; - } - - if (this.ignoreMutation) { - return; - } - this.ignoreMutation = true; - var newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions); - this.observerLocator.taskQueue.queueMicroTask(function () { - return _this3.ignoreMutation = false; - }); - - if (newItems === this.items) { - this.itemsChanged(); - } else { - this.items = newItems; - } - }; - - Repeat.prototype._observeInnerCollection = function _observeInnerCollection() { - var items = this._getInnerCollection(); - var strategy = this.strategyLocator.getStrategy(items); - if (!strategy) { - return false; - } - this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items); - if (!this.collectionObserver) { - return false; - } - this.callContext = 'handleInnerCollectionMutated'; - this.collectionObserver.subscribe(this.callContext, this); - return true; - }; - - Repeat.prototype._observeCollection = function _observeCollection() { - var items = this.items; - this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items); - if (this.collectionObserver) { - this.callContext = 'handleCollectionMutated'; - this.collectionObserver.subscribe(this.callContext, this); - } - }; - - Repeat.prototype._captureAndRemoveMatcherBinding = function _captureAndRemoveMatcherBinding() { - if (this.viewFactory.viewFactory) { - var instructions = this.viewFactory.viewFactory.instructions; - var instructionIds = Object.keys(instructions); - for (var i = 0; i < instructionIds.length; i++) { - var expressions = instructions[instructionIds[i]].expressions; - if (expressions) { - for (var ii = 0; i < expressions.length; i++) { - if (expressions[ii].targetProperty === 'matcher') { - var matcherBinding = expressions[ii]; - expressions.splice(ii, 1); - return matcherBinding; - } - } - } - } - } - - return undefined; - }; - - Repeat.prototype.viewCount = function viewCount() { - return this.viewSlot.children.length; - }; - - Repeat.prototype.views = function views() { - return this.viewSlot.children; - }; - - Repeat.prototype.view = function view(index) { - return this.viewSlot.children[index]; - }; - - Repeat.prototype.matcher = function matcher() { - return this.matcherBinding ? this.matcherBinding.sourceExpression.evaluate(this.scope, this.matcherBinding.lookupFunctions) : null; - }; - - Repeat.prototype.addView = function addView(bindingContext, overrideContext) { - var view = this.viewFactory.create(); - view.bind(bindingContext, overrideContext); - this.viewSlot.add(view); - }; - - Repeat.prototype.insertView = function insertView(index, bindingContext, overrideContext) { - var view = this.viewFactory.create(); - view.bind(bindingContext, overrideContext); - this.viewSlot.insert(index, view); - }; - - Repeat.prototype.moveView = function moveView(sourceIndex, targetIndex) { - this.viewSlot.move(sourceIndex, targetIndex); - }; - - Repeat.prototype.removeAllViews = function removeAllViews(returnToCache, skipAnimation) { - return this.viewSlot.removeAll(returnToCache, skipAnimation); - }; - - Repeat.prototype.removeViews = function removeViews(viewsToRemove, returnToCache, skipAnimation) { - return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation); - }; - - Repeat.prototype.removeView = function removeView(index, returnToCache, skipAnimation) { - return this.viewSlot.removeAt(index, returnToCache, skipAnimation); - }; - - Repeat.prototype.updateBindings = function updateBindings(view) { - var j = view.bindings.length; - while (j--) { - (0, _repeatUtilities.updateOneTimeBinding)(view.bindings[j]); - } - j = view.controllers.length; - while (j--) { - var k = view.controllers[j].boundProperties.length; - while (k--) { - var binding = view.controllers[j].boundProperties[k].binding; - (0, _repeatUtilities.updateOneTimeBinding)(binding); - } - } - }; - - return Repeat; -}(_abstractRepeater.AbstractRepeater), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'items', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'local', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'key', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, 'value', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -})), _class2)) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/commonjs/replaceable.js b/dist/commonjs/replaceable.js deleted file mode 100644 index 521f668..0000000 --- a/dist/commonjs/replaceable.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.Replaceable = undefined; - -var _dec, _dec2, _class; - -var _aureliaDependencyInjection = require('aurelia-dependency-injection'); - -var _aureliaTemplating = require('aurelia-templating'); - - - -var Replaceable = exports.Replaceable = (_dec = (0, _aureliaTemplating.customAttribute)('replaceable'), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.ViewSlot), _dec(_class = (0, _aureliaTemplating.templateController)(_class = _dec2(_class = function () { - function Replaceable(viewFactory, viewSlot) { - - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.view = null; - } - - Replaceable.prototype.bind = function bind(bindingContext, overrideContext) { - if (this.view === null) { - this.view = this.viewFactory.create(); - this.viewSlot.add(this.view); - } - - this.view.bind(bindingContext, overrideContext); - }; - - Replaceable.prototype.unbind = function unbind() { - this.view.unbind(); - }; - - return Replaceable; -}()) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/commonjs/sanitize-html.js b/dist/commonjs/sanitize-html.js deleted file mode 100644 index b4b0b6c..0000000 --- a/dist/commonjs/sanitize-html.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.SanitizeHTMLValueConverter = undefined; - -var _dec, _dec2, _class; - -var _aureliaBinding = require('aurelia-binding'); - -var _aureliaDependencyInjection = require('aurelia-dependency-injection'); - -var _htmlSanitizer = require('./html-sanitizer'); - - - -var SanitizeHTMLValueConverter = exports.SanitizeHTMLValueConverter = (_dec = (0, _aureliaBinding.valueConverter)('sanitizeHTML'), _dec2 = (0, _aureliaDependencyInjection.inject)(_htmlSanitizer.HTMLSanitizer), _dec(_class = _dec2(_class = function () { - function SanitizeHTMLValueConverter(sanitizer) { - - - this.sanitizer = sanitizer; - } - - SanitizeHTMLValueConverter.prototype.toView = function toView(untrustedMarkup) { - if (untrustedMarkup === null || untrustedMarkup === undefined) { - return null; - } - - return this.sanitizer.sanitize(untrustedMarkup); - }; - - return SanitizeHTMLValueConverter; -}()) || _class) || _class); \ No newline at end of file diff --git a/dist/commonjs/self-binding-behavior.js b/dist/commonjs/self-binding-behavior.js deleted file mode 100644 index 5113875..0000000 --- a/dist/commonjs/self-binding-behavior.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.SelfBindingBehavior = undefined; - -var _dec, _class; - -var _aureliaBinding = require('aurelia-binding'); - - - -function findOriginalEventTarget(event) { - return event.path && event.path[0] || event.deepPath && event.deepPath[0] || event.target; -} - -function handleSelfEvent(event) { - var target = findOriginalEventTarget(event); - if (this.target !== target) return; - this.selfEventCallSource(event); -} - -var SelfBindingBehavior = exports.SelfBindingBehavior = (_dec = (0, _aureliaBinding.bindingBehavior)('self'), _dec(_class = function () { - function SelfBindingBehavior() { - - } - - SelfBindingBehavior.prototype.bind = function bind(binding, source) { - if (!binding.callSource || !binding.targetEvent) throw new Error('Self binding behavior only supports event.'); - binding.selfEventCallSource = binding.callSource; - binding.callSource = handleSelfEvent; - }; - - SelfBindingBehavior.prototype.unbind = function unbind(binding, source) { - binding.callSource = binding.selfEventCallSource; - binding.selfEventCallSource = null; - }; - - return SelfBindingBehavior; -}()) || _class); \ No newline at end of file diff --git a/dist/commonjs/set-repeat-strategy.js b/dist/commonjs/set-repeat-strategy.js deleted file mode 100644 index dcc5db9..0000000 --- a/dist/commonjs/set-repeat-strategy.js +++ /dev/null @@ -1,104 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.SetRepeatStrategy = undefined; - -var _repeatUtilities = require('./repeat-utilities'); - - - -var SetRepeatStrategy = exports.SetRepeatStrategy = function () { - function SetRepeatStrategy() { - - } - - SetRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getSetObserver(items); - }; - - SetRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this._standardProcessItems(repeat, items); - }); - return; - } - this._standardProcessItems(repeat, items); - }; - - SetRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, items) { - var index = 0; - var overrideContext = void 0; - - items.forEach(function (value) { - overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, value, index, items.size); - repeat.addView(overrideContext.bindingContext, overrideContext); - ++index; - }); - }; - - SetRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, set, records) { - var value = void 0; - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var removeIndex = void 0; - var record = void 0; - var rmPromises = []; - var viewOrPromise = void 0; - - for (i = 0, ii = records.length; i < ii; ++i) { - record = records[i]; - value = record.value; - switch (record.type) { - case 'add': - var size = Math.max(set.size - 1, 0); - overrideContext = (0, _repeatUtilities.createFullOverrideContext)(repeat, value, size, set.size); - repeat.insertView(size, overrideContext.bindingContext, overrideContext); - break; - case 'delete': - removeIndex = this._getViewIndexByValue(repeat, value); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - break; - case 'clear': - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - break; - default: - continue; - } - } - - if (rmPromises.length > 0) { - Promise.all(rmPromises).then(function () { - (0, _repeatUtilities.updateOverrideContexts)(repeat.views(), 0); - }); - } else { - (0, _repeatUtilities.updateOverrideContexts)(repeat.views(), 0); - } - }; - - SetRepeatStrategy.prototype._getViewIndexByValue = function _getViewIndexByValue(repeat, value) { - var i = void 0; - var ii = void 0; - var child = void 0; - - for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { - child = repeat.view(i); - if (child.bindingContext[repeat.local] === value) { - return i; - } - } - - return undefined; - }; - - return SetRepeatStrategy; -}(); \ No newline at end of file diff --git a/dist/commonjs/show.js b/dist/commonjs/show.js deleted file mode 100644 index baf442f..0000000 --- a/dist/commonjs/show.js +++ /dev/null @@ -1,50 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.Show = undefined; - -var _dec, _class; - -var _aureliaDependencyInjection = require('aurelia-dependency-injection'); - -var _aureliaTemplating = require('aurelia-templating'); - -var _aureliaPal = require('aurelia-pal'); - -var _aureliaHideStyle = require('./aurelia-hide-style'); - - - -var Show = exports.Show = (_dec = (0, _aureliaTemplating.customAttribute)('show'), _dec(_class = function () { - Show.inject = function inject() { - return [_aureliaPal.DOM.Element, _aureliaTemplating.Animator, _aureliaDependencyInjection.Optional.of(_aureliaPal.DOM.boundary, true)]; - }; - - function Show(element, animator, domBoundary) { - - - this.element = element; - this.animator = animator; - this.domBoundary = domBoundary; - } - - Show.prototype.created = function created() { - (0, _aureliaHideStyle.injectAureliaHideStyleAtBoundary)(this.domBoundary); - }; - - Show.prototype.valueChanged = function valueChanged(newValue) { - if (newValue) { - this.animator.removeClass(this.element, _aureliaHideStyle.aureliaHideClassName); - } else { - this.animator.addClass(this.element, _aureliaHideStyle.aureliaHideClassName); - } - }; - - Show.prototype.bind = function bind(bindingContext) { - this.valueChanged(this.value); - }; - - return Show; -}()) || _class); \ No newline at end of file diff --git a/dist/commonjs/signal-binding-behavior.js b/dist/commonjs/signal-binding-behavior.js deleted file mode 100644 index f81303f..0000000 --- a/dist/commonjs/signal-binding-behavior.js +++ /dev/null @@ -1,72 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.SignalBindingBehavior = undefined; - -var _dec, _class; - -var _aureliaBinding = require('aurelia-binding'); - -var _bindingSignaler = require('./binding-signaler'); - - - -var SignalBindingBehavior = exports.SignalBindingBehavior = (_dec = (0, _aureliaBinding.bindingBehavior)('signal'), _dec(_class = function () { - SignalBindingBehavior.inject = function inject() { - return [_bindingSignaler.BindingSignaler]; - }; - - function SignalBindingBehavior(bindingSignaler) { - - - this.signals = bindingSignaler.signals; - } - - SignalBindingBehavior.prototype.bind = function bind(binding, source) { - if (!binding.updateTarget) { - throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.'); - } - - for (var _len = arguments.length, names = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { - names[_key - 2] = arguments[_key]; - } - - if (names.length === 1) { - var name = names[0]; - var bindings = this.signals[name] || (this.signals[name] = []); - bindings.push(binding); - binding.signalName = name; - } else if (names.length > 1) { - var i = names.length; - while (i--) { - var _name = names[i]; - var _bindings = this.signals[_name] || (this.signals[_name] = []); - _bindings.push(binding); - } - binding.signalName = names; - } else { - throw new Error('Signal name is required.'); - } - }; - - SignalBindingBehavior.prototype.unbind = function unbind(binding, source) { - var name = binding.signalName; - binding.signalName = null; - if (Array.isArray(name)) { - var _names = name; - var i = _names.length; - while (i--) { - var n = _names[i]; - var bindings = this.signals[n]; - bindings.splice(bindings.indexOf(binding), 1); - } - } else { - var _bindings2 = this.signals[name]; - _bindings2.splice(_bindings2.indexOf(binding), 1); - } - }; - - return SignalBindingBehavior; -}()) || _class); \ No newline at end of file diff --git a/dist/commonjs/throttle-binding-behavior.js b/dist/commonjs/throttle-binding-behavior.js deleted file mode 100644 index 09b4755..0000000 --- a/dist/commonjs/throttle-binding-behavior.js +++ /dev/null @@ -1,72 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.ThrottleBindingBehavior = undefined; - -var _dec, _class; - -var _aureliaBinding = require('aurelia-binding'); - - - -function throttle(newValue) { - var _this = this; - - var state = this.throttleState; - var elapsed = +new Date() - state.last; - if (elapsed >= state.delay) { - clearTimeout(state.timeoutId); - state.timeoutId = null; - state.last = +new Date(); - this.throttledMethod(newValue); - return; - } - state.newValue = newValue; - if (state.timeoutId === null) { - state.timeoutId = setTimeout(function () { - state.timeoutId = null; - state.last = +new Date(); - _this.throttledMethod(state.newValue); - }, state.delay - elapsed); - } -} - -var ThrottleBindingBehavior = exports.ThrottleBindingBehavior = (_dec = (0, _aureliaBinding.bindingBehavior)('throttle'), _dec(_class = function () { - function ThrottleBindingBehavior() { - - } - - ThrottleBindingBehavior.prototype.bind = function bind(binding, source) { - var delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200; - - var methodToThrottle = 'updateTarget'; - if (binding.callSource) { - methodToThrottle = 'callSource'; - } else if (binding.updateSource && binding.mode === _aureliaBinding.bindingMode.twoWay) { - methodToThrottle = 'updateSource'; - } - - binding.throttledMethod = binding[methodToThrottle]; - binding.throttledMethod.originalName = methodToThrottle; - - binding[methodToThrottle] = throttle; - - binding.throttleState = { - delay: delay, - last: 0, - timeoutId: null - }; - }; - - ThrottleBindingBehavior.prototype.unbind = function unbind(binding, source) { - var methodToRestore = binding.throttledMethod.originalName; - binding[methodToRestore] = binding.throttledMethod; - binding.throttledMethod = null; - clearTimeout(binding.throttleState.timeoutId); - binding.throttleState = null; - }; - - return ThrottleBindingBehavior; -}()) || _class); \ No newline at end of file diff --git a/dist/commonjs/update-trigger-binding-behavior.js b/dist/commonjs/update-trigger-binding-behavior.js deleted file mode 100644 index 3006418..0000000 --- a/dist/commonjs/update-trigger-binding-behavior.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.UpdateTriggerBindingBehavior = undefined; - -var _dec, _class; - -var _aureliaBinding = require('aurelia-binding'); - - - -var eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg '; -var notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.'; - -var UpdateTriggerBindingBehavior = exports.UpdateTriggerBindingBehavior = (_dec = (0, _aureliaBinding.bindingBehavior)('updateTrigger'), _dec(_class = function () { - function UpdateTriggerBindingBehavior() { - - } - - UpdateTriggerBindingBehavior.prototype.bind = function bind(binding, source) { - for (var _len = arguments.length, events = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { - events[_key - 2] = arguments[_key]; - } - - if (events.length === 0) { - throw new Error(eventNamesRequired); - } - if (binding.mode !== _aureliaBinding.bindingMode.twoWay && binding.mode !== _aureliaBinding.bindingMode.fromView) { - throw new Error(notApplicableMessage); - } - - var targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty); - if (!targetObserver.handler) { - throw new Error(notApplicableMessage); - } - binding.targetObserver = targetObserver; - - targetObserver.originalHandler = binding.targetObserver.handler; - - var handler = new _aureliaBinding.EventSubscriber(events); - targetObserver.handler = handler; - }; - - UpdateTriggerBindingBehavior.prototype.unbind = function unbind(binding, source) { - binding.targetObserver.handler.dispose(); - binding.targetObserver.handler = binding.targetObserver.originalHandler; - binding.targetObserver.originalHandler = null; - }; - - return UpdateTriggerBindingBehavior; -}()) || _class); \ No newline at end of file diff --git a/dist/commonjs/with.js b/dist/commonjs/with.js deleted file mode 100644 index 42179a6..0000000 --- a/dist/commonjs/with.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.With = undefined; - -var _dec, _dec2, _class; - -var _aureliaDependencyInjection = require('aurelia-dependency-injection'); - -var _aureliaTemplating = require('aurelia-templating'); - -var _aureliaBinding = require('aurelia-binding'); - - - -var With = exports.With = (_dec = (0, _aureliaTemplating.customAttribute)('with'), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.ViewSlot), _dec(_class = (0, _aureliaTemplating.templateController)(_class = _dec2(_class = function () { - function With(viewFactory, viewSlot) { - - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.parentOverrideContext = null; - this.view = null; - } - - With.prototype.bind = function bind(bindingContext, overrideContext) { - this.parentOverrideContext = overrideContext; - this.valueChanged(this.value); - }; - - With.prototype.valueChanged = function valueChanged(newValue) { - var overrideContext = (0, _aureliaBinding.createOverrideContext)(newValue, this.parentOverrideContext); - if (!this.view) { - this.view = this.viewFactory.create(); - this.view.bind(newValue, overrideContext); - this.viewSlot.add(this.view); - } else { - this.view.bind(newValue, overrideContext); - } - }; - - With.prototype.unbind = function unbind() { - this.parentOverrideContext = null; - - if (this.view) { - this.view.unbind(); - } - }; - - return With; -}()) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/es2015/abstract-repeater.js b/dist/es2015/abstract-repeater.js deleted file mode 100644 index d0b3788..0000000 --- a/dist/es2015/abstract-repeater.js +++ /dev/null @@ -1,53 +0,0 @@ - -export let AbstractRepeater = class AbstractRepeater { - constructor(options) { - Object.assign(this, { - local: 'items', - viewsRequireLifecycle: true - }, options); - } - - viewCount() { - throw new Error('subclass must implement `viewCount`'); - } - - views() { - throw new Error('subclass must implement `views`'); - } - - view(index) { - throw new Error('subclass must implement `view`'); - } - - matcher() { - throw new Error('subclass must implement `matcher`'); - } - - addView(bindingContext, overrideContext) { - throw new Error('subclass must implement `addView`'); - } - - insertView(index, bindingContext, overrideContext) { - throw new Error('subclass must implement `insertView`'); - } - - moveView(sourceIndex, targetIndex) { - throw new Error('subclass must implement `moveView`'); - } - - removeAllViews(returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeAllViews`'); - } - - removeViews(viewsToRemove, returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeView`'); - } - - removeView(index, returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeView`'); - } - - updateBindings(view) { - throw new Error('subclass must implement `updateBindings`'); - } -}; \ No newline at end of file diff --git a/dist/es2015/analyze-view-factory.js b/dist/es2015/analyze-view-factory.js deleted file mode 100644 index fa0c7f7..0000000 --- a/dist/es2015/analyze-view-factory.js +++ /dev/null @@ -1,50 +0,0 @@ - -export const lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with']; - -function behaviorRequiresLifecycle(instruction) { - let t = instruction.type; - let name = t.elementName !== null ? t.elementName : t.attributeName; - return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind) || t.viewFactory && viewsRequireLifecycle(t.viewFactory) || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); -} - -function targetRequiresLifecycle(instruction) { - let behaviors = instruction.behaviorInstructions; - if (behaviors) { - let i = behaviors.length; - while (i--) { - if (behaviorRequiresLifecycle(behaviors[i])) { - return true; - } - } - } - - return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); -} - -export function viewsRequireLifecycle(viewFactory) { - if ('_viewsRequireLifecycle' in viewFactory) { - return viewFactory._viewsRequireLifecycle; - } - - viewFactory._viewsRequireLifecycle = false; - - if (viewFactory.viewFactory) { - viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory); - return viewFactory._viewsRequireLifecycle; - } - - if (viewFactory.template.querySelector('.au-animate')) { - viewFactory._viewsRequireLifecycle = true; - return true; - } - - for (let id in viewFactory.instructions) { - if (targetRequiresLifecycle(viewFactory.instructions[id])) { - viewFactory._viewsRequireLifecycle = true; - return true; - } - } - - viewFactory._viewsRequireLifecycle = false; - return false; -} \ No newline at end of file diff --git a/dist/es2015/array-repeat-strategy.js b/dist/es2015/array-repeat-strategy.js deleted file mode 100644 index 8b4a086..0000000 --- a/dist/es2015/array-repeat-strategy.js +++ /dev/null @@ -1,213 +0,0 @@ -import { createFullOverrideContext, updateOverrideContexts, updateOverrideContext, indexOf } from './repeat-utilities'; -import { mergeSplice } from 'aurelia-binding'; - -export let ArrayRepeatStrategy = class ArrayRepeatStrategy { - getCollectionObserver(observerLocator, items) { - return observerLocator.getArrayObserver(items); - } - - instanceChanged(repeat, items) { - const itemsLength = items.length; - - if (!items || itemsLength === 0) { - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - return; - } - - const children = repeat.views(); - const viewsLength = children.length; - - if (viewsLength === 0) { - this._standardProcessInstanceChanged(repeat, items); - return; - } - - if (repeat.viewsRequireLifecycle) { - const childrenSnapshot = children.slice(0); - const itemNameInBindingContext = repeat.local; - const matcher = repeat.matcher(); - - let itemsPreviouslyInViews = []; - const viewsToRemove = []; - - for (let index = 0; index < viewsLength; index++) { - const view = childrenSnapshot[index]; - const oldItem = view.bindingContext[itemNameInBindingContext]; - - if (indexOf(items, oldItem, matcher) === -1) { - viewsToRemove.push(view); - } else { - itemsPreviouslyInViews.push(oldItem); - } - } - - let updateViews; - let removePromise; - - if (itemsPreviouslyInViews.length > 0) { - removePromise = repeat.removeViews(viewsToRemove, true, !repeat.viewsRequireLifecycle); - updateViews = () => { - for (let index = 0; index < itemsLength; index++) { - const item = items[index]; - const indexOfView = indexOf(itemsPreviouslyInViews, item, matcher, index); - let view; - - if (indexOfView === -1) { - const overrideContext = createFullOverrideContext(repeat, items[index], index, itemsLength); - repeat.insertView(index, overrideContext.bindingContext, overrideContext); - - itemsPreviouslyInViews.splice(index, 0, undefined); - } else if (indexOfView === index) { - view = children[indexOfView]; - itemsPreviouslyInViews[indexOfView] = undefined; - } else { - view = children[indexOfView]; - repeat.moveView(indexOfView, index); - itemsPreviouslyInViews.splice(indexOfView, 1); - itemsPreviouslyInViews.splice(index, 0, undefined); - } - - if (view) { - updateOverrideContext(view.overrideContext, index, itemsLength); - } - } - - this._inPlaceProcessItems(repeat, items); - }; - } else { - removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - updateViews = () => this._standardProcessInstanceChanged(repeat, items); - } - - if (removePromise instanceof Promise) { - removePromise.then(updateViews); - } else { - updateViews(); - } - } else { - this._inPlaceProcessItems(repeat, items); - } - } - - _standardProcessInstanceChanged(repeat, items) { - for (let i = 0, ii = items.length; i < ii; i++) { - let overrideContext = createFullOverrideContext(repeat, items[i], i, ii); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - } - - _inPlaceProcessItems(repeat, items) { - let itemsLength = items.length; - let viewsLength = repeat.viewCount(); - - while (viewsLength > itemsLength) { - viewsLength--; - repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle); - } - - let local = repeat.local; - - for (let i = 0; i < viewsLength; i++) { - let view = repeat.view(i); - let last = i === itemsLength - 1; - let middle = i !== 0 && !last; - - if (view.bindingContext[local] === items[i] && view.overrideContext.$middle === middle && view.overrideContext.$last === last) { - continue; - } - - view.bindingContext[local] = items[i]; - view.overrideContext.$middle = middle; - view.overrideContext.$last = last; - repeat.updateBindings(view); - } - - for (let i = viewsLength; i < itemsLength; i++) { - let overrideContext = createFullOverrideContext(repeat, items[i], i, itemsLength); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - } - - instanceMutated(repeat, array, splices) { - if (repeat.__queuedSplices) { - for (let i = 0, ii = splices.length; i < ii; ++i) { - let { index, removed, addedCount } = splices[i]; - mergeSplice(repeat.__queuedSplices, index, removed, addedCount); - } - - repeat.__array = array.slice(0); - return; - } - - let maybePromise = this._runSplices(repeat, array.slice(0), splices); - if (maybePromise instanceof Promise) { - let queuedSplices = repeat.__queuedSplices = []; - - let runQueuedSplices = () => { - if (!queuedSplices.length) { - repeat.__queuedSplices = undefined; - repeat.__array = undefined; - return; - } - - let nextPromise = this._runSplices(repeat, repeat.__array, queuedSplices) || Promise.resolve(); - queuedSplices = repeat.__queuedSplices = []; - nextPromise.then(runQueuedSplices); - }; - - maybePromise.then(runQueuedSplices); - } - } - - _runSplices(repeat, array, splices) { - let removeDelta = 0; - let rmPromises = []; - - for (let i = 0, ii = splices.length; i < ii; ++i) { - let splice = splices[i]; - let removed = splice.removed; - - for (let j = 0, jj = removed.length; j < jj; ++j) { - let viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - } - removeDelta -= splice.addedCount; - } - - if (rmPromises.length > 0) { - return Promise.all(rmPromises).then(() => { - let spliceIndexLow = this._handleAddedSplices(repeat, array, splices); - updateOverrideContexts(repeat.views(), spliceIndexLow); - }); - } - - let spliceIndexLow = this._handleAddedSplices(repeat, array, splices); - updateOverrideContexts(repeat.views(), spliceIndexLow); - - return undefined; - } - - _handleAddedSplices(repeat, array, splices) { - let spliceIndex; - let spliceIndexLow; - let arrayLength = array.length; - for (let i = 0, ii = splices.length; i < ii; ++i) { - let splice = splices[i]; - let addIndex = spliceIndex = splice.index; - let end = splice.index + splice.addedCount; - - if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) { - spliceIndexLow = spliceIndex; - } - - for (; addIndex < end; ++addIndex) { - let overrideContext = createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength); - repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext); - } - } - - return spliceIndexLow; - } -}; \ No newline at end of file diff --git a/dist/es2015/attr-binding-behavior.js b/dist/es2015/attr-binding-behavior.js deleted file mode 100644 index 9f6bcf5..0000000 --- a/dist/es2015/attr-binding-behavior.js +++ /dev/null @@ -1,11 +0,0 @@ -var _dec, _class; - -import { DataAttributeObserver, bindingBehavior } from 'aurelia-binding'; - -export let AttrBindingBehavior = (_dec = bindingBehavior('attr'), _dec(_class = class AttrBindingBehavior { - bind(binding, source) { - binding.targetObserver = new DataAttributeObserver(binding.target, binding.targetProperty); - } - - unbind(binding, source) {} -}) || _class); \ No newline at end of file diff --git a/dist/es2015/aurelia-hide-style.js b/dist/es2015/aurelia-hide-style.js deleted file mode 100644 index 58b7250..0000000 --- a/dist/es2015/aurelia-hide-style.js +++ /dev/null @@ -1,16 +0,0 @@ -import { FEATURE, DOM } from 'aurelia-pal'; - -export const aureliaHideClassName = 'aurelia-hide'; - -const aureliaHideClass = `.${aureliaHideClassName} { display:none !important; }`; - -export function injectAureliaHideStyleAtHead() { - DOM.injectStyles(aureliaHideClass); -} - -export function injectAureliaHideStyleAtBoundary(domBoundary) { - if (FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) { - domBoundary.hasAureliaHideStyle = true; - DOM.injectStyles(aureliaHideClass, domBoundary); - } -} \ No newline at end of file diff --git a/dist/es2015/aurelia-templating-resources.js b/dist/es2015/aurelia-templating-resources.js index c5b931f..a37e684 100644 --- a/dist/es2015/aurelia-templating-resources.js +++ b/dist/es2015/aurelia-templating-resources.js @@ -1,50 +1,1773 @@ -import { Compose } from './compose'; -import { If } from './if'; -import { Else } from './else'; -import { With } from './with'; -import { Repeat } from './repeat'; -import { Show } from './show'; -import { Hide } from './hide'; -import { SanitizeHTMLValueConverter } from './sanitize-html'; -import { Replaceable } from './replaceable'; -import { Focus } from './focus'; -import { ViewEngine } from 'aurelia-templating'; -import { _createCSSResource } from './css-resource'; -import { HTMLSanitizer } from './html-sanitizer'; -import { AttrBindingBehavior } from './attr-binding-behavior'; -import { OneTimeBindingBehavior, OneWayBindingBehavior, TwoWayBindingBehavior, FromViewBindingBehavior, ToViewBindingBehavior } from './binding-mode-behaviors'; -import { ThrottleBindingBehavior } from './throttle-binding-behavior'; -import { DebounceBindingBehavior } from './debounce-binding-behavior'; -import { SelfBindingBehavior } from './self-binding-behavior'; -import { SignalBindingBehavior } from './signal-binding-behavior'; -import { BindingSignaler } from './binding-signaler'; -import { UpdateTriggerBindingBehavior } from './update-trigger-binding-behavior'; -import { AbstractRepeater } from './abstract-repeater'; -import { RepeatStrategyLocator } from './repeat-strategy-locator'; -import { configure as configureHtmlResourcePlugin } from './html-resource-plugin'; -import { NullRepeatStrategy } from './null-repeat-strategy'; -import { ArrayRepeatStrategy } from './array-repeat-strategy'; -import { MapRepeatStrategy } from './map-repeat-strategy'; -import { SetRepeatStrategy } from './set-repeat-strategy'; -import { NumberRepeatStrategy } from './number-repeat-strategy'; -import { createFullOverrideContext, updateOverrideContext, getItemsSourceExpression, isOneTime, updateOneTimeBinding, unwrapExpression } from './repeat-utilities'; -import { viewsRequireLifecycle } from './analyze-view-factory'; -import { injectAureliaHideStyleAtHead } from './aurelia-hide-style'; - -function configure(config) { - injectAureliaHideStyleAtHead(); - - config.globalResources(Compose, If, Else, With, Repeat, Show, Hide, Replaceable, Focus, SanitizeHTMLValueConverter, OneTimeBindingBehavior, OneWayBindingBehavior, ToViewBindingBehavior, FromViewBindingBehavior, TwoWayBindingBehavior, ThrottleBindingBehavior, DebounceBindingBehavior, SelfBindingBehavior, SignalBindingBehavior, UpdateTriggerBindingBehavior, AttrBindingBehavior); - - configureHtmlResourcePlugin(config); - - let viewEngine = config.container.get(ViewEngine); - let styleResourcePlugin = { - fetch(address) { - return { [address]: _createCSSResource(address) }; - } - }; - ['.css', '.less', '.sass', '.scss', '.styl'].forEach(ext => viewEngine.addResourcePlugin(ext, styleResourcePlugin)); -} - -export { Compose, If, Else, With, Repeat, Show, Hide, HTMLSanitizer, SanitizeHTMLValueConverter, Replaceable, Focus, configure, AttrBindingBehavior, OneTimeBindingBehavior, OneWayBindingBehavior, ToViewBindingBehavior, FromViewBindingBehavior, TwoWayBindingBehavior, ThrottleBindingBehavior, DebounceBindingBehavior, SelfBindingBehavior, SignalBindingBehavior, BindingSignaler, UpdateTriggerBindingBehavior, AbstractRepeater, RepeatStrategyLocator, NullRepeatStrategy, ArrayRepeatStrategy, MapRepeatStrategy, SetRepeatStrategy, NumberRepeatStrategy, createFullOverrideContext, updateOverrideContext, getItemsSourceExpression, isOneTime, updateOneTimeBinding, unwrapExpression, viewsRequireLifecycle }; \ No newline at end of file +import { Container, inject, Optional } from 'aurelia-dependency-injection'; +import { DOM, FEATURE } from 'aurelia-pal'; +import { TaskQueue } from 'aurelia-task-queue'; +import { CompositionEngine, ViewSlot, ViewResources, bindable, noView, customElement, customAttribute, templateController, BoundViewFactory, TargetInstruction, Animator, resource, useView, useShadowDOM, ViewEngine } from 'aurelia-templating'; +import { createOverrideContext, bindingMode, BindingBehavior, ValueConverter, sourceContext, mergeSplice, ObserverLocator, valueConverter, DataAttributeObserver, bindingBehavior, targetContext, EventSubscriber } from 'aurelia-binding'; +import { getLogger } from 'aurelia-logging'; +import { Loader } from 'aurelia-loader'; +import { relativeToFile } from 'aurelia-path'; +import { mixin } from 'aurelia-metadata'; + +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + +function __decorate(decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +} + +let Compose = class Compose { + constructor(element, container, compositionEngine, viewSlot, viewResources, taskQueue) { + this.element = element; + this.container = container; + this.compositionEngine = compositionEngine; + this.viewSlot = viewSlot; + this.viewResources = viewResources; + this.taskQueue = taskQueue; + this.currentController = null; + this.currentViewModel = null; + this.changes = Object.create(null); + } + static inject() { + return [DOM.Element, Container, CompositionEngine, ViewSlot, ViewResources, TaskQueue]; + } + created(owningView) { + this.owningView = owningView; + } + bind(bindingContext, overrideContext) { + this.bindingContext = bindingContext; + this.overrideContext = overrideContext; + let changes = this.changes; + changes.view = this.view; + changes.viewModel = this.viewModel; + changes.model = this.model; + if (!this.pendingTask) { + processChanges(this); + } + } + unbind() { + this.changes = Object.create(null); + this.bindingContext = null; + this.overrideContext = null; + let returnToCache = true; + let skipAnimation = true; + this.viewSlot.removeAll(returnToCache, skipAnimation); + } + modelChanged(newValue, oldValue) { + this.changes.model = newValue; + requestUpdate(this); + } + viewChanged(newValue, oldValue) { + this.changes.view = newValue; + requestUpdate(this); + } + viewModelChanged(newValue, oldValue) { + this.changes.viewModel = newValue; + requestUpdate(this); + } +}; +__decorate([ + bindable +], Compose.prototype, "model", void 0); +__decorate([ + bindable +], Compose.prototype, "view", void 0); +__decorate([ + bindable +], Compose.prototype, "viewModel", void 0); +__decorate([ + bindable +], Compose.prototype, "swapOrder", void 0); +Compose = __decorate([ + noView, + customElement('compose') +], Compose); +function isEmpty(obj) { + for (const _ in obj) { + return false; + } + return true; +} +function tryActivateViewModel(vm, model) { + if (vm && typeof vm.activate === 'function') { + return Promise.resolve(vm.activate(model)); + } +} +function createInstruction(composer, instruction) { + return Object.assign(instruction, { + bindingContext: composer.bindingContext, + overrideContext: composer.overrideContext, + owningView: composer.owningView, + container: composer.container, + viewSlot: composer.viewSlot, + viewResources: composer.viewResources, + currentController: composer.currentController, + host: composer.element, + swapOrder: composer.swapOrder + }); +} +function processChanges(composer) { + const changes = composer.changes; + composer.changes = Object.create(null); + if (!('view' in changes) && !('viewModel' in changes) && ('model' in changes)) { + composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model); + if (!composer.pendingTask) { + return; + } + } + else { + let instruction = { + view: composer.view, + viewModel: composer.currentViewModel || composer.viewModel, + model: composer.model + }; + instruction = Object.assign(instruction, changes); + instruction = createInstruction(composer, instruction); + composer.pendingTask = composer.compositionEngine.compose(instruction).then(controller => { + composer.currentController = controller; + composer.currentViewModel = controller ? controller.viewModel : null; + }); + } + composer.pendingTask = composer.pendingTask + .then(() => { + completeCompositionTask(composer); + }, reason => { + completeCompositionTask(composer); + throw reason; + }); +} +function completeCompositionTask(composer) { + composer.pendingTask = null; + if (!isEmpty(composer.changes)) { + processChanges(composer); + } +} +function requestUpdate(composer) { + if (composer.pendingTask || composer.updateRequested) { + return; + } + composer.updateRequested = true; + composer.taskQueue.queueMicroTask(() => { + composer.updateRequested = false; + processChanges(composer); + }); +} + +class IfCore { + constructor(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.view = null; + this.bindingContext = null; + this.overrideContext = null; + this.showing = false; + this.cache = true; + } + bind(bindingContext, overrideContext) { + this.bindingContext = bindingContext; + this.overrideContext = overrideContext; + } + unbind() { + if (this.view === null) { + return; + } + this.view.unbind(); + if (!this.viewFactory.isCaching) { + return; + } + if (this.showing) { + this.showing = false; + this.viewSlot.remove(this.view, true, true); + } + else { + this.view.returnToCache(); + } + this.view = null; + } + _show() { + if (this.showing) { + if (!this.view.isBound) { + this.view.bind(this.bindingContext, this.overrideContext); + } + return; + } + if (this.view === null) { + this.view = this.viewFactory.create(); + } + if (!this.view.isBound) { + this.view.bind(this.bindingContext, this.overrideContext); + } + this.showing = true; + return this.viewSlot.add(this.view); + } + _hide() { + if (!this.showing) { + return; + } + this.showing = false; + let removed = this.viewSlot.remove(this.view); + if (removed instanceof Promise) { + return removed.then(() => { + this._unbindView(); + }); + } + this._unbindView(); + } + _unbindView() { + const cache = this.cache === 'false' ? false : !!this.cache; + this.view.unbind(); + if (!cache) { + this.view = null; + } + } +} + +let If = class If extends IfCore { + constructor() { + super(...arguments); + this.cache = true; + } + bind(bindingContext, overrideContext) { + super.bind(bindingContext, overrideContext); + if (this.condition) { + this._show(); + } + else { + this._hide(); + } + } + conditionChanged(newValue) { + this._update(newValue); + } + _update(show) { + if (this.animating) { + return; + } + let promise; + if (this.elseVm) { + promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm); + } + else { + promise = show ? this._show() : this._hide(); + } + if (promise) { + this.animating = true; + promise.then(() => { + this.animating = false; + if (this.condition !== this.showing) { + this._update(this.condition); + } + }); + } + } + _swap(remove, add) { + switch (this.swapOrder) { + case 'before': + return Promise.resolve(add._show()).then(() => remove._hide()); + case 'with': + return Promise.all([remove._hide(), add._show()]); + default: + let promise = remove._hide(); + return promise ? promise.then(() => add._show()) : add._show(); + } + } +}; +__decorate([ + bindable({ primaryProperty: true }) +], If.prototype, "condition", void 0); +__decorate([ + bindable +], If.prototype, "swapOrder", void 0); +__decorate([ + bindable +], If.prototype, "cache", void 0); +If = __decorate([ + customAttribute('if'), + templateController, + inject(BoundViewFactory, ViewSlot) +], If); + +let Else = class Else extends IfCore { + constructor(viewFactory, viewSlot) { + super(viewFactory, viewSlot); + this._registerInIf(); + } + bind(bindingContext, overrideContext) { + super.bind(bindingContext, overrideContext); + if (this.ifVm.condition) { + this._hide(); + } + else { + this._show(); + } + } + _registerInIf() { + let previous = this.viewSlot.anchor.previousSibling; + while (previous && !previous.au) { + previous = previous.previousSibling; + } + if (!previous || !previous.au.if) { + throw new Error("Can't find matching If for Else custom attribute."); + } + this.ifVm = previous.au.if.viewModel; + this.ifVm.elseVm = this; + } +}; +Else = __decorate([ + customAttribute('else'), + templateController, + inject(BoundViewFactory, ViewSlot) +], Else); + +let With = class With { + constructor(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.parentOverrideContext = null; + this.view = null; + } + bind(bindingContext, overrideContext) { + this.parentOverrideContext = overrideContext; + this.valueChanged(this.value); + } + valueChanged(newValue) { + let overrideContext = createOverrideContext(newValue, this.parentOverrideContext); + let view = this.view; + if (!view) { + view = this.view = this.viewFactory.create(); + view.bind(newValue, overrideContext); + this.viewSlot.add(view); + } + else { + view.bind(newValue, overrideContext); + } + } + unbind() { + let view = this.view; + this.parentOverrideContext = null; + if (view) { + view.unbind(); + } + } +}; +With = __decorate([ + customAttribute('with'), + templateController, + inject(BoundViewFactory, ViewSlot) +], With); + +const oneTime = bindingMode.oneTime; +function updateOverrideContexts(views, startIndex) { + let length = views.length; + if (startIndex > 0) { + startIndex = startIndex - 1; + } + for (; startIndex < length; ++startIndex) { + updateOverrideContext(views[startIndex].overrideContext, startIndex, length); + } +} +function createFullOverrideContext(repeat, data, index, length, key) { + let bindingContext = {}; + let overrideContext = createOverrideContext(bindingContext, repeat.scope.overrideContext); + if (typeof key !== 'undefined') { + bindingContext[repeat.key] = key; + bindingContext[repeat.value] = data; + } + else { + bindingContext[repeat.local] = data; + } + updateOverrideContext(overrideContext, index, length); + return overrideContext; +} +function updateOverrideContext(overrideContext, index, length) { + let first = (index === 0); + let last = (index === length - 1); + let even = index % 2 === 0; + overrideContext.$index = index; + overrideContext.$first = first; + overrideContext.$last = last; + overrideContext.$middle = !(first || last); + overrideContext.$odd = !even; + overrideContext.$even = even; +} +function getItemsSourceExpression(instruction, attrName) { + return instruction.behaviorInstructions + .filter(bi => bi.originalAttrName === attrName)[0] + .attributes + .items + .sourceExpression; +} +function unwrapExpression(expression) { + let unwrapped = false; + while (expression instanceof BindingBehavior) { + expression = expression.expression; + } + while (expression instanceof ValueConverter) { + expression = expression.expression; + unwrapped = true; + } + return unwrapped ? expression : null; +} +function isOneTime(expression) { + while (expression instanceof BindingBehavior) { + if (expression.name === 'oneTime') { + return true; + } + expression = expression.expression; + } + return false; +} +function updateOneTimeBinding(binding) { + if (binding.call && binding.mode === oneTime) { + binding.call(sourceContext); + } + else if (binding.updateOneTimeBindings) { + binding.updateOneTimeBindings(); + } +} +function indexOf(array, item, matcher, startIndex) { + if (!matcher) { + return array.indexOf(item); + } + const length = array.length; + for (let index = startIndex || 0; index < length; index++) { + if (matcher(array[index], item)) { + return index; + } + } + return -1; +} + +class ArrayRepeatStrategy { + getCollectionObserver(observerLocator, items) { + return observerLocator.getArrayObserver(items); + } + instanceChanged(repeat, items) { + const itemsLength = items.length; + if (!items || itemsLength === 0) { + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + return; + } + const children = repeat.views(); + const viewsLength = children.length; + if (viewsLength === 0) { + this._standardProcessInstanceChanged(repeat, items); + return; + } + if (repeat.viewsRequireLifecycle) { + const childrenSnapshot = children.slice(0); + const itemNameInBindingContext = repeat.local; + const matcher = repeat.matcher(); + let itemsPreviouslyInViews = []; + const viewsToRemove = []; + for (let index = 0; index < viewsLength; index++) { + const view = childrenSnapshot[index]; + const oldItem = view.bindingContext[itemNameInBindingContext]; + if (indexOf(items, oldItem, matcher) === -1) { + viewsToRemove.push(view); + } + else { + itemsPreviouslyInViews.push(oldItem); + } + } + let updateViews; + let removePromise; + if (itemsPreviouslyInViews.length > 0) { + removePromise = repeat.removeViews(viewsToRemove, true, !repeat.viewsRequireLifecycle); + updateViews = () => { + for (let index = 0; index < itemsLength; index++) { + const item = items[index]; + const indexOfView = indexOf(itemsPreviouslyInViews, item, matcher, index); + let view; + if (indexOfView === -1) { + const overrideContext = createFullOverrideContext(repeat, items[index], index, itemsLength); + repeat.insertView(index, overrideContext.bindingContext, overrideContext); + itemsPreviouslyInViews.splice(index, 0, undefined); + } + else if (indexOfView === index) { + view = children[indexOfView]; + itemsPreviouslyInViews[indexOfView] = undefined; + } + else { + view = children[indexOfView]; + repeat.moveView(indexOfView, index); + itemsPreviouslyInViews.splice(indexOfView, 1); + itemsPreviouslyInViews.splice(index, 0, undefined); + } + if (view) { + updateOverrideContext(view.overrideContext, index, itemsLength); + } + } + this._inPlaceProcessItems(repeat, items); + }; + } + else { + removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + updateViews = () => this._standardProcessInstanceChanged(repeat, items); + } + if (removePromise instanceof Promise) { + removePromise.then(updateViews); + } + else { + updateViews(); + } + } + else { + this._inPlaceProcessItems(repeat, items); + } + } + _standardProcessInstanceChanged(repeat, items) { + for (let i = 0, ii = items.length; i < ii; i++) { + let overrideContext = createFullOverrideContext(repeat, items[i], i, ii); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + } + _inPlaceProcessItems(repeat, items) { + let itemsLength = items.length; + let viewsLength = repeat.viewCount(); + while (viewsLength > itemsLength) { + viewsLength--; + repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle); + } + let local = repeat.local; + for (let i = 0; i < viewsLength; i++) { + let view = repeat.view(i); + let last = i === itemsLength - 1; + let middle = i !== 0 && !last; + let bindingContext = view.bindingContext; + let overrideContext = view.overrideContext; + if (bindingContext[local] === items[i] + && overrideContext.$middle === middle + && overrideContext.$last === last) { + continue; + } + bindingContext[local] = items[i]; + overrideContext.$middle = middle; + overrideContext.$last = last; + repeat.updateBindings(view); + } + for (let i = viewsLength; i < itemsLength; i++) { + let overrideContext = createFullOverrideContext(repeat, items[i], i, itemsLength); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + } + instanceMutated(repeat, array, splices) { + if (repeat.__queuedSplices) { + for (let i = 0, ii = splices.length; i < ii; ++i) { + let { index, removed, addedCount } = splices[i]; + mergeSplice(repeat.__queuedSplices, index, removed, addedCount); + } + repeat.__array = array.slice(0); + return; + } + let maybePromise = this._runSplices(repeat, array.slice(0), splices); + if (maybePromise instanceof Promise) { + let queuedSplices = repeat.__queuedSplices = []; + let runQueuedSplices = () => { + if (!queuedSplices.length) { + repeat.__queuedSplices = undefined; + repeat.__array = undefined; + return; + } + let nextPromise = this._runSplices(repeat, repeat.__array, queuedSplices) || Promise.resolve(); + queuedSplices = repeat.__queuedSplices = []; + nextPromise.then(runQueuedSplices); + }; + maybePromise.then(runQueuedSplices); + } + } + _runSplices(repeat, array, splices) { + let removeDelta = 0; + let rmPromises = []; + for (let i = 0, ii = splices.length; i < ii; ++i) { + let splice = splices[i]; + let removed = splice.removed; + for (let j = 0, jj = removed.length; j < jj; ++j) { + let viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + } + removeDelta -= splice.addedCount; + } + if (rmPromises.length > 0) { + return Promise.all(rmPromises).then(() => { + let spliceIndexLow = this._handleAddedSplices(repeat, array, splices); + updateOverrideContexts(repeat.views(), spliceIndexLow); + }); + } + let spliceIndexLow = this._handleAddedSplices(repeat, array, splices); + updateOverrideContexts(repeat.views(), spliceIndexLow); + return undefined; + } + _handleAddedSplices(repeat, array, splices) { + let spliceIndex; + let spliceIndexLow; + let arrayLength = array.length; + for (let i = 0, ii = splices.length; i < ii; ++i) { + let splice = splices[i]; + let addIndex = spliceIndex = splice.index; + let end = splice.index + splice.addedCount; + if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) { + spliceIndexLow = spliceIndex; + } + for (; addIndex < end; ++addIndex) { + let overrideContext = createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength); + repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext); + } + } + return spliceIndexLow; + } +} + +class MapRepeatStrategy { + getCollectionObserver(observerLocator, items) { + return observerLocator.getMapObserver(items); + } + instanceChanged(repeat, items) { + let removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(() => this._standardProcessItems(repeat, items)); + return; + } + this._standardProcessItems(repeat, items); + } + _standardProcessItems(repeat, items) { + let index = 0; + let overrideContext; + items.forEach((value, key) => { + overrideContext = createFullOverrideContext(repeat, value, index, items.size, key); + repeat.addView(overrideContext.bindingContext, overrideContext); + ++index; + }); + } + instanceMutated(repeat, map, records) { + let key; + let i; + let ii; + let overrideContext; + let removeIndex; + let addIndex; + let record; + let rmPromises = []; + let viewOrPromise; + for (i = 0, ii = records.length; i < ii; ++i) { + record = records[i]; + key = record.key; + switch (record.type) { + case 'update': + removeIndex = this._getViewIndexByKey(repeat, key); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + overrideContext = createFullOverrideContext(repeat, map.get(key), removeIndex, map.size, key); + repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext); + break; + case 'add': + addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1; + overrideContext = createFullOverrideContext(repeat, map.get(key), addIndex, map.size, key); + repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext); + break; + case 'delete': + if (record.oldValue === undefined) { + return; + } + removeIndex = this._getViewIndexByKey(repeat, key); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + break; + case 'clear': + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + break; + default: + continue; + } + } + if (rmPromises.length > 0) { + Promise.all(rmPromises).then(() => { + updateOverrideContexts(repeat.views(), 0); + }); + } + else { + updateOverrideContexts(repeat.views(), 0); + } + } + _getViewIndexByKey(repeat, key) { + let i; + let ii; + let child; + for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { + child = repeat.view(i); + if (child.bindingContext[repeat.key] === key) { + return i; + } + } + return undefined; + } +} + +class NullRepeatStrategy { + instanceChanged(repeat, items) { + repeat.removeAllViews(true); + } + getCollectionObserver(observerLocator, items) { + } +} + +class NumberRepeatStrategy { + getCollectionObserver() { + return null; + } + instanceChanged(repeat, value) { + let removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(() => this._standardProcessItems(repeat, value)); + return; + } + this._standardProcessItems(repeat, value); + } + _standardProcessItems(repeat, value) { + let childrenLength = repeat.viewCount(); + let i; + let ii; + let overrideContext; + let viewsToRemove; + value = Math.floor(value); + viewsToRemove = childrenLength - value; + if (viewsToRemove > 0) { + if (viewsToRemove > childrenLength) { + viewsToRemove = childrenLength; + } + for (i = 0, ii = viewsToRemove; i < ii; ++i) { + repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle); + } + return; + } + for (i = childrenLength, ii = value; i < ii; ++i) { + overrideContext = createFullOverrideContext(repeat, i, i, ii); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + updateOverrideContexts(repeat.views(), 0); + } +} + +class SetRepeatStrategy { + getCollectionObserver(observerLocator, items) { + return observerLocator.getSetObserver(items); + } + instanceChanged(repeat, items) { + let removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(() => this._standardProcessItems(repeat, items)); + return; + } + this._standardProcessItems(repeat, items); + } + _standardProcessItems(repeat, items) { + let index = 0; + let overrideContext; + items.forEach(value => { + overrideContext = createFullOverrideContext(repeat, value, index, items.size); + repeat.addView(overrideContext.bindingContext, overrideContext); + ++index; + }); + } + instanceMutated(repeat, set, records) { + let value; + let i; + let ii; + let overrideContext; + let removeIndex; + let record; + let rmPromises = []; + let viewOrPromise; + for (i = 0, ii = records.length; i < ii; ++i) { + record = records[i]; + value = record.value; + switch (record.type) { + case 'add': + let size = Math.max(set.size - 1, 0); + overrideContext = createFullOverrideContext(repeat, value, size, set.size); + repeat.insertView(size, overrideContext.bindingContext, overrideContext); + break; + case 'delete': + removeIndex = this._getViewIndexByValue(repeat, value); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + break; + case 'clear': + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + break; + default: + continue; + } + } + if (rmPromises.length > 0) { + Promise.all(rmPromises).then(() => { + updateOverrideContexts(repeat.views(), 0); + }); + } + else { + updateOverrideContexts(repeat.views(), 0); + } + } + _getViewIndexByValue(repeat, value) { + let i; + let ii; + let child; + for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { + child = repeat.view(i); + if (child.bindingContext[repeat.local] === value) { + return i; + } + } + return undefined; + } +} + +class RepeatStrategyLocator { + constructor() { + this.matchers = []; + this.strategies = []; + this.addStrategy(items => items === null || items === undefined, new NullRepeatStrategy()); + this.addStrategy(items => items instanceof Array, new ArrayRepeatStrategy()); + this.addStrategy(items => items instanceof Map, new MapRepeatStrategy()); + this.addStrategy(items => items instanceof Set, new SetRepeatStrategy()); + this.addStrategy(items => typeof items === 'number', new NumberRepeatStrategy()); + } + addStrategy(matcher, strategy) { + this.matchers.push(matcher); + this.strategies.push(strategy); + } + getStrategy(items) { + let matchers = this.matchers; + for (let i = 0, ii = matchers.length; i < ii; ++i) { + if (matchers[i](items)) { + return this.strategies[i]; + } + } + return null; + } +} + +const lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with']; +function behaviorRequiresLifecycle(instruction) { + let t = instruction.type; + let name = t.elementName !== null ? t.elementName : t.attributeName; + return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind) + || t.viewFactory && viewsRequireLifecycle(t.viewFactory) + || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); +} +function targetRequiresLifecycle(instruction) { + let behaviors = instruction.behaviorInstructions; + if (behaviors) { + let i = behaviors.length; + while (i--) { + if (behaviorRequiresLifecycle(behaviors[i])) { + return true; + } + } + } + return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); +} +function viewsRequireLifecycle(viewFactory) { + if ('_viewsRequireLifecycle' in viewFactory) { + return viewFactory._viewsRequireLifecycle; + } + viewFactory._viewsRequireLifecycle = false; + if (viewFactory.viewFactory) { + viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory); + return viewFactory._viewsRequireLifecycle; + } + if (viewFactory.template.querySelector('.au-animate')) { + viewFactory._viewsRequireLifecycle = true; + return true; + } + for (let id in viewFactory.instructions) { + if (targetRequiresLifecycle(viewFactory.instructions[id])) { + viewFactory._viewsRequireLifecycle = true; + return true; + } + } + viewFactory._viewsRequireLifecycle = false; + return false; +} + +class AbstractRepeater { + constructor(options) { + Object.assign(this, { + local: 'items', + viewsRequireLifecycle: true + }, options); + } + viewCount() { + throw new Error('subclass must implement `viewCount`'); + } + views() { + throw new Error('subclass must implement `views`'); + } + view(index) { + throw new Error('subclass must implement `view`'); + } + matcher() { + throw new Error('subclass must implement `matcher`'); + } + addView(bindingContext, overrideContext) { + throw new Error('subclass must implement `addView`'); + } + insertView(index, bindingContext, overrideContext) { + throw new Error('subclass must implement `insertView`'); + } + moveView(sourceIndex, targetIndex) { + throw new Error('subclass must implement `moveView`'); + } + removeAllViews(returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeAllViews`'); + } + removeViews(viewsToRemove, returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeView`'); + } + removeView(index, returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeView`'); + } + updateBindings(view) { + throw new Error('subclass must implement `updateBindings`'); + } +} + +let Repeat = class Repeat extends AbstractRepeater { + constructor(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) { + super({ + local: 'item', + viewsRequireLifecycle: viewsRequireLifecycle(viewFactory) + }); + this.viewFactory = viewFactory; + this.instruction = instruction; + this.viewSlot = viewSlot; + this.lookupFunctions = viewResources.lookupFunctions; + this.observerLocator = observerLocator; + this.key = 'key'; + this.value = 'value'; + this.strategyLocator = strategyLocator; + this.ignoreMutation = false; + this.sourceExpression = getItemsSourceExpression(this.instruction, 'repeat.for'); + this.isOneTime = isOneTime(this.sourceExpression); + this.viewsRequireLifecycle = viewsRequireLifecycle(viewFactory); + } + call(context, changes) { + this[context](this.items, changes); + } + bind(bindingContext, overrideContext) { + this.scope = { bindingContext, overrideContext }; + this.matcherBinding = this._captureAndRemoveMatcherBinding(); + this.itemsChanged(); + } + unbind() { + this.scope = null; + this.items = null; + this.matcherBinding = null; + this.viewSlot.removeAll(true, true); + this._unsubscribeCollection(); + } + _unsubscribeCollection() { + if (this.collectionObserver) { + this.collectionObserver.unsubscribe(this.callContext, this); + this.collectionObserver = null; + this.callContext = null; + } + } + itemsChanged() { + this._unsubscribeCollection(); + if (!this.scope) { + return; + } + let items = this.items; + this.strategy = this.strategyLocator.getStrategy(items); + if (!this.strategy) { + throw new Error(`Value for '${this.sourceExpression}' is non-repeatable`); + } + if (!this.isOneTime && !this._observeInnerCollection()) { + this._observeCollection(); + } + this.ignoreMutation = true; + this.strategy.instanceChanged(this, items); + this.observerLocator.taskQueue.queueMicroTask(() => { + this.ignoreMutation = false; + }); + } + _getInnerCollection() { + let expression = unwrapExpression(this.sourceExpression); + if (!expression) { + return null; + } + return expression.evaluate(this.scope, null); + } + handleCollectionMutated(collection, changes) { + if (!this.collectionObserver) { + return; + } + if (this.ignoreMutation) { + return; + } + this.strategy.instanceMutated(this, collection, changes); + } + handleInnerCollectionMutated(collection, changes) { + if (!this.collectionObserver) { + return; + } + if (this.ignoreMutation) { + return; + } + this.ignoreMutation = true; + let newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions); + this.observerLocator.taskQueue.queueMicroTask(() => this.ignoreMutation = false); + if (newItems === this.items) { + this.itemsChanged(); + } + else { + this.items = newItems; + } + } + _observeInnerCollection() { + let items = this._getInnerCollection(); + let strategy = this.strategyLocator.getStrategy(items); + if (!strategy) { + return false; + } + this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items); + if (!this.collectionObserver) { + return false; + } + this.callContext = 'handleInnerCollectionMutated'; + this.collectionObserver.subscribe(this.callContext, this); + return true; + } + _observeCollection() { + let items = this.items; + this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items); + if (this.collectionObserver) { + this.callContext = 'handleCollectionMutated'; + this.collectionObserver.subscribe(this.callContext, this); + } + } + _captureAndRemoveMatcherBinding() { + if (this.viewFactory.viewFactory) { + const instructions = this.viewFactory.viewFactory.instructions; + const instructionIds = Object.keys(instructions); + for (let i = 0; i < instructionIds.length; i++) { + const expressions = instructions[instructionIds[i]].expressions; + if (expressions) { + for (let ii = 0; ii < expressions.length; ii++) { + if (expressions[ii].targetProperty === 'matcher') { + const matcherBinding = expressions[ii]; + expressions.splice(ii, 1); + return matcherBinding; + } + } + } + } + } + return undefined; + } + viewCount() { return this.viewSlot.children.length; } + views() { return this.viewSlot.children; } + view(index) { return this.viewSlot.children[index]; } + matcher() { return this.matcherBinding ? this.matcherBinding.sourceExpression.evaluate(this.scope, this.matcherBinding.lookupFunctions) : null; } + addView(bindingContext, overrideContext) { + let view = this.viewFactory.create(); + view.bind(bindingContext, overrideContext); + this.viewSlot.add(view); + } + insertView(index, bindingContext, overrideContext) { + let view = this.viewFactory.create(); + view.bind(bindingContext, overrideContext); + this.viewSlot.insert(index, view); + } + moveView(sourceIndex, targetIndex) { + this.viewSlot.move(sourceIndex, targetIndex); + } + removeAllViews(returnToCache, skipAnimation) { + return this.viewSlot.removeAll(returnToCache, skipAnimation); + } + removeViews(viewsToRemove, returnToCache, skipAnimation) { + return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation); + } + removeView(index, returnToCache, skipAnimation) { + return this.viewSlot.removeAt(index, returnToCache, skipAnimation); + } + updateBindings(view) { + const $view = view; + let j = $view.bindings.length; + while (j--) { + updateOneTimeBinding($view.bindings[j]); + } + j = $view.controllers.length; + while (j--) { + let k = $view.controllers[j].boundProperties.length; + while (k--) { + let binding = $view.controllers[j].boundProperties[k].binding; + updateOneTimeBinding(binding); + } + } + } +}; +__decorate([ + bindable +], Repeat.prototype, "items", void 0); +__decorate([ + bindable +], Repeat.prototype, "local", void 0); +__decorate([ + bindable +], Repeat.prototype, "key", void 0); +__decorate([ + bindable +], Repeat.prototype, "value", void 0); +Repeat = __decorate([ + customAttribute('repeat'), + templateController, + inject(BoundViewFactory, TargetInstruction, ViewSlot, ViewResources, ObserverLocator, RepeatStrategyLocator) +], Repeat); + +const aureliaHideClassName = 'aurelia-hide'; +const aureliaHideClass = `.${aureliaHideClassName} { display:none !important; }`; +function injectAureliaHideStyleAtHead() { + DOM.injectStyles(aureliaHideClass); +} +function injectAureliaHideStyleAtBoundary(domBoundary) { + if (FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) { + domBoundary.hasAureliaHideStyle = true; + DOM.injectStyles(aureliaHideClass, domBoundary); + } +} + +let Show = class Show { + constructor(element, animator, domBoundary) { + this.element = element; + this.animator = animator; + this.domBoundary = domBoundary; + } + static inject() { + return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; + } + created() { + injectAureliaHideStyleAtBoundary(this.domBoundary); + } + valueChanged(newValue) { + let element = this.element; + let animator = this.animator; + if (newValue) { + animator.removeClass(element, aureliaHideClassName); + } + else { + animator.addClass(element, aureliaHideClassName); + } + } + bind(bindingContext) { + this.valueChanged(this.value); + } +}; +Show = __decorate([ + customAttribute('show') +], Show); + +let Hide = class Hide { + constructor(element, animator, domBoundary) { + this.element = element; + this.animator = animator; + this.domBoundary = domBoundary; + } + static inject() { + return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; + } + created() { + injectAureliaHideStyleAtBoundary(this.domBoundary); + } + valueChanged(newValue) { + if (newValue) { + this.animator.addClass(this.element, aureliaHideClassName); + } + else { + this.animator.removeClass(this.element, aureliaHideClassName); + } + } + bind(bindingContext) { + this.valueChanged(this.value); + } + value(value) { + throw new Error('Method not implemented.'); + } +}; +Hide = __decorate([ + customAttribute('hide') +], Hide); + +const SCRIPT_REGEX = /)<[^<]*)*<\/script>/gi; +let needsToWarn = true; +class HTMLSanitizer { + sanitize(input) { + if (needsToWarn) { + needsToWarn = false; + getLogger('html-sanitizer') + .warn(`CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks, +and should not be relied on for sanitizing input from unknown sources. +Please see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html.`); + } + return input.replace(SCRIPT_REGEX, ''); + } +} + +let SanitizeHTMLValueConverter = class SanitizeHTMLValueConverter { + constructor(sanitizer) { + this.sanitizer = sanitizer; + } + toView(untrustedMarkup) { + if (untrustedMarkup === null || untrustedMarkup === undefined) { + return null; + } + return this.sanitizer.sanitize(untrustedMarkup); + } +}; +SanitizeHTMLValueConverter = __decorate([ + valueConverter('sanitizeHTML'), + inject(HTMLSanitizer) +], SanitizeHTMLValueConverter); + +let Replaceable = class Replaceable { + constructor(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.view = null; + } + bind(bindingContext, overrideContext) { + if (this.view === null) { + this.view = this.viewFactory.create(); + this.viewSlot.add(this.view); + } + this.view.bind(bindingContext, overrideContext); + } + unbind() { + this.view.unbind(); + } +}; +Replaceable = __decorate([ + customAttribute('replaceable'), + templateController, + inject(BoundViewFactory, ViewSlot) +], Replaceable); + +let Focus = class Focus { + constructor(element, taskQueue) { + this.element = element; + this.taskQueue = taskQueue; + this.isAttached = false; + this.needsApply = false; + } + static inject() { + return [DOM.Element, TaskQueue]; + } + valueChanged(newValue) { + if (this.isAttached) { + this._apply(); + } + else { + this.needsApply = true; + } + } + _apply() { + if (this.value) { + this.taskQueue.queueMicroTask(() => { + if (this.value) { + this.element.focus(); + } + }); + } + else { + this.element.blur(); + } + } + attached() { + this.isAttached = true; + if (this.needsApply) { + this.needsApply = false; + this._apply(); + } + this.element.addEventListener('focus', this); + this.element.addEventListener('blur', this); + } + detached() { + this.isAttached = false; + this.element.removeEventListener('focus', this); + this.element.removeEventListener('blur', this); + } + handleEvent(e) { + if (e.type === 'focus') { + this.value = true; + } + else if (DOM.activeElement !== this.element) { + this.value = false; + } + } +}; +Focus = __decorate([ + customAttribute('focus', bindingMode.twoWay) +], Focus); + +let cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi; +function fixupCSSUrls(address, css) { + if (typeof css !== 'string') { + throw new Error(`Failed loading required CSS file: ${address}`); + } + return css.replace(cssUrlMatcher, (match, p1) => { + let quote = p1.charAt(0); + if (quote === '\'' || quote === '"') { + p1 = p1.substr(1, p1.length - 2); + } + return 'url(\'' + relativeToFile(p1, address) + '\')'; + }); +} +class CSSResource { + constructor(address) { + this.address = address; + this._scoped = null; + this._global = false; + this._alreadyGloballyInjected = false; + } + initialize(container, Target) { + this._scoped = new Target(this); + } + register(registry, name) { + if (name === 'scoped') { + registry.registerViewEngineHooks(this._scoped); + } + else { + this._global = true; + } + } + load(container) { + return container.get(Loader) + .loadText(this.address) + .catch(err => null) + .then(text => { + text = fixupCSSUrls(this.address, text); + this._scoped.css = text; + if (this._global) { + this._alreadyGloballyInjected = true; + DOM.injectStyles(text); + } + }); + } +} +class CSSViewEngineHooks { + constructor(owner) { + this.owner = owner; + this.css = null; + } + beforeCompile(content, resources, instruction) { + if (instruction.targetShadowDOM) { + DOM.injectStyles(this.css, content, true); + } + else if (FEATURE.scopedCSS) { + let styleNode = DOM.injectStyles(this.css, content, true); + styleNode.setAttribute('scoped', 'scoped'); + } + else if (this._global && !this.owner._alreadyGloballyInjected) { + DOM.injectStyles(this.css); + this.owner._alreadyGloballyInjected = true; + } + } +} +function _createCSSResource(address) { + let ViewCSS = class ViewCSS extends CSSViewEngineHooks { + }; + ViewCSS = __decorate([ + resource(new CSSResource(address)) + ], ViewCSS); + return ViewCSS; +} + +let AttrBindingBehavior = class AttrBindingBehavior { + bind(binding, source) { + binding.targetObserver = new DataAttributeObserver(binding.target, binding.targetProperty); + } + unbind(binding, source) { + } +}; +AttrBindingBehavior = __decorate([ + bindingBehavior('attr') +], AttrBindingBehavior); + +let modeBindingBehavior = { + bind(binding, source, lookupFunctions) { + binding.originalMode = binding.mode; + binding.mode = this.mode; + }, + unbind(binding, source) { + binding.mode = binding.originalMode; + binding.originalMode = null; + } +}; +let OneTimeBindingBehavior = class OneTimeBindingBehavior { + constructor() { + this.mode = bindingMode.oneTime; + } +}; +OneTimeBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('oneTime') +], OneTimeBindingBehavior); +let OneWayBindingBehavior = class OneWayBindingBehavior { + constructor() { + this.mode = bindingMode.toView; + } +}; +OneWayBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('oneWay') +], OneWayBindingBehavior); +let ToViewBindingBehavior = class ToViewBindingBehavior { + constructor() { + this.mode = bindingMode.toView; + } +}; +ToViewBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('toView') +], ToViewBindingBehavior); +let FromViewBindingBehavior = class FromViewBindingBehavior { + constructor() { + this.mode = bindingMode.fromView; + } +}; +FromViewBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('fromView') +], FromViewBindingBehavior); +let TwoWayBindingBehavior = class TwoWayBindingBehavior { + constructor() { + this.mode = bindingMode.twoWay; + } +}; +TwoWayBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('twoWay') +], TwoWayBindingBehavior); + +function throttle(newValue) { + let state = this.throttleState; + let elapsed = +new Date() - state.last; + if (elapsed >= state.delay) { + clearTimeout(state.timeoutId); + state.timeoutId = null; + state.last = +new Date(); + this.throttledMethod(newValue); + return; + } + state.newValue = newValue; + if (state.timeoutId === null) { + state.timeoutId = setTimeout(() => { + state.timeoutId = null; + state.last = +new Date(); + this.throttledMethod(state.newValue); + }, state.delay - elapsed); + } +} +let ThrottleBindingBehavior = class ThrottleBindingBehavior { + bind(binding, source, delay = 200) { + let methodToThrottle = 'updateTarget'; + if (binding.callSource) { + methodToThrottle = 'callSource'; + } + else if (binding.updateSource && binding.mode === bindingMode.twoWay) { + methodToThrottle = 'updateSource'; + } + binding.throttledMethod = binding[methodToThrottle]; + binding.throttledMethod.originalName = methodToThrottle; + binding[methodToThrottle] = throttle; + binding.throttleState = { + delay: delay, + last: 0, + timeoutId: null + }; + } + unbind(binding, source) { + let methodToRestore = binding.throttledMethod.originalName; + binding[methodToRestore] = binding.throttledMethod; + binding.throttledMethod = null; + clearTimeout(binding.throttleState.timeoutId); + binding.throttleState = null; + } +}; +ThrottleBindingBehavior = __decorate([ + bindingBehavior('throttle') +], ThrottleBindingBehavior); + +const unset = {}; +function debounceCallSource(event) { + const state = this.debounceState; + clearTimeout(state.timeoutId); + state.timeoutId = setTimeout(() => this.debouncedMethod(event), state.delay); +} +function debounceCall(context, newValue, oldValue) { + const state = this.debounceState; + clearTimeout(state.timeoutId); + if (context !== state.callContextToDebounce) { + state.oldValue = unset; + this.debouncedMethod(context, newValue, oldValue); + return; + } + if (state.oldValue === unset) { + state.oldValue = oldValue; + } + state.timeoutId = setTimeout(() => { + const _oldValue = state.oldValue; + state.oldValue = unset; + this.debouncedMethod(context, newValue, _oldValue); + }, state.delay); +} +let DebounceBindingBehavior = class DebounceBindingBehavior { + bind(binding, source, delay = 200) { + const isCallSource = binding.callSource !== undefined; + const methodToDebounce = isCallSource ? 'callSource' : 'call'; + const debouncer = isCallSource ? debounceCallSource : debounceCall; + const mode = binding.mode; + const callContextToDebounce = mode === bindingMode.twoWay || mode === bindingMode.fromView ? targetContext : sourceContext; + binding.debouncedMethod = binding[methodToDebounce]; + binding.debouncedMethod.originalName = methodToDebounce; + binding[methodToDebounce] = debouncer; + binding.debounceState = { + callContextToDebounce, + delay, + timeoutId: 0, + oldValue: unset + }; + } + unbind(binding, source) { + const methodToRestore = binding.debouncedMethod.originalName; + binding[methodToRestore] = binding.debouncedMethod; + binding.debouncedMethod = null; + clearTimeout(binding.debounceState.timeoutId); + binding.debounceState = null; + } +}; +DebounceBindingBehavior = __decorate([ + bindingBehavior('debounce') +], DebounceBindingBehavior); + +function findOriginalEventTarget(event) { + return (event.path && event.path[0]) || (event.deepPath && event.deepPath[0]) || event.target; +} +function handleSelfEvent(event) { + let target = findOriginalEventTarget(event); + if (this.target !== target) { + return; + } + this.selfEventCallSource(event); +} +let SelfBindingBehavior = class SelfBindingBehavior { + bind(binding, source) { + if (!binding.callSource || !binding.targetEvent) { + throw new Error('Self binding behavior only supports event.'); + } + binding.selfEventCallSource = binding.callSource; + binding.callSource = handleSelfEvent; + } + unbind(binding, source) { + binding.callSource = binding.selfEventCallSource; + binding.selfEventCallSource = null; + } +}; +SelfBindingBehavior = __decorate([ + bindingBehavior('self') +], SelfBindingBehavior); + +class BindingSignaler { + constructor() { + this.signals = {}; + } + signal(name) { + let bindings = this.signals[name]; + if (!bindings) { + return; + } + let i = bindings.length; + while (i--) { + bindings[i].call(sourceContext); + } + } +} + +let SignalBindingBehavior = class SignalBindingBehavior { + constructor(bindingSignaler) { + this.signals = bindingSignaler.signals; + } + static inject() { return [BindingSignaler]; } + bind(binding, source, ...names) { + if (!binding.updateTarget) { + throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.'); + } + let signals = this.signals; + if (names.length === 1) { + let name = names[0]; + let bindings = signals[name] || (signals[name] = []); + bindings.push(binding); + binding.signalName = name; + } + else if (names.length > 1) { + let i = names.length; + while (i--) { + let name = names[i]; + let bindings = signals[name] || (signals[name] = []); + bindings.push(binding); + } + binding.signalName = names; + } + else { + throw new Error('Signal name is required.'); + } + } + unbind(binding, source) { + let signals = this.signals; + let name = binding.signalName; + binding.signalName = null; + if (Array.isArray(name)) { + let names = name; + let i = names.length; + while (i--) { + let n = names[i]; + let bindings = signals[n]; + bindings.splice(bindings.indexOf(binding), 1); + } + } + else { + let bindings = signals[name]; + bindings.splice(bindings.indexOf(binding), 1); + } + } +}; +SignalBindingBehavior = __decorate([ + bindingBehavior('signal') +], SignalBindingBehavior); + +const eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg '; +const notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.'; +let UpdateTriggerBindingBehavior = class UpdateTriggerBindingBehavior { + bind(binding, source, ...events) { + if (events.length === 0) { + throw new Error(eventNamesRequired); + } + if (binding.mode !== bindingMode.twoWay && binding.mode !== bindingMode.fromView) { + throw new Error(notApplicableMessage); + } + let targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty); + if (!targetObserver.handler) { + throw new Error(notApplicableMessage); + } + binding.targetObserver = targetObserver; + targetObserver.originalHandler = binding.targetObserver.handler; + let handler = new EventSubscriber(events); + targetObserver.handler = handler; + } + unbind(binding, source) { + let targetObserver = binding.targetObserver; + targetObserver.handler.dispose(); + targetObserver.handler = targetObserver.originalHandler; + targetObserver.originalHandler = null; + } +}; +UpdateTriggerBindingBehavior = __decorate([ + bindingBehavior('updateTrigger') +], UpdateTriggerBindingBehavior); + +function _createDynamicElement({ name, viewUrl, bindableNames, useShadowDOMmode }) { + let DynamicElement = class DynamicElement { + bind(bindingContext) { + this.$parent = bindingContext; + } + }; + DynamicElement = __decorate([ + customElement(name), + useView(viewUrl) + ], DynamicElement); + for (let i = 0, ii = bindableNames.length; i < ii; ++i) { + bindable(bindableNames[i])(DynamicElement); + } + switch (useShadowDOMmode) { + case 'open': + useShadowDOM({ mode: 'open' })(DynamicElement); + break; + case 'closed': + useShadowDOM({ mode: 'closed' })(DynamicElement); + break; + case '': + useShadowDOM(DynamicElement); + break; + case null: + break; + default: + getLogger('aurelia-html-only-element') + .warn(`Expected 'use-shadow-dom' value to be "close", "open" or "", received ${useShadowDOMmode}`); + break; + } + return DynamicElement; +} + +function getElementName(address) { + return /([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase(); +} +function configure(config) { + const viewEngine = config.container.get(ViewEngine); + const loader = config.aurelia.loader; + viewEngine.addResourcePlugin('.html', { + 'fetch': function (viewUrl) { + return loader.loadTemplate(viewUrl).then(registryEntry => { + let bindableNames = registryEntry.template.getAttribute('bindable'); + const useShadowDOMmode = registryEntry.template.getAttribute('use-shadow-dom'); + const name = getElementName(viewUrl); + if (bindableNames) { + bindableNames = bindableNames.split(',').map(x => x.trim()); + registryEntry.template.removeAttribute('bindable'); + } + else { + bindableNames = []; + } + return { [name]: _createDynamicElement({ name, viewUrl, bindableNames, useShadowDOMmode }) }; + }); + } + }); +} + +function configure$1(config) { + injectAureliaHideStyleAtHead(); + config.globalResources(Compose, If, Else, With, Repeat, Show, Hide, Replaceable, Focus, SanitizeHTMLValueConverter, OneTimeBindingBehavior, OneWayBindingBehavior, ToViewBindingBehavior, FromViewBindingBehavior, TwoWayBindingBehavior, ThrottleBindingBehavior, DebounceBindingBehavior, SelfBindingBehavior, SignalBindingBehavior, UpdateTriggerBindingBehavior, AttrBindingBehavior); + configure(config); + let viewEngine = config.container.get(ViewEngine); + let styleResourcePlugin = { + fetch(address) { + return { [address]: _createCSSResource(address) }; + } + }; + ['.css', '.less', '.sass', '.scss', '.styl'].forEach(ext => viewEngine.addResourcePlugin(ext, styleResourcePlugin)); +} + +export { AbstractRepeater, ArrayRepeatStrategy, AttrBindingBehavior, BindingSignaler, Compose, DebounceBindingBehavior, Else, Focus, FromViewBindingBehavior, HTMLSanitizer, Hide, If, MapRepeatStrategy, NullRepeatStrategy, NumberRepeatStrategy, OneTimeBindingBehavior, OneWayBindingBehavior, Repeat, RepeatStrategyLocator, Replaceable, SanitizeHTMLValueConverter, SelfBindingBehavior, SetRepeatStrategy, Show, SignalBindingBehavior, ThrottleBindingBehavior, ToViewBindingBehavior, TwoWayBindingBehavior, UpdateTriggerBindingBehavior, With, configure$1 as configure, createFullOverrideContext, getItemsSourceExpression, isOneTime, unwrapExpression, updateOneTimeBinding, updateOverrideContext, viewsRequireLifecycle }; +//# sourceMappingURL=aurelia-templating-resources.js.map diff --git a/dist/es2015/aurelia-templating-resources.js.map b/dist/es2015/aurelia-templating-resources.js.map new file mode 100644 index 0000000..b7b5f2f --- /dev/null +++ b/dist/es2015/aurelia-templating-resources.js.map @@ -0,0 +1 @@ +{"version":3,"file":"aurelia-templating-resources.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/es2015/binding-mode-behaviors.js b/dist/es2015/binding-mode-behaviors.js deleted file mode 100644 index d36cd86..0000000 --- a/dist/es2015/binding-mode-behaviors.js +++ /dev/null @@ -1,46 +0,0 @@ -var _dec, _dec2, _class, _dec3, _dec4, _class2, _dec5, _dec6, _class3, _dec7, _dec8, _class4, _dec9, _dec10, _class5; - -import { bindingMode, bindingBehavior } from 'aurelia-binding'; -import { mixin } from 'aurelia-metadata'; - -let modeBindingBehavior = { - bind(binding, source, lookupFunctions) { - binding.originalMode = binding.mode; - binding.mode = this.mode; - }, - - unbind(binding, source) { - binding.mode = binding.originalMode; - binding.originalMode = null; - } -}; - -export let OneTimeBindingBehavior = (_dec = mixin(modeBindingBehavior), _dec2 = bindingBehavior('oneTime'), _dec(_class = _dec2(_class = class OneTimeBindingBehavior { - constructor() { - this.mode = bindingMode.oneTime; - } -}) || _class) || _class); - -export let OneWayBindingBehavior = (_dec3 = mixin(modeBindingBehavior), _dec4 = bindingBehavior('oneWay'), _dec3(_class2 = _dec4(_class2 = class OneWayBindingBehavior { - constructor() { - this.mode = bindingMode.toView; - } -}) || _class2) || _class2); - -export let ToViewBindingBehavior = (_dec5 = mixin(modeBindingBehavior), _dec6 = bindingBehavior('toView'), _dec5(_class3 = _dec6(_class3 = class ToViewBindingBehavior { - constructor() { - this.mode = bindingMode.toView; - } -}) || _class3) || _class3); - -export let FromViewBindingBehavior = (_dec7 = mixin(modeBindingBehavior), _dec8 = bindingBehavior('fromView'), _dec7(_class4 = _dec8(_class4 = class FromViewBindingBehavior { - constructor() { - this.mode = bindingMode.fromView; - } -}) || _class4) || _class4); - -export let TwoWayBindingBehavior = (_dec9 = mixin(modeBindingBehavior), _dec10 = bindingBehavior('twoWay'), _dec9(_class5 = _dec10(_class5 = class TwoWayBindingBehavior { - constructor() { - this.mode = bindingMode.twoWay; - } -}) || _class5) || _class5); \ No newline at end of file diff --git a/dist/es2015/binding-signaler.js b/dist/es2015/binding-signaler.js deleted file mode 100644 index cc7a341..0000000 --- a/dist/es2015/binding-signaler.js +++ /dev/null @@ -1,18 +0,0 @@ -import { sourceContext } from 'aurelia-binding'; - -export let BindingSignaler = class BindingSignaler { - constructor() { - this.signals = {}; - } - - signal(name) { - let bindings = this.signals[name]; - if (!bindings) { - return; - } - let i = bindings.length; - while (i--) { - bindings[i].call(sourceContext); - } - } -}; \ No newline at end of file diff --git a/dist/es2015/compose.js b/dist/es2015/compose.js deleted file mode 100644 index 6607f47..0000000 --- a/dist/es2015/compose.js +++ /dev/null @@ -1,205 +0,0 @@ -var _dec, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4; - -function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); -} - -function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; -} - -function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); -} - -import { Container } from 'aurelia-dependency-injection'; -import { TaskQueue } from 'aurelia-task-queue'; -import { CompositionEngine, CompositionContext, ViewSlot, ViewResources, customElement, bindable, noView, View } from 'aurelia-templating'; -import { DOM } from 'aurelia-pal'; - -export let Compose = (_dec = customElement('compose'), _dec(_class = noView(_class = (_class2 = class Compose { - - static inject() { - return [DOM.Element, Container, CompositionEngine, ViewSlot, ViewResources, TaskQueue]; - } - - constructor(element, container, compositionEngine, viewSlot, viewResources, taskQueue) { - _initDefineProp(this, 'model', _descriptor, this); - - _initDefineProp(this, 'view', _descriptor2, this); - - _initDefineProp(this, 'viewModel', _descriptor3, this); - - _initDefineProp(this, 'swapOrder', _descriptor4, this); - - this.element = element; - this.container = container; - this.compositionEngine = compositionEngine; - this.viewSlot = viewSlot; - this.viewResources = viewResources; - this.taskQueue = taskQueue; - this.currentController = null; - this.currentViewModel = null; - this.changes = Object.create(null); - } - - created(owningView) { - this.owningView = owningView; - } - - bind(bindingContext, overrideContext) { - this.bindingContext = bindingContext; - this.overrideContext = overrideContext; - this.changes.view = this.view; - this.changes.viewModel = this.viewModel; - this.changes.model = this.model; - if (!this.pendingTask) { - processChanges(this); - } - } - - unbind() { - this.changes = Object.create(null); - this.bindingContext = null; - this.overrideContext = null; - let returnToCache = true; - let skipAnimation = true; - this.viewSlot.removeAll(returnToCache, skipAnimation); - } - - modelChanged(newValue, oldValue) { - this.changes.model = newValue; - requestUpdate(this); - } - - viewChanged(newValue, oldValue) { - this.changes.view = newValue; - requestUpdate(this); - } - - viewModelChanged(newValue, oldValue) { - this.changes.viewModel = newValue; - requestUpdate(this); - } -}, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'model', [bindable], { - enumerable: true, - initializer: null -}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'view', [bindable], { - enumerable: true, - initializer: null -}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'viewModel', [bindable], { - enumerable: true, - initializer: null -}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, 'swapOrder', [bindable], { - enumerable: true, - initializer: null -})), _class2)) || _class) || _class); - -function isEmpty(obj) { - for (const key in obj) { - return false; - } - return true; -} - -function tryActivateViewModel(vm, model) { - if (vm && typeof vm.activate === 'function') { - return Promise.resolve(vm.activate(model)); - } -} - -function createInstruction(composer, instruction) { - return Object.assign(instruction, { - bindingContext: composer.bindingContext, - overrideContext: composer.overrideContext, - owningView: composer.owningView, - container: composer.container, - viewSlot: composer.viewSlot, - viewResources: composer.viewResources, - currentController: composer.currentController, - host: composer.element, - swapOrder: composer.swapOrder - }); -} - -function processChanges(composer) { - const changes = composer.changes; - composer.changes = Object.create(null); - - if (!('view' in changes) && !('viewModel' in changes) && 'model' in changes) { - composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model); - if (!composer.pendingTask) { - return; - } - } else { - let instruction = { - view: composer.view, - viewModel: composer.currentViewModel || composer.viewModel, - model: composer.model - }; - - instruction = Object.assign(instruction, changes); - - instruction = createInstruction(composer, instruction); - composer.pendingTask = composer.compositionEngine.compose(instruction).then(controller => { - composer.currentController = controller; - composer.currentViewModel = controller ? controller.viewModel : null; - }); - } - - composer.pendingTask = composer.pendingTask.then(() => { - completeCompositionTask(composer); - }, reason => { - completeCompositionTask(composer); - throw reason; - }); -} - -function completeCompositionTask(composer) { - composer.pendingTask = null; - if (!isEmpty(composer.changes)) { - processChanges(composer); - } -} - -function requestUpdate(composer) { - if (composer.pendingTask || composer.updateRequested) { - return; - } - composer.updateRequested = true; - composer.taskQueue.queueMicroTask(() => { - composer.updateRequested = false; - processChanges(composer); - }); -} \ No newline at end of file diff --git a/dist/es2015/css-resource.js b/dist/es2015/css-resource.js deleted file mode 100644 index d69e617..0000000 --- a/dist/es2015/css-resource.js +++ /dev/null @@ -1,80 +0,0 @@ - -import { ViewResources, resource, ViewCompileInstruction } from 'aurelia-templating'; -import { Loader } from 'aurelia-loader'; -import { Container } from 'aurelia-dependency-injection'; -import { relativeToFile } from 'aurelia-path'; -import { DOM, FEATURE } from 'aurelia-pal'; - -let cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi; - -function fixupCSSUrls(address, css) { - if (typeof css !== 'string') { - throw new Error(`Failed loading required CSS file: ${address}`); - } - return css.replace(cssUrlMatcher, (match, p1) => { - let quote = p1.charAt(0); - if (quote === '\'' || quote === '"') { - p1 = p1.substr(1, p1.length - 2); - } - return 'url(\'' + relativeToFile(p1, address) + '\')'; - }); -} - -let CSSResource = class CSSResource { - constructor(address) { - this.address = address; - this._scoped = null; - this._global = false; - this._alreadyGloballyInjected = false; - } - - initialize(container, target) { - this._scoped = new target(this); - } - - register(registry, name) { - if (name === 'scoped') { - registry.registerViewEngineHooks(this._scoped); - } else { - this._global = true; - } - } - - load(container) { - return container.get(Loader).loadText(this.address).catch(err => null).then(text => { - text = fixupCSSUrls(this.address, text); - this._scoped.css = text; - if (this._global) { - this._alreadyGloballyInjected = true; - DOM.injectStyles(text); - } - }); - } -}; -let CSSViewEngineHooks = class CSSViewEngineHooks { - constructor(owner) { - this.owner = owner; - this.css = null; - } - - beforeCompile(content, resources, instruction) { - if (instruction.targetShadowDOM) { - DOM.injectStyles(this.css, content, true); - } else if (FEATURE.scopedCSS) { - let styleNode = DOM.injectStyles(this.css, content, true); - styleNode.setAttribute('scoped', 'scoped'); - } else if (this._global && !this.owner._alreadyGloballyInjected) { - DOM.injectStyles(this.css); - this.owner._alreadyGloballyInjected = true; - } - } -}; - - -export function _createCSSResource(address) { - var _dec, _class; - - let ViewCSS = (_dec = resource(new CSSResource(address)), _dec(_class = class ViewCSS extends CSSViewEngineHooks {}) || _class); - - return ViewCSS; -} \ No newline at end of file diff --git a/dist/es2015/debounce-binding-behavior.js b/dist/es2015/debounce-binding-behavior.js deleted file mode 100644 index fc4c566..0000000 --- a/dist/es2015/debounce-binding-behavior.js +++ /dev/null @@ -1,59 +0,0 @@ -var _dec, _class; - -import { bindingMode, sourceContext, targetContext, bindingBehavior } from 'aurelia-binding'; - -const unset = {}; - -function debounceCallSource(event) { - const state = this.debounceState; - clearTimeout(state.timeoutId); - state.timeoutId = setTimeout(() => this.debouncedMethod(event), state.delay); -} - -function debounceCall(context, newValue, oldValue) { - const state = this.debounceState; - clearTimeout(state.timeoutId); - if (context !== state.callContextToDebounce) { - state.oldValue = unset; - this.debouncedMethod(context, newValue, oldValue); - return; - } - if (state.oldValue === unset) { - state.oldValue = oldValue; - } - state.timeoutId = setTimeout(() => { - const _oldValue = state.oldValue; - state.oldValue = unset; - this.debouncedMethod(context, newValue, _oldValue); - }, state.delay); -} - -export let DebounceBindingBehavior = (_dec = bindingBehavior('debounce'), _dec(_class = class DebounceBindingBehavior { - bind(binding, source, delay = 200) { - const isCallSource = binding.callSource !== undefined; - const methodToDebounce = isCallSource ? 'callSource' : 'call'; - const debouncer = isCallSource ? debounceCallSource : debounceCall; - const mode = binding.mode; - const callContextToDebounce = mode === bindingMode.twoWay || mode === bindingMode.fromView ? targetContext : sourceContext; - - binding.debouncedMethod = binding[methodToDebounce]; - binding.debouncedMethod.originalName = methodToDebounce; - - binding[methodToDebounce] = debouncer; - - binding.debounceState = { - callContextToDebounce, - delay, - timeoutId: 0, - oldValue: unset - }; - } - - unbind(binding, source) { - const methodToRestore = binding.debouncedMethod.originalName; - binding[methodToRestore] = binding.debouncedMethod; - binding.debouncedMethod = null; - clearTimeout(binding.debounceState.timeoutId); - binding.debounceState = null; - } -}) || _class); \ No newline at end of file diff --git a/dist/es2015/dynamic-element.js b/dist/es2015/dynamic-element.js deleted file mode 100644 index 039e436..0000000 --- a/dist/es2015/dynamic-element.js +++ /dev/null @@ -1,41 +0,0 @@ - -import { useView, customElement, bindable, useShadowDOM } from 'aurelia-templating'; -import { getLogger } from 'aurelia-logging'; - -export function _createDynamicElement({ name, viewUrl, bindableNames, useShadowDOMmode }) { - var _dec, _dec2, _class; - - let DynamicElement = (_dec = customElement(name), _dec2 = useView(viewUrl), _dec(_class = _dec2(_class = class DynamicElement { - bind(bindingContext) { - this.$parent = bindingContext; - } - }) || _class) || _class); - - - for (let i = 0, ii = bindableNames.length; i < ii; ++i) { - bindable(bindableNames[i])(DynamicElement); - } - - switch (useShadowDOMmode) { - case 'open': - useShadowDOM({ mode: 'open' })(DynamicElement); - break; - - case 'closed': - useShadowDOM({ mode: 'closed' })(DynamicElement); - break; - - case '': - useShadowDOM(DynamicElement); - break; - - case null: - break; - - default: - getLogger('aurelia-html-only-element').warn(`Expected 'use-shadow-dom' value to be "close", "open" or "", received ${useShadowDOMmode}`); - break; - } - - return DynamicElement; -} \ No newline at end of file diff --git a/dist/es2015/else.js b/dist/es2015/else.js deleted file mode 100644 index 75b1e4c..0000000 --- a/dist/es2015/else.js +++ /dev/null @@ -1,34 +0,0 @@ -var _dec, _dec2, _class; - -import { BoundViewFactory, ViewSlot, customAttribute, templateController } from 'aurelia-templating'; -import { inject } from 'aurelia-dependency-injection'; -import { IfCore } from './if-core'; - -export let Else = (_dec = customAttribute('else'), _dec2 = inject(BoundViewFactory, ViewSlot), _dec(_class = templateController(_class = _dec2(_class = class Else extends IfCore { - constructor(viewFactory, viewSlot) { - super(viewFactory, viewSlot); - this._registerInIf(); - } - - bind(bindingContext, overrideContext) { - super.bind(bindingContext, overrideContext); - - if (this.ifVm.condition) { - this._hide(); - } else { - this._show(); - } - } - - _registerInIf() { - let previous = this.viewSlot.anchor.previousSibling; - while (previous && !previous.au) { - previous = previous.previousSibling; - } - if (!previous || !previous.au.if) { - throw new Error("Can't find matching If for Else custom attribute."); - } - this.ifVm = previous.au.if.viewModel; - this.ifVm.elseVm = this; - } -}) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/es2015/focus.js b/dist/es2015/focus.js deleted file mode 100644 index d399f2a..0000000 --- a/dist/es2015/focus.js +++ /dev/null @@ -1,64 +0,0 @@ -var _dec, _class; - -import { customAttribute } from 'aurelia-templating'; -import { bindingMode } from 'aurelia-binding'; -import { TaskQueue } from 'aurelia-task-queue'; -import { DOM } from 'aurelia-pal'; - -export let Focus = (_dec = customAttribute('focus', bindingMode.twoWay), _dec(_class = class Focus { - - static inject() { - return [DOM.Element, TaskQueue]; - } - - constructor(element, taskQueue) { - this.element = element; - this.taskQueue = taskQueue; - this.isAttached = false; - this.needsApply = false; - } - - valueChanged(newValue) { - if (this.isAttached) { - this._apply(); - } else { - this.needsApply = true; - } - } - - _apply() { - if (this.value) { - this.taskQueue.queueMicroTask(() => { - if (this.value) { - this.element.focus(); - } - }); - } else { - this.element.blur(); - } - } - - attached() { - this.isAttached = true; - if (this.needsApply) { - this.needsApply = false; - this._apply(); - } - this.element.addEventListener('focus', this); - this.element.addEventListener('blur', this); - } - - detached() { - this.isAttached = false; - this.element.removeEventListener('focus', this); - this.element.removeEventListener('blur', this); - } - - handleEvent(e) { - if (e.type === 'focus') { - this.value = true; - } else if (DOM.activeElement !== this.element) { - this.value = false; - } - } -}) || _class); \ No newline at end of file diff --git a/dist/es2015/hide.js b/dist/es2015/hide.js deleted file mode 100644 index ed2b5bb..0000000 --- a/dist/es2015/hide.js +++ /dev/null @@ -1,35 +0,0 @@ -var _dec, _class; - -import { Optional } from 'aurelia-dependency-injection'; -import { customAttribute, Animator } from 'aurelia-templating'; -import { DOM } from 'aurelia-pal'; -import { injectAureliaHideStyleAtBoundary, aureliaHideClassName } from './aurelia-hide-style'; - -export let Hide = (_dec = customAttribute('hide'), _dec(_class = class Hide { - - static inject() { - return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; - } - - constructor(element, animator, domBoundary) { - this.element = element; - this.animator = animator; - this.domBoundary = domBoundary; - } - - created() { - injectAureliaHideStyleAtBoundary(this.domBoundary); - } - - valueChanged(newValue) { - if (newValue) { - this.animator.addClass(this.element, aureliaHideClassName); - } else { - this.animator.removeClass(this.element, aureliaHideClassName); - } - } - - bind(bindingContext) { - this.valueChanged(this.value); - } -}) || _class); \ No newline at end of file diff --git a/dist/es2015/html-resource-plugin.js b/dist/es2015/html-resource-plugin.js deleted file mode 100644 index 5983e51..0000000 --- a/dist/es2015/html-resource-plugin.js +++ /dev/null @@ -1,31 +0,0 @@ -import { ViewEngine } from 'aurelia-templating'; -import { _createDynamicElement } from './dynamic-element'; - -export function getElementName(address) { - return (/([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase() - ); -} - -export function configure(config) { - const viewEngine = config.container.get(ViewEngine); - const loader = config.aurelia.loader; - - viewEngine.addResourcePlugin('.html', { - 'fetch': function (viewUrl) { - return loader.loadTemplate(viewUrl).then(registryEntry => { - let bindableNames = registryEntry.template.getAttribute('bindable'); - const useShadowDOMmode = registryEntry.template.getAttribute('use-shadow-dom'); - const name = getElementName(viewUrl); - - if (bindableNames) { - bindableNames = bindableNames.split(',').map(x => x.trim()); - registryEntry.template.removeAttribute('bindable'); - } else { - bindableNames = []; - } - - return { [name]: _createDynamicElement({ name, viewUrl, bindableNames, useShadowDOMmode }) }; - }); - } - }); -} \ No newline at end of file diff --git a/dist/es2015/html-sanitizer.js b/dist/es2015/html-sanitizer.js deleted file mode 100644 index 29a7ae7..0000000 --- a/dist/es2015/html-sanitizer.js +++ /dev/null @@ -1,18 +0,0 @@ -import { getLogger } from 'aurelia-logging'; - -const SCRIPT_REGEX = /)<[^<]*)*<\/script>/gi; -let needsToWarn = true; - -export let HTMLSanitizer = class HTMLSanitizer { - sanitize(input) { - if (needsToWarn) { - needsToWarn = false; - - getLogger('html-sanitizer').warn(`CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks, - and should not be relied on for sanitizing input from unknown sources. - Please see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html.`); - } - - return input.replace(SCRIPT_REGEX, ''); - } -}; \ No newline at end of file diff --git a/dist/es2015/if-core.js b/dist/es2015/if-core.js deleted file mode 100644 index a4e529c..0000000 --- a/dist/es2015/if-core.js +++ /dev/null @@ -1,84 +0,0 @@ - -export let IfCore = class IfCore { - constructor(viewFactory, viewSlot) { - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.view = null; - this.bindingContext = null; - this.overrideContext = null; - - this.showing = false; - this.cache = true; - } - - bind(bindingContext, overrideContext) { - this.bindingContext = bindingContext; - this.overrideContext = overrideContext; - } - - unbind() { - if (this.view === null) { - return; - } - - this.view.unbind(); - - if (!this.viewFactory.isCaching) { - return; - } - - if (this.showing) { - this.showing = false; - this.viewSlot.remove(this.view, true, true); - } else { - this.view.returnToCache(); - } - - this.view = null; - } - - _show() { - if (this.showing) { - if (!this.view.isBound) { - this.view.bind(this.bindingContext, this.overrideContext); - } - return; - } - - if (this.view === null) { - this.view = this.viewFactory.create(); - } - - if (!this.view.isBound) { - this.view.bind(this.bindingContext, this.overrideContext); - } - - this.showing = true; - return this.viewSlot.add(this.view); - } - - _hide() { - if (!this.showing) { - return; - } - - this.showing = false; - let removed = this.viewSlot.remove(this.view); - - if (removed instanceof Promise) { - return removed.then(() => { - this._unbindView(); - }); - } - - this._unbindView(); - } - - _unbindView() { - const cache = this.cache === 'false' ? false : !!this.cache; - this.view.unbind(); - if (!cache) { - this.view = null; - } - } -}; \ No newline at end of file diff --git a/dist/es2015/if.js b/dist/es2015/if.js deleted file mode 100644 index b68b372..0000000 --- a/dist/es2015/if.js +++ /dev/null @@ -1,115 +0,0 @@ -var _dec, _dec2, _dec3, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3; - -function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); -} - -function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; -} - -function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); -} - -import { BoundViewFactory, ViewSlot, bindable, customAttribute, templateController } from 'aurelia-templating'; -import { inject } from 'aurelia-dependency-injection'; -import { IfCore } from './if-core'; - -export let If = (_dec = customAttribute('if'), _dec2 = inject(BoundViewFactory, ViewSlot), _dec3 = bindable({ primaryProperty: true }), _dec(_class = templateController(_class = _dec2(_class = (_class2 = class If extends IfCore { - constructor(...args) { - var _temp; - - return _temp = super(...args), _initDefineProp(this, 'condition', _descriptor, this), _initDefineProp(this, 'swapOrder', _descriptor2, this), _initDefineProp(this, 'cache', _descriptor3, this), _temp; - } - - bind(bindingContext, overrideContext) { - super.bind(bindingContext, overrideContext); - if (this.condition) { - this._show(); - } else { - this._hide(); - } - } - - conditionChanged(newValue) { - this._update(newValue); - } - - _update(show) { - if (this.animating) { - return; - } - - let promise; - if (this.elseVm) { - promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm); - } else { - promise = show ? this._show() : this._hide(); - } - - if (promise) { - this.animating = true; - promise.then(() => { - this.animating = false; - if (this.condition !== this.showing) { - this._update(this.condition); - } - }); - } - } - - _swap(remove, add) { - switch (this.swapOrder) { - case 'before': - return Promise.resolve(add._show()).then(() => remove._hide()); - case 'with': - return Promise.all([remove._hide(), add._show()]); - default: - let promise = remove._hide(); - return promise ? promise.then(() => add._show()) : add._show(); - } - } -}, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'condition', [_dec3], { - enumerable: true, - initializer: null -}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'swapOrder', [bindable], { - enumerable: true, - initializer: null -}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'cache', [bindable], { - enumerable: true, - initializer: function () { - return true; - } -})), _class2)) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/es2015/index.js b/dist/es2015/index.js deleted file mode 100644 index 5d31d56..0000000 --- a/dist/es2015/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from './aurelia-templating-resources'; \ No newline at end of file diff --git a/dist/es2015/map-repeat-strategy.js b/dist/es2015/map-repeat-strategy.js deleted file mode 100644 index de4c2e8..0000000 --- a/dist/es2015/map-repeat-strategy.js +++ /dev/null @@ -1,98 +0,0 @@ -import { createFullOverrideContext, updateOverrideContexts } from './repeat-utilities'; - -export let MapRepeatStrategy = class MapRepeatStrategy { - getCollectionObserver(observerLocator, items) { - return observerLocator.getMapObserver(items); - } - - instanceChanged(repeat, items) { - let removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(() => this._standardProcessItems(repeat, items)); - return; - } - this._standardProcessItems(repeat, items); - } - - _standardProcessItems(repeat, items) { - let index = 0; - let overrideContext; - - items.forEach((value, key) => { - overrideContext = createFullOverrideContext(repeat, value, index, items.size, key); - repeat.addView(overrideContext.bindingContext, overrideContext); - ++index; - }); - } - - instanceMutated(repeat, map, records) { - let key; - let i; - let ii; - let overrideContext; - let removeIndex; - let addIndex; - let record; - let rmPromises = []; - let viewOrPromise; - - for (i = 0, ii = records.length; i < ii; ++i) { - record = records[i]; - key = record.key; - switch (record.type) { - case 'update': - removeIndex = this._getViewIndexByKey(repeat, key); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - overrideContext = createFullOverrideContext(repeat, map.get(key), removeIndex, map.size, key); - repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext); - break; - case 'add': - addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1; - overrideContext = createFullOverrideContext(repeat, map.get(key), addIndex, map.size, key); - repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext); - break; - case 'delete': - if (record.oldValue === undefined) { - return; - } - removeIndex = this._getViewIndexByKey(repeat, key); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - break; - case 'clear': - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - break; - default: - continue; - } - } - - if (rmPromises.length > 0) { - Promise.all(rmPromises).then(() => { - updateOverrideContexts(repeat.views(), 0); - }); - } else { - updateOverrideContexts(repeat.views(), 0); - } - } - - _getViewIndexByKey(repeat, key) { - let i; - let ii; - let child; - - for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { - child = repeat.view(i); - if (child.bindingContext[repeat.key] === key) { - return i; - } - } - - return undefined; - } -}; \ No newline at end of file diff --git a/dist/es2015/null-repeat-strategy.js b/dist/es2015/null-repeat-strategy.js deleted file mode 100644 index 53a2814..0000000 --- a/dist/es2015/null-repeat-strategy.js +++ /dev/null @@ -1,8 +0,0 @@ - -export let NullRepeatStrategy = class NullRepeatStrategy { - instanceChanged(repeat, items) { - repeat.removeAllViews(true); - } - - getCollectionObserver(observerLocator, items) {} -}; \ No newline at end of file diff --git a/dist/es2015/number-repeat-strategy.js b/dist/es2015/number-repeat-strategy.js deleted file mode 100644 index e5b4fcc..0000000 --- a/dist/es2015/number-repeat-strategy.js +++ /dev/null @@ -1,46 +0,0 @@ -import { createFullOverrideContext, updateOverrideContexts } from './repeat-utilities'; - -export let NumberRepeatStrategy = class NumberRepeatStrategy { - getCollectionObserver() { - return null; - } - - instanceChanged(repeat, value) { - let removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(() => this._standardProcessItems(repeat, value)); - return; - } - this._standardProcessItems(repeat, value); - } - - _standardProcessItems(repeat, value) { - let childrenLength = repeat.viewCount(); - let i; - let ii; - let overrideContext; - let viewsToRemove; - - value = Math.floor(value); - viewsToRemove = childrenLength - value; - - if (viewsToRemove > 0) { - if (viewsToRemove > childrenLength) { - viewsToRemove = childrenLength; - } - - for (i = 0, ii = viewsToRemove; i < ii; ++i) { - repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle); - } - - return; - } - - for (i = childrenLength, ii = value; i < ii; ++i) { - overrideContext = createFullOverrideContext(repeat, i, i, ii); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - - updateOverrideContexts(repeat.views(), 0); - } -}; \ No newline at end of file diff --git a/dist/es2015/repeat-strategy-locator.js b/dist/es2015/repeat-strategy-locator.js deleted file mode 100644 index 5d55858..0000000 --- a/dist/es2015/repeat-strategy-locator.js +++ /dev/null @@ -1,35 +0,0 @@ -import { NullRepeatStrategy } from './null-repeat-strategy'; -import { ArrayRepeatStrategy } from './array-repeat-strategy'; -import { MapRepeatStrategy } from './map-repeat-strategy'; -import { SetRepeatStrategy } from './set-repeat-strategy'; -import { NumberRepeatStrategy } from './number-repeat-strategy'; - -export let RepeatStrategyLocator = class RepeatStrategyLocator { - constructor() { - this.matchers = []; - this.strategies = []; - - this.addStrategy(items => items === null || items === undefined, new NullRepeatStrategy()); - this.addStrategy(items => items instanceof Array, new ArrayRepeatStrategy()); - this.addStrategy(items => items instanceof Map, new MapRepeatStrategy()); - this.addStrategy(items => items instanceof Set, new SetRepeatStrategy()); - this.addStrategy(items => typeof items === 'number', new NumberRepeatStrategy()); - } - - addStrategy(matcher, strategy) { - this.matchers.push(matcher); - this.strategies.push(strategy); - } - - getStrategy(items) { - let matchers = this.matchers; - - for (let i = 0, ii = matchers.length; i < ii; ++i) { - if (matchers[i](items)) { - return this.strategies[i]; - } - } - - return null; - } -}; \ No newline at end of file diff --git a/dist/es2015/repeat-utilities.js b/dist/es2015/repeat-utilities.js deleted file mode 100644 index 42776f6..0000000 --- a/dist/es2015/repeat-utilities.js +++ /dev/null @@ -1,89 +0,0 @@ -import { createOverrideContext, BindingBehavior, ValueConverter, sourceContext, bindingMode } from 'aurelia-binding'; - -const oneTime = bindingMode.oneTime; - -export function updateOverrideContexts(views, startIndex) { - let length = views.length; - - if (startIndex > 0) { - startIndex = startIndex - 1; - } - - for (; startIndex < length; ++startIndex) { - updateOverrideContext(views[startIndex].overrideContext, startIndex, length); - } -} - -export function createFullOverrideContext(repeat, data, index, length, key) { - let bindingContext = {}; - let overrideContext = createOverrideContext(bindingContext, repeat.scope.overrideContext); - - if (typeof key !== 'undefined') { - bindingContext[repeat.key] = key; - bindingContext[repeat.value] = data; - } else { - bindingContext[repeat.local] = data; - } - updateOverrideContext(overrideContext, index, length); - return overrideContext; -} - -export function updateOverrideContext(overrideContext, index, length) { - let first = index === 0; - let last = index === length - 1; - let even = index % 2 === 0; - - overrideContext.$index = index; - overrideContext.$first = first; - overrideContext.$last = last; - overrideContext.$middle = !(first || last); - overrideContext.$odd = !even; - overrideContext.$even = even; -} - -export function getItemsSourceExpression(instruction, attrName) { - return instruction.behaviorInstructions.filter(bi => bi.originalAttrName === attrName)[0].attributes.items.sourceExpression; -} - -export function unwrapExpression(expression) { - let unwrapped = false; - while (expression instanceof BindingBehavior) { - expression = expression.expression; - } - while (expression instanceof ValueConverter) { - expression = expression.expression; - unwrapped = true; - } - return unwrapped ? expression : null; -} - -export function isOneTime(expression) { - while (expression instanceof BindingBehavior) { - if (expression.name === 'oneTime') { - return true; - } - expression = expression.expression; - } - return false; -} - -export function updateOneTimeBinding(binding) { - if (binding.call && binding.mode === oneTime) { - binding.call(sourceContext); - } else if (binding.updateOneTimeBindings) { - binding.updateOneTimeBindings(); - } -} - -export function indexOf(array, item, matcher, startIndex) { - if (!matcher) { - return array.indexOf(item); - } - const length = array.length; - for (let index = startIndex || 0; index < length; index++) { - if (matcher(array[index], item)) { - return index; - } - } - return -1; -} \ No newline at end of file diff --git a/dist/es2015/repeat.js b/dist/es2015/repeat.js deleted file mode 100644 index 42065e6..0000000 --- a/dist/es2015/repeat.js +++ /dev/null @@ -1,281 +0,0 @@ -var _dec, _dec2, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4; - -function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); -} - -function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; -} - -function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); -} - -import { inject } from 'aurelia-dependency-injection'; -import { ObserverLocator } from 'aurelia-binding'; -import { BoundViewFactory, TargetInstruction, ViewSlot, ViewResources, customAttribute, bindable, templateController } from 'aurelia-templating'; -import { RepeatStrategyLocator } from './repeat-strategy-locator'; -import { getItemsSourceExpression, unwrapExpression, isOneTime, updateOneTimeBinding } from './repeat-utilities'; -import { viewsRequireLifecycle } from './analyze-view-factory'; -import { AbstractRepeater } from './abstract-repeater'; - -export let Repeat = (_dec = customAttribute('repeat'), _dec2 = inject(BoundViewFactory, TargetInstruction, ViewSlot, ViewResources, ObserverLocator, RepeatStrategyLocator), _dec(_class = templateController(_class = _dec2(_class = (_class2 = class Repeat extends AbstractRepeater { - constructor(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) { - super({ - local: 'item', - viewsRequireLifecycle: viewsRequireLifecycle(viewFactory) - }); - - _initDefineProp(this, 'items', _descriptor, this); - - _initDefineProp(this, 'local', _descriptor2, this); - - _initDefineProp(this, 'key', _descriptor3, this); - - _initDefineProp(this, 'value', _descriptor4, this); - - this.viewFactory = viewFactory; - this.instruction = instruction; - this.viewSlot = viewSlot; - this.lookupFunctions = viewResources.lookupFunctions; - this.observerLocator = observerLocator; - this.key = 'key'; - this.value = 'value'; - this.strategyLocator = strategyLocator; - this.ignoreMutation = false; - this.sourceExpression = getItemsSourceExpression(this.instruction, 'repeat.for'); - this.isOneTime = isOneTime(this.sourceExpression); - this.viewsRequireLifecycle = viewsRequireLifecycle(viewFactory); - } - - call(context, changes) { - this[context](this.items, changes); - } - - bind(bindingContext, overrideContext) { - this.scope = { bindingContext, overrideContext }; - this.matcherBinding = this._captureAndRemoveMatcherBinding(); - this.itemsChanged(); - } - - unbind() { - this.scope = null; - this.items = null; - this.matcherBinding = null; - this.viewSlot.removeAll(true, true); - this._unsubscribeCollection(); - } - - _unsubscribeCollection() { - if (this.collectionObserver) { - this.collectionObserver.unsubscribe(this.callContext, this); - this.collectionObserver = null; - this.callContext = null; - } - } - - itemsChanged() { - this._unsubscribeCollection(); - - if (!this.scope) { - return; - } - - let items = this.items; - this.strategy = this.strategyLocator.getStrategy(items); - if (!this.strategy) { - throw new Error(`Value for '${this.sourceExpression}' is non-repeatable`); - } - - if (!this.isOneTime && !this._observeInnerCollection()) { - this._observeCollection(); - } - this.ignoreMutation = true; - this.strategy.instanceChanged(this, items); - this.observerLocator.taskQueue.queueMicroTask(() => { - this.ignoreMutation = false; - }); - } - - _getInnerCollection() { - let expression = unwrapExpression(this.sourceExpression); - if (!expression) { - return null; - } - return expression.evaluate(this.scope, null); - } - - handleCollectionMutated(collection, changes) { - if (!this.collectionObserver) { - return; - } - if (this.ignoreMutation) { - return; - } - this.strategy.instanceMutated(this, collection, changes); - } - - handleInnerCollectionMutated(collection, changes) { - if (!this.collectionObserver) { - return; - } - - if (this.ignoreMutation) { - return; - } - this.ignoreMutation = true; - let newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions); - this.observerLocator.taskQueue.queueMicroTask(() => this.ignoreMutation = false); - - if (newItems === this.items) { - this.itemsChanged(); - } else { - this.items = newItems; - } - } - - _observeInnerCollection() { - let items = this._getInnerCollection(); - let strategy = this.strategyLocator.getStrategy(items); - if (!strategy) { - return false; - } - this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items); - if (!this.collectionObserver) { - return false; - } - this.callContext = 'handleInnerCollectionMutated'; - this.collectionObserver.subscribe(this.callContext, this); - return true; - } - - _observeCollection() { - let items = this.items; - this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items); - if (this.collectionObserver) { - this.callContext = 'handleCollectionMutated'; - this.collectionObserver.subscribe(this.callContext, this); - } - } - - _captureAndRemoveMatcherBinding() { - if (this.viewFactory.viewFactory) { - const instructions = this.viewFactory.viewFactory.instructions; - const instructionIds = Object.keys(instructions); - for (let i = 0; i < instructionIds.length; i++) { - const expressions = instructions[instructionIds[i]].expressions; - if (expressions) { - for (let ii = 0; i < expressions.length; i++) { - if (expressions[ii].targetProperty === 'matcher') { - const matcherBinding = expressions[ii]; - expressions.splice(ii, 1); - return matcherBinding; - } - } - } - } - } - - return undefined; - } - - viewCount() { - return this.viewSlot.children.length; - } - views() { - return this.viewSlot.children; - } - view(index) { - return this.viewSlot.children[index]; - } - matcher() { - return this.matcherBinding ? this.matcherBinding.sourceExpression.evaluate(this.scope, this.matcherBinding.lookupFunctions) : null; - } - - addView(bindingContext, overrideContext) { - let view = this.viewFactory.create(); - view.bind(bindingContext, overrideContext); - this.viewSlot.add(view); - } - - insertView(index, bindingContext, overrideContext) { - let view = this.viewFactory.create(); - view.bind(bindingContext, overrideContext); - this.viewSlot.insert(index, view); - } - - moveView(sourceIndex, targetIndex) { - this.viewSlot.move(sourceIndex, targetIndex); - } - - removeAllViews(returnToCache, skipAnimation) { - return this.viewSlot.removeAll(returnToCache, skipAnimation); - } - - removeViews(viewsToRemove, returnToCache, skipAnimation) { - return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation); - } - - removeView(index, returnToCache, skipAnimation) { - return this.viewSlot.removeAt(index, returnToCache, skipAnimation); - } - - updateBindings(view) { - let j = view.bindings.length; - while (j--) { - updateOneTimeBinding(view.bindings[j]); - } - j = view.controllers.length; - while (j--) { - let k = view.controllers[j].boundProperties.length; - while (k--) { - let binding = view.controllers[j].boundProperties[k].binding; - updateOneTimeBinding(binding); - } - } - } -}, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'items', [bindable], { - enumerable: true, - initializer: null -}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'local', [bindable], { - enumerable: true, - initializer: null -}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'key', [bindable], { - enumerable: true, - initializer: null -}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, 'value', [bindable], { - enumerable: true, - initializer: null -})), _class2)) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/es2015/replaceable.js b/dist/es2015/replaceable.js deleted file mode 100644 index ab49255..0000000 --- a/dist/es2015/replaceable.js +++ /dev/null @@ -1,25 +0,0 @@ -var _dec, _dec2, _class; - -import { inject } from 'aurelia-dependency-injection'; -import { BoundViewFactory, ViewSlot, customAttribute, templateController } from 'aurelia-templating'; - -export let Replaceable = (_dec = customAttribute('replaceable'), _dec2 = inject(BoundViewFactory, ViewSlot), _dec(_class = templateController(_class = _dec2(_class = class Replaceable { - constructor(viewFactory, viewSlot) { - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.view = null; - } - - bind(bindingContext, overrideContext) { - if (this.view === null) { - this.view = this.viewFactory.create(); - this.viewSlot.add(this.view); - } - - this.view.bind(bindingContext, overrideContext); - } - - unbind() { - this.view.unbind(); - } -}) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/es2015/sanitize-html.js b/dist/es2015/sanitize-html.js deleted file mode 100644 index 99525fa..0000000 --- a/dist/es2015/sanitize-html.js +++ /dev/null @@ -1,19 +0,0 @@ -var _dec, _dec2, _class; - -import { valueConverter } from 'aurelia-binding'; -import { inject } from 'aurelia-dependency-injection'; -import { HTMLSanitizer } from './html-sanitizer'; - -export let SanitizeHTMLValueConverter = (_dec = valueConverter('sanitizeHTML'), _dec2 = inject(HTMLSanitizer), _dec(_class = _dec2(_class = class SanitizeHTMLValueConverter { - constructor(sanitizer) { - this.sanitizer = sanitizer; - } - - toView(untrustedMarkup) { - if (untrustedMarkup === null || untrustedMarkup === undefined) { - return null; - } - - return this.sanitizer.sanitize(untrustedMarkup); - } -}) || _class) || _class); \ No newline at end of file diff --git a/dist/es2015/self-binding-behavior.js b/dist/es2015/self-binding-behavior.js deleted file mode 100644 index 7c1ddae..0000000 --- a/dist/es2015/self-binding-behavior.js +++ /dev/null @@ -1,26 +0,0 @@ -var _dec, _class; - -import { bindingBehavior } from 'aurelia-binding'; - -function findOriginalEventTarget(event) { - return event.path && event.path[0] || event.deepPath && event.deepPath[0] || event.target; -} - -function handleSelfEvent(event) { - let target = findOriginalEventTarget(event); - if (this.target !== target) return; - this.selfEventCallSource(event); -} - -export let SelfBindingBehavior = (_dec = bindingBehavior('self'), _dec(_class = class SelfBindingBehavior { - bind(binding, source) { - if (!binding.callSource || !binding.targetEvent) throw new Error('Self binding behavior only supports event.'); - binding.selfEventCallSource = binding.callSource; - binding.callSource = handleSelfEvent; - } - - unbind(binding, source) { - binding.callSource = binding.selfEventCallSource; - binding.selfEventCallSource = null; - } -}) || _class); \ No newline at end of file diff --git a/dist/es2015/set-repeat-strategy.js b/dist/es2015/set-repeat-strategy.js deleted file mode 100644 index 644552a..0000000 --- a/dist/es2015/set-repeat-strategy.js +++ /dev/null @@ -1,85 +0,0 @@ -import { createFullOverrideContext, updateOverrideContexts } from './repeat-utilities'; - -export let SetRepeatStrategy = class SetRepeatStrategy { - getCollectionObserver(observerLocator, items) { - return observerLocator.getSetObserver(items); - } - - instanceChanged(repeat, items) { - let removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(() => this._standardProcessItems(repeat, items)); - return; - } - this._standardProcessItems(repeat, items); - } - - _standardProcessItems(repeat, items) { - let index = 0; - let overrideContext; - - items.forEach(value => { - overrideContext = createFullOverrideContext(repeat, value, index, items.size); - repeat.addView(overrideContext.bindingContext, overrideContext); - ++index; - }); - } - - instanceMutated(repeat, set, records) { - let value; - let i; - let ii; - let overrideContext; - let removeIndex; - let record; - let rmPromises = []; - let viewOrPromise; - - for (i = 0, ii = records.length; i < ii; ++i) { - record = records[i]; - value = record.value; - switch (record.type) { - case 'add': - let size = Math.max(set.size - 1, 0); - overrideContext = createFullOverrideContext(repeat, value, size, set.size); - repeat.insertView(size, overrideContext.bindingContext, overrideContext); - break; - case 'delete': - removeIndex = this._getViewIndexByValue(repeat, value); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - break; - case 'clear': - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - break; - default: - continue; - } - } - - if (rmPromises.length > 0) { - Promise.all(rmPromises).then(() => { - updateOverrideContexts(repeat.views(), 0); - }); - } else { - updateOverrideContexts(repeat.views(), 0); - } - } - - _getViewIndexByValue(repeat, value) { - let i; - let ii; - let child; - - for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { - child = repeat.view(i); - if (child.bindingContext[repeat.local] === value) { - return i; - } - } - - return undefined; - } -}; \ No newline at end of file diff --git a/dist/es2015/show.js b/dist/es2015/show.js deleted file mode 100644 index a82b4b3..0000000 --- a/dist/es2015/show.js +++ /dev/null @@ -1,35 +0,0 @@ -var _dec, _class; - -import { Optional } from 'aurelia-dependency-injection'; -import { customAttribute, Animator } from 'aurelia-templating'; -import { DOM } from 'aurelia-pal'; -import { injectAureliaHideStyleAtBoundary, aureliaHideClassName } from './aurelia-hide-style'; - -export let Show = (_dec = customAttribute('show'), _dec(_class = class Show { - - static inject() { - return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; - } - - constructor(element, animator, domBoundary) { - this.element = element; - this.animator = animator; - this.domBoundary = domBoundary; - } - - created() { - injectAureliaHideStyleAtBoundary(this.domBoundary); - } - - valueChanged(newValue) { - if (newValue) { - this.animator.removeClass(this.element, aureliaHideClassName); - } else { - this.animator.addClass(this.element, aureliaHideClassName); - } - } - - bind(bindingContext) { - this.valueChanged(this.value); - } -}) || _class); \ No newline at end of file diff --git a/dist/es2015/signal-binding-behavior.js b/dist/es2015/signal-binding-behavior.js deleted file mode 100644 index 09dd6d7..0000000 --- a/dist/es2015/signal-binding-behavior.js +++ /dev/null @@ -1,54 +0,0 @@ -var _dec, _class; - -import { bindingBehavior } from 'aurelia-binding'; -import { BindingSignaler } from './binding-signaler'; - -export let SignalBindingBehavior = (_dec = bindingBehavior('signal'), _dec(_class = class SignalBindingBehavior { - static inject() { - return [BindingSignaler]; - } - - - constructor(bindingSignaler) { - this.signals = bindingSignaler.signals; - } - - bind(binding, source, ...names) { - if (!binding.updateTarget) { - throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.'); - } - if (names.length === 1) { - let name = names[0]; - let bindings = this.signals[name] || (this.signals[name] = []); - bindings.push(binding); - binding.signalName = name; - } else if (names.length > 1) { - let i = names.length; - while (i--) { - let name = names[i]; - let bindings = this.signals[name] || (this.signals[name] = []); - bindings.push(binding); - } - binding.signalName = names; - } else { - throw new Error('Signal name is required.'); - } - } - - unbind(binding, source) { - let name = binding.signalName; - binding.signalName = null; - if (Array.isArray(name)) { - let names = name; - let i = names.length; - while (i--) { - let n = names[i]; - let bindings = this.signals[n]; - bindings.splice(bindings.indexOf(binding), 1); - } - } else { - let bindings = this.signals[name]; - bindings.splice(bindings.indexOf(binding), 1); - } - } -}) || _class); \ No newline at end of file diff --git a/dist/es2015/throttle-binding-behavior.js b/dist/es2015/throttle-binding-behavior.js deleted file mode 100644 index 2aef321..0000000 --- a/dist/es2015/throttle-binding-behavior.js +++ /dev/null @@ -1,53 +0,0 @@ -var _dec, _class; - -import { bindingMode, bindingBehavior } from 'aurelia-binding'; - -function throttle(newValue) { - let state = this.throttleState; - let elapsed = +new Date() - state.last; - if (elapsed >= state.delay) { - clearTimeout(state.timeoutId); - state.timeoutId = null; - state.last = +new Date(); - this.throttledMethod(newValue); - return; - } - state.newValue = newValue; - if (state.timeoutId === null) { - state.timeoutId = setTimeout(() => { - state.timeoutId = null; - state.last = +new Date(); - this.throttledMethod(state.newValue); - }, state.delay - elapsed); - } -} - -export let ThrottleBindingBehavior = (_dec = bindingBehavior('throttle'), _dec(_class = class ThrottleBindingBehavior { - bind(binding, source, delay = 200) { - let methodToThrottle = 'updateTarget'; - if (binding.callSource) { - methodToThrottle = 'callSource'; - } else if (binding.updateSource && binding.mode === bindingMode.twoWay) { - methodToThrottle = 'updateSource'; - } - - binding.throttledMethod = binding[methodToThrottle]; - binding.throttledMethod.originalName = methodToThrottle; - - binding[methodToThrottle] = throttle; - - binding.throttleState = { - delay: delay, - last: 0, - timeoutId: null - }; - } - - unbind(binding, source) { - let methodToRestore = binding.throttledMethod.originalName; - binding[methodToRestore] = binding.throttledMethod; - binding.throttledMethod = null; - clearTimeout(binding.throttleState.timeoutId); - binding.throttleState = null; - } -}) || _class); \ No newline at end of file diff --git a/dist/es2015/update-trigger-binding-behavior.js b/dist/es2015/update-trigger-binding-behavior.js deleted file mode 100644 index b07475b..0000000 --- a/dist/es2015/update-trigger-binding-behavior.js +++ /dev/null @@ -1,35 +0,0 @@ -var _dec, _class; - -import { bindingMode, EventSubscriber, bindingBehavior } from 'aurelia-binding'; - -const eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg '; -const notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.'; - -export let UpdateTriggerBindingBehavior = (_dec = bindingBehavior('updateTrigger'), _dec(_class = class UpdateTriggerBindingBehavior { - - bind(binding, source, ...events) { - if (events.length === 0) { - throw new Error(eventNamesRequired); - } - if (binding.mode !== bindingMode.twoWay && binding.mode !== bindingMode.fromView) { - throw new Error(notApplicableMessage); - } - - let targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty); - if (!targetObserver.handler) { - throw new Error(notApplicableMessage); - } - binding.targetObserver = targetObserver; - - targetObserver.originalHandler = binding.targetObserver.handler; - - let handler = new EventSubscriber(events); - targetObserver.handler = handler; - } - - unbind(binding, source) { - binding.targetObserver.handler.dispose(); - binding.targetObserver.handler = binding.targetObserver.originalHandler; - binding.targetObserver.originalHandler = null; - } -}) || _class); \ No newline at end of file diff --git a/dist/es2015/with.js b/dist/es2015/with.js deleted file mode 100644 index 1221530..0000000 --- a/dist/es2015/with.js +++ /dev/null @@ -1,38 +0,0 @@ -var _dec, _dec2, _class; - -import { inject } from 'aurelia-dependency-injection'; -import { BoundViewFactory, ViewSlot, customAttribute, templateController } from 'aurelia-templating'; -import { createOverrideContext } from 'aurelia-binding'; - -export let With = (_dec = customAttribute('with'), _dec2 = inject(BoundViewFactory, ViewSlot), _dec(_class = templateController(_class = _dec2(_class = class With { - constructor(viewFactory, viewSlot) { - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.parentOverrideContext = null; - this.view = null; - } - - bind(bindingContext, overrideContext) { - this.parentOverrideContext = overrideContext; - this.valueChanged(this.value); - } - - valueChanged(newValue) { - let overrideContext = createOverrideContext(newValue, this.parentOverrideContext); - if (!this.view) { - this.view = this.viewFactory.create(); - this.view.bind(newValue, overrideContext); - this.viewSlot.add(this.view); - } else { - this.view.bind(newValue, overrideContext); - } - } - - unbind() { - this.parentOverrideContext = null; - - if (this.view) { - this.view.unbind(); - } - } -}) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/es2017/aurelia-templating-resources.js b/dist/es2017/aurelia-templating-resources.js new file mode 100644 index 0000000..a37e684 --- /dev/null +++ b/dist/es2017/aurelia-templating-resources.js @@ -0,0 +1,1773 @@ +import { Container, inject, Optional } from 'aurelia-dependency-injection'; +import { DOM, FEATURE } from 'aurelia-pal'; +import { TaskQueue } from 'aurelia-task-queue'; +import { CompositionEngine, ViewSlot, ViewResources, bindable, noView, customElement, customAttribute, templateController, BoundViewFactory, TargetInstruction, Animator, resource, useView, useShadowDOM, ViewEngine } from 'aurelia-templating'; +import { createOverrideContext, bindingMode, BindingBehavior, ValueConverter, sourceContext, mergeSplice, ObserverLocator, valueConverter, DataAttributeObserver, bindingBehavior, targetContext, EventSubscriber } from 'aurelia-binding'; +import { getLogger } from 'aurelia-logging'; +import { Loader } from 'aurelia-loader'; +import { relativeToFile } from 'aurelia-path'; +import { mixin } from 'aurelia-metadata'; + +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + +function __decorate(decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +} + +let Compose = class Compose { + constructor(element, container, compositionEngine, viewSlot, viewResources, taskQueue) { + this.element = element; + this.container = container; + this.compositionEngine = compositionEngine; + this.viewSlot = viewSlot; + this.viewResources = viewResources; + this.taskQueue = taskQueue; + this.currentController = null; + this.currentViewModel = null; + this.changes = Object.create(null); + } + static inject() { + return [DOM.Element, Container, CompositionEngine, ViewSlot, ViewResources, TaskQueue]; + } + created(owningView) { + this.owningView = owningView; + } + bind(bindingContext, overrideContext) { + this.bindingContext = bindingContext; + this.overrideContext = overrideContext; + let changes = this.changes; + changes.view = this.view; + changes.viewModel = this.viewModel; + changes.model = this.model; + if (!this.pendingTask) { + processChanges(this); + } + } + unbind() { + this.changes = Object.create(null); + this.bindingContext = null; + this.overrideContext = null; + let returnToCache = true; + let skipAnimation = true; + this.viewSlot.removeAll(returnToCache, skipAnimation); + } + modelChanged(newValue, oldValue) { + this.changes.model = newValue; + requestUpdate(this); + } + viewChanged(newValue, oldValue) { + this.changes.view = newValue; + requestUpdate(this); + } + viewModelChanged(newValue, oldValue) { + this.changes.viewModel = newValue; + requestUpdate(this); + } +}; +__decorate([ + bindable +], Compose.prototype, "model", void 0); +__decorate([ + bindable +], Compose.prototype, "view", void 0); +__decorate([ + bindable +], Compose.prototype, "viewModel", void 0); +__decorate([ + bindable +], Compose.prototype, "swapOrder", void 0); +Compose = __decorate([ + noView, + customElement('compose') +], Compose); +function isEmpty(obj) { + for (const _ in obj) { + return false; + } + return true; +} +function tryActivateViewModel(vm, model) { + if (vm && typeof vm.activate === 'function') { + return Promise.resolve(vm.activate(model)); + } +} +function createInstruction(composer, instruction) { + return Object.assign(instruction, { + bindingContext: composer.bindingContext, + overrideContext: composer.overrideContext, + owningView: composer.owningView, + container: composer.container, + viewSlot: composer.viewSlot, + viewResources: composer.viewResources, + currentController: composer.currentController, + host: composer.element, + swapOrder: composer.swapOrder + }); +} +function processChanges(composer) { + const changes = composer.changes; + composer.changes = Object.create(null); + if (!('view' in changes) && !('viewModel' in changes) && ('model' in changes)) { + composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model); + if (!composer.pendingTask) { + return; + } + } + else { + let instruction = { + view: composer.view, + viewModel: composer.currentViewModel || composer.viewModel, + model: composer.model + }; + instruction = Object.assign(instruction, changes); + instruction = createInstruction(composer, instruction); + composer.pendingTask = composer.compositionEngine.compose(instruction).then(controller => { + composer.currentController = controller; + composer.currentViewModel = controller ? controller.viewModel : null; + }); + } + composer.pendingTask = composer.pendingTask + .then(() => { + completeCompositionTask(composer); + }, reason => { + completeCompositionTask(composer); + throw reason; + }); +} +function completeCompositionTask(composer) { + composer.pendingTask = null; + if (!isEmpty(composer.changes)) { + processChanges(composer); + } +} +function requestUpdate(composer) { + if (composer.pendingTask || composer.updateRequested) { + return; + } + composer.updateRequested = true; + composer.taskQueue.queueMicroTask(() => { + composer.updateRequested = false; + processChanges(composer); + }); +} + +class IfCore { + constructor(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.view = null; + this.bindingContext = null; + this.overrideContext = null; + this.showing = false; + this.cache = true; + } + bind(bindingContext, overrideContext) { + this.bindingContext = bindingContext; + this.overrideContext = overrideContext; + } + unbind() { + if (this.view === null) { + return; + } + this.view.unbind(); + if (!this.viewFactory.isCaching) { + return; + } + if (this.showing) { + this.showing = false; + this.viewSlot.remove(this.view, true, true); + } + else { + this.view.returnToCache(); + } + this.view = null; + } + _show() { + if (this.showing) { + if (!this.view.isBound) { + this.view.bind(this.bindingContext, this.overrideContext); + } + return; + } + if (this.view === null) { + this.view = this.viewFactory.create(); + } + if (!this.view.isBound) { + this.view.bind(this.bindingContext, this.overrideContext); + } + this.showing = true; + return this.viewSlot.add(this.view); + } + _hide() { + if (!this.showing) { + return; + } + this.showing = false; + let removed = this.viewSlot.remove(this.view); + if (removed instanceof Promise) { + return removed.then(() => { + this._unbindView(); + }); + } + this._unbindView(); + } + _unbindView() { + const cache = this.cache === 'false' ? false : !!this.cache; + this.view.unbind(); + if (!cache) { + this.view = null; + } + } +} + +let If = class If extends IfCore { + constructor() { + super(...arguments); + this.cache = true; + } + bind(bindingContext, overrideContext) { + super.bind(bindingContext, overrideContext); + if (this.condition) { + this._show(); + } + else { + this._hide(); + } + } + conditionChanged(newValue) { + this._update(newValue); + } + _update(show) { + if (this.animating) { + return; + } + let promise; + if (this.elseVm) { + promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm); + } + else { + promise = show ? this._show() : this._hide(); + } + if (promise) { + this.animating = true; + promise.then(() => { + this.animating = false; + if (this.condition !== this.showing) { + this._update(this.condition); + } + }); + } + } + _swap(remove, add) { + switch (this.swapOrder) { + case 'before': + return Promise.resolve(add._show()).then(() => remove._hide()); + case 'with': + return Promise.all([remove._hide(), add._show()]); + default: + let promise = remove._hide(); + return promise ? promise.then(() => add._show()) : add._show(); + } + } +}; +__decorate([ + bindable({ primaryProperty: true }) +], If.prototype, "condition", void 0); +__decorate([ + bindable +], If.prototype, "swapOrder", void 0); +__decorate([ + bindable +], If.prototype, "cache", void 0); +If = __decorate([ + customAttribute('if'), + templateController, + inject(BoundViewFactory, ViewSlot) +], If); + +let Else = class Else extends IfCore { + constructor(viewFactory, viewSlot) { + super(viewFactory, viewSlot); + this._registerInIf(); + } + bind(bindingContext, overrideContext) { + super.bind(bindingContext, overrideContext); + if (this.ifVm.condition) { + this._hide(); + } + else { + this._show(); + } + } + _registerInIf() { + let previous = this.viewSlot.anchor.previousSibling; + while (previous && !previous.au) { + previous = previous.previousSibling; + } + if (!previous || !previous.au.if) { + throw new Error("Can't find matching If for Else custom attribute."); + } + this.ifVm = previous.au.if.viewModel; + this.ifVm.elseVm = this; + } +}; +Else = __decorate([ + customAttribute('else'), + templateController, + inject(BoundViewFactory, ViewSlot) +], Else); + +let With = class With { + constructor(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.parentOverrideContext = null; + this.view = null; + } + bind(bindingContext, overrideContext) { + this.parentOverrideContext = overrideContext; + this.valueChanged(this.value); + } + valueChanged(newValue) { + let overrideContext = createOverrideContext(newValue, this.parentOverrideContext); + let view = this.view; + if (!view) { + view = this.view = this.viewFactory.create(); + view.bind(newValue, overrideContext); + this.viewSlot.add(view); + } + else { + view.bind(newValue, overrideContext); + } + } + unbind() { + let view = this.view; + this.parentOverrideContext = null; + if (view) { + view.unbind(); + } + } +}; +With = __decorate([ + customAttribute('with'), + templateController, + inject(BoundViewFactory, ViewSlot) +], With); + +const oneTime = bindingMode.oneTime; +function updateOverrideContexts(views, startIndex) { + let length = views.length; + if (startIndex > 0) { + startIndex = startIndex - 1; + } + for (; startIndex < length; ++startIndex) { + updateOverrideContext(views[startIndex].overrideContext, startIndex, length); + } +} +function createFullOverrideContext(repeat, data, index, length, key) { + let bindingContext = {}; + let overrideContext = createOverrideContext(bindingContext, repeat.scope.overrideContext); + if (typeof key !== 'undefined') { + bindingContext[repeat.key] = key; + bindingContext[repeat.value] = data; + } + else { + bindingContext[repeat.local] = data; + } + updateOverrideContext(overrideContext, index, length); + return overrideContext; +} +function updateOverrideContext(overrideContext, index, length) { + let first = (index === 0); + let last = (index === length - 1); + let even = index % 2 === 0; + overrideContext.$index = index; + overrideContext.$first = first; + overrideContext.$last = last; + overrideContext.$middle = !(first || last); + overrideContext.$odd = !even; + overrideContext.$even = even; +} +function getItemsSourceExpression(instruction, attrName) { + return instruction.behaviorInstructions + .filter(bi => bi.originalAttrName === attrName)[0] + .attributes + .items + .sourceExpression; +} +function unwrapExpression(expression) { + let unwrapped = false; + while (expression instanceof BindingBehavior) { + expression = expression.expression; + } + while (expression instanceof ValueConverter) { + expression = expression.expression; + unwrapped = true; + } + return unwrapped ? expression : null; +} +function isOneTime(expression) { + while (expression instanceof BindingBehavior) { + if (expression.name === 'oneTime') { + return true; + } + expression = expression.expression; + } + return false; +} +function updateOneTimeBinding(binding) { + if (binding.call && binding.mode === oneTime) { + binding.call(sourceContext); + } + else if (binding.updateOneTimeBindings) { + binding.updateOneTimeBindings(); + } +} +function indexOf(array, item, matcher, startIndex) { + if (!matcher) { + return array.indexOf(item); + } + const length = array.length; + for (let index = startIndex || 0; index < length; index++) { + if (matcher(array[index], item)) { + return index; + } + } + return -1; +} + +class ArrayRepeatStrategy { + getCollectionObserver(observerLocator, items) { + return observerLocator.getArrayObserver(items); + } + instanceChanged(repeat, items) { + const itemsLength = items.length; + if (!items || itemsLength === 0) { + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + return; + } + const children = repeat.views(); + const viewsLength = children.length; + if (viewsLength === 0) { + this._standardProcessInstanceChanged(repeat, items); + return; + } + if (repeat.viewsRequireLifecycle) { + const childrenSnapshot = children.slice(0); + const itemNameInBindingContext = repeat.local; + const matcher = repeat.matcher(); + let itemsPreviouslyInViews = []; + const viewsToRemove = []; + for (let index = 0; index < viewsLength; index++) { + const view = childrenSnapshot[index]; + const oldItem = view.bindingContext[itemNameInBindingContext]; + if (indexOf(items, oldItem, matcher) === -1) { + viewsToRemove.push(view); + } + else { + itemsPreviouslyInViews.push(oldItem); + } + } + let updateViews; + let removePromise; + if (itemsPreviouslyInViews.length > 0) { + removePromise = repeat.removeViews(viewsToRemove, true, !repeat.viewsRequireLifecycle); + updateViews = () => { + for (let index = 0; index < itemsLength; index++) { + const item = items[index]; + const indexOfView = indexOf(itemsPreviouslyInViews, item, matcher, index); + let view; + if (indexOfView === -1) { + const overrideContext = createFullOverrideContext(repeat, items[index], index, itemsLength); + repeat.insertView(index, overrideContext.bindingContext, overrideContext); + itemsPreviouslyInViews.splice(index, 0, undefined); + } + else if (indexOfView === index) { + view = children[indexOfView]; + itemsPreviouslyInViews[indexOfView] = undefined; + } + else { + view = children[indexOfView]; + repeat.moveView(indexOfView, index); + itemsPreviouslyInViews.splice(indexOfView, 1); + itemsPreviouslyInViews.splice(index, 0, undefined); + } + if (view) { + updateOverrideContext(view.overrideContext, index, itemsLength); + } + } + this._inPlaceProcessItems(repeat, items); + }; + } + else { + removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + updateViews = () => this._standardProcessInstanceChanged(repeat, items); + } + if (removePromise instanceof Promise) { + removePromise.then(updateViews); + } + else { + updateViews(); + } + } + else { + this._inPlaceProcessItems(repeat, items); + } + } + _standardProcessInstanceChanged(repeat, items) { + for (let i = 0, ii = items.length; i < ii; i++) { + let overrideContext = createFullOverrideContext(repeat, items[i], i, ii); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + } + _inPlaceProcessItems(repeat, items) { + let itemsLength = items.length; + let viewsLength = repeat.viewCount(); + while (viewsLength > itemsLength) { + viewsLength--; + repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle); + } + let local = repeat.local; + for (let i = 0; i < viewsLength; i++) { + let view = repeat.view(i); + let last = i === itemsLength - 1; + let middle = i !== 0 && !last; + let bindingContext = view.bindingContext; + let overrideContext = view.overrideContext; + if (bindingContext[local] === items[i] + && overrideContext.$middle === middle + && overrideContext.$last === last) { + continue; + } + bindingContext[local] = items[i]; + overrideContext.$middle = middle; + overrideContext.$last = last; + repeat.updateBindings(view); + } + for (let i = viewsLength; i < itemsLength; i++) { + let overrideContext = createFullOverrideContext(repeat, items[i], i, itemsLength); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + } + instanceMutated(repeat, array, splices) { + if (repeat.__queuedSplices) { + for (let i = 0, ii = splices.length; i < ii; ++i) { + let { index, removed, addedCount } = splices[i]; + mergeSplice(repeat.__queuedSplices, index, removed, addedCount); + } + repeat.__array = array.slice(0); + return; + } + let maybePromise = this._runSplices(repeat, array.slice(0), splices); + if (maybePromise instanceof Promise) { + let queuedSplices = repeat.__queuedSplices = []; + let runQueuedSplices = () => { + if (!queuedSplices.length) { + repeat.__queuedSplices = undefined; + repeat.__array = undefined; + return; + } + let nextPromise = this._runSplices(repeat, repeat.__array, queuedSplices) || Promise.resolve(); + queuedSplices = repeat.__queuedSplices = []; + nextPromise.then(runQueuedSplices); + }; + maybePromise.then(runQueuedSplices); + } + } + _runSplices(repeat, array, splices) { + let removeDelta = 0; + let rmPromises = []; + for (let i = 0, ii = splices.length; i < ii; ++i) { + let splice = splices[i]; + let removed = splice.removed; + for (let j = 0, jj = removed.length; j < jj; ++j) { + let viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + } + removeDelta -= splice.addedCount; + } + if (rmPromises.length > 0) { + return Promise.all(rmPromises).then(() => { + let spliceIndexLow = this._handleAddedSplices(repeat, array, splices); + updateOverrideContexts(repeat.views(), spliceIndexLow); + }); + } + let spliceIndexLow = this._handleAddedSplices(repeat, array, splices); + updateOverrideContexts(repeat.views(), spliceIndexLow); + return undefined; + } + _handleAddedSplices(repeat, array, splices) { + let spliceIndex; + let spliceIndexLow; + let arrayLength = array.length; + for (let i = 0, ii = splices.length; i < ii; ++i) { + let splice = splices[i]; + let addIndex = spliceIndex = splice.index; + let end = splice.index + splice.addedCount; + if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) { + spliceIndexLow = spliceIndex; + } + for (; addIndex < end; ++addIndex) { + let overrideContext = createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength); + repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext); + } + } + return spliceIndexLow; + } +} + +class MapRepeatStrategy { + getCollectionObserver(observerLocator, items) { + return observerLocator.getMapObserver(items); + } + instanceChanged(repeat, items) { + let removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(() => this._standardProcessItems(repeat, items)); + return; + } + this._standardProcessItems(repeat, items); + } + _standardProcessItems(repeat, items) { + let index = 0; + let overrideContext; + items.forEach((value, key) => { + overrideContext = createFullOverrideContext(repeat, value, index, items.size, key); + repeat.addView(overrideContext.bindingContext, overrideContext); + ++index; + }); + } + instanceMutated(repeat, map, records) { + let key; + let i; + let ii; + let overrideContext; + let removeIndex; + let addIndex; + let record; + let rmPromises = []; + let viewOrPromise; + for (i = 0, ii = records.length; i < ii; ++i) { + record = records[i]; + key = record.key; + switch (record.type) { + case 'update': + removeIndex = this._getViewIndexByKey(repeat, key); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + overrideContext = createFullOverrideContext(repeat, map.get(key), removeIndex, map.size, key); + repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext); + break; + case 'add': + addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1; + overrideContext = createFullOverrideContext(repeat, map.get(key), addIndex, map.size, key); + repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext); + break; + case 'delete': + if (record.oldValue === undefined) { + return; + } + removeIndex = this._getViewIndexByKey(repeat, key); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + break; + case 'clear': + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + break; + default: + continue; + } + } + if (rmPromises.length > 0) { + Promise.all(rmPromises).then(() => { + updateOverrideContexts(repeat.views(), 0); + }); + } + else { + updateOverrideContexts(repeat.views(), 0); + } + } + _getViewIndexByKey(repeat, key) { + let i; + let ii; + let child; + for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { + child = repeat.view(i); + if (child.bindingContext[repeat.key] === key) { + return i; + } + } + return undefined; + } +} + +class NullRepeatStrategy { + instanceChanged(repeat, items) { + repeat.removeAllViews(true); + } + getCollectionObserver(observerLocator, items) { + } +} + +class NumberRepeatStrategy { + getCollectionObserver() { + return null; + } + instanceChanged(repeat, value) { + let removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(() => this._standardProcessItems(repeat, value)); + return; + } + this._standardProcessItems(repeat, value); + } + _standardProcessItems(repeat, value) { + let childrenLength = repeat.viewCount(); + let i; + let ii; + let overrideContext; + let viewsToRemove; + value = Math.floor(value); + viewsToRemove = childrenLength - value; + if (viewsToRemove > 0) { + if (viewsToRemove > childrenLength) { + viewsToRemove = childrenLength; + } + for (i = 0, ii = viewsToRemove; i < ii; ++i) { + repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle); + } + return; + } + for (i = childrenLength, ii = value; i < ii; ++i) { + overrideContext = createFullOverrideContext(repeat, i, i, ii); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + updateOverrideContexts(repeat.views(), 0); + } +} + +class SetRepeatStrategy { + getCollectionObserver(observerLocator, items) { + return observerLocator.getSetObserver(items); + } + instanceChanged(repeat, items) { + let removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(() => this._standardProcessItems(repeat, items)); + return; + } + this._standardProcessItems(repeat, items); + } + _standardProcessItems(repeat, items) { + let index = 0; + let overrideContext; + items.forEach(value => { + overrideContext = createFullOverrideContext(repeat, value, index, items.size); + repeat.addView(overrideContext.bindingContext, overrideContext); + ++index; + }); + } + instanceMutated(repeat, set, records) { + let value; + let i; + let ii; + let overrideContext; + let removeIndex; + let record; + let rmPromises = []; + let viewOrPromise; + for (i = 0, ii = records.length; i < ii; ++i) { + record = records[i]; + value = record.value; + switch (record.type) { + case 'add': + let size = Math.max(set.size - 1, 0); + overrideContext = createFullOverrideContext(repeat, value, size, set.size); + repeat.insertView(size, overrideContext.bindingContext, overrideContext); + break; + case 'delete': + removeIndex = this._getViewIndexByValue(repeat, value); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + break; + case 'clear': + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + break; + default: + continue; + } + } + if (rmPromises.length > 0) { + Promise.all(rmPromises).then(() => { + updateOverrideContexts(repeat.views(), 0); + }); + } + else { + updateOverrideContexts(repeat.views(), 0); + } + } + _getViewIndexByValue(repeat, value) { + let i; + let ii; + let child; + for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { + child = repeat.view(i); + if (child.bindingContext[repeat.local] === value) { + return i; + } + } + return undefined; + } +} + +class RepeatStrategyLocator { + constructor() { + this.matchers = []; + this.strategies = []; + this.addStrategy(items => items === null || items === undefined, new NullRepeatStrategy()); + this.addStrategy(items => items instanceof Array, new ArrayRepeatStrategy()); + this.addStrategy(items => items instanceof Map, new MapRepeatStrategy()); + this.addStrategy(items => items instanceof Set, new SetRepeatStrategy()); + this.addStrategy(items => typeof items === 'number', new NumberRepeatStrategy()); + } + addStrategy(matcher, strategy) { + this.matchers.push(matcher); + this.strategies.push(strategy); + } + getStrategy(items) { + let matchers = this.matchers; + for (let i = 0, ii = matchers.length; i < ii; ++i) { + if (matchers[i](items)) { + return this.strategies[i]; + } + } + return null; + } +} + +const lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with']; +function behaviorRequiresLifecycle(instruction) { + let t = instruction.type; + let name = t.elementName !== null ? t.elementName : t.attributeName; + return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind) + || t.viewFactory && viewsRequireLifecycle(t.viewFactory) + || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); +} +function targetRequiresLifecycle(instruction) { + let behaviors = instruction.behaviorInstructions; + if (behaviors) { + let i = behaviors.length; + while (i--) { + if (behaviorRequiresLifecycle(behaviors[i])) { + return true; + } + } + } + return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); +} +function viewsRequireLifecycle(viewFactory) { + if ('_viewsRequireLifecycle' in viewFactory) { + return viewFactory._viewsRequireLifecycle; + } + viewFactory._viewsRequireLifecycle = false; + if (viewFactory.viewFactory) { + viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory); + return viewFactory._viewsRequireLifecycle; + } + if (viewFactory.template.querySelector('.au-animate')) { + viewFactory._viewsRequireLifecycle = true; + return true; + } + for (let id in viewFactory.instructions) { + if (targetRequiresLifecycle(viewFactory.instructions[id])) { + viewFactory._viewsRequireLifecycle = true; + return true; + } + } + viewFactory._viewsRequireLifecycle = false; + return false; +} + +class AbstractRepeater { + constructor(options) { + Object.assign(this, { + local: 'items', + viewsRequireLifecycle: true + }, options); + } + viewCount() { + throw new Error('subclass must implement `viewCount`'); + } + views() { + throw new Error('subclass must implement `views`'); + } + view(index) { + throw new Error('subclass must implement `view`'); + } + matcher() { + throw new Error('subclass must implement `matcher`'); + } + addView(bindingContext, overrideContext) { + throw new Error('subclass must implement `addView`'); + } + insertView(index, bindingContext, overrideContext) { + throw new Error('subclass must implement `insertView`'); + } + moveView(sourceIndex, targetIndex) { + throw new Error('subclass must implement `moveView`'); + } + removeAllViews(returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeAllViews`'); + } + removeViews(viewsToRemove, returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeView`'); + } + removeView(index, returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeView`'); + } + updateBindings(view) { + throw new Error('subclass must implement `updateBindings`'); + } +} + +let Repeat = class Repeat extends AbstractRepeater { + constructor(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) { + super({ + local: 'item', + viewsRequireLifecycle: viewsRequireLifecycle(viewFactory) + }); + this.viewFactory = viewFactory; + this.instruction = instruction; + this.viewSlot = viewSlot; + this.lookupFunctions = viewResources.lookupFunctions; + this.observerLocator = observerLocator; + this.key = 'key'; + this.value = 'value'; + this.strategyLocator = strategyLocator; + this.ignoreMutation = false; + this.sourceExpression = getItemsSourceExpression(this.instruction, 'repeat.for'); + this.isOneTime = isOneTime(this.sourceExpression); + this.viewsRequireLifecycle = viewsRequireLifecycle(viewFactory); + } + call(context, changes) { + this[context](this.items, changes); + } + bind(bindingContext, overrideContext) { + this.scope = { bindingContext, overrideContext }; + this.matcherBinding = this._captureAndRemoveMatcherBinding(); + this.itemsChanged(); + } + unbind() { + this.scope = null; + this.items = null; + this.matcherBinding = null; + this.viewSlot.removeAll(true, true); + this._unsubscribeCollection(); + } + _unsubscribeCollection() { + if (this.collectionObserver) { + this.collectionObserver.unsubscribe(this.callContext, this); + this.collectionObserver = null; + this.callContext = null; + } + } + itemsChanged() { + this._unsubscribeCollection(); + if (!this.scope) { + return; + } + let items = this.items; + this.strategy = this.strategyLocator.getStrategy(items); + if (!this.strategy) { + throw new Error(`Value for '${this.sourceExpression}' is non-repeatable`); + } + if (!this.isOneTime && !this._observeInnerCollection()) { + this._observeCollection(); + } + this.ignoreMutation = true; + this.strategy.instanceChanged(this, items); + this.observerLocator.taskQueue.queueMicroTask(() => { + this.ignoreMutation = false; + }); + } + _getInnerCollection() { + let expression = unwrapExpression(this.sourceExpression); + if (!expression) { + return null; + } + return expression.evaluate(this.scope, null); + } + handleCollectionMutated(collection, changes) { + if (!this.collectionObserver) { + return; + } + if (this.ignoreMutation) { + return; + } + this.strategy.instanceMutated(this, collection, changes); + } + handleInnerCollectionMutated(collection, changes) { + if (!this.collectionObserver) { + return; + } + if (this.ignoreMutation) { + return; + } + this.ignoreMutation = true; + let newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions); + this.observerLocator.taskQueue.queueMicroTask(() => this.ignoreMutation = false); + if (newItems === this.items) { + this.itemsChanged(); + } + else { + this.items = newItems; + } + } + _observeInnerCollection() { + let items = this._getInnerCollection(); + let strategy = this.strategyLocator.getStrategy(items); + if (!strategy) { + return false; + } + this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items); + if (!this.collectionObserver) { + return false; + } + this.callContext = 'handleInnerCollectionMutated'; + this.collectionObserver.subscribe(this.callContext, this); + return true; + } + _observeCollection() { + let items = this.items; + this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items); + if (this.collectionObserver) { + this.callContext = 'handleCollectionMutated'; + this.collectionObserver.subscribe(this.callContext, this); + } + } + _captureAndRemoveMatcherBinding() { + if (this.viewFactory.viewFactory) { + const instructions = this.viewFactory.viewFactory.instructions; + const instructionIds = Object.keys(instructions); + for (let i = 0; i < instructionIds.length; i++) { + const expressions = instructions[instructionIds[i]].expressions; + if (expressions) { + for (let ii = 0; ii < expressions.length; ii++) { + if (expressions[ii].targetProperty === 'matcher') { + const matcherBinding = expressions[ii]; + expressions.splice(ii, 1); + return matcherBinding; + } + } + } + } + } + return undefined; + } + viewCount() { return this.viewSlot.children.length; } + views() { return this.viewSlot.children; } + view(index) { return this.viewSlot.children[index]; } + matcher() { return this.matcherBinding ? this.matcherBinding.sourceExpression.evaluate(this.scope, this.matcherBinding.lookupFunctions) : null; } + addView(bindingContext, overrideContext) { + let view = this.viewFactory.create(); + view.bind(bindingContext, overrideContext); + this.viewSlot.add(view); + } + insertView(index, bindingContext, overrideContext) { + let view = this.viewFactory.create(); + view.bind(bindingContext, overrideContext); + this.viewSlot.insert(index, view); + } + moveView(sourceIndex, targetIndex) { + this.viewSlot.move(sourceIndex, targetIndex); + } + removeAllViews(returnToCache, skipAnimation) { + return this.viewSlot.removeAll(returnToCache, skipAnimation); + } + removeViews(viewsToRemove, returnToCache, skipAnimation) { + return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation); + } + removeView(index, returnToCache, skipAnimation) { + return this.viewSlot.removeAt(index, returnToCache, skipAnimation); + } + updateBindings(view) { + const $view = view; + let j = $view.bindings.length; + while (j--) { + updateOneTimeBinding($view.bindings[j]); + } + j = $view.controllers.length; + while (j--) { + let k = $view.controllers[j].boundProperties.length; + while (k--) { + let binding = $view.controllers[j].boundProperties[k].binding; + updateOneTimeBinding(binding); + } + } + } +}; +__decorate([ + bindable +], Repeat.prototype, "items", void 0); +__decorate([ + bindable +], Repeat.prototype, "local", void 0); +__decorate([ + bindable +], Repeat.prototype, "key", void 0); +__decorate([ + bindable +], Repeat.prototype, "value", void 0); +Repeat = __decorate([ + customAttribute('repeat'), + templateController, + inject(BoundViewFactory, TargetInstruction, ViewSlot, ViewResources, ObserverLocator, RepeatStrategyLocator) +], Repeat); + +const aureliaHideClassName = 'aurelia-hide'; +const aureliaHideClass = `.${aureliaHideClassName} { display:none !important; }`; +function injectAureliaHideStyleAtHead() { + DOM.injectStyles(aureliaHideClass); +} +function injectAureliaHideStyleAtBoundary(domBoundary) { + if (FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) { + domBoundary.hasAureliaHideStyle = true; + DOM.injectStyles(aureliaHideClass, domBoundary); + } +} + +let Show = class Show { + constructor(element, animator, domBoundary) { + this.element = element; + this.animator = animator; + this.domBoundary = domBoundary; + } + static inject() { + return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; + } + created() { + injectAureliaHideStyleAtBoundary(this.domBoundary); + } + valueChanged(newValue) { + let element = this.element; + let animator = this.animator; + if (newValue) { + animator.removeClass(element, aureliaHideClassName); + } + else { + animator.addClass(element, aureliaHideClassName); + } + } + bind(bindingContext) { + this.valueChanged(this.value); + } +}; +Show = __decorate([ + customAttribute('show') +], Show); + +let Hide = class Hide { + constructor(element, animator, domBoundary) { + this.element = element; + this.animator = animator; + this.domBoundary = domBoundary; + } + static inject() { + return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; + } + created() { + injectAureliaHideStyleAtBoundary(this.domBoundary); + } + valueChanged(newValue) { + if (newValue) { + this.animator.addClass(this.element, aureliaHideClassName); + } + else { + this.animator.removeClass(this.element, aureliaHideClassName); + } + } + bind(bindingContext) { + this.valueChanged(this.value); + } + value(value) { + throw new Error('Method not implemented.'); + } +}; +Hide = __decorate([ + customAttribute('hide') +], Hide); + +const SCRIPT_REGEX = /)<[^<]*)*<\/script>/gi; +let needsToWarn = true; +class HTMLSanitizer { + sanitize(input) { + if (needsToWarn) { + needsToWarn = false; + getLogger('html-sanitizer') + .warn(`CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks, +and should not be relied on for sanitizing input from unknown sources. +Please see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html.`); + } + return input.replace(SCRIPT_REGEX, ''); + } +} + +let SanitizeHTMLValueConverter = class SanitizeHTMLValueConverter { + constructor(sanitizer) { + this.sanitizer = sanitizer; + } + toView(untrustedMarkup) { + if (untrustedMarkup === null || untrustedMarkup === undefined) { + return null; + } + return this.sanitizer.sanitize(untrustedMarkup); + } +}; +SanitizeHTMLValueConverter = __decorate([ + valueConverter('sanitizeHTML'), + inject(HTMLSanitizer) +], SanitizeHTMLValueConverter); + +let Replaceable = class Replaceable { + constructor(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.view = null; + } + bind(bindingContext, overrideContext) { + if (this.view === null) { + this.view = this.viewFactory.create(); + this.viewSlot.add(this.view); + } + this.view.bind(bindingContext, overrideContext); + } + unbind() { + this.view.unbind(); + } +}; +Replaceable = __decorate([ + customAttribute('replaceable'), + templateController, + inject(BoundViewFactory, ViewSlot) +], Replaceable); + +let Focus = class Focus { + constructor(element, taskQueue) { + this.element = element; + this.taskQueue = taskQueue; + this.isAttached = false; + this.needsApply = false; + } + static inject() { + return [DOM.Element, TaskQueue]; + } + valueChanged(newValue) { + if (this.isAttached) { + this._apply(); + } + else { + this.needsApply = true; + } + } + _apply() { + if (this.value) { + this.taskQueue.queueMicroTask(() => { + if (this.value) { + this.element.focus(); + } + }); + } + else { + this.element.blur(); + } + } + attached() { + this.isAttached = true; + if (this.needsApply) { + this.needsApply = false; + this._apply(); + } + this.element.addEventListener('focus', this); + this.element.addEventListener('blur', this); + } + detached() { + this.isAttached = false; + this.element.removeEventListener('focus', this); + this.element.removeEventListener('blur', this); + } + handleEvent(e) { + if (e.type === 'focus') { + this.value = true; + } + else if (DOM.activeElement !== this.element) { + this.value = false; + } + } +}; +Focus = __decorate([ + customAttribute('focus', bindingMode.twoWay) +], Focus); + +let cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi; +function fixupCSSUrls(address, css) { + if (typeof css !== 'string') { + throw new Error(`Failed loading required CSS file: ${address}`); + } + return css.replace(cssUrlMatcher, (match, p1) => { + let quote = p1.charAt(0); + if (quote === '\'' || quote === '"') { + p1 = p1.substr(1, p1.length - 2); + } + return 'url(\'' + relativeToFile(p1, address) + '\')'; + }); +} +class CSSResource { + constructor(address) { + this.address = address; + this._scoped = null; + this._global = false; + this._alreadyGloballyInjected = false; + } + initialize(container, Target) { + this._scoped = new Target(this); + } + register(registry, name) { + if (name === 'scoped') { + registry.registerViewEngineHooks(this._scoped); + } + else { + this._global = true; + } + } + load(container) { + return container.get(Loader) + .loadText(this.address) + .catch(err => null) + .then(text => { + text = fixupCSSUrls(this.address, text); + this._scoped.css = text; + if (this._global) { + this._alreadyGloballyInjected = true; + DOM.injectStyles(text); + } + }); + } +} +class CSSViewEngineHooks { + constructor(owner) { + this.owner = owner; + this.css = null; + } + beforeCompile(content, resources, instruction) { + if (instruction.targetShadowDOM) { + DOM.injectStyles(this.css, content, true); + } + else if (FEATURE.scopedCSS) { + let styleNode = DOM.injectStyles(this.css, content, true); + styleNode.setAttribute('scoped', 'scoped'); + } + else if (this._global && !this.owner._alreadyGloballyInjected) { + DOM.injectStyles(this.css); + this.owner._alreadyGloballyInjected = true; + } + } +} +function _createCSSResource(address) { + let ViewCSS = class ViewCSS extends CSSViewEngineHooks { + }; + ViewCSS = __decorate([ + resource(new CSSResource(address)) + ], ViewCSS); + return ViewCSS; +} + +let AttrBindingBehavior = class AttrBindingBehavior { + bind(binding, source) { + binding.targetObserver = new DataAttributeObserver(binding.target, binding.targetProperty); + } + unbind(binding, source) { + } +}; +AttrBindingBehavior = __decorate([ + bindingBehavior('attr') +], AttrBindingBehavior); + +let modeBindingBehavior = { + bind(binding, source, lookupFunctions) { + binding.originalMode = binding.mode; + binding.mode = this.mode; + }, + unbind(binding, source) { + binding.mode = binding.originalMode; + binding.originalMode = null; + } +}; +let OneTimeBindingBehavior = class OneTimeBindingBehavior { + constructor() { + this.mode = bindingMode.oneTime; + } +}; +OneTimeBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('oneTime') +], OneTimeBindingBehavior); +let OneWayBindingBehavior = class OneWayBindingBehavior { + constructor() { + this.mode = bindingMode.toView; + } +}; +OneWayBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('oneWay') +], OneWayBindingBehavior); +let ToViewBindingBehavior = class ToViewBindingBehavior { + constructor() { + this.mode = bindingMode.toView; + } +}; +ToViewBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('toView') +], ToViewBindingBehavior); +let FromViewBindingBehavior = class FromViewBindingBehavior { + constructor() { + this.mode = bindingMode.fromView; + } +}; +FromViewBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('fromView') +], FromViewBindingBehavior); +let TwoWayBindingBehavior = class TwoWayBindingBehavior { + constructor() { + this.mode = bindingMode.twoWay; + } +}; +TwoWayBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('twoWay') +], TwoWayBindingBehavior); + +function throttle(newValue) { + let state = this.throttleState; + let elapsed = +new Date() - state.last; + if (elapsed >= state.delay) { + clearTimeout(state.timeoutId); + state.timeoutId = null; + state.last = +new Date(); + this.throttledMethod(newValue); + return; + } + state.newValue = newValue; + if (state.timeoutId === null) { + state.timeoutId = setTimeout(() => { + state.timeoutId = null; + state.last = +new Date(); + this.throttledMethod(state.newValue); + }, state.delay - elapsed); + } +} +let ThrottleBindingBehavior = class ThrottleBindingBehavior { + bind(binding, source, delay = 200) { + let methodToThrottle = 'updateTarget'; + if (binding.callSource) { + methodToThrottle = 'callSource'; + } + else if (binding.updateSource && binding.mode === bindingMode.twoWay) { + methodToThrottle = 'updateSource'; + } + binding.throttledMethod = binding[methodToThrottle]; + binding.throttledMethod.originalName = methodToThrottle; + binding[methodToThrottle] = throttle; + binding.throttleState = { + delay: delay, + last: 0, + timeoutId: null + }; + } + unbind(binding, source) { + let methodToRestore = binding.throttledMethod.originalName; + binding[methodToRestore] = binding.throttledMethod; + binding.throttledMethod = null; + clearTimeout(binding.throttleState.timeoutId); + binding.throttleState = null; + } +}; +ThrottleBindingBehavior = __decorate([ + bindingBehavior('throttle') +], ThrottleBindingBehavior); + +const unset = {}; +function debounceCallSource(event) { + const state = this.debounceState; + clearTimeout(state.timeoutId); + state.timeoutId = setTimeout(() => this.debouncedMethod(event), state.delay); +} +function debounceCall(context, newValue, oldValue) { + const state = this.debounceState; + clearTimeout(state.timeoutId); + if (context !== state.callContextToDebounce) { + state.oldValue = unset; + this.debouncedMethod(context, newValue, oldValue); + return; + } + if (state.oldValue === unset) { + state.oldValue = oldValue; + } + state.timeoutId = setTimeout(() => { + const _oldValue = state.oldValue; + state.oldValue = unset; + this.debouncedMethod(context, newValue, _oldValue); + }, state.delay); +} +let DebounceBindingBehavior = class DebounceBindingBehavior { + bind(binding, source, delay = 200) { + const isCallSource = binding.callSource !== undefined; + const methodToDebounce = isCallSource ? 'callSource' : 'call'; + const debouncer = isCallSource ? debounceCallSource : debounceCall; + const mode = binding.mode; + const callContextToDebounce = mode === bindingMode.twoWay || mode === bindingMode.fromView ? targetContext : sourceContext; + binding.debouncedMethod = binding[methodToDebounce]; + binding.debouncedMethod.originalName = methodToDebounce; + binding[methodToDebounce] = debouncer; + binding.debounceState = { + callContextToDebounce, + delay, + timeoutId: 0, + oldValue: unset + }; + } + unbind(binding, source) { + const methodToRestore = binding.debouncedMethod.originalName; + binding[methodToRestore] = binding.debouncedMethod; + binding.debouncedMethod = null; + clearTimeout(binding.debounceState.timeoutId); + binding.debounceState = null; + } +}; +DebounceBindingBehavior = __decorate([ + bindingBehavior('debounce') +], DebounceBindingBehavior); + +function findOriginalEventTarget(event) { + return (event.path && event.path[0]) || (event.deepPath && event.deepPath[0]) || event.target; +} +function handleSelfEvent(event) { + let target = findOriginalEventTarget(event); + if (this.target !== target) { + return; + } + this.selfEventCallSource(event); +} +let SelfBindingBehavior = class SelfBindingBehavior { + bind(binding, source) { + if (!binding.callSource || !binding.targetEvent) { + throw new Error('Self binding behavior only supports event.'); + } + binding.selfEventCallSource = binding.callSource; + binding.callSource = handleSelfEvent; + } + unbind(binding, source) { + binding.callSource = binding.selfEventCallSource; + binding.selfEventCallSource = null; + } +}; +SelfBindingBehavior = __decorate([ + bindingBehavior('self') +], SelfBindingBehavior); + +class BindingSignaler { + constructor() { + this.signals = {}; + } + signal(name) { + let bindings = this.signals[name]; + if (!bindings) { + return; + } + let i = bindings.length; + while (i--) { + bindings[i].call(sourceContext); + } + } +} + +let SignalBindingBehavior = class SignalBindingBehavior { + constructor(bindingSignaler) { + this.signals = bindingSignaler.signals; + } + static inject() { return [BindingSignaler]; } + bind(binding, source, ...names) { + if (!binding.updateTarget) { + throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.'); + } + let signals = this.signals; + if (names.length === 1) { + let name = names[0]; + let bindings = signals[name] || (signals[name] = []); + bindings.push(binding); + binding.signalName = name; + } + else if (names.length > 1) { + let i = names.length; + while (i--) { + let name = names[i]; + let bindings = signals[name] || (signals[name] = []); + bindings.push(binding); + } + binding.signalName = names; + } + else { + throw new Error('Signal name is required.'); + } + } + unbind(binding, source) { + let signals = this.signals; + let name = binding.signalName; + binding.signalName = null; + if (Array.isArray(name)) { + let names = name; + let i = names.length; + while (i--) { + let n = names[i]; + let bindings = signals[n]; + bindings.splice(bindings.indexOf(binding), 1); + } + } + else { + let bindings = signals[name]; + bindings.splice(bindings.indexOf(binding), 1); + } + } +}; +SignalBindingBehavior = __decorate([ + bindingBehavior('signal') +], SignalBindingBehavior); + +const eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg '; +const notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.'; +let UpdateTriggerBindingBehavior = class UpdateTriggerBindingBehavior { + bind(binding, source, ...events) { + if (events.length === 0) { + throw new Error(eventNamesRequired); + } + if (binding.mode !== bindingMode.twoWay && binding.mode !== bindingMode.fromView) { + throw new Error(notApplicableMessage); + } + let targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty); + if (!targetObserver.handler) { + throw new Error(notApplicableMessage); + } + binding.targetObserver = targetObserver; + targetObserver.originalHandler = binding.targetObserver.handler; + let handler = new EventSubscriber(events); + targetObserver.handler = handler; + } + unbind(binding, source) { + let targetObserver = binding.targetObserver; + targetObserver.handler.dispose(); + targetObserver.handler = targetObserver.originalHandler; + targetObserver.originalHandler = null; + } +}; +UpdateTriggerBindingBehavior = __decorate([ + bindingBehavior('updateTrigger') +], UpdateTriggerBindingBehavior); + +function _createDynamicElement({ name, viewUrl, bindableNames, useShadowDOMmode }) { + let DynamicElement = class DynamicElement { + bind(bindingContext) { + this.$parent = bindingContext; + } + }; + DynamicElement = __decorate([ + customElement(name), + useView(viewUrl) + ], DynamicElement); + for (let i = 0, ii = bindableNames.length; i < ii; ++i) { + bindable(bindableNames[i])(DynamicElement); + } + switch (useShadowDOMmode) { + case 'open': + useShadowDOM({ mode: 'open' })(DynamicElement); + break; + case 'closed': + useShadowDOM({ mode: 'closed' })(DynamicElement); + break; + case '': + useShadowDOM(DynamicElement); + break; + case null: + break; + default: + getLogger('aurelia-html-only-element') + .warn(`Expected 'use-shadow-dom' value to be "close", "open" or "", received ${useShadowDOMmode}`); + break; + } + return DynamicElement; +} + +function getElementName(address) { + return /([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase(); +} +function configure(config) { + const viewEngine = config.container.get(ViewEngine); + const loader = config.aurelia.loader; + viewEngine.addResourcePlugin('.html', { + 'fetch': function (viewUrl) { + return loader.loadTemplate(viewUrl).then(registryEntry => { + let bindableNames = registryEntry.template.getAttribute('bindable'); + const useShadowDOMmode = registryEntry.template.getAttribute('use-shadow-dom'); + const name = getElementName(viewUrl); + if (bindableNames) { + bindableNames = bindableNames.split(',').map(x => x.trim()); + registryEntry.template.removeAttribute('bindable'); + } + else { + bindableNames = []; + } + return { [name]: _createDynamicElement({ name, viewUrl, bindableNames, useShadowDOMmode }) }; + }); + } + }); +} + +function configure$1(config) { + injectAureliaHideStyleAtHead(); + config.globalResources(Compose, If, Else, With, Repeat, Show, Hide, Replaceable, Focus, SanitizeHTMLValueConverter, OneTimeBindingBehavior, OneWayBindingBehavior, ToViewBindingBehavior, FromViewBindingBehavior, TwoWayBindingBehavior, ThrottleBindingBehavior, DebounceBindingBehavior, SelfBindingBehavior, SignalBindingBehavior, UpdateTriggerBindingBehavior, AttrBindingBehavior); + configure(config); + let viewEngine = config.container.get(ViewEngine); + let styleResourcePlugin = { + fetch(address) { + return { [address]: _createCSSResource(address) }; + } + }; + ['.css', '.less', '.sass', '.scss', '.styl'].forEach(ext => viewEngine.addResourcePlugin(ext, styleResourcePlugin)); +} + +export { AbstractRepeater, ArrayRepeatStrategy, AttrBindingBehavior, BindingSignaler, Compose, DebounceBindingBehavior, Else, Focus, FromViewBindingBehavior, HTMLSanitizer, Hide, If, MapRepeatStrategy, NullRepeatStrategy, NumberRepeatStrategy, OneTimeBindingBehavior, OneWayBindingBehavior, Repeat, RepeatStrategyLocator, Replaceable, SanitizeHTMLValueConverter, SelfBindingBehavior, SetRepeatStrategy, Show, SignalBindingBehavior, ThrottleBindingBehavior, ToViewBindingBehavior, TwoWayBindingBehavior, UpdateTriggerBindingBehavior, With, configure$1 as configure, createFullOverrideContext, getItemsSourceExpression, isOneTime, unwrapExpression, updateOneTimeBinding, updateOverrideContext, viewsRequireLifecycle }; +//# sourceMappingURL=aurelia-templating-resources.js.map diff --git a/dist/es2017/aurelia-templating-resources.js.map b/dist/es2017/aurelia-templating-resources.js.map new file mode 100644 index 0000000..b7b5f2f --- /dev/null +++ b/dist/es2017/aurelia-templating-resources.js.map @@ -0,0 +1 @@ +{"version":3,"file":"aurelia-templating-resources.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/native-modules/abstract-repeater.js b/dist/native-modules/abstract-repeater.js deleted file mode 100644 index 99e6bdf..0000000 --- a/dist/native-modules/abstract-repeater.js +++ /dev/null @@ -1,58 +0,0 @@ - - -export var AbstractRepeater = function () { - function AbstractRepeater(options) { - - - Object.assign(this, { - local: 'items', - viewsRequireLifecycle: true - }, options); - } - - AbstractRepeater.prototype.viewCount = function viewCount() { - throw new Error('subclass must implement `viewCount`'); - }; - - AbstractRepeater.prototype.views = function views() { - throw new Error('subclass must implement `views`'); - }; - - AbstractRepeater.prototype.view = function view(index) { - throw new Error('subclass must implement `view`'); - }; - - AbstractRepeater.prototype.matcher = function matcher() { - throw new Error('subclass must implement `matcher`'); - }; - - AbstractRepeater.prototype.addView = function addView(bindingContext, overrideContext) { - throw new Error('subclass must implement `addView`'); - }; - - AbstractRepeater.prototype.insertView = function insertView(index, bindingContext, overrideContext) { - throw new Error('subclass must implement `insertView`'); - }; - - AbstractRepeater.prototype.moveView = function moveView(sourceIndex, targetIndex) { - throw new Error('subclass must implement `moveView`'); - }; - - AbstractRepeater.prototype.removeAllViews = function removeAllViews(returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeAllViews`'); - }; - - AbstractRepeater.prototype.removeViews = function removeViews(viewsToRemove, returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeView`'); - }; - - AbstractRepeater.prototype.removeView = function removeView(index, returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeView`'); - }; - - AbstractRepeater.prototype.updateBindings = function updateBindings(view) { - throw new Error('subclass must implement `updateBindings`'); - }; - - return AbstractRepeater; -}(); \ No newline at end of file diff --git a/dist/native-modules/analyze-view-factory.js b/dist/native-modules/analyze-view-factory.js deleted file mode 100644 index 7fc1a54..0000000 --- a/dist/native-modules/analyze-view-factory.js +++ /dev/null @@ -1,50 +0,0 @@ - -export var lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with']; - -function behaviorRequiresLifecycle(instruction) { - var t = instruction.type; - var name = t.elementName !== null ? t.elementName : t.attributeName; - return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind) || t.viewFactory && viewsRequireLifecycle(t.viewFactory) || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); -} - -function targetRequiresLifecycle(instruction) { - var behaviors = instruction.behaviorInstructions; - if (behaviors) { - var i = behaviors.length; - while (i--) { - if (behaviorRequiresLifecycle(behaviors[i])) { - return true; - } - } - } - - return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); -} - -export function viewsRequireLifecycle(viewFactory) { - if ('_viewsRequireLifecycle' in viewFactory) { - return viewFactory._viewsRequireLifecycle; - } - - viewFactory._viewsRequireLifecycle = false; - - if (viewFactory.viewFactory) { - viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory); - return viewFactory._viewsRequireLifecycle; - } - - if (viewFactory.template.querySelector('.au-animate')) { - viewFactory._viewsRequireLifecycle = true; - return true; - } - - for (var id in viewFactory.instructions) { - if (targetRequiresLifecycle(viewFactory.instructions[id])) { - viewFactory._viewsRequireLifecycle = true; - return true; - } - } - - viewFactory._viewsRequireLifecycle = false; - return false; -} \ No newline at end of file diff --git a/dist/native-modules/array-repeat-strategy.js b/dist/native-modules/array-repeat-strategy.js deleted file mode 100644 index c3c3cb1..0000000 --- a/dist/native-modules/array-repeat-strategy.js +++ /dev/null @@ -1,233 +0,0 @@ - - -import { createFullOverrideContext, updateOverrideContexts, updateOverrideContext, indexOf } from './repeat-utilities'; -import { mergeSplice } from 'aurelia-binding'; - -export var ArrayRepeatStrategy = function () { - function ArrayRepeatStrategy() { - - } - - ArrayRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getArrayObserver(items); - }; - - ArrayRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this = this; - - var itemsLength = items.length; - - if (!items || itemsLength === 0) { - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - return; - } - - var children = repeat.views(); - var viewsLength = children.length; - - if (viewsLength === 0) { - this._standardProcessInstanceChanged(repeat, items); - return; - } - - if (repeat.viewsRequireLifecycle) { - var childrenSnapshot = children.slice(0); - var itemNameInBindingContext = repeat.local; - var matcher = repeat.matcher(); - - var itemsPreviouslyInViews = []; - var viewsToRemove = []; - - for (var index = 0; index < viewsLength; index++) { - var view = childrenSnapshot[index]; - var oldItem = view.bindingContext[itemNameInBindingContext]; - - if (indexOf(items, oldItem, matcher) === -1) { - viewsToRemove.push(view); - } else { - itemsPreviouslyInViews.push(oldItem); - } - } - - var updateViews = void 0; - var removePromise = void 0; - - if (itemsPreviouslyInViews.length > 0) { - removePromise = repeat.removeViews(viewsToRemove, true, !repeat.viewsRequireLifecycle); - updateViews = function updateViews() { - for (var _index = 0; _index < itemsLength; _index++) { - var item = items[_index]; - var indexOfView = indexOf(itemsPreviouslyInViews, item, matcher, _index); - var _view = void 0; - - if (indexOfView === -1) { - var overrideContext = createFullOverrideContext(repeat, items[_index], _index, itemsLength); - repeat.insertView(_index, overrideContext.bindingContext, overrideContext); - - itemsPreviouslyInViews.splice(_index, 0, undefined); - } else if (indexOfView === _index) { - _view = children[indexOfView]; - itemsPreviouslyInViews[indexOfView] = undefined; - } else { - _view = children[indexOfView]; - repeat.moveView(indexOfView, _index); - itemsPreviouslyInViews.splice(indexOfView, 1); - itemsPreviouslyInViews.splice(_index, 0, undefined); - } - - if (_view) { - updateOverrideContext(_view.overrideContext, _index, itemsLength); - } - } - - _this._inPlaceProcessItems(repeat, items); - }; - } else { - removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - updateViews = function updateViews() { - return _this._standardProcessInstanceChanged(repeat, items); - }; - } - - if (removePromise instanceof Promise) { - removePromise.then(updateViews); - } else { - updateViews(); - } - } else { - this._inPlaceProcessItems(repeat, items); - } - }; - - ArrayRepeatStrategy.prototype._standardProcessInstanceChanged = function _standardProcessInstanceChanged(repeat, items) { - for (var i = 0, ii = items.length; i < ii; i++) { - var overrideContext = createFullOverrideContext(repeat, items[i], i, ii); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - }; - - ArrayRepeatStrategy.prototype._inPlaceProcessItems = function _inPlaceProcessItems(repeat, items) { - var itemsLength = items.length; - var viewsLength = repeat.viewCount(); - - while (viewsLength > itemsLength) { - viewsLength--; - repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle); - } - - var local = repeat.local; - - for (var i = 0; i < viewsLength; i++) { - var view = repeat.view(i); - var last = i === itemsLength - 1; - var middle = i !== 0 && !last; - - if (view.bindingContext[local] === items[i] && view.overrideContext.$middle === middle && view.overrideContext.$last === last) { - continue; - } - - view.bindingContext[local] = items[i]; - view.overrideContext.$middle = middle; - view.overrideContext.$last = last; - repeat.updateBindings(view); - } - - for (var _i = viewsLength; _i < itemsLength; _i++) { - var overrideContext = createFullOverrideContext(repeat, items[_i], _i, itemsLength); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - }; - - ArrayRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, array, splices) { - var _this2 = this; - - if (repeat.__queuedSplices) { - for (var i = 0, ii = splices.length; i < ii; ++i) { - var _splices$i = splices[i], - index = _splices$i.index, - removed = _splices$i.removed, - addedCount = _splices$i.addedCount; - - mergeSplice(repeat.__queuedSplices, index, removed, addedCount); - } - - repeat.__array = array.slice(0); - return; - } - - var maybePromise = this._runSplices(repeat, array.slice(0), splices); - if (maybePromise instanceof Promise) { - var queuedSplices = repeat.__queuedSplices = []; - - var runQueuedSplices = function runQueuedSplices() { - if (!queuedSplices.length) { - repeat.__queuedSplices = undefined; - repeat.__array = undefined; - return; - } - - var nextPromise = _this2._runSplices(repeat, repeat.__array, queuedSplices) || Promise.resolve(); - queuedSplices = repeat.__queuedSplices = []; - nextPromise.then(runQueuedSplices); - }; - - maybePromise.then(runQueuedSplices); - } - }; - - ArrayRepeatStrategy.prototype._runSplices = function _runSplices(repeat, array, splices) { - var _this3 = this; - - var removeDelta = 0; - var rmPromises = []; - - for (var i = 0, ii = splices.length; i < ii; ++i) { - var splice = splices[i]; - var removed = splice.removed; - - for (var j = 0, jj = removed.length; j < jj; ++j) { - var viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - } - removeDelta -= splice.addedCount; - } - - if (rmPromises.length > 0) { - return Promise.all(rmPromises).then(function () { - var spliceIndexLow = _this3._handleAddedSplices(repeat, array, splices); - updateOverrideContexts(repeat.views(), spliceIndexLow); - }); - } - - var spliceIndexLow = this._handleAddedSplices(repeat, array, splices); - updateOverrideContexts(repeat.views(), spliceIndexLow); - - return undefined; - }; - - ArrayRepeatStrategy.prototype._handleAddedSplices = function _handleAddedSplices(repeat, array, splices) { - var spliceIndex = void 0; - var spliceIndexLow = void 0; - var arrayLength = array.length; - for (var i = 0, ii = splices.length; i < ii; ++i) { - var splice = splices[i]; - var addIndex = spliceIndex = splice.index; - var end = splice.index + splice.addedCount; - - if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) { - spliceIndexLow = spliceIndex; - } - - for (; addIndex < end; ++addIndex) { - var overrideContext = createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength); - repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext); - } - } - - return spliceIndexLow; - }; - - return ArrayRepeatStrategy; -}(); \ No newline at end of file diff --git a/dist/native-modules/attr-binding-behavior.js b/dist/native-modules/attr-binding-behavior.js deleted file mode 100644 index 9c54735..0000000 --- a/dist/native-modules/attr-binding-behavior.js +++ /dev/null @@ -1,19 +0,0 @@ -var _dec, _class; - - - -import { DataAttributeObserver, bindingBehavior } from 'aurelia-binding'; - -export var AttrBindingBehavior = (_dec = bindingBehavior('attr'), _dec(_class = function () { - function AttrBindingBehavior() { - - } - - AttrBindingBehavior.prototype.bind = function bind(binding, source) { - binding.targetObserver = new DataAttributeObserver(binding.target, binding.targetProperty); - }; - - AttrBindingBehavior.prototype.unbind = function unbind(binding, source) {}; - - return AttrBindingBehavior; -}()) || _class); \ No newline at end of file diff --git a/dist/native-modules/aurelia-hide-style.js b/dist/native-modules/aurelia-hide-style.js deleted file mode 100644 index 27e69bd..0000000 --- a/dist/native-modules/aurelia-hide-style.js +++ /dev/null @@ -1,16 +0,0 @@ -import { FEATURE, DOM } from 'aurelia-pal'; - -export var aureliaHideClassName = 'aurelia-hide'; - -var aureliaHideClass = '.' + aureliaHideClassName + ' { display:none !important; }'; - -export function injectAureliaHideStyleAtHead() { - DOM.injectStyles(aureliaHideClass); -} - -export function injectAureliaHideStyleAtBoundary(domBoundary) { - if (FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) { - domBoundary.hasAureliaHideStyle = true; - DOM.injectStyles(aureliaHideClass, domBoundary); - } -} \ No newline at end of file diff --git a/dist/native-modules/aurelia-templating-resources.js b/dist/native-modules/aurelia-templating-resources.js index 1a3c776..ed3580a 100644 --- a/dist/native-modules/aurelia-templating-resources.js +++ b/dist/native-modules/aurelia-templating-resources.js @@ -1,54 +1,1882 @@ -import { Compose } from './compose'; -import { If } from './if'; -import { Else } from './else'; -import { With } from './with'; -import { Repeat } from './repeat'; -import { Show } from './show'; -import { Hide } from './hide'; -import { SanitizeHTMLValueConverter } from './sanitize-html'; -import { Replaceable } from './replaceable'; -import { Focus } from './focus'; -import { ViewEngine } from 'aurelia-templating'; -import { _createCSSResource } from './css-resource'; -import { HTMLSanitizer } from './html-sanitizer'; -import { AttrBindingBehavior } from './attr-binding-behavior'; -import { OneTimeBindingBehavior, OneWayBindingBehavior, TwoWayBindingBehavior, FromViewBindingBehavior, ToViewBindingBehavior } from './binding-mode-behaviors'; -import { ThrottleBindingBehavior } from './throttle-binding-behavior'; -import { DebounceBindingBehavior } from './debounce-binding-behavior'; -import { SelfBindingBehavior } from './self-binding-behavior'; -import { SignalBindingBehavior } from './signal-binding-behavior'; -import { BindingSignaler } from './binding-signaler'; -import { UpdateTriggerBindingBehavior } from './update-trigger-binding-behavior'; -import { AbstractRepeater } from './abstract-repeater'; -import { RepeatStrategyLocator } from './repeat-strategy-locator'; -import { configure as configureHtmlResourcePlugin } from './html-resource-plugin'; -import { NullRepeatStrategy } from './null-repeat-strategy'; -import { ArrayRepeatStrategy } from './array-repeat-strategy'; -import { MapRepeatStrategy } from './map-repeat-strategy'; -import { SetRepeatStrategy } from './set-repeat-strategy'; -import { NumberRepeatStrategy } from './number-repeat-strategy'; -import { createFullOverrideContext, updateOverrideContext, getItemsSourceExpression, isOneTime, updateOneTimeBinding, unwrapExpression } from './repeat-utilities'; -import { viewsRequireLifecycle } from './analyze-view-factory'; -import { injectAureliaHideStyleAtHead } from './aurelia-hide-style'; - -function configure(config) { - injectAureliaHideStyleAtHead(); - - config.globalResources(Compose, If, Else, With, Repeat, Show, Hide, Replaceable, Focus, SanitizeHTMLValueConverter, OneTimeBindingBehavior, OneWayBindingBehavior, ToViewBindingBehavior, FromViewBindingBehavior, TwoWayBindingBehavior, ThrottleBindingBehavior, DebounceBindingBehavior, SelfBindingBehavior, SignalBindingBehavior, UpdateTriggerBindingBehavior, AttrBindingBehavior); - - configureHtmlResourcePlugin(config); - - var viewEngine = config.container.get(ViewEngine); - var styleResourcePlugin = { - fetch: function fetch(address) { - var _ref; - - return _ref = {}, _ref[address] = _createCSSResource(address), _ref; - } - }; - ['.css', '.less', '.sass', '.scss', '.styl'].forEach(function (ext) { - return viewEngine.addResourcePlugin(ext, styleResourcePlugin); - }); -} - -export { Compose, If, Else, With, Repeat, Show, Hide, HTMLSanitizer, SanitizeHTMLValueConverter, Replaceable, Focus, configure, AttrBindingBehavior, OneTimeBindingBehavior, OneWayBindingBehavior, ToViewBindingBehavior, FromViewBindingBehavior, TwoWayBindingBehavior, ThrottleBindingBehavior, DebounceBindingBehavior, SelfBindingBehavior, SignalBindingBehavior, BindingSignaler, UpdateTriggerBindingBehavior, AbstractRepeater, RepeatStrategyLocator, NullRepeatStrategy, ArrayRepeatStrategy, MapRepeatStrategy, SetRepeatStrategy, NumberRepeatStrategy, createFullOverrideContext, updateOverrideContext, getItemsSourceExpression, isOneTime, updateOneTimeBinding, unwrapExpression, viewsRequireLifecycle }; \ No newline at end of file +import { Container, inject, Optional } from 'aurelia-dependency-injection'; +import { DOM, FEATURE } from 'aurelia-pal'; +import { TaskQueue } from 'aurelia-task-queue'; +import { CompositionEngine, ViewSlot, ViewResources, bindable, noView, customElement, customAttribute, templateController, BoundViewFactory, TargetInstruction, Animator, resource, useView, useShadowDOM, ViewEngine } from 'aurelia-templating'; +import { createOverrideContext, bindingMode, BindingBehavior, ValueConverter, sourceContext, mergeSplice, ObserverLocator, valueConverter, DataAttributeObserver, bindingBehavior, targetContext, EventSubscriber } from 'aurelia-binding'; +import { getLogger } from 'aurelia-logging'; +import { Loader } from 'aurelia-loader'; +import { relativeToFile } from 'aurelia-path'; +import { mixin } from 'aurelia-metadata'; + +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ +/* global Reflect, Promise */ + +var extendStatics = function(d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); +}; + +function __extends(d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +} + +function __decorate(decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +} + +var Compose = (function () { + function Compose(element, container, compositionEngine, viewSlot, viewResources, taskQueue) { + this.element = element; + this.container = container; + this.compositionEngine = compositionEngine; + this.viewSlot = viewSlot; + this.viewResources = viewResources; + this.taskQueue = taskQueue; + this.currentController = null; + this.currentViewModel = null; + this.changes = Object.create(null); + } + Compose.inject = function () { + return [DOM.Element, Container, CompositionEngine, ViewSlot, ViewResources, TaskQueue]; + }; + Compose.prototype.created = function (owningView) { + this.owningView = owningView; + }; + Compose.prototype.bind = function (bindingContext, overrideContext) { + this.bindingContext = bindingContext; + this.overrideContext = overrideContext; + var changes = this.changes; + changes.view = this.view; + changes.viewModel = this.viewModel; + changes.model = this.model; + if (!this.pendingTask) { + processChanges(this); + } + }; + Compose.prototype.unbind = function () { + this.changes = Object.create(null); + this.bindingContext = null; + this.overrideContext = null; + var returnToCache = true; + var skipAnimation = true; + this.viewSlot.removeAll(returnToCache, skipAnimation); + }; + Compose.prototype.modelChanged = function (newValue, oldValue) { + this.changes.model = newValue; + requestUpdate(this); + }; + Compose.prototype.viewChanged = function (newValue, oldValue) { + this.changes.view = newValue; + requestUpdate(this); + }; + Compose.prototype.viewModelChanged = function (newValue, oldValue) { + this.changes.viewModel = newValue; + requestUpdate(this); + }; + __decorate([ + bindable + ], Compose.prototype, "model", void 0); + __decorate([ + bindable + ], Compose.prototype, "view", void 0); + __decorate([ + bindable + ], Compose.prototype, "viewModel", void 0); + __decorate([ + bindable + ], Compose.prototype, "swapOrder", void 0); + Compose = __decorate([ + noView, + customElement('compose') + ], Compose); + return Compose; +}()); +function isEmpty(obj) { + for (var _ in obj) { + return false; + } + return true; +} +function tryActivateViewModel(vm, model) { + if (vm && typeof vm.activate === 'function') { + return Promise.resolve(vm.activate(model)); + } +} +function createInstruction(composer, instruction) { + return Object.assign(instruction, { + bindingContext: composer.bindingContext, + overrideContext: composer.overrideContext, + owningView: composer.owningView, + container: composer.container, + viewSlot: composer.viewSlot, + viewResources: composer.viewResources, + currentController: composer.currentController, + host: composer.element, + swapOrder: composer.swapOrder + }); +} +function processChanges(composer) { + var changes = composer.changes; + composer.changes = Object.create(null); + if (!('view' in changes) && !('viewModel' in changes) && ('model' in changes)) { + composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model); + if (!composer.pendingTask) { + return; + } + } + else { + var instruction = { + view: composer.view, + viewModel: composer.currentViewModel || composer.viewModel, + model: composer.model + }; + instruction = Object.assign(instruction, changes); + instruction = createInstruction(composer, instruction); + composer.pendingTask = composer.compositionEngine.compose(instruction).then(function (controller) { + composer.currentController = controller; + composer.currentViewModel = controller ? controller.viewModel : null; + }); + } + composer.pendingTask = composer.pendingTask + .then(function () { + completeCompositionTask(composer); + }, function (reason) { + completeCompositionTask(composer); + throw reason; + }); +} +function completeCompositionTask(composer) { + composer.pendingTask = null; + if (!isEmpty(composer.changes)) { + processChanges(composer); + } +} +function requestUpdate(composer) { + if (composer.pendingTask || composer.updateRequested) { + return; + } + composer.updateRequested = true; + composer.taskQueue.queueMicroTask(function () { + composer.updateRequested = false; + processChanges(composer); + }); +} + +var IfCore = (function () { + function IfCore(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.view = null; + this.bindingContext = null; + this.overrideContext = null; + this.showing = false; + this.cache = true; + } + IfCore.prototype.bind = function (bindingContext, overrideContext) { + this.bindingContext = bindingContext; + this.overrideContext = overrideContext; + }; + IfCore.prototype.unbind = function () { + if (this.view === null) { + return; + } + this.view.unbind(); + if (!this.viewFactory.isCaching) { + return; + } + if (this.showing) { + this.showing = false; + this.viewSlot.remove(this.view, true, true); + } + else { + this.view.returnToCache(); + } + this.view = null; + }; + IfCore.prototype._show = function () { + if (this.showing) { + if (!this.view.isBound) { + this.view.bind(this.bindingContext, this.overrideContext); + } + return; + } + if (this.view === null) { + this.view = this.viewFactory.create(); + } + if (!this.view.isBound) { + this.view.bind(this.bindingContext, this.overrideContext); + } + this.showing = true; + return this.viewSlot.add(this.view); + }; + IfCore.prototype._hide = function () { + var _this = this; + if (!this.showing) { + return; + } + this.showing = false; + var removed = this.viewSlot.remove(this.view); + if (removed instanceof Promise) { + return removed.then(function () { + _this._unbindView(); + }); + } + this._unbindView(); + }; + IfCore.prototype._unbindView = function () { + var cache = this.cache === 'false' ? false : !!this.cache; + this.view.unbind(); + if (!cache) { + this.view = null; + } + }; + return IfCore; +}()); + +var If = (function (_super) { + __extends(If, _super); + function If() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.cache = true; + return _this; + } + If.prototype.bind = function (bindingContext, overrideContext) { + _super.prototype.bind.call(this, bindingContext, overrideContext); + if (this.condition) { + this._show(); + } + else { + this._hide(); + } + }; + If.prototype.conditionChanged = function (newValue) { + this._update(newValue); + }; + If.prototype._update = function (show) { + var _this = this; + if (this.animating) { + return; + } + var promise; + if (this.elseVm) { + promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm); + } + else { + promise = show ? this._show() : this._hide(); + } + if (promise) { + this.animating = true; + promise.then(function () { + _this.animating = false; + if (_this.condition !== _this.showing) { + _this._update(_this.condition); + } + }); + } + }; + If.prototype._swap = function (remove, add) { + switch (this.swapOrder) { + case 'before': + return Promise.resolve(add._show()).then(function () { return remove._hide(); }); + case 'with': + return Promise.all([remove._hide(), add._show()]); + default: + var promise = remove._hide(); + return promise ? promise.then(function () { return add._show(); }) : add._show(); + } + }; + __decorate([ + bindable({ primaryProperty: true }) + ], If.prototype, "condition", void 0); + __decorate([ + bindable + ], If.prototype, "swapOrder", void 0); + __decorate([ + bindable + ], If.prototype, "cache", void 0); + If = __decorate([ + customAttribute('if'), + templateController, + inject(BoundViewFactory, ViewSlot) + ], If); + return If; +}(IfCore)); + +var Else = (function (_super) { + __extends(Else, _super); + function Else(viewFactory, viewSlot) { + var _this = _super.call(this, viewFactory, viewSlot) || this; + _this._registerInIf(); + return _this; + } + Else.prototype.bind = function (bindingContext, overrideContext) { + _super.prototype.bind.call(this, bindingContext, overrideContext); + if (this.ifVm.condition) { + this._hide(); + } + else { + this._show(); + } + }; + Else.prototype._registerInIf = function () { + var previous = this.viewSlot.anchor.previousSibling; + while (previous && !previous.au) { + previous = previous.previousSibling; + } + if (!previous || !previous.au.if) { + throw new Error("Can't find matching If for Else custom attribute."); + } + this.ifVm = previous.au.if.viewModel; + this.ifVm.elseVm = this; + }; + Else = __decorate([ + customAttribute('else'), + templateController, + inject(BoundViewFactory, ViewSlot) + ], Else); + return Else; +}(IfCore)); + +var With = (function () { + function With(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.parentOverrideContext = null; + this.view = null; + } + With.prototype.bind = function (bindingContext, overrideContext) { + this.parentOverrideContext = overrideContext; + this.valueChanged(this.value); + }; + With.prototype.valueChanged = function (newValue) { + var overrideContext = createOverrideContext(newValue, this.parentOverrideContext); + var view = this.view; + if (!view) { + view = this.view = this.viewFactory.create(); + view.bind(newValue, overrideContext); + this.viewSlot.add(view); + } + else { + view.bind(newValue, overrideContext); + } + }; + With.prototype.unbind = function () { + var view = this.view; + this.parentOverrideContext = null; + if (view) { + view.unbind(); + } + }; + With = __decorate([ + customAttribute('with'), + templateController, + inject(BoundViewFactory, ViewSlot) + ], With); + return With; +}()); + +var oneTime = bindingMode.oneTime; +function updateOverrideContexts(views, startIndex) { + var length = views.length; + if (startIndex > 0) { + startIndex = startIndex - 1; + } + for (; startIndex < length; ++startIndex) { + updateOverrideContext(views[startIndex].overrideContext, startIndex, length); + } +} +function createFullOverrideContext(repeat, data, index, length, key) { + var bindingContext = {}; + var overrideContext = createOverrideContext(bindingContext, repeat.scope.overrideContext); + if (typeof key !== 'undefined') { + bindingContext[repeat.key] = key; + bindingContext[repeat.value] = data; + } + else { + bindingContext[repeat.local] = data; + } + updateOverrideContext(overrideContext, index, length); + return overrideContext; +} +function updateOverrideContext(overrideContext, index, length) { + var first = (index === 0); + var last = (index === length - 1); + var even = index % 2 === 0; + overrideContext.$index = index; + overrideContext.$first = first; + overrideContext.$last = last; + overrideContext.$middle = !(first || last); + overrideContext.$odd = !even; + overrideContext.$even = even; +} +function getItemsSourceExpression(instruction, attrName) { + return instruction.behaviorInstructions + .filter(function (bi) { return bi.originalAttrName === attrName; })[0] + .attributes + .items + .sourceExpression; +} +function unwrapExpression(expression) { + var unwrapped = false; + while (expression instanceof BindingBehavior) { + expression = expression.expression; + } + while (expression instanceof ValueConverter) { + expression = expression.expression; + unwrapped = true; + } + return unwrapped ? expression : null; +} +function isOneTime(expression) { + while (expression instanceof BindingBehavior) { + if (expression.name === 'oneTime') { + return true; + } + expression = expression.expression; + } + return false; +} +function updateOneTimeBinding(binding) { + if (binding.call && binding.mode === oneTime) { + binding.call(sourceContext); + } + else if (binding.updateOneTimeBindings) { + binding.updateOneTimeBindings(); + } +} +function indexOf(array, item, matcher, startIndex) { + if (!matcher) { + return array.indexOf(item); + } + var length = array.length; + for (var index = startIndex || 0; index < length; index++) { + if (matcher(array[index], item)) { + return index; + } + } + return -1; +} + +var ArrayRepeatStrategy = (function () { + function ArrayRepeatStrategy() { + } + ArrayRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + return observerLocator.getArrayObserver(items); + }; + ArrayRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + var _this = this; + var itemsLength = items.length; + if (!items || itemsLength === 0) { + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + return; + } + var children = repeat.views(); + var viewsLength = children.length; + if (viewsLength === 0) { + this._standardProcessInstanceChanged(repeat, items); + return; + } + if (repeat.viewsRequireLifecycle) { + var childrenSnapshot = children.slice(0); + var itemNameInBindingContext = repeat.local; + var matcher_1 = repeat.matcher(); + var itemsPreviouslyInViews_1 = []; + var viewsToRemove = []; + for (var index = 0; index < viewsLength; index++) { + var view = childrenSnapshot[index]; + var oldItem = view.bindingContext[itemNameInBindingContext]; + if (indexOf(items, oldItem, matcher_1) === -1) { + viewsToRemove.push(view); + } + else { + itemsPreviouslyInViews_1.push(oldItem); + } + } + var updateViews = void 0; + var removePromise = void 0; + if (itemsPreviouslyInViews_1.length > 0) { + removePromise = repeat.removeViews(viewsToRemove, true, !repeat.viewsRequireLifecycle); + updateViews = function () { + for (var index = 0; index < itemsLength; index++) { + var item = items[index]; + var indexOfView = indexOf(itemsPreviouslyInViews_1, item, matcher_1, index); + var view = void 0; + if (indexOfView === -1) { + var overrideContext = createFullOverrideContext(repeat, items[index], index, itemsLength); + repeat.insertView(index, overrideContext.bindingContext, overrideContext); + itemsPreviouslyInViews_1.splice(index, 0, undefined); + } + else if (indexOfView === index) { + view = children[indexOfView]; + itemsPreviouslyInViews_1[indexOfView] = undefined; + } + else { + view = children[indexOfView]; + repeat.moveView(indexOfView, index); + itemsPreviouslyInViews_1.splice(indexOfView, 1); + itemsPreviouslyInViews_1.splice(index, 0, undefined); + } + if (view) { + updateOverrideContext(view.overrideContext, index, itemsLength); + } + } + _this._inPlaceProcessItems(repeat, items); + }; + } + else { + removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + updateViews = function () { return _this._standardProcessInstanceChanged(repeat, items); }; + } + if (removePromise instanceof Promise) { + removePromise.then(updateViews); + } + else { + updateViews(); + } + } + else { + this._inPlaceProcessItems(repeat, items); + } + }; + ArrayRepeatStrategy.prototype._standardProcessInstanceChanged = function (repeat, items) { + for (var i = 0, ii = items.length; i < ii; i++) { + var overrideContext = createFullOverrideContext(repeat, items[i], i, ii); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + }; + ArrayRepeatStrategy.prototype._inPlaceProcessItems = function (repeat, items) { + var itemsLength = items.length; + var viewsLength = repeat.viewCount(); + while (viewsLength > itemsLength) { + viewsLength--; + repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle); + } + var local = repeat.local; + for (var i = 0; i < viewsLength; i++) { + var view = repeat.view(i); + var last = i === itemsLength - 1; + var middle = i !== 0 && !last; + var bindingContext = view.bindingContext; + var overrideContext = view.overrideContext; + if (bindingContext[local] === items[i] + && overrideContext.$middle === middle + && overrideContext.$last === last) { + continue; + } + bindingContext[local] = items[i]; + overrideContext.$middle = middle; + overrideContext.$last = last; + repeat.updateBindings(view); + } + for (var i = viewsLength; i < itemsLength; i++) { + var overrideContext = createFullOverrideContext(repeat, items[i], i, itemsLength); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + }; + ArrayRepeatStrategy.prototype.instanceMutated = function (repeat, array, splices) { + var _this = this; + if (repeat.__queuedSplices) { + for (var i = 0, ii = splices.length; i < ii; ++i) { + var _a = splices[i], index = _a.index, removed = _a.removed, addedCount = _a.addedCount; + mergeSplice(repeat.__queuedSplices, index, removed, addedCount); + } + repeat.__array = array.slice(0); + return; + } + var maybePromise = this._runSplices(repeat, array.slice(0), splices); + if (maybePromise instanceof Promise) { + var queuedSplices_1 = repeat.__queuedSplices = []; + var runQueuedSplices_1 = function () { + if (!queuedSplices_1.length) { + repeat.__queuedSplices = undefined; + repeat.__array = undefined; + return; + } + var nextPromise = _this._runSplices(repeat, repeat.__array, queuedSplices_1) || Promise.resolve(); + queuedSplices_1 = repeat.__queuedSplices = []; + nextPromise.then(runQueuedSplices_1); + }; + maybePromise.then(runQueuedSplices_1); + } + }; + ArrayRepeatStrategy.prototype._runSplices = function (repeat, array, splices) { + var _this = this; + var removeDelta = 0; + var rmPromises = []; + for (var i = 0, ii = splices.length; i < ii; ++i) { + var splice = splices[i]; + var removed = splice.removed; + for (var j = 0, jj = removed.length; j < jj; ++j) { + var viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + } + removeDelta -= splice.addedCount; + } + if (rmPromises.length > 0) { + return Promise.all(rmPromises).then(function () { + var spliceIndexLow = _this._handleAddedSplices(repeat, array, splices); + updateOverrideContexts(repeat.views(), spliceIndexLow); + }); + } + var spliceIndexLow = this._handleAddedSplices(repeat, array, splices); + updateOverrideContexts(repeat.views(), spliceIndexLow); + return undefined; + }; + ArrayRepeatStrategy.prototype._handleAddedSplices = function (repeat, array, splices) { + var spliceIndex; + var spliceIndexLow; + var arrayLength = array.length; + for (var i = 0, ii = splices.length; i < ii; ++i) { + var splice = splices[i]; + var addIndex = spliceIndex = splice.index; + var end = splice.index + splice.addedCount; + if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) { + spliceIndexLow = spliceIndex; + } + for (; addIndex < end; ++addIndex) { + var overrideContext = createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength); + repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext); + } + } + return spliceIndexLow; + }; + return ArrayRepeatStrategy; +}()); + +var MapRepeatStrategy = (function () { + function MapRepeatStrategy() { + } + MapRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + return observerLocator.getMapObserver(items); + }; + MapRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + var _this = this; + var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(function () { return _this._standardProcessItems(repeat, items); }); + return; + } + this._standardProcessItems(repeat, items); + }; + MapRepeatStrategy.prototype._standardProcessItems = function (repeat, items) { + var index = 0; + var overrideContext; + items.forEach(function (value, key) { + overrideContext = createFullOverrideContext(repeat, value, index, items.size, key); + repeat.addView(overrideContext.bindingContext, overrideContext); + ++index; + }); + }; + MapRepeatStrategy.prototype.instanceMutated = function (repeat, map, records) { + var key; + var i; + var ii; + var overrideContext; + var removeIndex; + var addIndex; + var record; + var rmPromises = []; + var viewOrPromise; + for (i = 0, ii = records.length; i < ii; ++i) { + record = records[i]; + key = record.key; + switch (record.type) { + case 'update': + removeIndex = this._getViewIndexByKey(repeat, key); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + overrideContext = createFullOverrideContext(repeat, map.get(key), removeIndex, map.size, key); + repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext); + break; + case 'add': + addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1; + overrideContext = createFullOverrideContext(repeat, map.get(key), addIndex, map.size, key); + repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext); + break; + case 'delete': + if (record.oldValue === undefined) { + return; + } + removeIndex = this._getViewIndexByKey(repeat, key); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + break; + case 'clear': + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + break; + default: + continue; + } + } + if (rmPromises.length > 0) { + Promise.all(rmPromises).then(function () { + updateOverrideContexts(repeat.views(), 0); + }); + } + else { + updateOverrideContexts(repeat.views(), 0); + } + }; + MapRepeatStrategy.prototype._getViewIndexByKey = function (repeat, key) { + var i; + var ii; + var child; + for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { + child = repeat.view(i); + if (child.bindingContext[repeat.key] === key) { + return i; + } + } + return undefined; + }; + return MapRepeatStrategy; +}()); + +var NullRepeatStrategy = (function () { + function NullRepeatStrategy() { + } + NullRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + repeat.removeAllViews(true); + }; + NullRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + }; + return NullRepeatStrategy; +}()); + +var NumberRepeatStrategy = (function () { + function NumberRepeatStrategy() { + } + NumberRepeatStrategy.prototype.getCollectionObserver = function () { + return null; + }; + NumberRepeatStrategy.prototype.instanceChanged = function (repeat, value) { + var _this = this; + var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(function () { return _this._standardProcessItems(repeat, value); }); + return; + } + this._standardProcessItems(repeat, value); + }; + NumberRepeatStrategy.prototype._standardProcessItems = function (repeat, value) { + var childrenLength = repeat.viewCount(); + var i; + var ii; + var overrideContext; + var viewsToRemove; + value = Math.floor(value); + viewsToRemove = childrenLength - value; + if (viewsToRemove > 0) { + if (viewsToRemove > childrenLength) { + viewsToRemove = childrenLength; + } + for (i = 0, ii = viewsToRemove; i < ii; ++i) { + repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle); + } + return; + } + for (i = childrenLength, ii = value; i < ii; ++i) { + overrideContext = createFullOverrideContext(repeat, i, i, ii); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + updateOverrideContexts(repeat.views(), 0); + }; + return NumberRepeatStrategy; +}()); + +var SetRepeatStrategy = (function () { + function SetRepeatStrategy() { + } + SetRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + return observerLocator.getSetObserver(items); + }; + SetRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + var _this = this; + var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(function () { return _this._standardProcessItems(repeat, items); }); + return; + } + this._standardProcessItems(repeat, items); + }; + SetRepeatStrategy.prototype._standardProcessItems = function (repeat, items) { + var index = 0; + var overrideContext; + items.forEach(function (value) { + overrideContext = createFullOverrideContext(repeat, value, index, items.size); + repeat.addView(overrideContext.bindingContext, overrideContext); + ++index; + }); + }; + SetRepeatStrategy.prototype.instanceMutated = function (repeat, set, records) { + var value; + var i; + var ii; + var overrideContext; + var removeIndex; + var record; + var rmPromises = []; + var viewOrPromise; + for (i = 0, ii = records.length; i < ii; ++i) { + record = records[i]; + value = record.value; + switch (record.type) { + case 'add': + var size = Math.max(set.size - 1, 0); + overrideContext = createFullOverrideContext(repeat, value, size, set.size); + repeat.insertView(size, overrideContext.bindingContext, overrideContext); + break; + case 'delete': + removeIndex = this._getViewIndexByValue(repeat, value); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + break; + case 'clear': + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + break; + default: + continue; + } + } + if (rmPromises.length > 0) { + Promise.all(rmPromises).then(function () { + updateOverrideContexts(repeat.views(), 0); + }); + } + else { + updateOverrideContexts(repeat.views(), 0); + } + }; + SetRepeatStrategy.prototype._getViewIndexByValue = function (repeat, value) { + var i; + var ii; + var child; + for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { + child = repeat.view(i); + if (child.bindingContext[repeat.local] === value) { + return i; + } + } + return undefined; + }; + return SetRepeatStrategy; +}()); + +var RepeatStrategyLocator = (function () { + function RepeatStrategyLocator() { + this.matchers = []; + this.strategies = []; + this.addStrategy(function (items) { return items === null || items === undefined; }, new NullRepeatStrategy()); + this.addStrategy(function (items) { return items instanceof Array; }, new ArrayRepeatStrategy()); + this.addStrategy(function (items) { return items instanceof Map; }, new MapRepeatStrategy()); + this.addStrategy(function (items) { return items instanceof Set; }, new SetRepeatStrategy()); + this.addStrategy(function (items) { return typeof items === 'number'; }, new NumberRepeatStrategy()); + } + RepeatStrategyLocator.prototype.addStrategy = function (matcher, strategy) { + this.matchers.push(matcher); + this.strategies.push(strategy); + }; + RepeatStrategyLocator.prototype.getStrategy = function (items) { + var matchers = this.matchers; + for (var i = 0, ii = matchers.length; i < ii; ++i) { + if (matchers[i](items)) { + return this.strategies[i]; + } + } + return null; + }; + return RepeatStrategyLocator; +}()); + +var lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with']; +function behaviorRequiresLifecycle(instruction) { + var t = instruction.type; + var name = t.elementName !== null ? t.elementName : t.attributeName; + return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind) + || t.viewFactory && viewsRequireLifecycle(t.viewFactory) + || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); +} +function targetRequiresLifecycle(instruction) { + var behaviors = instruction.behaviorInstructions; + if (behaviors) { + var i = behaviors.length; + while (i--) { + if (behaviorRequiresLifecycle(behaviors[i])) { + return true; + } + } + } + return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); +} +function viewsRequireLifecycle(viewFactory) { + if ('_viewsRequireLifecycle' in viewFactory) { + return viewFactory._viewsRequireLifecycle; + } + viewFactory._viewsRequireLifecycle = false; + if (viewFactory.viewFactory) { + viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory); + return viewFactory._viewsRequireLifecycle; + } + if (viewFactory.template.querySelector('.au-animate')) { + viewFactory._viewsRequireLifecycle = true; + return true; + } + for (var id in viewFactory.instructions) { + if (targetRequiresLifecycle(viewFactory.instructions[id])) { + viewFactory._viewsRequireLifecycle = true; + return true; + } + } + viewFactory._viewsRequireLifecycle = false; + return false; +} + +var AbstractRepeater = (function () { + function AbstractRepeater(options) { + Object.assign(this, { + local: 'items', + viewsRequireLifecycle: true + }, options); + } + AbstractRepeater.prototype.viewCount = function () { + throw new Error('subclass must implement `viewCount`'); + }; + AbstractRepeater.prototype.views = function () { + throw new Error('subclass must implement `views`'); + }; + AbstractRepeater.prototype.view = function (index) { + throw new Error('subclass must implement `view`'); + }; + AbstractRepeater.prototype.matcher = function () { + throw new Error('subclass must implement `matcher`'); + }; + AbstractRepeater.prototype.addView = function (bindingContext, overrideContext) { + throw new Error('subclass must implement `addView`'); + }; + AbstractRepeater.prototype.insertView = function (index, bindingContext, overrideContext) { + throw new Error('subclass must implement `insertView`'); + }; + AbstractRepeater.prototype.moveView = function (sourceIndex, targetIndex) { + throw new Error('subclass must implement `moveView`'); + }; + AbstractRepeater.prototype.removeAllViews = function (returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeAllViews`'); + }; + AbstractRepeater.prototype.removeViews = function (viewsToRemove, returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeView`'); + }; + AbstractRepeater.prototype.removeView = function (index, returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeView`'); + }; + AbstractRepeater.prototype.updateBindings = function (view) { + throw new Error('subclass must implement `updateBindings`'); + }; + return AbstractRepeater; +}()); + +var Repeat = (function (_super) { + __extends(Repeat, _super); + function Repeat(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) { + var _this = _super.call(this, { + local: 'item', + viewsRequireLifecycle: viewsRequireLifecycle(viewFactory) + }) || this; + _this.viewFactory = viewFactory; + _this.instruction = instruction; + _this.viewSlot = viewSlot; + _this.lookupFunctions = viewResources.lookupFunctions; + _this.observerLocator = observerLocator; + _this.key = 'key'; + _this.value = 'value'; + _this.strategyLocator = strategyLocator; + _this.ignoreMutation = false; + _this.sourceExpression = getItemsSourceExpression(_this.instruction, 'repeat.for'); + _this.isOneTime = isOneTime(_this.sourceExpression); + _this.viewsRequireLifecycle = viewsRequireLifecycle(viewFactory); + return _this; + } + Repeat.prototype.call = function (context, changes) { + this[context](this.items, changes); + }; + Repeat.prototype.bind = function (bindingContext, overrideContext) { + this.scope = { bindingContext: bindingContext, overrideContext: overrideContext }; + this.matcherBinding = this._captureAndRemoveMatcherBinding(); + this.itemsChanged(); + }; + Repeat.prototype.unbind = function () { + this.scope = null; + this.items = null; + this.matcherBinding = null; + this.viewSlot.removeAll(true, true); + this._unsubscribeCollection(); + }; + Repeat.prototype._unsubscribeCollection = function () { + if (this.collectionObserver) { + this.collectionObserver.unsubscribe(this.callContext, this); + this.collectionObserver = null; + this.callContext = null; + } + }; + Repeat.prototype.itemsChanged = function () { + var _this = this; + this._unsubscribeCollection(); + if (!this.scope) { + return; + } + var items = this.items; + this.strategy = this.strategyLocator.getStrategy(items); + if (!this.strategy) { + throw new Error("Value for '" + this.sourceExpression + "' is non-repeatable"); + } + if (!this.isOneTime && !this._observeInnerCollection()) { + this._observeCollection(); + } + this.ignoreMutation = true; + this.strategy.instanceChanged(this, items); + this.observerLocator.taskQueue.queueMicroTask(function () { + _this.ignoreMutation = false; + }); + }; + Repeat.prototype._getInnerCollection = function () { + var expression = unwrapExpression(this.sourceExpression); + if (!expression) { + return null; + } + return expression.evaluate(this.scope, null); + }; + Repeat.prototype.handleCollectionMutated = function (collection, changes) { + if (!this.collectionObserver) { + return; + } + if (this.ignoreMutation) { + return; + } + this.strategy.instanceMutated(this, collection, changes); + }; + Repeat.prototype.handleInnerCollectionMutated = function (collection, changes) { + var _this = this; + if (!this.collectionObserver) { + return; + } + if (this.ignoreMutation) { + return; + } + this.ignoreMutation = true; + var newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions); + this.observerLocator.taskQueue.queueMicroTask(function () { return _this.ignoreMutation = false; }); + if (newItems === this.items) { + this.itemsChanged(); + } + else { + this.items = newItems; + } + }; + Repeat.prototype._observeInnerCollection = function () { + var items = this._getInnerCollection(); + var strategy = this.strategyLocator.getStrategy(items); + if (!strategy) { + return false; + } + this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items); + if (!this.collectionObserver) { + return false; + } + this.callContext = 'handleInnerCollectionMutated'; + this.collectionObserver.subscribe(this.callContext, this); + return true; + }; + Repeat.prototype._observeCollection = function () { + var items = this.items; + this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items); + if (this.collectionObserver) { + this.callContext = 'handleCollectionMutated'; + this.collectionObserver.subscribe(this.callContext, this); + } + }; + Repeat.prototype._captureAndRemoveMatcherBinding = function () { + if (this.viewFactory.viewFactory) { + var instructions = this.viewFactory.viewFactory.instructions; + var instructionIds = Object.keys(instructions); + for (var i = 0; i < instructionIds.length; i++) { + var expressions = instructions[instructionIds[i]].expressions; + if (expressions) { + for (var ii = 0; ii < expressions.length; ii++) { + if (expressions[ii].targetProperty === 'matcher') { + var matcherBinding = expressions[ii]; + expressions.splice(ii, 1); + return matcherBinding; + } + } + } + } + } + return undefined; + }; + Repeat.prototype.viewCount = function () { return this.viewSlot.children.length; }; + Repeat.prototype.views = function () { return this.viewSlot.children; }; + Repeat.prototype.view = function (index) { return this.viewSlot.children[index]; }; + Repeat.prototype.matcher = function () { return this.matcherBinding ? this.matcherBinding.sourceExpression.evaluate(this.scope, this.matcherBinding.lookupFunctions) : null; }; + Repeat.prototype.addView = function (bindingContext, overrideContext) { + var view = this.viewFactory.create(); + view.bind(bindingContext, overrideContext); + this.viewSlot.add(view); + }; + Repeat.prototype.insertView = function (index, bindingContext, overrideContext) { + var view = this.viewFactory.create(); + view.bind(bindingContext, overrideContext); + this.viewSlot.insert(index, view); + }; + Repeat.prototype.moveView = function (sourceIndex, targetIndex) { + this.viewSlot.move(sourceIndex, targetIndex); + }; + Repeat.prototype.removeAllViews = function (returnToCache, skipAnimation) { + return this.viewSlot.removeAll(returnToCache, skipAnimation); + }; + Repeat.prototype.removeViews = function (viewsToRemove, returnToCache, skipAnimation) { + return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation); + }; + Repeat.prototype.removeView = function (index, returnToCache, skipAnimation) { + return this.viewSlot.removeAt(index, returnToCache, skipAnimation); + }; + Repeat.prototype.updateBindings = function (view) { + var $view = view; + var j = $view.bindings.length; + while (j--) { + updateOneTimeBinding($view.bindings[j]); + } + j = $view.controllers.length; + while (j--) { + var k = $view.controllers[j].boundProperties.length; + while (k--) { + var binding = $view.controllers[j].boundProperties[k].binding; + updateOneTimeBinding(binding); + } + } + }; + __decorate([ + bindable + ], Repeat.prototype, "items", void 0); + __decorate([ + bindable + ], Repeat.prototype, "local", void 0); + __decorate([ + bindable + ], Repeat.prototype, "key", void 0); + __decorate([ + bindable + ], Repeat.prototype, "value", void 0); + Repeat = __decorate([ + customAttribute('repeat'), + templateController, + inject(BoundViewFactory, TargetInstruction, ViewSlot, ViewResources, ObserverLocator, RepeatStrategyLocator) + ], Repeat); + return Repeat; +}(AbstractRepeater)); + +var aureliaHideClassName = 'aurelia-hide'; +var aureliaHideClass = "." + aureliaHideClassName + " { display:none !important; }"; +function injectAureliaHideStyleAtHead() { + DOM.injectStyles(aureliaHideClass); +} +function injectAureliaHideStyleAtBoundary(domBoundary) { + if (FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) { + domBoundary.hasAureliaHideStyle = true; + DOM.injectStyles(aureliaHideClass, domBoundary); + } +} + +var Show = (function () { + function Show(element, animator, domBoundary) { + this.element = element; + this.animator = animator; + this.domBoundary = domBoundary; + } + Show.inject = function () { + return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; + }; + Show.prototype.created = function () { + injectAureliaHideStyleAtBoundary(this.domBoundary); + }; + Show.prototype.valueChanged = function (newValue) { + var element = this.element; + var animator = this.animator; + if (newValue) { + animator.removeClass(element, aureliaHideClassName); + } + else { + animator.addClass(element, aureliaHideClassName); + } + }; + Show.prototype.bind = function (bindingContext) { + this.valueChanged(this.value); + }; + Show = __decorate([ + customAttribute('show') + ], Show); + return Show; +}()); + +var Hide = (function () { + function Hide(element, animator, domBoundary) { + this.element = element; + this.animator = animator; + this.domBoundary = domBoundary; + } + Hide.inject = function () { + return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; + }; + Hide.prototype.created = function () { + injectAureliaHideStyleAtBoundary(this.domBoundary); + }; + Hide.prototype.valueChanged = function (newValue) { + if (newValue) { + this.animator.addClass(this.element, aureliaHideClassName); + } + else { + this.animator.removeClass(this.element, aureliaHideClassName); + } + }; + Hide.prototype.bind = function (bindingContext) { + this.valueChanged(this.value); + }; + Hide.prototype.value = function (value) { + throw new Error('Method not implemented.'); + }; + Hide = __decorate([ + customAttribute('hide') + ], Hide); + return Hide; +}()); + +var SCRIPT_REGEX = /)<[^<]*)*<\/script>/gi; +var needsToWarn = true; +var HTMLSanitizer = (function () { + function HTMLSanitizer() { + } + HTMLSanitizer.prototype.sanitize = function (input) { + if (needsToWarn) { + needsToWarn = false; + getLogger('html-sanitizer') + .warn("CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks,\nand should not be relied on for sanitizing input from unknown sources.\nPlease see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html."); + } + return input.replace(SCRIPT_REGEX, ''); + }; + return HTMLSanitizer; +}()); + +var SanitizeHTMLValueConverter = (function () { + function SanitizeHTMLValueConverter(sanitizer) { + this.sanitizer = sanitizer; + } + SanitizeHTMLValueConverter.prototype.toView = function (untrustedMarkup) { + if (untrustedMarkup === null || untrustedMarkup === undefined) { + return null; + } + return this.sanitizer.sanitize(untrustedMarkup); + }; + SanitizeHTMLValueConverter = __decorate([ + valueConverter('sanitizeHTML'), + inject(HTMLSanitizer) + ], SanitizeHTMLValueConverter); + return SanitizeHTMLValueConverter; +}()); + +var Replaceable = (function () { + function Replaceable(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.view = null; + } + Replaceable.prototype.bind = function (bindingContext, overrideContext) { + if (this.view === null) { + this.view = this.viewFactory.create(); + this.viewSlot.add(this.view); + } + this.view.bind(bindingContext, overrideContext); + }; + Replaceable.prototype.unbind = function () { + this.view.unbind(); + }; + Replaceable = __decorate([ + customAttribute('replaceable'), + templateController, + inject(BoundViewFactory, ViewSlot) + ], Replaceable); + return Replaceable; +}()); + +var Focus = (function () { + function Focus(element, taskQueue) { + this.element = element; + this.taskQueue = taskQueue; + this.isAttached = false; + this.needsApply = false; + } + Focus.inject = function () { + return [DOM.Element, TaskQueue]; + }; + Focus.prototype.valueChanged = function (newValue) { + if (this.isAttached) { + this._apply(); + } + else { + this.needsApply = true; + } + }; + Focus.prototype._apply = function () { + var _this = this; + if (this.value) { + this.taskQueue.queueMicroTask(function () { + if (_this.value) { + _this.element.focus(); + } + }); + } + else { + this.element.blur(); + } + }; + Focus.prototype.attached = function () { + this.isAttached = true; + if (this.needsApply) { + this.needsApply = false; + this._apply(); + } + this.element.addEventListener('focus', this); + this.element.addEventListener('blur', this); + }; + Focus.prototype.detached = function () { + this.isAttached = false; + this.element.removeEventListener('focus', this); + this.element.removeEventListener('blur', this); + }; + Focus.prototype.handleEvent = function (e) { + if (e.type === 'focus') { + this.value = true; + } + else if (DOM.activeElement !== this.element) { + this.value = false; + } + }; + Focus = __decorate([ + customAttribute('focus', bindingMode.twoWay) + ], Focus); + return Focus; +}()); + +var cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi; +function fixupCSSUrls(address, css) { + if (typeof css !== 'string') { + throw new Error("Failed loading required CSS file: " + address); + } + return css.replace(cssUrlMatcher, function (match, p1) { + var quote = p1.charAt(0); + if (quote === '\'' || quote === '"') { + p1 = p1.substr(1, p1.length - 2); + } + return 'url(\'' + relativeToFile(p1, address) + '\')'; + }); +} +var CSSResource = (function () { + function CSSResource(address) { + this.address = address; + this._scoped = null; + this._global = false; + this._alreadyGloballyInjected = false; + } + CSSResource.prototype.initialize = function (container, Target) { + this._scoped = new Target(this); + }; + CSSResource.prototype.register = function (registry, name) { + if (name === 'scoped') { + registry.registerViewEngineHooks(this._scoped); + } + else { + this._global = true; + } + }; + CSSResource.prototype.load = function (container) { + var _this = this; + return container.get(Loader) + .loadText(this.address) + .catch(function (err) { return null; }) + .then(function (text) { + text = fixupCSSUrls(_this.address, text); + _this._scoped.css = text; + if (_this._global) { + _this._alreadyGloballyInjected = true; + DOM.injectStyles(text); + } + }); + }; + return CSSResource; +}()); +var CSSViewEngineHooks = (function () { + function CSSViewEngineHooks(owner) { + this.owner = owner; + this.css = null; + } + CSSViewEngineHooks.prototype.beforeCompile = function (content, resources, instruction) { + if (instruction.targetShadowDOM) { + DOM.injectStyles(this.css, content, true); + } + else if (FEATURE.scopedCSS) { + var styleNode = DOM.injectStyles(this.css, content, true); + styleNode.setAttribute('scoped', 'scoped'); + } + else if (this._global && !this.owner._alreadyGloballyInjected) { + DOM.injectStyles(this.css); + this.owner._alreadyGloballyInjected = true; + } + }; + return CSSViewEngineHooks; +}()); +function _createCSSResource(address) { + var ViewCSS = (function (_super) { + __extends(ViewCSS, _super); + function ViewCSS() { + return _super !== null && _super.apply(this, arguments) || this; + } + ViewCSS = __decorate([ + resource(new CSSResource(address)) + ], ViewCSS); + return ViewCSS; + }(CSSViewEngineHooks)); + return ViewCSS; +} + +var AttrBindingBehavior = (function () { + function AttrBindingBehavior() { + } + AttrBindingBehavior.prototype.bind = function (binding, source) { + binding.targetObserver = new DataAttributeObserver(binding.target, binding.targetProperty); + }; + AttrBindingBehavior.prototype.unbind = function (binding, source) { + }; + AttrBindingBehavior = __decorate([ + bindingBehavior('attr') + ], AttrBindingBehavior); + return AttrBindingBehavior; +}()); + +var modeBindingBehavior = { + bind: function (binding, source, lookupFunctions) { + binding.originalMode = binding.mode; + binding.mode = this.mode; + }, + unbind: function (binding, source) { + binding.mode = binding.originalMode; + binding.originalMode = null; + } +}; +var OneTimeBindingBehavior = (function () { + function OneTimeBindingBehavior() { + this.mode = bindingMode.oneTime; + } + OneTimeBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('oneTime') + ], OneTimeBindingBehavior); + return OneTimeBindingBehavior; +}()); +var OneWayBindingBehavior = (function () { + function OneWayBindingBehavior() { + this.mode = bindingMode.toView; + } + OneWayBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('oneWay') + ], OneWayBindingBehavior); + return OneWayBindingBehavior; +}()); +var ToViewBindingBehavior = (function () { + function ToViewBindingBehavior() { + this.mode = bindingMode.toView; + } + ToViewBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('toView') + ], ToViewBindingBehavior); + return ToViewBindingBehavior; +}()); +var FromViewBindingBehavior = (function () { + function FromViewBindingBehavior() { + this.mode = bindingMode.fromView; + } + FromViewBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('fromView') + ], FromViewBindingBehavior); + return FromViewBindingBehavior; +}()); +var TwoWayBindingBehavior = (function () { + function TwoWayBindingBehavior() { + this.mode = bindingMode.twoWay; + } + TwoWayBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('twoWay') + ], TwoWayBindingBehavior); + return TwoWayBindingBehavior; +}()); + +function throttle(newValue) { + var _this = this; + var state = this.throttleState; + var elapsed = +new Date() - state.last; + if (elapsed >= state.delay) { + clearTimeout(state.timeoutId); + state.timeoutId = null; + state.last = +new Date(); + this.throttledMethod(newValue); + return; + } + state.newValue = newValue; + if (state.timeoutId === null) { + state.timeoutId = setTimeout(function () { + state.timeoutId = null; + state.last = +new Date(); + _this.throttledMethod(state.newValue); + }, state.delay - elapsed); + } +} +var ThrottleBindingBehavior = (function () { + function ThrottleBindingBehavior() { + } + ThrottleBindingBehavior.prototype.bind = function (binding, source, delay) { + if (delay === void 0) { delay = 200; } + var methodToThrottle = 'updateTarget'; + if (binding.callSource) { + methodToThrottle = 'callSource'; + } + else if (binding.updateSource && binding.mode === bindingMode.twoWay) { + methodToThrottle = 'updateSource'; + } + binding.throttledMethod = binding[methodToThrottle]; + binding.throttledMethod.originalName = methodToThrottle; + binding[methodToThrottle] = throttle; + binding.throttleState = { + delay: delay, + last: 0, + timeoutId: null + }; + }; + ThrottleBindingBehavior.prototype.unbind = function (binding, source) { + var methodToRestore = binding.throttledMethod.originalName; + binding[methodToRestore] = binding.throttledMethod; + binding.throttledMethod = null; + clearTimeout(binding.throttleState.timeoutId); + binding.throttleState = null; + }; + ThrottleBindingBehavior = __decorate([ + bindingBehavior('throttle') + ], ThrottleBindingBehavior); + return ThrottleBindingBehavior; +}()); + +var unset = {}; +function debounceCallSource(event) { + var _this = this; + var state = this.debounceState; + clearTimeout(state.timeoutId); + state.timeoutId = setTimeout(function () { return _this.debouncedMethod(event); }, state.delay); +} +function debounceCall(context, newValue, oldValue) { + var _this = this; + var state = this.debounceState; + clearTimeout(state.timeoutId); + if (context !== state.callContextToDebounce) { + state.oldValue = unset; + this.debouncedMethod(context, newValue, oldValue); + return; + } + if (state.oldValue === unset) { + state.oldValue = oldValue; + } + state.timeoutId = setTimeout(function () { + var _oldValue = state.oldValue; + state.oldValue = unset; + _this.debouncedMethod(context, newValue, _oldValue); + }, state.delay); +} +var DebounceBindingBehavior = (function () { + function DebounceBindingBehavior() { + } + DebounceBindingBehavior.prototype.bind = function (binding, source, delay) { + if (delay === void 0) { delay = 200; } + var isCallSource = binding.callSource !== undefined; + var methodToDebounce = isCallSource ? 'callSource' : 'call'; + var debouncer = isCallSource ? debounceCallSource : debounceCall; + var mode = binding.mode; + var callContextToDebounce = mode === bindingMode.twoWay || mode === bindingMode.fromView ? targetContext : sourceContext; + binding.debouncedMethod = binding[methodToDebounce]; + binding.debouncedMethod.originalName = methodToDebounce; + binding[methodToDebounce] = debouncer; + binding.debounceState = { + callContextToDebounce: callContextToDebounce, + delay: delay, + timeoutId: 0, + oldValue: unset + }; + }; + DebounceBindingBehavior.prototype.unbind = function (binding, source) { + var methodToRestore = binding.debouncedMethod.originalName; + binding[methodToRestore] = binding.debouncedMethod; + binding.debouncedMethod = null; + clearTimeout(binding.debounceState.timeoutId); + binding.debounceState = null; + }; + DebounceBindingBehavior = __decorate([ + bindingBehavior('debounce') + ], DebounceBindingBehavior); + return DebounceBindingBehavior; +}()); + +function findOriginalEventTarget(event) { + return (event.path && event.path[0]) || (event.deepPath && event.deepPath[0]) || event.target; +} +function handleSelfEvent(event) { + var target = findOriginalEventTarget(event); + if (this.target !== target) { + return; + } + this.selfEventCallSource(event); +} +var SelfBindingBehavior = (function () { + function SelfBindingBehavior() { + } + SelfBindingBehavior.prototype.bind = function (binding, source) { + if (!binding.callSource || !binding.targetEvent) { + throw new Error('Self binding behavior only supports event.'); + } + binding.selfEventCallSource = binding.callSource; + binding.callSource = handleSelfEvent; + }; + SelfBindingBehavior.prototype.unbind = function (binding, source) { + binding.callSource = binding.selfEventCallSource; + binding.selfEventCallSource = null; + }; + SelfBindingBehavior = __decorate([ + bindingBehavior('self') + ], SelfBindingBehavior); + return SelfBindingBehavior; +}()); + +var BindingSignaler = (function () { + function BindingSignaler() { + this.signals = {}; + } + BindingSignaler.prototype.signal = function (name) { + var bindings = this.signals[name]; + if (!bindings) { + return; + } + var i = bindings.length; + while (i--) { + bindings[i].call(sourceContext); + } + }; + return BindingSignaler; +}()); + +var SignalBindingBehavior = (function () { + function SignalBindingBehavior(bindingSignaler) { + this.signals = bindingSignaler.signals; + } + SignalBindingBehavior.inject = function () { return [BindingSignaler]; }; + SignalBindingBehavior.prototype.bind = function (binding, source) { + var names = []; + for (var _i = 2; _i < arguments.length; _i++) { + names[_i - 2] = arguments[_i]; + } + if (!binding.updateTarget) { + throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.'); + } + var signals = this.signals; + if (names.length === 1) { + var name_1 = names[0]; + var bindings = signals[name_1] || (signals[name_1] = []); + bindings.push(binding); + binding.signalName = name_1; + } + else if (names.length > 1) { + var i = names.length; + while (i--) { + var name_2 = names[i]; + var bindings = signals[name_2] || (signals[name_2] = []); + bindings.push(binding); + } + binding.signalName = names; + } + else { + throw new Error('Signal name is required.'); + } + }; + SignalBindingBehavior.prototype.unbind = function (binding, source) { + var signals = this.signals; + var name = binding.signalName; + binding.signalName = null; + if (Array.isArray(name)) { + var names = name; + var i = names.length; + while (i--) { + var n = names[i]; + var bindings = signals[n]; + bindings.splice(bindings.indexOf(binding), 1); + } + } + else { + var bindings = signals[name]; + bindings.splice(bindings.indexOf(binding), 1); + } + }; + SignalBindingBehavior = __decorate([ + bindingBehavior('signal') + ], SignalBindingBehavior); + return SignalBindingBehavior; +}()); + +var eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg '; +var notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.'; +var UpdateTriggerBindingBehavior = (function () { + function UpdateTriggerBindingBehavior() { + } + UpdateTriggerBindingBehavior.prototype.bind = function (binding, source) { + var events = []; + for (var _i = 2; _i < arguments.length; _i++) { + events[_i - 2] = arguments[_i]; + } + if (events.length === 0) { + throw new Error(eventNamesRequired); + } + if (binding.mode !== bindingMode.twoWay && binding.mode !== bindingMode.fromView) { + throw new Error(notApplicableMessage); + } + var targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty); + if (!targetObserver.handler) { + throw new Error(notApplicableMessage); + } + binding.targetObserver = targetObserver; + targetObserver.originalHandler = binding.targetObserver.handler; + var handler = new EventSubscriber(events); + targetObserver.handler = handler; + }; + UpdateTriggerBindingBehavior.prototype.unbind = function (binding, source) { + var targetObserver = binding.targetObserver; + targetObserver.handler.dispose(); + targetObserver.handler = targetObserver.originalHandler; + targetObserver.originalHandler = null; + }; + UpdateTriggerBindingBehavior = __decorate([ + bindingBehavior('updateTrigger') + ], UpdateTriggerBindingBehavior); + return UpdateTriggerBindingBehavior; +}()); + +function _createDynamicElement(_a) { + var name = _a.name, viewUrl = _a.viewUrl, bindableNames = _a.bindableNames, useShadowDOMmode = _a.useShadowDOMmode; + var DynamicElement = (function () { + function DynamicElement() { + } + DynamicElement.prototype.bind = function (bindingContext) { + this.$parent = bindingContext; + }; + DynamicElement = __decorate([ + customElement(name), + useView(viewUrl) + ], DynamicElement); + return DynamicElement; + }()); + for (var i = 0, ii = bindableNames.length; i < ii; ++i) { + bindable(bindableNames[i])(DynamicElement); + } + switch (useShadowDOMmode) { + case 'open': + useShadowDOM({ mode: 'open' })(DynamicElement); + break; + case 'closed': + useShadowDOM({ mode: 'closed' })(DynamicElement); + break; + case '': + useShadowDOM(DynamicElement); + break; + case null: + break; + default: + getLogger('aurelia-html-only-element') + .warn("Expected 'use-shadow-dom' value to be \"close\", \"open\" or \"\", received " + useShadowDOMmode); + break; + } + return DynamicElement; +} + +function getElementName(address) { + return /([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase(); +} +function configure(config) { + var viewEngine = config.container.get(ViewEngine); + var loader = config.aurelia.loader; + viewEngine.addResourcePlugin('.html', { + 'fetch': function (viewUrl) { + return loader.loadTemplate(viewUrl).then(function (registryEntry) { + var _a; + var bindableNames = registryEntry.template.getAttribute('bindable'); + var useShadowDOMmode = registryEntry.template.getAttribute('use-shadow-dom'); + var name = getElementName(viewUrl); + if (bindableNames) { + bindableNames = bindableNames.split(',').map(function (x) { return x.trim(); }); + registryEntry.template.removeAttribute('bindable'); + } + else { + bindableNames = []; + } + return _a = {}, _a[name] = _createDynamicElement({ name: name, viewUrl: viewUrl, bindableNames: bindableNames, useShadowDOMmode: useShadowDOMmode }), _a; + }); + } + }); +} + +function configure$1(config) { + injectAureliaHideStyleAtHead(); + config.globalResources(Compose, If, Else, With, Repeat, Show, Hide, Replaceable, Focus, SanitizeHTMLValueConverter, OneTimeBindingBehavior, OneWayBindingBehavior, ToViewBindingBehavior, FromViewBindingBehavior, TwoWayBindingBehavior, ThrottleBindingBehavior, DebounceBindingBehavior, SelfBindingBehavior, SignalBindingBehavior, UpdateTriggerBindingBehavior, AttrBindingBehavior); + configure(config); + var viewEngine = config.container.get(ViewEngine); + var styleResourcePlugin = { + fetch: function (address) { + var _a; + return _a = {}, _a[address] = _createCSSResource(address), _a; + } + }; + ['.css', '.less', '.sass', '.scss', '.styl'].forEach(function (ext) { return viewEngine.addResourcePlugin(ext, styleResourcePlugin); }); +} + +export { AbstractRepeater, ArrayRepeatStrategy, AttrBindingBehavior, BindingSignaler, Compose, DebounceBindingBehavior, Else, Focus, FromViewBindingBehavior, HTMLSanitizer, Hide, If, MapRepeatStrategy, NullRepeatStrategy, NumberRepeatStrategy, OneTimeBindingBehavior, OneWayBindingBehavior, Repeat, RepeatStrategyLocator, Replaceable, SanitizeHTMLValueConverter, SelfBindingBehavior, SetRepeatStrategy, Show, SignalBindingBehavior, ThrottleBindingBehavior, ToViewBindingBehavior, TwoWayBindingBehavior, UpdateTriggerBindingBehavior, With, configure$1 as configure, createFullOverrideContext, getItemsSourceExpression, isOneTime, unwrapExpression, updateOneTimeBinding, updateOverrideContext, viewsRequireLifecycle }; +//# sourceMappingURL=aurelia-templating-resources.js.map diff --git a/dist/native-modules/aurelia-templating-resources.js.map b/dist/native-modules/aurelia-templating-resources.js.map new file mode 100644 index 0000000..2b4004b --- /dev/null +++ b/dist/native-modules/aurelia-templating-resources.js.map @@ -0,0 +1 @@ +{"version":3,"file":"aurelia-templating-resources.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/native-modules/binding-mode-behaviors.js b/dist/native-modules/binding-mode-behaviors.js deleted file mode 100644 index f4e268d..0000000 --- a/dist/native-modules/binding-mode-behaviors.js +++ /dev/null @@ -1,47 +0,0 @@ -var _dec, _dec2, _class, _dec3, _dec4, _class2, _dec5, _dec6, _class3, _dec7, _dec8, _class4, _dec9, _dec10, _class5; - - - -import { bindingMode, bindingBehavior } from 'aurelia-binding'; -import { mixin } from 'aurelia-metadata'; - -var modeBindingBehavior = { - bind: function bind(binding, source, lookupFunctions) { - binding.originalMode = binding.mode; - binding.mode = this.mode; - }, - unbind: function unbind(binding, source) { - binding.mode = binding.originalMode; - binding.originalMode = null; - } -}; - -export var OneTimeBindingBehavior = (_dec = mixin(modeBindingBehavior), _dec2 = bindingBehavior('oneTime'), _dec(_class = _dec2(_class = function OneTimeBindingBehavior() { - - - this.mode = bindingMode.oneTime; -}) || _class) || _class); - -export var OneWayBindingBehavior = (_dec3 = mixin(modeBindingBehavior), _dec4 = bindingBehavior('oneWay'), _dec3(_class2 = _dec4(_class2 = function OneWayBindingBehavior() { - - - this.mode = bindingMode.toView; -}) || _class2) || _class2); - -export var ToViewBindingBehavior = (_dec5 = mixin(modeBindingBehavior), _dec6 = bindingBehavior('toView'), _dec5(_class3 = _dec6(_class3 = function ToViewBindingBehavior() { - - - this.mode = bindingMode.toView; -}) || _class3) || _class3); - -export var FromViewBindingBehavior = (_dec7 = mixin(modeBindingBehavior), _dec8 = bindingBehavior('fromView'), _dec7(_class4 = _dec8(_class4 = function FromViewBindingBehavior() { - - - this.mode = bindingMode.fromView; -}) || _class4) || _class4); - -export var TwoWayBindingBehavior = (_dec9 = mixin(modeBindingBehavior), _dec10 = bindingBehavior('twoWay'), _dec9(_class5 = _dec10(_class5 = function TwoWayBindingBehavior() { - - - this.mode = bindingMode.twoWay; -}) || _class5) || _class5); \ No newline at end of file diff --git a/dist/native-modules/binding-signaler.js b/dist/native-modules/binding-signaler.js deleted file mode 100644 index e5819ac..0000000 --- a/dist/native-modules/binding-signaler.js +++ /dev/null @@ -1,24 +0,0 @@ - - -import { sourceContext } from 'aurelia-binding'; - -export var BindingSignaler = function () { - function BindingSignaler() { - - - this.signals = {}; - } - - BindingSignaler.prototype.signal = function signal(name) { - var bindings = this.signals[name]; - if (!bindings) { - return; - } - var i = bindings.length; - while (i--) { - bindings[i].call(sourceContext); - } - }; - - return BindingSignaler; -}(); \ No newline at end of file diff --git a/dist/native-modules/compose.js b/dist/native-modules/compose.js deleted file mode 100644 index 243f183..0000000 --- a/dist/native-modules/compose.js +++ /dev/null @@ -1,210 +0,0 @@ -var _dec, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4; - -function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); -} - - - -function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; -} - -function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); -} - -import { Container } from 'aurelia-dependency-injection'; -import { TaskQueue } from 'aurelia-task-queue'; -import { CompositionEngine, CompositionContext, ViewSlot, ViewResources, customElement, bindable, noView, View } from 'aurelia-templating'; -import { DOM } from 'aurelia-pal'; - -export var Compose = (_dec = customElement('compose'), _dec(_class = noView(_class = (_class2 = function () { - Compose.inject = function inject() { - return [DOM.Element, Container, CompositionEngine, ViewSlot, ViewResources, TaskQueue]; - }; - - function Compose(element, container, compositionEngine, viewSlot, viewResources, taskQueue) { - - - _initDefineProp(this, 'model', _descriptor, this); - - _initDefineProp(this, 'view', _descriptor2, this); - - _initDefineProp(this, 'viewModel', _descriptor3, this); - - _initDefineProp(this, 'swapOrder', _descriptor4, this); - - this.element = element; - this.container = container; - this.compositionEngine = compositionEngine; - this.viewSlot = viewSlot; - this.viewResources = viewResources; - this.taskQueue = taskQueue; - this.currentController = null; - this.currentViewModel = null; - this.changes = Object.create(null); - } - - Compose.prototype.created = function created(owningView) { - this.owningView = owningView; - }; - - Compose.prototype.bind = function bind(bindingContext, overrideContext) { - this.bindingContext = bindingContext; - this.overrideContext = overrideContext; - this.changes.view = this.view; - this.changes.viewModel = this.viewModel; - this.changes.model = this.model; - if (!this.pendingTask) { - processChanges(this); - } - }; - - Compose.prototype.unbind = function unbind() { - this.changes = Object.create(null); - this.bindingContext = null; - this.overrideContext = null; - var returnToCache = true; - var skipAnimation = true; - this.viewSlot.removeAll(returnToCache, skipAnimation); - }; - - Compose.prototype.modelChanged = function modelChanged(newValue, oldValue) { - this.changes.model = newValue; - requestUpdate(this); - }; - - Compose.prototype.viewChanged = function viewChanged(newValue, oldValue) { - this.changes.view = newValue; - requestUpdate(this); - }; - - Compose.prototype.viewModelChanged = function viewModelChanged(newValue, oldValue) { - this.changes.viewModel = newValue; - requestUpdate(this); - }; - - return Compose; -}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'model', [bindable], { - enumerable: true, - initializer: null -}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'view', [bindable], { - enumerable: true, - initializer: null -}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'viewModel', [bindable], { - enumerable: true, - initializer: null -}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, 'swapOrder', [bindable], { - enumerable: true, - initializer: null -})), _class2)) || _class) || _class); - -function isEmpty(obj) { - for (var key in obj) { - return false; - } - return true; -} - -function tryActivateViewModel(vm, model) { - if (vm && typeof vm.activate === 'function') { - return Promise.resolve(vm.activate(model)); - } -} - -function createInstruction(composer, instruction) { - return Object.assign(instruction, { - bindingContext: composer.bindingContext, - overrideContext: composer.overrideContext, - owningView: composer.owningView, - container: composer.container, - viewSlot: composer.viewSlot, - viewResources: composer.viewResources, - currentController: composer.currentController, - host: composer.element, - swapOrder: composer.swapOrder - }); -} - -function processChanges(composer) { - var changes = composer.changes; - composer.changes = Object.create(null); - - if (!('view' in changes) && !('viewModel' in changes) && 'model' in changes) { - composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model); - if (!composer.pendingTask) { - return; - } - } else { - var instruction = { - view: composer.view, - viewModel: composer.currentViewModel || composer.viewModel, - model: composer.model - }; - - instruction = Object.assign(instruction, changes); - - instruction = createInstruction(composer, instruction); - composer.pendingTask = composer.compositionEngine.compose(instruction).then(function (controller) { - composer.currentController = controller; - composer.currentViewModel = controller ? controller.viewModel : null; - }); - } - - composer.pendingTask = composer.pendingTask.then(function () { - completeCompositionTask(composer); - }, function (reason) { - completeCompositionTask(composer); - throw reason; - }); -} - -function completeCompositionTask(composer) { - composer.pendingTask = null; - if (!isEmpty(composer.changes)) { - processChanges(composer); - } -} - -function requestUpdate(composer) { - if (composer.pendingTask || composer.updateRequested) { - return; - } - composer.updateRequested = true; - composer.taskQueue.queueMicroTask(function () { - composer.updateRequested = false; - processChanges(composer); - }); -} \ No newline at end of file diff --git a/dist/native-modules/css-resource.js b/dist/native-modules/css-resource.js deleted file mode 100644 index f02273f..0000000 --- a/dist/native-modules/css-resource.js +++ /dev/null @@ -1,107 +0,0 @@ -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - - - -import { ViewResources, resource, ViewCompileInstruction } from 'aurelia-templating'; -import { Loader } from 'aurelia-loader'; -import { Container } from 'aurelia-dependency-injection'; -import { relativeToFile } from 'aurelia-path'; -import { DOM, FEATURE } from 'aurelia-pal'; - -var cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi; - -function fixupCSSUrls(address, css) { - if (typeof css !== 'string') { - throw new Error('Failed loading required CSS file: ' + address); - } - return css.replace(cssUrlMatcher, function (match, p1) { - var quote = p1.charAt(0); - if (quote === '\'' || quote === '"') { - p1 = p1.substr(1, p1.length - 2); - } - return 'url(\'' + relativeToFile(p1, address) + '\')'; - }); -} - -var CSSResource = function () { - function CSSResource(address) { - - - this.address = address; - this._scoped = null; - this._global = false; - this._alreadyGloballyInjected = false; - } - - CSSResource.prototype.initialize = function initialize(container, target) { - this._scoped = new target(this); - }; - - CSSResource.prototype.register = function register(registry, name) { - if (name === 'scoped') { - registry.registerViewEngineHooks(this._scoped); - } else { - this._global = true; - } - }; - - CSSResource.prototype.load = function load(container) { - var _this = this; - - return container.get(Loader).loadText(this.address).catch(function (err) { - return null; - }).then(function (text) { - text = fixupCSSUrls(_this.address, text); - _this._scoped.css = text; - if (_this._global) { - _this._alreadyGloballyInjected = true; - DOM.injectStyles(text); - } - }); - }; - - return CSSResource; -}(); - -var CSSViewEngineHooks = function () { - function CSSViewEngineHooks(owner) { - - - this.owner = owner; - this.css = null; - } - - CSSViewEngineHooks.prototype.beforeCompile = function beforeCompile(content, resources, instruction) { - if (instruction.targetShadowDOM) { - DOM.injectStyles(this.css, content, true); - } else if (FEATURE.scopedCSS) { - var styleNode = DOM.injectStyles(this.css, content, true); - styleNode.setAttribute('scoped', 'scoped'); - } else if (this._global && !this.owner._alreadyGloballyInjected) { - DOM.injectStyles(this.css); - this.owner._alreadyGloballyInjected = true; - } - }; - - return CSSViewEngineHooks; -}(); - -export function _createCSSResource(address) { - var _dec, _class; - - var ViewCSS = (_dec = resource(new CSSResource(address)), _dec(_class = function (_CSSViewEngineHooks) { - _inherits(ViewCSS, _CSSViewEngineHooks); - - function ViewCSS() { - - - return _possibleConstructorReturn(this, _CSSViewEngineHooks.apply(this, arguments)); - } - - return ViewCSS; - }(CSSViewEngineHooks)) || _class); - - return ViewCSS; -} \ No newline at end of file diff --git a/dist/native-modules/debounce-binding-behavior.js b/dist/native-modules/debounce-binding-behavior.js deleted file mode 100644 index db29bec..0000000 --- a/dist/native-modules/debounce-binding-behavior.js +++ /dev/null @@ -1,75 +0,0 @@ -var _dec, _class; - - - -import { bindingMode, sourceContext, targetContext, bindingBehavior } from 'aurelia-binding'; - -var unset = {}; - -function debounceCallSource(event) { - var _this = this; - - var state = this.debounceState; - clearTimeout(state.timeoutId); - state.timeoutId = setTimeout(function () { - return _this.debouncedMethod(event); - }, state.delay); -} - -function debounceCall(context, newValue, oldValue) { - var _this2 = this; - - var state = this.debounceState; - clearTimeout(state.timeoutId); - if (context !== state.callContextToDebounce) { - state.oldValue = unset; - this.debouncedMethod(context, newValue, oldValue); - return; - } - if (state.oldValue === unset) { - state.oldValue = oldValue; - } - state.timeoutId = setTimeout(function () { - var _oldValue = state.oldValue; - state.oldValue = unset; - _this2.debouncedMethod(context, newValue, _oldValue); - }, state.delay); -} - -export var DebounceBindingBehavior = (_dec = bindingBehavior('debounce'), _dec(_class = function () { - function DebounceBindingBehavior() { - - } - - DebounceBindingBehavior.prototype.bind = function bind(binding, source) { - var delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200; - - var isCallSource = binding.callSource !== undefined; - var methodToDebounce = isCallSource ? 'callSource' : 'call'; - var debouncer = isCallSource ? debounceCallSource : debounceCall; - var mode = binding.mode; - var callContextToDebounce = mode === bindingMode.twoWay || mode === bindingMode.fromView ? targetContext : sourceContext; - - binding.debouncedMethod = binding[methodToDebounce]; - binding.debouncedMethod.originalName = methodToDebounce; - - binding[methodToDebounce] = debouncer; - - binding.debounceState = { - callContextToDebounce: callContextToDebounce, - delay: delay, - timeoutId: 0, - oldValue: unset - }; - }; - - DebounceBindingBehavior.prototype.unbind = function unbind(binding, source) { - var methodToRestore = binding.debouncedMethod.originalName; - binding[methodToRestore] = binding.debouncedMethod; - binding.debouncedMethod = null; - clearTimeout(binding.debounceState.timeoutId); - binding.debounceState = null; - }; - - return DebounceBindingBehavior; -}()) || _class); \ No newline at end of file diff --git a/dist/native-modules/dynamic-element.js b/dist/native-modules/dynamic-element.js deleted file mode 100644 index 567dfe3..0000000 --- a/dist/native-modules/dynamic-element.js +++ /dev/null @@ -1,52 +0,0 @@ - - -import { useView, customElement, bindable, useShadowDOM } from 'aurelia-templating'; -import { getLogger } from 'aurelia-logging'; - -export function _createDynamicElement(_ref) { - var _dec, _dec2, _class; - - var name = _ref.name, - viewUrl = _ref.viewUrl, - bindableNames = _ref.bindableNames, - useShadowDOMmode = _ref.useShadowDOMmode; - var DynamicElement = (_dec = customElement(name), _dec2 = useView(viewUrl), _dec(_class = _dec2(_class = function () { - function DynamicElement() { - - } - - DynamicElement.prototype.bind = function bind(bindingContext) { - this.$parent = bindingContext; - }; - - return DynamicElement; - }()) || _class) || _class); - - - for (var i = 0, ii = bindableNames.length; i < ii; ++i) { - bindable(bindableNames[i])(DynamicElement); - } - - switch (useShadowDOMmode) { - case 'open': - useShadowDOM({ mode: 'open' })(DynamicElement); - break; - - case 'closed': - useShadowDOM({ mode: 'closed' })(DynamicElement); - break; - - case '': - useShadowDOM(DynamicElement); - break; - - case null: - break; - - default: - getLogger('aurelia-html-only-element').warn('Expected \'use-shadow-dom\' value to be "close", "open" or "", received ' + useShadowDOMmode); - break; - } - - return DynamicElement; -} \ No newline at end of file diff --git a/dist/native-modules/else.js b/dist/native-modules/else.js deleted file mode 100644 index 42f4c25..0000000 --- a/dist/native-modules/else.js +++ /dev/null @@ -1,48 +0,0 @@ -var _dec, _dec2, _class; - - - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -import { BoundViewFactory, ViewSlot, customAttribute, templateController } from 'aurelia-templating'; -import { inject } from 'aurelia-dependency-injection'; -import { IfCore } from './if-core'; - -export var Else = (_dec = customAttribute('else'), _dec2 = inject(BoundViewFactory, ViewSlot), _dec(_class = templateController(_class = _dec2(_class = function (_IfCore) { - _inherits(Else, _IfCore); - - function Else(viewFactory, viewSlot) { - - - var _this = _possibleConstructorReturn(this, _IfCore.call(this, viewFactory, viewSlot)); - - _this._registerInIf(); - return _this; - } - - Else.prototype.bind = function bind(bindingContext, overrideContext) { - _IfCore.prototype.bind.call(this, bindingContext, overrideContext); - - if (this.ifVm.condition) { - this._hide(); - } else { - this._show(); - } - }; - - Else.prototype._registerInIf = function _registerInIf() { - var previous = this.viewSlot.anchor.previousSibling; - while (previous && !previous.au) { - previous = previous.previousSibling; - } - if (!previous || !previous.au.if) { - throw new Error("Can't find matching If for Else custom attribute."); - } - this.ifVm = previous.au.if.viewModel; - this.ifVm.elseVm = this; - }; - - return Else; -}(IfCore)) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/native-modules/focus.js b/dist/native-modules/focus.js deleted file mode 100644 index 081d65a..0000000 --- a/dist/native-modules/focus.js +++ /dev/null @@ -1,71 +0,0 @@ -var _dec, _class; - - - -import { customAttribute } from 'aurelia-templating'; -import { bindingMode } from 'aurelia-binding'; -import { TaskQueue } from 'aurelia-task-queue'; -import { DOM } from 'aurelia-pal'; - -export var Focus = (_dec = customAttribute('focus', bindingMode.twoWay), _dec(_class = function () { - Focus.inject = function inject() { - return [DOM.Element, TaskQueue]; - }; - - function Focus(element, taskQueue) { - - - this.element = element; - this.taskQueue = taskQueue; - this.isAttached = false; - this.needsApply = false; - } - - Focus.prototype.valueChanged = function valueChanged(newValue) { - if (this.isAttached) { - this._apply(); - } else { - this.needsApply = true; - } - }; - - Focus.prototype._apply = function _apply() { - var _this = this; - - if (this.value) { - this.taskQueue.queueMicroTask(function () { - if (_this.value) { - _this.element.focus(); - } - }); - } else { - this.element.blur(); - } - }; - - Focus.prototype.attached = function attached() { - this.isAttached = true; - if (this.needsApply) { - this.needsApply = false; - this._apply(); - } - this.element.addEventListener('focus', this); - this.element.addEventListener('blur', this); - }; - - Focus.prototype.detached = function detached() { - this.isAttached = false; - this.element.removeEventListener('focus', this); - this.element.removeEventListener('blur', this); - }; - - Focus.prototype.handleEvent = function handleEvent(e) { - if (e.type === 'focus') { - this.value = true; - } else if (DOM.activeElement !== this.element) { - this.value = false; - } - }; - - return Focus; -}()) || _class); \ No newline at end of file diff --git a/dist/native-modules/hide.js b/dist/native-modules/hide.js deleted file mode 100644 index a85cafd..0000000 --- a/dist/native-modules/hide.js +++ /dev/null @@ -1,40 +0,0 @@ -var _dec, _class; - - - -import { Optional } from 'aurelia-dependency-injection'; -import { customAttribute, Animator } from 'aurelia-templating'; -import { DOM } from 'aurelia-pal'; -import { injectAureliaHideStyleAtBoundary, aureliaHideClassName } from './aurelia-hide-style'; - -export var Hide = (_dec = customAttribute('hide'), _dec(_class = function () { - Hide.inject = function inject() { - return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; - }; - - function Hide(element, animator, domBoundary) { - - - this.element = element; - this.animator = animator; - this.domBoundary = domBoundary; - } - - Hide.prototype.created = function created() { - injectAureliaHideStyleAtBoundary(this.domBoundary); - }; - - Hide.prototype.valueChanged = function valueChanged(newValue) { - if (newValue) { - this.animator.addClass(this.element, aureliaHideClassName); - } else { - this.animator.removeClass(this.element, aureliaHideClassName); - } - }; - - Hide.prototype.bind = function bind(bindingContext) { - this.valueChanged(this.value); - }; - - return Hide; -}()) || _class); \ No newline at end of file diff --git a/dist/native-modules/html-resource-plugin.js b/dist/native-modules/html-resource-plugin.js deleted file mode 100644 index cd2bfe1..0000000 --- a/dist/native-modules/html-resource-plugin.js +++ /dev/null @@ -1,35 +0,0 @@ -import { ViewEngine } from 'aurelia-templating'; -import { _createDynamicElement } from './dynamic-element'; - -export function getElementName(address) { - return (/([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase() - ); -} - -export function configure(config) { - var viewEngine = config.container.get(ViewEngine); - var loader = config.aurelia.loader; - - viewEngine.addResourcePlugin('.html', { - 'fetch': function fetch(viewUrl) { - return loader.loadTemplate(viewUrl).then(function (registryEntry) { - var _ref; - - var bindableNames = registryEntry.template.getAttribute('bindable'); - var useShadowDOMmode = registryEntry.template.getAttribute('use-shadow-dom'); - var name = getElementName(viewUrl); - - if (bindableNames) { - bindableNames = bindableNames.split(',').map(function (x) { - return x.trim(); - }); - registryEntry.template.removeAttribute('bindable'); - } else { - bindableNames = []; - } - - return _ref = {}, _ref[name] = _createDynamicElement({ name: name, viewUrl: viewUrl, bindableNames: bindableNames, useShadowDOMmode: useShadowDOMmode }), _ref; - }); - } - }); -} \ No newline at end of file diff --git a/dist/native-modules/html-sanitizer.js b/dist/native-modules/html-sanitizer.js deleted file mode 100644 index 3c2f714..0000000 --- a/dist/native-modules/html-sanitizer.js +++ /dev/null @@ -1,24 +0,0 @@ - - -import { getLogger } from 'aurelia-logging'; - -var SCRIPT_REGEX = /)<[^<]*)*<\/script>/gi; -var needsToWarn = true; - -export var HTMLSanitizer = function () { - function HTMLSanitizer() { - - } - - HTMLSanitizer.prototype.sanitize = function sanitize(input) { - if (needsToWarn) { - needsToWarn = false; - - getLogger('html-sanitizer').warn('CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks,\n and should not be relied on for sanitizing input from unknown sources.\n Please see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html.'); - } - - return input.replace(SCRIPT_REGEX, ''); - }; - - return HTMLSanitizer; -}(); \ No newline at end of file diff --git a/dist/native-modules/if-core.js b/dist/native-modules/if-core.js deleted file mode 100644 index 4ef0350..0000000 --- a/dist/native-modules/if-core.js +++ /dev/null @@ -1,91 +0,0 @@ - - -export var IfCore = function () { - function IfCore(viewFactory, viewSlot) { - - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.view = null; - this.bindingContext = null; - this.overrideContext = null; - - this.showing = false; - this.cache = true; - } - - IfCore.prototype.bind = function bind(bindingContext, overrideContext) { - this.bindingContext = bindingContext; - this.overrideContext = overrideContext; - }; - - IfCore.prototype.unbind = function unbind() { - if (this.view === null) { - return; - } - - this.view.unbind(); - - if (!this.viewFactory.isCaching) { - return; - } - - if (this.showing) { - this.showing = false; - this.viewSlot.remove(this.view, true, true); - } else { - this.view.returnToCache(); - } - - this.view = null; - }; - - IfCore.prototype._show = function _show() { - if (this.showing) { - if (!this.view.isBound) { - this.view.bind(this.bindingContext, this.overrideContext); - } - return; - } - - if (this.view === null) { - this.view = this.viewFactory.create(); - } - - if (!this.view.isBound) { - this.view.bind(this.bindingContext, this.overrideContext); - } - - this.showing = true; - return this.viewSlot.add(this.view); - }; - - IfCore.prototype._hide = function _hide() { - var _this = this; - - if (!this.showing) { - return; - } - - this.showing = false; - var removed = this.viewSlot.remove(this.view); - - if (removed instanceof Promise) { - return removed.then(function () { - _this._unbindView(); - }); - } - - this._unbindView(); - }; - - IfCore.prototype._unbindView = function _unbindView() { - var cache = this.cache === 'false' ? false : !!this.cache; - this.view.unbind(); - if (!cache) { - this.view = null; - } - }; - - return IfCore; -}(); \ No newline at end of file diff --git a/dist/native-modules/if.js b/dist/native-modules/if.js deleted file mode 100644 index 7240f94..0000000 --- a/dist/native-modules/if.js +++ /dev/null @@ -1,137 +0,0 @@ -var _dec, _dec2, _dec3, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3; - -function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); -} - - - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; -} - -function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); -} - -import { BoundViewFactory, ViewSlot, bindable, customAttribute, templateController } from 'aurelia-templating'; -import { inject } from 'aurelia-dependency-injection'; -import { IfCore } from './if-core'; - -export var If = (_dec = customAttribute('if'), _dec2 = inject(BoundViewFactory, ViewSlot), _dec3 = bindable({ primaryProperty: true }), _dec(_class = templateController(_class = _dec2(_class = (_class2 = function (_IfCore) { - _inherits(If, _IfCore); - - function If() { - var _temp, _this, _ret; - - - - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - return _ret = (_temp = (_this = _possibleConstructorReturn(this, _IfCore.call.apply(_IfCore, [this].concat(args))), _this), _initDefineProp(_this, 'condition', _descriptor, _this), _initDefineProp(_this, 'swapOrder', _descriptor2, _this), _initDefineProp(_this, 'cache', _descriptor3, _this), _temp), _possibleConstructorReturn(_this, _ret); - } - - If.prototype.bind = function bind(bindingContext, overrideContext) { - _IfCore.prototype.bind.call(this, bindingContext, overrideContext); - if (this.condition) { - this._show(); - } else { - this._hide(); - } - }; - - If.prototype.conditionChanged = function conditionChanged(newValue) { - this._update(newValue); - }; - - If.prototype._update = function _update(show) { - var _this2 = this; - - if (this.animating) { - return; - } - - var promise = void 0; - if (this.elseVm) { - promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm); - } else { - promise = show ? this._show() : this._hide(); - } - - if (promise) { - this.animating = true; - promise.then(function () { - _this2.animating = false; - if (_this2.condition !== _this2.showing) { - _this2._update(_this2.condition); - } - }); - } - }; - - If.prototype._swap = function _swap(remove, add) { - switch (this.swapOrder) { - case 'before': - return Promise.resolve(add._show()).then(function () { - return remove._hide(); - }); - case 'with': - return Promise.all([remove._hide(), add._show()]); - default: - var promise = remove._hide(); - return promise ? promise.then(function () { - return add._show(); - }) : add._show(); - } - }; - - return If; -}(IfCore), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'condition', [_dec3], { - enumerable: true, - initializer: null -}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'swapOrder', [bindable], { - enumerable: true, - initializer: null -}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'cache', [bindable], { - enumerable: true, - initializer: function initializer() { - return true; - } -})), _class2)) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/native-modules/index.js b/dist/native-modules/index.js deleted file mode 100644 index 5d31d56..0000000 --- a/dist/native-modules/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from './aurelia-templating-resources'; \ No newline at end of file diff --git a/dist/native-modules/map-repeat-strategy.js b/dist/native-modules/map-repeat-strategy.js deleted file mode 100644 index fc46715..0000000 --- a/dist/native-modules/map-repeat-strategy.js +++ /dev/null @@ -1,110 +0,0 @@ - - -import { createFullOverrideContext, updateOverrideContexts } from './repeat-utilities'; - -export var MapRepeatStrategy = function () { - function MapRepeatStrategy() { - - } - - MapRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getMapObserver(items); - }; - - MapRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this._standardProcessItems(repeat, items); - }); - return; - } - this._standardProcessItems(repeat, items); - }; - - MapRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, items) { - var index = 0; - var overrideContext = void 0; - - items.forEach(function (value, key) { - overrideContext = createFullOverrideContext(repeat, value, index, items.size, key); - repeat.addView(overrideContext.bindingContext, overrideContext); - ++index; - }); - }; - - MapRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, map, records) { - var key = void 0; - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var removeIndex = void 0; - var addIndex = void 0; - var record = void 0; - var rmPromises = []; - var viewOrPromise = void 0; - - for (i = 0, ii = records.length; i < ii; ++i) { - record = records[i]; - key = record.key; - switch (record.type) { - case 'update': - removeIndex = this._getViewIndexByKey(repeat, key); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - overrideContext = createFullOverrideContext(repeat, map.get(key), removeIndex, map.size, key); - repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext); - break; - case 'add': - addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1; - overrideContext = createFullOverrideContext(repeat, map.get(key), addIndex, map.size, key); - repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext); - break; - case 'delete': - if (record.oldValue === undefined) { - return; - } - removeIndex = this._getViewIndexByKey(repeat, key); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - break; - case 'clear': - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - break; - default: - continue; - } - } - - if (rmPromises.length > 0) { - Promise.all(rmPromises).then(function () { - updateOverrideContexts(repeat.views(), 0); - }); - } else { - updateOverrideContexts(repeat.views(), 0); - } - }; - - MapRepeatStrategy.prototype._getViewIndexByKey = function _getViewIndexByKey(repeat, key) { - var i = void 0; - var ii = void 0; - var child = void 0; - - for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { - child = repeat.view(i); - if (child.bindingContext[repeat.key] === key) { - return i; - } - } - - return undefined; - }; - - return MapRepeatStrategy; -}(); \ No newline at end of file diff --git a/dist/native-modules/null-repeat-strategy.js b/dist/native-modules/null-repeat-strategy.js deleted file mode 100644 index 86434d5..0000000 --- a/dist/native-modules/null-repeat-strategy.js +++ /dev/null @@ -1,15 +0,0 @@ - - -export var NullRepeatStrategy = function () { - function NullRepeatStrategy() { - - } - - NullRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - repeat.removeAllViews(true); - }; - - NullRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) {}; - - return NullRepeatStrategy; -}(); \ No newline at end of file diff --git a/dist/native-modules/number-repeat-strategy.js b/dist/native-modules/number-repeat-strategy.js deleted file mode 100644 index 68ff2e7..0000000 --- a/dist/native-modules/number-repeat-strategy.js +++ /dev/null @@ -1,58 +0,0 @@ - - -import { createFullOverrideContext, updateOverrideContexts } from './repeat-utilities'; - -export var NumberRepeatStrategy = function () { - function NumberRepeatStrategy() { - - } - - NumberRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver() { - return null; - }; - - NumberRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, value) { - var _this = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this._standardProcessItems(repeat, value); - }); - return; - } - this._standardProcessItems(repeat, value); - }; - - NumberRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, value) { - var childrenLength = repeat.viewCount(); - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var viewsToRemove = void 0; - - value = Math.floor(value); - viewsToRemove = childrenLength - value; - - if (viewsToRemove > 0) { - if (viewsToRemove > childrenLength) { - viewsToRemove = childrenLength; - } - - for (i = 0, ii = viewsToRemove; i < ii; ++i) { - repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle); - } - - return; - } - - for (i = childrenLength, ii = value; i < ii; ++i) { - overrideContext = createFullOverrideContext(repeat, i, i, ii); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - - updateOverrideContexts(repeat.views(), 0); - }; - - return NumberRepeatStrategy; -}(); \ No newline at end of file diff --git a/dist/native-modules/repeat-strategy-locator.js b/dist/native-modules/repeat-strategy-locator.js deleted file mode 100644 index 788e9f1..0000000 --- a/dist/native-modules/repeat-strategy-locator.js +++ /dev/null @@ -1,51 +0,0 @@ - - -import { NullRepeatStrategy } from './null-repeat-strategy'; -import { ArrayRepeatStrategy } from './array-repeat-strategy'; -import { MapRepeatStrategy } from './map-repeat-strategy'; -import { SetRepeatStrategy } from './set-repeat-strategy'; -import { NumberRepeatStrategy } from './number-repeat-strategy'; - -export var RepeatStrategyLocator = function () { - function RepeatStrategyLocator() { - - - this.matchers = []; - this.strategies = []; - - this.addStrategy(function (items) { - return items === null || items === undefined; - }, new NullRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Array; - }, new ArrayRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Map; - }, new MapRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Set; - }, new SetRepeatStrategy()); - this.addStrategy(function (items) { - return typeof items === 'number'; - }, new NumberRepeatStrategy()); - } - - RepeatStrategyLocator.prototype.addStrategy = function addStrategy(matcher, strategy) { - this.matchers.push(matcher); - this.strategies.push(strategy); - }; - - RepeatStrategyLocator.prototype.getStrategy = function getStrategy(items) { - var matchers = this.matchers; - - for (var i = 0, ii = matchers.length; i < ii; ++i) { - if (matchers[i](items)) { - return this.strategies[i]; - } - } - - return null; - }; - - return RepeatStrategyLocator; -}(); \ No newline at end of file diff --git a/dist/native-modules/repeat-utilities.js b/dist/native-modules/repeat-utilities.js deleted file mode 100644 index f5d810a..0000000 --- a/dist/native-modules/repeat-utilities.js +++ /dev/null @@ -1,91 +0,0 @@ -import { createOverrideContext, BindingBehavior, ValueConverter, sourceContext, bindingMode } from 'aurelia-binding'; - -var oneTime = bindingMode.oneTime; - -export function updateOverrideContexts(views, startIndex) { - var length = views.length; - - if (startIndex > 0) { - startIndex = startIndex - 1; - } - - for (; startIndex < length; ++startIndex) { - updateOverrideContext(views[startIndex].overrideContext, startIndex, length); - } -} - -export function createFullOverrideContext(repeat, data, index, length, key) { - var bindingContext = {}; - var overrideContext = createOverrideContext(bindingContext, repeat.scope.overrideContext); - - if (typeof key !== 'undefined') { - bindingContext[repeat.key] = key; - bindingContext[repeat.value] = data; - } else { - bindingContext[repeat.local] = data; - } - updateOverrideContext(overrideContext, index, length); - return overrideContext; -} - -export function updateOverrideContext(overrideContext, index, length) { - var first = index === 0; - var last = index === length - 1; - var even = index % 2 === 0; - - overrideContext.$index = index; - overrideContext.$first = first; - overrideContext.$last = last; - overrideContext.$middle = !(first || last); - overrideContext.$odd = !even; - overrideContext.$even = even; -} - -export function getItemsSourceExpression(instruction, attrName) { - return instruction.behaviorInstructions.filter(function (bi) { - return bi.originalAttrName === attrName; - })[0].attributes.items.sourceExpression; -} - -export function unwrapExpression(expression) { - var unwrapped = false; - while (expression instanceof BindingBehavior) { - expression = expression.expression; - } - while (expression instanceof ValueConverter) { - expression = expression.expression; - unwrapped = true; - } - return unwrapped ? expression : null; -} - -export function isOneTime(expression) { - while (expression instanceof BindingBehavior) { - if (expression.name === 'oneTime') { - return true; - } - expression = expression.expression; - } - return false; -} - -export function updateOneTimeBinding(binding) { - if (binding.call && binding.mode === oneTime) { - binding.call(sourceContext); - } else if (binding.updateOneTimeBindings) { - binding.updateOneTimeBindings(); - } -} - -export function indexOf(array, item, matcher, startIndex) { - if (!matcher) { - return array.indexOf(item); - } - var length = array.length; - for (var index = startIndex || 0; index < length; index++) { - if (matcher(array[index], item)) { - return index; - } - } - return -1; -} \ No newline at end of file diff --git a/dist/native-modules/repeat.js b/dist/native-modules/repeat.js deleted file mode 100644 index 1d6a03b..0000000 --- a/dist/native-modules/repeat.js +++ /dev/null @@ -1,303 +0,0 @@ -var _dec, _dec2, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4; - -function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); -} - - - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; -} - -function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); -} - -import { inject } from 'aurelia-dependency-injection'; -import { ObserverLocator } from 'aurelia-binding'; -import { BoundViewFactory, TargetInstruction, ViewSlot, ViewResources, customAttribute, bindable, templateController } from 'aurelia-templating'; -import { RepeatStrategyLocator } from './repeat-strategy-locator'; -import { getItemsSourceExpression, unwrapExpression, isOneTime, updateOneTimeBinding } from './repeat-utilities'; -import { viewsRequireLifecycle } from './analyze-view-factory'; -import { AbstractRepeater } from './abstract-repeater'; - -export var Repeat = (_dec = customAttribute('repeat'), _dec2 = inject(BoundViewFactory, TargetInstruction, ViewSlot, ViewResources, ObserverLocator, RepeatStrategyLocator), _dec(_class = templateController(_class = _dec2(_class = (_class2 = function (_AbstractRepeater) { - _inherits(Repeat, _AbstractRepeater); - - function Repeat(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) { - - - var _this = _possibleConstructorReturn(this, _AbstractRepeater.call(this, { - local: 'item', - viewsRequireLifecycle: viewsRequireLifecycle(viewFactory) - })); - - _initDefineProp(_this, 'items', _descriptor, _this); - - _initDefineProp(_this, 'local', _descriptor2, _this); - - _initDefineProp(_this, 'key', _descriptor3, _this); - - _initDefineProp(_this, 'value', _descriptor4, _this); - - _this.viewFactory = viewFactory; - _this.instruction = instruction; - _this.viewSlot = viewSlot; - _this.lookupFunctions = viewResources.lookupFunctions; - _this.observerLocator = observerLocator; - _this.key = 'key'; - _this.value = 'value'; - _this.strategyLocator = strategyLocator; - _this.ignoreMutation = false; - _this.sourceExpression = getItemsSourceExpression(_this.instruction, 'repeat.for'); - _this.isOneTime = isOneTime(_this.sourceExpression); - _this.viewsRequireLifecycle = viewsRequireLifecycle(viewFactory); - return _this; - } - - Repeat.prototype.call = function call(context, changes) { - this[context](this.items, changes); - }; - - Repeat.prototype.bind = function bind(bindingContext, overrideContext) { - this.scope = { bindingContext: bindingContext, overrideContext: overrideContext }; - this.matcherBinding = this._captureAndRemoveMatcherBinding(); - this.itemsChanged(); - }; - - Repeat.prototype.unbind = function unbind() { - this.scope = null; - this.items = null; - this.matcherBinding = null; - this.viewSlot.removeAll(true, true); - this._unsubscribeCollection(); - }; - - Repeat.prototype._unsubscribeCollection = function _unsubscribeCollection() { - if (this.collectionObserver) { - this.collectionObserver.unsubscribe(this.callContext, this); - this.collectionObserver = null; - this.callContext = null; - } - }; - - Repeat.prototype.itemsChanged = function itemsChanged() { - var _this2 = this; - - this._unsubscribeCollection(); - - if (!this.scope) { - return; - } - - var items = this.items; - this.strategy = this.strategyLocator.getStrategy(items); - if (!this.strategy) { - throw new Error('Value for \'' + this.sourceExpression + '\' is non-repeatable'); - } - - if (!this.isOneTime && !this._observeInnerCollection()) { - this._observeCollection(); - } - this.ignoreMutation = true; - this.strategy.instanceChanged(this, items); - this.observerLocator.taskQueue.queueMicroTask(function () { - _this2.ignoreMutation = false; - }); - }; - - Repeat.prototype._getInnerCollection = function _getInnerCollection() { - var expression = unwrapExpression(this.sourceExpression); - if (!expression) { - return null; - } - return expression.evaluate(this.scope, null); - }; - - Repeat.prototype.handleCollectionMutated = function handleCollectionMutated(collection, changes) { - if (!this.collectionObserver) { - return; - } - if (this.ignoreMutation) { - return; - } - this.strategy.instanceMutated(this, collection, changes); - }; - - Repeat.prototype.handleInnerCollectionMutated = function handleInnerCollectionMutated(collection, changes) { - var _this3 = this; - - if (!this.collectionObserver) { - return; - } - - if (this.ignoreMutation) { - return; - } - this.ignoreMutation = true; - var newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions); - this.observerLocator.taskQueue.queueMicroTask(function () { - return _this3.ignoreMutation = false; - }); - - if (newItems === this.items) { - this.itemsChanged(); - } else { - this.items = newItems; - } - }; - - Repeat.prototype._observeInnerCollection = function _observeInnerCollection() { - var items = this._getInnerCollection(); - var strategy = this.strategyLocator.getStrategy(items); - if (!strategy) { - return false; - } - this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items); - if (!this.collectionObserver) { - return false; - } - this.callContext = 'handleInnerCollectionMutated'; - this.collectionObserver.subscribe(this.callContext, this); - return true; - }; - - Repeat.prototype._observeCollection = function _observeCollection() { - var items = this.items; - this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items); - if (this.collectionObserver) { - this.callContext = 'handleCollectionMutated'; - this.collectionObserver.subscribe(this.callContext, this); - } - }; - - Repeat.prototype._captureAndRemoveMatcherBinding = function _captureAndRemoveMatcherBinding() { - if (this.viewFactory.viewFactory) { - var instructions = this.viewFactory.viewFactory.instructions; - var instructionIds = Object.keys(instructions); - for (var i = 0; i < instructionIds.length; i++) { - var expressions = instructions[instructionIds[i]].expressions; - if (expressions) { - for (var ii = 0; i < expressions.length; i++) { - if (expressions[ii].targetProperty === 'matcher') { - var matcherBinding = expressions[ii]; - expressions.splice(ii, 1); - return matcherBinding; - } - } - } - } - } - - return undefined; - }; - - Repeat.prototype.viewCount = function viewCount() { - return this.viewSlot.children.length; - }; - - Repeat.prototype.views = function views() { - return this.viewSlot.children; - }; - - Repeat.prototype.view = function view(index) { - return this.viewSlot.children[index]; - }; - - Repeat.prototype.matcher = function matcher() { - return this.matcherBinding ? this.matcherBinding.sourceExpression.evaluate(this.scope, this.matcherBinding.lookupFunctions) : null; - }; - - Repeat.prototype.addView = function addView(bindingContext, overrideContext) { - var view = this.viewFactory.create(); - view.bind(bindingContext, overrideContext); - this.viewSlot.add(view); - }; - - Repeat.prototype.insertView = function insertView(index, bindingContext, overrideContext) { - var view = this.viewFactory.create(); - view.bind(bindingContext, overrideContext); - this.viewSlot.insert(index, view); - }; - - Repeat.prototype.moveView = function moveView(sourceIndex, targetIndex) { - this.viewSlot.move(sourceIndex, targetIndex); - }; - - Repeat.prototype.removeAllViews = function removeAllViews(returnToCache, skipAnimation) { - return this.viewSlot.removeAll(returnToCache, skipAnimation); - }; - - Repeat.prototype.removeViews = function removeViews(viewsToRemove, returnToCache, skipAnimation) { - return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation); - }; - - Repeat.prototype.removeView = function removeView(index, returnToCache, skipAnimation) { - return this.viewSlot.removeAt(index, returnToCache, skipAnimation); - }; - - Repeat.prototype.updateBindings = function updateBindings(view) { - var j = view.bindings.length; - while (j--) { - updateOneTimeBinding(view.bindings[j]); - } - j = view.controllers.length; - while (j--) { - var k = view.controllers[j].boundProperties.length; - while (k--) { - var binding = view.controllers[j].boundProperties[k].binding; - updateOneTimeBinding(binding); - } - } - }; - - return Repeat; -}(AbstractRepeater), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'items', [bindable], { - enumerable: true, - initializer: null -}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'local', [bindable], { - enumerable: true, - initializer: null -}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'key', [bindable], { - enumerable: true, - initializer: null -}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, 'value', [bindable], { - enumerable: true, - initializer: null -})), _class2)) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/native-modules/replaceable.js b/dist/native-modules/replaceable.js deleted file mode 100644 index 2062e25..0000000 --- a/dist/native-modules/replaceable.js +++ /dev/null @@ -1,31 +0,0 @@ -var _dec, _dec2, _class; - - - -import { inject } from 'aurelia-dependency-injection'; -import { BoundViewFactory, ViewSlot, customAttribute, templateController } from 'aurelia-templating'; - -export var Replaceable = (_dec = customAttribute('replaceable'), _dec2 = inject(BoundViewFactory, ViewSlot), _dec(_class = templateController(_class = _dec2(_class = function () { - function Replaceable(viewFactory, viewSlot) { - - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.view = null; - } - - Replaceable.prototype.bind = function bind(bindingContext, overrideContext) { - if (this.view === null) { - this.view = this.viewFactory.create(); - this.viewSlot.add(this.view); - } - - this.view.bind(bindingContext, overrideContext); - }; - - Replaceable.prototype.unbind = function unbind() { - this.view.unbind(); - }; - - return Replaceable; -}()) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/native-modules/sanitize-html.js b/dist/native-modules/sanitize-html.js deleted file mode 100644 index 70258a6..0000000 --- a/dist/native-modules/sanitize-html.js +++ /dev/null @@ -1,25 +0,0 @@ -var _dec, _dec2, _class; - - - -import { valueConverter } from 'aurelia-binding'; -import { inject } from 'aurelia-dependency-injection'; -import { HTMLSanitizer } from './html-sanitizer'; - -export var SanitizeHTMLValueConverter = (_dec = valueConverter('sanitizeHTML'), _dec2 = inject(HTMLSanitizer), _dec(_class = _dec2(_class = function () { - function SanitizeHTMLValueConverter(sanitizer) { - - - this.sanitizer = sanitizer; - } - - SanitizeHTMLValueConverter.prototype.toView = function toView(untrustedMarkup) { - if (untrustedMarkup === null || untrustedMarkup === undefined) { - return null; - } - - return this.sanitizer.sanitize(untrustedMarkup); - }; - - return SanitizeHTMLValueConverter; -}()) || _class) || _class); \ No newline at end of file diff --git a/dist/native-modules/self-binding-behavior.js b/dist/native-modules/self-binding-behavior.js deleted file mode 100644 index bd4aac7..0000000 --- a/dist/native-modules/self-binding-behavior.js +++ /dev/null @@ -1,34 +0,0 @@ -var _dec, _class; - - - -import { bindingBehavior } from 'aurelia-binding'; - -function findOriginalEventTarget(event) { - return event.path && event.path[0] || event.deepPath && event.deepPath[0] || event.target; -} - -function handleSelfEvent(event) { - var target = findOriginalEventTarget(event); - if (this.target !== target) return; - this.selfEventCallSource(event); -} - -export var SelfBindingBehavior = (_dec = bindingBehavior('self'), _dec(_class = function () { - function SelfBindingBehavior() { - - } - - SelfBindingBehavior.prototype.bind = function bind(binding, source) { - if (!binding.callSource || !binding.targetEvent) throw new Error('Self binding behavior only supports event.'); - binding.selfEventCallSource = binding.callSource; - binding.callSource = handleSelfEvent; - }; - - SelfBindingBehavior.prototype.unbind = function unbind(binding, source) { - binding.callSource = binding.selfEventCallSource; - binding.selfEventCallSource = null; - }; - - return SelfBindingBehavior; -}()) || _class); \ No newline at end of file diff --git a/dist/native-modules/set-repeat-strategy.js b/dist/native-modules/set-repeat-strategy.js deleted file mode 100644 index 731a310..0000000 --- a/dist/native-modules/set-repeat-strategy.js +++ /dev/null @@ -1,97 +0,0 @@ - - -import { createFullOverrideContext, updateOverrideContexts } from './repeat-utilities'; - -export var SetRepeatStrategy = function () { - function SetRepeatStrategy() { - - } - - SetRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getSetObserver(items); - }; - - SetRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this._standardProcessItems(repeat, items); - }); - return; - } - this._standardProcessItems(repeat, items); - }; - - SetRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, items) { - var index = 0; - var overrideContext = void 0; - - items.forEach(function (value) { - overrideContext = createFullOverrideContext(repeat, value, index, items.size); - repeat.addView(overrideContext.bindingContext, overrideContext); - ++index; - }); - }; - - SetRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, set, records) { - var value = void 0; - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var removeIndex = void 0; - var record = void 0; - var rmPromises = []; - var viewOrPromise = void 0; - - for (i = 0, ii = records.length; i < ii; ++i) { - record = records[i]; - value = record.value; - switch (record.type) { - case 'add': - var size = Math.max(set.size - 1, 0); - overrideContext = createFullOverrideContext(repeat, value, size, set.size); - repeat.insertView(size, overrideContext.bindingContext, overrideContext); - break; - case 'delete': - removeIndex = this._getViewIndexByValue(repeat, value); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - break; - case 'clear': - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - break; - default: - continue; - } - } - - if (rmPromises.length > 0) { - Promise.all(rmPromises).then(function () { - updateOverrideContexts(repeat.views(), 0); - }); - } else { - updateOverrideContexts(repeat.views(), 0); - } - }; - - SetRepeatStrategy.prototype._getViewIndexByValue = function _getViewIndexByValue(repeat, value) { - var i = void 0; - var ii = void 0; - var child = void 0; - - for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { - child = repeat.view(i); - if (child.bindingContext[repeat.local] === value) { - return i; - } - } - - return undefined; - }; - - return SetRepeatStrategy; -}(); \ No newline at end of file diff --git a/dist/native-modules/show.js b/dist/native-modules/show.js deleted file mode 100644 index ef8ecee..0000000 --- a/dist/native-modules/show.js +++ /dev/null @@ -1,40 +0,0 @@ -var _dec, _class; - - - -import { Optional } from 'aurelia-dependency-injection'; -import { customAttribute, Animator } from 'aurelia-templating'; -import { DOM } from 'aurelia-pal'; -import { injectAureliaHideStyleAtBoundary, aureliaHideClassName } from './aurelia-hide-style'; - -export var Show = (_dec = customAttribute('show'), _dec(_class = function () { - Show.inject = function inject() { - return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; - }; - - function Show(element, animator, domBoundary) { - - - this.element = element; - this.animator = animator; - this.domBoundary = domBoundary; - } - - Show.prototype.created = function created() { - injectAureliaHideStyleAtBoundary(this.domBoundary); - }; - - Show.prototype.valueChanged = function valueChanged(newValue) { - if (newValue) { - this.animator.removeClass(this.element, aureliaHideClassName); - } else { - this.animator.addClass(this.element, aureliaHideClassName); - } - }; - - Show.prototype.bind = function bind(bindingContext) { - this.valueChanged(this.value); - }; - - return Show; -}()) || _class); \ No newline at end of file diff --git a/dist/native-modules/signal-binding-behavior.js b/dist/native-modules/signal-binding-behavior.js deleted file mode 100644 index 59164b7..0000000 --- a/dist/native-modules/signal-binding-behavior.js +++ /dev/null @@ -1,64 +0,0 @@ -var _dec, _class; - - - -import { bindingBehavior } from 'aurelia-binding'; -import { BindingSignaler } from './binding-signaler'; - -export var SignalBindingBehavior = (_dec = bindingBehavior('signal'), _dec(_class = function () { - SignalBindingBehavior.inject = function inject() { - return [BindingSignaler]; - }; - - function SignalBindingBehavior(bindingSignaler) { - - - this.signals = bindingSignaler.signals; - } - - SignalBindingBehavior.prototype.bind = function bind(binding, source) { - if (!binding.updateTarget) { - throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.'); - } - - for (var _len = arguments.length, names = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { - names[_key - 2] = arguments[_key]; - } - - if (names.length === 1) { - var name = names[0]; - var bindings = this.signals[name] || (this.signals[name] = []); - bindings.push(binding); - binding.signalName = name; - } else if (names.length > 1) { - var i = names.length; - while (i--) { - var _name = names[i]; - var _bindings = this.signals[_name] || (this.signals[_name] = []); - _bindings.push(binding); - } - binding.signalName = names; - } else { - throw new Error('Signal name is required.'); - } - }; - - SignalBindingBehavior.prototype.unbind = function unbind(binding, source) { - var name = binding.signalName; - binding.signalName = null; - if (Array.isArray(name)) { - var _names = name; - var i = _names.length; - while (i--) { - var n = _names[i]; - var bindings = this.signals[n]; - bindings.splice(bindings.indexOf(binding), 1); - } - } else { - var _bindings2 = this.signals[name]; - _bindings2.splice(_bindings2.indexOf(binding), 1); - } - }; - - return SignalBindingBehavior; -}()) || _class); \ No newline at end of file diff --git a/dist/native-modules/throttle-binding-behavior.js b/dist/native-modules/throttle-binding-behavior.js deleted file mode 100644 index eb16b0e..0000000 --- a/dist/native-modules/throttle-binding-behavior.js +++ /dev/null @@ -1,65 +0,0 @@ -var _dec, _class; - - - -import { bindingMode, bindingBehavior } from 'aurelia-binding'; - -function throttle(newValue) { - var _this = this; - - var state = this.throttleState; - var elapsed = +new Date() - state.last; - if (elapsed >= state.delay) { - clearTimeout(state.timeoutId); - state.timeoutId = null; - state.last = +new Date(); - this.throttledMethod(newValue); - return; - } - state.newValue = newValue; - if (state.timeoutId === null) { - state.timeoutId = setTimeout(function () { - state.timeoutId = null; - state.last = +new Date(); - _this.throttledMethod(state.newValue); - }, state.delay - elapsed); - } -} - -export var ThrottleBindingBehavior = (_dec = bindingBehavior('throttle'), _dec(_class = function () { - function ThrottleBindingBehavior() { - - } - - ThrottleBindingBehavior.prototype.bind = function bind(binding, source) { - var delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200; - - var methodToThrottle = 'updateTarget'; - if (binding.callSource) { - methodToThrottle = 'callSource'; - } else if (binding.updateSource && binding.mode === bindingMode.twoWay) { - methodToThrottle = 'updateSource'; - } - - binding.throttledMethod = binding[methodToThrottle]; - binding.throttledMethod.originalName = methodToThrottle; - - binding[methodToThrottle] = throttle; - - binding.throttleState = { - delay: delay, - last: 0, - timeoutId: null - }; - }; - - ThrottleBindingBehavior.prototype.unbind = function unbind(binding, source) { - var methodToRestore = binding.throttledMethod.originalName; - binding[methodToRestore] = binding.throttledMethod; - binding.throttledMethod = null; - clearTimeout(binding.throttleState.timeoutId); - binding.throttleState = null; - }; - - return ThrottleBindingBehavior; -}()) || _class); \ No newline at end of file diff --git a/dist/native-modules/update-trigger-binding-behavior.js b/dist/native-modules/update-trigger-binding-behavior.js deleted file mode 100644 index 08f82a0..0000000 --- a/dist/native-modules/update-trigger-binding-behavior.js +++ /dev/null @@ -1,46 +0,0 @@ -var _dec, _class; - - - -import { bindingMode, EventSubscriber, bindingBehavior } from 'aurelia-binding'; - -var eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg '; -var notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.'; - -export var UpdateTriggerBindingBehavior = (_dec = bindingBehavior('updateTrigger'), _dec(_class = function () { - function UpdateTriggerBindingBehavior() { - - } - - UpdateTriggerBindingBehavior.prototype.bind = function bind(binding, source) { - for (var _len = arguments.length, events = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { - events[_key - 2] = arguments[_key]; - } - - if (events.length === 0) { - throw new Error(eventNamesRequired); - } - if (binding.mode !== bindingMode.twoWay && binding.mode !== bindingMode.fromView) { - throw new Error(notApplicableMessage); - } - - var targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty); - if (!targetObserver.handler) { - throw new Error(notApplicableMessage); - } - binding.targetObserver = targetObserver; - - targetObserver.originalHandler = binding.targetObserver.handler; - - var handler = new EventSubscriber(events); - targetObserver.handler = handler; - }; - - UpdateTriggerBindingBehavior.prototype.unbind = function unbind(binding, source) { - binding.targetObserver.handler.dispose(); - binding.targetObserver.handler = binding.targetObserver.originalHandler; - binding.targetObserver.originalHandler = null; - }; - - return UpdateTriggerBindingBehavior; -}()) || _class); \ No newline at end of file diff --git a/dist/native-modules/with.js b/dist/native-modules/with.js deleted file mode 100644 index f5a0ce6..0000000 --- a/dist/native-modules/with.js +++ /dev/null @@ -1,44 +0,0 @@ -var _dec, _dec2, _class; - - - -import { inject } from 'aurelia-dependency-injection'; -import { BoundViewFactory, ViewSlot, customAttribute, templateController } from 'aurelia-templating'; -import { createOverrideContext } from 'aurelia-binding'; - -export var With = (_dec = customAttribute('with'), _dec2 = inject(BoundViewFactory, ViewSlot), _dec(_class = templateController(_class = _dec2(_class = function () { - function With(viewFactory, viewSlot) { - - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.parentOverrideContext = null; - this.view = null; - } - - With.prototype.bind = function bind(bindingContext, overrideContext) { - this.parentOverrideContext = overrideContext; - this.valueChanged(this.value); - }; - - With.prototype.valueChanged = function valueChanged(newValue) { - var overrideContext = createOverrideContext(newValue, this.parentOverrideContext); - if (!this.view) { - this.view = this.viewFactory.create(); - this.view.bind(newValue, overrideContext); - this.viewSlot.add(this.view); - } else { - this.view.bind(newValue, overrideContext); - } - }; - - With.prototype.unbind = function unbind() { - this.parentOverrideContext = null; - - if (this.view) { - this.view.unbind(); - } - }; - - return With; -}()) || _class) || _class) || _class); \ No newline at end of file diff --git a/dist/system/abstract-repeater.js b/dist/system/abstract-repeater.js deleted file mode 100644 index 5170d92..0000000 --- a/dist/system/abstract-repeater.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; - -System.register([], function (_export, _context) { - "use strict"; - - var AbstractRepeater; - - - - return { - setters: [], - execute: function () { - _export('AbstractRepeater', AbstractRepeater = function () { - function AbstractRepeater(options) { - - - Object.assign(this, { - local: 'items', - viewsRequireLifecycle: true - }, options); - } - - AbstractRepeater.prototype.viewCount = function viewCount() { - throw new Error('subclass must implement `viewCount`'); - }; - - AbstractRepeater.prototype.views = function views() { - throw new Error('subclass must implement `views`'); - }; - - AbstractRepeater.prototype.view = function view(index) { - throw new Error('subclass must implement `view`'); - }; - - AbstractRepeater.prototype.matcher = function matcher() { - throw new Error('subclass must implement `matcher`'); - }; - - AbstractRepeater.prototype.addView = function addView(bindingContext, overrideContext) { - throw new Error('subclass must implement `addView`'); - }; - - AbstractRepeater.prototype.insertView = function insertView(index, bindingContext, overrideContext) { - throw new Error('subclass must implement `insertView`'); - }; - - AbstractRepeater.prototype.moveView = function moveView(sourceIndex, targetIndex) { - throw new Error('subclass must implement `moveView`'); - }; - - AbstractRepeater.prototype.removeAllViews = function removeAllViews(returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeAllViews`'); - }; - - AbstractRepeater.prototype.removeViews = function removeViews(viewsToRemove, returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeView`'); - }; - - AbstractRepeater.prototype.removeView = function removeView(index, returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeView`'); - }; - - AbstractRepeater.prototype.updateBindings = function updateBindings(view) { - throw new Error('subclass must implement `updateBindings`'); - }; - - return AbstractRepeater; - }()); - - _export('AbstractRepeater', AbstractRepeater); - } - }; -}); \ No newline at end of file diff --git a/dist/system/analyze-view-factory.js b/dist/system/analyze-view-factory.js deleted file mode 100644 index f894890..0000000 --- a/dist/system/analyze-view-factory.js +++ /dev/null @@ -1,67 +0,0 @@ -'use strict'; - -System.register([], function (_export, _context) { - "use strict"; - - var lifecycleOptionalBehaviors; - - - function behaviorRequiresLifecycle(instruction) { - var t = instruction.type; - var name = t.elementName !== null ? t.elementName : t.attributeName; - return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind) || t.viewFactory && viewsRequireLifecycle(t.viewFactory) || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); - } - - function targetRequiresLifecycle(instruction) { - var behaviors = instruction.behaviorInstructions; - if (behaviors) { - var i = behaviors.length; - while (i--) { - if (behaviorRequiresLifecycle(behaviors[i])) { - return true; - } - } - } - - return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); - } - - function viewsRequireLifecycle(viewFactory) { - if ('_viewsRequireLifecycle' in viewFactory) { - return viewFactory._viewsRequireLifecycle; - } - - viewFactory._viewsRequireLifecycle = false; - - if (viewFactory.viewFactory) { - viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory); - return viewFactory._viewsRequireLifecycle; - } - - if (viewFactory.template.querySelector('.au-animate')) { - viewFactory._viewsRequireLifecycle = true; - return true; - } - - for (var id in viewFactory.instructions) { - if (targetRequiresLifecycle(viewFactory.instructions[id])) { - viewFactory._viewsRequireLifecycle = true; - return true; - } - } - - viewFactory._viewsRequireLifecycle = false; - return false; - } - - _export('viewsRequireLifecycle', viewsRequireLifecycle); - - return { - setters: [], - execute: function () { - _export('lifecycleOptionalBehaviors', lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with']); - - _export('lifecycleOptionalBehaviors', lifecycleOptionalBehaviors); - } - }; -}); \ No newline at end of file diff --git a/dist/system/array-repeat-strategy.js b/dist/system/array-repeat-strategy.js deleted file mode 100644 index ba36cf9..0000000 --- a/dist/system/array-repeat-strategy.js +++ /dev/null @@ -1,252 +0,0 @@ -'use strict'; - -System.register(['./repeat-utilities', 'aurelia-binding'], function (_export, _context) { - "use strict"; - - var createFullOverrideContext, updateOverrideContexts, updateOverrideContext, indexOf, mergeSplice, ArrayRepeatStrategy; - - - - return { - setters: [function (_repeatUtilities) { - createFullOverrideContext = _repeatUtilities.createFullOverrideContext; - updateOverrideContexts = _repeatUtilities.updateOverrideContexts; - updateOverrideContext = _repeatUtilities.updateOverrideContext; - indexOf = _repeatUtilities.indexOf; - }, function (_aureliaBinding) { - mergeSplice = _aureliaBinding.mergeSplice; - }], - execute: function () { - _export('ArrayRepeatStrategy', ArrayRepeatStrategy = function () { - function ArrayRepeatStrategy() { - - } - - ArrayRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getArrayObserver(items); - }; - - ArrayRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this = this; - - var itemsLength = items.length; - - if (!items || itemsLength === 0) { - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - return; - } - - var children = repeat.views(); - var viewsLength = children.length; - - if (viewsLength === 0) { - this._standardProcessInstanceChanged(repeat, items); - return; - } - - if (repeat.viewsRequireLifecycle) { - var childrenSnapshot = children.slice(0); - var itemNameInBindingContext = repeat.local; - var matcher = repeat.matcher(); - - var itemsPreviouslyInViews = []; - var viewsToRemove = []; - - for (var index = 0; index < viewsLength; index++) { - var view = childrenSnapshot[index]; - var oldItem = view.bindingContext[itemNameInBindingContext]; - - if (indexOf(items, oldItem, matcher) === -1) { - viewsToRemove.push(view); - } else { - itemsPreviouslyInViews.push(oldItem); - } - } - - var updateViews = void 0; - var removePromise = void 0; - - if (itemsPreviouslyInViews.length > 0) { - removePromise = repeat.removeViews(viewsToRemove, true, !repeat.viewsRequireLifecycle); - updateViews = function updateViews() { - for (var _index = 0; _index < itemsLength; _index++) { - var item = items[_index]; - var indexOfView = indexOf(itemsPreviouslyInViews, item, matcher, _index); - var _view = void 0; - - if (indexOfView === -1) { - var overrideContext = createFullOverrideContext(repeat, items[_index], _index, itemsLength); - repeat.insertView(_index, overrideContext.bindingContext, overrideContext); - - itemsPreviouslyInViews.splice(_index, 0, undefined); - } else if (indexOfView === _index) { - _view = children[indexOfView]; - itemsPreviouslyInViews[indexOfView] = undefined; - } else { - _view = children[indexOfView]; - repeat.moveView(indexOfView, _index); - itemsPreviouslyInViews.splice(indexOfView, 1); - itemsPreviouslyInViews.splice(_index, 0, undefined); - } - - if (_view) { - updateOverrideContext(_view.overrideContext, _index, itemsLength); - } - } - - _this._inPlaceProcessItems(repeat, items); - }; - } else { - removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - updateViews = function updateViews() { - return _this._standardProcessInstanceChanged(repeat, items); - }; - } - - if (removePromise instanceof Promise) { - removePromise.then(updateViews); - } else { - updateViews(); - } - } else { - this._inPlaceProcessItems(repeat, items); - } - }; - - ArrayRepeatStrategy.prototype._standardProcessInstanceChanged = function _standardProcessInstanceChanged(repeat, items) { - for (var i = 0, ii = items.length; i < ii; i++) { - var overrideContext = createFullOverrideContext(repeat, items[i], i, ii); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - }; - - ArrayRepeatStrategy.prototype._inPlaceProcessItems = function _inPlaceProcessItems(repeat, items) { - var itemsLength = items.length; - var viewsLength = repeat.viewCount(); - - while (viewsLength > itemsLength) { - viewsLength--; - repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle); - } - - var local = repeat.local; - - for (var i = 0; i < viewsLength; i++) { - var view = repeat.view(i); - var last = i === itemsLength - 1; - var middle = i !== 0 && !last; - - if (view.bindingContext[local] === items[i] && view.overrideContext.$middle === middle && view.overrideContext.$last === last) { - continue; - } - - view.bindingContext[local] = items[i]; - view.overrideContext.$middle = middle; - view.overrideContext.$last = last; - repeat.updateBindings(view); - } - - for (var _i = viewsLength; _i < itemsLength; _i++) { - var overrideContext = createFullOverrideContext(repeat, items[_i], _i, itemsLength); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - }; - - ArrayRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, array, splices) { - var _this2 = this; - - if (repeat.__queuedSplices) { - for (var i = 0, ii = splices.length; i < ii; ++i) { - var _splices$i = splices[i], - index = _splices$i.index, - removed = _splices$i.removed, - addedCount = _splices$i.addedCount; - - mergeSplice(repeat.__queuedSplices, index, removed, addedCount); - } - - repeat.__array = array.slice(0); - return; - } - - var maybePromise = this._runSplices(repeat, array.slice(0), splices); - if (maybePromise instanceof Promise) { - var queuedSplices = repeat.__queuedSplices = []; - - var runQueuedSplices = function runQueuedSplices() { - if (!queuedSplices.length) { - repeat.__queuedSplices = undefined; - repeat.__array = undefined; - return; - } - - var nextPromise = _this2._runSplices(repeat, repeat.__array, queuedSplices) || Promise.resolve(); - queuedSplices = repeat.__queuedSplices = []; - nextPromise.then(runQueuedSplices); - }; - - maybePromise.then(runQueuedSplices); - } - }; - - ArrayRepeatStrategy.prototype._runSplices = function _runSplices(repeat, array, splices) { - var _this3 = this; - - var removeDelta = 0; - var rmPromises = []; - - for (var i = 0, ii = splices.length; i < ii; ++i) { - var splice = splices[i]; - var removed = splice.removed; - - for (var j = 0, jj = removed.length; j < jj; ++j) { - var viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - } - removeDelta -= splice.addedCount; - } - - if (rmPromises.length > 0) { - return Promise.all(rmPromises).then(function () { - var spliceIndexLow = _this3._handleAddedSplices(repeat, array, splices); - updateOverrideContexts(repeat.views(), spliceIndexLow); - }); - } - - var spliceIndexLow = this._handleAddedSplices(repeat, array, splices); - updateOverrideContexts(repeat.views(), spliceIndexLow); - - return undefined; - }; - - ArrayRepeatStrategy.prototype._handleAddedSplices = function _handleAddedSplices(repeat, array, splices) { - var spliceIndex = void 0; - var spliceIndexLow = void 0; - var arrayLength = array.length; - for (var i = 0, ii = splices.length; i < ii; ++i) { - var splice = splices[i]; - var addIndex = spliceIndex = splice.index; - var end = splice.index + splice.addedCount; - - if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) { - spliceIndexLow = spliceIndex; - } - - for (; addIndex < end; ++addIndex) { - var overrideContext = createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength); - repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext); - } - } - - return spliceIndexLow; - }; - - return ArrayRepeatStrategy; - }()); - - _export('ArrayRepeatStrategy', ArrayRepeatStrategy); - } - }; -}); \ No newline at end of file diff --git a/dist/system/attr-binding-behavior.js b/dist/system/attr-binding-behavior.js deleted file mode 100644 index 91ab339..0000000 --- a/dist/system/attr-binding-behavior.js +++ /dev/null @@ -1,33 +0,0 @@ -'use strict'; - -System.register(['aurelia-binding'], function (_export, _context) { - "use strict"; - - var DataAttributeObserver, bindingBehavior, _dec, _class, AttrBindingBehavior; - - - - return { - setters: [function (_aureliaBinding) { - DataAttributeObserver = _aureliaBinding.DataAttributeObserver; - bindingBehavior = _aureliaBinding.bindingBehavior; - }], - execute: function () { - _export('AttrBindingBehavior', AttrBindingBehavior = (_dec = bindingBehavior('attr'), _dec(_class = function () { - function AttrBindingBehavior() { - - } - - AttrBindingBehavior.prototype.bind = function bind(binding, source) { - binding.targetObserver = new DataAttributeObserver(binding.target, binding.targetProperty); - }; - - AttrBindingBehavior.prototype.unbind = function unbind(binding, source) {}; - - return AttrBindingBehavior; - }()) || _class)); - - _export('AttrBindingBehavior', AttrBindingBehavior); - } - }; -}); \ No newline at end of file diff --git a/dist/system/aurelia-hide-style.js b/dist/system/aurelia-hide-style.js deleted file mode 100644 index 09a3ee5..0000000 --- a/dist/system/aurelia-hide-style.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; - -System.register(['aurelia-pal'], function (_export, _context) { - "use strict"; - - var FEATURE, DOM, aureliaHideClassName, aureliaHideClass; - function injectAureliaHideStyleAtHead() { - DOM.injectStyles(aureliaHideClass); - } - - _export('injectAureliaHideStyleAtHead', injectAureliaHideStyleAtHead); - - function injectAureliaHideStyleAtBoundary(domBoundary) { - if (FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) { - domBoundary.hasAureliaHideStyle = true; - DOM.injectStyles(aureliaHideClass, domBoundary); - } - } - - _export('injectAureliaHideStyleAtBoundary', injectAureliaHideStyleAtBoundary); - - return { - setters: [function (_aureliaPal) { - FEATURE = _aureliaPal.FEATURE; - DOM = _aureliaPal.DOM; - }], - execute: function () { - _export('aureliaHideClassName', aureliaHideClassName = 'aurelia-hide'); - - _export('aureliaHideClassName', aureliaHideClassName); - - aureliaHideClass = '.' + aureliaHideClassName + ' { display:none !important; }'; - } - }; -}); \ No newline at end of file diff --git a/dist/system/aurelia-templating-resources.js b/dist/system/aurelia-templating-resources.js index 78727f8..b20828a 100644 --- a/dist/system/aurelia-templating-resources.js +++ b/dist/system/aurelia-templating-resources.js @@ -1,181 +1,1938 @@ -'use strict'; +System.register(['aurelia-dependency-injection', 'aurelia-pal', 'aurelia-task-queue', 'aurelia-templating', 'aurelia-binding', 'aurelia-logging', 'aurelia-loader', 'aurelia-path', 'aurelia-metadata'], function (exports, module) { + 'use strict'; + var Container, inject, Optional, DOM, FEATURE, TaskQueue, CompositionEngine, ViewSlot, ViewResources, bindable, noView, customElement, customAttribute, templateController, BoundViewFactory, TargetInstruction, Animator, resource, useView, useShadowDOM, ViewEngine, createOverrideContext, bindingMode, BindingBehavior, ValueConverter, sourceContext, mergeSplice, ObserverLocator, valueConverter, DataAttributeObserver, bindingBehavior, targetContext, EventSubscriber, getLogger, Loader, relativeToFile, mixin; + return { + setters: [function (module) { + Container = module.Container; + inject = module.inject; + Optional = module.Optional; + }, function (module) { + DOM = module.DOM; + FEATURE = module.FEATURE; + }, function (module) { + TaskQueue = module.TaskQueue; + }, function (module) { + CompositionEngine = module.CompositionEngine; + ViewSlot = module.ViewSlot; + ViewResources = module.ViewResources; + bindable = module.bindable; + noView = module.noView; + customElement = module.customElement; + customAttribute = module.customAttribute; + templateController = module.templateController; + BoundViewFactory = module.BoundViewFactory; + TargetInstruction = module.TargetInstruction; + Animator = module.Animator; + resource = module.resource; + useView = module.useView; + useShadowDOM = module.useShadowDOM; + ViewEngine = module.ViewEngine; + }, function (module) { + createOverrideContext = module.createOverrideContext; + bindingMode = module.bindingMode; + BindingBehavior = module.BindingBehavior; + ValueConverter = module.ValueConverter; + sourceContext = module.sourceContext; + mergeSplice = module.mergeSplice; + ObserverLocator = module.ObserverLocator; + valueConverter = module.valueConverter; + DataAttributeObserver = module.DataAttributeObserver; + bindingBehavior = module.bindingBehavior; + targetContext = module.targetContext; + EventSubscriber = module.EventSubscriber; + }, function (module) { + getLogger = module.getLogger; + }, function (module) { + Loader = module.Loader; + }, function (module) { + relativeToFile = module.relativeToFile; + }, function (module) { + mixin = module.mixin; + }], + execute: function () { -System.register(['./compose', './if', './else', './with', './repeat', './show', './hide', './sanitize-html', './replaceable', './focus', 'aurelia-templating', './css-resource', './html-sanitizer', './attr-binding-behavior', './binding-mode-behaviors', './throttle-binding-behavior', './debounce-binding-behavior', './self-binding-behavior', './signal-binding-behavior', './binding-signaler', './update-trigger-binding-behavior', './abstract-repeater', './repeat-strategy-locator', './html-resource-plugin', './null-repeat-strategy', './array-repeat-strategy', './map-repeat-strategy', './set-repeat-strategy', './number-repeat-strategy', './repeat-utilities', './analyze-view-factory', './aurelia-hide-style'], function (_export, _context) { - "use strict"; + exports({ + configure: configure$1, + createFullOverrideContext: createFullOverrideContext, + getItemsSourceExpression: getItemsSourceExpression, + isOneTime: isOneTime, + unwrapExpression: unwrapExpression, + updateOneTimeBinding: updateOneTimeBinding, + updateOverrideContext: updateOverrideContext, + viewsRequireLifecycle: viewsRequireLifecycle + }); - var Compose, If, Else, With, Repeat, Show, Hide, SanitizeHTMLValueConverter, Replaceable, Focus, ViewEngine, _createCSSResource, HTMLSanitizer, AttrBindingBehavior, OneTimeBindingBehavior, OneWayBindingBehavior, TwoWayBindingBehavior, FromViewBindingBehavior, ToViewBindingBehavior, ThrottleBindingBehavior, DebounceBindingBehavior, SelfBindingBehavior, SignalBindingBehavior, BindingSignaler, UpdateTriggerBindingBehavior, AbstractRepeater, RepeatStrategyLocator, configureHtmlResourcePlugin, NullRepeatStrategy, ArrayRepeatStrategy, MapRepeatStrategy, SetRepeatStrategy, NumberRepeatStrategy, createFullOverrideContext, updateOverrideContext, getItemsSourceExpression, isOneTime, updateOneTimeBinding, unwrapExpression, viewsRequireLifecycle, injectAureliaHideStyleAtHead; + /*! ***************************************************************************** + Copyright (c) Microsoft Corporation. All rights reserved. + Licensed under the Apache License, Version 2.0 (the "License"); you may not use + this file except in compliance with the License. You may obtain a copy of the + License at http://www.apache.org/licenses/LICENSE-2.0 + + THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED + WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, + MERCHANTABLITY OR NON-INFRINGEMENT. + + See the Apache Version 2.0 License for specific language governing permissions + and limitations under the License. + ***************************************************************************** */ + /* global Reflect, Promise */ + + var extendStatics = function(d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + + function __extends(d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + } + + function __decorate(decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; + } - function configure(config) { - injectAureliaHideStyleAtHead(); + var Compose = exports('Compose', (function () { + function Compose(element, container, compositionEngine, viewSlot, viewResources, taskQueue) { + this.element = element; + this.container = container; + this.compositionEngine = compositionEngine; + this.viewSlot = viewSlot; + this.viewResources = viewResources; + this.taskQueue = taskQueue; + this.currentController = null; + this.currentViewModel = null; + this.changes = Object.create(null); + } + Compose.inject = function () { + return [DOM.Element, Container, CompositionEngine, ViewSlot, ViewResources, TaskQueue]; + }; + Compose.prototype.created = function (owningView) { + this.owningView = owningView; + }; + Compose.prototype.bind = function (bindingContext, overrideContext) { + this.bindingContext = bindingContext; + this.overrideContext = overrideContext; + var changes = this.changes; + changes.view = this.view; + changes.viewModel = this.viewModel; + changes.model = this.model; + if (!this.pendingTask) { + processChanges(this); + } + }; + Compose.prototype.unbind = function () { + this.changes = Object.create(null); + this.bindingContext = null; + this.overrideContext = null; + var returnToCache = true; + var skipAnimation = true; + this.viewSlot.removeAll(returnToCache, skipAnimation); + }; + Compose.prototype.modelChanged = function (newValue, oldValue) { + this.changes.model = newValue; + requestUpdate(this); + }; + Compose.prototype.viewChanged = function (newValue, oldValue) { + this.changes.view = newValue; + requestUpdate(this); + }; + Compose.prototype.viewModelChanged = function (newValue, oldValue) { + this.changes.viewModel = newValue; + requestUpdate(this); + }; + __decorate([ + bindable + ], Compose.prototype, "model", void 0); + __decorate([ + bindable + ], Compose.prototype, "view", void 0); + __decorate([ + bindable + ], Compose.prototype, "viewModel", void 0); + __decorate([ + bindable + ], Compose.prototype, "swapOrder", void 0); + Compose = __decorate([ + noView, + customElement('compose') + ], Compose); + return Compose; + }())); + function isEmpty(obj) { + for (var _ in obj) { + return false; + } + return true; + } + function tryActivateViewModel(vm, model) { + if (vm && typeof vm.activate === 'function') { + return Promise.resolve(vm.activate(model)); + } + } + function createInstruction(composer, instruction) { + return Object.assign(instruction, { + bindingContext: composer.bindingContext, + overrideContext: composer.overrideContext, + owningView: composer.owningView, + container: composer.container, + viewSlot: composer.viewSlot, + viewResources: composer.viewResources, + currentController: composer.currentController, + host: composer.element, + swapOrder: composer.swapOrder + }); + } + function processChanges(composer) { + var changes = composer.changes; + composer.changes = Object.create(null); + if (!('view' in changes) && !('viewModel' in changes) && ('model' in changes)) { + composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model); + if (!composer.pendingTask) { + return; + } + } + else { + var instruction = { + view: composer.view, + viewModel: composer.currentViewModel || composer.viewModel, + model: composer.model + }; + instruction = Object.assign(instruction, changes); + instruction = createInstruction(composer, instruction); + composer.pendingTask = composer.compositionEngine.compose(instruction).then(function (controller) { + composer.currentController = controller; + composer.currentViewModel = controller ? controller.viewModel : null; + }); + } + composer.pendingTask = composer.pendingTask + .then(function () { + completeCompositionTask(composer); + }, function (reason) { + completeCompositionTask(composer); + throw reason; + }); + } + function completeCompositionTask(composer) { + composer.pendingTask = null; + if (!isEmpty(composer.changes)) { + processChanges(composer); + } + } + function requestUpdate(composer) { + if (composer.pendingTask || composer.updateRequested) { + return; + } + composer.updateRequested = true; + composer.taskQueue.queueMicroTask(function () { + composer.updateRequested = false; + processChanges(composer); + }); + } - config.globalResources(Compose, If, Else, With, Repeat, Show, Hide, Replaceable, Focus, SanitizeHTMLValueConverter, OneTimeBindingBehavior, OneWayBindingBehavior, ToViewBindingBehavior, FromViewBindingBehavior, TwoWayBindingBehavior, ThrottleBindingBehavior, DebounceBindingBehavior, SelfBindingBehavior, SignalBindingBehavior, UpdateTriggerBindingBehavior, AttrBindingBehavior); + var IfCore = (function () { + function IfCore(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.view = null; + this.bindingContext = null; + this.overrideContext = null; + this.showing = false; + this.cache = true; + } + IfCore.prototype.bind = function (bindingContext, overrideContext) { + this.bindingContext = bindingContext; + this.overrideContext = overrideContext; + }; + IfCore.prototype.unbind = function () { + if (this.view === null) { + return; + } + this.view.unbind(); + if (!this.viewFactory.isCaching) { + return; + } + if (this.showing) { + this.showing = false; + this.viewSlot.remove(this.view, true, true); + } + else { + this.view.returnToCache(); + } + this.view = null; + }; + IfCore.prototype._show = function () { + if (this.showing) { + if (!this.view.isBound) { + this.view.bind(this.bindingContext, this.overrideContext); + } + return; + } + if (this.view === null) { + this.view = this.viewFactory.create(); + } + if (!this.view.isBound) { + this.view.bind(this.bindingContext, this.overrideContext); + } + this.showing = true; + return this.viewSlot.add(this.view); + }; + IfCore.prototype._hide = function () { + var _this = this; + if (!this.showing) { + return; + } + this.showing = false; + var removed = this.viewSlot.remove(this.view); + if (removed instanceof Promise) { + return removed.then(function () { + _this._unbindView(); + }); + } + this._unbindView(); + }; + IfCore.prototype._unbindView = function () { + var cache = this.cache === 'false' ? false : !!this.cache; + this.view.unbind(); + if (!cache) { + this.view = null; + } + }; + return IfCore; + }()); - configureHtmlResourcePlugin(config); + var If = exports('If', (function (_super) { + __extends(If, _super); + function If() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.cache = true; + return _this; + } + If.prototype.bind = function (bindingContext, overrideContext) { + _super.prototype.bind.call(this, bindingContext, overrideContext); + if (this.condition) { + this._show(); + } + else { + this._hide(); + } + }; + If.prototype.conditionChanged = function (newValue) { + this._update(newValue); + }; + If.prototype._update = function (show) { + var _this = this; + if (this.animating) { + return; + } + var promise; + if (this.elseVm) { + promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm); + } + else { + promise = show ? this._show() : this._hide(); + } + if (promise) { + this.animating = true; + promise.then(function () { + _this.animating = false; + if (_this.condition !== _this.showing) { + _this._update(_this.condition); + } + }); + } + }; + If.prototype._swap = function (remove, add) { + switch (this.swapOrder) { + case 'before': + return Promise.resolve(add._show()).then(function () { return remove._hide(); }); + case 'with': + return Promise.all([remove._hide(), add._show()]); + default: + var promise = remove._hide(); + return promise ? promise.then(function () { return add._show(); }) : add._show(); + } + }; + __decorate([ + bindable({ primaryProperty: true }) + ], If.prototype, "condition", void 0); + __decorate([ + bindable + ], If.prototype, "swapOrder", void 0); + __decorate([ + bindable + ], If.prototype, "cache", void 0); + If = __decorate([ + customAttribute('if'), + templateController, + inject(BoundViewFactory, ViewSlot) + ], If); + return If; + }(IfCore))); - var viewEngine = config.container.get(ViewEngine); - var styleResourcePlugin = { - fetch: function fetch(address) { - var _ref; + var Else = exports('Else', (function (_super) { + __extends(Else, _super); + function Else(viewFactory, viewSlot) { + var _this = _super.call(this, viewFactory, viewSlot) || this; + _this._registerInIf(); + return _this; + } + Else.prototype.bind = function (bindingContext, overrideContext) { + _super.prototype.bind.call(this, bindingContext, overrideContext); + if (this.ifVm.condition) { + this._hide(); + } + else { + this._show(); + } + }; + Else.prototype._registerInIf = function () { + var previous = this.viewSlot.anchor.previousSibling; + while (previous && !previous.au) { + previous = previous.previousSibling; + } + if (!previous || !previous.au.if) { + throw new Error("Can't find matching If for Else custom attribute."); + } + this.ifVm = previous.au.if.viewModel; + this.ifVm.elseVm = this; + }; + Else = __decorate([ + customAttribute('else'), + templateController, + inject(BoundViewFactory, ViewSlot) + ], Else); + return Else; + }(IfCore))); - return _ref = {}, _ref[address] = _createCSSResource(address), _ref; - } - }; - ['.css', '.less', '.sass', '.scss', '.styl'].forEach(function (ext) { - return viewEngine.addResourcePlugin(ext, styleResourcePlugin); - }); - } - - return { - setters: [function (_compose) { - Compose = _compose.Compose; - }, function (_if) { - If = _if.If; - }, function (_else) { - Else = _else.Else; - }, function (_with) { - With = _with.With; - }, function (_repeat) { - Repeat = _repeat.Repeat; - }, function (_show) { - Show = _show.Show; - }, function (_hide) { - Hide = _hide.Hide; - }, function (_sanitizeHtml) { - SanitizeHTMLValueConverter = _sanitizeHtml.SanitizeHTMLValueConverter; - }, function (_replaceable) { - Replaceable = _replaceable.Replaceable; - }, function (_focus) { - Focus = _focus.Focus; - }, function (_aureliaTemplating) { - ViewEngine = _aureliaTemplating.ViewEngine; - }, function (_cssResource) { - _createCSSResource = _cssResource._createCSSResource; - }, function (_htmlSanitizer) { - HTMLSanitizer = _htmlSanitizer.HTMLSanitizer; - }, function (_attrBindingBehavior) { - AttrBindingBehavior = _attrBindingBehavior.AttrBindingBehavior; - }, function (_bindingModeBehaviors) { - OneTimeBindingBehavior = _bindingModeBehaviors.OneTimeBindingBehavior; - OneWayBindingBehavior = _bindingModeBehaviors.OneWayBindingBehavior; - TwoWayBindingBehavior = _bindingModeBehaviors.TwoWayBindingBehavior; - FromViewBindingBehavior = _bindingModeBehaviors.FromViewBindingBehavior; - ToViewBindingBehavior = _bindingModeBehaviors.ToViewBindingBehavior; - }, function (_throttleBindingBehavior) { - ThrottleBindingBehavior = _throttleBindingBehavior.ThrottleBindingBehavior; - }, function (_debounceBindingBehavior) { - DebounceBindingBehavior = _debounceBindingBehavior.DebounceBindingBehavior; - }, function (_selfBindingBehavior) { - SelfBindingBehavior = _selfBindingBehavior.SelfBindingBehavior; - }, function (_signalBindingBehavior) { - SignalBindingBehavior = _signalBindingBehavior.SignalBindingBehavior; - }, function (_bindingSignaler) { - BindingSignaler = _bindingSignaler.BindingSignaler; - }, function (_updateTriggerBindingBehavior) { - UpdateTriggerBindingBehavior = _updateTriggerBindingBehavior.UpdateTriggerBindingBehavior; - }, function (_abstractRepeater) { - AbstractRepeater = _abstractRepeater.AbstractRepeater; - }, function (_repeatStrategyLocator) { - RepeatStrategyLocator = _repeatStrategyLocator.RepeatStrategyLocator; - }, function (_htmlResourcePlugin) { - configureHtmlResourcePlugin = _htmlResourcePlugin.configure; - }, function (_nullRepeatStrategy) { - NullRepeatStrategy = _nullRepeatStrategy.NullRepeatStrategy; - }, function (_arrayRepeatStrategy) { - ArrayRepeatStrategy = _arrayRepeatStrategy.ArrayRepeatStrategy; - }, function (_mapRepeatStrategy) { - MapRepeatStrategy = _mapRepeatStrategy.MapRepeatStrategy; - }, function (_setRepeatStrategy) { - SetRepeatStrategy = _setRepeatStrategy.SetRepeatStrategy; - }, function (_numberRepeatStrategy) { - NumberRepeatStrategy = _numberRepeatStrategy.NumberRepeatStrategy; - }, function (_repeatUtilities) { - createFullOverrideContext = _repeatUtilities.createFullOverrideContext; - updateOverrideContext = _repeatUtilities.updateOverrideContext; - getItemsSourceExpression = _repeatUtilities.getItemsSourceExpression; - isOneTime = _repeatUtilities.isOneTime; - updateOneTimeBinding = _repeatUtilities.updateOneTimeBinding; - unwrapExpression = _repeatUtilities.unwrapExpression; - }, function (_analyzeViewFactory) { - viewsRequireLifecycle = _analyzeViewFactory.viewsRequireLifecycle; - }, function (_aureliaHideStyle) { - injectAureliaHideStyleAtHead = _aureliaHideStyle.injectAureliaHideStyleAtHead; - }], - execute: function () { - _export('Compose', Compose); - - _export('If', If); - - _export('Else', Else); - - _export('With', With); - - _export('Repeat', Repeat); - - _export('Show', Show); - - _export('Hide', Hide); - - _export('HTMLSanitizer', HTMLSanitizer); - - _export('SanitizeHTMLValueConverter', SanitizeHTMLValueConverter); - - _export('Replaceable', Replaceable); - - _export('Focus', Focus); - - _export('configure', configure); + var With = exports('With', (function () { + function With(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.parentOverrideContext = null; + this.view = null; + } + With.prototype.bind = function (bindingContext, overrideContext) { + this.parentOverrideContext = overrideContext; + this.valueChanged(this.value); + }; + With.prototype.valueChanged = function (newValue) { + var overrideContext = createOverrideContext(newValue, this.parentOverrideContext); + var view = this.view; + if (!view) { + view = this.view = this.viewFactory.create(); + view.bind(newValue, overrideContext); + this.viewSlot.add(view); + } + else { + view.bind(newValue, overrideContext); + } + }; + With.prototype.unbind = function () { + var view = this.view; + this.parentOverrideContext = null; + if (view) { + view.unbind(); + } + }; + With = __decorate([ + customAttribute('with'), + templateController, + inject(BoundViewFactory, ViewSlot) + ], With); + return With; + }())); + + var oneTime = bindingMode.oneTime; + function updateOverrideContexts(views, startIndex) { + var length = views.length; + if (startIndex > 0) { + startIndex = startIndex - 1; + } + for (; startIndex < length; ++startIndex) { + updateOverrideContext(views[startIndex].overrideContext, startIndex, length); + } + } + function createFullOverrideContext(repeat, data, index, length, key) { + var bindingContext = {}; + var overrideContext = createOverrideContext(bindingContext, repeat.scope.overrideContext); + if (typeof key !== 'undefined') { + bindingContext[repeat.key] = key; + bindingContext[repeat.value] = data; + } + else { + bindingContext[repeat.local] = data; + } + updateOverrideContext(overrideContext, index, length); + return overrideContext; + } + function updateOverrideContext(overrideContext, index, length) { + var first = (index === 0); + var last = (index === length - 1); + var even = index % 2 === 0; + overrideContext.$index = index; + overrideContext.$first = first; + overrideContext.$last = last; + overrideContext.$middle = !(first || last); + overrideContext.$odd = !even; + overrideContext.$even = even; + } + function getItemsSourceExpression(instruction, attrName) { + return instruction.behaviorInstructions + .filter(function (bi) { return bi.originalAttrName === attrName; })[0] + .attributes + .items + .sourceExpression; + } + function unwrapExpression(expression) { + var unwrapped = false; + while (expression instanceof BindingBehavior) { + expression = expression.expression; + } + while (expression instanceof ValueConverter) { + expression = expression.expression; + unwrapped = true; + } + return unwrapped ? expression : null; + } + function isOneTime(expression) { + while (expression instanceof BindingBehavior) { + if (expression.name === 'oneTime') { + return true; + } + expression = expression.expression; + } + return false; + } + function updateOneTimeBinding(binding) { + if (binding.call && binding.mode === oneTime) { + binding.call(sourceContext); + } + else if (binding.updateOneTimeBindings) { + binding.updateOneTimeBindings(); + } + } + function indexOf(array, item, matcher, startIndex) { + if (!matcher) { + return array.indexOf(item); + } + var length = array.length; + for (var index = startIndex || 0; index < length; index++) { + if (matcher(array[index], item)) { + return index; + } + } + return -1; + } + + var ArrayRepeatStrategy = exports('ArrayRepeatStrategy', (function () { + function ArrayRepeatStrategy() { + } + ArrayRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + return observerLocator.getArrayObserver(items); + }; + ArrayRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + var _this = this; + var itemsLength = items.length; + if (!items || itemsLength === 0) { + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + return; + } + var children = repeat.views(); + var viewsLength = children.length; + if (viewsLength === 0) { + this._standardProcessInstanceChanged(repeat, items); + return; + } + if (repeat.viewsRequireLifecycle) { + var childrenSnapshot = children.slice(0); + var itemNameInBindingContext = repeat.local; + var matcher_1 = repeat.matcher(); + var itemsPreviouslyInViews_1 = []; + var viewsToRemove = []; + for (var index = 0; index < viewsLength; index++) { + var view = childrenSnapshot[index]; + var oldItem = view.bindingContext[itemNameInBindingContext]; + if (indexOf(items, oldItem, matcher_1) === -1) { + viewsToRemove.push(view); + } + else { + itemsPreviouslyInViews_1.push(oldItem); + } + } + var updateViews = void 0; + var removePromise = void 0; + if (itemsPreviouslyInViews_1.length > 0) { + removePromise = repeat.removeViews(viewsToRemove, true, !repeat.viewsRequireLifecycle); + updateViews = function () { + for (var index = 0; index < itemsLength; index++) { + var item = items[index]; + var indexOfView = indexOf(itemsPreviouslyInViews_1, item, matcher_1, index); + var view = void 0; + if (indexOfView === -1) { + var overrideContext = createFullOverrideContext(repeat, items[index], index, itemsLength); + repeat.insertView(index, overrideContext.bindingContext, overrideContext); + itemsPreviouslyInViews_1.splice(index, 0, undefined); + } + else if (indexOfView === index) { + view = children[indexOfView]; + itemsPreviouslyInViews_1[indexOfView] = undefined; + } + else { + view = children[indexOfView]; + repeat.moveView(indexOfView, index); + itemsPreviouslyInViews_1.splice(indexOfView, 1); + itemsPreviouslyInViews_1.splice(index, 0, undefined); + } + if (view) { + updateOverrideContext(view.overrideContext, index, itemsLength); + } + } + _this._inPlaceProcessItems(repeat, items); + }; + } + else { + removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + updateViews = function () { return _this._standardProcessInstanceChanged(repeat, items); }; + } + if (removePromise instanceof Promise) { + removePromise.then(updateViews); + } + else { + updateViews(); + } + } + else { + this._inPlaceProcessItems(repeat, items); + } + }; + ArrayRepeatStrategy.prototype._standardProcessInstanceChanged = function (repeat, items) { + for (var i = 0, ii = items.length; i < ii; i++) { + var overrideContext = createFullOverrideContext(repeat, items[i], i, ii); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + }; + ArrayRepeatStrategy.prototype._inPlaceProcessItems = function (repeat, items) { + var itemsLength = items.length; + var viewsLength = repeat.viewCount(); + while (viewsLength > itemsLength) { + viewsLength--; + repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle); + } + var local = repeat.local; + for (var i = 0; i < viewsLength; i++) { + var view = repeat.view(i); + var last = i === itemsLength - 1; + var middle = i !== 0 && !last; + var bindingContext = view.bindingContext; + var overrideContext = view.overrideContext; + if (bindingContext[local] === items[i] + && overrideContext.$middle === middle + && overrideContext.$last === last) { + continue; + } + bindingContext[local] = items[i]; + overrideContext.$middle = middle; + overrideContext.$last = last; + repeat.updateBindings(view); + } + for (var i = viewsLength; i < itemsLength; i++) { + var overrideContext = createFullOverrideContext(repeat, items[i], i, itemsLength); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + }; + ArrayRepeatStrategy.prototype.instanceMutated = function (repeat, array, splices) { + var _this = this; + if (repeat.__queuedSplices) { + for (var i = 0, ii = splices.length; i < ii; ++i) { + var _a = splices[i], index = _a.index, removed = _a.removed, addedCount = _a.addedCount; + mergeSplice(repeat.__queuedSplices, index, removed, addedCount); + } + repeat.__array = array.slice(0); + return; + } + var maybePromise = this._runSplices(repeat, array.slice(0), splices); + if (maybePromise instanceof Promise) { + var queuedSplices_1 = repeat.__queuedSplices = []; + var runQueuedSplices_1 = function () { + if (!queuedSplices_1.length) { + repeat.__queuedSplices = undefined; + repeat.__array = undefined; + return; + } + var nextPromise = _this._runSplices(repeat, repeat.__array, queuedSplices_1) || Promise.resolve(); + queuedSplices_1 = repeat.__queuedSplices = []; + nextPromise.then(runQueuedSplices_1); + }; + maybePromise.then(runQueuedSplices_1); + } + }; + ArrayRepeatStrategy.prototype._runSplices = function (repeat, array, splices) { + var _this = this; + var removeDelta = 0; + var rmPromises = []; + for (var i = 0, ii = splices.length; i < ii; ++i) { + var splice = splices[i]; + var removed = splice.removed; + for (var j = 0, jj = removed.length; j < jj; ++j) { + var viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + } + removeDelta -= splice.addedCount; + } + if (rmPromises.length > 0) { + return Promise.all(rmPromises).then(function () { + var spliceIndexLow = _this._handleAddedSplices(repeat, array, splices); + updateOverrideContexts(repeat.views(), spliceIndexLow); + }); + } + var spliceIndexLow = this._handleAddedSplices(repeat, array, splices); + updateOverrideContexts(repeat.views(), spliceIndexLow); + return undefined; + }; + ArrayRepeatStrategy.prototype._handleAddedSplices = function (repeat, array, splices) { + var spliceIndex; + var spliceIndexLow; + var arrayLength = array.length; + for (var i = 0, ii = splices.length; i < ii; ++i) { + var splice = splices[i]; + var addIndex = spliceIndex = splice.index; + var end = splice.index + splice.addedCount; + if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) { + spliceIndexLow = spliceIndex; + } + for (; addIndex < end; ++addIndex) { + var overrideContext = createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength); + repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext); + } + } + return spliceIndexLow; + }; + return ArrayRepeatStrategy; + }())); + + var MapRepeatStrategy = exports('MapRepeatStrategy', (function () { + function MapRepeatStrategy() { + } + MapRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + return observerLocator.getMapObserver(items); + }; + MapRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + var _this = this; + var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(function () { return _this._standardProcessItems(repeat, items); }); + return; + } + this._standardProcessItems(repeat, items); + }; + MapRepeatStrategy.prototype._standardProcessItems = function (repeat, items) { + var index = 0; + var overrideContext; + items.forEach(function (value, key) { + overrideContext = createFullOverrideContext(repeat, value, index, items.size, key); + repeat.addView(overrideContext.bindingContext, overrideContext); + ++index; + }); + }; + MapRepeatStrategy.prototype.instanceMutated = function (repeat, map, records) { + var key; + var i; + var ii; + var overrideContext; + var removeIndex; + var addIndex; + var record; + var rmPromises = []; + var viewOrPromise; + for (i = 0, ii = records.length; i < ii; ++i) { + record = records[i]; + key = record.key; + switch (record.type) { + case 'update': + removeIndex = this._getViewIndexByKey(repeat, key); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + overrideContext = createFullOverrideContext(repeat, map.get(key), removeIndex, map.size, key); + repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext); + break; + case 'add': + addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1; + overrideContext = createFullOverrideContext(repeat, map.get(key), addIndex, map.size, key); + repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext); + break; + case 'delete': + if (record.oldValue === undefined) { + return; + } + removeIndex = this._getViewIndexByKey(repeat, key); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + break; + case 'clear': + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + break; + default: + continue; + } + } + if (rmPromises.length > 0) { + Promise.all(rmPromises).then(function () { + updateOverrideContexts(repeat.views(), 0); + }); + } + else { + updateOverrideContexts(repeat.views(), 0); + } + }; + MapRepeatStrategy.prototype._getViewIndexByKey = function (repeat, key) { + var i; + var ii; + var child; + for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { + child = repeat.view(i); + if (child.bindingContext[repeat.key] === key) { + return i; + } + } + return undefined; + }; + return MapRepeatStrategy; + }())); - _export('AttrBindingBehavior', AttrBindingBehavior); - - _export('OneTimeBindingBehavior', OneTimeBindingBehavior); + var NullRepeatStrategy = exports('NullRepeatStrategy', (function () { + function NullRepeatStrategy() { + } + NullRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + repeat.removeAllViews(true); + }; + NullRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + }; + return NullRepeatStrategy; + }())); - _export('OneWayBindingBehavior', OneWayBindingBehavior); + var NumberRepeatStrategy = exports('NumberRepeatStrategy', (function () { + function NumberRepeatStrategy() { + } + NumberRepeatStrategy.prototype.getCollectionObserver = function () { + return null; + }; + NumberRepeatStrategy.prototype.instanceChanged = function (repeat, value) { + var _this = this; + var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(function () { return _this._standardProcessItems(repeat, value); }); + return; + } + this._standardProcessItems(repeat, value); + }; + NumberRepeatStrategy.prototype._standardProcessItems = function (repeat, value) { + var childrenLength = repeat.viewCount(); + var i; + var ii; + var overrideContext; + var viewsToRemove; + value = Math.floor(value); + viewsToRemove = childrenLength - value; + if (viewsToRemove > 0) { + if (viewsToRemove > childrenLength) { + viewsToRemove = childrenLength; + } + for (i = 0, ii = viewsToRemove; i < ii; ++i) { + repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle); + } + return; + } + for (i = childrenLength, ii = value; i < ii; ++i) { + overrideContext = createFullOverrideContext(repeat, i, i, ii); + repeat.addView(overrideContext.bindingContext, overrideContext); + } + updateOverrideContexts(repeat.views(), 0); + }; + return NumberRepeatStrategy; + }())); - _export('ToViewBindingBehavior', ToViewBindingBehavior); + var SetRepeatStrategy = exports('SetRepeatStrategy', (function () { + function SetRepeatStrategy() { + } + SetRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) { + return observerLocator.getSetObserver(items); + }; + SetRepeatStrategy.prototype.instanceChanged = function (repeat, items) { + var _this = this; + var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + if (removePromise instanceof Promise) { + removePromise.then(function () { return _this._standardProcessItems(repeat, items); }); + return; + } + this._standardProcessItems(repeat, items); + }; + SetRepeatStrategy.prototype._standardProcessItems = function (repeat, items) { + var index = 0; + var overrideContext; + items.forEach(function (value) { + overrideContext = createFullOverrideContext(repeat, value, index, items.size); + repeat.addView(overrideContext.bindingContext, overrideContext); + ++index; + }); + }; + SetRepeatStrategy.prototype.instanceMutated = function (repeat, set, records) { + var value; + var i; + var ii; + var overrideContext; + var removeIndex; + var record; + var rmPromises = []; + var viewOrPromise; + for (i = 0, ii = records.length; i < ii; ++i) { + record = records[i]; + value = record.value; + switch (record.type) { + case 'add': + var size = Math.max(set.size - 1, 0); + overrideContext = createFullOverrideContext(repeat, value, size, set.size); + repeat.insertView(size, overrideContext.bindingContext, overrideContext); + break; + case 'delete': + removeIndex = this._getViewIndexByValue(repeat, value); + viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); + if (viewOrPromise instanceof Promise) { + rmPromises.push(viewOrPromise); + } + break; + case 'clear': + repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); + break; + default: + continue; + } + } + if (rmPromises.length > 0) { + Promise.all(rmPromises).then(function () { + updateOverrideContexts(repeat.views(), 0); + }); + } + else { + updateOverrideContexts(repeat.views(), 0); + } + }; + SetRepeatStrategy.prototype._getViewIndexByValue = function (repeat, value) { + var i; + var ii; + var child; + for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { + child = repeat.view(i); + if (child.bindingContext[repeat.local] === value) { + return i; + } + } + return undefined; + }; + return SetRepeatStrategy; + }())); - _export('FromViewBindingBehavior', FromViewBindingBehavior); + var RepeatStrategyLocator = exports('RepeatStrategyLocator', (function () { + function RepeatStrategyLocator() { + this.matchers = []; + this.strategies = []; + this.addStrategy(function (items) { return items === null || items === undefined; }, new NullRepeatStrategy()); + this.addStrategy(function (items) { return items instanceof Array; }, new ArrayRepeatStrategy()); + this.addStrategy(function (items) { return items instanceof Map; }, new MapRepeatStrategy()); + this.addStrategy(function (items) { return items instanceof Set; }, new SetRepeatStrategy()); + this.addStrategy(function (items) { return typeof items === 'number'; }, new NumberRepeatStrategy()); + } + RepeatStrategyLocator.prototype.addStrategy = function (matcher, strategy) { + this.matchers.push(matcher); + this.strategies.push(strategy); + }; + RepeatStrategyLocator.prototype.getStrategy = function (items) { + var matchers = this.matchers; + for (var i = 0, ii = matchers.length; i < ii; ++i) { + if (matchers[i](items)) { + return this.strategies[i]; + } + } + return null; + }; + return RepeatStrategyLocator; + }())); - _export('TwoWayBindingBehavior', TwoWayBindingBehavior); + var lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with']; + function behaviorRequiresLifecycle(instruction) { + var t = instruction.type; + var name = t.elementName !== null ? t.elementName : t.attributeName; + return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind) + || t.viewFactory && viewsRequireLifecycle(t.viewFactory) + || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); + } + function targetRequiresLifecycle(instruction) { + var behaviors = instruction.behaviorInstructions; + if (behaviors) { + var i = behaviors.length; + while (i--) { + if (behaviorRequiresLifecycle(behaviors[i])) { + return true; + } + } + } + return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); + } + function viewsRequireLifecycle(viewFactory) { + if ('_viewsRequireLifecycle' in viewFactory) { + return viewFactory._viewsRequireLifecycle; + } + viewFactory._viewsRequireLifecycle = false; + if (viewFactory.viewFactory) { + viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory); + return viewFactory._viewsRequireLifecycle; + } + if (viewFactory.template.querySelector('.au-animate')) { + viewFactory._viewsRequireLifecycle = true; + return true; + } + for (var id in viewFactory.instructions) { + if (targetRequiresLifecycle(viewFactory.instructions[id])) { + viewFactory._viewsRequireLifecycle = true; + return true; + } + } + viewFactory._viewsRequireLifecycle = false; + return false; + } - _export('ThrottleBindingBehavior', ThrottleBindingBehavior); + var AbstractRepeater = exports('AbstractRepeater', (function () { + function AbstractRepeater(options) { + Object.assign(this, { + local: 'items', + viewsRequireLifecycle: true + }, options); + } + AbstractRepeater.prototype.viewCount = function () { + throw new Error('subclass must implement `viewCount`'); + }; + AbstractRepeater.prototype.views = function () { + throw new Error('subclass must implement `views`'); + }; + AbstractRepeater.prototype.view = function (index) { + throw new Error('subclass must implement `view`'); + }; + AbstractRepeater.prototype.matcher = function () { + throw new Error('subclass must implement `matcher`'); + }; + AbstractRepeater.prototype.addView = function (bindingContext, overrideContext) { + throw new Error('subclass must implement `addView`'); + }; + AbstractRepeater.prototype.insertView = function (index, bindingContext, overrideContext) { + throw new Error('subclass must implement `insertView`'); + }; + AbstractRepeater.prototype.moveView = function (sourceIndex, targetIndex) { + throw new Error('subclass must implement `moveView`'); + }; + AbstractRepeater.prototype.removeAllViews = function (returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeAllViews`'); + }; + AbstractRepeater.prototype.removeViews = function (viewsToRemove, returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeView`'); + }; + AbstractRepeater.prototype.removeView = function (index, returnToCache, skipAnimation) { + throw new Error('subclass must implement `removeView`'); + }; + AbstractRepeater.prototype.updateBindings = function (view) { + throw new Error('subclass must implement `updateBindings`'); + }; + return AbstractRepeater; + }())); - _export('DebounceBindingBehavior', DebounceBindingBehavior); + var Repeat = exports('Repeat', (function (_super) { + __extends(Repeat, _super); + function Repeat(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) { + var _this = _super.call(this, { + local: 'item', + viewsRequireLifecycle: viewsRequireLifecycle(viewFactory) + }) || this; + _this.viewFactory = viewFactory; + _this.instruction = instruction; + _this.viewSlot = viewSlot; + _this.lookupFunctions = viewResources.lookupFunctions; + _this.observerLocator = observerLocator; + _this.key = 'key'; + _this.value = 'value'; + _this.strategyLocator = strategyLocator; + _this.ignoreMutation = false; + _this.sourceExpression = getItemsSourceExpression(_this.instruction, 'repeat.for'); + _this.isOneTime = isOneTime(_this.sourceExpression); + _this.viewsRequireLifecycle = viewsRequireLifecycle(viewFactory); + return _this; + } + Repeat.prototype.call = function (context, changes) { + this[context](this.items, changes); + }; + Repeat.prototype.bind = function (bindingContext, overrideContext) { + this.scope = { bindingContext: bindingContext, overrideContext: overrideContext }; + this.matcherBinding = this._captureAndRemoveMatcherBinding(); + this.itemsChanged(); + }; + Repeat.prototype.unbind = function () { + this.scope = null; + this.items = null; + this.matcherBinding = null; + this.viewSlot.removeAll(true, true); + this._unsubscribeCollection(); + }; + Repeat.prototype._unsubscribeCollection = function () { + if (this.collectionObserver) { + this.collectionObserver.unsubscribe(this.callContext, this); + this.collectionObserver = null; + this.callContext = null; + } + }; + Repeat.prototype.itemsChanged = function () { + var _this = this; + this._unsubscribeCollection(); + if (!this.scope) { + return; + } + var items = this.items; + this.strategy = this.strategyLocator.getStrategy(items); + if (!this.strategy) { + throw new Error("Value for '" + this.sourceExpression + "' is non-repeatable"); + } + if (!this.isOneTime && !this._observeInnerCollection()) { + this._observeCollection(); + } + this.ignoreMutation = true; + this.strategy.instanceChanged(this, items); + this.observerLocator.taskQueue.queueMicroTask(function () { + _this.ignoreMutation = false; + }); + }; + Repeat.prototype._getInnerCollection = function () { + var expression = unwrapExpression(this.sourceExpression); + if (!expression) { + return null; + } + return expression.evaluate(this.scope, null); + }; + Repeat.prototype.handleCollectionMutated = function (collection, changes) { + if (!this.collectionObserver) { + return; + } + if (this.ignoreMutation) { + return; + } + this.strategy.instanceMutated(this, collection, changes); + }; + Repeat.prototype.handleInnerCollectionMutated = function (collection, changes) { + var _this = this; + if (!this.collectionObserver) { + return; + } + if (this.ignoreMutation) { + return; + } + this.ignoreMutation = true; + var newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions); + this.observerLocator.taskQueue.queueMicroTask(function () { return _this.ignoreMutation = false; }); + if (newItems === this.items) { + this.itemsChanged(); + } + else { + this.items = newItems; + } + }; + Repeat.prototype._observeInnerCollection = function () { + var items = this._getInnerCollection(); + var strategy = this.strategyLocator.getStrategy(items); + if (!strategy) { + return false; + } + this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items); + if (!this.collectionObserver) { + return false; + } + this.callContext = 'handleInnerCollectionMutated'; + this.collectionObserver.subscribe(this.callContext, this); + return true; + }; + Repeat.prototype._observeCollection = function () { + var items = this.items; + this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items); + if (this.collectionObserver) { + this.callContext = 'handleCollectionMutated'; + this.collectionObserver.subscribe(this.callContext, this); + } + }; + Repeat.prototype._captureAndRemoveMatcherBinding = function () { + if (this.viewFactory.viewFactory) { + var instructions = this.viewFactory.viewFactory.instructions; + var instructionIds = Object.keys(instructions); + for (var i = 0; i < instructionIds.length; i++) { + var expressions = instructions[instructionIds[i]].expressions; + if (expressions) { + for (var ii = 0; ii < expressions.length; ii++) { + if (expressions[ii].targetProperty === 'matcher') { + var matcherBinding = expressions[ii]; + expressions.splice(ii, 1); + return matcherBinding; + } + } + } + } + } + return undefined; + }; + Repeat.prototype.viewCount = function () { return this.viewSlot.children.length; }; + Repeat.prototype.views = function () { return this.viewSlot.children; }; + Repeat.prototype.view = function (index) { return this.viewSlot.children[index]; }; + Repeat.prototype.matcher = function () { return this.matcherBinding ? this.matcherBinding.sourceExpression.evaluate(this.scope, this.matcherBinding.lookupFunctions) : null; }; + Repeat.prototype.addView = function (bindingContext, overrideContext) { + var view = this.viewFactory.create(); + view.bind(bindingContext, overrideContext); + this.viewSlot.add(view); + }; + Repeat.prototype.insertView = function (index, bindingContext, overrideContext) { + var view = this.viewFactory.create(); + view.bind(bindingContext, overrideContext); + this.viewSlot.insert(index, view); + }; + Repeat.prototype.moveView = function (sourceIndex, targetIndex) { + this.viewSlot.move(sourceIndex, targetIndex); + }; + Repeat.prototype.removeAllViews = function (returnToCache, skipAnimation) { + return this.viewSlot.removeAll(returnToCache, skipAnimation); + }; + Repeat.prototype.removeViews = function (viewsToRemove, returnToCache, skipAnimation) { + return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation); + }; + Repeat.prototype.removeView = function (index, returnToCache, skipAnimation) { + return this.viewSlot.removeAt(index, returnToCache, skipAnimation); + }; + Repeat.prototype.updateBindings = function (view) { + var $view = view; + var j = $view.bindings.length; + while (j--) { + updateOneTimeBinding($view.bindings[j]); + } + j = $view.controllers.length; + while (j--) { + var k = $view.controllers[j].boundProperties.length; + while (k--) { + var binding = $view.controllers[j].boundProperties[k].binding; + updateOneTimeBinding(binding); + } + } + }; + __decorate([ + bindable + ], Repeat.prototype, "items", void 0); + __decorate([ + bindable + ], Repeat.prototype, "local", void 0); + __decorate([ + bindable + ], Repeat.prototype, "key", void 0); + __decorate([ + bindable + ], Repeat.prototype, "value", void 0); + Repeat = __decorate([ + customAttribute('repeat'), + templateController, + inject(BoundViewFactory, TargetInstruction, ViewSlot, ViewResources, ObserverLocator, RepeatStrategyLocator) + ], Repeat); + return Repeat; + }(AbstractRepeater))); - _export('SelfBindingBehavior', SelfBindingBehavior); + var aureliaHideClassName = 'aurelia-hide'; + var aureliaHideClass = "." + aureliaHideClassName + " { display:none !important; }"; + function injectAureliaHideStyleAtHead() { + DOM.injectStyles(aureliaHideClass); + } + function injectAureliaHideStyleAtBoundary(domBoundary) { + if (FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) { + domBoundary.hasAureliaHideStyle = true; + DOM.injectStyles(aureliaHideClass, domBoundary); + } + } - _export('SignalBindingBehavior', SignalBindingBehavior); + var Show = exports('Show', (function () { + function Show(element, animator, domBoundary) { + this.element = element; + this.animator = animator; + this.domBoundary = domBoundary; + } + Show.inject = function () { + return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; + }; + Show.prototype.created = function () { + injectAureliaHideStyleAtBoundary(this.domBoundary); + }; + Show.prototype.valueChanged = function (newValue) { + var element = this.element; + var animator = this.animator; + if (newValue) { + animator.removeClass(element, aureliaHideClassName); + } + else { + animator.addClass(element, aureliaHideClassName); + } + }; + Show.prototype.bind = function (bindingContext) { + this.valueChanged(this.value); + }; + Show = __decorate([ + customAttribute('show') + ], Show); + return Show; + }())); - _export('BindingSignaler', BindingSignaler); + var Hide = exports('Hide', (function () { + function Hide(element, animator, domBoundary) { + this.element = element; + this.animator = animator; + this.domBoundary = domBoundary; + } + Hide.inject = function () { + return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; + }; + Hide.prototype.created = function () { + injectAureliaHideStyleAtBoundary(this.domBoundary); + }; + Hide.prototype.valueChanged = function (newValue) { + if (newValue) { + this.animator.addClass(this.element, aureliaHideClassName); + } + else { + this.animator.removeClass(this.element, aureliaHideClassName); + } + }; + Hide.prototype.bind = function (bindingContext) { + this.valueChanged(this.value); + }; + Hide.prototype.value = function (value) { + throw new Error('Method not implemented.'); + }; + Hide = __decorate([ + customAttribute('hide') + ], Hide); + return Hide; + }())); - _export('UpdateTriggerBindingBehavior', UpdateTriggerBindingBehavior); + var SCRIPT_REGEX = /)<[^<]*)*<\/script>/gi; + var needsToWarn = true; + var HTMLSanitizer = exports('HTMLSanitizer', (function () { + function HTMLSanitizer() { + } + HTMLSanitizer.prototype.sanitize = function (input) { + if (needsToWarn) { + needsToWarn = false; + getLogger('html-sanitizer') + .warn("CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks,\nand should not be relied on for sanitizing input from unknown sources.\nPlease see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html."); + } + return input.replace(SCRIPT_REGEX, ''); + }; + return HTMLSanitizer; + }())); - _export('AbstractRepeater', AbstractRepeater); + var SanitizeHTMLValueConverter = exports('SanitizeHTMLValueConverter', (function () { + function SanitizeHTMLValueConverter(sanitizer) { + this.sanitizer = sanitizer; + } + SanitizeHTMLValueConverter.prototype.toView = function (untrustedMarkup) { + if (untrustedMarkup === null || untrustedMarkup === undefined) { + return null; + } + return this.sanitizer.sanitize(untrustedMarkup); + }; + SanitizeHTMLValueConverter = __decorate([ + valueConverter('sanitizeHTML'), + inject(HTMLSanitizer) + ], SanitizeHTMLValueConverter); + return SanitizeHTMLValueConverter; + }())); - _export('RepeatStrategyLocator', RepeatStrategyLocator); + var Replaceable = exports('Replaceable', (function () { + function Replaceable(viewFactory, viewSlot) { + this.viewFactory = viewFactory; + this.viewSlot = viewSlot; + this.view = null; + } + Replaceable.prototype.bind = function (bindingContext, overrideContext) { + if (this.view === null) { + this.view = this.viewFactory.create(); + this.viewSlot.add(this.view); + } + this.view.bind(bindingContext, overrideContext); + }; + Replaceable.prototype.unbind = function () { + this.view.unbind(); + }; + Replaceable = __decorate([ + customAttribute('replaceable'), + templateController, + inject(BoundViewFactory, ViewSlot) + ], Replaceable); + return Replaceable; + }())); - _export('NullRepeatStrategy', NullRepeatStrategy); + var Focus = exports('Focus', (function () { + function Focus(element, taskQueue) { + this.element = element; + this.taskQueue = taskQueue; + this.isAttached = false; + this.needsApply = false; + } + Focus.inject = function () { + return [DOM.Element, TaskQueue]; + }; + Focus.prototype.valueChanged = function (newValue) { + if (this.isAttached) { + this._apply(); + } + else { + this.needsApply = true; + } + }; + Focus.prototype._apply = function () { + var _this = this; + if (this.value) { + this.taskQueue.queueMicroTask(function () { + if (_this.value) { + _this.element.focus(); + } + }); + } + else { + this.element.blur(); + } + }; + Focus.prototype.attached = function () { + this.isAttached = true; + if (this.needsApply) { + this.needsApply = false; + this._apply(); + } + this.element.addEventListener('focus', this); + this.element.addEventListener('blur', this); + }; + Focus.prototype.detached = function () { + this.isAttached = false; + this.element.removeEventListener('focus', this); + this.element.removeEventListener('blur', this); + }; + Focus.prototype.handleEvent = function (e) { + if (e.type === 'focus') { + this.value = true; + } + else if (DOM.activeElement !== this.element) { + this.value = false; + } + }; + Focus = __decorate([ + customAttribute('focus', bindingMode.twoWay) + ], Focus); + return Focus; + }())); - _export('ArrayRepeatStrategy', ArrayRepeatStrategy); + var cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi; + function fixupCSSUrls(address, css) { + if (typeof css !== 'string') { + throw new Error("Failed loading required CSS file: " + address); + } + return css.replace(cssUrlMatcher, function (match, p1) { + var quote = p1.charAt(0); + if (quote === '\'' || quote === '"') { + p1 = p1.substr(1, p1.length - 2); + } + return 'url(\'' + relativeToFile(p1, address) + '\')'; + }); + } + var CSSResource = (function () { + function CSSResource(address) { + this.address = address; + this._scoped = null; + this._global = false; + this._alreadyGloballyInjected = false; + } + CSSResource.prototype.initialize = function (container, Target) { + this._scoped = new Target(this); + }; + CSSResource.prototype.register = function (registry, name) { + if (name === 'scoped') { + registry.registerViewEngineHooks(this._scoped); + } + else { + this._global = true; + } + }; + CSSResource.prototype.load = function (container) { + var _this = this; + return container.get(Loader) + .loadText(this.address) + .catch(function (err) { return null; }) + .then(function (text) { + text = fixupCSSUrls(_this.address, text); + _this._scoped.css = text; + if (_this._global) { + _this._alreadyGloballyInjected = true; + DOM.injectStyles(text); + } + }); + }; + return CSSResource; + }()); + var CSSViewEngineHooks = (function () { + function CSSViewEngineHooks(owner) { + this.owner = owner; + this.css = null; + } + CSSViewEngineHooks.prototype.beforeCompile = function (content, resources, instruction) { + if (instruction.targetShadowDOM) { + DOM.injectStyles(this.css, content, true); + } + else if (FEATURE.scopedCSS) { + var styleNode = DOM.injectStyles(this.css, content, true); + styleNode.setAttribute('scoped', 'scoped'); + } + else if (this._global && !this.owner._alreadyGloballyInjected) { + DOM.injectStyles(this.css); + this.owner._alreadyGloballyInjected = true; + } + }; + return CSSViewEngineHooks; + }()); + function _createCSSResource(address) { + var ViewCSS = (function (_super) { + __extends(ViewCSS, _super); + function ViewCSS() { + return _super !== null && _super.apply(this, arguments) || this; + } + ViewCSS = __decorate([ + resource(new CSSResource(address)) + ], ViewCSS); + return ViewCSS; + }(CSSViewEngineHooks)); + return ViewCSS; + } - _export('MapRepeatStrategy', MapRepeatStrategy); + var AttrBindingBehavior = exports('AttrBindingBehavior', (function () { + function AttrBindingBehavior() { + } + AttrBindingBehavior.prototype.bind = function (binding, source) { + binding.targetObserver = new DataAttributeObserver(binding.target, binding.targetProperty); + }; + AttrBindingBehavior.prototype.unbind = function (binding, source) { + }; + AttrBindingBehavior = __decorate([ + bindingBehavior('attr') + ], AttrBindingBehavior); + return AttrBindingBehavior; + }())); - _export('SetRepeatStrategy', SetRepeatStrategy); + var modeBindingBehavior = { + bind: function (binding, source, lookupFunctions) { + binding.originalMode = binding.mode; + binding.mode = this.mode; + }, + unbind: function (binding, source) { + binding.mode = binding.originalMode; + binding.originalMode = null; + } + }; + var OneTimeBindingBehavior = exports('OneTimeBindingBehavior', (function () { + function OneTimeBindingBehavior() { + this.mode = bindingMode.oneTime; + } + OneTimeBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('oneTime') + ], OneTimeBindingBehavior); + return OneTimeBindingBehavior; + }())); + var OneWayBindingBehavior = exports('OneWayBindingBehavior', (function () { + function OneWayBindingBehavior() { + this.mode = bindingMode.toView; + } + OneWayBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('oneWay') + ], OneWayBindingBehavior); + return OneWayBindingBehavior; + }())); + var ToViewBindingBehavior = exports('ToViewBindingBehavior', (function () { + function ToViewBindingBehavior() { + this.mode = bindingMode.toView; + } + ToViewBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('toView') + ], ToViewBindingBehavior); + return ToViewBindingBehavior; + }())); + var FromViewBindingBehavior = exports('FromViewBindingBehavior', (function () { + function FromViewBindingBehavior() { + this.mode = bindingMode.fromView; + } + FromViewBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('fromView') + ], FromViewBindingBehavior); + return FromViewBindingBehavior; + }())); + var TwoWayBindingBehavior = exports('TwoWayBindingBehavior', (function () { + function TwoWayBindingBehavior() { + this.mode = bindingMode.twoWay; + } + TwoWayBindingBehavior = __decorate([ + mixin(modeBindingBehavior), + bindingBehavior('twoWay') + ], TwoWayBindingBehavior); + return TwoWayBindingBehavior; + }())); - _export('NumberRepeatStrategy', NumberRepeatStrategy); + function throttle(newValue) { + var _this = this; + var state = this.throttleState; + var elapsed = +new Date() - state.last; + if (elapsed >= state.delay) { + clearTimeout(state.timeoutId); + state.timeoutId = null; + state.last = +new Date(); + this.throttledMethod(newValue); + return; + } + state.newValue = newValue; + if (state.timeoutId === null) { + state.timeoutId = setTimeout(function () { + state.timeoutId = null; + state.last = +new Date(); + _this.throttledMethod(state.newValue); + }, state.delay - elapsed); + } + } + var ThrottleBindingBehavior = exports('ThrottleBindingBehavior', (function () { + function ThrottleBindingBehavior() { + } + ThrottleBindingBehavior.prototype.bind = function (binding, source, delay) { + if (delay === void 0) { delay = 200; } + var methodToThrottle = 'updateTarget'; + if (binding.callSource) { + methodToThrottle = 'callSource'; + } + else if (binding.updateSource && binding.mode === bindingMode.twoWay) { + methodToThrottle = 'updateSource'; + } + binding.throttledMethod = binding[methodToThrottle]; + binding.throttledMethod.originalName = methodToThrottle; + binding[methodToThrottle] = throttle; + binding.throttleState = { + delay: delay, + last: 0, + timeoutId: null + }; + }; + ThrottleBindingBehavior.prototype.unbind = function (binding, source) { + var methodToRestore = binding.throttledMethod.originalName; + binding[methodToRestore] = binding.throttledMethod; + binding.throttledMethod = null; + clearTimeout(binding.throttleState.timeoutId); + binding.throttleState = null; + }; + ThrottleBindingBehavior = __decorate([ + bindingBehavior('throttle') + ], ThrottleBindingBehavior); + return ThrottleBindingBehavior; + }())); - _export('createFullOverrideContext', createFullOverrideContext); + var unset = {}; + function debounceCallSource(event) { + var _this = this; + var state = this.debounceState; + clearTimeout(state.timeoutId); + state.timeoutId = setTimeout(function () { return _this.debouncedMethod(event); }, state.delay); + } + function debounceCall(context, newValue, oldValue) { + var _this = this; + var state = this.debounceState; + clearTimeout(state.timeoutId); + if (context !== state.callContextToDebounce) { + state.oldValue = unset; + this.debouncedMethod(context, newValue, oldValue); + return; + } + if (state.oldValue === unset) { + state.oldValue = oldValue; + } + state.timeoutId = setTimeout(function () { + var _oldValue = state.oldValue; + state.oldValue = unset; + _this.debouncedMethod(context, newValue, _oldValue); + }, state.delay); + } + var DebounceBindingBehavior = exports('DebounceBindingBehavior', (function () { + function DebounceBindingBehavior() { + } + DebounceBindingBehavior.prototype.bind = function (binding, source, delay) { + if (delay === void 0) { delay = 200; } + var isCallSource = binding.callSource !== undefined; + var methodToDebounce = isCallSource ? 'callSource' : 'call'; + var debouncer = isCallSource ? debounceCallSource : debounceCall; + var mode = binding.mode; + var callContextToDebounce = mode === bindingMode.twoWay || mode === bindingMode.fromView ? targetContext : sourceContext; + binding.debouncedMethod = binding[methodToDebounce]; + binding.debouncedMethod.originalName = methodToDebounce; + binding[methodToDebounce] = debouncer; + binding.debounceState = { + callContextToDebounce: callContextToDebounce, + delay: delay, + timeoutId: 0, + oldValue: unset + }; + }; + DebounceBindingBehavior.prototype.unbind = function (binding, source) { + var methodToRestore = binding.debouncedMethod.originalName; + binding[methodToRestore] = binding.debouncedMethod; + binding.debouncedMethod = null; + clearTimeout(binding.debounceState.timeoutId); + binding.debounceState = null; + }; + DebounceBindingBehavior = __decorate([ + bindingBehavior('debounce') + ], DebounceBindingBehavior); + return DebounceBindingBehavior; + }())); - _export('updateOverrideContext', updateOverrideContext); + function findOriginalEventTarget(event) { + return (event.path && event.path[0]) || (event.deepPath && event.deepPath[0]) || event.target; + } + function handleSelfEvent(event) { + var target = findOriginalEventTarget(event); + if (this.target !== target) { + return; + } + this.selfEventCallSource(event); + } + var SelfBindingBehavior = exports('SelfBindingBehavior', (function () { + function SelfBindingBehavior() { + } + SelfBindingBehavior.prototype.bind = function (binding, source) { + if (!binding.callSource || !binding.targetEvent) { + throw new Error('Self binding behavior only supports event.'); + } + binding.selfEventCallSource = binding.callSource; + binding.callSource = handleSelfEvent; + }; + SelfBindingBehavior.prototype.unbind = function (binding, source) { + binding.callSource = binding.selfEventCallSource; + binding.selfEventCallSource = null; + }; + SelfBindingBehavior = __decorate([ + bindingBehavior('self') + ], SelfBindingBehavior); + return SelfBindingBehavior; + }())); - _export('getItemsSourceExpression', getItemsSourceExpression); + var BindingSignaler = exports('BindingSignaler', (function () { + function BindingSignaler() { + this.signals = {}; + } + BindingSignaler.prototype.signal = function (name) { + var bindings = this.signals[name]; + if (!bindings) { + return; + } + var i = bindings.length; + while (i--) { + bindings[i].call(sourceContext); + } + }; + return BindingSignaler; + }())); - _export('isOneTime', isOneTime); + var SignalBindingBehavior = exports('SignalBindingBehavior', (function () { + function SignalBindingBehavior(bindingSignaler) { + this.signals = bindingSignaler.signals; + } + SignalBindingBehavior.inject = function () { return [BindingSignaler]; }; + SignalBindingBehavior.prototype.bind = function (binding, source) { + var names = []; + for (var _i = 2; _i < arguments.length; _i++) { + names[_i - 2] = arguments[_i]; + } + if (!binding.updateTarget) { + throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.'); + } + var signals = this.signals; + if (names.length === 1) { + var name_1 = names[0]; + var bindings = signals[name_1] || (signals[name_1] = []); + bindings.push(binding); + binding.signalName = name_1; + } + else if (names.length > 1) { + var i = names.length; + while (i--) { + var name_2 = names[i]; + var bindings = signals[name_2] || (signals[name_2] = []); + bindings.push(binding); + } + binding.signalName = names; + } + else { + throw new Error('Signal name is required.'); + } + }; + SignalBindingBehavior.prototype.unbind = function (binding, source) { + var signals = this.signals; + var name = binding.signalName; + binding.signalName = null; + if (Array.isArray(name)) { + var names = name; + var i = names.length; + while (i--) { + var n = names[i]; + var bindings = signals[n]; + bindings.splice(bindings.indexOf(binding), 1); + } + } + else { + var bindings = signals[name]; + bindings.splice(bindings.indexOf(binding), 1); + } + }; + SignalBindingBehavior = __decorate([ + bindingBehavior('signal') + ], SignalBindingBehavior); + return SignalBindingBehavior; + }())); - _export('updateOneTimeBinding', updateOneTimeBinding); + var eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg '; + var notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.'; + var UpdateTriggerBindingBehavior = exports('UpdateTriggerBindingBehavior', (function () { + function UpdateTriggerBindingBehavior() { + } + UpdateTriggerBindingBehavior.prototype.bind = function (binding, source) { + var events = []; + for (var _i = 2; _i < arguments.length; _i++) { + events[_i - 2] = arguments[_i]; + } + if (events.length === 0) { + throw new Error(eventNamesRequired); + } + if (binding.mode !== bindingMode.twoWay && binding.mode !== bindingMode.fromView) { + throw new Error(notApplicableMessage); + } + var targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty); + if (!targetObserver.handler) { + throw new Error(notApplicableMessage); + } + binding.targetObserver = targetObserver; + targetObserver.originalHandler = binding.targetObserver.handler; + var handler = new EventSubscriber(events); + targetObserver.handler = handler; + }; + UpdateTriggerBindingBehavior.prototype.unbind = function (binding, source) { + var targetObserver = binding.targetObserver; + targetObserver.handler.dispose(); + targetObserver.handler = targetObserver.originalHandler; + targetObserver.originalHandler = null; + }; + UpdateTriggerBindingBehavior = __decorate([ + bindingBehavior('updateTrigger') + ], UpdateTriggerBindingBehavior); + return UpdateTriggerBindingBehavior; + }())); - _export('unwrapExpression', unwrapExpression); + function _createDynamicElement(_a) { + var name = _a.name, viewUrl = _a.viewUrl, bindableNames = _a.bindableNames, useShadowDOMmode = _a.useShadowDOMmode; + var DynamicElement = (function () { + function DynamicElement() { + } + DynamicElement.prototype.bind = function (bindingContext) { + this.$parent = bindingContext; + }; + DynamicElement = __decorate([ + customElement(name), + useView(viewUrl) + ], DynamicElement); + return DynamicElement; + }()); + for (var i = 0, ii = bindableNames.length; i < ii; ++i) { + bindable(bindableNames[i])(DynamicElement); + } + switch (useShadowDOMmode) { + case 'open': + useShadowDOM({ mode: 'open' })(DynamicElement); + break; + case 'closed': + useShadowDOM({ mode: 'closed' })(DynamicElement); + break; + case '': + useShadowDOM(DynamicElement); + break; + case null: + break; + default: + getLogger('aurelia-html-only-element') + .warn("Expected 'use-shadow-dom' value to be \"close\", \"open\" or \"\", received " + useShadowDOMmode); + break; + } + return DynamicElement; + } - _export('viewsRequireLifecycle', viewsRequireLifecycle); - } - }; -}); \ No newline at end of file + function getElementName(address) { + return /([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase(); + } + function configure(config) { + var viewEngine = config.container.get(ViewEngine); + var loader = config.aurelia.loader; + viewEngine.addResourcePlugin('.html', { + 'fetch': function (viewUrl) { + return loader.loadTemplate(viewUrl).then(function (registryEntry) { + var _a; + var bindableNames = registryEntry.template.getAttribute('bindable'); + var useShadowDOMmode = registryEntry.template.getAttribute('use-shadow-dom'); + var name = getElementName(viewUrl); + if (bindableNames) { + bindableNames = bindableNames.split(',').map(function (x) { return x.trim(); }); + registryEntry.template.removeAttribute('bindable'); + } + else { + bindableNames = []; + } + return _a = {}, _a[name] = _createDynamicElement({ name: name, viewUrl: viewUrl, bindableNames: bindableNames, useShadowDOMmode: useShadowDOMmode }), _a; + }); + } + }); + } + + function configure$1(config) { + injectAureliaHideStyleAtHead(); + config.globalResources(Compose, If, Else, With, Repeat, Show, Hide, Replaceable, Focus, SanitizeHTMLValueConverter, OneTimeBindingBehavior, OneWayBindingBehavior, ToViewBindingBehavior, FromViewBindingBehavior, TwoWayBindingBehavior, ThrottleBindingBehavior, DebounceBindingBehavior, SelfBindingBehavior, SignalBindingBehavior, UpdateTriggerBindingBehavior, AttrBindingBehavior); + configure(config); + var viewEngine = config.container.get(ViewEngine); + var styleResourcePlugin = { + fetch: function (address) { + var _a; + return _a = {}, _a[address] = _createCSSResource(address), _a; + } + }; + ['.css', '.less', '.sass', '.scss', '.styl'].forEach(function (ext) { return viewEngine.addResourcePlugin(ext, styleResourcePlugin); }); + } + + } + }; +}); +//# sourceMappingURL=aurelia-templating-resources.js.map diff --git a/dist/system/aurelia-templating-resources.js.map b/dist/system/aurelia-templating-resources.js.map new file mode 100644 index 0000000..7bd47fd --- /dev/null +++ b/dist/system/aurelia-templating-resources.js.map @@ -0,0 +1 @@ +{"version":3,"file":"aurelia-templating-resources.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/system/binding-mode-behaviors.js b/dist/system/binding-mode-behaviors.js deleted file mode 100644 index f0684df..0000000 --- a/dist/system/binding-mode-behaviors.js +++ /dev/null @@ -1,70 +0,0 @@ -'use strict'; - -System.register(['aurelia-binding', 'aurelia-metadata'], function (_export, _context) { - "use strict"; - - var bindingMode, bindingBehavior, mixin, _dec, _dec2, _class, _dec3, _dec4, _class2, _dec5, _dec6, _class3, _dec7, _dec8, _class4, _dec9, _dec10, _class5, modeBindingBehavior, OneTimeBindingBehavior, OneWayBindingBehavior, ToViewBindingBehavior, FromViewBindingBehavior, TwoWayBindingBehavior; - - - - return { - setters: [function (_aureliaBinding) { - bindingMode = _aureliaBinding.bindingMode; - bindingBehavior = _aureliaBinding.bindingBehavior; - }, function (_aureliaMetadata) { - mixin = _aureliaMetadata.mixin; - }], - execute: function () { - modeBindingBehavior = { - bind: function bind(binding, source, lookupFunctions) { - binding.originalMode = binding.mode; - binding.mode = this.mode; - }, - unbind: function unbind(binding, source) { - binding.mode = binding.originalMode; - binding.originalMode = null; - } - }; - - _export('OneTimeBindingBehavior', OneTimeBindingBehavior = (_dec = mixin(modeBindingBehavior), _dec2 = bindingBehavior('oneTime'), _dec(_class = _dec2(_class = function OneTimeBindingBehavior() { - - - this.mode = bindingMode.oneTime; - }) || _class) || _class)); - - _export('OneTimeBindingBehavior', OneTimeBindingBehavior); - - _export('OneWayBindingBehavior', OneWayBindingBehavior = (_dec3 = mixin(modeBindingBehavior), _dec4 = bindingBehavior('oneWay'), _dec3(_class2 = _dec4(_class2 = function OneWayBindingBehavior() { - - - this.mode = bindingMode.toView; - }) || _class2) || _class2)); - - _export('OneWayBindingBehavior', OneWayBindingBehavior); - - _export('ToViewBindingBehavior', ToViewBindingBehavior = (_dec5 = mixin(modeBindingBehavior), _dec6 = bindingBehavior('toView'), _dec5(_class3 = _dec6(_class3 = function ToViewBindingBehavior() { - - - this.mode = bindingMode.toView; - }) || _class3) || _class3)); - - _export('ToViewBindingBehavior', ToViewBindingBehavior); - - _export('FromViewBindingBehavior', FromViewBindingBehavior = (_dec7 = mixin(modeBindingBehavior), _dec8 = bindingBehavior('fromView'), _dec7(_class4 = _dec8(_class4 = function FromViewBindingBehavior() { - - - this.mode = bindingMode.fromView; - }) || _class4) || _class4)); - - _export('FromViewBindingBehavior', FromViewBindingBehavior); - - _export('TwoWayBindingBehavior', TwoWayBindingBehavior = (_dec9 = mixin(modeBindingBehavior), _dec10 = bindingBehavior('twoWay'), _dec9(_class5 = _dec10(_class5 = function TwoWayBindingBehavior() { - - - this.mode = bindingMode.twoWay; - }) || _class5) || _class5)); - - _export('TwoWayBindingBehavior', TwoWayBindingBehavior); - } - }; -}); \ No newline at end of file diff --git a/dist/system/binding-signaler.js b/dist/system/binding-signaler.js deleted file mode 100644 index a3bd373..0000000 --- a/dist/system/binding-signaler.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -System.register(['aurelia-binding'], function (_export, _context) { - "use strict"; - - var sourceContext, BindingSignaler; - - - - return { - setters: [function (_aureliaBinding) { - sourceContext = _aureliaBinding.sourceContext; - }], - execute: function () { - _export('BindingSignaler', BindingSignaler = function () { - function BindingSignaler() { - - - this.signals = {}; - } - - BindingSignaler.prototype.signal = function signal(name) { - var bindings = this.signals[name]; - if (!bindings) { - return; - } - var i = bindings.length; - while (i--) { - bindings[i].call(sourceContext); - } - }; - - return BindingSignaler; - }()); - - _export('BindingSignaler', BindingSignaler); - } - }; -}); \ No newline at end of file diff --git a/dist/system/compose.js b/dist/system/compose.js deleted file mode 100644 index 9b0b11b..0000000 --- a/dist/system/compose.js +++ /dev/null @@ -1,232 +0,0 @@ -'use strict'; - -System.register(['aurelia-dependency-injection', 'aurelia-task-queue', 'aurelia-templating', 'aurelia-pal'], function (_export, _context) { - "use strict"; - - var Container, TaskQueue, CompositionEngine, CompositionContext, ViewSlot, ViewResources, customElement, bindable, noView, View, DOM, _dec, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, Compose; - - function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); - } - - - - function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; - } - - function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); - } - - function isEmpty(obj) { - for (var key in obj) { - return false; - } - return true; - } - - function tryActivateViewModel(vm, model) { - if (vm && typeof vm.activate === 'function') { - return Promise.resolve(vm.activate(model)); - } - } - - function createInstruction(composer, instruction) { - return Object.assign(instruction, { - bindingContext: composer.bindingContext, - overrideContext: composer.overrideContext, - owningView: composer.owningView, - container: composer.container, - viewSlot: composer.viewSlot, - viewResources: composer.viewResources, - currentController: composer.currentController, - host: composer.element, - swapOrder: composer.swapOrder - }); - } - - function processChanges(composer) { - var changes = composer.changes; - composer.changes = Object.create(null); - - if (!('view' in changes) && !('viewModel' in changes) && 'model' in changes) { - composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model); - if (!composer.pendingTask) { - return; - } - } else { - var instruction = { - view: composer.view, - viewModel: composer.currentViewModel || composer.viewModel, - model: composer.model - }; - - instruction = Object.assign(instruction, changes); - - instruction = createInstruction(composer, instruction); - composer.pendingTask = composer.compositionEngine.compose(instruction).then(function (controller) { - composer.currentController = controller; - composer.currentViewModel = controller ? controller.viewModel : null; - }); - } - - composer.pendingTask = composer.pendingTask.then(function () { - completeCompositionTask(composer); - }, function (reason) { - completeCompositionTask(composer); - throw reason; - }); - } - - function completeCompositionTask(composer) { - composer.pendingTask = null; - if (!isEmpty(composer.changes)) { - processChanges(composer); - } - } - - function requestUpdate(composer) { - if (composer.pendingTask || composer.updateRequested) { - return; - } - composer.updateRequested = true; - composer.taskQueue.queueMicroTask(function () { - composer.updateRequested = false; - processChanges(composer); - }); - } - return { - setters: [function (_aureliaDependencyInjection) { - Container = _aureliaDependencyInjection.Container; - }, function (_aureliaTaskQueue) { - TaskQueue = _aureliaTaskQueue.TaskQueue; - }, function (_aureliaTemplating) { - CompositionEngine = _aureliaTemplating.CompositionEngine; - CompositionContext = _aureliaTemplating.CompositionContext; - ViewSlot = _aureliaTemplating.ViewSlot; - ViewResources = _aureliaTemplating.ViewResources; - customElement = _aureliaTemplating.customElement; - bindable = _aureliaTemplating.bindable; - noView = _aureliaTemplating.noView; - View = _aureliaTemplating.View; - }, function (_aureliaPal) { - DOM = _aureliaPal.DOM; - }], - execute: function () { - _export('Compose', Compose = (_dec = customElement('compose'), _dec(_class = noView(_class = (_class2 = function () { - Compose.inject = function inject() { - return [DOM.Element, Container, CompositionEngine, ViewSlot, ViewResources, TaskQueue]; - }; - - function Compose(element, container, compositionEngine, viewSlot, viewResources, taskQueue) { - - - _initDefineProp(this, 'model', _descriptor, this); - - _initDefineProp(this, 'view', _descriptor2, this); - - _initDefineProp(this, 'viewModel', _descriptor3, this); - - _initDefineProp(this, 'swapOrder', _descriptor4, this); - - this.element = element; - this.container = container; - this.compositionEngine = compositionEngine; - this.viewSlot = viewSlot; - this.viewResources = viewResources; - this.taskQueue = taskQueue; - this.currentController = null; - this.currentViewModel = null; - this.changes = Object.create(null); - } - - Compose.prototype.created = function created(owningView) { - this.owningView = owningView; - }; - - Compose.prototype.bind = function bind(bindingContext, overrideContext) { - this.bindingContext = bindingContext; - this.overrideContext = overrideContext; - this.changes.view = this.view; - this.changes.viewModel = this.viewModel; - this.changes.model = this.model; - if (!this.pendingTask) { - processChanges(this); - } - }; - - Compose.prototype.unbind = function unbind() { - this.changes = Object.create(null); - this.bindingContext = null; - this.overrideContext = null; - var returnToCache = true; - var skipAnimation = true; - this.viewSlot.removeAll(returnToCache, skipAnimation); - }; - - Compose.prototype.modelChanged = function modelChanged(newValue, oldValue) { - this.changes.model = newValue; - requestUpdate(this); - }; - - Compose.prototype.viewChanged = function viewChanged(newValue, oldValue) { - this.changes.view = newValue; - requestUpdate(this); - }; - - Compose.prototype.viewModelChanged = function viewModelChanged(newValue, oldValue) { - this.changes.viewModel = newValue; - requestUpdate(this); - }; - - return Compose; - }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'model', [bindable], { - enumerable: true, - initializer: null - }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'view', [bindable], { - enumerable: true, - initializer: null - }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'viewModel', [bindable], { - enumerable: true, - initializer: null - }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, 'swapOrder', [bindable], { - enumerable: true, - initializer: null - })), _class2)) || _class) || _class)); - - _export('Compose', Compose); - } - }; -}); \ No newline at end of file diff --git a/dist/system/css-resource.js b/dist/system/css-resource.js deleted file mode 100644 index ab2bc57..0000000 --- a/dist/system/css-resource.js +++ /dev/null @@ -1,149 +0,0 @@ -'use strict'; - -System.register(['aurelia-templating', 'aurelia-loader', 'aurelia-dependency-injection', 'aurelia-path', 'aurelia-pal'], function (_export, _context) { - "use strict"; - - var ViewResources, resource, ViewCompileInstruction, Loader, Container, relativeToFile, DOM, FEATURE, cssUrlMatcher, CSSResource, CSSViewEngineHooks; - - function _possibleConstructorReturn(self, call) { - if (!self) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return call && (typeof call === "object" || typeof call === "function") ? call : self; - } - - function _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - enumerable: false, - writable: true, - configurable: true - } - }); - if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; - } - - - - function fixupCSSUrls(address, css) { - if (typeof css !== 'string') { - throw new Error('Failed loading required CSS file: ' + address); - } - return css.replace(cssUrlMatcher, function (match, p1) { - var quote = p1.charAt(0); - if (quote === '\'' || quote === '"') { - p1 = p1.substr(1, p1.length - 2); - } - return 'url(\'' + relativeToFile(p1, address) + '\')'; - }); - } - - function _createCSSResource(address) { - var _dec, _class; - - var ViewCSS = (_dec = resource(new CSSResource(address)), _dec(_class = function (_CSSViewEngineHooks) { - _inherits(ViewCSS, _CSSViewEngineHooks); - - function ViewCSS() { - - - return _possibleConstructorReturn(this, _CSSViewEngineHooks.apply(this, arguments)); - } - - return ViewCSS; - }(CSSViewEngineHooks)) || _class); - - return ViewCSS; - } - - _export('_createCSSResource', _createCSSResource); - - return { - setters: [function (_aureliaTemplating) { - ViewResources = _aureliaTemplating.ViewResources; - resource = _aureliaTemplating.resource; - ViewCompileInstruction = _aureliaTemplating.ViewCompileInstruction; - }, function (_aureliaLoader) { - Loader = _aureliaLoader.Loader; - }, function (_aureliaDependencyInjection) { - Container = _aureliaDependencyInjection.Container; - }, function (_aureliaPath) { - relativeToFile = _aureliaPath.relativeToFile; - }, function (_aureliaPal) { - DOM = _aureliaPal.DOM; - FEATURE = _aureliaPal.FEATURE; - }], - execute: function () { - cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi; - - CSSResource = function () { - function CSSResource(address) { - - - this.address = address; - this._scoped = null; - this._global = false; - this._alreadyGloballyInjected = false; - } - - CSSResource.prototype.initialize = function initialize(container, target) { - this._scoped = new target(this); - }; - - CSSResource.prototype.register = function register(registry, name) { - if (name === 'scoped') { - registry.registerViewEngineHooks(this._scoped); - } else { - this._global = true; - } - }; - - CSSResource.prototype.load = function load(container) { - var _this = this; - - return container.get(Loader).loadText(this.address).catch(function (err) { - return null; - }).then(function (text) { - text = fixupCSSUrls(_this.address, text); - _this._scoped.css = text; - if (_this._global) { - _this._alreadyGloballyInjected = true; - DOM.injectStyles(text); - } - }); - }; - - return CSSResource; - }(); - - CSSViewEngineHooks = function () { - function CSSViewEngineHooks(owner) { - - - this.owner = owner; - this.css = null; - } - - CSSViewEngineHooks.prototype.beforeCompile = function beforeCompile(content, resources, instruction) { - if (instruction.targetShadowDOM) { - DOM.injectStyles(this.css, content, true); - } else if (FEATURE.scopedCSS) { - var styleNode = DOM.injectStyles(this.css, content, true); - styleNode.setAttribute('scoped', 'scoped'); - } else if (this._global && !this.owner._alreadyGloballyInjected) { - DOM.injectStyles(this.css); - this.owner._alreadyGloballyInjected = true; - } - }; - - return CSSViewEngineHooks; - }(); - } - }; -}); \ No newline at end of file diff --git a/dist/system/debounce-binding-behavior.js b/dist/system/debounce-binding-behavior.js deleted file mode 100644 index 7a09b3c..0000000 --- a/dist/system/debounce-binding-behavior.js +++ /dev/null @@ -1,91 +0,0 @@ -'use strict'; - -System.register(['aurelia-binding'], function (_export, _context) { - "use strict"; - - var bindingMode, sourceContext, targetContext, bindingBehavior, _dec, _class, unset, DebounceBindingBehavior; - - - - function debounceCallSource(event) { - var _this = this; - - var state = this.debounceState; - clearTimeout(state.timeoutId); - state.timeoutId = setTimeout(function () { - return _this.debouncedMethod(event); - }, state.delay); - } - - function debounceCall(context, newValue, oldValue) { - var _this2 = this; - - var state = this.debounceState; - clearTimeout(state.timeoutId); - if (context !== state.callContextToDebounce) { - state.oldValue = unset; - this.debouncedMethod(context, newValue, oldValue); - return; - } - if (state.oldValue === unset) { - state.oldValue = oldValue; - } - state.timeoutId = setTimeout(function () { - var _oldValue = state.oldValue; - state.oldValue = unset; - _this2.debouncedMethod(context, newValue, _oldValue); - }, state.delay); - } - - return { - setters: [function (_aureliaBinding) { - bindingMode = _aureliaBinding.bindingMode; - sourceContext = _aureliaBinding.sourceContext; - targetContext = _aureliaBinding.targetContext; - bindingBehavior = _aureliaBinding.bindingBehavior; - }], - execute: function () { - unset = {}; - - _export('DebounceBindingBehavior', DebounceBindingBehavior = (_dec = bindingBehavior('debounce'), _dec(_class = function () { - function DebounceBindingBehavior() { - - } - - DebounceBindingBehavior.prototype.bind = function bind(binding, source) { - var delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200; - - var isCallSource = binding.callSource !== undefined; - var methodToDebounce = isCallSource ? 'callSource' : 'call'; - var debouncer = isCallSource ? debounceCallSource : debounceCall; - var mode = binding.mode; - var callContextToDebounce = mode === bindingMode.twoWay || mode === bindingMode.fromView ? targetContext : sourceContext; - - binding.debouncedMethod = binding[methodToDebounce]; - binding.debouncedMethod.originalName = methodToDebounce; - - binding[methodToDebounce] = debouncer; - - binding.debounceState = { - callContextToDebounce: callContextToDebounce, - delay: delay, - timeoutId: 0, - oldValue: unset - }; - }; - - DebounceBindingBehavior.prototype.unbind = function unbind(binding, source) { - var methodToRestore = binding.debouncedMethod.originalName; - binding[methodToRestore] = binding.debouncedMethod; - binding.debouncedMethod = null; - clearTimeout(binding.debounceState.timeoutId); - binding.debounceState = null; - }; - - return DebounceBindingBehavior; - }()) || _class)); - - _export('DebounceBindingBehavior', DebounceBindingBehavior); - } - }; -}); \ No newline at end of file diff --git a/dist/system/dynamic-element.js b/dist/system/dynamic-element.js deleted file mode 100644 index cfc82e0..0000000 --- a/dist/system/dynamic-element.js +++ /dev/null @@ -1,71 +0,0 @@ -'use strict'; - -System.register(['aurelia-templating', 'aurelia-logging'], function (_export, _context) { - "use strict"; - - var useView, customElement, bindable, useShadowDOM, getLogger; - - - - function _createDynamicElement(_ref) { - var _dec, _dec2, _class; - - var name = _ref.name, - viewUrl = _ref.viewUrl, - bindableNames = _ref.bindableNames, - useShadowDOMmode = _ref.useShadowDOMmode; - var DynamicElement = (_dec = customElement(name), _dec2 = useView(viewUrl), _dec(_class = _dec2(_class = function () { - function DynamicElement() { - - } - - DynamicElement.prototype.bind = function bind(bindingContext) { - this.$parent = bindingContext; - }; - - return DynamicElement; - }()) || _class) || _class); - - - for (var i = 0, ii = bindableNames.length; i < ii; ++i) { - bindable(bindableNames[i])(DynamicElement); - } - - switch (useShadowDOMmode) { - case 'open': - useShadowDOM({ mode: 'open' })(DynamicElement); - break; - - case 'closed': - useShadowDOM({ mode: 'closed' })(DynamicElement); - break; - - case '': - useShadowDOM(DynamicElement); - break; - - case null: - break; - - default: - getLogger('aurelia-html-only-element').warn('Expected \'use-shadow-dom\' value to be "close", "open" or "", received ' + useShadowDOMmode); - break; - } - - return DynamicElement; - } - - _export('_createDynamicElement', _createDynamicElement); - - return { - setters: [function (_aureliaTemplating) { - useView = _aureliaTemplating.useView; - customElement = _aureliaTemplating.customElement; - bindable = _aureliaTemplating.bindable; - useShadowDOM = _aureliaTemplating.useShadowDOM; - }, function (_aureliaLogging) { - getLogger = _aureliaLogging.getLogger; - }], - execute: function () {} - }; -}); \ No newline at end of file diff --git a/dist/system/else.js b/dist/system/else.js deleted file mode 100644 index 9dc65f2..0000000 --- a/dist/system/else.js +++ /dev/null @@ -1,86 +0,0 @@ -'use strict'; - -System.register(['aurelia-templating', 'aurelia-dependency-injection', './if-core'], function (_export, _context) { - "use strict"; - - var BoundViewFactory, ViewSlot, customAttribute, templateController, inject, IfCore, _dec, _dec2, _class, Else; - - - - function _possibleConstructorReturn(self, call) { - if (!self) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return call && (typeof call === "object" || typeof call === "function") ? call : self; - } - - function _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - enumerable: false, - writable: true, - configurable: true - } - }); - if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; - } - - return { - setters: [function (_aureliaTemplating) { - BoundViewFactory = _aureliaTemplating.BoundViewFactory; - ViewSlot = _aureliaTemplating.ViewSlot; - customAttribute = _aureliaTemplating.customAttribute; - templateController = _aureliaTemplating.templateController; - }, function (_aureliaDependencyInjection) { - inject = _aureliaDependencyInjection.inject; - }, function (_ifCore) { - IfCore = _ifCore.IfCore; - }], - execute: function () { - _export('Else', Else = (_dec = customAttribute('else'), _dec2 = inject(BoundViewFactory, ViewSlot), _dec(_class = templateController(_class = _dec2(_class = function (_IfCore) { - _inherits(Else, _IfCore); - - function Else(viewFactory, viewSlot) { - - - var _this = _possibleConstructorReturn(this, _IfCore.call(this, viewFactory, viewSlot)); - - _this._registerInIf(); - return _this; - } - - Else.prototype.bind = function bind(bindingContext, overrideContext) { - _IfCore.prototype.bind.call(this, bindingContext, overrideContext); - - if (this.ifVm.condition) { - this._hide(); - } else { - this._show(); - } - }; - - Else.prototype._registerInIf = function _registerInIf() { - var previous = this.viewSlot.anchor.previousSibling; - while (previous && !previous.au) { - previous = previous.previousSibling; - } - if (!previous || !previous.au.if) { - throw new Error("Can't find matching If for Else custom attribute."); - } - this.ifVm = previous.au.if.viewModel; - this.ifVm.elseVm = this; - }; - - return Else; - }(IfCore)) || _class) || _class) || _class)); - - _export('Else', Else); - } - }; -}); \ No newline at end of file diff --git a/dist/system/focus.js b/dist/system/focus.js deleted file mode 100644 index e112a76..0000000 --- a/dist/system/focus.js +++ /dev/null @@ -1,87 +0,0 @@ -'use strict'; - -System.register(['aurelia-templating', 'aurelia-binding', 'aurelia-task-queue', 'aurelia-pal'], function (_export, _context) { - "use strict"; - - var customAttribute, bindingMode, TaskQueue, DOM, _dec, _class, Focus; - - - - return { - setters: [function (_aureliaTemplating) { - customAttribute = _aureliaTemplating.customAttribute; - }, function (_aureliaBinding) { - bindingMode = _aureliaBinding.bindingMode; - }, function (_aureliaTaskQueue) { - TaskQueue = _aureliaTaskQueue.TaskQueue; - }, function (_aureliaPal) { - DOM = _aureliaPal.DOM; - }], - execute: function () { - _export('Focus', Focus = (_dec = customAttribute('focus', bindingMode.twoWay), _dec(_class = function () { - Focus.inject = function inject() { - return [DOM.Element, TaskQueue]; - }; - - function Focus(element, taskQueue) { - - - this.element = element; - this.taskQueue = taskQueue; - this.isAttached = false; - this.needsApply = false; - } - - Focus.prototype.valueChanged = function valueChanged(newValue) { - if (this.isAttached) { - this._apply(); - } else { - this.needsApply = true; - } - }; - - Focus.prototype._apply = function _apply() { - var _this = this; - - if (this.value) { - this.taskQueue.queueMicroTask(function () { - if (_this.value) { - _this.element.focus(); - } - }); - } else { - this.element.blur(); - } - }; - - Focus.prototype.attached = function attached() { - this.isAttached = true; - if (this.needsApply) { - this.needsApply = false; - this._apply(); - } - this.element.addEventListener('focus', this); - this.element.addEventListener('blur', this); - }; - - Focus.prototype.detached = function detached() { - this.isAttached = false; - this.element.removeEventListener('focus', this); - this.element.removeEventListener('blur', this); - }; - - Focus.prototype.handleEvent = function handleEvent(e) { - if (e.type === 'focus') { - this.value = true; - } else if (DOM.activeElement !== this.element) { - this.value = false; - } - }; - - return Focus; - }()) || _class)); - - _export('Focus', Focus); - } - }; -}); \ No newline at end of file diff --git a/dist/system/hide.js b/dist/system/hide.js deleted file mode 100644 index 85b606c..0000000 --- a/dist/system/hide.js +++ /dev/null @@ -1,58 +0,0 @@ -'use strict'; - -System.register(['aurelia-dependency-injection', 'aurelia-templating', 'aurelia-pal', './aurelia-hide-style'], function (_export, _context) { - "use strict"; - - var Optional, customAttribute, Animator, DOM, injectAureliaHideStyleAtBoundary, aureliaHideClassName, _dec, _class, Hide; - - - - return { - setters: [function (_aureliaDependencyInjection) { - Optional = _aureliaDependencyInjection.Optional; - }, function (_aureliaTemplating) { - customAttribute = _aureliaTemplating.customAttribute; - Animator = _aureliaTemplating.Animator; - }, function (_aureliaPal) { - DOM = _aureliaPal.DOM; - }, function (_aureliaHideStyle) { - injectAureliaHideStyleAtBoundary = _aureliaHideStyle.injectAureliaHideStyleAtBoundary; - aureliaHideClassName = _aureliaHideStyle.aureliaHideClassName; - }], - execute: function () { - _export('Hide', Hide = (_dec = customAttribute('hide'), _dec(_class = function () { - Hide.inject = function inject() { - return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; - }; - - function Hide(element, animator, domBoundary) { - - - this.element = element; - this.animator = animator; - this.domBoundary = domBoundary; - } - - Hide.prototype.created = function created() { - injectAureliaHideStyleAtBoundary(this.domBoundary); - }; - - Hide.prototype.valueChanged = function valueChanged(newValue) { - if (newValue) { - this.animator.addClass(this.element, aureliaHideClassName); - } else { - this.animator.removeClass(this.element, aureliaHideClassName); - } - }; - - Hide.prototype.bind = function bind(bindingContext) { - this.valueChanged(this.value); - }; - - return Hide; - }()) || _class)); - - _export('Hide', Hide); - } - }; -}); \ No newline at end of file diff --git a/dist/system/html-resource-plugin.js b/dist/system/html-resource-plugin.js deleted file mode 100644 index 3e4e8cf..0000000 --- a/dist/system/html-resource-plugin.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -System.register(['aurelia-templating', './dynamic-element'], function (_export, _context) { - "use strict"; - - var ViewEngine, _createDynamicElement; - - function getElementName(address) { - return (/([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase() - ); - } - - _export('getElementName', getElementName); - - function configure(config) { - var viewEngine = config.container.get(ViewEngine); - var loader = config.aurelia.loader; - - viewEngine.addResourcePlugin('.html', { - 'fetch': function fetch(viewUrl) { - return loader.loadTemplate(viewUrl).then(function (registryEntry) { - var _ref; - - var bindableNames = registryEntry.template.getAttribute('bindable'); - var useShadowDOMmode = registryEntry.template.getAttribute('use-shadow-dom'); - var name = getElementName(viewUrl); - - if (bindableNames) { - bindableNames = bindableNames.split(',').map(function (x) { - return x.trim(); - }); - registryEntry.template.removeAttribute('bindable'); - } else { - bindableNames = []; - } - - return _ref = {}, _ref[name] = _createDynamicElement({ name: name, viewUrl: viewUrl, bindableNames: bindableNames, useShadowDOMmode: useShadowDOMmode }), _ref; - }); - } - }); - } - - _export('configure', configure); - - return { - setters: [function (_aureliaTemplating) { - ViewEngine = _aureliaTemplating.ViewEngine; - }, function (_dynamicElement) { - _createDynamicElement = _dynamicElement._createDynamicElement; - }], - execute: function () {} - }; -}); \ No newline at end of file diff --git a/dist/system/html-sanitizer.js b/dist/system/html-sanitizer.js deleted file mode 100644 index 86317ae..0000000 --- a/dist/system/html-sanitizer.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -System.register(['aurelia-logging'], function (_export, _context) { - "use strict"; - - var getLogger, SCRIPT_REGEX, needsToWarn, HTMLSanitizer; - - - - return { - setters: [function (_aureliaLogging) { - getLogger = _aureliaLogging.getLogger; - }], - execute: function () { - SCRIPT_REGEX = /)<[^<]*)*<\/script>/gi; - needsToWarn = true; - - _export('HTMLSanitizer', HTMLSanitizer = function () { - function HTMLSanitizer() { - - } - - HTMLSanitizer.prototype.sanitize = function sanitize(input) { - if (needsToWarn) { - needsToWarn = false; - - getLogger('html-sanitizer').warn('CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks,\n and should not be relied on for sanitizing input from unknown sources.\n Please see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html.'); - } - - return input.replace(SCRIPT_REGEX, ''); - }; - - return HTMLSanitizer; - }()); - - _export('HTMLSanitizer', HTMLSanitizer); - } - }; -}); \ No newline at end of file diff --git a/dist/system/if-core.js b/dist/system/if-core.js deleted file mode 100644 index 3a5807f..0000000 --- a/dist/system/if-core.js +++ /dev/null @@ -1,106 +0,0 @@ -'use strict'; - -System.register([], function (_export, _context) { - "use strict"; - - var IfCore; - - - - return { - setters: [], - execute: function () { - _export('IfCore', IfCore = function () { - function IfCore(viewFactory, viewSlot) { - - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.view = null; - this.bindingContext = null; - this.overrideContext = null; - - this.showing = false; - this.cache = true; - } - - IfCore.prototype.bind = function bind(bindingContext, overrideContext) { - this.bindingContext = bindingContext; - this.overrideContext = overrideContext; - }; - - IfCore.prototype.unbind = function unbind() { - if (this.view === null) { - return; - } - - this.view.unbind(); - - if (!this.viewFactory.isCaching) { - return; - } - - if (this.showing) { - this.showing = false; - this.viewSlot.remove(this.view, true, true); - } else { - this.view.returnToCache(); - } - - this.view = null; - }; - - IfCore.prototype._show = function _show() { - if (this.showing) { - if (!this.view.isBound) { - this.view.bind(this.bindingContext, this.overrideContext); - } - return; - } - - if (this.view === null) { - this.view = this.viewFactory.create(); - } - - if (!this.view.isBound) { - this.view.bind(this.bindingContext, this.overrideContext); - } - - this.showing = true; - return this.viewSlot.add(this.view); - }; - - IfCore.prototype._hide = function _hide() { - var _this = this; - - if (!this.showing) { - return; - } - - this.showing = false; - var removed = this.viewSlot.remove(this.view); - - if (removed instanceof Promise) { - return removed.then(function () { - _this._unbindView(); - }); - } - - this._unbindView(); - }; - - IfCore.prototype._unbindView = function _unbindView() { - var cache = this.cache === 'false' ? false : !!this.cache; - this.view.unbind(); - if (!cache) { - this.view = null; - } - }; - - return IfCore; - }()); - - _export('IfCore', IfCore); - } - }; -}); \ No newline at end of file diff --git a/dist/system/if.js b/dist/system/if.js deleted file mode 100644 index dcedf8a..0000000 --- a/dist/system/if.js +++ /dev/null @@ -1,176 +0,0 @@ -'use strict'; - -System.register(['aurelia-templating', 'aurelia-dependency-injection', './if-core'], function (_export, _context) { - "use strict"; - - var BoundViewFactory, ViewSlot, bindable, customAttribute, templateController, inject, IfCore, _dec, _dec2, _dec3, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, If; - - function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); - } - - - - function _possibleConstructorReturn(self, call) { - if (!self) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return call && (typeof call === "object" || typeof call === "function") ? call : self; - } - - function _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - enumerable: false, - writable: true, - configurable: true - } - }); - if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; - } - - function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; - } - - function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); - } - - return { - setters: [function (_aureliaTemplating) { - BoundViewFactory = _aureliaTemplating.BoundViewFactory; - ViewSlot = _aureliaTemplating.ViewSlot; - bindable = _aureliaTemplating.bindable; - customAttribute = _aureliaTemplating.customAttribute; - templateController = _aureliaTemplating.templateController; - }, function (_aureliaDependencyInjection) { - inject = _aureliaDependencyInjection.inject; - }, function (_ifCore) { - IfCore = _ifCore.IfCore; - }], - execute: function () { - _export('If', If = (_dec = customAttribute('if'), _dec2 = inject(BoundViewFactory, ViewSlot), _dec3 = bindable({ primaryProperty: true }), _dec(_class = templateController(_class = _dec2(_class = (_class2 = function (_IfCore) { - _inherits(If, _IfCore); - - function If() { - var _temp, _this, _ret; - - - - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - return _ret = (_temp = (_this = _possibleConstructorReturn(this, _IfCore.call.apply(_IfCore, [this].concat(args))), _this), _initDefineProp(_this, 'condition', _descriptor, _this), _initDefineProp(_this, 'swapOrder', _descriptor2, _this), _initDefineProp(_this, 'cache', _descriptor3, _this), _temp), _possibleConstructorReturn(_this, _ret); - } - - If.prototype.bind = function bind(bindingContext, overrideContext) { - _IfCore.prototype.bind.call(this, bindingContext, overrideContext); - if (this.condition) { - this._show(); - } else { - this._hide(); - } - }; - - If.prototype.conditionChanged = function conditionChanged(newValue) { - this._update(newValue); - }; - - If.prototype._update = function _update(show) { - var _this2 = this; - - if (this.animating) { - return; - } - - var promise = void 0; - if (this.elseVm) { - promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm); - } else { - promise = show ? this._show() : this._hide(); - } - - if (promise) { - this.animating = true; - promise.then(function () { - _this2.animating = false; - if (_this2.condition !== _this2.showing) { - _this2._update(_this2.condition); - } - }); - } - }; - - If.prototype._swap = function _swap(remove, add) { - switch (this.swapOrder) { - case 'before': - return Promise.resolve(add._show()).then(function () { - return remove._hide(); - }); - case 'with': - return Promise.all([remove._hide(), add._show()]); - default: - var promise = remove._hide(); - return promise ? promise.then(function () { - return add._show(); - }) : add._show(); - } - }; - - return If; - }(IfCore), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'condition', [_dec3], { - enumerable: true, - initializer: null - }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'swapOrder', [bindable], { - enumerable: true, - initializer: null - }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'cache', [bindable], { - enumerable: true, - initializer: function initializer() { - return true; - } - })), _class2)) || _class) || _class) || _class)); - - _export('If', If); - } - }; -}); \ No newline at end of file diff --git a/dist/system/index.js b/dist/system/index.js deleted file mode 100644 index 9b7f5ca..0000000 --- a/dist/system/index.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -System.register(['./aurelia-templating-resources'], function (_export, _context) { - "use strict"; - - return { - setters: [function (_aureliaTemplatingResources) { - var _exportObj = {}; - - for (var _key in _aureliaTemplatingResources) { - if (_key !== "default" && _key !== "__esModule") _exportObj[_key] = _aureliaTemplatingResources[_key]; - } - - _export(_exportObj); - }], - execute: function () {} - }; -}); \ No newline at end of file diff --git a/dist/system/map-repeat-strategy.js b/dist/system/map-repeat-strategy.js deleted file mode 100644 index cd9371a..0000000 --- a/dist/system/map-repeat-strategy.js +++ /dev/null @@ -1,126 +0,0 @@ -'use strict'; - -System.register(['./repeat-utilities'], function (_export, _context) { - "use strict"; - - var createFullOverrideContext, updateOverrideContexts, MapRepeatStrategy; - - - - return { - setters: [function (_repeatUtilities) { - createFullOverrideContext = _repeatUtilities.createFullOverrideContext; - updateOverrideContexts = _repeatUtilities.updateOverrideContexts; - }], - execute: function () { - _export('MapRepeatStrategy', MapRepeatStrategy = function () { - function MapRepeatStrategy() { - - } - - MapRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getMapObserver(items); - }; - - MapRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this._standardProcessItems(repeat, items); - }); - return; - } - this._standardProcessItems(repeat, items); - }; - - MapRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, items) { - var index = 0; - var overrideContext = void 0; - - items.forEach(function (value, key) { - overrideContext = createFullOverrideContext(repeat, value, index, items.size, key); - repeat.addView(overrideContext.bindingContext, overrideContext); - ++index; - }); - }; - - MapRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, map, records) { - var key = void 0; - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var removeIndex = void 0; - var addIndex = void 0; - var record = void 0; - var rmPromises = []; - var viewOrPromise = void 0; - - for (i = 0, ii = records.length; i < ii; ++i) { - record = records[i]; - key = record.key; - switch (record.type) { - case 'update': - removeIndex = this._getViewIndexByKey(repeat, key); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - overrideContext = createFullOverrideContext(repeat, map.get(key), removeIndex, map.size, key); - repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext); - break; - case 'add': - addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1; - overrideContext = createFullOverrideContext(repeat, map.get(key), addIndex, map.size, key); - repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext); - break; - case 'delete': - if (record.oldValue === undefined) { - return; - } - removeIndex = this._getViewIndexByKey(repeat, key); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - break; - case 'clear': - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - break; - default: - continue; - } - } - - if (rmPromises.length > 0) { - Promise.all(rmPromises).then(function () { - updateOverrideContexts(repeat.views(), 0); - }); - } else { - updateOverrideContexts(repeat.views(), 0); - } - }; - - MapRepeatStrategy.prototype._getViewIndexByKey = function _getViewIndexByKey(repeat, key) { - var i = void 0; - var ii = void 0; - var child = void 0; - - for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { - child = repeat.view(i); - if (child.bindingContext[repeat.key] === key) { - return i; - } - } - - return undefined; - }; - - return MapRepeatStrategy; - }()); - - _export('MapRepeatStrategy', MapRepeatStrategy); - } - }; -}); \ No newline at end of file diff --git a/dist/system/null-repeat-strategy.js b/dist/system/null-repeat-strategy.js deleted file mode 100644 index 10e7d7e..0000000 --- a/dist/system/null-repeat-strategy.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; - -System.register([], function (_export, _context) { - "use strict"; - - var NullRepeatStrategy; - - - - return { - setters: [], - execute: function () { - _export("NullRepeatStrategy", NullRepeatStrategy = function () { - function NullRepeatStrategy() { - - } - - NullRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - repeat.removeAllViews(true); - }; - - NullRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) {}; - - return NullRepeatStrategy; - }()); - - _export("NullRepeatStrategy", NullRepeatStrategy); - } - }; -}); \ No newline at end of file diff --git a/dist/system/number-repeat-strategy.js b/dist/system/number-repeat-strategy.js deleted file mode 100644 index 43f31f6..0000000 --- a/dist/system/number-repeat-strategy.js +++ /dev/null @@ -1,74 +0,0 @@ -'use strict'; - -System.register(['./repeat-utilities'], function (_export, _context) { - "use strict"; - - var createFullOverrideContext, updateOverrideContexts, NumberRepeatStrategy; - - - - return { - setters: [function (_repeatUtilities) { - createFullOverrideContext = _repeatUtilities.createFullOverrideContext; - updateOverrideContexts = _repeatUtilities.updateOverrideContexts; - }], - execute: function () { - _export('NumberRepeatStrategy', NumberRepeatStrategy = function () { - function NumberRepeatStrategy() { - - } - - NumberRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver() { - return null; - }; - - NumberRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, value) { - var _this = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this._standardProcessItems(repeat, value); - }); - return; - } - this._standardProcessItems(repeat, value); - }; - - NumberRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, value) { - var childrenLength = repeat.viewCount(); - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var viewsToRemove = void 0; - - value = Math.floor(value); - viewsToRemove = childrenLength - value; - - if (viewsToRemove > 0) { - if (viewsToRemove > childrenLength) { - viewsToRemove = childrenLength; - } - - for (i = 0, ii = viewsToRemove; i < ii; ++i) { - repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle); - } - - return; - } - - for (i = childrenLength, ii = value; i < ii; ++i) { - overrideContext = createFullOverrideContext(repeat, i, i, ii); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - - updateOverrideContexts(repeat.views(), 0); - }; - - return NumberRepeatStrategy; - }()); - - _export('NumberRepeatStrategy', NumberRepeatStrategy); - } - }; -}); \ No newline at end of file diff --git a/dist/system/repeat-strategy-locator.js b/dist/system/repeat-strategy-locator.js deleted file mode 100644 index ba71a2c..0000000 --- a/dist/system/repeat-strategy-locator.js +++ /dev/null @@ -1,70 +0,0 @@ -'use strict'; - -System.register(['./null-repeat-strategy', './array-repeat-strategy', './map-repeat-strategy', './set-repeat-strategy', './number-repeat-strategy'], function (_export, _context) { - "use strict"; - - var NullRepeatStrategy, ArrayRepeatStrategy, MapRepeatStrategy, SetRepeatStrategy, NumberRepeatStrategy, RepeatStrategyLocator; - - - - return { - setters: [function (_nullRepeatStrategy) { - NullRepeatStrategy = _nullRepeatStrategy.NullRepeatStrategy; - }, function (_arrayRepeatStrategy) { - ArrayRepeatStrategy = _arrayRepeatStrategy.ArrayRepeatStrategy; - }, function (_mapRepeatStrategy) { - MapRepeatStrategy = _mapRepeatStrategy.MapRepeatStrategy; - }, function (_setRepeatStrategy) { - SetRepeatStrategy = _setRepeatStrategy.SetRepeatStrategy; - }, function (_numberRepeatStrategy) { - NumberRepeatStrategy = _numberRepeatStrategy.NumberRepeatStrategy; - }], - execute: function () { - _export('RepeatStrategyLocator', RepeatStrategyLocator = function () { - function RepeatStrategyLocator() { - - - this.matchers = []; - this.strategies = []; - - this.addStrategy(function (items) { - return items === null || items === undefined; - }, new NullRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Array; - }, new ArrayRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Map; - }, new MapRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Set; - }, new SetRepeatStrategy()); - this.addStrategy(function (items) { - return typeof items === 'number'; - }, new NumberRepeatStrategy()); - } - - RepeatStrategyLocator.prototype.addStrategy = function addStrategy(matcher, strategy) { - this.matchers.push(matcher); - this.strategies.push(strategy); - }; - - RepeatStrategyLocator.prototype.getStrategy = function getStrategy(items) { - var matchers = this.matchers; - - for (var i = 0, ii = matchers.length; i < ii; ++i) { - if (matchers[i](items)) { - return this.strategies[i]; - } - } - - return null; - }; - - return RepeatStrategyLocator; - }()); - - _export('RepeatStrategyLocator', RepeatStrategyLocator); - } - }; -}); \ No newline at end of file diff --git a/dist/system/repeat-utilities.js b/dist/system/repeat-utilities.js deleted file mode 100644 index 7cc7d52..0000000 --- a/dist/system/repeat-utilities.js +++ /dev/null @@ -1,123 +0,0 @@ -'use strict'; - -System.register(['aurelia-binding'], function (_export, _context) { - "use strict"; - - var createOverrideContext, BindingBehavior, ValueConverter, sourceContext, bindingMode, oneTime; - function updateOverrideContexts(views, startIndex) { - var length = views.length; - - if (startIndex > 0) { - startIndex = startIndex - 1; - } - - for (; startIndex < length; ++startIndex) { - updateOverrideContext(views[startIndex].overrideContext, startIndex, length); - } - } - - _export('updateOverrideContexts', updateOverrideContexts); - - function createFullOverrideContext(repeat, data, index, length, key) { - var bindingContext = {}; - var overrideContext = createOverrideContext(bindingContext, repeat.scope.overrideContext); - - if (typeof key !== 'undefined') { - bindingContext[repeat.key] = key; - bindingContext[repeat.value] = data; - } else { - bindingContext[repeat.local] = data; - } - updateOverrideContext(overrideContext, index, length); - return overrideContext; - } - - _export('createFullOverrideContext', createFullOverrideContext); - - function updateOverrideContext(overrideContext, index, length) { - var first = index === 0; - var last = index === length - 1; - var even = index % 2 === 0; - - overrideContext.$index = index; - overrideContext.$first = first; - overrideContext.$last = last; - overrideContext.$middle = !(first || last); - overrideContext.$odd = !even; - overrideContext.$even = even; - } - - _export('updateOverrideContext', updateOverrideContext); - - function getItemsSourceExpression(instruction, attrName) { - return instruction.behaviorInstructions.filter(function (bi) { - return bi.originalAttrName === attrName; - })[0].attributes.items.sourceExpression; - } - - _export('getItemsSourceExpression', getItemsSourceExpression); - - function unwrapExpression(expression) { - var unwrapped = false; - while (expression instanceof BindingBehavior) { - expression = expression.expression; - } - while (expression instanceof ValueConverter) { - expression = expression.expression; - unwrapped = true; - } - return unwrapped ? expression : null; - } - - _export('unwrapExpression', unwrapExpression); - - function isOneTime(expression) { - while (expression instanceof BindingBehavior) { - if (expression.name === 'oneTime') { - return true; - } - expression = expression.expression; - } - return false; - } - - _export('isOneTime', isOneTime); - - function updateOneTimeBinding(binding) { - if (binding.call && binding.mode === oneTime) { - binding.call(sourceContext); - } else if (binding.updateOneTimeBindings) { - binding.updateOneTimeBindings(); - } - } - - _export('updateOneTimeBinding', updateOneTimeBinding); - - function indexOf(array, item, matcher, startIndex) { - if (!matcher) { - return array.indexOf(item); - } - var length = array.length; - for (var index = startIndex || 0; index < length; index++) { - if (matcher(array[index], item)) { - return index; - } - } - return -1; - } - - _export('indexOf', indexOf); - - return { - setters: [function (_aureliaBinding) { - createOverrideContext = _aureliaBinding.createOverrideContext; - BindingBehavior = _aureliaBinding.BindingBehavior; - ValueConverter = _aureliaBinding.ValueConverter; - sourceContext = _aureliaBinding.sourceContext; - bindingMode = _aureliaBinding.bindingMode; - }], - execute: function () { - oneTime = bindingMode.oneTime; - } - }; -}); \ No newline at end of file diff --git a/dist/system/repeat.js b/dist/system/repeat.js deleted file mode 100644 index 51fcd41..0000000 --- a/dist/system/repeat.js +++ /dev/null @@ -1,351 +0,0 @@ -'use strict'; - -System.register(['aurelia-dependency-injection', 'aurelia-binding', 'aurelia-templating', './repeat-strategy-locator', './repeat-utilities', './analyze-view-factory', './abstract-repeater'], function (_export, _context) { - "use strict"; - - var inject, ObserverLocator, BoundViewFactory, TargetInstruction, ViewSlot, ViewResources, customAttribute, bindable, templateController, RepeatStrategyLocator, getItemsSourceExpression, unwrapExpression, isOneTime, updateOneTimeBinding, viewsRequireLifecycle, AbstractRepeater, _dec, _dec2, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, Repeat; - - function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); - } - - - - function _possibleConstructorReturn(self, call) { - if (!self) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return call && (typeof call === "object" || typeof call === "function") ? call : self; - } - - function _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - enumerable: false, - writable: true, - configurable: true - } - }); - if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; - } - - function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; - } - - function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); - } - - return { - setters: [function (_aureliaDependencyInjection) { - inject = _aureliaDependencyInjection.inject; - }, function (_aureliaBinding) { - ObserverLocator = _aureliaBinding.ObserverLocator; - }, function (_aureliaTemplating) { - BoundViewFactory = _aureliaTemplating.BoundViewFactory; - TargetInstruction = _aureliaTemplating.TargetInstruction; - ViewSlot = _aureliaTemplating.ViewSlot; - ViewResources = _aureliaTemplating.ViewResources; - customAttribute = _aureliaTemplating.customAttribute; - bindable = _aureliaTemplating.bindable; - templateController = _aureliaTemplating.templateController; - }, function (_repeatStrategyLocator) { - RepeatStrategyLocator = _repeatStrategyLocator.RepeatStrategyLocator; - }, function (_repeatUtilities) { - getItemsSourceExpression = _repeatUtilities.getItemsSourceExpression; - unwrapExpression = _repeatUtilities.unwrapExpression; - isOneTime = _repeatUtilities.isOneTime; - updateOneTimeBinding = _repeatUtilities.updateOneTimeBinding; - }, function (_analyzeViewFactory) { - viewsRequireLifecycle = _analyzeViewFactory.viewsRequireLifecycle; - }, function (_abstractRepeater) { - AbstractRepeater = _abstractRepeater.AbstractRepeater; - }], - execute: function () { - _export('Repeat', Repeat = (_dec = customAttribute('repeat'), _dec2 = inject(BoundViewFactory, TargetInstruction, ViewSlot, ViewResources, ObserverLocator, RepeatStrategyLocator), _dec(_class = templateController(_class = _dec2(_class = (_class2 = function (_AbstractRepeater) { - _inherits(Repeat, _AbstractRepeater); - - function Repeat(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) { - - - var _this = _possibleConstructorReturn(this, _AbstractRepeater.call(this, { - local: 'item', - viewsRequireLifecycle: viewsRequireLifecycle(viewFactory) - })); - - _initDefineProp(_this, 'items', _descriptor, _this); - - _initDefineProp(_this, 'local', _descriptor2, _this); - - _initDefineProp(_this, 'key', _descriptor3, _this); - - _initDefineProp(_this, 'value', _descriptor4, _this); - - _this.viewFactory = viewFactory; - _this.instruction = instruction; - _this.viewSlot = viewSlot; - _this.lookupFunctions = viewResources.lookupFunctions; - _this.observerLocator = observerLocator; - _this.key = 'key'; - _this.value = 'value'; - _this.strategyLocator = strategyLocator; - _this.ignoreMutation = false; - _this.sourceExpression = getItemsSourceExpression(_this.instruction, 'repeat.for'); - _this.isOneTime = isOneTime(_this.sourceExpression); - _this.viewsRequireLifecycle = viewsRequireLifecycle(viewFactory); - return _this; - } - - Repeat.prototype.call = function call(context, changes) { - this[context](this.items, changes); - }; - - Repeat.prototype.bind = function bind(bindingContext, overrideContext) { - this.scope = { bindingContext: bindingContext, overrideContext: overrideContext }; - this.matcherBinding = this._captureAndRemoveMatcherBinding(); - this.itemsChanged(); - }; - - Repeat.prototype.unbind = function unbind() { - this.scope = null; - this.items = null; - this.matcherBinding = null; - this.viewSlot.removeAll(true, true); - this._unsubscribeCollection(); - }; - - Repeat.prototype._unsubscribeCollection = function _unsubscribeCollection() { - if (this.collectionObserver) { - this.collectionObserver.unsubscribe(this.callContext, this); - this.collectionObserver = null; - this.callContext = null; - } - }; - - Repeat.prototype.itemsChanged = function itemsChanged() { - var _this2 = this; - - this._unsubscribeCollection(); - - if (!this.scope) { - return; - } - - var items = this.items; - this.strategy = this.strategyLocator.getStrategy(items); - if (!this.strategy) { - throw new Error('Value for \'' + this.sourceExpression + '\' is non-repeatable'); - } - - if (!this.isOneTime && !this._observeInnerCollection()) { - this._observeCollection(); - } - this.ignoreMutation = true; - this.strategy.instanceChanged(this, items); - this.observerLocator.taskQueue.queueMicroTask(function () { - _this2.ignoreMutation = false; - }); - }; - - Repeat.prototype._getInnerCollection = function _getInnerCollection() { - var expression = unwrapExpression(this.sourceExpression); - if (!expression) { - return null; - } - return expression.evaluate(this.scope, null); - }; - - Repeat.prototype.handleCollectionMutated = function handleCollectionMutated(collection, changes) { - if (!this.collectionObserver) { - return; - } - if (this.ignoreMutation) { - return; - } - this.strategy.instanceMutated(this, collection, changes); - }; - - Repeat.prototype.handleInnerCollectionMutated = function handleInnerCollectionMutated(collection, changes) { - var _this3 = this; - - if (!this.collectionObserver) { - return; - } - - if (this.ignoreMutation) { - return; - } - this.ignoreMutation = true; - var newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions); - this.observerLocator.taskQueue.queueMicroTask(function () { - return _this3.ignoreMutation = false; - }); - - if (newItems === this.items) { - this.itemsChanged(); - } else { - this.items = newItems; - } - }; - - Repeat.prototype._observeInnerCollection = function _observeInnerCollection() { - var items = this._getInnerCollection(); - var strategy = this.strategyLocator.getStrategy(items); - if (!strategy) { - return false; - } - this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items); - if (!this.collectionObserver) { - return false; - } - this.callContext = 'handleInnerCollectionMutated'; - this.collectionObserver.subscribe(this.callContext, this); - return true; - }; - - Repeat.prototype._observeCollection = function _observeCollection() { - var items = this.items; - this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items); - if (this.collectionObserver) { - this.callContext = 'handleCollectionMutated'; - this.collectionObserver.subscribe(this.callContext, this); - } - }; - - Repeat.prototype._captureAndRemoveMatcherBinding = function _captureAndRemoveMatcherBinding() { - if (this.viewFactory.viewFactory) { - var instructions = this.viewFactory.viewFactory.instructions; - var instructionIds = Object.keys(instructions); - for (var i = 0; i < instructionIds.length; i++) { - var expressions = instructions[instructionIds[i]].expressions; - if (expressions) { - for (var ii = 0; i < expressions.length; i++) { - if (expressions[ii].targetProperty === 'matcher') { - var matcherBinding = expressions[ii]; - expressions.splice(ii, 1); - return matcherBinding; - } - } - } - } - } - - return undefined; - }; - - Repeat.prototype.viewCount = function viewCount() { - return this.viewSlot.children.length; - }; - - Repeat.prototype.views = function views() { - return this.viewSlot.children; - }; - - Repeat.prototype.view = function view(index) { - return this.viewSlot.children[index]; - }; - - Repeat.prototype.matcher = function matcher() { - return this.matcherBinding ? this.matcherBinding.sourceExpression.evaluate(this.scope, this.matcherBinding.lookupFunctions) : null; - }; - - Repeat.prototype.addView = function addView(bindingContext, overrideContext) { - var view = this.viewFactory.create(); - view.bind(bindingContext, overrideContext); - this.viewSlot.add(view); - }; - - Repeat.prototype.insertView = function insertView(index, bindingContext, overrideContext) { - var view = this.viewFactory.create(); - view.bind(bindingContext, overrideContext); - this.viewSlot.insert(index, view); - }; - - Repeat.prototype.moveView = function moveView(sourceIndex, targetIndex) { - this.viewSlot.move(sourceIndex, targetIndex); - }; - - Repeat.prototype.removeAllViews = function removeAllViews(returnToCache, skipAnimation) { - return this.viewSlot.removeAll(returnToCache, skipAnimation); - }; - - Repeat.prototype.removeViews = function removeViews(viewsToRemove, returnToCache, skipAnimation) { - return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation); - }; - - Repeat.prototype.removeView = function removeView(index, returnToCache, skipAnimation) { - return this.viewSlot.removeAt(index, returnToCache, skipAnimation); - }; - - Repeat.prototype.updateBindings = function updateBindings(view) { - var j = view.bindings.length; - while (j--) { - updateOneTimeBinding(view.bindings[j]); - } - j = view.controllers.length; - while (j--) { - var k = view.controllers[j].boundProperties.length; - while (k--) { - var binding = view.controllers[j].boundProperties[k].binding; - updateOneTimeBinding(binding); - } - } - }; - - return Repeat; - }(AbstractRepeater), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'items', [bindable], { - enumerable: true, - initializer: null - }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'local', [bindable], { - enumerable: true, - initializer: null - }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'key', [bindable], { - enumerable: true, - initializer: null - }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, 'value', [bindable], { - enumerable: true, - initializer: null - })), _class2)) || _class) || _class) || _class)); - - _export('Repeat', Repeat); - } - }; -}); \ No newline at end of file diff --git a/dist/system/replaceable.js b/dist/system/replaceable.js deleted file mode 100644 index 32541db..0000000 --- a/dist/system/replaceable.js +++ /dev/null @@ -1,48 +0,0 @@ -'use strict'; - -System.register(['aurelia-dependency-injection', 'aurelia-templating'], function (_export, _context) { - "use strict"; - - var inject, BoundViewFactory, ViewSlot, customAttribute, templateController, _dec, _dec2, _class, Replaceable; - - - - return { - setters: [function (_aureliaDependencyInjection) { - inject = _aureliaDependencyInjection.inject; - }, function (_aureliaTemplating) { - BoundViewFactory = _aureliaTemplating.BoundViewFactory; - ViewSlot = _aureliaTemplating.ViewSlot; - customAttribute = _aureliaTemplating.customAttribute; - templateController = _aureliaTemplating.templateController; - }], - execute: function () { - _export('Replaceable', Replaceable = (_dec = customAttribute('replaceable'), _dec2 = inject(BoundViewFactory, ViewSlot), _dec(_class = templateController(_class = _dec2(_class = function () { - function Replaceable(viewFactory, viewSlot) { - - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.view = null; - } - - Replaceable.prototype.bind = function bind(bindingContext, overrideContext) { - if (this.view === null) { - this.view = this.viewFactory.create(); - this.viewSlot.add(this.view); - } - - this.view.bind(bindingContext, overrideContext); - }; - - Replaceable.prototype.unbind = function unbind() { - this.view.unbind(); - }; - - return Replaceable; - }()) || _class) || _class) || _class)); - - _export('Replaceable', Replaceable); - } - }; -}); \ No newline at end of file diff --git a/dist/system/sanitize-html.js b/dist/system/sanitize-html.js deleted file mode 100644 index daca1aa..0000000 --- a/dist/system/sanitize-html.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -System.register(['aurelia-binding', 'aurelia-dependency-injection', './html-sanitizer'], function (_export, _context) { - "use strict"; - - var valueConverter, inject, HTMLSanitizer, _dec, _dec2, _class, SanitizeHTMLValueConverter; - - - - return { - setters: [function (_aureliaBinding) { - valueConverter = _aureliaBinding.valueConverter; - }, function (_aureliaDependencyInjection) { - inject = _aureliaDependencyInjection.inject; - }, function (_htmlSanitizer) { - HTMLSanitizer = _htmlSanitizer.HTMLSanitizer; - }], - execute: function () { - _export('SanitizeHTMLValueConverter', SanitizeHTMLValueConverter = (_dec = valueConverter('sanitizeHTML'), _dec2 = inject(HTMLSanitizer), _dec(_class = _dec2(_class = function () { - function SanitizeHTMLValueConverter(sanitizer) { - - - this.sanitizer = sanitizer; - } - - SanitizeHTMLValueConverter.prototype.toView = function toView(untrustedMarkup) { - if (untrustedMarkup === null || untrustedMarkup === undefined) { - return null; - } - - return this.sanitizer.sanitize(untrustedMarkup); - }; - - return SanitizeHTMLValueConverter; - }()) || _class) || _class)); - - _export('SanitizeHTMLValueConverter', SanitizeHTMLValueConverter); - } - }; -}); \ No newline at end of file diff --git a/dist/system/self-binding-behavior.js b/dist/system/self-binding-behavior.js deleted file mode 100644 index 04611a5..0000000 --- a/dist/system/self-binding-behavior.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -System.register(['aurelia-binding'], function (_export, _context) { - "use strict"; - - var bindingBehavior, _dec, _class, SelfBindingBehavior; - - - - function findOriginalEventTarget(event) { - return event.path && event.path[0] || event.deepPath && event.deepPath[0] || event.target; - } - - function handleSelfEvent(event) { - var target = findOriginalEventTarget(event); - if (this.target !== target) return; - this.selfEventCallSource(event); - } - - return { - setters: [function (_aureliaBinding) { - bindingBehavior = _aureliaBinding.bindingBehavior; - }], - execute: function () { - _export('SelfBindingBehavior', SelfBindingBehavior = (_dec = bindingBehavior('self'), _dec(_class = function () { - function SelfBindingBehavior() { - - } - - SelfBindingBehavior.prototype.bind = function bind(binding, source) { - if (!binding.callSource || !binding.targetEvent) throw new Error('Self binding behavior only supports event.'); - binding.selfEventCallSource = binding.callSource; - binding.callSource = handleSelfEvent; - }; - - SelfBindingBehavior.prototype.unbind = function unbind(binding, source) { - binding.callSource = binding.selfEventCallSource; - binding.selfEventCallSource = null; - }; - - return SelfBindingBehavior; - }()) || _class)); - - _export('SelfBindingBehavior', SelfBindingBehavior); - } - }; -}); \ No newline at end of file diff --git a/dist/system/set-repeat-strategy.js b/dist/system/set-repeat-strategy.js deleted file mode 100644 index 5ace03c..0000000 --- a/dist/system/set-repeat-strategy.js +++ /dev/null @@ -1,113 +0,0 @@ -'use strict'; - -System.register(['./repeat-utilities'], function (_export, _context) { - "use strict"; - - var createFullOverrideContext, updateOverrideContexts, SetRepeatStrategy; - - - - return { - setters: [function (_repeatUtilities) { - createFullOverrideContext = _repeatUtilities.createFullOverrideContext; - updateOverrideContexts = _repeatUtilities.updateOverrideContexts; - }], - execute: function () { - _export('SetRepeatStrategy', SetRepeatStrategy = function () { - function SetRepeatStrategy() { - - } - - SetRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getSetObserver(items); - }; - - SetRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this._standardProcessItems(repeat, items); - }); - return; - } - this._standardProcessItems(repeat, items); - }; - - SetRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, items) { - var index = 0; - var overrideContext = void 0; - - items.forEach(function (value) { - overrideContext = createFullOverrideContext(repeat, value, index, items.size); - repeat.addView(overrideContext.bindingContext, overrideContext); - ++index; - }); - }; - - SetRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, set, records) { - var value = void 0; - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var removeIndex = void 0; - var record = void 0; - var rmPromises = []; - var viewOrPromise = void 0; - - for (i = 0, ii = records.length; i < ii; ++i) { - record = records[i]; - value = record.value; - switch (record.type) { - case 'add': - var size = Math.max(set.size - 1, 0); - overrideContext = createFullOverrideContext(repeat, value, size, set.size); - repeat.insertView(size, overrideContext.bindingContext, overrideContext); - break; - case 'delete': - removeIndex = this._getViewIndexByValue(repeat, value); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - break; - case 'clear': - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - break; - default: - continue; - } - } - - if (rmPromises.length > 0) { - Promise.all(rmPromises).then(function () { - updateOverrideContexts(repeat.views(), 0); - }); - } else { - updateOverrideContexts(repeat.views(), 0); - } - }; - - SetRepeatStrategy.prototype._getViewIndexByValue = function _getViewIndexByValue(repeat, value) { - var i = void 0; - var ii = void 0; - var child = void 0; - - for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { - child = repeat.view(i); - if (child.bindingContext[repeat.local] === value) { - return i; - } - } - - return undefined; - }; - - return SetRepeatStrategy; - }()); - - _export('SetRepeatStrategy', SetRepeatStrategy); - } - }; -}); \ No newline at end of file diff --git a/dist/system/show.js b/dist/system/show.js deleted file mode 100644 index 097ceb3..0000000 --- a/dist/system/show.js +++ /dev/null @@ -1,58 +0,0 @@ -'use strict'; - -System.register(['aurelia-dependency-injection', 'aurelia-templating', 'aurelia-pal', './aurelia-hide-style'], function (_export, _context) { - "use strict"; - - var Optional, customAttribute, Animator, DOM, injectAureliaHideStyleAtBoundary, aureliaHideClassName, _dec, _class, Show; - - - - return { - setters: [function (_aureliaDependencyInjection) { - Optional = _aureliaDependencyInjection.Optional; - }, function (_aureliaTemplating) { - customAttribute = _aureliaTemplating.customAttribute; - Animator = _aureliaTemplating.Animator; - }, function (_aureliaPal) { - DOM = _aureliaPal.DOM; - }, function (_aureliaHideStyle) { - injectAureliaHideStyleAtBoundary = _aureliaHideStyle.injectAureliaHideStyleAtBoundary; - aureliaHideClassName = _aureliaHideStyle.aureliaHideClassName; - }], - execute: function () { - _export('Show', Show = (_dec = customAttribute('show'), _dec(_class = function () { - Show.inject = function inject() { - return [DOM.Element, Animator, Optional.of(DOM.boundary, true)]; - }; - - function Show(element, animator, domBoundary) { - - - this.element = element; - this.animator = animator; - this.domBoundary = domBoundary; - } - - Show.prototype.created = function created() { - injectAureliaHideStyleAtBoundary(this.domBoundary); - }; - - Show.prototype.valueChanged = function valueChanged(newValue) { - if (newValue) { - this.animator.removeClass(this.element, aureliaHideClassName); - } else { - this.animator.addClass(this.element, aureliaHideClassName); - } - }; - - Show.prototype.bind = function bind(bindingContext) { - this.valueChanged(this.value); - }; - - return Show; - }()) || _class)); - - _export('Show', Show); - } - }; -}); \ No newline at end of file diff --git a/dist/system/signal-binding-behavior.js b/dist/system/signal-binding-behavior.js deleted file mode 100644 index bdc0bb6..0000000 --- a/dist/system/signal-binding-behavior.js +++ /dev/null @@ -1,78 +0,0 @@ -'use strict'; - -System.register(['aurelia-binding', './binding-signaler'], function (_export, _context) { - "use strict"; - - var bindingBehavior, BindingSignaler, _dec, _class, SignalBindingBehavior; - - - - return { - setters: [function (_aureliaBinding) { - bindingBehavior = _aureliaBinding.bindingBehavior; - }, function (_bindingSignaler) { - BindingSignaler = _bindingSignaler.BindingSignaler; - }], - execute: function () { - _export('SignalBindingBehavior', SignalBindingBehavior = (_dec = bindingBehavior('signal'), _dec(_class = function () { - SignalBindingBehavior.inject = function inject() { - return [BindingSignaler]; - }; - - function SignalBindingBehavior(bindingSignaler) { - - - this.signals = bindingSignaler.signals; - } - - SignalBindingBehavior.prototype.bind = function bind(binding, source) { - if (!binding.updateTarget) { - throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.'); - } - - for (var _len = arguments.length, names = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { - names[_key - 2] = arguments[_key]; - } - - if (names.length === 1) { - var name = names[0]; - var bindings = this.signals[name] || (this.signals[name] = []); - bindings.push(binding); - binding.signalName = name; - } else if (names.length > 1) { - var i = names.length; - while (i--) { - var _name = names[i]; - var _bindings = this.signals[_name] || (this.signals[_name] = []); - _bindings.push(binding); - } - binding.signalName = names; - } else { - throw new Error('Signal name is required.'); - } - }; - - SignalBindingBehavior.prototype.unbind = function unbind(binding, source) { - var name = binding.signalName; - binding.signalName = null; - if (Array.isArray(name)) { - var _names = name; - var i = _names.length; - while (i--) { - var n = _names[i]; - var bindings = this.signals[n]; - bindings.splice(bindings.indexOf(binding), 1); - } - } else { - var _bindings2 = this.signals[name]; - _bindings2.splice(_bindings2.indexOf(binding), 1); - } - }; - - return SignalBindingBehavior; - }()) || _class)); - - _export('SignalBindingBehavior', SignalBindingBehavior); - } - }; -}); \ No newline at end of file diff --git a/dist/system/throttle-binding-behavior.js b/dist/system/throttle-binding-behavior.js deleted file mode 100644 index 86ca480..0000000 --- a/dist/system/throttle-binding-behavior.js +++ /dev/null @@ -1,79 +0,0 @@ -'use strict'; - -System.register(['aurelia-binding'], function (_export, _context) { - "use strict"; - - var bindingMode, bindingBehavior, _dec, _class, ThrottleBindingBehavior; - - - - function throttle(newValue) { - var _this = this; - - var state = this.throttleState; - var elapsed = +new Date() - state.last; - if (elapsed >= state.delay) { - clearTimeout(state.timeoutId); - state.timeoutId = null; - state.last = +new Date(); - this.throttledMethod(newValue); - return; - } - state.newValue = newValue; - if (state.timeoutId === null) { - state.timeoutId = setTimeout(function () { - state.timeoutId = null; - state.last = +new Date(); - _this.throttledMethod(state.newValue); - }, state.delay - elapsed); - } - } - - return { - setters: [function (_aureliaBinding) { - bindingMode = _aureliaBinding.bindingMode; - bindingBehavior = _aureliaBinding.bindingBehavior; - }], - execute: function () { - _export('ThrottleBindingBehavior', ThrottleBindingBehavior = (_dec = bindingBehavior('throttle'), _dec(_class = function () { - function ThrottleBindingBehavior() { - - } - - ThrottleBindingBehavior.prototype.bind = function bind(binding, source) { - var delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200; - - var methodToThrottle = 'updateTarget'; - if (binding.callSource) { - methodToThrottle = 'callSource'; - } else if (binding.updateSource && binding.mode === bindingMode.twoWay) { - methodToThrottle = 'updateSource'; - } - - binding.throttledMethod = binding[methodToThrottle]; - binding.throttledMethod.originalName = methodToThrottle; - - binding[methodToThrottle] = throttle; - - binding.throttleState = { - delay: delay, - last: 0, - timeoutId: null - }; - }; - - ThrottleBindingBehavior.prototype.unbind = function unbind(binding, source) { - var methodToRestore = binding.throttledMethod.originalName; - binding[methodToRestore] = binding.throttledMethod; - binding.throttledMethod = null; - clearTimeout(binding.throttleState.timeoutId); - binding.throttleState = null; - }; - - return ThrottleBindingBehavior; - }()) || _class)); - - _export('ThrottleBindingBehavior', ThrottleBindingBehavior); - } - }; -}); \ No newline at end of file diff --git a/dist/system/update-trigger-binding-behavior.js b/dist/system/update-trigger-binding-behavior.js deleted file mode 100644 index c4a7388..0000000 --- a/dist/system/update-trigger-binding-behavior.js +++ /dev/null @@ -1,61 +0,0 @@ -'use strict'; - -System.register(['aurelia-binding'], function (_export, _context) { - "use strict"; - - var bindingMode, EventSubscriber, bindingBehavior, _dec, _class, eventNamesRequired, notApplicableMessage, UpdateTriggerBindingBehavior; - - - - return { - setters: [function (_aureliaBinding) { - bindingMode = _aureliaBinding.bindingMode; - EventSubscriber = _aureliaBinding.EventSubscriber; - bindingBehavior = _aureliaBinding.bindingBehavior; - }], - execute: function () { - eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg '; - notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.'; - - _export('UpdateTriggerBindingBehavior', UpdateTriggerBindingBehavior = (_dec = bindingBehavior('updateTrigger'), _dec(_class = function () { - function UpdateTriggerBindingBehavior() { - - } - - UpdateTriggerBindingBehavior.prototype.bind = function bind(binding, source) { - for (var _len = arguments.length, events = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { - events[_key - 2] = arguments[_key]; - } - - if (events.length === 0) { - throw new Error(eventNamesRequired); - } - if (binding.mode !== bindingMode.twoWay && binding.mode !== bindingMode.fromView) { - throw new Error(notApplicableMessage); - } - - var targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty); - if (!targetObserver.handler) { - throw new Error(notApplicableMessage); - } - binding.targetObserver = targetObserver; - - targetObserver.originalHandler = binding.targetObserver.handler; - - var handler = new EventSubscriber(events); - targetObserver.handler = handler; - }; - - UpdateTriggerBindingBehavior.prototype.unbind = function unbind(binding, source) { - binding.targetObserver.handler.dispose(); - binding.targetObserver.handler = binding.targetObserver.originalHandler; - binding.targetObserver.originalHandler = null; - }; - - return UpdateTriggerBindingBehavior; - }()) || _class)); - - _export('UpdateTriggerBindingBehavior', UpdateTriggerBindingBehavior); - } - }; -}); \ No newline at end of file diff --git a/dist/system/with.js b/dist/system/with.js deleted file mode 100644 index 1c499e9..0000000 --- a/dist/system/with.js +++ /dev/null @@ -1,62 +0,0 @@ -'use strict'; - -System.register(['aurelia-dependency-injection', 'aurelia-templating', 'aurelia-binding'], function (_export, _context) { - "use strict"; - - var inject, BoundViewFactory, ViewSlot, customAttribute, templateController, createOverrideContext, _dec, _dec2, _class, With; - - - - return { - setters: [function (_aureliaDependencyInjection) { - inject = _aureliaDependencyInjection.inject; - }, function (_aureliaTemplating) { - BoundViewFactory = _aureliaTemplating.BoundViewFactory; - ViewSlot = _aureliaTemplating.ViewSlot; - customAttribute = _aureliaTemplating.customAttribute; - templateController = _aureliaTemplating.templateController; - }, function (_aureliaBinding) { - createOverrideContext = _aureliaBinding.createOverrideContext; - }], - execute: function () { - _export('With', With = (_dec = customAttribute('with'), _dec2 = inject(BoundViewFactory, ViewSlot), _dec(_class = templateController(_class = _dec2(_class = function () { - function With(viewFactory, viewSlot) { - - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.parentOverrideContext = null; - this.view = null; - } - - With.prototype.bind = function bind(bindingContext, overrideContext) { - this.parentOverrideContext = overrideContext; - this.valueChanged(this.value); - }; - - With.prototype.valueChanged = function valueChanged(newValue) { - var overrideContext = createOverrideContext(newValue, this.parentOverrideContext); - if (!this.view) { - this.view = this.viewFactory.create(); - this.view.bind(newValue, overrideContext); - this.viewSlot.add(this.view); - } else { - this.view.bind(newValue, overrideContext); - } - }; - - With.prototype.unbind = function unbind() { - this.parentOverrideContext = null; - - if (this.view) { - this.view.unbind(); - } - }; - - return With; - }()) || _class) || _class) || _class)); - - _export('With', With); - } - }; -}); \ No newline at end of file diff --git a/dist/temp/aurelia-templating-resources.js b/dist/temp/aurelia-templating-resources.js deleted file mode 100644 index 49692c8..0000000 --- a/dist/temp/aurelia-templating-resources.js +++ /dev/null @@ -1,2191 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.Repeat = exports.RepeatStrategyLocator = exports.Show = exports.Hide = exports.SignalBindingBehavior = exports.SanitizeHTMLValueConverter = exports.If = exports.Else = exports.SetRepeatStrategy = exports.NumberRepeatStrategy = exports.MapRepeatStrategy = exports.ArrayRepeatStrategy = exports.AbstractRepeater = exports.lifecycleOptionalBehaviors = exports.AttrBindingBehavior = exports.aureliaHideClassName = exports.TwoWayBindingBehavior = exports.FromViewBindingBehavior = exports.ToViewBindingBehavior = exports.OneWayBindingBehavior = exports.OneTimeBindingBehavior = exports.BindingSignaler = exports.Compose = exports.DebounceBindingBehavior = exports.Focus = exports.HTMLSanitizer = exports.IfCore = exports.NullRepeatStrategy = exports.Replaceable = exports.SelfBindingBehavior = exports.ThrottleBindingBehavior = exports.UpdateTriggerBindingBehavior = exports.With = undefined; - -var _dec, _dec2, _class, _dec3, _class2, _dec4, _class3, _dec5, _class4, _dec6, _dec7, _class5, _dec8, _class6, _dec11, _class8, _dec13, _class10, _desc, _value, _class11, _descriptor, _descriptor2, _descriptor3, _descriptor4, _dec14, _dec15, _class14, _dec16, _dec17, _class15, _dec18, _dec19, _class16, _dec20, _dec21, _class17, _dec22, _dec23, _class18, _dec24, _class19, _dec25, _dec26, _class20, _dec27, _dec28, _dec29, _class21, _desc2, _value2, _class22, _descriptor5, _descriptor6, _descriptor7, _dec30, _dec31, _class24, _dec32, _class25, _dec33, _class26, _dec34, _class27, _dec35, _dec36, _class28, _desc3, _value3, _class29, _descriptor8, _descriptor9, _descriptor10, _descriptor11; - -exports.updateOverrideContexts = updateOverrideContexts; -exports.createFullOverrideContext = createFullOverrideContext; -exports.updateOverrideContext = updateOverrideContext; -exports.getItemsSourceExpression = getItemsSourceExpression; -exports.unwrapExpression = unwrapExpression; -exports.isOneTime = isOneTime; -exports.updateOneTimeBinding = updateOneTimeBinding; -exports.indexOf = indexOf; -exports._createDynamicElement = _createDynamicElement; -exports._createCSSResource = _createCSSResource; -exports.injectAureliaHideStyleAtHead = injectAureliaHideStyleAtHead; -exports.injectAureliaHideStyleAtBoundary = injectAureliaHideStyleAtBoundary; -exports.viewsRequireLifecycle = viewsRequireLifecycle; -exports.getElementName = getElementName; -exports.configure = configure; - -var _aureliaDependencyInjection = require('aurelia-dependency-injection'); - -var _aureliaTemplating = require('aurelia-templating'); - -var _aureliaBinding = require('aurelia-binding'); - -var _aureliaLogging = require('aurelia-logging'); - -var _aureliaTaskQueue = require('aurelia-task-queue'); - -var _aureliaPal = require('aurelia-pal'); - -var _aureliaLoader = require('aurelia-loader'); - -var _aureliaPath = require('aurelia-path'); - -var _aureliaMetadata = require('aurelia-metadata'); - -function _initDefineProp(target, property, descriptor, context) { - if (!descriptor) return; - Object.defineProperty(target, property, { - enumerable: descriptor.enumerable, - configurable: descriptor.configurable, - writable: descriptor.writable, - value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 - }); -} - -function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { - var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { - desc[key] = descriptor[key]; - }); - desc.enumerable = !!desc.enumerable; - desc.configurable = !!desc.configurable; - - if ('value' in desc || desc.initializer) { - desc.writable = true; - } - - desc = decorators.slice().reverse().reduce(function (desc, decorator) { - return decorator(target, property, desc) || desc; - }, desc); - - if (context && desc.initializer !== void 0) { - desc.value = desc.initializer ? desc.initializer.call(context) : void 0; - desc.initializer = undefined; - } - - if (desc.initializer === void 0) { - Object['define' + 'Property'](target, property, desc); - desc = null; - } - - return desc; -} - -function _initializerWarningHelper(descriptor, context) { - throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); -} - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var With = exports.With = (_dec = (0, _aureliaTemplating.customAttribute)('with'), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.ViewSlot), _dec(_class = (0, _aureliaTemplating.templateController)(_class = _dec2(_class = function () { - function With(viewFactory, viewSlot) { - _classCallCheck(this, With); - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.parentOverrideContext = null; - this.view = null; - } - - With.prototype.bind = function bind(bindingContext, overrideContext) { - this.parentOverrideContext = overrideContext; - this.valueChanged(this.value); - }; - - With.prototype.valueChanged = function valueChanged(newValue) { - var overrideContext = (0, _aureliaBinding.createOverrideContext)(newValue, this.parentOverrideContext); - if (!this.view) { - this.view = this.viewFactory.create(); - this.view.bind(newValue, overrideContext); - this.viewSlot.add(this.view); - } else { - this.view.bind(newValue, overrideContext); - } - }; - - With.prototype.unbind = function unbind() { - this.parentOverrideContext = null; - - if (this.view) { - this.view.unbind(); - } - }; - - return With; -}()) || _class) || _class) || _class); - - -var eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg '; -var notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.'; - -var UpdateTriggerBindingBehavior = exports.UpdateTriggerBindingBehavior = (_dec3 = (0, _aureliaBinding.bindingBehavior)('updateTrigger'), _dec3(_class2 = function () { - function UpdateTriggerBindingBehavior() { - _classCallCheck(this, UpdateTriggerBindingBehavior); - } - - UpdateTriggerBindingBehavior.prototype.bind = function bind(binding, source) { - for (var _len = arguments.length, events = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { - events[_key - 2] = arguments[_key]; - } - - if (events.length === 0) { - throw new Error(eventNamesRequired); - } - if (binding.mode !== _aureliaBinding.bindingMode.twoWay && binding.mode !== _aureliaBinding.bindingMode.fromView) { - throw new Error(notApplicableMessage); - } - - var targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty); - if (!targetObserver.handler) { - throw new Error(notApplicableMessage); - } - binding.targetObserver = targetObserver; - - targetObserver.originalHandler = binding.targetObserver.handler; - - var handler = new _aureliaBinding.EventSubscriber(events); - targetObserver.handler = handler; - }; - - UpdateTriggerBindingBehavior.prototype.unbind = function unbind(binding, source) { - binding.targetObserver.handler.dispose(); - binding.targetObserver.handler = binding.targetObserver.originalHandler; - binding.targetObserver.originalHandler = null; - }; - - return UpdateTriggerBindingBehavior; -}()) || _class2); - - -function throttle(newValue) { - var _this = this; - - var state = this.throttleState; - var elapsed = +new Date() - state.last; - if (elapsed >= state.delay) { - clearTimeout(state.timeoutId); - state.timeoutId = null; - state.last = +new Date(); - this.throttledMethod(newValue); - return; - } - state.newValue = newValue; - if (state.timeoutId === null) { - state.timeoutId = setTimeout(function () { - state.timeoutId = null; - state.last = +new Date(); - _this.throttledMethod(state.newValue); - }, state.delay - elapsed); - } -} - -var ThrottleBindingBehavior = exports.ThrottleBindingBehavior = (_dec4 = (0, _aureliaBinding.bindingBehavior)('throttle'), _dec4(_class3 = function () { - function ThrottleBindingBehavior() { - _classCallCheck(this, ThrottleBindingBehavior); - } - - ThrottleBindingBehavior.prototype.bind = function bind(binding, source) { - var delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200; - - var methodToThrottle = 'updateTarget'; - if (binding.callSource) { - methodToThrottle = 'callSource'; - } else if (binding.updateSource && binding.mode === _aureliaBinding.bindingMode.twoWay) { - methodToThrottle = 'updateSource'; - } - - binding.throttledMethod = binding[methodToThrottle]; - binding.throttledMethod.originalName = methodToThrottle; - - binding[methodToThrottle] = throttle; - - binding.throttleState = { - delay: delay, - last: 0, - timeoutId: null - }; - }; - - ThrottleBindingBehavior.prototype.unbind = function unbind(binding, source) { - var methodToRestore = binding.throttledMethod.originalName; - binding[methodToRestore] = binding.throttledMethod; - binding.throttledMethod = null; - clearTimeout(binding.throttleState.timeoutId); - binding.throttleState = null; - }; - - return ThrottleBindingBehavior; -}()) || _class3); - - -function findOriginalEventTarget(event) { - return event.path && event.path[0] || event.deepPath && event.deepPath[0] || event.target; -} - -function handleSelfEvent(event) { - var target = findOriginalEventTarget(event); - if (this.target !== target) return; - this.selfEventCallSource(event); -} - -var SelfBindingBehavior = exports.SelfBindingBehavior = (_dec5 = (0, _aureliaBinding.bindingBehavior)('self'), _dec5(_class4 = function () { - function SelfBindingBehavior() { - _classCallCheck(this, SelfBindingBehavior); - } - - SelfBindingBehavior.prototype.bind = function bind(binding, source) { - if (!binding.callSource || !binding.targetEvent) throw new Error('Self binding behavior only supports event.'); - binding.selfEventCallSource = binding.callSource; - binding.callSource = handleSelfEvent; - }; - - SelfBindingBehavior.prototype.unbind = function unbind(binding, source) { - binding.callSource = binding.selfEventCallSource; - binding.selfEventCallSource = null; - }; - - return SelfBindingBehavior; -}()) || _class4); -var Replaceable = exports.Replaceable = (_dec6 = (0, _aureliaTemplating.customAttribute)('replaceable'), _dec7 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.ViewSlot), _dec6(_class5 = (0, _aureliaTemplating.templateController)(_class5 = _dec7(_class5 = function () { - function Replaceable(viewFactory, viewSlot) { - _classCallCheck(this, Replaceable); - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.view = null; - } - - Replaceable.prototype.bind = function bind(bindingContext, overrideContext) { - if (this.view === null) { - this.view = this.viewFactory.create(); - this.viewSlot.add(this.view); - } - - this.view.bind(bindingContext, overrideContext); - }; - - Replaceable.prototype.unbind = function unbind() { - this.view.unbind(); - }; - - return Replaceable; -}()) || _class5) || _class5) || _class5); - - -var oneTime = _aureliaBinding.bindingMode.oneTime; - -function updateOverrideContexts(views, startIndex) { - var length = views.length; - - if (startIndex > 0) { - startIndex = startIndex - 1; - } - - for (; startIndex < length; ++startIndex) { - updateOverrideContext(views[startIndex].overrideContext, startIndex, length); - } -} - -function createFullOverrideContext(repeat, data, index, length, key) { - var bindingContext = {}; - var overrideContext = (0, _aureliaBinding.createOverrideContext)(bindingContext, repeat.scope.overrideContext); - - if (typeof key !== 'undefined') { - bindingContext[repeat.key] = key; - bindingContext[repeat.value] = data; - } else { - bindingContext[repeat.local] = data; - } - updateOverrideContext(overrideContext, index, length); - return overrideContext; -} - -function updateOverrideContext(overrideContext, index, length) { - var first = index === 0; - var last = index === length - 1; - var even = index % 2 === 0; - - overrideContext.$index = index; - overrideContext.$first = first; - overrideContext.$last = last; - overrideContext.$middle = !(first || last); - overrideContext.$odd = !even; - overrideContext.$even = even; -} - -function getItemsSourceExpression(instruction, attrName) { - return instruction.behaviorInstructions.filter(function (bi) { - return bi.originalAttrName === attrName; - })[0].attributes.items.sourceExpression; -} - -function unwrapExpression(expression) { - var unwrapped = false; - while (expression instanceof _aureliaBinding.BindingBehavior) { - expression = expression.expression; - } - while (expression instanceof _aureliaBinding.ValueConverter) { - expression = expression.expression; - unwrapped = true; - } - return unwrapped ? expression : null; -} - -function isOneTime(expression) { - while (expression instanceof _aureliaBinding.BindingBehavior) { - if (expression.name === 'oneTime') { - return true; - } - expression = expression.expression; - } - return false; -} - -function updateOneTimeBinding(binding) { - if (binding.call && binding.mode === oneTime) { - binding.call(_aureliaBinding.sourceContext); - } else if (binding.updateOneTimeBindings) { - binding.updateOneTimeBindings(); - } -} - -function indexOf(array, item, matcher, startIndex) { - if (!matcher) { - return array.indexOf(item); - } - var length = array.length; - for (var index = startIndex || 0; index < length; index++) { - if (matcher(array[index], item)) { - return index; - } - } - return -1; -} - -var NullRepeatStrategy = exports.NullRepeatStrategy = function () { - function NullRepeatStrategy() { - _classCallCheck(this, NullRepeatStrategy); - } - - NullRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - repeat.removeAllViews(true); - }; - - NullRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) {}; - - return NullRepeatStrategy; -}(); - -var IfCore = exports.IfCore = function () { - function IfCore(viewFactory, viewSlot) { - _classCallCheck(this, IfCore); - - this.viewFactory = viewFactory; - this.viewSlot = viewSlot; - this.view = null; - this.bindingContext = null; - this.overrideContext = null; - - this.showing = false; - this.cache = true; - } - - IfCore.prototype.bind = function bind(bindingContext, overrideContext) { - this.bindingContext = bindingContext; - this.overrideContext = overrideContext; - }; - - IfCore.prototype.unbind = function unbind() { - if (this.view === null) { - return; - } - - this.view.unbind(); - - if (!this.viewFactory.isCaching) { - return; - } - - if (this.showing) { - this.showing = false; - this.viewSlot.remove(this.view, true, true); - } else { - this.view.returnToCache(); - } - - this.view = null; - }; - - IfCore.prototype._show = function _show() { - if (this.showing) { - if (!this.view.isBound) { - this.view.bind(this.bindingContext, this.overrideContext); - } - return; - } - - if (this.view === null) { - this.view = this.viewFactory.create(); - } - - if (!this.view.isBound) { - this.view.bind(this.bindingContext, this.overrideContext); - } - - this.showing = true; - return this.viewSlot.add(this.view); - }; - - IfCore.prototype._hide = function _hide() { - var _this2 = this; - - if (!this.showing) { - return; - } - - this.showing = false; - var removed = this.viewSlot.remove(this.view); - - if (removed instanceof Promise) { - return removed.then(function () { - _this2._unbindView(); - }); - } - - this._unbindView(); - }; - - IfCore.prototype._unbindView = function _unbindView() { - var cache = this.cache === 'false' ? false : !!this.cache; - this.view.unbind(); - if (!cache) { - this.view = null; - } - }; - - return IfCore; -}(); - -var SCRIPT_REGEX = /)<[^<]*)*<\/script>/gi; -var needsToWarn = true; - -var HTMLSanitizer = exports.HTMLSanitizer = function () { - function HTMLSanitizer() { - _classCallCheck(this, HTMLSanitizer); - } - - HTMLSanitizer.prototype.sanitize = function sanitize(input) { - if (needsToWarn) { - needsToWarn = false; - - (0, _aureliaLogging.getLogger)('html-sanitizer').warn('CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks,\n and should not be relied on for sanitizing input from unknown sources.\n Please see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html.'); - } - - return input.replace(SCRIPT_REGEX, ''); - }; - - return HTMLSanitizer; -}(); - -var Focus = exports.Focus = (_dec8 = (0, _aureliaTemplating.customAttribute)('focus', _aureliaBinding.bindingMode.twoWay), _dec8(_class6 = function () { - Focus.inject = function inject() { - return [_aureliaPal.DOM.Element, _aureliaTaskQueue.TaskQueue]; - }; - - function Focus(element, taskQueue) { - _classCallCheck(this, Focus); - - this.element = element; - this.taskQueue = taskQueue; - this.isAttached = false; - this.needsApply = false; - } - - Focus.prototype.valueChanged = function valueChanged(newValue) { - if (this.isAttached) { - this._apply(); - } else { - this.needsApply = true; - } - }; - - Focus.prototype._apply = function _apply() { - var _this3 = this; - - if (this.value) { - this.taskQueue.queueMicroTask(function () { - if (_this3.value) { - _this3.element.focus(); - } - }); - } else { - this.element.blur(); - } - }; - - Focus.prototype.attached = function attached() { - this.isAttached = true; - if (this.needsApply) { - this.needsApply = false; - this._apply(); - } - this.element.addEventListener('focus', this); - this.element.addEventListener('blur', this); - }; - - Focus.prototype.detached = function detached() { - this.isAttached = false; - this.element.removeEventListener('focus', this); - this.element.removeEventListener('blur', this); - }; - - Focus.prototype.handleEvent = function handleEvent(e) { - if (e.type === 'focus') { - this.value = true; - } else if (_aureliaPal.DOM.activeElement !== this.element) { - this.value = false; - } - }; - - return Focus; -}()) || _class6); -function _createDynamicElement(_ref) { - var _dec9, _dec10, _class7; - - var name = _ref.name, - viewUrl = _ref.viewUrl, - bindableNames = _ref.bindableNames, - useShadowDOMmode = _ref.useShadowDOMmode; - var DynamicElement = (_dec9 = (0, _aureliaTemplating.customElement)(name), _dec10 = (0, _aureliaTemplating.useView)(viewUrl), _dec9(_class7 = _dec10(_class7 = function () { - function DynamicElement() { - _classCallCheck(this, DynamicElement); - } - - DynamicElement.prototype.bind = function bind(bindingContext) { - this.$parent = bindingContext; - }; - - return DynamicElement; - }()) || _class7) || _class7); - - - for (var i = 0, ii = bindableNames.length; i < ii; ++i) { - (0, _aureliaTemplating.bindable)(bindableNames[i])(DynamicElement); - } - - switch (useShadowDOMmode) { - case 'open': - (0, _aureliaTemplating.useShadowDOM)({ mode: 'open' })(DynamicElement); - break; - - case 'closed': - (0, _aureliaTemplating.useShadowDOM)({ mode: 'closed' })(DynamicElement); - break; - - case '': - (0, _aureliaTemplating.useShadowDOM)(DynamicElement); - break; - - case null: - break; - - default: - (0, _aureliaLogging.getLogger)('aurelia-html-only-element').warn('Expected \'use-shadow-dom\' value to be "close", "open" or "", received ' + useShadowDOMmode); - break; - } - - return DynamicElement; -} - -var unset = {}; - -function debounceCallSource(event) { - var _this4 = this; - - var state = this.debounceState; - clearTimeout(state.timeoutId); - state.timeoutId = setTimeout(function () { - return _this4.debouncedMethod(event); - }, state.delay); -} - -function debounceCall(context, newValue, oldValue) { - var _this5 = this; - - var state = this.debounceState; - clearTimeout(state.timeoutId); - if (context !== state.callContextToDebounce) { - state.oldValue = unset; - this.debouncedMethod(context, newValue, oldValue); - return; - } - if (state.oldValue === unset) { - state.oldValue = oldValue; - } - state.timeoutId = setTimeout(function () { - var _oldValue = state.oldValue; - state.oldValue = unset; - _this5.debouncedMethod(context, newValue, _oldValue); - }, state.delay); -} - -var DebounceBindingBehavior = exports.DebounceBindingBehavior = (_dec11 = (0, _aureliaBinding.bindingBehavior)('debounce'), _dec11(_class8 = function () { - function DebounceBindingBehavior() { - _classCallCheck(this, DebounceBindingBehavior); - } - - DebounceBindingBehavior.prototype.bind = function bind(binding, source) { - var delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200; - - var isCallSource = binding.callSource !== undefined; - var methodToDebounce = isCallSource ? 'callSource' : 'call'; - var debouncer = isCallSource ? debounceCallSource : debounceCall; - var mode = binding.mode; - var callContextToDebounce = mode === _aureliaBinding.bindingMode.twoWay || mode === _aureliaBinding.bindingMode.fromView ? _aureliaBinding.targetContext : _aureliaBinding.sourceContext; - - binding.debouncedMethod = binding[methodToDebounce]; - binding.debouncedMethod.originalName = methodToDebounce; - - binding[methodToDebounce] = debouncer; - - binding.debounceState = { - callContextToDebounce: callContextToDebounce, - delay: delay, - timeoutId: 0, - oldValue: unset - }; - }; - - DebounceBindingBehavior.prototype.unbind = function unbind(binding, source) { - var methodToRestore = binding.debouncedMethod.originalName; - binding[methodToRestore] = binding.debouncedMethod; - binding.debouncedMethod = null; - clearTimeout(binding.debounceState.timeoutId); - binding.debounceState = null; - }; - - return DebounceBindingBehavior; -}()) || _class8); - -var cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi; - -function fixupCSSUrls(address, css) { - if (typeof css !== 'string') { - throw new Error('Failed loading required CSS file: ' + address); - } - return css.replace(cssUrlMatcher, function (match, p1) { - var quote = p1.charAt(0); - if (quote === '\'' || quote === '"') { - p1 = p1.substr(1, p1.length - 2); - } - return 'url(\'' + (0, _aureliaPath.relativeToFile)(p1, address) + '\')'; - }); -} - -var CSSResource = function () { - function CSSResource(address) { - _classCallCheck(this, CSSResource); - - this.address = address; - this._scoped = null; - this._global = false; - this._alreadyGloballyInjected = false; - } - - CSSResource.prototype.initialize = function initialize(container, target) { - this._scoped = new target(this); - }; - - CSSResource.prototype.register = function register(registry, name) { - if (name === 'scoped') { - registry.registerViewEngineHooks(this._scoped); - } else { - this._global = true; - } - }; - - CSSResource.prototype.load = function load(container) { - var _this6 = this; - - return container.get(_aureliaLoader.Loader).loadText(this.address).catch(function (err) { - return null; - }).then(function (text) { - text = fixupCSSUrls(_this6.address, text); - _this6._scoped.css = text; - if (_this6._global) { - _this6._alreadyGloballyInjected = true; - _aureliaPal.DOM.injectStyles(text); - } - }); - }; - - return CSSResource; -}(); - -var CSSViewEngineHooks = function () { - function CSSViewEngineHooks(owner) { - _classCallCheck(this, CSSViewEngineHooks); - - this.owner = owner; - this.css = null; - } - - CSSViewEngineHooks.prototype.beforeCompile = function beforeCompile(content, resources, instruction) { - if (instruction.targetShadowDOM) { - _aureliaPal.DOM.injectStyles(this.css, content, true); - } else if (_aureliaPal.FEATURE.scopedCSS) { - var styleNode = _aureliaPal.DOM.injectStyles(this.css, content, true); - styleNode.setAttribute('scoped', 'scoped'); - } else if (this._global && !this.owner._alreadyGloballyInjected) { - _aureliaPal.DOM.injectStyles(this.css); - this.owner._alreadyGloballyInjected = true; - } - }; - - return CSSViewEngineHooks; -}(); - -function _createCSSResource(address) { - var _dec12, _class9; - - var ViewCSS = (_dec12 = (0, _aureliaTemplating.resource)(new CSSResource(address)), _dec12(_class9 = function (_CSSViewEngineHooks) { - _inherits(ViewCSS, _CSSViewEngineHooks); - - function ViewCSS() { - _classCallCheck(this, ViewCSS); - - return _possibleConstructorReturn(this, _CSSViewEngineHooks.apply(this, arguments)); - } - - return ViewCSS; - }(CSSViewEngineHooks)) || _class9); - - return ViewCSS; -} - -var Compose = exports.Compose = (_dec13 = (0, _aureliaTemplating.customElement)('compose'), _dec13(_class10 = (0, _aureliaTemplating.noView)(_class10 = (_class11 = function () { - Compose.inject = function inject() { - return [_aureliaPal.DOM.Element, _aureliaDependencyInjection.Container, _aureliaTemplating.CompositionEngine, _aureliaTemplating.ViewSlot, _aureliaTemplating.ViewResources, _aureliaTaskQueue.TaskQueue]; - }; - - function Compose(element, container, compositionEngine, viewSlot, viewResources, taskQueue) { - _classCallCheck(this, Compose); - - _initDefineProp(this, 'model', _descriptor, this); - - _initDefineProp(this, 'view', _descriptor2, this); - - _initDefineProp(this, 'viewModel', _descriptor3, this); - - _initDefineProp(this, 'swapOrder', _descriptor4, this); - - this.element = element; - this.container = container; - this.compositionEngine = compositionEngine; - this.viewSlot = viewSlot; - this.viewResources = viewResources; - this.taskQueue = taskQueue; - this.currentController = null; - this.currentViewModel = null; - this.changes = Object.create(null); - } - - Compose.prototype.created = function created(owningView) { - this.owningView = owningView; - }; - - Compose.prototype.bind = function bind(bindingContext, overrideContext) { - this.bindingContext = bindingContext; - this.overrideContext = overrideContext; - this.changes.view = this.view; - this.changes.viewModel = this.viewModel; - this.changes.model = this.model; - if (!this.pendingTask) { - processChanges(this); - } - }; - - Compose.prototype.unbind = function unbind() { - this.changes = Object.create(null); - this.bindingContext = null; - this.overrideContext = null; - var returnToCache = true; - var skipAnimation = true; - this.viewSlot.removeAll(returnToCache, skipAnimation); - }; - - Compose.prototype.modelChanged = function modelChanged(newValue, oldValue) { - this.changes.model = newValue; - requestUpdate(this); - }; - - Compose.prototype.viewChanged = function viewChanged(newValue, oldValue) { - this.changes.view = newValue; - requestUpdate(this); - }; - - Compose.prototype.viewModelChanged = function viewModelChanged(newValue, oldValue) { - this.changes.viewModel = newValue; - requestUpdate(this); - }; - - return Compose; -}(), (_descriptor = _applyDecoratedDescriptor(_class11.prototype, 'model', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -}), _descriptor2 = _applyDecoratedDescriptor(_class11.prototype, 'view', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -}), _descriptor3 = _applyDecoratedDescriptor(_class11.prototype, 'viewModel', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -}), _descriptor4 = _applyDecoratedDescriptor(_class11.prototype, 'swapOrder', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -})), _class11)) || _class10) || _class10); - - -function isEmpty(obj) { - for (var key in obj) { - return false; - } - return true; -} - -function tryActivateViewModel(vm, model) { - if (vm && typeof vm.activate === 'function') { - return Promise.resolve(vm.activate(model)); - } -} - -function createInstruction(composer, instruction) { - return Object.assign(instruction, { - bindingContext: composer.bindingContext, - overrideContext: composer.overrideContext, - owningView: composer.owningView, - container: composer.container, - viewSlot: composer.viewSlot, - viewResources: composer.viewResources, - currentController: composer.currentController, - host: composer.element, - swapOrder: composer.swapOrder - }); -} - -function processChanges(composer) { - var changes = composer.changes; - composer.changes = Object.create(null); - - if (!('view' in changes) && !('viewModel' in changes) && 'model' in changes) { - composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model); - if (!composer.pendingTask) { - return; - } - } else { - var instruction = { - view: composer.view, - viewModel: composer.currentViewModel || composer.viewModel, - model: composer.model - }; - - instruction = Object.assign(instruction, changes); - - instruction = createInstruction(composer, instruction); - composer.pendingTask = composer.compositionEngine.compose(instruction).then(function (controller) { - composer.currentController = controller; - composer.currentViewModel = controller ? controller.viewModel : null; - }); - } - - composer.pendingTask = composer.pendingTask.then(function () { - completeCompositionTask(composer); - }, function (reason) { - completeCompositionTask(composer); - throw reason; - }); -} - -function completeCompositionTask(composer) { - composer.pendingTask = null; - if (!isEmpty(composer.changes)) { - processChanges(composer); - } -} - -function requestUpdate(composer) { - if (composer.pendingTask || composer.updateRequested) { - return; - } - composer.updateRequested = true; - composer.taskQueue.queueMicroTask(function () { - composer.updateRequested = false; - processChanges(composer); - }); -} - -var BindingSignaler = exports.BindingSignaler = function () { - function BindingSignaler() { - _classCallCheck(this, BindingSignaler); - - this.signals = {}; - } - - BindingSignaler.prototype.signal = function signal(name) { - var bindings = this.signals[name]; - if (!bindings) { - return; - } - var i = bindings.length; - while (i--) { - bindings[i].call(_aureliaBinding.sourceContext); - } - }; - - return BindingSignaler; -}(); - -var modeBindingBehavior = { - bind: function bind(binding, source, lookupFunctions) { - binding.originalMode = binding.mode; - binding.mode = this.mode; - }, - unbind: function unbind(binding, source) { - binding.mode = binding.originalMode; - binding.originalMode = null; - } -}; - -var OneTimeBindingBehavior = exports.OneTimeBindingBehavior = (_dec14 = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec15 = (0, _aureliaBinding.bindingBehavior)('oneTime'), _dec14(_class14 = _dec15(_class14 = function OneTimeBindingBehavior() { - _classCallCheck(this, OneTimeBindingBehavior); - - this.mode = _aureliaBinding.bindingMode.oneTime; -}) || _class14) || _class14); -var OneWayBindingBehavior = exports.OneWayBindingBehavior = (_dec16 = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec17 = (0, _aureliaBinding.bindingBehavior)('oneWay'), _dec16(_class15 = _dec17(_class15 = function OneWayBindingBehavior() { - _classCallCheck(this, OneWayBindingBehavior); - - this.mode = _aureliaBinding.bindingMode.toView; -}) || _class15) || _class15); -var ToViewBindingBehavior = exports.ToViewBindingBehavior = (_dec18 = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec19 = (0, _aureliaBinding.bindingBehavior)('toView'), _dec18(_class16 = _dec19(_class16 = function ToViewBindingBehavior() { - _classCallCheck(this, ToViewBindingBehavior); - - this.mode = _aureliaBinding.bindingMode.toView; -}) || _class16) || _class16); -var FromViewBindingBehavior = exports.FromViewBindingBehavior = (_dec20 = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec21 = (0, _aureliaBinding.bindingBehavior)('fromView'), _dec20(_class17 = _dec21(_class17 = function FromViewBindingBehavior() { - _classCallCheck(this, FromViewBindingBehavior); - - this.mode = _aureliaBinding.bindingMode.fromView; -}) || _class17) || _class17); -var TwoWayBindingBehavior = exports.TwoWayBindingBehavior = (_dec22 = (0, _aureliaMetadata.mixin)(modeBindingBehavior), _dec23 = (0, _aureliaBinding.bindingBehavior)('twoWay'), _dec22(_class18 = _dec23(_class18 = function TwoWayBindingBehavior() { - _classCallCheck(this, TwoWayBindingBehavior); - - this.mode = _aureliaBinding.bindingMode.twoWay; -}) || _class18) || _class18); -var aureliaHideClassName = exports.aureliaHideClassName = 'aurelia-hide'; - -var aureliaHideClass = '.' + aureliaHideClassName + ' { display:none !important; }'; - -function injectAureliaHideStyleAtHead() { - _aureliaPal.DOM.injectStyles(aureliaHideClass); -} - -function injectAureliaHideStyleAtBoundary(domBoundary) { - if (_aureliaPal.FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) { - domBoundary.hasAureliaHideStyle = true; - _aureliaPal.DOM.injectStyles(aureliaHideClass, domBoundary); - } -} - -var AttrBindingBehavior = exports.AttrBindingBehavior = (_dec24 = (0, _aureliaBinding.bindingBehavior)('attr'), _dec24(_class19 = function () { - function AttrBindingBehavior() { - _classCallCheck(this, AttrBindingBehavior); - } - - AttrBindingBehavior.prototype.bind = function bind(binding, source) { - binding.targetObserver = new _aureliaBinding.DataAttributeObserver(binding.target, binding.targetProperty); - }; - - AttrBindingBehavior.prototype.unbind = function unbind(binding, source) {}; - - return AttrBindingBehavior; -}()) || _class19); -var lifecycleOptionalBehaviors = exports.lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with']; - -function behaviorRequiresLifecycle(instruction) { - var t = instruction.type; - var name = t.elementName !== null ? t.elementName : t.attributeName; - return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind) || t.viewFactory && viewsRequireLifecycle(t.viewFactory) || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); -} - -function targetRequiresLifecycle(instruction) { - var behaviors = instruction.behaviorInstructions; - if (behaviors) { - var i = behaviors.length; - while (i--) { - if (behaviorRequiresLifecycle(behaviors[i])) { - return true; - } - } - } - - return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory); -} - -function viewsRequireLifecycle(viewFactory) { - if ('_viewsRequireLifecycle' in viewFactory) { - return viewFactory._viewsRequireLifecycle; - } - - viewFactory._viewsRequireLifecycle = false; - - if (viewFactory.viewFactory) { - viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory); - return viewFactory._viewsRequireLifecycle; - } - - if (viewFactory.template.querySelector('.au-animate')) { - viewFactory._viewsRequireLifecycle = true; - return true; - } - - for (var id in viewFactory.instructions) { - if (targetRequiresLifecycle(viewFactory.instructions[id])) { - viewFactory._viewsRequireLifecycle = true; - return true; - } - } - - viewFactory._viewsRequireLifecycle = false; - return false; -} - -var AbstractRepeater = exports.AbstractRepeater = function () { - function AbstractRepeater(options) { - _classCallCheck(this, AbstractRepeater); - - Object.assign(this, { - local: 'items', - viewsRequireLifecycle: true - }, options); - } - - AbstractRepeater.prototype.viewCount = function viewCount() { - throw new Error('subclass must implement `viewCount`'); - }; - - AbstractRepeater.prototype.views = function views() { - throw new Error('subclass must implement `views`'); - }; - - AbstractRepeater.prototype.view = function view(index) { - throw new Error('subclass must implement `view`'); - }; - - AbstractRepeater.prototype.matcher = function matcher() { - throw new Error('subclass must implement `matcher`'); - }; - - AbstractRepeater.prototype.addView = function addView(bindingContext, overrideContext) { - throw new Error('subclass must implement `addView`'); - }; - - AbstractRepeater.prototype.insertView = function insertView(index, bindingContext, overrideContext) { - throw new Error('subclass must implement `insertView`'); - }; - - AbstractRepeater.prototype.moveView = function moveView(sourceIndex, targetIndex) { - throw new Error('subclass must implement `moveView`'); - }; - - AbstractRepeater.prototype.removeAllViews = function removeAllViews(returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeAllViews`'); - }; - - AbstractRepeater.prototype.removeViews = function removeViews(viewsToRemove, returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeView`'); - }; - - AbstractRepeater.prototype.removeView = function removeView(index, returnToCache, skipAnimation) { - throw new Error('subclass must implement `removeView`'); - }; - - AbstractRepeater.prototype.updateBindings = function updateBindings(view) { - throw new Error('subclass must implement `updateBindings`'); - }; - - return AbstractRepeater; -}(); - -var ArrayRepeatStrategy = exports.ArrayRepeatStrategy = function () { - function ArrayRepeatStrategy() { - _classCallCheck(this, ArrayRepeatStrategy); - } - - ArrayRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getArrayObserver(items); - }; - - ArrayRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this8 = this; - - var itemsLength = items.length; - - if (!items || itemsLength === 0) { - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - return; - } - - var children = repeat.views(); - var viewsLength = children.length; - - if (viewsLength === 0) { - this._standardProcessInstanceChanged(repeat, items); - return; - } - - if (repeat.viewsRequireLifecycle) { - var childrenSnapshot = children.slice(0); - var itemNameInBindingContext = repeat.local; - var matcher = repeat.matcher(); - - var itemsPreviouslyInViews = []; - var viewsToRemove = []; - - for (var index = 0; index < viewsLength; index++) { - var view = childrenSnapshot[index]; - var oldItem = view.bindingContext[itemNameInBindingContext]; - - if (indexOf(items, oldItem, matcher) === -1) { - viewsToRemove.push(view); - } else { - itemsPreviouslyInViews.push(oldItem); - } - } - - var updateViews = void 0; - var removePromise = void 0; - - if (itemsPreviouslyInViews.length > 0) { - removePromise = repeat.removeViews(viewsToRemove, true, !repeat.viewsRequireLifecycle); - updateViews = function updateViews() { - for (var _index = 0; _index < itemsLength; _index++) { - var item = items[_index]; - var indexOfView = indexOf(itemsPreviouslyInViews, item, matcher, _index); - var _view = void 0; - - if (indexOfView === -1) { - var overrideContext = createFullOverrideContext(repeat, items[_index], _index, itemsLength); - repeat.insertView(_index, overrideContext.bindingContext, overrideContext); - - itemsPreviouslyInViews.splice(_index, 0, undefined); - } else if (indexOfView === _index) { - _view = children[indexOfView]; - itemsPreviouslyInViews[indexOfView] = undefined; - } else { - _view = children[indexOfView]; - repeat.moveView(indexOfView, _index); - itemsPreviouslyInViews.splice(indexOfView, 1); - itemsPreviouslyInViews.splice(_index, 0, undefined); - } - - if (_view) { - updateOverrideContext(_view.overrideContext, _index, itemsLength); - } - } - - _this8._inPlaceProcessItems(repeat, items); - }; - } else { - removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - updateViews = function updateViews() { - return _this8._standardProcessInstanceChanged(repeat, items); - }; - } - - if (removePromise instanceof Promise) { - removePromise.then(updateViews); - } else { - updateViews(); - } - } else { - this._inPlaceProcessItems(repeat, items); - } - }; - - ArrayRepeatStrategy.prototype._standardProcessInstanceChanged = function _standardProcessInstanceChanged(repeat, items) { - for (var i = 0, ii = items.length; i < ii; i++) { - var overrideContext = createFullOverrideContext(repeat, items[i], i, ii); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - }; - - ArrayRepeatStrategy.prototype._inPlaceProcessItems = function _inPlaceProcessItems(repeat, items) { - var itemsLength = items.length; - var viewsLength = repeat.viewCount(); - - while (viewsLength > itemsLength) { - viewsLength--; - repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle); - } - - var local = repeat.local; - - for (var i = 0; i < viewsLength; i++) { - var view = repeat.view(i); - var last = i === itemsLength - 1; - var middle = i !== 0 && !last; - - if (view.bindingContext[local] === items[i] && view.overrideContext.$middle === middle && view.overrideContext.$last === last) { - continue; - } - - view.bindingContext[local] = items[i]; - view.overrideContext.$middle = middle; - view.overrideContext.$last = last; - repeat.updateBindings(view); - } - - for (var _i = viewsLength; _i < itemsLength; _i++) { - var overrideContext = createFullOverrideContext(repeat, items[_i], _i, itemsLength); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - }; - - ArrayRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, array, splices) { - var _this9 = this; - - if (repeat.__queuedSplices) { - for (var i = 0, ii = splices.length; i < ii; ++i) { - var _splices$i = splices[i], - index = _splices$i.index, - removed = _splices$i.removed, - addedCount = _splices$i.addedCount; - - (0, _aureliaBinding.mergeSplice)(repeat.__queuedSplices, index, removed, addedCount); - } - - repeat.__array = array.slice(0); - return; - } - - var maybePromise = this._runSplices(repeat, array.slice(0), splices); - if (maybePromise instanceof Promise) { - var queuedSplices = repeat.__queuedSplices = []; - - var runQueuedSplices = function runQueuedSplices() { - if (!queuedSplices.length) { - repeat.__queuedSplices = undefined; - repeat.__array = undefined; - return; - } - - var nextPromise = _this9._runSplices(repeat, repeat.__array, queuedSplices) || Promise.resolve(); - queuedSplices = repeat.__queuedSplices = []; - nextPromise.then(runQueuedSplices); - }; - - maybePromise.then(runQueuedSplices); - } - }; - - ArrayRepeatStrategy.prototype._runSplices = function _runSplices(repeat, array, splices) { - var _this10 = this; - - var removeDelta = 0; - var rmPromises = []; - - for (var i = 0, ii = splices.length; i < ii; ++i) { - var splice = splices[i]; - var removed = splice.removed; - - for (var j = 0, jj = removed.length; j < jj; ++j) { - var viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - } - removeDelta -= splice.addedCount; - } - - if (rmPromises.length > 0) { - return Promise.all(rmPromises).then(function () { - var spliceIndexLow = _this10._handleAddedSplices(repeat, array, splices); - updateOverrideContexts(repeat.views(), spliceIndexLow); - }); - } - - var spliceIndexLow = this._handleAddedSplices(repeat, array, splices); - updateOverrideContexts(repeat.views(), spliceIndexLow); - - return undefined; - }; - - ArrayRepeatStrategy.prototype._handleAddedSplices = function _handleAddedSplices(repeat, array, splices) { - var spliceIndex = void 0; - var spliceIndexLow = void 0; - var arrayLength = array.length; - for (var i = 0, ii = splices.length; i < ii; ++i) { - var splice = splices[i]; - var addIndex = spliceIndex = splice.index; - var end = splice.index + splice.addedCount; - - if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) { - spliceIndexLow = spliceIndex; - } - - for (; addIndex < end; ++addIndex) { - var overrideContext = createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength); - repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext); - } - } - - return spliceIndexLow; - }; - - return ArrayRepeatStrategy; -}(); - -var MapRepeatStrategy = exports.MapRepeatStrategy = function () { - function MapRepeatStrategy() { - _classCallCheck(this, MapRepeatStrategy); - } - - MapRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getMapObserver(items); - }; - - MapRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this11 = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this11._standardProcessItems(repeat, items); - }); - return; - } - this._standardProcessItems(repeat, items); - }; - - MapRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, items) { - var index = 0; - var overrideContext = void 0; - - items.forEach(function (value, key) { - overrideContext = createFullOverrideContext(repeat, value, index, items.size, key); - repeat.addView(overrideContext.bindingContext, overrideContext); - ++index; - }); - }; - - MapRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, map, records) { - var key = void 0; - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var removeIndex = void 0; - var addIndex = void 0; - var record = void 0; - var rmPromises = []; - var viewOrPromise = void 0; - - for (i = 0, ii = records.length; i < ii; ++i) { - record = records[i]; - key = record.key; - switch (record.type) { - case 'update': - removeIndex = this._getViewIndexByKey(repeat, key); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - overrideContext = createFullOverrideContext(repeat, map.get(key), removeIndex, map.size, key); - repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext); - break; - case 'add': - addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1; - overrideContext = createFullOverrideContext(repeat, map.get(key), addIndex, map.size, key); - repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext); - break; - case 'delete': - if (record.oldValue === undefined) { - return; - } - removeIndex = this._getViewIndexByKey(repeat, key); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - break; - case 'clear': - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - break; - default: - continue; - } - } - - if (rmPromises.length > 0) { - Promise.all(rmPromises).then(function () { - updateOverrideContexts(repeat.views(), 0); - }); - } else { - updateOverrideContexts(repeat.views(), 0); - } - }; - - MapRepeatStrategy.prototype._getViewIndexByKey = function _getViewIndexByKey(repeat, key) { - var i = void 0; - var ii = void 0; - var child = void 0; - - for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { - child = repeat.view(i); - if (child.bindingContext[repeat.key] === key) { - return i; - } - } - - return undefined; - }; - - return MapRepeatStrategy; -}(); - -var NumberRepeatStrategy = exports.NumberRepeatStrategy = function () { - function NumberRepeatStrategy() { - _classCallCheck(this, NumberRepeatStrategy); - } - - NumberRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver() { - return null; - }; - - NumberRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, value) { - var _this12 = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this12._standardProcessItems(repeat, value); - }); - return; - } - this._standardProcessItems(repeat, value); - }; - - NumberRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, value) { - var childrenLength = repeat.viewCount(); - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var viewsToRemove = void 0; - - value = Math.floor(value); - viewsToRemove = childrenLength - value; - - if (viewsToRemove > 0) { - if (viewsToRemove > childrenLength) { - viewsToRemove = childrenLength; - } - - for (i = 0, ii = viewsToRemove; i < ii; ++i) { - repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle); - } - - return; - } - - for (i = childrenLength, ii = value; i < ii; ++i) { - overrideContext = createFullOverrideContext(repeat, i, i, ii); - repeat.addView(overrideContext.bindingContext, overrideContext); - } - - updateOverrideContexts(repeat.views(), 0); - }; - - return NumberRepeatStrategy; -}(); - -var SetRepeatStrategy = exports.SetRepeatStrategy = function () { - function SetRepeatStrategy() { - _classCallCheck(this, SetRepeatStrategy); - } - - SetRepeatStrategy.prototype.getCollectionObserver = function getCollectionObserver(observerLocator, items) { - return observerLocator.getSetObserver(items); - }; - - SetRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) { - var _this13 = this; - - var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - if (removePromise instanceof Promise) { - removePromise.then(function () { - return _this13._standardProcessItems(repeat, items); - }); - return; - } - this._standardProcessItems(repeat, items); - }; - - SetRepeatStrategy.prototype._standardProcessItems = function _standardProcessItems(repeat, items) { - var index = 0; - var overrideContext = void 0; - - items.forEach(function (value) { - overrideContext = createFullOverrideContext(repeat, value, index, items.size); - repeat.addView(overrideContext.bindingContext, overrideContext); - ++index; - }); - }; - - SetRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, set, records) { - var value = void 0; - var i = void 0; - var ii = void 0; - var overrideContext = void 0; - var removeIndex = void 0; - var record = void 0; - var rmPromises = []; - var viewOrPromise = void 0; - - for (i = 0, ii = records.length; i < ii; ++i) { - record = records[i]; - value = record.value; - switch (record.type) { - case 'add': - var size = Math.max(set.size - 1, 0); - overrideContext = createFullOverrideContext(repeat, value, size, set.size); - repeat.insertView(size, overrideContext.bindingContext, overrideContext); - break; - case 'delete': - removeIndex = this._getViewIndexByValue(repeat, value); - viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle); - if (viewOrPromise instanceof Promise) { - rmPromises.push(viewOrPromise); - } - break; - case 'clear': - repeat.removeAllViews(true, !repeat.viewsRequireLifecycle); - break; - default: - continue; - } - } - - if (rmPromises.length > 0) { - Promise.all(rmPromises).then(function () { - updateOverrideContexts(repeat.views(), 0); - }); - } else { - updateOverrideContexts(repeat.views(), 0); - } - }; - - SetRepeatStrategy.prototype._getViewIndexByValue = function _getViewIndexByValue(repeat, value) { - var i = void 0; - var ii = void 0; - var child = void 0; - - for (i = 0, ii = repeat.viewCount(); i < ii; ++i) { - child = repeat.view(i); - if (child.bindingContext[repeat.local] === value) { - return i; - } - } - - return undefined; - }; - - return SetRepeatStrategy; -}(); - -var Else = exports.Else = (_dec25 = (0, _aureliaTemplating.customAttribute)('else'), _dec26 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.ViewSlot), _dec25(_class20 = (0, _aureliaTemplating.templateController)(_class20 = _dec26(_class20 = function (_IfCore) { - _inherits(Else, _IfCore); - - function Else(viewFactory, viewSlot) { - _classCallCheck(this, Else); - - var _this14 = _possibleConstructorReturn(this, _IfCore.call(this, viewFactory, viewSlot)); - - _this14._registerInIf(); - return _this14; - } - - Else.prototype.bind = function bind(bindingContext, overrideContext) { - _IfCore.prototype.bind.call(this, bindingContext, overrideContext); - - if (this.ifVm.condition) { - this._hide(); - } else { - this._show(); - } - }; - - Else.prototype._registerInIf = function _registerInIf() { - var previous = this.viewSlot.anchor.previousSibling; - while (previous && !previous.au) { - previous = previous.previousSibling; - } - if (!previous || !previous.au.if) { - throw new Error("Can't find matching If for Else custom attribute."); - } - this.ifVm = previous.au.if.viewModel; - this.ifVm.elseVm = this; - }; - - return Else; -}(IfCore)) || _class20) || _class20) || _class20); -var If = exports.If = (_dec27 = (0, _aureliaTemplating.customAttribute)('if'), _dec28 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.ViewSlot), _dec29 = (0, _aureliaTemplating.bindable)({ primaryProperty: true }), _dec27(_class21 = (0, _aureliaTemplating.templateController)(_class21 = _dec28(_class21 = (_class22 = function (_IfCore2) { - _inherits(If, _IfCore2); - - function If() { - var _temp, _this15, _ret; - - _classCallCheck(this, If); - - for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { - args[_key2] = arguments[_key2]; - } - - return _ret = (_temp = (_this15 = _possibleConstructorReturn(this, _IfCore2.call.apply(_IfCore2, [this].concat(args))), _this15), _initDefineProp(_this15, 'condition', _descriptor5, _this15), _initDefineProp(_this15, 'swapOrder', _descriptor6, _this15), _initDefineProp(_this15, 'cache', _descriptor7, _this15), _temp), _possibleConstructorReturn(_this15, _ret); - } - - If.prototype.bind = function bind(bindingContext, overrideContext) { - _IfCore2.prototype.bind.call(this, bindingContext, overrideContext); - if (this.condition) { - this._show(); - } else { - this._hide(); - } - }; - - If.prototype.conditionChanged = function conditionChanged(newValue) { - this._update(newValue); - }; - - If.prototype._update = function _update(show) { - var _this16 = this; - - if (this.animating) { - return; - } - - var promise = void 0; - if (this.elseVm) { - promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm); - } else { - promise = show ? this._show() : this._hide(); - } - - if (promise) { - this.animating = true; - promise.then(function () { - _this16.animating = false; - if (_this16.condition !== _this16.showing) { - _this16._update(_this16.condition); - } - }); - } - }; - - If.prototype._swap = function _swap(remove, add) { - switch (this.swapOrder) { - case 'before': - return Promise.resolve(add._show()).then(function () { - return remove._hide(); - }); - case 'with': - return Promise.all([remove._hide(), add._show()]); - default: - var promise = remove._hide(); - return promise ? promise.then(function () { - return add._show(); - }) : add._show(); - } - }; - - return If; -}(IfCore), (_descriptor5 = _applyDecoratedDescriptor(_class22.prototype, 'condition', [_dec29], { - enumerable: true, - initializer: null -}), _descriptor6 = _applyDecoratedDescriptor(_class22.prototype, 'swapOrder', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -}), _descriptor7 = _applyDecoratedDescriptor(_class22.prototype, 'cache', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: function initializer() { - return true; - } -})), _class22)) || _class21) || _class21) || _class21); -var SanitizeHTMLValueConverter = exports.SanitizeHTMLValueConverter = (_dec30 = (0, _aureliaBinding.valueConverter)('sanitizeHTML'), _dec31 = (0, _aureliaDependencyInjection.inject)(HTMLSanitizer), _dec30(_class24 = _dec31(_class24 = function () { - function SanitizeHTMLValueConverter(sanitizer) { - _classCallCheck(this, SanitizeHTMLValueConverter); - - this.sanitizer = sanitizer; - } - - SanitizeHTMLValueConverter.prototype.toView = function toView(untrustedMarkup) { - if (untrustedMarkup === null || untrustedMarkup === undefined) { - return null; - } - - return this.sanitizer.sanitize(untrustedMarkup); - }; - - return SanitizeHTMLValueConverter; -}()) || _class24) || _class24); -function getElementName(address) { - return (/([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase() - ); -} - -function configure(config) { - var viewEngine = config.container.get(_aureliaTemplating.ViewEngine); - var loader = config.aurelia.loader; - - viewEngine.addResourcePlugin('.html', { - 'fetch': function fetch(viewUrl) { - return loader.loadTemplate(viewUrl).then(function (registryEntry) { - var _ref2; - - var bindableNames = registryEntry.template.getAttribute('bindable'); - var useShadowDOMmode = registryEntry.template.getAttribute('use-shadow-dom'); - var name = getElementName(viewUrl); - - if (bindableNames) { - bindableNames = bindableNames.split(',').map(function (x) { - return x.trim(); - }); - registryEntry.template.removeAttribute('bindable'); - } else { - bindableNames = []; - } - - return _ref2 = {}, _ref2[name] = _createDynamicElement({ name: name, viewUrl: viewUrl, bindableNames: bindableNames, useShadowDOMmode: useShadowDOMmode }), _ref2; - }); - } - }); -} - -var SignalBindingBehavior = exports.SignalBindingBehavior = (_dec32 = (0, _aureliaBinding.bindingBehavior)('signal'), _dec32(_class25 = function () { - SignalBindingBehavior.inject = function inject() { - return [BindingSignaler]; - }; - - function SignalBindingBehavior(bindingSignaler) { - _classCallCheck(this, SignalBindingBehavior); - - this.signals = bindingSignaler.signals; - } - - SignalBindingBehavior.prototype.bind = function bind(binding, source) { - if (!binding.updateTarget) { - throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.'); - } - - for (var _len3 = arguments.length, names = Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) { - names[_key3 - 2] = arguments[_key3]; - } - - if (names.length === 1) { - var name = names[0]; - var bindings = this.signals[name] || (this.signals[name] = []); - bindings.push(binding); - binding.signalName = name; - } else if (names.length > 1) { - var i = names.length; - while (i--) { - var _name = names[i]; - var _bindings = this.signals[_name] || (this.signals[_name] = []); - _bindings.push(binding); - } - binding.signalName = names; - } else { - throw new Error('Signal name is required.'); - } - }; - - SignalBindingBehavior.prototype.unbind = function unbind(binding, source) { - var name = binding.signalName; - binding.signalName = null; - if (Array.isArray(name)) { - var _names = name; - var i = _names.length; - while (i--) { - var n = _names[i]; - var bindings = this.signals[n]; - bindings.splice(bindings.indexOf(binding), 1); - } - } else { - var _bindings2 = this.signals[name]; - _bindings2.splice(_bindings2.indexOf(binding), 1); - } - }; - - return SignalBindingBehavior; -}()) || _class25); -var Hide = exports.Hide = (_dec33 = (0, _aureliaTemplating.customAttribute)('hide'), _dec33(_class26 = function () { - Hide.inject = function inject() { - return [_aureliaPal.DOM.Element, _aureliaTemplating.Animator, _aureliaDependencyInjection.Optional.of(_aureliaPal.DOM.boundary, true)]; - }; - - function Hide(element, animator, domBoundary) { - _classCallCheck(this, Hide); - - this.element = element; - this.animator = animator; - this.domBoundary = domBoundary; - } - - Hide.prototype.created = function created() { - injectAureliaHideStyleAtBoundary(this.domBoundary); - }; - - Hide.prototype.valueChanged = function valueChanged(newValue) { - if (newValue) { - this.animator.addClass(this.element, aureliaHideClassName); - } else { - this.animator.removeClass(this.element, aureliaHideClassName); - } - }; - - Hide.prototype.bind = function bind(bindingContext) { - this.valueChanged(this.value); - }; - - return Hide; -}()) || _class26); -var Show = exports.Show = (_dec34 = (0, _aureliaTemplating.customAttribute)('show'), _dec34(_class27 = function () { - Show.inject = function inject() { - return [_aureliaPal.DOM.Element, _aureliaTemplating.Animator, _aureliaDependencyInjection.Optional.of(_aureliaPal.DOM.boundary, true)]; - }; - - function Show(element, animator, domBoundary) { - _classCallCheck(this, Show); - - this.element = element; - this.animator = animator; - this.domBoundary = domBoundary; - } - - Show.prototype.created = function created() { - injectAureliaHideStyleAtBoundary(this.domBoundary); - }; - - Show.prototype.valueChanged = function valueChanged(newValue) { - if (newValue) { - this.animator.removeClass(this.element, aureliaHideClassName); - } else { - this.animator.addClass(this.element, aureliaHideClassName); - } - }; - - Show.prototype.bind = function bind(bindingContext) { - this.valueChanged(this.value); - }; - - return Show; -}()) || _class27); - -var RepeatStrategyLocator = exports.RepeatStrategyLocator = function () { - function RepeatStrategyLocator() { - _classCallCheck(this, RepeatStrategyLocator); - - this.matchers = []; - this.strategies = []; - - this.addStrategy(function (items) { - return items === null || items === undefined; - }, new NullRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Array; - }, new ArrayRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Map; - }, new MapRepeatStrategy()); - this.addStrategy(function (items) { - return items instanceof Set; - }, new SetRepeatStrategy()); - this.addStrategy(function (items) { - return typeof items === 'number'; - }, new NumberRepeatStrategy()); - } - - RepeatStrategyLocator.prototype.addStrategy = function addStrategy(matcher, strategy) { - this.matchers.push(matcher); - this.strategies.push(strategy); - }; - - RepeatStrategyLocator.prototype.getStrategy = function getStrategy(items) { - var matchers = this.matchers; - - for (var i = 0, ii = matchers.length; i < ii; ++i) { - if (matchers[i](items)) { - return this.strategies[i]; - } - } - - return null; - }; - - return RepeatStrategyLocator; -}(); - -var Repeat = exports.Repeat = (_dec35 = (0, _aureliaTemplating.customAttribute)('repeat'), _dec36 = (0, _aureliaDependencyInjection.inject)(_aureliaTemplating.BoundViewFactory, _aureliaTemplating.TargetInstruction, _aureliaTemplating.ViewSlot, _aureliaTemplating.ViewResources, _aureliaBinding.ObserverLocator, RepeatStrategyLocator), _dec35(_class28 = (0, _aureliaTemplating.templateController)(_class28 = _dec36(_class28 = (_class29 = function (_AbstractRepeater) { - _inherits(Repeat, _AbstractRepeater); - - function Repeat(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) { - _classCallCheck(this, Repeat); - - var _this17 = _possibleConstructorReturn(this, _AbstractRepeater.call(this, { - local: 'item', - viewsRequireLifecycle: viewsRequireLifecycle(viewFactory) - })); - - _initDefineProp(_this17, 'items', _descriptor8, _this17); - - _initDefineProp(_this17, 'local', _descriptor9, _this17); - - _initDefineProp(_this17, 'key', _descriptor10, _this17); - - _initDefineProp(_this17, 'value', _descriptor11, _this17); - - _this17.viewFactory = viewFactory; - _this17.instruction = instruction; - _this17.viewSlot = viewSlot; - _this17.lookupFunctions = viewResources.lookupFunctions; - _this17.observerLocator = observerLocator; - _this17.key = 'key'; - _this17.value = 'value'; - _this17.strategyLocator = strategyLocator; - _this17.ignoreMutation = false; - _this17.sourceExpression = getItemsSourceExpression(_this17.instruction, 'repeat.for'); - _this17.isOneTime = isOneTime(_this17.sourceExpression); - _this17.viewsRequireLifecycle = viewsRequireLifecycle(viewFactory); - return _this17; - } - - Repeat.prototype.call = function call(context, changes) { - this[context](this.items, changes); - }; - - Repeat.prototype.bind = function bind(bindingContext, overrideContext) { - this.scope = { bindingContext: bindingContext, overrideContext: overrideContext }; - this.matcherBinding = this._captureAndRemoveMatcherBinding(); - this.itemsChanged(); - }; - - Repeat.prototype.unbind = function unbind() { - this.scope = null; - this.items = null; - this.matcherBinding = null; - this.viewSlot.removeAll(true, true); - this._unsubscribeCollection(); - }; - - Repeat.prototype._unsubscribeCollection = function _unsubscribeCollection() { - if (this.collectionObserver) { - this.collectionObserver.unsubscribe(this.callContext, this); - this.collectionObserver = null; - this.callContext = null; - } - }; - - Repeat.prototype.itemsChanged = function itemsChanged() { - var _this18 = this; - - this._unsubscribeCollection(); - - if (!this.scope) { - return; - } - - var items = this.items; - this.strategy = this.strategyLocator.getStrategy(items); - if (!this.strategy) { - throw new Error('Value for \'' + this.sourceExpression + '\' is non-repeatable'); - } - - if (!this.isOneTime && !this._observeInnerCollection()) { - this._observeCollection(); - } - this.ignoreMutation = true; - this.strategy.instanceChanged(this, items); - this.observerLocator.taskQueue.queueMicroTask(function () { - _this18.ignoreMutation = false; - }); - }; - - Repeat.prototype._getInnerCollection = function _getInnerCollection() { - var expression = unwrapExpression(this.sourceExpression); - if (!expression) { - return null; - } - return expression.evaluate(this.scope, null); - }; - - Repeat.prototype.handleCollectionMutated = function handleCollectionMutated(collection, changes) { - if (!this.collectionObserver) { - return; - } - if (this.ignoreMutation) { - return; - } - this.strategy.instanceMutated(this, collection, changes); - }; - - Repeat.prototype.handleInnerCollectionMutated = function handleInnerCollectionMutated(collection, changes) { - var _this19 = this; - - if (!this.collectionObserver) { - return; - } - - if (this.ignoreMutation) { - return; - } - this.ignoreMutation = true; - var newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions); - this.observerLocator.taskQueue.queueMicroTask(function () { - return _this19.ignoreMutation = false; - }); - - if (newItems === this.items) { - this.itemsChanged(); - } else { - this.items = newItems; - } - }; - - Repeat.prototype._observeInnerCollection = function _observeInnerCollection() { - var items = this._getInnerCollection(); - var strategy = this.strategyLocator.getStrategy(items); - if (!strategy) { - return false; - } - this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items); - if (!this.collectionObserver) { - return false; - } - this.callContext = 'handleInnerCollectionMutated'; - this.collectionObserver.subscribe(this.callContext, this); - return true; - }; - - Repeat.prototype._observeCollection = function _observeCollection() { - var items = this.items; - this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items); - if (this.collectionObserver) { - this.callContext = 'handleCollectionMutated'; - this.collectionObserver.subscribe(this.callContext, this); - } - }; - - Repeat.prototype._captureAndRemoveMatcherBinding = function _captureAndRemoveMatcherBinding() { - if (this.viewFactory.viewFactory) { - var instructions = this.viewFactory.viewFactory.instructions; - var instructionIds = Object.keys(instructions); - for (var i = 0; i < instructionIds.length; i++) { - var expressions = instructions[instructionIds[i]].expressions; - if (expressions) { - for (var ii = 0; i < expressions.length; i++) { - if (expressions[ii].targetProperty === 'matcher') { - var matcherBinding = expressions[ii]; - expressions.splice(ii, 1); - return matcherBinding; - } - } - } - } - } - - return undefined; - }; - - Repeat.prototype.viewCount = function viewCount() { - return this.viewSlot.children.length; - }; - - Repeat.prototype.views = function views() { - return this.viewSlot.children; - }; - - Repeat.prototype.view = function view(index) { - return this.viewSlot.children[index]; - }; - - Repeat.prototype.matcher = function matcher() { - return this.matcherBinding ? this.matcherBinding.sourceExpression.evaluate(this.scope, this.matcherBinding.lookupFunctions) : null; - }; - - Repeat.prototype.addView = function addView(bindingContext, overrideContext) { - var view = this.viewFactory.create(); - view.bind(bindingContext, overrideContext); - this.viewSlot.add(view); - }; - - Repeat.prototype.insertView = function insertView(index, bindingContext, overrideContext) { - var view = this.viewFactory.create(); - view.bind(bindingContext, overrideContext); - this.viewSlot.insert(index, view); - }; - - Repeat.prototype.moveView = function moveView(sourceIndex, targetIndex) { - this.viewSlot.move(sourceIndex, targetIndex); - }; - - Repeat.prototype.removeAllViews = function removeAllViews(returnToCache, skipAnimation) { - return this.viewSlot.removeAll(returnToCache, skipAnimation); - }; - - Repeat.prototype.removeViews = function removeViews(viewsToRemove, returnToCache, skipAnimation) { - return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation); - }; - - Repeat.prototype.removeView = function removeView(index, returnToCache, skipAnimation) { - return this.viewSlot.removeAt(index, returnToCache, skipAnimation); - }; - - Repeat.prototype.updateBindings = function updateBindings(view) { - var j = view.bindings.length; - while (j--) { - updateOneTimeBinding(view.bindings[j]); - } - j = view.controllers.length; - while (j--) { - var k = view.controllers[j].boundProperties.length; - while (k--) { - var binding = view.controllers[j].boundProperties[k].binding; - updateOneTimeBinding(binding); - } - } - }; - - return Repeat; -}(AbstractRepeater), (_descriptor8 = _applyDecoratedDescriptor(_class29.prototype, 'items', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -}), _descriptor9 = _applyDecoratedDescriptor(_class29.prototype, 'local', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -}), _descriptor10 = _applyDecoratedDescriptor(_class29.prototype, 'key', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -}), _descriptor11 = _applyDecoratedDescriptor(_class29.prototype, 'value', [_aureliaTemplating.bindable], { - enumerable: true, - initializer: null -})), _class29)) || _class28) || _class28) || _class28); \ No newline at end of file diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 308b712..f8865e0 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,7 @@ +# [1.10.0](https://github.com/aurelia/templating-resources/compare/1.9.1...1.10.0) (2019-05-02) + + + ## [1.9.1](https://github.com/aurelia/templating-resources/compare/1.9.0...1.9.1) (2019-03-28) diff --git a/package.json b/package.json index 944ddfb..f043546 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-templating-resources", - "version": "1.9.1", + "version": "1.10.0", "description": "A standard set of behaviors, converters and other resources for use with the Aurelia templating library.", "keywords": [ "aurelia",