bo-grid 0.25.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -17
- package/dist/{bo-grid.FilterMenu-BHI6rILc.js → bo-grid.FilterMenu-BBxlxrnZ.js} +1 -1
- package/dist/{bo-grid.ToolPanel-C3u-4YKc.js → bo-grid.ToolPanel-CCBi982x.js} +1 -1
- package/dist/bo-grid.element-BZGnfKB_.js +6898 -0
- package/dist/bo-grid.element.d.ts +17 -0
- package/dist/bo-grid.element.js +3 -2
- package/dist/grid/Cell.svelte +61 -9
- package/dist/grid/Grid.svelte +213 -19
- package/dist/grid/Grid.svelte.d.ts +21 -1
- package/dist/grid/Pager.svelte +45 -0
- package/dist/grid/Pager.svelte.d.ts +3 -0
- package/dist/grid/column.d.ts +36 -3
- package/dist/grid/column.js +17 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +0 -1
- package/package.json +3 -2
- package/dist/bo-grid.element-DPnHUXMa.js +0 -6623
package/dist/grid/Pager.svelte
CHANGED
|
@@ -6,12 +6,20 @@
|
|
|
6
6
|
pageCount,
|
|
7
7
|
total,
|
|
8
8
|
onGoto,
|
|
9
|
+
pageSize,
|
|
10
|
+
pageSizeOptions,
|
|
11
|
+
onPageSize,
|
|
9
12
|
}: {
|
|
10
13
|
page: number;
|
|
11
14
|
pageCount: number;
|
|
12
15
|
total: number;
|
|
13
16
|
onGoto: (page: number) => void;
|
|
17
|
+
pageSize?: number;
|
|
18
|
+
pageSizeOptions?: number[];
|
|
19
|
+
onPageSize?: (size: number) => void;
|
|
14
20
|
} = $props();
|
|
21
|
+
|
|
22
|
+
const showSizes = $derived(!!pageSizeOptions && pageSizeOptions.length > 0);
|
|
15
23
|
</script>
|
|
16
24
|
|
|
17
25
|
<div class="pager" role="navigation" aria-label="Pagination">
|
|
@@ -20,6 +28,20 @@
|
|
|
20
28
|
<span class="pageinfo">Page {page + 1} of {pageCount} · {total.toLocaleString()} rows</span>
|
|
21
29
|
<button type="button" class="pg" disabled={page >= pageCount - 1} onclick={() => onGoto(page + 1)}>Next ›</button>
|
|
22
30
|
<button type="button" class="pg" disabled={page >= pageCount - 1} aria-label="Last page" onclick={() => onGoto(pageCount - 1)}>»</button>
|
|
31
|
+
{#if showSizes}
|
|
32
|
+
<label class="pgsize">
|
|
33
|
+
Rows
|
|
34
|
+
<select
|
|
35
|
+
aria-label="Rows per page"
|
|
36
|
+
value={pageSize}
|
|
37
|
+
onchange={(e) => onPageSize?.(Number((e.currentTarget as HTMLSelectElement).value))}
|
|
38
|
+
>
|
|
39
|
+
{#each pageSizeOptions as opt (opt)}
|
|
40
|
+
<option value={opt}>{opt}</option>
|
|
41
|
+
{/each}
|
|
42
|
+
</select>
|
|
43
|
+
</label>
|
|
44
|
+
{/if}
|
|
23
45
|
</div>
|
|
24
46
|
|
|
25
47
|
<style>
|
|
@@ -60,4 +82,27 @@
|
|
|
60
82
|
color: var(--bo-text-dim);
|
|
61
83
|
font-variant-numeric: tabular-nums;
|
|
62
84
|
}
|
|
85
|
+
.pgsize {
|
|
86
|
+
display: inline-flex;
|
|
87
|
+
align-items: center;
|
|
88
|
+
gap: 5px;
|
|
89
|
+
margin-left: auto;
|
|
90
|
+
font-family: var(--bo-mono);
|
|
91
|
+
font-size: 11px;
|
|
92
|
+
color: var(--bo-text-dim);
|
|
93
|
+
}
|
|
94
|
+
.pgsize select {
|
|
95
|
+
font: inherit;
|
|
96
|
+
font-size: 11px;
|
|
97
|
+
color: var(--bo-text);
|
|
98
|
+
background: transparent;
|
|
99
|
+
border: 0.5px solid var(--bo-border);
|
|
100
|
+
border-radius: 6px;
|
|
101
|
+
padding: 2px 4px;
|
|
102
|
+
cursor: pointer;
|
|
103
|
+
}
|
|
104
|
+
.pgsize select:focus-visible {
|
|
105
|
+
outline: 2px solid var(--bo-sel-border);
|
|
106
|
+
outline-offset: 1px;
|
|
107
|
+
}
|
|
63
108
|
</style>
|
|
@@ -3,6 +3,9 @@ type $$ComponentProps = {
|
|
|
3
3
|
pageCount: number;
|
|
4
4
|
total: number;
|
|
5
5
|
onGoto: (page: number) => void;
|
|
6
|
+
pageSize?: number;
|
|
7
|
+
pageSizeOptions?: number[];
|
|
8
|
+
onPageSize?: (size: number) => void;
|
|
6
9
|
};
|
|
7
10
|
declare const Pager: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
11
|
type Pager = ReturnType<typeof Pager>;
|
package/dist/grid/column.d.ts
CHANGED
|
@@ -28,6 +28,13 @@ interface ColBase {
|
|
|
28
28
|
cellClass?: string | ((value: unknown, row: GridRow) => string | undefined);
|
|
29
29
|
/** Extra class(es) for this column's header. Target via `:global`. */
|
|
30
30
|
headerClass?: string;
|
|
31
|
+
/** Show a styled tooltip on the column header (the same themed bubble as cell
|
|
32
|
+
`tooltip`) — describe what the column means, units, caveats. Hovering
|
|
33
|
+
anywhere on the header reveals it. */
|
|
34
|
+
headerTooltip?: string;
|
|
35
|
+
/** Render a small ⓘ info icon in the header as a visible cue that a
|
|
36
|
+
`headerTooltip` is available. Ignored without `headerTooltip`. */
|
|
37
|
+
headerInfo?: boolean;
|
|
31
38
|
/** Amber flash on value change (drives off the row's flashSeq/flashDir). */
|
|
32
39
|
flash?: boolean;
|
|
33
40
|
/** Set false to disable header-click sorting on this column. */
|
|
@@ -48,13 +55,26 @@ interface ColBase {
|
|
|
48
55
|
/** Editable choices: when set, editing renders a `<select>` of these options
|
|
49
56
|
instead of a text input (enum/status columns). */
|
|
50
57
|
options?: string[];
|
|
51
|
-
/**
|
|
52
|
-
when content
|
|
53
|
-
|
|
58
|
+
/** Show a styled floating tooltip on each cell (themed, instant — replaces the
|
|
59
|
+
native `title`). `true` shows the full formatted value (handy when content
|
|
60
|
+
truncates); a function returns custom text per value/row (any column type,
|
|
61
|
+
including `custom`). Return '' to suppress for a given cell. */
|
|
62
|
+
tooltip?: boolean | ((value: unknown, row: GridRow) => string);
|
|
63
|
+
/** Let long content wrap to multiple lines instead of truncating with an
|
|
64
|
+
ellipsis. Pair with a taller `rowHeight`. Default false (single-line +
|
|
65
|
+
ellipsis). */
|
|
66
|
+
wrap?: boolean;
|
|
54
67
|
/** Custom display formatter, overriding the built-in type formatter. Applies
|
|
55
68
|
to display, tooltip, copy and (formatted) export. `row` is absent for
|
|
56
69
|
aggregate cells. */
|
|
57
70
|
format?: (value: unknown, row?: GridRow) => string;
|
|
71
|
+
/** JS cell renderer — the framework-agnostic alternative to the `cell`
|
|
72
|
+
snippet, for React/Vue/vanilla (and the `<bo-grid>` web component). Return
|
|
73
|
+
an `HTMLElement`/`Node` (safe — appended as-is) or an HTML **string**
|
|
74
|
+
(inserted as innerHTML — YOU must sanitize any untrusted data; prefer
|
|
75
|
+
returning a Node for that). Overrides the cell's display only — sort,
|
|
76
|
+
filter, tooltip, copy and export still use the value/`format`. */
|
|
77
|
+
render?: (ctx: CellRenderContext) => string | Node | null | undefined;
|
|
58
78
|
/** Set false to disable drag-to-resize on this column (default on). */
|
|
59
79
|
resizable?: boolean;
|
|
60
80
|
/** Parent header label. Consecutive columns sharing a `group` render under a
|
|
@@ -117,6 +137,12 @@ export interface DataBarGeom {
|
|
|
117
137
|
/** The value is negative (use the bar's `negative` colour). */
|
|
118
138
|
negative: boolean;
|
|
119
139
|
}
|
|
140
|
+
/** Context passed to a column's JS `render` hook. */
|
|
141
|
+
export interface CellRenderContext {
|
|
142
|
+
value: unknown;
|
|
143
|
+
row: GridRow;
|
|
144
|
+
column: ColumnDef;
|
|
145
|
+
}
|
|
120
146
|
export interface CellEditEvent {
|
|
121
147
|
row: GridRow;
|
|
122
148
|
column: ColumnDef;
|
|
@@ -204,6 +230,13 @@ export interface GridRow {
|
|
|
204
230
|
*/
|
|
205
231
|
export declare function cellValue(col: ColumnDef, row: GridRow): unknown;
|
|
206
232
|
export declare function formatCell(col: ColumnDef, value: unknown, row?: GridRow): string;
|
|
233
|
+
/**
|
|
234
|
+
* Resolve a cell's tooltip text for the styled floating tooltip. A boolean
|
|
235
|
+
* `tooltip` shows the formatted value (skipped for sparkline/custom — no text
|
|
236
|
+
* form); a function returns custom text for any column type. Empty/whitespace →
|
|
237
|
+
* no tooltip. Pure; unit-tested.
|
|
238
|
+
*/
|
|
239
|
+
export declare function tooltipText(col: ColumnDef, value: unknown, row: GridRow): string | undefined;
|
|
207
240
|
export declare function isSortable(col: ColumnDef): boolean;
|
|
208
241
|
export declare function isEditable(col: ColumnDef): boolean;
|
|
209
242
|
export declare function compareRows(a: GridRow, b: GridRow, sort: SortState, col?: ColumnDef): number;
|
package/dist/grid/column.js
CHANGED
|
@@ -39,6 +39,23 @@ export function formatCell(col, value, row) {
|
|
|
39
39
|
return value == null ? '' : String(value);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolve a cell's tooltip text for the styled floating tooltip. A boolean
|
|
44
|
+
* `tooltip` shows the formatted value (skipped for sparkline/custom — no text
|
|
45
|
+
* form); a function returns custom text for any column type. Empty/whitespace →
|
|
46
|
+
* no tooltip. Pure; unit-tested.
|
|
47
|
+
*/
|
|
48
|
+
export function tooltipText(col, value, row) {
|
|
49
|
+
const t = col.tooltip;
|
|
50
|
+
if (!t)
|
|
51
|
+
return undefined;
|
|
52
|
+
const text = typeof t === 'function'
|
|
53
|
+
? t(value, row)
|
|
54
|
+
: col.type === 'sparkline' || col.type === 'custom'
|
|
55
|
+
? ''
|
|
56
|
+
: formatCell(col, value, row);
|
|
57
|
+
return text && text.trim() ? text : undefined;
|
|
58
|
+
}
|
|
42
59
|
export function isSortable(col) {
|
|
43
60
|
return col.type !== 'sparkline' && col.sortable !== false;
|
|
44
61
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import type { ComponentProps } from 'svelte';
|
|
2
|
+
import type GridComponent from './grid/Grid.svelte';
|
|
1
3
|
export { default as Grid } from './grid/Grid.svelte';
|
|
2
4
|
export { default as Sparkline } from './sparkline/Sparkline.svelte';
|
|
5
|
+
/** Every `<Grid>` prop, as one object type. Use it to type a config object —
|
|
6
|
+
especially the `<bo-grid>` web component's `config` (see `bo-grid/element`). */
|
|
7
|
+
export type GridProps = ComponentProps<typeof GridComponent>;
|
|
3
8
|
export type { LazyGroup } from './grid/grouping';
|
|
4
|
-
export type { ColumnDef, Align, GridRow, SortDir, SortState, CellEditEvent, BadgeTone, DataBarConfig, IconRule, ColorScaleConfig, } from './grid/column';
|
|
9
|
+
export type { ColumnDef, Align, GridRow, SortDir, SortState, CellEditEvent, CellRenderContext, BadgeTone, DataBarConfig, IconRule, ColorScaleConfig, } from './grid/column';
|
|
5
10
|
export type { AggKind, AggResult } from './grid/aggregate';
|
|
6
11
|
export type { ColumnFilter, FilterKind, TextOp, NumberOp, DateOp } from './grid/filtering';
|
|
7
12
|
export { fmtPrice, fmtPercent, fmtVolume, fmtDate, fmtCurrency, relativeTime } from './format/format';
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
// This surface is intentionally small — every export is a compatibility promise.
|
|
5
5
|
// Internal helpers (layout, sorting, grouping, selection internals) are NOT
|
|
6
6
|
// exported; they can change freely between versions.
|
|
7
|
-
// Components
|
|
8
7
|
export { default as Grid } from './grid/Grid.svelte';
|
|
9
8
|
export { default as Sparkline } from './sparkline/Sparkline.svelte';
|
|
10
9
|
// Value formatters (handy when building custom cell content)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bo-grid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Tiny, fast Svelte 5 data grid: canvas sparklines, batched realtime cell updates, and virtual scrolling. A free, fintech-focused alternative to heavyweight grids.",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"default": "./dist/charts/index.js"
|
|
40
40
|
},
|
|
41
41
|
"./element": {
|
|
42
|
+
"types": "./dist/bo-grid.element.d.ts",
|
|
42
43
|
"default": "./dist/bo-grid.element.js"
|
|
43
44
|
},
|
|
44
45
|
"./package.json": "./package.json"
|
|
@@ -61,7 +62,7 @@
|
|
|
61
62
|
"demo:build": "vite build",
|
|
62
63
|
"pages:build": "vite build --base=/bo-grid/ --outDir demo-dist",
|
|
63
64
|
"preview": "vite preview",
|
|
64
|
-
"package": "svelte-package -i src/lib -o dist && node scripts/clean-dist.mjs && pnpm run build:wc",
|
|
65
|
+
"package": "svelte-package -i src/lib -o dist && node scripts/clean-dist.mjs && pnpm run build:wc && node scripts/emit-element-dts.mjs",
|
|
65
66
|
"build:wc": "vite build --config vite.wc.config.ts",
|
|
66
67
|
"prepublishOnly": "pnpm run package",
|
|
67
68
|
"check": "svelte-check --tsconfig ./tsconfig.json",
|