import type { CSVExportOptions, GetStateOptions, GridSchema, GridState, SetStateOptions, SetStateResult } from 'apex-grid'; import { ApexGrid, type ExportFormat, type ExportOptions, type GridFeatureModule, StateController, type ToolbarAction } from 'apex-grid/internal'; import { type PropertyValues } from 'lit'; import { type AggregationConfig, type AggregationResults } from './features/aggregation.js'; import type { AIEngine, AIResult, RunPromptOptions } from './features/ai/engine.js'; import type { Reasoner } from './features/ai/reasoner.js'; import type { Plan } from './features/ai/types.js'; import { type ChartDefinition, type ChartField, type ChartModel, type RenderChartOptions } from './features/chart.js'; import { type ContextMenuConfig } from './features/context-menu.js'; import { type FormulaFn } from './features/formula/index.js'; import { type GroupRowMeta } from './features/grouping.js'; import { type InfiniteRowModelConfig } from './features/infinite-row-model.js'; import { type MasterDetailConfig } from './features/master-detail.js'; import { type RangeBounds, type RangeStats } from './features/range-selection.js'; import { type XLSXExportOptions } from './features/xlsx.js'; /** Custom-element tag for the enterprise grid. */ export declare const ENTERPRISE_TAG = "apex-grid-enterprise"; /** * Fired on the grid (bubbles, composed) after its render pipeline settles and the * rendered view (columns / row count / grouping / pivot) has changed. The signal * `` listens to for live redraws on group/pivot/data changes. */ export declare const VIEW_CHANGED_EVENT = "apex-view-changed"; /** Enterprise export option: emit each formula cell's `=...` source instead of its value. */ export interface FormulaExportOptions { /** When true, cells holding a formula export their source; others export normally. */ formulas?: boolean; } /** * Pro-licensed grid. Extends the community {@link ApexGrid} and registers as * ``, reusing the full grid template/DOM and layering in * enterprise-only feature modules through `createStateController()`. * * Licensing follows the non-hostile, offline model: without a valid key set via * {@link ApexGridEnterprise.setLicense} the grid keeps working but renders a * watermark and logs a console notice. * * @element apex-grid-enterprise * * @remarks * Inherits all properties, attributes, methods, and events of {@link ApexGrid} * (see its docs for the full `@fires` list and `--ag-*` theming hooks), and adds * column aggregations, row grouping, pivoting, integrated charts, cell range * selection, XLSX export, and licensing on top. * * @csspart license-watermark - Non-interactive diagonal watermark overlay shown when no valid license is set. */ export declare class ApexGridEnterprise extends ApexGrid { #private; /** * Opt feature modules into every enterprise grid (idempotent per module id). * Returns the class so calls can chain. Call before constructing any * `` (and before {@link register}). * * @example * ```ts * import { ApexGridEnterprise, pivotModule } from 'apex-grid-enterprise'; * ApexGridEnterprise.use(pivotModule); // only pivoting is bundled + wired * ApexGridEnterprise.register(); * ``` */ static use(...modules: ReadonlyArray): typeof ApexGridEnterprise; /** * Per-column aggregation request (sum/avg/min/max/count). Read on demand by * {@link getAggregations}, and computed per group when {@link groupBy} is set. * Reactive: changing it re-runs grouping so group aggregates update. */ aggregations: AggregationConfig; /** * Ordered column keys to group rows by (derived row grouping, distinct from * declared `tree` data). Empty disables grouping. Each group renders an * expandable, full-width header row with its value, leaf count, and the * configured {@link aggregations}. */ groupBy: string[]; /** Tuning for row grouping (e.g. default group expansion). */ groupingOptions: { defaultExpanded?: boolean | number; }; /** * Column-dimension field for pivoting: its distinct values become columns. * Empty disables pivoting. Requires {@link pivotRows} and {@link pivotValues}. * Pivoting and {@link groupBy} are mutually exclusive (pivot wins). */ pivotOn: string; /** Row-dimension field(s) for pivoting (one leading column each). */ pivotRows: string[]; /** Measures aggregated into each pivot cell, e.g. `{ salary: ['sum'] }`. */ pivotValues: AggregationConfig; /** * Spreadsheet-style cell range selection (click-drag / shift-click). Enabled * by default; set `range-selection="false"` (or the property) to turn it off. * Pairs with `` for live selection aggregates and with * {@link copySelection} for clipboard export. */ rangeSelection: boolean; /** * Show the stored formula source in `allowFormula` cells instead of their * computed values (a spreadsheet "show formulas" view). Toggle with the * `show-formulas` attribute or the property; the computed values are * untouched, so turning it off restores the normal display. A user-provided * `cellTemplate` is respected (never overridden). */ showFormulas: boolean; /** * Right-click context menu on cells and headers (sort / pin / hide / copy, plus "Chart range"). * Enabled by default; set `context-menu="false"` to turn it off, or assign a * {@link ContextMenuConfig} (via property) to replace the items. */ contextMenu: boolean | ContextMenuConfig; /** * Declarative master/detail: each expanded master row renders a nested grid * of related rows. Setting this configures the grid's {@link expansion} * automatically (creating, caching, and populating the child grids), so you * don't hand-write a `detailTemplate`. Overrides any manual `expansion`. */ masterDetail: MasterDetailConfig | null; /** * Infinite (server-side) row model: lazily fetch fixed-size blocks from a * datasource as the user scrolls, pushing sort/filter/quick-filter to the * server. Setting this disables client-side sort/filter (the server owns * ordering) — keep pagination off. See {@link InfiniteRowModelConfig}. */ infiniteRowModel: InfiniteRowModelConfig | null; /** * An optional escalation {@link Reasoner} the AI layer consults when the built-in * deterministic rule engine is not confident (e.g. `createClaudeReasoner(...)` for * Anthropic/Claude). Unset (the default), {@link runPrompt} is handled entirely by * the rule engine: no LLM, no key, no network. The AI Toolkit is an enterprise feature. */ aiReasoner: Reasoner | null; /** * Advanced: a fully custom {@link AIEngine} (custom tools, memory, or routing * policy) used instead of the lazily-built default. When set, it overrides * {@link aiReasoner}. */ aiEngine: AIEngine | null; static get tagName(): string; /** Whether a pivot view is currently active. */ get isPivoting(): boolean; /** * Registers `` and the grid's internal dependencies. * Idempotent. Reuses {@link ApexGrid.register} for the shared sub-components, * then defines the enterprise element. */ static register(): void; /** * Sets the global ApexCharts license key. Without a valid key the grid renders * with a watermark. Validation is offline (no network). */ static setLicense(key: string): void; connectedCallback(): void; disconnectedCallback(): void; /** Computes the configured {@link aggregations} over the grid's data. */ getAggregations(): AggregationResults; /** * Extends the core {@link ApexGrid.getState} snapshot with the enterprise view * state (row grouping, aggregations, and pivoting), stored under * `modules.enterprise`. * * @remarks * These live as reactive properties on the enterprise grid (the controllers * are synced from them), so they are captured here rather than through the * per-module {@link SerializableModule} seam. */ getState(options?: GetStateOptions): GridState; /** * Extends the core {@link ApexGrid.getSchema} descriptor with enterprise * capabilities: marks every column groupable / pivotable, numeric columns * aggregatable (with the supported aggregation functions), and advertises * grouping / pivot / aggregation at the grid level. */ getSchema(): GridSchema; /** * Restores the enterprise view state from `modules.enterprise` (if present), * then applies the core slices via {@link ApexGrid.setState}. Enterprise * structure (grouping / pivot) is set first so the transformed view is in * place before the core pass resolves row-referencing slices. */ setState(state: Partial, options?: SetStateOptions): SetStateResult; /** * Run a natural-language `prompt` against the grid. * * Works out of the box via the built-in deterministic rule engine (no LLM, no * key, no network). Set {@link aiReasoner} to add an LLM escalation path for * requests the rule engine cannot map. * * - **`'control'` (default):** the planned tool calls are validated and applied * via {@link setState}; the result carries an `undo()` that restores the prior * snapshot. * - **`'ask'`:** a read-only answer about the current view / data; no mutation. * * AI Toolkit is an enterprise feature. * * @example * ```ts * const result = await grid.runPrompt('sort by price, highest first'); * if (result.mode === 'control') result.undo(); // one-click revert * ``` */ runPrompt(prompt: string, options?: RunPromptOptions): Promise; /** * Dry-run a prompt: return the {@link Plan} the reasoner would execute, without * applying it. The natural primitive for a confirm-before-apply UI. */ previewPrompt(prompt: string, options?: RunPromptOptions): Promise; protected willUpdate(changed: PropertyValues): void; protected updated(): void; /** Whether a row is an unloaded placeholder under the infinite row model. */ isRowLoading(row: T): boolean; /** Discard the infinite-model cache and refetch from the top. */ refreshRows(): void; /** Drop a master row's cached detail grid so it rebuilds on next expand. */ refreshDetail(row: T): void; /** * Set a spreadsheet formula on a cell (enterprise formula module). The source * may start with `=`; the computed result becomes the cell value and any * dependent cells recompute. No-op if the formula module is not enabled or the * row is not in {@link ApexGrid.data}. * * @example * ```ts * grid.setFormula(grid.data[0], 'total', '=B1*C1'); * ``` */ setFormula(row: T, columnKey: keyof T & string, formula: string): void; /** The formula source stored on a cell, or `undefined` if it holds a literal. */ getFormula(row: T, columnKey: keyof T & string): string | undefined; /** Remove a cell's formula; its dependents recompute against the literal left behind. */ clearFormula(row: T, columnKey: keyof T & string): void; /** Recompute every stored formula (e.g. after mutating data in place). */ recalculateFormulas(): void; /** * Register a custom formula function (upper-cased) for this grid, callable from * formulas as `NAME(args)`. * * @example * ```ts * grid.registerFormulaFunction('TAX', (args) => * typeof args[0] === 'number' ? args[0] * 0.2 : 0 * ); * ``` */ registerFormulaFunction(name: string, fn: FormulaFn): void; /** * Programmatically select a rectangular cell range by row index + column key * (anchor → focus). `to` defaults to `from`. Useful for restoring state or * driving the selection from app code. */ selectRange(from: { row: number; column: string; }, to?: { row: number; column: string; }): void; /** Bounds of the active cell range selection (view coordinates), or `null`. */ getSelectionBounds(): RangeBounds | null; /** Every selected rectangle (Ctrl-click ranges + the active one). */ getSelectionRanges(): RangeBounds[]; /** * Fill from the active range toward the given cell (row + column key) — the * programmatic form of dragging the fill handle. Numeric source lines * extrapolate a series; everything else tiles the source. */ fillTo(to: { row: number; column: string; }): void; /** * Paste a TSV block into the grid starting at the active range's top-left, * expanding the selection to cover it (values coerced to column type). */ pasteText(text: string): void; /** Aggregate statistics (count/sum/avg/min/max) over the selected range. */ getSelectionStats(): RangeStats; /** The selected range serialized as TSV (tab-separated, Excel-pasteable). */ getSelectionTSV(): string; /** Copy the selected range to the clipboard as TSV. */ copySelection(): Promise; /** * Clear the current cell range selection. Named distinctly from the inherited * {@link ApexGrid.clearSelection} (which clears selected rows). */ clearRangeSelection(): void; /** Expand a single group by its key (see {@link GroupRowMeta.key}). */ expandGroup(key: string): void; /** Collapse a single group by its key. */ collapseGroup(key: string): void; /** Toggle a single group's expansion by its key. */ toggleGroup(key: string): void; /** Expand every group. */ expandAllGroups(): void; /** Collapse every group. */ collapseAllGroups(): void; /** The group headers (with counts + aggregates) from the latest pipeline pass. */ getGroups(): GroupRowMeta[]; /** * Build a chart-ready model from the current view. Dispatches by intent: * - **Cell range selected (non-empty):** the range model (see {@link getRangeChartModel}) wins. * - **Grouping active:** categories = top-level group labels; one series per * `aggregations` measure×fn. * - **Pivot active:** categories = pivot row labels; one series per generated * pivot value column. * - **None of the above:** empty model. * * An optional {@link ChartDefinition} steers the range and flat-view paths (category, measures, * per-series aggregation); the grouping/pivot paths use their own configured aggregations. */ getChartModel(definition?: ChartDefinition): ChartModel; /** * Build a chart-ready model from the **grouping or pivot view** (ignoring any cell range * selection). The selection-independent half of {@link getChartModel}; `` uses * it for `source="view"`. * - **Grouping active:** categories = top-level group labels; one series per `aggregations` * measure×fn. * - **Pivot active:** categories = pivot row labels; one series per generated pivot value column. * - **Flat grid:** the whole current view (all `pageItems`, in view order) charted via * {@link buildCategoryModel} — first non-numeric visible column is the category axis, every * numeric column a series, repeated categories summed. This is what makes a docked * `source="view"` chart a live companion: sorting, filtering, and edits flow straight through. * An optional {@link ChartDefinition} overrides the category, measures, and aggregation here. * - **No rows:** empty model. */ getViewChartModel(definition?: ChartDefinition): ChartModel; /** * The chartable columns of the current flat view — key, label, and whether the column is numeric — * for driving a mapping UI (``'s Data popover). Category candidates are all * columns; measure candidates are the numeric ones. Reflects the visible columns and the current * (sorted/filtered) rows; empty while grouping/pivot is active (those views carry their own * aggregation and ignore a {@link ChartDefinition}). */ getChartFields(): ChartField[]; /** * Build a chart-ready model from the **active cell range selection** (the Excel-style * "select cells → chart" path). Orientation: the first non-numeric column in the range is the * category axis; every numeric column becomes a series (named by its header). When the range is * all-numeric, row positions (1, 2, 3, …) are the categories and every column is a series. * * When the category column has **repeated values** (e.g. a `department` column with several rows * per department) the rows are grouped by category and each series is aggregated per category * (summed by default), so the chart shows one bar/point per distinct category instead of one per * row. A category axis of already-distinct values (or all-numeric row positions) is charted * row-for-row. An optional {@link ChartDefinition} overrides the category, measures, and * aggregation. * * Returns an empty model when there is no selection or no numeric series. Uses the active * (primary) range under a multi-range selection. */ getRangeChartModel(definition?: ChartDefinition): ChartModel; /** * Build a **cross-filter** chart model: the category column from the active selection (first * non-numeric column), aggregated over the grid's **full, unfiltered** `data`, summing the first * numeric column (or counting rows). Reading the full data keeps every category present, so a * chart-driven filter highlights a category instead of collapsing the chart. Returns the * `categoryKey` so the caller knows which column to filter. Empty when no category column. */ getCrossFilterModel(): { categoryKey: string | null; model: ChartModel; }; /** * Render the current {@link getChartModel} into a (light-DOM) container using * ApexCharts and return the instance. ApexCharts is dynamically imported. */ renderChart(container: HTMLElement, options?: RenderChartOptions): Promise; /** * Render the active cell range ({@link getRangeChartModel}) into a (light-DOM) container using * ApexCharts and return the instance. ApexCharts is dynamically imported. */ createRangeChart(container: HTMLElement, options?: RenderChartOptions): Promise; /** * Adds a "Create chart" button to the toolbar (on top of the community grid's none). Clicking it * opens a floating `` bound to this grid. Requires * `` to be registered (the `/define` entry does so). */ get toolbarActions(): ReadonlyArray; /** * Adds XLSX (Excel) export to the community grid's CSV-only menu. Excel * export is an enterprise feature; CSV stays in the community package. */ get exportFormats(): ReadonlyArray; exportAs(formatId: string, options?: ExportOptions): void; /** * CSV export with the enterprise `formulas` option: when set, `allowFormula` * cells export their formula source (`=A1*B1`) rather than the computed value. * Otherwise identical to the community {@link ApexGrid.exportToCSV}. */ exportToCSV(options?: CSVExportOptions & FormulaExportOptions): string; /** * Exports the current grid contents as an `.xlsx` workbook and (in a browser * context) triggers a download. * * @remarks * Produces a single-sheet workbook with a bold header row. Numbers, booleans * and `Date` values keep their native cell type in Excel; everything else is * written as inline strings. Shares the same `source` / `columns` / * `formatter` options as the community grid's `exportToCSV`, plus an optional * `sheetName`. Pass `filename: ''` to skip the download and only receive the * bytes back. * * @example * ```ts * grid.exportToXLSX(); * grid.exportToXLSX({ filename: 'users', sheetName: 'Users' }); * ``` */ exportToXLSX(options?: XLSXExportOptions & FormulaExportOptions): Uint8Array; protected createStateController(): StateController; protected render(): import("lit-html").TemplateResult<1>; }