Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zendeskgarden/container-grid

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zendeskgarden/container-grid - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

177

dist/index.cjs.js

@@ -20,30 +20,2 @@ /**

function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function composeEventHandlers() {

@@ -106,32 +78,28 @@ for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {

var _excluded$1 = ["rowIdx", "colIdx", "onFocus", "onKeyDown"];
var GRID_KEYS = [KEYS.LEFT, KEYS.RIGHT, KEYS.UP, KEYS.DOWN, KEYS.HOME, KEYS.END];
const GRID_KEYS = [KEYS.LEFT, KEYS.RIGHT, KEYS.UP, KEYS.DOWN, KEYS.HOME, KEYS.END];
function useGrid(_ref) {
var rtl = _ref.rtl,
wrap = _ref.wrap,
matrix = _ref.matrix,
idPrefix = _ref.idPrefix,
onChange = _ref.onChange,
_ref$environment = _ref.environment,
environment = _ref$environment === void 0 ? document : _ref$environment,
controlledRowIndex = _ref.rowIndex,
controlledColIndex = _ref.colIndex,
defaultRowIndex = _ref.defaultRowIndex,
defaultColIndex = _ref.defaultColIndex;
var _useState = React.useState(defaultRowIndex !== null && defaultRowIndex !== undefined ? defaultRowIndex : 0),
uncontrolledRowIndex = _useState[0],
setUncontrolledRowIndex = _useState[1];
var _useState2 = React.useState(defaultColIndex !== null && defaultColIndex !== undefined ? defaultColIndex : 0),
uncontrolledColIndex = _useState2[0],
setUncontrolledColIndex = _useState2[1];
var isControlled = controlledRowIndex !== null && controlledColIndex !== null && controlledRowIndex !== undefined && controlledColIndex !== undefined;
var rowIndex = isControlled ? controlledRowIndex : uncontrolledRowIndex;
var colIndex = isControlled ? controlledColIndex : uncontrolledColIndex;
var rowCount = matrix.length;
var colCount = matrix[0].length;
var getCellRight = function getCellRight() {
var retVal = [];
var lastRowIndex = rowCount - 1;
var lastColIndex = matrix[lastRowIndex].length - 1;
var isLastCellFocused = rowIndex === lastRowIndex && colIndex === lastColIndex;
let {
rtl,
wrap,
matrix,
idPrefix,
onChange,
environment = document,
rowIndex: controlledRowIndex,
colIndex: controlledColIndex,
defaultRowIndex,
defaultColIndex
} = _ref;
const [uncontrolledRowIndex, setUncontrolledRowIndex] = React.useState(defaultRowIndex !== null && defaultRowIndex !== undefined ? defaultRowIndex : 0);
const [uncontrolledColIndex, setUncontrolledColIndex] = React.useState(defaultColIndex !== null && defaultColIndex !== undefined ? defaultColIndex : 0);
const isControlled = controlledRowIndex !== null && controlledColIndex !== null && controlledRowIndex !== undefined && controlledColIndex !== undefined;
const rowIndex = isControlled ? controlledRowIndex : uncontrolledRowIndex;
const colIndex = isControlled ? controlledColIndex : uncontrolledColIndex;
const rowCount = matrix.length;
const colCount = matrix[0].length;
const getCellRight = () => {
let retVal = [];
const lastRowIndex = rowCount - 1;
const lastColIndex = matrix[lastRowIndex].length - 1;
const isLastCellFocused = rowIndex === lastRowIndex && colIndex === lastColIndex;
if (!isLastCellFocused) {

@@ -149,5 +117,5 @@ if (colIndex === colCount - 1

};
var getCellLeft = function getCellLeft() {
var retVal = [];
var isFirstCellFocused = rowIndex === 0 && colIndex === 0;
const getCellLeft = () => {
let retVal = [];
const isFirstCellFocused = rowIndex === 0 && colIndex === 0;
if (!isFirstCellFocused) {

@@ -165,6 +133,6 @@ if (colIndex === 0

};
var getCellDown = function getCellDown() {
var retVal = [];
var lastRowLength = matrix[rowCount - 1].length;
var isLastCellFocused = rowIndex === rowCount - (colCount > lastRowLength ? 2 : 1) && colIndex === colCount - 1;
const getCellDown = () => {
let retVal = [];
const lastRowLength = matrix[rowCount - 1].length;
const isLastCellFocused = rowIndex === rowCount - (colCount > lastRowLength ? 2 : 1) && colIndex === colCount - 1;
if (!isLastCellFocused) {

@@ -182,5 +150,5 @@ if (rowIndex === rowCount - (colIndex >= lastRowLength ? 2 : 1)

};
var getCellUp = function getCellUp() {
var retVal = [];
var isFirstCellFocused = rowIndex === 0 && colIndex === 0;
const getCellUp = () => {
let retVal = [];
const isFirstCellFocused = rowIndex === 0 && colIndex === 0;
if (!isFirstCellFocused) {

@@ -190,5 +158,5 @@ if (rowIndex === 0

if (wrap) {
var lastRowLength = matrix[rowCount - 1].length;
var col = colIndex - 1;
var row = rowCount - (col >= lastRowLength ? 2 : 1);
const lastRowLength = matrix[rowCount - 1].length;
const col = colIndex - 1;
const row = rowCount - (col >= lastRowLength ? 2 : 1);
retVal = [row, col];

@@ -202,27 +170,19 @@ }

};
var handleKeyDown = function handleKeyDown(event) {
const handleKeyDown = event => {
if (GRID_KEYS.includes(event.key)) {
event.preventDefault();
var row = rowIndex;
var col = colIndex;
let row = rowIndex;
let col = colIndex;
switch (event.key) {
case KEYS.RIGHT:
var _ref2 = rtl ? getCellLeft() : getCellRight();
row = _ref2[0];
col = _ref2[1];
[row, col] = rtl ? getCellLeft() : getCellRight();
break;
case KEYS.LEFT:
var _ref3 = rtl ? getCellRight() : getCellLeft();
row = _ref3[0];
col = _ref3[1];
[row, col] = rtl ? getCellRight() : getCellLeft();
break;
case KEYS.DOWN:
var _getCellDown = getCellDown();
row = _getCellDown[0];
col = _getCellDown[1];
[row, col] = getCellDown();
break;
case KEYS.UP:
var _getCellUp = getCellUp();
row = _getCellUp[0];
col = _getCellUp[1];
[row, col] = getCellUp();
break;

@@ -235,4 +195,4 @@ case KEYS.HOME:

{
var lastRowIndex = rowCount - 1;
var lastColIndex = matrix[lastRowIndex].length - 1;
const lastRowIndex = rowCount - 1;
const lastColIndex = matrix[lastRowIndex].length - 1;
row = event.ctrlKey ? lastRowIndex : rowIndex;

@@ -244,4 +204,4 @@ col = event.ctrlKey ? lastColIndex : matrix[rowIndex].length - 1;

if (row !== rowIndex || col !== colIndex) {
var id = idPrefix + "-" + row + "-" + col;
var element = environment.getElementById(id);
const id = `${idPrefix}-${row}-${col}`;
const element = environment.getElementById(id);
element == null ? void 0 : element.focus();

@@ -251,13 +211,15 @@ }

};
var getGridCellProps = function getGridCellProps(_ref4) {
var rowIdx = _ref4.rowIdx,
colIdx = _ref4.colIdx,
onFocus = _ref4.onFocus,
onKeyDown = _ref4.onKeyDown,
other = _objectWithoutPropertiesLoose(_ref4, _excluded$1);
return _extends({
const getGridCellProps = _ref2 => {
let {
rowIdx,
colIdx,
onFocus,
onKeyDown,
...other
} = _ref2;
return {
tabIndex: rowIndex === rowIdx && colIndex === colIdx ? 0 : -1,
role: 'gridcell',
id: idPrefix + "-" + rowIdx + "-" + colIdx,
onFocus: composeEventHandlers(onFocus, function () {
id: `${idPrefix}-${rowIdx}-${colIdx}`,
onFocus: composeEventHandlers(onFocus, () => {
if (!isControlled) {

@@ -269,16 +231,17 @@ setUncontrolledRowIndex(rowIdx);

}),
onKeyDown: composeEventHandlers(onKeyDown, handleKeyDown)
}, other);
onKeyDown: composeEventHandlers(onKeyDown, handleKeyDown),
...other
};
};
return {
getGridCellProps: getGridCellProps
getGridCellProps
};
}
var _excluded = ["children", "render"];
var GridContainer = function GridContainer(props) {
var children = props.children,
_props$render = props.render,
render = _props$render === void 0 ? children : _props$render,
options = _objectWithoutPropertiesLoose(props, _excluded);
const GridContainer = props => {
const {
children,
render = children,
...options
} = props;
return React__default["default"].createElement(React__default["default"].Fragment, null, render(useGrid(options)));

@@ -285,0 +248,0 @@ };

@@ -11,30 +11,2 @@ /**

function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function composeEventHandlers() {

@@ -97,32 +69,28 @@ for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {

var _excluded$1 = ["rowIdx", "colIdx", "onFocus", "onKeyDown"];
var GRID_KEYS = [KEYS.LEFT, KEYS.RIGHT, KEYS.UP, KEYS.DOWN, KEYS.HOME, KEYS.END];
const GRID_KEYS = [KEYS.LEFT, KEYS.RIGHT, KEYS.UP, KEYS.DOWN, KEYS.HOME, KEYS.END];
function useGrid(_ref) {
var rtl = _ref.rtl,
wrap = _ref.wrap,
matrix = _ref.matrix,
idPrefix = _ref.idPrefix,
onChange = _ref.onChange,
_ref$environment = _ref.environment,
environment = _ref$environment === void 0 ? document : _ref$environment,
controlledRowIndex = _ref.rowIndex,
controlledColIndex = _ref.colIndex,
defaultRowIndex = _ref.defaultRowIndex,
defaultColIndex = _ref.defaultColIndex;
var _useState = useState(defaultRowIndex !== null && defaultRowIndex !== undefined ? defaultRowIndex : 0),
uncontrolledRowIndex = _useState[0],
setUncontrolledRowIndex = _useState[1];
var _useState2 = useState(defaultColIndex !== null && defaultColIndex !== undefined ? defaultColIndex : 0),
uncontrolledColIndex = _useState2[0],
setUncontrolledColIndex = _useState2[1];
var isControlled = controlledRowIndex !== null && controlledColIndex !== null && controlledRowIndex !== undefined && controlledColIndex !== undefined;
var rowIndex = isControlled ? controlledRowIndex : uncontrolledRowIndex;
var colIndex = isControlled ? controlledColIndex : uncontrolledColIndex;
var rowCount = matrix.length;
var colCount = matrix[0].length;
var getCellRight = function getCellRight() {
var retVal = [];
var lastRowIndex = rowCount - 1;
var lastColIndex = matrix[lastRowIndex].length - 1;
var isLastCellFocused = rowIndex === lastRowIndex && colIndex === lastColIndex;
let {
rtl,
wrap,
matrix,
idPrefix,
onChange,
environment = document,
rowIndex: controlledRowIndex,
colIndex: controlledColIndex,
defaultRowIndex,
defaultColIndex
} = _ref;
const [uncontrolledRowIndex, setUncontrolledRowIndex] = useState(defaultRowIndex !== null && defaultRowIndex !== undefined ? defaultRowIndex : 0);
const [uncontrolledColIndex, setUncontrolledColIndex] = useState(defaultColIndex !== null && defaultColIndex !== undefined ? defaultColIndex : 0);
const isControlled = controlledRowIndex !== null && controlledColIndex !== null && controlledRowIndex !== undefined && controlledColIndex !== undefined;
const rowIndex = isControlled ? controlledRowIndex : uncontrolledRowIndex;
const colIndex = isControlled ? controlledColIndex : uncontrolledColIndex;
const rowCount = matrix.length;
const colCount = matrix[0].length;
const getCellRight = () => {
let retVal = [];
const lastRowIndex = rowCount - 1;
const lastColIndex = matrix[lastRowIndex].length - 1;
const isLastCellFocused = rowIndex === lastRowIndex && colIndex === lastColIndex;
if (!isLastCellFocused) {

@@ -140,5 +108,5 @@ if (colIndex === colCount - 1

};
var getCellLeft = function getCellLeft() {
var retVal = [];
var isFirstCellFocused = rowIndex === 0 && colIndex === 0;
const getCellLeft = () => {
let retVal = [];
const isFirstCellFocused = rowIndex === 0 && colIndex === 0;
if (!isFirstCellFocused) {

@@ -156,6 +124,6 @@ if (colIndex === 0

};
var getCellDown = function getCellDown() {
var retVal = [];
var lastRowLength = matrix[rowCount - 1].length;
var isLastCellFocused = rowIndex === rowCount - (colCount > lastRowLength ? 2 : 1) && colIndex === colCount - 1;
const getCellDown = () => {
let retVal = [];
const lastRowLength = matrix[rowCount - 1].length;
const isLastCellFocused = rowIndex === rowCount - (colCount > lastRowLength ? 2 : 1) && colIndex === colCount - 1;
if (!isLastCellFocused) {

@@ -173,5 +141,5 @@ if (rowIndex === rowCount - (colIndex >= lastRowLength ? 2 : 1)

};
var getCellUp = function getCellUp() {
var retVal = [];
var isFirstCellFocused = rowIndex === 0 && colIndex === 0;
const getCellUp = () => {
let retVal = [];
const isFirstCellFocused = rowIndex === 0 && colIndex === 0;
if (!isFirstCellFocused) {

@@ -181,5 +149,5 @@ if (rowIndex === 0

if (wrap) {
var lastRowLength = matrix[rowCount - 1].length;
var col = colIndex - 1;
var row = rowCount - (col >= lastRowLength ? 2 : 1);
const lastRowLength = matrix[rowCount - 1].length;
const col = colIndex - 1;
const row = rowCount - (col >= lastRowLength ? 2 : 1);
retVal = [row, col];

@@ -193,27 +161,19 @@ }

};
var handleKeyDown = function handleKeyDown(event) {
const handleKeyDown = event => {
if (GRID_KEYS.includes(event.key)) {
event.preventDefault();
var row = rowIndex;
var col = colIndex;
let row = rowIndex;
let col = colIndex;
switch (event.key) {
case KEYS.RIGHT:
var _ref2 = rtl ? getCellLeft() : getCellRight();
row = _ref2[0];
col = _ref2[1];
[row, col] = rtl ? getCellLeft() : getCellRight();
break;
case KEYS.LEFT:
var _ref3 = rtl ? getCellRight() : getCellLeft();
row = _ref3[0];
col = _ref3[1];
[row, col] = rtl ? getCellRight() : getCellLeft();
break;
case KEYS.DOWN:
var _getCellDown = getCellDown();
row = _getCellDown[0];
col = _getCellDown[1];
[row, col] = getCellDown();
break;
case KEYS.UP:
var _getCellUp = getCellUp();
row = _getCellUp[0];
col = _getCellUp[1];
[row, col] = getCellUp();
break;

@@ -226,4 +186,4 @@ case KEYS.HOME:

{
var lastRowIndex = rowCount - 1;
var lastColIndex = matrix[lastRowIndex].length - 1;
const lastRowIndex = rowCount - 1;
const lastColIndex = matrix[lastRowIndex].length - 1;
row = event.ctrlKey ? lastRowIndex : rowIndex;

@@ -235,4 +195,4 @@ col = event.ctrlKey ? lastColIndex : matrix[rowIndex].length - 1;

if (row !== rowIndex || col !== colIndex) {
var id = idPrefix + "-" + row + "-" + col;
var element = environment.getElementById(id);
const id = `${idPrefix}-${row}-${col}`;
const element = environment.getElementById(id);
element == null ? void 0 : element.focus();

@@ -242,13 +202,15 @@ }

};
var getGridCellProps = function getGridCellProps(_ref4) {
var rowIdx = _ref4.rowIdx,
colIdx = _ref4.colIdx,
onFocus = _ref4.onFocus,
onKeyDown = _ref4.onKeyDown,
other = _objectWithoutPropertiesLoose(_ref4, _excluded$1);
return _extends({
const getGridCellProps = _ref2 => {
let {
rowIdx,
colIdx,
onFocus,
onKeyDown,
...other
} = _ref2;
return {
tabIndex: rowIndex === rowIdx && colIndex === colIdx ? 0 : -1,
role: 'gridcell',
id: idPrefix + "-" + rowIdx + "-" + colIdx,
onFocus: composeEventHandlers(onFocus, function () {
id: `${idPrefix}-${rowIdx}-${colIdx}`,
onFocus: composeEventHandlers(onFocus, () => {
if (!isControlled) {

@@ -260,16 +222,17 @@ setUncontrolledRowIndex(rowIdx);

}),
onKeyDown: composeEventHandlers(onKeyDown, handleKeyDown)
}, other);
onKeyDown: composeEventHandlers(onKeyDown, handleKeyDown),
...other
};
};
return {
getGridCellProps: getGridCellProps
getGridCellProps
};
}
var _excluded = ["children", "render"];
var GridContainer = function GridContainer(props) {
var children = props.children,
_props$render = props.render,
render = _props$render === void 0 ? children : _props$render,
options = _objectWithoutPropertiesLoose(props, _excluded);
const GridContainer = props => {
const {
children,
render = children,
...options
} = props;
return React.createElement(React.Fragment, null, render(useGrid(options)));

@@ -276,0 +239,0 @@ };

{
"name": "@zendeskgarden/container-grid",
"version": "2.0.0",
"version": "2.0.1",
"description": "Containers relating to Grid in the Garden Design System",

@@ -44,3 +44,3 @@ "license": "Apache-2.0",

"zendeskgarden:src": "src/index.ts",
"gitHead": "9d58d7c857d5b21a8d90558be2f2be341b2a9270"
"gitHead": "621beb216c03789ed99aa39ed0f2897fa2e52368"
}
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