listpage-next 0.0.169 → 0.0.171

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.
Files changed (91) hide show
  1. package/dist/components/PageLayout/components/PageContent/index.d.ts +5 -0
  2. package/dist/components/PageLayout/components/PageContent/index.js +15 -0
  3. package/dist/components/PageLayout/components/PageHeader/index.d.ts +5 -0
  4. package/dist/components/PageLayout/components/PageHeader/index.js +5 -0
  5. package/dist/components/PageLayout/components/PageLayout/index.d.ts +10 -0
  6. package/dist/components/PageLayout/components/PageLayout/index.js +44 -0
  7. package/dist/components/{Page/components/Loading → PageLayout/components/PageLoading}/index.js +16 -6
  8. package/dist/components/{Page/context/page.d.ts → PageLayout/components/PageProvider/index.d.ts} +4 -4
  9. package/dist/components/{Page/context/page.js → PageLayout/components/PageProvider/index.js} +6 -3
  10. package/dist/components/PageLayout/components/PageSider/index.d.ts +7 -0
  11. package/dist/components/PageLayout/components/PageSider/index.js +43 -0
  12. package/dist/components/PageLayout/index.d.ts +4 -0
  13. package/dist/components/PageLayout/index.js +4 -0
  14. package/dist/context/index.d.ts +1 -1
  15. package/dist/demos/demo2.js +2 -2
  16. package/dist/demos/demo5.js +1 -1
  17. package/dist/features/ChatClient/components/ChatContent/index.js +1 -1
  18. package/dist/features/ChatClient/components/HistoryConversation/index.d.ts +3 -9
  19. package/dist/features/ChatClient/components/HistoryConversation/index.js +20 -73
  20. package/dist/features/ChatClient/components/HistoryConversation/styles.d.ts +0 -5
  21. package/dist/features/ChatClient/components/HistoryConversation/styles.js +17 -45
  22. package/dist/features/ChatClient/ui/Bubble/BubbleList.d.ts +2 -0
  23. package/dist/features/ChatClient/ui/Bubble/BubbleList.js +22 -15
  24. package/dist/features/ChatClient/ui/ConversationList/index.d.ts +21 -0
  25. package/dist/features/ChatClient/ui/ConversationList/index.js +85 -0
  26. package/dist/features/ChatClient/ui/ConversationList/styles.d.ts +5 -0
  27. package/dist/features/ChatClient/ui/ConversationList/styles.js +30 -0
  28. package/dist/features/ChatClient/ui/index.d.ts +1 -0
  29. package/dist/features/ChatClient/ui/index.js +1 -0
  30. package/dist/features/ListPage/components/DataTable/index.d.ts +4 -0
  31. package/dist/{components/Page/components/ListPage/DataTable.js → features/ListPage/components/DataTable/index.js} +3 -3
  32. package/dist/features/ListPage/components/DataTable/renders/index.d.ts +7 -0
  33. package/dist/features/ListPage/components/DataTable/renders/index.js +13 -0
  34. package/dist/features/ListPage/components/DataTable/renders/link.d.ts +2 -0
  35. package/dist/features/ListPage/components/DataTable/renders/link.js +27 -0
  36. package/dist/features/ListPage/components/DataTable/renders/switch.d.ts +2 -0
  37. package/dist/features/ListPage/components/DataTable/renders/switch.js +10 -0
  38. package/dist/features/ListPage/components/DataTable/renders/tag.d.ts +2 -0
  39. package/dist/features/ListPage/components/DataTable/renders/tag.js +7 -0
  40. package/dist/features/ListPage/components/DataTable/renders/text.d.ts +2 -0
  41. package/dist/features/ListPage/components/DataTable/renders/text.js +10 -0
  42. package/dist/features/ListPage/components/DataTable/renders/time.d.ts +2 -0
  43. package/dist/features/ListPage/components/DataTable/renders/time.js +15 -0
  44. package/dist/features/ListPage/components/DataTable/types.d.ts +34 -0
  45. package/dist/features/ListPage/components/DataTable/types.js +0 -0
  46. package/dist/features/ListPage/components/DataTable/utils/render.d.ts +2 -0
  47. package/dist/features/ListPage/components/DataTable/utils/render.js +25 -0
  48. package/dist/features/ListPage/components/ListPageContainer/index.d.ts +17 -0
  49. package/dist/{components/Page/components/ListPage/v2.js → features/ListPage/components/ListPageContainer/index.js} +10 -24
  50. package/dist/features/ListPage/context/context.d.ts +4 -0
  51. package/dist/features/ListPage/context/context.js +22 -0
  52. package/dist/features/ListPage/context/index.d.ts +2 -0
  53. package/dist/features/ListPage/context/index.js +3 -0
  54. package/dist/features/ListPage/context/store.d.ts +37 -0
  55. package/dist/{components/Page/context/listpage.js → features/ListPage/context/store.js} +2 -42
  56. package/dist/features/ListPage/context/types.d.ts +12 -0
  57. package/dist/features/ListPage/context/types.js +0 -0
  58. package/dist/features/ListPage/hooks/useColumns.d.ts +3 -0
  59. package/dist/features/ListPage/hooks/useColumns.js +20 -0
  60. package/dist/{components/Page → features/ListPage}/hooks/useFloat.js +1 -1
  61. package/dist/features/ListPage/hooks/useHeader.d.ts +2 -0
  62. package/dist/{components/Page → features/ListPage}/hooks/useHeader.js +2 -2
  63. package/dist/{components/Page → features/ListPage}/hooks/usePagination.js +2 -2
  64. package/dist/{components/Page → features/ListPage}/hooks/useSelectionTools.js +1 -1
  65. package/dist/features/ListPage/index.d.ts +3 -0
  66. package/dist/features/ListPage/index.js +4 -0
  67. package/dist/{components/Page/components → features}/ListPage/styles.d.ts +3 -1
  68. package/dist/{components/Page/components → features}/ListPage/styles.js +15 -2
  69. package/dist/features/ListPage/types.d.ts +33 -0
  70. package/dist/features/ListPage/types.js +0 -0
  71. package/dist/features/ListPage/utils/index.d.ts +10 -0
  72. package/dist/features/ListPage/utils/index.js +23 -0
  73. package/dist/index.d.ts +2 -2
  74. package/dist/index.js +2 -2
  75. package/package.json +1 -2
  76. package/dist/components/Page/components/ListPage/DataTable.d.ts +0 -20
  77. package/dist/components/Page/components/ListPage/index.d.ts +0 -16
  78. package/dist/components/Page/components/ListPage/index.js +0 -51
  79. package/dist/components/Page/components/ListPage/v2.d.ts +0 -43
  80. package/dist/components/Page/components/PageContainer/index.d.ts +0 -10
  81. package/dist/components/Page/components/PageContainer/index.js +0 -82
  82. package/dist/components/Page/context/listpage.d.ts +0 -80
  83. package/dist/components/Page/hooks/useColumns.d.ts +0 -3
  84. package/dist/components/Page/hooks/useColumns.js +0 -10
  85. package/dist/components/Page/hooks/useHeader.d.ts +0 -7
  86. package/dist/components/Page/index.d.ts +0 -8
  87. package/dist/components/Page/index.js +0 -7
  88. /package/dist/components/{Page/components/Loading → PageLayout/components/PageLoading}/index.d.ts +0 -0
  89. /package/dist/{components/Page → features/ListPage}/hooks/useFloat.d.ts +0 -0
  90. /package/dist/{components/Page → features/ListPage}/hooks/usePagination.d.ts +0 -0
  91. /package/dist/{components/Page → features/ListPage}/hooks/useSelectionTools.d.ts +0 -0
@@ -0,0 +1,85 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { Avatar, Button, Dropdown, Typography } from "antd";
4
+ import { ListContainer, ListItemContainer, ListText } from "./styles.js";
5
+ import { MessageOutlined, MoreOutlined } from "@ant-design/icons";
6
+ import { InfiniteList } from "../../../../components/InfiniteList/index.js";
7
+ const ConversationList = (props)=>{
8
+ const { ref, rowKey, request, menus = [], defaultActiveKey, onSelectConversation, onDeleteConversation, onRenameConversation } = props;
9
+ const [activeKey, setActiveKey] = useState(defaultActiveKey);
10
+ return /*#__PURE__*/ jsx(ListContainer, {
11
+ children: /*#__PURE__*/ jsx(InfiniteList, {
12
+ pageSize: 10,
13
+ rowKey: rowKey,
14
+ ref: ref,
15
+ request: request,
16
+ renderItem: (item, index, actions)=>{
17
+ const key = item[rowKey];
18
+ const items = [
19
+ ...menus.map((menu)=>({
20
+ ...menu,
21
+ onClick: ()=>menu.onClick?.(item, index, actions)
22
+ })),
23
+ onRenameConversation && {
24
+ key: 'rename',
25
+ label: '重命名',
26
+ onClick: async ()=>{
27
+ const newItem = await onRenameConversation?.(item);
28
+ if (!newItem) return;
29
+ actions.updateItem(key, newItem);
30
+ }
31
+ },
32
+ onDeleteConversation && {
33
+ key: 'delete',
34
+ danger: true,
35
+ label: '删除',
36
+ onClick: async ()=>{
37
+ await onDeleteConversation?.(item);
38
+ setActiveKey('');
39
+ actions.deleteItem(key);
40
+ }
41
+ }
42
+ ].filter(Boolean);
43
+ return /*#__PURE__*/ jsxs(ListItemContainer, {
44
+ isHover: activeKey === key ? true : void 0,
45
+ onClick: ()=>{
46
+ if (activeKey === key) return;
47
+ setActiveKey?.(key);
48
+ onSelectConversation?.(item);
49
+ },
50
+ children: [
51
+ /*#__PURE__*/ jsx(Avatar, {
52
+ size: 20,
53
+ icon: item.icon || /*#__PURE__*/ jsx(MessageOutlined, {})
54
+ }),
55
+ /*#__PURE__*/ jsx(ListText, {
56
+ children: /*#__PURE__*/ jsx(Typography.Text, {
57
+ ellipsis: {
58
+ tooltip: {
59
+ title: item.title,
60
+ placement: 'right'
61
+ }
62
+ },
63
+ children: item.title
64
+ })
65
+ }),
66
+ /*#__PURE__*/ jsx("div", {
67
+ onClick: (e)=>e.stopPropagation(),
68
+ children: /*#__PURE__*/ jsx(Dropdown, {
69
+ menu: {
70
+ items
71
+ },
72
+ children: /*#__PURE__*/ jsx(Button, {
73
+ type: "text",
74
+ size: "small",
75
+ icon: /*#__PURE__*/ jsx(MoreOutlined, {})
76
+ })
77
+ })
78
+ })
79
+ ]
80
+ });
81
+ }
82
+ })
83
+ });
84
+ };
85
+ export { ConversationList };
@@ -0,0 +1,5 @@
1
+ export declare const ListContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
2
+ export declare const ListItemContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
3
+ isHover?: boolean;
4
+ }>> & string;
5
+ export declare const ListText: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
@@ -0,0 +1,30 @@
1
+ import styled_components from "styled-components";
2
+ const ListContainer = styled_components.div`
3
+ flex: 1;
4
+ overflow: hidden;
5
+ padding: 0 2px;
6
+ `;
7
+ const ListItemContainer = styled_components.div`
8
+ display: flex;
9
+ align-items: center;
10
+ padding: 8px 4px;
11
+ border-radius: 8px;
12
+ cursor: pointer;
13
+ gap: 4px;
14
+
15
+ background-color: ${(props)=>props.isHover ? '#0000000a' : 'transparent'};
16
+
17
+ &:hover {
18
+ background-color: #0000000a;
19
+ }
20
+ `;
21
+ const ListText = styled_components.div`
22
+ flex: 1;
23
+
24
+ overflow: hidden;
25
+ text-overflow: ellipsis;
26
+ white-space: nowrap;
27
+ word-break: break-all;
28
+ word-wrap: break-word;
29
+ `;
30
+ export { ListContainer, ListItemContainer, ListText };
@@ -2,3 +2,4 @@ export * from './Bubble';
2
2
  export * from './ChatSplitter';
3
3
  export * from './ChatDialog';
4
4
  export * from './EditorContent';
5
+ export * from './ConversationList';
@@ -2,3 +2,4 @@ export * from "./Bubble/index.js";
2
2
  export * from "./ChatSplitter/index.js";
3
3
  export * from "./ChatDialog/index.js";
4
4
  export * from "./EditorContent/index.js";
5
+ export * from "./ConversationList/index.js";
@@ -0,0 +1,4 @@
1
+ import { DataTableProps } from './types';
2
+ export declare const DataTable: (<FilterValue = any, RecordValue extends Record<string, any> = any>(props: DataTableProps<FilterValue, RecordValue>) => import("react/jsx-runtime").JSX.Element) & {
3
+ displayName: string;
4
+ };
@@ -1,13 +1,13 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Card, Table } from "antd";
3
3
  import { observer } from "mobx-react-lite";
4
- import { useListPageStore } from "../../context/listpage.js";
5
- import { TableContainer } from "../../../DataTable/index.js";
4
+ import { useListPageStore } from "../../context/index.js";
6
5
  import { usePagination } from "../../hooks/usePagination.js";
7
6
  import { useColumns } from "../../hooks/useColumns.js";
8
7
  import { useSelectionTools } from "../../hooks/useSelectionTools.js";
8
+ import { TableContainer } from "../../styles.js";
9
9
  const DataTable = observer((props)=>{
10
- const { title, extra, columns, rowTitleKey, rowSelectionType, tableProps } = props;
10
+ const { title, extra, columns = [], rowTitleKey, rowSelectionType, tableProps } = props;
11
11
  const store = useListPageStore();
12
12
  const paginationEle = usePagination(tableProps?.pagination);
13
13
  const newColumns = useColumns(columns);
@@ -0,0 +1,7 @@
1
+ export declare const renders: {
2
+ link: import("../types").ColumnRender<"link">;
3
+ text: import("../types").ColumnRender<"text">;
4
+ tag: import("../types").ColumnRender<"tag">;
5
+ switch: import("../types").ColumnRender<"switch">;
6
+ time: import("../types").ColumnRender<"time">;
7
+ };
@@ -0,0 +1,13 @@
1
+ import { linkRender } from "./link.js";
2
+ import { switchRender } from "./switch.js";
3
+ import { tagRender } from "./tag.js";
4
+ import { textRender } from "./text.js";
5
+ import { timeRender } from "./time.js";
6
+ const renders = {
7
+ link: linkRender,
8
+ text: textRender,
9
+ tag: tagRender,
10
+ switch: switchRender,
11
+ time: timeRender
12
+ };
13
+ export { renders };
@@ -0,0 +1,2 @@
1
+ import { ColumnRender } from '../types';
2
+ export declare const linkRender: ColumnRender<'link'>;
@@ -0,0 +1,27 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { styled } from "styled-components";
3
+ const LinkStyle = styled.a`
4
+ color: #1677ff;
5
+ &:hover {
6
+ color: #69b1ff;
7
+ }
8
+ outline: 0;
9
+ text-decoration: none;
10
+ transition: color 0.3s;
11
+ background-color: transparent;
12
+ cursor: pointer;
13
+ `;
14
+ const getPropName = (propName, record)=>{
15
+ if ('function' == typeof propName) return propName(record);
16
+ return record[propName];
17
+ };
18
+ const linkRender = (value, record, index, props)=>{
19
+ const title = getPropName(props?.titlePropName || 'title', record);
20
+ const href = getPropName(props?.hrefPropName || 'href', record);
21
+ return /*#__PURE__*/ jsx(LinkStyle, {
22
+ href: href,
23
+ target: props?.target,
24
+ children: title
25
+ });
26
+ };
27
+ export { linkRender };
@@ -0,0 +1,2 @@
1
+ import { ColumnRender } from '../types';
2
+ export declare const switchRender: ColumnRender<'switch'>;
@@ -0,0 +1,10 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { AsyncSwitch } from "../../../../../components/AsyncSwitch/index.js";
3
+ const switchRender = (value, record, index, props)=>/*#__PURE__*/ jsx(AsyncSwitch, {
4
+ defaultValue: value,
5
+ ...props,
6
+ syncChange: async (checked)=>{
7
+ await props?.syncChange?.(checked, record);
8
+ }
9
+ });
10
+ export { switchRender };
@@ -0,0 +1,2 @@
1
+ import { ColumnRender } from '../types';
2
+ export declare const tagRender: ColumnRender<'tag'>;
@@ -0,0 +1,7 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Tag } from "antd";
3
+ const tagRender = (value, record, index, props)=>/*#__PURE__*/ jsx(Tag, {
4
+ ...props,
5
+ children: value
6
+ });
7
+ export { tagRender };
@@ -0,0 +1,2 @@
1
+ import { ColumnRender } from '../types';
2
+ export declare const textRender: ColumnRender<'text'>;
@@ -0,0 +1,10 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Typography } from "antd";
3
+ const textRender = (value, record, index, props)=>/*#__PURE__*/ jsx(Typography.Text, {
4
+ ellipsis: {
5
+ tooltip: true
6
+ },
7
+ ...props,
8
+ children: value
9
+ });
10
+ export { textRender };
@@ -0,0 +1,2 @@
1
+ import { ColumnRender } from '../types';
2
+ export declare const timeRender: ColumnRender<'time'>;
@@ -0,0 +1,15 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import dayjs from "dayjs";
3
+ const timeRender = (value, record, index, props)=>{
4
+ try {
5
+ const time = value ? dayjs(value).format(props?.format) : '-';
6
+ return /*#__PURE__*/ jsx("span", {
7
+ children: time
8
+ });
9
+ } catch {
10
+ return /*#__PURE__*/ jsx("span", {
11
+ children: "-"
12
+ });
13
+ }
14
+ };
15
+ export { timeRender };
@@ -0,0 +1,34 @@
1
+ import { TableProps, TagProps, TypographyProps } from 'antd';
2
+ import { ColumnType } from 'antd/es/table';
3
+ import { HTMLAttributeAnchorTarget, ReactNode } from 'react';
4
+ import { ListPageStore } from '../../context';
5
+ export type ComponentType = 'text' | 'time' | 'tag' | 'link' | 'switch';
6
+ export type ComponentProps<RecordValue extends Record<string, any> = any> = {
7
+ text: TypographyProps['Text'];
8
+ time: {
9
+ format?: string;
10
+ };
11
+ tag: TagProps;
12
+ link: {
13
+ titlePropName?: string | ((record: RecordValue) => string);
14
+ hrefPropName?: string | ((record: RecordValue) => string);
15
+ target?: HTMLAttributeAnchorTarget;
16
+ };
17
+ switch: {
18
+ syncChange?: (value: boolean, record: RecordValue) => Promise<void>;
19
+ };
20
+ };
21
+ export type CustomColumnRender<RecordValue extends Record<string, any> = any, Context = any> = (value: RecordValue[keyof RecordValue], record: RecordValue, index: number, ctx: Context) => ReactNode;
22
+ export interface ListPageTableColumn<FilterValue = any, RecordValue extends Record<string, any> = any> extends ColumnType<RecordValue> {
23
+ component?: ComponentType | CustomColumnRender<RecordValue, ListPageStore<FilterValue, RecordValue>>;
24
+ props?: this['component'] extends ComponentType ? ComponentProps<RecordValue>[this['component']] : unknown;
25
+ }
26
+ export interface DataTableProps<FilterValue = any, RecordValue extends Record<string, any> = any> {
27
+ title?: ReactNode;
28
+ extra?: React.ReactNode | ((ctx: ListPageStore<FilterValue, RecordValue>) => React.ReactNode);
29
+ rowSelectionType?: 'checkbox' | 'radio';
30
+ rowTitleKey?: string;
31
+ columns?: ListPageTableColumn<FilterValue, RecordValue>[];
32
+ tableProps?: Omit<TableProps<RecordValue>, 'dataSource' | 'title' | 'columns'>;
33
+ }
34
+ export type ColumnRender<Type extends ComponentType, R extends Record<string, any> = any, K extends string = any> = (value: R[K], record: R, index: number, props: ComponentProps<R>[Type]) => ReactNode;
@@ -0,0 +1,2 @@
1
+ import { ComponentType } from '../types';
2
+ export declare function createColumnRender<RecordValue extends Record<string, any> = any, FilterValue = any>(component?: ComponentType, props?: any): ((value: any, record: RecordValue, index: number) => import("react").ReactNode) | undefined;
@@ -0,0 +1,25 @@
1
+ import { textRender } from "../renders/text.js";
2
+ import { timeRender } from "../renders/time.js";
3
+ import { tagRender } from "../renders/tag.js";
4
+ import { linkRender } from "../renders/link.js";
5
+ import { switchRender } from "../renders/switch.js";
6
+ function createColumnRender(component, props) {
7
+ if (component) {
8
+ if ('text' === component) return function(value, record, index) {
9
+ return textRender(value, record, index, props);
10
+ };
11
+ if ('time' === component) return function(value, record, index) {
12
+ return timeRender(value, record, index, props);
13
+ };
14
+ if ('tag' === component) return function(value, record, index) {
15
+ return tagRender(value, record, index, props);
16
+ };
17
+ if ('link' === component) return function(value, record, index) {
18
+ return linkRender(value, record, index, props);
19
+ };
20
+ if ('switch' === component) return function(value, record, index) {
21
+ return switchRender(value, record, index, props);
22
+ };
23
+ }
24
+ }
25
+ export { createColumnRender };
@@ -0,0 +1,17 @@
1
+ import { ListPageFilterProps, ListPageFloatProps, ListPageHeaderProps, ListPageRequest, ListPageToolbarProps, StateValue } from '../../types';
2
+ import { DataTableProps } from '../DataTable/types';
3
+ export interface ListPageProps<FilterValue = any, RecordValue extends Record<string, any> = any> {
4
+ styles?: {
5
+ page?: React.CSSProperties;
6
+ };
7
+ request: ListPageRequest<FilterValue, RecordValue>;
8
+ storageKey?: string;
9
+ initialValues?: StateValue<FilterValue>;
10
+ state?: StateValue<FilterValue>;
11
+ header?: ListPageHeaderProps;
12
+ floats?: ListPageFloatProps[];
13
+ filter?: ListPageFilterProps<FilterValue>;
14
+ toolbar?: ListPageToolbarProps<FilterValue, RecordValue>;
15
+ table: DataTableProps<FilterValue, RecordValue>;
16
+ }
17
+ export declare const ListPage: (props: ListPageProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,31 +1,17 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useImperativeHandle } from "react";
3
2
  import { observer } from "mobx-react-lite";
4
- import { useMount, useUpdateEffect } from "ahooks";
5
- import { toJS } from "mobx";
6
- import { ListPageProvider, useListPageStore } from "../../context/listpage.js";
7
- import { FilterSection, ListPageContainer, ToolbarSection } from "./styles.js";
8
- import { FilterForm } from "../../../FilterGroup/index.js";
3
+ import { FilterForm } from "../../../../components/FilterGroup/index.js";
4
+ import { ListPageProvider, useListPageStore } from "../../context/index.js";
9
5
  import { useFloat } from "../../hooks/useFloat.js";
10
- import { DataTable } from "./DataTable.js";
11
6
  import { useHeader } from "../../hooks/useHeader.js";
12
- const PureListPage = observer((props)=>{
13
- const { header, filter, toolbar, table, styles, pageRef } = props;
7
+ import { FilterSection, ListPageWrapper, ToolbarSection } from "../../styles.js";
8
+ import { DataTable } from "../DataTable/index.js";
9
+ const ListPageContainerComponent = observer((props)=>{
10
+ const { styles, header, filter, toolbar, table } = props;
14
11
  const store = useListPageStore();
15
- const floatEle = useFloat();
16
12
  const headerEle = useHeader(header);
17
- useMount(()=>{
18
- store.refreshTable();
19
- });
20
- useUpdateEffect(()=>{
21
- filter?.onChange?.(toJS(store.filters));
22
- }, [
23
- store.filters
24
- ]);
25
- useImperativeHandle(pageRef, ()=>store, [
26
- store
27
- ]);
28
- return /*#__PURE__*/ jsxs(ListPageContainer, {
13
+ const floatEle = useFloat();
14
+ return /*#__PURE__*/ jsxs(ListPageWrapper, {
29
15
  style: styles?.page,
30
16
  children: [
31
17
  headerEle,
@@ -54,8 +40,8 @@ const ListPage = (props)=>/*#__PURE__*/ jsx(ListPageProvider, {
54
40
  floats: props.floats,
55
41
  initialValues: props.initialValues,
56
42
  state: props.state,
57
- children: /*#__PURE__*/ jsx(PureListPage, {
43
+ children: /*#__PURE__*/ jsx(ListPageContainerComponent, {
58
44
  ...props
59
45
  })
60
46
  });
61
- export { ListPage, PureListPage };
47
+ export { ListPage };
@@ -0,0 +1,4 @@
1
+ import { ListPageStore } from './store';
2
+ import { ListPageProviderProps } from './types';
3
+ export declare const ListPageProvider: (props: ListPageProviderProps) => import("react/jsx-runtime").JSX.Element;
4
+ export declare function useListPageStore<FilterValue = any, RecordValue extends Record<string, any> = any>(): ListPageStore<FilterValue, RecordValue>;
@@ -0,0 +1,22 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useMemo } from "react";
3
+ import { ListPageStore } from "./store.js";
4
+ const ListPageContext = /*#__PURE__*/ createContext({});
5
+ const ListPageProvider = (props)=>{
6
+ const { state, request, children, initialValues, storageKey, floats } = props;
7
+ const store = useMemo(()=>new ListPageStore({
8
+ state,
9
+ initialValues,
10
+ request,
11
+ floats,
12
+ storageKey
13
+ }), []);
14
+ return /*#__PURE__*/ jsx(ListPageContext.Provider, {
15
+ value: store,
16
+ children: children
17
+ });
18
+ };
19
+ function useListPageStore() {
20
+ return useContext(ListPageContext);
21
+ }
22
+ export { ListPageProvider, useListPageStore };
@@ -0,0 +1,2 @@
1
+ export { ListPageProvider, useListPageStore } from './context';
2
+ export { ListPageStore } from './store';
@@ -0,0 +1,3 @@
1
+ import { ListPageProvider, useListPageStore } from "./context.js";
2
+ import { ListPageStore } from "./store.js";
3
+ export { ListPageProvider, ListPageStore, useListPageStore };
@@ -0,0 +1,37 @@
1
+ import { Key } from 'react';
2
+ import { ListPageFloatProps, ListPageRequest } from '../types';
3
+ import { ListPageStorageOption } from './types';
4
+ export declare class ListPageStore<FilterValue = any, RecordValue extends Record<string, any> = any> {
5
+ storageKey?: string;
6
+ filters: FilterValue;
7
+ tableDataRequest: ListPageRequest<FilterValue, RecordValue>;
8
+ floats: ListPageFloatProps[];
9
+ visibleFloat?: {
10
+ key: string;
11
+ record: RecordValue;
12
+ onCloseCallback?: true | (() => void);
13
+ };
14
+ loadingData: boolean;
15
+ dataSource: RecordValue[];
16
+ pagination: {
17
+ current: number;
18
+ pageSize: number;
19
+ total: number;
20
+ };
21
+ selection: {
22
+ selectedRowKeys: Key[];
23
+ selectedRows: RecordValue[];
24
+ };
25
+ listeners: Record<string, Function>;
26
+ constructor(options: ListPageStorageOption<FilterValue, RecordValue>);
27
+ submitFiltersChange(value?: FilterValue): void;
28
+ showFloat(key: string, record: any, onCloseCallback?: true | (() => void)): void;
29
+ hideFloat(): void;
30
+ updatePage(page: number, pageSize: number): void;
31
+ fetchTableData(): Promise<void>;
32
+ onSelectChange: (selectedRowKeys: Key[], selectedRows: RecordValue[]) => void;
33
+ clearSelection(): void;
34
+ refreshTable(): void;
35
+ listen(name: string, callback: (data: any) => void): void;
36
+ emit(name: string, data: any): void;
37
+ }
@@ -1,6 +1,5 @@
1
- import { jsx } from "react/jsx-runtime";
2
1
  import { makeAutoObservable, runInAction } from "mobx";
3
- import { createContext, useContext, useMemo } from "react";
2
+ import { getDefaultValue, setDefaultValue } from "../utils/index.js";
4
3
  class ListPageStore {
5
4
  storageKey;
6
5
  filters = {};
@@ -96,43 +95,4 @@ class ListPageStore {
96
95
  this.listeners[name]?.(data);
97
96
  }
98
97
  }
99
- const ListPageContext = /*#__PURE__*/ createContext({});
100
- const ListPageProvider = ({ children, initialValues, state, request, storageKey, floats = [] })=>{
101
- const store = useMemo(()=>new ListPageStore({
102
- state,
103
- initialValues,
104
- request,
105
- floats,
106
- storageKey
107
- }), []);
108
- return /*#__PURE__*/ jsx(ListPageContext.Provider, {
109
- value: store,
110
- children: children
111
- });
112
- };
113
- function useListPageStore() {
114
- return useContext(ListPageContext);
115
- }
116
- const getDefaultValue = (STORAGE_KEY)=>{
117
- if (!STORAGE_KEY) return {
118
- currentPage: 1,
119
- pageSize: 10,
120
- filterValues: void 0
121
- };
122
- const storageValue = localStorage.getItem(STORAGE_KEY);
123
- const value = JSON.parse(storageValue ?? '{}');
124
- return {
125
- currentPage: value.currentPage || 1,
126
- pageSize: value.pageSize || 10,
127
- filterValues: value.filterValues || void 0
128
- };
129
- };
130
- const setDefaultValue = (STORAGE_KEY, value)=>{
131
- if (!STORAGE_KEY) return;
132
- const defaultValue = getDefaultValue(STORAGE_KEY);
133
- localStorage.setItem(STORAGE_KEY, JSON.stringify({
134
- ...defaultValue,
135
- ...value
136
- }));
137
- };
138
- export { ListPageProvider, ListPageStore, useListPageStore };
98
+ export { ListPageStore };
@@ -0,0 +1,12 @@
1
+ import { ReactNode } from 'react';
2
+ import { ListPageFloatProps, ListPageRequest, StateValue } from '../types';
3
+ export type ListPageStorageOption<FilterValue = any, RecordValue extends Record<string, any> = any> = {
4
+ storageKey?: string;
5
+ initialValues?: StateValue<FilterValue>;
6
+ state?: StateValue<FilterValue>;
7
+ request: ListPageRequest<FilterValue, RecordValue>;
8
+ floats?: ListPageFloatProps[];
9
+ };
10
+ export type ListPageProviderProps = ListPageStorageOption & {
11
+ children: ReactNode;
12
+ };
File without changes
@@ -0,0 +1,3 @@
1
+ import { ColumnType } from 'antd/es/table';
2
+ import { ListPageTableColumn } from '../components/DataTable/types';
3
+ export declare function useColumns<FilterValue = any, RecordValue extends Record<string, any> = any>(columns: ListPageTableColumn<FilterValue, RecordValue>[]): ColumnType<RecordValue>[];
@@ -0,0 +1,20 @@
1
+ import { useListPageStore } from "../context/index.js";
2
+ import { renders } from "../components/DataTable/renders/index.js";
3
+ function useColumns(columns) {
4
+ const ctx = useListPageStore();
5
+ return columns.map((column)=>{
6
+ if (!column.render && column.component) column.render = createColumnRender(column.component, column.props, ctx);
7
+ return column;
8
+ });
9
+ }
10
+ function createColumnRender(component, props, ctx) {
11
+ if ('string' == typeof component) {
12
+ const render = renders[component];
13
+ if (render) return (value, record, index)=>render(value, record, index, props);
14
+ }
15
+ if ('function' == typeof component) return (value, record, index)=>{
16
+ const render = component;
17
+ return render(value, record, index, ctx);
18
+ };
19
+ }
20
+ export { useColumns };
@@ -1,6 +1,6 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { useMemo } from "react";
3
- import { useListPageStore } from "../context/listpage.js";
3
+ import { useListPageStore } from "../context/index.js";
4
4
  function useFloat() {
5
5
  const store = useListPageStore();
6
6
  const visibleFloat = store.visibleFloat;
@@ -0,0 +1,2 @@
1
+ import { ListPageHeaderProps } from '../types';
2
+ export declare function useHeader(props?: ListPageHeaderProps): false | import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { HeaderSection, Title } from "../components/ListPage/styles.js";
3
- import { useListPageStore } from "../context/listpage.js";
2
+ import { useListPageStore } from "../context/index.js";
3
+ import { HeaderSection, Title } from "../styles.js";
4
4
  function useHeader(props) {
5
5
  const store = useListPageStore();
6
6
  if (!props) return false;
@@ -1,7 +1,7 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { Pagination } from "antd";
3
- import { useListPageStore } from "../context/listpage.js";
4
- import { PaginationContainer } from "../../DataTable/index.js";
3
+ import { useListPageStore } from "../context/index.js";
4
+ import { PaginationContainer } from "../styles.js";
5
5
  function usePagination(props) {
6
6
  const store = useListPageStore();
7
7
  const ele = false === props ? null : /*#__PURE__*/ jsx(PaginationContainer, {
@@ -1,7 +1,7 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Button, Tooltip } from "antd";
3
- import { useListPageStore } from "../context/listpage.js";
4
3
  import styled_components from "styled-components";
4
+ import { useListPageStore } from "../context/index.js";
5
5
  function useSelectionTools(rowTitleKey) {
6
6
  const store = useListPageStore();
7
7
  const { selectedRowKeys, selectedRows } = store.selection;