@jsenv/navi 0.4.0 → 0.4.1

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.
@@ -16760,10 +16760,10 @@ const setBaseUrl = (value) => {
16760
16760
  baseUrl = new URL(value, window.location).href;
16761
16761
  };
16762
16762
 
16763
- const encodedSymbol = Symbol("encoded_uri_component");
16764
- const encodedURIComponent = (value) => {
16763
+ const rawUrlPartSymbol = Symbol("raw_url_part");
16764
+ const rawUrlPart = (value) => {
16765
16765
  return {
16766
- [encodedSymbol]: true,
16766
+ [rawUrlPartSymbol]: true,
16767
16767
  value,
16768
16768
  };
16769
16769
  };
@@ -17041,10 +17041,16 @@ const createRoute = (urlPatternInput) => {
17041
17041
 
17042
17042
  const buildRelativeUrl = (params = {}) => {
17043
17043
  let relativeUrl = urlPatternInput;
17044
+ let hasRawUrlPartWithInvalidChars = false;
17044
17045
 
17045
17046
  const encode = (value) => {
17046
- if (value && value[encodedSymbol]) {
17047
- return value.value;
17047
+ if (value && value[rawUrlPartSymbol]) {
17048
+ const rawValue = value.value;
17049
+ // Check if raw value contains invalid URL characters
17050
+ if (/[\s<>{}|\\^`]/.test(rawValue)) {
17051
+ hasRawUrlPartWithInvalidChars = true;
17052
+ }
17053
+ return rawValue;
17048
17054
  }
17049
17055
  return encodeURIComponent(value);
17050
17056
  };
@@ -17074,14 +17080,29 @@ const createRoute = (urlPatternInput) => {
17074
17080
  });
17075
17081
  }
17076
17082
 
17077
- return relativeUrl;
17083
+ return {
17084
+ relativeUrl,
17085
+ hasRawUrlPartWithInvalidChars,
17086
+ };
17078
17087
  };
17079
17088
  const buildUrl = (params = {}) => {
17080
- let relativeUrl = buildRelativeUrl(params);
17081
- if (relativeUrl[0] === "/") {
17082
- relativeUrl = relativeUrl.slice(1);
17089
+ const { relativeUrl, hasRawUrlPartWithInvalidChars } =
17090
+ buildRelativeUrl(params);
17091
+ let processedRelativeUrl = relativeUrl;
17092
+ if (processedRelativeUrl[0] === "/") {
17093
+ processedRelativeUrl = processedRelativeUrl.slice(1);
17083
17094
  }
17084
- const url = new URL(relativeUrl, baseUrl).href;
17095
+
17096
+ if (hasRawUrlPartWithInvalidChars) {
17097
+ // Manually construct URL to avoid automatic encoding by URL constructor
17098
+ const baseUrlObj = new URL(baseUrl);
17099
+ if (baseUrlObj.pathname.endsWith("/")) {
17100
+ return `${baseUrl}${processedRelativeUrl}`;
17101
+ }
17102
+ return `${baseUrl}/${processedRelativeUrl}`;
17103
+ }
17104
+
17105
+ const url = new URL(processedRelativeUrl, baseUrl).href;
17085
17106
  return url;
17086
17107
  };
17087
17108
  route.buildUrl = buildUrl;
@@ -17091,7 +17112,7 @@ const createRoute = (urlPatternInput) => {
17091
17112
  const visitedSignal = signal(false);
17092
17113
  const relativeUrlSignal = computed(() => {
17093
17114
  const params = paramsSignal.value;
17094
- const relativeUrl = buildRelativeUrl(params);
17115
+ const { relativeUrl } = buildRelativeUrl(params);
17095
17116
  return relativeUrl;
17096
17117
  });
17097
17118
  const disposeRelativeUrlEffect = effect(() => {
@@ -27898,4 +27919,4 @@ const useDependenciesDiff = (inputs) => {
27898
27919
  return diffRef.current;
27899
27920
  };
27900
27921
 
27901
- export { ActionRenderer, ActiveKeyboardShortcuts, Button, Checkbox, CheckboxList, Col, Colgroup, Details, Editable, ErrorBoundaryContext, FontSizedSvg, Form, IconAndText, Input, Label, Link, LinkWithIcon, Overflow, Radio, RadioList, Route, RowNumberCol, RowNumberTableCell, SINGLE_SPACE_CONSTRAINT, SVGMaskOverlay, Select, SelectionContext, SummaryMarker, Tab, TabList, Table, TableCell, Tbody, TextAndCount, Thead, Tr, UITransition, actionIntegratedVia, addCustomMessage, createAction, createSelectionKeyboardShortcuts, createUniqueValueConstraint, defineRoutes, enableDebugActions, enableDebugOnDocumentLoading, encodedURIComponent, goBack, goForward, goTo, isCellSelected, isColumnSelected, isRowSelected, openCallout, reload, removeCustomMessage, rerunActions, resource, setBaseUrl, stopLoad, stringifyTableSelectionValue, updateActions, useActionData, useActionStatus, useCellsAndColumns, useDependenciesDiff, useDocumentState, useDocumentUrl, useEditionController, useFocusGroup, useKeyboardShortcuts, useNavState, useRouteStatus, useRunOnMount, useSelectableElement, useSelectionController, useSignalSync, useStateArray, valueInLocalStorage };
27922
+ export { ActionRenderer, ActiveKeyboardShortcuts, Button, Checkbox, CheckboxList, Col, Colgroup, Details, Editable, ErrorBoundaryContext, FontSizedSvg, Form, IconAndText, Input, Label, Link, LinkWithIcon, Overflow, Radio, RadioList, Route, RowNumberCol, RowNumberTableCell, SINGLE_SPACE_CONSTRAINT, SVGMaskOverlay, Select, SelectionContext, SummaryMarker, Tab, TabList, Table, TableCell, Tbody, TextAndCount, Thead, Tr, UITransition, actionIntegratedVia, addCustomMessage, createAction, createSelectionKeyboardShortcuts, createUniqueValueConstraint, defineRoutes, enableDebugActions, enableDebugOnDocumentLoading, goBack, goForward, goTo, isCellSelected, isColumnSelected, isRowSelected, openCallout, rawUrlPart, reload, removeCustomMessage, rerunActions, resource, setBaseUrl, stopLoad, stringifyTableSelectionValue, updateActions, useActionData, useActionStatus, useCellsAndColumns, useDependenciesDiff, useDocumentState, useDocumentUrl, useEditionController, useFocusGroup, useKeyboardShortcuts, useNavState, useRouteStatus, useRunOnMount, useSelectableElement, useSelectionController, useSignalSync, useStateArray, valueInLocalStorage };
package/index.js CHANGED
@@ -26,7 +26,7 @@ export { useDocumentState } from "./src/browser_integration/document_state_signa
26
26
  export { useDocumentUrl } from "./src/browser_integration/document_url_signal.js";
27
27
  export {
28
28
  defineRoutes,
29
- encodedURIComponent,
29
+ rawUrlPart,
30
30
  setBaseUrl,
31
31
  useRouteStatus,
32
32
  } from "./src/route/route.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/navi",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Library of components including navigation to create frontend applications",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,10 +13,10 @@ export const setBaseUrl = (value) => {
13
13
  baseUrl = new URL(value, window.location).href;
14
14
  };
15
15
 
16
- const encodedSymbol = Symbol("encoded_uri_component");
17
- export const encodedURIComponent = (value) => {
16
+ const rawUrlPartSymbol = Symbol("raw_url_part");
17
+ export const rawUrlPart = (value) => {
18
18
  return {
19
- [encodedSymbol]: true,
19
+ [rawUrlPartSymbol]: true,
20
20
  value,
21
21
  };
22
22
  };
@@ -308,10 +308,16 @@ const createRoute = (urlPatternInput) => {
308
308
 
309
309
  const buildRelativeUrl = (params = {}) => {
310
310
  let relativeUrl = urlPatternInput;
311
+ let hasRawUrlPartWithInvalidChars = false;
311
312
 
312
313
  const encode = (value) => {
313
- if (value && value[encodedSymbol]) {
314
- return value.value;
314
+ if (value && value[rawUrlPartSymbol]) {
315
+ const rawValue = value.value;
316
+ // Check if raw value contains invalid URL characters
317
+ if (/[\s<>{}|\\^`]/.test(rawValue)) {
318
+ hasRawUrlPartWithInvalidChars = true;
319
+ }
320
+ return rawValue;
315
321
  }
316
322
  return encodeURIComponent(value);
317
323
  };
@@ -341,14 +347,29 @@ const createRoute = (urlPatternInput) => {
341
347
  });
342
348
  }
343
349
 
344
- return relativeUrl;
350
+ return {
351
+ relativeUrl,
352
+ hasRawUrlPartWithInvalidChars,
353
+ };
345
354
  };
346
355
  const buildUrl = (params = {}) => {
347
- let relativeUrl = buildRelativeUrl(params);
348
- if (relativeUrl[0] === "/") {
349
- relativeUrl = relativeUrl.slice(1);
356
+ const { relativeUrl, hasRawUrlPartWithInvalidChars } =
357
+ buildRelativeUrl(params);
358
+ let processedRelativeUrl = relativeUrl;
359
+ if (processedRelativeUrl[0] === "/") {
360
+ processedRelativeUrl = processedRelativeUrl.slice(1);
350
361
  }
351
- const url = new URL(relativeUrl, baseUrl).href;
362
+
363
+ if (hasRawUrlPartWithInvalidChars) {
364
+ // Manually construct URL to avoid automatic encoding by URL constructor
365
+ const baseUrlObj = new URL(baseUrl);
366
+ if (baseUrlObj.pathname.endsWith("/")) {
367
+ return `${baseUrl}${processedRelativeUrl}`;
368
+ }
369
+ return `${baseUrl}/${processedRelativeUrl}`;
370
+ }
371
+
372
+ const url = new URL(processedRelativeUrl, baseUrl).href;
352
373
  return url;
353
374
  };
354
375
  route.buildUrl = buildUrl;
@@ -358,7 +379,7 @@ const createRoute = (urlPatternInput) => {
358
379
  const visitedSignal = signal(false);
359
380
  const relativeUrlSignal = computed(() => {
360
381
  const params = paramsSignal.value;
361
- const relativeUrl = buildRelativeUrl(params);
382
+ const { relativeUrl } = buildRelativeUrl(params);
362
383
  return relativeUrl;
363
384
  });
364
385
  const disposeRelativeUrlEffect = effect(() => {