@xy-planning-network/trees 0.4.6 → 0.4.8-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xy-planning-network/trees",
3
- "version": "0.4.6",
3
+ "version": "0.4.8-rc-2",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "repository": "github:xy-planning-network/trees",
@@ -58,7 +58,7 @@
58
58
  "dependencies": {
59
59
  "@headlessui/vue": "^1.4.2",
60
60
  "@heroicons/vue": "^1.0.5",
61
- "axios": "^0.21.4",
61
+ "axios": "^0.27.2",
62
62
  "flatpickr": "^4.6.9"
63
63
  },
64
64
  "peerDependencies": {
@@ -79,7 +79,7 @@ const onChange = (checked: boolean, val: CheckboxValue) => {
79
79
  >
80
80
  <div class="flex items-center h-5">
81
81
  <input
82
- :id="uuid"
82
+ :id="`${uuid}-${index}`"
83
83
  :aria-labelledby="`${uuid}-${index}-label`"
84
84
  :aria-describedby="
85
85
  option?.help && option.help
@@ -91,7 +91,9 @@ const onChange = (checked: boolean, val: CheckboxValue) => {
91
91
  class="focus:ring-blue-500 h-4 w-4 text-blue-500 border-gray-600 rounded disabled:opacity-50 disabled:cursor-not-allowed"
92
92
  type="checkbox"
93
93
  v-bind="{
94
- onChange: ($event) => { onChange(($event.target as HTMLInputElement).checked, option.value) },
94
+ onChange: ($event) => {
95
+ onChange(($event.target as HTMLInputElement).checked, option.value)
96
+ },
95
97
  ...$attrs,
96
98
  }"
97
99
  />
@@ -105,7 +107,7 @@ const onChange = (checked: boolean, val: CheckboxValue) => {
105
107
  option.disabled === true
106
108
  "
107
109
  :id="`${uuid}-${index}-label`"
108
- :for="uuid"
110
+ :for="`${uuid}-${index}`"
109
111
  :label="option.label"
110
112
  />
111
113
  <InputHelp
@@ -93,7 +93,7 @@ const hasLegend = computed(() => {
93
93
  option.disabled === true
94
94
  "
95
95
  :id="`${uuid}-${index}-label`"
96
- :for="uuid"
96
+ :for="`${uuid}-${index}`"
97
97
  :label="option.label"
98
98
  />
99
99
  <InputHelp
@@ -1,12 +1,18 @@
1
- import { AxiosPromise, AxiosRequestConfig } from "axios";
1
+ import { AxiosResponse, AxiosRequestConfig } from "axios";
2
+ export declare type RequestMethod = "GET" | "get" | "PUT" | "put" | "POST" | "post" | "DELETE" | "delete";
3
+ export interface TreesResponse<T> extends AxiosResponse<T> {
4
+ data: T;
5
+ }
2
6
  export interface RequestOptions {
7
+ dataIntercept?: boolean;
3
8
  skipLoader?: boolean;
9
+ withDelay?: number;
4
10
  }
5
11
  declare const BaseAPI: {
6
- makeRequest(config: AxiosRequestConfig, opts: RequestOptions): AxiosPromise;
7
- get(path: string, opts: RequestOptions, params?: Record<string, unknown> | undefined): AxiosPromise;
8
- delete(path: string, opts: RequestOptions): AxiosPromise;
9
- post(path: string, data: Record<string, unknown>, opts: RequestOptions): AxiosPromise;
10
- put(path: string, data: Record<string, unknown>, opts: RequestOptions): AxiosPromise;
12
+ makeRequest<T = any>(config: AxiosRequestConfig, opts: RequestOptions): Promise<T>;
13
+ get<T_1 = any>(path: string, opts: RequestOptions, params?: Record<string, unknown> | undefined): Promise<T_1>;
14
+ delete<T_2 = any>(path: string, opts: RequestOptions): Promise<T_2>;
15
+ post<T_3 = any>(path: string, data: Record<string, unknown>, opts: RequestOptions): Promise<T_3>;
16
+ put<T_4 = any>(path: string, data: Record<string, unknown>, opts: RequestOptions): Promise<T_4>;
11
17
  };
12
18
  export default BaseAPI;
@@ -0,0 +1,4 @@
1
+ import { default as useBaseAPI, useBaseAPIGet, useBaseAPIPut, useBaseAPIPost, useBaseAPIDelete } from "./useBaseAPI";
2
+ import type { UseBaseAPIOptions, UseBaseAPI } from "./useBaseAPI";
3
+ export type { UseBaseAPIOptions, UseBaseAPI };
4
+ export { useBaseAPI, useBaseAPIGet, useBaseAPIPut, useBaseAPIPost, useBaseAPIDelete, };
@@ -0,0 +1,105 @@
1
+ import { AxiosError, AxiosRequestConfig } from "axios";
2
+ import { Ref, ShallowRef } from "vue";
3
+ import type { RequestMethod, RequestOptions } from "../api/base";
4
+ /**
5
+ * UseBaseAPIOptions extends Trees/RequestOptions
6
+ * these options are used only in the instantiation
7
+ * of a new UseBaseAPI composable
8
+ */
9
+ export interface UseBaseAPIOptions extends RequestOptions {
10
+ /**
11
+ * Whether to immediately fire the execute function during instantiation
12
+ */
13
+ immediate?: boolean;
14
+ }
15
+ /**
16
+ * UseBaseAPI is a composable the wraps up the
17
+ * usage of Trees/BaseAPI and returns reactive
18
+ * state variables along with reusaable execute and abort functions
19
+ */
20
+ export interface UseBaseAPI<T> {
21
+ /**
22
+ * Axios response data
23
+ */
24
+ result: Ref<T | undefined>;
25
+ /**
26
+ * Any errors that may have occurred
27
+ */
28
+ error: ShallowRef<Error | AxiosError<T> | undefined>;
29
+ /**
30
+ * Indicates if the request has finished
31
+ */
32
+ isFinished: Ref<boolean>;
33
+ /**
34
+ * Indicates if the request is currently loading
35
+ */
36
+ isLoading: Ref<boolean>;
37
+ /**
38
+ * Indicates if the request was canceled
39
+ */
40
+ isAborted: Ref<boolean>;
41
+ /**
42
+ * Indicates if a first request has completed
43
+ */
44
+ hasFetched: Ref<boolean>;
45
+ /**
46
+ * Aborts the current request
47
+ * can be used multiple times
48
+ */
49
+ abort: () => void;
50
+ /**
51
+ * Manually call the axios request
52
+ * can be used multiple times
53
+ */
54
+ execute: (data?: Record<string, unknown>, opts?: RequestOptions, config?: AxiosRequestConfig) => Promise<T>;
55
+ }
56
+ /**
57
+ * useBaseAPI is a composable wrapper of BaseAPI
58
+ * @param path {string} the api path or full url for the
59
+ * @param method {RequestMethod} the initial request type
60
+ * @param initOpts {UseBaseAPIOptions}
61
+ * @param initConfig {AxiosRequestConfig}
62
+ * @returns {UseBaseAPI<T>}
63
+ */
64
+ export default function useBaseAPI<T = any>(path: string, method?: RequestMethod, initOpts?: UseBaseAPIOptions, initConfig?: AxiosRequestConfig): {
65
+ result: Ref<T | undefined>;
66
+ error: ShallowRef<Error | AxiosError<T, any> | undefined>;
67
+ isFinished: Ref<boolean>;
68
+ isLoading: Ref<boolean>;
69
+ isAborted: Ref<boolean>;
70
+ hasFetched: Ref<boolean>;
71
+ abort: () => void;
72
+ execute: (data?: Record<string, unknown>, execOpts?: RequestOptions, execConfig?: AxiosRequestConfig) => Promise<T>;
73
+ };
74
+ /**
75
+ * useBaseAPIGet is a convenience function for useBaseAPI
76
+ * @param path {string} the api path or full url for the
77
+ * @param initOpts {UseBaseAPIOptions}
78
+ * @param initConfig {AxiosRequestConfig}
79
+ * @returns {UseBaseAPI<T>}
80
+ */
81
+ export declare function useBaseAPIGet<T = any>(url: string, initOpts?: UseBaseAPIOptions, initConfig?: AxiosRequestConfig): UseBaseAPI<T>;
82
+ /**
83
+ * useBaseAPIDelete is a convenience function for useBaseAPI
84
+ * @param path {string} the api path or full url for the
85
+ * @param initOpts {UseBaseAPIOptions}
86
+ * @param initConfig {AxiosRequestConfig}
87
+ * @returns {UseBaseAPI<T>}
88
+ */
89
+ export declare function useBaseAPIDelete<T = any>(url: string, initOpts?: UseBaseAPIOptions, initConfig?: AxiosRequestConfig): UseBaseAPI<T>;
90
+ /**
91
+ * useBaseAPIPost is a convenience function for useBaseAPI
92
+ * @param path {string} the api path or full url for the
93
+ * @param initOpts {UseBaseAPIOptions}
94
+ * @param initConfig {AxiosRequestConfig}
95
+ * @returns {UseBaseAPI<T>}
96
+ */
97
+ export declare function useBaseAPIPost<T = any>(url: string, initOpts?: UseBaseAPIOptions, initConfig?: AxiosRequestConfig): UseBaseAPI<T>;
98
+ /**
99
+ * useBaseAPIPut is a convenience function for useBaseAPI
100
+ * @param path {string} the api path or full url for the
101
+ * @param initOpts {UseBaseAPIOptions}
102
+ * @param initConfig {AxiosRequestConfig}
103
+ * @returns {UseBaseAPI<T>}
104
+ */
105
+ export declare function useBaseAPIPut<T = any>(url: string, initOpts?: UseBaseAPIOptions, initConfig?: AxiosRequestConfig): UseBaseAPI<T>;
package/types/entry.d.ts CHANGED
@@ -2,5 +2,6 @@ import { Plugin } from "vue";
2
2
  import BaseAPI from "./api/base";
3
3
  declare const install: Exclude<Plugin["install"], undefined>;
4
4
  export default install;
5
+ export * from "./composables/index";
5
6
  export * from "./lib-components/index";
6
7
  export { BaseAPI };
@@ -1 +1,2 @@
1
1
  export declare function debounce(func: () => void, timeout?: number): () => void;
2
+ export declare function debounceLeading(func: () => void, timeout?: number): (...args: any[]) => void;
@@ -0,0 +1,12 @@
1
+ export interface Pagination {
2
+ page: number;
3
+ perPage: number;
4
+ totalItems: number;
5
+ totalPages: number;
6
+ }
7
+ export interface PaginationItems<T = any> {
8
+ items: T[];
9
+ }
10
+ export interface PaginationData<T = any> {
11
+ data: Pagination & PaginationItems<T>;
12
+ }