szld-libs 0.2.32 → 0.2.33

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,8 +1,7 @@
1
1
  import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
2
  import { Table } from "antd";
3
3
  import classNames from "classnames";
4
- import _ from "lodash";
5
- import { useRef, useState, useEffect, useCallback, useMemo } from "react";
4
+ import { useState, useEffect } from "react";
6
5
  import { Resizable } from "react-resizable";
7
6
  import { getLocalStorage } from "../../utils";
8
7
  import CreateForm from "../CreateForm";
@@ -28,7 +27,6 @@ function SearchTable(props) {
28
27
  storageKey = "szld_table_cell_width",
29
28
  ...rest
30
29
  } = tableProps;
31
- const ref = useRef(null);
32
30
  const [columns, setColumns] = useState([]);
33
31
  const getWidth = (v) => {
34
32
  var _a, _b;
@@ -46,24 +44,36 @@ function SearchTable(props) {
46
44
  if (list.length === 0) {
47
45
  return;
48
46
  }
49
- const result = list.map((v) => ({
50
- ...v,
51
- width: getWidth(v)
52
- }));
47
+ const result = list == null ? void 0 : list.filter((v) => !v.hidden).map((v) => {
48
+ if (v.dataIndex) {
49
+ return {
50
+ ...v,
51
+ width: getWidth(v),
52
+ onHeaderCell: (column) => ({
53
+ width: column.width,
54
+ resizeable,
55
+ onResize: (_e, { size }) => handleResize(column, size)
56
+ })
57
+ };
58
+ }
59
+ return v;
60
+ });
61
+ if (result.length > 0) {
62
+ result[result.length - 1].width = void 0;
63
+ }
53
64
  setColumns(result);
54
- ref.current = Date.now();
55
65
  }, [tableProps.columns, tableId, minColumnWidth]);
56
- const handleResize = useCallback(
57
- (column, size) => {
58
- const list = _.cloneDeep(columns);
59
- if (!list || list.length === 0) {
60
- return;
61
- }
62
- const index = list == null ? void 0 : list.findIndex((v) => v.dataIndex === column.dataIndex);
63
- list[index] = {
64
- ...list[index],
65
- width: size.width
66
- };
66
+ const handleResize = (column, size) => {
67
+ setColumns((prevColumns) => {
68
+ const list = prevColumns == null ? void 0 : prevColumns.map((v) => {
69
+ if (v.dataIndex === column.dataIndex) {
70
+ return {
71
+ ...v,
72
+ width: size.width
73
+ };
74
+ }
75
+ return v;
76
+ });
67
77
  if (tableId) {
68
78
  const obj = getLocalStorage(storageKey) || {};
69
79
  obj[tableId] = obj[tableId] || {};
@@ -74,28 +84,9 @@ function SearchTable(props) {
74
84
  });
75
85
  localStorage.setItem(storageKey, JSON.stringify(obj));
76
86
  }
77
- setColumns(list);
78
- },
79
- [columns, tableId, storageKey]
80
- );
81
- const realColumns = useMemo(() => {
82
- if (!ref.current || columns === void 0) {
83
- return [];
84
- }
85
- const result = columns == null ? void 0 : columns.filter((v) => !v.hidden).map((v) => ({
86
- ...v,
87
- width: v.width,
88
- onHeaderCell: (column) => ({
89
- width: column.width,
90
- resizeable,
91
- onResize: (_e, { size }) => handleResize(column, size)
92
- })
93
- }));
94
- if (result.length > 0) {
95
- result[result.length - 1].width = void 0;
96
- }
97
- return result;
98
- }, [resizeable, columns, ref.current, minColumnWidth]);
87
+ return list;
88
+ });
89
+ };
99
90
  const components = {
100
91
  header: {
101
92
  cell: ResizeableTitle
@@ -107,9 +98,9 @@ function SearchTable(props) {
107
98
  Table,
108
99
  {
109
100
  ...rest,
110
- columns: realColumns,
101
+ columns,
111
102
  scroll: {
112
- x: realColumns.reduce((a, b) => a + (typeof b.width === "number" ? b.width : minColumnWidth), 0)
103
+ x: columns == null ? void 0 : columns.reduce((a, b) => a + (typeof b.width === "number" ? b.width : minColumnWidth), 0)
113
104
  },
114
105
  components,
115
106
  className: classNames(classes.table, tableProps == null ? void 0 : tableProps.className),
package/es/index.js CHANGED
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useState } from "react";
3
3
  import ReactDOM from "react-dom/client";
4
4
  import { BrowserRouter } from "react-router-dom";
5
- import { Button } from "antd";
5
+ import { Table, Button } from "antd";
6
6
  import useConfig from "./hooks/useConfig";
7
7
  import { AES, SearchTable } from "./main";
8
8
  let key = "U2FsdGVkX1/dG1NSXNR9hnp3Ech/v6Gh8CDDJxgBm1EPFQel12ySIf84ARXCPwTae7TzwgPvjOyE3S5rAEzl/wAZmId6pbezpFeFcJqxdmIl3FeluYHFxJzQHDETTvrr3G/REvv00kHptOVwg6ecjPH6yk7PNit0sWTBLorROxLxMD8lVDmOA66p7Zp4QnYzqScYJGFbutmfHYXfBRBe1Q2UKummJ798svNY5SIwEwl4spzgyWmhARtuyq4zhysFrj/xODuNDjtwitA6XfX566WcZkj3F+2P+mkYzDYOhXXaomnlybjrZ2hEHfcczQhUfJd89O8PNIuEWo24wjYRgMdKlw5CWSeocFCqV7ZJ/CV/7vNRcaO4awKlFNobLikkwDznxpcX+4UEej+ED+pgfmPQLsKedcfEscStkSAZXaD5pBRTiFU9xGLfDt6seUrEnMBeXkpMIY9j1SZDDK18/G7lSHjDQMZYZP6sfLdBdwY=";
@@ -29,11 +29,13 @@ const Demo = () => {
29
29
  dataIndex: "a",
30
30
  title: "a"
31
31
  },
32
+ Table.EXPAND_COLUMN,
32
33
  {
33
34
  dataIndex: "b",
34
35
  title: "b",
35
36
  width: 400
36
37
  },
38
+ Table.SELECTION_COLUMN,
37
39
  {
38
40
  dataIndex: "c",
39
41
  title: "c"
@@ -42,7 +44,29 @@ const Demo = () => {
42
44
  const [list, setList] = useState([]);
43
45
  return /* @__PURE__ */ jsxs("div", { style: { height: "100vh" }, children: [
44
46
  /* @__PURE__ */ jsx(Button, { onClick: () => setList(columns), children: "test" }),
45
- /* @__PURE__ */ jsx(SearchTable, { tableProps: { columns: list, dataSource: [], resizeable: true, tableId: "demo1" } })
47
+ /* @__PURE__ */ jsx(
48
+ SearchTable,
49
+ {
50
+ tableProps: {
51
+ columns: list,
52
+ dataSource: [
53
+ { a: 1, b: 2, c: 3, id: 1 },
54
+ { a: 1, b: 2, c: 3, id: 2 },
55
+ { a: 1, b: 2, c: 3, id: 3 }
56
+ ],
57
+ resizeable: true,
58
+ rowKey: "id",
59
+ rowSelection: {},
60
+ expandable: {
61
+ expandedRowRender: () => {
62
+ return /* @__PURE__ */ jsx("div", { children: "123" });
63
+ }
64
+ },
65
+ tableId: "demo1",
66
+ storageKey: "szld-libs-test"
67
+ }
68
+ }
69
+ )
46
70
  ] });
47
71
  };
48
72
  ReactDOM.createRoot(document.getElementById("root")).render(
@@ -2,7 +2,6 @@
2
2
  const jsxRuntime = require("react/jsx-runtime");
3
3
  const antd = require("antd");
4
4
  const classNames = require("classnames");
5
- const _ = require("lodash");
6
5
  const react = require("react");
7
6
  const reactResizable = require("react-resizable");
8
7
  const utils = require("../../utils");
@@ -29,7 +28,6 @@ function SearchTable(props) {
29
28
  storageKey = "szld_table_cell_width",
30
29
  ...rest
31
30
  } = tableProps;
32
- const ref = react.useRef(null);
33
31
  const [columns, setColumns] = react.useState([]);
34
32
  const getWidth = (v) => {
35
33
  var _a, _b;
@@ -47,24 +45,36 @@ function SearchTable(props) {
47
45
  if (list.length === 0) {
48
46
  return;
49
47
  }
50
- const result = list.map((v) => ({
51
- ...v,
52
- width: getWidth(v)
53
- }));
48
+ const result = list == null ? void 0 : list.filter((v) => !v.hidden).map((v) => {
49
+ if (v.dataIndex) {
50
+ return {
51
+ ...v,
52
+ width: getWidth(v),
53
+ onHeaderCell: (column) => ({
54
+ width: column.width,
55
+ resizeable,
56
+ onResize: (_e, { size }) => handleResize(column, size)
57
+ })
58
+ };
59
+ }
60
+ return v;
61
+ });
62
+ if (result.length > 0) {
63
+ result[result.length - 1].width = void 0;
64
+ }
54
65
  setColumns(result);
55
- ref.current = Date.now();
56
66
  }, [tableProps.columns, tableId, minColumnWidth]);
57
- const handleResize = react.useCallback(
58
- (column, size) => {
59
- const list = _.cloneDeep(columns);
60
- if (!list || list.length === 0) {
61
- return;
62
- }
63
- const index = list == null ? void 0 : list.findIndex((v) => v.dataIndex === column.dataIndex);
64
- list[index] = {
65
- ...list[index],
66
- width: size.width
67
- };
67
+ const handleResize = (column, size) => {
68
+ setColumns((prevColumns) => {
69
+ const list = prevColumns == null ? void 0 : prevColumns.map((v) => {
70
+ if (v.dataIndex === column.dataIndex) {
71
+ return {
72
+ ...v,
73
+ width: size.width
74
+ };
75
+ }
76
+ return v;
77
+ });
68
78
  if (tableId) {
69
79
  const obj = utils.getLocalStorage(storageKey) || {};
70
80
  obj[tableId] = obj[tableId] || {};
@@ -75,28 +85,9 @@ function SearchTable(props) {
75
85
  });
76
86
  localStorage.setItem(storageKey, JSON.stringify(obj));
77
87
  }
78
- setColumns(list);
79
- },
80
- [columns, tableId, storageKey]
81
- );
82
- const realColumns = react.useMemo(() => {
83
- if (!ref.current || columns === void 0) {
84
- return [];
85
- }
86
- const result = columns == null ? void 0 : columns.filter((v) => !v.hidden).map((v) => ({
87
- ...v,
88
- width: v.width,
89
- onHeaderCell: (column) => ({
90
- width: column.width,
91
- resizeable,
92
- onResize: (_e, { size }) => handleResize(column, size)
93
- })
94
- }));
95
- if (result.length > 0) {
96
- result[result.length - 1].width = void 0;
97
- }
98
- return result;
99
- }, [resizeable, columns, ref.current, minColumnWidth]);
88
+ return list;
89
+ });
90
+ };
100
91
  const components = {
101
92
  header: {
102
93
  cell: ResizeableTitle
@@ -108,9 +99,9 @@ function SearchTable(props) {
108
99
  antd.Table,
109
100
  {
110
101
  ...rest,
111
- columns: realColumns,
102
+ columns,
112
103
  scroll: {
113
- x: realColumns.reduce((a, b) => a + (typeof b.width === "number" ? b.width : minColumnWidth), 0)
104
+ x: columns == null ? void 0 : columns.reduce((a, b) => a + (typeof b.width === "number" ? b.width : minColumnWidth), 0)
114
105
  },
115
106
  components,
116
107
  className: classNames(classes.table, tableProps == null ? void 0 : tableProps.className),
package/lib/index.js CHANGED
@@ -30,11 +30,13 @@ const Demo = () => {
30
30
  dataIndex: "a",
31
31
  title: "a"
32
32
  },
33
+ antd.Table.EXPAND_COLUMN,
33
34
  {
34
35
  dataIndex: "b",
35
36
  title: "b",
36
37
  width: 400
37
38
  },
39
+ antd.Table.SELECTION_COLUMN,
38
40
  {
39
41
  dataIndex: "c",
40
42
  title: "c"
@@ -43,7 +45,29 @@ const Demo = () => {
43
45
  const [list, setList] = react.useState([]);
44
46
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { height: "100vh" }, children: [
45
47
  /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { onClick: () => setList(columns), children: "test" }),
46
- /* @__PURE__ */ jsxRuntime.jsx(main.SearchTable, { tableProps: { columns: list, dataSource: [], resizeable: true, tableId: "demo1" } })
48
+ /* @__PURE__ */ jsxRuntime.jsx(
49
+ main.SearchTable,
50
+ {
51
+ tableProps: {
52
+ columns: list,
53
+ dataSource: [
54
+ { a: 1, b: 2, c: 3, id: 1 },
55
+ { a: 1, b: 2, c: 3, id: 2 },
56
+ { a: 1, b: 2, c: 3, id: 3 }
57
+ ],
58
+ resizeable: true,
59
+ rowKey: "id",
60
+ rowSelection: {},
61
+ expandable: {
62
+ expandedRowRender: () => {
63
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { children: "123" });
64
+ }
65
+ },
66
+ tableId: "demo1",
67
+ storageKey: "szld-libs-test"
68
+ }
69
+ }
70
+ )
47
71
  ] });
48
72
  };
49
73
  ReactDOM.createRoot(document.getElementById("root")).render(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "szld-libs",
3
3
  "private": false,
4
- "version": "0.2.32",
4
+ "version": "0.2.33",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",