@xy-planning-network/trees 0.4.8-rc-1 → 0.4.9-rc-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/dist/trees.es.js CHANGED
@@ -1237,31 +1237,39 @@ axios$1.isAxiosError = isAxiosError;
1237
1237
  axios$2.exports = axios$1;
1238
1238
  axios$2.exports.default = axios$1;
1239
1239
  var axios = axios$2.exports;
1240
+ const apiDelayReqIntercept = (config) => {
1241
+ const delay = config.withDelay || 0;
1242
+ return new Promise((resolve) => {
1243
+ setTimeout(() => {
1244
+ resolve(config);
1245
+ }, Math.max(delay, 0));
1246
+ });
1247
+ };
1248
+ const apiDataRespIntercept = (response) => {
1249
+ var _a;
1250
+ if (response.config.dataIntercept && ((_a = response.data) == null ? void 0 : _a.data)) {
1251
+ response.data = response.data.data;
1252
+ }
1253
+ return response;
1254
+ };
1240
1255
  const apiAxiosInstance = axios.create({
1241
1256
  baseURL: process.env.VUE_APP_BASE_API_URL || "/api/v1",
1242
1257
  responseType: "json",
1243
1258
  withCredentials: true
1244
1259
  });
1260
+ apiAxiosInstance.interceptors.request.use(apiDelayReqIntercept);
1261
+ apiAxiosInstance.interceptors.response.use(apiDataRespIntercept);
1245
1262
  const BaseAPI = {
1246
1263
  makeRequest(config, opts) {
1247
- config.data = JSON.stringify(config.data);
1248
- config.headers = { "Content-Type": "application/json" };
1249
1264
  const wait = window.setTimeout(() => {
1250
- if (!opts.skipLoader)
1265
+ if (!opts.skipLoader) {
1251
1266
  window.VueBus.emit("Spinner-show");
1267
+ }
1252
1268
  }, 200);
1253
- return new Promise((resolve, reject) => {
1254
- setTimeout(() => {
1255
- apiAxiosInstance(config).then((success) => {
1256
- resolve(success.data);
1257
- }, (err) => {
1258
- reject(err);
1259
- }).finally(() => {
1260
- window.clearTimeout(wait);
1261
- if (!opts.skipLoader)
1262
- window.VueBus.emit("Spinner-hide");
1263
- });
1264
- }, (opts == null ? void 0 : opts.withDelay) ? opts.withDelay : 0);
1269
+ return apiAxiosInstance(__spreadValues(__spreadValues({}, config), opts)).then((success) => success.data).finally(() => {
1270
+ if (!opts.skipLoader)
1271
+ window.VueBus.emit("Spinner-hide");
1272
+ window.clearTimeout(wait);
1265
1273
  });
1266
1274
  },
1267
1275
  get(path, opts, params) {
@@ -1274,7 +1282,11 @@ const BaseAPI = {
1274
1282
  return this.makeRequest({ url: path, data: data2, method: "POST" }, opts);
1275
1283
  },
1276
1284
  put(path, data2, opts) {
1277
- return this.makeRequest({ url: path, data: data2, method: "PUT" }, opts);
1285
+ return this.makeRequest({
1286
+ url: path,
1287
+ data: data2,
1288
+ method: "PUT"
1289
+ }, opts);
1278
1290
  }
1279
1291
  };
1280
1292
  function _extends() {
@@ -9417,7 +9429,7 @@ var components = /* @__PURE__ */ Object.freeze({
9417
9429
  TextArea: _sfc_main$1,
9418
9430
  YesOrNoRadio: _sfc_main
9419
9431
  });
9420
- function useBaseAPI(path, method = "GET", initOpts = {}, initConfig = {}) {
9432
+ function useBaseAPI(path, method = "GET", initOpts = {}) {
9421
9433
  const result = ref();
9422
9434
  const error = shallowRef();
9423
9435
  const hasFetched = ref(false);
@@ -9431,21 +9443,21 @@ function useBaseAPI(path, method = "GET", initOpts = {}, initConfig = {}) {
9431
9443
  controller.abort();
9432
9444
  }
9433
9445
  };
9434
- const execute = (data2 = {}, execOpts = {}, execConfig = {}) => {
9446
+ const execute = (data2 = {}, opts = {}) => {
9435
9447
  requestCount++;
9436
9448
  const count = requestCount;
9437
9449
  controller = new AbortController();
9438
9450
  isAborted.value = false;
9439
9451
  isFinished.value = false;
9440
9452
  isLoading.value = true;
9441
- const requestConfig = __spreadValues(__spreadProps(__spreadValues({}, initConfig), {
9442
- data: !["GET", "get"].includes(method) ? data2 : {},
9453
+ const requestConfig = {
9454
+ data: ["POST", "post", "PUT", "put"].includes(method) ? data2 : {},
9443
9455
  method,
9444
9456
  params: ["GET", "get"].includes(method) ? data2 : {},
9445
9457
  signal: controller.signal,
9446
9458
  url: path
9447
- }), execConfig);
9448
- return BaseAPI.makeRequest(requestConfig, __spreadValues(__spreadValues({}, initOpts), execOpts)).then((success) => {
9459
+ };
9460
+ return BaseAPI.makeRequest(requestConfig, __spreadValues(__spreadValues({}, initOpts), opts)).then((success) => {
9449
9461
  result.value = success;
9450
9462
  error.value = void 0;
9451
9463
  isAborted.value = false;
@@ -9478,17 +9490,17 @@ function useBaseAPI(path, method = "GET", initOpts = {}, initConfig = {}) {
9478
9490
  execute
9479
9491
  };
9480
9492
  }
9481
- function useBaseAPIGet(url, initOpts = {}, initConfig = {}) {
9482
- return useBaseAPI(url, "GET", initOpts, initConfig);
9493
+ function useBaseAPIGet(url, opts = {}) {
9494
+ return useBaseAPI(url, "GET", opts);
9483
9495
  }
9484
- function useBaseAPIDelete(url, initOpts = {}, initConfig = {}) {
9485
- return useBaseAPI(url, "DELETE", initOpts, initConfig);
9496
+ function useBaseAPIDelete(url, opts = {}) {
9497
+ return useBaseAPI(url, "DELETE", opts);
9486
9498
  }
9487
- function useBaseAPIPost(url, initOpts = {}, initConfig = {}) {
9488
- return useBaseAPI(url, "POST", initOpts, initConfig);
9499
+ function useBaseAPIPost(url, opts = {}) {
9500
+ return useBaseAPI(url, "POST", opts);
9489
9501
  }
9490
- function useBaseAPIPut(url, initOpts = {}, initConfig = {}) {
9491
- return useBaseAPI(url, "PUT", initOpts, initConfig);
9502
+ function useBaseAPIPut(url, opts = {}) {
9503
+ return useBaseAPI(url, "PUT", opts);
9492
9504
  }
9493
9505
  const install = function installTrees(app) {
9494
9506
  Object.entries(components).forEach(([componentName, component]) => {