@ishibashi0112/spreadsheet-grid 0.34.0 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -44,7 +44,7 @@ npm install @ishibashi0112/spreadsheet-grid
44
44
  # yarn add @ishibashi0112/spreadsheet-grid
45
45
  ```
46
46
 
47
- Requires **react** and **react-dom** `>= 19` as peer dependencies (install them in your app if you have not already). `@tanstack/react-virtual` is a regular dependency and is installed automatically.
47
+ Requires **react** and **react-dom** `>= 19` as peer dependencies (install them in your app if you have not already). `@tanstack/virtual-core` (the framework-agnostic core of TanStack Virtual) is a regular dependency and is installed automatically; the React adapter is bundled with the grid.
48
48
 
49
49
  ## Styles
50
50
 
@@ -333,7 +333,7 @@ npm install @ishibashi0112/spreadsheet-grid
333
333
  # yarn add @ishibashi0112/spreadsheet-grid
334
334
  ```
335
335
 
336
- peer 依存として **react** / **react-dom** `>= 19` が必要です(未導入なら利用側で入れてください)。`@tanstack/react-virtual` は通常依存として自動的に入ります。
336
+ peer 依存として **react** / **react-dom** `>= 19` が必要です(未導入なら利用側で入れてください)。`@tanstack/virtual-core`(TanStack Virtual のフレームワーク非依存コア)は通常依存として自動的に入ります。React 向けアダプタはグリッド側に同梱しています。
337
337
 
338
338
  ### スタイル
339
339
 
@@ -0,0 +1,31 @@
1
+ import { type GridUiAction } from '../model/gridActions';
2
+ import type { GridColumn, GridSelection, GridUiState, RowModel, SpreadsheetGridProps } from '../model/gridTypes';
3
+ import type { ServerSideCellEditInput } from '../logic/serverSideEdits';
4
+ export type ClipboardEventLike = {
5
+ clipboardData: {
6
+ getData: (type: string) => string;
7
+ } | null;
8
+ preventDefault: () => void;
9
+ };
10
+ export type ClipboardControllerArgs<T extends object> = {
11
+ rows: T[];
12
+ rowModel: RowModel<T>;
13
+ visibleColumns: GridColumn<T>[];
14
+ uiState: GridUiState;
15
+ readOnly: boolean;
16
+ canEditCell: SpreadsheetGridProps<T>['canEditCell'];
17
+ createRow?: () => T;
18
+ createOverflowColumn?: (columnIndex: number) => GridColumn<T>;
19
+ onRowsChange?: (nextRows: T[]) => void;
20
+ onColumnsChange?: (nextColumns: GridColumn<T>[]) => void;
21
+ applyServerSideCellEdits?: (edits: ServerSideCellEditInput<T>[]) => number;
22
+ isRowExportable?: SpreadsheetGridProps<T>['isRowExportable'];
23
+ dispatch: (action: GridUiAction) => void;
24
+ };
25
+ export type ClipboardController<T extends object> = {
26
+ update: (args: ClipboardControllerArgs<T>) => void;
27
+ handleCopy: () => Promise<void>;
28
+ handlePaste: (event: ClipboardEventLike) => void;
29
+ };
30
+ export declare const computeIsWholeGridSelected: (selection: GridSelection, viewRowCount: number, columnCount: number) => boolean;
31
+ export declare const createClipboardController: <T extends object>() => ClipboardController<T>;
@@ -0,0 +1,27 @@
1
+ import { type GridUiAction } from '../model/gridActions';
2
+ import type { CellCoord, EditorCommitDirection, EditorCommitResult, GridColumn, GridUiState, RowModel } from '../model/gridTypes';
3
+ import type { ServerSideCellEditInput } from '../logic/serverSideEdits';
4
+ export type EditControllerArgs<T extends object> = {
5
+ uiState: GridUiState;
6
+ rows: T[];
7
+ visibleColumns: GridColumn<T>[];
8
+ rowModel: RowModel<T>;
9
+ setEditorInitialValue: (value: string) => void;
10
+ onRowsChange?: (nextRows: T[]) => void;
11
+ applyServerSideCellEdits?: (edits: ServerSideCellEditInput<T>[]) => number;
12
+ dispatch: (action: GridUiAction) => void;
13
+ gridRootRef: {
14
+ readonly current: HTMLElement | null;
15
+ };
16
+ editorActionGuardRef: {
17
+ current: boolean;
18
+ };
19
+ };
20
+ export type EditController<T extends object> = {
21
+ update: (args: EditControllerArgs<T>) => void;
22
+ activateSingleCell: (cell: CellCoord) => void;
23
+ startEditWithValue: (cell: CellCoord, initialValue: string) => void;
24
+ commitEdit: (committedValue: unknown, direction?: EditorCommitDirection) => EditorCommitResult;
25
+ cancelEdit: () => void;
26
+ };
27
+ export declare const createEditController: <T extends object>() => EditController<T>;
@@ -0,0 +1,28 @@
1
+ import { type GridUiAction } from '../model/gridActions';
2
+ import type { CellCoord, GridSelection, UndoRedoState } from '../model/gridTypes.core';
3
+ export type GridHistoryEntry<T> = {
4
+ rows: T[];
5
+ selection: GridSelection;
6
+ activeCell: CellCoord | null;
7
+ };
8
+ export type HistoryControllerArgs<T> = {
9
+ rows: T[];
10
+ selection: GridSelection;
11
+ activeCell: CellCoord | null;
12
+ onRowsChange?: (nextRows: T[]) => void;
13
+ dispatch: (action: GridUiAction) => void;
14
+ enabled: boolean;
15
+ limit: number;
16
+ onUndoRedoStateChange?: (state: UndoRedoState) => void;
17
+ onAfterRestore?: (activeCell: CellCoord | null) => void;
18
+ };
19
+ export type HistoryController<T> = {
20
+ update: (args: HistoryControllerArgs<T>) => void;
21
+ handleRowsChange: (nextRows: T[]) => void;
22
+ undo: () => void;
23
+ redo: () => void;
24
+ canUndo: () => boolean;
25
+ canRedo: () => boolean;
26
+ clearHistory: () => void;
27
+ };
28
+ export declare const createHistoryController: <T>() => HistoryController<T>;
@@ -0,0 +1,36 @@
1
+ import { type GridUiAction } from '../model/gridActions';
2
+ import type { CellCoord, GridColumn, GridUiState, RowModel, SpreadsheetGridProps } from '../model/gridTypes';
3
+ export type GridKeyboardEventLike = {
4
+ key: string;
5
+ ctrlKey: boolean;
6
+ metaKey: boolean;
7
+ shiftKey: boolean;
8
+ altKey: boolean;
9
+ isComposing: boolean;
10
+ target: EventTarget | null;
11
+ preventDefault: () => void;
12
+ };
13
+ export type KeyboardControllerArgs<T> = {
14
+ uiState: GridUiState;
15
+ rowModel: RowModel<T>;
16
+ visibleColumns: GridColumn<T>[];
17
+ readOnly: boolean;
18
+ canEditCell: SpreadsheetGridProps<T>['canEditCell'];
19
+ setEditorInitialValue: (value: string) => void;
20
+ dispatch: (action: GridUiAction) => void;
21
+ handleCopy: () => Promise<void>;
22
+ handleCellDoubleClick: (cell: CellCoord) => void;
23
+ isWholeGridSelected: boolean;
24
+ selectEntireGrid: () => void;
25
+ onUndo: () => void;
26
+ onRedo: () => void;
27
+ onClearSelection: () => void;
28
+ enableClearOnDelete: boolean;
29
+ onToggleCheckboxCell: (cell: CellCoord) => void;
30
+ onToggleGroup: (groupKey: string) => void;
31
+ };
32
+ export type KeyboardController<T> = {
33
+ update: (args: KeyboardControllerArgs<T>) => void;
34
+ handleKeyDown: (event: GridKeyboardEventLike) => Promise<void>;
35
+ };
36
+ export declare const createKeyboardController: <T>() => KeyboardController<T>;
@@ -0,0 +1,21 @@
1
+ export type PanelHeaderDragPointerDown = {
2
+ button: number;
3
+ pointerId: number;
4
+ clientX: number;
5
+ clientY: number;
6
+ target: EventTarget | null;
7
+ preventDefault: () => void;
8
+ };
9
+ export type PanelHeaderDragStartArgs = {
10
+ layout: {
11
+ top: number;
12
+ left: number;
13
+ } | null;
14
+ onMove: (top: number, left: number) => void;
15
+ };
16
+ export type PanelHeaderDragController = {
17
+ startFromPointerDown: (event: PanelHeaderDragPointerDown, args: PanelHeaderDragStartArgs) => boolean;
18
+ isActive: () => boolean;
19
+ dispose: () => void;
20
+ };
21
+ export declare const createPanelHeaderDragController: () => PanelHeaderDragController;
@@ -0,0 +1,5 @@
1
+ export declare const systemColorSchemeStore: {
2
+ subscribe(onChange: () => void): () => void;
3
+ getSnapshot(): boolean;
4
+ getServerSnapshot(): boolean;
5
+ };
@@ -0,0 +1,6 @@
1
+ import type { GridResolvedSlot } from '../model/gridTypes.core';
2
+ export type TooltipController = {
3
+ setSlot: (slot: GridResolvedSlot | undefined) => void;
4
+ dispose: () => void;
5
+ };
6
+ export declare function acquireTooltipController(slot?: GridResolvedSlot): TooltipController;
@@ -0,0 +1,30 @@
1
+ import type { ColumnMeasurement } from '../logic/geometry';
2
+ import type { CellCoord } from '../model/gridTypes.core';
3
+ export type ViewportCellRect = {
4
+ left: number;
5
+ top: number;
6
+ width: number;
7
+ height: number;
8
+ };
9
+ export type ViewportSyncArgs<T> = {
10
+ scrollElement: HTMLElement | null;
11
+ columnVirtualizer: {
12
+ measure: () => void;
13
+ };
14
+ columnMeasurements: ColumnMeasurement<T>[];
15
+ totalScrollWidth: number;
16
+ physicalBodyHeight: number;
17
+ headerHeight: number;
18
+ leftPaneWidth: number;
19
+ rightPaneWidth: number;
20
+ centerLeadingWidth: number;
21
+ activeCellRect: ViewportCellRect | null;
22
+ activeCell: CellCoord | null;
23
+ verticalScaleFactor: number;
24
+ };
25
+ export type ViewportSyncController<T> = {
26
+ update: (args: ViewportSyncArgs<T>) => void;
27
+ };
28
+ export declare const clampScrollToContent: (scrollElement: HTMLElement, args: Pick<ViewportSyncArgs<unknown>, "totalScrollWidth" | "physicalBodyHeight" | "headerHeight">) => void;
29
+ export declare const scrollCellIntoView: (scrollElement: HTMLElement, rect: ViewportCellRect, args: Pick<ViewportSyncArgs<unknown>, "headerHeight" | "leftPaneWidth" | "rightPaneWidth" | "centerLeadingWidth" | "verticalScaleFactor">) => void;
30
+ export declare const createViewportSyncController: <T>() => ViewportSyncController<T>;
@@ -0,0 +1,5 @@
1
+ export type ControllerLike<Args> = {
2
+ update: (args: Args) => void;
3
+ dispose?: () => void;
4
+ };
5
+ export declare function useController<Args, C extends ControllerLike<Args>>(create: () => C, args: Args): C;
@@ -1,25 +1,8 @@
1
- import { type Dispatch } from 'react';
2
- import { type GridUiAction } from '../model/gridActions';
3
- import type { GridColumn, SpreadsheetGridProps, GridUiState, RowModel } from '../model/gridTypes';
4
- import type { ServerSideCellEditInput } from '../logic/serverSideEdits';
5
- type UseGridClipboardControllerArgs<T extends object> = {
6
- rows: T[];
7
- rowModel: RowModel<T>;
8
- visibleColumns: GridColumn<T>[];
9
- uiState: GridUiState;
10
- readOnly: boolean;
11
- canEditCell: SpreadsheetGridProps<T>['canEditCell'];
12
- createRow?: () => T;
13
- createOverflowColumn?: (columnIndex: number) => GridColumn<T>;
14
- onRowsChange?: (nextRows: T[]) => void;
15
- onColumnsChange?: (nextColumns: GridColumn<T>[]) => void;
16
- applyServerSideCellEdits?: (edits: ServerSideCellEditInput<T>[]) => number;
17
- isRowExportable?: SpreadsheetGridProps<T>['isRowExportable'];
18
- dispatch: Dispatch<GridUiAction>;
19
- };
20
- export declare const useGridClipboardController: <T extends object>({ rows, rowModel, visibleColumns, uiState, readOnly, canEditCell, createRow, createOverflowColumn, onRowsChange, onColumnsChange, applyServerSideCellEdits, isRowExportable, dispatch, }: UseGridClipboardControllerArgs<T>) => {
1
+ import { type ClipboardEvent } from 'react';
2
+ import { type ClipboardControllerArgs } from '../controllers/clipboardController';
3
+ export declare const useGridClipboardController: <T extends object>(args: ClipboardControllerArgs<T>) => {
21
4
  isWholeGridSelected: boolean;
22
5
  handleCopy: () => Promise<void>;
23
- handlePaste: (event: React.ClipboardEvent<HTMLDivElement>) => void;
6
+ handlePaste: (event: ClipboardEvent<HTMLDivElement>) => void;
24
7
  };
25
8
  export default useGridClipboardController;
@@ -1,23 +1,8 @@
1
- import { type Dispatch, type RefObject } from 'react';
2
- import { type GridUiAction } from '../model/gridActions';
3
- import type { CellCoord, EditorCommitDirection, EditorCommitResult, GridColumn, GridUiState, RowModel } from '../model/gridTypes';
4
- import type { ServerSideCellEditInput } from '../logic/serverSideEdits';
5
- type UseGridEditControllerArgs<T extends object> = {
6
- uiState: GridUiState;
7
- rows: T[];
8
- visibleColumns: GridColumn<T>[];
9
- rowModel: RowModel<T>;
10
- setEditorInitialValue: (value: string) => void;
11
- onRowsChange?: (nextRows: T[]) => void;
12
- applyServerSideCellEdits?: (edits: ServerSideCellEditInput<T>[]) => number;
13
- dispatch: Dispatch<GridUiAction>;
14
- gridRootRef: RefObject<HTMLDivElement | null>;
15
- editorActionGuardRef: RefObject<boolean>;
16
- };
17
- export declare const useGridEditController: <T extends object>({ uiState, rows, visibleColumns, rowModel, setEditorInitialValue, onRowsChange, applyServerSideCellEdits, dispatch, gridRootRef, editorActionGuardRef, }: UseGridEditControllerArgs<T>) => {
18
- activateSingleCell: (cell: CellCoord) => void;
19
- startEditWithValue: (cell: CellCoord, initialValue: string) => void;
20
- commitEdit: (committedValue: unknown, direction?: EditorCommitDirection) => EditorCommitResult;
1
+ import { type EditControllerArgs } from '../controllers/editController';
2
+ export declare const useGridEditController: <T extends object>(args: EditControllerArgs<T>) => {
3
+ activateSingleCell: (cell: import("..").CellCoord) => void;
4
+ startEditWithValue: (cell: import("..").CellCoord, initialValue: string) => void;
5
+ commitEdit: (committedValue: unknown, direction?: import("..").EditorCommitDirection) => import("..").EditorCommitResult;
21
6
  cancelEdit: () => void;
22
7
  };
23
8
  export default useGridEditController;
@@ -1,18 +1,5 @@
1
- import type { Dispatch } from 'react';
2
- import { type GridUiAction } from '../model/gridActions';
3
- import type { CellCoord, GridSelection, UndoRedoState } from '../model/gridTypes';
4
- type UseGridHistoryControllerArgs<T> = {
5
- rows: T[];
6
- selection: GridSelection;
7
- activeCell: CellCoord | null;
8
- onRowsChange?: (nextRows: T[]) => void;
9
- dispatch: Dispatch<GridUiAction>;
10
- enabled: boolean;
11
- limit: number;
12
- onUndoRedoStateChange?: (state: UndoRedoState) => void;
13
- onAfterRestore?: (activeCell: CellCoord | null) => void;
14
- };
15
- export declare const useGridHistoryController: <T>({ rows, selection, activeCell, onRowsChange, dispatch, enabled, limit, onUndoRedoStateChange, onAfterRestore, }: UseGridHistoryControllerArgs<T>) => {
1
+ import { type HistoryControllerArgs } from '../controllers/historyController';
2
+ export declare const useGridHistoryController: <T>(args: HistoryControllerArgs<T>) => {
16
3
  handleRowsChange: ((nextRows: T[]) => void) | undefined;
17
4
  undo: () => void;
18
5
  redo: () => void;
@@ -1,26 +1,6 @@
1
- import { type Dispatch, type KeyboardEvent } from 'react';
2
- import { type GridUiAction } from '../model/gridActions';
3
- import type { CellCoord, GridColumn, GridUiState, RowModel, SpreadsheetGridProps } from '../model/gridTypes';
4
- type UseGridKeyboardInteractionsArgs<T> = {
5
- uiState: GridUiState;
6
- rowModel: RowModel<T>;
7
- visibleColumns: GridColumn<T>[];
8
- readOnly: boolean;
9
- canEditCell: SpreadsheetGridProps<T>['canEditCell'];
10
- setEditorInitialValue: (value: string) => void;
11
- dispatch: Dispatch<GridUiAction>;
12
- handleCopy: () => Promise<void>;
13
- handleCellDoubleClick: (cell: CellCoord) => void;
14
- isWholeGridSelected: boolean;
15
- selectEntireGrid: () => void;
16
- onUndo: () => void;
17
- onRedo: () => void;
18
- onClearSelection: () => void;
19
- enableClearOnDelete: boolean;
20
- onToggleCheckboxCell: (cell: CellCoord) => void;
21
- onToggleGroup: (groupKey: string) => void;
22
- };
23
- export declare const useGridKeyboardInteractions: <T>({ uiState, rowModel, visibleColumns, readOnly, canEditCell, setEditorInitialValue, dispatch, handleCopy, handleCellDoubleClick, isWholeGridSelected, selectEntireGrid, onUndo, onRedo, onClearSelection, enableClearOnDelete, onToggleCheckboxCell, onToggleGroup, }: UseGridKeyboardInteractionsArgs<T>) => {
1
+ import { type KeyboardEvent } from 'react';
2
+ import { type KeyboardControllerArgs } from '../controllers/keyboardController';
3
+ export declare const useGridKeyboardInteractions: <T>(args: KeyboardControllerArgs<T>) => {
24
4
  handleKeyDown: (event: KeyboardEvent<HTMLDivElement>) => Promise<void>;
25
5
  };
26
6
  export default useGridKeyboardInteractions;
@@ -0,0 +1,7 @@
1
+ import { type GridStore, type GridViewState, type Updater } from '../model/gridStore';
2
+ import type { GridUiState } from '../model/gridTypes';
3
+ export declare function useGridStore(store: GridStore): [GridUiState, GridStore['dispatch']];
4
+ export type GridViewStateSetters = {
5
+ [K in keyof GridViewState as `set${Capitalize<K>}`]: (next: Updater<GridViewState[K]>) => void;
6
+ };
7
+ export declare function useGridViewState(store: GridStore): [GridViewState, GridViewStateSetters];
@@ -1,23 +1,7 @@
1
1
  import { type RefObject } from 'react';
2
- import type { ActiveCellOverlayRect } from '../ActiveCellOverlay';
3
- import type { ColumnMeasurement } from '../logic/geometry';
4
- import type { CellCoord } from '../model/gridTypes';
5
- type VirtualizerLike = {
6
- measure: () => void;
7
- };
8
- type UseGridViewportSyncArgs<T> = {
2
+ import { type ViewportSyncArgs } from '../controllers/viewportSyncController';
3
+ type UseGridViewportSyncArgs<T> = Omit<ViewportSyncArgs<T>, 'scrollElement'> & {
9
4
  scrollRef: RefObject<HTMLDivElement | null>;
10
- columnVirtualizer: VirtualizerLike;
11
- columnMeasurements: ColumnMeasurement<T>[];
12
- totalScrollWidth: number;
13
- physicalBodyHeight: number;
14
- headerHeight: number;
15
- leftPaneWidth: number;
16
- rightPaneWidth: number;
17
- centerLeadingWidth: number;
18
- activeCellRect: ActiveCellOverlayRect | null;
19
- activeCell: CellCoord | null;
20
- verticalScaleFactor: number;
21
5
  };
22
- export declare const useGridViewportSync: <T>({ scrollRef, columnVirtualizer, columnMeasurements, totalScrollWidth, physicalBodyHeight, headerHeight, leftPaneWidth, rightPaneWidth, centerLeadingWidth, activeCellRect, activeCell, verticalScaleFactor, }: UseGridViewportSyncArgs<T>) => void;
6
+ export declare const useGridViewportSync: <T>({ scrollRef, ...args }: UseGridViewportSyncArgs<T>) => void;
23
7
  export default useGridViewportSync;
@@ -1,2 +1,3 @@
1
+ import { type ResolvedGridTheme } from '../logic/theme';
1
2
  import type { GridTheme } from '../model/gridTypes';
2
- export declare function useResolvedGridTheme(theme: GridTheme): 'light' | 'dark';
3
+ export declare function useResolvedGridTheme(theme: GridTheme): ResolvedGridTheme;
@@ -0,0 +1,5 @@
1
+ import { Virtualizer, type PartialKeys, type VirtualizerOptions } from '@tanstack/virtual-core';
2
+ export type UseVirtualizerCoreOptions<TScrollElement extends Element, TItemElement extends Element> = PartialKeys<VirtualizerOptions<TScrollElement, TItemElement>, 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'> & {
3
+ useFlushSync?: boolean;
4
+ };
5
+ export declare function useVirtualizerCore<TScrollElement extends Element, TItemElement extends Element = Element>(options: UseVirtualizerCoreOptions<TScrollElement, TItemElement>): Virtualizer<TScrollElement, TItemElement>;