@zat-design/sisyphus-react 4.6.5-beta.5 → 4.6.5-beta.6
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.
|
@@ -184,13 +184,13 @@ const InputNumber = (props) => {
|
|
|
184
184
|
onBlur == null ? void 0 : onBlur(value, (_b = e == null ? void 0 : e.target) == null ? void 0 : _b.value);
|
|
185
185
|
return false;
|
|
186
186
|
}
|
|
187
|
+
value = parser(String(value), props.precision ?? (valueProps == null ? void 0 : valueProps.precision));
|
|
187
188
|
if (_max !== void 0 && value > _max) {
|
|
188
189
|
value = _max;
|
|
189
190
|
}
|
|
190
191
|
if (_min !== void 0 && value < _min) {
|
|
191
192
|
value = _min;
|
|
192
193
|
}
|
|
193
|
-
value = parser(String(value), props.precision ?? (valueProps == null ? void 0 : valueProps.precision));
|
|
194
194
|
(_c = rest == null ? void 0 : rest.onChange) == null ? void 0 : _c.call(rest, value);
|
|
195
195
|
const limit = { min: Number(_min), max: Number(_max) };
|
|
196
196
|
switch (valueType || viewType) {
|
|
@@ -43,8 +43,11 @@ const OpenMenu = (props) => {
|
|
|
43
43
|
return [];
|
|
44
44
|
}
|
|
45
45
|
const menuDeep = (data) => {
|
|
46
|
-
data.
|
|
47
|
-
|
|
46
|
+
const visibleItems = data.filter(
|
|
47
|
+
(item) => !(item == null ? void 0 : item.hideInMenu) && !["TAB", "QUERY", "BUTTON"].includes(item == null ? void 0 : item.type)
|
|
48
|
+
);
|
|
49
|
+
visibleItems.forEach((item) => {
|
|
50
|
+
var _a, _b;
|
|
48
51
|
const isFirstMenu = ((_a = item.keyIdPath) == null ? void 0 : _a.length) === 1 || sideMenu && ((_b = item.keyIdPath) == null ? void 0 : _b.length) === 2;
|
|
49
52
|
item.label = /* @__PURE__ */ jsxs(
|
|
50
53
|
"div",
|
|
@@ -80,21 +83,16 @@ const OpenMenu = (props) => {
|
|
|
80
83
|
).forEach((_keyItem) => {
|
|
81
84
|
delete item[_keyItem];
|
|
82
85
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
delete item.children;
|
|
87
|
-
} else {
|
|
88
|
-
menuDeep(item.children);
|
|
89
|
-
}
|
|
86
|
+
const visibleChildren = Array.isArray(item == null ? void 0 : item.children) ? menuDeep(item.children) : [];
|
|
87
|
+
if (visibleChildren.length) {
|
|
88
|
+
item.children = visibleChildren;
|
|
90
89
|
} else {
|
|
91
90
|
delete item.children;
|
|
92
91
|
}
|
|
93
92
|
});
|
|
94
|
-
return
|
|
93
|
+
return visibleItems;
|
|
95
94
|
};
|
|
96
|
-
menuDeep(result);
|
|
97
|
-
return result;
|
|
95
|
+
return menuDeep(result);
|
|
98
96
|
}, [dataSource, selectedRootKey]);
|
|
99
97
|
useDeepCompareEffect(() => {
|
|
100
98
|
if (Array.isArray(selectKeyIdPath)) {
|
package/es/ProLayout/index.js
CHANGED
|
@@ -129,7 +129,7 @@ const ProLayout = (props) => {
|
|
|
129
129
|
const userData = transformMenus(dataSource, pathPrefix);
|
|
130
130
|
const menuData = Array.isArray(userData) ? userData : (userData == null ? void 0 : userData.menus) || [];
|
|
131
131
|
setState({ menus: menuData });
|
|
132
|
-
}, [dataSource]);
|
|
132
|
+
}, [dataSource, pathPrefix]);
|
|
133
133
|
const menuDataSource = useMemo(() => {
|
|
134
134
|
if (Array.isArray(menus) && menus.length > 0) {
|
|
135
135
|
return { menus };
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import isPlainObject from "lodash/isPlainObject";
|
|
2
|
+
const addPathPrefix = (pathPrefix, route) => {
|
|
3
|
+
if (!route || !pathPrefix || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(route))
|
|
4
|
+
return route || "";
|
|
5
|
+
const normalizedPrefix = `/${pathPrefix.replace(/^\/+|\/+$/g, "")}`;
|
|
6
|
+
if (normalizedPrefix === "/")
|
|
7
|
+
return route;
|
|
8
|
+
const match = route.match(/^([^?#]*)(.*)$/);
|
|
9
|
+
const pathname = (match == null ? void 0 : match[1]) || "";
|
|
10
|
+
const suffix = (match == null ? void 0 : match[2]) || "";
|
|
11
|
+
const normalizedPathname = pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
12
|
+
const alreadyPrefixed = normalizedPathname === normalizedPrefix || normalizedPathname.startsWith(`${normalizedPrefix}/`);
|
|
13
|
+
return `${alreadyPrefixed ? normalizedPathname : `${normalizedPrefix}${normalizedPathname}`}${suffix}`;
|
|
14
|
+
};
|
|
2
15
|
const updateBestMatch = (pathName, itemUrl, itemRedirectUrl, keyIdPath, bestMatch) => {
|
|
3
16
|
const isSameOrNestedPath = (candidate) => {
|
|
4
17
|
if (!candidate)
|
|
@@ -49,12 +62,13 @@ const getIdsByPathName = (menus, activeMenu) => {
|
|
|
49
62
|
let result;
|
|
50
63
|
let bestMatch = null;
|
|
51
64
|
const menuDeep = (menuDeepItem) => {
|
|
52
|
-
var _a, _b;
|
|
65
|
+
var _a, _b, _c;
|
|
53
66
|
for (let i = 0; i <= menuDeepItem.length - 1; i++) {
|
|
54
67
|
const item = menuDeepItem[i];
|
|
55
68
|
const itemUrl = ((_a = item == null ? void 0 : item.url) == null ? void 0 : _a.split("?")[0]) || "";
|
|
56
69
|
const itemRedirectUrl = ((_b = item == null ? void 0 : item.redirectUrl) == null ? void 0 : _b.split("?")[0]) || "";
|
|
57
|
-
|
|
70
|
+
const itemRouter = ((_c = item == null ? void 0 : item.router) == null ? void 0 : _c.split("?")[0]) || "";
|
|
71
|
+
if ((item == null ? void 0 : item.url) === _pathName || item.redirectUrl === _pathName || item.router === _pathName) {
|
|
58
72
|
result = item.keyIdPath;
|
|
59
73
|
return;
|
|
60
74
|
}
|
|
@@ -67,6 +81,7 @@ const getIdsByPathName = (menus, activeMenu) => {
|
|
|
67
81
|
continue;
|
|
68
82
|
}
|
|
69
83
|
bestMatch = updateBestMatch(_pathName, itemUrl, itemRedirectUrl, item.keyIdPath, bestMatch);
|
|
84
|
+
bestMatch = updateBestMatch(_pathName, itemRouter, "", item.keyIdPath, bestMatch);
|
|
70
85
|
}
|
|
71
86
|
};
|
|
72
87
|
menuDeep(menus);
|
|
@@ -93,7 +108,13 @@ const resolveMenuKeyIdPath = ({
|
|
|
93
108
|
return selectedPath ? getIdsByPathName(menus, selectedPath) : [];
|
|
94
109
|
};
|
|
95
110
|
const transformMenu = (menuData, pathPrefix) => {
|
|
96
|
-
const
|
|
111
|
+
const cloneMenuTree = (items) => items.map((item) => ({
|
|
112
|
+
...item,
|
|
113
|
+
keyUrlPath: Array.isArray(item.keyUrlPath) ? [...item.keyUrlPath] : item.keyUrlPath,
|
|
114
|
+
keyIdPath: Array.isArray(item.keyIdPath) ? [...item.keyIdPath] : item.keyIdPath,
|
|
115
|
+
children: Array.isArray(item.children) ? cloneMenuTree(item.children) : item.children
|
|
116
|
+
}));
|
|
117
|
+
const data = cloneMenuTree(menuData);
|
|
97
118
|
const menuDeep = (menuDeepItem) => {
|
|
98
119
|
var _a, _b, _c;
|
|
99
120
|
if (!Array.isArray(menuDeepItem) || !menuDeepItem.length) {
|
|
@@ -101,18 +122,26 @@ const transformMenu = (menuData, pathPrefix) => {
|
|
|
101
122
|
}
|
|
102
123
|
for (let i = menuDeepItem.length - 1; i >= 0; i -= 1) {
|
|
103
124
|
const item = menuDeepItem[i];
|
|
104
|
-
item.code = item.code
|
|
105
|
-
item.url =
|
|
106
|
-
item.redirectUrl = (
|
|
125
|
+
item.code = item.code ?? item.id;
|
|
126
|
+
item.url = addPathPrefix(pathPrefix, item.url);
|
|
127
|
+
item.redirectUrl = addPathPrefix(pathPrefix, item.redirectUrl);
|
|
128
|
+
if (item.router)
|
|
129
|
+
item.router = addPathPrefix(pathPrefix, item.router);
|
|
130
|
+
const itemRoute = item.redirectUrl || item.url || item.router;
|
|
107
131
|
if ((_a = item == null ? void 0 : item.keyUrlPath) == null ? void 0 : _a.length) {
|
|
108
|
-
|
|
109
|
-
|
|
132
|
+
if (itemRoute)
|
|
133
|
+
item.keyUrlPath.push(itemRoute);
|
|
134
|
+
item.keyUrlPath = item.keyUrlPath.filter(
|
|
135
|
+
(route, index, routes) => routes.indexOf(route) === index
|
|
136
|
+
);
|
|
110
137
|
} else {
|
|
111
|
-
item.keyUrlPath = [
|
|
138
|
+
item.keyUrlPath = itemRoute ? [itemRoute] : [];
|
|
112
139
|
}
|
|
113
140
|
if ((_b = item == null ? void 0 : item.keyIdPath) == null ? void 0 : _b.length) {
|
|
114
141
|
item.keyIdPath.push(item.id);
|
|
115
|
-
item.keyIdPath =
|
|
142
|
+
item.keyIdPath = item.keyIdPath.filter(
|
|
143
|
+
(id, index, ids) => ids.indexOf(id) === index
|
|
144
|
+
);
|
|
116
145
|
} else {
|
|
117
146
|
item.keyIdPath = [item.id];
|
|
118
147
|
}
|
|
@@ -135,8 +164,10 @@ const transformMenus = (data, pathPrefix) => {
|
|
|
135
164
|
if (!Array.isArray(data == null ? void 0 : data.menus)) {
|
|
136
165
|
return [];
|
|
137
166
|
}
|
|
138
|
-
|
|
139
|
-
|
|
167
|
+
return {
|
|
168
|
+
...data,
|
|
169
|
+
menus: transformMenu(data.menus, pathPrefix)
|
|
170
|
+
};
|
|
140
171
|
}
|
|
141
172
|
if (Array.isArray(data)) {
|
|
142
173
|
return transformMenu(data, pathPrefix);
|
|
@@ -166,7 +197,7 @@ const getPathNameKey = ({ menus, pathName }) => {
|
|
|
166
197
|
let result;
|
|
167
198
|
let bestMatch = null;
|
|
168
199
|
const menuDeep = (menuDeepItem) => {
|
|
169
|
-
var _a, _b;
|
|
200
|
+
var _a, _b, _c;
|
|
170
201
|
if (!Array.isArray(menuDeepItem) || !menuDeepItem.length) {
|
|
171
202
|
return;
|
|
172
203
|
}
|
|
@@ -177,7 +208,8 @@ const getPathNameKey = ({ menus, pathName }) => {
|
|
|
177
208
|
}
|
|
178
209
|
const itemUrl = ((_a = item == null ? void 0 : item.url) == null ? void 0 : _a.split("?")[0]) || "";
|
|
179
210
|
const itemRedirectUrl = ((_b = item == null ? void 0 : item.redirectUrl) == null ? void 0 : _b.split("?")[0]) || "";
|
|
180
|
-
|
|
211
|
+
const itemRouter = ((_c = item == null ? void 0 : item.router) == null ? void 0 : _c.split("?")[0]) || "";
|
|
212
|
+
if ((item == null ? void 0 : item.url) === pathName || (item == null ? void 0 : item.redirectUrl) === pathName || (item == null ? void 0 : item.router) === pathName) {
|
|
181
213
|
result = item.keyIdPath;
|
|
182
214
|
return;
|
|
183
215
|
}
|
|
@@ -190,6 +222,7 @@ const getPathNameKey = ({ menus, pathName }) => {
|
|
|
190
222
|
continue;
|
|
191
223
|
}
|
|
192
224
|
bestMatch = updateBestMatch(pathName, itemUrl, itemRedirectUrl, item.keyIdPath, bestMatch);
|
|
225
|
+
bestMatch = updateBestMatch(pathName, itemRouter, "", item.keyIdPath, bestMatch);
|
|
193
226
|
}
|
|
194
227
|
};
|
|
195
228
|
menuDeep(menus);
|