@refinedev/core 4.14.1 → 4.15.0

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": "@refinedev/core",
3
- "version": "4.14.1",
3
+ "version": "4.15.0",
4
4
  "description": "refine is a React-based framework for building internal tools, rapidly. It ships with Ant Design System, an enterprise-level UI toolkit.",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -51,129 +51,129 @@ export interface RefineProps {
51
51
  /**
52
52
  * `resources` is the predefined interaction points for a refine app. A resource represents an entity in an endpoint in the API.
53
53
  * While this is not a required property, it is used in resource detection and creation of routes for the app.
54
- * @type [`ResourceProps[]`](/docs/api-reference/core/components/refine-config/#resources)
54
+ * @type [`ResourceProps[]`](https://refine.dev/docs/api-reference/core/components/refine-config/#resources)
55
55
  */
56
56
  resources?: ResourceProps[];
57
57
  /**
58
58
  * **refine** needs some router functions to create resource pages, handle navigation, etc. This provider allows you to use the router library you want
59
- * @type [`IRouterProvider`](/docs/api-reference/core/providers/router-provider/)
59
+ * @type [`IRouterProvider`](https://refine.dev/docs/api-reference/core/providers/router-provider/)
60
60
  * @deprecated This property is deprecated and was the legacy way of routing. Please use `routerProvider` with new router bindings instead.
61
61
  */
62
62
  legacyRouterProvider?: IRouterProvider;
63
63
  /**
64
64
  * Router bindings for **refine**. A simple interface for **refine** to interact with your router in a flexible way.
65
- * @type [`RouterBindings`](/docs/api-reference/core/bindings/router/)
65
+ * @type [`RouterBindings`](https://refine.dev/docs/api-reference/core/bindings/router/)
66
66
  */
67
67
  routerProvider?: RouterBindings;
68
68
  /**
69
69
  * A `dataProvider` is the place where a refine app communicates with an API. Data providers also act as adapters for refine, making it possible for it to consume different API's and data services.
70
- * @type [`IDataContextProvider` | `IDataMultipleContextProvider`](/docs/api-reference/core/providers/data-provider/)
70
+ * @type [`IDataContextProvider` | `IDataMultipleContextProvider`](https://refine.dev/docs/api-reference/core/providers/data-provider/)
71
71
  */
72
72
  dataProvider: IDataContextProvider | IDataMultipleContextProvider;
73
73
  /**
74
74
  * `authProvider` handles authentication logic like login, logout flow and checking user credentials. It is an object with methods that refine uses when necessary.
75
- * @type [`AuthBindings`](/docs/api-reference/core/providers/auth-provider/)
75
+ * @type [`AuthBindings`](https://refine.dev/docs/api-reference/core/providers/auth-provider/)
76
76
  */
77
77
  authProvider?: AuthBindings;
78
78
  /**
79
79
  * `legacyAuthProvider` handles authentication logic like login, logout flow and checking user credentials. It is an object with methods that refine uses when necessary.
80
- * @type [`AuthProvider`](/docs/api-reference/core/providers/auth-provider/)
80
+ * @type [`AuthProvider`](https://refine.dev/docs/api-reference/core/providers/auth-provider/)
81
81
  * @deprecated `legacyAuthProvider` is deprecated with refine@4, use `authProvider` instead.
82
82
  */
83
83
  legacyAuthProvider?: LegacyAuthProvider;
84
84
  /**
85
85
  * **refine** lets you add Realtime support to your app via `liveProvider`. It can be used to update and show data in Realtime throughout your app.
86
- * @type [`ILiveContext`](/docs/api-reference/core/providers/live-provider/)
86
+ * @type [`ILiveContext`](https://refine.dev/docs/api-reference/core/providers/live-provider/)
87
87
  */
88
88
  liveProvider?: ILiveContext;
89
89
  /**
90
90
  * `notificationProvider` handles notification logics. It is an object with methods that refine uses when necessary.
91
- * @type [`NotificationProvider` | `(() => NotificationProvider)`](/docs/api-reference/core/providers/notification-provider/)
91
+ * @type [`NotificationProvider` | `(() => NotificationProvider)`](https://refine.dev/docs/api-reference/core/providers/notification-provider/)
92
92
  */
93
93
  notificationProvider?: NotificationProvider | (() => NotificationProvider);
94
94
  /**
95
95
  * `accessControlProvider` is the entry point for implementing access control for refine apps.
96
- * @type [`AccessControlProvider`](/docs/api-reference/core/providers/accessControl-provider/)
96
+ * @type [`AccessControlProvider`](https://refine.dev/docs/api-reference/core/providers/accessControl-provider/)
97
97
  */
98
98
  accessControlProvider?: AccessControlProvider;
99
99
  /**
100
100
  * **refine** allows you to track changes in your data and keep track of who made the changes.
101
- * @type [`AuditLogProvider`](/docs/api-reference/core/providers/audit-log-provider#overview)
101
+ * @type [`AuditLogProvider`](https://refine.dev/docs/api-reference/core/providers/audit-log-provider#overview)
102
102
  */
103
103
  auditLogProvider?: AuditLogProvider;
104
104
  /**
105
105
  * `i18nProvider` property lets you add i18n support to your app. Making you able to use any i18n framework.
106
- * @type [`i18nProvider`](/docs/api-reference/core/providers/i18n-provider/)
106
+ * @type [`i18nProvider`](https://refine.dev/docs/api-reference/core/providers/i18n-provider/)
107
107
  */
108
108
  i18nProvider?: I18nProvider;
109
109
  /**
110
110
  * A custom error component.
111
- * @type [`ReactNode`](/docs/api-reference/core/components/refine-config/#catchall)
111
+ * @type [`ReactNode`](https://refine.dev/docs/api-reference/core/components/refine-config/#catchall)
112
112
  * @deprecated Please use the `catchAll` element in your routes instead.
113
113
  */
114
114
  catchAll?: React.ReactNode;
115
115
  /**
116
116
  * Custom login component can be passed to the `LoginPage` property.
117
- * @type [`React.FC`](/docs/api-reference/core/components/refine-config/#loginpage)
117
+ * @type [`React.FC`](https://refine.dev/docs/api-reference/core/components/refine-config/#loginpage)
118
118
  * @deprecated Please use the `LoginPage` component in your routes instead.
119
119
  */
120
120
  LoginPage?: React.FC;
121
121
  /**
122
122
  * A custom dashboard page can be passed to the `DashboardPage` prop which is accessible on root route.
123
- * @type [`React.FC<DashboardPageProps>`](/docs/api-reference/core/components/refine-config/#dashboardpage)
123
+ * @type [`React.FC<DashboardPageProps>`](https://refine.dev/docs/api-reference/core/components/refine-config/#dashboardpage)
124
124
  * @deprecated Please use the `DashboardPage` component in your routes instead.
125
125
  */
126
126
  DashboardPage?: React.FC<DashboardPageProps>;
127
127
  /**
128
128
  * Custom ready page component can be set by passing to `ReadyPage` property.
129
- * @type [`React.FC`](/docs/api-reference/core/components/refine-config/#readypage)
129
+ * @type [`React.FC`](https://refine.dev/docs/api-reference/core/components/refine-config/#readypage)
130
130
  * @deprecated This component is only used with the legacy router and will be removed in the future.
131
131
  */
132
132
  ReadyPage?: React.FC;
133
133
  /**
134
134
  * Default layout can be customized by passing the `Layout` property.
135
- * @type [`React.FC<LayoutProps>`](/docs/api-reference/core/components/refine-config/#layout)
135
+ * @type [`React.FC<LayoutProps>`](https://refine.dev/docs/api-reference/core/components/refine-config/#layout)
136
136
  * @deprecated Please use the `Layout` component as a children instead of a prop.
137
137
  */
138
138
  Layout?: React.FC<LayoutProps>;
139
139
  /**
140
140
  * The default sidebar can be customized by using refine hooks and passing custom components to `Sider` property.
141
- * @type [`React.FC`](/docs/api-reference/core/components/refine-config/#sider)
141
+ * @type [`React.FC`](https://refine.dev/docs/api-reference/core/components/refine-config/#sider)
142
142
  * @deprecated Please pass the `Sider` component to your `Layout` component.
143
143
  */
144
144
  Sider?: React.FC;
145
145
  /**
146
146
  * The default app header can be customized by passing the `Header` property.
147
- * @type [`React.FC`](/docs/api-reference/core/components/refine-config/#header)
147
+ * @type [`React.FC`](https://refine.dev/docs/api-reference/core/components/refine-config/#header)
148
148
  * @deprecated Please pass the `Header` component to your `Layout` component.
149
149
  */
150
150
  Header?: React.FC;
151
151
  /**
152
152
  *The default app footer can be customized by passing the `Footer` property.
153
- * @type [`React.FC`](/docs/api-reference/core/components/refine-config/#footer)
153
+ * @type [`React.FC`](https://refine.dev/docs/api-reference/core/components/refine-config/#footer)
154
154
  * @deprecated Please pass the `Footer` component to your `Layout` component.
155
155
  */
156
156
  Footer?: React.FC;
157
157
  /**
158
158
  * The component wanted to be placed out of app layout structure can be set by passing to `OffLayoutArea` prop.
159
- * @type [`React.FC`](/docs/api-reference/core/components/refine-config/#offlayoutarea)
159
+ * @type [`React.FC`](https://refine.dev/docs/api-reference/core/components/refine-config/#offlayoutarea)
160
160
  * @deprecated Please use your `OffLayoutArea` component as a children instead of a prop.
161
161
  */
162
162
  OffLayoutArea?: React.FC;
163
163
  /**
164
164
  * TThe app title can be set by passing the `Title` property.
165
- * @type [`React.FC<TitleProps>`](/docs/api-reference/core/components/refine-config/#title)
165
+ * @type [`React.FC<TitleProps>`](https://refine.dev/docs/api-reference/core/components/refine-config/#title)
166
166
  * @deprecated Please pass the `Title` component to your `Layout` component.
167
167
  */
168
168
  Title?: React.FC<TitleProps>;
169
169
  /**
170
170
  * Callback to handle all live events.
171
- * @type [`(event: LiveEvent) => void`](/docs/api-reference/core/providers/live-provider/#onliveevent)
171
+ * @type [`(event: LiveEvent) => void`](https://refine.dev/docs/api-reference/core/providers/live-provider/#onliveevent)
172
172
  */
173
173
  onLiveEvent?: LiveModeProps["onLiveEvent"];
174
174
  /**
175
175
  * `options` is used to configure the app.
176
- * @type [`IRefineOptions`](/docs/api-reference/core/components/refine-config/#options-1)
176
+ * @type [`IRefineOptions`](https://refine.dev/docs/api-reference/core/components/refine-config/#options)
177
177
  * */
178
178
  options?: IRefineOptions;
179
179
  }
@@ -0,0 +1,48 @@
1
+ import { IResourceItem } from "@contexts/resource";
2
+ import capitalize from "lodash/capitalize";
3
+ import { userFriendlyResourceName } from "../userFriendlyResourceName";
4
+
5
+ /**
6
+ * Generates document title for the given resource and action.
7
+ */
8
+ export function generateDefaultDocumentTitle(
9
+ translate: {
10
+ (
11
+ key: string,
12
+ options?: any,
13
+ defaultMessage?: string | undefined,
14
+ ): string;
15
+ (key: string, defaultMessage?: string | undefined): string;
16
+ },
17
+ resource?: IResourceItem,
18
+ action?: string,
19
+ id?: string,
20
+ ) {
21
+ const actionPrefixMatcher = {
22
+ create: "Create new ",
23
+ edit: `#${id ?? ""} Edit `,
24
+ show: `#${id ?? ""} Show `,
25
+ list: "",
26
+ };
27
+
28
+ const resourceName = userFriendlyResourceName(
29
+ resource?.name,
30
+ action === "list" ? "plural" : "singular",
31
+ );
32
+
33
+ const defaultTitle = translate("documentTitle.default", "refine");
34
+ const suffix = translate("documentTitle.suffix", " | refine");
35
+ let autoGeneratedTitle = defaultTitle;
36
+
37
+ if (action && resource?.name) {
38
+ autoGeneratedTitle = translate(
39
+ `documentTitle.${resource.name}.${action}`,
40
+ { id },
41
+ `${
42
+ actionPrefixMatcher[action as keyof typeof actionPrefixMatcher]
43
+ }${capitalize(resourceName)}${suffix}`,
44
+ );
45
+ }
46
+
47
+ return autoGeneratedTitle;
48
+ }
@@ -24,3 +24,4 @@ export { composeRoute } from "./router/compose-route";
24
24
  export { useActiveAuthProvider } from "./useActiveAuthProvider";
25
25
  export { handlePaginationParams } from "./handlePaginationParams";
26
26
  export { useMediaQuery } from "./useMediaQuery";
27
+ export { generateDefaultDocumentTitle } from './generateDocumentTitle'
@@ -147,7 +147,7 @@ export const useCustom = <
147
147
  method,
148
148
  ...config,
149
149
  meta: {
150
- ...(combinedMeta || {}),
150
+ ...combinedMeta,
151
151
  queryContext: {
152
152
  queryKey,
153
153
  pageParam,
@@ -155,7 +155,7 @@ export const useCustom = <
155
155
  },
156
156
  },
157
157
  metaData: {
158
- ...(combinedMeta || {}),
158
+ ...combinedMeta,
159
159
  queryContext: {
160
160
  queryKey,
161
161
  pageParam,
@@ -171,7 +171,7 @@ export const useCustom = <
171
171
  typeof successNotification === "function"
172
172
  ? successNotification(data, {
173
173
  ...config,
174
- ...(combinedMeta || {}),
174
+ ...combinedMeta,
175
175
  })
176
176
  : successNotification;
177
177
 
@@ -185,7 +185,7 @@ export const useCustom = <
185
185
  typeof errorNotification === "function"
186
186
  ? errorNotification(err, {
187
187
  ...config,
188
- ...(combinedMeta || {}),
188
+ ...combinedMeta,
189
189
  })
190
190
  : errorNotification;
191
191
 
@@ -327,7 +327,7 @@ export const useDelete = <
327
327
  },
328
328
  context,
329
329
  ) => {
330
- const resourceSingular = pluralize.singular(resource ?? "");
330
+ const resourceSingular = pluralize.singular(resource);
331
331
 
332
332
  // Remove the queries from the cache:
333
333
  queryClient.removeQueries(context?.queryKey.detail(id));
@@ -357,7 +357,7 @@ export const useDelete = <
357
357
  channel: `resources/${resource}`,
358
358
  type: "deleted",
359
359
  payload: {
360
- ids: id ? [id] : [],
360
+ ids: [id],
361
361
  },
362
362
  date: new Date(),
363
363
  });
@@ -397,7 +397,7 @@ export const useDelete = <
397
397
  if (err.message !== "mutationCancelled") {
398
398
  checkError(err);
399
399
 
400
- const resourceSingular = pluralize.singular(resource ?? "");
400
+ const resourceSingular = pluralize.singular(resource);
401
401
 
402
402
  const notificationConfig =
403
403
  typeof errorNotification === "function"
@@ -247,7 +247,7 @@ export const useInfiniteList = <
247
247
  sort: prefferedSorters,
248
248
  sorters: prefferedSorters,
249
249
  meta: {
250
- ...(combinedMeta || {}),
250
+ ...combinedMeta,
251
251
  queryContext: {
252
252
  queryKey,
253
253
  pageParam,
@@ -255,7 +255,7 @@ export const useInfiniteList = <
255
255
  },
256
256
  },
257
257
  metaData: {
258
- ...(combinedMeta || {}),
258
+ ...combinedMeta,
259
259
  queryContext: {
260
260
  queryKey,
261
261
  pageParam,
@@ -240,7 +240,7 @@ export const useList = <
240
240
  sort: prefferedSorters,
241
241
  sorters: prefferedSorters,
242
242
  meta: {
243
- ...(combinedMeta || {}),
243
+ ...combinedMeta,
244
244
  queryContext: {
245
245
  queryKey,
246
246
  pageParam,
@@ -248,7 +248,7 @@ export const useList = <
248
248
  },
249
249
  },
250
250
  metaData: {
251
- ...(combinedMeta || {}),
251
+ ...combinedMeta,
252
252
  queryContext: {
253
253
  queryKey,
254
254
  pageParam,
@@ -129,7 +129,7 @@ export const useMany = <
129
129
  resource,
130
130
  types: ["*"],
131
131
  params: {
132
- ids: ids ?? [],
132
+ ids: ids,
133
133
  meta: combinedMeta,
134
134
  metaData: combinedMeta,
135
135
  subscriptionType: "useMany",
@@ -153,7 +153,7 @@ export const useMany = <
153
153
  resource,
154
154
  ids,
155
155
  meta: {
156
- ...(combinedMeta || {}),
156
+ ...combinedMeta,
157
157
  queryContext: {
158
158
  queryKey,
159
159
  pageParam,
@@ -161,7 +161,7 @@ export const useMany = <
161
161
  },
162
162
  },
163
163
  metaData: {
164
- ...(combinedMeta || {}),
164
+ ...combinedMeta,
165
165
  queryContext: {
166
166
  queryKey,
167
167
  pageParam,
@@ -176,7 +176,7 @@ export const useMany = <
176
176
  resource,
177
177
  id,
178
178
  meta: {
179
- ...(combinedMeta || {}),
179
+ ...combinedMeta,
180
180
  queryContext: {
181
181
  queryKey,
182
182
  pageParam,
@@ -184,7 +184,7 @@ export const useMany = <
184
184
  },
185
185
  },
186
186
  metaData: {
187
- ...(combinedMeta || {}),
187
+ ...combinedMeta,
188
188
  queryContext: {
189
189
  queryKey,
190
190
  pageParam,
@@ -157,7 +157,7 @@ export const useOne = <
157
157
  resource: resource!,
158
158
  id: id!,
159
159
  meta: {
160
- ...(combinedMeta || {}),
160
+ ...combinedMeta,
161
161
  queryContext: {
162
162
  queryKey,
163
163
  pageParam,
@@ -165,7 +165,7 @@ export const useOne = <
165
165
  },
166
166
  },
167
167
  metaData: {
168
- ...(combinedMeta || {}),
168
+ ...combinedMeta,
169
169
  queryContext: {
170
170
  queryKey,
171
171
  pageParam,
@@ -188,7 +188,7 @@ export const useOne = <
188
188
  data,
189
189
  {
190
190
  id,
191
- ...(combinedMeta || {}),
191
+ ...combinedMeta,
192
192
  },
193
193
  resource,
194
194
  )
@@ -206,7 +206,7 @@ export const useOne = <
206
206
  err,
207
207
  {
208
208
  id,
209
- ...(combinedMeta || {}),
209
+ ...combinedMeta,
210
210
  },
211
211
  resource,
212
212
  )
package/src/index.tsx CHANGED
@@ -116,5 +116,7 @@ export {
116
116
  useActiveAuthProvider,
117
117
  } from "./definitions/helpers";
118
118
  export { file2Base64 } from "./definitions/upload";
119
+ export { generateDefaultDocumentTitle } from "./definitions";
119
120
 
120
121
  export { ResourceContext } from "./contexts/resource/index";
122
+ export { TranslationContext } from "./contexts/translation/index";