@primate/solid 0.10.0 → 0.11.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,9 +1,9 @@
1
1
  import type Child from "#Head/ClientChild";
2
- declare const Head: {
3
- (props: {
4
- children: Child[];
5
- }): null;
6
- clear(data_value?: string): void;
7
- };
2
+ declare function Head(props: {
3
+ children: Child[];
4
+ }): null;
5
+ declare namespace Head {
6
+ var clear: (data_value?: string) => void;
7
+ }
8
8
  export default Head;
9
9
  //# sourceMappingURL=browser.d.ts.map
@@ -1,9 +1,9 @@
1
1
  import type Child from "#Head/ServerChild";
2
- declare const Head: {
3
- (props: {
4
- children: Child[];
5
- }): null;
6
- clear(data_value?: string): void;
7
- };
2
+ declare function Head(props: {
3
+ children: Child[];
4
+ }): null;
5
+ declare namespace Head {
6
+ var clear: (data_value?: string) => void;
7
+ }
8
8
  export default Head;
9
9
  //# sourceMappingURL=default.d.ts.map
@@ -1,8 +1,8 @@
1
- declare const Head: {
2
- (props: {
3
- children: any[];
4
- }): null;
5
- clear: (data_value?: string) => void;
6
- };
1
+ declare function Head(props: {
2
+ children: any[];
3
+ }): null;
4
+ declare namespace Head {
5
+ var clear: (data_value?: string) => void;
6
+ }
7
7
  export default Head;
8
8
  //# sourceMappingURL=Head.d.ts.map
@@ -1,9 +1,10 @@
1
1
  import type { ClientMethod, FormInit } from "@primate/core/client";
2
2
  import type { Dict } from "@rcompat/type";
3
- type FormView<Values extends Dict> = {
3
+ type FormView<Values extends Dict, Result = unknown> = {
4
4
  id: string;
5
5
  submitting: boolean;
6
6
  submitted: boolean;
7
+ result: Result | null;
7
8
  submit: (event?: Event) => Promise<void>;
8
9
  errors: string[];
9
10
  field: <K extends keyof Values & string>(name: K) => {
@@ -16,7 +17,11 @@ type FormView<Values extends Dict> = {
16
17
  type Initial<Values extends Dict> = FormInit & {
17
18
  initial?: Values;
18
19
  };
19
- declare function form<Values extends Dict>(action: ClientMethod<Values>, init?: Initial<Values>): FormView<Values>;
20
+ declare function form<Values extends Dict, Path extends Dict, Result = unknown>(action: ClientMethod<Values, Path> & {
21
+ _result?: Result;
22
+ }, init?: Initial<Values> & {
23
+ path?: Path;
24
+ }): FormView<Values, Result>;
20
25
  declare function form<Values extends Dict>(init: Initial<Values>): FormView<Values>;
21
26
  declare function form(init?: FormInit): FormView<Dict>;
22
27
  export default form;
@@ -28,6 +28,9 @@ function form(action_or_init, maybe_init) {
28
28
  get submitted() {
29
29
  return snapshot().submitted;
30
30
  },
31
+ get result() {
32
+ return snapshot().result;
33
+ },
31
34
  submit(event) {
32
35
  return controller.submit(event);
33
36
  },
@@ -1,4 +1,4 @@
1
- import type ContextData from "@primate/core/i18n/ContextData";
1
+ import type { ContextData } from "@primate/core/i18n";
2
2
  import type { Dict } from "@rcompat/type";
3
3
  import { type Accessor, type Setter } from "solid-js";
4
4
  type Context = {
@@ -1,3 +1,3 @@
1
- declare const _default: (length: number, i18n_active: boolean) => string;
1
+ declare const _default: (length: number) => string;
2
2
  export default _default;
3
3
  //# sourceMappingURL=create-root.d.ts.map
@@ -1,4 +1,4 @@
1
- export default (length, i18n_active) => {
1
+ export default (length) => {
2
2
  const n = length;
3
3
  const body = Array.from({ length: n }, (_, i) => i - 1).reduceRight((child, _, i) => `views[${i + 1}] !== undefined
4
4
  ? createComponent(views[${i}], { ...props[${i}],
@@ -6,31 +6,17 @@ export default (length, i18n_active) => {
6
6
  })
7
7
  : createComponent(views[${i}], props[${i}])
8
8
  `, `createComponent(views[${n}], props[${n}])`);
9
- const i18n_imports = i18n_active
10
- ? `
11
- import I18nBridge from "@primate/solid/i18n/Bridge";
12
- import t from "#i18n";`
13
- : "";
14
- const tree = i18n_active
15
- ? `<I18nBridge t={t}>{${body}}</I18nBridge>`
16
- : `{${body}}`;
17
9
  return `
18
- import { createSignal } from "solid-js";
19
10
  import { createComponent } from "solid-js/web";
20
11
  import { setRequest } from "@primate/solid/app";
21
- import AppContext from "@primate/solid/context/app";
22
- import HeadContext from "@primate/solid/context/head";${i18n_imports}
12
+ import HeadContext from "@primate/solid/context/head";
23
13
 
24
14
  export default ({ views, props, request, push_heads: value }) => {
25
15
  setRequest(request);
26
- const [context, setContext] = createSignal(request.context);
27
- const $value = { context, setContext };
28
16
 
29
- return <AppContext.Provider value={$value}>
30
- <HeadContext.Provider value={value}>
31
- ${tree}
32
- </HeadContext.Provider>
33
- </AppContext.Provider>
17
+ return <HeadContext.Provider value={value}>
18
+ {${body}}
19
+ </HeadContext.Provider>
34
20
  }
35
21
  `;
36
22
  };
@@ -0,0 +1,3 @@
1
+ import type { BridgedTranslator, HeadlessTranslator } from "@primate/core/i18n";
2
+ export default function i18n<const T extends HeadlessTranslator>(source: T): BridgedTranslator<T>;
3
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1,51 @@
1
+ import { request } from "#request/store";
2
+ import { createSignal } from "solid-js";
3
+ export default function i18n(source) {
4
+ const [version, setVersion] = createSignal(0);
5
+ let restored = false;
6
+ let restored_request;
7
+ const current_request = () => request();
8
+ const restore_from_request = () => {
9
+ const next = current_request();
10
+ if (restored && next === restored_request)
11
+ return;
12
+ restored = true;
13
+ restored_request = next;
14
+ source.restore(next);
15
+ };
16
+ const depend = () => {
17
+ version();
18
+ restore_from_request();
19
+ };
20
+ const restore = (next = current_request()) => {
21
+ const before = source.locale.get();
22
+ restored = true;
23
+ restored_request = next;
24
+ source.restore(next);
25
+ if (source.locale.get() !== before)
26
+ setVersion(v => v + 1);
27
+ };
28
+ const get = () => {
29
+ depend();
30
+ return source.locale.get();
31
+ };
32
+ const set = (locale) => {
33
+ const before = source.locale.get();
34
+ source.locale.set(locale);
35
+ if (source.locale.get() !== before)
36
+ setVersion(v => v + 1);
37
+ };
38
+ const value = ((...args) => {
39
+ depend();
40
+ return source(...args);
41
+ });
42
+ value.defaultLocale = source.defaultLocale;
43
+ value.locales = source.locales;
44
+ value.catalogs = source.catalogs;
45
+ value.currency = source.currency;
46
+ value.locale = { get, set };
47
+ value.restore = restore;
48
+ restore();
49
+ return value;
50
+ }
51
+ //# 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 solid(): {
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 solid() {
2
+ return {
3
+ name: "solid",
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
@@ -1,3 +1,2 @@
1
- export { default as client } from "#client/index";
2
1
  export { default } from "#runtime";
3
2
  //# sourceMappingURL=runtime.d.ts.map
@@ -1,3 +1,2 @@
1
- export { default as client } from "#client/index";
2
1
  export { default } from "#runtime";
3
2
  //# sourceMappingURL=runtime.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/solid",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "SolidJS for Primate",
5
5
  "homepage": "https://primate.run/docs/frontend/solid",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",
@@ -22,21 +22,16 @@
22
22
  "@types/babel__core": "^7.20.5"
23
23
  },
24
24
  "dependencies": {
25
- "@babel/core": "^7.28.6",
26
- "@rcompat/fs": "^0.33.2",
25
+ "@babel/core": "^7.29.7",
27
26
  "@rcompat/runtime": "^0.16.0",
28
27
  "babel-preset-solid": "^1.9.12",
29
- "@primate/core": "^0.7.0"
28
+ "@primate/core": "^0.8.0"
30
29
  },
31
30
  "peerDependencies": {
32
31
  "solid-js": "1",
33
- "primate": "^0.38.0"
32
+ "primate": "^0.39.0"
34
33
  },
35
34
  "imports": {
36
- "#i18n/Bridge.default": {
37
- "@primate/source": "./src/private/i18n/Bridge.default.tsx",
38
- "default": "./lib/private/i18n/Bridge.default.js"
39
- },
40
35
  "#*": {
41
36
  "@primate/source": "./src/private/*.ts",
42
37
  "default": "./lib/private/*.js"
@@ -50,25 +45,22 @@
50
45
  "exports": {
51
46
  ".": {
52
47
  "types": "./lib/index.d.ts",
48
+ "browser": {
49
+ "@primate/source": "./src/public/browser.ts",
50
+ "default": "./lib/public/browser.js"
51
+ },
53
52
  "@primate/runtime": "./src/public/runtime.ts",
54
53
  "@primate/source": "./src/public/default.ts",
55
- "browser": "./lib/public/browser.js",
56
54
  "runtime": "./lib/public/runtime.js",
57
55
  "default": "./lib/public/default.js"
58
56
  },
59
57
  "./*": {
60
58
  "@primate/source": "./src/public/*.ts",
61
59
  "default": "./lib/public/*.js"
62
- },
63
- "./i18n/Bridge": {
64
- "@primate/source": "./src/public/i18n/Bridge/default.ts",
65
- "browser": "./lib/public/i18n/Bridge/browser.js",
66
- "default": "./lib/public/i18n/Bridge/default.js"
67
60
  }
68
61
  },
69
62
  "scripts": {
70
- "build": "npm run clean && tsc && cp src/types/{app,index}.d.ts lib",
71
- "postbuild": "node scripts/compile-jsx.js",
63
+ "build": "npm run clean && tsgo && cp src/types/{app,index}.d.ts lib",
72
64
  "clean": "rm -rf ./lib",
73
65
  "lint": "eslint ."
74
66
  }
@@ -1,8 +0,0 @@
1
- import type API from "@primate/core/i18n/API";
2
- import type Catalogs from "@primate/core/i18n/Catalogs";
3
- import { type JSX } from "solid-js";
4
- export default function I18nBridge<C extends Catalogs>(props: {
5
- t: API<C>;
6
- children?: JSX.Element;
7
- }): any;
8
- //# sourceMappingURL=Bridge.browser.d.ts.map
@@ -1,25 +0,0 @@
1
- import { memo as _$memo } from "solid-js/web";
2
- import AppContext from "#context/app";
3
- import sInternal from "@primate/core/i18n/sInternal";
4
- import { createSignal, onCleanup, onMount, useContext } from "solid-js";
5
- function I18nBridge(props) {
6
- const {
7
- context
8
- } = useContext(AppContext);
9
- const server = context().i18n.locale;
10
- if (server !== void 0 && server !== props.t.locale.get()) {
11
- props.t[sInternal].init(server);
12
- }
13
- const [version, setVersion] = createSignal(props.t[sInternal].version);
14
- const removeDepend = props.t[sInternal].depend(() => {
15
- version();
16
- });
17
- const off = props.t.subscribe(() => setVersion(v => v + 1));
18
- onMount(() => props.t[sInternal].restore());
19
- onCleanup(() => {
20
- off();
21
- removeDepend();
22
- });
23
- return _$memo(() => props.children);
24
- }
25
- export { I18nBridge as default };
@@ -1,8 +0,0 @@
1
- import type API from "@primate/core/i18n/API";
2
- import type Catalogs from "@primate/core/i18n/Catalogs";
3
- import { type JSX } from "solid-js";
4
- export default function I18nBridge<C extends Catalogs>(props: {
5
- t: API<C>;
6
- children?: JSX.Element;
7
- }): any;
8
- //# sourceMappingURL=Bridge.default.d.ts.map
@@ -1,12 +0,0 @@
1
- import { memo as _$memo } from "solid-js/web";
2
- import AppContext from "#context/app";
3
- import sInternal from "@primate/core/i18n/sInternal";
4
- import { useContext } from "solid-js";
5
- function I18nBridge(props) {
6
- const {
7
- context
8
- } = useContext(AppContext);
9
- props.t[sInternal].init(context().i18n.locale);
10
- return _$memo(() => props.children);
11
- }
12
- export { I18nBridge as default };
@@ -1,2 +0,0 @@
1
- export { default } from "#i18n/Bridge.browser";
2
- //# sourceMappingURL=browser.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "#i18n/Bridge.browser";
2
- //# sourceMappingURL=browser.js.map
@@ -1,2 +0,0 @@
1
- export { default } from "#i18n/Bridge.default";
2
- //# sourceMappingURL=default.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "#i18n/Bridge.default";
2
- //# sourceMappingURL=default.js.map