create-grist-widget 0.3.25 → 0.3.27

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.
@@ -1,63 +0,0 @@
1
- import { useEffect, useState } from "react"
2
-
3
- import { parseShowcasePath } from "@/lib/showcase-routing"
4
-
5
- // Used by ReleaseInfo, which needs the released-version list on every
6
- // non-embedded, deployed URL. URLs are root-relative to wherever THIS
7
- // deploy actually lives (derived from
8
- // window.location.pathname via parseShowcasePath's hubPath), not hardcoded
9
- // to the grist-widget-sdk monorepo's own showcase: a real scaffolded
10
- // widget has its own versions.json and its own v<version>/ + dev/ dirs,
11
- // and previously showed the monorepo's version history and links instead
12
- // of its own (found live on a real scaffold's landing page).
13
- function hubPath(): string {
14
- const path = parseShowcasePath(window.location.pathname).hubPath
15
- return path.endsWith("/") ? path : `${path}/`
16
- }
17
-
18
- export type ReleasedVersion = {
19
- version: string
20
- publishedAt: string
21
- }
22
-
23
- export function versionsUrl(): string {
24
- return `${hubPath()}versions.json`
25
- }
26
-
27
- export function devUrl(): string {
28
- return `${hubPath()}dev/`
29
- }
30
-
31
- export function versionUrl(version: string): string {
32
- return `${hubPath()}v${version}/`
33
- }
34
-
35
- export function useVersions() {
36
- const [versions, setVersions] = useState<ReleasedVersion[] | null>(null)
37
- const [error, setError] = useState(false)
38
-
39
- useEffect(() => {
40
- let cancelled = false
41
- fetch(versionsUrl(), { cache: "no-store" })
42
- .then((res) => (res.ok ? res.json() : Promise.reject(res)))
43
- .then((data: ReleasedVersion[]) => {
44
- if (!cancelled) setVersions(data)
45
- })
46
- .catch(() => {
47
- if (!cancelled) setError(true)
48
- })
49
- return () => {
50
- cancelled = true
51
- }
52
- }, [])
53
-
54
- return { versions, error }
55
- }
56
-
57
- export function formatDate(iso: string) {
58
- return new Date(iso).toLocaleDateString(undefined, {
59
- year: "numeric",
60
- month: "short",
61
- day: "numeric",
62
- })
63
- }