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

@commercetools-uikit/hooks

Package Overview
Dependencies
Maintainers
4
Versions
736
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercetools-uikit/hooks - npm Package Compare versions

Comparing version 10.17.1-canary.0 to 10.17.1-canary.1

204

dist/hooks.cjs.js

@@ -9,3 +9,53 @@ 'use strict';

var React__default = _interopDefault(React);
var sortBy = _interopDefault(require('lodash/sortBy'));
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
function _slicedToArray(arr, i) {

@@ -92,7 +142,159 @@ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();

var version = '10.17.1-canary.0+a66a593d';
var getInitialState = function getInitialState(rows, keyName) {
return rows.reduce(function (items, currentItem) {
return _objectSpread2({}, items, _defineProperty({}, currentItem.id, currentItem[keyName] || false));
}, {});
};
function selectionReducer(state, action) {
switch (action.type) {
case 'toggle':
return _objectSpread2({}, state, _defineProperty({}, action.payload, !state[action.payload]));
case 'select':
return _objectSpread2({}, state, _defineProperty({}, action.payload, true));
case 'deselect':
return _objectSpread2({}, state, _defineProperty({}, action.payload, false));
case 'selectAll':
{
return Object.keys(state).reduce(function (accumulator, currentItem) {
return _objectSpread2({}, accumulator, _defineProperty({}, currentItem, true));
}, {});
}
case 'deselectAll':
{
return Object.keys(state).reduce(function (accumulator, currentItem) {
return _objectSpread2({}, accumulator, _defineProperty({}, currentItem, false));
}, {});
}
default:
return state;
}
}
var useSelectionReducer = function useSelectionReducer(rows, keyName) {
var _React$useReducer = React__default.useReducer(selectionReducer, getInitialState(rows, keyName)),
_React$useReducer2 = _slicedToArray(_React$useReducer, 2),
selectionState = _React$useReducer2[0],
dispatch = _React$useReducer2[1];
React__default.useDebugValue(selectionState);
return [selectionState, dispatch];
};
var useRowSelection = function useRowSelection(keyName, rows) {
var _useSelectionReducer = useSelectionReducer(rows, keyName),
_useSelectionReducer2 = _slicedToArray(_useSelectionReducer, 2),
selectionState = _useSelectionReducer2[0],
dispatch = _useSelectionReducer2[1];
var selectableRows = rows.map(function (item) {
return _objectSpread2({}, item, _defineProperty({}, keyName, selectionState[item.id]));
});
var toggleRow = function toggleRow(id) {
return dispatch({
type: 'toggle',
payload: id
});
};
var selectRow = function selectRow(id) {
return dispatch({
type: 'select',
payload: id
});
};
var deselectRow = function deselectRow(id) {
return dispatch({
type: 'deselect',
payload: id
});
};
var selectAllRows = function selectAllRows() {
return dispatch({
type: 'selectAll'
});
};
var deselectAllRows = function deselectAllRows() {
return dispatch({
type: 'deselectAll'
});
};
var getIsRowSelected = function getIsRowSelected(id) {
return selectionState[id];
};
var getNumberOfSelectedRows = function getNumberOfSelectedRows() {
return selectableRows.reduce(function (count, item) {
return count + item[keyName];
}, 0);
};
return {
rows: selectableRows,
toggleRow: toggleRow,
selectRow: selectRow,
deselectRow: deselectRow,
selectAllRows: selectAllRows,
deselectAllRows: deselectAllRows,
getIsRowSelected: getIsRowSelected,
getNumberOfSelectedRows: getNumberOfSelectedRows
};
};
var sortItems = function sortItems(items, field, direction) {
var sortingFunction = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : sortBy;
if (!field) {
return items;
}
var sortedItems = sortingFunction(items, field);
if (direction === 'desc') {
return sortedItems.reverse();
}
return sortedItems;
};
var getInitialState$1 = function getInitialState(items, field, sortDirection, sortingFunction) {
return {
items: sortItems(items, field, sortDirection, sortingFunction),
sortedBy: field,
sortDirection: sortDirection
};
};
var useSortingState = function useSortingState(items, field, sortDirection, sortingFunction) {
var _React$useState = React__default.useState(function () {
return getInitialState$1(items, field, sortDirection, sortingFunction);
}),
_React$useState2 = _slicedToArray(_React$useState, 2),
sortState = _React$useState2[0],
setSorting = _React$useState2[1];
React__default.useDebugValue(sortState);
return [sortState, setSorting];
};
var useSorting = function useSorting(items, field, sortDirection, sortingFunction) {
var _useSortingState = useSortingState(items, field, sortDirection, sortingFunction),
_useSortingState2 = _slicedToArray(_useSortingState, 2),
sortState = _useSortingState2[0],
setSorting = _useSortingState2[1];
function onSortChange(fieldKey) {
var nextSortDirection;
var sortedItems;
if (sortState.sortedBy !== fieldKey) {
nextSortDirection = 'asc';
sortedItems = sortItems(sortState.items, fieldKey, nextSortDirection);
} else {
nextSortDirection = sortState.sortDirection === 'asc' ? 'desc' : 'asc';
sortedItems = sortState.items.reverse();
}
setSorting({
items: sortedItems,
sortedBy: fieldKey,
sortDirection: nextSortDirection
});
}
return {
items: sortState.items,
sortedBy: sortState.sortedBy,
sortDirection: sortState.sortDirection,
onSortChange: onSortChange
};
};
var version = '10.17.1-canary.1+3c3abfef';
exports.useFieldId = useFieldId;
exports.usePrevious = usePrevious;
exports.useRowSelection = useRowSelection;
exports.useSorting = useSorting;
exports.useToggleState = useToggleState;
exports.version = version;
import React, { useState, useCallback } from 'react';
import sortBy from 'lodash/sortBy';
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
function _slicedToArray(arr, i) {

@@ -84,4 +134,154 @@ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();

var version = '10.17.1-canary.0+a66a593d';
var getInitialState = function getInitialState(rows, keyName) {
return rows.reduce(function (items, currentItem) {
return _objectSpread2({}, items, _defineProperty({}, currentItem.id, currentItem[keyName] || false));
}, {});
};
function selectionReducer(state, action) {
switch (action.type) {
case 'toggle':
return _objectSpread2({}, state, _defineProperty({}, action.payload, !state[action.payload]));
case 'select':
return _objectSpread2({}, state, _defineProperty({}, action.payload, true));
case 'deselect':
return _objectSpread2({}, state, _defineProperty({}, action.payload, false));
case 'selectAll':
{
return Object.keys(state).reduce(function (accumulator, currentItem) {
return _objectSpread2({}, accumulator, _defineProperty({}, currentItem, true));
}, {});
}
case 'deselectAll':
{
return Object.keys(state).reduce(function (accumulator, currentItem) {
return _objectSpread2({}, accumulator, _defineProperty({}, currentItem, false));
}, {});
}
default:
return state;
}
}
var useSelectionReducer = function useSelectionReducer(rows, keyName) {
var _React$useReducer = React.useReducer(selectionReducer, getInitialState(rows, keyName)),
_React$useReducer2 = _slicedToArray(_React$useReducer, 2),
selectionState = _React$useReducer2[0],
dispatch = _React$useReducer2[1];
React.useDebugValue(selectionState);
return [selectionState, dispatch];
};
var useRowSelection = function useRowSelection(keyName, rows) {
var _useSelectionReducer = useSelectionReducer(rows, keyName),
_useSelectionReducer2 = _slicedToArray(_useSelectionReducer, 2),
selectionState = _useSelectionReducer2[0],
dispatch = _useSelectionReducer2[1];
var selectableRows = rows.map(function (item) {
return _objectSpread2({}, item, _defineProperty({}, keyName, selectionState[item.id]));
});
var toggleRow = function toggleRow(id) {
return dispatch({
type: 'toggle',
payload: id
});
};
var selectRow = function selectRow(id) {
return dispatch({
type: 'select',
payload: id
});
};
var deselectRow = function deselectRow(id) {
return dispatch({
type: 'deselect',
payload: id
});
};
var selectAllRows = function selectAllRows() {
return dispatch({
type: 'selectAll'
});
};
var deselectAllRows = function deselectAllRows() {
return dispatch({
type: 'deselectAll'
});
};
var getIsRowSelected = function getIsRowSelected(id) {
return selectionState[id];
};
var getNumberOfSelectedRows = function getNumberOfSelectedRows() {
return selectableRows.reduce(function (count, item) {
return count + item[keyName];
}, 0);
};
return {
rows: selectableRows,
toggleRow: toggleRow,
selectRow: selectRow,
deselectRow: deselectRow,
selectAllRows: selectAllRows,
deselectAllRows: deselectAllRows,
getIsRowSelected: getIsRowSelected,
getNumberOfSelectedRows: getNumberOfSelectedRows
};
};
export { useFieldId, usePrevious, useToggleState, version };
var sortItems = function sortItems(items, field, direction) {
var sortingFunction = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : sortBy;
if (!field) {
return items;
}
var sortedItems = sortingFunction(items, field);
if (direction === 'desc') {
return sortedItems.reverse();
}
return sortedItems;
};
var getInitialState$1 = function getInitialState(items, field, sortDirection, sortingFunction) {
return {
items: sortItems(items, field, sortDirection, sortingFunction),
sortedBy: field,
sortDirection: sortDirection
};
};
var useSortingState = function useSortingState(items, field, sortDirection, sortingFunction) {
var _React$useState = React.useState(function () {
return getInitialState$1(items, field, sortDirection, sortingFunction);
}),
_React$useState2 = _slicedToArray(_React$useState, 2),
sortState = _React$useState2[0],
setSorting = _React$useState2[1];
React.useDebugValue(sortState);
return [sortState, setSorting];
};
var useSorting = function useSorting(items, field, sortDirection, sortingFunction) {
var _useSortingState = useSortingState(items, field, sortDirection, sortingFunction),
_useSortingState2 = _slicedToArray(_useSortingState, 2),
sortState = _useSortingState2[0],
setSorting = _useSortingState2[1];
function onSortChange(fieldKey) {
var nextSortDirection;
var sortedItems;
if (sortState.sortedBy !== fieldKey) {
nextSortDirection = 'asc';
sortedItems = sortItems(sortState.items, fieldKey, nextSortDirection);
} else {
nextSortDirection = sortState.sortDirection === 'asc' ? 'desc' : 'asc';
sortedItems = sortState.items.reverse();
}
setSorting({
items: sortedItems,
sortedBy: fieldKey,
sortDirection: nextSortDirection
});
}
return {
items: sortState.items,
sortedBy: sortState.sortedBy,
sortDirection: sortState.sortDirection,
onSortChange: onSortChange
};
};
var version = '10.17.1-canary.1+3c3abfef';
export { useFieldId, usePrevious, useRowSelection, useSorting, useToggleState, version };

5

package.json
{
"name": "@commercetools-uikit/hooks",
"version": "10.17.1-canary.0+a66a593d",
"version": "10.17.1-canary.1+3c3abfef",
"description": "",

@@ -21,6 +21,7 @@ "main": "dist/hooks.cjs.js",

"peerDependencies": {
"lodash": "4.17.15",
"react": ">= 16.8.0"
},
"license": "MIT",
"gitHead": "a66a593dd9462e26537b4dd2d13180c367632773"
"gitHead": "3c3abfefb13b3d319241c293ae9ff99f26d11ebc"
}
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