@revolist/revogrid
Version:
Virtual reactive data grid spreadsheet component - RevoGrid.
1,016 lines (1,000 loc) • 93.9 kB
JavaScript
/*!
* Built by Revolist OU ❤️
*/
import { h, r as registerInstance, c as createEvent, H as Host, a as getElement } from './index-f6fae858.js';
import { c as columnTypes, K as reduce, D as getColumnType, r as rowTypes, i as isRowType, E as getColumnSizes, O as EMPTY_INDEX, J as getColumnByProp, H as getColumns, Q as SelectionStoreConnector } from './column.service-e3c41fb8.js';
import { D as DataStore, b as getSourceItem, f as getSourceItemVirtualIndexByProp, d as setSourceByPhysicalIndex, s as setSourceByVirtualIndex, a as getVisibleSourceItem, h as gatherTrimmedItems, k as getItemByIndex, R as RESIZE_INTERVAL, u as timeout } from './dimension.helpers-87e12689.js';
import { d as debounce } from './debounce-b3166f78.js';
import { D as DimensionStore, B as BasePlugin, G as GroupingRowPlugin, S as StretchColumn, i as isStretchPlugin, A as AutoSizeColumnPlugin, d as FilterPlugin, E as ExportFilePlugin, l as SortingPlugin, C as ColumnMovePlugin } from './column.drag.plugin-c6b89504.js';
import { V as ViewportStore } from './viewport.store-84060ef5.js';
import { v as viewportDataPartition, H as HEADER_SLOT, C as CONTENT_SLOT, F as FOOTER_SLOT, D as DATA_SLOT } from './viewport.helpers-7e7f9dad.js';
import { g as getPropertyFromEvent } from './events-cf0893a3.js';
import './filter.button-84396156.js';
import './header-cell-renderer-c2acd090.js';
class ThemeCompact {
constructor() {
this.defaultRowSize = 32;
}
}
class ThemeDefault {
constructor() {
this.defaultRowSize = 27;
}
}
class ThemeMaterial {
constructor() {
this.defaultRowSize = 42;
}
}
const DEFAULT_THEME = 'default';
const allowedThemes = [
DEFAULT_THEME,
'material',
'compact',
'darkMaterial',
'darkCompact',
];
class ThemeService {
get theme() {
return this.currentTheme;
}
get rowSize() {
return this.customRowSize || this.currentTheme.defaultRowSize;
}
set rowSize(size) {
this.customRowSize = size;
}
constructor(cfg) {
this.customRowSize = 0;
this.customRowSize = cfg.rowSize;
this.register('default');
}
register(theme) {
const parsedTheme = getTheme(theme);
switch (parsedTheme) {
case 'material':
case 'darkMaterial':
this.currentTheme = new ThemeMaterial();
break;
case 'compact':
case 'darkCompact':
this.currentTheme = new ThemeCompact();
break;
default:
this.currentTheme = new ThemeDefault();
break;
}
}
}
function getTheme(theme) {
if (theme && allowedThemes.indexOf(theme) > -1) {
return theme;
}
return DEFAULT_THEME;
}
class ColumnDataProvider {
get stores() {
return this.dataSources;
}
constructor() {
this.collection = null;
this.dataSources = columnTypes.reduce((sources, k) => {
sources[k] = new DataStore(k);
return sources;
}, {});
}
column(c, type = 'rgCol') {
return this.getColumn(c, type);
}
getColumn(virtualIndex, type) {
return getSourceItem(this.dataSources[type].store, virtualIndex);
}
getRawColumns() {
return reduce(this.dataSources, (result, item, type) => {
result[type] = item.store.get('source');
return result;
}, {
rgCol: [],
colPinStart: [],
colPinEnd: [],
});
}
getColumns(type = 'all') {
const columnsByType = this.getRawColumns();
if (type !== 'all') {
return columnsByType[type];
}
return columnTypes.reduce((r, t) => [...r, ...columnsByType[t]], []);
}
getColumnIndexByProp(prop, type) {
return getSourceItemVirtualIndexByProp(this.dataSources[type].store, prop);
}
getColumnByProp(prop) {
var _a;
return (_a = this.collection) === null || _a === void 0 ? void 0 : _a.columnByProp[prop];
}
refreshByType(type) {
this.dataSources[type].refresh();
}
/**
* Main method to set columns
*/
setColumns(data) {
columnTypes.forEach(k => {
// set columns data
this.dataSources[k].updateData(data.columns[k], {
// max depth level
depth: data.maxLevel,
// groups
groups: data.columnGrouping[k].reduce((res, g) => {
if (!res[g.level]) {
res[g.level] = [];
}
res[g.level].push(g);
return res;
}, {}),
});
});
this.collection = data;
return data;
}
/**
* Used in plugins
* Modify columns in store
*/
updateColumns(updatedColumns) {
// collect column by type and propert
const columnByKey = updatedColumns.reduce((res, c) => {
const type = getColumnType(c);
if (!res[type]) {
res[type] = {};
}
res[type][c.prop] = c;
return res;
}, {});
// find indexes in source
const colByIndex = {};
for (const t in columnByKey) {
if (!columnByKey.hasOwnProperty(t)) {
continue;
}
const type = t;
const colsToUpdate = columnByKey[type];
const sourceItems = this.dataSources[type].store.get('source');
colByIndex[type] = {};
for (let i = 0; i < sourceItems.length; i++) {
const column = sourceItems[i];
const colToUpdateIfExists = colsToUpdate === null || colsToUpdate === void 0 ? void 0 : colsToUpdate[column.prop];
// update column if exists in source
if (colToUpdateIfExists) {
colByIndex[type][i] = colToUpdateIfExists;
}
}
}
for (const t in colByIndex) {
if (!colByIndex.hasOwnProperty(t)) {
continue;
}
const type = t;
setSourceByPhysicalIndex(this.dataSources[type].store, colByIndex[type] || {});
}
}
updateColumn(column, index) {
const type = getColumnType(column);
setSourceByVirtualIndex(this.dataSources[type].store, { [index]: column });
}
}
/**
* Data source provider
*
* @dependsOn DimensionProvider
*/
class DataProvider {
constructor(dimensionProvider) {
this.dimensionProvider = dimensionProvider;
this.stores = reduce(rowTypes, (sources, k) => {
sources[k] = new DataStore(k);
return sources;
}, {});
}
setData(data, type = 'rgRow', disableVirtualRows = false, grouping, silent = false) {
// set rgRow data
this.stores[type].updateData([...data], grouping, silent);
// for pinned row no need virtual data
const noVirtual = type !== 'rgRow' || disableVirtualRows;
this.dimensionProvider.setData(data.length, type, noVirtual);
return data;
}
getModel(virtualIndex, type = 'rgRow') {
const store = this.stores[type].store;
return getSourceItem(store, virtualIndex);
}
changeOrder({ rowType = 'rgRow', from, to }) {
const storeService = this.stores[rowType];
// take currently visible row indexes
const newItemsOrder = [...storeService.store.get('proxyItems')];
const prevItems = storeService.store.get('items');
// take out
const toMove = newItemsOrder.splice(newItemsOrder.indexOf(prevItems[from]), // get index in proxy
1);
// insert before
newItemsOrder.splice(newItemsOrder.indexOf(prevItems[to]), // get index in proxy
0, ...toMove);
storeService.setData({
proxyItems: newItemsOrder,
});
// take currently visible row indexes
const newItems = storeService.store.get('items');
this.dimensionProvider.updateSizesPositionByNewDataIndexes(rowType, newItems, prevItems);
}
setCellData({ type, rowIndex, prop, val }, mutate = true) {
const model = this.getModel(rowIndex, type);
model[prop] = val;
this.stores[type].setSourceData({ [rowIndex]: model }, mutate);
}
setRangeData(data, type) {
const items = {};
for (let rowIndex in data) {
const oldModel = (items[rowIndex] = getSourceItem(this.stores[type].store, parseInt(rowIndex, 10)));
if (!oldModel) {
continue;
}
for (let prop in data[rowIndex]) {
oldModel[prop] = data[rowIndex][prop];
}
}
this.stores[type].setSourceData(items);
}
refresh(type = 'all') {
if (isRowType(type)) {
this.refreshItems(type);
}
rowTypes.forEach((t) => this.refreshItems(t));
}
refreshItems(type = 'rgRow') {
const items = this.stores[type].store.get('items');
this.stores[type].setData({ items: [...items] });
}
setGrouping({ depth }, type = 'rgRow') {
this.stores[type].setData({ groupingDepth: depth });
}
setTrimmed(trimmed, type = 'rgRow') {
const store = this.stores[type];
store.addTrimmed(trimmed);
this.dimensionProvider.setTrimmed(trimmed, type);
if (type === 'rgRow') {
this.dimensionProvider.setData(getVisibleSourceItem(store.store).length, type);
}
}
}
/**
* Dimension provider
* Stores dimension information and custom sizes
*
* @dependsOn ViewportProvider
*/
class DimensionProvider {
constructor(viewports, config) {
this.viewports = viewports;
const sizeChanged = debounce((k) => config.realSizeChanged(k), RESIZE_INTERVAL);
this.stores = reduce([...rowTypes, ...columnTypes], (sources, t) => {
sources[t] = new DimensionStore(t);
sources[t].store.onChange('realSize', () => sizeChanged(t));
return sources;
}, {});
}
/**
* Clear old sizes from dimension and viewports
* @param type - dimension type
* @param count - count of items
*/
clearSize(t, count) {
this.stores[t].drop();
// after we done with drop trigger viewport recalculaction
this.viewports.stores[t].setOriginalSizes(this.stores[t].store.get('originItemSize'));
this.setItemCount(count, t);
}
/**
* Apply new custom sizes to dimension and view port
* @param type - dimension type
* @param sizes - new custom sizes
* @param keepOld - keep old sizes merge new with old
*/
setCustomSizes(type, sizes, keepOld = false) {
let newSizes = sizes;
if (keepOld) {
const oldSizes = this.stores[type].store.get('sizes');
newSizes = Object.assign(Object.assign({}, oldSizes), sizes);
}
this.stores[type].setDimensionSize(newSizes);
this.setViewPortCoordinate({
type,
force: true,
});
}
setItemCount(realCount, type) {
this.viewports.stores[type].setViewport({ realCount });
this.stores[type].setStore({ count: realCount });
}
/**
* Apply trimmed items
* @param trimmed - trimmed items
* @param type
*/
setTrimmed(trimmed, type) {
const allTrimmed = gatherTrimmedItems(trimmed);
const dimStoreType = this.stores[type];
dimStoreType.setStore({ trimmed: allTrimmed });
this.setViewPortCoordinate({
type,
force: true,
});
}
/**
* Sets dimension data and viewport coordinate
* @param itemCount
* @param type - dimension type
* @param noVirtual - disable virtual data
*/
setData(itemCount, type, noVirtual = false) {
this.setItemCount(itemCount, type);
// Virtualization will get disabled
if (noVirtual) {
const dimension = this.stores[type].getCurrentState();
this.viewports.stores[type].setViewport({
virtualSize: dimension.realSize,
});
}
this.setViewPortCoordinate({
type,
});
}
/**
* Applies new columns to the dimension provider
* @param columns - new columns data
* @param disableVirtualX - disable virtual data for X axis
*/
applyNewColumns(columns, disableVirtualX, keepOld = false) {
// Apply new columns to dimension provider
for (let type of columnTypes) {
if (!keepOld) {
// Clear existing data in the dimension provider
this.stores[type].drop();
}
// Get the new columns for the current type
const items = columns[type];
// Determine if virtual data should be disabled for the current type
const noVirtual = type !== 'rgCol' || disableVirtualX;
// Set the items count in the dimension provider
this.stores[type].setStore({ count: items.length });
// Set the custom sizes for the columns
const newSizes = getColumnSizes(items);
this.stores[type].setDimensionSize(newSizes);
// Update the viewport with new data
const vpUpdate = {
// This triggers drop on realCount change
realCount: items.length,
};
// If virtual data is disabled, set the virtual size to the real size
if (noVirtual) {
vpUpdate.virtualSize = this.stores[type].getCurrentState().realSize;
}
// Update the viewport
this.viewports.stores[type].setViewport(vpUpdate);
this.setViewPortCoordinate({
type,
});
}
}
/**
* Gets the full size of the grid by summing up the sizes of all dimensions
* Goes through all dimensions columnTypes (x) and rowTypes (y) and sums up their sizes
*/
getFullSize() {
var _a, _b;
let x = 0;
let y = 0;
for (let type of columnTypes) {
x += ((_a = this.stores[type]) === null || _a === void 0 ? void 0 : _a.store.get('realSize')) || 0;
}
for (let type of rowTypes) {
y += ((_b = this.stores[type]) === null || _b === void 0 ? void 0 : _b.store.get('realSize')) || 0;
}
return { y, x };
}
setViewPortCoordinate({ type, coordinate = this.viewports.stores[type].lastCoordinate, force = false, }) {
const dimension = this.stores[type].getCurrentState();
this.viewports.stores[type].setViewPortCoordinate(coordinate, dimension, force);
}
getViewPortPos(e) {
const dimension = this.stores[e.dimension].getCurrentState();
const item = getItemByIndex(dimension, e.coordinate);
return item.start;
}
setSettings(data, dimensionType) {
let stores = [];
switch (dimensionType) {
case 'rgCol':
stores = columnTypes;
break;
case 'rgRow':
stores = rowTypes;
break;
}
for (let s of stores) {
this.stores[s].setStore(data);
}
}
updateSizesPositionByNewDataIndexes(type, newItemsOrder, prevItemsOrder = []) {
// Move custom sizes to new order
this.stores[type].updateSizesPositionByIndexes(newItemsOrder, prevItemsOrder);
this.setViewPortCoordinate({
type,
force: true,
});
}
}
class ViewportProvider {
constructor() {
this.stores = reduce([...rowTypes, ...columnTypes], (sources, k) => {
sources[k] = new ViewportStore(k);
return sources;
}, {});
}
setViewport(type, data) {
this.stores[type].setViewport(data);
}
}
/** Collect Column data */
function gatherColumnData(data) {
const colDimension = data.dimensions[data.colType].store;
const realWidth = colDimension.get('realSize');
const prop = {
contentWidth: realWidth,
class: data.colType,
contentHeight: data.contentHeight,
key: data.colType,
colType: data.colType,
onResizeviewport: data.onResizeviewport,
// set viewport size to real size
style: data.fixWidth ? { minWidth: `${realWidth}px` } : undefined,
};
const headerProp = {
colData: getVisibleSourceItem(data.colStore),
dimensionCol: colDimension,
type: data.colType,
groups: data.colStore.get('groups'),
groupingDepth: data.colStore.get('groupingDepth'),
resizeHandler: data.colType === 'colPinEnd' ? ['l'] : undefined,
onHeaderresize: data.onHeaderresize,
};
return {
prop,
type: data.colType,
position: data.position,
headerProp,
viewportCol: data.viewports[data.colType].store,
};
}
class ViewportService {
constructor(config, contentHeight) {
var _a, _b;
this.config = config;
(_a = this.config.selectionStoreConnector) === null || _a === void 0 ? void 0 : _a.beforeUpdate();
// ----------- Handle columns ----------- //
// Transform data from stores and apply it to different components
const columns = [];
let x = 0; // we increase x only if column present
columnTypes.forEach(val => {
const colStore = config.columnProvider.stores[val].store;
// only columns that have data show
if (!colStore.get('items').length) {
return;
}
const column = {
colType: val,
position: { x, y: 1 },
contentHeight,
// only central column has dynamic width
fixWidth: val !== 'rgCol',
viewports: config.viewportProvider.stores,
dimensions: config.dimensionProvider.stores,
rowStores: config.dataProvider.stores,
colStore,
onHeaderresize: e => this.onColumnResize(val, e, colStore),
};
if (val === 'rgCol') {
column.onResizeviewport = (e) => {
var _a;
const vpState = {
clientSize: e.detail.size,
};
// virtual size will be handled by dimension provider if disabled
if ((e.detail.dimension === 'rgRow' && !config.disableVirtualY)
|| (e.detail.dimension === 'rgCol' && !config.disableVirtualX)) {
vpState.virtualSize = e.detail.size;
}
(_a = config.viewportProvider) === null || _a === void 0 ? void 0 : _a.setViewport(e.detail.dimension, vpState);
};
}
const colData = gatherColumnData(column);
const columnSelectionStore = this.registerCol(colData.position.x, val);
// render per each column data collections vertically
const dataPorts = this.dataViewPort(column).reduce((r, rgRow) => {
// register selection store for Segment
const segmentSelection = this.registerSegment(rgRow.position);
segmentSelection.setLastCell(rgRow.lastCell);
// register selection store for Row
const rowSelectionStore = this.registerRow(rgRow.position.y, rgRow.type);
const rowDef = Object.assign(Object.assign({ colType: val }, rgRow), { rowSelectionStore, selectionStore: segmentSelection.store, ref: (e) => config.selectionStoreConnector.registerSection(e), onSetrange: e => {
segmentSelection.setRangeArea(e.detail);
}, onSettemprange: e => segmentSelection.setTempArea(e.detail), onFocuscell: e => {
// todo: multi focus
segmentSelection.clearFocus();
config.selectionStoreConnector.focus(segmentSelection, e.detail);
} });
r.push(rowDef);
return r;
}, []);
columns.push(Object.assign(Object.assign({}, colData), { columnSelectionStore,
dataPorts }));
x++;
});
this.columns = columns;
// ----------- Handle columns end ----------- //
(_b = this.config.scrollingService) === null || _b === void 0 ? void 0 : _b.unregister();
}
onColumnResize(type, { detail }, store) {
var _a;
// apply to dimension provider
(_a = this.config.dimensionProvider) === null || _a === void 0 ? void 0 : _a.setCustomSizes(type, detail, true);
// set resize event
const changedItems = {};
for (const [i, size] of Object.entries(detail || {})) {
const virtualIndex = parseInt(i, 10);
const item = getSourceItem(store, virtualIndex);
if (item) {
changedItems[virtualIndex] = Object.assign(Object.assign({}, item), { size });
}
}
this.config.resize(changedItems);
}
/** register selection store for Segment */
registerSegment(position) {
return this.config.selectionStoreConnector.register(position);
}
/** register selection store for Row */
registerRow(y, type) {
return this.config.selectionStoreConnector.registerRow(y, type).store;
}
/** register selection store for Column */
registerCol(x, type) {
return this.config.selectionStoreConnector.registerColumn(x, type).store;
}
/** Collect Row data */
dataViewPort(data) {
const slots = {
rowPinStart: HEADER_SLOT,
rgRow: CONTENT_SLOT,
rowPinEnd: FOOTER_SLOT,
};
// y position for selection
let y = 0;
return rowTypes.reduce((result, type) => {
// filter out empty sources, we still need to return source to keep slot working
const isPresent = data.viewports[type].store.get('realCount') || type === 'rgRow';
const rgCol = Object.assign(Object.assign({}, data), { position: Object.assign(Object.assign({}, data.position), { y: isPresent ? y : EMPTY_INDEX }) });
const partition = viewportDataPartition(rgCol, type, slots[type], type !== 'rgRow');
result.push(partition);
if (isPresent) {
y++;
}
return result;
}, []);
}
scrollToCell(cell) {
for (let key in cell) {
const coordinate = cell[key];
if (typeof coordinate === 'number') {
this.config.scrollingService.proxyScroll({
dimension: key === 'x' ? 'rgCol' : 'rgRow',
coordinate,
});
}
}
}
/**
* Clear current grid focus
*/
clearFocused() {
this.config.selectionStoreConnector.clearAll();
}
clearEdit() {
this.config.selectionStoreConnector.setEdit(false);
}
/**
* Collect focused element data
*/
getFocused() {
const focused = this.config.selectionStoreConnector.focusedStore;
if (!focused) {
return null;
}
// get column data
const colType = this.config.selectionStoreConnector.storesXToType[focused.position.x];
const column = this.config.columnProvider.getColumn(focused.cell.x, colType);
// get row data
const rowType = this.config.selectionStoreConnector.storesYToType[focused.position.y];
const model = this.config.dataProvider.getModel(focused.cell.y, rowType);
return {
column,
model,
cell: focused.cell,
colType,
rowType,
};
}
getStoreCoordinateByType(colType, rowType) {
const stores = this.config.selectionStoreConnector.storesByType;
if (typeof stores[colType] === 'undefined' || typeof stores[rowType] === 'undefined') {
return;
}
return {
x: stores[colType],
y: stores[rowType],
};
}
setFocus(colType, rowType, start, end) {
var _a;
const coordinate = this.getStoreCoordinateByType(colType, rowType);
if (coordinate) {
(_a = this.config.selectionStoreConnector) === null || _a === void 0 ? void 0 : _a.focusByCell(coordinate, start, end);
}
}
getSelectedRange() {
const focused = this.config.selectionStoreConnector.focusedStore;
if (!focused) {
return null;
}
// get column data
const colType = this.config.selectionStoreConnector.storesXToType[focused.position.x];
// get row data
const rowType = this.config.selectionStoreConnector.storesYToType[focused.position.y];
const range = focused.entity.store.get('range');
if (!range) {
return null;
}
return Object.assign(Object.assign({}, range), { colType,
rowType });
}
setEdit(rowIndex, colIndex, colType, rowType) {
var _a;
const coordinate = this.getStoreCoordinateByType(colType, rowType);
if (coordinate) {
(_a = this.config.selectionStoreConnector) === null || _a === void 0 ? void 0 : _a.setEditByCell(coordinate, { x: colIndex, y: rowIndex });
}
}
}
class GridScrollingService {
constructor(setViewport) {
this.setViewport = setViewport;
this.elements = {};
}
async proxyScroll(e, key) {
var _a;
let newEventPromise;
let event = e;
for (let elKey in this.elements) {
// skip
if (e.dimension === 'rgCol' && elKey === 'headerRow') {
continue;
// pinned column only
}
else if (this.isPinnedColumn(key) && e.dimension === 'rgCol') {
if (elKey === key || !e.delta) {
continue;
}
for (let el of this.elements[elKey]) {
if (el.changeScroll) {
newEventPromise = el.changeScroll(e);
}
}
}
else {
for (let el of this.elements[elKey]) {
await ((_a = el.setScroll) === null || _a === void 0 ? void 0 : _a.call(el, e));
}
}
}
const newEvent = await newEventPromise;
if (newEvent) {
event = newEvent;
}
this.setViewport(event);
}
/**
* Silent scroll update for mobile devices when we have negative scroll top
*/
async scrollSilentService(e, key) {
var _a;
for (let elKey in this.elements) {
// skip same element update
if (elKey === key) {
continue;
}
if (columnTypes.includes(key) &&
(elKey === 'headerRow' ||
columnTypes.includes(elKey))) {
for (let el of this.elements[elKey]) {
await ((_a = el.changeScroll) === null || _a === void 0 ? void 0 : _a.call(el, e, true));
}
continue;
}
}
}
isPinnedColumn(key) {
return !!key && ['colPinStart', 'colPinEnd'].indexOf(key) > -1;
}
registerElements(els) {
this.elements = els;
}
/**
* Register new element for farther scroll support
* @param el - can be null if holder removed
* @param key - element key
*/
registerElement(el, key) {
if (!this.elements[key]) {
this.elements[key] = [];
}
// new element added
if (el) {
this.elements[key].push(el);
}
else if (this.elements[key]) {
// element removed
delete this.elements[key];
}
}
unregister() {
this.elements = {};
}
}
/**
* Draw drag
*/
class OrdererService {
constructor() {
this.parentY = 0;
}
start(parent, { pos, text, event }) {
var _a;
const { top } = parent.getBoundingClientRect();
this.parentY = top;
if (this.text) {
this.text.innerText = text;
}
this.move(pos);
this.moveTip({ x: event.x, y: event.y });
(_a = this.el) === null || _a === void 0 ? void 0 : _a.classList.remove('hidden');
}
end() {
var _a;
(_a = this.el) === null || _a === void 0 ? void 0 : _a.classList.add('hidden');
}
move(pos) {
this.moveElement(pos.end - this.parentY);
}
moveTip({ x, y }) {
if (!this.draggable) {
return;
}
this.draggable.style.left = `${x}px`;
this.draggable.style.top = `${y}px`;
}
moveElement(y) {
if (!this.rgRow) {
return;
}
this.rgRow.style.transform = `translateY(${y}px)`;
}
}
const OrderRenderer = ({ ref }) => {
const service = new OrdererService();
ref(service);
return (h("div", { class: "draggable-wrapper hidden", ref: e => (service.el = e) },
h("div", { class: "draggable", ref: el => (service.draggable = el) },
h("span", { class: "revo-alt-icon" }),
h("span", { ref: e => (service.text = e) })),
h("div", { class: "drag-position", ref: e => (service.rgRow = e) })));
};
const rowDefinitionByType = (newVal = []) => {
const result = {};
for (const v of newVal) {
let rowDefs = result[v.type];
if (!rowDefs) {
rowDefs = result[v.type] = {};
}
if (v.size) {
if (!rowDefs.sizes) {
rowDefs.sizes = {};
}
rowDefs.sizes[v.index] = v.size;
}
}
return result;
};
const rowDefinitionRemoveByType = (oldVal = []) => {
const result = {};
for (const v of oldVal) {
let rowDefs = result[v.type];
if (!rowDefs) {
rowDefs = result[v.type] = [];
}
if (v.size) {
rowDefs.push(v.index);
}
}
return result;
};
function isMobileDevice() {
return /Mobi/i.test(navigator.userAgent) || /Android/i.test(navigator.userAgent) || navigator.maxTouchPoints > 0;
}
/**
* WCAG Plugin is responsible for enhancing the accessibility features of the RevoGrid component.
* It ensures that the grid is fully compliant with Web Content Accessibility Guidelines (WCAG) 2.1.
* This plugin should be the last plugin you add, as it modifies the grid's default behavior.
*
* The WCAG Plugin performs the following tasks:
* - Sets the 'dir' attribute to 'ltr' for left-to-right text direction.
* - Sets the 'role' attribute to 'treegrid' for treelike hierarchical structure.
* - Sets the 'aria-keyshortcuts' attribute to 'Enter' and 'Esc' for keyboard shortcuts.
* - Adds event listeners for keyboard navigation and editing.
*
* By default, the plugin adds ARIA roles and properties to the grid elements, providing semantic information
* for assistive technologies. These roles include 'grid', 'row', and 'gridcell'. The plugin also sets
* ARIA attributes such as 'aria-rowindex', 'aria-colindex', and 'aria-selected'.
*
* The WCAG Plugin ensures that the grid is fully functional and usable for users with various disabilities,
* including visual impairments, deaf-blindness, and cognitive disabilities.
*
* Note: The WCAG Plugin should be added as the last plugin in the list of plugins, as it modifies the grid's
* default behavior and may conflict with other plugins if added earlier.
*/
class WCAGPlugin extends BasePlugin {
constructor(revogrid, providers) {
super(revogrid, providers);
revogrid.setAttribute('dir', 'ltr');
revogrid.setAttribute('role', 'treegrid');
revogrid.setAttribute('aria-keyshortcuts', 'Enter');
revogrid.setAttribute('aria-multiselectable', 'true');
revogrid.setAttribute('tabindex', '0');
/**
* Before Columns Set Event
*/
this.addEventListener('beforecolumnsset', ({ detail }) => {
const columns = [
...detail.columns.colPinStart,
...detail.columns.rgCol,
...detail.columns.colPinEnd,
];
revogrid.setAttribute('aria-colcount', `${columns.length}`);
columns.forEach((column, index) => {
const { columnProperties, cellProperties } = column;
column.columnProperties = (...args) => {
const result = (columnProperties === null || columnProperties === void 0 ? void 0 : columnProperties(...args)) || {};
result.role = 'columnheader';
result['aria-colindex'] = index;
return result;
};
column.cellProperties = (...args) => {
const wcagProps = {
['role']: 'gridcell',
['aria-colindex']: index,
['aria-rowindex']: args[0].rowIndex,
['tabindex']: -1,
};
const columnProps = (cellProperties === null || cellProperties === void 0 ? void 0 : cellProperties(...args)) || {};
return Object.assign(Object.assign({}, wcagProps), columnProps);
};
});
});
/**
* Before Row Set Event
*/
this.addEventListener('beforesourceset', ({ detail, }) => {
revogrid.setAttribute('aria-rowcount', `${detail.source.length}`);
});
this.addEventListener('beforerowrender', ({ detail, }) => {
detail.node.$attrs$ = Object.assign(Object.assign({}, detail.node.$attrs$), { role: 'row', ['aria-rowindex']: detail.item.itemIndex });
});
// focuscell
this.addEventListener('afterfocus', async (e) => {
if (e.defaultPrevented) {
return;
}
const el = this.revogrid.querySelector(`revogr-data[type="${e.detail.rowType}"][col-type="${e.detail.colType}"] [data-rgrow="${e.detail.rowIndex}"][data-rgcol="${e.detail.colIndex}"]`);
if (el instanceof HTMLElement) {
el.focus();
}
});
}
}
/**
* Plugin service
* Manages plugins
*/
class PluginService {
constructor() {
/**
* Plugins
* Define plugins collection
*/
this.internalPlugins = [];
}
/**
* Get all plugins
*/
get() {
return [...this.internalPlugins];
}
/**
* Add plugin to collection
*/
add(plugin) {
this.internalPlugins.push(plugin);
}
/**
* Add user plugins and create
*/
addUserPluginsAndCreate(element, plugins = [], prevPlugins, pluginData) {
if (!pluginData) {
return;
}
// Step 1: Identify plugins to remove, compare new and old plugins
const pluginsToRemove = (prevPlugins === null || prevPlugins === void 0 ? void 0 : prevPlugins.filter(prevPlugin => !plugins.some(userPlugin => userPlugin === prevPlugin))) || [];
// Step 2: Remove old plugins
pluginsToRemove.forEach(plugin => {
var _a, _b;
const index = this.internalPlugins.findIndex(createdPlugin => createdPlugin instanceof plugin);
if (index !== -1) {
(_b = (_a = this.internalPlugins[index]).destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
this.internalPlugins.splice(index, 1); // Remove the plugin
}
});
// Step 3: Register user plugins
plugins === null || plugins === void 0 ? void 0 : plugins.forEach(userPlugin => {
// check if plugin already exists, if so, skip
const existingPlugin = this.internalPlugins.find(createdPlugin => createdPlugin instanceof userPlugin);
if (existingPlugin) {
return;
}
this.add(new userPlugin(element, pluginData));
});
}
/**
* Get plugin by class
*/
getByClass(pluginClass) {
return this.internalPlugins.find(p => p instanceof pluginClass);
}
/**
* Remove plugin
*/
remove(plugin) {
var _a, _b;
const index = this.internalPlugins.indexOf(plugin);
if (index > -1) {
(_b = (_a = this.internalPlugins[index]).destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
this.internalPlugins.splice(index, 1);
}
}
/**
* Remove all plugins
*/
destroy() {
this.internalPlugins.forEach(p => { var _a; return (_a = p.destroy) === null || _a === void 0 ? void 0 : _a.call(p); });
this.internalPlugins = [];
}
}
const revoGridStyleCss = ".revo-drag-icon{width:11px;opacity:0.8}.revo-drag-icon::before{content:\"::\"}.revo-alt-icon{-webkit-mask-image:url(\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg viewBox='0 0 384 383' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cg%3E%3Cpath d='M192.4375,383 C197.424479,383 201.663411,381.254557 205.154297,377.763672 L205.154297,377.763672 L264.25,318.667969 C270.234375,312.683594 271.605794,306.075846 268.364258,298.844727 C265.122721,291.613607 259.51237,287.998047 251.533203,287.998047 L251.533203,287.998047 L213.382812,287.998047 L213.382812,212.445312 L288.935547,212.445312 L288.935547,250.595703 C288.935547,258.57487 292.551107,264.185221 299.782227,267.426758 C307.013346,270.668294 313.621094,269.296875 319.605469,263.3125 L319.605469,263.3125 L378.701172,204.216797 C382.192057,200.725911 383.9375,196.486979 383.9375,191.5 C383.9375,186.513021 382.192057,182.274089 378.701172,178.783203 L378.701172,178.783203 L319.605469,119.6875 C313.621094,114.201823 307.013346,112.955078 299.782227,115.947266 C292.551107,118.939453 288.935547,124.42513 288.935547,132.404297 L288.935547,132.404297 L288.935547,170.554688 L213.382812,170.554688 L213.382812,95.0019531 L251.533203,95.0019531 C259.51237,95.0019531 264.998047,91.3863932 267.990234,84.1552734 C270.982422,76.9241536 269.735677,70.3164062 264.25,64.3320312 L264.25,64.3320312 L205.154297,5.23632812 C201.663411,1.74544271 197.424479,0 192.4375,0 C187.450521,0 183.211589,1.74544271 179.720703,5.23632812 L179.720703,5.23632812 L120.625,64.3320312 C114.640625,70.3164062 113.269206,76.9241536 116.510742,84.1552734 C119.752279,91.3863932 125.36263,95.0019531 133.341797,95.0019531 L133.341797,95.0019531 L171.492188,95.0019531 L171.492188,170.554688 L95.9394531,170.554688 L95.9394531,132.404297 C95.9394531,124.42513 92.3238932,118.814779 85.0927734,115.573242 C77.8616536,112.331706 71.2539062,113.703125 65.2695312,119.6875 L65.2695312,119.6875 L6.17382812,178.783203 C2.68294271,182.274089 0.9375,186.513021 0.9375,191.5 C0.9375,196.486979 2.68294271,200.725911 6.17382812,204.216797 L6.17382812,204.216797 L65.2695312,263.3125 C71.2539062,268.798177 77.8616536,270.044922 85.0927734,267.052734 C92.3238932,264.060547 95.9394531,258.57487 95.9394531,250.595703 L95.9394531,250.595703 L95.9394531,212.445312 L171.492188,212.445312 L171.492188,287.998047 L133.341797,287.998047 C125.36263,287.998047 119.876953,291.613607 116.884766,298.844727 C113.892578,306.075846 115.139323,312.683594 120.625,318.667969 L120.625,318.667969 L179.720703,377.763672 C183.211589,381.254557 187.450521,383 192.4375,383 Z'%3E%3C/path%3E%3C/g%3E%3C/svg%3E\");mask-image:url(\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg viewBox='0 0 384 383' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cg%3E%3Cpath d='M192.4375,383 C197.424479,383 201.663411,381.254557 205.154297,377.763672 L205.154297,377.763672 L264.25,318.667969 C270.234375,312.683594 271.605794,306.075846 268.364258,298.844727 C265.122721,291.613607 259.51237,287.998047 251.533203,287.998047 L251.533203,287.998047 L213.382812,287.998047 L213.382812,212.445312 L288.935547,212.445312 L288.935547,250.595703 C288.935547,258.57487 292.551107,264.185221 299.782227,267.426758 C307.013346,270.668294 313.621094,269.296875 319.605469,263.3125 L319.605469,263.3125 L378.701172,204.216797 C382.192057,200.725911 383.9375,196.486979 383.9375,191.5 C383.9375,186.513021 382.192057,182.274089 378.701172,178.783203 L378.701172,178.783203 L319.605469,119.6875 C313.621094,114.201823 307.013346,112.955078 299.782227,115.947266 C292.551107,118.939453 288.935547,124.42513 288.935547,132.404297 L288.935547,132.404297 L288.935547,170.554688 L213.382812,170.554688 L213.382812,95.0019531 L251.533203,95.0019531 C259.51237,95.0019531 264.998047,91.3863932 267.990234,84.1552734 C270.982422,76.9241536 269.735677,70.3164062 264.25,64.3320312 L264.25,64.3320312 L205.154297,5.23632812 C201.663411,1.74544271 197.424479,0 192.4375,0 C187.450521,0 183.211589,1.74544271 179.720703,5.23632812 L179.720703,5.23632812 L120.625,64.3320312 C114.640625,70.3164062 113.269206,76.9241536 116.510742,84.1552734 C119.752279,91.3863932 125.36263,95.0019531 133.341797,95.0019531 L133.341797,95.0019531 L171.492188,95.0019531 L171.492188,170.554688 L95.9394531,170.554688 L95.9394531,132.404297 C95.9394531,124.42513 92.3238932,118.814779 85.0927734,115.573242 C77.8616536,112.331706 71.2539062,113.703125 65.2695312,119.6875 L65.2695312,119.6875 L6.17382812,178.783203 C2.68294271,182.274089 0.9375,186.513021 0.9375,191.5 C0.9375,196.486979 2.68294271,200.725911 6.17382812,204.216797 L6.17382812,204.216797 L65.2695312,263.3125 C71.2539062,268.798177 77.8616536,270.044922 85.0927734,267.052734 C92.3238932,264.060547 95.9394531,258.57487 95.9394531,250.595703 L95.9394531,250.595703 L95.9394531,212.445312 L171.492188,212.445312 L171.492188,287.998047 L133.341797,287.998047 C125.36263,287.998047 119.876953,291.613607 116.884766,298.844727 C113.892578,306.075846 115.139323,312.683594 120.625,318.667969 L120.625,318.667969 L179.720703,377.763672 C183.211589,381.254557 187.450521,383 192.4375,383 Z'%3E%3C/path%3E%3C/g%3E%3C/svg%3E\");width:11px;height:11px;background-size:cover;background-repeat:no-repeat}.arrow-down{position:absolute;right:5px;top:0}.arrow-down svg{width:8px;margin-top:5px;margin-left:5px;opacity:0.4}.cell-value-wrapper{margin-right:10px;overflow:hidden;text-overflow:ellipsis}.revo-button{position:relative;overflow:hidden;color:#fff;background-color:#4545ff;height:32px;line-height:32px;padding:0 15px;outline:0;border:0;border-radius:7px;box-sizing:border-box;cursor:pointer}.revo-button.green{background-color:#009037}.revo-button.red{background-color:#E0662E}.revo-button:disabled,.revo-button[disabled]{cursor:not-allowed !important;filter:opacity(0.35) !important}.revo-button.outline{border:1px solid #dbdbdb;line-height:30px;background:none;color:#000;box-shadow:none}revo-grid[theme^=dark] .revo-button.outline{border:1px solid #404040;color:#d8d8d8}revo-grid[theme=default],revo-grid:not([theme]){border:1px solid var(--revo-grid-header-border);font-size:12px}revo-grid[theme=default] .rowHeaders revogr-header,revo-grid:not([theme]) .rowHeaders revogr-header{box-shadow:-1px 0 0 0 var(--revo-grid-header-border) inset}revo-grid[theme=default] revogr-header,revo-grid:not([theme]) revogr-header{text-align:center;line-height:30px;background-color:var(--revo-grid-header-bg)}revo-grid[theme=default] revogr-header .group-rgRow,revo-grid:not([theme]) revogr-header .group-rgRow{box-shadow:none}revo-grid[theme=default] revogr-header .group-rgRow .rgHeaderCell,revo-grid:not([theme]) revogr-header .group-rgRow .rgHeaderCell{box-shadow:-1px 0 0 0 var(--revo-grid-header-border), -1px 0 0 0 var(--revo-grid-header-border) inset, 0 -1px 0 0 var(--revo-grid-header-border), 0 -1px 0 0 var(--revo-grid-header-border) inset}revo-grid[theme=default] revogr-header .header-rgRow,revo-grid[theme=default] revogr-header .group-rgRow,revo-grid:not([theme]) revogr-header .header-rgRow,revo-grid:not([theme]) revogr-header .group-rgRow{text-transform:uppercase;font-size:12px;color:var(--revo-grid-header-color)}revo-grid[theme=default] revogr-header .header-rgRow,revo-grid:not([theme]) revogr-header .header-rgRow{height:30px;box-shadow:0 -1px 0 0 var(--revo-grid-header-border) inset}revo-grid[theme=default] revogr-header .rgHeaderCell,revo-grid:not([theme]) revogr-header .rgHeaderCell{box-shadow:-1px 0 0 0 var(--revo-grid-header-border) inset, 0 -1px 0 0 var(--revo-grid-header-border), 0 -1px 0 0 var(--revo-grid-header-border) inset}revo-grid[theme=default] .rowHeaders,revo-grid:not([theme]) .rowHeaders{background-color:var(--revo-grid-header-bg)}revo-grid[theme=default] .rowHeaders revogr-data .rgCell,revo-grid:not([theme]) .rowHeaders revogr-data .rgCell{color:var(--revo-grid-header-color)}revo-grid[theme=default] .rowHeaders revogr-data .rgCell:first-child,revo-grid:not([theme]) .rowHeaders revogr-data .rgCell:first-child{box-shadow:0 -1px 0 0 var(--revo-grid-header-border) inset}revo-grid[theme=default] .rowHeaders revogr-data .rgCell:not(:first-child),revo-grid:not([theme]) .rowHeaders revogr-data .rgCell:not(:first-child){box-shadow:0 -1px 0 0 var(--revo-grid-header-border) inset, 1px 0 0 0 var(--revo-grid-header-border) inset}revo-grid[theme=default] .rowHeaders revogr-data .rgCell:last-child,revo-grid:not([theme]) .rowHeaders revogr-data .rgCell:last-child{border-right:1px solid var(--revo-grid-header-border)}revo-grid[theme=default] .rowHeaders revogr-data revogr-header,revo-grid:not([theme]) .rowHeaders revogr-data revogr-header{box-shadow:0 -1px 0 0 var(--revo-grid-header-border) inset}revo-grid[theme=default] revogr-viewport-scroll.colPinStart revogr-data .rgRow .rgCell:last-child,revo-grid:not([theme]) revogr-viewport-scroll.colPinStart revogr-data .rgRow .rgCell:last-child{box-shadow:0 -1px 0 0 var(--revo-grid-cell-border) inset, -1px 0 0 0 var(--revo-grid-header-border) inset}revo-grid[theme=default] revogr-viewport-scroll.colPinStart .footer-wrapper revogr-data .rgRow:first-child .rgCell,revo-grid:not([theme]) revogr-viewport-scroll.colPinStart .footer-wrapper revogr-data .rgRow:first-child .rgCell{box-shadow:0 1px 0 0 var(--revo-grid-header-border) inset, -1px 0 0 0 var(--revo-grid-header-border) inset}revo-grid[theme=default] revogr-viewport-scroll.colPinEnd,revo-grid[theme=default] revogr-viewport-scroll.colPinEnd revogr-header,revo-grid:not([theme]) revogr-viewport-scroll.colPinEnd,revo-grid:not([theme]) revogr-viewport-scroll.colPinEnd revogr-header{box-shadow:1px 0 0 var(--revo-grid-header-border) inset}revo-grid[theme=default] .footer-wrapper revogr-data .rgRow:first-child .rgCell,revo-grid:not([theme]) .footer-wrapper revogr-data .rgRow:first-child .rgCell{box-shadow:0 1px 0 0 var(--revo-grid-cell-border) inset, -1px 0 0 0 var(--revo-grid-cell-border) inset, 0 -1px 0 0 var(--revo-grid-cell-border) inset}revo-grid[theme=default] revogr-data,revo-grid:not([theme]) revogr-data{text-align:center}revo-grid[theme=default] revogr-data .revo-draggable,revo-grid:not([theme]) revogr-data .revo-draggable{float:left}revo-grid[theme=default] revogr-data .rgRow,revo-grid:not([theme]) revogr-data .rgRow{line-height:27px}revo-grid[theme=default] revogr-data .rgCell,revo-grid:not([theme]) revogr-data .rgCell{box-shadow:0 -1px 0 0 var(--revo-grid-cell-border) inset, -1px 0 0 0 var(--revo-grid-cell-border) inset}revo-grid[theme=material]{font-family:Nunito, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"}revo-grid[theme=material] revogr-header{line-height:50px;font-weight:600;text-align:left}revo-grid[theme=material] revogr-header .rgHeaderCell{padding:0 15px;text-overflow:ellipsis}revo-grid[theme=material] revogr-header .header-rgRow{height:50px}revo-grid[theme=material] revogr-data{text-align:left}revo-grid[theme=material] revogr-data .rgRow{line-height:42px}revo-grid[theme=material] revogr-data .rgCell{padding:0 15px}revo-grid[theme=darkMaterial]{font-family:Nunito, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"}revo-grid[theme=darkMaterial] revogr-header{line-height:50px;font-weight:600;text-align:left}revo-grid[theme=darkMaterial] revogr-header .rgHeaderCell{padding:0 15px;text-overflow:ellipsis}revo-grid[theme=darkMaterial] revogr-header .header-rgRow{height:50px}revo-grid[theme=darkMaterial] revogr-data{text-align:left}revo-grid[theme=darkMaterial] revogr-data .rgRow{line-height:42px}revo-grid[theme=darkMaterial] revogr-data .rgCell{padding:0 15px}revo-grid[theme=darkCompact]{font-family:Nunito, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"}revo-grid[theme=darkCompact] revogr-header{line-height:45px;font-weight:600;text-align:left}revo-grid[theme=darkCompact] revogr-header .rgHeaderCell{padding:0 15px;text-overflow:ellipsis}revo-grid[theme=darkCompact] revogr-header .header-rgRow{height:45px}revo-grid[theme=darkCompact] revogr-data{text-align:left}revo-grid[theme=darkCompact] revogr-data .rgRow{line-height:32px}revo-grid[theme=darkCompact] revogr-data .rgCell{padding:0 15px}revo-grid[theme=compact]{font-family:Nunito, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"}revo-grid[theme=compact] revogr-header{line-height:45px;font-weight:600;text-align:left}revo-grid[theme=compact] revogr-header .rgHeaderCell{padding:0 15px;text-overflow:ell