funda-ui 4.7.163 → 4.7.175

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.
@@ -96,6 +96,15 @@ __webpack_require__.r(__webpack_exports__);
96
96
  /* harmony export */ });
97
97
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(787);
98
98
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
99
+ 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); }
100
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
101
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
102
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
103
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
104
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
105
+ 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.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
106
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
107
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
99
108
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
100
109
  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."); }
101
110
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
@@ -108,17 +117,19 @@ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefine
108
117
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
109
118
  /**
110
119
  * History Tracker
120
+ * @since 20250515
111
121
  *
112
122
  * @usage:
113
123
 
114
124
  const App = () => {
115
125
  const {
116
- history,
117
- forwardHistory,
118
- currentUrl,
119
- firstUrl,
126
+ getReady,
120
127
  clearHistory,
121
- goBack
128
+ goBack,
129
+ getFirstUrl,
130
+ getCurrentUrl,
131
+ getForwardHistory,
132
+ getHistory,
122
133
  } = useHistoryTracker({
123
134
  onChange: ({
124
135
  isReady,
@@ -149,32 +160,50 @@ const App = () => {
149
160
  }
150
161
  });
151
162
 
163
+ // useEffect(() => {
164
+ // console.log(getReady(), getFirstUrl(), getCurrentUrl(), getForwardHistory(), getHistory());
165
+ // }, [getReady, getFirstUrl, getCurrentUrl]);
166
+
167
+
168
+ // useEffect(() => {
169
+ // setTimeout(async () => {
170
+ // console.log('--> clean history within 2m');
171
+ // await clearHistory();
172
+ // }, 2000);
173
+ // }, []);
174
+
175
+
152
176
  return (
153
177
  <div>
154
178
 
179
+ <div>
180
+ <h3>isReady:</h3>
181
+ <p>{String(getReady())}</p>
182
+ </div>
183
+
155
184
  <div>
156
185
  <h3>First URL:</h3>
157
- <p>{firstUrl}</p>
186
+ <p>{getFirstUrl()}</p>
158
187
  </div>
159
188
 
160
189
  <div>
161
190
  <h3>Current URL:</h3>
162
- <p>{currentUrl}</p>
191
+ <p>{getCurrentUrl()}</p>
163
192
  </div>
164
193
 
165
194
  <div>
166
- <h3>History ({history.length}):</h3>
195
+ <h3>History ({getHistory().length}):</h3>
167
196
  <ul>
168
- {history.map((url, index) => (
197
+ {getHistory().map((url, index) => (
169
198
  <li key={index}>{url}</li>
170
199
  ))}
171
200
  </ul>
172
201
  </div>
173
202
 
174
203
  <div>
175
- <h3>Forward History ({forwardHistory.length}):</h3>
204
+ <h3>Forward History ({getForwardHistory().length}):</h3>
176
205
  <ul>
177
- {forwardHistory.map((url, index) => (
206
+ {getForwardHistory().map((url, index) => (
178
207
  <li key={index}>{url}</li>
179
208
  ))}
180
209
  </ul>
@@ -225,10 +254,12 @@ const App = () => {
225
254
 
226
255
  */
227
256
 
257
+
228
258
  // Create a secure version of useLayoutEffect that is downgraded to useEffect when SSR
229
259
  var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? react__WEBPACK_IMPORTED_MODULE_0__.useLayoutEffect : react__WEBPACK_IMPORTED_MODULE_0__.useEffect;
230
260
  var useHistoryTracker = function useHistoryTracker(props) {
231
- var onChange = props.onChange;
261
+ var _ref = props || {},
262
+ onChange = _ref.onChange;
232
263
  var _useState = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(false),
233
264
  _useState2 = _slicedToArray(_useState, 2),
234
265
  isReady = _useState2[0],
@@ -240,7 +271,14 @@ var useHistoryTracker = function useHistoryTracker(props) {
240
271
  _useState4 = _slicedToArray(_useState3, 2),
241
272
  currentUrl = _useState4[0],
242
273
  setCurrentUrl = _useState4[1];
274
+ var canGoBack = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
275
+ return historyRef.current.length > 1;
276
+ }, []);
277
+ var canGoForward = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
278
+ return forwardHistoryRef.current.length > 0;
279
+ }, []);
243
280
  var initialize = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
281
+ var ready = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
244
282
  if (typeof window === 'undefined') return;
245
283
  var currentLocation = window.location.href;
246
284
 
@@ -249,8 +287,8 @@ var useHistoryTracker = function useHistoryTracker(props) {
249
287
  firstUrlRef.current = currentLocation;
250
288
  historyRef.current = [currentLocation];
251
289
  setCurrentUrl(currentLocation);
252
- onChange === null || onChange === void 0 ? void 0 : onChange({
253
- isReady: false,
290
+ onChange && onChange({
291
+ isReady: ready,
254
292
  history: [currentLocation],
255
293
  forwardHistory: [],
256
294
  currentUrl: currentLocation,
@@ -260,27 +298,10 @@ var useHistoryTracker = function useHistoryTracker(props) {
260
298
  });
261
299
  }
262
300
  setIsReady(true);
263
- }, []);
301
+ }, [onChange]);
264
302
  useIsomorphicLayoutEffect(function () {
265
303
  initialize();
266
304
  }, [initialize]);
267
- var clearHistory = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
268
- if (typeof window === 'undefined') return;
269
- historyRef.current = [];
270
- forwardHistoryRef.current = [];
271
- firstUrlRef.current = '';
272
- setCurrentUrl('');
273
- onChange === null || onChange === void 0 ? void 0 : onChange({
274
- isReady: true,
275
- history: [],
276
- forwardHistory: [],
277
- currentUrl: '',
278
- firstUrl: '',
279
- canGoBack: false,
280
- canGoForward: false
281
- });
282
- }, [onChange]); // only "onChange"
283
-
284
305
  var goToHistory = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function (index) {
285
306
  if (typeof window === 'undefined') return;
286
307
  if (index < 0 || index >= historyRef.current.length) return;
@@ -291,11 +312,13 @@ var useHistoryTracker = function useHistoryTracker(props) {
291
312
  }, []);
292
313
  var goBack = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
293
314
  if (typeof window === 'undefined') return Promise.reject('Window is undefined');
294
- if (historyRef.current.length <= 1) return Promise.reject('Cannot go back');
315
+ if (historyRef.current.length <= 1) return Promise.reject('History does not meet the criteria (total records are less than 2), cannot go back');
295
316
  return new Promise(function (resolve) {
296
317
  // Moves the current URL into the forward history
297
318
  var removedUrl = historyRef.current.pop();
298
- forwardHistoryRef.current.push(removedUrl);
319
+ if (removedUrl) {
320
+ forwardHistoryRef.current.push(removedUrl);
321
+ }
299
322
  var newCurrentUrl = historyRef.current[historyRef.current.length - 1];
300
323
  setCurrentUrl(newCurrentUrl);
301
324
 
@@ -311,7 +334,7 @@ var useHistoryTracker = function useHistoryTracker(props) {
311
334
  };
312
335
 
313
336
  // Notify about the history change
314
- onChange === null || onChange === void 0 ? void 0 : onChange(data);
337
+ onChange && onChange(data);
315
338
 
316
339
  // Create one-time listener for popstate
317
340
  var handlePopState = function handlePopState() {
@@ -337,27 +360,29 @@ var useHistoryTracker = function useHistoryTracker(props) {
337
360
  // Trigger the navigation
338
361
  window.history.go(-1);
339
362
  });
340
- }, [onChange]);
363
+ }, [onChange, canGoBack, canGoForward]);
341
364
  var goForward = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
342
365
  if (typeof window === 'undefined') return Promise.reject('Window is undefined');
343
- if (forwardHistoryRef.current.length === 0) return Promise.reject('Cannot go forward');
366
+ if (forwardHistoryRef.current.length === 0) return Promise.reject('Forward history does not meet the criteria (total 0 records), cannot go forward');
344
367
  return new Promise(function (resolve) {
345
368
  // Take the URL from the forward history and add it to the main history
346
369
  var nextUrl = forwardHistoryRef.current.pop();
347
- historyRef.current.push(nextUrl);
348
- setCurrentUrl(nextUrl);
370
+ if (nextUrl) {
371
+ historyRef.current.push(nextUrl);
372
+ setCurrentUrl(nextUrl);
373
+ }
349
374
 
350
375
  // Create initial data object
351
376
  var data = {
352
377
  isReady: true,
353
378
  history: _toConsumableArray(historyRef.current),
354
379
  forwardHistory: _toConsumableArray(forwardHistoryRef.current),
355
- currentUrl: nextUrl,
380
+ currentUrl: nextUrl || '',
356
381
  firstUrl: firstUrlRef.current,
357
382
  canGoBack: canGoBack(),
358
383
  canGoForward: canGoForward()
359
384
  };
360
- onChange === null || onChange === void 0 ? void 0 : onChange(data);
385
+ onChange && onChange(data);
361
386
 
362
387
  // Create one-time listener for popstate
363
388
  var handlePopState = function handlePopState() {
@@ -383,42 +408,164 @@ var useHistoryTracker = function useHistoryTracker(props) {
383
408
  // Trigger the navigation
384
409
  window.history.go(1);
385
410
  });
386
- }, [onChange]);
387
- var canGoBack = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
388
- return historyRef.current.length > 1;
389
- }, []);
390
- var canGoForward = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
391
- return forwardHistoryRef.current.length > 0;
392
- }, []);
411
+ }, [onChange, canGoBack, canGoForward]);
393
412
  var handleUrlChange = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
394
413
  if (typeof window === 'undefined') return;
395
414
  var newUrl = window.location.href;
396
415
 
397
- // If the history is empty, set to the first URL
416
+ // If the history is empty, set the first record
398
417
  if (historyRef.current.length === 0) {
399
418
  firstUrlRef.current = newUrl;
400
419
  }
401
420
 
402
- // Avoid recording the same URL
403
- if (historyRef.current[historyRef.current.length - 1] !== newUrl) {
404
- historyRef.current.push(newUrl);
421
+ // Check whether it is back
422
+ var isBackOperation = historyRef.current.length > 1 && historyRef.current[historyRef.current.length - 2] === newUrl;
405
423
 
406
- // Clear the advance history, as new navigation invalidates the advance history
424
+ // Check whether it is forward
425
+ var isForwardOperation = forwardHistoryRef.current.length > 0 && forwardHistoryRef.current[forwardHistoryRef.current.length - 1] === newUrl;
426
+ if (isBackOperation) {
427
+ // If it is a rollback, remove the last URL and add it to forwardHistory
428
+ var removedUrl = historyRef.current.pop();
429
+ if (removedUrl) {
430
+ forwardHistoryRef.current.push(removedUrl);
431
+ }
432
+ } else if (isForwardOperation) {
433
+ // If it is a forward operation, take out the URL from forwardHistory and add it to history
434
+ var nextUrl = forwardHistoryRef.current.pop();
435
+ if (nextUrl) {
436
+ historyRef.current.push(nextUrl);
437
+ }
438
+ } else if (historyRef.current[historyRef.current.length - 1] !== newUrl) {
439
+ // If it's a new navigation, add to history and clear forwardHistory
440
+ historyRef.current.push(newUrl);
407
441
  forwardHistoryRef.current = [];
408
- setCurrentUrl(newUrl);
409
- onChange === null || onChange === void 0 ? void 0 : onChange({
410
- isReady: true,
411
- history: _toConsumableArray(historyRef.current),
412
- forwardHistory: _toConsumableArray(forwardHistoryRef.current),
413
- currentUrl: newUrl,
414
- firstUrl: firstUrlRef.current || newUrl,
415
- // Make sure there is always a value
416
- canGoBack: canGoBack(),
417
- canGoForward: canGoForward()
418
- });
419
442
  }
420
- }, [onChange]); // only "onChange"
443
+ setCurrentUrl(newUrl);
444
+ onChange && onChange({
445
+ isReady: true,
446
+ history: _toConsumableArray(historyRef.current),
447
+ forwardHistory: _toConsumableArray(forwardHistoryRef.current),
448
+ currentUrl: newUrl,
449
+ firstUrl: firstUrlRef.current || newUrl,
450
+ canGoBack: canGoBack(),
451
+ canGoForward: canGoForward()
452
+ });
453
+ }, [onChange, canGoBack, canGoForward]);
421
454
 
455
+ // Create a wrapper for history methods
456
+ var createHistoryWrapper = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function (originalMethod) {
457
+ return function () {
458
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
459
+ args[_key] = arguments[_key];
460
+ }
461
+ var result = originalMethod.apply(this, args);
462
+ handleUrlChange();
463
+ return result;
464
+ };
465
+ }, [handleUrlChange]);
466
+ var getFirstUrl = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
467
+ return firstUrlRef.current;
468
+ }, []);
469
+ var getCurrentUrl = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
470
+ return currentUrl;
471
+ }, [currentUrl]);
472
+ var getForwardHistory = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
473
+ return forwardHistoryRef.current;
474
+ }, []);
475
+ var getHistory = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
476
+ return historyRef.current;
477
+ }, []);
478
+ var getReady = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
479
+ return isReady;
480
+ }, [isReady]);
481
+ var addHistoryToFirst = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)( /*#__PURE__*/function () {
482
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
483
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
484
+ while (1) switch (_context.prev = _context.next) {
485
+ case 0:
486
+ if (!(typeof window === 'undefined')) {
487
+ _context.next = 2;
488
+ break;
489
+ }
490
+ return _context.abrupt("return", Promise.reject('Window is undefined'));
491
+ case 2:
492
+ if (url) {
493
+ _context.next = 4;
494
+ break;
495
+ }
496
+ return _context.abrupt("return", Promise.reject('URL does not exist'));
497
+ case 4:
498
+ return _context.abrupt("return", new Promise(function (resolve) {
499
+ if (historyRef.current.length === 0) {
500
+ firstUrlRef.current = url;
501
+ historyRef.current = [url];
502
+ setCurrentUrl(url);
503
+ } else {
504
+ // Insert at the front
505
+ historyRef.current = [url].concat(_toConsumableArray(historyRef.current));
506
+ firstUrlRef.current = url;
507
+ }
508
+ var result = {
509
+ isReady: true,
510
+ history: _toConsumableArray(historyRef.current),
511
+ forwardHistory: _toConsumableArray(forwardHistoryRef.current),
512
+ currentUrl: currentUrl || url,
513
+ firstUrl: firstUrlRef.current,
514
+ canGoBack: canGoBack(),
515
+ canGoForward: canGoForward()
516
+ };
517
+ onChange && onChange(result);
518
+ resolve(result);
519
+ }));
520
+ case 5:
521
+ case "end":
522
+ return _context.stop();
523
+ }
524
+ }, _callee);
525
+ }));
526
+ return function (_x2) {
527
+ return _ref2.apply(this, arguments);
528
+ };
529
+ }(), [onChange, currentUrl, canGoBack, canGoForward]);
530
+ var clearHistory = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
531
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
532
+ while (1) switch (_context2.prev = _context2.next) {
533
+ case 0:
534
+ if (!(typeof window === 'undefined')) {
535
+ _context2.next = 2;
536
+ break;
537
+ }
538
+ return _context2.abrupt("return", Promise.reject('Window is undefined'));
539
+ case 2:
540
+ return _context2.abrupt("return", new Promise(function (resolve) {
541
+ historyRef.current = [];
542
+ forwardHistoryRef.current = [];
543
+ firstUrlRef.current = '';
544
+ setCurrentUrl('');
545
+ var result = {
546
+ isReady: true,
547
+ history: [],
548
+ forwardHistory: [],
549
+ currentUrl: '',
550
+ firstUrl: '',
551
+ canGoBack: false,
552
+ canGoForward: false
553
+ };
554
+ onChange && onChange(result);
555
+
556
+ // After clearHistory(), immediately take the current url as the first history
557
+ // !!!Fixed: "There is still only 1 record of goBack(), and there is no cumulative forward record"
558
+ setTimeout(function () {
559
+ initialize(true);
560
+ resolve(result);
561
+ }, 0);
562
+ }));
563
+ case 3:
564
+ case "end":
565
+ return _context2.stop();
566
+ }
567
+ }, _callee2);
568
+ })), [onChange, initialize]);
422
569
  (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () {
423
570
  if (typeof window === 'undefined') return;
424
571
 
@@ -428,42 +575,69 @@ var useHistoryTracker = function useHistoryTracker(props) {
428
575
  // Listen for hashchange events
429
576
  window.addEventListener('hashchange', handleUrlChange);
430
577
 
431
- // Listen for DOM and property changes
432
- var observer = new MutationObserver(function (mutations) {
433
- mutations.forEach(function (mutation) {
434
- if (mutation.type === 'childList' || mutation.type === 'attributes') {
435
- handleUrlChange();
578
+ // !!!Fixed: "Reinitialize the history, but this will not cause the URL to change either"
579
+
580
+ // Store original methods (Just save the reference, don't modify the global)
581
+ var originalPushState = window.history.pushState.bind(window.history);
582
+ var originalReplaceState = window.history.replaceState.bind(window.history);
583
+ var originalGo = window.history.go.bind(window.history);
584
+
585
+ // Create wrapped versions of history methods
586
+ var wrappedPushState = createHistoryWrapper(originalPushState);
587
+ var wrappedReplaceState = createHistoryWrapper(originalReplaceState);
588
+ var wrappedGo = createHistoryWrapper(originalGo);
589
+
590
+ // Create a proxy for history object
591
+ var historyProxy = new Proxy(window.history, {
592
+ get: function get(target, prop) {
593
+ if (prop === 'pushState') {
594
+ return wrappedPushState;
436
595
  }
437
- });
438
- });
439
- observer.observe(document.body, {
440
- childList: true,
441
- // monitor the addition and deletion of child nodes
442
- subtree: true,
443
- // monitor all descendant nodes
444
- attributes: true,
445
- // monitor attribute changes
446
- attributeFilter: ['href'] // only monitor changes in the href attribute
596
+ if (prop === 'replaceState') {
597
+ return wrappedReplaceState;
598
+ }
599
+ if (prop === 'go') {
600
+ return wrappedGo;
601
+ }
602
+ return target[prop];
603
+ }
447
604
  });
448
605
 
606
+ // Replace window.history with our proxy
607
+ Object.defineProperty(window, 'history', {
608
+ value: historyProxy,
609
+ writable: true,
610
+ configurable: true
611
+ });
449
612
  return function () {
450
613
  window.removeEventListener('popstate', handleUrlChange);
451
614
  window.removeEventListener('hashchange', handleUrlChange);
452
- observer.disconnect();
615
+
616
+ // Restore original history methods
617
+ Object.defineProperty(window, 'history', {
618
+ value: _objectSpread(_objectSpread({}, window.history), {}, {
619
+ pushState: originalPushState,
620
+ replaceState: originalReplaceState,
621
+ go: originalGo
622
+ }),
623
+ writable: true,
624
+ configurable: true
625
+ });
453
626
  };
454
- }, [handleUrlChange]);
627
+ }, [handleUrlChange, createHistoryWrapper]);
455
628
  return {
456
- isReady: isReady,
457
- history: historyRef.current,
458
- forwardHistory: forwardHistoryRef.current,
459
- currentUrl: currentUrl,
460
- firstUrl: firstUrlRef.current,
629
+ getReady: getReady,
630
+ getHistory: getHistory,
631
+ getForwardHistory: getForwardHistory,
632
+ getCurrentUrl: getCurrentUrl,
633
+ getFirstUrl: getFirstUrl,
461
634
  clearHistory: clearHistory,
462
635
  goToHistory: goToHistory,
463
636
  goBack: goBack,
464
637
  goForward: goForward,
465
638
  canGoBack: canGoBack,
466
- canGoForward: canGoForward
639
+ canGoForward: canGoForward,
640
+ addHistoryToFirst: addHistoryToFirst
467
641
  };
468
642
  };
469
643
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (useHistoryTracker);
@@ -9,6 +9,8 @@
9
9
  --cus-sel-control-wrapper-bg: #fff;
10
10
  --cus-sel-control-wrapper-border-color: #dee2e6;
11
11
  --cus-sel-control-list-bg: #efefef;
12
+ --cus-sel-clear-fill: #a5a5a5;
13
+ --cus-sel-clear-hover-fill: #000;
12
14
  --cus-sel-arrow-fill: #a5a5a5;
13
15
  --cus-sel-searchbtn-fill: #a5a5a5;
14
16
  --cus-sel-searchbtn-hover-fill: #333;
@@ -17,7 +19,8 @@
17
19
  position: relative; /* Required */
18
20
  /*------ Placeholder for input ------*/
19
21
  /*------ Arrow ------*/
20
- /*------ Clean ------*/
22
+ /*------ Clear Icon ------*/
23
+ /*------ Clear Trigger ------*/
21
24
  /*------ Input ------*/
22
25
  /*------ Arrow ------*/
23
26
  /*------ Blinking cursor ------*/
@@ -33,7 +36,32 @@
33
36
  .custom-select__wrapper .arrow svg .arrow-fill-g {
34
37
  fill: var(--cus-sel-arrow-fill);
35
38
  }
36
- .custom-select__wrapper .clean svg .clean-fill-g {
39
+ .custom-select__wrapper .custom-select-clear-icon {
40
+ position: absolute;
41
+ top: 50%;
42
+ transform: rotate(0deg) translateY(-50%);
43
+ transform-origin: top;
44
+ right: 1.5rem;
45
+ z-index: 2;
46
+ pointer-events: all;
47
+ }
48
+ .custom-select__wrapper .custom-select-clear-icon button {
49
+ border: none;
50
+ box-shadow: none;
51
+ margin: 0;
52
+ padding: 0;
53
+ background: none;
54
+ }
55
+ .custom-select__wrapper .custom-select-clear-icon.pos-offset {
56
+ right: 2.25rem;
57
+ }
58
+ .custom-select__wrapper .custom-select-clear-icon svg path {
59
+ fill: var(--cus-sel-clear-fill);
60
+ }
61
+ .custom-select__wrapper .custom-select-clear-icon:hover svg path {
62
+ fill: var(--cus-sel-clear-hover-fill);
63
+ }
64
+ .custom-select__wrapper .clear svg .clear-fill-g {
37
65
  fill: var(--cus-sel-arrow-fill);
38
66
  }
39
67
  .custom-select__wrapper [data-select]:focus {
@@ -392,10 +420,10 @@
392
420
  font-size: 0.75rem;
393
421
  padding: 0.1rem 0.5rem;
394
422
  }
395
- .custom-select__options-wrapper .custom-select-multi__control-option-item--clean.hide {
423
+ .custom-select__options-wrapper .custom-select-multi__control-option-item--clear.hide {
396
424
  display: none !important;
397
425
  }
398
- .custom-select__options-wrapper .custom-select-multi__control-option-item--clean .btn {
426
+ .custom-select__options-wrapper .custom-select-multi__control-option-item--clear .btn {
399
427
  font-size: 0.75rem;
400
428
  padding: 0.1rem 0.5rem;
401
429
  }