@tker-react/layout 0.2.2 → 0.2.4
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/LICENSE +21 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +44 -5
- package/package.json +34 -41
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joey
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.mts
CHANGED
|
@@ -85,6 +85,8 @@ interface LayoutContextValue {
|
|
|
85
85
|
setActivePath: (path: string, fullPath?: string) => void;
|
|
86
86
|
toggleCollapse: () => void;
|
|
87
87
|
setCollapsed: (collapsed: boolean) => void;
|
|
88
|
+
openKeys: Set<string>;
|
|
89
|
+
toggleMenuOpen: (path: string, forceOpen?: boolean) => void;
|
|
88
90
|
setExpandedWidth: (width: string) => void;
|
|
89
91
|
setCollapsedWidth: (width: string) => void;
|
|
90
92
|
setLayoutMode: (mode: "side-menu" | "top-menu") => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -85,6 +85,8 @@ interface LayoutContextValue {
|
|
|
85
85
|
setActivePath: (path: string, fullPath?: string) => void;
|
|
86
86
|
toggleCollapse: () => void;
|
|
87
87
|
setCollapsed: (collapsed: boolean) => void;
|
|
88
|
+
openKeys: Set<string>;
|
|
89
|
+
toggleMenuOpen: (path: string, forceOpen?: boolean) => void;
|
|
88
90
|
setExpandedWidth: (width: string) => void;
|
|
89
91
|
setCollapsedWidth: (width: string) => void;
|
|
90
92
|
setLayoutMode: (mode: "side-menu" | "top-menu") => void;
|
package/dist/index.mjs
CHANGED
|
@@ -99,10 +99,37 @@ function LayoutProvider({ children }) {
|
|
|
99
99
|
"side-menu"
|
|
100
100
|
);
|
|
101
101
|
const setMenus = useCallback((data) => setMenuData(data), []);
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
const [openKeys, setOpenKeys] = useState(/* @__PURE__ */ new Set());
|
|
103
|
+
const savedOpenKeysRef = useRef(/* @__PURE__ */ new Set());
|
|
104
|
+
const openKeysRef = useRef(openKeys);
|
|
105
|
+
openKeysRef.current = openKeys;
|
|
106
|
+
const collapsedRef = useRef(collapsed);
|
|
107
|
+
collapsedRef.current = collapsed;
|
|
108
|
+
const toggleMenuOpen = useCallback((path, forceOpen) => {
|
|
109
|
+
setOpenKeys((prev) => {
|
|
110
|
+
const next = new Set(prev);
|
|
111
|
+
if (forceOpen === true) {
|
|
112
|
+
next.add(path);
|
|
113
|
+
} else if (forceOpen === false) {
|
|
114
|
+
next.delete(path);
|
|
115
|
+
} else if (next.has(path)) {
|
|
116
|
+
next.delete(path);
|
|
117
|
+
} else {
|
|
118
|
+
next.add(path);
|
|
119
|
+
}
|
|
120
|
+
return next;
|
|
121
|
+
});
|
|
122
|
+
}, []);
|
|
123
|
+
const toggleCollapse = useCallback(() => {
|
|
124
|
+
const nextCollapsed = !collapsedRef.current;
|
|
125
|
+
if (nextCollapsed) {
|
|
126
|
+
savedOpenKeysRef.current = new Set(openKeysRef.current);
|
|
127
|
+
setOpenKeys(/* @__PURE__ */ new Set());
|
|
128
|
+
} else {
|
|
129
|
+
setOpenKeys(new Set(savedOpenKeysRef.current));
|
|
130
|
+
}
|
|
131
|
+
setCollapsedState(nextCollapsed);
|
|
132
|
+
}, []);
|
|
106
133
|
const pathParamsMap = useRef(/* @__PURE__ */ new Map());
|
|
107
134
|
const storePathParams = useCallback((path, fullPath) => {
|
|
108
135
|
if (fullPath && fullPath !== path) {
|
|
@@ -153,7 +180,17 @@ function LayoutProvider({ children }) {
|
|
|
153
180
|
setMenus,
|
|
154
181
|
setActivePath,
|
|
155
182
|
toggleCollapse,
|
|
156
|
-
setCollapsed:
|
|
183
|
+
setCollapsed: (val) => {
|
|
184
|
+
if (val) {
|
|
185
|
+
savedOpenKeysRef.current = new Set(openKeysRef.current);
|
|
186
|
+
setOpenKeys(/* @__PURE__ */ new Set());
|
|
187
|
+
} else {
|
|
188
|
+
setOpenKeys(new Set(savedOpenKeysRef.current));
|
|
189
|
+
}
|
|
190
|
+
setCollapsedState(val);
|
|
191
|
+
},
|
|
192
|
+
openKeys,
|
|
193
|
+
toggleMenuOpen,
|
|
157
194
|
setExpandedWidth,
|
|
158
195
|
setCollapsedWidth,
|
|
159
196
|
setLayoutMode,
|
|
@@ -183,6 +220,8 @@ function LayoutProvider({ children }) {
|
|
|
183
220
|
setMenus,
|
|
184
221
|
setActivePath,
|
|
185
222
|
toggleCollapse,
|
|
223
|
+
openKeys,
|
|
224
|
+
toggleMenuOpen,
|
|
186
225
|
isConcretePage,
|
|
187
226
|
getFullPath,
|
|
188
227
|
setNavigateAdapter,
|
package/package.json
CHANGED
|
@@ -1,43 +1,36 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
".": {
|
|
18
|
-
"types": "./dist/index.d.ts",
|
|
19
|
-
"development": "./src/index.ts",
|
|
20
|
-
"default": "./dist/index.mjs"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"publishConfig": {
|
|
24
|
-
"access": "public",
|
|
25
|
-
"exports": {
|
|
26
|
-
".": {
|
|
27
|
-
"types": "./dist/index.d.ts",
|
|
28
|
-
"default": "./dist/index.mjs"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"peerDependencies": {
|
|
33
|
-
"react": ">=18",
|
|
34
|
-
"react-dom": ">=18"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@tker-react/tsconfig": "workspace:*",
|
|
38
|
-
"@types/react": "catalog:",
|
|
39
|
-
"@types/react-dom": "catalog:",
|
|
40
|
-
"react": "catalog:",
|
|
41
|
-
"react-dom": "catalog:"
|
|
2
|
+
"name": "@tker-react/layout",
|
|
3
|
+
"version": "0.2.4",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"sideEffects": [
|
|
11
|
+
"**/*.css"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.mjs"
|
|
42
17
|
}
|
|
43
|
-
}
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"react": ">=18",
|
|
24
|
+
"react-dom": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/react": "^19.2.14",
|
|
28
|
+
"@types/react-dom": "^19.2.3",
|
|
29
|
+
"react": "^19.2.6",
|
|
30
|
+
"react-dom": "^19.2.6",
|
|
31
|
+
"@tker-react/tsconfig": "0.0.1"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "pnpm unbuild"
|
|
35
|
+
}
|
|
36
|
+
}
|