pagiera 0.2.0-alpha.40 → 0.2.0-alpha.42

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.
@@ -9547,6 +9547,15 @@ function isRegistry(value) {
9547
9547
  (entry) => Boolean(entry && typeof entry.id === "string" && typeof entry.name === "string" && typeof entry.version === "string" && entry.preview)
9548
9548
  );
9549
9549
  }
9550
+ function withRefresh(url) {
9551
+ try {
9552
+ const parsed = new URL(url, globalThis.location?.href ?? "http://localhost");
9553
+ parsed.searchParams.set("refresh", "1");
9554
+ return /^[a-z][a-z0-9+.-]*:|^\/\//i.test(url) ? parsed.href : parsed.pathname + parsed.search + parsed.hash;
9555
+ } catch {
9556
+ return url;
9557
+ }
9558
+ }
9550
9559
  async function fetchJson(url) {
9551
9560
  const response = await fetch(url, { cache: "no-cache", headers: { Accept: "application/json" } });
9552
9561
  if (!response.ok) throw new Error(`Template registry returned ${response.status}.`);
@@ -9563,7 +9572,7 @@ async function loadTemplateRegistry(url = DEFAULT_TEMPLATE_REGISTRY_URL, force =
9563
9572
  if (cached && isRegistry(cached)) return { registry: cached, source: "cache" };
9564
9573
  }
9565
9574
  try {
9566
- const response = await fetchJson(url);
9575
+ const response = await fetchJson(force ? withRefresh(url) : url);
9567
9576
  const value = response.value;
9568
9577
  if (!isRegistry(value)) throw new Error("Template registry has an unsupported format.");
9569
9578
  if (cacheable) writeCache(key, value);
@@ -9792,16 +9801,23 @@ var FALLBACK_DEVICES = [
9792
9801
  { id: "tablet", name: "Tablet", width: 834 },
9793
9802
  { id: "mobile", name: "Mobile", width: 390 }
9794
9803
  ];
9795
- function previewUrlFor(templateId) {
9796
- return `${DEFAULT_TEMPLATE_REGISTRY_URL.replace(/registry\.json$/, "")}${encodeURIComponent(templateId)}/preview`;
9804
+ function previewUrlFor(templateId, force) {
9805
+ const base = `${DEFAULT_TEMPLATE_REGISTRY_URL.replace(/registry\.json$/, "")}${encodeURIComponent(templateId)}/preview`;
9806
+ return force ? `${base}?refresh=1` : base;
9797
9807
  }
9798
- function useTemplatePreview(templateId) {
9808
+ function useTemplatePreview(templateId, revision = 0) {
9799
9809
  const [pages, setPages] = useState12();
9800
9810
  const [error, setError] = useState12("");
9801
9811
  const [loading, setLoading] = useState12(false);
9802
9812
  const cache = useRef4(/* @__PURE__ */ new Map());
9813
+ const lastRevision = useRef4(revision);
9803
9814
  useEffect9(() => {
9804
9815
  if (!templateId) return;
9816
+ const force = revision !== lastRevision.current;
9817
+ if (force) {
9818
+ cache.current.clear();
9819
+ lastRevision.current = revision;
9820
+ }
9805
9821
  const cached = cache.current.get(templateId);
9806
9822
  if (cached) {
9807
9823
  setPages(cached);
@@ -9812,7 +9828,10 @@ function useTemplatePreview(templateId) {
9812
9828
  setLoading(true);
9813
9829
  setError("");
9814
9830
  setPages(void 0);
9815
- fetch(previewUrlFor(templateId), { headers: { Accept: "application/json" } }).then(async (response) => {
9831
+ fetch(previewUrlFor(templateId, force), {
9832
+ headers: { Accept: "application/json" },
9833
+ cache: force ? "no-store" : "default"
9834
+ }).then(async (response) => {
9816
9835
  const payload = await response.json().catch(() => ({}));
9817
9836
  if (!response.ok) throw new Error(payload?.error ?? `Preview returned ${response.status}.`);
9818
9837
  if (!Array.isArray(payload?.pages) || payload.pages.length === 0) {
@@ -9832,7 +9851,7 @@ function useTemplatePreview(templateId) {
9832
9851
  return () => {
9833
9852
  active = false;
9834
9853
  };
9835
- }, [templateId]);
9854
+ }, [templateId, revision]);
9836
9855
  return { pages, loading, error };
9837
9856
  }
9838
9857
  function devicesFor(page) {
@@ -9972,7 +9991,8 @@ function TemplatesPanel({
9972
9991
  const [selectedFont, setSelectedFont] = useState13("");
9973
9992
  const [portalContainer, setPortalContainer] = useState13(null);
9974
9993
  const providerFonts = usePagieraFonts2();
9975
- const preview = useTemplatePreview(pendingTemplate?.id);
9994
+ const [catalogRevision, setCatalogRevision] = useState13(0);
9995
+ const preview = useTemplatePreview(pendingTemplate?.id, catalogRevision);
9976
9996
  const fontOptions = useMemo3(() => {
9977
9997
  const options = [
9978
9998
  ...pendingTemplate?.font?.url ? [{ label: `${pendingTemplate.font.title} \xB7 Template`, value: pendingTemplate.font.family }] : [],
@@ -9984,6 +10004,7 @@ function TemplatesPanel({
9984
10004
  const refresh = async (force = false) => {
9985
10005
  setStatus("loading");
9986
10006
  setError("");
10007
+ if (force) setCatalogRevision((current) => current + 1);
9987
10008
  const result = await loadTemplateRegistry(registryUrl, force);
9988
10009
  setTemplates(result.registry.templates);
9989
10010
  setStatus(result.source);