@platforma-sdk/ui-vue 1.41.11 → 1.41.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
   WARN  Issue while reading "/home/runner/_work/platforma/platforma/.npmrc". Failed to replace env in config: ${NPMJS_TOKEN}
2
2
 
3
- > @platforma-sdk/ui-vue@1.41.11 build /home/runner/_work/platforma/platforma/sdk/ui-vue
3
+ > @platforma-sdk/ui-vue@1.41.13 build /home/runner/_work/platforma/platforma/sdk/ui-vue
4
4
  > vite build
5
5
 
6
6
  vite v6.3.5 building for production...
@@ -10,7 +10,7 @@ rendering chunks...
10
10
 
11
11
  [vite:dts] Start generate declaration files...
12
12
  computing gzip size...
13
- [vite:dts] Declaration files built in 5047ms.
13
+ [vite:dts] Declaration files built in 4873ms.
14
14
 
15
15
  dist/_virtual/re.js  0.08 kB │ gzip: 0.10 kB │ map: 0.09 kB
16
16
  dist/lib/ui/uikit/dist/node_modules/.pnpm/d3-interpolate@3.0.1/node_modules/d3-interpolate/src/constant.js  0.09 kB │ gzip: 0.10 kB │ map: 0.32 kB
@@ -38,14 +38,14 @@ computing gzip size...
38
38
  dist/lib/ui/uikit/dist/node_modules/.pnpm/d3-array@3.2.4/node_modules/d3-array/src/number.js  0.11 kB │ gzip: 0.12 kB │ map: 0.79 kB
39
39
  dist/components/PlAgCsvExporter/PlAgCsvExporter.vue2.js  0.12 kB │ gzip: 0.12 kB │ map: 0.11 kB
40
40
  dist/lib/ui/uikit/dist/helpers/math.js  0.12 kB │ gzip: 0.13 kB │ map: 0.36 kB
41
- dist/components/PlAgColumnHeader/PlAgColumnHeader.vue2.js  0.12 kB │ gzip: 0.12 kB │ map: 0.11 kB
42
41
  dist/components/PlAgCellProgress/PlAgCellProgress.vue2.js  0.12 kB │ gzip: 0.12 kB │ map: 0.11 kB
42
+ dist/components/PlAgColumnHeader/PlAgColumnHeader.vue2.js  0.12 kB │ gzip: 0.12 kB │ map: 0.11 kB
43
43
  dist/components/PlAgRowNumHeader.vue2.js  0.12 kB │ gzip: 0.12 kB │ map: 0.11 kB
44
44
  dist/lib/ui/uikit/dist/node_modules/.pnpm/d3-selection@3.0.0/node_modules/d3-selection/src/constant.js  0.12 kB │ gzip: 0.12 kB │ map: 0.40 kB
45
45
  dist/lib/ui/uikit/dist/node_modules/.pnpm/d3-scale@4.0.2/node_modules/d3-scale/src/constant.js  0.12 kB │ gzip: 0.12 kB │ map: 0.40 kB
46
46
  dist/components/PlAgDataTable/PlAgOverlayLoading.vue2.js  0.12 kB │ gzip: 0.12 kB │ map: 0.11 kB
47
- dist/components/PlAgRowNumCheckbox/PlAgRowNumCheckbox.vue2.js  0.12 kB │ gzip: 0.12 kB │ map: 0.11 kB
48
47
  dist/components/PlTableFilters/PlTableAddFilterV2.vue2.js  0.12 kB │ gzip: 0.12 kB │ map: 0.11 kB
48
+ dist/components/PlAgRowNumCheckbox/PlAgRowNumCheckbox.vue2.js  0.12 kB │ gzip: 0.12 kB │ map: 0.11 kB
49
49
  dist/plugins/Monetization/MonetizationSidebar.vue2.js  0.13 kB │ gzip: 0.12 kB │ map: 0.11 kB
50
50
  dist/components/PlTableFilters/PlTableFilterEntryV2.vue2.js  0.13 kB │ gzip: 0.12 kB │ map: 0.11 kB
51
51
  dist/components/PlAgGridColumnManager/PlAgGridColumnManager.vue2.js  0.13 kB │ gzip: 0.12 kB │ map: 0.11 kB
@@ -156,8 +156,8 @@ computing gzip size...
156
156
  dist/lib/ui/uikit/dist/components/PlRadio/PlRadio.vue.js  0.27 kB │ gzip: 0.21 kB │ map: 0.10 kB
157
157
  dist/_virtual/index.js  0.27 kB │ gzip: 0.21 kB │ map: 0.09 kB
158
158
  dist/components/PlMultiSequenceAlignment/Toolbar.vue.js  0.27 kB │ gzip: 0.21 kB │ map: 0.10 kB
159
- dist/lib/ui/uikit/dist/assets/icons/icon-assets-min/24_linetype-longdash.svg.js  0.27 kB │ gzip: 0.23 kB │ map: 0.50 kB
160
159
  dist/lib/ui/uikit/dist/components/PlChartStackedBar/Legends.vue.js  0.27 kB │ gzip: 0.21 kB │ map: 0.10 kB
160
+ dist/lib/ui/uikit/dist/assets/icons/icon-assets-min/24_linetype-longdash.svg.js  0.27 kB │ gzip: 0.23 kB │ map: 0.50 kB
161
161
  dist/lib/ui/uikit/dist/assets/icons/icon-assets-min/16_chevron-first.svg.js  0.28 kB │ gzip: 0.23 kB │ map: 0.48 kB
162
162
  dist/lib/ui/uikit/dist/components/PlIcon16/PlIcon16.vue.js  0.28 kB │ gzip: 0.22 kB │ map: 0.10 kB
163
163
  dist/lib/ui/uikit/dist/components/PlIcon24/PlIcon24.vue.js  0.28 kB │ gzip: 0.22 kB │ map: 0.10 kB
@@ -215,8 +215,8 @@ computing gzip size...
215
215
  dist/lib/ui/uikit/dist/assets/icons/icon-assets-min/24_text-align-left.svg.js  0.30 kB │ gzip: 0.25 kB │ map: 0.52 kB
216
216
  dist/components/PlAgDataTable/PlAgDataTableV2.vue.js  0.30 kB │ gzip: 0.22 kB │ map: 0.11 kB
217
217
  dist/lib/ui/uikit/dist/assets/icons/icon-assets-min/24_arrow-link.svg.js  0.30 kB │ gzip: 0.25 kB │ map: 0.51 kB
218
- dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/clean.js  0.30 kB │ gzip: 0.23 kB │ map: 0.65 kB
219
218
  dist/plugins/Monetization/UserCabinetCard.vue.js  0.30 kB │ gzip: 0.22 kB │ map: 0.11 kB
219
+ dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/clean.js  0.30 kB │ gzip: 0.23 kB │ map: 0.65 kB
220
220
  dist/lib/ui/uikit/dist/assets/icons/icon-assets-min/24_chevron-right.svg.js  0.30 kB │ gzip: 0.25 kB │ map: 0.52 kB
221
221
  dist/lib/ui/uikit/dist/assets/icons/icon-assets-min/16_arrow-link.svg.js  0.30 kB │ gzip: 0.25 kB │ map: 0.51 kB
222
222
  dist/lib/ui/uikit/dist/assets/icons/icon-assets-min/16_link-arrow.svg.js  0.30 kB │ gzip: 0.25 kB │ map: 0.51 kB
@@ -244,8 +244,8 @@ computing gzip size...
244
244
  dist/lib/ui/uikit/dist/assets/icons/icon-assets-min/16_arrow-right.svg.js  0.31 kB │ gzip: 0.25 kB │ map: 0.52 kB
245
245
  dist/_virtual/stringify.js  0.31 kB │ gzip: 0.22 kB │ map: 0.10 kB
246
246
  dist/components/PlAnnotations/components/PlAnnotationsModal.vue.js  0.31 kB │ gzip: 0.22 kB │ map: 0.11 kB
247
- dist/components/PlAgDataTable/PlAgDataTableSheets.vue.js  0.31 kB │ gzip: 0.22 kB │ map: 0.11 kB
248
247
  dist/components/PlAnnotations/components/AnnotationsSidebar.vue.js  0.31 kB │ gzip: 0.22 kB │ map: 0.11 kB
248
+ dist/components/PlAgDataTable/PlAgDataTableSheets.vue.js  0.31 kB │ gzip: 0.22 kB │ map: 0.11 kB
249
249
  dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/valid.js  0.31 kB │ gzip: 0.22 kB │ map: 0.76 kB
250
250
  dist/lib/ui/uikit/dist/assets/icons/icon-assets-min/24_chevron-first.svg.js  0.31 kB │ gzip: 0.25 kB │ map: 0.53 kB
251
251
  dist/lib/ui/uikit/dist/node_modules/.pnpm/d3-selection@3.0.0/node_modules/d3-selection/src/namespaces.js  0.31 kB │ gzip: 0.19 kB │ map: 0.65 kB
@@ -861,7 +861,7 @@ computing gzip size...
861
861
  dist/internal/createAppV1.js  5.80 kB │ gzip: 1.89 kB │ map: 15.32 kB
862
862
  dist/lib/ui/uikit/dist/components/PlDialogModal/PlDialogModal.vue.js  5.80 kB │ gzip: 2.01 kB │ map: 5.33 kB
863
863
  dist/lib/ui/uikit/dist/components/PlSidebar/PlSidebarItem.vue3.js  5.87 kB │ gzip: 1.77 kB │ map: 0.12 kB
864
- dist/internal/createAppV2.js  6.37 kB │ gzip: 2.21 kB │ map: 17.56 kB
864
+ dist/internal/createAppV2.js  6.49 kB │ gzip: 2.29 kB │ map: 18.40 kB
865
865
  dist/lib/ui/uikit/dist/components/PlLogView/PlLogView.vue.js  6.50 kB │ gzip: 2.32 kB │ map: 5.68 kB
866
866
  dist/components/PlTableFilters/PlTableFiltersV2.vue2.js  6.57 kB │ gzip: 2.06 kB │ map: 9.28 kB
867
867
  dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/semver.js  6.70 kB │ gzip: 1.86 kB │ map: 15.20 kB
@@ -913,4 +913,4 @@ computing gzip size...
913
913
  dist/lib/ui/uikit/dist/index.js 497.97 kB │ gzip: 191.79 kB │ map: 0.19 kB
914
914
  dist/lib/ui/uikit/dist/components/PlSlideModal/PlPureSlideModal.vue.js 601.20 kB │ gzip: 204.75 kB │ map: 0.22 kB
915
915
  dist/lib/ui/uikit/dist/components/DataTable/TableComponent.vue.js 603.09 kB │ gzip: 205.61 kB │ map: 0.28 kB
916
- ✓ built in 9.10s
916
+ ✓ built in 8.91s
@@ -1,5 +1,5 @@
1
1
   WARN  Issue while reading "/home/runner/_work/platforma/platforma/.npmrc". Failed to replace env in config: ${NPMJS_TOKEN}
2
2
 
3
- > @platforma-sdk/ui-vue@1.41.11 type-check /home/runner/_work/platforma/platforma/sdk/ui-vue
3
+ > @platforma-sdk/ui-vue@1.41.13 type-check /home/runner/_work/platforma/platforma/sdk/ui-vue
4
4
  > vue-tsc --noEmit --project ./tsconfig.json
5
5
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @platforma-sdk/ui-vue
2
2
 
3
+ ## 1.41.13
4
+
5
+ ### Patch Changes
6
+
7
+ - d29cbad: Simplify app model for v2 api
8
+
3
9
  ## 1.41.11
4
10
 
5
11
  ### Patch Changes
@@ -18,19 +18,13 @@ export declare const createNextAuthorMarker: (marker: AuthorMarker | undefined)
18
18
  * @returns A reactive application object with methods, getters, and state.
19
19
  */
20
20
  export declare function createAppV2<Args = unknown, Outputs extends BlockOutputsBase = BlockOutputsBase, UiState = unknown, Href extends `/${string}` = `/${string}`>(state: ValueWithUTag<BlockState<Args, Outputs, UiState, Href>>, platforma: PlatformaV2<Args, Outputs, UiState, Href>, settings: AppSettings): {
21
+ error: string;
21
22
  model: {
22
23
  args: import('vue').UnwrapRef<Args>;
23
24
  ui: import('vue').UnwrapRef<UiState>;
24
25
  outputs: import('vue').UnwrapRef<OutputValues<Outputs>>;
25
26
  outputErrors: import('vue').UnwrapRef<OutputErrors<Outputs>>;
26
27
  };
27
- readonly valid: boolean;
28
- readonly isChanged: boolean;
29
- readonly error: Error | undefined;
30
- readonly errorString: string | undefined;
31
- readonly save: () => void;
32
- readonly revert: () => void;
33
- readonly setError: (cause: unknown) => void;
34
28
  cloneArgs: () => Args;
35
29
  cloneUiState: () => UiState;
36
30
  cloneNavigationState: () => Mutable<NavigationState<Href>>;
@@ -1 +1 @@
1
- {"version":3,"file":"createAppV2.d.ts","sourceRoot":"","sources":["../../src/internal/createAppV2.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpI,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAQ1G,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,eAAO,MAAM,sBAAsB,WAAY,YAAY,GAAG,SAAS,KAAG,YAGxE,CAAC;AAEH;;;;;;;;;;;;;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,aAAa,CAAC,UAAU,CAAC,IAAI,EAAE,OA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AAC;YACrB,OAAO;yBACM,eAAe,CAAC,IAAI,CAAC;;;;;EAmOzC;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"}
@@ -1,73 +1,75 @@
1
- import { uniqueId as B, deepClone as w, delay as $ } from "../lib/util/helpers/dist/index.js";
1
+ import { deepClone as l, uniqueId as V, delay as L } from "../lib/util/helpers/dist/index.js";
2
2
  import "../sdk/model/dist/index.js";
3
- import { ref as A, computed as h, reactive as z } from "vue";
3
+ import { ref as A, computed as p, reactive as B, watch as W } from "vue";
4
4
  import { createModel as N } from "../createModel.js";
5
- import { createAppModel as D } from "./createAppModel.js";
6
- import { parseQuery as L } from "../urls.js";
7
- import { MultiError as F, unwrapValueOrErrors as G } from "../utils.js";
5
+ import { parseQuery as F } from "../urls.js";
6
+ import { MultiError as G, unwrapValueOrErrors as H } from "../utils.js";
8
7
  import "../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/index.js";
9
- import { UpdateSerializer as v } from "./UpdateSerializer.js";
10
- import { unwrapResult as s, hasAbortError as H } from "../lib/model/common/dist/index.js";
8
+ import { UpdateSerializer as m } from "./UpdateSerializer.js";
9
+ import { unwrapResult as c, hasAbortError as K } from "../lib/model/common/dist/index.js";
11
10
  import { applyPatch as O } from "../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/core.js";
12
- const P = 100, K = (n) => ({
13
- authorId: (n == null ? void 0 : n.authorId) ?? B(),
11
+ const Q = 100, X = (n) => ({
12
+ authorId: (n == null ? void 0 : n.authorId) ?? V(),
14
13
  localVersion: ((n == null ? void 0 : n.localVersion) ?? 0) + 1
15
14
  });
16
- function ue(n, c, d) {
15
+ function se(n, d, h) {
17
16
  const r = (e, ...t) => {
18
- d.debug && console.log(`%c>>> %c${e}`, "color: orange; font-weight: bold", "color: orange", d.appId, ...t);
17
+ h.debug && console.log(`%c>>> %c${e}`, "color: orange; font-weight: bold", "color: orange", h.appId, ...t);
19
18
  }, b = (e, ...t) => {
20
- console.error(`%c>>> %c${e}`, "color: red; font-weight: bold", "color: red", d.appId, ...t);
19
+ console.error(`%c>>> %c${e}`, "color: red; font-weight: bold", "color: red", h.appId, ...t);
21
20
  }, u = {
22
21
  isExternalSnapshot: !1,
23
22
  author: {
24
- authorId: B(),
23
+ authorId: V(),
25
24
  localVersion: 0
26
25
  }
27
- }, S = () => (u.author = K(u.author), r("nextAuthorMarker", u.author), u.author), p = A(!1), f = A(n.uTag), g = d.debounceSpan ?? 200, y = new v({ debounceSpan: g }), U = new v({ debounceSpan: g }), M = new v({ debounceSpan: g }), Q = new v({ debounceSpan: g }), o = A(n.value), T = async (e) => c.setBlockArgs(e, S()), x = async (e) => c.setBlockUiState(e, S()), V = async (e, t) => c.setBlockArgsAndUiState(e, t, S()), R = async (e) => c.setNavigationState(e);
26
+ }, S = () => (u.author = X(u.author), r("nextAuthorMarker", u.author), u.author), g = A(!1), f = A(n.uTag), v = h.debounceSpan ?? 200, y = new m({ debounceSpan: v }), M = new m({ debounceSpan: v }), U = new m({ debounceSpan: v }), R = new m({ debounceSpan: v }), o = A(n.value), T = async (e) => d.setBlockArgs(e, S()), x = async (e) => d.setBlockUiState(e, S()), k = async (e, t) => d.setBlockArgsAndUiState(e, t, S()), q = async (e) => d.setNavigationState(e), C = p(() => {
27
+ const e = Object.entries(o.value.outputs).map(([t, a]) => [t, a.ok && a.value !== void 0 ? a.value : void 0]);
28
+ return Object.fromEntries(e);
29
+ }), D = p(() => {
30
+ const e = Object.entries(o.value.outputs).map(([t, a]) => [t, a && !a.ok ? new G(a.errors) : void 0]);
31
+ return Object.fromEntries(e);
32
+ }), s = B({
33
+ error: "",
34
+ model: {
35
+ args: l(o.value.args),
36
+ ui: l(o.value.ui),
37
+ outputs: C,
38
+ outputErrors: D
39
+ }
40
+ }), E = W(
41
+ () => s.model,
42
+ (e) => {
43
+ const t = l(e);
44
+ r("appModel.model", t), U.run(() => k(t.args, t.ui).then(c));
45
+ },
46
+ { deep: !0 }
47
+ ), $ = (e) => {
48
+ r("updateAppModelSilently", e), E.pause(), s.model.args = l(e.args), s.model.ui = l(e.ui), E.resume();
49
+ };
28
50
  (async () => {
29
51
  var e, t;
30
52
  for (window.addEventListener("beforeunload", () => {
31
- p.value = !0, c.dispose().then(s).catch((a) => {
53
+ g.value = !0, d.dispose().then(c).catch((a) => {
32
54
  b("error in dispose", a);
33
55
  });
34
- }); !p.value; )
56
+ }); !g.value; )
35
57
  try {
36
- const a = await c.getPatches(f.value).then(s);
37
- if (r("patches", JSON.stringify(a, null, 2)), r("uTagRef.value", f.value), r("patches.uTag", a.uTag), r("patches.author", a.author), r("data.author", u.author), f.value = a.uTag, a.value.length === 0) {
38
- await new Promise((m) => setTimeout(m, P));
58
+ const a = await d.getPatches(f.value).then(c);
59
+ if (r("patches.length", a.value.length), r("uTagRef.value", f.value), r("patches.uTag", a.uTag), r("patches.author", a.author), r("data.author", u.author), f.value = a.uTag, a.value.length === 0) {
60
+ await new Promise((w) => setTimeout(w, Q));
39
61
  continue;
40
62
  }
41
- const l = ((e = u.author) == null ? void 0 : e.authorId) !== ((t = a.author) == null ? void 0 : t.authorId);
42
- l || u.isExternalSnapshot ? (r("got external changes, applying them to the snapshot", JSON.stringify(o.value, null, 2)), o.value = O(o.value, a.value, !1, !1).newDocument, u.isExternalSnapshot = l) : o.value = O(o.value, a.value).newDocument, await new Promise((m) => setTimeout(m, P));
63
+ const i = ((e = u.author) == null ? void 0 : e.authorId) !== ((t = a.author) == null ? void 0 : t.authorId);
64
+ i || u.isExternalSnapshot ? (r("got external changes, applying them to the snapshot", JSON.stringify(o.value, null, 2)), o.value = O(o.value, a.value, !1, !1).newDocument, $(o.value), u.isExternalSnapshot = i) : o.value = O(o.value, a.value).newDocument, await new Promise((w) => setTimeout(w, Q));
43
65
  } catch (a) {
44
- H(a) ? (r("patches loop aborted"), p.value = !0) : (b("error in patches loop", a), await new Promise((l) => setTimeout(l, 1e3)));
66
+ K(a) ? (r("patches loop aborted"), g.value = !0) : (b("error in patches loop", a), await new Promise((i) => setTimeout(i, 1e3)));
45
67
  }
46
68
  })();
47
- const k = h(() => {
48
- const e = Object.entries(o.value.outputs).map(([t, a]) => [t, a.ok && a.value !== void 0 ? a.value : void 0]);
49
- return Object.fromEntries(e);
50
- }), q = h(() => {
51
- const e = Object.entries(o.value.outputs).map(([t, a]) => [t, a && !a.ok ? new F(a.errors) : void 0]);
52
- return Object.fromEntries(e);
53
- }), i = D(
54
- {
55
- get() {
56
- return { args: o.value.args, ui: o.value.ui };
57
- },
58
- autoSave: !0,
59
- onSave(e) {
60
- r("onSave", e), M.run(() => V(e.args, e.ui).then(s));
61
- }
62
- },
63
- {
64
- outputs: k,
65
- outputErrors: q
66
- }
67
- ), E = () => w(i.model.args), I = () => w(i.model.ui), j = () => w(o.value.navigationState), C = {
68
- cloneArgs: E,
69
- cloneUiState: I,
70
- cloneNavigationState: j,
69
+ const I = () => l(s.model.args), j = () => l(s.model.ui), P = () => l(o.value.navigationState), z = {
70
+ cloneArgs: I,
71
+ cloneUiState: j,
72
+ cloneNavigationState: P,
71
73
  createArgsModel(e = {}) {
72
74
  return N({
73
75
  get() {
@@ -76,7 +78,7 @@ function ue(n, c, d) {
76
78
  validate: e.validate,
77
79
  autoSave: !0,
78
80
  onSave(t) {
79
- y.run(() => T(t).then(s));
81
+ y.run(() => T(t).then(c));
80
82
  }
81
83
  });
82
84
  },
@@ -91,7 +93,7 @@ function ue(n, c, d) {
91
93
  validate: e.validate,
92
94
  autoSave: !0,
93
95
  onSave(a) {
94
- U.run(() => x(a).then(s));
96
+ M.run(() => x(a).then(c));
95
97
  }
96
98
  });
97
99
  },
@@ -104,7 +106,7 @@ function ue(n, c, d) {
104
106
  * @returns An object with unwrapped output values.
105
107
  */
106
108
  unwrapOutputs(...e) {
107
- const t = o.value.outputs, a = e.map((l) => [l, G(t[l])]);
109
+ const t = o.value.outputs, a = e.map((i) => [i, H(t[i])]);
108
110
  return Object.fromEntries(a);
109
111
  },
110
112
  /**
@@ -114,8 +116,8 @@ function ue(n, c, d) {
114
116
  * @returns A promise resolving after the update is applied.
115
117
  */
116
118
  updateArgs(e) {
117
- const t = E();
118
- return e(t), r("updateArgs", t), i.model.args = t, y.run(() => T(t).then(s));
119
+ const t = I();
120
+ return e(t), r("updateArgs", t), s.model.args = t, y.run(() => T(t).then(c));
119
121
  },
120
122
  /**
121
123
  * Updates the UI state by applying a callback.
@@ -125,8 +127,8 @@ function ue(n, c, d) {
125
127
  * @todo Make it mutable since there is already an initial one
126
128
  */
127
129
  updateUiState(e) {
128
- const t = e(I());
129
- return r("updateUiState", t), i.model.ui = t, U.run(() => x(t).then(s));
130
+ const t = e(j());
131
+ return r("updateUiState", t), s.model.ui = t, M.run(() => x(t).then(c));
130
132
  },
131
133
  /**
132
134
  * Navigates to a specific href by updating the navigation state.
@@ -135,24 +137,24 @@ function ue(n, c, d) {
135
137
  * @returns A promise resolving after the navigation state is updated.
136
138
  */
137
139
  navigateTo(e) {
138
- const t = j();
139
- return t.href = e, Q.run(() => R(t).then(s));
140
+ const t = P();
141
+ return t.href = e, R.run(() => q(t).then(c));
140
142
  },
141
143
  async allSettled() {
142
- return await $(0), M.allSettled();
144
+ return await L(0), U.allSettled();
143
145
  }
144
146
  }, J = {
145
- closedRef: p,
147
+ closedRef: g,
146
148
  snapshot: o,
147
- queryParams: h(() => L(o.value.navigationState.href)),
148
- href: h(() => o.value.navigationState.href),
149
- hasErrors: h(() => Object.values(o.value.outputs).some((e) => !(e != null && e.ok)))
149
+ queryParams: p(() => F(o.value.navigationState.href)),
150
+ href: p(() => o.value.navigationState.href),
151
+ hasErrors: p(() => Object.values(o.value.outputs).some((e) => !(e != null && e.ok)))
150
152
  };
151
- return z(Object.assign(i, C, J));
153
+ return B(Object.assign(s, z, J));
152
154
  }
153
155
  export {
154
- ue as createAppV2,
155
- K as createNextAuthorMarker,
156
- P as patchPoolingDelay
156
+ se as createAppV2,
157
+ X as createNextAuthorMarker,
158
+ Q as patchPoolingDelay
157
159
  };
158
160
  //# sourceMappingURL=createAppV2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createAppV2.js","sources":["../../src/internal/createAppV2.ts"],"sourcesContent":["import { deepClone, delay, uniqueId } from '@milaboratories/helpers';\nimport type { Mutable } from '@milaboratories/helpers';\nimport type { NavigationState, BlockOutputsBase, BlockState, PlatformaV2, ValueWithUTag, AuthorMarker } from '@platforma-sdk/model';\nimport { hasAbortError, unwrapResult } from '@platforma-sdk/model';\nimport type { Ref } from 'vue';\nimport { reactive, computed, ref } from 'vue';\nimport type { StateModelOptions, UnwrapOutputs, OutputValues, OutputErrors, AppSettings } from '../types';\nimport { createModel } from '../createModel';\nimport { createAppModel } from './createAppModel';\nimport { parseQuery } from '../urls';\nimport { MultiError, unwrapValueOrErrors } from '../utils';\nimport { applyPatch } from 'fast-json-patch';\nimport { UpdateSerializer } from './UpdateSerializer';\n\nexport const patchPoolingDelay = 100;\n\nexport const createNextAuthorMarker = (marker: AuthorMarker | undefined): AuthorMarker => ({\n authorId: marker?.authorId ?? uniqueId(),\n localVersion: (marker?.localVersion ?? 0) + 1,\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 UiState - The type of the UI state.\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 createAppV2<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n>(\n state: ValueWithUTag<BlockState<Args, Outputs, UiState, Href>>,\n platforma: PlatformaV2<Args, Outputs, UiState, Href>,\n settings: AppSettings,\n) {\n type AppModel = {\n args: Args;\n ui: UiState;\n };\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', settings.appId, ...rest);\n }\n };\n\n const error = (msg: string, ...rest: unknown[]) => {\n console.error(`%c>>> %c${msg}`, 'color: red; font-weight: bold', 'color: red', settings.appId, ...rest);\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 setArgsQueue = new UpdateSerializer({ debounceSpan });\n const setUiStateQueue = new UpdateSerializer({ debounceSpan });\n const setArgsAndUiStateQueue = 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 args: Args;\n outputs: Partial<Outputs>;\n ui: UiState;\n navigationState: NavigationState<Href>;\n }>(state.value) as Ref<{\n args: Args;\n outputs: Partial<Outputs>;\n ui: UiState;\n navigationState: NavigationState<Href>;\n }>;\n\n const setBlockArgs = async (args: Args) => {\n return platforma.setBlockArgs(args, nextAuthorMarker());\n };\n\n const setBlockUiState = async (ui: UiState) => {\n return platforma.setBlockUiState(ui, nextAuthorMarker());\n };\n\n const setBlockArgsAndUiState = async (args: Args, ui: UiState) => {\n return platforma.setBlockArgsAndUiState(args, ui, nextAuthorMarker());\n };\n\n const setNavigationState = async (state: NavigationState<Href>) => {\n return platforma.setNavigationState(state);\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', JSON.stringify(patches, null, 2));\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', JSON.stringify(snapshot.value, null, 2));\n snapshot.value = applyPatch(snapshot.value, patches.value, false, false).newDocument;\n data.isExternalSnapshot = isAuthorChanged;\n } else {\n // Mutable behavior\n snapshot.value = applyPatch(snapshot.value, patches.value).newDocument;\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 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 ? new MultiError(vOrErr.errors) : undefined]);\n return Object.fromEntries(entries);\n });\n\n const appModel = createAppModel(\n {\n get() {\n return { args: snapshot.value.args, ui: snapshot.value.ui } as AppModel;\n },\n autoSave: true,\n onSave(newData: AppModel) {\n debug('onSave', newData);\n setArgsAndUiStateQueue.run(() => setBlockArgsAndUiState(newData.args, newData.ui).then(unwrapResult));\n },\n },\n {\n outputs,\n outputErrors,\n },\n settings,\n );\n\n const cloneArgs = () => deepClone(appModel.model.args) as Args;\n const cloneUiState = () => deepClone(appModel.model.ui) as UiState;\n const cloneNavigationState = () => deepClone(snapshot.value.navigationState) as Mutable<NavigationState<Href>>;\n\n const methods = {\n cloneArgs,\n cloneUiState,\n cloneNavigationState,\n createArgsModel<T extends Args = Args>(options: StateModelOptions<Args, T> = {}) {\n return createModel<T, Args>({\n get() {\n if (options.transform) {\n return options.transform(snapshot.value.args as Args);\n }\n\n return snapshot.value.args as T;\n },\n validate: options.validate,\n autoSave: true,\n onSave(newArgs) {\n setArgsQueue.run(() => setBlockArgs(newArgs).then(unwrapResult));\n },\n });\n },\n /**\n * defaultUiState is temporarily here, remove it after implementing initialUiState\n */\n createUiModel<T extends UiState = UiState>(options: StateModelOptions<UiState, T> = {}, defaultUiState: () => UiState) {\n return createModel<T, UiState>({\n get() {\n if (options.transform) {\n return options.transform(snapshot.value.ui as UiState);\n }\n\n return (snapshot.value.ui ?? defaultUiState()) as T;\n },\n validate: options.validate,\n autoSave: true,\n onSave(newData) {\n setUiStateQueue.run(() => setBlockUiState(newData).then(unwrapResult));\n },\n });\n },\n /**\n * Retrieves the unwrapped values of outputs for the given keys.\n *\n * @template K - Keys of the outputs to unwrap.\n * @param keys - List of output names.\n * @throws Error if the outputs contain errors.\n * @returns An object with unwrapped output values.\n */\n unwrapOutputs<K extends keyof Outputs>(...keys: K[]): UnwrapOutputs<Outputs, K> {\n const outputs = snapshot.value.outputs as Partial<Readonly<Outputs>>;\n const entries = keys.map((key) => [key, unwrapValueOrErrors(outputs[key])]);\n return Object.fromEntries(entries);\n },\n /**\n * Updates the arguments state by applying a callback.\n *\n * @param cb - Callback to modify the current arguments.\n * @returns A promise resolving after the update is applied.\n */\n updateArgs(cb: (args: Args) => void): Promise<boolean> {\n const newArgs = cloneArgs();\n cb(newArgs);\n debug('updateArgs', newArgs);\n appModel.model.args = newArgs;\n return setArgsQueue.run(() => setBlockArgs(newArgs).then(unwrapResult));\n },\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 updateUiState(cb: (args: UiState) => UiState): Promise<boolean> {\n const newUiState = cb(cloneUiState());\n debug('updateUiState', newUiState);\n appModel.model.ui = newUiState;\n return setUiStateQueue.run(() => setBlockUiState(newUiState).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 setArgsAndUiStateQueue.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 return reactive(Object.assign(appModel, methods, getters));\n}\n\nexport type BaseAppV2<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n> = ReturnType<typeof createAppV2<Args, Outputs, UiState, Href>>;\n"],"names":["patchPoolingDelay","createNextAuthorMarker","marker","uniqueId","createAppV2","state","platforma","settings","debug","msg","rest","error","data","nextAuthorMarker","closedRef","ref","uTagRef","debounceSpan","setArgsQueue","UpdateSerializer","setUiStateQueue","setArgsAndUiStateQueue","setNavigationStateQueue","snapshot","setBlockArgs","args","setBlockUiState","ui","setBlockArgsAndUiState","setNavigationState","unwrapResult","err","patches","resolve","isAuthorChanged","_a","_b","applyPatch","hasAbortError","outputs","computed","entries","k","vOrErr","outputErrors","MultiError","appModel","createAppModel","newData","cloneArgs","deepClone","cloneUiState","cloneNavigationState","methods","options","createModel","newArgs","defaultUiState","keys","key","unwrapValueOrErrors","cb","newUiState","href","newState","delay","getters","parseQuery","v","reactive"],"mappings":";;;;;;;;;;;AAcO,MAAMA,IAAoB,KAEpBC,IAAyB,CAACC,OAAoD;AAAA,EACzF,WAAUA,KAAA,gBAAAA,EAAQ,aAAYC,EAAS;AAAA,EACvC,gBAAeD,KAAA,gBAAAA,EAAQ,iBAAgB,KAAK;AAC9C;AAgBgB,SAAAE,GAMdC,GACAC,GACAC,GACA;AAMM,QAAAC,IAAQ,CAACC,MAAgBC,MAAoB;AACjD,IAAIH,EAAS,SACH,QAAA,IAAI,WAAWE,CAAG,IAAI,oCAAoC,iBAAiBF,EAAS,OAAO,GAAGG,CAAI;AAAA,EAE9G,GAEMC,IAAQ,CAACF,MAAgBC,MAAoB;AACzC,YAAA,MAAM,WAAWD,CAAG,IAAI,iCAAiC,cAAcF,EAAS,OAAO,GAAGG,CAAI;AAAA,EACxG,GAEME,IAAO;AAAA,IACX,oBAAoB;AAAA,IACpB,QAAQ;AAAA,MACN,UAAUT,EAAS;AAAA,MACnB,cAAc;AAAA,IAAA;AAAA,EAElB,GAEMU,IAAmB,OAClBD,EAAA,SAASX,EAAuBW,EAAK,MAAM,GAC1CJ,EAAA,oBAAoBI,EAAK,MAAM,GAC9BA,EAAK,SAGRE,IAAYC,EAAI,EAAK,GAErBC,IAAUD,EAAIV,EAAM,IAAI,GAExBY,IAAeV,EAAS,gBAAgB,KAExCW,IAAe,IAAIC,EAAiB,EAAE,cAAAF,GAAc,GACpDG,IAAkB,IAAID,EAAiB,EAAE,cAAAF,GAAc,GACvDI,IAAyB,IAAIF,EAAiB,EAAE,cAAAF,GAAc,GAC9DK,IAA0B,IAAIH,EAAiB,EAAE,cAAAF,GA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O,CAAC;AAC3D;"}
1
+ {"version":3,"file":"createAppV2.js","sources":["../../src/internal/createAppV2.ts"],"sourcesContent":["import { deepClone, delay, uniqueId } from '@milaboratories/helpers';\nimport type { Mutable } from '@milaboratories/helpers';\nimport type { NavigationState, BlockOutputsBase, BlockState, PlatformaV2, ValueWithUTag, AuthorMarker } from '@platforma-sdk/model';\nimport { hasAbortError, unwrapResult } from '@platforma-sdk/model';\nimport type { Ref } from 'vue';\nimport { reactive, computed, ref, watch } from 'vue';\nimport type { StateModelOptions, UnwrapOutputs, OutputValues, OutputErrors, AppSettings } from '../types';\nimport { createModel } from '../createModel';\nimport { parseQuery } from '../urls';\nimport { MultiError, unwrapValueOrErrors } from '../utils';\nimport { applyPatch } from 'fast-json-patch';\nimport { UpdateSerializer } from './UpdateSerializer';\n\nexport const patchPoolingDelay = 100;\n\nexport const createNextAuthorMarker = (marker: AuthorMarker | undefined): AuthorMarker => ({\n authorId: marker?.authorId ?? uniqueId(),\n localVersion: (marker?.localVersion ?? 0) + 1,\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 UiState - The type of the UI state.\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 createAppV2<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n>(\n state: ValueWithUTag<BlockState<Args, Outputs, UiState, Href>>,\n platforma: PlatformaV2<Args, Outputs, UiState, 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', settings.appId, ...rest);\n }\n };\n\n const error = (msg: string, ...rest: unknown[]) => {\n console.error(`%c>>> %c${msg}`, 'color: red; font-weight: bold', 'color: red', settings.appId, ...rest);\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 setArgsQueue = new UpdateSerializer({ debounceSpan });\n const setUiStateQueue = new UpdateSerializer({ debounceSpan });\n const setArgsAndUiStateQueue = 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 args: Args;\n outputs: Partial<Outputs>;\n ui: UiState;\n navigationState: NavigationState<Href>;\n }>(state.value) as Ref<{\n args: Args;\n outputs: Partial<Outputs>;\n ui: UiState;\n navigationState: NavigationState<Href>;\n }>;\n\n const setBlockArgs = async (args: Args) => {\n return platforma.setBlockArgs(args, nextAuthorMarker());\n };\n\n const setBlockUiState = async (ui: UiState) => {\n return platforma.setBlockUiState(ui, nextAuthorMarker());\n };\n\n const setBlockArgsAndUiState = async (args: Args, ui: UiState) => {\n return platforma.setBlockArgsAndUiState(args, ui, 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 ? new MultiError(vOrErr.errors) : undefined]);\n return Object.fromEntries(entries);\n });\n\n const appModel = reactive({\n error: '',\n model: {\n args: deepClone(snapshot.value.args) as Args,\n ui: deepClone(snapshot.value.ui) as UiState,\n outputs,\n outputErrors,\n },\n }) as {\n error: string;\n model: {\n args: Args;\n ui: UiState;\n outputs: OutputValues<Outputs>;\n outputErrors: OutputErrors<Outputs>;\n };\n };\n\n const appModelWatch = watch(\n () => appModel.model,\n (_newData) => {\n const newData = deepClone(_newData);\n debug('appModel.model', newData);\n setArgsAndUiStateQueue.run(() => setBlockArgsAndUiState(newData.args, newData.ui).then(unwrapResult));\n },\n { deep: true },\n );\n\n const updateAppModelSilently = (newData: {\n args: Args;\n ui: UiState;\n }) => {\n debug('updateAppModelSilently', newData);\n appModelWatch.pause();\n appModel.model.args = deepClone(newData.args) as Args;\n appModel.model.ui = deepClone(newData.ui) as UiState;\n appModelWatch.resume();\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', JSON.stringify(snapshot.value, null, 2));\n snapshot.value = applyPatch(snapshot.value, patches.value, false, false).newDocument;\n updateAppModelSilently(snapshot.value);\n data.isExternalSnapshot = isAuthorChanged;\n } else {\n // Mutable behavior\n snapshot.value = applyPatch(snapshot.value, patches.value).newDocument;\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 cloneArgs = () => deepClone(appModel.model.args) as Args;\n const cloneUiState = () => deepClone(appModel.model.ui) as UiState;\n const cloneNavigationState = () => deepClone(snapshot.value.navigationState) as Mutable<NavigationState<Href>>;\n\n const methods = {\n cloneArgs,\n cloneUiState,\n cloneNavigationState,\n createArgsModel<T extends Args = Args>(options: StateModelOptions<Args, T> = {}) {\n return createModel<T, Args>({\n get() {\n if (options.transform) {\n return options.transform(snapshot.value.args as Args);\n }\n\n return snapshot.value.args as T;\n },\n validate: options.validate,\n autoSave: true,\n onSave(newArgs) {\n setArgsQueue.run(() => setBlockArgs(newArgs).then(unwrapResult));\n },\n });\n },\n /**\n * defaultUiState is temporarily here, remove it after implementing initialUiState\n */\n createUiModel<T extends UiState = UiState>(options: StateModelOptions<UiState, T> = {}, defaultUiState: () => UiState) {\n return createModel<T, UiState>({\n get() {\n if (options.transform) {\n return options.transform(snapshot.value.ui as UiState);\n }\n\n return (snapshot.value.ui ?? defaultUiState()) as T;\n },\n validate: options.validate,\n autoSave: true,\n onSave(newData) {\n setUiStateQueue.run(() => setBlockUiState(newData).then(unwrapResult));\n },\n });\n },\n /**\n * Retrieves the unwrapped values of outputs for the given keys.\n *\n * @template K - Keys of the outputs to unwrap.\n * @param keys - List of output names.\n * @throws Error if the outputs contain errors.\n * @returns An object with unwrapped output values.\n */\n unwrapOutputs<K extends keyof Outputs>(...keys: K[]): UnwrapOutputs<Outputs, K> {\n const outputs = snapshot.value.outputs as Partial<Readonly<Outputs>>;\n const entries = keys.map((key) => [key, unwrapValueOrErrors(outputs[key])]);\n return Object.fromEntries(entries);\n },\n /**\n * Updates the arguments state by applying a callback.\n *\n * @param cb - Callback to modify the current arguments.\n * @returns A promise resolving after the update is applied.\n */\n updateArgs(cb: (args: Args) => void): Promise<boolean> {\n const newArgs = cloneArgs();\n cb(newArgs);\n debug('updateArgs', newArgs);\n appModel.model.args = newArgs;\n return setArgsQueue.run(() => setBlockArgs(newArgs).then(unwrapResult));\n },\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 updateUiState(cb: (args: UiState) => UiState): Promise<boolean> {\n const newUiState = cb(cloneUiState());\n debug('updateUiState', newUiState);\n appModel.model.ui = newUiState;\n return setUiStateQueue.run(() => setBlockUiState(newUiState).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 setArgsAndUiStateQueue.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 return reactive(Object.assign(appModel, methods, getters));\n}\n\nexport type BaseAppV2<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n> = ReturnType<typeof createAppV2<Args, Outputs, UiState, Href>>;\n"],"names":["patchPoolingDelay","createNextAuthorMarker","marker","uniqueId","createAppV2","state","platforma","settings","debug","msg","rest","error","data","nextAuthorMarker","closedRef","ref","uTagRef","debounceSpan","setArgsQueue","UpdateSerializer","setUiStateQueue","setArgsAndUiStateQueue","setNavigationStateQueue","snapshot","setBlockArgs","args","setBlockUiState","ui","setBlockArgsAndUiState","setNavigationState","outputs","computed","entries","k","vOrErr","outputErrors","MultiError","appModel","reactive","deepClone","appModelWatch","watch","_newData","newData","unwrapResult","updateAppModelSilently","err","patches","resolve","isAuthorChanged","_a","_b","applyPatch","hasAbortError","cloneArgs","cloneUiState","cloneNavigationState","methods","options","createModel","newArgs","defaultUiState","keys","key","unwrapValueOrErrors","cb","newUiState","href","newState","delay","getters","parseQuery","v"],"mappings":";;;;;;;;;;AAaO,MAAMA,IAAoB,KAEpBC,IAAyB,CAACC,OAAoD;AAAA,EACzF,WAAUA,KAAA,gBAAAA,EAAQ,aAAYC,EAAS;AAAA,EACvC,gBAAeD,KAAA,gBAAAA,EAAQ,iBAAgB,KAAK;AAC9C;AAgBgB,SAAAE,GAMdC,GACAC,GACAC,GACA;AACM,QAAAC,IAAQ,CAACC,MAAgBC,MAAoB;AACjD,IAAIH,EAAS,SACH,QAAA,IAAI,WAAWE,CAAG,IAAI,oCAAoC,iBAAiBF,EAAS,OAAO,GAAGG,CAAI;AAAA,EAE9G,GAEMC,IAAQ,CAACF,MAAgBC,MAAoB;AACzC,YAAA,MAAM,WAAWD,CAAG,IAAI,iCAAiC,cAAcF,EAAS,OAAO,GAAGG,CAAI;AAAA,EACxG,GAEME,IAAO;AAAA,IACX,oBAAoB;AAAA,IACpB,QAAQ;AAAA,MACN,UAAUT,EAAS;AAAA,MACnB,cAAc;AAAA,IAAA;AAAA,EAElB,GAEMU,IAAmB,OAClBD,EAAA,SAASX,EAAuBW,EAAK,MAAM,GAC1CJ,EAAA,oBAAoBI,EAAK,MAAM,GAC9BA,EAAK,SAGRE,IAAYC,EAAI,EAAK,GAErBC,IAAUD,EAAIV,EAAM,IAAI,GAExBY,IAAeV,EAAS,gBAAgB,KAExCW,IAAe,IAAIC,EAAiB,EAAE,cAAAF,GAAc,GACpDG,IAAkB,IAAID,EAAiB,EAAE,cAAAF,GAAc,GACvDI,IAAyB,IAAIF,EAAiB,EAAE,cAAAF,GAAc,GAC9DK,IAA0B,IAAI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;AAAA,IACd,WAAAxD;AAAA,IACA,UAAAS;AAAA,IACA,aAAaQ,EAAS,MAAMwC,EAAiBhD,EAAS,MAAM,gBAAgB,IAAY,CAAC;AAAA,IACzF,MAAMQ,EAAS,MAAMR,EAAS,MAAM,gBAAgB,IAAI;AAAA,IACxD,WAAWQ,EAAS,MAAM,OAAO,OAAOR,EAAS,MAAM,OAAqC,EAAE,KAAK,CAACiD,MAAM,EAACA,KAAA,QAAAA,EAAG,GAAE,CAAC;AAAA,EACnH;AAEA,SAAOlC,EAAS,OAAO,OAAOD,GAAUoB,GAASa,CAAO,CAAC;AAC3D;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/ui-vue",
3
- "version": "1.41.11",
3
+ "version": "1.41.13",
4
4
  "type": "module",
5
5
  "main": "dist/lib.js",
6
6
  "styles": "dist/lib.js",
@@ -26,8 +26,8 @@
26
26
  "d3-format": "^3.1.0",
27
27
  "zod": "~3.23.8",
28
28
  "@milaboratories/biowasm-tools": "^1.1.0",
29
- "@milaboratories/uikit": "2.3.21",
30
- "@platforma-sdk/model": "~1.41.6"
29
+ "@platforma-sdk/model": "~1.41.6",
30
+ "@milaboratories/uikit": "2.3.21"
31
31
  },
32
32
  "devDependencies": {
33
33
  "happy-dom": "^15.11.7",
@@ -43,9 +43,9 @@
43
43
  "yarpm": "^1.2.0",
44
44
  "fast-json-patch": "^3.1.1",
45
45
  "@faker-js/faker": "^9.2.0",
46
+ "@milaboratories/ts-configs": "1.0.5",
46
47
  "@milaboratories/build-configs": "1.0.5",
47
48
  "@milaboratories/helpers": "^1.6.19",
48
- "@milaboratories/ts-configs": "1.0.5",
49
49
  "@milaboratories/eslint-config": "^1.0.4"
50
50
  },
51
51
  "scripts": {
@@ -3,10 +3,9 @@ import type { Mutable } from '@milaboratories/helpers';
3
3
  import type { NavigationState, BlockOutputsBase, BlockState, PlatformaV2, ValueWithUTag, AuthorMarker } from '@platforma-sdk/model';
4
4
  import { hasAbortError, unwrapResult } from '@platforma-sdk/model';
5
5
  import type { Ref } from 'vue';
6
- import { reactive, computed, ref } from 'vue';
6
+ import { reactive, computed, ref, watch } from 'vue';
7
7
  import type { StateModelOptions, UnwrapOutputs, OutputValues, OutputErrors, AppSettings } from '../types';
8
8
  import { createModel } from '../createModel';
9
- import { createAppModel } from './createAppModel';
10
9
  import { parseQuery } from '../urls';
11
10
  import { MultiError, unwrapValueOrErrors } from '../utils';
12
11
  import { applyPatch } from 'fast-json-patch';
@@ -43,11 +42,6 @@ export function createAppV2<
43
42
  platforma: PlatformaV2<Args, Outputs, UiState, Href>,
44
43
  settings: AppSettings,
45
44
  ) {
46
- type AppModel = {
47
- args: Args;
48
- ui: UiState;
49
- };
50
-
51
45
  const debug = (msg: string, ...rest: unknown[]) => {
52
46
  if (settings.debug) {
53
47
  console.log(`%c>>> %c${msg}`, 'color: orange; font-weight: bold', 'color: orange', settings.appId, ...rest);
@@ -113,6 +107,55 @@ export function createAppV2<
113
107
  return platforma.setNavigationState(state);
114
108
  };
115
109
 
110
+ const outputs = computed<OutputValues<Outputs>>(() => {
111
+ const entries = Object.entries(snapshot.value.outputs as Partial<Readonly<Outputs>>).map(([k, vOrErr]) => [k, vOrErr.ok && vOrErr.value !== undefined ? vOrErr.value : undefined]);
112
+ return Object.fromEntries(entries);
113
+ });
114
+
115
+ const outputErrors = computed<OutputErrors<Outputs>>(() => {
116
+ const entries = Object.entries(snapshot.value.outputs as Partial<Readonly<Outputs>>).map(([k, vOrErr]) => [k, vOrErr && !vOrErr.ok ? new MultiError(vOrErr.errors) : undefined]);
117
+ return Object.fromEntries(entries);
118
+ });
119
+
120
+ const appModel = reactive({
121
+ error: '',
122
+ model: {
123
+ args: deepClone(snapshot.value.args) as Args,
124
+ ui: deepClone(snapshot.value.ui) as UiState,
125
+ outputs,
126
+ outputErrors,
127
+ },
128
+ }) as {
129
+ error: string;
130
+ model: {
131
+ args: Args;
132
+ ui: UiState;
133
+ outputs: OutputValues<Outputs>;
134
+ outputErrors: OutputErrors<Outputs>;
135
+ };
136
+ };
137
+
138
+ const appModelWatch = watch(
139
+ () => appModel.model,
140
+ (_newData) => {
141
+ const newData = deepClone(_newData);
142
+ debug('appModel.model', newData);
143
+ setArgsAndUiStateQueue.run(() => setBlockArgsAndUiState(newData.args, newData.ui).then(unwrapResult));
144
+ },
145
+ { deep: true },
146
+ );
147
+
148
+ const updateAppModelSilently = (newData: {
149
+ args: Args;
150
+ ui: UiState;
151
+ }) => {
152
+ debug('updateAppModelSilently', newData);
153
+ appModelWatch.pause();
154
+ appModel.model.args = deepClone(newData.args) as Args;
155
+ appModel.model.ui = deepClone(newData.ui) as UiState;
156
+ appModelWatch.resume();
157
+ };
158
+
116
159
  (async () => {
117
160
  window.addEventListener('beforeunload', () => {
118
161
  closedRef.value = true;
@@ -125,7 +168,7 @@ export function createAppV2<
125
168
  try {
126
169
  const patches = await platforma.getPatches(uTagRef.value).then(unwrapResult);
127
170
 
128
- debug('patches', JSON.stringify(patches, null, 2));
171
+ debug('patches.length', patches.value.length);
129
172
  debug('uTagRef.value', uTagRef.value);
130
173
  debug('patches.uTag', patches.uTag);
131
174
  debug('patches.author', patches.author);
@@ -144,6 +187,7 @@ export function createAppV2<
144
187
  if (isAuthorChanged || data.isExternalSnapshot) {
145
188
  debug('got external changes, applying them to the snapshot', JSON.stringify(snapshot.value, null, 2));
146
189
  snapshot.value = applyPatch(snapshot.value, patches.value, false, false).newDocument;
190
+ updateAppModelSilently(snapshot.value);
147
191
  data.isExternalSnapshot = isAuthorChanged;
148
192
  } else {
149
193
  // Mutable behavior
@@ -163,34 +207,6 @@ export function createAppV2<
163
207
  }
164
208
  })();
165
209
 
166
- const outputs = computed<OutputValues<Outputs>>(() => {
167
- const entries = Object.entries(snapshot.value.outputs as Partial<Readonly<Outputs>>).map(([k, vOrErr]) => [k, vOrErr.ok && vOrErr.value !== undefined ? vOrErr.value : undefined]);
168
- return Object.fromEntries(entries);
169
- });
170
-
171
- const outputErrors = computed<OutputErrors<Outputs>>(() => {
172
- const entries = Object.entries(snapshot.value.outputs as Partial<Readonly<Outputs>>).map(([k, vOrErr]) => [k, vOrErr && !vOrErr.ok ? new MultiError(vOrErr.errors) : undefined]);
173
- return Object.fromEntries(entries);
174
- });
175
-
176
- const appModel = createAppModel(
177
- {
178
- get() {
179
- return { args: snapshot.value.args, ui: snapshot.value.ui } as AppModel;
180
- },
181
- autoSave: true,
182
- onSave(newData: AppModel) {
183
- debug('onSave', newData);
184
- setArgsAndUiStateQueue.run(() => setBlockArgsAndUiState(newData.args, newData.ui).then(unwrapResult));
185
- },
186
- },
187
- {
188
- outputs,
189
- outputErrors,
190
- },
191
- settings,
192
- );
193
-
194
210
  const cloneArgs = () => deepClone(appModel.model.args) as Args;
195
211
  const cloneUiState = () => deepClone(appModel.model.ui) as UiState;
196
212
  const cloneNavigationState = () => deepClone(snapshot.value.navigationState) as Mutable<NavigationState<Href>>;