@xy-planning-network/trees 0.6.1 → 0.6.2-rc-2

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
@@ -1,49 +1,4 @@
1
1
  import { ref, cloneVNode, h, inject, watchEffect, provide, defineComponent, onUnmounted, Teleport, reactive, onUpdated, computed, unref, onMounted, nextTick, toRaw, watch, openBlock, createBlock, createVNode, withCtx, Transition, createElementVNode, createElementBlock, Fragment, renderList, normalizeClass, toDisplayString, createCommentVNode, renderSlot, resolveDynamicComponent, mergeProps, createTextVNode, normalizeProps, useAttrs, shallowRef, withModifiers, TransitionGroup, withDirectives, vShow, normalizeStyle, getCurrentInstance, vModelText, resolveComponent, Comment as Comment$1, Text, useSlots } from "vue";
2
- function useSpinnerDisplay() {
3
- const idx = ref(0);
4
- const loading = ref(false);
5
- const maxIdx = ref(0);
6
- const messages = ref([]);
7
- const msg = ref("");
8
- const showMsg = ref(false);
9
- const show = (spinMessages = []) => {
10
- if (spinMessages) {
11
- messages.value = spinMessages;
12
- maxIdx.value = spinMessages.length - 1;
13
- msg.value = messages.value[idx.value];
14
- showMsg.value = true;
15
- }
16
- loading.value = true;
17
- };
18
- const hide = () => {
19
- idx.value = 0;
20
- maxIdx.value = 0;
21
- messages.value = [];
22
- msg.value = "";
23
- loading.value = false;
24
- };
25
- return {
26
- idx,
27
- loading,
28
- maxIdx,
29
- messages,
30
- msg,
31
- showMsg,
32
- show,
33
- hide
34
- };
35
- }
36
- let appSpinner = void 0;
37
- function useAppSpinnerDisplay() {
38
- if (appSpinner === void 0) {
39
- appSpinner = useSpinnerDisplay();
40
- }
41
- return appSpinner;
42
- }
43
- const useAppSpinner = (() => {
44
- const { show, hide } = useAppSpinnerDisplay();
45
- return { show, hide };
46
- })();
47
2
  var axios$2 = { exports: {} };
48
3
  var bind$2 = function bind(fn, thisArg) {
49
4
  return function wrap() {
@@ -1304,6 +1259,61 @@ axios$1.isAxiosError = isAxiosError;
1304
1259
  axios$2.exports = axios$1;
1305
1260
  axios$2.exports.default = axios$1;
1306
1261
  var axios = axios$2.exports;
1262
+ const HTTP_ERROR = "HttpError";
1263
+ const HTTP_CANCELLED_ERROR = "HttpCanceledError";
1264
+ class HttpError extends Error {
1265
+ constructor(message, status, response, name) {
1266
+ super(message || "");
1267
+ this.name = name || HTTP_ERROR;
1268
+ this.status = status || 0;
1269
+ this.response = response;
1270
+ }
1271
+ }
1272
+ function useSpinnerDisplay() {
1273
+ const idx = ref(0);
1274
+ const loading = ref(false);
1275
+ const maxIdx = ref(0);
1276
+ const messages = ref([]);
1277
+ const msg = ref("");
1278
+ const showMsg = ref(false);
1279
+ const show = (spinMessages = []) => {
1280
+ if (spinMessages) {
1281
+ messages.value = spinMessages;
1282
+ maxIdx.value = spinMessages.length - 1;
1283
+ msg.value = messages.value[idx.value];
1284
+ showMsg.value = true;
1285
+ }
1286
+ loading.value = true;
1287
+ };
1288
+ const hide = () => {
1289
+ idx.value = 0;
1290
+ maxIdx.value = 0;
1291
+ messages.value = [];
1292
+ msg.value = "";
1293
+ loading.value = false;
1294
+ };
1295
+ return {
1296
+ idx,
1297
+ loading,
1298
+ maxIdx,
1299
+ messages,
1300
+ msg,
1301
+ showMsg,
1302
+ show,
1303
+ hide
1304
+ };
1305
+ }
1306
+ let appSpinner = void 0;
1307
+ function useAppSpinnerDisplay() {
1308
+ if (appSpinner === void 0) {
1309
+ appSpinner = useSpinnerDisplay();
1310
+ }
1311
+ return appSpinner;
1312
+ }
1313
+ const useAppSpinner = (() => {
1314
+ const { show, hide } = useAppSpinnerDisplay();
1315
+ return { show, hide };
1316
+ })();
1307
1317
  const apiDelayReqIntercept = (config) => {
1308
1318
  const delay = config.withDelay || 0;
1309
1319
  return new Promise((resolve) => {
@@ -1312,50 +1322,82 @@ const apiDelayReqIntercept = (config) => {
1312
1322
  }, Math.max(delay, 0));
1313
1323
  });
1314
1324
  };
1315
- const apiDataRespIntercept = (response) => {
1316
- var _a;
1317
- if (response.config.dataIntercept && ((_a = response.data) == null ? void 0 : _a.data)) {
1318
- response.data = response.data.data;
1319
- }
1320
- return response;
1321
- };
1322
1325
  const apiAxiosInstance = axios.create({
1323
1326
  baseURL: process.env.VUE_APP_BASE_API_URL || "/api/v1",
1324
1327
  responseType: "json",
1325
1328
  withCredentials: true
1326
1329
  });
1327
1330
  apiAxiosInstance.interceptors.request.use(apiDelayReqIntercept);
1328
- apiAxiosInstance.interceptors.response.use(apiDataRespIntercept);
1331
+ const httpRequest = (config, opts) => {
1332
+ const options = {
1333
+ skipLoader: false,
1334
+ withDelay: 0,
1335
+ ...opts
1336
+ };
1337
+ const wait = window.setTimeout(() => {
1338
+ if (options.skipLoader !== true) {
1339
+ useAppSpinner.show();
1340
+ }
1341
+ }, 200);
1342
+ return apiAxiosInstance({ ...config, ...opts }).then((success) => {
1343
+ return success.data;
1344
+ }).catch((err) => {
1345
+ var _a, _b;
1346
+ if (axios.isAxiosError(err)) {
1347
+ throw new HttpError(
1348
+ err.message,
1349
+ (_a = err.response) == null ? void 0 : _a.status,
1350
+ (_b = err.response) == null ? void 0 : _b.data,
1351
+ axios.isCancel(err) ? "HttpCanceledError" : void 0
1352
+ );
1353
+ }
1354
+ if (err instanceof Error) {
1355
+ throw new HttpError(err.message, 0);
1356
+ }
1357
+ throw new HttpError("An unknown error has occurred.", 0);
1358
+ }).finally(() => {
1359
+ if (options.skipLoader !== true) {
1360
+ useAppSpinner.hide();
1361
+ }
1362
+ window.clearTimeout(wait);
1363
+ });
1364
+ };
1329
1365
  const BaseAPI = {
1330
- makeRequest(config, opts) {
1331
- const wait = window.setTimeout(() => {
1332
- if (!opts.skipLoader) {
1333
- useAppSpinner.show();
1334
- }
1335
- }, 200);
1336
- return apiAxiosInstance({ ...config, ...opts }).then((success) => success.data).finally(() => {
1337
- if (!opts.skipLoader)
1338
- useAppSpinner.hide();
1339
- window.clearTimeout(wait);
1340
- });
1341
- },
1342
1366
  get(path, opts, params) {
1343
- return this.makeRequest({ url: path, method: "GET", params }, opts);
1367
+ return httpRequest({ url: path, method: "GET", params }, opts || {});
1344
1368
  },
1345
1369
  delete(path, opts) {
1346
- return this.makeRequest({ url: path, method: "DELETE" }, opts);
1370
+ return httpRequest({ url: path, method: "DELETE" }, opts || {});
1371
+ },
1372
+ hasErrStatus(err, codes) {
1373
+ if (typeof codes === "number") {
1374
+ codes = [codes];
1375
+ }
1376
+ if (this.isHttpError(err)) {
1377
+ return codes.includes(err.status);
1378
+ }
1379
+ return false;
1380
+ },
1381
+ isHttpCancel(err) {
1382
+ return this.isHttpError(err) && err.name === HTTP_CANCELLED_ERROR;
1383
+ },
1384
+ isHttpError(err) {
1385
+ return err instanceof HttpError;
1386
+ },
1387
+ patch(path, data2, opts) {
1388
+ return httpRequest({ url: path, data: data2, method: "PATCH" }, opts || {});
1347
1389
  },
1348
1390
  post(path, data2, opts) {
1349
- return this.makeRequest({ url: path, data: data2, method: "POST" }, opts);
1391
+ return httpRequest({ url: path, data: data2, method: "POST" }, opts || {});
1350
1392
  },
1351
1393
  put(path, data2, opts) {
1352
- return this.makeRequest(
1394
+ return httpRequest(
1353
1395
  {
1354
1396
  url: path,
1355
1397
  data: data2,
1356
1398
  method: "PUT"
1357
1399
  },
1358
- opts
1400
+ opts || {}
1359
1401
  );
1360
1402
  }
1361
1403
  };
@@ -7456,13 +7498,13 @@ function useBaseAPI(path, method = "GET", initOpts = {}) {
7456
7498
  isFinished.value = false;
7457
7499
  isLoading.value = true;
7458
7500
  const requestConfig = {
7459
- data: ["POST", "post", "PUT", "put"].includes(method) ? data2 : {},
7501
+ data: ["PATCH", "patch", "POST", "post", "PUT", "put"].includes(method) ? data2 : {},
7460
7502
  method,
7461
7503
  params: ["GET", "get"].includes(method) ? data2 : {},
7462
7504
  signal: controller.signal,
7463
7505
  url: path
7464
7506
  };
7465
- return BaseAPI.makeRequest(requestConfig, { ...initOpts, ...opts }).then(
7507
+ return httpRequest(requestConfig, { ...initOpts, ...opts }).then(
7466
7508
  (success) => {
7467
7509
  result.value = success;
7468
7510
  error.value = void 0;
@@ -7471,7 +7513,7 @@ function useBaseAPI(path, method = "GET", initOpts = {}) {
7471
7513
  },
7472
7514
  (err) => {
7473
7515
  error.value = err;
7474
- if (axios.isCancel(err)) {
7516
+ if (BaseAPI.isHttpCancel(err)) {
7475
7517
  isAborted.value = true;
7476
7518
  }
7477
7519
  throw err;
@@ -9444,7 +9486,11 @@ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
9444
9486
  sortDir: currentSortDirection.value,
9445
9487
  q: query.value
9446
9488
  };
9447
- BaseAPI.get(props.tableData.url, { skipLoader: !props.loader }, params).then(
9489
+ BaseAPI.get(
9490
+ props.tableData.url,
9491
+ { skipLoader: !props.loader },
9492
+ params
9493
+ ).then(
9448
9494
  (success) => {
9449
9495
  pagination.value = {
9450
9496
  page: success.data.page,