listpage-next 0.0.14 → 0.0.30

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.
@@ -1,9 +1,10 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useMemo, useRef } from "react";
3
3
  import { Button, Form, Space } from "antd";
4
+ import { ReloadOutlined, SearchOutlined } from "@ant-design/icons";
4
5
  import { FilterGridLayout } from "../FilterGridLayout/index.js";
5
- import { getComponent } from "../../utils/getComponent.js";
6
6
  import { FilterItem } from "../FilterItem/index.js";
7
+ import { getComponent } from "../../utils/getComponent.js";
7
8
  const FilterForm = ({ options, initialValues, onSubmit, onReset })=>{
8
9
  const formRef = useRef(null);
9
10
  const items = useMemo(()=>(options ?? []).map(({ colSpan, component, label, ...props })=>{
@@ -41,11 +42,13 @@ const FilterForm = ({ options, initialValues, onSubmit, onReset })=>{
41
42
  onClick: handleSubmit,
42
43
  type: "primary",
43
44
  htmlType: "submit",
44
- children: "提交"
45
+ icon: /*#__PURE__*/ jsx(SearchOutlined, {}),
46
+ children: "搜索"
45
47
  }),
46
48
  /*#__PURE__*/ jsx(Button, {
47
49
  onClick: handleReset,
48
50
  htmlType: "reset",
51
+ icon: /*#__PURE__*/ jsx(ReloadOutlined, {}),
49
52
  children: "重置"
50
53
  })
51
54
  ]
@@ -20,6 +20,7 @@ const FilterItem = (props)=>{
20
20
  const valuePropName = formItemProps.valuePropName || 'value';
21
21
  const triggerPropsName = formItemProps.trigger || 'onChange';
22
22
  const onChange = (v)=>{
23
+ if (v.target instanceof HTMLInputElement) v = v.target.value;
23
24
  form.setFieldValue(formItemProps.name, v);
24
25
  };
25
26
  const onFocus = ()=>{
@@ -0,0 +1,2 @@
1
+ import { MenuItem } from '../types';
2
+ export declare function useActiveMenuKey(items: MenuItem[]): [string | null, (key: string) => void];
@@ -0,0 +1,63 @@
1
+ import { useCallback, useMemo } from "react";
2
+ import { useLocation, useNavigate } from "react-router-dom";
3
+ function useActiveMenuKey(items) {
4
+ const location = useLocation();
5
+ const navigate = useNavigate();
6
+ const setActiveKey = useCallback((key)=>{
7
+ function findKeyPath(items, paths = []) {
8
+ for (const item of items){
9
+ if (item.key === key) return [
10
+ ...paths,
11
+ item.path || item.key
12
+ ];
13
+ if (item.children) {
14
+ const subPaths = findKeyPath(item.children, []);
15
+ if (subPaths.length) return [
16
+ ...paths,
17
+ item.path || item.key,
18
+ ...subPaths
19
+ ];
20
+ }
21
+ }
22
+ return [];
23
+ }
24
+ const paths = findKeyPath(items, []);
25
+ const urlPath = paths.map((p)=>getPaths(p)).flat().join('/');
26
+ navigate(urlPath);
27
+ }, [
28
+ items,
29
+ navigate
30
+ ]);
31
+ const activeKey = useMemo(()=>{
32
+ const paths = getPaths(location.pathname);
33
+ return matchRoutes(items, paths);
34
+ }, [
35
+ location.pathname,
36
+ items
37
+ ]);
38
+ return [
39
+ activeKey,
40
+ setActiveKey
41
+ ];
42
+ }
43
+ const matchRoutes = (routes, paths)=>{
44
+ for (const route of routes){
45
+ const routePaths = getPaths(route.path || route.key);
46
+ const isMatch = isPathMatch(paths, routePaths);
47
+ if (isMatch) {
48
+ if (route.children) return matchRoutes(route.children, paths.slice(routePaths.length));
49
+ return route.key;
50
+ }
51
+ }
52
+ return null;
53
+ };
54
+ const isPathMatch = (urlPaths, routePaths)=>{
55
+ for(let i = 0; i < routePaths.length; i++){
56
+ const matchAny = '*' === routePaths[i];
57
+ const matchUrl = routePaths[i] === urlPaths[i];
58
+ if (!matchAny && !matchUrl) return false;
59
+ }
60
+ return true;
61
+ };
62
+ const getPaths = (path = '')=>path.split('/').filter(Boolean);
63
+ export { useActiveMenuKey };
@@ -0,0 +1,2 @@
1
+ import { MenuProps } from './types';
2
+ export declare const Menu: (props: MenuProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,33 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useMemo } from "react";
3
+ import { Menu } from "antd";
4
+ import { useActiveMenuKey } from "./hooks/useMenuNavigation.js";
5
+ const Menu_Menu = (props)=>{
6
+ const { menus, theme, style } = props;
7
+ const [activeKey, setActiveKey] = useActiveMenuKey(menus);
8
+ const menuItems = useMemo(()=>menus.map((item)=>({
9
+ key: item.key,
10
+ label: item.label,
11
+ icon: item.icon,
12
+ children: item.children?.map((child)=>({
13
+ key: child.key,
14
+ label: child.label,
15
+ icon: child.icon
16
+ }))
17
+ })), [
18
+ menus
19
+ ]);
20
+ return /*#__PURE__*/ jsx(Menu, {
21
+ mode: "vertical",
22
+ theme: theme,
23
+ style: style,
24
+ items: menuItems,
25
+ selectedKeys: activeKey ? [
26
+ activeKey
27
+ ] : [],
28
+ onSelect: (info)=>{
29
+ setActiveKey(info.key);
30
+ }
31
+ });
32
+ };
33
+ export { Menu_Menu as Menu };
@@ -0,0 +1,14 @@
1
+ import { CSSProperties } from "react";
2
+ export interface MenuItem {
3
+ key: string;
4
+ label: React.ReactNode;
5
+ icon?: React.ReactNode;
6
+ children?: MenuItem[];
7
+ disabled?: boolean;
8
+ path?: string;
9
+ }
10
+ export interface MenuProps {
11
+ menus: MenuItem[];
12
+ theme?: 'light' | 'dark';
13
+ style?: CSSProperties;
14
+ }
File without changes
@@ -1,12 +1,12 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { DatePicker, Select } from "antd";
2
+ import { DatePicker, Input, Select } from "antd";
3
3
  import { FilterForm } from "../index.js";
4
4
  const Demo1 = ()=>{
5
5
  const options = [
6
6
  {
7
7
  name: 'title',
8
8
  label: '标题',
9
- component: 'input'
9
+ component: /*#__PURE__*/ jsx(Input, {})
10
10
  },
11
11
  {
12
12
  name: 'type',
@@ -0,0 +1 @@
1
+ export declare const Demo4: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,43 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { BrowserRouter } from "react-router-dom";
3
+ import { Menu } from "../components/Menu/index.js";
4
+ const Demo4 = ()=>{
5
+ const menuItems = [
6
+ {
7
+ key: '1',
8
+ label: '首页',
9
+ path: 'home'
10
+ },
11
+ {
12
+ key: '2',
13
+ label: '产品',
14
+ path: 'products',
15
+ children: [
16
+ {
17
+ key: '2-1',
18
+ label: '产品列表',
19
+ path: 'list'
20
+ },
21
+ {
22
+ key: '2-2',
23
+ label: '产品详情',
24
+ path: 'detail'
25
+ }
26
+ ]
27
+ },
28
+ {
29
+ key: '3',
30
+ label: '关于我们',
31
+ path: 'about'
32
+ }
33
+ ];
34
+ return /*#__PURE__*/ jsx(BrowserRouter, {
35
+ children: /*#__PURE__*/ jsx(Menu, {
36
+ menus: menuItems,
37
+ style: {
38
+ width: 200
39
+ }
40
+ })
41
+ });
42
+ };
43
+ export { Demo4 };
@@ -1,6 +1,7 @@
1
1
  function setupBaseUrl(HttpClient) {
2
2
  HttpClient.prototype.getBaseURL = function() {
3
- const { server } = this.options;
3
+ const { server, config } = this.options;
4
+ if (config?.baseURL) return config.baseURL;
4
5
  return `${server?.protocol}//${server?.host}:${server?.port}${server?.publicPath}`;
5
6
  };
6
7
  }
@@ -1,5 +1,6 @@
1
1
  function setupHeaders(HttpClient) {
2
2
  HttpClient.prototype.getHeaders = function() {
3
+ if (this.options.config?.headers) return this.options.config.headers;
3
4
  return {
4
5
  'Content-Type': 'application/json'
5
6
  };
package/dist/index.d.ts CHANGED
@@ -2,4 +2,5 @@ import '@ant-design/v5-patch-for-react-19';
2
2
  export * from './components/FilterGroup';
3
3
  export * from './components/Page';
4
4
  export * from './components/InfiniteList';
5
+ export * from './components/Menu';
5
6
  export * from './http-client';
package/dist/index.js CHANGED
@@ -2,4 +2,5 @@ import "@ant-design/v5-patch-for-react-19";
2
2
  export * from "./components/FilterGroup/index.js";
3
3
  export * from "./components/Page/index.js";
4
4
  export * from "./components/InfiniteList/index.js";
5
+ export * from "./components/Menu/index.js";
5
6
  export * from "./http-client/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listpage-next",
3
- "version": "0.0.14",
3
+ "version": "0.0.30",
4
4
  "description": "A React component library for creating filter forms with Ant Design",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -45,11 +45,13 @@
45
45
  "storybook": "^8.6.14",
46
46
  "storybook-addon-rslib": "^1.0.3",
47
47
  "storybook-react-rsbuild": "^1.0.3",
48
- "typescript": "^5.9.2"
48
+ "typescript": "^5.9.2",
49
+ "react-router-dom": ">=6.0.0"
49
50
  },
50
51
  "peerDependencies": {
51
52
  "react": ">=16.9.0",
52
- "react-dom": ">=16.9.0"
53
+ "react-dom": ">=16.9.0",
54
+ "react-router-dom": ">=6.0.0"
53
55
  },
54
56
  "dependencies": {
55
57
  "ahooks": "^3.9.5",
@@ -64,4 +66,4 @@
64
66
  "mobx-react-lite": "~4.1.1",
65
67
  "rc-virtual-list": "~3.19.2"
66
68
  }
67
- }
69
+ }