@primate/svelte 0.24.0 → 0.26.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/lib/index.d.ts +0 -1
- package/lib/private/client/form.d.ts +7 -2
- package/lib/private/client/form.js +1 -0
- package/lib/private/client/root.d.ts +7 -8
- package/lib/private/context-name.d.ts +1 -1
- package/lib/private/create-root.d.ts +1 -1
- package/lib/private/create-root.js +9 -28
- package/lib/private/i18n.d.ts +18 -0
- package/lib/private/i18n.js +46 -0
- package/lib/public/browser.d.ts +5 -2
- package/lib/public/browser.js +7 -2
- package/lib/public/client.d.ts +2 -0
- package/lib/public/client.js +2 -0
- package/lib/public/i18n.d.ts +2 -0
- package/lib/public/i18n.js +2 -0
- package/package.json +14 -7
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ClientMethod, FormInit } from "@primate/core/client";
|
|
2
2
|
import type { Dict } from "@rcompat/type";
|
|
3
3
|
import type { Readable } from "svelte/store";
|
|
4
|
-
type SvelteFormView<Values extends Dict> = {
|
|
4
|
+
type SvelteFormView<Values extends Dict, Result = unknown> = {
|
|
5
5
|
id: string;
|
|
6
6
|
submitting: boolean;
|
|
7
7
|
submitted: boolean;
|
|
8
|
+
result: Result | null;
|
|
8
9
|
submit: (event?: Event) => Promise<void>;
|
|
9
10
|
errors: readonly string[];
|
|
10
11
|
field: <K extends keyof Values & string>(name: K) => {
|
|
@@ -17,7 +18,11 @@ type SvelteFormView<Values extends Dict> = {
|
|
|
17
18
|
type Initial<Values extends Dict> = FormInit & {
|
|
18
19
|
initial?: Values;
|
|
19
20
|
};
|
|
20
|
-
declare function form<Values extends Dict>(action: ClientMethod<Values
|
|
21
|
+
declare function form<Values extends Dict, Path extends Dict, Result = unknown>(action: ClientMethod<Values, Path> & {
|
|
22
|
+
_result?: Result;
|
|
23
|
+
}, init?: Initial<Values> & {
|
|
24
|
+
path?: Path;
|
|
25
|
+
}): Readable<SvelteFormView<Values, Result>>;
|
|
21
26
|
declare function form<Values extends Dict>(init: Initial<Values>): Readable<SvelteFormView<Values>>;
|
|
22
27
|
declare function form(init?: FormInit): Readable<SvelteFormView<Dict>>;
|
|
23
28
|
export default form;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type Data from "#client/Data";
|
|
2
2
|
import type { Dict } from "@rcompat/type";
|
|
3
|
-
import { hydrate, mount } from "svelte";
|
|
4
3
|
import type { Component } from "svelte";
|
|
5
|
-
|
|
4
|
+
import { hydrate, mount } from "svelte";
|
|
6
5
|
export type RootProps = {
|
|
7
|
-
views:
|
|
6
|
+
views: Component<any>[];
|
|
8
7
|
props: Dict[];
|
|
9
8
|
request: Data["request"] & {
|
|
10
9
|
url: URL;
|
|
@@ -15,12 +14,12 @@ declare function toProps(data: Data): {
|
|
|
15
14
|
views: Component<{}, {}, string>[];
|
|
16
15
|
props: Dict[];
|
|
17
16
|
request: {
|
|
18
|
-
url: URL;
|
|
19
17
|
context: Dict;
|
|
20
|
-
cookies:
|
|
21
|
-
headers:
|
|
22
|
-
path:
|
|
23
|
-
query:
|
|
18
|
+
cookies: import("@rcompat/type").PartialDict<string>;
|
|
19
|
+
headers: import("@rcompat/type").PartialDict<string>;
|
|
20
|
+
path: import("@rcompat/type").PartialDict<string>;
|
|
21
|
+
query: import("@rcompat/type").PartialDict<string>;
|
|
22
|
+
url: URL;
|
|
24
23
|
};
|
|
25
24
|
update: () => undefined;
|
|
26
25
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export default (depth
|
|
1
|
+
export default (depth) => {
|
|
2
2
|
const n = depth;
|
|
3
3
|
const body = Array.from({ length: n }, (_, i) => i - 1)
|
|
4
4
|
.reduceRight((child, _, i) => `
|
|
5
|
-
{#if p.views[${i + 1}]}
|
|
5
|
+
{#if p.views[${i + 1}] !== undefined}
|
|
6
6
|
<svelte:component this={p.views[${i}]} {...p.props[${i}]}>
|
|
7
7
|
${child}
|
|
8
8
|
</svelte:component>
|
|
@@ -10,43 +10,24 @@ export default (depth, i18n_active) => {
|
|
|
10
10
|
<svelte:component this={p.views[${i}]} {...p.props[${i}]}/>
|
|
11
11
|
{/if}
|
|
12
12
|
`, `<svelte:component this={p.views[${n}]} {...p.props[${n}]}/>`);
|
|
13
|
-
const i18nImports = i18n_active
|
|
14
|
-
? `
|
|
15
|
-
import t from "#i18n";
|
|
16
|
-
import sInternal from "primate/s/internal";
|
|
17
|
-
import { onMount } from "svelte";`
|
|
18
|
-
: "";
|
|
19
|
-
const i18nInit = i18n_active
|
|
20
|
-
? `
|
|
21
|
-
const server = p.request.context.i18n.locale;
|
|
22
|
-
if (server !== undefined && server !== t.locale.get()) {
|
|
23
|
-
t[sInternal].init(server);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// after hydration: in storage modes, flip to saved locale once
|
|
27
|
-
onMount(() => { t[sInternal].restore(); });`
|
|
28
|
-
: "";
|
|
29
13
|
return `
|
|
30
14
|
<script>
|
|
31
15
|
import { afterUpdate, setContext } from "svelte";
|
|
32
16
|
import context_name from "@primate/svelte/context-name";
|
|
33
17
|
import { request } from "@primate/svelte/app";
|
|
34
|
-
${i18nImports}
|
|
35
18
|
|
|
36
19
|
export let p;
|
|
37
20
|
|
|
38
|
-
setContext(context_name, p.
|
|
21
|
+
setContext(context_name, p.context);
|
|
39
22
|
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
function sync(next) {
|
|
24
|
+
const { context, path, ...public_request } = next.request;
|
|
25
|
+
request.set(public_request);
|
|
26
|
+
}
|
|
42
27
|
|
|
43
|
-
|
|
28
|
+
sync(p);
|
|
44
29
|
|
|
45
|
-
afterUpdate(() => {
|
|
46
|
-
const { context, path, ...public_request } = p.request;
|
|
47
|
-
request.set(public_request);
|
|
48
|
-
p.update?.();
|
|
49
|
-
});
|
|
30
|
+
afterUpdate(() => { sync(p); });
|
|
50
31
|
</script>
|
|
51
32
|
|
|
52
33
|
${body}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BridgedTranslator, HeadlessTranslator, LocaleOf, RestoreRequest, SetLocaleOf } from "@primate/core/i18n";
|
|
2
|
+
type Unsubscribe = () => void;
|
|
3
|
+
type Subscriber<T> = (value: T) => void;
|
|
4
|
+
type I18NStore<T extends HeadlessTranslator> = {
|
|
5
|
+
subscribe(run: Subscriber<BridgedTranslator<T>>): Unsubscribe;
|
|
6
|
+
defaultLocale: T["defaultLocale"];
|
|
7
|
+
locales: T["locales"];
|
|
8
|
+
catalogs: T["catalogs"];
|
|
9
|
+
currency: T["currency"];
|
|
10
|
+
locale: {
|
|
11
|
+
get(): LocaleOf<T>;
|
|
12
|
+
set(locale: SetLocaleOf<T>): void;
|
|
13
|
+
};
|
|
14
|
+
restore(request?: RestoreRequest): void;
|
|
15
|
+
};
|
|
16
|
+
export default function i18n<const T extends HeadlessTranslator>(source: T): I18NStore<T>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=i18n.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import request from "#request/store";
|
|
2
|
+
export default function i18n(source) {
|
|
3
|
+
const subscribers = new Set();
|
|
4
|
+
const notify = () => {
|
|
5
|
+
for (const subscriber of subscribers)
|
|
6
|
+
subscriber(value);
|
|
7
|
+
};
|
|
8
|
+
const get = () => source.locale.get();
|
|
9
|
+
const set = (locale) => {
|
|
10
|
+
const before = source.locale.get();
|
|
11
|
+
source.locale.set(locale);
|
|
12
|
+
if (source.locale.get() !== before)
|
|
13
|
+
notify();
|
|
14
|
+
};
|
|
15
|
+
const restore = (next) => {
|
|
16
|
+
const before = source.locale.get();
|
|
17
|
+
source.restore(next);
|
|
18
|
+
if (source.locale.get() !== before)
|
|
19
|
+
notify();
|
|
20
|
+
};
|
|
21
|
+
const value = ((...args) => {
|
|
22
|
+
return source(...args);
|
|
23
|
+
});
|
|
24
|
+
value.defaultLocale = source.defaultLocale;
|
|
25
|
+
value.locales = source.locales;
|
|
26
|
+
value.catalogs = source.catalogs;
|
|
27
|
+
value.currency = source.currency;
|
|
28
|
+
value.locale = { get, set };
|
|
29
|
+
value.restore = restore;
|
|
30
|
+
restore();
|
|
31
|
+
request.subscribe(next => { restore(next); });
|
|
32
|
+
return {
|
|
33
|
+
subscribe(run) {
|
|
34
|
+
subscribers.add(run);
|
|
35
|
+
run(value);
|
|
36
|
+
return () => { subscribers.delete(run); };
|
|
37
|
+
},
|
|
38
|
+
defaultLocale: source.defaultLocale,
|
|
39
|
+
locales: source.locales,
|
|
40
|
+
catalogs: source.catalogs,
|
|
41
|
+
currency: source.currency,
|
|
42
|
+
locale: { get, set },
|
|
43
|
+
restore,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=i18n.js.map
|
package/lib/public/browser.d.ts
CHANGED
package/lib/public/browser.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export default function svelte() {
|
|
2
|
+
return {
|
|
3
|
+
name: "svelte",
|
|
4
|
+
setup() { },
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export { default as app } from "#client/app";
|
|
3
8
|
//# sourceMappingURL=browser.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Svelte for Primate",
|
|
5
5
|
"homepage": "https://primate.run/docs/frontend/svelte",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
],
|
|
19
19
|
"types": "lib/index.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@rcompat/fs": "^0.
|
|
22
|
-
"esbuild": "^0.28.
|
|
23
|
-
"@primate/core": "^0.
|
|
21
|
+
"@rcompat/fs": "^0.35.1",
|
|
22
|
+
"esbuild": "^0.28.1",
|
|
23
|
+
"@primate/core": "^0.9.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@rcompat/type": "^0.
|
|
26
|
+
"@rcompat/type": "^0.18.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"svelte": "5",
|
|
30
|
-
"primate": "^0.
|
|
30
|
+
"primate": "^0.40.0"
|
|
31
31
|
},
|
|
32
32
|
"imports": {
|
|
33
33
|
"#*": {
|
|
@@ -38,12 +38,19 @@
|
|
|
38
38
|
"exports": {
|
|
39
39
|
".": {
|
|
40
40
|
"types": "./lib/index.d.ts",
|
|
41
|
+
"browser": {
|
|
42
|
+
"@primate/source": "./src/public/browser.ts",
|
|
43
|
+
"default": "./lib/public/browser.js"
|
|
44
|
+
},
|
|
41
45
|
"@primate/runtime": "./src/public/runtime.ts",
|
|
42
46
|
"@primate/source": "./src/public/default.ts",
|
|
43
|
-
"browser": "./lib/public/browser.js",
|
|
44
47
|
"runtime": "./lib/public/runtime.js",
|
|
45
48
|
"default": "./lib/public/default.js"
|
|
46
49
|
},
|
|
50
|
+
"./i18n": {
|
|
51
|
+
"@primate/source": "./src/public/i18n.ts",
|
|
52
|
+
"default": "./lib/public/i18n.js"
|
|
53
|
+
},
|
|
47
54
|
"./*": {
|
|
48
55
|
"@primate/source": "./src/public/*.ts",
|
|
49
56
|
"default": "./lib/public/*.js"
|