New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@glideapps/glide-data-grid-source

Package Overview
Dependencies
Maintainers
8
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@glideapps/glide-data-grid-source - npm Package Compare versions

Comparing version 5.3.1-alpha1 to 5.3.1-alpha2

5

dist/cjs/index.js

@@ -36,11 +36,6 @@ "use strict";

});
var _useCollapsingGroups = require("./use-collapsing-groups");
var _useMovableColumns = require("./use-movable-columns");
var _useColumnSort = require("./use-column-sort");
var _useAsyncDataSource = require("./use-async-data-source");
var _useUndoRedo = require("./use-undo-redo");

@@ -7,20 +7,11 @@ "use strict";

exports.useAsyncDataSource = useAsyncDataSource;
var _glideDataGrid = require("@glideapps/glide-data-grid");
var _range = _interopRequireDefault(require("lodash/range.js"));
var _chunk = _interopRequireDefault(require("lodash/chunk.js"));
var _react = _interopRequireDefault(require("react"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function useAsyncDataSource(pageSize, maxConcurrency, getRowData, toCell, onEdited, gridRef) {
pageSize = Math.max(pageSize, 1);
const loadingRef = _react.default.useRef(_glideDataGrid.CompactSelection.empty());
const dataRef = _react.default.useRef([]);
const [visiblePages, setVisiblePages] = _react.default.useState({

@@ -32,7 +23,4 @@ x: 0,

});
const visiblePagesRef = _react.default.useRef(visiblePages);
visiblePagesRef.current = visiblePages;
const onVisibleRegionChanged = _react.default.useCallback(r => {

@@ -44,11 +32,8 @@ setVisiblePages(cv => {

}, []);
const getCellContent = _react.default.useCallback(cell => {
const [col, row] = cell;
const rowData = dataRef.current[row];
if (rowData !== undefined) {
return toCell(rowData, col);
}
return {

@@ -59,6 +44,4 @@ kind: _glideDataGrid.GridCellKind.Loading,

}, [toCell]);
const loadPage = _react.default.useCallback(async page => {
var _gridRef$current;
loadingRef.current = loadingRef.current.add(page);

@@ -70,6 +53,4 @@ const startIndex = page * pageSize;

const data = dataRef.current;
for (let i = 0; i < d.length; i++) {
data[i + startIndex] = d[i];
for (let col = vr.x; col <= vr.x + vr.width; col++) {

@@ -81,6 +62,4 @@ damageList.push({

}
(_gridRef$current = gridRef.current) === null || _gridRef$current === void 0 ? void 0 : _gridRef$current.updateCells(damageList);
}, [getRowData, gridRef, pageSize]);
const getCellsForSelection = _react.default.useCallback(r => {

@@ -90,23 +69,16 @@ return async () => {

const lastPage = Math.floor((r.y + r.height) / pageSize);
for (const pageChunk of (0, _chunk.default)((0, _range.default)(firstPage, lastPage + 1).filter(i => !loadingRef.current.hasIndex(i)), maxConcurrency)) {
await Promise.all(pageChunk.map(loadPage));
}
const result = [];
for (let y = r.y; y < r.y + r.height; y++) {
const row = [];
for (let x = r.x; x < r.x + r.width; x++) {
row.push(getCellContent([x, y]));
}
result.push(row);
}
return result;
};
}, [getCellContent, loadPage, maxConcurrency, pageSize]);
_react.default.useEffect(() => {

@@ -116,3 +88,2 @@ const r = visiblePages;

const lastPage = Math.floor((r.y + r.height + pageSize / 2) / pageSize);
for (const page of (0, _range.default)(firstPage, lastPage + 1)) {

@@ -123,3 +94,2 @@ if (loadingRef.current.hasIndex(page)) continue;

}, [loadPage, pageSize, visiblePages]);
const onCellEdited = _react.default.useCallback((cell, newVal) => {

@@ -130,3 +100,2 @@ const [, row] = cell;

const result = onEdited(cell, newVal, current);
if (result !== undefined) {

@@ -136,3 +105,2 @@ dataRef.current[row] = result;

}, [onEdited]);
return {

@@ -139,0 +107,0 @@ getCellContent,

30

dist/cjs/use-collapsing-groups.js

@@ -7,12 +7,7 @@ "use strict";

exports.useCollapsingGroups = useCollapsingGroups;
var _react = _interopRequireDefault(require("react"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function useCollapsingGroups(props) {
const [collapsed, setCollapsed] = _react.default.useState([]);
const [gridSelectionInner, setGridSelectionsInner] = _react.default.useState(undefined);
const {

@@ -28,3 +23,2 @@ columns: columnsIn,

const gridSelection = gridSelectionIn !== null && gridSelectionIn !== void 0 ? gridSelectionIn : gridSelectionInner;
const spans = _react.default.useMemo(() => {

@@ -34,10 +28,7 @@ const result = [];

let lastGroup;
for (let i = freezeColumns; i < columnsIn.length; i++) {
var _c$group;
const c = columnsIn[i];
const group = (_c$group = c.group) !== null && _c$group !== void 0 ? _c$group : "";
const isCollapsed = collapsed.includes(group);
if (lastGroup !== group && current[0] !== -1) {

@@ -47,3 +38,2 @@ result.push(current);

}
if (isCollapsed && current[0] !== -1) {

@@ -57,10 +47,7 @@ current[1] += 1;

}
lastGroup = group;
}
if (current[0] !== -1) result.push(current);
return result;
}, [collapsed, columnsIn, freezeColumns]);
const columns = _react.default.useMemo(() => {

@@ -72,8 +59,7 @@ if (spans.length === 0) return columnsIn;

let width = 8;
if (index === start + length - 1) {
width = 36;
}
return { ...c,
return {
...c,
width,

@@ -86,10 +72,7 @@ themeOverride: {

}
return c;
});
}, [columnsIn, spans, theme.bgCellMedium]);
const onGroupHeaderClicked = _react.default.useCallback((index, a) => {
var _columns$index$group, _columns$index;
onGroupHeaderClickedIn === null || onGroupHeaderClickedIn === void 0 ? void 0 : onGroupHeaderClickedIn(index, a);

@@ -101,3 +84,2 @@ const group = (_columns$index$group = (_columns$index = columns[index]) === null || _columns$index === void 0 ? void 0 : _columns$index.group) !== null && _columns$index$group !== void 0 ? _columns$index$group : "";

}, [columns, onGroupHeaderClickedIn]);
const onGridSelectionChange = _react.default.useCallback(s => {

@@ -109,11 +91,8 @@ if (s.current !== undefined) {

var _column$group;
if (cv.includes((_column$group = column === null || column === void 0 ? void 0 : column.group) !== null && _column$group !== void 0 ? _column$group : "")) {
return cv.filter(g => g !== column.group);
}
return cv;
});
}
if (onGridSelectionChangeIn !== undefined) {

@@ -125,6 +104,6 @@ onGridSelectionChangeIn(s);

}, [columns, onGridSelectionChangeIn]);
const getGroupDetails = _react.default.useCallback(group => {
const result = getGroupDetailsIn === null || getGroupDetailsIn === void 0 ? void 0 : getGroupDetailsIn(group);
return { ...result,
return {
...result,
name: group,

@@ -136,3 +115,2 @@ overrideTheme: collapsed.includes(group !== null && group !== void 0 ? group : "") ? {

}, [collapsed, getGroupDetailsIn, theme.bgHeaderHasFocus]);
return {

@@ -139,0 +117,0 @@ columns,

@@ -9,25 +9,15 @@ "use strict";

exports.useColumnSort = useColumnSort;
var _glideDataGrid = require("@glideapps/glide-data-grid");
var _range = _interopRequireDefault(require("lodash/range.js"));
var React = _interopRequireWildcard(require("react"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function cellToSortData(c) {
var _c$data$toString, _c$data, _c$data$toString2, _c$data2, _c$data3;
switch (c.kind) {
case _glideDataGrid.GridCellKind.Number:
return (_c$data$toString = (_c$data = c.data) === null || _c$data === void 0 ? void 0 : _c$data.toString()) !== null && _c$data$toString !== void 0 ? _c$data$toString : "";
case _glideDataGrid.GridCellKind.Boolean:
return (_c$data$toString2 = (_c$data2 = c.data) === null || _c$data2 === void 0 ? void 0 : _c$data2.toString()) !== null && _c$data$toString2 !== void 0 ? _c$data$toString2 : "";
case _glideDataGrid.GridCellKind.Markdown:

@@ -38,14 +28,10 @@ case _glideDataGrid.GridCellKind.RowID:

return (_c$data3 = c.data) !== null && _c$data3 !== void 0 ? _c$data3 : "";
case _glideDataGrid.GridCellKind.Bubble:
case _glideDataGrid.GridCellKind.Image:
return c.data.join("");
case _glideDataGrid.GridCellKind.Drilldown:
return c.data.map(x => x.text).join("");
case _glideDataGrid.GridCellKind.Protected:
case _glideDataGrid.GridCellKind.Loading:
return "";
case _glideDataGrid.GridCellKind.Custom:

@@ -55,9 +41,6 @@ return c.copyData;

}
function tryParse(val) {
if (typeof val === "number") return val;
if (val.length > 0) {
const x = Number(val);
if (!isNaN(x)) {

@@ -67,10 +50,7 @@ val = x;

}
return val;
}
function compareSmart(a, b) {
a = tryParse(a);
b = tryParse(b);
if (typeof a === "string" && typeof b === "string") {

@@ -84,6 +64,4 @@ return a.localeCompare(b);

}
return a > b ? 1 : -1;
}
function compareRaw(a, b) {

@@ -94,6 +72,4 @@ if (a > b) return 1;

}
function useColumnSort(p) {
var _sort$direction;
const {

@@ -111,3 +87,2 @@ sort,

const index = [sortCol, 0];
for (let i = 0; i < rows; i++) {

@@ -117,5 +92,3 @@ index[1] = i;

}
let result;
if ((sort === null || sort === void 0 ? void 0 : sort.mode) === "raw") {

@@ -128,7 +101,5 @@ result = (0, _range.default)(rows).sort((a, b) => compareRaw(vals[a], vals[b]));

}
if (dir === "desc") {
result.reverse();
}
return result;

@@ -146,3 +117,2 @@ }, [getCellContentIn, rows, sort === null || sort === void 0 ? void 0 : sort.mode, dir, sortCol]);

}, [getCellContentIn, sortMap]);
if (sortMap === undefined) {

@@ -154,3 +124,2 @@ return {

}
return {

@@ -157,0 +126,0 @@ getOriginalIndex,

"use strict";
var _useColumnSort = require("./use-column-sort");
describe('use-column-sort', () => {

@@ -6,0 +5,0 @@ describe('compareSmart', function () {

"use strict";
var React = _interopRequireWildcard(require("react"));
var _react2 = require("@testing-library/react");
var _glideDataGrid = require("@glideapps/glide-data-grid");
var _ = require(".");
var _useColumnSort = require("./use-column-sort");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const props = {

@@ -69,3 +62,2 @@ columns: [{

};
const DataSourceMonkey = p => {

@@ -93,9 +85,6 @@ const columns = p.columns;

};
describe("use-data-source", () => {
test("Smoke test", async () => {
(0, _react2.render)(React.createElement(DataSourceMonkey, props));
const zeroZero = _react2.screen.getByTestId("cell-0-0");
expect(zeroZero.textContent).toBe("0x0");

@@ -102,0 +91,0 @@ });

@@ -7,19 +7,11 @@ "use strict";

exports.useMoveableColumns = useMoveableColumns;
var React = _interopRequireWildcard(require("react"));
var _orderBy = _interopRequireDefault(require("lodash/orderBy.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function colToKey(c) {
var _c$id, _c$group;
return (_c$id = c.id) !== null && _c$id !== void 0 ? _c$id : `${(_c$group = c.group) !== null && _c$group !== void 0 ? _c$group : ""}/${c.title}`;
}
function looseCompareCol(a, b) {

@@ -29,6 +21,4 @@ if (typeof b === "string") {

}
return colToKey(a) === colToKey(b);
}
function getSortIndexByKey(needle, current, keys) {

@@ -39,3 +29,2 @@ const index = current.indexOf(needle);

if (remapped !== -1) return remapped;
for (let n = index; n >= 0; n--) {

@@ -45,6 +34,4 @@ const ind = keys.findIndex(key => looseCompareCol(current[n], key));

}
return -1;
}
function useMoveableColumns(p) {

@@ -64,3 +51,2 @@ const {

var _onColumnMovedRef$cur;
setKeys(old => {

@@ -67,0 +53,0 @@ const newCols = [...old];

@@ -7,5 +7,3 @@ "use strict";

exports.useUndoRedo = useUndoRedo;
var _react = require("react");
const initialState = {

@@ -19,7 +17,6 @@ undoHistory: [],

};
function reducer(state, action) {
const newState = { ...state
const newState = {
...state
};
switch (action.type) {

@@ -35,5 +32,3 @@ case "undo":

}
return state;
case "redo":

@@ -48,5 +43,3 @@ if (state.canRedo) {

}
return state;
case "operationApplied":

@@ -57,3 +50,2 @@ newState.operation = undefined;

return newState;
case "edit":

@@ -66,3 +58,2 @@ if (!state.isApplyingRedo && !state.isApplyingUndo) {

}
if (state.isApplyingUndo) {

@@ -72,3 +63,2 @@ newState.redoHistory = [...state.redoHistory, action.batch];

}
if (state.isApplyingRedo) {

@@ -78,5 +68,3 @@ newState.undoHistory = [...state.undoHistory, action.batch];

}
return newState;
default:

@@ -86,3 +74,2 @@ throw new Error("Invalid action");

}
function useUndoRedo(gridRef, getCellContent, onCellEdited, onGridSelectionChange) {

@@ -104,3 +91,2 @@ const [state, dispatch] = (0, _react.useReducer)(reducer, initialState);

}
setGridSelection(newVal);

@@ -111,7 +97,5 @@ gridSelectionRef.current = newVal;

const isApplyingUpdate = isApplyingUndoRef.current || isApplyingRedoRef.current;
if (!isApplyingUpdate && gridSelectionRef.current) {
clearTimeout(timeout.current);
const previousValue = getCellContent(cell);
if (currentBatch.current === null) {

@@ -123,3 +107,2 @@ currentBatch.current = {

}
currentBatch.current.edits.push({

@@ -139,3 +122,2 @@ cell,

}
onCellEdited(cell, newValue);

@@ -160,3 +142,2 @@ }, [onCellEdited, getCellContent]);

};
for (const edit of state.operation.edits) {

@@ -173,3 +154,2 @@ const prevValue = getCellContent(edit.cell);

}
setGridSelection(state.operation.selection);

@@ -196,3 +176,2 @@ gridSelectionRef.current = state.operation.selection;

}
if (e.key === "y" && (e.metaKey || e.ctrlKey)) {

@@ -202,3 +181,2 @@ redo();

};
window.addEventListener("keydown", onKeyDown);

@@ -205,0 +183,0 @@ return () => {

@@ -26,7 +26,5 @@ import { CompactSelection, GridCellKind } from "@glideapps/glide-data-grid";

const rowData = dataRef.current[row];
if (rowData !== undefined) {
return toCell(rowData, col);
}
return {

@@ -39,3 +37,2 @@ kind: GridCellKind.Loading,

var _gridRef$current;
loadingRef.current = loadingRef.current.add(page);

@@ -47,6 +44,4 @@ const startIndex = page * pageSize;

const data = dataRef.current;
for (let i = 0; i < d.length; i++) {
data[i + startIndex] = d[i];
for (let col = vr.x; col <= vr.x + vr.width; col++) {

@@ -58,3 +53,2 @@ damageList.push({

}
(_gridRef$current = gridRef.current) === null || _gridRef$current === void 0 ? void 0 : _gridRef$current.updateCells(damageList);

@@ -66,19 +60,13 @@ }, [getRowData, gridRef, pageSize]);

const lastPage = Math.floor((r.y + r.height) / pageSize);
for (const pageChunk of chunk(range(firstPage, lastPage + 1).filter(i => !loadingRef.current.hasIndex(i)), maxConcurrency)) {
await Promise.all(pageChunk.map(loadPage));
}
const result = [];
for (let y = r.y; y < r.y + r.height; y++) {
const row = [];
for (let x = r.x; x < r.x + r.width; x++) {
row.push(getCellContent([x, y]));
}
result.push(row);
}
return result;

@@ -91,3 +79,2 @@ };

const lastPage = Math.floor((r.y + r.height + pageSize / 2) / pageSize);
for (const page of range(firstPage, lastPage + 1)) {

@@ -103,3 +90,2 @@ if (loadingRef.current.hasIndex(page)) continue;

const result = onEdited(cell, newVal, current);
if (result !== undefined) {

@@ -106,0 +92,0 @@ dataRef.current[row] = result;

19

dist/js/use-collapsing-groups.js

@@ -19,10 +19,7 @@ import React from "react";

let lastGroup;
for (let i = freezeColumns; i < columnsIn.length; i++) {
var _c$group;
const c = columnsIn[i];
const group = (_c$group = c.group) !== null && _c$group !== void 0 ? _c$group : "";
const isCollapsed = collapsed.includes(group);
if (lastGroup !== group && current[0] !== -1) {

@@ -32,3 +29,2 @@ result.push(current);

}
if (isCollapsed && current[0] !== -1) {

@@ -42,6 +38,4 @@ current[1] += 1;

}
lastGroup = group;
}
if (current[0] !== -1) result.push(current);

@@ -56,8 +50,7 @@ return result;

let width = 8;
if (index === start + length - 1) {
width = 36;
}
return { ...c,
return {
...c,
width,

@@ -70,3 +63,2 @@ themeOverride: {

}
return c;

@@ -77,3 +69,2 @@ });

var _columns$index$group, _columns$index;
onGroupHeaderClickedIn === null || onGroupHeaderClickedIn === void 0 ? void 0 : onGroupHeaderClickedIn(index, a);

@@ -91,11 +82,8 @@ const group = (_columns$index$group = (_columns$index = columns[index]) === null || _columns$index === void 0 ? void 0 : _columns$index.group) !== null && _columns$index$group !== void 0 ? _columns$index$group : "";

var _column$group;
if (cv.includes((_column$group = column === null || column === void 0 ? void 0 : column.group) !== null && _column$group !== void 0 ? _column$group : "")) {
return cv.filter(g => g !== column.group);
}
return cv;
});
}
if (onGridSelectionChangeIn !== undefined) {

@@ -109,3 +97,4 @@ onGridSelectionChangeIn(s);

const result = getGroupDetailsIn === null || getGroupDetailsIn === void 0 ? void 0 : getGroupDetailsIn(group);
return { ...result,
return {
...result,
name: group,

@@ -112,0 +101,0 @@ overrideTheme: collapsed.includes(group !== null && group !== void 0 ? group : "") ? {

import { GridCellKind } from "@glideapps/glide-data-grid";
import range from "lodash/range.js";
import * as React from "react";
function cellToSortData(c) {
var _c$data$toString, _c$data, _c$data$toString2, _c$data2, _c$data3;
switch (c.kind) {
case GridCellKind.Number:
return (_c$data$toString = (_c$data = c.data) === null || _c$data === void 0 ? void 0 : _c$data.toString()) !== null && _c$data$toString !== void 0 ? _c$data$toString : "";
case GridCellKind.Boolean:
return (_c$data$toString2 = (_c$data2 = c.data) === null || _c$data2 === void 0 ? void 0 : _c$data2.toString()) !== null && _c$data$toString2 !== void 0 ? _c$data$toString2 : "";
case GridCellKind.Markdown:

@@ -20,14 +16,10 @@ case GridCellKind.RowID:

return (_c$data3 = c.data) !== null && _c$data3 !== void 0 ? _c$data3 : "";
case GridCellKind.Bubble:
case GridCellKind.Image:
return c.data.join("");
case GridCellKind.Drilldown:
return c.data.map(x => x.text).join("");
case GridCellKind.Protected:
case GridCellKind.Loading:
return "";
case GridCellKind.Custom:

@@ -37,9 +29,6 @@ return c.copyData;

}
function tryParse(val) {
if (typeof val === "number") return val;
if (val.length > 0) {
const x = Number(val);
if (!isNaN(x)) {

@@ -49,10 +38,7 @@ val = x;

}
return val;
}
export function compareSmart(a, b) {
a = tryParse(a);
b = tryParse(b);
if (typeof a === "string" && typeof b === "string") {

@@ -66,3 +52,2 @@ return a.localeCompare(b);

}
return a > b ? 1 : -1;

@@ -77,3 +62,2 @@ }

var _sort$direction;
const {

@@ -91,3 +75,2 @@ sort,

const index = [sortCol, 0];
for (let i = 0; i < rows; i++) {

@@ -97,5 +80,3 @@ index[1] = i;

}
let result;
if ((sort === null || sort === void 0 ? void 0 : sort.mode) === "raw") {

@@ -108,7 +89,5 @@ result = range(rows).sort((a, b) => compareRaw(vals[a], vals[b]));

}
if (dir === "desc") {
result.reverse();
}
return result;

@@ -126,3 +105,2 @@ }, [getCellContentIn, rows, sort === null || sort === void 0 ? void 0 : sort.mode, dir, sortCol]);

}, [getCellContentIn, sortMap]);
if (sortMap === undefined) {

@@ -134,3 +112,2 @@ return {

}
return {

@@ -137,0 +114,0 @@ getOriginalIndex,

@@ -58,3 +58,2 @@ import * as React from "react";

};
const DataSourceMonkey = p => {

@@ -82,3 +81,2 @@ const columns = p.columns;

};
describe("use-data-source", () => {

@@ -85,0 +83,0 @@ test("Smoke test", async () => {

import * as React from "react";
import orderBy from "lodash/orderBy.js";
function colToKey(c) {
var _c$id, _c$group;
return (_c$id = c.id) !== null && _c$id !== void 0 ? _c$id : `${(_c$group = c.group) !== null && _c$group !== void 0 ? _c$group : ""}/${c.title}`;
}
function looseCompareCol(a, b) {

@@ -14,6 +11,4 @@ if (typeof b === "string") {

}
return colToKey(a) === colToKey(b);
}
function getSortIndexByKey(needle, current, keys) {

@@ -24,3 +19,2 @@ const index = current.indexOf(needle);

if (remapped !== -1) return remapped;
for (let n = index; n >= 0; n--) {

@@ -30,6 +24,4 @@ const ind = keys.findIndex(key => looseCompareCol(current[n], key));

}
return -1;
}
export function useMoveableColumns(p) {

@@ -49,3 +41,2 @@ const {

var _onColumnMovedRef$cur;
setKeys(old => {

@@ -52,0 +43,0 @@ const newCols = [...old];

@@ -10,7 +10,6 @@ import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from "react";

};
function reducer(state, action) {
const newState = { ...state
const newState = {
...state
};
switch (action.type) {

@@ -26,5 +25,3 @@ case "undo":

}
return state;
case "redo":

@@ -39,5 +36,3 @@ if (state.canRedo) {

}
return state;
case "operationApplied":

@@ -48,3 +43,2 @@ newState.operation = undefined;

return newState;
case "edit":

@@ -57,3 +51,2 @@ if (!state.isApplyingRedo && !state.isApplyingUndo) {

}
if (state.isApplyingUndo) {

@@ -63,3 +56,2 @@ newState.redoHistory = [...state.redoHistory, action.batch];

}
if (state.isApplyingRedo) {

@@ -69,5 +61,3 @@ newState.undoHistory = [...state.undoHistory, action.batch];

}
return newState;
default:

@@ -77,3 +67,2 @@ throw new Error("Invalid action");

}
export function useUndoRedo(gridRef, getCellContent, onCellEdited, onGridSelectionChange) {

@@ -95,3 +84,2 @@ const [state, dispatch] = useReducer(reducer, initialState);

}
setGridSelection(newVal);

@@ -102,7 +90,5 @@ gridSelectionRef.current = newVal;

const isApplyingUpdate = isApplyingUndoRef.current || isApplyingRedoRef.current;
if (!isApplyingUpdate && gridSelectionRef.current) {
clearTimeout(timeout.current);
const previousValue = getCellContent(cell);
if (currentBatch.current === null) {

@@ -114,3 +100,2 @@ currentBatch.current = {

}
currentBatch.current.edits.push({

@@ -130,3 +115,2 @@ cell,

}
onCellEdited(cell, newValue);

@@ -151,3 +135,2 @@ }, [onCellEdited, getCellContent]);

};
for (const edit of state.operation.edits) {

@@ -164,3 +147,2 @@ const prevValue = getCellContent(edit.cell);

}
setGridSelection(state.operation.selection);

@@ -187,3 +169,2 @@ gridSelectionRef.current = state.operation.selection;

}
if (e.key === "y" && (e.metaKey || e.ctrlKey)) {

@@ -193,3 +174,2 @@ redo();

};
window.addEventListener("keydown", onKeyDown);

@@ -196,0 +176,0 @@ return () => {

@@ -1,6 +0,6 @@

import { DataEditorProps, DataEditorRef, EditableGridCell, GridCell, Item } from "@glideapps/glide-data-grid";
import { type DataEditorProps, type DataEditorRef, type EditableGridCell, type GridCell, type Item } from "@glideapps/glide-data-grid";
import React from "react";
export declare type RowCallback<T> = (range: Item) => Promise<readonly T[]>;
export declare type RowToCell<T> = (row: T, col: number) => GridCell;
export declare type RowEditedCallback<T> = (cell: Item, newVal: EditableGridCell, rowData: T) => T | undefined;
export type RowCallback<T> = (range: Item) => Promise<readonly T[]>;
export type RowToCell<T> = (row: T, col: number) => GridCell;
export type RowEditedCallback<T> = (cell: Item, newVal: EditableGridCell, rowData: T) => T | undefined;
export declare function useAsyncDataSource<TRowType>(pageSize: number, maxConcurrency: number, getRowData: RowCallback<TRowType>, toCell: RowToCell<TRowType>, onEdited: RowEditedCallback<TRowType>, gridRef: React.MutableRefObject<DataEditorRef | null>): Pick<DataEditorProps, "getCellContent" | "onVisibleRegionChanged" | "onCellEdited" | "getCellsForSelection">;
import type { DataEditorProps, Theme } from "@glideapps/glide-data-grid";
declare type Props = Pick<DataEditorProps, "columns" | "onGroupHeaderClicked" | "onGridSelectionChange" | "getGroupDetails" | "gridSelection" | "freezeColumns"> & {
type Props = Pick<DataEditorProps, "columns" | "onGroupHeaderClicked" | "onGridSelectionChange" | "getGroupDetails" | "gridSelection" | "freezeColumns"> & {
theme: Theme;
};
declare type Result = Pick<DataEditorProps, "columns" | "onGroupHeaderClicked" | "onGridSelectionChange" | "getGroupDetails" | "gridSelection">;
type Result = Pick<DataEditorProps, "columns" | "onGroupHeaderClicked" | "onGridSelectionChange" | "getGroupDetails" | "gridSelection">;
export declare function useCollapsingGroups(props: Props): Result;
export {};

@@ -1,5 +0,5 @@

import { DataEditorProps, GridColumn } from "@glideapps/glide-data-grid";
import { type DataEditorProps, type GridColumn } from "@glideapps/glide-data-grid";
export declare function compareSmart(a: string | number, b: string | number): number;
export declare function compareRaw(a: string | number, b: string | number): 0 | 1 | -1;
declare type Props = Pick<DataEditorProps, "getCellContent" | "rows" | "columns"> & {
type Props = Pick<DataEditorProps, "getCellContent" | "rows" | "columns"> & {
sort?: {

@@ -11,3 +11,3 @@ column: GridColumn;

};
declare type Result = Pick<DataEditorProps, "getCellContent"> & {
type Result = Pick<DataEditorProps, "getCellContent"> & {
getOriginalIndex: (index: number) => number;

@@ -14,0 +14,0 @@ };

import type { DataEditorProps } from "@glideapps/glide-data-grid";
declare type Props = Pick<DataEditorProps, "columns" | "onColumnMoved" | "getCellContent">;
type Props = Pick<DataEditorProps, "columns" | "onColumnMoved" | "getCellContent">;
export declare function useMoveableColumns(p: Props): Required<Props>;
export {};
{
"name": "@glideapps/glide-data-grid-source",
"version": "5.3.1-alpha1",
"version": "5.3.1-alpha2",
"description": "Useful data source hooks for Glide Data Grid",

@@ -47,3 +47,3 @@ "sideEffects": false,

"dependencies": {
"@glideapps/glide-data-grid": "5.3.1-alpha1"
"@glideapps/glide-data-grid": "5.3.1-alpha2"
},

@@ -50,0 +50,0 @@ "peerDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc