@panneau/data 4.0.63 → 4.0.72
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/index.d.ts +3 -1
- package/dist/index.js +22 -12
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -100,9 +100,10 @@ type UseResourceDestroyResult = UseMutationResult & {
|
|
|
100
100
|
destroyAsync: (id?: string) => Promise<unknown>;
|
|
101
101
|
loading: boolean;
|
|
102
102
|
};
|
|
103
|
+
declare function useResourceDestroy(resource: Resource | string): UseResourceDestroyResult;
|
|
103
104
|
declare function useResourceDestroy(id: string | null): UseResourceDestroyResult;
|
|
104
|
-
declare function useResourceDestroy(id: string | null, options: UseMutationOptions): UseResourceDestroyResult;
|
|
105
105
|
declare function useResourceDestroy(resource: Resource | string, id: string | null): UseResourceDestroyResult;
|
|
106
|
+
declare function useResourceDestroy(id: string | null, options: UseMutationOptions): UseResourceDestroyResult;
|
|
106
107
|
declare function useResourceDestroy(resource: Resource | string, id: string | null, options: UseMutationOptions): UseResourceDestroyResult;
|
|
107
108
|
|
|
108
109
|
type UseResourceItem<T> = UseQueryResult<T> & {
|
|
@@ -157,6 +158,7 @@ declare class Base {
|
|
|
157
158
|
requestPut(path: any, data: any, opts?: any): Promise<unknown>;
|
|
158
159
|
requestPatch(path: any, data: any, opts?: any): Promise<unknown>;
|
|
159
160
|
requestDelete(path: any): Promise<unknown>;
|
|
161
|
+
hasRoute(route: any): boolean;
|
|
160
162
|
route(route: any, params: any): any;
|
|
161
163
|
getFullUrl(path: any): any;
|
|
162
164
|
onError(err: any): any;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { c } from 'react/compiler-runtime';
|
|
2
2
|
import { useState, use, createContext } from 'react';
|
|
3
|
-
import { useUrlGenerator, usePanneauResource, useResource } from '@panneau/core/contexts';
|
|
3
|
+
import { useUrlGenerator, useRoutes, usePanneauResource, useResource } from '@panneau/core/contexts';
|
|
4
4
|
import { getJSON, getCSRFHeaders, postJSON } from '@folklore/fetch';
|
|
5
5
|
import { generatePath } from '@folklore/routes';
|
|
6
6
|
import queryString from 'query-string';
|
|
@@ -618,6 +618,12 @@ class Base {
|
|
|
618
618
|
_method: 'DELETE'
|
|
619
619
|
}).catch(error => this.onError(error));
|
|
620
620
|
}
|
|
621
|
+
hasRoute(route) {
|
|
622
|
+
const {
|
|
623
|
+
routes
|
|
624
|
+
} = this.options;
|
|
625
|
+
return typeof routes[route] !== 'undefined';
|
|
626
|
+
}
|
|
621
627
|
route(route, params) {
|
|
622
628
|
const {
|
|
623
629
|
routes,
|
|
@@ -740,8 +746,9 @@ class ResourcesApi {
|
|
|
740
746
|
id,
|
|
741
747
|
has_routes: hasRoutes = false
|
|
742
748
|
}, route, params) {
|
|
743
|
-
const
|
|
744
|
-
|
|
749
|
+
const hasSpecificRoute = this.hasRoute(`resources.${id}.${route}`);
|
|
750
|
+
const routeName = hasSpecificRoute ? `resources.${id}.${route}` : `resources.${id}`;
|
|
751
|
+
return this.api.route(routeName, hasSpecificRoute ? params : {
|
|
745
752
|
resource: id,
|
|
746
753
|
...params
|
|
747
754
|
});
|
|
@@ -821,7 +828,7 @@ function useApi() {
|
|
|
821
828
|
return use(ApiContext);
|
|
822
829
|
}
|
|
823
830
|
function ApiProvider(t0) {
|
|
824
|
-
const $ = c(
|
|
831
|
+
const $ = c(10);
|
|
825
832
|
const {
|
|
826
833
|
api: t1,
|
|
827
834
|
baseUrl: t2,
|
|
@@ -833,11 +840,13 @@ function ApiProvider(t0) {
|
|
|
833
840
|
const onUnauthorized = t3 === undefined ? null : t3;
|
|
834
841
|
const generateUrl = useUrlGenerator();
|
|
835
842
|
const previousApi = useApi();
|
|
843
|
+
const routes = useRoutes();
|
|
836
844
|
let t4;
|
|
837
|
-
if ($[0] !== baseUrl || $[1] !== generateUrl || $[2] !== initialApi || $[3] !== onUnauthorized || $[4] !== previousApi) {
|
|
845
|
+
if ($[0] !== baseUrl || $[1] !== generateUrl || $[2] !== initialApi || $[3] !== onUnauthorized || $[4] !== previousApi || $[5] !== routes) {
|
|
838
846
|
t4 = initialApi || previousApi || new Api({
|
|
839
847
|
baseUrl,
|
|
840
848
|
generateUrl,
|
|
849
|
+
routes,
|
|
841
850
|
onUnauthorized
|
|
842
851
|
});
|
|
843
852
|
$[0] = baseUrl;
|
|
@@ -845,22 +854,23 @@ function ApiProvider(t0) {
|
|
|
845
854
|
$[2] = initialApi;
|
|
846
855
|
$[3] = onUnauthorized;
|
|
847
856
|
$[4] = previousApi;
|
|
848
|
-
$[5] =
|
|
857
|
+
$[5] = routes;
|
|
858
|
+
$[6] = t4;
|
|
849
859
|
} else {
|
|
850
|
-
t4 = $[
|
|
860
|
+
t4 = $[6];
|
|
851
861
|
}
|
|
852
862
|
const api = t4;
|
|
853
863
|
let t5;
|
|
854
|
-
if ($[
|
|
864
|
+
if ($[7] !== api || $[8] !== children) {
|
|
855
865
|
t5 = /*#__PURE__*/jsx(ApiContext, {
|
|
856
866
|
value: api,
|
|
857
867
|
children: children
|
|
858
868
|
});
|
|
859
|
-
$[
|
|
860
|
-
$[
|
|
861
|
-
$[
|
|
869
|
+
$[7] = api;
|
|
870
|
+
$[8] = children;
|
|
871
|
+
$[9] = t5;
|
|
862
872
|
} else {
|
|
863
|
-
t5 = $[
|
|
873
|
+
t5 = $[9];
|
|
864
874
|
}
|
|
865
875
|
return t5;
|
|
866
876
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panneau/data",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.72",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@babel/runtime": "^7.28.6",
|
|
56
56
|
"@folklore/fetch": "^0.1.21",
|
|
57
|
-
"@folklore/routes": "^0.
|
|
58
|
-
"@panneau/core": "^4.0.
|
|
57
|
+
"@folklore/routes": "^0.4.11",
|
|
58
|
+
"@panneau/core": "^4.0.72",
|
|
59
59
|
"@tanstack/react-query": "^5.100.9",
|
|
60
60
|
"lodash": "^4.17.21",
|
|
61
61
|
"query-string": "^9.0.0"
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"access": "public"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "6ef477fccf4ca9b81fcca140f56eb45413391c87"
|
|
75
75
|
}
|