likec4 1.7.1 → 1.7.3

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.
@@ -1,7 +1,7 @@
1
+ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
1
2
  import * as React from "react";
2
3
  import React__default from "react";
3
4
  import { flushSync } from "react-dom";
4
- import { jsx, jsxs, Fragment } from "react/jsx-runtime";
5
5
  const pushStateEvent = "pushstate", popStateEvent = "popstate", beforeUnloadEvent = "beforeunload", beforeUnloadListener = (event) => (event.preventDefault(), event.returnValue = ""), stopBlocking = () => {
6
6
  removeEventListener(beforeUnloadEvent, beforeUnloadListener, {
7
7
  capture: !0
@@ -146,7 +146,7 @@ function createMemoryHistory(opts = {
146
146
  return createHistory({
147
147
  getLocation: () => parseHref(entries[index], currentState),
148
148
  pushState: (path, state) => {
149
- currentState = state, index < entries.length - 1 && entries.splice(index + 1), entries.push(path), index = Math.max(entries.length - 1, 0);
149
+ currentState = state, entries.splice, index < entries.length - 1 && entries.splice(index + 1), entries.push(path), index = Math.max(entries.length - 1, 0);
150
150
  },
151
151
  replaceState: (path, state) => {
152
152
  currentState = state, entries[index] = path;
@@ -179,17 +179,38 @@ function parseHref(href, state) {
179
179
  function createRandomKey() {
180
180
  return (Math.random() + 1).toString(36).substring(7);
181
181
  }
182
- var prefix = "Invariant failed";
182
+ var isProduction$1 = !0, prefix = "Invariant failed";
183
183
  function invariant(condition, message) {
184
- if (!condition)
185
- throw new Error(prefix);
184
+ if (!condition) {
185
+ if (isProduction$1)
186
+ throw new Error(prefix);
187
+ var provided = typeof message == "function" ? message() : message, value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
188
+ throw new Error(value);
189
+ }
190
+ }
191
+ var isProduction = !0;
192
+ function warning(condition, message) {
193
+ if (!isProduction) {
194
+ if (condition)
195
+ return;
196
+ var text = "Warning: " + message;
197
+ typeof console < "u" && console.warn(text);
198
+ try {
199
+ throw Error(text);
200
+ } catch {
201
+ }
202
+ }
186
203
  }
187
204
  const routerContext = React.createContext(null);
188
205
  function getRouterContext() {
189
206
  return typeof document > "u" ? routerContext : window.__TSR_ROUTER_CONTEXT__ ? window.__TSR_ROUTER_CONTEXT__ : (window.__TSR_ROUTER_CONTEXT__ = routerContext, routerContext);
190
207
  }
191
208
  function useRouter(opts) {
192
- return React.useContext(getRouterContext());
209
+ const value = React.useContext(getRouterContext());
210
+ return warning(
211
+ !((opts?.warn ?? !0) && !value),
212
+ "useRouter must be used inside a <RouterProvider> component!"
213
+ ), value;
193
214
  }
194
215
  var withSelector = { exports: {} }, withSelector_production_min = {}, shim = { exports: {} }, useSyncExternalStoreShim_production_min = {};
195
216
  /**
@@ -231,6 +252,7 @@ function t$1(a, b) {
231
252
  }
232
253
  var u$1 = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? t$1 : q$1;
233
254
  useSyncExternalStoreShim_production_min.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : u$1;
255
+ shim.exports;
234
256
  shim.exports = useSyncExternalStoreShim_production_min;
235
257
  var shimExports = shim.exports;
236
258
  /**
@@ -278,6 +300,7 @@ withSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e2
278
300
  f.hasValue = !0, f.value = d;
279
301
  }, [d]), w(d), d;
280
302
  };
303
+ withSelector.exports;
281
304
  withSelector.exports = withSelector_production_min;
282
305
  var withSelectorExports = withSelector.exports;
283
306
  class Store {
@@ -730,7 +753,9 @@ function ErrorComponent({ error }) {
730
753
  ] });
731
754
  }
732
755
  function useRouterState(opts) {
733
- const contextRouter = useRouter();
756
+ const contextRouter = useRouter({
757
+ warn: opts?.router === void 0
758
+ });
734
759
  return useStore((opts?.router || contextRouter).__store, opts?.select);
735
760
  }
736
761
  function notFound(options = {}) {
@@ -812,7 +837,8 @@ class Router {
812
837
  childRoute.init({ originalIndex: i });
813
838
  const existingRoute = this.routesById[childRoute.id];
814
839
  if (invariant(
815
- !existingRoute
840
+ !existingRoute,
841
+ `Duplicate routes found with id: ${String(childRoute.id)}`
816
842
  ), this.routesById[childRoute.id] = childRoute, !childRoute.isRoot && childRoute.path) {
817
843
  const trimmedFullPath = trimPathRight(childRoute.fullPath);
818
844
  (!this.routesByPath[trimmedFullPath] || childRoute.fullPath.endsWith("/")) && (this.routesByPath[trimmedFullPath] = childRoute);
@@ -1033,7 +1059,8 @@ class Router {
1033
1059
  })
1034
1060
  ) : void 0, fromPath = fromMatch?.pathname || this.latestLocation.pathname;
1035
1061
  invariant(
1036
- dest.from == null || fromMatch != null
1062
+ dest.from == null || fromMatch != null,
1063
+ "Could not find match for from: " + dest.from
1037
1064
  );
1038
1065
  const fromSearch = ((_a = last(fromMatches)) == null ? void 0 : _a.search) || this.latestLocation.search, stayingMatches = matches?.filter(
1039
1066
  (d) => fromMatches.find((e2) => e2.routeId === d.routeId)
@@ -1163,7 +1190,8 @@ class Router {
1163
1190
  } catch {
1164
1191
  }
1165
1192
  return invariant(
1166
- !isExternal
1193
+ !isExternal,
1194
+ "Attempting to navigate to external url with router.navigate!"
1167
1195
  ), this.buildAndCommitLocation({
1168
1196
  ...rest,
1169
1197
  from,
@@ -1665,7 +1693,8 @@ class Router {
1665
1693
  var _a, _b, _c;
1666
1694
  let ctx;
1667
1695
  typeof document < "u" && (ctx = this.options.transformer.parse((_a = window.__TSR__) == null ? void 0 : _a.dehydrated)), invariant(
1668
- ctx
1696
+ ctx,
1697
+ "Expected to find a dehydrated data on window.__TSR__.dehydrated... but we did not. Please file an issue!"
1669
1698
  ), this.dehydratedData = ctx.payload, (_c = (_b = this.options).hydrate) == null || _c.call(_b, ctx.payload);
1670
1699
  const dehydratedState = ctx.router.state, matches = this.matchRoutes(
1671
1700
  this.state.location.pathname,
@@ -1675,7 +1704,8 @@ class Router {
1675
1704
  (d) => d.id === match.id
1676
1705
  );
1677
1706
  return invariant(
1678
- dehydratedMatch
1707
+ dehydratedMatch,
1708
+ `Could not find a client-side match for dehydrated match with id: ${match.id}!`
1679
1709
  ), {
1680
1710
  ...match,
1681
1711
  ...dehydratedMatch
@@ -1697,7 +1727,10 @@ class Router {
1697
1727
  return streamedValue.parsed || (streamedValue.parsed = this.options.transformer.parse(streamedValue.value)), streamedValue.parsed;
1698
1728
  }, this.streamValue = (key, value) => {
1699
1729
  var _a;
1700
- this.streamedKeys.has(key), this.streamedKeys.add(key);
1730
+ warning(
1731
+ !this.streamedKeys.has(key),
1732
+ "Key has already been streamed: " + key
1733
+ ), this.streamedKeys.add(key);
1701
1734
  const children = `__TSR__.streamedValues['${key}'] = { value: ${(_a = this.serializer) == null ? void 0 : _a.call(this, this.options.transformer.stringify(value))}}`;
1702
1735
  this.injectHtml(
1703
1736
  `<script class='tsr-once'>${children}; __TSR__.cleanScripts()<\/script>`
@@ -1711,10 +1744,11 @@ class Router {
1711
1744
  let routeCursor = (err.global ? this.looseRoutesById[rootRouteId] : this.looseRoutesById[err.routeId]) || this.looseRoutesById[rootRouteId];
1712
1745
  for (; !routeCursor.options.notFoundComponent && !this.options.defaultNotFoundComponent && routeCursor.id !== rootRouteId; )
1713
1746
  routeCursor = routeCursor.parentRoute, invariant(
1714
- routeCursor
1747
+ routeCursor,
1748
+ "Found invalid route tree while trying to find not-found handler."
1715
1749
  );
1716
1750
  const match = matchesByRouteId[routeCursor.id];
1717
- invariant(match), updateMatch(match.id, (prev) => ({
1751
+ invariant(match, "Could not find match for route: " + routeCursor.id), updateMatch(match.id, (prev) => ({
1718
1752
  ...prev,
1719
1753
  status: "notFound",
1720
1754
  error: err,
@@ -1786,7 +1820,8 @@ function useMatch(opts) {
1786
1820
  (d) => opts.from ? opts.from === d.routeId : d.id === nearestMatchId
1787
1821
  );
1788
1822
  if (invariant(
1789
- !((opts.shouldThrow ?? !0) && !match)
1823
+ !((opts.shouldThrow ?? !0) && !match),
1824
+ `Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`
1790
1825
  ), match !== void 0)
1791
1826
  return opts.select ? opts.select(match) : match;
1792
1827
  }
@@ -1835,7 +1870,8 @@ class Route {
1835
1870
  this.originalIndex = opts.originalIndex;
1836
1871
  const options2 = this.options, isRoot = !options2?.path && !options2?.id;
1837
1872
  this.parentRoute = (_b = (_a = this.options) == null ? void 0 : _a.getParentRoute) == null ? void 0 : _b.call(_a), isRoot ? this.path = rootRouteId : invariant(
1838
- this.parentRoute
1873
+ this.parentRoute,
1874
+ "Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance."
1839
1875
  );
1840
1876
  let path = isRoot ? rootRouteId : options2.path;
1841
1877
  path && path !== "/" && (path = trimPathLeft(path));
@@ -1851,8 +1887,9 @@ class Route {
1851
1887
  ...opts,
1852
1888
  from: this.id,
1853
1889
  select: (d) => opts?.select ? opts.select(d.context) : d.context
1854
- }), this.useSearch = (opts) => useSearch({ ...opts, from: this.id }), this.useParams = (opts) => useParams({ ...opts, from: this.id }), this.useLoaderDeps = (opts) => useLoaderDeps({ ...opts, from: this.id }), this.useLoaderData = (opts) => useLoaderData({ ...opts, from: this.id }), this.useNavigate = () => useNavigate(), this.options = options || {}, this.isRoot = !options?.getParentRoute, invariant(
1855
- !(options?.id && options?.path)
1890
+ }), this.useSearch = (opts) => useSearch({ ...opts, from: this.id }), this.useParams = (opts) => useParams({ ...opts, from: this.id }), this.useLoaderDeps = (opts) => useLoaderDeps({ ...opts, from: this.id }), this.useLoaderData = (opts) => useLoaderData({ ...opts, from: this.id }), this.useNavigate = () => useNavigate({ from: this.id }), this.options = options || {}, this.isRoot = !options?.getParentRoute, invariant(
1891
+ !(options?.id && options?.path),
1892
+ "Route cannot have both an 'id' and a 'path' option."
1856
1893
  ), this.$$typeof = Symbol.for("react.memo");
1857
1894
  }
1858
1895
  addChildren(children) {
@@ -1887,6 +1924,10 @@ function createFileRoute(path) {
1887
1924
  class FileRoute {
1888
1925
  constructor(path, _opts) {
1889
1926
  this.path = path, this.createRoute = (options) => {
1927
+ warning(
1928
+ this.silent,
1929
+ "FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead."
1930
+ );
1890
1931
  const route = createRoute(options);
1891
1932
  return route.isRoot = !1, route;
1892
1933
  }, this.silent = _opts?.silent;
@@ -2122,7 +2163,8 @@ function Match({ matchId }) {
2122
2163
  }
2123
2164
  });
2124
2165
  invariant(
2125
- routeId
2166
+ routeId,
2167
+ `Could not find routeId for matchId "${matchId}". Please file an issue!`
2126
2168
  );
2127
2169
  const route = router.routesById[routeId], PendingComponent = route.options.pendingComponent ?? router.options.defaultPendingComponent, pendingElement = PendingComponent ? /* @__PURE__ */ jsx(PendingComponent, {}) : null, routeErrorComponent = route.options.errorComponent ?? router.options.defaultErrorComponent, routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch, routeNotFoundComponent = route.isRoot ? (
2128
2170
  // If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component
@@ -2140,7 +2182,7 @@ function Match({ matchId }) {
2140
2182
  errorComponent: routeErrorComponent || ErrorComponent,
2141
2183
  onCatch: (error, errorInfo) => {
2142
2184
  if (isNotFound(error)) throw error;
2143
- routeOnCatch?.(error, errorInfo);
2185
+ warning(!1, `Error in route match: ${matchId}`), routeOnCatch?.(error, errorInfo);
2144
2186
  },
2145
2187
  children: /* @__PURE__ */ jsx(
2146
2188
  ResolvedNotFoundBoundary,
@@ -2179,10 +2221,10 @@ function MatchInner({ matchId }) {
2179
2221
  }), RouteErrorComponent = (route.options.errorComponent ?? router.options.defaultErrorComponent) || ErrorComponent;
2180
2222
  if (match.status === "notFound") {
2181
2223
  let error;
2182
- return isServerSideError(match.error) ? error = (((_a = router.options.errorSerializer) == null ? void 0 : _a.deserialize) ?? defaultDeserializeError)(match.error.data) : error = match.error, invariant(isNotFound(error)), renderRouteNotFound(router, route, error);
2224
+ return isServerSideError(match.error) ? error = (((_a = router.options.errorSerializer) == null ? void 0 : _a.deserialize) ?? defaultDeserializeError)(match.error.data) : error = match.error, invariant(isNotFound(error), "Expected a notFound error"), renderRouteNotFound(router, route, error);
2183
2225
  }
2184
2226
  if (match.status === "redirected")
2185
- throw invariant(isRedirect(match.error)), match.loadPromise;
2227
+ throw invariant(isRedirect(match.error), "Expected a redirect error"), match.loadPromise;
2186
2228
  if (match.status === "error") {
2187
2229
  if (router.isServer)
2188
2230
  return /* @__PURE__ */ jsx(
@@ -2230,7 +2272,8 @@ const Outlet = React.memo(function() {
2230
2272
  select: (s) => {
2231
2273
  const parentMatch = s.matches.find((d) => d.id === matchId);
2232
2274
  return invariant(
2233
- parentMatch
2275
+ parentMatch,
2276
+ `Could not find parent match for matchId "${matchId}"`
2234
2277
  ), {
2235
2278
  parentGlobalNotFound: parentMatch.globalNotFound
2236
2279
  };
@@ -2271,7 +2314,10 @@ function MatchesInner() {
2271
2314
  getResetKey: () => resetKey,
2272
2315
  errorComponent: ErrorComponent,
2273
2316
  onCatch: (error) => {
2274
- error.message || error.toString();
2317
+ warning(
2318
+ !1,
2319
+ "The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!"
2320
+ ), warning(!1, error.message || error.toString());
2275
2321
  },
2276
2322
  children: matchId ? /* @__PURE__ */ jsx(Match, { matchId }) : null
2277
2323
  }