@tanstack/router-core 1.131.26 → 1.131.28

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 +1 @@
1
- {"version":3,"file":"qss.js","sources":["../../src/qss.ts"],"sourcesContent":["/**\n * Program is a reimplementation of the `qss` package:\n * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License\n * https://github.com/lukeed/qss/blob/master/license.md\n *\n * This reimplementation uses modern browser APIs\n * (namely URLSearchParams) and TypeScript while still\n * maintaining the original functionality and interface.\n */\n\n/**\n * Encodes an object into a query string.\n * @param obj - The object to encode into a query string.\n * @param [pfx] - An optional prefix to add before the query string.\n * @returns The encoded query string.\n * @example\n * ```\n * // Example input: encode({ token: 'foo', key: 'value' })\n * // Expected output: \"token=foo&key=value\"\n * ```\n */\nexport function encode(obj: any, pfx?: string) {\n const normalizedObject = Object.entries(obj).flatMap(([key, value]) => {\n if (Array.isArray(value)) {\n return value.map((v) => [key, String(v)])\n } else {\n return [[key, String(value)]]\n }\n })\n\n const searchParams = new URLSearchParams(normalizedObject)\n\n return (pfx || '') + searchParams.toString()\n}\n\n/**\n * Converts a string value to its appropriate type (string, number, boolean).\n * @param mix - The string value to convert.\n * @returns The converted value.\n * @example\n * // Example input: toValue(\"123\")\n * // Expected output: 123\n */\nfunction toValue(str: unknown) {\n if (!str) return ''\n\n if (str === 'false') return false\n if (str === 'true') return true\n return +str * 0 === 0 && +str + '' === str ? +str : str\n}\n\n/**\n * Decodes a query string into an object.\n * @param str - The query string to decode.\n * @param [pfx] - An optional prefix to filter out from the query string.\n * @returns The decoded key-value pairs in an object format.\n * @example\n * // Example input: decode(\"token=foo&key=value\")\n * // Expected output: { \"token\": \"foo\", \"key\": \"value\" }\n */\nexport function decode(str: any, pfx?: string): any {\n const searchParamsPart = pfx ? str.slice(pfx.length) : str\n const searchParams = new URLSearchParams(searchParamsPart)\n\n const entries = [...searchParams.entries()]\n\n return entries.reduce<Record<string, unknown>>((acc, [key, value]) => {\n const previousValue = acc[key]\n if (previousValue == null) {\n acc[key] = toValue(value)\n } else {\n acc[key] = Array.isArray(previousValue)\n ? [...previousValue, toValue(value)]\n : [previousValue, toValue(value)]\n }\n\n return acc\n }, {})\n}\n"],"names":[],"mappings":"AAqBgB,SAAA,OAAO,KAAU,KAAc;AACvC,QAAA,mBAAmB,OAAO,QAAQ,GAAG,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACjE,QAAA,MAAM,QAAQ,KAAK,GAAG;AACjB,aAAA,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC;AAAA,IAAA,OACnC;AACL,aAAO,CAAC,CAAC,KAAK,OAAO,KAAK,CAAC,CAAC;AAAA,IAAA;AAAA,EAC9B,CACD;AAEK,QAAA,eAAe,IAAI,gBAAgB,gBAAgB;AAEjD,UAAA,OAAO,MAAM,aAAa,SAAS;AAC7C;AAUA,SAAS,QAAQ,KAAc;AACzB,MAAA,CAAC,IAAY,QAAA;AAEb,MAAA,QAAQ,QAAgB,QAAA;AACxB,MAAA,QAAQ,OAAe,QAAA;AACpB,SAAA,CAAC,MAAM,MAAM,KAAK,CAAC,MAAM,OAAO,MAAM,CAAC,MAAM;AACtD;AAWgB,SAAA,OAAO,KAAU,KAAmB;AAClD,QAAM,mBAAmB,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI;AACjD,QAAA,eAAe,IAAI,gBAAgB,gBAAgB;AAEzD,QAAM,UAAU,CAAC,GAAG,aAAa,SAAS;AAE1C,SAAO,QAAQ,OAAgC,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AAC9D,UAAA,gBAAgB,IAAI,GAAG;AAC7B,QAAI,iBAAiB,MAAM;AACrB,UAAA,GAAG,IAAI,QAAQ,KAAK;AAAA,IAAA,OACnB;AACL,UAAI,GAAG,IAAI,MAAM,QAAQ,aAAa,IAClC,CAAC,GAAG,eAAe,QAAQ,KAAK,CAAC,IACjC,CAAC,eAAe,QAAQ,KAAK,CAAC;AAAA,IAAA;AAG7B,WAAA;AAAA,EACT,GAAG,EAAE;AACP;"}
1
+ {"version":3,"file":"qss.js","sources":["../../src/qss.ts"],"sourcesContent":["/**\n * Program is a reimplementation of the `qss` package:\n * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License\n * https://github.com/lukeed/qss/blob/master/license.md\n *\n * This reimplementation uses modern browser APIs\n * (namely URLSearchParams) and TypeScript while still\n * maintaining the original functionality and interface.\n *\n * Update: this implementation has also been mangled to\n * fit exactly our use-case (single value per key in encoding).\n */\n\n/**\n * Encodes an object into a query string.\n * @param obj - The object to encode into a query string.\n * @param stringify - An optional custom stringify function.\n * @returns The encoded query string.\n * @example\n * ```\n * // Example input: encode({ token: 'foo', key: 'value' })\n * // Expected output: \"token=foo&key=value\"\n * ```\n */\nexport function encode(\n obj: Record<string, any>,\n stringify: (value: any) => string = String,\n): string {\n const result = new URLSearchParams()\n\n for (const key in obj) {\n const val = obj[key]\n if (val !== undefined) {\n result.set(key, stringify(val))\n }\n }\n\n return result.toString()\n}\n\n/**\n * Converts a string value to its appropriate type (string, number, boolean).\n * @param mix - The string value to convert.\n * @returns The converted value.\n * @example\n * // Example input: toValue(\"123\")\n * // Expected output: 123\n */\nfunction toValue(str: unknown) {\n if (!str) return ''\n\n if (str === 'false') return false\n if (str === 'true') return true\n return +str * 0 === 0 && +str + '' === str ? +str : str\n}\n\n/**\n * Decodes a query string into an object.\n * @param str - The query string to decode.\n * @returns The decoded key-value pairs in an object format.\n * @example\n * // Example input: decode(\"token=foo&key=value\")\n * // Expected output: { \"token\": \"foo\", \"key\": \"value\" }\n */\nexport function decode(str: any): any {\n const searchParams = new URLSearchParams(str)\n\n const result: Record<string, unknown> = {}\n\n for (const [key, value] of searchParams.entries()) {\n const previousValue = result[key]\n if (previousValue == null) {\n result[key] = toValue(value)\n } else if (Array.isArray(previousValue)) {\n previousValue.push(toValue(value))\n } else {\n result[key] = [previousValue, toValue(value)]\n }\n }\n\n return result\n}\n"],"names":[],"mappings":"AAwBgB,SAAA,OACd,KACA,YAAoC,QAC5B;AACF,QAAA,SAAS,IAAI,gBAAgB;AAEnC,aAAW,OAAO,KAAK;AACf,UAAA,MAAM,IAAI,GAAG;AACnB,QAAI,QAAQ,QAAW;AACrB,aAAO,IAAI,KAAK,UAAU,GAAG,CAAC;AAAA,IAAA;AAAA,EAChC;AAGF,SAAO,OAAO,SAAS;AACzB;AAUA,SAAS,QAAQ,KAAc;AACzB,MAAA,CAAC,IAAY,QAAA;AAEb,MAAA,QAAQ,QAAgB,QAAA;AACxB,MAAA,QAAQ,OAAe,QAAA;AACpB,SAAA,CAAC,MAAM,MAAM,KAAK,CAAC,MAAM,OAAO,MAAM,CAAC,MAAM;AACtD;AAUO,SAAS,OAAO,KAAe;AAC9B,QAAA,eAAe,IAAI,gBAAgB,GAAG;AAE5C,QAAM,SAAkC,CAAC;AAEzC,aAAW,CAAC,KAAK,KAAK,KAAK,aAAa,WAAW;AAC3C,UAAA,gBAAgB,OAAO,GAAG;AAChC,QAAI,iBAAiB,MAAM;AAClB,aAAA,GAAG,IAAI,QAAQ,KAAK;AAAA,IAClB,WAAA,MAAM,QAAQ,aAAa,GAAG;AACzB,oBAAA,KAAK,QAAQ,KAAK,CAAC;AAAA,IAAA,OAC5B;AACL,aAAO,GAAG,IAAI,CAAC,eAAe,QAAQ,KAAK,CAAC;AAAA,IAAA;AAAA,EAC9C;AAGK,SAAA;AACT;"}
@@ -235,30 +235,23 @@ class RouterCore {
235
235
  _buildLocation: true
236
236
  });
237
237
  const lastMatch = last(allCurrentLocationMatches);
238
- let fromPath = this.resolvePathWithBase(lastMatch.fullPath, ".");
239
- const toPath = dest.to ? this.resolvePathWithBase(fromPath, `${dest.to}`) : this.resolvePathWithBase(fromPath, ".");
240
- const routeIsChanging = !!dest.to && !comparePaths(dest.to.toString(), fromPath) && !comparePaths(toPath, fromPath);
241
- if (dest.unsafeRelative === "path") {
242
- fromPath = currentLocation.pathname;
243
- } else if (routeIsChanging && dest.from) {
244
- fromPath = dest.from;
245
- if (process.env.NODE_ENV !== "production" && dest._isNavigate) {
246
- const allFromMatches = this.getMatchedRoutes(
247
- dest.from,
248
- void 0
249
- ).matchedRoutes;
250
- const matchedFrom = findLast(allCurrentLocationMatches, (d) => {
251
- return comparePaths(d.fullPath, fromPath);
252
- });
253
- const matchedCurrent = findLast(allFromMatches, (d) => {
254
- return comparePaths(d.fullPath, currentLocation.pathname);
255
- });
256
- if (!matchedFrom && !matchedCurrent) {
257
- console.warn(`Could not find match for from: ${fromPath}`);
258
- }
238
+ if (dest.from && process.env.NODE_ENV !== "production" && dest._isNavigate) {
239
+ const allFromMatches = this.getMatchedRoutes(
240
+ dest.from,
241
+ void 0
242
+ ).matchedRoutes;
243
+ const matchedFrom = findLast(allCurrentLocationMatches, (d) => {
244
+ return comparePaths(d.fullPath, dest.from);
245
+ });
246
+ const matchedCurrent = findLast(allFromMatches, (d) => {
247
+ return comparePaths(d.fullPath, lastMatch.fullPath);
248
+ });
249
+ if (!matchedFrom && !matchedCurrent) {
250
+ console.warn(`Could not find match for from: ${dest.from}`);
259
251
  }
260
252
  }
261
- fromPath = this.resolvePathWithBase(fromPath, ".");
253
+ const defaultedFromPath = dest.unsafeRelative === "path" ? currentLocation.pathname : dest.from ?? lastMatch.fullPath;
254
+ const fromPath = this.resolvePathWithBase(defaultedFromPath, ".");
262
255
  const fromSearch = lastMatch.search;
263
256
  const fromParams = { ...lastMatch.params };
264
257
  const nextTo = dest.to ? this.resolvePathWithBase(fromPath, `${dest.to}`) : this.resolvePathWithBase(fromPath, ".");