@aiquants/spreadsheet 0.20.3 → 0.21.1

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.
@@ -265,6 +265,14 @@ export type ReadOnlyRejection =
265
265
  * バックではない)。getCellFormat なしの getConditionalFormats 宣言はマウント時 RangeError
266
266
  * (塗り書式は base ⊕ CF で、getCellFormat なしに base は無い)。
267
267
  */
268
+ /**
269
+ * The on-screen keyboard a cell asks for while the grid invites one: HTML's `inputmode` values except `"none"` (the grid
270
+ * renders `"none"` itself while it does not invite a keyboard).
271
+ * グリッドが画面のキーボードを招いている間に、セルが求めるキーボード。`"none"` を除く HTML の `inputmode` の値 (招かない間の `"none"` は
272
+ * グリッド自身が描く)。
273
+ */
274
+ export type CellInputMode = "text" | "decimal" | "numeric" | "tel" | "search" | "email" | "url"
275
+
268
276
  export type SpreadsheetDataAdapter = {
269
277
  rowCount: number
270
278
  colCount: number
@@ -449,6 +457,19 @@ export type SpreadsheetDataAdapter = {
449
457
  * (getCellText と同格、描画パスでも呼ばれるため)。未宣言 = 全セル編集可 = 従来挙動とバイト同一。
450
458
  */
451
459
  isCellReadOnly?: (row: number, col: number) => boolean
460
+ /**
461
+ * OPTIONAL capability (v0.21): the on-screen keyboard one cell asks for. While the grid invites a keyboard (an editor
462
+ * opened by a pointer — the mouse double-click, or a finger or pen tap of `touchEditing`) the hidden input's `inputmode`
463
+ * is the active cell's answer, so a numeric column can bring up the number pad. Absent = `"text"` for every cell. Any
464
+ * value outside `CellInputMode` is a `RangeError` at render naming the cell and the value (never a silent `"text"`).
465
+ * Read at every render of the grid (never memoised); publish changes via `dataVersion`. The grid only ever calls this
466
+ * with in-grid coordinates. Host cost budget: O(1) and allocation-free.
467
+ * 任意の能力 (v0.21): 1 つのセルが求める画面のキーボード。グリッドがキーボードを招いている間 (ポインタで開いたエディタ — マウスの二度押し、
468
+ * または `touchEditing` の指とペンの叩き) の受け口の `inputmode` は、選んでいるセルのこの答えになるので、数の列は数の鍵盤を出せる。未宣言 =
469
+ * どのセルも `"text"`。`CellInputMode` の外の値は描画の時に `RangeError` (セルと値を名指す。黙って `"text"` にしない)。グリッドの描画の
470
+ * たびに読む (覚えない)。変更は `dataVersion` で公開。座標は常にグリッドの中。ホストのコストは O(1)・割当なし。
471
+ */
472
+ getCellInputMode?: (row: number, col: number) => CellInputMode
452
473
  /**
453
474
  * OPTIONAL capability (v0.12): host-owned `data-*` attributes for one cell, merged verbatim
454
475
  * onto the PACKAGE-OWNED cell element (`[data-aqsp-cell]`) so host CSS can target cell
@@ -649,6 +670,7 @@ const ADAPTER_MEMBERS = [
649
670
  "getCellValidation",
650
671
  "getConditionalFormats",
651
672
  "isCellReadOnly",
673
+ "getCellInputMode",
652
674
  "getCellAttributes",
653
675
  "getRangeExtrema",
654
676
  "evaluateFormula",
@@ -658,6 +680,32 @@ const ADAPTER_MEMBERS = [
658
680
  const ADAPTER_MEMBERS_COMPLETE: [Exclude<keyof SpreadsheetDataAdapter, (typeof ADAPTER_MEMBERS)[number]>] extends [never] ? true : never = true
659
681
  void ADAPTER_MEMBERS_COMPLETE
660
682
 
683
+ /** The keyboards a cell may ask for (`CellInputMode`), in the order the render-time error names them. / セルが求めうるキーボード (描画の時の誤りが名指す順)。 */
684
+ const CELL_INPUT_MODES: readonly CellInputMode[] = ["text", "decimal", "numeric", "tel", "search", "email", "url"]
685
+
686
+ /**
687
+ * The on-screen keyboard one cell asks for (`getCellInputMode`), checked: `"text"` when the adapter does not declare the
688
+ * capability.
689
+ * 1 つのセルが求める画面のキーボード (`getCellInputMode`) を、確かめて読む処理。アダプタが能力を宣言しなければ `"text"`。
690
+ *
691
+ * @param adapter - The adapter / アダプタ
692
+ * @param row - The cell's row (in the grid) / セルの行 (グリッドの中)
693
+ * @param col - The cell's column (in the grid) / セルの列 (グリッドの中)
694
+ * @returns The keyboard / キーボード
695
+ * @throws {RangeError} When the adapter answers a value outside `CellInputMode` / アダプタが `CellInputMode` の外の値を答えた場合
696
+ */
697
+ export const resolveCellInputMode = (adapter: SpreadsheetDataAdapter, row: number, col: number): CellInputMode => {
698
+ if (adapter.getCellInputMode === undefined) {
699
+ return "text"
700
+ }
701
+ const mode: unknown = adapter.getCellInputMode(row, col)
702
+ const known = CELL_INPUT_MODES.find((candidate) => candidate === mode)
703
+ if (known === undefined) {
704
+ throw new RangeError(`[Spreadsheet] getCellInputMode(${row}, ${col}) must return one of ${CELL_INPUT_MODES.join(" / ")}; got ${typeof mode === "string" ? JSON.stringify(mode) : String(mode)}`)
705
+ }
706
+ return known
707
+ }
708
+
661
709
  /** The read-only answer of a whole read-only grid: every cell. / グリッド全体を読み取り専用にしたときの答え (どのセルも読み取り専用)。 */
662
710
  const EVERY_CELL_READ_ONLY = (): boolean => true
663
711
 
@@ -115,6 +115,7 @@ import type { AxisModel } from "../model/axisModel.ts"
115
115
  import { isWholeCols, isWholeRows } from "../model/cellAnnotations.ts"
116
116
  import { type CellCoord, type CellRange, makeRange } from "../model/cellCoord.ts"
117
117
  import { type EditPaint, IDLE_EDIT_PAINT } from "../model/cellPaint.ts"
118
+ import type { CellInputMode } from "../model/dataAdapter.ts"
118
119
  import { type AxisForwardCtx, colToViewportX, frozenHeightOf, frozenWidthOf, rowToViewportY, trailingHeightOf, trailingWidthOf } from "../model/frozenPartition.ts"
119
120
  import type { PopoverAnchorState } from "../popover/usePopovers.ts"
120
121
  import type { SelectionState } from "../selection/selectionState.ts"
@@ -683,8 +684,8 @@ type SelectionOverlayProps = {
683
684
  getSelection: () => SelectionState
684
685
  /** Editing state as a boolean prop (§6.7.2-4 — mind the name clash with the isEditing function seam; !editing is safe as a per-render evaluation). / 編集状態の boolean prop (関数シーム isEditing との同名衝突に注意)。 */
685
686
  editing: boolean
686
- /** Virtual-keyboard invitation (Spreadsheet owns the flag): rendered as the sink's inputmode — "text" while invited, "none" otherwise. / 仮想キーボード招待 (フラグは Spreadsheet が所有) — シンクの inputmode として描画 ("text" = 招待中 / "none")。 */
687
- virtualKeyboard: boolean
687
+ /** The sink's `inputmode` (Spreadsheet owns the invitation flag): `"none"` while no keyboard is invited, otherwise the keyboard the active cell asks for (`resolveCellInputMode` — `"text"` unless the adapter declares `getCellInputMode`). / シンクの `inputmode` (招きの旗は Spreadsheet が所有)。招かない間は `"none"`、招いている間は選んでいるセルが求めるキーボード (`resolveCellInputMode` — アダプタが `getCellInputMode` を宣言しなければ `"text"`)。 */
688
+ sinkInputMode: "none" | CellInputMode
688
689
  /** Registration target for repaintOverlay (owner: Spreadsheet — the §6.9-7 repaintOverlayRef indirection). / repaintOverlay の登録先 (所有は Spreadsheet)。 */
689
690
  repaintRef: RefObject<(() => void) | null>
690
691
  /** Drag-rect writer registration (called via the Spreadsheet onDragFrame relay, which appends the §3.2 mode; v0.8 adds "point" for the formula-reference drag). / ドラッグ矩形 writer の登録先 (Spreadsheet の onDragFrame リレー経由 — mode は §3.2 のリレーが付加。v0.8 は参照ドラッグの "point" を追加)。 */
@@ -1037,7 +1038,7 @@ export const SelectionOverlay = ({
1037
1038
  sinkRef,
1038
1039
  getSelection,
1039
1040
  editing,
1040
- virtualKeyboard,
1041
+ sinkInputMode,
1041
1042
  repaintRef,
1042
1043
  dragFrameRef,
1043
1044
  getClip,
@@ -2501,10 +2502,10 @@ export const SelectionOverlay = ({
2501
2502
  </div>
2502
2503
  )
2503
2504
  })}
2504
- {/* inputMode (R4 / R5 / R7 是正): 仮想キーボード招待フラグの純粋な描画 — "none" = 非招待 (touch / ペンは
2505
- スクロール専用で選択も編集もしない。タップの compat mousedown 既定で root → シンクへ焦点が戻っても OSK は
2506
- 出ない)、"text" = 招待中 (ポインタでエディタを開いた — キーボード無し端末が OSK を出せる。Enter / Tab の
2507
- 確定では下ろさず、グリッド脱出か touch / ペン押下で下ろす)。キーボード / IME 利用者には常に "none" で
2505
+ {/* inputMode (R4 / R5 / R7 是正): 仮想キーボード招待フラグと、選んでいるセルが求めるキーボードの純粋な描画 — "none" = 非招待
2506
+ (touchEditing の無い表では touch / ペンはスクロール専用で選択も編集もしない。タップの compat mousedown 既定で root → シンクへ
2507
+ 焦点が戻っても OSK は出ない)、招待中は選んでいるセルの getCellInputMode の答え (宣言しなければ "text" — ポインタでエディタを
2508
+ 開いた: キーボード無し端末が OSK を出せる。Enter / Tab の確定では下ろさず、グリッド脱出か touch / ペン押下で下ろす)。キーボード / IME 利用者には常に "none" で
2508
2509
  一度も変化しない — 変換中の属性変更 (Windows TSF が変換を強制終了する) を構造的に排除する。
2509
2510
  OSK の実際の表示は UA 依存: WebKit はフォーカス済み要素の変更を再評価する、Chromium はフォーカス取得時に
2510
2511
  しか評価しない。ハードウェアキーボードとデスクトップ IME は無影響 */}
@@ -2516,7 +2517,7 @@ export const SelectionOverlay = ({
2516
2517
  aria-keyshortcuts={sinkKeyShortcuts}
2517
2518
  tabIndex={-1}
2518
2519
  defaultValue=" "
2519
- inputMode={virtualKeyboard ? "text" : "none"}
2520
+ inputMode={sinkInputMode}
2520
2521
  spellCheck={false}
2521
2522
  autoCorrect="off"
2522
2523
  autoCapitalize="off"
@@ -43,7 +43,7 @@
43
43
  * 止めた帯の行の箱へ移すため)、今どおりスクロールの機械へ渡す。
44
44
  */
45
45
 
46
- import type { VirtualGridHandle } from "@aiquants/virtualscroll"
46
+ import { didPressStopScrollMotion, type VirtualGridHandle } from "@aiquants/virtualscroll"
47
47
  import { type RefObject, useCallback, useEffect, useMemo, useRef } from "react"
48
48
  import type { AxisModel } from "../model/axisModel.ts"
49
49
  import { type CellCoord, type CellRange, clampCoord, coordEquals, makeRange, rangeContains } from "../model/cellCoord.ts"
@@ -62,6 +62,13 @@ import { type AutoScroller, SCROLLER_ARM_THRESHOLD } from "./useAutoScroller.ts"
62
62
  */
63
63
  export const HEADER_TAP_SLOP_PX = 6
64
64
 
65
+ /**
66
+ * How long a finger or a pen holds a body cell still before the press opens the context menu (v0.21 `touchEditing`, ms) — a
67
+ * long-press about as long as the platforms' own.
68
+ * 指かペンが体のマスを動かさずに押さえてから、押下が品書きを開くまでの時間 (v0.21 `touchEditing`、ms)。素の長押しとおおよそ同じ長さ。
69
+ */
70
+ export const TOUCH_LONG_PRESS_MS = 500
71
+
65
72
  /**
66
73
  * Whether a pointer moved `HEADER_TAP_SLOP_PX` or more from where it was pressed (the larger axis, client px — the
67
74
  * ScrollPane's drag test).
@@ -256,6 +263,15 @@ type UseSelectionEngineParams = {
256
263
  * root はここから状態を変える手順 (確定の関門が先) を走らせる。
257
264
  */
258
265
  onHeaderSortPress?: (col: number, pointerType: string) => void
266
+ /**
267
+ * v0.21 capability (`touchEditing`): opens the editor on the active cell from a finger or pen tap, inviting the on-screen
268
+ * keyboard inside the tap (the root's touch-edit funnel). Undefined = a touch / pen press on a body cell is never
269
+ * recorded — no tap, no long-press, and the native `contextmenu` of a touch / pen press keeps its default (the press path
270
+ * byte-for-byte).
271
+ * v0.21 能力 (`touchEditing`): 指とペンの叩きで、選んでいるマスのエディタを開き、叩きの中で画面のキーボードを招く (root の指で書く道)。undefined
272
+ * なら体のマスの指とペンの押下を一切記録しない (叩きも長押しも無く、指とペンの素の `contextmenu` の既定も止めない。押下経路は byte 同一)。
273
+ */
274
+ onRequestTouchEdit?: (cell: CellCoord) => void
259
275
  }
260
276
 
261
277
  /** Producer side of the Escape split (§6.6.2). / Escape 分担の生産側。 */
@@ -345,6 +361,17 @@ export const useSelectionEngine = (params: UseSelectionEngineParams): SelectionE
345
361
  * そのポインタの `pointercancel`・`HEADER_TAP_SLOP_PX` の動きで捨てる。
346
362
  */
347
363
  const headerTapRef = useRef<{ readonly pointerId: number; readonly pointerType: string; readonly cell: CellCoord; readonly clientX: number; readonly clientY: number } | null>(null)
364
+ /**
365
+ * The touch / pen press on a body cell that may still complete as a tap or a long-press (v0.21 `touchEditing`), owned by
366
+ * its pointer id: cleared by the next press of any pointer, by that pointer's release, `pointercancel` or movement of
367
+ * `HEADER_TAP_SLOP_PX`, and when its long-press fires. `event` is the press itself (the long-press hands it to the context
368
+ * menu, whose coordinates are then the pressed point).
369
+ * 叩きか長押しで終わり得る、体のマスの指・ペンの押下 (v0.21 `touchEditing`)。持ち主はその pointerId。どのポインタでも次の押下・そのポインタの
370
+ * 解放・`pointercancel`・`HEADER_TAP_SLOP_PX` の動き・その長押しの発火で捨てる。`event` は押下そのもの (長押しが品書きへ渡す。座標は押した点)。
371
+ */
372
+ const bodyTapRef = useRef<{ readonly pointerId: number; readonly cell: CellCoord; readonly clientX: number; readonly clientY: number; readonly event: PointerEvent } | null>(null)
373
+ /** The long-press clock of the recorded body tap (`TOUCH_LONG_PRESS_MS`), or null. / 記録した体の叩きの長押しの時計 (`TOUCH_LONG_PRESS_MS`)。無ければ null。 */
374
+ const longPressTimerRef = useRef<number | null>(null)
348
375
 
349
376
  /** Hit test with the freshness hierarchy (§6.4.3-3) over the press-cached body rect — the shared mapping. / 鮮度序列準拠のヒットテスト (押下時計測の body rect 上) — 共有写像。 */
350
377
  const hitTest = useCallback((clientX: number, clientY: number): CellCoord | null => {
@@ -440,10 +467,133 @@ export const useSelectionEngine = (params: UseSelectionEngineParams): SelectionE
440
467
  return hitTestCell(handleRef.current, body.getBoundingClientRect(), rowAxis, colAxis, zoomRef.current, clientX, clientY)
441
468
  }
442
469
 
470
+ /**
471
+ * Discards the recorded body tap and stops its long-press clock (idempotent).
472
+ * 記録した体の叩きを捨て、その長押しの時計を止める処理 (冪等)。
473
+ */
474
+ const discardBodyTap = () => {
475
+ bodyTapRef.current = null
476
+ if (longPressTimerRef.current !== null) {
477
+ window.clearTimeout(longPressTimerRef.current)
478
+ longPressTimerRef.current = null
479
+ }
480
+ }
481
+
482
+ /**
483
+ * Delivers a pointer context menu on a cell (Excel semantics): a cell outside the selection becomes the selection,
484
+ * then `onContextMenuSelect` is told — unconditionally, the one delivery channel (a menu opened inside the selection is
485
+ * the most common consumer flow).
486
+ * マスへのポインタの品書きを配る処理 (Excel の意味論)。選択の外のマスなら選択をそのマスへ置き換えてから、`onContextMenuSelect` へ無条件に知らせる
487
+ * (唯一の配送チャネル — 選択の内の品書きが consumer の最頻のフロー)。
488
+ *
489
+ * @param cell - The cell / マス
490
+ * @param event - The event the menu opens from / 品書きを開く出来事
491
+ */
492
+ const deliverContextMenu = (cell: CellCoord, event: MouseEvent) => {
493
+ const p = paramsRef.current
494
+ // 順序は置換 → 通知 (Excel 意味論 — メニューは置換後の新選択に作用する)。
495
+ // 選択の置換だけが条件付き: 選択外なら置換、選択内なら不変 (§6.4.1)
496
+ const selection = p.getSelection()
497
+ const inSelection = selection.ranges.some((range) => rangeContains(range, cell))
498
+ if (!inSelection) {
499
+ p.setSelection(reduceSelectionPress(selection, cell, { extend: false, append: false }))
500
+ }
501
+ p.onContextMenuSelect(cell, event)
502
+ }
503
+
504
+ /**
505
+ * Opens the context menu from a long-press (v0.21 `touchEditing`) the way a mouse right-click does: nothing while a
506
+ * drag is in flight, an open editor commits first (a refusal keeps it open), the focus comes back to the sink, then the
507
+ * menu is delivered with the press (its coordinates are the pressed point).
508
+ * 長押しから品書きを開く処理 (v0.21 `touchEditing`)。マウスの右押しと同じ: ドラッグの飛行中は何もしない。開いているエディタは先に確定する (断られたら
509
+ * 続ける)。焦点を受け口へ戻してから、押下の出来事で品書きを配る (座標は押した点)。
510
+ *
511
+ * @param cell - The pressed cell / 押したマス
512
+ * @param press - The press / 押下
513
+ */
514
+ const openTouchContextMenu = (cell: CellCoord, press: PointerEvent) => {
515
+ const p = paramsRef.current
516
+ if (p.isAnyDragging()) {
517
+ return
518
+ }
519
+ if (p.isEditing() && !p.requestCommit()) {
520
+ p.focusSink()
521
+ return
522
+ }
523
+ p.focusSink()
524
+ deliverContextMenu(cell, press)
525
+ }
526
+
527
+ /**
528
+ * Records a touch / pen press on a body cell as a tap candidate and starts its long-press clock (v0.21
529
+ * `touchEditing`) — unless the press only stopped the moving list (`didPressStopScrollMotion`: the pane marks it in the
530
+ * capture phase), which, as in a native list, is no tap.
531
+ * 体のマスの指・ペンの押下を叩きの候補として記録し、その長押しの時計を走らせる処理 (v0.21 `touchEditing`)。押下が流れている一覧を止めただけなら
532
+ * (`didPressStopScrollMotion` — ペインが capture で印を付ける)、素の一覧と同じく叩きにしない。
533
+ *
534
+ * @param event - The press / 押下
535
+ * @param cell - The pressed body cell / 押した体のマス
536
+ */
537
+ const recordBodyTap = (event: PointerEvent, cell: CellCoord) => {
538
+ if (didPressStopScrollMotion(event)) {
539
+ return
540
+ }
541
+ // 叩きの互換のマウスの押下は pointerup の後に届き、焦点を根の箱へ逃がす — 既定を止める。パンは touch-action が決めるので止まらない
542
+ event.preventDefault()
543
+ bodyTapRef.current = { pointerId: event.pointerId, cell, clientX: event.clientX, clientY: event.clientY, event }
544
+ longPressTimerRef.current = window.setTimeout(() => {
545
+ longPressTimerRef.current = null
546
+ const tap = bodyTapRef.current
547
+ // 時計は記録と一緒に止まるので、走った時の記録はこの押下のもの (動かず・離さず・取り消されていない)
548
+ if (tap === null) {
549
+ return
550
+ }
551
+ bodyTapRef.current = null
552
+ openTouchContextMenu(tap.cell, tap.event)
553
+ }, TOUCH_LONG_PRESS_MS)
554
+ }
555
+
556
+ /**
557
+ * Completes a finger or pen tap on a body cell (v0.21 `touchEditing`) through the gates of a mouse click: nothing while a
558
+ * drag is in flight or a formula points (references are inserted by mouse and keyboard only, and a commit would end
559
+ * the formula half-written); an open editor commits first (a refusal keeps it open), and a tap on its own cell keeps it
560
+ * open; otherwise the active cell's tap opens its editor (the root invites the on-screen keyboard inside the tap) and
561
+ * any other cell's tap selects that cell alone.
562
+ * 体のマスの指・ペンの叩き (v0.21 `touchEditing`) を、マウスのクリックの関門で終える処理。ドラッグの飛行中と数式が参照を指している間は何もしない
563
+ * (参照の挿入はマウスとキーボードだけで、確定すると書きかけの数式で終わる)。開いているエディタは先に確定し (断られたら続ける)、そのマス自身の叩きは
564
+ * 編集を続ける。ほかは、選んでいるマスの叩きがそのエディタを開き (root が叩きの中で画面のキーボードを招く)、ほかのマスの叩きはそのマスだけを選ぶ。
565
+ *
566
+ * @param cell - The tapped cell / 叩いたマス
567
+ */
568
+ const completeTouchTap = (cell: CellCoord) => {
569
+ const p = paramsRef.current
570
+ const onRequestTouchEdit = p.onRequestTouchEdit
571
+ if (onRequestTouchEdit === undefined || p.isAnyDragging()) {
572
+ return
573
+ }
574
+ if (p.getPointing?.()) {
575
+ p.focusSink()
576
+ return
577
+ }
578
+ const isActive = coordEquals(p.getSelection().active, cell)
579
+ if (p.isEditing()) {
580
+ if (isActive || !p.requestCommit()) {
581
+ p.focusSink()
582
+ return
583
+ }
584
+ } else if (isActive) {
585
+ onRequestTouchEdit(cell)
586
+ return
587
+ }
588
+ p.setSelection(reduceSelectionPress(p.getSelection(), cell, { extend: false, append: false }))
589
+ p.focusSink()
590
+ }
591
+
443
592
  const onPointerDown = (event: PointerEvent) => {
444
593
  const p = paramsRef.current
445
594
  // 叩きの記録はどのポインタでも次の押下で捨てる (2 本目の指や続く押下が入ったジェスチャは叩きではない)
446
595
  headerTapRef.current = null
596
+ discardBodyTap()
447
597
  // 主ボタン mouse 押下は領域を問わず最上流で stale 減算フラグを掃除する (§3.2 の
448
598
  // 二重遮断の完全形 — 領域外 / 編集ゲート拒否 / hitTest null で中断される押下でも
449
599
  // 必ず走る。宙吊りジェスチャ (capture 失敗 + 領域外リリース) が残した旧フラグで
@@ -492,18 +642,26 @@ export const useSelectionEngine = (params: UseSelectionEngineParams): SelectionE
492
642
  // (mouse ゲートより先 — touch 押下も記録してから弾く)
493
643
  lastPointerTypeRef.current = event.pointerType
494
644
  if (event.pointerType !== "mouse") {
495
- // 指とペン (v0.20.3): 並べ替えの見出しのマスなら叩きの記録を置き、押下は今どおりスクロールの機械へ渡す。
496
- // 矩形の読みは能力があるときだけ (渡さない表の押下はレイアウトを読まない)
497
- if (p.isSortHeaderCell !== undefined) {
498
- const cell = hitTestNow(event.clientX, event.clientY)
499
- if (cell !== null && p.isSortHeaderCell(cell)) {
500
- // 叩きの互換のマウスの押下は pointerup の後に届き、焦点を止めた帯の行の箱 (tabIndex −1) へ移す (実の Chromium で
501
- // 確かめた) — 叩きの後に受け口へ戻した焦点を奪われないよう既定を止める。パンは touch-action が決めるので止まらない
502
- event.preventDefault()
503
- headerTapRef.current = { pointerId: event.pointerId, pointerType: event.pointerType, cell, clientX: event.clientX, clientY: event.clientY }
504
- }
645
+ // 指とペン (v0.20.3): 並べ替えの見出しのマスなら叩きの記録を置き、押下は今どおりスクロールの機械へ渡す。v0.21 (touchEditing) は
646
+ // 体のマスの叩きと長押しも記録する。矩形の読みは能力があるときだけ (渡さない表の押下はレイアウトを読まない)
647
+ if (p.isSortHeaderCell === undefined && p.onRequestTouchEdit === undefined) {
648
+ return // タッチ / ペンは virtualscroll のドラッグスクロールへ
649
+ }
650
+ const cell = hitTestNow(event.clientX, event.clientY)
651
+ if (cell === null) {
652
+ return
653
+ }
654
+ if (p.isSortHeaderCell?.(cell) === true) {
655
+ // 叩きの互換のマウスの押下は pointerup の後に届き、焦点を止めた帯の行の箱 (tabIndex −1) へ移す (実の Chromium で
656
+ // 確かめた) — 叩きの後に受け口へ戻した焦点を奪われないよう既定を止める。パンは touch-action が決めるので止まらない
657
+ event.preventDefault()
658
+ headerTapRef.current = { pointerId: event.pointerId, pointerType: event.pointerType, cell, clientX: event.clientX, clientY: event.clientY }
659
+ return
505
660
  }
506
- return // タッチ / ペンは virtualscroll のドラッグスクロールへ
661
+ if (p.onRequestTouchEdit !== undefined) {
662
+ recordBodyTap(event, cell)
663
+ }
664
+ return // 押下そのものは今どおり virtualscroll のドラッグスクロールへ
507
665
  }
508
666
  if (event.button !== 0) {
509
667
  // 右クリックは contextmenu ハンドラ (§6.4.3-4)。押下の既定動作 (mousedown のフォーカス移動)
@@ -654,6 +812,10 @@ export const useSelectionEngine = (params: UseSelectionEngineParams): SelectionE
654
812
  if (tap !== null && event.pointerId === tap.pointerId && movedPastTapSlop(tap, event)) {
655
813
  headerTapRef.current = null
656
814
  }
815
+ const bodyTap = bodyTapRef.current
816
+ if (bodyTap !== null && event.pointerId === bodyTap.pointerId && movedPastTapSlop(bodyTap, event)) {
817
+ discardBodyTap()
818
+ }
657
819
  applyPointerMove(event)
658
820
  // chord 中の主ボタン解放 (R4 是正): 主ボタン保持中に 2 本目を押した状態で主ボタンを離すと、
659
821
  // その解放は pointerup でなく pointermove (buttons から主ビットが消える) で届き、最後の
@@ -674,6 +836,14 @@ export const useSelectionEngine = (params: UseSelectionEngineParams): SelectionE
674
836
  paramsRef.current.onHeaderSortPress?.(tap.cell.col, tap.pointerType)
675
837
  }
676
838
  }
839
+ // 体のマスの指とペンの叩き (v0.21 touchEditing): 長押しが発火する前に、閾まで動かず同じマスで離せば叩き
840
+ const bodyTap = bodyTapRef.current
841
+ if (bodyTap !== null && event.pointerId === bodyTap.pointerId) {
842
+ discardBodyTap()
843
+ if (!movedPastTapSlop(bodyTap, event) && hitsCell(hitTestNow(event.clientX, event.clientY), bodyTap.cell)) {
844
+ completeTouchTap(bodyTap.cell)
845
+ }
846
+ }
677
847
  // 主ボタンのリリースのみ確定する (非主ボタンの up は同一 pointerId のため isOwnPointer を
678
848
  // 通過してしまう — ドラッグ中の右ボタンリリースでの早期確定と、宙吊りジェスチャを
679
849
  // 右クリックが旧フラグのまま確定する事故の両方を閉塞。Excel も左リリースのみ確定)
@@ -696,6 +866,10 @@ export const useSelectionEngine = (params: UseSelectionEngineParams): SelectionE
696
866
  if (tap !== null && event.pointerId === tap.pointerId) {
697
867
  headerTapRef.current = null
698
868
  }
869
+ const bodyTap = bodyTapRef.current
870
+ if (bodyTap !== null && event.pointerId === bodyTap.pointerId) {
871
+ discardBodyTap()
872
+ }
699
873
  }
700
874
 
701
875
  /** Confirms the in-flight gesture at the event position (primary release — pointerup or chorded move). / 飛行中ジェスチャの確定 (主ボタン解放 — pointerup または chord 中の move)。 */
@@ -737,6 +911,10 @@ export const useSelectionEngine = (params: UseSelectionEngineParams): SelectionE
737
911
  // pointerdown の種別で判定する (実ブラウザは mouse 右クリックの前に必ず pointerdown
738
912
  // (button 2) を配送し、その記録は button ゲートより前で行われる)
739
913
  if (lastPointerTypeRef.current !== "mouse") {
914
+ // 指とペンの品書きは長押しの時計の 1 つの道 (v0.21 touchEditing)。素の品書きは、その表でだけ既定を止める (道を 2 つにしない)
915
+ if (p.onRequestTouchEdit !== undefined) {
916
+ event.preventDefault()
917
+ }
740
918
  return
741
919
  }
742
920
  // ドラッグ中の同時右クリックは無視 (Excel 同等) — 素通しするとドラッグ中に選択が置換され
@@ -762,15 +940,7 @@ export const useSelectionEngine = (params: UseSelectionEngineParams): SelectionE
762
940
  if (cell === null) {
763
941
  return
764
942
  }
765
- // 順序は置換 → 通知 (Excel 意味論 — メニューは置換後の新選択に作用する)。
766
- // 選択の置換だけが条件付き: 選択外なら置換、選択内なら不変 (§6.4.1)
767
- const selection = p.getSelection()
768
- const inSelection = selection.ranges.some((range) => rangeContains(range, cell))
769
- if (!inSelection) {
770
- p.setSelection(reduceSelectionPress(selection, cell, { extend: false, append: false }))
771
- }
772
- // 無条件通知 (唯一の配送チャネル — 選択内右クリック = consumer メニューの最頻フローでも発火)
773
- p.onContextMenuSelect(cell, event)
943
+ deliverContextMenu(cell, event)
774
944
  // preventDefault しない (ネイティブメニューは妨げない — §6.4.1)
775
945
  }
776
946
 
@@ -826,6 +996,7 @@ export const useSelectionEngine = (params: UseSelectionEngineParams): SelectionE
826
996
  body.removeEventListener("lostpointercapture", onLostPointerCapture)
827
997
  body.removeEventListener("contextmenu", onContextMenu)
828
998
  body.removeEventListener("dblclick", onDblClick)
999
+ discardBodyTap()
829
1000
  cleanupDrag()
830
1001
  }
831
1002
  }, [enabled, bodyRef, hitTest, cleanupDrag, abortDrag])
@@ -252,6 +252,14 @@
252
252
  cursor: default;
253
253
  }
254
254
 
255
+ /* 指とペンで選び書く表 (v0.21 touchEditing): 長押しは品書きの時計の 1 つの道 — 行の上の素の吹き出し (iOS) と、長押しの文字の選択を
256
+ 止める (指とペンの素の contextmenu の既定は選択の機械が止める)。属性は touchEditing の表の根にだけ付くので、ほかの表は変わらない */
257
+ .aqsp-root[data-aqsp-touch-editing] .aqsp-row {
258
+ -webkit-touch-callout: none;
259
+ -webkit-user-select: none;
260
+ user-select: none;
261
+ }
262
+
255
263
  /* 配置 (absolute / left / width / top / height / overflow) は VirtualGrid の .aqvs-grid-cell が
256
264
  所有 (§7-3) — ここは描画特性のみ */
257
265
  .aqsp-cell {