foss-design 0.4.2 → 0.5.0

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.
@@ -594,8 +594,9 @@ function useTheme() {
594
594
  );
595
595
  }
596
596
  function go(target) {
597
- if (embedded) post({ type: "go", target });
598
- else console.info(`[design] go("${target}") works inside the canvas viewer`);
597
+ const message = `go("${target}") is no longer supported: link to the screen instead (<a href="/\u2026">, or history.pushState in code) and give it a "route" in canvas.json`;
598
+ recordError(message);
599
+ throw new Error(message);
599
600
  }
600
601
  function useScreen() {
601
602
  return { canvas: config.canvas, id: config.id, props: config.props };
@@ -701,11 +702,13 @@ async function takeSnapshot() {
701
702
  }
702
703
  }
703
704
  function keepLinksInFrame() {
704
- const report = (target, form) => post({
705
+ const report = (target, form, raw, pushed = false) => post({
705
706
  type: "link",
706
707
  href: target.href,
707
708
  path: target.origin === location.origin ? target.pathname + target.search + target.hash : null,
708
- form
709
+ form,
710
+ raw,
711
+ pushed
709
712
  });
710
713
  const onClick = (event) => {
711
714
  if (event.defaultPrevented || event.button > 1) return;
@@ -716,7 +719,7 @@ function keepLinksInFrame() {
716
719
  const samePage = target.origin === location.origin && target.pathname === location.pathname && target.search === location.search;
717
720
  if (samePage && target.hash) return;
718
721
  event.preventDefault();
719
- report(target, false);
722
+ report(target, false, link.getAttribute("href") ?? "");
720
723
  };
721
724
  window.addEventListener("click", onClick);
722
725
  window.addEventListener("auxclick", onClick);
@@ -724,8 +727,32 @@ function keepLinksInFrame() {
724
727
  const form = event.target;
725
728
  if (event.defaultPrevented || form.method === "dialog") return;
726
729
  event.preventDefault();
727
- report(new URL(form.getAttribute("action") || location.href, location.href), true);
730
+ const action = form.getAttribute("action") ?? "";
731
+ report(new URL(action || location.href, location.href), true, action);
728
732
  });
733
+ const navigation = window.navigation;
734
+ navigation?.addEventListener("navigate", (event) => {
735
+ const nav = event;
736
+ if (!nav.cancelable || nav.destination.sameDocument || nav.downloadRequest !== null) return;
737
+ if (nav.navigationType === "reload") return;
738
+ const target = new URL(nav.destination.url);
739
+ if (target.pathname === location.pathname && target.search === location.search) return;
740
+ event.preventDefault();
741
+ report(
742
+ target,
743
+ false,
744
+ target.origin === location.origin ? target.pathname + target.search + target.hash : target.href
745
+ );
746
+ });
747
+ for (const name of ["pushState", "replaceState"]) {
748
+ const original = history[name].bind(history);
749
+ history[name] = (data, unused, url) => {
750
+ original(data, unused, url);
751
+ if (url === void 0 || url === null) return;
752
+ const raw = String(url);
753
+ report(new URL(raw, location.href), false, raw, true);
754
+ };
755
+ }
729
756
  }
730
757
  var booted = false;
731
758
  var hmrBound = false;