@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
|
@@ -49,6 +49,10 @@
|
|
|
49
49
|
* bail and the dispatch-level `requestCommit` (content-present annotate chords fall through and
|
|
50
50
|
* open the viewer; content-absent and the list chord consume + refuse without force-committing).
|
|
51
51
|
* Capability undeclared = every wall compiles to the previous behaviour byte-identically.
|
|
52
|
+
* - v0.20.3 (`sortFilter`, the `columnMenu` capability): on a header cell carrying column controls
|
|
53
|
+
* `openValidationList` (Alt+ArrowDown by default) opens the column menu instead — available there
|
|
54
|
+
* whatever the validation capability, and never through G15 (sorting and filtering change the
|
|
55
|
+
* view, not the data); the menu runs its own commit gate. Every other cell is unchanged.
|
|
52
56
|
*
|
|
53
57
|
* コマンド実行器 (v0.8 §4.1.13 — ADR-17)。75 の SpreadsheetCommand 全件の executeCommand、handle の
|
|
54
58
|
* 書込群 (applyFormat / setBorders / setHyperlink / setNote / addComment / setValidation)、能力
|
|
@@ -85,6 +89,9 @@
|
|
|
85
89
|
* G13 注釈 setter ×4 (commit-gate-first 維持)、G15 = popover 系 4 コマンド id の単一 pre-check
|
|
86
90
|
* (availability bail と dispatch 水準 requestCommit の間 — 内容有の注釈チョードはビューア開通、
|
|
87
91
|
* 内容無と list は force-commit なしの消費拒否)。能力未宣言 = 全壁が従来挙動と byte 恒等。
|
|
92
|
+
* v0.20.3 (`sortFilter` の `columnMenu` 能力): 列の操作を持つ見出しのマスでは `openValidationList` (既定は Alt+↓) が
|
|
93
|
+
* 列の品書きを開く — そのマスでは検証の能力を問わず使え、G15 は通らない (並べ替えと絞り込みはデータでなく見た目を
|
|
94
|
+
* 変える)。確定の関門は品書きの側が通す。ほかのマスは変わらない。
|
|
88
95
|
*/
|
|
89
96
|
|
|
90
97
|
import { useCallback, useMemo, useRef } from "react"
|
|
@@ -181,6 +188,14 @@ export type UseCommandsParams = {
|
|
|
181
188
|
/** Live-region text after a keyboard resize (the active track's new size); absent ⇒ silent. / キーボードの寸法の変更の後の読み上げ (アクティブなトラックの新しい寸法)。無ければ無音。 */
|
|
182
189
|
formatResizeAnnouncement?: (ctx: { command: SpreadsheetCommand; axis: "row" | "column"; index: number; size: number }) => string
|
|
183
190
|
keyboardCellRect: () => KeyboardCellRect
|
|
191
|
+
/**
|
|
192
|
+
* v0.20.3 capability (`sortFilter`): the column menu of the header cells carrying column controls. `isColumnMenuCell`
|
|
193
|
+
* names those cells; `open` opens the menu on one (false = it did not open, e.g. the commit was refused). Undefined =
|
|
194
|
+
* `openValidationList` behaves as before on every cell.
|
|
195
|
+
* v0.20.3 能力 (`sortFilter`): 列の操作を持つ見出しのマスの列の品書き。`isColumnMenuCell` はそのマスを名指し、`open` はそこで
|
|
196
|
+
* 品書きを開く (false は開かなかった — 確定の断りなど)。undefined なら `openValidationList` はどのマスでも今までどおり。
|
|
197
|
+
*/
|
|
198
|
+
columnMenu?: { readonly isColumnMenuCell: (cell: CellCoord) => boolean; readonly open: (cell: CellCoord) => boolean }
|
|
184
199
|
}
|
|
185
200
|
|
|
186
201
|
/** The handle's write group + the command entry points (v0.8 §1.10 / §4.1.13). / handle の書込群 + コマンド入口 (v0.8 §1.10 / §4.1.13)。 */
|
|
@@ -789,6 +804,10 @@ export const useCommands = (params: UseCommandsParams): CommandRunner => {
|
|
|
789
804
|
const spec = COMMAND_SPECS[command]
|
|
790
805
|
const formatDeclared = adapter.getCellFormat !== undefined
|
|
791
806
|
const popoverEnabled = (kind: PopoverKind): boolean => (p.popovers === undefined ? true : p.popovers[kind] !== false)
|
|
807
|
+
// v0.20.3: 列の操作を持つ見出しのマスでは Alt+↓ の行は列の品書きの物 — 検証の能力が無くても行がある
|
|
808
|
+
if (spec.kind === "popover" && spec.popover === "list" && p.columnMenu?.isColumnMenuCell(p.getActive()) === true) {
|
|
809
|
+
return true
|
|
810
|
+
}
|
|
792
811
|
switch (spec.kind) {
|
|
793
812
|
case "resize":
|
|
794
813
|
return p.trackResize !== undefined
|
|
@@ -919,6 +938,14 @@ export const useCommands = (params: UseCommandsParams): CommandRunner => {
|
|
|
919
938
|
return false
|
|
920
939
|
}
|
|
921
940
|
const spec = COMMAND_SPECS[command]
|
|
941
|
+
// v0.20.3: 列の操作を持つ見出しのマスの Alt+↓ は列の品書き (Excel の「そのマスの ▼ を開く」)。並べ替えと絞り込みは
|
|
942
|
+
// 見た目の変更なので G15 の読むだけの断りを通らず、確定の関門は品書きの側が通す
|
|
943
|
+
if (spec.kind === "popover" && spec.popover === "list" && p.columnMenu !== undefined) {
|
|
944
|
+
const active = p.getActive()
|
|
945
|
+
if (p.columnMenu.isColumnMenuCell(active)) {
|
|
946
|
+
return p.columnMenu.open(active)
|
|
947
|
+
}
|
|
948
|
+
}
|
|
922
949
|
// G15 (v0.10 §6.9 / 設計 ADR-30): popover を開くディスパッチ (popover 系 4 コマンド id +
|
|
923
950
|
// openHyperlink の host 未宣言 fallback) の**単一** pre-check — 座席は availability bail と
|
|
924
951
|
// dispatch 水準 requestCommit の**間** (doomed-open 原則: 拒否腕は無関係セッションを
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
* ants kept, no scroll jump, before seeding) and G16 live-re-checks the session cell at
|
|
24
24
|
* `finishEdit` commit time (after the unchanged short-circuit, before `validateCommit`);
|
|
25
25
|
* both fire the required `rejectReadOnly` funnel, and an undeclared capability is byte-identical.
|
|
26
|
+
* The session opens only in `startEdit` and closes only in `finishEdit`'s `closeSession`, so the host's
|
|
27
|
+
* `onEditSessionChange` (the `onSessionChange` param) hears every open and every close from those two points.
|
|
26
28
|
*
|
|
27
29
|
* セル編集セッション状態機械 (§6.7.1)。idle / editing(edit) / editing(replace) のセッション
|
|
28
30
|
* 状態・composition 追跡・グリッド外 focusout commit・suppressFocusoutCommit を所有する。
|
|
@@ -41,7 +43,8 @@
|
|
|
41
43
|
* v0.10 読み取り専用セル (計画 §6.3): G1 は全 6 入口の単一漏斗 `startEdit` で編集モード進入を
|
|
42
44
|
* 拒否し (sink-null bail と `discardClip` の間 — アンツ保持・スクロール不跳び・シード前)、G16 は
|
|
43
45
|
* `finishEdit` の確定時にセッションセルを生再検査する (無変更短絡の後・`validateCommit` の前)。
|
|
44
|
-
* どちらも必須 `rejectReadOnly`
|
|
46
|
+
* どちらも必須 `rejectReadOnly` 漏斗へ発火し、能力未宣言は従来挙動とバイト同一。セッションが開くのは `startEdit`、閉じるのは
|
|
47
|
+
* `finishEdit` の `closeSession` だけなので、利用側の `onEditSessionChange` (`onSessionChange` 引数) は全ての開閉をこの 2 点から聞く。
|
|
45
48
|
*/
|
|
46
49
|
|
|
47
50
|
import { type RefObject, useCallback, useEffect, useMemo, useRef, useState } from "react"
|
|
@@ -52,8 +55,19 @@ import { type CellEdit, type EditRejection, isReadOnlyCell, type ReadOnlyRejecti
|
|
|
52
55
|
import type { ValidationVerdict } from "../model/dataValidation.ts"
|
|
53
56
|
import { cycleAnchorAt, findReferenceAt, formatRangeReference, isPointingPrefix, type PointingTarget, type ReferenceAxis } from "../model/formulaRefs.ts"
|
|
54
57
|
|
|
55
|
-
/**
|
|
56
|
-
|
|
58
|
+
/**
|
|
59
|
+
* The open in-place edit session (§6.7.1): the cell it writes to, captured when it opened, and how it opened — `"edit"`
|
|
60
|
+
* (F2, a double-click, `startEdit("edit")`: the cell's text with the caret in it) or `"replace"` (a printable key, an IME
|
|
61
|
+
* composition, `startEdit("replace")`: an empty editor). Reported by `onEditSessionChange` and read by the handle's
|
|
62
|
+
* `getEditSession`; the grid replaces the object, never mutates it.
|
|
63
|
+
* 開いているその場の入力のセッション (§6.7.1): 開いた時に捉えた書き込み先のマスと、開き方 — `"edit"` (F2・ダブルクリック・
|
|
64
|
+
* `startEdit("edit")`。マスの字にキャレット) か `"replace"` (印字キー・IME の変換・`startEdit("replace")`。空の入力欄)。
|
|
65
|
+
* `onEditSessionChange` が知らせ、handle の `getEditSession` が読む。グリッドは物を差し替え、書き換えない。
|
|
66
|
+
*/
|
|
67
|
+
export type EditSession = { readonly cell: CellCoord; readonly mode: "edit" | "replace" }
|
|
68
|
+
|
|
69
|
+
/** Editing mode (§6.7.1 state diagram) — the session's own `mode`. / 編集モード (セッションの `mode` そのもの)。 */
|
|
70
|
+
export type EditingMode = EditSession["mode"]
|
|
57
71
|
|
|
58
72
|
/** Sink snapshot for the reference-drag Escape restore (value + caret range before the drag). / 参照ドラッグの Escape 復元用シンク断面 (ドラッグ前の value とキャレット区間)。 */
|
|
59
73
|
export type SinkSnapshot = { value: string; selectionStart: number; selectionEnd: number }
|
|
@@ -151,6 +165,16 @@ type UseCellEditorParams = {
|
|
|
151
165
|
* keep / discard 経路。undefined = 検証なし (v0.7 恒等)。
|
|
152
166
|
*/
|
|
153
167
|
validateCommit?: (cell: CellCoord, text: string) => ValidationVerdict
|
|
168
|
+
/**
|
|
169
|
+
* The host's `onEditSessionChange`, read when called (a re-render with another function takes effect at the next
|
|
170
|
+
* open or close): the new session right after it opens, `null` right after it closes — after `applyEdits` returned
|
|
171
|
+
* for a commit, before the key that committed moves the active cell. A refused commit that keeps the session open
|
|
172
|
+
* closes nothing and calls nothing. Undefined = no notice.
|
|
173
|
+
* 利用側の `onEditSessionChange` (呼ぶ時に読む — 別の関数での再描画は次の開閉から効く): 開いた直後に新しいセッション、閉じた直後に
|
|
174
|
+
* `null` — 確定なら `applyEdits` が戻った後、確定したキーがアクティブなマスを動かす前。入力を続ける断りは何も閉じず何も呼ばない。
|
|
175
|
+
* undefined = 知らせない。
|
|
176
|
+
*/
|
|
177
|
+
onSessionChange?: (session: EditSession | null) => void
|
|
154
178
|
}
|
|
155
179
|
|
|
156
180
|
/** Seams consumed by the keymap and the pointer machines. / キーマップ / ポインタ機械が消費するシーム。 */
|
|
@@ -182,6 +206,8 @@ export type CellEditor = PointingSeams & {
|
|
|
182
206
|
getSessionText: () => string | null
|
|
183
207
|
/** The session's cell, or null when idle — the count-shrink clamp cancels a session whose cell left the grid. / セッションのセル (idle は null) — 行数 / 列数縮小の畳込みが、グリッドから消えたセルのセッションを取り消す判定に使う。 */
|
|
184
208
|
getSessionCell: () => CellCoord | null
|
|
209
|
+
/** The open session — the same object `onSessionChange` reported — or null when idle (the handle's `getEditSession`). / 開いているセッション (`onSessionChange` が知らせた物と同じ物)、idle は null (handle の `getEditSession`)。 */
|
|
210
|
+
getSession: () => EditSession | null
|
|
185
211
|
/** Recomputes and re-applies the edit paint after an editing-column format toggle, then repaints the overlay. / 編集列の書式トグル後に塗りを再計算・再適用し overlay を再描画。 */
|
|
186
212
|
refreshPaint: () => void
|
|
187
213
|
/** React state mirror for the overlay's editing prop (§6.7.2-4). / overlay の editing prop 用ミラー。 */
|
|
@@ -224,7 +250,7 @@ export const useCellEditor = (params: UseCellEditorParams): CellEditor => {
|
|
|
224
250
|
paramsRef.current = params
|
|
225
251
|
|
|
226
252
|
/** In-flight session (null = idle); commit writes to the cell captured at start. / 飛行中セッション。commit は開始時に捕捉したセルへ書く。 */
|
|
227
|
-
const sessionRef = useRef<
|
|
253
|
+
const sessionRef = useRef<EditSession | null>(null)
|
|
228
254
|
const [editing, setEditing] = useState(false)
|
|
229
255
|
const isComposingRef = useRef(false)
|
|
230
256
|
const suppressFocusoutCommitRef = useRef(false)
|
|
@@ -348,6 +374,7 @@ export const useCellEditor = (params: UseCellEditorParams): CellEditor => {
|
|
|
348
374
|
sink.removeAttribute(POINTING_ATTRIBUTE)
|
|
349
375
|
}
|
|
350
376
|
setEditing(false)
|
|
377
|
+
p.onSessionChange?.(null)
|
|
351
378
|
}
|
|
352
379
|
if (options.commit) {
|
|
353
380
|
const sink = p.sinkRef.current
|
|
@@ -464,8 +491,10 @@ export const useCellEditor = (params: UseCellEditorParams): CellEditor => {
|
|
|
464
491
|
// 非武装のため述語は構造的に不成立で、ヒント属性は前セッションの closeSession が除去済み
|
|
465
492
|
pointingArmedRef.current = false
|
|
466
493
|
pointingAnchorRef.current = null
|
|
467
|
-
|
|
494
|
+
const session: EditSession = { cell: active, mode }
|
|
495
|
+
sessionRef.current = session
|
|
468
496
|
setEditing(true)
|
|
497
|
+
p.onSessionChange?.(session)
|
|
469
498
|
},
|
|
470
499
|
[applyPaint],
|
|
471
500
|
)
|
|
@@ -659,6 +688,8 @@ export const useCellEditor = (params: UseCellEditorParams): CellEditor => {
|
|
|
659
688
|
|
|
660
689
|
const getSessionCell = useCallback((): CellCoord | null => (sessionRef.current === null ? null : sessionRef.current.cell), [])
|
|
661
690
|
|
|
691
|
+
const getSession = useCallback((): EditSession | null => sessionRef.current, [])
|
|
692
|
+
|
|
662
693
|
const refreshPaint = useCallback((): void => {
|
|
663
694
|
const p = paramsRef.current
|
|
664
695
|
const session = sessionRef.current
|
|
@@ -754,9 +785,10 @@ export const useCellEditor = (params: UseCellEditorParams): CellEditor => {
|
|
|
754
785
|
insertAtCaret,
|
|
755
786
|
getSessionText,
|
|
756
787
|
getSessionCell,
|
|
788
|
+
getSession,
|
|
757
789
|
refreshPaint,
|
|
758
790
|
editing,
|
|
759
791
|
}),
|
|
760
|
-
[requestCommit, cancelEdit, startEdit, getPointing, togglePointingArm, getReferenceCursor, insertReference, captureSink, restoreSink, cycleAnchorAtCaret, insertAtCaret, getSessionText, getSessionCell, refreshPaint, editing],
|
|
792
|
+
[requestCommit, cancelEdit, startEdit, getPointing, togglePointingArm, getReferenceCursor, insertReference, captureSink, restoreSink, cycleAnchorAtCaret, insertAtCaret, getSessionText, getSessionCell, getSession, refreshPaint, editing],
|
|
761
793
|
)
|
|
762
794
|
}
|
package/src/grid/GridBody.tsx
CHANGED
|
@@ -45,6 +45,12 @@
|
|
|
45
45
|
* forwarded to VirtualGrid, which localizes the embedded vertical bar, the horizontal bar and the
|
|
46
46
|
* degenerate-band "No items" — no lang attribute, no new data-* hook.
|
|
47
47
|
*
|
|
48
|
+
* Sort and filter controls (v0.20.3, `sortFilter`): with a resolved `sortFilter`, every header cell of the last header
|
|
49
|
+
* row whose column sorts or filters carries `data-aqsp-column-controls` (the stylesheet keeps its text clear of the
|
|
50
|
+
* button), the sorted one `aria-sort` and `data-aqsp-sort`, a filtered one `data-aqsp-filtered`, and its content is the
|
|
51
|
+
* cell renderer followed by the column menu button (`HeaderControls`, named after the cell's shown text). Without it no
|
|
52
|
+
* attribute and no button is added — the cell DOM is the v0.20.2 one.
|
|
53
|
+
*
|
|
48
54
|
* グリッド本体。VirtualGrid 結線 (両軸) とセルレンダラーを所有する。v0.4 から横軸は VirtualGrid
|
|
49
55
|
* の所有 (量子化列アンカー + 残差 transform + 横バー) — v0.3 の列スタック (useColumnWindow /
|
|
50
56
|
* --aqsp-hx CSS 変数 / 軸原点絶対 left / 自前 HScrollBar) は設計計画 §7-1 に従い削除。
|
|
@@ -81,6 +87,11 @@
|
|
|
81
87
|
*
|
|
82
88
|
* UI クロームロケール: 解決済み `locale` と値安定なエンジン部分集合 `scrollLabels` を VirtualGrid へ
|
|
83
89
|
* 素通しし、埋込み縦バー・横バー・退化帯の "No items" を現地化する (lang 属性・新規 data-* フックなし)。
|
|
90
|
+
*
|
|
91
|
+
* 並べ替えと絞り込みの操作 (v0.20.3、`sortFilter`): 解いた `sortFilter` があれば、見出しの最後の行のうち並べ替えできるか絞り込める列の
|
|
92
|
+
* マスに `data-aqsp-column-controls` (スタイルが字をボタンから離す)、並べ替えている列に `aria-sort` と `data-aqsp-sort`、絞り込んでいる列に
|
|
93
|
+
* `data-aqsp-filtered` を付け、中身はセルの描き手の後に列の品書きのボタン (`HeaderControls`。名前はマスの見せる字から) を置く。無ければ
|
|
94
|
+
* 属性もボタンも足さない (マスの DOM は v0.20.2 と同じ)。
|
|
84
95
|
*/
|
|
85
96
|
|
|
86
97
|
import { type ScrollBarTapCircleOptions, VirtualGrid, type VirtualGridHandle, type VirtualGridRange, type VirtualScrollLabels, type VirtualScrollScrollBarOptions } from "@aiquants/virtualscroll"
|
|
@@ -94,6 +105,8 @@ import { isReadOnlyCell, lazyCellText, resolveCellAlign, resolveCellAttributes,
|
|
|
94
105
|
import { isVisiblyInvalid } from "../model/dataValidation.ts"
|
|
95
106
|
import type { SpreadsheetLocale } from "../model/labels.ts"
|
|
96
107
|
import type { ViewStore } from "../model/viewStore.ts"
|
|
108
|
+
import { HeaderControls } from "../sortFilter/HeaderControls.tsx"
|
|
109
|
+
import { controlsColumnOf, headerColumnName, type ResolvedSortFilter } from "../sortFilter/sortFilterModel.ts"
|
|
97
110
|
import { SPREADSHEET_SCROLLBAR_SIZE_PX } from "../view.ts"
|
|
98
111
|
import { CellView, type RenderCellContext } from "./CellView.tsx"
|
|
99
112
|
|
|
@@ -300,6 +313,15 @@ export const resolveRichCellProps = (adapter: SpreadsheetDataAdapter, rowAxis: A
|
|
|
300
313
|
return { attrs, style, value }
|
|
301
314
|
}
|
|
302
315
|
|
|
316
|
+
/**
|
|
317
|
+
* What the column menu buttons need besides the resolved `sortFilter` (v0.20.3): the column whose menu is open, the two
|
|
318
|
+
* resolved label strings of the button's name and the identity-stable toggle. The root memoizes it, so it changes only
|
|
319
|
+
* when one of these does.
|
|
320
|
+
* 解いた `sortFilter` のほかに列の品書きのボタンが要る物 (v0.20.3)。品書きが開いている列・ボタンの名前の解いた言葉 2 つ・同一性の安定した
|
|
321
|
+
* 開閉。root が memo するので、どれかが変わった時だけ替わる。
|
|
322
|
+
*/
|
|
323
|
+
export type GridColumnMenu = { readonly openCol: number | null; readonly menuLabel: string; readonly filteredLabel: string; readonly onToggle: (col: number) => void }
|
|
324
|
+
|
|
303
325
|
type GridBodyProps = {
|
|
304
326
|
adapter: SpreadsheetDataAdapter
|
|
305
327
|
rowAxis: AxisModel
|
|
@@ -417,6 +439,13 @@ type GridBodyProps = {
|
|
|
417
439
|
* identity が変わる — さもなくば shell 再レンダー毎に memo 境界を貫通)。
|
|
418
440
|
*/
|
|
419
441
|
scrollLabels: VirtualScrollLabels
|
|
442
|
+
/**
|
|
443
|
+
* v0.20.3 capability: the resolved `sortFilter` (null or absent = no column controls, the v0.20.2 cell DOM).
|
|
444
|
+
* v0.20.3 能力: 解いた `sortFilter` (null か無しなら列の操作は無く、マスの DOM は v0.20.2 と同じ)。
|
|
445
|
+
*/
|
|
446
|
+
sortFilter?: ResolvedSortFilter | null
|
|
447
|
+
/** v0.20.3: the column menu buttons' inputs (null or absent = no button). / v0.20.3: 列の品書きのボタンへの入力 (null か無しならボタンは無い)。 */
|
|
448
|
+
columnMenu?: GridColumnMenu | null
|
|
420
449
|
}
|
|
421
450
|
|
|
422
451
|
/**
|
|
@@ -461,6 +490,8 @@ const GridBodyInner = ({
|
|
|
461
490
|
onRenderTruncated,
|
|
462
491
|
locale,
|
|
463
492
|
scrollLabels,
|
|
493
|
+
sortFilter,
|
|
494
|
+
columnMenu,
|
|
464
495
|
}: GridBodyProps): ReactNode => {
|
|
465
496
|
const internalBodyRef = useRef<HTMLDivElement | null>(null)
|
|
466
497
|
// 外部 ref (エンジン結線用) と内部 ref の合成
|
|
@@ -527,6 +558,14 @@ const GridBodyInner = ({
|
|
|
527
558
|
// 宣言ホストは塗りセル毎 1 述語読み (ADR-31 の登記コスト)
|
|
528
559
|
...(isReadOnlyCell(adapter, row, col) ? { "aria-readonly": "true", "data-aqsp-readonly": "" } : {}),
|
|
529
560
|
...(isHeader ? { "data-aqsp-header-row": "" } : {}),
|
|
561
|
+
// v0.20.3: 操作の列の見出しのマス (並べ替えている列だけが aria-sort を持つ — 並べ替えの表の作法)
|
|
562
|
+
...(sortFilter === undefined || sortFilter === null || row !== sortFilter.headerRow || controlsColumnOf(sortFilter, col) === null
|
|
563
|
+
? {}
|
|
564
|
+
: {
|
|
565
|
+
"data-aqsp-column-controls": "",
|
|
566
|
+
...(sortFilter.sort !== null && sortFilter.sort.col === col ? { "aria-sort": sortFilter.sort.direction === "asc" ? "ascending" : "descending", "data-aqsp-sort": sortFilter.sort.direction } : {}),
|
|
567
|
+
...(sortFilter.filteredColumns.has(col) ? { "data-aqsp-filtered": "" } : {}),
|
|
568
|
+
}),
|
|
530
569
|
}
|
|
531
570
|
// v0.12 ホスト属性の継ぎ目: resolveCellAttributes が予約キー (data-aqsp* / data-row /
|
|
532
571
|
// data-col) と非 data-* を fail-fast 済みなのでパッケージ属性と衝突しない。未宣言は
|
|
@@ -544,7 +583,7 @@ const GridBodyInner = ({
|
|
|
544
583
|
}
|
|
545
584
|
return (rich.style === null ? { ...stamped, ...rich.attrs } : { ...stamped, ...rich.attrs, style: rich.style }) as HTMLAttributes<HTMLDivElement>
|
|
546
585
|
},
|
|
547
|
-
[adapter, rowAxis, colAxis, cf, headerRows],
|
|
586
|
+
[adapter, rowAxis, colAxis, cf, headerRows, sortFilter],
|
|
548
587
|
)
|
|
549
588
|
/** Row attribute surface — carries the engine event gate (data-aqsp-cells §6.4.3-1). / 行属性面 — エンジンのイベントゲート (data-aqsp-cells) を運ぶ。 */
|
|
550
589
|
const getRowProps = useCallback(
|
|
@@ -579,9 +618,28 @@ const GridBodyInner = ({
|
|
|
579
618
|
if (adapter.getCellFormat !== undefined) {
|
|
580
619
|
display = formatCellValue(text, takeLatchedValue(displayLatchRef.current, row, col))
|
|
581
620
|
}
|
|
582
|
-
|
|
621
|
+
const content = <CellView row={row} col={col} text={text} display={display} renderCell={renderCell} __onCellRender={__onCellRender} />
|
|
622
|
+
// v0.20.3: 操作の列の見出しのマスだけ、中身の後に列の品書きのボタン (CellView は字と描き手でしか描き直さないので中に入れない)
|
|
623
|
+
if (sortFilter === undefined || sortFilter === null || columnMenu === undefined || columnMenu === null || row !== sortFilter.headerRow || controlsColumnOf(sortFilter, col) === null) {
|
|
624
|
+
return content
|
|
625
|
+
}
|
|
626
|
+
return (
|
|
627
|
+
<>
|
|
628
|
+
{content}
|
|
629
|
+
<HeaderControls
|
|
630
|
+
col={col}
|
|
631
|
+
direction={sortFilter.sort !== null && sortFilter.sort.col === col ? sortFilter.sort.direction : null}
|
|
632
|
+
filtered={sortFilter.filteredColumns.has(col)}
|
|
633
|
+
expanded={columnMenu.openCol === col}
|
|
634
|
+
columnName={headerColumnName(display)}
|
|
635
|
+
menuLabel={columnMenu.menuLabel}
|
|
636
|
+
filteredLabel={columnMenu.filteredLabel}
|
|
637
|
+
onToggle={columnMenu.onToggle}
|
|
638
|
+
/>
|
|
639
|
+
</>
|
|
640
|
+
)
|
|
583
641
|
},
|
|
584
|
-
[renderVersion, renderCell, __onCellRender, adapter],
|
|
642
|
+
[renderVersion, renderCell, __onCellRender, adapter, sortFilter, columnMenu],
|
|
585
643
|
)
|
|
586
644
|
|
|
587
645
|
return (
|
package/src/index.ts
CHANGED
|
@@ -49,6 +49,7 @@ export { estimatePasteCellCount, expandPaste } from "./clipboard/tiling.ts"
|
|
|
49
49
|
export { iterateTsvPrefixRows, iterateTsvRows, measureTsv, parseTsv, serializeClipboardTsv, serializeTsv } from "./clipboard/tsv.ts"
|
|
50
50
|
export type { ClipInfo, PasteOutcome } from "./clipboard/useClipboard.ts"
|
|
51
51
|
export type { BorderPreset } from "./commands/useCommands.ts"
|
|
52
|
+
export type { EditSession } from "./editor/useCellEditor.ts"
|
|
52
53
|
// renderCell の ctx 型 — prop が公開面にある以上、その引数型も名指しできなければならない
|
|
53
54
|
// (未公開だと consumer は Parameters<...> 抽出を強いられる)。型のみの追加で非破壊
|
|
54
55
|
export type { RenderCellContext } from "./grid/CellView.tsx"
|
|
@@ -122,5 +123,26 @@ export { NoteTip, type NoteTipProps } from "./popover/NoteTip.tsx"
|
|
|
122
123
|
// PopoverContext.anchorRect の型 (層座標系の矩形) — 配置エンジン placePopover 本体は非公開のまま
|
|
123
124
|
export type { PopoverRect } from "./popover/placement.ts"
|
|
124
125
|
export type { CommentPopoverContext, LinkPopoverContext, ListPopoverContext, MessagePopoverContext, NotePopoverContext, NoteTipContext, PopoverContext, PopoverKind, PopoverOverrides } from "./popover/usePopovers.ts"
|
|
125
|
-
export {
|
|
126
|
+
export {
|
|
127
|
+
type CommitEditOutcome,
|
|
128
|
+
DEFAULT_CUSTOM_COLORS,
|
|
129
|
+
type ScrollToCellOptions,
|
|
130
|
+
type SelectionChangeReason,
|
|
131
|
+
type SetSelectionOptions,
|
|
132
|
+
Spreadsheet,
|
|
133
|
+
type SpreadsheetContentSize,
|
|
134
|
+
type SpreadsheetHandle,
|
|
135
|
+
type SpreadsheetProps,
|
|
136
|
+
type SpreadsheetScrollBarControls,
|
|
137
|
+
} from "./Spreadsheet.tsx"
|
|
126
138
|
export type { SelectionState } from "./selection/selectionState.ts"
|
|
139
|
+
// 見出しの並べ替えと列ごとの絞り込み (v0.20.3) — props `sortFilter` の型と、その項目が到達する型の全て
|
|
140
|
+
export type {
|
|
141
|
+
SpreadsheetColumnFilter,
|
|
142
|
+
SpreadsheetColumnSortFilterOptions,
|
|
143
|
+
SpreadsheetFilterValue,
|
|
144
|
+
SpreadsheetMatchMode,
|
|
145
|
+
SpreadsheetSortDirection,
|
|
146
|
+
SpreadsheetSortFilter,
|
|
147
|
+
SpreadsheetSortFilterState,
|
|
148
|
+
} from "./sortFilter/sortFilterModel.ts"
|
|
@@ -37,7 +37,12 @@
|
|
|
37
37
|
* in a text field (`isConsumedWhileEditing` — no Alt, a function key or Ctrl with a character
|
|
38
38
|
* key) the editing column consumes it after every row, so the browser's own shortcut (bookmark,
|
|
39
39
|
* reload, search box) never fires; the session is left untouched and `onCommandBlockedWhileEditing`
|
|
40
|
-
* reports the command and chord.
|
|
40
|
+
* reports the command and chord. The composition guard drops every IME keydown except one: the
|
|
41
|
+
* editing column's `fillSelection` chord (read from `event.code`, rebinding included) pressed while
|
|
42
|
+
* the composition is open is remembered and runs once in the task after `compositionend` when the
|
|
43
|
+
* committed text is not empty and the session is still open, and one arriving right after the
|
|
44
|
+
* composition ended (Safari's order, the 50 ms window) runs at once — so Ctrl+Enter fills with the
|
|
45
|
+
* confirmed text on the first press.
|
|
41
46
|
*
|
|
42
47
|
* シンク keydown 上のキーマップ実装 (§6.6.1 の契約表 — idle 列。編集列は Phase 3 の編集
|
|
43
48
|
* セッションへ委譲)。v0.2 で findDataEdge ナビゲーション + ディスパッチ前 fail-fast 検証 (§2)・
|
|
@@ -68,7 +73,10 @@
|
|
|
68
73
|
* fillRight の Ctrl+R・insertLink の Ctrl+K …) は編集中に走らず、入力欄に何も打たないチョード
|
|
69
74
|
* (`isConsumedWhileEditing` — Alt なしで機能キーか Ctrl + 文字キー) なら編集列が全ての行の後で消費する
|
|
70
75
|
* — ブラウザの既定 (ブックマーク・再読込・検索欄) は発火しない。セッションには触らず、
|
|
71
|
-
* `onCommandBlockedWhileEditing`
|
|
76
|
+
* `onCommandBlockedWhileEditing` がコマンドとチョードを報告する。変換ガードは IME の keydown を全て捨てるが、
|
|
77
|
+
* 1 つだけ例外がある: 変換の途中に押した編集列の `fillSelection` のチョード (`event.code` で読む。付け替えも
|
|
78
|
+
* 含む) は覚え、`compositionend` の次のタスクで、確定した字が空でなく入力がまだ開いていれば 1 回走らせる。変換が
|
|
79
|
+
* 終わった直後に届いたもの (Safari の順・50 ms の窓) はその場で走らせる — Ctrl+Enter は確定した字で 1 回で埋める。
|
|
72
80
|
*/
|
|
73
81
|
|
|
74
82
|
import type { VirtualGridHandle } from "@aiquants/virtualscroll"
|
|
@@ -234,6 +242,11 @@ const isSelectionDestroyingNav = (event: KeyboardEvent): boolean => {
|
|
|
234
242
|
export const useGridKeyboard = (params: UseGridKeyboardParams): void => {
|
|
235
243
|
const compositionEndedAtRef = useRef<number | null>(null)
|
|
236
244
|
const clearTimerRef = useRef<number | null>(null)
|
|
245
|
+
// 変換の途中かどうかはこのフック自身の compositionstart / compositionend で持つ — エディタの変換の印とは聞き手の順が決まらない
|
|
246
|
+
const composingRef = useRef(false)
|
|
247
|
+
// 変換中に押された fillSelection のチョード (冒頭のガードが捨てる keydown) の覚えと、確定の後に走らせるタイマー
|
|
248
|
+
const pendingFillRef = useRef(false)
|
|
249
|
+
const fillTimerRef = useRef<number | null>(null)
|
|
237
250
|
// ctrl+alt 印字形状の遅延開始保留 (v0.3.3): 直前 keydown が ctrl+alt 同時の 1 文字キーの
|
|
238
251
|
// ときだけ true。実文字の到着 (input) で消費、次の keydown / keyup / blur で失効する一発
|
|
239
252
|
// フラグ。現実の通過者は文字を生まないリテラル和音 (Ctrl+Alt+X 等 — 空置換セッション破壊の
|
|
@@ -397,6 +410,65 @@ export const useGridKeyboard = (params: UseGridKeyboardParams): void => {
|
|
|
397
410
|
p.moveActive({ mode: "cycle", direction: cycleDirection })
|
|
398
411
|
}
|
|
399
412
|
|
|
413
|
+
/**
|
|
414
|
+
* The command dispatch when a composition-guarded keydown is the editing column's `fillSelection` chord (the
|
|
415
|
+
* chord is read from `event.code`, so an IME keydown whose `key` is `"Process"` resolves too, and so does a
|
|
416
|
+
* rebound chord); null otherwise — idle, the command unavailable, or another chord.
|
|
417
|
+
* 変換ガードが捨てる keydown が編集列の `fillSelection` のチョードなら、そのコマンドの配り口 (チョードは `event.code` で読むので、
|
|
418
|
+
* `key` が `"Process"` の IME の keydown も、付け替えたチョードも解決する)。それ以外 (idle・使えない・別のチョード) は null。
|
|
419
|
+
*
|
|
420
|
+
* @param event - The keydown the composition guard dropped. 変換ガードが捨てた keydown。
|
|
421
|
+
* @returns The dispatch to run `fillSelection` through, or null. `fillSelection` を走らせる配り口、または null。
|
|
422
|
+
*/
|
|
423
|
+
const compositionFillDispatch = (event: KeyboardEvent): CommandDispatch | null => {
|
|
424
|
+
const p = paramsRef.current
|
|
425
|
+
const commands = p.commands
|
|
426
|
+
if (commands === undefined || !p.isEditing()) {
|
|
427
|
+
return null
|
|
428
|
+
}
|
|
429
|
+
const binding = resolveBinding(commands.table, event)
|
|
430
|
+
return binding !== null && binding.command === "fillSelection" && commands.isAvailable("fillSelection") ? commands : null
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Runs the `fillSelection` remembered during a composition, after the composition committed — only while the
|
|
435
|
+
* session is still open and the command still available.
|
|
436
|
+
* 変換中に覚えた `fillSelection` を、変換の確定の後に走らせる — 入力がまだ開いていて、コマンドがまだ使えるときだけ。
|
|
437
|
+
*/
|
|
438
|
+
const runCompositionFill = (): void => {
|
|
439
|
+
fillTimerRef.current = null
|
|
440
|
+
const p = paramsRef.current
|
|
441
|
+
const commands = p.commands
|
|
442
|
+
// 確定の前に入力が閉じた (焦点の離脱の確定など) — 入力の無い fillSelection はアクティブなマスを写す別の動きになる
|
|
443
|
+
if (commands === undefined || !p.isEditing() || !commands.isAvailable("fillSelection")) {
|
|
444
|
+
return
|
|
445
|
+
}
|
|
446
|
+
commands.execute("fillSelection")
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Handles a keydown the composition guard drops. While the composition is open, a `fillSelection` chord is
|
|
451
|
+
* remembered for the commit and any other key forgets it (the IME took that key for itself). Right after the
|
|
452
|
+
* composition ended — Safari fires `compositionend` before the confirming keydown, and the 50 ms window drops a
|
|
453
|
+
* chord pressed just after a confirmation — the chord runs at once. Every other dropped keydown stays dropped.
|
|
454
|
+
* 変換ガードが捨てる keydown の扱い。変換の途中なら、`fillSelection` のチョードは確定まで覚え、ほかのキーは覚えを捨てる (IME が
|
|
455
|
+
* そのキーを使った)。変換が終わった直後 — Safari は確定のキーより先に `compositionend` を出し、50 ms の窓は確定の直後に押した
|
|
456
|
+
* チョードを捨てる — なら、その場で走らせる。ほかの捨てた keydown は捨てたまま。
|
|
457
|
+
*
|
|
458
|
+
* @param event - The keydown the composition guard dropped. 変換ガードが捨てた keydown。
|
|
459
|
+
*/
|
|
460
|
+
const takeCompositionKeydown = (event: KeyboardEvent): void => {
|
|
461
|
+
const fill = compositionFillDispatch(event)
|
|
462
|
+
if (composingRef.current) {
|
|
463
|
+
pendingFillRef.current = fill !== null
|
|
464
|
+
return
|
|
465
|
+
}
|
|
466
|
+
if (fill !== null && compositionEndedAtRef.current !== null) {
|
|
467
|
+
event.preventDefault()
|
|
468
|
+
fill.execute("fillSelection")
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
400
472
|
/** Manual newline insertion at the caret (editing Alt+Enter — most browsers insert nothing natively). / キャレット位置へ改行を挿入 (編集列 Alt+Enter)。 */
|
|
401
473
|
const insertNewlineAtCaret = (): void => {
|
|
402
474
|
const sink = sinkRef.current
|
|
@@ -441,8 +513,10 @@ export const useGridKeyboard = (params: UseGridKeyboardParams): void => {
|
|
|
441
513
|
// 新しい打鍵は AltGr 保留を無条件に失効させる (保留を再設定するのは末尾の AltGr 分岐のみ)
|
|
442
514
|
altGrPendingRef.current = false
|
|
443
515
|
// 冒頭ガード (§6.6.2-1): 変換中 / keyCode 229 / compositionend 直後 50 ms 窓の Enter・Escape —
|
|
444
|
-
// 判定は compositionGuard.ts の単一真実源 (ポップオーバーの keydown も同じ関数を通す)
|
|
516
|
+
// 判定は compositionGuard.ts の単一真実源 (ポップオーバーの keydown も同じ関数を通す)。捨てる keydown のうち
|
|
517
|
+
// fillSelection のチョードだけは、確定した字で 1 回で埋める (変換中の Ctrl+Enter が 2 回押しにならない)
|
|
445
518
|
if (isCompositionKeydown(event, compositionEndedAtRef.current)) {
|
|
519
|
+
takeCompositionKeydown(event)
|
|
446
520
|
return
|
|
447
521
|
}
|
|
448
522
|
const ctrl = event.ctrlKey || event.metaKey
|
|
@@ -911,6 +985,8 @@ export const useGridKeyboard = (params: UseGridKeyboardParams): void => {
|
|
|
911
985
|
|
|
912
986
|
const onCompositionStart = () => {
|
|
913
987
|
const p = paramsRef.current
|
|
988
|
+
composingRef.current = true
|
|
989
|
+
pendingFillRef.current = false
|
|
914
990
|
if (!p.isEditing()) {
|
|
915
991
|
// IME トリガー: value = "" の設定 1 点で replace モード開始 (§6.6.2-5)
|
|
916
992
|
p.startEdit("replace")
|
|
@@ -918,6 +994,7 @@ export const useGridKeyboard = (params: UseGridKeyboardParams): void => {
|
|
|
918
994
|
}
|
|
919
995
|
|
|
920
996
|
const onCompositionEnd = (event: CompositionEvent) => {
|
|
997
|
+
composingRef.current = false
|
|
921
998
|
compositionEndedAtRef.current = event.timeStamp
|
|
922
999
|
if (clearTimerRef.current !== null) {
|
|
923
1000
|
window.clearTimeout(clearTimerRef.current)
|
|
@@ -927,6 +1004,20 @@ export const useGridKeyboard = (params: UseGridKeyboardParams): void => {
|
|
|
927
1004
|
compositionEndedAtRef.current = null
|
|
928
1005
|
clearTimerRef.current = null
|
|
929
1006
|
}, COMPOSITION_CLEAR_MS)
|
|
1007
|
+
if (!pendingFillRef.current) {
|
|
1008
|
+
return
|
|
1009
|
+
}
|
|
1010
|
+
pendingFillRef.current = false
|
|
1011
|
+
// 取り消された変換 (確定した字が空) の後に埋めると、置き換えで始まった入力の空の字で選んだマスを全て消す
|
|
1012
|
+
if (event.data === "") {
|
|
1013
|
+
return
|
|
1014
|
+
}
|
|
1015
|
+
if (fillTimerRef.current !== null) {
|
|
1016
|
+
window.clearTimeout(fillTimerRef.current)
|
|
1017
|
+
}
|
|
1018
|
+
// compositionend の聞き手はほかにもあり (エディタの変換の印)、Firefox は compositionend の後に input を出す —
|
|
1019
|
+
// 全てが済んだ次のタスクで入力の字を読む
|
|
1020
|
+
fillTimerRef.current = window.setTimeout(runCompositionFill, 0)
|
|
930
1021
|
}
|
|
931
1022
|
|
|
932
1023
|
const onInput = () => {
|
|
@@ -1002,6 +1093,13 @@ export const useGridKeyboard = (params: UseGridKeyboardParams): void => {
|
|
|
1002
1093
|
if (clearTimerRef.current !== null) {
|
|
1003
1094
|
window.clearTimeout(clearTimerRef.current)
|
|
1004
1095
|
}
|
|
1096
|
+
// 再結線 / アンマウントを跨いで、覚えた埋めを古い結線の上で走らせない
|
|
1097
|
+
if (fillTimerRef.current !== null) {
|
|
1098
|
+
window.clearTimeout(fillTimerRef.current)
|
|
1099
|
+
fillTimerRef.current = null
|
|
1100
|
+
}
|
|
1101
|
+
composingRef.current = false
|
|
1102
|
+
pendingFillRef.current = false
|
|
1005
1103
|
// 再結線 / アンマウントを跨いで矩形を残さない (writer リレーはノード不在なら no-op)
|
|
1006
1104
|
clearPointFrame()
|
|
1007
1105
|
}
|