@ishibashi0112/spreadsheet-grid-core 0.49.0 → 0.50.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,7 +1,8 @@
1
1
  import { reconcileColumnWidths as e } from "../logic/columnWidthState.js";
2
2
  import { createEmptyRowSelection as t, rowSelectionStateEquals as n } from "../logic/rowSelection.js";
3
+ import { isSameColumnFilterValue as r, isSameSortState as i } from "../logic/gridState.js";
3
4
  //#region src/model/gridReducer.ts
4
- var r = 60, i = (e, t, n) => Math.min(Math.max(e, t), n), a = (e, t) => {
5
+ var a = 60, o = (e, t, n) => Math.min(Math.max(e, t), n), s = (e, t) => {
5
6
  let { activeCell: n, selection: r, dragState: i } = e;
6
7
  if (t <= 0) {
7
8
  let t = r !== null && r.type !== "col", a = i?.type === "selection" && i.selectionKind !== "col";
@@ -61,7 +62,7 @@ var r = 60, i = (e, t, n) => Math.min(Math.max(e, t), n), a = (e, t) => {
61
62
  anchorRow: a
62
63
  }
63
64
  })), o;
64
- }, o = () => ({
65
+ }, c = () => ({
65
66
  activeCell: null,
66
67
  selection: null,
67
68
  rowSelection: t(),
@@ -75,60 +76,60 @@ var r = 60, i = (e, t, n) => Math.min(Math.max(e, t), n), a = (e, t) => {
75
76
  sort: [],
76
77
  collapsedGroupKeys: /* @__PURE__ */ new Set(),
77
78
  expandedDetailRowKeys: /* @__PURE__ */ new Set()
78
- }), s = (t, o) => {
79
- switch (o.type) {
80
- case "cell/activate": return {
79
+ }), l = (t, c) => {
80
+ switch (c.type) {
81
+ case "cell/activate": return c.cell === t.activeCell || c.cell !== null && t.activeCell !== null && c.cell.row === t.activeCell.row && c.cell.col === t.activeCell.col ? t : {
81
82
  ...t,
82
- activeCell: o.cell
83
+ activeCell: c.cell
83
84
  };
84
85
  case "selection/start": return {
85
86
  ...t,
86
- activeCell: o.cell,
87
+ activeCell: c.cell,
87
88
  selection: {
88
89
  type: "cell",
89
90
  range: {
90
- start: o.cell,
91
- end: o.cell
91
+ start: c.cell,
92
+ end: c.cell
92
93
  }
93
94
  },
94
95
  dragState: {
95
96
  type: "selection",
96
97
  selectionKind: "cell",
97
- anchor: o.cell
98
+ anchor: c.cell
98
99
  }
99
100
  };
100
101
  case "rowSelection/start": return {
101
102
  ...t,
102
103
  activeCell: {
103
- row: o.row,
104
+ row: c.row,
104
105
  col: t.activeCell?.col ?? 0
105
106
  },
106
107
  selection: {
107
108
  type: "row",
108
- startRow: o.row,
109
- endRow: o.row
109
+ startRow: c.row,
110
+ endRow: c.row
110
111
  },
111
112
  dragState: {
112
113
  type: "selection",
113
114
  selectionKind: "row",
114
- anchorRow: o.row
115
+ anchorRow: c.row
115
116
  }
116
117
  };
117
- case "rowSelection/update": return t.dragState?.type !== "selection" || t.dragState.selectionKind !== "row" || t.selection?.type === "row" && t.selection.endRow === o.row ? t : {
118
+ case "rowSelection/update": return t.dragState?.type !== "selection" || t.dragState.selectionKind !== "row" || t.selection?.type === "row" && t.selection.endRow === c.row ? t : {
118
119
  ...t,
119
120
  selection: {
120
121
  type: "row",
121
122
  startRow: t.dragState.anchorRow,
122
- endRow: o.row
123
+ endRow: c.row
123
124
  }
124
125
  };
125
- case "selection/update": return t.dragState?.type !== "selection" || t.dragState.selectionKind !== "cell" || t.selection?.type === "cell" && t.selection.range.end.row === o.cell.row && t.selection.range.end.col === o.cell.col ? t : {
126
+ case "selection/update": return t.dragState?.type !== "selection" || t.dragState.selectionKind !== "cell" || t.selection?.type === "cell" && t.selection.range.end.row === c.cell.row && t.selection.range.end.col === c.cell.col ? t : {
126
127
  ...t,
127
128
  selection: {
128
129
  type: "cell",
129
130
  range: {
130
131
  start: t.dragState.anchor,
131
- end: o.cell
132
+ end: c.cell
132
133
  }
133
134
  }
134
135
  };
@@ -136,43 +137,43 @@ var r = 60, i = (e, t, n) => Math.min(Math.max(e, t), n), a = (e, t) => {
136
137
  ...t,
137
138
  activeCell: {
138
139
  row: t.activeCell?.row ?? 0,
139
- col: o.col
140
+ col: c.col
140
141
  },
141
142
  selection: {
142
143
  type: "col",
143
- startCol: o.col,
144
- endCol: o.col
144
+ startCol: c.col,
145
+ endCol: c.col
145
146
  },
146
147
  dragState: {
147
148
  type: "selection",
148
149
  selectionKind: "col",
149
- anchorCol: o.col
150
+ anchorCol: c.col
150
151
  }
151
152
  };
152
- case "columnSelection/update": return t.dragState?.type !== "selection" || t.dragState.selectionKind !== "col" || t.selection?.type === "col" && t.selection.endCol === o.col ? t : {
153
+ case "columnSelection/update": return t.dragState?.type !== "selection" || t.dragState.selectionKind !== "col" || t.selection?.type === "col" && t.selection.endCol === c.col ? t : {
153
154
  ...t,
154
155
  selection: {
155
156
  type: "col",
156
157
  startCol: t.dragState.anchorCol,
157
- endCol: o.col
158
+ endCol: c.col
158
159
  }
159
160
  };
160
161
  case "selection/end": return t.dragState?.type === "selection" ? {
161
162
  ...t,
162
163
  dragState: null
163
164
  } : t;
164
- case "selection/clear": return {
165
+ case "selection/clear": return t.selection === null && t.dragState === null ? t : {
165
166
  ...t,
166
167
  selection: null,
167
168
  dragState: null
168
169
  };
169
- case "selection/clampToRowCount": return a(t, o.rowCount);
170
+ case "selection/clampToRowCount": return s(t, c.rowCount);
170
171
  case "edit/start": return {
171
172
  ...t,
172
- editingCell: o.cell,
173
- activeCell: o.cell
173
+ editingCell: c.cell,
174
+ activeCell: c.cell
174
175
  };
175
- case "edit/stop": return {
176
+ case "edit/stop": return t.editingCell === null ? t : {
176
177
  ...t,
177
178
  editingCell: null
178
179
  };
@@ -180,16 +181,16 @@ var r = 60, i = (e, t, n) => Math.min(Math.max(e, t), n), a = (e, t) => {
180
181
  ...t,
181
182
  dragState: {
182
183
  type: "columnResize",
183
- columnKey: o.columnKey,
184
- startX: o.startX,
185
- startWidth: o.startWidth,
186
- minWidth: o.minWidth ?? r,
187
- maxWidth: o.maxWidth ?? Infinity
184
+ columnKey: c.columnKey,
185
+ startX: c.startX,
186
+ startWidth: c.startWidth,
187
+ minWidth: c.minWidth ?? a,
188
+ maxWidth: c.maxWidth ?? Infinity
188
189
  }
189
190
  };
190
191
  case "column/resizeUpdate": {
191
192
  if (t.dragState?.type !== "columnResize") return t;
192
- let e = i(t.dragState.startWidth + (o.clientX - t.dragState.startX), t.dragState.minWidth, t.dragState.maxWidth);
193
+ let e = o(t.dragState.startWidth + (c.clientX - t.dragState.startX), t.dragState.minWidth, t.dragState.maxWidth);
193
194
  return t.columnWidths[t.dragState.columnKey] === e ? t : {
194
195
  ...t,
195
196
  columnWidths: {
@@ -206,40 +207,44 @@ var r = 60, i = (e, t, n) => Math.min(Math.max(e, t), n), a = (e, t) => {
206
207
  ...t,
207
208
  columnWidths: {
208
209
  ...t.columnWidths,
209
- ...o.widths
210
+ ...c.widths
210
211
  }
211
212
  };
212
213
  case "columnWidths/reset": return {
213
214
  ...t,
214
- columnWidths: o.widths
215
+ columnWidths: c.widths
215
216
  };
216
217
  case "columnWidths/reconcile": {
217
- let n = e(t.columnWidths, o.prevColumns, o.nextColumns);
218
+ let n = e(t.columnWidths, c.prevColumns, c.nextColumns);
218
219
  return n === t.columnWidths ? t : {
219
220
  ...t,
220
221
  columnWidths: n
221
222
  };
222
223
  }
223
- case "filter/setGlobal": return {
224
+ case "filter/setGlobal": return t.filters.globalText === c.value ? t : {
224
225
  ...t,
225
226
  filters: {
226
227
  ...t.filters,
227
- globalText: o.value
228
+ globalText: c.value
228
229
  }
229
230
  };
230
- case "filter/setColumn": return {
231
- ...t,
232
- filters: {
233
- ...t.filters,
234
- columnFilters: {
235
- ...t.filters.columnFilters,
236
- [o.columnKey]: o.value
231
+ case "filter/setColumn": {
232
+ let e = t.filters.columnFilters[c.columnKey];
233
+ return e !== void 0 && (e === c.value || r(e, c.value)) ? t : {
234
+ ...t,
235
+ filters: {
236
+ ...t.filters,
237
+ columnFilters: {
238
+ ...t.filters.columnFilters,
239
+ [c.columnKey]: c.value
240
+ }
237
241
  }
238
- }
239
- };
242
+ };
243
+ }
240
244
  case "filter/clearColumn": {
245
+ if (!(c.columnKey in t.filters.columnFilters)) return t;
241
246
  let e = { ...t.filters.columnFilters };
242
- return delete e[o.columnKey], {
247
+ return delete e[c.columnKey], {
243
248
  ...t,
244
249
  filters: {
245
250
  ...t.filters,
@@ -247,7 +252,7 @@ var r = 60, i = (e, t, n) => Math.min(Math.max(e, t), n), a = (e, t) => {
247
252
  }
248
253
  };
249
254
  }
250
- case "filter/resetAll": return {
255
+ case "filter/resetAll": return t.filters.globalText === "" && Object.keys(t.filters.columnFilters).length === 0 ? t : {
251
256
  ...t,
252
257
  filters: {
253
258
  globalText: "",
@@ -256,60 +261,60 @@ var r = 60, i = (e, t, n) => Math.min(Math.max(e, t), n), a = (e, t) => {
256
261
  };
257
262
  case "filter/setAll": return {
258
263
  ...t,
259
- filters: o.filters
264
+ filters: c.filters
260
265
  };
261
- case "sort/set": return {
266
+ case "sort/set": return i(t.sort, c.entries) ? t : {
262
267
  ...t,
263
- sort: o.entries
268
+ sort: c.entries
264
269
  };
265
- case "sort/clear": return {
270
+ case "sort/clear": return t.sort.length === 0 ? t : {
266
271
  ...t,
267
272
  sort: []
268
273
  };
269
- case "rowSelect/set": return n(t.rowSelection, o.state) ? t : {
274
+ case "rowSelect/set": return n(t.rowSelection, c.state) ? t : {
270
275
  ...t,
271
- rowSelection: o.state
276
+ rowSelection: c.state
272
277
  };
273
278
  case "group/toggleCollapsed": {
274
279
  let e = new Set(t.collapsedGroupKeys);
275
- return e.has(o.groupKey) ? e.delete(o.groupKey) : e.add(o.groupKey), {
280
+ return e.has(c.groupKey) ? e.delete(c.groupKey) : e.add(c.groupKey), {
276
281
  ...t,
277
282
  collapsedGroupKeys: e
278
283
  };
279
284
  }
280
285
  case "group/setCollapsed": {
281
- if (t.collapsedGroupKeys.has(o.groupKey) === o.collapsed) return t;
286
+ if (t.collapsedGroupKeys.has(c.groupKey) === c.collapsed) return t;
282
287
  let e = new Set(t.collapsedGroupKeys);
283
- return o.collapsed ? e.add(o.groupKey) : e.delete(o.groupKey), {
288
+ return c.collapsed ? e.add(c.groupKey) : e.delete(c.groupKey), {
284
289
  ...t,
285
290
  collapsedGroupKeys: e
286
291
  };
287
292
  }
288
- case "group/setCollapsedKeys": return o.keys === t.collapsedGroupKeys || o.keys.size === 0 && t.collapsedGroupKeys.size === 0 ? t : {
293
+ case "group/setCollapsedKeys": return c.keys === t.collapsedGroupKeys || c.keys.size === 0 && t.collapsedGroupKeys.size === 0 ? t : {
289
294
  ...t,
290
- collapsedGroupKeys: o.keys
295
+ collapsedGroupKeys: c.keys
291
296
  };
292
297
  case "detail/toggle": {
293
298
  let e = new Set(t.expandedDetailRowKeys);
294
- return e.has(o.rowKey) ? e.delete(o.rowKey) : e.add(o.rowKey), {
299
+ return e.has(c.rowKey) ? e.delete(c.rowKey) : e.add(c.rowKey), {
295
300
  ...t,
296
301
  expandedDetailRowKeys: e
297
302
  };
298
303
  }
299
304
  case "detail/setExpanded": {
300
- if (t.expandedDetailRowKeys.has(o.rowKey) === o.expanded) return t;
305
+ if (t.expandedDetailRowKeys.has(c.rowKey) === c.expanded) return t;
301
306
  let e = new Set(t.expandedDetailRowKeys);
302
- return o.expanded ? e.add(o.rowKey) : e.delete(o.rowKey), {
307
+ return c.expanded ? e.add(c.rowKey) : e.delete(c.rowKey), {
303
308
  ...t,
304
309
  expandedDetailRowKeys: e
305
310
  };
306
311
  }
307
- case "detail/setKeys": return o.keys === t.expandedDetailRowKeys || o.keys.size === 0 && t.expandedDetailRowKeys.size === 0 ? t : {
312
+ case "detail/setKeys": return c.keys === t.expandedDetailRowKeys || c.keys.size === 0 && t.expandedDetailRowKeys.size === 0 ? t : {
308
313
  ...t,
309
- expandedDetailRowKeys: o.keys
314
+ expandedDetailRowKeys: c.keys
310
315
  };
311
316
  default: return t;
312
317
  }
313
318
  };
314
319
  //#endregion
315
- export { o as createInitialGridUiState, s as gridUiReducer };
320
+ export { c as createInitialGridUiState, l as gridUiReducer };
@@ -627,7 +627,8 @@ export type GridColumn<T, F extends GridFrameworkTypes = GridFrameworkTypes> = {
627
627
  lineBreak?: 'auto' | 'loose' | 'normal' | 'strict' | 'anywhere';
628
628
  /**
629
629
  * center 列(非 pinned)の伸縮比。余り幅(コンテナ幅 − 行ヘッダー − pinned 合計 − `width`
630
- * 固定列の合計)を flex 比で配分し `minWidth`/`maxWidth` でクランプ。
630
+ * 固定列の合計)を flex 比で配分し `minWidth`/`maxWidth` でクランプ。配分した幅は整数
631
+ * px(端数は切り捨てて次の列へ回すため、合計が利用可能幅をはみ出さない)。
631
632
  * コンテナ追従でリアクティブに伸縮。手動リサイズで固定 px へ変化(その列の `flex` / `pinned` /
632
633
  * `width` 指定が変わるか列のリセットまで固定 → 以後 flex 復帰)。pinned 列では無視。
633
634
  * 詳細は下記「flex と autoSize」節。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ishibashi0112/spreadsheet-grid-core",
3
- "version": "0.49.0",
3
+ "version": "0.50.0",
4
4
  "description": "SpreadsheetGrid のフレームワーク非依存コア(状態 / 派生値計算 / コマンド / DOM コントローラ)。React 版 @ishibashi0112/spreadsheet-grid と将来の Solid 版が共有します。",
5
5
  "keywords": [
6
6
  "grid",