@panneau/core 4.0.66 → 4.0.73

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.
@@ -156,6 +156,13 @@ interface Field {
156
156
  component?: string | ElementType;
157
157
  label?: ReactNode;
158
158
  }
159
+ /**
160
+ * Form definition
161
+ */
162
+ interface Form {
163
+ title: ReactNode;
164
+ fields?: Field[];
165
+ }
159
166
 
160
167
  /**
161
168
  * Resource Types
@@ -218,7 +225,7 @@ interface Resource {
218
225
  intl?: ResourceIntl;
219
226
  fields?: Field[];
220
227
  index?: ResourceIndex;
221
- forms?: Record<string, unknown>;
228
+ forms?: Record<string, Form>;
222
229
  shows_in_navbar?: boolean;
223
230
  settings?: Record<string, unknown>;
224
231
  }
package/dist/hooks.d.ts CHANGED
@@ -34,6 +34,13 @@ interface Field$1 {
34
34
  component?: string | ElementType;
35
35
  label?: ReactNode;
36
36
  }
37
+ /**
38
+ * Form definition
39
+ */
40
+ interface Form {
41
+ title: ReactNode;
42
+ fields?: Field$1[];
43
+ }
37
44
 
38
45
  /**
39
46
  * Resource Types
@@ -96,7 +103,7 @@ interface Resource {
96
103
  intl?: ResourceIntl;
97
104
  fields?: Field$1[];
98
105
  index?: ResourceIndex;
99
- forms?: Record<string, unknown>;
106
+ forms?: Record<string, Form>;
100
107
  shows_in_navbar?: boolean;
101
108
  settings?: Record<string, unknown>;
102
109
  }
@@ -351,8 +358,8 @@ interface ResourceWithTypes extends Resource {
351
358
  }
352
359
  declare function useResourceTypeName(resource: ResourceWithTypes | null, type?: string | null): string | null;
353
360
 
354
- type ResourceUrlGenerator = (routeResourceId: string | Resource, routeName?: string | Record<string, unknown> | null, params?: Record<string, unknown> | null) => string | null;
355
- declare function useResourceUrlGenerator(resourceId?: string | Resource | null): ResourceUrlGenerator;
361
+ declare function useResourceUrlGenerator(): (routeResourceId: string | Resource, routeName?: string, params?: Record<string, unknown> | null) => string | null;
362
+ declare function useResourceUrlGenerator(resourceId: string | Resource): (routeName?: string, params?: Record<string, unknown> | null) => string | null;
356
363
 
357
364
  interface QueryParams {
358
365
  page?: number;
package/dist/hooks.js CHANGED
@@ -7,7 +7,8 @@ import get from 'lodash-es/get';
7
7
  import isArray from 'lodash-es/isArray';
8
8
  import isObject from 'lodash-es/isObject';
9
9
  import isString from 'lodash-es/isString';
10
- import { useFieldsManager, usePanneauResources, useResource, useUrlGenerator } from '@panneau/core/contexts';
10
+ import { useFieldsManager, usePanneauResources, useResource, useUrlGenerator, useRoutes } from '@panneau/core/contexts';
11
+ import { isString as isString$1 } from 'lodash';
11
12
  import dayjs from 'dayjs';
12
13
  import { useIntl } from 'react-intl';
13
14
  import { match } from 'css-mediaquery';
@@ -1274,33 +1275,38 @@ function useResourceUrlGenerator(t0) {
1274
1275
  }
1275
1276
  const resource = t1;
1276
1277
  const route = useUrlGenerator();
1278
+ const routes = useRoutes();
1277
1279
  let t2;
1278
- if ($[4] !== resource || $[5] !== resourceId || $[6] !== resources || $[7] !== route) {
1280
+ if ($[4] !== resource || $[5] !== resources || $[6] !== route || $[7] !== routes) {
1279
1281
  t2 = (routeResourceId, t3, t4) => {
1280
1282
  const routeName = t3 === undefined ? null : t3;
1281
1283
  const params = t4 === undefined ? null : t4;
1282
- const finalRouteName = resourceId !== null ? routeResourceId : routeName;
1283
- const finalParams = resourceId !== null ? routeName : params;
1284
- const finalResource = getResource(resources, routeResourceId) || resource;
1284
+ const hasResourceId = isString$1(routeName);
1285
+ const finalRouteName = hasResourceId ? routeName : routeResourceId;
1286
+ const finalParams = hasResourceId ? params : routeName;
1287
+ const finalResource = hasResourceId ? getResource(resources, routeResourceId) : resource;
1285
1288
  const {
1286
1289
  id: t5
1287
1290
  } = finalResource || {};
1288
1291
  const id = t5 === undefined ? null : t5;
1289
- const finalRoute = id !== null ? route(`resources.${finalRouteName}`, {
1292
+ const specificRouteName = `resources.${id}.${finalRouteName}`;
1293
+ const hasSpecificRoute = typeof routes[specificRouteName] !== "undefined";
1294
+ const finalRoute = id !== null ? route(hasSpecificRoute ? specificRouteName : `resources.${finalRouteName}`, hasSpecificRoute ? finalParams : {
1290
1295
  ...finalParams,
1291
1296
  resource: id
1292
1297
  }) : null;
1293
1298
  return finalRoute;
1294
1299
  };
1295
1300
  $[4] = resource;
1296
- $[5] = resourceId;
1297
- $[6] = resources;
1298
- $[7] = route;
1301
+ $[5] = resources;
1302
+ $[6] = route;
1303
+ $[7] = routes;
1299
1304
  $[8] = t2;
1300
1305
  } else {
1301
1306
  t2 = $[8];
1302
1307
  }
1303
- return t2;
1308
+ const generateUrl = t2;
1309
+ return generateUrl;
1304
1310
  }
1305
1311
 
1306
1312
  function useQuery(t0, t1) {
package/dist/index.d.ts CHANGED
@@ -430,7 +430,7 @@ interface Resource {
430
430
  intl?: ResourceIntl;
431
431
  fields?: Field[];
432
432
  index?: ResourceIndex;
433
- forms?: Record<string, unknown>;
433
+ forms?: Record<string, Form>;
434
434
  shows_in_navbar?: boolean;
435
435
  settings?: Record<string, unknown>;
436
436
  }
package/dist/utils.d.ts CHANGED
@@ -75,6 +75,13 @@ interface Field {
75
75
  component?: string | ElementType;
76
76
  label?: ReactNode;
77
77
  }
78
+ /**
79
+ * Form definition
80
+ */
81
+ interface Form {
82
+ title: ReactNode;
83
+ fields?: Field[];
84
+ }
78
85
 
79
86
  /**
80
87
  * Resource Types
@@ -137,7 +144,7 @@ interface Resource {
137
144
  intl?: ResourceIntl;
138
145
  fields?: Field[];
139
146
  index?: ResourceIndex;
140
- forms?: Record<string, unknown>;
147
+ forms?: Record<string, Form>;
141
148
  shows_in_navbar?: boolean;
142
149
  settings?: Record<string, unknown>;
143
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/core",
3
- "version": "4.0.66",
3
+ "version": "4.0.73",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "javascript"
@@ -61,7 +61,7 @@
61
61
  "@babel/runtime": "^7.28.6",
62
62
  "@folklore/fetch": "^0.1.21",
63
63
  "@folklore/forms": "~0.0.30",
64
- "@folklore/routes": "^0.2.44",
64
+ "@folklore/routes": "^0.4.11",
65
65
  "@folklore/services": "^0.1.44",
66
66
  "@folklore/tracking": "~0.0.34",
67
67
  "@fortawesome/fontawesome-svg-core": "^6.5.1",
@@ -96,5 +96,5 @@
96
96
  "publishConfig": {
97
97
  "access": "public"
98
98
  },
99
- "gitHead": "9f89301a517c628efb03ed6f27632c66a03dd146"
99
+ "gitHead": "59fe06241775f60d387d99b22c16bb474964e6d0"
100
100
  }