@toclocoinc/lattice-grid 1.9.1 → 1.11.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/lattice-grid.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Lattice Grid 1.9.1 — type declarations
2
+ * Lattice Grid 1.11.0 — type declarations
3
3
  * Copyright (c) 2026 TOCLOCO Inc. All rights reserved.
4
4
  * https://latticegrid.dev
5
5
  */
@@ -393,8 +393,8 @@ export type RendererName =
393
393
  export type EditorName =
394
394
  | 'checkbox' | 'code' | 'colour' | 'date' | 'datetime' | 'duration' | 'iconPicker'
395
395
  | 'ipaddress' | 'multiSelect' | 'number' | 'objectPicker' | 'password' | 'radix'
396
- | 'rating' | 'segmented' | 'select' | 'slider' | 'text' | 'textarea' | 'time'
397
- | 'treeSelect' | 'unit' | (string & {});
396
+ | 'rating' | 'segmented' | 'select' | 'slider' | 'temperature' | 'text' | 'textarea'
397
+ | 'time' | 'treeSelect' | 'unit' | (string & {});
398
398
 
399
399
  export interface EditorParams extends CellParams {
400
400
  stop(cancel?: boolean): void;
@@ -757,8 +757,104 @@ export interface StreamSourceConfig {
757
757
  coalesceMs?: number;
758
758
  }
759
759
 
760
+ /** One reduced column of a derived grid. */
761
+ export interface DerivedSelect {
762
+ /** The column to reduce, as a field name or a dotted path. Omit for `count`. */
763
+ of?: string;
764
+ /** A key of `TOTAL_FNS` — `sum`, `avg`, `median`, `p95`, `distinct` and the rest. */
765
+ fn?: TotalName;
766
+ }
767
+
768
+ /**
769
+ * A grid whose rows are derived from another grid: aggregated, unnested,
770
+ * filtered, ranked or profiled. Read-only — write to the source instead.
771
+ */
772
+ export interface DerivedSourceConfig {
773
+ mode: 'derived';
774
+ /**
775
+ * A derived grid keys on `__key`, which the source writes onto every row it
776
+ * produces — the group value, the profiled column, or the source row's own
777
+ * key when nothing is grouped. `config.rowKey` defaults to it, so it need not
778
+ * be set; an explicit `rowKey` still wins.
779
+ */
780
+ /** The grid to read. */
781
+ from: Grid;
782
+ /** Which of its rows to read. `filtered` by default. */
783
+ follow?: 'filtered' | 'all' | 'selected' | 'grouped';
784
+
785
+ /** An array property to expand, one row per element, before anything else. */
786
+ unnest?: string;
787
+ /**
788
+ * Match each row against a second grid on a shared key, and bring some of its
789
+ * fields across. Runs after `unnest` and before `where`, so a condition — and
790
+ * a grouping, and a total — can read a field the join produced.
791
+ */
792
+ join?: DerivedJoin;
793
+ /** A row predicate, applied before grouping. */
794
+ where?: (row: unknown) => boolean;
795
+ /** Round a date column down to a period, and group on that. */
796
+ bucket?: { of: string; by: 'day' | 'week' | 'month' | 'quarter' | 'year' };
797
+ /** The dimension, or dimensions, to group by. Omit to pass rows through. */
798
+ groupBy?: string | string[];
799
+ /** The reduced columns, by output id. */
800
+ select?: Record<string, DerivedSelect>;
801
+ /** How to order the derived rows before limiting them. */
802
+ sort?: { col: string; dir?: 'asc' | 'desc' }[];
803
+ /** Keep at most this many rows. */
804
+ limit?: number;
805
+ /** Apply `limit` within each distinct value of this column, not overall. */
806
+ limitPer?: string;
807
+ /** Keep rows until their running share of the total reaches `upTo`, 0 to 1. */
808
+ cumulative?: { of: string; upTo: number };
809
+
810
+ /** One row per column, with the statistics as columns. Replaces the pipeline. */
811
+ profile?: string | string[];
812
+ /** With `profile`, emit one row per statistic instead of one per column. */
813
+ orient?: 'columns' | 'metrics';
814
+
815
+ /** When to re-derive. `idle` by default — coalesced to a frame. */
816
+ refresh?: 'live' | 'idle' | 'manual' | number;
817
+
818
+ /**
819
+ * Let this grid filter the grid it derives from. `true` cross-filters through
820
+ * whatever it groups by; a string names a different source column.
821
+ */
822
+ crossFilter?: boolean | string | { col?: string };
823
+ }
824
+
825
+ export interface DerivedJoin {
826
+ /** The grid holding the other side. */
827
+ with: Grid;
828
+ /** The shared key: one field name when both sides use it, or one each. */
829
+ on: string | { left?: string; right?: string };
830
+ /** `inner` keeps only rows that matched; `left` keeps them all. */
831
+ type?: 'inner' | 'left';
832
+ /** Which of the partner's fields to bring across. All of them by default. */
833
+ select?: string[];
834
+ /** Rename the brought-across fields, when both sides have one worth keeping. */
835
+ prefix?: string;
836
+ /** Which of the partner's rows to read. `all` by default. */
837
+ follow?: 'all' | 'filtered';
838
+ }
839
+
840
+ export interface CrossFilter {
841
+ /** Whether this grid can cross-filter a source. */
842
+ enabled(): boolean;
843
+ /** The source column the filter is pushed onto. */
844
+ column(): string | null;
845
+ /** The keys currently filtering the source. */
846
+ get(): string[];
847
+ /** Filter the source to these derived rows. */
848
+ set(keys: string | string[] | null): void;
849
+ /** Add or remove one key, for click-to-filter. */
850
+ toggle(key: string): void;
851
+ /** Take this grid's filter off its source. */
852
+ clear(): void;
853
+ }
854
+
760
855
  export type SourceConfig =
761
- | MemorySourceConfig | PagedSourceConfig | RemoteSourceConfig | StreamSourceConfig;
856
+ | MemorySourceConfig | PagedSourceConfig | RemoteSourceConfig | StreamSourceConfig
857
+ | DerivedSourceConfig;
762
858
 
763
859
  // ---------------------------------------------------------------------------
764
860
  // Grid configuration (spec 18.1)
@@ -1033,6 +1129,26 @@ export interface GridConfig {
1033
1129
  */
1034
1130
  showColumnFunctions?: boolean;
1035
1131
  rowHeight?: number | ((row: Row) => number);
1132
+ /**
1133
+ * A caption for the grid, drawn above the column headings.
1134
+ *
1135
+ * Inside the grid rather than an element the host places above it: a title
1136
+ * outside does not scroll with the grid, is not in the region a screen reader
1137
+ * announces, and is left behind by image capture and print.
1138
+ */
1139
+ title?: string;
1140
+ /**
1141
+ * Draw the column headings at all.
1142
+ *
1143
+ * `true` by default. `false` removes the row, and removes it from the
1144
+ * accessibility tree rather than only from view — a heading a screen reader
1145
+ * still announces is invisible, not hidden. What a small dashboard tile
1146
+ * wants when its `title` already says what the panel is.
1147
+ *
1148
+ * Distinct from `showColumnFunctions`, which keeps the headings and drops
1149
+ * only the sort, filter and menu controls inside them.
1150
+ */
1151
+ showHeader?: boolean;
1036
1152
  headerHeight?: number;
1037
1153
  overscan?: number;
1038
1154
  /**
@@ -1804,6 +1920,11 @@ export interface RowsApi {
1804
1920
  forEach(fn: (row: Row, index: number) => void): void;
1805
1921
  /** Every row in the data, before any filter. Leaf rows, in physical order. */
1806
1922
  forEachAll(fn: (row: Row, index: number) => void): void;
1923
+ /**
1924
+ * Visit the rows surviving every filter except one column's own — the
1925
+ * faceting question, asked of the rows.
1926
+ */
1927
+ forEachExcept(colId: string, fn: (row: Row, index: number) => void): void;
1807
1928
  value(key: string, colId: string): unknown;
1808
1929
  text(key: string, colId: string): string;
1809
1930
  values(key: string): Record<string, unknown>;
@@ -2701,6 +2822,8 @@ export interface Grid {
2701
2822
  readonly presentation: PresentationApi;
2702
2823
  readonly updates: UpdatesApi;
2703
2824
  readonly timeline: TimelineApi;
2825
+ /** Cross-filtering — a derived grid filtering the grid it derives from. */
2826
+ readonly crossFilter: CrossFilter;
2704
2827
  readonly facets: FacetsApi;
2705
2828
  readonly detail: DetailApi;
2706
2829
  readonly comments: CommentsApi;
@@ -2796,10 +2919,138 @@ export function parseUnit(text: string | number, opts?: UnitConfig): number | nu
2796
2919
  export function formatUnit(value: number | null | undefined, opts?: UnitConfig): string;
2797
2920
  export const UNIT_SYSTEMS: Record<string, readonly UnitDescriptor[]>;
2798
2921
 
2922
+ /** How a statistic block finds the number it reports. */
2923
+ export interface StatValueSpec {
2924
+ /** The column to reduce, as a field name or a dotted path. Omit for `count`. */
2925
+ of?: string;
2926
+ /** A key of `TOTAL_FNS` — `sum`, `avg`, `median`, `p95`, `gini` and the rest. */
2927
+ fn?: TotalName;
2928
+ /**
2929
+ * Report this column from the row holding the extreme, rather than the
2930
+ * extreme itself: `{ of: 'sales', fn: 'max', show: 'rep' }` is the *name* of
2931
+ * the best rep. Needs `min` or `max` — no single row holds an average.
2932
+ */
2933
+ show?: string;
2934
+ }
2935
+
2936
+ /**
2937
+ * A statistic block: a label, a value, its change, and what it is compared with.
2938
+ *
2939
+ * Reads the grid, so it cannot disagree with the table beneath it, and formats
2940
+ * through the column's own type, so the tile and the table cannot drift.
2941
+ */
2942
+ export interface StatConfig extends StatValueSpec {
2943
+ grid?: Grid;
2944
+ /** An element, or a CSS selector resolved against the grid's document. */
2945
+ container: HTMLElement | string;
2946
+ title?: string;
2947
+ /** A literal value, a spec to reduce, or a function of the grid. */
2948
+ value?: unknown | StatValueSpec | ((grid: Grid) => unknown);
2949
+ /** Text under the value, or a function of it. */
2950
+ footer?: string | ((value: unknown, grid: Grid) => string);
2951
+ /** What the value is compared against, for the change indicator. */
2952
+ baseline?: number | ((grid: Grid) => number);
2953
+ /** Whether a rise is good news. `up` by default. */
2954
+ goodWhen?: 'up' | 'down' | 'neither';
2955
+ /** Which rows feed the value. `filtered` by default. */
2956
+ scope?: 'filtered' | 'all' | 'selected';
2957
+ /** `false` stops the tile following the grid; `refresh()` still works. */
2958
+ live?: boolean;
2959
+ /** Override the formatting the column's type would apply. */
2960
+ format?: (value: unknown, grid: Grid) => string;
2961
+ /** Shown when there is no value. `—` by default. */
2962
+ empty?: string;
2963
+ /** Fraction digits for a value whose reduction changed the unit. 2 by default. */
2964
+ decimals?: number;
2965
+ /** Extra class names for the tile's root. */
2966
+ class?: string;
2967
+ }
2968
+
2969
+ /** The handle `createStat` returns. */
2970
+ export interface Stat {
2971
+ element(): HTMLElement | null;
2972
+ value(): unknown;
2973
+ refresh(): void;
2974
+ destroy(): void;
2975
+ }
2976
+
2977
+ export function createStat(config: StatConfig): Stat;
2978
+ export function deltaOf(value: number | null, baseline: number | null):
2979
+ { direction: 'up' | 'down' | 'flat'; change: number | null; percent: number | null };
2980
+ export function toneOf(direction: string, goodWhen: string): 'good' | 'bad' | 'flat';
2981
+
2799
2982
  export function createGrid(element: HTMLElement, config?: GridConfig): Grid;
2800
2983
  export function createHeadlessGrid(config?: GridConfig): Grid;
2801
2984
  export function registerModules(modules: GridModule[], opts?: { licence?: string }): void;
2802
2985
  export function setLicence(licence: string): LicenceInfo;
2986
+
2987
+ /**
2988
+ * American spellings of the licence functions, exported alongside the British
2989
+ * ones because a host that writes `license` everywhere else should not have to
2990
+ * remember which spelling this one API uses.
2991
+ */
2992
+ export const setLicense: typeof setLicence;
2993
+ export function licenceInfo(): LicenceInfo;
2994
+ export const licenseInfo: typeof licenceInfo;
2995
+ export function licenceState(): LicenceInfo;
2996
+ export const licenseState: typeof licenceState;
2997
+
2998
+ /**
2999
+ * Compile a formatting rule list into a style function.
3000
+ *
3001
+ * `stats` supplies the column summary the distribution operators need — the
3002
+ * top decile, the outliers, two deviations from the mean. Without it those
3003
+ * rules cannot be answered and are skipped.
3004
+ */
3005
+ export function compileRules(
3006
+ rules: FormattingRule[],
3007
+ stats?: object | null,
3008
+ ): (p: CellParams) => CellStyle | null;
3009
+
3010
+ /**
3011
+ * Browser-storage backing for saved views.
3012
+ *
3013
+ * Returns null where no usable storage exists — a private window, or a browser
3014
+ * with site data blocked — so a caller can fall back rather than throw.
3015
+ */
3016
+ export function createLocalViewStorage(opts?: {
3017
+ key?: string;
3018
+ storage?: { getItem: Function; setItem: Function };
3019
+ }): { read(): object[] | null; write(views: object[]): void } | null;
3020
+
3021
+ /** Build a data type for hexadecimal, binary or octal values. */
3022
+ export function createRadixType(config?: object | string): DataType;
3023
+
3024
+ /** Build a column store from row objects, off the main thread where available. */
3025
+ export function ingest(
3026
+ rows: unknown[],
3027
+ plan?: object,
3028
+ opts?: object,
3029
+ ): Promise<{ store: object; schema: object[]; decisions: object[] }>;
3030
+ /** The synchronous form of {@link ingest}. */
3031
+ export function ingestSync(
3032
+ rows: unknown[],
3033
+ plan?: object,
3034
+ opts?: object,
3035
+ ): { store: object; schema: object[]; decisions: object[] };
3036
+
3037
+ /** Mount one tool panel into an element of your own, outside the grid's rail. */
3038
+ export function mountPanel(opts: {
3039
+ grid: Grid;
3040
+ panel: string | Function;
3041
+ container: Element;
3042
+ }): { element: HTMLElement; refresh(): void; destroy(): void };
3043
+
3044
+ /** The column names a compiled formula reads, deduplicated. */
3045
+ export function referencesOf(node: object): string[];
3046
+
3047
+ /** The right-click menu, for a host that drives it directly. */
3048
+ export class ContextMenu {
3049
+ constructor(opts?: object);
3050
+ open(p: object): void;
3051
+ close(): void;
3052
+ destroy(): void;
3053
+ }
2803
3054
  export function version(): string;
2804
3055
 
2805
3056
  export const LatticeGrid: {