@usecsv/vuejs 1.0.3 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.1.1](https://github.com/layercodedev/usecsv-vuejs-plugin/compare/v1.1.0...v1.1.1) (2022-03-07)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * dependencies ([2ef2dfd](https://github.com/layercodedev/usecsv-vuejs-plugin/commit/2ef2dfd1279ffb0d4e549c9803943a4c85cf9c4b))
7
+
8
+ # [1.1.0](https://github.com/layercodedev/usecsv-vuejs-plugin/compare/v1.0.3...v1.1.0) (2022-03-07)
9
+
10
+
11
+ ### Features
12
+
13
+ * add onData callback ([4c5830d](https://github.com/layercodedev/usecsv-vuejs-plugin/commit/4c5830debdb8e1d98ec23f7b8c0ec7a8ad4a6bfe))
14
+
1
15
  ## [1.0.3](https://github.com/layercodedev/usecsv-vuejs-plugin/compare/v1.0.2...v1.0.3) (2022-02-15)
2
16
 
3
17
 
@@ -1,11 +1,37 @@
1
1
  import Vue from 'vue';
2
2
 
3
3
  /*!
4
- * @usecsv/js v0.1.0
4
+ * @usecsv/js v0.2.0
5
5
  * (c) layercode
6
6
  * Released under the MIT License.
7
7
  */
8
8
 
9
+ /*! *****************************************************************************
10
+ Copyright (c) Microsoft Corporation.
11
+
12
+ Permission to use, copy, modify, and/or distribute this software for any
13
+ purpose with or without fee is hereby granted.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
16
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
18
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
+ PERFORMANCE OF THIS SOFTWARE.
22
+ ***************************************************************************** */
23
+
24
+ var __assign = function() {
25
+ __assign = Object.assign || function __assign(t) {
26
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
27
+ s = arguments[i];
28
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
29
+ }
30
+ return t;
31
+ };
32
+ return __assign.apply(this, arguments);
33
+ };
34
+
9
35
  var containers = []; // will store container HTMLElement references
10
36
  var styleElements = []; // will store {prepend: HTMLElement, append: HTMLElement}
11
37
 
@@ -567,18 +593,16 @@ var insertIframe = function (id) {
567
593
  return iframe;
568
594
  };
569
595
  var useCsvPlugin = function (_a) {
570
- var importerKey = _a.importerKey, user = _a.user, metadata = _a.metadata;
596
+ var importerKey = _a.importerKey, user = _a.user, metadata = _a.metadata, onData = _a.onData;
571
597
  var id = "usecsv-".concat(Math.round(Math.random() * 100000000));
572
598
  return whenDomReady().then(function () {
573
599
  var iframe = insertIframe(id);
574
600
  var iframeConnection = connectToChild({
575
601
  iframe: iframe,
576
- methods: {
577
- closeIframe: function () {
602
+ methods: __assign({ closeIframe: function () {
578
603
  var _a;
579
604
  (_a = document.getElementById(id)) === null || _a === void 0 ? void 0 : _a.remove();
580
- },
581
- },
605
+ } }, (onData ? { onData: onData } : {})),
582
606
  });
583
607
  iframeConnection.promise.then(function (child) {
584
608
  var _a;
@@ -595,7 +619,8 @@ var script = /*#__PURE__*/Vue.extend({
595
619
  props: {
596
620
  importerKey: {},
597
621
  user: {},
598
- metadata: {}
622
+ metadata: {},
623
+ onData: {}
599
624
  },
600
625
 
601
626
  data() {
@@ -609,7 +634,8 @@ var script = /*#__PURE__*/Vue.extend({
609
634
  useCsvPlugin({
610
635
  importerKey: this.importerKey,
611
636
  user: this.user,
612
- metadata: this.metadata
637
+ metadata: this.metadata,
638
+ onData: this.onData
613
639
  });
614
640
  },
615
641
 
@@ -781,8 +807,8 @@ var __vue_staticRenderFns__ = [];
781
807
 
782
808
  const __vue_inject_styles__ = function (inject) {
783
809
  if (!inject) return;
784
- inject("data-v-0af7725f_0", {
785
- source: "#usecsv-button[data-v-0af7725f]{background-color:#fff;color:#000;border:2px solid #000;border-radius:6px;padding:10px 15px;text-align:center;font-size:16px;cursor:pointer}",
810
+ inject("data-v-4807283e_0", {
811
+ source: "#usecsv-button[data-v-4807283e]{background-color:#fff;color:#000;border:2px solid #000;border-radius:6px;padding:10px 15px;text-align:center;font-size:16px;cursor:pointer}",
786
812
  map: undefined,
787
813
  media: undefined
788
814
  });
@@ -790,7 +816,7 @@ const __vue_inject_styles__ = function (inject) {
790
816
  /* scoped */
791
817
 
792
818
 
793
- const __vue_scope_id__ = "data-v-0af7725f";
819
+ const __vue_scope_id__ = "data-v-4807283e";
794
820
  /* module identifier */
795
821
 
796
822
  const __vue_module_identifier__ = undefined;
@@ -1,6 +1,20 @@
1
1
  var UseCSVButton=function(e){"use strict";function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(e);function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var o,r,i=[],s=!0,a=!1;try{for(n=n.call(e);!(s=(o=n.next()).done)&&(i.push(o.value),!t||i.length!==t);s=!0);}catch(e){a=!0,r=e}finally{try{s||null==n.return||n.return()}finally{if(a)throw r}}return i}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return r(e,t)}(e,t)||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.")}
2
2
  /*!
3
- * @usecsv/js v0.1.0
3
+ * @usecsv/js v0.2.0
4
4
  * (c) layercode
5
5
  * Released under the MIT License.
6
- */()}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}var i=[],s=[];function a(e,t){if(t=t||{},void 0===e)throw new Error("insert-css: You need to provide a CSS string. Usage: insertCss(cssString[, options]).");var n,o=!0===t.prepend?"prepend":"append",r=void 0!==t.container?t.container:document.querySelector("head"),a=i.indexOf(r);return-1===a&&(a=i.push(r)-1,s[a]={}),void 0!==s[a]&&void 0!==s[a][o]?n=s[a][o]:(n=s[a][o]=function(){var e=document.createElement("style");return e.setAttribute("type","text/css"),e}(),"prepend"===o?r.insertBefore(n,r.childNodes[0]):r.appendChild(n)),65279===e.charCodeAt(0)&&(e=e.substr(1,e.length)),n.styleSheet?n.styleSheet.cssText+=e:n.textContent+=e,n}var c,d,l,u,f,m=a;a.insertCss=m,function(e){e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack"}(c||(c={})),function(e){e.Fulfilled="fulfilled",e.Rejected="rejected"}(d||(d={})),function(e){e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc"}(l||(l={})),function(e){e.DataCloneError="DataCloneError"}(u||(u={})),function(e){e.Message="message"}(f||(f={}));const p={"http:":"80","https:":"443"},h=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,v=["file:","data:"];const g=({name:e,message:t,stack:n})=>({name:e,message:t,stack:n});let y=0;var S=()=>++y,b=(e,t,n,o,r)=>{const{localName:i,local:s,remote:a,originForSending:u,originForReceiving:m}=t;let p=!1;r(`${i}: Connecting call sender`);const h=e=>(...t)=>{let n;r(`${i}: Sending ${e}() call`);try{a.closed&&(n=!0)}catch(e){n=!0}if(n&&o(),p){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=l.ConnectionDestroyed,t}return new Promise(((n,o)=>{const l=S(),p=t=>{if(t.source!==a||t.data.penpal!==c.Reply||t.data.id!==l)return;if(t.origin!==m)return void r(`${i} received message from origin ${t.origin} which did not match expected origin ${m}`);const u=t.data;r(`${i}: Received ${e}() reply`),s.removeEventListener(f.Message,p);let h=u.returnValue;u.returnValueIsError&&(h=(e=>{const t=new Error;return Object.keys(e).forEach((n=>t[n]=e[n])),t})(h)),(u.resolution===d.Fulfilled?n:o)(h)};s.addEventListener(f.Message,p);const h={penpal:c.Call,id:l,methodName:e,args:t};a.postMessage(h,u)}))};return n.reduce(((e,t)=>(e[t]=h(t),e)),e),()=>{p=!0}},C=(e,t,n,o,r)=>{const{destroy:i,onDestroy:s}=o;let a,l;const m={};return o=>{if(o.origin!==t)return void r(`Parent: Handshake - Received ACK message from origin ${o.origin} which did not match expected origin ${t}`);r("Parent: Handshake - Received ACK");const p={localName:"Parent",local:window,remote:o.source,originForSending:n,originForReceiving:t};a&&a(),a=((e,t,n)=>{const{localName:o,local:r,remote:i,originForSending:s,originForReceiving:a}=e;let l=!1;const m=e=>{if(e.source!==i||e.data.penpal!==c.Call)return;if(e.origin!==a)return void n(`${o} received message from origin ${e.origin} which did not match expected origin ${a}`);const r=e.data,{methodName:f,args:m,id:p}=r;n(`${o}: Received ${f}() call`);const h=e=>t=>{if(n(`${o}: Sending ${f}() reply`),l)return void n(`${o}: Unable to send ${f}() reply due to destroyed connection`);const r={penpal:c.Reply,id:p,resolution:e,returnValue:t};e===d.Rejected&&t instanceof Error&&(r.returnValue=g(t),r.returnValueIsError=!0);try{i.postMessage(r,s)}catch(e){if(e.name===u.DataCloneError){const t={penpal:c.Reply,id:p,resolution:d.Rejected,returnValue:g(e),returnValueIsError:!0};i.postMessage(t,s)}throw e}};new Promise((e=>e(t[f].apply(t,m)))).then(h(d.Fulfilled),h(d.Rejected))};return r.addEventListener(f.Message,m),()=>{l=!0,r.removeEventListener(f.Message,m)}})(p,e,r),s(a),l&&l.forEach((e=>{delete m[e]})),l=o.data.methodNames;const h=b(m,p,l,i,r);return s(h),m}};var w=e=>{let{iframe:t,methods:n={},childOrigin:o,timeout:r,debug:i=!1}=e;const s=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(i),a=((e,t)=>{const n=[];let o=!1;return{destroy(r){o||(o=!0,t(`${e}: Destroying connection`),n.forEach((e=>{e(r)})))},onDestroy(e){o?e():n.push(e)}}})("Parent",s),{onDestroy:d,destroy:u}=a;o||((e=>{if(!e.src&&!e.srcdoc){const e=new Error("Iframe must have src or srcdoc property defined.");throw e.code=l.NoIframeSrc,e}})(t),o=(e=>{if(e&&v.find((t=>e.startsWith(t))))return"null";const t=document.location,n=h.exec(e);let o,r,i;return n?(o=n[1]?n[1]:t.protocol,r=n[2],i=n[4]):(o=t.protocol,r=t.hostname,i=t.port),`${o}//${r}${i&&i!==p[o]?`:${i}`:""}`})(t.src));const m="null"===o?"*":o,g=((e,t,n,o)=>r=>{if(r.origin!==n)return void e(`Parent: Handshake - Received SYN message from origin ${r.origin} which did not match expected origin ${n}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const i={penpal:c.SynAck,methodNames:Object.keys(t)};r.source.postMessage(i,o)})(s,n,o,m),y=C(n,o,m,a,s),S=new Promise(((e,n)=>{const o=((e,t)=>{let n;return void 0!==e&&(n=window.setTimeout((()=>{const n=new Error(`Connection timed out after ${e}ms`);n.code=l.ConnectionTimeout,t(n)}),e)),()=>{clearTimeout(n)}})(r,u),i=n=>{if(n.source===t.contentWindow&&n.data)if(n.data.penpal!==c.Syn)if(n.data.penpal!==c.Ack);else{const t=y(n);t&&(o(),e(t))}else g(n)};window.addEventListener(f.Message,i),s("Parent: Awaiting handshake"),((e,t)=>{const{destroy:n,onDestroy:o}=t,r=setInterval((()=>{e.isConnected||(clearInterval(r),n())}),6e4);o((()=>{clearInterval(r)}))})(t,a),d((e=>{window.removeEventListener(f.Message,i),e&&n(e)}))}));return{promise:S,destroy(){u()}}},$=["interactive","complete"],E=function(e,t){return new Promise((function(n){e&&"function"!=typeof e&&(t=e,e=null),t=t||window.document;var o=function(){return n(void(e&&setTimeout(e)))};-1!==$.indexOf(t.readyState)?o():t.addEventListener("DOMContentLoaded",o)}))};E.resume=function(e){return function(t){return E(e).then((function(){return t}))}};var _=function(e){var t=e.importerKey,n=e.user,o=e.metadata,r="usecsv-".concat(Math.round(1e8*Math.random()));return E().then((function(){var e=function(e){var t;m("\n .usecsv_container {\n position: fixed;\n top: 0;\n bottom: 0;\n right: 0;\n left: 0;\n z-index: 100000;\n }\n .usecsv_container iframe {\n width: 100%;\n height: 100%;\n position: absolute;\n border-width: 0;\n }\n .usecsv_container {\n overflow: hidden;\n overscroll-behavior-x: none;\n }\n"),document.body.insertAdjacentHTML("beforeend","<div id=".concat(e,' class="usecsv_container loading">\n</div>'));var n=document.createElement("iframe");return n.setAttribute("src","https://app.usecsv.com/importer"),null===(t=document.getElementById(e))||void 0===t||t.appendChild(n),n}(r),i=w({iframe:e,methods:{closeIframe:function(){var e;null===(e=document.getElementById(r))||void 0===e||e.remove()}}});return i.promise.then((function(e){var i;null===(i=document.getElementById(r))||void 0===i||i.classList.remove("loading"),e.setParams&&e.setParams({importerKey:t,user:n,metadata:o})})),i}))},R=n.default.extend({name:"usecsv-button",props:{importerKey:{},user:{},metadata:{}},data:function(){return{hasSlot:!!this.$slots.default}},methods:{openModal:function(){_({importerKey:this.importerKey,user:this.user,metadata:this.metadata})},hasScopedSlot:function(){return"normalized"===(this.$scopedSlots.default&&this.$scopedSlots.default.name)}}});function x(e,t,n,o,r,i,s,a,c,d){"boolean"!=typeof s&&(c=a,a=s,s=!1);const l="function"==typeof n?n.options:n;let u;if(e&&e.render&&(l.render=e.render,l.staticRenderFns=e.staticRenderFns,l._compiled=!0,r&&(l.functional=!0)),o&&(l._scopeId=o),i?(u=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,c(e)),e&&e._registeredComponents&&e._registeredComponents.add(i)},l._ssrRegister=u):t&&(u=s?function(e){t.call(this,d(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,a(e))}),u)if(l.functional){const e=l.render;l.render=function(t,n){return u.call(n),e(t,n)}}else{const e=l.beforeCreate;l.beforeCreate=e?[].concat(e,u):[u]}return n}const A="undefined"!=typeof navigator&&/msie [6-9]\\b/.test(navigator.userAgent.toLowerCase());function M(e){return(e,t)=>function(e,t){const n=A?t.media||"default":e,o=I[n]||(I[n]={ids:new Set,styles:[]});if(!o.ids.has(e)){o.ids.add(e);let n=t.source;if(t.map&&(n+="\n/*# sourceURL="+t.map.sources[0]+" */",n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(t.map))))+" */"),o.element||(o.element=document.createElement("style"),o.element.type="text/css",t.media&&o.element.setAttribute("media",t.media),void 0===N&&(N=document.head||document.getElementsByTagName("head")[0]),N.appendChild(o.element)),"styleSheet"in o.element)o.styles.push(n),o.element.styleSheet.cssText=o.styles.filter(Boolean).join("\n");else{const e=o.ids.size-1,t=document.createTextNode(n),r=o.element.childNodes;r[e]&&o.element.removeChild(r[e]),r.length?o.element.insertBefore(t,r[e]):o.element.appendChild(t)}}}(e,t)}let N;const I={};var k=x({render:function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"usecsv"},[e.hasScopedSlot()?n("div",[e._t("default",null,{openModal:e.openModal})],2):n("div",[n("button",{attrs:{type:"button",id:"usecsv-button"},on:{click:e.openModal}},[e._t("default",(function(){return[e._v(" open usecsv ")]}))],2)])])},staticRenderFns:[]},(function(e){e&&e("data-v-0af7725f_0",{source:"#usecsv-button[data-v-0af7725f]{background-color:#fff;color:#000;border:2px solid #000;border-radius:6px;padding:10px 15px;text-align:center;font-size:16px;cursor:pointer}",map:void 0,media:void 0})}),R,"data-v-0af7725f",false,undefined,!1,M,void 0,void 0),j=function(){var e=k;return e.install=function(t){t.component("usecsv-button",e)},e}(),T=Object.freeze({__proto__:null,default:j});return Object.entries(T).forEach((function(e){var t=o(e,2),n=t[0],r=t[1];"default"!==n&&(j[n]=r)})),j}(Vue);
6
+ */
7
+ /*! *****************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */()}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}var i=function(){return i=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},i.apply(this,arguments)},s=[],a=[];function c(e,t){if(t=t||{},void 0===e)throw new Error("insert-css: You need to provide a CSS string. Usage: insertCss(cssString[, options]).");var n,o=!0===t.prepend?"prepend":"append",r=void 0!==t.container?t.container:document.querySelector("head"),i=s.indexOf(r);return-1===i&&(i=s.push(r)-1,a[i]={}),void 0!==a[i]&&void 0!==a[i][o]?n=a[i][o]:(n=a[i][o]=function(){var e=document.createElement("style");return e.setAttribute("type","text/css"),e}(),"prepend"===o?r.insertBefore(n,r.childNodes[0]):r.appendChild(n)),65279===e.charCodeAt(0)&&(e=e.substr(1,e.length)),n.styleSheet?n.styleSheet.cssText+=e:n.textContent+=e,n}var d,l,u,f,m,p=c;c.insertCss=p,function(e){e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack"}(d||(d={})),function(e){e.Fulfilled="fulfilled",e.Rejected="rejected"}(l||(l={})),function(e){e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc"}(u||(u={})),function(e){e.DataCloneError="DataCloneError"}(f||(f={})),function(e){e.Message="message"}(m||(m={}));const h={"http:":"80","https:":"443"},v=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,g=["file:","data:"];const y=({name:e,message:t,stack:n})=>({name:e,message:t,stack:n});let b=0;var S=()=>++b,C=(e,t,n,o,r)=>{const{localName:i,local:s,remote:a,originForSending:c,originForReceiving:f}=t;let p=!1;r(`${i}: Connecting call sender`);const h=e=>(...t)=>{let n;r(`${i}: Sending ${e}() call`);try{a.closed&&(n=!0)}catch(e){n=!0}if(n&&o(),p){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=u.ConnectionDestroyed,t}return new Promise(((n,o)=>{const u=S(),p=t=>{if(t.source!==a||t.data.penpal!==d.Reply||t.data.id!==u)return;if(t.origin!==f)return void r(`${i} received message from origin ${t.origin} which did not match expected origin ${f}`);const c=t.data;r(`${i}: Received ${e}() reply`),s.removeEventListener(m.Message,p);let h=c.returnValue;c.returnValueIsError&&(h=(e=>{const t=new Error;return Object.keys(e).forEach((n=>t[n]=e[n])),t})(h)),(c.resolution===l.Fulfilled?n:o)(h)};s.addEventListener(m.Message,p);const h={penpal:d.Call,id:u,methodName:e,args:t};a.postMessage(h,c)}))};return n.reduce(((e,t)=>(e[t]=h(t),e)),e),()=>{p=!0}},w=(e,t,n,o,r)=>{const{destroy:i,onDestroy:s}=o;let a,c;const u={};return o=>{if(o.origin!==t)return void r(`Parent: Handshake - Received ACK message from origin ${o.origin} which did not match expected origin ${t}`);r("Parent: Handshake - Received ACK");const p={localName:"Parent",local:window,remote:o.source,originForSending:n,originForReceiving:t};a&&a(),a=((e,t,n)=>{const{localName:o,local:r,remote:i,originForSending:s,originForReceiving:a}=e;let c=!1;const u=e=>{if(e.source!==i||e.data.penpal!==d.Call)return;if(e.origin!==a)return void n(`${o} received message from origin ${e.origin} which did not match expected origin ${a}`);const r=e.data,{methodName:u,args:m,id:p}=r;n(`${o}: Received ${u}() call`);const h=e=>t=>{if(n(`${o}: Sending ${u}() reply`),c)return void n(`${o}: Unable to send ${u}() reply due to destroyed connection`);const r={penpal:d.Reply,id:p,resolution:e,returnValue:t};e===l.Rejected&&t instanceof Error&&(r.returnValue=y(t),r.returnValueIsError=!0);try{i.postMessage(r,s)}catch(e){if(e.name===f.DataCloneError){const t={penpal:d.Reply,id:p,resolution:l.Rejected,returnValue:y(e),returnValueIsError:!0};i.postMessage(t,s)}throw e}};new Promise((e=>e(t[u].apply(t,m)))).then(h(l.Fulfilled),h(l.Rejected))};return r.addEventListener(m.Message,u),()=>{c=!0,r.removeEventListener(m.Message,u)}})(p,e,r),s(a),c&&c.forEach((e=>{delete u[e]})),c=o.data.methodNames;const h=C(u,p,c,i,r);return s(h),u}};var $=e=>{let{iframe:t,methods:n={},childOrigin:o,timeout:r,debug:i=!1}=e;const s=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(i),a=((e,t)=>{const n=[];let o=!1;return{destroy(r){o||(o=!0,t(`${e}: Destroying connection`),n.forEach((e=>{e(r)})))},onDestroy(e){o?e():n.push(e)}}})("Parent",s),{onDestroy:c,destroy:l}=a;o||((e=>{if(!e.src&&!e.srcdoc){const e=new Error("Iframe must have src or srcdoc property defined.");throw e.code=u.NoIframeSrc,e}})(t),o=(e=>{if(e&&g.find((t=>e.startsWith(t))))return"null";const t=document.location,n=v.exec(e);let o,r,i;return n?(o=n[1]?n[1]:t.protocol,r=n[2],i=n[4]):(o=t.protocol,r=t.hostname,i=t.port),`${o}//${r}${i&&i!==h[o]?`:${i}`:""}`})(t.src));const f="null"===o?"*":o,p=((e,t,n,o)=>r=>{if(r.origin!==n)return void e(`Parent: Handshake - Received SYN message from origin ${r.origin} which did not match expected origin ${n}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const i={penpal:d.SynAck,methodNames:Object.keys(t)};r.source.postMessage(i,o)})(s,n,o,f),y=w(n,o,f,a,s),b=new Promise(((e,n)=>{const o=((e,t)=>{let n;return void 0!==e&&(n=window.setTimeout((()=>{const n=new Error(`Connection timed out after ${e}ms`);n.code=u.ConnectionTimeout,t(n)}),e)),()=>{clearTimeout(n)}})(r,l),i=n=>{if(n.source===t.contentWindow&&n.data)if(n.data.penpal!==d.Syn)if(n.data.penpal!==d.Ack);else{const t=y(n);t&&(o(),e(t))}else p(n)};window.addEventListener(m.Message,i),s("Parent: Awaiting handshake"),((e,t)=>{const{destroy:n,onDestroy:o}=t,r=setInterval((()=>{e.isConnected||(clearInterval(r),n())}),6e4);o((()=>{clearInterval(r)}))})(t,a),c((e=>{window.removeEventListener(m.Message,i),e&&n(e)}))}));return{promise:b,destroy(){l()}}},E=["interactive","complete"],_=function(e,t){return new Promise((function(n){e&&"function"!=typeof e&&(t=e,e=null),t=t||window.document;var o=function(){return n(void(e&&setTimeout(e)))};-1!==E.indexOf(t.readyState)?o():t.addEventListener("DOMContentLoaded",o)}))};_.resume=function(e){return function(t){return _(e).then((function(){return t}))}};var R=function(e){var t=e.importerKey,n=e.user,o=e.metadata,r=e.onData,s="usecsv-".concat(Math.round(1e8*Math.random()));return _().then((function(){var e=function(e){var t;p("\n .usecsv_container {\n position: fixed;\n top: 0;\n bottom: 0;\n right: 0;\n left: 0;\n z-index: 100000;\n }\n .usecsv_container iframe {\n width: 100%;\n height: 100%;\n position: absolute;\n border-width: 0;\n }\n .usecsv_container {\n overflow: hidden;\n overscroll-behavior-x: none;\n }\n"),document.body.insertAdjacentHTML("beforeend","<div id=".concat(e,' class="usecsv_container loading">\n</div>'));var n=document.createElement("iframe");return n.setAttribute("src","https://app.usecsv.com/importer"),null===(t=document.getElementById(e))||void 0===t||t.appendChild(n),n}(s),a=$({iframe:e,methods:i({closeIframe:function(){var e;null===(e=document.getElementById(s))||void 0===e||e.remove()}},r?{onData:r}:{})});return a.promise.then((function(e){var r;null===(r=document.getElementById(s))||void 0===r||r.classList.remove("loading"),e.setParams&&e.setParams({importerKey:t,user:n,metadata:o})})),a}))},x=n.default.extend({name:"usecsv-button",props:{importerKey:{},user:{},metadata:{},onData:{}},data:function(){return{hasSlot:!!this.$slots.default}},methods:{openModal:function(){R({importerKey:this.importerKey,user:this.user,metadata:this.metadata,onData:this.onData})},hasScopedSlot:function(){return"normalized"===(this.$scopedSlots.default&&this.$scopedSlots.default.name)}}});function A(e,t,n,o,r,i,s,a,c,d){"boolean"!=typeof s&&(c=a,a=s,s=!1);const l="function"==typeof n?n.options:n;let u;if(e&&e.render&&(l.render=e.render,l.staticRenderFns=e.staticRenderFns,l._compiled=!0,r&&(l.functional=!0)),o&&(l._scopeId=o),i?(u=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,c(e)),e&&e._registeredComponents&&e._registeredComponents.add(i)},l._ssrRegister=u):t&&(u=s?function(e){t.call(this,d(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,a(e))}),u)if(l.functional){const e=l.render;l.render=function(t,n){return u.call(n),e(t,n)}}else{const e=l.beforeCreate;l.beforeCreate=e?[].concat(e,u):[u]}return n}const M="undefined"!=typeof navigator&&/msie [6-9]\\b/.test(navigator.userAgent.toLowerCase());function N(e){return(e,t)=>function(e,t){const n=M?t.media||"default":e,o=j[n]||(j[n]={ids:new Set,styles:[]});if(!o.ids.has(e)){o.ids.add(e);let n=t.source;if(t.map&&(n+="\n/*# sourceURL="+t.map.sources[0]+" */",n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(t.map))))+" */"),o.element||(o.element=document.createElement("style"),o.element.type="text/css",t.media&&o.element.setAttribute("media",t.media),void 0===I&&(I=document.head||document.getElementsByTagName("head")[0]),I.appendChild(o.element)),"styleSheet"in o.element)o.styles.push(n),o.element.styleSheet.cssText=o.styles.filter(Boolean).join("\n");else{const e=o.ids.size-1,t=document.createTextNode(n),r=o.element.childNodes;r[e]&&o.element.removeChild(r[e]),r.length?o.element.insertBefore(t,r[e]):o.element.appendChild(t)}}}(e,t)}let I;const j={};var k=A({render:function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"usecsv"},[e.hasScopedSlot()?n("div",[e._t("default",null,{openModal:e.openModal})],2):n("div",[n("button",{attrs:{type:"button",id:"usecsv-button"},on:{click:e.openModal}},[e._t("default",(function(){return[e._v(" open usecsv ")]}))],2)])])},staticRenderFns:[]},(function(e){e&&e("data-v-4807283e_0",{source:"#usecsv-button[data-v-4807283e]{background-color:#fff;color:#000;border:2px solid #000;border-radius:6px;padding:10px 15px;text-align:center;font-size:16px;cursor:pointer}",map:void 0,media:void 0})}),x,"data-v-4807283e",false,undefined,!1,N,void 0,void 0),D=function(){var e=k;return e.install=function(t){t.component("usecsv-button",e)},e}(),O=Object.freeze({__proto__:null,default:D});return Object.entries(O).forEach((function(e){var t=o(e,2),n=t[0],r=t[1];"default"!==n&&(D[n]=r)})),D}(Vue);
@@ -56,11 +56,37 @@ function _arrayLikeToArray(arr, len) {
56
56
  function _nonIterableRest() {
57
57
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
58
58
  }/*!
59
- * @usecsv/js v0.1.0
59
+ * @usecsv/js v0.2.0
60
60
  * (c) layercode
61
61
  * Released under the MIT License.
62
62
  */
63
63
 
64
+ /*! *****************************************************************************
65
+ Copyright (c) Microsoft Corporation.
66
+
67
+ Permission to use, copy, modify, and/or distribute this software for any
68
+ purpose with or without fee is hereby granted.
69
+
70
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
71
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
72
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
73
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
74
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
75
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
76
+ PERFORMANCE OF THIS SOFTWARE.
77
+ ***************************************************************************** */
78
+
79
+ var __assign = function() {
80
+ __assign = Object.assign || function __assign(t) {
81
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
82
+ s = arguments[i];
83
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
84
+ }
85
+ return t;
86
+ };
87
+ return __assign.apply(this, arguments);
88
+ };
89
+
64
90
  var containers = []; // will store container HTMLElement references
65
91
  var styleElements = []; // will store {prepend: HTMLElement, append: HTMLElement}
66
92
 
@@ -622,18 +648,16 @@ var insertIframe = function (id) {
622
648
  return iframe;
623
649
  };
624
650
  var useCsvPlugin = function (_a) {
625
- var importerKey = _a.importerKey, user = _a.user, metadata = _a.metadata;
651
+ var importerKey = _a.importerKey, user = _a.user, metadata = _a.metadata, onData = _a.onData;
626
652
  var id = "usecsv-".concat(Math.round(Math.random() * 100000000));
627
653
  return whenDomReady().then(function () {
628
654
  var iframe = insertIframe(id);
629
655
  var iframeConnection = connectToChild({
630
656
  iframe: iframe,
631
- methods: {
632
- closeIframe: function () {
657
+ methods: __assign({ closeIframe: function () {
633
658
  var _a;
634
659
  (_a = document.getElementById(id)) === null || _a === void 0 ? void 0 : _a.remove();
635
- },
636
- },
660
+ } }, (onData ? { onData: onData } : {})),
637
661
  });
638
662
  iframeConnection.promise.then(function (child) {
639
663
  var _a;
@@ -649,7 +673,8 @@ var useCsvPlugin = function (_a) {
649
673
  props: {
650
674
  importerKey: {},
651
675
  user: {},
652
- metadata: {}
676
+ metadata: {},
677
+ onData: {}
653
678
  },
654
679
  data: function data() {
655
680
  return {
@@ -661,7 +686,8 @@ var useCsvPlugin = function (_a) {
661
686
  useCsvPlugin({
662
687
  importerKey: this.importerKey,
663
688
  user: this.user,
664
- metadata: this.metadata
689
+ metadata: this.metadata,
690
+ onData: this.onData
665
691
  });
666
692
  },
667
693
  hasScopedSlot: function hasScopedSlot() {
@@ -794,9 +820,9 @@ var __vue_render__ = function __vue_render__() {
794
820
 
795
821
  return _c('div', {
796
822
  staticClass: "usecsv"
797
- }, [_vm.hasScopedSlot() ? _vm._ssrNode("<div data-v-0af7725f>", "</div>", [_vm._t("default", null, {
823
+ }, [_vm.hasScopedSlot() ? _vm._ssrNode("<div data-v-4807283e>", "</div>", [_vm._t("default", null, {
798
824
  "openModal": _vm.openModal
799
- })], 2) : _vm._ssrNode("<div data-v-0af7725f>", "</div>", [_vm._ssrNode("<button type=\"button\" id=\"usecsv-button\" data-v-0af7725f>", "</button>", [_vm._t("default", function () {
825
+ })], 2) : _vm._ssrNode("<div data-v-4807283e>", "</div>", [_vm._ssrNode("<button type=\"button\" id=\"usecsv-button\" data-v-4807283e>", "</button>", [_vm._t("default", function () {
800
826
  return [_vm._v(" open usecsv ")];
801
827
  })], 2)])]);
802
828
  };
@@ -806,8 +832,8 @@ var __vue_staticRenderFns__ = [];
806
832
 
807
833
  var __vue_inject_styles__ = function __vue_inject_styles__(inject) {
808
834
  if (!inject) return;
809
- inject("data-v-0af7725f_0", {
810
- source: "#usecsv-button[data-v-0af7725f]{background-color:#fff;color:#000;border:2px solid #000;border-radius:6px;padding:10px 15px;text-align:center;font-size:16px;cursor:pointer}",
835
+ inject("data-v-4807283e_0", {
836
+ source: "#usecsv-button[data-v-4807283e]{background-color:#fff;color:#000;border:2px solid #000;border-radius:6px;padding:10px 15px;text-align:center;font-size:16px;cursor:pointer}",
811
837
  map: undefined,
812
838
  media: undefined
813
839
  });
@@ -815,10 +841,10 @@ var __vue_inject_styles__ = function __vue_inject_styles__(inject) {
815
841
  /* scoped */
816
842
 
817
843
 
818
- var __vue_scope_id__ = "data-v-0af7725f";
844
+ var __vue_scope_id__ = "data-v-4807283e";
819
845
  /* module identifier */
820
846
 
821
- var __vue_module_identifier__ = "data-v-0af7725f";
847
+ var __vue_module_identifier__ = "data-v-4807283e";
822
848
  /* functional template */
823
849
 
824
850
  var __vue_is_functional_template__ = false;
@@ -1,16 +1,18 @@
1
1
  import Vue from "vue";
2
- declare type UserObject = {
3
- readonly userId: string;
4
- };
5
- interface IUsecsv {
6
- importerKey: string;
7
- user?: UserObject;
8
- metadata: Record<string, string | number> | undefined;
9
- }
10
2
  declare const _default: import("vue/types/vue").ExtendedVue<Vue, {
11
3
  hasSlot: boolean;
12
4
  }, {
13
5
  openModal: () => void;
14
6
  hasScopedSlot: () => boolean;
15
- }, any, IUsecsv>;
7
+ }, any, {
8
+ readonly importerKey: string;
9
+ readonly user?: {
10
+ readonly userId: string;
11
+ } | undefined;
12
+ readonly metadata?: Record<string, string | number> | undefined;
13
+ readonly onData?: ((data: {
14
+ readonly uploadId: number;
15
+ readonly rows: readonly Record<string, string | number>[];
16
+ }) => void) | undefined;
17
+ }>;
16
18
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usecsv/vuejs",
3
- "version": "1.0.3",
3
+ "version": "1.1.1",
4
4
  "description": "",
5
5
  "main": "dist/UseCSVButton.ssr.js",
6
6
  "browser": "dist/UseCSVButton.esm.js",
@@ -13,7 +13,7 @@
13
13
  ],
14
14
  "sideEffects": false,
15
15
  "scripts": {
16
- "serve": "vue-cli-service help",
16
+ "serve": "vue-cli-service serve dev/serve.ts",
17
17
  "lint": "eslint src --ext .ts,.vue",
18
18
  "prebuild": "rimraf ./dist",
19
19
  "build": "cross-env NODE_ENV=production rollup --config build/rollup.config.js",
@@ -24,13 +24,7 @@
24
24
  "prepublishOnly": "yarn build"
25
25
  },
26
26
  "dependencies": {
27
- "@semantic-release/changelog": "^6.0.1",
28
- "@semantic-release/commit-analyzer": "^9.0.2",
29
- "@semantic-release/git": "^10.0.1",
30
- "@semantic-release/github": "^8.0.2",
31
- "@semantic-release/release-notes-generator": "^10.0.3",
32
- "@usecsv/js": "^0.1.0",
33
- "semantic-release": "^19.0.2"
27
+ "@usecsv/js": "0.2.0"
34
28
  },
35
29
  "devDependencies": {
36
30
  "@babel/core": "^7.14.6",
@@ -42,6 +36,11 @@
42
36
  "@rollup/plugin-node-resolve": "^9.0.0",
43
37
  "@rollup/plugin-replace": "^2.4.2",
44
38
  "@rushstack/eslint-patch": "^1.1.0",
39
+ "@semantic-release/changelog": "^6.0.1",
40
+ "@semantic-release/commit-analyzer": "^9.0.2",
41
+ "@semantic-release/git": "^10.0.1",
42
+ "@semantic-release/github": "^8.0.2",
43
+ "@semantic-release/release-notes-generator": "^10.0.3",
45
44
  "@vue/cli-plugin-babel": "^4.5.15",
46
45
  "@vue/cli-plugin-typescript": "^4.5.15",
47
46
  "@vue/cli-service": "^4.5.15",
@@ -56,6 +55,7 @@
56
55
  "rollup-plugin-terser": "^7.0.2",
57
56
  "rollup-plugin-typescript2": "^0.30.0",
58
57
  "rollup-plugin-vue": "^5.1.9",
58
+ "semantic-release": "^19.0.2",
59
59
  "ttypescript": "^1.5.12",
60
60
  "typescript": "^4.0.3",
61
61
  "vue": "^2.6.14",
@@ -2,21 +2,17 @@
2
2
  import Vue from "vue";
3
3
  import useCsvPlugin from "@usecsv/js";
4
4
 
5
- type UserObject = {
6
- readonly userId: string;
7
- };
8
- interface IUsecsv {
9
- importerKey: string;
10
- user?: UserObject;
11
- metadata: Record<string, string | number> | undefined;
12
- }
5
+
6
+ type IUsecsv = Parameters<typeof useCsvPlugin>[0];
7
+
13
8
 
14
9
  export default /*#__PURE__*/ Vue.extend<{hasSlot:boolean},{openModal:()=>void,hasScopedSlot:()=>boolean},any,IUsecsv>({
15
10
  name: "usecsv-button", // vue component name
16
11
  props:{
17
12
  importerKey:{},
18
13
  user:{},
19
- metadata:{}
14
+ metadata:{},
15
+ onData:{}
20
16
  },
21
17
  data() {
22
18
  return {
@@ -29,6 +25,7 @@ export default /*#__PURE__*/ Vue.extend<{hasSlot:boolean},{openModal:()=>void,ha
29
25
  importerKey: this.importerKey,
30
26
  user: this.user,
31
27
  metadata: this.metadata,
28
+ onData: this.onData,
32
29
  });
33
30
  },
34
31
  hasScopedSlot(): boolean {