UNPKG

funda-ui

Version:

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

800 lines (757 loc) 35.8 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__; /******/ }() ); }); /***/ }), /***/ 316: /***/ (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__); 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; } /** * Determine whether it is the mobile terminal of the specified breakpoint * * * @usage: * const App = () => { const isMobile = useIsMobile(); return ( <div> {isMobile ? ( <p>This content is hidden on mobile devices.</p> ) : ( <p>This content is visible on larger screens.</p> )} </div> ); } */ var useIsMobile = function useIsMobile() { var breakpoint = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 600; var _useState = (0, react__WEBPACK_IMPORTED_MODULE_0__.useState)(false), _useState2 = _slicedToArray(_useState, 2), isMobile = _useState2[0], setIsMobile = _useState2[1]; var _useState3 = (0, react__WEBPACK_IMPORTED_MODULE_0__.useState)(false), _useState4 = _slicedToArray(_useState3, 2), isMounted = _useState4[0], setIsMounted = _useState4[1]; (0, react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () { // Set the mounted state to true after the component has mounted setIsMounted(true); var handleResize = function handleResize() { if (typeof window !== 'undefined') { var detectDeviceType = function detectDeviceType() { // 1. First check if window and navigator are available (SSR compatibility) if (typeof window === 'undefined' || typeof navigator === 'undefined') { return 'desktop'; // Default to desktop } // 2. Get user agent string var ua = navigator.userAgent.toLowerCase(); // 3. Get platform info var platform = navigator.platform ? navigator.platform.toLowerCase() : ''; // 4. Check screen characteristics using window.matchMedia var isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0; var isPortrait = window.matchMedia('(orientation: portrait)').matches; var isLandscape = window.matchMedia('(orientation: landscape)').matches; // 5. Get screen dimensions var screenWidth = window.screen.width; var screenHeight = window.screen.height; var minScreenSize = Math.min(screenWidth, screenHeight); var maxScreenSize = Math.max(screenWidth, screenHeight); // Define device characteristics var isTablet = // Traditional UA detection /ipad/.test(ua) || /android/.test(ua) && !/mobile/.test(ua) || /tablet/.test(ua) || /playbook/.test(ua) || /nexus (7|9|10)/.test(ua) || /sm-t/.test(ua) || /huawei(.*)mediapad/.test(ua) || // Special detection for iPad Pro and newer iPads navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1 || // Screen size characteristics (tablets typically fall within this range) minScreenSize >= breakpoint && maxScreenSize <= 1366 && isTouch || // Specific device detection /kindle|silk|kftt|kfot|kfjwa|kfjwi|kfsowi|kfthwa|kfthwi|kfapwa|kfapwi/i.test(ua); var isMobile = !isTablet && ( // Prevent tablets from being detected as phones // Traditional mobile device detection /iphone|ipod|android.*mobile|windows phone|mobi/.test(ua) || // Screen size characteristics (phones typically smaller than 600px) minScreenSize < breakpoint && isTouch || // Additional mobile device detection /blackberry|\bbb\d+|meego|webos|palm|phone|pocket|mobile|mini|iemobile/i.test(ua)); // 6. Comprehensive decision logic if (isMobile) { // Additional check for small tablets if (maxScreenSize >= 1024 && isTouch) { return 'tablet'; } return 'mobile'; } if (isTablet) { // Additional check for touch-enabled laptops if (maxScreenSize > 1366 && /windows/.test(ua)) { return 'desktop'; } return 'tablet'; } // 7. Check for touch-enabled laptops if (isTouch && /windows/.test(ua) && maxScreenSize > 1366) { return 'desktop'; } return 'desktop'; }; setIsMobile(detectDeviceType() === 'mobile'); } }; // Add event listener for resize window.addEventListener('resize', handleResize); // Call the handler once to set the initial state handleResize(); // Cleanup the event listener on component unmount return function () { window.removeEventListener('resize', handleResize); }; }, [breakpoint]); // Only return the isMobile state if the component is mounted return isMounted ? isMobile : false; }; /* harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = useIsMobile; })(); /******/ 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"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(787); /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var funda_utils_dist_cjs_cls__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(188); /* harmony import */ var funda_utils_dist_cjs_cls__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(funda_utils_dist_cjs_cls__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var funda_utils_dist_cjs_useIsMobile__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(316); /* harmony import */ var funda_utils_dist_cjs_useIsMobile__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(funda_utils_dist_cjs_useIsMobile__WEBPACK_IMPORTED_MODULE_2__); 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; } var SplitterPanelLeft = function SplitterPanelLeft(_ref) { var children = _ref.children; return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, children); }; var SplitterPanelRight = function SplitterPanelRight(_ref2) { var children = _ref2.children; return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, children); }; var SplitterPanel = function SplitterPanel(props) { var wrapperClassName = props.wrapperClassName, _props$draggable = props.draggable, draggable = _props$draggable === void 0 ? true : _props$draggable, maxWidth = props.maxWidth, _props$minWidth = props.minWidth, minWidth = _props$minWidth === void 0 ? 100 : _props$minWidth, _props$initialWidth = props.initialWidth, initialWidth = _props$initialWidth === void 0 ? 200 : _props$initialWidth, onDrag = props.onDrag, children = props.children; var containerRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(null); var dividerRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(null); var getDefaultWidth = function getDefaultWidth() { if (typeof initialWidth === 'number') return initialWidth; if (typeof minWidth === 'number') return minWidth; return 200; }; var _useState = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(getDefaultWidth()), _useState2 = _slicedToArray(_useState, 2), leftWidth = _useState2[0], setLeftWidth = _useState2[1]; var isMobile = funda_utils_dist_cjs_useIsMobile__WEBPACK_IMPORTED_MODULE_2___default()(); // adjust split panel var _useState3 = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(false), _useState4 = _slicedToArray(_useState3, 2), dragging = _useState4[0], setDragging = _useState4[1]; // Update only when initialWidth changes and is valid, and only when it has not been dragged var hasDragged = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(false); var left = null; var right = null; react__WEBPACK_IMPORTED_MODULE_0___default().Children.forEach(children, function (child) { if (! /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().isValidElement(child)) return; if (child.type === SplitterPanelLeft) left = child.props.children; if (child.type === SplitterPanelRight) right = child.props.children; }); // dragdrop function handleSplitPanelsChange(clientX) { if (!containerRef.current) return; var containerLeft = containerRef.current.getBoundingClientRect().left; var separatorXPosition = clientX - containerLeft; var minWidthValue = minWidth || 100; var maxWidthValue = maxWidth || window.innerWidth / 2; if (dragging && separatorXPosition > minWidthValue && separatorXPosition < maxWidthValue) { setLeftWidth(separatorXPosition); onDrag === null || onDrag === void 0 ? void 0 : onDrag('drag', separatorXPosition); hasDragged.current = true; } } function handleMouseDownSplitPanels(e) { setDragging(true); onDrag === null || onDrag === void 0 ? void 0 : onDrag('dragStart', leftWidth !== null && leftWidth !== void 0 ? leftWidth : initialWidth); } function handleTouchStartSplitPanels(e) { setDragging(true); onDrag === null || onDrag === void 0 ? void 0 : onDrag('dragStart', leftWidth !== null && leftWidth !== void 0 ? leftWidth : initialWidth); } function handleMouseMoveSplitPanels(e) { handleSplitPanelsChange(e.clientX); } function handleTouchMoveSplitPanels(e) { handleSplitPanelsChange(e.touches[0].clientX); } function handleMouseUpSplitPanels() { setDragging(false); onDrag === null || onDrag === void 0 ? void 0 : onDrag('dragEnd', leftWidth !== null && leftWidth !== void 0 ? leftWidth : initialWidth); } (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () { if (!draggable) return; // 事件监听用原生事件 document.addEventListener('mousemove', handleMouseMoveSplitPanels, false); document.addEventListener('touchmove', handleTouchMoveSplitPanels, false); document.addEventListener('mouseup', handleMouseUpSplitPanels, false); document.addEventListener('touchend', handleMouseUpSplitPanels, false); return function () { document.removeEventListener('mousemove', handleMouseMoveSplitPanels, false); document.removeEventListener('touchmove', handleTouchMoveSplitPanels, false); document.removeEventListener('mouseup', handleMouseUpSplitPanels, false); document.removeEventListener('touchend', handleMouseUpSplitPanels, false); }; }, [draggable, dragging]); (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () { if (!hasDragged.current && typeof initialWidth === 'number') { setLeftWidth(initialWidth); } }, [initialWidth]); return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, isMobile ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", { className: (0,funda_utils_dist_cjs_cls__WEBPACK_IMPORTED_MODULE_1__.combinedCls)('splitter-panel-vertical', (0,funda_utils_dist_cjs_cls__WEBPACK_IMPORTED_MODULE_1__.clsWrite)(wrapperClassName, '')) }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", { className: "splitter-panel-top" }, left), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", { className: "splitter-panel-bottom" }, right))) : /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", { className: (0,funda_utils_dist_cjs_cls__WEBPACK_IMPORTED_MODULE_1__.combinedCls)('splitter-panel', (0,funda_utils_dist_cjs_cls__WEBPACK_IMPORTED_MODULE_1__.clsWrite)(wrapperClassName, '')), ref: containerRef }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", { className: "splitter-panel-left", style: { "--splitter-panel-left-w": "".concat(leftWidth, "px") } }, left), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", { ref: dividerRef, className: "splitter-panel-divider ".concat(dragging ? 'dragging' : ''), onMouseDown: handleMouseDownSplitPanels, onTouchStart: handleTouchStartSplitPanels, onTouchEnd: handleMouseUpSplitPanels }), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", { className: "splitter-panel-right" }, right)))); }; SplitterPanel.Left = SplitterPanelLeft; SplitterPanel.Right = SplitterPanelRight; /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (SplitterPanel); })(); /******/ return __webpack_exports__; /******/ })() ; });