@ishibashi0112/spreadsheet-grid-core 0.44.0 → 0.45.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 o=null,s=null,c=(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}},l=(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},u=e=>{o=e;let t=e.uiState.editingCell;if(!t){s=null;return}let r=c(e,t);if(s!==null&&r!==null&&Object.is(r.rowKey,s.rowKey)&&r.columnKey===s.columnKey){s={...s,cell:t};return}let i=s!==null&&s.cell.row===t.row&&s.cell.col===t.col;if(s===null||!i){s=r?{...r,cell:t}:null;return}let a=l(e,s);a?(s={...s,cell:a},e.dispatch(n.gridActions.startEdit(a))):(s=null,e.dispatch(n.gridActions.stopEdit()))},d=e=>{o!==null&&(o.dispatch(n.gridActions.startSelection(e)),o.dispatch(n.gridActions.endSelection()),o.dispatch(n.gridActions.activateCell(e)))},f=(e,t)=>{o!==null&&(o.setEditorInitialValue(t),o.dispatch(n.gridActions.startEdit(e)))},p=e=>{let n=o;n!==null&&requestAnimationFrame(()=>{if(t.isFocusInsideDetailCard()||n.gridRootRef.current?.focus(),e!==null&&o!==null){let t=o.rowModel.getRowCount(),n=o.visibleColumns.length;d({row:r.clamp(e.row,0,Math.max(t-1,0)),col:r.clamp(e.col,0,Math.max(n-1,0))})}n.editorActionGuardRef.current=!1})};return{update:u,activateSingleCell:d,startEditWithValue:f,commitEdit:(t,r)=>{if(o===null)return{status:`noop`};let{uiState:s,visibleColumns:c,rowModel:l,rows:u,applyServerSideCellEdits:d,onRowsChange:f,dispatch:m,editorActionGuardRef:h}=o;if(h.current||!s.editingCell)return{status:`noop`};let g=s.editingCell,_=r===`down`?{row:g.row+1,col:g.col}:r===`up`?{row:g.row-1,col:g.col}:r===`right`?{row:g.row,col:g.col+1}:r===`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 m(n.gridActions.stopEdit()),{status:`noop`};if(!e.isCellEditable({readOnly:o.readOnly,canEditCell:o.canEditCell},g.row,g.col,b,v))return h.current=!0,m(n.gridActions.stopEdit()),p(null),{status:`noop`};if(d){let e=i.parseCommittedValue(v,t,b),n=a.decideCellWrite(v,b,e);if(n.action===`reject`)return{status:`rejected`,message:n.message};d([{viewIndex:g.row,column:v,value:e}])}else if(f){let e=i.parseCommittedValue(v,t,b),n=a.decideCellWrite(v,b,e);if(n.action===`reject`)return{status:`rejected`,message:n.message};f(i.writeRowsCell(u,y,v,e))}return h.current=!0,p(_),m(n.gridActions.stopEdit()),{status:`committed`}},cancelEdit:()=>{o===null||o.editorActionGuardRef.current||(o.editorActionGuardRef.current=!0,o.dispatch(n.gridActions.stopEdit()),p(null))}}};exports.createEditController=o;
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
- let s = null, c = null, l = (e, t) => {
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
- }, u = (e, t) => {
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
- }, d = (e) => {
25
- s = e;
26
- let t = e.uiState.editingCell;
27
- if (!t) {
28
- c = null;
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 r = l(e, t);
32
- if (c !== null && r !== null && Object.is(r.rowKey, c.rowKey) && r.columnKey === c.columnKey) {
33
- c = {
34
- ...c,
35
- cell: t
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 i = c !== null && c.cell.row === t.row && c.cell.col === t.col;
40
- if (c === null || !i) {
41
- c = r ? {
42
- ...r,
43
- cell: t
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 a = u(e, c);
48
- a ? (c = {
49
- ...c,
50
- cell: a
51
- }, e.dispatch(n.startEdit(a))) : (c = null, e.dispatch(n.stopEdit()));
52
- }, f = (e) => {
53
- s !== null && (s.dispatch(n.startSelection(e)), s.dispatch(n.endSelection()), s.dispatch(n.activateCell(e)));
54
- }, p = (e, t) => {
55
- s !== null && (s.setEditorInitialValue(t), s.dispatch(n.startEdit(e)));
56
- }, m = (e) => {
57
- let n = s;
58
- n !== null && requestAnimationFrame(() => {
59
- if (t() || n.gridRootRef.current?.focus(), e !== null && s !== null) {
60
- let t = s.rowModel.getRowCount(), n = s.visibleColumns.length;
61
- f({
62
- row: r(e.row, 0, Math.max(t - 1, 0)),
63
- col: r(e.col, 0, Math.max(n - 1, 0))
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
- n.editorActionGuardRef.current = !1;
71
+ i.editorActionGuardRef.current = !1;
67
72
  });
68
73
  };
69
74
  return {
70
- update: d,
71
- activateSingleCell: f,
72
- startEditWithValue: p,
73
- commitEdit: (t, r) => {
74
- if (s === null) return { status: "noop" };
75
- let { uiState: c, visibleColumns: l, rowModel: u, rows: d, applyServerSideCellEdits: f, onRowsChange: p, dispatch: h, editorActionGuardRef: g } = s;
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 = r === "down" ? {
82
+ let _ = c.editingCell, v = s === "down" ? {
78
83
  row: _.row + 1,
79
84
  col: _.col
80
- } : r === "up" ? {
85
+ } : s === "up" ? {
81
86
  row: _.row - 1,
82
87
  col: _.col
83
- } : r === "right" ? {
88
+ } : s === "right" ? {
84
89
  row: _.row,
85
90
  col: _.col + 1
86
- } : r === "left" ? {
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 h(n.stopEdit()), { status: "noop" };
95
+ if (!y || !x) return m(n.stopEdit()), { status: "noop" };
91
96
  if (!e({
92
- readOnly: s.readOnly,
93
- canEditCell: s.canEditCell
94
- }, _.row, _.col, x, y)) return g.current = !0, h(n.stopEdit()), m(null), { status: "noop" };
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, t, x), n = o(y, x, e);
97
- if (n.action === "reject") return {
101
+ let e = i(y, r, x), t = o(y, x, e);
102
+ if (t.action === "reject") return {
98
103
  status: "rejected",
99
- message: n.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, t, x), n = o(y, x, e);
108
- if (n.action === "reject") return {
112
+ let e = i(y, r, x), t = o(y, x, e);
113
+ if (t.action === "reject") return {
109
114
  status: "rejected",
110
- message: n.message
115
+ message: t.message
111
116
  };
112
117
  p(a(d, b, y, e));
113
118
  }
114
- return g.current = !0, m(v), h(n.stopEdit()), { status: "committed" };
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
- s === null || s.editorActionGuardRef.current || (s.editorActionGuardRef.current = !0, s.dispatch(n.stopEdit()), m(null));
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 { s as createEditController };
130
+ export { l as createEditController };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ishibashi0112/spreadsheet-grid-core",
3
- "version": "0.44.0",
3
+ "version": "0.45.0",
4
4
  "description": "SpreadsheetGrid のフレームワーク非依存コア(状態 / 派生値計算 / コマンド / DOM コントローラ)。React 版 @ishibashi0112/spreadsheet-grid と将来の Solid 版が共有します。",
5
5
  "keywords": [
6
6
  "grid",