@creekjs/web-components 1.0.5 → 1.0.7
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/.turbo/turbo-father$colon$build.log +32 -16
- package/README.md +117 -66
- package/dist/creek-config-provider/CreekConfigContext.d.ts +4 -0
- package/dist/creek-config-provider/CreekConfigContext.js.map +2 -2
- package/dist/creek-config-provider/CreekI18nProvider.d.ts +22 -0
- package/dist/creek-config-provider/CreekI18nProvider.js +92 -0
- package/dist/creek-config-provider/CreekI18nProvider.js.map +7 -0
- package/dist/creek-config-provider/index.d.ts +5 -3
- package/dist/creek-config-provider/index.js +47 -4
- package/dist/creek-config-provider/index.js.map +3 -3
- package/dist/creek-hooks/useApp/index.d.ts +3 -3
- package/dist/creek-keep-alive/index.d.ts +24 -1
- package/dist/creek-keep-alive/index.js +141 -4
- package/dist/creek-keep-alive/index.js.map +2 -2
- package/dist/creek-layout/ActionRender/FullScreen.js +3 -1
- package/dist/creek-layout/ActionRender/FullScreen.js.map +2 -2
- package/dist/creek-layout/ActionRender/LayoutSettings.d.ts +5 -0
- package/dist/creek-layout/ActionRender/LayoutSettings.js +73 -0
- package/dist/creek-layout/ActionRender/LayoutSettings.js.map +7 -0
- package/dist/creek-layout/ActionRender/UserInfo.js.map +2 -2
- package/dist/creek-layout/ActionRender/index.d.ts +1 -0
- package/dist/creek-layout/ActionRender/index.js +3 -0
- package/dist/creek-layout/ActionRender/index.js.map +2 -2
- package/dist/creek-layout/index.d.ts +5 -5
- package/dist/creek-layout/index.js +79 -16
- package/dist/creek-layout/index.js.map +3 -3
- package/dist/creek-layout/useLayoutSettingsStore.d.ts +20 -0
- package/dist/creek-layout/useLayoutSettingsStore.js +45 -0
- package/dist/creek-layout/useLayoutSettingsStore.js.map +7 -0
- package/dist/creek-locale-button/index.d.ts +1 -0
- package/dist/creek-locale-button/index.js +66 -0
- package/dist/creek-locale-button/index.js.map +7 -0
- package/dist/creek-page-container/index.d.ts +4 -0
- package/dist/creek-page-container/index.js +68 -0
- package/dist/creek-page-container/index.js.map +7 -0
- package/dist/creek-style/index.d.ts +1 -0
- package/dist/creek-style/index.js +24 -0
- package/dist/creek-style/index.js.map +7 -0
- package/dist/creek-style/scrollbar.d.ts +2 -0
- package/dist/creek-style/scrollbar.js +55 -0
- package/dist/creek-style/scrollbar.js.map +7 -0
- package/dist/creek-table/SearchTable.d.ts +9 -0
- package/dist/creek-table/SearchTable.js +109 -72
- package/dist/creek-table/SearchTable.js.map +3 -3
- package/dist/creek-table/components/DensityIcon.d.ts +9 -0
- package/dist/creek-table/components/DensityIcon.js +77 -0
- package/dist/creek-table/components/DensityIcon.js.map +7 -0
- package/dist/creek-table/components/EllipsisTooltip.d.ts +9 -0
- package/dist/creek-table/components/EllipsisTooltip.js +122 -0
- package/dist/creek-table/components/EllipsisTooltip.js.map +7 -0
- package/dist/creek-table/components/index.d.ts +2 -0
- package/dist/creek-table/components/index.js +26 -0
- package/dist/creek-table/components/index.js.map +7 -0
- package/dist/creek-table/hooks/index.d.ts +5 -0
- package/dist/creek-table/hooks/index.js +10 -0
- package/dist/creek-table/hooks/index.js.map +2 -2
- package/dist/creek-table/hooks/useAutoWidthColumns.d.ts +1 -1
- package/dist/creek-table/hooks/useAutoWidthColumns.js +76 -17
- package/dist/creek-table/hooks/useAutoWidthColumns.js.map +2 -2
- package/dist/creek-table/hooks/useEllipsisColumns.d.ts +8 -0
- package/dist/creek-table/hooks/useEllipsisColumns.js +58 -0
- package/dist/creek-table/hooks/useEllipsisColumns.js.map +7 -0
- package/dist/creek-table/hooks/useIndexColumn.d.ts +2 -0
- package/dist/creek-table/hooks/useIndexColumn.js +52 -0
- package/dist/creek-table/hooks/useIndexColumn.js.map +7 -0
- package/dist/creek-table/hooks/useResizableColumns.d.ts +20 -0
- package/dist/creek-table/hooks/useResizableColumns.js +279 -0
- package/dist/creek-table/hooks/useResizableColumns.js.map +7 -0
- package/dist/creek-table/hooks/useStatusColumns.d.ts +2 -0
- package/dist/creek-table/hooks/useStatusColumns.js +215 -0
- package/dist/creek-table/hooks/useStatusColumns.js.map +7 -0
- package/dist/creek-table/hooks/useTableOptions.d.ts +15 -0
- package/dist/creek-table/hooks/useTableOptions.js +78 -0
- package/dist/creek-table/hooks/useTableOptions.js.map +7 -0
- package/dist/creek-table/hooks/useTableScrollHeight.d.ts +6 -1
- package/dist/creek-table/hooks/useTableScrollHeight.js +44 -5
- package/dist/creek-table/hooks/useTableScrollHeight.js.map +2 -2
- package/dist/creek-table/type.d.ts +4 -6
- package/dist/creek-table/type.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +2 -2
- package/dist/locales/en-US.d.ts +25 -0
- package/dist/locales/en-US.js +49 -0
- package/dist/locales/en-US.js.map +7 -0
- package/dist/locales/zh-CN.d.ts +25 -0
- package/dist/locales/zh-CN.js +49 -0
- package/dist/locales/zh-CN.js.map +7 -0
- package/dist/utils/i18n.d.ts +2 -0
- package/dist/utils/i18n.js +34 -0
- package/dist/utils/i18n.js.map +7 -0
- package/i18n.config.ts +27 -0
- package/package.json +22 -8
- package/src/creek-config-provider/CreekConfigContext.tsx +5 -1
- package/src/creek-config-provider/CreekI18nProvider.tsx +87 -0
- package/src/creek-config-provider/index.tsx +53 -4
- package/src/creek-keep-alive/index.tsx +225 -6
- package/src/creek-layout/ActionRender/FullScreen.tsx +10 -6
- package/src/creek-layout/ActionRender/LayoutSettings.tsx +67 -0
- package/src/creek-layout/ActionRender/UserInfo.tsx +1 -1
- package/src/creek-layout/ActionRender/index.tsx +1 -0
- package/src/creek-layout/index.tsx +89 -22
- package/src/creek-layout/useLayoutSettingsStore.ts +25 -0
- package/src/creek-locale-button/index.tsx +42 -0
- package/src/creek-page-container/index.tsx +32 -0
- package/src/creek-style/index.ts +1 -0
- package/src/creek-style/scrollbar.ts +29 -0
- package/src/creek-table/SearchTable.tsx +125 -72
- package/src/creek-table/components/DensityIcon.tsx +63 -0
- package/src/creek-table/components/EllipsisTooltip.tsx +116 -0
- package/src/creek-table/components/index.tsx +3 -0
- package/src/creek-table/hooks/index.ts +5 -1
- package/src/creek-table/hooks/useAutoWidthColumns.tsx +93 -19
- package/src/creek-table/hooks/useEllipsisColumns.tsx +47 -0
- package/src/creek-table/hooks/useIndexColumn.tsx +27 -0
- package/src/creek-table/hooks/useResizableColumns.tsx +323 -0
- package/src/creek-table/hooks/useStatusColumns.tsx +252 -0
- package/src/creek-table/hooks/useTableOptions.tsx +81 -0
- package/src/creek-table/hooks/useTableScrollHeight.tsx +61 -6
- package/src/creek-table/type.ts +5 -7
- package/src/index.tsx +4 -0
- package/src/locales/en-US.ts +24 -0
- package/src/locales/zh-CN.ts +24 -0
- package/src/utils/i18n.ts +4 -0
- package/dist/creek-config-provider/CreekConfigContext.d.ts.map +0 -1
- package/dist/creek-config-provider/index.d.ts.map +0 -1
- package/dist/creek-hooks/index.d.ts.map +0 -1
- package/dist/creek-hooks/useApp/DrawerHelper.d.ts.map +0 -1
- package/dist/creek-hooks/useApp/ModalHelper.d.ts.map +0 -1
- package/dist/creek-hooks/useApp/index.d.ts.map +0 -1
- package/dist/creek-hooks/useApp/types.d.ts.map +0 -1
- package/dist/creek-hooks/useViewportHeight.d.ts.map +0 -1
- package/dist/creek-icon/index.d.ts.map +0 -1
- package/dist/creek-keep-alive/index.d.ts.map +0 -1
- package/dist/creek-layout/ActionRender/FullScreen.d.ts.map +0 -1
- package/dist/creek-layout/ActionRender/UserInfo.d.ts.map +0 -1
- package/dist/creek-layout/ActionRender/index.d.ts.map +0 -1
- package/dist/creek-layout/CollapseButton.d.ts.map +0 -1
- package/dist/creek-layout/Exception/NotFound.d.ts.map +0 -1
- package/dist/creek-layout/Exception/NotFoundPage.d.ts.map +0 -1
- package/dist/creek-layout/Exception/index.d.ts.map +0 -1
- package/dist/creek-layout/index.d.ts.map +0 -1
- package/dist/creek-loading/index.d.ts.map +0 -1
- package/dist/creek-table/SearchTable.d.ts.map +0 -1
- package/dist/creek-table/TableOptionRender.d.ts +0 -9
- package/dist/creek-table/TableOptionRender.d.ts.map +0 -1
- package/dist/creek-table/TableOptionRender.js +0 -74
- package/dist/creek-table/TableOptionRender.js.map +0 -7
- package/dist/creek-table/hooks/index.d.ts.map +0 -1
- package/dist/creek-table/hooks/useAdaptiveToolBar.d.ts.map +0 -1
- package/dist/creek-table/hooks/useAutoWidthColumns.d.ts.map +0 -1
- package/dist/creek-table/hooks/useElementDistance.d.ts.map +0 -1
- package/dist/creek-table/hooks/useTableScrollHeight.d.ts.map +0 -1
- package/dist/creek-table/index.d.ts.map +0 -1
- package/dist/creek-table/toolBarRender.d.ts +0 -5
- package/dist/creek-table/toolBarRender.d.ts.map +0 -1
- package/dist/creek-table/toolBarRender.js +0 -58
- package/dist/creek-table/toolBarRender.js.map +0 -7
- package/dist/creek-table/type.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/src/creek-table/TableOptionRender.tsx +0 -57
- package/src/creek-table/toolBarRender.tsx +0 -28
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/creek-table/hooks/useEllipsisColumns.tsx"],
|
|
4
|
+
"sourcesContent": ["import type { ParamsType, ProColumns } from '@ant-design/pro-components';\nimport React, { useMemo } from 'react';\nimport { EllipsisTooltip } from '../components';\n\n/**\n * 默认开启 ellipsis 的 Hook\n * 1. 如果用户未配置 ellipsis,默认开启,并使用 Tooltip 显示完整内容\n * 2. 如果是 option 列,默认不开启\n * 3. 尊重用户配置\n */\nexport const useEllipsisColumns = <T extends ParamsType, ValueType = 'text'>(\n columns: ProColumns<T, ValueType>[] | undefined,\n) => {\n const processedColumns = useMemo(() => {\n return columns?.map((col) => {\n // 对于操作列,默认不开启 ellipsis\n if (col.valueType === 'option') {\n return col;\n }\n // 其他列默认开启 ellipsis,并使用自定义渲染\n return {\n ...col,\n // 关闭 Table 自带的 ellipsis title,因为我们要用自己的 Tooltip\n // 但保留 ellipsis 属性以确保 Table 传递正确的样式给 cell(虽然我们的 EllipsisTooltip 也有样式)\n // 实际上,为了让 EllipsisTooltip 占据 100% 宽度并生效,最好让 Table cell 也保持一定的约束\n ellipsis: {\n showTitle: false,\n },\n render: (dom: React.ReactNode, entity: T, index: number, action: any, schema: any) => {\n const originalRenderResult = col.render ? (col.render(dom, entity, index, action, schema) as React.ReactNode) : dom;\n \n // 如果内容为空,直接返回\n if (originalRenderResult === null || originalRenderResult === undefined || originalRenderResult === '') {\n return originalRenderResult;\n }\n\n // 如果是简单的文本或数字,使用 EllipsisTooltip 包裹\n return (\n <EllipsisTooltip>{originalRenderResult}</EllipsisTooltip>\n );\n },\n } as ProColumns<T, ValueType>;\n });\n }, [columns]);\n\n return processedColumns;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA+B;AAC/B,wBAAgC;AAoCpB;AA5BL,IAAM,qBAAqB,CAChC,YACG;AACH,QAAM,uBAAmB,sBAAQ,MAAM;AACrC,WAAO,mCAAS,IAAI,CAAC,QAAQ;AAE3B,UAAI,IAAI,cAAc,UAAU;AAC9B,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,QACL,GAAG;AAAA;AAAA;AAAA;AAAA,QAIH,UAAU;AAAA,UACR,WAAW;AAAA,QACb;AAAA,QACA,QAAQ,CAAC,KAAsB,QAAW,OAAe,QAAa,WAAgB;AACpF,gBAAM,uBAAuB,IAAI,SAAU,IAAI,OAAO,KAAK,QAAQ,OAAO,QAAQ,MAAM,IAAwB;AAGhH,cAAI,yBAAyB,QAAQ,yBAAyB,UAAa,yBAAyB,IAAI;AACtG,mBAAO;AAAA,UACT;AAGA,iBACE,4CAAC,qCAAiB,gCAAqB;AAAA,QAE3C;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/creek-table/hooks/useIndexColumn.tsx
|
|
20
|
+
var useIndexColumn_exports = {};
|
|
21
|
+
__export(useIndexColumn_exports, {
|
|
22
|
+
useIndexColumn: () => useIndexColumn
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useIndexColumn_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
var import_i18n = require("../../utils/i18n");
|
|
27
|
+
var useIndexColumn = (columns = [], showIndex = true) => {
|
|
28
|
+
const t = (0, import_i18n.useT)();
|
|
29
|
+
return (0, import_react.useMemo)(() => {
|
|
30
|
+
if (!showIndex) {
|
|
31
|
+
return columns;
|
|
32
|
+
}
|
|
33
|
+
const indexColumn = {
|
|
34
|
+
title: t("creek-table.hooks.useIndexColumn.xuHao", "序号"),
|
|
35
|
+
dataIndex: "index",
|
|
36
|
+
width: 48,
|
|
37
|
+
fixed: "left",
|
|
38
|
+
disable: true,
|
|
39
|
+
hideInSearch: true,
|
|
40
|
+
render: (dom, entity, index, action, schema) => {
|
|
41
|
+
const { current = 1, pageSize = 20 } = (action == null ? void 0 : action.pageInfo) || {};
|
|
42
|
+
return (current - 1) * pageSize + index + 1;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return [indexColumn, ...columns];
|
|
46
|
+
}, [columns, showIndex, t]);
|
|
47
|
+
};
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
useIndexColumn
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=useIndexColumn.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/creek-table/hooks/useIndexColumn.tsx"],
|
|
4
|
+
"sourcesContent": ["import { ProColumns } from '@ant-design/pro-components';\nimport { useMemo } from 'react';\n\nimport { useT } from '@/utils/i18n';\n\nexport const useIndexColumn = <T = any, ValueType = 'text'>(columns: ProColumns<T, ValueType>[] = [], showIndex: boolean = true) => {\n const t = useT();\n\n return useMemo(() => {\n if (!showIndex) {\n return columns;\n }\n const indexColumn: ProColumns<T, ValueType> = {\n title: t('creek-table.hooks.useIndexColumn.xuHao', '序号'),\n dataIndex: 'index',\n width: 48,\n fixed: 'left',\n disable: true,\n hideInSearch: true,\n render: (dom, entity, index, action, schema) => {\n const { current = 1, pageSize = 20 } = action?.pageInfo || {};\n return (current - 1) * pageSize + index + 1;\n },\n };\n return [indexColumn, ...columns];\n }, [columns, showIndex, t]);\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAwB;AAExB,kBAAqB;AAEd,IAAM,iBAAiB,CAA8B,UAAsC,CAAC,GAAG,YAAqB,SAAS;AAClI,QAAM,QAAI,kBAAK;AAEf,aAAO,sBAAQ,MAAM;AACnB,QAAI,CAAC,WAAW;AACd,aAAO;AAAA,IACT;AACA,UAAM,cAAwC;AAAA,MAC5C,OAAO,EAAE,0CAA0C,IAAI;AAAA,MACvD,WAAW;AAAA,MACX,OAAO;AAAA,MACP,OAAO;AAAA,MACP,SAAS;AAAA,MACT,cAAc;AAAA,MACd,QAAQ,CAAC,KAAK,QAAQ,OAAO,QAAQ,WAAW;AAC9C,cAAM,EAAE,UAAU,GAAG,WAAW,GAAG,KAAI,iCAAQ,aAAY,CAAC;AAC5D,gBAAQ,UAAU,KAAK,WAAW,QAAQ;AAAA,MAC5C;AAAA,IACF;AACA,WAAO,CAAC,aAAa,GAAG,OAAO;AAAA,EACjC,GAAG,CAAC,SAAS,WAAW,CAAC,CAAC;AAC5B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ProColumns } from '@ant-design/pro-components';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ResizeCallbackData } from 'react-resizable';
|
|
4
|
+
interface ResizableTitleProps extends React.HTMLAttributes<HTMLTableCellElement> {
|
|
5
|
+
onResize?: (e: React.SyntheticEvent, data: ResizeCallbackData) => void;
|
|
6
|
+
onResizeStart?: (e: React.SyntheticEvent, data: ResizeCallbackData) => void;
|
|
7
|
+
onResizeStop?: (e: React.SyntheticEvent, data: ResizeCallbackData) => void;
|
|
8
|
+
width?: number | string;
|
|
9
|
+
minWidth?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const useResizableColumns: <T, ValueType>(columns: ProColumns<T, ValueType>[] | undefined, resizable?: boolean, resizedWidthsProp?: Record<string, number>, setResizedWidthsProp?: React.Dispatch<React.SetStateAction<Record<string, number>>>, tableRef?: React.RefObject<HTMLDivElement>) => {
|
|
12
|
+
columns: ProColumns<T, ValueType>[] | undefined;
|
|
13
|
+
components: {
|
|
14
|
+
header: {
|
|
15
|
+
cell: React.ComponentType<ResizableTitleProps>;
|
|
16
|
+
};
|
|
17
|
+
} | undefined;
|
|
18
|
+
resizedWidths: Record<string, number>;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/creek-table/hooks/useResizableColumns.tsx
|
|
30
|
+
var useResizableColumns_exports = {};
|
|
31
|
+
__export(useResizableColumns_exports, {
|
|
32
|
+
useResizableColumns: () => useResizableColumns
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(useResizableColumns_exports);
|
|
35
|
+
var import_ahooks = require("ahooks");
|
|
36
|
+
var import_antd_style = require("antd-style");
|
|
37
|
+
var import_classnames = __toESM(require("classnames"));
|
|
38
|
+
var import_react = require("react");
|
|
39
|
+
var import_react_resizable = require("react-resizable");
|
|
40
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
41
|
+
var useStyles = (0, import_antd_style.createStyles)(({ token }) => ({
|
|
42
|
+
"resizable-handle": {
|
|
43
|
+
position: "absolute",
|
|
44
|
+
right: -5,
|
|
45
|
+
bottom: 0,
|
|
46
|
+
zIndex: 10,
|
|
47
|
+
width: 10,
|
|
48
|
+
height: "100%",
|
|
49
|
+
cursor: "col-resize",
|
|
50
|
+
touchAction: "none",
|
|
51
|
+
userSelect: "none",
|
|
52
|
+
// 添加一个小竖线作为视觉提示
|
|
53
|
+
"&::after": {
|
|
54
|
+
content: '""',
|
|
55
|
+
position: "absolute",
|
|
56
|
+
top: 0,
|
|
57
|
+
bottom: 0,
|
|
58
|
+
left: "50%",
|
|
59
|
+
width: 1,
|
|
60
|
+
opacity: 0,
|
|
61
|
+
transition: "all 0.3s",
|
|
62
|
+
transform: "translateX(-50%)"
|
|
63
|
+
},
|
|
64
|
+
"&:hover::after": {
|
|
65
|
+
opacity: 1
|
|
66
|
+
},
|
|
67
|
+
"&:active::after": {
|
|
68
|
+
opacity: 1
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"resizable-th": {
|
|
72
|
+
position: "relative",
|
|
73
|
+
"&:hover .resizable-handle::after": {
|
|
74
|
+
opacity: 0.5
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
78
|
+
var ResizableTitle = (props) => {
|
|
79
|
+
const { onResize, onResizeStart, onResizeStop, width, className, minWidth, ...restProps } = props;
|
|
80
|
+
const { styles } = useStyles();
|
|
81
|
+
const ref = (0, import_react.useRef)(null);
|
|
82
|
+
const [realWidth, setRealWidth] = (0, import_react.useState)(void 0);
|
|
83
|
+
const [localWidth, setLocalWidth] = (0, import_react.useState)(typeof width === "number" ? width : void 0);
|
|
84
|
+
const [isResizing, setIsResizing] = (0, import_react.useState)(false);
|
|
85
|
+
(0, import_react.useEffect)(() => {
|
|
86
|
+
if (!isResizing && typeof width === "number") {
|
|
87
|
+
setLocalWidth(width);
|
|
88
|
+
}
|
|
89
|
+
}, [width, isResizing]);
|
|
90
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
91
|
+
if (ref.current) {
|
|
92
|
+
const w = ref.current.getBoundingClientRect().width;
|
|
93
|
+
setRealWidth(w);
|
|
94
|
+
if (typeof width !== "number") {
|
|
95
|
+
setLocalWidth(w);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}, []);
|
|
99
|
+
const handleResizeStart = (e, data) => {
|
|
100
|
+
setIsResizing(true);
|
|
101
|
+
document.body.style.userSelect = "none";
|
|
102
|
+
document.body.style.cursor = "col-resize";
|
|
103
|
+
if (onResizeStart) {
|
|
104
|
+
onResizeStart(e, data);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const handleResizeStop = (e, data) => {
|
|
108
|
+
setIsResizing(false);
|
|
109
|
+
document.body.style.userSelect = "";
|
|
110
|
+
document.body.style.cursor = "";
|
|
111
|
+
if (onResizeStop) {
|
|
112
|
+
onResizeStop(e, data);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const handleResize = (e, data) => {
|
|
116
|
+
setLocalWidth(data.size.width);
|
|
117
|
+
if (onResize) {
|
|
118
|
+
onResize(e, data);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const currentWidth = localWidth ?? realWidth;
|
|
122
|
+
if (typeof currentWidth === "number" && onResize) {
|
|
123
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
124
|
+
import_react_resizable.Resizable,
|
|
125
|
+
{
|
|
126
|
+
width: currentWidth,
|
|
127
|
+
height: 0,
|
|
128
|
+
minConstraints: [minWidth || 0, 0],
|
|
129
|
+
handle: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
130
|
+
"span",
|
|
131
|
+
{
|
|
132
|
+
className: (0, import_classnames.default)(styles["resizable-handle"], "resizable-handle"),
|
|
133
|
+
onClick: (e) => {
|
|
134
|
+
e.stopPropagation();
|
|
135
|
+
},
|
|
136
|
+
onMouseEnter: (e) => {
|
|
137
|
+
if (onResizeStart) {
|
|
138
|
+
onResizeStart(e, { node: e.currentTarget, size: { width: currentWidth, height: 0 }, handle: "e" });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
),
|
|
143
|
+
onResize: handleResize,
|
|
144
|
+
onResizeStart: handleResizeStart,
|
|
145
|
+
onResizeStop: handleResizeStop,
|
|
146
|
+
draggableOpts: { enableUserSelectHack: false },
|
|
147
|
+
axis: "x",
|
|
148
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { ...restProps, className: (0, import_classnames.default)(className, styles["resizable-th"]), style: { ...restProps.style, width: currentWidth } })
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (!onResize || !realWidth) {
|
|
153
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { ...restProps, className, ref });
|
|
154
|
+
}
|
|
155
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
156
|
+
import_react_resizable.Resizable,
|
|
157
|
+
{
|
|
158
|
+
width: realWidth,
|
|
159
|
+
height: 0,
|
|
160
|
+
minConstraints: [minWidth || 0, 0],
|
|
161
|
+
handle: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
162
|
+
"span",
|
|
163
|
+
{
|
|
164
|
+
className: (0, import_classnames.default)(styles["resizable-handle"], "resizable-handle"),
|
|
165
|
+
onClick: (e) => {
|
|
166
|
+
e.stopPropagation();
|
|
167
|
+
},
|
|
168
|
+
onMouseEnter: (e) => {
|
|
169
|
+
if (onResizeStart) {
|
|
170
|
+
onResizeStart(e, { node: e.currentTarget, size: { width: realWidth, height: 0 }, handle: "e" });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
),
|
|
175
|
+
onResize: handleResize,
|
|
176
|
+
onResizeStart: handleResizeStart,
|
|
177
|
+
onResizeStop: handleResizeStop,
|
|
178
|
+
draggableOpts: { enableUserSelectHack: false },
|
|
179
|
+
axis: "x",
|
|
180
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { ...restProps, className: (0, import_classnames.default)(className, styles["resizable-th"]), style: { ...restProps.style, width: realWidth } })
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
};
|
|
184
|
+
var useResizableColumns = (columns, resizable = true, resizedWidthsProp, setResizedWidthsProp, tableRef) => {
|
|
185
|
+
const [internalResizedWidths, setInternalResizedWidths] = (0, import_react.useState)({});
|
|
186
|
+
const [minWidths, setMinWidths] = (0, import_react.useState)({});
|
|
187
|
+
const resizedWidths = resizedWidthsProp || internalResizedWidths;
|
|
188
|
+
const setResizedWidths = setResizedWidthsProp || setInternalResizedWidths;
|
|
189
|
+
const handleResize = (0, import_ahooks.useMemoizedFn)((key) => (_, { size }) => {
|
|
190
|
+
});
|
|
191
|
+
const handleResizeStop = (0, import_ahooks.useMemoizedFn)((key) => (_, { size }) => {
|
|
192
|
+
setResizedWidths((prev) => ({
|
|
193
|
+
...prev,
|
|
194
|
+
[key]: size.width
|
|
195
|
+
}));
|
|
196
|
+
});
|
|
197
|
+
const handleResizeStart = (0, import_ahooks.useMemoizedFn)(() => {
|
|
198
|
+
if (!(tableRef == null ? void 0 : tableRef.current))
|
|
199
|
+
return;
|
|
200
|
+
const thElements = tableRef.current.querySelectorAll("th[data-column-key]");
|
|
201
|
+
if (!thElements || thElements.length === 0)
|
|
202
|
+
return;
|
|
203
|
+
const currentWidths = {};
|
|
204
|
+
thElements.forEach((th) => {
|
|
205
|
+
const key = th.getAttribute("data-column-key");
|
|
206
|
+
const width = th.getBoundingClientRect().width;
|
|
207
|
+
if (key && width) {
|
|
208
|
+
currentWidths[key] = width;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
setResizedWidths((prev) => {
|
|
212
|
+
const next = { ...currentWidths, ...prev };
|
|
213
|
+
const isSame = Object.keys(next).every((k) => next[k] === prev[k]) && Object.keys(prev).length === Object.keys(next).length;
|
|
214
|
+
if (isSame)
|
|
215
|
+
return prev;
|
|
216
|
+
return next;
|
|
217
|
+
});
|
|
218
|
+
setMinWidths((prev) => {
|
|
219
|
+
const next = { ...prev };
|
|
220
|
+
let hasChange = false;
|
|
221
|
+
Object.keys(currentWidths).forEach((key) => {
|
|
222
|
+
if (next[key] === void 0) {
|
|
223
|
+
next[key] = currentWidths[key];
|
|
224
|
+
hasChange = true;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
return hasChange ? next : prev;
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
const resizableColumns = (0, import_react.useMemo)(() => {
|
|
231
|
+
if (!resizable || !columns)
|
|
232
|
+
return columns;
|
|
233
|
+
return columns.map((col, index) => {
|
|
234
|
+
const key = col.key || col.dataIndex || `col-${index}`;
|
|
235
|
+
if (col.valueType === "option") {
|
|
236
|
+
return col;
|
|
237
|
+
}
|
|
238
|
+
const width = resizedWidths[key] ?? col.width;
|
|
239
|
+
const calculatedMinWidth = col.calculatedWidth || 0;
|
|
240
|
+
const autoMinWidth = minWidths[key] || 0;
|
|
241
|
+
const minWidth = Math.max(calculatedMinWidth, autoMinWidth);
|
|
242
|
+
return {
|
|
243
|
+
...col,
|
|
244
|
+
width,
|
|
245
|
+
// 应用调整后的宽度
|
|
246
|
+
onHeaderCell: (column) => ({
|
|
247
|
+
width,
|
|
248
|
+
// 传递给 ResizableTitle
|
|
249
|
+
minWidth,
|
|
250
|
+
onResize: handleResize(key),
|
|
251
|
+
onResizeStart: handleResizeStart,
|
|
252
|
+
onResizeStop: handleResizeStop(key),
|
|
253
|
+
"data-column-key": key,
|
|
254
|
+
// 用于在 DOM 中查找
|
|
255
|
+
...col.onHeaderCell ? col.onHeaderCell(column) : null
|
|
256
|
+
})
|
|
257
|
+
};
|
|
258
|
+
});
|
|
259
|
+
}, [columns, resizable, resizedWidths, handleResize, handleResizeStart, handleResizeStop]);
|
|
260
|
+
const components = (0, import_react.useMemo)(() => {
|
|
261
|
+
if (!resizable)
|
|
262
|
+
return void 0;
|
|
263
|
+
return {
|
|
264
|
+
header: {
|
|
265
|
+
cell: ResizableTitle
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
}, [resizable]);
|
|
269
|
+
return {
|
|
270
|
+
columns: resizableColumns,
|
|
271
|
+
components,
|
|
272
|
+
resizedWidths
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
276
|
+
0 && (module.exports = {
|
|
277
|
+
useResizableColumns
|
|
278
|
+
});
|
|
279
|
+
//# sourceMappingURL=useResizableColumns.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/creek-table/hooks/useResizableColumns.tsx"],
|
|
4
|
+
"sourcesContent": ["import { ProColumns } from '@ant-design/pro-components';\nimport { useMemoizedFn } from 'ahooks';\nimport { createStyles } from 'antd-style';\nimport classnames from 'classnames';\nimport React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';\nimport { Resizable, ResizeCallbackData } from 'react-resizable';\n\ninterface ResizableTitleProps extends React.HTMLAttributes<HTMLTableCellElement> {\n onResize?: (e: React.SyntheticEvent, data: ResizeCallbackData) => void;\n onResizeStart?: (e: React.SyntheticEvent, data: ResizeCallbackData) => void;\n onResizeStop?: (e: React.SyntheticEvent, data: ResizeCallbackData) => void;\n width?: number | string;\n minWidth?: number;\n}\n\n// 样式定义\nconst useStyles = createStyles(({ token }) => ({\n 'resizable-handle': {\n position: 'absolute',\n right: -5,\n bottom: 0,\n zIndex: 10,\n width: 10,\n height: '100%',\n cursor: 'col-resize',\n touchAction: 'none',\n userSelect: 'none',\n \n // 添加一个小竖线作为视觉提示\n '&::after': {\n content: '\"\"',\n position: 'absolute',\n top: 0,\n bottom: 0,\n left: '50%',\n width: 1,\n opacity: 0,\n transition: 'all 0.3s',\n transform: 'translateX(-50%)',\n },\n\n '&:hover::after': {\n opacity: 1,\n },\n\n '&:active::after': {\n opacity: 1,\n },\n },\n 'resizable-th': {\n position: 'relative',\n '&:hover .resizable-handle::after': {\n opacity: 0.5,\n },\n },\n}));\n\nconst ResizableTitle = (props: ResizableTitleProps) => {\n const { onResize, onResizeStart, onResizeStop, width, className, minWidth, ...restProps } = props;\n const { styles } = useStyles();\n\n // 2. 如果 width 不是数字,尝试测量(降级处理)\n const ref = useRef<HTMLTableCellElement>(null);\n const [realWidth, setRealWidth] = useState<number | undefined>(undefined);\n\n // 本地状态,用于控制拖动过程中的平滑更新\n // 初始化为 props.width (如果是数字) 或 undefined\n const [localWidth, setLocalWidth] = useState<number | undefined>(typeof width === 'number' ? width : undefined);\n const [isResizing, setIsResizing] = useState(false);\n\n // 当外部 width 变化且非拖动状态时,同步到内部\n useEffect(() => {\n if (!isResizing && typeof width === 'number') {\n setLocalWidth(width);\n }\n }, [width, isResizing]);\n\n useLayoutEffect(() => {\n if (ref.current) {\n const w = ref.current.getBoundingClientRect().width;\n setRealWidth(w);\n // 如果没有传入具体数字宽度,初始化 localWidth 为测量值\n if (typeof width !== 'number') {\n setLocalWidth(w);\n }\n }\n }, []); // 只在挂载时测量一次\n\n const handleResizeStart = (e: React.SyntheticEvent, data: ResizeCallbackData) => {\n setIsResizing(true);\n // 增加全局样式防止选中文字\n document.body.style.userSelect = 'none';\n document.body.style.cursor = 'col-resize';\n if (onResizeStart) {\n onResizeStart(e, data);\n }\n };\n\n const handleResizeStop = (e: React.SyntheticEvent, data: ResizeCallbackData) => {\n setIsResizing(false);\n document.body.style.userSelect = '';\n document.body.style.cursor = '';\n // 拖动结束时,确保最后一次更新传递出去\n if (onResizeStop) {\n onResizeStop(e, data);\n }\n };\n\n const handleResize = (e: React.SyntheticEvent, data: ResizeCallbackData) => {\n // 1. 立即更新本地状态,保证 handle 跟手\n setLocalWidth(data.size.width);\n \n // 2. 调用外部 onResize (可能会被节流)\n if (onResize) {\n onResize(e, data);\n }\n };\n\n // 1. 如果 width 是数字,直接使用,避免任何 state/effect 开销\n // 修改逻辑:只要有 localWidth 就使用 Resizable\n const currentWidth = localWidth ?? realWidth;\n\n if (typeof currentWidth === 'number' && onResize) {\n return (\n <Resizable\n width={currentWidth}\n height={0}\n minConstraints={[minWidth || 0, 0]}\n handle={\n <span\n className={classnames(styles['resizable-handle'], 'resizable-handle')}\n onClick={(e) => {\n e.stopPropagation();\n }}\n onMouseEnter={(e) => {\n // 鼠标进入 handle 时触发一次 onResizeStart,用于预先锁定其他列宽度\n // 这样可以避免在 onResizeStart (mousedown) 时触发重渲染导致 drag 失败\n if (onResizeStart) {\n // 构造一个假的 event 和 data,因为这里只需要触发锁定逻辑\n onResizeStart(e, { node: e.currentTarget, size: { width: currentWidth, height: 0 }, handle: 'e' as any });\n }\n }}\n />\n }\n onResize={handleResize}\n onResizeStart={handleResizeStart}\n onResizeStop={handleResizeStop}\n draggableOpts={{ enableUserSelectHack: false }} // 我们自己处理了 userSelect\n axis=\"x\"\n >\n <th {...restProps} className={classnames(className, styles['resizable-th'])} style={{ ...restProps.style, width: currentWidth }} />\n </Resizable>\n );\n }\n\n if (!onResize || !realWidth) {\n return <th {...restProps} className={className} ref={ref} />;\n }\n\n // Fallback (虽然逻辑上可能不需要了,保留以防万一)\n return (\n <Resizable\n width={realWidth}\n height={0}\n minConstraints={[minWidth || 0, 0]}\n handle={\n <span\n className={classnames(styles['resizable-handle'], 'resizable-handle')}\n onClick={(e) => {\n e.stopPropagation();\n }}\n onMouseEnter={(e) => {\n if (onResizeStart) {\n onResizeStart(e, { node: e.currentTarget, size: { width: realWidth, height: 0 }, handle: 'e' as any });\n }\n }}\n />\n }\n onResize={handleResize}\n onResizeStart={handleResizeStart}\n onResizeStop={handleResizeStop}\n draggableOpts={{ enableUserSelectHack: false }}\n axis=\"x\"\n >\n <th {...restProps} className={classnames(className, styles['resizable-th'])} style={{ ...restProps.style, width: realWidth }} />\n </Resizable>\n );\n};\n\nexport const useResizableColumns = <T, ValueType>(\n columns: ProColumns<T, ValueType>[] | undefined,\n resizable: boolean = true,\n resizedWidthsProp?: Record<string, number>,\n setResizedWidthsProp?: React.Dispatch<React.SetStateAction<Record<string, number>>>,\n tableRef?: React.RefObject<HTMLDivElement>,\n): { \n columns: ProColumns<T, ValueType>[] | undefined;\n components: { header: { cell: React.ComponentType<ResizableTitleProps> } } | undefined;\n resizedWidths: Record<string, number>;\n} => {\n // 存储用户手动调整的列宽\n const [internalResizedWidths, setInternalResizedWidths] = useState<Record<string, number>>({});\n // 存储列的初始自动计算宽度,作为最小宽度限制\n const [minWidths, setMinWidths] = useState<Record<string, number>>({});\n\n const resizedWidths = resizedWidthsProp || internalResizedWidths;\n const setResizedWidths = setResizedWidthsProp || setInternalResizedWidths;\n\n // 性能优化:Resize 过程中不更新 state,只在 Stop 时更新\n // handleResize 仅用于 potential future usage (e.g. events) or removed if not needed\n const handleResize = useMemoizedFn((key: string) => (_: React.SyntheticEvent, { size }: ResizeCallbackData) => {\n // Intentionally empty or minimal logic to avoid re-renders during drag\n // ResizableTitle handles visual updates locally\n });\n \n const handleResizeStop = useMemoizedFn((key: string) => (_: React.SyntheticEvent, { size }: ResizeCallbackData) => {\n setResizedWidths((prev) => ({\n ...prev,\n [key]: size.width,\n }));\n });\n\n const handleResizeStart = useMemoizedFn(() => {\n // 只有当 tableRef 存在时才能获取当前宽度\n if (!tableRef?.current) return;\n\n // 查找所有表头单元格\n const thElements = tableRef.current.querySelectorAll('th[data-column-key]');\n if (!thElements || thElements.length === 0) return;\n\n const currentWidths: Record<string, number> = {};\n thElements.forEach((th) => {\n const key = th.getAttribute('data-column-key');\n const width = th.getBoundingClientRect().width;\n if (key && width) {\n currentWidths[key] = width;\n }\n });\n\n setResizedWidths((prev) => {\n // 只有当之前的状态中缺少某些列的宽度时,才合并当前宽度\n // 这样可以避免覆盖用户已经调整过的值,同时填补未调整列的宽度\n // 实际上,我们希望一旦开始 resize,所有列都有明确的宽度\n const next = { ...currentWidths, ...prev };\n \n // 简单的浅比较,如果内容没变就不更新,避免重渲染\n const isSame = Object.keys(next).every(k => next[k] === prev[k]) && Object.keys(prev).length === Object.keys(next).length;\n if (isSame) return prev;\n\n return next;\n });\n\n // 记录初始宽度作为 minWidth\n setMinWidths((prev) => {\n const next = { ...prev };\n let hasChange = false;\n Object.keys(currentWidths).forEach((key) => {\n // 只有当没有记录该列的最小宽度时才记录\n // 这样可以确保 minWidth 始终是第一次捕获时的宽度(即 auto 宽度)\n if (next[key] === undefined) {\n next[key] = currentWidths[key];\n hasChange = true;\n }\n });\n return hasChange ? next : prev;\n });\n });\n\n const resizableColumns = useMemo(() => {\n if (!resizable || !columns) return columns;\n\n return columns.map((col, index) => {\n // 优先使用 key,如果没有则使用 dataIndex,如果都没有则使用 index\n const key = (col.key as string) || (col.dataIndex as string) || `col-${index}`;\n \n // 针对 valueType 为 'option' 的操作列,不启用 resizing\n if (col.valueType === 'option') {\n return col;\n }\n \n // 只有当存在 resizedWidths[key] 时才使用它,否则完全依赖外部传入的 col.width(即 useAutoWidthColumns 计算出的宽度)\n const width = resizedWidths[key] ?? col.width;\n\n // 从 col 中获取 calculatedWidth 作为 minWidth\n const calculatedMinWidth = (col as any).calculatedWidth || 0;\n // 使用捕获到的 auto 宽度作为最小宽度,如果没有则使用 0\n const autoMinWidth = minWidths[key] || 0;\n \n // 最终的 minWidth 取两者的最大值,确保至少是 auto 宽度\n const minWidth = Math.max(calculatedMinWidth, autoMinWidth);\n\n return {\n ...col,\n width, // 应用调整后的宽度\n onHeaderCell: (column: any) => ({\n width: width, // 传递给 ResizableTitle\n minWidth: minWidth,\n onResize: handleResize(key),\n onResizeStart: handleResizeStart,\n onResizeStop: handleResizeStop(key),\n 'data-column-key': key, // 用于在 DOM 中查找\n ...(col.onHeaderCell ? col.onHeaderCell(column) : null),\n }) as React.HTMLAttributes<HTMLElement>,\n };\n });\n }, [columns, resizable, resizedWidths, handleResize, handleResizeStart, handleResizeStop]);\n\n const components = useMemo(() => {\n if (!resizable) return undefined;\n\n return {\n header: {\n cell: ResizableTitle,\n },\n };\n }, [resizable]);\n\n return {\n columns: resizableColumns,\n components,\n resizedWidths,\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA8B;AAC9B,wBAA6B;AAC7B,wBAAuB;AACvB,mBAA6E;AAC7E,6BAA8C;AA4HpC;AAjHV,IAAM,gBAAY,gCAAa,CAAC,EAAE,MAAM,OAAO;AAAA,EAC7C,oBAAoB;AAAA,IAClB,UAAU;AAAA,IACV,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,YAAY;AAAA;AAAA,IAGZ,YAAY;AAAA,MACV,SAAS;AAAA,MACT,UAAU;AAAA,MACV,KAAK;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,WAAW;AAAA,IACb;AAAA,IAEA,kBAAkB;AAAA,MAChB,SAAS;AAAA,IACX;AAAA,IAEA,mBAAmB;AAAA,MACjB,SAAS;AAAA,IACX;AAAA,EACF;AAAA,EACA,gBAAgB;AAAA,IACd,UAAU;AAAA,IACV,oCAAoC;AAAA,MAClC,SAAS;AAAA,IACX;AAAA,EACF;AACF,EAAE;AAEF,IAAM,iBAAiB,CAAC,UAA+B;AACrD,QAAM,EAAE,UAAU,eAAe,cAAc,OAAO,WAAW,UAAU,GAAG,UAAU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;AAAA,EACH,GAAG,CAAC,SAAS,WAAW,eAAe,cAAc,mBAAmB,gBAAgB,CAAC;AAEzF,QAAM,iBAAa,sBAAQ,MAAM;AAC/B,QAAI,CAAC;AAAW,aAAO;AAEvB,WAAO;AAAA,MACL,QAAQ;AAAA,QACN,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF,GAAG,CAAC,SAAS,CAAC;AAEd,SAAO;AAAA,IACL,SAAS;AAAA,IACT;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["classnames"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/creek-table/hooks/useStatusColumns.tsx
|
|
20
|
+
var useStatusColumns_exports = {};
|
|
21
|
+
__export(useStatusColumns_exports, {
|
|
22
|
+
useStatusColumns: () => useStatusColumns
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useStatusColumns_exports);
|
|
25
|
+
var import_antd = require("antd");
|
|
26
|
+
var import_lodash = require("lodash");
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
29
|
+
var PRESET_COLORS = [
|
|
30
|
+
"blue",
|
|
31
|
+
"green",
|
|
32
|
+
"volcano",
|
|
33
|
+
"orange",
|
|
34
|
+
"gold",
|
|
35
|
+
"lime",
|
|
36
|
+
"cyan",
|
|
37
|
+
"geekblue",
|
|
38
|
+
"purple",
|
|
39
|
+
"magenta"
|
|
40
|
+
];
|
|
41
|
+
var SEMANTIC_STATUS_MAP = {
|
|
42
|
+
// Success / Green
|
|
43
|
+
success: "success",
|
|
44
|
+
ok: "success",
|
|
45
|
+
pass: "success",
|
|
46
|
+
complete: "success",
|
|
47
|
+
finish: "success",
|
|
48
|
+
online: "success",
|
|
49
|
+
active: "success",
|
|
50
|
+
enable: "success",
|
|
51
|
+
published: "success",
|
|
52
|
+
open: "success",
|
|
53
|
+
正常: "success",
|
|
54
|
+
成功: "success",
|
|
55
|
+
完成: "success",
|
|
56
|
+
通过: "success",
|
|
57
|
+
启用: "success",
|
|
58
|
+
在线: "success",
|
|
59
|
+
发布: "success",
|
|
60
|
+
开启: "success",
|
|
61
|
+
已发布: "success",
|
|
62
|
+
// Error / Red
|
|
63
|
+
fail: "error",
|
|
64
|
+
error: "error",
|
|
65
|
+
reject: "error",
|
|
66
|
+
stop: "error",
|
|
67
|
+
close: "error",
|
|
68
|
+
offline: "error",
|
|
69
|
+
disable: "error",
|
|
70
|
+
banned: "error",
|
|
71
|
+
exception: "error",
|
|
72
|
+
blocked: "error",
|
|
73
|
+
失败: "error",
|
|
74
|
+
错误: "error",
|
|
75
|
+
拒绝: "error",
|
|
76
|
+
停止: "error",
|
|
77
|
+
关闭: "error",
|
|
78
|
+
离线: "error",
|
|
79
|
+
禁用: "error",
|
|
80
|
+
异常: "error",
|
|
81
|
+
封禁: "error",
|
|
82
|
+
// Processing / Blue
|
|
83
|
+
process: "processing",
|
|
84
|
+
running: "processing",
|
|
85
|
+
pending: "processing",
|
|
86
|
+
waiting: "processing",
|
|
87
|
+
loading: "processing",
|
|
88
|
+
init: "processing",
|
|
89
|
+
doing: "processing",
|
|
90
|
+
进行中: "processing",
|
|
91
|
+
处理中: "processing",
|
|
92
|
+
等待: "processing",
|
|
93
|
+
加载: "processing",
|
|
94
|
+
初始化: "processing",
|
|
95
|
+
启动: "processing",
|
|
96
|
+
运行中: "processing",
|
|
97
|
+
// Warning / Warning
|
|
98
|
+
warn: "warning",
|
|
99
|
+
timeout: "warning",
|
|
100
|
+
expire: "warning",
|
|
101
|
+
risk: "warning",
|
|
102
|
+
abnormal: "warning",
|
|
103
|
+
警告: "warning",
|
|
104
|
+
超时: "warning",
|
|
105
|
+
过期: "warning",
|
|
106
|
+
风险: "warning",
|
|
107
|
+
// Default
|
|
108
|
+
default: "default",
|
|
109
|
+
normal: "default",
|
|
110
|
+
unknown: "default",
|
|
111
|
+
默认: "default",
|
|
112
|
+
未知: "default"
|
|
113
|
+
};
|
|
114
|
+
var inferStatusColor = (key, text) => {
|
|
115
|
+
const normalizedKey = String(key).toLowerCase();
|
|
116
|
+
const normalizedText = String(text).toLowerCase();
|
|
117
|
+
for (const keyword in SEMANTIC_STATUS_MAP) {
|
|
118
|
+
if (normalizedKey.includes(keyword)) {
|
|
119
|
+
return SEMANTIC_STATUS_MAP[keyword];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (const keyword in SEMANTIC_STATUS_MAP) {
|
|
123
|
+
if (normalizedText.includes(keyword)) {
|
|
124
|
+
return SEMANTIC_STATUS_MAP[keyword];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
let hash = 0;
|
|
128
|
+
for (let i = 0; i < normalizedKey.length; i++) {
|
|
129
|
+
hash = normalizedKey.charCodeAt(i) + ((hash << 5) - hash);
|
|
130
|
+
}
|
|
131
|
+
const index = Math.abs(hash) % PRESET_COLORS.length;
|
|
132
|
+
return PRESET_COLORS[index];
|
|
133
|
+
};
|
|
134
|
+
var useStatusColumns = (columns) => {
|
|
135
|
+
return (0, import_react.useMemo)(() => {
|
|
136
|
+
return columns == null ? void 0 : columns.map((col) => {
|
|
137
|
+
var _a;
|
|
138
|
+
if (col.render) {
|
|
139
|
+
return col;
|
|
140
|
+
}
|
|
141
|
+
if (!col.valueEnum) {
|
|
142
|
+
return col;
|
|
143
|
+
}
|
|
144
|
+
const statusRender = (_a = col.fieldProps) == null ? void 0 : _a.statusRender;
|
|
145
|
+
if (statusRender === "none") {
|
|
146
|
+
return col;
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
...col,
|
|
150
|
+
render: (dom, entity, index, action, schema) => {
|
|
151
|
+
const valueEnum = schema == null ? void 0 : schema.valueEnum;
|
|
152
|
+
if (!valueEnum) {
|
|
153
|
+
return dom;
|
|
154
|
+
}
|
|
155
|
+
const dataIndex = col.dataIndex || col.key;
|
|
156
|
+
const rawValue = typeof dataIndex === "string" || Array.isArray(dataIndex) ? (0, import_lodash.get)(entity, dataIndex) : void 0;
|
|
157
|
+
if (rawValue === void 0 || rawValue === null) {
|
|
158
|
+
return dom;
|
|
159
|
+
}
|
|
160
|
+
let enumItem = null;
|
|
161
|
+
if (valueEnum instanceof Map) {
|
|
162
|
+
enumItem = valueEnum.get(rawValue);
|
|
163
|
+
if (!enumItem && typeof rawValue === "number") {
|
|
164
|
+
enumItem = valueEnum.get(String(rawValue));
|
|
165
|
+
} else if (!enumItem && typeof rawValue === "string") {
|
|
166
|
+
enumItem = valueEnum.get(Number(rawValue));
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
enumItem = valueEnum[rawValue];
|
|
170
|
+
}
|
|
171
|
+
if (!enumItem) {
|
|
172
|
+
return dom;
|
|
173
|
+
}
|
|
174
|
+
if (enumItem.color && statusRender !== "badge") {
|
|
175
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tag, { color: enumItem.color, style: { margin: 0 }, children: enumItem.text || dom });
|
|
176
|
+
}
|
|
177
|
+
if (enumItem.status && statusRender !== "tag") {
|
|
178
|
+
const status = String(enumItem.status).toLowerCase();
|
|
179
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Badge, { status, text: enumItem.text || dom });
|
|
180
|
+
}
|
|
181
|
+
if (enumItem.status === null || enumItem.status === false) {
|
|
182
|
+
return dom;
|
|
183
|
+
}
|
|
184
|
+
const inferred = inferStatusColor(
|
|
185
|
+
rawValue,
|
|
186
|
+
enumItem.text || String(rawValue)
|
|
187
|
+
);
|
|
188
|
+
if (statusRender === "tag") {
|
|
189
|
+
let tagColor = inferred;
|
|
190
|
+
if (inferred === "processing")
|
|
191
|
+
tagColor = "blue";
|
|
192
|
+
if (inferred === "error")
|
|
193
|
+
tagColor = "error";
|
|
194
|
+
if (inferred === "success")
|
|
195
|
+
tagColor = "success";
|
|
196
|
+
if (inferred === "warning")
|
|
197
|
+
tagColor = "warning";
|
|
198
|
+
if (inferred === "default")
|
|
199
|
+
tagColor = "default";
|
|
200
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tag, { color: tagColor, style: { margin: 0 }, children: enumItem.text || dom });
|
|
201
|
+
}
|
|
202
|
+
if (["success", "processing", "error", "default", "warning"].includes(inferred)) {
|
|
203
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Badge, { status: inferred, text: enumItem.text || dom });
|
|
204
|
+
}
|
|
205
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Badge, { color: inferred, text: enumItem.text || dom });
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
});
|
|
209
|
+
}, [columns]);
|
|
210
|
+
};
|
|
211
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
212
|
+
0 && (module.exports = {
|
|
213
|
+
useStatusColumns
|
|
214
|
+
});
|
|
215
|
+
//# sourceMappingURL=useStatusColumns.js.map
|