@jsenv/navi 0.12.40 → 0.12.41

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.
@@ -7741,6 +7741,7 @@ const createRoute = (urlPatternInput) => {
7741
7741
  hasRawUrlPartWithInvalidChars,
7742
7742
  };
7743
7743
  };
7744
+ route.buildRelativeUrl = buildRelativeUrl;
7744
7745
 
7745
7746
  /**
7746
7747
  * Builds a complete URL for this route with the given parameters.
@@ -8120,6 +8121,37 @@ const updateDocumentUrl = (value) => {
8120
8121
  documentUrlSignal.value = value;
8121
8122
  };
8122
8123
 
8124
+ computed(() => {
8125
+ const documentUrl = documentUrlSignal.value;
8126
+ const documentResource = urlToResource(documentUrl);
8127
+ return documentResource;
8128
+ });
8129
+ const urlToResource = (url) => {
8130
+ const scheme = urlToScheme(url);
8131
+ if (scheme === "file") {
8132
+ const urlAsStringWithoutFileProtocol = String(url).slice("file://".length);
8133
+ return urlAsStringWithoutFileProtocol;
8134
+ }
8135
+ if (scheme === "https" || scheme === "http") {
8136
+ // remove origin
8137
+ const afterProtocol = String(url).slice(scheme.length + "://".length);
8138
+ const pathnameSlashIndex = afterProtocol.indexOf("/", "://".length);
8139
+ const urlAsStringWithoutOrigin = afterProtocol.slice(pathnameSlashIndex);
8140
+ return urlAsStringWithoutOrigin;
8141
+ }
8142
+ const urlAsStringWithoutProtocol = String(url).slice(scheme.length + 1);
8143
+ return urlAsStringWithoutProtocol;
8144
+ };
8145
+ const urlToScheme = (url) => {
8146
+ const urlString = String(url);
8147
+ const colonIndex = urlString.indexOf(":");
8148
+ if (colonIndex === -1) {
8149
+ return "";
8150
+ }
8151
+ const scheme = urlString.slice(0, colonIndex);
8152
+ return scheme;
8153
+ };
8154
+
8123
8155
  const getHrefTargetInfo = (href) => {
8124
8156
  href = String(href);
8125
8157
 
@@ -8340,7 +8372,8 @@ const setupBrowserIntegrationViaHistory = ({
8340
8372
  });
8341
8373
  });
8342
8374
 
8343
- const goTo = async (url, { state = null, replace } = {}) => {
8375
+ const goTo = async (target, { state = null, replace } = {}) => {
8376
+ const url = new URL(target, window.location.href).href;
8344
8377
  const currentUrl = documentUrlSignal.peek();
8345
8378
  if (url === currentUrl) {
8346
8379
  return;
@@ -8566,11 +8599,11 @@ const useNavStateBasic = (id, initialValue, { debug } = {}) => {
8566
8599
  const useNavState = useNavStateBasic;
8567
8600
 
8568
8601
  const NEVER_SET = {};
8569
- const useUrlSearchParam = (paramName) => {
8602
+ const useUrlSearchParam = (paramName, defaultValue) => {
8570
8603
  const documentUrl = documentUrlSignal.value;
8571
8604
  const searchParam = new URL(documentUrl).searchParams.get(paramName);
8572
8605
  const valueRef = useRef(NEVER_SET);
8573
- const [value, setValue] = useState();
8606
+ const [value, setValue] = useState(defaultValue);
8574
8607
  if (valueRef.current !== searchParam) {
8575
8608
  valueRef.current = searchParam;
8576
8609
  setValue(searchParam);