diff --git a/README.md b/README.md index 3a18f58..52f41ad 100644 --- a/README.md +++ b/README.md @@ -193,8 +193,7 @@ values.* ## Licensing -Released under the [MIT](https://opensource.org/licenses/MIT) -license. +Released under the [MIT](https://opensource.org/licenses/MIT) license. ## Contributions diff --git a/dist/vue-ctx-injector.js b/dist/vue-ctx-injector.js index 8302894..e264f68 100644 --- a/dist/vue-ctx-injector.js +++ b/dist/vue-ctx-injector.js @@ -1 +1 @@ -!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.VueCtxInjector=n():t.VueCtxInjector=n()}(self,(function(){return function(){var t={7773:function(t,n,e){"use strict";e.d(n,{default:function(){return f}});e(5395),e(3292);function r(t,n){for(var e=0;e=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=!0,a=!1;return{s:function(){e=t[Symbol.iterator]()},n:function(){var t=e.next();return u=t.done,t},e:function(t){a=!0,i=t},f:function(){try{u||null==e.return||e.return()}finally{if(a)throw i}}}}function c(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,r=new Array(n);e1?arguments[1]:void 0)}},452:function(t,n,e){var r=e(4721),o=e(6674),i=e(9625),c=function(t){return function(n,e,c){var u,a=r(n),f=o(a.length),s=i(c,f);if(t&&e!=e){for(;f>s;)if((u=a[s++])!=u)return!0}else for(;f>s;s++)if((t||s in a)&&a[s]===e)return t||s||0;return!t&&-1}};t.exports={includes:c(!0),indexOf:c(!1)}},7265:function(t,n,e){var r=e(9910),o=e(4015),i=e(7706),c=e(6674),u=e(9400),a=[].push,f=function(t){var n=1==t,e=2==t,f=3==t,s=4==t,p=6==t,l=7==t,v=5==t||p;return function(y,m,h,d){for(var b,x,g=i(y),S=o(g),_=r(m,h,3),w=c(S.length),O=0,P=d||u,E=n?P(y,w):e||l?P(y,0):void 0;w>O;O++)if((v||O in S)&&(x=_(b=S[O],O,g),t))if(n)E[O]=x;else if(x)switch(t){case 3:return!0;case 5:return b;case 6:return O;case 2:a.call(E,b)}else switch(t){case 4:return!1;case 7:a.call(E,b)}return p?-1:f||s?s:E}};t.exports={forEach:f(0),map:f(1),filter:f(2),some:f(3),every:f(4),find:f(5),findIndex:f(6),filterOut:f(7)}},9904:function(t,n,e){"use strict";var r=e(3894);t.exports=function(t,n){var e=[][t];return!!e&&r((function(){e.call(null,n||function(){throw 1},1)}))}},2114:function(t,n,e){var r=e(4244),o=e(3894),i=e(4361),c=Object.defineProperty,u={},a=function(t){throw t};t.exports=function(t,n){if(i(u,t))return u[t];n||(n={});var e=[][t],f=!!i(n,"ACCESSORS")&&n.ACCESSORS,s=i(n,0)?n[0]:a,p=i(n,1)?n[1]:void 0;return u[t]=!!e&&!o((function(){if(f&&!r)return!0;var t={length:-1};f?c(t,1,{enumerable:!0,get:a}):t[1]=1,e.call(t,s,p)}))}},9400:function(t,n,e){var r=e(3196),o=e(5588),i=e(1398)("species");t.exports=function(t,n){var e;return o(t)&&("function"!=typeof(e=t.constructor)||e!==Array&&!o(e.prototype)?r(e)&&null===(e=e[i])&&(e=void 0):e=void 0),new(void 0===e?Array:e)(0===n?0:n)}},1030:function(t){var n={}.toString;t.exports=function(t){return n.call(t).slice(8,-1)}},9129:function(t,n,e){var r=e(4361),o=e(6660),i=e(7872),c=e(6337);t.exports=function(t,n){for(var e=o(n),u=c.f,a=i.f,f=0;f"+t+""},y=function(){try{r=document.domain&&new ActiveXObject("htmlfile")}catch(t){}var t,n;y=r?function(t){t.write(v("")),t.close();var n=t.parentWindow.Object;return t=null,n}(r):((n=f("iframe")).style.display="none",a.appendChild(n),n.src=String("javascript:"),(t=n.contentWindow.document).open(),t.write(v("document.F=Object")),t.close(),t.F);for(var e=c.length;e--;)delete y.prototype[c[e]];return y()};u[p]=!0,t.exports=Object.create||function(t,n){var e;return null!==t?(l.prototype=o(t),e=new l,l.prototype=null,e[p]=t):e=y(),void 0===n?e:i(e,n)}},8068:function(t,n,e){var r=e(4244),o=e(6337),i=e(6302),c=e(8201);t.exports=r?Object.defineProperties:function(t,n){i(t);for(var e,r=c(n),u=r.length,a=0;u>a;)o.f(t,e=r[a++],n[e]);return t}},6337:function(t,n,e){var r=e(4244),o=e(7320),i=e(6302),c=e(9155),u=Object.defineProperty;n.f=r?u:function(t,n,e){if(i(t),n=c(n,!0),i(e),o)try{return u(t,n,e)}catch(t){}if("get"in e||"set"in e)throw TypeError("Accessors not supported");return"value"in e&&(t[n]=e.value),t}},7872:function(t,n,e){var r=e(4244),o=e(2028),i=e(654),c=e(4721),u=e(9155),a=e(4361),f=e(7320),s=Object.getOwnPropertyDescriptor;n.f=r?s:function(t,n){if(t=c(t),n=u(n,!0),f)try{return s(t,n)}catch(t){}if(a(t,n))return i(!o.f.call(t,n),t[n])}},1019:function(t,n,e){var r=e(6406),o=e(2507).concat("length","prototype");n.f=Object.getOwnPropertyNames||function(t){return r(t,o)}},8586:function(t,n){n.f=Object.getOwnPropertySymbols},6406:function(t,n,e){var r=e(4361),o=e(4721),i=e(452).indexOf,c=e(2570);t.exports=function(t,n){var e,u=o(t),a=0,f=[];for(e in u)!r(c,e)&&r(u,e)&&f.push(e);for(;n.length>a;)r(u,e=n[a++])&&(~i(f,e)||f.push(e));return f}},8201:function(t,n,e){var r=e(6406),o=e(2507);t.exports=Object.keys||function(t){return r(t,o)}},2028:function(t,n){"use strict";var e={}.propertyIsEnumerable,r=Object.getOwnPropertyDescriptor,o=r&&!e.call({1:2},1);n.f=o?function(t){var n=r(this,t);return!!n&&n.enumerable}:e},6660:function(t,n,e){var r=e(2546),o=e(1019),i=e(8586),c=e(6302);t.exports=r("Reflect","ownKeys")||function(t){var n=o.f(c(t)),e=i.f;return e?n.concat(e(t)):n}},1612:function(t,n,e){var r=e(4516);t.exports=r},8875:function(t,n,e){var r=e(4516),o=e(1831),i=e(4361),c=e(8870),u=e(1683),a=e(3023),f=a.get,s=a.enforce,p=String(String).split("String");(t.exports=function(t,n,e,u){var a,f=!!u&&!!u.unsafe,l=!!u&&!!u.enumerable,v=!!u&&!!u.noTargetGet;"function"==typeof e&&("string"!=typeof n||i(e,"name")||o(e,"name",n),(a=s(e)).source||(a.source=p.join("string"==typeof n?n:""))),t!==r?(f?!v&&t[n]&&(l=!0):delete t[n],l?t[n]=e:o(t,n,e)):l?t[n]=e:c(n,e)})(Function.prototype,"toString",(function(){return"function"==typeof this&&f(this).source||u(this)}))},2191:function(t){t.exports=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t}},8870:function(t,n,e){var r=e(4516),o=e(1831);t.exports=function(t,n){try{o(r,t,n)}catch(e){r[t]=n}return n}},6894:function(t,n,e){var r=e(8365),o=e(7025),i=r("keys");t.exports=function(t){return i[t]||(i[t]=o(t))}},4111:function(t,n,e){var r=e(4516),o=e(8870),i="__core-js_shared__",c=r[i]||o(i,{});t.exports=c},8365:function(t,n,e){var r=e(3310),o=e(4111);(t.exports=function(t,n){return o[t]||(o[t]=void 0!==n?n:{})})("versions",[]).push({version:"3.8.3",mode:r?"pure":"global",copyright:"© 2021 Denis Pushkarev (zloirock.ru)"})},9625:function(t,n,e){var r=e(4001),o=Math.max,i=Math.min;t.exports=function(t,n){var e=r(t);return e<0?o(e+n,0):i(e,n)}},4721:function(t,n,e){var r=e(4015),o=e(2191);t.exports=function(t){return r(o(t))}},4001:function(t){var n=Math.ceil,e=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?e:n)(t)}},6674:function(t,n,e){var r=e(4001),o=Math.min;t.exports=function(t){return t>0?o(r(t),9007199254740991):0}},7706:function(t,n,e){var r=e(2191);t.exports=function(t){return Object(r(t))}},9155:function(t,n,e){var r=e(3196);t.exports=function(t,n){if(!r(t))return t;var e,o;if(n&&"function"==typeof(e=t.toString)&&!r(o=e.call(t)))return o;if("function"==typeof(e=t.valueOf)&&!r(o=e.call(t)))return o;if(!n&&"function"==typeof(e=t.toString)&&!r(o=e.call(t)))return o;throw TypeError("Can't convert object to primitive value")}},7025:function(t){var n=0,e=Math.random();t.exports=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++n+e).toString(36)}},8477:function(t,n,e){function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var o=e(7449);t.exports=o&&!Symbol.sham&&"symbol"==r(Symbol.iterator)},1398:function(t,n,e){var r=e(4516),o=e(8365),i=e(4361),c=e(7025),u=e(7449),a=e(8477),f=o("wks"),s=r.Symbol,p=a?s:s&&s.withoutSetter||c;t.exports=function(t){return i(f,t)||(u&&i(s,t)?f[t]=s[t]:f[t]=p("Symbol."+t)),f[t]}},3949:function(t,n,e){"use strict";var r=e(7330),o=e(452).includes,i=e(6278);r({target:"Array",proto:!0,forced:!e(2114)("indexOf",{ACCESSORS:!0,1:0})},{includes:function(t){return o(this,t,arguments.length>1?arguments[1]:void 0)}}),i("includes")},3923:function(t,n,e){var r=e(4516),o=e(3464),i=e(9682),c=e(1831);for(var u in o){var a=r[u],f=a&&a.prototype;if(f&&f.forEach!==i)try{c(f,"forEach",i)}catch(t){f.forEach=i}}},1326:function(t,n,e){e(3923);var r=e(9682);t.exports=r}},n={};function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{}};return t[r](o,o.exports,e),o.exports}return e.d=function(t,n){for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e(7773)}().default})); \ No newline at end of file +!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.VueCtxInjector=n():t.VueCtxInjector=n()}(self,(function(){return function(){var t={335:function(t,n,e){"use strict";e.d(n,{default:function(){return l}});e(5395),e(3292);function r(t,n){for(var e=0;e0&&void 0!==arguments[0]?arguments[0]:null;this.componentName=t,this.isValidName=!!t}},{key:"setPropsData",value:function(t){for(var n in t)this.propsData[n]=t[n]}}])&&i(n.prototype,e),r&&i(n,r),t}();function u(t,n){var e;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(e=function(t,n){if(!t)return;if("string"==typeof t)return f(t,n);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return f(t,n)}(t))||n&&t&&"number"==typeof t.length){e&&(t=e);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,c=!0,a=!1;return{s:function(){e=t[Symbol.iterator]()},n:function(){var t=e.next();return c=t.done,t},e:function(t){a=!0,i=t},f:function(){try{c||null==e.return||e.return()}finally{if(a)throw i}}}}function f(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,r=new Array(n);e1?arguments[1]:void 0)}},452:function(t,n,e){var r=e(4721),o=e(6674),i=e(9625),c=function(t){return function(n,e,c){var a,u=r(n),f=o(u.length),s=i(c,f);if(t&&e!=e){for(;f>s;)if((a=u[s++])!=a)return!0}else for(;f>s;s++)if((t||s in u)&&u[s]===e)return t||s||0;return!t&&-1}};t.exports={includes:c(!0),indexOf:c(!1)}},7265:function(t,n,e){var r=e(9910),o=e(4015),i=e(7706),c=e(6674),a=e(9400),u=[].push,f=function(t){var n=1==t,e=2==t,f=3==t,s=4==t,p=6==t,l=7==t,m=5==t||p;return function(v,y,h,d){for(var b,g,x=i(v),S=o(x),_=r(y,h,3),w=c(S.length),P=0,O=d||a,E=n?O(v,w):e||l?O(v,0):void 0;w>P;P++)if((m||P in S)&&(g=_(b=S[P],P,x),t))if(n)E[P]=g;else if(g)switch(t){case 3:return!0;case 5:return b;case 6:return P;case 2:u.call(E,b)}else switch(t){case 4:return!1;case 7:u.call(E,b)}return p?-1:f||s?s:E}};t.exports={forEach:f(0),map:f(1),filter:f(2),some:f(3),every:f(4),find:f(5),findIndex:f(6),filterOut:f(7)}},9904:function(t,n,e){"use strict";var r=e(3894);t.exports=function(t,n){var e=[][t];return!!e&&r((function(){e.call(null,n||function(){throw 1},1)}))}},2114:function(t,n,e){var r=e(4244),o=e(3894),i=e(4361),c=Object.defineProperty,a={},u=function(t){throw t};t.exports=function(t,n){if(i(a,t))return a[t];n||(n={});var e=[][t],f=!!i(n,"ACCESSORS")&&n.ACCESSORS,s=i(n,0)?n[0]:u,p=i(n,1)?n[1]:void 0;return a[t]=!!e&&!o((function(){if(f&&!r)return!0;var t={length:-1};f?c(t,1,{enumerable:!0,get:u}):t[1]=1,e.call(t,s,p)}))}},9400:function(t,n,e){var r=e(3196),o=e(5588),i=e(1398)("species");t.exports=function(t,n){var e;return o(t)&&("function"!=typeof(e=t.constructor)||e!==Array&&!o(e.prototype)?r(e)&&null===(e=e[i])&&(e=void 0):e=void 0),new(void 0===e?Array:e)(0===n?0:n)}},1030:function(t){var n={}.toString;t.exports=function(t){return n.call(t).slice(8,-1)}},9129:function(t,n,e){var r=e(4361),o=e(6660),i=e(7872),c=e(6337);t.exports=function(t,n){for(var e=o(n),a=c.f,u=i.f,f=0;f"+t+""},v=function(){try{r=document.domain&&new ActiveXObject("htmlfile")}catch(t){}var t,n;v=r?function(t){t.write(m("")),t.close();var n=t.parentWindow.Object;return t=null,n}(r):((n=f("iframe")).style.display="none",u.appendChild(n),n.src=String("javascript:"),(t=n.contentWindow.document).open(),t.write(m("document.F=Object")),t.close(),t.F);for(var e=c.length;e--;)delete v.prototype[c[e]];return v()};a[p]=!0,t.exports=Object.create||function(t,n){var e;return null!==t?(l.prototype=o(t),e=new l,l.prototype=null,e[p]=t):e=v(),void 0===n?e:i(e,n)}},8068:function(t,n,e){var r=e(4244),o=e(6337),i=e(6302),c=e(8201);t.exports=r?Object.defineProperties:function(t,n){i(t);for(var e,r=c(n),a=r.length,u=0;a>u;)o.f(t,e=r[u++],n[e]);return t}},6337:function(t,n,e){var r=e(4244),o=e(7320),i=e(6302),c=e(9155),a=Object.defineProperty;n.f=r?a:function(t,n,e){if(i(t),n=c(n,!0),i(e),o)try{return a(t,n,e)}catch(t){}if("get"in e||"set"in e)throw TypeError("Accessors not supported");return"value"in e&&(t[n]=e.value),t}},7872:function(t,n,e){var r=e(4244),o=e(2028),i=e(654),c=e(4721),a=e(9155),u=e(4361),f=e(7320),s=Object.getOwnPropertyDescriptor;n.f=r?s:function(t,n){if(t=c(t),n=a(n,!0),f)try{return s(t,n)}catch(t){}if(u(t,n))return i(!o.f.call(t,n),t[n])}},1019:function(t,n,e){var r=e(6406),o=e(2507).concat("length","prototype");n.f=Object.getOwnPropertyNames||function(t){return r(t,o)}},8586:function(t,n){n.f=Object.getOwnPropertySymbols},6406:function(t,n,e){var r=e(4361),o=e(4721),i=e(452).indexOf,c=e(2570);t.exports=function(t,n){var e,a=o(t),u=0,f=[];for(e in a)!r(c,e)&&r(a,e)&&f.push(e);for(;n.length>u;)r(a,e=n[u++])&&(~i(f,e)||f.push(e));return f}},8201:function(t,n,e){var r=e(6406),o=e(2507);t.exports=Object.keys||function(t){return r(t,o)}},2028:function(t,n){"use strict";var e={}.propertyIsEnumerable,r=Object.getOwnPropertyDescriptor,o=r&&!e.call({1:2},1);n.f=o?function(t){var n=r(this,t);return!!n&&n.enumerable}:e},6660:function(t,n,e){var r=e(2546),o=e(1019),i=e(8586),c=e(6302);t.exports=r("Reflect","ownKeys")||function(t){var n=o.f(c(t)),e=i.f;return e?n.concat(e(t)):n}},1612:function(t,n,e){var r=e(4516);t.exports=r},8875:function(t,n,e){var r=e(4516),o=e(1831),i=e(4361),c=e(8870),a=e(1683),u=e(3023),f=u.get,s=u.enforce,p=String(String).split("String");(t.exports=function(t,n,e,a){var u,f=!!a&&!!a.unsafe,l=!!a&&!!a.enumerable,m=!!a&&!!a.noTargetGet;"function"==typeof e&&("string"!=typeof n||i(e,"name")||o(e,"name",n),(u=s(e)).source||(u.source=p.join("string"==typeof n?n:""))),t!==r?(f?!m&&t[n]&&(l=!0):delete t[n],l?t[n]=e:o(t,n,e)):l?t[n]=e:c(n,e)})(Function.prototype,"toString",(function(){return"function"==typeof this&&f(this).source||a(this)}))},2191:function(t){t.exports=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t}},8870:function(t,n,e){var r=e(4516),o=e(1831);t.exports=function(t,n){try{o(r,t,n)}catch(e){r[t]=n}return n}},6894:function(t,n,e){var r=e(8365),o=e(7025),i=r("keys");t.exports=function(t){return i[t]||(i[t]=o(t))}},4111:function(t,n,e){var r=e(4516),o=e(8870),i="__core-js_shared__",c=r[i]||o(i,{});t.exports=c},8365:function(t,n,e){var r=e(3310),o=e(4111);(t.exports=function(t,n){return o[t]||(o[t]=void 0!==n?n:{})})("versions",[]).push({version:"3.8.3",mode:r?"pure":"global",copyright:"© 2021 Denis Pushkarev (zloirock.ru)"})},9625:function(t,n,e){var r=e(4001),o=Math.max,i=Math.min;t.exports=function(t,n){var e=r(t);return e<0?o(e+n,0):i(e,n)}},4721:function(t,n,e){var r=e(4015),o=e(2191);t.exports=function(t){return r(o(t))}},4001:function(t){var n=Math.ceil,e=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?e:n)(t)}},6674:function(t,n,e){var r=e(4001),o=Math.min;t.exports=function(t){return t>0?o(r(t),9007199254740991):0}},7706:function(t,n,e){var r=e(2191);t.exports=function(t){return Object(r(t))}},9155:function(t,n,e){var r=e(3196);t.exports=function(t,n){if(!r(t))return t;var e,o;if(n&&"function"==typeof(e=t.toString)&&!r(o=e.call(t)))return o;if("function"==typeof(e=t.valueOf)&&!r(o=e.call(t)))return o;if(!n&&"function"==typeof(e=t.toString)&&!r(o=e.call(t)))return o;throw TypeError("Can't convert object to primitive value")}},7025:function(t){var n=0,e=Math.random();t.exports=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++n+e).toString(36)}},8477:function(t,n,e){function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var o=e(7449);t.exports=o&&!Symbol.sham&&"symbol"==r(Symbol.iterator)},1398:function(t,n,e){var r=e(4516),o=e(8365),i=e(4361),c=e(7025),a=e(7449),u=e(8477),f=o("wks"),s=r.Symbol,p=u?s:s&&s.withoutSetter||c;t.exports=function(t){return i(f,t)||(a&&i(s,t)?f[t]=s[t]:f[t]=p("Symbol."+t)),f[t]}},3949:function(t,n,e){"use strict";var r=e(7330),o=e(452).includes,i=e(6278);r({target:"Array",proto:!0,forced:!e(2114)("indexOf",{ACCESSORS:!0,1:0})},{includes:function(t){return o(this,t,arguments.length>1?arguments[1]:void 0)}}),i("includes")},3923:function(t,n,e){var r=e(4516),o=e(3464),i=e(9682),c=e(1831);for(var a in o){var u=r[a],f=u&&u.prototype;if(f&&f.forEach!==i)try{c(f,"forEach",i)}catch(t){f.forEach=i}}},1326:function(t,n,e){e(3923);var r=e(9682);t.exports=r}},n={};function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{}};return t[r](o,o.exports,e),o.exports}return e.d=function(t,n){for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e(335)}().default})); \ No newline at end of file diff --git a/src/CLink.js b/src/CLink.js new file mode 100644 index 0000000..e53cb72 --- /dev/null +++ b/src/CLink.js @@ -0,0 +1,22 @@ +/** + * CLink - Represents VCI-managed data used for communication between DOM and + * Vue components. + */ + +export default class CLink { + isValidName = false + componentName = null + propsData = {} + + setComponentName (name = null) { + this.componentName = name + this.isValidName = !!name + } + + setPropsData (data) { + for (let name in data) { + this.propsData[name] = data[name] + } + } + +} diff --git a/src/VueCtxInjector.js b/src/VueCtxInjector.js index b934dd8..ca692f4 100644 --- a/src/VueCtxInjector.js +++ b/src/VueCtxInjector.js @@ -1,4 +1,5 @@ import ErrorManager from './ErrorManager.js' +import CLink from './CLink.js' /** * VueCtxInjector - Main VCI class. @@ -101,9 +102,12 @@ export default class VueCtxInjector { * @return {[type]} [description] */ _storeFormattedUserOptions (opts) { - this._replaceRoot = opts.replaceRoot === undefined ? true : opts.replaceRoot - this._componentPrefix = opts.componentPrefix === undefined ? 'data-v-comp' : `data-${opts.componentPrefix}` - this._propPrefix = opts.propPrefix === undefined ? 'data-v:' : `data-${opts.propPrefix}` + this._replaceRoot = opts.replaceRoot === undefined ? + this._replaceRoot : opts.replaceRoot + this._componentPrefix = opts.componentPrefix === undefined ? + this._componentPrefix : `data-${opts.componentPrefix}` + this._propPrefix = opts.propPrefix === undefined ? + this._propPrefix : `data-${opts.propPrefix}` } /** @@ -115,16 +119,23 @@ export default class VueCtxInjector { _initStdlComponents () { document.querySelectorAll(`[${this._componentPrefix}]`).forEach(stdlCompElement => { const componentName = stdlCompElement.getAttribute(this._componentPrefix) + const cLink = new CLink() + cLink.setComponentName(componentName) // check for well-formatted component name - if (!componentName) { - console.error('[VueCtxInjector] No component name specified.') - return - } + let validCName = true + this._errorManager.encapsulate(() => { + if (!cLink.isValidName) { + validCName = false + this._errorManager.error('No component name specified.') + } + }) // store & mount component - this._compElements[componentName] = stdlCompElement - const props = this._getParsedElementProps(stdlCompElement) - this._mountStdlComponent(componentName, props) - this._watchStdlComponent(componentName) + if (validCName) { + this._compElements[componentName] = stdlCompElement + cLink.setPropsData(this._getParsedElementProps(stdlCompElement)) + this._mountStdlComponent(cLink) + this._watchStdlComponent(cLink) + } }) } @@ -136,25 +147,30 @@ export default class VueCtxInjector { * @param {Object} propsData - Data used for component props. * @return {void} */ - _mountStdlComponent (name, propsData) { + _mountStdlComponent (cLink) { // check for existing component definition - if (name && !this._compDefs.hasOwnProperty(name)) { - console.error(`[VueCtxInjector] No component found with name: ${name}.`) - return - } - // configuration/mounting - const component = this._compDefs[name] - const props = this._castProps(propsData, component) - this._compConstructors[name] = this._vueInstance.extend(component) - this._compInstances[name] = new this._compConstructors[name]({ - propsData: props, + let validName = true + this._errorManager.encapsulate(() => { + if (cLink.componentName && !this._compDefs.hasOwnProperty(cLink.componentName)) { + validName = false + this._errorManager.error(`No component found with name: ${cLink.componentName}.`) + } }) - this._compInstances[name]._props = this._vueInstance.observable(props) - const vm = this._compInstances[name].$mount() - if (this._replaceRoot) { - this._mergeComponentWithRootElement(name, vm.$el) - } else { - this._compElements[name].appendChild(vm.$el) + // configuration/mounting + if (validName) { + const component = this._compDefs[cLink.componentName] + const props = this._castProps(cLink.propsData, component) + this._compConstructors[cLink.componentName] = this._vueInstance.extend(component) + this._compInstances[cLink.componentName] = new this._compConstructors[cLink.componentName]({ + propsData: props, + }) + this._compInstances[cLink.componentName]._props = this._vueInstance.observable(props) + const vm = this._compInstances[cLink.componentName].$mount() + if (this._replaceRoot) { + this._mergeComponentWithRootElement(cLink.componentName, vm.$el) + } else { + this._compElements[cLink.componentName].appendChild(vm.$el) + } } } @@ -214,28 +230,28 @@ export default class VueCtxInjector { * @param {String} name - The component name. * @return {void} */ - _watchStdlComponent (name) { + _watchStdlComponent (cLink) { const observer = new MutationObserver(mutations => { mutations.forEach(mutation => { if (mutation.type === 'attributes') { - const newProps = this._getParsedElementProps(this._compElements[name]) + const newProps = this._getParsedElementProps(this._compElements[cLink.componentName]) // TODO: Look for another way to update props than re-instanciating // & mounting the whole component (needed because `propsData` is only // usable at instance creation). - this._compInstances[name] = new this._compConstructors[name]({ + this._compInstances[cLink.componentName] = new this._compConstructors[cLink.componentName]({ propsData: newProps, }) - const vm = this._compInstances[name].$mount() + const vm = this._compInstances[cLink.componentName].$mount() if (this._replaceRoot) { - this._compElements[name].innerHTML = vm.$el.innerHTML + this._compElements[cLink.componentName].innerHTML = vm.$el.innerHTML } else { - this._compElements[name].innerHTML = '' - this._compElements[name].appendChild(vm.$el) + this._compElements[cLink.componentName].innerHTML = '' + this._compElements[cLink.componentName].appendChild(vm.$el) } } }) }); - observer.observe(this._compElements[name], { attributes: true, }); + observer.observe(this._compElements[cLink.componentName], { attributes: true, }); } /**