funda-ui 4.7.111 → 4.7.125

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CascadingSelect/index.d.ts +1 -0
  2. package/CascadingSelect/index.js +7 -3
  3. package/CascadingSelectE2E/index.d.ts +1 -0
  4. package/CascadingSelectE2E/index.js +7 -3
  5. package/Date/index.js +25 -2
  6. package/EventCalendar/index.js +25 -2
  7. package/EventCalendarTimeline/index.js +25 -2
  8. package/README.md +9 -10
  9. package/SplitterPanel/index.css +63 -0
  10. package/SplitterPanel/index.d.ts +20 -0
  11. package/SplitterPanel/index.js +736 -0
  12. package/Stepper/index.js +3 -2
  13. package/Utils/date.d.ts +15 -5
  14. package/Utils/date.js +22 -2
  15. package/Utils/time.d.ts +34 -0
  16. package/Utils/time.js +162 -0
  17. package/Utils/useHistoryTracker.d.ts +26 -0
  18. package/Utils/useHistoryTracker.js +475 -0
  19. package/all.d.ts +1 -0
  20. package/all.js +1 -0
  21. package/lib/cjs/CascadingSelect/index.d.ts +1 -0
  22. package/lib/cjs/CascadingSelect/index.js +7 -3
  23. package/lib/cjs/CascadingSelectE2E/index.d.ts +1 -0
  24. package/lib/cjs/CascadingSelectE2E/index.js +7 -3
  25. package/lib/cjs/Date/index.js +25 -2
  26. package/lib/cjs/EventCalendar/index.js +25 -2
  27. package/lib/cjs/EventCalendarTimeline/index.js +25 -2
  28. package/lib/cjs/SplitterPanel/index.d.ts +20 -0
  29. package/lib/cjs/SplitterPanel/index.js +736 -0
  30. package/lib/cjs/Stepper/index.js +3 -2
  31. package/lib/cjs/Utils/date.d.ts +15 -5
  32. package/lib/cjs/Utils/date.js +22 -2
  33. package/lib/cjs/Utils/time.d.ts +34 -0
  34. package/lib/cjs/Utils/time.js +162 -0
  35. package/lib/cjs/Utils/useHistoryTracker.d.ts +26 -0
  36. package/lib/cjs/Utils/useHistoryTracker.js +475 -0
  37. package/lib/cjs/index.d.ts +1 -0
  38. package/lib/cjs/index.js +1 -0
  39. package/lib/css/SplitterPanel/index.css +63 -0
  40. package/lib/esm/CascadingSelect/Group.tsx +4 -2
  41. package/lib/esm/CascadingSelect/index.tsx +3 -0
  42. package/lib/esm/CascadingSelectE2E/Group.tsx +4 -2
  43. package/lib/esm/CascadingSelectE2E/index.tsx +3 -0
  44. package/lib/esm/SplitterPanel/index.scss +82 -0
  45. package/lib/esm/SplitterPanel/index.tsx +174 -0
  46. package/lib/esm/Stepper/index.tsx +4 -2
  47. package/lib/esm/Utils/hooks/useHistoryTracker.tsx +403 -0
  48. package/lib/esm/Utils/libs/date.ts +28 -8
  49. package/lib/esm/Utils/libs/time.ts +125 -0
  50. package/lib/esm/index.js +1 -0
  51. package/package.json +1 -1
  52. package/Utils/useGlobalUrlListener.d.ts +0 -2
  53. package/Utils/useGlobalUrlListener.js +0 -157
  54. package/lib/cjs/Utils/useGlobalUrlListener.d.ts +0 -2
  55. package/lib/cjs/Utils/useGlobalUrlListener.js +0 -157
  56. package/lib/esm/Utils/hooks/useGlobalUrlListener.tsx +0 -46
@@ -205,6 +205,25 @@ function getSpecifiedDate(v: Date | string, days: number): string {
205
205
  return specifiedDay;
206
206
  }
207
207
 
208
+ /**
209
+ * Calculates the total number of days from today going back a specified number of months.
210
+ *
211
+ * @param {number} monthsAgo - The number of months to go back (e.g., 3 means the past 3 months).
212
+ * @returns {number} The total number of days between the calculated past date and today.
213
+ *
214
+ * @example
215
+ * getDaysInLastMonths(3); // Returns number of days in the past 3 months
216
+ */
217
+ function getDaysInLastMonths(monthsAgo: number = 3): number {
218
+ const today: Date = new Date();
219
+ const pastDate: Date = new Date();
220
+ pastDate.setMonth(today.getMonth() - monthsAgo);
221
+
222
+ const diffInMs: number = today.getTime() - pastDate.getTime();
223
+ const diffInDays: number = Math.round(diffInMs / (1000 * 60 * 60 * 24));
224
+
225
+ return diffInDays;
226
+ }
208
227
 
209
228
 
210
229
  /**
@@ -304,28 +323,26 @@ function getCurrentYear(): number {
304
323
  /**
305
324
  * Get current month
306
325
  * @param {Boolean} padZeroEnabled
307
- * @returns {Number}
326
+ * @returns {Number|String}
308
327
  */
309
- function getCurrentMonth(padZeroEnabled: boolean = true): number {
310
- const m: any = new Date().getMonth() + 1;
328
+ function getCurrentMonth(padZeroEnabled: boolean = true): string | number {
329
+ const m: number = new Date().getMonth() + 1;
311
330
  return padZeroEnabled ? String(m).padStart(2, '0') : m;
312
331
  }
313
332
 
314
333
 
315
-
316
334
  /**
317
335
  * Get current day
318
336
  * @param {Boolean} padZeroEnabled
319
- * @returns {Number}
337
+ * @returns {Number|String}
320
338
  */
321
- function getCurrentDay(padZeroEnabled: boolean = true): number {
322
- const d: any = new Date().getDate();
339
+ function getCurrentDay(padZeroEnabled: boolean = true): string | number {
340
+ const d: number = new Date().getDate();
323
341
  return padZeroEnabled ? String(d).padStart(2, '0') : d;
324
342
  }
325
343
 
326
344
 
327
345
 
328
-
329
346
  /**
330
347
  * Get first and last month day
331
348
  * @param {Number} v
@@ -562,7 +579,10 @@ export {
562
579
  getPrevMonthDate,
563
580
  getNextYearDate,
564
581
  getPrevYearDate,
582
+
583
+ //
565
584
  getSpecifiedDate,
585
+ getDaysInLastMonths,
566
586
 
567
587
 
568
588
  // convert
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Get timeslots from starting and ending time
3
+ * @param {string} startTime - start time in format "HH:mm"
4
+ * @param {string} endTime - end time in format "HH:mm"
5
+ * @param {number} timeInterval - time interval in minutes
6
+ * @param {boolean} formatRange - if true returns ranges like "10:00 - 11:00", if false returns single times like "10:00"
7
+ * @returns {string[]} Array of time slots
8
+ * @example
9
+
10
+ console.log(getTimeslots("10:00", "14:00", 60, true)); //['10:00 - 11:00', '11:00 - 12:00', '12:00 - 13:00', '13:00 - 14:00']
11
+ console.log(getTimeslots("10:00", "14:00", 60)); // ['10:00', '11:00', '12:00', '13:00']
12
+ */
13
+
14
+ function getTimeslots(
15
+ startTime: string,
16
+ endTime: string,
17
+ timeInterval: number,
18
+ formatRange: boolean = false
19
+ ): string[] {
20
+ const parseTime = (s: string): number => {
21
+ const c = s.split(':');
22
+ return parseInt(c[0]) * 60 + parseInt(c[1]);
23
+ }
24
+
25
+ const convertHours = (mins: number): string => {
26
+ const hour = Math.floor(mins / 60);
27
+ mins = Math.trunc(mins % 60);
28
+ const converted = pad(hour, 2) + ':' + pad(mins, 2);
29
+ return converted;
30
+ }
31
+
32
+ const pad = (str: string | number, max: number): string => {
33
+ str = str.toString();
34
+ return str.length < max ? pad("0" + str, max) : str;
35
+ }
36
+
37
+ // calculate time slot
38
+ const calculateTimeSlot = (_startTime: number, _endTime: number, _timeInterval: number): string[] => {
39
+ const timeSlots: string[] = [];
40
+ // Round start and end times to next 30 min interval
41
+ _startTime = Math.ceil(_startTime / 30) * 30;
42
+ _endTime = Math.ceil(_endTime / 30) * 30;
43
+
44
+ // Start and end of interval in the loop
45
+ let currentTime = _startTime;
46
+ while (currentTime < _endTime) {
47
+ if (formatRange) {
48
+ const t = convertHours(currentTime) + ' - ' + convertHours(currentTime + _timeInterval);
49
+ timeSlots.push(t);
50
+ } else {
51
+ timeSlots.push(convertHours(currentTime));
52
+ }
53
+ currentTime += _timeInterval;
54
+ }
55
+ return timeSlots;
56
+ }
57
+
58
+ const inputEndTime = parseTime(endTime);
59
+ const inputStartTime = parseTime(startTime);
60
+ const timeSegment = calculateTimeSlot(inputStartTime, inputEndTime, timeInterval);
61
+
62
+ return timeSegment;
63
+ }
64
+
65
+
66
+ /**
67
+ * Get minutes between two dates
68
+ * @param {Date} startDate - start date
69
+ * @param {Date} endDate - ebd date
70
+ * @returns Number
71
+ */
72
+ function getMinutesBetweenDates(startDate, endDate) {
73
+ const diff = endDate.getTime() - startDate.getTime();
74
+ return (diff / 60000);
75
+ }
76
+
77
+
78
+ /**
79
+ * Get minutes between two time
80
+ * @param {String} startTime - start time
81
+ * @param {String} endTime - ebd time
82
+ * @returns Number
83
+ */
84
+ function getMinutesBetweenTime(startTime, endTime) {
85
+ const pad = (num) => {
86
+ return ("0" + num).slice(-2);
87
+ };
88
+ let s = startTime.split(":"), sMin = +s[1] + s[0] * 60,
89
+ e = endTime.split(":"), eMin = +e[1] + e[0] * 60,
90
+ diff = eMin - sMin;
91
+
92
+ if (diff < 0) { sMin -= 12 * 60; diff = eMin - sMin }
93
+ const h = Math.floor(diff / 60),
94
+ m = diff % 60;
95
+ return "" + pad(h) + ":" + pad(m);
96
+ }
97
+
98
+
99
+
100
+ /**
101
+ * Convert HH:MM:SS into minute
102
+ * @param {String} timeStr - time string
103
+ * @returns Number
104
+ */
105
+ function convertTimeToMin(timeStr) {
106
+ const _time = timeStr.split(':').length === 3 ? `${timeStr}` : `${timeStr}:00`;
107
+
108
+ const res = _time.split(':'); // split it at the colons
109
+
110
+ // Hours are worth 60 minutes.
111
+ const minutes = (+res[0]) * 60 + (+res[1]);
112
+ return minutes;
113
+ }
114
+
115
+
116
+ export {
117
+ getTimeslots,
118
+ getMinutesBetweenDates,
119
+ getMinutesBetweenTime,
120
+ convertTimeToMin
121
+ };
122
+
123
+
124
+
125
+
package/lib/esm/index.js CHANGED
@@ -33,6 +33,7 @@ export { default as Scrollbar } from './Scrollbar';
33
33
  export { default as SearchBar } from './SearchBar';
34
34
  export { default as Select } from './Select';
35
35
  export { default as ShowMoreLess } from './ShowMoreLess';
36
+ export { default as SplitterPanel } from './SplitterPanel';
36
37
  export { default as Stepper } from './Stepper';
37
38
  export { default as Switch } from './Switch';
38
39
  export { default as Table } from './Table';
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "UIUX Lab",
3
3
  "email": "uiuxlab@gmail.com",
4
4
  "name": "funda-ui",
5
- "version": "4.7.111",
5
+ "version": "4.7.125",
6
6
  "description": "React components using pure Bootstrap 5+ which does not contain any external style and script libraries.",
7
7
  "repository": {
8
8
  "type": "git",
@@ -1,2 +0,0 @@
1
- declare const useGlobalUrlListener: () => string;
2
- export default useGlobalUrlListener;
@@ -1,157 +0,0 @@
1
- (function webpackUniversalModuleDefinition(root, factory) {
2
- if(typeof exports === 'object' && typeof module === 'object')
3
- module.exports = factory(require("react"));
4
- else if(typeof define === 'function' && define.amd)
5
- define(["react"], factory);
6
- else if(typeof exports === 'object')
7
- exports["RPB"] = factory(require("react"));
8
- else
9
- root["RPB"] = factory(root["React"]);
10
- })(this, (__WEBPACK_EXTERNAL_MODULE__787__) => {
11
- return /******/ (() => { // webpackBootstrap
12
- /******/ "use strict";
13
- /******/ var __webpack_modules__ = ({
14
-
15
- /***/ 787:
16
- /***/ ((module) => {
17
-
18
- module.exports = __WEBPACK_EXTERNAL_MODULE__787__;
19
-
20
- /***/ })
21
-
22
- /******/ });
23
- /************************************************************************/
24
- /******/ // The module cache
25
- /******/ var __webpack_module_cache__ = {};
26
- /******/
27
- /******/ // The require function
28
- /******/ function __webpack_require__(moduleId) {
29
- /******/ // Check if module is in cache
30
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
31
- /******/ if (cachedModule !== undefined) {
32
- /******/ return cachedModule.exports;
33
- /******/ }
34
- /******/ // Create a new module (and put it into the cache)
35
- /******/ var module = __webpack_module_cache__[moduleId] = {
36
- /******/ // no module.id needed
37
- /******/ // no module.loaded needed
38
- /******/ exports: {}
39
- /******/ };
40
- /******/
41
- /******/ // Execute the module function
42
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
43
- /******/
44
- /******/ // Return the exports of the module
45
- /******/ return module.exports;
46
- /******/ }
47
- /******/
48
- /************************************************************************/
49
- /******/ /* webpack/runtime/compat get default export */
50
- /******/ (() => {
51
- /******/ // getDefaultExport function for compatibility with non-harmony modules
52
- /******/ __webpack_require__.n = (module) => {
53
- /******/ var getter = module && module.__esModule ?
54
- /******/ () => (module['default']) :
55
- /******/ () => (module);
56
- /******/ __webpack_require__.d(getter, { a: getter });
57
- /******/ return getter;
58
- /******/ };
59
- /******/ })();
60
- /******/
61
- /******/ /* webpack/runtime/define property getters */
62
- /******/ (() => {
63
- /******/ // define getter functions for harmony exports
64
- /******/ __webpack_require__.d = (exports, definition) => {
65
- /******/ for(var key in definition) {
66
- /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
67
- /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
68
- /******/ }
69
- /******/ }
70
- /******/ };
71
- /******/ })();
72
- /******/
73
- /******/ /* webpack/runtime/hasOwnProperty shorthand */
74
- /******/ (() => {
75
- /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
76
- /******/ })();
77
- /******/
78
- /******/ /* webpack/runtime/make namespace object */
79
- /******/ (() => {
80
- /******/ // define __esModule on exports
81
- /******/ __webpack_require__.r = (exports) => {
82
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
83
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
84
- /******/ }
85
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
86
- /******/ };
87
- /******/ })();
88
- /******/
89
- /************************************************************************/
90
- var __webpack_exports__ = {};
91
- // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
92
- (() => {
93
- __webpack_require__.r(__webpack_exports__);
94
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
95
- /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
96
- /* harmony export */ });
97
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(787);
98
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
99
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
100
- 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."); }
101
- 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); }
102
- 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; }
103
- 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; } }
104
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
105
- /**
106
- * Global Url Listener (including micro frontends, frameworks, hashes, etc., applicable to multiple react app)
107
- *
108
- * @usage:
109
-
110
- const App = () => {
111
- const url = useGlobalUrlListener();
112
-
113
- useEffect(() => {
114
- console.log("URL changed:", url);
115
- }, [url]);
116
- };
117
-
118
- */
119
-
120
- var useGlobalUrlListener = function useGlobalUrlListener() {
121
- // Initialize state with empty string to avoid SSR issues
122
- var _useState = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(''),
123
- _useState2 = _slicedToArray(_useState, 2),
124
- url = _useState2[0],
125
- setUrl = _useState2[1];
126
- (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () {
127
- // Type guard for SSR
128
- if (typeof window === 'undefined') return;
129
-
130
- // Initialize the URL on the client side
131
- setUrl(window.location.href);
132
-
133
- // Create MutationObserver instance
134
- var observer = new MutationObserver(function () {
135
- setUrl(window.location.href);
136
- });
137
-
138
- // Start observing
139
- observer.observe(document, {
140
- subtree: true,
141
- childList: true
142
- });
143
-
144
- // Cleanup function
145
- return function () {
146
- return observer.disconnect();
147
- };
148
- }, []);
149
- return url;
150
- };
151
- /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (useGlobalUrlListener);
152
- })();
153
-
154
- /******/ return __webpack_exports__;
155
- /******/ })()
156
- ;
157
- });
@@ -1,2 +0,0 @@
1
- declare const useGlobalUrlListener: () => string;
2
- export default useGlobalUrlListener;
@@ -1,157 +0,0 @@
1
- (function webpackUniversalModuleDefinition(root, factory) {
2
- if(typeof exports === 'object' && typeof module === 'object')
3
- module.exports = factory(require("react"));
4
- else if(typeof define === 'function' && define.amd)
5
- define(["react"], factory);
6
- else if(typeof exports === 'object')
7
- exports["RPB"] = factory(require("react"));
8
- else
9
- root["RPB"] = factory(root["React"]);
10
- })(this, (__WEBPACK_EXTERNAL_MODULE__787__) => {
11
- return /******/ (() => { // webpackBootstrap
12
- /******/ "use strict";
13
- /******/ var __webpack_modules__ = ({
14
-
15
- /***/ 787:
16
- /***/ ((module) => {
17
-
18
- module.exports = __WEBPACK_EXTERNAL_MODULE__787__;
19
-
20
- /***/ })
21
-
22
- /******/ });
23
- /************************************************************************/
24
- /******/ // The module cache
25
- /******/ var __webpack_module_cache__ = {};
26
- /******/
27
- /******/ // The require function
28
- /******/ function __webpack_require__(moduleId) {
29
- /******/ // Check if module is in cache
30
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
31
- /******/ if (cachedModule !== undefined) {
32
- /******/ return cachedModule.exports;
33
- /******/ }
34
- /******/ // Create a new module (and put it into the cache)
35
- /******/ var module = __webpack_module_cache__[moduleId] = {
36
- /******/ // no module.id needed
37
- /******/ // no module.loaded needed
38
- /******/ exports: {}
39
- /******/ };
40
- /******/
41
- /******/ // Execute the module function
42
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
43
- /******/
44
- /******/ // Return the exports of the module
45
- /******/ return module.exports;
46
- /******/ }
47
- /******/
48
- /************************************************************************/
49
- /******/ /* webpack/runtime/compat get default export */
50
- /******/ (() => {
51
- /******/ // getDefaultExport function for compatibility with non-harmony modules
52
- /******/ __webpack_require__.n = (module) => {
53
- /******/ var getter = module && module.__esModule ?
54
- /******/ () => (module['default']) :
55
- /******/ () => (module);
56
- /******/ __webpack_require__.d(getter, { a: getter });
57
- /******/ return getter;
58
- /******/ };
59
- /******/ })();
60
- /******/
61
- /******/ /* webpack/runtime/define property getters */
62
- /******/ (() => {
63
- /******/ // define getter functions for harmony exports
64
- /******/ __webpack_require__.d = (exports, definition) => {
65
- /******/ for(var key in definition) {
66
- /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
67
- /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
68
- /******/ }
69
- /******/ }
70
- /******/ };
71
- /******/ })();
72
- /******/
73
- /******/ /* webpack/runtime/hasOwnProperty shorthand */
74
- /******/ (() => {
75
- /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
76
- /******/ })();
77
- /******/
78
- /******/ /* webpack/runtime/make namespace object */
79
- /******/ (() => {
80
- /******/ // define __esModule on exports
81
- /******/ __webpack_require__.r = (exports) => {
82
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
83
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
84
- /******/ }
85
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
86
- /******/ };
87
- /******/ })();
88
- /******/
89
- /************************************************************************/
90
- var __webpack_exports__ = {};
91
- // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
92
- (() => {
93
- __webpack_require__.r(__webpack_exports__);
94
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
95
- /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
96
- /* harmony export */ });
97
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(787);
98
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
99
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
100
- 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."); }
101
- 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); }
102
- 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; }
103
- 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; } }
104
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
105
- /**
106
- * Global Url Listener (including micro frontends, frameworks, hashes, etc., applicable to multiple react app)
107
- *
108
- * @usage:
109
-
110
- const App = () => {
111
- const url = useGlobalUrlListener();
112
-
113
- useEffect(() => {
114
- console.log("URL changed:", url);
115
- }, [url]);
116
- };
117
-
118
- */
119
-
120
- var useGlobalUrlListener = function useGlobalUrlListener() {
121
- // Initialize state with empty string to avoid SSR issues
122
- var _useState = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(''),
123
- _useState2 = _slicedToArray(_useState, 2),
124
- url = _useState2[0],
125
- setUrl = _useState2[1];
126
- (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () {
127
- // Type guard for SSR
128
- if (typeof window === 'undefined') return;
129
-
130
- // Initialize the URL on the client side
131
- setUrl(window.location.href);
132
-
133
- // Create MutationObserver instance
134
- var observer = new MutationObserver(function () {
135
- setUrl(window.location.href);
136
- });
137
-
138
- // Start observing
139
- observer.observe(document, {
140
- subtree: true,
141
- childList: true
142
- });
143
-
144
- // Cleanup function
145
- return function () {
146
- return observer.disconnect();
147
- };
148
- }, []);
149
- return url;
150
- };
151
- /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (useGlobalUrlListener);
152
- })();
153
-
154
- /******/ return __webpack_exports__;
155
- /******/ })()
156
- ;
157
- });
@@ -1,46 +0,0 @@
1
- /**
2
- * Global Url Listener (including micro frontends, frameworks, hashes, etc., applicable to multiple react app)
3
- *
4
- * @usage:
5
-
6
- const App = () => {
7
- const url = useGlobalUrlListener();
8
-
9
- useEffect(() => {
10
- console.log("URL changed:", url);
11
- }, [url]);
12
- };
13
-
14
- */
15
- import { useEffect, useState } from "react";
16
-
17
- const useGlobalUrlListener = (): string => {
18
- // Initialize state with empty string to avoid SSR issues
19
- const [url, setUrl] = useState<string>('');
20
-
21
- useEffect(() => {
22
- // Type guard for SSR
23
- if (typeof window === 'undefined') return;
24
-
25
- // Initialize the URL on the client side
26
- setUrl(window.location.href);
27
-
28
- // Create MutationObserver instance
29
- const observer: MutationObserver = new MutationObserver(() => {
30
- setUrl(window.location.href);
31
- });
32
-
33
- // Start observing
34
- observer.observe(document, {
35
- subtree: true,
36
- childList: true
37
- });
38
-
39
- // Cleanup function
40
- return () => observer.disconnect();
41
- }, []);
42
-
43
- return url;
44
- };
45
-
46
- export default useGlobalUrlListener;