droplinked-chatbot-next 1.0.3 → 1.0.5

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.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var Chakra = require('@chakra-ui/react');
5
- var React3 = require('react');
5
+ var React = require('react');
6
6
 
7
7
  function _interopNamespaceDefault(e) {
8
8
  var n = Object.create(null);
@@ -22,7 +22,7 @@ function _interopNamespaceDefault(e) {
22
22
  }
23
23
 
24
24
  var Chakra__namespace = /*#__PURE__*/_interopNamespaceDefault(Chakra);
25
- var React3__namespace = /*#__PURE__*/_interopNamespaceDefault(React3);
25
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
26
26
 
27
27
  function _arrayLikeToArray(r, a) {
28
28
  (null == a || a > r.length) && (a = r.length);
@@ -4367,11 +4367,11 @@ var useChatbot = function useChatbot(_ref) {
4367
4367
  apiKey = _ref.apiKey,
4368
4368
  initialUser = _ref.initialUser,
4369
4369
  client = _ref.client;
4370
- var _useState = React3.useState([]),
4370
+ var _useState = React.useState([]),
4371
4371
  _useState2 = _slicedToArray(_useState, 2),
4372
4372
  messages = _useState2[0],
4373
4373
  setMessages = _useState2[1];
4374
- var _useState3 = React3.useState({
4374
+ var _useState3 = React.useState({
4375
4375
  email: (_initialUser$email = initialUser === null || initialUser === void 0 ? void 0 : initialUser.email) !== null && _initialUser$email !== void 0 ? _initialUser$email : "",
4376
4376
  isLoggedIn: (initialUser === null || initialUser === void 0 ? void 0 : initialUser.isLoggedIn) !== undefined ? initialUser.isLoggedIn : Boolean(initialUser === null || initialUser === void 0 ? void 0 : initialUser.email),
4377
4377
  name: initialUser === null || initialUser === void 0 ? void 0 : initialUser.name,
@@ -4380,55 +4380,55 @@ var useChatbot = function useChatbot(_ref) {
4380
4380
  _useState4 = _slicedToArray(_useState3, 2),
4381
4381
  user = _useState4[0],
4382
4382
  setUser = _useState4[1];
4383
- var _useState5 = React3.useState("hello"),
4383
+ var _useState5 = React.useState("hello"),
4384
4384
  _useState6 = _slicedToArray(_useState5, 2),
4385
4385
  currentView = _useState6[0],
4386
4386
  setCurrentView = _useState6[1];
4387
- var _useState7 = React3.useState(""),
4387
+ var _useState7 = React.useState(""),
4388
4388
  _useState8 = _slicedToArray(_useState7, 2),
4389
4389
  threadId = _useState8[0],
4390
4390
  setThreadId = _useState8[1];
4391
- var _useState9 = React3.useState(false),
4391
+ var _useState9 = React.useState(false),
4392
4392
  _useState0 = _slicedToArray(_useState9, 2),
4393
4393
  isLoading = _useState0[0],
4394
4394
  setIsLoading = _useState0[1];
4395
- var _useState1 = React3.useState(false),
4395
+ var _useState1 = React.useState(false),
4396
4396
  _useState10 = _slicedToArray(_useState1, 2),
4397
4397
  isTyping = _useState10[0],
4398
4398
  setIsTyping = _useState10[1];
4399
- var _useState11 = React3.useState(false),
4399
+ var _useState11 = React.useState(false),
4400
4400
  _useState12 = _slicedToArray(_useState11, 2),
4401
4401
  isEmailSubmitting = _useState12[0],
4402
4402
  setIsEmailSubmitting = _useState12[1];
4403
- var _useState13 = React3.useState(false),
4403
+ var _useState13 = React.useState(false),
4404
4404
  _useState14 = _slicedToArray(_useState13, 2),
4405
4405
  isStartingChat = _useState14[0],
4406
4406
  setIsStartingChat = _useState14[1];
4407
- var _useState15 = React3.useState(new Set()),
4407
+ var _useState15 = React.useState(new Set()),
4408
4408
  _useState16 = _slicedToArray(_useState15, 2),
4409
4409
  historyMessageIds = _useState16[0],
4410
4410
  setHistoryMessageIds = _useState16[1];
4411
- var _useState17 = React3.useState(null),
4411
+ var _useState17 = React.useState(null),
4412
4412
  _useState18 = _slicedToArray(_useState17, 2),
4413
4413
  currentlyProcessingMessageId = _useState18[0],
4414
4414
  setCurrentlyProcessingMessageId = _useState18[1];
4415
- var _useState19 = React3.useState(null),
4415
+ var _useState19 = React.useState(null),
4416
4416
  _useState20 = _slicedToArray(_useState19, 2),
4417
4417
  lastFailedMessage = _useState20[0],
4418
4418
  setLastFailedMessage = _useState20[1];
4419
- var api = React3.useMemo(function () {
4419
+ var api = React.useMemo(function () {
4420
4420
  return client !== null && client !== void 0 ? client : new ChatbotAPI(apiBaseUrl, apiKey);
4421
4421
  }, [client, apiBaseUrl, apiKey]);
4422
- var startControllerRef = React3.useRef(null);
4423
- var sendControllerRef = React3.useRef(null);
4424
- React3.useEffect(function () {
4422
+ var startControllerRef = React.useRef(null);
4423
+ var sendControllerRef = React.useRef(null);
4424
+ React.useEffect(function () {
4425
4425
  return function () {
4426
4426
  var _startControllerRef$c, _sendControllerRef$cu;
4427
4427
  (_startControllerRef$c = startControllerRef.current) === null || _startControllerRef$c === void 0 || _startControllerRef$c.abort();
4428
4428
  (_sendControllerRef$cu = sendControllerRef.current) === null || _sendControllerRef$cu === void 0 || _sendControllerRef$cu.abort();
4429
4429
  };
4430
4430
  }, []);
4431
- var loadConversationHistory = React3.useCallback(/*#__PURE__*/function () {
4431
+ var loadConversationHistory = React.useCallback(/*#__PURE__*/function () {
4432
4432
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(thread) {
4433
4433
  var _startControllerRef$c2;
4434
4434
  var history, historyIds;
@@ -4455,7 +4455,7 @@ var useChatbot = function useChatbot(_ref) {
4455
4455
  return _ref2.apply(this, arguments);
4456
4456
  };
4457
4457
  }(), [api]);
4458
- var handleStartChat = React3.useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
4458
+ var handleStartChat = React.useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
4459
4459
  var _startControllerRef$c3;
4460
4460
  var startChatRequest, response, _t;
4461
4461
  return _regenerator().w(function (_context2) {
@@ -4502,10 +4502,10 @@ var useChatbot = function useChatbot(_ref) {
4502
4502
  }
4503
4503
  }, _callee2, null, [[1, 4, 5, 6]]);
4504
4504
  })), [api, threadId, user.email, user.isLoggedIn, loadConversationHistory]);
4505
- var handleBackToHello = React3.useCallback(function () {
4505
+ var handleBackToHello = React.useCallback(function () {
4506
4506
  setCurrentView("hello");
4507
4507
  }, []);
4508
- var handleEmailSubmit = React3.useCallback(/*#__PURE__*/function () {
4508
+ var handleEmailSubmit = React.useCallback(/*#__PURE__*/function () {
4509
4509
  var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(email, showToast) {
4510
4510
  var _startControllerRef$c4;
4511
4511
  var startChatRequest, response, errorMessage, _errorMessage, _t2;
@@ -4567,7 +4567,7 @@ var useChatbot = function useChatbot(_ref) {
4567
4567
  return _ref4.apply(this, arguments);
4568
4568
  };
4569
4569
  }(), [api, loadConversationHistory]);
4570
- var handleSendMessage = React3.useCallback(/*#__PURE__*/function () {
4570
+ var handleSendMessage = React.useCallback(/*#__PURE__*/function () {
4571
4571
  var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(text) {
4572
4572
  var newMessage, _sendControllerRef$cu2, request, response, botResponse, errorMessage, _t3;
4573
4573
  return _regenerator().w(function (_context4) {
@@ -4644,7 +4644,7 @@ var useChatbot = function useChatbot(_ref) {
4644
4644
  return _ref5.apply(this, arguments);
4645
4645
  };
4646
4646
  }(), [api, threadId]);
4647
- var resetChat = React3.useCallback(function () {
4647
+ var resetChat = React.useCallback(function () {
4648
4648
  setMessages([]);
4649
4649
  setUser({
4650
4650
  email: "",
@@ -4658,7 +4658,7 @@ var useChatbot = function useChatbot(_ref) {
4658
4658
  setCurrentlyProcessingMessageId(null);
4659
4659
  setLastFailedMessage(null);
4660
4660
  }, []);
4661
- var handleRetryLastMessage = React3.useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
4661
+ var handleRetryLastMessage = React.useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
4662
4662
  var _sendControllerRef$cu3, request, response, botResponse, errorMessage, _t4;
4663
4663
  return _regenerator().w(function (_context5) {
4664
4664
  while (1) switch (_context5.p = _context5.n) {
@@ -4807,7 +4807,7 @@ function EmailCapture(_ref) {
4807
4807
  var onSubmit = _ref.onSubmit,
4808
4808
  _ref$isSubmitting = _ref.isSubmitting,
4809
4809
  isSubmitting = _ref$isSubmitting === void 0 ? false : _ref$isSubmitting;
4810
- var _useState = React3.useState(""),
4810
+ var _useState = React.useState(""),
4811
4811
  _useState2 = _slicedToArray(_useState, 2),
4812
4812
  email = _useState2[0],
4813
4813
  setEmail = _useState2[1];
@@ -4958,7 +4958,7 @@ function MessageInput(_ref) {
4958
4958
  isEmailSubmitting = _ref$isEmailSubmittin === void 0 ? false : _ref$isEmailSubmittin,
4959
4959
  _ref$messages = _ref.messages,
4960
4960
  messages = _ref$messages === void 0 ? [] : _ref$messages;
4961
- var _useState = React3.useState(""),
4961
+ var _useState = React.useState(""),
4962
4962
  _useState2 = _slicedToArray(_useState, 2),
4963
4963
  input = _useState2[0],
4964
4964
  setInput = _useState2[1];
@@ -5074,9 +5074,9 @@ if (typeof document !== "undefined" && !document.getElementById("typing-indicato
5074
5074
  styleElement.textContent = typingIndicatorStyles;
5075
5075
  document.head.appendChild(styleElement);
5076
5076
  }
5077
- var TypingIndicator = /*#__PURE__*/React3.memo(function TypingIndicator(_ref) {
5077
+ var TypingIndicator = /*#__PURE__*/React.memo(function TypingIndicator(_ref) {
5078
5078
  var isVisible = _ref.isVisible;
5079
- var getDotStyle = React3.useMemo(function () {
5079
+ var getDotStyle = React.useMemo(function () {
5080
5080
  return function (index, delay) {
5081
5081
  var animationDelay = "".concat(index * 0.2 + delay * 0.5, "s");
5082
5082
  return {
@@ -5090,11 +5090,11 @@ var TypingIndicator = /*#__PURE__*/React3.memo(function TypingIndicator(_ref) {
5090
5090
  animation: isVisible ? 'scaleIn 0.5s ease-out forwards' : 'scaleOut 0.5s ease-in forwards',
5091
5091
  transformOrigin: 'bottom left'
5092
5092
  };
5093
- var _React$useState = React3.useState(isVisible),
5093
+ var _React$useState = React.useState(isVisible),
5094
5094
  _React$useState2 = _slicedToArray(_React$useState, 2),
5095
5095
  shouldRender = _React$useState2[0],
5096
5096
  setShouldRender = _React$useState2[1];
5097
- React3.useEffect(function () {
5097
+ React.useEffect(function () {
5098
5098
  var timer = null;
5099
5099
  if (isVisible) {
5100
5100
  setShouldRender(true);
@@ -5110,8 +5110,8 @@ var TypingIndicator = /*#__PURE__*/React3.memo(function TypingIndicator(_ref) {
5110
5110
  };
5111
5111
  }, [isVisible]);
5112
5112
  if (!shouldRender) return null;
5113
- var TypingDots = React3.useMemo(function () {
5114
- return /*#__PURE__*/React3.memo(function (_ref2) {
5113
+ var TypingDots = React.useMemo(function () {
5114
+ return /*#__PURE__*/React.memo(function (_ref2) {
5115
5115
  var _ref2$delay = _ref2.delay,
5116
5116
  delay = _ref2$delay === void 0 ? 0 : _ref2$delay;
5117
5117
  return jsxRuntime.jsx(Chakra.HStack, {
@@ -41520,29 +41520,29 @@ function GradualMessageDisplay(_ref) {
41520
41520
  onComplete = _ref.onComplete,
41521
41521
  _ref$isHistoryMessage = _ref.isHistoryMessage,
41522
41522
  isHistoryMessage = _ref$isHistoryMessage === void 0 ? false : _ref$isHistoryMessage;
41523
- var _useState = React3.useState("typing"),
41523
+ var _useState = React.useState("typing"),
41524
41524
  _useState2 = _slicedToArray(_useState, 2),
41525
41525
  phase = _useState2[0],
41526
41526
  setPhase = _useState2[1];
41527
- var _useState3 = React3.useState([]),
41527
+ var _useState3 = React.useState([]),
41528
41528
  _useState4 = _slicedToArray(_useState3, 2),
41529
41529
  displayedLines = _useState4[0],
41530
41530
  setDisplayedLines = _useState4[1];
41531
- var _useState5 = React3.useState(0),
41531
+ var _useState5 = React.useState(0),
41532
41532
  _useState6 = _slicedToArray(_useState5, 2),
41533
41533
  currentLineIndex = _useState6[0],
41534
41534
  setCurrentLineIndex = _useState6[1];
41535
- var _useState7 = React3.useState(0),
41535
+ var _useState7 = React.useState(0),
41536
41536
  _useState8 = _slicedToArray(_useState7, 2),
41537
41537
  lineProgress = _useState8[0],
41538
41538
  setLineProgress = _useState8[1];
41539
- var intervalRef = React3.useRef(null);
41540
- var onCompleteRef = React3.useRef(onComplete);
41541
- var messageLines = React3.useRef([]);
41542
- React3.useEffect(function () {
41539
+ var intervalRef = React.useRef(null);
41540
+ var onCompleteRef = React.useRef(onComplete);
41541
+ var messageLines = React.useRef([]);
41542
+ React.useEffect(function () {
41543
41543
  onCompleteRef.current = onComplete;
41544
41544
  }, [onComplete]);
41545
- React3.useEffect(function () {
41545
+ React.useEffect(function () {
41546
41546
  if (!isBot || isHistoryMessage) {
41547
41547
  var _onCompleteRef$curren;
41548
41548
  setDisplayedLines([message]);
@@ -41782,7 +41782,7 @@ function ErrorMessage(_ref) {
41782
41782
  var onRetry = _ref.onRetry,
41783
41783
  _ref$showRetry = _ref.showRetry,
41784
41784
  showRetry = _ref$showRetry === void 0 ? true : _ref$showRetry;
41785
- var _useState = React3.useState(false),
41785
+ var _useState = React.useState(false),
41786
41786
  _useState2 = _slicedToArray(_useState, 2),
41787
41787
  isRetrying = _useState2[0],
41788
41788
  setIsRetrying = _useState2[1];
@@ -58963,7 +58963,7 @@ function requireIndex_umd () {
58963
58963
  hasRequiredIndex_umd = 1;
58964
58964
  (function (module, exports) {
58965
58965
  (function (global, factory) {
58966
- factory(exports, /*@__PURE__*/ requireLottie(), React3) ;
58966
+ factory(exports, /*@__PURE__*/ requireLottie(), React) ;
58967
58967
  })(index_umd, (function (exports, lottie, React) {
58968
58968
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
58969
58969
 
@@ -65633,12 +65633,12 @@ function MessageList(_ref) {
65633
65633
  currentlyProcessingMessageId = _ref.currentlyProcessingMessageId,
65634
65634
  clearProcessingMessageId = _ref.clearProcessingMessageId,
65635
65635
  onRetryMessage = _ref.onRetryMessage;
65636
- var scrollContainerRef = React3.useRef(null);
65637
- var _useState = React3.useState(new Set()),
65636
+ var scrollContainerRef = React.useRef(null);
65637
+ var _useState = React.useState(new Set()),
65638
65638
  _useState2 = _slicedToArray(_useState, 2),
65639
65639
  completedMessages = _useState2[0],
65640
65640
  setCompletedMessages = _useState2[1];
65641
- var _useState3 = React3.useState(null),
65641
+ var _useState3 = React.useState(null),
65642
65642
  _useState4 = _slicedToArray(_useState3, 2),
65643
65643
  currentlyDisplayingMessage = _useState4[0],
65644
65644
  setCurrentlyDisplayingMessage = _useState4[1];
@@ -65650,7 +65650,7 @@ function MessageList(_ref) {
65650
65650
  });
65651
65651
  setCurrentlyDisplayingMessage(null);
65652
65652
  };
65653
- React3.useEffect(function () {
65653
+ React.useEffect(function () {
65654
65654
  var latestBotMessage = messages.filter(function (msg) {
65655
65655
  return msg.sender === "bot";
65656
65656
  }).slice(-1)[0];
@@ -65658,7 +65658,7 @@ function MessageList(_ref) {
65658
65658
  setCurrentlyDisplayingMessage(latestBotMessage.id);
65659
65659
  }
65660
65660
  }, [messages, completedMessages]);
65661
- React3.useEffect(function () {
65661
+ React.useEffect(function () {
65662
65662
  if (scrollContainerRef.current) {
65663
65663
  scrollContainerRef.current.scrollTo({
65664
65664
  top: scrollContainerRef.current.scrollHeight,
@@ -65813,1735 +65813,6 @@ function ChatPage(_ref) {
65813
65813
  });
65814
65814
  }
65815
65815
 
65816
- /**
65817
- * react-router v7.8.2
65818
- *
65819
- * Copyright (c) Remix Software Inc.
65820
- *
65821
- * This source code is licensed under the MIT license found in the
65822
- * LICENSE.md file in the root directory of this source tree.
65823
- *
65824
- * @license MIT
65825
- */
65826
- function invariant(value, message) {
65827
- if (value === false || value === null || typeof value === "undefined") {
65828
- throw new Error(message);
65829
- }
65830
- }
65831
- function warning(cond, message) {
65832
- if (!cond) {
65833
- if (typeof console !== "undefined") console.warn(message);
65834
- try {
65835
- throw new Error(message);
65836
- } catch (e) {
65837
- }
65838
- }
65839
- }
65840
- function createPath({
65841
- pathname = "/",
65842
- search = "",
65843
- hash = ""
65844
- }) {
65845
- if (search && search !== "?")
65846
- pathname += search.charAt(0) === "?" ? search : "?" + search;
65847
- if (hash && hash !== "#")
65848
- pathname += hash.charAt(0) === "#" ? hash : "#" + hash;
65849
- return pathname;
65850
- }
65851
- function parsePath(path) {
65852
- let parsedPath = {};
65853
- if (path) {
65854
- let hashIndex = path.indexOf("#");
65855
- if (hashIndex >= 0) {
65856
- parsedPath.hash = path.substring(hashIndex);
65857
- path = path.substring(0, hashIndex);
65858
- }
65859
- let searchIndex = path.indexOf("?");
65860
- if (searchIndex >= 0) {
65861
- parsedPath.search = path.substring(searchIndex);
65862
- path = path.substring(0, searchIndex);
65863
- }
65864
- if (path) {
65865
- parsedPath.pathname = path;
65866
- }
65867
- }
65868
- return parsedPath;
65869
- }
65870
- function matchRoutes(routes, locationArg, basename = "/") {
65871
- return matchRoutesImpl(routes, locationArg, basename, false);
65872
- }
65873
- function matchRoutesImpl(routes, locationArg, basename, allowPartial) {
65874
- let location = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
65875
- let pathname = stripBasename(location.pathname || "/", basename);
65876
- if (pathname == null) {
65877
- return null;
65878
- }
65879
- let branches = flattenRoutes(routes);
65880
- rankRouteBranches(branches);
65881
- let matches = null;
65882
- for (let i = 0; matches == null && i < branches.length; ++i) {
65883
- let decoded = decodePath(pathname);
65884
- matches = matchRouteBranch(
65885
- branches[i],
65886
- decoded,
65887
- allowPartial
65888
- );
65889
- }
65890
- return matches;
65891
- }
65892
- function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "", _hasParentOptionalSegments = false) {
65893
- let flattenRoute = (route, index, hasParentOptionalSegments = _hasParentOptionalSegments, relativePath) => {
65894
- let meta = {
65895
- relativePath: relativePath === void 0 ? route.path || "" : relativePath,
65896
- caseSensitive: route.caseSensitive === true,
65897
- childrenIndex: index,
65898
- route
65899
- };
65900
- if (meta.relativePath.startsWith("/")) {
65901
- if (!meta.relativePath.startsWith(parentPath) && hasParentOptionalSegments) {
65902
- return;
65903
- }
65904
- invariant(
65905
- meta.relativePath.startsWith(parentPath),
65906
- `Absolute route path "${meta.relativePath}" nested under path "${parentPath}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`
65907
- );
65908
- meta.relativePath = meta.relativePath.slice(parentPath.length);
65909
- }
65910
- let path = joinPaths([parentPath, meta.relativePath]);
65911
- let routesMeta = parentsMeta.concat(meta);
65912
- if (route.children && route.children.length > 0) {
65913
- invariant(
65914
- // Our types know better, but runtime JS may not!
65915
- // @ts-expect-error
65916
- route.index !== true,
65917
- `Index routes must not have child routes. Please remove all child routes from route path "${path}".`
65918
- );
65919
- flattenRoutes(
65920
- route.children,
65921
- branches,
65922
- routesMeta,
65923
- path,
65924
- hasParentOptionalSegments
65925
- );
65926
- }
65927
- if (route.path == null && !route.index) {
65928
- return;
65929
- }
65930
- branches.push({
65931
- path,
65932
- score: computeScore(path, route.index),
65933
- routesMeta
65934
- });
65935
- };
65936
- routes.forEach((route, index) => {
65937
- if (route.path === "" || !route.path?.includes("?")) {
65938
- flattenRoute(route, index);
65939
- } else {
65940
- for (let exploded of explodeOptionalSegments(route.path)) {
65941
- flattenRoute(route, index, true, exploded);
65942
- }
65943
- }
65944
- });
65945
- return branches;
65946
- }
65947
- function explodeOptionalSegments(path) {
65948
- let segments = path.split("/");
65949
- if (segments.length === 0) return [];
65950
- let [first, ...rest] = segments;
65951
- let isOptional = first.endsWith("?");
65952
- let required = first.replace(/\?$/, "");
65953
- if (rest.length === 0) {
65954
- return isOptional ? [required, ""] : [required];
65955
- }
65956
- let restExploded = explodeOptionalSegments(rest.join("/"));
65957
- let result = [];
65958
- result.push(
65959
- ...restExploded.map(
65960
- (subpath) => subpath === "" ? required : [required, subpath].join("/")
65961
- )
65962
- );
65963
- if (isOptional) {
65964
- result.push(...restExploded);
65965
- }
65966
- return result.map(
65967
- (exploded) => path.startsWith("/") && exploded === "" ? "/" : exploded
65968
- );
65969
- }
65970
- function rankRouteBranches(branches) {
65971
- branches.sort(
65972
- (a, b) => a.score !== b.score ? b.score - a.score : compareIndexes(
65973
- a.routesMeta.map((meta) => meta.childrenIndex),
65974
- b.routesMeta.map((meta) => meta.childrenIndex)
65975
- )
65976
- );
65977
- }
65978
- var paramRe = /^:[\w-]+$/;
65979
- var dynamicSegmentValue = 3;
65980
- var indexRouteValue = 2;
65981
- var emptySegmentValue = 1;
65982
- var staticSegmentValue = 10;
65983
- var splatPenalty = -2;
65984
- var isSplat = (s) => s === "*";
65985
- function computeScore(path, index) {
65986
- let segments = path.split("/");
65987
- let initialScore = segments.length;
65988
- if (segments.some(isSplat)) {
65989
- initialScore += splatPenalty;
65990
- }
65991
- if (index) {
65992
- initialScore += indexRouteValue;
65993
- }
65994
- return segments.filter((s) => !isSplat(s)).reduce(
65995
- (score, segment) => score + (paramRe.test(segment) ? dynamicSegmentValue : segment === "" ? emptySegmentValue : staticSegmentValue),
65996
- initialScore
65997
- );
65998
- }
65999
- function compareIndexes(a, b) {
66000
- let siblings = a.length === b.length && a.slice(0, -1).every((n, i) => n === b[i]);
66001
- return siblings ? (
66002
- // If two routes are siblings, we should try to match the earlier sibling
66003
- // first. This allows people to have fine-grained control over the matching
66004
- // behavior by simply putting routes with identical paths in the order they
66005
- // want them tried.
66006
- a[a.length - 1] - b[b.length - 1]
66007
- ) : (
66008
- // Otherwise, it doesn't really make sense to rank non-siblings by index,
66009
- // so they sort equally.
66010
- 0
66011
- );
66012
- }
66013
- function matchRouteBranch(branch, pathname, allowPartial = false) {
66014
- let { routesMeta } = branch;
66015
- let matchedParams = {};
66016
- let matchedPathname = "/";
66017
- let matches = [];
66018
- for (let i = 0; i < routesMeta.length; ++i) {
66019
- let meta = routesMeta[i];
66020
- let end = i === routesMeta.length - 1;
66021
- let remainingPathname = matchedPathname === "/" ? pathname : pathname.slice(matchedPathname.length) || "/";
66022
- let match = matchPath(
66023
- { path: meta.relativePath, caseSensitive: meta.caseSensitive, end },
66024
- remainingPathname
66025
- );
66026
- let route = meta.route;
66027
- if (!match && end && allowPartial && !routesMeta[routesMeta.length - 1].route.index) {
66028
- match = matchPath(
66029
- {
66030
- path: meta.relativePath,
66031
- caseSensitive: meta.caseSensitive,
66032
- end: false
66033
- },
66034
- remainingPathname
66035
- );
66036
- }
66037
- if (!match) {
66038
- return null;
66039
- }
66040
- Object.assign(matchedParams, match.params);
66041
- matches.push({
66042
- // TODO: Can this as be avoided?
66043
- params: matchedParams,
66044
- pathname: joinPaths([matchedPathname, match.pathname]),
66045
- pathnameBase: normalizePathname(
66046
- joinPaths([matchedPathname, match.pathnameBase])
66047
- ),
66048
- route
66049
- });
66050
- if (match.pathnameBase !== "/") {
66051
- matchedPathname = joinPaths([matchedPathname, match.pathnameBase]);
66052
- }
66053
- }
66054
- return matches;
66055
- }
66056
- function matchPath(pattern, pathname) {
66057
- if (typeof pattern === "string") {
66058
- pattern = { path: pattern, caseSensitive: false, end: true };
66059
- }
66060
- let [matcher, compiledParams] = compilePath(
66061
- pattern.path,
66062
- pattern.caseSensitive,
66063
- pattern.end
66064
- );
66065
- let match = pathname.match(matcher);
66066
- if (!match) return null;
66067
- let matchedPathname = match[0];
66068
- let pathnameBase = matchedPathname.replace(/(.)\/+$/, "$1");
66069
- let captureGroups = match.slice(1);
66070
- let params = compiledParams.reduce(
66071
- (memo2, { paramName, isOptional }, index) => {
66072
- if (paramName === "*") {
66073
- let splatValue = captureGroups[index] || "";
66074
- pathnameBase = matchedPathname.slice(0, matchedPathname.length - splatValue.length).replace(/(.)\/+$/, "$1");
66075
- }
66076
- const value = captureGroups[index];
66077
- if (isOptional && !value) {
66078
- memo2[paramName] = void 0;
66079
- } else {
66080
- memo2[paramName] = (value || "").replace(/%2F/g, "/");
66081
- }
66082
- return memo2;
66083
- },
66084
- {}
66085
- );
66086
- return {
66087
- params,
66088
- pathname: matchedPathname,
66089
- pathnameBase,
66090
- pattern
66091
- };
66092
- }
66093
- function compilePath(path, caseSensitive = false, end = true) {
66094
- warning(
66095
- path === "*" || !path.endsWith("*") || path.endsWith("/*"),
66096
- `Route path "${path}" will be treated as if it were "${path.replace(/\*$/, "/*")}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${path.replace(/\*$/, "/*")}".`
66097
- );
66098
- let params = [];
66099
- let regexpSource = "^" + path.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace(
66100
- /\/:([\w-]+)(\?)?/g,
66101
- (_, paramName, isOptional) => {
66102
- params.push({ paramName, isOptional: isOptional != null });
66103
- return isOptional ? "/?([^\\/]+)?" : "/([^\\/]+)";
66104
- }
66105
- ).replace(/\/([\w-]+)\?(\/|$)/g, "(/$1)?$2");
66106
- if (path.endsWith("*")) {
66107
- params.push({ paramName: "*" });
66108
- regexpSource += path === "*" || path === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$";
66109
- } else if (end) {
66110
- regexpSource += "\\/*$";
66111
- } else if (path !== "" && path !== "/") {
66112
- regexpSource += "(?:(?=\\/|$))";
66113
- } else ;
66114
- let matcher = new RegExp(regexpSource, caseSensitive ? void 0 : "i");
66115
- return [matcher, params];
66116
- }
66117
- function decodePath(value) {
66118
- try {
66119
- return value.split("/").map((v) => decodeURIComponent(v).replace(/\//g, "%2F")).join("/");
66120
- } catch (error) {
66121
- warning(
66122
- false,
66123
- `The URL path "${value}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${error}).`
66124
- );
66125
- return value;
66126
- }
66127
- }
66128
- function stripBasename(pathname, basename) {
66129
- if (basename === "/") return pathname;
66130
- if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) {
66131
- return null;
66132
- }
66133
- let startIndex = basename.endsWith("/") ? basename.length - 1 : basename.length;
66134
- let nextChar = pathname.charAt(startIndex);
66135
- if (nextChar && nextChar !== "/") {
66136
- return null;
66137
- }
66138
- return pathname.slice(startIndex) || "/";
66139
- }
66140
- function resolvePath(to, fromPathname = "/") {
66141
- let {
66142
- pathname: toPathname,
66143
- search = "",
66144
- hash = ""
66145
- } = typeof to === "string" ? parsePath(to) : to;
66146
- let pathname = toPathname ? toPathname.startsWith("/") ? toPathname : resolvePathname(toPathname, fromPathname) : fromPathname;
66147
- return {
66148
- pathname,
66149
- search: normalizeSearch(search),
66150
- hash: normalizeHash(hash)
66151
- };
66152
- }
66153
- function resolvePathname(relativePath, fromPathname) {
66154
- let segments = fromPathname.replace(/\/+$/, "").split("/");
66155
- let relativeSegments = relativePath.split("/");
66156
- relativeSegments.forEach((segment) => {
66157
- if (segment === "..") {
66158
- if (segments.length > 1) segments.pop();
66159
- } else if (segment !== ".") {
66160
- segments.push(segment);
66161
- }
66162
- });
66163
- return segments.length > 1 ? segments.join("/") : "/";
66164
- }
66165
- function getInvalidPathError(char, field, dest, path) {
66166
- return `Cannot include a '${char}' character in a manually specified \`to.${field}\` field [${JSON.stringify(
66167
- path
66168
- )}]. Please separate it out to the \`to.${dest}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`;
66169
- }
66170
- function getPathContributingMatches(matches) {
66171
- return matches.filter(
66172
- (match, index) => index === 0 || match.route.path && match.route.path.length > 0
66173
- );
66174
- }
66175
- function getResolveToMatches(matches) {
66176
- let pathMatches = getPathContributingMatches(matches);
66177
- return pathMatches.map(
66178
- (match, idx) => idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase
66179
- );
66180
- }
66181
- function resolveTo(toArg, routePathnames, locationPathname, isPathRelative = false) {
66182
- let to;
66183
- if (typeof toArg === "string") {
66184
- to = parsePath(toArg);
66185
- } else {
66186
- to = { ...toArg };
66187
- invariant(
66188
- !to.pathname || !to.pathname.includes("?"),
66189
- getInvalidPathError("?", "pathname", "search", to)
66190
- );
66191
- invariant(
66192
- !to.pathname || !to.pathname.includes("#"),
66193
- getInvalidPathError("#", "pathname", "hash", to)
66194
- );
66195
- invariant(
66196
- !to.search || !to.search.includes("#"),
66197
- getInvalidPathError("#", "search", "hash", to)
66198
- );
66199
- }
66200
- let isEmptyPath = toArg === "" || to.pathname === "";
66201
- let toPathname = isEmptyPath ? "/" : to.pathname;
66202
- let from;
66203
- if (toPathname == null) {
66204
- from = locationPathname;
66205
- } else {
66206
- let routePathnameIndex = routePathnames.length - 1;
66207
- if (!isPathRelative && toPathname.startsWith("..")) {
66208
- let toSegments = toPathname.split("/");
66209
- while (toSegments[0] === "..") {
66210
- toSegments.shift();
66211
- routePathnameIndex -= 1;
66212
- }
66213
- to.pathname = toSegments.join("/");
66214
- }
66215
- from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/";
66216
- }
66217
- let path = resolvePath(to, from);
66218
- let hasExplicitTrailingSlash = toPathname && toPathname !== "/" && toPathname.endsWith("/");
66219
- let hasCurrentTrailingSlash = (isEmptyPath || toPathname === ".") && locationPathname.endsWith("/");
66220
- if (!path.pathname.endsWith("/") && (hasExplicitTrailingSlash || hasCurrentTrailingSlash)) {
66221
- path.pathname += "/";
66222
- }
66223
- return path;
66224
- }
66225
- var joinPaths = (paths) => paths.join("/").replace(/\/\/+/g, "/");
66226
- var normalizePathname = (pathname) => pathname.replace(/\/+$/, "").replace(/^\/*/, "/");
66227
- var normalizeSearch = (search) => !search || search === "?" ? "" : search.startsWith("?") ? search : "?" + search;
66228
- var normalizeHash = (hash) => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash;
66229
- function isRouteErrorResponse(error) {
66230
- return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
66231
- }
66232
-
66233
- // lib/router/router.ts
66234
- var validMutationMethodsArr = [
66235
- "POST",
66236
- "PUT",
66237
- "PATCH",
66238
- "DELETE"
66239
- ];
66240
- new Set(
66241
- validMutationMethodsArr
66242
- );
66243
- var validRequestMethodsArr = [
66244
- "GET",
66245
- ...validMutationMethodsArr
66246
- ];
66247
- new Set(validRequestMethodsArr);
66248
- var DataRouterContext = React3__namespace.createContext(null);
66249
- DataRouterContext.displayName = "DataRouter";
66250
- var DataRouterStateContext = React3__namespace.createContext(null);
66251
- DataRouterStateContext.displayName = "DataRouterState";
66252
- React3__namespace.createContext(false);
66253
- var ViewTransitionContext = React3__namespace.createContext({
66254
- isTransitioning: false
66255
- });
66256
- ViewTransitionContext.displayName = "ViewTransition";
66257
- var FetchersContext = React3__namespace.createContext(
66258
- /* @__PURE__ */ new Map()
66259
- );
66260
- FetchersContext.displayName = "Fetchers";
66261
- var AwaitContext = React3__namespace.createContext(null);
66262
- AwaitContext.displayName = "Await";
66263
- var NavigationContext = React3__namespace.createContext(
66264
- null
66265
- );
66266
- NavigationContext.displayName = "Navigation";
66267
- var LocationContext = React3__namespace.createContext(
66268
- null
66269
- );
66270
- LocationContext.displayName = "Location";
66271
- var RouteContext = React3__namespace.createContext({
66272
- outlet: null,
66273
- matches: [],
66274
- isDataRoute: false
66275
- });
66276
- RouteContext.displayName = "Route";
66277
- var RouteErrorContext = React3__namespace.createContext(null);
66278
- RouteErrorContext.displayName = "RouteError";
66279
- function useHref(to, { relative } = {}) {
66280
- invariant(
66281
- useInRouterContext(),
66282
- // TODO: This error is probably because they somehow have 2 versions of the
66283
- // router loaded. We can help them understand how to avoid that.
66284
- `useHref() may be used only in the context of a <Router> component.`
66285
- );
66286
- let { basename, navigator } = React3__namespace.useContext(NavigationContext);
66287
- let { hash, pathname, search } = useResolvedPath(to, { relative });
66288
- let joinedPathname = pathname;
66289
- if (basename !== "/") {
66290
- joinedPathname = pathname === "/" ? basename : joinPaths([basename, pathname]);
66291
- }
66292
- return navigator.createHref({ pathname: joinedPathname, search, hash });
66293
- }
66294
- function useInRouterContext() {
66295
- return React3__namespace.useContext(LocationContext) != null;
66296
- }
66297
- function useLocation() {
66298
- invariant(
66299
- useInRouterContext(),
66300
- // TODO: This error is probably because they somehow have 2 versions of the
66301
- // router loaded. We can help them understand how to avoid that.
66302
- `useLocation() may be used only in the context of a <Router> component.`
66303
- );
66304
- return React3__namespace.useContext(LocationContext).location;
66305
- }
66306
- var navigateEffectWarning = `You should call navigate() in a React.useEffect(), not when your component is first rendered.`;
66307
- function useIsomorphicLayoutEffect(cb) {
66308
- let isStatic = React3__namespace.useContext(NavigationContext).static;
66309
- if (!isStatic) {
66310
- React3__namespace.useLayoutEffect(cb);
66311
- }
66312
- }
66313
- function useNavigate() {
66314
- let { isDataRoute } = React3__namespace.useContext(RouteContext);
66315
- return isDataRoute ? useNavigateStable() : useNavigateUnstable();
66316
- }
66317
- function useNavigateUnstable() {
66318
- invariant(
66319
- useInRouterContext(),
66320
- // TODO: This error is probably because they somehow have 2 versions of the
66321
- // router loaded. We can help them understand how to avoid that.
66322
- `useNavigate() may be used only in the context of a <Router> component.`
66323
- );
66324
- let dataRouterContext = React3__namespace.useContext(DataRouterContext);
66325
- let { basename, navigator } = React3__namespace.useContext(NavigationContext);
66326
- let { matches } = React3__namespace.useContext(RouteContext);
66327
- let { pathname: locationPathname } = useLocation();
66328
- let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));
66329
- let activeRef = React3__namespace.useRef(false);
66330
- useIsomorphicLayoutEffect(() => {
66331
- activeRef.current = true;
66332
- });
66333
- let navigate = React3__namespace.useCallback(
66334
- (to, options = {}) => {
66335
- warning(activeRef.current, navigateEffectWarning);
66336
- if (!activeRef.current) return;
66337
- if (typeof to === "number") {
66338
- navigator.go(to);
66339
- return;
66340
- }
66341
- let path = resolveTo(
66342
- to,
66343
- JSON.parse(routePathnamesJson),
66344
- locationPathname,
66345
- options.relative === "path"
66346
- );
66347
- if (dataRouterContext == null && basename !== "/") {
66348
- path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
66349
- }
66350
- (!!options.replace ? navigator.replace : navigator.push)(
66351
- path,
66352
- options.state,
66353
- options
66354
- );
66355
- },
66356
- [
66357
- basename,
66358
- navigator,
66359
- routePathnamesJson,
66360
- locationPathname,
66361
- dataRouterContext
66362
- ]
66363
- );
66364
- return navigate;
66365
- }
66366
- React3__namespace.createContext(null);
66367
- function useResolvedPath(to, { relative } = {}) {
66368
- let { matches } = React3__namespace.useContext(RouteContext);
66369
- let { pathname: locationPathname } = useLocation();
66370
- let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));
66371
- return React3__namespace.useMemo(
66372
- () => resolveTo(
66373
- to,
66374
- JSON.parse(routePathnamesJson),
66375
- locationPathname,
66376
- relative === "path"
66377
- ),
66378
- [to, routePathnamesJson, locationPathname, relative]
66379
- );
66380
- }
66381
- function useRoutesImpl(routes, locationArg, dataRouterState, unstable_onError, future) {
66382
- invariant(
66383
- useInRouterContext(),
66384
- // TODO: This error is probably because they somehow have 2 versions of the
66385
- // router loaded. We can help them understand how to avoid that.
66386
- `useRoutes() may be used only in the context of a <Router> component.`
66387
- );
66388
- let { navigator } = React3__namespace.useContext(NavigationContext);
66389
- let { matches: parentMatches } = React3__namespace.useContext(RouteContext);
66390
- let routeMatch = parentMatches[parentMatches.length - 1];
66391
- let parentParams = routeMatch ? routeMatch.params : {};
66392
- let parentPathname = routeMatch ? routeMatch.pathname : "/";
66393
- let parentPathnameBase = routeMatch ? routeMatch.pathnameBase : "/";
66394
- let parentRoute = routeMatch && routeMatch.route;
66395
- {
66396
- let parentPath = parentRoute && parentRoute.path || "";
66397
- warningOnce(
66398
- parentPathname,
66399
- !parentRoute || parentPath.endsWith("*") || parentPath.endsWith("*?"),
66400
- `You rendered descendant <Routes> (or called \`useRoutes()\`) at "${parentPathname}" (under <Route path="${parentPath}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
66401
-
66402
- Please change the parent <Route path="${parentPath}"> to <Route path="${parentPath === "/" ? "*" : `${parentPath}/*`}">.`
66403
- );
66404
- }
66405
- let locationFromContext = useLocation();
66406
- let location;
66407
- {
66408
- location = locationFromContext;
66409
- }
66410
- let pathname = location.pathname || "/";
66411
- let remainingPathname = pathname;
66412
- if (parentPathnameBase !== "/") {
66413
- let parentSegments = parentPathnameBase.replace(/^\//, "").split("/");
66414
- let segments = pathname.replace(/^\//, "").split("/");
66415
- remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
66416
- }
66417
- let matches = matchRoutes(routes, { pathname: remainingPathname });
66418
- {
66419
- warning(
66420
- parentRoute || matches != null,
66421
- `No routes matched location "${location.pathname}${location.search}${location.hash}" `
66422
- );
66423
- warning(
66424
- matches == null || matches[matches.length - 1].route.element !== void 0 || matches[matches.length - 1].route.Component !== void 0 || matches[matches.length - 1].route.lazy !== void 0,
66425
- `Matched leaf route at location "${location.pathname}${location.search}${location.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`
66426
- );
66427
- }
66428
- let renderedMatches = _renderMatches(
66429
- matches && matches.map(
66430
- (match) => Object.assign({}, match, {
66431
- params: Object.assign({}, parentParams, match.params),
66432
- pathname: joinPaths([
66433
- parentPathnameBase,
66434
- // Re-encode pathnames that were decoded inside matchRoutes
66435
- navigator.encodeLocation ? navigator.encodeLocation(match.pathname).pathname : match.pathname
66436
- ]),
66437
- pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([
66438
- parentPathnameBase,
66439
- // Re-encode pathnames that were decoded inside matchRoutes
66440
- navigator.encodeLocation ? navigator.encodeLocation(match.pathnameBase).pathname : match.pathnameBase
66441
- ])
66442
- })
66443
- ),
66444
- parentMatches,
66445
- dataRouterState,
66446
- unstable_onError,
66447
- future
66448
- );
66449
- return renderedMatches;
66450
- }
66451
- function DefaultErrorComponent() {
66452
- let error = useRouteError();
66453
- let message = isRouteErrorResponse(error) ? `${error.status} ${error.statusText}` : error instanceof Error ? error.message : JSON.stringify(error);
66454
- let stack = error instanceof Error ? error.stack : null;
66455
- let lightgrey = "rgba(200,200,200, 0.5)";
66456
- let preStyles = { padding: "0.5rem", backgroundColor: lightgrey };
66457
- let codeStyles = { padding: "2px 4px", backgroundColor: lightgrey };
66458
- let devInfo = null;
66459
- {
66460
- console.error(
66461
- "Error handled by React Router default ErrorBoundary:",
66462
- error
66463
- );
66464
- devInfo = /* @__PURE__ */ React3__namespace.createElement(React3__namespace.Fragment, null, /* @__PURE__ */ React3__namespace.createElement("p", null, "\u{1F4BF} Hey developer \u{1F44B}"), /* @__PURE__ */ React3__namespace.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", /* @__PURE__ */ React3__namespace.createElement("code", { style: codeStyles }, "ErrorBoundary"), " or", " ", /* @__PURE__ */ React3__namespace.createElement("code", { style: codeStyles }, "errorElement"), " prop on your route."));
66465
- }
66466
- return /* @__PURE__ */ React3__namespace.createElement(React3__namespace.Fragment, null, /* @__PURE__ */ React3__namespace.createElement("h2", null, "Unexpected Application Error!"), /* @__PURE__ */ React3__namespace.createElement("h3", { style: { fontStyle: "italic" } }, message), stack ? /* @__PURE__ */ React3__namespace.createElement("pre", { style: preStyles }, stack) : null, devInfo);
66467
- }
66468
- var defaultErrorElement = /* @__PURE__ */ React3__namespace.createElement(DefaultErrorComponent, null);
66469
- var RenderErrorBoundary = class extends React3__namespace.Component {
66470
- constructor(props) {
66471
- super(props);
66472
- this.state = {
66473
- location: props.location,
66474
- revalidation: props.revalidation,
66475
- error: props.error
66476
- };
66477
- }
66478
- static getDerivedStateFromError(error) {
66479
- return { error };
66480
- }
66481
- static getDerivedStateFromProps(props, state) {
66482
- if (state.location !== props.location || state.revalidation !== "idle" && props.revalidation === "idle") {
66483
- return {
66484
- error: props.error,
66485
- location: props.location,
66486
- revalidation: props.revalidation
66487
- };
66488
- }
66489
- return {
66490
- error: props.error !== void 0 ? props.error : state.error,
66491
- location: state.location,
66492
- revalidation: props.revalidation || state.revalidation
66493
- };
66494
- }
66495
- componentDidCatch(error, errorInfo) {
66496
- if (this.props.unstable_onError) {
66497
- this.props.unstable_onError(error, errorInfo);
66498
- } else {
66499
- console.error(
66500
- "React Router caught the following error during render",
66501
- error
66502
- );
66503
- }
66504
- }
66505
- render() {
66506
- return this.state.error !== void 0 ? /* @__PURE__ */ React3__namespace.createElement(RouteContext.Provider, { value: this.props.routeContext }, /* @__PURE__ */ React3__namespace.createElement(
66507
- RouteErrorContext.Provider,
66508
- {
66509
- value: this.state.error,
66510
- children: this.props.component
66511
- }
66512
- )) : this.props.children;
66513
- }
66514
- };
66515
- function RenderedRoute({ routeContext, match, children }) {
66516
- let dataRouterContext = React3__namespace.useContext(DataRouterContext);
66517
- if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && (match.route.errorElement || match.route.ErrorBoundary)) {
66518
- dataRouterContext.staticContext._deepestRenderedBoundaryId = match.route.id;
66519
- }
66520
- return /* @__PURE__ */ React3__namespace.createElement(RouteContext.Provider, { value: routeContext }, children);
66521
- }
66522
- function _renderMatches(matches, parentMatches = [], dataRouterState = null, unstable_onError = null, future = null) {
66523
- if (matches == null) {
66524
- if (!dataRouterState) {
66525
- return null;
66526
- }
66527
- if (dataRouterState.errors) {
66528
- matches = dataRouterState.matches;
66529
- } else if (parentMatches.length === 0 && !dataRouterState.initialized && dataRouterState.matches.length > 0) {
66530
- matches = dataRouterState.matches;
66531
- } else {
66532
- return null;
66533
- }
66534
- }
66535
- let renderedMatches = matches;
66536
- let errors = dataRouterState?.errors;
66537
- if (errors != null) {
66538
- let errorIndex = renderedMatches.findIndex(
66539
- (m) => m.route.id && errors?.[m.route.id] !== void 0
66540
- );
66541
- invariant(
66542
- errorIndex >= 0,
66543
- `Could not find a matching route for errors on route IDs: ${Object.keys(
66544
- errors
66545
- ).join(",")}`
66546
- );
66547
- renderedMatches = renderedMatches.slice(
66548
- 0,
66549
- Math.min(renderedMatches.length, errorIndex + 1)
66550
- );
66551
- }
66552
- let renderFallback = false;
66553
- let fallbackIndex = -1;
66554
- if (dataRouterState) {
66555
- for (let i = 0; i < renderedMatches.length; i++) {
66556
- let match = renderedMatches[i];
66557
- if (match.route.HydrateFallback || match.route.hydrateFallbackElement) {
66558
- fallbackIndex = i;
66559
- }
66560
- if (match.route.id) {
66561
- let { loaderData, errors: errors2 } = dataRouterState;
66562
- let needsToRunLoader = match.route.loader && !loaderData.hasOwnProperty(match.route.id) && (!errors2 || errors2[match.route.id] === void 0);
66563
- if (match.route.lazy || needsToRunLoader) {
66564
- renderFallback = true;
66565
- if (fallbackIndex >= 0) {
66566
- renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
66567
- } else {
66568
- renderedMatches = [renderedMatches[0]];
66569
- }
66570
- break;
66571
- }
66572
- }
66573
- }
66574
- }
66575
- return renderedMatches.reduceRight(
66576
- (outlet, match, index) => {
66577
- let error;
66578
- let shouldRenderHydrateFallback = false;
66579
- let errorElement = null;
66580
- let hydrateFallbackElement = null;
66581
- if (dataRouterState) {
66582
- error = errors && match.route.id ? errors[match.route.id] : void 0;
66583
- errorElement = match.route.errorElement || defaultErrorElement;
66584
- if (renderFallback) {
66585
- if (fallbackIndex < 0 && index === 0) {
66586
- warningOnce(
66587
- "route-fallback",
66588
- false,
66589
- "No `HydrateFallback` element provided to render during initial hydration"
66590
- );
66591
- shouldRenderHydrateFallback = true;
66592
- hydrateFallbackElement = null;
66593
- } else if (fallbackIndex === index) {
66594
- shouldRenderHydrateFallback = true;
66595
- hydrateFallbackElement = match.route.hydrateFallbackElement || null;
66596
- }
66597
- }
66598
- }
66599
- let matches2 = parentMatches.concat(renderedMatches.slice(0, index + 1));
66600
- let getChildren = () => {
66601
- let children;
66602
- if (error) {
66603
- children = errorElement;
66604
- } else if (shouldRenderHydrateFallback) {
66605
- children = hydrateFallbackElement;
66606
- } else if (match.route.Component) {
66607
- children = /* @__PURE__ */ React3__namespace.createElement(match.route.Component, null);
66608
- } else if (match.route.element) {
66609
- children = match.route.element;
66610
- } else {
66611
- children = outlet;
66612
- }
66613
- return /* @__PURE__ */ React3__namespace.createElement(
66614
- RenderedRoute,
66615
- {
66616
- match,
66617
- routeContext: {
66618
- outlet,
66619
- matches: matches2,
66620
- isDataRoute: dataRouterState != null
66621
- },
66622
- children
66623
- }
66624
- );
66625
- };
66626
- return dataRouterState && (match.route.ErrorBoundary || match.route.errorElement || index === 0) ? /* @__PURE__ */ React3__namespace.createElement(
66627
- RenderErrorBoundary,
66628
- {
66629
- location: dataRouterState.location,
66630
- revalidation: dataRouterState.revalidation,
66631
- component: errorElement,
66632
- error,
66633
- children: getChildren(),
66634
- routeContext: { outlet: null, matches: matches2, isDataRoute: true },
66635
- unstable_onError
66636
- }
66637
- ) : getChildren();
66638
- },
66639
- null
66640
- );
66641
- }
66642
- function getDataRouterConsoleError(hookName) {
66643
- return `${hookName} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
66644
- }
66645
- function useDataRouterContext(hookName) {
66646
- let ctx = React3__namespace.useContext(DataRouterContext);
66647
- invariant(ctx, getDataRouterConsoleError(hookName));
66648
- return ctx;
66649
- }
66650
- function useDataRouterState(hookName) {
66651
- let state = React3__namespace.useContext(DataRouterStateContext);
66652
- invariant(state, getDataRouterConsoleError(hookName));
66653
- return state;
66654
- }
66655
- function useRouteContext(hookName) {
66656
- let route = React3__namespace.useContext(RouteContext);
66657
- invariant(route, getDataRouterConsoleError(hookName));
66658
- return route;
66659
- }
66660
- function useCurrentRouteId(hookName) {
66661
- let route = useRouteContext(hookName);
66662
- let thisRoute = route.matches[route.matches.length - 1];
66663
- invariant(
66664
- thisRoute.route.id,
66665
- `${hookName} can only be used on routes that contain a unique "id"`
66666
- );
66667
- return thisRoute.route.id;
66668
- }
66669
- function useRouteId() {
66670
- return useCurrentRouteId("useRouteId" /* UseRouteId */);
66671
- }
66672
- function useRouteError() {
66673
- let error = React3__namespace.useContext(RouteErrorContext);
66674
- let state = useDataRouterState("useRouteError" /* UseRouteError */);
66675
- let routeId = useCurrentRouteId("useRouteError" /* UseRouteError */);
66676
- if (error !== void 0) {
66677
- return error;
66678
- }
66679
- return state.errors?.[routeId];
66680
- }
66681
- function useNavigateStable() {
66682
- let { router } = useDataRouterContext("useNavigate" /* UseNavigateStable */);
66683
- let id = useCurrentRouteId("useNavigate" /* UseNavigateStable */);
66684
- let activeRef = React3__namespace.useRef(false);
66685
- useIsomorphicLayoutEffect(() => {
66686
- activeRef.current = true;
66687
- });
66688
- let navigate = React3__namespace.useCallback(
66689
- async (to, options = {}) => {
66690
- warning(activeRef.current, navigateEffectWarning);
66691
- if (!activeRef.current) return;
66692
- if (typeof to === "number") {
66693
- router.navigate(to);
66694
- } else {
66695
- await router.navigate(to, { fromRouteId: id, ...options });
66696
- }
66697
- },
66698
- [router, id]
66699
- );
66700
- return navigate;
66701
- }
66702
- var alreadyWarned = {};
66703
- function warningOnce(key, cond, message) {
66704
- if (!cond && !alreadyWarned[key]) {
66705
- alreadyWarned[key] = true;
66706
- warning(false, message);
66707
- }
66708
- }
66709
- React3__namespace.memo(DataRoutes);
66710
- function DataRoutes({
66711
- routes,
66712
- future,
66713
- state,
66714
- unstable_onError
66715
- }) {
66716
- return useRoutesImpl(routes, void 0, state, unstable_onError, future);
66717
- }
66718
-
66719
- // lib/dom/dom.ts
66720
- var defaultMethod = "get";
66721
- var defaultEncType = "application/x-www-form-urlencoded";
66722
- function isHtmlElement(object) {
66723
- return object != null && typeof object.tagName === "string";
66724
- }
66725
- function isButtonElement(object) {
66726
- return isHtmlElement(object) && object.tagName.toLowerCase() === "button";
66727
- }
66728
- function isFormElement(object) {
66729
- return isHtmlElement(object) && object.tagName.toLowerCase() === "form";
66730
- }
66731
- function isInputElement(object) {
66732
- return isHtmlElement(object) && object.tagName.toLowerCase() === "input";
66733
- }
66734
- function isModifiedEvent(event) {
66735
- return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
66736
- }
66737
- function shouldProcessLinkClick(event, target) {
66738
- return event.button === 0 && // Ignore everything but left clicks
66739
- (!target || target === "_self") && // Let browser handle "target=_blank" etc.
66740
- !isModifiedEvent(event);
66741
- }
66742
- var _formDataSupportsSubmitter = null;
66743
- function isFormDataSubmitterSupported() {
66744
- if (_formDataSupportsSubmitter === null) {
66745
- try {
66746
- new FormData(
66747
- document.createElement("form"),
66748
- // @ts-expect-error if FormData supports the submitter parameter, this will throw
66749
- 0
66750
- );
66751
- _formDataSupportsSubmitter = false;
66752
- } catch (e) {
66753
- _formDataSupportsSubmitter = true;
66754
- }
66755
- }
66756
- return _formDataSupportsSubmitter;
66757
- }
66758
- var supportedFormEncTypes = /* @__PURE__ */ new Set([
66759
- "application/x-www-form-urlencoded",
66760
- "multipart/form-data",
66761
- "text/plain"
66762
- ]);
66763
- function getFormEncType(encType) {
66764
- if (encType != null && !supportedFormEncTypes.has(encType)) {
66765
- warning(
66766
- false,
66767
- `"${encType}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${defaultEncType}"`
66768
- );
66769
- return null;
66770
- }
66771
- return encType;
66772
- }
66773
- function getFormSubmissionInfo(target, basename) {
66774
- let method;
66775
- let action;
66776
- let encType;
66777
- let formData;
66778
- let body;
66779
- if (isFormElement(target)) {
66780
- let attr = target.getAttribute("action");
66781
- action = attr ? stripBasename(attr, basename) : null;
66782
- method = target.getAttribute("method") || defaultMethod;
66783
- encType = getFormEncType(target.getAttribute("enctype")) || defaultEncType;
66784
- formData = new FormData(target);
66785
- } else if (isButtonElement(target) || isInputElement(target) && (target.type === "submit" || target.type === "image")) {
66786
- let form = target.form;
66787
- if (form == null) {
66788
- throw new Error(
66789
- `Cannot submit a <button> or <input type="submit"> without a <form>`
66790
- );
66791
- }
66792
- let attr = target.getAttribute("formaction") || form.getAttribute("action");
66793
- action = attr ? stripBasename(attr, basename) : null;
66794
- method = target.getAttribute("formmethod") || form.getAttribute("method") || defaultMethod;
66795
- encType = getFormEncType(target.getAttribute("formenctype")) || getFormEncType(form.getAttribute("enctype")) || defaultEncType;
66796
- formData = new FormData(form, target);
66797
- if (!isFormDataSubmitterSupported()) {
66798
- let { name, type, value } = target;
66799
- if (type === "image") {
66800
- let prefix = name ? `${name}.` : "";
66801
- formData.append(`${prefix}x`, "0");
66802
- formData.append(`${prefix}y`, "0");
66803
- } else if (name) {
66804
- formData.append(name, value);
66805
- }
66806
- }
66807
- } else if (isHtmlElement(target)) {
66808
- throw new Error(
66809
- `Cannot submit element that is not <form>, <button>, or <input type="submit|image">`
66810
- );
66811
- } else {
66812
- method = defaultMethod;
66813
- action = null;
66814
- encType = defaultEncType;
66815
- body = target;
66816
- }
66817
- if (formData && encType === "text/plain") {
66818
- body = formData;
66819
- formData = void 0;
66820
- }
66821
- return { action, method: method.toLowerCase(), encType, formData, body };
66822
- }
66823
- Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
66824
-
66825
- // lib/dom/ssr/invariant.ts
66826
- function invariant2(value, message) {
66827
- if (value === false || value === null || typeof value === "undefined") {
66828
- throw new Error(message);
66829
- }
66830
- }
66831
- function singleFetchUrl(reqUrl, basename, extension) {
66832
- let url = typeof reqUrl === "string" ? new URL(
66833
- reqUrl,
66834
- // This can be called during the SSR flow via PrefetchPageLinksImpl so
66835
- // don't assume window is available
66836
- typeof window === "undefined" ? "server://singlefetch/" : window.location.origin
66837
- ) : reqUrl;
66838
- if (url.pathname === "/") {
66839
- url.pathname = `_root.${extension}`;
66840
- } else if (basename && stripBasename(url.pathname, basename) === "/") {
66841
- url.pathname = `${basename.replace(/\/$/, "")}/_root.${extension}`;
66842
- } else {
66843
- url.pathname = `${url.pathname.replace(/\/$/, "")}.${extension}`;
66844
- }
66845
- return url;
66846
- }
66847
-
66848
- // lib/dom/ssr/routeModules.ts
66849
- async function loadRouteModule(route, routeModulesCache) {
66850
- if (route.id in routeModulesCache) {
66851
- return routeModulesCache[route.id];
66852
- }
66853
- try {
66854
- let routeModule = await import(
66855
- /* @vite-ignore */
66856
- /* webpackIgnore: true */
66857
- route.module
66858
- );
66859
- routeModulesCache[route.id] = routeModule;
66860
- return routeModule;
66861
- } catch (error) {
66862
- console.error(
66863
- `Error loading route module \`${route.module}\`, reloading page...`
66864
- );
66865
- console.error(error);
66866
- if (window.__reactRouterContext && window.__reactRouterContext.isSpaMode && // @ts-expect-error
66867
- undefined) {
66868
- throw error;
66869
- }
66870
- window.location.reload();
66871
- return new Promise(() => {
66872
- });
66873
- }
66874
- }
66875
- function isHtmlLinkDescriptor(object) {
66876
- if (object == null) {
66877
- return false;
66878
- }
66879
- if (object.href == null) {
66880
- return object.rel === "preload" && typeof object.imageSrcSet === "string" && typeof object.imageSizes === "string";
66881
- }
66882
- return typeof object.rel === "string" && typeof object.href === "string";
66883
- }
66884
- async function getKeyedPrefetchLinks(matches, manifest, routeModules) {
66885
- let links = await Promise.all(
66886
- matches.map(async (match) => {
66887
- let route = manifest.routes[match.route.id];
66888
- if (route) {
66889
- let mod = await loadRouteModule(route, routeModules);
66890
- return mod.links ? mod.links() : [];
66891
- }
66892
- return [];
66893
- })
66894
- );
66895
- return dedupeLinkDescriptors(
66896
- links.flat(1).filter(isHtmlLinkDescriptor).filter((link) => link.rel === "stylesheet" || link.rel === "preload").map(
66897
- (link) => link.rel === "stylesheet" ? { ...link, rel: "prefetch", as: "style" } : { ...link, rel: "prefetch" }
66898
- )
66899
- );
66900
- }
66901
- function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, location, mode) {
66902
- let isNew = (match, index) => {
66903
- if (!currentMatches[index]) return true;
66904
- return match.route.id !== currentMatches[index].route.id;
66905
- };
66906
- let matchPathChanged = (match, index) => {
66907
- return (
66908
- // param change, /users/123 -> /users/456
66909
- currentMatches[index].pathname !== match.pathname || // splat param changed, which is not present in match.path
66910
- // e.g. /files/images/avatar.jpg -> files/finances.xls
66911
- currentMatches[index].route.path?.endsWith("*") && currentMatches[index].params["*"] !== match.params["*"]
66912
- );
66913
- };
66914
- if (mode === "assets") {
66915
- return nextMatches.filter(
66916
- (match, index) => isNew(match, index) || matchPathChanged(match, index)
66917
- );
66918
- }
66919
- if (mode === "data") {
66920
- return nextMatches.filter((match, index) => {
66921
- let manifestRoute = manifest.routes[match.route.id];
66922
- if (!manifestRoute || !manifestRoute.hasLoader) {
66923
- return false;
66924
- }
66925
- if (isNew(match, index) || matchPathChanged(match, index)) {
66926
- return true;
66927
- }
66928
- if (match.route.shouldRevalidate) {
66929
- let routeChoice = match.route.shouldRevalidate({
66930
- currentUrl: new URL(
66931
- location.pathname + location.search + location.hash,
66932
- window.origin
66933
- ),
66934
- currentParams: currentMatches[0]?.params || {},
66935
- nextUrl: new URL(page, window.origin),
66936
- nextParams: match.params,
66937
- defaultShouldRevalidate: true
66938
- });
66939
- if (typeof routeChoice === "boolean") {
66940
- return routeChoice;
66941
- }
66942
- }
66943
- return true;
66944
- });
66945
- }
66946
- return [];
66947
- }
66948
- function getModuleLinkHrefs(matches, manifest, { includeHydrateFallback } = {}) {
66949
- return dedupeHrefs(
66950
- matches.map((match) => {
66951
- let route = manifest.routes[match.route.id];
66952
- if (!route) return [];
66953
- let hrefs = [route.module];
66954
- if (route.clientActionModule) {
66955
- hrefs = hrefs.concat(route.clientActionModule);
66956
- }
66957
- if (route.clientLoaderModule) {
66958
- hrefs = hrefs.concat(route.clientLoaderModule);
66959
- }
66960
- if (includeHydrateFallback && route.hydrateFallbackModule) {
66961
- hrefs = hrefs.concat(route.hydrateFallbackModule);
66962
- }
66963
- if (route.imports) {
66964
- hrefs = hrefs.concat(route.imports);
66965
- }
66966
- return hrefs;
66967
- }).flat(1)
66968
- );
66969
- }
66970
- function dedupeHrefs(hrefs) {
66971
- return [...new Set(hrefs)];
66972
- }
66973
- function sortKeys(obj) {
66974
- let sorted = {};
66975
- let keys = Object.keys(obj).sort();
66976
- for (let key of keys) {
66977
- sorted[key] = obj[key];
66978
- }
66979
- return sorted;
66980
- }
66981
- function dedupeLinkDescriptors(descriptors, preloads) {
66982
- let set = /* @__PURE__ */ new Set();
66983
- new Set(preloads);
66984
- return descriptors.reduce((deduped, descriptor) => {
66985
- let key = JSON.stringify(sortKeys(descriptor));
66986
- if (!set.has(key)) {
66987
- set.add(key);
66988
- deduped.push({ key, link: descriptor });
66989
- }
66990
- return deduped;
66991
- }, []);
66992
- }
66993
-
66994
- // lib/dom/ssr/components.tsx
66995
- function useDataRouterContext2() {
66996
- let context = React3__namespace.useContext(DataRouterContext);
66997
- invariant2(
66998
- context,
66999
- "You must render this element inside a <DataRouterContext.Provider> element"
67000
- );
67001
- return context;
67002
- }
67003
- function useDataRouterStateContext() {
67004
- let context = React3__namespace.useContext(DataRouterStateContext);
67005
- invariant2(
67006
- context,
67007
- "You must render this element inside a <DataRouterStateContext.Provider> element"
67008
- );
67009
- return context;
67010
- }
67011
- var FrameworkContext = React3__namespace.createContext(void 0);
67012
- FrameworkContext.displayName = "FrameworkContext";
67013
- function useFrameworkContext() {
67014
- let context = React3__namespace.useContext(FrameworkContext);
67015
- invariant2(
67016
- context,
67017
- "You must render this element inside a <HydratedRouter> element"
67018
- );
67019
- return context;
67020
- }
67021
- function usePrefetchBehavior(prefetch, theirElementProps) {
67022
- let frameworkContext = React3__namespace.useContext(FrameworkContext);
67023
- let [maybePrefetch, setMaybePrefetch] = React3__namespace.useState(false);
67024
- let [shouldPrefetch, setShouldPrefetch] = React3__namespace.useState(false);
67025
- let { onFocus, onBlur, onMouseEnter, onMouseLeave, onTouchStart } = theirElementProps;
67026
- let ref = React3__namespace.useRef(null);
67027
- React3__namespace.useEffect(() => {
67028
- if (prefetch === "render") {
67029
- setShouldPrefetch(true);
67030
- }
67031
- if (prefetch === "viewport") {
67032
- let callback = (entries) => {
67033
- entries.forEach((entry) => {
67034
- setShouldPrefetch(entry.isIntersecting);
67035
- });
67036
- };
67037
- let observer = new IntersectionObserver(callback, { threshold: 0.5 });
67038
- if (ref.current) observer.observe(ref.current);
67039
- return () => {
67040
- observer.disconnect();
67041
- };
67042
- }
67043
- }, [prefetch]);
67044
- React3__namespace.useEffect(() => {
67045
- if (maybePrefetch) {
67046
- let id = setTimeout(() => {
67047
- setShouldPrefetch(true);
67048
- }, 100);
67049
- return () => {
67050
- clearTimeout(id);
67051
- };
67052
- }
67053
- }, [maybePrefetch]);
67054
- let setIntent = () => {
67055
- setMaybePrefetch(true);
67056
- };
67057
- let cancelIntent = () => {
67058
- setMaybePrefetch(false);
67059
- setShouldPrefetch(false);
67060
- };
67061
- if (!frameworkContext) {
67062
- return [false, ref, {}];
67063
- }
67064
- if (prefetch !== "intent") {
67065
- return [shouldPrefetch, ref, {}];
67066
- }
67067
- return [
67068
- shouldPrefetch,
67069
- ref,
67070
- {
67071
- onFocus: composeEventHandlers(onFocus, setIntent),
67072
- onBlur: composeEventHandlers(onBlur, cancelIntent),
67073
- onMouseEnter: composeEventHandlers(onMouseEnter, setIntent),
67074
- onMouseLeave: composeEventHandlers(onMouseLeave, cancelIntent),
67075
- onTouchStart: composeEventHandlers(onTouchStart, setIntent)
67076
- }
67077
- ];
67078
- }
67079
- function composeEventHandlers(theirHandler, ourHandler) {
67080
- return (event) => {
67081
- theirHandler && theirHandler(event);
67082
- if (!event.defaultPrevented) {
67083
- ourHandler(event);
67084
- }
67085
- };
67086
- }
67087
- function PrefetchPageLinks({ page, ...linkProps }) {
67088
- let { router } = useDataRouterContext2();
67089
- let matches = React3__namespace.useMemo(
67090
- () => matchRoutes(router.routes, page, router.basename),
67091
- [router.routes, page, router.basename]
67092
- );
67093
- if (!matches) {
67094
- return null;
67095
- }
67096
- return /* @__PURE__ */ React3__namespace.createElement(PrefetchPageLinksImpl, { page, matches, ...linkProps });
67097
- }
67098
- function useKeyedPrefetchLinks(matches) {
67099
- let { manifest, routeModules } = useFrameworkContext();
67100
- let [keyedPrefetchLinks, setKeyedPrefetchLinks] = React3__namespace.useState([]);
67101
- React3__namespace.useEffect(() => {
67102
- let interrupted = false;
67103
- void getKeyedPrefetchLinks(matches, manifest, routeModules).then(
67104
- (links) => {
67105
- if (!interrupted) {
67106
- setKeyedPrefetchLinks(links);
67107
- }
67108
- }
67109
- );
67110
- return () => {
67111
- interrupted = true;
67112
- };
67113
- }, [matches, manifest, routeModules]);
67114
- return keyedPrefetchLinks;
67115
- }
67116
- function PrefetchPageLinksImpl({
67117
- page,
67118
- matches: nextMatches,
67119
- ...linkProps
67120
- }) {
67121
- let location = useLocation();
67122
- let { manifest, routeModules } = useFrameworkContext();
67123
- let { basename } = useDataRouterContext2();
67124
- let { loaderData, matches } = useDataRouterStateContext();
67125
- let newMatchesForData = React3__namespace.useMemo(
67126
- () => getNewMatchesForLinks(
67127
- page,
67128
- nextMatches,
67129
- matches,
67130
- manifest,
67131
- location,
67132
- "data"
67133
- ),
67134
- [page, nextMatches, matches, manifest, location]
67135
- );
67136
- let newMatchesForAssets = React3__namespace.useMemo(
67137
- () => getNewMatchesForLinks(
67138
- page,
67139
- nextMatches,
67140
- matches,
67141
- manifest,
67142
- location,
67143
- "assets"
67144
- ),
67145
- [page, nextMatches, matches, manifest, location]
67146
- );
67147
- let dataHrefs = React3__namespace.useMemo(() => {
67148
- if (page === location.pathname + location.search + location.hash) {
67149
- return [];
67150
- }
67151
- let routesParams = /* @__PURE__ */ new Set();
67152
- let foundOptOutRoute = false;
67153
- nextMatches.forEach((m) => {
67154
- let manifestRoute = manifest.routes[m.route.id];
67155
- if (!manifestRoute || !manifestRoute.hasLoader) {
67156
- return;
67157
- }
67158
- if (!newMatchesForData.some((m2) => m2.route.id === m.route.id) && m.route.id in loaderData && routeModules[m.route.id]?.shouldRevalidate) {
67159
- foundOptOutRoute = true;
67160
- } else if (manifestRoute.hasClientLoader) {
67161
- foundOptOutRoute = true;
67162
- } else {
67163
- routesParams.add(m.route.id);
67164
- }
67165
- });
67166
- if (routesParams.size === 0) {
67167
- return [];
67168
- }
67169
- let url = singleFetchUrl(page, basename, "data");
67170
- if (foundOptOutRoute && routesParams.size > 0) {
67171
- url.searchParams.set(
67172
- "_routes",
67173
- nextMatches.filter((m) => routesParams.has(m.route.id)).map((m) => m.route.id).join(",")
67174
- );
67175
- }
67176
- return [url.pathname + url.search];
67177
- }, [
67178
- basename,
67179
- loaderData,
67180
- location,
67181
- manifest,
67182
- newMatchesForData,
67183
- nextMatches,
67184
- page,
67185
- routeModules
67186
- ]);
67187
- let moduleHrefs = React3__namespace.useMemo(
67188
- () => getModuleLinkHrefs(newMatchesForAssets, manifest),
67189
- [newMatchesForAssets, manifest]
67190
- );
67191
- let keyedPrefetchLinks = useKeyedPrefetchLinks(newMatchesForAssets);
67192
- return /* @__PURE__ */ React3__namespace.createElement(React3__namespace.Fragment, null, dataHrefs.map((href) => /* @__PURE__ */ React3__namespace.createElement("link", { key: href, rel: "prefetch", as: "fetch", href, ...linkProps })), moduleHrefs.map((href) => /* @__PURE__ */ React3__namespace.createElement("link", { key: href, rel: "modulepreload", href, ...linkProps })), keyedPrefetchLinks.map(({ key, link }) => (
67193
- // these don't spread `linkProps` because they are full link descriptors
67194
- // already with their own props
67195
- /* @__PURE__ */ React3__namespace.createElement("link", { key, nonce: linkProps.nonce, ...link })
67196
- )));
67197
- }
67198
- function mergeRefs(...refs) {
67199
- return (value) => {
67200
- refs.forEach((ref) => {
67201
- if (typeof ref === "function") {
67202
- ref(value);
67203
- } else if (ref != null) {
67204
- ref.current = value;
67205
- }
67206
- });
67207
- };
67208
- }
67209
- var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
67210
- try {
67211
- if (isBrowser) {
67212
- window.__reactRouterVersion = // @ts-expect-error
67213
- "7.8.2";
67214
- }
67215
- } catch (e) {
67216
- }
67217
- var ABSOLUTE_URL_REGEX2 = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
67218
- var Link = React3__namespace.forwardRef(
67219
- function LinkWithRef({
67220
- onClick,
67221
- discover = "render",
67222
- prefetch = "none",
67223
- relative,
67224
- reloadDocument,
67225
- replace: replace2,
67226
- state,
67227
- target,
67228
- to,
67229
- preventScrollReset,
67230
- viewTransition,
67231
- ...rest
67232
- }, forwardedRef) {
67233
- let { basename } = React3__namespace.useContext(NavigationContext);
67234
- let isAbsolute = typeof to === "string" && ABSOLUTE_URL_REGEX2.test(to);
67235
- let absoluteHref;
67236
- let isExternal = false;
67237
- if (typeof to === "string" && isAbsolute) {
67238
- absoluteHref = to;
67239
- if (isBrowser) {
67240
- try {
67241
- let currentUrl = new URL(window.location.href);
67242
- let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to);
67243
- let path = stripBasename(targetUrl.pathname, basename);
67244
- if (targetUrl.origin === currentUrl.origin && path != null) {
67245
- to = path + targetUrl.search + targetUrl.hash;
67246
- } else {
67247
- isExternal = true;
67248
- }
67249
- } catch (e) {
67250
- warning(
67251
- false,
67252
- `<Link to="${to}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`
67253
- );
67254
- }
67255
- }
67256
- }
67257
- let href = useHref(to, { relative });
67258
- let [shouldPrefetch, prefetchRef, prefetchHandlers] = usePrefetchBehavior(
67259
- prefetch,
67260
- rest
67261
- );
67262
- let internalOnClick = useLinkClickHandler(to, {
67263
- replace: replace2,
67264
- state,
67265
- target,
67266
- preventScrollReset,
67267
- relative,
67268
- viewTransition
67269
- });
67270
- function handleClick(event) {
67271
- if (onClick) onClick(event);
67272
- if (!event.defaultPrevented) {
67273
- internalOnClick(event);
67274
- }
67275
- }
67276
- let link = (
67277
- // eslint-disable-next-line jsx-a11y/anchor-has-content
67278
- /* @__PURE__ */ React3__namespace.createElement(
67279
- "a",
67280
- {
67281
- ...rest,
67282
- ...prefetchHandlers,
67283
- href: absoluteHref || href,
67284
- onClick: isExternal || reloadDocument ? onClick : handleClick,
67285
- ref: mergeRefs(forwardedRef, prefetchRef),
67286
- target,
67287
- "data-discover": !isAbsolute && discover === "render" ? "true" : void 0
67288
- }
67289
- )
67290
- );
67291
- return shouldPrefetch && !isAbsolute ? /* @__PURE__ */ React3__namespace.createElement(React3__namespace.Fragment, null, link, /* @__PURE__ */ React3__namespace.createElement(PrefetchPageLinks, { page: href })) : link;
67292
- }
67293
- );
67294
- Link.displayName = "Link";
67295
- var NavLink = React3__namespace.forwardRef(
67296
- function NavLinkWithRef({
67297
- "aria-current": ariaCurrentProp = "page",
67298
- caseSensitive = false,
67299
- className: classNameProp = "",
67300
- end = false,
67301
- style: styleProp,
67302
- to,
67303
- viewTransition,
67304
- children,
67305
- ...rest
67306
- }, ref) {
67307
- let path = useResolvedPath(to, { relative: rest.relative });
67308
- let location = useLocation();
67309
- let routerState = React3__namespace.useContext(DataRouterStateContext);
67310
- let { navigator, basename } = React3__namespace.useContext(NavigationContext);
67311
- let isTransitioning = routerState != null && // Conditional usage is OK here because the usage of a data router is static
67312
- // eslint-disable-next-line react-hooks/rules-of-hooks
67313
- useViewTransitionState(path) && viewTransition === true;
67314
- let toPathname = navigator.encodeLocation ? navigator.encodeLocation(path).pathname : path.pathname;
67315
- let locationPathname = location.pathname;
67316
- let nextLocationPathname = routerState && routerState.navigation && routerState.navigation.location ? routerState.navigation.location.pathname : null;
67317
- if (!caseSensitive) {
67318
- locationPathname = locationPathname.toLowerCase();
67319
- nextLocationPathname = nextLocationPathname ? nextLocationPathname.toLowerCase() : null;
67320
- toPathname = toPathname.toLowerCase();
67321
- }
67322
- if (nextLocationPathname && basename) {
67323
- nextLocationPathname = stripBasename(nextLocationPathname, basename) || nextLocationPathname;
67324
- }
67325
- const endSlashPosition = toPathname !== "/" && toPathname.endsWith("/") ? toPathname.length - 1 : toPathname.length;
67326
- let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(endSlashPosition) === "/";
67327
- let isPending = nextLocationPathname != null && (nextLocationPathname === toPathname || !end && nextLocationPathname.startsWith(toPathname) && nextLocationPathname.charAt(toPathname.length) === "/");
67328
- let renderProps = {
67329
- isActive,
67330
- isPending,
67331
- isTransitioning
67332
- };
67333
- let ariaCurrent = isActive ? ariaCurrentProp : void 0;
67334
- let className;
67335
- if (typeof classNameProp === "function") {
67336
- className = classNameProp(renderProps);
67337
- } else {
67338
- className = [
67339
- classNameProp,
67340
- isActive ? "active" : null,
67341
- isPending ? "pending" : null,
67342
- isTransitioning ? "transitioning" : null
67343
- ].filter(Boolean).join(" ");
67344
- }
67345
- let style = typeof styleProp === "function" ? styleProp(renderProps) : styleProp;
67346
- return /* @__PURE__ */ React3__namespace.createElement(
67347
- Link,
67348
- {
67349
- ...rest,
67350
- "aria-current": ariaCurrent,
67351
- className,
67352
- ref,
67353
- style,
67354
- to,
67355
- viewTransition
67356
- },
67357
- typeof children === "function" ? children(renderProps) : children
67358
- );
67359
- }
67360
- );
67361
- NavLink.displayName = "NavLink";
67362
- var Form = React3__namespace.forwardRef(
67363
- ({
67364
- discover = "render",
67365
- fetcherKey,
67366
- navigate,
67367
- reloadDocument,
67368
- replace: replace2,
67369
- state,
67370
- method = defaultMethod,
67371
- action,
67372
- onSubmit,
67373
- relative,
67374
- preventScrollReset,
67375
- viewTransition,
67376
- ...props
67377
- }, forwardedRef) => {
67378
- let submit = useSubmit();
67379
- let formAction = useFormAction(action, { relative });
67380
- let formMethod = method.toLowerCase() === "get" ? "get" : "post";
67381
- let isAbsolute = typeof action === "string" && ABSOLUTE_URL_REGEX2.test(action);
67382
- let submitHandler = (event) => {
67383
- onSubmit && onSubmit(event);
67384
- if (event.defaultPrevented) return;
67385
- event.preventDefault();
67386
- let submitter = event.nativeEvent.submitter;
67387
- let submitMethod = submitter?.getAttribute("formmethod") || method;
67388
- submit(submitter || event.currentTarget, {
67389
- fetcherKey,
67390
- method: submitMethod,
67391
- navigate,
67392
- replace: replace2,
67393
- state,
67394
- relative,
67395
- preventScrollReset,
67396
- viewTransition
67397
- });
67398
- };
67399
- return /* @__PURE__ */ React3__namespace.createElement(
67400
- "form",
67401
- {
67402
- ref: forwardedRef,
67403
- method: formMethod,
67404
- action: formAction,
67405
- onSubmit: reloadDocument ? onSubmit : submitHandler,
67406
- ...props,
67407
- "data-discover": !isAbsolute && discover === "render" ? "true" : void 0
67408
- }
67409
- );
67410
- }
67411
- );
67412
- Form.displayName = "Form";
67413
- function getDataRouterConsoleError2(hookName) {
67414
- return `${hookName} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
67415
- }
67416
- function useDataRouterContext3(hookName) {
67417
- let ctx = React3__namespace.useContext(DataRouterContext);
67418
- invariant(ctx, getDataRouterConsoleError2(hookName));
67419
- return ctx;
67420
- }
67421
- function useLinkClickHandler(to, {
67422
- target,
67423
- replace: replaceProp,
67424
- state,
67425
- preventScrollReset,
67426
- relative,
67427
- viewTransition
67428
- } = {}) {
67429
- let navigate = useNavigate();
67430
- let location = useLocation();
67431
- let path = useResolvedPath(to, { relative });
67432
- return React3__namespace.useCallback(
67433
- (event) => {
67434
- if (shouldProcessLinkClick(event, target)) {
67435
- event.preventDefault();
67436
- let replace2 = replaceProp !== void 0 ? replaceProp : createPath(location) === createPath(path);
67437
- navigate(to, {
67438
- replace: replace2,
67439
- state,
67440
- preventScrollReset,
67441
- relative,
67442
- viewTransition
67443
- });
67444
- }
67445
- },
67446
- [
67447
- location,
67448
- navigate,
67449
- path,
67450
- replaceProp,
67451
- state,
67452
- target,
67453
- to,
67454
- preventScrollReset,
67455
- relative,
67456
- viewTransition
67457
- ]
67458
- );
67459
- }
67460
- var fetcherId = 0;
67461
- var getUniqueFetcherId = () => `__${String(++fetcherId)}__`;
67462
- function useSubmit() {
67463
- let { router } = useDataRouterContext3("useSubmit" /* UseSubmit */);
67464
- let { basename } = React3__namespace.useContext(NavigationContext);
67465
- let currentRouteId = useRouteId();
67466
- return React3__namespace.useCallback(
67467
- async (target, options = {}) => {
67468
- let { action, method, encType, formData, body } = getFormSubmissionInfo(
67469
- target,
67470
- basename
67471
- );
67472
- if (options.navigate === false) {
67473
- let key = options.fetcherKey || getUniqueFetcherId();
67474
- await router.fetch(key, currentRouteId, options.action || action, {
67475
- preventScrollReset: options.preventScrollReset,
67476
- formData,
67477
- body,
67478
- formMethod: options.method || method,
67479
- formEncType: options.encType || encType,
67480
- flushSync: options.flushSync
67481
- });
67482
- } else {
67483
- await router.navigate(options.action || action, {
67484
- preventScrollReset: options.preventScrollReset,
67485
- formData,
67486
- body,
67487
- formMethod: options.method || method,
67488
- formEncType: options.encType || encType,
67489
- replace: options.replace,
67490
- state: options.state,
67491
- fromRouteId: currentRouteId,
67492
- flushSync: options.flushSync,
67493
- viewTransition: options.viewTransition
67494
- });
67495
- }
67496
- },
67497
- [router, basename, currentRouteId]
67498
- );
67499
- }
67500
- function useFormAction(action, { relative } = {}) {
67501
- let { basename } = React3__namespace.useContext(NavigationContext);
67502
- let routeContext = React3__namespace.useContext(RouteContext);
67503
- invariant(routeContext, "useFormAction must be used inside a RouteContext");
67504
- let [match] = routeContext.matches.slice(-1);
67505
- let path = { ...useResolvedPath(action ? action : ".", { relative }) };
67506
- let location = useLocation();
67507
- if (action == null) {
67508
- path.search = location.search;
67509
- let params = new URLSearchParams(path.search);
67510
- let indexValues = params.getAll("index");
67511
- let hasNakedIndexParam = indexValues.some((v) => v === "");
67512
- if (hasNakedIndexParam) {
67513
- params.delete("index");
67514
- indexValues.filter((v) => v).forEach((v) => params.append("index", v));
67515
- let qs = params.toString();
67516
- path.search = qs ? `?${qs}` : "";
67517
- }
67518
- }
67519
- if ((!action || action === ".") && match.route.index) {
67520
- path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
67521
- }
67522
- if (basename !== "/") {
67523
- path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
67524
- }
67525
- return createPath(path);
67526
- }
67527
- function useViewTransitionState(to, { relative } = {}) {
67528
- let vtContext = React3__namespace.useContext(ViewTransitionContext);
67529
- invariant(
67530
- vtContext != null,
67531
- "`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?"
67532
- );
67533
- let { basename } = useDataRouterContext3(
67534
- "useViewTransitionState" /* useViewTransitionState */
67535
- );
67536
- let path = useResolvedPath(to, { relative });
67537
- if (!vtContext.isTransitioning) {
67538
- return false;
67539
- }
67540
- let currentPath = stripBasename(vtContext.currentLocation.pathname, basename) || vtContext.currentLocation.pathname;
67541
- let nextPath = stripBasename(vtContext.nextLocation.pathname, basename) || vtContext.nextLocation.pathname;
67542
- return matchPath(path.pathname, nextPath) != null || matchPath(path.pathname, currentPath) != null;
67543
- }
67544
-
67545
65816
  var _excluded$6 = ["color"];
67546
65817
  var ExternalarrowMd = function ExternalarrowMd(_ref) {
67547
65818
  var _ref$color = _ref.color,
@@ -67569,7 +65840,7 @@ function RuledGrid(_ref) {
67569
65840
  var columns = _ref.columns,
67570
65841
  children = _ref.children,
67571
65842
  rest = _objectWithoutProperties(_ref, _excluded$5);
67572
- var childrenArray = React3.Children.toArray(children);
65843
+ var childrenArray = React.Children.toArray(children);
67573
65844
  return jsxRuntime.jsx(Chakra.Grid, _objectSpread2(_objectSpread2({
67574
65845
  templateColumns: "repeat(".concat(columns, ", 1fr)"),
67575
65846
  border: "1px solid",
@@ -67592,7 +65863,9 @@ function HelloPage(_ref) {
67592
65863
  var userName = _ref.userName,
67593
65864
  onStartChat = _ref.onStartChat,
67594
65865
  _ref$isStartingChat = _ref.isStartingChat,
67595
- isStartingChat = _ref$isStartingChat === void 0 ? false : _ref$isStartingChat;
65866
+ isStartingChat = _ref$isStartingChat === void 0 ? false : _ref$isStartingChat,
65867
+ LinkComponent = _ref.LinkComponent;
65868
+ var hasRouterLink = Boolean(LinkComponent);
67596
65869
  var navigationItems = [{
67597
65870
  label: "Documentation",
67598
65871
  href: "https://droplinked.gitbook.io/droplinked-store-front-help-center",
@@ -67647,8 +65920,9 @@ function HelloPage(_ref) {
67647
65920
  },
67648
65921
  children: jsxRuntime.jsxs(Chakra.VStack, {
67649
65922
  align: "stretch",
67650
- justify: "flex-start",
65923
+ justify: "flex-end",
67651
65924
  gap: 4,
65925
+ minH: "full",
67652
65926
  children: [jsxRuntime.jsxs(Chakra.Flex, {
67653
65927
  flexDirection: "column",
67654
65928
  justifyContent: "flex-end",
@@ -67738,9 +66012,9 @@ function HelloPage(_ref) {
67738
66012
  fontWeight: 500,
67739
66013
  color: "white",
67740
66014
  textDecoration: "none",
67741
- as: item.isExternal ? undefined : Link,
67742
- to: item.isExternal ? undefined : item.href,
67743
- href: item.isExternal ? item.href : undefined,
66015
+ as: !item.isExternal && hasRouterLink ? LinkComponent : undefined,
66016
+ to: !item.isExternal && hasRouterLink ? item.href : undefined,
66017
+ href: item.isExternal || !hasRouterLink ? item.href : undefined,
67744
66018
  isExternal: item.isExternal,
67745
66019
  children: [item.label, jsxRuntime.jsx(ExternalarrowMd, {
67746
66020
  color: "white"
@@ -67920,7 +66194,7 @@ var TooltipMd = function TooltipMd(_ref) {
67920
66194
  };
67921
66195
 
67922
66196
  var _excluded = ["showArrow", "children", "disabled", "portalled", "content", "portalRef", "placement"];
67923
- var Tooltip = /*#__PURE__*/React3__namespace.forwardRef(function Tooltip(_ref2, _ref) {
66197
+ var Tooltip = /*#__PURE__*/React__namespace.forwardRef(function Tooltip(_ref2, _ref) {
67924
66198
  var showArrow = _ref2.showArrow,
67925
66199
  children = _ref2.children,
67926
66200
  disabled = _ref2.disabled;