@primate/svelte 0.24.0 → 0.25.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 CHANGED
@@ -1,3 +1,2 @@
1
1
  import "./app.d.ts";
2
2
  export { default } from "#default";
3
- export { default as client } from "#client/index";
@@ -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>, init?: Initial<Values>): Readable<SvelteFormView<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;
@@ -21,6 +21,7 @@ function form(action_or_init, maybe_init) {
21
21
  id: snapshot.id,
22
22
  submitting: snapshot.submitting,
23
23
  submitted: snapshot.submitted,
24
+ result: snapshot.result,
24
25
  submit: controller.submit,
25
26
  errors: form_errors,
26
27
  field(name) {
@@ -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
- type ViewComponent = Component<any>;
4
+ import { hydrate, mount } from "svelte";
6
5
  export type RootProps = {
7
- views: ViewComponent[];
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: Dict<string>;
21
- headers: Dict<string>;
22
- path: Dict<string>;
23
- query: Dict<string>;
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,3 +1,3 @@
1
- declare const _default: "__PRMT__";
1
+ declare const _default = "__PRMT__";
2
2
  export default _default;
3
3
  //# sourceMappingURL=context-name.d.ts.map
@@ -1,3 +1,3 @@
1
- declare const _default: (depth: number, i18n_active: boolean) => string;
1
+ declare const _default: (depth: number) => string;
2
2
  export default _default;
3
3
  //# sourceMappingURL=create-root.d.ts.map
@@ -1,8 +1,8 @@
1
- export default (depth, i18n_active) => {
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.request.context);
21
+ setContext(context_name, p.context);
39
22
 
40
- const { context, path, ...public_request } = p.request;
41
- request.set(public_request);
23
+ function sync(next) {
24
+ const { context, path, ...public_request } = next.request;
25
+ request.set(public_request);
26
+ }
42
27
 
43
- ${i18nInit}
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
@@ -1,3 +1,6 @@
1
- export { default } from "#client/app";
2
- export { default as client } from "#client/index";
1
+ export default function svelte(): {
2
+ name: string;
3
+ setup(): void;
4
+ };
5
+ export { default as app } from "#client/app";
3
6
  //# sourceMappingURL=browser.d.ts.map
@@ -1,3 +1,8 @@
1
- export { default } from "#client/app";
2
- export { default as client } from "#client/index";
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
@@ -0,0 +1,2 @@
1
+ export { default } from "#client/index";
2
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { default } from "#client/index";
2
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,2 @@
1
+ export { default } from "#i18n";
2
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { default } from "#i18n";
2
+ //# sourceMappingURL=i18n.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/svelte",
3
- "version": "0.24.0",
3
+ "version": "0.25.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",
@@ -20,14 +20,14 @@
20
20
  "dependencies": {
21
21
  "@rcompat/fs": "^0.33.2",
22
22
  "esbuild": "^0.28.0",
23
- "@primate/core": "^0.7.0"
23
+ "@primate/core": "^0.8.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@rcompat/type": "^0.17.0"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "svelte": "5",
30
- "primate": "^0.38.0"
30
+ "primate": "^0.39.0"
31
31
  },
32
32
  "imports": {
33
33
  "#*": {
@@ -38,19 +38,26 @@
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"
50
57
  }
51
58
  },
52
59
  "scripts": {
53
- "build": "npm run clean && tsc && cp src/types/app.d.ts lib && cp src/types/index.d.ts lib",
60
+ "build": "npm run clean && tsgo && cp src/types/app.d.ts lib && cp src/types/index.d.ts lib",
54
61
  "clean": "rm -rf ./lib",
55
62
  "lint": "eslint ."
56
63
  }