@xy-planning-network/trees 0.4.8-rc-2 → 0.4.8

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,66 +1237,55 @@ 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 apiAxiosInstance = axios.create({
1241
- baseURL: process.env.VUE_APP_BASE_API_URL || "/api/v1",
1242
- responseType: "json",
1243
- withCredentials: true
1244
- });
1245
- const apiDataIntercept = (response) => {
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) => {
1246
1249
  var _a;
1247
- if ((_a = response.data) == null ? void 0 : _a.data) {
1248
- return response.data;
1250
+ if (response.config.dataIntercept && ((_a = response.data) == null ? void 0 : _a.data)) {
1251
+ response.data = response.data.data;
1249
1252
  }
1250
1253
  return response;
1251
1254
  };
1252
- const apiDelay = (func, delay = 0) => {
1253
- setTimeout(func, delay);
1254
- };
1255
+ const apiAxiosInstance = axios.create({
1256
+ baseURL: process.env.VUE_APP_BASE_API_URL || "/api/v1",
1257
+ responseType: "json",
1258
+ withCredentials: true,
1259
+ headers: {
1260
+ "Content-Type": "application/json"
1261
+ }
1262
+ });
1263
+ apiAxiosInstance.interceptors.request.use(apiDelayReqIntercept);
1264
+ apiAxiosInstance.interceptors.response.use(apiDataRespIntercept);
1255
1265
  const BaseAPI = {
1256
- makeRequest(config, opts) {
1257
- config.data = JSON.stringify(config.data);
1258
- config.headers = { "Content-Type": "application/json" };
1259
- let dataIntercept;
1260
- if (opts.dataIntercept) {
1261
- dataIntercept = apiAxiosInstance.interceptors.response.use(apiDataIntercept);
1262
- }
1266
+ makeRequest(opts) {
1263
1267
  const wait = window.setTimeout(() => {
1264
1268
  if (!opts.skipLoader) {
1265
1269
  window.VueBus.emit("Spinner-show");
1266
1270
  }
1267
1271
  }, 200);
1268
- return new Promise((resolve, reject) => {
1269
- apiAxiosInstance(config).then((success) => {
1270
- apiDelay(() => {
1271
- resolve(success.data);
1272
- }, opts.withDelay || 0);
1273
- }, (err) => {
1274
- apiDelay(() => {
1275
- reject(err);
1276
- }, opts.withDelay || 0);
1277
- }).finally(() => {
1278
- if (dataIntercept !== null) {
1279
- apiAxiosInstance.interceptors.response.eject(dataIntercept);
1280
- }
1281
- apiDelay(() => {
1282
- window.clearTimeout(wait);
1283
- if (!opts.skipLoader)
1284
- window.VueBus.emit("Spinner-hide");
1285
- }, opts.withDelay || 0);
1286
- });
1272
+ return apiAxiosInstance(opts).then((success) => success.data).finally(() => {
1273
+ if (!opts.skipLoader)
1274
+ window.VueBus.emit("Spinner-hide");
1275
+ window.clearTimeout(wait);
1287
1276
  });
1288
1277
  },
1289
1278
  get(path, opts, params) {
1290
- return this.makeRequest({ url: path, method: "GET", params }, opts);
1279
+ return this.makeRequest(__spreadValues({ url: path, method: "GET", params }, opts));
1291
1280
  },
1292
1281
  delete(path, opts) {
1293
- return this.makeRequest({ url: path, method: "DELETE" }, opts);
1282
+ return this.makeRequest(__spreadValues({ url: path, method: "DELETE" }, opts));
1294
1283
  },
1295
1284
  post(path, data2, opts) {
1296
- return this.makeRequest({ url: path, data: data2, method: "POST" }, opts);
1285
+ return this.makeRequest(__spreadValues({ url: path, data: data2, method: "POST" }, opts));
1297
1286
  },
1298
1287
  put(path, data2, opts) {
1299
- return this.makeRequest({ url: path, data: data2, method: "PUT" }, opts);
1288
+ return this.makeRequest(__spreadValues({ url: path, data: data2, method: "PUT" }, opts));
1300
1289
  }
1301
1290
  };
1302
1291
  function _extends() {
@@ -9439,7 +9428,7 @@ var components = /* @__PURE__ */ Object.freeze({
9439
9428
  TextArea: _sfc_main$1,
9440
9429
  YesOrNoRadio: _sfc_main
9441
9430
  });
9442
- function useBaseAPI(path, method = "GET", initOpts = {}, initConfig = {}) {
9431
+ function useBaseAPI(path, method = "GET", initOpts = {}) {
9443
9432
  const result = ref();
9444
9433
  const error = shallowRef();
9445
9434
  const hasFetched = ref(false);
@@ -9453,21 +9442,21 @@ function useBaseAPI(path, method = "GET", initOpts = {}, initConfig = {}) {
9453
9442
  controller.abort();
9454
9443
  }
9455
9444
  };
9456
- const execute = (data2 = {}, execOpts = {}, execConfig = {}) => {
9445
+ const execute = (data2 = {}, opts = {}) => {
9457
9446
  requestCount++;
9458
9447
  const count = requestCount;
9459
9448
  controller = new AbortController();
9460
9449
  isAborted.value = false;
9461
9450
  isFinished.value = false;
9462
9451
  isLoading.value = true;
9463
- const requestConfig = __spreadValues(__spreadProps(__spreadValues({}, initConfig), {
9464
- data: !["GET", "get"].includes(method) ? data2 : {},
9452
+ const requestOpts = __spreadValues(__spreadProps(__spreadValues({}, initOpts), {
9453
+ data: ["POST", "post", "PUT", "put"].includes(method) ? data2 : {},
9465
9454
  method,
9466
9455
  params: ["GET", "get"].includes(method) ? data2 : {},
9467
9456
  signal: controller.signal,
9468
9457
  url: path
9469
- }), execConfig);
9470
- return BaseAPI.makeRequest(requestConfig, __spreadValues(__spreadValues({}, initOpts), execOpts)).then((success) => {
9458
+ }), opts);
9459
+ return BaseAPI.makeRequest(requestOpts).then((success) => {
9471
9460
  result.value = success;
9472
9461
  error.value = void 0;
9473
9462
  isAborted.value = false;
@@ -9500,17 +9489,17 @@ function useBaseAPI(path, method = "GET", initOpts = {}, initConfig = {}) {
9500
9489
  execute
9501
9490
  };
9502
9491
  }
9503
- function useBaseAPIGet(url, initOpts = {}, initConfig = {}) {
9504
- return useBaseAPI(url, "GET", initOpts, initConfig);
9492
+ function useBaseAPIGet(url, opts = {}) {
9493
+ return useBaseAPI(url, "GET", opts);
9505
9494
  }
9506
- function useBaseAPIDelete(url, initOpts = {}, initConfig = {}) {
9507
- return useBaseAPI(url, "DELETE", initOpts, initConfig);
9495
+ function useBaseAPIDelete(url, opts = {}) {
9496
+ return useBaseAPI(url, "DELETE", opts);
9508
9497
  }
9509
- function useBaseAPIPost(url, initOpts = {}, initConfig = {}) {
9510
- return useBaseAPI(url, "POST", initOpts, initConfig);
9498
+ function useBaseAPIPost(url, opts = {}) {
9499
+ return useBaseAPI(url, "POST", opts);
9511
9500
  }
9512
- function useBaseAPIPut(url, initOpts = {}, initConfig = {}) {
9513
- return useBaseAPI(url, "PUT", initOpts, initConfig);
9501
+ function useBaseAPIPut(url, opts = {}) {
9502
+ return useBaseAPI(url, "PUT", opts);
9514
9503
  }
9515
9504
  const install = function installTrees(app) {
9516
9505
  Object.entries(components).forEach(([componentName, component]) => {