@primate/solid 0.7.1 → 0.8.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.
@@ -1,16 +1,12 @@
1
1
  import create_root from "#create-root";
2
2
  import Runtime from "#Runtime";
3
3
  import { transformSync } from "@babel/core";
4
- import transform from "@rcompat/build/sync/transform";
4
+ import build_presets from "@primate/core/build/presets";
5
+ import transform from "@primate/core/build/transform";
5
6
  // @ts-expect-error no declaration file
6
7
  import solid from "babel-preset-solid";
7
8
  function compile(text, presets) {
8
- return transformSync(transform(text, {
9
- format: "esm",
10
- jsx: "preserve",
11
- loader: "tsx",
12
- target: "esnext",
13
- }).code, { presets })?.code ?? "";
9
+ return transformSync(transform(text, build_presets.solid).code, { presets })?.code ?? "";
14
10
  }
15
11
  export default class Default extends Runtime {
16
12
  root = {
@@ -1,4 +1,4 @@
1
- import type Dict from "@rcompat/type/Dict";
1
+ import type { Dict } from "@rcompat/type";
2
2
  type Child = {
3
3
  props: Dict;
4
4
  t: string;
@@ -1,11 +1,11 @@
1
1
  import type ClientData from "@primate/core/client/Data";
2
- import type Dict from "@rcompat/type/Dict";
2
+ import type { Dict } from "@rcompat/type";
3
3
  type Data = ClientData<{
4
4
  views: string[];
5
5
  props: Dict[];
6
6
  }>;
7
- export default class Solid {
7
+ export default class SolidApp {
8
8
  static mount(_view: string, data: ClientData<Data>): void;
9
9
  }
10
10
  export {};
11
- //# sourceMappingURL=index.d.ts.map
11
+ //# sourceMappingURL=app.d.ts.map
@@ -15,9 +15,10 @@ const make_props = (data) => ({
15
15
  url: new URL(location.href),
16
16
  },
17
17
  });
18
- export default class Solid {
18
+ export default class SolidApp {
19
19
  static mount(_view, data) {
20
- let dispose = hydrate(() => root_view(make_props(data)), body);
20
+ const mount = () => root_view(make_props(data));
21
+ let dispose = data.ssr ? hydrate(mount, body) : render(mount, body);
21
22
  if (data.spa) {
22
23
  window.addEventListener("DOMContentLoaded", _ => spa(_data => {
23
24
  dispose();
@@ -26,4 +27,4 @@ export default class Solid {
26
27
  }
27
28
  }
28
29
  }
29
- //# sourceMappingURL=index.js.map
30
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1,31 @@
1
+ import { type ValidateUpdater, type ValidationError } from "@primate/core/client";
2
+ type Validated<T> = {
3
+ error: () => null | ValidationError;
4
+ loading: () => boolean;
5
+ update: (updater: ValidateUpdater<T>) => Promise<void>;
6
+ value: () => T;
7
+ };
8
+ declare const field: <T>(initial: T) => {
9
+ delete: (url: string, options?: {
10
+ headers?: import("@rcompat/type").Dict<string>;
11
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
12
+ path?: import("@rcompat/type").JSONPointer;
13
+ } | undefined) => Validated<T>;
14
+ patch: (url: string, options?: {
15
+ headers?: import("@rcompat/type").Dict<string>;
16
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
17
+ path?: import("@rcompat/type").JSONPointer;
18
+ } | undefined) => Validated<T>;
19
+ post: (url: string, options?: {
20
+ headers?: import("@rcompat/type").Dict<string>;
21
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
22
+ path?: import("@rcompat/type").JSONPointer;
23
+ } | undefined) => Validated<T>;
24
+ put: (url: string, options?: {
25
+ headers?: import("@rcompat/type").Dict<string>;
26
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
27
+ path?: import("@rcompat/type").JSONPointer;
28
+ } | undefined) => Validated<T>;
29
+ };
30
+ export default field;
31
+ //# sourceMappingURL=field.d.ts.map
@@ -1,5 +1,4 @@
1
- import toValidated from "@primate/core/client/toValidated";
2
- import validate from "@primate/core/client/validate";
1
+ import client from "@primate/core/client";
3
2
  import { createSignal } from "solid-js";
4
3
  function useValidate(init) {
5
4
  const [value, setValue] = createSignal(init.initial);
@@ -12,7 +11,7 @@ function useValidate(init) {
12
11
  setLoading(true);
13
12
  setError(null);
14
13
  try {
15
- await validate(init, next);
14
+ await client.validateField(init, next);
16
15
  }
17
16
  catch (e) {
18
17
  // rollback
@@ -25,5 +24,6 @@ function useValidate(init) {
25
24
  }
26
25
  return { error, loading, update, value };
27
26
  }
28
- export default toValidated(useValidate);
29
- //# sourceMappingURL=validate.js.map
27
+ const field = client.toValidated(useValidate);
28
+ export default field;
29
+ //# sourceMappingURL=field.js.map
@@ -0,0 +1,21 @@
1
+ import { type FormInit } from "@primate/core/client";
2
+ import type { Dict } from "@rcompat/type";
3
+ type FormView<Values extends Dict> = {
4
+ id: string;
5
+ submitting: boolean;
6
+ submit: (event?: Event) => Promise<void>;
7
+ errors: readonly string[];
8
+ field: <K extends keyof Values & string>(name: K) => {
9
+ name: string;
10
+ value: Values[K];
11
+ error: string | null;
12
+ errors: readonly string[];
13
+ };
14
+ };
15
+ type Initial<Values extends Dict> = FormInit & {
16
+ initial?: Values;
17
+ };
18
+ declare function form<Values extends Dict>(init: Initial<Values>): FormView<Values>;
19
+ declare function form(init?: FormInit): FormView<Dict>;
20
+ export default form;
21
+ //# sourceMappingURL=form.d.ts.map
@@ -0,0 +1,36 @@
1
+ import core from "@primate/core/client";
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 ?? {};
7
+ const [snapshot, setSnapshot] = createSignal(controller.read());
8
+ const unsub = controller.subscribe((next) => setSnapshot(next));
9
+ onCleanup(unsub);
10
+ return {
11
+ id: controller.id,
12
+ get submitting() {
13
+ return snapshot().submitting;
14
+ },
15
+ submit: (event) => controller.submit(event),
16
+ get errors() {
17
+ return snapshot().errors.form;
18
+ },
19
+ field(name) {
20
+ const key = name;
21
+ return {
22
+ name: key,
23
+ value: values[name],
24
+ get errors() {
25
+ return snapshot().errors.fields[key] ?? [];
26
+ },
27
+ get error() {
28
+ const errors = snapshot().errors.fields[key] ?? [];
29
+ return errors[0] ?? null;
30
+ },
31
+ };
32
+ },
33
+ };
34
+ }
35
+ export default form;
36
+ //# sourceMappingURL=form.js.map
@@ -1,5 +1,5 @@
1
1
  import type ContextData from "@primate/core/i18n/ContextData";
2
- import type Dict from "@rcompat/type/Dict";
2
+ import type { Dict } from "@rcompat/type";
3
3
  import { type Accessor, type Setter } from "solid-js";
4
4
  type Context = {
5
5
  i18n: ContextData;
@@ -1,11 +1,11 @@
1
1
  export default (length, i18n_active) => {
2
2
  const n = length;
3
- const body = Array.from({ length: n }, (_, i) => i - 1)
4
- .reduceRight((child, _, i) => `views[${i + 1}] !== undefined
5
- ? createComponent(views[${i}], {request, ...props[${i}],
6
- children: ${child}})
7
- : createComponent(views[${i}], {request, ...props[${i}]})
8
- `, `createComponent(views[${n}], {request, ...props[${n}]})`);
3
+ const body = Array.from({ length: n }, (_, i) => i - 1).reduceRight((child, _, i) => `views[${i + 1}] !== undefined
4
+ ? createComponent(views[${i}], { request, ...props[${i}],
5
+ get children() { return ${child}; }
6
+ })
7
+ : createComponent(views[${i}], { request, ...props[${i}] })
8
+ `, `createComponent(views[${n}], { request, ...props[${n}] })`);
9
9
  const i18n_imports = i18n_active
10
10
  ? `
11
11
  import I18nBridge from "@primate/solid/i18n/Bridge";
@@ -1,2 +1,2 @@
1
- export { default } from "#client/index";
1
+ export { default } from "#client/app";
2
2
  //# sourceMappingURL=browser.d.ts.map
@@ -1,2 +1,2 @@
1
- export { default } from "#client/index";
1
+ export { default } from "#client/app";
2
2
  //# sourceMappingURL=browser.js.map
@@ -0,0 +1,48 @@
1
+ import form from "#client/form";
2
+ declare const client: {
3
+ form: typeof form;
4
+ field: <T>(initial: T) => {
5
+ delete: (url: string, options?: {
6
+ headers?: import("@rcompat/type").Dict<string>;
7
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
8
+ path?: import("@rcompat/type").JSONPointer;
9
+ } | undefined) => {
10
+ error: () => null | import("@primate/core/client").ValidationError;
11
+ loading: () => boolean;
12
+ update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
13
+ value: () => T;
14
+ };
15
+ patch: (url: string, options?: {
16
+ headers?: import("@rcompat/type").Dict<string>;
17
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
18
+ path?: import("@rcompat/type").JSONPointer;
19
+ } | undefined) => {
20
+ error: () => null | import("@primate/core/client").ValidationError;
21
+ loading: () => boolean;
22
+ update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
23
+ value: () => T;
24
+ };
25
+ post: (url: string, options?: {
26
+ headers?: import("@rcompat/type").Dict<string>;
27
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
28
+ path?: import("@rcompat/type").JSONPointer;
29
+ } | undefined) => {
30
+ error: () => null | import("@primate/core/client").ValidationError;
31
+ loading: () => boolean;
32
+ update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
33
+ value: () => T;
34
+ };
35
+ put: (url: string, options?: {
36
+ headers?: import("@rcompat/type").Dict<string>;
37
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
38
+ path?: import("@rcompat/type").JSONPointer;
39
+ } | undefined) => {
40
+ error: () => null | import("@primate/core/client").ValidationError;
41
+ loading: () => boolean;
42
+ update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
43
+ value: () => T;
44
+ };
45
+ };
46
+ };
47
+ export default client;
48
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,5 @@
1
+ import field from "#client/field";
2
+ import form from "#client/form";
3
+ const client = { form, field };
4
+ export default client;
5
+ //# sourceMappingURL=client.js.map
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
1
  {
2
2
  "name": "@primate/solid",
3
- "version": "0.7.1",
4
- "description": "Primate Solid frontend",
3
+ "version": "0.8.0",
4
+ "description": "SolidJS for Primate",
5
5
  "homepage": "https://primate.run/docs/frontend/solid",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",
7
7
  "license": "MIT",
8
- "files": [
9
- "/lib/**/*.js",
10
- "/lib/**/*.d.ts",
11
- "!/**/*.spec.*"
12
- ],
8
+ "type": "module",
13
9
  "repository": {
14
10
  "type": "git",
15
11
  "url": "https://github.com/primate-run/primate",
16
12
  "directory": "packages/solid"
17
13
  },
14
+ "files": [
15
+ "/lib/**/*.js",
16
+ "/lib/**/*.d.ts",
17
+ "!/**/*.spec.*"
18
+ ],
18
19
  "devDependencies": {
20
+ "@rcompat/type": "^0.9.0",
19
21
  "@types/babel__core": "^7.20.5"
20
22
  },
21
23
  "dependencies": {
22
- "@babel/core": "^7.28.4",
23
- "@rcompat/build": "^0.15.0",
24
- "@rcompat/fs": "^0.22.3",
25
- "@rcompat/runtime": "^0.6.0",
24
+ "@babel/core": "^7.28.6",
25
+ "@rcompat/fs": "^0.25.2",
26
+ "@rcompat/runtime": "^0.9.0",
26
27
  "babel-preset-solid": "^1.9.10",
27
- "@primate/core": "^0.4.1"
28
+ "@primate/core": "^0.5.0"
28
29
  },
29
30
  "peerDependencies": {
30
31
  "solid-js": "1",
31
- "primate": "^0.35.0"
32
+ "primate": "^0.36.0"
32
33
  },
33
- "type": "module",
34
34
  "imports": {
35
35
  "#*": {
36
36
  "apekit": "./src/private/*.ts",
@@ -1,10 +0,0 @@
1
- import type ValidateUpdater from "@primate/core/client/ValidateUpdater";
2
- import type ValidationError from "@primate/core/client/ValidationError";
3
- type Validated<T> = {
4
- error: () => null | ValidationError;
5
- loading: () => boolean;
6
- update: (updater: ValidateUpdater<T>) => Promise<void>;
7
- value: () => T;
8
- };
9
- export type { Validated as default };
10
- //# sourceMappingURL=Validated.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Validated.js.map
@@ -1,25 +0,0 @@
1
- import type Validated from "#client/Validated";
2
- declare const _default: <T>(initial: T) => {
3
- delete: (url: string, options?: {
4
- headers?: import("@rcompat/type/Dict").default<string>;
5
- map?: ((v: T) => import("@rcompat/type/JSONValue").default) | undefined;
6
- path?: import("@rcompat/type/JSONPointer").default;
7
- } | undefined) => Validated<T>;
8
- patch: (url: string, options?: {
9
- headers?: import("@rcompat/type/Dict").default<string>;
10
- map?: ((v: T) => import("@rcompat/type/JSONValue").default) | undefined;
11
- path?: import("@rcompat/type/JSONPointer").default;
12
- } | undefined) => Validated<T>;
13
- post: (url: string, options?: {
14
- headers?: import("@rcompat/type/Dict").default<string>;
15
- map?: ((v: T) => import("@rcompat/type/JSONValue").default) | undefined;
16
- path?: import("@rcompat/type/JSONPointer").default;
17
- } | undefined) => Validated<T>;
18
- put: (url: string, options?: {
19
- headers?: import("@rcompat/type/Dict").default<string>;
20
- map?: ((v: T) => import("@rcompat/type/JSONValue").default) | undefined;
21
- path?: import("@rcompat/type/JSONPointer").default;
22
- } | undefined) => Validated<T>;
23
- };
24
- export default _default;
25
- //# sourceMappingURL=validate.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "#client/Validated";
2
- //# sourceMappingURL=Validated.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Validated.js.map
@@ -1,2 +0,0 @@
1
- export { default } from "#client/validate";
2
- //# sourceMappingURL=validate.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "#client/validate";
2
- //# sourceMappingURL=validate.js.map