@ishibashi0112/spreadsheet-grid-core 0.44.0 → 0.46.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../utils/permissions.cjs"),t=require("../logic/detailRow.cjs"),n=require("../model/gridActions.cjs"),r=require("../logic/geometry.cjs"),i=require("../logic/editorValues.cjs"),a=require("../logic/validation.cjs");var o=()=>{let
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../utils/permissions.cjs"),t=require("../logic/detailRow.cjs"),n=require("../model/gridActions.cjs"),r=require("../logic/geometry.cjs"),i=require("../logic/editorValues.cjs"),a=require("../logic/validation.cjs");var o=(e,t)=>t.activeCell!==e.activeCell||t.selection!==e.selection,s=e=>{if(t.isFocusInsideDetailCard())return!1;let n=e.ownerDocument,r=n.activeElement;return r===null||r===n.body||r===n.documentElement||e.contains(r)},c=()=>{let t=null,c=null,l=(e,t)=>{let n=e.visibleColumns[t.col];return!n||t.row<0||t.row>=e.rowModel.getRowCount()||e.rowModel.getRow(t.row)===void 0?null:{rowKey:e.rowModel.getRowKey(t.row),columnKey:n.key}},u=(e,t)=>{let n=e.visibleColumns.findIndex(e=>e.key===t.columnKey);if(n<0)return null;let r=e.rowModel.getRowCount();for(let i=0;i<r;i+=1)if(e.rowModel.getRow(i)!==void 0&&Object.is(e.rowModel.getRowKey(i),t.rowKey))return{row:i,col:n};return null},d=e=>{t=e;let r=e.uiState.editingCell;if(!r){c=null;return}let i=l(e,r);if(c!==null&&i!==null&&Object.is(i.rowKey,c.rowKey)&&i.columnKey===c.columnKey){c={...c,cell:r};return}let a=c!==null&&c.cell.row===r.row&&c.cell.col===r.col;if(c===null||!a){c=i?{...i,cell:r}:null;return}let o=u(e,c);o?(c={...c,cell:o},e.dispatch(n.gridActions.startEdit(o))):(c=null,e.dispatch(n.gridActions.stopEdit()))},f=e=>{t!==null&&(t.dispatch(n.gridActions.startSelection(e)),t.dispatch(n.gridActions.endSelection()),t.dispatch(n.gridActions.activateCell(e)))},p=(e,r)=>{t!==null&&(t.setEditorInitialValue(r),t.dispatch(n.gridActions.startEdit(e)))},m=(e,n=null)=>{let i=t;i!==null&&requestAnimationFrame(()=>{let a=i.gridRootRef.current;if(a!==null&&s(a)&&a.focus(),e!==null&&t!==null&&!(n!==null&&o(n,t.uiState))){let n=t.rowModel.getRowCount(),i=t.visibleColumns.length;f({row:r.clamp(e.row,0,Math.max(n-1,0)),col:r.clamp(e.col,0,Math.max(i-1,0))})}i.editorActionGuardRef.current=!1})};return{update:d,activateSingleCell:f,startEditWithValue:p,commitEdit:(r,o)=>{if(t===null)return{status:`noop`};let{uiState:s,visibleColumns:c,rowModel:l,rows:u,applyServerSideCellEdits:d,onRowsChange:f,dispatch:p,editorActionGuardRef:h}=t;if(h.current||!s.editingCell)return{status:`noop`};let g=s.editingCell,_=o===`down`?{row:g.row+1,col:g.col}:o===`up`?{row:g.row-1,col:g.col}:o===`right`?{row:g.row,col:g.col+1}:o===`left`?{row:g.row,col:g.col-1}:g,v=c[g.col],y=l.getSourceIndex(g.row),b=d?l.getRow(g.row):u[y];if(!v||!b)return p(n.gridActions.stopEdit()),{status:`noop`};if(!e.isCellEditable({readOnly:t.readOnly,canEditCell:t.canEditCell},g.row,g.col,b,v))return h.current=!0,p(n.gridActions.stopEdit()),m(null),{status:`noop`};if(d){let e=i.parseCommittedValue(v,r,b),t=a.decideCellWrite(v,b,e);if(t.action===`reject`)return{status:`rejected`,message:t.message};d([{viewIndex:g.row,column:v,value:e}])}else if(f){let e=i.parseCommittedValue(v,r,b),t=a.decideCellWrite(v,b,e);if(t.action===`reject`)return{status:`rejected`,message:t.message};f(i.writeRowsCell(u,y,v,e))}return h.current=!0,m(_,o===void 0?{activeCell:s.activeCell,selection:s.selection}:null),p(n.gridActions.stopEdit()),{status:`committed`}},cancelEdit:()=>{t===null||t.editorActionGuardRef.current||(t.editorActionGuardRef.current=!0,t.dispatch(n.gridActions.stopEdit()),m(null))}}};exports.createEditController=c;
|
|
@@ -5,14 +5,18 @@ import { clamp as r } from "../logic/geometry.js";
|
|
|
5
5
|
import { parseCommittedValue as i, writeRowsCell as a } from "../logic/editorValues.js";
|
|
6
6
|
import { decideCellWrite as o } from "../logic/validation.js";
|
|
7
7
|
//#region src/controllers/editController.ts
|
|
8
|
-
var s = () => {
|
|
9
|
-
|
|
8
|
+
var s = (e, t) => t.activeCell !== e.activeCell || t.selection !== e.selection, c = (e) => {
|
|
9
|
+
if (t()) return !1;
|
|
10
|
+
let n = e.ownerDocument, r = n.activeElement;
|
|
11
|
+
return r === null || r === n.body || r === n.documentElement || e.contains(r);
|
|
12
|
+
}, l = () => {
|
|
13
|
+
let t = null, l = null, u = (e, t) => {
|
|
10
14
|
let n = e.visibleColumns[t.col];
|
|
11
15
|
return !n || t.row < 0 || t.row >= e.rowModel.getRowCount() || e.rowModel.getRow(t.row) === void 0 ? null : {
|
|
12
16
|
rowKey: e.rowModel.getRowKey(t.row),
|
|
13
17
|
columnKey: n.key
|
|
14
18
|
};
|
|
15
|
-
},
|
|
19
|
+
}, d = (e, t) => {
|
|
16
20
|
let n = e.visibleColumns.findIndex((e) => e.key === t.columnKey);
|
|
17
21
|
if (n < 0) return null;
|
|
18
22
|
let r = e.rowModel.getRowCount();
|
|
@@ -21,82 +25,83 @@ var s = () => {
|
|
|
21
25
|
col: n
|
|
22
26
|
};
|
|
23
27
|
return null;
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
let
|
|
27
|
-
if (!
|
|
28
|
-
|
|
28
|
+
}, f = (e) => {
|
|
29
|
+
t = e;
|
|
30
|
+
let r = e.uiState.editingCell;
|
|
31
|
+
if (!r) {
|
|
32
|
+
l = null;
|
|
29
33
|
return;
|
|
30
34
|
}
|
|
31
|
-
let
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
...
|
|
35
|
-
cell:
|
|
35
|
+
let i = u(e, r);
|
|
36
|
+
if (l !== null && i !== null && Object.is(i.rowKey, l.rowKey) && i.columnKey === l.columnKey) {
|
|
37
|
+
l = {
|
|
38
|
+
...l,
|
|
39
|
+
cell: r
|
|
36
40
|
};
|
|
37
41
|
return;
|
|
38
42
|
}
|
|
39
|
-
let
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
...
|
|
43
|
-
cell:
|
|
43
|
+
let a = l !== null && l.cell.row === r.row && l.cell.col === r.col;
|
|
44
|
+
if (l === null || !a) {
|
|
45
|
+
l = i ? {
|
|
46
|
+
...i,
|
|
47
|
+
cell: r
|
|
44
48
|
} : null;
|
|
45
49
|
return;
|
|
46
50
|
}
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
...
|
|
50
|
-
cell:
|
|
51
|
-
}, e.dispatch(n.startEdit(
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
let
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
51
|
+
let o = d(e, l);
|
|
52
|
+
o ? (l = {
|
|
53
|
+
...l,
|
|
54
|
+
cell: o
|
|
55
|
+
}, e.dispatch(n.startEdit(o))) : (l = null, e.dispatch(n.stopEdit()));
|
|
56
|
+
}, p = (e) => {
|
|
57
|
+
t !== null && (t.dispatch(n.startSelection(e)), t.dispatch(n.endSelection()), t.dispatch(n.activateCell(e)));
|
|
58
|
+
}, m = (e, r) => {
|
|
59
|
+
t !== null && (t.setEditorInitialValue(r), t.dispatch(n.startEdit(e)));
|
|
60
|
+
}, h = (e, n = null) => {
|
|
61
|
+
let i = t;
|
|
62
|
+
i !== null && requestAnimationFrame(() => {
|
|
63
|
+
let a = i.gridRootRef.current;
|
|
64
|
+
if (a !== null && c(a) && a.focus(), e !== null && t !== null && !(n !== null && s(n, t.uiState))) {
|
|
65
|
+
let n = t.rowModel.getRowCount(), i = t.visibleColumns.length;
|
|
66
|
+
p({
|
|
67
|
+
row: r(e.row, 0, Math.max(n - 1, 0)),
|
|
68
|
+
col: r(e.col, 0, Math.max(i - 1, 0))
|
|
64
69
|
});
|
|
65
70
|
}
|
|
66
|
-
|
|
71
|
+
i.editorActionGuardRef.current = !1;
|
|
67
72
|
});
|
|
68
73
|
};
|
|
69
74
|
return {
|
|
70
|
-
update:
|
|
71
|
-
activateSingleCell:
|
|
72
|
-
startEditWithValue:
|
|
73
|
-
commitEdit: (
|
|
74
|
-
if (
|
|
75
|
-
let { uiState: c, visibleColumns: l, rowModel: u, rows: d, applyServerSideCellEdits: f, onRowsChange: p, dispatch:
|
|
75
|
+
update: f,
|
|
76
|
+
activateSingleCell: p,
|
|
77
|
+
startEditWithValue: m,
|
|
78
|
+
commitEdit: (r, s) => {
|
|
79
|
+
if (t === null) return { status: "noop" };
|
|
80
|
+
let { uiState: c, visibleColumns: l, rowModel: u, rows: d, applyServerSideCellEdits: f, onRowsChange: p, dispatch: m, editorActionGuardRef: g } = t;
|
|
76
81
|
if (g.current || !c.editingCell) return { status: "noop" };
|
|
77
|
-
let _ = c.editingCell, v =
|
|
82
|
+
let _ = c.editingCell, v = s === "down" ? {
|
|
78
83
|
row: _.row + 1,
|
|
79
84
|
col: _.col
|
|
80
|
-
} :
|
|
85
|
+
} : s === "up" ? {
|
|
81
86
|
row: _.row - 1,
|
|
82
87
|
col: _.col
|
|
83
|
-
} :
|
|
88
|
+
} : s === "right" ? {
|
|
84
89
|
row: _.row,
|
|
85
90
|
col: _.col + 1
|
|
86
|
-
} :
|
|
91
|
+
} : s === "left" ? {
|
|
87
92
|
row: _.row,
|
|
88
93
|
col: _.col - 1
|
|
89
94
|
} : _, y = l[_.col], b = u.getSourceIndex(_.row), x = f ? u.getRow(_.row) : d[b];
|
|
90
|
-
if (!y || !x) return
|
|
95
|
+
if (!y || !x) return m(n.stopEdit()), { status: "noop" };
|
|
91
96
|
if (!e({
|
|
92
|
-
readOnly:
|
|
93
|
-
canEditCell:
|
|
94
|
-
}, _.row, _.col, x, y)) return g.current = !0,
|
|
97
|
+
readOnly: t.readOnly,
|
|
98
|
+
canEditCell: t.canEditCell
|
|
99
|
+
}, _.row, _.col, x, y)) return g.current = !0, m(n.stopEdit()), h(null), { status: "noop" };
|
|
95
100
|
if (f) {
|
|
96
|
-
let e = i(y,
|
|
97
|
-
if (
|
|
101
|
+
let e = i(y, r, x), t = o(y, x, e);
|
|
102
|
+
if (t.action === "reject") return {
|
|
98
103
|
status: "rejected",
|
|
99
|
-
message:
|
|
104
|
+
message: t.message
|
|
100
105
|
};
|
|
101
106
|
f([{
|
|
102
107
|
viewIndex: _.row,
|
|
@@ -104,19 +109,22 @@ var s = () => {
|
|
|
104
109
|
value: e
|
|
105
110
|
}]);
|
|
106
111
|
} else if (p) {
|
|
107
|
-
let e = i(y,
|
|
108
|
-
if (
|
|
112
|
+
let e = i(y, r, x), t = o(y, x, e);
|
|
113
|
+
if (t.action === "reject") return {
|
|
109
114
|
status: "rejected",
|
|
110
|
-
message:
|
|
115
|
+
message: t.message
|
|
111
116
|
};
|
|
112
117
|
p(a(d, b, y, e));
|
|
113
118
|
}
|
|
114
|
-
return g.current = !0,
|
|
119
|
+
return g.current = !0, h(v, s === void 0 ? {
|
|
120
|
+
activeCell: c.activeCell,
|
|
121
|
+
selection: c.selection
|
|
122
|
+
} : null), m(n.stopEdit()), { status: "committed" };
|
|
115
123
|
},
|
|
116
124
|
cancelEdit: () => {
|
|
117
|
-
|
|
125
|
+
t === null || t.editorActionGuardRef.current || (t.editorActionGuardRef.current = !0, t.dispatch(n.stopEdit()), h(null));
|
|
118
126
|
}
|
|
119
127
|
};
|
|
120
128
|
};
|
|
121
129
|
//#endregion
|
|
122
|
-
export {
|
|
130
|
+
export { l as createEditController };
|
package/package.json
CHANGED