UNPKG

funda-ui

Version:

React components using pure Bootstrap 5+ which does not contain any external style and script libraries.

1,049 lines (973 loc) 122 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("react")); else if(typeof define === 'function' && define.amd) define(["react"], factory); else if(typeof exports === 'object') exports["RPB"] = factory(require("react")); else root["RPB"] = factory(root["React"]); })(this, (__WEBPACK_EXTERNAL_MODULE__787__) => { return /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 188: /***/ (function(module, exports, __webpack_require__) { /* module decorator */ module = __webpack_require__.nmd(module); var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;function _typeof2(obj) { "@babel/helpers - typeof"; return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof2(obj); } (function webpackUniversalModuleDefinition(root, factory) { if (( false ? 0 : _typeof2(exports)) === 'object' && ( false ? 0 : _typeof2(module)) === 'object') module.exports = factory();else if (true) !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));else {} })(this, function () { return (/******/function () { // webpackBootstrap /******/ "use strict"; /******/ // The require scope /******/ var __nested_webpack_require_993__ = {}; /******/ /************************************************************************/ /******/ /* webpack/runtime/define property getters */ /******/ (function () { /******/ // define getter functions for harmony exports /******/__nested_webpack_require_993__.d = function (exports, definition) { /******/for (var key in definition) { /******/if (__nested_webpack_require_993__.o(definition, key) && !__nested_webpack_require_993__.o(exports, key)) { /******/Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (function () { /******/__nested_webpack_require_993__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; /******/ })(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ (function () { /******/ // define __esModule on exports /******/__nested_webpack_require_993__.r = function (exports) { /******/if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ })(); /******/ /************************************************************************/ var __webpack_exports__ = {}; __nested_webpack_require_993__.r(__webpack_exports__); /* harmony export */ __nested_webpack_require_993__.d(__webpack_exports__, { /* harmony export */"clsWrite": function clsWrite() { return (/* binding */_clsWrite ); }, /* harmony export */"combinedCls": function combinedCls() { return (/* binding */_combinedCls ); } /* harmony export */ }); function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } /** * Output of class name * @param {*} s - Any * @param {String} defaultCls - Default string * @param {?*} targetCls - Any * @returns {*} */ function _clsWrite(s, defaultCls) { var targetCls = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; return s || s === '' ? typeof targetCls === 'undefined' ? s : targetCls : defaultCls; } /** * Combined classnames * @param {*} args * @returns {String|undefined} */ /* Usage: console.log(combinedCls('a-1', 'a-2', 'a-3', { 'p-1': null, 'p-2': undefined, 'p-3': true, 'p-4': false, 'p-5': 'kkk', 'p-6': 0, 'p-7': 1, 'p-8': '', undefined })); // a-1 a-2 a-3 p-3 p-5 p-7 */ function _combinedCls() { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } if (args) { var classes = []; for (var i = 0; i < args.length; i++) { var className = args[i]; if (!className) { continue; } var type = _typeof(className); if (type === 'string' || type === 'number') { classes.push(className); } else if (type === 'object') { var _classes = Array.isArray(className) ? className : Object.entries(className).map(function (_ref) { var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1]; return value ? key : null; }); classes = _classes.length ? classes.concat(_classes.filter(function (c) { return !!c; })) : classes; } } return classes.join(' ').trim(); } return undefined; } /******/ return __webpack_exports__; /******/ }() ); }); /***/ }), /***/ 85: /***/ (function(module, exports, __webpack_require__) { /* module decorator */ module = __webpack_require__.nmd(module); var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } (function webpackUniversalModuleDefinition(root, factory) { if (( false ? 0 : _typeof(exports)) === 'object' && ( false ? 0 : _typeof(module)) === 'object') module.exports = factory(__webpack_require__(787));else if (true) !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(787)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));else {} })(this, function (__WEBPACK_EXTERNAL_MODULE__787__) { return (/******/function () { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = { /***/787: /***/function _(module) { module.exports = __WEBPACK_EXTERNAL_MODULE__787__; /***/ } /******/ }; /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __nested_webpack_require_1465__(moduleId) { /******/ // Check if module is in cache /******/var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_1465__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/compat get default export */ /******/ (function () { /******/ // getDefaultExport function for compatibility with non-harmony modules /******/__nested_webpack_require_1465__.n = function (module) { /******/var getter = module && module.__esModule ? /******/function () { return module['default']; } : /******/function () { return module; }; /******/ __nested_webpack_require_1465__.d(getter, { a: getter }); /******/ return getter; /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/define property getters */ /******/ (function () { /******/ // define getter functions for harmony exports /******/__nested_webpack_require_1465__.d = function (exports, definition) { /******/for (var key in definition) { /******/if (__nested_webpack_require_1465__.o(definition, key) && !__nested_webpack_require_1465__.o(exports, key)) { /******/Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (function () { /******/__nested_webpack_require_1465__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; /******/ })(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ (function () { /******/ // define __esModule on exports /******/__nested_webpack_require_1465__.r = function (exports) { /******/if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ })(); /******/ /************************************************************************/ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. (function () { __nested_webpack_require_1465__.r(__webpack_exports__); /* harmony export */ __nested_webpack_require_1465__.d(__webpack_exports__, { /* harmony export */"default": function _default() { return __WEBPACK_DEFAULT_EXPORT__; } /* harmony export */ }); /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __nested_webpack_require_1465__(787); /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nested_webpack_require_1465__.n(react__WEBPACK_IMPORTED_MODULE_0__); /** * Create an available ID * */ var useComId = function useComId() { return "ID-".concat((0, react__WEBPACK_IMPORTED_MODULE_0__.useId)().replace(/\:/g, "-")); }; /* harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = useComId; })(); /******/ return __webpack_exports__; /******/ }() ); }); /***/ }), /***/ 787: /***/ ((module) => { "use strict"; module.exports = __WEBPACK_EXTERNAL_MODULE__787__; /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ id: moduleId, /******/ loaded: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/compat get default export */ /******/ (() => { /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = (module) => { /******/ var getter = module && module.__esModule ? /******/ () => (module['default']) : /******/ () => (module); /******/ __webpack_require__.d(getter, { a: getter }); /******/ return getter; /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = (exports, definition) => { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (() => { /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) /******/ })(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ (() => { /******/ // define __esModule on exports /******/ __webpack_require__.r = (exports) => { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/node module decorator */ /******/ (() => { /******/ __webpack_require__.nmd = (module) => { /******/ module.paths = []; /******/ if (!module.children) module.children = []; /******/ return module; /******/ }; /******/ })(); /******/ /************************************************************************/ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { "use strict"; // ESM COMPAT FLAG __webpack_require__.r(__webpack_exports__); // EXPORTS __webpack_require__.d(__webpack_exports__, { "DragHandleSprite": () => (/* reexport */ utils_DragHandleSprite), "SortSprite": () => (/* reexport */ utils_SortSprite), "Table": () => (/* reexport */ src_Table), "TableBody": () => (/* reexport */ src_TableBody), "TableCaption": () => (/* reexport */ src_TableCaption), "TableCell": () => (/* reexport */ src_TableCell), "TableColgroup": () => (/* reexport */ src_TableColgroup), "TableFilter": () => (/* reexport */ utils_TableFilter), "TableFoot": () => (/* reexport */ src_TableFoot), "TableHead": () => (/* reexport */ src_TableHead), "TableRow": () => (/* reexport */ src_TableRow), "ToggleSelection": () => (/* reexport */ utils_ToggleSelection) }); // EXTERNAL MODULE: external {"root":"React","commonjs2":"react","commonjs":"react","amd":"react"} var external_root_React_commonjs2_react_commonjs_react_amd_react_ = __webpack_require__(787); var external_root_React_commonjs2_react_commonjs_react_amd_react_default = /*#__PURE__*/__webpack_require__.n(external_root_React_commonjs2_react_commonjs_react_amd_react_); // EXTERNAL MODULE: ../Utils/dist/cjs/useComId.js var useComId = __webpack_require__(85); var useComId_default = /*#__PURE__*/__webpack_require__.n(useComId); // EXTERNAL MODULE: ../Utils/dist/cjs/cls.js var cls = __webpack_require__(188); ;// CONCATENATED MODULE: ./src/TableContext.tsx var TableContext = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.createContext)(undefined); var TableProvider = function TableProvider(props) { var children = props.children, value = props.value; return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(TableContext.Provider, { value: value }, children); }; ;// CONCATENATED MODULE: ./src/utils/func.ts function convertMapToArr(setData) { var res = []; var s = setData; for (var it = s.values(), val = null; val = it.next().value;) { res.push(val); } return res; } function htmlToPlain(input) { return input.replace(/(<([^>]+)>)/ig, ''); } function sortDataByIndex(orderArr, data) { return Array.isArray(data) ? orderArr.map(function (index) { return data[index]; }) : data; } function getTbody(root) { if (root === null) return null; var tbodyRef = root.querySelector('table tbody'); return tbodyRef; } function getThead(root) { if (root === null) return null; var tbodyRef = root.querySelector('table thead'); return tbodyRef; } function allRows(root) { var tbodyRef = getTbody(root); if (tbodyRef === null) return []; return [].slice.call(tbodyRef.children); } function allHeadRows(root) { var tbodyRef = getThead(root); if (tbodyRef === null) return []; return [].slice.call(tbodyRef.children); } function initOrderProps(rootElem) { if (rootElem === null) return; // !!! Execute it only once if (typeof rootElem.dataset.customPropsInit !== 'undefined') return; rootElem.dataset.customPropsInit = 1; var _allRows = allRows(rootElem); // key _allRows.forEach(function (node, i) { node.dataset.order = "".concat(i); }); } function initRowColProps(rootElem) { if (rootElem === null) return; var _allRows = allRows(rootElem); var _allHeadRows = allHeadRows(rootElem); // key _allRows.forEach(function (node, i) { node.dataset.tableRow = "".concat(i); // columns var perCol = [].slice.call(node.children); perCol.forEach(function (col, j) { col.dataset.tableRow = "".concat(i); col.dataset.tableCol = "".concat(j); col.classList.add(cellMark(i, j)); }); }); _allHeadRows.forEach(function (node, i) { node.dataset.tableRow = "-1"; // columns var perCol = [].slice.call(node.children); perCol.forEach(function (col, j) { col.dataset.tableRow = "-1"; col.dataset.tableCol = "".concat(j); col.classList.add(cellMark(-1, j)); }); }); } function insertAfter(newNode, existingNode) { existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling); } function maxDimension(elements) { var res = { 'height': 0, 'width': 0 }; var elementHeights = Array.prototype.map.call(elements, function (el) { return el.clientHeight; }); var elementWidths = Array.prototype.map.call(elements, function (el) { return el.clientWidth; }); var maxHeight = Math.max.apply(null, elementHeights); var maxWidth = Math.max.apply(null, elementWidths); res = { 'height': maxHeight, 'width': maxWidth }; return res; } ; function tableElemScrolledInit(root, w) { var tbodyRef = getTbody(root); if (tbodyRef === null) return; if (w <= 768 && tbodyRef.querySelector('tr') !== null) { var _loop = function _loop() { var tbodyRows = root.querySelectorAll("tbody tr [data-table-col=\"".concat(i, "\"]")); var maxHeight = maxDimension(tbodyRows).height; if (maxHeight > 0) { [].slice.call(tbodyRows).forEach(function (row) { row.style.height = maxHeight + 'px'; }); // var theadRows = root.querySelectorAll("thead tr [data-table-col=\"".concat(i, "\"]")); [].slice.call(theadRows).forEach(function (row) { row.style.height = maxHeight + 'px'; }); } }; //get maxHeight of per row for (var i = 0; i < tbodyRef.querySelector('tr').children.length; i++) { _loop(); } } else { [].slice.call(root.querySelectorAll('tbody td, tbody th, thead th')).forEach(function (node, i) { node.style.removeProperty('height'); }); } } function cellMark(row, col) { var isNegative = function isNegative(num) { return num < 0; }; return "cell-".concat(isNegative(row) ? 0 : row, "-").concat(isNegative(col) ? 0 : col); } function removeCellFocusClassName(root) { if (root) { [].slice.call(root.querySelectorAll('td, th')).forEach(function (el) { el.classList.remove('cell-focus'); }); } } function getTableRowsColCount(root) { var rows = allRows(root); return rows.map(function (row, i) { return { row: i, colCount: row.children.length }; }); } ;// CONCATENATED MODULE: ./src/utils/hooks/useTableResponsive.tsx function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } /** * Handles the event of responsive table * * @usage: const App = () => { const responsiveTable = true; const rootRef = useRef<any>(null); useTableResponsive({ enabled: responsiveTable && rootRef.current, spyElement: rootRef.current }, [rootRef]); return ( <div ref={rootRef} >Test</div> ); }; */ function useTableResponsive(_ref, deps) { var enabled = _ref.enabled, spyElement = _ref.spyElement; var debounce = function debounce(fn) { var limit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 300; var timer; return function () { clearTimeout(timer); timer = setTimeout(function () { fn.apply(this, arguments); }, limit); }; }; var windowResizeUpdate = debounce(handleWindowUpdate, 50); var windowWidth = typeof window !== 'undefined' ? window.innerWidth : 0; function handleWindowUpdate() { // Check window width has actually changed and it's not just iOS triggering a resize event on scroll if (window.innerWidth != windowWidth) { // Update the window width for next time windowWidth = window.innerWidth; // Do stuff here tableElemScrolledInit(spyElement, windowWidth); } } (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () { if (enabled) { // Initialize custom props of table elements initOrderProps(spyElement); initRowColProps(spyElement); // With scroll bars var _windowWidth = window.innerWidth; tableElemScrolledInit(spyElement, _windowWidth); // Add function to the element that should be used as the scrollable area. window.removeEventListener('resize', windowResizeUpdate); window.addEventListener('resize', windowResizeUpdate); // Remove the global list of events, especially as scroll and interval. return function () { window.removeEventListener('resize', windowResizeUpdate); }; } }, [enabled, spyElement].concat(_toConsumableArray(deps))); } /* harmony default export */ const hooks_useTableResponsive = (useTableResponsive); ;// CONCATENATED MODULE: ./src/utils/hooks/useTableDraggable.tsx function useTableDraggable_toConsumableArray(arr) { return useTableDraggable_arrayWithoutHoles(arr) || useTableDraggable_iterableToArray(arr) || useTableDraggable_unsupportedIterableToArray(arr) || useTableDraggable_nonIterableSpread(); } function useTableDraggable_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function useTableDraggable_iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function useTableDraggable_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return useTableDraggable_arrayLikeToArray(arr); } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || useTableDraggable_unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function useTableDraggable_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return useTableDraggable_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return useTableDraggable_arrayLikeToArray(o, minLen); } function useTableDraggable_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /** * Handles the event of drag-and-drop sorting * * @usage: const App = () => { const rowDraggable = true; const data = [{a: 1}, {b: 2}] const rootRef = useRef<any>(null); const { handleDragStart, handleDragEnd, handledragOver, handleTbodyEnter } = useTableDraggable({ enabled: rowDraggable && spyElement, data: data, spyElement: spyElement onRowDrag: (dragStart: any, dragEnd: any) => void(0) }, [data, rootRef]); return ( <div ref={rootRef} >Test</div> ); }; */ function useTableDraggable(_ref, deps) { var enabled = _ref.enabled, data = _ref.data, spyElement = _ref.spyElement, onRowDrag = _ref.onRowDrag; // drag & drop var _useState = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)([]), _useState2 = _slicedToArray(_useState, 2), sortData = _useState2[0], setSortData = _useState2[1]; // ================================================================ // drag & drop // ================================================================ var draggedObj = null; var overObj = null; var placeholderGenerator = function placeholderGenerator(trHeight) { var tbodyRef = getTbody(spyElement); if (tbodyRef === null || tbodyRef.querySelector('tr') === null) return; // Insert a row at the "index" of the table var newRow = document.createElement('tr'); newRow.className = 'row-placeholder'; newRow.dataset.placeholder = 'true'; newRow.style.height = trHeight + 'px'; // Insert a cell in the row at index var newCell = newRow.insertCell(0); newCell.colSpan = tbodyRef.querySelector('tr').children.length; // Append a text node to the cell var newText = document.createTextNode(' '); newCell.appendChild(newText); return newRow; }; var lastRowGenerator = function lastRowGenerator(trHeight) { var tbodyRef = getTbody(spyElement); if (tbodyRef === null || tbodyRef.querySelector('tr') === null) return; var cloneEl = tbodyRef.querySelector('.row-obj-clonelast'); if (cloneEl !== null) return; // Insert a row at the "index" of the table var newRow = document.createElement('tr'); newRow.className = 'row-obj row-obj-clonelast'; newRow.dataset.order = allRows(spyElement).length.toString(); newRow.style.height = trHeight + 'px'; newRow.style.display = 'none'; // Insert a cell in the row at index var newCell = newRow.insertCell(0); newCell.colSpan = tbodyRef.querySelector('tr').children.length; // Append a text node to the cell var newText = document.createTextNode(' '); newCell.appendChild(newText); return newRow; }; var removePlaceholder = function removePlaceholder() { var tbodyRef = getTbody(spyElement); if (tbodyRef === null) return; // Delete row at the "index" of the table var placeholder = [].slice.call(tbodyRef.querySelectorAll("[data-placeholder]")); placeholder.forEach(function (node) { tbodyRef.removeChild(node); }); }; // Initialize drag & drop data // !!! Execute it only once var initDragDropData = function initDragDropData() { if (spyElement === null) return; if (typeof spyElement.dataset.dragdropDataInit !== 'undefined') return; spyElement.dataset.dragdropDataInit = 1; var _allRows = allRows(spyElement); // sort list data var listIndexes = _allRows.map(function (node, i) { return i; }); setSortData(listIndexes); //last placeholder if (_allRows.length > 0) { var lastEl = lastRowGenerator(_allRows.at(-1).clientHeight); if (typeof _allRows.at(-1) !== 'undefined') { insertAfter(lastEl, _allRows.at(-1)); } } }; var handleTbodyEnter = function handleTbodyEnter(e) { var _table = e.currentTarget.closest('table'); if (_table === null) return; _table.querySelector('tbody').classList.add('drag-trigger-mousedown'); }; var handleTbodyLeave = function handleTbodyLeave(e) { var tbodyRef = getTbody(spyElement); if (tbodyRef === null) return; tbodyRef === null || tbodyRef === void 0 ? void 0 : tbodyRef.classList.remove('drag-trigger-mousedown'); }; // events fired on the drop targets var handledragOver = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function (e) { var tbodyRef = getTbody(spyElement); if (tbodyRef === null) return; e.preventDefault(); if (draggedObj === null) return; draggedObj.style.display = 'none'; if (e.target.classList.contains('row-placeholder')) return; var itemsWrapper = e.target.parentNode; if (itemsWrapper.classList.contains('row-obj')) { overObj = itemsWrapper; removePlaceholder(); if (Number(overObj.dataset.order) === allRows(spyElement).length - 1) { tbodyRef.insertBefore(placeholderGenerator(allRows(spyElement).at(-2).clientHeight), overObj); } else { tbodyRef.insertBefore(placeholderGenerator(overObj.clientHeight), overObj); } } }, [sortData]); var handleDragStart = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function (e) { var tbodyRef = getTbody(spyElement); if (tbodyRef === null) return; draggedObj = e.currentTarget; e.dataTransfer.effectAllowed = 'move'; e.dataTransfer.setData('text/html', draggedObj); draggedObj.classList.add('dragging'); allRows(spyElement).at(-1).style.setProperty('display', 'table-row', "important"); // callback var dragStart = function dragStart(callback) { callback.call(null, draggedObj, sortData, sortDataByIndex(sortData, data)); }; onRowDrag === null || onRowDrag === void 0 ? void 0 : onRowDrag(dragStart, null); // init clone <tr> // !!! It needs to be put at the end of the code to fix the location of the clone element var cloneEl = tbodyRef.querySelector('.row-obj-clonelast'); if (cloneEl !== null) { cloneEl.style.display = 'none'; } }, [handledragOver]); var handleDragEnd = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function (e) { var tbodyRef = getTbody(spyElement); if (tbodyRef === null) return; draggedObj.style.display = 'table-row'; removePlaceholder(); draggedObj.classList.remove('dragging'); tbodyRef === null || tbodyRef === void 0 ? void 0 : tbodyRef.classList.remove('drag-trigger-mousedown'); if (overObj === null) return; // update state var curData = []; curData = JSON.parse(JSON.stringify(sortData)); var from = Number(draggedObj.dataset.order); var to = Number(overObj.dataset.order); if (from < to) to--; //sort data var newData = []; // console.log('--> data1:', curData); curData.splice(to, 0, curData.splice(from, 1)[0]); for (var i = 0; i < curData.length; i++) { for (var j = 0; j < curData.length; j++) { if (curData[i] === curData[j]) { newData.push(curData[j]); } } } // console.log("--> data2: ", newData); setSortData(newData); // reset data-id in order to sort data newData.forEach(function (curId, order) { var _el = spyElement.querySelector('table').querySelector("tbody [data-key=\"row-".concat(curId, "\"]")); if (_el !== null) _el.dataset.order = order; }); // sort elements var categoryItemsArray = allRows(spyElement); var sorter = function sorter(a, b) { var txt1 = Number(a.dataset.order), txt2 = Number(b.dataset.order); return txt2 < txt1 ? -1 : txt2 > txt1 ? 1 : 0; }; var sorted = categoryItemsArray.sort(sorter).reverse(); sorted.forEach(function (e) { return spyElement.querySelector('table').querySelector('tbody').appendChild(e); }); // callback var dragEnd = function dragEnd(callback) { callback.call(null, draggedObj, newData, sortDataByIndex(newData, data)); }; onRowDrag === null || onRowDrag === void 0 ? void 0 : onRowDrag(null, dragEnd); // init clone <tr> // !!! It needs to be put at the end of the code to fix the location of the clone element var _allRows = allRows(spyElement); var cloneEl = tbodyRef.querySelector('.row-obj-clonelast'); if (cloneEl !== null) { if (typeof _allRows.at(-1) !== 'undefined') { insertAfter(cloneEl, _allRows.at(-1)); cloneEl.style.display = 'none'; } } }, [sortData]); (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () { if (enabled) { if (Array.isArray(data) && data.length > 0) { // !!! REQUIRED "data.length > 0" to avoid data-order cannot be assigned when asynchronous data is empty data.forEach(function (item, i) { item.order = i; }); // Initialize custom props of table elements initOrderProps(spyElement); initRowColProps(spyElement); // Initialize drag & drop data initDragDropData(); } } }, [data, enabled, spyElement].concat(useTableDraggable_toConsumableArray(deps))); return { handleDragStart: handleDragStart, handleDragEnd: handleDragEnd, handledragOver: handledragOver, handleTbodyEnter: handleTbodyEnter, handleTbodyLeave: handleTbodyLeave }; } /* harmony default export */ const hooks_useTableDraggable = (useTableDraggable); ;// CONCATENATED MODULE: ./src/utils/hooks/useTableKeyPress.tsx function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } function useTableKeyPress_toConsumableArray(arr) { return useTableKeyPress_arrayWithoutHoles(arr) || useTableKeyPress_iterableToArray(arr) || useTableKeyPress_unsupportedIterableToArray(arr) || useTableKeyPress_nonIterableSpread(); } function useTableKeyPress_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function useTableKeyPress_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return useTableKeyPress_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return useTableKeyPress_arrayLikeToArray(o, minLen); } function useTableKeyPress_iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function useTableKeyPress_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return useTableKeyPress_arrayLikeToArray(arr); } function useTableKeyPress_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGenerat