@primate/vue 0.14.0 → 0.15.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,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 VueClient {
7
+ export default class VueApp {
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
@@ -0,0 +1,32 @@
1
+ import spa from "@primate/core/client/spa";
2
+ import { createApp, createSSRApp } from "vue";
3
+ import root from "vue:root";
4
+ import * as views from "vue:views";
5
+ function resolve(names) {
6
+ return names.map(n => views[n]);
7
+ }
8
+ const make_app = (ssr, data, update) => {
9
+ const create = ssr ? createSSRApp : createApp;
10
+ return create(root, {
11
+ p: {
12
+ views: resolve(data.views),
13
+ props: data.props,
14
+ request: data.request,
15
+ update,
16
+ },
17
+ });
18
+ };
19
+ export default class VueApp {
20
+ static mount(_view, data) {
21
+ let app = make_app(data.ssr, data);
22
+ app.mount("#app");
23
+ if (data.spa) {
24
+ window.addEventListener("DOMContentLoaded", () => spa((next, update) => {
25
+ app.unmount();
26
+ app = make_app(false, next, update);
27
+ app.mount("#app");
28
+ }));
29
+ }
30
+ }
31
+ }
32
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1,32 @@
1
+ import { type ValidateUpdater, type ValidationError } from "@primate/core/client";
2
+ import { type Ref } from "vue";
3
+ type Validated<T> = {
4
+ error: Ref<null | ValidationError>;
5
+ loading: Ref<boolean>;
6
+ update: (updater: ValidateUpdater<T>) => Promise<void>;
7
+ value: Ref<T>;
8
+ };
9
+ declare const field: <T>(initial: T) => {
10
+ delete: (url: string, options?: {
11
+ headers?: import("@rcompat/type").Dict<string>;
12
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
13
+ path?: import("@rcompat/type").JSONPointer;
14
+ } | undefined) => Validated<T>;
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) => Validated<T>;
20
+ post: (url: string, options?: {
21
+ headers?: import("@rcompat/type").Dict<string>;
22
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
23
+ path?: import("@rcompat/type").JSONPointer;
24
+ } | undefined) => Validated<T>;
25
+ put: (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) => Validated<T>;
30
+ };
31
+ export default field;
32
+ //# 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 { ref } from "vue";
4
3
  function useValidate(init) {
5
4
  const value = ref(init.initial);
@@ -12,7 +11,7 @@ function useValidate(init) {
12
11
  loading.value = true;
13
12
  error.value = 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,34 @@
1
+ import core from "@primate/core/client";
2
+ import { onUnmounted, shallowRef } from "vue";
3
+ function form(init) {
4
+ const { initial, ...form_init } = init ?? {};
5
+ const controller = core.createForm(form_init);
6
+ const values = initial ?? {};
7
+ const snapshot = shallowRef(controller.read());
8
+ const unsub = controller.subscribe(next => {
9
+ snapshot.value = next;
10
+ });
11
+ onUnmounted(unsub);
12
+ return {
13
+ id: controller.id,
14
+ get submitting() {
15
+ return snapshot.value.submitting;
16
+ },
17
+ submit: (event) => controller.submit(event),
18
+ get errors() {
19
+ return snapshot.value.errors.form;
20
+ },
21
+ field(name) {
22
+ const key = name;
23
+ const errs = snapshot.value.errors.fields[key] ?? [];
24
+ return {
25
+ name: key,
26
+ value: values[name],
27
+ error: errs[0] ?? null,
28
+ errors: errs,
29
+ };
30
+ },
31
+ };
32
+ }
33
+ export default form;
34
+ //# sourceMappingURL=form.js.map
@@ -1,5 +1,5 @@
1
- import typescript from "@rcompat/build/preset/typescript";
2
- import transform from "@rcompat/build/sync/transform";
1
+ import presets from "@primate/core/build/presets";
2
+ import transform from "@primate/core/build/transform";
3
3
  import { compileScript, compileTemplate, parse, } from "vue/compiler-sfc";
4
4
  const genDefaultAs = "__SCRIPT__";
5
5
  const id_size = 8;
@@ -17,7 +17,8 @@ export default {
17
17
  const { has_script, inline, is_typescript } = analyze(descriptor);
18
18
  let module;
19
19
  if (inline) {
20
- // For <script setup>, compile with inlineTemplate to get both script and render
20
+ // for <script setup>, compile with inlineTemplate to get both script and
21
+ // render
21
22
  const script = compileScript(descriptor, {
22
23
  genDefaultAs,
23
24
  id,
@@ -44,7 +45,7 @@ export default {
44
45
  export default { ...__SCRIPT__, render };
45
46
  `;
46
47
  }
47
- return is_typescript ? transform(module, typescript).code : module;
48
+ return is_typescript ? transform(module, presets.typescript).code : module;
48
49
  },
49
50
  };
50
51
  //# sourceMappingURL=compile.js.map
@@ -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: import("vue").Ref<null | import("@primate/core/client").ValidationError>;
11
+ loading: import("vue").Ref<boolean>;
12
+ update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
13
+ value: import("vue").Ref<T, 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: import("vue").Ref<null | import("@primate/core/client").ValidationError>;
21
+ loading: import("vue").Ref<boolean>;
22
+ update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
23
+ value: import("vue").Ref<T, 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: import("vue").Ref<null | import("@primate/core/client").ValidationError>;
31
+ loading: import("vue").Ref<boolean>;
32
+ update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
33
+ value: import("vue").Ref<T, 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: import("vue").Ref<null | import("@primate/core/client").ValidationError>;
41
+ loading: import("vue").Ref<boolean>;
42
+ update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
43
+ value: import("vue").Ref<T, 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,29 +1,31 @@
1
1
  {
2
2
  "name": "@primate/vue",
3
- "version": "0.14.0",
4
- "description": "Primate Vue frontend",
3
+ "version": "0.15.0",
4
+ "description": "Vue for Primate",
5
5
  "homepage": "https://primate.run/docs/frontend/vue",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",
7
+ "type": "module",
7
8
  "license": "MIT",
8
- "files": [
9
- "/lib/**/*.js",
10
- "/lib/**/*.d.ts",
11
- "!/**/*.spec.*"
12
- ],
13
9
  "repository": {
14
10
  "type": "git",
15
11
  "url": "https://github.com/primate-run/primate",
16
12
  "directory": "packages/vue"
17
13
  },
14
+ "files": [
15
+ "/lib/**/*.js",
16
+ "/lib/**/*.d.ts",
17
+ "!/**/*.spec.*"
18
+ ],
18
19
  "dependencies": {
19
- "@rcompat/build": "^0.15.0",
20
- "@primate/core": "^0.4.0"
20
+ "@primate/core": "^0.5.0"
21
+ },
22
+ "devDependencies": {
23
+ "@rcompat/type": "^0.9.0"
21
24
  },
22
25
  "peerDependencies": {
23
26
  "vue": "3",
24
- "primate": "^0.35.0"
27
+ "primate": "^0.36.0"
25
28
  },
26
- "type": "module",
27
29
  "imports": {
28
30
  "#*": {
29
31
  "apekit": "./src/private/*.ts",
@@ -1,11 +0,0 @@
1
- import type ValidateUpdater from "@primate/core/client/ValidateUpdater";
2
- import type ValidationError from "@primate/core/client/ValidationError";
3
- import { type Ref } from "vue";
4
- type Validated<T> = {
5
- error: Ref<null | ValidationError>;
6
- loading: Ref<boolean>;
7
- update: (updater: ValidateUpdater<T>) => Promise<void>;
8
- value: Ref<T>;
9
- };
10
- export type { Validated as default };
11
- //# sourceMappingURL=Validated.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Validated.js.map
@@ -1,34 +0,0 @@
1
- import spa from "@primate/core/client/spa";
2
- import { createSSRApp } from "vue";
3
- import root from "vue:root";
4
- import * as views from "vue:views";
5
- export default class VueClient {
6
- static mount(_view, data) {
7
- const resolve = (names) => names.map((n) => views[n]);
8
- let app = createSSRApp(root, {
9
- p: {
10
- views: resolve(data.views),
11
- props: data.props,
12
- request: data.request,
13
- update: undefined,
14
- },
15
- });
16
- app.mount("#app");
17
- if (data.spa) {
18
- window.addEventListener("DOMContentLoaded", () => spa((next, update) => {
19
- app.unmount();
20
- app = createSSRApp(root, {
21
- p: {
22
- views: resolve(next.views),
23
- props: next.props,
24
- request: next.request,
25
- update,
26
- },
27
- });
28
- app.mount("#app");
29
- update?.();
30
- }));
31
- }
32
- }
33
- }
34
- //# sourceMappingURL=index.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