@ishibashi0112/spreadsheet-grid 1.13.0 → 1.15.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/API_REFERENCE.md +228 -16
- package/README.md +13 -11
- package/dist/GridShell.d.ts +1 -1
- package/dist/ai/useGridAgentTools.d.ts +8 -0
- package/dist/ai.cjs +1 -1
- package/dist/ai.d.ts +4 -0
- package/dist/ai.js +186 -125
- package/dist/common.d.ts +1 -1
- package/dist/features/pagination.d.ts +2 -0
- package/dist/features/types.d.ts +8 -0
- package/dist/hooks/useGridBarContext.d.ts +5 -3
- package/dist/hooks/useGridLocaleText.d.ts +1 -1
- package/dist/hooks/useServerSideRowModel.d.ts +2 -1
- package/dist/index.cjs +14 -13
- package/dist/index.js +4608 -4328
- package/dist/lite/createSpreadsheetGrid-DRSQBYBT.cjs +14 -0
- package/dist/lite/createSpreadsheetGrid-atbwakIX.js +5597 -0
- package/dist/lite/createSpreadsheetGrid.cjs +1 -1
- package/dist/lite/createSpreadsheetGrid.js +1 -1
- package/dist/lite/features/grouping.cjs +1 -1
- package/dist/lite/features/grouping.js +1 -1
- package/dist/lite/features/pagination.cjs +1 -0
- package/dist/lite/features/pagination.js +2 -0
- package/dist/lite/features/rowDrag.cjs +1 -1
- package/dist/lite/features/rowDrag.js +1 -1
- package/dist/lite/features/scrollHint.cjs +1 -1
- package/dist/lite/features/scrollHint.js +1 -1
- package/dist/lite/features/serverSide.cjs +1 -1
- package/dist/lite/features/serverSide.js +1 -1
- package/dist/lite/grouping-BKT6i8at.cjs +1 -0
- package/dist/lite/{grouping-u4J8Rl0V.js → grouping-CZ86adA8.js} +30 -30
- package/dist/lite/pagination-C6zVQode.cjs +1 -0
- package/dist/lite/pagination-DJB7JLDr.js +114 -0
- package/dist/lite/rowDrag-DMI_HkRV.cjs +1 -0
- package/dist/lite/{rowDrag-e6TC1gsM.js → rowDrag-DZ5LiIQN.js} +20 -19
- package/dist/lite/scrollHint-Bn6YBjDF.js +210 -0
- package/dist/lite/scrollHint-CvLQcvC4.cjs +1 -0
- package/dist/lite/{serverSide-CLb4dLUK.js → serverSide-BWZPpSkL.js} +1 -0
- package/dist/lite/serverSide-BXmZ_co8.cjs +1 -0
- package/dist/lite.cjs +1 -1
- package/dist/lite.d.ts +1 -0
- package/dist/lite.js +17 -16
- package/dist/style.css +1 -1
- package/dist/style.layer.css +1 -1
- package/dist/view/DefaultGridBottomBar.d.ts +3 -1
- package/dist/view/DefaultGridTopBar.d.ts +2 -1
- package/dist/view/GridBodyGroupRow.d.ts +2 -1
- package/dist/view/GridBodyLayer.d.ts +2 -1
- package/dist/view/GridPager.d.ts +13 -0
- package/dist/view/GridScrollHint.d.ts +3 -1
- package/package.json +2 -2
- package/skills/spreadsheet-grid/SKILL.md +7 -3
- package/dist/lite/createSpreadsheetGrid-DNoVKiwo.cjs +0 -13
- package/dist/lite/createSpreadsheetGrid-cOTbng_2.js +0 -5436
- package/dist/lite/grouping-DKYPOjCk.cjs +0 -1
- package/dist/lite/rowDrag-Cn5fud6W.cjs +0 -1
- package/dist/lite/scrollHint-Bt8fuU7l.cjs +0 -1
- package/dist/lite/scrollHint-Dr4TOFNn.js +0 -196
- package/dist/lite/serverSide-COYBN6Pt.cjs +0 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A virtualized spreadsheet / data grid for React 18.3 / 19 (~1M rows, pinned columns, Excel-like editing / selection / clipboard, filters & sorting, client-side and server-side row models). 日本語は下にあります。
|
|
4
4
|
|
|
5
|
-
**[Docs & live demo](https://datasheet-grid.vercel.app)** · [Playground](https://datasheet-grid.vercel.app/playground) · [Try on StackBlitz](https://stackblitz.com/fork/github/ishibashi0112/datasheet-grid/tree/main/examples/basic?file=src/App.tsx&terminal=dev) · [GitHub](https://github.com/ishibashi0112/datasheet-grid) · [Changelog](https://github.com/ishibashi0112/datasheet-grid/blob/main/CHANGELOG.md) · [Solid version](https://datasheet-grid.vercel.app/docs/solid/installation)
|
|
5
|
+
**[Docs & live demo](https://datasheet-grid.vercel.app/en)** · [Playground](https://datasheet-grid.vercel.app/en/playground) · [Try on StackBlitz](https://stackblitz.com/fork/github/ishibashi0112/datasheet-grid/tree/main/examples/basic?file=src/App.tsx&terminal=dev) · [GitHub](https://github.com/ishibashi0112/datasheet-grid) · [Changelog](https://github.com/ishibashi0112/datasheet-grid/blob/main/CHANGELOG.md) · [Solid version](https://datasheet-grid.vercel.app/en/docs/solid/installation)
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -16,9 +16,9 @@ Peer dependencies: `react` / `react-dom` `^18.3.0 || ^19.0.0`. Supported browser
|
|
|
16
16
|
import '@ishibashi0112/spreadsheet-grid/style.css'
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
`style.css` also works as is with Tailwind CSS v4. The cascade-layer variant `style.layer.css` (everything inside `@layer ssg-base`) is only for when you want the grid inside your layer order, and then you must declare that order in your CSS before Tailwind — `@layer theme, base, ssg-base, components, utilities;` — otherwise `ssg-base` becomes the weakest layer and Tailwind's preflight breaks the borders, buttons and popovers ([details](https://datasheet-grid.vercel.app/docs/css)). The declaration must load before `style.layer.css`: import `style.layer.css` from that CSS file (`@import`), or, from JS, after it. The same goes for StyleX with `useLayers`.
|
|
19
|
+
`style.css` also works as is with Tailwind CSS v4. The cascade-layer variant `style.layer.css` (everything inside `@layer ssg-base`) is only for when you want the grid inside your layer order, and then you must declare that order in your CSS before Tailwind — `@layer theme, base, ssg-base, components, utilities;` — otherwise `ssg-base` becomes the weakest layer and Tailwind's preflight breaks the borders, buttons and popovers ([details](https://datasheet-grid.vercel.app/en/docs/css)). The declaration must load before `style.layer.css`: import `style.layer.css` from that CSS file (`@import`), or, from JS, after it. The same goes for StyleX with `useLayers`.
|
|
20
20
|
|
|
21
|
-
Using Astryx, Mantine, HeroUI v3 or shadcn/ui? Also import its theme after `style.css` (`themes/astryx.css` / `themes/mantine.css` / `themes/heroui.css` / `themes/shadcn.css`) so the grid follows your design system's colors and light / dark ([guide](https://datasheet-grid.vercel.app/docs/guides/design-systems)).
|
|
21
|
+
Using Astryx, Mantine, HeroUI v3 or shadcn/ui? Also import its theme after `style.css` (`themes/astryx.css` / `themes/mantine.css` / `themes/heroui.css` / `themes/shadcn.css`) so the grid follows your design system's colors and light / dark ([guide](https://datasheet-grid.vercel.app/en/docs/guides/design-systems)).
|
|
22
22
|
|
|
23
23
|
## Quick start
|
|
24
24
|
|
|
@@ -52,7 +52,7 @@ More runnable examples (server-side row model, Astryx) are in [`examples/`](http
|
|
|
52
52
|
|
|
53
53
|
## Smaller bundles: `/lite` (0.54.0+)
|
|
54
54
|
|
|
55
|
-
`SpreadsheetGrid` includes every feature (about
|
|
55
|
+
`SpreadsheetGrid` includes every feature (about 236KB gzip of initial JS). The `/lite` entry builds a grid with only the features you pass; the rest is left out of your bundle (about 119KB with no features, about 145KB with the `standardFeatures` preset).
|
|
56
56
|
|
|
57
57
|
```tsx
|
|
58
58
|
import { createSpreadsheetGrid, standardFeatures, serverSideFeature } from '@ishibashi0112/spreadsheet-grid/lite'
|
|
@@ -66,7 +66,7 @@ Props, the `ref` handle and types are the same as `SpreadsheetGrid`. Props of fe
|
|
|
66
66
|
|
|
67
67
|
## Natural-language filtering: `/ai` (0.57.0+)
|
|
68
68
|
|
|
69
|
-
`GridAskBar` from the `/ai` entry turns a sentence ("Tokyo items with 10 or fewer in stock, most expensive first") into the grid's filters, sort, global search and column visibility. The grid never calls an AI: your `ask` function forwards the request to your own server, which calls any model with structured output. Row data is never sent, and every answer is validated, shown as chips and undoable. It is a separate entry (about 14.0KB gzip). Server code for Claude, OpenAI, Gemini and the Vercel AI SDK (AI Gateway) is in the [guide](https://datasheet-grid.vercel.app/docs/guides/ai-filter); the API is in `API_REFERENCE.md` (「ことばで絞り込み」).
|
|
69
|
+
`GridAskBar` from the `/ai` entry turns a sentence ("Tokyo items with 10 or fewer in stock, most expensive first") into the grid's filters, sort, global search and column visibility. The grid never calls an AI: your `ask` function forwards the request to your own server, which calls any model with structured output. Row data is never sent, and every answer is validated, shown as chips and undoable. It is a separate entry (about 14.0KB gzip). Server code for Claude, OpenAI, Gemini and the Vercel AI SDK (AI Gateway) is in the [guide](https://datasheet-grid.vercel.app/en/docs/guides/ai-filter); the API is in `API_REFERENCE.md` (「ことばで絞り込み」).
|
|
70
70
|
|
|
71
71
|
```tsx
|
|
72
72
|
import { GridAskBar } from '@ishibashi0112/spreadsheet-grid/ai'
|
|
@@ -74,6 +74,8 @@ import { GridAskBar } from '@ishibashi0112/spreadsheet-grid/ai'
|
|
|
74
74
|
<GridAskBar grid={gridRef} columns={columns} ask={ask} />
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
The same entry has `useGridAgentTools` (1.14.0+; `createGridAgentTools` outside components): tools an AI agent can call to read and change the view, jump to a row and, when you allow it, read rows and write cells (one undo step). Pass `definitions` to your own chat and run calls with `execute(name, input)`, or register them with a browser agent (WebMCP) with `registerGridAgentTools`. See the [guide](https://datasheet-grid.vercel.app/en/docs/guides/ai-agent) and `API_REFERENCE.md` (「AI エージェントの道具」).
|
|
78
|
+
|
|
77
79
|
## Documentation in this package
|
|
78
80
|
|
|
79
81
|
Everything below ships inside the npm package, so it is available offline (for example to coding agents reading `node_modules`).
|
|
@@ -82,7 +84,7 @@ Everything below ships inside the npm package, so it is available offline (for e
|
|
|
82
84
|
| --- | --- |
|
|
83
85
|
| Full API reference — props, column options, imperative handle (`ref`), recipes (Japanese) | `API_REFERENCE.md` in this package |
|
|
84
86
|
| Per-field docs (shown on hover) | JSDoc in the type definitions. Field docs live in the core package's file `dist/model/gridTypes.core.d.ts` and match the tables in `API_REFERENCE.md` |
|
|
85
|
-
|
|
|
87
|
+
| Docs in English and Japanese (the guides are being translated into English), guides with live demos, playground, theme builder | [datasheet-grid.vercel.app/en](https://datasheet-grid.vercel.app/en) |
|
|
86
88
|
| Design notes, changelog | [GitHub README](https://github.com/ishibashi0112/datasheet-grid#readme) / [CHANGELOG.md](https://github.com/ishibashi0112/datasheet-grid/blob/main/CHANGELOG.md) |
|
|
87
89
|
|
|
88
90
|
## Using with AI coding assistants
|
|
@@ -91,7 +93,7 @@ This library is new, so AI coding assistants rarely know its API and tend to gue
|
|
|
91
93
|
|
|
92
94
|
- **Skill.** The package ships an [Agent Skill](https://agentskills.io) at `skills/spreadsheet-grid/SKILL.md` (0.57.0+): a short guide with the rules below and where to look in `API_REFERENCE.md`. Tools that read `SKILL.md` (Claude Code, Cursor, Codex, GitHub Copilot and others) use it once it is in their skills folder. Install it from GitHub with `npx skills add https://github.com/ishibashi0112/datasheet-grid/tree/main/packages/react/skills/spreadsheet-grid`, or copy the folder from `node_modules` (for Claude Code, into `.claude/skills/`).
|
|
93
95
|
- **One line for `AGENTS.md` / `CLAUDE.md`:** "Before writing grid code, read `node_modules/@ishibashi0112/spreadsheet-grid/API_REFERENCE.md` and use only the props and methods it lists."
|
|
94
|
-
- **Docs for LLMs:** [llms.txt](https://datasheet-grid.vercel.app/llms.txt) lists every docs page (add `.md` to a page URL to get its Markdown), and [llms-full.txt](https://datasheet-grid.vercel.app/llms-full.txt) has all pages in one (large) file. Each docs page also has "Copy Markdown" and "Open" (in ChatGPT / Claude / Cursor).
|
|
96
|
+
- **Docs for LLMs:** [llms.txt](https://datasheet-grid.vercel.app/en/llms.txt) lists every docs page (add `.md` to a page URL to get its Markdown), and [llms-full.txt](https://datasheet-grid.vercel.app/en/llms-full.txt) has all pages in one (large) file. Each docs page also has "Copy Markdown" and "Open" (in ChatGPT / Claude / Cursor).
|
|
95
97
|
|
|
96
98
|
## Rules that are easy to get wrong
|
|
97
99
|
|
|
@@ -101,13 +103,13 @@ This library is new, so AI coding assistants rarely know its API and tend to gue
|
|
|
101
103
|
- **`rows` or `dataSource`.** `rows` is the client-side row model; `dataSource` switches to the server-side row model. They are mutually exclusive.
|
|
102
104
|
- **Height.** Use the `height` prop, not `style.height` on the root. A value containing `%` (`'100%'`) sizes the **whole grid including its bars** and needs a parent with a definite height; a number sizes the **scroll area only**. Without `height`, the scroll area is capped at `480px` (`maxHeight`).
|
|
103
105
|
- **Imperative API.** Pass `ref` to get a `SpreadsheetGridHandle<T>` (no `forwardRef` needed on your side; works the same on React 18.3 and 19). If you wrap the grid in your own component and pass `ref` to the wrapper, make the wrapper a `forwardRef` on React 18: the types accept `ref` either way, but React 18 does not pass it as a prop, so the handle stays `null`.
|
|
104
|
-
- **Positions are view positions.** `viewRowIndex` / `colIndex` (in `selectCell` and the like) are positions after sorting and filtering, and `colIndex` also counts the columns the grid adds (row drag handle, detail toggle, auto group column). Look them up with `getViewRowIndex(rowKey)` / `getColIndex(columnKey)` instead of `rows.findIndex`.
|
|
106
|
+
- **Positions are view positions.** `viewRowIndex` / `colIndex` (in `selectCell` and the like) are positions after sorting and filtering, and `colIndex` also counts the columns the grid adds (row drag handle, detail toggle, auto group column). Look them up with `getViewRowIndex(rowKey)` / `getColIndex(columnKey)` instead of `rows.findIndex`. With pagination (`pagination`) row positions are still continuous across all pages (not positions within the current page).
|
|
105
107
|
- **Next.js App Router.** Render the grid from a Client Component (a file with `'use client'`); the package does not add the directive.
|
|
106
108
|
- **UI language.** The grid's own texts are Japanese by default. For English pass `localeText={localeTextEn}` from `@ishibashi0112/spreadsheet-grid/locales/en` (and `gridAskLocaleTextEn` to `GridAskBar`).
|
|
107
109
|
|
|
108
110
|
## Versioning
|
|
109
111
|
|
|
110
|
-
Releases follow semver, and this package, the core and the Solid version (`@ishibashi0112/spreadsheet-grid-solid`, from 1.4.0) always share one version. Since 1.0, breaking changes ship only in major releases and are listed in the [changelog](https://github.com/ishibashi0112/datasheet-grid/blob/main/CHANGELOG.md) (before 1.0 they shipped in minor releases, under 「挙動の変化」 / 「core の破壊的変更」). The public surface is the entry points above (`.` / `/lite` / `/ai` / `/locales/en` / `/testing`), the CSS files, `API_REFERENCE.md`, and the CSS tokens, classes and attributes listed there. TypeScript 5.8 or later is supported (`moduleResolution` `bundler` or `nodenext`). Anything to be removed is deprecated in a minor release first, with a one-time console warning in development builds. The core's building blocks (`@ishibashi0112/spreadsheet-grid-core/internal/…`; the old subpaths without `internal/` were removed in 0.61.0) are internal and may change in any release (this package depends on the core of exactly the same version). Details: [Versioning](https://datasheet-grid.vercel.app/docs/versioning)
|
|
112
|
+
Releases follow semver, and this package, the core and the Solid version (`@ishibashi0112/spreadsheet-grid-solid`, from 1.4.0) always share one version. Since 1.0, breaking changes ship only in major releases and are listed in the [changelog](https://github.com/ishibashi0112/datasheet-grid/blob/main/CHANGELOG.md) (before 1.0 they shipped in minor releases, under 「挙動の変化」 / 「core の破壊的変更」). The public surface is the entry points above (`.` / `/lite` / `/ai` / `/locales/en` / `/testing`), the CSS files, `API_REFERENCE.md`, and the CSS tokens, classes and attributes listed there. TypeScript 5.8 or later is supported (`moduleResolution` `bundler` or `nodenext`). Anything to be removed is deprecated in a minor release first, with a one-time console warning in development builds. The core's building blocks (`@ishibashi0112/spreadsheet-grid-core/internal/…`; the old subpaths without `internal/` were removed in 0.61.0) are internal and may change in any release (this package depends on the core of exactly the same version). Details: [Versioning](https://datasheet-grid.vercel.app/en/docs/versioning).
|
|
111
113
|
|
|
112
114
|
## License
|
|
113
115
|
|
|
@@ -133,7 +135,7 @@ Astryx / Mantine / HeroUI v3 / shadcn/ui の中で使うときは、`style.css`
|
|
|
133
135
|
|
|
134
136
|
### バンドルを小さくする: `/lite`(0.54.0 から)
|
|
135
137
|
|
|
136
|
-
`SpreadsheetGrid` は全機能入りです(初期読み込みの JS が約
|
|
138
|
+
`SpreadsheetGrid` は全機能入りです(初期読み込みの JS が約 236KB gzip)。`/lite` の入口では、渡した機能だけを入れたグリッドを作れます。渡さなかった機能はバンドルに入りません(機能なしで約 119KB、プリセット `standardFeatures` で約 145KB)。
|
|
137
139
|
|
|
138
140
|
```tsx
|
|
139
141
|
import { createSpreadsheetGrid, standardFeatures, serverSideFeature } from '@ishibashi0112/spreadsheet-grid/lite'
|
|
@@ -182,7 +184,7 @@ npm パッケージに同梱されているため、オフライン(`node_module
|
|
|
182
184
|
- **`rows` か `dataSource`。** `rows` はクライアントサイド行モデル、`dataSource` を渡すとサーバーサイド行モデルです。両者は排他です。
|
|
183
185
|
- **高さ。** ルートの `style.height` ではなく `height` prop で指定します。`%` を含む値(`'100%'`)は**バーを含むグリッド全体**の高さで、親要素に確定高さが必要です。数値は**スクロール領域だけ**の高さです。`height` 未指定時のスクロール領域は `480px`(`maxHeight`)が上限です。
|
|
184
186
|
- **命令的 API。** `ref` を渡すと `SpreadsheetGridHandle<T>` を受け取れます(利用側で `forwardRef` は不要。React 18.3 / 19 のどちらでも同じ)。グリッドを自分のコンポーネントで包んでその部品へ `ref` を渡すときは、React 18 では包む部品を `forwardRef` にします(型はどちらでも通りますが、React 18 は `ref` を props として渡さないので、ハンドルが `null` のままになります)。
|
|
185
|
-
- **位置は表示の位置。** `selectCell` などの `viewRowIndex` / `colIndex` は並べ替え・絞り込みの後の表示の位置で、`colIndex` は行ドラッグのハンドル列・展開トグル列・自動グループ列(ライブラリが足す列)も数えます。`rows.findIndex` ではなく `getViewRowIndex(rowKey)` / `getColIndex(columnKey)`
|
|
187
|
+
- **位置は表示の位置。** `selectCell` などの `viewRowIndex` / `colIndex` は並べ替え・絞り込みの後の表示の位置で、`colIndex` は行ドラッグのハンドル列・展開トグル列・自動グループ列(ライブラリが足す列)も数えます。`rows.findIndex` ではなく `getViewRowIndex(rowKey)` / `getColIndex(columnKey)` で引いてください。ページ送り(`pagination`)の表でも行の位置は全ページの通し番号です(今のページの中の番号ではありません)。
|
|
186
188
|
- **Next.js App Router。** クライアントコンポーネント(`'use client'` のファイル)から描画してください。パッケージ側はディレクティブを付けていません。
|
|
187
189
|
- **UI の言語。** グリッドが出す文言の既定は日本語です。英語は `@ishibashi0112/spreadsheet-grid/locales/en` の `localeTextEn` を `localeText` に渡します(`GridAskBar` には `gridAskLocaleTextEn`)。
|
|
188
190
|
|
package/dist/GridShell.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { SpreadsheetGridProps } from './model/gridTypes.js';
|
|
2
2
|
import type { GridShellFeatures } from './features/types.js';
|
|
3
|
-
export declare function useGridShell<T extends object>({ rows: rowsProp, dataSource, serverSideRefreshToken, serverSideRefetch, onServerSideLoadError, onServerSideWriteError, columns: columnsProp, onRowsChange, onColumnsChange, rowKeyGetter, isRowExportable, createRow, createOverflowColumn, onPasteSkipped, pasteFillsSelection, copyFormat, copyHeaders, excelShortcuts, newRow, rowHeight: rowHeightProp, autoHeight, estimateRowHeight, verticalAlign, headerHeight: headerHeightProp, density, theme, motion, popupContainer, animateRows, showCopyRange, hoverHighlight, highlightChanges, showSaveStatus, rowDragMotion, columnDragMotion, find, onFindChange, rowHeaderWidth, height, maxHeight, readOnly, dimReadOnlyCells, canEditCell: canEditCellProp, enableUndoRedo, enableClearOnDelete, editorEnterMove, imeDirectInput, undoHistoryLimit, onUndoRedoStateChange, trackChanges, rangeDecorations, onChangesChange, enableRangeSelection, enableRowSelection, rowSelectionMode, enableSelectAllRows: enableSelectAllRowsProp, rowSelection: rowSelectionProp, selectedRowKeys: selectedRowKeysProp, onRowSelectionChange, enableGlobalFilter, globalFilterMatch, enableColumnFilter, renderFilterDateInput, getFilterOptions, enableSorting, manualFiltering, manualSorting, enableColumnResize, autoSizeColumns, showCellOverflowTooltip, showValidationMarks, enableRowHover, enableColumnHeaderHover, hoveredRowIndex: hoveredRowIndexProp, onHoveredRowChange, onCellClick, onCellDoubleClick, onActiveCellChange, enableColumnMenu, noMatchingRowsText, noRowsText, ariaLabel, showTopBar, showBottomBar, showTopBarSummary, showTopBarFilter, globalFilterPlaceholder, globalFilterIcon, localeText, showTopBarCounts, showBottomBarCounts, showSelectionAggregates, showFilterChipBar, renderTopBar, renderBottomBar, className, style, classNames, getRowClassName, detailRow, onExpandedDetailRowKeysChange, labelRow, totalRow, pinnedTopRows, pinnedBottomRows, pinnedBottomRowsPlacement, columnGroups: columnGroupsProp, columnGroupHeaderHeight: columnGroupHeaderHeightProp, onColumnGroupOpenChange, treeData, onTreeRowOpenChange, fillHandle, enableRowDrag, isRowDraggable, onRowMove, canDropRow, enableContextMenu, getContextMenuItems, onContextMenuOpen, scrollHint, ref, onStateChange, initialState, includeGroupingInState, activeCellFollows, onFiltersChange, onSortChange, onScroll, }: SpreadsheetGridProps<T>, features: GridShellFeatures): import("react").JSX.Element;
|
|
3
|
+
export declare function useGridShell<T extends object>({ rows: rowsProp, dataSource, serverSideRefreshToken, serverSideRefetch, loading, pagination, onPageChange, onServerSideLoadError, onServerSideWriteError, columns: columnsProp, onRowsChange, onColumnsChange, rowKeyGetter, isRowExportable, createRow, createOverflowColumn, onPasteSkipped, pasteFillsSelection, copyFormat, copyHeaders, excelShortcuts, newRow, rowHeight: rowHeightProp, autoHeight, estimateRowHeight, verticalAlign, headerHeight: headerHeightProp, density, theme, motion, popupContainer, animateRows, showCopyRange, hoverHighlight, highlightChanges, showSaveStatus, rowDragMotion, columnDragMotion, find, onFindChange, rowHeaderWidth, height, maxHeight, readOnly, dimReadOnlyCells, canEditCell: canEditCellProp, enableUndoRedo, enableClearOnDelete, editorEnterMove, imeDirectInput, undoHistoryLimit, onUndoRedoStateChange, trackChanges, rangeDecorations, onChangesChange, enableRangeSelection, enableRowSelection, rowSelectionMode, enableSelectAllRows: enableSelectAllRowsProp, rowSelection: rowSelectionProp, selectedRowKeys: selectedRowKeysProp, onRowSelectionChange, enableGlobalFilter, globalFilterMatch, enableColumnFilter, renderFilterDateInput, getFilterOptions, enableSorting, manualFiltering, manualSorting, enableColumnResize, autoSizeColumns, showCellOverflowTooltip, showValidationMarks, enableRowHover, enableColumnHeaderHover, hoveredRowIndex: hoveredRowIndexProp, onHoveredRowChange, onCellClick, onCellDoubleClick, onActiveCellChange, enableColumnMenu, noMatchingRowsText, noRowsText, ariaLabel, showTopBar, showBottomBar, showTopBarSummary, showTopBarFilter, globalFilterPlaceholder, globalFilterIcon, localeText, showTopBarCounts, showBottomBarCounts, showSelectionAggregates, showFilterChipBar, renderTopBar, renderBottomBar, className, style, classNames, getRowClassName, detailRow, onExpandedDetailRowKeysChange, labelRow, totalRow, pinnedTopRows, pinnedBottomRows, pinnedBottomRowsPlacement, columnGroups: columnGroupsProp, columnGroupHeaderHeight: columnGroupHeaderHeightProp, onColumnGroupOpenChange, treeData, onTreeRowOpenChange, fillHandle, enableRowDrag, isRowDraggable, onRowMove, canDropRow, enableContextMenu, getContextMenuItems, onContextMenuOpen, scrollHint, ref, onStateChange, initialState, includeGroupingInState, activeCellFollows, onFiltersChange, onSortChange, onScroll, }: SpreadsheetGridProps<T>, features: GridShellFeatures): import("react").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type GridAgentTools, type GridAgentToolsOptions } from '@ishibashi0112/spreadsheet-grid-core/internal/logic/gridAgentTools';
|
|
2
|
+
/** `useGridAgentTools` のオプション(`createGridAgentTools` と同じ。`grid` は `useRef` の ref をそのまま渡せる)。 */
|
|
3
|
+
export type UseGridAgentToolsOptions<T> = GridAgentToolsOptions<T>;
|
|
4
|
+
/**
|
|
5
|
+
* AI エージェントがグリッドを操作する道具を作ります(React 版。1.14.0 から)。返す値は `createGridAgentTools` と同じ
|
|
6
|
+
* `{ tools, definitions, execute }` で、列定義と設定が変わったときだけ新しくなります。
|
|
7
|
+
*/
|
|
8
|
+
export declare const useGridAgentTools: <T>(options: UseGridAgentToolsOptions<T>) => GridAgentTools;
|
package/dist/ai.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime"),n=require("@ishibashi0112/spreadsheet-grid-core/internal/controllers/systemColorSchemeStore"),r=require("@ishibashi0112/spreadsheet-grid-core/internal/logic/theme"),i=require("@ishibashi0112/spreadsheet-grid-core/internal/logic/gridAskLocaleText"),a=require("@ishibashi0112/spreadsheet-grid-core/internal/logic/localeTextFilters"),o=require("@ishibashi0112/spreadsheet-grid-core/internal/logic/gridAsk");var s=1e3,c=400,l=(e,t,n)=>n?(0,o.isSameGridAskView)(e,t):(0,o.isSameGridAskView)({...e,columns:void 0},{...t,columns:void 0}),u=e=>({columns:e.columns,columnHints:e.columnHints,allowFilter:e.allowFilter,allowSort:e.allowSort,allowSearch:e.allowSearch,allowColumnVisibility:e.allowColumnVisibility,localeText:e.localeText}),d=(e,t)=>(0,o.isGridAskColumnsChanged)(e,t)?t:{...t,columns:void 0},f=(e,t,n)=>{if(!n)return{...e,filters:t.filters,sort:t.sort};let r=new Set((t.columns??[]).filter(e=>e.visible===!1).map(e=>e.key));return{...e,filters:t.filters,sort:t.sort,columns:e.columns?.map(e=>{if(r.has(e.key))return{...e,visible:!1};let t={...e};return delete t.visible,t})}};function p(t){let[n,r]=(0,e.useState)(`idle`),[a,p]=(0,e.useState)(null),[m,h]=(0,e.useState)(null),[g,_]=(0,e.useState)(null),v=(0,e.useRef)(null),y=(0,e.useRef)(t);(0,e.useEffect)(()=>{y.current=t}),(0,e.useEffect)(()=>()=>{let e=v.current;e!==null&&(v.current=null,e.abort(),r(`idle`))},[]);let b=u(t),x=(0,i.resolveGridAskLocaleText)(t.localeText),S=e=>(0,o.describeGridAskView)(e,b),C=t.allowColumnVisibility??!1,w=process.env.NODE_ENV===`production`||!t.columnHints?``:Object.keys(t.columnHints).filter(e=>!t.columns.some(t=>t.key===e)).join(`, `),T=(0,e.useRef)(``);(0,e.useEffect)(()=>{w!==``&&w!==T.current&&(T.current=w,console.warn(`[spreadsheet-grid] GridAskBar / useGridAsk の columnHints に列に無いキーがあります: ${w}。列の key と同じ名前にしてください(この補足や \`false\` は効いていません)。\n[spreadsheet-grid] columnHints of GridAskBar / useGridAsk has keys that are not columns: ${w}. Use the column keys (these hints and \`false\` have no effect).`))},[w]);let E=g!==null&&g.view.phase===`applied`?g:null;(0,e.useEffect)(()=>{if(E===null)return;let e=null,t=()=>{if(v.current!==null)return;let e=y.current.grid.current;e===null||l(e.getState(),E.applied,C)||(_(e=>e===E?{...e,view:{...e.view,phase:`changed`}}:e),h((0,i.resolveGridAskLocaleText)(y.current.localeText).changedNotice))},n=()=>{e===null&&(e=setTimeout(()=>{e=null,t()},c))},r=setInterval(t,s);return document.addEventListener(`click`,n,!0),document.addEventListener(`keyup`,n,!0),()=>{clearInterval(r),e!==null&&clearTimeout(e),document.removeEventListener(`click`,n,!0),document.removeEventListener(`keyup`,n,!0)}},[E,C]);let D=async e=>{let n=e.trim();if(n===``||v.current!==null)return!1;let i=t.grid.current;if(i===null)return p(x.noGrid),!1;let a=new AbortController;v.current=a,r(`asking`),p(null),h(null);let s;try{s=await t.ask((0,o.createGridAskRequest)(n,i.getState(),b),{signal:a.signal})}catch(e){return a.signal.aborted?!1:(v.current=null,r(`idle`),y.current.onError?.(e),p(x.askFailed),!1)}if(a.signal.aborted)return!1;v.current=null,r(`idle`);let c=y.current,l=u(c),f=c.grid.current;if(f===null)return p(x.noGrid),!1;let m=f.getState(),g=(0,o.readGridAskAnswer)(s,m,l);if(!g.ok)return p(g.message),!1;let S={text:n,dropped:g.dropped,unsupported:g.unsupported};return h(null),g.changed?(f.applyState(d(m,g.state)),_({view:{...S,phase:`applied`,items:(0,o.describeGridAskView)(g.state,l)},before:m,applied:g.state}),c.onApply?.({text:n,state:g.state,dropped:g.dropped,unsupported:g.unsupported}),!0):(_({view:{...S,phase:`unchanged`,items:(0,o.describeGridAskView)(m,l)},before:m,applied:m}),!0)},O=()=>{let e=v.current;e!==null&&(v.current=null,e.abort(),r(`idle`))},k=e=>{let n=t.grid.current;if(n===null||e.view.phase!==`applied`)return null;let r=n.getState();return l(r,e.applied,C)?{target:n,now:r}:(h(x.changedNotice),_({...e,view:{...e.view,phase:`changed`}}),null)};return{status:n,error:a,notice:m,session:g?.view??null,submit:D,cancel:O,undo:()=>{if(g===null)return;let e=k(g);if(e===null)return;let t=f(e.now,g.before,C);e.target.applyState(d(e.now,t)),h(null),_({...g,view:{...g.view,phase:`undone`}})},remove:e=>{if(g===null)return;let t=k(g);if(t===null)return;let n=(0,o.removeGridAskItem)(t.now,e);t.target.applyState(d(t.now,n)),_({...g,applied:n,view:{...g.view,items:S(n)}})},dismiss:()=>{_(null),h(null),p(null)}}}var m=(...e)=>e.filter(Boolean).join(` `);function h({examples:o,placeholder:s,label:c,className:l,theme:u=`light`,...d}){let f=p(d),h=(0,i.resolveGridAskLocaleText)(d.localeText),[g,_]=(0,e.useState)(``),v=(0,r.resolveGridThemeClassName)(u,(0,e.useSyncExternalStore)(n.systemColorSchemeStore.subscribe,n.systemColorSchemeStore.getSnapshot,n.systemColorSchemeStore.getServerSnapshot)),y=f.status===`asking`,b=f.session,x=f.cancel,[S,C]=(0,e.useState)(``),w=(0,e.useRef)(null),T=(0,e.useRef)(null),E=(0,e.useRef)(null),D=(0,e.useRef)(null);(0,e.useEffect)(()=>{let e=D.current;if(D.current=null,e===null||performance.now()-e.at>1e3)return;let t=document.activeElement;if(t!==null&&t!==document.body)return;let n=E.current?.querySelectorAll(`.ssg-ask-chip-remove`);(e.chip!==null&&n&&n.length>0?n[Math.min(e.chip,n.length-1)]:T.current)?.focus()}),(0,e.useEffect)(()=>{if(!y)return;let e=w.current,t=e?.ownerDocument??document,n=n=>{if(n.key!==`Escape`||n.defaultPrevented||n.isComposing||n.keyCode===229)return;let r=e!==null&&n.composedPath().includes(e),i=t.activeElement;!r&&i!==null&&i!==t.body||(n.preventDefault(),x())};return t.addEventListener(`keydown`,n),()=>t.removeEventListener(`keydown`,n)},[y,x]);let O=(e=null)=>{D.current={chip:e,at:performance.now()}},k=e=>{if(y||e.trim()===``)return;let t=e.trim();C(t),f.submit(e).then(e=>{e&&_(e=>e.trim()===t?``:e)})};return(0,t.jsxs)(`div`,{ref:w,className:m(`ssg-ask`,v,l),"data-ssg-ask":``,children:[(0,t.jsxs)(`form`,{className:`ssg-ask-form`,onSubmit:e=>{e.preventDefault(),k(g)},children:[(0,t.jsx)(`svg`,{className:`ssg-ask-icon`,viewBox:`0 0 16 16`,width:`16`,height:`16`,"aria-hidden":`true`,children:(0,t.jsx)(`path`,{d:`M6 1.5l1.1 3.4L10.5 6 7.1 7.1 6 10.5 4.9 7.1 1.5 6l3.4-1.1L6 1.5zm6 7l.6 1.9 1.9.6-1.9.6-.6 1.9-.6-1.9-1.9-.6 1.9-.6.6-1.9z`,fill:`currentColor`})}),(0,t.jsx)(`input`,{ref:T,className:`ssg-ask-input`,type:`text`,value:g,placeholder:s??h.placeholder,"aria-label":c??h.label,enterKeyHint:`send`,onChange:e=>_(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.nativeEvent.isComposing||e.keyCode===229)&&e.preventDefault()}}),y?(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-button`,onClick:e=>{e.preventDefault(),!(e.detail>1)&&x()},children:h.stop}):(0,t.jsx)(`button`,{type:`submit`,className:`ssg-ask-button ssg-ask-button--primary`,disabled:g.trim()===``,onClick:e=>{e.detail>1&&e.preventDefault()},children:h.submit})]}),o&&o.length>0&&(0,t.jsxs)(`div`,{className:`ssg-ask-examples`,children:[(0,t.jsx)(`span`,{className:`ssg-ask-examples-label`,children:h.examples}),o.map((e,n)=>(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-example`,"aria-disabled":y||void 0,title:e,onClick:()=>{y||(_(e),k(e))},children:e},n))]}),(0,t.jsxs)(`div`,{className:`ssg-ask-output`,"aria-live":`polite`,children:[y&&(0,t.jsxs)(`div`,{className:`ssg-ask-status`,children:[(0,t.jsx)(`span`,{className:`ssg-ask-spinner`,"aria-hidden":`true`}),h.thinking,(0,t.jsx)(`span`,{className:`ssg-ask-hint`,children:h.escHint})]}),!y&&f.error!==null&&(0,t.jsxs)(`div`,{className:`ssg-ask-note ssg-ask-note--error`,children:[(0,t.jsx)(`span`,{children:f.error}),S!==``&&(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-link`,onClick:()=>{O(),k(S)},children:h.retry})]}),!y&&b!==null&&(0,t.jsxs)(t.Fragment,{children:[b.phase===`applied`&&(0,t.jsxs)(`div`,{className:`ssg-ask-result`,children:[(0,t.jsxs)(`div`,{className:`ssg-ask-result-head`,children:[(0,t.jsx)(`span`,{className:`ssg-ask-result-title`,children:h.appliedTitle}),(0,t.jsxs)(`span`,{className:`ssg-ask-result-actions`,children:[(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-link`,onClick:()=>{O(),f.undo()},children:h.undo}),(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-link`,onClick:()=>{O(),f.dismiss()},children:h.close})]})]}),b.items.length>0?(0,t.jsx)(`ul`,{ref:E,className:`ssg-ask-chips`,children:b.items.map((e,n)=>(0,t.jsxs)(`li`,{className:`ssg-ask-chip`,title:`${e.label}: ${e.text}`,children:[(0,t.jsx)(`span`,{className:`ssg-ask-chip-label`,children:e.label}),(0,t.jsx)(`span`,{className:`ssg-ask-chip-text`,children:e.text}),(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-chip-remove`,"aria-label":(0,a.formatLocaleText)(h.removeItem,{label:e.label,text:e.text}),onClick:()=>{O(n),f.remove(e.id)},children:`×`})]},e.id))}):(0,t.jsx)(`div`,{className:`ssg-ask-empty`,children:h.allRemoved})]}),b.phase===`unchanged`&&(0,t.jsxs)(`div`,{className:`ssg-ask-note`,children:[(0,t.jsx)(`span`,{children:h.unchanged}),(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-link`,onClick:()=>{O(),f.dismiss()},children:h.close})]}),b.phase===`undone`&&(0,t.jsxs)(`div`,{className:`ssg-ask-note`,children:[(0,t.jsx)(`span`,{children:h.undone}),(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-link`,onClick:()=>{O(),f.dismiss()},children:h.close})]}),b.phase!==`undone`&&b.phase!==`changed`&&b.dropped.length>0&&(0,t.jsxs)(`div`,{className:`ssg-ask-note ssg-ask-note--warn`,children:[(0,t.jsx)(`span`,{className:`ssg-ask-note-title`,children:h.droppedTitle}),(0,t.jsx)(`ul`,{className:`ssg-ask-dropped`,children:b.dropped.map((e,n)=>(0,t.jsx)(`li`,{children:e},n))})]}),b.phase!==`undone`&&b.phase!==`changed`&&b.unsupported!==null&&(0,t.jsx)(`div`,{className:`ssg-ask-note`,children:(0,t.jsx)(`span`,{children:(0,a.formatLocaleText)(h.fromAi,{text:b.unsupported})})})]}),f.notice!==null&&(0,t.jsxs)(`div`,{className:`ssg-ask-note ssg-ask-note--warn`,children:[(0,t.jsx)(`span`,{children:f.notice}),b?.phase===`changed`&&(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-link`,onClick:()=>{O(),f.dismiss()},children:h.close})]})]})]})}exports.GridAskBar=h,Object.defineProperty(exports,"createGridAskRequest",{enumerable:!0,get:function(){return o.createGridAskRequest}}),Object.defineProperty(exports,"describeGridAskView",{enumerable:!0,get:function(){return o.describeGridAskView}}),Object.defineProperty(exports,"gridAskSystemPrompt",{enumerable:!0,get:function(){return o.gridAskSystemPrompt}}),Object.defineProperty(exports,"isGridAskColumnsChanged",{enumerable:!0,get:function(){return o.isGridAskColumnsChanged}}),Object.defineProperty(exports,"isSameGridAskView",{enumerable:!0,get:function(){return o.isSameGridAskView}}),Object.defineProperty(exports,"readGridAskAnswer",{enumerable:!0,get:function(){return o.readGridAskAnswer}}),Object.defineProperty(exports,"removeGridAskItem",{enumerable:!0,get:function(){return o.removeGridAskItem}}),exports.useGridAsk=p;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime"),n=require("@ishibashi0112/spreadsheet-grid-core/internal/controllers/systemColorSchemeStore"),r=require("@ishibashi0112/spreadsheet-grid-core/internal/logic/theme"),i=require("@ishibashi0112/spreadsheet-grid-core/internal/logic/gridAskLocaleText"),a=require("@ishibashi0112/spreadsheet-grid-core/internal/logic/localeTextFilters"),o=require("@ishibashi0112/spreadsheet-grid-core/internal/logic/gridAsk"),s=require("@ishibashi0112/spreadsheet-grid-core/internal/logic/gridAgentTools");var c=1e3,l=400,u=(e,t,n)=>n?(0,o.isSameGridAskView)(e,t):(0,o.isSameGridAskView)({...e,columns:void 0},{...t,columns:void 0}),d=e=>({columns:e.columns,columnHints:e.columnHints,allowFilter:e.allowFilter,allowSort:e.allowSort,allowSearch:e.allowSearch,allowColumnVisibility:e.allowColumnVisibility,localeText:e.localeText}),f=(e,t)=>(0,o.isGridAskColumnsChanged)(e,t)?t:{...t,columns:void 0},p=(e,t,n)=>{if(!n)return{...e,filters:t.filters,sort:t.sort};let r=new Set((t.columns??[]).filter(e=>e.visible===!1).map(e=>e.key));return{...e,filters:t.filters,sort:t.sort,columns:e.columns?.map(e=>{if(r.has(e.key))return{...e,visible:!1};let t={...e};return delete t.visible,t})}};function m(t){let[n,r]=(0,e.useState)(`idle`),[a,s]=(0,e.useState)(null),[m,h]=(0,e.useState)(null),[g,_]=(0,e.useState)(null),v=(0,e.useRef)(null),y=(0,e.useRef)(t);(0,e.useEffect)(()=>{y.current=t}),(0,e.useEffect)(()=>()=>{let e=v.current;e!==null&&(v.current=null,e.abort(),r(`idle`))},[]);let b=d(t),x=(0,i.resolveGridAskLocaleText)(t.localeText),S=e=>(0,o.describeGridAskView)(e,b),C=t.allowColumnVisibility??!1,w=process.env.NODE_ENV===`production`||!t.columnHints?``:Object.keys(t.columnHints).filter(e=>!t.columns.some(t=>t.key===e)).join(`, `),T=(0,e.useRef)(``);(0,e.useEffect)(()=>{w!==``&&w!==T.current&&(T.current=w,console.warn(`[spreadsheet-grid] GridAskBar / useGridAsk の columnHints に列に無いキーがあります: ${w}。列の key と同じ名前にしてください(この補足や \`false\` は効いていません)。\n[spreadsheet-grid] columnHints of GridAskBar / useGridAsk has keys that are not columns: ${w}. Use the column keys (these hints and \`false\` have no effect).`))},[w]);let E=g!==null&&g.view.phase===`applied`?g:null;(0,e.useEffect)(()=>{if(E===null)return;let e=null,t=()=>{if(v.current!==null)return;let e=y.current.grid.current;e===null||u(e.getState(),E.applied,C)||(_(e=>e===E?{...e,view:{...e.view,phase:`changed`}}:e),h((0,i.resolveGridAskLocaleText)(y.current.localeText).changedNotice))},n=()=>{e===null&&(e=setTimeout(()=>{e=null,t()},l))},r=setInterval(t,c);return document.addEventListener(`click`,n,!0),document.addEventListener(`keyup`,n,!0),()=>{clearInterval(r),e!==null&&clearTimeout(e),document.removeEventListener(`click`,n,!0),document.removeEventListener(`keyup`,n,!0)}},[E,C]);let D=async e=>{let n=e.trim();if(n===``||v.current!==null)return!1;let i=t.grid.current;if(i===null)return s(x.noGrid),!1;let a=new AbortController;v.current=a,r(`asking`),s(null),h(null);let c;try{c=await t.ask((0,o.createGridAskRequest)(n,i.getState(),b),{signal:a.signal})}catch(e){return a.signal.aborted?!1:(v.current=null,r(`idle`),y.current.onError?.(e),s(x.askFailed),!1)}if(a.signal.aborted)return!1;v.current=null,r(`idle`);let l=y.current,u=d(l),p=l.grid.current;if(p===null)return s(x.noGrid),!1;let m=p.getState(),g=(0,o.readGridAskAnswer)(c,m,u);if(!g.ok)return s(g.message),!1;let S={text:n,dropped:g.dropped,unsupported:g.unsupported};return h(null),g.changed?(p.applyState(f(m,g.state)),_({view:{...S,phase:`applied`,items:(0,o.describeGridAskView)(g.state,u)},before:m,applied:g.state}),l.onApply?.({text:n,state:g.state,dropped:g.dropped,unsupported:g.unsupported}),!0):(_({view:{...S,phase:`unchanged`,items:(0,o.describeGridAskView)(m,u)},before:m,applied:m}),!0)},O=()=>{let e=v.current;e!==null&&(v.current=null,e.abort(),r(`idle`))},k=e=>{let n=t.grid.current;if(n===null||e.view.phase!==`applied`)return null;let r=n.getState();return u(r,e.applied,C)?{target:n,now:r}:(h(x.changedNotice),_({...e,view:{...e.view,phase:`changed`}}),null)};return{status:n,error:a,notice:m,session:g?.view??null,submit:D,cancel:O,undo:()=>{if(g===null)return;let e=k(g);if(e===null)return;let t=p(e.now,g.before,C);e.target.applyState(f(e.now,t)),h(null),_({...g,view:{...g.view,phase:`undone`}})},remove:e=>{if(g===null)return;let t=k(g);if(t===null)return;let n=(0,o.removeGridAskItem)(t.now,e);t.target.applyState(f(t.now,n)),_({...g,applied:n,view:{...g.view,items:S(n)}})},dismiss:()=>{_(null),h(null),s(null)}}}var h=(...e)=>e.filter(Boolean).join(` `);function g({examples:o,placeholder:s,label:c,className:l,theme:u=`light`,...d}){let f=m(d),p=(0,i.resolveGridAskLocaleText)(d.localeText),[g,_]=(0,e.useState)(``),v=(0,r.resolveGridThemeClassName)(u,(0,e.useSyncExternalStore)(n.systemColorSchemeStore.subscribe,n.systemColorSchemeStore.getSnapshot,n.systemColorSchemeStore.getServerSnapshot)),y=f.status===`asking`,b=f.session,x=f.cancel,[S,C]=(0,e.useState)(``),w=(0,e.useRef)(null),T=(0,e.useRef)(null),E=(0,e.useRef)(null),D=(0,e.useRef)(null);(0,e.useEffect)(()=>{let e=D.current;if(D.current=null,e===null||performance.now()-e.at>1e3)return;let t=document.activeElement;if(t!==null&&t!==document.body)return;let n=E.current?.querySelectorAll(`.ssg-ask-chip-remove`);(e.chip!==null&&n&&n.length>0?n[Math.min(e.chip,n.length-1)]:T.current)?.focus()}),(0,e.useEffect)(()=>{if(!y)return;let e=w.current,t=e?.ownerDocument??document,n=n=>{if(n.key!==`Escape`||n.defaultPrevented||n.isComposing||n.keyCode===229)return;let r=e!==null&&n.composedPath().includes(e),i=t.activeElement;!r&&i!==null&&i!==t.body||(n.preventDefault(),x())};return t.addEventListener(`keydown`,n),()=>t.removeEventListener(`keydown`,n)},[y,x]);let O=(e=null)=>{D.current={chip:e,at:performance.now()}},k=e=>{if(y||e.trim()===``)return;let t=e.trim();C(t),f.submit(e).then(e=>{e&&_(e=>e.trim()===t?``:e)})};return(0,t.jsxs)(`div`,{ref:w,className:h(`ssg-ask`,v,l),"data-ssg-ask":``,children:[(0,t.jsxs)(`form`,{className:`ssg-ask-form`,onSubmit:e=>{e.preventDefault(),k(g)},children:[(0,t.jsx)(`svg`,{className:`ssg-ask-icon`,viewBox:`0 0 16 16`,width:`16`,height:`16`,"aria-hidden":`true`,children:(0,t.jsx)(`path`,{d:`M6 1.5l1.1 3.4L10.5 6 7.1 7.1 6 10.5 4.9 7.1 1.5 6l3.4-1.1L6 1.5zm6 7l.6 1.9 1.9.6-1.9.6-.6 1.9-.6-1.9-1.9-.6 1.9-.6.6-1.9z`,fill:`currentColor`})}),(0,t.jsx)(`input`,{ref:T,className:`ssg-ask-input`,type:`text`,value:g,placeholder:s??p.placeholder,"aria-label":c??p.label,enterKeyHint:`send`,onChange:e=>_(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.nativeEvent.isComposing||e.keyCode===229)&&e.preventDefault()}}),y?(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-button`,onClick:e=>{e.preventDefault(),!(e.detail>1)&&x()},children:p.stop}):(0,t.jsx)(`button`,{type:`submit`,className:`ssg-ask-button ssg-ask-button--primary`,disabled:g.trim()===``,onClick:e=>{e.detail>1&&e.preventDefault()},children:p.submit})]}),o&&o.length>0&&(0,t.jsxs)(`div`,{className:`ssg-ask-examples`,children:[(0,t.jsx)(`span`,{className:`ssg-ask-examples-label`,children:p.examples}),o.map((e,n)=>(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-example`,"aria-disabled":y||void 0,title:e,onClick:()=>{y||(_(e),k(e))},children:e},n))]}),(0,t.jsxs)(`div`,{className:`ssg-ask-output`,"aria-live":`polite`,children:[y&&(0,t.jsxs)(`div`,{className:`ssg-ask-status`,children:[(0,t.jsx)(`span`,{className:`ssg-ask-spinner`,"aria-hidden":`true`}),p.thinking,(0,t.jsx)(`span`,{className:`ssg-ask-hint`,children:p.escHint})]}),!y&&f.error!==null&&(0,t.jsxs)(`div`,{className:`ssg-ask-note ssg-ask-note--error`,children:[(0,t.jsx)(`span`,{children:f.error}),S!==``&&(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-link`,onClick:()=>{O(),k(S)},children:p.retry})]}),!y&&b!==null&&(0,t.jsxs)(t.Fragment,{children:[b.phase===`applied`&&(0,t.jsxs)(`div`,{className:`ssg-ask-result`,children:[(0,t.jsxs)(`div`,{className:`ssg-ask-result-head`,children:[(0,t.jsx)(`span`,{className:`ssg-ask-result-title`,children:p.appliedTitle}),(0,t.jsxs)(`span`,{className:`ssg-ask-result-actions`,children:[(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-link`,onClick:()=>{O(),f.undo()},children:p.undo}),(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-link`,onClick:()=>{O(),f.dismiss()},children:p.close})]})]}),b.items.length>0?(0,t.jsx)(`ul`,{ref:E,className:`ssg-ask-chips`,children:b.items.map((e,n)=>(0,t.jsxs)(`li`,{className:`ssg-ask-chip`,title:`${e.label}: ${e.text}`,children:[(0,t.jsx)(`span`,{className:`ssg-ask-chip-label`,children:e.label}),(0,t.jsx)(`span`,{className:`ssg-ask-chip-text`,children:e.text}),(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-chip-remove`,"aria-label":(0,a.formatLocaleText)(p.removeItem,{label:e.label,text:e.text}),onClick:()=>{O(n),f.remove(e.id)},children:`×`})]},e.id))}):(0,t.jsx)(`div`,{className:`ssg-ask-empty`,children:p.allRemoved})]}),b.phase===`unchanged`&&(0,t.jsxs)(`div`,{className:`ssg-ask-note`,children:[(0,t.jsx)(`span`,{children:p.unchanged}),(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-link`,onClick:()=>{O(),f.dismiss()},children:p.close})]}),b.phase===`undone`&&(0,t.jsxs)(`div`,{className:`ssg-ask-note`,children:[(0,t.jsx)(`span`,{children:p.undone}),(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-link`,onClick:()=>{O(),f.dismiss()},children:p.close})]}),b.phase!==`undone`&&b.phase!==`changed`&&b.dropped.length>0&&(0,t.jsxs)(`div`,{className:`ssg-ask-note ssg-ask-note--warn`,children:[(0,t.jsx)(`span`,{className:`ssg-ask-note-title`,children:p.droppedTitle}),(0,t.jsx)(`ul`,{className:`ssg-ask-dropped`,children:b.dropped.map((e,n)=>(0,t.jsx)(`li`,{children:e},n))})]}),b.phase!==`undone`&&b.phase!==`changed`&&b.unsupported!==null&&(0,t.jsx)(`div`,{className:`ssg-ask-note`,children:(0,t.jsx)(`span`,{children:(0,a.formatLocaleText)(p.fromAi,{text:b.unsupported})})})]}),f.notice!==null&&(0,t.jsxs)(`div`,{className:`ssg-ask-note ssg-ask-note--warn`,children:[(0,t.jsx)(`span`,{children:f.notice}),b?.phase===`changed`&&(0,t.jsx)(`button`,{type:`button`,className:`ssg-ask-link`,onClick:()=>{O(),f.dismiss()},children:p.close})]})]})]})}var _=e=>{let t=e;return{update:e=>{t=e},grid:()=>{let e=t.grid;return typeof e==`function`?e():e.current},confirm:e=>t.confirm?t.confirm(e):!0,onToolCall:e=>{t.onToolCall?.(e)},localeText:()=>t.localeText}},v=(e,t)=>e===void 0||typeof e==`boolean`?e:e[t]??!0,y=(e,t)=>typeof e==`number`?{[t]:e}:e,b=t=>{let[n]=(0,e.useState)(()=>_(t));(0,e.useEffect)(()=>{n.update(t)});let{columns:r,name:i,description:a,allowFilter:o,allowSort:c,allowSearch:l,allowColumnVisibility:u}=t,d=t.columnHints===void 0?void 0:JSON.stringify(t.columnHints),f=v(t.readRows,`maxRows`),p=v(t.readSelection,`maxCells`),m=v(t.editCells,`maxCells`),h=t.now?.getTime(),g=t.confirm!==void 0;return(0,e.useMemo)(()=>(0,s.createGridAgentTools)({grid:n.grid,columns:r,name:i,description:a,columnHints:d===void 0?void 0:JSON.parse(d),allowFilter:o,allowSort:c,allowSearch:l,allowColumnVisibility:u,get localeText(){return n.localeText()},now:h===void 0?void 0:new Date(h),readRows:y(f,`maxRows`),readSelection:y(p,`maxCells`),editCells:y(m,`maxCells`),confirm:g?n.confirm:void 0,onToolCall:n.onToolCall}),[n,r,i,a,d,o,c,l,u,h,f,p,m,g])};exports.GridAskBar=g,Object.defineProperty(exports,"createGridAgentTools",{enumerable:!0,get:function(){return s.createGridAgentTools}}),Object.defineProperty(exports,"createGridAskRequest",{enumerable:!0,get:function(){return o.createGridAskRequest}}),Object.defineProperty(exports,"describeGridAskView",{enumerable:!0,get:function(){return o.describeGridAskView}}),Object.defineProperty(exports,"gridAskSystemPrompt",{enumerable:!0,get:function(){return o.gridAskSystemPrompt}}),Object.defineProperty(exports,"isGridAskColumnsChanged",{enumerable:!0,get:function(){return o.isGridAskColumnsChanged}}),Object.defineProperty(exports,"isSameGridAskView",{enumerable:!0,get:function(){return o.isSameGridAskView}}),Object.defineProperty(exports,"readGridAskAnswer",{enumerable:!0,get:function(){return o.readGridAskAnswer}}),Object.defineProperty(exports,"registerGridAgentTools",{enumerable:!0,get:function(){return s.registerGridAgentTools}}),Object.defineProperty(exports,"removeGridAskItem",{enumerable:!0,get:function(){return o.removeGridAskItem}}),exports.useGridAgentTools=b,exports.useGridAsk=m;
|
package/dist/ai.d.ts
CHANGED
|
@@ -4,4 +4,8 @@ export { useGridAsk } from './ai/useGridAsk.js';
|
|
|
4
4
|
export type { GridAsk, GridAskApplyEvent, GridAskSession, GridAskTarget, UseGridAskOptions, UseGridAskResult, } from './ai/useGridAsk.js';
|
|
5
5
|
export { createGridAskRequest, describeGridAskView, gridAskSystemPrompt, isGridAskColumnsChanged, isSameGridAskView, readGridAskAnswer, removeGridAskItem, } from '@ishibashi0112/spreadsheet-grid-core/internal/logic/gridAsk';
|
|
6
6
|
export type { GridAskAnswer, GridAskFilter, GridAskItem, GridAskOp, GridAskOptions, GridAskRequest, GridAskResult, GridAskSort, } from '@ishibashi0112/spreadsheet-grid-core/internal/logic/gridAsk';
|
|
7
|
+
export { useGridAgentTools } from './ai/useGridAgentTools.js';
|
|
8
|
+
export type { UseGridAgentToolsOptions } from './ai/useGridAgentTools.js';
|
|
9
|
+
export { createGridAgentTools, registerGridAgentTools } from '@ishibashi0112/spreadsheet-grid-core/internal/logic/gridAgentTools';
|
|
10
|
+
export type { GridAgentConfirmRequest, GridAgentExecuteOptions, GridAgentTarget, GridAgentTool, GridAgentToolAnnotations, GridAgentToolCall, GridAgentToolDefinition, GridAgentToolOutput, GridAgentTools, GridAgentToolsOptions, } from '@ishibashi0112/spreadsheet-grid-core/internal/logic/gridAgentTools';
|
|
7
11
|
export type { GridAskLocaleText } from '@ishibashi0112/spreadsheet-grid-core/internal/logic/gridAskLocaleText';
|