@zhenliang/sheet 0.0.7 → 0.1.0
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/README.md +3 -2
- package/dist/core/config.js +1 -2
- package/dist/core/editor/cascaderEditor/index.js +14 -7
- package/dist/core/editor/dateEditor/index.d.ts +2 -1
- package/dist/core/editor/dateEditor/index.js +44 -36
- package/dist/core/editor/index.d.ts +1 -1
- package/dist/core/editor/index.js +2 -3
- package/dist/core/editor/numberEditor/index.d.ts +1 -1
- package/dist/core/editor/numberEditor/index.js +53 -5
- package/dist/core/editor/numberEditor/index.less +1 -0
- package/dist/core/editor/selectEditor/index.d.ts +1 -1
- package/dist/core/editor/selectEditor/index.js +34 -5
- package/dist/core/reducers/index.d.ts +1 -1
- package/dist/core/reducers/index.js +3 -2
- package/dist/core/reducers/keyboardReducer.js +2 -3
- package/dist/core/reducers/mouseReducer.js +1 -2
- package/dist/core/reducers/sideEffectReducer.js +61 -26
- package/dist/core/reducers/stateReducer.js +38 -9
- package/dist/core/sheet/Cell.js +37 -15
- package/dist/core/sheet/DataEditor.js +4 -2
- package/dist/core/sheet/DefaultCell.js +1 -2
- package/dist/core/sheet/DefaultRow.d.ts +1 -0
- package/dist/core/sheet/DefaultRow.js +5 -3
- package/dist/core/sheet/DefaultRowMapper.js +1 -2
- package/dist/core/sheet/DefaultShell.js +1 -2
- package/dist/core/sheet/Event.js +2 -3
- package/dist/core/sheet/ValueViewer.js +1 -2
- package/dist/core/sheet/index.js +60 -20
- package/dist/core/sheet/index.less +20 -11
- package/dist/core/sheet/useCellEvent.js +1 -2
- package/dist/core/sheet/useContextMenu.d.ts +1 -1
- package/dist/core/sheet/useContextMenu.js +2 -3
- package/dist/core/sheet/useKeyBoardEvent.js +15 -3
- package/dist/core/sheet/useMouseEvent.js +3 -4
- package/dist/core/sheet/useSelectVisible.d.ts +2 -0
- package/dist/core/sheet/useSelectVisible.js +48 -0
- package/dist/core/sheet/useVirtualList.d.ts +1 -1
- package/dist/core/sheet/useVirtualList.js +24 -12
- package/dist/core/shell/draggableShell/index.js +21 -13
- package/dist/core/shell/tableShell.js +9 -6
- package/dist/core/table/events.d.ts +15 -0
- package/dist/core/table/events.js +94 -0
- package/dist/core/table/index.js +91 -112
- package/dist/core/table/useGroupConfig.js +24 -7
- package/dist/core/table/useRowSelection.d.ts +2 -1
- package/dist/core/table/useRowSelection.js +1 -2
- package/dist/core/table/util.js +2 -3
- package/dist/core/util.d.ts +5 -2
- package/dist/core/util.js +97 -16
- package/dist/core/viewer/btnViewer/index.js +2 -3
- package/dist/core/viewer/cascaderViewer/index.d.ts +2 -0
- package/dist/core/viewer/cascaderViewer/index.js +11 -0
- package/dist/core/viewer/checkViewer/index.js +2 -3
- package/dist/core/viewer/editViewer/index.js +2 -3
- package/dist/core/viewer/groupViewer/index.js +5 -3
- package/dist/core/viewer/index.d.ts +1 -0
- package/dist/core/viewer/index.js +2 -2
- package/dist/core/viewer/selectorViewer/index.d.ts +2 -0
- package/dist/core/viewer/selectorViewer/index.js +12 -0
- package/dist/core/viewer/switchViewer/index.js +2 -3
- package/dist/example/antComponent.js +60 -14
- package/dist/example/basic.js +2 -3
- package/dist/example/ellipsis.js +1 -2
- package/dist/example/fixed.js +1 -2
- package/dist/example/group.js +42 -4
- package/dist/example/selection.js +2 -3
- package/dist/example/sheet.js +52 -16
- package/dist/example/valuationAnalyze.js +20 -18
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useEventBus.js +1 -2
- package/dist/hooks/useKeyboard.js +1 -2
- package/dist/hooks/useMiddlewareReducer.js +1 -2
- package/dist/hooks/useMouse.js +35 -20
- package/dist/hooks/useSetState.js +1 -2
- package/dist/hooks/useSheetEvent.js +1 -2
- package/dist/hooks/useWidthConfig.d.ts +4 -0
- package/dist/hooks/useWidthConfig.js +5 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -1
- package/dist/standardUtils/index.js +2 -3
- package/dist/type/index.js +1 -2
- package/dist/type/sheet.d.ts +14 -3
- package/dist/type/sheet.js +1 -2
- package/dist/type/sheetTable.d.ts +45 -16
- package/dist/type/sheetTable.js +1 -2
- package/package.json +1 -1
- package/dist/core/config.js.map +0 -1
- package/dist/core/editor/cascaderEditor/index.js.map +0 -1
- package/dist/core/editor/dateEditor/index.js.map +0 -1
- package/dist/core/editor/index.js.map +0 -1
- package/dist/core/editor/numberEditor/index.js.map +0 -1
- package/dist/core/editor/selectEditor/index.js.map +0 -1
- package/dist/core/reducers/index.js.map +0 -1
- package/dist/core/reducers/keyboardReducer.js.map +0 -1
- package/dist/core/reducers/mouseReducer.js.map +0 -1
- package/dist/core/reducers/sideEffectReducer.js.map +0 -1
- package/dist/core/reducers/stateReducer.js.map +0 -1
- package/dist/core/sheet/Cell.js.map +0 -1
- package/dist/core/sheet/DataEditor.js.map +0 -1
- package/dist/core/sheet/DefaultCell.js.map +0 -1
- package/dist/core/sheet/DefaultRow.js.map +0 -1
- package/dist/core/sheet/DefaultRowMapper.js.map +0 -1
- package/dist/core/sheet/DefaultShell.js.map +0 -1
- package/dist/core/sheet/Event.js.map +0 -1
- package/dist/core/sheet/ValueViewer.js.map +0 -1
- package/dist/core/sheet/index.js.map +0 -1
- package/dist/core/sheet/useCellEvent.js.map +0 -1
- package/dist/core/sheet/useContextMenu.js.map +0 -1
- package/dist/core/sheet/useKeyBoardEvent.js.map +0 -1
- package/dist/core/sheet/useMouseEvent.js.map +0 -1
- package/dist/core/sheet/useVirtualList.js.map +0 -1
- package/dist/core/shell/draggableShell/index.js.map +0 -1
- package/dist/core/shell/tableShell.js.map +0 -1
- package/dist/core/table/index.js.map +0 -1
- package/dist/core/table/useGroupConfig.js.map +0 -1
- package/dist/core/table/useRowSelection.js.map +0 -1
- package/dist/core/table/util.js.map +0 -1
- package/dist/core/util.js.map +0 -1
- package/dist/core/viewer/btnViewer/index.js.map +0 -1
- package/dist/core/viewer/checkViewer/index.js.map +0 -1
- package/dist/core/viewer/editViewer/index.js.map +0 -1
- package/dist/core/viewer/groupViewer/index.js.map +0 -1
- package/dist/core/viewer/index.js.map +0 -1
- package/dist/core/viewer/switchViewer/index.js.map +0 -1
- package/dist/example/antComponent.js.map +0 -1
- package/dist/example/basic.js.map +0 -1
- package/dist/example/ellipsis.js.map +0 -1
- package/dist/example/fixed.js.map +0 -1
- package/dist/example/group.js.map +0 -1
- package/dist/example/selection.js.map +0 -1
- package/dist/example/sheet.js.map +0 -1
- package/dist/example/valuationAnalyze.js.map +0 -1
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/useEventBus.js.map +0 -1
- package/dist/hooks/useKeyboard.js.map +0 -1
- package/dist/hooks/useMiddlewareReducer.js.map +0 -1
- package/dist/hooks/useMouse.js.map +0 -1
- package/dist/hooks/useSetState.js.map +0 -1
- package/dist/hooks/useSheetEvent.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/standardUtils/index.js.map +0 -1
- package/dist/type/index.js.map +0 -1
- package/dist/type/sheet.js.map +0 -1
- package/dist/type/sheetTable.js.map +0 -1
|
@@ -10,6 +10,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
10
10
|
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; }
|
|
11
11
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
12
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
|
+
import { SheetType } from "../..";
|
|
13
14
|
export var stateReducer = {
|
|
14
15
|
change: function change(state, payload) {
|
|
15
16
|
var _ref = payload,
|
|
@@ -51,15 +52,16 @@ export var stateReducer = {
|
|
|
51
52
|
_ref2$cell = _ref2.cell,
|
|
52
53
|
row = _ref2$cell.row,
|
|
53
54
|
col = _ref2$cell.col,
|
|
54
|
-
confirm = _ref2$cell.confirm
|
|
55
|
+
confirm = _ref2$cell.confirm,
|
|
56
|
+
id = _ref2$cell.id;
|
|
55
57
|
var history = _toConsumableArray(state.history || []);
|
|
56
58
|
var current = data === null || data === void 0 ? void 0 : (_data$row = data[row]) === null || _data$row === void 0 ? void 0 : _data$row[col].value;
|
|
57
|
-
console.log(history.length, current);
|
|
58
59
|
history.push({
|
|
59
60
|
changes: [{
|
|
60
61
|
row: row,
|
|
61
62
|
col: col,
|
|
62
|
-
value: current
|
|
63
|
+
value: current,
|
|
64
|
+
id: id
|
|
63
65
|
}],
|
|
64
66
|
type: 'Edit'
|
|
65
67
|
});
|
|
@@ -74,17 +76,44 @@ export var stateReducer = {
|
|
|
74
76
|
history: history
|
|
75
77
|
});
|
|
76
78
|
},
|
|
79
|
+
popHistory: function popHistory(state) {
|
|
80
|
+
var _state$history = state.history,
|
|
81
|
+
history = _state$history === void 0 ? [] : _state$history;
|
|
82
|
+
var newHistory = _toConsumableArray(history);
|
|
83
|
+
newHistory.pop();
|
|
84
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
85
|
+
history: newHistory
|
|
86
|
+
});
|
|
87
|
+
},
|
|
77
88
|
pushHistory: function pushHistory(state, payload) {
|
|
78
89
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
79
90
|
history: [].concat(_toConsumableArray(state.history || []), [payload])
|
|
80
91
|
});
|
|
81
92
|
},
|
|
93
|
+
select: function select(state, payload) {
|
|
94
|
+
var oldStart = state.start,
|
|
95
|
+
oldEnd = state.end;
|
|
96
|
+
var _ref3 = payload,
|
|
97
|
+
start = _ref3.start,
|
|
98
|
+
end = _ref3.end;
|
|
99
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
100
|
+
start: start,
|
|
101
|
+
end: end,
|
|
102
|
+
lastSelected: {
|
|
103
|
+
start: oldStart,
|
|
104
|
+
end: oldEnd
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
},
|
|
82
108
|
selectRow: function selectRow(state, payload) {
|
|
83
|
-
var _state$data4, _state$data4$, _state$data5
|
|
109
|
+
var _state$data4, _state$data4$, _state$data5, _state$data5$, _state$data6, _state$data6$;
|
|
84
110
|
var startCol = ((_state$data4 = state.data) === null || _state$data4 === void 0 ? void 0 : (_state$data4$ = _state$data4[0]) === null || _state$data4$ === void 0 ? void 0 : _state$data4$.findIndex(function (item) {
|
|
85
111
|
return !item.fixed;
|
|
86
112
|
})) || 0;
|
|
87
|
-
var endCol = (((_state$data5 = state.data) === null || _state$data5 === void 0 ? void 0 : _state$data5[0]
|
|
113
|
+
var endCol = (((_state$data5 = state.data) === null || _state$data5 === void 0 ? void 0 : (_state$data5$ = _state$data5[0]) === null || _state$data5$ === void 0 ? void 0 : _state$data5$.findIndex(function (item) {
|
|
114
|
+
return item.fixed === SheetType.CellAlign.right;
|
|
115
|
+
})) || ((_state$data6 = state.data) === null || _state$data6 === void 0 ? void 0 : (_state$data6$ = _state$data6[0]) === null || _state$data6$ === void 0 ? void 0 : _state$data6$.length) || 0) - 1;
|
|
116
|
+
// const endCol = (state.data?.[0].length || 0) - 1;
|
|
88
117
|
if (startCol >= 0 && endCol >= 0) {
|
|
89
118
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
90
119
|
start: {
|
|
@@ -118,8 +147,8 @@ export var stateReducer = {
|
|
|
118
147
|
clearSelectIfNotSingleRow: function clearSelectIfNotSingleRow(state) {
|
|
119
148
|
var start = state.start,
|
|
120
149
|
end = state.end;
|
|
121
|
-
if ((start === null || start === void 0 ? void 0 : start.row) === (end === null || end === void 0 ? void 0 : end.row)) {
|
|
122
|
-
return
|
|
150
|
+
if (!start || !end || (start === null || start === void 0 ? void 0 : start.row) === (end === null || end === void 0 ? void 0 : end.row)) {
|
|
151
|
+
return state;
|
|
123
152
|
}
|
|
124
153
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
125
154
|
start: undefined,
|
|
@@ -132,10 +161,10 @@ export var stateReducer = {
|
|
|
132
161
|
},
|
|
133
162
|
clearEdit: function clearEdit(state) {
|
|
134
163
|
var editing = state.editing;
|
|
164
|
+
if (!editing) return state;
|
|
135
165
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
136
166
|
editing: undefined,
|
|
137
167
|
lastEditing: editing
|
|
138
168
|
});
|
|
139
169
|
}
|
|
140
|
-
};
|
|
141
|
-
//# sourceMappingURL=stateReducer.js.map
|
|
170
|
+
};
|
package/dist/core/sheet/Cell.js
CHANGED
|
@@ -64,8 +64,13 @@ var Cell = function Cell(props) {
|
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
var onCellState = function onCellState(eventInfo) {
|
|
67
|
-
if (eventInfo.
|
|
68
|
-
|
|
67
|
+
if (eventInfo.editing === false && !eventInfo.confirm) {
|
|
68
|
+
// 退出编辑,重设数据
|
|
69
|
+
setValue(valueRef.current);
|
|
70
|
+
} else if (eventInfo.value && eventInfo.editing) {
|
|
71
|
+
var _cell$dataEditor, _cell$dataEditor2, _cell$dataEditor2$par;
|
|
72
|
+
// 单元格直接键盘编辑,设置为输入值
|
|
73
|
+
setValue((_cell$dataEditor = cell.dataEditor) !== null && _cell$dataEditor !== void 0 && _cell$dataEditor.parser ? cell === null || cell === void 0 ? void 0 : (_cell$dataEditor2 = cell.dataEditor) === null || _cell$dataEditor2 === void 0 ? void 0 : (_cell$dataEditor2$par = _cell$dataEditor2.parser) === null || _cell$dataEditor2$par === void 0 ? void 0 : _cell$dataEditor2$par.call(_cell$dataEditor2, eventInfo.value) : value);
|
|
69
74
|
}
|
|
70
75
|
setEventState(eventInfo);
|
|
71
76
|
};
|
|
@@ -87,28 +92,42 @@ var Cell = function Cell(props) {
|
|
|
87
92
|
confirm: false
|
|
88
93
|
});
|
|
89
94
|
if (value !== valueRef.current) {
|
|
90
|
-
|
|
95
|
+
var _cell$dataEditor3, _cell$dataEditor4, _cell$dataEditor4$che;
|
|
96
|
+
if (cell !== null && cell !== void 0 && (_cell$dataEditor3 = cell.dataEditor) !== null && _cell$dataEditor3 !== void 0 && _cell$dataEditor3.checker && !((_cell$dataEditor4 = cell.dataEditor) !== null && _cell$dataEditor4 !== void 0 && (_cell$dataEditor4$che = _cell$dataEditor4.checker) !== null && _cell$dataEditor4$che !== void 0 && _cell$dataEditor4$che.call(_cell$dataEditor4, value, cell.record))) {
|
|
97
|
+
setValue(valueRef.current);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
91
100
|
eventBus.emit('cell-change', {
|
|
92
101
|
row: row,
|
|
93
102
|
col: col,
|
|
103
|
+
id: cell.id,
|
|
94
104
|
value: value
|
|
105
|
+
// 没必要format value 已经是legal 的值了
|
|
106
|
+
// value: cell.dataEditor?.formatter
|
|
107
|
+
// ? cell.dataEditor.formatter?.(value)
|
|
108
|
+
// : value,
|
|
95
109
|
});
|
|
96
110
|
}
|
|
97
111
|
}
|
|
98
|
-
}, [confirm, eventBus, value]);
|
|
112
|
+
}, [confirm, eventBus, value, cell]);
|
|
99
113
|
var handleCommit = useCallback(function (value) {
|
|
114
|
+
var _cell$dataEditor5, _cell$dataEditor6, _cell$dataEditor6$che;
|
|
100
115
|
if (valueRef.current === value) {
|
|
101
116
|
return;
|
|
102
117
|
}
|
|
118
|
+
if (cell !== null && cell !== void 0 && (_cell$dataEditor5 = cell.dataEditor) !== null && _cell$dataEditor5 !== void 0 && _cell$dataEditor5.checker && !((_cell$dataEditor6 = cell.dataEditor) !== null && _cell$dataEditor6 !== void 0 && (_cell$dataEditor6$che = _cell$dataEditor6.checker) !== null && _cell$dataEditor6$che !== void 0 && _cell$dataEditor6$che.call(_cell$dataEditor6, value, cell.record))) {
|
|
119
|
+
setValue(valueRef.current);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
103
122
|
setValue(value);
|
|
104
|
-
console.log('handle omit');
|
|
105
123
|
eventBus.emit('cell-change', {
|
|
106
124
|
row: row,
|
|
107
125
|
col: col,
|
|
126
|
+
id: cell.id,
|
|
108
127
|
value: value,
|
|
109
128
|
confirm: true
|
|
110
129
|
});
|
|
111
|
-
}, [eventBus, valueRef]);
|
|
130
|
+
}, [eventBus, valueRef, cell]);
|
|
112
131
|
var renderEditor = function renderEditor(cel, r, col, editor, isEditing) {
|
|
113
132
|
if (isEditing) {
|
|
114
133
|
var Editor = cel.dataEditor || editor || DataEditor;
|
|
@@ -117,6 +136,7 @@ var Cell = function Cell(props) {
|
|
|
117
136
|
row: r,
|
|
118
137
|
col: col,
|
|
119
138
|
value: value,
|
|
139
|
+
record: cel.record,
|
|
120
140
|
onConfirm: handleCommit,
|
|
121
141
|
onChange: setValue
|
|
122
142
|
});
|
|
@@ -126,12 +146,15 @@ var Cell = function Cell(props) {
|
|
|
126
146
|
var renderViewer = function renderViewer(cel, r, col, valViewer) {
|
|
127
147
|
var Viewer = cell.valueViewer || valViewer || ValueViewer;
|
|
128
148
|
var val = renderValue(cell);
|
|
129
|
-
return /*#__PURE__*/_jsx(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
149
|
+
return /*#__PURE__*/_jsx("span", {
|
|
150
|
+
className: "value-viewer",
|
|
151
|
+
children: /*#__PURE__*/_jsx(Viewer, {
|
|
152
|
+
record: cell.record,
|
|
153
|
+
cell: cell,
|
|
154
|
+
row: row,
|
|
155
|
+
col: col,
|
|
156
|
+
value: val
|
|
157
|
+
})
|
|
135
158
|
});
|
|
136
159
|
};
|
|
137
160
|
var content = ((_cell$editable = cell.editable) !== null && _cell$editable !== void 0 ? _cell$editable : true) && editing ? renderEditor(cell, row, col, dataEditor, editing) : renderViewer(cell, row, col, valueViewer);
|
|
@@ -153,7 +176,6 @@ var Cell = function Cell(props) {
|
|
|
153
176
|
});
|
|
154
177
|
};
|
|
155
178
|
export default /*#__PURE__*/memo(Cell, function (pre, next) {
|
|
156
|
-
var shouldUpdate = pre.col === next.col && pre.row === next.row && pre.cell.value === next.cell.value && pre.cell.record === next.cell.record;
|
|
179
|
+
var shouldUpdate = pre.col === next.col && pre.row === next.row && pre.cell.value === next.cell.value && pre.cell.dataEditor === next.cell.dataEditor && pre.cell.record === next.cell.record;
|
|
157
180
|
return shouldUpdate;
|
|
158
|
-
});
|
|
159
|
-
//# sourceMappingURL=Cell.js.map
|
|
181
|
+
});
|
|
@@ -13,10 +13,12 @@ var DataEditor = function DataEditor(_ref) {
|
|
|
13
13
|
};
|
|
14
14
|
return /*#__PURE__*/_jsx("input", {
|
|
15
15
|
ref: inputRef,
|
|
16
|
+
onMouseDown: function onMouseDown(e) {
|
|
17
|
+
return e.stopPropagation();
|
|
18
|
+
},
|
|
16
19
|
className: "data-editor",
|
|
17
20
|
value: value,
|
|
18
21
|
onChange: handleChange
|
|
19
22
|
});
|
|
20
23
|
};
|
|
21
|
-
export default DataEditor;
|
|
22
|
-
//# sourceMappingURL=DataEditor.js.map
|
|
24
|
+
export default DataEditor;
|
|
@@ -3,7 +3,8 @@ import { groupConfigToGroupMap } from "../util";
|
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
var DefaultRow = function DefaultRow(_ref) {
|
|
5
5
|
var _groupMap$get, _groupMap$get2;
|
|
6
|
-
var
|
|
6
|
+
var rowClassName = _ref.rowClassName,
|
|
7
|
+
children = _ref.children,
|
|
7
8
|
row = _ref.row,
|
|
8
9
|
groupConfig = _ref.groupConfig;
|
|
9
10
|
var groupMap = useMemo(function () {
|
|
@@ -12,6 +13,7 @@ var DefaultRow = function DefaultRow(_ref) {
|
|
|
12
13
|
}, [groupConfig]);
|
|
13
14
|
if (groupMap.get(row) && !((_groupMap$get = groupMap.get(row)) !== null && _groupMap$get !== void 0 && _groupMap$get.isStart) && !((_groupMap$get2 = groupMap.get(row)) !== null && _groupMap$get2 !== void 0 && _groupMap$get2.isOpen)) {
|
|
14
15
|
return /*#__PURE__*/_jsx("tr", {
|
|
16
|
+
className: rowClassName,
|
|
15
17
|
style: {
|
|
16
18
|
display: 'none'
|
|
17
19
|
},
|
|
@@ -19,8 +21,8 @@ var DefaultRow = function DefaultRow(_ref) {
|
|
|
19
21
|
});
|
|
20
22
|
}
|
|
21
23
|
return /*#__PURE__*/_jsx("tr", {
|
|
24
|
+
className: rowClassName,
|
|
22
25
|
children: children
|
|
23
26
|
});
|
|
24
27
|
};
|
|
25
|
-
export default DefaultRow;
|
|
26
|
-
//# sourceMappingURL=DefaultRow.js.map
|
|
28
|
+
export default DefaultRow;
|
package/dist/core/sheet/Event.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useSheetEvent } from "
|
|
1
|
+
import { useSheetEvent } from "../..";
|
|
2
2
|
import { useEffect } from 'react';
|
|
3
3
|
export var SheetEvent = function SheetEvent(_ref) {
|
|
4
4
|
var handler = _ref.handler,
|
|
@@ -14,5 +14,4 @@ export var SheetEvent = function SheetEvent(_ref) {
|
|
|
14
14
|
};
|
|
15
15
|
}, [eventBus, handler, name]);
|
|
16
16
|
return null;
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=Event.js.map
|
|
17
|
+
};
|
package/dist/core/sheet/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
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; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1
7
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
8
|
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."); }
|
|
3
9
|
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); }
|
|
@@ -9,7 +15,8 @@ import ReduxLogger from 'redux-logger';
|
|
|
9
15
|
import ReduxThunk from 'redux-thunk';
|
|
10
16
|
import DefaultRow from "./DefaultRow";
|
|
11
17
|
import DefaultShell from "./DefaultShell";
|
|
12
|
-
import {
|
|
18
|
+
import { Button } from 'antd';
|
|
19
|
+
import { isNil, isNumber } from 'lodash';
|
|
13
20
|
import { SheetEventContext, useEventBus, useMiddlewareReducer } from "../../hooks";
|
|
14
21
|
import sheetReducer from "../reducers";
|
|
15
22
|
import { classNames, getRowHeight, rowToActualRow } from "../util";
|
|
@@ -19,11 +26,12 @@ import { useCellEvent } from "./useCellEvent";
|
|
|
19
26
|
import { useContextMenu } from "./useContextMenu";
|
|
20
27
|
import { useKeyBoardEvent } from "./useKeyBoardEvent";
|
|
21
28
|
import { useMouseEvent } from "./useMouseEvent";
|
|
29
|
+
import { useSelectVisible } from "./useSelectVisible";
|
|
22
30
|
import { useVirtualList } from "./useVirtualList";
|
|
23
31
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
32
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
25
33
|
var Sheet = function Sheet(props) {
|
|
26
|
-
var _state$data$length, _state$
|
|
34
|
+
var _state$data$length, _state$data3, _scroll$y, _scroll$x;
|
|
27
35
|
var _props$sheetInstance = props.sheetInstance,
|
|
28
36
|
sheetInstance = _props$sheetInstance === void 0 ? {
|
|
29
37
|
current: null
|
|
@@ -45,7 +53,9 @@ var Sheet = function Sheet(props) {
|
|
|
45
53
|
onContextMenu = props.onContextMenu,
|
|
46
54
|
rowClassName = props.rowClassName,
|
|
47
55
|
scroll = props.scroll,
|
|
48
|
-
children = props.children
|
|
56
|
+
children = props.children,
|
|
57
|
+
showBackEdit = props.showBackEdit,
|
|
58
|
+
backEditStyle = props.backEditStyle;
|
|
49
59
|
var sheetWrapperRef = useRef(null);
|
|
50
60
|
var contextMenuRef = useRef(null);
|
|
51
61
|
var eventBus = useEventBus();
|
|
@@ -63,17 +73,20 @@ var Sheet = function Sheet(props) {
|
|
|
63
73
|
useEffect(function () {
|
|
64
74
|
sheetInstance.current = {
|
|
65
75
|
zoomTo: function zoomTo(row) {
|
|
66
|
-
//
|
|
76
|
+
// 给定 row 回到行
|
|
77
|
+
// 不给定 row 默认回到编辑行和列
|
|
67
78
|
dispatch(function (d, getState) {
|
|
68
79
|
var _ref, _sheetWrapperRef$curr;
|
|
69
80
|
var _getState = getState(),
|
|
70
81
|
start = _getState.start,
|
|
71
82
|
groupConfig = _getState.groupConfig;
|
|
83
|
+
var container = sheetWrapperRef.current;
|
|
72
84
|
if (!start && isNil(row)) return;
|
|
73
85
|
var actual = rowToActualRow((_ref = row) !== null && _ref !== void 0 ? _ref : start === null || start === void 0 ? void 0 : start.row, groupConfig);
|
|
74
|
-
|
|
75
|
-
var
|
|
76
|
-
|
|
86
|
+
var rowHeight = getRowHeight(container);
|
|
87
|
+
var firstRowCell = container.querySelector("td.cell[data-col='".concat(start === null || start === void 0 ? void 0 : start.col, "']"));
|
|
88
|
+
var colPosition = firstRowCell ? firstRowCell.offsetLeft - firstRowCell.clientWidth : 0;
|
|
89
|
+
(_sheetWrapperRef$curr = sheetWrapperRef.current) === null || _sheetWrapperRef$curr === void 0 ? void 0 : _sheetWrapperRef$curr.scrollTo(isNumber(row) ? 0 : colPosition, rowHeight * actual);
|
|
77
90
|
});
|
|
78
91
|
},
|
|
79
92
|
pushToHistory: function pushToHistory(config) {
|
|
@@ -94,11 +107,21 @@ var Sheet = function Sheet(props) {
|
|
|
94
107
|
});
|
|
95
108
|
}
|
|
96
109
|
},
|
|
110
|
+
select: function select(props) {
|
|
111
|
+
dispatch({
|
|
112
|
+
type: 'select',
|
|
113
|
+
payload: props
|
|
114
|
+
});
|
|
115
|
+
},
|
|
97
116
|
popHistory: function popHistory() {
|
|
98
|
-
|
|
117
|
+
var history = state.history;
|
|
118
|
+
dispatch({
|
|
119
|
+
type: 'popHistory'
|
|
120
|
+
});
|
|
121
|
+
return history !== null && history !== void 0 && history.length ? history === null || history === void 0 ? void 0 : history[history.length - 1] : {};
|
|
99
122
|
}
|
|
100
123
|
};
|
|
101
|
-
}, [sheetWrapperRef.current]);
|
|
124
|
+
}, [sheetWrapperRef.current, state.history]);
|
|
102
125
|
useEffect(function () {
|
|
103
126
|
// 同步必要的状态
|
|
104
127
|
dispatch({
|
|
@@ -128,7 +151,7 @@ var Sheet = function Sheet(props) {
|
|
|
128
151
|
}, 1);
|
|
129
152
|
}
|
|
130
153
|
}, [state.editing, state.start]);
|
|
131
|
-
var _useVirtualList = useVirtualList(sheetWrapperRef, state.data, virtualized),
|
|
154
|
+
var _useVirtualList = useVirtualList(sheetWrapperRef, state.data, groupConfig, virtualized),
|
|
132
155
|
virtualStart = _useVirtualList.virtualStart,
|
|
133
156
|
virtualEnd = _useVirtualList.virtualEnd,
|
|
134
157
|
paddingTop = _useVirtualList.paddingTop,
|
|
@@ -142,21 +165,25 @@ var Sheet = function Sheet(props) {
|
|
|
142
165
|
});
|
|
143
166
|
}, [groupConfig]);
|
|
144
167
|
var rowElements = useMemo(function () {
|
|
145
|
-
var _state$data;
|
|
146
|
-
return state === null || state === void 0 ? void 0 : (_state$data = state.data) === null || _state$data === void 0 ? void 0 : _state$data.map(function (rowData
|
|
168
|
+
var _state$data, _state$data$slice;
|
|
169
|
+
return state === null || state === void 0 ? void 0 : (_state$data = state.data) === null || _state$data === void 0 ? void 0 : (_state$data$slice = _state$data.slice(virtualStart, virtualEnd)) === null || _state$data$slice === void 0 ? void 0 : _state$data$slice.map(function (rowData) {
|
|
170
|
+
var _state$data2, _rowData;
|
|
171
|
+
var row = (state === null || state === void 0 ? void 0 : (_state$data2 = state.data) === null || _state$data2 === void 0 ? void 0 : _state$data2.indexOf(rowData)) || 0;
|
|
172
|
+
var rowCN = rowClassName instanceof Function ? rowClassName === null || rowClassName === void 0 ? void 0 : rowClassName(rowData === null || rowData === void 0 ? void 0 : (_rowData = rowData[rowData.length - 1]) === null || _rowData === void 0 ? void 0 : _rowData.record, row) : rowClassName;
|
|
147
173
|
return /*#__PURE__*/_jsx(Row, {
|
|
148
174
|
row: row,
|
|
149
175
|
cells: rowData,
|
|
150
176
|
groupConfig: groupConfig,
|
|
151
|
-
rowClassName:
|
|
177
|
+
rowClassName: rowCN,
|
|
152
178
|
children: /*#__PURE__*/_jsx(DefaultRowMapper, {
|
|
153
179
|
rowData: rowData,
|
|
154
180
|
row: row
|
|
155
181
|
})
|
|
156
182
|
}, row);
|
|
157
183
|
});
|
|
158
|
-
}, [state.data, groupConfig]);
|
|
159
|
-
var memoHeight = Math.min(((_state$data$length = state === null || state === void 0 ? void 0 : (_state$
|
|
184
|
+
}, [state.data, groupConfig, virtualStart, virtualEnd, rowClassName]);
|
|
185
|
+
var memoHeight = Math.min(((_state$data$length = state === null || state === void 0 ? void 0 : (_state$data3 = state.data) === null || _state$data3 === void 0 ? void 0 : _state$data3.length) !== null && _state$data$length !== void 0 ? _state$data$length : 0) + 1, 10) * 42 + 43;
|
|
186
|
+
var startRowVisible = useSelectVisible(sheetWrapperRef, state.start);
|
|
160
187
|
return /*#__PURE__*/_jsx(SheetEventContext.Provider, {
|
|
161
188
|
value: eventBus,
|
|
162
189
|
children: /*#__PURE__*/_jsxs("span", {
|
|
@@ -175,7 +202,7 @@ var Sheet = function Sheet(props) {
|
|
|
175
202
|
paddingBottom: paddingTop,
|
|
176
203
|
display: 'block'
|
|
177
204
|
}
|
|
178
|
-
}), rowElements
|
|
205
|
+
}), rowElements, /*#__PURE__*/_jsx("tr", {
|
|
179
206
|
style: {
|
|
180
207
|
height: 0,
|
|
181
208
|
paddingBottom: paddingBottom,
|
|
@@ -192,12 +219,25 @@ var Sheet = function Sheet(props) {
|
|
|
192
219
|
cell: menu.cellPosition,
|
|
193
220
|
onContextMenu: onContextMenu
|
|
194
221
|
})
|
|
195
|
-
}) : null, /*#__PURE__*/
|
|
222
|
+
}) : null, /*#__PURE__*/_jsxs("div", {
|
|
196
223
|
className: "harvest-sheet-control",
|
|
197
|
-
children: children
|
|
224
|
+
children: [children, showBackEdit && !startRowVisible ? /*#__PURE__*/_jsx(Button, {
|
|
225
|
+
type: "dashed",
|
|
226
|
+
onClick: function onClick() {
|
|
227
|
+
var _sheetInstance$curren;
|
|
228
|
+
return sheetInstance === null || sheetInstance === void 0 ? void 0 : (_sheetInstance$curren = sheetInstance.current) === null || _sheetInstance$curren === void 0 ? void 0 : _sheetInstance$curren.zoomTo();
|
|
229
|
+
},
|
|
230
|
+
style: _objectSpread({
|
|
231
|
+
position: 'absolute',
|
|
232
|
+
zIndex: 4
|
|
233
|
+
}, !backEditStyle ? {
|
|
234
|
+
top: 0,
|
|
235
|
+
right: 0
|
|
236
|
+
} : backEditStyle),
|
|
237
|
+
children: "\u56DE\u5230\u7F16\u8F91\u884C"
|
|
238
|
+
}) : null]
|
|
198
239
|
})]
|
|
199
240
|
})
|
|
200
241
|
});
|
|
201
242
|
};
|
|
202
|
-
export default Sheet;
|
|
203
|
-
//# sourceMappingURL=index.js.map
|
|
243
|
+
export default Sheet;
|
|
@@ -91,6 +91,12 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
|
|
|
91
91
|
box-shadow: var(--cell-fixed-box-shadow-left);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
|
|
95
|
+
&.fixed-right{
|
|
96
|
+
// transform: translateX(1px);
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
94
100
|
&.fixed-right::after{
|
|
95
101
|
position: absolute;
|
|
96
102
|
top: 0;
|
|
@@ -124,22 +130,32 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
|
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
.harvest-sheet-container .harvest-sheet .cell.selected-top{
|
|
127
|
-
border-top-color: var(--resizer)
|
|
133
|
+
border-top-color: var(--resizer);
|
|
128
134
|
}
|
|
129
135
|
|
|
130
136
|
.harvest-sheet-container .harvest-sheet .cell.selected-left{
|
|
131
|
-
border-left-color: var(--resizer)
|
|
137
|
+
border-left-color: var(--resizer);
|
|
132
138
|
}
|
|
133
139
|
|
|
134
140
|
.harvest-sheet-container .harvest-sheet .cell.selected-bottom{
|
|
135
|
-
border-bottom-color: var(--resizer)
|
|
141
|
+
border-bottom-color: var(--resizer);
|
|
136
142
|
}
|
|
137
143
|
|
|
138
144
|
.harvest-sheet-container .harvest-sheet .cell.selected-right{
|
|
139
|
-
border-right-color: var(--resizer)
|
|
145
|
+
border-right-color: var(--resizer);
|
|
140
146
|
}
|
|
141
147
|
|
|
142
148
|
|
|
149
|
+
.harvest-sheet-container .harvest-sheet .cell.sheet-control{
|
|
150
|
+
border-right: 1px solid transparent;
|
|
151
|
+
background: var(--cell-background-color) ;
|
|
152
|
+
color:var(--read-color);
|
|
153
|
+
|
|
154
|
+
&.read-only{
|
|
155
|
+
border-right: 1px solid var(--cell-title-background-color);
|
|
156
|
+
}
|
|
157
|
+
// position: relative !important;
|
|
158
|
+
}
|
|
143
159
|
|
|
144
160
|
.harvest-sheet-container .harvest-sheet .cell.read-only {
|
|
145
161
|
background: var(--cell-read-only-background-color);
|
|
@@ -147,12 +163,6 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
|
|
|
147
163
|
text-align: center;
|
|
148
164
|
}
|
|
149
165
|
|
|
150
|
-
.harvest-sheet-container .harvest-sheet .cell.sheet-control{
|
|
151
|
-
border-right: 1px solid transparent;
|
|
152
|
-
background: var(--cell-background-color) ;
|
|
153
|
-
color:var(--read-color);
|
|
154
|
-
// position: relative !important;
|
|
155
|
-
}
|
|
156
166
|
|
|
157
167
|
.harvest-sheet-container .harvest-sheet .cell-title.sheet-control{
|
|
158
168
|
border-right: 1px solid var(--cell-title-background-color);
|
|
@@ -263,7 +273,6 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
|
|
|
263
273
|
.harvest-sheet-container .harvest-sheet-control{
|
|
264
274
|
position: sticky;
|
|
265
275
|
z-index: 3;
|
|
266
|
-
height: 32px;
|
|
267
276
|
bottom: 0;
|
|
268
277
|
left: 0;
|
|
269
278
|
background-color: white;
|
|
@@ -10,7 +10,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
10
10
|
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; }
|
|
11
11
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
12
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
import { useSetState } from "
|
|
13
|
+
import { useSetState } from "../..";
|
|
14
14
|
import { useEffect } from 'react';
|
|
15
15
|
import { calcMenuPosition, extractDataRowAndCol, findParentTd } from "../util";
|
|
16
16
|
export var useContextMenu = function useContextMenu(dispatch, elementRef) {
|
|
@@ -83,5 +83,4 @@ export var useContextMenu = function useContextMenu(dispatch, elementRef) {
|
|
|
83
83
|
};
|
|
84
84
|
}, [elementRef.current, enableContextMenu]);
|
|
85
85
|
return _objectSpread({}, menuEvent);
|
|
86
|
-
};
|
|
87
|
-
//# sourceMappingURL=useContextMenu.js.map
|
|
86
|
+
};
|
|
@@ -1,12 +1,25 @@
|
|
|
1
|
-
import { useKeyBoard } from "
|
|
1
|
+
import { useKeyBoard } from "../..";
|
|
2
2
|
import { sideEffectReducer } from "../reducers/sideEffectReducer";
|
|
3
|
+
import { getRowHeight } from "../util";
|
|
3
4
|
export var useKeyBoardEvent = function useKeyBoardEvent(dispatch, elementRef) {
|
|
4
5
|
useKeyBoard({
|
|
5
6
|
move: function move(e, value) {
|
|
7
|
+
e.preventDefault();
|
|
6
8
|
dispatch({
|
|
7
9
|
type: 'move',
|
|
8
10
|
payload: value
|
|
9
11
|
});
|
|
12
|
+
// todo 横向滚动的处理
|
|
13
|
+
var _ref = value,
|
|
14
|
+
row = _ref.row;
|
|
15
|
+
if (Math.abs(row) !== 0) {
|
|
16
|
+
var _elementRef$current;
|
|
17
|
+
var rowHeight = getRowHeight(elementRef.current);
|
|
18
|
+
var itemHeight = rowHeight || 30;
|
|
19
|
+
elementRef === null || elementRef === void 0 ? void 0 : (_elementRef$current = elementRef.current) === null || _elementRef$current === void 0 ? void 0 : _elementRef$current.scrollBy({
|
|
20
|
+
top: itemHeight * row
|
|
21
|
+
});
|
|
22
|
+
}
|
|
10
23
|
},
|
|
11
24
|
escape: function escape() {
|
|
12
25
|
dispatch({
|
|
@@ -50,5 +63,4 @@ export var useKeyBoardEvent = function useKeyBoardEvent(dispatch, elementRef) {
|
|
|
50
63
|
dispatch(sideEffectReducer.delete);
|
|
51
64
|
}
|
|
52
65
|
}, elementRef.current);
|
|
53
|
-
};
|
|
54
|
-
//# sourceMappingURL=useKeyBoardEvent.js.map
|
|
66
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useMouse } from "
|
|
1
|
+
import { useMouse } from "../..";
|
|
2
2
|
import { useCallback, useRef } from 'react';
|
|
3
3
|
import { extractDataRowAndCol, findParentTd } from "../util";
|
|
4
4
|
var rowCount = 10; //每秒10行
|
|
5
|
-
var colCount = 5; //每秒
|
|
5
|
+
var colCount = 5; //每秒5列
|
|
6
6
|
|
|
7
7
|
export var useMouseEvent = function useMouseEvent(dispatch, elementRef) {
|
|
8
8
|
var animateRef = useRef(false);
|
|
@@ -295,5 +295,4 @@ export var useMouseEvent = function useMouseEvent(dispatch, elementRef) {
|
|
|
295
295
|
doubleClick: doubleClick,
|
|
296
296
|
loseFocus: loseFocus
|
|
297
297
|
}, elementRef.current);
|
|
298
|
-
};
|
|
299
|
-
//# sourceMappingURL=useMouseEvent.js.map
|
|
298
|
+
};
|