@teamias/rex-design 0.0.23 → 0.0.24

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,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { GetProps, Table } from 'antd';
3
- import { IDataCellItem, TGroupV2 } from '../data-cell/types';
4
- export declare const BaseTable: <T extends object = object>({ useDataCellRender, fields: outFields, fieldsConfig, fieldProps: outFieldProps, requestFields, requestFieldsUrl, requestFieldsParams, fieldPropsFn, indexColumn, extraColumns, onDataCellClick, onDataCellClickV2, scroll, rootClassName, customEmptyText, headerStyle: topHeaderStyle, ...otherProps }: IBaseTableProps<T>) => import("react/jsx-runtime").JSX.Element;
3
+ import { IDataCellItem, TDataCellConfig, TGroupV2 } from '../data-cell';
4
+ export declare const BaseTable: <T extends object = object>({ useDataCellRender, fields: outFields, fieldsConfig, fieldProps: outFieldProps, requestFields, requestFieldsUrl, requestFieldsParams, fieldPropsFn, indexColumn, extraColumns, onDataCellClick, onDataCellClickV2, scroll, rootClassName, customEmptyText, headerStyle: topHeaderStyle, useDataCellConfig, dataCellConfig, dataSource, ...otherProps }: IBaseTableProps<T>) => import("react/jsx-runtime").JSX.Element;
5
5
  /** 组件props */
6
6
  export interface IBaseTableProps<T extends object = object> extends Omit<TRawTableProps<T>, 'size' | 'bordered' | 'tableLayout' | 'scroll'> {
7
7
  /** @deprecated 使用 fieldsConfig */
@@ -29,6 +29,10 @@ export interface IBaseTableProps<T extends object = object> extends Omit<TRawTab
29
29
  * @default true
30
30
  */
31
31
  useDataCellRender?: boolean;
32
+ /** 是否使用 dataCell 配置,进行渲染 */
33
+ useDataCellConfig?: boolean;
34
+ /** dataCell 组件配置项, 通过这种方式来配置单元格内容,简化bff层的逻辑 */
35
+ dataCellConfig?: TDataCellConfig;
32
36
  /** dataCell组件中的点击回调 */
33
37
  onDataCellClick?: (item: IDataCellItem, dataIndex: string, record: T, index: number) => void;
34
38
  onDataCellClickV2?: (data: {
@@ -1,4 +1,4 @@
1
- var _excluded = ["useDataCellRender", "fields", "fieldsConfig", "fieldProps", "requestFields", "requestFieldsUrl", "requestFieldsParams", "fieldPropsFn", "indexColumn", "extraColumns", "onDataCellClick", "onDataCellClickV2", "scroll", "rootClassName", "customEmptyText", "headerStyle"];
1
+ var _excluded = ["useDataCellRender", "fields", "fieldsConfig", "fieldProps", "requestFields", "requestFieldsUrl", "requestFieldsParams", "fieldPropsFn", "indexColumn", "extraColumns", "onDataCellClick", "onDataCellClickV2", "scroll", "rootClassName", "customEmptyText", "headerStyle", "useDataCellConfig", "dataCellConfig", "dataSource"];
2
2
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -12,6 +12,7 @@ import { useDebounceEffect } from 'ahooks';
12
12
  import { ConfigProvider, Empty, Skeleton, Table } from 'antd';
13
13
  import classNames from 'classnames';
14
14
  import { useMemo } from 'react';
15
+ import { dataToDataCellData } from "../data-cell";
15
16
  import { DataCell } from "../data-cell/data-cell";
16
17
  import { BaseTableRow } from "./components/BaseTableRow";
17
18
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -35,6 +36,10 @@ export var BaseTable = function BaseTable(_ref) {
35
36
  rootClassName = _ref.rootClassName,
36
37
  customEmptyText = _ref.customEmptyText,
37
38
  topHeaderStyle = _ref.headerStyle,
39
+ useDataCellConfig = _ref.useDataCellConfig,
40
+ _ref$dataCellConfig = _ref.dataCellConfig,
41
+ dataCellConfig = _ref$dataCellConfig === void 0 ? [] : _ref$dataCellConfig,
42
+ dataSource = _ref.dataSource,
38
43
  otherProps = _objectWithoutProperties(_ref, _excluded);
39
44
  var responseConfig = useRequestFieldsConfig();
40
45
  var _useRexProConfigProvi = useRexProConfigProvider(),
@@ -60,6 +65,7 @@ export var BaseTable = function BaseTable(_ref) {
60
65
  }),
61
66
  loading = _useRequestFields.loading,
62
67
  fields = _useRequestFields.fields;
68
+ // const newDataSrouce = useMemo(() => useDataCellConfig ? dataToDataCellData(dataSource as [], dataCellConfig) as [] : dataSource, [])
63
69
 
64
70
  /** 表格点击事件 */
65
71
  var cellClick = function cellClick(data) {
@@ -272,6 +278,7 @@ export var BaseTable = function BaseTable(_ref) {
272
278
  })),
273
279
  rowKey: "key"
274
280
  }, otherProps), {}, {
281
+ dataSource: useDataCellConfig ? dataToDataCellData(dataSource, dataCellConfig) : dataSource,
275
282
  rootClassName: classNames(state.tableKey, rootClassName),
276
283
  onRow: function onRow() {
277
284
  return {
@@ -0,0 +1,2 @@
1
+ declare const _default: () => import("react/jsx-runtime").JSX.Element;
2
+ export default _default;
@@ -0,0 +1,67 @@
1
+ import { BaseTable } from "../base-table";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export default (function () {
4
+ var config = [{
5
+ field: 'goods_image',
6
+ items: [{
7
+ type: 'group-v2',
8
+ props: {
9
+ items: [{
10
+ type: 'text',
11
+ action: 'default',
12
+ value: '{{ dqewe }}'
13
+ }]
14
+ },
15
+ extra: {}
16
+ }],
17
+ key: '1763099807878ve0lbd1'
18
+ }, {
19
+ field: 'sku_size',
20
+ items: [{
21
+ type: 'group-v2',
22
+ props: {
23
+ items: [{
24
+ type: 'text',
25
+ action: 'default',
26
+ value: '{{ qweqwe }}'
27
+ }, {
28
+ type: 'text',
29
+ action: 'default',
30
+ value: '{{ eeeeeeqw }}'
31
+ }, {
32
+ type: 'text',
33
+ action: 'default',
34
+ value: 'eeeeeeqw'
35
+ }],
36
+ itemsDirection: 'row',
37
+ itemsGap: 4,
38
+ itemsSeparator: '/',
39
+ label: 'weqw'
40
+ },
41
+ extra: {}
42
+ }],
43
+ key: '1763099807878dft337k'
44
+ }];
45
+ var data = [{
46
+ qweqwe: 1,
47
+ dqewe: '图片1',
48
+ eeeeeeqw: 'false'
49
+ }, {
50
+ qweqwe: 2,
51
+ dqewe: '图片2',
52
+ eeeeeeqw: 'true'
53
+ }];
54
+ return /*#__PURE__*/_jsx(BaseTable, {
55
+ fieldsConfig: [{
56
+ title: 'sku_size',
57
+ dataIndex: 'sku_size'
58
+ }, {
59
+ title: 'goods_image',
60
+ dataIndex: 'goods_image'
61
+ }],
62
+ useDataCellRender: true,
63
+ useDataCellConfig: true,
64
+ dataCellConfig: config,
65
+ dataSource: data
66
+ });
67
+ });
@@ -1,4 +1,3 @@
1
1
  import React from 'react';
2
2
  import { BigInputProps } from './types';
3
3
  export declare const BigInput: React.FC<BigInputProps>;
4
- export default BigInput;
@@ -7,15 +7,15 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
7
7
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
8
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
9
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
- import React, { useState, useRef, useEffect, useCallback } from 'react';
11
10
  import Input from 'antd/es/input';
11
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { Fragment as _Fragment } from "react/jsx-runtime";
14
14
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
15
  var TextArea = Input.TextArea;
16
16
  export var BigInput = function BigInput(props) {
17
17
  var _props$placeholder = props.placeholder,
18
- placeholder = _props$placeholder === void 0 ? "请输入" : _props$placeholder,
18
+ placeholder = _props$placeholder === void 0 ? '请输入' : _props$placeholder,
19
19
  handleChange = props.onChange,
20
20
  handleBlur = props.onBlur,
21
21
  handleFocus = props.onFocus,
@@ -169,5 +169,4 @@ export var BigInput = function BigInput(props) {
169
169
  className: className
170
170
  }, "input")
171
171
  });
172
- };
173
- export default BigInput;
172
+ };
@@ -11,11 +11,11 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
11
11
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
12
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
13
  import { RexProConfigProvider } from "../../../context";
14
- import enUS from "antd/es/calendar/locale/en_US";
15
- import { crush } from "radash";
16
- import { createIntl } from "react-intl";
17
14
  import { BigInput } from "../../..";
18
- import { useState } from "react";
15
+ import enUS from 'antd/es/calendar/locale/en_US';
16
+ import { crush } from 'radash';
17
+ import { useState } from 'react';
18
+ import { createIntl } from 'react-intl';
19
19
  import { jsx as _jsx } from "react/jsx-runtime";
20
20
  import { jsxs as _jsxs } from "react/jsx-runtime";
21
21
  export default (function () {
@@ -0,0 +1,2 @@
1
+ declare const _default: () => import("react/jsx-runtime").JSX.Element;
2
+ export default _default;
@@ -0,0 +1,80 @@
1
+ import { DataCell } from "../data-cell";
2
+ import { dataToDataCellData } from "../utils";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ import { Fragment as _Fragment } from "react/jsx-runtime";
5
+ import { jsxs as _jsxs } from "react/jsx-runtime";
6
+ export default (function () {
7
+ var _dataSource$, _dataSource$2, _dataSource$3, _dataSource$4;
8
+ var config = [{
9
+ field: 'goods_image',
10
+ items: [{
11
+ type: 'group-v2',
12
+ props: {
13
+ items: [{
14
+ type: 'text',
15
+ action: 'default',
16
+ value: '{{ dqewe }}'
17
+ }]
18
+ },
19
+ extra: {}
20
+ }],
21
+ key: '1763099807878ve0lbd1'
22
+ }, {
23
+ field: 'sku_size',
24
+ items: [{
25
+ type: 'group-v2',
26
+ props: {
27
+ items: [{
28
+ type: 'text',
29
+ action: 'default',
30
+ value: '{{ qweqwe }}'
31
+ }, {
32
+ type: 'text',
33
+ action: 'default',
34
+ value: '{{ eeeeeeqw }}'
35
+ }, {
36
+ type: 'text',
37
+ action: 'default',
38
+ value: 'eeeeeeqw'
39
+ }],
40
+ itemsDirection: 'row',
41
+ itemsGap: 4,
42
+ itemsSeparator: '/',
43
+ label: 'weqw'
44
+ },
45
+ extra: {}
46
+ }],
47
+ key: '1763099807878dft337k'
48
+ }];
49
+ var data = [{
50
+ qweqwe: 1,
51
+ dqewe: '图片1',
52
+ eeeeeeqw: 'false'
53
+ }, {
54
+ qweqwe: 2,
55
+ dqewe: '图片2',
56
+ eeeeeeqw: 'true'
57
+ }];
58
+ var dataSource = dataToDataCellData(data, config) || [];
59
+ // console.log(dataSource);
60
+
61
+ return /*#__PURE__*/_jsxs(_Fragment, {
62
+ children: [/*#__PURE__*/_jsx("div", {
63
+ children: /*#__PURE__*/_jsx(DataCell, {
64
+ items: (_dataSource$ = dataSource[0]) === null || _dataSource$ === void 0 ? void 0 : _dataSource$.goods_image
65
+ })
66
+ }), /*#__PURE__*/_jsx("div", {
67
+ children: /*#__PURE__*/_jsx(DataCell, {
68
+ items: (_dataSource$2 = dataSource[0]) === null || _dataSource$2 === void 0 ? void 0 : _dataSource$2.sku_size
69
+ })
70
+ }), /*#__PURE__*/_jsx("div", {
71
+ children: /*#__PURE__*/_jsx(DataCell, {
72
+ items: (_dataSource$3 = dataSource[1]) === null || _dataSource$3 === void 0 ? void 0 : _dataSource$3.goods_image
73
+ })
74
+ }), /*#__PURE__*/_jsx("div", {
75
+ children: /*#__PURE__*/_jsx(DataCell, {
76
+ items: (_dataSource$4 = dataSource[1]) === null || _dataSource$4 === void 0 ? void 0 : _dataSource$4.sku_size
77
+ })
78
+ })]
79
+ });
80
+ });
@@ -1,2 +1,3 @@
1
1
  export * from './data-cell';
2
2
  export * from './types';
3
+ export * from './utils';
@@ -1,2 +1,3 @@
1
1
  export * from "./data-cell";
2
- export * from "./types";
2
+ export * from "./types";
3
+ export * from "./utils";
@@ -190,3 +190,9 @@ export type TCellActionExtend = {
190
190
  };
191
191
  /** 支持配置的展示类型 */
192
192
  export type TDataCellType = 'text' | 'link' | 'tag' | 'link-group' | 'img' | 'icon' | 'group' | 'group-v2';
193
+ /** 数据单元格配置 */
194
+ export type TDataCellConfig = Array<{
195
+ field: string;
196
+ key: string;
197
+ items: Array<TGroupV2>;
198
+ }>;
@@ -0,0 +1,3 @@
1
+ import { TDataCellConfig } from '../types';
2
+ /** 将 普通数据 转 dataCell 数据 */
3
+ export declare const dataToDataCellData: (oldDataSource?: Record<string, any>[], config?: TDataCellConfig) => Record<string, any>[] | undefined;
@@ -0,0 +1,68 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ import { get } from 'radash';
3
+ // 缓存编译后的正则表达式
4
+ var TEMPLATE_REGEX = /"{{\s*(.+?)\s*}}"/g;
5
+
6
+ // 缓存字符串转义函数
7
+ var escapeString = function escapeString(str) {
8
+ // 使用更高效的替换方式
9
+ var result = '';
10
+ for (var i = 0; i < str.length; i++) {
11
+ var char = str[i];
12
+ if (char === '\\') result += '\\\\';else if (char === '"') result += '\\"';else result += char;
13
+ }
14
+ return result;
15
+ };
16
+
17
+ // 提取替换逻辑为独立函数,避免重复创建
18
+ var replaceTemplate = function replaceTemplate(item) {
19
+ return function (rawStr, matchKey) {
20
+ var trimmedKey = matchKey.trim();
21
+ var newVal = get(item, trimmedKey);
22
+ if (typeof newVal === 'string') {
23
+ return "\"".concat(escapeString(newVal), "\"");
24
+ } else if (typeof newVal === 'number' || typeof newVal === 'boolean') {
25
+ return String(newVal);
26
+ } else if (newVal === null || typeof newVal === 'undefined') {
27
+ return 'null';
28
+ } else if (_typeof(newVal) === 'object') {
29
+ return JSON.stringify(newVal);
30
+ }
31
+ return rawStr;
32
+ };
33
+ };
34
+
35
+ /** 将 普通数据 转 dataCell 数据 */
36
+ export var dataToDataCellData = function dataToDataCellData(oldDataSource, config) {
37
+ if (!Array.isArray(config) || !config.length) return oldDataSource;
38
+ if (!oldDataSource || !oldDataSource.length) return oldDataSource;
39
+ var newDataSource = [];
40
+
41
+ // 预编译配置的 JSON 字符串,避免重复 stringify
42
+ var preCompiledConfigs = config.map(function (cfg) {
43
+ return {
44
+ field: cfg.field,
45
+ items: cfg.items,
46
+ jsonStr: JSON.stringify(cfg.items)
47
+ };
48
+ });
49
+ oldDataSource.forEach(function (item) {
50
+ // 保留原始数据的所有字段
51
+ var newItem = {
52
+ _raw: item
53
+ };
54
+ var replacer = replaceTemplate(item);
55
+ preCompiledConfigs.forEach(function (config) {
56
+ // 重置正则表达式的 lastIndex(虽然使用了 g 标志,但 replace 会自动处理)
57
+ var newJson = config.jsonStr.replace(TEMPLATE_REGEX, replacer);
58
+ try {
59
+ newItem[config.field] = JSON.parse(newJson);
60
+ } catch (error) {
61
+ console.error("DataCell config parse error for key \"".concat(config.field, "\":"), error, '\nJSON:', newJson);
62
+ newItem[config.field] = config.items;
63
+ }
64
+ });
65
+ newDataSource.push(newItem);
66
+ });
67
+ return newDataSource;
68
+ };
@@ -3,9 +3,9 @@ export * from './base-descriptions';
3
3
  export * from './base-form';
4
4
  export * from './base-list-table';
5
5
  export * from './base-table';
6
+ export * from './big-input';
6
7
  export * from './data-cell';
7
8
  export * from './icons';
8
9
  export * from './media-viewer';
9
10
  export * from './tiptap-editor';
10
- export * from './big-input';
11
11
  export * from './upload-plus';
@@ -3,9 +3,9 @@ export * from "./base-descriptions";
3
3
  export * from "./base-form";
4
4
  export * from "./base-list-table";
5
5
  export * from "./base-table";
6
+ export * from "./big-input";
6
7
  export * from "./data-cell";
7
8
  export * from "./icons";
8
9
  export * from "./media-viewer";
9
10
  export * from "./tiptap-editor";
10
- export * from "./big-input";
11
11
  export * from "./upload-plus";
@@ -5,11 +5,11 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
7
  import { RexProConfigProvider } from "../../../context";
8
- import enUS from "antd/es/calendar/locale/en_US";
9
- import { crush } from "radash";
10
- import { createIntl } from "react-intl";
11
- import UploadPlus from "../upload-plus";
12
- import { Card, message } from "antd";
8
+ import { Card, message } from 'antd';
9
+ import enUS from 'antd/es/calendar/locale/en_US';
10
+ import { crush } from 'radash';
11
+ import { createIntl } from 'react-intl';
12
+ import { UploadPlus } from "../../..";
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
15
  export default (function () {
@@ -1,2 +1,2 @@
1
- export * from './upload-plus';
2
1
  export * from './types';
2
+ export * from './upload-plus';
@@ -1,2 +1,2 @@
1
- export * from "./upload-plus";
2
- export * from "./types";
1
+ export * from "./types";
2
+ export * from "./upload-plus";
@@ -1,3 +1,2 @@
1
1
  import { UploadProps } from 'antd';
2
- export interface UploadPlusProps extends UploadProps {
3
- }
2
+ export type UploadPlusProps = UploadProps;
@@ -1,3 +1,2 @@
1
1
  import React from 'react';
2
- declare const App: React.FC;
3
- export default App;
2
+ export declare const UploadPlus: React.FC;
@@ -10,7 +10,7 @@ import React from 'react';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { jsxs as _jsxs } from "react/jsx-runtime";
12
12
  var Dragger = Upload.Dragger;
13
- var App = function App(props) {
13
+ export var UploadPlus = function UploadPlus(props) {
14
14
  var draggerRef = React.useRef(null);
15
15
 
16
16
  // 处理粘贴事件
@@ -79,5 +79,4 @@ var App = function App(props) {
79
79
  })]
80
80
  }))
81
81
  });
82
- };
83
- export default App;
82
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamias/rex-design",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",