@primate/solid 0.8.0 → 0.10.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/app.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ declare module "app:solid" {
2
+ import type { RequestPublic } from "@primate/core";
3
+ import type { Accessor } from "solid-js";
4
+ export const request: Accessor<RequestPublic>;
5
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import "./app.d.ts";
2
+ export { default } from "#default";
3
+ export { default as client } from "#client/index";
@@ -0,0 +1,5 @@
1
+ import type { Data as CoreData } from "@primate/core/client";
2
+ import type Payload from "#client/Payload";
3
+ type Data = CoreData<Payload>;
4
+ export default Data;
5
+ //# sourceMappingURL=Data.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Data.js.map
@@ -0,0 +1,7 @@
1
+ import type { Dict } from "@rcompat/type";
2
+ type Payload = {
3
+ views: string[];
4
+ props: Dict[];
5
+ };
6
+ export default Payload;
7
+ //# sourceMappingURL=Payload.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Payload.js.map
@@ -1,11 +1,14 @@
1
- import type ClientData from "@primate/core/client/Data";
2
- import type { Dict } from "@rcompat/type";
3
- type Data = ClientData<{
4
- views: string[];
5
- props: Dict[];
6
- }>;
1
+ import type Data from "#client/Data";
2
+ declare global {
3
+ interface Window {
4
+ _$HY: {
5
+ completed: WeakSet<object>;
6
+ events: unknown[];
7
+ r: Record<string, unknown>;
8
+ };
9
+ }
10
+ }
7
11
  export default class SolidApp {
8
- static mount(_view: string, data: ClientData<Data>): void;
12
+ static mount(_view: string, data: Data): void;
9
13
  }
10
- export {};
11
14
  //# sourceMappingURL=app.d.ts.map
@@ -1,29 +1,29 @@
1
- import spa from "@primate/core/client/spa";
1
+ import root from "#client/root";
2
+ import client from "@primate/core/client";
2
3
  import SolidHead from "@primate/solid/Head";
3
- import { hydrate, render } from "solid-js/web";
4
- import root_view from "solid:root";
5
- import * as views from "solid:views";
6
- // @ts-expect-error solid hydration
7
- globalThis._$HY = { completed: new WeakSet(), events: [], r: {} };
4
+ import Root from "solid:root";
5
+ window._$HY = { completed: new WeakSet(), events: [], r: {} };
8
6
  const { body } = globalThis.window.document;
9
7
  SolidHead.clear();
10
- const make_props = (data) => ({
11
- views: data.views.map(name => views[name]),
12
- props: data.props,
13
- request: {
14
- ...data.request,
15
- url: new URL(location.href),
16
- },
17
- });
18
8
  export default class SolidApp {
19
9
  static mount(_view, data) {
20
- const mount = () => root_view(make_props(data));
21
- let dispose = data.ssr ? hydrate(mount, body) : render(mount, body);
22
- if (data.spa) {
23
- window.addEventListener("DOMContentLoaded", _ => spa(_data => {
10
+ const interactive = !data.ssr || data.csr;
11
+ if (!interactive)
12
+ return;
13
+ const mount = () => Root(root.toProps(data));
14
+ let dispose = root[data.ssr ? "ssr" : "csr"](mount, body);
15
+ if (data.csr) {
16
+ const start = () => client.boot((_data, update) => {
24
17
  dispose();
25
- dispose = render(() => root_view(make_props(_data)), body);
26
- }));
18
+ dispose = root.csr(() => Root(root.toProps(_data, update)), body);
19
+ update?.();
20
+ });
21
+ if (document.readyState === "loading") {
22
+ window.addEventListener("DOMContentLoaded", start, { once: true });
23
+ }
24
+ else {
25
+ start();
26
+ }
27
27
  }
28
28
  }
29
29
  }
@@ -1,20 +1,22 @@
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
3
  type FormView<Values extends Dict> = {
4
4
  id: string;
5
5
  submitting: boolean;
6
+ submitted: boolean;
6
7
  submit: (event?: Event) => Promise<void>;
7
- errors: readonly string[];
8
+ errors: string[];
8
9
  field: <K extends keyof Values & string>(name: K) => {
9
10
  name: string;
10
11
  value: Values[K];
11
12
  error: string | null;
12
- errors: readonly string[];
13
+ errors: string[];
13
14
  };
14
15
  };
15
16
  type Initial<Values extends Dict> = FormInit & {
16
17
  initial?: Values;
17
18
  };
19
+ declare function form<Values extends Dict>(action: ClientMethod<Values>, init?: Initial<Values>): FormView<Values>;
18
20
  declare function form<Values extends Dict>(init: Initial<Values>): FormView<Values>;
19
21
  declare function form(init?: FormInit): FormView<Dict>;
20
22
  export default form;
@@ -1,18 +1,36 @@
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);
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
+ });
6
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
- id: controller.id,
22
+ get id() {
23
+ return snapshot().id;
24
+ },
12
25
  get submitting() {
13
26
  return snapshot().submitting;
14
27
  },
15
- submit: (event) => controller.submit(event),
28
+ get submitted() {
29
+ return snapshot().submitted;
30
+ },
31
+ submit(event) {
32
+ return controller.submit(event);
33
+ },
16
34
  get errors() {
17
35
  return snapshot().errors.form;
18
36
  },
@@ -25,8 +43,7 @@ function form(init) {
25
43
  return snapshot().errors.fields[key] ?? [];
26
44
  },
27
45
  get error() {
28
- const errors = snapshot().errors.fields[key] ?? [];
29
- return errors[0] ?? null;
46
+ return (snapshot().errors.fields[key] ?? [])[0] ?? null;
30
47
  },
31
48
  };
32
49
  },
@@ -45,4 +45,4 @@ declare const client: {
45
45
  };
46
46
  };
47
47
  export default client;
48
- //# sourceMappingURL=client.d.ts.map
48
+ //# sourceMappingURL=index.d.ts.map
@@ -2,4 +2,4 @@ import field from "#client/field";
2
2
  import form from "#client/form";
3
3
  const client = { form, field };
4
4
  export default client;
5
- //# sourceMappingURL=client.js.map
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,21 @@
1
+ import type Data from "#client/Data";
2
+ import type { Dict } from "@rcompat/type";
3
+ import { type Component } from "solid-js";
4
+ import { render } from "solid-js/web";
5
+ type ViewComponent = Component<any>;
6
+ export type RootProps = {
7
+ views: ViewComponent[];
8
+ props: Dict[];
9
+ request: Data["request"] & {
10
+ url: URL;
11
+ };
12
+ update?: () => void;
13
+ };
14
+ declare function toProps(data: Data, update?: () => void): RootProps;
15
+ declare const root: {
16
+ toProps: typeof toProps;
17
+ csr: typeof render;
18
+ ssr: typeof import("solid-js/web/types/client.js").hydrate;
19
+ };
20
+ export default root;
21
+ //# sourceMappingURL=root.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { hydrate, render } from "solid-js/web";
2
+ import * as Views from "solid:views";
3
+ function toProps(data, update) {
4
+ return {
5
+ views: data.views.map(name => Views[name]),
6
+ props: data.props,
7
+ request: {
8
+ ...data.request,
9
+ url: new URL(data.request.url),
10
+ },
11
+ update,
12
+ };
13
+ }
14
+ const root = {
15
+ toProps,
16
+ csr: render,
17
+ ssr: hydrate,
18
+ };
19
+ export default root;
20
+ //# sourceMappingURL=root.js.map
@@ -1,11 +1,11 @@
1
1
  export default (length, i18n_active) => {
2
2
  const n = length;
3
3
  const body = Array.from({ length: n }, (_, i) => i - 1).reduceRight((child, _, i) => `views[${i + 1}] !== undefined
4
- ? createComponent(views[${i}], { request, ...props[${i}],
4
+ ? createComponent(views[${i}], { ...props[${i}],
5
5
  get children() { return ${child}; }
6
6
  })
7
- : createComponent(views[${i}], { request, ...props[${i}] })
8
- `, `createComponent(views[${n}], { request, ...props[${n}] })`);
7
+ : createComponent(views[${i}], props[${i}])
8
+ `, `createComponent(views[${n}], props[${n}])`);
9
9
  const i18n_imports = i18n_active
10
10
  ? `
11
11
  import I18nBridge from "@primate/solid/i18n/Bridge";
@@ -17,10 +17,12 @@ export default (length, i18n_active) => {
17
17
  return `
18
18
  import { createSignal } from "solid-js";
19
19
  import { createComponent } from "solid-js/web";
20
+ import { setRequest } from "@primate/solid/app";
20
21
  import AppContext from "@primate/solid/context/app";
21
22
  import HeadContext from "@primate/solid/context/head";${i18n_imports}
22
23
 
23
24
  export default ({ views, props, request, push_heads: value }) => {
25
+ setRequest(request);
24
26
  const [context, setContext] = createSignal(request.context);
25
27
  const $value = { context, setContext };
26
28
 
@@ -0,0 +1,7 @@
1
+ declare const _default: (input?: {
2
+ extensions?: string[] | undefined;
3
+ csr?: boolean | undefined;
4
+ ssr?: boolean | undefined;
5
+ } | undefined) => import("@primate/core/frontend").Module;
6
+ export default _default;
7
+ //# sourceMappingURL=default.d.ts.map
@@ -1,18 +1,20 @@
1
1
  import create_root from "#create-root";
2
- import Runtime from "#Runtime";
2
+ import init from "#init";
3
3
  import { transformSync } from "@babel/core";
4
4
  import build_presets from "@primate/core/build/presets";
5
5
  import transform from "@primate/core/build/transform";
6
+ import frontend from "@primate/core/frontend";
6
7
  // @ts-expect-error no declaration file
7
8
  import solid from "babel-preset-solid";
8
9
  function compile(text, presets) {
9
10
  return transformSync(transform(text, build_presets.solid).code, { presets })?.code ?? "";
10
11
  }
11
- export default class Default extends Runtime {
12
- root = {
12
+ export default frontend({
13
+ ...init,
14
+ root: {
13
15
  create: create_root,
14
- };
15
- compile = {
16
+ },
17
+ compile: {
16
18
  client: (text) => {
17
19
  const presets = [[solid, { generate: "dom", hydratable: true }]];
18
20
  return { js: compile(text, presets) };
@@ -21,6 +23,6 @@ export default class Default extends Runtime {
21
23
  const presets = [[solid, { generate: "ssr", hydratable: true }]];
22
24
  return compile(text, presets);
23
25
  },
24
- };
25
- }
26
- //# sourceMappingURL=Default.js.map
26
+ },
27
+ });
28
+ //# sourceMappingURL=default.js.map
@@ -0,0 +1,5 @@
1
+ import type { Init } from "@primate/core/frontend";
2
+ import type { Component } from "solid-js";
3
+ declare const module: Init<Component>;
4
+ export default module;
5
+ //# sourceMappingURL=init.d.ts.map
@@ -1,11 +1,10 @@
1
- import FrontendModule from "@primate/core/frontend/Module";
2
1
  import { renderToString } from "solid-js/web";
3
- export default class Runtime extends FrontendModule {
4
- name = "solid";
5
- defaultExtensions = [".jsx", ".tsx"];
6
- client = true;
7
- layouts = true;
8
- render = (view, props) => {
2
+ const module = {
3
+ name: "solid",
4
+ extensions: [".jsx", ".tsx"],
5
+ layouts: true,
6
+ client: true,
7
+ render(view, props) {
9
8
  const heads = [];
10
9
  const push_heads = (sub_heads) => {
11
10
  heads.push(...sub_heads);
@@ -17,6 +16,7 @@ export default class Runtime extends FrontendModule {
17
16
  }
18
17
  const head = heads.join("\n");
19
18
  return { body, head };
20
- };
21
- }
22
- //# sourceMappingURL=Runtime.js.map
19
+ },
20
+ };
21
+ export default module;
22
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1,4 @@
1
+ import type { RequestPublic } from "@primate/core";
2
+ declare const request: import("solid-js").Accessor<RequestPublic>, setRequest: import("solid-js").Setter<RequestPublic>;
3
+ export { request, setRequest };
4
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1,4 @@
1
+ import { createSignal } from "solid-js";
2
+ const [request, setRequest] = createSignal(undefined);
3
+ export { request, setRequest };
4
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1,7 @@
1
+ declare const _default: (input?: {
2
+ extensions?: string[] | undefined;
3
+ csr?: boolean | undefined;
4
+ ssr?: boolean | undefined;
5
+ } | undefined) => import("@primate/core/frontend").Module;
6
+ export default _default;
7
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1,4 @@
1
+ import init from "#init";
2
+ import frontend from "@primate/core/frontend";
3
+ export default frontend(init);
4
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1,2 @@
1
+ export { request, setRequest } from "#request/store";
2
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { request, setRequest } from "#request/store";
2
+ //# sourceMappingURL=app.js.map
@@ -1,2 +1,3 @@
1
1
  export { default } from "#client/app";
2
+ export { default as client } from "#client/index";
2
3
  //# sourceMappingURL=browser.d.ts.map
@@ -1,2 +1,3 @@
1
1
  export { default } from "#client/app";
2
+ export { default as client } from "#client/index";
2
3
  //# sourceMappingURL=browser.js.map
@@ -1,4 +1,2 @@
1
- import Default from "#Default";
2
- declare const _default: (options?: typeof Default.input) => Default;
3
- export default _default;
1
+ export { default } from "#default";
4
2
  //# sourceMappingURL=default.d.ts.map
@@ -1,3 +1,2 @@
1
- import Default from "#Default";
2
- export default (options) => new Default(options);
1
+ export { default } from "#default";
3
2
  //# sourceMappingURL=default.js.map
@@ -1,4 +1,3 @@
1
- import Runtime from "#Runtime";
2
- declare const _default: (options?: typeof Runtime.input) => Runtime;
3
- export default _default;
1
+ export { default as client } from "#client/index";
2
+ export { default } from "#runtime";
4
3
  //# sourceMappingURL=runtime.d.ts.map
@@ -1,3 +1,3 @@
1
- import Runtime from "#Runtime";
2
- export default (options) => new Runtime(options);
1
+ export { default as client } from "#client/index";
2
+ export { default } from "#runtime";
3
3
  //# sourceMappingURL=runtime.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/solid",
3
- "version": "0.8.0",
3
+ "version": "0.10.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",
@@ -16,46 +16,58 @@
16
16
  "/lib/**/*.d.ts",
17
17
  "!/**/*.spec.*"
18
18
  ],
19
+ "types": "lib/index.d.ts",
19
20
  "devDependencies": {
20
- "@rcompat/type": "^0.9.0",
21
+ "@rcompat/type": "^0.17.0",
21
22
  "@types/babel__core": "^7.20.5"
22
23
  },
23
24
  "dependencies": {
24
25
  "@babel/core": "^7.28.6",
25
- "@rcompat/fs": "^0.25.2",
26
- "@rcompat/runtime": "^0.9.0",
27
- "babel-preset-solid": "^1.9.10",
28
- "@primate/core": "^0.5.0"
26
+ "@rcompat/fs": "^0.33.2",
27
+ "@rcompat/runtime": "^0.16.0",
28
+ "babel-preset-solid": "^1.9.12",
29
+ "@primate/core": "^0.7.0"
29
30
  },
30
31
  "peerDependencies": {
31
32
  "solid-js": "1",
32
- "primate": "^0.36.0"
33
+ "primate": "^0.38.0"
33
34
  },
34
35
  "imports": {
36
+ "#i18n/Bridge.default": {
37
+ "@primate/source": "./src/private/i18n/Bridge.default.tsx",
38
+ "default": "./lib/private/i18n/Bridge.default.js"
39
+ },
35
40
  "#*": {
36
- "apekit": "./src/private/*.ts",
41
+ "@primate/source": "./src/private/*.ts",
37
42
  "default": "./lib/private/*.js"
38
43
  },
39
44
  "#HeadImpl": {
40
- "apekit": "./src/private/Head/default.ts",
45
+ "@primate/source": "./src/private/Head/default.ts",
41
46
  "browser": "./lib/private/Head/browser.js",
42
47
  "default": "./lib/private/Head/default.js"
43
48
  }
44
49
  },
45
50
  "exports": {
46
51
  ".": {
52
+ "types": "./lib/index.d.ts",
53
+ "@primate/runtime": "./src/public/runtime.ts",
54
+ "@primate/source": "./src/public/default.ts",
47
55
  "browser": "./lib/public/browser.js",
48
56
  "runtime": "./lib/public/runtime.js",
49
57
  "default": "./lib/public/default.js"
50
58
  },
51
- "./*": "./lib/public/*.js",
59
+ "./*": {
60
+ "@primate/source": "./src/public/*.ts",
61
+ "default": "./lib/public/*.js"
62
+ },
52
63
  "./i18n/Bridge": {
64
+ "@primate/source": "./src/public/i18n/Bridge/default.ts",
53
65
  "browser": "./lib/public/i18n/Bridge/browser.js",
54
66
  "default": "./lib/public/i18n/Bridge/default.js"
55
67
  }
56
68
  },
57
69
  "scripts": {
58
- "build": "npm run clean && tsc",
70
+ "build": "npm run clean && tsc && cp src/types/{app,index}.d.ts lib",
59
71
  "postbuild": "node scripts/compile-jsx.js",
60
72
  "clean": "rm -rf ./lib",
61
73
  "lint": "eslint ."
@@ -1,13 +0,0 @@
1
- import Runtime from "#Runtime";
2
- export default class Default extends Runtime {
3
- root: {
4
- create: (length: number, i18n_active: boolean) => string;
5
- };
6
- compile: {
7
- client: (text: string) => {
8
- js: string;
9
- };
10
- server: (text: string) => string;
11
- };
12
- }
13
- //# sourceMappingURL=Default.d.ts.map
@@ -1,11 +0,0 @@
1
- import FrontendModule from "@primate/core/frontend/Module";
2
- import type Render from "@primate/core/frontend/Render";
3
- import type { Component } from "solid-js";
4
- export default class Runtime extends FrontendModule<Component> {
5
- name: string;
6
- defaultExtensions: string[];
7
- client: boolean;
8
- layouts: boolean;
9
- render: Render<Component>;
10
- }
11
- //# sourceMappingURL=Runtime.d.ts.map