@platforma-sdk/ui-vue 1.51.8 → 1.52.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.
@@ -0,0 +1,121 @@
1
+ import { delay as $ } from "../lib/util/helpers/dist/utils.js";
2
+ import { uniqueId as V } from "../lib/util/helpers/dist/strings.js";
3
+ import { deepClone as c } from "../lib/util/helpers/dist/objects.js";
4
+ import { deriveDataFromStorage as M, unwrapResult as i, hasAbortError as z } from "@platforma-sdk/model";
5
+ import { ref as b, computed as p, reactive as E } from "vue";
6
+ import { parseQuery as J } from "../urls.js";
7
+ import { MultiError as L } from "../utils.js";
8
+ import "../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/index.js";
9
+ import { UpdateSerializer as I } from "./UpdateSerializer.js";
10
+ import { watchIgnorable as k } from "@vueuse/core";
11
+ import { applyPatch as P } from "../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/core.js";
12
+ const j = 150, B = (n) => ({
13
+ authorId: (n == null ? void 0 : n.authorId) ?? V(),
14
+ localVersion: ((n == null ? void 0 : n.localVersion) ?? 0) + 1
15
+ }), N = (n) => {
16
+ try {
17
+ return JSON.stringify(n, null, 2);
18
+ } catch (u) {
19
+ return u instanceof Error ? u.message : String(u);
20
+ }
21
+ };
22
+ function re(n, u, g) {
23
+ const r = (e, ...a) => {
24
+ g.debug && console.log(`%c>>> %c${e}`, "color: orange; font-weight: bold", "color: orange", ...a.map((t) => N(t)));
25
+ }, w = (e, ...a) => {
26
+ console.error(`%c>>> %c${e}`, "color: red; font-weight: bold", "color: red", ...a.map((t) => N(t)));
27
+ }, s = {
28
+ isExternalSnapshot: !1,
29
+ author: {
30
+ authorId: V(),
31
+ localVersion: 0
32
+ }
33
+ }, _ = () => (s.author = B(s.author), r("nextAuthorMarker", s.author), s.author), d = b(!1), m = b(n.uTag), S = g.debounceSpan ?? 200, v = new I({ debounceSpan: S }), Q = new I({ debounceSpan: S }), o = b(n.value), y = async (e) => u.mutateStorage({ operation: "update-data", value: e }, _()), R = async (e) => u.setNavigationState(e), O = p(() => {
34
+ const e = Object.entries(o.value.outputs).map(([a, t]) => [a, t.ok && t.value !== void 0 ? t.value : void 0]);
35
+ return Object.fromEntries(e);
36
+ }), q = p(() => {
37
+ const e = Object.entries(o.value.outputs).map(([a, t]) => [a, t && t.ok === !1 ? new L(t.errors) : void 0]);
38
+ return Object.fromEntries(e);
39
+ }), l = E({
40
+ apiVersion: 3,
41
+ error: "",
42
+ model: {
43
+ data: c(M(o.value.blockStorage)),
44
+ outputs: O,
45
+ outputErrors: q
46
+ }
47
+ }), { ignoreUpdates: D } = k(
48
+ () => l.model,
49
+ (e) => {
50
+ const a = c(e);
51
+ r("setDataQueue appModel.model, data", a.data), v.run(() => y(a.data).then(i));
52
+ },
53
+ { deep: !0 }
54
+ ), C = (e) => {
55
+ r("updateAppModel", e), l.model.data = c(e.data);
56
+ };
57
+ (async () => {
58
+ var e, a;
59
+ for (window.addEventListener("beforeunload", () => {
60
+ d.value = !0, u.dispose().then(i).catch((t) => {
61
+ w("error in dispose", t);
62
+ });
63
+ }); !d.value; )
64
+ try {
65
+ const t = await u.getPatches(m.value).then(i);
66
+ if (r("patches.length", t.value.length), r("uTagRef.value", m.value), r("patches.uTag", t.uTag), r("patches.author", t.author), r("data.author", s.author), m.value = t.uTag, t.value.length === 0) {
67
+ await new Promise((f) => setTimeout(f, j));
68
+ continue;
69
+ }
70
+ const h = ((e = s.author) == null ? void 0 : e.authorId) !== ((a = t.author) == null ? void 0 : a.authorId);
71
+ h || s.isExternalSnapshot ? (r("got external changes, applying them to the snapshot", t.value), D(() => {
72
+ o.value = P(o.value, t.value, !1, !1).newDocument, C({ data: M(o.value.blockStorage) }), s.isExternalSnapshot = h;
73
+ })) : (r("outputs changed", t.value), D(() => {
74
+ o.value = P(o.value, t.value).newDocument;
75
+ })), await new Promise((f) => setTimeout(f, j));
76
+ } catch (t) {
77
+ z(t) ? (r("patches loop aborted"), d.value = !0) : (w("error in patches loop", t), await new Promise((h) => setTimeout(h, 1e3)));
78
+ }
79
+ })();
80
+ const T = () => c(l.model.data), x = () => c(o.value.navigationState), F = {
81
+ cloneData: T,
82
+ cloneNavigationState: x,
83
+ /**
84
+ * Updates the UI state by applying a callback.
85
+ *
86
+ * @param cb - Callback to modify the current UI state.
87
+ * @returns A promise resolving after the update is applied.
88
+ * @todo Make it mutable since there is already an initial one
89
+ */
90
+ updateData(e) {
91
+ const a = e(T());
92
+ return r("updateData", a), l.model.data = a, v.run(() => y(a).then(i));
93
+ },
94
+ /**
95
+ * Navigates to a specific href by updating the navigation state.
96
+ *
97
+ * @param href - The target href to navigate to.
98
+ * @returns A promise resolving after the navigation state is updated.
99
+ */
100
+ navigateTo(e) {
101
+ const a = x();
102
+ return a.href = e, Q.run(() => R(a).then(i));
103
+ },
104
+ async allSettled() {
105
+ return await $(0), v.allSettled();
106
+ }
107
+ }, U = {
108
+ closedRef: d,
109
+ snapshot: o,
110
+ queryParams: p(() => J(o.value.navigationState.href)),
111
+ href: p(() => o.value.navigationState.href),
112
+ hasErrors: p(() => Object.values(o.value.outputs).some((e) => !(e != null && e.ok)))
113
+ }, A = E(Object.assign(l, F, U));
114
+ return g.debug && (globalThis.__block_app__ = A), A;
115
+ }
116
+ export {
117
+ re as createAppV3,
118
+ B as createNextAuthorMarker,
119
+ j as patchPoolingDelay
120
+ };
121
+ //# sourceMappingURL=createAppV3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAppV3.js","sources":["../../src/internal/createAppV3.ts"],"sourcesContent":["import { deepClone, delay, uniqueId } from '@milaboratories/helpers';\nimport type { Mutable } from '@milaboratories/helpers';\nimport type {\n NavigationState,\n BlockOutputsBase,\n BlockStateV3,\n PlatformaV3,\n ValueWithUTag,\n AuthorMarker,\n} from '@platforma-sdk/model';\nimport { hasAbortError, unwrapResult, deriveDataFromStorage } from '@platforma-sdk/model';\nimport type { Ref } from 'vue';\nimport { reactive, computed, ref } from 'vue';\nimport type { OutputValues, OutputErrors, AppSettings } from '../types';\nimport { parseQuery } from '../urls';\nimport { MultiError } from '../utils';\nimport { applyPatch } from 'fast-json-patch';\nimport { UpdateSerializer } from './UpdateSerializer';\nimport { watchIgnorable } from '@vueuse/core';\n\nexport const patchPoolingDelay = 150;\n\nexport const createNextAuthorMarker = (marker: AuthorMarker | undefined): AuthorMarker => ({\n authorId: marker?.authorId ?? uniqueId(),\n localVersion: (marker?.localVersion ?? 0) + 1,\n});\n\nconst stringifyForDebug = (v: unknown) => {\n try {\n return JSON.stringify(v, null, 2);\n } catch (err) {\n return err instanceof Error ? err.message : String(err);\n }\n};\n\n/**\n * Creates an application instance with reactive state management, outputs, and methods for state updates and navigation.\n *\n * @template Args - The type of arguments used in the application.\n * @template Outputs - The type of block outputs extending `BlockOutputsBase`.\n * @template Data - The type of the block data.\n * @template Href - The type of navigation href, defaulting to a string starting with `/`.\n *\n * @param state - Initial state of the application, including args, outputs, UI state, and navigation state.\n * @param platforma - A platform interface for interacting with block states.\n * @param settings - Application settings, such as debug flags.\n *\n * @returns A reactive application object with methods, getters, and state.\n */\nexport function createAppV3<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n Data = unknown,\n Href extends `/${string}` = `/${string}`,\n>(\n state: ValueWithUTag<BlockStateV3<Outputs, Data, Href>>,\n platforma: PlatformaV3<Args, Outputs, Data, Href>,\n settings: AppSettings,\n) {\n const debug = (msg: string, ...rest: unknown[]) => {\n if (settings.debug) {\n console.log(`%c>>> %c${msg}`, 'color: orange; font-weight: bold', 'color: orange', ...rest.map((r) => stringifyForDebug(r)));\n }\n };\n\n const error = (msg: string, ...rest: unknown[]) => {\n console.error(`%c>>> %c${msg}`, 'color: red; font-weight: bold', 'color: red', ...rest.map((r) => stringifyForDebug(r)));\n };\n\n const data = {\n isExternalSnapshot: false,\n author: {\n authorId: uniqueId(),\n localVersion: 0,\n },\n };\n\n const nextAuthorMarker = () => {\n data.author = createNextAuthorMarker(data.author);\n debug('nextAuthorMarker', data.author);\n return data.author;\n };\n\n const closedRef = ref(false);\n\n const uTagRef = ref(state.uTag);\n\n const debounceSpan = settings.debounceSpan ?? 200;\n\n const setDataQueue = new UpdateSerializer({ debounceSpan });\n const setNavigationStateQueue = new UpdateSerializer({ debounceSpan });\n /**\n * Reactive snapshot of the application state, including args, outputs, UI state, and navigation state.\n */\n const snapshot = ref<{\n outputs: Partial<Outputs>;\n blockStorage: unknown;\n navigationState: NavigationState<Href>;\n }>(state.value) as Ref<{\n outputs: Partial<Outputs>;\n blockStorage: unknown;\n navigationState: NavigationState<Href>;\n }>;\n\n const updateData = async (value: Data) => {\n return platforma.mutateStorage({ operation: 'update-data', value }, nextAuthorMarker());\n };\n\n const setNavigationState = async (state: NavigationState<Href>) => {\n return platforma.setNavigationState(state);\n };\n\n const outputs = computed<OutputValues<Outputs>>(() => {\n const entries = Object.entries(snapshot.value.outputs as Partial<Readonly<Outputs>>).map(([k, vOrErr]) => [k, vOrErr.ok && vOrErr.value !== undefined ? vOrErr.value : undefined]);\n return Object.fromEntries(entries);\n });\n\n const outputErrors = computed<OutputErrors<Outputs>>(() => {\n const entries = Object.entries(snapshot.value.outputs as Partial<Readonly<Outputs>>).map(([k, vOrErr]) => [k, vOrErr && vOrErr.ok === false ? new MultiError(vOrErr.errors) : undefined]);\n return Object.fromEntries(entries);\n });\n\n const appModel = reactive({\n apiVersion: 3,\n error: '',\n model: {\n data: deepClone(deriveDataFromStorage<Data>(snapshot.value.blockStorage)) as Data,\n outputs,\n outputErrors,\n },\n }) as {\n error: string;\n model: {\n data: Data;\n outputs: OutputValues<Outputs>;\n outputErrors: OutputErrors<Outputs>;\n };\n };\n\n const { ignoreUpdates } = watchIgnorable(\n () => appModel.model,\n (_newData) => {\n const newData = deepClone(_newData);\n debug('setDataQueue appModel.model, data', newData.data);\n setDataQueue.run(() => updateData(newData.data).then(unwrapResult));\n },\n { deep: true },\n );\n\n const updateAppModel = (newData: {\n data: Data;\n }) => {\n debug('updateAppModel', newData);\n appModel.model.data = deepClone(newData.data) as Data;\n };\n\n (async () => {\n window.addEventListener('beforeunload', () => {\n closedRef.value = true;\n platforma.dispose().then(unwrapResult).catch((err) => {\n error('error in dispose', err);\n });\n });\n\n while (!closedRef.value) {\n try {\n const patches = await platforma.getPatches(uTagRef.value).then(unwrapResult);\n\n debug('patches.length', patches.value.length);\n debug('uTagRef.value', uTagRef.value);\n debug('patches.uTag', patches.uTag);\n debug('patches.author', patches.author);\n debug('data.author', data.author);\n\n uTagRef.value = patches.uTag;\n\n if (patches.value.length === 0) {\n await new Promise((resolve) => setTimeout(resolve, patchPoolingDelay));\n continue;\n }\n\n const isAuthorChanged = data.author?.authorId !== patches.author?.authorId;\n\n // Immutable behavior, apply external changes to the snapshot\n if (isAuthorChanged || data.isExternalSnapshot) {\n debug('got external changes, applying them to the snapshot', patches.value);\n ignoreUpdates(() => {\n snapshot.value = applyPatch(snapshot.value, patches.value, false, false).newDocument;\n updateAppModel({ data: deriveDataFromStorage<Data>(snapshot.value.blockStorage) });\n data.isExternalSnapshot = isAuthorChanged;\n });\n } else {\n // Mutable behavior\n debug('outputs changed', patches.value);\n ignoreUpdates(() => {\n snapshot.value = applyPatch(snapshot.value, patches.value).newDocument;\n });\n }\n\n await new Promise((resolve) => setTimeout(resolve, patchPoolingDelay));\n } catch (err) {\n if (hasAbortError(err)) {\n debug('patches loop aborted');\n closedRef.value = true;\n } else {\n error('error in patches loop', err);\n await new Promise((resolve) => setTimeout(resolve, 1000));\n }\n }\n }\n })();\n\n const cloneData = () => deepClone(appModel.model.data) as Data;\n const cloneNavigationState = () => deepClone(snapshot.value.navigationState) as Mutable<NavigationState<Href>>;\n\n const methods = {\n cloneData,\n cloneNavigationState,\n /**\n * Updates the UI state by applying a callback.\n *\n * @param cb - Callback to modify the current UI state.\n * @returns A promise resolving after the update is applied.\n * @todo Make it mutable since there is already an initial one\n */\n updateData(cb: (data: Data) => Data): Promise<boolean> {\n const newData = cb(cloneData());\n debug('updateData', newData);\n appModel.model.data = newData;\n return setDataQueue.run(() => updateData(newData).then(unwrapResult));\n },\n /**\n * Navigates to a specific href by updating the navigation state.\n *\n * @param href - The target href to navigate to.\n * @returns A promise resolving after the navigation state is updated.\n */\n navigateTo(href: Href) {\n const newState = cloneNavigationState();\n newState.href = href;\n return setNavigationStateQueue.run(() => setNavigationState(newState).then(unwrapResult));\n },\n async allSettled() {\n await delay(0);\n return setDataQueue.allSettled();\n },\n };\n\n const getters = {\n closedRef,\n snapshot,\n queryParams: computed(() => parseQuery<Href>(snapshot.value.navigationState.href as Href)),\n href: computed(() => snapshot.value.navigationState.href),\n hasErrors: computed(() => Object.values(snapshot.value.outputs as Partial<Readonly<Outputs>>).some((v) => !v?.ok)),\n };\n\n const app = reactive(Object.assign(appModel, methods, getters));\n\n if (settings.debug) {\n // @ts-expect-error (to inspect in console in debug mode)\n globalThis.__block_app__ = app;\n }\n\n return app;\n}\n\nexport type BaseAppV3<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n Data = unknown,\n Href extends `/${string}` = `/${string}`,\n> = ReturnType<typeof createAppV3<Args, Outputs, Data, Href>>;\n"],"names":["patchPoolingDelay","createNextAuthorMarker","marker","uniqueId","stringifyForDebug","v","err","createAppV3","state","platforma","settings","debug","msg","rest","r","error","data","nextAuthorMarker","closedRef","ref","uTagRef","debounceSpan","setDataQueue","UpdateSerializer","setNavigationStateQueue","snapshot","updateData","value","setNavigationState","outputs","computed","entries","k","vOrErr","outputErrors","MultiError","appModel","reactive","deepClone","deriveDataFromStorage","ignoreUpdates","watchIgnorable","_newData","newData","unwrapResult","updateAppModel","patches","resolve","isAuthorChanged","_a","_b","applyPatch","hasAbortError","cloneData","cloneNavigationState","methods","cb","href","newState","delay","getters","parseQuery","app"],"mappings":";;;;;;;;;;;AAoBO,MAAMA,IAAoB,KAEpBC,IAAyB,CAACC,OAAoD;AAAA,EACzF,WAAUA,KAAA,gBAAAA,EAAQ,a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AGtBA;AACT;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useInfo.d.ts","sourceRoot":"","sources":["../../../src/plugins/Monetization/useInfo.ts"],"names":[],"mappings":"AAKA,wBAAgB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuEtB"}
1
+ {"version":3,"file":"useInfo.d.ts","sourceRoot":"","sources":["../../../src/plugins/Monetization/useInfo.ts"],"names":[],"mappings":"AAKA,wBAAgB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsFtB"}
@@ -1,70 +1,68 @@
1
- import { computed as n, ref as i, watch as g } from "vue";
2
- import { useSdkPlugin as h } from "../../defineApp.js";
3
- import { Response as D } from "./validation.js";
4
- import { useIntervalFn as O } from "@vueuse/core";
5
- function E() {
6
- const m = h(), s = n(() => m.loaded ? m.useApp() : void 0), a = n(() => {
7
- var e, o;
8
- return "__mnzDate" in ((o = (e = s.value) == null ? void 0 : e.model) == null ? void 0 : o.args);
9
- }), v = n(() => {
1
+ import { computed as t, ref as l, watch as _ } from "vue";
2
+ import { useSdkPlugin as S } from "../../defineApp.js";
3
+ import { Response as h } from "./validation.js";
4
+ import { useIntervalFn as k } from "@vueuse/core";
5
+ function M() {
6
+ const v = S(), c = t(() => v.loaded ? v.useApp() : void 0), z = (e) => e ? "data" in e ? e.data : "args" in e ? e.args : {} : {}, s = t(() => {
10
7
  var e;
11
- return D.safeParse((e = s.value) == null ? void 0 : e.model.outputs.__mnzInfo);
12
- }), c = n(() => {
8
+ return z((e = c.value) == null ? void 0 : e.model);
9
+ }), r = t(() => s.value && "__mnzDate" in s.value), f = t(() => {
13
10
  var e;
14
- return (e = v.value) == null ? void 0 : e.data;
15
- }), _ = n(() => {
16
- var e, o, p;
17
- return ((e = v.value) == null ? void 0 : e.error) ?? ((p = (o = u.value) == null ? void 0 : o.response) == null ? void 0 : p.error);
18
- }), u = i(void 0), r = i(!1), l = i(0);
19
- g([c], ([e]) => {
11
+ return h.safeParse((e = c.value) == null ? void 0 : e.model.outputs.__mnzInfo);
12
+ }), m = t(() => {
13
+ var e;
14
+ return (e = f.value) == null ? void 0 : e.data;
15
+ }), I = t(() => {
16
+ var e, n, g;
17
+ return ((e = f.value) == null ? void 0 : e.error) ?? ((g = (n = o.value) == null ? void 0 : n.response) == null ? void 0 : g.error);
18
+ }), o = l(void 0), u = l(!1), i = l(0);
19
+ _([m], ([e]) => {
20
20
  if (e) {
21
- u.value = e;
22
- const o = ++l.value;
21
+ o.value = e;
22
+ const n = ++i.value;
23
23
  setTimeout(() => {
24
- l.value === o && (r.value = !1);
24
+ i.value === n && (u.value = !1);
25
25
  }, 1e3);
26
26
  }
27
27
  }, { immediate: !0 });
28
- const t = n(() => {
29
- var e, o;
30
- return (o = (e = u.value) == null ? void 0 : e.response) == null ? void 0 : o.result;
31
- }), f = n(() => {
32
- var e;
33
- return !!((e = t.value) != null && e.canRun);
34
- }), z = n(() => {
28
+ const a = t(() => {
29
+ var e, n;
30
+ return (n = (e = o.value) == null ? void 0 : e.response) == null ? void 0 : n.result;
31
+ }), d = t(() => {
35
32
  var e;
36
- return c.value ? (e = t.value) == null ? void 0 : e.status : "";
37
- }), I = n(() => {
33
+ return !!((e = a.value) != null && e.canRun);
34
+ }), D = t(() => {
38
35
  var e;
39
- return (e = t.value) == null ? void 0 : e.customerEmail;
40
- }), P = n(() => {
36
+ return m.value ? (e = a.value) == null ? void 0 : e.status : "";
37
+ }), O = t(() => {
41
38
  var e;
42
- return (e = t.value) == null ? void 0 : e.mnz.endOfBillingPeriod;
43
- }), R = n(() => {
39
+ return (e = a.value) == null ? void 0 : e.customerEmail;
40
+ }), P = t(() => {
44
41
  var e;
45
- return (e = t.value) == null ? void 0 : e.mnz.limits;
46
- }), d = () => {
42
+ return (e = a.value) == null ? void 0 : e.mnz.endOfBillingPeriod;
43
+ }), R = t(() => {
47
44
  var e;
48
- r.value = !0, ((e = s.value) == null ? void 0 : e.model.args).__mnzDate = (/* @__PURE__ */ new Date()).toISOString();
45
+ return (e = a.value) == null ? void 0 : e.mnz.limits;
46
+ }), p = () => {
47
+ u.value = !0, s.value.__mnzDate = (/* @__PURE__ */ new Date()).toISOString();
49
48
  };
50
- return g(f, (e) => {
51
- var o;
52
- a.value && (((o = s.value) == null ? void 0 : o.model.args).__mnzCanRun = e);
53
- }), a.value && O(d, 6e4), {
54
- hasMonetization: a,
55
- result: t,
56
- error: _,
57
- canRun: f,
58
- status: z,
59
- customerEmail: I,
49
+ return _(d, (e) => {
50
+ r.value && (s.value.__mnzCanRun = e);
51
+ }), r.value && k(p, 6e4), {
52
+ hasMonetization: r,
53
+ result: a,
54
+ error: I,
55
+ canRun: d,
56
+ status: D,
57
+ customerEmail: O,
60
58
  endOfBillingPeriod: P,
61
59
  limits: R,
62
- refresh: d,
63
- version: l,
64
- isLoading: r
60
+ refresh: p,
61
+ version: i,
62
+ isLoading: u
65
63
  };
66
64
  }
67
65
  export {
68
- E as useInfo
66
+ M as useInfo
69
67
  };
70
68
  //# sourceMappingURL=useInfo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useInfo.js","sources":["../../../src/plugins/Monetization/useInfo.ts"],"sourcesContent":["import { computed, watch, ref } from 'vue';\nimport { useSdkPlugin } from '../../defineApp';\nimport { Response } from './validation';\nimport { useIntervalFn } from '@vueuse/core';\n\nexport function useInfo() {\n const sdk = useSdkPlugin();\n\n const app = computed(() => (sdk.loaded ? sdk.useApp() : undefined));\n\n const hasMonetization = computed(() => '__mnzDate' in (app.value?.model?.args as Record<string, unknown>));\n\n const parsed = computed(() => Response.safeParse(app.value?.model.outputs['__mnzInfo']));\n\n const currentInfo = computed<Response | undefined>(() => parsed.value?.data);\n\n const error = computed(() => parsed.value?.error ?? info.value?.response?.error);\n\n const info = ref<Response | undefined>(undefined);\n\n const isLoading = ref(false);\n\n const version = ref(0);\n\n watch([currentInfo], ([i]) => {\n if (i) {\n info.value = i;\n const v = ++version.value;\n setTimeout(() => {\n if (version.value === v) {\n isLoading.value = false;\n }\n }, 1000);\n }\n }, { immediate: true });\n\n const result = computed(() => info.value?.response?.result);\n\n const canRun = computed(() => !!result.value?.canRun);\n\n const status = computed(() => currentInfo.value ? result.value?.status : '');\n\n const customerEmail = computed(() => result.value?.customerEmail);\n\n const endOfBillingPeriod = computed(() => result.value?.mnz.endOfBillingPeriod);\n\n const limits = computed(() => result.value?.mnz.limits);\n\n const refresh = () => {\n isLoading.value = true;\n (app.value?.model.args as Record<string, unknown>)['__mnzDate'] = new Date().toISOString();\n };\n\n watch(canRun, (v) => {\n if (hasMonetization.value) {\n (app.value?.model.args as Record<string, unknown>)['__mnzCanRun'] = v;\n }\n });\n\n if (hasMonetization.value) {\n useIntervalFn(refresh, 60_000); // 1 minute\n }\n\n return {\n hasMonetization,\n result,\n error,\n canRun,\n status,\n customerEmail,\n endOfBillingPeriod,\n limits,\n refresh,\n version,\n isLoading,\n };\n}\n"],"names":["useInfo","sdk","useSdkPlugin","app","computed","hasMonetization","_b","_a","parsed","Response","currentInfo","error","_c","info","ref","isLoading","version","watch","i","v","result","canRun","status","customerEmail","endOfBillingPeriod","limits","refresh","useIntervalFn"],"mappings":";;;;AAKO,SAASA,IAAU;AACxB,QAAMC,IAAMC,EAAA,GAENC,IAAMC,EAAS,MAAOH,EAAI,SAASA,EAAI,OAAA,IAAW,MAAU,GAE5DI,IAAkBD,EAAS,MAAA;;AAAM,4BAAgBE,KAAAC,IAAAJ,EAAI,UAAJ,gBAAAI,EAAW,UAAX,gBAAAD,EAAkB;AAAA,GAAgC,GAEnGE,IAASJ,EAAS,MAAA;;AAAM,WAAAK,EAAS,WAAUF,IAAAJ,EAAI,UAAJ,gBAAAI,EAAW,MAAM,QAAQ,SAAY;AAAA,GAAC,GAEjFG,IAAcN,EAA+B,MAAA;;AAAM,YAAAG,IAAAC,EAAO,UAAP,gBAAAD,EAAc;AAAA,GAAI,GAErEI,IAAQP,EAAS,MAAA;;AAAM,aAAAG,IAAAC,EAAO,UAAP,gBAAAD,EAAc,YAASK,KA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,IAAId,EAAgB,YACjBE,IAAAJ,EAAI,UAAJ,gBAAAI,EAAW,MAAM,MAAiC,cAAiBY;AAAA,EAExE,CAAC,GAEGd,EAAgB,SAClBsB,EAAcD,GAAS,GAAM,GAGxB;AAAA,IACL,iBAAArB;AAAA,IACA,QAAAe;AAAA,IACA,OAAAT;AAAA,IACA,QAAAU;AAAA,IACA,QAAAC;AAAA,IACA,eAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,QAAAC;AAAA,IACA,SAAAC;AAAA,IACA,SAAAV;AAAA,IACA,WAAAD;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useInfo.js","sources":["../../../src/plugins/Monetization/useInfo.ts"],"sourcesContent":["import { computed, watch, ref } from 'vue';\nimport { useSdkPlugin } from '../../defineApp';\nimport { Response } from './validation';\nimport { useIntervalFn } from '@vueuse/core';\n\nexport function useInfo() {\n const sdk = useSdkPlugin();\n\n const app = computed(() => (sdk.loaded ? sdk.useApp() : undefined));\n\n // TODO use a separate plugin state when it's implemented\n const getModelArgsOrState = (model: Record<string, unknown> | undefined) => {\n if (!model) return {};\n if ('data' in model) {\n return model.data as Record<string, unknown>;\n } else if ('args' in model) {\n return model.args as Record<string, unknown>;\n }\n return {};\n };\n\n const inputData = computed(() => getModelArgsOrState(app.value?.model));\n\n const hasMonetization = computed(() => {\n return inputData.value && ('__mnzDate' in inputData.value);\n });\n\n const parsed = computed(() => Response.safeParse(app.value?.model.outputs['__mnzInfo']));\n\n const currentInfo = computed<Response | undefined>(() => parsed.value?.data);\n\n const error = computed(() => parsed.value?.error ?? info.value?.response?.error);\n\n const info = ref<Response | undefined>(undefined);\n\n const isLoading = ref(false);\n\n const version = ref(0);\n\n watch([currentInfo], ([i]) => {\n if (i) {\n info.value = i;\n const v = ++version.value;\n setTimeout(() => {\n if (version.value === v) {\n isLoading.value = false;\n }\n }, 1000);\n }\n }, { immediate: true });\n\n const result = computed(() => info.value?.response?.result);\n\n const canRun = computed(() => !!result.value?.canRun);\n\n const status = computed(() => currentInfo.value ? result.value?.status : '');\n\n const customerEmail = computed(() => result.value?.customerEmail);\n\n const endOfBillingPeriod = computed(() => result.value?.mnz.endOfBillingPeriod);\n\n const limits = computed(() => result.value?.mnz.limits);\n\n const refresh = () => {\n isLoading.value = true;\n (inputData.value)['__mnzDate'] = new Date().toISOString();\n };\n\n watch(canRun, (v) => {\n if (hasMonetization.value) {\n (inputData.value as Record<string, unknown>)['__mnzCanRun'] = v;\n }\n });\n\n if (hasMonetization.value) {\n useIntervalFn(refresh, 60_000); // 1 minute\n }\n\n return {\n hasMonetization,\n result,\n error,\n canRun,\n status,\n customerEmail,\n endOfBillingPeriod,\n limits,\n refresh,\n version,\n isLoading,\n };\n}\n"],"names":["useInfo","sdk","useSdkPlugin","app","computed","getModelArgsOrState","model","inputData","_a","hasMonetization","parsed","Response","currentInfo","error","_c","_b","info","ref","isLoading","version","watch","i","v","result","canRun","status","customerEmail","endOfBillingPeriod","limits","refresh","useIntervalFn"],"mappings":";;;;AAKO,SAASA,IAAU;AACxB,QAAMC,IAAMC,EAAA,GAENC,IAAMC,EAAS,MAAOH,EAAI,SAASA,EAAI,OAAA,IAAW,MAAU,GAG5DI,IAAsB,CAACC,MACtBA,IACD,UAAUA,IACLA,EAAM,OACJ,UAAUA,IACZA,EAAM,OAER,CAAA,IANY,CAAA,GASfC,IAAYH,EAAS,MAAA;;AAAM,WAAAC,GAAoBG,IAAAL,EAAI,UAAJ,gBAAAK,EAAW,KAAK;AAAA,GAAC,GAEhEC,IAAkBL,EAAS,MACxBG,EAAU,SAAU,eAAeA,EAAU,KACrD,GAEKG,IAASN,EAAS,MAAA;;AAAM,WAAAO,EAAS,WAAUH,IAAAL,EAAI,UAAJ,gBAAAK,EAAW,MAAM,QAAQ,SAAY;AAAA,GAAC,GAEjFI,IAAcR,EAA+B,MAAA;;AAAM,YAAAI,IAAAE,EAAO,UAAP,gBAAAF,EAAc;AAAA,GAAI,GAErEK,IAAQT,EAAS,MAAA;;AAA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ACF,MAAM;AACnB,IAAIb,EAAgB,UACjBF,EAAU,MAAkC,cAAiBe;AAAA,EAElE,CAAC,GAEGb,EAAgB,SAClBqB,EAAcD,GAAS,GAAM,GAGxB;AAAA,IACL,iBAAApB;AAAA,IACA,QAAAc;AAAA,IACA,OAAAV;AAAA,IACA,QAAAW;AAAA,IACA,QAAAC;AAAA,IACA,eAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,QAAAC;AAAA,IACA,SAAAC;AAAA,IACA,SAAAV;AAAA,IACA,WAAAD;AAAA,EAAA;AAEJ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/ui-vue",
3
- "version": "1.51.8",
3
+ "version": "1.52.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "styles": "dist/index.js",
@@ -27,10 +27,10 @@
27
27
  "zod": "~3.23.8",
28
28
  "@zip.js/zip.js": "^2.8.2",
29
29
  "es-toolkit": "^1.39.10",
30
- "@milaboratories/ptabler-expression-js": "1.1.9",
31
- "@milaboratories/uikit": "2.10.3",
30
+ "@milaboratories/ptabler-expression-js": "1.1.10",
32
31
  "@milaboratories/biowasm-tools": "2.0.0",
33
- "@platforma-sdk/model": "1.51.6"
32
+ "@platforma-sdk/model": "1.52.0",
33
+ "@milaboratories/uikit": "2.10.5"
34
34
  },
35
35
  "devDependencies": {
36
36
  "happy-dom": "^15.11.7",
@@ -47,11 +47,11 @@
47
47
  "yarpm": "^1.2.0",
48
48
  "fast-json-patch": "^3.1.1",
49
49
  "@faker-js/faker": "^9.2.0",
50
- "@milaboratories/build-configs": "1.2.2",
51
50
  "@milaboratories/eslint-config": "1.0.5",
51
+ "@milaboratories/build-configs": "1.2.2",
52
+ "@milaboratories/ts-builder": "1.2.2",
52
53
  "@milaboratories/helpers": "1.13.0",
53
- "@milaboratories/ts-configs": "1.2.0",
54
- "@milaboratories/ts-builder": "1.2.2"
54
+ "@milaboratories/ts-configs": "1.2.0"
55
55
  },
56
56
  "scripts": {
57
57
  "test": "vitest run --coverage",
package/src/defineApp.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { notEmpty } from '@milaboratories/helpers';
2
- import type { PlatformaExtended, PlatformaV1, PlatformaV2 } from '@platforma-sdk/model';
3
- import { getPlatformaApiVersion, unwrapResult, type BlockOutputsBase, type Platforma } from '@platforma-sdk/model';
2
+ import type { PlatformaExtended, PlatformaV3, PlatformaV1, PlatformaV2 } from '@platforma-sdk/model';
3
+ import { getPlatformaApiVersion, unwrapResult, type BlockOutputsBase, type Platforma, type BlockModelInfo } from '@platforma-sdk/model';
4
4
  import type { Component, Reactive } from 'vue';
5
5
  import { inject, markRaw, reactive } from 'vue';
6
6
  import { createAppV1, type BaseAppV1 } from './internal/createAppV1';
7
7
  import { createAppV2, type BaseAppV2 } from './internal/createAppV2';
8
+ import { createAppV3, type BaseAppV3 } from './internal/createAppV3';
8
9
  import type { AppSettings, ExtendSettings, Routes } from './types';
9
10
  import { activateAgGrid } from './aggrid';
10
11
 
@@ -21,7 +22,9 @@ export function defineApp<
21
22
  Href extends `/${string}` = `/${string}`,
22
23
  Extend extends ExtendSettings<Href> = ExtendSettings<Href>,
23
24
  >(
24
- platforma: PlatformaExtended<PlatformaV1<Args, Outputs, UiState, Href>>,
25
+ platforma: PlatformaV1<Args, Outputs, UiState, Href> & {
26
+ blockModelInfo: BlockModelInfo;
27
+ },
25
28
  extendApp: (app: BaseAppV1<Args, Outputs, UiState, Href>) => Extend,
26
29
  settings?: AppSettings,
27
30
  ): SdkPluginV1<Args, Outputs, UiState, Href, Extend>;
@@ -33,7 +36,9 @@ export function defineApp<
33
36
  Href extends `/${string}` = `/${string}`,
34
37
  Extend extends ExtendSettings<Href> = ExtendSettings<Href>,
35
38
  >(
36
- platforma: PlatformaExtended<PlatformaV2<Args, Outputs, UiState, Href>>,
39
+ platforma: PlatformaV2<Args, Outputs, UiState, Href> & {
40
+ blockModelInfo: BlockModelInfo;
41
+ },
37
42
  extendApp: (app: BaseAppV2<Args, Outputs, UiState, Href>) => Extend,
38
43
  settings?: AppSettings,
39
44
  ): SdkPluginV2<Args, Outputs, UiState, Href, Extend>;
@@ -41,16 +46,30 @@ export function defineApp<
41
46
  export function defineApp<
42
47
  Args = unknown,
43
48
  Outputs extends BlockOutputsBase = BlockOutputsBase,
44
- UiState = unknown,
49
+ Data = unknown,
50
+ Href extends `/${string}` = `/${string}`,
51
+ Extend extends ExtendSettings<Href> = ExtendSettings<Href>,
52
+ >(
53
+ platforma: PlatformaV3<Args, Outputs, Data, Href> & {
54
+ blockModelInfo: BlockModelInfo;
55
+ },
56
+ extendApp: (app: BaseAppV3<Args, Outputs, Data, Href>) => Extend,
57
+ settings?: AppSettings,
58
+ ): SdkPluginV3<Args, Outputs, Data, Href, Extend>;
59
+
60
+ export function defineApp<
61
+ Args = unknown,
62
+ Outputs extends BlockOutputsBase = BlockOutputsBase,
63
+ UiStateOrData = unknown,
45
64
  Href extends `/${string}` = `/${string}`,
46
65
  Extend extends ExtendSettings<Href> = ExtendSettings<Href>,
47
66
  >(
48
- platforma: PlatformaExtended<Platforma<Args, Outputs, UiState, Href>>,
67
+ platforma: PlatformaExtended<Platforma<Args, Outputs, UiStateOrData, Href>>,
49
68
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
69
  extendApp: (app: any) => Extend,
51
70
  settings: AppSettings = {},
52
- ): SdkPlugin<Args, Outputs, UiState, Href, Extend> {
53
- let app: undefined | AppV1<Args, Outputs, UiState, Href, Extend> | AppV2<Args, Outputs, UiState, Href, Extend> = undefined;
71
+ ): SdkPlugin<Args, Outputs, UiStateOrData, Href, Extend> {
72
+ let app: undefined | AppV1<Args, Outputs, UiStateOrData, Href, Extend> | AppV2<Args, Outputs, UiStateOrData, Href, Extend> | AppV3<Args, Outputs, UiStateOrData, Href, Extend> = undefined;
54
73
 
55
74
  activateAgGrid();
56
75
 
@@ -69,7 +88,7 @@ export function defineApp<
69
88
  .loadBlockState()
70
89
  .then((state) => {
71
90
  plugin.loaded = true;
72
- const baseApp = createAppV1<Args, Outputs, UiState, Href>(state, platforma, settings);
91
+ const baseApp = createAppV1<Args, Outputs, UiStateOrData, Href>(state, platforma, settings);
73
92
 
74
93
  const localState = extendApp(baseApp);
75
94
 
@@ -85,7 +104,7 @@ export function defineApp<
85
104
  getRoute(href: Href): Component | undefined {
86
105
  return routes[href];
87
106
  },
88
- } as unknown as AppV1<Args, Outputs, UiState, Href, Extend>);
107
+ } as unknown as AppV1<Args, Outputs, UiStateOrData, Href, Extend>);
89
108
  });
90
109
  } else if (platforma.apiVersion === 2) {
91
110
  await platforma
@@ -93,7 +112,7 @@ export function defineApp<
93
112
  .then((stateOrError) => {
94
113
  const state = unwrapResult(stateOrError);
95
114
  plugin.loaded = true;
96
- const baseApp = createAppV2<Args, Outputs, UiState, Href>(state, platforma, settings);
115
+ const baseApp = createAppV2<Args, Outputs, UiStateOrData, Href>(state, platforma, settings);
97
116
 
98
117
  const localState = extendApp(baseApp);
99
118
 
@@ -109,17 +128,42 @@ export function defineApp<
109
128
  getRoute(href: Href): Component | undefined {
110
129
  return routes[href];
111
130
  },
112
- } as unknown as AppV2<Args, Outputs, UiState, Href, Extend>);
131
+ } as unknown as AppV2<Args, Outputs, UiStateOrData, Href, Extend>);
132
+ });
133
+ } else if (platforma.apiVersion === 3) {
134
+ await platforma
135
+ .loadBlockState()
136
+ .then((stateOrError) => {
137
+ const state = unwrapResult(stateOrError);
138
+ plugin.loaded = true;
139
+ const baseApp = createAppV3<Args, Outputs, UiStateOrData, Href>(state, platforma, settings);
140
+
141
+ const localState = extendApp(baseApp);
142
+
143
+ const routes = Object.fromEntries(
144
+ Object.entries(localState.routes as Routes<Href>).map(([href, component]) => {
145
+ const c = typeof component === 'function' ? component() : component;
146
+ return [href, markRaw(c as Component)];
147
+ }),
148
+ );
149
+
150
+ app = Object.assign(baseApp, {
151
+ ...localState,
152
+ getRoute(href: Href): Component | undefined {
153
+ return routes[href];
154
+ },
155
+ } as unknown as AppV3<Args, Outputs, UiStateOrData, Href, Extend>);
113
156
  });
114
157
  }
115
158
  };
116
159
 
117
160
  const plugin = reactive({
161
+ apiVersion: platforma.apiVersion ?? 1,
118
162
  loaded: false,
119
163
  error: undefined as unknown,
120
164
  // Href to get typed query parameters for a specific route
121
165
  useApp<PageHref extends Href = Href>() {
122
- return notEmpty(app, 'App is not loaded') as App<Args, Outputs, UiState, PageHref, Extend>;
166
+ return notEmpty(app, 'App is not loaded') as App<Args, Outputs, UiStateOrData, PageHref, Extend>;
123
167
  },
124
168
  // @todo type portability issue with Vue
125
169
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -132,7 +176,7 @@ export function defineApp<
132
176
  },
133
177
  });
134
178
 
135
- return plugin as SdkPlugin<Args, Outputs, UiState, Href, Extend>;
179
+ return plugin as SdkPlugin<Args, Outputs, UiStateOrData, Href, Extend>;
136
180
  }
137
181
 
138
182
  export type AppV1<
@@ -151,13 +195,21 @@ export type AppV2<
151
195
  Local extends ExtendSettings<Href> = ExtendSettings<Href>,
152
196
  > = (BaseAppV2<Args, Outputs, UiState, Href>) & Reactive<Omit<Local, 'routes'>> & { getRoute(href: Href): Component | undefined };
153
197
 
198
+ export type AppV3<
199
+ Args = unknown,
200
+ Outputs extends BlockOutputsBase = BlockOutputsBase,
201
+ Data = unknown,
202
+ Href extends `/${string}` = `/${string}`,
203
+ Local extends ExtendSettings<Href> = ExtendSettings<Href>,
204
+ > = (BaseAppV3<Args, Outputs, Data, Href>) & Reactive<Omit<Local, 'routes'>> & { getRoute(href: Href): Component | undefined };
205
+
154
206
  export type App<
155
207
  Args = unknown,
156
208
  Outputs extends BlockOutputsBase = BlockOutputsBase,
157
209
  UiState = unknown,
158
210
  Href extends `/${string}` = `/${string}`,
159
211
  Local extends ExtendSettings<Href> = ExtendSettings<Href>,
160
- > = AppV1<Args, Outputs, UiState, Href, Local> | AppV2<Args, Outputs, UiState, Href, Local>;
212
+ > = AppV1<Args, Outputs, UiState, Href, Local> | AppV2<Args, Outputs, UiState, Href, Local> | AppV3<Args, Outputs, UiState, Href, Local>;
161
213
 
162
214
  export type SdkPluginV1<
163
215
  Args = unknown,
@@ -166,6 +218,7 @@ export type SdkPluginV1<
166
218
  Href extends `/${string}` = `/${string}`,
167
219
  Local extends ExtendSettings<Href> = ExtendSettings<Href>,
168
220
  > = {
221
+ apiVersion: 1;
169
222
  loaded: boolean;
170
223
  error: unknown;
171
224
  useApp<PageHref extends Href = Href>(): AppV1<Args, Outputs, UiState, PageHref, Local>;
@@ -179,16 +232,31 @@ export type SdkPluginV2<
179
232
  Href extends `/${string}` = `/${string}`,
180
233
  Local extends ExtendSettings<Href> = ExtendSettings<Href>,
181
234
  > = {
235
+ apiVersion: 2;
182
236
  loaded: boolean;
183
237
  error: unknown;
184
238
  useApp<PageHref extends Href = Href>(): AppV2<Args, Outputs, UiState, PageHref, Local>;
185
239
  install(app: unknown): void;
186
240
  };
187
241
 
242
+ export type SdkPluginV3<
243
+ Args = unknown,
244
+ Outputs extends BlockOutputsBase = BlockOutputsBase,
245
+ Data = unknown,
246
+ Href extends `/${string}` = `/${string}`,
247
+ Local extends ExtendSettings<Href> = ExtendSettings<Href>,
248
+ > = {
249
+ apiVersion: 3;
250
+ loaded: boolean;
251
+ error: unknown;
252
+ useApp<PageHref extends Href = Href>(): AppV3<Args, Outputs, Data, PageHref, Local>;
253
+ install(app: unknown): void;
254
+ };
255
+
188
256
  export type SdkPlugin<
189
257
  Args = unknown,
190
258
  Outputs extends BlockOutputsBase = BlockOutputsBase,
191
259
  UiState = unknown,
192
260
  Href extends `/${string}` = `/${string}`,
193
261
  Local extends ExtendSettings<Href> = ExtendSettings<Href>,
194
- > = SdkPluginV1<Args, Outputs, UiState, Href, Local> | SdkPluginV2<Args, Outputs, UiState, Href, Local>;
262
+ > = SdkPluginV1<Args, Outputs, UiState, Href, Local> | SdkPluginV2<Args, Outputs, UiState, Href, Local> | SdkPluginV3<Args, Outputs, UiState, Href, Local>;
@@ -85,6 +85,7 @@ export function createAppV2<
85
85
  const setUiStateQueue = new UpdateSerializer({ debounceSpan });
86
86
  const setArgsAndUiStateQueue = new UpdateSerializer({ debounceSpan });
87
87
  const setNavigationStateQueue = new UpdateSerializer({ debounceSpan });
88
+
88
89
  /**
89
90
  * Reactive snapshot of the application state, including args, outputs, UI state, and navigation state.
90
91
  */