@freegridjs/core 1.1.0 → 1.7.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.
@@ -22,6 +22,8 @@ interface XlsxSheet {
22
22
  /** Rows frozen at the top (also the AutoFilter row when `autoFilter` is set). */
23
23
  freezeRows?: number;
24
24
  autoFilter?: boolean;
25
+ /** Rows printed at the top of every page (Excel's "rows to repeat at top"). */
26
+ printTitleRows?: number;
25
27
  }
26
28
  /** Build an .xlsx workbook (stored zip) from rows of values. */
27
29
  declare function writeXlsx(sheets: XlsxSheet[]): Uint8Array;
@@ -136,6 +138,8 @@ interface ColumnDef {
136
138
  required?: boolean;
137
139
  /** Cells may hold formulas like `=qty*price` (same-row fields); the result is shown, sorted and exported. */
138
140
  formulas?: boolean;
141
+ /** A computed column: this formula (like `=qty*price`) is worked out for every row; the column needs no field. */
142
+ formula?: string;
139
143
  /** Reject a value another row already has in this column (blank values are allowed). */
140
144
  unique?: boolean;
141
145
  /** Set false (or return false) to keep values out of copies: blocked cells copy as empty text. */
@@ -203,6 +207,7 @@ interface SavedGridState {
203
207
  pageSize?: number;
204
208
  /** Selected row ids (needs getRowId to survive reloads). */
205
209
  selected?: string[];
210
+ conditionalFormats?: ConditionalFormat[];
206
211
  }
207
212
  type SavedStatePart = keyof SavedGridState;
208
213
  /** Row changes from outside (a server push, a websocket): matched by getRowId, not undoable, not tracked as edits. */
@@ -214,6 +219,8 @@ interface RowTransaction {
214
219
  update?: Row[];
215
220
  /** Rows (or objects with the id fields) to take out. */
216
221
  remove?: Row[];
222
+ /** Rows to update when a row with their id exists, else to add (live feeds that send whole rows). */
223
+ upsert?: Row[];
217
224
  }
218
225
  interface TransactionResult {
219
226
  added: Row[];
@@ -370,6 +377,38 @@ interface Messages {
370
377
  chartArea: string;
371
378
  chartPie: string;
372
379
  freeBadge: string;
380
+ /** Context menu: download a PDF of the rows. */
381
+ exportPdf: string;
382
+ exportJson: string;
383
+ /** The assistant panel. */
384
+ ai: {
385
+ title: string;
386
+ placeholder: string;
387
+ send: string;
388
+ thinking: string;
389
+ undo: string;
390
+ undone: string;
391
+ failed: string;
392
+ skipped: string;
393
+ done: string;
394
+ };
395
+ /** Conditional formatting dialog. */
396
+ cf: {
397
+ title: string;
398
+ add: string;
399
+ clear: string;
400
+ none: string;
401
+ type: string;
402
+ style: string;
403
+ wholeRow: string;
404
+ count: string;
405
+ types: Record<ConditionalFormatType, string>;
406
+ ops: {
407
+ notBetween: string;
408
+ notContains: string;
409
+ };
410
+ styles: Record<'red' | 'yellow' | 'green' | 'blue' | 'redText' | 'bold', string>;
411
+ };
373
412
  ops: Record<FilterOp, string>;
374
413
  }
375
414
  interface LocalePack extends Messages {
@@ -448,6 +487,10 @@ interface Datasource {
448
487
  }>;
449
488
  }
450
489
  interface ExportOptions {
490
+ /** xlsx and print: header rows on every printed page (default true). */
491
+ repeatHeader?: boolean;
492
+ /** xlsx and print: the first n data rows also on every printed page. */
493
+ repeatRows?: number;
451
494
  /** Column ids in order (hidden columns allowed); default: the displayed data columns. */
452
495
  columns?: string[];
453
496
  /** 'filtered' (default, current sort and filters), 'all' (source order) or 'selected' (checked rows). */
@@ -462,6 +505,20 @@ interface ExportOptions {
462
505
  styles?: boolean;
463
506
  }
464
507
  /** print() and getPrintHtml(): the export options plus how the page looks. */
508
+ interface PdfOptions extends PrintOptions {
509
+ /** Pixels per CSS pixel in the page images (default 2; higher is sharper and larger). */
510
+ resolution?: number;
511
+ /** JPEG quality of the page images, 0–1 (default 0.92). */
512
+ quality?: number;
513
+ }
514
+ interface JsonExportOptions extends ExportOptions {
515
+ /** Object keys: column ids (default) or column headers. */
516
+ keys?: 'id' | 'header';
517
+ /** Values as shown in the grid (formatted text) instead of the raw values. */
518
+ formatted?: boolean;
519
+ /** Indentation (default 2; 0 for one line). */
520
+ space?: number;
521
+ }
465
522
  interface PrintOptions extends ExportOptions {
466
523
  /** Heading above the table; also the document title. */
467
524
  title?: string;
@@ -487,6 +544,162 @@ interface PrintOptions extends ExportOptions {
487
544
  printedAt?: boolean;
488
545
  /** A row number column. Default: when the grid shows row numbers. */
489
546
  rowNumbers?: boolean;
547
+ /** Repeat the title block on every page. Default false. */
548
+ repeatTitle?: boolean;
549
+ }
550
+ /** Look of a cell set by a conditional format. Colours: #hex, rgb(), hsl(), names or var(--x). */
551
+ interface CellStyle {
552
+ color?: string;
553
+ background?: string;
554
+ bold?: boolean;
555
+ italic?: boolean;
556
+ strike?: boolean;
557
+ }
558
+ type ConditionalFormatType = 'value' | 'formula' | 'top' | 'bottom' | 'aboveAverage' | 'belowAverage' | 'duplicate' | 'unique' | 'dataBar' | 'colorScale' | 'iconSet';
559
+ type ConditionalOp = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'between' | 'notBetween' | 'contains' | 'notContains' | 'startsWith' | 'endsWith' | 'blank' | 'notBlank';
560
+ /** A conditional format: a rule that styles cells, or a scale drawn over a column. Later rules win on conflicts. */
561
+ interface ConditionalFormat {
562
+ /** Column ids the format applies to. */
563
+ columns: string[];
564
+ /** Default 'value'. */
565
+ type?: ConditionalFormatType;
566
+ /** 'value': how the cell is compared with value (and valueTo for between). */
567
+ op?: ConditionalOp;
568
+ value?: unknown;
569
+ valueTo?: unknown;
570
+ /** 'formula': a formula over the row, true to apply, e.g. '=amount > target'. */
571
+ formula?: string;
572
+ /** 'top' / 'bottom': how many cells (default 10), or a percentage with percent: true. */
573
+ rank?: number;
574
+ percent?: boolean;
575
+ /** The look of matching cells. */
576
+ style?: CellStyle;
577
+ /** Style every cell of the row when the first column (or the formula) matches. */
578
+ row?: boolean;
579
+ /** Matching cells get no styles from later rules. */
580
+ stopIfTrue?: boolean;
581
+ /** 'dataBar': the bar colour (default the accent colour). */
582
+ color?: string;
583
+ /** 'colorScale': two or three #hex colours from the lowest to the highest value. */
584
+ colors?: string[];
585
+ /** 'iconSet': default 'arrows'. */
586
+ icons?: 'arrows' | 'traffic' | 'signs';
587
+ /** Scales: the values the bar or colours run between (default the column's lowest and highest). */
588
+ min?: number;
589
+ max?: number;
590
+ }
591
+ /** The AI assistant: the grid asks your server, your server asks the model and answers with actions. */
592
+ interface AssistantOptions {
593
+ /** Your endpoint (POST JSON). It holds the model API key; the browser never sees it. */
594
+ url: string;
595
+ headers?: Record<string, string> | (() => Record<string, string>);
596
+ credentials?: RequestCredentials;
597
+ /** Rows sent as examples (default 5, max 50; 0 sends none). Columns always go as summaries, not rows. */
598
+ sampleRows?: number;
599
+ /** Extra facts for the model, such as what the screen is for. */
600
+ context?: () => Record<string, unknown>;
601
+ /** Ideas shown under the input. */
602
+ suggestions?: string[];
603
+ }
604
+ /** A column as the assistant sees it. */
605
+ interface AssistantColumn {
606
+ id: string;
607
+ header: string;
608
+ type?: string;
609
+ formula?: string;
610
+ aggFunc?: string;
611
+ hidden?: boolean;
612
+ blanks?: number;
613
+ distinct?: number;
614
+ min?: number | string;
615
+ max?: number | string;
616
+ avg?: number;
617
+ /** Most frequent values of text columns. */
618
+ top?: {
619
+ value: string;
620
+ count: number;
621
+ }[];
622
+ }
623
+ /** What the grid sends to the assistant endpoint. */
624
+ interface AssistantRequest {
625
+ prompt: string;
626
+ locale: string;
627
+ /** Rows after the filters. */
628
+ rowCount: number;
629
+ totalRows: number;
630
+ columns: AssistantColumn[];
631
+ sample: Row[];
632
+ state: {
633
+ sort: SortItem[];
634
+ filters: Record<string, FilterModel>;
635
+ quickFilter: string;
636
+ advancedFilter: AdvancedFilter | null;
637
+ groupBy: string[];
638
+ pivot: PivotConfig | null;
639
+ conditionalFormats: ConditionalFormat[];
640
+ };
641
+ context?: Record<string, unknown>;
642
+ }
643
+ /** What the assistant endpoint answers with: { message?, actions? }. */
644
+ type AssistantAction = {
645
+ type: 'sort';
646
+ sort: SortItem[];
647
+ } | {
648
+ type: 'filter';
649
+ colId: string;
650
+ model: FilterModel | null;
651
+ } | {
652
+ type: 'clearFilters';
653
+ } | {
654
+ type: 'quickFilter';
655
+ text: string;
656
+ } | {
657
+ type: 'advancedFilter';
658
+ filter: AdvancedFilter | null;
659
+ } | {
660
+ type: 'groupBy';
661
+ colIds: string[];
662
+ expand?: boolean;
663
+ } | {
664
+ type: 'pivot';
665
+ pivot: PivotConfig | null;
666
+ } | {
667
+ type: 'showColumns' | 'hideColumns';
668
+ colIds: string[];
669
+ } | {
670
+ type: 'conditionalFormat';
671
+ format: ConditionalFormat;
672
+ } | {
673
+ type: 'clearConditionalFormats';
674
+ } | {
675
+ type: 'addColumn';
676
+ column: {
677
+ id: string;
678
+ header?: string;
679
+ formula: string;
680
+ type?: 'number' | 'text' | 'date';
681
+ };
682
+ } | {
683
+ type: 'summary';
684
+ summary: SummaryOptions | null;
685
+ } | {
686
+ type: 'chart';
687
+ chartType?: ChartOptions['type'];
688
+ colIds: string[];
689
+ title?: string;
690
+ } | {
691
+ type: 'message';
692
+ text: string;
693
+ };
694
+ interface AssistantResult {
695
+ message: string;
696
+ applied: AssistantAction[];
697
+ skipped: {
698
+ action: unknown;
699
+ reason: string;
700
+ }[];
701
+ /** Put the grid back as it was before these actions. */
702
+ undo(): void;
490
703
  }
491
704
  interface PivotConfig {
492
705
  /** Row fields; every field but the last becomes a group level. */
@@ -581,6 +794,16 @@ interface GridOptions {
581
794
  editType?: 'cell' | 'row';
582
795
  /** Briefly highlight cells whose value changed through applyTransaction (default true). */
583
796
  flashCells?: boolean;
797
+ /** An AI assistant answered by your server (see AssistantOptions). */
798
+ assistant?: AssistantOptions;
799
+ /** Rules that colour cells by their values, and data bars, colour scales and icon sets. */
800
+ conditionalFormats?: ConditionalFormat[];
801
+ /** Show "Conditional formatting…" in the column menu (default true). */
802
+ conditionalFormatMenu?: boolean;
803
+ /** How long a changed cell flashes, in ms (default 1000). Numbers flash green going up and red going down. */
804
+ flashDuration?: number;
805
+ /** applyTransactionAsync: how long to collect transactions before applying them together, in ms (default 50). */
806
+ asyncTransactionWait?: number;
584
807
  /** Row spacing: 'compact', 'normal' (default) or 'comfortable'. Fixed rowHeight / headerHeight win. */
585
808
  density?: 'compact' | 'normal' | 'comfortable';
586
809
  /** Shown when there are no rows: text, or a function returning text or an element (filtered: the filters hide every row). */
@@ -752,6 +975,19 @@ interface GridEvents {
752
975
  };
753
976
  /** applyTransaction (or a batch of applyTransactionAsync) finished. */
754
977
  transactionApplied: TransactionResult;
978
+ conditionalFormatsChange: {
979
+ formats: ConditionalFormat[];
980
+ };
981
+ /** The assistant answered and its actions were applied. */
982
+ assistantAnswer: {
983
+ prompt: string;
984
+ message: string;
985
+ applied: AssistantAction[];
986
+ skipped: {
987
+ action: unknown;
988
+ reason: string;
989
+ }[];
990
+ };
755
991
  /** A row was dropped on this grid (also from another grid of the same drag group). */
756
992
  rowDrop: RowDropParams & {
757
993
  fromGrid: GridApi | null;
@@ -845,6 +1081,16 @@ interface GridApi {
845
1081
  applyTransaction(tx: RowTransaction): TransactionResult;
846
1082
  /** Queue a transaction; queued ones are merged and applied together about every 50 ms. */
847
1083
  applyTransactionAsync(tx: RowTransaction): void;
1084
+ /** Apply the queued applyTransactionAsync transactions now. */
1085
+ flushAsyncTransactions(): void;
1086
+ setConditionalFormats(formats: ConditionalFormat[]): void;
1087
+ getConditionalFormats(): ConditionalFormat[];
1088
+ /** Ask the assistant (options.assistant) and apply its answer. */
1089
+ askAssistant(prompt: string): Promise<AssistantResult>;
1090
+ /** The assistant panel. */
1091
+ openAssistant(): void;
1092
+ /** The conditional formatting dialog for a column. */
1093
+ openConditionalFormats(colId: string): void;
848
1094
  /** Conditions across columns, applied together with the column filters; null clears it. */
849
1095
  setAdvancedFilter(filter: AdvancedFilter | null): void;
850
1096
  getAdvancedFilter(): AdvancedFilter | null;
@@ -861,6 +1107,10 @@ interface GridApi {
861
1107
  showOverlay(kind: 'loading' | 'noRows' | null): void;
862
1108
  /** Print the rows as a table (current sort and filters, group rows and summary rows) on the paper you choose. */
863
1109
  print(options?: PrintOptions): void;
1110
+ /** The print page as a PDF file (null when the browser cannot draw on a canvas). */
1111
+ getPdf(options?: PdfOptions): Uint8Array | null;
1112
+ /** Download getPdf() as a .pdf file. */
1113
+ exportPdf(filename?: string, options?: PdfOptions): void;
864
1114
  /** The HTML page print() would print. */
865
1115
  getPrintHtml(options?: PrintOptions): string;
866
1116
  /** Check every editable cell against required, unique and validate. Empty when all rows are valid. */
@@ -974,6 +1224,10 @@ interface GridApi {
974
1224
  getCsv(options?: ExportOptions): string;
975
1225
  /** Download a CSV file (UTF-8 with BOM so Excel reads non-Latin text). */
976
1226
  exportCsv(filename?: string, options?: ExportOptions): void;
1227
+ /** The rows as a JSON array of objects. */
1228
+ getJson(options?: JsonExportOptions): string;
1229
+ /** Download getJson() as a .json file. */
1230
+ exportJson(filename?: string, options?: JsonExportOptions): void;
977
1231
  /** An .xlsx workbook of the rows. */
978
1232
  getXlsx(options?: ExportOptions): Uint8Array;
979
1233
  exportXlsx(filename?: string, options?: ExportOptions): void;
@@ -989,4 +1243,4 @@ interface GridApi {
989
1243
  destroy(): void;
990
1244
  }
991
1245
 
992
- export { type TextFilterModel as $, type AdvancedFilter as A, type RowDropPosition as B, type CellEvent as C, type Datasource as D, type ExportOptions as E, type FilterModel as F, type GridOptions as G, type RowTransaction as H, type InvalidCell as I, type SavedStatePart as J, type KeyAction as K, type LocalePack as L, type Messages as M, type NumberFilterModel as N, type ScrollPosition as O, type PivotConfig as P, type SelectOption as Q, type Row as R, type SavedGridState as S, type ServerParams as T, type SetFilterModel as U, type SortDir as V, type SortItem as W, type SpanParams as X, type SummaryCell as Y, type SummaryOptions as Z, type SummaryRowDef as _, type GridApi as a, type TextOp as a0, type TransactionResult as a1, type XlsxCell as a2, type XlsxSheet as a3, readXlsx as a4, writeXlsx as a5, type AdvancedFilterCondition as b, type Aggregator as c, type CellParams as d, type ChartHandle as e, type ChartOptions as f, type ColumnDef as g, type ColumnState as h, type ColumnType as i, type CombinedFilterModel as j, type ContextMenuItem as k, type ContextMenuParams as l, type CustomEditor as m, type DateFilterModel as n, type DateOp as o, type EditorParams as p, type EditorSpec as q, type FilterOp as r, type FilterType as s, type GridEvents as t, type GridRange as u, type NumberOp as v, type PrintOptions as w, type Region as x, type RowDragOptions as y, type RowDropParams as z };
1246
+ export { type SavedStatePart as $, type AdvancedFilter as A, type EditorSpec as B, type CellEvent as C, type Datasource as D, type ExportOptions as E, type FilterModel as F, type GridOptions as G, type FilterOp as H, type FilterType as I, type GridEvents as J, type GridRange as K, type LocalePack as L, type InvalidCell as M, type JsonExportOptions as N, type KeyAction as O, type Messages as P, type NumberFilterModel as Q, type Row as R, type NumberOp as S, type PdfOptions as T, type PivotConfig as U, type PrintOptions as V, type Region as W, type RowDragOptions as X, type RowDropParams as Y, type RowDropPosition as Z, type SavedGridState as _, type GridApi as a, type ScrollPosition as a0, type SelectOption as a1, type ServerParams as a2, type SetFilterModel as a3, type SortDir as a4, type SortItem as a5, type SpanParams as a6, type SummaryCell as a7, type SummaryOptions as a8, type SummaryRowDef as a9, type TextFilterModel as aa, type TextOp as ab, type TransactionResult as ac, type XlsxCell as ad, type XlsxSheet as ae, readXlsx as af, writeXlsx as ag, type RowTransaction as b, type AdvancedFilterCondition as c, type Aggregator as d, type AssistantAction as e, type AssistantColumn as f, type AssistantOptions as g, type AssistantRequest as h, type AssistantResult as i, type CellParams as j, type CellStyle as k, type ChartHandle as l, type ChartOptions as m, type ColumnDef as n, type ColumnState as o, type ColumnType as p, type CombinedFilterModel as q, type ConditionalFormat as r, type ConditionalFormatType as s, type ConditionalOp as t, type ContextMenuItem as u, type ContextMenuParams as v, type CustomEditor as w, type DateFilterModel as x, type DateOp as y, type EditorParams as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freegridjs/core",
3
- "version": "1.1.0",
3
+ "version": "1.7.0",
4
4
  "description": "FreeGrid — a fast data grid for the web (free for personal use): virtual scrolling, grouping, pivot, charts, Excel export, 7 languages.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",