szld-libs 0.2.30 → 0.2.31

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.
@@ -3,12 +3,14 @@ import { ColumnType } from 'antd/es/table';
3
3
  import { CreateFormProps } from '../CreateForm';
4
4
  export interface TableColumnProps<T> extends ColumnType<T> {
5
5
  hidden?: boolean;
6
- width?: number;
6
+ width?: number | string;
7
7
  }
8
8
  export interface MTableProps<T> extends Omit<TableProps<T>, 'columns'> {
9
9
  columns?: TableColumnProps<T>[];
10
10
  minColumnWidth?: number;
11
11
  resizeable?: boolean;
12
+ tableId?: string;
13
+ storageKey?: string;
12
14
  }
13
15
  export interface SearchTableProps<RecordType> {
14
16
  searchProps?: CreateFormProps;
@@ -4,6 +4,7 @@ import classNames from "classnames";
4
4
  import _ from "lodash";
5
5
  import { useState, useMemo } from "react";
6
6
  import { Resizable } from "react-resizable";
7
+ import { getLocalStorage } from "../../utils";
7
8
  import CreateForm from "../CreateForm";
8
9
  const search = "search-table-module_search_17add";
9
10
  const table = "search-table-module_table_5f652";
@@ -20,7 +21,13 @@ const ResizeableTitle = (props) => {
20
21
  };
21
22
  function SearchTable(props) {
22
23
  const { tableProps = {}, searchProps } = props;
23
- const { minColumnWidth = 200, resizeable = true, ...rest } = tableProps;
24
+ const {
25
+ minColumnWidth = 200,
26
+ resizeable = true,
27
+ tableId,
28
+ storageKey = "szld_table_cell_width",
29
+ ...rest
30
+ } = tableProps;
24
31
  const [columns, setColumns] = useState(tableProps.columns || []);
25
32
  const handleResize = (column, size) => {
26
33
  const list = _.cloneDeep(columns);
@@ -29,19 +36,42 @@ function SearchTable(props) {
29
36
  ...list[index],
30
37
  width: size.width
31
38
  };
39
+ if (tableId) {
40
+ const obj = getLocalStorage(storageKey) || {};
41
+ obj[tableId] = obj[tableId] || {};
42
+ list == null ? void 0 : list.forEach((v) => {
43
+ if (typeof v.dataIndex === "string") {
44
+ obj[tableId][v.dataIndex] = v.width;
45
+ }
46
+ });
47
+ localStorage.setItem(storageKey, JSON.stringify(obj));
48
+ }
32
49
  setColumns(list);
33
50
  };
51
+ const getWidth = (v) => {
52
+ var _a, _b;
53
+ let width = v.width || minColumnWidth;
54
+ if (typeof v.dataIndex === "string" && tableId) {
55
+ const _width = (_b = (_a = getLocalStorage(storageKey)) == null ? void 0 : _a[tableId]) == null ? void 0 : _b[v.dataIndex];
56
+ if (_width) {
57
+ width = _width;
58
+ }
59
+ }
60
+ return width;
61
+ };
34
62
  const realColumns = useMemo(() => {
35
63
  const result = columns.filter((v) => !v.hidden).map((v) => ({
36
64
  ...v,
37
- width: v.width || minColumnWidth,
38
- onHeaderCell: (column, index) => ({
65
+ width: getWidth(v),
66
+ onHeaderCell: (column) => ({
39
67
  width: column.width,
40
68
  resizeable,
41
69
  onResize: (_e, { size }) => handleResize(column, size)
42
70
  })
43
71
  }));
44
- result[result.length - 1].width = void 0;
72
+ if (result.length > 0) {
73
+ result[result.length - 1].width = void 0;
74
+ }
45
75
  return result;
46
76
  }, [resizeable, columns, minColumnWidth]);
47
77
  const components = {
package/es/index.js CHANGED
@@ -38,7 +38,7 @@ const Demo = () => {
38
38
  title: "c"
39
39
  }
40
40
  ];
41
- return /* @__PURE__ */ jsx("div", { style: { height: "100vh" }, children: /* @__PURE__ */ jsx(SearchTable, { tableProps: { columns, dataSource: [], resizeable: false } }) });
41
+ return /* @__PURE__ */ jsx("div", { style: { height: "100vh" }, children: /* @__PURE__ */ jsx(SearchTable, { tableProps: { columns, dataSource: [], resizeable: true, tableId: "demo1" } }) });
42
42
  };
43
43
  ReactDOM.createRoot(document.getElementById("root")).render(
44
44
  /* @__PURE__ */ jsx(BrowserRouter, { children: /* @__PURE__ */ jsx(Demo, {}) })
@@ -3,12 +3,14 @@ import { ColumnType } from 'antd/es/table';
3
3
  import { CreateFormProps } from '../CreateForm';
4
4
  export interface TableColumnProps<T> extends ColumnType<T> {
5
5
  hidden?: boolean;
6
- width?: number;
6
+ width?: number | string;
7
7
  }
8
8
  export interface MTableProps<T> extends Omit<TableProps<T>, 'columns'> {
9
9
  columns?: TableColumnProps<T>[];
10
10
  minColumnWidth?: number;
11
11
  resizeable?: boolean;
12
+ tableId?: string;
13
+ storageKey?: string;
12
14
  }
13
15
  export interface SearchTableProps<RecordType> {
14
16
  searchProps?: CreateFormProps;
@@ -5,6 +5,7 @@ const classNames = require("classnames");
5
5
  const _ = require("lodash");
6
6
  const react = require("react");
7
7
  const reactResizable = require("react-resizable");
8
+ const utils = require("../../utils");
8
9
  const CreateForm = require("../CreateForm");
9
10
  const search = "search-table-module_search_17add";
10
11
  const table = "search-table-module_table_5f652";
@@ -21,7 +22,13 @@ const ResizeableTitle = (props) => {
21
22
  };
22
23
  function SearchTable(props) {
23
24
  const { tableProps = {}, searchProps } = props;
24
- const { minColumnWidth = 200, resizeable = true, ...rest } = tableProps;
25
+ const {
26
+ minColumnWidth = 200,
27
+ resizeable = true,
28
+ tableId,
29
+ storageKey = "szld_table_cell_width",
30
+ ...rest
31
+ } = tableProps;
25
32
  const [columns, setColumns] = react.useState(tableProps.columns || []);
26
33
  const handleResize = (column, size) => {
27
34
  const list = _.cloneDeep(columns);
@@ -30,19 +37,42 @@ function SearchTable(props) {
30
37
  ...list[index],
31
38
  width: size.width
32
39
  };
40
+ if (tableId) {
41
+ const obj = utils.getLocalStorage(storageKey) || {};
42
+ obj[tableId] = obj[tableId] || {};
43
+ list == null ? void 0 : list.forEach((v) => {
44
+ if (typeof v.dataIndex === "string") {
45
+ obj[tableId][v.dataIndex] = v.width;
46
+ }
47
+ });
48
+ localStorage.setItem(storageKey, JSON.stringify(obj));
49
+ }
33
50
  setColumns(list);
34
51
  };
52
+ const getWidth = (v) => {
53
+ var _a, _b;
54
+ let width = v.width || minColumnWidth;
55
+ if (typeof v.dataIndex === "string" && tableId) {
56
+ const _width = (_b = (_a = utils.getLocalStorage(storageKey)) == null ? void 0 : _a[tableId]) == null ? void 0 : _b[v.dataIndex];
57
+ if (_width) {
58
+ width = _width;
59
+ }
60
+ }
61
+ return width;
62
+ };
35
63
  const realColumns = react.useMemo(() => {
36
64
  const result = columns.filter((v) => !v.hidden).map((v) => ({
37
65
  ...v,
38
- width: v.width || minColumnWidth,
39
- onHeaderCell: (column, index) => ({
66
+ width: getWidth(v),
67
+ onHeaderCell: (column) => ({
40
68
  width: column.width,
41
69
  resizeable,
42
70
  onResize: (_e, { size }) => handleResize(column, size)
43
71
  })
44
72
  }));
45
- result[result.length - 1].width = void 0;
73
+ if (result.length > 0) {
74
+ result[result.length - 1].width = void 0;
75
+ }
46
76
  return result;
47
77
  }, [resizeable, columns, minColumnWidth]);
48
78
  const components = {
package/lib/index.js CHANGED
@@ -39,7 +39,7 @@ const Demo = () => {
39
39
  title: "c"
40
40
  }
41
41
  ];
42
- return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { height: "100vh" }, children: /* @__PURE__ */ jsxRuntime.jsx(main.SearchTable, { tableProps: { columns, dataSource: [], resizeable: false } }) });
42
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { height: "100vh" }, children: /* @__PURE__ */ jsxRuntime.jsx(main.SearchTable, { tableProps: { columns, dataSource: [], resizeable: true, tableId: "demo1" } }) });
43
43
  };
44
44
  ReactDOM.createRoot(document.getElementById("root")).render(
45
45
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.BrowserRouter, { children: /* @__PURE__ */ jsxRuntime.jsx(Demo, {}) })
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "szld-libs",
3
3
  "private": false,
4
- "version": "0.2.30",
4
+ "version": "0.2.31",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",