@hanwenbo/x-web-pro-components 0.0.1
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/LICENSE +21 -0
- package/es/blocks/index.d.ts +1 -0
- package/es/blocks/index.js +2 -0
- package/es/blocks/shared.d.ts +24 -0
- package/es/blocks/shared.js +77 -0
- package/es/components/card/index.d.ts +82 -0
- package/es/components/card/index.js +361 -0
- package/es/components/descriptions/index.d.ts +31 -0
- package/es/components/descriptions/index.js +434 -0
- package/es/components/field/index.d.ts +75 -0
- package/es/components/field/index.js +761 -0
- package/es/components/form/captcha.d.ts +19 -0
- package/es/components/form/captcha.js +165 -0
- package/es/components/form/colorPicker.d.ts +7 -0
- package/es/components/form/colorPicker.js +73 -0
- package/es/components/form/fieldControls.d.ts +43 -0
- package/es/components/form/fieldControls.js +282 -0
- package/es/components/form/index.d.ts +285 -0
- package/es/components/form/index.js +2268 -0
- package/es/components/form/loginForm.d.ts +22 -0
- package/es/components/form/loginForm.js +159 -0
- package/es/components/form/schemaForm.d.ts +30 -0
- package/es/components/form/schemaForm.js +644 -0
- package/es/components/form/stepsForm.d.ts +26 -0
- package/es/components/form/stepsForm.js +183 -0
- package/es/components/form/uploadButton.d.ts +20 -0
- package/es/components/form/uploadButton.js +134 -0
- package/es/components/form/uploadDragger.d.ts +13 -0
- package/es/components/form/uploadDragger.js +144 -0
- package/es/components/index.d.ts +9 -0
- package/es/components/index.js +9 -0
- package/es/components/layout/components/Help/index.d.ts +72 -0
- package/es/components/layout/components/Help/index.js +350 -0
- package/es/components/layout/index.d.ts +182 -0
- package/es/components/layout/index.js +892 -0
- package/es/components/list/index.d.ts +80 -0
- package/es/components/list/index.js +431 -0
- package/es/components/provider/context.d.ts +7 -0
- package/es/components/provider/context.js +21 -0
- package/es/components/provider/index.d.ts +28 -0
- package/es/components/provider/index.js +117 -0
- package/es/components/provider/intl.d.ts +38 -0
- package/es/components/provider/intl.js +112 -0
- package/es/components/provider/types.d.ts +37 -0
- package/es/components/provider/types.js +1 -0
- package/es/components/provider/useStyle/index.d.ts +28 -0
- package/es/components/provider/useStyle/index.js +208 -0
- package/es/components/skeleton/index.d.ts +61 -0
- package/es/components/skeleton/index.js +388 -0
- package/es/components/table/dragSortTable.d.ts +8 -0
- package/es/components/table/dragSortTable.js +229 -0
- package/es/components/table/editableTable.d.ts +31 -0
- package/es/components/table/editableTable.js +507 -0
- package/es/components/table/index.d.ts +52 -0
- package/es/components/table/index.js +1554 -0
- package/es/components/table/listToolBar.d.ts +48 -0
- package/es/components/table/listToolBar.js +194 -0
- package/es/components/table/search.d.ts +5 -0
- package/es/components/table/search.js +13 -0
- package/es/index.d.ts +4 -0
- package/es/index.js +4 -0
- package/es/types.d.ts +219 -0
- package/es/types.js +1 -0
- package/es/utils/attachPropertiesToComponent.d.ts +1 -0
- package/es/utils/attachPropertiesToComponent.js +6 -0
- package/es/utils/getRequestParams.d.ts +19 -0
- package/es/utils/getRequestParams.js +57 -0
- package/es/utils/getTableListColumns.d.ts +20 -0
- package/es/utils/getTableListColumns.js +36 -0
- package/es/utils/index.d.ts +4 -0
- package/es/utils/index.js +4 -0
- package/es/utils/loading.d.ts +3 -0
- package/es/utils/loading.js +25 -0
- package/es/version.d.ts +2 -0
- package/es/version.js +2 -0
- package/lib/blocks/index.d.ts +1 -0
- package/lib/blocks/index.js +5 -0
- package/lib/blocks/shared.d.ts +24 -0
- package/lib/blocks/shared.js +83 -0
- package/lib/components/card/index.d.ts +82 -0
- package/lib/components/card/index.js +368 -0
- package/lib/components/descriptions/index.d.ts +31 -0
- package/lib/components/descriptions/index.js +440 -0
- package/lib/components/field/index.d.ts +75 -0
- package/lib/components/field/index.js +767 -0
- package/lib/components/form/captcha.d.ts +19 -0
- package/lib/components/form/captcha.js +172 -0
- package/lib/components/form/colorPicker.d.ts +7 -0
- package/lib/components/form/colorPicker.js +79 -0
- package/lib/components/form/fieldControls.d.ts +43 -0
- package/lib/components/form/fieldControls.js +288 -0
- package/lib/components/form/index.d.ts +285 -0
- package/lib/components/form/index.js +2332 -0
- package/lib/components/form/loginForm.d.ts +22 -0
- package/lib/components/form/loginForm.js +165 -0
- package/lib/components/form/schemaForm.d.ts +30 -0
- package/lib/components/form/schemaForm.js +651 -0
- package/lib/components/form/stepsForm.d.ts +26 -0
- package/lib/components/form/stepsForm.js +189 -0
- package/lib/components/form/uploadButton.d.ts +20 -0
- package/lib/components/form/uploadButton.js +141 -0
- package/lib/components/form/uploadDragger.d.ts +13 -0
- package/lib/components/form/uploadDragger.js +151 -0
- package/lib/components/index.d.ts +9 -0
- package/lib/components/index.js +104 -0
- package/lib/components/layout/components/Help/index.d.ts +72 -0
- package/lib/components/layout/components/Help/index.js +356 -0
- package/lib/components/layout/index.d.ts +182 -0
- package/lib/components/layout/index.js +930 -0
- package/lib/components/list/index.d.ts +80 -0
- package/lib/components/list/index.js +438 -0
- package/lib/components/provider/context.d.ts +7 -0
- package/lib/components/provider/context.js +27 -0
- package/lib/components/provider/index.d.ts +28 -0
- package/lib/components/provider/index.js +174 -0
- package/lib/components/provider/intl.d.ts +38 -0
- package/lib/components/provider/intl.js +118 -0
- package/lib/components/provider/types.d.ts +37 -0
- package/lib/components/provider/types.js +5 -0
- package/lib/components/provider/useStyle/index.d.ts +28 -0
- package/lib/components/provider/useStyle/index.js +217 -0
- package/lib/components/skeleton/index.d.ts +61 -0
- package/lib/components/skeleton/index.js +394 -0
- package/lib/components/table/dragSortTable.d.ts +8 -0
- package/lib/components/table/dragSortTable.js +236 -0
- package/lib/components/table/editableTable.d.ts +31 -0
- package/lib/components/table/editableTable.js +514 -0
- package/lib/components/table/index.d.ts +52 -0
- package/lib/components/table/index.js +1699 -0
- package/lib/components/table/listToolBar.d.ts +48 -0
- package/lib/components/table/listToolBar.js +200 -0
- package/lib/components/table/search.d.ts +5 -0
- package/lib/components/table/search.js +20 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +49 -0
- package/lib/types.d.ts +219 -0
- package/lib/types.js +5 -0
- package/lib/utils/attachPropertiesToComponent.d.ts +1 -0
- package/lib/utils/attachPropertiesToComponent.js +12 -0
- package/lib/utils/getRequestParams.d.ts +19 -0
- package/lib/utils/getRequestParams.js +63 -0
- package/lib/utils/getTableListColumns.d.ts +20 -0
- package/lib/utils/getTableListColumns.js +42 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +49 -0
- package/lib/utils/loading.d.ts +3 -0
- package/lib/utils/loading.js +31 -0
- package/lib/version.d.ts +2 -0
- package/lib/version.js +8 -0
- package/package.json +68 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.DragSortTable = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _lucideReact = require("lucide-react");
|
|
10
|
+
var _card = require("@hanwenbo/x-web-ui/card");
|
|
11
|
+
var _table = require("@hanwenbo/x-web-ui/table");
|
|
12
|
+
var _cn = require("@hanwenbo/x-web-ui/utils/cn");
|
|
13
|
+
var _field = require("../field");
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
var _excluded = ["rowKey", "dataSource", "columns", "dragSortKey", "onDataSourceChange", "onDragSortEnd", "headerTitle", "toolBarRender", "className"];
|
|
16
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
17
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
|
+
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
|
19
|
+
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; }
|
|
20
|
+
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; }
|
|
21
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
22
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
23
|
+
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); }
|
|
24
|
+
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; }
|
|
25
|
+
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; }
|
|
26
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
27
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
28
|
+
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; } }
|
|
29
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
30
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
31
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
32
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
33
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
34
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
35
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
36
|
+
var getValueByDataIndex = function getValueByDataIndex(record, dataIndex) {
|
|
37
|
+
if (!dataIndex) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
var path = Array.isArray(dataIndex) ? dataIndex : [dataIndex];
|
|
41
|
+
return path.reduce(function (current, key) {
|
|
42
|
+
return current == null ? current : current[key];
|
|
43
|
+
}, record);
|
|
44
|
+
};
|
|
45
|
+
var move = function move(list, from, to) {
|
|
46
|
+
var next = _toConsumableArray(list);
|
|
47
|
+
var _next$splice = next.splice(from, 1),
|
|
48
|
+
_next$splice2 = _slicedToArray(_next$splice, 1),
|
|
49
|
+
item = _next$splice2[0];
|
|
50
|
+
next.splice(to, 0, item);
|
|
51
|
+
return next;
|
|
52
|
+
};
|
|
53
|
+
var DragSortTable = exports.DragSortTable = function DragSortTable(_ref) {
|
|
54
|
+
var _ref$rowKey = _ref.rowKey,
|
|
55
|
+
rowKey = _ref$rowKey === void 0 ? 'id' : _ref$rowKey,
|
|
56
|
+
controlledDataSource = _ref.dataSource,
|
|
57
|
+
columns = _ref.columns,
|
|
58
|
+
dragSortKey = _ref.dragSortKey,
|
|
59
|
+
onDataSourceChange = _ref.onDataSourceChange,
|
|
60
|
+
onDragSortEnd = _ref.onDragSortEnd,
|
|
61
|
+
headerTitle = _ref.headerTitle,
|
|
62
|
+
toolBarRender = _ref.toolBarRender,
|
|
63
|
+
className = _ref.className,
|
|
64
|
+
tableProps = _objectWithoutProperties(_ref, _excluded);
|
|
65
|
+
var _useState = (0, _react.useState)(controlledDataSource || []),
|
|
66
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
67
|
+
rows = _useState2[0],
|
|
68
|
+
setRows = _useState2[1];
|
|
69
|
+
var _useState3 = (0, _react.useState)(null),
|
|
70
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
71
|
+
draggingKey = _useState4[0],
|
|
72
|
+
setDraggingKey = _useState4[1];
|
|
73
|
+
var _useState5 = (0, _react.useState)(null),
|
|
74
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
75
|
+
dragOverKey = _useState6[0],
|
|
76
|
+
setDragOverKey = _useState6[1];
|
|
77
|
+
(0, _react.useEffect)(function () {
|
|
78
|
+
setRows(controlledDataSource || []);
|
|
79
|
+
}, [controlledDataSource]);
|
|
80
|
+
var resolveRowKey = function resolveRowKey(record, index) {
|
|
81
|
+
var _rowKey;
|
|
82
|
+
return typeof rowKey === 'function' ? rowKey(record) : (_rowKey = record[rowKey]) !== null && _rowKey !== void 0 ? _rowKey : index;
|
|
83
|
+
};
|
|
84
|
+
var handleDrop = function handleDrop(targetKey) {
|
|
85
|
+
if (draggingKey == null || draggingKey === targetKey) {
|
|
86
|
+
setDragOverKey(null);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
var fromIndex = rows.findIndex(function (item, index) {
|
|
90
|
+
return resolveRowKey(item, index) === draggingKey;
|
|
91
|
+
});
|
|
92
|
+
var toIndex = rows.findIndex(function (item, index) {
|
|
93
|
+
return resolveRowKey(item, index) === targetKey;
|
|
94
|
+
});
|
|
95
|
+
if (fromIndex < 0 || toIndex < 0) {
|
|
96
|
+
setDragOverKey(null);
|
|
97
|
+
setDraggingKey(null);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
var nextRows = move(rows, fromIndex, toIndex);
|
|
101
|
+
if (!controlledDataSource) {
|
|
102
|
+
setRows(nextRows);
|
|
103
|
+
}
|
|
104
|
+
onDataSourceChange === null || onDataSourceChange === void 0 || onDataSourceChange(nextRows);
|
|
105
|
+
onDragSortEnd === null || onDragSortEnd === void 0 || onDragSortEnd(fromIndex, toIndex, nextRows);
|
|
106
|
+
setDragOverKey(null);
|
|
107
|
+
setDraggingKey(null);
|
|
108
|
+
};
|
|
109
|
+
var loading = (0, _react.useMemo)(function () {
|
|
110
|
+
var _tableProps$loading$s;
|
|
111
|
+
if (tableProps.loading == null) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
if (typeof tableProps.loading === 'boolean') {
|
|
115
|
+
return tableProps.loading;
|
|
116
|
+
}
|
|
117
|
+
var hasLoadingConfig = Object.keys(tableProps.loading).length > 0;
|
|
118
|
+
if (!hasLoadingConfig) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return _objectSpread(_objectSpread({}, tableProps.loading), {}, {
|
|
122
|
+
spinning: (_tableProps$loading$s = tableProps.loading.spinning) !== null && _tableProps$loading$s !== void 0 ? _tableProps$loading$s : true
|
|
123
|
+
});
|
|
124
|
+
}, [tableProps.loading]);
|
|
125
|
+
var tableColumns = (0, _react.useMemo)(function () {
|
|
126
|
+
var mappedColumns = columns.filter(function (column) {
|
|
127
|
+
return !column.hideInTable;
|
|
128
|
+
}).map(function (column) {
|
|
129
|
+
var _column$key, _column$dataIndex;
|
|
130
|
+
var columnKey = String((_column$key = column.key) !== null && _column$key !== void 0 ? _column$key : Array.isArray(column.dataIndex) ? column.dataIndex.join('.') : (_column$dataIndex = column.dataIndex) !== null && _column$dataIndex !== void 0 ? _column$dataIndex : '');
|
|
131
|
+
return _objectSpread(_objectSpread({}, column), {}, {
|
|
132
|
+
render: function render(value, record, index) {
|
|
133
|
+
var rawValue = getValueByDataIndex(record, column.dataIndex);
|
|
134
|
+
var nextValue = column.renderText ? column.renderText(rawValue, record, index) : rawValue;
|
|
135
|
+
var content = column.render ? column.render(value, record, index) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_field.ProField, {
|
|
136
|
+
text: nextValue,
|
|
137
|
+
valueType: column.valueType,
|
|
138
|
+
valueEnum: column.valueEnum
|
|
139
|
+
});
|
|
140
|
+
if (!dragSortKey || columnKey !== dragSortKey) {
|
|
141
|
+
return content;
|
|
142
|
+
}
|
|
143
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
144
|
+
className: "flex items-center gap-2",
|
|
145
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_lucideReact.GripVertical, {
|
|
146
|
+
className: "h-4 w-4 text-muted-foreground"
|
|
147
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
148
|
+
className: "min-w-0 flex-1",
|
|
149
|
+
children: content
|
|
150
|
+
})]
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
if (!dragSortKey && mappedColumns.length) {
|
|
156
|
+
var _mappedColumns = _toArray(mappedColumns),
|
|
157
|
+
first = _mappedColumns[0],
|
|
158
|
+
rest = _mappedColumns.slice(1);
|
|
159
|
+
return [_objectSpread(_objectSpread({}, first), {}, {
|
|
160
|
+
render: function render(value, record, index) {
|
|
161
|
+
var rawValue = getValueByDataIndex(record, first.dataIndex);
|
|
162
|
+
var nextValue = first.renderText ? first.renderText(rawValue, record, index) : rawValue;
|
|
163
|
+
var content = first.render ? first.render(value, record, index) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_field.ProField, {
|
|
164
|
+
text: nextValue,
|
|
165
|
+
valueType: first.valueType,
|
|
166
|
+
valueEnum: first.valueEnum
|
|
167
|
+
});
|
|
168
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
169
|
+
className: "flex items-center gap-2",
|
|
170
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_lucideReact.GripVertical, {
|
|
171
|
+
className: "h-4 w-4 text-muted-foreground"
|
|
172
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
173
|
+
className: "min-w-0 flex-1",
|
|
174
|
+
children: content
|
|
175
|
+
})]
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
})].concat(_toConsumableArray(rest));
|
|
179
|
+
}
|
|
180
|
+
return mappedColumns;
|
|
181
|
+
}, [columns, dragSortKey]);
|
|
182
|
+
var actions = toolBarRender === null || toolBarRender === void 0 ? void 0 : toolBarRender(undefined, []);
|
|
183
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_card.Card, {
|
|
184
|
+
className: (0, _cn.cn)('overflow-visible', className),
|
|
185
|
+
children: [headerTitle || actions !== null && actions !== void 0 && actions.length ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
186
|
+
className: "mb-4 flex flex-wrap items-center justify-between gap-3",
|
|
187
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
188
|
+
className: "text-lg text-foreground",
|
|
189
|
+
children: headerTitle
|
|
190
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
191
|
+
className: "flex flex-wrap items-center gap-2",
|
|
192
|
+
children: actions
|
|
193
|
+
})]
|
|
194
|
+
}) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(_table.Table, _objectSpread(_objectSpread({}, tableProps), {}, {
|
|
195
|
+
loading: loading,
|
|
196
|
+
rowKey: rowKey,
|
|
197
|
+
columns: tableColumns,
|
|
198
|
+
dataSource: rows,
|
|
199
|
+
rowClassName: function rowClassName(record, index) {
|
|
200
|
+
var _tableProps$rowClassN;
|
|
201
|
+
return (0, _cn.cn)(draggingKey === resolveRowKey(record) && 'opacity-50', dragOverKey === resolveRowKey(record) && 'ring-2 ring-primary/30', (_tableProps$rowClassN = tableProps.rowClassName) === null || _tableProps$rowClassN === void 0 ? void 0 : _tableProps$rowClassN.call(tableProps, record, index));
|
|
202
|
+
},
|
|
203
|
+
onRow: function onRow(record, index) {
|
|
204
|
+
var _tableProps$onRow;
|
|
205
|
+
return _objectSpread(_objectSpread({}, (_tableProps$onRow = tableProps.onRow) === null || _tableProps$onRow === void 0 ? void 0 : _tableProps$onRow.call(tableProps, record, index !== null && index !== void 0 ? index : 0)), {}, {
|
|
206
|
+
draggable: true,
|
|
207
|
+
'data-testid': "drag-row-".concat(resolveRowKey(record)),
|
|
208
|
+
onDragStart: function onDragStart(event) {
|
|
209
|
+
var _tableProps$onRow2, _tableProps$onRow2$on;
|
|
210
|
+
setDraggingKey(resolveRowKey(record));
|
|
211
|
+
(_tableProps$onRow2 = tableProps.onRow) === null || _tableProps$onRow2 === void 0 || (_tableProps$onRow2 = _tableProps$onRow2.call(tableProps, record, index !== null && index !== void 0 ? index : 0)) === null || _tableProps$onRow2 === void 0 || (_tableProps$onRow2$on = _tableProps$onRow2.onDragStart) === null || _tableProps$onRow2$on === void 0 || _tableProps$onRow2$on.call(_tableProps$onRow2, event);
|
|
212
|
+
},
|
|
213
|
+
onDragOver: function onDragOver(event) {
|
|
214
|
+
var _tableProps$onRow3, _tableProps$onRow3$on;
|
|
215
|
+
event.preventDefault();
|
|
216
|
+
setDragOverKey(resolveRowKey(record));
|
|
217
|
+
(_tableProps$onRow3 = tableProps.onRow) === null || _tableProps$onRow3 === void 0 || (_tableProps$onRow3 = _tableProps$onRow3.call(tableProps, record, index !== null && index !== void 0 ? index : 0)) === null || _tableProps$onRow3 === void 0 || (_tableProps$onRow3$on = _tableProps$onRow3.onDragOver) === null || _tableProps$onRow3$on === void 0 || _tableProps$onRow3$on.call(_tableProps$onRow3, event);
|
|
218
|
+
},
|
|
219
|
+
onDrop: function onDrop(event) {
|
|
220
|
+
var _tableProps$onRow4, _tableProps$onRow4$on;
|
|
221
|
+
event.preventDefault();
|
|
222
|
+
handleDrop(resolveRowKey(record));
|
|
223
|
+
(_tableProps$onRow4 = tableProps.onRow) === null || _tableProps$onRow4 === void 0 || (_tableProps$onRow4 = _tableProps$onRow4.call(tableProps, record, index !== null && index !== void 0 ? index : 0)) === null || _tableProps$onRow4 === void 0 || (_tableProps$onRow4$on = _tableProps$onRow4.onDrop) === null || _tableProps$onRow4$on === void 0 || _tableProps$onRow4$on.call(_tableProps$onRow4, event);
|
|
224
|
+
},
|
|
225
|
+
onDragEnd: function onDragEnd(event) {
|
|
226
|
+
var _tableProps$onRow5, _tableProps$onRow5$on;
|
|
227
|
+
setDraggingKey(null);
|
|
228
|
+
setDragOverKey(null);
|
|
229
|
+
(_tableProps$onRow5 = tableProps.onRow) === null || _tableProps$onRow5 === void 0 || (_tableProps$onRow5 = _tableProps$onRow5.call(tableProps, record, index !== null && index !== void 0 ? index : 0)) === null || _tableProps$onRow5 === void 0 || (_tableProps$onRow5$on = _tableProps$onRow5.onDragEnd) === null || _tableProps$onRow5$on === void 0 || _tableProps$onRow5$on.call(_tableProps$onRow5, event);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}))]
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
var _default = exports.default = DragSortTable;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ProTableProps } from '../../types';
|
|
3
|
+
declare type EditableType = 'single' | 'multiple';
|
|
4
|
+
export interface EditableTableAction<RecordType = any> {
|
|
5
|
+
save: () => void;
|
|
6
|
+
cancel: () => void;
|
|
7
|
+
delete: () => void;
|
|
8
|
+
edit: () => void;
|
|
9
|
+
record: RecordType;
|
|
10
|
+
}
|
|
11
|
+
export interface EditableConfig<RecordType = any> {
|
|
12
|
+
type?: EditableType;
|
|
13
|
+
editableKeys?: React.Key[];
|
|
14
|
+
onChange?: (editableKeys: React.Key[], editableRows: RecordType[]) => void;
|
|
15
|
+
onSave?: (key: React.Key, record: RecordType, originRow: RecordType, newLine?: boolean) => Promise<void> | void;
|
|
16
|
+
onDelete?: (key: React.Key, record: RecordType) => Promise<void> | void;
|
|
17
|
+
onCancel?: (key: React.Key, record: RecordType) => void;
|
|
18
|
+
onValuesChange?: (record: RecordType, dataSource: RecordType[]) => void;
|
|
19
|
+
actionRender?: (row: RecordType, action: EditableTableAction<RecordType>, defaultDom: React.ReactNode[]) => React.ReactNode[];
|
|
20
|
+
}
|
|
21
|
+
export interface RecordCreatorProps<RecordType = any> {
|
|
22
|
+
record: RecordType | (() => RecordType);
|
|
23
|
+
creatorButtonText?: React.ReactNode;
|
|
24
|
+
position?: 'top' | 'bottom';
|
|
25
|
+
}
|
|
26
|
+
export interface EditableTableProps<RecordType extends Record<string, any> = Record<string, any>> extends Omit<ProTableProps<RecordType>, 'request'> {
|
|
27
|
+
editable?: EditableConfig<RecordType> | false;
|
|
28
|
+
recordCreatorProps?: RecordCreatorProps<RecordType> | false;
|
|
29
|
+
}
|
|
30
|
+
export declare const EditableTable: <RecordType extends Record<string, any> = Record<string, any>>({ rowKey, columns, dataSource: controlledDataSource, editable, recordCreatorProps, headerTitle, toolBarRender, pagination, className, onDataSourceChange, ...tableProps }: EditableTableProps<RecordType>) => React.JSX.Element;
|
|
31
|
+
export default EditableTable;
|