@aseity/igrid-react 0.3.0 → 0.4.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/CHANGELOG.md +31 -0
- package/README.md +4 -2
- package/dist/charts.js +1 -1
- package/dist/echarts-adapter.js +26 -8
- package/dist/images.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14 -6
- package/dist/presentation.d.ts +4 -3
- package/dist/text.js +24 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @aseity/igrid-react
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Prevent text strokes from being clipped in short rows and correct raised text when the font box is taller than the row. Keep visible glyphs inside the row while preserving normal alignment in taller rows.
|
|
8
|
+
- Synchronize the exact engine dependency to `@aseity/igrid-engine@0.4.1`.
|
|
9
|
+
|
|
10
|
+
## 0.4.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- Apply picture cropping and render chart/axis titles, chart blank-display modes
|
|
15
|
+
and visible-data filtering. Report unsupported styling and layout details.
|
|
16
|
+
- Keep worksheet navigation available when the initial or newly selected sheet
|
|
17
|
+
fails. Hosts receive `renderError(error, "sheet")` for these recoverable failures;
|
|
18
|
+
workbook opening failures continue to use `"workbook"`.
|
|
19
|
+
- Export `GridErrorKind`, including the new `"sheet"` member.
|
|
20
|
+
|
|
21
|
+
### Migration
|
|
22
|
+
|
|
23
|
+
Hosts with exhaustive error-kind switches or explicitly typed `renderError`
|
|
24
|
+
callbacks must handle `"sheet"`. Keep the viewer mounted for these errors so users
|
|
25
|
+
can select another worksheet; reserve whole-workbook recovery for `"workbook"`.
|
|
26
|
+
Chart accessible names now include restored titles when present.
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Update the exact engine dependency to `@aseity/igrid-engine@0.4.0` for the XLSX
|
|
31
|
+
compatibility, numeric-formatting, calculation and performance improvements.
|
|
32
|
+
- Preserve existing chart bounds when no rendered axis title needs extra space.
|
|
33
|
+
|
|
3
34
|
## 0.3.0
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ stylesheet imports. The engine is installed as a dependency. Supply a new
|
|
|
18
18
|
`Uint8Array` when opening another file. Licensed under MIT; the source repository
|
|
19
19
|
is currently private.
|
|
20
20
|
|
|
21
|
-
The package contains compiled JavaScript, declarations and styles. `labels` overrides control and accessibility text. `loadingFallback` replaces the opening state. `renderError(error, kind)` replaces caught
|
|
21
|
+
The package contains compiled JavaScript, declarations and styles. `labels` overrides control and accessibility text. `loadingFallback` replaces the opening state. `renderError(error, kind)` replaces caught errors. The exported `GridErrorKind` type is `"workbook" | "sheet" | "chart" | "image"`. The demo's Host messages checkbox demonstrates these options. A host error boundary should handle render failures separately.
|
|
22
22
|
|
|
23
23
|
`<IGrid bytes={xlsxBytes} />` opens the saved active visible worksheet and uses each sheet's saved zoom. Hidden and veryHidden sheets stay out of the tab bar. Frozen rows and columns remain fixed while the rest of the sheet scrolls.
|
|
24
24
|
|
|
@@ -32,7 +32,9 @@ A single selected cell, including a merged cell, has an outline without a fill.
|
|
|
32
32
|
|
|
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
|
-
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
|
|
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 worksheet raises an error when accessed. Failure to read the initially selected sheet or a sheet selected later calls `renderError(error, "sheet")` while retaining the worksheet tabs, so the user can return to a healthy sheet. Failure to open the workbook itself calls `renderError(error, "workbook")` without worksheet navigation. Chart and image errors remain local to those objects.
|
|
36
|
+
|
|
37
|
+
When upgrading, add a `"sheet"` branch to exhaustive `kind` switches or explicitly typed callbacks. Treat it as a recoverable sheet failure rather than a reason to discard the whole workbook. Existing callbacks that ignore `kind` continue to work.
|
|
36
38
|
|
|
37
39
|
## CSV preview
|
|
38
40
|
|
package/dist/charts.js
CHANGED
|
@@ -47,5 +47,5 @@ function ChartCanvas({ workbook, chart, pixelRatio, }) {
|
|
|
47
47
|
}, [workbook, chart, pixelRatio]);
|
|
48
48
|
if (error)
|
|
49
49
|
return _jsx(GridError, { error: error, kind: "chart" });
|
|
50
|
-
return (_jsx("div", { ref: element, role: "img", "aria-label": `${labels.chart} ${chart.series.map((series) => series.name).join(", ")}`, style: { width: "100%", height: "100%" } }));
|
|
50
|
+
return (_jsx("div", { ref: element, role: "img", "aria-label": `${labels.chart} ${[chart.title, ...chart.series.map((series) => series.name)].filter(Boolean).join(", ")}`, style: { width: "100%", height: "100%" } }));
|
|
51
51
|
}
|
package/dist/echarts-adapter.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BarChart, LineChart, PieChart } from "echarts/charts";
|
|
2
|
-
import { GridComponent, LegendComponent } from "echarts/components";
|
|
2
|
+
import { GridComponent, LegendComponent, TitleComponent, } from "echarts/components";
|
|
3
3
|
import { init, use } from "echarts/core";
|
|
4
4
|
import { CanvasRenderer } from "echarts/renderers";
|
|
5
5
|
use([
|
|
@@ -8,6 +8,7 @@ use([
|
|
|
8
8
|
PieChart,
|
|
9
9
|
GridComponent,
|
|
10
10
|
LegendComponent,
|
|
11
|
+
TitleComponent,
|
|
11
12
|
CanvasRenderer,
|
|
12
13
|
]);
|
|
13
14
|
export function renderChart(element, chart, formatNumber, pixelRatio) {
|
|
@@ -23,11 +24,19 @@ function options(chart, formatNumber) {
|
|
|
23
24
|
const verticalLegend = position === "left" || position === "right";
|
|
24
25
|
const pie = chart.kind === "pie";
|
|
25
26
|
const horizontal = chart.kind === "bar";
|
|
26
|
-
const
|
|
27
|
+
const titleSpace = chart.title && !chart.title_overlay
|
|
28
|
+
? 28 * chart.title.split("\n").length
|
|
29
|
+
: 0;
|
|
30
|
+
const isCategory = (kind) => kind === "category" || kind === "date";
|
|
31
|
+
const isHorizontal = (kind) => isCategory(kind) !== horizontal;
|
|
27
32
|
const axis = (direction) => chart.axes
|
|
33
|
+
.filter((axis) => axis.kind !== "series")
|
|
28
34
|
.filter((axis) => isHorizontal(axis.kind) === (direction === "x"))
|
|
29
35
|
.map((axis) => ({
|
|
30
|
-
|
|
36
|
+
name: axis.title ?? "",
|
|
37
|
+
nameLocation: "middle",
|
|
38
|
+
nameGap: isHorizontal(axis.kind) ? 30 : 45,
|
|
39
|
+
type: isCategory(axis.kind) ? "category" : "value",
|
|
31
40
|
position: isHorizontal(axis.kind)
|
|
32
41
|
? axis.position === "top"
|
|
33
42
|
? "top"
|
|
@@ -35,8 +44,8 @@ function options(chart, formatNumber) {
|
|
|
35
44
|
: axis.position === "right"
|
|
36
45
|
? "right"
|
|
37
46
|
: "left",
|
|
38
|
-
data: axis.kind
|
|
39
|
-
boundaryGap: axis.kind
|
|
47
|
+
data: isCategory(axis.kind) ? chart.series[0]?.categories : undefined,
|
|
48
|
+
boundaryGap: isCategory(axis.kind) ? true : undefined,
|
|
40
49
|
splitNumber: 10,
|
|
41
50
|
axisLabel: {
|
|
42
51
|
color: "#595959",
|
|
@@ -65,6 +74,12 @@ function options(chart, formatNumber) {
|
|
|
65
74
|
},
|
|
66
75
|
}));
|
|
67
76
|
return {
|
|
77
|
+
title: {
|
|
78
|
+
text: chart.title ?? "",
|
|
79
|
+
left: "center",
|
|
80
|
+
top: 6,
|
|
81
|
+
textStyle: { fontSize: 16, fontWeight: "normal" },
|
|
82
|
+
},
|
|
68
83
|
animation: false,
|
|
69
84
|
backgroundColor: "#ffffff",
|
|
70
85
|
textStyle: { fontFamily: "Calibri, Arial, sans-serif", color: "#595959" },
|
|
@@ -76,7 +91,7 @@ function options(chart, formatNumber) {
|
|
|
76
91
|
? chart.series[0]?.categories
|
|
77
92
|
: chart.series.map((series) => series.name),
|
|
78
93
|
[position || "right"]: 6,
|
|
79
|
-
...(position === "top" ? { top: 6 } : {}),
|
|
94
|
+
...(position === "top" ? { top: 6 + titleSpace } : {}),
|
|
80
95
|
...(verticalLegend ? { top: "middle" } : { left: "center" }),
|
|
81
96
|
textStyle: { color: "#595959", fontSize: 12 },
|
|
82
97
|
itemWidth: 24,
|
|
@@ -86,10 +101,12 @@ function options(chart, formatNumber) {
|
|
|
86
101
|
grid: {
|
|
87
102
|
left: position === "left" ? Math.min(chart.rectangle.width * 0.3, 120) : 12,
|
|
88
103
|
right: position === "right" ? Math.min(chart.rectangle.width * 0.3, 120) : 18,
|
|
89
|
-
top: 12 + (position === "top" ? 25 : 0),
|
|
104
|
+
top: 12 + titleSpace + (position === "top" ? 25 : 0),
|
|
90
105
|
bottom: position === "bottom" ? 36 : 12,
|
|
91
106
|
outerBoundsMode: "same",
|
|
92
|
-
outerBoundsContain: "
|
|
107
|
+
outerBoundsContain: chart.axes.some((axis) => axis.kind !== "series" && axis.title)
|
|
108
|
+
? "all"
|
|
109
|
+
: "axisLabel",
|
|
93
110
|
outerBoundsClampWidth: 0,
|
|
94
111
|
outerBoundsClampHeight: 0,
|
|
95
112
|
},
|
|
@@ -116,6 +133,7 @@ function options(chart, formatNumber) {
|
|
|
116
133
|
type: chart.kind === "line" ? "line" : "bar",
|
|
117
134
|
silent: true,
|
|
118
135
|
emphasis: { disabled: true },
|
|
136
|
+
connectNulls: chart.display_blanks_as === "span",
|
|
119
137
|
showSymbol: false,
|
|
120
138
|
symbol: "none",
|
|
121
139
|
lineStyle: { color: series.color, width: 3, type: "solid" },
|
package/dist/images.js
CHANGED
|
@@ -32,7 +32,8 @@ function Picture({ image, view, }) {
|
|
|
32
32
|
return;
|
|
33
33
|
element.width = Math.round(image.rectangle.width * view.dpr);
|
|
34
34
|
element.height = Math.round(image.rectangle.height * view.dpr);
|
|
35
|
-
|
|
35
|
+
const crop = image.crop ?? { left: 0, top: 0, right: 0, bottom: 0 };
|
|
36
|
+
context.drawImage(bitmap, crop.left * bitmap.width, crop.top * bitmap.height, (1 - crop.left - crop.right) * bitmap.width, (1 - crop.top - crop.bottom) * bitmap.height, 0, 0, element.width, element.height);
|
|
36
37
|
})
|
|
37
38
|
.catch((cause) => {
|
|
38
39
|
if (!cancelled)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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 { GridErrorKind } from "./presentation.js";
|
|
4
5
|
export type WorkbookFormat = "xlsx" | "csv";
|
|
5
6
|
export type IGridProps = IGridPresentation & {
|
|
6
7
|
bytes: Uint8Array;
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ function WorkbookView({ bytes, format = "xlsx", onLosses, zoom, onZoomChange, })
|
|
|
12
12
|
const [workbook, setWorkbook] = useState();
|
|
13
13
|
const [workbookVersion, setWorkbookVersion] = useState(0);
|
|
14
14
|
const [error, setError] = useState("");
|
|
15
|
+
const [sheetError, setSheetError] = useState("");
|
|
15
16
|
const [sheetZoom, setSheetZoom] = useState({});
|
|
16
17
|
const [sheet, setSheet] = useState(0);
|
|
17
18
|
useEffect(() => {
|
|
@@ -19,6 +20,7 @@ function WorkbookView({ bytes, format = "xlsx", onLosses, zoom, onZoomChange, })
|
|
|
19
20
|
let opened;
|
|
20
21
|
setWorkbook(undefined);
|
|
21
22
|
setError("");
|
|
23
|
+
setSheetError("");
|
|
22
24
|
setSheet(0);
|
|
23
25
|
setSheetZoom({});
|
|
24
26
|
(format === "csv" ? loadCsv(bytes) : load(bytes))
|
|
@@ -31,8 +33,13 @@ function WorkbookView({ bytes, format = "xlsx", onLosses, zoom, onZoomChange, })
|
|
|
31
33
|
const active = result.sheets[result.activeTab]?.visibility === "visible"
|
|
32
34
|
? result.activeTab
|
|
33
35
|
: result.sheets.findIndex((info) => info.visibility === "visible");
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
try {
|
|
37
|
+
result.view(Math.max(0, active));
|
|
38
|
+
result.charts(Math.max(0, active));
|
|
39
|
+
}
|
|
40
|
+
catch (cause) {
|
|
41
|
+
setSheetError(cause instanceof Error ? cause.message : String(cause));
|
|
42
|
+
}
|
|
36
43
|
setSheet(Math.max(0, active));
|
|
37
44
|
setWorkbookVersion((version) => version + 1);
|
|
38
45
|
setWorkbook(result);
|
|
@@ -53,23 +60,24 @@ function WorkbookView({ bytes, format = "xlsx", onLosses, zoom, onZoomChange, })
|
|
|
53
60
|
return _jsx(GridError, { error: error, kind: "workbook" });
|
|
54
61
|
if (!workbook)
|
|
55
62
|
return loadingFallback ?? _jsx("output", { children: "Loading workbook\u2026" });
|
|
56
|
-
const scale = zoom ?? sheetZoom[sheet] ?? workbook.view(sheet).zoom;
|
|
63
|
+
const scale = zoom ?? sheetZoom[sheet] ?? (sheetError ? 1 : workbook.view(sheet).zoom);
|
|
57
64
|
const changeSheet = (index) => {
|
|
65
|
+
setSheet(index);
|
|
66
|
+
setSheetError("");
|
|
58
67
|
try {
|
|
59
68
|
workbook.view(index);
|
|
60
69
|
workbook.charts(index);
|
|
61
|
-
setSheet(index);
|
|
62
70
|
onLosses?.(workbook.losses);
|
|
63
71
|
}
|
|
64
72
|
catch (cause) {
|
|
65
|
-
|
|
73
|
+
setSheetError(cause instanceof Error ? cause.message : String(cause));
|
|
66
74
|
}
|
|
67
75
|
};
|
|
68
76
|
const changeZoom = (value) => {
|
|
69
77
|
setSheetZoom((previous) => ({ ...previous, [sheet]: value }));
|
|
70
78
|
onZoomChange?.(value);
|
|
71
79
|
};
|
|
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) => {
|
|
80
|
+
return (_jsxs("div", { className: "igrid", children: [sheetError ? (_jsx(GridError, { error: sheetError, kind: "sheet" })) : (_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) => {
|
|
73
81
|
const value = event.currentTarget.valueAsNumber;
|
|
74
82
|
if (Number.isFinite(value) && value >= 10 && value <= 400)
|
|
75
83
|
changeZoom(value / 100);
|
package/dist/presentation.d.ts
CHANGED
|
@@ -11,10 +11,11 @@ export declare const defaultLabels: {
|
|
|
11
11
|
resizeColumn: string;
|
|
12
12
|
unsupportedChart: string;
|
|
13
13
|
};
|
|
14
|
+
export type GridErrorKind = "workbook" | "sheet" | "chart" | "image";
|
|
14
15
|
export type IGridPresentation = {
|
|
15
16
|
labels?: Partial<typeof defaultLabels>;
|
|
16
17
|
loadingFallback?: ReactNode;
|
|
17
|
-
renderError?: (error: unknown, kind:
|
|
18
|
+
renderError?: (error: unknown, kind: GridErrorKind) => ReactNode;
|
|
18
19
|
};
|
|
19
20
|
export declare const PresentationContext: import("react").Context<IGridPresentation>;
|
|
20
21
|
export declare function useGridPresentation(): {
|
|
@@ -31,9 +32,9 @@ export declare function useGridPresentation(): {
|
|
|
31
32
|
unsupportedChart: string;
|
|
32
33
|
};
|
|
33
34
|
loadingFallback?: ReactNode;
|
|
34
|
-
renderError?: (error: unknown, kind:
|
|
35
|
+
renderError?: (error: unknown, kind: GridErrorKind) => ReactNode;
|
|
35
36
|
};
|
|
36
37
|
export declare function GridError({ error, kind, }: {
|
|
37
38
|
error: unknown;
|
|
38
|
-
kind:
|
|
39
|
+
kind: GridErrorKind;
|
|
39
40
|
}): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
package/dist/text.js
CHANGED
|
@@ -35,10 +35,32 @@ export function drawText(context, list, index) {
|
|
|
35
35
|
: vertical === 1
|
|
36
36
|
? y + (height - blockHeight) / 2
|
|
37
37
|
: y + height - blockHeight - 1;
|
|
38
|
+
let firstBaseline = top + ascent;
|
|
39
|
+
if (blockHeight > height - 2) {
|
|
40
|
+
const ink = lines.flatMap((line, lineIndex) => line
|
|
41
|
+
.filter((segment) => !segment.spacing && segment.text.trim())
|
|
42
|
+
.map((segment) => {
|
|
43
|
+
context.font = segment.font;
|
|
44
|
+
const metrics = context.measureText(segment.text);
|
|
45
|
+
return {
|
|
46
|
+
top: lineIndex * lineHeight - metrics.actualBoundingBoxAscent,
|
|
47
|
+
bottom: lineIndex * lineHeight + metrics.actualBoundingBoxDescent,
|
|
48
|
+
};
|
|
49
|
+
}));
|
|
50
|
+
if (ink.length) {
|
|
51
|
+
const inkTop = Math.min(...ink.map((bounds) => bounds.top));
|
|
52
|
+
const inkBottom = Math.max(...ink.map((bounds) => bounds.bottom));
|
|
53
|
+
const spare = height - (inkBottom - inkTop);
|
|
54
|
+
if (spare >= 0) {
|
|
55
|
+
const inset = Math.min(1, spare / 2);
|
|
56
|
+
firstBaseline = Math.max(y + inset - inkTop, Math.min(firstBaseline, y + height - inset - inkBottom));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
38
60
|
const [left, right] = list.text_bounds.subarray(index * 2, index * 2 + 2);
|
|
39
61
|
context.save();
|
|
40
62
|
context.beginPath();
|
|
41
|
-
context.rect(left + 1, y
|
|
63
|
+
context.rect(left + 1, y, Math.max(0, right - left - 2), Math.max(0, height));
|
|
42
64
|
context.clip();
|
|
43
65
|
context.textAlign = "left";
|
|
44
66
|
context.textBaseline = "alphabetic";
|
|
@@ -49,7 +71,7 @@ export function drawText(context, list, index) {
|
|
|
49
71
|
: horizontal === 2
|
|
50
72
|
? x + (width - lineWidth) / 2
|
|
51
73
|
: x + padding;
|
|
52
|
-
const baseline =
|
|
74
|
+
const baseline = firstBaseline + lineIndex * lineHeight;
|
|
53
75
|
for (const segment of line) {
|
|
54
76
|
context.font = segment.font;
|
|
55
77
|
context.fillStyle = segment.color;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aseity/igrid-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
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.
|
|
14
|
+
"@aseity/igrid-engine": "0.4.1",
|
|
15
15
|
"echarts": "6.1.0"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|