@koeroesi86/canvas-grid 1.0.15 → 26.11.2

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.
Files changed (57) hide show
  1. package/README.md +27 -0
  2. package/build/types/cell-background/index.d.ts +25 -0
  3. package/build/types/cell-value/index.d.ts +21 -0
  4. package/build/types/character/index.d.ts +21 -0
  5. package/build/types/header/index.d.ts +25 -0
  6. package/build/types/rectangle/index.d.ts +12 -0
  7. package/build/types/text/index.d.ts +31 -0
  8. package/build/types/types.d.ts +87 -0
  9. package/build/types/utils/canvas.d.ts +1 -0
  10. package/build/types/utils/collection.d.ts +18 -0
  11. package/build/types/utils/column-store.d.ts +16 -0
  12. package/build/types/utils/data-store.d.ts +49 -0
  13. package/build/types/utils/jsx.d.ts +40 -0
  14. package/build/types/utils/layer.d.ts +26 -0
  15. package/build/types/utils/loading.d.ts +17 -0
  16. package/build/types/utils/lru-cache.d.ts +11 -0
  17. package/build/types/utils/renderer-registry.d.ts +13 -0
  18. package/build/types/utils/renderer.d.ts +26 -0
  19. package/build/types/utils/row-store.d.ts +37 -0
  20. package/build/types/utils/selectors.d.ts +3 -0
  21. package/build/types/web-component.d.ts +189 -0
  22. package/build/web-component.js +1 -732
  23. package/build/web-component.js.map +1 -1
  24. package/build/web-component.mjs +1226 -0
  25. package/build/web-component.mjs.map +1 -0
  26. package/package.json +32 -32
  27. package/.babelrc +0 -14
  28. package/.eslintrc +0 -7
  29. package/.github/CODEOWNERS +0 -1
  30. package/.github/SECURITY.md +0 -9
  31. package/.github/dependabot.yml +0 -11
  32. package/.github/workflows/ci.yml +0 -32
  33. package/.github/workflows/codeql.yml +0 -26
  34. package/.github/workflows/publish.yml +0 -51
  35. package/components/cellBackground/index.jsx +0 -86
  36. package/components/cellValue/index.jsx +0 -80
  37. package/components/character/index.jsx +0 -82
  38. package/components/component.scss +0 -45
  39. package/components/example.js +0 -56
  40. package/components/header/index.jsx +0 -100
  41. package/components/rectangle/index.jsx +0 -65
  42. package/components/text/index.jsx +0 -131
  43. package/components/utils/collection.js +0 -58
  44. package/components/utils/drawingLayer.js +0 -66
  45. package/components/utils/jsx.js +0 -57
  46. package/components/utils/loading.js +0 -58
  47. package/components/utils/renderer.js +0 -45
  48. package/components/utils/selectors.js +0 -13
  49. package/components/web-component.js +0 -582
  50. package/config/htmlGenerator.js +0 -36
  51. package/nodemon.json +0 -5
  52. package/public/index.html +0 -29
  53. package/scripts/build.js +0 -30
  54. package/scripts/dev.js +0 -64
  55. package/server/example.js +0 -59
  56. package/server/exampleServe.js +0 -3
  57. package/webpack.config.js +0 -151
package/README.md CHANGED
@@ -1,3 +1,30 @@
1
1
  # Canvas Grid
2
2
 
3
3
  [![CI](https://github.com/Koeroesi86/canvas-grid/actions/workflows/ci.yml/badge.svg)](https://github.com/Koeroesi86/canvas-grid/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/@koeroesi86/canvas-grid)](https://www.npmjs.com/package/@koeroesi86/canvas-grid)
5
+
6
+ A fast data grid rendered on `<canvas>`, shipped as a framework-agnostic custom element (`<canvas-grid>`). It virtualises rows and columns, flashes cells when their values change, and is built for streams of frequent updates.
7
+
8
+ - Plain web component: no framework required, works with React, Vue, Angular or vanilla JS
9
+ - Written in TypeScript, types included
10
+ - Optional AG Grid-style adapter (`agApi`) for `setRowData` / `updateRowData` / `setColumnDefs`
11
+
12
+ Live demo and feature overview: https://koeroesi86.github.io/canvas-grid/
13
+
14
+ ## Documentation
15
+
16
+ - [Getting started](docs/getting-started.md): install, usage, browser support
17
+ - [API reference](docs/api.md): data model, methods, properties
18
+ - [Sorting](docs/sorting.md)
19
+ - [Custom renderers and layers](docs/renderers.md)
20
+ - [AG Grid-style adapter](docs/ag-grid-adapter.md)
21
+ - [TypeScript](docs/typescript.md)
22
+ - [Development](docs/development.md): scripts, demo site, releases, benchmarks
23
+
24
+ ## Security
25
+
26
+ See [SECURITY.md](.github/SECURITY.md).
27
+
28
+ ## License
29
+
30
+ [MIT](LICENSE)
@@ -0,0 +1,25 @@
1
+ import Renderer from '../utils/renderer';
2
+ import type { CellContext, CellRenderer } from '../types';
3
+ export interface CellBackgroundOptions {
4
+ layer: string;
5
+ enableFlashing: boolean;
6
+ background: string;
7
+ flashInDuration: number;
8
+ flashOutDuration: number;
9
+ flashRGB: string;
10
+ borderRightWidth: number;
11
+ borderRightColor: string;
12
+ borderBottomWidth: number;
13
+ borderBottomColor: string;
14
+ }
15
+ declare class CellBackground extends Renderer<CellBackgroundOptions> implements CellRenderer {
16
+ static readonly defaultOptions: CellBackgroundOptions;
17
+ constructor(options?: Partial<CellBackgroundOptions>);
18
+ get layer(): string;
19
+ /** Cells flash after their value changed, until the flash has faded out. */
20
+ isAnimating({ age }: Readonly<CellContext>): boolean;
21
+ /** Flash opacity for a cell updated `age` ms ago: fades in, then out, then 0. */
22
+ private getFlashAlpha;
23
+ draw({ ctx, x, y, width, height, age }: Readonly<CellContext>): void;
24
+ }
25
+ export default CellBackground;
@@ -0,0 +1,21 @@
1
+ import Renderer from '../utils/renderer';
2
+ import type { CellContext, CellRenderer } from '../types';
3
+ export interface CellValueOptions {
4
+ layer: string;
5
+ font: string;
6
+ color: string;
7
+ }
8
+ export default class CellValueRenderer extends Renderer<CellValueOptions> implements CellRenderer {
9
+ static readonly defaultOptions: CellValueOptions;
10
+ private readonly renderer;
11
+ constructor(options?: Partial<CellValueOptions>);
12
+ get layer(): string;
13
+ set font(font: string);
14
+ get font(): string;
15
+ set color(color: string);
16
+ get color(): string;
17
+ set pixelRatio(pixelRatio: number);
18
+ get pixelRatio(): number;
19
+ clearCache(): void;
20
+ draw({ ctx, x, y, width, height, formatted, valueChanged, forced }: Readonly<CellContext>): void;
21
+ }
@@ -0,0 +1,21 @@
1
+ import { CanvasRenderer } from '../utils/renderer';
2
+ import type { RenderProps } from '../types';
3
+ export interface CharacterOptions {
4
+ font: string;
5
+ color: string;
6
+ alpha: boolean;
7
+ clearBeforeRender: boolean;
8
+ }
9
+ export default class CharacterRenderer extends CanvasRenderer<CharacterOptions> {
10
+ static readonly defaultOptions: CharacterOptions;
11
+ private readonly charWidthCache;
12
+ private readonly canvas;
13
+ private readonly ctx;
14
+ constructor(options?: Partial<CharacterOptions>);
15
+ set font(font: string);
16
+ set color(color: string);
17
+ clearCache(): void;
18
+ protected cacheKey({ value, height }: RenderProps): string;
19
+ getCharacterWidth(character?: string): number;
20
+ render({ value, height }: RenderProps): HTMLCanvasElement;
21
+ }
@@ -0,0 +1,25 @@
1
+ import Renderer from '../utils/renderer';
2
+ import type { CellContext, CellRenderer } from '../types';
3
+ export interface HeaderOptions {
4
+ layer: string;
5
+ background: string;
6
+ font: string;
7
+ color: string;
8
+ borderRightWidth: number;
9
+ borderRightColor: string;
10
+ borderBottomWidth: number;
11
+ borderBottomColor: string;
12
+ }
13
+ declare class HeaderRenderer extends Renderer<HeaderOptions> implements CellRenderer {
14
+ static readonly defaultOptions: HeaderOptions;
15
+ private readonly textRenderer;
16
+ constructor(options?: Partial<HeaderOptions>);
17
+ get layer(): string;
18
+ set font(font: string);
19
+ get font(): string;
20
+ set pixelRatio(pixelRatio: number);
21
+ get pixelRatio(): number;
22
+ clearCache(): void;
23
+ draw({ ctx, x, y, width, height, formatted }: Readonly<CellContext>): void;
24
+ }
25
+ export default HeaderRenderer;
@@ -0,0 +1,12 @@
1
+ export interface RectProps {
2
+ x?: number;
3
+ y?: number;
4
+ width: number;
5
+ height: number;
6
+ color: string;
7
+ /** Opacity from 0 to 1, applied on top of the color. */
8
+ alpha?: number;
9
+ }
10
+ /** Solid rectangle, filled straight onto the target context. */
11
+ declare const Rect: import("../utils/jsx").Component<RectProps>;
12
+ export default Rect;
@@ -0,0 +1,31 @@
1
+ import Renderer from '../utils/renderer';
2
+ import type { RenderProps } from '../types';
3
+ export interface TextOptions {
4
+ ellipsis: string;
5
+ cellPadding: {
6
+ top: number;
7
+ right: number;
8
+ bottom: number;
9
+ left: number;
10
+ };
11
+ font: string;
12
+ color: string;
13
+ isEllipsisRight: boolean;
14
+ }
15
+ declare class TextRenderer extends Renderer<TextOptions> {
16
+ static readonly defaultOptions: TextOptions;
17
+ private readonly characterRenderer;
18
+ constructor(options?: Partial<TextOptions>);
19
+ set font(font: string);
20
+ get font(): string;
21
+ set color(color: string);
22
+ get color(): string;
23
+ set pixelRatio(pixelRatio: number);
24
+ get pixelRatio(): number;
25
+ clearCache(): void;
26
+ getTextWidth(text: string): number;
27
+ /** Draws the text clipped with an ellipsis; `(x, y)` is the offset of the text box from `(originX, originY)`. */
28
+ paint(ctx: CanvasRenderingContext2D, { value, x, y, width, height }: RenderProps, originX: number, originY: number): void;
29
+ readonly element: import("../utils/jsx").Component<RenderProps>;
30
+ }
31
+ export default TextRenderer;
@@ -0,0 +1,87 @@
1
+ export type Key = string | number;
2
+ export type RowId = Key;
3
+ export interface RowInput {
4
+ id: RowId;
5
+ [column: string]: unknown;
6
+ }
7
+ /** A row's position and size; its values live in the column stores, addressed by `slot`. */
8
+ export interface RowData {
9
+ id: RowId;
10
+ /** Position in the displayed (sorted) order. */
11
+ index: number;
12
+ /** Position in the column stores; stable until rows are removed. */
13
+ slot: number;
14
+ height: number;
15
+ }
16
+ export type SortDirection = 'asc' | 'desc';
17
+ export interface SortKey {
18
+ columnId: Key;
19
+ direction?: SortDirection;
20
+ /** Orders two values of the column; defaults to numbers numerically, then text, with empty values last. */
21
+ compare?: (a: unknown, b: unknown) => number;
22
+ }
23
+ /** Props of a drawable element (see utils/jsx); positions are relative to the draw origin. */
24
+ export interface RenderProps {
25
+ value?: string;
26
+ x?: number;
27
+ y?: number;
28
+ width?: number;
29
+ height?: number;
30
+ }
31
+ /** Free-form storage a renderer can keep per cell; it survives between frames. */
32
+ export type CellState = Record<string, unknown>;
33
+ export interface CellRow {
34
+ id: RowId;
35
+ index: number;
36
+ }
37
+ export interface CellColumn {
38
+ id: Key;
39
+ index: number;
40
+ displayName?: string;
41
+ }
42
+ /**
43
+ * Everything a renderer needs to draw one cell, header or row number.
44
+ *
45
+ * One object is reused for every cell, so read what you need while drawing and never keep a reference to it.
46
+ */
47
+ export interface CellContext {
48
+ /** Context of the layer the renderer is registered for. */
49
+ ctx: CanvasRenderingContext2D;
50
+ x: number;
51
+ y: number;
52
+ width: number;
53
+ height: number;
54
+ /** Undefined for headers and placeholder cells. */
55
+ row: CellRow | undefined;
56
+ /** Undefined for row numbers. */
57
+ column: CellColumn | undefined;
58
+ /** Raw value as stored. */
59
+ value: unknown;
60
+ /** Value after the column's `valueFormatter`; this is what the built-in renderers draw. */
61
+ formatted: string;
62
+ /** When the value last changed, in ms since the epoch. */
63
+ updatedAt: number | undefined;
64
+ /** Milliseconds since `updatedAt`; Infinity when the value never changed. */
65
+ age: number;
66
+ /** Timestamp of the current frame. */
67
+ now: number;
68
+ /** Milliseconds since the previous frame. */
69
+ dt: number;
70
+ /** The formatted value differs from what was drawn last time. */
71
+ valueChanged: boolean;
72
+ /** Everything has to be redrawn: first draw, resize or scrolling. */
73
+ forced: boolean;
74
+ isScrolling: boolean;
75
+ state: CellState;
76
+ }
77
+ /** Draws into one named layer. Register it with `grid.registerRenderer` and select it per column. */
78
+ export interface CellRenderer {
79
+ /** Name of the layer `ctx` belongs to. */
80
+ readonly layer: string;
81
+ draw(cell: Readonly<CellContext>): void;
82
+ /** Return true while the cell is animating; it is redrawn every frame, plus once more after it stops. */
83
+ isAnimating?(cell: Readonly<CellContext>): boolean;
84
+ clearCache?(): void;
85
+ }
86
+ /** A renderer, or the name it was registered under. */
87
+ export type RendererRef = string | CellRenderer;
@@ -0,0 +1 @@
1
+ export declare const getContext2d: (canvas: HTMLCanvasElement, options?: CanvasRenderingContext2DSettings) => CanvasRenderingContext2D;
@@ -0,0 +1,18 @@
1
+ import type { Key } from '../types';
2
+ /**
3
+ * Insertion-ordered map. Keys are compared as strings (1 and '1' are the same entry),
4
+ * and every operation is O(1) apart from iteration.
5
+ */
6
+ declare class Collection<T> {
7
+ private entries;
8
+ constructor();
9
+ get keys(): Key[];
10
+ get(key: Key): T | undefined;
11
+ set(key: Key, value: T): void;
12
+ add(value: T): void;
13
+ delete(key: Key): void;
14
+ clear(matcher?: (item: T, key: Key) => boolean): void;
15
+ forEach(fn: (item: T, key: Key) => void): void;
16
+ get length(): number;
17
+ }
18
+ export default Collection;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Values of one column for all rows, indexed by row slot. Two flat arrays instead of an object per cell.
3
+ * `undefined` means the row has no value in this column.
4
+ */
5
+ declare class ColumnStore {
6
+ values: unknown[];
7
+ /** When each value last changed, 0 when unknown; only allocated once a value changes after loading. */
8
+ private updatedAt;
9
+ constructor(length?: number);
10
+ get(slot: number): unknown;
11
+ getUpdatedAt(slot: number): number | undefined;
12
+ set(slot: number, value: unknown, updatedAt?: number): void;
13
+ /** Drops the values of the given slots (ascending) and shifts the following ones down. */
14
+ removeSlots(slots: readonly number[]): void;
15
+ }
16
+ export default ColumnStore;
@@ -0,0 +1,49 @@
1
+ import ColumnStore from './column-store';
2
+ import RowStore from './row-store';
3
+ import type { Key, RowId, RowInput, SortKey } from '../types';
4
+ export type RowIdGetter = (row: RowInput, index?: number) => RowId;
5
+ export interface DataStoreEnvironment {
6
+ getRowId: RowIdGetter;
7
+ getCellHeight: () => number;
8
+ }
9
+ /** Numbers numerically, then text, then anything else as text; empty values sort last. */
10
+ export declare const compareValues: (a: unknown, b: unknown) => number;
11
+ /**
12
+ * Cell values stored by column (one array per column, addressed by the row's slot) plus the row order,
13
+ * with the queued add/update/remove handling and the sort model. Independent of the DOM.
14
+ */
15
+ declare class DataStore {
16
+ rows: RowStore;
17
+ columns: Map<string, ColumnStore>;
18
+ /** Queued changes, applied in the order they were made. */
19
+ private pending;
20
+ private sortModel;
21
+ private sortDirty;
22
+ private environment;
23
+ constructor(environment: DataStoreEnvironment);
24
+ get hasPending(): boolean;
25
+ getSortModel(): readonly SortKey[];
26
+ /** Orders the rows by the given columns, in priority order; an empty model restores the insertion order. */
27
+ setSortModel(model: readonly SortKey[]): void;
28
+ /** Value of a cell, `undefined` when the row has none. */
29
+ getValue(rowId: RowId, columnKey: Key): unknown;
30
+ getUpdatedAt(rowId: RowId, columnKey: Key): number | undefined;
31
+ queueUpdate(row: RowInput): void;
32
+ queueRemove(row: RowInput): void;
33
+ clear(): void;
34
+ /** Replaces everything, dropping any queued changes. */
35
+ setRows(data: RowInput[]): void;
36
+ /**
37
+ * Applies the queued changes in the order they were queued; consecutive removals are applied together.
38
+ * Returns whether rows changed position (removed or re-sorted), which needs the whole grid to be redrawn.
39
+ */
40
+ flush(now?: number): boolean;
41
+ private column;
42
+ private addRow;
43
+ private removeRows;
44
+ private applyUpdate;
45
+ private applyValue;
46
+ private markSortDirty;
47
+ private sort;
48
+ }
49
+ export default DataStore;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Minimal declarative layer over the canvas 2D API.
3
+ *
4
+ * `<Group>` and friends do not draw when evaluated. They build a light tree of nodes, and calling
5
+ * `node.draw(ctx, x, y)` paints it, with `(x, y)` as the origin that child positions are relative to.
6
+ * Nothing is rasterized to an intermediate canvas unless a component opts into bitmap caching.
7
+ */
8
+ export interface VNode {
9
+ draw(ctx: CanvasRenderingContext2D, x: number, y: number): void;
10
+ }
11
+ /** `false`, `null` and `undefined` are skipped, so `{condition && <Rect />}` works. */
12
+ export type Child = VNode | false | null | undefined;
13
+ export type Children = Child | readonly Child[];
14
+ export interface ChildrenProps {
15
+ /** A single child, an array of them, or the mix of both that JSX produces for several children. */
16
+ children?: Children | readonly Children[];
17
+ }
18
+ export type Component<Props extends object> = (props: Props) => VNode;
19
+ declare global {
20
+ namespace JSX {
21
+ type Element = VNode;
22
+ interface ElementChildrenAttribute {
23
+ children: unknown;
24
+ }
25
+ interface IntrinsicElements {
26
+ }
27
+ }
28
+ }
29
+ /** Wraps a paint function into a leaf component; positions in `props` are relative to the draw origin. */
30
+ export declare const primitive: <Props extends object>(paint: (ctx: CanvasRenderingContext2D, props: Props, x: number, y: number) => void) => Component<Props>;
31
+ export interface GroupProps extends ChildrenProps {
32
+ x?: number;
33
+ y?: number;
34
+ }
35
+ /** Draws its children relative to its own offset. */
36
+ export declare const Group: Component<GroupProps>;
37
+ declare const React: {
38
+ createElement<Props extends object>(component: Component<Props & ChildrenProps>, props: Props | null, ...children: Children[]): VNode;
39
+ };
40
+ export default React;
@@ -0,0 +1,26 @@
1
+ export interface LayerOptions {
2
+ /** Transparent canvas. Opaque layers (`false`) draw faster; keep the bottom layer opaque. */
3
+ alpha?: boolean;
4
+ /** Lets the browser present frames without syncing to the compositor: lower latency, but may tear. Off by default. */
5
+ desynchronized?: boolean;
6
+ /** Name of an existing layer to stack this one below; defaults to the top. */
7
+ before?: string;
8
+ }
9
+ /** A named canvas stacked in the grid; renderers draw into its context. */
10
+ declare class Layer {
11
+ readonly name: string;
12
+ readonly canvas: HTMLCanvasElement;
13
+ readonly ctx: CanvasRenderingContext2D;
14
+ constructor(name: string, { alpha, desynchronized }?: Pick<LayerOptions, 'alpha' | 'desynchronized'>);
15
+ /** Size in CSS pixels; the backing store is `pixelRatio` times larger. */
16
+ width: number;
17
+ height: number;
18
+ pixelRatio: number;
19
+ /**
20
+ * Resizes the canvas, scaling the context so renderers keep drawing in CSS pixels.
21
+ * Returns false, leaving the canvas untouched, when nothing changed (assigning a size clears the canvas).
22
+ */
23
+ resize(width: number, height: number, pixelRatio?: number): boolean;
24
+ clear(): void;
25
+ }
26
+ export default Layer;
@@ -0,0 +1,17 @@
1
+ import Renderer from './renderer';
2
+ interface LoadingOptions {
3
+ ctx: CanvasRenderingContext2D;
4
+ }
5
+ declare class Loading extends Renderer<LoadingOptions> {
6
+ private readonly ctx;
7
+ private readonly offCanvas;
8
+ private readonly offCtx;
9
+ private rotation;
10
+ private readonly speed;
11
+ private readonly count;
12
+ constructor(options: LoadingOptions);
13
+ updateLoader(): void;
14
+ renderLoader(): void;
15
+ render(): HTMLCanvasElement;
16
+ }
17
+ export default Loading;
@@ -0,0 +1,11 @@
1
+ /** Size-bounded map that evicts the least recently used entry first. */
2
+ declare class LruCache<T> {
3
+ private readonly entries;
4
+ private readonly limit;
5
+ constructor(limit: number);
6
+ get(key: string): T | undefined;
7
+ set(key: string, value: T): void;
8
+ clear(): void;
9
+ get size(): number;
10
+ }
11
+ export default LruCache;
@@ -0,0 +1,13 @@
1
+ import type { CellRenderer, RendererRef } from '../types';
2
+ /** Named renderers; columns refer to them by name or hand over a renderer directly. */
3
+ declare class RendererRegistry {
4
+ private readonly renderers;
5
+ private readonly warned;
6
+ register(name: string, renderer: CellRenderer): void;
7
+ unregister(name: string): void;
8
+ get(name: string): CellRenderer | undefined;
9
+ /** Resolves a reference without allocating; unknown names are reported once and yield undefined. */
10
+ resolve(ref: RendererRef): CellRenderer | undefined;
11
+ clearCaches(): void;
12
+ }
13
+ export default RendererRegistry;
@@ -0,0 +1,26 @@
1
+ import type { RenderProps } from '../types';
2
+ declare abstract class Renderer<Options extends object> {
3
+ readonly options: Options;
4
+ protected constructor(options: Options);
5
+ /** Applies the given options and notifies `optionsUpdated` with the previous ones. */
6
+ update(options: Partial<Options>): void;
7
+ optionsUpdated(_previous: Options): void;
8
+ clearCache(): void;
9
+ }
10
+ /**
11
+ * Renderer producing a bitmap from props; usable as a JSX tag through `element`.
12
+ * Bitmaps are reused through a bounded LRU cache whenever `cacheKey` returns a key.
13
+ */
14
+ export declare abstract class CanvasRenderer<Options extends object> extends Renderer<Options> {
15
+ private readonly bitmaps;
16
+ abstract render(props: RenderProps): HTMLCanvasElement;
17
+ /** Props with the same key must render the same pixels. Undefined disables caching. */
18
+ protected cacheKey(_props: RenderProps): string | undefined;
19
+ /** Device pixels per CSS pixel of the layer being drawn to; bitmaps are rendered at this scale to stay sharp. */
20
+ pixelRatio: number;
21
+ clearCache(): void;
22
+ paint(ctx: CanvasRenderingContext2D, props: RenderProps, x: number, y: number): void;
23
+ readonly element: import("./jsx").Component<RenderProps>;
24
+ private renderBitmap;
25
+ }
26
+ export default Renderer;
@@ -0,0 +1,37 @@
1
+ import type { Key, RowData, RowId } from '../types';
2
+ export type Row = RowData;
3
+ /**
4
+ * Rows in display order: a dense array with an id lookup and each row's top offset,
5
+ * so appends, lookups and finding the row at a scroll offset never scan every row.
6
+ * Removing rows renumbers the rows after the first removed one (once per call).
7
+ * Rows keep a `slot` into the column stores that does not change when the rows are sorted.
8
+ */
9
+ declare class RowStore {
10
+ private items;
11
+ private readonly indexById;
12
+ /** `tops[i]` is the offset of row `i` from the top of the first row. */
13
+ private tops;
14
+ private end;
15
+ get length(): number;
16
+ /** Sum of all row heights. */
17
+ get totalHeight(): number;
18
+ get keys(): RowId[];
19
+ get(id: Key): Row | undefined;
20
+ at(index: number): Row | undefined;
21
+ topOf(index: number): number;
22
+ /** Index of the first row that ends below `offset`; `length` when the offset is past the last row. */
23
+ indexAt(offset: number): number;
24
+ /** Appends the row, or replaces the row with the same id in place. */
25
+ set(row: Omit<Row, 'index' | 'slot'>): void;
26
+ /**
27
+ * Removes the rows with the given ids, ignoring unknown ones.
28
+ * Returns the slots of the removed rows in ascending order, which the column stores must drop too.
29
+ */
30
+ removeMany(ids: Key[]): number[];
31
+ /** Reorders the rows; the sort is stable, so equal rows keep their relative order. */
32
+ sort(compare: (a: Row, b: Row) => number): void;
33
+ clear(): void;
34
+ /** Recomputes positions and offsets from `from` onwards. */
35
+ private reindexFrom;
36
+ }
37
+ export default RowStore;
@@ -0,0 +1,3 @@
1
+ import type { RowId, RowInput } from '../types';
2
+ export declare const getNow: () => number;
3
+ export declare const getRowId: (row: RowInput, _index?: number) => RowId;