@platforma-sdk/ui-vue 1.90.0 → 1.90.6

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.
@@ -36,7 +36,7 @@ transforming...
36
36
  rendering chunks...
37
37
  
38
38
  [unplugin:dts] Start generate declaration files...
39
- [unplugin:dts] Declaration files built in 5066ms.
39
+ [unplugin:dts] Declaration files built in 5217ms.
40
40
  
41
41
  computing gzip size...
42
42
  dist/components/PlAnnotations/components/PlAnnotations.vue_vue_type_style_index_0_lang.css 0.04 kB │ gzip: 0.06 kB
@@ -261,16 +261,16 @@ dist/components/PlTableFilters/PlTableFiltersV2.vue_vue_type_script_setup_true_l
261
261
  dist/components/PlBtnExportArchive/PlBtnExportArchive.vue_vue_type_script_setup_true_lang.js 5.39 kB │ gzip: 2.19 kB │ map: 12.10 kB
262
262
  dist/index.js 5.42 kB │ gzip: 1.55 kB │ map: 1.75 kB
263
263
  dist/lib.js 6.23 kB │ gzip: 1.60 kB │ map: 9.81 kB
264
- dist/internal/createAppV3.js 6.24 kB │ gzip: 2.35 kB │ map: 23.42 kB
264
+ dist/internal/createAppV3.js 6.35 kB │ gzip: 2.38 kB │ map: 24.05 kB
265
265
  dist/components/PlAgDataTable/sources/table-source-v2.js 7.76 kB │ gzip: 2.94 kB │ map: 30.69 kB
266
266
  dist/components/PlAdvancedFilter/PlAdvancedFilter.vue_vue_type_script_setup_true_lang.js 9.05 kB │ gzip: 2.69 kB │ map: 21.15 kB
267
267
  dist/components/PlAdvancedFilter/FilterEditor.vue_vue_type_script_setup_true_lang.js 11.71 kB │ gzip: 3.31 kB │ map: 28.56 kB
268
268
  dist/components/PlAgDataTable/PlAgDataTableV2.vue_vue_type_script_setup_true_lang.js 12.72 kB │ gzip: 4.05 kB │ map: 34.95 kB
269
269
 
270
- ✓ built in 5.95s
270
+ ✓ built in 5.96s
271
271
  [PLUGIN_TIMINGS] JavaScript callbacks ran for 5.9s of this 5.9s build (99%).
272
272
  The slowest callbacks, timed inside each callback (the wait before a callback starts is excluded, the time it awaits is included):
273
- - plugin unplugin-dts buildStart (81%, 4.8s, 1 call)
273
+ - plugin unplugin-dts buildStart (84%, 5.0s, 1 call)
274
274
  Additional callback time came from the callbacks below and from callbacks under 1s.
275
275
  2 callbacks are listed without a time. Their calls overlapped, so the time inside one call includes work from other calls. To find their cost, profile the build with `node --cpu-prof`:
276
276
  - plugin sourcemaps load (144 calls)
@@ -6,5 +6,5 @@ Checking formatting...
6
6
  Checking formatting...
7
7
 
8
8
  All matched files use the correct format.
9
- Finished in 1100ms on 160 files using 16 threads.
9
+ Finished in 607ms on 160 files using 16 threads.
10
10
  Format check completed successfully
@@ -4,5 +4,5 @@ $ ts-builder linter --check
4
4
  Linting project...
5
5
  ↳ oxlint --config /home/runner/_work/platforma/platforma/sdk/ui-vue/.oxlintrc.json --deny-warnings
6
6
  Found 0 warnings and 0 errors.
7
- Finished in 14ms on 143 files with 108 rules using 16 threads.
7
+ Finished in 22ms on 143 files with 108 rules using 16 threads.
8
8
  Linting completed successfully
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @platforma-sdk/ui-vue
2
2
 
3
+ ## 1.90.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 2a61e1a: A block window no longer drops an edit that is not saved yet. Until the first save of a window landed, every update from the server carried the previous author of the block's data, also an update that changed the outputs or the section only. The window took such an update for a change made elsewhere and put the server's data in place of its own, so an edit with its save still on the way was lost, and the next save wrote the block's data without it. The window's data is now replaced only when the stored data itself has changed.
8
+
9
+ ## 1.90.2
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [fd21724]
14
+ - @platforma-sdk/model@1.90.2
15
+ - @milaboratories/uikit@2.17.10
16
+
3
17
  ## 1.90.0
4
18
 
5
19
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"PlAnnotations.vue_vue_type_script_setup_true_lang.js","names":["$style","_openBlock","_createBlock","_unref","_withCtx","_createVNode","AnnotationsSidebar","_normalizeClass","FilterSidebar","_createCommentVNode","AnnotationsSidebar_default","FilterSidebar_default","PlAnnotations_vue_vue_type_script_setup_true_lang_default","props","__props","selectedStepId","shallowRef","selectedStep","computed","isNil","step","confirmResetSchema","useConfirm","handleDeleteSchema","updateSelectedStepId","id","updateSelectedStep","produce","idx","draft","s","openBlock","createBlock","unref","PlSidebarGroup","withCtx","createVNode","normalizeClass","_ctx","createCommentVNode"],"sources":["../../../../src/components/PlAnnotations/components/PlAnnotations.vue"],"sourcesContent":["<script lang=\"ts\">\nimport type { Props as BaseProps } from \"./FilterSidebar.vue\";\nexport type Props = Omit<BaseProps, \"step\" | \"onUpdateStep\"> & {\n annotation: Annotation;\n onUpdateAnnotation: (annotation: Annotation) => void;\n onDeleteSchema?: () => void;\n};\n</script>\n\n<script setup lang=\"ts\">\nimport { computed, effect, shallowRef } from \"vue\";\n\nimport { isNil } from \"@milaboratories/helpers\";\nimport { produce } from \"immer\";\nimport { PlSidebarGroup, useConfirm } from \"@milaboratories/uikit\";\n\nimport type { Annotation, Filter } from \"../types\";\nimport AnnotationsSidebar from \"./AnnotationsSidebar.vue\";\nimport FilterSidebar from \"./FilterSidebar.vue\";\n\nconst props = defineProps<Props>();\n\nconst selectedStepId = shallowRef<undefined | number>(undefined);\n\nconst selectedStep = computed(() => {\n return isNil(selectedStepId.value) || isNil(props.annotation)\n ? undefined\n : props.annotation.steps.find((step) => step.id === selectedStepId.value);\n});\n\neffect(function setDefaultStepId() {\n if (selectedStepId.value === undefined && props.annotation.steps.length > 0) {\n selectedStepId.value = props.annotation.steps[0].id;\n }\n});\n\nconst confirmResetSchema = useConfirm({\n title: \"Reset Schema\",\n message: \"Are you sure you want to reset the schema? This action cannot be undone.\",\n confirmLabel: \"Yes, reset\",\n cancelLabel: \"No, cancel\",\n});\n\nasync function handleDeleteSchema() {\n if (await confirmResetSchema()) {\n selectedStepId.value = undefined;\n props.onDeleteSchema?.();\n }\n}\n\nfunction updateSelectedStepId(id: undefined | number) {\n selectedStepId.value = id;\n}\n\nfunction updateSelectedStep(step: Filter) {\n props.onUpdateAnnotation(\n produce(props.annotation, (draft) => {\n const idx = draft.steps.findIndex((s) => s.id === step.id);\n if (idx !== -1) {\n draft.steps[idx] = step;\n }\n }),\n );\n}\n</script>\n\n<template>\n <PlSidebarGroup data-testid=\"pl-annotations\">\n <template #item-0>\n <AnnotationsSidebar\n :annotation=\"props.annotation\"\n :selected-step-id=\"selectedStepId\"\n :on-update-annotation=\"props.onUpdateAnnotation\"\n :on-update-selected-step-id=\"updateSelectedStepId\"\n :class=\"$style.sidebarItem\"\n @delete-schema=\"handleDeleteSchema\"\n />\n </template>\n <template #item-1>\n <FilterSidebar\n v-if=\"selectedStep\"\n :step=\"selectedStep\"\n :on-update-step=\"updateSelectedStep\"\n :class=\"$style.sidebarItem\"\n :columns=\"props.columns\"\n :get-suggest-options=\"props.getSuggestOptions\"\n :hasSelectedColumns=\"props.hasSelectedColumns\"\n :getValuesForSelectedColumns=\"props.getValuesForSelectedColumns\"\n />\n </template>\n </PlSidebarGroup>\n</template>\n\n<style module>\n.sidebarItem {\n width: 100%;\n height: 100%;\n}\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EAoBA,IAAMa,IAAQC,GAERC,IAAiBC,EAA+B,KAAA,CAAS,GAEzDC,IAAeC,QACZC,EAAMJ,EAAe,KAAK,KAAKI,EAAMN,EAAM,UAAU,IACxD,KAAA,IACAA,EAAM,WAAW,MAAM,MAAM,MAASO,EAAK,OAAOL,EAAe,KAAK,CAC3E;EAED,EAAO,WAA4B;GACjC,AAAIA,EAAe,UAAU,KAAA,KAAaF,EAAM,WAAW,MAAM,SAAS,MACxE,EAAe,QAAQA,EAAM,WAAW,MAAM,EAAE,CAAC;EAErD,CAAC;EAED,IAAMQ,IAAqBC,EAAW;GACpC,OAAO;GACP,SAAS;GACT,cAAc;GACd,aAAa;EACf,CAAC;EAED,eAAeC,IAAqB;GAClC,AAAI,MAAMF,EAAmB,MAC3B,EAAe,QAAQ,KAAA,GACvBR,EAAM,iBAAiB;EAE3B;EAEA,SAASW,EAAqB,GAAwB;GACpD,EAAe,QAAQC;EACzB;EAEA,SAASC,EAAmB,GAAc;GACxC,EAAM,mBACJC,EAAQd,EAAM,aAAa,MAAU;IACnC,IAAMe,IAAMC,EAAM,MAAM,WAAW,MAAMC,EAAE,OAAOV,EAAK,EAAE;IACzD,AAAIQ,MAAQ,OACV,EAAM,MAAMA,KAAOR;GAEvB,CAAC,CACH;EACF;E,kBAIEnB,EAAA,GAAAC,EAuBiBC,EAAA+B,CAAA,GAAA,EAvBD,eAAY,iBAAgB,GAAA;GAC/B,UAAM9B,QAQb,CAPFC,EAOEC,GAAA;IANC,YAAYO,EAAM;IAClB,oBAAkBE,EAAA;IAClB,wBAAsBF,EAAM;IAC5B,8BAA4BW;IAC5B,OAAKjB,EAAEP,EAAAA,OAAO,WAAW;IACzB,gBAAeuB;;;;;;;GAGT,UAAMnB,QAUb,CARMa,EAAA,SADRhB,EAAA,GAAAC,EASEM,GAAA;;IAPC,MAAMS,EAAA;IACN,kBAAgBS;IAChB,OAAKnB,EAAEP,EAAAA,OAAO,WAAW;IACzB,SAASa,EAAM;IACf,uBAAqBA,EAAM;IAC3B,oBAAoBA,EAAM;IAC1B,6BAA6BA,EAAM"}
1
+ {"version":3,"file":"PlAnnotations.vue_vue_type_script_setup_true_lang.js","names":["$style","_openBlock","_createBlock","_unref","_withCtx","_createVNode","AnnotationsSidebar","_normalizeClass","FilterSidebar","_createCommentVNode","AnnotationsSidebar_default","FilterSidebar_default","PlAnnotations_vue_vue_type_script_setup_true_lang_default","props","__props","selectedStepId","shallowRef","selectedStep","computed","isNil","step","confirmResetSchema","useConfirm","handleDeleteSchema","updateSelectedStepId","id","updateSelectedStep","produce","idx","draft","s","openBlock","createBlock","unref","PlSidebarGroup","withCtx","createVNode","normalizeClass","_ctx","createCommentVNode"],"sources":["../../../../src/components/PlAnnotations/components/PlAnnotations.vue"],"sourcesContent":["<script lang=\"ts\">\nimport type { Props as BaseProps } from \"./FilterSidebar.vue\";\nexport type Props = Omit<BaseProps, \"step\" | \"onUpdateStep\"> & {\n annotation: Annotation;\n onUpdateAnnotation: (annotation: Annotation) => void;\n onDeleteSchema?: () => void;\n};\n</script>\n\n<script setup lang=\"ts\">\nimport { computed, effect, shallowRef } from \"vue\";\n\nimport { isNil } from \"@milaboratories/helpers\";\nimport { produce } from \"immer\";\nimport { PlSidebarGroup, useConfirm } from \"@milaboratories/uikit\";\n\nimport type { Annotation, Filter } from \"../types\";\nimport AnnotationsSidebar from \"./AnnotationsSidebar.vue\";\nimport FilterSidebar from \"./FilterSidebar.vue\";\n\nconst props = defineProps<Props>();\n\nconst selectedStepId = shallowRef<undefined | number>(undefined);\n\nconst selectedStep = computed(() => {\n return isNil(selectedStepId.value) || isNil(props.annotation)\n ? undefined\n : props.annotation.steps.find((step) => step.id === selectedStepId.value);\n});\n\neffect(function setDefaultStepId() {\n if (selectedStepId.value === undefined && props.annotation.steps.length > 0) {\n selectedStepId.value = props.annotation.steps[0].id;\n }\n});\n\nconst confirmResetSchema = useConfirm({\n title: \"Reset Schema\",\n message: \"Are you sure you want to reset the schema? This action cannot be undone.\",\n confirmLabel: \"Yes, reset\",\n cancelLabel: \"No, cancel\",\n});\n\nasync function handleDeleteSchema() {\n if (await confirmResetSchema()) {\n selectedStepId.value = undefined;\n props.onDeleteSchema?.();\n }\n}\n\nfunction updateSelectedStepId(id: undefined | number) {\n selectedStepId.value = id;\n}\n\nfunction updateSelectedStep(step: Filter) {\n props.onUpdateAnnotation(\n produce(props.annotation, (draft) => {\n const idx = draft.steps.findIndex((s) => s.id === step.id);\n if (idx !== -1) {\n draft.steps[idx] = step;\n }\n }),\n );\n}\n</script>\n\n<template>\n <PlSidebarGroup data-testid=\"pl-annotations\">\n <template #item-0>\n <AnnotationsSidebar\n :annotation=\"props.annotation\"\n :selected-step-id=\"selectedStepId\"\n :on-update-annotation=\"props.onUpdateAnnotation\"\n :on-update-selected-step-id=\"updateSelectedStepId\"\n :class=\"$style.sidebarItem\"\n @delete-schema=\"handleDeleteSchema\"\n />\n </template>\n <template #item-1>\n <FilterSidebar\n v-if=\"selectedStep\"\n :step=\"selectedStep\"\n :on-update-step=\"updateSelectedStep\"\n :class=\"$style.sidebarItem\"\n :columns=\"props.columns\"\n :get-suggest-options=\"props.getSuggestOptions\"\n :hasSelectedColumns=\"props.hasSelectedColumns\"\n :getValuesForSelectedColumns=\"props.getValuesForSelectedColumns\"\n />\n </template>\n </PlSidebarGroup>\n</template>\n\n<style module>\n.sidebarItem {\n width: 100%;\n height: 100%;\n}\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EAoBA,IAAMa,IAAQC,GAERC,IAAiBC,EAA+B,KAAA,CAAS,GAEzDC,IAAeC,QACZC,EAAMJ,EAAe,KAAK,KAAKI,EAAMN,EAAM,UAAU,IACxD,KAAA,IACAA,EAAM,WAAW,MAAM,MAAM,MAASO,EAAK,OAAOL,EAAe,KAAK,CAC3E;EAED,EAAO,WAA4B;GACjC,AAAIA,EAAe,UAAU,KAAA,KAAaF,EAAM,WAAW,MAAM,SAAS,MACxE,EAAe,QAAQA,EAAM,WAAW,MAAM,EAAE,CAAC;EAErD,CAAC;EAED,IAAMQ,IAAqBC,EAAW;GACpC,OAAO;GACP,SAAS;GACT,cAAc;GACd,aAAa;EACf,CAAC;EAED,eAAeC,IAAqB;GAClC,AAAI,MAAMF,EAAmB,MAC3B,EAAe,QAAQ,KAAA,GACvBR,EAAM,iBAAiB;EAE3B;EAEA,SAASW,EAAqB,GAAwB;GACpD,EAAe,QAAQC;EACzB;EAEA,SAASC,EAAmB,GAAc;GACxC,EAAM,mBACJC,EAAQd,EAAM,aAAa,MAAU;IACnC,IAAMe,IAAMC,EAAM,MAAM,WAAW,MAAMC,EAAE,OAAOV,EAAK,EAAE;IACzD,AAAIQ,MAAQ,OACV,EAAM,MAAMA,KAAOR;GAEvB,CAAC,CACH;EACF;E,kBAIEnB,EAA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J,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;0BACrB,OAAO;6BACJ,eAAe,CAAC,IAAI,CAAC;yBACzB,gBAAgB,GAAG,SAAS;;;;;;;;yBAqJe,IAAI;oCAEf,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAK3E;;;;;;WAMG;uBACY,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC;QAMtD;;;;;WAKG;yBACc,IAAI;;;;;EAuJxB;AAED,MAAM,MAAM,SAAS,CACnB,IAAI,GAAG,OAAO,EACd,IAAI,GAAG,OAAO,EACd,OAAO,SAAS,gBAAgB,GAAG,gBAAgB,EACnD,IAAI,SAAS,IAAI,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,EACxC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjE,UAAU,SAAS,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,IAChE,UAAU,CAAC,OAAO,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC"}
@@ -1,133 +1,136 @@
1
1
  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
- import { deepClone as n } from "../lib/util/helpers/dist/objects.js";
3
+ import { deepClone as n, isJsonEqual as r } from "../lib/util/helpers/dist/objects.js";
4
4
  import "../lib/util/helpers/dist/index.js";
5
- import { parseQuery as r } from "../urls.js";
6
- import { MultiError as i, ensureOutputHasStableFlag as a } from "../utils.js";
7
- import { UpdateSerializer as o } from "./UpdateSerializer.js";
8
- import { logDebug as s, logError as c } from "./utils.js";
9
- import { getServices as l } from "./getServices.js";
10
- import { computed as u, markRaw as d, reactive as f, ref as p } from "vue";
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 { applyPatch as b } from "fast-json-patch";
13
- import { watchIgnorable as x } from "@vueuse/core";
14
- var S = (e) => ({
5
+ import { parseQuery as i } from "../urls.js";
6
+ import { MultiError as a, ensureOutputHasStableFlag as o } from "../utils.js";
7
+ import { UpdateSerializer as s } from "./UpdateSerializer.js";
8
+ import { logDebug as c, logError as l } from "./utils.js";
9
+ import { getServices as u } from "./getServices.js";
10
+ import { computed as d, markRaw as f, reactive as p, ref as m } from "vue";
11
+ import { deriveDataFromStorage as h, getPluginData as g, hasAbortError as _, isPluginOutputKey as v, pluginOutputPrefix as y, unwrapResult as b } from "@platforma-sdk/model";
12
+ import { applyPatch as x } from "fast-json-patch";
13
+ import { watchIgnorable as S } from "@vueuse/core";
14
+ var C = (e) => ({
15
15
  authorId: e?.authorId ?? t(),
16
16
  localVersion: (e?.localVersion ?? 0) + 1
17
17
  });
18
- function C(C, w, T) {
19
- let E = T.debug ? s : () => {}, D = c, O = {
18
+ function w(w, T, E) {
19
+ let D = E.debug ? c : () => {}, O = l, k = {
20
20
  isExternalSnapshot: !1,
21
21
  author: {
22
22
  authorId: t(),
23
23
  localVersion: 0
24
24
  }
25
- }, k = () => (O.author = S(O.author), E("nextAuthorMarker", O.author), O.author), A = p(!1), j = p(C.uTag), M = T.debounceSpan ?? 200, N = new o({ debounceSpan: M }), P = /* @__PURE__ */ new Map(), F = (e) => {
26
- let t = P.get(e);
27
- return t || (t = new o({ debounceSpan: M }), P.set(e, t)), t;
28
- }, I = new o({ debounceSpan: M }), L = /* @__PURE__ */ new Map(), R = p(C.value), z = async (e) => w.mutateStorage({
25
+ }, A = () => (k.author = C(k.author), D("nextAuthorMarker", k.author), k.author), j = m(!1), M = m(w.uTag), N = E.debounceSpan ?? 200, P = new s({ debounceSpan: N }), F = /* @__PURE__ */ new Map(), I = (e) => {
26
+ let t = F.get(e);
27
+ return t || (t = new s({ debounceSpan: N }), F.set(e, t)), t;
28
+ }, L = new s({ debounceSpan: N }), R = /* @__PURE__ */ new Map(), z = m(w.value), B = async (e) => T.mutateStorage({
29
29
  operation: "update-block-data",
30
30
  value: e
31
- }, k()), B = async (e, t) => w.mutateStorage({
31
+ }, A()), V = async (e, t) => T.mutateStorage({
32
32
  operation: "update-plugin-data",
33
33
  pluginId: e,
34
34
  value: t
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, a(t)] : [e, t.ok && t.value !== void 0 ? t.value : void 0]);
35
+ }, A()), H = async (e) => T.setNavigationState(e), U = d(() => {
36
+ let e = Object.entries(z.value.outputs).filter(([e]) => !v(e)).map(([e, t]) => T.blockModelInfo.outputs[e]?.withStatus ? [e, o(t)] : [e, t.ok && t.value !== void 0 ? t.value : void 0]);
37
37
  return Object.fromEntries(e);
38
- }), U = u(() => {
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]);
38
+ }), W = d(() => {
39
+ let e = Object.entries(z.value.outputs).filter(([e]) => !v(e)).map(([e, t]) => [e, t && t.ok === !1 ? new a(t.errors) : void 0]);
40
40
  return Object.fromEntries(e);
41
- }), W = f({
41
+ }), G = p({
42
42
  apiVersion: 3,
43
43
  error: "",
44
44
  model: {
45
- data: n(m(R.value.blockStorage)),
46
- outputs: H,
47
- outputErrors: U
45
+ data: n(h(z.value.blockStorage)),
46
+ outputs: U,
47
+ outputErrors: W
48
48
  }
49
- }), { ignoreUpdates: G } = x(() => W.model, (e) => {
49
+ }), { ignoreUpdates: K } = S(() => G.model, (e) => {
50
50
  let t = n(e);
51
- E("setDataQueue appModel.model, data", t.data), N.run(() => z(t.data).then(y));
52
- }, { deep: !0 }), K = (e) => {
53
- E("updateAppModel", e), W.model.data = n(e.data);
51
+ D("setDataQueue appModel.model, data", t.data), P.run(() => B(t.data).then(b));
52
+ }, { deep: !0 }), q = (e) => {
53
+ D("updateAppModel", e), G.model.data = n(e.data);
54
54
  };
55
55
  (async () => {
56
56
  for (window.addEventListener("beforeunload", () => {
57
- A.value = !0, w.dispose().then(y).catch((e) => {
58
- D("platforma error in dispose", e);
57
+ j.value = !0, T.dispose().then(b).catch((e) => {
58
+ O("platforma error in dispose", e);
59
59
  });
60
- }); !A.value;) try {
61
- let e = await w.getPatches(j.value).then(y);
62
- if (E("patches.length", e.value.length), E("uTagRef.value", j.value), E("patches.uTag", e.uTag), E("patches.author", e.author), E("data.author", O.author), j.value = e.uTag, e.value.length === 0) {
60
+ }); !j.value;) try {
61
+ let e = await T.getPatches(M.value).then(b);
62
+ if (D("patches.length", e.value.length), D("uTagRef.value", M.value), D("patches.uTag", e.uTag), D("patches.author", e.author), D("data.author", k.author), M.value = e.uTag, e.value.length === 0) {
63
63
  await new Promise((e) => setTimeout(e, 150));
64
64
  continue;
65
65
  }
66
- let t = O.author?.authorId !== e.author?.authorId;
67
- t || O.isExternalSnapshot ? (E("got external changes, applying them to the snapshot", e.value), G(() => {
68
- R.value = b(R.value, e.value, !1, !1).newDocument, K({ data: m(R.value.blockStorage) });
69
- for (let [e, t] of L) t.ignoreUpdates(() => {
70
- t.model.data = n(h(R.value.blockStorage, e));
71
- });
72
- O.isExternalSnapshot = t;
73
- })) : (E("outputs changed", e.value), G(() => {
74
- R.value = b(R.value, e.value).newDocument;
66
+ let t = k.author?.authorId !== e.author?.authorId;
67
+ t || k.isExternalSnapshot ? (D("got external changes, applying them to the snapshot", e.value), K(() => {
68
+ let i = z.value.blockStorage;
69
+ if (z.value = x(z.value, e.value, !1, !1).newDocument, !r(i, z.value.blockStorage)) {
70
+ q({ data: h(z.value.blockStorage) });
71
+ for (let [e, t] of R) t.ignoreUpdates(() => {
72
+ t.model.data = n(g(z.value.blockStorage, e));
73
+ });
74
+ k.isExternalSnapshot = t;
75
+ }
76
+ })) : (D("outputs changed", e.value), K(() => {
77
+ z.value = x(z.value, e.value).newDocument;
75
78
  })), await new Promise((e) => setTimeout(e, 150));
76
79
  } catch (e) {
77
- g(e) ? (E("patches loop aborted"), A.value = !0) : (D("error in patches loop", e), await new Promise((e) => setTimeout(e, 1e3)));
80
+ _(e) ? (D("patches loop aborted"), j.value = !0) : (O("error in patches loop", e), await new Promise((e) => setTimeout(e, 1e3)));
78
81
  }
79
82
  })();
80
- let q = () => n(W.model.data), J = () => n(R.value.navigationState), Y = {
81
- cloneData: q,
82
- cloneNavigationState: J,
83
+ let J = () => n(G.model.data), Y = () => n(z.value.navigationState), X = {
84
+ cloneData: J,
85
+ cloneNavigationState: Y,
83
86
  updateData(e) {
84
- let t = e(q());
85
- return E("updateData", t), W.model.data = t, N.run(() => z(t).then(y));
87
+ let t = e(J());
88
+ return D("updateData", t), G.model.data = t, P.run(() => B(t).then(b));
86
89
  },
87
90
  navigateTo(e) {
88
- let t = J();
89
- return t.href = e, I.run(() => V(t).then(y));
91
+ let t = Y();
92
+ return t.href = e, L.run(() => H(t).then(b));
90
93
  },
91
94
  async allSettled() {
92
95
  await e(0);
93
- let t = [N.allSettled(), ...Array.from(P.values()).map((e) => e.allSettled())];
96
+ let t = [P.allSettled(), ...Array.from(F.values()).map((e) => e.allSettled())];
94
97
  await Promise.all(t);
95
98
  }
96
- }, X = l({ platforma: w }), Z = (e) => {
97
- let t = v(e), r = u(() => {
99
+ }, Z = u({ platforma: T }), ee = (e) => {
100
+ let t = y(e), r = d(() => {
98
101
  let e = {};
99
- for (let [n, r] of Object.entries(R.value.outputs)) {
102
+ for (let [n, r] of Object.entries(z.value.outputs)) {
100
103
  if (!n.startsWith(t)) continue;
101
104
  let i = n.slice(t.length);
102
- e[i] = w.blockModelInfo.outputs[n]?.withStatus ? r ? a(r) : void 0 : r.ok && r.value !== void 0 ? r.value : void 0;
105
+ e[i] = T.blockModelInfo.outputs[n]?.withStatus ? r ? o(r) : void 0 : r.ok && r.value !== void 0 ? r.value : void 0;
103
106
  }
104
107
  return e;
105
- }), o = u(() => {
108
+ }), i = d(() => {
106
109
  let e = {};
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);
110
+ for (let [n, r] of Object.entries(z.value.outputs)) n.startsWith(t) && (e[n.slice(t.length)] = r && r.ok === !1 ? new a(r.errors) : void 0);
108
111
  return e;
109
- }), s = f({
110
- data: n(h(R.value.blockStorage, e)),
112
+ }), s = p({
113
+ data: n(g(z.value.blockStorage, e)),
111
114
  outputs: r,
112
- outputErrors: o
113
- }), { ignoreUpdates: c } = x(() => s.data, (t) => {
114
- t !== void 0 && (E("plugin setData", e, t), F(e).run(() => B(e, n(t)).then(y)));
115
+ outputErrors: i
116
+ }), { ignoreUpdates: c } = S(() => s.data, (t) => {
117
+ t !== void 0 && (D("plugin setData", e, t), I(e).run(() => V(e, n(t)).then(b)));
115
118
  }, { deep: !0 });
116
119
  return {
117
120
  model: s,
118
- services: d(X),
121
+ services: f(Z),
119
122
  ignoreUpdates: c
120
123
  };
121
124
  }, Q = { getOrCreatePluginState(e) {
122
- let t = L.get(e);
125
+ let t = R.get(e);
123
126
  if (t) return t;
124
- let n = Z(e);
125
- return L.set(e, n), n;
126
- } }, ee = {
127
- closedRef: A,
128
- snapshot: R,
129
- plugins: Object.fromEntries(w.blockModelInfo.pluginIds.map((e) => {
130
- let t = w.blockModelInfo.pluginPublicOutputs?.[e] ?? {}, n = Object.keys(t);
127
+ let n = ee(e);
128
+ return R.set(e, n), n;
129
+ } }, te = {
130
+ closedRef: j,
131
+ snapshot: z,
132
+ plugins: Object.fromEntries(T.blockModelInfo.pluginIds.map((e) => {
133
+ let t = T.blockModelInfo.pluginPublicOutputs?.[e] ?? {}, n = Object.keys(t);
131
134
  if (n.length === 0) return [e, {
132
135
  handle: e,
133
136
  publicOutputs: {}
@@ -135,26 +138,26 @@ function C(C, w, T) {
135
138
  let r = Q.getOrCreatePluginState(e);
136
139
  return [e, {
137
140
  handle: e,
138
- publicOutputs: f(Object.fromEntries(n.map((e) => {
141
+ publicOutputs: p(Object.fromEntries(n.map((e) => {
139
142
  let { getter: n } = t[e];
140
- return [e, u(() => {
143
+ return [e, d(() => {
141
144
  let e = r.model.data;
142
145
  return e == null ? void 0 : n(e);
143
146
  })];
144
147
  })))
145
148
  }];
146
149
  })),
147
- services: d(X),
148
- queryParams: u(() => r(R.value.navigationState.href)),
149
- href: u(() => R.value.navigationState.href),
150
- hasErrors: u(() => Object.values(R.value.outputs).some((e) => !e?.ok))
151
- }, $ = Object.assign(f(Object.assign(W, ee)), Y);
152
- return T.debug && (globalThis.__block_app__ = $), {
150
+ services: f(Z),
151
+ queryParams: d(() => i(z.value.navigationState.href)),
152
+ href: d(() => z.value.navigationState.href),
153
+ hasErrors: d(() => Object.values(z.value.outputs).some((e) => !e?.ok))
154
+ }, $ = Object.assign(p(Object.assign(G, te)), X);
155
+ return E.debug && (globalThis.__block_app__ = $), {
153
156
  app: $,
154
157
  pluginAccess: Q,
155
- columnLinks: u(() => R.value.columnLinks)
158
+ columnLinks: d(() => z.value.columnLinks)
156
159
  };
157
160
  }
158
- export { C as createAppV3, S as createNextAuthorMarker };
161
+ export { w as createAppV3, C as createNextAuthorMarker };
159
162
 
160
163
  //# sourceMappingURL=createAppV3.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createAppV3.js","names":["createNextAuthorMarker","marker","uniqueId","createAppV3","debug","settings","logDebug","error","logError","data","nextAuthorMarker","closedRef","ref","uTagRef","state","debounceSpan","setDataQueue","UpdateSerializer","pluginDataQueues","getPluginDataQueue","queue","handle","setNavigationStateQueue","pluginStates","snapshot","updateData","platforma","updatePluginData","setNavigationState","outputs","computed","entries","k","isPluginOutputKey","outputWithStatus","ensureOutputHasStableFlag","outputErrors","vOrErr","MultiError","appModel","reactive","deepClone","deriveDataFromStorage","watchIgnorable","newData","_newData","unwrapResult","updateAppModel","err","patches","resolve","isAuthorChanged","ignoreUpdates","applyPatch","pluginState","getPluginData","hasAbortError","cloneData","cloneNavigationState","methods","cb","newState","href","delay","allQueues","q","services","getServices","createPluginState","prefix","pluginOutputPrefix","pluginOutputs","result","key","outputKey","pluginOutputErrors","pluginModel","markRaw","pluginAccess","existing","getters","rawDef","id","keys","getter","parseQuery","v","app"],"sources":["../../src/internal/createAppV3.ts"],"sourcesContent":["import { deepClone, delay, uniqueId } from \"@milaboratories/helpers\";\nimport type { Mutable } from \"@milaboratories/helpers\";\nimport type {\n NavigationState,\n BlockColumnLinks,\n BlockOutputsBase,\n BlockStateV3,\n PlatformaV3,\n ValueWithUTag,\n AuthorMarker,\n PlatformaExtended,\n InferPluginUiEntries,\n PluginHandle,\n InferFactoryData,\n InferFactoryOutputs,\n PluginFactoryLike,\n UiServices as AllUiServices,\n InferFactoryUiServices,\n} from \"@platforma-sdk/model\";\nimport {\n hasAbortError,\n unwrapResult,\n deriveDataFromStorage,\n getPluginData,\n isPluginOutputKey,\n pluginOutputPrefix,\n} from \"@platforma-sdk/model\";\nimport type { Ref } from \"vue\";\nimport { reactive, computed, ref, markRaw } from \"vue\";\nimport type { OutputValues, OutputErrors, AppSettings } from \"../types\";\nimport { parseQuery } from \"../urls\";\nimport { ensureOutputHasStableFlag, MultiError } from \"../utils\";\nimport { applyPatch } from \"fast-json-patch\";\nimport { UpdateSerializer } from \"./UpdateSerializer\";\nimport { watchIgnorable } from \"@vueuse/core\";\nimport type { PluginState, PluginAccess } from \"../composition/usePlugin\";\nimport { logDebug, logError } from \"./utils\";\nimport { getServices } from \"./getServices\";\n\nexport const patchPoolingDelay = 150;\n\n/** Internal per-plugin state with reconciliation support. */\ninterface InternalPluginState<\n Data = unknown,\n Outputs = unknown,\n Services = Record<string, unknown>,\n> extends PluginState<Data, Outputs, Services> {\n readonly ignoreUpdates: (fn: () => void) => void;\n}\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 Data - The type of the block data.\n * @template Href - The type of navigation href, defaulting to a string starting with `/`.\n *\n * @param state - Initial state of the application, including args, outputs, UI state, and navigation state.\n * @param platforma - A platform interface for interacting with block states.\n * @param settings - Application settings, such as debug flags.\n *\n * @returns A reactive application object with methods, getters, and state.\n */\nexport function createAppV3<\n Data = unknown,\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n Href extends `/${string}` = `/${string}`,\n Plugins extends Record<string, unknown> = Record<string, unknown>,\n UiServices extends Partial<AllUiServices> = Partial<AllUiServices>,\n>(\n state: ValueWithUTag<BlockStateV3<Data, Outputs, Href>>,\n platforma: PlatformaExtended<PlatformaV3<Data, Args, Outputs, Href, Plugins, UiServices>>,\n settings: AppSettings,\n) {\n const debug = settings.debug ? logDebug : () => {};\n const error = logError;\n\n const data = {\n isExternalSnapshot: false,\n author: {\n authorId: uniqueId(),\n localVersion: 0,\n },\n };\n\n const nextAuthorMarker = () => {\n data.author = createNextAuthorMarker(data.author);\n debug(\"nextAuthorMarker\", data.author);\n return data.author;\n };\n\n const closedRef = ref(false);\n\n const uTagRef = ref(state.uTag);\n\n const debounceSpan = settings.debounceSpan ?? 200;\n\n const setDataQueue = new UpdateSerializer({ debounceSpan });\n const pluginDataQueues = new Map<PluginHandle, UpdateSerializer>();\n const getPluginDataQueue = (handle: PluginHandle): UpdateSerializer => {\n let queue = pluginDataQueues.get(handle);\n if (!queue) {\n queue = new UpdateSerializer({ debounceSpan });\n pluginDataQueues.set(handle, queue);\n }\n return queue;\n };\n const setNavigationStateQueue = new UpdateSerializer({ debounceSpan });\n\n /** Lazily-created per-plugin reactive states. */\n const pluginStates = new Map<PluginHandle, InternalPluginState>();\n /**\n * Reactive snapshot of the application state, including args, outputs, UI state, and navigation state.\n */\n const snapshot = ref<{\n outputs: Partial<Readonly<Outputs>>;\n blockStorage: unknown;\n navigationState: NavigationState<Href>;\n columnLinks: BlockColumnLinks | undefined;\n }>(state.value) as Ref<{\n outputs: Partial<Readonly<Outputs>>;\n blockStorage: unknown;\n navigationState: NavigationState<Href>;\n columnLinks: BlockColumnLinks | undefined;\n }>;\n\n const updateData = async (value: Data) => {\n return platforma.mutateStorage({ operation: \"update-block-data\", value }, nextAuthorMarker());\n };\n\n const updatePluginData = async (handle: PluginHandle, value: unknown) => {\n return platforma.mutateStorage(\n { operation: \"update-plugin-data\", pluginId: handle, value },\n nextAuthorMarker(),\n );\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>>)\n .filter(([k]) => !isPluginOutputKey(k))\n .map(([k, outputWithStatus]) =>\n platforma.blockModelInfo.outputs[k]?.withStatus\n ? [k, ensureOutputHasStableFlag(outputWithStatus)]\n : [\n k,\n outputWithStatus.ok && outputWithStatus.value !== undefined\n ? outputWithStatus.value\n : undefined,\n ],\n );\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>>)\n .filter(([k]) => !isPluginOutputKey(k))\n .map(([k, vOrErr]) => [\n k,\n vOrErr && vOrErr.ok === false ? new MultiError(vOrErr.errors) : undefined,\n ]);\n return Object.fromEntries(entries);\n });\n\n const appModel = reactive({\n apiVersion: 3,\n error: \"\",\n model: {\n data: deepClone(deriveDataFromStorage<Data>(snapshot.value.blockStorage)) as Data,\n outputs,\n outputErrors,\n },\n }) as {\n error: string;\n model: {\n data: Data;\n outputs: OutputValues<Outputs>;\n outputErrors: OutputErrors<Outputs>;\n };\n };\n\n const { ignoreUpdates } = watchIgnorable(\n () => appModel.model,\n (_newData) => {\n const newData = deepClone(_newData);\n debug(\"setDataQueue appModel.model, data\", newData.data);\n setDataQueue.run(() => updateData(newData.data).then(unwrapResult));\n },\n { deep: true },\n );\n\n const updateAppModel = (newData: { data: Data }) => {\n debug(\"updateAppModel\", newData);\n appModel.model.data = deepClone(newData.data) as Data;\n };\n\n (async () => {\n window.addEventListener(\"beforeunload\", () => {\n closedRef.value = true;\n platforma\n .dispose()\n .then(unwrapResult)\n .catch((err) => {\n error(\"platforma error in dispose\", err);\n });\n });\n\n while (!closedRef.value) {\n try {\n const patches = await platforma.getPatches(uTagRef.value).then(unwrapResult);\n\n debug(\"patches.length\", patches.value.length);\n debug(\"uTagRef.value\", uTagRef.value);\n debug(\"patches.uTag\", patches.uTag);\n debug(\"patches.author\", patches.author);\n debug(\"data.author\", data.author);\n\n uTagRef.value = patches.uTag;\n\n if (patches.value.length === 0) {\n await new Promise((resolve) => setTimeout(resolve, patchPoolingDelay));\n continue;\n }\n\n const isAuthorChanged = data.author?.authorId !== patches.author?.authorId;\n\n // Immutable behavior, apply external changes to the snapshot\n if (isAuthorChanged || data.isExternalSnapshot) {\n debug(\"got external changes, applying them to the snapshot\", patches.value);\n ignoreUpdates(() => {\n snapshot.value = applyPatch(snapshot.value, patches.value, false, false).newDocument;\n updateAppModel({ data: deriveDataFromStorage<Data>(snapshot.value.blockStorage) });\n // Reconcile plugin data from external source\n for (const [handle, pluginState] of pluginStates) {\n pluginState.ignoreUpdates(() => {\n pluginState.model.data = deepClone(\n getPluginData(snapshot.value.blockStorage, handle),\n );\n });\n }\n data.isExternalSnapshot = isAuthorChanged;\n });\n } else {\n // Mutable behavior\n debug(\"outputs changed\", patches.value);\n ignoreUpdates(() => {\n snapshot.value = applyPatch(snapshot.value, patches.value).newDocument;\n });\n }\n\n await new Promise((resolve) => setTimeout(resolve, patchPoolingDelay));\n } catch (err) {\n if (hasAbortError(err)) {\n debug(\"patches loop aborted\");\n closedRef.value = true;\n } else {\n error(\"error in patches loop\", err);\n await new Promise((resolve) => setTimeout(resolve, 1000));\n }\n }\n }\n })();\n\n const cloneData = () => deepClone(appModel.model.data) as Data;\n const cloneNavigationState = () =>\n deepClone(snapshot.value.navigationState) as Mutable<NavigationState<Href>>;\n\n const methods = {\n cloneData,\n cloneNavigationState,\n /**\n * Updates the UI state by applying a callback.\n *\n * @param cb - Callback to modify the current UI state.\n * @returns A promise resolving after the update is applied.\n * @todo Make it mutable since there is already an initial one\n */\n updateData(cb: (data: Data) => Data): Promise<boolean> {\n const newData = cb(cloneData());\n debug(\"updateData\", newData);\n appModel.model.data = newData;\n return setDataQueue.run(() => updateData(newData).then(unwrapResult));\n },\n /**\n * Navigates to a specific href by updating the navigation state.\n *\n * @param href - The target href to navigate to.\n * @returns A promise resolving after the navigation state is updated.\n */\n navigateTo(href: Href) {\n const newState = cloneNavigationState();\n newState.href = href;\n return setNavigationStateQueue.run(() => setNavigationState(newState).then(unwrapResult));\n },\n async allSettled() {\n await delay(0);\n const allQueues = [\n setDataQueue.allSettled(),\n ...Array.from(pluginDataQueues.values()).map((q) => q.allSettled()),\n ];\n await Promise.all(allQueues);\n },\n };\n\n const services = getServices<UiServices>({ platforma });\n\n /** Creates a lazily-cached per-plugin reactive state. */\n const createPluginState = <F extends PluginFactoryLike>(\n handle: PluginHandle<F>,\n ): InternalPluginState<InferFactoryData<F>, InferFactoryOutputs<F>> => {\n const prefix = pluginOutputPrefix(handle);\n\n const pluginOutputs = computed(() => {\n const result: Record<string, unknown> = {};\n for (const [key, outputWithStatus] of Object.entries(\n snapshot.value.outputs as Partial<Readonly<Outputs>>,\n )) {\n if (!key.startsWith(prefix)) continue;\n const outputKey = key.slice(prefix.length);\n if (platforma.blockModelInfo.outputs[key]?.withStatus) {\n result[outputKey] = outputWithStatus\n ? ensureOutputHasStableFlag(outputWithStatus)\n : undefined;\n } else {\n result[outputKey] =\n outputWithStatus.ok && outputWithStatus.value !== undefined\n ? outputWithStatus.value\n : undefined;\n }\n }\n return result;\n });\n\n const pluginOutputErrors = computed(() => {\n const result: Record<string, Error | undefined> = {};\n for (const [key, vOrErr] of Object.entries(\n snapshot.value.outputs as Partial<Readonly<Outputs>>,\n )) {\n if (!key.startsWith(prefix)) continue;\n result[key.slice(prefix.length)] =\n vOrErr && vOrErr.ok === false ? new MultiError(vOrErr.errors) : undefined;\n }\n return result;\n });\n\n const pluginModel = reactive({\n data: deepClone(getPluginData(snapshot.value.blockStorage, handle)),\n outputs: pluginOutputs,\n outputErrors: pluginOutputErrors,\n }) as InternalPluginState<InferFactoryData<F>, InferFactoryOutputs<F>>[\"model\"];\n\n const { ignoreUpdates } = watchIgnorable(\n () => pluginModel.data,\n (newData) => {\n if (newData === undefined) return;\n debug(\"plugin setData\", handle, newData);\n getPluginDataQueue(handle).run(() =>\n updatePluginData(handle, deepClone(newData)).then(unwrapResult),\n );\n },\n { deep: true },\n );\n\n return {\n model: pluginModel,\n services: markRaw(services),\n ignoreUpdates,\n };\n };\n\n /** Plugin internals — provided via separate injection key, not exposed on useApp(). */\n const pluginAccess: PluginAccess = {\n getOrCreatePluginState<F extends PluginFactoryLike>(handle: PluginHandle<F>) {\n const existing = pluginStates.get(handle);\n if (existing) {\n return existing as unknown as PluginState<\n InferFactoryData<F>,\n InferFactoryOutputs<F>,\n InferFactoryUiServices<F>\n >;\n }\n const state = createPluginState(handle);\n pluginStates.set(handle, state);\n return state as unknown as PluginState<\n InferFactoryData<F>,\n InferFactoryOutputs<F>,\n InferFactoryUiServices<F>\n >;\n },\n };\n\n const plugins = Object.fromEntries(\n platforma.blockModelInfo.pluginIds.map((id) => {\n const rawDef = platforma.blockModelInfo.pluginPublicOutputs?.[id] ?? {};\n const keys = Object.keys(rawDef);\n if (keys.length === 0) {\n return [id, { handle: id, publicOutputs: {} }];\n }\n const state = pluginAccess.getOrCreatePluginState(id);\n // reactive() ensures publicOutputs is its own proxy, so access via toRaw(app) still unwraps correctly.\n const publicOutputs = reactive(\n Object.fromEntries(\n keys.map((key) => {\n const { getter } = rawDef[key];\n return [\n key,\n computed(() => {\n const data = state.model.data;\n return data != null ? getter(data) : undefined;\n }),\n ];\n }),\n ),\n );\n return [id, { handle: id, publicOutputs }];\n }),\n ) as InferPluginUiEntries<Plugins>;\n\n const getters = {\n closedRef,\n snapshot,\n plugins,\n services: markRaw(services),\n queryParams: computed(() => parseQuery<Href>(snapshot.value.navigationState.href as Href)),\n href: computed(() => snapshot.value.navigationState.href),\n hasErrors: computed(() =>\n Object.values(snapshot.value.outputs as Partial<Readonly<Outputs>>).some((v) => !v?.ok),\n ),\n };\n\n const app = Object.assign(reactive(Object.assign(appModel, getters)), methods);\n\n if (settings.debug) {\n // @ts-expect-error (to inspect in console in debug mode)\n globalThis.__block_app__ = app;\n }\n\n const columnLinks = computed(() => snapshot.value.columnLinks);\n\n return { app, pluginAccess, columnLinks };\n}\n\nexport type BaseAppV3<\n Data = unknown,\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n Href extends `/${string}` = `/${string}`,\n Plugins extends Record<string, unknown> = Record<string, unknown>,\n UiServices extends Partial<AllUiServices> = Partial<AllUiServices>,\n> = ReturnType<typeof createAppV3<Data, Args, Outputs, Href, Plugins, UiServices>>[\"app\"];\n"],"mappings":";;;;;;;;;;;;;AAkDA,IAAaA,KAA0B,OAAoD;CACzF,UAAUC,GAAQ,YAAYC,EAAS;CACvC,eAAeD,GAAQ,gBAAgB,KAAK;AAC9C;AAgBA,SAAgBE,EAQd,GACA,GACA,GACA;CACA,IAAMC,IAAQC,EAAS,QAAQC,UAAiB,CAAC,GAC3CC,IAAQC,GAERC,IAAO;EACX,oBAAoB;EACpB,QAAQ;GACN,UAAUP,EAAS;GACnB,cAAc;EAChB;CACF,GAEMQ,WACJ,EAAK,SAASV,EAAuBS,EAAK,MAAM,GAChDL,EAAM,oBAAoBK,EAAK,MAAM,GAC9BA,EAAK,SAGRE,IAAYC,EAAI,EAAK,GAErBC,IAAUD,EAAIE,EAAM,IAAI,GAExBC,I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;EACzF,MAAMM,QAAeN,EAAS,MAAM,gBAAgB,IAAI;EACxD,WAAWM,QACT,OAAO,OAAON,EAAS,MAAM,OAAqC,CAAC,CAAC,MAAM,MAAM,CAAC8D,GAAG,EAAE,CACxF;CACF,GAEMC,IAAM,OAAO,OAAO/C,EAAS,OAAO,OAAOD,GAAUyC,EAAO,CAAC,GAAGrB,CAAO;CAS7E,OAPItD,EAAS,UAEX,WAAW,gBAAgBkF,IAKtB;EAAE;EAAK;EAAc,aAFRzD,QAAeN,EAAS,MAAM,WAEtB;CAAY;AAC1C"}
1
+ {"version":3,"file":"createAppV3.js","names":["createNextAuthorMarker","marker","uniqueId","createAppV3","debug","settings","logDebug","error","logError","data","nextAuthorMarker","closedRef","ref","uTagRef","state","debounceSpan","setDataQueue","UpdateSerializer","pluginDataQueues","getPluginDataQueue","queue","handle","setNavigationStateQueue","pluginStates","snapshot","updateData","platforma","updatePluginData","setNavigationState","outputs","computed","entries","k","isPluginOutputKey","outputWithStatus","ensureOutputHasStableFlag","outputErrors","vOrErr","MultiError","appModel","reactive","deepClone","deriveDataFromStorage","watchIgnorable","newData","_newData","unwrapResult","updateAppModel","err","patches","resolve","isAuthorChanged","ignoreUpdates","storageBefore","applyPatch","pluginState","getPluginData","hasAbortError","cloneData","cloneNavigationState","methods","cb","newState","href","delay","allQueues","q","services","getServices","createPluginState","prefix","pluginOutputPrefix","pluginOutputs","result","key","outputKey","pluginOutputErrors","pluginModel","markRaw","pluginAccess","existing","getters","rawDef","id","keys","getter","parseQuery","v","app"],"sources":["../../src/internal/createAppV3.ts"],"sourcesContent":["import { deepClone, delay, isJsonEqual, uniqueId } from \"@milaboratories/helpers\";\nimport type { Mutable } from \"@milaboratories/helpers\";\nimport type {\n NavigationState,\n BlockColumnLinks,\n BlockOutputsBase,\n BlockStateV3,\n PlatformaV3,\n ValueWithUTag,\n AuthorMarker,\n PlatformaExtended,\n InferPluginUiEntries,\n PluginHandle,\n InferFactoryData,\n InferFactoryOutputs,\n PluginFactoryLike,\n UiServices as AllUiServices,\n InferFactoryUiServices,\n} from \"@platforma-sdk/model\";\nimport {\n hasAbortError,\n unwrapResult,\n deriveDataFromStorage,\n getPluginData,\n isPluginOutputKey,\n pluginOutputPrefix,\n} from \"@platforma-sdk/model\";\nimport type { Ref } from \"vue\";\nimport { reactive, computed, ref, markRaw } from \"vue\";\nimport type { OutputValues, OutputErrors, AppSettings } from \"../types\";\nimport { parseQuery } from \"../urls\";\nimport { ensureOutputHasStableFlag, MultiError } from \"../utils\";\nimport { applyPatch } from \"fast-json-patch\";\nimport { UpdateSerializer } from \"./UpdateSerializer\";\nimport { watchIgnorable } from \"@vueuse/core\";\nimport type { PluginState, PluginAccess } from \"../composition/usePlugin\";\nimport { logDebug, logError } from \"./utils\";\nimport { getServices } from \"./getServices\";\n\nexport const patchPoolingDelay = 150;\n\n/** Internal per-plugin state with reconciliation support. */\ninterface InternalPluginState<\n Data = unknown,\n Outputs = unknown,\n Services = Record<string, unknown>,\n> extends PluginState<Data, Outputs, Services> {\n readonly ignoreUpdates: (fn: () => void) => void;\n}\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 Data - The type of the block data.\n * @template Href - The type of navigation href, defaulting to a string starting with `/`.\n *\n * @param state - Initial state of the application, including args, outputs, UI state, and navigation state.\n * @param platforma - A platform interface for interacting with block states.\n * @param settings - Application settings, such as debug flags.\n *\n * @returns A reactive application object with methods, getters, and state.\n */\nexport function createAppV3<\n Data = unknown,\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n Href extends `/${string}` = `/${string}`,\n Plugins extends Record<string, unknown> = Record<string, unknown>,\n UiServices extends Partial<AllUiServices> = Partial<AllUiServices>,\n>(\n state: ValueWithUTag<BlockStateV3<Data, Outputs, Href>>,\n platforma: PlatformaExtended<PlatformaV3<Data, Args, Outputs, Href, Plugins, UiServices>>,\n settings: AppSettings,\n) {\n const debug = settings.debug ? logDebug : () => {};\n const error = logError;\n\n const data = {\n isExternalSnapshot: false,\n author: {\n authorId: uniqueId(),\n localVersion: 0,\n },\n };\n\n const nextAuthorMarker = () => {\n data.author = createNextAuthorMarker(data.author);\n debug(\"nextAuthorMarker\", data.author);\n return data.author;\n };\n\n const closedRef = ref(false);\n\n const uTagRef = ref(state.uTag);\n\n const debounceSpan = settings.debounceSpan ?? 200;\n\n const setDataQueue = new UpdateSerializer({ debounceSpan });\n const pluginDataQueues = new Map<PluginHandle, UpdateSerializer>();\n const getPluginDataQueue = (handle: PluginHandle): UpdateSerializer => {\n let queue = pluginDataQueues.get(handle);\n if (!queue) {\n queue = new UpdateSerializer({ debounceSpan });\n pluginDataQueues.set(handle, queue);\n }\n return queue;\n };\n const setNavigationStateQueue = new UpdateSerializer({ debounceSpan });\n\n /** Lazily-created per-plugin reactive states. */\n const pluginStates = new Map<PluginHandle, InternalPluginState>();\n /**\n * Reactive snapshot of the application state, including args, outputs, UI state, and navigation state.\n */\n const snapshot = ref<{\n outputs: Partial<Readonly<Outputs>>;\n blockStorage: unknown;\n navigationState: NavigationState<Href>;\n columnLinks: BlockColumnLinks | undefined;\n }>(state.value) as Ref<{\n outputs: Partial<Readonly<Outputs>>;\n blockStorage: unknown;\n navigationState: NavigationState<Href>;\n columnLinks: BlockColumnLinks | undefined;\n }>;\n\n const updateData = async (value: Data) => {\n return platforma.mutateStorage({ operation: \"update-block-data\", value }, nextAuthorMarker());\n };\n\n const updatePluginData = async (handle: PluginHandle, value: unknown) => {\n return platforma.mutateStorage(\n { operation: \"update-plugin-data\", pluginId: handle, value },\n nextAuthorMarker(),\n );\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>>)\n .filter(([k]) => !isPluginOutputKey(k))\n .map(([k, outputWithStatus]) =>\n platforma.blockModelInfo.outputs[k]?.withStatus\n ? [k, ensureOutputHasStableFlag(outputWithStatus)]\n : [\n k,\n outputWithStatus.ok && outputWithStatus.value !== undefined\n ? outputWithStatus.value\n : undefined,\n ],\n );\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>>)\n .filter(([k]) => !isPluginOutputKey(k))\n .map(([k, vOrErr]) => [\n k,\n vOrErr && vOrErr.ok === false ? new MultiError(vOrErr.errors) : undefined,\n ]);\n return Object.fromEntries(entries);\n });\n\n const appModel = reactive({\n apiVersion: 3,\n error: \"\",\n model: {\n data: deepClone(deriveDataFromStorage<Data>(snapshot.value.blockStorage)) as Data,\n outputs,\n outputErrors,\n },\n }) as {\n error: string;\n model: {\n data: Data;\n outputs: OutputValues<Outputs>;\n outputErrors: OutputErrors<Outputs>;\n };\n };\n\n const { ignoreUpdates } = watchIgnorable(\n () => appModel.model,\n (_newData) => {\n const newData = deepClone(_newData);\n debug(\"setDataQueue appModel.model, data\", newData.data);\n setDataQueue.run(() => updateData(newData.data).then(unwrapResult));\n },\n { deep: true },\n );\n\n const updateAppModel = (newData: { data: Data }) => {\n debug(\"updateAppModel\", newData);\n appModel.model.data = deepClone(newData.data) as Data;\n };\n\n (async () => {\n window.addEventListener(\"beforeunload\", () => {\n closedRef.value = true;\n platforma\n .dispose()\n .then(unwrapResult)\n .catch((err) => {\n error(\"platforma error in dispose\", err);\n });\n });\n\n while (!closedRef.value) {\n try {\n const patches = await platforma.getPatches(uTagRef.value).then(unwrapResult);\n\n debug(\"patches.length\", patches.value.length);\n debug(\"uTagRef.value\", uTagRef.value);\n debug(\"patches.uTag\", patches.uTag);\n debug(\"patches.author\", patches.author);\n debug(\"data.author\", data.author);\n\n uTagRef.value = patches.uTag;\n\n if (patches.value.length === 0) {\n await new Promise((resolve) => setTimeout(resolve, patchPoolingDelay));\n continue;\n }\n\n const isAuthorChanged = data.author?.authorId !== patches.author?.authorId;\n\n // Immutable behavior, apply external changes to the snapshot\n if (isAuthorChanged || data.isExternalSnapshot) {\n debug(\"got external changes, applying them to the snapshot\", patches.value);\n ignoreUpdates(() => {\n const storageBefore = snapshot.value.blockStorage;\n snapshot.value = applyPatch(snapshot.value, patches.value, false, false).newDocument;\n // The author is the author of the stored data, not of this update. Until the first\n // save of this window lands, every update carries the previous author, also one that\n // changes the outputs or the section only. Such an update holds no data to take: the\n // window's data may already be ahead of it, with a save queued or on its way.\n if (isJsonEqual(storageBefore, snapshot.value.blockStorage)) return;\n updateAppModel({ data: deriveDataFromStorage<Data>(snapshot.value.blockStorage) });\n // Reconcile plugin data from external source\n for (const [handle, pluginState] of pluginStates) {\n pluginState.ignoreUpdates(() => {\n pluginState.model.data = deepClone(\n getPluginData(snapshot.value.blockStorage, handle),\n );\n });\n }\n data.isExternalSnapshot = isAuthorChanged;\n });\n } else {\n // Mutable behavior\n debug(\"outputs changed\", patches.value);\n ignoreUpdates(() => {\n snapshot.value = applyPatch(snapshot.value, patches.value).newDocument;\n });\n }\n\n await new Promise((resolve) => setTimeout(resolve, patchPoolingDelay));\n } catch (err) {\n if (hasAbortError(err)) {\n debug(\"patches loop aborted\");\n closedRef.value = true;\n } else {\n error(\"error in patches loop\", err);\n await new Promise((resolve) => setTimeout(resolve, 1000));\n }\n }\n }\n })();\n\n const cloneData = () => deepClone(appModel.model.data) as Data;\n const cloneNavigationState = () =>\n deepClone(snapshot.value.navigationState) as Mutable<NavigationState<Href>>;\n\n const methods = {\n cloneData,\n cloneNavigationState,\n /**\n * Updates the UI state by applying a callback.\n *\n * @param cb - Callback to modify the current UI state.\n * @returns A promise resolving after the update is applied.\n * @todo Make it mutable since there is already an initial one\n */\n updateData(cb: (data: Data) => Data): Promise<boolean> {\n const newData = cb(cloneData());\n debug(\"updateData\", newData);\n appModel.model.data = newData;\n return setDataQueue.run(() => updateData(newData).then(unwrapResult));\n },\n /**\n * Navigates to a specific href by updating the navigation state.\n *\n * @param href - The target href to navigate to.\n * @returns A promise resolving after the navigation state is updated.\n */\n navigateTo(href: Href) {\n const newState = cloneNavigationState();\n newState.href = href;\n return setNavigationStateQueue.run(() => setNavigationState(newState).then(unwrapResult));\n },\n async allSettled() {\n await delay(0);\n const allQueues = [\n setDataQueue.allSettled(),\n ...Array.from(pluginDataQueues.values()).map((q) => q.allSettled()),\n ];\n await Promise.all(allQueues);\n },\n };\n\n const services = getServices<UiServices>({ platforma });\n\n /** Creates a lazily-cached per-plugin reactive state. */\n const createPluginState = <F extends PluginFactoryLike>(\n handle: PluginHandle<F>,\n ): InternalPluginState<InferFactoryData<F>, InferFactoryOutputs<F>> => {\n const prefix = pluginOutputPrefix(handle);\n\n const pluginOutputs = computed(() => {\n const result: Record<string, unknown> = {};\n for (const [key, outputWithStatus] of Object.entries(\n snapshot.value.outputs as Partial<Readonly<Outputs>>,\n )) {\n if (!key.startsWith(prefix)) continue;\n const outputKey = key.slice(prefix.length);\n if (platforma.blockModelInfo.outputs[key]?.withStatus) {\n result[outputKey] = outputWithStatus\n ? ensureOutputHasStableFlag(outputWithStatus)\n : undefined;\n } else {\n result[outputKey] =\n outputWithStatus.ok && outputWithStatus.value !== undefined\n ? outputWithStatus.value\n : undefined;\n }\n }\n return result;\n });\n\n const pluginOutputErrors = computed(() => {\n const result: Record<string, Error | undefined> = {};\n for (const [key, vOrErr] of Object.entries(\n snapshot.value.outputs as Partial<Readonly<Outputs>>,\n )) {\n if (!key.startsWith(prefix)) continue;\n result[key.slice(prefix.length)] =\n vOrErr && vOrErr.ok === false ? new MultiError(vOrErr.errors) : undefined;\n }\n return result;\n });\n\n const pluginModel = reactive({\n data: deepClone(getPluginData(snapshot.value.blockStorage, handle)),\n outputs: pluginOutputs,\n outputErrors: pluginOutputErrors,\n }) as InternalPluginState<InferFactoryData<F>, InferFactoryOutputs<F>>[\"model\"];\n\n const { ignoreUpdates } = watchIgnorable(\n () => pluginModel.data,\n (newData) => {\n if (newData === undefined) return;\n debug(\"plugin setData\", handle, newData);\n getPluginDataQueue(handle).run(() =>\n updatePluginData(handle, deepClone(newData)).then(unwrapResult),\n );\n },\n { deep: true },\n );\n\n return {\n model: pluginModel,\n services: markRaw(services),\n ignoreUpdates,\n };\n };\n\n /** Plugin internals — provided via separate injection key, not exposed on useApp(). */\n const pluginAccess: PluginAccess = {\n getOrCreatePluginState<F extends PluginFactoryLike>(handle: PluginHandle<F>) {\n const existing = pluginStates.get(handle);\n if (existing) {\n return existing as unknown as PluginState<\n InferFactoryData<F>,\n InferFactoryOutputs<F>,\n InferFactoryUiServices<F>\n >;\n }\n const state = createPluginState(handle);\n pluginStates.set(handle, state);\n return state as unknown as PluginState<\n InferFactoryData<F>,\n InferFactoryOutputs<F>,\n InferFactoryUiServices<F>\n >;\n },\n };\n\n const plugins = Object.fromEntries(\n platforma.blockModelInfo.pluginIds.map((id) => {\n const rawDef = platforma.blockModelInfo.pluginPublicOutputs?.[id] ?? {};\n const keys = Object.keys(rawDef);\n if (keys.length === 0) {\n return [id, { handle: id, publicOutputs: {} }];\n }\n const state = pluginAccess.getOrCreatePluginState(id);\n // reactive() ensures publicOutputs is its own proxy, so access via toRaw(app) still unwraps correctly.\n const publicOutputs = reactive(\n Object.fromEntries(\n keys.map((key) => {\n const { getter } = rawDef[key];\n return [\n key,\n computed(() => {\n const data = state.model.data;\n return data != null ? getter(data) : undefined;\n }),\n ];\n }),\n ),\n );\n return [id, { handle: id, publicOutputs }];\n }),\n ) as InferPluginUiEntries<Plugins>;\n\n const getters = {\n closedRef,\n snapshot,\n plugins,\n services: markRaw(services),\n queryParams: computed(() => parseQuery<Href>(snapshot.value.navigationState.href as Href)),\n href: computed(() => snapshot.value.navigationState.href),\n hasErrors: computed(() =>\n Object.values(snapshot.value.outputs as Partial<Readonly<Outputs>>).some((v) => !v?.ok),\n ),\n };\n\n const app = Object.assign(reactive(Object.assign(appModel, getters)), methods);\n\n if (settings.debug) {\n // @ts-expect-error (to inspect in console in debug mode)\n globalThis.__block_app__ = app;\n }\n\n const columnLinks = computed(() => snapshot.value.columnLinks);\n\n return { app, pluginAccess, columnLinks };\n}\n\nexport type BaseAppV3<\n Data = unknown,\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n Href extends `/${string}` = `/${string}`,\n Plugins extends Record<string, unknown> = Record<string, unknown>,\n UiServices extends Partial<AllUiServices> = Partial<AllUiServices>,\n> = ReturnType<typeof createAppV3<Data, Args, Outputs, Href, Plugins, UiServices>>[\"app\"];\n"],"mappings":";;;;;;;;;;;;;AAkDA,IAAaA,KAA0B,OAAoD;CACzF,UAAUC,GAAQ,YAAYC,EAAS;CACvC,eAAeD,GAAQ,gBAAgB,KAAK;AAC9C;AAgBA,SAAgBE,EAQd,GACA,GACA,GACA;CACA,IAAMC,IAAQC,EAAS,QAAQC,UAAiB,CAAC,GAC3CC,IAAQC,GAERC,IAAO;EACX,oBAAoB;EACpB,QAAQ;GACN,UAAUP,EAAS;GACnB,cAAc;EAChB;CACF,GAEMQ,WACJ,EAAK,SAASV,EAAuBS,EAAK,MAAM,GAChDL,EAAM,oBAAoBK,EAAK,MAAM,GAC9BA,EAAK,SAGRE,IAAYC,EAAI,EAAK,GAErBC,IAAUD,EAAIE,EAAM,IAAI,GAExBC,IAAeV,EAAS,gBAAgB,KAExCW,IAAe,IAAIC,EAAiB,EAAE,gBAAa,CAAC,GACpDC,oBAAmB,IAAI,IAAoC,GAC3DC,KAAsB,MAA2C;EACrE,IAAIC,IAAQF,EAAiB,IAAIG,CAAM;EAKvC,OAJKD,MACH,IAAQ,IAAIH,EAAiB,EAAE,gBAAa,CAAC,GAC7CC,EAAiB,IAAIG,GAAQD,CAAK,IAE7BA;CACT,GACME,IAA0B,IAAIL,EAAiB,EAAE,gBAAa,CAAC,GAG/DM,oBAAe,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IvD,EAAS,UAEX,WAAW,gBAAgBmF,IAKtB;EAAE;EAAK;EAAc,aAFR1D,QAAeN,EAAS,MAAM,WAEtB;CAAY;AAC1C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/ui-vue",
3
- "version": "1.90.0",
3
+ "version": "1.90.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -14,8 +14,8 @@
14
14
  "@milaboratories/columns-collection-driver": "0.3.0",
15
15
  "@milaboratories/pf-spec-driver": "1.6.0",
16
16
  "@milaboratories/pl-model-common": "1.56.0",
17
- "@milaboratories/uikit": "2.17.9",
18
- "@platforma-sdk/model": "1.90.0",
17
+ "@milaboratories/uikit": "2.17.10",
18
+ "@platforma-sdk/model": "1.90.2",
19
19
  "@types/d3-format": "^3.0.4",
20
20
  "@types/node": "~24.19.2",
21
21
  "@types/semver": "^7.7.0",
@@ -464,6 +464,119 @@ describe("createAppV3", { timeout: 20_000 }, () => {
464
464
  app.closedRef = true;
465
465
  });
466
466
 
467
+ it("should keep an unsaved edit when the outputs change before the save lands", async () => {
468
+ const state = createDefaultState();
469
+ const platforma = createMockApiV3<Data, Args, Outputs>(state, defaultBlockModelInfo());
470
+ // A save that takes its time, as in a large project.
471
+ const mutateStorage = platforma.mutateStorage.bind(platforma);
472
+ platforma.mutateStorage = async (payload, author) => {
473
+ await delay(patchPoolingDelay * 3);
474
+ return mutateStorage(payload, author);
475
+ };
476
+ const initialState = await platforma.loadBlockState();
477
+ if ("error" in initialState) throw initialState.error;
478
+
479
+ const { app } = createAppV3<Data, Args, Outputs>(initialState.value!, platforma, {
480
+ debug: false,
481
+ debounceSpan: 10,
482
+ });
483
+
484
+ app.model.data.count = 5;
485
+ await delay(50);
486
+
487
+ // The save is on its way. The state the server holds is still the previous author's.
488
+ state.setOutputs({ doubled: { ok: true, value: 42, stable: true } });
489
+ await delay(patchPoolingDelay + 50);
490
+
491
+ expect(app.model.outputs.doubled).toEqual(42);
492
+ expect(app.model.data).toEqual({ count: 5, label: "" });
493
+
494
+ app.model.data.label = "hello";
495
+
496
+ await app.allSettled();
497
+ await delay(patchPoolingDelay * 2 + 50);
498
+
499
+ expect(state.blockStorage.__data).toEqual({ count: 5, label: "hello" });
500
+ expect(app.model.data).toEqual({ count: 5, label: "hello" });
501
+
502
+ app.closedRef = true;
503
+ });
504
+
505
+ it("should keep an unsaved edit when the section changes before the save lands", async () => {
506
+ const state = createDefaultState();
507
+ const platforma = createMockApiV3<Data, Args, Outputs>(state, defaultBlockModelInfo());
508
+ const mutateStorage = platforma.mutateStorage.bind(platforma);
509
+ platforma.mutateStorage = async (payload, author) => {
510
+ await delay(patchPoolingDelay * 3);
511
+ return mutateStorage(payload, author);
512
+ };
513
+ const initialState = await platforma.loadBlockState();
514
+ if ("error" in initialState) throw initialState.error;
515
+
516
+ const { app } = createAppV3<Data, Args, Outputs>(initialState.value!, platforma, {
517
+ debug: false,
518
+ debounceSpan: 10,
519
+ });
520
+
521
+ app.model.data.count = 5;
522
+ await delay(50);
523
+
524
+ await app.navigateTo("/second" as `/${string}`);
525
+ await delay(patchPoolingDelay + 50);
526
+
527
+ expect(app.model.data).toEqual({ count: 5, label: "" });
528
+
529
+ app.model.data.label = "hello";
530
+
531
+ await app.allSettled();
532
+ await delay(patchPoolingDelay * 2 + 50);
533
+
534
+ expect(state.blockStorage.__data).toEqual({ count: 5, label: "hello" });
535
+ expect(app.model.data).toEqual({ count: 5, label: "hello" });
536
+
537
+ app.closedRef = true;
538
+ });
539
+
540
+ it("should keep unsaved plugin data when the outputs change before the save lands", async () => {
541
+ type F = PluginFactory<PluginData, undefined, { formatted: string }>;
542
+ const pluginId = "counter" as PluginHandle<F>;
543
+
544
+ const state = createDefaultState({ [pluginId]: defaultPluginData() });
545
+ const platforma = createMockApiV3<Data, Args, Outputs>(
546
+ state,
547
+ defaultBlockModelInfo([pluginId]),
548
+ );
549
+ const mutateStorage = platforma.mutateStorage.bind(platforma);
550
+ platforma.mutateStorage = async (payload, author) => {
551
+ await delay(patchPoolingDelay * 3);
552
+ return mutateStorage(payload, author);
553
+ };
554
+ const initialState = await platforma.loadBlockState();
555
+ if ("error" in initialState) throw initialState.error;
556
+
557
+ const { app, pluginAccess } = createAppV3<Data, Args, Outputs>(initialState.value!, platforma, {
558
+ debug: false,
559
+ debounceSpan: 10,
560
+ });
561
+
562
+ const pluginState = pluginAccess.getOrCreatePluginState(pluginId);
563
+ pluginState.model.data.value = 11;
564
+ await delay(50);
565
+
566
+ state.setOutputs({ doubled: { ok: true, value: 42, stable: true } });
567
+ await delay(patchPoolingDelay + 50);
568
+
569
+ expect(pluginState.model.data).toEqual({ value: 11 });
570
+
571
+ await app.allSettled();
572
+ await delay(patchPoolingDelay * 2 + 50);
573
+
574
+ expect(pluginState.model.data).toEqual({ value: 11 });
575
+ expect(state.blockStorage.__plugins?.[pluginId]?.__data).toEqual({ value: 11 });
576
+
577
+ app.closedRef = true;
578
+ });
579
+
467
580
  it("should report output errors", async () => {
468
581
  const state = new BlockStateV3Mock<Data, Outputs>(
469
582
  defaultData(),
@@ -1,4 +1,4 @@
1
- import { deepClone, delay, uniqueId } from "@milaboratories/helpers";
1
+ import { deepClone, delay, isJsonEqual, uniqueId } from "@milaboratories/helpers";
2
2
  import type { Mutable } from "@milaboratories/helpers";
3
3
  import type {
4
4
  NavigationState,
@@ -238,7 +238,13 @@ export function createAppV3<
238
238
  if (isAuthorChanged || data.isExternalSnapshot) {
239
239
  debug("got external changes, applying them to the snapshot", patches.value);
240
240
  ignoreUpdates(() => {
241
+ const storageBefore = snapshot.value.blockStorage;
241
242
  snapshot.value = applyPatch(snapshot.value, patches.value, false, false).newDocument;
243
+ // The author is the author of the stored data, not of this update. Until the first
244
+ // save of this window lands, every update carries the previous author, also one that
245
+ // changes the outputs or the section only. Such an update holds no data to take: the
246
+ // window's data may already be ahead of it, with a save queued or on its way.
247
+ if (isJsonEqual(storageBefore, snapshot.value.blockStorage)) return;
242
248
  updateAppModel({ data: deriveDataFromStorage<Data>(snapshot.value.blockStorage) });
243
249
  // Reconcile plugin data from external source
244
250
  for (const [handle, pluginState] of pluginStates) {