From 92a6027aa09a9293d94575f798c36ac3c7d7d45d Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 23 Sep 2024 17:02:51 +0200 Subject: [PATCH] Improved Knockout property binding error --- .../build/output/knockout-latest.debug.js | 13 +++--- .../knockout/build/output/knockout-latest.js | 46 +++++++++---------- .../src/binding/defaultBindings/checked.js | 2 +- .../src/binding/defaultBindings/hasfocus.js | 2 +- .../src/binding/defaultBindings/textInput.js | 2 +- .../src/binding/defaultBindings/value.js | 2 +- .../src/binding/expressionRewriting.js | 5 +- 7 files changed, 37 insertions(+), 35 deletions(-) diff --git a/vendors/knockout/build/output/knockout-latest.debug.js b/vendors/knockout/build/output/knockout-latest.debug.js index 94087363f..0de9f2dee 100644 --- a/vendors/knockout/build/output/knockout-latest.debug.js +++ b/vendors/knockout/build/output/knockout-latest.debug.js @@ -1460,6 +1460,7 @@ ko.expressionRewriting = (() => { -1 < keyValueArray.findIndex(v => v['key'] == key), // Internal, private KO utility for updating model properties from within bindings + // element: the HTML element it belongs to // property: If the property being updated is (or might be) an observable, pass it here // If it turns out to be a writable observable, it will be written to directly // allBindings: An object with a get method to retrieve bindings in the current execution context. @@ -1468,9 +1469,9 @@ ko.expressionRewriting = (() => { // value: The value to be written // checkIfDifferent: If true, and if the property being written is a writable observable, the value will only be written if // it is !== existing value on that writable observable - writeValueToProperty: (property, allBindings, key, value, checkIfDifferent) => { + writeValueToProperty: (element, property, allBindings, key, value, checkIfDifferent) => { if (!property || !ko.isObservable(property)) { - throw Error(`${key} , must be observable`); + throw Error(`"${key}" must be observable for ${element.outerHTML.replace(/>.+/,'>')}`); // allBindings.get('_ko_property_writers')?.[key]?.(value); } else if (ko.isWriteableObservable(property) && (!checkIfDifferent || property.peek() !== value)) { property(value); @@ -2353,7 +2354,7 @@ ko.bindingHandlers['checked'] = { elemValue = undefined; } } - ko.expressionRewriting.writeValueToProperty(modelValue, allBindings, 'checked', elemValue, true); + ko.expressionRewriting.writeValueToProperty(element, modelValue, allBindings, 'checked', elemValue, true); } } @@ -2514,7 +2515,7 @@ ko.bindingHandlers['hasfocus'] = { // Discussion at https://github.com/SteveSanderson/knockout/pull/352 element[hasfocusUpdatingProperty] = true; isFocused = (element.ownerDocument.activeElement === element); - ko.expressionRewriting.writeValueToProperty(valueAccessor(), allBindings, 'hasfocus', isFocused, true); + ko.expressionRewriting.writeValueToProperty(element, valueAccessor(), allBindings, 'hasfocus', isFocused, true); //cache the latest value, so we can avoid unnecessarily calling focus/blur in the update function element[hasfocusLastValue] = isFocused; @@ -2825,7 +2826,7 @@ ko.bindingHandlers['textInput'] = { if (element.checkValidity() && previousElementValue !== elementValue) { // Provide a way for tests to know exactly which event was processed previousElementValue = elementValue; - ko.expressionRewriting.writeValueToProperty(valueAccessor(), allBindings, 'textInput', elementValue); + ko.expressionRewriting.writeValueToProperty(element, valueAccessor(), allBindings, 'textInput', elementValue); } }; @@ -2878,7 +2879,7 @@ ko.bindingHandlers['value'] = { elementValueBeforeEvent = null; var modelValue = valueAccessor(); var elementValue = ko.selectExtensions.readValue(element); - ko.expressionRewriting.writeValueToProperty(modelValue, allBindings, 'value', elementValue); + ko.expressionRewriting.writeValueToProperty(element, modelValue, allBindings, 'value', elementValue); }; if (requestedEventsToCatch) { diff --git a/vendors/knockout/build/output/knockout-latest.js b/vendors/knockout/build/output/knockout-latest.js index d76eca028..3c32d29bf 100644 --- a/vendors/knockout/build/output/knockout-latest.js +++ b/vendors/knockout/build/output/knockout-latest.js @@ -28,33 +28,33 @@ null,d.G=0,b.T()&&b.Ea();else{var e=[];c.g.K(d.v,(g,l)=>e[l.fa]=g);e.forEach((g, c.o);c.isComputed=a=>"function"==typeof a&&a[O]===K[O];c.xb=a=>{if("function"===typeof a)return c.o(a,{pure:!0});a={...a,pure:!0};return c.o(a)};c.C={M:a=>{switch(a.nodeName){case "OPTION":return!0===a.__ko__hasDomDataOptionValue__?c.g.l.get(a,c.i.options.Wa):a.value;case "SELECT":return 0<=a.selectedIndex?c.C.M(a.options[a.selectedIndex]):void 0;default:return a.value}},Fa:(a,b)=>{switch(a.nodeName){case "OPTION":"string"===typeof b?(c.g.l.set(a,c.i.options.Wa,void 0),delete a.__ko__hasDomDataOptionValue__, a.value=b):(c.g.l.set(a,c.i.options.Wa,b),a.__ko__hasDomDataOptionValue__=!0,a.value="number"===typeof b?b:"");break;case "SELECT":for(var d=-1,e=""===(b??""),g=a.options.length,l;g--;)if(l=c.C.M(a.options[g]),l==b||""===l&&e){d=g;break}if(0<=d||e&&1{var a=RegExp("\"(?:\\\\.|[^\"])*\"|'(?:\\\\.|[^'])*'|`(?:\\\\.|[^`])*`|/\\*(?:[^*]|\\*+[^*/])*\\*+/|//.*\n|/(?:\\\\.|[^/])+/w*|[^\\s:,/][^,\"'`{}()/:[\\]]*[^\\s,\"'`{}()/:[\\]]|[^\\s]", "g"),b=/[\])"'A-Za-z0-9_$]+$/,d={"in":1,"return":1,"typeof":1},e=g=>{g=c.g.Bb(g);123===g.charCodeAt(0)&&(g=g.slice(1,-1));g+="\n,";var l=[],f=g.match(a),h=[],k=0;if(1=k){l.push(q&&h.length?{key:q,value:h.join("")}:{unknown:q||h.join("")});var q=k=0;h=[];continue}}else if(58===m){if(!k&&!q&&1===h.length){q=h.pop();continue}}else if(47===m&&1{var l=[];e(g).forEach(f=>{l.push("'"+(f.key||f.unknown)+"':function(){return "+(f.value+" }"))});return l.join(",")},cc:(g,l)=>-1f.key==l),Ga:(g,l,f,h,k)=>{if(g&&c.W(g))!c.vb(g)||k&&g.L()===h|| -g(h);else throw Error(`${f} , must be observable`);}}})();(()=>{function a(f){return 8==f.nodeType&&e.test(f.nodeValue)}function b(f){return 8==f.nodeType&&g.test(f.nodeValue)}function d(f,h){for(var k=f,n=1,p=[];k=k.nextSibling;){if(b(k)&&(c.g.l.set(k,l,!0),!--n))return p;p.push(k);a(k)&&++n}if(!h)throw Error("Cannot find closing comment tag to match: "+f.nodeValue);return null}var e=/^\s*ko(?:\s+([\s\S]+))?\s*$/,g=/^\s*\/ko\s*$/,l="__ko_matchedEndComment__";c.m={aa:{},childNodes:f=>a(f)?d(f):f.childNodes, -ja:f=>{a(f)?(f=d(f))&&[...f].forEach(h=>c.removeNode(h)):c.g.Qa(f)},pa:(f,h)=>{a(f)?(c.m.ja(f),f.after(...h)):c.g.pa(f,h)},prepend:(f,h)=>{a(f)?f.nextSibling.before(h):f.prepend(h)},Ub:(f,h,k)=>{k?k.after(h):c.m.prepend(f,h)},firstChild:f=>{if(a(f))return f=f.nextSibling,!f||b(f)?null:f;let h=f.firstChild;if(h&&b(h))throw Error("Found invalid end comment, as the first child of "+f);return h},nextSibling:f=>{if(a(f)){var h=d(f,void 0);f=h?(h.length?h[h.length-1]:f).nextSibling:null}if((h=f.nextSibling)&& -b(h)){if(b(h)&&!c.g.l.get(h,l))throw Error("Found end comment without a matching opening comment, as child of "+f);return null}return h},Qb:a,ac:f=>(f=f.nodeValue.match(e))?f[1]:null}})();const T=new Map;c.ob=new class{Xb(a){switch(a.nodeType){case 1:return null!=a.getAttribute("data-bind");case 8:return c.m.Qb(a)}return!1}Ob(a,b){a:{switch(a.nodeType){case 1:var d=a.getAttribute("data-bind");break a;case 8:d=c.m.ac(a);break a}d=null}if(d)try{let g=T.get(d);if(!g){var e="with($context){with($data||{}){return{"+ -c.la.Yb(d)+"}}}";g=new Function("$context","$element",e);T.set(d,g)}return g(b,a)}catch(g){throw g.message="Unable to parse bindings.\nBindings value: "+d+"\nMessage: "+g.message,g;}return null}};const G=Symbol("_subscribable"),H=Symbol("_ancestorBindingInfo"),U=Symbol("_dataDependency"),V={},I=c.g.l.Z();c.i={};c.ba=class{constructor(a,b,d,e){var g=this,l=a===V,f=l?void 0:a,h="function"==typeof f&&!c.W(f),k=e?.dataDependency;a=()=>{var p=h?f():f;p=c.g.h(p);b?(c.g.extend(g,b),H in b&&(g[H]=b[H])): -(g.$root=p,g.ko=c);g[G]=n;l?p=g.$data:g.$data=p;d?.(g,b,p);if(b?.[G]&&!c.u.o().Sa(b[G]))b[G]();k&&(g[U]=k);return g.$data};if(e?.exportDependencies)a();else{var n=c.xb(a);n.L();n.isActive()?n.ka=null:g[G]=void 0}}createChildContext(a,b){return new c.ba(a,this,(d,e)=>{d.$parent=e.$data;b.extend?.(d)},b)}extend(a,b){return new c.ba(V,this,d=>c.g.extend(d,"function"==typeof a?a(d):a),b)}};const W=a=>{a=c.g.l.get(a,I);var b=a?.D;b&&(a.D=null,b.wb())};class ma{constructor(a,b,d){this.H=a;this.da=b;this.ta= -new Set;this.F=!1;b.D||c.g.N.addDisposeCallback(a,W);d?.D&&(d.D.ta.add(a),this.za=d)}wb(){this.za?.D?.Mb(this.H)}Mb(a){this.ta.delete(a);this.ta.size||this.rb?.()}rb(){this.F=!0;this.da.D&&!this.ta.size&&(this.da.D=null,c.g.N.Ya(this.H,W),c.j.notify(this.H,c.j.ca),this.wb())}}c.j={F:"childrenComplete",ca:"descendantsComplete",subscribe:(a,b,d,e,g)=>{var l=c.g.l.Ra(a,I,{});l.wa||(l.wa=new c.P);g?.notifyImmediately&&l.Va[b]&&c.u.I(d,e,[a]);return l.wa.subscribe(d,e,b)},notify:(a,b)=>{var d=c.g.l.get(a, -I);if(d&&(d.Va[b]=!0,d.wa?.B(a,b),b==c.j.F))if(d.D)d.D.rb();else if(void 0===d.D&&d.wa?.na(c.j.ca))throw Error("descendantsComplete event not supported for bindings on this node");},$a:(a,b)=>{var d=c.g.l.Ra(a,I,{});d.D||(d.D=new ma(a,d,b[H]));return b[H]==d?b:b.extend(e=>{e[H]=d})}};const Y=(a,b)=>{for(var d,e=c.m.firstChild(b);d=e;)e=c.m.nextSibling(d),X(a,d);c.j.notify(b,c.j.F)},X=(a,b)=>{var d=a;if(1===b.nodeType||c.ob.Xb(b))d=Z(b,null,a);d&&!b.matches?.("SCRIPT,TEXTAREA,TEMPLATE")&&Y(d,b)},na= -a=>{var b=[],d={},e=[],g=l=>{if(!d[l]){var f=c.i[l];f&&(f.after&&(e.push(l),f.after.forEach(h=>{if(a[h]){if(e.includes(h))throw Error("Cannot combine the following bindings, because they have a cyclic dependency: "+e.join(", "));g(h)}}),e.length--),b.push({key:l,ub:f}));d[l]=!0}};c.g.K(a,g);return b},Z=(a,b,d)=>{var e=c.g.l.Ra(a,I,{}),g=e.Hb;if(!b){if(g)throw Error("You cannot apply bindings multiple times to the same element.");e.Hb=!0}g||(e.context=d);e.Va||(e.Va={});if(b&&"function"!==typeof b)var l= -b;else{var f=c.o(()=>{if(l=b?b(d,a):c.ob.Ob(a,d))d[G]?.(),d[U]?.();return l},{s:a});l&&f.isActive()||(f=null)}var h=d,k;if(l){var n=f?m=>()=>f()[m]():m=>l[m],p={get:m=>l[m]&&n(m)(),has:m=>m in l};c.j.F in l&&c.j.subscribe(a,c.j.F,()=>{var m=l[c.j.F]();if(m){var q=c.m.childNodes(a);q.length&&m(q,c.dataFor(q[0]))}});c.j.ca in l&&(h=c.j.$a(a,d),c.j.subscribe(a,c.j.ca,()=>{var m=l[c.j.ca]();m&&c.m.firstChild(a)&&m(a)}));na(l).forEach(m=>{var q=m.ub.init,r=m.ub.update,u=m.key;if(8===a.nodeType&&!c.m.aa[u])throw Error("The binding '"+ -u+"' cannot be used with comment nodes");try{"function"==typeof q&&c.u.I(()=>{var t=q(a,n(u),p,h.$data,h);if(t&&t.controlsDescendantBindings){if(void 0!==k)throw Error("Multiple bindings ("+k+" and "+u+") are trying to control descendant bindings of the same element. You cannot use these bindings together on the same element.");k=u}}),"function"==typeof r&&c.o(()=>r(a,n(u),p,h.$data,h),{s:a})}catch(t){throw t.message='Unable to process binding "'+u+": "+l[u]+'"\nMessage: '+t.message,t;}})}return void 0=== -k&&h};c.$b=a=>c.g.l.get(a,I)?.context;const P=a=>a&&a instanceof c.ba?a:new c.ba(a);c.applyBindingAccessorsToNode=(a,b,d)=>Z(a,b,P(d));c.mb=(a,b)=>{1!==b.nodeType&&8!==b.nodeType||Y(P(a),b)};c.Ib=(a,b)=>X(P(a),b);c.dataFor=a=>([1,8].includes(a?.nodeType)&&c.$b(a))?.$data;c.U("bindingHandlers",c.i);(()=>{var a=Object.create(null),b=new Map;c.components={get:(l,f)=>{if(b.has(l))f(b.get(l));else{var h=a[l];h?h.subscribe(f):(h=a[l]=new c.P,h.subscribe(f),g(l,k=>{b.set(l,k);delete a[l];h.B(k)}))}},register:(l, -f)=>{if(!f)throw Error("Invalid configuration for "+l);if(d[l])throw Error("Component "+l+" is already registered");d[l]=f}};var d=Object.create(null),e=(l,f)=>{throw Error(`Component '${l}': ${f}`);},g=(l,f)=>{var h={},k=d[l]||{},n=k.template;k=k.viewModel;if(n){n.element||e(l,"Unknown template value: "+n);n=n.element;var p=J.getElementById(n);p||e(l,"Cannot find element with ID "+n);p.matches("TEMPLATE")||e(l,"Template Source Element not a