From eebfe8aaf4581ed989c71b46b2defd8efdfd0783 Mon Sep 17 00:00:00 2001 From: Christian Kotzbauer Date: Sat, 5 Dec 2020 11:41:56 +0100 Subject: [PATCH] chore: release 2.4.1 Signed-off-by: Christian Kotzbauer --- dist/amd/knockout-composition.js | 26 +++++++++++++++++---- dist/commonjs/knockout-composition.js | 26 +++++++++++++++++---- dist/es2015/knockout-composition.js | 26 +++++++++++++++++---- dist/es2017/knockout-composition.js | 26 +++++++++++++++++---- dist/native-modules/knockout-composition.js | 26 +++++++++++++++++---- dist/system/knockout-composition.js | 26 +++++++++++++++++---- doc/CHANGELOG.md | 15 ++++++++++++ package-lock.json | 2 +- package.json | 2 +- 9 files changed, 143 insertions(+), 32 deletions(-) diff --git a/dist/amd/knockout-composition.js b/dist/amd/knockout-composition.js index de745eb..ff6e2a0 100644 --- a/dist/amd/knockout-composition.js +++ b/dist/amd/knockout-composition.js @@ -20,11 +20,23 @@ define(["require", "exports", "knockout", "aurelia-dependency-injection", "aurel } return null; } + function getAuTarget(elements) { + var _a; + for (var i = 0; i < elements.length; i++) { + if ((_a = elements.item(i)) === null || _a === void 0 ? void 0 : _a.classList.contains("au-target")) { + return elements.item(i); + } + } + return null; + } function callEvent(element, eventName, args) { - var viewModel = ko.dataFor(element.children[0]); - var func = viewModel[eventName]; - if (func && typeof func === 'function') { - func.apply(viewModel, args); + var target = getAuTarget(element.children); + if (target) { + var viewModel = ko.dataFor(target); + var func = viewModel[eventName]; + if (func && typeof func === 'function') { + func.apply(viewModel, args); + } } } function doComposition(element, unwrappedValue, viewModel) { @@ -70,7 +82,7 @@ define(["require", "exports", "knockout", "aurelia-dependency-injection", "aurel window.ko = ko; } ko.bindingHandlers.compose = { - update: function (element, valueAccessor, allBindings, viewModel) { + update: function (element, valueAccessor, allBindings, viewModel, bindingContext) { var value = valueAccessor(); if (element.childElementCount > 0) { // Remove previous composed view @@ -79,6 +91,10 @@ define(["require", "exports", "knockout", "aurelia-dependency-injection", "aurel element.removeChild(element.firstChild); } } + if (viewModel) { + viewModel.$parent = viewModel.$parent || bindingContext.$parent; + viewModel.$root = viewModel.$root || bindingContext.$root; + } doComposition.call(_this, element, ko.unwrap(value), viewModel); } }; diff --git a/dist/commonjs/knockout-composition.js b/dist/commonjs/knockout-composition.js index f143c47..1fa73f4 100644 --- a/dist/commonjs/knockout-composition.js +++ b/dist/commonjs/knockout-composition.js @@ -23,11 +23,23 @@ function getMatchingProperty(result, propName) { } return null; } +function getAuTarget(elements) { + var _a; + for (var i = 0; i < elements.length; i++) { + if ((_a = elements.item(i)) === null || _a === void 0 ? void 0 : _a.classList.contains("au-target")) { + return elements.item(i); + } + } + return null; +} function callEvent(element, eventName, args) { - var viewModel = ko.dataFor(element.children[0]); - var func = viewModel[eventName]; - if (func && typeof func === 'function') { - func.apply(viewModel, args); + var target = getAuTarget(element.children); + if (target) { + var viewModel = ko.dataFor(target); + var func = viewModel[eventName]; + if (func && typeof func === 'function') { + func.apply(viewModel, args); + } } } function doComposition(element, unwrappedValue, viewModel) { @@ -73,7 +85,7 @@ var KnockoutComposition = /** @class */ (function () { window.ko = ko; } ko.bindingHandlers.compose = { - update: function (element, valueAccessor, allBindings, viewModel) { + update: function (element, valueAccessor, allBindings, viewModel, bindingContext) { var value = valueAccessor(); if (element.childElementCount > 0) { // Remove previous composed view @@ -82,6 +94,10 @@ var KnockoutComposition = /** @class */ (function () { element.removeChild(element.firstChild); } } + if (viewModel) { + viewModel.$parent = viewModel.$parent || bindingContext.$parent; + viewModel.$root = viewModel.$root || bindingContext.$root; + } doComposition.call(_this, element, ko.unwrap(value), viewModel); } }; diff --git a/dist/es2015/knockout-composition.js b/dist/es2015/knockout-composition.js index c4c6eaa..357ae3a 100644 --- a/dist/es2015/knockout-composition.js +++ b/dist/es2015/knockout-composition.js @@ -21,11 +21,23 @@ function getMatchingProperty(result, propName) { } return null; } +function getAuTarget(elements) { + var _a; + for (let i = 0; i < elements.length; i++) { + if ((_a = elements.item(i)) === null || _a === void 0 ? void 0 : _a.classList.contains("au-target")) { + return elements.item(i); + } + } + return null; +} function callEvent(element, eventName, args) { - const viewModel = ko.dataFor(element.children[0]); - const func = viewModel[eventName]; - if (func && typeof func === 'function') { - func.apply(viewModel, args); + const target = getAuTarget(element.children); + if (target) { + const viewModel = ko.dataFor(target); + const func = viewModel[eventName]; + if (func && typeof func === 'function') { + func.apply(viewModel, args); + } } } function doComposition(element, unwrappedValue, viewModel) { @@ -68,7 +80,7 @@ let KnockoutComposition = class KnockoutComposition { window.ko = ko; } ko.bindingHandlers.compose = { - update: (element, valueAccessor, allBindings, viewModel) => { + update: (element, valueAccessor, allBindings, viewModel, bindingContext) => { const value = valueAccessor(); if (element.childElementCount > 0) { // Remove previous composed view @@ -77,6 +89,10 @@ let KnockoutComposition = class KnockoutComposition { element.removeChild(element.firstChild); } } + if (viewModel) { + viewModel.$parent = viewModel.$parent || bindingContext.$parent; + viewModel.$root = viewModel.$root || bindingContext.$root; + } doComposition.call(this, element, ko.unwrap(value), viewModel); } }; diff --git a/dist/es2017/knockout-composition.js b/dist/es2017/knockout-composition.js index c4c6eaa..357ae3a 100644 --- a/dist/es2017/knockout-composition.js +++ b/dist/es2017/knockout-composition.js @@ -21,11 +21,23 @@ function getMatchingProperty(result, propName) { } return null; } +function getAuTarget(elements) { + var _a; + for (let i = 0; i < elements.length; i++) { + if ((_a = elements.item(i)) === null || _a === void 0 ? void 0 : _a.classList.contains("au-target")) { + return elements.item(i); + } + } + return null; +} function callEvent(element, eventName, args) { - const viewModel = ko.dataFor(element.children[0]); - const func = viewModel[eventName]; - if (func && typeof func === 'function') { - func.apply(viewModel, args); + const target = getAuTarget(element.children); + if (target) { + const viewModel = ko.dataFor(target); + const func = viewModel[eventName]; + if (func && typeof func === 'function') { + func.apply(viewModel, args); + } } } function doComposition(element, unwrappedValue, viewModel) { @@ -68,7 +80,7 @@ let KnockoutComposition = class KnockoutComposition { window.ko = ko; } ko.bindingHandlers.compose = { - update: (element, valueAccessor, allBindings, viewModel) => { + update: (element, valueAccessor, allBindings, viewModel, bindingContext) => { const value = valueAccessor(); if (element.childElementCount > 0) { // Remove previous composed view @@ -77,6 +89,10 @@ let KnockoutComposition = class KnockoutComposition { element.removeChild(element.firstChild); } } + if (viewModel) { + viewModel.$parent = viewModel.$parent || bindingContext.$parent; + viewModel.$root = viewModel.$root || bindingContext.$root; + } doComposition.call(this, element, ko.unwrap(value), viewModel); } }; diff --git a/dist/native-modules/knockout-composition.js b/dist/native-modules/knockout-composition.js index 3fbceaa..c66e307 100644 --- a/dist/native-modules/knockout-composition.js +++ b/dist/native-modules/knockout-composition.js @@ -21,11 +21,23 @@ function getMatchingProperty(result, propName) { } return null; } +function getAuTarget(elements) { + var _a; + for (var i = 0; i < elements.length; i++) { + if ((_a = elements.item(i)) === null || _a === void 0 ? void 0 : _a.classList.contains("au-target")) { + return elements.item(i); + } + } + return null; +} function callEvent(element, eventName, args) { - var viewModel = ko.dataFor(element.children[0]); - var func = viewModel[eventName]; - if (func && typeof func === 'function') { - func.apply(viewModel, args); + var target = getAuTarget(element.children); + if (target) { + var viewModel = ko.dataFor(target); + var func = viewModel[eventName]; + if (func && typeof func === 'function') { + func.apply(viewModel, args); + } } } function doComposition(element, unwrappedValue, viewModel) { @@ -71,7 +83,7 @@ var KnockoutComposition = /** @class */ (function () { window.ko = ko; } ko.bindingHandlers.compose = { - update: function (element, valueAccessor, allBindings, viewModel) { + update: function (element, valueAccessor, allBindings, viewModel, bindingContext) { var value = valueAccessor(); if (element.childElementCount > 0) { // Remove previous composed view @@ -80,6 +92,10 @@ var KnockoutComposition = /** @class */ (function () { element.removeChild(element.firstChild); } } + if (viewModel) { + viewModel.$parent = viewModel.$parent || bindingContext.$parent; + viewModel.$root = viewModel.$root || bindingContext.$root; + } doComposition.call(_this, element, ko.unwrap(value), viewModel); } }; diff --git a/dist/system/knockout-composition.js b/dist/system/knockout-composition.js index 5f35044..55807a8 100644 --- a/dist/system/knockout-composition.js +++ b/dist/system/knockout-composition.js @@ -21,11 +21,23 @@ System.register(["knockout", "aurelia-dependency-injection", "aurelia-loader", " } return null; } + function getAuTarget(elements) { + var _a; + for (var i = 0; i < elements.length; i++) { + if ((_a = elements.item(i)) === null || _a === void 0 ? void 0 : _a.classList.contains("au-target")) { + return elements.item(i); + } + } + return null; + } function callEvent(element, eventName, args) { - var viewModel = ko.dataFor(element.children[0]); - var func = viewModel[eventName]; - if (func && typeof func === 'function') { - func.apply(viewModel, args); + var target = getAuTarget(element.children); + if (target) { + var viewModel = ko.dataFor(target); + var func = viewModel[eventName]; + if (func && typeof func === 'function') { + func.apply(viewModel, args); + } } } function doComposition(element, unwrappedValue, viewModel) { @@ -87,7 +99,7 @@ System.register(["knockout", "aurelia-dependency-injection", "aurelia-loader", " window.ko = ko; } ko.bindingHandlers.compose = { - update: function (element, valueAccessor, allBindings, viewModel) { + update: function (element, valueAccessor, allBindings, viewModel, bindingContext) { var value = valueAccessor(); if (element.childElementCount > 0) { // Remove previous composed view @@ -96,6 +108,10 @@ System.register(["knockout", "aurelia-dependency-injection", "aurelia-loader", " element.removeChild(element.firstChild); } } + if (viewModel) { + viewModel.$parent = viewModel.$parent || bindingContext.$parent; + viewModel.$root = viewModel.$root || bindingContext.$root; + } doComposition.call(_this, element, ko.unwrap(value), viewModel); } }; diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 9ca03eb..5830b27 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## Version 2.4.1 + +Released on December 5, 2020. + +- Fix: Preserve `$root` and `$parent` context when composing with `with` directive. +- Fix: Use first bound element to fetch view-model from. + + +## Version 2.4.0 + +Released on February 23, 2020. + +- Updated dependencies + + ## Version 2.3.0 Released on July 27, 2018. diff --git a/package-lock.json b/package-lock.json index c5624cf..89e3296 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "aurelia-knockout", - "version": "2.4.0", + "version": "2.4.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9eefdb3..68dc12e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-knockout", - "version": "2.4.0", + "version": "2.4.1", "main": "dist/commonjs/aurelia-knockout.js", "author": "Christian Kotzbauer (Twitter: https://twitter.com/ckotzbauer1)", "license": "MIT",