@v2coding/ui 0.1.48 → 0.1.49

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.
@@ -667,7 +667,91 @@ var Objects = {
667
667
 
668
668
  }
669
669
  };
670
- var DefaultSetting$1 = DefaultSetting;var downloadFile = function downloadFile(data, filename, mime) {
670
+ var DefaultSetting$1 = DefaultSetting;var defaultOptions = {
671
+ timeout: 30000,
672
+ jsonpCallback: 'callback',
673
+ jsonpCallbackFunction: null
674
+ };
675
+
676
+ function generateCallbackFunction() {
677
+ return "jsonp_".concat(Date.now(), "_").concat(Math.ceil(Math.random() * 100000));
678
+ }
679
+
680
+ function clearFunction(functionName) {
681
+ // IE8 throws an exception when you try to delete a property on window
682
+ // http://stackoverflow.com/a/1824228/751089
683
+ try {
684
+ delete window[functionName];
685
+ } catch (e) {
686
+ window[functionName] = undefined;
687
+ }
688
+ }
689
+
690
+ function removeScript(scriptId) {
691
+ var script = document.getElementById(scriptId);
692
+
693
+ if (script) {
694
+ document.getElementsByTagName('head')[0].removeChild(script);
695
+ }
696
+ }
697
+
698
+ function jsonp(_url) {
699
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
700
+ // to avoid param reassign
701
+ var url = _url;
702
+ var timeout = options.timeout || defaultOptions.timeout;
703
+ var jsonpCallback = options.jsonpCallback || defaultOptions.jsonpCallback;
704
+ var timeoutId;
705
+ return new Promise(function (resolve, reject) {
706
+ var callbackFunction = options.jsonpCallbackFunction || generateCallbackFunction();
707
+ var scriptId = "".concat(jsonpCallback, "_").concat(callbackFunction);
708
+
709
+ window[callbackFunction] = function (response) {
710
+ resolve({
711
+ ok: true,
712
+ // keep consistent with fetch API
713
+ json: function json() {
714
+ return Promise.resolve(response);
715
+ }
716
+ });
717
+ if (timeoutId) clearTimeout(timeoutId);
718
+ removeScript(scriptId);
719
+ clearFunction(callbackFunction);
720
+ }; // Check if the user set their own params, and if not add a ? to start a list of params
721
+
722
+
723
+ url += url.indexOf('?') === -1 ? '?' : '&';
724
+ var jsonpScript = document.createElement('script');
725
+ jsonpScript.src = "".concat(url).concat(jsonpCallback, "=").concat(callbackFunction);
726
+
727
+ if (options.nonce) {
728
+ jsonpScript.nonce = options.nonce;
729
+ }
730
+
731
+ if (options.referrerPolicy) {
732
+ jsonpScript.referrerPolicy = options.referrerPolicy;
733
+ }
734
+
735
+ jsonpScript.id = scriptId;
736
+ document.head.appendChild(jsonpScript);
737
+ timeoutId = setTimeout(function () {
738
+ reject(new Error("JSONP request to ".concat(_url, " timed out")));
739
+ clearFunction(callbackFunction);
740
+ removeScript(scriptId);
741
+
742
+ window[callbackFunction] = function () {
743
+ clearFunction(callbackFunction);
744
+ };
745
+ }, timeout); // Caught if got 404/500
746
+
747
+ jsonpScript.onerror = function () {
748
+ reject(new Error("JSONP request to ".concat(_url, " failed")));
749
+ clearFunction(callbackFunction);
750
+ removeScript(scriptId);
751
+ if (timeoutId) clearTimeout(timeoutId);
752
+ };
753
+ });
754
+ }var downloadFile = function downloadFile(data, filename, mime) {
671
755
  var blob = new Blob([data], {
672
756
  type: mime || data.type || 'application/octet-stream'
673
757
  });
@@ -846,6 +930,7 @@ var init$2 = function init(Vue) {
846
930
  instance.interceptors.response.use(onResponseSuccess, onResponseError);
847
931
  downloadInstance.interceptors.request.use(onRequestSuccess);
848
932
  downloadInstance.interceptors.response.use(onResponseSuccess, onResponseError);
933
+ instance.jsonp = jsonp;
849
934
  instance.download = initDownload(downloadInstance);
850
935
  instance.downloadServer = downloadInstance;
851
936
  Vue.prototype.$axios = instance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v2coding/ui",
3
- "version": "0.1.48",
3
+ "version": "0.1.49",
4
4
  "description": "",
5
5
 
6
6
  "main": "dist/v2coding-ui.ssr.js",