@nifrajs/web-svelte 2.14.1 → 3.2.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.
- package/dist/Chain.svelte +1 -1
- package/dist/Router.svelte +1 -0
- package/dist/fetcher.d.ts.map +1 -1
- package/dist/fetcher.js +6 -9
- package/dist/fetcher.js.map +1 -1
- package/dist/mdx.js +5 -5
- package/dist/mdx.js.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +5 -5
- package/dist/plugin.js.map +1 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +5 -25
- package/dist/query.js.map +1 -1
- package/dist/svg.d.ts +10 -0
- package/dist/svg.d.ts.map +1 -1
- package/dist/svg.js +2 -1
- package/dist/svg.js.map +1 -1
- package/package.json +5 -5
- package/src/Chain.svelte +1 -1
- package/src/Router.svelte +1 -0
- package/src/fetcher.ts +10 -10
- package/src/mdx.ts +5 -5
- package/src/plugin.ts +11 -5
- package/src/query.ts +9 -25
- package/src/svg.ts +3 -1
package/dist/Chain.svelte
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
</svelte:boundary>
|
|
38
38
|
{:else}
|
|
39
39
|
{@const Layout = chain[0]}
|
|
40
|
-
<Layout data={layoutData?.[0] ?? null}>
|
|
40
|
+
<Layout data={layoutData?.[0] ?? null} boundaries={props.boundaries}>
|
|
41
41
|
{#snippet children()}
|
|
42
42
|
<Self chain={chain.slice(1)} {props} layoutData={layoutData?.slice(1)} />
|
|
43
43
|
{/snippet}
|
package/dist/Router.svelte
CHANGED
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
pending: snapshot.pending,
|
|
38
38
|
search: searchOfChain(searchSchemas?.[snapshot.routeId] ?? [], q === -1 ? "" : snapshot.path.slice(q)),
|
|
39
39
|
...(snapshot.submission ? { submission: snapshot.submission } : {}),
|
|
40
|
+
...(snapshot.boundaries !== undefined ? { boundaries: snapshot.boundaries } : {}),
|
|
40
41
|
}
|
|
41
42
|
})
|
|
42
43
|
</script>
|
package/dist/fetcher.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../src/fetcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../src/fetcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAMvE;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAItD,oGAAoG;AACpG,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,GAAG,IAAI,CAEvE;AAED,kGAAkG;AAClG,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC,GAAG;IAClD,qGAAqG;IACrG,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9C,oFAAoF;IACpF,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3F,CAAA;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAWpD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,QAAQ,CAAC,SAAS,OAAO,EAAE,CAAC,CAO1D"}
|
package/dist/fetcher.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createMountedRouterRef, IDLE_FETCHER_STATE, noopAsync, } from "@nifrajs/web/internal/fetcher-runtime";
|
|
1
2
|
/**
|
|
2
3
|
* `@nifrajs/web-svelte/fetcher` - Svelte bindings for concurrent fetchers, as **Svelte stores** (plain
|
|
3
4
|
* `.ts`, no runes/compiler needed). `useFetcher(key)` returns a `Readable<FetcherState>` augmented with
|
|
@@ -11,23 +12,19 @@
|
|
|
11
12
|
* (fetchers are client-only); the first client render starts from the same idle snapshot - no mismatch.
|
|
12
13
|
*/
|
|
13
14
|
import { readable } from "svelte/store";
|
|
14
|
-
|
|
15
|
-
// page, and fetchers never exist on the server. Shared with `client.ts`'s `mountRouter`.
|
|
16
|
-
let mountedRouter;
|
|
15
|
+
const mountedRouter = createMountedRouterRef();
|
|
17
16
|
/** Register (or clear) the router that owns fetchers - called by `mountRouter`. Not for app use. */
|
|
18
17
|
export function setMountedRouter(router) {
|
|
19
|
-
mountedRouter
|
|
18
|
+
mountedRouter.set(router);
|
|
20
19
|
}
|
|
21
|
-
const IDLE = { pending: false, data: undefined };
|
|
22
|
-
const noopAsync = async () => { };
|
|
23
20
|
/**
|
|
24
21
|
* Subscribe to the independent fetcher for `key` (created lazily, stable across renders). Returns a
|
|
25
22
|
* store of its state (`pending`/`data`/`actionData`/`submission`) augmented with `load`/`submit`.
|
|
26
23
|
* Multiple `useFetcher` calls with different keys run concurrently without disturbing the active route.
|
|
27
24
|
*/
|
|
28
25
|
export function useFetcher(key) {
|
|
29
|
-
const fetcher = mountedRouter?.fetcher(key);
|
|
30
|
-
const store = readable(fetcher ? fetcher.snapshot() :
|
|
26
|
+
const fetcher = mountedRouter.get()?.fetcher(key);
|
|
27
|
+
const store = readable(fetcher ? fetcher.snapshot() : IDLE_FETCHER_STATE, (set) => {
|
|
31
28
|
if (fetcher === undefined)
|
|
32
29
|
return;
|
|
33
30
|
set(fetcher.snapshot());
|
|
@@ -44,7 +41,7 @@ export function useFetcher(key) {
|
|
|
44
41
|
* new one is created.
|
|
45
42
|
*/
|
|
46
43
|
export function useFetchers() {
|
|
47
|
-
const router = mountedRouter;
|
|
44
|
+
const router = mountedRouter.get();
|
|
48
45
|
return readable(router ? router.fetchers() : [], (set) => {
|
|
49
46
|
if (router === undefined)
|
|
50
47
|
return;
|
package/dist/fetcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.js","sourceRoot":"","sources":["../src/fetcher.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;GAWG;AACH,OAAO,EAAiB,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEtD,
|
|
1
|
+
{"version":3,"file":"fetcher.js","sourceRoot":"","sources":["../src/fetcher.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,SAAS,GACV,MAAM,uCAAuC,CAAA;AAC9C;;;;;;;;;;;GAWG;AACH,OAAO,EAAiB,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEtD,MAAM,aAAa,GAAG,sBAAsB,EAAE,CAAA;AAE9C,oGAAoG;AACpG,MAAM,UAAU,gBAAgB,CAAC,MAAgC;IAC/D,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AAC3B,CAAC;AAUD;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IACjD,MAAM,KAAK,GAAG,QAAQ,CAAe,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC,GAAG,EAAE,EAAE;QAC9F,IAAI,OAAO,KAAK,SAAS;YAAE,OAAM;QACjC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;QACvB,OAAO,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;IACzD,CAAC,CAAC,CAAA;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE;QAC1B,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,SAAS;QAChC,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,SAAS;KACrC,CAAC,CAAA;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW;IACzB,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,EAAE,CAAA;IAClC,OAAO,QAAQ,CAAqB,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;QAC3E,IAAI,MAAM,KAAK,SAAS;YAAE,OAAM;QAChC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAA;QACtB,OAAO,MAAM,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;IAC/D,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/mdx.js
CHANGED
|
@@ -6,7 +6,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
6
6
|
}
|
|
7
7
|
return path;
|
|
8
8
|
};
|
|
9
|
-
import { rewriteSsrImports } from "@nifrajs/web/plugins/kit";
|
|
9
|
+
import { normalizeFilePath, portablePath, rewriteSsrImports } from "@nifrajs/web/plugins/kit";
|
|
10
10
|
import { compile } from "svelte/compiler";
|
|
11
11
|
/**
|
|
12
12
|
* `@nifrajs/web-svelte/mdx` - compile `.mdx` routes/files to **Svelte** components. Svelte has no JSX
|
|
@@ -37,7 +37,7 @@ export function svelteMdxBunPlugin(generate) {
|
|
|
37
37
|
throw new Error("@nifrajs/web-svelte/mdx: compiling `.mdx` for Svelte needs the `mdsvex` package - install it (`bun add mdsvex`).");
|
|
38
38
|
}
|
|
39
39
|
build.onLoad({ filter: /\.mdx(\?|$)/ }, async (args) => {
|
|
40
|
-
const path = args.path
|
|
40
|
+
const path = normalizeFilePath(args.path);
|
|
41
41
|
// 1. Markdown/MDX → Svelte source (mdsvex). `extensions` must include `.mdx` or mdsvex skips the
|
|
42
42
|
// file (returns undefined - it only processes its configured extensions, default `.svx`).
|
|
43
43
|
const pre = await mdsvexCompile(await Bun.file(path).text(), {
|
|
@@ -53,9 +53,9 @@ export function svelteMdxBunPlugin(generate) {
|
|
|
53
53
|
css: "external",
|
|
54
54
|
});
|
|
55
55
|
if (generate === "dom" && css?.code) {
|
|
56
|
-
cssByPath.set(path, css.code);
|
|
56
|
+
cssByPath.set(portablePath(path), css.code);
|
|
57
57
|
return {
|
|
58
|
-
contents: `${js.code}\nimport ${JSON.stringify(path + STYLE_SUFFIX)}\n`,
|
|
58
|
+
contents: `${js.code}\nimport ${JSON.stringify(portablePath(path) + STYLE_SUFFIX)}\n`,
|
|
59
59
|
loader: "js",
|
|
60
60
|
};
|
|
61
61
|
}
|
|
@@ -66,7 +66,7 @@ export function svelteMdxBunPlugin(generate) {
|
|
|
66
66
|
namespace: STYLE_NS,
|
|
67
67
|
}));
|
|
68
68
|
build.onLoad({ filter: /.*/, namespace: STYLE_NS }, (args) => ({
|
|
69
|
-
contents: cssByPath.get(args.path.slice(0, -STYLE_SUFFIX.length)) ?? "",
|
|
69
|
+
contents: cssByPath.get(portablePath(args.path.slice(0, -STYLE_SUFFIX.length))) ?? "",
|
|
70
70
|
loader: "css",
|
|
71
71
|
}));
|
|
72
72
|
},
|
package/dist/mdx.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mdx.js","sourceRoot":"","sources":["../src/mdx.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"mdx.js","sourceRoot":"","sources":["../src/mdx.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAE7F,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+1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAsBpC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,CAEtF;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CA8DlE"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { devHotComponent, devServerCompile, rewriteSsrImports } from "@nifrajs/web/plugins/kit";
|
|
1
|
+
import { devHotComponent, devServerCompile, normalizeFilePath, portablePath, rewriteSsrImports, } from "@nifrajs/web/plugins/kit";
|
|
2
2
|
import { compile } from "svelte/compiler";
|
|
3
3
|
/**
|
|
4
4
|
* `@nifrajs/web-svelte/plugin` - the `.svelte` compiler Bun-plugin, in its OWN module (no `.svelte`
|
|
@@ -49,7 +49,7 @@ export function svelteBunPlugin(generate) {
|
|
|
49
49
|
// Match `.svelte`, tolerating a `?query` suffix (dev servers append one to bust Bun's import
|
|
50
50
|
// cache); strip it before reading the file off disk.
|
|
51
51
|
build.onLoad({ filter: /\.svelte(\?|$)/ }, async (args) => {
|
|
52
|
-
const path = args.path
|
|
52
|
+
const path = normalizeFilePath(args.path);
|
|
53
53
|
const source = await Bun.file(path).text();
|
|
54
54
|
// Per compile, not per registration: the CLI registers the SSR plugin before the dev server
|
|
55
55
|
// exists, and the flag is set by the dev server.
|
|
@@ -82,10 +82,10 @@ export function svelteBunPlugin(generate) {
|
|
|
82
82
|
hmr: dev && generate === "dom" && devHotComponent(path),
|
|
83
83
|
});
|
|
84
84
|
if (generate === "dom" && css?.code) {
|
|
85
|
-
cssByPath.set(path, css.code);
|
|
85
|
+
cssByPath.set(portablePath(path), css.code);
|
|
86
86
|
// Import the virtual style module so the bundler pulls the scoped CSS into the app stylesheet.
|
|
87
87
|
return {
|
|
88
|
-
contents: `${js.code}\nimport ${JSON.stringify(path + STYLE_SUFFIX)}\n`,
|
|
88
|
+
contents: `${js.code}\nimport ${JSON.stringify(portablePath(path) + STYLE_SUFFIX)}\n`,
|
|
89
89
|
loader: "js",
|
|
90
90
|
};
|
|
91
91
|
}
|
|
@@ -97,7 +97,7 @@ export function svelteBunPlugin(generate) {
|
|
|
97
97
|
namespace: STYLE_NS,
|
|
98
98
|
}));
|
|
99
99
|
build.onLoad({ filter: /.*/, namespace: STYLE_NS }, (args) => ({
|
|
100
|
-
contents: cssByPath.get(args.path.slice(0, -STYLE_SUFFIX.length)) ?? "",
|
|
100
|
+
contents: cssByPath.get(portablePath(args.path.slice(0, -STYLE_SUFFIX.length))) ?? "",
|
|
101
101
|
loader: "css",
|
|
102
102
|
}));
|
|
103
103
|
},
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,GAClB,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAEzC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,YAAY,GAAG,aAAa,CAAA;AAClC,MAAM,QAAQ,GAAG,kBAAkB,CAAA;AAEnC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAA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sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAe,UAAU,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAe,UAAU,EAAE,MAAM,cAAc,CAAA;AAMxE;;;;;;;;;;GAUG;AACH,OAAO,EAAE,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAEtD,wGAAwG;AACxG,wBAAgB,cAAc,IAAI,IAAI,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAEvE;AAED,gFAAgF;AAChF,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG;IACpD,6CAA6C;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAA;CACnC,CAAA;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAa7E"}
|
package/dist/query.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// server, which Vite's dev server evaluates rather than tree-shakes.
|
|
3
|
-
import { createQueryClient } from "@nifrajs/web/client";
|
|
1
|
+
import { createNoClientRefetch, getQueryClientSingleton, IDLE_QUERY_STATE, } from "@nifrajs/web/internal/query-runtime";
|
|
4
2
|
/**
|
|
5
3
|
* `@nifrajs/web-svelte/query` - Svelte bindings for the keyed query-cache, as **Svelte stores** (plain
|
|
6
4
|
* `.ts`). `useQuery(key, fn)` returns a `Readable<QueryState<T>>` augmented with `refetch` - read it
|
|
@@ -13,33 +11,17 @@ import { createQueryClient } from "@nifrajs/web/client";
|
|
|
13
11
|
* SSR data source). The first client render uses the same idle snapshot, so no mismatch.
|
|
14
12
|
*/
|
|
15
13
|
import { readable } from "svelte/store";
|
|
16
|
-
let client;
|
|
17
|
-
function getClient() {
|
|
18
|
-
if (typeof window === "undefined")
|
|
19
|
-
return undefined; // SSR → no client (queries render idle)
|
|
20
|
-
if (client === undefined)
|
|
21
|
-
client = createQueryClient({ now: () => Date.now() });
|
|
22
|
-
return client;
|
|
23
|
-
}
|
|
24
14
|
/** Access the query client to imperatively `invalidateQueries(keyOrPrefix)` (e.g. after a mutation). */
|
|
25
15
|
export function useQueryClient() {
|
|
26
|
-
return
|
|
16
|
+
return getQueryClientSingleton() ?? { invalidateQueries: () => { } };
|
|
27
17
|
}
|
|
28
|
-
// Stable idle snapshot for the server / pre-fetch render.
|
|
29
|
-
const IDLE = Object.freeze({
|
|
30
|
-
status: "pending",
|
|
31
|
-
data: undefined,
|
|
32
|
-
error: undefined,
|
|
33
|
-
isFetching: false,
|
|
34
|
-
updatedAt: Number.NEGATIVE_INFINITY,
|
|
35
|
-
});
|
|
36
18
|
/**
|
|
37
19
|
* Subscribe to the keyed query for `key`, fetched via `fn`. Returns a store of `{ status, data, error,
|
|
38
20
|
* isFetching, updatedAt }` augmented with `refetch`. Fetches on mount (first `$`-subscription); SSR-idle.
|
|
39
21
|
*/
|
|
40
22
|
export function useQuery(key, fn) {
|
|
41
|
-
const handle =
|
|
42
|
-
const store = readable(handle ? handle.snapshot() :
|
|
23
|
+
const handle = getQueryClientSingleton()?.query(key, fn);
|
|
24
|
+
const store = readable(handle ? handle.snapshot() : IDLE_QUERY_STATE, (set) => {
|
|
43
25
|
if (handle === undefined)
|
|
44
26
|
return;
|
|
45
27
|
set(handle.snapshot());
|
|
@@ -49,9 +31,7 @@ export function useQuery(key, fn) {
|
|
|
49
31
|
});
|
|
50
32
|
const refetch = handle
|
|
51
33
|
? handle.refetch
|
|
52
|
-
: (
|
|
53
|
-
throw new Error("[nifra/web-svelte] useQuery.refetch called with no query client (server?)");
|
|
54
|
-
});
|
|
34
|
+
: createNoClientRefetch("[nifra/web-svelte]", "useQuery.refetch");
|
|
55
35
|
return Object.assign(store, { refetch });
|
|
56
36
|
}
|
|
57
37
|
//# sourceMappingURL=query.js.map
|
package/dist/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,qCAAqC,CAAA;AAC5C;;;;;;;;;;GAUG;AACH,OAAO,EAAiB,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEtD,wGAAwG;AACxG,MAAM,UAAU,cAAc;IAC5B,OAAO,uBAAuB,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAA;AACrE,CAAC;AAQD;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAI,GAAY,EAAE,EAAoB;IAC5D,MAAM,MAAM,GAA+B,uBAAuB,EAAE,EAAE,KAAK,CAAI,GAAG,EAAE,EAAE,CAAC,CAAA;IACvF,MAAM,KAAK,GAAG,QAAQ,CAAgB,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC,GAAG,EAAE,EAAE;QAC3F,IAAI,MAAM,KAAK,SAAS;YAAE,OAAM;QAChC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAA;QACtB,MAAM,WAAW,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;QAClE,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA,CAAC,iDAAiD;QAChF,OAAO,WAAW,CAAA;IACpB,CAAC,CAAC,CAAA;IACF,MAAM,OAAO,GAAG,MAAM;QACpB,CAAC,CAAC,MAAM,CAAC,OAAO;QAChB,CAAC,CAAC,qBAAqB,CAAI,oBAAoB,EAAE,kBAAkB,CAAC,CAAA;IACtE,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;AAC1C,CAAC"}
|
package/dist/svg.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@nifrajs/web-svelte/svg` - the Svelte build of the SVG-as-component plugin. `import Icon from
|
|
3
|
+
* "./icon.svg?component"`, then `<Icon class="w-6 h-6" />`, props spread onto the root `<svg>`.
|
|
4
|
+
*
|
|
5
|
+
* Svelte markup accepts SVG almost verbatim (`class`, hyphenated attributes, an inline `style` string
|
|
6
|
+
* all work as-is), so - unlike the JSX adapters - no attribute rewriting is needed: the raw SVG is
|
|
7
|
+
* wrapped in a Svelte 5 component that spreads its props onto the root element, then compiled with the
|
|
8
|
+
* project's `svelte` compiler. Pass `"dom"` for the client bundle and preload `"ssr"` for the server;
|
|
9
|
+
* a plain `import "./icon.svg"` (asset URL) is untouched - only `?component` matches.
|
|
10
|
+
*/
|
|
1
11
|
import type { BunPlugin } from "bun";
|
|
2
12
|
/** Wrap raw SVG XML in a Svelte 5 component: strip XML noise, spread props onto the root `<svg>`. */
|
|
3
13
|
export declare function svgToSvelte(xml: string): string;
|
package/dist/svg.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAGpC,qGAAqG;AACrG,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED;wBACwB;AACxB,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CAe9E"}
|
package/dist/svg.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* project's `svelte` compiler. Pass `"dom"` for the client bundle and preload `"ssr"` for the server;
|
|
9
9
|
* a plain `import "./icon.svg"` (asset URL) is untouched - only `?component` matches.
|
|
10
10
|
*/
|
|
11
|
+
import { normalizeFilePath } from "@nifrajs/web/plugins/kit";
|
|
11
12
|
import { SVG_COMPONENT_FILTER, stripSvgPreamble } from "@nifrajs/web/plugins/svg";
|
|
12
13
|
import { compile } from "svelte/compiler";
|
|
13
14
|
/** Wrap raw SVG XML in a Svelte 5 component: strip XML noise, spread props onto the root `<svg>`. */
|
|
@@ -24,7 +25,7 @@ export function svelteSvgComponentBunPlugin(generate) {
|
|
|
24
25
|
name: `nifra-svelte-svg-${generate}`,
|
|
25
26
|
setup(build) {
|
|
26
27
|
build.onLoad({ filter: SVG_COMPONENT_FILTER }, async (args) => {
|
|
27
|
-
const path = args.path
|
|
28
|
+
const path = normalizeFilePath(args.path);
|
|
28
29
|
const xml = await Bun.file(path).text();
|
|
29
30
|
const { js } = compile(svgToSvelte(xml), {
|
|
30
31
|
generate: generate === "ssr" ? "server" : "client",
|
package/dist/svg.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svg.js","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"svg.js","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAEjF,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAEzC,qGAAqG;AACrG,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,MAAM,OAAO,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAA;IACrC,+FAA+F;IAC/F,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAA;IACxE,OAAO,4CAA4C,UAAU,IAAI,CAAA;AACnE,CAAC;AAED;wBACwB;AACxB,MAAM,UAAU,2BAA2B,CAAC,QAAuB;IACjE,OAAO;QACL,IAAI,EAAE,oBAAoB,QAAQ,EAAE;QACpC,KAAK,CAAC,KAAK;YACT,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,oBAAoB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;gBAC5D,MAAM,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACzC,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAA;gBACvC,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE;oBACvC,QAAQ,EAAE,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;oBAClD,QAAQ,EAAE,IAAI;iBACf,CAAC,CAAA;gBACF,OAAO,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;YAC5C,CAAC,CAAC,CAAA;QACJ,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nifrajs/web-svelte",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Svelte 5 render adapter for @nifrajs/web - SSR + hydration + the .svelte compiler Bun-plugin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -100,10 +100,10 @@
|
|
|
100
100
|
"access": "public"
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@nifrajs/core": "2.
|
|
104
|
-
"@nifrajs/i18n": "2.
|
|
105
|
-
"@nifrajs/image": "2.
|
|
106
|
-
"@nifrajs/web": "2.
|
|
103
|
+
"@nifrajs/core": "3.2.0",
|
|
104
|
+
"@nifrajs/i18n": "3.2.0",
|
|
105
|
+
"@nifrajs/image": "3.2.0",
|
|
106
|
+
"@nifrajs/web": "3.2.0"
|
|
107
107
|
},
|
|
108
108
|
"peerDependencies": {
|
|
109
109
|
"mdsvex": "^0.12",
|
package/src/Chain.svelte
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
</svelte:boundary>
|
|
38
38
|
{:else}
|
|
39
39
|
{@const Layout = chain[0]}
|
|
40
|
-
<Layout data={layoutData?.[0] ?? null}>
|
|
40
|
+
<Layout data={layoutData?.[0] ?? null} boundaries={props.boundaries}>
|
|
41
41
|
{#snippet children()}
|
|
42
42
|
<Self chain={chain.slice(1)} {props} layoutData={layoutData?.slice(1)} />
|
|
43
43
|
{/snippet}
|
package/src/Router.svelte
CHANGED
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
pending: snapshot.pending,
|
|
38
38
|
search: searchOfChain(searchSchemas?.[snapshot.routeId] ?? [], q === -1 ? "" : snapshot.path.slice(q)),
|
|
39
39
|
...(snapshot.submission ? { submission: snapshot.submission } : {}),
|
|
40
|
+
...(snapshot.boundaries !== undefined ? { boundaries: snapshot.boundaries } : {}),
|
|
40
41
|
}
|
|
41
42
|
})
|
|
42
43
|
</script>
|
package/src/fetcher.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { ClientRouter, Fetcher, FetcherState } from "@nifrajs/web"
|
|
2
|
+
import {
|
|
3
|
+
createMountedRouterRef,
|
|
4
|
+
IDLE_FETCHER_STATE,
|
|
5
|
+
noopAsync,
|
|
6
|
+
} from "@nifrajs/web/internal/fetcher-runtime"
|
|
2
7
|
/**
|
|
3
8
|
* `@nifrajs/web-svelte/fetcher` - Svelte bindings for concurrent fetchers, as **Svelte stores** (plain
|
|
4
9
|
* `.ts`, no runes/compiler needed). `useFetcher(key)` returns a `Readable<FetcherState>` augmented with
|
|
@@ -13,18 +18,13 @@ import type { ClientRouter, Fetcher, FetcherState } from "@nifrajs/web"
|
|
|
13
18
|
*/
|
|
14
19
|
import { type Readable, readable } from "svelte/store"
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
// page, and fetchers never exist on the server. Shared with `client.ts`'s `mountRouter`.
|
|
18
|
-
let mountedRouter: ClientRouter | undefined
|
|
21
|
+
const mountedRouter = createMountedRouterRef()
|
|
19
22
|
|
|
20
23
|
/** Register (or clear) the router that owns fetchers - called by `mountRouter`. Not for app use. */
|
|
21
24
|
export function setMountedRouter(router: ClientRouter | undefined): void {
|
|
22
|
-
mountedRouter
|
|
25
|
+
mountedRouter.set(router)
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
const IDLE: FetcherState = { pending: false, data: undefined }
|
|
26
|
-
const noopAsync = async (): Promise<void> => {}
|
|
27
|
-
|
|
28
28
|
/** A fetcher store: a `Readable<FetcherState>` (read via `$`) plus imperative `load`/`submit`. */
|
|
29
29
|
export type FetcherStore = Readable<FetcherState> & {
|
|
30
30
|
/** Load a route path's loader data into this fetcher (concurrent; doesn't touch the active view). */
|
|
@@ -39,8 +39,8 @@ export type FetcherStore = Readable<FetcherState> & {
|
|
|
39
39
|
* Multiple `useFetcher` calls with different keys run concurrently without disturbing the active route.
|
|
40
40
|
*/
|
|
41
41
|
export function useFetcher(key: string): FetcherStore {
|
|
42
|
-
const fetcher = mountedRouter?.fetcher(key)
|
|
43
|
-
const store = readable<FetcherState>(fetcher ? fetcher.snapshot() :
|
|
42
|
+
const fetcher = mountedRouter.get()?.fetcher(key)
|
|
43
|
+
const store = readable<FetcherState>(fetcher ? fetcher.snapshot() : IDLE_FETCHER_STATE, (set) => {
|
|
44
44
|
if (fetcher === undefined) return
|
|
45
45
|
set(fetcher.snapshot())
|
|
46
46
|
return fetcher.subscribe(() => set(fetcher.snapshot()))
|
|
@@ -57,7 +57,7 @@ export function useFetcher(key: string): FetcherStore {
|
|
|
57
57
|
* new one is created.
|
|
58
58
|
*/
|
|
59
59
|
export function useFetchers(): Readable<readonly Fetcher[]> {
|
|
60
|
-
const router = mountedRouter
|
|
60
|
+
const router = mountedRouter.get()
|
|
61
61
|
return readable<readonly Fetcher[]>(router ? router.fetchers() : [], (set) => {
|
|
62
62
|
if (router === undefined) return
|
|
63
63
|
set(router.fetchers())
|
package/src/mdx.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rewriteSsrImports } from "@nifrajs/web/plugins/kit"
|
|
1
|
+
import { normalizeFilePath, portablePath, rewriteSsrImports } from "@nifrajs/web/plugins/kit"
|
|
2
2
|
import type { BunPlugin } from "bun"
|
|
3
3
|
import { compile } from "svelte/compiler"
|
|
4
4
|
|
|
@@ -37,7 +37,7 @@ export function svelteMdxBunPlugin(generate: "dom" | "ssr"): BunPlugin {
|
|
|
37
37
|
)
|
|
38
38
|
}
|
|
39
39
|
build.onLoad({ filter: /\.mdx(\?|$)/ }, async (args) => {
|
|
40
|
-
const path = args.path
|
|
40
|
+
const path = normalizeFilePath(args.path)
|
|
41
41
|
// 1. Markdown/MDX → Svelte source (mdsvex). `extensions` must include `.mdx` or mdsvex skips the
|
|
42
42
|
// file (returns undefined - it only processes its configured extensions, default `.svx`).
|
|
43
43
|
const pre = await mdsvexCompile(await Bun.file(path).text(), {
|
|
@@ -52,9 +52,9 @@ export function svelteMdxBunPlugin(generate: "dom" | "ssr"): BunPlugin {
|
|
|
52
52
|
css: "external",
|
|
53
53
|
})
|
|
54
54
|
if (generate === "dom" && css?.code) {
|
|
55
|
-
cssByPath.set(path, css.code)
|
|
55
|
+
cssByPath.set(portablePath(path), css.code)
|
|
56
56
|
return {
|
|
57
|
-
contents: `${js.code}\nimport ${JSON.stringify(path + STYLE_SUFFIX)}\n`,
|
|
57
|
+
contents: `${js.code}\nimport ${JSON.stringify(portablePath(path) + STYLE_SUFFIX)}\n`,
|
|
58
58
|
loader: "js",
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -65,7 +65,7 @@ export function svelteMdxBunPlugin(generate: "dom" | "ssr"): BunPlugin {
|
|
|
65
65
|
namespace: STYLE_NS,
|
|
66
66
|
}))
|
|
67
67
|
build.onLoad({ filter: /.*/, namespace: STYLE_NS }, (args) => ({
|
|
68
|
-
contents: cssByPath.get(args.path.slice(0, -STYLE_SUFFIX.length)) ?? "",
|
|
68
|
+
contents: cssByPath.get(portablePath(args.path.slice(0, -STYLE_SUFFIX.length))) ?? "",
|
|
69
69
|
loader: "css",
|
|
70
70
|
}))
|
|
71
71
|
},
|
package/src/plugin.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
devHotComponent,
|
|
3
|
+
devServerCompile,
|
|
4
|
+
normalizeFilePath,
|
|
5
|
+
portablePath,
|
|
6
|
+
rewriteSsrImports,
|
|
7
|
+
} from "@nifrajs/web/plugins/kit"
|
|
2
8
|
import type { BunPlugin } from "bun"
|
|
3
9
|
import { compile } from "svelte/compiler"
|
|
4
10
|
|
|
@@ -53,7 +59,7 @@ export function svelteBunPlugin(generate: "dom" | "ssr"): BunPlugin {
|
|
|
53
59
|
// Match `.svelte`, tolerating a `?query` suffix (dev servers append one to bust Bun's import
|
|
54
60
|
// cache); strip it before reading the file off disk.
|
|
55
61
|
build.onLoad({ filter: /\.svelte(\?|$)/ }, async (args) => {
|
|
56
|
-
const path = args.path
|
|
62
|
+
const path = normalizeFilePath(args.path)
|
|
57
63
|
const source = await Bun.file(path).text()
|
|
58
64
|
// Per compile, not per registration: the CLI registers the SSR plugin before the dev server
|
|
59
65
|
// exists, and the flag is set by the dev server.
|
|
@@ -86,10 +92,10 @@ export function svelteBunPlugin(generate: "dom" | "ssr"): BunPlugin {
|
|
|
86
92
|
hmr: dev && generate === "dom" && devHotComponent(path),
|
|
87
93
|
})
|
|
88
94
|
if (generate === "dom" && css?.code) {
|
|
89
|
-
cssByPath.set(path, css.code)
|
|
95
|
+
cssByPath.set(portablePath(path), css.code)
|
|
90
96
|
// Import the virtual style module so the bundler pulls the scoped CSS into the app stylesheet.
|
|
91
97
|
return {
|
|
92
|
-
contents: `${js.code}\nimport ${JSON.stringify(path + STYLE_SUFFIX)}\n`,
|
|
98
|
+
contents: `${js.code}\nimport ${JSON.stringify(portablePath(path) + STYLE_SUFFIX)}\n`,
|
|
93
99
|
loader: "js",
|
|
94
100
|
}
|
|
95
101
|
}
|
|
@@ -101,7 +107,7 @@ export function svelteBunPlugin(generate: "dom" | "ssr"): BunPlugin {
|
|
|
101
107
|
namespace: STYLE_NS,
|
|
102
108
|
}))
|
|
103
109
|
build.onLoad({ filter: /.*/, namespace: STYLE_NS }, (args) => ({
|
|
104
|
-
contents: cssByPath.get(args.path.slice(0, -STYLE_SUFFIX.length)) ?? "",
|
|
110
|
+
contents: cssByPath.get(portablePath(args.path.slice(0, -STYLE_SUFFIX.length))) ?? "",
|
|
105
111
|
loader: "css",
|
|
106
112
|
}))
|
|
107
113
|
},
|
package/src/query.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { QueryClient, QueryHandle, QueryState } from "@nifrajs/web"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import {
|
|
3
|
+
createNoClientRefetch,
|
|
4
|
+
getQueryClientSingleton,
|
|
5
|
+
IDLE_QUERY_STATE,
|
|
6
|
+
} from "@nifrajs/web/internal/query-runtime"
|
|
5
7
|
/**
|
|
6
8
|
* `@nifrajs/web-svelte/query` - Svelte bindings for the keyed query-cache, as **Svelte stores** (plain
|
|
7
9
|
* `.ts`). `useQuery(key, fn)` returns a `Readable<QueryState<T>>` augmented with `refetch` - read it
|
|
@@ -15,27 +17,11 @@ import { createQueryClient } from "@nifrajs/web/client"
|
|
|
15
17
|
*/
|
|
16
18
|
import { type Readable, readable } from "svelte/store"
|
|
17
19
|
|
|
18
|
-
let client: QueryClient | undefined
|
|
19
|
-
function getClient(): QueryClient | undefined {
|
|
20
|
-
if (typeof window === "undefined") return undefined // SSR → no client (queries render idle)
|
|
21
|
-
if (client === undefined) client = createQueryClient({ now: () => Date.now() })
|
|
22
|
-
return client
|
|
23
|
-
}
|
|
24
|
-
|
|
25
20
|
/** Access the query client to imperatively `invalidateQueries(keyOrPrefix)` (e.g. after a mutation). */
|
|
26
21
|
export function useQueryClient(): Pick<QueryClient, "invalidateQueries"> {
|
|
27
|
-
return
|
|
22
|
+
return getQueryClientSingleton() ?? { invalidateQueries: () => {} }
|
|
28
23
|
}
|
|
29
24
|
|
|
30
|
-
// Stable idle snapshot for the server / pre-fetch render.
|
|
31
|
-
const IDLE: QueryState<never> = Object.freeze({
|
|
32
|
-
status: "pending",
|
|
33
|
-
data: undefined,
|
|
34
|
-
error: undefined,
|
|
35
|
-
isFetching: false,
|
|
36
|
-
updatedAt: Number.NEGATIVE_INFINITY,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
25
|
/** A query store: a `Readable<QueryState<T>>` (read via `$`) plus `refetch`. */
|
|
40
26
|
export type QueryStore<T> = Readable<QueryState<T>> & {
|
|
41
27
|
/** Force a refetch (ignores `staleTime`). */
|
|
@@ -47,8 +33,8 @@ export type QueryStore<T> = Readable<QueryState<T>> & {
|
|
|
47
33
|
* isFetching, updatedAt }` augmented with `refetch`. Fetches on mount (first `$`-subscription); SSR-idle.
|
|
48
34
|
*/
|
|
49
35
|
export function useQuery<T>(key: unknown, fn: () => Promise<T>): QueryStore<T> {
|
|
50
|
-
const handle: QueryHandle<T> | undefined =
|
|
51
|
-
const store = readable<QueryState<T>>(handle ? handle.snapshot() :
|
|
36
|
+
const handle: QueryHandle<T> | undefined = getQueryClientSingleton()?.query<T>(key, fn)
|
|
37
|
+
const store = readable<QueryState<T>>(handle ? handle.snapshot() : IDLE_QUERY_STATE, (set) => {
|
|
52
38
|
if (handle === undefined) return
|
|
53
39
|
set(handle.snapshot())
|
|
54
40
|
const unsubscribe = handle.subscribe(() => set(handle.snapshot()))
|
|
@@ -57,8 +43,6 @@ export function useQuery<T>(key: unknown, fn: () => Promise<T>): QueryStore<T> {
|
|
|
57
43
|
})
|
|
58
44
|
const refetch = handle
|
|
59
45
|
? handle.refetch
|
|
60
|
-
: (
|
|
61
|
-
throw new Error("[nifra/web-svelte] useQuery.refetch called with no query client (server?)")
|
|
62
|
-
}) as () => Promise<T>)
|
|
46
|
+
: createNoClientRefetch<T>("[nifra/web-svelte]", "useQuery.refetch")
|
|
63
47
|
return Object.assign(store, { refetch })
|
|
64
48
|
}
|
package/src/svg.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* project's `svelte` compiler. Pass `"dom"` for the client bundle and preload `"ssr"` for the server;
|
|
9
9
|
* a plain `import "./icon.svg"` (asset URL) is untouched - only `?component` matches.
|
|
10
10
|
*/
|
|
11
|
+
|
|
12
|
+
import { normalizeFilePath } from "@nifrajs/web/plugins/kit"
|
|
11
13
|
import { SVG_COMPONENT_FILTER, stripSvgPreamble } from "@nifrajs/web/plugins/svg"
|
|
12
14
|
import type { BunPlugin } from "bun"
|
|
13
15
|
import { compile } from "svelte/compiler"
|
|
@@ -27,7 +29,7 @@ export function svelteSvgComponentBunPlugin(generate: "dom" | "ssr"): BunPlugin
|
|
|
27
29
|
name: `nifra-svelte-svg-${generate}`,
|
|
28
30
|
setup(build) {
|
|
29
31
|
build.onLoad({ filter: SVG_COMPONENT_FILTER }, async (args) => {
|
|
30
|
-
const path = args.path
|
|
32
|
+
const path = normalizeFilePath(args.path)
|
|
31
33
|
const xml = await Bun.file(path).text()
|
|
32
34
|
const { js } = compile(svgToSvelte(xml), {
|
|
33
35
|
generate: generate === "ssr" ? "server" : "client",
|