muffin-admin 3.12.2 → 3.12.3
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/MuffinAdmin.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +21 -0
- package/package.json +1 -1
- package/src/MuffinAdmin.tsx +2 -2
- package/src/utils.tsx +21 -0
package/dist/utils.d.ts
CHANGED
|
@@ -23,3 +23,4 @@ export declare function makeRequest(url: string, params?: APIParams): Promise<{
|
|
|
23
23
|
}>;
|
|
24
24
|
export declare function findIcon(icon?: string): any;
|
|
25
25
|
export declare function buildIcon(icon?: string): import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
export declare function deepMerge(target: any, ...sources: any[]): any;
|
package/dist/utils.js
CHANGED
|
@@ -55,3 +55,24 @@ export function buildIcon(icon) {
|
|
|
55
55
|
if (Icon)
|
|
56
56
|
return _jsx(Icon, {});
|
|
57
57
|
}
|
|
58
|
+
function isObject(item) {
|
|
59
|
+
return item && typeof item === "object" && !Array.isArray(item);
|
|
60
|
+
}
|
|
61
|
+
export function deepMerge(target, ...sources) {
|
|
62
|
+
if (!sources.length)
|
|
63
|
+
return target;
|
|
64
|
+
const source = sources.shift();
|
|
65
|
+
if (isObject(target) && isObject(source)) {
|
|
66
|
+
for (const key in source) {
|
|
67
|
+
if (isObject(source[key])) {
|
|
68
|
+
if (!target[key])
|
|
69
|
+
Object.assign(target, { [key]: {} });
|
|
70
|
+
deepMerge(target[key], source[key]);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
Object.assign(target, { [key]: source[key] });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return deepMerge(target, ...sources);
|
|
78
|
+
}
|
package/package.json
CHANGED
package/src/MuffinAdmin.tsx
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
import { ConfirmationProvider } from "./common"
|
|
18
18
|
import { useMuffinAdminOpts } from "./hooks"
|
|
19
19
|
import { buildProvider, muffinTranslations } from "./i18n"
|
|
20
|
-
import { buildAdmin, findBuilder, findIcon, setupAdmin } from "./utils"
|
|
20
|
+
import { buildAdmin, deepMerge, findBuilder, findIcon, setupAdmin } from "./utils"
|
|
21
21
|
|
|
22
22
|
export function MuffinAdmin(props: AdminProps) {
|
|
23
23
|
const opts = useMuffinAdminOpts()
|
|
@@ -29,7 +29,7 @@ export function MuffinAdmin(props: AdminProps) {
|
|
|
29
29
|
? Object.fromEntries(
|
|
30
30
|
Object.entries(muffinTranslations).map(([locale, messages]) => [
|
|
31
31
|
locale,
|
|
32
|
-
{
|
|
32
|
+
deepMerge({}, messages, backendLocales[locale], buildAdmin(["locale", locale]) || {}),
|
|
33
33
|
])
|
|
34
34
|
)
|
|
35
35
|
: muffinTranslations
|
package/src/utils.tsx
CHANGED
|
@@ -64,3 +64,24 @@ export function buildIcon(icon?: string) {
|
|
|
64
64
|
const Icon = findIcon(icon)
|
|
65
65
|
if (Icon) return <Icon />
|
|
66
66
|
}
|
|
67
|
+
|
|
68
|
+
function isObject(item: any) {
|
|
69
|
+
return item && typeof item === "object" && !Array.isArray(item)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function deepMerge(target: any, ...sources: any[]): any {
|
|
73
|
+
if (!sources.length) return target
|
|
74
|
+
const source = sources.shift()
|
|
75
|
+
|
|
76
|
+
if (isObject(target) && isObject(source)) {
|
|
77
|
+
for (const key in source) {
|
|
78
|
+
if (isObject(source[key])) {
|
|
79
|
+
if (!target[key]) Object.assign(target, { [key]: {} })
|
|
80
|
+
deepMerge(target[key], source[key])
|
|
81
|
+
} else {
|
|
82
|
+
Object.assign(target, { [key]: source[key] })
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return deepMerge(target, ...sources)
|
|
87
|
+
}
|