@ya-grid/core 0.4.0 → 0.5.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 +48 -1
- package/dist/index.js +127 -0
- package/dist/index.js.map +1 -1
- package/dist/styles.css +127 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -791,6 +791,53 @@ interface SparklineColumnOptions {
|
|
|
791
791
|
* Supports `'area'`, `'line'`, and `'bar'` variants, trend coloring, and sorting by latest value.
|
|
792
792
|
*/
|
|
793
793
|
declare function sparklineColumn<TData = Record<string, unknown>>(options?: SparklineColumnOptions): Partial<ColDef<TData, number[]>>;
|
|
794
|
+
type BuiltInActionIcon = 'edit' | 'delete' | 'view' | 'copy' | 'download' | 'plus' | 'check' | 'external' | 'more';
|
|
795
|
+
type ActionButtonTone = 'default' | 'primary' | 'danger';
|
|
796
|
+
type ActionButtonVariant = 'ghost' | 'outline' | 'solid';
|
|
797
|
+
interface ActionButtonParams<TData = Record<string, unknown>> extends CellRendererParams<TData, unknown> {
|
|
798
|
+
event: MouseEvent;
|
|
799
|
+
}
|
|
800
|
+
interface ActionButtonDef<TData = Record<string, unknown>> {
|
|
801
|
+
/** Stable identifier exposed as `data-ya-action="<id>"`. */
|
|
802
|
+
id: string;
|
|
803
|
+
/** Accessible button label (rendered visually unless `iconOnly: true`, always sets `aria-label`/`title`). */
|
|
804
|
+
label: string;
|
|
805
|
+
/**
|
|
806
|
+
* Optional icon: a built-in icon name (`'edit' | 'delete' | 'view' | 'copy' | 'download' | 'plus' | 'check' | 'external' | 'more'`),
|
|
807
|
+
* any custom text/emoji symbol, or a factory returning a DOM / SVG element.
|
|
808
|
+
*/
|
|
809
|
+
icon?: BuiltInActionIcon | (string & {}) | ((params: CellRendererParams<TData, unknown>) => HTMLElement | SVGElement | string | null);
|
|
810
|
+
/** Render only the icon while preserving `label` as `aria-label` and tooltip. */
|
|
811
|
+
iconOnly?: boolean;
|
|
812
|
+
/** Visual color intent (default `'default'`). */
|
|
813
|
+
tone?: ActionButtonTone;
|
|
814
|
+
/** Visual button style (defaults to `ActionsColumnOptions.variant` or `'ghost'`). */
|
|
815
|
+
variant?: ActionButtonVariant;
|
|
816
|
+
/** Custom hover tooltip (defaults to `label` when `iconOnly: true`). */
|
|
817
|
+
title?: string;
|
|
818
|
+
/** Disable the button statically or per row. */
|
|
819
|
+
disabled?: boolean | ((params: CellRendererParams<TData, unknown>) => boolean);
|
|
820
|
+
/** Hide the button statically or per row. */
|
|
821
|
+
hidden?: boolean | ((params: CellRendererParams<TData, unknown>) => boolean);
|
|
822
|
+
/** Invoked on click (event propagation is stopped automatically so row selection is not toggled). */
|
|
823
|
+
onClick: (params: ActionButtonParams<TData>) => void;
|
|
824
|
+
}
|
|
825
|
+
interface ActionsColumnOptions<TData = Record<string, unknown>> {
|
|
826
|
+
/** Static list or per-row factory of action buttons. */
|
|
827
|
+
actions: ActionButtonDef<TData>[] | ((params: CellRendererParams<TData, unknown>) => ActionButtonDef<TData>[]);
|
|
828
|
+
/** Default visual variant for buttons that omit `variant` (default `'ghost'`). */
|
|
829
|
+
variant?: ActionButtonVariant;
|
|
830
|
+
/** Horizontal alignment of the action button group (default `'center'`). */
|
|
831
|
+
align?: 'left' | 'center' | 'right';
|
|
832
|
+
/** Gap between buttons in pixels (default `4`). */
|
|
833
|
+
gap?: number;
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Built-in row action buttons column preset with optional built-in or custom icons,
|
|
837
|
+
* per-row disabled/hidden predicates, automatic click propagation stopping, and zero-overhead
|
|
838
|
+
* native DOM rendering across all framework adapters.
|
|
839
|
+
*/
|
|
840
|
+
declare function actionsColumn<TData = Record<string, unknown>>(options: ActionsColumnOptions<TData>): Partial<ColDef<TData, unknown>>;
|
|
794
841
|
/**
|
|
795
842
|
* Convenience map of default built-in column presets ready to pass into `GridOptions.columnTypes`:
|
|
796
843
|
* `currency`, `accounting`, `percent`, `bar`, `badge`, `boolean`, and `sparkline`.
|
|
@@ -987,4 +1034,4 @@ declare class EventBus<TEventMap extends {
|
|
|
987
1034
|
clear(): void;
|
|
988
1035
|
}
|
|
989
1036
|
|
|
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 };
|
|
1037
|
+
export { type ActionButtonDef, type ActionButtonParams, type ActionButtonTone, type ActionButtonVariant, type ActionsColumnOptions, type AggFunc, type AggFuncParams, type BadgeColumnOptions, type BadgeStyleConfig, type BadgeTone, type BarColumnOptions, type BarColumnThresholds, type BooleanColumnOptions, type BuiltInActionIcon, 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, actionsColumn, badgeColumn, barColumn, booleanColumn, buildCsvString, buildQuickFilterHaystack, buildTsvString, createBuiltInColumnTypes, createGrid, currencyColumn, downloadCsvFile, filterRowNodes, getFormattedCellValue, getRawCellValue, isColGroupDef, markVanillaRenderer, matchesColumnFilter, normalizeSelectionConfig, parseQuickFilterTokens, percentColumn, resolveColumnFilterType, sortRowNodes, sparklineColumn };
|
package/dist/index.js
CHANGED
|
@@ -856,6 +856,132 @@ function sparklineColumn(options = {}) {
|
|
|
856
856
|
cellRenderer: renderer
|
|
857
857
|
};
|
|
858
858
|
}
|
|
859
|
+
var ACTION_ICON_PATHS = {
|
|
860
|
+
edit: ["M11.5 2.5a1.414 1.414 0 0 1 2 2L5.5 12.5 2.5 13.5l1-3 8-8Z", "M10 4l2 2"],
|
|
861
|
+
delete: [
|
|
862
|
+
"M3 4.5h10",
|
|
863
|
+
"M6 4.5V3a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v1.5",
|
|
864
|
+
"M4.5 4.5l.6 8.2A1.2 1.2 0 0 0 6.3 13.8h3.4a1.2 1.2 0 0 0 1.2-1.1l.6-8.2",
|
|
865
|
+
"M6.75 7.25v4",
|
|
866
|
+
"M9.25 7.25v4"
|
|
867
|
+
],
|
|
868
|
+
view: [
|
|
869
|
+
"M1.75 8S4.25 3.75 8 3.75 14.25 8 14.25 8 11.75 12.25 8 12.25 1.75 8 1.75 8Z",
|
|
870
|
+
"M8 9.75a1.75 1.75 0 1 0 0-3.5 1.75 1.75 0 0 0 0 3.5Z"
|
|
871
|
+
],
|
|
872
|
+
copy: [
|
|
873
|
+
"M6 6h6.5a1 1 0 0 1 1 1v6.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1Z",
|
|
874
|
+
"M3.5 10.5H3a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1h6.5a1 1 0 0 1 1 1v.5"
|
|
875
|
+
],
|
|
876
|
+
download: [
|
|
877
|
+
"M8 2.5v7.5",
|
|
878
|
+
"M5.25 7.5 8 10.25 10.75 7.5",
|
|
879
|
+
"M2.75 11.5v1.25a1 1 0 0 0 1 1h8.5a1 1 0 0 0 1-1V11.5"
|
|
880
|
+
],
|
|
881
|
+
plus: ["M8 3.25v9.5", "M3.25 8h9.5"],
|
|
882
|
+
check: ["M3.25 8.5 6.5 11.75 12.75 4.5"],
|
|
883
|
+
external: [
|
|
884
|
+
"M9.5 2.5h4v4",
|
|
885
|
+
"M7 9l6.5-6.5",
|
|
886
|
+
"M12.5 9v3.5a1 1 0 0 1-1 1h-8a1 1 0 0 1-1-1v-8a1 1 0 0 1 1-1H7"
|
|
887
|
+
],
|
|
888
|
+
more: ["M4 8h.01", "M8 8h.01", "M12 8h.01"]
|
|
889
|
+
};
|
|
890
|
+
function createActionIconNode(icon, params) {
|
|
891
|
+
if (!icon) return null;
|
|
892
|
+
if (typeof icon === "function") {
|
|
893
|
+
const custom = icon(params);
|
|
894
|
+
if (custom === null || custom === void 0) return null;
|
|
895
|
+
if (typeof custom === "string") {
|
|
896
|
+
const span2 = document.createElement("span");
|
|
897
|
+
span2.className = "ya-action-icon";
|
|
898
|
+
span2.setAttribute("aria-hidden", "true");
|
|
899
|
+
span2.textContent = custom;
|
|
900
|
+
return span2;
|
|
901
|
+
}
|
|
902
|
+
return custom;
|
|
903
|
+
}
|
|
904
|
+
const paths = ACTION_ICON_PATHS[icon];
|
|
905
|
+
if (paths) {
|
|
906
|
+
const svg = document.createElementNS(SVG_NS, "svg");
|
|
907
|
+
svg.setAttribute("class", "ya-action-icon");
|
|
908
|
+
svg.setAttribute("width", "14");
|
|
909
|
+
svg.setAttribute("height", "14");
|
|
910
|
+
svg.setAttribute("viewBox", "0 0 16 16");
|
|
911
|
+
svg.setAttribute("fill", "none");
|
|
912
|
+
svg.setAttribute("aria-hidden", "true");
|
|
913
|
+
for (const d of paths) {
|
|
914
|
+
const p = document.createElementNS(SVG_NS, "path");
|
|
915
|
+
p.setAttribute("d", d);
|
|
916
|
+
p.setAttribute("stroke", "currentColor");
|
|
917
|
+
p.setAttribute("stroke-width", icon === "more" ? "2.4" : "1.5");
|
|
918
|
+
p.setAttribute("stroke-linecap", "round");
|
|
919
|
+
p.setAttribute("stroke-linejoin", "round");
|
|
920
|
+
svg.appendChild(p);
|
|
921
|
+
}
|
|
922
|
+
return svg;
|
|
923
|
+
}
|
|
924
|
+
const span = document.createElement("span");
|
|
925
|
+
span.className = "ya-action-icon";
|
|
926
|
+
span.setAttribute("aria-hidden", "true");
|
|
927
|
+
span.textContent = icon;
|
|
928
|
+
return span;
|
|
929
|
+
}
|
|
930
|
+
function actionsColumn(options) {
|
|
931
|
+
const { actions, variant: defaultVariant = "ghost", align = "center", gap = 4 } = options;
|
|
932
|
+
const renderer = markVanillaRenderer(
|
|
933
|
+
(params) => {
|
|
934
|
+
const defs = typeof actions === "function" ? actions(params) : actions;
|
|
935
|
+
const wrap = document.createElement("div");
|
|
936
|
+
wrap.className = "ya-actions-cell";
|
|
937
|
+
if (gap !== 4) wrap.style.gap = `${gap}px`;
|
|
938
|
+
for (const action of defs) {
|
|
939
|
+
const isHidden = typeof action.hidden === "function" ? action.hidden(params) : Boolean(action.hidden);
|
|
940
|
+
if (isHidden) continue;
|
|
941
|
+
const isDisabled = typeof action.disabled === "function" ? action.disabled(params) : Boolean(action.disabled);
|
|
942
|
+
const btn = document.createElement("button");
|
|
943
|
+
btn.type = "button";
|
|
944
|
+
btn.className = action.iconOnly ? "ya-action-btn ya-action-btn-icon-only" : "ya-action-btn";
|
|
945
|
+
btn.dataset.yaAction = action.id;
|
|
946
|
+
btn.dataset.tone = action.tone ?? "default";
|
|
947
|
+
btn.dataset.variant = action.variant ?? defaultVariant;
|
|
948
|
+
btn.disabled = isDisabled;
|
|
949
|
+
if (action.iconOnly) {
|
|
950
|
+
btn.setAttribute("aria-label", action.label);
|
|
951
|
+
}
|
|
952
|
+
const tooltip = action.title ?? (action.iconOnly ? action.label : void 0);
|
|
953
|
+
if (tooltip) btn.title = tooltip;
|
|
954
|
+
const iconNode = createActionIconNode(action.icon, params);
|
|
955
|
+
if (iconNode) btn.appendChild(iconNode);
|
|
956
|
+
if (!action.iconOnly || !iconNode) {
|
|
957
|
+
const lbl = document.createElement("span");
|
|
958
|
+
lbl.className = "ya-action-label";
|
|
959
|
+
lbl.textContent = action.label;
|
|
960
|
+
btn.appendChild(lbl);
|
|
961
|
+
}
|
|
962
|
+
btn.addEventListener("dblclick", (event) => {
|
|
963
|
+
event.stopPropagation();
|
|
964
|
+
});
|
|
965
|
+
btn.addEventListener("click", (event) => {
|
|
966
|
+
event.stopPropagation();
|
|
967
|
+
if (btn.disabled) return;
|
|
968
|
+
action.onClick({ ...params, event });
|
|
969
|
+
});
|
|
970
|
+
wrap.appendChild(btn);
|
|
971
|
+
}
|
|
972
|
+
return wrap;
|
|
973
|
+
}
|
|
974
|
+
);
|
|
975
|
+
return {
|
|
976
|
+
sortable: false,
|
|
977
|
+
filter: false,
|
|
978
|
+
searchable: false,
|
|
979
|
+
editable: false,
|
|
980
|
+
align,
|
|
981
|
+
valueFormatter: () => "",
|
|
982
|
+
cellRenderer: renderer
|
|
983
|
+
};
|
|
984
|
+
}
|
|
859
985
|
function createBuiltInColumnTypes() {
|
|
860
986
|
return {
|
|
861
987
|
currency: currencyColumn(),
|
|
@@ -6415,6 +6541,7 @@ export {
|
|
|
6415
6541
|
UndoRedoStack,
|
|
6416
6542
|
VANILLA_RENDERER_SYMBOL,
|
|
6417
6543
|
YaGridCore,
|
|
6544
|
+
actionsColumn,
|
|
6418
6545
|
badgeColumn,
|
|
6419
6546
|
barColumn,
|
|
6420
6547
|
booleanColumn,
|