@primate/solid 0.9.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,2 +1,2 @@
1
1
  import "./app.d.ts";
2
- export { default } from "./public/default";
2
+ export { default } from "#default";
@@ -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
@@ -7,9 +7,12 @@ const { body } = globalThis.window.document;
7
7
  SolidHead.clear();
8
8
  export default class SolidApp {
9
9
  static mount(_view, data) {
10
+ const interactive = !data.ssr || data.csr;
11
+ if (!interactive)
12
+ return;
10
13
  const mount = () => Root(root.toProps(data));
11
14
  let dispose = root[data.ssr ? "ssr" : "csr"](mount, body);
12
- if (data.spa) {
15
+ if (data.csr) {
13
16
  const start = () => client.boot((_data, update) => {
14
17
  dispose();
15
18
  dispose = root.csr(() => Root(root.toProps(_data, update)), body);
@@ -1,21 +1,27 @@
1
- import { type FormInit } from "@primate/core/client";
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
- errors: readonly string[];
9
+ errors: string[];
9
10
  field: <K extends keyof Values & string>(name: K) => {
10
11
  name: string;
11
12
  value: Values[K];
12
13
  error: string | null;
13
- errors: readonly string[];
14
+ errors: string[];
14
15
  };
15
16
  };
16
17
  type Initial<Values extends Dict> = FormInit & {
17
18
  initial?: Values;
18
19
  };
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>;
19
25
  declare function form<Values extends Dict>(init: Initial<Values>): FormView<Values>;
20
26
  declare function form(init?: FormInit): FormView<Dict>;
21
27
  export default form;
@@ -1,12 +1,23 @@
1
1
  import core from "@primate/core/client";
2
2
  import { createSignal, onCleanup } from "solid-js";
3
- function form(init) {
4
- const { initial, ...form_init } = (init ?? {});
5
- const controller = core.createForm(form_init);
6
- const values = (initial ?? {});
3
+ function form(action_or_init, maybe_init) {
4
+ const is_action = typeof action_or_init === "function";
5
+ const { initial, ...form_init } = (is_action ? (maybe_init ?? {}) : (action_or_init ?? {}));
6
+ const action = is_action ? action_or_init : undefined;
7
+ const contentType = is_action
8
+ ? action_or_init.contentType
9
+ : undefined;
10
+ const controller = core.createForm({
11
+ ...form_init,
12
+ ...action !== undefined && {
13
+ action: action,
14
+ contentType,
15
+ },
16
+ });
17
+ const values = initial ?? {};
7
18
  const [snapshot, setSnapshot] = createSignal(controller.read());
8
- const unsub = controller.subscribe((next) => setSnapshot(next));
9
- onCleanup(unsub);
19
+ const unsubscribe = controller.subscribe(next => setSnapshot(next));
20
+ onCleanup(unsubscribe);
10
21
  return {
11
22
  get id() {
12
23
  return snapshot().id;
@@ -17,6 +28,9 @@ function form(init) {
17
28
  get submitted() {
18
29
  return snapshot().submitted;
19
30
  },
31
+ get result() {
32
+ return snapshot().result;
33
+ },
20
34
  submit(event) {
21
35
  return controller.submit(event);
22
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
  };
@@ -1,6 +1,6 @@
1
1
  declare const _default: (input?: {
2
2
  extensions?: string[] | undefined;
3
- spa?: boolean | undefined;
3
+ csr?: boolean | undefined;
4
4
  ssr?: boolean | undefined;
5
5
  } | undefined) => import("@primate/core/frontend").Module;
6
6
  export default _default;
@@ -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,6 +1,6 @@
1
1
  declare const _default: (input?: {
2
2
  extensions?: string[] | undefined;
3
- spa?: boolean | undefined;
3
+ csr?: boolean | undefined;
4
4
  ssr?: boolean | undefined;
5
5
  } | undefined) => import("@primate/core/frontend").Module;
6
6
  export default _default;
@@ -1,2 +1,6 @@
1
- export { default } from "#client/app";
1
+ export default function solid(): {
2
+ name: string;
3
+ setup(): void;
4
+ };
5
+ export { default as app } from "#client/app";
2
6
  //# sourceMappingURL=browser.d.ts.map
@@ -1,2 +1,8 @@
1
- export { default } from "#client/app";
1
+ export default function solid() {
2
+ return {
3
+ name: "solid",
4
+ setup() { },
5
+ };
6
+ }
7
+ export { default as app } from "#client/app";
2
8
  //# sourceMappingURL=browser.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/solid",
3
- "version": "0.9.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",
@@ -18,20 +18,18 @@
18
18
  ],
19
19
  "types": "lib/index.d.ts",
20
20
  "devDependencies": {
21
- "@rcompat/type": "^0.11.1",
22
- "@types/babel__core": "^7.20.5",
23
- "@primate/test": "^0.0.0"
21
+ "@rcompat/type": "^0.17.0",
22
+ "@types/babel__core": "^7.20.5"
24
23
  },
25
24
  "dependencies": {
26
- "@babel/core": "^7.28.6",
27
- "@rcompat/fs": "^0.28.1",
28
- "@rcompat/runtime": "^0.11.1",
25
+ "@babel/core": "^7.29.7",
26
+ "@rcompat/runtime": "^0.16.0",
29
27
  "babel-preset-solid": "^1.9.12",
30
- "@primate/core": "^0.6.0"
28
+ "@primate/core": "^0.8.0"
31
29
  },
32
30
  "peerDependencies": {
33
31
  "solid-js": "1",
34
- "primate": "^0.37.0"
32
+ "primate": "^0.39.0"
35
33
  },
36
34
  "imports": {
37
35
  "#*": {
@@ -47,26 +45,23 @@
47
45
  "exports": {
48
46
  ".": {
49
47
  "types": "./lib/index.d.ts",
48
+ "browser": {
49
+ "@primate/source": "./src/public/browser.ts",
50
+ "default": "./lib/public/browser.js"
51
+ },
52
+ "@primate/runtime": "./src/public/runtime.ts",
50
53
  "@primate/source": "./src/public/default.ts",
51
- "browser": "./lib/public/browser.js",
52
54
  "runtime": "./lib/public/runtime.js",
53
55
  "default": "./lib/public/default.js"
54
56
  },
55
57
  "./*": {
56
58
  "@primate/source": "./src/public/*.ts",
57
59
  "default": "./lib/public/*.js"
58
- },
59
- "./i18n/Bridge": {
60
- "@primate/source": "./src/public/i18n/Bridge/default.ts",
61
- "browser": "./lib/public/i18n/Bridge/browser.js",
62
- "default": "./lib/public/i18n/Bridge/default.js"
63
60
  }
64
61
  },
65
62
  "scripts": {
66
- "build": "npm run clean && tsc && cp src/types/{app,index}.d.ts lib",
67
- "postbuild": "node scripts/compile-jsx.js",
63
+ "build": "npm run clean && tsgo && cp src/types/{app,index}.d.ts lib",
68
64
  "clean": "rm -rf ./lib",
69
- "lint": "eslint .",
70
- "test": "npx proby"
65
+ "lint": "eslint ."
71
66
  }
72
67
  }
@@ -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