@primate/vue 0.16.1 → 0.18.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";
@@ -2,9 +2,12 @@ import root from "#client/root";
2
2
  import client from "@primate/core/client";
3
3
  export default class VueApp {
4
4
  static mount(_view, data) {
5
+ const interactive = !data.ssr || data.csr;
6
+ if (!interactive)
7
+ return;
5
8
  let app = root[data.ssr ? "ssr" : "csr"](root.toProps(data));
6
9
  app.mount("#app");
7
- if (data.spa) {
10
+ if (data.csr) {
8
11
  const start = () => client.boot((next, update) => {
9
12
  app.unmount();
10
13
  app = root.csr(root.toProps(next, update));
@@ -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,14 +1,25 @@
1
1
  import core from "@primate/core/client";
2
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 ?? {});
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 = shallowRef(controller.read());
8
- const unsub = controller.subscribe((next) => {
19
+ const unsubscribe = controller.subscribe(next => {
9
20
  snapshot.value = next;
10
21
  });
11
- onUnmounted(unsub);
22
+ onUnmounted(unsubscribe);
12
23
  return {
13
24
  get id() {
14
25
  return snapshot.value.id;
@@ -19,6 +30,9 @@ function form(init) {
19
30
  get submitted() {
20
31
  return snapshot.value.submitted;
21
32
  },
33
+ get result() {
34
+ return snapshot.value.result;
35
+ },
22
36
  submit(event) {
23
37
  return controller.submit(event);
24
38
  },
@@ -1,3 +1,2 @@
1
- declare const _default: (depth: number, i18n_active: boolean) => string;
2
- export default _default;
1
+ export default function createRoot(depth: number): string;
3
2
  //# sourceMappingURL=create-root.d.ts.map
@@ -1,58 +1,31 @@
1
- export default (depth, i18n_active) => {
2
- const n = depth;
1
+ export default function createRoot(depth) {
3
2
  const build_view = (index) => {
4
- // anchor case: render the deepest view
5
- if (index === n)
3
+ if (index > depth)
4
+ return `h("div")`;
5
+ if (index === depth)
6
6
  return `h(p.views[${index}], p.props[${index}] || {})`;
7
- else {
8
- // recursive case: render view with child
9
- const child = build_view(index + 1);
10
- return `h(p.views[${index}], p.props[${index}] || {}, () => [${child}])`;
11
- }
7
+ const child = build_view(index + 1);
8
+ return `h(p.views[${index}], p.props[${index}] || {}, () => [${child}])`;
12
9
  };
13
- const body = depth > 0 ? build_view(0) : "h(\"div\")";
14
- const vueImports = `
15
- import {
16
- defineComponent, h${i18n_active ? ", ref, onMounted, onUnmounted" : ""}
17
- } from "vue";
18
- import { setRequest } from "@primate/vue/app";
19
- `;
20
- const i18nImports = i18n_active
21
- ? `
22
- import t from "#i18n";
23
- import sInternal from "primate/s/internal";`
24
- : "";
25
- const i18nSetup = i18n_active
26
- ? `
27
- const initialLocale = props.p?.request?.context?.i18n?.locale;
28
- if (initialLocale) t[sInternal].init(initialLocale);
29
-
30
- onMounted(() => { t[sInternal].restore(); });
31
-
32
- if (typeof window !== "undefined") {
33
- const version = ref(t[sInternal].version);
34
- const removeDepend = t[sInternal].depend(() => { void version.value; });
35
- const unsubscribe = t.onChange(() => {
36
- version.value = t[sInternal].version;
37
- });
38
- onUnmounted(() => { unsubscribe?.(); removeDepend?.(); });
39
- }`
40
- : "";
10
+ const body = `h(Suspense, null, { default: () => ${build_view(0)} })`;
41
11
  return `
42
- ${vueImports}
43
- ${i18nImports}
12
+ import { defineComponent, h, Suspense } from "vue";
13
+ import { setRequest } from "@primate/vue/app";
14
+
44
15
  export default defineComponent({
45
16
  name: "root",
46
17
  props: { p: { type: Object, required: true } },
18
+
47
19
  setup(props) {
48
- ${i18nSetup}
49
20
  return () => {
50
21
  const p = props.p;
51
- setRequest(props.p.request);
22
+
23
+ setRequest(p.request);
24
+
52
25
  return ${body};
53
26
  };
54
27
  },
55
28
  });
56
29
  `;
57
- };
30
+ }
58
31
  //# sourceMappingURL=create-root.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;
@@ -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,42 @@
1
+ import request from "#request/store";
2
+ import { ref, watch } from "vue";
3
+ export default function i18n(source) {
4
+ const version = ref(0);
5
+ const notify = () => { version.value += 1; };
6
+ const depend = () => {
7
+ void version.value;
8
+ };
9
+ const restore = (next) => {
10
+ const before = source.locale.get();
11
+ source.restore(next);
12
+ if (source.locale.get() !== before)
13
+ notify();
14
+ };
15
+ const get = () => {
16
+ depend();
17
+ return source.locale.get();
18
+ };
19
+ const set = (locale) => {
20
+ const before = source.locale.get();
21
+ source.locale.set(locale);
22
+ if (source.locale.get() !== before) {
23
+ notify();
24
+ }
25
+ };
26
+ const value = ((...args) => {
27
+ depend();
28
+ return source(...args);
29
+ });
30
+ value.defaultLocale = source.defaultLocale;
31
+ value.locales = source.locales;
32
+ value.catalogs = source.catalogs;
33
+ value.currency = source.currency;
34
+ value.locale = { get, set };
35
+ value.restore = restore;
36
+ restore(request.value);
37
+ watch(request, next => {
38
+ restore(next);
39
+ }, { immediate: false });
40
+ return value;
41
+ }
42
+ //# sourceMappingURL=i18n.js.map
@@ -26,10 +26,10 @@ declare const store: import("vue").Ref<{
26
26
  sort: () => void;
27
27
  toString: () => string;
28
28
  forEach: (callbackfn: (value: string, key: string, parent: URLSearchParams) => void, thisArg?: any) => void;
29
+ [Symbol.iterator]: () => URLSearchParamsIterator<[string, string]>;
29
30
  entries: () => URLSearchParamsIterator<[string, string]>;
30
31
  keys: () => URLSearchParamsIterator<string>;
31
32
  values: () => URLSearchParamsIterator<string>;
32
- [Symbol.iterator]: () => URLSearchParamsIterator<[string, string]>;
33
33
  };
34
34
  username: string;
35
35
  toJSON: () => string;
@@ -61,10 +61,10 @@ declare const store: import("vue").Ref<{
61
61
  sort: () => void;
62
62
  toString: () => string;
63
63
  forEach: (callbackfn: (value: string, key: string, parent: URLSearchParams) => void, thisArg?: any) => void;
64
+ [Symbol.iterator]: () => URLSearchParamsIterator<[string, string]>;
64
65
  entries: () => URLSearchParamsIterator<[string, string]>;
65
66
  keys: () => URLSearchParamsIterator<string>;
66
67
  values: () => URLSearchParamsIterator<string>;
67
- [Symbol.iterator]: () => URLSearchParamsIterator<[string, string]>;
68
68
  };
69
69
  username: string;
70
70
  toJSON: () => string;
@@ -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;
@@ -25,10 +25,10 @@ export declare function useRequest(): import("vue").Ref<{
25
25
  sort: () => void;
26
26
  toString: () => string;
27
27
  forEach: (callbackfn: (value: string, key: string, parent: URLSearchParams) => void, thisArg?: any) => void;
28
+ [Symbol.iterator]: () => URLSearchParamsIterator<[string, string]>;
28
29
  entries: () => URLSearchParamsIterator<[string, string]>;
29
30
  keys: () => URLSearchParamsIterator<string>;
30
31
  values: () => URLSearchParamsIterator<string>;
31
- [Symbol.iterator]: () => URLSearchParamsIterator<[string, string]>;
32
32
  };
33
33
  username: string;
34
34
  toJSON: () => string;
@@ -60,10 +60,10 @@ export declare function useRequest(): import("vue").Ref<{
60
60
  sort: () => void;
61
61
  toString: () => string;
62
62
  forEach: (callbackfn: (value: string, key: string, parent: URLSearchParams) => void, thisArg?: any) => void;
63
+ [Symbol.iterator]: () => URLSearchParamsIterator<[string, string]>;
63
64
  entries: () => URLSearchParamsIterator<[string, string]>;
64
65
  keys: () => URLSearchParamsIterator<string>;
65
66
  values: () => URLSearchParamsIterator<string>;
66
- [Symbol.iterator]: () => URLSearchParamsIterator<[string, string]>;
67
67
  };
68
68
  username: string;
69
69
  toJSON: () => string;
@@ -1,2 +1,6 @@
1
- export { default } from "#client/app";
1
+ export default function vue(): {
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 vue() {
2
+ return {
3
+ name: "vue",
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/vue",
3
- "version": "0.16.1",
3
+ "version": "0.18.0",
4
4
  "description": "Vue for Primate",
5
5
  "homepage": "https://primate.run/docs/frontend/vue",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",
@@ -18,15 +18,15 @@
18
18
  ],
19
19
  "types": "lib/index.d.ts",
20
20
  "dependencies": {
21
- "@primate/core": "^0.6.0"
21
+ "@rcompat/fs": "^0.33.2",
22
+ "@primate/core": "^0.8.0"
22
23
  },
23
24
  "devDependencies": {
24
- "@rcompat/type": "^0.11.1",
25
- "@primate/test": "^0.0.0"
25
+ "@rcompat/type": "^0.17.0"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "vue": "3",
29
- "primate": "^0.37.0"
29
+ "primate": "^0.39.0"
30
30
  },
31
31
  "imports": {
32
32
  "#*": {
@@ -37,8 +37,12 @@
37
37
  "exports": {
38
38
  ".": {
39
39
  "types": "./lib/index.d.ts",
40
+ "browser": {
41
+ "@primate/source": "./src/public/browser.ts",
42
+ "default": "./lib/public/browser.js"
43
+ },
44
+ "@primate/runtime": "./src/public/runtime.ts",
40
45
  "@primate/source": "./src/public/default.ts",
41
- "browser": "./lib/public/browser.js",
42
46
  "runtime": "./lib/public/runtime.js",
43
47
  "default": "./lib/public/default.js"
44
48
  },
@@ -48,9 +52,8 @@
48
52
  }
49
53
  },
50
54
  "scripts": {
51
- "build": "npm run clean && tsc && cp src/types/{app,index}.d.ts lib",
55
+ "build": "npm run clean && tsgo && cp src/types/{app,index}.d.ts lib",
52
56
  "clean": "rm -rf ./lib",
53
- "lint": "eslint .",
54
- "test": "npx proby"
57
+ "lint": "eslint ."
55
58
  }
56
59
  }