@aiquants/spreadsheet 0.20.1 → 0.20.3
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/CHANGELOG.md +149 -0
- package/README.md +153 -10
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +301 -25
- package/dist/index.d.ts +301 -25
- package/dist/index.js +6320 -5670
- package/dist/styles/spreadsheet.css +1 -1
- package/dist/styles/spreadsheet.standalone.css +1 -1
- package/package.json +2 -2
- package/src/Spreadsheet.tsx +379 -39
- package/src/commands/useCommands.ts +27 -0
- package/src/editor/useCellEditor.ts +38 -6
- package/src/grid/GridBody.tsx +61 -3
- package/src/index.ts +23 -1
- package/src/keyboard/useGridKeyboard.ts +101 -3
- package/src/model/labels.ts +100 -10
- package/src/popover/PopoverLayer.tsx +66 -4
- package/src/popover/usePopovers.ts +87 -9
- package/src/selection/selectionState.ts +70 -0
- package/src/selection/useSelectionEngine.ts +141 -2
- package/src/sortFilter/ColumnMenu.tsx +380 -0
- package/src/sortFilter/HeaderControls.tsx +128 -0
- package/src/sortFilter/sortFilterModel.ts +648 -0
- package/src/styles/spreadsheet.css +148 -2
package/src/Spreadsheet.tsx
CHANGED
|
@@ -54,9 +54,9 @@ import type { ClipChannel } from "./clipboard/clipPayload.ts"
|
|
|
54
54
|
import type { PasteOptions } from "./clipboard/pasteSpecial.ts"
|
|
55
55
|
import { type ClipInfo, type PasteOutcome, type PasteSheet, useClipboard } from "./clipboard/useClipboard.ts"
|
|
56
56
|
import { type BorderPreset, type CommandRunner, type KeyboardCellRect, useCommands } from "./commands/useCommands.ts"
|
|
57
|
-
import { type SinkSnapshot, useCellEditor } from "./editor/useCellEditor.ts"
|
|
57
|
+
import { type EditSession, type SinkSnapshot, useCellEditor } from "./editor/useCellEditor.ts"
|
|
58
58
|
import type { RenderCellContext } from "./grid/CellView.tsx"
|
|
59
|
-
import { GridBody } from "./grid/GridBody.tsx"
|
|
59
|
+
import { GridBody, type GridColumnMenu } from "./grid/GridBody.tsx"
|
|
60
60
|
import { ColumnHeader } from "./header/ColumnHeader.tsx"
|
|
61
61
|
import { columnIndexToName } from "./header/columnName.ts"
|
|
62
62
|
import { RowHeader } from "./header/RowHeader.tsx"
|
|
@@ -79,12 +79,13 @@ import { pickEngineLabels, resolveLabels, type SpreadsheetLabelOverrides, type S
|
|
|
79
79
|
import { createViewStore, type ViewStore } from "./model/viewStore.ts"
|
|
80
80
|
import { DEFAULT_HIGHLIGHT_COLORS, type DragFrameMode, type HighlightColors, type HighlightState, type ResizeGuide, SelectionOverlay } from "./overlay/SelectionOverlay.tsx"
|
|
81
81
|
import { useFillHandle } from "./overlay/useFillHandle.ts"
|
|
82
|
-
import { PopoverLayer } from "./popover/PopoverLayer.tsx"
|
|
82
|
+
import { type ColumnMenuLayerProps, PopoverLayer } from "./popover/PopoverLayer.tsx"
|
|
83
83
|
import { type PopoverAnchorState, type PopoverContext, type PopoverController, type PopoverKind, type PopoverOpenOptions, type PopoverOverrides, usePopovers } from "./popover/usePopovers.ts"
|
|
84
|
-
import { clampSelectionToGrid, reduceActiveCycle, reduceSelectionExtend, reduceSelectionPress, type SelectionState, selectionStateEquals } from "./selection/selectionState.ts"
|
|
84
|
+
import { clampSelectionToGrid, placedSelectionOf, reduceActiveCycle, reduceSelectionExtend, reduceSelectionPress, type SelectionState, selectionStateEquals } from "./selection/selectionState.ts"
|
|
85
85
|
import { useAutoScroller } from "./selection/useAutoScroller.ts"
|
|
86
86
|
import { type PointDragOwner, usePointDrag } from "./selection/usePointDrag.ts"
|
|
87
87
|
import { useSelectionEngine } from "./selection/useSelectionEngine.ts"
|
|
88
|
+
import { controlsColumnOf, cycleSort, headerColumnName, type ResolvedSortFilterColumn, resolveSortFilter, type SpreadsheetSortFilter, type SpreadsheetSortFilterState, sameResolvedColumn, sameSortFilterState } from "./sortFilter/sortFilterModel.ts"
|
|
88
89
|
import { clampSpreadsheetZoom, SPREADSHEET_DEFAULT_COLUMN_WIDTH_PX, SPREADSHEET_MAX_OPERATION_CELLS, SPREADSHEET_SCROLLBAR_SIZE_PX, stepSpreadsheetZoom } from "./view.ts"
|
|
89
90
|
|
|
90
91
|
export type { SelectionState } from "./selection/selectionState.ts"
|
|
@@ -216,6 +217,62 @@ const seenSpanOf = (seen: (y: number) => boolean, top: number, bottom: number):
|
|
|
216
217
|
}
|
|
217
218
|
}
|
|
218
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Why a confirmed selection changed — the second argument of `onSelectionChange`. `"user"`: a gesture, a chord, a command
|
|
222
|
+
* or a paste moved it, including a command or paste the host runs through the handle (`executeCommand`, `paste`) for the
|
|
223
|
+
* user; `"setSelection"`: the host placed it through the handle's `setSelection`; `"sheetSwitch"`: the adapter identity
|
|
224
|
+
* changed to a non-empty adapter and the selection reset to A1; `"countShrink"`: the same adapter's `rowCount` /
|
|
225
|
+
* `colCount` shrank and the selection was pulled onto the grid.
|
|
226
|
+
* 確定選択が変わった理由 — `onSelectionChange` の 2 つ目の引数。`"user"`: ジェスチャ・チョード・コマンド・貼り付けが動かした (利用側が
|
|
227
|
+
* 利用者の代わりに handle で走らせるコマンドと貼り付け — `executeCommand`・`paste` — も含む)。`"setSelection"`: 利用側が handle の
|
|
228
|
+
* `setSelection` で置いた。`"sheetSwitch"`: アダプタの同一性が空でないアダプタへ替わり、選択が A1 へ戻った。`"countShrink"`: 同じ
|
|
229
|
+
* アダプタの `rowCount` / `colCount` が縮み、選択をグリッドの中へ畳んだ。
|
|
230
|
+
*/
|
|
231
|
+
export type SelectionChangeReason = "user" | "setSelection" | "sheetSwitch" | "countShrink"
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Options of the handle's `setSelection`. `scroll: true` brings the placed active cell into view with the keyboard's
|
|
235
|
+
* minimal scroll (the grid's own viewport, then the page); absent or `false` leaves every scroll position alone — pair it
|
|
236
|
+
* with `scrollToCell` for an alignment of your own.
|
|
237
|
+
* handle の `setSelection` の選択肢。`scroll: true` は、置いたアクティブなマスをキーの移動と同じ最小の送りで見せる (グリッド自身の
|
|
238
|
+
* 表示域、続けてページ)。無しか `false` はどのスクロール位置も変えない — 揃えを選ぶなら `scrollToCell` と組み合わせる。
|
|
239
|
+
*/
|
|
240
|
+
export type SetSelectionOptions = { scroll?: boolean }
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* What the handle's `commitEdit` did: `"committed"` — the open session closed (its text written through `applyEdits`, or
|
|
244
|
+
* closed without a write when the text was unchanged); `"rejected"` — the commit was refused and the session stays open
|
|
245
|
+
* with the typed text (the refusal went through `onEditRejected`, `onValidationRejected` or `onReadOnlyRejected`, as an
|
|
246
|
+
* Enter's would); `"idle"` — no session was open and nothing happened.
|
|
247
|
+
* handle の `commitEdit` の結果: `"committed"` — 開いていたセッションが閉じた (字を `applyEdits` で書いた、または字が変わらず書かずに
|
|
248
|
+
* 閉じた)。`"rejected"` — 確定が断られ、打った字のままセッションが続く (断りは Enter と同じく `onEditRejected`・`onValidationRejected`・
|
|
249
|
+
* `onReadOnlyRejected` で知らせた)。`"idle"` — セッションが無く、何もしなかった。
|
|
250
|
+
*/
|
|
251
|
+
export type CommitEditOutcome = "committed" | "rejected" | "idle"
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Whether the handle's `setSelection` scrolls: `options.scroll`, false when the options or the member are absent (the
|
|
255
|
+
* documented default — a placement leaves the scroll alone).
|
|
256
|
+
* handle の `setSelection` が送るか: `options.scroll`。選択肢かその項目が無ければ false (定めた既定 — 置くだけでは送らない)。
|
|
257
|
+
*
|
|
258
|
+
* @param options - The options the host passed. 利用側が渡した選択肢。
|
|
259
|
+
* @returns Whether to bring the placed active cell into view. 置いたアクティブなマスを見せるか。
|
|
260
|
+
* @throws {RangeError} When the options are not an object or `scroll` is neither `true`, `false` nor absent (a JS host's `null`, `1` or `"yes"`). 選択肢が物でない、または `scroll` が `true`・`false`・無しのどれでもないとき (JS の利用側の `null`・`1`・`"yes"`)。
|
|
261
|
+
*/
|
|
262
|
+
const setSelectionScrolls = (options: SetSelectionOptions | undefined): boolean => {
|
|
263
|
+
if (options === undefined) {
|
|
264
|
+
return false
|
|
265
|
+
}
|
|
266
|
+
if (typeof options !== "object" || options === null) {
|
|
267
|
+
throw new RangeError(`[spreadsheet] setSelection: the options must be an object (got ${String(options)})`)
|
|
268
|
+
}
|
|
269
|
+
const { scroll } = options
|
|
270
|
+
if (scroll !== undefined && scroll !== true && scroll !== false) {
|
|
271
|
+
throw new RangeError(`[spreadsheet] setSelection: options.scroll must be true, false or absent (got ${String(scroll)})`)
|
|
272
|
+
}
|
|
273
|
+
return scroll === true
|
|
274
|
+
}
|
|
275
|
+
|
|
219
276
|
/** Imperative surface (§6.9-8). / 命令 API (§6.9-8)。 */
|
|
220
277
|
export type SpreadsheetHandle = {
|
|
221
278
|
/** Row-height pair seam (§6.9-8). / 行高変更の対シーム。 */
|
|
@@ -268,6 +325,46 @@ export type SpreadsheetHandle = {
|
|
|
268
325
|
paste: (options: PasteOptions) => Promise<PasteOutcome>
|
|
269
326
|
/** The confirmed selection (imperative read). / 確定選択の命令読み。 */
|
|
270
327
|
getSelection: () => SelectionState
|
|
328
|
+
/**
|
|
329
|
+
* Places the selection — its ranges, anchor and active cell — where the host decides (a row the page chose from its
|
|
330
|
+
* URL, the same month after the host moved the window a year). It goes through the same write path as a gesture:
|
|
331
|
+
* `onSelectionChange` fires once with reason `"setSelection"` (never for a selection equal to the current one), the
|
|
332
|
+
* announcement formatters run, the active cell's input message shows, and the next Arrow key moves from the placed
|
|
333
|
+
* active cell. The grid keeps a copy, so the host may reuse its object. A hidden row or column is a valid place.
|
|
334
|
+
* Focus does not move (call `focus()` for that), and an open popover keeps its cell.
|
|
335
|
+
* 選択 (レンジ・anchor・アクティブなマス) を利用側が決めた所へ置く (ページが URL から選んだ行・利用側が窓を 1 年送った後の同じ月)。
|
|
336
|
+
* ジェスチャと同じ書き込みの道を通る: `onSelectionChange` が理由 `"setSelection"` で 1 回発火 (今と等しい選択では発火しない)、読み上げの
|
|
337
|
+
* 整形が走り、アクティブなマスの入力メッセージが出て、次の矢印キーは置いたアクティブなマスから動く。グリッドは写しを持つので、利用側は
|
|
338
|
+
* 自分の物を使い回してよい。隠した行・列の上にも置ける。焦点は動かさず (要るなら `focus()`)、開いているポップオーバーは自分のマスを保つ。
|
|
339
|
+
*
|
|
340
|
+
* @param selection - The ranges (at least one, each start at most its end), the anchor (inside the last range) and the active cell (inside some range), all inside the grid. レンジ (1 つ以上、始まりは終わり以下)・anchor (末尾のレンジの中)・アクティブなマス (どれかのレンジの中)。どれもグリッドの中。
|
|
341
|
+
* @param options - `scroll: true` brings the active cell into view as an Arrow key does; absent or `false` leaves the scroll alone. `scroll: true` は矢印キーと同じくアクティブなマスを見せる。無しか `false` は送らない。
|
|
342
|
+
* @returns True when the selection is placed (or already was); false — nothing changed — while a cell is being edited (the session stays open) or a pointer drag is in flight. 置けた (または既にその選択だった) なら true。セルの入力中 (セッションは続く) とポインタのドラッグの途中は false で何も変えない。
|
|
343
|
+
* @throws {RangeError} When the selection is not a valid selection of the grid (no range, a bound that is not a whole number inside the grid, a range whose start is after its end, the anchor outside the last range, the active cell outside every range — a grid without rows or columns throws for any selection), or `options.scroll` is neither `true`, `false` nor absent. 選択がグリッドの正しい選択でないとき (レンジが無い・境がグリッドの中の整数でない・始まりが終わりより後のレンジ・末尾のレンジの外の anchor・どのレンジの外のアクティブなマス — 行か列の無いグリッドではどの選択も投げる)、または `options.scroll` が `true`・`false`・無しのどれでもないとき。
|
|
344
|
+
*/
|
|
345
|
+
setSelection: (selection: SelectionState, options?: SetSelectionOptions) => boolean
|
|
346
|
+
/**
|
|
347
|
+
* The open in-place edit session — the cell it writes to and how it opened — or null when no cell is being edited
|
|
348
|
+
* (the same object `onEditSessionChange` last reported).
|
|
349
|
+
* 開いているその場の入力のセッション (書き込み先のマスと開き方)。入力中のセルが無ければ null (`onEditSessionChange` が最後に知らせた物と同じ)。
|
|
350
|
+
*
|
|
351
|
+
* @returns The session, or null. セッション、または null。
|
|
352
|
+
*/
|
|
353
|
+
getEditSession: () => EditSession | null
|
|
354
|
+
/**
|
|
355
|
+
* Commits the open session as Enter does, without moving the active cell — for a host that saves from outside the
|
|
356
|
+
* grid's keys (a Ctrl+S listener) and must not lose the typed text. The text is validated and written through
|
|
357
|
+
* `applyEdits` when it changed; an unchanged text just closes the session. A refused commit keeps the session open
|
|
358
|
+
* with the typed text and reports the refusal through the same callback as an Enter. An IME composition in flight is
|
|
359
|
+
* confirmed first, as a press elsewhere in the grid confirms it (the hidden input blurs and takes the focus back).
|
|
360
|
+
* 開いているセッションを Enter と同じく確定する (アクティブなマスは動かさない) — グリッドのキーの外で保存する利用側 (Ctrl+S の聞き手)
|
|
361
|
+
* が、打った字を失わないため。字が変わっていれば検めて `applyEdits` で書き、変わっていなければセッションを閉じるだけ。断られた確定は打った字の
|
|
362
|
+
* ままセッションを続け、Enter と同じ口で断りを知らせる。IME の変換中なら、グリッドの中の押下と同じく先に変換を確定させる (隠れた入力欄を
|
|
363
|
+
* blur して焦点を取り戻す)。
|
|
364
|
+
*
|
|
365
|
+
* @returns `"committed"` when the session closed, `"rejected"` when the commit was refused (the session stays), `"idle"` when no session was open. セッションが閉じたら `"committed"`、断られたら `"rejected"` (セッションは続く)、開いていなければ `"idle"`。
|
|
366
|
+
*/
|
|
367
|
+
commitEdit: () => CommitEditOutcome
|
|
271
368
|
/** The adapter's BASE format of a cell (toolbar state) — the getCellFormat capability branch. / セルの base 書式 (getCellFormat の能力分岐)。 */
|
|
272
369
|
getBaseFormat: (cell: CellCoord) => CellFormat | undefined
|
|
273
370
|
/** base ⊕ conditional formats of a cell (the paint the user sees). / base ⊕ 条件付き書式 (描画される書式)。 */
|
|
@@ -325,6 +422,28 @@ export type SpreadsheetProps = {
|
|
|
325
422
|
* を受け、支援技術は下の列の見出しとして読む。[0, frozenRows] の整数 (見出しの行は常に凍結行)。それ以外は描画中の RangeError。
|
|
326
423
|
*/
|
|
327
424
|
headerRows?: number
|
|
425
|
+
/**
|
|
426
|
+
* Header sorting and per-column filtering (v0.20.3). The host owns the state (a controlled prop) and the rows: it
|
|
427
|
+
* matches and reorders its adapter when `onStateChange` reports a new state. The package draws the controls on the
|
|
428
|
+
* last header row (`headerRows - 1`) — pressing a sortable column's header cell (a mouse click, a finger or pen tap)
|
|
429
|
+
* cycles ascending → descending → unsorted, and the cell's ▼ button or Alt+ArrowDown opens the column menu (sort,
|
|
430
|
+
* match mode, exact value list or fuzzy query, apply, clear) — and decides when the state may change: the in-place
|
|
431
|
+
* edit is committed first (Enter's commit; a refusal changes nothing), then the column menu, the interactive popover
|
|
432
|
+
* and the note tip close and the copy / cut marquee is dropped, then `onStateChange` is called once (never with a state
|
|
433
|
+
* of the same shape). The selection keeps its position. Every member is read at render and the whole object is
|
|
434
|
+
* validated again whenever its identity changes (memoize it); a malformed prop, option or state is a RangeError during
|
|
435
|
+
* render. An empty grid (no row or no column) draws no control and validates nothing (the check runs once data
|
|
436
|
+
* arrives). Absent = no control, the v0.20.2 DOM and behaviour.
|
|
437
|
+
* 見出しの並べ替えと列ごとの絞り込み (v0.20.3)。状態 (制御された props) と行は利用側が持ち、`onStateChange` が知らせた新しい状態で
|
|
438
|
+
* アダプタの行を照らして並べ直す。部品は見出しの最後の行 (`headerRows - 1`) に操作を描き (並べ替えできる列の見出しのマスの押下 —
|
|
439
|
+
* マウスのクリック・指とペンの叩き — は昇順 → 降順 → 無しと巡り、マスの ▼ と Alt+↓ は列の品書き — 並べ替え・検索方法・完全一致の
|
|
440
|
+
* 値の一覧かあいまい検索の語・当てる・外す — を開く)、状態を変えてよい時を見極める: その場の入力は先に確定し (Enter と同じ確定。
|
|
441
|
+
* 断られたら何も変えない)、次に列の品書き・対話のポップオーバー・メモの吹き出しを閉じて写しの印を捨て、`onStateChange` を 1 回呼ぶ
|
|
442
|
+
* (同じ形の状態では呼ばない)。選択は位置を保つ。全ての項目を描く時に読み、物が替わるたびに全体を検め直す (memo して渡す)。誤った
|
|
443
|
+
* props・指定・状態は描く時の RangeError。空の表 (行か列が 0) は操作を描かず、何も検めない (データが来て描いた時に検める)。無ければ
|
|
444
|
+
* 操作は無く、DOM と動きは v0.20.2 と同じ。
|
|
445
|
+
*/
|
|
446
|
+
sortFilter?: SpreadsheetSortFilter
|
|
328
447
|
/**
|
|
329
448
|
* Freezes the LAST N columns at the right edge (v0.9 — the VirtualGrid frozenTrailingCols
|
|
330
449
|
* pass-through; LIVE prop, default 0). Validation SSOT is the engine's fail-fast contract
|
|
@@ -471,31 +590,48 @@ export type SpreadsheetProps = {
|
|
|
471
590
|
renderCell?: (ctx: RenderCellContext) => ReactNode
|
|
472
591
|
/**
|
|
473
592
|
* Fires on every confirmed SelectionState change (press replace, extend confirm, cycling,
|
|
474
|
-
* paste replace, Ctrl+A, ...),
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
593
|
+
* paste replace, Ctrl+A, ...), with the reason as the second argument
|
|
594
|
+
* ({@link SelectionChangeReason}): `"user"` for gestures, chords, commands and pastes — one
|
|
595
|
+
* run by a handle call too (the handle `paste` moves the selection to the written block and
|
|
596
|
+
* fires like the keyboard paste) — and `"setSelection"` for the handle's `setSelection`. Never
|
|
597
|
+
* during a drag (state frozen — one fire at pointerup), with ONE documented in-drag firing
|
|
598
|
+
* point: the header subtract reservation converts to a real press on the first movement,
|
|
599
|
+
* firing the deferred press replace mid-drag (total fire count matches v0.1 — conversion 1 +
|
|
600
|
+
* up 1). Never for the initial A1 mount. TWO adapter-driven fire points, each firing from a
|
|
601
|
+
* layout effect of the commit that brings the new adapter or counts (neither a gesture nor a
|
|
602
|
+
* handle call): a sheet switch (a new adapter identity) to a non-empty adapter resets the
|
|
603
|
+
* selection to A1 through the wrapper and fires once with `"sheetSwitch"`, unless the
|
|
604
|
+
* selection already was the lone cell A1; and a same-adapter rowCount / colCount shrink that
|
|
605
|
+
* moved the selection fires once with `"countShrink"` (ADR-33). A switch or a shrink that
|
|
606
|
+
* leaves 0 rows or 0 columns (so no A1) writes the empty-grid state directly and never fires.
|
|
486
607
|
* Independent of the live region's 200ms debounce (firing point: the §6.9-1 setSelection
|
|
487
608
|
* wrapper).
|
|
488
|
-
* 確定 SelectionState
|
|
489
|
-
* `
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
|
|
498
|
-
|
|
609
|
+
* 確定 SelectionState が変わるたびに発火し、2 つ目の引数で理由を渡す ({@link SelectionChangeReason}):
|
|
610
|
+
* ジェスチャ・チョード・コマンド・貼り付けは `"user"` (handle の呼び出しが走らせた変化も — handle の
|
|
611
|
+
* `paste` は選択を書いた範囲へ動かし、キーボードの貼り付けと同じく発火)、handle の `setSelection` は
|
|
612
|
+
* `"setSelection"`。ドラッグ中と初期マウントでは発火しない。明文のドラッグ中発火点が 1 つ: ヘッダー減算
|
|
613
|
+
* 予約の実 press 変換 (初動 move) は遅延 press 置換をドラッグ中に発火する (発火総数は v0.1 と同一 —
|
|
614
|
+
* 変換 1 + up 1)。adapter 起点の発火点は 2 つで、どちらも新しい adapter や行数・列数を運んだ commit の
|
|
615
|
+
* layout effect から発火 (ジェスチャでも handle の呼び出しでもない): 空でない adapter へのシート切替
|
|
616
|
+
* (adapter の同一性の変化) は、ラッパー経由の A1 へのリセットで `"sheetSwitch"` を 1 回発火 (選択が
|
|
617
|
+
* 既に A1 の 1 マスだけなら発火なし)。同一 adapter の rowCount / colCount 縮小で選択が動いたときは
|
|
618
|
+
* `"countShrink"` を 1 回発火 (ADR-33)。0 行または 0 列 (A1 が無い) になる切替と縮小は、空グリッドの
|
|
619
|
+
* 状態をラッパーを通さずに書き、発火なし。
|
|
620
|
+
*/
|
|
621
|
+
onSelectionChange?: (selection: SelectionState, reason: SelectionChangeReason) => void
|
|
622
|
+
/**
|
|
623
|
+
* Notice of the in-place edit session: the new {@link EditSession} right after a session opens (F2, a double-click,
|
|
624
|
+
* a printable key, an IME composition, the handle's `startEdit`), `null` right after it closes — a commit (after
|
|
625
|
+
* `applyEdits` returned, before the Enter / Tab that committed moves the active cell), a cancel, the focus leaving
|
|
626
|
+
* the grid, an adapter switch, a count shrink that removed the cell, an editing Ctrl+Enter fill. A refused commit
|
|
627
|
+
* keeps the session open and reports nothing here. Not called on unmount. Read when it fires (no remount). The
|
|
628
|
+
* handle's `getEditSession` returns the same object.
|
|
629
|
+
* その場の入力のセッションの知らせ: セッションが開いた直後 (F2・ダブルクリック・印字キー・IME の変換・handle の `startEdit`) に新しい
|
|
630
|
+
* {@link EditSession}、閉じた直後に `null` — 確定 (`applyEdits` が戻った後、確定した Enter / Tab がアクティブなマスを動かす前)・取り消し・
|
|
631
|
+
* 焦点のグリッドの外への離脱・アダプタの切り替え・マスを消した縮小・入力中の Ctrl+Enter の埋め。断られた確定はセッションを続け、ここでは
|
|
632
|
+
* 何も知らせない。アンマウントでは呼ばない。発火の時に読む (再マウント不要)。handle の `getEditSession` は同じ物を返す。
|
|
633
|
+
*/
|
|
634
|
+
onEditSessionChange?: (session: EditSession | null) => void
|
|
499
635
|
/** Consumer context menu (§6.4.3-4 / §6.6.1 Shift+F10); keyboard origin carries the active cell viewport rect. / consumer コンテキストメニュー。 */
|
|
500
636
|
onCellContextMenu?: (cell: CellCoord, origin: { kind: "pointer"; event: MouseEvent } | { kind: "keyboard"; cellRect: { top: number; left: number; width: number; height: number } }) => void
|
|
501
637
|
/** Undo request relay (history lives in the consumer — ADR-6). / Undo 要求の中継。 */
|
|
@@ -1090,6 +1226,7 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
1090
1226
|
{
|
|
1091
1227
|
adapter: hostAdapter,
|
|
1092
1228
|
headerRows = 0,
|
|
1229
|
+
sortFilter,
|
|
1093
1230
|
readOnly = false,
|
|
1094
1231
|
labelledBy,
|
|
1095
1232
|
defaultRowHeight = DEFAULT_ROW_HEIGHT,
|
|
@@ -1106,6 +1243,7 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
1106
1243
|
onRenderTruncated,
|
|
1107
1244
|
renderCell,
|
|
1108
1245
|
onSelectionChange,
|
|
1246
|
+
onEditSessionChange,
|
|
1109
1247
|
onCellContextMenu,
|
|
1110
1248
|
onUndoRequest,
|
|
1111
1249
|
onRedoRequest,
|
|
@@ -1261,6 +1399,15 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
1261
1399
|
// 恒久固定され、ジェスチャが永久に死ぬ — R2(E) blocking)
|
|
1262
1400
|
const isEmpty = adapter.rowCount === 0 || adapter.colCount === 0
|
|
1263
1401
|
const zoomGestureEnabled = !isEmpty
|
|
1402
|
+
// ---- 並べ替えと絞り込み (v0.20.3 — sortFilter): 描くたびに 1 回だけ検めて解く。空の表は操作を描かないので検めない
|
|
1403
|
+
// (列が 0 だと状態の鍵が全て知らない列になり、読み込み中の表が落ちる — データが来て描いた時に検める) ----
|
|
1404
|
+
const sortFilterColCount = adapter.colCount
|
|
1405
|
+
const resolvedSortFilter = useMemo(() => (sortFilter === undefined || isEmpty ? null : resolveSortFilter(sortFilter, sortFilterColCount, headerRows)), [sortFilter, isEmpty, sortFilterColCount, headerRows])
|
|
1406
|
+
// コールバックは今の props と解き方を ref で読む (押下から離すまでの間・品書きの開いている間に替わっても今の物で決める)
|
|
1407
|
+
const sortFilterRef = useRef(sortFilter)
|
|
1408
|
+
sortFilterRef.current = sortFilter
|
|
1409
|
+
const resolvedSortFilterRef = useRef(resolvedSortFilter)
|
|
1410
|
+
resolvedSortFilterRef.current = resolvedSortFilter
|
|
1264
1411
|
useEffect(() => {
|
|
1265
1412
|
const root = rootRef.current
|
|
1266
1413
|
if (!zoomGestureEnabled || root === null) {
|
|
@@ -1979,11 +2126,14 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
1979
2126
|
|
|
1980
2127
|
/**
|
|
1981
2128
|
* The §6.9-1 setSelection wrapper — the ONLY write path for every producer (engine /
|
|
1982
|
-
* keyboard / headers / clipboard
|
|
1983
|
-
* setSelection
|
|
2129
|
+
* keyboard / headers / clipboard, the adapter switch and count shrink, the handle's
|
|
2130
|
+
* `setSelection`). 5 ordered steps; `reason` reaches `onSelectionChange` unchanged.
|
|
2131
|
+
* setSelection ラッパー (§6.9-1) — 全書き込み経路の唯一の入口 (エンジン / キーボード / ヘッダー /
|
|
2132
|
+
* クリップボード、アダプタの切り替えと縮小、handle の `setSelection`)。5 段の順序処理で、`reason` は
|
|
2133
|
+
* そのまま `onSelectionChange` へ渡る。
|
|
1984
2134
|
*/
|
|
1985
|
-
const
|
|
1986
|
-
(next: SelectionState) => {
|
|
2135
|
+
const writeSelection = useCallback(
|
|
2136
|
+
(next: SelectionState, reason: SelectionChangeReason) => {
|
|
1987
2137
|
const prev = selectionRef.current
|
|
1988
2138
|
// (1) 等価 bail — Object.is は reducer の identity 保存契約の高速経路、構造等価は
|
|
1989
2139
|
// 構築系 state (Ctrl+A / コーナー / ヘッダー合成) の等価再発火を抑える (どちらも
|
|
@@ -1996,7 +2146,7 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
1996
2146
|
// (3) setState
|
|
1997
2147
|
setSelectionState(next)
|
|
1998
2148
|
// (4) onSelectionChange を同期発火し、読み上げ 3 段判定もここで評価 (prev は (2) 前の退避値)
|
|
1999
|
-
onSelectionChange?.(next)
|
|
2149
|
+
onSelectionChange?.(next, reason)
|
|
2000
2150
|
evaluateAnnouncement(prev, next)
|
|
2001
2151
|
// (5) 編集セッション外なら rearm (ADR-3 の rearm 点 (c) の実行点はここ 1 箇所)
|
|
2002
2152
|
if (!(isEditingRef.current?.() ?? false)) {
|
|
@@ -2006,6 +2156,14 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
2006
2156
|
[onSelectionChange, evaluateAnnouncement, rearmSink],
|
|
2007
2157
|
)
|
|
2008
2158
|
|
|
2159
|
+
/**
|
|
2160
|
+
* The producers' write path (engine / keyboard / headers / corner / fill handle / clipboard / commands): every change
|
|
2161
|
+
* they make — a handle-run command or paste included — is the user's, reason `"user"`.
|
|
2162
|
+
* 書き手 (エンジン / キーボード / ヘッダー / 角 / fill handle / クリップボード / コマンド) の書き込みの道: 書き手の変化は全て
|
|
2163
|
+
* 利用者の物 (handle が走らせるコマンドと貼り付けも含む)、理由は `"user"`。
|
|
2164
|
+
*/
|
|
2165
|
+
const setSelection = useCallback((next: SelectionState) => writeSelection(next, "user"), [writeSelection])
|
|
2166
|
+
|
|
2009
2167
|
/** moveActive (§6.6.2-3): discriminated union to reducer to ensureCellVisible; owned by Spreadsheet (§6.9-7). / 判別 union → reducer → ensureCellVisible の順に適用。 */
|
|
2010
2168
|
const moveActive = useCallback(
|
|
2011
2169
|
(input: MoveActiveInput) => {
|
|
@@ -2105,6 +2263,105 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
2105
2263
|
/** Sheet-switch relay into the clipboard hook (copy discarded, cut kept as foreign). / シート切替のクリップ中継 (copy 破棄、cut は foreign で保持)。 */
|
|
2106
2264
|
const onAdapterSwitchRef = useRef<() => void>(() => {})
|
|
2107
2265
|
|
|
2266
|
+
/**
|
|
2267
|
+
* The one funnel every sort / filter action goes through (v0.20.3 — the header press and every column-menu action):
|
|
2268
|
+
* commits the in-place edit first (Enter's commit, an IME composition confirmed first; a refusal returns false and
|
|
2269
|
+
* changes nothing — the refusal reaches the host through its usual channel), then closes the column menu, the
|
|
2270
|
+
* interactive popover and the note tip and drops the copy / cut marquee (all of them point at positions, which hold
|
|
2271
|
+
* other rows once the host reorders), then calls `onStateChange` once unless `next` has the shape of the current
|
|
2272
|
+
* state; returns true when the change was accepted.
|
|
2273
|
+
* 並べ替えと絞り込みの全ての操作が通る 1 つの手順 (v0.20.3 — 見出しの押下と品書きの全ての操作)。先にその場の入力を確定し (Enter と同じ
|
|
2274
|
+
* 確定。変換中は変換を確定させてから。断られたら false を返して何も変えない — 断りはいつもの口で利用側へ届く)、次に列の品書き・対話の
|
|
2275
|
+
* ポップオーバー・メモの吹き出しを閉じて写しの印を捨て (どれも位置を指し、利用側が並べ直すと別の行を指す)、`next` が今の状態と同じ形で
|
|
2276
|
+
* なければ `onStateChange` を 1 回呼ぶ。受けた時は true。
|
|
2277
|
+
*/
|
|
2278
|
+
const changeSortFilterState = useCallback(
|
|
2279
|
+
(next: SpreadsheetSortFilterState): boolean => {
|
|
2280
|
+
const host = sortFilterRef.current
|
|
2281
|
+
if (host === undefined) {
|
|
2282
|
+
return false
|
|
2283
|
+
}
|
|
2284
|
+
// 開いた入力のまま行の並びが変わると、続きの確定が並べ替えた後の別の行へ書く — 先に閉じる
|
|
2285
|
+
if (!requestCommit()) {
|
|
2286
|
+
return false
|
|
2287
|
+
}
|
|
2288
|
+
popoversRef.current?.hideTip()
|
|
2289
|
+
popoversRef.current?.close()
|
|
2290
|
+
discardClip()
|
|
2291
|
+
if (!sameSortFilterState(host.state, next)) {
|
|
2292
|
+
host.onStateChange(next)
|
|
2293
|
+
}
|
|
2294
|
+
return true
|
|
2295
|
+
},
|
|
2296
|
+
[requestCommit, discardClip],
|
|
2297
|
+
)
|
|
2298
|
+
|
|
2299
|
+
/**
|
|
2300
|
+
* A press on a sort header cell completed as a click or a tap (v0.20.3, from the selection engine): cycles the column's
|
|
2301
|
+
* sort through the funnel, then brings the focus back to the sink after a finger or pen tap.
|
|
2302
|
+
* 並べ替えの見出しのマスの押下がクリックか叩きで終わった時 (v0.20.3、選択のエンジンから)。手順を通して列の並べ替えを巡らせ、指とペンの
|
|
2303
|
+
* 叩きの後は焦点を受け口へ戻す。
|
|
2304
|
+
*/
|
|
2305
|
+
const onHeaderSortPress = useCallback(
|
|
2306
|
+
(col: number, pointerType: string) => {
|
|
2307
|
+
const host = sortFilterRef.current
|
|
2308
|
+
const resolved = resolvedSortFilterRef.current
|
|
2309
|
+
const column = resolved === null ? null : controlsColumnOf(resolved, col)
|
|
2310
|
+
// 押してから離すまでの間に利用側が指定を替え、並べ替えできなくなった列は巡らせない
|
|
2311
|
+
if (host !== undefined && column?.sortable === true) {
|
|
2312
|
+
changeSortFilterState(cycleSort(host.state, column.key))
|
|
2313
|
+
}
|
|
2314
|
+
// 止めた帯の行の箱は tabIndex −1 で、指で叩くと焦点がそこに留まる — 断られても受け口へ戻す
|
|
2315
|
+
if (pointerType !== "mouse") {
|
|
2316
|
+
focusSink({ preventScroll: true })
|
|
2317
|
+
}
|
|
2318
|
+
},
|
|
2319
|
+
[changeSortFilterState, focusSink],
|
|
2320
|
+
)
|
|
2321
|
+
|
|
2322
|
+
/** Opens or closes a column's menu from its ▼ button (v0.20.3). / ▼ のボタンから列の品書きを開くか閉じる (v0.20.3)。 */
|
|
2323
|
+
const toggleColumnMenu = useCallback((col: number) => {
|
|
2324
|
+
const controller = popoversRef.current
|
|
2325
|
+
const resolved = resolvedSortFilterRef.current
|
|
2326
|
+
if (controller === null || resolved === null) {
|
|
2327
|
+
return
|
|
2328
|
+
}
|
|
2329
|
+
const open = controller.context
|
|
2330
|
+
if (open !== null && open.kind === "columnMenu" && open.cell.col === col) {
|
|
2331
|
+
controller.close()
|
|
2332
|
+
return
|
|
2333
|
+
}
|
|
2334
|
+
controller.openColumnMenu({ row: resolved.headerRow, col })
|
|
2335
|
+
}, [])
|
|
2336
|
+
|
|
2337
|
+
/** The column name of a header cell: its shown text (the value format applied) with line breaks as spaces (v0.20.3). / 見出しのマスの列の名。見せる字 (値の書式を当てた物) の改行を空白にした物 (v0.20.3)。 */
|
|
2338
|
+
const headerNameOf = useCallback(
|
|
2339
|
+
(cell: CellCoord): string => {
|
|
2340
|
+
const text = adapter.getCellText(cell.row, cell.col)
|
|
2341
|
+
// 描いた書式の value は base の value (条件付き書式の語彙に value は無い) — マスの描画と同じ字にする
|
|
2342
|
+
return headerColumnName(adapter.getCellFormat === undefined ? text : formatCellValue(text, adapter.getCellFormat(cell.row, cell.col)?.value))
|
|
2343
|
+
},
|
|
2344
|
+
[adapter],
|
|
2345
|
+
)
|
|
2346
|
+
/** Whether a node is inside the grid's root (the column menu's blur rule). / ノードがグリッドの根の中か (列の品書きの blur の決まり)。 */
|
|
2347
|
+
const isInsideGrid = useCallback((node: Node): boolean => rootRef.current?.contains(node) === true, [])
|
|
2348
|
+
/** v0.20.3: whether a cell is a sort header cell (the engine's capability; absent while no column sorts). / v0.20.3: マスが並べ替えの見出しのマスか (エンジンの能力。並べ替えできる列が無ければ無し)。 */
|
|
2349
|
+
const isSortHeaderCell = useMemo(() => {
|
|
2350
|
+
if (resolvedSortFilter === null || !resolvedSortFilter.columns.some((column) => column?.sortable === true)) {
|
|
2351
|
+
return undefined
|
|
2352
|
+
}
|
|
2353
|
+
const resolved = resolvedSortFilter
|
|
2354
|
+
return (cell: CellCoord): boolean => cell.row === resolved.headerRow && resolved.columns[cell.col]?.sortable === true
|
|
2355
|
+
}, [resolvedSortFilter])
|
|
2356
|
+
/** v0.20.3: the resolved column of a header cell carrying column controls (the column-menu capability; absent while no column has controls). / v0.20.3: 列の操作を持つ見出しのマスの解いた列 (列の品書きの能力。操作を持つ列が無ければ無し)。 */
|
|
2357
|
+
const columnMenuAt = useMemo(() => {
|
|
2358
|
+
if (resolvedSortFilter === null || !resolvedSortFilter.hasControls) {
|
|
2359
|
+
return undefined
|
|
2360
|
+
}
|
|
2361
|
+
const resolved = resolvedSortFilter
|
|
2362
|
+
return (cell: CellCoord): ResolvedSortFilterColumn | null => (cell.row === resolved.headerRow ? controlsColumnOf(resolved, cell.col) : null)
|
|
2363
|
+
}, [resolvedSortFilter])
|
|
2364
|
+
|
|
2108
2365
|
/** Transaction counter (v0.8 §4.2.13 / §1.3): one strictly increasing id per applyEdits call of THIS grid instance (a rejected call consumes its id too — an id the adapter has seen is never reused) — the consumer's undo groups by it. / トランザクション採番 (v0.8 §4.2.13 / §1.3): このグリッド実体の applyEdits 呼び出し 1 回につき厳密増加の id 1 つ (拒否された呼び出しも id を消費 — アダプタが見た id は再利用しない) — consumer の Undo はこれで束ねる。 */
|
|
2109
2366
|
const transactionRef = useRef(0)
|
|
2110
2367
|
/**
|
|
@@ -2372,6 +2629,9 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
2372
2629
|
onHyperlinkOpen(url, cell)
|
|
2373
2630
|
return true
|
|
2374
2631
|
},
|
|
2632
|
+
// v0.20.3 (sortFilter): 並べ替えの見出しのマスの押下 (マウスのクリック・指とペンの叩き) — 並べ替えできる列が無ければ能力ごと無し
|
|
2633
|
+
isSortHeaderCell,
|
|
2634
|
+
onHeaderSortPress,
|
|
2375
2635
|
})
|
|
2376
2636
|
|
|
2377
2637
|
// ---- ヘッダー選択 (§6.8 — 列 / 行の転置共通機械) ----
|
|
@@ -2571,6 +2831,7 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
2571
2831
|
repaintOverlay,
|
|
2572
2832
|
// 検証ゲート (v0.8 §4.2.6) — 編集列 fillSelection と共有する root の useCallback
|
|
2573
2833
|
validateCommit,
|
|
2834
|
+
onSessionChange: onEditSessionChange,
|
|
2574
2835
|
})
|
|
2575
2836
|
// レンダー時代入でシームを実体へ接続 (paramsRef と同じ規律 — 構築循環切りの ref 間接)
|
|
2576
2837
|
isEditingRef.current = editor.isEditing
|
|
@@ -2650,6 +2911,8 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
2650
2911
|
repaintOverlay,
|
|
2651
2912
|
// v0.10: G14a / G14b / G14c の拒否漏斗 (§6.4)
|
|
2652
2913
|
rejectReadOnly,
|
|
2914
|
+
// v0.20.3 (sortFilter): 列の品書き — 操作を持つ列が無ければ能力ごと無し (層の導出は v0.20.2 と同じ)
|
|
2915
|
+
columnMenuAt,
|
|
2653
2916
|
})
|
|
2654
2917
|
popoversRef.current = popovers
|
|
2655
2918
|
openPopoverRef.current = popovers.open
|
|
@@ -2700,6 +2963,8 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
2700
2963
|
keyboardCellRect,
|
|
2701
2964
|
// v0.10: G8–G13 / G15 の拒否漏斗 (§6.4)
|
|
2702
2965
|
rejectReadOnly,
|
|
2966
|
+
// v0.20.3 (sortFilter): 操作の列の見出しのマスの Alt+↓ は列の品書き
|
|
2967
|
+
columnMenu: columnMenuAt === undefined ? undefined : { isColumnMenuCell: (cell) => columnMenuAt(cell) !== null, open: popovers.openColumnMenu },
|
|
2703
2968
|
})
|
|
2704
2969
|
commandsRef.current = commands
|
|
2705
2970
|
executeCommandRef.current = commands.executeCommand
|
|
@@ -2766,6 +3031,36 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
2766
3031
|
onPointFrame,
|
|
2767
3032
|
})
|
|
2768
3033
|
|
|
3034
|
+
// ---- 列の品書き (v0.20.3 — sortFilter) の描く時の入力 ----
|
|
3035
|
+
const hasColumnControls = resolvedSortFilter?.hasControls === true
|
|
3036
|
+
const openColumnMenuCol = popovers.context !== null && popovers.context.kind === "columnMenu" ? popovers.context.cell.col : null
|
|
3037
|
+
/** The column menu buttons' inputs (value-stable: changes only with the open column, the two labels or the controls' presence). / 列の品書きのボタンへの入力 (値で安定 — 開いている列・言葉 2 つ・操作の有無が変わった時だけ替わる)。 */
|
|
3038
|
+
const gridColumnMenu = useMemo(
|
|
3039
|
+
(): GridColumnMenu | null => (hasColumnControls ? { openCol: openColumnMenuCol, menuLabel: resolvedLabels.columnMenu, filteredLabel: resolvedLabels.columnMenuFiltered, onToggle: toggleColumnMenu } : null),
|
|
3040
|
+
[hasColumnControls, openColumnMenuCol, resolvedLabels.columnMenu, resolvedLabels.columnMenuFiltered, toggleColumnMenu],
|
|
3041
|
+
)
|
|
3042
|
+
/** The column menu's live inputs for the popover layer. / ポップオーバーの層へ渡す列の品書きの今の入力。 */
|
|
3043
|
+
const columnMenuLayer = useMemo(
|
|
3044
|
+
(): ColumnMenuLayerProps | null =>
|
|
3045
|
+
sortFilter === undefined || resolvedSortFilter === null || !resolvedSortFilter.hasControls
|
|
3046
|
+
? null
|
|
3047
|
+
: { resolved: resolvedSortFilter, state: sortFilter.state, getFilterValues: sortFilter.getFilterValues, changeState: changeSortFilterState, columnNameOf: headerNameOf, isInsideGrid },
|
|
3048
|
+
[sortFilter, resolvedSortFilter, changeSortFilterState, headerNameOf, isInsideGrid],
|
|
3049
|
+
)
|
|
3050
|
+
// 開いている列の品書きは、その見出しのマスがもう開いた時と同じ列の操作でなければ閉じる (鍵を失った・指定で操作を失った・見出しの行が
|
|
3051
|
+
// 動いた・指定ごと外れた・空の表になった)。焦点はグリッドの中にある時だけ受け口へ戻す (利用側の欄の打鍵先を奪わない)
|
|
3052
|
+
useLayoutEffect(() => {
|
|
3053
|
+
const controller = popoversRef.current
|
|
3054
|
+
const ctx = controller === null ? null : controller.context
|
|
3055
|
+
if (controller === null || ctx === null || ctx.kind !== "columnMenu") {
|
|
3056
|
+
return
|
|
3057
|
+
}
|
|
3058
|
+
const live = resolvedSortFilter === null || ctx.cell.row !== resolvedSortFilter.headerRow ? null : controlsColumnOf(resolvedSortFilter, ctx.cell.col)
|
|
3059
|
+
if (live === null || !sameResolvedColumn(live, ctx.column)) {
|
|
3060
|
+
controller.closeColumnMenu({ restoreFocus: rootRef.current?.contains(document.activeElement) === true })
|
|
3061
|
+
}
|
|
3062
|
+
}, [resolvedSortFilter])
|
|
3063
|
+
|
|
2769
3064
|
// ---- 入力メッセージ (root 方針): active セルが変わるたび、前のメッセージを畳んで新セルの inputMessage を出す ----
|
|
2770
3065
|
const activeRow = selection.active.row
|
|
2771
3066
|
const activeCol = selection.active.col
|
|
@@ -3076,7 +3371,7 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
3076
3371
|
selectionRef.current = INITIAL_SELECTION
|
|
3077
3372
|
setSelectionState(INITIAL_SELECTION)
|
|
3078
3373
|
} else {
|
|
3079
|
-
|
|
3374
|
+
writeSelection(INITIAL_SELECTION, "sheetSwitch")
|
|
3080
3375
|
}
|
|
3081
3376
|
// クリップはシート切替の意味論 (v0.8 §4.2.5): copy は破棄、cut は foreign として保持し
|
|
3082
3377
|
// 切替先の paste を跨ぎ move にする (マーキーは foreign で非表示 — 旧シート座標を新軸で
|
|
@@ -3086,7 +3381,7 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
3086
3381
|
// effect 化する将来変更でこの順序が実防壁になるため維持する
|
|
3087
3382
|
onAdapterSwitchRef.current()
|
|
3088
3383
|
}
|
|
3089
|
-
}, [hostAdapter, isEmpty,
|
|
3384
|
+
}, [hostAdapter, isEmpty, writeSelection, engine, colHeaderMachine, rowHeaderMachine, headerResizeMachine, fillMachine, pointDrag, viewStore, editor.cancelEdit])
|
|
3090
3385
|
|
|
3091
3386
|
// ---- 行数 / 列数の縮小 (同一 adapter — 絞り込み / カテゴリ / 期間の変更で明細が減る) は保持中の
|
|
3092
3387
|
// 座標を新グリッドへ畳む (ADR-33) ----
|
|
@@ -3101,7 +3396,7 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
3101
3396
|
// 旧クロージャ = 旧軸、将来 layout effect 化しても新軸) どちらのクロージャでも安全 — 切替 effect の
|
|
3102
3397
|
// 「防御的順序」を一段強めた形
|
|
3103
3398
|
const prevCountsRef = useRef({ adapter, rows: rowAxis.count, cols: colAxis.count })
|
|
3104
|
-
const { getSessionCell, cancelEdit: cancelEditSession } = editor
|
|
3399
|
+
const { getSessionCell, getSession, cancelEdit: cancelEditSession } = editor
|
|
3105
3400
|
useLayoutEffect(() => {
|
|
3106
3401
|
const prev = prevCountsRef.current
|
|
3107
3402
|
const rows = rowAxis.count
|
|
@@ -3116,7 +3411,7 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
3116
3411
|
setSelectionState(INITIAL_SELECTION)
|
|
3117
3412
|
} else {
|
|
3118
3413
|
// 選択は端へ畳む — 範囲外が無ければ同一 object が返り、ラッパーの Object.is bail で通知なし
|
|
3119
|
-
|
|
3414
|
+
writeSelection(clampSelectionToGrid(selectionRef.current, rows, cols), "countShrink")
|
|
3120
3415
|
}
|
|
3121
3416
|
// 飛行中ドラッグは復元なしで取り消す (各機械の dragBeforeRef は旧グリッド座標 — 切替シームと同文)
|
|
3122
3417
|
engine.cancelDrag()
|
|
@@ -3148,7 +3443,7 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
3148
3443
|
if (clip !== null && !clip.foreign && outside({ row: clip.range.endRow, col: clip.range.endCol })) {
|
|
3149
3444
|
discardClip()
|
|
3150
3445
|
}
|
|
3151
|
-
}, [adapter, rowAxis.count, colAxis.count, isEmpty,
|
|
3446
|
+
}, [adapter, rowAxis.count, colAxis.count, isEmpty, writeSelection, engine, colHeaderMachine, rowHeaderMachine, headerResizeMachine, fillMachine, pointDrag, getSessionCell, cancelEditSession, getClip, discardClip])
|
|
3152
3447
|
|
|
3153
3448
|
// ---- 凍結列数の変化 (v0.5 ライブ prop) は飛行中ジェスチャを復元なしで取り消す ----
|
|
3154
3449
|
// 押下時の grab オフセット / アンカーは旧パーティション座標系で確立済み — 変更後の鮮度
|
|
@@ -3281,6 +3576,27 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
3281
3576
|
setValidation: (rule: DataValidationRule | null) => requireCommands().setValidation(rule),
|
|
3282
3577
|
paste: (options: PasteOptions) => pasteRef.current(options),
|
|
3283
3578
|
getSelection: () => selectionRef.current,
|
|
3579
|
+
setSelection: (selection: SelectionState, options?: SetSelectionOptions): boolean => {
|
|
3580
|
+
// 形の誤りは状態に依らず投げる — 入力中でもドラッグの途中でも、呼び手の誤りは誤り
|
|
3581
|
+
const placed = placedSelectionOf(selection, rowAxis.count, colAxis.count)
|
|
3582
|
+
const scroll = setSelectionScrolls(options)
|
|
3583
|
+
// 入力中は入力を勝手に閉じない (エディタは入力中のマスに付いている)。ドラッグの途中は利用者の操作を奪わない
|
|
3584
|
+
if (isEditing() || isAnyDragging()) {
|
|
3585
|
+
return false
|
|
3586
|
+
}
|
|
3587
|
+
writeSelection(placed, "setSelection")
|
|
3588
|
+
if (scroll) {
|
|
3589
|
+
ensureCellVisible(placed.active)
|
|
3590
|
+
}
|
|
3591
|
+
return true
|
|
3592
|
+
},
|
|
3593
|
+
getEditSession: getSession,
|
|
3594
|
+
commitEdit: (): CommitEditOutcome => {
|
|
3595
|
+
if (!isEditing()) {
|
|
3596
|
+
return "idle"
|
|
3597
|
+
}
|
|
3598
|
+
return requestCommit() ? "committed" : "rejected"
|
|
3599
|
+
},
|
|
3284
3600
|
// base = アダプタ書式 (能力分岐)、painted = base ⊕ CF (単一シーム resolvePaintedFormat)
|
|
3285
3601
|
getBaseFormat: (cell: CellCoord) => (adapter.getCellFormat === undefined ? undefined : adapter.getCellFormat(cell.row, cell.col)),
|
|
3286
3602
|
getPaintedFormat: (cell: CellCoord) => (adapter.getCellFormat === undefined ? undefined : paintedFormatOf(cell.row, cell.col, lazyCellText(adapter, cell.row, cell.col))),
|
|
@@ -3292,7 +3608,29 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
3292
3608
|
openPopoverRef.current(kind)
|
|
3293
3609
|
},
|
|
3294
3610
|
}),
|
|
3295
|
-
[
|
|
3611
|
+
[
|
|
3612
|
+
rowAxis,
|
|
3613
|
+
colAxis,
|
|
3614
|
+
viewStore,
|
|
3615
|
+
repaintColHeaders,
|
|
3616
|
+
repaintHeaders,
|
|
3617
|
+
repaintOverlay,
|
|
3618
|
+
scheduleDividerHeal,
|
|
3619
|
+
reportContentSize,
|
|
3620
|
+
headerResizeMachine,
|
|
3621
|
+
focusSink,
|
|
3622
|
+
isEditing,
|
|
3623
|
+
rearmSink,
|
|
3624
|
+
adapter,
|
|
3625
|
+
paintedFormatOf,
|
|
3626
|
+
startEdit,
|
|
3627
|
+
requireCommands,
|
|
3628
|
+
writeSelection,
|
|
3629
|
+
isAnyDragging,
|
|
3630
|
+
ensureCellVisible,
|
|
3631
|
+
getSession,
|
|
3632
|
+
requestCommit,
|
|
3633
|
+
],
|
|
3296
3634
|
)
|
|
3297
3635
|
|
|
3298
3636
|
// ---- 空グリッド分岐 (§6.9-1: フックの後・結線の前) ----
|
|
@@ -3438,6 +3776,8 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
3438
3776
|
isPointing={isPointing}
|
|
3439
3777
|
locale={uiLocale}
|
|
3440
3778
|
scrollLabels={scrollLabels}
|
|
3779
|
+
sortFilter={resolvedSortFilter}
|
|
3780
|
+
columnMenu={gridColumnMenu}
|
|
3441
3781
|
/>
|
|
3442
3782
|
<SelectionOverlay
|
|
3443
3783
|
rowAxis={rowAxis}
|
|
@@ -3473,7 +3813,7 @@ export const Spreadsheet = forwardRef<SpreadsheetHandle, SpreadsheetProps & Spre
|
|
|
3473
3813
|
tipAnchorRef={tipAnchorRef}
|
|
3474
3814
|
/>
|
|
3475
3815
|
{/* ポップオーバー層 (ADR-15): overlay の直後の兄弟 (CSS の前提順)。層は導出規則が true のときだけ DOM を持つ */}
|
|
3476
|
-
{popovers.layerEnabled ? <PopoverLayer controller={popovers} labels={resolvedLabels} renderPopover={renderPopover} interactiveAnchorRef={interactiveAnchorRef} tipAnchorRef={tipAnchorRef} /> : null}
|
|
3816
|
+
{popovers.layerEnabled ? <PopoverLayer controller={popovers} labels={resolvedLabels} renderPopover={renderPopover} interactiveAnchorRef={interactiveAnchorRef} tipAnchorRef={tipAnchorRef} columnMenu={columnMenuLayer} /> : null}
|
|
3477
3817
|
</div>
|
|
3478
3818
|
{hasAnnouncement ? <div ref={liveRegionRef} className="aqsp-live-region" aria-live="polite" data-aqsp-live-region="" /> : null}
|
|
3479
3819
|
</div>
|