@ya-grid/core 0.3.1 → 0.4.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/dist/index.d.ts CHANGED
@@ -256,6 +256,8 @@ interface ServerSideGetRowsResult<TData = Record<string, unknown>> {
256
256
  interface ServerSideDatasource<TData = Record<string, unknown>> {
257
257
  getRows: (request: ServerSideGetRowsRequest) => Promise<ServerSideGetRowsResult<TData>>;
258
258
  }
259
+ /** Reusable column preset merged between `defaultColDef` and an individual `ColDef`. */
260
+ type ColumnTypeDef<TData = Record<string, unknown>> = Partial<ColDef<TData, any>>;
259
261
  /** Leaf column definition configuring rendering, editing, sizing, sorting, filtering, and aggregation. */
260
262
  interface ColDef<TData = Record<string, unknown>, TValue = unknown> {
261
263
  /** Unique column ID (defaults to `field`). */
@@ -264,6 +266,11 @@ interface ColDef<TData = Record<string, unknown>, TValue = unknown> {
264
266
  field?: Extract<keyof TData, string> | string;
265
267
  /** Header title (auto-formatted from `field` if omitted). */
266
268
  headerName?: string;
269
+ /**
270
+ * One or more named column types defined in `GridOptions.columnTypes`.
271
+ * Applied in order after `defaultColDef` and before properties on this `ColDef`.
272
+ */
273
+ type?: string | string[];
267
274
  valueGetter?: (params: ValueGetterParams<TData>) => TValue;
268
275
  valueFormatter?: (params: ValueFormatterParams<TData, TValue>) => string;
269
276
  cellRenderer?: CellRenderer<TData, TValue>;
@@ -426,6 +433,11 @@ interface GridOptions<TData = Record<string, unknown>> {
426
433
  rowData: TData[];
427
434
  columnDefs: ColumnDefItem<TData>[];
428
435
  defaultColDef?: Partial<ColDef<TData, any>>;
436
+ /**
437
+ * Named reusable column presets referenced by `ColDef.type`.
438
+ * Precedence: `defaultColDef` -> `columnTypes` (left-to-right) -> `colDef`.
439
+ */
440
+ columnTypes?: Record<string, ColumnTypeDef<TData>>;
429
441
  /** Stable unique row ID extractor. Required for `applyTransaction` and preserving selection/expansion across updates. */
430
442
  getRowId?: (params: {
431
443
  data: TData;
@@ -609,7 +621,7 @@ declare class ColumnController<TData = Record<string, unknown>> {
609
621
  private setOverride;
610
622
  private recordUserOrder;
611
623
  private applyUserState;
612
- setColumnDefs(columnDefs: ColumnDefItem<TData>[], defaultColDef?: Partial<ColDef<TData, any>>, selectionConfig?: RowSelectionConfig<TData> | null, masterDetail?: boolean): void;
624
+ setColumnDefs(columnDefs: ColumnDefItem<TData>[], defaultColDef?: Partial<ColDef<TData, any>>, selectionConfig?: RowSelectionConfig<TData> | null, masterDetail?: boolean, columnTypes?: Record<string, Partial<ColDef<TData, any>>>): void;
613
625
  /**
614
626
  * Configures automatic unpinning on narrow viewports. Returns true if the effective
615
627
  * collapsed state changed (requiring a zone re-render).
@@ -648,6 +660,143 @@ declare class ColumnController<TData = Record<string, unknown>> {
648
660
  applyColumnState(state: ColumnStateItem[]): boolean;
649
661
  }
650
662
 
663
+ /**
664
+ * Shared brand symbol recognized by framework adapters (`@ya-grid/react`, `@ya-grid/vue`, etc.)
665
+ * so built-in and user-marked vanilla DOM cell renderers bypass framework portal/teleport overhead.
666
+ */
667
+ declare const VANILLA_RENDERER_SYMBOL: unique symbol;
668
+ /**
669
+ * Marks a function as a plain DOM cell renderer so framework adapters let `@ya-grid/core`
670
+ * mount its returned `HTMLElement` or string directly without framework wrapper overhead.
671
+ */
672
+ declare function markVanillaRenderer<TData = Record<string, unknown>, TValue = unknown>(fn: VanillaCellRendererFn<TData, TValue>): VanillaCellRendererFn<TData, TValue>;
673
+ interface CurrencyColumnOptions {
674
+ /** BCP 47 locale (default `'en-US'`). */
675
+ locale?: string;
676
+ /** ISO 4217 currency code (default `'USD'`). */
677
+ currency?: string;
678
+ /** Minimum fraction digits (default `0`). */
679
+ minimumFractionDigits?: number;
680
+ /** Maximum fraction digits (default `2`, or `1` when `compact: true`). */
681
+ maximumFractionDigits?: number;
682
+ /** `'accounting'` renders negatives in parentheses, e.g. `($1,250)`. */
683
+ currencySign?: 'standard' | 'accounting';
684
+ /** Controls explicit `+`/`-` sign rendering. */
685
+ signDisplay?: 'auto' | 'always' | 'exceptZero' | 'never';
686
+ /** Compact notation (`$1.4M`, `$42K`). */
687
+ compact?: boolean;
688
+ /** Apply semantic positive (green) / negative (red) text coloring. */
689
+ colorizeSign?: boolean;
690
+ /** Horizontal alignment (default `'right'`). */
691
+ align?: 'left' | 'center' | 'right';
692
+ }
693
+ /**
694
+ * Built-in financial / currency column preset using native `Intl.NumberFormat`
695
+ * with tabular numerals, right alignment, numeric sorting/filtering, and optional accounting notation.
696
+ */
697
+ declare function currencyColumn<TData = Record<string, unknown>>(options?: CurrencyColumnOptions): Partial<ColDef<TData, number>>;
698
+ interface PercentColumnOptions {
699
+ /**
700
+ * `'percent'` (default): `85` formats as `85%`.
701
+ * `'unit'`: `0.85` formats as `85%`.
702
+ */
703
+ scale?: 'percent' | 'unit';
704
+ /** BCP 47 locale (default `'en-US'`). */
705
+ locale?: string;
706
+ minimumFractionDigits?: number;
707
+ maximumFractionDigits?: number;
708
+ signDisplay?: 'auto' | 'always' | 'exceptZero' | 'never';
709
+ /** Apply semantic positive (green) / negative (red) text coloring. */
710
+ colorizeSign?: boolean;
711
+ align?: 'left' | 'center' | 'right';
712
+ }
713
+ /** Built-in percentage column preset with tabular numerals and numeric sort/filter. */
714
+ declare function percentColumn<TData = Record<string, unknown>>(options?: PercentColumnOptions): Partial<ColDef<TData, number>>;
715
+ interface BarColumnThresholds {
716
+ /** Value at or above which the bar uses the warning tone (or at/below when `invert: true`). */
717
+ warn?: number;
718
+ /** Value at or above which the bar uses the danger tone (or at/below when `invert: true`). */
719
+ danger?: number;
720
+ /** When `true`, lower values trigger `warn`/`danger` and higher values render in the success tone. */
721
+ invert?: boolean;
722
+ }
723
+ interface BarColumnOptions {
724
+ /** Minimum scale value (default `0`). */
725
+ min?: number;
726
+ /** Maximum scale value (default `100`). */
727
+ max?: number;
728
+ /** Display the formatted numeric label alongside the bar (default `true`). */
729
+ showValue?: boolean;
730
+ /** Custom value label formatter. Defaults to `${Math.round(v)}%` for 0–100 bars. */
731
+ valueFormatter?: (value: number) => string;
732
+ /** Optional custom CSS fill color (overrides tone coloring). */
733
+ color?: string;
734
+ /** Optional threshold-based semantic coloring (`accent`, `success`, `warning`, `danger`). */
735
+ thresholds?: BarColumnThresholds;
736
+ /** Bar track height in pixels (default `6`). */
737
+ height?: number;
738
+ }
739
+ /**
740
+ * Built-in progress / value bar column preset. Renders an accessible `role="progressbar"`
741
+ * inline bar using `--ya-*` theme tokens at 60fps across all framework adapters.
742
+ */
743
+ declare function barColumn<TData = Record<string, unknown>>(options?: BarColumnOptions): Partial<ColDef<TData, number>>;
744
+ type BadgeTone = 'success' | 'info' | 'warning' | 'danger' | 'purple' | 'neutral';
745
+ interface BadgeStyleConfig {
746
+ tone?: BadgeTone;
747
+ label?: string;
748
+ bg?: string;
749
+ color?: string;
750
+ }
751
+ interface BadgeColumnOptions {
752
+ /** Maps raw cell values to a semantic tone or custom label/color config. */
753
+ map?: Record<string, BadgeTone | BadgeStyleConfig>;
754
+ /** Fallback tone when a value is not present in `map` (default `'neutral'`). */
755
+ defaultTone?: BadgeTone;
756
+ /** Render a subtle status indicator dot before the label (default `false`). */
757
+ dot?: boolean;
758
+ }
759
+ /** Built-in theme-aware pill / status badge column preset. */
760
+ declare function badgeColumn<TData = Record<string, unknown>>(options?: BadgeColumnOptions): Partial<ColDef<TData, string>>;
761
+ interface BooleanColumnOptions {
762
+ /** Visual presentation: `'icon'` (default), `'pill'`, or `'text'`. */
763
+ style?: 'icon' | 'pill' | 'text';
764
+ /** Accessible / formatted label for `true` (default `'Yes'`). */
765
+ trueLabel?: string;
766
+ /** Accessible / formatted label for `false` (default `'No'`). */
767
+ falseLabel?: string;
768
+ }
769
+ /** Built-in boolean column preset with checkbox editing and icon/pill/text rendering. */
770
+ declare function booleanColumn<TData = Record<string, unknown>>(options?: BooleanColumnOptions): Partial<ColDef<TData, boolean>>;
771
+ interface SparklineColumnOptions {
772
+ /** Chart style: `'area'` (default), `'line'`, or `'bar'`. */
773
+ variant?: 'area' | 'line' | 'bar';
774
+ /** SVG width in pixels (default `88`). */
775
+ width?: number;
776
+ /** SVG height in pixels (default `22`). */
777
+ height?: number;
778
+ /** Line stroke width in pixels (default `1.6`). */
779
+ strokeWidth?: number;
780
+ /** Fixed CSS color override (disables automatic trend coloring unless omitted). */
781
+ color?: string;
782
+ /** Color green when last > first, red when last < first, neutral when flat (default `true`). */
783
+ trendColor?: boolean;
784
+ /** Show the formatted latest series value next to the sparkline (default `false`). */
785
+ showLastValue?: boolean;
786
+ /** Formats individual values for `showLastValue`, `aria-label`, and CSV export. */
787
+ valueFormatter?: (value: number) => string;
788
+ }
789
+ /**
790
+ * Built-in zero-dependency inline SVG sparkline column preset for `number[]` series.
791
+ * Supports `'area'`, `'line'`, and `'bar'` variants, trend coloring, and sorting by latest value.
792
+ */
793
+ declare function sparklineColumn<TData = Record<string, unknown>>(options?: SparklineColumnOptions): Partial<ColDef<TData, number[]>>;
794
+ /**
795
+ * Convenience map of default built-in column presets ready to pass into `GridOptions.columnTypes`:
796
+ * `currency`, `accounting`, `percent`, `bar`, `badge`, `boolean`, and `sparkline`.
797
+ */
798
+ declare function createBuiltInColumnTypes<TData = Record<string, unknown>>(): Record<string, ColumnTypeDef<TData>>;
799
+
651
800
  declare class YaGridCore<TData = Record<string, unknown>> {
652
801
  private options;
653
802
  private readonly eventBus;
@@ -838,4 +987,4 @@ declare class EventBus<TEventMap extends {
838
987
  clear(): void;
839
988
  }
840
989
 
841
- export { type AggFunc, type AggFuncParams, type BuiltInAggFunc, type CellClassParams, type CellClickedEvent, type CellEditorParams, type CellEditorType, type CellRenderer, type CellRendererParams, type CellValidatorParams, type CellValueChangedEvent, type ColDef, type ColGroupDef, ColumnController, type ColumnDefItem, type ColumnFilterModel, type ColumnMovedEvent, type ColumnPinnedEvent, type ColumnResizedEvent, type ColumnStateItem, type ColumnVisibilityChangedEvent, type ComponentMountAdapter, type CsvExportParams, type CustomFilterDef, DETAIL_COL_ID, type DateFilterModel, type DateFilterOperator, type DetailCellRenderer, type DetailCellRendererParams, type EditableParams, EventBus, type FilterChangedEvent, type FilterModel, type FilterType, type GlobalSearchConfig, type GridApi, type GridDensity, type GridEventMap, type GridOptions, type GridReadyEvent, type GridState, type GridThemeMode, type HeaderGroupMeta, type MountedComponentHandle, type NumberFilterModel, type NumberFilterOperator, type PaginationChangedEvent, type PaginationState, type PinnedDirection, type PinnedSummaryConfig, type ResolvedColDef, type ResponsivePinningConfig, type RowClickedEvent, type RowDataTransaction, type RowDataTransactionResult, type RowDetailToggledEvent, RowModel, type RowModelType, type RowNode, type RowSelectionConfig, SELECTION_COL_ID, type SelectionChangedEvent, SelectionController, type ServerSideDatasource, type ServerSideGetRowsRequest, type ServerSideGetRowsResult, type SetFilterModel, type SortChangedEvent, type SortDirection, type SortModelItem, type StateChangedEvent, type TextFilterModel, type TextFilterOperator, UndoRedoStack, type ValueFormatterParams, type ValueGetterParams, type ValueParserParams, type ValueSetterParams, type VanillaCellRendererFn, type VanillaDetailCellRendererFn, type VirtualizationConfig, YaGridCore, buildCsvString, buildQuickFilterHaystack, buildTsvString, createGrid, downloadCsvFile, filterRowNodes, getFormattedCellValue, getRawCellValue, isColGroupDef, matchesColumnFilter, normalizeSelectionConfig, parseQuickFilterTokens, resolveColumnFilterType, sortRowNodes };
990
+ export { type AggFunc, type AggFuncParams, type BadgeColumnOptions, type BadgeStyleConfig, type BadgeTone, type BarColumnOptions, type BarColumnThresholds, type BooleanColumnOptions, type BuiltInAggFunc, type CellClassParams, type CellClickedEvent, type CellEditorParams, type CellEditorType, type CellRenderer, type CellRendererParams, type CellValidatorParams, type CellValueChangedEvent, type ColDef, type ColGroupDef, ColumnController, type ColumnDefItem, type ColumnFilterModel, type ColumnMovedEvent, type ColumnPinnedEvent, type ColumnResizedEvent, type ColumnStateItem, type ColumnTypeDef, type ColumnVisibilityChangedEvent, type ComponentMountAdapter, type CsvExportParams, type CurrencyColumnOptions, type CustomFilterDef, DETAIL_COL_ID, type DateFilterModel, type DateFilterOperator, type DetailCellRenderer, type DetailCellRendererParams, type EditableParams, EventBus, type FilterChangedEvent, type FilterModel, type FilterType, type GlobalSearchConfig, type GridApi, type GridDensity, type GridEventMap, type GridOptions, type GridReadyEvent, type GridState, type GridThemeMode, type HeaderGroupMeta, type MountedComponentHandle, type NumberFilterModel, type NumberFilterOperator, type PaginationChangedEvent, type PaginationState, type PercentColumnOptions, type PinnedDirection, type PinnedSummaryConfig, type ResolvedColDef, type ResponsivePinningConfig, type RowClickedEvent, type RowDataTransaction, type RowDataTransactionResult, type RowDetailToggledEvent, RowModel, type RowModelType, type RowNode, type RowSelectionConfig, SELECTION_COL_ID, type SelectionChangedEvent, SelectionController, type ServerSideDatasource, type ServerSideGetRowsRequest, type ServerSideGetRowsResult, type SetFilterModel, type SortChangedEvent, type SortDirection, type SortModelItem, type SparklineColumnOptions, type StateChangedEvent, type TextFilterModel, type TextFilterOperator, UndoRedoStack, VANILLA_RENDERER_SYMBOL, type ValueFormatterParams, type ValueGetterParams, type ValueParserParams, type ValueSetterParams, type VanillaCellRendererFn, type VanillaDetailCellRendererFn, type VirtualizationConfig, YaGridCore, badgeColumn, barColumn, booleanColumn, buildCsvString, buildQuickFilterHaystack, buildTsvString, createBuiltInColumnTypes, createGrid, currencyColumn, downloadCsvFile, filterRowNodes, getFormattedCellValue, getRawCellValue, isColGroupDef, markVanillaRenderer, matchesColumnFilter, normalizeSelectionConfig, parseQuickFilterTokens, percentColumn, resolveColumnFilterType, sortRowNodes, sparklineColumn };