@reactloom/data-grid 0.0.0-stage → 1.0.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.
- package/README.md +65 -2
- package/dist/LICENSE +21 -0
- package/dist/_internal/hooks/use-controllable-state.js +24 -0
- package/dist/_internal/hooks/use-controllable-state.js.map +1 -0
- package/dist/_internal/primitives/visually-hidden.js +29 -0
- package/dist/_internal/primitives/visually-hidden.js.map +1 -0
- package/dist/_internal/utils/cx.js +10 -0
- package/dist/_internal/utils/cx.js.map +1 -0
- package/dist/_internal/utils/data-attr.js +8 -0
- package/dist/_internal/utils/data-attr.js.map +1 -0
- package/dist/_internal/utils/warn.js +13 -0
- package/dist/_internal/utils/warn.js.map +1 -0
- package/dist/cell-editor.d.ts +26 -0
- package/dist/cell-editor.d.ts.map +1 -0
- package/dist/cell-editor.js +109 -0
- package/dist/cell-editor.js.map +1 -0
- package/dist/clipboard.d.ts +10 -0
- package/dist/clipboard.d.ts.map +1 -0
- package/dist/clipboard.js +54 -0
- package/dist/clipboard.js.map +1 -0
- package/dist/column-filters.d.ts +4 -0
- package/dist/column-filters.d.ts.map +1 -0
- package/dist/column-filters.js +30 -0
- package/dist/column-filters.js.map +1 -0
- package/dist/column-layout.d.ts +18 -0
- package/dist/column-layout.d.ts.map +1 -0
- package/dist/column-layout.js +59 -0
- package/dist/column-layout.js.map +1 -0
- package/dist/csv.d.ts +26 -0
- package/dist/csv.d.ts.map +1 -0
- package/dist/csv.js +60 -0
- package/dist/csv.js.map +1 -0
- package/dist/data-grid.d.ts +11 -0
- package/dist/data-grid.d.ts.map +1 -0
- package/dist/data-grid.js +1610 -0
- package/dist/data-grid.js.map +1 -0
- package/dist/data-grid.module.js +70 -0
- package/dist/data-grid.module.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/pivot-table.d.ts +26 -0
- package/dist/pivot-table.d.ts.map +1 -0
- package/dist/pivot-table.js +174 -0
- package/dist/pivot-table.js.map +1 -0
- package/dist/pivot-table.module.js +30 -0
- package/dist/pivot-table.module.js.map +1 -0
- package/dist/server.d.ts +34 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +97 -0
- package/dist/server.js.map +1 -0
- package/dist/spreadsheet.d.ts +18 -0
- package/dist/spreadsheet.d.ts.map +1 -0
- package/dist/spreadsheet.js +329 -0
- package/dist/spreadsheet.js.map +1 -0
- package/dist/spreadsheet.module.js +30 -0
- package/dist/spreadsheet.module.js.map +1 -0
- package/dist/styles.css +3 -0
- package/dist/tree.d.ts +24 -0
- package/dist/tree.d.ts.map +1 -0
- package/dist/tree.js +75 -0
- package/dist/tree.js.map +1 -0
- package/dist/types.d.ts +365 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +43 -0
- package/dist/types.js.map +1 -0
- package/dist/use-grid-navigation.d.ts +36 -0
- package/dist/use-grid-navigation.d.ts.map +1 -0
- package/dist/use-grid-navigation.js +188 -0
- package/dist/use-grid-navigation.js.map +1 -0
- package/dist/xlsx.d.ts +12 -0
- package/dist/xlsx.d.ts.map +1 -0
- package/dist/xlsx.js +57 -0
- package/dist/xlsx.js.map +1 -0
- package/dist/zip.d.ts +6 -0
- package/dist/zip.d.ts.map +1 -0
- package/dist/zip.js +54 -0
- package/dist/zip.js.map +1 -0
- package/package.json +108 -3
package/README.md
CHANGED
|
@@ -1,3 +1,66 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @reactloom/data-grid
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An accessible data grid for ReactLoom: `role="grid"` keyboard navigation, sorting, search,
|
|
4
|
+
pagination, row selection, cell editing, grouping with totals, CSV export, resizable and
|
|
5
|
+
hideable columns, and row virtualization.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @reactloom/data-grid @reactloom/ui @reactloom/theme
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import '@reactloom/data-grid/styles.css';
|
|
13
|
+
import { DataGrid } from '@reactloom/data-grid';
|
|
14
|
+
|
|
15
|
+
<DataGrid
|
|
16
|
+
aria-label="Invoices"
|
|
17
|
+
columns={[{ key: 'customer', header: 'Customer', sortable: true }, { key: 'amount', header: 'Amount', align: 'end' }]}
|
|
18
|
+
rows={invoices}
|
|
19
|
+
getRowId={(r) => r.id}
|
|
20
|
+
pageSize={25}
|
|
21
|
+
/>;
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- **Editing:** `editable`, `editor: 'text' | 'number' | 'select' | custom`, `validate`; Enter,
|
|
25
|
+
F2 or typing starts, Enter saves, Escape cancels. `onCellEdit` may return a promise.
|
|
26
|
+
- **Grouping:** `groupBy="status"` with `aggregate: 'sum' | 'avg' | 'min' | 'max' | 'count'`.
|
|
27
|
+
- **Multi-sort:** supply `defaultSorts` or controlled `sorts` and `onSortsChange`. Put the primary
|
|
28
|
+
sort first. Shift + click or Shift + Enter/Space updates a column without clearing the others.
|
|
29
|
+
- **Column filters:** pass `filters` or `defaultFilters` with typed text, number, date, boolean or
|
|
30
|
+
empty rules. Every rule must match. Date rules use epoch milliseconds against `Date` values.
|
|
31
|
+
Use `apiRef.current.setFilters([])` to clear an uncontrolled grid. Set `manualFiltering` and
|
|
32
|
+
`manualSorting` when your server owns the query, and pass the server’s total with manual pagination.
|
|
33
|
+
- **Export:** `apiRef.current.downloadCsv('orders.csv')` saves the filtered, sorted view;
|
|
34
|
+
`toCsv(columns, rows)` works anywhere. Formula-like text is neutralised (CSV injection).
|
|
35
|
+
|
|
36
|
+
Built on TanStack Table and TanStack Virtual; the public API is ReactLoom's own. For simple,
|
|
37
|
+
read-only data use `Table` from `@reactloom/ui` instead.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Column layouts and Excel export
|
|
41
|
+
|
|
42
|
+
Pass `columnLayout` or `defaultColumnLayout` with ordered keys and logical
|
|
43
|
+
`pinnedStart` / `pinnedEnd` groups. Enable `reorderableColumns` to move a header
|
|
44
|
+
within its group with Alt + Shift + an arrow key. Save a layout in your app
|
|
45
|
+
using `getColumnLayout()` and restore it with `setColumnLayout(layout)`.
|
|
46
|
+
|
|
47
|
+
For a full saved view, use `getView()` and `restoreView(view)` on the grid API.
|
|
48
|
+
The versioned snapshot includes the layout, widths, visibility, filters, search,
|
|
49
|
+
sorts, and grouping. Store it in your application and pass change handlers for
|
|
50
|
+
controlled settings you want to restore.
|
|
51
|
+
|
|
52
|
+
Load `toXlsx` or `downloadXlsx` from `@reactloom/data-grid/xlsx` when export is
|
|
53
|
+
requested. Pass `getExportColumns()` and `getRows(scope)` to export the visible
|
|
54
|
+
columns in display order. The single worksheet uses typed numbers and booleans,
|
|
55
|
+
ISO text for dates, and literal text for strings.
|
|
56
|
+
|
|
57
|
+
## Server data source
|
|
58
|
+
|
|
59
|
+
Import `useDataGridDataSource` from `@reactloom/data-grid/server`. It loads the active
|
|
60
|
+
offset and limit with your search, column filters, and sort priorities. Pass its
|
|
61
|
+
`rows`, `rowCount`, and `loading` to a grid using manual sorting, filtering, and
|
|
62
|
+
pagination. Keep the loader identity stable and forward its `signal` to fetch.
|
|
63
|
+
Use `refresh()` to clear cached ranges and reload the active page.
|
|
64
|
+
|
|
65
|
+
Documentation and live examples: <https://www.reactloom.dev/components/data-grid> ·
|
|
66
|
+
<https://www.reactloom.dev/components/pivot-table> · <https://www.reactloom.dev/components/spreadsheet>
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ReactLoom UI contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
|
+
// ../hooks/src/use-controllable-state.ts
|
|
3
|
+
/**
|
|
4
|
+
* State that can be controlled (`value` defined) or uncontrolled (`defaultValue`).
|
|
5
|
+
* `onChange` fires on every requested change in both modes; no-op changes are ignored.
|
|
6
|
+
*/
|
|
7
|
+
function useControllableState(params) {
|
|
8
|
+
const { value, defaultValue, onChange } = params;
|
|
9
|
+
const [internal, setInternal] = useState(defaultValue);
|
|
10
|
+
const controlled = value !== void 0;
|
|
11
|
+
const current = controlled ? value : internal;
|
|
12
|
+
return [current, useCallback((next) => {
|
|
13
|
+
if (Object.is(next, current)) return;
|
|
14
|
+
if (!controlled) setInternal(next);
|
|
15
|
+
onChange?.(next);
|
|
16
|
+
}, [
|
|
17
|
+
controlled,
|
|
18
|
+
current,
|
|
19
|
+
onChange
|
|
20
|
+
])];
|
|
21
|
+
}
|
|
22
|
+
export { useControllableState };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=use-controllable-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-controllable-state.js","names":[],"sources":["../../../../hooks/src/use-controllable-state.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\n\n/**\n * State that can be controlled (`value` defined) or uncontrolled (`defaultValue`).\n * `onChange` fires on every requested change in both modes; no-op changes are ignored.\n */\nexport function useControllableState<T>(params: {\n value: T | undefined;\n defaultValue: T;\n onChange?: ((value: T) => void) | undefined;\n}): [T, (next: T) => void] {\n const { value, defaultValue, onChange } = params;\n const [internal, setInternal] = useState(defaultValue);\n const controlled = value !== undefined;\n const current = controlled ? value : internal;\n\n const setValue = useCallback(\n (next: T) => {\n if (Object.is(next, current)) return;\n if (!controlled) setInternal(next);\n onChange?.(next);\n },\n [controlled, current, onChange],\n );\n\n return [current, setValue];\n}\n"],"mappings":";;;;;;AAMA,SAAgB,qBAAwB,QAIb;CACzB,MAAM,EAAE,OAAO,cAAc,aAAa;CAC1C,MAAM,CAAC,UAAU,eAAe,SAAS,YAAY;CACrD,MAAM,aAAa,UAAU,KAAA;CAC7B,MAAM,UAAU,aAAa,QAAQ;CAWrC,OAAO,CAAC,SATS,aACd,SAAY;EACX,IAAI,OAAO,GAAG,MAAM,OAAO,GAAG;EAC9B,IAAI,CAAC,YAAY,YAAY,IAAI;EACjC,WAAW,IAAI;CACjB,GACA;EAAC;EAAY;EAAS;CAAQ,CAGf,CAAQ;AAC3B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// ../primitives/src/visually-hidden.tsx
|
|
4
|
+
var hidden = {
|
|
5
|
+
position: "absolute",
|
|
6
|
+
width: 1,
|
|
7
|
+
height: 1,
|
|
8
|
+
padding: 0,
|
|
9
|
+
margin: -1,
|
|
10
|
+
overflow: "hidden",
|
|
11
|
+
clip: "rect(0 0 0 0)",
|
|
12
|
+
clipPath: "inset(50%)",
|
|
13
|
+
whiteSpace: "nowrap",
|
|
14
|
+
border: 0
|
|
15
|
+
};
|
|
16
|
+
/** Content available to assistive technology but not rendered visually. */
|
|
17
|
+
var VisuallyHidden = /*#__PURE__*/ forwardRef(function VisuallyHidden({ style, ...props }, ref) {
|
|
18
|
+
return /* @__PURE__ */ jsx("span", {
|
|
19
|
+
ref,
|
|
20
|
+
...props,
|
|
21
|
+
style: {
|
|
22
|
+
...hidden,
|
|
23
|
+
...style
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
export { VisuallyHidden };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=visually-hidden.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visually-hidden.js","names":[],"sources":["../../../../primitives/src/visually-hidden.tsx"],"sourcesContent":["import { forwardRef, type CSSProperties, type HTMLAttributes } from 'react';\n\nconst hidden: CSSProperties = {\n position: 'absolute',\n width: 1,\n height: 1,\n padding: 0,\n margin: -1,\n overflow: 'hidden',\n clip: 'rect(0 0 0 0)',\n clipPath: 'inset(50%)',\n whiteSpace: 'nowrap',\n border: 0,\n};\n\nexport type VisuallyHiddenProps = HTMLAttributes<HTMLSpanElement>;\n\n/** Content available to assistive technology but not rendered visually. */\nexport const VisuallyHidden = /*#__PURE__*/ forwardRef<HTMLSpanElement, VisuallyHiddenProps>(function VisuallyHidden(\n { style, ...props },\n ref,\n) {\n return <span ref={ref} {...props} style={{ ...hidden, ...style }} />;\n});\n"],"mappings":";;;AAEA,IAAM,SAAwB;CAC5B,UAAU;CACV,OAAO;CACP,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,UAAU;CACV,MAAM;CACN,UAAU;CACV,YAAY;CACZ,QAAQ;AACV;;AAKA,IAAa,iBAA+B,yBAAiD,SAAS,eACpG,EAAE,OAAO,GAAG,SACZ,KACA;CACA,OAAO,oBAAC,QAAD;EAAW;EAAK,GAAI;EAAO,OAAO;GAAE,GAAG;GAAQ,GAAG;EAAM;CAAI,CAAA;AACrE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// ../utils/src/cx.ts
|
|
2
|
+
/** Joins truthy class names with a single space. */
|
|
3
|
+
function cx(...values) {
|
|
4
|
+
let out = "";
|
|
5
|
+
for (const v of values) if (v) out = out ? `${out} ${v}` : v;
|
|
6
|
+
return out || void 0;
|
|
7
|
+
}
|
|
8
|
+
export { cx };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=cx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cx.js","names":[],"sources":["../../../../utils/src/cx.ts"],"sourcesContent":["type ClassValue = string | false | null | undefined;\n\n/** Joins truthy class names with a single space. */\nexport function cx(...values: ClassValue[]): string | undefined {\n let out = '';\n for (const v of values) if (v) out = out ? `${out} ${v}` : v;\n return out || undefined;\n}\n"],"mappings":";;AAGA,SAAgB,GAAG,GAAG,QAA0C;CAC9D,IAAI,MAAM;CACV,KAAK,MAAM,KAAK,QAAQ,IAAI,GAAG,MAAM,MAAM,GAAG,IAAI,GAAG,MAAM;CAC3D,OAAO,OAAO,KAAA;AAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-attr.js","names":[],"sources":["../../../../utils/src/data-attr.ts"],"sourcesContent":["/** `true` → `\"\"` (attribute present), falsy → `undefined` (attribute absent). */\nexport function dataAttr(condition: boolean | undefined): '' | undefined {\n return condition ? '' : undefined;\n}\n"],"mappings":";;AACA,SAAgB,SAAS,WAAgD;CACvE,OAAO,YAAY,KAAK,KAAA;AAC1B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// ../utils/src/warn.ts
|
|
2
|
+
/** True unless the consumer's bundler replaced NODE_ENV with "production". */
|
|
3
|
+
var isDev = typeof process === "undefined" || process.env.NODE_ENV !== "production";
|
|
4
|
+
var seen = /* @__PURE__ */ new Set();
|
|
5
|
+
/** Development-only warning, printed once per message. Stripped by consumers' minifiers in prod. */
|
|
6
|
+
function warnOnce(message) {
|
|
7
|
+
if (!isDev || seen.has(message)) return;
|
|
8
|
+
seen.add(message);
|
|
9
|
+
console.warn(`[reactloom] ${message}`);
|
|
10
|
+
}
|
|
11
|
+
export { isDev, warnOnce };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=warn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warn.js","names":[],"sources":["../../../../utils/src/warn.ts"],"sourcesContent":["declare const process: { env: { NODE_ENV?: string } } | undefined;\n\n/** True unless the consumer's bundler replaced NODE_ENV with \"production\". */\nexport const isDev: boolean =\n typeof process === 'undefined' || process.env.NODE_ENV !== 'production';\n\nconst seen = new Set<string>();\n\n/** Development-only warning, printed once per message. Stripped by consumers' minifiers in prod. */\nexport function warnOnce(message: string): void {\n if (!isDev || seen.has(message)) return;\n seen.add(message);\n console.warn(`[reactloom] ${message}`);\n}\n"],"mappings":";;AAGA,IAAa,QACX,OAAO,YAAY,eAAA,QAAA,IAAA,aAAwC;AAE7D,IAAM,uBAAO,IAAI,IAAY;;AAG7B,SAAgB,SAAS,SAAuB;CAC9C,IAAI,CAAC,SAAS,KAAK,IAAI,OAAO,GAAG;CACjC,KAAK,IAAI,OAAO;CAChB,QAAQ,KAAK,eAAe,SAAS;AACvC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CellValue, DataGridColumn } from './types.js';
|
|
2
|
+
export interface EditingState {
|
|
3
|
+
rowId: string;
|
|
4
|
+
column: string;
|
|
5
|
+
draft: string;
|
|
6
|
+
error?: string;
|
|
7
|
+
saving?: boolean;
|
|
8
|
+
/** Started by typing: keep the typed text and put the caret after it (instead of selecting). */
|
|
9
|
+
typed?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface CellEditorProps<Row> {
|
|
12
|
+
column: DataGridColumn<Row>;
|
|
13
|
+
row: Row;
|
|
14
|
+
value: CellValue;
|
|
15
|
+
state: EditingState;
|
|
16
|
+
label: string;
|
|
17
|
+
errorId: string;
|
|
18
|
+
savingLabel: string;
|
|
19
|
+
onDraftChange: (draft: string) => void;
|
|
20
|
+
onCommit: (value?: unknown, restoreFocus?: boolean) => void;
|
|
21
|
+
onCancel: () => void;
|
|
22
|
+
}
|
|
23
|
+
/** The editor shown inside a cell while it is edited (text, number, select or your own). */
|
|
24
|
+
export declare function CellEditor<Row>({ column, row, value, state, label, errorId, savingLabel, onDraftChange, onCommit, onCancel }: CellEditorProps<Row>): import("react").JSX.Element;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=cell-editor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cell-editor.d.ts","sourceRoot":"","sources":["../src/cell-editor.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5D,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gGAAgG;IAChG,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,UAAU,eAAe,CAAC,GAAG;IAC3B,MAAM,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;IAC5B,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,YAAY,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC5D,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,4FAA4F;AAC5F,wBAAgB,UAAU,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,eAAe,CAAC,GAAG,CAAC,+BAoHlJ"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import data_grid_module_default from "./data-grid.module.js";
|
|
3
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/cell-editor.tsx
|
|
6
|
+
/** The editor shown inside a cell while it is edited (text, number, select or your own). */
|
|
7
|
+
function CellEditor({ column, row, value, state, label, errorId, savingLabel, onDraftChange, onCommit, onCancel }) {
|
|
8
|
+
const focusRef = useRef(null);
|
|
9
|
+
const typed = useRef(state.typed);
|
|
10
|
+
const finished = useRef(false);
|
|
11
|
+
const autoFocusRef = useCallback((el) => {
|
|
12
|
+
focusRef.current = el;
|
|
13
|
+
}, []);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const el = focusRef.current;
|
|
16
|
+
if (!el) return;
|
|
17
|
+
el.focus();
|
|
18
|
+
if (!(el instanceof HTMLInputElement)) return;
|
|
19
|
+
if (typed.current) el.setSelectionRange(el.value.length, el.value.length);
|
|
20
|
+
else el.select();
|
|
21
|
+
}, []);
|
|
22
|
+
const finish = (fn) => {
|
|
23
|
+
finished.current = true;
|
|
24
|
+
fn();
|
|
25
|
+
queueMicrotask(() => finished.current = false);
|
|
26
|
+
};
|
|
27
|
+
const onKeyDown = (event) => {
|
|
28
|
+
if (event.key === "Escape") {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
event.stopPropagation();
|
|
31
|
+
finish(onCancel);
|
|
32
|
+
} else if (event.key === "Enter" && !event.nativeEvent.isComposing) {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
event.stopPropagation();
|
|
35
|
+
finish(() => onCommit());
|
|
36
|
+
} else event.stopPropagation();
|
|
37
|
+
};
|
|
38
|
+
const onBlur = (event) => {
|
|
39
|
+
if (!finished.current && !state.saving) onCommit(void 0, !event.relatedTarget);
|
|
40
|
+
};
|
|
41
|
+
const invalid = Boolean(state.error);
|
|
42
|
+
const common = {
|
|
43
|
+
"aria-label": label,
|
|
44
|
+
"aria-invalid": invalid || void 0,
|
|
45
|
+
"aria-describedby": invalid ? errorId : void 0,
|
|
46
|
+
disabled: state.saving
|
|
47
|
+
};
|
|
48
|
+
let control;
|
|
49
|
+
if (typeof column.editor === "function") {
|
|
50
|
+
const Editor = column.editor;
|
|
51
|
+
control = /* @__PURE__ */ jsx(Editor, {
|
|
52
|
+
row,
|
|
53
|
+
value,
|
|
54
|
+
draft: state.draft,
|
|
55
|
+
onDraftChange,
|
|
56
|
+
commit: (v) => finish(() => onCommit(v)),
|
|
57
|
+
cancel: () => finish(onCancel),
|
|
58
|
+
"aria-label": label,
|
|
59
|
+
"aria-describedby": common["aria-describedby"],
|
|
60
|
+
"aria-invalid": common["aria-invalid"],
|
|
61
|
+
autoFocusRef
|
|
62
|
+
});
|
|
63
|
+
} else if (column.editor === "select") control = /* @__PURE__ */ jsx("select", {
|
|
64
|
+
ref: autoFocusRef,
|
|
65
|
+
className: data_grid_module_default.editor,
|
|
66
|
+
value: state.draft,
|
|
67
|
+
onChange: (e) => {
|
|
68
|
+
onDraftChange(e.target.value);
|
|
69
|
+
finish(() => onCommit(e.target.value));
|
|
70
|
+
},
|
|
71
|
+
onKeyDown,
|
|
72
|
+
onBlur,
|
|
73
|
+
...common,
|
|
74
|
+
children: (column.options ?? []).map((o) => /* @__PURE__ */ jsx("option", {
|
|
75
|
+
value: o.value,
|
|
76
|
+
children: o.label
|
|
77
|
+
}, o.value))
|
|
78
|
+
});
|
|
79
|
+
else control = /* @__PURE__ */ jsx("input", {
|
|
80
|
+
ref: autoFocusRef,
|
|
81
|
+
className: data_grid_module_default.editor,
|
|
82
|
+
type: "text",
|
|
83
|
+
inputMode: column.editor === "number" ? "decimal" : void 0,
|
|
84
|
+
value: state.draft,
|
|
85
|
+
onChange: (e) => onDraftChange(e.target.value),
|
|
86
|
+
onKeyDown,
|
|
87
|
+
onBlur,
|
|
88
|
+
...common
|
|
89
|
+
});
|
|
90
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
91
|
+
className: data_grid_module_default.editing,
|
|
92
|
+
onKeyDown: typeof column.editor === "function" ? onKeyDown : void 0,
|
|
93
|
+
children: [
|
|
94
|
+
control,
|
|
95
|
+
state.saving && /* @__PURE__ */ jsx("span", {
|
|
96
|
+
className: data_grid_module_default.editStatus,
|
|
97
|
+
children: savingLabel
|
|
98
|
+
}),
|
|
99
|
+
state.error && /* @__PURE__ */ jsx("span", {
|
|
100
|
+
id: errorId,
|
|
101
|
+
className: data_grid_module_default.editError,
|
|
102
|
+
children: state.error
|
|
103
|
+
})
|
|
104
|
+
]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
export { CellEditor };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=cell-editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cell-editor.js","names":["styles"],"sources":["../src/cell-editor.tsx"],"sourcesContent":["'use client';\n\nimport { useCallback, useEffect, useRef, type FocusEvent, type KeyboardEvent } from 'react';\nimport type { CellValue, DataGridColumn } from './types.js';\nimport styles from './data-grid.module.css';\n\nexport interface EditingState {\n rowId: string;\n column: string;\n draft: string;\n error?: string;\n saving?: boolean;\n /** Started by typing: keep the typed text and put the caret after it (instead of selecting). */\n typed?: boolean;\n}\n\ninterface CellEditorProps<Row> {\n column: DataGridColumn<Row>;\n row: Row;\n value: CellValue;\n state: EditingState;\n label: string;\n errorId: string;\n savingLabel: string;\n onDraftChange: (draft: string) => void;\n onCommit: (value?: unknown, restoreFocus?: boolean) => void;\n onCancel: () => void;\n}\n\n/** The editor shown inside a cell while it is edited (text, number, select or your own). */\nexport function CellEditor<Row>({ column, row, value, state, label, errorId, savingLabel, onDraftChange, onCommit, onCancel }: CellEditorProps<Row>) {\n const focusRef = useRef<HTMLElement | null>(null);\n const typed = useRef(state.typed);\n // Blur commits, except when Escape or Enter already finished the edit.\n const finished = useRef(false);\n const autoFocusRef = useCallback((el: HTMLElement | null) => {\n focusRef.current = el;\n }, []);\n useEffect(() => {\n const el = focusRef.current;\n if (!el) return;\n el.focus();\n if (!(el instanceof HTMLInputElement)) return;\n // Typing into a cell replaces its value with what was typed, so keep typing after it.\n if (typed.current) el.setSelectionRange(el.value.length, el.value.length);\n else el.select();\n }, []);\n\n const finish = (fn: () => void) => {\n finished.current = true;\n fn();\n // Re-arm for the next attempt if validation keeps the editor open.\n queueMicrotask(() => (finished.current = false));\n };\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n event.stopPropagation();\n finish(onCancel);\n } else if (event.key === 'Enter' && !event.nativeEvent.isComposing) {\n event.preventDefault();\n event.stopPropagation();\n finish(() => onCommit());\n } else {\n // Keep arrow keys, Home/End etc. inside the editor (not grid navigation).\n event.stopPropagation();\n }\n };\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n if (!finished.current && !state.saving) onCommit(undefined, !event.relatedTarget);\n };\n const invalid = Boolean(state.error);\n const common = {\n 'aria-label': label,\n 'aria-invalid': invalid || undefined,\n 'aria-describedby': invalid ? errorId : undefined,\n disabled: state.saving,\n };\n\n let control;\n if (typeof column.editor === 'function') {\n const Editor = column.editor;\n control = (\n <Editor\n row={row}\n value={value}\n draft={state.draft}\n onDraftChange={onDraftChange}\n commit={(v) => finish(() => onCommit(v))}\n cancel={() => finish(onCancel)}\n aria-label={label}\n aria-describedby={common['aria-describedby']}\n aria-invalid={common['aria-invalid']}\n autoFocusRef={autoFocusRef}\n />\n );\n } else if (column.editor === 'select') {\n control = (\n <select\n ref={autoFocusRef}\n className={styles.editor}\n value={state.draft}\n onChange={(e) => {\n onDraftChange(e.target.value);\n // Choosing an option is the commit.\n finish(() => onCommit(e.target.value));\n }}\n onKeyDown={onKeyDown}\n onBlur={onBlur}\n {...common}\n >\n {(column.options ?? []).map((o) => (\n <option key={o.value} value={o.value}>\n {o.label}\n </option>\n ))}\n </select>\n );\n } else {\n control = (\n <input\n ref={autoFocusRef}\n className={styles.editor}\n type=\"text\"\n inputMode={column.editor === 'number' ? 'decimal' : undefined}\n value={state.draft}\n onChange={(e) => onDraftChange(e.target.value)}\n onKeyDown={onKeyDown}\n onBlur={onBlur}\n {...common}\n />\n );\n }\n\n return (\n // Custom editors handle their own keys; this wrapper only stops grid navigation.\n <div className={styles.editing} onKeyDown={typeof column.editor === 'function' ? onKeyDown : undefined}>\n {control}\n {state.saving && <span className={styles.editStatus}>{savingLabel}</span>}\n {state.error && (\n <span id={errorId} className={styles.editError}>\n {state.error}\n </span>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;AA8BA,SAAgB,WAAgB,EAAE,QAAQ,KAAK,OAAO,OAAO,OAAO,SAAS,aAAa,eAAe,UAAU,YAAkC;CACnJ,MAAM,WAAW,OAA2B,IAAI;CAChD,MAAM,QAAQ,OAAO,MAAM,KAAK;CAEhC,MAAM,WAAW,OAAO,KAAK;CAC7B,MAAM,eAAe,aAAa,OAA2B;EAC3D,SAAS,UAAU;CACrB,GAAG,CAAC,CAAC;CACL,gBAAgB;EACd,MAAM,KAAK,SAAS;EACpB,IAAI,CAAC,IAAI;EACT,GAAG,MAAM;EACT,IAAI,EAAE,cAAc,mBAAmB;EAEvC,IAAI,MAAM,SAAS,GAAG,kBAAkB,GAAG,MAAM,QAAQ,GAAG,MAAM,MAAM;OACnE,GAAG,OAAO;CACjB,GAAG,CAAC,CAAC;CAEL,MAAM,UAAU,OAAmB;EACjC,SAAS,UAAU;EACnB,GAAG;EAEH,qBAAsB,SAAS,UAAU,KAAM;CACjD;CACA,MAAM,aAAa,UAAsC;EACvD,IAAI,MAAM,QAAQ,UAAU;GAC1B,MAAM,eAAe;GACrB,MAAM,gBAAgB;GACtB,OAAO,QAAQ;EACjB,OAAO,IAAI,MAAM,QAAQ,WAAW,CAAC,MAAM,YAAY,aAAa;GAClE,MAAM,eAAe;GACrB,MAAM,gBAAgB;GACtB,aAAa,SAAS,CAAC;EACzB,OAEE,MAAM,gBAAgB;CAE1B;CACA,MAAM,UAAU,UAAmC;EACjD,IAAI,CAAC,SAAS,WAAW,CAAC,MAAM,QAAQ,SAAS,KAAA,GAAW,CAAC,MAAM,aAAa;CAClF;CACA,MAAM,UAAU,QAAQ,MAAM,KAAK;CACnC,MAAM,SAAS;EACb,cAAc;EACd,gBAAgB,WAAW,KAAA;EAC3B,oBAAoB,UAAU,UAAU,KAAA;EACxC,UAAU,MAAM;CAClB;CAEA,IAAI;CACJ,IAAI,OAAO,OAAO,WAAW,YAAY;EACvC,MAAM,SAAS,OAAO;EACtB,UACE,oBAAC,QAAD;GACO;GACE;GACP,OAAO,MAAM;GACE;GACf,SAAS,MAAM,aAAa,SAAS,CAAC,CAAC;GACvC,cAAc,OAAO,QAAQ;GAC7B,cAAY;GACZ,oBAAkB,OAAO;GACzB,gBAAc,OAAO;GACP;EACf,CAAA;CAEL,OAAO,IAAI,OAAO,WAAW,UAC3B,UACE,oBAAC,UAAD;EACE,KAAK;EACL,WAAWA,yBAAO;EAClB,OAAO,MAAM;EACb,WAAW,MAAM;GACf,cAAc,EAAE,OAAO,KAAK;GAE5B,aAAa,SAAS,EAAE,OAAO,KAAK,CAAC;EACvC;EACW;EACH;EACR,GAAI;EAEF,WAAA,OAAO,WAAW,CAAC,EAAA,CAAG,KAAK,MAC3B,oBAAC,UAAD;GAAsB,OAAO,EAAE;GAC5B,UAAA,EAAE;EACG,GAFK,EAAE,KAEP,CACT;CACK,CAAA;MAGV,UACE,oBAAC,SAAD;EACE,KAAK;EACL,WAAWA,yBAAO;EAClB,MAAK;EACL,WAAW,OAAO,WAAW,WAAW,YAAY,KAAA;EACpD,OAAO,MAAM;EACb,WAAW,MAAM,cAAc,EAAE,OAAO,KAAK;EAClC;EACH;EACR,GAAI;CACL,CAAA;CAIL,OAEE,qBAAC,OAAD;EAAK,WAAWA,yBAAO;EAAS,WAAW,OAAO,OAAO,WAAW,aAAa,YAAY,KAAA;EAA7F,UAAA;GACG;GACA,MAAM,UAAU,oBAAC,QAAD;IAAM,WAAWA,yBAAO;IAAa,UAAA;GAAkB,CAAA;GACvE,MAAM,SACL,oBAAC,QAAD;IAAM,IAAI;IAAS,WAAWA,yBAAO;IAClC,UAAA,MAAM;GACH,CAAA;EAEL;;AAET"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clipboard text in the format spreadsheets use: tab-separated columns, line-separated rows,
|
|
3
|
+
* fields quoted when they contain a tab, line break or quote (quotes doubled).
|
|
4
|
+
*/
|
|
5
|
+
export declare function toTsv(rows: ReadonlyArray<ReadonlyArray<string>>): string;
|
|
6
|
+
/** Parses spreadsheet clipboard text (as written by Excel, Google Sheets, Numbers or `toTsv`). */
|
|
7
|
+
export declare function parseTsv(text: string): string[][];
|
|
8
|
+
/** An HTML table for rich paste targets (spreadsheets keep the cells; documents get a table). */
|
|
9
|
+
export declare function toHtmlTable(rows: ReadonlyArray<ReadonlyArray<string>>): string;
|
|
10
|
+
//# sourceMappingURL=clipboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../src/clipboard.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAGxE;AAED,kGAAkG;AAClG,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAoCjD;AAED,iGAAiG;AACjG,wBAAgB,WAAW,CAAC,IAAI,EAAE,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAG9E"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/clipboard.ts
|
|
2
|
+
/**
|
|
3
|
+
* Clipboard text in the format spreadsheets use: tab-separated columns, line-separated rows,
|
|
4
|
+
* fields quoted when they contain a tab, line break or quote (quotes doubled).
|
|
5
|
+
*/
|
|
6
|
+
function toTsv(rows) {
|
|
7
|
+
const field = (text) => /[\t\n\r"]/.test(text) ? `"${text.replace(/"/g, "\"\"")}"` : text;
|
|
8
|
+
return rows.map((cells) => cells.map(field).join(" ")).join("\n");
|
|
9
|
+
}
|
|
10
|
+
/** Parses spreadsheet clipboard text (as written by Excel, Google Sheets, Numbers or `toTsv`). */
|
|
11
|
+
function parseTsv(text) {
|
|
12
|
+
const rows = [];
|
|
13
|
+
let row = [];
|
|
14
|
+
let field = "";
|
|
15
|
+
let quoted = false;
|
|
16
|
+
let i = 0;
|
|
17
|
+
const input = text.replace(/\r\n?/g, "\n").replace(/\n$/, "");
|
|
18
|
+
while (i < input.length) {
|
|
19
|
+
const c = input[i];
|
|
20
|
+
if (quoted) {
|
|
21
|
+
if (c === "\"" && input[i + 1] === "\"") {
|
|
22
|
+
field += "\"";
|
|
23
|
+
i += 2;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (c === "\"") quoted = false;
|
|
27
|
+
else field += c;
|
|
28
|
+
i++;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (c === "\"" && field === "") quoted = true;
|
|
32
|
+
else if (c === " ") {
|
|
33
|
+
row.push(field);
|
|
34
|
+
field = "";
|
|
35
|
+
} else if (c === "\n") {
|
|
36
|
+
row.push(field);
|
|
37
|
+
rows.push(row);
|
|
38
|
+
row = [];
|
|
39
|
+
field = "";
|
|
40
|
+
} else field += c;
|
|
41
|
+
i++;
|
|
42
|
+
}
|
|
43
|
+
row.push(field);
|
|
44
|
+
rows.push(row);
|
|
45
|
+
return rows;
|
|
46
|
+
}
|
|
47
|
+
/** An HTML table for rich paste targets (spreadsheets keep the cells; documents get a table). */
|
|
48
|
+
function toHtmlTable(rows) {
|
|
49
|
+
const esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
50
|
+
return `<table>${rows.map((cells) => `<tr>${cells.map((c) => `<td>${esc(c)}</td>`).join("")}</tr>`).join("")}</table>`;
|
|
51
|
+
}
|
|
52
|
+
export { parseTsv, toHtmlTable, toTsv };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=clipboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboard.js","names":[],"sources":["../src/clipboard.ts"],"sourcesContent":["/**\n * Clipboard text in the format spreadsheets use: tab-separated columns, line-separated rows,\n * fields quoted when they contain a tab, line break or quote (quotes doubled).\n */\nexport function toTsv(rows: ReadonlyArray<ReadonlyArray<string>>): string {\n const field = (text: string) => (/[\\t\\n\\r\"]/.test(text) ? `\"${text.replace(/\"/g, '\"\"')}\"` : text);\n return rows.map((cells) => cells.map(field).join('\\t')).join('\\n');\n}\n\n/** Parses spreadsheet clipboard text (as written by Excel, Google Sheets, Numbers or `toTsv`). */\nexport function parseTsv(text: string): string[][] {\n const rows: string[][] = [];\n let row: string[] = [];\n let field = '';\n let quoted = false;\n let i = 0;\n // A trailing line break is not an extra empty row.\n const input = text.replace(/\\r\\n?/g, '\\n').replace(/\\n$/, '');\n while (i < input.length) {\n const c = input[i];\n if (quoted) {\n if (c === '\"' && input[i + 1] === '\"') {\n field += '\"';\n i += 2;\n continue;\n }\n if (c === '\"') quoted = false;\n else field += c;\n i++;\n continue;\n }\n if (c === '\"' && field === '') quoted = true;\n else if (c === '\\t') {\n row.push(field);\n field = '';\n } else if (c === '\\n') {\n row.push(field);\n rows.push(row);\n row = [];\n field = '';\n } else field += c;\n i++;\n }\n row.push(field);\n rows.push(row);\n return rows;\n}\n\n/** An HTML table for rich paste targets (spreadsheets keep the cells; documents get a table). */\nexport function toHtmlTable(rows: ReadonlyArray<ReadonlyArray<string>>): string {\n const esc = (s: string) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\n return `<table>${rows.map((cells) => `<tr>${cells.map((c) => `<td>${esc(c)}</td>`).join('')}</tr>`).join('')}</table>`;\n}\n"],"mappings":";;;;;AAIA,SAAgB,MAAM,MAAoD;CACxE,MAAM,SAAS,SAAkB,YAAY,KAAK,IAAI,IAAI,IAAI,KAAK,QAAQ,MAAM,MAAI,EAAE,KAAK;CAC5F,OAAO,KAAK,KAAK,UAAU,MAAM,IAAI,KAAK,CAAC,CAAC,KAAK,GAAI,CAAC,CAAC,CAAC,KAAK,IAAI;AACnE;;AAGA,SAAgB,SAAS,MAA0B;CACjD,MAAM,OAAmB,CAAC;CAC1B,IAAI,MAAgB,CAAC;CACrB,IAAI,QAAQ;CACZ,IAAI,SAAS;CACb,IAAI,IAAI;CAER,MAAM,QAAQ,KAAK,QAAQ,UAAU,IAAI,CAAC,CAAC,QAAQ,OAAO,EAAE;CAC5D,OAAO,IAAI,MAAM,QAAQ;EACvB,MAAM,IAAI,MAAM;EAChB,IAAI,QAAQ;GACV,IAAI,MAAM,QAAO,MAAM,IAAI,OAAO,MAAK;IACrC,SAAS;IACT,KAAK;IACL;GACF;GACA,IAAI,MAAM,MAAK,SAAS;QACnB,SAAS;GACd;GACA;EACF;EACA,IAAI,MAAM,QAAO,UAAU,IAAI,SAAS;OACnC,IAAI,MAAM,KAAM;GACnB,IAAI,KAAK,KAAK;GACd,QAAQ;EACV,OAAO,IAAI,MAAM,MAAM;GACrB,IAAI,KAAK,KAAK;GACd,KAAK,KAAK,GAAG;GACb,MAAM,CAAC;GACP,QAAQ;EACV,OAAO,SAAS;EAChB;CACF;CACA,IAAI,KAAK,KAAK;CACd,KAAK,KAAK,GAAG;CACb,OAAO;AACT;;AAGA,SAAgB,YAAY,MAAoD;CAC9E,MAAM,OAAO,MAAc,EAAE,QAAQ,MAAM,OAAO,CAAC,CAAC,QAAQ,MAAM,MAAM,CAAC,CAAC,QAAQ,MAAM,MAAM;CAC9F,OAAO,UAAU,KAAK,KAAK,UAAU,OAAO,MAAM,KAAK,MAAM,OAAO,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;AAC/G"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CellValue, DataGridFilter } from './types.js';
|
|
2
|
+
export declare const isEmpty: (value: CellValue) => value is "" | null | undefined;
|
|
3
|
+
export declare function matchesColumnFilter(value: CellValue, filter: DataGridFilter, locale: string): boolean;
|
|
4
|
+
//# sourceMappingURL=column-filters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-filters.d.ts","sourceRoot":"","sources":["../src/column-filters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5D,eAAO,MAAM,OAAO,GAAI,OAAO,SAAS,mCAA0D,CAAC;AAEnG,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CA0BrG"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/column-filters.ts
|
|
2
|
+
var isEmpty = (value) => value === null || value === void 0 || value === "";
|
|
3
|
+
function matchesColumnFilter(value, filter, locale) {
|
|
4
|
+
if (filter.type === "empty") return isEmpty(value) === (filter.operator === "isEmpty");
|
|
5
|
+
if (filter.type === "boolean") return value === filter.value;
|
|
6
|
+
if (filter.type === "text") {
|
|
7
|
+
if (typeof value !== "string" || isEmpty(value)) return false;
|
|
8
|
+
const text = value.toLocaleLowerCase(locale);
|
|
9
|
+
const query = filter.value.toLocaleLowerCase(locale);
|
|
10
|
+
switch (filter.operator) {
|
|
11
|
+
case "contains": return text.includes(query);
|
|
12
|
+
case "startsWith": return text.startsWith(query);
|
|
13
|
+
case "endsWith": return text.endsWith(query);
|
|
14
|
+
case "equals": return text === query;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const numeric = filter.type === "date" && value instanceof Date ? value.getTime() : filter.type === "number" && typeof value === "number" ? value : NaN;
|
|
18
|
+
if (!Number.isFinite(numeric) || !Number.isFinite(filter.value)) return false;
|
|
19
|
+
switch (filter.operator) {
|
|
20
|
+
case "equals": return numeric === filter.value;
|
|
21
|
+
case "notEquals": return numeric !== filter.value;
|
|
22
|
+
case "lt": return numeric < filter.value;
|
|
23
|
+
case "lte": return numeric <= filter.value;
|
|
24
|
+
case "gt": return numeric > filter.value;
|
|
25
|
+
case "gte": return numeric >= filter.value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export { isEmpty, matchesColumnFilter };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=column-filters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-filters.js","names":[],"sources":["../src/column-filters.ts"],"sourcesContent":["import type { CellValue, DataGridFilter } from './types.js';\n\nexport const isEmpty = (value: CellValue) => value === null || value === undefined || value === '';\n\nexport function matchesColumnFilter(value: CellValue, filter: DataGridFilter, locale: string): boolean {\n if (filter.type === 'empty') return isEmpty(value) === (filter.operator === 'isEmpty');\n if (filter.type === 'boolean') return value === filter.value;\n if (filter.type === 'text') {\n if (typeof value !== 'string' || isEmpty(value)) return false;\n const text = value.toLocaleLowerCase(locale);\n const query = filter.value.toLocaleLowerCase(locale);\n switch (filter.operator) {\n case 'contains': return text.includes(query);\n case 'startsWith': return text.startsWith(query);\n case 'endsWith': return text.endsWith(query);\n case 'equals': return text === query;\n }\n }\n\n const numeric = filter.type === 'date' && value instanceof Date ? value.getTime()\n : filter.type === 'number' && typeof value === 'number' ? value : NaN;\n if (!Number.isFinite(numeric) || !Number.isFinite(filter.value)) return false;\n switch (filter.operator) {\n case 'equals': return numeric === filter.value;\n case 'notEquals': return numeric !== filter.value;\n case 'lt': return numeric < filter.value;\n case 'lte': return numeric <= filter.value;\n case 'gt': return numeric > filter.value;\n case 'gte': return numeric >= filter.value;\n }\n}\n"],"mappings":";AAEA,IAAa,WAAW,UAAqB,UAAU,QAAQ,UAAU,KAAA,KAAa,UAAU;AAEhG,SAAgB,oBAAoB,OAAkB,QAAwB,QAAyB;CACrG,IAAI,OAAO,SAAS,SAAS,OAAO,QAAQ,KAAK,OAAO,OAAO,aAAa;CAC5E,IAAI,OAAO,SAAS,WAAW,OAAO,UAAU,OAAO;CACvD,IAAI,OAAO,SAAS,QAAQ;EAC1B,IAAI,OAAO,UAAU,YAAY,QAAQ,KAAK,GAAG,OAAO;EACxD,MAAM,OAAO,MAAM,kBAAkB,MAAM;EAC3C,MAAM,QAAQ,OAAO,MAAM,kBAAkB,MAAM;EACnD,QAAQ,OAAO,UAAf;GACE,KAAK,YAAY,OAAO,KAAK,SAAS,KAAK;GAC3C,KAAK,cAAc,OAAO,KAAK,WAAW,KAAK;GAC/C,KAAK,YAAY,OAAO,KAAK,SAAS,KAAK;GAC3C,KAAK,UAAU,OAAO,SAAS;EACjC;CACF;CAEA,MAAM,UAAU,OAAO,SAAS,UAAU,iBAAiB,OAAO,MAAM,QAAQ,IAC5E,OAAO,SAAS,YAAY,OAAO,UAAU,WAAW,QAAQ;CACpE,IAAI,CAAC,OAAO,SAAS,OAAO,KAAK,CAAC,OAAO,SAAS,OAAO,KAAK,GAAG,OAAO;CACxE,QAAQ,OAAO,UAAf;EACE,KAAK,UAAU,OAAO,YAAY,OAAO;EACzC,KAAK,aAAa,OAAO,YAAY,OAAO;EAC5C,KAAK,MAAM,OAAO,UAAU,OAAO;EACnC,KAAK,OAAO,OAAO,WAAW,OAAO;EACrC,KAAK,MAAM,OAAO,UAAU,OAAO;EACnC,KAAK,OAAO,OAAO,WAAW,OAAO;CACvC;AACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DataGridColumnLayout } from './types.js';
|
|
2
|
+
type Side = 'start' | 'end';
|
|
3
|
+
/** Restore valid keys once, preserving declared order for columns added since a view was saved. */
|
|
4
|
+
export declare function arrangeColumns(keys: readonly string[], layout: DataGridColumnLayout, leading?: string | readonly string[]): {
|
|
5
|
+
order: string[];
|
|
6
|
+
sides: Map<string, Side>;
|
|
7
|
+
};
|
|
8
|
+
export declare function snapshotColumnLayout(layout: ReturnType<typeof arrangeColumns>, leading?: string | readonly string[]): DataGridColumnLayout;
|
|
9
|
+
/** Only visible columns contribute to the sticky offset, using the widths actually rendered. */
|
|
10
|
+
export declare function getPinnedOffsets(columns: ReadonlyArray<{
|
|
11
|
+
id: string;
|
|
12
|
+
getSize(): number;
|
|
13
|
+
}>, sides: ReadonlyMap<string, Side>): Map<string, {
|
|
14
|
+
side: Side;
|
|
15
|
+
offset: number;
|
|
16
|
+
}>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=column-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-layout.d.ts","sourceRoot":"","sources":["../src/column-layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD,KAAK,IAAI,GAAG,OAAO,GAAG,KAAK,CAAC;AAE5B,mGAAmG;AACnG,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,oBAAoB,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE;;;EAYzH;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,oBAAoB,CAQ1I;AAED,gGAAgG;AAChG,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,IAAI,MAAM,CAAA;CAAE,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC;UAClF,IAAI;YAAU,MAAM;GAgB7D"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/column-layout.ts
|
|
2
|
+
/** Restore valid keys once, preserving declared order for columns added since a view was saved. */
|
|
3
|
+
function arrangeColumns(keys, layout, leading) {
|
|
4
|
+
const remaining = new Set(keys);
|
|
5
|
+
const take = (candidates = []) => candidates.filter((key) => remaining.delete(key));
|
|
6
|
+
const start = take(layout.pinnedStart);
|
|
7
|
+
const end = take(layout.pinnedEnd);
|
|
8
|
+
const center = [...take(layout.order), ...remaining];
|
|
9
|
+
const lead = typeof leading === "string" ? [leading] : leading ?? [];
|
|
10
|
+
if (lead.length) (start.length ? start : center).unshift(...lead);
|
|
11
|
+
const sides = /* @__PURE__ */ new Map();
|
|
12
|
+
for (const key of start) sides.set(key, "start");
|
|
13
|
+
for (const key of end) sides.set(key, "end");
|
|
14
|
+
return {
|
|
15
|
+
order: [
|
|
16
|
+
...start,
|
|
17
|
+
...center,
|
|
18
|
+
...end
|
|
19
|
+
],
|
|
20
|
+
sides
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function snapshotColumnLayout(layout, leading) {
|
|
24
|
+
const lead = new Set(typeof leading === "string" ? [leading] : leading ?? []);
|
|
25
|
+
const order = layout.order.filter((key) => !lead.has(key));
|
|
26
|
+
return {
|
|
27
|
+
order,
|
|
28
|
+
pinnedStart: order.filter((key) => layout.sides.get(key) === "start"),
|
|
29
|
+
pinnedEnd: order.filter((key) => layout.sides.get(key) === "end")
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Only visible columns contribute to the sticky offset, using the widths actually rendered. */
|
|
33
|
+
function getPinnedOffsets(columns, sides) {
|
|
34
|
+
const offsets = /* @__PURE__ */ new Map();
|
|
35
|
+
let start = 0;
|
|
36
|
+
let end = 0;
|
|
37
|
+
for (let index = 0; index < columns.length; index++) {
|
|
38
|
+
const leading = columns[index];
|
|
39
|
+
const trailing = columns[columns.length - index - 1];
|
|
40
|
+
if (leading && sides.get(leading.id) === "start") {
|
|
41
|
+
offsets.set(leading.id, {
|
|
42
|
+
side: "start",
|
|
43
|
+
offset: start
|
|
44
|
+
});
|
|
45
|
+
start += leading.getSize();
|
|
46
|
+
}
|
|
47
|
+
if (trailing && sides.get(trailing.id) === "end") {
|
|
48
|
+
offsets.set(trailing.id, {
|
|
49
|
+
side: "end",
|
|
50
|
+
offset: end
|
|
51
|
+
});
|
|
52
|
+
end += trailing.getSize();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return offsets;
|
|
56
|
+
}
|
|
57
|
+
export { arrangeColumns, getPinnedOffsets, snapshotColumnLayout };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=column-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-layout.js","names":[],"sources":["../src/column-layout.ts"],"sourcesContent":["import type { DataGridColumnLayout } from './types.js';\n\ntype Side = 'start' | 'end';\n\n/** Restore valid keys once, preserving declared order for columns added since a view was saved. */\nexport function arrangeColumns(keys: readonly string[], layout: DataGridColumnLayout, leading?: string | readonly string[]) {\n const remaining = new Set(keys);\n const take = (candidates: readonly string[] = []) => candidates.filter((key) => remaining.delete(key));\n const start = take(layout.pinnedStart);\n const end = take(layout.pinnedEnd);\n const center = [...take(layout.order), ...remaining];\n const lead = typeof leading === 'string' ? [leading] : (leading ?? []);\n if (lead.length) (start.length ? start : center).unshift(...lead);\n const sides = new Map<string, Side>();\n for (const key of start) sides.set(key, 'start');\n for (const key of end) sides.set(key, 'end');\n return { order: [...start, ...center, ...end], sides };\n}\n\nexport function snapshotColumnLayout(layout: ReturnType<typeof arrangeColumns>, leading?: string | readonly string[]): DataGridColumnLayout {\n const lead = new Set(typeof leading === 'string' ? [leading] : (leading ?? []));\n const order = layout.order.filter((key) => !lead.has(key));\n return {\n order,\n pinnedStart: order.filter((key) => layout.sides.get(key) === 'start'),\n pinnedEnd: order.filter((key) => layout.sides.get(key) === 'end'),\n };\n}\n\n/** Only visible columns contribute to the sticky offset, using the widths actually rendered. */\nexport function getPinnedOffsets(columns: ReadonlyArray<{ id: string; getSize(): number }>, sides: ReadonlyMap<string, Side>) {\n const offsets = new Map<string, { side: Side; offset: number }>();\n let start = 0;\n let end = 0;\n for (let index = 0; index < columns.length; index++) {\n const leading = columns[index];\n const trailing = columns[columns.length - index - 1];\n if (leading && sides.get(leading.id) === 'start') {\n offsets.set(leading.id, { side: 'start', offset: start });\n start += leading.getSize();\n }\n if (trailing && sides.get(trailing.id) === 'end') {\n offsets.set(trailing.id, { side: 'end', offset: end });\n end += trailing.getSize();\n }\n }\n return offsets;\n}\n"],"mappings":";;AAKA,SAAgB,eAAe,MAAyB,QAA8B,SAAsC;CAC1H,MAAM,YAAY,IAAI,IAAI,IAAI;CAC9B,MAAM,QAAQ,aAAgC,CAAC,MAAM,WAAW,QAAQ,QAAQ,UAAU,OAAO,GAAG,CAAC;CACrG,MAAM,QAAQ,KAAK,OAAO,WAAW;CACrC,MAAM,MAAM,KAAK,OAAO,SAAS;CACjC,MAAM,SAAS,CAAC,GAAG,KAAK,OAAO,KAAK,GAAG,GAAG,SAAS;CACnD,MAAM,OAAO,OAAO,YAAY,WAAW,CAAC,OAAO,IAAK,WAAW,CAAC;CACpE,IAAI,KAAK,QAAQ,CAAC,MAAM,SAAS,QAAQ,OAAA,CAAQ,QAAQ,GAAG,IAAI;CAChE,MAAM,wBAAQ,IAAI,IAAkB;CACpC,KAAK,MAAM,OAAO,OAAO,MAAM,IAAI,KAAK,OAAO;CAC/C,KAAK,MAAM,OAAO,KAAK,MAAM,IAAI,KAAK,KAAK;CAC3C,OAAO;EAAE,OAAO;GAAC,GAAG;GAAO,GAAG;GAAQ,GAAG;EAAG;EAAG;CAAM;AACvD;AAEA,SAAgB,qBAAqB,QAA2C,SAA4D;CAC1I,MAAM,OAAO,IAAI,IAAI,OAAO,YAAY,WAAW,CAAC,OAAO,IAAK,WAAW,CAAC,CAAE;CAC9E,MAAM,QAAQ,OAAO,MAAM,QAAQ,QAAQ,CAAC,KAAK,IAAI,GAAG,CAAC;CACzD,OAAO;EACL;EACA,aAAa,MAAM,QAAQ,QAAQ,OAAO,MAAM,IAAI,GAAG,MAAM,OAAO;EACpE,WAAW,MAAM,QAAQ,QAAQ,OAAO,MAAM,IAAI,GAAG,MAAM,KAAK;CAClE;AACF;;AAGA,SAAgB,iBAAiB,SAA2D,OAAkC;CAC5H,MAAM,0BAAU,IAAI,IAA4C;CAChE,IAAI,QAAQ;CACZ,IAAI,MAAM;CACV,KAAK,IAAI,QAAQ,GAAG,QAAQ,QAAQ,QAAQ,SAAS;EACnD,MAAM,UAAU,QAAQ;EACxB,MAAM,WAAW,QAAQ,QAAQ,SAAS,QAAQ;EAClD,IAAI,WAAW,MAAM,IAAI,QAAQ,EAAE,MAAM,SAAS;GAChD,QAAQ,IAAI,QAAQ,IAAI;IAAE,MAAM;IAAS,QAAQ;GAAM,CAAC;GACxD,SAAS,QAAQ,QAAQ;EAC3B;EACA,IAAI,YAAY,MAAM,IAAI,SAAS,EAAE,MAAM,OAAO;GAChD,QAAQ,IAAI,SAAS,IAAI;IAAE,MAAM;IAAO,QAAQ;GAAI,CAAC;GACrD,OAAO,SAAS,QAAQ;EAC1B;CACF;CACA,OAAO;AACT"}
|
package/dist/csv.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CellValue, CsvOptions, DataGridColumn } from './types.js';
|
|
2
|
+
type Exported = string | number | boolean | Date | null | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* One CSV field (RFC 4180): quoted when it contains the delimiter, a quote or a line break.
|
|
5
|
+
* Text that a spreadsheet would run as a formula is prefixed with `'` (OWASP CSV injection
|
|
6
|
+
* guidance); numbers, including negative ones, are written as numbers.
|
|
7
|
+
*/
|
|
8
|
+
export declare function csvField(value: Exported, delimiter?: string): string;
|
|
9
|
+
/** Dates without a time as `YYYY-MM-DD`, others as full ISO 8601. */
|
|
10
|
+
export declare function isoDate(date: Date): string;
|
|
11
|
+
export declare const exportHeader: <Row>(column: DataGridColumn<Row>) => string;
|
|
12
|
+
export declare const exportValue: <Row>(column: DataGridColumn<Row>, row: Row) => CellValue;
|
|
13
|
+
/**
|
|
14
|
+
* Rows to CSV text with the given columns, in order. Each cell is `column.exportValue`, else
|
|
15
|
+
* `column.value`, else `row[column.key]`. Lines end with CRLF (RFC 4180).
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const csv = toCsv(columns, rows);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function toCsv<Row>(columns: ReadonlyArray<DataGridColumn<Row>>, rows: readonly Row[], options?: CsvOptions): string;
|
|
22
|
+
/** Saves text as a file in the browser (no-op on the server). */
|
|
23
|
+
export declare function downloadText(text: string, filename: string): void;
|
|
24
|
+
export declare function downloadData(data: BlobPart, filename: string, type: string): void;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=csv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv.d.ts","sourceRoot":"","sources":["../src/csv.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAExE,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;AAKpE;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,SAAM,GAAG,MAAM,CAOjE;AAED,qEAAqE;AACrE,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAM1C;AAID,eAAO,MAAM,YAAY,GAAI,GAAG,EAAG,QAAQ,cAAc,CAAC,GAAG,CAAC,WAAyF,CAAC;AACxJ,eAAO,MAAM,WAAW,GAAI,GAAG,EAAG,QAAQ,cAAc,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,KAAG,SAC+B,CAAC;AAG1G;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,aAAa,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,OAAO,GAAE,UAAe,GAAG,MAAM,CAY9H;AAED,iEAAiE;AACjE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAEjE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAYjF"}
|