vuex-map-fields
Version:
Enable two-way data binding for form fields saved in a Vuex store
1 lines • 3.17 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["vuex-map-fields"]={})}(this,function(t){"use strict";function e(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function r(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],n=!0,o=!1,u=void 0;try{for(var i,c=t[Symbol.iterator]();!(n=(i=c.next()).done)&&(r.push(i.value),!e||r.length!==e);n=!0);}catch(t){o=!0,u=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw u}}return r}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function o(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).reduce(function(t,e){var r=e.split(".").slice(-1)[0];if(t[r])throw new Error("The key `".concat(r,"` is already in use."));return t[r]=e,t},{})}function u(t){return function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var u=r("string"==typeof n[0]?[].concat(n):[""].concat(n),4),i=u[0],c=u[1],a=u[2],f=u[3];return i.length&&"/"!==i.charAt(i.length-1)&&(i+="/"),a="".concat(i).concat(a||"getField"),f="".concat(i).concat(f||"updateField"),t(i,c,a,f)}}function i(t){return function(e){return e.split(/[.[\]]+/).reduce(function(t,e){return t[e]},t)}}function c(t,e){var r=e.path,n=e.value;r.split(/[.[\]]+/).reduce(function(t,e,r,o){return o.length===r+1&&(t[e]=n),t[e]},t)}var a=u(function(t,e,r,n){var u=Array.isArray(e)?o(e):e;return Object.keys(u).reduce(function(t,e){var o=u[e],i={get:function(){return this.$store.getters[r](o)},set:function(t){this.$store.commit(n,{path:o,value:t})}};return t[e]=i,t},{})}),f=u(function(t,e,r,n){var u=Array.isArray(e)?o(e):e;return Object.keys(u).reduce(function(t,e){var o=u[e];return t[e]={get:function(){var t,e=this.$store;return(t=e.getters[r](o),Object.keys(t).map(function(e){return[e,t[e]]})).map(function(t){return Object.keys(t[1]).reduce(function(u,i){var c="".concat(o,"[").concat(t[0],"].").concat(i);return Object.defineProperty(u,i,{get:function(){return e.getters[r](c)},set:function(t){e.commit(n,{path:c,value:t})}})},{})})}},t},{})});t.createHelpers=function(t){var r,n=t.getterType,o=t.mutationType;return e(r={},n,i),e(r,o,c),e(r,"mapFields",u(function(t,e){return a(t,e,n,o)})),e(r,"mapMultiRowFields",u(function(t,e){return f(t,e,n,o)})),r},t.getField=i,t.mapFields=a,t.mapMultiRowFields=f,t.updateField=c,Object.defineProperty(t,"__esModule",{value:!0})});