@platforma-sdk/ui-vue 1.82.1 → 1.83.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/.turbo/turbo-build.log +12 -15
- package/.turbo/turbo-formatter$colon$check.log +2 -2
- package/.turbo/turbo-linter$colon$check.log +2 -2
- package/.turbo/turbo-types$colon$check.log +1 -1
- package/CHANGELOG.md +45 -0
- package/dist/components/PlAnnotations/components/PlAnnotations.vue2.js.map +1 -1
- package/dist/defineApp.d.ts +2 -32
- package/dist/defineApp.d.ts.map +1 -1
- package/dist/defineApp.js +20 -62
- package/dist/defineApp.js.map +1 -1
- package/dist/index.js +39 -39
- package/dist/internal/createAppV3.js +16 -16
- package/dist/lib/util/helpers/dist/utils.js +2 -5
- package/dist/lib/util/helpers/dist/utils.js.map +1 -1
- package/dist/lib.js +1 -1
- package/package.json +7 -7
- package/src/defineApp.ts +1 -183
- package/dist/internal/createAppModel.d.ts +0 -7
- package/dist/internal/createAppModel.d.ts.map +0 -1
- package/dist/internal/createAppModel.js +0 -57
- package/dist/internal/createAppModel.js.map +0 -1
- package/dist/internal/createAppV1.d.ts +0 -53
- package/dist/internal/createAppV1.d.ts.map +0 -1
- package/dist/internal/createAppV1.js +0 -129
- package/dist/internal/createAppV1.js.map +0 -1
- package/dist/internal/createAppV2.d.ts +0 -50
- package/dist/internal/createAppV2.d.ts.map +0 -1
- package/dist/internal/createAppV2.js +0 -137
- package/dist/internal/createAppV2.js.map +0 -1
- package/dist/internal/createAppV2.test.d.ts +0 -15
- package/dist/internal/createAppV2.test.d.ts.map +0 -1
- package/dist/internal/test-helpers/BlockMock.d.ts +0 -29
- package/dist/internal/test-helpers/BlockMock.d.ts.map +0 -1
- package/dist/internal/test-helpers/createMockApi.d.ts +0 -4
- package/dist/internal/test-helpers/createMockApi.d.ts.map +0 -1
- package/dist/internal/test-helpers/utils.d.ts +0 -4
- package/dist/internal/test-helpers/utils.d.ts.map +0 -1
- package/dist/internal/v1.static-test.d.ts +0 -7
- package/dist/internal/v1.static-test.d.ts.map +0 -1
- package/dist/internal/v2.static-test.d.ts +0 -7
- package/dist/internal/v2.static-test.d.ts.map +0 -1
- package/src/internal/createAppModel.ts +0 -112
- package/src/internal/createAppV1.ts +0 -324
- package/src/internal/createAppV2.test.ts +0 -207
- package/src/internal/createAppV2.ts +0 -392
- package/src/internal/test-helpers/BlockMock.ts +0 -161
- package/src/internal/test-helpers/createMockApi.ts +0 -104
- package/src/internal/test-helpers/utils.ts +0 -65
- package/src/internal/v1.static-test.ts +0 -107
- package/src/internal/v2.static-test.ts +0 -107
|
@@ -2,15 +2,15 @@ import { delay as e } from "../lib/util/helpers/dist/utils.js";
|
|
|
2
2
|
import { uniqueId as t } from "../lib/util/helpers/dist/strings.js";
|
|
3
3
|
import { deepClone as n } from "../lib/util/helpers/dist/objects.js";
|
|
4
4
|
import "../lib/util/helpers/dist/index.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { parseQuery as r } from "../urls.js";
|
|
6
|
+
import { MultiError as i, ensureOutputHasStableFlag as a } from "../utils.js";
|
|
7
7
|
import { UpdateSerializer as o } from "./UpdateSerializer.js";
|
|
8
8
|
import { logDebug as s, logError as c } from "./utils.js";
|
|
9
9
|
import { getServices as l } from "./getServices.js";
|
|
10
10
|
import { computed as u, markRaw as d, reactive as f, ref as p } from "vue";
|
|
11
11
|
import { deriveDataFromStorage as m, getPluginData as h, hasAbortError as g, isPluginOutputKey as _, pluginOutputPrefix as v, unwrapResult as y } from "@platforma-sdk/model";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { applyPatch as b } from "fast-json-patch";
|
|
13
|
+
import { watchIgnorable as x } from "@vueuse/core";
|
|
14
14
|
var S = (e) => ({
|
|
15
15
|
authorId: e?.authorId ?? t(),
|
|
16
16
|
localVersion: (e?.localVersion ?? 0) + 1
|
|
@@ -33,10 +33,10 @@ function C(C, w, T) {
|
|
|
33
33
|
pluginId: e,
|
|
34
34
|
value: t
|
|
35
35
|
}, k()), V = async (e) => w.setNavigationState(e), H = u(() => {
|
|
36
|
-
let e = Object.entries(R.value.outputs).filter(([e]) => !_(e)).map(([e, t]) => w.blockModelInfo.outputs[e]?.withStatus ? [e,
|
|
36
|
+
let e = Object.entries(R.value.outputs).filter(([e]) => !_(e)).map(([e, t]) => w.blockModelInfo.outputs[e]?.withStatus ? [e, a(t)] : [e, t.ok && t.value !== void 0 ? t.value : void 0]);
|
|
37
37
|
return Object.fromEntries(e);
|
|
38
38
|
}), U = u(() => {
|
|
39
|
-
let e = Object.entries(R.value.outputs).filter(([e]) => !_(e)).map(([e, t]) => [e, t && t.ok === !1 ? new
|
|
39
|
+
let e = Object.entries(R.value.outputs).filter(([e]) => !_(e)).map(([e, t]) => [e, t && t.ok === !1 ? new i(t.errors) : void 0]);
|
|
40
40
|
return Object.fromEntries(e);
|
|
41
41
|
}), W = f({
|
|
42
42
|
apiVersion: 3,
|
|
@@ -46,7 +46,7 @@ function C(C, w, T) {
|
|
|
46
46
|
outputs: H,
|
|
47
47
|
outputErrors: U
|
|
48
48
|
}
|
|
49
|
-
}), { ignoreUpdates: G } =
|
|
49
|
+
}), { ignoreUpdates: G } = x(() => W.model, (e) => {
|
|
50
50
|
let t = n(e);
|
|
51
51
|
E("setDataQueue appModel.model, data", t.data), N.run(() => z(t.data).then(y));
|
|
52
52
|
}, { deep: !0 }), K = (e) => {
|
|
@@ -65,13 +65,13 @@ function C(C, w, T) {
|
|
|
65
65
|
}
|
|
66
66
|
let t = O.author?.authorId !== e.author?.authorId;
|
|
67
67
|
t || O.isExternalSnapshot ? (E("got external changes, applying them to the snapshot", e.value), G(() => {
|
|
68
|
-
R.value =
|
|
68
|
+
R.value = b(R.value, e.value, !1, !1).newDocument, K({ data: m(R.value.blockStorage) });
|
|
69
69
|
for (let [e, t] of L) t.ignoreUpdates(() => {
|
|
70
70
|
t.model.data = n(h(R.value.blockStorage, e));
|
|
71
71
|
});
|
|
72
72
|
O.isExternalSnapshot = t;
|
|
73
73
|
})) : (E("outputs changed", e.value), G(() => {
|
|
74
|
-
R.value =
|
|
74
|
+
R.value = b(R.value, e.value).newDocument;
|
|
75
75
|
})), await new Promise((e) => setTimeout(e, 150));
|
|
76
76
|
} catch (e) {
|
|
77
77
|
g(e) ? (E("patches loop aborted"), A.value = !0) : (D("error in patches loop", e), await new Promise((e) => setTimeout(e, 1e3)));
|
|
@@ -94,23 +94,23 @@ function C(C, w, T) {
|
|
|
94
94
|
await Promise.all(t);
|
|
95
95
|
}
|
|
96
96
|
}, X = l({ platforma: w }), Z = (e) => {
|
|
97
|
-
let t = v(e),
|
|
97
|
+
let t = v(e), r = u(() => {
|
|
98
98
|
let e = {};
|
|
99
99
|
for (let [n, r] of Object.entries(R.value.outputs)) {
|
|
100
100
|
if (!n.startsWith(t)) continue;
|
|
101
|
-
let
|
|
102
|
-
w.blockModelInfo.outputs[n]?.withStatus ? e[
|
|
101
|
+
let i = n.slice(t.length);
|
|
102
|
+
w.blockModelInfo.outputs[n]?.withStatus ? e[i] = r ? a(r) : void 0 : e[i] = r.ok && r.value !== void 0 ? r.value : void 0;
|
|
103
103
|
}
|
|
104
104
|
return e;
|
|
105
105
|
}), o = u(() => {
|
|
106
106
|
let e = {};
|
|
107
|
-
for (let [n,
|
|
107
|
+
for (let [n, r] of Object.entries(R.value.outputs)) n.startsWith(t) && (e[n.slice(t.length)] = r && r.ok === !1 ? new i(r.errors) : void 0);
|
|
108
108
|
return e;
|
|
109
109
|
}), s = f({
|
|
110
110
|
data: n(h(R.value.blockStorage, e)),
|
|
111
|
-
outputs:
|
|
111
|
+
outputs: r,
|
|
112
112
|
outputErrors: o
|
|
113
|
-
}), { ignoreUpdates: c } =
|
|
113
|
+
}), { ignoreUpdates: c } = x(() => s.data, (t) => {
|
|
114
114
|
t !== void 0 && (E("plugin setData", e, t), F(e).run(() => B(e, n(t)).then(y)));
|
|
115
115
|
}, { deep: !0 });
|
|
116
116
|
return {
|
|
@@ -145,7 +145,7 @@ function C(C, w, T) {
|
|
|
145
145
|
}];
|
|
146
146
|
})),
|
|
147
147
|
services: d(X),
|
|
148
|
-
queryParams: u(() =>
|
|
148
|
+
queryParams: u(() => r(R.value.navigationState.href)),
|
|
149
149
|
href: u(() => R.value.navigationState.href),
|
|
150
150
|
hasErrors: u(() => Object.values(R.value.outputs).some((e) => !e?.ok))
|
|
151
151
|
}, $ = Object.assign(f(Object.assign(W, ee)), Y);
|
|
@@ -20,12 +20,9 @@ function r(e) {
|
|
|
20
20
|
return new Promise((t) => setTimeout(t, e));
|
|
21
21
|
}
|
|
22
22
|
function i(e, t) {
|
|
23
|
-
return t(e);
|
|
24
|
-
}
|
|
25
|
-
function a(e, t) {
|
|
26
23
|
if (e != null) return t(e);
|
|
27
24
|
}
|
|
28
|
-
var
|
|
25
|
+
var a = class {
|
|
29
26
|
promises = /* @__PURE__ */ new Map();
|
|
30
27
|
fetch(e, t) {
|
|
31
28
|
if (this.promises.has(e)) return this.promises.get(e);
|
|
@@ -36,6 +33,6 @@ var o = class {
|
|
|
36
33
|
}
|
|
37
34
|
};
|
|
38
35
|
//#endregion
|
|
39
|
-
export { n as Deferred,
|
|
36
|
+
export { n as Deferred, a as Fetcher, r as delay, e as isNil, t as notEmpty, i as tapIf };
|
|
40
37
|
|
|
41
38
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../../../../../../lib/util/helpers/src/utils.ts"],"sourcesContent":["import type { AwaitedStruct, Option, Primitive, Result, Unionize } from \"./types\";\n\nexport function isNil(v: unknown): v is null | undefined | void {\n return v === null || v === undefined;\n}\n\nexport function isPrimitive(v: unknown): v is Primitive {\n return (\n isNil(v) ||\n typeof v === \"string\" ||\n typeof v === \"number\" ||\n typeof v === \"boolean\" ||\n typeof v === \"bigint\"\n );\n}\n\nexport function notEmpty<T>(v: T | null | undefined, message?: string): T {\n if (v === null || v === undefined) {\n throw Error(message ?? \"Empty (null | undefined) value\");\n }\n\n return v;\n}\n\nexport function notUndef<T>(v: T | undefined, message?: string): T {\n if (v === undefined) {\n throw Error(message ?? \"Undefined value\");\n }\n\n return v;\n}\n\nexport function undef<V>(v: V | undefined = undefined): V | undefined {\n return v;\n}\n\nexport function bool<V extends boolean>(v: V): boolean {\n return v;\n}\n\nexport function uniqueValues<T>(items: T[]): T[] {\n return [...new Set(items)];\n}\n\nexport function checkIfNotEmpty<T>(v: T | null | undefined, message?: string): asserts v is T {\n if (v === undefined || v === null) {\n throw Error(message ?? \"Empty (null | undefined) value\");\n }\n}\n\nexport function checkIfDefined<T>(v: T | undefined, message?: string): asserts v is T {\n if (v === undefined) {\n throw Error(message ?? \"Undefined value\");\n }\n}\n\nexport function between(n: number, a: number, b: number) {\n const min = Math.min(a, b);\n const max = Math.max(a, b);\n\n return n >= min && n <= max;\n}\n\nexport function listToOptions<T>(list: T[] | readonly T[]): Option<T>[] {\n return list.map((value) => ({ text: String(value), value }));\n}\n\nexport function async<A extends unknown[]>(gf: (...args: A) => Generator) {\n return function (...args: A) {\n const generator = gf(...args);\n\n async function handle(result: IteratorResult<unknown>): Promise<unknown> {\n if (result.done) {\n return Promise.resolve(result.value);\n }\n\n return Promise.resolve(result.value)\n .then((res) => {\n return handle(generator.next(res));\n })\n .catch((err) => {\n return handle(generator.throw(err));\n });\n }\n\n try {\n return handle(generator.next());\n } catch (ex) {\n return Promise.reject(ex instanceof Error ? ex : Error(String(ex)));\n }\n };\n}\n\nexport class Deferred<T> {\n public readonly promise: Promise<T>;\n\n constructor() {\n this.promise = new Promise<T>((res, rej) => {\n this.resolve = res;\n this.reject = rej;\n });\n }\n\n public resolve: (v: T) => void = () => {};\n\n public reject: (err: Error) => void = () => {};\n}\n\nexport function delay(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport function tear() {\n return new Promise<void>((r) => queueMicrotask(r));\n}\n\nexport function timer() {\n const t = new Date().getTime();\n return function () {\n return new Date().getTime() - t;\n };\n}\n\nexport function performanceTimer() {\n const t = performance.now();\n return function () {\n return performance.now() - t;\n };\n}\n\nexport function call<R>(f: () => R): R {\n return f();\n}\n\nexport function clamp(n: number, lo: number, up: number) {\n return lo > n ? lo : n > up ? up : n;\n}\n\nexport function tap<T, R>(v: T, cb: (v: T) => R) {\n return cb(v);\n}\n\nexport function tapIf<T, R>(v: T | null | undefined, cb: (v: T) => R) {\n if (v !== null && v !== undefined) {\n return cb(v);\n }\n\n return;\n}\n\nexport function* range(from: number, to: number, step = 1) {\n for (let i = from; i < to; i += step) {\n yield i;\n }\n}\n\nexport function toList<T>(iterable: Iterable<T>): T[] {\n const lst: T[] = [];\n for (const it of iterable) {\n lst.push(it);\n }\n\n return lst;\n}\n\nexport function times<R>(n: number, cb: (i: number) => R): R[] {\n return toList(range(0, n)).map(cb);\n}\n\nexport class Interval {\n constructor(private _delay: number) {}\n\n async *generate(): AsyncGenerator<number> {\n let i = 0;\n while (true) {\n await delay(this._delay);\n yield i++;\n }\n }\n\n async *[Symbol.asyncIterator]() {\n let i = 0;\n while (true) {\n await delay(this._delay);\n yield i++;\n }\n }\n}\n\nexport function arrayFrom<T>(length: number, cb: (i: number) => T) {\n return Array.from({ length }, (_, i) => cb(i));\n}\n\nexport function exhaustive(v: never, message: string): never {\n throw Error(message);\n}\n\nexport type Matcher<T extends string, R = unknown> = {\n [P in T]: () => R;\n};\n\nexport function match<T extends string, R = unknown>(matcher: Matcher<T, R>) {\n return (key: T) => matcher[key]();\n}\n\nexport function okOptional<V>(v: { ok: true; value: V } | { ok: false } | undefined) {\n if (!v) {\n return undefined;\n }\n\n if (v.ok) {\n return v.value;\n }\n}\n\nexport function errorOptional<V>(v: Result<V> | undefined) {\n if (!v) {\n return undefined;\n }\n\n if (!v.ok) {\n return v.error;\n }\n}\n\nexport function unwrap<T>(r: Result<T>): T {\n if (r.ok) {\n return r.value;\n }\n\n throw Error(r.error);\n}\n\nexport function flatValue<T>(v: T | T[]): T[] {\n return Array.isArray(v) ? v : [v];\n}\n\nexport async function resolveAwaited<O extends Record<string, unknown>>(\n obj: O,\n): Promise<AwaitedStruct<O>> {\n return Object.fromEntries(\n await Promise.all(Object.entries(obj).map(async ([k, v]) => [k, await v])),\n ) as Promise<AwaitedStruct<O>>;\n}\n\nexport function alike(obj: Record<string, unknown>, to: Record<string, unknown>) {\n return Object.keys(to).every((bKey) => obj[bKey] === to[bKey]);\n}\n\nexport const identity = <T>(v: T): T => v;\n\nexport function asConst<const T>(v: T) {\n return v;\n}\n\nexport function unionize<K extends keyof O, V, O extends Record<K, V>>(obj: O): Unionize<O>[] {\n return Object.entries(obj).map(([key, value]) => ({\n key,\n value,\n })) as Unionize<O>[];\n}\n\nexport class Fetcher<K, V> {\n private promises = new Map<K, Promise<V>>();\n fetch(key: K, callback: () => Promise<V>) {\n if (this.promises.has(key)) {\n return this.promises.get(key)!;\n }\n const promise = callback().finally(() => {\n this.promises.delete(key);\n });\n this.promises.set(key, promise);\n return promise;\n }\n}\n"],"mappings":";AAEA,SAAgB,EAAM,GAA0C;AAC9D,QAAO,KAAM;;AAaf,SAAgB,EAAY,GAAyB,GAAqB;AACxE,KAAI,KAAM,KACR,OAAM,MAAM,KAAW,iCAAgC;AAGzD,QAAO;;AAwET,IAAa,IAAb,MAAyB;CACvB;CAEA,cAAc;AACZ,OAAK,UAAU,IAAI,SAAY,GAAK,MAAQ;AAE1C,GADA,KAAK,UAAU,GACf,KAAK,SAAS;IACf;;CAGH,gBAAuC;CAEvC,eAA4C;;AAG9C,SAAgB,EAAM,GAAY;AAChC,QAAO,IAAI,SAAS,MAAY,WAAW,GAAS,EAAG,CAAA;;
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../../../../../../lib/util/helpers/src/utils.ts"],"sourcesContent":["import type { AwaitedStruct, Option, Primitive, Result, Unionize } from \"./types\";\n\nexport function isNil(v: unknown): v is null | undefined | void {\n return v === null || v === undefined;\n}\n\nexport function isPrimitive(v: unknown): v is Primitive {\n return (\n isNil(v) ||\n typeof v === \"string\" ||\n typeof v === \"number\" ||\n typeof v === \"boolean\" ||\n typeof v === \"bigint\"\n );\n}\n\nexport function notEmpty<T>(v: T | null | undefined, message?: string): T {\n if (v === null || v === undefined) {\n throw Error(message ?? \"Empty (null | undefined) value\");\n }\n\n return v;\n}\n\nexport function notUndef<T>(v: T | undefined, message?: string): T {\n if (v === undefined) {\n throw Error(message ?? \"Undefined value\");\n }\n\n return v;\n}\n\nexport function undef<V>(v: V | undefined = undefined): V | undefined {\n return v;\n}\n\nexport function bool<V extends boolean>(v: V): boolean {\n return v;\n}\n\nexport function uniqueValues<T>(items: T[]): T[] {\n return [...new Set(items)];\n}\n\nexport function checkIfNotEmpty<T>(v: T | null | undefined, message?: string): asserts v is T {\n if (v === undefined || v === null) {\n throw Error(message ?? \"Empty (null | undefined) value\");\n }\n}\n\nexport function checkIfDefined<T>(v: T | undefined, message?: string): asserts v is T {\n if (v === undefined) {\n throw Error(message ?? \"Undefined value\");\n }\n}\n\nexport function between(n: number, a: number, b: number) {\n const min = Math.min(a, b);\n const max = Math.max(a, b);\n\n return n >= min && n <= max;\n}\n\nexport function listToOptions<T>(list: T[] | readonly T[]): Option<T>[] {\n return list.map((value) => ({ text: String(value), value }));\n}\n\nexport function async<A extends unknown[]>(gf: (...args: A) => Generator) {\n return function (...args: A) {\n const generator = gf(...args);\n\n async function handle(result: IteratorResult<unknown>): Promise<unknown> {\n if (result.done) {\n return Promise.resolve(result.value);\n }\n\n return Promise.resolve(result.value)\n .then((res) => {\n return handle(generator.next(res));\n })\n .catch((err) => {\n return handle(generator.throw(err));\n });\n }\n\n try {\n return handle(generator.next());\n } catch (ex) {\n return Promise.reject(ex instanceof Error ? ex : Error(String(ex)));\n }\n };\n}\n\nexport class Deferred<T> {\n public readonly promise: Promise<T>;\n\n constructor() {\n this.promise = new Promise<T>((res, rej) => {\n this.resolve = res;\n this.reject = rej;\n });\n }\n\n public resolve: (v: T) => void = () => {};\n\n public reject: (err: Error) => void = () => {};\n}\n\nexport function delay(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport function tear() {\n return new Promise<void>((r) => queueMicrotask(r));\n}\n\nexport function timer() {\n const t = new Date().getTime();\n return function () {\n return new Date().getTime() - t;\n };\n}\n\nexport function performanceTimer() {\n const t = performance.now();\n return function () {\n return performance.now() - t;\n };\n}\n\nexport function call<R>(f: () => R): R {\n return f();\n}\n\nexport function clamp(n: number, lo: number, up: number) {\n return lo > n ? lo : n > up ? up : n;\n}\n\nexport function tap<T, R>(v: T, cb: (v: T) => R) {\n return cb(v);\n}\n\nexport function tapIf<T, R>(v: T | null | undefined, cb: (v: T) => R) {\n if (v !== null && v !== undefined) {\n return cb(v);\n }\n\n return;\n}\n\nexport function* range(from: number, to: number, step = 1) {\n for (let i = from; i < to; i += step) {\n yield i;\n }\n}\n\nexport function toList<T>(iterable: Iterable<T>): T[] {\n const lst: T[] = [];\n for (const it of iterable) {\n lst.push(it);\n }\n\n return lst;\n}\n\nexport function times<R>(n: number, cb: (i: number) => R): R[] {\n return toList(range(0, n)).map(cb);\n}\n\nexport class Interval {\n constructor(private _delay: number) {}\n\n async *generate(): AsyncGenerator<number> {\n let i = 0;\n while (true) {\n await delay(this._delay);\n yield i++;\n }\n }\n\n async *[Symbol.asyncIterator]() {\n let i = 0;\n while (true) {\n await delay(this._delay);\n yield i++;\n }\n }\n}\n\nexport function arrayFrom<T>(length: number, cb: (i: number) => T) {\n return Array.from({ length }, (_, i) => cb(i));\n}\n\nexport function exhaustive(v: never, message: string): never {\n throw Error(message);\n}\n\nexport type Matcher<T extends string, R = unknown> = {\n [P in T]: () => R;\n};\n\nexport function match<T extends string, R = unknown>(matcher: Matcher<T, R>) {\n return (key: T) => matcher[key]();\n}\n\nexport function okOptional<V>(v: { ok: true; value: V } | { ok: false } | undefined) {\n if (!v) {\n return undefined;\n }\n\n if (v.ok) {\n return v.value;\n }\n}\n\nexport function errorOptional<V>(v: Result<V> | undefined) {\n if (!v) {\n return undefined;\n }\n\n if (!v.ok) {\n return v.error;\n }\n}\n\nexport function unwrap<T>(r: Result<T>): T {\n if (r.ok) {\n return r.value;\n }\n\n throw Error(r.error);\n}\n\nexport function flatValue<T>(v: T | T[]): T[] {\n return Array.isArray(v) ? v : [v];\n}\n\nexport async function resolveAwaited<O extends Record<string, unknown>>(\n obj: O,\n): Promise<AwaitedStruct<O>> {\n return Object.fromEntries(\n await Promise.all(Object.entries(obj).map(async ([k, v]) => [k, await v])),\n ) as Promise<AwaitedStruct<O>>;\n}\n\nexport function alike(obj: Record<string, unknown>, to: Record<string, unknown>) {\n return Object.keys(to).every((bKey) => obj[bKey] === to[bKey]);\n}\n\nexport const identity = <T>(v: T): T => v;\n\nexport function asConst<const T>(v: T) {\n return v;\n}\n\nexport function unionize<K extends keyof O, V, O extends Record<K, V>>(obj: O): Unionize<O>[] {\n return Object.entries(obj).map(([key, value]) => ({\n key,\n value,\n })) as Unionize<O>[];\n}\n\nexport class Fetcher<K, V> {\n private promises = new Map<K, Promise<V>>();\n fetch(key: K, callback: () => Promise<V>) {\n if (this.promises.has(key)) {\n return this.promises.get(key)!;\n }\n const promise = callback().finally(() => {\n this.promises.delete(key);\n });\n this.promises.set(key, promise);\n return promise;\n }\n}\n"],"mappings":";AAEA,SAAgB,EAAM,GAA0C;AAC9D,QAAO,KAAM;;AAaf,SAAgB,EAAY,GAAyB,GAAqB;AACxE,KAAI,KAAM,KACR,OAAM,MAAM,KAAW,iCAAgC;AAGzD,QAAO;;AAwET,IAAa,IAAb,MAAyB;CACvB;CAEA,cAAc;AACZ,OAAK,UAAU,IAAI,SAAY,GAAK,MAAQ;AAE1C,GADA,KAAK,UAAU,GACf,KAAK,SAAS;IACf;;CAGH,gBAAuC;CAEvC,eAA4C;;AAG9C,SAAgB,EAAM,GAAY;AAChC,QAAO,IAAI,SAAS,MAAY,WAAW,GAAS,EAAG,CAAA;;AAiCzD,SAAgB,EAAY,GAAyB,GAAiB;AACpE,KAAI,KAAM,KACR,QAAO,EAAG,EAAC;;AAsHf,IAAa,IAAb,MAA2B;CACzB,2BAAmB,IAAI,KAAmB;CAC1C,MAAM,GAAQ,GAA4B;AACxC,MAAI,KAAK,SAAS,IAAI,EAAG,CACvB,QAAO,KAAK,SAAS,IAAI,EAAG;EAE9B,IAAM,IAAU,GAAU,CAAC,cAAc;AACvC,QAAK,SAAS,OAAO,EAAG;IACzB;AAED,SADA,KAAK,SAAS,IAAI,GAAK,EAAO,EACvB"}
|
package/dist/lib.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import './assets/ui.css';/* empty css */
|
|
3
3
|
import "./utils.js";
|
|
4
|
-
import "./createModel.js";
|
|
5
4
|
import "./defineApp.js";
|
|
6
5
|
import "./components/BlockLayout.js";
|
|
7
6
|
import "./components/PlAgDataTable/PlAgOverlayLoading.js";
|
|
@@ -47,6 +46,7 @@ import "./components/PlBtnExportArchive/index.js";
|
|
|
47
46
|
import "./components/PlDatasetSelector/PlDatasetSelector.js";
|
|
48
47
|
import "./components/PlDatasetSelector/index.js";
|
|
49
48
|
import "./composition/usePlugin.js";
|
|
49
|
+
import "./createModel.js";
|
|
50
50
|
import "./defineStore.js";
|
|
51
51
|
import "./composition/AgGrid/index.js";
|
|
52
52
|
import "./objectHash.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/ui-vue",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.83.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"lru-cache": "^11.2.2",
|
|
27
27
|
"vue": "3.5.24",
|
|
28
28
|
"zod": "~3.25.76",
|
|
29
|
-
"@milaboratories/
|
|
29
|
+
"@milaboratories/columns-collection-driver": "0.2.4",
|
|
30
30
|
"@milaboratories/pf-spec-driver": "1.5.1",
|
|
31
|
-
"@
|
|
32
|
-
"@milaboratories/
|
|
33
|
-
"@
|
|
31
|
+
"@milaboratories/uikit": "2.15.26",
|
|
32
|
+
"@milaboratories/pl-model-common": "1.48.0",
|
|
33
|
+
"@platforma-sdk/model": "1.83.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@faker-js/faker": "^9.2.0",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"vite": "^8.0.6",
|
|
48
48
|
"vitest": "^4.1.3",
|
|
49
49
|
"@milaboratories/build-configs": "2.0.0",
|
|
50
|
-
"@milaboratories/ts-builder": "1.7.0",
|
|
51
50
|
"@milaboratories/helpers": "1.14.5",
|
|
52
|
-
"@milaboratories/ts-configs": "1.4.0"
|
|
51
|
+
"@milaboratories/ts-configs": "1.4.0",
|
|
52
|
+
"@milaboratories/ts-builder": "1.7.0"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"dev": "ts-builder serve --target browser-lib",
|
package/src/defineApp.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { notEmpty } from "@milaboratories/helpers";
|
|
2
2
|
import type {
|
|
3
|
-
PlatformaExtended,
|
|
4
3
|
PlatformaV3,
|
|
5
|
-
PlatformaV1,
|
|
6
|
-
PlatformaV2,
|
|
7
4
|
BlockCodeKnownFeatureFlags,
|
|
8
5
|
UiServices as AllUiServices,
|
|
9
6
|
} from "@platforma-sdk/model";
|
|
@@ -15,8 +12,6 @@ import {
|
|
|
15
12
|
} from "@platforma-sdk/model";
|
|
16
13
|
import type { App as VueApp, Component, Reactive } from "vue";
|
|
17
14
|
import { inject, markRaw, reactive } from "vue";
|
|
18
|
-
import { createAppV1, type BaseAppV1 } from "./internal/createAppV1";
|
|
19
|
-
import { createAppV2, type BaseAppV2 } from "./internal/createAppV2";
|
|
20
15
|
import { createAppV3, type BaseAppV3 } from "./internal/createAppV3";
|
|
21
16
|
import type { AppSettings, ExtendSettings, Routes } from "./types";
|
|
22
17
|
|
|
@@ -32,135 +27,6 @@ export function useFeatureFlags() {
|
|
|
32
27
|
return sdk.featureFlags;
|
|
33
28
|
}
|
|
34
29
|
|
|
35
|
-
export function defineApp<
|
|
36
|
-
Args = unknown,
|
|
37
|
-
Outputs extends BlockOutputsBase = BlockOutputsBase,
|
|
38
|
-
UiState = unknown,
|
|
39
|
-
Href extends `/${string}` = `/${string}`,
|
|
40
|
-
Extend extends ExtendSettings<Href> = ExtendSettings<Href>,
|
|
41
|
-
>(
|
|
42
|
-
platforma: PlatformaV1<Args, Outputs, UiState, Href> & {
|
|
43
|
-
blockModelInfo: BlockModelInfo;
|
|
44
|
-
},
|
|
45
|
-
extendApp: (app: BaseAppV1<Args, Outputs, UiState, Href>) => Extend,
|
|
46
|
-
settings?: AppSettings,
|
|
47
|
-
): SdkPluginV1<Args, Outputs, UiState, Href, Extend>;
|
|
48
|
-
|
|
49
|
-
export function defineApp<
|
|
50
|
-
Args = unknown,
|
|
51
|
-
Outputs extends BlockOutputsBase = BlockOutputsBase,
|
|
52
|
-
UiState = unknown,
|
|
53
|
-
Href extends `/${string}` = `/${string}`,
|
|
54
|
-
Extend extends ExtendSettings<Href> = ExtendSettings<Href>,
|
|
55
|
-
>(
|
|
56
|
-
platforma: PlatformaV2<Args, Outputs, UiState, Href> & {
|
|
57
|
-
blockModelInfo: BlockModelInfo;
|
|
58
|
-
},
|
|
59
|
-
extendApp: (app: BaseAppV2<Args, Outputs, UiState, Href>) => Extend,
|
|
60
|
-
settings?: AppSettings,
|
|
61
|
-
): SdkPluginV2<Args, Outputs, UiState, Href, Extend>;
|
|
62
|
-
|
|
63
|
-
export function defineApp<
|
|
64
|
-
Args = unknown,
|
|
65
|
-
Outputs extends BlockOutputsBase = BlockOutputsBase,
|
|
66
|
-
UiState = unknown,
|
|
67
|
-
Href extends `/${string}` = `/${string}`,
|
|
68
|
-
Extend extends ExtendSettings<Href> = ExtendSettings<Href>,
|
|
69
|
-
>(
|
|
70
|
-
platforma: PlatformaExtended<
|
|
71
|
-
PlatformaV1<Args, Outputs, UiState, Href> | PlatformaV2<Args, Outputs, UiState, Href>
|
|
72
|
-
>,
|
|
73
|
-
|
|
74
|
-
//
|
|
75
|
-
extendApp: (app: any) => Extend,
|
|
76
|
-
settings: AppSettings = {},
|
|
77
|
-
):
|
|
78
|
-
| SdkPluginV1<Args, Outputs, UiState, Href, Extend>
|
|
79
|
-
| SdkPluginV2<Args, Outputs, UiState, Href, Extend> {
|
|
80
|
-
let app:
|
|
81
|
-
| AppV1<Args, Outputs, UiState, Href, Extend>
|
|
82
|
-
| AppV2<Args, Outputs, UiState, Href, Extend>
|
|
83
|
-
| undefined = undefined;
|
|
84
|
-
|
|
85
|
-
const runtimeApiVersion = platforma.apiVersion ?? 1; // undefined means 1 (backward compatibility)
|
|
86
|
-
const blockRequestedApiVersion = getPlatformaApiVersion();
|
|
87
|
-
|
|
88
|
-
const loadApp = async () => {
|
|
89
|
-
if (blockRequestedApiVersion !== runtimeApiVersion) {
|
|
90
|
-
throw new Error(`Block requested API version ${blockRequestedApiVersion} but runtime API version is ${runtimeApiVersion}.
|
|
91
|
-
Please update the desktop app to use the latest API version.`);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (platforma.apiVersion === undefined || platforma.apiVersion === 1) {
|
|
95
|
-
await platforma.loadBlockState().then((state) => {
|
|
96
|
-
plugin.loaded = true;
|
|
97
|
-
const baseApp = createAppV1<Args, Outputs, UiState, Href>(state, platforma, settings);
|
|
98
|
-
|
|
99
|
-
const localState = extendApp(baseApp);
|
|
100
|
-
|
|
101
|
-
const routes = Object.fromEntries(
|
|
102
|
-
Object.entries(localState.routes as Routes<Href>).map(([href, component]) => {
|
|
103
|
-
const c = typeof component === "function" ? component() : component;
|
|
104
|
-
return [href, markRaw(c as Component)];
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
app = Object.assign(baseApp, {
|
|
109
|
-
...localState,
|
|
110
|
-
getRoute(href: Href): Component | undefined {
|
|
111
|
-
return routes[href];
|
|
112
|
-
},
|
|
113
|
-
} as unknown as AppV1<Args, Outputs, UiState, Href, Extend>);
|
|
114
|
-
});
|
|
115
|
-
} else if (platforma.apiVersion === 2) {
|
|
116
|
-
await platforma.loadBlockState().then((stateOrError) => {
|
|
117
|
-
const state = unwrapResult(stateOrError);
|
|
118
|
-
plugin.loaded = true;
|
|
119
|
-
const baseApp = createAppV2<Args, Outputs, UiState, Href>(state, platforma, settings);
|
|
120
|
-
|
|
121
|
-
const localState = extendApp(baseApp);
|
|
122
|
-
|
|
123
|
-
const routes = Object.fromEntries(
|
|
124
|
-
Object.entries(localState.routes as Routes<Href>).map(([href, component]) => {
|
|
125
|
-
const c = typeof component === "function" ? component() : component;
|
|
126
|
-
return [href, markRaw(c as Component)];
|
|
127
|
-
}),
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
app = Object.assign(baseApp, {
|
|
131
|
-
...localState,
|
|
132
|
-
getRoute(href: Href): Component | undefined {
|
|
133
|
-
return routes[href];
|
|
134
|
-
},
|
|
135
|
-
} as unknown as AppV2<Args, Outputs, UiState, Href, Extend>);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const plugin = reactive({
|
|
141
|
-
apiVersion: platforma.apiVersion ?? 1,
|
|
142
|
-
featureFlags: platforma.blockModelInfo.featureFlags,
|
|
143
|
-
loaded: false,
|
|
144
|
-
error: undefined as unknown,
|
|
145
|
-
useApp<PageHref extends Href = Href>() {
|
|
146
|
-
return notEmpty(app, "App is not loaded") as
|
|
147
|
-
| AppV1<Args, Outputs, UiState, PageHref, Extend>
|
|
148
|
-
| AppV2<Args, Outputs, UiState, PageHref, Extend>;
|
|
149
|
-
},
|
|
150
|
-
install(app: VueApp) {
|
|
151
|
-
app.provide(pluginKey, this);
|
|
152
|
-
loadApp().catch((err) => {
|
|
153
|
-
console.error("load initial state error", err);
|
|
154
|
-
plugin.error = err;
|
|
155
|
-
});
|
|
156
|
-
},
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
return plugin as
|
|
160
|
-
| SdkPluginV1<Args, Outputs, UiState, Href, Extend>
|
|
161
|
-
| SdkPluginV2<Args, Outputs, UiState, Href, Extend>;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
30
|
export function defineAppV3<
|
|
165
31
|
Data = unknown,
|
|
166
32
|
Args = unknown,
|
|
@@ -256,24 +122,6 @@ export function defineAppV3<
|
|
|
256
122
|
return plugin as SdkPluginV3<Data, Args, Outputs, Href, Plugins, Extend, UiServices>;
|
|
257
123
|
}
|
|
258
124
|
|
|
259
|
-
export type AppV1<
|
|
260
|
-
Args = unknown,
|
|
261
|
-
Outputs extends BlockOutputsBase = BlockOutputsBase,
|
|
262
|
-
UiState = unknown,
|
|
263
|
-
Href extends `/${string}` = `/${string}`,
|
|
264
|
-
Local extends ExtendSettings<Href> = ExtendSettings<Href>,
|
|
265
|
-
> = BaseAppV1<Args, Outputs, UiState, Href> &
|
|
266
|
-
Reactive<Omit<Local, "routes">> & { getRoute(href: Href): Component | undefined };
|
|
267
|
-
|
|
268
|
-
export type AppV2<
|
|
269
|
-
Args = unknown,
|
|
270
|
-
Outputs extends BlockOutputsBase = BlockOutputsBase,
|
|
271
|
-
UiState = unknown,
|
|
272
|
-
Href extends `/${string}` = `/${string}`,
|
|
273
|
-
Local extends ExtendSettings<Href> = ExtendSettings<Href>,
|
|
274
|
-
> = BaseAppV2<Args, Outputs, UiState, Href> &
|
|
275
|
-
Reactive<Omit<Local, "routes">> & { getRoute(href: Href): Component | undefined };
|
|
276
|
-
|
|
277
125
|
export type AppV3<
|
|
278
126
|
Data = unknown,
|
|
279
127
|
Args = unknown,
|
|
@@ -289,36 +137,6 @@ export type AppV3<
|
|
|
289
137
|
// SdkPlugin types
|
|
290
138
|
// ---------------------------------------------------------------------------
|
|
291
139
|
|
|
292
|
-
export type SdkPluginV1<
|
|
293
|
-
Args = unknown,
|
|
294
|
-
Outputs extends BlockOutputsBase = BlockOutputsBase,
|
|
295
|
-
UiState = unknown,
|
|
296
|
-
Href extends `/${string}` = `/${string}`,
|
|
297
|
-
Local extends ExtendSettings<Href> = ExtendSettings<Href>,
|
|
298
|
-
> = {
|
|
299
|
-
apiVersion: 1;
|
|
300
|
-
featureFlags: BlockCodeKnownFeatureFlags;
|
|
301
|
-
loaded: boolean;
|
|
302
|
-
error: unknown;
|
|
303
|
-
useApp<PageHref extends Href = Href>(): AppV1<Args, Outputs, UiState, PageHref, Local>;
|
|
304
|
-
install(app: VueApp): void;
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
export type SdkPluginV2<
|
|
308
|
-
Args = unknown,
|
|
309
|
-
Outputs extends BlockOutputsBase = BlockOutputsBase,
|
|
310
|
-
UiState = unknown,
|
|
311
|
-
Href extends `/${string}` = `/${string}`,
|
|
312
|
-
Local extends ExtendSettings<Href> = ExtendSettings<Href>,
|
|
313
|
-
> = {
|
|
314
|
-
apiVersion: 2;
|
|
315
|
-
featureFlags: BlockCodeKnownFeatureFlags;
|
|
316
|
-
loaded: boolean;
|
|
317
|
-
error: unknown;
|
|
318
|
-
useApp<PageHref extends Href = Href>(): AppV2<Args, Outputs, UiState, PageHref, Local>;
|
|
319
|
-
install(app: VueApp): void;
|
|
320
|
-
};
|
|
321
|
-
|
|
322
140
|
export type SdkPluginV3<
|
|
323
141
|
Data = unknown,
|
|
324
142
|
Args = unknown,
|
|
@@ -344,4 +162,4 @@ export type SdkPluginV3<
|
|
|
344
162
|
install(app: VueApp): void;
|
|
345
163
|
};
|
|
346
164
|
|
|
347
|
-
export type SdkPlugin =
|
|
165
|
+
export type SdkPlugin = SdkPluginV3;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ComputedRef, UnwrapNestedRefs } from 'vue';
|
|
2
|
-
import { ModelOptions, Model, AppSettings } from '../types';
|
|
3
|
-
export declare function createAppModel<M extends {
|
|
4
|
-
args: unknown;
|
|
5
|
-
ui: unknown;
|
|
6
|
-
}, V = unknown, E extends Record<string, ComputedRef<unknown>> = Record<string, ComputedRef<unknown>>>(options: ModelOptions<M, V>, extended: E, _settings: AppSettings): Model<M & UnwrapNestedRefs<E>>;
|
|
7
|
-
//# sourceMappingURL=createAppModel.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createAppModel.d.ts","sourceRoot":"","sources":["../../src/internal/createAppModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACtB,MAAM,KAAK,CAAC;AACb,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAIjE,wBAAgB,cAAc,CAC5B,CAAC,SAAS;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,OAAO,CAAA;CAAE,EACxC,CAAC,GAAG,OAAO,EACX,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,EAErF,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EAC3B,QAAQ,EAAE,CAAC,EACX,SAAS,EAAE,WAAW,GACrB,KAAK,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,CA0FhC"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { deepClone as e, isJsonEqual as t } from "../lib/util/helpers/dist/objects.js";
|
|
2
|
-
import "../lib/util/helpers/dist/index.js";
|
|
3
|
-
import { ensureError as n, formatZodError as r, identity as i, isZodError as a } from "../utils.js";
|
|
4
|
-
import { computed as o, reactive as s, ref as c, unref as l, watch as u } from "vue";
|
|
5
|
-
//#region src/internal/createAppModel.ts
|
|
6
|
-
function d(d, f, p) {
|
|
7
|
-
let m = d.validate ?? i, { autoSave: h } = d, g = c(), _ = c(), v = (t) => {
|
|
8
|
-
_.value = {
|
|
9
|
-
model: Object.assign(e(t), f ?? {}),
|
|
10
|
-
stage: Symbol()
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
u(() => d.get(), (e) => v(e), { immediate: !0 });
|
|
14
|
-
let y = () => d.onSave(m(e(_.value?.model))), b = () => {
|
|
15
|
-
v(d.get()), g.value = void 0;
|
|
16
|
-
}, x = (e) => {
|
|
17
|
-
let t = n(e);
|
|
18
|
-
a(t) ? g.value = Error(r(t)) : g.value = t;
|
|
19
|
-
}, S = (e) => {
|
|
20
|
-
g.value = void 0;
|
|
21
|
-
try {
|
|
22
|
-
m(e), h && y();
|
|
23
|
-
} catch (e) {
|
|
24
|
-
x(e);
|
|
25
|
-
}
|
|
26
|
-
}, C = o({
|
|
27
|
-
get: () => _.value?.model,
|
|
28
|
-
set() {
|
|
29
|
-
throw Error("Cannot replace base model");
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
return u([() => ({
|
|
33
|
-
args: C.value.args,
|
|
34
|
-
ui: C.value.ui
|
|
35
|
-
}), () => _.value?.stage], ([e, t], [n, r]) => {
|
|
36
|
-
t === r && S(e);
|
|
37
|
-
}, { deep: !0 }), s({
|
|
38
|
-
model: C,
|
|
39
|
-
valid: o(() => !g.value),
|
|
40
|
-
isChanged: o(() => {
|
|
41
|
-
let { args: e, ui: n } = l(_)?.model ?? {};
|
|
42
|
-
return !t(d.get(), {
|
|
43
|
-
args: e,
|
|
44
|
-
ui: n
|
|
45
|
-
});
|
|
46
|
-
}),
|
|
47
|
-
error: g,
|
|
48
|
-
errorString: o(() => g.value ? g.value.message : ""),
|
|
49
|
-
save: y,
|
|
50
|
-
revert: b,
|
|
51
|
-
setError: x
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
//#endregion
|
|
55
|
-
export { d as createAppModel };
|
|
56
|
-
|
|
57
|
-
//# sourceMappingURL=createAppModel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createAppModel.js","names":[],"sources":["../../src/internal/createAppModel.ts"],"sourcesContent":["import {\n reactive,\n computed,\n ref,\n watch,\n unref,\n type ComputedRef,\n type UnwrapNestedRefs,\n} from \"vue\";\nimport type { ModelOptions, Model, AppSettings } from \"../types\";\nimport { deepClone, isJsonEqual } from \"@milaboratories/helpers\";\nimport { identity, ensureError, isZodError, formatZodError } from \"../utils\";\n\nexport function createAppModel<\n M extends { args: unknown; ui: unknown },\n V = unknown,\n E extends Record<string, ComputedRef<unknown>> = Record<string, ComputedRef<unknown>>,\n>(\n options: ModelOptions<M, V>,\n extended: E,\n _settings: AppSettings,\n): Model<M & UnwrapNestedRefs<E>> {\n type R = M & UnwrapNestedRefs<E>;\n\n const validate = options.validate ?? identity;\n\n const { autoSave } = options;\n\n const error = ref<Error | undefined>();\n\n const local = ref<{ model: R; readonly stage: symbol }>();\n\n const setSource = (v: M) => {\n local.value = {\n model: Object.assign(deepClone(v), extended ?? {}) as R,\n stage: Symbol(),\n };\n };\n\n watch(\n () => options.get(),\n (v) => setSource(v),\n { immediate: true },\n );\n\n const save = () => options.onSave(validate(deepClone(local.value?.model)));\n\n const revert = () => {\n setSource(options.get());\n error.value = undefined;\n };\n\n const setError = (cause: unknown) => {\n const err = ensureError(cause);\n if (isZodError(err)) {\n error.value = Error(formatZodError(err)); // @todo temp\n } else {\n error.value = err;\n }\n };\n\n const setValue = (v: M) => {\n error.value = undefined;\n try {\n validate(v);\n if (autoSave) {\n save();\n }\n } catch (cause: unknown) {\n setError(cause);\n }\n };\n\n const model = computed<R>({\n get: () => {\n return local.value?.model as R;\n },\n set() {\n throw Error(\"Cannot replace base model\");\n },\n });\n\n watch(\n [() => ({ args: model.value.args, ui: model.value.ui }), () => local.value?.stage],\n ([n, newStage], [_, oldStage]) => {\n if (newStage === oldStage) {\n setValue(n as M);\n }\n },\n { deep: true },\n );\n\n const valid = computed(() => !error.value);\n\n const isChanged = computed(() => {\n const { args, ui } = unref(local)?.model ?? {};\n return !isJsonEqual(options.get(), { args, ui });\n });\n\n const errorString = computed(() => (error.value ? error.value.message : \"\"));\n\n return reactive({\n model,\n valid,\n isChanged,\n error,\n errorString,\n save,\n revert,\n setError,\n });\n}\n"],"mappings":";;;;;AAaA,SAAgB,EAKd,GACA,GACA,GACgC;CAGhC,IAAM,IAAW,EAAQ,YAAY,GAE/B,EAAE,gBAAa,GAEf,IAAQ,GAAwB,EAEhC,IAAQ,GAA2C,EAEnD,KAAa,MAAS;AAC1B,IAAM,QAAQ;GACZ,OAAO,OAAO,OAAO,EAAU,EAAE,EAAE,KAAY,EAAE,CAAC;GAClD,OAAO,QAAQ;GAChB;;AAGH,SACQ,EAAQ,KAAK,GAClB,MAAM,EAAU,EAAE,EACnB,EAAE,WAAW,IAAM,CACpB;CAED,IAAM,UAAa,EAAQ,OAAO,EAAS,EAAU,EAAM,OAAO,MAAM,CAAC,CAAC,EAEpE,UAAe;AAEnB,EADA,EAAU,EAAQ,KAAK,CAAC,EACxB,EAAM,QAAQ,KAAA;IAGV,KAAY,MAAmB;EACnC,IAAM,IAAM,EAAY,EAAM;AAC9B,EAAI,EAAW,EAAI,GACjB,EAAM,QAAQ,MAAM,EAAe,EAAI,CAAC,GAExC,EAAM,QAAQ;IAIZ,KAAY,MAAS;AACzB,IAAM,QAAQ,KAAA;AACd,MAAI;AAEF,GADA,EAAS,EAAE,EACP,KACF,GAAM;WAED,GAAgB;AACvB,KAAS,EAAM;;IAIb,IAAQ,EAAY;EACxB,WACS,EAAM,OAAO;EAEtB,MAAM;AACJ,SAAM,MAAM,4BAA4B;;EAE3C,CAAC;AAqBF,QAnBA,EACE,QAAQ;EAAE,MAAM,EAAM,MAAM;EAAM,IAAI,EAAM,MAAM;EAAI,SAAS,EAAM,OAAO,MAAM,GACjF,CAAC,GAAG,IAAW,CAAC,GAAG,OAAc;AAChC,EAAI,MAAa,KACf,EAAS,EAAO;IAGpB,EAAE,MAAM,IAAM,CACf,EAWM,EAAS;EACd;EACA,OAXY,QAAe,CAAC,EAAM,MAAM;EAYxC,WAVgB,QAAe;GAC/B,IAAM,EAAE,SAAM,UAAO,EAAM,EAAM,EAAE,SAAS,EAAE;AAC9C,UAAO,CAAC,EAAY,EAAQ,KAAK,EAAE;IAAE;IAAM;IAAI,CAAC;IAChD;EAQA;EACA,aAPkB,QAAgB,EAAM,QAAQ,EAAM,MAAM,UAAU,GAAI;EAQ1E;EACA;EACA;EACD,CAAC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Mutable } from '@milaboratories/helpers';
|
|
2
|
-
import { NavigationState, BlockOutputsBase, BlockState, PlatformaV1, PlatformaExtended } from '@platforma-sdk/model';
|
|
3
|
-
import { StateModelOptions, UnwrapOutputs, OptionalResult, OutputValues, OutputErrors, AppSettings } from '../types';
|
|
4
|
-
/**
|
|
5
|
-
* Creates an application instance with reactive state management, outputs, and methods for state updates and navigation.
|
|
6
|
-
*
|
|
7
|
-
* @template Args - The type of arguments used in the application.
|
|
8
|
-
* @template Outputs - The type of block outputs extending `BlockOutputsBase`.
|
|
9
|
-
* @template UiState - The type of the UI state.
|
|
10
|
-
* @template Href - The type of navigation href, defaulting to a string starting with `/`.
|
|
11
|
-
*
|
|
12
|
-
* @param state - Initial state of the application, including args, outputs, UI state, and navigation state.
|
|
13
|
-
* @param platforma - A platform interface for interacting with block states.
|
|
14
|
-
* @param settings - Application settings, such as debug flags.
|
|
15
|
-
*
|
|
16
|
-
* @returns A reactive application object with methods, getters, and state.
|
|
17
|
-
*/
|
|
18
|
-
export declare function createAppV1<Args = unknown, Outputs extends BlockOutputsBase = BlockOutputsBase, UiState = unknown, Href extends `/${string}` = `/${string}`>(state: BlockState<Args, Outputs, UiState, Href>, platforma: PlatformaExtended<PlatformaV1<Args, Outputs, UiState, Href>>, settings: AppSettings): {
|
|
19
|
-
model: {
|
|
20
|
-
args: import('vue').UnwrapRef<Args>;
|
|
21
|
-
ui: import('vue').UnwrapRef<UiState>;
|
|
22
|
-
outputs: import('vue').UnwrapRef<OutputValues<Outputs>>;
|
|
23
|
-
outputErrors: import('vue').UnwrapRef<OutputErrors<Outputs>>;
|
|
24
|
-
};
|
|
25
|
-
readonly valid: boolean;
|
|
26
|
-
readonly isChanged: boolean;
|
|
27
|
-
readonly error: Error | undefined;
|
|
28
|
-
readonly errorString: string | undefined;
|
|
29
|
-
readonly save: () => void;
|
|
30
|
-
readonly revert: () => void;
|
|
31
|
-
readonly setError: (cause: unknown) => void;
|
|
32
|
-
createArgsModel: <T = Args>(options?: StateModelOptions<Args, T>) => import('../types').Model<T>;
|
|
33
|
-
createUiModel: <T = UiState>(options: StateModelOptions<UiState, T> | undefined, defaultUiState: () => UiState) => import('../types').Model<T>;
|
|
34
|
-
useOutputs: <K extends keyof Outputs>(...keys: K[]) => OptionalResult<UnwrapOutputs<Outputs, K>>;
|
|
35
|
-
unwrapOutputs: <K extends keyof Outputs>(...keys: K[]) => UnwrapOutputs<Outputs, K>;
|
|
36
|
-
updateArgs: (cb: (args: Args) => void) => Promise<void>;
|
|
37
|
-
updateUiState: (cb: (args: UiState) => UiState) => Promise<void>;
|
|
38
|
-
updateNavigationState: (cb: (args: Mutable<NavigationState<Href>>) => void) => Promise<void>;
|
|
39
|
-
navigateTo: (href: Href) => Promise<void>;
|
|
40
|
-
snapshot: {
|
|
41
|
-
args: import('vue').UnwrapRef<Readonly<Args>>;
|
|
42
|
-
outputs: import('vue').UnwrapRef<Partial<Readonly<Outputs>>>;
|
|
43
|
-
ui: import('vue').UnwrapRef<Readonly<UiState>>;
|
|
44
|
-
navigationState: {
|
|
45
|
-
readonly href: import('vue').UnwrapRef<Href>;
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
queryParams: import('../types').ParseQuery<Href>;
|
|
49
|
-
href: Href;
|
|
50
|
-
hasErrors: boolean;
|
|
51
|
-
};
|
|
52
|
-
export type BaseAppV1<Args = unknown, Outputs extends BlockOutputsBase = BlockOutputsBase, UiState = unknown, Href extends `/${string}` = `/${string}`> = ReturnType<typeof createAppV1<Args, Outputs, UiState, Href>>;
|
|
53
|
-
//# sourceMappingURL=createAppV1.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createAppV1.d.ts","sourceRoot":"","sources":["../../src/internal/createAppV1.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EACV,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,WAAW,EACZ,MAAM,UAAU,CAAC;AAMlB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,IAAI,GAAG,OAAO,EACd,OAAO,SAAS,gBAAgB,GAAG,gBAAgB,EACnD,OAAO,GAAG,OAAO,EACjB,IAAI,SAAS,IAAI,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,EAExC,KAAK,EAAE,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAC/C,SAAS,EAAE,iBAAiB,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,EACvE,QAAQ,EAAE,WAAW;;;;;;;;;;;;;;sBAgGH,CAAC,mBAAkB,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC;oBAmB/C,CAAC,qBACJ,iBAAiB,CAAC,OAAO,EAAE,CAAC,CAAC,8BACtB,MAAM,OAAO;iBAsBpB,CAAC,SAAS,MAAM,OAAO,WAAW,CAAC,EAAE,KAAG,cAAc,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;oBAkC9E,CAAC,SAAS,MAAM,OAAO,WAAW,CAAC,EAAE,KAAG,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC;qBAWhE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI;wBAYjB,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,KAAG,OAAO,CAAC,IAAI,CAAC;gCAUlC,CAAC,IAAI,EAAE,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI;uBAWvD,IAAI;;;;;;;;;;;;EAsDxB;AAED,MAAM,MAAM,SAAS,CACnB,IAAI,GAAG,OAAO,EACd,OAAO,SAAS,gBAAgB,GAAG,gBAAgB,EACnD,OAAO,GAAG,OAAO,EACjB,IAAI,SAAS,IAAI,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,IACtC,UAAU,CAAC,OAAO,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC"}
|