@aseity/igrid-react 0.1.0 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @aseity/igrid-react
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Update the exact engine dependency to `@aseity/igrid-engine@0.3.0`, adding
8
+ comparison-based conditional formatting and conditional font properties to
9
+ previews, and fixing status colors and overdue highlighting in workbooks
10
+ resaved by LibreOffice.
11
+
12
+ ## 0.2.0
13
+
14
+ ### Minor Changes
15
+
16
+ - Add `<IGrid format="csv" bytes={bytes} />` for CSV previews with the existing
17
+ grid interactions and host-customizable loading and error presentation.
18
+ The default format remains XLSX.
19
+ - Export `WorkbookFormat` for hosts that select between XLSX and CSV.
20
+
21
+ ### Patch Changes
22
+
23
+ - Reset selection and scroll state when replacing a workbook, including loads
24
+ batched by React. Content and format changes reuse the workbook cleanup path.
25
+ - Highlight only actual formulas. CSV values and XLSX text beginning with `=`
26
+ retain plain-text presentation.
27
+ - Update the exact engine dependency to `@aseity/igrid-engine@0.2.0`.
28
+
3
29
  ## 0.1.0
4
30
 
5
31
  ### Minor Changes
package/README.md CHANGED
@@ -33,3 +33,37 @@ A single selected cell, including a merged cell, has an outline without a fill.
33
33
  The read-only formula bar uses a decorative stroked SVG for its function marker, keeping its shape independent of the available text fonts.
34
34
 
35
35
  Worksheets parse on first access. The engine's `workbook.losses` getter contains losses from sheets accessed so far, including required formula/chart dependencies. Read it again after opening another sheet; the React `onLosses` callback updates on sheet changes. A malformed deferred worksheet raises an error when accessed and the demo displays it explicitly.
36
+
37
+ ## CSV preview
38
+
39
+ ```tsx
40
+ const csvBytes = new TextEncoder().encode('id,value\n00123,"hello, world"');
41
+ <div style={{ height: 600 }}><IGrid bytes={csvBytes} format="csv" /></div>
42
+ ```
43
+
44
+ The exported `WorkbookFormat` type is `"xlsx" | "csv"`. `format?: WorkbookFormat` defaults to `"xlsx"`. CSV requires an explicit format;
45
+ invalid XLSX is never treated as CSV. Changing `format` or supplying a new `bytes`
46
+ array releases and replaces the workbook. Unmounting releases it too. Parse errors
47
+ use `renderError(error, "workbook")`; opening valid input clears the error.
48
+
49
+ CSV uses one `Sheet1`, default grid styles and 100% initial zoom. The first row is
50
+ ordinary data. All fields retain their text, including whitespace, leading zeros,
51
+ long integers, date-like values and formula-like text; no formulas are calculated or highlighted. XLSX text cells beginning with `=` also
52
+ remain unhighlighted; real XLSX formulas retain syntax colors.
53
+ Scrolling, selection, keyboard navigation, the formula bar, TSV copying and temporary
54
+ column-width changes are available. CSV editing, export and saving are not supported.
55
+
56
+ Supply UTF-8 bytes, optionally with a leading UTF-8 BOM. Invalid UTF-8 fails;
57
+ convert other encodings in the host before passing bytes. There is no encoding or
58
+ delimiter detection. Comma-separated fields support double-quote enclosing,
59
+ doubled-quote escapes, embedded commas and newlines. LF, CRLF and CR separate rows;
60
+ quoted line breaks retain their original characters. Misplaced or unclosed quotes,
61
+ or characters after a closing quote before a separator, fail the entire load. Errors
62
+ identify CSV record numbers rather than physical lines in multiline fields.
63
+
64
+ Empty or BOM-only input opens an empty sheet. Empty lines create one empty field.
65
+ The final newline does not add a row; consecutive newlines preserve blank rows.
66
+ Trailing commas preserve empty fields. Unequal row widths are accepted and missing
67
+ fields display blank. Input exceeding 1,048,576 rows or 16,384 columns fails without
68
+ truncation. Syntax and size are validated before allocating cells, while retaining
69
+ the UTF-8 input in memory. Parsing is eager on the main thread and keeps the entire sheet in memory.
@@ -1,4 +1,5 @@
1
- export declare function FormulaValue({ value, label, }: {
1
+ export declare function FormulaValue({ value, isFormula, label, }: {
2
2
  value: string;
3
+ isFormula: boolean;
3
4
  label: string;
4
5
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useRef } from "react";
3
3
  const tokens = /(?<string>"(?:[^"]|"")*")|(?<reference>(?:'(?:[^']|'')*'|[\p{L}_][\p{L}\p{N}_.]*)!)|(?<function>[\p{L}_][\p{L}\p{N}_.]*(?=\s*\())|(?<cell>\$?[A-Za-z]{1,3}\$?\d+\b)|(?<number>(?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?%?)|(?<name>[\p{L}_][\p{L}\p{N}_.]*)/gu;
4
- export function FormulaValue({ value, label, }) {
4
+ export function FormulaValue({ value, isFormula, label, }) {
5
5
  const highlight = useRef(null);
6
6
  const parts = [];
7
7
  let start = 0;
8
- if (value.startsWith("=")) {
8
+ if (isFormula) {
9
9
  for (const match of value.matchAll(tokens)) {
10
10
  parts.push(value.slice(start, match.index));
11
11
  const kind = Object.keys(match.groups ?? {}).find((key) => match.groups?.[key] !== undefined);
package/dist/grid.js CHANGED
@@ -128,7 +128,7 @@ export function CanvasGrid({ workbook, sheet, zoom, }) {
128
128
  headerHeight,
129
129
  });
130
130
  }, [lists, panes, view, zoom, headerWidth, headerHeight]);
131
- return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "igrid-formula", children: [_jsx("input", { "aria-label": labels.nameBox, readOnly: true, value: interaction.selection.address }), _jsx("span", { className: "igrid-formula-symbol", "aria-hidden": "true", children: _jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M12 4h-1.5C9 4 8.4 5 8.1 6.5L6.4 17.5C6.2 19 5.5 20 4 20H3M5.5 9H12M14 10l6 8m0-8-6 8" }) }) }), _jsx(FormulaValue, { label: labels.formulaBar, value: interaction.formulaText })] }), _jsxs("div", { className: "igrid-viewport", children: [_jsx("section", { ref: scroll, tabIndex: 0, ...interaction.pointer, onKeyDown: interaction.onKeyDown, onCopy: interaction.onCopy, "aria-label": labels.viewport, style: {
131
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "igrid-formula", children: [_jsx("input", { "aria-label": labels.nameBox, readOnly: true, value: interaction.selection.address }), _jsx("span", { className: "igrid-formula-symbol", "aria-hidden": "true", children: _jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M12 4h-1.5C9 4 8.4 5 8.1 6.5L6.4 17.5C6.2 19 5.5 20 4 20H3M5.5 9H12M14 10l6 8m0-8-6 8" }) }) }), _jsx(FormulaValue, { label: labels.formulaBar, value: interaction.formulaText, isFormula: interaction.isFormula })] }), _jsxs("div", { className: "igrid-viewport", children: [_jsx("section", { ref: scroll, tabIndex: 0, ...interaction.pointer, onKeyDown: interaction.onKeyDown, onCopy: interaction.onCopy, "aria-label": labels.viewport, style: {
132
132
  position: "absolute",
133
133
  inset: 0,
134
134
  overflow: "auto",
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { type RenderingLoss } from "@aseity/igrid-engine";
2
2
  import { type IGridPresentation } from "./presentation.js";
3
3
  import "./style.css";
4
+ export type WorkbookFormat = "xlsx" | "csv";
4
5
  export type IGridProps = IGridPresentation & {
5
6
  bytes: Uint8Array;
7
+ format?: WorkbookFormat;
6
8
  zoom?: number;
7
9
  onZoomChange?: (zoom: number) => void;
8
10
  onLosses?: (losses: RenderingLoss[]) => void;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { load } from "@aseity/igrid-engine";
2
+ import { load, loadCsv, } from "@aseity/igrid-engine";
3
3
  import { useEffect, useState } from "react";
4
4
  import { CanvasGrid } from "./grid.js";
5
5
  import { GridError, PresentationContext, useGridPresentation, } from "./presentation.js";
@@ -7,9 +7,10 @@ import "./style.css";
7
7
  export function IGrid({ labels, loadingFallback, renderError, ...props }) {
8
8
  return (_jsx(PresentationContext.Provider, { value: { labels, loadingFallback, renderError }, children: _jsx(WorkbookView, { ...props }) }));
9
9
  }
10
- function WorkbookView({ bytes, onLosses, zoom, onZoomChange }) {
10
+ function WorkbookView({ bytes, format = "xlsx", onLosses, zoom, onZoomChange, }) {
11
11
  const { labels, loadingFallback } = useGridPresentation();
12
12
  const [workbook, setWorkbook] = useState();
13
+ const [workbookVersion, setWorkbookVersion] = useState(0);
13
14
  const [error, setError] = useState("");
14
15
  const [sheetZoom, setSheetZoom] = useState({});
15
16
  const [sheet, setSheet] = useState(0);
@@ -20,7 +21,7 @@ function WorkbookView({ bytes, onLosses, zoom, onZoomChange }) {
20
21
  setError("");
21
22
  setSheet(0);
22
23
  setSheetZoom({});
23
- load(bytes)
24
+ (format === "csv" ? loadCsv(bytes) : load(bytes))
24
25
  .then((result) => {
25
26
  if (cancelled) {
26
27
  result.dispose();
@@ -33,6 +34,7 @@ function WorkbookView({ bytes, onLosses, zoom, onZoomChange }) {
33
34
  result.view(Math.max(0, active));
34
35
  result.charts(Math.max(0, active));
35
36
  setSheet(Math.max(0, active));
37
+ setWorkbookVersion((version) => version + 1);
36
38
  setWorkbook(result);
37
39
  })
38
40
  .catch((cause) => {
@@ -43,7 +45,7 @@ function WorkbookView({ bytes, onLosses, zoom, onZoomChange }) {
43
45
  cancelled = true;
44
46
  opened?.dispose();
45
47
  };
46
- }, [bytes]);
48
+ }, [bytes, format]);
47
49
  useEffect(() => {
48
50
  onLosses?.(workbook?.losses ?? []);
49
51
  }, [workbook, onLosses]);
@@ -67,7 +69,7 @@ function WorkbookView({ bytes, onLosses, zoom, onZoomChange }) {
67
69
  setSheetZoom((previous) => ({ ...previous, [sheet]: value }));
68
70
  onZoomChange?.(value);
69
71
  };
70
- return (_jsxs("div", { className: "igrid", children: [_jsx(CanvasGrid, { workbook: workbook, sheet: sheet, zoom: Math.min(4, Math.max(0.1, scale)) }, sheet), _jsx("nav", { "aria-label": labels.worksheets, children: workbook.sheets.map((info, index) => info.visibility === "visible" && (_jsx("button", { type: "button", "aria-pressed": index === sheet, onClick: () => changeSheet(index), children: info.name }, info.name))) }), _jsxs("label", { className: "igrid-zoom", children: [labels.zoom, " ", _jsx("input", { "aria-label": labels.zoom, type: "number", min: "10", max: "400", step: "10", value: Math.round(scale * 100), onChange: (event) => {
72
+ return (_jsxs("div", { className: "igrid", children: [_jsx(CanvasGrid, { workbook: workbook, sheet: sheet, zoom: Math.min(4, Math.max(0.1, scale)) }, `${workbookVersion}:${sheet}`), _jsx("nav", { "aria-label": labels.worksheets, children: workbook.sheets.map((info, index) => info.visibility === "visible" && (_jsx("button", { type: "button", "aria-pressed": index === sheet, onClick: () => changeSheet(index), children: info.name }, info.name))) }), _jsxs("label", { className: "igrid-zoom", children: [labels.zoom, " ", _jsx("input", { "aria-label": labels.zoom, type: "number", min: "10", max: "400", step: "10", value: Math.round(scale * 100), onChange: (event) => {
71
73
  const value = event.currentTarget.valueAsNumber;
72
74
  if (Number.isFinite(value) && value >= 10 && value <= 400)
73
75
  changeZoom(value / 100);
@@ -25,6 +25,7 @@ export declare function useSelection(workbook: Workbook, sheet: number, panes: P
25
25
  height: number;
26
26
  };
27
27
  onCopy(event: ClipboardEvent<HTMLElement>): void;
28
+ isFormula: boolean;
28
29
  formulaText: string;
29
30
  onKeyDown(event: KeyboardEvent<HTMLElement>): void;
30
31
  pointer: {
package/dist/selection.js CHANGED
@@ -55,6 +55,7 @@ export function useSelection(workbook, sheet, panes, zoom, headerWidth, headerHe
55
55
  event.preventDefault();
56
56
  event.clipboardData.setData("text/plain", workbook.copySelection(sheet, state.anchor, state.focus, state.mode));
57
57
  },
58
+ isFormula: cell?.formula !== undefined,
58
59
  formulaText: cell?.formula ??
59
60
  (typeof cell?.value === "boolean"
60
61
  ? cell.value
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aseity/igrid-react",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -11,7 +11,7 @@
11
11
  "./styles.css": "./dist/style.css"
12
12
  },
13
13
  "dependencies": {
14
- "@aseity/igrid-engine": "0.1.0",
14
+ "@aseity/igrid-engine": "0.3.0",
15
15
  "echarts": "6.1.0"
16
16
  },
17
17
  "peerDependencies": {
@@ -26,7 +26,7 @@
26
26
  "sideEffects": [
27
27
  "**/*.css"
28
28
  ],
29
- "description": "Read-only React XLSX viewer powered by Rust/WASM and Canvas2D.",
29
+ "description": "Read-only React XLSX and CSV viewer powered by Rust/WASM and Canvas2D.",
30
30
  "license": "MIT",
31
31
  "publishConfig": {
32
32
  "access": "public",