@jsenv/navi 0.15.6 → 0.15.8

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.
@@ -7194,7 +7194,11 @@ const UITransition = ({
7194
7194
  };
7195
7195
  const update = (part, newPart) => {
7196
7196
  if (!set.has(part)) {
7197
- console.warn(`UITransition: trying to update an id that does not exist: ${part}`);
7197
+ if (set.size === 0) {
7198
+ console.warn(`UITransition: content id update "${part}" -> "${newPart}" ignored because content id set is empty`);
7199
+ return;
7200
+ }
7201
+ console.warn(`UITransition: content id update "${part}" -> "${newPart}" ignored because content id not found in set, only got [${Array.from(set).join(", ")}]`);
7198
7202
  return;
7199
7203
  }
7200
7204
  set.delete(part);
@@ -7361,7 +7365,10 @@ const buildRouteRelativeUrl = (
7361
7365
  // When a parameter is wrapped with rawUrlPart(), it bypasses encoding and is
7362
7366
  // inserted as-is into the URL. This allows including pre-encoded values or
7363
7367
  // special characters that should not be percent-encoded.
7364
- const encodeParamValue = (value) => {
7368
+ //
7369
+ // For wildcard parameters (isWildcard=true), we preserve slashes as path separators.
7370
+ // For named parameters and search params (isWildcard=false), we encode slashes.
7371
+ const encodeParamValue = (value, isWildcard = false) => {
7365
7372
  if (value && value[rawUrlPartSymbol]) {
7366
7373
  const rawValue = value.value;
7367
7374
  // Check if raw value contains invalid URL characters
@@ -7370,15 +7377,54 @@ const buildRouteRelativeUrl = (
7370
7377
  }
7371
7378
  return rawValue;
7372
7379
  }
7380
+
7381
+ if (isWildcard) {
7382
+ // For wildcards, only encode characters that are invalid in URL paths,
7383
+ // but preserve slashes as they are path separators
7384
+ return value
7385
+ ? value.replace(/[^a-zA-Z0-9\-._~!$&'()*+,;=:@/]/g, (char) => {
7386
+ return encodeURIComponent(char);
7387
+ })
7388
+ : value;
7389
+ }
7390
+
7391
+ // For named parameters and search params, encode everything including slashes
7373
7392
  return encodeURIComponent(value);
7374
7393
  };
7375
7394
  const extraParamMap = new Map();
7395
+ let wildcardIndex = 0; // Declare wildcard index in the main scope
7396
+
7376
7397
  if (params) {
7377
7398
  const keys = Object.keys(params);
7399
+
7400
+ // First, handle special case: optional groups immediately followed by wildcards
7401
+ // This handles patterns like {/}?* where the optional part should be included when wildcard has content
7402
+ relativeUrl = relativeUrl.replace(/\{([^}]*)\}\?\*/g, (match, group) => {
7403
+ const paramKey = wildcardIndex.toString();
7404
+ const paramValue = params[paramKey];
7405
+
7406
+ if (paramValue) {
7407
+ // Don't add to extraParamMap since we're processing it here
7408
+ // For wildcards, preserve slashes as path separators
7409
+ const wildcardValue = encodeParamValue(paramValue, true);
7410
+ wildcardIndex++;
7411
+ // Include the optional group content when wildcard has value
7412
+ return group + wildcardValue;
7413
+ }
7414
+ wildcardIndex++;
7415
+ // Remove the optional group and wildcard when no value
7416
+ return "";
7417
+ });
7418
+
7378
7419
  // Replace named parameters (:param and {param}) and remove optional markers
7379
7420
  for (const key of keys) {
7421
+ // Skip numeric keys (wildcards) if they were already processed
7422
+ if (!isNaN(key) && parseInt(key) < wildcardIndex) {
7423
+ continue;
7424
+ }
7425
+
7380
7426
  const value = params[key];
7381
- const encodedValue = encodeParamValue(value);
7427
+ const encodedValue = encodeParamValue(value, false); // Named parameters should encode slashes
7382
7428
  const beforeReplace = relativeUrl;
7383
7429
 
7384
7430
  // Replace parameter and remove optional marker if present
@@ -7401,7 +7447,7 @@ const buildRouteRelativeUrl = (
7401
7447
  // Check if any parameters in the group were provided
7402
7448
  for (const key of keys) {
7403
7449
  if (params[key] !== undefined) {
7404
- const encodedValue = encodeParamValue(params[key]);
7450
+ const encodedValue = encodeParamValue(params[key], false); // Named parameters encode slashes
7405
7451
  const paramPattern = new RegExp(`:${key}\\b`);
7406
7452
  if (paramPattern.test(processedGroup)) {
7407
7453
  processedGroup = processedGroup.replace(paramPattern, encodedValue);
@@ -7414,7 +7460,7 @@ const buildRouteRelativeUrl = (
7414
7460
  // Also check for literal parts that match parameter names (like /time where time is a param)
7415
7461
  for (const key of keys) {
7416
7462
  if (params[key] !== undefined) {
7417
- const encodedValue = encodeParamValue(params[key]);
7463
+ const encodedValue = encodeParamValue(params[key], false); // Named parameters encode slashes
7418
7464
  // Check for literal parts like /time that match parameter names
7419
7465
  const literalPattern = new RegExp(`\\/${key}\\b`);
7420
7466
  if (literalPattern.test(processedGroup)) {
@@ -7437,18 +7483,19 @@ const buildRouteRelativeUrl = (
7437
7483
  // Clean up any double slashes or trailing slashes that might result
7438
7484
  relativeUrl = relativeUrl.replace(/\/+/g, "/").replace(/\/$/, "");
7439
7485
 
7440
- // Handle remaining wildcards
7486
+ // Handle remaining wildcards (those not processed by optional group + wildcard above)
7441
7487
  if (params) {
7442
- let wildcardIndex = 0;
7443
7488
  relativeUrl = relativeUrl.replace(/\*/g, () => {
7444
7489
  const paramKey = wildcardIndex.toString();
7445
7490
  const paramValue = params[paramKey];
7446
7491
  if (paramValue) {
7447
7492
  extraParamMap.delete(paramKey);
7493
+ const replacement = encodeParamValue(paramValue, true); // Wildcards preserve slashes
7494
+ wildcardIndex++;
7495
+ return replacement;
7448
7496
  }
7449
- const replacement = paramValue ? encodeParamValue(paramValue) : "*";
7450
7497
  wildcardIndex++;
7451
- return replacement;
7498
+ return "*";
7452
7499
  });
7453
7500
  }
7454
7501
 
@@ -7477,7 +7524,7 @@ const buildRouteRelativeUrl = (
7477
7524
  if (value === true) {
7478
7525
  searchParamPairs.push(encodedKey);
7479
7526
  } else {
7480
- const encodedValue = encodeParamValue(value);
7527
+ const encodedValue = encodeParamValue(value, false); // Search params encode slashes
7481
7528
  searchParamPairs.push(`${encodedKey}=${encodedValue}`);
7482
7529
  }
7483
7530
  }